clitrigger 0.2.51 → 0.2.52
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/client/assets/{AnalyticsPanel-D7j7h--_.js → AnalyticsPanel-t7izyfbC.js} +1 -1
- package/dist/client/assets/{FloatingComposerController-5A3GJtK4-rYpQNHgT.js → FloatingComposerController-5A3GJtK4-m4CvKW0S.js} +1 -1
- package/dist/client/assets/{PlannerPageEditor-xt9n6F2p.js → PlannerPageEditor-DbJ5m1Ou.js} +3 -3
- package/dist/client/assets/{TaskGraph-BJ2xQmxj.js → TaskGraph-BohSFDDr.js} +1 -1
- package/dist/client/assets/{VaultLayout-Dj1ex4Lj.js → VaultLayout-A4lg8TSX.js} +1 -1
- package/dist/client/assets/{index-Ct2ZTmxX.css → index-D9kIIsvk.css} +1 -1
- package/dist/client/assets/{index-C7uvnGzt.js → index-iTp4ZnQ5.js} +4 -4
- package/dist/client/assets/{style-crwR-hgF.js → style-_-XY44fI.js} +1 -1
- package/dist/client/assets/{with-selector-J8hQXpaw.js → with-selector-CKx-PK4m.js} +1 -1
- package/dist/client/index.html +2 -2
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/TaskGraph-
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/TaskGraph-BohSFDDr.js","assets/style-_-XY44fI.js","assets/value-BTdN53H7.js","assets/with-selector-CKx-PK4m.js","assets/style-BZV40eAE.css","assets/PlannerPageEditor-DbJ5m1Ou.js","assets/index-Vcq4gwWv.js","assets/clsx-B-dksMZM.js","assets/PlannerPageEditor-1-XUcFw6.css","assets/AnalyticsPanel-t7izyfbC.js","assets/VaultLayout-A4lg8TSX.js"])))=>i.map(i=>d[i]);
|
|
2
2
|
var HC=Object.defineProperty;var $C=(e,s,i)=>s in e?HC(e,s,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[s]=i;var k0=(e,s,i)=>$C(e,typeof s!="symbol"?s+"":s,i);function UC(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 p of f.addedNodes)p.tagName==="LINK"&&p.rel==="modulepreload"&&a(p)}).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 ZB=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function wl(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var af={exports:{}},Uo={};/**
|
|
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 EN=[["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"}]],NN=ot("zoom-out",EN),eb=8;function LN({onLogin:e,onChangePassword:s}){const[i,a]=S.useState(""),[u,f]=S.useState(""),[p,o]=S.useState(""),[c,h]=S.useState(!1),[m,d]=S.useState(!1),[g,b]=S.useState(!1),[C,k]=S.useState(""),[x,_]=S.useState(!1),{t:w,toggleLang:y}=ft(),E=c&&u.length>0&&u.length<eb,R=c&&p.length>0&&u!==p,j=c?!!i&&u.length>=eb&&u===p:!!i,T=()=>{h(D=>!D),f(""),o(""),k("")},N=async D=>{if(D.preventDefault(),!(!j||x)){k(""),_(!0);try{c?await s(i,u,p,g):await e(i,g)}catch(A){k(c&&A instanceof Error&&A.message?A.message:w("login.error"))}finally{_(!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:y,className:"lang-toggle absolute top-6 right-6",children:w("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(ml,{size:32,className:"text-accent"})}),t.jsx("h1",{className:"text-2xl font-semibold text-theme-text",children:w("login.title")}),t.jsx("p",{className:"text-theme-muted text-sm mt-2",children:w("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:w(c?"account.oldPassword":"login.password")}),t.jsx("input",{type:"password",value:i,onChange:D=>a(D.target.value),placeholder:"*************",className:"input-field text-base",autoComplete:"current-password",autoFocus:!0}),c&&t.jsxs(t.Fragment,{children:[t.jsx("label",{className:"block text-sm font-medium text-theme-text-secondary mb-2 mt-4",children:w("account.newPassword")}),t.jsx("input",{type:"password",value:u,onChange:D=>f(D.target.value),className:"input-field text-base",autoComplete:"new-password","aria-label":w("account.newPassword")}),E&&t.jsx("p",{className:"mt-1 text-2xs text-status-error",children:w("account.tooShort")}),t.jsx("label",{className:"block text-sm font-medium text-theme-text-secondary mb-2 mt-4",children:w("account.confirm")}),t.jsx("input",{type:"password",value:p,onChange:D=>o(D.target.value),className:"input-field text-base",autoComplete:"new-password","aria-label":w("account.confirm")}),R&&t.jsx("p",{className:"mt-1 text-2xs text-status-error",children:w("account.mismatch")})]}),C&&t.jsx("div",{className:"mt-4 py-2.5 px-4 bg-status-error/5 border border-status-error/20 rounded-xl text-sm text-status-error",children: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:D=>b(D.target.checked),className:"accent-accent w-4 h-4"}),w("login.rememberMe")]}),t.jsx("button",{type:"submit",disabled:!j||x,className:"btn-primary w-full mt-6 py-3",children:w(x?"login.loading":c?"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:T,className:"text-theme-muted hover:text-theme-text underline-offset-2 hover:underline",children:w(c?"login.backToLogin":"login.changePassword")}),t.jsx("button",{type:"button",onClick:()=>d(D=>!D),className:"text-theme-muted hover:text-theme-text underline-offset-2 hover:underline",children:w("login.forgot")})]}),m&&t.jsx("div",{className:"mt-3 px-4 py-3 rounded-xl text-xs text-theme-text-tertiary border leading-relaxed",children:w("login.forgotHint")}),t.jsx("div",{className:"mt-6 text-center text-xs text-theme-text-tertiary",children:w("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:w("login.disclaimer")})]})]})}const tb=8;function DN({onSetup:e}){const[s,i]=S.useState(""),[a,u]=S.useState(""),[f,p]=S.useState(""),[o,c]=S.useState(!1),{t:h,toggleLang:m}=ft(),d=s.length>0&&s.length<tb,g=a.length>0&&s!==a,b=s.length>=tb&&s===a&&!o,C=async k=>{if(k.preventDefault(),!!b){p(""),c(!0);try{await e(s,a)}catch(x){p(x instanceof Error&&x.message?x.message:h("setup.error"))}finally{c(!1)}}};return t.jsxs("div",{className:"min-h-screen bg-theme-bg flex items-center justify-center px-4 relative",children:[t.jsx("button",{onClick:m,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(ml,{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 border border-status-error/20 rounded-xl text-sm text-status-error",children:f}),t.jsx("button",{type:"submit",disabled:!b,className:"btn-primary w-full mt-6 py-3",children: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 TN(e){return it("/api/projects/browse",{initialPath:e})}function RN(e){return it("/api/projects/open-folder",{path:e})}function Uu(){return xt("/api/projects")}function MN(e){return xt(`/api/projects/${e}`)}function e1(e){return it("/api/projects",e)}function AN(e){return xt(`/api/projects/${e}/svn-detect`)}function hm(e,s){return dn(`/api/projects/${e}`,s)}function zN(e,s){const i=s?`?todoId=${encodeURIComponent(s)}`:"";return xt(`/api/projects/${e}/debug-logs${i}`)}function t1(e){return Wn(`/api/projects/${e}`)}function ON(e){return it("/api/projects/reorder",{ids:e})}function BN(e){return it(`/api/projects/${e}/start`)}function PN(e){return it(`/api/projects/${e}/stop`)}function n1(e){return xt(`/api/projects/${e}/status`)}function nb(){return xt("/api/active-work")}function IN(e){return it(`/api/projects/${e}/check-git`)}function s1(e,s){const i=s?`?worktreePath=${encodeURIComponent(s)}`:"";return xt(`/api/projects/${e}/git-status${i}`)}function FN(e,s=0,i=50,a){const u=new URLSearchParams({skip:String(s),limit:String(i)});return xt(`/api/projects/${e}/git-log?${u}`)}function fm(e,s){return xt(`/api/projects/${e}/git-refs`)}function HN(e,s,i){return it(`/api/projects/${e}/git-stage`,{files:s,worktreePath:i})}function $N(e,s,i){return it(`/api/projects/${e}/git-unstage`,{files:s,worktreePath:i})}function r1(e,s,i){return it(`/api/projects/${e}/git-commit`,{message:s,worktreePath:i})}function i1(e,s,i){return it(`/api/projects/${e}/git-pull`,{remote:s,branch:i})}function op(e,s){return it(`/api/projects/${e}/git-push`,s||{})}function UN(e){return xt(`/api/projects/${e}/git-remotes`)}function a1(e,s,i){return it(`/api/projects/${e}/git-fetch`,{remote:s,prune:i})}function o1(e,s,i){return it(`/api/projects/${e}/git-branch`,{name:s,startPoint:i})}function mm(e,s,i){return it(`/api/projects/${e}/git-branch-delete`,{name:s,force:i})}function pm(e,s){return it(`/api/projects/${e}/git-checkout`,{branch:s})}function l1(e,s){return it(`/api/projects/${e}/git-merge`,{branch:s})}function sb(e,s,i,a){return it(`/api/projects/${e}/git-conflict-resolve`,{file:s,side:i,worktreePath:a})}function WN(e,s,i){const a=i?`&worktreePath=${encodeURIComponent(i)}`:"";return xt(`/api/projects/${e}/git-conflict-file?file=${encodeURIComponent(s)}${a}`)}function qN(e,s,i,a){return it(`/api/projects/${e}/git-conflict-file`,{file:s,content:i,worktreePath:a})}function KN(e){return it(`/api/projects/${e}/git-conflict-continue`)}function GN(e){return it(`/api/projects/${e}/git-conflict-abort`)}function VN(e,s){return it(`/api/projects/${e}/git-stash`,{message:s})}function YN(e,s){return it(`/api/projects/${e}/git-stash-pop`,{index:s})}function XN(e){return xt(`/api/projects/${e}/git-stash-list`)}function JN(e,s,i,a){return it(`/api/projects/${e}/git-discard`,{files:s,all:i,worktreePath:a})}function c1(e,s,i,a){return it(`/api/projects/${e}/git-tag`,{name:s,message:i,commit:a})}function rb(e,s,i){return it(`/api/projects/${e}/git-branch-rename`,{oldName:s,newName:i})}function QN(e,s){return it(`/api/projects/${e}/git-rebase`,{onto:s})}function ZN(e,s){return it(`/api/projects/${e}/git-revert`,{commit:s})}function e3(e,s){return it(`/api/projects/${e}/git-cherry-pick`,{commit:s})}function t3(e,s,i){return it(`/api/projects/${e}/git-reset`,{commit:s,mode:i})}function n3(e,s,i,a){const u=new URLSearchParams;return s&&u.set("file",s),i&&u.set("staged","true"),a&&u.set("worktreePath",a),xt(`/api/projects/${e}/git-diff?${u}`)}function s3(e,s){const i=new URLSearchParams({hash:s});return xt(`/api/projects/${e}/git-commit-files?${i}`)}function ib(e,s,i){const a=new URLSearchParams({hash:s});return i&&a.set("file",i),xt(`/api/projects/${e}/git-commit-diff?${a}`)}function gm(e){return xt(`/api/projects/${e}/worktrees`)}function ab(e,s,i){return it(`/api/projects/${e}/worktree-cleanup`,{worktreePath:s,branchName:i})}function u1(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 r3(e={}){return xt(`/api/review/queue${u1(e)}`)}function d1(e={}){return xt(`/api/review/summary${u1(e)}`)}function i3(e){return xt(`/api/review/diff/${encodeURIComponent(e)}`)}function a3(e,s){return xt(`/api/review/diff/${encodeURIComponent(e)}/file?path=${encodeURIComponent(s)}`)}function o3(){return xt("/api/favorites")}function l3(e){return it("/api/favorites",e)}function c3(e,s){return dn(`/api/favorites/${e}`,s)}function u3(e){return Wn(`/api/favorites/${e}`)}function d3(e){return it(`/api/favorites/${e}/launch`)}function h3(e){return it("/api/favorites/browse-file",{initialPath:e})}function xm(){return xt("/api/tunnel/status")}function f3(){return xt("/api/tunnel/config")}function m3(e){return dn("/api/tunnel/config",e)}function h1(e){return it("/api/tunnel/start",{})}function p3(){return it("/api/tunnel/stop")}const f1=S.createContext({theme:"light",toggleTheme:()=>{}});function g3(){const[e,s]=S.useState(()=>{const a=localStorage.getItem("theme");return a==="light"||a==="dark"?a:window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light"});S.useEffect(()=>{document.documentElement.setAttribute("data-theme",e),localStorage.setItem("theme",e)},[e]);const i=S.useCallback(()=>{s(a=>a==="light"?"dark":"light")},[]);return{theme:e,toggleTheme:i}}function x3(){return S.useContext(f1)}const m1=S.createContext({enabled:!1,supported:!1,toggleNotification:()=>{},sendNotification:()=>{}});function v3(){const e="Notification"in window,[s,i]=S.useState(()=>e?localStorage.getItem("clitrigger-notifications")==="on"&&Notification.permission==="granted":!1),a=S.useRef(s);S.useEffect(()=>{a.current=s},[s]);const u=S.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=S.useCallback((p,o)=>{if(!a.current)return;const c=new Notification(p,{body:o});c.onclick=()=>{window.focus(),c.close()}},[]);return{enabled:s,supported:e,toggleNotification:u,sendNotification:f}}function lp(){return S.useContext(m1)}let b3=0;const p1=S.createContext(null);function y3({children:e}){const[s,i]=S.useState([]),a=S.useRef(new Map),u=S.useRef(new Map),f=S.useRef(new Map),p=S.useCallback(b=>{i(x=>x.filter(_=>_.id!==b));const C=f.current.get(b);C&&u.current.get(C)===b&&u.current.delete(C),f.current.delete(b);const k=a.current.get(b);k&&(clearTimeout(k),a.current.delete(b))},[]),o=S.useCallback((b,C="info",k=3500)=>{const x=`${C}:${b}`,_=u.current.get(x);if(_)return _;const w=`toast-${++b3}`;u.current.set(x,w),f.current.set(w,x),i(E=>[...E,{id:w,message:b,type:C,duration:k}]);const y=setTimeout(()=>p(w),k);return a.current.set(w,y),w},[p]),c=S.useCallback((b,C)=>o(b,"success",C),[o]),h=S.useCallback((b,C)=>o(b,"error",C),[o]),m=S.useCallback((b,C)=>o(b,"info",C),[o]),d=S.useCallback((b,C)=>o(b,"warning",C),[o]);S.useEffect(()=>()=>{a.current.forEach(clearTimeout),a.current.clear(),u.current.clear(),f.current.clear()},[]);const g=S.useMemo(()=>({toasts:s,show:o,success:c,error:h,info:m,warning:d,dismiss:p}),[s,o,c,h,m,d,p]);return S.createElement(p1.Provider,{value:g},e)}function Ls(){const e=S.useContext(p1);if(!e)throw new Error("useToast must be used within ToastProvider");return e}function Hs(...e){return e.filter(Boolean).join(" ")}const w3={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 jn({open:e,onClose:s,size:i="md",position:a="center",disableEscClose:u=!1,disableBackdropClose:f=!1,children:p}){const o=S.useRef(null);return S.useEffect(()=>{if(!e||u)return;const c=h=>{h.key==="Escape"&&s()};return document.addEventListener("keydown",c),()=>document.removeEventListener("keydown",c)},[e,u,s]),e?rn.createPortal(t.jsx("div",{ref:o,className:Hs("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:c=>{!f&&c.target===o.current&&s()},children:t.jsx("div",{className:Hs("w-full",w3[i]),children:p})}),document.body):null}const _3={default:"btn",primary:"btn-primary",secondary:"btn-secondary",danger:"btn-danger",ghost:"btn-ghost"},S3={sm:"btn-sm",md:"btn-md",lg:"btn-lg"},Gt=S.forwardRef(function({variant:s="default",size:i,type:a="button",className:u,...f},p){return t.jsx("button",{ref:p,type:a,className:Hs(_3[s],i&&S3[i],u),...f})}),g1=S.createContext(null);let ob=0;function k3({children:e}){const[s,i]=S.useState(null),a=S.useRef(null),u=S.useCallback(h=>{const m=a.current;m&&(m.kind==="confirm"?m.resolve(!1):m.resolve(null)),a.current=h,i(h)},[]),f=S.useCallback(()=>{a.current=null,i(null)},[]),p=S.useCallback(h=>{const m=typeof h=="string"?{message:h}:h;return new Promise(d=>{u({id:++ob,kind:"confirm",options:m,resolve:d})})},[u]),o=S.useCallback(h=>{const m=typeof h=="string"?{message:h}:h;return new Promise(d=>{u({id:++ob,kind:"prompt",options:m,resolve:d})})},[u]),c=S.useMemo(()=>({confirm:p,prompt:o}),[p,o]);return t.jsxs(g1.Provider,{value:c,children:[e,s&&t.jsx(C3,{dialog:s,onSettled:f},s.id)]})}function C3({dialog:e,onSettled:s}){const{t:i}=ft(),[a,u]=S.useState(e.kind==="prompt"?e.options.initialValue??"":""),f=()=>{e.kind==="confirm"?e.resolve(!1):e.resolve(null),s()},p=()=>{e.kind==="confirm"?e.resolve(!0):e.resolve(a),s()},o=e.kind==="confirm"&&!!e.options.danger,c=e.kind==="confirm"&&e.options.confirmLabel||i("common.ok"),h=e.kind==="confirm"&&e.options.cancelLabel||i("common.cancel"),m=t.jsxs("div",{className:"mt-4 flex justify-end gap-2",children:[t.jsx(Gt,{size:"sm",onClick:f,autoFocus:o,children:h}),t.jsx(Gt,{variant:o?"danger":"primary",size:"sm",type:e.kind==="prompt"?"submit":"button",onClick:e.kind==="prompt"?void 0:p,autoFocus:e.kind==="confirm"&&!o,children:c})]});return t.jsx(jn,{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(),p()},children:[t.jsx("input",{autoFocus:!0,value:a,onChange:d=>u(d.target.value),placeholder:e.options.placeholder,className:"input-field mt-3"}),m]}):m]})})}function qn(){const e=S.useContext(g1);if(!e)throw new Error("useDialog must be used within DialogProvider");return e}function x1({onSubmit:e,onCancel:s}){const[i,a]=S.useState(""),[u,f]=S.useState(""),[p,o]=S.useState(!1),[c,h]=S.useState(!1),[m,d]=S.useState(""),{t:g}=ft(),b=async k=>{if(k.preventDefault(),!(!i.trim()||!u.trim())){d(""),h(!0);try{await e(i.trim(),u.trim())}catch(x){const _=x instanceof Error?x.message:String(x);d(_||g("form.createError"))}finally{h(!1)}}},C=async()=>{o(!0);try{const k=await TN(u||void 0);k.path&&f(k.path)}catch{}o(!1)};return t.jsx(jn,{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:b,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:p,className:"btn-ghost text-sm px-3 shrink-0",title:g("browse.title"),children:p?t.jsx(hi,{size:16,className:"animate-spin"}):t.jsx(Fu,{size:16})})]})]}),m&&t.jsx("p",{className:"text-sm mb-4",style:{color:"var(--color-danger, #ef4444)"},children:m}),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()||c,className:"btn-primary text-sm",children:g(c?"form.creating":"form.create")})]})]})]})})}const j3=[{value:"executable",icon:sp},{value:"command",icon:pi},{value:"url",icon:fl}];function E3(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 lb(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 N3({initial:e,onSubmit:s,onCancel:i}){const{t:a}=ft(),[u,f]=S.useState((e==null?void 0:e.name)??""),[p,o]=S.useState((e==null?void 0:e.type)??"executable"),[c,h]=S.useState((e==null?void 0:e.target)??""),[m,d]=S.useState(lb((e==null?void 0:e.args)??null)),[g,b]=S.useState((e==null?void 0:e.cwd)??""),[C,k]=S.useState(!1);S.useEffect(()=>{f((e==null?void 0:e.name)??""),o((e==null?void 0:e.type)??"executable"),h((e==null?void 0:e.target)??""),d(lb((e==null?void 0:e.args)??null)),b((e==null?void 0:e.cwd)??"")},[e]);const[x,_]=S.useState(!1),w=p==="executable",y=async()=>{_(!0);try{const{path:B}=await h3(c||void 0);if(!B)return;if(h(B),!u.trim()){const O=B.replace(/\\/g,"/").split("/").pop()||"";f(O.replace(/\.[^.]+$/,""))}}catch{}finally{_(!1)}},E=!!e,R=u.trim(),j=c.trim(),T=p!=="url"||/^https?:\/\//i.test(j),N=!!R&&!!j&&T&&!C,D=async B=>{if(B.preventDefault(),!!N){k(!0);try{const O={name:R,type:p,target:j,args:p==="executable"&&m.trim()?E3(m.trim()):null,cwd:p!=="url"&&g.trim()?g.trim():null};await s(O)}finally{k(!1)}}},A=a(p==="executable"?"favorites.form.targetHint.executable":p==="command"?"favorites.form.targetHint.command":"favorites.form.targetHint.url");return t.jsx(jn,{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(E?"favorites.form.title.edit":"favorites.form.title.create")}),t.jsxs("form",{onSubmit:D,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:j3.map(({value:B,icon:O})=>t.jsxs("button",{type:"button",onClick:()=>o(B),className:"flex items-center justify-center gap-2 px-3 py-2 rounded-lg text-xs font-medium transition-all border",style:p===B?{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.${B}`)]},B))})]}),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:B=>f(B.target.value),className:"input-field",autoFocus:!0})]}),t.jsxs("div",{className:"mb-5",children:[t.jsx("label",{className:"block text-sm font-medium text-warm-600 mb-2",children:a("favorites.form.target")}),t.jsxs("div",{className:"flex gap-2",children:[t.jsx("input",{type:"text",value:c,onChange:B=>h(B.target.value),className:"input-field text-sm font-mono flex-1",placeholder:A}),w&&t.jsxs("button",{type:"button",onClick:y,disabled:x,className:"btn-ghost text-sm whitespace-nowrap flex items-center gap-1.5 disabled:opacity-50",children:[t.jsx(Fu,{size:14}),a("favorites.form.browse")]})]}),t.jsx("p",{className:"mt-1 text-2xs",style:{color:"var(--color-text-muted)"},children:A})]}),p==="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:m,onChange:B=>d(B.target.value),className:"input-field text-sm font-mono",placeholder:'--flag value "with spaces"'})]}),p!=="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:B=>b(B.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(E?"favorites.form.save":"favorites.form.create")})]})]})]})})}const L3=/^([a-z0-9]([a-z0-9-]*[a-z0-9])?\.)+[a-z]{2,}$/i;function D3({onClose:e}){const{t:s}=ft(),{error:i,success:a}=Ls(),[u,f]=S.useState(""),[p,o]=S.useState(""),[c,h]=S.useState(""),[m,d]=S.useState(""),[g,b]=S.useState(!1),[C,k]=S.useState(!1),[x,_]=S.useState(!1),[w,y]=S.useState(null);S.useEffect(()=>{let O=!1;return Promise.all([f3(),xm()]).then(([F,$])=>{O||(f(F.tunnelName),o(F.customHostname),h(F.tunnelName),d(F.customHostname),y($))}).catch(()=>{}),()=>{O=!0}},[]);const E=u.trim(),R=p.trim(),j=E!==c.trim()||R!==m.trim(),T=!!R&&(!L3.test(R)||R.toLowerCase()==="localhost"||R.toLowerCase()==="127.0.0.1"),N=!!R&&!E,D=j&&!C&&!T&&!N,A=async()=>{if(D){k(!0);try{const O=await m3({tunnelName:E,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)}}},B=async()=>{_(!0);try{try{await p3()}catch{}const O=await h1();y({status:"running",url:O.url}),a(s("tunnel.restarted"))}catch(O){i(O instanceof Error?O.message:s("tunnel.restartFailed"))}finally{_(!1)}};return t.jsxs("div",{className:"p-8",children:[t.jsx("h2",{className:"text-lg font-semibold text-warm-800 mb-1",children:s("tunnel.title")}),t.jsx("p",{className:"text-xs text-warm-400 mb-6",children:s("tunnel.description")}),w&&t.jsxs("div",{className:"mb-5 p-3 rounded-lg text-xs flex items-center gap-2",style:{backgroundColor:"var(--color-bg-hover)",color:"var(--color-text-tertiary)"},children:[t.jsx("span",{className:`w-2 h-2 rounded-full ${w.status==="running"?"bg-status-success":w.status==="error"?"bg-status-error":"bg-status-pending"}`}),t.jsx("span",{className:"font-medium",children:s(`tunnel.status.${w.status}`)}),w.url&&t.jsx("a",{href:w.url,target:"_blank",rel:"noreferrer",className:"ml-auto font-mono truncate hover:underline",style:{color:"var(--color-accent)"},children:w.url})]}),t.jsxs("div",{className:"mb-4",children:[t.jsx("label",{className:"block text-sm font-medium text-warm-600 mb-2",children:s("tunnel.name.label")}),t.jsx("input",{type:"text",value: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:p,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")}),T&&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:()=>b(!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:B,disabled:x,className:"btn-ghost text-sm disabled:opacity-50",children:x?(w==null?void 0:w.status)==="running"?s("tunnel.restarting"):s("tunnel.starting"):(w==null?void 0:w.status)==="running"?s("tunnel.restart"):s("tunnel.start")}),t.jsxs("div",{className:"flex gap-3",children:[e&&t.jsx("button",{type:"button",onClick:e,className:"btn-ghost text-sm",children:s("tunnel.close")}),t.jsx("button",{type:"button",onClick:A,disabled:!D,className:"btn-primary text-sm",children:s(C?"tunnel.saving":"tunnel.save")})]})]})]})}const cb=8;function T3({onClose:e}){const{t:s}=ft(),{error:i,success:a}=Ls(),[u,f]=S.useState(""),[p,o]=S.useState(""),[c,h]=S.useState(""),[m,d]=S.useState(!1),g=p.length>0&&p.length<cb,b=c.length>0&&p!==c,C=!!u&&p.length>=cb&&p===c&&!m,k=()=>{f(""),o(""),h("")},x=async()=>{if(C){d(!0);try{await Fw(u,p,c),a(s("account.saved")),k()}catch(_){i(_ instanceof Error&&_.message?_.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:_=>f(_.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:p,onChange:_=>o(_.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:c,onChange:_=>h(_.target.value),className:"input-field text-sm",autoComplete:"new-password"}),b&&t.jsx("p",{className:"mt-1 text-2xs text-status-error",children:s("account.mismatch")})]}),t.jsxs("div",{className:"flex items-center justify-end gap-3",children:[e&&t.jsx("button",{type:"button",onClick:e,className:"btn-ghost text-sm",children:s("account.close")}),t.jsx("button",{type:"button",onClick:x,disabled:!C,className:"btn-primary text-sm",children:s(m?"account.saving":"account.save")})]})]})}function cp(){return xt("/api/session-tags")}function R3(e){return it("/api/session-tags",e)}function M3(e,s){return dn(`/api/session-tags/${e}`,s)}function A3(e){return Wn(`/api/session-tags/${e}`)}function v1(){return xt("/api/session-aliases")}function b1(e){return it("/api/session-aliases",e)}function z3(e,s){return dn(`/api/session-aliases/${e}`,s)}function O3(e){return Wn(`/api/session-aliases/${e}`)}function up(){return xt("/api/session-settings")}function gf(e){return dn("/api/session-settings",e)}const Ue={titleBg:"#2d2d2d",titleText:"#999",bg:"#0c0c0c",text:"#cccccc",dim:"#666666",bright:"#f2f2f2",prompt:"#16c60c",success:"#16c60c",error:"#f14c4c",warning:"#cca700",info:"#569cd6",separator:"#333333"},Ot="'Cascadia Code', 'Cascadia Mono', ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, 'Courier New', monospace",dp=13,nl=8,sl=28,Ka=new Map,$i=new Map;let _u=dp;function hp(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);Ka.delete(s);const i=$i.get(s);if(i){const u=rl(s);i.forEach(f=>f(u))}});function vm(e){return Number.isFinite(e)?Math.max(nl,Math.min(sl,Math.round(e))):_u}function B3(e){if(Ka.has(e))return!0;try{return localStorage.getItem(hp(e))!==null}catch{return!1}}function rl(e){const s=Ka.get(e);if(s!==void 0)return s;let i=null;try{const a=localStorage.getItem(hp(e));if(a!==null){const u=parseInt(a,10);Number.isFinite(u)&&(i=vm(u))}}catch{}return i===null?vm(_u):(Ka.set(e,i),i)}function bm(e,s){const i=vm(s);if(Ka.get(e)===i)return;Ka.set(e,i);try{localStorage.setItem(hp(e),String(i))}catch{}const a=$i.get(e);a&&a.forEach(u=>u(i))}function Ko(e,s){bm(e,rl(e)+s)}function cu(e){const s=Math.max(nl,Math.min(sl,Math.round(e)));Number.isFinite(s)&&s!==_u&&(_u=s,$i.forEach((i,a)=>{B3(a)||i.forEach(u=>u(s))}))}function y1(e){const[s,i]=S.useState(()=>rl(e));S.useEffect(()=>{i(rl(e));let f=$i.get(e);return f||(f=new Set,$i.set(e,f)),f.add(i),()=>{const p=$i.get(e);p&&(p.delete(i),p.size===0&&$i.delete(e))}},[e]);const a=S.useCallback(f=>bm(e,f),[e]),u=S.useCallback(f=>bm(e,rl(e)+f),[e]);return[s,a,u]}const il=["#A78BFA","#F472B6","#FB923C","#FBBF24","#34D399","#60A5FA","#F87171","#94A3B8"];function ub(e){for(const s of il)if(!e.some(i=>i.color.toLowerCase()===s.toLowerCase()))return s;return il[e.length%il.length]}function P3({onClose:e}){const{t:s}=ft(),{confirm:i}=qn(),{error:a,success:u}=Ls(),[f,p]=S.useState([]),[o,c]=S.useState(!1),[h,m]=S.useState(dp),[d,g]=S.useState(!1),[b,C]=S.useState(!1),[k,x]=S.useState(!1),[_,w]=S.useState(!1),y=S.useRef(null),[E,R]=S.useState(""),[j,T]=S.useState(il[0]),[N,D]=S.useState(!1),[A,B]=S.useState(null),[O,F]=S.useState(""),[$,P]=S.useState(il[0]),[H,W]=S.useState(!1),[G,I]=S.useState([]),[z,U]=S.useState(""),[V,q]=S.useState(""),[oe,ee]=S.useState(!1),[Z,te]=S.useState(null),[Y,he]=S.useState(""),[de,ye]=S.useState(""),[le,De]=S.useState(!1);S.useEffect(()=>{let J=!1;return Promise.all([cp(),up(),v1()]).then(([se,pe,we])=>{J||(p(se),c(pe.defaultUseWorktree),m(pe.defaultFontSize),cu(pe.defaultFontSize),g(pe.imeDebug),T(ub(se)),I(we),C(!0))}).catch(se=>{J||a(se instanceof Error?se.message:"Failed to load")}),()=>{J=!0}},[a]);const Re=E.trim(),ve=!!Re&&!N,Me=S.useMemo(()=>[...f].sort((J,se)=>J.sort_order-se.sort_order||J.name.localeCompare(se.name)),[f]);S.useEffect(()=>()=>{y.current&&clearTimeout(y.current)},[]);const Oe=J=>{if(!Number.isFinite(J))return;const se=Math.max(nl,Math.min(sl,Math.round(J)));m(se),cu(se),y.current&&clearTimeout(y.current),y.current=setTimeout(()=>{gf({defaultFontSize:se}).then(pe=>{m(pe.defaultFontSize),cu(pe.defaultFontSize)}).catch(pe=>a(pe instanceof Error?pe.message:"Save failed"))},350)},tt=async J=>{x(!0);try{const se=await gf({defaultUseWorktree:J});c(se.defaultUseWorktree),u(s("sessionSettings.saved"))}catch(se){a(se instanceof Error?se.message:"Save failed")}finally{x(!1)}},nt=async J=>{var se,pe;w(!0);try{const we=await gf({imeDebug:J});g(we.imeDebug),(pe=(se=window.electronAPI)==null?void 0:se.imeSetDebug)==null||pe.call(se,we.imeDebug),u(s("sessionSettings.saved"))}catch(we){a(we instanceof Error?we.message:"Save failed")}finally{w(!1)}},ke=async()=>{if(ve){D(!0);try{const J=await R3({name:Re,color:j});p(se=>[...se,J]),R(""),T(ub([...f,J]))}catch(J){a(J instanceof Error?J.message:"Create failed")}finally{D(!1)}}},fe=J=>{B(J.id),F(J.name),P(J.color)},Te=()=>{B(null),F("")},Ce=async()=>{if(!A)return;const J=O.trim();if(J){W(!0);try{const se=await M3(A,{name:J,color:$});p(pe=>pe.map(we=>we.id===se.id?se:we)),Te()}catch(se){a(se instanceof Error?se.message:"Save failed")}finally{W(!1)}}},Ge=async J=>{if(await i({message:s("sessionSettings.tags.deleteConfirm").replace("{name}",J.name),danger:!0}))try{await A3(J.id),p(se=>se.filter(pe=>pe.id!==J.id))}catch(se){a(se instanceof Error?se.message:"Delete failed")}},Ze=z.trim(),be=V.trim(),Be=!!Ze&&!!be&&!oe,ne=S.useMemo(()=>[...G].sort((J,se)=>J.sort_order-se.sort_order||J.name.localeCompare(se.name)),[G]),_e=async()=>{if(Be){ee(!0);try{const J=await b1({name:Ze,command_template:be});I(se=>[...se,J]),U(""),q("")}catch(J){a(J instanceof Error?J.message:"Create failed")}finally{ee(!1)}}},X=J=>{te(J.id),he(J.name),ye(J.command_template)},me=()=>{te(null),he(""),ye("")},re=async()=>{if(!Z)return;const J=Y.trim(),se=de.trim();if(!(!J||!se)){De(!0);try{const pe=await z3(Z,{name:J,command_template:se});I(we=>we.map(je=>je.id===pe.id?pe:je)),me()}catch(pe){a(pe instanceof Error?pe.message:"Save failed")}finally{De(!1)}}},ae=async J=>{if(await i({message:s("sessionSettings.aliases.deleteConfirm").replace("{name}",J.name),danger:!0}))try{await O3(J.id),I(se=>se.filter(pe=>pe.id!==J.id))}catch(se){a(se instanceof Error?se.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(Vi,{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||!b,onChange:J=>tt(J.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(vN,{size:14}),s("sessionSettings.fontSize.title")]}),t.jsxs("div",{className:"flex items-center gap-3",children:[t.jsx("input",{type:"range",min:nl,max:sl,step:1,value:h,disabled:!b,onChange:J=>Oe(parseInt(J.target.value,10)),className:"flex-1 max-w-xs","aria-label":s("sessionSettings.fontSize.label")}),t.jsx("input",{type:"number",min:nl,max:sl,step:1,value:h,disabled:!b,onChange:J=>Oe(parseInt(J.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:j,onChange:J=>T(J.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:E,onChange:J=>R(J.target.value),onKeyDown:J=>{J.key==="Enter"&&(J.preventDefault(),ke())},placeholder:s("sessionSettings.tags.namePlaceholder"),className:"input text-sm flex-1",maxLength:32}),t.jsxs("button",{type:"button",onClick:ke,disabled:!ve,className:"btn-primary text-sm py-1.5 px-3 inline-flex items-center gap-1",children:[t.jsx(yn,{size:14}),s("sessionSettings.tags.add")]})]}),Me.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:Me.map(J=>{const se=A===J.id;return t.jsx("li",{className:"flex items-center gap-2 px-3 py-2 rounded-lg border",style:{borderColor:"var(--color-border)"},children:se?t.jsxs(t.Fragment,{children:[t.jsx("input",{type:"color",value:$,onChange:pe=>P(pe.target.value),className:"w-7 h-7 rounded-md cursor-pointer border border-warm-200"}),t.jsx("input",{type:"text",value:O,onChange:pe=>F(pe.target.value),onKeyDown:pe=>{pe.key==="Enter"&&(pe.preventDefault(),Ce()),pe.key==="Escape"&&Te()},autoFocus:!0,className:"input text-sm flex-1",maxLength:32}),t.jsx("button",{type:"button",onClick:Ce,disabled:H||!O.trim(),className:"p-1.5 text-status-success hover:bg-status-success/10 rounded-md",title:s("sessionSettings.tags.save"),children:t.jsx(rr,{size:14})}),t.jsx("button",{type:"button",onClick:Te,className:"p-1.5 text-warm-400 hover:bg-warm-100 rounded-md",title:s("sessionSettings.tags.cancel"),children:t.jsx(Xt,{size:14})})]}):t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"w-4 h-4 rounded-full shrink-0 border",style:{backgroundColor:J.color,borderColor:"rgba(0,0,0,0.08)"}}),t.jsx("span",{className:"text-sm text-warm-700 flex-1 truncate",children:J.name}),t.jsx("button",{type:"button",onClick:()=>fe(J),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(fi,{size:14})}),t.jsx("button",{type:"button",onClick:()=>Ge(J),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(An,{size:14})})]})},J.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:z,onChange:J=>U(J.target.value),placeholder:s("sessionSettings.aliases.namePlaceholder"),className:"input text-sm w-44",maxLength:64}),t.jsx("input",{type:"text",value:V,onChange:J=>q(J.target.value),onKeyDown:J=>{J.key==="Enter"&&(J.preventDefault(),_e())},placeholder:s("sessionSettings.aliases.commandPlaceholder"),className:"input text-sm flex-1 font-mono",maxLength:1024}),t.jsxs("button",{type:"button",onClick:_e,disabled:!Be,className:"btn-primary text-sm py-1.5 px-3 inline-flex items-center gap-1",children:[t.jsx(yn,{size:14}),s("sessionSettings.aliases.add")]})]}),ne.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:ne.map(J=>{const se=Z===J.id;return t.jsx("li",{className:"flex items-center gap-2 px-3 py-2 rounded-lg border",style:{borderColor:"var(--color-border)"},children:se?t.jsxs(t.Fragment,{children:[t.jsx("input",{type:"text",value:Y,onChange:pe=>he(pe.target.value),className:"input text-sm w-44",maxLength:64}),t.jsx("input",{type:"text",value:de,onChange:pe=>ye(pe.target.value),onKeyDown:pe=>{pe.key==="Enter"&&(pe.preventDefault(),re()),pe.key==="Escape"&&me()},autoFocus:!0,className:"input text-sm flex-1 font-mono",maxLength:1024}),t.jsx("button",{type:"button",onClick:re,disabled:le||!Y.trim()||!de.trim(),className:"p-1.5 text-status-success hover:bg-status-success/10 rounded-md",title:s("common.save"),children:t.jsx(rr,{size:14})}),t.jsx("button",{type:"button",onClick:me,className:"p-1.5 text-warm-400 hover:bg-warm-100 rounded-md",title:s("common.cancel"),children:t.jsx(Xt,{size:14})})]}):t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"text-sm text-warm-700 w-44 truncate",children:J.name}),t.jsx("code",{className:"text-xs text-warm-500 flex-1 truncate font-mono",children:J.command_template}),t.jsx("button",{type:"button",onClick:()=>X(J),className:"p-1.5 text-warm-400 hover:text-warm-700 hover:bg-warm-100 rounded-md",title:s("common.edit"),children:t.jsx(fi,{size:14})}),t.jsx("button",{type:"button",onClick:()=>ae(J),className:"p-1.5 text-warm-400 hover:text-status-error hover:bg-warm-100 rounded-md",title:s("common.delete"),children:t.jsx(An,{size:14})})]})},J.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(o5,{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:_||!b,onChange:J=>nt(J.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 I3(){return xt("/api/mcp/connection")}function F3({onClose:e}){const{t:s}=ft(),{success:i,error:a}=Ls(),[u,f]=S.useState(null),[p,o]=S.useState(null);S.useEffect(()=>{let g=!1;return I3().then(b=>{g||f(b)}).catch(()=>{}),()=>{g=!0}},[]);const c=async(g,b)=>{try{await navigator.clipboard.writeText(b),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):"",m=({label:g,text:b})=>t.jsxs("button",{type:"button",onClick:()=>c(g,b),className:"btn-ghost text-xs flex items-center gap-1",children:[p===g?t.jsx(rr,{size:14}):t.jsx(F5,{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(m,{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(m,{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 db({open:e,onClose:s}){const{t:i}=ft(),[a,u]=S.useState("account");if(!e)return null;const f=[{id:"account",label:i("settings.tabs.account"),icon:xE},{id:"session",label:i("settings.tabs.session"),icon:ml},{id:"tunnel",label:i("settings.tabs.tunnel"),icon:Yw},{id:"mcp",label:i("settings.tabs.mcp"),icon:QE}];return t.jsx(jn,{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:p,label:o,icon:c})=>{const h=a===p;return t.jsxs("button",{type:"button",onClick:()=>u(p),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(c,{size:14}),t.jsx("span",{children:o})]},p)})}),t.jsxs("div",{className:"px-4 py-3 mt-auto text-[11px] tracking-wide",style:{color:"var(--color-text-muted)"},children:["v","0.2.51"]})]}),t.jsxs("div",{className:"flex-1 min-w-0",children:[a==="account"&&t.jsx(T3,{onClose:s}),a==="session"&&t.jsx(P3,{onClose:s}),a==="tunnel"&&t.jsx(D3,{onClose:s}),a==="mcp"&&t.jsx(F3,{onClose:s})]})]})})})}const ym=["#55708F","#4F7A68","#9A783F","#A15F5A","#74658A","#925F73","#477B7D","#747A50"];function H3(e,s){let i=0;for(let a=0;a<e.length;a++)i=(i<<5)-i+e.charCodeAt(a)|0;return Math.abs(i)%s}function Ga(e){return e.color&&/^#[0-9a-f]{6}$/i.test(e.color)?e.color:ym[H3(e.id,ym.length)]}const hb=192,$3=88,Hc=8;function U3({project:e,anchorX:s,anchorY:i,onPick:a,onClose:u}){const f=S.useRef(null),[p,o]=S.useState({left:s,top:i}),c=Ga(e);return S.useLayoutEffect(()=>{const h=Math.min(Math.max(s,Hc),window.innerWidth-hb-Hc),m=Math.min(Math.max(i,Hc),window.innerHeight-$3-Hc);o({left:h,top:m})},[s,i]),S.useEffect(()=>{const h=d=>{var g;(g=f.current)!=null&&g.contains(d.target)||u()},m=d=>{d.key==="Escape"&&u()};return window.addEventListener("mousedown",h),window.addEventListener("keydown",m),()=>{window.removeEventListener("mousedown",h),window.removeEventListener("keydown",m)}},[u]),rn.createPortal(t.jsxs("div",{ref:f,role:"menu",className:"z-tooltip",style:{position:"fixed",left:p.left,top:p.top,width:hb,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:ym.map(h=>{const m=e.color?h.toLowerCase()===e.color.toLowerCase():h===c&&!e.color;return t.jsx("button",{onClick:()=>a(h),"aria-label":h,style:{width:20,height:20,borderRadius:6,background:h,border:m?"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 al(e,s){return e instanceof Error&&e.message.trim()?e.message:typeof e=="string"&&e.trim()?e:s}function W3(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 q3={sm:"btn-icon-sm",md:"btn-icon-md",lg:"btn-icon-lg"},K3={default:"",active:"btn-icon-active",danger:"btn-icon-danger"},Sn=S.forwardRef(function({label:s,size:i="md",variant:a="default",pressed:u,type:f="button",title:p,className:o,...c},h){return t.jsx("button",{ref:h,type:f,"aria-label":s,"aria-pressed":u,title:p??s,className:Hs("btn-icon",q3[i],K3[a],o),...c})});function G3(e){return e==="executable"?sp:e==="command"?pi:fl}function V3({onLogout:e,authRequired:s,connected:i,onEvent:a,onClose:u,collapsed:f=!1,onToggleCollapsed:p}){var Be;const[o,c]=S.useState([]),[h,m]=S.useState({}),[d,g]=S.useState(null),[b,C]=S.useState(!1),[k,x]=S.useState(null),[_,w]=S.useState([]),[y,E]=S.useState(!1),[R,j]=S.useState(null),[T,N]=S.useState(!1),[D,A]=S.useState(null),[B,O]=S.useState(!1),[F,$]=S.useState(null),[P,H]=S.useState(null),W=Ws(),G=xi(),{t:I,toggleLang:z}=ft(),{theme:U,toggleTheme:V}=x3(),{enabled:q,supported:oe,toggleNotification:ee}=lp(),{error:Z,success:te,info:Y,warning:he}=Ls(),{confirm:de}=qn(),ye=((Be=W.pathname.match(/^\/projects\/([^/]+)/))==null?void 0:Be[1])||null;S.useEffect(()=>{nt(),De(),xm().then(A).catch(()=>{})},[]);async function le(){if(!B){O(!0);try{const ne=await xm();if(A(ne),ne.status==="running"&&ne.url){await navigator.clipboard.writeText(ne.url),te(I("tunnel.urlCopied"));return}const _e=await h1(),X={status:"running",url:_e.url};A(X);try{await navigator.clipboard.writeText(_e.url),te(I("tunnel.urlCopied"))}catch{te(_e.url)}}catch(ne){Z(ne instanceof Error?ne.message:I("tunnel.restartFailed"))}finally{O(!1)}}}function De(){o3().then(w).catch(()=>{})}const Re=async ne=>{try{R?await c3(R.id,ne):await l3(ne),E(!1),j(null),De()}catch(_e){Z(_e instanceof Error?_e.message:"Failed to save favorite")}},ve=async ne=>{try{await d3(ne)}catch(_e){const X=_e instanceof Error?_e.message:I("favorites.launchFailed");Z(`${I("favorites.launchFailed")}: ${X}`)}},Me=async(ne,_e)=>{if(_e.preventDefault(),_e.stopPropagation(),!!await de({message:I("favorites.deleteConfirm"),danger:!0}))try{await u3(ne),w(X=>X.filter(me=>me.id!==ne))}catch(X){Z(X instanceof Error?X.message:"Failed to delete favorite")}},Oe=(ne,_e)=>{_e.preventDefault(),_e.stopPropagation(),j(ne),E(!0)};S.useEffect(()=>{const ne=()=>nt();return window.addEventListener("projects:changed",ne),()=>window.removeEventListener("projects:changed",ne)},[]),S.useEffect(()=>{const ne=()=>tt();return window.addEventListener("review:changed",ne),()=>window.removeEventListener("review:changed",ne)},[]),S.useEffect(()=>a(ne=>{var _e;if(ne.type==="project:status-changed"&&ne.projectId&&m(X=>({...X,[ne.projectId]:{running:ne.running??0,completed:ne.completed??0,total:ne.total??0,running_sessions:ne.running_sessions??0,running_discussions:ne.running_discussions??0}})),ne.type==="todo:status-changed"&&tt(),ne.type==="memory:ingest-finished"){const X=o.find(je=>je.id===ne.projectId),me=(X==null?void 0:X.name)??"",re=ne.sourceTitle?`“${ne.sourceTitle}”`:ne.sourceType??"",ae=me?`[${me}] `:"";if(ne.error){Z(`${ae}${I("wiki.ingest.toast.failed")}: ${ne.error}`,6e3);return}const J=ne.created??0,se=ne.updated??0,pe=ne.edgesAdded??0;if(J+se+pe>0){const je=I("wiki.ingest.toast.success").replace("{source}",re).replace("{created}",String(J)).replace("{updated}",String(se)).replace("{edges}",String(pe));te(`${ae}${je}`)}else(_e=ne.skipped)!=null&&_e.parseFailed?he(`${ae}${I("wiki.ingest.toast.parseFailed").replace("{source}",re)}`,5e3):Y(`${ae}${I("wiki.ingest.toast.empty").replace("{source}",re)}`,4e3)}}),[a,o,I,Z,Y,te,he]),S.useEffect(()=>{tt()},[]);function tt(){d1({hours:24}).then(ne=>g(ne.total_todos)).catch(()=>{})}function nt(){Uu().then(ne=>{c(ne),ne.forEach(_e=>{n1(_e.id).then(X=>{m(me=>({...me,[_e.id]:X}))}).catch(()=>{})})}).catch(()=>{})}const ke=()=>{u==null||u()},fe=async(ne,_e)=>{await e1({name:ne,path:_e}),C(!1),window.dispatchEvent(new Event("projects:changed"))},Te=S.useCallback(async(ne,_e)=>{const X=o.map(je=>je.id),me=X.indexOf(ne);if(me<0)return;const re=X.filter(je=>je!==ne),ae=_e>me?_e-1:_e;if(ae===me)return;const J=[...re.slice(0,ae),ne,...re.slice(ae)],se=o,pe=new Map(o.map(je=>[je.id,je])),we=J.map(je=>pe.get(je)).filter(Boolean);c(we);try{await ON(J)}catch(je){c(se),Z(je instanceof Error?je.message:"Failed to reorder projects")}},[o,Z]),Ce=S.useRef(!1),Ge=S.useCallback((ne,_e)=>{if(_e.button!==0||_e.target.closest("button"))return;_e.preventDefault();const me=_e.clientX,re=_e.clientY,ae=6;let J=!1,se=null;const pe=qe=>{const Ee=document.querySelectorAll("[data-workspace-item]");if(Ee.length===0)return null;const st=Ee[0].getBoundingClientRect();if(qe<st.top)return 0;const lt=Ee[Ee.length-1].getBoundingClientRect();if(qe>lt.bottom)return Ee.length;for(let yt=0;yt<Ee.length;yt++){const mt=Ee[yt].getBoundingClientRect();if(qe>=mt.top&&qe<=mt.bottom){const pt=mt.top+mt.height/2;return qe<pt?yt:yt+1}}return null},we=qe=>{if(!J){if(Math.hypot(qe.clientX-me,qe.clientY-re)<ae)return;J=!0,$(ne)}const Ee=pe(qe.clientY);Ee!==se&&(se=Ee,H(Ee))},je=()=>{window.removeEventListener("mousemove",we),window.removeEventListener("mouseup",$e),window.removeEventListener("keydown",Je)},$e=()=>{if(je(),!J)return;Ce.current=!0,requestAnimationFrame(()=>{Ce.current=!1});const qe=se;$(null),H(null),qe!==null&&Te(ne,qe)},Je=qe=>{qe.key==="Escape"&&(je(),$(null),H(null),J&&(Ce.current=!0,requestAnimationFrame(()=>{Ce.current=!1})))};window.addEventListener("mousemove",we),window.addEventListener("mouseup",$e),window.addEventListener("keydown",Je)},[Te]),Ze=async(ne,_e)=>{if(_e.preventDefault(),_e.stopPropagation(),!!await de({message:I("projects.deleteConfirm"),danger:!0}))try{await t1(ne),c(X=>X.filter(me=>me.id!==ne)),window.dispatchEvent(new Event("projects:changed")),ye===String(ne)&&G("/")}catch(X){Z(al(X,I("errors.projectDelete")))}},be=ne=>t.jsx("div",{className:"pointer-events-none absolute left-2 right-2 h-0.5 rounded-full",style:{backgroundColor:"var(--color-accent)",zIndex:10,...ne==="above"?{top:-1}:{bottom:-1}}});if(f){const ne=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(Sn,{onClick:p,label:I("sidebar.expand"),size:"lg",children:t.jsx(KE,{size:16})}),ne,t.jsx(Un,{to:"/",onClick:ke,className:"relative flex items-center justify-center w-9 h-9 rounded-lg transition-colors hover:bg-theme-hover",style:W.pathname==="/"?{backgroundColor:"var(--color-bg-hover)",color:"var(--color-text-primary)"}:{color:"var(--color-text-tertiary)"},title:I("sidebar.home"),children:t.jsx(V0,{size:16})}),t.jsxs(Un,{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:W.pathname==="/review"?{backgroundColor:"var(--color-bg-hover)",color:"var(--color-text-primary)"}:{color:"var(--color-text-tertiary)"},title:I("sidebar.review"),children:[t.jsx(bu,{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(Un,{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:W.pathname==="/agenda"?{backgroundColor:"var(--color-bg-hover)",color:"var(--color-text-primary)"}:{color:"var(--color-text-tertiary)"},title:I("sidebar.agenda"),children:t.jsx(am,{size:16})}),ne,t.jsx("div",{className:"flex-1 overflow-y-auto w-full flex flex-col items-center gap-1 py-1",children:o.map(_e=>{const X=h[_e.id],me=ye===String(_e.id),re=X?X.running+X.running_sessions+X.running_discussions:0,ae=re>0,J=Ga(_e);return t.jsxs(Un,{to:`/projects/${_e.id}`,onClick:ke,className:"relative flex items-center justify-center w-9 h-9 rounded-lg transition-colors hover:bg-theme-hover",style:me?{backgroundColor:"var(--color-bg-hover)"}:void 0,title:ae?`${_e.name} · ${re} ${I("detail.live")}`:_e.name,children:[me&&t.jsx("span",{className:"absolute left-0 top-1/4 bottom-1/4 w-[3px] rounded-r-full",style:{backgroundColor:J}}),t.jsx("span",{className:`w-2.5 h-2.5 rounded-[3px] ${ae?"workspace-dot-pulse":""}`,style:{backgroundColor:J,opacity:me||ae?1:.55}})]},_e.id)})}),ne,t.jsx("span",{className:`w-1.5 h-1.5 rounded-full my-1 ${i?"bg-status-success":"bg-status-error"}`,title:i?I("detail.live"):"Disconnected"}),t.jsx(Sn,{onClick:V,label:I(U==="light"?"theme.dark":"theme.light"),size:"lg",children:U==="light"?t.jsx(X0,{size:16}):t.jsx(Q0,{size:16})}),t.jsx(Sn,{onClick:()=>N(!0),label:I("settings.title"),size:"lg",children:t.jsx(wu,{size:16})}),t.jsx(db,{open:T,onClose:()=>N(!1)})]})}return t.jsxs("div",{className:"flex flex-col h-full bg-theme-bg-secondary border-none",onDragStart:ne=>ne.preventDefault(),children:[t.jsxs("div",{className:"px-4 pt-5 pb-3 flex items-center justify-between",children:[t.jsxs(Un,{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(Sn,{onClick:p,label:I("sidebar.collapse"),size:"sm",className:"hidden md:inline-flex flex-shrink-0",children:t.jsx(WE,{size:16})})]}),t.jsxs("nav",{className:"px-3 mb-2 space-y-0.5",children:[t.jsxs(Un,{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 ${W.pathname==="/"?"font-medium":""}`,style:W.pathname==="/"?{backgroundColor:"var(--color-bg-hover)",color:"var(--color-text-primary)",boxShadow:"var(--shadow-soft)"}:{color:"var(--color-text-tertiary)"},children:[W.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(V0,{size:16}),I("sidebar.home")]}),t.jsxs(Un,{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 ${W.pathname==="/review"?"font-medium":""}`,style:W.pathname==="/review"?{backgroundColor:"var(--color-bg-hover)",color:"var(--color-text-primary)",boxShadow:"var(--shadow-soft)"}:{color:"var(--color-text-tertiary)"},children:[W.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(bu,{size:16}),t.jsx("span",{className:"flex-1",children:I("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(Un,{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 ${W.pathname==="/agenda"?"font-medium":""}`,style:W.pathname==="/agenda"?{backgroundColor:"var(--color-bg-hover)",color:"var(--color-text-primary)",boxShadow:"var(--shadow-soft)"}:{color:"var(--color-text-tertiary)"},children:[W.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(am,{size:16}),I("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:I("sidebar.workspaces")}),t.jsx(Sn,{onClick:()=>C(!0),label:I("projects.new"),size:"sm",children:t.jsx(yn,{size:14})})]}),t.jsx("div",{className:"space-y-0.5",children:o.map((ne,_e)=>{const X=h[ne.id],me=ye===String(ne.id),re=X?X.running+X.running_sessions+X.running_discussions:0,ae=re>0,J=Ga(ne),se=F===ne.id,pe=F!==null&&P===_e,we=F!==null&&_e===o.length-1&&P===o.length;return t.jsxs("div",{className:"relative","data-workspace-item":!0,children:[pe&&be("above"),t.jsxs(Un,{to:`/projects/${ne.id}`,draggable:!1,onDragStart:je=>je.preventDefault(),onClick:je=>{if(Ce.current){je.preventDefault();return}ke()},onMouseDown:je=>Ge(ne.id,je),onContextMenu:je=>{je.preventDefault(),x({project:ne,x:je.clientX,y:je.clientY})},className:`relative flex items-center gap-2.5 px-3 py-1.5 rounded-lg text-sm transition-all duration-200 hover:bg-theme-hover active:scale-95 group ${me?"font-medium":""} ${se?"opacity-50":""}`,style:me?{backgroundColor:"var(--color-bg-hover)",color:"var(--color-text-primary)",boxShadow:"var(--shadow-soft)",cursor:F?"grabbing":"pointer",userSelect:"none"}:{color:"var(--color-text-tertiary)",cursor:F?"grabbing":"pointer",userSelect:"none"},children:[me&&t.jsx("span",{className:"absolute left-0 top-1/4 bottom-1/4 w-[3px] rounded-r-full",style:{backgroundColor:J}}),t.jsx("span",{className:`w-1.5 h-3 rounded-[2px] flex-shrink-0 ${ae?"workspace-dot-pulse":""}`,style:{backgroundColor:J,opacity:me||ae?1:.55},title:ae?`${I("sidebar.workspaces")} · ${re} ${I("detail.live")}`:ne.name}),t.jsx("span",{className:"truncate flex-1",children:ne.name}),t.jsx(Sn,{onClick:je=>Ze(ne.id,je),label:I("projects.delete"),size:"sm",variant:"danger",className:"flex-shrink-0 opacity-0 group-hover:opacity-100 focus-visible:opacity-100",children:t.jsx(Xt,{size:12})})]}),we&&be("below")]},ne.id)})})]}),b&&t.jsx(x1,{onSubmit:(ne,_e)=>fe(ne,_e),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:I("sidebar.favorites")}),t.jsx(Sn,{onClick:()=>{j(null),E(!0)},label:I("favorites.add"),size:"sm",children:t.jsx(yn,{size:14})})]}),t.jsx("div",{className:"space-y-0.5 max-h-48 overflow-y-auto",children:_.map(ne=>{const _e=G3(ne.type);return t.jsxs("button",{onClick:()=>ve(ne.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:ne.target,children:[t.jsx(_e,{size:14,className:"flex-shrink-0"}),t.jsx("span",{className:"truncate flex-1 text-left",children:ne.name}),t.jsx("span",{onClick:X=>Oe(ne,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:I("favorites.edit"),children:t.jsx(um,{size:12})}),t.jsx("span",{onClick:X=>Me(ne.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:I("favorites.delete"),children:t.jsx(Xt,{size:12})})]},ne.id)})})]}),y&&t.jsx(N3,{initial:R??void 0,onSubmit:Re,onCancel:()=>{E(!1),j(null)}}),k&&t.jsx(U3,{project:k.project,anchorX:k.x,anchorY:k.y,onPick:async ne=>{try{const _e=await hm(k.project.id,{color:ne});c(X=>X.map(me=>me.id===_e.id?{...me,color:_e.color}:me)),window.dispatchEvent(new Event("projects:changed"))}catch(_e){Z(_e instanceof Error?_e.message:"Failed to update color")}x(null)},onClose:()=>x(null)}),t.jsx(db,{open:T,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?I("detail.live"):"Disconnected"}),t.jsx(Sn,{onClick:V,label:I(U==="light"?"theme.dark":"theme.light"),children:U==="light"?t.jsx(X0,{size:16}):t.jsx(Q0,{size:16})}),t.jsx(Sn,{onClick:z,label:I("lang.toggle"),className:"text-xs font-medium",children:I("lang.toggle")}),oe&&t.jsx(Sn,{onClick:ee,label:"Notification"in window&&Notification.permission==="denied"?I("notification.blocked"):I("notification.toggle"),variant:q?"active":"default",pressed:q,children:q?t.jsx(i5,{size:16}):t.jsx(s5,{size:16})}),t.jsx(Sn,{onClick:le,disabled:B,label:I("tunnel.start"),variant:(D==null?void 0:D.status)==="running"?"active":"default",pressed:(D==null?void 0:D.status)==="running",title:(D==null?void 0:D.status)==="running"&&D.url?`${D.url} — ${I("tunnel.urlCopied")}`:I(B?"tunnel.starting":"tunnel.start"),children:t.jsx(Yw,{size:16})}),t.jsx(Sn,{onClick:()=>N(!0),label:I("settings.title"),children:t.jsx(wu,{size:16})}),s&&t.jsx(Sn,{onClick:e,label:I("projects.logout"),variant:"danger",className:"ml-auto",children:t.jsx(DE,{size:16})})]})})]})}function Y3({children:e,onLogout:s,authRequired:i,connected:a,onEvent:u}){const[f,p]=S.useState(!1),{t:o}=ft(),[c,h]=S.useState(()=>localStorage.getItem("sidebarCollapsed")==="1"),m=()=>{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 EN=[["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"}]],NN=ot("zoom-out",EN),eb=8;function LN({onLogin:e,onChangePassword:s}){const[i,a]=S.useState(""),[u,f]=S.useState(""),[p,o]=S.useState(""),[c,h]=S.useState(!1),[m,d]=S.useState(!1),[g,b]=S.useState(!1),[C,k]=S.useState(""),[x,_]=S.useState(!1),{t:w,toggleLang:y}=ft(),E=c&&u.length>0&&u.length<eb,R=c&&p.length>0&&u!==p,j=c?!!i&&u.length>=eb&&u===p:!!i,T=()=>{h(D=>!D),f(""),o(""),k("")},N=async D=>{if(D.preventDefault(),!(!j||x)){k(""),_(!0);try{c?await s(i,u,p,g):await e(i,g)}catch(A){k(c&&A instanceof Error&&A.message?A.message:w("login.error"))}finally{_(!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:y,className:"lang-toggle absolute top-6 right-6",children:w("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(ml,{size:32,className:"text-accent"})}),t.jsx("h1",{className:"text-2xl font-semibold text-theme-text",children:w("login.title")}),t.jsx("p",{className:"text-theme-muted text-sm mt-2",children:w("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:w(c?"account.oldPassword":"login.password")}),t.jsx("input",{type:"password",value:i,onChange:D=>a(D.target.value),placeholder:"*************",className:"input-field text-base",autoComplete:"current-password",autoFocus:!0}),c&&t.jsxs(t.Fragment,{children:[t.jsx("label",{className:"block text-sm font-medium text-theme-text-secondary mb-2 mt-4",children:w("account.newPassword")}),t.jsx("input",{type:"password",value:u,onChange:D=>f(D.target.value),className:"input-field text-base",autoComplete:"new-password","aria-label":w("account.newPassword")}),E&&t.jsx("p",{className:"mt-1 text-2xs text-status-error",children:w("account.tooShort")}),t.jsx("label",{className:"block text-sm font-medium text-theme-text-secondary mb-2 mt-4",children:w("account.confirm")}),t.jsx("input",{type:"password",value:p,onChange:D=>o(D.target.value),className:"input-field text-base",autoComplete:"new-password","aria-label":w("account.confirm")}),R&&t.jsx("p",{className:"mt-1 text-2xs text-status-error",children:w("account.mismatch")})]}),C&&t.jsx("div",{className:"mt-4 py-2.5 px-4 bg-status-error/5 border border-status-error/20 rounded-xl text-sm text-status-error",children: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:D=>b(D.target.checked),className:"accent-accent w-4 h-4"}),w("login.rememberMe")]}),t.jsx("button",{type:"submit",disabled:!j||x,className:"btn-primary w-full mt-6 py-3",children:w(x?"login.loading":c?"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:T,className:"text-theme-muted hover:text-theme-text underline-offset-2 hover:underline",children:w(c?"login.backToLogin":"login.changePassword")}),t.jsx("button",{type:"button",onClick:()=>d(D=>!D),className:"text-theme-muted hover:text-theme-text underline-offset-2 hover:underline",children:w("login.forgot")})]}),m&&t.jsx("div",{className:"mt-3 px-4 py-3 rounded-xl text-xs text-theme-text-tertiary border leading-relaxed",children:w("login.forgotHint")}),t.jsx("div",{className:"mt-6 text-center text-xs text-theme-text-tertiary",children:w("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:w("login.disclaimer")})]})]})}const tb=8;function DN({onSetup:e}){const[s,i]=S.useState(""),[a,u]=S.useState(""),[f,p]=S.useState(""),[o,c]=S.useState(!1),{t:h,toggleLang:m}=ft(),d=s.length>0&&s.length<tb,g=a.length>0&&s!==a,b=s.length>=tb&&s===a&&!o,C=async k=>{if(k.preventDefault(),!!b){p(""),c(!0);try{await e(s,a)}catch(x){p(x instanceof Error&&x.message?x.message:h("setup.error"))}finally{c(!1)}}};return t.jsxs("div",{className:"min-h-screen bg-theme-bg flex items-center justify-center px-4 relative",children:[t.jsx("button",{onClick:m,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(ml,{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 border border-status-error/20 rounded-xl text-sm text-status-error",children:f}),t.jsx("button",{type:"submit",disabled:!b,className:"btn-primary w-full mt-6 py-3",children: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 TN(e){return it("/api/projects/browse",{initialPath:e})}function RN(e){return it("/api/projects/open-folder",{path:e})}function Uu(){return xt("/api/projects")}function MN(e){return xt(`/api/projects/${e}`)}function e1(e){return it("/api/projects",e)}function AN(e){return xt(`/api/projects/${e}/svn-detect`)}function hm(e,s){return dn(`/api/projects/${e}`,s)}function zN(e,s){const i=s?`?todoId=${encodeURIComponent(s)}`:"";return xt(`/api/projects/${e}/debug-logs${i}`)}function t1(e){return Wn(`/api/projects/${e}`)}function ON(e){return it("/api/projects/reorder",{ids:e})}function BN(e){return it(`/api/projects/${e}/start`)}function PN(e){return it(`/api/projects/${e}/stop`)}function n1(e){return xt(`/api/projects/${e}/status`)}function nb(){return xt("/api/active-work")}function IN(e){return it(`/api/projects/${e}/check-git`)}function s1(e,s){const i=s?`?worktreePath=${encodeURIComponent(s)}`:"";return xt(`/api/projects/${e}/git-status${i}`)}function FN(e,s=0,i=50,a){const u=new URLSearchParams({skip:String(s),limit:String(i)});return xt(`/api/projects/${e}/git-log?${u}`)}function fm(e,s){return xt(`/api/projects/${e}/git-refs`)}function HN(e,s,i){return it(`/api/projects/${e}/git-stage`,{files:s,worktreePath:i})}function $N(e,s,i){return it(`/api/projects/${e}/git-unstage`,{files:s,worktreePath:i})}function r1(e,s,i){return it(`/api/projects/${e}/git-commit`,{message:s,worktreePath:i})}function i1(e,s,i){return it(`/api/projects/${e}/git-pull`,{remote:s,branch:i})}function op(e,s){return it(`/api/projects/${e}/git-push`,s||{})}function UN(e){return xt(`/api/projects/${e}/git-remotes`)}function a1(e,s,i){return it(`/api/projects/${e}/git-fetch`,{remote:s,prune:i})}function o1(e,s,i){return it(`/api/projects/${e}/git-branch`,{name:s,startPoint:i})}function mm(e,s,i){return it(`/api/projects/${e}/git-branch-delete`,{name:s,force:i})}function pm(e,s){return it(`/api/projects/${e}/git-checkout`,{branch:s})}function l1(e,s){return it(`/api/projects/${e}/git-merge`,{branch:s})}function sb(e,s,i,a){return it(`/api/projects/${e}/git-conflict-resolve`,{file:s,side:i,worktreePath:a})}function WN(e,s,i){const a=i?`&worktreePath=${encodeURIComponent(i)}`:"";return xt(`/api/projects/${e}/git-conflict-file?file=${encodeURIComponent(s)}${a}`)}function qN(e,s,i,a){return it(`/api/projects/${e}/git-conflict-file`,{file:s,content:i,worktreePath:a})}function KN(e){return it(`/api/projects/${e}/git-conflict-continue`)}function GN(e){return it(`/api/projects/${e}/git-conflict-abort`)}function VN(e,s){return it(`/api/projects/${e}/git-stash`,{message:s})}function YN(e,s){return it(`/api/projects/${e}/git-stash-pop`,{index:s})}function XN(e){return xt(`/api/projects/${e}/git-stash-list`)}function JN(e,s,i,a){return it(`/api/projects/${e}/git-discard`,{files:s,all:i,worktreePath:a})}function c1(e,s,i,a){return it(`/api/projects/${e}/git-tag`,{name:s,message:i,commit:a})}function rb(e,s,i){return it(`/api/projects/${e}/git-branch-rename`,{oldName:s,newName:i})}function QN(e,s){return it(`/api/projects/${e}/git-rebase`,{onto:s})}function ZN(e,s){return it(`/api/projects/${e}/git-revert`,{commit:s})}function e3(e,s){return it(`/api/projects/${e}/git-cherry-pick`,{commit:s})}function t3(e,s,i){return it(`/api/projects/${e}/git-reset`,{commit:s,mode:i})}function n3(e,s,i,a){const u=new URLSearchParams;return s&&u.set("file",s),i&&u.set("staged","true"),a&&u.set("worktreePath",a),xt(`/api/projects/${e}/git-diff?${u}`)}function s3(e,s){const i=new URLSearchParams({hash:s});return xt(`/api/projects/${e}/git-commit-files?${i}`)}function ib(e,s,i){const a=new URLSearchParams({hash:s});return i&&a.set("file",i),xt(`/api/projects/${e}/git-commit-diff?${a}`)}function gm(e){return xt(`/api/projects/${e}/worktrees`)}function ab(e,s,i){return it(`/api/projects/${e}/worktree-cleanup`,{worktreePath:s,branchName:i})}function u1(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 r3(e={}){return xt(`/api/review/queue${u1(e)}`)}function d1(e={}){return xt(`/api/review/summary${u1(e)}`)}function i3(e){return xt(`/api/review/diff/${encodeURIComponent(e)}`)}function a3(e,s){return xt(`/api/review/diff/${encodeURIComponent(e)}/file?path=${encodeURIComponent(s)}`)}function o3(){return xt("/api/favorites")}function l3(e){return it("/api/favorites",e)}function c3(e,s){return dn(`/api/favorites/${e}`,s)}function u3(e){return Wn(`/api/favorites/${e}`)}function d3(e){return it(`/api/favorites/${e}/launch`)}function h3(e){return it("/api/favorites/browse-file",{initialPath:e})}function xm(){return xt("/api/tunnel/status")}function f3(){return xt("/api/tunnel/config")}function m3(e){return dn("/api/tunnel/config",e)}function h1(e){return it("/api/tunnel/start",{})}function p3(){return it("/api/tunnel/stop")}const f1=S.createContext({theme:"light",toggleTheme:()=>{}});function g3(){const[e,s]=S.useState(()=>{const a=localStorage.getItem("theme");return a==="light"||a==="dark"?a:window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light"});S.useEffect(()=>{document.documentElement.setAttribute("data-theme",e),localStorage.setItem("theme",e)},[e]);const i=S.useCallback(()=>{s(a=>a==="light"?"dark":"light")},[]);return{theme:e,toggleTheme:i}}function x3(){return S.useContext(f1)}const m1=S.createContext({enabled:!1,supported:!1,toggleNotification:()=>{},sendNotification:()=>{}});function v3(){const e="Notification"in window,[s,i]=S.useState(()=>e?localStorage.getItem("clitrigger-notifications")==="on"&&Notification.permission==="granted":!1),a=S.useRef(s);S.useEffect(()=>{a.current=s},[s]);const u=S.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=S.useCallback((p,o)=>{if(!a.current)return;const c=new Notification(p,{body:o});c.onclick=()=>{window.focus(),c.close()}},[]);return{enabled:s,supported:e,toggleNotification:u,sendNotification:f}}function lp(){return S.useContext(m1)}let b3=0;const p1=S.createContext(null);function y3({children:e}){const[s,i]=S.useState([]),a=S.useRef(new Map),u=S.useRef(new Map),f=S.useRef(new Map),p=S.useCallback(b=>{i(x=>x.filter(_=>_.id!==b));const C=f.current.get(b);C&&u.current.get(C)===b&&u.current.delete(C),f.current.delete(b);const k=a.current.get(b);k&&(clearTimeout(k),a.current.delete(b))},[]),o=S.useCallback((b,C="info",k=3500)=>{const x=`${C}:${b}`,_=u.current.get(x);if(_)return _;const w=`toast-${++b3}`;u.current.set(x,w),f.current.set(w,x),i(E=>[...E,{id:w,message:b,type:C,duration:k}]);const y=setTimeout(()=>p(w),k);return a.current.set(w,y),w},[p]),c=S.useCallback((b,C)=>o(b,"success",C),[o]),h=S.useCallback((b,C)=>o(b,"error",C),[o]),m=S.useCallback((b,C)=>o(b,"info",C),[o]),d=S.useCallback((b,C)=>o(b,"warning",C),[o]);S.useEffect(()=>()=>{a.current.forEach(clearTimeout),a.current.clear(),u.current.clear(),f.current.clear()},[]);const g=S.useMemo(()=>({toasts:s,show:o,success:c,error:h,info:m,warning:d,dismiss:p}),[s,o,c,h,m,d,p]);return S.createElement(p1.Provider,{value:g},e)}function Ls(){const e=S.useContext(p1);if(!e)throw new Error("useToast must be used within ToastProvider");return e}function Hs(...e){return e.filter(Boolean).join(" ")}const w3={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 jn({open:e,onClose:s,size:i="md",position:a="center",disableEscClose:u=!1,disableBackdropClose:f=!1,children:p}){const o=S.useRef(null);return S.useEffect(()=>{if(!e||u)return;const c=h=>{h.key==="Escape"&&s()};return document.addEventListener("keydown",c),()=>document.removeEventListener("keydown",c)},[e,u,s]),e?rn.createPortal(t.jsx("div",{ref:o,className:Hs("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:c=>{!f&&c.target===o.current&&s()},children:t.jsx("div",{className:Hs("w-full",w3[i]),children:p})}),document.body):null}const _3={default:"btn",primary:"btn-primary",secondary:"btn-secondary",danger:"btn-danger",ghost:"btn-ghost"},S3={sm:"btn-sm",md:"btn-md",lg:"btn-lg"},Gt=S.forwardRef(function({variant:s="default",size:i,type:a="button",className:u,...f},p){return t.jsx("button",{ref:p,type:a,className:Hs(_3[s],i&&S3[i],u),...f})}),g1=S.createContext(null);let ob=0;function k3({children:e}){const[s,i]=S.useState(null),a=S.useRef(null),u=S.useCallback(h=>{const m=a.current;m&&(m.kind==="confirm"?m.resolve(!1):m.resolve(null)),a.current=h,i(h)},[]),f=S.useCallback(()=>{a.current=null,i(null)},[]),p=S.useCallback(h=>{const m=typeof h=="string"?{message:h}:h;return new Promise(d=>{u({id:++ob,kind:"confirm",options:m,resolve:d})})},[u]),o=S.useCallback(h=>{const m=typeof h=="string"?{message:h}:h;return new Promise(d=>{u({id:++ob,kind:"prompt",options:m,resolve:d})})},[u]),c=S.useMemo(()=>({confirm:p,prompt:o}),[p,o]);return t.jsxs(g1.Provider,{value:c,children:[e,s&&t.jsx(C3,{dialog:s,onSettled:f},s.id)]})}function C3({dialog:e,onSettled:s}){const{t:i}=ft(),[a,u]=S.useState(e.kind==="prompt"?e.options.initialValue??"":""),f=()=>{e.kind==="confirm"?e.resolve(!1):e.resolve(null),s()},p=()=>{e.kind==="confirm"?e.resolve(!0):e.resolve(a),s()},o=e.kind==="confirm"&&!!e.options.danger,c=e.kind==="confirm"&&e.options.confirmLabel||i("common.ok"),h=e.kind==="confirm"&&e.options.cancelLabel||i("common.cancel"),m=t.jsxs("div",{className:"mt-4 flex justify-end gap-2",children:[t.jsx(Gt,{size:"sm",onClick:f,autoFocus:o,children:h}),t.jsx(Gt,{variant:o?"danger":"primary",size:"sm",type:e.kind==="prompt"?"submit":"button",onClick:e.kind==="prompt"?void 0:p,autoFocus:e.kind==="confirm"&&!o,children:c})]});return t.jsx(jn,{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(),p()},children:[t.jsx("input",{autoFocus:!0,value:a,onChange:d=>u(d.target.value),placeholder:e.options.placeholder,className:"input-field mt-3"}),m]}):m]})})}function qn(){const e=S.useContext(g1);if(!e)throw new Error("useDialog must be used within DialogProvider");return e}function x1({onSubmit:e,onCancel:s}){const[i,a]=S.useState(""),[u,f]=S.useState(""),[p,o]=S.useState(!1),[c,h]=S.useState(!1),[m,d]=S.useState(""),{t:g}=ft(),b=async k=>{if(k.preventDefault(),!(!i.trim()||!u.trim())){d(""),h(!0);try{await e(i.trim(),u.trim())}catch(x){const _=x instanceof Error?x.message:String(x);d(_||g("form.createError"))}finally{h(!1)}}},C=async()=>{o(!0);try{const k=await TN(u||void 0);k.path&&f(k.path)}catch{}o(!1)};return t.jsx(jn,{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:b,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:p,className:"btn-ghost text-sm px-3 shrink-0",title:g("browse.title"),children:p?t.jsx(hi,{size:16,className:"animate-spin"}):t.jsx(Fu,{size:16})})]})]}),m&&t.jsx("p",{className:"text-sm mb-4",style:{color:"var(--color-danger, #ef4444)"},children:m}),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()||c,className:"btn-primary text-sm",children:g(c?"form.creating":"form.create")})]})]})]})})}const j3=[{value:"executable",icon:sp},{value:"command",icon:pi},{value:"url",icon:fl}];function E3(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 lb(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 N3({initial:e,onSubmit:s,onCancel:i}){const{t:a}=ft(),[u,f]=S.useState((e==null?void 0:e.name)??""),[p,o]=S.useState((e==null?void 0:e.type)??"executable"),[c,h]=S.useState((e==null?void 0:e.target)??""),[m,d]=S.useState(lb((e==null?void 0:e.args)??null)),[g,b]=S.useState((e==null?void 0:e.cwd)??""),[C,k]=S.useState(!1);S.useEffect(()=>{f((e==null?void 0:e.name)??""),o((e==null?void 0:e.type)??"executable"),h((e==null?void 0:e.target)??""),d(lb((e==null?void 0:e.args)??null)),b((e==null?void 0:e.cwd)??"")},[e]);const[x,_]=S.useState(!1),w=p==="executable",y=async()=>{_(!0);try{const{path:B}=await h3(c||void 0);if(!B)return;if(h(B),!u.trim()){const O=B.replace(/\\/g,"/").split("/").pop()||"";f(O.replace(/\.[^.]+$/,""))}}catch{}finally{_(!1)}},E=!!e,R=u.trim(),j=c.trim(),T=p!=="url"||/^https?:\/\//i.test(j),N=!!R&&!!j&&T&&!C,D=async B=>{if(B.preventDefault(),!!N){k(!0);try{const O={name:R,type:p,target:j,args:p==="executable"&&m.trim()?E3(m.trim()):null,cwd:p!=="url"&&g.trim()?g.trim():null};await s(O)}finally{k(!1)}}},A=a(p==="executable"?"favorites.form.targetHint.executable":p==="command"?"favorites.form.targetHint.command":"favorites.form.targetHint.url");return t.jsx(jn,{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(E?"favorites.form.title.edit":"favorites.form.title.create")}),t.jsxs("form",{onSubmit:D,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:j3.map(({value:B,icon:O})=>t.jsxs("button",{type:"button",onClick:()=>o(B),className:"flex items-center justify-center gap-2 px-3 py-2 rounded-lg text-xs font-medium transition-all border",style:p===B?{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.${B}`)]},B))})]}),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:B=>f(B.target.value),className:"input-field",autoFocus:!0})]}),t.jsxs("div",{className:"mb-5",children:[t.jsx("label",{className:"block text-sm font-medium text-warm-600 mb-2",children:a("favorites.form.target")}),t.jsxs("div",{className:"flex gap-2",children:[t.jsx("input",{type:"text",value:c,onChange:B=>h(B.target.value),className:"input-field text-sm font-mono flex-1",placeholder:A}),w&&t.jsxs("button",{type:"button",onClick:y,disabled:x,className:"btn-ghost text-sm whitespace-nowrap flex items-center gap-1.5 disabled:opacity-50",children:[t.jsx(Fu,{size:14}),a("favorites.form.browse")]})]}),t.jsx("p",{className:"mt-1 text-2xs",style:{color:"var(--color-text-muted)"},children:A})]}),p==="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:m,onChange:B=>d(B.target.value),className:"input-field text-sm font-mono",placeholder:'--flag value "with spaces"'})]}),p!=="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:B=>b(B.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(E?"favorites.form.save":"favorites.form.create")})]})]})]})})}const L3=/^([a-z0-9]([a-z0-9-]*[a-z0-9])?\.)+[a-z]{2,}$/i;function D3({onClose:e}){const{t:s}=ft(),{error:i,success:a}=Ls(),[u,f]=S.useState(""),[p,o]=S.useState(""),[c,h]=S.useState(""),[m,d]=S.useState(""),[g,b]=S.useState(!1),[C,k]=S.useState(!1),[x,_]=S.useState(!1),[w,y]=S.useState(null);S.useEffect(()=>{let O=!1;return Promise.all([f3(),xm()]).then(([F,$])=>{O||(f(F.tunnelName),o(F.customHostname),h(F.tunnelName),d(F.customHostname),y($))}).catch(()=>{}),()=>{O=!0}},[]);const E=u.trim(),R=p.trim(),j=E!==c.trim()||R!==m.trim(),T=!!R&&(!L3.test(R)||R.toLowerCase()==="localhost"||R.toLowerCase()==="127.0.0.1"),N=!!R&&!E,D=j&&!C&&!T&&!N,A=async()=>{if(D){k(!0);try{const O=await m3({tunnelName:E,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)}}},B=async()=>{_(!0);try{try{await p3()}catch{}const O=await h1();y({status:"running",url:O.url}),a(s("tunnel.restarted"))}catch(O){i(O instanceof Error?O.message:s("tunnel.restartFailed"))}finally{_(!1)}};return t.jsxs("div",{className:"p-8",children:[t.jsx("h2",{className:"text-lg font-semibold text-warm-800 mb-1",children:s("tunnel.title")}),t.jsx("p",{className:"text-xs text-warm-400 mb-6",children:s("tunnel.description")}),w&&t.jsxs("div",{className:"mb-5 p-3 rounded-lg text-xs flex items-center gap-2",style:{backgroundColor:"var(--color-bg-hover)",color:"var(--color-text-tertiary)"},children:[t.jsx("span",{className:`w-2 h-2 rounded-full ${w.status==="running"?"bg-status-success":w.status==="error"?"bg-status-error":"bg-status-pending"}`}),t.jsx("span",{className:"font-medium",children:s(`tunnel.status.${w.status}`)}),w.url&&t.jsx("a",{href:w.url,target:"_blank",rel:"noreferrer",className:"ml-auto font-mono truncate hover:underline",style:{color:"var(--color-accent)"},children:w.url})]}),t.jsxs("div",{className:"mb-4",children:[t.jsx("label",{className:"block text-sm font-medium text-warm-600 mb-2",children:s("tunnel.name.label")}),t.jsx("input",{type:"text",value: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:p,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")}),T&&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:()=>b(!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:B,disabled:x,className:"btn-ghost text-sm disabled:opacity-50",children:x?(w==null?void 0:w.status)==="running"?s("tunnel.restarting"):s("tunnel.starting"):(w==null?void 0:w.status)==="running"?s("tunnel.restart"):s("tunnel.start")}),t.jsxs("div",{className:"flex gap-3",children:[e&&t.jsx("button",{type:"button",onClick:e,className:"btn-ghost text-sm",children:s("tunnel.close")}),t.jsx("button",{type:"button",onClick:A,disabled:!D,className:"btn-primary text-sm",children:s(C?"tunnel.saving":"tunnel.save")})]})]})]})}const cb=8;function T3({onClose:e}){const{t:s}=ft(),{error:i,success:a}=Ls(),[u,f]=S.useState(""),[p,o]=S.useState(""),[c,h]=S.useState(""),[m,d]=S.useState(!1),g=p.length>0&&p.length<cb,b=c.length>0&&p!==c,C=!!u&&p.length>=cb&&p===c&&!m,k=()=>{f(""),o(""),h("")},x=async()=>{if(C){d(!0);try{await Fw(u,p,c),a(s("account.saved")),k()}catch(_){i(_ instanceof Error&&_.message?_.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:_=>f(_.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:p,onChange:_=>o(_.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:c,onChange:_=>h(_.target.value),className:"input-field text-sm",autoComplete:"new-password"}),b&&t.jsx("p",{className:"mt-1 text-2xs text-status-error",children:s("account.mismatch")})]}),t.jsxs("div",{className:"flex items-center justify-end gap-3",children:[e&&t.jsx("button",{type:"button",onClick:e,className:"btn-ghost text-sm",children:s("account.close")}),t.jsx("button",{type:"button",onClick:x,disabled:!C,className:"btn-primary text-sm",children:s(m?"account.saving":"account.save")})]})]})}function cp(){return xt("/api/session-tags")}function R3(e){return it("/api/session-tags",e)}function M3(e,s){return dn(`/api/session-tags/${e}`,s)}function A3(e){return Wn(`/api/session-tags/${e}`)}function v1(){return xt("/api/session-aliases")}function b1(e){return it("/api/session-aliases",e)}function z3(e,s){return dn(`/api/session-aliases/${e}`,s)}function O3(e){return Wn(`/api/session-aliases/${e}`)}function up(){return xt("/api/session-settings")}function gf(e){return dn("/api/session-settings",e)}const Ue={titleBg:"#2d2d2d",titleText:"#999",bg:"#0c0c0c",text:"#cccccc",dim:"#666666",bright:"#f2f2f2",prompt:"#16c60c",success:"#16c60c",error:"#f14c4c",warning:"#cca700",info:"#569cd6",separator:"#333333"},Ot="'Cascadia Code', 'Cascadia Mono', ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, 'Courier New', monospace",dp=13,nl=8,sl=28,Ka=new Map,$i=new Map;let _u=dp;function hp(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);Ka.delete(s);const i=$i.get(s);if(i){const u=rl(s);i.forEach(f=>f(u))}});function vm(e){return Number.isFinite(e)?Math.max(nl,Math.min(sl,Math.round(e))):_u}function B3(e){if(Ka.has(e))return!0;try{return localStorage.getItem(hp(e))!==null}catch{return!1}}function rl(e){const s=Ka.get(e);if(s!==void 0)return s;let i=null;try{const a=localStorage.getItem(hp(e));if(a!==null){const u=parseInt(a,10);Number.isFinite(u)&&(i=vm(u))}}catch{}return i===null?vm(_u):(Ka.set(e,i),i)}function bm(e,s){const i=vm(s);if(Ka.get(e)===i)return;Ka.set(e,i);try{localStorage.setItem(hp(e),String(i))}catch{}const a=$i.get(e);a&&a.forEach(u=>u(i))}function Ko(e,s){bm(e,rl(e)+s)}function cu(e){const s=Math.max(nl,Math.min(sl,Math.round(e)));Number.isFinite(s)&&s!==_u&&(_u=s,$i.forEach((i,a)=>{B3(a)||i.forEach(u=>u(s))}))}function y1(e){const[s,i]=S.useState(()=>rl(e));S.useEffect(()=>{i(rl(e));let f=$i.get(e);return f||(f=new Set,$i.set(e,f)),f.add(i),()=>{const p=$i.get(e);p&&(p.delete(i),p.size===0&&$i.delete(e))}},[e]);const a=S.useCallback(f=>bm(e,f),[e]),u=S.useCallback(f=>bm(e,rl(e)+f),[e]);return[s,a,u]}const il=["#A78BFA","#F472B6","#FB923C","#FBBF24","#34D399","#60A5FA","#F87171","#94A3B8"];function ub(e){for(const s of il)if(!e.some(i=>i.color.toLowerCase()===s.toLowerCase()))return s;return il[e.length%il.length]}function P3({onClose:e}){const{t:s}=ft(),{confirm:i}=qn(),{error:a,success:u}=Ls(),[f,p]=S.useState([]),[o,c]=S.useState(!1),[h,m]=S.useState(dp),[d,g]=S.useState(!1),[b,C]=S.useState(!1),[k,x]=S.useState(!1),[_,w]=S.useState(!1),y=S.useRef(null),[E,R]=S.useState(""),[j,T]=S.useState(il[0]),[N,D]=S.useState(!1),[A,B]=S.useState(null),[O,F]=S.useState(""),[$,P]=S.useState(il[0]),[H,W]=S.useState(!1),[G,I]=S.useState([]),[z,U]=S.useState(""),[V,q]=S.useState(""),[oe,ee]=S.useState(!1),[Z,te]=S.useState(null),[Y,he]=S.useState(""),[de,ye]=S.useState(""),[le,De]=S.useState(!1);S.useEffect(()=>{let J=!1;return Promise.all([cp(),up(),v1()]).then(([se,pe,we])=>{J||(p(se),c(pe.defaultUseWorktree),m(pe.defaultFontSize),cu(pe.defaultFontSize),g(pe.imeDebug),T(ub(se)),I(we),C(!0))}).catch(se=>{J||a(se instanceof Error?se.message:"Failed to load")}),()=>{J=!0}},[a]);const Re=E.trim(),ve=!!Re&&!N,Me=S.useMemo(()=>[...f].sort((J,se)=>J.sort_order-se.sort_order||J.name.localeCompare(se.name)),[f]);S.useEffect(()=>()=>{y.current&&clearTimeout(y.current)},[]);const Oe=J=>{if(!Number.isFinite(J))return;const se=Math.max(nl,Math.min(sl,Math.round(J)));m(se),cu(se),y.current&&clearTimeout(y.current),y.current=setTimeout(()=>{gf({defaultFontSize:se}).then(pe=>{m(pe.defaultFontSize),cu(pe.defaultFontSize)}).catch(pe=>a(pe instanceof Error?pe.message:"Save failed"))},350)},tt=async J=>{x(!0);try{const se=await gf({defaultUseWorktree:J});c(se.defaultUseWorktree),u(s("sessionSettings.saved"))}catch(se){a(se instanceof Error?se.message:"Save failed")}finally{x(!1)}},nt=async J=>{var se,pe;w(!0);try{const we=await gf({imeDebug:J});g(we.imeDebug),(pe=(se=window.electronAPI)==null?void 0:se.imeSetDebug)==null||pe.call(se,we.imeDebug),u(s("sessionSettings.saved"))}catch(we){a(we instanceof Error?we.message:"Save failed")}finally{w(!1)}},ke=async()=>{if(ve){D(!0);try{const J=await R3({name:Re,color:j});p(se=>[...se,J]),R(""),T(ub([...f,J]))}catch(J){a(J instanceof Error?J.message:"Create failed")}finally{D(!1)}}},fe=J=>{B(J.id),F(J.name),P(J.color)},Te=()=>{B(null),F("")},Ce=async()=>{if(!A)return;const J=O.trim();if(J){W(!0);try{const se=await M3(A,{name:J,color:$});p(pe=>pe.map(we=>we.id===se.id?se:we)),Te()}catch(se){a(se instanceof Error?se.message:"Save failed")}finally{W(!1)}}},Ge=async J=>{if(await i({message:s("sessionSettings.tags.deleteConfirm").replace("{name}",J.name),danger:!0}))try{await A3(J.id),p(se=>se.filter(pe=>pe.id!==J.id))}catch(se){a(se instanceof Error?se.message:"Delete failed")}},Ze=z.trim(),be=V.trim(),Be=!!Ze&&!!be&&!oe,ne=S.useMemo(()=>[...G].sort((J,se)=>J.sort_order-se.sort_order||J.name.localeCompare(se.name)),[G]),_e=async()=>{if(Be){ee(!0);try{const J=await b1({name:Ze,command_template:be});I(se=>[...se,J]),U(""),q("")}catch(J){a(J instanceof Error?J.message:"Create failed")}finally{ee(!1)}}},X=J=>{te(J.id),he(J.name),ye(J.command_template)},me=()=>{te(null),he(""),ye("")},re=async()=>{if(!Z)return;const J=Y.trim(),se=de.trim();if(!(!J||!se)){De(!0);try{const pe=await z3(Z,{name:J,command_template:se});I(we=>we.map(je=>je.id===pe.id?pe:je)),me()}catch(pe){a(pe instanceof Error?pe.message:"Save failed")}finally{De(!1)}}},ae=async J=>{if(await i({message:s("sessionSettings.aliases.deleteConfirm").replace("{name}",J.name),danger:!0}))try{await O3(J.id),I(se=>se.filter(pe=>pe.id!==J.id))}catch(se){a(se instanceof Error?se.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(Vi,{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||!b,onChange:J=>tt(J.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(vN,{size:14}),s("sessionSettings.fontSize.title")]}),t.jsxs("div",{className:"flex items-center gap-3",children:[t.jsx("input",{type:"range",min:nl,max:sl,step:1,value:h,disabled:!b,onChange:J=>Oe(parseInt(J.target.value,10)),className:"flex-1 max-w-xs","aria-label":s("sessionSettings.fontSize.label")}),t.jsx("input",{type:"number",min:nl,max:sl,step:1,value:h,disabled:!b,onChange:J=>Oe(parseInt(J.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:j,onChange:J=>T(J.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:E,onChange:J=>R(J.target.value),onKeyDown:J=>{J.key==="Enter"&&(J.preventDefault(),ke())},placeholder:s("sessionSettings.tags.namePlaceholder"),className:"input text-sm flex-1",maxLength:32}),t.jsxs("button",{type:"button",onClick:ke,disabled:!ve,className:"btn-primary text-sm py-1.5 px-3 inline-flex items-center gap-1",children:[t.jsx(yn,{size:14}),s("sessionSettings.tags.add")]})]}),Me.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:Me.map(J=>{const se=A===J.id;return t.jsx("li",{className:"flex items-center gap-2 px-3 py-2 rounded-lg border",style:{borderColor:"var(--color-border)"},children:se?t.jsxs(t.Fragment,{children:[t.jsx("input",{type:"color",value:$,onChange:pe=>P(pe.target.value),className:"w-7 h-7 rounded-md cursor-pointer border border-warm-200"}),t.jsx("input",{type:"text",value:O,onChange:pe=>F(pe.target.value),onKeyDown:pe=>{pe.key==="Enter"&&(pe.preventDefault(),Ce()),pe.key==="Escape"&&Te()},autoFocus:!0,className:"input text-sm flex-1",maxLength:32}),t.jsx("button",{type:"button",onClick:Ce,disabled:H||!O.trim(),className:"p-1.5 text-status-success hover:bg-status-success/10 rounded-md",title:s("sessionSettings.tags.save"),children:t.jsx(rr,{size:14})}),t.jsx("button",{type:"button",onClick:Te,className:"p-1.5 text-warm-400 hover:bg-warm-100 rounded-md",title:s("sessionSettings.tags.cancel"),children:t.jsx(Xt,{size:14})})]}):t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"w-4 h-4 rounded-full shrink-0 border",style:{backgroundColor:J.color,borderColor:"rgba(0,0,0,0.08)"}}),t.jsx("span",{className:"text-sm text-warm-700 flex-1 truncate",children:J.name}),t.jsx("button",{type:"button",onClick:()=>fe(J),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(fi,{size:14})}),t.jsx("button",{type:"button",onClick:()=>Ge(J),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(An,{size:14})})]})},J.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:z,onChange:J=>U(J.target.value),placeholder:s("sessionSettings.aliases.namePlaceholder"),className:"input text-sm w-44",maxLength:64}),t.jsx("input",{type:"text",value:V,onChange:J=>q(J.target.value),onKeyDown:J=>{J.key==="Enter"&&(J.preventDefault(),_e())},placeholder:s("sessionSettings.aliases.commandPlaceholder"),className:"input text-sm flex-1 font-mono",maxLength:1024}),t.jsxs("button",{type:"button",onClick:_e,disabled:!Be,className:"btn-primary text-sm py-1.5 px-3 inline-flex items-center gap-1",children:[t.jsx(yn,{size:14}),s("sessionSettings.aliases.add")]})]}),ne.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:ne.map(J=>{const se=Z===J.id;return t.jsx("li",{className:"flex items-center gap-2 px-3 py-2 rounded-lg border",style:{borderColor:"var(--color-border)"},children:se?t.jsxs(t.Fragment,{children:[t.jsx("input",{type:"text",value:Y,onChange:pe=>he(pe.target.value),className:"input text-sm w-44",maxLength:64}),t.jsx("input",{type:"text",value:de,onChange:pe=>ye(pe.target.value),onKeyDown:pe=>{pe.key==="Enter"&&(pe.preventDefault(),re()),pe.key==="Escape"&&me()},autoFocus:!0,className:"input text-sm flex-1 font-mono",maxLength:1024}),t.jsx("button",{type:"button",onClick:re,disabled:le||!Y.trim()||!de.trim(),className:"p-1.5 text-status-success hover:bg-status-success/10 rounded-md",title:s("common.save"),children:t.jsx(rr,{size:14})}),t.jsx("button",{type:"button",onClick:me,className:"p-1.5 text-warm-400 hover:bg-warm-100 rounded-md",title:s("common.cancel"),children:t.jsx(Xt,{size:14})})]}):t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"text-sm text-warm-700 w-44 truncate",children:J.name}),t.jsx("code",{className:"text-xs text-warm-500 flex-1 truncate font-mono",children:J.command_template}),t.jsx("button",{type:"button",onClick:()=>X(J),className:"p-1.5 text-warm-400 hover:text-warm-700 hover:bg-warm-100 rounded-md",title:s("common.edit"),children:t.jsx(fi,{size:14})}),t.jsx("button",{type:"button",onClick:()=>ae(J),className:"p-1.5 text-warm-400 hover:text-status-error hover:bg-warm-100 rounded-md",title:s("common.delete"),children:t.jsx(An,{size:14})})]})},J.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(o5,{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:_||!b,onChange:J=>nt(J.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 I3(){return xt("/api/mcp/connection")}function F3({onClose:e}){const{t:s}=ft(),{success:i,error:a}=Ls(),[u,f]=S.useState(null),[p,o]=S.useState(null);S.useEffect(()=>{let g=!1;return I3().then(b=>{g||f(b)}).catch(()=>{}),()=>{g=!0}},[]);const c=async(g,b)=>{try{await navigator.clipboard.writeText(b),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):"",m=({label:g,text:b})=>t.jsxs("button",{type:"button",onClick:()=>c(g,b),className:"btn-ghost text-xs flex items-center gap-1",children:[p===g?t.jsx(rr,{size:14}):t.jsx(F5,{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(m,{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(m,{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 db({open:e,onClose:s}){const{t:i}=ft(),[a,u]=S.useState("account");if(!e)return null;const f=[{id:"account",label:i("settings.tabs.account"),icon:xE},{id:"session",label:i("settings.tabs.session"),icon:ml},{id:"tunnel",label:i("settings.tabs.tunnel"),icon:Yw},{id:"mcp",label:i("settings.tabs.mcp"),icon:QE}];return t.jsx(jn,{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:p,label:o,icon:c})=>{const h=a===p;return t.jsxs("button",{type:"button",onClick:()=>u(p),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(c,{size:14}),t.jsx("span",{children:o})]},p)})}),t.jsxs("div",{className:"px-4 py-3 mt-auto text-[11px] tracking-wide",style:{color:"var(--color-text-muted)"},children:["v","0.2.52"]})]}),t.jsxs("div",{className:"flex-1 min-w-0",children:[a==="account"&&t.jsx(T3,{onClose:s}),a==="session"&&t.jsx(P3,{onClose:s}),a==="tunnel"&&t.jsx(D3,{onClose:s}),a==="mcp"&&t.jsx(F3,{onClose:s})]})]})})})}const ym=["#55708F","#4F7A68","#9A783F","#A15F5A","#74658A","#925F73","#477B7D","#747A50"];function H3(e,s){let i=0;for(let a=0;a<e.length;a++)i=(i<<5)-i+e.charCodeAt(a)|0;return Math.abs(i)%s}function Ga(e){return e.color&&/^#[0-9a-f]{6}$/i.test(e.color)?e.color:ym[H3(e.id,ym.length)]}const hb=192,$3=88,Hc=8;function U3({project:e,anchorX:s,anchorY:i,onPick:a,onClose:u}){const f=S.useRef(null),[p,o]=S.useState({left:s,top:i}),c=Ga(e);return S.useLayoutEffect(()=>{const h=Math.min(Math.max(s,Hc),window.innerWidth-hb-Hc),m=Math.min(Math.max(i,Hc),window.innerHeight-$3-Hc);o({left:h,top:m})},[s,i]),S.useEffect(()=>{const h=d=>{var g;(g=f.current)!=null&&g.contains(d.target)||u()},m=d=>{d.key==="Escape"&&u()};return window.addEventListener("mousedown",h),window.addEventListener("keydown",m),()=>{window.removeEventListener("mousedown",h),window.removeEventListener("keydown",m)}},[u]),rn.createPortal(t.jsxs("div",{ref:f,role:"menu",className:"z-tooltip",style:{position:"fixed",left:p.left,top:p.top,width:hb,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:ym.map(h=>{const m=e.color?h.toLowerCase()===e.color.toLowerCase():h===c&&!e.color;return t.jsx("button",{onClick:()=>a(h),"aria-label":h,style:{width:20,height:20,borderRadius:6,background:h,border:m?"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 al(e,s){return e instanceof Error&&e.message.trim()?e.message:typeof e=="string"&&e.trim()?e:s}function W3(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 q3={sm:"btn-icon-sm",md:"btn-icon-md",lg:"btn-icon-lg"},K3={default:"",active:"btn-icon-active",danger:"btn-icon-danger"},Sn=S.forwardRef(function({label:s,size:i="md",variant:a="default",pressed:u,type:f="button",title:p,className:o,...c},h){return t.jsx("button",{ref:h,type:f,"aria-label":s,"aria-pressed":u,title:p??s,className:Hs("btn-icon",q3[i],K3[a],o),...c})});function G3(e){return e==="executable"?sp:e==="command"?pi:fl}function V3({onLogout:e,authRequired:s,connected:i,onEvent:a,onClose:u,collapsed:f=!1,onToggleCollapsed:p}){var Be;const[o,c]=S.useState([]),[h,m]=S.useState({}),[d,g]=S.useState(null),[b,C]=S.useState(!1),[k,x]=S.useState(null),[_,w]=S.useState([]),[y,E]=S.useState(!1),[R,j]=S.useState(null),[T,N]=S.useState(!1),[D,A]=S.useState(null),[B,O]=S.useState(!1),[F,$]=S.useState(null),[P,H]=S.useState(null),W=Ws(),G=xi(),{t:I,toggleLang:z}=ft(),{theme:U,toggleTheme:V}=x3(),{enabled:q,supported:oe,toggleNotification:ee}=lp(),{error:Z,success:te,info:Y,warning:he}=Ls(),{confirm:de}=qn(),ye=((Be=W.pathname.match(/^\/projects\/([^/]+)/))==null?void 0:Be[1])||null;S.useEffect(()=>{nt(),De(),xm().then(A).catch(()=>{})},[]);async function le(){if(!B){O(!0);try{const ne=await xm();if(A(ne),ne.status==="running"&&ne.url){await navigator.clipboard.writeText(ne.url),te(I("tunnel.urlCopied"));return}const _e=await h1(),X={status:"running",url:_e.url};A(X);try{await navigator.clipboard.writeText(_e.url),te(I("tunnel.urlCopied"))}catch{te(_e.url)}}catch(ne){Z(ne instanceof Error?ne.message:I("tunnel.restartFailed"))}finally{O(!1)}}}function De(){o3().then(w).catch(()=>{})}const Re=async ne=>{try{R?await c3(R.id,ne):await l3(ne),E(!1),j(null),De()}catch(_e){Z(_e instanceof Error?_e.message:"Failed to save favorite")}},ve=async ne=>{try{await d3(ne)}catch(_e){const X=_e instanceof Error?_e.message:I("favorites.launchFailed");Z(`${I("favorites.launchFailed")}: ${X}`)}},Me=async(ne,_e)=>{if(_e.preventDefault(),_e.stopPropagation(),!!await de({message:I("favorites.deleteConfirm"),danger:!0}))try{await u3(ne),w(X=>X.filter(me=>me.id!==ne))}catch(X){Z(X instanceof Error?X.message:"Failed to delete favorite")}},Oe=(ne,_e)=>{_e.preventDefault(),_e.stopPropagation(),j(ne),E(!0)};S.useEffect(()=>{const ne=()=>nt();return window.addEventListener("projects:changed",ne),()=>window.removeEventListener("projects:changed",ne)},[]),S.useEffect(()=>{const ne=()=>tt();return window.addEventListener("review:changed",ne),()=>window.removeEventListener("review:changed",ne)},[]),S.useEffect(()=>a(ne=>{var _e;if(ne.type==="project:status-changed"&&ne.projectId&&m(X=>({...X,[ne.projectId]:{running:ne.running??0,completed:ne.completed??0,total:ne.total??0,running_sessions:ne.running_sessions??0,running_discussions:ne.running_discussions??0}})),ne.type==="todo:status-changed"&&tt(),ne.type==="memory:ingest-finished"){const X=o.find(je=>je.id===ne.projectId),me=(X==null?void 0:X.name)??"",re=ne.sourceTitle?`“${ne.sourceTitle}”`:ne.sourceType??"",ae=me?`[${me}] `:"";if(ne.error){Z(`${ae}${I("wiki.ingest.toast.failed")}: ${ne.error}`,6e3);return}const J=ne.created??0,se=ne.updated??0,pe=ne.edgesAdded??0;if(J+se+pe>0){const je=I("wiki.ingest.toast.success").replace("{source}",re).replace("{created}",String(J)).replace("{updated}",String(se)).replace("{edges}",String(pe));te(`${ae}${je}`)}else(_e=ne.skipped)!=null&&_e.parseFailed?he(`${ae}${I("wiki.ingest.toast.parseFailed").replace("{source}",re)}`,5e3):Y(`${ae}${I("wiki.ingest.toast.empty").replace("{source}",re)}`,4e3)}}),[a,o,I,Z,Y,te,he]),S.useEffect(()=>{tt()},[]);function tt(){d1({hours:24}).then(ne=>g(ne.total_todos)).catch(()=>{})}function nt(){Uu().then(ne=>{c(ne),ne.forEach(_e=>{n1(_e.id).then(X=>{m(me=>({...me,[_e.id]:X}))}).catch(()=>{})})}).catch(()=>{})}const ke=()=>{u==null||u()},fe=async(ne,_e)=>{await e1({name:ne,path:_e}),C(!1),window.dispatchEvent(new Event("projects:changed"))},Te=S.useCallback(async(ne,_e)=>{const X=o.map(je=>je.id),me=X.indexOf(ne);if(me<0)return;const re=X.filter(je=>je!==ne),ae=_e>me?_e-1:_e;if(ae===me)return;const J=[...re.slice(0,ae),ne,...re.slice(ae)],se=o,pe=new Map(o.map(je=>[je.id,je])),we=J.map(je=>pe.get(je)).filter(Boolean);c(we);try{await ON(J)}catch(je){c(se),Z(je instanceof Error?je.message:"Failed to reorder projects")}},[o,Z]),Ce=S.useRef(!1),Ge=S.useCallback((ne,_e)=>{if(_e.button!==0||_e.target.closest("button"))return;_e.preventDefault();const me=_e.clientX,re=_e.clientY,ae=6;let J=!1,se=null;const pe=qe=>{const Ee=document.querySelectorAll("[data-workspace-item]");if(Ee.length===0)return null;const st=Ee[0].getBoundingClientRect();if(qe<st.top)return 0;const lt=Ee[Ee.length-1].getBoundingClientRect();if(qe>lt.bottom)return Ee.length;for(let yt=0;yt<Ee.length;yt++){const mt=Ee[yt].getBoundingClientRect();if(qe>=mt.top&&qe<=mt.bottom){const pt=mt.top+mt.height/2;return qe<pt?yt:yt+1}}return null},we=qe=>{if(!J){if(Math.hypot(qe.clientX-me,qe.clientY-re)<ae)return;J=!0,$(ne)}const Ee=pe(qe.clientY);Ee!==se&&(se=Ee,H(Ee))},je=()=>{window.removeEventListener("mousemove",we),window.removeEventListener("mouseup",$e),window.removeEventListener("keydown",Je)},$e=()=>{if(je(),!J)return;Ce.current=!0,requestAnimationFrame(()=>{Ce.current=!1});const qe=se;$(null),H(null),qe!==null&&Te(ne,qe)},Je=qe=>{qe.key==="Escape"&&(je(),$(null),H(null),J&&(Ce.current=!0,requestAnimationFrame(()=>{Ce.current=!1})))};window.addEventListener("mousemove",we),window.addEventListener("mouseup",$e),window.addEventListener("keydown",Je)},[Te]),Ze=async(ne,_e)=>{if(_e.preventDefault(),_e.stopPropagation(),!!await de({message:I("projects.deleteConfirm"),danger:!0}))try{await t1(ne),c(X=>X.filter(me=>me.id!==ne)),window.dispatchEvent(new Event("projects:changed")),ye===String(ne)&&G("/")}catch(X){Z(al(X,I("errors.projectDelete")))}},be=ne=>t.jsx("div",{className:"pointer-events-none absolute left-2 right-2 h-0.5 rounded-full",style:{backgroundColor:"var(--color-accent)",zIndex:10,...ne==="above"?{top:-1}:{bottom:-1}}});if(f){const ne=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(Sn,{onClick:p,label:I("sidebar.expand"),size:"lg",children:t.jsx(KE,{size:16})}),ne,t.jsx(Un,{to:"/",onClick:ke,className:"relative flex items-center justify-center w-9 h-9 rounded-lg transition-colors hover:bg-theme-hover",style:W.pathname==="/"?{backgroundColor:"var(--color-bg-hover)",color:"var(--color-text-primary)"}:{color:"var(--color-text-tertiary)"},title:I("sidebar.home"),children:t.jsx(V0,{size:16})}),t.jsxs(Un,{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:W.pathname==="/review"?{backgroundColor:"var(--color-bg-hover)",color:"var(--color-text-primary)"}:{color:"var(--color-text-tertiary)"},title:I("sidebar.review"),children:[t.jsx(bu,{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(Un,{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:W.pathname==="/agenda"?{backgroundColor:"var(--color-bg-hover)",color:"var(--color-text-primary)"}:{color:"var(--color-text-tertiary)"},title:I("sidebar.agenda"),children:t.jsx(am,{size:16})}),ne,t.jsx("div",{className:"flex-1 overflow-y-auto w-full flex flex-col items-center gap-1 py-1",children:o.map(_e=>{const X=h[_e.id],me=ye===String(_e.id),re=X?X.running+X.running_sessions+X.running_discussions:0,ae=re>0,J=Ga(_e);return t.jsxs(Un,{to:`/projects/${_e.id}`,onClick:ke,className:"relative flex items-center justify-center w-9 h-9 rounded-lg transition-colors hover:bg-theme-hover",style:me?{backgroundColor:"var(--color-bg-hover)"}:void 0,title:ae?`${_e.name} · ${re} ${I("detail.live")}`:_e.name,children:[me&&t.jsx("span",{className:"absolute left-0 top-1/4 bottom-1/4 w-[3px] rounded-r-full",style:{backgroundColor:J}}),t.jsx("span",{className:`w-2.5 h-2.5 rounded-[3px] ${ae?"workspace-dot-pulse":""}`,style:{backgroundColor:J,opacity:me||ae?1:.55}})]},_e.id)})}),ne,t.jsx("span",{className:`w-1.5 h-1.5 rounded-full my-1 ${i?"bg-status-success":"bg-status-error"}`,title:i?I("detail.live"):"Disconnected"}),t.jsx(Sn,{onClick:V,label:I(U==="light"?"theme.dark":"theme.light"),size:"lg",children:U==="light"?t.jsx(X0,{size:16}):t.jsx(Q0,{size:16})}),t.jsx(Sn,{onClick:()=>N(!0),label:I("settings.title"),size:"lg",children:t.jsx(wu,{size:16})}),t.jsx(db,{open:T,onClose:()=>N(!1)})]})}return t.jsxs("div",{className:"flex flex-col h-full bg-theme-bg-secondary border-none",onDragStart:ne=>ne.preventDefault(),children:[t.jsxs("div",{className:"px-4 pt-5 pb-3 flex items-center justify-between",children:[t.jsxs(Un,{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(Sn,{onClick:p,label:I("sidebar.collapse"),size:"sm",className:"hidden md:inline-flex flex-shrink-0",children:t.jsx(WE,{size:16})})]}),t.jsxs("nav",{className:"px-3 mb-2 space-y-0.5",children:[t.jsxs(Un,{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 ${W.pathname==="/"?"font-medium":""}`,style:W.pathname==="/"?{backgroundColor:"var(--color-bg-hover)",color:"var(--color-text-primary)",boxShadow:"var(--shadow-soft)"}:{color:"var(--color-text-tertiary)"},children:[W.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(V0,{size:16}),I("sidebar.home")]}),t.jsxs(Un,{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 ${W.pathname==="/review"?"font-medium":""}`,style:W.pathname==="/review"?{backgroundColor:"var(--color-bg-hover)",color:"var(--color-text-primary)",boxShadow:"var(--shadow-soft)"}:{color:"var(--color-text-tertiary)"},children:[W.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(bu,{size:16}),t.jsx("span",{className:"flex-1",children:I("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(Un,{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 ${W.pathname==="/agenda"?"font-medium":""}`,style:W.pathname==="/agenda"?{backgroundColor:"var(--color-bg-hover)",color:"var(--color-text-primary)",boxShadow:"var(--shadow-soft)"}:{color:"var(--color-text-tertiary)"},children:[W.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(am,{size:16}),I("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:I("sidebar.workspaces")}),t.jsx(Sn,{onClick:()=>C(!0),label:I("projects.new"),size:"sm",children:t.jsx(yn,{size:14})})]}),t.jsx("div",{className:"space-y-0.5",children:o.map((ne,_e)=>{const X=h[ne.id],me=ye===String(ne.id),re=X?X.running+X.running_sessions+X.running_discussions:0,ae=re>0,J=Ga(ne),se=F===ne.id,pe=F!==null&&P===_e,we=F!==null&&_e===o.length-1&&P===o.length;return t.jsxs("div",{className:"relative","data-workspace-item":!0,children:[pe&&be("above"),t.jsxs(Un,{to:`/projects/${ne.id}`,draggable:!1,onDragStart:je=>je.preventDefault(),onClick:je=>{if(Ce.current){je.preventDefault();return}ke()},onMouseDown:je=>Ge(ne.id,je),onContextMenu:je=>{je.preventDefault(),x({project:ne,x:je.clientX,y:je.clientY})},className:`relative flex items-center gap-2.5 px-3 py-1.5 rounded-lg text-sm transition-all duration-200 hover:bg-theme-hover active:scale-95 group ${me?"font-medium":""} ${se?"opacity-50":""}`,style:me?{backgroundColor:"var(--color-bg-hover)",color:"var(--color-text-primary)",boxShadow:"var(--shadow-soft)",cursor:F?"grabbing":"pointer",userSelect:"none"}:{color:"var(--color-text-tertiary)",cursor:F?"grabbing":"pointer",userSelect:"none"},children:[me&&t.jsx("span",{className:"absolute left-0 top-1/4 bottom-1/4 w-[3px] rounded-r-full",style:{backgroundColor:J}}),t.jsx("span",{className:`w-1.5 h-3 rounded-[2px] flex-shrink-0 ${ae?"workspace-dot-pulse":""}`,style:{backgroundColor:J,opacity:me||ae?1:.55},title:ae?`${I("sidebar.workspaces")} · ${re} ${I("detail.live")}`:ne.name}),t.jsx("span",{className:"truncate flex-1",children:ne.name}),t.jsx(Sn,{onClick:je=>Ze(ne.id,je),label:I("projects.delete"),size:"sm",variant:"danger",className:"flex-shrink-0 opacity-0 group-hover:opacity-100 focus-visible:opacity-100",children:t.jsx(Xt,{size:12})})]}),we&&be("below")]},ne.id)})})]}),b&&t.jsx(x1,{onSubmit:(ne,_e)=>fe(ne,_e),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:I("sidebar.favorites")}),t.jsx(Sn,{onClick:()=>{j(null),E(!0)},label:I("favorites.add"),size:"sm",children:t.jsx(yn,{size:14})})]}),t.jsx("div",{className:"space-y-0.5 max-h-48 overflow-y-auto",children:_.map(ne=>{const _e=G3(ne.type);return t.jsxs("button",{onClick:()=>ve(ne.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:ne.target,children:[t.jsx(_e,{size:14,className:"flex-shrink-0"}),t.jsx("span",{className:"truncate flex-1 text-left",children:ne.name}),t.jsx("span",{onClick:X=>Oe(ne,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:I("favorites.edit"),children:t.jsx(um,{size:12})}),t.jsx("span",{onClick:X=>Me(ne.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:I("favorites.delete"),children:t.jsx(Xt,{size:12})})]},ne.id)})})]}),y&&t.jsx(N3,{initial:R??void 0,onSubmit:Re,onCancel:()=>{E(!1),j(null)}}),k&&t.jsx(U3,{project:k.project,anchorX:k.x,anchorY:k.y,onPick:async ne=>{try{const _e=await hm(k.project.id,{color:ne});c(X=>X.map(me=>me.id===_e.id?{...me,color:_e.color}:me)),window.dispatchEvent(new Event("projects:changed"))}catch(_e){Z(_e instanceof Error?_e.message:"Failed to update color")}x(null)},onClose:()=>x(null)}),t.jsx(db,{open:T,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?I("detail.live"):"Disconnected"}),t.jsx(Sn,{onClick:V,label:I(U==="light"?"theme.dark":"theme.light"),children:U==="light"?t.jsx(X0,{size:16}):t.jsx(Q0,{size:16})}),t.jsx(Sn,{onClick:z,label:I("lang.toggle"),className:"text-xs font-medium",children:I("lang.toggle")}),oe&&t.jsx(Sn,{onClick:ee,label:"Notification"in window&&Notification.permission==="denied"?I("notification.blocked"):I("notification.toggle"),variant:q?"active":"default",pressed:q,children:q?t.jsx(i5,{size:16}):t.jsx(s5,{size:16})}),t.jsx(Sn,{onClick:le,disabled:B,label:I("tunnel.start"),variant:(D==null?void 0:D.status)==="running"?"active":"default",pressed:(D==null?void 0:D.status)==="running",title:(D==null?void 0:D.status)==="running"&&D.url?`${D.url} — ${I("tunnel.urlCopied")}`:I(B?"tunnel.starting":"tunnel.start"),children:t.jsx(Yw,{size:16})}),t.jsx(Sn,{onClick:()=>N(!0),label:I("settings.title"),children:t.jsx(wu,{size:16})}),s&&t.jsx(Sn,{onClick:e,label:I("projects.logout"),variant:"danger",className:"ml-auto",children:t.jsx(DE,{size:16})})]})})]})}function Y3({children:e,onLogout:s,authRequired:i,connected:a,onEvent:u}){const[f,p]=S.useState(!1),{t:o}=ft(),[c,h]=S.useState(()=>localStorage.getItem("sidebarCollapsed")==="1"),m=()=>{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 @@ ${A.message}
|
|
|
657
657
|
`)?"":`
|
|
658
658
|
`;await i8(e,a+p+u+`
|
|
659
659
|
`)}async function lP(e,s,i){await it(`/api/projects/${e}/vault/ignore/unhide`,{path:s,isDir:i})}function a8(e){return e<1024?`${e}B`:e<1024*1024?`${(e/1024).toFixed(1)}KB`:`${(e/1024/1024).toFixed(2)}MB`}function o8(e){const s=new Map,i=new Map;for(const u of e){const f=u.stem.toLowerCase(),p=u.title.toLowerCase(),o=s.get(f)??[];o.push(u.relativePath),s.set(f,o);const c=i.get(p)??[];c.push(u.relativePath),i.set(p,c)}const a=new Map;for(const u of e){const f=u.relativePath.includes("/")?u.relativePath.slice(0,u.relativePath.lastIndexOf("/")+1):"",p=[];for(const o of u.wikilinks){const c=o.toLowerCase(),h=s.get(c)??i.get(c)??[];if(h.length===0)continue;const m=h.length===1?h[0]:h.find(d=>d.startsWith(f))??h[0];m&&m!==u.relativePath&&!p.includes(m)&&p.push(m)}a.set(u.relativePath,p)}return a}function Rp({projectId:e,mode:s,selectedPaths:i,includeLinked:a,onChange:u}){const{t:f}=ft(),[p,o]=S.useState([]),[c,h]=S.useState(!1),[m,d]=S.useState(!1),[g,b]=S.useState(""),[C,k]=S.useState(!1),[x,_]=S.useState("");S.useEffect(()=>{let T=!1;return n8(e).then(N=>{T||(o(N.files),h(!0))}).catch(N=>{console.error("Load vault files failed",N),h(!0)}),()=>{T=!0}},[e]);const w=S.useMemo(()=>{const T=x.toLowerCase(),N=T?p.filter(A=>A.stem.toLowerCase().includes(T)||A.title.toLowerCase().includes(T)||A.relativePath.toLowerCase().includes(T)):p,D={};for(const A of N){const B=A.relativePath.includes("/")?A.relativePath.split("/").slice(0,-1).join("/"):".";D[B]||(D[B]=[]),D[B].push(A)}return D},[p,x]),y=S.useMemo(()=>o8(p),[p]),E=T=>{const N=new Set(i);if(N.has(T))N.delete(T);else if(N.add(T),a){const D=y.get(T)??[];for(const A of D)N.add(A)}u("selected",Array.from(N),a)},R=async()=>{k(!0);try{const N=await s8(e,s==="auto"?"all":s,i);b(N.block||f("vault.empty"))}catch(T){b(T instanceof Error?T.message:"Preview failed")}finally{k(!1)}},j=s!=="none"&&s!=="auto";return S.useEffect(()=>{m&&j&&R()},[m,s,i]),t.jsxs("div",{className:"rounded-lg border border-warm-200 bg-warm-50 p-3",children:[t.jsxs("div",{className:"flex items-center justify-between mb-2",children:[t.jsx("div",{className:"text-sm font-medium text-warm-800",children:f("vaultInject.title")}),j&&t.jsxs("button",{type:"button",onClick:()=>d(T=>!T),className:"inline-flex items-center gap-1 text-xs text-warm-600 hover:text-warm-800",children:[m?t.jsx(q5,{size:12}):t.jsx(cm,{size:12}),f("vaultInject.previewToggle")]})]}),t.jsx("div",{className:"flex flex-wrap gap-1.5 mb-2",children:["none","auto","all","selected"].map(T=>t.jsx("button",{type:"button",onClick:()=>u(T,T==="selected"?i:[],a),className:`px-3 py-1.5 rounded-md text-xs ${s===T?"bg-warm-700 text-warm-50":"bg-warm-100 text-warm-700 hover:bg-warm-200"}`,children:f(`vaultInject.mode${T.charAt(0).toUpperCase()+T.slice(1)}`)},T))}),s==="auto"&&t.jsx("div",{className:"text-xs text-warm-500 mt-1 leading-snug",children:f("vaultInject.autoHint").replace("{count}",String(p.length))}),s==="selected"&&t.jsx("div",{className:"mt-2",children:c?p.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:T=>u(s,i,T.target.checked)}),f("vaultInject.includeLinked")]}),t.jsx("input",{value:x,onChange:T=>_(T.target.value),placeholder:f("vaultInject.searchPlaceholder"),className:"w-full px-2 py-1.5 rounded-md border border-warm-200 bg-warm-0 text-sm focus:outline-none focus:ring-2 focus:ring-warm-400 mb-2"}),t.jsx("div",{className:"max-h-56 overflow-y-auto border border-warm-200 rounded-md",children:Object.keys(w).length===0?t.jsx("div",{className:"text-xs text-warm-500 italic px-2 py-2",children:f("vaultInject.noResults")}):Object.entries(w).sort(([T],[N])=>T.localeCompare(N)).map(([T,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:T}),t.jsx("div",{className:"divide-y divide-warm-100",children:N.map(D=>{const A=(y.get(D.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(D.relativePath),onChange:()=>E(D.relativePath)}),D.kind==="html"?t.jsx(sp,{size:12,className:"text-warm-500 shrink-0"}):t.jsx(tl,{size:12,className:"text-warm-500 shrink-0"}),t.jsx("span",{className:"text-sm text-warm-800 truncate flex-1",title:D.relativePath,children:D.title||D.stem}),a&&A>0&&t.jsx("span",{className:"text-[10px] text-warm-600 bg-warm-200 px-1.5 py-0.5 rounded-md shrink-0",title:D.wikilinks.join(", "),children:f("vaultInject.linkedAdded").replace("{n}",String(A))}),t.jsx("span",{className:"text-[10px] text-warm-500 font-mono shrink-0",children:a8(D.size)})]},D.relativePath)})})]},T))}),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"&&p.length>0&&t.jsx("div",{className:"text-xs text-warm-500 mt-1",children:f("vaultInject.allCount").replace("{count}",String(p.length))}),m&&j&&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 l8(e){if(!e)return[];try{const s=JSON.parse(e);return Array.isArray(s)?s.map(String).filter(Boolean):[]}catch{return[]}}let c8=0;function U_({onSave:e,onCancel:s,initialTitle:i="",initialDescription:a="",initialCliTool:u,initialDependsOn:f,initialMaxTurns:p,initialUseWorktree:o=null,initialMemoryInjectMode:c="none",initialMemoryRawFilePaths:h=null,projectId:m,projectCliTool:d="claude",projectIsGitRepo:g=!1,projectUseWorktree:b=!0,existingImages:C=[],todoId:k,onDeleteImage:x,availableTodos:_=[]}){const[w,y]=S.useState(i),[E,R]=S.useState(a),[j,T]=S.useState(u||d||"claude"),[N,D]=S.useState(f??""),[A,B]=S.useState((p==null?void 0:p.toString())??""),[O,F]=S.useState(o===1?"force-on":o===0?"force-off":"inherit"),[$,P]=S.useState(c),[H,W]=S.useState(l8(h)),[G,I]=S.useState(!1),[z,U]=S.useState([]),[V,q]=S.useState(C),oe=S.useRef(null),ee=S.useRef(null),{t:Z}=ft(),te=S.useCallback(ve=>{const Me=Array.from(ve).filter(Oe=>Oe.type.startsWith("image/"));for(const Oe of Me){const tt=new FileReader;tt.onload=()=>{const nt=tt.result,ke=`pending-${++c8}`;U(fe=>[...fe,{id:ke,name:Oe.name,data:nt,preview:nt}])},tt.readAsDataURL(Oe)}},[]),Y=S.useCallback(ve=>{var nt;const Me=(nt=ve.clipboardData)==null?void 0:nt.items;if(!Me)return;const Oe=[];for(let ke=0;ke<Me.length;ke++)Me[ke].type.startsWith("image/")&&Oe.push(Me[ke]);if(Oe.length===0)return;ve.preventDefault();const tt=[];for(const ke of Oe){const fe=ke.getAsFile();fe&&tt.push(fe)}te(tt)},[te]),he=S.useCallback(ve=>{var Me;ve.preventDefault(),ve.stopPropagation(),(Me=ve.dataTransfer)!=null&&Me.files&&te(ve.dataTransfer.files)},[te]),de=S.useCallback(ve=>{ve.preventDefault(),ve.stopPropagation()},[]),ye=ve=>{U(Me=>Me.filter(Oe=>Oe.id!==ve))},le=ve=>{x&&x(ve),q(Me=>Me.filter(Oe=>Oe.id!==ve))},De=ve=>{if(ve.preventDefault(),!w.trim())return;const Me=A?parseInt(A,10):void 0,Oe=O==="force-on"?1:O==="force-off"?0:null;e(w.trim(),E.trim(),j,z.length>0?z:void 0,N||void 0,Me||void 0,Oe,$,[],H)},Re=V.length+z.length;return t.jsxs("form",{onSubmit:De,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:w,onChange:ve=>y(ve.target.value),className:"input-field",autoFocus:!0})}),t.jsxs("div",{className:"mb-4",children:[t.jsx("textarea",{ref:oe,placeholder:Z("todoForm.descPlaceholder"),value:E,onChange:ve=>R(ve.target.value),onPaste:Y,onDrop:he,onDragOver:de,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 ve;return(ve=ee.current)==null?void 0:ve.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(qa,{size:14}),Z("todoForm.addImage")]}),t.jsx("span",{className:"text-2xs text-warm-300",children:Z("todoForm.pasteHint")})]}),t.jsx("input",{ref:ee,type:"file",accept:"image/*",multiple:!0,className:"hidden",onChange:ve=>{ve.target.files&&te(ve.target.files),ve.target.value=""}})]}),Re>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:["(",Re,")"]})]}),t.jsxs("div",{className:"flex flex-wrap gap-2",children:[V.map(ve=>t.jsxs("div",{className:"relative group",children:[t.jsx("img",{src:k?_m(k,ve.id):"",alt:ve.originalName,className:"h-20 w-20 object-cover rounded-lg border border-warm-200"}),t.jsx("button",{type:"button",onClick:()=>le(ve.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(Xt,{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:ve.originalName})})]},ve.id)),z.map(ve=>t.jsxs("div",{className:"relative group",children:[t.jsx("img",{src:ve.preview,alt:ve.name,className:"h-20 w-20 object-cover rounded-lg border border-accent/30"}),t.jsx("button",{type:"button",onClick:()=>ye(ve.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(Xt,{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:ve.name})})]},ve.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:j,onChange:ve=>T(ve.target.value),className:"input-field text-sm",children:Is.map(ve=>t.jsx("option",{value:ve.value,children:ve.label},ve.value))})]})}),j==="claude"&&t.jsxs("div",{className:"mb-4",children:[t.jsx("label",{className:"block text-xs font-medium text-warm-500 mb-1.5",children:Z("todoForm.maxTurns")}),t.jsx("input",{type:"number",min:"1",max:"500",placeholder:Z("todoForm.maxTurnsPlaceholder"),value:A,onChange:ve=>B(ve.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:()=>F("inherit")}),t.jsxs("span",{children:[Z("todoForm.worktreeInherit"),t.jsxs("span",{className:"text-2xs text-warm-400 ml-1",children:["(",Z(b?"todoForm.worktreeProjectDefaultOn":"todoForm.worktreeProjectDefaultOff"),")"]})]})]}),t.jsxs("label",{className:"flex items-center gap-2 cursor-pointer text-sm",children:[t.jsx("input",{type:"radio",name:"useWorktreeMode",checked:O==="force-on",onChange:()=>F("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:()=>F("force-off")}),t.jsx("span",{children:Z("todoForm.worktreeForceOff")})]})]}),(O==="force-off"||O==="inherit"&&!b)&&t.jsx("p",{className:"text-2xs text-status-warning mt-1.5",children:Z("todoForm.worktreeMainWarning")})]}),_.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:ve=>D(ve.target.value),className:"input-field text-sm",children:[t.jsx("option",{value:"",children:Z("todoForm.noDependency")}),_.map(ve=>t.jsxs("option",{value:ve.id,children:[ve.title," (",Z(`status.${ve.status}`),")"]},ve.id))]}),N&&t.jsx("p",{className:"text-2xs text-warm-400 mt-1",children:Z("todoForm.dependsOnHint")})]}),m&&t.jsx("div",{className:"mb-4",children:t.jsx(Rp,{projectId:m,mode:$,selectedPaths:H,includeLinked:G,onChange:(ve,Me,Oe)=>{P(ve),W(Me),I(Oe)}})}),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:!w.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",Mp="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 W_(){return t.jsx("div",{className:"my-1 border-t border-warm-200"})}function gi(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 ir({x:e,y:s,onClose:i,children:a}){const u=S.useRef(null),[f,p]=S.useState({top:s,left:e,visible:!1});return S.useLayoutEffect(()=>{const o=u.current;if(!o)return;const c=window.innerWidth,h=window.innerHeight;let m=e,d=s;m+o.offsetWidth>c-8&&(m=Math.max(8,c-8-o.offsetWidth)),d+o.offsetHeight>h-8&&(d=Math.max(8,h-8-o.offsetHeight)),m<8&&(m=8),d<8&&(d=8),p({top:d,left:m,visible:!0})},[e,s]),S.useEffect(()=>{const o=m=>{var d;(d=u.current)!=null&&d.contains(m.target)||i()},c=m=>{m.key==="Escape"&&i()},h=()=>i();return document.addEventListener("mousedown",o),document.addEventListener("keydown",c),window.addEventListener("scroll",h,!0),window.addEventListener("resize",i),()=>{document.removeEventListener("mousedown",o),document.removeEventListener("keydown",c),window.removeEventListener("scroll",h,!0),window.removeEventListener("resize",i)}},[i]),rn.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 u8({children:e}){const[s,i]=S.useState(!1),[a,u]=S.useState(!1),f=S.useRef(null),p=S.useRef(null),[o,c]=S.useState({top:0,left:0}),h=S.useCallback(()=>{if(!f.current)return;const d=f.current.getBoundingClientRect(),g=window.innerWidth,b=window.innerHeight;let C=d.bottom+4;const k=p.current;if(k){const x=k.offsetWidth,_=k.offsetHeight;let w=d.right-x;w<8&&(w=8),w+x>g-8&&(w=g-8-x),C+_>b-8&&(C=d.top-_-4),c({top:C,left:w}),u(!0)}else c({top:C,left:Math.max(8,d.right-180)})},[]);S.useEffect(()=>{if(!s){u(!1);return}h();const d=requestAnimationFrame(h),g=b=>{var k,x;const C=b.target;(k=f.current)!=null&&k.contains(C)||(x=p.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 m=(Array.isArray(e)?e:[e]).filter(Boolean);return m.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(np,{size:14})}),s&&rn.createPortal(t.jsx("div",{ref:p,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:m}),document.body)]})}function d8({todo:e,allTodos:s=[],projectCliTool:i,projectIsGitRepo:a,projectUseWorktree:u,onStart:f,onStop:p,onDelete:o,onEdit:c,onMerge:h,onCleanup:m,onRetry:d,onContinue:g,onFix:b,onSchedule:C,onScheduleOnReset:k,resetsAt:x,onEvent:_,isInteractive:w,onSendInput:y,isDragSource:E,isDragging:R,isDragOver:j,isValidDropTarget:T,onDragStart:N,onDragEnd:D,onDragOverTarget:A,onDragLeaveTarget:B,onDropTarget:O,onRemoveDependency:F,debugLogging:$,showTokenUsage:P,isChainMember:H}){const[W,G]=S.useState(!1),[I,z]=S.useState(!1),[U,V]=S.useState([]),[q,oe]=S.useState(!1),[ee,Z]=S.useState(!1),[te,Y]=S.useState(null),[he,de]=S.useState(!1),[ye,le]=S.useState(null),[De,Re]=S.useState(!1),[ve,Me]=S.useState(null),[Oe,tt]=S.useState(!1),[nt,ke]=S.useState(null),[fe,Te]=S.useState(!1),[Ce,Ge]=S.useState(null),[Ze,be]=S.useState(!1),[Be,ne]=S.useState(""),[_e,X]=S.useState(!1),[me,re]=S.useState(null),[ae,J]=S.useState(!1),[se,pe]=S.useState(""),[we,je]=S.useState(!1),[$e,Je]=S.useState(null),[qe,Ee]=S.useState(null),[st,lt]=S.useState(!1),[yt,mt]=S.useState(!1),[pt,dt]=S.useState(!1),[kt,gt]=S.useState(()=>{const ge=new Date;ge.setHours(ge.getHours()+1),ge.setMinutes(0,0,0);const Ae=ge.getFullYear(),rt=String(ge.getMonth()+1).padStart(2,"0"),_t=String(ge.getDate()).padStart(2,"0"),Pt=String(ge.getHours()).padStart(2,"0"),As=String(ge.getMinutes()).padStart(2,"0");return`${Ae}-${rt}-${_t}T${Pt}:${As}`}),[vt,Tt]=S.useState(!1),[Xe,ut]=S.useState(null),{t:Q}=ft(),{confirm:ze}=qn(),ue=e.status==="pending"||e.status==="failed"||e.status==="stopped",Fe=(e.status==="pending"||e.status==="failed"||e.status==="stopped")&&!!C,Ve=(e.status==="pending"||e.status==="completed"||e.status==="failed"||e.status==="stopped")&&!!k&&!!x&&x>Math.floor(Date.now()/1e3),ht=e.status==="running",Ne=e.status==="completed"||e.status==="stopped"||e.status==="merged",at=e.status==="completed"&&!H&&!!e.branch_name,bt=e.status==="completed"||e.status==="failed"||e.status==="stopped",Ct=!!g&&e.status==="completed"&&!!e.worktree_path,qt=e.status!=="running"&&e.status!=="pending"&&!!e.worktree_path&&!H,an=e.status==="completed"||e.status==="failed"||e.status==="stopped"||e.status==="merged";S.useEffect(()=>{w&&e.status==="running"&&!W&&G(!0)},[w,e.status]),S.useEffect(()=>{W&&!q&&_1(e.id).then(ge=>{V(ge),oe(!0)}).catch(()=>{})},[W,q,e.id]),S.useEffect(()=>{W&&an&&!st&&n4(e.id).then(ge=>{Ee(ge),lt(!0)}).catch(()=>{lt(!0)})},[W,an,st,e.id]),S.useEffect(()=>_(ge=>{if(ge.type==="todo:log"&&ge.todoId===e.id&&ge.message){const Ae={id:`ws-${Date.now()}-${Math.random()}`,todo_id:e.id,log_type:ge.logType||"output",message:ge.message,created_at:new Date().toISOString()};V(rt=>[...rt,Ae])}if(ge.type==="todo:commit"&&ge.todoId===e.id&&ge.message){const Ae={id:`ws-commit-${Date.now()}-${Math.random()}`,todo_id:e.id,log_type:"commit",message:`${ge.commitHash?`[${ge.commitHash}] `:""}${ge.message}`,created_at:new Date().toISOString()};V(rt=>[...rt,Ae])}}),[_,e.id]);const Pn=async()=>{try{const{files:ge}=await zN(e.project_id,e.id);ge.length>0&&window.open(`/api/projects/${e.project_id}/debug-logs/${encodeURIComponent(ge[0].name)}`,"_blank")}catch{}},vn=async()=>{if(ee){Z(!1);return}de(!0),le(null);try{const ge=await t4(e.id);Y(ge),Z(!0),G(!0)}catch(ge){le(ge instanceof Error?ge.message:"Failed to load diff"),G(!0)}finally{de(!1)}},Xn=async()=>{Re(!0),Me(null);try{await h(e.id)}catch(ge){Me(ge instanceof Error?ge.message:"Merge failed")}finally{Re(!1)}},Ds=async()=>{const ge=e.branch_name?await ze({message:Q("cleanup.confirmDeleteBranch").replace("{name}",e.branch_name),danger:!0}):!1;tt(!0),ke(null);try{await m(e.id,ge)}catch(Ae){ke(Ae instanceof Error?Ae.message:"Cleanup failed")}finally{tt(!1)}},xs=async(ge="headless")=>{Te(!0),Ge(null),V([]),oe(!1),Y(null),Z(!1),Ee(null),lt(!1);try{await d(e.id,ge)}catch(Ae){Ge(Ae instanceof Error?Ae.message:"Retry failed")}finally{Te(!1)}},hn=async(ge="headless")=>{if(!g)return;const Ae=Be.trim();if(!Ae){re(Q("todo.continuePromptRequired"));return}X(!0),re(null);try{await g(e.id,Ae,ge),be(!1),ne(""),V([]),oe(!1)}catch(rt){re(rt instanceof Error?rt.message:"Continue failed")}finally{X(!1)}},qs=async()=>{if(!(!k||!se.trim())){je(!0),Je(null);try{await k(e.id,se.trim()),J(!1),pe("")}catch(ge){Je(ge instanceof Error?ge.message:"Failed")}finally{je(!1)}}},Ji=async()=>{if(!(!C||!kt)){Tt(!0);try{await C(e.id,new Date(kt).toISOString(),pt),mt(!1)}catch{}finally{Tt(!1)}}},Ts=ge=>{if(ge<60)return`${ge}s`;const Ae=Math.floor(ge/60),rt=ge%60;if(Ae<60)return rt>0?`${Ae}m ${rt}s`:`${Ae}m`;const _t=Math.floor(Ae/60),Pt=Ae%60;return Pt>0?`${_t}h ${Pt}m`:`${_t}h`},Rs=ge=>ge>=1e6?`${(ge/1e6).toFixed(1)}M`:ge>=1e3?`${(ge/1e3).toFixed(1)}k`:String(ge),Ks=e.images?JSON.parse(e.images):[],os=e.depends_on?s.find(ge=>ge.id===e.depends_on):null,Ms=s.find(ge=>ge.depends_on===e.id&&ge.merged_from_branch),Qi=e.cli_tool||i||"claude",Gs=Cm(Qi).supportsInteractive;if(I)return t.jsx(U_,{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:Ks,todoId:e.id,availableTodos:s.filter(ge=>ge.id!==e.id),onDeleteImage:async ge=>{await i4(e.id,ge)},onSave:async(ge,Ae,rt,_t,Pt,As,Mr,Nl,Ll,Ar)=>{await c(e.id,ge,Ae,rt,Pt,As,Mr,Nl,Ll,Ar),_t&&_t.length>0&&await j1(e.id,_t.map(Dl=>({name:Dl.name,data:Dl.data}))),z(!1)},onCancel:()=>z(!1)});const lr=ge=>{ge.dataTransfer.setData("text/plain",e.id),ge.dataTransfer.effectAllowed="link",N==null||N(e.id)},Kn=()=>{D==null||D()},En=ge=>{!R||E||(ge.preventDefault(),ge.dataTransfer.dropEffect=T?"link":"none",A==null||A(e.id))},Zi=()=>{B==null||B(e.id)},ea=ge=>{ge.preventDefault(),!(!R||E||!T)&&(O==null||O(e.id))},ce=R&&!E&&j&&T,We=R&&!E&&j&&!T;return t.jsxs("div",{className:`relative transition-opacity duration-200 ${E?"opacity-40":""}`,onDragOver:En,onDragLeave:Zi,onDrop:ea,onContextMenu:ge=>{gi(ge)||(ge.preventDefault(),ge.stopPropagation(),ut({x:ge.clientX,y:ge.clientY}))},children:[t.jsxs("div",{className:`card overflow-hidden transition-all duration-200 ${ce?"ring-2 ring-accent/50 ring-offset-1":""} ${We?"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:()=>G(!W),children:[t.jsx("div",{draggable:!0,onDragStart:lr,onDragEnd:Kn,onClick:ge=>ge.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:Q("dnd.dropHint"),children:t.jsx(Zw,{size:16})}),t.jsx("button",{className:"text-warm-400 hover:text-accent flex-shrink-0 transition-colors",children:t.jsx(Es,{size:14,className:`transition-transform duration-200 ${W?"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}),Ks.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(qa,{size:12}),Ks.length]}),os&&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:`${Q("todo.dependsOn")}: ${os.title}`,children:[t.jsx(fl,{size:12}),os.title.length>20?os.title.slice(0,20)+"...":os.title,F&&t.jsx("button",{onClick:ge=>{ge.stopPropagation(),F(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:Q("dnd.removeDep"),children:t.jsx(Xt,{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:Cm(e.cli_tool||"claude").label}),t.jsx(LL,{status:e.status}),t.jsxs("div",{className:"flex items-center gap-0.5 ml-auto md:ml-2 flex-shrink-0",onClick:ge=>ge.stopPropagation(),children:[ue&&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:Q("todo.startHeadless"),children:t.jsx(Tr,{size:14})}),ht&&t.jsx("button",{onClick:()=>p(e.id),className:"p-1.5 text-status-error/60 hover:text-status-error hover:bg-status-error/10 rounded-lg transition-colors",title:Q("todo.stop"),children:t.jsx(Ki,{size:14})}),at&&t.jsx("button",{onClick:Xn,disabled:De,className:"p-1.5 text-theme-muted hover:text-accent hover:bg-theme-hover rounded-lg transition-colors disabled:opacity-30",title:Q("todo.merge"),children:t.jsx(vu,{size:14})}),Ct&&t.jsx("button",{onClick:()=>{be(ge=>!ge),re(null)},disabled:_e,className:"p-1.5 text-theme-muted hover:text-accent hover:bg-theme-hover rounded-lg transition-colors disabled:opacity-30",title:Q("todo.continue"),children:t.jsx(K0,{size:14})}),bt&&t.jsx("button",{onClick:()=>xs("headless"),disabled:fe,className:"p-1.5 text-theme-muted hover:text-accent hover:bg-theme-hover rounded-lg transition-colors disabled:opacity-30",title:Q("todo.retry"),children:t.jsx(mi,{size:14})}),t.jsxs(u8,{children:[ue&&Gs&&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:Q("todo.startInteractiveDesc"),children:[t.jsx(pi,{size:14}),Q("todo.startInteractive")]}),ue&&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:Q("todo.startVerboseDesc"),children:[t.jsx(cm,{size:14}),Q("todo.startVerbose")]}),Fe&&t.jsxs("button",{onClick:()=>mt(!yt),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:Q("todo.scheduleDesc"),children:[t.jsx(om,{size:14}),Q("todo.schedule")]}),Ve&&t.jsxs("button",{onClick:()=>{J(ge=>!ge),Je(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:Q("todo.scheduleOnResetDesc"),children:[t.jsx(Wi,{size:14}),Q("todo.scheduleOnReset")]}),Ne&&t.jsxs("button",{onClick:vn,disabled:he,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(tl,{size:14}),Q("todo.viewDiff")]}),$&&an&&t.jsxs("button",{onClick:Pn,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(J0,{size:14}),Q("todo.viewDebugLog")]}),qt&&t.jsxs("button",{onClick:Ds,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(xu,{size:14}),Q("todo.cleanup")]}),t.jsxs("button",{onClick:()=>z(!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(fi,{size:14}),Q("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(An,{size:14}),Q("todo.delete")]})]})]})]}),yt&&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:Q("todo.scheduleAt")}),t.jsx("input",{type:"datetime-local",value:kt,onChange:ge=>gt(ge.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:Ji,disabled:vt||!kt,className:"btn-primary text-xs py-1.5 disabled:opacity-30",children:Q(vt?"todo.scheduling":"todo.confirmSchedule")}),t.jsx("button",{onClick:()=>mt(!1),className:"btn-ghost text-xs py-1.5",children:Q("scheduleForm.cancel")}),t.jsxs("label",{className:"flex items-center gap-2 text-xs text-warm-500",children:[t.jsx("input",{type:"checkbox",checked:pt,onChange:ge=>dt(ge.target.checked),className:"rounded-md border-accent/40 text-accent focus:ring-accent"}),Q("todo.scheduleKeepOriginal")]})]})}),Ze&&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:[Q("todo.continuePromptLabel"),(e.round_count??1)>1&&t.jsxs("span",{className:"ml-2 text-theme-muted",children:["(",Q("todo.roundLabel")," ",e.round_count,")"]})]}),t.jsx("textarea",{value:Be,onChange:ge=>ne(ge.target.value),placeholder:Q("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:_e}),me&&t.jsx("p",{className:"text-xs text-status-error",children:me}),t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("button",{onClick:()=>hn("headless"),disabled:_e||!Be.trim(),className:"btn-primary text-xs py-1.5 disabled:opacity-30",children:Q(_e?"todo.continuing":"todo.confirmContinue")}),t.jsx("button",{onClick:()=>{be(!1),re(null)},disabled:_e,className:"btn-ghost text-xs py-1.5",children:Q("scheduleForm.cancel")})]})]})}),ae&&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:Q("todo.scheduleOnResetLabel")}),t.jsx("span",{className:"text-xs text-warm-400 font-mono",children:new Date(x*1e3).toLocaleString()})]}),t.jsx("textarea",{value:se,onChange:ge=>pe(ge.target.value),placeholder:Q("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:we}),$e&&t.jsx("p",{className:"text-xs text-status-error",children:$e}),t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("button",{onClick:qs,disabled:we||!se.trim(),className:"btn-primary text-xs py-1.5 disabled:opacity-30",children:Q(we?"todo.scheduling":"todo.confirmResetSchedule")}),t.jsx("button",{onClick:()=>{J(!1),Je(null)},disabled:we,className:"btn-ghost text-xs py-1.5",children:Q("scheduleForm.cancel")})]})]})}),W&&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:Q("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:Q("todo.noDescription")})})]}),Ks.length>0&&t.jsxs("section",{children:[t.jsxs("h4",{className:"section-label mb-1.5",children:[Q("todo.attachedImages")," ",t.jsxs("span",{className:"text-warm-400 normal-case",children:["(",Ks.length,")"]})]}),t.jsx("div",{className:"flex flex-wrap gap-1.5",children:Ks.map(ge=>t.jsx("a",{href:_m(e.id,ge.id),target:"_blank",rel:"noopener noreferrer",children:t.jsx("img",{src:_m(e.id,ge.id),alt:ge.originalName,className:"h-16 w-16 object-cover rounded-md border border-theme-border"})},ge.id))})]}),(os||e.branch_name||Ms)&&t.jsxs("section",{children:[t.jsx("h4",{className:"section-label mb-1.5",children:Q("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:[os&&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:Q("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:os.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:Q("todo.branch")}),t.jsx(Vi,{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:Q("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:Q("todo.mergedFrom")}),t.jsx("code",{className:"font-mono text-xs text-theme-text-secondary break-all",children:e.merged_from_branch})]}),!e.worktree_path&&Ms&&t.jsxs("div",{className:"flex items-center gap-2 text-xs",children:[t.jsx("span",{className:"text-warm-400 w-24 flex-shrink-0",children:Q("todo.transferredTo")}),t.jsx("span",{className:"text-warm-700 truncate",children:Ms.title.length>30?Ms.title.slice(0,27)+"...":Ms.title})]})]})]}),e.status==="failed"&&U.length>0&&(()=>{var _t;const ge=U.filter(Pt=>Pt.log_type==="error");if(ge.length===0)return null;const Ae=ge.find(Pt=>/exited with code (\d+)/.test(Pt.message)),rt=Ae?(_t=Ae.message.match(/exited with code (\d+)/))==null?void 0:_t[1]:null;return t.jsxs("div",{style:{background:Ue.bg,fontFamily:Ot,fontSize:12,lineHeight:"1.5",padding:"10px 12px",borderRadius:8,border:`1px solid ${Ue.separator}`,color:Ue.text},children:[t.jsxs("div",{children:[t.jsx("span",{style:{color:Ue.error},children:">"})," ",t.jsx("span",{style:{color:Ue.error,fontWeight:700},children:"FAILED"}),rt&&t.jsxs("span",{style:{color:Ue.dim},children:[" (exit code: ",rt,")"]}),b&&t.jsx("button",{onClick:()=>b(e,ge),style:{marginLeft:12,color:Ue.warning,background:"none",border:`1px solid ${Ue.warning}`,padding:"1px 8px",borderRadius:2,cursor:"pointer",fontSize:11,fontFamily:Ot},children:Q("failure.fix")})]}),t.jsx("div",{style:{maxHeight:192,overflowY:"auto",marginTop:4},children:ge.map(Pt=>t.jsxs("div",{children:[t.jsx("span",{style:{color:Ue.dim},children:new Date(Pt.created_at).toLocaleTimeString()})," ",t.jsx("span",{style:{color:Ue.error},children:Pt.message})]},Pt.id))})]})})(),an&&qe&&t.jsxs("section",{children:[t.jsx("h4",{className:"section-label mb-1.5",children:Q("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:[qe.duration_seconds!==null&&t.jsxs("span",{className:"inline-flex items-center gap-1",children:[t.jsx(Wi,{size:12,className:"text-warm-400"}),t.jsx("span",{className:"text-warm-400",children:Q("result.duration")}),t.jsx("span",{className:"text-warm-700 font-medium",children:Ts(qe.duration_seconds)})]}),qe.commits.length>0&&t.jsxs("span",{className:"inline-flex items-center gap-1",children:[t.jsx(rE,{size:12,className:"text-status-success"}),t.jsx("span",{className:"text-status-success font-medium",children:qe.commits.length}),t.jsx("span",{className:"text-warm-400",children:Q("result.commits")})]}),qe.diff_stats.files_changed>0&&t.jsxs("span",{className:"inline-flex items-center gap-1",children:[t.jsx(tl,{size:12,className:"text-warm-400"}),t.jsx("span",{className:"text-warm-700 font-medium",children:qe.diff_stats.files_changed}),t.jsx("span",{className:"text-warm-400",children:Q("result.filesChanged")}),t.jsxs("span",{className:"text-status-success font-mono",children:["+",qe.diff_stats.insertions]}),t.jsxs("span",{className:"text-status-error font-mono",children:["-",qe.diff_stats.deletions]})]}),P&&qe.token_usage&&(()=>{const ge=qe.token_usage,Ae=(ge.input_tokens??0)+(ge.cache_read_input_tokens??0)+(ge.cache_creation_input_tokens??0),rt=Ae+(ge.output_tokens??0);let _t,Pt;return rt>=5e5?(_t=Q("result.levelHeavy"),Pt="text-status-error"):rt>=3e5?(_t=Q("result.levelHigh"),Pt="text-status-warning"):rt>=1e5?(_t=Q("result.levelModerate"),Pt="text-status-warning"):(_t=Q("result.levelLight"),Pt="text-status-info"),t.jsxs("span",{className:"inline-flex items-center gap-1",children:[Ae>0&&t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"text-warm-400",children:Q("result.inputTokens")}),t.jsx("span",{className:"text-warm-700 font-medium",children:Rs(Ae)})]}),Ae>0&&ge.output_tokens!==null&&t.jsx("span",{className:"text-warm-400",children:"·"}),ge.output_tokens!==null&&t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"text-warm-400",children:Q("result.outputTokens")}),t.jsx("span",{className:"text-warm-700 font-medium",children:Rs(ge.output_tokens)})]}),ge.num_turns!=null&&ge.num_turns>1&&t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"text-warm-400",children:"·"}),t.jsxs("span",{className:"text-warm-700",children:[ge.num_turns,Q("result.turns")]})]}),t.jsx("span",{className:"text-warm-400",children:"·"}),t.jsx("span",{className:`font-medium ${Pt}`,children:_t})]})})()]}),qe.commits.length>0&&t.jsxs("div",{children:[t.jsx("h5",{className:"text-2xs font-semibold text-warm-400 uppercase tracking-wider mb-1",children:Q("result.commitHistory")}),t.jsx("div",{className:"space-y-0.5",children:qe.commits.map((ge,Ae)=>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:ge.hash.slice(0,7)||"-------"}),t.jsx("span",{className:"text-warm-700 truncate flex-1",children:ge.message}),t.jsx("span",{className:"text-2xs text-warm-400 flex-shrink-0",children:new Date(ge.date).toLocaleTimeString()})]},Ae))})]}),qe.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:Q("result.changedFiles")}),Ne&&t.jsxs("button",{onClick:vn,disabled:he,className:"flex items-center gap-1 text-2xs text-warm-500 hover:text-accent transition-colors disabled:opacity-30",children:[t.jsx(Es,{size:12,className:`transition-transform ${ee?"rotate-90":""}`}),t.jsx("span",{children:Q(ee?"todo.hideDiff":"todo.viewDiff")})]})]}),t.jsx("div",{className:"space-y-0.5",children:qe.changed_files.map((ge,Ae)=>{const rt=ge.status==="A"?"bg-status-success/15 text-status-success":ge.status==="D"?"bg-status-error/15 text-status-error":ge.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 ${rt}`,children:ge.status}),t.jsx("span",{className:"text-warm-700 font-mono text-2xs break-all flex-1",children:ge.file}),ge.renamedFrom&&t.jsxs("span",{className:"text-warm-400 text-2xs flex-shrink-0",children:["← ",ge.renamedFrom]})]},Ae)})})]})]})]}),ve&&t.jsxs("div",{className:"rounded-md bg-status-error/10 text-status-error text-xs px-3 py-2",children:[Q("todo.mergeFailed"),": ",ve]}),nt&&t.jsxs("div",{className:"rounded-md bg-status-error/10 text-status-error text-xs px-3 py-2",children:[Q("todo.cleanupFailed"),": ",nt]}),Ce&&t.jsxs("div",{className:"rounded-md bg-status-error/10 text-status-error text-xs px-3 py-2",children:[Q("todo.retryFailed"),": ",Ce]}),ye&&t.jsxs("div",{className:"rounded-md bg-status-error/10 text-status-error text-xs px-3 py-2",children:[Q("todo.diffError"),": ",ye]}),ee&&te&&t.jsxs("section",{children:[t.jsxs("div",{className:"flex items-center justify-between mb-1.5",children:[t.jsx("h4",{className:"section-label",children:Q("todo.diffOutput")}),t.jsxs("div",{className:"flex items-center gap-1.5 text-2xs",children:[t.jsxs("span",{className:"text-warm-500",children:[te.stats.files_changed," ",Q("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:["+",te.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:["-",te.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:te.diff?te.diff.split(`
|
|
660
|
-
`).map((ge,Ae)=>{let rt="text-theme-text",_t="";return ge.startsWith("+")&&!ge.startsWith("+++")?rt="text-theme-text bg-status-success/15":ge.startsWith("-")&&!ge.startsWith("---")?rt="text-theme-text bg-status-error/15":ge.startsWith("@@")?rt="text-accent":ge.startsWith("diff ")&&(rt="text-warm-700",_t="font-semibold"),t.jsx("div",{className:`whitespace-pre ${rt} ${_t}`,children:ge},Ae)}):t.jsx("span",{className:"text-warm-400 italic",children:Q("log.noChanges")})})]}),t.jsxs("div",{className:"rounded-lg overflow-hidden",style:{background:Ue.bg,fontFamily:Ot,border:`1px solid ${Ue.separator}`},children:[t.jsxs("div",{style:{padding:"8px 12px",borderBottom:`1px solid ${Ue.separator}`,fontSize:12,color:Ue.text},children:[t.jsx("span",{style:{color:Ue.prompt},children:"$"})," ",t.jsx("span",{style:{color:Ue.bright},children:"tail"})," ",t.jsx("span",{style:{color:Ue.dim},children:"-f task.log"})]}),t.jsx($_,{logs:U,interactive:w&&e.status==="running",todoId:e.id,onSendInput:y,embedded:!0})]})]})})]}),ce&&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(fl,{size:14,className:"text-accent flex-shrink-0"}),t.jsx("span",{className:"text-xs font-medium text-accent",children:Q("dnd.dropHint")})]}),We&&t.jsxs("div",{className:"mt-1.5 flex items-center gap-2 px-4 py-2 rounded-lg border-2 border-dashed border-status-error/30 bg-status-error/10",children:[t.jsx(t5,{size:14,className:"text-status-error flex-shrink-0"}),t.jsx("span",{className:"text-xs font-medium text-status-error",children:Q("dnd.cyclicWarning")})]}),Xe&&t.jsxs(ir,{x:Xe.x,y:Xe.y,onClose:()=>ut(null),children:[ue&&t.jsxs("button",{onClick:()=>f(e.id,"headless"),className:sn,title:Q("todo.startHeadless"),children:[t.jsx(Tr,{size:14}),Q("todo.start")]}),ue&&Gs&&t.jsxs("button",{onClick:()=>f(e.id,"interactive"),className:sn,title:Q("todo.startInteractiveDesc"),children:[t.jsx(pi,{size:14}),Q("todo.startInteractive")]}),ue&&t.jsxs("button",{onClick:()=>f(e.id,"verbose"),className:sn,title:Q("todo.startVerboseDesc"),children:[t.jsx(cm,{size:14}),Q("todo.startVerbose")]}),ht&&t.jsxs("button",{onClick:()=>p(e.id),className:sn,children:[t.jsx(Ki,{size:14}),Q("todo.stop")]}),at&&t.jsxs("button",{onClick:Xn,disabled:De,className:sn,children:[t.jsx(vu,{size:14}),Q("todo.merge")]}),Ct&&t.jsxs("button",{onClick:()=>{be(!0),re(null)},disabled:_e,className:sn,children:[t.jsx(K0,{size:14}),Q("todo.continue")]}),bt&&t.jsxs("button",{onClick:()=>xs("headless"),disabled:fe,className:sn,children:[t.jsx(mi,{size:14}),Q("todo.retry")]}),Fe&&t.jsxs("button",{onClick:()=>mt(!0),className:sn,title:Q("todo.scheduleDesc"),children:[t.jsx(om,{size:14}),Q("todo.schedule")]}),Ve&&t.jsxs("button",{onClick:()=>{J(!0),Je(null)},className:sn,title:Q("todo.scheduleOnResetDesc"),children:[t.jsx(Wi,{size:14}),Q("todo.scheduleOnReset")]}),Ne&&t.jsxs("button",{onClick:vn,disabled:he,className:sn,children:[t.jsx(tl,{size:14}),Q("todo.viewDiff")]}),$&&an&&t.jsxs("button",{onClick:Pn,className:sn,children:[t.jsx(J0,{size:14}),Q("todo.viewDebugLog")]}),qt&&t.jsxs("button",{onClick:Ds,disabled:Oe,className:sn,children:[t.jsx(xu,{size:14}),Q("todo.cleanup")]}),t.jsx(W_,{}),t.jsxs("button",{onClick:()=>z(!0),className:sn,children:[t.jsx(fi,{size:14}),Q("todo.edit")]}),t.jsxs("button",{onClick:()=>o(e.id),className:Mp,children:[t.jsx(An,{size:14}),Q("todo.delete")]})]})]})}const h8=S.lazy(()=>Wu(()=>import("./TaskGraph-BJ2xQmxj.js"),__vite__mapDeps([0,1,2,3,4]))),Yc={all:null,active:["pending","running"],completed:["completed","merged"],cancelled:["stopped","failed"]};function gy(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(p=>p.id===a);a=(f==null?void 0:f.depends_on)??null}return!1}function f8({todos:e,projectId:s,projectCliTool:i,projectIsGitRepo:a,projectUseWorktree:u,onAddTodo:f,onStartAll:p,onStopAll:o,onStartTodo:c,onStopTodo:h,onDeleteTodo:m,onEditTodo:d,onMergeTodo:g,onMergeChain:b,onCleanupTodo:C,onRetryTodo:k,onContinueTodo:x,onFixTodo:_,onScheduleTodo:w,onScheduleOnResetTodo:y,resetsAt:E,onUpdateDependency:R,onUpdatePosition:j,onReorderTodos:T,onEvent:N,onSendInput:D,interactiveTodos:A,debugLogging:B,showTokenUsage:O}){var qe;const[F,$]=S.useState(!1),[P,H]=S.useState(null),[W,G]=S.useState(null),[I,z]=S.useState(null),[U,V]=S.useState(null),[q,oe]=S.useState(()=>{try{return localStorage.getItem("todoViewMode")||"list"}catch{return"list"}}),[ee,Z]=S.useState(()=>{try{return localStorage.getItem("todoStatusFilter")||"all"}catch{return"all"}}),[te,Y]=S.useState(()=>{try{return localStorage.getItem("todoStackModeEnabled")==="true"}catch{return!1}}),[he,de]=S.useState(()=>{try{return localStorage.getItem("todoStackCollapsed")==="true"}catch{return!1}}),{t:ye}=ft(),le=S.useCallback(Ee=>{oe(Ee);try{localStorage.setItem("todoViewMode",Ee)}catch{}},[]),De=S.useCallback(Ee=>{Z(Ee);try{localStorage.setItem("todoStatusFilter",Ee)}catch{}},[]),Re=S.useCallback(()=>{Y(Ee=>{const st=!Ee;try{localStorage.setItem("todoStackModeEnabled",String(st))}catch{}if(!st){de(!1);try{localStorage.setItem("todoStackCollapsed","false")}catch{}}return st})},[]),ve=S.useCallback(()=>{de(Ee=>{const st=!Ee;try{localStorage.setItem("todoStackCollapsed",String(st))}catch{}return st})},[]),Me=te&&he&&q==="list",Oe=S.useMemo(()=>({all:e.length,active:e.filter(Ee=>Yc.active.includes(Ee.status)).length,completed:e.filter(Ee=>Yc.completed.includes(Ee.status)).length,cancelled:e.filter(Ee=>Yc.cancelled.includes(Ee.status)).length}),[e]),tt=S.useMemo(()=>{const Ee=Yc[ee];return Ee?e.filter(st=>Ee.includes(st.status)):e},[e,ee]),nt=(()=>{const Ee=[...tt].sort((dt,kt)=>dt.priority-kt.priority);if(ee!=="all"||Me)return Ee.map(dt=>({todo:dt,depth:0}));const st=new Map,lt=[];for(const dt of Ee)if(dt.depends_on){const kt=st.get(dt.depends_on)||[];kt.push(dt),st.set(dt.depends_on,kt)}else lt.push(dt);const yt=[],mt=new Set,pt=(dt,kt)=>{if(mt.has(dt.id))return;mt.add(dt.id),yt.push({todo:dt,depth:kt});const gt=st.get(dt.id);if(gt)for(const vt of gt)pt(vt,kt+1)};for(const dt of lt)pt(dt,0);for(const dt of Ee)mt.has(dt.id)||yt.push({todo:dt,depth:0});return yt})(),{completedChainRoots:ke,completedChainMembers:fe}=S.useMemo(()=>{const Ee=new Map;for(const mt of e)if(mt.depends_on){const pt=Ee.get(mt.depends_on)||[];pt.push(mt.id),Ee.set(mt.depends_on,pt)}const st=e.filter(mt=>!mt.depends_on&&Ee.has(mt.id)),lt=new Map,yt=new Set;for(const mt of st){const pt=[],dt=kt=>{if(!e.find(Tt=>Tt.id===kt))return;pt.push(kt);const vt=Ee.get(kt)||[];for(const Tt of vt)dt(Tt)};if(dt(mt.id),pt.length>=2&&pt.every(kt=>{const gt=e.find(vt=>vt.id===kt);return(gt==null?void 0:gt.status)==="completed"||(gt==null?void 0:gt.status)==="merged"})){lt.set(mt.id,pt.length);for(const kt of pt)yt.add(kt)}}return{completedChainRoots:lt,completedChainMembers:yt}},[e]),[Te,Ce]=S.useState(null),[Ge,Ze]=S.useState(null),be=S.useCallback(async Ee=>{if(b){Ce(Ee),Ze(null);try{await b(Ee)}catch(st){Ze(st instanceof Error?st.message:"Merge failed")}finally{Ce(null)}}},[b]),Be=S.useRef(!1),ne=S.useCallback(Ee=>{Be.current=!1,G(Ee)},[]),_e=S.useCallback(async()=>{if(!Be.current&&W&&R){const Ee=e.find(st=>st.id===W);Ee!=null&&Ee.depends_on&&await R(W,null)}G(null),z(null),V(null)},[W,e,R]),X=S.useCallback(Ee=>{z(Ee),V(null)},[]),me=S.useCallback(Ee=>{z(st=>st===Ee?null:st)},[]),re=S.useCallback(async Ee=>{!W||!R||W!==Ee&&(gy(e,W,Ee)||(Be.current=!0,await R(W,Ee),G(null),z(null),V(null)))},[W,e,R]),ae=S.useCallback(async Ee=>{R&&await R(Ee,null)},[R]),J=S.useCallback(Ee=>!W||W===Ee?!1:!gy(e,W,Ee),[W,e]),se=S.useCallback(Ee=>{V(Ee),z(null)},[]),pe=S.useCallback(Ee=>{V(st=>st===Ee?null:st)},[]),we=S.useCallback(async(Ee,st)=>{if(!W||!T)return;const lt=st.indexOf(W);if(lt<0)return;const yt=st.filter(dt=>dt!==W),mt=Ee>lt?Ee-1:Ee;if(mt===lt){V(null);return}const pt=[...yt.slice(0,mt),W,...yt.slice(mt)];Be.current=!0,await T(pt),G(null),V(null),z(null)},[W,T]),je=e.some(Ee=>Ee.status==="pending"||Ee.status==="failed"||Ee.status==="stopped"),$e=e.some(Ee=>Ee.status==="running"),Je=t.jsxs(t.Fragment,{children:[t.jsxs("button",{onClick:p,disabled:!je,className:"btn-ghost text-sm",children:[t.jsx(Tr,{size:14}),ye("header.runAll")]}),t.jsxs("button",{onClick:o,disabled:!$e,className:"btn-ghost text-sm",children:[t.jsx(Ki,{size:14}),ye("header.stopAll")]})]});return q==="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:ye("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(Sn,{onClick:()=>le("list"),label:ye("graph.listView"),size:"sm",children:t.jsx(yu,{size:14})}),t.jsx(Sn,{onClick:()=>le("graph"),label:ye("graph.graphView"),size:"sm",variant:"active",pressed:!0,children:t.jsx(Y0,{size:14})})]}),Je]})]}),t.jsx(S.Suspense,{fallback:null,children:t.jsx(h8,{todos:e,projectId:s,projectCliTool:i,projectIsGitRepo:a,projectUseWorktree:u,onAddTodo:f,onStartTodo:c,onStopTodo:h,onDeleteTodo:m,onEditTodo:d,onMergeTodo:g,onCleanupTodo:C,onRetryTodo:k,onContinueTodo:x,onFixTodo:_,onUpdateDependency:R,onUpdatePosition:j,onEvent:N,onSendInput:D,interactiveTodos:A,debugLogging:B,showTokenUsage:O})})]}):t.jsxs("div",{className:"min-h-[50vh]",onContextMenu:Ee=>{gi(Ee)||(Ee.preventDefault(),H({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:ye("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(Sn,{onClick:()=>le("list"),label:ye("graph.listView"),size:"sm",variant:"active",pressed:!0,children:t.jsx(yu,{size:14})}),t.jsx(Sn,{onClick:()=>le("graph"),label:ye("graph.graphView"),size:"sm",children:t.jsx(Y0,{size:14})})]}),t.jsx(Sn,{onClick:Re,label:ye(te?"todos.stackModeOn":"todos.stackModeOff"),size:"sm",variant:te?"active":"default",pressed:te,children:t.jsx(bE,{size:14})}),te&&!he&&q==="list"&&nt.length>0&&t.jsx(Sn,{onClick:ve,label:ye("todos.collapseStack"),size:"sm",children:t.jsx(S5,{size:14})}),Je,!F&&t.jsxs("button",{onClick:()=>$(!0),className:"btn-primary text-xs py-2",children:[t.jsx(yn,{size:14}),ye("todos.add")]})]})]}),F&&t.jsx("div",{className:"mb-5",children:t.jsx(U_,{projectId:s,projectCliTool:i,projectIsGitRepo:a,projectUseWorktree:u,availableTodos:e,onSave:async(Ee,st,lt,yt,mt,pt,dt,kt,gt,vt)=>{await f(Ee,st,lt,yt,mt,pt,dt,kt,gt,vt),$(!1)},onCancel:()=>$(!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 st=ee===Ee,lt=Ee==="all"?"todos.filterAll":Ee==="active"?"todos.filterActive":Ee==="completed"?"todos.filterCompleted":"todos.filterCancelled";return t.jsxs("button",{onClick:()=>De(Ee),className:`inline-flex items-center gap-1.5 px-3 py-1.5 rounded-md text-xs font-medium transition-colors ${st?"bg-theme-card shadow-sm text-accent":"text-warm-500 hover:text-warm-700"}`,children:[t.jsx("span",{children:ye(lt)}),t.jsx("span",{className:`text-2xs font-mono ${st?"text-accent/70":"text-warm-400"}`,children:Oe[Ee]})]},Ee)})}),t.jsx("div",{className:Me?"relative cursor-pointer":"space-y-3",onClick:Me?ve:void 0,title:Me?ye("todos.expandStack"):void 0,style:Me?{height:76+Math.max(nt.length-1,0)*6}:void 0,children:nt.length===0?t.jsx("div",{className:"card",children:t.jsx(Yi,{icon:Vw,title:ye(ee==="all"?"todos.empty":"todos.filterEmpty"),description:ee==="all"?ye("todos.emptyHint"):void 0})}):(()=>{const Ee=nt.map(({todo:lt})=>lt.id),st=lt=>{if(Me||!T)return null;const yt=W!==null&&U===lt;return t.jsx("div",{onDragEnter:mt=>{mt.preventDefault(),se(lt)},onDragOver:mt=>{mt.preventDefault(),mt.stopPropagation(),mt.dataTransfer.dropEffect="link",se(lt)},onDragLeave:()=>pe(lt),onDrop:mt=>{mt.preventDefault(),mt.stopPropagation(),we(lt,Ee)},className:"relative",style:{height:16,marginTop:-8,marginBottom:-8},children:yt&&t.jsx("div",{className:"absolute inset-x-0 top-1/2 -translate-y-1/2 h-0.5 bg-accent rounded-full shadow-[0_0_6px_rgba(0,0,0,0.15)]"})},`gap-${lt}`)};return t.jsxs(t.Fragment,{children:[st(0),nt.map(({todo:lt,depth:yt},mt)=>{const pt=ke.has(lt.id),dt=fe.has(lt.id),kt=6,gt="top 400ms cubic-bezier(0.2, 0.8, 0.2, 1), opacity 300ms ease",vt=Me?{position:"absolute",top:mt*kt,left:0,right:0,zIndex:nt.length+10-mt,opacity:mt===0?1:.9,pointerEvents:mt===0?"auto":"none",transition:gt}:{transition:gt};return t.jsxs("div",{className:"",style:vt,children:[!Me&&pt&&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(fl,{size:16,className:"text-theme-muted flex-shrink-0"}),t.jsx("span",{className:"text-xs font-semibold text-theme-text-secondary",children:ye("todo.chainComplete")}),t.jsx("span",{className:"text-2xs font-mono text-warm-400",children:ye("todo.chainTasks").replace("{count}",String(ke.get(lt.id)))}),t.jsxs("div",{className:"ml-auto flex items-center gap-2",children:[Ge&&Te===null&&t.jsx("span",{className:"text-2xs text-status-error",children:Ge}),t.jsxs("button",{onClick:()=>be(lt.id),disabled:Te===lt.id,className:"btn-secondary text-xs py-1.5 disabled:opacity-50",title:ye("todo.mergeChainDesc"),children:[t.jsx(Xj,{size:14}),Te===lt.id?"...":ye("todo.mergeChain")]})]})]}),t.jsxs("div",{className:"relative",style:{marginLeft:yt>0?`${yt*24}px`:void 0},children:[yt>0&&t.jsx("div",{className:"absolute top-0 bottom-0 w-px",style:{left:"-13px",backgroundColor:"var(--color-border)"}}),t.jsx(d8,{todo:lt,allTodos:e,projectCliTool:i,projectIsGitRepo:a,projectUseWorktree:u,onStart:c,onStop:h,onDelete:m,onEdit:d,onMerge:g,onCleanup:C,onRetry:k,onContinue:x,onFix:_,onSchedule:w,onScheduleOnReset:y,resetsAt:E,onEvent:N,isInteractive:A.has(lt.id),onSendInput:D,isDragSource:W===lt.id,isDragging:W!==null,isDragOver:I===lt.id,isValidDropTarget:J(lt.id),onDragStart:ne,onDragEnd:_e,onDragOverTarget:X,onDragLeaveTarget:me,onDropTarget:re,onRemoveDependency:R?ae:void 0,debugLogging:B,showTokenUsage:O,isChainMember:dt})]}),st(mt+1)]},lt.id)})]})})()}),!Me&&W&&((qe=e.find(Ee=>Ee.id===W))==null?void 0:qe.depends_on)&&t.jsxs("div",{className:"mt-3 border-2 border-dashed border-status-error/30 rounded-lg p-4 text-center text-sm text-status-error transition-colors hover:border-status-error/30 hover:text-status-error hover:bg-status-error/10",onDragOver:Ee=>{Ee.preventDefault(),Ee.dataTransfer.dropEffect="move"},onDrop:Ee=>{Ee.preventDefault(),W&&R&&(Be.current=!0,R(W,null))},children:[t.jsx(yN,{size:20,className:"mx-auto mb-1"}),ye("dnd.dropToRemoveDep")]}),P&&t.jsx(ir,{x:P.x,y:P.y,onClose:()=>H(null),children:t.jsxs("button",{onClick:()=>$(!0),className:sn,children:[t.jsx(yn,{size:14}),ye("todos.add")]})})]})}const m8=[{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 p8(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,,p]=i,o=a.match(/^\*\/(\d+)$/);if(o&&u==="*"&&f==="*"&&p==="*")return{...s,mode:"minutes",everyMinutes:parseInt(o[1])};if(/^\d+$/.test(a)&&u==="*"&&f==="*"&&p==="*")return{...s,mode:"hourly",hourlyMinute:parseInt(a)};const c=/^\d+$/.test(a)?parseInt(a):-1,h=/^\d+$/.test(u)?parseInt(u):-1;if(c<0||h<0)return{...s,mode:"custom"};if(f==="*"&&p!=="*"){const m=p.split(",").map(d=>{const g=parseInt(d);return isNaN(g)?-1:g}).filter(d=>d>=0);if(m.length>0)return{...s,mode:"weekly",weeklyDays:m,weeklyHour:h,weeklyMinute:c}}return/^\d+$/.test(f)&&p==="*"?{...s,mode:"monthly",monthlyDay:parseInt(f),monthlyHour:h,monthlyMinute:c}:f==="*"&&p==="*"?{...s,mode:"daily",dailyHour:h,dailyMinute:c}:{...s,mode:"custom"}}function xy(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 g8({value:e,onChange:s}){const{t:i}=ft(),[a,u]=S.useState(()=>p8(e)),[f,p]=S.useState(e);S.useEffect(()=>{if(a.mode==="custom")s(f);else{const b=xy(a);s(b)}},[a,f]);const o=b=>{u(C=>({...C,...b}))},c=b=>{u(C=>{const k=C.weeklyDays.includes(b)?C.weeklyDays.filter(x=>x!==b):[...C.weeklyDays,b];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"}],m="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=(b,C,k,x)=>t.jsxs("div",{className:"flex items-center gap-1.5",children:[t.jsx("select",{value:b,onChange:_=>k(parseInt(_.target.value)),className:`${m} w-16`,children:Array.from({length:24},(_,w)=>t.jsx("option",{value:w,children:String(w).padStart(2,"0")},w))}),t.jsx("span",{className:"text-warm-500 font-mono",children:":"}),t.jsx("select",{value:C,onChange:_=>x(parseInt(_.target.value)),className:`${m} w-16`,children:Array.from({length:12},(_,w)=>w*5).map(_=>t.jsx("option",{value:_,children:String(_).padStart(2,"0")},_))})]}),g=a.mode==="custom"?f:xy(a);return t.jsxs("div",{className:"space-y-3",children:[t.jsx("div",{className:"flex flex-wrap gap-1.5",children:h.map(b=>t.jsx("button",{type:"button",onClick:()=>o({mode:b.value}),className:`px-2.5 py-1 rounded-md text-xs font-medium transition-colors ${a.mode===b.value?"bg-accent text-white":"bg-warm-100 text-warm-500 hover:bg-warm-200"}`,children:i(b.labelKey)},b.value))}),t.jsxs("div",{className:"bg-warm-50 rounded-lg p-3",children:[a.mode==="minutes"&&t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("span",{className:"text-sm text-warm-600",children:i("cron.every")}),t.jsx("select",{value:a.everyMinutes,onChange:b=>o({everyMinutes:parseInt(b.target.value)}),className:`${m} w-20`,children:[5,10,15,20,30].map(b=>t.jsx("option",{value:b,children:b},b))}),t.jsx("span",{className:"text-sm text-warm-600",children:i("cron.minutesLabel")})]}),a.mode==="hourly"&&t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("span",{className:"text-sm text-warm-600",children:i("cron.everyHourAt")}),t.jsx("select",{value:a.hourlyMinute,onChange:b=>o({hourlyMinute:parseInt(b.target.value)}),className:`${m} w-16`,children:Array.from({length:12},(b,C)=>C*5).map(b=>t.jsx("option",{value:b,children:String(b).padStart(2,"0")},b))}),t.jsx("span",{className:"text-sm text-warm-600",children:i("cron.minutesPast")})]}),a.mode==="daily"&&t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("span",{className:"text-sm text-warm-600",children:i("cron.everyDayAt")}),d(a.dailyHour,a.dailyMinute,b=>o({dailyHour:b}),b=>o({dailyMinute:b}))]}),a.mode==="weekly"&&t.jsxs("div",{className:"space-y-3",children:[t.jsx("div",{className:"flex flex-wrap gap-1.5",children:m8.map(b=>t.jsx("button",{type:"button",onClick:()=>c(b.value),className:`w-9 h-9 rounded-lg text-xs font-medium transition-colors ${a.weeklyDays.includes(b.value)?"bg-accent text-white":"bg-theme-card text-warm-500 border border-warm-200 hover:border-accent"}`,children:i(b.labelKey)},b.value))}),t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("span",{className:"text-sm text-warm-600",children:i("cron.at")}),d(a.weeklyHour,a.weeklyMinute,b=>o({weeklyHour:b}),b=>o({weeklyMinute:b}))]})]}),a.mode==="monthly"&&t.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[t.jsx("span",{className:"text-sm text-warm-600",children:i("cron.everyMonthOn")}),t.jsx("select",{value:a.monthlyDay,onChange:b=>o({monthlyDay:parseInt(b.target.value)}),className:`${m} w-16`,children:Array.from({length:28},(b,C)=>C+1).map(b=>t.jsx("option",{value:b,children:b},b))}),t.jsx("span",{className:"text-sm text-warm-600",children:i("cron.dayAt")}),d(a.monthlyHour,a.monthlyMinute,b=>o({monthlyHour:b}),b=>o({monthlyMinute:b}))]}),a.mode==="custom"&&t.jsxs("div",{children:[t.jsx("input",{type:"text",placeholder:"*/30 * * * *",value:f,onChange:b=>p(b.target.value),className:"bg-warm-50 border border-warm-300 rounded-lg px-3 py-1.5 w-full text-sm text-warm-800 font-mono transition-all duration-200 focus:border-accent focus:outline-none focus:ring-2 focus:ring-accent/20"}),t.jsx("p",{className:"text-2xs text-warm-400 mt-1",children:i("schedule.cronHint")})]})]}),a.mode!=="custom"&&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 x8(){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 v8(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"),p=String(s.getMinutes()).padStart(2,"0");return`${i}-${a}-${u}T${f}:${p}`}function q_({onSave:e,onCancel:s,initialTitle:i="",initialDescription:a="",initialCronExpression:u="",initialCliTool:f,initialSkipIfRunning:p=!0,initialScheduleType:o="recurring",initialRunAt:c,projectCliTool:h="claude"}){const[m,d]=S.useState(i),[g,b]=S.useState(a),[C,k]=S.useState(u),[x,_]=S.useState(f||h||"claude"),[w,y]=S.useState(p),[E,R]=S.useState(o),[j,T]=S.useState(c?v8(c):x8()),{t:N}=ft(),D=E==="once",A=m.trim()&&(D?!!j:!!C.trim()),B=O=>{O.preventDefault(),A&&e({title:m.trim(),description:g.trim(),cronExpression:D?"":C.trim(),cliTool:x,skipIfRunning:w,scheduleType:E,runAt:D?new Date(j).toISOString():void 0})};return t.jsxs("form",{onSubmit:B,className:"card p-5",children:[t.jsx("div",{className:"mb-3",children:t.jsx("input",{type:"text",placeholder:N("scheduleForm.titlePlaceholder"),value:m,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=>b(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 ${E==="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 ${E==="once"?"bg-theme-card text-warm-700 shadow-sm":"text-warm-500 hover:text-warm-700"}`,children:N("schedule.once")})]})]}),D?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:j,onChange:O=>T(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(g8,{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=>_(O.target.value),className:"input-field text-sm !py-2",children:Is.map(O=>t.jsx("option",{value:O.value,children:O.label},O.value))})]})}),!D&&t.jsx("div",{className:"mb-4",children:t.jsxs("label",{className:"flex items-center gap-2 text-sm text-warm-600 cursor-pointer",children:[t.jsx("input",{type:"checkbox",checked:w,onChange:O=>y(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:!A,className:"btn-primary text-sm",children:N("scheduleForm.save")})]})]})}function b8({schedule:e,onToggle:s,onDelete:i,onEdit:a,onTrigger:u,onMergeRun:f,onCleanupRun:p}){const[o,c]=S.useState(!1),[h,m]=S.useState(!1),[d,g]=S.useState([]),[b,C]=S.useState(!1),[k,x]=S.useState(!1),[_,w]=S.useState(null),{t:y}=ft(),E=async()=>{try{const $=await vf(e.id);g($)}catch{}},R=async $=>{if(!(!$.todo_id||!f)){w($.id);try{await f($.todo_id),await E()}finally{w(null)}}},j=async $=>{if(!(!$.todo_id||!p)){w($.id);try{await p($.todo_id),await E()}finally{w(null)}}},T=e.schedule_type==="once",N=async()=>{if(!b)try{const $=await vf(e.id);g($),C(!0)}catch{}},D=()=>{const $=!o;c($),$&&N()},A=async()=>{x(!0);try{await u(e.id);const $=await vf(e.id);g($),C(!0)}finally{x(!1)}};if(h)return t.jsx(q_,{initialTitle:e.title,initialDescription:e.description??"",initialCronExpression:T?"":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 $=>{await a(e.id,{title:$.title,description:$.description,cron_expression:$.cronExpression||void 0,cli_tool:$.cliTool,skip_if_running:$.skipIfRunning,schedule_type:$.scheduleType,run_at:$.runAt}),m(!1)},onCancel:()=>m(!1)});const B={triggered:"bg-status-running",skipped:"bg-status-warning",completed:"bg-status-success",failed:"bg-status-error"},O={triggered:y("schedule.runTriggered"),skipped:y("schedule.runSkipped"),completed:y("schedule.runCompleted"),failed:y("schedule.runFailed")},F=$=>$?new Date($).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:D,children:[t.jsx("button",{className:"mt-0.5 text-warm-400 hover:text-warm-600 flex-shrink-0 transition-colors",children:t.jsx(Es,{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(Wi,{size:12}),T?F(e.run_at):e.cron_expression]}),t.jsx("span",{"aria-hidden":"true",children:"·"}),t.jsx("span",{children:y(T?"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?y("schedule.active"):y("schedule.paused")]})]})]}),t.jsxs("div",{className:"flex items-center gap-0.5 ml-2",onClick:$=>$.stopPropagation(),children:[t.jsx("button",{onClick:A,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:y("schedule.trigger"),children:t.jsx(Tr,{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?y("schedule.pause"):y("schedule.activate"),children:e.is_active?t.jsx(ip,{size:14}):t.jsx(rr,{size:14})}),t.jsx("button",{onClick:()=>m(!0),className:"p-1.5 text-warm-400 hover:text-accent hover:bg-accent/10 rounded-lg transition-colors",title:y("schedule.edit"),children:t.jsx(fi,{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:y("schedule.delete"),children:t.jsx(An,{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:y(T?"schedule.runAtLabel":"schedule.cronExpression")}),t.jsx("span",{className:"min-w-0 truncate font-mono text-warm-600",children:T?F(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:y("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():y("schedule.never")})]}),!T&&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"}),y("schedule.skipIfRunning")]})]}),t.jsxs("div",{children:[t.jsx("h4",{className:"text-xs font-semibold text-warm-500 uppercase tracking-wider mb-2",children:y("schedule.runs")}),d.length===0?t.jsx("p",{className:"text-xs text-warm-400 italic",children:y("schedule.noRuns")}):t.jsx("div",{className:"max-h-48 overflow-auto space-y-1",children:d.map($=>{const P=$.todo_id&&$.todo_status==="completed"&&!!$.todo_branch_name,H=$.todo_id&&$.todo_status!=="running"&&$.todo_status!=="pending"&&($.todo_worktree_path||$.todo_branch_name),W=_===$.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 ${B[$.status]||"bg-warm-400"}`}),O[$.status]||$.status]}),$.skipped_reason&&t.jsxs("span",{className:"text-warm-400",children:["(",$.skipped_reason,")"]}),t.jsxs("div",{className:"flex items-center gap-0.5 ml-auto",children:[P&&f&&t.jsx("button",{onClick:()=>R($),disabled:W,className:"p-1 text-status-merged/60 hover:text-status-merged hover:bg-status-merged/10 rounded-md transition-colors disabled:opacity-30",title:y("todo.merge"),children:t.jsx(vu,{size:12})}),H&&p&&t.jsx("button",{onClick:()=>j($),disabled:W,className:"p-1 text-status-warning/60 hover:text-status-warning hover:bg-status-warning/10 rounded-md transition-colors disabled:opacity-30",title:y("todo.cleanup"),children:t.jsx(An,{size:12})})]}),t.jsx("span",{className:"text-warm-400 font-mono flex-shrink-0",children:new Date($.started_at).toLocaleString()})]},$.id)})})]})]})]})}function y8({schedules:e,projectCliTool:s,onAddSchedule:i,onToggleSchedule:a,onDeleteSchedule:u,onEditSchedule:f,onTriggerSchedule:p,onMergeRun:o,onCleanupRun:c}){const[h,m]=S.useState(!1),[d,g]=S.useState(null),{t:b}=ft();return t.jsxs("div",{className:"min-h-[50vh]",onContextMenu:C=>{gi(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:b("schedules.title")}),!h&&t.jsxs("button",{onClick:()=>m(!0),className:"btn-primary btn-sm",children:[t.jsx(yn,{size:14}),b("schedules.add")]})]}),h&&t.jsx("div",{className:"mb-5",children:t.jsx(q_,{projectCliTool:s,onSave:async C=>{await i(C),m(!1)},onCancel:()=>m(!1)})}),t.jsx("div",{className:"space-y-3",children:e.length===0?t.jsx("div",{className:"card",children:t.jsx(Yi,{icon:c5,title:b("schedules.empty"),description:b("schedules.emptyHint")})}):e.map((C,k)=>t.jsx("div",{children:t.jsx(b8,{schedule:C,onToggle:a,onDelete:u,onEdit:f,onTrigger:p,onMergeRun:o,onCleanupRun:c})},C.id))}),d&&t.jsx(ir,{x:d.x,y:d.y,onClose:()=>g(null),children:t.jsxs("button",{type:"button",className:sn,onClick:()=>m(!0),children:[t.jsx(yn,{size:14}),b("schedules.add")]})})]})}function K_(e){const[s,i]=S.useState(()=>typeof window>"u"||!window.matchMedia?!1:window.matchMedia(e).matches);return S.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 vy="__custom__";function w8({open:e,onClose:s,projectId:i,projectName:a,onPushed:u}){const{t:f}=ft(),[p,o]=S.useState(!1),[c,h]=S.useState(!1),[m,d]=S.useState(null),[g,b]=S.useState([]),[C,k]=S.useState("origin"),[x,_]=S.useState([]),[w,y]=S.useState([]),[E,R]=S.useState(!0),[j,T]=S.useState(!1);S.useEffect(()=>{if(!e)return;let P=!1;return o(!0),d(null),Promise.all([UN(i),fm(i)]).then(([H,W])=>{var ee,Z;if(P)return;const G=H.remotes||[];b(G);const I=((ee=G.find(te=>te.name==="origin"))==null?void 0:ee.name)||((Z=G[0])==null?void 0:Z.name)||"origin";k(I);const z=W.branches||[],U=z.filter(te=>!te.remote),V=`remotes/${I}/`,q=z.filter(te=>te.remote&&te.name.startsWith(V)).map(te=>te.name.slice(V.length)).filter(te=>te&&te!=="HEAD");y(q);const oe=new Set(q);_(U.map(te=>{const Y=oe.has(te.name);return{local:te.name,current:te.current,remote:te.name,customRemote:!1,setUpstream:!Y,checked:te.current}}))}).catch(H=>{P||d(H instanceof Error?H.message:"Failed to load remotes")}).finally(()=>{P||o(!1)}),()=>{P=!0}},[e,i]),S.useEffect(()=>{if(!e||!C)return;let P=!1;return fm(i).then(H=>{if(P)return;const W=`remotes/${C}/`,G=(H.branches||[]).filter(I=>I.remote&&I.name.startsWith(W)).map(I=>I.name.slice(W.length)).filter(I=>I&&I!=="HEAD");y(G)}).catch(()=>{}),()=>{P=!0}},[C,i,e]);const N=x.length>0&&x.every(P=>P.checked),D=x.some(P=>P.checked),A=x.filter(P=>P.checked).length,B=S.useMemo(()=>{var P;return((P=g.find(H=>H.name===C))==null?void 0:P.url)||""},[g,C]),O=(P,H)=>{_(W=>W.map(G=>G.local===P?{...G,...H}:G))},F=()=>{const P=!N;_(H=>H.map(W=>({...W,checked:P})))},$=async()=>{d(null);const P=x.filter(W=>W.checked);if(P.length===0){d(f("git.pushDialog.errorRequireBranch"));return}const H=P.map(W=>({local:W.local,remote:(W.remote||"").trim()||W.local,setUpstream:W.setUpstream}));h(!0);try{await op(i,{remote:C,branches:H,pushAllTags:E,force:j}),u==null||u(),s()}catch(W){d(W instanceof Error?W.message:"Push failed")}finally{h(!1)}};return t.jsx(jn,{open:e,onClose:c?()=>{}:s,size:"2xl",disableBackdropClose:!0,disableEscClose:c,children:t.jsxs("div",{className:"card p-5 space-y-4",children:[t.jsxs("h3",{className:"text-base font-semibold",style:{color:"var(--color-text-primary)"},children:["Push : ",a]}),t.jsxs("div",{className:"flex items-center gap-3",children:[t.jsx("label",{className:"text-xs font-medium text-warm-500 whitespace-nowrap",children:f("git.pushDialog.targetRemote")}),t.jsxs("select",{value:C,onChange:P=>k(P.target.value),className:"input-field text-xs py-1.5 px-3 w-auto",disabled:p||c||g.length===0,children:[g.length===0&&t.jsx("option",{value:"origin",children:"origin"}),g.map(P=>t.jsx("option",{value:P.name,children:P.name},P.name))]}),t.jsx("input",{readOnly:!0,value:B,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:[p&&t.jsx("tr",{children:t.jsx("td",{colSpan:4,className:"py-6 text-center text-xs text-warm-500",children:f("git.pushDialog.loading")})}),!p&&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(P=>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:P.checked,onChange:H=>O(P.local,{checked:H.target.checked}),disabled:c,className:"cursor-pointer"})}),t.jsxs("td",{className:"py-2 px-3 font-mono text-xs",style:{color:"var(--color-text-primary)"},children:[P.local,P.current&&t.jsx("span",{className:"ml-1.5 text-[10px] text-status-warning",children:"●"})]}),t.jsx("td",{className:"py-2 px-3",children:P.customRemote?t.jsx("input",{type:"text",value:P.remote,onChange:H=>O(P.local,{remote:H.target.value}),placeholder:P.local,className:"input-field text-xs font-mono py-1 px-2 w-full",disabled:c}):t.jsxs("select",{value:w.includes(P.remote)||P.remote?P.remote:"",onChange:H=>{const W=H.target.value;W===vy?O(P.local,{customRemote:!0}):O(P.local,{remote:W})},className:"input-field text-xs font-mono py-1 px-2 w-full",disabled:c,children:[!w.includes(P.remote)&&P.remote&&t.jsxs("option",{value:P.remote,children:[P.remote," (",f("git.pushDialog.newBranch"),")"]}),w.map(H=>t.jsx("option",{value:H,children:H},H)),t.jsx("option",{value:vy,children:f("git.pushDialog.customRemote")})]})}),t.jsx("td",{className:"py-2 px-3",children:t.jsx("input",{type:"checkbox",checked:P.setUpstream,onChange:H=>O(P.local,{setUpstream:H.target.checked}),disabled:c,className:"cursor-pointer"})})]},P.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:P=>{P&&(P.indeterminate=!N&&D)},onChange:F,disabled:c||x.length===0,className:"cursor-pointer"}),f("git.pushDialog.selectAll")]}),t.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[t.jsx("input",{type:"checkbox",checked:E,onChange:P=>R(P.target.checked),disabled:c,className:"cursor-pointer"}),f("git.pushDialog.allTags")]}),t.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[t.jsx("input",{type:"checkbox",checked:j,onChange:P=>T(P.target.checked),disabled:c,className:"cursor-pointer"}),t.jsx("span",{title:f("git.pushDialog.forceHint"),children:f("git.pushDialog.force")})]})]}),m&&t.jsx("div",{className:"text-xs text-status-error font-medium",children:m}),t.jsxs("div",{className:"flex items-center justify-end gap-2 pt-1",children:[t.jsx("button",{type:"button",onClick:s,disabled:c,className:"btn-secondary btn-md",children:f("git.pushDialog.cancel")}),t.jsx("button",{type:"button",onClick:$,disabled:c||p||A===0,className:"btn-primary btn-md",children:f(c?"git.pushDialog.pushing":"git.pushDialog.submit")})]})]})})}function _8(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 Xu({files:e,loading:s,selectedFile:i,onFileClick:a,commitHash:u}){const{t:f}=ft();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(p=>{const o=_8(p.status),c=i===p.path;return t.jsxs("div",{onClick:()=>a(p.path),className:`flex items-center gap-2 px-3 py-1.5 cursor-pointer text-xs hover:bg-warm-50/50 transition-colors ${c?"bg-accent/10 border-l-2 border-accent":""}`,children:[t.jsx("span",{className:`font-mono font-bold text-2xs w-3 shrink-0 ${o.color}`,children:o.label}),t.jsxs("span",{className:"truncate flex-1 text-warm-600",title:p.path,children:[p.path.split("/").pop(),t.jsx("span",{className:"text-warm-400 ml-1 text-2xs",children:p.path.includes("/")?p.path.substring(0,p.path.lastIndexOf("/")):""})]}),t.jsxs("span",{className:"shrink-0 text-2xs text-status-success",children:["+",p.additions]}),t.jsxs("span",{className:"shrink-0 text-2xs text-status-error",children:["-",p.deletions]})]},p.path)})})]})}function eo({diff:e,loading:s,selectedFile:i,fileHeaders:a}){const{t:u}=ft(),[f,p]=S.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:()=>p(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(mN,{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,c=0,h=!1;return e.split(`
|
|
660
|
+
`).map((ge,Ae)=>{let rt="text-theme-text",_t="";return ge.startsWith("+")&&!ge.startsWith("+++")?rt="text-theme-text bg-status-success/15":ge.startsWith("-")&&!ge.startsWith("---")?rt="text-theme-text bg-status-error/15":ge.startsWith("@@")?rt="text-accent":ge.startsWith("diff ")&&(rt="text-warm-700",_t="font-semibold"),t.jsx("div",{className:`whitespace-pre ${rt} ${_t}`,children:ge},Ae)}):t.jsx("span",{className:"text-warm-400 italic",children:Q("log.noChanges")})})]}),t.jsxs("div",{className:"rounded-lg overflow-hidden",style:{background:Ue.bg,fontFamily:Ot,border:`1px solid ${Ue.separator}`},children:[t.jsxs("div",{style:{padding:"8px 12px",borderBottom:`1px solid ${Ue.separator}`,fontSize:12,color:Ue.text},children:[t.jsx("span",{style:{color:Ue.prompt},children:"$"})," ",t.jsx("span",{style:{color:Ue.bright},children:"tail"})," ",t.jsx("span",{style:{color:Ue.dim},children:"-f task.log"})]}),t.jsx($_,{logs:U,interactive:w&&e.status==="running",todoId:e.id,onSendInput:y,embedded:!0})]})]})})]}),ce&&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(fl,{size:14,className:"text-accent flex-shrink-0"}),t.jsx("span",{className:"text-xs font-medium text-accent",children:Q("dnd.dropHint")})]}),We&&t.jsxs("div",{className:"mt-1.5 flex items-center gap-2 px-4 py-2 rounded-lg border-2 border-dashed border-status-error/30 bg-status-error/10",children:[t.jsx(t5,{size:14,className:"text-status-error flex-shrink-0"}),t.jsx("span",{className:"text-xs font-medium text-status-error",children:Q("dnd.cyclicWarning")})]}),Xe&&t.jsxs(ir,{x:Xe.x,y:Xe.y,onClose:()=>ut(null),children:[ue&&t.jsxs("button",{onClick:()=>f(e.id,"headless"),className:sn,title:Q("todo.startHeadless"),children:[t.jsx(Tr,{size:14}),Q("todo.start")]}),ue&&Gs&&t.jsxs("button",{onClick:()=>f(e.id,"interactive"),className:sn,title:Q("todo.startInteractiveDesc"),children:[t.jsx(pi,{size:14}),Q("todo.startInteractive")]}),ue&&t.jsxs("button",{onClick:()=>f(e.id,"verbose"),className:sn,title:Q("todo.startVerboseDesc"),children:[t.jsx(cm,{size:14}),Q("todo.startVerbose")]}),ht&&t.jsxs("button",{onClick:()=>p(e.id),className:sn,children:[t.jsx(Ki,{size:14}),Q("todo.stop")]}),at&&t.jsxs("button",{onClick:Xn,disabled:De,className:sn,children:[t.jsx(vu,{size:14}),Q("todo.merge")]}),Ct&&t.jsxs("button",{onClick:()=>{be(!0),re(null)},disabled:_e,className:sn,children:[t.jsx(K0,{size:14}),Q("todo.continue")]}),bt&&t.jsxs("button",{onClick:()=>xs("headless"),disabled:fe,className:sn,children:[t.jsx(mi,{size:14}),Q("todo.retry")]}),Fe&&t.jsxs("button",{onClick:()=>mt(!0),className:sn,title:Q("todo.scheduleDesc"),children:[t.jsx(om,{size:14}),Q("todo.schedule")]}),Ve&&t.jsxs("button",{onClick:()=>{J(!0),Je(null)},className:sn,title:Q("todo.scheduleOnResetDesc"),children:[t.jsx(Wi,{size:14}),Q("todo.scheduleOnReset")]}),Ne&&t.jsxs("button",{onClick:vn,disabled:he,className:sn,children:[t.jsx(tl,{size:14}),Q("todo.viewDiff")]}),$&&an&&t.jsxs("button",{onClick:Pn,className:sn,children:[t.jsx(J0,{size:14}),Q("todo.viewDebugLog")]}),qt&&t.jsxs("button",{onClick:Ds,disabled:Oe,className:sn,children:[t.jsx(xu,{size:14}),Q("todo.cleanup")]}),t.jsx(W_,{}),t.jsxs("button",{onClick:()=>z(!0),className:sn,children:[t.jsx(fi,{size:14}),Q("todo.edit")]}),t.jsxs("button",{onClick:()=>o(e.id),className:Mp,children:[t.jsx(An,{size:14}),Q("todo.delete")]})]})]})}const h8=S.lazy(()=>Wu(()=>import("./TaskGraph-BohSFDDr.js"),__vite__mapDeps([0,1,2,3,4]))),Yc={all:null,active:["pending","running"],completed:["completed","merged"],cancelled:["stopped","failed"]};function gy(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(p=>p.id===a);a=(f==null?void 0:f.depends_on)??null}return!1}function f8({todos:e,projectId:s,projectCliTool:i,projectIsGitRepo:a,projectUseWorktree:u,onAddTodo:f,onStartAll:p,onStopAll:o,onStartTodo:c,onStopTodo:h,onDeleteTodo:m,onEditTodo:d,onMergeTodo:g,onMergeChain:b,onCleanupTodo:C,onRetryTodo:k,onContinueTodo:x,onFixTodo:_,onScheduleTodo:w,onScheduleOnResetTodo:y,resetsAt:E,onUpdateDependency:R,onUpdatePosition:j,onReorderTodos:T,onEvent:N,onSendInput:D,interactiveTodos:A,debugLogging:B,showTokenUsage:O}){var qe;const[F,$]=S.useState(!1),[P,H]=S.useState(null),[W,G]=S.useState(null),[I,z]=S.useState(null),[U,V]=S.useState(null),[q,oe]=S.useState(()=>{try{return localStorage.getItem("todoViewMode")||"list"}catch{return"list"}}),[ee,Z]=S.useState(()=>{try{return localStorage.getItem("todoStatusFilter")||"all"}catch{return"all"}}),[te,Y]=S.useState(()=>{try{return localStorage.getItem("todoStackModeEnabled")==="true"}catch{return!1}}),[he,de]=S.useState(()=>{try{return localStorage.getItem("todoStackCollapsed")==="true"}catch{return!1}}),{t:ye}=ft(),le=S.useCallback(Ee=>{oe(Ee);try{localStorage.setItem("todoViewMode",Ee)}catch{}},[]),De=S.useCallback(Ee=>{Z(Ee);try{localStorage.setItem("todoStatusFilter",Ee)}catch{}},[]),Re=S.useCallback(()=>{Y(Ee=>{const st=!Ee;try{localStorage.setItem("todoStackModeEnabled",String(st))}catch{}if(!st){de(!1);try{localStorage.setItem("todoStackCollapsed","false")}catch{}}return st})},[]),ve=S.useCallback(()=>{de(Ee=>{const st=!Ee;try{localStorage.setItem("todoStackCollapsed",String(st))}catch{}return st})},[]),Me=te&&he&&q==="list",Oe=S.useMemo(()=>({all:e.length,active:e.filter(Ee=>Yc.active.includes(Ee.status)).length,completed:e.filter(Ee=>Yc.completed.includes(Ee.status)).length,cancelled:e.filter(Ee=>Yc.cancelled.includes(Ee.status)).length}),[e]),tt=S.useMemo(()=>{const Ee=Yc[ee];return Ee?e.filter(st=>Ee.includes(st.status)):e},[e,ee]),nt=(()=>{const Ee=[...tt].sort((dt,kt)=>dt.priority-kt.priority);if(ee!=="all"||Me)return Ee.map(dt=>({todo:dt,depth:0}));const st=new Map,lt=[];for(const dt of Ee)if(dt.depends_on){const kt=st.get(dt.depends_on)||[];kt.push(dt),st.set(dt.depends_on,kt)}else lt.push(dt);const yt=[],mt=new Set,pt=(dt,kt)=>{if(mt.has(dt.id))return;mt.add(dt.id),yt.push({todo:dt,depth:kt});const gt=st.get(dt.id);if(gt)for(const vt of gt)pt(vt,kt+1)};for(const dt of lt)pt(dt,0);for(const dt of Ee)mt.has(dt.id)||yt.push({todo:dt,depth:0});return yt})(),{completedChainRoots:ke,completedChainMembers:fe}=S.useMemo(()=>{const Ee=new Map;for(const mt of e)if(mt.depends_on){const pt=Ee.get(mt.depends_on)||[];pt.push(mt.id),Ee.set(mt.depends_on,pt)}const st=e.filter(mt=>!mt.depends_on&&Ee.has(mt.id)),lt=new Map,yt=new Set;for(const mt of st){const pt=[],dt=kt=>{if(!e.find(Tt=>Tt.id===kt))return;pt.push(kt);const vt=Ee.get(kt)||[];for(const Tt of vt)dt(Tt)};if(dt(mt.id),pt.length>=2&&pt.every(kt=>{const gt=e.find(vt=>vt.id===kt);return(gt==null?void 0:gt.status)==="completed"||(gt==null?void 0:gt.status)==="merged"})){lt.set(mt.id,pt.length);for(const kt of pt)yt.add(kt)}}return{completedChainRoots:lt,completedChainMembers:yt}},[e]),[Te,Ce]=S.useState(null),[Ge,Ze]=S.useState(null),be=S.useCallback(async Ee=>{if(b){Ce(Ee),Ze(null);try{await b(Ee)}catch(st){Ze(st instanceof Error?st.message:"Merge failed")}finally{Ce(null)}}},[b]),Be=S.useRef(!1),ne=S.useCallback(Ee=>{Be.current=!1,G(Ee)},[]),_e=S.useCallback(async()=>{if(!Be.current&&W&&R){const Ee=e.find(st=>st.id===W);Ee!=null&&Ee.depends_on&&await R(W,null)}G(null),z(null),V(null)},[W,e,R]),X=S.useCallback(Ee=>{z(Ee),V(null)},[]),me=S.useCallback(Ee=>{z(st=>st===Ee?null:st)},[]),re=S.useCallback(async Ee=>{!W||!R||W!==Ee&&(gy(e,W,Ee)||(Be.current=!0,await R(W,Ee),G(null),z(null),V(null)))},[W,e,R]),ae=S.useCallback(async Ee=>{R&&await R(Ee,null)},[R]),J=S.useCallback(Ee=>!W||W===Ee?!1:!gy(e,W,Ee),[W,e]),se=S.useCallback(Ee=>{V(Ee),z(null)},[]),pe=S.useCallback(Ee=>{V(st=>st===Ee?null:st)},[]),we=S.useCallback(async(Ee,st)=>{if(!W||!T)return;const lt=st.indexOf(W);if(lt<0)return;const yt=st.filter(dt=>dt!==W),mt=Ee>lt?Ee-1:Ee;if(mt===lt){V(null);return}const pt=[...yt.slice(0,mt),W,...yt.slice(mt)];Be.current=!0,await T(pt),G(null),V(null),z(null)},[W,T]),je=e.some(Ee=>Ee.status==="pending"||Ee.status==="failed"||Ee.status==="stopped"),$e=e.some(Ee=>Ee.status==="running"),Je=t.jsxs(t.Fragment,{children:[t.jsxs("button",{onClick:p,disabled:!je,className:"btn-ghost text-sm",children:[t.jsx(Tr,{size:14}),ye("header.runAll")]}),t.jsxs("button",{onClick:o,disabled:!$e,className:"btn-ghost text-sm",children:[t.jsx(Ki,{size:14}),ye("header.stopAll")]})]});return q==="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:ye("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(Sn,{onClick:()=>le("list"),label:ye("graph.listView"),size:"sm",children:t.jsx(yu,{size:14})}),t.jsx(Sn,{onClick:()=>le("graph"),label:ye("graph.graphView"),size:"sm",variant:"active",pressed:!0,children:t.jsx(Y0,{size:14})})]}),Je]})]}),t.jsx(S.Suspense,{fallback:null,children:t.jsx(h8,{todos:e,projectId:s,projectCliTool:i,projectIsGitRepo:a,projectUseWorktree:u,onAddTodo:f,onStartTodo:c,onStopTodo:h,onDeleteTodo:m,onEditTodo:d,onMergeTodo:g,onCleanupTodo:C,onRetryTodo:k,onContinueTodo:x,onFixTodo:_,onUpdateDependency:R,onUpdatePosition:j,onEvent:N,onSendInput:D,interactiveTodos:A,debugLogging:B,showTokenUsage:O})})]}):t.jsxs("div",{className:"min-h-[50vh]",onContextMenu:Ee=>{gi(Ee)||(Ee.preventDefault(),H({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:ye("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(Sn,{onClick:()=>le("list"),label:ye("graph.listView"),size:"sm",variant:"active",pressed:!0,children:t.jsx(yu,{size:14})}),t.jsx(Sn,{onClick:()=>le("graph"),label:ye("graph.graphView"),size:"sm",children:t.jsx(Y0,{size:14})})]}),t.jsx(Sn,{onClick:Re,label:ye(te?"todos.stackModeOn":"todos.stackModeOff"),size:"sm",variant:te?"active":"default",pressed:te,children:t.jsx(bE,{size:14})}),te&&!he&&q==="list"&&nt.length>0&&t.jsx(Sn,{onClick:ve,label:ye("todos.collapseStack"),size:"sm",children:t.jsx(S5,{size:14})}),Je,!F&&t.jsxs("button",{onClick:()=>$(!0),className:"btn-primary text-xs py-2",children:[t.jsx(yn,{size:14}),ye("todos.add")]})]})]}),F&&t.jsx("div",{className:"mb-5",children:t.jsx(U_,{projectId:s,projectCliTool:i,projectIsGitRepo:a,projectUseWorktree:u,availableTodos:e,onSave:async(Ee,st,lt,yt,mt,pt,dt,kt,gt,vt)=>{await f(Ee,st,lt,yt,mt,pt,dt,kt,gt,vt),$(!1)},onCancel:()=>$(!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 st=ee===Ee,lt=Ee==="all"?"todos.filterAll":Ee==="active"?"todos.filterActive":Ee==="completed"?"todos.filterCompleted":"todos.filterCancelled";return t.jsxs("button",{onClick:()=>De(Ee),className:`inline-flex items-center gap-1.5 px-3 py-1.5 rounded-md text-xs font-medium transition-colors ${st?"bg-theme-card shadow-sm text-accent":"text-warm-500 hover:text-warm-700"}`,children:[t.jsx("span",{children:ye(lt)}),t.jsx("span",{className:`text-2xs font-mono ${st?"text-accent/70":"text-warm-400"}`,children:Oe[Ee]})]},Ee)})}),t.jsx("div",{className:Me?"relative cursor-pointer":"space-y-3",onClick:Me?ve:void 0,title:Me?ye("todos.expandStack"):void 0,style:Me?{height:76+Math.max(nt.length-1,0)*6}:void 0,children:nt.length===0?t.jsx("div",{className:"card",children:t.jsx(Yi,{icon:Vw,title:ye(ee==="all"?"todos.empty":"todos.filterEmpty"),description:ee==="all"?ye("todos.emptyHint"):void 0})}):(()=>{const Ee=nt.map(({todo:lt})=>lt.id),st=lt=>{if(Me||!T)return null;const yt=W!==null&&U===lt;return t.jsx("div",{onDragEnter:mt=>{mt.preventDefault(),se(lt)},onDragOver:mt=>{mt.preventDefault(),mt.stopPropagation(),mt.dataTransfer.dropEffect="link",se(lt)},onDragLeave:()=>pe(lt),onDrop:mt=>{mt.preventDefault(),mt.stopPropagation(),we(lt,Ee)},className:"relative",style:{height:16,marginTop:-8,marginBottom:-8},children:yt&&t.jsx("div",{className:"absolute inset-x-0 top-1/2 -translate-y-1/2 h-0.5 bg-accent rounded-full shadow-[0_0_6px_rgba(0,0,0,0.15)]"})},`gap-${lt}`)};return t.jsxs(t.Fragment,{children:[st(0),nt.map(({todo:lt,depth:yt},mt)=>{const pt=ke.has(lt.id),dt=fe.has(lt.id),kt=6,gt="top 400ms cubic-bezier(0.2, 0.8, 0.2, 1), opacity 300ms ease",vt=Me?{position:"absolute",top:mt*kt,left:0,right:0,zIndex:nt.length+10-mt,opacity:mt===0?1:.9,pointerEvents:mt===0?"auto":"none",transition:gt}:{transition:gt};return t.jsxs("div",{className:"",style:vt,children:[!Me&&pt&&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(fl,{size:16,className:"text-theme-muted flex-shrink-0"}),t.jsx("span",{className:"text-xs font-semibold text-theme-text-secondary",children:ye("todo.chainComplete")}),t.jsx("span",{className:"text-2xs font-mono text-warm-400",children:ye("todo.chainTasks").replace("{count}",String(ke.get(lt.id)))}),t.jsxs("div",{className:"ml-auto flex items-center gap-2",children:[Ge&&Te===null&&t.jsx("span",{className:"text-2xs text-status-error",children:Ge}),t.jsxs("button",{onClick:()=>be(lt.id),disabled:Te===lt.id,className:"btn-secondary text-xs py-1.5 disabled:opacity-50",title:ye("todo.mergeChainDesc"),children:[t.jsx(Xj,{size:14}),Te===lt.id?"...":ye("todo.mergeChain")]})]})]}),t.jsxs("div",{className:"relative",style:{marginLeft:yt>0?`${yt*24}px`:void 0},children:[yt>0&&t.jsx("div",{className:"absolute top-0 bottom-0 w-px",style:{left:"-13px",backgroundColor:"var(--color-border)"}}),t.jsx(d8,{todo:lt,allTodos:e,projectCliTool:i,projectIsGitRepo:a,projectUseWorktree:u,onStart:c,onStop:h,onDelete:m,onEdit:d,onMerge:g,onCleanup:C,onRetry:k,onContinue:x,onFix:_,onSchedule:w,onScheduleOnReset:y,resetsAt:E,onEvent:N,isInteractive:A.has(lt.id),onSendInput:D,isDragSource:W===lt.id,isDragging:W!==null,isDragOver:I===lt.id,isValidDropTarget:J(lt.id),onDragStart:ne,onDragEnd:_e,onDragOverTarget:X,onDragLeaveTarget:me,onDropTarget:re,onRemoveDependency:R?ae:void 0,debugLogging:B,showTokenUsage:O,isChainMember:dt})]}),st(mt+1)]},lt.id)})]})})()}),!Me&&W&&((qe=e.find(Ee=>Ee.id===W))==null?void 0:qe.depends_on)&&t.jsxs("div",{className:"mt-3 border-2 border-dashed border-status-error/30 rounded-lg p-4 text-center text-sm text-status-error transition-colors hover:border-status-error/30 hover:text-status-error hover:bg-status-error/10",onDragOver:Ee=>{Ee.preventDefault(),Ee.dataTransfer.dropEffect="move"},onDrop:Ee=>{Ee.preventDefault(),W&&R&&(Be.current=!0,R(W,null))},children:[t.jsx(yN,{size:20,className:"mx-auto mb-1"}),ye("dnd.dropToRemoveDep")]}),P&&t.jsx(ir,{x:P.x,y:P.y,onClose:()=>H(null),children:t.jsxs("button",{onClick:()=>$(!0),className:sn,children:[t.jsx(yn,{size:14}),ye("todos.add")]})})]})}const m8=[{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 p8(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,,p]=i,o=a.match(/^\*\/(\d+)$/);if(o&&u==="*"&&f==="*"&&p==="*")return{...s,mode:"minutes",everyMinutes:parseInt(o[1])};if(/^\d+$/.test(a)&&u==="*"&&f==="*"&&p==="*")return{...s,mode:"hourly",hourlyMinute:parseInt(a)};const c=/^\d+$/.test(a)?parseInt(a):-1,h=/^\d+$/.test(u)?parseInt(u):-1;if(c<0||h<0)return{...s,mode:"custom"};if(f==="*"&&p!=="*"){const m=p.split(",").map(d=>{const g=parseInt(d);return isNaN(g)?-1:g}).filter(d=>d>=0);if(m.length>0)return{...s,mode:"weekly",weeklyDays:m,weeklyHour:h,weeklyMinute:c}}return/^\d+$/.test(f)&&p==="*"?{...s,mode:"monthly",monthlyDay:parseInt(f),monthlyHour:h,monthlyMinute:c}:f==="*"&&p==="*"?{...s,mode:"daily",dailyHour:h,dailyMinute:c}:{...s,mode:"custom"}}function xy(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 g8({value:e,onChange:s}){const{t:i}=ft(),[a,u]=S.useState(()=>p8(e)),[f,p]=S.useState(e);S.useEffect(()=>{if(a.mode==="custom")s(f);else{const b=xy(a);s(b)}},[a,f]);const o=b=>{u(C=>({...C,...b}))},c=b=>{u(C=>{const k=C.weeklyDays.includes(b)?C.weeklyDays.filter(x=>x!==b):[...C.weeklyDays,b];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"}],m="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=(b,C,k,x)=>t.jsxs("div",{className:"flex items-center gap-1.5",children:[t.jsx("select",{value:b,onChange:_=>k(parseInt(_.target.value)),className:`${m} w-16`,children:Array.from({length:24},(_,w)=>t.jsx("option",{value:w,children:String(w).padStart(2,"0")},w))}),t.jsx("span",{className:"text-warm-500 font-mono",children:":"}),t.jsx("select",{value:C,onChange:_=>x(parseInt(_.target.value)),className:`${m} w-16`,children:Array.from({length:12},(_,w)=>w*5).map(_=>t.jsx("option",{value:_,children:String(_).padStart(2,"0")},_))})]}),g=a.mode==="custom"?f:xy(a);return t.jsxs("div",{className:"space-y-3",children:[t.jsx("div",{className:"flex flex-wrap gap-1.5",children:h.map(b=>t.jsx("button",{type:"button",onClick:()=>o({mode:b.value}),className:`px-2.5 py-1 rounded-md text-xs font-medium transition-colors ${a.mode===b.value?"bg-accent text-white":"bg-warm-100 text-warm-500 hover:bg-warm-200"}`,children:i(b.labelKey)},b.value))}),t.jsxs("div",{className:"bg-warm-50 rounded-lg p-3",children:[a.mode==="minutes"&&t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("span",{className:"text-sm text-warm-600",children:i("cron.every")}),t.jsx("select",{value:a.everyMinutes,onChange:b=>o({everyMinutes:parseInt(b.target.value)}),className:`${m} w-20`,children:[5,10,15,20,30].map(b=>t.jsx("option",{value:b,children:b},b))}),t.jsx("span",{className:"text-sm text-warm-600",children:i("cron.minutesLabel")})]}),a.mode==="hourly"&&t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("span",{className:"text-sm text-warm-600",children:i("cron.everyHourAt")}),t.jsx("select",{value:a.hourlyMinute,onChange:b=>o({hourlyMinute:parseInt(b.target.value)}),className:`${m} w-16`,children:Array.from({length:12},(b,C)=>C*5).map(b=>t.jsx("option",{value:b,children:String(b).padStart(2,"0")},b))}),t.jsx("span",{className:"text-sm text-warm-600",children:i("cron.minutesPast")})]}),a.mode==="daily"&&t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("span",{className:"text-sm text-warm-600",children:i("cron.everyDayAt")}),d(a.dailyHour,a.dailyMinute,b=>o({dailyHour:b}),b=>o({dailyMinute:b}))]}),a.mode==="weekly"&&t.jsxs("div",{className:"space-y-3",children:[t.jsx("div",{className:"flex flex-wrap gap-1.5",children:m8.map(b=>t.jsx("button",{type:"button",onClick:()=>c(b.value),className:`w-9 h-9 rounded-lg text-xs font-medium transition-colors ${a.weeklyDays.includes(b.value)?"bg-accent text-white":"bg-theme-card text-warm-500 border border-warm-200 hover:border-accent"}`,children:i(b.labelKey)},b.value))}),t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("span",{className:"text-sm text-warm-600",children:i("cron.at")}),d(a.weeklyHour,a.weeklyMinute,b=>o({weeklyHour:b}),b=>o({weeklyMinute:b}))]})]}),a.mode==="monthly"&&t.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[t.jsx("span",{className:"text-sm text-warm-600",children:i("cron.everyMonthOn")}),t.jsx("select",{value:a.monthlyDay,onChange:b=>o({monthlyDay:parseInt(b.target.value)}),className:`${m} w-16`,children:Array.from({length:28},(b,C)=>C+1).map(b=>t.jsx("option",{value:b,children:b},b))}),t.jsx("span",{className:"text-sm text-warm-600",children:i("cron.dayAt")}),d(a.monthlyHour,a.monthlyMinute,b=>o({monthlyHour:b}),b=>o({monthlyMinute:b}))]}),a.mode==="custom"&&t.jsxs("div",{children:[t.jsx("input",{type:"text",placeholder:"*/30 * * * *",value:f,onChange:b=>p(b.target.value),className:"bg-warm-50 border border-warm-300 rounded-lg px-3 py-1.5 w-full text-sm text-warm-800 font-mono transition-all duration-200 focus:border-accent focus:outline-none focus:ring-2 focus:ring-accent/20"}),t.jsx("p",{className:"text-2xs text-warm-400 mt-1",children:i("schedule.cronHint")})]})]}),a.mode!=="custom"&&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 x8(){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 v8(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"),p=String(s.getMinutes()).padStart(2,"0");return`${i}-${a}-${u}T${f}:${p}`}function q_({onSave:e,onCancel:s,initialTitle:i="",initialDescription:a="",initialCronExpression:u="",initialCliTool:f,initialSkipIfRunning:p=!0,initialScheduleType:o="recurring",initialRunAt:c,projectCliTool:h="claude"}){const[m,d]=S.useState(i),[g,b]=S.useState(a),[C,k]=S.useState(u),[x,_]=S.useState(f||h||"claude"),[w,y]=S.useState(p),[E,R]=S.useState(o),[j,T]=S.useState(c?v8(c):x8()),{t:N}=ft(),D=E==="once",A=m.trim()&&(D?!!j:!!C.trim()),B=O=>{O.preventDefault(),A&&e({title:m.trim(),description:g.trim(),cronExpression:D?"":C.trim(),cliTool:x,skipIfRunning:w,scheduleType:E,runAt:D?new Date(j).toISOString():void 0})};return t.jsxs("form",{onSubmit:B,className:"card p-5",children:[t.jsx("div",{className:"mb-3",children:t.jsx("input",{type:"text",placeholder:N("scheduleForm.titlePlaceholder"),value:m,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=>b(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 ${E==="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 ${E==="once"?"bg-theme-card text-warm-700 shadow-sm":"text-warm-500 hover:text-warm-700"}`,children:N("schedule.once")})]})]}),D?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:j,onChange:O=>T(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(g8,{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=>_(O.target.value),className:"input-field text-sm !py-2",children:Is.map(O=>t.jsx("option",{value:O.value,children:O.label},O.value))})]})}),!D&&t.jsx("div",{className:"mb-4",children:t.jsxs("label",{className:"flex items-center gap-2 text-sm text-warm-600 cursor-pointer",children:[t.jsx("input",{type:"checkbox",checked:w,onChange:O=>y(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:!A,className:"btn-primary text-sm",children:N("scheduleForm.save")})]})]})}function b8({schedule:e,onToggle:s,onDelete:i,onEdit:a,onTrigger:u,onMergeRun:f,onCleanupRun:p}){const[o,c]=S.useState(!1),[h,m]=S.useState(!1),[d,g]=S.useState([]),[b,C]=S.useState(!1),[k,x]=S.useState(!1),[_,w]=S.useState(null),{t:y}=ft(),E=async()=>{try{const $=await vf(e.id);g($)}catch{}},R=async $=>{if(!(!$.todo_id||!f)){w($.id);try{await f($.todo_id),await E()}finally{w(null)}}},j=async $=>{if(!(!$.todo_id||!p)){w($.id);try{await p($.todo_id),await E()}finally{w(null)}}},T=e.schedule_type==="once",N=async()=>{if(!b)try{const $=await vf(e.id);g($),C(!0)}catch{}},D=()=>{const $=!o;c($),$&&N()},A=async()=>{x(!0);try{await u(e.id);const $=await vf(e.id);g($),C(!0)}finally{x(!1)}};if(h)return t.jsx(q_,{initialTitle:e.title,initialDescription:e.description??"",initialCronExpression:T?"":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 $=>{await a(e.id,{title:$.title,description:$.description,cron_expression:$.cronExpression||void 0,cli_tool:$.cliTool,skip_if_running:$.skipIfRunning,schedule_type:$.scheduleType,run_at:$.runAt}),m(!1)},onCancel:()=>m(!1)});const B={triggered:"bg-status-running",skipped:"bg-status-warning",completed:"bg-status-success",failed:"bg-status-error"},O={triggered:y("schedule.runTriggered"),skipped:y("schedule.runSkipped"),completed:y("schedule.runCompleted"),failed:y("schedule.runFailed")},F=$=>$?new Date($).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:D,children:[t.jsx("button",{className:"mt-0.5 text-warm-400 hover:text-warm-600 flex-shrink-0 transition-colors",children:t.jsx(Es,{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(Wi,{size:12}),T?F(e.run_at):e.cron_expression]}),t.jsx("span",{"aria-hidden":"true",children:"·"}),t.jsx("span",{children:y(T?"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?y("schedule.active"):y("schedule.paused")]})]})]}),t.jsxs("div",{className:"flex items-center gap-0.5 ml-2",onClick:$=>$.stopPropagation(),children:[t.jsx("button",{onClick:A,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:y("schedule.trigger"),children:t.jsx(Tr,{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?y("schedule.pause"):y("schedule.activate"),children:e.is_active?t.jsx(ip,{size:14}):t.jsx(rr,{size:14})}),t.jsx("button",{onClick:()=>m(!0),className:"p-1.5 text-warm-400 hover:text-accent hover:bg-accent/10 rounded-lg transition-colors",title:y("schedule.edit"),children:t.jsx(fi,{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:y("schedule.delete"),children:t.jsx(An,{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:y(T?"schedule.runAtLabel":"schedule.cronExpression")}),t.jsx("span",{className:"min-w-0 truncate font-mono text-warm-600",children:T?F(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:y("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():y("schedule.never")})]}),!T&&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"}),y("schedule.skipIfRunning")]})]}),t.jsxs("div",{children:[t.jsx("h4",{className:"text-xs font-semibold text-warm-500 uppercase tracking-wider mb-2",children:y("schedule.runs")}),d.length===0?t.jsx("p",{className:"text-xs text-warm-400 italic",children:y("schedule.noRuns")}):t.jsx("div",{className:"max-h-48 overflow-auto space-y-1",children:d.map($=>{const P=$.todo_id&&$.todo_status==="completed"&&!!$.todo_branch_name,H=$.todo_id&&$.todo_status!=="running"&&$.todo_status!=="pending"&&($.todo_worktree_path||$.todo_branch_name),W=_===$.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 ${B[$.status]||"bg-warm-400"}`}),O[$.status]||$.status]}),$.skipped_reason&&t.jsxs("span",{className:"text-warm-400",children:["(",$.skipped_reason,")"]}),t.jsxs("div",{className:"flex items-center gap-0.5 ml-auto",children:[P&&f&&t.jsx("button",{onClick:()=>R($),disabled:W,className:"p-1 text-status-merged/60 hover:text-status-merged hover:bg-status-merged/10 rounded-md transition-colors disabled:opacity-30",title:y("todo.merge"),children:t.jsx(vu,{size:12})}),H&&p&&t.jsx("button",{onClick:()=>j($),disabled:W,className:"p-1 text-status-warning/60 hover:text-status-warning hover:bg-status-warning/10 rounded-md transition-colors disabled:opacity-30",title:y("todo.cleanup"),children:t.jsx(An,{size:12})})]}),t.jsx("span",{className:"text-warm-400 font-mono flex-shrink-0",children:new Date($.started_at).toLocaleString()})]},$.id)})})]})]})]})}function y8({schedules:e,projectCliTool:s,onAddSchedule:i,onToggleSchedule:a,onDeleteSchedule:u,onEditSchedule:f,onTriggerSchedule:p,onMergeRun:o,onCleanupRun:c}){const[h,m]=S.useState(!1),[d,g]=S.useState(null),{t:b}=ft();return t.jsxs("div",{className:"min-h-[50vh]",onContextMenu:C=>{gi(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:b("schedules.title")}),!h&&t.jsxs("button",{onClick:()=>m(!0),className:"btn-primary btn-sm",children:[t.jsx(yn,{size:14}),b("schedules.add")]})]}),h&&t.jsx("div",{className:"mb-5",children:t.jsx(q_,{projectCliTool:s,onSave:async C=>{await i(C),m(!1)},onCancel:()=>m(!1)})}),t.jsx("div",{className:"space-y-3",children:e.length===0?t.jsx("div",{className:"card",children:t.jsx(Yi,{icon:c5,title:b("schedules.empty"),description:b("schedules.emptyHint")})}):e.map((C,k)=>t.jsx("div",{children:t.jsx(b8,{schedule:C,onToggle:a,onDelete:u,onEdit:f,onTrigger:p,onMergeRun:o,onCleanupRun:c})},C.id))}),d&&t.jsx(ir,{x:d.x,y:d.y,onClose:()=>g(null),children:t.jsxs("button",{type:"button",className:sn,onClick:()=>m(!0),children:[t.jsx(yn,{size:14}),b("schedules.add")]})})]})}function K_(e){const[s,i]=S.useState(()=>typeof window>"u"||!window.matchMedia?!1:window.matchMedia(e).matches);return S.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 vy="__custom__";function w8({open:e,onClose:s,projectId:i,projectName:a,onPushed:u}){const{t:f}=ft(),[p,o]=S.useState(!1),[c,h]=S.useState(!1),[m,d]=S.useState(null),[g,b]=S.useState([]),[C,k]=S.useState("origin"),[x,_]=S.useState([]),[w,y]=S.useState([]),[E,R]=S.useState(!0),[j,T]=S.useState(!1);S.useEffect(()=>{if(!e)return;let P=!1;return o(!0),d(null),Promise.all([UN(i),fm(i)]).then(([H,W])=>{var ee,Z;if(P)return;const G=H.remotes||[];b(G);const I=((ee=G.find(te=>te.name==="origin"))==null?void 0:ee.name)||((Z=G[0])==null?void 0:Z.name)||"origin";k(I);const z=W.branches||[],U=z.filter(te=>!te.remote),V=`remotes/${I}/`,q=z.filter(te=>te.remote&&te.name.startsWith(V)).map(te=>te.name.slice(V.length)).filter(te=>te&&te!=="HEAD");y(q);const oe=new Set(q);_(U.map(te=>{const Y=oe.has(te.name);return{local:te.name,current:te.current,remote:te.name,customRemote:!1,setUpstream:!Y,checked:te.current}}))}).catch(H=>{P||d(H instanceof Error?H.message:"Failed to load remotes")}).finally(()=>{P||o(!1)}),()=>{P=!0}},[e,i]),S.useEffect(()=>{if(!e||!C)return;let P=!1;return fm(i).then(H=>{if(P)return;const W=`remotes/${C}/`,G=(H.branches||[]).filter(I=>I.remote&&I.name.startsWith(W)).map(I=>I.name.slice(W.length)).filter(I=>I&&I!=="HEAD");y(G)}).catch(()=>{}),()=>{P=!0}},[C,i,e]);const N=x.length>0&&x.every(P=>P.checked),D=x.some(P=>P.checked),A=x.filter(P=>P.checked).length,B=S.useMemo(()=>{var P;return((P=g.find(H=>H.name===C))==null?void 0:P.url)||""},[g,C]),O=(P,H)=>{_(W=>W.map(G=>G.local===P?{...G,...H}:G))},F=()=>{const P=!N;_(H=>H.map(W=>({...W,checked:P})))},$=async()=>{d(null);const P=x.filter(W=>W.checked);if(P.length===0){d(f("git.pushDialog.errorRequireBranch"));return}const H=P.map(W=>({local:W.local,remote:(W.remote||"").trim()||W.local,setUpstream:W.setUpstream}));h(!0);try{await op(i,{remote:C,branches:H,pushAllTags:E,force:j}),u==null||u(),s()}catch(W){d(W instanceof Error?W.message:"Push failed")}finally{h(!1)}};return t.jsx(jn,{open:e,onClose:c?()=>{}:s,size:"2xl",disableBackdropClose:!0,disableEscClose:c,children:t.jsxs("div",{className:"card p-5 space-y-4",children:[t.jsxs("h3",{className:"text-base font-semibold",style:{color:"var(--color-text-primary)"},children:["Push : ",a]}),t.jsxs("div",{className:"flex items-center gap-3",children:[t.jsx("label",{className:"text-xs font-medium text-warm-500 whitespace-nowrap",children:f("git.pushDialog.targetRemote")}),t.jsxs("select",{value:C,onChange:P=>k(P.target.value),className:"input-field text-xs py-1.5 px-3 w-auto",disabled:p||c||g.length===0,children:[g.length===0&&t.jsx("option",{value:"origin",children:"origin"}),g.map(P=>t.jsx("option",{value:P.name,children:P.name},P.name))]}),t.jsx("input",{readOnly:!0,value:B,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:[p&&t.jsx("tr",{children:t.jsx("td",{colSpan:4,className:"py-6 text-center text-xs text-warm-500",children:f("git.pushDialog.loading")})}),!p&&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(P=>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:P.checked,onChange:H=>O(P.local,{checked:H.target.checked}),disabled:c,className:"cursor-pointer"})}),t.jsxs("td",{className:"py-2 px-3 font-mono text-xs",style:{color:"var(--color-text-primary)"},children:[P.local,P.current&&t.jsx("span",{className:"ml-1.5 text-[10px] text-status-warning",children:"●"})]}),t.jsx("td",{className:"py-2 px-3",children:P.customRemote?t.jsx("input",{type:"text",value:P.remote,onChange:H=>O(P.local,{remote:H.target.value}),placeholder:P.local,className:"input-field text-xs font-mono py-1 px-2 w-full",disabled:c}):t.jsxs("select",{value:w.includes(P.remote)||P.remote?P.remote:"",onChange:H=>{const W=H.target.value;W===vy?O(P.local,{customRemote:!0}):O(P.local,{remote:W})},className:"input-field text-xs font-mono py-1 px-2 w-full",disabled:c,children:[!w.includes(P.remote)&&P.remote&&t.jsxs("option",{value:P.remote,children:[P.remote," (",f("git.pushDialog.newBranch"),")"]}),w.map(H=>t.jsx("option",{value:H,children:H},H)),t.jsx("option",{value:vy,children:f("git.pushDialog.customRemote")})]})}),t.jsx("td",{className:"py-2 px-3",children:t.jsx("input",{type:"checkbox",checked:P.setUpstream,onChange:H=>O(P.local,{setUpstream:H.target.checked}),disabled:c,className:"cursor-pointer"})})]},P.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:P=>{P&&(P.indeterminate=!N&&D)},onChange:F,disabled:c||x.length===0,className:"cursor-pointer"}),f("git.pushDialog.selectAll")]}),t.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[t.jsx("input",{type:"checkbox",checked:E,onChange:P=>R(P.target.checked),disabled:c,className:"cursor-pointer"}),f("git.pushDialog.allTags")]}),t.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[t.jsx("input",{type:"checkbox",checked:j,onChange:P=>T(P.target.checked),disabled:c,className:"cursor-pointer"}),t.jsx("span",{title:f("git.pushDialog.forceHint"),children:f("git.pushDialog.force")})]})]}),m&&t.jsx("div",{className:"text-xs text-status-error font-medium",children:m}),t.jsxs("div",{className:"flex items-center justify-end gap-2 pt-1",children:[t.jsx("button",{type:"button",onClick:s,disabled:c,className:"btn-secondary btn-md",children:f("git.pushDialog.cancel")}),t.jsx("button",{type:"button",onClick:$,disabled:c||p||A===0,className:"btn-primary btn-md",children:f(c?"git.pushDialog.pushing":"git.pushDialog.submit")})]})]})})}function _8(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 Xu({files:e,loading:s,selectedFile:i,onFileClick:a,commitHash:u}){const{t:f}=ft();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(p=>{const o=_8(p.status),c=i===p.path;return t.jsxs("div",{onClick:()=>a(p.path),className:`flex items-center gap-2 px-3 py-1.5 cursor-pointer text-xs hover:bg-warm-50/50 transition-colors ${c?"bg-accent/10 border-l-2 border-accent":""}`,children:[t.jsx("span",{className:`font-mono font-bold text-2xs w-3 shrink-0 ${o.color}`,children:o.label}),t.jsxs("span",{className:"truncate flex-1 text-warm-600",title:p.path,children:[p.path.split("/").pop(),t.jsx("span",{className:"text-warm-400 ml-1 text-2xs",children:p.path.includes("/")?p.path.substring(0,p.path.lastIndexOf("/")):""})]}),t.jsxs("span",{className:"shrink-0 text-2xs text-status-success",children:["+",p.additions]}),t.jsxs("span",{className:"shrink-0 text-2xs text-status-error",children:["-",p.deletions]})]},p.path)})})]})}function eo({diff:e,loading:s,selectedFile:i,fileHeaders:a}){const{t:u}=ft(),[f,p]=S.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:()=>p(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(mN,{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,c=0,h=!1;return e.split(`
|
|
661
661
|
`).map((m,d)=>{if(a&&m.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:m.slice(7)},d);if(m.startsWith("@@")){const k=/@@ -(\d+)(?:,\d+)? \+(\d+)(?:,\d+)? @@/.exec(m);return k&&(o=parseInt(k[1],10),c=parseInt(k[2],10),h=!0),null}if(!h)return null;let g="text-gray-200",b=null,C=null;if(m.startsWith("+")&&!m.startsWith("+++"))g="text-gray-100 bg-green-500/20",C=c++;else if(m.startsWith("-")&&!m.startsWith("---"))g="text-gray-100 bg-red-500/20",b=o++;else if(m.startsWith(" "))b=o++,C=c++;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:b??""}),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:m||" "})]},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 S8(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 p=s[f];if(p.startsWith("<<<<<<<")){u();const o=p.slice(7).trim()||"HEAD";f++;const c=[];for(;f<s.length&&!s[f].startsWith("|||||||")&&!s[f].startsWith("=======");)c.push(s[f]),f++;if(f<s.length&&s[f].startsWith("|||||||"))for(f++;f<s.length&&!s[f].startsWith("=======");)f++;f<s.length&&s[f].startsWith("=======")&&f++;const 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:c,theirs:h,label:o})}else a.push(p),f++}return u(),i}function k8(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 C8=/^(<{7}|>{7})/m;function Bf({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 j8({projectId:e,worktreePath:s,filePath:i,onResolved:a,onError:u}){const{t:f}=ft(),[p,o]=S.useState(null),[c,h]=S.useState({}),[m,d]=S.useState(!1),[g,b]=S.useState(""),[C,k]=S.useState(!0),[x,_]=S.useState(!1),[w,y]=S.useState(!1);S.useEffect(()=>{let $=!1;return k(!0),d(!1),h({}),y(!1),WN(e,i,s).then(P=>{$||o(S8(P.content))}).catch(()=>{$||y(!0)}).finally(()=>{$||k(!1)}),()=>{$=!0}},[e,s,i]);const E=S.useMemo(()=>p?p.map(($,P)=>$.kind==="conflict"?P:-1).filter($=>$>=0):[],[p]),R=E.filter($=>c[$]).length,j=E.length-R,T=S.useMemo(()=>p?k8(p,c):"",[p,c]),N=m?g:T,D=C8.test(N),A=x||D||!m&&j>0,B=($,P)=>h(H=>({...H,[$]:P})),O=()=>{b(T),d(!0)},F=async()=>{_(!0),u(null);try{await qN(e,i,N,s),a()}catch($){u($ instanceof Error?$.message:"Failed to save resolution")}finally{_(!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&&!w&&t.jsxs(t.Fragment,{children:[t.jsx("span",{className:`text-2xs ${j>0?"text-amber-400":"text-emerald-400"}`,children:j>0?f("git.cr.unresolved").replace("{n}",String(j)):f("git.cr.allResolved")}),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:()=>m?d(!1):O(),children:f(m?"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:A,onClick:F,title:D?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")}):w?t.jsx("div",{className:"flex-1 flex items-center justify-center text-xs text-status-error",children:f("git.cr.loadFailed")}):m?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:$=>b($.target.value),spellCheck:!1}):E.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:p.map(($,P)=>$.kind==="text"?t.jsx(Bf,{lines:$.lines,tint:"text-gray-500"},P):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(H=>t.jsx("button",{onClick:()=>B(P,H),className:`text-2xs px-2 py-0.5 rounded-md border transition-colors ${c[P]===H?"bg-accent text-white border-accent":"border-gray-600 text-gray-300 hover:bg-gray-700"}`,children:f(H==="ours"?"git.acceptOurs":H==="theirs"?"git.acceptTheirs":"git.cr.both")},H))}),t.jsxs("div",{className:c[P]==="theirs"?"opacity-40":"",children:[t.jsx("div",{className:"px-3 pt-1 text-2xs text-emerald-400",children:f("git.cr.ours")}),t.jsx(Bf,{lines:$.ours,tint:"text-gray-100 bg-emerald-500/10"})]}),t.jsxs("div",{className:c[P]==="ours"?"opacity-40":"",children:[t.jsx("div",{className:"px-3 pt-1 text-2xs text-sky-400",children:f("git.cr.theirs")}),t.jsx(Bf,{lines:$.theirs,tint:"text-gray-100 bg-sky-500/10"})]})]},P))})]})}const za=["#B08A3E","#4B8DFF","#7A8797","#5E748A","#8B8178","#667085","#78909C","#9A8F7F"];function E8(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 p=i.indexOf(f.hash);p===-1&&(p=i.indexOf(null),p===-1&&(p=i.length,i.push(null))),i[p]=null;const o=za[p%za.length],c=[];for(let h=0;h<f.parentHashes.length;h++){const m=f.parentHashes[h],d=s.get(m);if(d===void 0)continue;let g=i.indexOf(m);if(g!==-1)c.push({fromLane:p,toLane:g,toRow:d,color:za[g%za.length]});else if(h===0)i[p]=m,c.push({fromLane:p,toLane:p,toRow:d,color:o});else{let b=i.indexOf(null);b===-1&&(b=i.length,i.push(null)),i[b]=m,c.push({fromLane:p,toLane:b,toRow:d,color:za[b%za.length]})}}a.push({lane:p,color:o,connections:c})}return a}function N8({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 di=32,Bi=16,L8=4,D8=10;function T8({graphNodes:e,totalRows:s}){const a=(Math.min(D8,e.reduce((u,f)=>{const p=f.connections.reduce((o,c)=>Math.max(o,c.fromLane,c.toLane),0);return Math.max(u,f.lane,p)},0)+1)+1)*Bi+8;return t.jsxs("svg",{width:a,height:s*di,className:"shrink-0",style:{minWidth:a},children:[e.map((u,f)=>u.connections.map((p,o)=>{const c=p.fromLane*Bi+Bi/2+4,h=f*di+di/2,m=p.toLane*Bi+Bi/2+4,d=p.toRow*di+di/2;if(c===m)return t.jsx("line",{x1:c,y1:h,x2:m,y2:d,stroke:p.color,strokeWidth:2,strokeOpacity:.7},`${f}-${o}`);{const g=(h+d)/2;return t.jsx("path",{d:`M${c},${h} C${c},${g} ${m},${g} ${m},${d}`,fill:"none",stroke:p.color,strokeWidth:2,strokeOpacity:.7},`${f}-${o}`)}})),e.map((u,f)=>{const p=u.lane*Bi+Bi/2+4,o=f*di+di/2;return t.jsx("circle",{cx:p,cy:o,r:L8,fill:u.color,stroke:"white",strokeWidth:1.5},`dot-${f}`)})]})}function R8({projectId:e,projectName:s,onRefresh:i,busy:a,setBusy:u,branches:f,statusFiles:p,worktreePath:o}){const{t:c}=ft(),{confirm:h}=qn(),[m,d]=S.useState(null),[g,b]=S.useState(""),[C,k]=S.useState(""),[x,_]=S.useState(null),w=()=>{d(null),b(""),k(""),_(null)},y=async O=>{u(!0),_(null);try{await O(),w(),i()}catch(F){_(F instanceof Error?F.message:"Error")}finally{u(!1)}},E=p.some(O=>O.index!==" "&&O.index!=="?"),R=({label:O,onClick:F,icon:$,badge:P})=>t.jsxs("button",{onClick:F,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:$}),t.jsx("span",{className:"text-2xs text-warm-600 whitespace-nowrap",children:O}),P!==void 0&&P>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:P})]}),j=({title:O,children:F})=>t.jsx(jn,{open:!0,onClose:w,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:w,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}),F]})]})}),T=f.filter(O=>!O.remote),N=f.find(O=>!O.remote&&O.current),D=p.length,A=(N==null?void 0:N.behind)??0,B=(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:c("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:D}),t.jsx(R,{label:c("git.pull"),onClick:()=>y(()=>i1(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:A}),t.jsx(R,{label:c("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:B}),t.jsx(R,{label:c("git.fetch"),onClick:()=>y(()=>a1(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:c("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:c("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:c("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:c("git.discard"),onClick:async()=>{p.length!==0&&await h({message:c("git.confirmDiscard"),danger:!0})&&y(()=>JN(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:c("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(w8,{open:m==="push",onClose:w,projectId:e,projectName:s,onPushed:i}),m==="commit"&&t.jsxs(j,{title:c("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:c("git.commitMessage"),value:g,onChange:O=>b(O.target.value),autoFocus:!0}),t.jsxs("button",{className:"w-full btn-primary text-sm py-2",disabled:a||!g.trim()||!E,onClick:()=>y(()=>r1(e,g.trim(),o)),children:[c("git.commit")," ",!E&&t.jsxs("span",{className:"text-xs opacity-70 ml-1",children:["(",c("git.staged"),": 0)"]})]})]}),m==="branch"&&t.jsxs(j,{title:c("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:c("git.branchName"),value:g,onChange:O=>b(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:()=>y(()=>o1(e,g.trim())),children:c("git.create")})}),T.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:c("git.selectBranch")}),t.jsx("div",{className:"max-h-32 overflow-y-auto space-y-px",children:T.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:()=>y(()=>pm(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:c("git.confirmDelete").replace("{name}",O.name),danger:!0})&&y(()=>mm(e,O.name))},children:c("git.delete")})]},O.name))})]})]}),m==="merge"&&t.jsxs(j,{title:c("git.merge"),children:[t.jsx("p",{className:"text-xs text-warm-500",children:c("git.selectBranch")}),t.jsx("div",{className:"max-h-48 overflow-y-auto space-y-px",children:T.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:()=>y(()=>l1(e,O.name)),children:O.name},O.name))})]}),m==="stash"&&t.jsx(M8,{projectId:e,busy:a,exec:y,inputValue:g,setInputValue:b}),m==="tag"&&t.jsxs(j,{title:c("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:c("git.tagName"),value:g,onChange:O=>b(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:c("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:()=>y(()=>c1(e,g.trim(),C.trim()||void 0)),children:c("git.create")})]})]})}function M8({projectId:e,busy:s,exec:i,inputValue:a,setInputValue:u}){const{t:f}=ft(),[p,o]=S.useState([]);return S.useEffect(()=>{XN(e).then(o).catch(()=>{})},[e]),t.jsx(jn,{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:c=>u(c.target.value),autoFocus:!0}),t.jsx("button",{className:"btn-primary text-sm px-3 py-2",disabled:s,onClick:()=>i(()=>VN(e,a.trim()||void 0)),children:f("git.stash")})]}),p.length>0?t.jsx("div",{className:"space-y-px max-h-40 overflow-y-auto",children:p.map(c=>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:c.message||`stash@{${c.index}}`}),t.jsx("button",{className:"text-accent hover:underline text-[11px] ml-2 shrink-0",disabled:s,onClick:()=>i(()=>YN(e,c.index)),children:f("git.stashPop")})]},c.index))}):t.jsx("p",{className:"text-xs text-warm-400 text-center",children:f("git.noStashes")})]})]})})}function by(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",p=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",p="M"),{label:p,color:f,type:a?"staged":"unstaged"}}function yy({file:e,pane:s,selected:i,checked:a,onClick:u,onToggleCheck:f}){const p=s==="staged"?by(e.index," "):by(" ",e.working_dir==="?"?"?":e.working_dir),o=s==="unstaged"&&e.index==="?"&&e.working_dir==="?"?{label:"U",color:"text-warm-400"}:p;return t.jsxs("div",{onClick:u,className:`flex items-center gap-2 px-3 py-1 cursor-pointer text-xs select-none transition-colors ${i?"bg-accent/15 text-accent":"hover:bg-warm-50 text-warm-700"}`,children:[t.jsx("input",{type:"checkbox",checked:a,onChange:f,onClick:c=>c.stopPropagation(),className:"h-3 w-3 shrink-0 cursor-pointer","aria-label":e.path}),t.jsx("span",{className:`shrink-0 w-4 h-4 flex items-center justify-center rounded-md text-[10px] font-mono font-bold ${s==="staged"?"bg-status-success/15":"bg-warm-200"} ${o.color}`,children:s==="staged"||o.label==="U"?"+":"−"}),t.jsx("span",{className:"truncate flex-1",title:e.path,children:e.path})]})}function A8({diff:e,loading:s,file:i}){const{t:a}=ft();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(`
|
|
@@ -676,7 +676,7 @@ WARNING: This link could potentially be dangerous`)){const _=window.open();if(_)
|
|
|
676
676
|
`)&&Y(ne),le.current=!0,Z(!0)},Re=S.useRef(De);Re.current=De;const ve=()=>{var ne,_e;le.current=!1,Z(!1),(ne=q.current)==null||ne.clearDecorations(),de({index:-1,count:0});try{(_e=T.current)==null||_e.focus()}catch{}},Me=S.useRef(ve);Me.current=ve;const Oe=S.useRef(0),tt=(ne,_e,X)=>{const me=++Oe.current,re=Date.now();V({dataUrl:ne,bytes:_e});const ae=()=>{const J=Math.max(0,600-(Date.now()-re));setTimeout(()=>{Oe.current===me&&V(null)},J)};X.then(ae,ae)},nt=S.useRef(tt);nt.current=tt;const{warning:ke}=Ls(),fe=S.useRef(ke);fe.current=ke;const[Te,Ce]=S.useState(null),Ge=S.useRef(()=>{});S.useEffect(()=>{if(!Te)return;const ne=()=>Ce(null),_e=X=>{X.key==="Escape"&&ne()};return window.addEventListener("keydown",_e,!0),window.addEventListener("resize",ne),window.addEventListener("scroll",ne,!0),()=>{window.removeEventListener("keydown",_e,!0),window.removeEventListener("resize",ne),window.removeEventListener("scroll",ne,!0)}},[Te]),S.useEffect(()=>{var ze;const ne=j.current;if(!ne)return;const _e=ue=>{const Fe=ue.type;_.current&&Fe==="session:terminal-input"||u(ue)},X=new xz.Terminal({fontFamily:Ot,fontSize:c,lineHeight:1,cursorBlink:s,convertEol:!1,scrollback:5e3,theme:x.current??Jc,minimumContrastRatio:zy(x.current??Jc),allowProposedApi:!0,macOptionIsMeta:!0}),me=/Mac|iPhone|iPad|iPod/.test(navigator.platform);let re=0;const ae=async()=>{var Fe;if(_.current){console.debug("[paste] inputBlocked → ignored");return}if(!window.isSecureContext)return;if(re=Date.now(),!w.current)try{const Ve=await navigator.clipboard.read();for(const ht of Ve){const Ne=ht.types.find(at=>at.startsWith("image/"));if(Ne){const at=await ht.getType(Ne),bt=new FileReader;bt.onload=()=>{const Ct=bt.result;console.debug("[paste] image via clipboard.read(), bytes=",at.size);const qt=R1(e,Ct);qt.catch(an=>console.warn("[paste] pasteImage failed:",an)),nt.current(Ct,at.size,qt)},bt.readAsDataURL(at);return}}}catch(Ve){console.debug("[paste] clipboard.read() rejected, falling through:",Ve)}let ue=null;try{ue=await navigator.clipboard.readText()}catch(Ve){console.warn("[paste] clipboard.readText() failed:",Ve)}if(ue){const Ve=ue.includes(`
|
|
677
677
|
`);console.debug("[paste] sending text, len=",ue.length,"multiline=",Ve),_e({type:"session:terminal-input",sessionId:e,input:rS(ue)});return}try{const Ve=await F4(e);if(Ve.path){console.debug("[paste] empty browser clipboard, using OS file path:",Ve.path),_e({type:"session:terminal-input",sessionId:e,input:Ve.path});return}}catch(Ve){console.debug("[paste] getClipboardImagePath failed:",Ve)}console.warn("[paste] no content available (text empty, no image, no file path)"),(Fe=fe.current)==null||Fe.call(fe,"붙여넣을 내용을 클립보드에서 읽지 못했습니다. 우클릭 → 붙여넣기를 사용하세요.")};X.attachCustomKeyEventHandler(ue=>{var bt;if(ue.type!=="keydown")return!0;const Fe=me?ue.metaKey:ue.ctrlKey,Ve=me?ue.ctrlKey:ue.metaKey,ht=Fe&&!Ve&&!ue.altKey&&!ue.shiftKey,Ne=Fe&&!Ve&&!ue.altKey&&ue.shiftKey,at=ue.key.toLowerCase();if(at==="tab"&&(ht||Ne)&&y.current)return ue.preventDefault(),y.current(Ne?"prev":"next"),!1;if(at==="f"&&ht)return ue.preventDefault(),Re.current(),!1;if(at==="t"&&ht||at==="r"&&Ne||at==="f5"&&!ue.ctrlKey&&!ue.metaKey&&!ue.altKey&&!ue.shiftKey)return ue.preventDefault(),!1;if(at==="d"&&Ne&&E.current)return ue.preventDefault(),E.current(),!1;if(Ne&&["a","p","o","m","x"].includes(at))return ue.preventDefault(),!1;if(ht&&at==="c"){const Ct=X.getSelection();return Ct?(ue.preventDefault(),(bt=navigator.clipboard)==null||bt.writeText(Ct).catch(()=>{}),X.clearSelection(),!1):!me}if(ht&&at==="v"||ue.altKey&&!ue.ctrlKey&&!ue.metaKey&&!ue.shiftKey&&at==="v")return ue.preventDefault(),ae(),!1;if((ue.ctrlKey||ue.metaKey)&&!ue.altKey){if(ue.key==="+"||ue.key==="=")return ue.preventDefault(),Ko(e,1),!1;if(ue.key==="-"||ue.key==="_")return ue.preventDefault(),Ko(e,-1),!1}return!0});const J=new bz.FitAddon;X.loadAddon(J),X.open(ne),T.current=X,N.current=J;try{const ue=new Ty.CanvasAddon;X.loadAddon(ue),D.current=ue}catch{D.current=null}const se=new _z.SearchAddon;X.loadAddon(se),q.current=se;const pe=se.onDidChangeResults(({resultIndex:ue,resultCount:Fe})=>{ye.current({index:ue,count:Fe})}),we=()=>{le.current&&Me.current()};ne.addEventListener("focusin",we),X.attachCustomWheelEventHandler(ue=>!ue.ctrlKey&&!ue.metaKey?!0:(ue.preventDefault(),ue.__zoomHandled=!0,ue.deltaY!==0&&Ko(e,ue.deltaY<0?1:-1),!1));const je=ue=>{if(ue.ctrlKey||ue.metaKey){if(ue.preventDefault(),ue.stopPropagation(),ue.deltaY===0||ue.__zoomHandled)return;Ko(e,ue.deltaY<0?1:-1);return}ue.stopPropagation()};ne.addEventListener("wheel",je,{passive:!1});const $e=window.electronAPI,Je=(ze=$e==null?void 0:$e.onTerminalZoom)==null?void 0:ze.call($e,ue=>{var Ne;const Fe=ne.matches(":hover"),Ve=document.querySelector("[data-term-container]:hover")!==null,ht=!!X.textarea&&document.activeElement===X.textarea;(Ne=$e.imeLog)==null||Ne.call($e,{reason:"zoom:recv",dir:ue,hovered:Fe,anyTermHovered:Ve,focused:ht,path:window.location.pathname}),(Fe||!Ve&&ht)&&Ko(e,ue==="in"?1:-1)});Ge.current=()=>{ae()};const qe=ue=>{ue.preventDefault(),Ce({x:ue.clientX,y:ue.clientY,hasSelection:X.hasSelection()})};ne.addEventListener("contextmenu",qe);try{J.fit()}catch{}if(d){const ue=document.activeElement;if(!(!!ue&&(ue.tagName==="INPUT"||ue.tagName==="TEXTAREA"||ue.tagName==="SELECT"||ue.isContentEditable))&&(ue===null||ue===document.body))try{X.focus()}catch{}}const Ee=()=>{const ue=X.cols,Fe=X.rows;ue===A.current.cols&&Fe===A.current.rows||(A.current={cols:ue,rows:Fe},u({type:"session:resize",sessionId:e,cols:ue,rows:Fe}))};P.current=Ee;const st=f(e,ue=>{try{X.write(ue)}catch{}}),lt=p(ue=>{ue.type==="session:replay-end"&&ue.sessionId===e&&W(!1)}),yt=()=>Date.now()-re<300,mt=()=>w.current,pt=ue=>z.current(ue),dt=(ue,Fe,Ve)=>nt.current(ue,Fe,Ve),kt=Ez()?Az({container:ne,term:X,sessionId:e,sendMessage:_e}):Mz({container:ne,term:X,sessionId:e,sendMessage:_e,isPasteAlreadyHandled:yt,isImagePasteDisabled:mt,onComposingChange:pt,onImagePasted:dt}),gt=100;let vt=null,Tt=0,Xe=!1;const ut={cols:X.cols,rows:X.rows},Q=new ResizeObserver(()=>{if(vt!==null)return;const ue=Math.max(0,gt-(performance.now()-Tt));vt=setTimeout(()=>{vt=null,requestAnimationFrame(()=>{var Ve;Tt=performance.now();const Fe=ne.getBoundingClientRect();if(!(Fe.width===0||Fe.height===0)){try{J.fit(),(X.cols!==ut.cols||X.rows!==ut.rows)&&(ut.cols=X.cols,ut.rows=X.rows,X.refresh(0,X.rows-1))}catch{}!Xe&&X.cols>=20&&X.rows>=5&&(Xe=!0,(Ve=$.current)==null||Ve.call($,X.cols,X.rows)),B.current&&clearTimeout(B.current),B.current=setTimeout(Ee,150)}})},ue)});return Q.observe(ne),()=>{var ue;Q.disconnect(),vt!==null&&clearTimeout(vt),B.current&&clearTimeout(B.current),O.current&&clearTimeout(O.current),ne.removeEventListener("wheel",je),Je==null||Je(),ne.removeEventListener("contextmenu",qe),Ce(null),kt(),st(),lt();try{u({type:"session:unsubscribe",sessionId:e})}catch{}ne.removeEventListener("focusin",we),pe.dispose(),q.current=null,(ue=D.current)==null||ue.dispose(),D.current=null,X.dispose(),T.current=null,N.current=null,P.current=null,F.current=!1}},[e]),S.useEffect(()=>{if(!i||F.current)return;F.current=!0;const ne=T.current;ne&&ne.cols>0&&ne.rows>0&&(A.current={cols:0,rows:0},u({type:"session:resize",sessionId:e,cols:ne.cols,rows:ne.rows})),u({type:"session:subscribe",sessionId:e})},[i,e,u]),S.useEffect(()=>{T.current&&(T.current.options.cursorBlink=s)},[s]),S.useEffect(()=>{var me;if(!d)return;const ne=document.activeElement;if(!(!(!!ne&&ne.classList.contains("xterm-helper-textarea"))&&!!ne&&(ne.tagName==="INPUT"||ne.tagName==="TEXTAREA"||ne.tagName==="SELECT"||ne.isContentEditable)))try{(me=T.current)==null||me.focus()}catch{}},[d]),S.useEffect(()=>{const ne=T.current,_e=N.current;if(!ne||!_e||ne.options.fontSize===c)return;if(ne.options.fontSize=c,D.current){try{D.current.dispose()}catch{}D.current=null;try{const me=new Ty.CanvasAddon;ne.loadAddon(me),D.current=me}catch{}}if(ne.buffer.active.type==="alternate"){O.current&&clearTimeout(O.current),O.current=setTimeout(()=>{var me;(me=R.current)==null||me.call(R)},500);return}try{_e.fit(),ne.refresh(0,ne.rows-1)}catch{}ne.cols===A.current.cols&&ne.rows===A.current.rows||(O.current&&clearTimeout(O.current),O.current=setTimeout(()=>{var me;(me=P.current)==null||me.call(P)},300))},[c,e]),S.useEffect(()=>{const ne=T.current;if(ne){ne.options.theme=h??Jc,ne.options.minimumContrastRatio=zy(h??Jc);try{ne.refresh(0,ne.rows-1)}catch{}}},[h]),S.useEffect(()=>{if(!ee)return;const ne=q.current;if(!ne)return;const _e=setTimeout(()=>{te?ne.findNext(te,{...Vf,incremental:!0}):(ne.clearDecorations(),de({index:-1,count:0}))},120);return()=>clearTimeout(_e)},[te,ee]),S.useEffect(()=>{var ne;ee&&((ne=oe.current)==null||ne.select())},[ee]);const Ze=(h==null?void 0:h.background)??Ue.bg,be=()=>{var ne;te&&((ne=q.current)==null||ne.findNext(te,Vf))},Be=()=>{var ne;te&&((ne=q.current)==null||ne.findPrevious(te,Vf))};return t.jsxs("div",{style:{position:"relative",background:Ze,padding:12,height:o,width:"100%",boxSizing:"border-box",overflow:"hidden"},children:[H&&i&&t.jsx("div",{style:{position:"absolute",top:8,right:12,fontFamily:Ot,fontSize:11,color:Ue.dim,zIndex:1,pointerEvents:"none"},children:"loading history…"}),t.jsx("div",{ref:j,"data-term-container":!0,style:{height:"100%",width:"100%"}}),ee&&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 ${Ue.separator}`,borderRadius:6,fontFamily:Ot,fontSize:12,boxShadow:"0 4px 16px rgba(0,0,0,0.5)"},children:[t.jsx("input",{ref:oe,value:te,onChange:ne=>Y(ne.target.value),onKeyDown:ne=>{ne.key==="Enter"?(ne.preventDefault(),ne.shiftKey?Be():be()):ne.key==="Escape"&&(ne.preventDefault(),ve())},placeholder:"검색",spellCheck:!1,style:{width:160,background:"transparent",border:"none",outline:"none",color:Ue.bright,fontFamily:Ot,fontSize:12}}),t.jsx("span",{style:{color:Ue.dim,minWidth:44,textAlign:"right",fontVariantNumeric:"tabular-nums"},children:te?he.count>0?`${he.index+1}/${he.count}`:"0/0":""}),[{label:"↑",title:"이전 (Shift+Enter)",onClick:Be},{label:"↓",title:"다음 (Enter)",onClick:be},{label:"×",title:"닫기 (Esc)",onClick:ve}].map(ne=>t.jsx("button",{type:"button",title:ne.title,onClick:ne.onClick,className:"px-1.5 rounded-md hover:bg-white/10",style:{color:Ue.bright,lineHeight:"18px"},children:ne.label},ne.label))]}),(G||U)&&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:[U&&t.jsxs("div",{style:{padding:4,background:"rgba(0,0,0,0.72)",border:`1px solid ${Ue.separator}`,borderRadius:4,maxWidth:"100%"},children:[t.jsx("img",{src:U.dataUrl,alt:"",style:{display:"block",maxWidth:220,maxHeight:140,borderRadius:2}}),t.jsxs("div",{style:{fontFamily:Ot,fontSize:11,color:Ue.dim,marginTop:3},children:["이미지 붙여넣음 · ",Cz(U.bytes)]})]}),G&&t.jsx("div",{style:{maxWidth:"100%",padding:"3px 8px",background:"rgba(0,0,0,0.72)",border:`1px solid ${Ue.separator}`,borderRadius:4,fontFamily:Ot,fontSize:Math.max(12,c),color:Ue.bright,lineHeight:1.3,whiteSpace:"pre",overflow:"hidden",textOverflow:"ellipsis"},children:G})]}),Te&&rn.createPortal((()=>{const X=Math.max(8,Math.min(Te.x,window.innerWidth-184-8)),me=Math.max(8,Math.min(Te.y,window.innerHeight-116-8)),re=()=>Ce(null),ae=()=>{var we,je;const pe=((we=T.current)==null?void 0:we.getSelection())??"";pe&&((je=navigator.clipboard)==null||je.writeText(pe).catch(()=>{})),re()},J=()=>{Ge.current(),re()},se=()=>{var pe;(pe=T.current)==null||pe.selectAll(),re()};return t.jsxs(t.Fragment,{children:[t.jsx("div",{style:{position:"fixed",inset:0,zIndex:2147483646},onMouseDown:re,onContextMenu:pe=>{pe.preventDefault(),re()}}),t.jsxs("div",{role:"menu",style:{position:"fixed",left:X,top:me,zIndex:2147483647,minWidth:168,background:Ue.bg,border:`1px solid ${Ue.separator}`,borderRadius:6,padding:4,fontFamily:Ot,fontSize:13,boxShadow:"0 8px 24px rgba(0,0,0,0.5)"},children:[t.jsx("button",{type:"button",disabled:!Te.hasSelection,onClick:ae,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:Ue.bright},children:"복사"}),t.jsx("button",{type:"button",onClick:J,className:"w-full text-left px-3 py-1.5 rounded-md hover:bg-white/10",style:{color:Ue.bright},children:"붙여넣기"}),t.jsx("button",{type:"button",onClick:se,className:"w-full text-left px-3 py-1.5 rounded-md hover:bg-white/10",style:{color:Ue.bright},children:"전체 선택"})]})]})})(),document.body)]})}function Ez(){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 fu=[12593,12594,12596,12599,12600,12601,12609,12610,12611,12613,12614,12615,12616,12617,12618,12619,12620,12621,12622],iS=[12623,12624,12625,12626,12627,12628,12629,12630,12631,12632,12633,12634,12635,12636,12637,12638,12639,12640,12641,12642,12643],Oy=[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 aS(e){return e>=12593&&e<=12622}function oS(e){return e>=12623&&e<=12643}function Nz(e){return aS(e)||oS(e)}function Lz(e){return e>=44032&&e<=55203}function Dz(){return{cho:-1,jung:-1,jong:0}}function zp(e){return e.cho<0&&e.jung<0&&e.jong===0}function Er(e){return zp(e)?"":e.cho>=0&&e.jung>=0?String.fromCharCode(44032+(e.cho*21+e.jung)*28+e.jong):e.cho>=0?String.fromCharCode(fu[e.cho]):e.jung>=0?String.fromCharCode(iS[e.jung]):""}function By(e){const s=Er(e);return e.cho=-1,e.jung=-1,e.jong=0,s}function Tz(e,s){if(oS(s)){const i=iS.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 p=Er(e);return e.jung=i,p}if(e.jong===0){const p=Er(e);return e.cho=-1,e.jung=i,e.jong=0,p}const a=Oy[e.jong],u=fu.indexOf(a);e.jong=0;const f=Er(e);return u>=0?(e.cho=u,e.jung=i,e.jong=0):(e.cho=-1,e.jung=i,e.jong=0),f}if(aS(s)){const i=fu.indexOf(s),a=Oy.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(fu[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=Er(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=Er(e);return e.cho=i>=0?i:-1,e.jung=-1,e.jong=0,f}const u=Er(e);return e.cho=i>=0?i:-1,e.jung=-1,e.jong=0,i<0?u+String.fromCharCode(s):u}return""}function Rz(e,s){const i=Er(e),a=s-44032;return e.cho=Math.floor(a/588),e.jung=Math.floor(a/28)%21,e.jong=a%28,i}function Py(e){return zp(e)?!1:(e.cho=-1,e.jung=-1,e.jong=0,!0)}function Mz({container:e,term:s,sessionId:i,sendMessage:a,isPasteAlreadyHandled:u,isImagePasteDisabled:f,onComposingChange:p,onImagePasted:o}){let c=!1;const h=D=>{try{p==null||p(D)}catch{}};let m=null;const d=(D,A={})=>{var B,O;try{(O=(B=window.electronAPI)==null?void 0:B.imeLog)==null||O.call(B,{reason:D,path:window.location.pathname,...A})}catch{}},g=(D=!1)=>{try{const A=e.querySelector(".xterm-helper-textarea"),B=e.querySelector(".xterm-screen");if(!A||!B){D||d("pos:no-dom",{hasHelper:!!A,hasScreen:!!B});return}const O=s.cols,F=s.rows;if(O<=0||F<=0){D||d("pos:no-grid",{cols:O,rows:F});return}const $=B.getBoundingClientRect();if($.width===0||$.height===0){D||d("pos:zero-screen",{w:$.width,h:$.height});return}const P=$.width/O,H=$.height/F,W=s.buffer.active,G=Math.min(W.cursorX,O-1),I=Math.max(0,Math.min(W.cursorY,F-1));A.style.left=`${G*P}px`,A.style.top=`${I*H}px`,A.style.width=`${Math.max(P,1)}px`,A.style.height=`${Math.max(H,1)}px`,D||d("pos:applied",{cursorX:G,cursorY:I,left:G*P,top:I*H})}catch{}};g();let b=0;const C=()=>{b||(b=requestAnimationFrame(()=>{b=0,g(!0)}))},k=s.onCursorMove(C),x=()=>{var D;c=!0,g(),h("");try{const A=document.activeElement,B=e.querySelector(".xterm-helper-textarea"),O=B==null?void 0:B.getBoundingClientRect();d("compositionstart",{activeTag:A==null?void 0:A.tagName,activeClass:A==null?void 0:A.className,activeIsHelper:!!A&&((D=A.classList)==null?void 0:D.contains("xterm-helper-textarea")),helperStyleLeft:B==null?void 0:B.style.left,helperStyleTop:B==null?void 0:B.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{}},_=D=>{h(D.data??""),d("compositionupdate",{data:D.data??""})},w=D=>{c=!1,h("");const A=D.data;d("compositionend",{data:A??"",sent:!!A}),A&&(m=A,a({type:"session:terminal-input",sessionId:i,input:A}))},y=D=>{var O,F;if(u()){D.preventDefault();return}const A=(O=D.clipboardData)==null?void 0:O.items;if(A&&!(f!=null&&f())){for(let $=0;$<A.length;$++)if(A[$].type.startsWith("image/")){D.preventDefault();const P=A[$].getAsFile();if(!P)return;const H=new FileReader;H.onload=()=>{const W=H.result;console.debug("[paste-fallback] image via paste event, bytes=",P.size);const G=R1(i,W,P.name);G.catch(I=>console.warn("[paste-fallback] pasteImage failed:",I)),o==null||o(W,P.size,G)},H.readAsDataURL(P);return}}const B=(F=D.clipboardData)==null?void 0:F.getData("text/plain");if(B){D.preventDefault();const $=B.includes(`
|
|
678
678
|
`);console.debug("[paste-fallback] sending text, len=",B.length,"multiline=",$),a({type:"session:terminal-input",sessionId:i,input:rS(B)})}else console.debug("[paste-fallback] paste event had no usable text/image")},E=D=>{var $,P;const A=($=D.dataTransfer)==null?void 0:$.files;if(!A||A.length===0)return;D.preventDefault();const B=(P=window.electronAPI)==null?void 0:P.getDroppedFilePath;if(!B)return;const O=[];for(let H=0;H<A.length;H++){const W=B(A[H]);W&&O.push(W)}const F=kz(O);F&&a({type:"session:terminal-input",sessionId:i,input:F})},R=D=>{var A,B;(B=(A=D.dataTransfer)==null?void 0:A.types)!=null&&B.includes("Files")&&(D.preventDefault(),D.dataTransfer.dropEffect="copy")},j=()=>{if(c)return;Ap(()=>{try{s.focus()}catch{}})&&d("focus-rescue")},T=D=>{var A,B;d("keydown",{key:D.key,composing:c,activeIsHelper:!!((B=(A=document.activeElement)==null?void 0:A.classList)!=null&&B.contains("xterm-helper-textarea")),hasFocus:document.hasFocus()}),document.hasFocus()||j()};e.addEventListener("keydown",T,!0),e.addEventListener("compositionstart",x,!0),e.addEventListener("compositionupdate",_,!0),e.addEventListener("compositionend",w,!0),e.addEventListener("paste",y,!0),e.addEventListener("dragover",R),e.addEventListener("drop",E);const N=s.onData(D=>{if(!c){if(m!==null&&D===m){m=null;return}m=null,a({type:"session:terminal-input",sessionId:i,input:D})}});return()=>{N.dispose(),k.dispose(),b&&cancelAnimationFrame(b),e.removeEventListener("keydown",T,!0),e.removeEventListener("compositionstart",x,!0),e.removeEventListener("compositionupdate",_,!0),e.removeEventListener("compositionend",w,!0),e.removeEventListener("paste",y,!0),e.removeEventListener("dragover",R),e.removeEventListener("drop",E),h("")}}function Az({container:e,term:s,sessionId:i,sendMessage:a}){const u=e.querySelector(".xterm-helper-textarea");let f="",p=0;u&&(f=u.style.display,p=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:Ot,fontSize:"16px",lineHeight:"1.2",resize:"none",overflow:"hidden",whiteSpace:"pre",caretColor:"rgba(255,255,255,0.001)",zIndex:"5"});const c=()=>{Object.assign(o.style,{inset:"0",left:"auto",top:"auto",width:"100%",height:"100%",color:"transparent"})},h=()=>{const j=e.querySelector(".xterm-screen");if(!j)return;const T=s.cols,N=s.rows;if(T<=0||N<=0)return;const D=j.clientWidth/T,A=j.clientHeight/N,B=s.buffer.active.cursorX,O=s.buffer.active.cursorY,F=j.getBoundingClientRect(),$=e.getBoundingClientRect();Object.assign(o.style,{inset:"auto",left:`${F.left-$.left+B*D}px`,top:`${F.top-$.top+O*A}px`,width:`${Math.max(D*30,240)}px`,height:`${Math.max(A,20)}px`,color:Ue.text})};c(),e.appendChild(o);let m=!1;const d=Dz();let g=null;const b=()=>{g&&(clearTimeout(g),g=null)},C=j=>{j&&a({type:"session:terminal-input",sessionId:i,input:j})},k=()=>{const j=By(d);j&&C(j)},x=()=>{const j=Er(d);o.value=j,j?h():c()},_=()=>{b(),g=setTimeout(()=>{g=null,k(),o.value="",c()},600)},w=()=>{m=!0,b(),k(),h()},y=j=>{m=!1,j.data&&C(j.data),o.value="",c()};o.addEventListener("compositionstart",w),o.addEventListener("compositionend",y);const E=j=>{if(m)return;const T=j;switch(T.inputType){case"insertCompositionText":case"insertFromComposition":return;case"deleteContentBackward":b(),Py(d)?x():(C(""),o.value="",c());return;case"insertLineBreak":case"insertParagraph":b(),k(),C("\r"),o.value="",c();return;default:if(!T.data){x();return}b();let N="";for(const D of T.data){const A=D.codePointAt(0);Nz(A)?N+=Tz(d,A):Lz(A)?N+=Rz(d,A):(N+=By(d),N+=D)}C(N),x(),zp(d)||_()}};o.addEventListener("input",E);const R=j=>{if(m||j.isComposing)return;let T=null;switch(j.key){case"Enter":T="\r";break;case"Backspace":T="";break;case"Tab":T=" ";break;case"Escape":T="\x1B";break;case"ArrowUp":T="\x1B[A";break;case"ArrowDown":T="\x1B[B";break;case"ArrowRight":T="\x1B[C";break;case"ArrowLeft":T="\x1B[D";break;case"Home":T="\x1B[H";break;case"End":T="\x1B[F";break}if(T){if(j.preventDefault(),b(),j.key==="Backspace"){if(Py(d)){x();return}}else k();C(T),o.value="",c();return}if(j.ctrlKey&&!j.metaKey&&!j.altKey&&j.key.length===1){const N=j.key.toUpperCase().charCodeAt(0);N>=64&&N<=95&&(j.preventDefault(),b(),k(),C(String.fromCharCode(N-64)),o.value="",c())}};return o.addEventListener("keydown",R),()=>{b(),k(),o.remove(),u&&(u.style.display=f,u.tabIndex=p)}}function zz({sessionId:e,onClose:s,projectId:i,onEvent:a,sendMessage:u}){const{t:f}=ft(),[p,o]=S.useState([]),[c,h]=S.useState(!0),[m,d]=S.useState(null),[g,b]=S.useState(!1),[C,k]=S.useState(null),[x,_]=S.useState(""),[w,y]=S.useState(!1),[E,R]=S.useState(0),[j,T]=S.useState([]),[N,D]=S.useState(null),[A,B]=S.useState(!1),[O,F]=S.useState({from:null,now:null}),$=S.useRef(new Map),P=S.useCallback(()=>R(G=>G+1),[]);S.useEffect(()=>{if(!(!u||!i))return u({type:"git:watch",projectId:i}),()=>u({type:"git:unwatch",projectId:i})},[u,i]),S.useEffect(()=>{if(!(!a||!i))return a(G=>{G.type==="git:changed"&&G.projectId===i&&P()})},[a,i,P]),S.useEffect(()=>{let G=!1;return T4(e).then(I=>{G||T(I.snapshots??[])}).catch(()=>{G||T([])}),()=>{G=!0}},[e,E]),S.useEffect(()=>{let G=!1;return b(!0),L4(e,N??void 0).then(I=>{if(G)return;h(I.available),d(I.reason??null);const z=I.available&&I.files?I.files.map(U=>({path:U.path,status:U.status,additions:U.insertions,deletions:U.deletions})):[];o(z),$.current.clear(),F({from:N,now:I.now??null}),k(U=>U&&z.some(V=>V.path===U)?U:z.length>0?z[0].path:null)}).catch(()=>{G||(h(!1),d("error"),o([]))}).finally(()=>{G||b(!1)}),()=>{G=!0}},[e,N,E]),S.useEffect(()=>{if(!C){_("");return}const G=`${O.now??""}:${C}`,I=$.current.get(G);if(I!==void 0){_(I),y(!1);return}let z=!1;return y(!0),_(""),D4(e,C,O.from??void 0,O.now??void 0).then(U=>{if(z)return;const V=U.available&&U.diff?U.diff:"";$.current.set(G,V),_(V)}).catch(()=>{z||_("")}).finally(()=>{z||y(!1)}),()=>{z=!0}},[e,C,O]);const H=S.useCallback(()=>{B(!0),R4(e).then(G=>{if(G.available&&G.snapshots){T(G.snapshots);const I=G.snapshots[G.snapshots.length-1];I&&D(I.sha)}}).catch(()=>{}).finally(()=>B(!1))},[e]),W=G=>{const I=new Date(G);return Number.isNaN(I.getTime())?G:I.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:H,disabled:A||!c,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(f5,{size:14,className:A?"animate-pulse":""})}),t.jsx("button",{onClick:P,title:f("common.refresh")||"Refresh",className:"p-1 rounded-md hover:bg-warm-100 text-warm-500",children:t.jsx(ap,{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(Xt,{size:14})})]})]}),j.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(Iy,{active:N===null,onClick:()=>D(null),label:f("session.diff.pageStart")||"From start"}),j.map(G=>t.jsx(Iy,{active:N===G.sha,onClick:()=>D(G.sha),label:`#${G.seq} ${W(G.at)}`},G.sha))]}),c?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(Xu,{files:p,loading:g,selectedFile:C,onFileClick:k})}),t.jsx("div",{className:"flex-1 min-w-0",children:t.jsx(eo,{diff:x,loading:w,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:m==="not-git"?f("session.diff.notGit")||"Not a git repository":f("session.diff.unavailable")||"Diff unavailable"})})]})}function Iy({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 Oz={presetId:sS},xl=new Map,Fa=new Map;function lS(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);xl.delete(s);const i=Fa.get(s);if(i){const u=Im(s);i.forEach(f=>f(u))}});function Bz(e){return typeof e!="string"?!1:e==="custom"||e in On}function Im(e){const s=xl.get(e);if(s!==void 0)return s;let i=Oz;try{const a=localStorage.getItem(lS(e));if(a!==null){const u=JSON.parse(a);u&&Bz(u.presetId)&&(i={presetId:u.presetId,custom:u.custom&&typeof u.custom=="object"?u.custom:void 0})}}catch{}return xl.set(e,i),i}function Pz(e,s){const i=xl.get(e);if(i&&i.presetId===s.presetId&&Iz(i.custom,s.custom))return;xl.set(e,s);try{localStorage.setItem(lS(e),JSON.stringify(s))}catch{}const a=Fa.get(e);a&&a.forEach(u=>u(s))}function Iz(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 Fz(e){if(e.presetId!=="custom")return Ay(e.presetId).theme;const s=Ay(sS).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 cS(e){const[s,i]=S.useState(()=>Im(e));S.useEffect(()=>{i(Im(e));let f=Fa.get(e);return f||(f=new Set,Fa.set(e,f)),f.add(i),()=>{const p=Fa.get(e);p&&(p.delete(i),p.size===0&&Fa.delete(e))}},[e]);const a=S.useCallback(f=>Pz(e,f),[e]),u=S.useMemo(()=>Fz(s),[s]);return[s,u,a]}function uS({session:e,visible:s,intent:i,intentNonce:a,onClose:u,sendMessage:f,subscribeBinary:p,onEvent:o,onCycleTab:c,remountKey:h=0}){const{t:m}=ft(),d=e.status==="running"||i==="start"||i==="resume"?"pendingFit":"replay-only",[g,b]=S.useState(d),[C,k]=S.useState(null),[x,_]=S.useState(!1),[w,y]=S.useState(480),E=!!e.is_git_repo,R=S.useRef(null),j=S.useCallback(ve=>{ve.preventDefault();const Me=R.current;if(!Me)return;const Oe=nt=>{const ke=Me.getBoundingClientRect(),fe=240,Te=Math.max(fe,ke.width-200);y(Math.min(Te,Math.max(fe,ke.right-nt.clientX)))},tt=()=>{window.removeEventListener("mousemove",Oe),window.removeEventListener("mouseup",tt),document.body.style.cursor="",document.body.style.userSelect=""};window.addEventListener("mousemove",Oe),window.addEventListener("mouseup",tt),document.body.style.cursor="col-resize",document.body.style.userSelect="none"},[]),[T,N]=S.useState(0),D=S.useCallback(()=>N(ve=>ve+1),[]),A=S.useRef(null),B=S.useRef(!1),O=S.useRef(a),[F,$]=S.useState(null),[P,H]=S.useState(null),[W,G]=S.useState(!1),[I,z]=S.useState(null),[U,V]=S.useState(null),q=S.useRef(e.status==="running");S.useEffect(()=>{e.status==="running"&&g!=="subscribed"&&g!=="starting"&&g!=="pendingFit"&&(q.current=!0,b("subscribed"))},[e.status,g]),S.useEffect(()=>{if(e.status==="running"||!q.current||g!=="subscribed"&&g!=="stopping")return;const ve=setTimeout(()=>u(),300);return()=>clearTimeout(ve)},[e.status,g,u]);const oe=S.useCallback(async()=>{const ve=A.current;if(ve&&!B.current){B.current=!0,b("starting"),k(null),V(null);try{const Me=await z4(e.id,ve,i==="resume"?{continueSession:!0}:void 0);b("subscribed"),Me.pendingInitialPrompt?($(Me.pendingInitialPromptLength??0),H(null),G(!1)):($(null),H(null))}catch(Me){const Oe=Me instanceof Error?Me.message:String(Me);k(Oe),b("error")}finally{B.current=!1}}},[e.id,i]),ee=S.useCallback(async()=>{if(W){G(!1);return}if(G(!0),P===null)try{const ve=await O4(e.id);H(ve.prompt??"")}catch(ve){V(ve instanceof Error?ve.message:String(ve))}},[W,P,e.id]),Z=S.useCallback(async()=>{if(!I){z("send"),V(null);try{await B4(e.id),$(null),H(null),G(!1)}catch(ve){V(ve instanceof Error?ve.message:String(ve))}finally{z(null)}}},[I,e.id]),te=S.useCallback(async()=>{if(!I){z("skip"),V(null);try{await P4(e.id),$(null),H(null),G(!1)}catch(ve){V(ve instanceof Error?ve.message:String(ve))}finally{z(null)}}},[I,e.id]);S.useEffect(()=>{if(a===O.current)return;O.current=a,(i==="start"||i==="resume")&&g==="replay-only"&&e.status!=="running"&&(A.current?oe():b("pendingFit"))},[a,i,g,e.status,oe]);const Y=S.useCallback(()=>{A.current?oe():b("pendingFit")},[oe]),he=S.useCallback((ve,Me)=>{A.current={cols:ve,rows:Me},g==="pendingFit"&&(e.status==="running"?(q.current=!0,b("subscribed")):oe())},[g,oe,e.status]),de=e.status==="running",ye=g==="subscribed",[le]=y1(e.id),[,De]=cS(e.id),Re=g==="starting"||g==="pendingFit"?t.jsxs("div",{style:{...Qc,pointerEvents:"none"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[t.jsx(hi,{size:14,style:{animation:"spin 1s linear infinite",color:Ue.dim}}),t.jsx("span",{style:{color:Ue.dim,fontFamily:Ot,fontSize:12},children:m("session.starting")||"starting…"})]}),t.jsx("span",{style:{color:Ue.dim,fontFamily:Ot,fontSize:10,marginTop:6},children:m("session.starting.typeAhead")||"type-ahead is captured and replayed once ready"})]}):g==="stopping"?t.jsx("div",{style:{...Qc,pointerEvents:"none"},children:t.jsx("span",{style:{color:Ue.dim,fontFamily:Ot,fontSize:12},children:m("session.stopping")||"stopping…"})}):g==="replay-only"?t.jsx("div",{style:Qc,children:t.jsxs("button",{onClick:Y,style:{display:"flex",alignItems:"center",gap:8,fontFamily:Ot,fontSize:14,color:Ue.bright,background:"transparent",border:`1px solid ${Ue.separator}`,padding:"10px 22px",borderRadius:6,cursor:"pointer"},children:[t.jsx(Tr,{size:16})," ",m("session.startInWindow")||"Start"]})}):g==="error"?t.jsxs("div",{style:Qc,children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,color:Ue.error,fontFamily:Ot,fontSize:12,marginBottom:8},children:[t.jsx(qw,{size:14})," ",m("session.startFailed")||"failed to start"]}),C&&t.jsx("div",{style:{color:Ue.dim,fontFamily:Ot,fontSize:11,marginBottom:8,maxWidth:360,textAlign:"center",wordBreak:"break-word"},children:C}),t.jsx("button",{onClick:()=>{oe()},style:{fontFamily:Ot,fontSize:12,color:Ue.bright,background:"transparent",border:`1px solid ${Ue.separator}`,padding:"4px 12px",borderRadius:4,cursor:"pointer"},children:m("common.retry")||"Retry"})]}):null;return t.jsxs("div",{ref:R,style:{display:s?"flex":"none",flexDirection:"row",position:"absolute",inset:0,background:Ue.bg},children:[t.jsxs("div",{style:{position:"relative",flex:1,minWidth:0,height:"100%"},children:[t.jsx(jz,{sessionId:e.id,isRunning:de,subscribed:ye,onFitted:he,sendMessage:f,subscribeBinary:p,onEvent:o,fontSize:le,theme:De,inputBlocked:F!==null,autoFocusOnMount:s,onRequestRefresh:D,disableImagePaste:e.cli_tool==="raw-shell",onCycleTab:c,onToggleDiff:()=>{E&&_(ve=>!ve)}},`${h}:${T}`),Re,E&&!x&&t.jsxs("button",{onClick:()=>_(!0),title:`${m("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:Ot,fontSize:10,color:Ue.dim,background:"rgba(20,20,28,0.7)",border:`1px solid ${Ue.separator}`,padding:"2px 8px",borderRadius:4,cursor:"pointer"},children:[t.jsx(oE,{size:12})," Diff"]}),F!==null&&t.jsxs("div",{style:Hz,children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[t.jsx(T5,{"aria-hidden":!0,size:14,style:{color:Ue.info}}),t.jsxs("span",{style:{flex:1},children:[m("session.initialPrompt.ready")||"Initial prompt ready",t.jsxs("span",{style:{color:Ue.dim,marginLeft:8},children:[F.toLocaleString()," chars"]}),t.jsx("div",{style:{color:Ue.warning,fontSize:10,marginTop:2},children:m("session.initialPrompt.blocked")||"Press Send or Skip before typing — keystrokes are ignored until then."})]}),t.jsxs("button",{onClick:ee,style:Yf("neutral"),title:W?m("session.initialPrompt.hidePreview")||"Hide preview":m("session.initialPrompt.preview")||"Preview",children:[W?t.jsx(Ww,{size:12}):t.jsx(Ja,{size:12}),W?m("session.initialPrompt.hidePreview")||"Hide":m("session.initialPrompt.preview")||"Preview"]}),t.jsxs("button",{onClick:Z,disabled:I!==null,style:Yf("primary"),children:[I==="send"?t.jsx(hi,{size:12,style:{animation:"spin 1s linear infinite"}}):t.jsx(aN,{size:12}),m("session.initialPrompt.send")||"Send"]}),t.jsx("button",{onClick:te,disabled:I!==null,style:Yf("danger"),children:m("session.initialPrompt.skip")||"Skip"})]}),U&&t.jsx("div",{style:{color:Ue.error,fontSize:10,marginTop:4},children:U}),W&&t.jsx("pre",{style:{margin:0,marginTop:6,maxHeight:240,overflow:"auto",background:"rgba(0,0,0,0.4)",padding:8,fontFamily:Ot,fontSize:10,color:Ue.bright,whiteSpace:"pre-wrap",wordBreak:"break-word",border:`1px solid ${Ue.separator}`,borderRadius:4},children:P===null?m("session.initialPrompt.loading")||"loading…":P})]})]}),E&&x&&t.jsxs(t.Fragment,{children:[t.jsx("div",{onMouseDown:j,style:{width:5,flexShrink:0,cursor:"col-resize",background:Ue.separator}}),t.jsx("div",{style:{width:w,flexShrink:0,minWidth:0,height:"100%"},children:t.jsx(zz,{sessionId:e.id,projectId:e.project_id,onEvent:o,sendMessage:f,onClose:()=>_(!1)})})]})]})}const Hz={position:"absolute",top:0,left:0,right:0,background:"rgba(28,28,38,0.96)",borderBottom:`1px solid ${Ue.separator}`,borderLeft:`3px solid ${Ue.warning}`,padding:"8px 10px",color:Ue.bright,fontFamily:Ot,fontSize:11,zIndex:3,display:"flex",flexDirection:"column"};function Yf(e){const s={display:"inline-flex",alignItems:"center",gap:4,fontFamily:Ot,fontSize:10,padding:"3px 8px",borderRadius:4,cursor:"pointer",border:`1px solid ${Ue.separator}`,background:"transparent"};return e==="primary"?{...s,color:Ue.bright,borderColor:Ue.info,background:`${Ue.info}22`}:e==="danger"?{...s,color:Ue.dim}:{...s,color:Ue.bright}}const Qc={position:"absolute",inset:0,background:"rgba(12,12,12,0.85)",display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",zIndex:1e3},Fy=340;function $z({sessionId:e}){var C,k,x,_,w,y;const[s,,i]=cS(e),[a,u]=S.useState(!1),[f,p]=S.useState(!1),[o,c]=S.useState({top:0,left:0}),h=S.useRef(null),m=S.useRef(null),d=S.useCallback(()=>{if(!h.current)return;const E=h.current.getBoundingClientRect(),R=window.innerWidth,j=window.innerHeight,T=m.current;let N=E.bottom+4,D=E.right-Fy;if(T){const A=T.offsetHeight,B=T.offsetWidth;D=E.right-B,D<8&&(D=8),D+B>R-8&&(D=R-8-B),N+A>j-8&&(N=Math.max(8,E.top-A-4))}else D<8&&(D=8);c({top:N,left:D}),p(!0)},[]);S.useEffect(()=>{if(!a){p(!1);return}d();const E=requestAnimationFrame(d),R=T=>{var D,A;const N=T.target;(D=h.current)!=null&&D.contains(N)||(A=m.current)!=null&&A.contains(N)||u(!1)},j=T=>{T.key==="Escape"&&u(!1)};return document.addEventListener("mousedown",R),document.addEventListener("keydown",j),window.addEventListener("scroll",d,!0),window.addEventListener("resize",d),()=>{cancelAnimationFrame(E),document.removeEventListener("mousedown",R),document.removeEventListener("keydown",j),window.removeEventListener("scroll",d,!0),window.removeEventListener("resize",d)}},[a,d]);const g=E=>{if(E==="custom"){const R=s.custom??{background:On.default.theme.background,foreground:On.default.theme.foreground,cursor:On.default.theme.cursor,selectionBackground:On.default.theme.selectionBackground,accent:On.default.theme.brightBlue};i({presetId:"custom",custom:R})}else i({presetId:E,custom:s.custom}),u(!1)},b=E=>{const R={...s.custom??{},...E};i({presetId:"custom",custom:R})};return t.jsxs(t.Fragment,{children:[t.jsx("button",{ref:h,"data-no-drag":!0,onMouseDown:E=>E.stopPropagation(),onClick:()=>u(E=>!E),"aria-label":"terminal-theme",title:"Terminal theme (Ctrl+Shift+P)",style:{background:"transparent",border:"none",color:Ue.titleText,cursor:"pointer",padding:"0 6px",display:"flex",alignItems:"center",justifyContent:"center",borderRadius:0,flexShrink:0,height:"100%"},children:t.jsx($E,{size:14})}),a&&rn.createPortal(t.jsxs("div",{ref:m,className:"z-tooltip",style:{position:"fixed",top:o.top,left:o.left,width:Fy,background:"#1e1e1e",border:`1px solid ${Ue.separator}`,borderRadius:6,padding:10,fontFamily:Ot,color:Ue.text,boxShadow:"0 8px 24px rgba(0,0,0,0.5)",opacity:f?1:0,transition:"opacity 80ms"},onMouseDown:E=>E.stopPropagation(),children:[t.jsx("div",{style:{fontSize:10,color:Ue.dim,marginBottom:6,letterSpacing:.5},children:"DARK"}),t.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(3, 1fr)",gap:6,marginBottom:10},children:My.filter(E=>!On[E].light).map(E=>t.jsx(Hy,{preset:On[E],selected:s.presetId===E,onClick:()=>g(E)},E))}),t.jsx("div",{style:{fontSize:10,color:Ue.dim,marginBottom:6,letterSpacing:.5},children:"LIGHT"}),t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(3, 1fr)",gap:6,marginBottom:10},children:[My.filter(E=>On[E].light).map(E=>t.jsx(Hy,{preset:On[E],selected:s.presetId===E,onClick:()=>g(E)},E)),t.jsx(Uz,{selected:s.presetId==="custom",accent:((C=s.custom)==null?void 0:C.accent)??On.default.theme.brightBlue??"#569cd6",onClick:()=>g("custom")})]}),s.presetId==="custom"&&t.jsxs("div",{style:{borderTop:`1px solid ${Ue.separator}`,paddingTop:8},children:[t.jsx("div",{style:{fontSize:10,color:Ue.dim,marginBottom:6,letterSpacing:.5},children:"CUSTOM COLORS"}),t.jsx(Jo,{label:"Background",value:((k=s.custom)==null?void 0:k.background)??On.default.theme.background??"#0c0c0c",onChange:E=>b({background:E})}),t.jsx(Jo,{label:"Foreground",value:((x=s.custom)==null?void 0:x.foreground)??On.default.theme.foreground??"#cccccc",onChange:E=>b({foreground:E})}),t.jsx(Jo,{label:"Cursor",value:((_=s.custom)==null?void 0:_.cursor)??On.default.theme.cursor??"#f2f2f2",onChange:E=>b({cursor:E})}),t.jsx(Jo,{label:"Selection",value:((w=s.custom)==null?void 0:w.selectionBackground)??On.default.theme.selectionBackground??"#264f78",onChange:E=>b({selectionBackground:E})}),t.jsx(Jo,{label:"Accent",value:((y=s.custom)==null?void 0:y.accent)??On.default.theme.brightBlue??"#569cd6",onChange:E=>b({accent:E})})]})]}),document.body)]})}function Hy({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:Ue.separator}`,outline:s?`1px solid ${e.accent}`:"none",outlineOffset:-2,borderRadius:4,padding:"6px 8px",cursor:"pointer",fontFamily:Ot,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(rr,{size:12,style:{marginLeft:"auto",flexShrink:0}})]}),t.jsxs("div",{style:{fontSize:9,opacity:.85,fontFamily:Ot},children:[t.jsx("span",{style:{color:e.theme.green},children:"$"})," ",t.jsx("span",{style:{color:e.theme.brightBlue},children:"ls"})]})]})}function Uz({selected:e,accent:s,onClick:i}){return t.jsxs("button",{onClick:i,style:{position:"relative",background:"#0c0c0c",border:`1px dashed ${e?s:Ue.separator}`,outline:e?`1px solid ${s}`:"none",outlineOffset:-2,borderRadius:4,padding:"6px 8px",cursor:"pointer",fontFamily:Ot,fontSize:10,color:Ue.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(rr,{size:12,style:{marginLeft:"auto",flexShrink:0}})]}),t.jsx("div",{style:{fontSize:9,opacity:.7},children:"edit colors"})]})}function Jo({label:e,value:s,onChange:i}){const[a,u]=S.useState(s);S.useEffect(()=>{u(s)},[s]);const f=p=>{u(p);const o=p.startsWith("#")?p:`#${p}`;(/^#[0-9a-fA-F]{6}$/.test(o)||/^#[0-9a-fA-F]{3}$/.test(o))&&i($y(o))};return t.jsxs("label",{style:{display:"flex",alignItems:"center",gap:8,padding:"4px 0",fontSize:11,color:Ue.text},children:[t.jsx("span",{style:{flex:1},children:e}),t.jsx("input",{type:"text",value:a,onChange:p=>f(p.target.value),onBlur:()=>u(s),spellCheck:!1,style:{width:64,padding:"2px 4px",fontSize:10,fontFamily:Ot,color:Ue.text,background:"transparent",border:`1px solid ${Ue.separator}`,borderRadius:3}}),t.jsx("input",{type:"color",value:$y(s),onChange:p=>i(p.target.value),style:{width:28,height:22,padding:0,border:`1px solid ${Ue.separator}`,borderRadius:3,background:"transparent",cursor:"pointer"}})]})}function $y(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 Uy=360;function Wz({sessionId:e,sendMessage:s}){const[i,a]=S.useState(!1),[u,f]=S.useState(!1),[p,o]=S.useState({top:0,left:0}),[c,h]=S.useState(null),[m,d]=S.useState(""),[g,b]=S.useState(!1),[C,k]=S.useState(""),[x,_]=S.useState(""),[w,y]=S.useState(!1),[E,R]=S.useState(null),j=S.useRef(null),T=S.useRef(null),N=S.useRef(null),D=S.useCallback(()=>{if(!j.current)return;const P=j.current.getBoundingClientRect(),H=window.innerWidth,W=window.innerHeight,G=T.current;let I=P.bottom+4,z=P.right-Uy;if(G){const U=G.offsetHeight,V=G.offsetWidth;z=P.right-V,z<8&&(z=8),z+V>H-8&&(z=H-8-V),I+U>W-8&&(I=Math.max(8,P.top-U-4))}else z<8&&(z=8);o({top:I,left:z}),f(!0)},[]);S.useEffect(()=>{if(!i)return;let P=!1;return v1().then(H=>{P||h(H)}).catch(H=>{P||R(H instanceof Error?H.message:"Failed to load")}),()=>{P=!0}},[i]),S.useEffect(()=>{if(!i){f(!1);return}D();const P=requestAnimationFrame(D),H=requestAnimationFrame(()=>{requestAnimationFrame(()=>{var I;return(I=N.current)==null?void 0:I.focus()})}),W=I=>{var U,V;const z=I.target;(U=j.current)!=null&&U.contains(z)||(V=T.current)!=null&&V.contains(z)||a(!1)},G=I=>{I.key==="Escape"&&a(!1)};return document.addEventListener("mousedown",W),document.addEventListener("keydown",G),window.addEventListener("scroll",D,!0),window.addEventListener("resize",D),()=>{cancelAnimationFrame(P),cancelAnimationFrame(H),document.removeEventListener("mousedown",W),document.removeEventListener("keydown",G),window.removeEventListener("scroll",D,!0),window.removeEventListener("resize",D)}},[i,D]),S.useEffect(()=>{i||(d(""),b(!1),k(""),_(""),R(null))},[i]);const A=S.useMemo(()=>{if(!c)return[];const P=m.trim().toLowerCase();return P?c.filter(H=>H.name.toLowerCase().includes(P)||H.command_template.toLowerCase().includes(P)):c},[c,m]),B=P=>{s({type:"session:terminal-input",sessionId:e,input:P.command_template}),a(!1)},O=P=>{P.key==="Enter"&&A.length>0&&(P.preventDefault(),B(A[0]))},F=!!C.trim()&&!!x.trim()&&!w,$=async()=>{if(F){y(!0),R(null);try{const P=await b1({name:C.trim(),command_template:x.trim()});h(H=>H?[P,...H]:[P]),k(""),_(""),b(!1)}catch(P){R(P instanceof Error?P.message:"Failed")}finally{y(!1)}}};return t.jsxs(t.Fragment,{children:[t.jsx("button",{ref:j,"data-no-drag":!0,onMouseDown:P=>P.stopPropagation(),onClick:()=>a(P=>!P),"aria-label":"alias-inserter",title:"Insert saved command (alias) (Ctrl+Shift+A)",style:qz,children:t.jsx(P5,{size:14})}),i&&rn.createPortal(t.jsxs("div",{ref:T,className:"z-tooltip",style:{position:"fixed",top:p.top,left:p.left,width:Uy,background:"#1e1e1e",border:`1px solid ${Ue.separator}`,borderRadius:6,padding:10,fontFamily:Ot,color:Ue.text,boxShadow:"0 8px 24px rgba(0,0,0,0.5)",opacity:u?1:0,transition:"opacity 80ms"},onMouseDown:P=>P.stopPropagation(),children:[t.jsx("input",{ref:N,type:"text",value:m,onChange:P=>d(P.target.value),onKeyDown:O,placeholder:"Filter aliases… (Enter inserts first match)",style:{width:"100%",boxSizing:"border-box",background:"#0c0c0c",border:`1px solid ${Ue.separator}`,borderRadius:4,color:Ue.bright,fontFamily:Ot,fontSize:11,padding:"6px 8px",outline:"none"}}),t.jsx("div",{style:{marginTop:8,maxHeight:280,overflowY:"auto"},children:c===null?t.jsx("div",{style:Wy,children:"Loading…"}):A.length===0?t.jsx("div",{style:Wy,children:c.length===0?"No aliases yet — add one below.":"No matches."}):A.map(P=>t.jsxs("button",{onClick:()=>B(P),style:Kz,onMouseEnter:H=>H.currentTarget.style.background="rgba(255,255,255,0.06)",onMouseLeave:H=>H.currentTarget.style.background="transparent",title:`Insert: ${P.command_template}`,children:[t.jsx("span",{style:{fontSize:11,color:Ue.bright,fontWeight:600},children:P.name}),t.jsx("code",{style:{fontSize:10,color:Ue.dim,marginLeft:8,flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:P.command_template})]},P.id))}),t.jsx("div",{style:{borderTop:`1px solid ${Ue.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:P=>k(P.target.value),placeholder:"Name (e.g. git status)",maxLength:64,style:qy}),t.jsx("input",{type:"text",value:x,onChange:P=>_(P.target.value),onKeyDown:P=>{P.key==="Enter"&&(P.preventDefault(),$())},placeholder:"Command (e.g. git status -sb)",maxLength:1024,style:{...qy,fontFamily:Ot}}),E&&t.jsx("div",{style:{fontSize:10,color:"#f87171"},children:E}),t.jsxs("div",{style:{display:"flex",justifyContent:"flex-end",gap:6},children:[t.jsxs("button",{type:"button",onClick:()=>{b(!1),R(null)},style:dS,children:[t.jsx(Xt,{size:12})," Cancel"]}),t.jsx("button",{type:"button",onClick:$,disabled:!F,style:{...Gz,opacity:F?1:.5},children:"Save"})]})]}):t.jsxs("button",{type:"button",onClick:()=>{b(!0),R(null)},style:Vz,children:[t.jsx(yn,{size:12})," New alias"]})})]}),document.body)]})}const qz={background:"transparent",border:"none",color:Ue.titleText,cursor:"pointer",padding:"0 6px",display:"flex",alignItems:"center",justifyContent:"center",borderRadius:0,flexShrink:0,height:"100%"},Wy={fontSize:11,color:Ue.dim,padding:"12px 4px",textAlign:"center"},Kz={display:"flex",alignItems:"center",width:"100%",background:"transparent",border:"none",padding:"6px 8px",cursor:"pointer",textAlign:"left",borderRadius:3,transition:"background 80ms"},qy={width:"100%",boxSizing:"border-box",background:"#0c0c0c",border:`1px solid ${Ue.separator}`,borderRadius:4,color:Ue.bright,fontSize:11,padding:"5px 7px",outline:"none"},dS={display:"inline-flex",alignItems:"center",gap:3,background:"transparent",border:`1px solid ${Ue.separator}`,color:Ue.dim,fontFamily:Ot,fontSize:10,padding:"3px 8px",borderRadius:4,cursor:"pointer"},Gz={...dS,background:"rgba(86,156,214,0.13)",border:"1px solid #569cd6",color:Ue.bright},Vz={display:"inline-flex",alignItems:"center",gap:4,background:"transparent",border:"none",color:Ue.dim,fontFamily:Ot,fontSize:11,padding:"4px 0",cursor:"pointer"},Yz=26;function Op({stack:e,path:s,groupId:i,sessionsById:a,colors:u,intents:f,onTabClick:p,onTabClose:o,onTabMouseDown:c,onPaneAutoClose:h,registerRect:m,sendMessage:d,subscribeBinary:g,onEvent:b,focusedSessionId:C,groupTopmost:k,onFocusStack:x,groupActions:_}){const{t:w}=ft(),[y,,E]=y1(e.activeTab),[R,j]=S.useState({}),T=()=>{const H=e.activeTab;H&&j(W=>({...W,[H]:(W[H]||0)+1}))},N=pO(),D=k===void 0?!0:k&&(!C||C===e.activeTab),A=k===!0&&!D,B=a.get(e.activeTab),O=[[B==null?void 0:B.cli_tool,B==null?void 0:B.cli_model].filter(Boolean).join("/"),B==null?void 0:B.branch_name,B==null?void 0:B.status,B!=null&&B.total_tokens?`${B.total_tokens.toLocaleString()} tok`:""].filter(Boolean).join(" · "),F=H=>{H.button===0&&e.activeTab&&(x?x(e.activeTab):N==null||N.focus(e.activeTab)),H.stopPropagation()},$=e.tabs.length>1?H=>{const W=e.tabs.indexOf(e.activeTab);if(W<0)return;const G=e.tabs.length,I=H==="next"?(W+1)%G:(W-1+G)%G;p(e.tabs[I])}:void 0,P=H=>{var oe;const W=/Mac|iPhone|iPad|iPod/.test(navigator.platform),G=W?H.metaKey:H.ctrlKey,I=W?H.ctrlKey:H.metaKey,z=G&&!I&&!H.altKey&&H.shiftKey,U=H.key.toLowerCase();if(H.key==="F5"&&!H.ctrlKey&&!H.metaKey&&!H.altKey&&!H.shiftKey||z&&U==="r"){H.preventDefault(),T();return}if(!z||U!=="a"&&U!=="p")return;H.preventDefault();const q=U==="a"?"alias-inserter":"terminal-theme";(oe=H.currentTarget.querySelector(`[aria-label="${q}"]`))==null||oe.click()};return t.jsxs("div",{onKeyDown:P,style:{flex:1,display:"flex",flexDirection:"column",background:Ue.bg,minWidth:0,minHeight:0,position:"relative",overflow:"hidden",opacity:A?k?.78:.88:1,filter:A?"saturate(0.78)":"none",boxShadow:D?`inset 0 0 0 1px ${Ue.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:H=>{var W;H.target.closest("button")||(W=_==null?void 0:_.onToggleMaximize)==null||W.call(_)},style:{display:"flex",height:Yz,background:D?"#323a42":Ue.titleBg,borderBottom:`1px solid ${Ue.separator}`,flexShrink:0,overflowX:"auto",overflowY:"hidden"},children:[e.tabs.map(H=>{const W=a.get(H),G=H===e.activeTab,I=u[H]||Ue.titleText,z=(W==null?void 0:W.status)==="running"?Ue.success:(W==null?void 0:W.status)==="failed"?Ue.error:(W==null?void 0:W.status)==="completed"?Ue.info:Ue.dim,U=[W==null?void 0:W.status,W==null?void 0:W.cli_tool,W==null?void 0:W.cli_model,W==null?void 0:W.branch_name].filter(Boolean).join(" · ");return t.jsxs("div",{onMouseDown:V=>{if(V.button===0){if(_){p(H);return}V.stopPropagation(),p(H),c(H,s,V)}},style:{display:"flex",alignItems:"center",gap:6,padding:"0 6px 0 10px",fontFamily:Ot,fontSize:11,color:G?Ue.bright:Ue.titleText,background:G?Ue.bg:"transparent",borderRight:`1px solid ${Ue.separator}`,cursor:"pointer",userSelect:"none",whiteSpace:"nowrap",maxWidth:200,position:"relative"},title:`${(W==null?void 0:W.title)||H}${U?`
|
|
679
|
-
${U}`:""}`,children:[t.jsx("span",{"aria-label":(W==null?void 0:W.status)||"unknown",style:{width:6,height:6,borderRadius:"50%",background:z,flexShrink:0}}),t.jsx("span",{"aria-hidden":!0,style:{flexShrink:0,fontFamily:Ot,fontSize:11,fontWeight:700,letterSpacing:-.5,lineHeight:1,color:I,width:16,textAlign:"center"},children:">_"}),t.jsx("span",{style:{overflow:"hidden",textOverflow:"ellipsis",flex:1},children:(W==null?void 0:W.title)||H}),t.jsx("button",{"data-no-drag":!0,onMouseDown:V=>V.stopPropagation(),onClick:V=>{V.stopPropagation(),o(H)},"aria-label":"close-tab",title:w("group.closeTab")||"Close tab",style:{background:"transparent",border:"none",color:Ue.titleText,cursor:"pointer",padding:1,display:"flex",alignItems:"center",justifyContent:"center",borderRadius:3,flexShrink:0},children:t.jsx(Xt,{size:12})})]},H)}),N&&t.jsx("button",{"data-no-drag":!0,onMouseDown:H=>H.stopPropagation(),onClick:()=>{N.createRawShellTab(i,s).catch(()=>{})},"aria-label":"new-tab",title:`${w("group.newTab")||"New shell tab"} (Ctrl+T)`,style:{background:"transparent",border:"none",borderRight:`1px solid ${Ue.separator}`,color:Ue.titleText,cursor:"pointer",padding:"0 8px",display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0,height:"100%"},children:t.jsx(yn,{size:14})}),t.jsx("div",{style:{flex:1,minWidth:8}}),O&&t.jsx("span",{title:O,style:{maxWidth:260,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:Ue.dim,fontFamily:Ot,fontSize:9,padding:"0 7px",flexShrink:1},children:O}),t.jsx(Wz,{sessionId:e.activeTab,sendMessage:d}),t.jsx("button",{"data-no-drag":!0,onMouseDown:H=>H.stopPropagation(),onClick:T,"aria-label":"refresh-terminal",title:`${w("session.refresh")||"Refresh rendering"} (F5 · Ctrl+Shift+R) — ${w("session.refresh.hint")||"Rebuild the terminal view (PTY stays running)"}`,style:Zs,children:t.jsx(sN,{size:12})}),t.jsx("button",{"data-no-drag":!0,onMouseDown:H=>H.stopPropagation(),onClick:()=>E(-1),"aria-label":"decrease-font",title:`${w("session.fontDecrease")||"Decrease font size"} (${y}px) · Ctrl+- · Ctrl+wheel`,style:Zs,children:t.jsx(NN,{size:14})}),t.jsx("button",{"data-no-drag":!0,onMouseDown:H=>H.stopPropagation(),onClick:()=>E(1),"aria-label":"increase-font",title:`${w("session.fontIncrease")||"Increase font size"} (${y}px) · Ctrl+= · Ctrl+wheel`,style:Zs,children:t.jsx(jN,{size:14})}),t.jsx($z,{sessionId:e.activeTab}),_&&t.jsxs(t.Fragment,{children:[e.tabs.length>1&&_.onApplyLayoutPreset&&t.jsxs(t.Fragment,{children:[t.jsx("button",{"data-no-drag":!0,onMouseDown:H=>H.stopPropagation(),onClick:()=>{var H;return(H=_.onApplyLayoutPreset)==null?void 0:H.call(_,"single")},"aria-label":"single-pane",title:w("session.layout.single"),style:Zs,children:t.jsx(Ki,{size:12})}),t.jsx("button",{"data-no-drag":!0,onMouseDown:H=>H.stopPropagation(),onClick:()=>{var H;return(H=_.onApplyLayoutPreset)==null?void 0:H.call(_,"columns")},"aria-label":"two-columns",title:w("session.layout.columns"),style:Zs,children:t.jsx(Xw,{size:14})}),t.jsx("button",{"data-no-drag":!0,onMouseDown:H=>H.stopPropagation(),onClick:()=>{var H;return(H=_.onApplyLayoutPreset)==null?void 0:H.call(_,"grid")},"aria-label":"grid-layout",title:w("session.layout.grid"),style:Zs,children:t.jsx(Qw,{size:14})})]}),_.onToggleMaximize&&t.jsx("button",{"data-no-drag":!0,onMouseDown:H=>H.stopPropagation(),onClick:_.onToggleMaximize,"aria-label":"toggle-maximize",title:`${_.isMaximized?w("session.restoreSize"):w("session.maximize")} · ${w("session.maximizeHint")}`,style:Zs,children:_.isMaximized?t.jsx(Hu,{size:14}):t.jsx(qi,{size:14})}),_.onPopOutGroup&&t.jsx("button",{"data-no-drag":!0,onMouseDown:H=>H.stopPropagation(),onClick:_.onPopOutGroup,"aria-label":"pop-out",title:`${w("session.popOut")||"Pop out to separate window"} (Ctrl+Shift+O)`,style:Zs,children:t.jsx(Dr,{size:14})}),t.jsx("button",{"data-no-drag":!0,onMouseDown:H=>H.stopPropagation(),onClick:_.onMinimizeGroup,"aria-label":"minimize",title:`${w("session.minimize")||"Minimize"} (Ctrl+Shift+M)`,style:Zs,children:t.jsx(rp,{size:14})}),t.jsx("button",{"data-no-drag":!0,onMouseDown:H=>H.stopPropagation(),onClick:_.onCloseGroup,"aria-label":"close",title:`${w("session.close")||"Close"} (Ctrl+Shift+X)`,style:Zs,children:t.jsx(Xt,{size:14})})]})]}),t.jsx("div",{"data-group-id":i,"data-stack-path":s.join("."),ref:H=>{if(!H){m(s,null);return}const W=H.getBoundingClientRect();m(s,{x:W.left,y:W.top,w:W.width,h:W.height})},onMouseDown:F,style:{flex:1,position:"relative",minHeight:0,minWidth:0},children:e.tabs.map(H=>{const W=a.get(H);if(!W)return null;const G=f[H]||{intent:"open",nonce:0};return t.jsx(uS,{session:W,visible:H===e.activeTab,intent:G.intent,intentNonce:G.nonce,onClose:()=>h(H),sendMessage:d,subscribeBinary:g,onEvent:b,onCycleTab:$,remountKey:R[H]||0},H)})})]})}const Zs={background:"transparent",border:"none",color:Ue.titleText,cursor:"pointer",padding:"0 6px",display:"flex",alignItems:"center",justifyContent:"center",borderRadius:0,flexShrink:0,height:"100%"};function Xz({orientation:e,onDragStart:s,onDrag:i,onDragEnd:a}){const u=S.useCallback(p=>{if(p.button!==0)return;p.preventDefault(),p.stopPropagation();const o=p.clientX,c=p.clientY;s();let h=!1;const m=()=>{h||(h=!0,window.removeEventListener("mousemove",C),window.removeEventListener("mouseup",k),window.removeEventListener("blur",d),window.removeEventListener("keydown",g),document.removeEventListener("visibilitychange",b))},d=()=>{m(),a()},g=x=>{x.key==="Escape"&&d()},b=()=>{document.hidden&&d()},C=x=>{const _=e==="horizontal"?x.clientX-o:x.clientY-c;i(_)},k=()=>{m(),a()};window.addEventListener("mousemove",C),window.addEventListener("mouseup",k),window.addEventListener("blur",d),window.addEventListener("keydown",g),document.addEventListener("visibilitychange",b)},[e,s,i,a]),f=e==="horizontal";return t.jsx("div",{onMouseDown:u,style:{flex:"0 0 4px",background:Ue.separator,cursor:f?"col-resize":"row-resize",position:"relative",zIndex:1}})}function Bp(e){const{node:s,path:i,onSplitSizes:a,...u}=e;return s.kind==="stack"?t.jsx(Op,{stack:s,path:i,...u}):t.jsx(Jz,{split:s,path:i,onSplitSizes:a,stackProps:u})}const Ky=80;function Jz({split:e,path:s,onSplitSizes:i,stackProps:a}){const u=e.orientation==="horizontal",f=S.useRef(null),p=S.useRef([]),o=S.useRef(null);return t.jsx("div",{ref:f,style:{display:"flex",flexDirection:u?"row":"column",flex:1,minWidth:0,minHeight:0},children:e.children.map((c,h)=>t.jsxs(S.Fragment,{children:[t.jsx("div",{ref:m=>{p.current[h]=m},style:{flex:`0 0 ${e.sizes[h]}%`,display:"flex",flexDirection:"column",minWidth:0,minHeight:0,overflow:"hidden"},children:t.jsx(Bp,{node:c,path:[...s,h],onSplitSizes:i,...a})}),h<e.children.length-1&&t.jsx(Xz,{orientation:e.orientation,onDragStart:()=>{const m=f.current;if(!m)return;const d=e.sizes.slice();o.current={i:h,initialSizes:d,finalSizes:d.slice(),total:u?m.clientWidth:m.clientHeight}},onDrag:m=>{const d=o.current;if(!d||d.total<=0)return;const g=d.initialSizes[d.i]/100*d.total,b=d.initialSizes[d.i+1]/100*d.total,C=g+b,k=Math.max(Ky,Math.min(C-Ky,g+m)),x=C-k,_=k/d.total*100,w=x/d.total*100,y=p.current[d.i],E=p.current[d.i+1];y&&(y.style.flexBasis=`${_}%`),E&&(E.style.flexBasis=`${w}%`);const R=d.initialSizes.slice();R[d.i]=_,R[d.i+1]=w,d.finalSizes=R},onDragEnd:()=>{const m=o.current;m&&i(s,m.finalSizes),o.current=null}})]},h))})}const Et=28,un=68;function Qu(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,p=u-i.h/2;return Math.abs(f)<=Et&&Math.abs(p)<=Et?"center":f>=-un-Et&&f<=-un+Et&&Math.abs(p)<=Et?"left":f>=un-Et&&f<=un+Et&&Math.abs(p)<=Et?"right":p>=-un-Et&&p<=-un+Et&&Math.abs(f)<=Et?"top":p>=un-Et&&p<=un+Et&&Math.abs(f)<=Et?"bottom":null}function Lu(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||"",p=f===""?[]:f.split(".").map(Number),o=u.getBoundingClientRect(),c={x:o.left,y:o.top,w:o.width,h:o.height};return{groupId:u.dataset.groupId||"",path:p,rect:c,zone:Qu(e,s,c)}}return null}function Qz(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 Fm=un*2+12;function hS(e,s,i,a){const u=e-i/2,f=s-a/2;return Math.abs(u)<=Et&&Math.abs(f)<=Et?"max":u>=-un-Et&&u<=-un+Et&&Math.abs(f)<=Et?"left":u>=un-Et&&u<=un+Et&&Math.abs(f)<=Et?"right":f>=-un-Et&&f<=-un+Et&&Math.abs(u)<=Et?"top":f>=un-Et&&f<=un+Et&&Math.abs(u)<=Et?"bottom":f>=-Fm-Et&&f<=-Fm+Et&&Math.abs(u)<=Et?"popout":null}function fS(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 vl(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 fS(e,u,s,i,a)}function Ha(){const e=document.querySelector("[data-app-sidebar]");return Math.max(0,e?e.getBoundingClientRect().right:0)}function mS({activeZone:e}){const s=window.innerWidth,i=window.innerHeight,a=s/2,u=i/2,f=e&&e!=="popout"?vl(e,s,i,Ha()):null;return rn.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:`${Ue.info}33`,border:`2px dashed ${Ue.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(Fs,{offsetX:a-Et,offsetY:u-Et,active:e==="max",kind:"center"}),t.jsx(Fs,{offsetX:a-un-Et,offsetY:u-Et,active:e==="left",kind:"left"}),t.jsx(Fs,{offsetX:a+un-Et,offsetY:u-Et,active:e==="right",kind:"right"}),t.jsx(Fs,{offsetX:a-Et,offsetY:u-un-Et,active:e==="top",kind:"top"}),t.jsx(Fs,{offsetX:a-Et,offsetY:u+un-Et,active:e==="bottom",kind:"bottom"}),t.jsx(Fs,{offsetX:a-Et,offsetY:u-Fm-Et,active:e==="popout",kind:"popout"})]})]}),document.body)}function bl({targetRect:e,activeZone:s}){const i=e.x+e.w/2,a=e.y+e.h/2,u=s?Qz(e,s):null;return rn.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:`${Ue.info}33`,border:`2px dashed ${Ue.info}`,borderRadius:4,pointerEvents:"none",zIndex:2400,boxSizing:"border-box"}}),(()=>{const f=un+Et;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(Fs,{offsetX:f-Et,offsetY:f-Et,active:s==="center",kind:"center"}),t.jsx(Fs,{offsetX:f-un-Et,offsetY:f-Et,active:s==="left",kind:"left"}),t.jsx(Fs,{offsetX:f+un-Et,offsetY:f-Et,active:s==="right",kind:"right"}),t.jsx(Fs,{offsetX:f-Et,offsetY:f-un-Et,active:s==="top",kind:"top"}),t.jsx(Fs,{offsetX:f-Et,offsetY:f+un-Et,active:s==="bottom",kind:"bottom"})]})})()]}),document.body)}function Fs({offsetX:e,offsetY:s,active:i,kind:a}){const u=Et*2,f=i?Ue.info:"#3a3a3a",p=i?Ue.bright:Ue.separator;return t.jsx("div",{style:{position:"absolute",left:e,top:s,width:u,height:u,background:"#1a1a1a",border:`1px solid ${p}`,borderRadius:4,boxShadow:i?`0 0 8px ${Ue.info}`:"0 1px 3px rgba(0,0,0,0.4)",boxSizing:"border-box",overflow:"hidden"},children:t.jsx(Zz,{kind:a,fill:f})})}function Zz({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(Dr,{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 Nr(e,s){return{kind:"stack",tabs:e.slice(),activeTab:s??e[0]}}function ul(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 Zu(e,s){if(e.kind==="stack")return e.tabs.includes(s)?[]:null;for(let i=0;i<e.children.length;i++){const a=Zu(e.children[i],s);if(a)return[i,...a]}return null}function gn(e){return e.kind==="stack"?e.tabs.slice():e.children.flatMap(gn)}function Du(e){return e.kind==="stack"?[e.activeTab]:e.children.flatMap(Du)}function eO(e,s){const i=gn(e);if(i.length<=1||s==="single")return Nr(i,Du(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(Du(e)),p=u.map(d=>Nr(d,d.find(g=>f.has(g))||d[0]));if(s==="columns"||p.length<=2)return{kind:"split",orientation:"horizontal",children:p,sizes:p.map(()=>100/p.length)};const o=p.slice(0,2),c=p.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(c)],sizes:[50,50]}}function Ui(e,s){return pS(e,s)}function pS(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 p=e.activeTab===s?f[0]:e.activeTab;return{kind:"stack",tabs:f,activeTab:p}}const i=[],a=[];for(let f=0;f<e.children.length;f++){const p=pS(e.children[f],s);p!==null&&(i.push(p),a.push(e.sizes[f]))}if(i.length===0)return null;if(i.length===1)return i[0];const u=a.reduce((f,p)=>f+p,0)||1;return{kind:"split",orientation:e.orientation,children:i,sizes:a.map(f=>f/u*100)}}function Hi(e,s,i){return ed(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 $a(e,s,i,a){const u=i==="left"||i==="right"?"horizontal":"vertical",f=i==="left"||i==="top";return ed(e,s,p=>({kind:"split",orientation:u,children:f?[a,p]:[p,a],sizes:[50,50]}))}function ed(e,s,i){if(s.length===0)return Tu(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((p,o)=>o===a?ed(p,u,i):p);return Tu({...e,children:f})}function Tu(e){if(e.kind==="stack")return e;const s=e.children.map(Tu),i=[],a=[];for(let f=0;f<s.length;f++){const p=s[f],o=e.sizes[f]??100/s.length;if(p.kind==="split"&&p.orientation===e.orientation){const c=p.sizes.reduce((h,m)=>h+m,0)||1;for(let h=0;h<p.children.length;h++)i.push(p.children[h]),a.push(p.sizes[h]/c*o)}else i.push(p),a.push(o)}if(i.length===1)return i[0];const u=a.reduce((f,p)=>f+p,0)||1;return{kind:"split",orientation:e.orientation,children:i,sizes:a.map(f=>f/u*100)}}function Ps(e,s){return e.kind==="stack"?e.tabs.includes(s)?{...e,activeTab:s}:e:{...e,children:e.children.map(i=>Ps(i,s))}}function gS(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=>gS(a,s,i))}}function xS(e,s,i){return ed(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 tO(e,s,i,a){const u=ul(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 p=Ui(e,s);if(!p)return null;const o=Zu(p,f);if(!o)return null;const c=a==="center"?Hi(p,o,s):$a(p,o,a,Nr([s]));return Ps(c,s)}function nO(e,s){const i=gn(e);let a=e;for(const u of i){if(!a)break;s.has(u)||(a=Ui(a,u))}return a}const Zc=320,eu=200,tu=80,nu=22,sO=4,Gy=8,ii=10,su=60,rO=12;function ai(e,s,i){return Math.max(s,Math.min(i,e))}function iO(e,s,i,a){const u=e<=Gy,f=e>=i-Gy;if(!u&&!f)return null;const p=a/3,o=a*2/3;return u?s<p?"top-left":s>o?"bottom-left":"left":s<p?"top-right":s>o?"bottom-right":"right"}function Vy(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 aO(e,s,i,a,u){let f=e,p=s;const o=f,c=f+i,h=p,m=p+a;for(const d of u){const g=d.x,b=d.x+d.w,C=d.y,k=d.y+d.h;h<k&&m>C&&(Math.abs(o-b)<=ii?f=b:Math.abs(c-g)<=ii?f=g-i:Math.abs(o-g)<=ii?f=g:Math.abs(c-b)<=ii&&(f=b-i)),o<b&&c>g&&(Math.abs(h-k)<=ii?p=k:Math.abs(m-C)<=ii?p=C-a:Math.abs(h-C)<=ii?p=C:Math.abs(m-k)<=ii&&(p=k-a))}return{x:f,y:p}}function oO({group:e,sessionsById:s,neighbors:i,isTopmost:a,zIndex:u,sendMessage:f,subscribeBinary:p,onEvent:o}){const{t:c}=ft(),h=K_("(max-width: 767px)"),m=_S(),d=S.useRef(null),[g,b]=S.useState(!1),C=S.useRef(null),[k,x]=S.useState(null),_=S.useRef({x:e.x,y:e.y,w:e.w,h:e.h});_.current={x:e.x,y:e.y,w:e.w,h:e.h};const[w,y]=S.useState(null),E=S.useRef(null),[R,j]=S.useState(!1),[T,N]=S.useState(null),D=S.useRef(null),A=S.useRef(i);A.current=i;const[B,O]=S.useState(null),F=S.useRef(null),$=S.useCallback((le,De)=>{if(h||g||le.button!==0||le.target.closest("[data-no-drag]"))return;le.preventDefault(),m.focus(gn(e.root)[0]||"");const ve=le.clientX,Me=le.clientY,Oe={..._.current},tt=d.current,nt=window.innerWidth,ke=window.innerHeight,fe=Ha();let Te=!1,Ce="";De&&tt&&(Ce=tt.style.pointerEvents,tt.style.pointerEvents="none");let Ge=!1;const Ze=()=>{Ge||(Ge=!0,window.removeEventListener("mousemove",X),window.removeEventListener("mouseup",me),window.removeEventListener("blur",be),window.removeEventListener("keydown",Be),document.removeEventListener("visibilitychange",ne),De&&tt&&(tt.style.pointerEvents=Ce))},be=()=>{Ze(),F.current=null,O(null),E.current=null,y(null),D.current=null,N(null),j(!1),m.setGroupGeometry(e.id,{..._.current})},Be=re=>{re.key==="Escape"&&be()},ne=()=>{document.hidden&&be()};let _e=!1;const X=re=>{if(_e)return;{const qe=window.screenX,Ee=window.screenY,st=qe+window.outerWidth,lt=Ee+window.outerHeight;if(re.screenX<qe-su||re.screenX>st+su||re.screenY<Ee-su||re.screenY>lt+su){_e=!0,Ze(),F.current=null,O(null),E.current=null,y(null),D.current=null,N(null),j(!1),m.setGroupGeometry(e.id,{..._.current}),m.popOutGroup(e.id,{atScreenX:re.screenX,atScreenY:re.screenY});return}}const ae=re.clientX-ve,J=re.clientY-Me;let se=ai(Oe.x+ae,-(Oe.w-tu),nt-tu),pe=ai(Oe.y+J,0,ke-nu);const we=A.current;if(we.length>0){const qe=aO(se,pe,Oe.w,Oe.h,we);se=qe.x,pe=qe.y}if(tt&&(tt.style.left=`${se}px`,tt.style.top=`${pe}px`),_.current.x=se,_.current.y=pe,De){let qe=null;const Ee=document.elementFromPoint(re.clientX,re.clientY),st=Ee==null?void 0:Ee.closest("[data-group-id][data-stack-path]");if(st){const lt=st.dataset.groupId||"";if(lt!==e.id){const yt=st.dataset.stackPath||"",mt=yt===""?[]:yt.split(".").map(Number),pt=st.getBoundingClientRect(),dt={x:pt.left,y:pt.top,w:pt.width,h:pt.height};qe={groupId:lt,path:mt,rect:dt,zone:Qu(re.clientX,re.clientY,dt)}}}F.current=qe,O(qe?{rect:qe.rect,zone:qe.zone}:null)}!Te&&Math.hypot(re.clientX-ve,re.clientY-Me)>=rO&&(Te=!0,j(!0),e.dock&&m.setGroupDock(e.id,null));const je=De&&F.current&&F.current.zone,$e=je||!Te?null:hS(re.clientX,re.clientY,nt,ke);$e!==D.current&&(D.current=$e,N($e));const Je=je||$e?null:iO(re.clientX,re.clientY,nt,ke);Je!==E.current&&(E.current=Je,y(Je))},me=re=>{Ze(),j(!1);const ae=D.current;if(D.current=null,N(null),De&&F.current&&F.current.zone){const se=F.current;m.dockGroup(e.id,se.groupId,se.path,se.zone),F.current=null,O(null),E.current=null,y(null);return}if(ae==="popout"){F.current=null,O(null),E.current=null,y(null),m.setGroupGeometry(e.id,{..._.current}),m.popOutGroup(e.id,{atScreenX:re.screenX,atScreenY:re.screenY});return}if(ae&&ae!=="max"){const se=vl(ae,nt,ke,fe);tt&&(tt.style.left=`${se.x}px`,tt.style.top=`${se.y}px`,tt.style.width=`${se.w}px`,tt.style.height=`${se.h}px`),_.current=se,F.current=null,O(null),E.current=null,y(null),m.setGroupDock(e.id,ae);return}const J=ae?vl(ae,nt,ke,fe):E.current?Vy(E.current,nt,ke):null;J&&(tt&&(tt.style.left=`${J.x}px`,tt.style.top=`${J.y}px`,tt.style.width=`${J.w}px`,tt.style.height=`${J.h}px`),_.current=J,E.current=null,y(null)),F.current=null,O(null),m.setGroupGeometry(e.id,{..._.current})};window.addEventListener("mousemove",X),window.addEventListener("mouseup",me),window.addEventListener("blur",be),window.addEventListener("keydown",Be),document.addEventListener("visibilitychange",ne)},[h,g,m,e.id,e.root,e.dock]),P=S.useCallback(le=>$(le,!1),[$]),H=S.useCallback(le=>$(le,!0),[$]),W=S.useCallback(le=>De=>{if(h||g||De.button!==0)return;De.preventDefault(),De.stopPropagation();const Re=De.clientX,ve=De.clientY,Me={..._.current},Oe=d.current,tt=window.innerWidth,nt=window.innerHeight,ke=Be=>{const ne=Be.clientX-Re,_e=Be.clientY-ve;let X=Me.x,me=Me.y,re=Me.w,ae=Me.h;le.includes("e")?re=ai(Me.w+ne,Zc,Math.max(Zc,tt-Me.x)):le.includes("w")&&(X=ai(Me.x+ne,0,Me.x+Me.w-Zc),re=Me.x+Me.w-X),le.includes("s")?ae=ai(Me.h+_e,eu,Math.max(eu,nt-Me.y)):le.includes("n")&&(me=ai(Me.y+_e,0,Me.y+Me.h-eu),ae=Me.y+Me.h-me),Oe&&(Oe.style.left=`${X}px`,Oe.style.top=`${me}px`,Oe.style.width=`${re}px`,Oe.style.height=`${ae}px`),_.current={x:X,y:me,w:re,h:ae}};let fe=!1;const Te=()=>{fe||(fe=!0,window.removeEventListener("mousemove",ke),window.removeEventListener("mouseup",be),window.removeEventListener("blur",Ce),window.removeEventListener("keydown",Ge),document.removeEventListener("visibilitychange",Ze))},Ce=()=>{Te(),m.setGroupGeometry(e.id,{..._.current})},Ge=Be=>{Be.key==="Escape"&&Ce()},Ze=()=>{document.hidden&&Ce()},be=()=>{Te(),m.setGroupGeometry(e.id,{..._.current})};window.addEventListener("mousemove",ke),window.addEventListener("mouseup",be),window.addEventListener("blur",Ce),window.addEventListener("keydown",Ge),document.addEventListener("visibilitychange",Ze)},[h,g,m,e.id]);S.useEffect(()=>{if(h||e.dock)return;const le=()=>{const De=window.innerWidth,Re=window.innerHeight,ve=_.current,Me=ai(ve.x,-(ve.w-tu),De-tu),Oe=ai(ve.y,0,Re-nu);(Me!==ve.x||Oe!==ve.y)&&m.setGroupGeometry(e.id,{...ve,x:Me,y:Oe})};return window.addEventListener("resize",le),()=>window.removeEventListener("resize",le)},[h,m,e.id,e.dock]);const G=S.useCallback(le=>{x(le),m.setActiveTab(e.id,le),m.focus(le)},[m,e.id]),I=S.useCallback(le=>{x(le),m.focus(le)},[m]),z=S.useCallback(le=>{m.close(le)},[m]),U=S.useCallback((le,De,Re)=>{m.beginTabDrag(e.id,le,De,Re)},[m,e.id]),V=S.useCallback(le=>{m.close(le)},[m]),q=S.useCallback((le,De)=>{m.setSplitSizes(e.id,le,De)},[m,e.id]),oe=Du(e.root),ee=gn(e.root);S.useEffect(()=>{k&&ee.includes(k)||x(oe[0]||ee[0]||null)},[k,oe,ee]);const Z=S.useCallback(()=>{if(g){const le=C.current;le&&m.setGroupGeometry(e.id,le),C.current=null,b(!1);return}C.current={..._.current},e.dock&&m.setGroupDock(e.id,null),m.setGroupGeometry(e.id,{x:6,y:6,w:Math.max(Zc,window.innerWidth-12),h:Math.max(eu,window.innerHeight-12)}),b(!0)},[m,e.id,g,e.dock]),te=le=>{const De=/Mac|iPhone|iPad|iPod/.test(navigator.platform),Re=De?le.metaKey:le.ctrlKey,ve=De?le.ctrlKey:le.metaKey;if(!Re||ve||le.altKey||!le.shiftKey)return;const Me=le.key.toLowerCase();Me==="o"?(le.preventDefault(),m.popOutGroup(e.id)):Me==="m"?(le.preventDefault(),m.minimizeGroup(e.id)):Me==="x"&&(le.preventDefault(),m.closeGroup(e.id))};if(h){const le=oe[0],De=le?s.get(le):null;if(!De)return null;const Re=e.intents[le]??{intent:"open",nonce:0};return rn.createPortal(t.jsxs("div",{style:{position:"fixed",inset:0,background:Ue.bg,display:"flex",flexDirection:"column",zIndex:110},children:[t.jsxs("div",{style:{background:Ue.titleBg,height:nu,display:"flex",alignItems:"center",borderBottom:`1px solid ${Ue.separator}`},children:[t.jsx("span",{style:{flex:1,color:Ue.titleText,fontFamily:Ot,fontSize:12,paddingLeft:8,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:De.title}),t.jsx("button",{"data-no-drag":!0,onClick:()=>m.closeGroup(e.id),style:oi,"aria-label":"close",children:t.jsx(Xt,{size:14})})]}),t.jsx("div",{style:{flex:1,position:"relative",minHeight:0},children:t.jsx(uS,{session:De,visible:!0,intent:Re.intent,intentNonce:Re.nonce,onClose:()=>m.close(le),sendMessage:f,subscribeBinary:p,onEvent:o})})]}),document.body)}const Y=w?(()=>{const le=window.innerWidth,De=window.innerHeight,Re=Vy(w,le,De);return rn.createPortal(t.jsx("div",{style:{position:"fixed",left:Re.x,top:Re.y,width:Re.w,height:Re.h,background:`${Ue.info}33`,border:`2px dashed ${Ue.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,he=(()=>{var De;if(ee.length===0)return"";const le=((De=s.get(ee[0]))==null?void 0:De.title)||ee[0];return ee.length===1?le:`${le} +${ee.length-1}`})(),de=e.root.kind==="split",ye=rn.createPortal(t.jsxs("div",{ref:d,onKeyDown:te,onMouseDown:de?()=>m.focus(ee[0]||""):H,style:{position:"fixed",left:e.x,top:e.y,width:e.w,height:e.h,zIndex:u,background:Ue.bg,border:`1px solid ${a?Ue.info:Ue.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 ${Ue.info}66, 0 0 18px ${Ue.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:[de&&t.jsxs("div",{onMouseDown:P,onDoubleClick:le=>{le.target.closest("button")||Z()},style:{height:nu,flexShrink:0,display:"flex",flexDirection:"column",background:Ue.titleBg,borderBottom:`1px solid ${Ue.separator}`,userSelect:"none",cursor:"move"},children:[t.jsx("div",{style:{display:"flex",height:sO,flexShrink:0},children:oe.map((le,De)=>t.jsx("div",{style:{flex:1,background:e.colors[le]||Ue.titleText}},De))}),t.jsxs("div",{style:{flex:1,display:"flex",alignItems:"center",padding:"0 4px 0 8px",color:Ue.titleText,fontFamily:Ot,fontSize:11},children:[t.jsx("span",{style:{color:Ue.info,fontWeight:600,letterSpacing:1,marginRight:8},"aria-hidden":!0,children:">_"}),t.jsx("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:he}),ee.length>1&&t.jsxs(t.Fragment,{children:[t.jsx("button",{"data-no-drag":!0,onMouseDown:le=>le.stopPropagation(),onClick:()=>m.applyLayoutPreset(e.id,"single"),style:oi,"aria-label":"single-pane",title:c("session.layout.single"),children:t.jsx(Ki,{size:12})}),t.jsx("button",{"data-no-drag":!0,onMouseDown:le=>le.stopPropagation(),onClick:()=>m.applyLayoutPreset(e.id,"columns"),style:oi,"aria-label":"two-columns",title:c("session.layout.columns"),children:t.jsx(Xw,{size:14})}),t.jsx("button",{"data-no-drag":!0,onMouseDown:le=>le.stopPropagation(),onClick:()=>m.applyLayoutPreset(e.id,"grid"),style:oi,"aria-label":"grid-layout",title:c("session.layout.grid"),children:t.jsx(Qw,{size:14})})]}),t.jsx("button",{"data-no-drag":!0,onMouseDown:le=>le.stopPropagation(),onClick:Z,style:oi,"aria-label":"toggle-maximize",title:`${c(g?"session.restoreSize":"session.maximize")} · ${c("session.maximizeHint")}`,children:g?t.jsx(Hu,{size:14}):t.jsx(qi,{size:14})}),t.jsx("button",{"data-no-drag":!0,onMouseDown:le=>le.stopPropagation(),onClick:()=>m.popOutGroup(e.id),style:oi,"aria-label":"pop-out",title:`${c("session.popOut")||"Pop out to separate window"} (Ctrl+Shift+O)`,children:t.jsx(Dr,{size:14})}),t.jsx("button",{"data-no-drag":!0,onClick:()=>m.minimizeGroup(e.id),style:oi,"aria-label":"minimize",title:`${c("session.minimize")||"Minimize"} (Ctrl+Shift+M)`,children:t.jsx(rp,{size:14})}),t.jsx("button",{"data-no-drag":!0,onClick:()=>m.closeGroup(e.id),style:oi,"aria-label":"close",title:`${c("session.close")||"Close"} (Ctrl+Shift+X)`,children:t.jsx(Xt,{size:14})})]})]}),t.jsx("div",{style:{flex:1,display:"flex",minHeight:0,minWidth:0},children:e.root.kind==="split"?t.jsx(Bp,{node:e.root,path:[],groupId:e.id,sessionsById:s,colors:e.colors,intents:e.intents,onTabClick:G,onTabClose:z,onTabMouseDown:U,onPaneAutoClose:V,registerRect:()=>{},onSplitSizes:q,sendMessage:f,subscribeBinary:p,onEvent:o,focusedSessionId:k||void 0,groupTopmost:a,onFocusStack:I}):t.jsx(Op,{stack:e.root,path:[],groupId:e.id,sessionsById:s,colors:e.colors,intents:e.intents,onTabClick:G,onTabClose:z,onTabMouseDown:U,onPaneAutoClose:V,registerRect:()=>{},sendMessage:f,subscribeBinary:p,onEvent:o,focusedSessionId:k||void 0,groupTopmost:a,onFocusStack:I,groupActions:{onMinimizeGroup:()=>m.minimizeGroup(e.id),onCloseGroup:()=>m.closeGroup(e.id),onPopOutGroup:()=>m.popOutGroup(e.id),onToggleMaximize:Z,isMaximized:g,onApplyLayoutPreset:le=>m.applyLayoutPreset(e.id,le)}})}),t.jsx("div",{onMouseDown:W("n"),style:{position:"absolute",top:0,left:6,right:6,height:4,cursor:"ns-resize",zIndex:3}}),t.jsx("div",{onMouseDown:W("s"),style:{position:"absolute",bottom:0,left:6,right:6,height:4,cursor:"ns-resize",zIndex:3}}),t.jsx("div",{onMouseDown:W("w"),style:{position:"absolute",top:6,bottom:6,left:0,width:4,cursor:"ew-resize",zIndex:3}}),t.jsx("div",{onMouseDown:W("e"),style:{position:"absolute",top:6,bottom:6,right:0,width:4,cursor:"ew-resize",zIndex:3}}),t.jsx("div",{onMouseDown:W("nw"),style:{position:"absolute",top:0,left:0,width:10,height:10,cursor:"nwse-resize",zIndex:4}}),t.jsx("div",{onMouseDown:W("ne"),style:{position:"absolute",top:0,right:0,width:10,height:10,cursor:"nesw-resize",zIndex:4}}),t.jsx("div",{onMouseDown:W("sw"),style:{position:"absolute",bottom:0,left:0,width:10,height:10,cursor:"nesw-resize",zIndex:4}}),t.jsx("div",{onMouseDown:W("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:[ye,Y,R&&!(B!=null&&B.zone)&&t.jsx(mS,{activeZone:T}),B&&t.jsx(bl,{targetRect:B.rect,activeZone:B.zone})]})}const oi={background:"transparent",border:"none",color:Ue.titleText,cursor:"pointer",padding:4,display:"flex",alignItems:"center",justifyContent:"center",borderRadius:4},Xf=["#3b82f6","#22c55e","#eab308","#ef4444","#a855f7","#06b6d4","#f97316","#ec4899"];function Fi(e){for(const s of Xf)if(!e.includes(s))return s;return Xf[e.length%Xf.length]}const lO="clitrigger:session-windows:global";function Pp(){if(typeof BroadcastChannel>"u")return{post:()=>{},subscribe:()=>()=>{},close:()=>{}};const e=new BroadcastChannel(lO),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 Bt="main",Hm=new Map;function cO(e,s){Hm.set(e,s)}function uO(e){const s=Hm.get(e);if(!s||s.closed)return Hm.delete(e),!1;try{return s.focus(),!0}catch{return!1}}function dO(){return`popout_${Math.random().toString(36).slice(2,10)}_${Date.now().toString(36)}`}const Ip=5e3,vS=15e3;let Ia=null;function bS(){if(typeof window>"u")return()=>{};const e=s=>{Ia={sx:s.screenX,sy:s.screenY,cx:s.clientX,cy:s.clientY}};return window.addEventListener("mousemove",e,{passive:!0}),()=>window.removeEventListener("mousemove",e)}function Ru(e,s){if(Ia)return{x:Ia.cx+(e-Ia.sx),y:Ia.cy+(s-Ia.sy)};const i=Math.max(0,(window.outerWidth-window.innerWidth)/2),a=Math.max(0,window.outerHeight-window.innerHeight-i);return{x:e-window.screenX-i,y:s-window.screenY-a}}function Mu(e){return e.x>=0&&e.y>=0&&e.x<=window.innerWidth&&e.y<=window.innerHeight}const $m="clitrigger:popout-alive:";function hO(e){return`${$m}${e}`}function Fp(){return typeof navigator<"u"&&!!navigator.locks&&typeof navigator.locks.query=="function"}function fO(e){if(!Fp())return()=>{};let s=()=>{};return navigator.locks.request(hO(e),()=>new Promise(i=>{s=i})).catch(()=>{}),()=>s()}async function yS(){var e;if(!Fp())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($m)&&i.add(a.name.slice($m.length));return i}catch{return new Set}}const Hp=S.createContext(null),wS=S.createContext({});function _S(){const e=S.useContext(Hp);if(!e)throw new Error("useSessionWindows must be used within SessionWindowsHost");return e}function mO(){return S.useContext(wS)}function pO(){return S.useContext(Hp)}const Au=720,$p=460,gO=320,xO=200,Yy=30,SS=80,kS=80,dl=80,Um=28;function vO(e){const s=typeof window<"u"?window.innerWidth:1280,i=typeof window<"u"?window.innerHeight:800;let a=Number.isFinite(e.w)&&e.w>=gO?e.w:Au,u=Number.isFinite(e.h)&&e.h>=xO?e.h:$p;a=Math.min(a,s),u=Math.min(u,i);let f=Number.isFinite(e.x)?e.x:SS,p=Number.isFinite(e.y)?e.y:kS;return f=Math.max(Math.min(f,s-dl),-(a-dl)),p=Math.max(Math.min(p,i-Um),0),{x:f,y:p,w:a,h:u}}const Xy=12,ru=60;function CS(e){return`sessionGroups:${e}`}function mu(e){try{const s=localStorage.getItem(CS(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 Wm(e,s){try{localStorage.setItem(CS(e),JSON.stringify(s))}catch{}}function bO(e,s){const i=mu(e);!i||!i.groups.some(a=>a.id===s)||(Wm(e,{...i,groups:i.groups.filter(a=>a.id!==s)}),window.dispatchEvent(new CustomEvent("session-windows:changed")))}function yO(e){const s=e%8;return{x:SS+s*Yy,y:kS+s*Yy,w:Au,h:$p}}function iu(e,s,i){return Math.max(s,Math.min(i,e))}function Jy(){return`g_${Math.random().toString(36).slice(2,10)}_${Date.now().toString(36)}`}function li(e,s){for(const i of e)if(Zu(i.root,s))return i;return null}function wO({projectId:e,sessions:s,sendMessage:i,subscribeBinary:a,onEvent:u,onAddSession:f,children:p}){const{t:o}=ft(),{warning:c}=Ls(),{confirm:h}=qn(),[m]=S.useState(()=>{const re=mu(e);if(!re)return{groups:[],zCounter:0};const ae=re.groups.map(J=>{const se=gn(J.root),pe=new Set(se),we={};for(const qe of Object.keys(J.colors||{}))pe.has(qe)&&(we[qe]=J.colors[qe]);const je={};for(const qe of se)je[qe]={intent:"open",nonce:0},we[qe]||(we[qe]=Fi(Object.values(we)));const $e=vO({x:J.x,y:J.y,w:J.w,h:J.h}),Je=J.ownerWindowId||Bt;return{...J,...$e,colors:we,intents:je,minimized:!!J.minimized,ownerWindowId:Je}});return{groups:ae,zCounter:re.zCounter||ae.length}}),[d,g]=S.useState(m.groups),b=S.useRef(m.zCounter),C=S.useRef(d);C.current=d;const k=S.useRef(s);k.current=s;const[x,_]=S.useState(null),w=S.useRef(null);w.current=x;const[y,E]=S.useState({}),R=S.useRef(y);R.current=y,S.useEffect(()=>{var se;const re={},ae=((se=mu(e))==null?void 0:se.sessionProjects)??{},J={};for(const pe of d)for(const we of gn(pe.root)){const je=s.find(Je=>Je.id===we)||y[we];je!=null&&je.title&&(re[we]=je.title);const $e=(je==null?void 0:je.project_id)||ae[we];$e&&(J[we]=$e)}Wm(e,{groups:d,zCounter:b.current,titles:re,sessionProjects:J}),window.dispatchEvent(new CustomEvent("session-windows:changed"))},[e,d,s,y]),S.useEffect(()=>()=>{var je;const re=C.current;if(re.length===0)return;let ae=!1;const J=re.map($e=>($e.ownerWindowId||Bt)!==Bt||$e.minimized?$e:(ae=!0,{...$e,minimized:!0}));if(!ae)return;const se={},pe=((je=mu(e))==null?void 0:je.sessionProjects)??{},we={};for(const $e of J)for(const Je of gn($e.root)){const qe=k.current.find(st=>st.id===Je)||R.current[Je];qe!=null&&qe.title&&(se[Je]=qe.title);const Ee=(qe==null?void 0:qe.project_id)||pe[Je];Ee&&(we[Je]=Ee)}Wm(e,{groups:J,zCounter:b.current,titles:se,sessionProjects:we}),window.dispatchEvent(new CustomEvent("session-windows:changed"))},[e]),S.useEffect(()=>{const re=document.documentElement.style,ae={left:0,right:0,top:0,bottom:0};for(const J of d)!J.dock||J.minimized||(J.ownerWindowId||Bt)!==Bt||(J.dock==="left"?ae.left=Math.max(ae.left,J.x+J.w-Ha()):J.dock==="right"?ae.right=Math.max(ae.right,window.innerWidth-J.x):J.dock==="top"?ae.top=Math.max(ae.top,J.y+J.h):ae.bottom=Math.max(ae.bottom,window.innerHeight-J.y));for(const J of["left","right","top","bottom"])re.setProperty(`--dock-inset-${J}`,`${Math.max(0,Math.round(ae[J]))}px`);return()=>{for(const J of["left","right","top","bottom"])re.removeProperty(`--dock-inset-${J}`)}},[d]),S.useEffect(()=>{const re=()=>{const se=window.innerWidth,pe=window.innerHeight,we=Ha();g(je=>{let $e=!1;const Je=je.map(qe=>{if(!qe.dock)return qe;const Ee=qe.dock==="left"||qe.dock==="right"?qe.w:qe.h,st=fS(qe.dock,Ee,se,pe,we);return st.x===qe.x&&st.y===qe.y&&st.w===qe.w&&st.h===qe.h?qe:($e=!0,{...qe,...st})});return $e?Je:je})};re();const ae=document.querySelector("main"),J=ae?new ResizeObserver(re):null;return ae&&J&&J.observe(ae),window.addEventListener("resize",re),()=>{J==null||J.disconnect(),window.removeEventListener("resize",re)}},[]);const[j,T]=S.useState(()=>new Set),N=S.useRef(new Set);S.useEffect(()=>{if(s.length===0)return;const re=s.filter(J=>J.project_id===e);if(re.length===0)return;const ae=new Set(re.map(J=>J.id));for(const J of d)for(const se of gn(J.root))ae.has(se)||y[se]||j.has(se)||N.current.has(se)||(N.current.add(se),T1(se).then(pe=>E(we=>({...we,[se]:pe}))).catch(pe=>{pe instanceof gu&&pe.status===404&&T(we=>new Set(we).add(se))}).finally(()=>N.current.delete(se)))},[d,s,e,y,j]),S.useEffect(()=>u(ae=>{ae.type!=="session:status-changed"||!ae.sessionId||E(J=>{const se=J[ae.sessionId];if(!se)return J;const pe={status:ae.status};return ae.worktree_path!==void 0&&(pe.worktree_path=ae.worktree_path),ae.branch_name!==void 0&&(pe.branch_name=ae.branch_name),{...J,[se.id]:{...se,...pe}}})}),[u]),S.useEffect(()=>{j.size!==0&&g(re=>{let ae=!1;const J=[];for(const se of re){const pe=gn(se.root);if(!pe.some(Ee=>j.has(Ee))){J.push(se);continue}ae=!0;const we=new Set(pe.filter(Ee=>!j.has(Ee))),je=nO(se.root,we);if(!je)continue;const $e=new Set(gn(je)),Je={};for(const Ee of Object.keys(se.colors))$e.has(Ee)&&(Je[Ee]=se.colors[Ee]);const qe={};for(const Ee of Object.keys(se.intents))$e.has(Ee)&&(qe[Ee]=se.intents[Ee]);J.push({...se,root:je,colors:Je,intents:qe})}return ae?J:re})},[j]);const D=S.useCallback((re,ae)=>{const J=C.current.length,se=yO(J);b.current+=1;const pe=b.current;return{id:Jy(),...se,z:pe,minimized:!1,root:Nr([re],re),colors:{[re]:Fi([])},intents:{[re]:{intent:ae,nonce:0}},ownerWindowId:Bt}},[]),A=S.useCallback((re,ae="open")=>{g(J=>{const se=li(J,re);b.current+=1;const pe=b.current;return se?J.map(we=>{var Ee,st,lt;if(we.id!==se.id)return we;const je=((Ee=we.intents[re])==null?void 0:Ee.intent)??"open",$e=ae==="start"||ae==="resume",Je=$e?ae:je,qe=Je!==je||$e;return{...we,z:pe,minimized:!1,root:Ps(we.root,re),intents:{...we.intents,[re]:{intent:Je,nonce:qe?(((st=we.intents[re])==null?void 0:st.nonce)??0)+1:((lt=we.intents[re])==null?void 0:lt.nonce)??0}}}}):[...J,D(re,ae)]})},[D]),B=S.useCallback(re=>{g(ae=>{const J=li(ae,re);if(!J)return ae;const se=ae.reduce((we,je)=>je.z>we?je.z:we,0);if(J.z===se&&!J.minimized)return ae;b.current+=1;const pe=b.current;return ae.map(we=>we.id===J.id?{...we,z:pe,minimized:!1}:we)})},[]),O=S.useCallback(async re=>{const ae=re.map(J=>k.current.find(se=>se.id===J)||R.current[J]).filter(J=>!!J&&J.status==="running");if(ae.length===0)return!0;if(!await h({message:o("session.confirmStop"),danger:!0}))return!1;for(const J of ae)Su(J.id).catch(()=>{});return!0},[o,h]),F=S.useCallback(async re=>{await O([re])&&g(ae=>{const J=li(ae,re);if(!J)return ae;const se=Ui(J.root,re);if(!se)return ae.filter(je=>je.id!==J.id);new Set(gn(se));const pe={...J.colors};delete pe[re];const we={...J.intents};return delete we[re],ae.map(je=>je.id===J.id?{...je,root:se,colors:pe,intents:we}:je)})},[O]),$=S.useCallback(re=>{g(ae=>{const J=li(ae,re);return J?ae.map(se=>se.id===J.id?{...se,minimized:!0}:se):ae})},[]),P=S.useCallback(re=>{g(ae=>{const J=li(ae,re);if(!J)return ae;b.current+=1;const se=b.current;return ae.map(pe=>pe.id===J.id?{...pe,minimized:!1,z:se}:pe)})},[]),H=S.useCallback(re=>!!li(C.current,re),[]),W=S.useCallback(async re=>{const ae=C.current.find(J=>J.id===re);ae&&!await O(gn(ae.root))||g(J=>J.filter(se=>se.id!==re))},[O]),G=S.useCallback(re=>{g(ae=>ae.map(J=>J.id===re?{...J,minimized:!0}:J))},[]);S.useEffect(()=>{const re=J=>{const se=J.detail;!(se!=null&&se.projectId)||!se.groupId||se.projectId===e&&g(pe=>{if(!pe.find($e=>$e.id===se.groupId))return pe;b.current+=1;const je=b.current;return pe.map($e=>$e.id===se.groupId?{...$e,minimized:!1,z:je}:$e)})},ae=async J=>{var je;const se=J.detail;if(!(se!=null&&se.projectId)||!se.groupId||se.projectId!==e)return;const pe=C.current.find($e=>$e.id===se.groupId);if(pe&&!await O(gn(pe.root)))return;const we=(pe==null?void 0:pe.ownerWindowId)||Bt;we!==Bt&&(de.current.delete(we),Me.current.delete(se.groupId),(je=he.current)==null||je.post({t:"group-reclaimed",popoutId:we,groupIds:[se.groupId],reason:"late-return"})),g($e=>$e.filter(Je=>Je.id!==se.groupId))};return window.addEventListener("session-windows:restore",re),window.addEventListener("session-windows:close",ae),()=>{window.removeEventListener("session-windows:restore",re),window.removeEventListener("session-windows:close",ae)}},[e,O]),S.useEffect(()=>{const re=sessionStorage.getItem("pendingSessionRestore");if(re)try{const ae=JSON.parse(re);if(ae.projectId!==e||!ae.groupId)return;sessionStorage.removeItem("pendingSessionRestore"),g(J=>{if(!J.find(we=>we.id===ae.groupId))return J;b.current+=1;const pe=b.current;return J.map(we=>we.id===ae.groupId?{...we,minimized:!1,z:pe}:we)})}catch{}},[e]);const I=S.useCallback(re=>{g(ae=>{if(!ae.find(pe=>pe.id===re))return ae;b.current+=1;const se=b.current;return ae.map(pe=>pe.id===re?{...pe,minimized:!1,z:se}:pe)})},[]),z=S.useCallback((re,ae)=>{g(J=>J.map(se=>se.id===re?{...se,...ae}:se))},[]),U=S.useCallback((re,ae)=>{g(J=>J.map(se=>{if(se.id===re){if(!ae)return se.dock?{...se,dock:void 0}:se;const pe=vl(ae,window.innerWidth,window.innerHeight,Ha());return{...se,...pe,dock:ae}}return ae&&se.dock===ae?{...se,dock:void 0}:se}))},[]),V=S.useCallback((re,ae,J)=>{g(se=>se.map(pe=>pe.id===re?{...pe,root:xS(pe.root,ae,J)}:pe))},[]),q=S.useCallback((re,ae)=>{g(J=>J.map(se=>se.id===re?{...se,root:Ps(se.root,ae)}:se))},[]),oe=S.useCallback((re,ae)=>{g(J=>J.map(se=>se.id===re?{...se,root:eO(se.root,ae)}:se))},[]),ee=S.useCallback((re,ae,J)=>{g(se=>se.map(pe=>pe.id===re?{...pe,root:gS(pe.root,ae,J)}:pe))},[]),Z=S.useCallback((re,ae,J,se)=>{if(se.button!==0||!C.current.find(gt=>gt.id===re))return;se.preventDefault();const we=se.clientX,je=se.clientY;let $e=null;_({groupId:re,sessionId:ae,fromPath:J,startX:we,startY:je,mouseX:we,mouseY:je,hoveredGroupId:null,hoveredPath:null,hoveredRect:null,zone:null,viewportZone:null});const Je=(gt,vt)=>{const Tt=Jy();$e=Tt;const Xe=window.innerWidth,ut=window.innerHeight,Q={x:iu(gt-60,-Au+dl,Xe-dl),y:iu(vt-12,0,ut-Um),w:Au,h:$p};g(ze=>{const ue=ze.find(Ct=>Ct.id===re);if(!ue)return ze;const Fe=Ui(ue.root,ae),Ve=ue.colors[ae]||Fi([]),ht=ue.intents[ae]??{intent:"open",nonce:0};b.current+=1;const Ne=b.current,at={id:Tt,...Q,z:Ne,minimized:!1,root:Nr([ae],ae),colors:{[ae]:Ve},intents:{[ae]:ht},ownerWindowId:Bt},bt=[];for(const Ct of ze)if(Ct.id===re){if(Fe){const qt=new Set(gn(Fe)),an={};for(const vn of Object.keys(Ct.colors))qt.has(vn)&&(an[vn]=Ct.colors[vn]);const Pn={};for(const vn of Object.keys(Ct.intents))qt.has(vn)&&(Pn[vn]=Ct.intents[vn]);bt.push({...Ct,root:Tu(Fe),colors:an,intents:Pn})}}else bt.push(Ct);return bt.push(at),bt})};let qe=!1;const Ee=gt=>{const vt=window.screenX,Tt=window.screenY,Xe=vt+window.outerWidth,ut=Tt+window.outerHeight;return gt.screenX<vt-ru||gt.screenX>Xe+ru||gt.screenY<Tt-ru||gt.screenY>ut+ru},st=gt=>{if(qe)return;const vt=w.current;if(!vt)return;if(!$e)Math.hypot(gt.clientX-we,gt.clientY-je)>=Xy&&Je(gt.clientX,gt.clientY);else{const Fe=window.innerWidth,Ve=window.innerHeight,ht=iu(gt.clientX-60,-640,Fe-dl),Ne=iu(gt.clientY-12,0,Ve-Um);g(at=>at.map(bt=>bt.id===$e?{...bt,x:ht,y:Ne}:bt))}if($e&&Ee(gt)&&C.current.some(Fe=>Fe.id===$e)){const Fe=Oe.current;if(Fe){qe=!0;const Ve=$e;yt(),_(null),Fe(Ve,{atScreenX:gt.screenX,atScreenY:gt.screenY});return}}let Tt=null,Xe=null,ut=null,Q=null;const ze=document.elementsFromPoint(gt.clientX,gt.clientY);for(const Fe of ze){const Ve=Fe.closest("[data-group-id][data-stack-path]");if(!Ve)continue;const ht=Ve.dataset.groupId||"",Ne=Ve.dataset.stackPath||"";if($e?ht===$e:ht===vt.groupId&&Ne===vt.fromPath.join("."))continue;const bt=Ne===""?[]:Ne.split(".").map(Number),Ct=Ve.getBoundingClientRect();Tt=ht,Xe=bt,ut={x:Ct.left,y:Ct.top,w:Ct.width,h:Ct.height},Q=Qu(gt.clientX,gt.clientY,ut);break}const ue=Q||!$e?null:hS(gt.clientX,gt.clientY,window.innerWidth,window.innerHeight);_({...vt,mouseX:gt.clientX,mouseY:gt.clientY,hoveredGroupId:Tt,hoveredPath:Xe,hoveredRect:ut,zone:Q,viewportZone:ue})};let lt=!1;const yt=()=>{lt||(lt=!0,window.removeEventListener("mousemove",st),window.removeEventListener("mouseup",kt),window.removeEventListener("blur",mt),window.removeEventListener("keydown",pt),document.removeEventListener("visibilitychange",dt))},mt=()=>{yt(),_(null)},pt=gt=>{gt.key==="Escape"&&mt()},dt=()=>{document.hidden&&mt()},kt=gt=>{var Xe;yt();const vt=w.current;if(_(null),!vt)return;if(vt.hoveredGroupId&&vt.hoveredPath&&vt.zone){const ut=$e||vt.groupId;te(ut,vt.sessionId,vt.hoveredGroupId,vt.hoveredPath,vt.zone);return}const Tt=vt.viewportZone;if(Tt&&$e&&C.current.some(ut=>ut.id===$e)){const ut=$e;if(Tt==="popout")(Xe=Oe.current)==null||Xe.call(Oe,ut,{atScreenX:gt.screenX,atScreenY:gt.screenY});else if(Tt==="max"){const Q=vl(Tt,window.innerWidth,window.innerHeight,Ha());g(ze=>ze.map(ue=>ue.id===ut?{...ue,x:Q.x,y:Q.y,w:Q.w,h:Q.h}:ue))}else U(ut,Tt);return}};window.addEventListener("mousemove",st),window.addEventListener("mouseup",kt),window.addEventListener("blur",mt),window.addEventListener("keydown",pt),document.addEventListener("visibilitychange",dt)},[]),te=S.useCallback((re,ae,J,se,pe)=>{g(we=>{const je=we.find(pt=>pt.id===re),$e=we.find(pt=>pt.id===J);if(!je||!$e)return we;if(re===J){const pt=ul(je.root,se);if(!pt||pt.kind!=="stack")return we;const dt=pt.tabs.find(Tt=>Tt!==ae);if(!dt)return we;const kt=Ui(je.root,ae);if(!kt)return we;const gt=Zu(kt,dt);if(!gt)return we;let vt;return pe==="center"?vt=Hi(kt,gt,ae):vt=$a(kt,gt,pe,Nr([ae])),vt=Ps(vt,ae),we.map(Tt=>Tt.id!==re?Tt:(b.current+=1,{...Tt,root:vt,z:b.current,minimized:!1}))}const Je=Ui(je.root,ae),qe=je.colors[ae],Ee=je.intents[ae]??{intent:"open",nonce:0};let st;if(pe==="center")st=Hi($e.root,se,ae);else{const pt=Nr([ae]);st=$a($e.root,se,pe,pt)}st=Ps(st,ae);const lt={...$e.colors};lt[ae]||(lt[ae]=qe||Fi(Object.values(lt)));const yt={...$e.intents,[ae]:Ee},mt=[];for(const pt of we)if(pt.id===re){if(Je){const dt=new Set(gn(Je)),kt={};for(const vt of Object.keys(pt.colors))dt.has(vt)&&(kt[vt]=pt.colors[vt]);const gt={};for(const vt of Object.keys(pt.intents))dt.has(vt)&&(gt[vt]=pt.intents[vt]);mt.push({...pt,root:Je,colors:kt,intents:gt})}}else pt.id===J?(b.current+=1,mt.push({...pt,root:st,colors:lt,intents:yt,z:b.current,minimized:!1})):mt.push(pt);return mt})},[]),Y=S.useCallback((re,ae,J,se)=>{g(pe=>{if(re===ae)return pe;const we=pe.find(lt=>lt.id===re),je=pe.find(lt=>lt.id===ae);if(!we||!je||we.root.kind!=="stack")return pe;const $e=we.root;let Je;se==="center"?Je=$e.tabs.reduce((lt,yt)=>Hi(lt,J,yt),je.root):Je=$a(je.root,J,se,$e),Je=Ps(Je,$e.activeTab);const qe={...je.colors,...we.colors},Ee={...je.intents,...we.intents},st=[];for(const lt of pe)lt.id!==re&&(lt.id===ae?(b.current+=1,st.push({...lt,root:Je,colors:qe,intents:Ee,z:b.current,minimized:!1})):st.push(lt));return st})},[]),he=S.useRef(null),de=S.useRef(new Map),[ye,le]=S.useState(null),De=S.useRef(ye);De.current=ye;const Re=S.useRef(null),ve=S.useRef(typeof document<"u"&&document.hasFocus()?Date.now():0);S.useEffect(()=>{const re=()=>{ve.current=Date.now()};window.addEventListener("focus",re);const ae=bS();return()=>{window.removeEventListener("focus",re),ae(),Re.current&&clearTimeout(Re.current)}},[]);const Me=S.useRef(new Map),Oe=S.useRef(null),tt=S.useCallback((re,ae)=>{var st;const J=C.current.find(lt=>lt.id===re);if(!J)return;const se=dO(),pe={...J,ownerWindowId:se,dock:void 0};Me.current.set(re,pe),de.current.set(se,Date.now()),g(lt=>lt.map(yt=>yt.id===re?{...yt,ownerWindowId:se,dock:void 0}:yt)),(st=he.current)==null||st.post({t:"group-handoff",to:se,groupId:re,group:pe});const we=ae&&(typeof ae.atScreenX=="number"||typeof ae.atScreenY=="number"),je=we?Math.max(0,((ae==null?void 0:ae.atScreenX)??window.screenX+J.x)-40):Math.max(0,window.screenX+J.x),$e=we?Math.max(0,((ae==null?void 0:ae.atScreenY)??window.screenY+J.y)-12):Math.max(0,window.screenY+J.y),Je=["popup",`width=${Math.max(400,J.w)}`,`height=${Math.max(300,J.h+40)}`,`left=${je}`,`top=${$e}`].join(","),qe=`/popout/${encodeURIComponent(e)}/${encodeURIComponent(re)}?wid=${encodeURIComponent(se)}`,Ee=window.open(qe,"_blank",Je);if(!Ee){Me.current.delete(re),de.current.delete(se),g(lt=>lt.map(yt=>yt.id===re?{...yt,ownerWindowId:Bt}:yt)),c(o("session.popout.blocked"));return}cO(se,Ee)},[e,o,c]);Oe.current=tt;const nt=S.useCallback(re=>{var se;const ae=C.current.find(pe=>pe.id===re);if(!ae)return;const J=ae.ownerWindowId||Bt;if(J===Bt){I(re);return}(se=he.current)==null||se.post({t:"group-recall",popoutId:J,groupId:re}),setTimeout(()=>{var je;const pe=C.current.find($e=>$e.id===re);if(!pe||(pe.ownerWindowId||Bt)===Bt)return;de.current.delete(J),Me.current.delete(re),(je=he.current)==null||je.post({t:"group-reclaimed",popoutId:J,groupIds:[re],reason:"late-return"}),b.current+=1;const we=b.current;g($e=>$e.map(Je=>Je.id===re?{...Je,ownerWindowId:Bt,minimized:!1,z:we}:Je))},1500)},[I]),ke=S.useCallback(re=>{const ae=li(C.current,re);ae&&nt(ae.id)},[nt]);S.useEffect(()=>{const re=ae=>{const J=ae.detail;!(J!=null&&J.projectId)||!J.groupId||J.projectId!==e||nt(J.groupId)};return window.addEventListener("session-windows:recall",re),()=>window.removeEventListener("session-windows:recall",re)},[e,nt]),S.useEffect(()=>{const re=sessionStorage.getItem("pendingSessionRecall");if(re)try{const ae=JSON.parse(re);if(ae.projectId!==e||!ae.groupId)return;sessionStorage.removeItem("pendingSessionRecall");const J=ae.groupId;setTimeout(()=>nt(J),0)}catch{}},[e,nt]);const fe=S.useCallback(re=>re.kind==="stack"?[]:[0,...fe(re.children[0])],[]),Te=S.useCallback((re,ae,J)=>{const se=ae?C.current.find($e=>$e.id===ae):null,pe=se&&(se.ownerWindowId||Bt)===Bt;if(!se||!pe){A(re,"start");return}const we=(()=>{if(J){const $e=ul(se.root,J);if($e&&$e.kind==="stack")return J}return fe(se.root)})();b.current+=1;const je=b.current;g($e=>$e.map(Je=>{if(Je.id!==se.id)return Je;const qe=Ps(Hi(Je.root,we,re),re);return{...Je,root:qe,z:je,minimized:!1,colors:{...Je.colors,[re]:Fi(Object.values(Je.colors))},intents:{...Je.intents,[re]:{intent:"start",nonce:0}}}}))},[A,fe]),Ce=S.useCallback(async(re,ae)=>{const J=new Date,se=String(J.getHours()).padStart(2,"0"),pe=String(J.getMinutes()).padStart(2,"0"),we=String(J.getSeconds()).padStart(2,"0"),je=await Sm(e,{title:`Shell ${se}:${pe}:${we}`,cli_tool:"raw-shell",use_worktree:!1,memory_inject_mode:"none"});return f==null||f(je),Te(je.id,re,ae),je.id},[e,f,Te]);S.useEffect(()=>{const re=Pp();he.current=re;const ae=se=>{var pe;if(se.t==="hello"){const we=Me.current.get(se.groupId);if(we&&we.ownerWindowId===se.from)re.post({t:"group-handoff",to:se.from,groupId:se.groupId,group:we});else{const je=C.current.find($e=>$e.id===se.groupId);je&&je.ownerWindowId===se.from&&re.post({t:"group-handoff",to:se.from,groupId:se.groupId,group:je})}}else if(se.t==="group-return"||se.t==="bye")if(se.t==="group-return"){const we=se.group;we&&we.id===se.groupId&&(Me.current.delete(se.groupId),de.current.delete(se.from),se.projectId&&se.projectId!==e&&bO(se.projectId,se.groupId),g(je=>{const $e=je.find(qe=>qe.id===se.groupId),Je={...we,ownerWindowId:Bt,dock:void 0};return $e?je.map(qe=>qe.id===se.groupId?Je:qe):[...je,Je]}))}else de.current.delete(se.from),g(we=>we.map(je=>je.ownerWindowId===se.from?{...je,ownerWindowId:Bt}:je));else if(se.t==="group-close")Me.current.delete(se.groupId),g(we=>we.filter(je=>je.id!==se.groupId));else if(se.t==="heartbeat")de.current.set(se.from,Date.now());else if(se.t==="group-update"){const we=se.patch;g(je=>je.map($e=>$e.id===se.groupId?{...$e,...we}:$e))}else if(se.t==="dock-probe"){if(document.visibilityState!=="visible")return;const we=Ru(se.x,se.y),je=Mu(we)?Lu(we.x,we.y):null;if(je){const $e=De.current;(!$e||$e.zone!==je.zone||$e.groupId!==je.groupId||$e.path.join(".")!==je.path.join("."))&&le({rect:je.rect,zone:je.zone,path:je.path,groupId:je.groupId}),Re.current&&clearTimeout(Re.current),Re.current=setTimeout(()=>le(null),800),re.post({t:"dock-probe-result",from:Bt,to:se.from,hit:!0,focusAt:ve.current})}else De.current&&le(null),re.post({t:"dock-probe-result",from:Bt,to:se.from,hit:!1,focusAt:ve.current})}else if(se.t==="dock-end")le(null);else if(se.t==="dock-commit"&&se.to===Bt){const we=Ru(se.x,se.y),je=Mu(we)?Lu(we.x,we.y):null,$e=je&&je.zone?je:(pe=De.current)!=null&&pe.zone?De.current:null;let Je=!1;const qe=C.current.filter(Ee=>(Ee.ownerWindowId||Bt)===Bt);if($e&&$e.zone&&!li(qe,se.sessionId)){const Ee=C.current.find(lt=>lt.id===$e.groupId),st=Ee?ul(Ee.root,$e.path):null;if(Ee&&st&&st.kind==="stack"){Je=!0;const lt=$e.zone,yt=$e.path;b.current+=1;const mt=b.current;g(pt=>pt.map(dt=>{if(dt.id!==Ee.id)return dt;const kt=lt==="center"?Hi(dt.root,yt,se.sessionId):$a(dt.root,yt,lt,Nr([se.sessionId])),gt=Ps(kt,se.sessionId),vt={...dt.colors};vt[se.sessionId]||(vt[se.sessionId]=se.color||Fi(Object.values(vt)));const Tt={...dt.intents,[se.sessionId]:se.intentInfo??{intent:"open",nonce:0}};return{...dt,root:gt,colors:vt,intents:Tt,z:mt,minimized:!1}}))}}le(null),re.post({t:"dock-commit-ack",from:Bt,to:se.from,sessionId:se.sessionId,accepted:Je})}},J=re.subscribe(ae);return()=>{J(),re.close(),he.current=null}},[e]),S.useEffect(()=>{const re=Date.now();for(const ae of m.groups)ae.ownerWindowId&&ae.ownerWindowId!==Bt&&de.current.set(ae.ownerWindowId,re)},[]),S.useEffect(()=>{const re=async()=>{var $e;const J=Date.now(),se=[];for(const[Je,qe]of de.current.entries())J-qe>vS&&se.push(Je);if(se.length===0)return;const pe=await yS(),we=se.filter(Je=>pe.has(Je)?(de.current.set(Je,J),!1):!0);if(we.length===0)return;for(const Je of we)de.current.delete(Je);const je=new Set(we);for(const Je of C.current)Je.ownerWindowId&&je.has(Je.ownerWindowId)&&Me.current.delete(Je.id);for(const Je of we){const qe=C.current.filter(Ee=>Ee.ownerWindowId===Je).map(Ee=>Ee.id);qe.length>0&&(($e=he.current)==null||$e.post({t:"group-reclaimed",popoutId:Je,groupIds:qe,reason:"heartbeat-timeout"}))}g(Je=>Je.map(qe=>qe.ownerWindowId&&we.includes(qe.ownerWindowId)?{...qe,ownerWindowId:Bt}:qe))},ae=setInterval(()=>{re()},Ip);return()=>clearInterval(ae)},[]);const Ge=S.useCallback((re,ae)=>{i({type:"session:terminal-input",sessionId:re,input:ae})},[i]),Ze=S.useCallback(()=>{var J,se;const re=C.current.filter(pe=>(pe.ownerWindowId||Bt)===Bt).slice().sort((pe,we)=>we.z-pe.z),ae=[];for(const pe of re)for(const we of gn(pe.root)){const je=((J=k.current.find($e=>$e.id===we))==null?void 0:J.title)||((se=R.current[we])==null?void 0:se.title)||we;ae.push({sessionId:we,label:je})}return ae},[]),be=S.useCallback(async(re,ae)=>{const se=C.current.filter(we=>!we.minimized&&(we.ownerWindowId||Bt)===Bt).reduce((we,je)=>we&&we.z>=je.z?we:je,null),pe=await Sm(e,{title:ae||"",description:re,use_worktree:!1,memory_inject_mode:"none"});f==null||f(pe),Te(pe.id,(se==null?void 0:se.id)??null)},[e,f,Te]),Be=S.useMemo(()=>({openOrFocus:A,close:F,focus:B,minimize:$,restore:P,isOpen:H,recallPopout:ke,closeGroup:W,minimizeGroup:G,restoreGroup:I,setGroupGeometry:z,setGroupDock:U,setSplitSizes:V,setActiveTab:q,applyLayoutPreset:oe,reorderTab:ee,beginTabDrag:Z,dockGroup:Y,popOutGroup:tt,createRawShellTab:Ce,sendToSession:Ge,listOpenTerminals:Ze,sendToNewTerminal:be}),[A,F,B,$,P,H,ke,W,G,I,z,U,V,q,oe,ee,Z,Y,tt,Ce,Ge,Ze,be]),ne=S.useMemo(()=>{const re={};for(const ae of d){const se=(ae.ownerWindowId||Bt)!==Bt?"popped":ae.minimized?"minimized":"floating";for(const pe of gn(ae.root))re[pe]=se}return re},[d]);S.useEffect(()=>{const re=ae=>{const J=/Mac|iPhone|iPad|iPod/.test(navigator.platform),se=J?ae.metaKey:ae.ctrlKey,pe=J?ae.ctrlKey:ae.metaKey;if(!se||pe||ae.altKey||ae.shiftKey||ae.key.toLowerCase()!=="t")return;ae.preventDefault();const je=C.current.filter($e=>!$e.minimized&&($e.ownerWindowId||Bt)===Bt).reduce(($e,Je)=>$e&&$e.z>=Je.z?$e:Je,null);Ce((je==null?void 0:je.id)??null).catch(()=>{})};return window.addEventListener("keydown",re),()=>window.removeEventListener("keydown",re)},[Ce]);const _e=S.useMemo(()=>{const re=new Map;for(const ae of Object.values(y))re.set(ae.id,ae);for(const ae of s)re.set(ae.id,ae);return re},[s,y]),X=d.filter(re=>!re.minimized&&(re.ownerWindowId||Bt)===Bt),me=X.reduce((re,ae)=>ae.z>re.z?{id:ae.id,z:ae.z}:re,{id:null,z:-1/0}).id;return t.jsx(Hp.Provider,{value:Be,children:t.jsxs(wS.Provider,{value:ne,children:[p,(()=>{const re=new Map(X.slice().sort((ae,J)=>ae.z-J.z).map((ae,J)=>[ae.id,J+1]));return X.map(ae=>{const J=X.filter(se=>se.id!==ae.id).map(({x:se,y:pe,w:we,h:je})=>({x:se,y:pe,w:we,h:je}));return t.jsx(oO,{group:ae,sessionsById:_e,neighbors:J,isTopmost:ae.id===me,zIndex:re.get(ae.id)??1,sendMessage:i,subscribeBinary:a,onEvent:u},ae.id)})})(),x&&x.hoveredRect&&t.jsx(bl,{targetRect:x.hoveredRect,activeZone:x.zone}),x&&!x.zone&&Math.hypot(x.mouseX-x.startX,x.mouseY-x.startY)>=Xy&&t.jsx(mS,{activeZone:x.viewportZone}),ye&&t.jsx(bl,{targetRect:ye.rect,activeZone:ye.zone})]})})}function _O(e){if(!e)return[];try{const s=JSON.parse(e);return Array.isArray(s)?s.map(String).filter(Boolean):[]}catch{return[]}}const SO={pending:"bg-warm-400",running:"bg-status-success",completed:"bg-accent",failed:"bg-status-error",stopped:"bg-status-warning"};function kO({projectId:e,sessions:s,projectCliTool:i,isGitRepo:a,projectUseWorktree:u,projectDefaultBranch:f,onAddSession:p,onUpdateSession:o,onStopSession:c,onDeleteSession:h,onCleanupSession:m}){const{t:d}=ft(),{confirm:g}=qn(),{openOrFocus:b,recallPopout:C}=_S(),k=mO(),[x,_]=S.useState(!1),[w,y]=S.useState(!1),[E,R]=S.useState(null),[j,T]=S.useState(!1),[N,D]=S.useState(null),[A,B]=S.useState([]),[O,F]=S.useState(""),[$,P]=S.useState(null);S.useEffect(()=>{let oe=!1;return cp().then(ee=>{oe||B(ee)}).catch(()=>{}),()=>{oe=!0}},[]),S.useEffect(()=>{if(!a)return;let oe=!1;return s1(e).then(ee=>{oe||F(ee.branch||"")}).catch(()=>{}),()=>{oe=!0}},[e,a]);const H=S.useMemo(()=>{const oe=new Map;for(const ee of A)oe.set(ee.id,ee);return oe},[A]),W=S.useMemo(()=>E?s.find(oe=>oe.id===E)??null:null,[E,s]),G=S.useMemo(()=>{if(W)return{title:W.title,description:W.description??"",cliTool:W.cli_tool??"",useWorktree:W.use_worktree===1,memoryInjectMode:W.memory_inject_mode??"none",memoryNodeIds:pz(W.memory_node_ids??null),memoryRawFilePaths:_O(W.memory_raw_file_paths??null),tagId:W.tag_id??null}},[W]),I=S.useCallback(()=>{R(null),D(null),_(oe=>!oe)},[]),z=S.useCallback(oe=>{_(!1),D(null),R(oe)},[]),U=S.useCallback(()=>{_(!1),R(null),D(null)},[]),V=S.useCallback(async(oe,ee,Z,te,Y,he,de,ye)=>{y(!0);try{const le=await Sm(e,{title:oe,description:ee||void 0,cli_tool:Z,use_worktree:te,memory_inject_mode:Y,memory_node_ids:he,memory_raw_file_paths:de,tag_id:ye??null});p(le),_(!1)}finally{y(!1)}},[e,p]),q=S.useCallback(async(oe,ee,Z,te,Y,he,de,ye)=>{if(E){T(!0),D(null);try{const le=await M4(E,{title:oe,description:ee||void 0,cli_tool:Z,use_worktree:te,memory_inject_mode:Y,memory_node_ids:he,memory_raw_file_paths:de,tag_id:ye??null});o(le),R(null)}catch(le){D(le instanceof Error?le.message:String(le))}finally{T(!1)}}},[E,o]);return t.jsxs("div",{className:"space-y-4 min-h-[50vh]",onContextMenu:oe=>{gi(oe)||(oe.preventDefault(),P({x:oe.clientX,y:oe.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:I,className:"btn-primary text-xs py-2",disabled:w,children:["+ ",d("session.new")]})]}),x&&t.jsx(Ey,{projectId:e,onSave:V,onCancel:U,projectCliTool:i,isGitRepo:a,projectUseWorktree:u}),G&&E&&t.jsxs("div",{className:"space-y-2",children:[t.jsx(Ey,{projectId:e,initial:G,onSave:q,onCancel:U,projectCliTool:i,isGitRepo:a},E),(j||N)&&t.jsxs("div",{className:"text-xs px-1",children:[j&&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(Yi,{icon:ml,title:d("session.empty"),description:d("session.emptyHint")})}):t.jsx("div",{className:"space-y-3",children:s.map((oe,ee)=>{const Z=["pending","failed","stopped","completed"].includes(oe.status),te=oe.status==="running",Y=oe.status!=="running",he=["stopped","failed","completed"].includes(oe.status)&&(oe.cli_tool??"claude")==="claude"&&!!oe.worktree_path,de=E===oe.id,ye=k[oe.id]??"closed",le=ye==="popped";return t.jsx("div",{className:`card overflow-hidden ${de?"border-l-4 border-accent bg-warm-100/30":""}`,onContextMenu:De=>{gi(De)||(De.preventDefault(),De.stopPropagation(),P({x:De.clientX,y:De.clientY,sessionId:oe.id}))},children:t.jsx("div",{className:"p-4 cursor-pointer hover:bg-warm-50/50 transition-colors",onClick:()=>le?C(oe.id):b(oe.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:[oe.tag_id&&H.get(oe.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:`${H.get(oe.tag_id).color}22`,color:H.get(oe.tag_id).color},children:[t.jsx("span",{className:"w-2 h-2 rounded-full",style:{backgroundColor:H.get(oe.tag_id).color}}),H.get(oe.tag_id).name]}),t.jsx("h3",{className:"text-sm font-semibold text-warm-700 truncate",children:oe.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 ${SO[oe.status]||"bg-warm-400"}`}),d(`status.${oe.status}`)||oe.status]}),ye!=="closed"&&t.jsxs("span",{className:"inline-flex items-center gap-1 text-2xs text-warm-400 whitespace-nowrap",title:le?d("session.dock.poppedHint"):void 0,children:[le?t.jsx(Dr,{size:12}):t.jsx("span",{"aria-hidden":"true",children:"·"}),d(`session.windowState.${ye}`)]})]}),oe.description&&t.jsx("p",{className:"text-xs text-warm-400 mt-1 line-clamp-1",children:oe.description}),t.jsxs("div",{className:"flex items-center gap-2 mt-1",children:[t.jsx("span",{className:"text-2xs text-warm-300",children:oe.cli_tool||"claude"}),(oe.branch_name||a&&(O||f))&&t.jsxs("span",{className:"text-2xs text-accent/70 flex items-center gap-0.5",children:[t.jsx(Vi,{size:12}),oe.branch_name||O||f]})]})]}),t.jsxs("div",{className:"flex gap-1",onClick:De=>De.stopPropagation(),children:[le&&t.jsx("button",{onClick:()=>C(oe.id),className:"p-1.5 text-accent hover:bg-accent/10 rounded-md transition-colors",title:d("session.recallToMain"),children:t.jsx(qi,{size:16})}),Z&&t.jsx("button",{onClick:()=>b(oe.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(Tr,{size:16})}),he&&t.jsx("button",{onClick:()=>b(oe.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(mi,{size:16})}),t.jsx("button",{onClick:()=>z(oe.id),disabled:!Y,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(Y?"session.edit":"session.editDisabledRunning"),children:t.jsx(um,{size:16})}),te&&t.jsx("button",{onClick:()=>c(oe.id),className:"p-1.5 text-status-warning hover:bg-status-warning/10 rounded-md transition-colors",title:d("session.stop"),children:t.jsx(Ki,{size:16})}),oe.status!=="running"&&(!!oe.worktree_path||!!oe.branch_name)&&t.jsx("button",{onClick:async()=>{const De=oe.branch_name?await g({message:d("cleanup.confirmDeleteBranch").replace("{name}",oe.branch_name),danger:!0}):!1;m(oe.id,De)},className:"p-1.5 text-warm-400 hover:text-status-warning rounded-md transition-colors",title:d("session.cleanup"),children:t.jsx(xu,{size:16})}),t.jsx("button",{onClick:()=>h(oe.id),className:"p-1.5 text-warm-400 hover:text-status-error rounded-md transition-colors",title:d("session.delete"),children:t.jsx(An,{size:16})})]})]})})},oe.id)})}),$&&(()=>{const oe=()=>P(null),ee=$.sessionId?s.find(Re=>Re.id===$.sessionId):void 0;if(!ee)return t.jsx(ir,{x:$.x,y:$.y,onClose:oe,children:t.jsxs("button",{type:"button",onClick:()=>{R(null),D(null),_(!0)},className:sn,children:[t.jsx(yn,{size:14}),d("session.new")]})});const Z=["pending","failed","stopped","completed"].includes(ee.status),te=ee.status==="running",Y=ee.status!=="running",he=["stopped","failed","completed"].includes(ee.status)&&(ee.cli_tool??"claude")==="claude"&&!!ee.worktree_path,de=ee.status!=="running"&&(!!ee.worktree_path||!!ee.branch_name),ye=k[ee.id]??"closed",le=ye==="popped",De=d(le?"session.recallToMain":ye==="minimized"?"session.restoreWindow":ye==="floating"?"session.focusWindow":"session.openWindow");return t.jsxs(ir,{x:$.x,y:$.y,onClose:oe,children:[t.jsxs("button",{type:"button",onClick:()=>le?C(ee.id):b(ee.id,"open"),className:sn,children:[le?t.jsx(qi,{size:14}):t.jsx(ml,{size:14}),De]}),Z&&t.jsxs("button",{type:"button",onClick:()=>b(ee.id,"start"),className:sn,children:[t.jsx(Tr,{size:14}),d("session.start")]}),he&&t.jsxs("button",{type:"button",onClick:()=>b(ee.id,"resume"),className:sn,title:d("session.resumeHint")||d("session.resume"),children:[t.jsx(mi,{size:14}),d("session.resume")]}),Y&&t.jsxs("button",{type:"button",onClick:()=>z(ee.id),className:sn,children:[t.jsx(um,{size:14}),d("session.edit")]}),te&&t.jsxs("button",{type:"button",onClick:()=>c(ee.id),className:sn,children:[t.jsx(Ki,{size:14}),d("session.stop")]}),de&&t.jsxs("button",{type:"button",onClick:async()=>{const Re=ee.branch_name?await g({message:d("cleanup.confirmDeleteBranch").replace("{name}",ee.branch_name),danger:!0}):!1;m(ee.id,Re)},className:sn,children:[t.jsx(xu,{size:14}),d("session.cleanup")]}),t.jsx(W_,{}),t.jsxs("button",{type:"button",onClick:()=>h(ee.id),className:Mp,children:[t.jsx(An,{size:14}),d("session.delete")]})]})})()]})}const zu={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"}},CO=Object.keys(zu),Ou={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 Wa(e){const s=zu[e]||zu.default;return`${s.bg} ${s.text}`}function Up({src:e,alt:s,onClose:i}){return S.useEffect(()=>{const a=u=>{u.key==="Escape"&&i()};return window.addEventListener("keydown",a),()=>window.removeEventListener("keydown",a)},[i]),rn.createPortal(t.jsxs("div",{className:"fixed inset-0 z-tooltip flex items-center justify-center p-6",style:{backgroundColor:"rgba(0,0,0,0.85)"},onClick:i,children:[t.jsx("button",{type:"button",onClick:i,className:"absolute top-4 right-4 h-9 w-9 rounded-full bg-white/10 text-white flex items-center justify-center hover:bg-white/20 transition-colors","aria-label":"close",children:t.jsx(Xt,{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 qm({anchorRef:e,width:s,onClose:i,className:a,style:u,children:f}){const p=S.useRef(null),[o,c]=S.useState(null);return S.useLayoutEffect(()=>{const h=e.current;if(!h)return;const m=h.getBoundingClientRect();let d=m.left;d+s>window.innerWidth-8&&(d=Math.max(8,window.innerWidth-8-s)),d<8&&(d=8),c({top:m.bottom+4,left:d})},[e,s]),S.useEffect(()=>{const h=d=>{var b,C;const g=d.target;(b=p.current)!=null&&b.contains(g)||(C=e.current)!=null&&C.contains(g)||i()},m=()=>i();return document.addEventListener("mousedown",h),window.addEventListener("scroll",m,!0),window.addEventListener("resize",m),()=>{document.removeEventListener("mousedown",h),window.removeEventListener("scroll",m,!0),window.removeEventListener("resize",m)}},[i,e]),o?rn.createPortal(t.jsx("div",{ref:p,className:a,style:{position:"fixed",top:o.top,left:o.left,width:s,...u},children:f}),document.body):null}const Qy={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 jO({item:e,tagColors:s,existingTags:i,onSave:a,onDelete:u,onConvertToTodo:f,onConvertToSchedule:p,onConvertToSession:o,onUpdateTag:c}){var ne,_e;const{t:h}=ft(),{confirm:m}=qn(),[d,g]=S.useState(!1),[b,C]=S.useState(!1),[k,x]=S.useState(!1),_=S.useRef(null),w=S.useRef(null),[y,E]=S.useState({top:0,left:0}),[R,j]=S.useState(e.title),[T,N]=S.useState(e.description??""),[D,A]=S.useState(e.priority),[B,O]=S.useState(e.due_date??""),[F,$]=S.useState(e.status),[P,H]=S.useState(()=>{try{return e.tags?JSON.parse(e.tags):[]}catch{return[]}}),[W,G]=S.useState(""),[I,z]=S.useState(!1),[U,V]=S.useState(null),[q,oe]=S.useState(null),ee=S.useRef(null),Z=S.useRef(null),[te,Y]=S.useState(()=>{try{return e.images?JSON.parse(e.images):[]}catch{return[]}}),he=S.useRef(null);S.useEffect(()=>{j(e.title),N(e.description??""),A(e.priority),O(e.due_date??""),$(e.status);try{H(e.tags?JSON.parse(e.tags):[])}catch{H([])}try{Y(e.images?JSON.parse(e.images):[])}catch{Y([])}},[e]);const de=P,ye=e.status==="moved",le=e.due_date&&new Date(e.due_date)<new Date&&!ye&&e.status!=="done",De=S.useCallback(X=>{a(e.id,X)},[e.id,a]),Re=()=>{const X=R.trim();X&&X!==e.title?De({title:X}):j(e.title)},ve=()=>{const X=T.trim();X!==(e.description??"")&&De({description:X||void 0})},Me=X=>{A(X),X!==e.priority&&De({priority:X})},Oe=X=>{O(X),X!==(e.due_date??"")&&De({due_date:X||void 0})},tt=X=>{const me=X;$(me),me!==e.status&&De({status:me})},nt=X=>{H(X);const me=(()=>{try{return e.tags?JSON.parse(e.tags):[]}catch{return[]}})();JSON.stringify(X)!==JSON.stringify(me)&&De({tags:X.length>0?JSON.stringify(X):void 0})},ke=X=>{var re;const me=X.trim();if(me&&!P.includes(me)&&(nt([...P,me]),!s.has(me)&&c)){const ae=["blue","green","orange","purple","pink","red","yellow","brown"],J=ae[s.size%ae.length];c(me,{color:J})}G(""),(re=ee.current)==null||re.focus()},fe=X=>nt(P.filter(me=>me!==X)),Te=i.filter(X=>!P.includes(X)&&(!W||X.toLowerCase().includes(W.toLowerCase()))),Ce=S.useCallback(X=>{const me=Array.from(X).filter(J=>J.type.startsWith("image/")),re=[];let ae=0;for(const J of me){const se=new FileReader;se.onload=()=>{re.push({name:J.name,data:se.result}),ae++,ae===me.length&&M1(e.id,re).then(pe=>Y(pe.images))},se.readAsDataURL(J)}},[e.id]),Ge=S.useCallback(X=>{var ae;const me=(ae=X.clipboardData)==null?void 0:ae.items;if(!me)return;const re=[];for(let J=0;J<me.length;J++)if(me[J].type.startsWith("image/")){const se=me[J].getAsFile();se&&re.push(se)}re.length!==0&&(X.preventDefault(),Ce(re))},[Ce]),Ze=S.useCallback(X=>{var me;X.preventDefault(),X.stopPropagation(),(me=X.dataTransfer)!=null&&me.files&&Ce(X.dataTransfer.files)},[Ce]),be=S.useCallback(X=>{A1(e.id,X).then(()=>{Y(me=>me.filter(re=>re.id!==X))})},[e.id]),Be=S.useCallback(()=>{if(!_.current)return;const X=_.current.getBoundingClientRect(),me=window.innerWidth,re=window.innerHeight;let ae=X.bottom+4;const J=w.current;if(J){const se=J.offsetWidth,pe=J.offsetHeight;let we=X.right-se;we<8&&(we=8),we+se>me-8&&(we=me-8-se),ae+pe>re-8&&(ae=X.top-pe-4),E({top:ae,left:we}),x(!0)}else E({top:ae,left:Math.max(8,X.right-180)})},[]);return S.useEffect(()=>{if(!d){x(!1);return}Be();const X=requestAnimationFrame(Be),me=re=>{var J,se;const ae=re.target;(J=_.current)!=null&&J.contains(ae)||(se=w.current)!=null&&se.contains(ae)||g(!1)};return document.addEventListener("mousedown",me),window.addEventListener("scroll",Be,!0),window.addEventListener("resize",Be),()=>{cancelAnimationFrame(X),document.removeEventListener("mousedown",me),window.removeEventListener("scroll",Be,!0),window.removeEventListener("resize",Be)}},[d,Be]),t.jsxs("div",{className:`${ye?"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(!b),children:[t.jsx(Es,{size:14,className:`text-warm-400 transition-transform duration-200 flex-shrink-0 ${b?"rotate-90":""}`,onClick:X=>{X.stopPropagation(),C(!b)}}),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}),ye&&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(Un,{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(BE,{size:12}),h("planner.fromDiscussion")]})]}),t.jsxs("div",{className:"hidden sm:flex items-center gap-1 w-[160px] flex-shrink-0 overflow-hidden",children:[te.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(qa,{size:12}),te.length]}),de.map(X=>t.jsx("span",{className:`px-2 py-0.5 rounded-md text-2xs font-medium whitespace-nowrap ${Wa(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 ${((ne=Qy[e.priority])==null?void 0:ne.style)??"text-warm-300"}`,children:((_e=Qy[e.priority])==null?void 0:_e.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 ${le?"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 ${Ou[e.status]||Ou.pending}`,children:h(`plannerStatus.${e.status}`)})}),t.jsxs("div",{className:"w-8 flex-shrink-0",children:[t.jsx("button",{ref:_,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(np,{size:14})}),d&&rn.createPortal(t.jsxs("div",{ref:w,className:"fixed z-tooltip min-w-[160px] rounded-xl py-1 shadow-elevated",style:{top:y.top,left:y.left,opacity:k?1:0,backgroundColor:"var(--color-bg-card)",border:"1px solid var(--color-border)"},onClick:()=>g(!1),children:[!ye&&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(Uw,{size:12})," ",h("planner.convertToTask")]}),t.jsxs("button",{onClick:p,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(Wi,{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(pi,{size:12})," ",h("planner.convertToTerminal")]})]}),t.jsxs("button",{onClick:async()=>{await m({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(An,{size:12})," ",h("planner.delete")]})]}),document.body)]})]}),b&&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=>j(X.target.value),onBlur:Re,onKeyDown:X=>{X.key==="Enter"&&(X.preventDefault(),Re(),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:T,onChange:X=>N(X.target.value),onPaste:Ge,onDrop:Ze,onDragOver:X=>{X.preventDefault(),X.stopPropagation()},onBlur:ve}),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=he.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(qa,{size:12}),h("plannerForm.addImage")]}),t.jsx("span",{className:"text-[10px] text-warm-300",children:h("plannerForm.pasteHint")})]}),t.jsx("input",{ref:he,type:"file",accept:"image/*",multiple:!0,className:"hidden",onChange:X=>{X.target.files&&Ce(X.target.files),X.target.value=""}}),te.length>0&&t.jsx("div",{className:"flex flex-wrap gap-2",children:te.map(X=>t.jsxs("div",{className:"relative group",children:[t.jsx("img",{src:ku(e.id,X.id),alt:X.originalName,onClick:()=>oe(ku(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:()=>be(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(Xt,{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:[P.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 ${Wa(s.get(X)||"default")}`,onClick:me=>{Z.current=me.currentTarget,V(U===X?null:X)},children:[X,t.jsx("button",{onClick:me=>{me.stopPropagation(),fe(X)},className:"opacity-60 hover:opacity-100",children:t.jsx(Xt,{size:12})})]}),U===X&&t.jsxs(qm,{anchorRef:Z,width:180,onClose:()=>V(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:CO.map(me=>t.jsx("button",{onClick:async()=>{c&&await c(X,{color:me}),V(null)},className:`aspect-square rounded-md flex items-center justify-center transition-all ${s.get(X)===me?"ring-2 ring-accent ring-offset-1":"hover:scale-110"}`,title:h(`plannerTag.color.${me}`),children:t.jsx("div",{className:`w-5 h-5 rounded-md ${zu[me].swatch}`})},me))})]})]},X)),t.jsxs("div",{className:"relative",children:[t.jsx("input",{ref:ee,className:"bg-transparent text-xs outline-none w-24",style:{color:"var(--color-text-primary)"},placeholder:"+",value:W,onChange:X=>{G(X.target.value),z(!0)},onKeyDown:X=>{(X.key==="Enter"||X.key===",")&&W.trim()&&(X.preventDefault(),ke(W.replace(",",""))),X.key==="Backspace"&&!W&&P.length>0&&fe(P[P.length-1])},onFocus:()=>z(!0),onBlur:()=>setTimeout(()=>z(!1),150)}),I&&Te.length>0&&t.jsx(qm,{anchorRef:ee,width:160,onClose:()=>z(!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:Te.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 ${Wa(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:D,onChange:X=>Me(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:B,onChange:X=>Oe(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:F,onChange:X=>tt(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")})]})]})]})]})}),q&&t.jsx(Up,{src:q,onClose:()=>oe(null)})]})}let EO=0;function NO({existingTags:e,editItem:s,initialDueDate:i,onSave:a,onCancel:u,onUpdateTag:f}){const{t:p}=ft(),[o,c]=S.useState(""),[h,m]=S.useState(""),[d,g]=S.useState([]),[b,C]=S.useState(""),[k,x]=S.useState(i??""),[_,w]=S.useState(0),[y,E]=S.useState("pending"),[R,j]=S.useState(!1),[T,N]=S.useState(!1),[D,A]=S.useState([]),[B,O]=S.useState([]),[F,$]=S.useState(null),P=S.useRef(null),H=S.useRef(null),W=S.useRef(null),[G,I]=S.useState(new Map),z=new Map([...e.map(le=>[le.name,le.color]),...G]),U=["blue","green","orange","purple","pink","red","yellow","brown"];S.useEffect(()=>{var le;if(s){c(s.title),m(s.description??""),g(s.tags?JSON.parse(s.tags):[]),x(s.due_date??""),w(s.priority),E(s.status);try{O(s.images?JSON.parse(s.images):[])}catch{O([])}}(le=P.current)==null||le.focus()},[s]);const V=e.filter(le=>!d.includes(le.name)&&(!b||le.name.toLowerCase().includes(b.toLowerCase()))),q=le=>{var Re;const De=le.trim();De&&!d.includes(De)&&g(ve=>{const Me=[...ve,De];if(!z.has(De)){const Oe=U[z.size%U.length];I(tt=>new Map([...tt,[De,Oe]]))}return Me}),C(""),N(!0),(Re=H.current)==null||Re.focus()},oe=le=>g(d.filter(De=>De!==le)),ee=S.useCallback(le=>{const De=Array.from(le).filter(Re=>Re.type.startsWith("image/"));for(const Re of De){const ve=new FileReader;ve.onload=()=>{const Me=ve.result,Oe=`pending-${++EO}`;A(tt=>[...tt,{id:Oe,name:Re.name,data:Me,preview:Me}])},ve.readAsDataURL(Re)}},[]),Z=S.useCallback(le=>{var ve;const De=(ve=le.clipboardData)==null?void 0:ve.items;if(!De)return;const Re=[];for(let Me=0;Me<De.length;Me++)if(De[Me].type.startsWith("image/")){const Oe=De[Me].getAsFile();Oe&&Re.push(Oe)}Re.length!==0&&(le.preventDefault(),ee(Re))},[ee]),te=S.useCallback(le=>{var De;le.preventDefault(),le.stopPropagation(),(De=le.dataTransfer)!=null&&De.files&&ee(le.dataTransfer.files)},[ee]),Y=le=>A(De=>De.filter(Re=>Re.id!==le)),he=le=>{s&&A1(s.id,le),O(De=>De.filter(Re=>Re.id!==le))},de=B.length+D.length,ye=async()=>{if(o.trim()){j(!0);try{const le=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?{status:y}:{}});if(f&&G.size>0&&await Promise.all([...G.entries()].map(([De,Re])=>f(De,{color:Re}))),D.length>0){const De=(s==null?void 0:s.id)??(le==null?void 0:le.id);De&&await M1(De,D.map(Re=>({name:Re.name,data:Re.data})))}}finally{j(!1)}}};return t.jsxs("div",{className:"card p-5",style:{borderColor:"var(--color-accent)",borderWidth:"1px"},children:[t.jsx("input",{ref:P,className:"input-field text-sm w-full mb-3",placeholder:p("plannerForm.titlePlaceholder"),value:o,onChange:le=>c(le.target.value),onKeyDown:le=>{le.key==="Enter"&&le.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:p("plannerForm.descPlaceholder"),value:h,onChange:le=>m(le.target.value),onPaste:Z,onDrop:te,onDragOver:le=>{le.preventDefault(),le.stopPropagation()}}),t.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[t.jsxs("button",{type:"button",onClick:()=>{var le;return(le=W.current)==null?void 0:le.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(qa,{size:14}),p("plannerForm.addImage")]}),t.jsx("span",{className:"text-[10px] text-warm-300",children:p("plannerForm.pasteHint")})]}),t.jsx("input",{ref:W,type:"file",accept:"image/*",multiple:!0,className:"hidden",onChange:le=>{le.target.files&&ee(le.target.files),le.target.value=""}}),de>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:p("plannerForm.images")}),t.jsxs("span",{className:"text-[10px] text-warm-400",children:["(",de,")"]})]}),t.jsxs("div",{className:"flex flex-wrap gap-2",children:[B.map(le=>t.jsxs("div",{className:"relative group",children:[t.jsx("img",{src:s?ku(s.id,le.id):"",alt:le.originalName,onClick:()=>s&&$(ku(s.id,le.id)),className:"h-20 w-20 object-cover rounded-lg border border-warm-200 cursor-zoom-in"}),t.jsx("button",{type:"button",onClick:()=>he(le.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(Xt,{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:le.originalName})})]},le.id)),D.map(le=>t.jsxs("div",{className:"relative group",children:[t.jsx("img",{src:le.preview,alt:le.name,onClick:()=>$(le.preview),className:"h-20 w-20 object-cover rounded-lg border border-accent/30 cursor-zoom-in"}),t.jsx("button",{type:"button",onClick:()=>Y(le.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(Xt,{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:le.name})})]},le.id))]})]}),t.jsxs("div",{className:"mb-4",children:[t.jsx("label",{className:"text-xs font-medium text-warm-500 mb-1.5 block",children:p("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(le=>t.jsxs("span",{className:`inline-flex items-center gap-1 px-2 py-0.5 rounded-md text-[11px] font-medium ${Wa(z.get(le)||"default")}`,children:[le,t.jsx("button",{onClick:()=>oe(le),className:"opacity-60 hover:opacity-100",children:t.jsx(Xt,{size:12})})]},le)),t.jsxs("div",{className:"relative flex-1 min-w-[120px]",children:[t.jsx("input",{ref:H,className:"bg-transparent text-sm outline-none w-full",style:{color:"var(--color-text-primary)"},placeholder:d.length===0?p("plannerForm.tagsPlaceholder"):"",value:b,onChange:le=>{C(le.target.value),N(!0)},onKeyDown:le=>{(le.key==="Enter"||le.key===",")&&b.trim()&&(le.preventDefault(),q(b.replace(",",""))),le.key==="Backspace"&&!b&&d.length>0&&oe(d[d.length-1])},onFocus:()=>N(!0),onBlur:()=>setTimeout(()=>N(!1),150)}),T&&(V.length>0||b.trim())&&t.jsxs(qm,{anchorRef:H,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:[V.slice(0,10).map(le=>t.jsx("button",{className:"flex items-center w-full px-2.5 py-1 hover:bg-warm-100/50 transition-colors text-left",onMouseDown:()=>q(le.name),children:t.jsx("span",{className:`px-2 py-0.5 rounded-md text-[11px] font-medium ${Wa(le.color)}`,children:le.name})},le.name)),b.trim()&&!e.some(le=>le.name===b.trim())&&t.jsx("button",{className:"flex items-center w-full px-2.5 py-1 hover:bg-warm-100/50 transition-colors text-left",onMouseDown:()=>q(b),children:t.jsxs("span",{className:"text-xs text-warm-500",children:['+ "',b.trim(),'"']})})]})]})]})]}),t.jsxs("div",{className:`grid gap-3 mb-4 ${s?"grid-cols-3":"grid-cols-2"}`,children:[t.jsxs("div",{children:[t.jsx("label",{className:"text-xs font-medium text-warm-500 mb-1.5 block",children:p("plannerForm.dueDate")}),t.jsx("input",{type:"date",className:"input-field text-xs w-full",value:k,onChange:le=>x(le.target.value)})]}),t.jsxs("div",{children:[t.jsx("label",{className:"text-xs font-medium text-warm-500 mb-1.5 block",children:p("plannerForm.priority")}),t.jsxs("select",{className:"input-field text-xs w-full",value:_,onChange:le=>w(Number(le.target.value)),children:[t.jsx("option",{value:0,children:p("plannerForm.priorityLow")}),t.jsx("option",{value:1,children:p("plannerForm.priorityNormal")}),t.jsx("option",{value:2,children:p("plannerForm.priorityHigh")}),t.jsx("option",{value:3,children:p("plannerForm.priorityCritical")})]})]}),s&&t.jsxs("div",{children:[t.jsx("label",{className:"text-xs font-medium text-warm-500 mb-1.5 block",children:p("plannerForm.status")}),t.jsxs("select",{className:"input-field text-xs w-full",value:y,onChange:le=>E(le.target.value),children:[t.jsx("option",{value:"pending",children:p("plannerStatus.pending")}),t.jsx("option",{value:"in_progress",children:p("plannerStatus.in_progress")}),t.jsx("option",{value:"done",children:p("plannerStatus.done")})]})]})]}),t.jsxs("div",{className:"flex justify-end gap-3",children:[t.jsx("button",{className:"btn-ghost text-xs",onClick:u,children:p("plannerForm.cancel")}),t.jsx("button",{className:"btn-primary text-xs py-2",onClick:ye,disabled:!o.trim()||R,children:p("plannerForm.save")})]}),F&&t.jsx(Up,{src:F,onClose:()=>$(null)})]})}function jS({item:e,mode:s,projectCliTool:i,onConvert:a,onClose:u}){const{t:f}=ft(),[p,o]=S.useState(i||"claude"),[c,h]=S.useState(""),[m,d]=S.useState(!1),[g,b]=S.useState("once"),[C,k]=S.useState("0 0 * * *"),[x,_]=S.useState(""),[w,y]=S.useState(!1),E=async()=>{y(!0);try{s==="todo"?await a({cli_tool:p,max_turns:c?Number(c):void 0}):s==="session"?await a({cli_tool:p,use_worktree:m}):await a({cli_tool:p,schedule_type:g,cron_expression:g==="recurring"?C:void 0,run_at:g==="once"?x:void 0})}finally{y(!1)}};return t.jsx(jn,{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:p,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:c,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:m,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:()=>b("once"),children:f("plannerConvert.once")}),t.jsx("button",{className:`flex-1 px-3 py-1.5 rounded-md text-xs font-medium transition-all ${g==="recurring"?"bg-accent text-white":"text-warm-500"}`,onClick:()=>b("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=>_(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:E,disabled:w||s==="schedule"&&g==="once"&&!x,children:f("plannerConvert.convert")})]})]})})}function xn(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 Zy(e){return xn(new Date(e))}function ew(e){return new Date(e.getFullYear(),e.getMonth(),1)}function ES(e){return new Date(e.getFullYear(),e.getMonth(),e.getDate())}function nr(e,s){const i=ES(e);return i.setDate(i.getDate()+s),i}function NS(e){return nr(e,-e.getDay())}function LO(e,s){return Math.round((new Date(s+"T00:00").getTime()-new Date(e+"T00:00").getTime())/864e5)}function DO(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=LO(a,i),f=p=>xn(nr(new Date(p+"T00:00"),u));return{startKey:f(s.startKey),endKey:f(s.endKey)}}function TO(e,s){if(e==="day"){const f=ES(s);return{rangeStart:xn(f),rangeEnd:xn(nr(f,1)),gridDays:[f],cols:1,dimOutOfMonth:!1}}if(e==="week"){const f=NS(s),p=Array.from({length:7},(o,c)=>nr(f,c));return{rangeStart:xn(f),rangeEnd:xn(nr(f,7)),gridDays:p,cols:7,dimOutOfMonth:!1}}if(e==="table"){const f=ew(s),p=new Date(s.getFullYear(),s.getMonth()+1,1);return{rangeStart:xn(f),rangeEnd:xn(p),gridDays:[],cols:7,dimOutOfMonth:!1}}const i=ew(s),a=nr(i,-i.getDay()),u=Array.from({length:42},(f,p)=>nr(a,p));return{rangeStart:xn(a),rangeEnd:xn(nr(a,42)),gridDays:u,cols:7,dimOutOfMonth:!0}}function LS(e,s){return S.useMemo(()=>TO(e,s),[e,s])}function DS(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 TS(e,s,i){if(s==="month"||s==="table")return e.toLocaleDateString(i,{year:"numeric",month:"long"});if(s==="week"){const a=NS(e);return`${a.toLocaleDateString(i,{month:"short",day:"numeric"})} – ${nr(a,6).toLocaleDateString(i,{month:"short",day:"numeric"})}`}return e.toLocaleDateString(i,{year:"numeric",month:"long",day:"numeric",weekday:"short"})}function RS(){const{lang:e}=ft();return S.useMemo(()=>{const s=new Date(2024,5,2);return Array.from({length:7},(i,a)=>nr(s,a).toLocaleDateString(e,{weekday:"short"}))},[e])}const RO=420,MO=140,AO=220,zO=26,Jf=16,tw=2;function OO(e,s){if(!s.length)return{placed:[],laneCount:0};const i=xn(e[0]),a=xn(e[e.length-1]),u=s.filter(o=>o.startKey<=a&&o.endKey>=i).map(o=>{const c=o.startKey<i?i:o.startKey,h=o.endKey>a?a:o.endKey;return{bar:o,startCol:e.findIndex(m=>xn(m)===c),endCol:e.findIndex(m=>xn(m)===h),contStart:o.startKey<i,contEnd:o.endKey>a}}).filter(o=>o.startCol>=0&&o.endCol>=0).sort((o,c)=>o.startCol-c.startCol||c.endCol-c.startCol-(o.endCol-o.startCol)),f=[];return{placed:u.map(o=>{let c=0;for(;c<f.length&&f[c]>=o.startCol;)c++;return f[c]=o.endCol,{...o,lane:c}}),laneCount:f.length}}function MS({view:e,gridDays:s,cols:i,dimOutOfMonth:a,monthIdx:u,todayKey:f,selectedDate:p,chipsByDay:o,maxChips:c,weekdayLabels:h,addItemLabel:m,bars:d,onBarClick:g,onSelectDate:b,onQuickAdd:C,onChipClick:k,onCellContextMenu:x,onChipContextMenu:_,onBarContextMenu:w,onBarDrag:y,onChipDrag:E,monthCellHeight:R=92}){const{lang:j}=ft(),[T,N]=S.useState(null),[D,A]=S.useState(!1),B=S.useRef(null),O=S.useRef(null),F=()=>{O.current&&(clearTimeout(O.current),O.current=null)},$=(Z,te)=>{F(),B.current&&clearTimeout(B.current);const Y=te.getBoundingClientRect();B.current=window.setTimeout(()=>N({key:Z,rect:Y}),RO)},P=()=>{B.current&&(clearTimeout(B.current),B.current=null),O.current=window.setTimeout(()=>N(null),MO)};S.useEffect(()=>{if(!T){A(!1);return}const Z=requestAnimationFrame(()=>A(!0));return()=>cancelAnimationFrame(Z)},[T]),S.useEffect(()=>()=>{B.current&&clearTimeout(B.current),O.current&&clearTimeout(O.current)},[]),S.useEffect(()=>{if(!T)return;const Z=()=>N(null);return window.addEventListener("scroll",Z,!0),window.addEventListener("resize",Z),()=>{window.removeEventListener("scroll",Z,!0),window.removeEventListener("resize",Z)}},[T]);const H=T?o.get(T.key)??[]:[],[W,G]=S.useState(null),I=S.useRef(!1),z=4,U=(Z,te)=>{var Y,he;return((he=(Y=document.elementFromPoint(Z,te))==null?void 0:Y.closest("[data-daykey]"))==null?void 0:he.getAttribute("data-daykey"))??null},V=(Z,te,Y)=>{Z.preventDefault(),Z.stopPropagation();const he=U(Z.clientX,Z.clientY)??Y.origStart,de=Z.clientX,ye=Z.clientY,le=te!=="move";let De=le,Re={startKey:Y.origStart,endKey:Y.origEnd};const ve=()=>G({kind:Y.kind,entryKey:Y.entryKey,curStart:Re.startKey,curEnd:Re.endKey,title:Y.title,bg:Y.bg,fg:Y.fg,done:Y.done}),Me=()=>{document.body.style.cursor=le?"ew-resize":"grabbing",document.body.style.userSelect="none"};le&&(Me(),ve());const Oe=nt=>{if(!De){if(Math.abs(nt.clientX-de)<z&&Math.abs(nt.clientY-ye)<z)return;De=!0,Me()}const ke=U(nt.clientX,nt.clientY);ke&&(Re=DO(te,{startKey:Y.origStart,endKey:Y.origEnd},ke,he),ve())},tt=()=>{window.removeEventListener("pointermove",Oe),window.removeEventListener("pointerup",tt),document.body.style.cursor="",document.body.style.userSelect="",G(null),De&&(I.current=!0,setTimeout(()=>{I.current=!1},0),!(Re.startKey===Y.origStart&&Re.endKey===Y.origEnd)&&(Y.kind==="bar"&&Y.bar?y==null||y(Y.bar,Re.startKey,Re.endKey):Y.kind==="chip"&&Y.chip&&(E==null||E(Y.chip,Re.startKey,Re.endKey))))};window.addEventListener("pointermove",Oe),window.addEventListener("pointerup",tt)},q=(()=>{const Z=d??[];return W?W.kind==="bar"?Z.map(te=>te.key===W.entryKey?{...te,startKey:W.curStart,endKey:W.curEnd}:te):[...Z,{key:`__drag__${W.entryKey}`,title:W.title,startKey:W.curStart,endKey:W.curEnd,bg:W.bg,fg:W.fg,done:W.done}]:Z})(),oe=(Z,te)=>{const Y=xn(Z),he=o.get(Y)??[],de=!a||Z.getMonth()===u,ye=Y===f,le=Y===p,De=e==="week"?"min-h-[360px]":e==="day"?"min-h-[480px]":"",Re=e==="month"&&he.length>c;return t.jsxs("div",{"data-daykey":Y,onClick:()=>{I.current||b(Y)},onContextMenu:x?ve=>x(Y,ve):void 0,onMouseEnter:Re?ve=>$(Y,ve.currentTarget):void 0,onMouseLeave:Re?P:void 0,className:`group relative ${De} text-left p-1.5 flex flex-col gap-1 transition-colors cursor-pointer`,style:{minHeight:e==="month"?R+te:void 0,backgroundColor:le?"var(--color-bg-hover)":"var(--color-bg-card)",opacity:de?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(j,{weekday:"short"})}),t.jsx("span",{className:"text-xs font-medium w-5 h-5 flex items-center justify-center rounded-full",style:ye?{backgroundColor:"var(--color-accent)",color:"#fff"}:{color:"var(--color-text-secondary)"},children:Z.getDate()})]}),t.jsx("button",{onClick:ve=>{ve.stopPropagation(),C(Y)},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:m,style:{backgroundColor:"var(--color-bg-secondary)",color:"var(--color-text-secondary)",border:"1px solid var(--color-border)"},children:t.jsx(yn,{size:14})}),t.jsxs("div",{className:"flex flex-col gap-0.5 overflow-hidden",style:{marginTop:te||void 0},children:[he.slice(0,c).map(ve=>{if((W==null?void 0:W.kind)==="chip"&&W.entryKey===ve.key)return null;const Me=e==="month"&&!!(ve.draggable&&E),Oe={kind:"chip",entryKey:ve.key,origStart:Y,origEnd:Y,title:ve.title,bg:ve.bg,fg:ve.fg,done:ve.done,chip:ve};return t.jsxs("span",{onClick:tt=>{tt.stopPropagation(),!I.current&&k(ve)},onPointerDown:Me?tt=>V(tt,"move",Oe):void 0,onContextMenu:_?tt=>_(ve,tt):void 0,className:`text-2xs truncate px-1 py-0.5 rounded-md cursor-pointer hover:opacity-80 transition-opacity ${Me?"relative group/chip":""}`,style:{backgroundColor:ve.bg,color:ve.fg,textDecoration:ve.done?"line-through":"none"},title:ve.title,children:[ve.prefix??"",ve.time?`${ve.time} `:"",ve.title,Me&&t.jsx("span",{onPointerDown:tt=>{tt.stopPropagation(),V(tt,"resize-end",Oe)},onClick:tt=>tt.stopPropagation(),className:"absolute top-0 right-0 h-full w-1.5 opacity-0 group-hover/chip:opacity-100 cursor-ew-resize rounded-r-md",style:{backgroundColor:"rgba(127,127,127,0.5)"}})]},ve.key)}),he.length>c&&t.jsxs("span",{className:"text-2xs px-1",style:{color:"var(--color-text-muted)"},children:["+",he.length-c]})]})]},Y)},ee=[];if(e==="month")for(let Z=0;Z<s.length;Z+=i)ee.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:ee.map((Z,te)=>{const{placed:Y,laneCount:he}=OO(Z,q),de=he*(Jf+tw);return t.jsxs("div",{className:"relative grid gap-px",style:{gridTemplateColumns:`repeat(${i}, minmax(0, 1fr))`,backgroundColor:"var(--color-border)"},children:[Z.map(ye=>oe(ye,de)),Y.map(({bar:ye,startCol:le,endCol:De,lane:Re,contStart:ve,contEnd:Me})=>{const Oe=!!y&&!ye.key.startsWith("__drag__"),tt={kind:"bar",entryKey:ye.key,origStart:ye.startKey,origEnd:ye.endKey,title:ye.title,bg:ye.bg,fg:ye.fg,done:ye.done,bar:ye};return t.jsxs("div",{onClick:nt=>{nt.stopPropagation(),!I.current&&(g==null||g(ye))},onPointerDown:Oe?nt=>V(nt,"move",tt):void 0,onContextMenu:w?nt=>w(ye,nt):void 0,className:"absolute text-2xs truncate px-1.5 cursor-pointer hover:opacity-80 transition-opacity flex items-center",style:{pointerEvents:W?"none":void 0,left:`calc(${le} / ${i} * 100% + 2px)`,width:`calc(${De-le+1} / ${i} * 100% - 4px)`,top:zO+Re*(Jf+tw),height:Jf,backgroundColor:ye.bg,color:ye.fg,textDecoration:ye.done?"line-through":"none",borderRadius:4,borderTopLeftRadius:ve?0:4,borderBottomLeftRadius:ve?0:4,borderTopRightRadius:Me?0:4,borderBottomRightRadius:Me?0:4},title:ye.title,children:[ve?"◀ ":"",ye.title,Me?" ▶":"",Oe&&!ve&&t.jsx("span",{onPointerDown:nt=>{nt.stopPropagation(),V(nt,"resize-start",tt)},onClick:nt=>nt.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)"}}),Oe&&!Me&&t.jsx("span",{onPointerDown:nt=>{nt.stopPropagation(),V(nt,"resize-end",tt)},onClick:nt=>nt.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)"}})]},ye.key)})]},te)})}):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=>oe(Z,0))}),T&&(()=>{const Z=Math.max(T.rect.width,AO),te=Math.min(Math.max(8,T.rect.left),window.innerWidth-Z-8),Y=Math.max(8,Math.min(T.rect.top,window.innerHeight-120)),he=window.innerHeight-Y-16,de=Number(T.key.slice(8,10));return rn.createPortal(t.jsxs("div",{className:"z-tooltip rounded-lg shadow-elevated",onMouseEnter:F,onMouseLeave:()=>N(null),style:{position:"fixed",left:te,top:Y,width:Z,maxHeight:he,overflowY:"auto",backgroundColor:"var(--color-bg-card)",border:"1px solid var(--color-border)",padding:6,transformOrigin:"top left",transform:D?"scale(1)":"scale(0.96)",opacity:D?1:0,transition:"transform 140ms ease, opacity 140ms ease"},children:[t.jsx("div",{className:"text-xs font-semibold px-1 pb-1",style:{color:"var(--color-text-secondary)"},children:de}),t.jsx("div",{className:"flex flex-col gap-0.5",children:H.map(ye=>t.jsxs("span",{onClick:le=>{le.stopPropagation(),k(ye),N(null)},onContextMenu:_?le=>_(ye,le):void 0,className:"text-2xs truncate px-1 py-0.5 rounded-md cursor-pointer hover:opacity-80 transition-opacity",style:{backgroundColor:ye.bg,color:ye.fg,textDecoration:ye.done?"line-through":"none"},title:ye.title,children:[ye.prefix??"",ye.time?`${ye.time} `:"",ye.title]},ye.key))})]}),document.body)})()]})}function BO(e){if(!e)return[];try{const s=JSON.parse(e);return Array.isArray(s)?s.filter(i=>typeof i=="string"):[]}catch{return[]}}function PO({view:e,items:s,tagColors:i,onQuickAdd:a,onEditItem:u,onConvert:f,onDeleteItem:p,onUpdateRange:o}){const{t:c,lang:h}=ft(),[m,d]=S.useState(()=>new Date),[g,b]=S.useState(()=>xn(new Date)),[C,k]=S.useState(null),x=RS(),{gridDays:_,cols:w,dimOutOfMonth:y}=LS(e,m),E=xn(new Date),R=m.getMonth(),j=e==="month"?3:99,T=ee=>d(Z=>DS(Z,e,ee)),N=()=>{d(new Date),b(xn(new Date))},D=TS(m,e,h);S.useEffect(()=>{e==="day"&&b(xn(m))},[e,m]);const A=260,B=760,O=S.useRef(null),[F,$]=S.useState(()=>{const ee=parseInt(localStorage.getItem("plannerCalendarPanelWidth")||"",10);return Number.isFinite(ee)&&ee>=A&&ee<=B?ee:320});S.useEffect(()=>{try{localStorage.setItem("plannerCalendarPanelWidth",String(F))}catch{}},[F]);const P=ee=>{ee.preventDefault();const Z=Y=>{var de;const he=(de=O.current)==null?void 0:de.getBoundingClientRect();he&&$(Math.min(B,Math.max(A,he.right-Y.clientX)))},te=()=>{window.removeEventListener("pointermove",Z),window.removeEventListener("pointerup",te),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",te)},[H,W]=S.useState(new Map);S.useEffect(()=>{W(new Map)},[s]);const G=S.useMemo(()=>H.size===0?s:s.map(ee=>{const Z=H.get(ee.id);return Z?{...ee,due_date:Z.due_date,end_date:Z.end_date}:ee}),[s,H]),I=S.useCallback((ee,Z,te)=>{W(Y=>new Map(Y).set(ee,{due_date:Z,end_date:te})),o(ee,Z,te)},[o]),z=ee=>!!(ee.due_date&&ee.end_date&&ee.end_date.slice(0,10)>ee.due_date.slice(0,10)),U=S.useMemo(()=>{const ee=new Map;for(const Z of G){if(!Z.due_date||e==="month"&&z(Z))continue;const te=Z.due_date.slice(0,10),Y=Z.status==="done",he=ee.get(te)??[];he.push({key:Z.id,title:Z.title,bg:"var(--color-bg-secondary)",fg:Y?"var(--color-text-muted)":"var(--color-text-secondary)",done:Y,payload:Z,draggable:!0}),ee.set(te,he)}return ee},[G,e]),V=S.useMemo(()=>e!=="month"?[]:G.filter(z).map(ee=>{const Z=ee.status==="done";return{key:ee.id,title:ee.title,startKey:ee.due_date.slice(0,10),endKey:ee.end_date.slice(0,10),bg:"var(--color-bg-secondary)",fg:Z?"var(--color-text-muted)":"var(--color-text-secondary)",done:Z,payload:ee}}),[G,e]),q=S.useMemo(()=>s.filter(ee=>ee.due_date&&ee.due_date.slice(0,10)===g),[s,g]),oe=S.useMemo(()=>s.filter(ee=>!ee.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:()=>T(-1),className:"btn-ghost p-1.5","aria-label":"prev",children:t.jsx(tp,{size:16})}),t.jsx("div",{className:"text-sm font-semibold min-w-[8rem] text-center",style:{color:"var(--color-text-primary)"},children:D}),t.jsx("button",{onClick:()=>T(1),className:"btn-ghost p-1.5","aria-label":"next",children:t.jsx(Es,{size:16})}),t.jsx("button",{onClick:N,className:"btn-ghost text-xs px-2.5 py-1.5",children:c("agenda.today")})]}),t.jsx("div",{className:"flex-1 overflow-auto px-4 pb-4",children:t.jsx(MS,{view:e,gridDays:_,cols:w,dimOutOfMonth:y,monthIdx:R,todayKey:E,selectedDate:g,chipsByDay:U,maxChips:j,weekdayLabels:x,addItemLabel:c("agenda.addItem"),onSelectDate:b,onQuickAdd:a,onChipClick:ee=>u(ee.payload),onCellContextMenu:(ee,Z)=>{Z.preventDefault(),k({x:Z.clientX,y:Z.clientY,dateKey:ee})},bars:V,onBarClick:ee=>u(ee.payload),onBarDrag:(ee,Z,te)=>I(ee.payload.id,Z,te),onChipDrag:(ee,Z,te)=>I(ee.payload.id,Z,te)})})]}),t.jsx("div",{onPointerDown:P,className:"w-1.5 flex-shrink-0 cursor-col-resize hover:bg-accent/40 transition-colors",style:{backgroundColor:"var(--color-border)"},title:c("agenda.resizePanel")}),t.jsxs("div",{className:"flex-shrink-0 flex flex-col overflow-hidden",style:{width:F},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(yn,{size:14}),c("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:[q.length===0&&t.jsx("p",{className:"text-xs py-2",style:{color:"var(--color-text-muted)"},children:c("agenda.dayEmpty")}),q.map(ee=>t.jsx(nw,{item:ee,tagColors:i,onEdit:u,onConvert:f,onDelete:p},ee.id))]}),t.jsxs("div",{children:[t.jsx("h4",{className:"text-2xs uppercase tracking-wider mb-1.5",style:{color:"var(--color-text-muted)"},children:c("agenda.backlog")}),t.jsxs("div",{className:"flex flex-col gap-1.5",children:[oe.length===0&&t.jsx("p",{className:"text-xs py-1",style:{color:"var(--color-text-muted)"},children:c("agenda.backlogEmpty")}),oe.map(ee=>t.jsx(nw,{item:ee,tagColors:i,onEdit:u,onConvert:f,onDelete:p},ee.id))]})]})]})]}),C&&t.jsx(ir,{x:C.x,y:C.y,onClose:()=>k(null),children:t.jsxs("button",{type:"button",className:sn,onClick:()=>a(C.dateKey),children:[t.jsx(yn,{size:14}),c("planner.add")]})})]})}function nw({item:e,tagColors:s,onEdit:i,onConvert:a,onDelete:u}){const{t:f}=ft(),{confirm:p}=qn(),[o,c]=S.useState(!1),[h,m]=S.useState(!1),[d,g]=S.useState({top:0,left:0}),b=S.useRef(null),C=S.useRef(null),k=BO(e.tags),x=e.status==="moved",_=S.useCallback(()=>{if(!b.current)return;const w=b.current.getBoundingClientRect(),y=window.innerWidth,E=window.innerHeight;let R=w.bottom+4;const j=C.current;if(j){const T=j.offsetWidth,N=j.offsetHeight;let D=w.right-T;D<8&&(D=8),D+T>y-8&&(D=y-8-T),R+N>E-8&&(R=w.top-N-4),g({top:R,left:D}),m(!0)}else g({top:R,left:Math.max(8,w.right-180)})},[]);return S.useEffect(()=>{if(!o){m(!1);return}_();const w=requestAnimationFrame(_),y=E=>{var j,T;const R=E.target;(j=b.current)!=null&&j.contains(R)||(T=C.current)!=null&&T.contains(R)||c(!1)};return document.addEventListener("mousedown",y),window.addEventListener("scroll",_,!0),window.addEventListener("resize",_),()=>{cancelAnimationFrame(w),document.removeEventListener("mousedown",y),window.removeEventListener("scroll",_,!0),window.removeEventListener("resize",_)}},[o,_]),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 ${Ou[e.status]||Ou.pending}`,children:f(`plannerStatus.${e.status}`)}),k.map(w=>t.jsx("span",{className:`px-1.5 py-0.5 rounded-md text-2xs font-medium ${Wa(s.get(w)||"default")}`,children:w},w))]})]}),t.jsxs("div",{className:"flex-shrink-0",children:[t.jsx("button",{ref:b,onClick:w=>{w.stopPropagation(),c(!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(np,{size:14})}),o&&rn.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:()=>c(!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(Uw,{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(Wi,{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(pi,{size:12})," ",f("planner.convertToTerminal")]})]}),t.jsxs("button",{onClick:async()=>{await p({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(An,{size:12})," ",f("planner.delete")]})]}),document.body)]})]})}const sw={pending:0,in_progress:1,done:2,moved:3};function IO({plannerItems:e,existingTags:s,projectCliTool:i,onAddItem:a,onEditItem:u,onDeleteItem:f,onConvertToTodo:p,onConvertToSchedule:o,onConvertToSession:c,onUpdateTag:h,onDeleteTag:m,onExport:d,onImport:g,view:b,onChangeView:C}){const{t:k}=ft(),{warning:x}=Ls(),[_,w]=S.useState(!1),[y,E]=S.useState(null),[R,j]=S.useState(void 0),[T,N]=S.useState(""),[D,A]=S.useState(""),[B,O]=S.useState("created_at"),[F,$]=S.useState("desc"),[P,H]=S.useState(null),[W,G]=S.useState("todo"),[I,z]=S.useState(!1),[U,V]=S.useState(!1),[q,oe]=S.useState(null),ee=S.useRef(null),Z=S.useRef(0),te=async()=>{if(!(!d||I)){z(!0);try{await d()}finally{z(!1)}}},Y=()=>{var fe;!g||I||(fe=ee.current)==null||fe.click()},he=async fe=>{var Ce;const Te=(Ce=fe.target.files)==null?void 0:Ce[0];if(fe.target.value="",!(!Te||!g)){z(!0);try{await g(Te)}finally{z(!1)}}},de=fe=>!!(/\.(md|markdown)$/i.test(fe.name)||fe.type==="text/markdown"),ye=fe=>Array.from(fe.dataTransfer.types).includes("Files"),le=fe=>{!g||I||ye(fe)&&(fe.preventDefault(),Z.current++,V(!0))},De=fe=>{!g||I||ye(fe)&&(fe.preventDefault(),fe.dataTransfer.dropEffect="copy")},Re=fe=>{g&&(fe.preventDefault(),Z.current=Math.max(0,Z.current-1),Z.current===0&&V(!1))},ve=async fe=>{var Ce;if(!g||(fe.preventDefault(),Z.current=0,V(!1),I))return;const Te=(Ce=fe.dataTransfer.files)==null?void 0:Ce[0];if(Te){if(!de(Te)){x(k("planner.dropInvalidFile"));return}z(!0);try{await g(Te)}finally{z(!1)}}},Me=S.useMemo(()=>s.map(fe=>fe.name),[s]),Oe=S.useMemo(()=>new Map(s.map(fe=>[fe.name,fe.color])),[s]),tt=S.useMemo(()=>{let fe=e.filter(Te=>!(D&&Te.status!==D||T&&!(Te.tags?(()=>{try{return JSON.parse(Te.tags)}catch{return[]}})():[]).includes(T)));return fe=[...fe].sort((Te,Ce)=>{let Ge=0;switch(B){case"title":Ge=Te.title.localeCompare(Ce.title);break;case"tags":{const Ze=Te.tags?(()=>{try{return JSON.parse(Te.tags).join(",")}catch{return""}})():"",be=Ce.tags?(()=>{try{return JSON.parse(Ce.tags).join(",")}catch{return""}})():"";Ge=(Ze||"zzz").localeCompare(be||"zzz");break}case"priority":Ge=Te.priority-Ce.priority;break;case"due_date":{const Ze=Te.due_date||"9999",be=Ce.due_date||"9999";Ge=Ze.localeCompare(be);break}case"status":Ge=(sw[Te.status]??9)-(sw[Ce.status]??9);break;case"created_at":Ge=Te.created_at.localeCompare(Ce.created_at);break}return F==="asc"?Ge:-Ge}),fe},[e,T,D,B,F]),nt=fe=>{B===fe?$(Te=>Te==="asc"?"desc":"asc"):(O(fe),$(fe==="priority"?"desc":"asc"))},ke=({field:fe})=>B!==fe?null:F==="asc"?t.jsx(Zj,{size:12,className:"inline ml-0.5"}):t.jsx(Vj,{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:[b!=="table"&&t.jsx("div",{className:"flex gap-0.5 p-0.5 rounded-lg shrink-0",style:{backgroundColor:"var(--color-bg-tertiary)"},children:["month","week","day"].map(fe=>t.jsx("button",{onClick:()=>C(fe),className:"px-2.5 py-1 text-xs rounded-md transition-all",style:b===fe?{backgroundColor:"var(--color-bg-card)",color:"var(--color-text-primary)",fontWeight:600}:{color:"var(--color-text-tertiary)"},children:k(`agenda.view.${fe}`)},fe))}),t.jsxs("select",{className:"input-field text-xs py-1.5 px-2 w-auto max-w-[10rem] shrink",value:T,onChange:fe=>N(fe.target.value),children:[t.jsx("option",{value:"",children:k("planner.filterTag")}),Me.map(fe=>t.jsx("option",{value:fe,children:fe},fe))]}),t.jsxs("select",{className:"input-field text-xs py-1.5 px-2 w-auto max-w-[10rem] shrink",value:D,onChange:fe=>A(fe.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:te,disabled:I||e.length===0,className:"btn-secondary text-xs py-2 whitespace-nowrap shrink-0 disabled:opacity-50",title:k("planner.exportTooltip"),children:[t.jsx(lm,{size:14,className:"inline-block shrink-0"}),k("planner.export")]}),g&&t.jsxs(t.Fragment,{children:[t.jsxs("button",{onClick:Y,disabled:I,className:"btn-secondary text-xs py-2 whitespace-nowrap shrink-0 disabled:opacity-50",title:k("planner.importTooltip"),children:[t.jsx(Z0,{size:14,className:"inline-block shrink-0"}),k("planner.import")]}),t.jsx("input",{ref:ee,type:"file",accept:".md,.markdown,text/markdown",className:"hidden",onChange:he})]}),!_&&!y&&t.jsxs("button",{onClick:()=>w(!0),className:"btn-primary text-xs py-2 whitespace-nowrap shrink-0",children:[t.jsx(yn,{size:14,className:"inline-block shrink-0"}),k("planner.add")]})]})]}),(_||y)&&t.jsx("div",{className:"mb-5",children:t.jsx(NO,{existingTags:s,editItem:y,initialDueDate:R,onSave:async fe=>{if(y){await u(y.id,fe),E(null);return}else{const Te=await a(fe);return w(!1),j(void 0),Te}},onCancel:()=>{w(!1),E(null),j(void 0)},onUpdateTag:h})}),b==="table"?t.jsxs("div",{className:"card relative",onDragEnter:g?le:void 0,onDragOver:g?De:void 0,onDragLeave:g?Re:void 0,onDrop:g?ve:void 0,onContextMenu:fe=>{gi(fe)||(fe.preventDefault(),oe({x:fe.clientX,y:fe.clientY}))},children:[U&&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(Z0,{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:()=>nt("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:()=>nt("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:()=>nt("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:()=>nt("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:()=>nt("status"),children:[k("planner.col.status"),t.jsx(ke,{field:"status"})]}),t.jsx("div",{className:"w-8"})]}),tt.length===0?t.jsx(Yi,{icon:SE,title:k("planner.empty"),description:k("planner.emptyHint")}):tt.map((fe,Te)=>t.jsx("div",{children:t.jsx(jO,{item:fe,tagColors:Oe,existingTags:Me,onSave:async(Ce,Ge)=>{await u(Ce,Ge)},onDelete:()=>f(fe.id),onConvertToTodo:()=>{H(fe),G("todo")},onConvertToSchedule:()=>{H(fe),G("schedule")},onConvertToSession:()=>{H(fe),G("session")},onUpdateTag:h})},fe.id))]}):t.jsx(PO,{view:b,items:tt,tagColors:Oe,onQuickAdd:fe=>{E(null),j(fe),w(!0)},onEditItem:fe=>{w(!1),E(fe)},onConvert:(fe,Te)=>{H(fe),G(Te)},onDeleteItem:f,onUpdateRange:(fe,Te,Ce)=>{u(fe,{due_date:Te,end_date:Ce})}}),P&&t.jsx(jS,{item:P,mode:W,projectCliTool:i,onConvert:async fe=>{W==="todo"?await p(P.id,fe):W==="session"?await c(P.id,fe):await o(P.id,fe),H(null)},onClose:()=>H(null)}),q&&t.jsx(ir,{x:q.x,y:q.y,onClose:()=>oe(null),children:t.jsxs("button",{type:"button",className:sn,onClick:()=>{E(null),j(void 0),w(!0)},children:[t.jsx(yn,{size:14}),k("planner.add")]})})]})}const AS=S.createContext(null),FO=AS.Provider;function cP(){const e=S.useContext(AS);if(!e)throw new Error("usePlannerPage must be used within a PlannerPageProvider");return e}const HO=S.lazy(()=>Wu(()=>import("./PlannerPageEditor-xt9n6F2p.js").then(e=>e.a),__vite__mapDeps([5,3,6,7,8]))),$O=800;function UO({pageId:e,projectId:s,projectCliTool:i,existingTags:a,onTitleChange:u,onConvertToTodo:f,onConvertToSchedule:p,onConvertToSession:o}){const{t:c}=ft(),[h,m]=S.useState(null),[d,g]=S.useState("idle"),[b,C]=S.useState(null),k=S.useRef({title:"",content:null}),x=S.useRef(null);S.useEffect(()=>{let j=!1;return V4(e).then(T=>{j||(m(T),k.current={title:T.title,content:T.content??null})}),()=>{j=!0}},[e]);const _=S.useCallback(()=>{x.current&&(clearTimeout(x.current),x.current=null);const{title:j,content:T}=k.current;return g("saving"),Y4(e,{title:j,content:T??void 0}).then(()=>g("saved"))},[e]);S.useEffect(()=>()=>{x.current&&_()},[_]);const w=S.useCallback(()=>{x.current&&clearTimeout(x.current),g("saving"),x.current=setTimeout(()=>{_()},$O)},[_]),y=j=>{k.current.title=j,m(T=>T&&{...T,title:j}),u(e,j),w()},E=j=>{k.current.content=j,w()},R=S.useCallback((j,T,N)=>{C({item:j,mode:T,onDone:N})},[]);return h?t.jsxs(FO,{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:j=>y(j.target.value),placeholder:c("planner.pages.untitled"),className:"flex-1 bg-transparent text-2xl font-bold outline-none",style:{color:"var(--color-text-primary)"}}),t.jsx("span",{className:"text-2xs text-warm-400 flex-shrink-0",children:d==="saving"?c("planner.pages.saving"):d==="saved"?c("planner.pages.saved"):""})]}),t.jsx("div",{className:"flex-1 overflow-y-auto pb-6",children:t.jsx(S.Suspense,{fallback:null,children:t.jsx(HO,{pageId:e,initialContent:h.content??null,onChange:E})})})]}),b&&t.jsx(jS,{item:b.item,mode:b.mode,projectCliTool:i,onConvert:async j=>{const{item:T,mode:N,onDone:D}=b;N==="todo"?await f(T.id,j):N==="session"?await o(T.id,j):await p(T.id,j),D==null||D(),C(null)},onClose:()=>C(null)})]}):null}const Rn=(e,s)=>({type:"heading",props:{level:e},content:s}),Qo=e=>e?{type:"paragraph",content:e}:{type:"paragraph"},rw=e=>({type:"bulletListItem"}),Ii=e=>({type:"checkListItem"}),iw=()=>({type:"tasklist"}),aw=()=>({type:"calendar"}),WO=[{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:[Rn(1,"회의 노트"),Qo("날짜: "),Qo("참석자: "),Rn(2,"안건"),rw(),Rn(2,"논의"),Qo(),Rn(2,"액션 아이템"),iw()]},{id:"project",labelKey:"planner.tpl.project",descKey:"planner.tpl.project.desc",title:"프로젝트 플랜",blocks:[Rn(1,"프로젝트 플랜"),Rn(2,"개요"),Qo(),Rn(2,"마일스톤"),iw(),Rn(2,"일정"),aw(),Rn(2,"리스크 / 메모"),Qo()]},{id:"weekly",labelKey:"planner.tpl.weekly",descKey:"planner.tpl.weekly.desc",title:"위클리 플래너",blocks:[Rn(1,"위클리 플래너"),Rn(2,"이번 주 목표"),rw(),Rn(2,"요일별 할 일"),Rn(3,"월요일"),Ii(),Rn(3,"화요일"),Ii(),Rn(3,"수요일"),Ii(),Rn(3,"목요일"),Ii(),Rn(3,"금요일"),Ii(),Rn(3,"토요일"),Ii(),Rn(3,"일요일"),Ii(),Rn(2,"주간 일정"),aw()]}];function qO({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 c=u;u=null,e(c)},p=c=>{u=c.clientX,a===null&&(a=requestAnimationFrame(f))},o=c=>{a!==null&&cancelAnimationFrame(a),a=null,c.type==="pointerup"&&u!==null&&f(),u=null,document.body.style.cursor="",document.body.style.userSelect="",i.removeEventListener("pointermove",p),i.removeEventListener("pointerup",o),i.removeEventListener("pointercancel",o)};i.addEventListener("pointermove",p),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 ow=160,lw=480,cw="plannerSidebarWidth";function KO({projectId:e,...s}){const{t:i}=ft(),{confirm:a}=qn(),[u,f]=S.useState([]),[p,o]=S.useState({kind:"work"}),[c,h]=S.useState("table"),[m,d]=S.useState(!1),[g,b]=S.useState({top:0,left:0}),C=S.useRef(null),k=S.useRef(null),x=S.useRef(!1),[_,w]=S.useState(()=>{const P=Number(localStorage.getItem(cw));return P>=ow&&P<=lw?P:208}),y=S.useCallback(P=>{var G;const H=((G=k.current)==null?void 0:G.getBoundingClientRect().left)??0,W=Math.round(Math.max(ow,Math.min(lw,P-H)));w(W),localStorage.setItem(cw,String(W))},[]),E=240,R=()=>{var H;const P=(H=C.current)==null?void 0:H.getBoundingClientRect();if(P){const W=Math.min(P.left,window.innerWidth-E-8);b({top:P.bottom+4,left:Math.max(8,W)})}d(!0)};S.useEffect(()=>{if(!m)return;const P=()=>d(!1),H=W=>{var G;(G=C.current)!=null&&G.contains(W.target)||W.target.closest("[data-template-picker]")||d(!1)};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)}},[m]),S.useEffect(()=>{K4(e).then(P=>{f(P),x.current||(x.current=!0,P.length>0&&o({kind:"page",id:P[0].id}))})},[e]);const j=async P=>{d(!1);const H=await G4(e,P.title||i("planner.pages.untitled"),P.blocks?JSON.stringify(P.blocks):void 0);f(W=>[...W,H]),o({kind:"page",id:H.id})},T=async P=>{await a({message:i("planner.pages.deleteConfirm"),danger:!0})&&(await X4(P),f(H=>H.filter(W=>W.id!==P)),o(H=>H.kind==="page"&&H.id===P?{kind:"work"}:H))},N=S.useCallback((P,H)=>{f(W=>W.map(G=>G.id===P?{...G,title:H}:G))},[]),D=()=>{o({kind:"work"}),h(P=>P==="table"?"month":P)},A=()=>{o({kind:"work"}),h("table")},B=p.kind==="work",O=B&&c!=="table",F=B&&c==="table",$=(P,H,W,G,I)=>t.jsxs("div",{onClick:H,className:`group flex items-center gap-2 px-2.5 py-1.5 rounded-lg cursor-pointer transition-colors ${P?"":"hover:bg-warm-50"}`,style:P?{backgroundColor:"var(--color-bg-tertiary)"}:void 0,children:[W,t.jsx("span",{className:"flex-1 text-sm truncate",style:{color:"var(--color-text-primary)"},children:G}),I]});return t.jsxs("div",{className:"flex gap-4",style:{minHeight:"70vh"},children:[t.jsxs("div",{ref:k,className:"flex-shrink-0 flex flex-col card p-2 overflow-y-auto",style:{width:_},children:[t.jsxs("div",{className:"flex items-center justify-between px-2.5 pt-1 pb-1",children:[t.jsx("span",{className:"text-2xs font-semibold uppercase tracking-wider text-warm-400",children:i("planner.view.pages")}),t.jsx("button",{ref:C,onClick:()=>m?d(!1):R(),className:"text-warm-400 hover:text-warm-600 transition-colors",title:i("planner.pages.new"),children:t.jsx(yn,{size:14})})]}),u.map(P=>$(p.kind==="page"&&p.id===P.id,()=>o({kind:"page",id:P.id}),t.jsx(tl,{size:14,className:"text-warm-400 flex-shrink-0"}),P.title||i("planner.pages.untitled"),t.jsx("button",{onClick:H=>{H.stopPropagation(),T(P.id)},className:"opacity-0 group-hover:opacity-100 text-warm-400 hover:text-status-error transition-all flex-shrink-0",children:t.jsx(An,{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")}),$(O,D,t.jsx(om,{size:14,className:"text-warm-400 flex-shrink-0"}),i("planner.nav.calendar")),$(F,A,t.jsx(yu,{size:14,className:"text-warm-400 flex-shrink-0"}),i("planner.nav.list"))]}),t.jsx(qO,{onResize:y}),t.jsx("div",{className:"flex-1 min-w-0 flex flex-col",children:p.kind==="page"?t.jsx("div",{className:"card flex flex-col flex-1",children:t.jsx(UO,{pageId:p.id,projectId:e,projectCliTool:s.projectCliTool,existingTags:s.existingTags,onTitleChange:N,onConvertToTodo:s.onConvertToTodo,onConvertToSchedule:s.onConvertToSchedule,onConvertToSession:s.onConvertToSession},p.id)}):t.jsx(IO,{...s,view:c,onChangeView:h})}),m&&rn.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:E,backgroundColor:"var(--color-bg-card)",border:"1px solid var(--color-border)"},children:WO.map(P=>t.jsxs("button",{onClick:()=>j(P),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(P.labelKey)}),t.jsx("div",{className:"text-2xs text-warm-400 mt-0.5",children:i(P.descKey)})]},P.id))}),document.body)]})}const GO=S.lazy(()=>Wu(()=>import("./AnalyticsPanel-D7j7h--_.js"),__vite__mapDeps([9,7,3,2]))),VO=S.lazy(()=>Wu(()=>import("./VaultLayout-Dj1ex4Lj.js"),__vite__mapDeps([10,6,1,2,3,4])));function YO({onEvent:e,connected:s,sendMessage:i,subscribeBinary:a}){const{id:u}=Ym(),[f,p]=S.useState(null),[o,c]=S.useState([]),[h,m]=S.useState([]),[d,g]=S.useState(null),[b,C]=S.useState([]),[k,x]=S.useState([]),[_,w]=S.useState([]),[y,E]=S.useState([]),[R,j]=Iw(),T=["tasks","discussions","schedules","analytics"],N=R.get("tab")||"tasks",[D,A]=S.useState(T.includes(N)?"automation":N),[B,O]=S.useState(T.includes(N)?N:"tasks"),F=S.useCallback(Q=>{if(Q==="automation"){A("automation"),j(B==="tasks"?{}:{tab:B},{replace:!0});return}A(Q),j(Q==="tasks"?{}:{tab:Q},{replace:!0})},[j,B]),$=S.useCallback(Q=>{A("automation"),O(Q),j(Q==="tasks"?{}:{tab:Q},{replace:!0})},[j]),[P,H]=S.useState(!0),[W,G]=S.useState(!1),[I,z]=S.useState(new Set),[U,V]=S.useState(0),{t:q}=ft(),{success:oe,error:ee,info:Z}=Ls(),{sendNotification:te}=lp(),Y=S.useRef([]);S.useEffect(()=>{Y.current=b},[b]),S.useEffect(()=>{u&&Promise.all([MN(u),xf(u),gb(u),xb(u),f4(),D1(u),Uc(u),Wc(u)]).then(([Q,ze,ue,Fe,Ve,ht,Ne,at])=>{p(Q),c(ze),m(ue),C(Fe),x(ht),w(Ne),E(at),Ve.resetsAt&&g(Ve.resetsAt);const bt=ze.filter(Ct=>Ct.status==="running"&&Ct.execution_mode==="interactive").map(Ct=>Ct.id);bt.length>0&&z(new Set(bt))}).catch(()=>G(!0)).finally(()=>H(!1))},[u]);const he=S.useRef(o);he.current=o,S.useEffect(()=>{if(!u)return;const Q=setInterval(()=>{he.current.some(ue=>ue.status==="running")&&xf(u).then(ue=>{c(Fe=>Fe.map(Ve=>{const ht=ue.find(Ne=>Ne.id===Ve.id);return ht&&ht.status!==Ve.status?ht:Ve}))}).catch(()=>{})},5e3);return()=>clearInterval(Q)},[u]);const de=S.useRef(s);S.useEffect(()=>{s&&!de.current&&u&&Promise.all([xf(u),gb(u),xb(u)]).then(([Q,ze,ue])=>{c(Q),m(ze),C(ue)}).catch(()=>{}),de.current=s},[s,u]),S.useEffect(()=>e(Q=>{if(Q.type==="todo:status-changed"&&Q.todoId&&Q.status){if(c(ze=>ze.map(ue=>{if(ue.id!==Q.todoId)return ue;const Fe={status:Q.status,updated_at:new Date().toISOString()};return Q.worktree_path!==void 0&&(Fe.worktree_path=Q.worktree_path??null),Q.branch_name!==void 0&&(Fe.branch_name=Q.branch_name??null),{...ue,...Fe}})),(Q.status==="completed"||Q.status==="merged"||Q.status==="failed")&&V(ze=>ze+1),Q.status==="completed"||Q.status==="failed"){const ze=he.current.find(ue=>ue.id===Q.todoId);ze&&te(Q.status==="completed"?q("notification.taskCompleted"):q("notification.taskFailed"),ze.title)}Q.status==="running"&&Q.mode==="interactive"?z(ze=>new Set(ze).add(Q.todoId)):Q.status!=="running"&&z(ze=>{const ue=new Set(ze);return ue.delete(Q.todoId),ue})}if(Q.type==="todo:created"&&Q.todo&&Q.todo.project_id===u){const ze=Q.todo;c(ue=>ue.some(Fe=>Fe.id===ze.id)?ue:[...ue,ze])}if(Q.type==="schedule:status-changed"&&Q.scheduleId&&m(ze=>ze.map(ue=>ue.id===Q.scheduleId?{...ue,is_active:Q.isActive?1:0,updated_at:new Date().toISOString()}:ue)),Q.type==="rate-limit:updated"&&Q.resetsAt&&g(Q.resetsAt),Q.type==="discussion:status-changed"&&Q.discussionId&&(C(ze=>ze.map(ue=>ue.id===Q.discussionId?{...ue,status:Q.status,current_round:Q.currentRound??ue.current_round,updated_at:new Date().toISOString()}:ue)),Q.status==="completed"||Q.status==="failed")){const ze=Y.current.find(ue=>ue.id===Q.discussionId);ze&&te(Q.status==="completed"?q("notification.discussionCompleted"):q("notification.discussionFailed"),ze.title)}Q.type==="session:status-changed"&&Q.sessionId&&x(ze=>ze.map(ue=>{if(ue.id!==Q.sessionId)return ue;const Fe={status:Q.status,updated_at:new Date().toISOString()};return Q.worktree_path!==void 0&&(Fe.worktree_path=Q.worktree_path),Q.branch_name!==void 0&&(Fe.branch_name=Q.branch_name),{...ue,...Fe}}))}),[e,te,q]);const ye=S.useCallback(async(Q,ze,ue,Fe,Ve,ht,Ne,at,bt,Ct)=>{if(!u)return;const qt=await mb(u,{title:Q,description:ze,cli_tool:ue,depends_on:Ve,max_turns:ht??null,use_worktree:Ne??null,...at?{memory_inject_mode:at}:{},...bt?{memory_node_ids:bt}:{},...Ct?{memory_raw_file_paths:Ct}:{}});if(Fe&&Fe.length>0){const an=await j1(qt.id,Fe.map(Pn=>({name:Pn.name,data:Pn.data})));qt.images=JSON.stringify(an.images)}c(an=>[...an,qt])},[u]),le=S.useCallback((Q,ze=[])=>{const ue=Q.split("/").filter(Boolean).pop()??Q,Fe=[Q,...ze].map(Ve=>`@${Ve}`).join(`
|
|
679
|
+
${U}`:""}`,children:[t.jsx("span",{"aria-label":(W==null?void 0:W.status)||"unknown",style:{width:6,height:6,borderRadius:"50%",background:z,flexShrink:0}}),t.jsx("span",{"aria-hidden":!0,style:{flexShrink:0,fontFamily:Ot,fontSize:11,fontWeight:700,letterSpacing:-.5,lineHeight:1,color:I,width:16,textAlign:"center"},children:">_"}),t.jsx("span",{style:{overflow:"hidden",textOverflow:"ellipsis",flex:1},children:(W==null?void 0:W.title)||H}),t.jsx("button",{"data-no-drag":!0,onMouseDown:V=>V.stopPropagation(),onClick:V=>{V.stopPropagation(),o(H)},"aria-label":"close-tab",title:w("group.closeTab")||"Close tab",style:{background:"transparent",border:"none",color:Ue.titleText,cursor:"pointer",padding:1,display:"flex",alignItems:"center",justifyContent:"center",borderRadius:3,flexShrink:0},children:t.jsx(Xt,{size:12})})]},H)}),N&&t.jsx("button",{"data-no-drag":!0,onMouseDown:H=>H.stopPropagation(),onClick:()=>{N.createRawShellTab(i,s).catch(()=>{})},"aria-label":"new-tab",title:`${w("group.newTab")||"New shell tab"} (Ctrl+T)`,style:{background:"transparent",border:"none",borderRight:`1px solid ${Ue.separator}`,color:Ue.titleText,cursor:"pointer",padding:"0 8px",display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0,height:"100%"},children:t.jsx(yn,{size:14})}),t.jsx("div",{style:{flex:1,minWidth:8}}),O&&t.jsx("span",{title:O,style:{maxWidth:260,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:Ue.dim,fontFamily:Ot,fontSize:9,padding:"0 7px",flexShrink:1},children:O}),t.jsx(Wz,{sessionId:e.activeTab,sendMessage:d}),t.jsx("button",{"data-no-drag":!0,onMouseDown:H=>H.stopPropagation(),onClick:T,"aria-label":"refresh-terminal",title:`${w("session.refresh")||"Refresh rendering"} (F5 · Ctrl+Shift+R) — ${w("session.refresh.hint")||"Rebuild the terminal view (PTY stays running)"}`,style:Zs,children:t.jsx(sN,{size:12})}),t.jsx("button",{"data-no-drag":!0,onMouseDown:H=>H.stopPropagation(),onClick:()=>E(-1),"aria-label":"decrease-font",title:`${w("session.fontDecrease")||"Decrease font size"} (${y}px) · Ctrl+- · Ctrl+wheel`,style:Zs,children:t.jsx(NN,{size:14})}),t.jsx("button",{"data-no-drag":!0,onMouseDown:H=>H.stopPropagation(),onClick:()=>E(1),"aria-label":"increase-font",title:`${w("session.fontIncrease")||"Increase font size"} (${y}px) · Ctrl+= · Ctrl+wheel`,style:Zs,children:t.jsx(jN,{size:14})}),t.jsx($z,{sessionId:e.activeTab}),_&&t.jsxs(t.Fragment,{children:[e.tabs.length>1&&_.onApplyLayoutPreset&&t.jsxs(t.Fragment,{children:[t.jsx("button",{"data-no-drag":!0,onMouseDown:H=>H.stopPropagation(),onClick:()=>{var H;return(H=_.onApplyLayoutPreset)==null?void 0:H.call(_,"single")},"aria-label":"single-pane",title:w("session.layout.single"),style:Zs,children:t.jsx(Ki,{size:12})}),t.jsx("button",{"data-no-drag":!0,onMouseDown:H=>H.stopPropagation(),onClick:()=>{var H;return(H=_.onApplyLayoutPreset)==null?void 0:H.call(_,"columns")},"aria-label":"two-columns",title:w("session.layout.columns"),style:Zs,children:t.jsx(Xw,{size:14})}),t.jsx("button",{"data-no-drag":!0,onMouseDown:H=>H.stopPropagation(),onClick:()=>{var H;return(H=_.onApplyLayoutPreset)==null?void 0:H.call(_,"grid")},"aria-label":"grid-layout",title:w("session.layout.grid"),style:Zs,children:t.jsx(Qw,{size:14})})]}),_.onToggleMaximize&&t.jsx("button",{"data-no-drag":!0,onMouseDown:H=>H.stopPropagation(),onClick:_.onToggleMaximize,"aria-label":"toggle-maximize",title:`${_.isMaximized?w("session.restoreSize"):w("session.maximize")} · ${w("session.maximizeHint")}`,style:Zs,children:_.isMaximized?t.jsx(Hu,{size:14}):t.jsx(qi,{size:14})}),_.onPopOutGroup&&t.jsx("button",{"data-no-drag":!0,onMouseDown:H=>H.stopPropagation(),onClick:_.onPopOutGroup,"aria-label":"pop-out",title:`${w("session.popOut")||"Pop out to separate window"} (Ctrl+Shift+O)`,style:Zs,children:t.jsx(Dr,{size:14})}),t.jsx("button",{"data-no-drag":!0,onMouseDown:H=>H.stopPropagation(),onClick:_.onMinimizeGroup,"aria-label":"minimize",title:`${w("session.minimize")||"Minimize"} (Ctrl+Shift+M)`,style:Zs,children:t.jsx(rp,{size:14})}),t.jsx("button",{"data-no-drag":!0,onMouseDown:H=>H.stopPropagation(),onClick:_.onCloseGroup,"aria-label":"close",title:`${w("session.close")||"Close"} (Ctrl+Shift+X)`,style:Zs,children:t.jsx(Xt,{size:14})})]})]}),t.jsx("div",{"data-group-id":i,"data-stack-path":s.join("."),ref:H=>{if(!H){m(s,null);return}const W=H.getBoundingClientRect();m(s,{x:W.left,y:W.top,w:W.width,h:W.height})},onMouseDown:F,style:{flex:1,position:"relative",minHeight:0,minWidth:0},children:e.tabs.map(H=>{const W=a.get(H);if(!W)return null;const G=f[H]||{intent:"open",nonce:0};return t.jsx(uS,{session:W,visible:H===e.activeTab,intent:G.intent,intentNonce:G.nonce,onClose:()=>h(H),sendMessage:d,subscribeBinary:g,onEvent:b,onCycleTab:$,remountKey:R[H]||0},H)})})]})}const Zs={background:"transparent",border:"none",color:Ue.titleText,cursor:"pointer",padding:"0 6px",display:"flex",alignItems:"center",justifyContent:"center",borderRadius:0,flexShrink:0,height:"100%"};function Xz({orientation:e,onDragStart:s,onDrag:i,onDragEnd:a}){const u=S.useCallback(p=>{if(p.button!==0)return;p.preventDefault(),p.stopPropagation();const o=p.clientX,c=p.clientY;s();let h=!1;const m=()=>{h||(h=!0,window.removeEventListener("mousemove",C),window.removeEventListener("mouseup",k),window.removeEventListener("blur",d),window.removeEventListener("keydown",g),document.removeEventListener("visibilitychange",b))},d=()=>{m(),a()},g=x=>{x.key==="Escape"&&d()},b=()=>{document.hidden&&d()},C=x=>{const _=e==="horizontal"?x.clientX-o:x.clientY-c;i(_)},k=()=>{m(),a()};window.addEventListener("mousemove",C),window.addEventListener("mouseup",k),window.addEventListener("blur",d),window.addEventListener("keydown",g),document.addEventListener("visibilitychange",b)},[e,s,i,a]),f=e==="horizontal";return t.jsx("div",{onMouseDown:u,style:{flex:"0 0 4px",background:Ue.separator,cursor:f?"col-resize":"row-resize",position:"relative",zIndex:1}})}function Bp(e){const{node:s,path:i,onSplitSizes:a,...u}=e;return s.kind==="stack"?t.jsx(Op,{stack:s,path:i,...u}):t.jsx(Jz,{split:s,path:i,onSplitSizes:a,stackProps:u})}const Ky=80;function Jz({split:e,path:s,onSplitSizes:i,stackProps:a}){const u=e.orientation==="horizontal",f=S.useRef(null),p=S.useRef([]),o=S.useRef(null);return t.jsx("div",{ref:f,style:{display:"flex",flexDirection:u?"row":"column",flex:1,minWidth:0,minHeight:0},children:e.children.map((c,h)=>t.jsxs(S.Fragment,{children:[t.jsx("div",{ref:m=>{p.current[h]=m},style:{flex:`0 0 ${e.sizes[h]}%`,display:"flex",flexDirection:"column",minWidth:0,minHeight:0,overflow:"hidden"},children:t.jsx(Bp,{node:c,path:[...s,h],onSplitSizes:i,...a})}),h<e.children.length-1&&t.jsx(Xz,{orientation:e.orientation,onDragStart:()=>{const m=f.current;if(!m)return;const d=e.sizes.slice();o.current={i:h,initialSizes:d,finalSizes:d.slice(),total:u?m.clientWidth:m.clientHeight}},onDrag:m=>{const d=o.current;if(!d||d.total<=0)return;const g=d.initialSizes[d.i]/100*d.total,b=d.initialSizes[d.i+1]/100*d.total,C=g+b,k=Math.max(Ky,Math.min(C-Ky,g+m)),x=C-k,_=k/d.total*100,w=x/d.total*100,y=p.current[d.i],E=p.current[d.i+1];y&&(y.style.flexBasis=`${_}%`),E&&(E.style.flexBasis=`${w}%`);const R=d.initialSizes.slice();R[d.i]=_,R[d.i+1]=w,d.finalSizes=R},onDragEnd:()=>{const m=o.current;m&&i(s,m.finalSizes),o.current=null}})]},h))})}const Et=28,un=68;function Qu(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,p=u-i.h/2;return Math.abs(f)<=Et&&Math.abs(p)<=Et?"center":f>=-un-Et&&f<=-un+Et&&Math.abs(p)<=Et?"left":f>=un-Et&&f<=un+Et&&Math.abs(p)<=Et?"right":p>=-un-Et&&p<=-un+Et&&Math.abs(f)<=Et?"top":p>=un-Et&&p<=un+Et&&Math.abs(f)<=Et?"bottom":null}function Lu(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||"",p=f===""?[]:f.split(".").map(Number),o=u.getBoundingClientRect(),c={x:o.left,y:o.top,w:o.width,h:o.height};return{groupId:u.dataset.groupId||"",path:p,rect:c,zone:Qu(e,s,c)}}return null}function Qz(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 Fm=un*2+12;function hS(e,s,i,a){const u=e-i/2,f=s-a/2;return Math.abs(u)<=Et&&Math.abs(f)<=Et?"max":u>=-un-Et&&u<=-un+Et&&Math.abs(f)<=Et?"left":u>=un-Et&&u<=un+Et&&Math.abs(f)<=Et?"right":f>=-un-Et&&f<=-un+Et&&Math.abs(u)<=Et?"top":f>=un-Et&&f<=un+Et&&Math.abs(u)<=Et?"bottom":f>=-Fm-Et&&f<=-Fm+Et&&Math.abs(u)<=Et?"popout":null}function fS(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 vl(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 fS(e,u,s,i,a)}function Ha(){const e=document.querySelector("[data-app-sidebar]");return Math.max(0,e?e.getBoundingClientRect().right:0)}function mS({activeZone:e}){const s=window.innerWidth,i=window.innerHeight,a=s/2,u=i/2,f=e&&e!=="popout"?vl(e,s,i,Ha()):null;return rn.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:`${Ue.info}33`,border:`2px dashed ${Ue.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(Fs,{offsetX:a-Et,offsetY:u-Et,active:e==="max",kind:"center"}),t.jsx(Fs,{offsetX:a-un-Et,offsetY:u-Et,active:e==="left",kind:"left"}),t.jsx(Fs,{offsetX:a+un-Et,offsetY:u-Et,active:e==="right",kind:"right"}),t.jsx(Fs,{offsetX:a-Et,offsetY:u-un-Et,active:e==="top",kind:"top"}),t.jsx(Fs,{offsetX:a-Et,offsetY:u+un-Et,active:e==="bottom",kind:"bottom"}),t.jsx(Fs,{offsetX:a-Et,offsetY:u-Fm-Et,active:e==="popout",kind:"popout"})]})]}),document.body)}function bl({targetRect:e,activeZone:s}){const i=e.x+e.w/2,a=e.y+e.h/2,u=s?Qz(e,s):null;return rn.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:`${Ue.info}33`,border:`2px dashed ${Ue.info}`,borderRadius:4,pointerEvents:"none",zIndex:2400,boxSizing:"border-box"}}),(()=>{const f=un+Et;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(Fs,{offsetX:f-Et,offsetY:f-Et,active:s==="center",kind:"center"}),t.jsx(Fs,{offsetX:f-un-Et,offsetY:f-Et,active:s==="left",kind:"left"}),t.jsx(Fs,{offsetX:f+un-Et,offsetY:f-Et,active:s==="right",kind:"right"}),t.jsx(Fs,{offsetX:f-Et,offsetY:f-un-Et,active:s==="top",kind:"top"}),t.jsx(Fs,{offsetX:f-Et,offsetY:f+un-Et,active:s==="bottom",kind:"bottom"})]})})()]}),document.body)}function Fs({offsetX:e,offsetY:s,active:i,kind:a}){const u=Et*2,f=i?Ue.info:"#3a3a3a",p=i?Ue.bright:Ue.separator;return t.jsx("div",{style:{position:"absolute",left:e,top:s,width:u,height:u,background:"#1a1a1a",border:`1px solid ${p}`,borderRadius:4,boxShadow:i?`0 0 8px ${Ue.info}`:"0 1px 3px rgba(0,0,0,0.4)",boxSizing:"border-box",overflow:"hidden"},children:t.jsx(Zz,{kind:a,fill:f})})}function Zz({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(Dr,{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 Nr(e,s){return{kind:"stack",tabs:e.slice(),activeTab:s??e[0]}}function ul(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 Zu(e,s){if(e.kind==="stack")return e.tabs.includes(s)?[]:null;for(let i=0;i<e.children.length;i++){const a=Zu(e.children[i],s);if(a)return[i,...a]}return null}function gn(e){return e.kind==="stack"?e.tabs.slice():e.children.flatMap(gn)}function Du(e){return e.kind==="stack"?[e.activeTab]:e.children.flatMap(Du)}function eO(e,s){const i=gn(e);if(i.length<=1||s==="single")return Nr(i,Du(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(Du(e)),p=u.map(d=>Nr(d,d.find(g=>f.has(g))||d[0]));if(s==="columns"||p.length<=2)return{kind:"split",orientation:"horizontal",children:p,sizes:p.map(()=>100/p.length)};const o=p.slice(0,2),c=p.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(c)],sizes:[50,50]}}function Ui(e,s){return pS(e,s)}function pS(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 p=e.activeTab===s?f[0]:e.activeTab;return{kind:"stack",tabs:f,activeTab:p}}const i=[],a=[];for(let f=0;f<e.children.length;f++){const p=pS(e.children[f],s);p!==null&&(i.push(p),a.push(e.sizes[f]))}if(i.length===0)return null;if(i.length===1)return i[0];const u=a.reduce((f,p)=>f+p,0)||1;return{kind:"split",orientation:e.orientation,children:i,sizes:a.map(f=>f/u*100)}}function Hi(e,s,i){return ed(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 $a(e,s,i,a){const u=i==="left"||i==="right"?"horizontal":"vertical",f=i==="left"||i==="top";return ed(e,s,p=>({kind:"split",orientation:u,children:f?[a,p]:[p,a],sizes:[50,50]}))}function ed(e,s,i){if(s.length===0)return Tu(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((p,o)=>o===a?ed(p,u,i):p);return Tu({...e,children:f})}function Tu(e){if(e.kind==="stack")return e;const s=e.children.map(Tu),i=[],a=[];for(let f=0;f<s.length;f++){const p=s[f],o=e.sizes[f]??100/s.length;if(p.kind==="split"&&p.orientation===e.orientation){const c=p.sizes.reduce((h,m)=>h+m,0)||1;for(let h=0;h<p.children.length;h++)i.push(p.children[h]),a.push(p.sizes[h]/c*o)}else i.push(p),a.push(o)}if(i.length===1)return i[0];const u=a.reduce((f,p)=>f+p,0)||1;return{kind:"split",orientation:e.orientation,children:i,sizes:a.map(f=>f/u*100)}}function Ps(e,s){return e.kind==="stack"?e.tabs.includes(s)?{...e,activeTab:s}:e:{...e,children:e.children.map(i=>Ps(i,s))}}function gS(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=>gS(a,s,i))}}function xS(e,s,i){return ed(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 tO(e,s,i,a){const u=ul(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 p=Ui(e,s);if(!p)return null;const o=Zu(p,f);if(!o)return null;const c=a==="center"?Hi(p,o,s):$a(p,o,a,Nr([s]));return Ps(c,s)}function nO(e,s){const i=gn(e);let a=e;for(const u of i){if(!a)break;s.has(u)||(a=Ui(a,u))}return a}const Zc=320,eu=200,tu=80,nu=22,sO=4,Gy=8,ii=10,su=60,rO=12;function ai(e,s,i){return Math.max(s,Math.min(i,e))}function iO(e,s,i,a){const u=e<=Gy,f=e>=i-Gy;if(!u&&!f)return null;const p=a/3,o=a*2/3;return u?s<p?"top-left":s>o?"bottom-left":"left":s<p?"top-right":s>o?"bottom-right":"right"}function Vy(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 aO(e,s,i,a,u){let f=e,p=s;const o=f,c=f+i,h=p,m=p+a;for(const d of u){const g=d.x,b=d.x+d.w,C=d.y,k=d.y+d.h;h<k&&m>C&&(Math.abs(o-b)<=ii?f=b:Math.abs(c-g)<=ii?f=g-i:Math.abs(o-g)<=ii?f=g:Math.abs(c-b)<=ii&&(f=b-i)),o<b&&c>g&&(Math.abs(h-k)<=ii?p=k:Math.abs(m-C)<=ii?p=C-a:Math.abs(h-C)<=ii?p=C:Math.abs(m-k)<=ii&&(p=k-a))}return{x:f,y:p}}function oO({group:e,sessionsById:s,neighbors:i,isTopmost:a,zIndex:u,sendMessage:f,subscribeBinary:p,onEvent:o}){const{t:c}=ft(),h=K_("(max-width: 767px)"),m=_S(),d=S.useRef(null),[g,b]=S.useState(!1),C=S.useRef(null),[k,x]=S.useState(null),_=S.useRef({x:e.x,y:e.y,w:e.w,h:e.h});_.current={x:e.x,y:e.y,w:e.w,h:e.h};const[w,y]=S.useState(null),E=S.useRef(null),[R,j]=S.useState(!1),[T,N]=S.useState(null),D=S.useRef(null),A=S.useRef(i);A.current=i;const[B,O]=S.useState(null),F=S.useRef(null),$=S.useCallback((le,De)=>{if(h||g||le.button!==0||le.target.closest("[data-no-drag]"))return;le.preventDefault(),m.focus(gn(e.root)[0]||"");const ve=le.clientX,Me=le.clientY,Oe={..._.current},tt=d.current,nt=window.innerWidth,ke=window.innerHeight,fe=Ha();let Te=!1,Ce="";De&&tt&&(Ce=tt.style.pointerEvents,tt.style.pointerEvents="none");let Ge=!1;const Ze=()=>{Ge||(Ge=!0,window.removeEventListener("mousemove",X),window.removeEventListener("mouseup",me),window.removeEventListener("blur",be),window.removeEventListener("keydown",Be),document.removeEventListener("visibilitychange",ne),De&&tt&&(tt.style.pointerEvents=Ce))},be=()=>{Ze(),F.current=null,O(null),E.current=null,y(null),D.current=null,N(null),j(!1),m.setGroupGeometry(e.id,{..._.current})},Be=re=>{re.key==="Escape"&&be()},ne=()=>{document.hidden&&be()};let _e=!1;const X=re=>{if(_e)return;{const qe=window.screenX,Ee=window.screenY,st=qe+window.outerWidth,lt=Ee+window.outerHeight;if(re.screenX<qe-su||re.screenX>st+su||re.screenY<Ee-su||re.screenY>lt+su){_e=!0,Ze(),F.current=null,O(null),E.current=null,y(null),D.current=null,N(null),j(!1),m.setGroupGeometry(e.id,{..._.current}),m.popOutGroup(e.id,{atScreenX:re.screenX,atScreenY:re.screenY});return}}const ae=re.clientX-ve,J=re.clientY-Me;let se=ai(Oe.x+ae,-(Oe.w-tu),nt-tu),pe=ai(Oe.y+J,0,ke-nu);const we=A.current;if(we.length>0){const qe=aO(se,pe,Oe.w,Oe.h,we);se=qe.x,pe=qe.y}if(tt&&(tt.style.left=`${se}px`,tt.style.top=`${pe}px`),_.current.x=se,_.current.y=pe,De){let qe=null;const Ee=document.elementFromPoint(re.clientX,re.clientY),st=Ee==null?void 0:Ee.closest("[data-group-id][data-stack-path]");if(st){const lt=st.dataset.groupId||"";if(lt!==e.id){const yt=st.dataset.stackPath||"",mt=yt===""?[]:yt.split(".").map(Number),pt=st.getBoundingClientRect(),dt={x:pt.left,y:pt.top,w:pt.width,h:pt.height};qe={groupId:lt,path:mt,rect:dt,zone:Qu(re.clientX,re.clientY,dt)}}}F.current=qe,O(qe?{rect:qe.rect,zone:qe.zone}:null)}!Te&&Math.hypot(re.clientX-ve,re.clientY-Me)>=rO&&(Te=!0,j(!0),e.dock&&m.setGroupDock(e.id,null));const je=De&&F.current&&F.current.zone,$e=je||!Te?null:hS(re.clientX,re.clientY,nt,ke);$e!==D.current&&(D.current=$e,N($e));const Je=je||$e?null:iO(re.clientX,re.clientY,nt,ke);Je!==E.current&&(E.current=Je,y(Je))},me=re=>{Ze(),j(!1);const ae=D.current;if(D.current=null,N(null),De&&F.current&&F.current.zone){const se=F.current;m.dockGroup(e.id,se.groupId,se.path,se.zone),F.current=null,O(null),E.current=null,y(null);return}if(ae==="popout"){F.current=null,O(null),E.current=null,y(null),m.setGroupGeometry(e.id,{..._.current}),m.popOutGroup(e.id,{atScreenX:re.screenX,atScreenY:re.screenY});return}if(ae&&ae!=="max"){const se=vl(ae,nt,ke,fe);tt&&(tt.style.left=`${se.x}px`,tt.style.top=`${se.y}px`,tt.style.width=`${se.w}px`,tt.style.height=`${se.h}px`),_.current=se,F.current=null,O(null),E.current=null,y(null),m.setGroupDock(e.id,ae);return}const J=ae?vl(ae,nt,ke,fe):E.current?Vy(E.current,nt,ke):null;J&&(tt&&(tt.style.left=`${J.x}px`,tt.style.top=`${J.y}px`,tt.style.width=`${J.w}px`,tt.style.height=`${J.h}px`),_.current=J,E.current=null,y(null)),F.current=null,O(null),m.setGroupGeometry(e.id,{..._.current})};window.addEventListener("mousemove",X),window.addEventListener("mouseup",me),window.addEventListener("blur",be),window.addEventListener("keydown",Be),document.addEventListener("visibilitychange",ne)},[h,g,m,e.id,e.root,e.dock]),P=S.useCallback(le=>$(le,!1),[$]),H=S.useCallback(le=>$(le,!0),[$]),W=S.useCallback(le=>De=>{if(h||g||De.button!==0)return;De.preventDefault(),De.stopPropagation();const Re=De.clientX,ve=De.clientY,Me={..._.current},Oe=d.current,tt=window.innerWidth,nt=window.innerHeight,ke=Be=>{const ne=Be.clientX-Re,_e=Be.clientY-ve;let X=Me.x,me=Me.y,re=Me.w,ae=Me.h;le.includes("e")?re=ai(Me.w+ne,Zc,Math.max(Zc,tt-Me.x)):le.includes("w")&&(X=ai(Me.x+ne,0,Me.x+Me.w-Zc),re=Me.x+Me.w-X),le.includes("s")?ae=ai(Me.h+_e,eu,Math.max(eu,nt-Me.y)):le.includes("n")&&(me=ai(Me.y+_e,0,Me.y+Me.h-eu),ae=Me.y+Me.h-me),Oe&&(Oe.style.left=`${X}px`,Oe.style.top=`${me}px`,Oe.style.width=`${re}px`,Oe.style.height=`${ae}px`),_.current={x:X,y:me,w:re,h:ae}};let fe=!1;const Te=()=>{fe||(fe=!0,window.removeEventListener("mousemove",ke),window.removeEventListener("mouseup",be),window.removeEventListener("blur",Ce),window.removeEventListener("keydown",Ge),document.removeEventListener("visibilitychange",Ze))},Ce=()=>{Te(),m.setGroupGeometry(e.id,{..._.current})},Ge=Be=>{Be.key==="Escape"&&Ce()},Ze=()=>{document.hidden&&Ce()},be=()=>{Te(),m.setGroupGeometry(e.id,{..._.current})};window.addEventListener("mousemove",ke),window.addEventListener("mouseup",be),window.addEventListener("blur",Ce),window.addEventListener("keydown",Ge),document.addEventListener("visibilitychange",Ze)},[h,g,m,e.id]);S.useEffect(()=>{if(h||e.dock)return;const le=()=>{const De=window.innerWidth,Re=window.innerHeight,ve=_.current,Me=ai(ve.x,-(ve.w-tu),De-tu),Oe=ai(ve.y,0,Re-nu);(Me!==ve.x||Oe!==ve.y)&&m.setGroupGeometry(e.id,{...ve,x:Me,y:Oe})};return window.addEventListener("resize",le),()=>window.removeEventListener("resize",le)},[h,m,e.id,e.dock]);const G=S.useCallback(le=>{x(le),m.setActiveTab(e.id,le),m.focus(le)},[m,e.id]),I=S.useCallback(le=>{x(le),m.focus(le)},[m]),z=S.useCallback(le=>{m.close(le)},[m]),U=S.useCallback((le,De,Re)=>{m.beginTabDrag(e.id,le,De,Re)},[m,e.id]),V=S.useCallback(le=>{m.close(le)},[m]),q=S.useCallback((le,De)=>{m.setSplitSizes(e.id,le,De)},[m,e.id]),oe=Du(e.root),ee=gn(e.root);S.useEffect(()=>{k&&ee.includes(k)||x(oe[0]||ee[0]||null)},[k,oe,ee]);const Z=S.useCallback(()=>{if(g){const le=C.current;le&&m.setGroupGeometry(e.id,le),C.current=null,b(!1);return}C.current={..._.current},e.dock&&m.setGroupDock(e.id,null),m.setGroupGeometry(e.id,{x:6,y:6,w:Math.max(Zc,window.innerWidth-12),h:Math.max(eu,window.innerHeight-12)}),b(!0)},[m,e.id,g,e.dock]),te=le=>{const De=/Mac|iPhone|iPad|iPod/.test(navigator.platform),Re=De?le.metaKey:le.ctrlKey,ve=De?le.ctrlKey:le.metaKey;if(!Re||ve||le.altKey||!le.shiftKey)return;const Me=le.key.toLowerCase();Me==="o"?(le.preventDefault(),m.popOutGroup(e.id)):Me==="m"?(le.preventDefault(),m.minimizeGroup(e.id)):Me==="x"&&(le.preventDefault(),m.closeGroup(e.id))};if(h){const le=oe[0],De=le?s.get(le):null;if(!De)return null;const Re=e.intents[le]??{intent:"open",nonce:0};return rn.createPortal(t.jsxs("div",{style:{position:"fixed",inset:0,background:Ue.bg,display:"flex",flexDirection:"column",zIndex:110},children:[t.jsxs("div",{style:{background:Ue.titleBg,height:nu,display:"flex",alignItems:"center",borderBottom:`1px solid ${Ue.separator}`},children:[t.jsx("span",{style:{flex:1,color:Ue.titleText,fontFamily:Ot,fontSize:12,paddingLeft:8,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:De.title}),t.jsx("button",{"data-no-drag":!0,onClick:()=>m.closeGroup(e.id),style:oi,"aria-label":"close",children:t.jsx(Xt,{size:14})})]}),t.jsx("div",{style:{flex:1,position:"relative",minHeight:0},children:t.jsx(uS,{session:De,visible:!0,intent:Re.intent,intentNonce:Re.nonce,onClose:()=>m.close(le),sendMessage:f,subscribeBinary:p,onEvent:o})})]}),document.body)}const Y=w?(()=>{const le=window.innerWidth,De=window.innerHeight,Re=Vy(w,le,De);return rn.createPortal(t.jsx("div",{style:{position:"fixed",left:Re.x,top:Re.y,width:Re.w,height:Re.h,background:`${Ue.info}33`,border:`2px dashed ${Ue.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,he=(()=>{var De;if(ee.length===0)return"";const le=((De=s.get(ee[0]))==null?void 0:De.title)||ee[0];return ee.length===1?le:`${le} +${ee.length-1}`})(),de=e.root.kind==="split",ye=rn.createPortal(t.jsxs("div",{ref:d,onKeyDown:te,onMouseDown:de?()=>m.focus(ee[0]||""):H,style:{position:"fixed",left:e.x,top:e.y,width:e.w,height:e.h,zIndex:u,background:Ue.bg,border:`1px solid ${a?Ue.info:Ue.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 ${Ue.info}66, 0 0 18px ${Ue.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:[de&&t.jsxs("div",{onMouseDown:P,onDoubleClick:le=>{le.target.closest("button")||Z()},style:{height:nu,flexShrink:0,display:"flex",flexDirection:"column",background:Ue.titleBg,borderBottom:`1px solid ${Ue.separator}`,userSelect:"none",cursor:"move"},children:[t.jsx("div",{style:{display:"flex",height:sO,flexShrink:0},children:oe.map((le,De)=>t.jsx("div",{style:{flex:1,background:e.colors[le]||Ue.titleText}},De))}),t.jsxs("div",{style:{flex:1,display:"flex",alignItems:"center",padding:"0 4px 0 8px",color:Ue.titleText,fontFamily:Ot,fontSize:11},children:[t.jsx("span",{style:{color:Ue.info,fontWeight:600,letterSpacing:1,marginRight:8},"aria-hidden":!0,children:">_"}),t.jsx("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:he}),ee.length>1&&t.jsxs(t.Fragment,{children:[t.jsx("button",{"data-no-drag":!0,onMouseDown:le=>le.stopPropagation(),onClick:()=>m.applyLayoutPreset(e.id,"single"),style:oi,"aria-label":"single-pane",title:c("session.layout.single"),children:t.jsx(Ki,{size:12})}),t.jsx("button",{"data-no-drag":!0,onMouseDown:le=>le.stopPropagation(),onClick:()=>m.applyLayoutPreset(e.id,"columns"),style:oi,"aria-label":"two-columns",title:c("session.layout.columns"),children:t.jsx(Xw,{size:14})}),t.jsx("button",{"data-no-drag":!0,onMouseDown:le=>le.stopPropagation(),onClick:()=>m.applyLayoutPreset(e.id,"grid"),style:oi,"aria-label":"grid-layout",title:c("session.layout.grid"),children:t.jsx(Qw,{size:14})})]}),t.jsx("button",{"data-no-drag":!0,onMouseDown:le=>le.stopPropagation(),onClick:Z,style:oi,"aria-label":"toggle-maximize",title:`${c(g?"session.restoreSize":"session.maximize")} · ${c("session.maximizeHint")}`,children:g?t.jsx(Hu,{size:14}):t.jsx(qi,{size:14})}),t.jsx("button",{"data-no-drag":!0,onMouseDown:le=>le.stopPropagation(),onClick:()=>m.popOutGroup(e.id),style:oi,"aria-label":"pop-out",title:`${c("session.popOut")||"Pop out to separate window"} (Ctrl+Shift+O)`,children:t.jsx(Dr,{size:14})}),t.jsx("button",{"data-no-drag":!0,onClick:()=>m.minimizeGroup(e.id),style:oi,"aria-label":"minimize",title:`${c("session.minimize")||"Minimize"} (Ctrl+Shift+M)`,children:t.jsx(rp,{size:14})}),t.jsx("button",{"data-no-drag":!0,onClick:()=>m.closeGroup(e.id),style:oi,"aria-label":"close",title:`${c("session.close")||"Close"} (Ctrl+Shift+X)`,children:t.jsx(Xt,{size:14})})]})]}),t.jsx("div",{style:{flex:1,display:"flex",minHeight:0,minWidth:0},children:e.root.kind==="split"?t.jsx(Bp,{node:e.root,path:[],groupId:e.id,sessionsById:s,colors:e.colors,intents:e.intents,onTabClick:G,onTabClose:z,onTabMouseDown:U,onPaneAutoClose:V,registerRect:()=>{},onSplitSizes:q,sendMessage:f,subscribeBinary:p,onEvent:o,focusedSessionId:k||void 0,groupTopmost:a,onFocusStack:I}):t.jsx(Op,{stack:e.root,path:[],groupId:e.id,sessionsById:s,colors:e.colors,intents:e.intents,onTabClick:G,onTabClose:z,onTabMouseDown:U,onPaneAutoClose:V,registerRect:()=>{},sendMessage:f,subscribeBinary:p,onEvent:o,focusedSessionId:k||void 0,groupTopmost:a,onFocusStack:I,groupActions:{onMinimizeGroup:()=>m.minimizeGroup(e.id),onCloseGroup:()=>m.closeGroup(e.id),onPopOutGroup:()=>m.popOutGroup(e.id),onToggleMaximize:Z,isMaximized:g,onApplyLayoutPreset:le=>m.applyLayoutPreset(e.id,le)}})}),t.jsx("div",{onMouseDown:W("n"),style:{position:"absolute",top:0,left:6,right:6,height:4,cursor:"ns-resize",zIndex:3}}),t.jsx("div",{onMouseDown:W("s"),style:{position:"absolute",bottom:0,left:6,right:6,height:4,cursor:"ns-resize",zIndex:3}}),t.jsx("div",{onMouseDown:W("w"),style:{position:"absolute",top:6,bottom:6,left:0,width:4,cursor:"ew-resize",zIndex:3}}),t.jsx("div",{onMouseDown:W("e"),style:{position:"absolute",top:6,bottom:6,right:0,width:4,cursor:"ew-resize",zIndex:3}}),t.jsx("div",{onMouseDown:W("nw"),style:{position:"absolute",top:0,left:0,width:10,height:10,cursor:"nwse-resize",zIndex:4}}),t.jsx("div",{onMouseDown:W("ne"),style:{position:"absolute",top:0,right:0,width:10,height:10,cursor:"nesw-resize",zIndex:4}}),t.jsx("div",{onMouseDown:W("sw"),style:{position:"absolute",bottom:0,left:0,width:10,height:10,cursor:"nesw-resize",zIndex:4}}),t.jsx("div",{onMouseDown:W("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:[ye,Y,R&&!(B!=null&&B.zone)&&t.jsx(mS,{activeZone:T}),B&&t.jsx(bl,{targetRect:B.rect,activeZone:B.zone})]})}const oi={background:"transparent",border:"none",color:Ue.titleText,cursor:"pointer",padding:4,display:"flex",alignItems:"center",justifyContent:"center",borderRadius:4},Xf=["#3b82f6","#22c55e","#eab308","#ef4444","#a855f7","#06b6d4","#f97316","#ec4899"];function Fi(e){for(const s of Xf)if(!e.includes(s))return s;return Xf[e.length%Xf.length]}const lO="clitrigger:session-windows:global";function Pp(){if(typeof BroadcastChannel>"u")return{post:()=>{},subscribe:()=>()=>{},close:()=>{}};const e=new BroadcastChannel(lO),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 Bt="main",Hm=new Map;function cO(e,s){Hm.set(e,s)}function uO(e){const s=Hm.get(e);if(!s||s.closed)return Hm.delete(e),!1;try{return s.focus(),!0}catch{return!1}}function dO(){return`popout_${Math.random().toString(36).slice(2,10)}_${Date.now().toString(36)}`}const Ip=5e3,vS=15e3;let Ia=null;function bS(){if(typeof window>"u")return()=>{};const e=s=>{Ia={sx:s.screenX,sy:s.screenY,cx:s.clientX,cy:s.clientY}};return window.addEventListener("mousemove",e,{passive:!0}),()=>window.removeEventListener("mousemove",e)}function Ru(e,s){if(Ia)return{x:Ia.cx+(e-Ia.sx),y:Ia.cy+(s-Ia.sy)};const i=Math.max(0,(window.outerWidth-window.innerWidth)/2),a=Math.max(0,window.outerHeight-window.innerHeight-i);return{x:e-window.screenX-i,y:s-window.screenY-a}}function Mu(e){return e.x>=0&&e.y>=0&&e.x<=window.innerWidth&&e.y<=window.innerHeight}const $m="clitrigger:popout-alive:";function hO(e){return`${$m}${e}`}function Fp(){return typeof navigator<"u"&&!!navigator.locks&&typeof navigator.locks.query=="function"}function fO(e){if(!Fp())return()=>{};let s=()=>{};return navigator.locks.request(hO(e),()=>new Promise(i=>{s=i})).catch(()=>{}),()=>s()}async function yS(){var e;if(!Fp())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($m)&&i.add(a.name.slice($m.length));return i}catch{return new Set}}const Hp=S.createContext(null),wS=S.createContext({});function _S(){const e=S.useContext(Hp);if(!e)throw new Error("useSessionWindows must be used within SessionWindowsHost");return e}function mO(){return S.useContext(wS)}function pO(){return S.useContext(Hp)}const Au=720,$p=460,gO=320,xO=200,Yy=30,SS=80,kS=80,dl=80,Um=28;function vO(e){const s=typeof window<"u"?window.innerWidth:1280,i=typeof window<"u"?window.innerHeight:800;let a=Number.isFinite(e.w)&&e.w>=gO?e.w:Au,u=Number.isFinite(e.h)&&e.h>=xO?e.h:$p;a=Math.min(a,s),u=Math.min(u,i);let f=Number.isFinite(e.x)?e.x:SS,p=Number.isFinite(e.y)?e.y:kS;return f=Math.max(Math.min(f,s-dl),-(a-dl)),p=Math.max(Math.min(p,i-Um),0),{x:f,y:p,w:a,h:u}}const Xy=12,ru=60;function CS(e){return`sessionGroups:${e}`}function mu(e){try{const s=localStorage.getItem(CS(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 Wm(e,s){try{localStorage.setItem(CS(e),JSON.stringify(s))}catch{}}function bO(e,s){const i=mu(e);!i||!i.groups.some(a=>a.id===s)||(Wm(e,{...i,groups:i.groups.filter(a=>a.id!==s)}),window.dispatchEvent(new CustomEvent("session-windows:changed")))}function yO(e){const s=e%8;return{x:SS+s*Yy,y:kS+s*Yy,w:Au,h:$p}}function iu(e,s,i){return Math.max(s,Math.min(i,e))}function Jy(){return`g_${Math.random().toString(36).slice(2,10)}_${Date.now().toString(36)}`}function li(e,s){for(const i of e)if(Zu(i.root,s))return i;return null}function wO({projectId:e,sessions:s,sendMessage:i,subscribeBinary:a,onEvent:u,onAddSession:f,children:p}){const{t:o}=ft(),{warning:c}=Ls(),{confirm:h}=qn(),[m]=S.useState(()=>{const re=mu(e);if(!re)return{groups:[],zCounter:0};const ae=re.groups.map(J=>{const se=gn(J.root),pe=new Set(se),we={};for(const qe of Object.keys(J.colors||{}))pe.has(qe)&&(we[qe]=J.colors[qe]);const je={};for(const qe of se)je[qe]={intent:"open",nonce:0},we[qe]||(we[qe]=Fi(Object.values(we)));const $e=vO({x:J.x,y:J.y,w:J.w,h:J.h}),Je=J.ownerWindowId||Bt;return{...J,...$e,colors:we,intents:je,minimized:!!J.minimized,ownerWindowId:Je}});return{groups:ae,zCounter:re.zCounter||ae.length}}),[d,g]=S.useState(m.groups),b=S.useRef(m.zCounter),C=S.useRef(d);C.current=d;const k=S.useRef(s);k.current=s;const[x,_]=S.useState(null),w=S.useRef(null);w.current=x;const[y,E]=S.useState({}),R=S.useRef(y);R.current=y,S.useEffect(()=>{var se;const re={},ae=((se=mu(e))==null?void 0:se.sessionProjects)??{},J={};for(const pe of d)for(const we of gn(pe.root)){const je=s.find(Je=>Je.id===we)||y[we];je!=null&&je.title&&(re[we]=je.title);const $e=(je==null?void 0:je.project_id)||ae[we];$e&&(J[we]=$e)}Wm(e,{groups:d,zCounter:b.current,titles:re,sessionProjects:J}),window.dispatchEvent(new CustomEvent("session-windows:changed"))},[e,d,s,y]),S.useEffect(()=>()=>{var je;const re=C.current;if(re.length===0)return;let ae=!1;const J=re.map($e=>($e.ownerWindowId||Bt)!==Bt||$e.minimized?$e:(ae=!0,{...$e,minimized:!0}));if(!ae)return;const se={},pe=((je=mu(e))==null?void 0:je.sessionProjects)??{},we={};for(const $e of J)for(const Je of gn($e.root)){const qe=k.current.find(st=>st.id===Je)||R.current[Je];qe!=null&&qe.title&&(se[Je]=qe.title);const Ee=(qe==null?void 0:qe.project_id)||pe[Je];Ee&&(we[Je]=Ee)}Wm(e,{groups:J,zCounter:b.current,titles:se,sessionProjects:we}),window.dispatchEvent(new CustomEvent("session-windows:changed"))},[e]),S.useEffect(()=>{const re=document.documentElement.style,ae={left:0,right:0,top:0,bottom:0};for(const J of d)!J.dock||J.minimized||(J.ownerWindowId||Bt)!==Bt||(J.dock==="left"?ae.left=Math.max(ae.left,J.x+J.w-Ha()):J.dock==="right"?ae.right=Math.max(ae.right,window.innerWidth-J.x):J.dock==="top"?ae.top=Math.max(ae.top,J.y+J.h):ae.bottom=Math.max(ae.bottom,window.innerHeight-J.y));for(const J of["left","right","top","bottom"])re.setProperty(`--dock-inset-${J}`,`${Math.max(0,Math.round(ae[J]))}px`);return()=>{for(const J of["left","right","top","bottom"])re.removeProperty(`--dock-inset-${J}`)}},[d]),S.useEffect(()=>{const re=()=>{const se=window.innerWidth,pe=window.innerHeight,we=Ha();g(je=>{let $e=!1;const Je=je.map(qe=>{if(!qe.dock)return qe;const Ee=qe.dock==="left"||qe.dock==="right"?qe.w:qe.h,st=fS(qe.dock,Ee,se,pe,we);return st.x===qe.x&&st.y===qe.y&&st.w===qe.w&&st.h===qe.h?qe:($e=!0,{...qe,...st})});return $e?Je:je})};re();const ae=document.querySelector("main"),J=ae?new ResizeObserver(re):null;return ae&&J&&J.observe(ae),window.addEventListener("resize",re),()=>{J==null||J.disconnect(),window.removeEventListener("resize",re)}},[]);const[j,T]=S.useState(()=>new Set),N=S.useRef(new Set);S.useEffect(()=>{if(s.length===0)return;const re=s.filter(J=>J.project_id===e);if(re.length===0)return;const ae=new Set(re.map(J=>J.id));for(const J of d)for(const se of gn(J.root))ae.has(se)||y[se]||j.has(se)||N.current.has(se)||(N.current.add(se),T1(se).then(pe=>E(we=>({...we,[se]:pe}))).catch(pe=>{pe instanceof gu&&pe.status===404&&T(we=>new Set(we).add(se))}).finally(()=>N.current.delete(se)))},[d,s,e,y,j]),S.useEffect(()=>u(ae=>{ae.type!=="session:status-changed"||!ae.sessionId||E(J=>{const se=J[ae.sessionId];if(!se)return J;const pe={status:ae.status};return ae.worktree_path!==void 0&&(pe.worktree_path=ae.worktree_path),ae.branch_name!==void 0&&(pe.branch_name=ae.branch_name),{...J,[se.id]:{...se,...pe}}})}),[u]),S.useEffect(()=>{j.size!==0&&g(re=>{let ae=!1;const J=[];for(const se of re){const pe=gn(se.root);if(!pe.some(Ee=>j.has(Ee))){J.push(se);continue}ae=!0;const we=new Set(pe.filter(Ee=>!j.has(Ee))),je=nO(se.root,we);if(!je)continue;const $e=new Set(gn(je)),Je={};for(const Ee of Object.keys(se.colors))$e.has(Ee)&&(Je[Ee]=se.colors[Ee]);const qe={};for(const Ee of Object.keys(se.intents))$e.has(Ee)&&(qe[Ee]=se.intents[Ee]);J.push({...se,root:je,colors:Je,intents:qe})}return ae?J:re})},[j]);const D=S.useCallback((re,ae)=>{const J=C.current.length,se=yO(J);b.current+=1;const pe=b.current;return{id:Jy(),...se,z:pe,minimized:!1,root:Nr([re],re),colors:{[re]:Fi([])},intents:{[re]:{intent:ae,nonce:0}},ownerWindowId:Bt}},[]),A=S.useCallback((re,ae="open")=>{g(J=>{const se=li(J,re);b.current+=1;const pe=b.current;return se?J.map(we=>{var Ee,st,lt;if(we.id!==se.id)return we;const je=((Ee=we.intents[re])==null?void 0:Ee.intent)??"open",$e=ae==="start"||ae==="resume",Je=$e?ae:je,qe=Je!==je||$e;return{...we,z:pe,minimized:!1,root:Ps(we.root,re),intents:{...we.intents,[re]:{intent:Je,nonce:qe?(((st=we.intents[re])==null?void 0:st.nonce)??0)+1:((lt=we.intents[re])==null?void 0:lt.nonce)??0}}}}):[...J,D(re,ae)]})},[D]),B=S.useCallback(re=>{g(ae=>{const J=li(ae,re);if(!J)return ae;const se=ae.reduce((we,je)=>je.z>we?je.z:we,0);if(J.z===se&&!J.minimized)return ae;b.current+=1;const pe=b.current;return ae.map(we=>we.id===J.id?{...we,z:pe,minimized:!1}:we)})},[]),O=S.useCallback(async re=>{const ae=re.map(J=>k.current.find(se=>se.id===J)||R.current[J]).filter(J=>!!J&&J.status==="running");if(ae.length===0)return!0;if(!await h({message:o("session.confirmStop"),danger:!0}))return!1;for(const J of ae)Su(J.id).catch(()=>{});return!0},[o,h]),F=S.useCallback(async re=>{await O([re])&&g(ae=>{const J=li(ae,re);if(!J)return ae;const se=Ui(J.root,re);if(!se)return ae.filter(je=>je.id!==J.id);new Set(gn(se));const pe={...J.colors};delete pe[re];const we={...J.intents};return delete we[re],ae.map(je=>je.id===J.id?{...je,root:se,colors:pe,intents:we}:je)})},[O]),$=S.useCallback(re=>{g(ae=>{const J=li(ae,re);return J?ae.map(se=>se.id===J.id?{...se,minimized:!0}:se):ae})},[]),P=S.useCallback(re=>{g(ae=>{const J=li(ae,re);if(!J)return ae;b.current+=1;const se=b.current;return ae.map(pe=>pe.id===J.id?{...pe,minimized:!1,z:se}:pe)})},[]),H=S.useCallback(re=>!!li(C.current,re),[]),W=S.useCallback(async re=>{const ae=C.current.find(J=>J.id===re);ae&&!await O(gn(ae.root))||g(J=>J.filter(se=>se.id!==re))},[O]),G=S.useCallback(re=>{g(ae=>ae.map(J=>J.id===re?{...J,minimized:!0}:J))},[]);S.useEffect(()=>{const re=J=>{const se=J.detail;!(se!=null&&se.projectId)||!se.groupId||se.projectId===e&&g(pe=>{if(!pe.find($e=>$e.id===se.groupId))return pe;b.current+=1;const je=b.current;return pe.map($e=>$e.id===se.groupId?{...$e,minimized:!1,z:je}:$e)})},ae=async J=>{var je;const se=J.detail;if(!(se!=null&&se.projectId)||!se.groupId||se.projectId!==e)return;const pe=C.current.find($e=>$e.id===se.groupId);if(pe&&!await O(gn(pe.root)))return;const we=(pe==null?void 0:pe.ownerWindowId)||Bt;we!==Bt&&(de.current.delete(we),Me.current.delete(se.groupId),(je=he.current)==null||je.post({t:"group-reclaimed",popoutId:we,groupIds:[se.groupId],reason:"late-return"})),g($e=>$e.filter(Je=>Je.id!==se.groupId))};return window.addEventListener("session-windows:restore",re),window.addEventListener("session-windows:close",ae),()=>{window.removeEventListener("session-windows:restore",re),window.removeEventListener("session-windows:close",ae)}},[e,O]),S.useEffect(()=>{const re=sessionStorage.getItem("pendingSessionRestore");if(re)try{const ae=JSON.parse(re);if(ae.projectId!==e||!ae.groupId)return;sessionStorage.removeItem("pendingSessionRestore"),g(J=>{if(!J.find(we=>we.id===ae.groupId))return J;b.current+=1;const pe=b.current;return J.map(we=>we.id===ae.groupId?{...we,minimized:!1,z:pe}:we)})}catch{}},[e]);const I=S.useCallback(re=>{g(ae=>{if(!ae.find(pe=>pe.id===re))return ae;b.current+=1;const se=b.current;return ae.map(pe=>pe.id===re?{...pe,minimized:!1,z:se}:pe)})},[]),z=S.useCallback((re,ae)=>{g(J=>J.map(se=>se.id===re?{...se,...ae}:se))},[]),U=S.useCallback((re,ae)=>{g(J=>J.map(se=>{if(se.id===re){if(!ae)return se.dock?{...se,dock:void 0}:se;const pe=vl(ae,window.innerWidth,window.innerHeight,Ha());return{...se,...pe,dock:ae}}return ae&&se.dock===ae?{...se,dock:void 0}:se}))},[]),V=S.useCallback((re,ae,J)=>{g(se=>se.map(pe=>pe.id===re?{...pe,root:xS(pe.root,ae,J)}:pe))},[]),q=S.useCallback((re,ae)=>{g(J=>J.map(se=>se.id===re?{...se,root:Ps(se.root,ae)}:se))},[]),oe=S.useCallback((re,ae)=>{g(J=>J.map(se=>se.id===re?{...se,root:eO(se.root,ae)}:se))},[]),ee=S.useCallback((re,ae,J)=>{g(se=>se.map(pe=>pe.id===re?{...pe,root:gS(pe.root,ae,J)}:pe))},[]),Z=S.useCallback((re,ae,J,se)=>{if(se.button!==0||!C.current.find(gt=>gt.id===re))return;se.preventDefault();const we=se.clientX,je=se.clientY;let $e=null;_({groupId:re,sessionId:ae,fromPath:J,startX:we,startY:je,mouseX:we,mouseY:je,hoveredGroupId:null,hoveredPath:null,hoveredRect:null,zone:null,viewportZone:null});const Je=(gt,vt)=>{const Tt=Jy();$e=Tt;const Xe=window.innerWidth,ut=window.innerHeight,Q={x:iu(gt-60,-Au+dl,Xe-dl),y:iu(vt-12,0,ut-Um),w:Au,h:$p};g(ze=>{const ue=ze.find(Ct=>Ct.id===re);if(!ue)return ze;const Fe=Ui(ue.root,ae),Ve=ue.colors[ae]||Fi([]),ht=ue.intents[ae]??{intent:"open",nonce:0};b.current+=1;const Ne=b.current,at={id:Tt,...Q,z:Ne,minimized:!1,root:Nr([ae],ae),colors:{[ae]:Ve},intents:{[ae]:ht},ownerWindowId:Bt},bt=[];for(const Ct of ze)if(Ct.id===re){if(Fe){const qt=new Set(gn(Fe)),an={};for(const vn of Object.keys(Ct.colors))qt.has(vn)&&(an[vn]=Ct.colors[vn]);const Pn={};for(const vn of Object.keys(Ct.intents))qt.has(vn)&&(Pn[vn]=Ct.intents[vn]);bt.push({...Ct,root:Tu(Fe),colors:an,intents:Pn})}}else bt.push(Ct);return bt.push(at),bt})};let qe=!1;const Ee=gt=>{const vt=window.screenX,Tt=window.screenY,Xe=vt+window.outerWidth,ut=Tt+window.outerHeight;return gt.screenX<vt-ru||gt.screenX>Xe+ru||gt.screenY<Tt-ru||gt.screenY>ut+ru},st=gt=>{if(qe)return;const vt=w.current;if(!vt)return;if(!$e)Math.hypot(gt.clientX-we,gt.clientY-je)>=Xy&&Je(gt.clientX,gt.clientY);else{const Fe=window.innerWidth,Ve=window.innerHeight,ht=iu(gt.clientX-60,-640,Fe-dl),Ne=iu(gt.clientY-12,0,Ve-Um);g(at=>at.map(bt=>bt.id===$e?{...bt,x:ht,y:Ne}:bt))}if($e&&Ee(gt)&&C.current.some(Fe=>Fe.id===$e)){const Fe=Oe.current;if(Fe){qe=!0;const Ve=$e;yt(),_(null),Fe(Ve,{atScreenX:gt.screenX,atScreenY:gt.screenY});return}}let Tt=null,Xe=null,ut=null,Q=null;const ze=document.elementsFromPoint(gt.clientX,gt.clientY);for(const Fe of ze){const Ve=Fe.closest("[data-group-id][data-stack-path]");if(!Ve)continue;const ht=Ve.dataset.groupId||"",Ne=Ve.dataset.stackPath||"";if($e?ht===$e:ht===vt.groupId&&Ne===vt.fromPath.join("."))continue;const bt=Ne===""?[]:Ne.split(".").map(Number),Ct=Ve.getBoundingClientRect();Tt=ht,Xe=bt,ut={x:Ct.left,y:Ct.top,w:Ct.width,h:Ct.height},Q=Qu(gt.clientX,gt.clientY,ut);break}const ue=Q||!$e?null:hS(gt.clientX,gt.clientY,window.innerWidth,window.innerHeight);_({...vt,mouseX:gt.clientX,mouseY:gt.clientY,hoveredGroupId:Tt,hoveredPath:Xe,hoveredRect:ut,zone:Q,viewportZone:ue})};let lt=!1;const yt=()=>{lt||(lt=!0,window.removeEventListener("mousemove",st),window.removeEventListener("mouseup",kt),window.removeEventListener("blur",mt),window.removeEventListener("keydown",pt),document.removeEventListener("visibilitychange",dt))},mt=()=>{yt(),_(null)},pt=gt=>{gt.key==="Escape"&&mt()},dt=()=>{document.hidden&&mt()},kt=gt=>{var Xe;yt();const vt=w.current;if(_(null),!vt)return;if(vt.hoveredGroupId&&vt.hoveredPath&&vt.zone){const ut=$e||vt.groupId;te(ut,vt.sessionId,vt.hoveredGroupId,vt.hoveredPath,vt.zone);return}const Tt=vt.viewportZone;if(Tt&&$e&&C.current.some(ut=>ut.id===$e)){const ut=$e;if(Tt==="popout")(Xe=Oe.current)==null||Xe.call(Oe,ut,{atScreenX:gt.screenX,atScreenY:gt.screenY});else if(Tt==="max"){const Q=vl(Tt,window.innerWidth,window.innerHeight,Ha());g(ze=>ze.map(ue=>ue.id===ut?{...ue,x:Q.x,y:Q.y,w:Q.w,h:Q.h}:ue))}else U(ut,Tt);return}};window.addEventListener("mousemove",st),window.addEventListener("mouseup",kt),window.addEventListener("blur",mt),window.addEventListener("keydown",pt),document.addEventListener("visibilitychange",dt)},[]),te=S.useCallback((re,ae,J,se,pe)=>{g(we=>{const je=we.find(pt=>pt.id===re),$e=we.find(pt=>pt.id===J);if(!je||!$e)return we;if(re===J){const pt=ul(je.root,se);if(!pt||pt.kind!=="stack")return we;const dt=pt.tabs.find(Tt=>Tt!==ae);if(!dt)return we;const kt=Ui(je.root,ae);if(!kt)return we;const gt=Zu(kt,dt);if(!gt)return we;let vt;return pe==="center"?vt=Hi(kt,gt,ae):vt=$a(kt,gt,pe,Nr([ae])),vt=Ps(vt,ae),we.map(Tt=>Tt.id!==re?Tt:(b.current+=1,{...Tt,root:vt,z:b.current,minimized:!1}))}const Je=Ui(je.root,ae),qe=je.colors[ae],Ee=je.intents[ae]??{intent:"open",nonce:0};let st;if(pe==="center")st=Hi($e.root,se,ae);else{const pt=Nr([ae]);st=$a($e.root,se,pe,pt)}st=Ps(st,ae);const lt={...$e.colors};lt[ae]||(lt[ae]=qe||Fi(Object.values(lt)));const yt={...$e.intents,[ae]:Ee},mt=[];for(const pt of we)if(pt.id===re){if(Je){const dt=new Set(gn(Je)),kt={};for(const vt of Object.keys(pt.colors))dt.has(vt)&&(kt[vt]=pt.colors[vt]);const gt={};for(const vt of Object.keys(pt.intents))dt.has(vt)&&(gt[vt]=pt.intents[vt]);mt.push({...pt,root:Je,colors:kt,intents:gt})}}else pt.id===J?(b.current+=1,mt.push({...pt,root:st,colors:lt,intents:yt,z:b.current,minimized:!1})):mt.push(pt);return mt})},[]),Y=S.useCallback((re,ae,J,se)=>{g(pe=>{if(re===ae)return pe;const we=pe.find(lt=>lt.id===re),je=pe.find(lt=>lt.id===ae);if(!we||!je||we.root.kind!=="stack")return pe;const $e=we.root;let Je;se==="center"?Je=$e.tabs.reduce((lt,yt)=>Hi(lt,J,yt),je.root):Je=$a(je.root,J,se,$e),Je=Ps(Je,$e.activeTab);const qe={...je.colors,...we.colors},Ee={...je.intents,...we.intents},st=[];for(const lt of pe)lt.id!==re&&(lt.id===ae?(b.current+=1,st.push({...lt,root:Je,colors:qe,intents:Ee,z:b.current,minimized:!1})):st.push(lt));return st})},[]),he=S.useRef(null),de=S.useRef(new Map),[ye,le]=S.useState(null),De=S.useRef(ye);De.current=ye;const Re=S.useRef(null),ve=S.useRef(typeof document<"u"&&document.hasFocus()?Date.now():0);S.useEffect(()=>{const re=()=>{ve.current=Date.now()};window.addEventListener("focus",re);const ae=bS();return()=>{window.removeEventListener("focus",re),ae(),Re.current&&clearTimeout(Re.current)}},[]);const Me=S.useRef(new Map),Oe=S.useRef(null),tt=S.useCallback((re,ae)=>{var st;const J=C.current.find(lt=>lt.id===re);if(!J)return;const se=dO(),pe={...J,ownerWindowId:se,dock:void 0};Me.current.set(re,pe),de.current.set(se,Date.now()),g(lt=>lt.map(yt=>yt.id===re?{...yt,ownerWindowId:se,dock:void 0}:yt)),(st=he.current)==null||st.post({t:"group-handoff",to:se,groupId:re,group:pe});const we=ae&&(typeof ae.atScreenX=="number"||typeof ae.atScreenY=="number"),je=we?Math.max(0,((ae==null?void 0:ae.atScreenX)??window.screenX+J.x)-40):Math.max(0,window.screenX+J.x),$e=we?Math.max(0,((ae==null?void 0:ae.atScreenY)??window.screenY+J.y)-12):Math.max(0,window.screenY+J.y),Je=["popup",`width=${Math.max(400,J.w)}`,`height=${Math.max(300,J.h+40)}`,`left=${je}`,`top=${$e}`].join(","),qe=`/popout/${encodeURIComponent(e)}/${encodeURIComponent(re)}?wid=${encodeURIComponent(se)}`,Ee=window.open(qe,"_blank",Je);if(!Ee){Me.current.delete(re),de.current.delete(se),g(lt=>lt.map(yt=>yt.id===re?{...yt,ownerWindowId:Bt}:yt)),c(o("session.popout.blocked"));return}cO(se,Ee)},[e,o,c]);Oe.current=tt;const nt=S.useCallback(re=>{var se;const ae=C.current.find(pe=>pe.id===re);if(!ae)return;const J=ae.ownerWindowId||Bt;if(J===Bt){I(re);return}(se=he.current)==null||se.post({t:"group-recall",popoutId:J,groupId:re}),setTimeout(()=>{var je;const pe=C.current.find($e=>$e.id===re);if(!pe||(pe.ownerWindowId||Bt)===Bt)return;de.current.delete(J),Me.current.delete(re),(je=he.current)==null||je.post({t:"group-reclaimed",popoutId:J,groupIds:[re],reason:"late-return"}),b.current+=1;const we=b.current;g($e=>$e.map(Je=>Je.id===re?{...Je,ownerWindowId:Bt,minimized:!1,z:we}:Je))},1500)},[I]),ke=S.useCallback(re=>{const ae=li(C.current,re);ae&&nt(ae.id)},[nt]);S.useEffect(()=>{const re=ae=>{const J=ae.detail;!(J!=null&&J.projectId)||!J.groupId||J.projectId!==e||nt(J.groupId)};return window.addEventListener("session-windows:recall",re),()=>window.removeEventListener("session-windows:recall",re)},[e,nt]),S.useEffect(()=>{const re=sessionStorage.getItem("pendingSessionRecall");if(re)try{const ae=JSON.parse(re);if(ae.projectId!==e||!ae.groupId)return;sessionStorage.removeItem("pendingSessionRecall");const J=ae.groupId;setTimeout(()=>nt(J),0)}catch{}},[e,nt]);const fe=S.useCallback(re=>re.kind==="stack"?[]:[0,...fe(re.children[0])],[]),Te=S.useCallback((re,ae,J)=>{const se=ae?C.current.find($e=>$e.id===ae):null,pe=se&&(se.ownerWindowId||Bt)===Bt;if(!se||!pe){A(re,"start");return}const we=(()=>{if(J){const $e=ul(se.root,J);if($e&&$e.kind==="stack")return J}return fe(se.root)})();b.current+=1;const je=b.current;g($e=>$e.map(Je=>{if(Je.id!==se.id)return Je;const qe=Ps(Hi(Je.root,we,re),re);return{...Je,root:qe,z:je,minimized:!1,colors:{...Je.colors,[re]:Fi(Object.values(Je.colors))},intents:{...Je.intents,[re]:{intent:"start",nonce:0}}}}))},[A,fe]),Ce=S.useCallback(async(re,ae)=>{const J=new Date,se=String(J.getHours()).padStart(2,"0"),pe=String(J.getMinutes()).padStart(2,"0"),we=String(J.getSeconds()).padStart(2,"0"),je=await Sm(e,{title:`Shell ${se}:${pe}:${we}`,cli_tool:"raw-shell",use_worktree:!1,memory_inject_mode:"none"});return f==null||f(je),Te(je.id,re,ae),je.id},[e,f,Te]);S.useEffect(()=>{const re=Pp();he.current=re;const ae=se=>{var pe;if(se.t==="hello"){const we=Me.current.get(se.groupId);if(we&&we.ownerWindowId===se.from)re.post({t:"group-handoff",to:se.from,groupId:se.groupId,group:we});else{const je=C.current.find($e=>$e.id===se.groupId);je&&je.ownerWindowId===se.from&&re.post({t:"group-handoff",to:se.from,groupId:se.groupId,group:je})}}else if(se.t==="group-return"||se.t==="bye")if(se.t==="group-return"){const we=se.group;we&&we.id===se.groupId&&(Me.current.delete(se.groupId),de.current.delete(se.from),se.projectId&&se.projectId!==e&&bO(se.projectId,se.groupId),g(je=>{const $e=je.find(qe=>qe.id===se.groupId),Je={...we,ownerWindowId:Bt,dock:void 0};return $e?je.map(qe=>qe.id===se.groupId?Je:qe):[...je,Je]}))}else de.current.delete(se.from),g(we=>we.map(je=>je.ownerWindowId===se.from?{...je,ownerWindowId:Bt}:je));else if(se.t==="group-close")Me.current.delete(se.groupId),g(we=>we.filter(je=>je.id!==se.groupId));else if(se.t==="heartbeat")de.current.set(se.from,Date.now());else if(se.t==="group-update"){const we=se.patch;g(je=>je.map($e=>$e.id===se.groupId?{...$e,...we}:$e))}else if(se.t==="dock-probe"){if(document.visibilityState!=="visible")return;const we=Ru(se.x,se.y),je=Mu(we)?Lu(we.x,we.y):null;if(je){const $e=De.current;(!$e||$e.zone!==je.zone||$e.groupId!==je.groupId||$e.path.join(".")!==je.path.join("."))&&le({rect:je.rect,zone:je.zone,path:je.path,groupId:je.groupId}),Re.current&&clearTimeout(Re.current),Re.current=setTimeout(()=>le(null),800),re.post({t:"dock-probe-result",from:Bt,to:se.from,hit:!0,focusAt:ve.current})}else De.current&&le(null),re.post({t:"dock-probe-result",from:Bt,to:se.from,hit:!1,focusAt:ve.current})}else if(se.t==="dock-end")le(null);else if(se.t==="dock-commit"&&se.to===Bt){const we=Ru(se.x,se.y),je=Mu(we)?Lu(we.x,we.y):null,$e=je&&je.zone?je:(pe=De.current)!=null&&pe.zone?De.current:null;let Je=!1;const qe=C.current.filter(Ee=>(Ee.ownerWindowId||Bt)===Bt);if($e&&$e.zone&&!li(qe,se.sessionId)){const Ee=C.current.find(lt=>lt.id===$e.groupId),st=Ee?ul(Ee.root,$e.path):null;if(Ee&&st&&st.kind==="stack"){Je=!0;const lt=$e.zone,yt=$e.path;b.current+=1;const mt=b.current;g(pt=>pt.map(dt=>{if(dt.id!==Ee.id)return dt;const kt=lt==="center"?Hi(dt.root,yt,se.sessionId):$a(dt.root,yt,lt,Nr([se.sessionId])),gt=Ps(kt,se.sessionId),vt={...dt.colors};vt[se.sessionId]||(vt[se.sessionId]=se.color||Fi(Object.values(vt)));const Tt={...dt.intents,[se.sessionId]:se.intentInfo??{intent:"open",nonce:0}};return{...dt,root:gt,colors:vt,intents:Tt,z:mt,minimized:!1}}))}}le(null),re.post({t:"dock-commit-ack",from:Bt,to:se.from,sessionId:se.sessionId,accepted:Je})}},J=re.subscribe(ae);return()=>{J(),re.close(),he.current=null}},[e]),S.useEffect(()=>{const re=Date.now();for(const ae of m.groups)ae.ownerWindowId&&ae.ownerWindowId!==Bt&&de.current.set(ae.ownerWindowId,re)},[]),S.useEffect(()=>{const re=async()=>{var $e;const J=Date.now(),se=[];for(const[Je,qe]of de.current.entries())J-qe>vS&&se.push(Je);if(se.length===0)return;const pe=await yS(),we=se.filter(Je=>pe.has(Je)?(de.current.set(Je,J),!1):!0);if(we.length===0)return;for(const Je of we)de.current.delete(Je);const je=new Set(we);for(const Je of C.current)Je.ownerWindowId&&je.has(Je.ownerWindowId)&&Me.current.delete(Je.id);for(const Je of we){const qe=C.current.filter(Ee=>Ee.ownerWindowId===Je).map(Ee=>Ee.id);qe.length>0&&(($e=he.current)==null||$e.post({t:"group-reclaimed",popoutId:Je,groupIds:qe,reason:"heartbeat-timeout"}))}g(Je=>Je.map(qe=>qe.ownerWindowId&&we.includes(qe.ownerWindowId)?{...qe,ownerWindowId:Bt}:qe))},ae=setInterval(()=>{re()},Ip);return()=>clearInterval(ae)},[]);const Ge=S.useCallback((re,ae)=>{i({type:"session:terminal-input",sessionId:re,input:ae})},[i]),Ze=S.useCallback(()=>{var J,se;const re=C.current.filter(pe=>(pe.ownerWindowId||Bt)===Bt).slice().sort((pe,we)=>we.z-pe.z),ae=[];for(const pe of re)for(const we of gn(pe.root)){const je=((J=k.current.find($e=>$e.id===we))==null?void 0:J.title)||((se=R.current[we])==null?void 0:se.title)||we;ae.push({sessionId:we,label:je})}return ae},[]),be=S.useCallback(async(re,ae)=>{const se=C.current.filter(we=>!we.minimized&&(we.ownerWindowId||Bt)===Bt).reduce((we,je)=>we&&we.z>=je.z?we:je,null),pe=await Sm(e,{title:ae||"",description:re,use_worktree:!1,memory_inject_mode:"none"});f==null||f(pe),Te(pe.id,(se==null?void 0:se.id)??null)},[e,f,Te]),Be=S.useMemo(()=>({openOrFocus:A,close:F,focus:B,minimize:$,restore:P,isOpen:H,recallPopout:ke,closeGroup:W,minimizeGroup:G,restoreGroup:I,setGroupGeometry:z,setGroupDock:U,setSplitSizes:V,setActiveTab:q,applyLayoutPreset:oe,reorderTab:ee,beginTabDrag:Z,dockGroup:Y,popOutGroup:tt,createRawShellTab:Ce,sendToSession:Ge,listOpenTerminals:Ze,sendToNewTerminal:be}),[A,F,B,$,P,H,ke,W,G,I,z,U,V,q,oe,ee,Z,Y,tt,Ce,Ge,Ze,be]),ne=S.useMemo(()=>{const re={};for(const ae of d){const se=(ae.ownerWindowId||Bt)!==Bt?"popped":ae.minimized?"minimized":"floating";for(const pe of gn(ae.root))re[pe]=se}return re},[d]);S.useEffect(()=>{const re=ae=>{const J=/Mac|iPhone|iPad|iPod/.test(navigator.platform),se=J?ae.metaKey:ae.ctrlKey,pe=J?ae.ctrlKey:ae.metaKey;if(!se||pe||ae.altKey||ae.shiftKey||ae.key.toLowerCase()!=="t")return;ae.preventDefault();const je=C.current.filter($e=>!$e.minimized&&($e.ownerWindowId||Bt)===Bt).reduce(($e,Je)=>$e&&$e.z>=Je.z?$e:Je,null);Ce((je==null?void 0:je.id)??null).catch(()=>{})};return window.addEventListener("keydown",re),()=>window.removeEventListener("keydown",re)},[Ce]);const _e=S.useMemo(()=>{const re=new Map;for(const ae of Object.values(y))re.set(ae.id,ae);for(const ae of s)re.set(ae.id,ae);return re},[s,y]),X=d.filter(re=>!re.minimized&&(re.ownerWindowId||Bt)===Bt),me=X.reduce((re,ae)=>ae.z>re.z?{id:ae.id,z:ae.z}:re,{id:null,z:-1/0}).id;return t.jsx(Hp.Provider,{value:Be,children:t.jsxs(wS.Provider,{value:ne,children:[p,(()=>{const re=new Map(X.slice().sort((ae,J)=>ae.z-J.z).map((ae,J)=>[ae.id,J+1]));return X.map(ae=>{const J=X.filter(se=>se.id!==ae.id).map(({x:se,y:pe,w:we,h:je})=>({x:se,y:pe,w:we,h:je}));return t.jsx(oO,{group:ae,sessionsById:_e,neighbors:J,isTopmost:ae.id===me,zIndex:re.get(ae.id)??1,sendMessage:i,subscribeBinary:a,onEvent:u},ae.id)})})(),x&&x.hoveredRect&&t.jsx(bl,{targetRect:x.hoveredRect,activeZone:x.zone}),x&&!x.zone&&Math.hypot(x.mouseX-x.startX,x.mouseY-x.startY)>=Xy&&t.jsx(mS,{activeZone:x.viewportZone}),ye&&t.jsx(bl,{targetRect:ye.rect,activeZone:ye.zone})]})})}function _O(e){if(!e)return[];try{const s=JSON.parse(e);return Array.isArray(s)?s.map(String).filter(Boolean):[]}catch{return[]}}const SO={pending:"bg-warm-400",running:"bg-status-success",completed:"bg-accent",failed:"bg-status-error",stopped:"bg-status-warning"};function kO({projectId:e,sessions:s,projectCliTool:i,isGitRepo:a,projectUseWorktree:u,projectDefaultBranch:f,onAddSession:p,onUpdateSession:o,onStopSession:c,onDeleteSession:h,onCleanupSession:m}){const{t:d}=ft(),{confirm:g}=qn(),{openOrFocus:b,recallPopout:C}=_S(),k=mO(),[x,_]=S.useState(!1),[w,y]=S.useState(!1),[E,R]=S.useState(null),[j,T]=S.useState(!1),[N,D]=S.useState(null),[A,B]=S.useState([]),[O,F]=S.useState(""),[$,P]=S.useState(null);S.useEffect(()=>{let oe=!1;return cp().then(ee=>{oe||B(ee)}).catch(()=>{}),()=>{oe=!0}},[]),S.useEffect(()=>{if(!a)return;let oe=!1;return s1(e).then(ee=>{oe||F(ee.branch||"")}).catch(()=>{}),()=>{oe=!0}},[e,a]);const H=S.useMemo(()=>{const oe=new Map;for(const ee of A)oe.set(ee.id,ee);return oe},[A]),W=S.useMemo(()=>E?s.find(oe=>oe.id===E)??null:null,[E,s]),G=S.useMemo(()=>{if(W)return{title:W.title,description:W.description??"",cliTool:W.cli_tool??"",useWorktree:W.use_worktree===1,memoryInjectMode:W.memory_inject_mode??"none",memoryNodeIds:pz(W.memory_node_ids??null),memoryRawFilePaths:_O(W.memory_raw_file_paths??null),tagId:W.tag_id??null}},[W]),I=S.useCallback(()=>{R(null),D(null),_(oe=>!oe)},[]),z=S.useCallback(oe=>{_(!1),D(null),R(oe)},[]),U=S.useCallback(()=>{_(!1),R(null),D(null)},[]),V=S.useCallback(async(oe,ee,Z,te,Y,he,de,ye)=>{y(!0);try{const le=await Sm(e,{title:oe,description:ee||void 0,cli_tool:Z,use_worktree:te,memory_inject_mode:Y,memory_node_ids:he,memory_raw_file_paths:de,tag_id:ye??null});p(le),_(!1)}finally{y(!1)}},[e,p]),q=S.useCallback(async(oe,ee,Z,te,Y,he,de,ye)=>{if(E){T(!0),D(null);try{const le=await M4(E,{title:oe,description:ee||void 0,cli_tool:Z,use_worktree:te,memory_inject_mode:Y,memory_node_ids:he,memory_raw_file_paths:de,tag_id:ye??null});o(le),R(null)}catch(le){D(le instanceof Error?le.message:String(le))}finally{T(!1)}}},[E,o]);return t.jsxs("div",{className:"space-y-4 min-h-[50vh]",onContextMenu:oe=>{gi(oe)||(oe.preventDefault(),P({x:oe.clientX,y:oe.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:I,className:"btn-primary text-xs py-2",disabled:w,children:["+ ",d("session.new")]})]}),x&&t.jsx(Ey,{projectId:e,onSave:V,onCancel:U,projectCliTool:i,isGitRepo:a,projectUseWorktree:u}),G&&E&&t.jsxs("div",{className:"space-y-2",children:[t.jsx(Ey,{projectId:e,initial:G,onSave:q,onCancel:U,projectCliTool:i,isGitRepo:a},E),(j||N)&&t.jsxs("div",{className:"text-xs px-1",children:[j&&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(Yi,{icon:ml,title:d("session.empty"),description:d("session.emptyHint")})}):t.jsx("div",{className:"space-y-3",children:s.map((oe,ee)=>{const Z=["pending","failed","stopped","completed"].includes(oe.status),te=oe.status==="running",Y=oe.status!=="running",he=["stopped","failed","completed"].includes(oe.status)&&(oe.cli_tool??"claude")==="claude"&&!!oe.worktree_path,de=E===oe.id,ye=k[oe.id]??"closed",le=ye==="popped";return t.jsx("div",{className:`card overflow-hidden ${de?"border-l-4 border-accent bg-warm-100/30":""}`,onContextMenu:De=>{gi(De)||(De.preventDefault(),De.stopPropagation(),P({x:De.clientX,y:De.clientY,sessionId:oe.id}))},children:t.jsx("div",{className:"p-4 cursor-pointer hover:bg-warm-50/50 transition-colors",onClick:()=>le?C(oe.id):b(oe.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:[oe.tag_id&&H.get(oe.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:`${H.get(oe.tag_id).color}22`,color:H.get(oe.tag_id).color},children:[t.jsx("span",{className:"w-2 h-2 rounded-full",style:{backgroundColor:H.get(oe.tag_id).color}}),H.get(oe.tag_id).name]}),t.jsx("h3",{className:"text-sm font-semibold text-warm-700 truncate",children:oe.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 ${SO[oe.status]||"bg-warm-400"}`}),d(`status.${oe.status}`)||oe.status]}),ye!=="closed"&&t.jsxs("span",{className:"inline-flex items-center gap-1 text-2xs text-warm-400 whitespace-nowrap",title:le?d("session.dock.poppedHint"):void 0,children:[le?t.jsx(Dr,{size:12}):t.jsx("span",{"aria-hidden":"true",children:"·"}),d(`session.windowState.${ye}`)]})]}),oe.description&&t.jsx("p",{className:"text-xs text-warm-400 mt-1 line-clamp-1",children:oe.description}),t.jsxs("div",{className:"flex items-center gap-2 mt-1",children:[t.jsx("span",{className:"text-2xs text-warm-300",children:oe.cli_tool||"claude"}),(oe.branch_name||a&&(O||f))&&t.jsxs("span",{className:"text-2xs text-accent/70 flex items-center gap-0.5",children:[t.jsx(Vi,{size:12}),oe.branch_name||O||f]})]})]}),t.jsxs("div",{className:"flex gap-1",onClick:De=>De.stopPropagation(),children:[le&&t.jsx("button",{onClick:()=>C(oe.id),className:"p-1.5 text-accent hover:bg-accent/10 rounded-md transition-colors",title:d("session.recallToMain"),children:t.jsx(qi,{size:16})}),Z&&t.jsx("button",{onClick:()=>b(oe.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(Tr,{size:16})}),he&&t.jsx("button",{onClick:()=>b(oe.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(mi,{size:16})}),t.jsx("button",{onClick:()=>z(oe.id),disabled:!Y,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(Y?"session.edit":"session.editDisabledRunning"),children:t.jsx(um,{size:16})}),te&&t.jsx("button",{onClick:()=>c(oe.id),className:"p-1.5 text-status-warning hover:bg-status-warning/10 rounded-md transition-colors",title:d("session.stop"),children:t.jsx(Ki,{size:16})}),oe.status!=="running"&&(!!oe.worktree_path||!!oe.branch_name)&&t.jsx("button",{onClick:async()=>{const De=oe.branch_name?await g({message:d("cleanup.confirmDeleteBranch").replace("{name}",oe.branch_name),danger:!0}):!1;m(oe.id,De)},className:"p-1.5 text-warm-400 hover:text-status-warning rounded-md transition-colors",title:d("session.cleanup"),children:t.jsx(xu,{size:16})}),t.jsx("button",{onClick:()=>h(oe.id),className:"p-1.5 text-warm-400 hover:text-status-error rounded-md transition-colors",title:d("session.delete"),children:t.jsx(An,{size:16})})]})]})})},oe.id)})}),$&&(()=>{const oe=()=>P(null),ee=$.sessionId?s.find(Re=>Re.id===$.sessionId):void 0;if(!ee)return t.jsx(ir,{x:$.x,y:$.y,onClose:oe,children:t.jsxs("button",{type:"button",onClick:()=>{R(null),D(null),_(!0)},className:sn,children:[t.jsx(yn,{size:14}),d("session.new")]})});const Z=["pending","failed","stopped","completed"].includes(ee.status),te=ee.status==="running",Y=ee.status!=="running",he=["stopped","failed","completed"].includes(ee.status)&&(ee.cli_tool??"claude")==="claude"&&!!ee.worktree_path,de=ee.status!=="running"&&(!!ee.worktree_path||!!ee.branch_name),ye=k[ee.id]??"closed",le=ye==="popped",De=d(le?"session.recallToMain":ye==="minimized"?"session.restoreWindow":ye==="floating"?"session.focusWindow":"session.openWindow");return t.jsxs(ir,{x:$.x,y:$.y,onClose:oe,children:[t.jsxs("button",{type:"button",onClick:()=>le?C(ee.id):b(ee.id,"open"),className:sn,children:[le?t.jsx(qi,{size:14}):t.jsx(ml,{size:14}),De]}),Z&&t.jsxs("button",{type:"button",onClick:()=>b(ee.id,"start"),className:sn,children:[t.jsx(Tr,{size:14}),d("session.start")]}),he&&t.jsxs("button",{type:"button",onClick:()=>b(ee.id,"resume"),className:sn,title:d("session.resumeHint")||d("session.resume"),children:[t.jsx(mi,{size:14}),d("session.resume")]}),Y&&t.jsxs("button",{type:"button",onClick:()=>z(ee.id),className:sn,children:[t.jsx(um,{size:14}),d("session.edit")]}),te&&t.jsxs("button",{type:"button",onClick:()=>c(ee.id),className:sn,children:[t.jsx(Ki,{size:14}),d("session.stop")]}),de&&t.jsxs("button",{type:"button",onClick:async()=>{const Re=ee.branch_name?await g({message:d("cleanup.confirmDeleteBranch").replace("{name}",ee.branch_name),danger:!0}):!1;m(ee.id,Re)},className:sn,children:[t.jsx(xu,{size:14}),d("session.cleanup")]}),t.jsx(W_,{}),t.jsxs("button",{type:"button",onClick:()=>h(ee.id),className:Mp,children:[t.jsx(An,{size:14}),d("session.delete")]})]})})()]})}const zu={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"}},CO=Object.keys(zu),Ou={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 Wa(e){const s=zu[e]||zu.default;return`${s.bg} ${s.text}`}function Up({src:e,alt:s,onClose:i}){return S.useEffect(()=>{const a=u=>{u.key==="Escape"&&i()};return window.addEventListener("keydown",a),()=>window.removeEventListener("keydown",a)},[i]),rn.createPortal(t.jsxs("div",{className:"fixed inset-0 z-tooltip flex items-center justify-center p-6",style:{backgroundColor:"rgba(0,0,0,0.85)"},onClick:i,children:[t.jsx("button",{type:"button",onClick:i,className:"absolute top-4 right-4 h-9 w-9 rounded-full bg-white/10 text-white flex items-center justify-center hover:bg-white/20 transition-colors","aria-label":"close",children:t.jsx(Xt,{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 qm({anchorRef:e,width:s,onClose:i,className:a,style:u,children:f}){const p=S.useRef(null),[o,c]=S.useState(null);return S.useLayoutEffect(()=>{const h=e.current;if(!h)return;const m=h.getBoundingClientRect();let d=m.left;d+s>window.innerWidth-8&&(d=Math.max(8,window.innerWidth-8-s)),d<8&&(d=8),c({top:m.bottom+4,left:d})},[e,s]),S.useEffect(()=>{const h=d=>{var b,C;const g=d.target;(b=p.current)!=null&&b.contains(g)||(C=e.current)!=null&&C.contains(g)||i()},m=()=>i();return document.addEventListener("mousedown",h),window.addEventListener("scroll",m,!0),window.addEventListener("resize",m),()=>{document.removeEventListener("mousedown",h),window.removeEventListener("scroll",m,!0),window.removeEventListener("resize",m)}},[i,e]),o?rn.createPortal(t.jsx("div",{ref:p,className:a,style:{position:"fixed",top:o.top,left:o.left,width:s,...u},children:f}),document.body):null}const Qy={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 jO({item:e,tagColors:s,existingTags:i,onSave:a,onDelete:u,onConvertToTodo:f,onConvertToSchedule:p,onConvertToSession:o,onUpdateTag:c}){var ne,_e;const{t:h}=ft(),{confirm:m}=qn(),[d,g]=S.useState(!1),[b,C]=S.useState(!1),[k,x]=S.useState(!1),_=S.useRef(null),w=S.useRef(null),[y,E]=S.useState({top:0,left:0}),[R,j]=S.useState(e.title),[T,N]=S.useState(e.description??""),[D,A]=S.useState(e.priority),[B,O]=S.useState(e.due_date??""),[F,$]=S.useState(e.status),[P,H]=S.useState(()=>{try{return e.tags?JSON.parse(e.tags):[]}catch{return[]}}),[W,G]=S.useState(""),[I,z]=S.useState(!1),[U,V]=S.useState(null),[q,oe]=S.useState(null),ee=S.useRef(null),Z=S.useRef(null),[te,Y]=S.useState(()=>{try{return e.images?JSON.parse(e.images):[]}catch{return[]}}),he=S.useRef(null);S.useEffect(()=>{j(e.title),N(e.description??""),A(e.priority),O(e.due_date??""),$(e.status);try{H(e.tags?JSON.parse(e.tags):[])}catch{H([])}try{Y(e.images?JSON.parse(e.images):[])}catch{Y([])}},[e]);const de=P,ye=e.status==="moved",le=e.due_date&&new Date(e.due_date)<new Date&&!ye&&e.status!=="done",De=S.useCallback(X=>{a(e.id,X)},[e.id,a]),Re=()=>{const X=R.trim();X&&X!==e.title?De({title:X}):j(e.title)},ve=()=>{const X=T.trim();X!==(e.description??"")&&De({description:X||void 0})},Me=X=>{A(X),X!==e.priority&&De({priority:X})},Oe=X=>{O(X),X!==(e.due_date??"")&&De({due_date:X||void 0})},tt=X=>{const me=X;$(me),me!==e.status&&De({status:me})},nt=X=>{H(X);const me=(()=>{try{return e.tags?JSON.parse(e.tags):[]}catch{return[]}})();JSON.stringify(X)!==JSON.stringify(me)&&De({tags:X.length>0?JSON.stringify(X):void 0})},ke=X=>{var re;const me=X.trim();if(me&&!P.includes(me)&&(nt([...P,me]),!s.has(me)&&c)){const ae=["blue","green","orange","purple","pink","red","yellow","brown"],J=ae[s.size%ae.length];c(me,{color:J})}G(""),(re=ee.current)==null||re.focus()},fe=X=>nt(P.filter(me=>me!==X)),Te=i.filter(X=>!P.includes(X)&&(!W||X.toLowerCase().includes(W.toLowerCase()))),Ce=S.useCallback(X=>{const me=Array.from(X).filter(J=>J.type.startsWith("image/")),re=[];let ae=0;for(const J of me){const se=new FileReader;se.onload=()=>{re.push({name:J.name,data:se.result}),ae++,ae===me.length&&M1(e.id,re).then(pe=>Y(pe.images))},se.readAsDataURL(J)}},[e.id]),Ge=S.useCallback(X=>{var ae;const me=(ae=X.clipboardData)==null?void 0:ae.items;if(!me)return;const re=[];for(let J=0;J<me.length;J++)if(me[J].type.startsWith("image/")){const se=me[J].getAsFile();se&&re.push(se)}re.length!==0&&(X.preventDefault(),Ce(re))},[Ce]),Ze=S.useCallback(X=>{var me;X.preventDefault(),X.stopPropagation(),(me=X.dataTransfer)!=null&&me.files&&Ce(X.dataTransfer.files)},[Ce]),be=S.useCallback(X=>{A1(e.id,X).then(()=>{Y(me=>me.filter(re=>re.id!==X))})},[e.id]),Be=S.useCallback(()=>{if(!_.current)return;const X=_.current.getBoundingClientRect(),me=window.innerWidth,re=window.innerHeight;let ae=X.bottom+4;const J=w.current;if(J){const se=J.offsetWidth,pe=J.offsetHeight;let we=X.right-se;we<8&&(we=8),we+se>me-8&&(we=me-8-se),ae+pe>re-8&&(ae=X.top-pe-4),E({top:ae,left:we}),x(!0)}else E({top:ae,left:Math.max(8,X.right-180)})},[]);return S.useEffect(()=>{if(!d){x(!1);return}Be();const X=requestAnimationFrame(Be),me=re=>{var J,se;const ae=re.target;(J=_.current)!=null&&J.contains(ae)||(se=w.current)!=null&&se.contains(ae)||g(!1)};return document.addEventListener("mousedown",me),window.addEventListener("scroll",Be,!0),window.addEventListener("resize",Be),()=>{cancelAnimationFrame(X),document.removeEventListener("mousedown",me),window.removeEventListener("scroll",Be,!0),window.removeEventListener("resize",Be)}},[d,Be]),t.jsxs("div",{className:`${ye?"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(!b),children:[t.jsx(Es,{size:14,className:`text-warm-400 transition-transform duration-200 flex-shrink-0 ${b?"rotate-90":""}`,onClick:X=>{X.stopPropagation(),C(!b)}}),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}),ye&&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(Un,{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(BE,{size:12}),h("planner.fromDiscussion")]})]}),t.jsxs("div",{className:"hidden sm:flex items-center gap-1 w-[160px] flex-shrink-0 overflow-hidden",children:[te.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(qa,{size:12}),te.length]}),de.map(X=>t.jsx("span",{className:`px-2 py-0.5 rounded-md text-2xs font-medium whitespace-nowrap ${Wa(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 ${((ne=Qy[e.priority])==null?void 0:ne.style)??"text-warm-300"}`,children:((_e=Qy[e.priority])==null?void 0:_e.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 ${le?"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 ${Ou[e.status]||Ou.pending}`,children:h(`plannerStatus.${e.status}`)})}),t.jsxs("div",{className:"w-8 flex-shrink-0",children:[t.jsx("button",{ref:_,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(np,{size:14})}),d&&rn.createPortal(t.jsxs("div",{ref:w,className:"fixed z-tooltip min-w-[160px] rounded-xl py-1 shadow-elevated",style:{top:y.top,left:y.left,opacity:k?1:0,backgroundColor:"var(--color-bg-card)",border:"1px solid var(--color-border)"},onClick:()=>g(!1),children:[!ye&&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(Uw,{size:12})," ",h("planner.convertToTask")]}),t.jsxs("button",{onClick:p,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(Wi,{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(pi,{size:12})," ",h("planner.convertToTerminal")]})]}),t.jsxs("button",{onClick:async()=>{await m({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(An,{size:12})," ",h("planner.delete")]})]}),document.body)]})]}),b&&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=>j(X.target.value),onBlur:Re,onKeyDown:X=>{X.key==="Enter"&&(X.preventDefault(),Re(),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:T,onChange:X=>N(X.target.value),onPaste:Ge,onDrop:Ze,onDragOver:X=>{X.preventDefault(),X.stopPropagation()},onBlur:ve}),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=he.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(qa,{size:12}),h("plannerForm.addImage")]}),t.jsx("span",{className:"text-[10px] text-warm-300",children:h("plannerForm.pasteHint")})]}),t.jsx("input",{ref:he,type:"file",accept:"image/*",multiple:!0,className:"hidden",onChange:X=>{X.target.files&&Ce(X.target.files),X.target.value=""}}),te.length>0&&t.jsx("div",{className:"flex flex-wrap gap-2",children:te.map(X=>t.jsxs("div",{className:"relative group",children:[t.jsx("img",{src:ku(e.id,X.id),alt:X.originalName,onClick:()=>oe(ku(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:()=>be(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(Xt,{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:[P.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 ${Wa(s.get(X)||"default")}`,onClick:me=>{Z.current=me.currentTarget,V(U===X?null:X)},children:[X,t.jsx("button",{onClick:me=>{me.stopPropagation(),fe(X)},className:"opacity-60 hover:opacity-100",children:t.jsx(Xt,{size:12})})]}),U===X&&t.jsxs(qm,{anchorRef:Z,width:180,onClose:()=>V(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:CO.map(me=>t.jsx("button",{onClick:async()=>{c&&await c(X,{color:me}),V(null)},className:`aspect-square rounded-md flex items-center justify-center transition-all ${s.get(X)===me?"ring-2 ring-accent ring-offset-1":"hover:scale-110"}`,title:h(`plannerTag.color.${me}`),children:t.jsx("div",{className:`w-5 h-5 rounded-md ${zu[me].swatch}`})},me))})]})]},X)),t.jsxs("div",{className:"relative",children:[t.jsx("input",{ref:ee,className:"bg-transparent text-xs outline-none w-24",style:{color:"var(--color-text-primary)"},placeholder:"+",value:W,onChange:X=>{G(X.target.value),z(!0)},onKeyDown:X=>{(X.key==="Enter"||X.key===",")&&W.trim()&&(X.preventDefault(),ke(W.replace(",",""))),X.key==="Backspace"&&!W&&P.length>0&&fe(P[P.length-1])},onFocus:()=>z(!0),onBlur:()=>setTimeout(()=>z(!1),150)}),I&&Te.length>0&&t.jsx(qm,{anchorRef:ee,width:160,onClose:()=>z(!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:Te.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 ${Wa(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:D,onChange:X=>Me(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:B,onChange:X=>Oe(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:F,onChange:X=>tt(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")})]})]})]})]})}),q&&t.jsx(Up,{src:q,onClose:()=>oe(null)})]})}let EO=0;function NO({existingTags:e,editItem:s,initialDueDate:i,onSave:a,onCancel:u,onUpdateTag:f}){const{t:p}=ft(),[o,c]=S.useState(""),[h,m]=S.useState(""),[d,g]=S.useState([]),[b,C]=S.useState(""),[k,x]=S.useState(i??""),[_,w]=S.useState(0),[y,E]=S.useState("pending"),[R,j]=S.useState(!1),[T,N]=S.useState(!1),[D,A]=S.useState([]),[B,O]=S.useState([]),[F,$]=S.useState(null),P=S.useRef(null),H=S.useRef(null),W=S.useRef(null),[G,I]=S.useState(new Map),z=new Map([...e.map(le=>[le.name,le.color]),...G]),U=["blue","green","orange","purple","pink","red","yellow","brown"];S.useEffect(()=>{var le;if(s){c(s.title),m(s.description??""),g(s.tags?JSON.parse(s.tags):[]),x(s.due_date??""),w(s.priority),E(s.status);try{O(s.images?JSON.parse(s.images):[])}catch{O([])}}(le=P.current)==null||le.focus()},[s]);const V=e.filter(le=>!d.includes(le.name)&&(!b||le.name.toLowerCase().includes(b.toLowerCase()))),q=le=>{var Re;const De=le.trim();De&&!d.includes(De)&&g(ve=>{const Me=[...ve,De];if(!z.has(De)){const Oe=U[z.size%U.length];I(tt=>new Map([...tt,[De,Oe]]))}return Me}),C(""),N(!0),(Re=H.current)==null||Re.focus()},oe=le=>g(d.filter(De=>De!==le)),ee=S.useCallback(le=>{const De=Array.from(le).filter(Re=>Re.type.startsWith("image/"));for(const Re of De){const ve=new FileReader;ve.onload=()=>{const Me=ve.result,Oe=`pending-${++EO}`;A(tt=>[...tt,{id:Oe,name:Re.name,data:Me,preview:Me}])},ve.readAsDataURL(Re)}},[]),Z=S.useCallback(le=>{var ve;const De=(ve=le.clipboardData)==null?void 0:ve.items;if(!De)return;const Re=[];for(let Me=0;Me<De.length;Me++)if(De[Me].type.startsWith("image/")){const Oe=De[Me].getAsFile();Oe&&Re.push(Oe)}Re.length!==0&&(le.preventDefault(),ee(Re))},[ee]),te=S.useCallback(le=>{var De;le.preventDefault(),le.stopPropagation(),(De=le.dataTransfer)!=null&&De.files&&ee(le.dataTransfer.files)},[ee]),Y=le=>A(De=>De.filter(Re=>Re.id!==le)),he=le=>{s&&A1(s.id,le),O(De=>De.filter(Re=>Re.id!==le))},de=B.length+D.length,ye=async()=>{if(o.trim()){j(!0);try{const le=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?{status:y}:{}});if(f&&G.size>0&&await Promise.all([...G.entries()].map(([De,Re])=>f(De,{color:Re}))),D.length>0){const De=(s==null?void 0:s.id)??(le==null?void 0:le.id);De&&await M1(De,D.map(Re=>({name:Re.name,data:Re.data})))}}finally{j(!1)}}};return t.jsxs("div",{className:"card p-5",style:{borderColor:"var(--color-accent)",borderWidth:"1px"},children:[t.jsx("input",{ref:P,className:"input-field text-sm w-full mb-3",placeholder:p("plannerForm.titlePlaceholder"),value:o,onChange:le=>c(le.target.value),onKeyDown:le=>{le.key==="Enter"&&le.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:p("plannerForm.descPlaceholder"),value:h,onChange:le=>m(le.target.value),onPaste:Z,onDrop:te,onDragOver:le=>{le.preventDefault(),le.stopPropagation()}}),t.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[t.jsxs("button",{type:"button",onClick:()=>{var le;return(le=W.current)==null?void 0:le.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(qa,{size:14}),p("plannerForm.addImage")]}),t.jsx("span",{className:"text-[10px] text-warm-300",children:p("plannerForm.pasteHint")})]}),t.jsx("input",{ref:W,type:"file",accept:"image/*",multiple:!0,className:"hidden",onChange:le=>{le.target.files&&ee(le.target.files),le.target.value=""}}),de>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:p("plannerForm.images")}),t.jsxs("span",{className:"text-[10px] text-warm-400",children:["(",de,")"]})]}),t.jsxs("div",{className:"flex flex-wrap gap-2",children:[B.map(le=>t.jsxs("div",{className:"relative group",children:[t.jsx("img",{src:s?ku(s.id,le.id):"",alt:le.originalName,onClick:()=>s&&$(ku(s.id,le.id)),className:"h-20 w-20 object-cover rounded-lg border border-warm-200 cursor-zoom-in"}),t.jsx("button",{type:"button",onClick:()=>he(le.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(Xt,{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:le.originalName})})]},le.id)),D.map(le=>t.jsxs("div",{className:"relative group",children:[t.jsx("img",{src:le.preview,alt:le.name,onClick:()=>$(le.preview),className:"h-20 w-20 object-cover rounded-lg border border-accent/30 cursor-zoom-in"}),t.jsx("button",{type:"button",onClick:()=>Y(le.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(Xt,{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:le.name})})]},le.id))]})]}),t.jsxs("div",{className:"mb-4",children:[t.jsx("label",{className:"text-xs font-medium text-warm-500 mb-1.5 block",children:p("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(le=>t.jsxs("span",{className:`inline-flex items-center gap-1 px-2 py-0.5 rounded-md text-[11px] font-medium ${Wa(z.get(le)||"default")}`,children:[le,t.jsx("button",{onClick:()=>oe(le),className:"opacity-60 hover:opacity-100",children:t.jsx(Xt,{size:12})})]},le)),t.jsxs("div",{className:"relative flex-1 min-w-[120px]",children:[t.jsx("input",{ref:H,className:"bg-transparent text-sm outline-none w-full",style:{color:"var(--color-text-primary)"},placeholder:d.length===0?p("plannerForm.tagsPlaceholder"):"",value:b,onChange:le=>{C(le.target.value),N(!0)},onKeyDown:le=>{(le.key==="Enter"||le.key===",")&&b.trim()&&(le.preventDefault(),q(b.replace(",",""))),le.key==="Backspace"&&!b&&d.length>0&&oe(d[d.length-1])},onFocus:()=>N(!0),onBlur:()=>setTimeout(()=>N(!1),150)}),T&&(V.length>0||b.trim())&&t.jsxs(qm,{anchorRef:H,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:[V.slice(0,10).map(le=>t.jsx("button",{className:"flex items-center w-full px-2.5 py-1 hover:bg-warm-100/50 transition-colors text-left",onMouseDown:()=>q(le.name),children:t.jsx("span",{className:`px-2 py-0.5 rounded-md text-[11px] font-medium ${Wa(le.color)}`,children:le.name})},le.name)),b.trim()&&!e.some(le=>le.name===b.trim())&&t.jsx("button",{className:"flex items-center w-full px-2.5 py-1 hover:bg-warm-100/50 transition-colors text-left",onMouseDown:()=>q(b),children:t.jsxs("span",{className:"text-xs text-warm-500",children:['+ "',b.trim(),'"']})})]})]})]})]}),t.jsxs("div",{className:`grid gap-3 mb-4 ${s?"grid-cols-3":"grid-cols-2"}`,children:[t.jsxs("div",{children:[t.jsx("label",{className:"text-xs font-medium text-warm-500 mb-1.5 block",children:p("plannerForm.dueDate")}),t.jsx("input",{type:"date",className:"input-field text-xs w-full",value:k,onChange:le=>x(le.target.value)})]}),t.jsxs("div",{children:[t.jsx("label",{className:"text-xs font-medium text-warm-500 mb-1.5 block",children:p("plannerForm.priority")}),t.jsxs("select",{className:"input-field text-xs w-full",value:_,onChange:le=>w(Number(le.target.value)),children:[t.jsx("option",{value:0,children:p("plannerForm.priorityLow")}),t.jsx("option",{value:1,children:p("plannerForm.priorityNormal")}),t.jsx("option",{value:2,children:p("plannerForm.priorityHigh")}),t.jsx("option",{value:3,children:p("plannerForm.priorityCritical")})]})]}),s&&t.jsxs("div",{children:[t.jsx("label",{className:"text-xs font-medium text-warm-500 mb-1.5 block",children:p("plannerForm.status")}),t.jsxs("select",{className:"input-field text-xs w-full",value:y,onChange:le=>E(le.target.value),children:[t.jsx("option",{value:"pending",children:p("plannerStatus.pending")}),t.jsx("option",{value:"in_progress",children:p("plannerStatus.in_progress")}),t.jsx("option",{value:"done",children:p("plannerStatus.done")})]})]})]}),t.jsxs("div",{className:"flex justify-end gap-3",children:[t.jsx("button",{className:"btn-ghost text-xs",onClick:u,children:p("plannerForm.cancel")}),t.jsx("button",{className:"btn-primary text-xs py-2",onClick:ye,disabled:!o.trim()||R,children:p("plannerForm.save")})]}),F&&t.jsx(Up,{src:F,onClose:()=>$(null)})]})}function jS({item:e,mode:s,projectCliTool:i,onConvert:a,onClose:u}){const{t:f}=ft(),[p,o]=S.useState(i||"claude"),[c,h]=S.useState(""),[m,d]=S.useState(!1),[g,b]=S.useState("once"),[C,k]=S.useState("0 0 * * *"),[x,_]=S.useState(""),[w,y]=S.useState(!1),E=async()=>{y(!0);try{s==="todo"?await a({cli_tool:p,max_turns:c?Number(c):void 0}):s==="session"?await a({cli_tool:p,use_worktree:m}):await a({cli_tool:p,schedule_type:g,cron_expression:g==="recurring"?C:void 0,run_at:g==="once"?x:void 0})}finally{y(!1)}};return t.jsx(jn,{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:p,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:c,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:m,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:()=>b("once"),children:f("plannerConvert.once")}),t.jsx("button",{className:`flex-1 px-3 py-1.5 rounded-md text-xs font-medium transition-all ${g==="recurring"?"bg-accent text-white":"text-warm-500"}`,onClick:()=>b("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=>_(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:E,disabled:w||s==="schedule"&&g==="once"&&!x,children:f("plannerConvert.convert")})]})]})})}function xn(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 Zy(e){return xn(new Date(e))}function ew(e){return new Date(e.getFullYear(),e.getMonth(),1)}function ES(e){return new Date(e.getFullYear(),e.getMonth(),e.getDate())}function nr(e,s){const i=ES(e);return i.setDate(i.getDate()+s),i}function NS(e){return nr(e,-e.getDay())}function LO(e,s){return Math.round((new Date(s+"T00:00").getTime()-new Date(e+"T00:00").getTime())/864e5)}function DO(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=LO(a,i),f=p=>xn(nr(new Date(p+"T00:00"),u));return{startKey:f(s.startKey),endKey:f(s.endKey)}}function TO(e,s){if(e==="day"){const f=ES(s);return{rangeStart:xn(f),rangeEnd:xn(nr(f,1)),gridDays:[f],cols:1,dimOutOfMonth:!1}}if(e==="week"){const f=NS(s),p=Array.from({length:7},(o,c)=>nr(f,c));return{rangeStart:xn(f),rangeEnd:xn(nr(f,7)),gridDays:p,cols:7,dimOutOfMonth:!1}}if(e==="table"){const f=ew(s),p=new Date(s.getFullYear(),s.getMonth()+1,1);return{rangeStart:xn(f),rangeEnd:xn(p),gridDays:[],cols:7,dimOutOfMonth:!1}}const i=ew(s),a=nr(i,-i.getDay()),u=Array.from({length:42},(f,p)=>nr(a,p));return{rangeStart:xn(a),rangeEnd:xn(nr(a,42)),gridDays:u,cols:7,dimOutOfMonth:!0}}function LS(e,s){return S.useMemo(()=>TO(e,s),[e,s])}function DS(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 TS(e,s,i){if(s==="month"||s==="table")return e.toLocaleDateString(i,{year:"numeric",month:"long"});if(s==="week"){const a=NS(e);return`${a.toLocaleDateString(i,{month:"short",day:"numeric"})} – ${nr(a,6).toLocaleDateString(i,{month:"short",day:"numeric"})}`}return e.toLocaleDateString(i,{year:"numeric",month:"long",day:"numeric",weekday:"short"})}function RS(){const{lang:e}=ft();return S.useMemo(()=>{const s=new Date(2024,5,2);return Array.from({length:7},(i,a)=>nr(s,a).toLocaleDateString(e,{weekday:"short"}))},[e])}const RO=420,MO=140,AO=220,zO=26,Jf=16,tw=2;function OO(e,s){if(!s.length)return{placed:[],laneCount:0};const i=xn(e[0]),a=xn(e[e.length-1]),u=s.filter(o=>o.startKey<=a&&o.endKey>=i).map(o=>{const c=o.startKey<i?i:o.startKey,h=o.endKey>a?a:o.endKey;return{bar:o,startCol:e.findIndex(m=>xn(m)===c),endCol:e.findIndex(m=>xn(m)===h),contStart:o.startKey<i,contEnd:o.endKey>a}}).filter(o=>o.startCol>=0&&o.endCol>=0).sort((o,c)=>o.startCol-c.startCol||c.endCol-c.startCol-(o.endCol-o.startCol)),f=[];return{placed:u.map(o=>{let c=0;for(;c<f.length&&f[c]>=o.startCol;)c++;return f[c]=o.endCol,{...o,lane:c}}),laneCount:f.length}}function MS({view:e,gridDays:s,cols:i,dimOutOfMonth:a,monthIdx:u,todayKey:f,selectedDate:p,chipsByDay:o,maxChips:c,weekdayLabels:h,addItemLabel:m,bars:d,onBarClick:g,onSelectDate:b,onQuickAdd:C,onChipClick:k,onCellContextMenu:x,onChipContextMenu:_,onBarContextMenu:w,onBarDrag:y,onChipDrag:E,monthCellHeight:R=92}){const{lang:j}=ft(),[T,N]=S.useState(null),[D,A]=S.useState(!1),B=S.useRef(null),O=S.useRef(null),F=()=>{O.current&&(clearTimeout(O.current),O.current=null)},$=(Z,te)=>{F(),B.current&&clearTimeout(B.current);const Y=te.getBoundingClientRect();B.current=window.setTimeout(()=>N({key:Z,rect:Y}),RO)},P=()=>{B.current&&(clearTimeout(B.current),B.current=null),O.current=window.setTimeout(()=>N(null),MO)};S.useEffect(()=>{if(!T){A(!1);return}const Z=requestAnimationFrame(()=>A(!0));return()=>cancelAnimationFrame(Z)},[T]),S.useEffect(()=>()=>{B.current&&clearTimeout(B.current),O.current&&clearTimeout(O.current)},[]),S.useEffect(()=>{if(!T)return;const Z=()=>N(null);return window.addEventListener("scroll",Z,!0),window.addEventListener("resize",Z),()=>{window.removeEventListener("scroll",Z,!0),window.removeEventListener("resize",Z)}},[T]);const H=T?o.get(T.key)??[]:[],[W,G]=S.useState(null),I=S.useRef(!1),z=4,U=(Z,te)=>{var Y,he;return((he=(Y=document.elementFromPoint(Z,te))==null?void 0:Y.closest("[data-daykey]"))==null?void 0:he.getAttribute("data-daykey"))??null},V=(Z,te,Y)=>{Z.preventDefault(),Z.stopPropagation();const he=U(Z.clientX,Z.clientY)??Y.origStart,de=Z.clientX,ye=Z.clientY,le=te!=="move";let De=le,Re={startKey:Y.origStart,endKey:Y.origEnd};const ve=()=>G({kind:Y.kind,entryKey:Y.entryKey,curStart:Re.startKey,curEnd:Re.endKey,title:Y.title,bg:Y.bg,fg:Y.fg,done:Y.done}),Me=()=>{document.body.style.cursor=le?"ew-resize":"grabbing",document.body.style.userSelect="none"};le&&(Me(),ve());const Oe=nt=>{if(!De){if(Math.abs(nt.clientX-de)<z&&Math.abs(nt.clientY-ye)<z)return;De=!0,Me()}const ke=U(nt.clientX,nt.clientY);ke&&(Re=DO(te,{startKey:Y.origStart,endKey:Y.origEnd},ke,he),ve())},tt=()=>{window.removeEventListener("pointermove",Oe),window.removeEventListener("pointerup",tt),document.body.style.cursor="",document.body.style.userSelect="",G(null),De&&(I.current=!0,setTimeout(()=>{I.current=!1},0),!(Re.startKey===Y.origStart&&Re.endKey===Y.origEnd)&&(Y.kind==="bar"&&Y.bar?y==null||y(Y.bar,Re.startKey,Re.endKey):Y.kind==="chip"&&Y.chip&&(E==null||E(Y.chip,Re.startKey,Re.endKey))))};window.addEventListener("pointermove",Oe),window.addEventListener("pointerup",tt)},q=(()=>{const Z=d??[];return W?W.kind==="bar"?Z.map(te=>te.key===W.entryKey?{...te,startKey:W.curStart,endKey:W.curEnd}:te):[...Z,{key:`__drag__${W.entryKey}`,title:W.title,startKey:W.curStart,endKey:W.curEnd,bg:W.bg,fg:W.fg,done:W.done}]:Z})(),oe=(Z,te)=>{const Y=xn(Z),he=o.get(Y)??[],de=!a||Z.getMonth()===u,ye=Y===f,le=Y===p,De=e==="week"?"min-h-[360px]":e==="day"?"min-h-[480px]":"",Re=e==="month"&&he.length>c;return t.jsxs("div",{"data-daykey":Y,onClick:()=>{I.current||b(Y)},onContextMenu:x?ve=>x(Y,ve):void 0,onMouseEnter:Re?ve=>$(Y,ve.currentTarget):void 0,onMouseLeave:Re?P:void 0,className:`group relative ${De} text-left p-1.5 flex flex-col gap-1 transition-colors cursor-pointer`,style:{minHeight:e==="month"?R+te:void 0,backgroundColor:le?"var(--color-bg-hover)":"var(--color-bg-card)",opacity:de?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(j,{weekday:"short"})}),t.jsx("span",{className:"text-xs font-medium w-5 h-5 flex items-center justify-center rounded-full",style:ye?{backgroundColor:"var(--color-accent)",color:"#fff"}:{color:"var(--color-text-secondary)"},children:Z.getDate()})]}),t.jsx("button",{onClick:ve=>{ve.stopPropagation(),C(Y)},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:m,style:{backgroundColor:"var(--color-bg-secondary)",color:"var(--color-text-secondary)",border:"1px solid var(--color-border)"},children:t.jsx(yn,{size:14})}),t.jsxs("div",{className:"flex flex-col gap-0.5 overflow-hidden",style:{marginTop:te||void 0},children:[he.slice(0,c).map(ve=>{if((W==null?void 0:W.kind)==="chip"&&W.entryKey===ve.key)return null;const Me=e==="month"&&!!(ve.draggable&&E),Oe={kind:"chip",entryKey:ve.key,origStart:Y,origEnd:Y,title:ve.title,bg:ve.bg,fg:ve.fg,done:ve.done,chip:ve};return t.jsxs("span",{onClick:tt=>{tt.stopPropagation(),!I.current&&k(ve)},onPointerDown:Me?tt=>V(tt,"move",Oe):void 0,onContextMenu:_?tt=>_(ve,tt):void 0,className:`text-2xs truncate px-1 py-0.5 rounded-md cursor-pointer hover:opacity-80 transition-opacity ${Me?"relative group/chip":""}`,style:{backgroundColor:ve.bg,color:ve.fg,textDecoration:ve.done?"line-through":"none"},title:ve.title,children:[ve.prefix??"",ve.time?`${ve.time} `:"",ve.title,Me&&t.jsx("span",{onPointerDown:tt=>{tt.stopPropagation(),V(tt,"resize-end",Oe)},onClick:tt=>tt.stopPropagation(),className:"absolute top-0 right-0 h-full w-1.5 opacity-0 group-hover/chip:opacity-100 cursor-ew-resize rounded-r-md",style:{backgroundColor:"rgba(127,127,127,0.5)"}})]},ve.key)}),he.length>c&&t.jsxs("span",{className:"text-2xs px-1",style:{color:"var(--color-text-muted)"},children:["+",he.length-c]})]})]},Y)},ee=[];if(e==="month")for(let Z=0;Z<s.length;Z+=i)ee.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:ee.map((Z,te)=>{const{placed:Y,laneCount:he}=OO(Z,q),de=he*(Jf+tw);return t.jsxs("div",{className:"relative grid gap-px",style:{gridTemplateColumns:`repeat(${i}, minmax(0, 1fr))`,backgroundColor:"var(--color-border)"},children:[Z.map(ye=>oe(ye,de)),Y.map(({bar:ye,startCol:le,endCol:De,lane:Re,contStart:ve,contEnd:Me})=>{const Oe=!!y&&!ye.key.startsWith("__drag__"),tt={kind:"bar",entryKey:ye.key,origStart:ye.startKey,origEnd:ye.endKey,title:ye.title,bg:ye.bg,fg:ye.fg,done:ye.done,bar:ye};return t.jsxs("div",{onClick:nt=>{nt.stopPropagation(),!I.current&&(g==null||g(ye))},onPointerDown:Oe?nt=>V(nt,"move",tt):void 0,onContextMenu:w?nt=>w(ye,nt):void 0,className:"absolute text-2xs truncate px-1.5 cursor-pointer hover:opacity-80 transition-opacity flex items-center",style:{pointerEvents:W?"none":void 0,left:`calc(${le} / ${i} * 100% + 2px)`,width:`calc(${De-le+1} / ${i} * 100% - 4px)`,top:zO+Re*(Jf+tw),height:Jf,backgroundColor:ye.bg,color:ye.fg,textDecoration:ye.done?"line-through":"none",borderRadius:4,borderTopLeftRadius:ve?0:4,borderBottomLeftRadius:ve?0:4,borderTopRightRadius:Me?0:4,borderBottomRightRadius:Me?0:4},title:ye.title,children:[ve?"◀ ":"",ye.title,Me?" ▶":"",Oe&&!ve&&t.jsx("span",{onPointerDown:nt=>{nt.stopPropagation(),V(nt,"resize-start",tt)},onClick:nt=>nt.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)"}}),Oe&&!Me&&t.jsx("span",{onPointerDown:nt=>{nt.stopPropagation(),V(nt,"resize-end",tt)},onClick:nt=>nt.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)"}})]},ye.key)})]},te)})}):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=>oe(Z,0))}),T&&(()=>{const Z=Math.max(T.rect.width,AO),te=Math.min(Math.max(8,T.rect.left),window.innerWidth-Z-8),Y=Math.max(8,Math.min(T.rect.top,window.innerHeight-120)),he=window.innerHeight-Y-16,de=Number(T.key.slice(8,10));return rn.createPortal(t.jsxs("div",{className:"z-tooltip rounded-lg shadow-elevated",onMouseEnter:F,onMouseLeave:()=>N(null),style:{position:"fixed",left:te,top:Y,width:Z,maxHeight:he,overflowY:"auto",backgroundColor:"var(--color-bg-card)",border:"1px solid var(--color-border)",padding:6,transformOrigin:"top left",transform:D?"scale(1)":"scale(0.96)",opacity:D?1:0,transition:"transform 140ms ease, opacity 140ms ease"},children:[t.jsx("div",{className:"text-xs font-semibold px-1 pb-1",style:{color:"var(--color-text-secondary)"},children:de}),t.jsx("div",{className:"flex flex-col gap-0.5",children:H.map(ye=>t.jsxs("span",{onClick:le=>{le.stopPropagation(),k(ye),N(null)},onContextMenu:_?le=>_(ye,le):void 0,className:"text-2xs truncate px-1 py-0.5 rounded-md cursor-pointer hover:opacity-80 transition-opacity",style:{backgroundColor:ye.bg,color:ye.fg,textDecoration:ye.done?"line-through":"none"},title:ye.title,children:[ye.prefix??"",ye.time?`${ye.time} `:"",ye.title]},ye.key))})]}),document.body)})()]})}function BO(e){if(!e)return[];try{const s=JSON.parse(e);return Array.isArray(s)?s.filter(i=>typeof i=="string"):[]}catch{return[]}}function PO({view:e,items:s,tagColors:i,onQuickAdd:a,onEditItem:u,onConvert:f,onDeleteItem:p,onUpdateRange:o}){const{t:c,lang:h}=ft(),[m,d]=S.useState(()=>new Date),[g,b]=S.useState(()=>xn(new Date)),[C,k]=S.useState(null),x=RS(),{gridDays:_,cols:w,dimOutOfMonth:y}=LS(e,m),E=xn(new Date),R=m.getMonth(),j=e==="month"?3:99,T=ee=>d(Z=>DS(Z,e,ee)),N=()=>{d(new Date),b(xn(new Date))},D=TS(m,e,h);S.useEffect(()=>{e==="day"&&b(xn(m))},[e,m]);const A=260,B=760,O=S.useRef(null),[F,$]=S.useState(()=>{const ee=parseInt(localStorage.getItem("plannerCalendarPanelWidth")||"",10);return Number.isFinite(ee)&&ee>=A&&ee<=B?ee:320});S.useEffect(()=>{try{localStorage.setItem("plannerCalendarPanelWidth",String(F))}catch{}},[F]);const P=ee=>{ee.preventDefault();const Z=Y=>{var de;const he=(de=O.current)==null?void 0:de.getBoundingClientRect();he&&$(Math.min(B,Math.max(A,he.right-Y.clientX)))},te=()=>{window.removeEventListener("pointermove",Z),window.removeEventListener("pointerup",te),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",te)},[H,W]=S.useState(new Map);S.useEffect(()=>{W(new Map)},[s]);const G=S.useMemo(()=>H.size===0?s:s.map(ee=>{const Z=H.get(ee.id);return Z?{...ee,due_date:Z.due_date,end_date:Z.end_date}:ee}),[s,H]),I=S.useCallback((ee,Z,te)=>{W(Y=>new Map(Y).set(ee,{due_date:Z,end_date:te})),o(ee,Z,te)},[o]),z=ee=>!!(ee.due_date&&ee.end_date&&ee.end_date.slice(0,10)>ee.due_date.slice(0,10)),U=S.useMemo(()=>{const ee=new Map;for(const Z of G){if(!Z.due_date||e==="month"&&z(Z))continue;const te=Z.due_date.slice(0,10),Y=Z.status==="done",he=ee.get(te)??[];he.push({key:Z.id,title:Z.title,bg:"var(--color-bg-secondary)",fg:Y?"var(--color-text-muted)":"var(--color-text-secondary)",done:Y,payload:Z,draggable:!0}),ee.set(te,he)}return ee},[G,e]),V=S.useMemo(()=>e!=="month"?[]:G.filter(z).map(ee=>{const Z=ee.status==="done";return{key:ee.id,title:ee.title,startKey:ee.due_date.slice(0,10),endKey:ee.end_date.slice(0,10),bg:"var(--color-bg-secondary)",fg:Z?"var(--color-text-muted)":"var(--color-text-secondary)",done:Z,payload:ee}}),[G,e]),q=S.useMemo(()=>s.filter(ee=>ee.due_date&&ee.due_date.slice(0,10)===g),[s,g]),oe=S.useMemo(()=>s.filter(ee=>!ee.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:()=>T(-1),className:"btn-ghost p-1.5","aria-label":"prev",children:t.jsx(tp,{size:16})}),t.jsx("div",{className:"text-sm font-semibold min-w-[8rem] text-center",style:{color:"var(--color-text-primary)"},children:D}),t.jsx("button",{onClick:()=>T(1),className:"btn-ghost p-1.5","aria-label":"next",children:t.jsx(Es,{size:16})}),t.jsx("button",{onClick:N,className:"btn-ghost text-xs px-2.5 py-1.5",children:c("agenda.today")})]}),t.jsx("div",{className:"flex-1 overflow-auto px-4 pb-4",children:t.jsx(MS,{view:e,gridDays:_,cols:w,dimOutOfMonth:y,monthIdx:R,todayKey:E,selectedDate:g,chipsByDay:U,maxChips:j,weekdayLabels:x,addItemLabel:c("agenda.addItem"),onSelectDate:b,onQuickAdd:a,onChipClick:ee=>u(ee.payload),onCellContextMenu:(ee,Z)=>{Z.preventDefault(),k({x:Z.clientX,y:Z.clientY,dateKey:ee})},bars:V,onBarClick:ee=>u(ee.payload),onBarDrag:(ee,Z,te)=>I(ee.payload.id,Z,te),onChipDrag:(ee,Z,te)=>I(ee.payload.id,Z,te)})})]}),t.jsx("div",{onPointerDown:P,className:"w-1.5 flex-shrink-0 cursor-col-resize hover:bg-accent/40 transition-colors",style:{backgroundColor:"var(--color-border)"},title:c("agenda.resizePanel")}),t.jsxs("div",{className:"flex-shrink-0 flex flex-col overflow-hidden",style:{width:F},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(yn,{size:14}),c("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:[q.length===0&&t.jsx("p",{className:"text-xs py-2",style:{color:"var(--color-text-muted)"},children:c("agenda.dayEmpty")}),q.map(ee=>t.jsx(nw,{item:ee,tagColors:i,onEdit:u,onConvert:f,onDelete:p},ee.id))]}),t.jsxs("div",{children:[t.jsx("h4",{className:"text-2xs uppercase tracking-wider mb-1.5",style:{color:"var(--color-text-muted)"},children:c("agenda.backlog")}),t.jsxs("div",{className:"flex flex-col gap-1.5",children:[oe.length===0&&t.jsx("p",{className:"text-xs py-1",style:{color:"var(--color-text-muted)"},children:c("agenda.backlogEmpty")}),oe.map(ee=>t.jsx(nw,{item:ee,tagColors:i,onEdit:u,onConvert:f,onDelete:p},ee.id))]})]})]})]}),C&&t.jsx(ir,{x:C.x,y:C.y,onClose:()=>k(null),children:t.jsxs("button",{type:"button",className:sn,onClick:()=>a(C.dateKey),children:[t.jsx(yn,{size:14}),c("planner.add")]})})]})}function nw({item:e,tagColors:s,onEdit:i,onConvert:a,onDelete:u}){const{t:f}=ft(),{confirm:p}=qn(),[o,c]=S.useState(!1),[h,m]=S.useState(!1),[d,g]=S.useState({top:0,left:0}),b=S.useRef(null),C=S.useRef(null),k=BO(e.tags),x=e.status==="moved",_=S.useCallback(()=>{if(!b.current)return;const w=b.current.getBoundingClientRect(),y=window.innerWidth,E=window.innerHeight;let R=w.bottom+4;const j=C.current;if(j){const T=j.offsetWidth,N=j.offsetHeight;let D=w.right-T;D<8&&(D=8),D+T>y-8&&(D=y-8-T),R+N>E-8&&(R=w.top-N-4),g({top:R,left:D}),m(!0)}else g({top:R,left:Math.max(8,w.right-180)})},[]);return S.useEffect(()=>{if(!o){m(!1);return}_();const w=requestAnimationFrame(_),y=E=>{var j,T;const R=E.target;(j=b.current)!=null&&j.contains(R)||(T=C.current)!=null&&T.contains(R)||c(!1)};return document.addEventListener("mousedown",y),window.addEventListener("scroll",_,!0),window.addEventListener("resize",_),()=>{cancelAnimationFrame(w),document.removeEventListener("mousedown",y),window.removeEventListener("scroll",_,!0),window.removeEventListener("resize",_)}},[o,_]),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 ${Ou[e.status]||Ou.pending}`,children:f(`plannerStatus.${e.status}`)}),k.map(w=>t.jsx("span",{className:`px-1.5 py-0.5 rounded-md text-2xs font-medium ${Wa(s.get(w)||"default")}`,children:w},w))]})]}),t.jsxs("div",{className:"flex-shrink-0",children:[t.jsx("button",{ref:b,onClick:w=>{w.stopPropagation(),c(!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(np,{size:14})}),o&&rn.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:()=>c(!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(Uw,{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(Wi,{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(pi,{size:12})," ",f("planner.convertToTerminal")]})]}),t.jsxs("button",{onClick:async()=>{await p({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(An,{size:12})," ",f("planner.delete")]})]}),document.body)]})]})}const sw={pending:0,in_progress:1,done:2,moved:3};function IO({plannerItems:e,existingTags:s,projectCliTool:i,onAddItem:a,onEditItem:u,onDeleteItem:f,onConvertToTodo:p,onConvertToSchedule:o,onConvertToSession:c,onUpdateTag:h,onDeleteTag:m,onExport:d,onImport:g,view:b,onChangeView:C}){const{t:k}=ft(),{warning:x}=Ls(),[_,w]=S.useState(!1),[y,E]=S.useState(null),[R,j]=S.useState(void 0),[T,N]=S.useState(""),[D,A]=S.useState(""),[B,O]=S.useState("created_at"),[F,$]=S.useState("desc"),[P,H]=S.useState(null),[W,G]=S.useState("todo"),[I,z]=S.useState(!1),[U,V]=S.useState(!1),[q,oe]=S.useState(null),ee=S.useRef(null),Z=S.useRef(0),te=async()=>{if(!(!d||I)){z(!0);try{await d()}finally{z(!1)}}},Y=()=>{var fe;!g||I||(fe=ee.current)==null||fe.click()},he=async fe=>{var Ce;const Te=(Ce=fe.target.files)==null?void 0:Ce[0];if(fe.target.value="",!(!Te||!g)){z(!0);try{await g(Te)}finally{z(!1)}}},de=fe=>!!(/\.(md|markdown)$/i.test(fe.name)||fe.type==="text/markdown"),ye=fe=>Array.from(fe.dataTransfer.types).includes("Files"),le=fe=>{!g||I||ye(fe)&&(fe.preventDefault(),Z.current++,V(!0))},De=fe=>{!g||I||ye(fe)&&(fe.preventDefault(),fe.dataTransfer.dropEffect="copy")},Re=fe=>{g&&(fe.preventDefault(),Z.current=Math.max(0,Z.current-1),Z.current===0&&V(!1))},ve=async fe=>{var Ce;if(!g||(fe.preventDefault(),Z.current=0,V(!1),I))return;const Te=(Ce=fe.dataTransfer.files)==null?void 0:Ce[0];if(Te){if(!de(Te)){x(k("planner.dropInvalidFile"));return}z(!0);try{await g(Te)}finally{z(!1)}}},Me=S.useMemo(()=>s.map(fe=>fe.name),[s]),Oe=S.useMemo(()=>new Map(s.map(fe=>[fe.name,fe.color])),[s]),tt=S.useMemo(()=>{let fe=e.filter(Te=>!(D&&Te.status!==D||T&&!(Te.tags?(()=>{try{return JSON.parse(Te.tags)}catch{return[]}})():[]).includes(T)));return fe=[...fe].sort((Te,Ce)=>{let Ge=0;switch(B){case"title":Ge=Te.title.localeCompare(Ce.title);break;case"tags":{const Ze=Te.tags?(()=>{try{return JSON.parse(Te.tags).join(",")}catch{return""}})():"",be=Ce.tags?(()=>{try{return JSON.parse(Ce.tags).join(",")}catch{return""}})():"";Ge=(Ze||"zzz").localeCompare(be||"zzz");break}case"priority":Ge=Te.priority-Ce.priority;break;case"due_date":{const Ze=Te.due_date||"9999",be=Ce.due_date||"9999";Ge=Ze.localeCompare(be);break}case"status":Ge=(sw[Te.status]??9)-(sw[Ce.status]??9);break;case"created_at":Ge=Te.created_at.localeCompare(Ce.created_at);break}return F==="asc"?Ge:-Ge}),fe},[e,T,D,B,F]),nt=fe=>{B===fe?$(Te=>Te==="asc"?"desc":"asc"):(O(fe),$(fe==="priority"?"desc":"asc"))},ke=({field:fe})=>B!==fe?null:F==="asc"?t.jsx(Zj,{size:12,className:"inline ml-0.5"}):t.jsx(Vj,{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:[b!=="table"&&t.jsx("div",{className:"flex gap-0.5 p-0.5 rounded-lg shrink-0",style:{backgroundColor:"var(--color-bg-tertiary)"},children:["month","week","day"].map(fe=>t.jsx("button",{onClick:()=>C(fe),className:"px-2.5 py-1 text-xs rounded-md transition-all",style:b===fe?{backgroundColor:"var(--color-bg-card)",color:"var(--color-text-primary)",fontWeight:600}:{color:"var(--color-text-tertiary)"},children:k(`agenda.view.${fe}`)},fe))}),t.jsxs("select",{className:"input-field text-xs py-1.5 px-2 w-auto max-w-[10rem] shrink",value:T,onChange:fe=>N(fe.target.value),children:[t.jsx("option",{value:"",children:k("planner.filterTag")}),Me.map(fe=>t.jsx("option",{value:fe,children:fe},fe))]}),t.jsxs("select",{className:"input-field text-xs py-1.5 px-2 w-auto max-w-[10rem] shrink",value:D,onChange:fe=>A(fe.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:te,disabled:I||e.length===0,className:"btn-secondary text-xs py-2 whitespace-nowrap shrink-0 disabled:opacity-50",title:k("planner.exportTooltip"),children:[t.jsx(lm,{size:14,className:"inline-block shrink-0"}),k("planner.export")]}),g&&t.jsxs(t.Fragment,{children:[t.jsxs("button",{onClick:Y,disabled:I,className:"btn-secondary text-xs py-2 whitespace-nowrap shrink-0 disabled:opacity-50",title:k("planner.importTooltip"),children:[t.jsx(Z0,{size:14,className:"inline-block shrink-0"}),k("planner.import")]}),t.jsx("input",{ref:ee,type:"file",accept:".md,.markdown,text/markdown",className:"hidden",onChange:he})]}),!_&&!y&&t.jsxs("button",{onClick:()=>w(!0),className:"btn-primary text-xs py-2 whitespace-nowrap shrink-0",children:[t.jsx(yn,{size:14,className:"inline-block shrink-0"}),k("planner.add")]})]})]}),(_||y)&&t.jsx("div",{className:"mb-5",children:t.jsx(NO,{existingTags:s,editItem:y,initialDueDate:R,onSave:async fe=>{if(y){await u(y.id,fe),E(null);return}else{const Te=await a(fe);return w(!1),j(void 0),Te}},onCancel:()=>{w(!1),E(null),j(void 0)},onUpdateTag:h})}),b==="table"?t.jsxs("div",{className:"card relative",onDragEnter:g?le:void 0,onDragOver:g?De:void 0,onDragLeave:g?Re:void 0,onDrop:g?ve:void 0,onContextMenu:fe=>{gi(fe)||(fe.preventDefault(),oe({x:fe.clientX,y:fe.clientY}))},children:[U&&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(Z0,{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:()=>nt("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:()=>nt("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:()=>nt("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:()=>nt("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:()=>nt("status"),children:[k("planner.col.status"),t.jsx(ke,{field:"status"})]}),t.jsx("div",{className:"w-8"})]}),tt.length===0?t.jsx(Yi,{icon:SE,title:k("planner.empty"),description:k("planner.emptyHint")}):tt.map((fe,Te)=>t.jsx("div",{children:t.jsx(jO,{item:fe,tagColors:Oe,existingTags:Me,onSave:async(Ce,Ge)=>{await u(Ce,Ge)},onDelete:()=>f(fe.id),onConvertToTodo:()=>{H(fe),G("todo")},onConvertToSchedule:()=>{H(fe),G("schedule")},onConvertToSession:()=>{H(fe),G("session")},onUpdateTag:h})},fe.id))]}):t.jsx(PO,{view:b,items:tt,tagColors:Oe,onQuickAdd:fe=>{E(null),j(fe),w(!0)},onEditItem:fe=>{w(!1),E(fe)},onConvert:(fe,Te)=>{H(fe),G(Te)},onDeleteItem:f,onUpdateRange:(fe,Te,Ce)=>{u(fe,{due_date:Te,end_date:Ce})}}),P&&t.jsx(jS,{item:P,mode:W,projectCliTool:i,onConvert:async fe=>{W==="todo"?await p(P.id,fe):W==="session"?await c(P.id,fe):await o(P.id,fe),H(null)},onClose:()=>H(null)}),q&&t.jsx(ir,{x:q.x,y:q.y,onClose:()=>oe(null),children:t.jsxs("button",{type:"button",className:sn,onClick:()=>{E(null),j(void 0),w(!0)},children:[t.jsx(yn,{size:14}),k("planner.add")]})})]})}const AS=S.createContext(null),FO=AS.Provider;function cP(){const e=S.useContext(AS);if(!e)throw new Error("usePlannerPage must be used within a PlannerPageProvider");return e}const HO=S.lazy(()=>Wu(()=>import("./PlannerPageEditor-DbJ5m1Ou.js").then(e=>e.a),__vite__mapDeps([5,3,6,7,8]))),$O=800;function UO({pageId:e,projectId:s,projectCliTool:i,existingTags:a,onTitleChange:u,onConvertToTodo:f,onConvertToSchedule:p,onConvertToSession:o}){const{t:c}=ft(),[h,m]=S.useState(null),[d,g]=S.useState("idle"),[b,C]=S.useState(null),k=S.useRef({title:"",content:null}),x=S.useRef(null);S.useEffect(()=>{let j=!1;return V4(e).then(T=>{j||(m(T),k.current={title:T.title,content:T.content??null})}),()=>{j=!0}},[e]);const _=S.useCallback(()=>{x.current&&(clearTimeout(x.current),x.current=null);const{title:j,content:T}=k.current;return g("saving"),Y4(e,{title:j,content:T??void 0}).then(()=>g("saved"))},[e]);S.useEffect(()=>()=>{x.current&&_()},[_]);const w=S.useCallback(()=>{x.current&&clearTimeout(x.current),g("saving"),x.current=setTimeout(()=>{_()},$O)},[_]),y=j=>{k.current.title=j,m(T=>T&&{...T,title:j}),u(e,j),w()},E=j=>{k.current.content=j,w()},R=S.useCallback((j,T,N)=>{C({item:j,mode:T,onDone:N})},[]);return h?t.jsxs(FO,{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:j=>y(j.target.value),placeholder:c("planner.pages.untitled"),className:"flex-1 bg-transparent text-2xl font-bold outline-none",style:{color:"var(--color-text-primary)"}}),t.jsx("span",{className:"text-2xs text-warm-400 flex-shrink-0",children:d==="saving"?c("planner.pages.saving"):d==="saved"?c("planner.pages.saved"):""})]}),t.jsx("div",{className:"flex-1 overflow-y-auto pb-6",children:t.jsx(S.Suspense,{fallback:null,children:t.jsx(HO,{pageId:e,initialContent:h.content??null,onChange:E})})})]}),b&&t.jsx(jS,{item:b.item,mode:b.mode,projectCliTool:i,onConvert:async j=>{const{item:T,mode:N,onDone:D}=b;N==="todo"?await f(T.id,j):N==="session"?await o(T.id,j):await p(T.id,j),D==null||D(),C(null)},onClose:()=>C(null)})]}):null}const Rn=(e,s)=>({type:"heading",props:{level:e},content:s}),Qo=e=>e?{type:"paragraph",content:e}:{type:"paragraph"},rw=e=>({type:"bulletListItem"}),Ii=e=>({type:"checkListItem"}),iw=()=>({type:"tasklist"}),aw=()=>({type:"calendar"}),WO=[{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:[Rn(1,"회의 노트"),Qo("날짜: "),Qo("참석자: "),Rn(2,"안건"),rw(),Rn(2,"논의"),Qo(),Rn(2,"액션 아이템"),iw()]},{id:"project",labelKey:"planner.tpl.project",descKey:"planner.tpl.project.desc",title:"프로젝트 플랜",blocks:[Rn(1,"프로젝트 플랜"),Rn(2,"개요"),Qo(),Rn(2,"마일스톤"),iw(),Rn(2,"일정"),aw(),Rn(2,"리스크 / 메모"),Qo()]},{id:"weekly",labelKey:"planner.tpl.weekly",descKey:"planner.tpl.weekly.desc",title:"위클리 플래너",blocks:[Rn(1,"위클리 플래너"),Rn(2,"이번 주 목표"),rw(),Rn(2,"요일별 할 일"),Rn(3,"월요일"),Ii(),Rn(3,"화요일"),Ii(),Rn(3,"수요일"),Ii(),Rn(3,"목요일"),Ii(),Rn(3,"금요일"),Ii(),Rn(3,"토요일"),Ii(),Rn(3,"일요일"),Ii(),Rn(2,"주간 일정"),aw()]}];function qO({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 c=u;u=null,e(c)},p=c=>{u=c.clientX,a===null&&(a=requestAnimationFrame(f))},o=c=>{a!==null&&cancelAnimationFrame(a),a=null,c.type==="pointerup"&&u!==null&&f(),u=null,document.body.style.cursor="",document.body.style.userSelect="",i.removeEventListener("pointermove",p),i.removeEventListener("pointerup",o),i.removeEventListener("pointercancel",o)};i.addEventListener("pointermove",p),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 ow=160,lw=480,cw="plannerSidebarWidth";function KO({projectId:e,...s}){const{t:i}=ft(),{confirm:a}=qn(),[u,f]=S.useState([]),[p,o]=S.useState({kind:"work"}),[c,h]=S.useState("table"),[m,d]=S.useState(!1),[g,b]=S.useState({top:0,left:0}),C=S.useRef(null),k=S.useRef(null),x=S.useRef(!1),[_,w]=S.useState(()=>{const P=Number(localStorage.getItem(cw));return P>=ow&&P<=lw?P:208}),y=S.useCallback(P=>{var G;const H=((G=k.current)==null?void 0:G.getBoundingClientRect().left)??0,W=Math.round(Math.max(ow,Math.min(lw,P-H)));w(W),localStorage.setItem(cw,String(W))},[]),E=240,R=()=>{var H;const P=(H=C.current)==null?void 0:H.getBoundingClientRect();if(P){const W=Math.min(P.left,window.innerWidth-E-8);b({top:P.bottom+4,left:Math.max(8,W)})}d(!0)};S.useEffect(()=>{if(!m)return;const P=()=>d(!1),H=W=>{var G;(G=C.current)!=null&&G.contains(W.target)||W.target.closest("[data-template-picker]")||d(!1)};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)}},[m]),S.useEffect(()=>{K4(e).then(P=>{f(P),x.current||(x.current=!0,P.length>0&&o({kind:"page",id:P[0].id}))})},[e]);const j=async P=>{d(!1);const H=await G4(e,P.title||i("planner.pages.untitled"),P.blocks?JSON.stringify(P.blocks):void 0);f(W=>[...W,H]),o({kind:"page",id:H.id})},T=async P=>{await a({message:i("planner.pages.deleteConfirm"),danger:!0})&&(await X4(P),f(H=>H.filter(W=>W.id!==P)),o(H=>H.kind==="page"&&H.id===P?{kind:"work"}:H))},N=S.useCallback((P,H)=>{f(W=>W.map(G=>G.id===P?{...G,title:H}:G))},[]),D=()=>{o({kind:"work"}),h(P=>P==="table"?"month":P)},A=()=>{o({kind:"work"}),h("table")},B=p.kind==="work",O=B&&c!=="table",F=B&&c==="table",$=(P,H,W,G,I)=>t.jsxs("div",{onClick:H,className:`group flex items-center gap-2 px-2.5 py-1.5 rounded-lg cursor-pointer transition-colors ${P?"":"hover:bg-warm-50"}`,style:P?{backgroundColor:"var(--color-bg-tertiary)"}:void 0,children:[W,t.jsx("span",{className:"flex-1 text-sm truncate",style:{color:"var(--color-text-primary)"},children:G}),I]});return t.jsxs("div",{className:"flex gap-4",style:{minHeight:"70vh"},children:[t.jsxs("div",{ref:k,className:"flex-shrink-0 flex flex-col card p-2 overflow-y-auto",style:{width:_},children:[t.jsxs("div",{className:"flex items-center justify-between px-2.5 pt-1 pb-1",children:[t.jsx("span",{className:"text-2xs font-semibold uppercase tracking-wider text-warm-400",children:i("planner.view.pages")}),t.jsx("button",{ref:C,onClick:()=>m?d(!1):R(),className:"text-warm-400 hover:text-warm-600 transition-colors",title:i("planner.pages.new"),children:t.jsx(yn,{size:14})})]}),u.map(P=>$(p.kind==="page"&&p.id===P.id,()=>o({kind:"page",id:P.id}),t.jsx(tl,{size:14,className:"text-warm-400 flex-shrink-0"}),P.title||i("planner.pages.untitled"),t.jsx("button",{onClick:H=>{H.stopPropagation(),T(P.id)},className:"opacity-0 group-hover:opacity-100 text-warm-400 hover:text-status-error transition-all flex-shrink-0",children:t.jsx(An,{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")}),$(O,D,t.jsx(om,{size:14,className:"text-warm-400 flex-shrink-0"}),i("planner.nav.calendar")),$(F,A,t.jsx(yu,{size:14,className:"text-warm-400 flex-shrink-0"}),i("planner.nav.list"))]}),t.jsx(qO,{onResize:y}),t.jsx("div",{className:"flex-1 min-w-0 flex flex-col",children:p.kind==="page"?t.jsx("div",{className:"card flex flex-col flex-1",children:t.jsx(UO,{pageId:p.id,projectId:e,projectCliTool:s.projectCliTool,existingTags:s.existingTags,onTitleChange:N,onConvertToTodo:s.onConvertToTodo,onConvertToSchedule:s.onConvertToSchedule,onConvertToSession:s.onConvertToSession},p.id)}):t.jsx(IO,{...s,view:c,onChangeView:h})}),m&&rn.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:E,backgroundColor:"var(--color-bg-card)",border:"1px solid var(--color-border)"},children:WO.map(P=>t.jsxs("button",{onClick:()=>j(P),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(P.labelKey)}),t.jsx("div",{className:"text-2xs text-warm-400 mt-0.5",children:i(P.descKey)})]},P.id))}),document.body)]})}const GO=S.lazy(()=>Wu(()=>import("./AnalyticsPanel-t7izyfbC.js"),__vite__mapDeps([9,7,3,2]))),VO=S.lazy(()=>Wu(()=>import("./VaultLayout-A4lg8TSX.js"),__vite__mapDeps([10,6,1,2,3,4])));function YO({onEvent:e,connected:s,sendMessage:i,subscribeBinary:a}){const{id:u}=Ym(),[f,p]=S.useState(null),[o,c]=S.useState([]),[h,m]=S.useState([]),[d,g]=S.useState(null),[b,C]=S.useState([]),[k,x]=S.useState([]),[_,w]=S.useState([]),[y,E]=S.useState([]),[R,j]=Iw(),T=["tasks","discussions","schedules","analytics"],N=R.get("tab")||"tasks",[D,A]=S.useState(T.includes(N)?"automation":N),[B,O]=S.useState(T.includes(N)?N:"tasks"),F=S.useCallback(Q=>{if(Q==="automation"){A("automation"),j(B==="tasks"?{}:{tab:B},{replace:!0});return}A(Q),j(Q==="tasks"?{}:{tab:Q},{replace:!0})},[j,B]),$=S.useCallback(Q=>{A("automation"),O(Q),j(Q==="tasks"?{}:{tab:Q},{replace:!0})},[j]),[P,H]=S.useState(!0),[W,G]=S.useState(!1),[I,z]=S.useState(new Set),[U,V]=S.useState(0),{t:q}=ft(),{success:oe,error:ee,info:Z}=Ls(),{sendNotification:te}=lp(),Y=S.useRef([]);S.useEffect(()=>{Y.current=b},[b]),S.useEffect(()=>{u&&Promise.all([MN(u),xf(u),gb(u),xb(u),f4(),D1(u),Uc(u),Wc(u)]).then(([Q,ze,ue,Fe,Ve,ht,Ne,at])=>{p(Q),c(ze),m(ue),C(Fe),x(ht),w(Ne),E(at),Ve.resetsAt&&g(Ve.resetsAt);const bt=ze.filter(Ct=>Ct.status==="running"&&Ct.execution_mode==="interactive").map(Ct=>Ct.id);bt.length>0&&z(new Set(bt))}).catch(()=>G(!0)).finally(()=>H(!1))},[u]);const he=S.useRef(o);he.current=o,S.useEffect(()=>{if(!u)return;const Q=setInterval(()=>{he.current.some(ue=>ue.status==="running")&&xf(u).then(ue=>{c(Fe=>Fe.map(Ve=>{const ht=ue.find(Ne=>Ne.id===Ve.id);return ht&&ht.status!==Ve.status?ht:Ve}))}).catch(()=>{})},5e3);return()=>clearInterval(Q)},[u]);const de=S.useRef(s);S.useEffect(()=>{s&&!de.current&&u&&Promise.all([xf(u),gb(u),xb(u)]).then(([Q,ze,ue])=>{c(Q),m(ze),C(ue)}).catch(()=>{}),de.current=s},[s,u]),S.useEffect(()=>e(Q=>{if(Q.type==="todo:status-changed"&&Q.todoId&&Q.status){if(c(ze=>ze.map(ue=>{if(ue.id!==Q.todoId)return ue;const Fe={status:Q.status,updated_at:new Date().toISOString()};return Q.worktree_path!==void 0&&(Fe.worktree_path=Q.worktree_path??null),Q.branch_name!==void 0&&(Fe.branch_name=Q.branch_name??null),{...ue,...Fe}})),(Q.status==="completed"||Q.status==="merged"||Q.status==="failed")&&V(ze=>ze+1),Q.status==="completed"||Q.status==="failed"){const ze=he.current.find(ue=>ue.id===Q.todoId);ze&&te(Q.status==="completed"?q("notification.taskCompleted"):q("notification.taskFailed"),ze.title)}Q.status==="running"&&Q.mode==="interactive"?z(ze=>new Set(ze).add(Q.todoId)):Q.status!=="running"&&z(ze=>{const ue=new Set(ze);return ue.delete(Q.todoId),ue})}if(Q.type==="todo:created"&&Q.todo&&Q.todo.project_id===u){const ze=Q.todo;c(ue=>ue.some(Fe=>Fe.id===ze.id)?ue:[...ue,ze])}if(Q.type==="schedule:status-changed"&&Q.scheduleId&&m(ze=>ze.map(ue=>ue.id===Q.scheduleId?{...ue,is_active:Q.isActive?1:0,updated_at:new Date().toISOString()}:ue)),Q.type==="rate-limit:updated"&&Q.resetsAt&&g(Q.resetsAt),Q.type==="discussion:status-changed"&&Q.discussionId&&(C(ze=>ze.map(ue=>ue.id===Q.discussionId?{...ue,status:Q.status,current_round:Q.currentRound??ue.current_round,updated_at:new Date().toISOString()}:ue)),Q.status==="completed"||Q.status==="failed")){const ze=Y.current.find(ue=>ue.id===Q.discussionId);ze&&te(Q.status==="completed"?q("notification.discussionCompleted"):q("notification.discussionFailed"),ze.title)}Q.type==="session:status-changed"&&Q.sessionId&&x(ze=>ze.map(ue=>{if(ue.id!==Q.sessionId)return ue;const Fe={status:Q.status,updated_at:new Date().toISOString()};return Q.worktree_path!==void 0&&(Fe.worktree_path=Q.worktree_path),Q.branch_name!==void 0&&(Fe.branch_name=Q.branch_name),{...ue,...Fe}}))}),[e,te,q]);const ye=S.useCallback(async(Q,ze,ue,Fe,Ve,ht,Ne,at,bt,Ct)=>{if(!u)return;const qt=await mb(u,{title:Q,description:ze,cli_tool:ue,depends_on:Ve,max_turns:ht??null,use_worktree:Ne??null,...at?{memory_inject_mode:at}:{},...bt?{memory_node_ids:bt}:{},...Ct?{memory_raw_file_paths:Ct}:{}});if(Fe&&Fe.length>0){const an=await j1(qt.id,Fe.map(Pn=>({name:Pn.name,data:Pn.data})));qt.images=JSON.stringify(an.images)}c(an=>[...an,qt])},[u]),le=S.useCallback((Q,ze=[])=>{const ue=Q.split("/").filter(Boolean).pop()??Q,Fe=[Q,...ze].map(Ve=>`@${Ve}`).join(`
|
|
680
680
|
`);return ye(ue,`다음 파일을 참고하세요:
|
|
681
681
|
${Fe}`)},[ye]),De=S.useCallback(async(Q,ze)=>{const ue=ze==="interactive";ue&&z(Fe=>new Set(Fe).add(Q));try{const Fe=await pb(Q,ze);c(Ve=>Ve.map(ht=>ht.id===Q?Fe:ht))}catch(Fe){throw ue&&z(Ve=>{const ht=new Set(Ve);return ht.delete(Q),ht}),Fe}},[]),Re=S.useCallback(async Q=>{const ze=await e4(Q);c(ue=>ue.map(Fe=>Fe.id===Q?ze:Fe))},[]),ve=S.useCallback(async Q=>{await w1(Q),c(ze=>ze.filter(ue=>ue.id!==Q))},[]),Me=S.useCallback(async(Q,ze,ue,Fe,Ve,ht,Ne,at,bt,Ct)=>{const qt=await $c(Q,{title:ze,description:ue,cli_tool:Fe,depends_on:Ve??null,max_turns:ht??null,use_worktree:Ne===void 0?null:Ne,...at?{memory_inject_mode:at}:{},...bt?{memory_node_ids:bt}:{},...Ct?{memory_raw_file_paths:Ct}:{}});c(an=>an.map(Pn=>Pn.id===Q?qt:Pn))},[]),Oe=S.useCallback(async Q=>{await S1(Q),c(ze=>ze.map(ue=>ue.id===Q?{...ue,status:"merged",worktree_path:null,branch_name:null,updated_at:new Date().toISOString()}:ue))},[]),tt=S.useCallback(async Q=>{const ze=await s4(Q),ue=new Set(ze.mergedIds);c(Fe=>Fe.map(Ve=>ue.has(Ve.id)?{...Ve,status:"merged",worktree_path:null,branch_name:null,updated_at:new Date().toISOString()}:Ve))},[]),nt=S.useCallback(async(Q,ze=!1)=>{await k1(Q,ze),c(ue=>ue.map(Fe=>Fe.id===Q?{...Fe,worktree_path:null,...ze?{branch_name:null}:{},updated_at:new Date().toISOString()}:Fe))},[]),ke=S.useCallback(async(Q,ze)=>{const ue=ze==="interactive";ue&&z(Fe=>new Set(Fe).add(Q));try{const Fe=await r4(Q,ze);c(Ve=>Ve.map(ht=>ht.id===Q?Fe:ht))}catch(Fe){throw ue&&z(Ve=>{const ht=new Set(Ve);return ht.delete(Q),ht}),Fe}},[]),fe=S.useCallback(async(Q,ze,ue)=>{const Fe=ue==="interactive";Fe&&z(Ve=>new Set(Ve).add(Q));try{const Ve=await C1(Q,ze,ue);c(ht=>ht.map(Ne=>Ne.id===Q?Ve:Ne))}catch(Ve){throw Fe&&z(ht=>{const Ne=new Set(ht);return Ne.delete(Q),Ne}),Ve}},[]),Te=S.useCallback(async(Q,ze,ue)=>{const Fe=await l4(Q,ze,ue);Fe.original_deleted&&c(Ve=>Ve.filter(ht=>ht.id!==Q)),m(Ve=>[Fe.schedule,...Ve])},[]),Ce=S.useCallback(async(Q,ze)=>{const ue=await m4(Q,ze);m(Fe=>[ue.schedule,...Fe])},[]),Ge=S.useCallback((Q,ze)=>{i({type:"todo:stdin",todoId:Q,input:ze})},[i]),Ze=S.useCallback(async(Q,ze)=>{const ue=await $c(Q,{depends_on:ze});c(Fe=>Fe.map(Ve=>Ve.id===Q?ue:Ve))},[]),be=S.useCallback(async Q=>{const ze=Q.map((ue,Fe)=>({id:ue,priority:Fe}));c(ue=>ue.map(Fe=>{const Ve=ze.find(ht=>ht.id===Fe.id);return Ve?{...Fe,priority:Ve.priority}:Fe})),await Promise.all(ze.map(ue=>$c(ue.id,{priority:ue.priority})))},[]),Be=S.useCallback(async(Q,ze,ue)=>{await $c(Q,{position_x:ze,position_y:ue}),c(Fe=>Fe.map(Ve=>Ve.id===Q?{...Ve,position_x:ze,position_y:ue}:Ve))},[]),ne=S.useCallback(async(Q,ze)=>{if(!u)return;const ue=ze.map(Ne=>Ne.message).join(`
|
|
682
682
|
`),Fe=`The previous task "${Q.title}" failed with the following errors:
|