clitrigger 0.2.56 → 0.2.57
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-CulPdMvq.js → AnalyticsPanel-BqveBWb3.js} +1 -1
- package/dist/client/assets/{FloatingComposerController-5A3GJtK4-C3GvM23u.js → FloatingComposerController-5A3GJtK4-BQoyUfnV.js} +1 -1
- package/dist/client/assets/{PlannerPageEditor-D6h0rQqh.js → PlannerPageEditor-BcGssFyo.js} +3 -3
- package/dist/client/assets/{TaskGraph-BX64vM3H.js → TaskGraph-ChBjtlXm.js} +1 -1
- package/dist/client/assets/{VaultLayout-CvzS1rr3.js → VaultLayout-D_BWNBzo.js} +1 -1
- package/dist/client/assets/{index-COJQG86i.js → index-BXle915b.js} +5 -5
- package/dist/client/assets/{style-5p514HAk.js → style-CUoKbhNI.js} +1 -1
- package/dist/client/assets/{with-selector-cC32Q-A5.js → with-selector-B15siOEI.js} +1 -1
- package/dist/client/index.html +1 -1
- 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-ChBjtlXm.js","assets/style-CUoKbhNI.js","assets/value-BTdN53H7.js","assets/with-selector-B15siOEI.js","assets/style-BZV40eAE.css","assets/PlannerPageEditor-BcGssFyo.js","assets/index-Vcq4gwWv.js","assets/clsx-B-dksMZM.js","assets/PlannerPageEditor-1-XUcFw6.css","assets/AnalyticsPanel-BqveBWb3.js","assets/VaultLayout-D_BWNBzo.js"])))=>i.map(i=>d[i]);
|
|
2
2
|
var QC=Object.defineProperty;var ZC=(e,s,i)=>s in e?QC(e,s,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[s]=i;var E0=(e,s,i)=>ZC(e,typeof s!="symbol"?s+"":s,i);function e2(e,s){for(var i=0;i<s.length;i++){const a=s[i];if(typeof a!="string"&&!Array.isArray(a)){for(const u in a)if(u!=="default"&&!(u in e)){const f=Object.getOwnPropertyDescriptor(a,u);f&&Object.defineProperty(e,u,f.get?f:{enumerable:!0,get:()=>a[u]})}}}return Object.freeze(Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}))}(function(){const s=document.createElement("link").relList;if(s&&s.supports&&s.supports("modulepreload"))return;for(const u of document.querySelectorAll('link[rel="modulepreload"]'))a(u);new MutationObserver(u=>{for(const f of u)if(f.type==="childList")for(const m of f.addedNodes)m.tagName==="LINK"&&m.rel==="modulepreload"&&a(m)}).observe(document,{childList:!0,subtree:!0});function i(u){const f={};return u.integrity&&(f.integrity=u.integrity),u.referrerPolicy&&(f.referrerPolicy=u.referrerPolicy),u.crossOrigin==="use-credentials"?f.credentials="include":u.crossOrigin==="anonymous"?f.credentials="omit":f.credentials="same-origin",f}function a(u){if(u.ep)return;u.ep=!0;const f=i(u);fetch(u.href,f)}})();var yP=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 of={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 ON=[["circle",{cx:"11",cy:"11",r:"8",key:"4ej97u"}],["line",{x1:"21",x2:"16.65",y1:"21",y2:"16.65",key:"13gj7c"}],["line",{x1:"8",x2:"14",y1:"11",y2:"11",key:"durymu"}]],BN=ot("zoom-out",ON),sb=8;function PN({onLogin:e,onChangePassword:s}){const[i,a]=S.useState(""),[u,f]=S.useState(""),[m,o]=S.useState(""),[l,d]=S.useState(!1),[p,h]=S.useState(!1),[g,b]=S.useState(!1),[C,k]=S.useState(""),[x,y]=S.useState(!1),{t:_,toggleLang:w}=ht(),E=l&&u.length>0&&u.length<sb,T=l&&m.length>0&&u!==m,j=l?!!i&&u.length>=sb&&u===m:!!i,D=()=>{d(R=>!R),f(""),o(""),k("")},N=async R=>{if(R.preventDefault(),!(!j||x)){k(""),y(!0);try{l?await s(i,u,m,g):await e(i,g)}catch(A){k(l&&A instanceof Error&&A.message?A.message:_("login.error"))}finally{y(!1)}}};return t.jsxs("div",{className:"min-h-screen bg-theme-bg flex items-center justify-center px-4 relative",children:[t.jsx("button",{onClick:w,className:"lang-toggle absolute top-6 right-6",children:_("lang.toggle")}),t.jsxs("div",{className:"w-full max-w-sm",children:[t.jsxs("div",{className:"text-center mb-10",children:[t.jsx("div",{className:"inline-flex items-center justify-center w-16 h-16 rounded-2xl bg-accent/10 mb-5",children:t.jsx(ml,{size:32,className:"text-accent"})}),t.jsx("h1",{className:"text-2xl font-semibold text-theme-text",children:_("login.title")}),t.jsx("p",{className:"text-theme-muted text-sm mt-2",children:_("login.subtitle")})]}),t.jsx("form",{onSubmit:N,children:t.jsxs("div",{className:"card p-8",children:[t.jsx("label",{className:"block text-sm font-medium text-theme-text-secondary mb-2",children:_(l?"account.oldPassword":"login.password")}),t.jsx("input",{type:"password",value:i,onChange:R=>a(R.target.value),placeholder:"*************",className:"input-field text-base",autoComplete:"current-password",autoFocus:!0}),l&&t.jsxs(t.Fragment,{children:[t.jsx("label",{className:"block text-sm font-medium text-theme-text-secondary mb-2 mt-4",children:_("account.newPassword")}),t.jsx("input",{type:"password",value:u,onChange:R=>f(R.target.value),className:"input-field text-base",autoComplete:"new-password","aria-label":_("account.newPassword")}),E&&t.jsx("p",{className:"mt-1 text-2xs text-status-error",children:_("account.tooShort")}),t.jsx("label",{className:"block text-sm font-medium text-theme-text-secondary mb-2 mt-4",children:_("account.confirm")}),t.jsx("input",{type:"password",value:m,onChange:R=>o(R.target.value),className:"input-field text-base",autoComplete:"new-password","aria-label":_("account.confirm")}),T&&t.jsx("p",{className:"mt-1 text-2xs text-status-error",children:_("account.mismatch")})]}),C&&t.jsx("div",{className:"mt-4 py-2.5 px-4 bg-status-error/5 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:R=>b(R.target.checked),className:"accent-accent w-4 h-4"}),_("login.rememberMe")]}),t.jsx("button",{type:"submit",disabled:!j||x,className:"btn-primary w-full mt-6 py-3",children:_(x?"login.loading":l?"login.changeSubmit":"login.submit")})]})}),t.jsxs("div",{className:"mt-4 flex items-center justify-center gap-5 text-xs",children:[t.jsx("button",{type:"button",onClick:D,className:"text-theme-muted hover:text-theme-text underline-offset-2 hover:underline",children:_(l?"login.backToLogin":"login.changePassword")}),t.jsx("button",{type:"button",onClick:()=>h(R=>!R),className:"text-theme-muted hover:text-theme-text underline-offset-2 hover:underline",children:_("login.forgot")})]}),p&&t.jsx("div",{className:"mt-3 px-4 py-3 rounded-xl text-xs text-theme-text-tertiary border leading-relaxed",children:_("login.forgotHint")}),t.jsx("div",{className:"mt-6 text-center text-xs text-theme-text-tertiary",children:_("login.footer")}),t.jsx("div",{className:"mt-4 px-2 py-3 rounded-xl text-xs text-theme-text-tertiary border leading-relaxed text-center",children:_("login.disclaimer")})]})]})}const rb=8;function IN({onSetup:e}){const[s,i]=S.useState(""),[a,u]=S.useState(""),[f,m]=S.useState(""),[o,l]=S.useState(!1),{t:d,toggleLang:p}=ht(),h=s.length>0&&s.length<rb,g=a.length>0&&s!==a,b=s.length>=rb&&s===a&&!o,C=async k=>{if(k.preventDefault(),!!b){m(""),l(!0);try{await e(s,a)}catch(x){m(x instanceof Error&&x.message?x.message:d("setup.error"))}finally{l(!1)}}};return t.jsxs("div",{className:"min-h-screen bg-theme-bg flex items-center justify-center px-4 relative",children:[t.jsx("button",{onClick:p,className:"lang-toggle absolute top-6 right-6",children:d("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:d("setup.title")}),t.jsx("p",{className:"text-theme-muted text-sm mt-2",children:d("setup.subtitle")})]}),t.jsx("form",{onSubmit:C,children:t.jsxs("div",{className:"card p-8",children:[t.jsx("label",{className:"block text-sm font-medium text-theme-text-secondary mb-2",children:d("setup.password")}),t.jsx("input",{type:"password",value:s,onChange:k=>i(k.target.value),placeholder:"*************",className:"input-field text-base",autoFocus:!0}),h&&t.jsx("p",{className:"mt-1 text-2xs text-status-error",children:d("setup.tooShort")}),t.jsx("label",{className:"block text-sm font-medium text-theme-text-secondary mb-2 mt-5",children:d("setup.confirm")}),t.jsx("input",{type:"password",value:a,onChange:k=>u(k.target.value),placeholder:"*************",className:"input-field text-base"}),g&&t.jsx("p",{className:"mt-1 text-2xs text-status-error",children:d("setup.mismatch")}),f&&t.jsx("div",{className:"mt-4 py-2.5 px-4 bg-status-error/5 border border-status-error/20 rounded-xl text-sm text-status-error",children:f}),t.jsx("button",{type:"submit",disabled:!b,className:"btn-primary w-full mt-6 py-3",children:d(o?"setup.loading":"setup.submit")})]})}),t.jsx("div",{className:"mt-4 px-4 py-3 rounded-xl text-xs text-theme-text-tertiary border leading-relaxed text-center",children:d("setup.tunnelPaused")})]})]})}function FN(e){return it("/api/projects/browse",{initialPath:e})}function HN(e){return it("/api/projects/open-folder",{path:e})}function Wu(){return xt("/api/projects")}function $N(e){return xt(`/api/projects/${e}`)}function c1(e){return it("/api/projects",e)}function UN(e){return xt(`/api/projects/${e}/svn-detect`)}function fm(e,s){return dn(`/api/projects/${e}`,s)}function WN(e,s){const i=s?`?todoId=${encodeURIComponent(s)}`:"";return xt(`/api/projects/${e}/debug-logs${i}`)}function u1(e){return Wn(`/api/projects/${e}`)}function qN(e){return it("/api/projects/reorder",{ids:e})}function GN(e){return it(`/api/projects/${e}/start`)}function KN(e){return it(`/api/projects/${e}/stop`)}function d1(e){return xt(`/api/projects/${e}/status`)}function ib(){return xt("/api/active-work")}function VN(e){return it(`/api/projects/${e}/check-git`)}function h1(e,s){const i=s?`?worktreePath=${encodeURIComponent(s)}`:"";return xt(`/api/projects/${e}/git-status${i}`)}function YN(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 mm(e,s){return xt(`/api/projects/${e}/git-refs`)}function XN(e,s,i){return it(`/api/projects/${e}/git-stage`,{files:s,worktreePath:i})}function JN(e,s,i){return it(`/api/projects/${e}/git-unstage`,{files:s,worktreePath:i})}function QN(e,s,i){return it(`/api/projects/${e}/git-ignore`,{path:s,worktreePath:i})}function f1(e,s,i){return it(`/api/projects/${e}/git-commit`,{message:s,worktreePath:i})}function m1(e,s,i){return it(`/api/projects/${e}/git-pull`,{remote:s,branch:i})}function cp(e,s){return it(`/api/projects/${e}/git-push`,s||{})}function ZN(e){return xt(`/api/projects/${e}/git-remotes`)}function p1(e,s,i){return it(`/api/projects/${e}/git-fetch`,{remote:s,prune:i})}function g1(e,s,i){return it(`/api/projects/${e}/git-branch`,{name:s,startPoint:i})}function pm(e,s,i){return it(`/api/projects/${e}/git-branch-delete`,{name:s,force:i})}function gm(e,s){return it(`/api/projects/${e}/git-checkout`,{branch:s})}function x1(e,s){return it(`/api/projects/${e}/git-merge`,{branch:s})}function ab(e,s,i,a){return it(`/api/projects/${e}/git-conflict-resolve`,{file:s,side:i,worktreePath:a})}function e3(e,s,i){const a=i?`&worktreePath=${encodeURIComponent(i)}`:"";return xt(`/api/projects/${e}/git-conflict-file?file=${encodeURIComponent(s)}${a}`)}function t3(e,s,i,a){return it(`/api/projects/${e}/git-conflict-file`,{file:s,content:i,worktreePath:a})}function n3(e){return it(`/api/projects/${e}/git-conflict-continue`)}function s3(e){return it(`/api/projects/${e}/git-conflict-abort`)}function r3(e,s){return it(`/api/projects/${e}/git-stash`,{message:s})}function i3(e,s){return it(`/api/projects/${e}/git-stash-pop`,{index:s})}function a3(e){return xt(`/api/projects/${e}/git-stash-list`)}function o3(e,s,i,a){return it(`/api/projects/${e}/git-discard`,{files:s,all:i,worktreePath:a})}function v1(e,s,i,a){return it(`/api/projects/${e}/git-tag`,{name:s,message:i,commit:a})}function ob(e,s,i){return it(`/api/projects/${e}/git-branch-rename`,{oldName:s,newName:i})}function l3(e,s){return it(`/api/projects/${e}/git-rebase`,{onto:s})}function c3(e,s){return it(`/api/projects/${e}/git-revert`,{commit:s})}function u3(e,s){return it(`/api/projects/${e}/git-cherry-pick`,{commit:s})}function d3(e,s,i){return it(`/api/projects/${e}/git-reset`,{commit:s,mode:i})}function h3(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 f3(e,s){const i=new URLSearchParams({hash:s});return xt(`/api/projects/${e}/git-commit-files?${i}`)}function lb(e,s,i){const a=new URLSearchParams({hash:s});return i&&a.set("file",i),xt(`/api/projects/${e}/git-commit-diff?${a}`)}function xm(e){return xt(`/api/projects/${e}/worktrees`)}function cb(e,s,i){return it(`/api/projects/${e}/worktree-cleanup`,{worktreePath:s,branchName:i})}function b1(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 m3(e={}){return xt(`/api/review/queue${b1(e)}`)}function y1(e={}){return xt(`/api/review/summary${b1(e)}`)}function p3(e){return xt(`/api/review/diff/${encodeURIComponent(e)}`)}function g3(e,s){return xt(`/api/review/diff/${encodeURIComponent(e)}/file?path=${encodeURIComponent(s)}`)}function x3(){return xt("/api/favorites")}function v3(e){return it("/api/favorites",e)}function b3(e,s){return dn(`/api/favorites/${e}`,s)}function y3(e){return Wn(`/api/favorites/${e}`)}function w3(e){return it(`/api/favorites/${e}/launch`)}function _3(e){return it("/api/favorites/browse-file",{initialPath:e})}function vm(){return xt("/api/tunnel/status")}function S3(){return xt("/api/tunnel/config")}function k3(e){return dn("/api/tunnel/config",e)}function w1(e){return it("/api/tunnel/start",{})}function C3(){return it("/api/tunnel/stop")}const _1=S.createContext({theme:"light",toggleTheme:()=>{}});function j3(){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 E3(){return S.useContext(_1)}const S1=S.createContext({enabled:!1,supported:!1,toggleNotification:()=>{},sendNotification:()=>{}});function N3(){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((m,o)=>{if(!a.current)return;const l=new Notification(m,{body:o});l.onclick=()=>{window.focus(),l.close()}},[]);return{enabled:s,supported:e,toggleNotification:u,sendNotification:f}}function up(){return S.useContext(S1)}let L3=0;const k1=S.createContext(null);function D3({children:e}){const[s,i]=S.useState([]),a=S.useRef(new Map),u=S.useRef(new Map),f=S.useRef(new Map),m=S.useCallback(b=>{i(x=>x.filter(y=>y.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}`,y=u.current.get(x);if(y)return y;const _=`toast-${++L3}`;u.current.set(x,_),f.current.set(_,x),i(E=>[...E,{id:_,message:b,type:C,duration:k}]);const w=setTimeout(()=>m(_),k);return a.current.set(_,w),_},[m]),l=S.useCallback((b,C)=>o(b,"success",C),[o]),d=S.useCallback((b,C)=>o(b,"error",C),[o]),p=S.useCallback((b,C)=>o(b,"info",C),[o]),h=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:l,error:d,info:p,warning:h,dismiss:m}),[s,o,l,d,p,h,m]);return S.createElement(k1.Provider,{value:g},e)}function Ls(){const e=S.useContext(k1);if(!e)throw new Error("useToast must be used within ToastProvider");return e}function Hs(...e){return e.filter(Boolean).join(" ")}const T3={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:m}){const o=S.useRef(null);return S.useEffect(()=>{if(!e||u)return;const l=d=>{d.key==="Escape"&&s()};return document.addEventListener("keydown",l),()=>document.removeEventListener("keydown",l)},[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:l=>{!f&&l.target===o.current&&s()},children:t.jsx("div",{className:Hs("w-full",T3[i]),children:m})}),document.body):null}const R3={default:"btn",primary:"btn-primary",secondary:"btn-secondary",danger:"btn-danger",ghost:"btn-ghost"},M3={sm:"btn-sm",md:"btn-md",lg:"btn-lg"},Bt=S.forwardRef(function({variant:s="default",size:i,type:a="button",className:u,...f},m){return t.jsx("button",{ref:m,type:a,className:Hs(R3[s],i&&M3[i],u),...f})}),C1=S.createContext(null);let ub=0;function A3({children:e}){const[s,i]=S.useState(null),a=S.useRef(null),u=S.useCallback(d=>{const p=a.current;p&&(p.kind==="confirm"?p.resolve(!1):p.resolve(null)),a.current=d,i(d)},[]),f=S.useCallback(()=>{a.current=null,i(null)},[]),m=S.useCallback(d=>{const p=typeof d=="string"?{message:d}:d;return new Promise(h=>{u({id:++ub,kind:"confirm",options:p,resolve:h})})},[u]),o=S.useCallback(d=>{const p=typeof d=="string"?{message:d}:d;return new Promise(h=>{u({id:++ub,kind:"prompt",options:p,resolve:h})})},[u]),l=S.useMemo(()=>({confirm:m,prompt:o}),[m,o]);return t.jsxs(C1.Provider,{value:l,children:[e,s&&t.jsx(z3,{dialog:s,onSettled:f},s.id)]})}function z3({dialog:e,onSettled:s}){const{t:i}=ht(),[a,u]=S.useState(e.kind==="prompt"?e.options.initialValue??"":""),f=()=>{e.kind==="confirm"?e.resolve(!1):e.resolve(null),s()},m=()=>{e.kind==="confirm"?e.resolve(!0):e.resolve(a),s()},o=e.kind==="confirm"&&!!e.options.danger,l=e.kind==="confirm"&&e.options.confirmLabel||i("common.ok"),d=e.kind==="confirm"&&e.options.cancelLabel||i("common.cancel"),p=t.jsxs("div",{className:"mt-4 flex justify-end gap-2",children:[t.jsx(Bt,{size:"sm",onClick:f,autoFocus:o,children:d}),t.jsx(Bt,{variant:o?"danger":"primary",size:"sm",type:e.kind==="prompt"?"submit":"button",onClick:e.kind==="prompt"?void 0:m,autoFocus:e.kind==="confirm"&&!o,children:l})]});return t.jsx(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:h=>{h.preventDefault(),m()},children:[t.jsx("input",{autoFocus:!0,value:a,onChange:h=>u(h.target.value),placeholder:e.options.placeholder,className:"input-field mt-3"}),p]}):p]})})}function qn(){const e=S.useContext(C1);if(!e)throw new Error("useDialog must be used within DialogProvider");return e}function j1({onSubmit:e,onCancel:s}){const[i,a]=S.useState(""),[u,f]=S.useState(""),[m,o]=S.useState(!1),[l,d]=S.useState(!1),[p,h]=S.useState(""),{t:g}=ht(),b=async k=>{if(k.preventDefault(),!(!i.trim()||!u.trim())){h(""),d(!0);try{await e(i.trim(),u.trim())}catch(x){const y=x instanceof Error?x.message:String(x);h(y||g("form.createError"))}finally{d(!1)}}},C=async()=>{o(!0);try{const k=await FN(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:m,className:"btn-ghost text-sm px-3 shrink-0",title:g("browse.title"),children:m?t.jsx(hi,{size:16,className:"animate-spin"}):t.jsx($u,{size:16})})]})]}),p&&t.jsx("p",{className:"text-sm mb-4",style:{color:"var(--color-danger, #ef4444)"},children:p}),t.jsxs("div",{className:"flex justify-end gap-3",children:[t.jsx("button",{type:"button",onClick:s,className:"btn-ghost text-sm",children:g("form.cancel")}),t.jsx("button",{type:"submit",disabled:!i.trim()||!u.trim()||l,className:"btn-primary text-sm",children:g(l?"form.creating":"form.create")})]})]})]})})}const O3=[{value:"executable",icon:ip},{value:"command",icon:gi},{value:"url",icon:fl}];function B3(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 db(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 P3({initial:e,onSubmit:s,onCancel:i}){const{t:a}=ht(),[u,f]=S.useState((e==null?void 0:e.name)??""),[m,o]=S.useState((e==null?void 0:e.type)??"executable"),[l,d]=S.useState((e==null?void 0:e.target)??""),[p,h]=S.useState(db((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"),d((e==null?void 0:e.target)??""),h(db((e==null?void 0:e.args)??null)),b((e==null?void 0:e.cwd)??"")},[e]);const[x,y]=S.useState(!1),_=m==="executable",w=async()=>{y(!0);try{const{path:B}=await _3(l||void 0);if(!B)return;if(d(B),!u.trim()){const O=B.replace(/\\/g,"/").split("/").pop()||"";f(O.replace(/\.[^.]+$/,""))}}catch{}finally{y(!1)}},E=!!e,T=u.trim(),j=l.trim(),D=m!=="url"||/^https?:\/\//i.test(j),N=!!T&&!!j&&D&&!C,R=async B=>{if(B.preventDefault(),!!N){k(!0);try{const O={name:T,type:m,target:j,args:m==="executable"&&p.trim()?B3(p.trim()):null,cwd:m!=="url"&&g.trim()?g.trim():null};await s(O)}finally{k(!1)}}},A=a(m==="executable"?"favorites.form.targetHint.executable":m==="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:R,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:O3.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:m===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:l,onChange:B=>d(B.target.value),className:"input-field text-sm font-mono flex-1",placeholder:A}),_&&t.jsxs("button",{type:"button",onClick:w,disabled:x,className:"btn-ghost text-sm whitespace-nowrap flex items-center gap-1.5 disabled:opacity-50",children:[t.jsx($u,{size:14}),a("favorites.form.browse")]})]}),t.jsx("p",{className:"mt-1 text-2xs",style:{color:"var(--color-text-muted)"},children:A})]}),m==="executable"&&t.jsxs("div",{className:"mb-5",children:[t.jsx("label",{className:"block text-sm font-medium text-warm-600 mb-2",children:a("favorites.form.args")}),t.jsx("input",{type:"text",value:p,onChange:B=>h(B.target.value),className:"input-field text-sm font-mono",placeholder:'--flag value "with spaces"'})]}),m!=="url"&&t.jsxs("div",{className:"mb-5",children:[t.jsx("label",{className:"block text-sm font-medium text-warm-600 mb-2",children:a("favorites.form.cwd")}),t.jsx("input",{type:"text",value:g,onChange: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 I3=/^([a-z0-9]([a-z0-9-]*[a-z0-9])?\.)+[a-z]{2,}$/i;function F3({onClose:e}){const{t:s}=ht(),{error:i,success:a}=Ls(),[u,f]=S.useState(""),[m,o]=S.useState(""),[l,d]=S.useState(""),[p,h]=S.useState(""),[g,b]=S.useState(!1),[C,k]=S.useState(!1),[x,y]=S.useState(!1),[_,w]=S.useState(null);S.useEffect(()=>{let O=!1;return Promise.all([S3(),vm()]).then(([F,U])=>{O||(f(F.tunnelName),o(F.customHostname),d(F.tunnelName),h(F.customHostname),w(U))}).catch(()=>{}),()=>{O=!0}},[]);const E=u.trim(),T=m.trim(),j=E!==l.trim()||T!==p.trim(),D=!!T&&(!I3.test(T)||T.toLowerCase()==="localhost"||T.toLowerCase()==="127.0.0.1"),N=!!T&&!E,R=j&&!C&&!D&&!N,A=async()=>{if(R){k(!0);try{const O=await k3({tunnelName:E,customHostname:T});d(O.tunnelName),h(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()=>{y(!0);try{try{await C3()}catch{}const O=await w1();w({status:"running",url:O.url}),a(s("tunnel.restarted"))}catch(O){i(O instanceof Error?O.message:s("tunnel.restartFailed"))}finally{y(!1)}};return t.jsxs("div",{className:"p-8",children:[t.jsx("h2",{className:"text-lg font-semibold text-warm-800 mb-1",children:s("tunnel.title")}),t.jsx("p",{className:"text-xs text-warm-400 mb-6",children:s("tunnel.description")}),_&&t.jsxs("div",{className:"mb-5 p-3 rounded-lg text-xs flex items-center gap-2",style:{backgroundColor:"var(--color-bg-hover)",color:"var(--color-text-tertiary)"},children:[t.jsx("span",{className:`w-2 h-2 rounded-full ${_.status==="running"?"bg-status-success":_.status==="error"?"bg-status-error":"bg-status-pending"}`}),t.jsx("span",{className:"font-medium",children:s(`tunnel.status.${_.status}`)}),_.url&&t.jsx("a",{href:_.url,target:"_blank",rel:"noreferrer",className:"ml-auto font-mono truncate hover:underline",style:{color:"var(--color-accent)"},children:_.url})]}),t.jsxs("div",{className:"mb-4",children:[t.jsx("label",{className:"block text-sm font-medium text-warm-600 mb-2",children:s("tunnel.name.label")}),t.jsx("input",{type:"text",value:u,onChange:O=>f(O.target.value),placeholder:s("tunnel.name.placeholder"),className:"input-field text-sm font-mono"}),t.jsx("p",{className:"mt-1 text-2xs",style:{color:"var(--color-text-muted)"},children:s("tunnel.name.hint")})]}),t.jsxs("div",{className:"mb-4",children:[t.jsx("label",{className:"block text-sm font-medium text-warm-600 mb-2",children:s("tunnel.hostname.label")}),t.jsx("input",{type:"text",value:m,onChange:O=>o(O.target.value),placeholder:s("tunnel.hostname.placeholder"),className:"input-field text-sm font-mono"}),t.jsx("p",{className:"mt-1 text-2xs",style:{color:"var(--color-text-muted)"},children:s("tunnel.hostname.hint")}),D&&t.jsx("p",{className:"mt-1 text-2xs text-status-error",children:s("tunnel.hostname.invalid")}),N&&t.jsx("p",{className:"mt-1 text-2xs text-status-error",children:s("tunnel.hostname.needsName")})]}),t.jsxs("div",{className:"mb-5",children:[t.jsxs("button",{type:"button",onClick:()=>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?(_==null?void 0:_.status)==="running"?s("tunnel.restarting"):s("tunnel.starting"):(_==null?void 0:_.status)==="running"?s("tunnel.restart"):s("tunnel.start")}),t.jsxs("div",{className:"flex gap-3",children:[e&&t.jsx("button",{type:"button",onClick:e,className:"btn-ghost text-sm",children:s("tunnel.close")}),t.jsx("button",{type:"button",onClick:A,disabled:!R,className:"btn-primary text-sm",children:s(C?"tunnel.saving":"tunnel.save")})]})]})]})}const hb=8;function H3({onClose:e}){const{t:s}=ht(),{error:i,success:a}=Ls(),[u,f]=S.useState(""),[m,o]=S.useState(""),[l,d]=S.useState(""),[p,h]=S.useState(!1),g=m.length>0&&m.length<hb,b=l.length>0&&m!==l,C=!!u&&m.length>=hb&&m===l&&!p,k=()=>{f(""),o(""),d("")},x=async()=>{if(C){h(!0);try{await Kw(u,m,l),a(s("account.saved")),k()}catch(y){i(y instanceof Error&&y.message?y.message:s("account.saveFailed"))}finally{h(!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:y=>f(y.target.value),className:"input-field text-sm",autoComplete:"current-password"})]}),t.jsxs("div",{className:"mb-4",children:[t.jsx("label",{className:"block text-sm font-medium text-warm-600 mb-2",children:s("account.newPassword")}),t.jsx("input",{type:"password",value:m,onChange:y=>o(y.target.value),className:"input-field text-sm",autoComplete:"new-password"}),g&&t.jsx("p",{className:"mt-1 text-2xs text-status-error",children:s("account.tooShort")})]}),t.jsxs("div",{className:"mb-6",children:[t.jsx("label",{className:"block text-sm font-medium text-warm-600 mb-2",children:s("account.confirm")}),t.jsx("input",{type:"password",value:l,onChange:y=>d(y.target.value),className:"input-field text-sm",autoComplete:"new-password"}),b&&t.jsx("p",{className:"mt-1 text-2xs text-status-error",children:s("account.mismatch")})]}),t.jsxs("div",{className:"flex items-center justify-end gap-3",children:[e&&t.jsx("button",{type:"button",onClick:e,className:"btn-ghost text-sm",children:s("account.close")}),t.jsx("button",{type:"button",onClick:x,disabled:!C,className:"btn-primary text-sm",children:s(p?"account.saving":"account.save")})]})]})}function dp(){return xt("/api/session-tags")}function $3(e){return it("/api/session-tags",e)}function U3(e,s){return dn(`/api/session-tags/${e}`,s)}function W3(e){return Wn(`/api/session-tags/${e}`)}function E1(){return xt("/api/session-aliases")}function N1(e){return it("/api/session-aliases",e)}function q3(e,s){return dn(`/api/session-aliases/${e}`,s)}function G3(e){return Wn(`/api/session-aliases/${e}`)}function hp(){return xt("/api/session-settings")}function xf(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",fp=13,nl=8,sl=28,Ga=new Map,Ui=new Map;let ku=fp;function mp(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);Ga.delete(s);const i=Ui.get(s);if(i){const u=rl(s);i.forEach(f=>f(u))}});function bm(e){return Number.isFinite(e)?Math.max(nl,Math.min(sl,Math.round(e))):ku}function K3(e){if(Ga.has(e))return!0;try{return localStorage.getItem(mp(e))!==null}catch{return!1}}function rl(e){const s=Ga.get(e);if(s!==void 0)return s;let i=null;try{const a=localStorage.getItem(mp(e));if(a!==null){const u=parseInt(a,10);Number.isFinite(u)&&(i=bm(u))}}catch{}return i===null?bm(ku):(Ga.set(e,i),i)}function ym(e,s){const i=bm(s);if(Ga.get(e)===i)return;Ga.set(e,i);try{localStorage.setItem(mp(e),String(i))}catch{}const a=Ui.get(e);a&&a.forEach(u=>u(i))}function Go(e,s){ym(e,rl(e)+s)}function du(e){const s=Math.max(nl,Math.min(sl,Math.round(e)));Number.isFinite(s)&&s!==ku&&(ku=s,Ui.forEach((i,a)=>{K3(a)||i.forEach(u=>u(s))}))}function L1(e){const[s,i]=S.useState(()=>rl(e));S.useEffect(()=>{i(rl(e));let f=Ui.get(e);return f||(f=new Set,Ui.set(e,f)),f.add(i),()=>{const m=Ui.get(e);m&&(m.delete(i),m.size===0&&Ui.delete(e))}},[e]);const a=S.useCallback(f=>ym(e,f),[e]),u=S.useCallback(f=>ym(e,rl(e)+f),[e]);return[s,a,u]}const il=["#A78BFA","#F472B6","#FB923C","#FBBF24","#34D399","#60A5FA","#F87171","#94A3B8"];function fb(e){for(const s of il)if(!e.some(i=>i.color.toLowerCase()===s.toLowerCase()))return s;return il[e.length%il.length]}function V3({onClose:e}){const{t:s}=ht(),{confirm:i}=qn(),{error:a,success:u}=Ls(),[f,m]=S.useState([]),[o,l]=S.useState(!1),[d,p]=S.useState(fp),[h,g]=S.useState(!1),[b,C]=S.useState(!1),[k,x]=S.useState(!1),[y,_]=S.useState(!1),w=S.useRef(null),[E,T]=S.useState(""),[j,D]=S.useState(il[0]),[N,R]=S.useState(!1),[A,B]=S.useState(null),[O,F]=S.useState(""),[U,I]=S.useState(il[0]),[H,W]=S.useState(!1),[K,P]=S.useState([]),[z,$]=S.useState(""),[Y,q]=S.useState(""),[oe,ce]=S.useState(!1),[ne,te]=S.useState(null),[G,de]=S.useState(""),[he,be]=S.useState(""),[ae,De]=S.useState(!1);S.useEffect(()=>{let J=!1;return Promise.all([dp(),hp(),E1()]).then(([ee,pe,we])=>{J||(m(ee),l(pe.defaultUseWorktree),p(pe.defaultFontSize),du(pe.defaultFontSize),g(pe.imeDebug),D(fb(ee)),P(we),C(!0))}).catch(ee=>{J||a(ee instanceof Error?ee.message:"Failed to load")}),()=>{J=!0}},[a]);const Re=E.trim(),ve=!!Re&&!N,Me=S.useMemo(()=>[...f].sort((J,ee)=>J.sort_order-ee.sort_order||J.name.localeCompare(ee.name)),[f]);S.useEffect(()=>()=>{w.current&&clearTimeout(w.current)},[]);const Oe=J=>{if(!Number.isFinite(J))return;const ee=Math.max(nl,Math.min(sl,Math.round(J)));p(ee),du(ee),w.current&&clearTimeout(w.current),w.current=setTimeout(()=>{xf({defaultFontSize:ee}).then(pe=>{p(pe.defaultFontSize),du(pe.defaultFontSize)}).catch(pe=>a(pe instanceof Error?pe.message:"Save failed"))},350)},tt=async J=>{x(!0);try{const ee=await xf({defaultUseWorktree:J});l(ee.defaultUseWorktree),u(s("sessionSettings.saved"))}catch(ee){a(ee instanceof Error?ee.message:"Save failed")}finally{x(!1)}},nt=async J=>{var ee,pe;_(!0);try{const we=await xf({imeDebug:J});g(we.imeDebug),(pe=(ee=window.electronAPI)==null?void 0:ee.imeSetDebug)==null||pe.call(ee,we.imeDebug),u(s("sessionSettings.saved"))}catch(we){a(we instanceof Error?we.message:"Save failed")}finally{_(!1)}},ke=async()=>{if(ve){R(!0);try{const J=await $3({name:Re,color:j});m(ee=>[...ee,J]),T(""),D(fb([...f,J]))}catch(J){a(J instanceof Error?J.message:"Create failed")}finally{R(!1)}}},fe=J=>{B(J.id),F(J.name),I(J.color)},Te=()=>{B(null),F("")},Ce=async()=>{if(!A)return;const J=O.trim();if(J){W(!0);try{const ee=await U3(A,{name:J,color:U});m(pe=>pe.map(we=>we.id===ee.id?ee:we)),Te()}catch(ee){a(ee instanceof Error?ee.message:"Save failed")}finally{W(!1)}}},Ke=async J=>{if(await i({message:s("sessionSettings.tags.deleteConfirm").replace("{name}",J.name),danger:!0}))try{await W3(J.id),m(ee=>ee.filter(pe=>pe.id!==J.id))}catch(ee){a(ee instanceof Error?ee.message:"Delete failed")}},Ze=z.trim(),ye=Y.trim(),Be=!!Ze&&!!ye&&!oe,Z=S.useMemo(()=>[...K].sort((J,ee)=>J.sort_order-ee.sort_order||J.name.localeCompare(ee.name)),[K]),_e=async()=>{if(Be){ce(!0);try{const J=await N1({name:Ze,command_template:ye});P(ee=>[...ee,J]),$(""),q("")}catch(J){a(J instanceof Error?J.message:"Create failed")}finally{ce(!1)}}},X=J=>{te(J.id),de(J.name),be(J.command_template)},me=()=>{te(null),de(""),be("")},se=async()=>{if(!ne)return;const J=G.trim(),ee=he.trim();if(!(!J||!ee)){De(!0);try{const pe=await q3(ne,{name:J,command_template:ee});P(we=>we.map(je=>je.id===pe.id?pe:je)),me()}catch(pe){a(pe instanceof Error?pe.message:"Save failed")}finally{De(!1)}}},ie=async J=>{if(await i({message:s("sessionSettings.aliases.deleteConfirm").replace("{name}",J.name),danger:!0}))try{await G3(J.id),P(ee=>ee.filter(pe=>pe.id!==J.id))}catch(ee){a(ee instanceof Error?ee.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(EN,{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:d,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:d,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=>D(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=>T(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(vn,{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 ee=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:ee?t.jsxs(t.Fragment,{children:[t.jsx("input",{type:"color",value:U,onChange:pe=>I(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(ir,{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(Vt,{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(mi,{size:14})}),t.jsx("button",{type:"button",onClick:()=>Ke(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=>$(J.target.value),placeholder:s("sessionSettings.aliases.namePlaceholder"),className:"input text-sm w-44",maxLength:64}),t.jsx("input",{type:"text",value:Y,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(vn,{size:14}),s("sessionSettings.aliases.add")]})]}),Z.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:Z.map(J=>{const ee=ne===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:ee?t.jsxs(t.Fragment,{children:[t.jsx("input",{type:"text",value:G,onChange:pe=>de(pe.target.value),className:"input text-sm w-44",maxLength:64}),t.jsx("input",{type:"text",value:he,onChange:pe=>be(pe.target.value),onKeyDown:pe=>{pe.key==="Enter"&&(pe.preventDefault(),se()),pe.key==="Escape"&&me()},autoFocus:!0,className:"input text-sm flex-1 font-mono",maxLength:1024}),t.jsx("button",{type:"button",onClick:se,disabled:ae||!G.trim()||!he.trim(),className:"p-1.5 text-status-success hover:bg-status-success/10 rounded-md",title:s("common.save"),children:t.jsx(ir,{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(Vt,{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(mi,{size:14})}),t.jsx("button",{type:"button",onClick:()=>ie(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(v5,{size:14}),"IME 디버그 로그"]}),t.jsxs("label",{className:"flex items-center gap-2 cursor-pointer select-none",children:[t.jsx("input",{type:"checkbox",checked:h,disabled:y||!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 Y3(){return xt("/api/mcp/connection")}function X3({onClose:e}){const{t:s}=ht(),{success:i,error:a}=Ls(),[u,f]=S.useState(null),[m,o]=S.useState(null);S.useEffect(()=>{let g=!1;return Y3().then(b=>{g||f(b)}).catch(()=>{}),()=>{g=!0}},[]);const l=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"))}},d=u?JSON.stringify(u.config,null,2):"",p=({label:g,text:b})=>t.jsxs("button",{type:"button",onClick:()=>l(g,b),className:"btn-ghost text-xs flex items-center gap-1",children:[m===g?t.jsx(ir,{size:14}):t.jsx(J5,{size:14}),s("mcp.copy")]}),h={backgroundColor:"var(--color-bg-hover)",color:"var(--color-text-secondary)"};return t.jsxs("div",{className:"p-8",children:[t.jsx("h2",{className:"text-lg font-semibold text-warm-800 mb-1",children:s("mcp.title")}),t.jsx("p",{className:"text-xs text-warm-400 mb-6",children:s("mcp.description")}),u?t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"mb-5",children:[t.jsxs("div",{className:"flex items-center justify-between mb-2",children:[t.jsx("label",{className:"block text-sm font-medium text-warm-600",children:s("mcp.config.label")}),t.jsx(p,{label:"config",text:d})]}),t.jsx("pre",{className:"p-3 rounded-lg text-2xs font-mono overflow-x-auto",style:h,children:d})]}),t.jsxs("div",{className:"mb-5",children:[t.jsx("label",{className:"block text-sm font-medium text-warm-600 mb-1",children:s("mcp.commands.label")}),t.jsx("p",{className:"text-2xs text-warm-400 mb-3",children:s("mcp.commands.hint")}),t.jsx("div",{className:"space-y-3",children:u.commands.map(g=>t.jsxs("div",{children:[t.jsxs("div",{className:"flex items-center justify-between mb-1",children:[t.jsx("span",{className:"text-xs text-warm-500",children:g.label}),t.jsx(p,{label:`command:${g.id}`,text:g.command})]}),t.jsx("pre",{className:"p-3 rounded-lg text-2xs font-mono overflow-x-auto",style:h,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 mb({open:e,onClose:s}){const{t:i}=ht(),[a,u]=S.useState("account");if(!e)return null;const f=[{id:"account",label:i("settings.tabs.account"),icon:NE},{id:"session",label:i("settings.tabs.session"),icon:ml},{id:"tunnel",label:i("settings.tabs.tunnel"),icon:n1},{id:"mcp",label:i("settings.tabs.mcp"),icon:oN}];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:m,label:o,icon:l})=>{const d=a===m;return t.jsxs("button",{type:"button",onClick:()=>u(m),className:"flex items-center gap-2 px-4 py-2.5 text-sm transition-colors text-left",style:{color:d?"var(--color-accent)":"var(--color-text-secondary)",backgroundColor:d?"var(--color-bg-primary)":"transparent",fontWeight:d?600:400},children:[t.jsx(l,{size:14}),t.jsx("span",{children:o})]},m)})}),t.jsxs("div",{className:"px-4 py-3 mt-auto text-[11px] tracking-wide",style:{color:"var(--color-text-muted)"},children:["v","0.2.56"]})]}),t.jsxs("div",{className:"flex-1 min-w-0",children:[a==="account"&&t.jsx(H3,{onClose:s}),a==="session"&&t.jsx(V3,{onClose:s}),a==="tunnel"&&t.jsx(F3,{onClose:s}),a==="mcp"&&t.jsx(X3,{onClose:s})]})]})})})}const wm=["#55708F","#4F7A68","#9A783F","#A15F5A","#74658A","#925F73","#477B7D","#747A50"];function J3(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 Ka(e){return e.color&&/^#[0-9a-f]{6}$/i.test(e.color)?e.color:wm[J3(e.id,wm.length)]}const pb=192,Q3=88,$c=8;function Z3({project:e,anchorX:s,anchorY:i,onPick:a,onClose:u}){const f=S.useRef(null),[m,o]=S.useState({left:s,top:i}),l=Ka(e);return S.useLayoutEffect(()=>{const d=Math.min(Math.max(s,$c),window.innerWidth-pb-$c),p=Math.min(Math.max(i,$c),window.innerHeight-Q3-$c);o({left:d,top:p})},[s,i]),S.useEffect(()=>{const d=h=>{var g;(g=f.current)!=null&&g.contains(h.target)||u()},p=h=>{h.key==="Escape"&&u()};return window.addEventListener("mousedown",d),window.addEventListener("keydown",p),()=>{window.removeEventListener("mousedown",d),window.removeEventListener("keydown",p)}},[u]),rn.createPortal(t.jsxs("div",{ref:f,role:"menu",className:"z-tooltip",style:{position:"fixed",left:m.left,top:m.top,width:pb,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:wm.map(d=>{const p=e.color?d.toLowerCase()===e.color.toLowerCase():d===l&&!e.color;return t.jsx("button",{onClick:()=>a(d),"aria-label":d,style:{width:20,height:20,borderRadius:6,background:d,border:p?"2px solid var(--color-text-primary)":"2px solid transparent",cursor:"pointer",padding:0}},d)})}),t.jsx("button",{onClick:()=>a(null),style:{width:"100%",background:"transparent",border:"1px solid var(--color-border)",color:"var(--color-text-tertiary)",padding:"4px 8px",borderRadius:6,fontSize:11,cursor:"pointer"},children:"자동 색 (기본값)"})]}),document.body)}function al(e,s){return e instanceof Error&&e.message.trim()?e.message:typeof e=="string"&&e.trim()?e:s}function e4(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 t4={sm:"btn-icon-sm",md:"btn-icon-md",lg:"btn-icon-lg"},n4={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:m,className:o,...l},d){return t.jsx("button",{ref:d,type:f,"aria-label":s,"aria-pressed":u,title:m??s,className:Hs("btn-icon",t4[i],n4[a],o),...l})});function s4(e){return e==="executable"?ip:e==="command"?gi:fl}function r4({onLogout:e,authRequired:s,connected:i,onEvent:a,onClose:u,collapsed:f=!1,onToggleCollapsed:m}){var Be;const[o,l]=S.useState([]),[d,p]=S.useState({}),[h,g]=S.useState(null),[b,C]=S.useState(!1),[k,x]=S.useState(null),[y,_]=S.useState([]),[w,E]=S.useState(!1),[T,j]=S.useState(null),[D,N]=S.useState(!1),[R,A]=S.useState(null),[B,O]=S.useState(!1),[F,U]=S.useState(null),[I,H]=S.useState(null),W=qs(),K=vi(),{t:P,toggleLang:z}=ht(),{theme:$,toggleTheme:Y}=E3(),{enabled:q,supported:oe,toggleNotification:ce}=up(),{error:ne,success:te,info:G,warning:de}=Ls(),{confirm:he}=qn(),be=((Be=W.pathname.match(/^\/projects\/([^/]+)/))==null?void 0:Be[1])||null;S.useEffect(()=>{nt(),De(),vm().then(A).catch(()=>{})},[]);async function ae(){if(!B){O(!0);try{const Z=await vm();if(A(Z),Z.status==="running"&&Z.url){await navigator.clipboard.writeText(Z.url),te(P("tunnel.urlCopied"));return}const _e=await w1(),X={status:"running",url:_e.url};A(X);try{await navigator.clipboard.writeText(_e.url),te(P("tunnel.urlCopied"))}catch{te(_e.url)}}catch(Z){ne(Z instanceof Error?Z.message:P("tunnel.restartFailed"))}finally{O(!1)}}}function De(){x3().then(_).catch(()=>{})}const Re=async Z=>{try{T?await b3(T.id,Z):await v3(Z),E(!1),j(null),De()}catch(_e){ne(_e instanceof Error?_e.message:"Failed to save favorite")}},ve=async Z=>{try{await w3(Z)}catch(_e){const X=_e instanceof Error?_e.message:P("favorites.launchFailed");ne(`${P("favorites.launchFailed")}: ${X}`)}},Me=async(Z,_e)=>{if(_e.preventDefault(),_e.stopPropagation(),!!await he({message:P("favorites.deleteConfirm"),danger:!0}))try{await y3(Z),_(X=>X.filter(me=>me.id!==Z))}catch(X){ne(X instanceof Error?X.message:"Failed to delete favorite")}},Oe=(Z,_e)=>{_e.preventDefault(),_e.stopPropagation(),j(Z),E(!0)};S.useEffect(()=>{const Z=()=>nt();return window.addEventListener("projects:changed",Z),()=>window.removeEventListener("projects:changed",Z)},[]),S.useEffect(()=>{const Z=()=>tt();return window.addEventListener("review:changed",Z),()=>window.removeEventListener("review:changed",Z)},[]),S.useEffect(()=>a(Z=>{var _e;if(Z.type==="project:status-changed"&&Z.projectId&&p(X=>({...X,[Z.projectId]:{running:Z.running??0,completed:Z.completed??0,total:Z.total??0,running_sessions:Z.running_sessions??0,running_discussions:Z.running_discussions??0}})),Z.type==="todo:status-changed"&&tt(),Z.type==="memory:ingest-finished"){const X=o.find(je=>je.id===Z.projectId),me=(X==null?void 0:X.name)??"",se=Z.sourceTitle?`“${Z.sourceTitle}”`:Z.sourceType??"",ie=me?`[${me}] `:"";if(Z.error){ne(`${ie}${P("wiki.ingest.toast.failed")}: ${Z.error}`,6e3);return}const J=Z.created??0,ee=Z.updated??0,pe=Z.edgesAdded??0;if(J+ee+pe>0){const je=P("wiki.ingest.toast.success").replace("{source}",se).replace("{created}",String(J)).replace("{updated}",String(ee)).replace("{edges}",String(pe));te(`${ie}${je}`)}else(_e=Z.skipped)!=null&&_e.parseFailed?de(`${ie}${P("wiki.ingest.toast.parseFailed").replace("{source}",se)}`,5e3):G(`${ie}${P("wiki.ingest.toast.empty").replace("{source}",se)}`,4e3)}}),[a,o,P,ne,G,te,de]),S.useEffect(()=>{tt()},[]);function tt(){y1({hours:24}).then(Z=>g(Z.total_todos)).catch(()=>{})}function nt(){Wu().then(Z=>{l(Z),Z.forEach(_e=>{d1(_e.id).then(X=>{p(me=>({...me,[_e.id]:X}))}).catch(()=>{})})}).catch(()=>{})}const ke=()=>{u==null||u()},fe=async(Z,_e)=>{await c1({name:Z,path:_e}),C(!1),window.dispatchEvent(new Event("projects:changed"))},Te=S.useCallback(async(Z,_e)=>{const X=o.map(je=>je.id),me=X.indexOf(Z);if(me<0)return;const se=X.filter(je=>je!==Z),ie=_e>me?_e-1:_e;if(ie===me)return;const J=[...se.slice(0,ie),Z,...se.slice(ie)],ee=o,pe=new Map(o.map(je=>[je.id,je])),we=J.map(je=>pe.get(je)).filter(Boolean);l(we);try{await qN(J)}catch(je){l(ee),ne(je instanceof Error?je.message:"Failed to reorder projects")}},[o,ne]),Ce=S.useRef(!1),Ke=S.useCallback((Z,_e)=>{if(_e.button!==0||_e.target.closest("button"))return;_e.preventDefault();const me=_e.clientX,se=_e.clientY,ie=6;let J=!1,ee=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-se)<ie)return;J=!0,U(Z)}const Ee=pe(qe.clientY);Ee!==ee&&(ee=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=ee;U(null),H(null),qe!==null&&Te(Z,qe)},Je=qe=>{qe.key==="Escape"&&(je(),U(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(Z,_e)=>{if(_e.preventDefault(),_e.stopPropagation(),!!await he({message:P("projects.deleteConfirm"),danger:!0}))try{await u1(Z),l(X=>X.filter(me=>me.id!==Z)),window.dispatchEvent(new Event("projects:changed")),be===String(Z)&&K("/")}catch(X){ne(al(X,P("errors.projectDelete")))}},ye=Z=>t.jsx("div",{className:"pointer-events-none absolute left-2 right-2 h-0.5 rounded-full",style:{backgroundColor:"var(--color-accent)",zIndex:10,...Z==="above"?{top:-1}:{bottom:-1}}});if(f){const Z=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:m,label:P("sidebar.expand"),size:"lg",children:t.jsx(l1,{size:16})}),Z,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:P("sidebar.home"),children:t.jsx(J0,{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:P("sidebar.review"),children:[t.jsx(wu,{size:16}),h!==null&&h>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:P("sidebar.agenda"),children:t.jsx(om,{size:16})}),Z,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=d[_e.id],me=be===String(_e.id),se=X?X.running+X.running_sessions+X.running_discussions:0,ie=se>0,J=Ka(_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:ie?`${_e.name} · ${se} ${P("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] ${ie?"workspace-dot-pulse":""}`,style:{backgroundColor:J,opacity:me||ie?1:.55}})]},_e.id)})}),Z,t.jsx("span",{className:`w-1.5 h-1.5 rounded-full my-1 ${i?"bg-status-success":"bg-status-error"}`,title:i?P("detail.live"):"Disconnected"}),t.jsx(Sn,{onClick:Y,label:P($==="light"?"theme.dark":"theme.light"),size:"lg",children:$==="light"?t.jsx(Z0,{size:16}):t.jsx(tb,{size:16})}),t.jsx(Sn,{onClick:()=>N(!0),label:P("settings.title"),size:"lg",children:t.jsx(Su,{size:16})}),t.jsx(mb,{open:D,onClose:()=>N(!1)})]})}return t.jsxs("div",{className:"flex flex-col h-full bg-theme-bg-secondary border-none",onDragStart:Z=>Z.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:m,label:P("sidebar.collapse"),size:"sm",className:"hidden md:inline-flex flex-shrink-0",children:t.jsx(o1,{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(J0,{size:16}),P("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(wu,{size:16}),t.jsx("span",{className:"flex-1",children:P("sidebar.review")}),h!==null&&h>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:h})]}),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(om,{size:16}),P("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:P("sidebar.workspaces")}),t.jsx(Sn,{onClick:()=>C(!0),label:P("projects.new"),size:"sm",children:t.jsx(vn,{size:14})})]}),t.jsx("div",{className:"space-y-0.5",children:o.map((Z,_e)=>{const X=d[Z.id],me=be===String(Z.id),se=X?X.running+X.running_sessions+X.running_discussions:0,ie=se>0,J=Ka(Z),ee=F===Z.id,pe=F!==null&&I===_e,we=F!==null&&_e===o.length-1&&I===o.length;return t.jsxs("div",{className:"relative","data-workspace-item":!0,children:[pe&&ye("above"),t.jsxs(Un,{to:`/projects/${Z.id}`,draggable:!1,onDragStart:je=>je.preventDefault(),onClick:je=>{if(Ce.current){je.preventDefault();return}ke()},onMouseDown:je=>Ke(Z.id,je),onContextMenu:je=>{je.preventDefault(),x({project:Z,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":""} ${ee?"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 ${ie?"workspace-dot-pulse":""}`,style:{backgroundColor:J,opacity:me||ie?1:.55},title:ie?`${P("sidebar.workspaces")} · ${se} ${P("detail.live")}`:Z.name}),t.jsx("span",{className:"truncate flex-1",children:Z.name}),t.jsx(Sn,{onClick:je=>Ze(Z.id,je),label:P("projects.delete"),size:"sm",variant:"danger",className:"flex-shrink-0 opacity-0 group-hover:opacity-100 focus-visible:opacity-100",children:t.jsx(Vt,{size:12})})]}),we&&ye("below")]},Z.id)})})]}),b&&t.jsx(j1,{onSubmit:(Z,_e)=>fe(Z,_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:P("sidebar.favorites")}),t.jsx(Sn,{onClick:()=>{j(null),E(!0)},label:P("favorites.add"),size:"sm",children:t.jsx(vn,{size:14})})]}),t.jsx("div",{className:"space-y-0.5 max-h-48 overflow-y-auto",children:y.map(Z=>{const _e=s4(Z.type);return t.jsxs("button",{onClick:()=>ve(Z.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:Z.target,children:[t.jsx(_e,{size:14,className:"flex-shrink-0"}),t.jsx("span",{className:"truncate flex-1 text-left",children:Z.name}),t.jsx("span",{onClick:X=>Oe(Z,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:P("favorites.edit"),children:t.jsx(dm,{size:12})}),t.jsx("span",{onClick:X=>Me(Z.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:P("favorites.delete"),children:t.jsx(Vt,{size:12})})]},Z.id)})})]}),w&&t.jsx(P3,{initial:T??void 0,onSubmit:Re,onCancel:()=>{E(!1),j(null)}}),k&&t.jsx(Z3,{project:k.project,anchorX:k.x,anchorY:k.y,onPick:async Z=>{try{const _e=await fm(k.project.id,{color:Z});l(X=>X.map(me=>me.id===_e.id?{...me,color:_e.color}:me)),window.dispatchEvent(new Event("projects:changed"))}catch(_e){ne(_e instanceof Error?_e.message:"Failed to update color")}x(null)},onClose:()=>x(null)}),t.jsx(mb,{open:D,onClose:()=>N(!1)}),t.jsx("div",{className:"px-3 pb-4 pt-2",style:{borderTop:"1px solid var(--color-border)"},children:t.jsxs("div",{className:"flex items-center gap-1 px-1",children:[t.jsx("span",{className:`w-1.5 h-1.5 rounded-full flex-shrink-0 mr-1 ${i?"bg-status-success":"bg-status-error"}`,title:i?P("detail.live"):"Disconnected"}),t.jsx(Sn,{onClick:Y,label:P($==="light"?"theme.dark":"theme.light"),children:$==="light"?t.jsx(Z0,{size:16}):t.jsx(tb,{size:16})}),t.jsx(Sn,{onClick:z,label:P("lang.toggle"),className:"text-xs font-medium",children:P("lang.toggle")}),oe&&t.jsx(Sn,{onClick:ce,label:"Notification"in window&&Notification.permission==="denied"?P("notification.blocked"):P("notification.toggle"),variant:q?"active":"default",pressed:q,children:q?t.jsx(g5,{size:16}):t.jsx(m5,{size:16})}),t.jsx(Sn,{onClick:ae,disabled:B,label:P("tunnel.start"),variant:(R==null?void 0:R.status)==="running"?"active":"default",pressed:(R==null?void 0:R.status)==="running",title:(R==null?void 0:R.status)==="running"&&R.url?`${R.url} — ${P("tunnel.urlCopied")}`:P(B?"tunnel.starting":"tunnel.start"),children:t.jsx(n1,{size:16})}),t.jsx(Sn,{onClick:()=>N(!0),label:P("settings.title"),children:t.jsx(Su,{size:16})}),s&&t.jsx(Sn,{onClick:e,label:P("projects.logout"),variant:"danger",className:"ml-auto",children:t.jsx(HE,{size:16})})]})})]})}function i4({children:e,onLogout:s,authRequired:i,connected:a,onEvent:u}){const[f,m]=S.useState(!1),{t:o}=ht(),[l,d]=S.useState(()=>localStorage.getItem("sidebarCollapsed")==="1"),p=()=>{d(h=>{const g=!h;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 ON=[["circle",{cx:"11",cy:"11",r:"8",key:"4ej97u"}],["line",{x1:"21",x2:"16.65",y1:"21",y2:"16.65",key:"13gj7c"}],["line",{x1:"8",x2:"14",y1:"11",y2:"11",key:"durymu"}]],BN=ot("zoom-out",ON),sb=8;function PN({onLogin:e,onChangePassword:s}){const[i,a]=S.useState(""),[u,f]=S.useState(""),[m,o]=S.useState(""),[l,d]=S.useState(!1),[p,h]=S.useState(!1),[g,b]=S.useState(!1),[C,k]=S.useState(""),[x,y]=S.useState(!1),{t:_,toggleLang:w}=ht(),E=l&&u.length>0&&u.length<sb,T=l&&m.length>0&&u!==m,j=l?!!i&&u.length>=sb&&u===m:!!i,D=()=>{d(R=>!R),f(""),o(""),k("")},N=async R=>{if(R.preventDefault(),!(!j||x)){k(""),y(!0);try{l?await s(i,u,m,g):await e(i,g)}catch(A){k(l&&A instanceof Error&&A.message?A.message:_("login.error"))}finally{y(!1)}}};return t.jsxs("div",{className:"min-h-screen bg-theme-bg flex items-center justify-center px-4 relative",children:[t.jsx("button",{onClick:w,className:"lang-toggle absolute top-6 right-6",children:_("lang.toggle")}),t.jsxs("div",{className:"w-full max-w-sm",children:[t.jsxs("div",{className:"text-center mb-10",children:[t.jsx("div",{className:"inline-flex items-center justify-center w-16 h-16 rounded-2xl bg-accent/10 mb-5",children:t.jsx(ml,{size:32,className:"text-accent"})}),t.jsx("h1",{className:"text-2xl font-semibold text-theme-text",children:_("login.title")}),t.jsx("p",{className:"text-theme-muted text-sm mt-2",children:_("login.subtitle")})]}),t.jsx("form",{onSubmit:N,children:t.jsxs("div",{className:"card p-8",children:[t.jsx("label",{className:"block text-sm font-medium text-theme-text-secondary mb-2",children:_(l?"account.oldPassword":"login.password")}),t.jsx("input",{type:"password",value:i,onChange:R=>a(R.target.value),placeholder:"*************",className:"input-field text-base",autoComplete:"current-password",autoFocus:!0}),l&&t.jsxs(t.Fragment,{children:[t.jsx("label",{className:"block text-sm font-medium text-theme-text-secondary mb-2 mt-4",children:_("account.newPassword")}),t.jsx("input",{type:"password",value:u,onChange:R=>f(R.target.value),className:"input-field text-base",autoComplete:"new-password","aria-label":_("account.newPassword")}),E&&t.jsx("p",{className:"mt-1 text-2xs text-status-error",children:_("account.tooShort")}),t.jsx("label",{className:"block text-sm font-medium text-theme-text-secondary mb-2 mt-4",children:_("account.confirm")}),t.jsx("input",{type:"password",value:m,onChange:R=>o(R.target.value),className:"input-field text-base",autoComplete:"new-password","aria-label":_("account.confirm")}),T&&t.jsx("p",{className:"mt-1 text-2xs text-status-error",children:_("account.mismatch")})]}),C&&t.jsx("div",{className:"mt-4 py-2.5 px-4 bg-status-error/5 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:R=>b(R.target.checked),className:"accent-accent w-4 h-4"}),_("login.rememberMe")]}),t.jsx("button",{type:"submit",disabled:!j||x,className:"btn-primary w-full mt-6 py-3",children:_(x?"login.loading":l?"login.changeSubmit":"login.submit")})]})}),t.jsxs("div",{className:"mt-4 flex items-center justify-center gap-5 text-xs",children:[t.jsx("button",{type:"button",onClick:D,className:"text-theme-muted hover:text-theme-text underline-offset-2 hover:underline",children:_(l?"login.backToLogin":"login.changePassword")}),t.jsx("button",{type:"button",onClick:()=>h(R=>!R),className:"text-theme-muted hover:text-theme-text underline-offset-2 hover:underline",children:_("login.forgot")})]}),p&&t.jsx("div",{className:"mt-3 px-4 py-3 rounded-xl text-xs text-theme-text-tertiary border leading-relaxed",children:_("login.forgotHint")}),t.jsx("div",{className:"mt-6 text-center text-xs text-theme-text-tertiary",children:_("login.footer")}),t.jsx("div",{className:"mt-4 px-2 py-3 rounded-xl text-xs text-theme-text-tertiary border leading-relaxed text-center",children:_("login.disclaimer")})]})]})}const rb=8;function IN({onSetup:e}){const[s,i]=S.useState(""),[a,u]=S.useState(""),[f,m]=S.useState(""),[o,l]=S.useState(!1),{t:d,toggleLang:p}=ht(),h=s.length>0&&s.length<rb,g=a.length>0&&s!==a,b=s.length>=rb&&s===a&&!o,C=async k=>{if(k.preventDefault(),!!b){m(""),l(!0);try{await e(s,a)}catch(x){m(x instanceof Error&&x.message?x.message:d("setup.error"))}finally{l(!1)}}};return t.jsxs("div",{className:"min-h-screen bg-theme-bg flex items-center justify-center px-4 relative",children:[t.jsx("button",{onClick:p,className:"lang-toggle absolute top-6 right-6",children:d("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:d("setup.title")}),t.jsx("p",{className:"text-theme-muted text-sm mt-2",children:d("setup.subtitle")})]}),t.jsx("form",{onSubmit:C,children:t.jsxs("div",{className:"card p-8",children:[t.jsx("label",{className:"block text-sm font-medium text-theme-text-secondary mb-2",children:d("setup.password")}),t.jsx("input",{type:"password",value:s,onChange:k=>i(k.target.value),placeholder:"*************",className:"input-field text-base",autoFocus:!0}),h&&t.jsx("p",{className:"mt-1 text-2xs text-status-error",children:d("setup.tooShort")}),t.jsx("label",{className:"block text-sm font-medium text-theme-text-secondary mb-2 mt-5",children:d("setup.confirm")}),t.jsx("input",{type:"password",value:a,onChange:k=>u(k.target.value),placeholder:"*************",className:"input-field text-base"}),g&&t.jsx("p",{className:"mt-1 text-2xs text-status-error",children:d("setup.mismatch")}),f&&t.jsx("div",{className:"mt-4 py-2.5 px-4 bg-status-error/5 border border-status-error/20 rounded-xl text-sm text-status-error",children:f}),t.jsx("button",{type:"submit",disabled:!b,className:"btn-primary w-full mt-6 py-3",children:d(o?"setup.loading":"setup.submit")})]})}),t.jsx("div",{className:"mt-4 px-4 py-3 rounded-xl text-xs text-theme-text-tertiary border leading-relaxed text-center",children:d("setup.tunnelPaused")})]})]})}function FN(e){return it("/api/projects/browse",{initialPath:e})}function HN(e){return it("/api/projects/open-folder",{path:e})}function Wu(){return xt("/api/projects")}function $N(e){return xt(`/api/projects/${e}`)}function c1(e){return it("/api/projects",e)}function UN(e){return xt(`/api/projects/${e}/svn-detect`)}function fm(e,s){return dn(`/api/projects/${e}`,s)}function WN(e,s){const i=s?`?todoId=${encodeURIComponent(s)}`:"";return xt(`/api/projects/${e}/debug-logs${i}`)}function u1(e){return Wn(`/api/projects/${e}`)}function qN(e){return it("/api/projects/reorder",{ids:e})}function GN(e){return it(`/api/projects/${e}/start`)}function KN(e){return it(`/api/projects/${e}/stop`)}function d1(e){return xt(`/api/projects/${e}/status`)}function ib(){return xt("/api/active-work")}function VN(e){return it(`/api/projects/${e}/check-git`)}function h1(e,s){const i=s?`?worktreePath=${encodeURIComponent(s)}`:"";return xt(`/api/projects/${e}/git-status${i}`)}function YN(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 mm(e,s){return xt(`/api/projects/${e}/git-refs`)}function XN(e,s,i){return it(`/api/projects/${e}/git-stage`,{files:s,worktreePath:i})}function JN(e,s,i){return it(`/api/projects/${e}/git-unstage`,{files:s,worktreePath:i})}function QN(e,s,i){return it(`/api/projects/${e}/git-ignore`,{path:s,worktreePath:i})}function f1(e,s,i){return it(`/api/projects/${e}/git-commit`,{message:s,worktreePath:i})}function m1(e,s,i){return it(`/api/projects/${e}/git-pull`,{remote:s,branch:i})}function cp(e,s){return it(`/api/projects/${e}/git-push`,s||{})}function ZN(e){return xt(`/api/projects/${e}/git-remotes`)}function p1(e,s,i){return it(`/api/projects/${e}/git-fetch`,{remote:s,prune:i})}function g1(e,s,i){return it(`/api/projects/${e}/git-branch`,{name:s,startPoint:i})}function pm(e,s,i){return it(`/api/projects/${e}/git-branch-delete`,{name:s,force:i})}function gm(e,s){return it(`/api/projects/${e}/git-checkout`,{branch:s})}function x1(e,s){return it(`/api/projects/${e}/git-merge`,{branch:s})}function ab(e,s,i,a){return it(`/api/projects/${e}/git-conflict-resolve`,{file:s,side:i,worktreePath:a})}function e3(e,s,i){const a=i?`&worktreePath=${encodeURIComponent(i)}`:"";return xt(`/api/projects/${e}/git-conflict-file?file=${encodeURIComponent(s)}${a}`)}function t3(e,s,i,a){return it(`/api/projects/${e}/git-conflict-file`,{file:s,content:i,worktreePath:a})}function n3(e){return it(`/api/projects/${e}/git-conflict-continue`)}function s3(e){return it(`/api/projects/${e}/git-conflict-abort`)}function r3(e,s){return it(`/api/projects/${e}/git-stash`,{message:s})}function i3(e,s){return it(`/api/projects/${e}/git-stash-pop`,{index:s})}function a3(e){return xt(`/api/projects/${e}/git-stash-list`)}function o3(e,s,i,a){return it(`/api/projects/${e}/git-discard`,{files:s,all:i,worktreePath:a})}function v1(e,s,i,a){return it(`/api/projects/${e}/git-tag`,{name:s,message:i,commit:a})}function ob(e,s,i){return it(`/api/projects/${e}/git-branch-rename`,{oldName:s,newName:i})}function l3(e,s){return it(`/api/projects/${e}/git-rebase`,{onto:s})}function c3(e,s){return it(`/api/projects/${e}/git-revert`,{commit:s})}function u3(e,s){return it(`/api/projects/${e}/git-cherry-pick`,{commit:s})}function d3(e,s,i){return it(`/api/projects/${e}/git-reset`,{commit:s,mode:i})}function h3(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 f3(e,s){const i=new URLSearchParams({hash:s});return xt(`/api/projects/${e}/git-commit-files?${i}`)}function lb(e,s,i){const a=new URLSearchParams({hash:s});return i&&a.set("file",i),xt(`/api/projects/${e}/git-commit-diff?${a}`)}function xm(e){return xt(`/api/projects/${e}/worktrees`)}function cb(e,s,i){return it(`/api/projects/${e}/worktree-cleanup`,{worktreePath:s,branchName:i})}function b1(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 m3(e={}){return xt(`/api/review/queue${b1(e)}`)}function y1(e={}){return xt(`/api/review/summary${b1(e)}`)}function p3(e){return xt(`/api/review/diff/${encodeURIComponent(e)}`)}function g3(e,s){return xt(`/api/review/diff/${encodeURIComponent(e)}/file?path=${encodeURIComponent(s)}`)}function x3(){return xt("/api/favorites")}function v3(e){return it("/api/favorites",e)}function b3(e,s){return dn(`/api/favorites/${e}`,s)}function y3(e){return Wn(`/api/favorites/${e}`)}function w3(e){return it(`/api/favorites/${e}/launch`)}function _3(e){return it("/api/favorites/browse-file",{initialPath:e})}function vm(){return xt("/api/tunnel/status")}function S3(){return xt("/api/tunnel/config")}function k3(e){return dn("/api/tunnel/config",e)}function w1(e){return it("/api/tunnel/start",{})}function C3(){return it("/api/tunnel/stop")}const _1=S.createContext({theme:"light",toggleTheme:()=>{}});function j3(){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 E3(){return S.useContext(_1)}const S1=S.createContext({enabled:!1,supported:!1,toggleNotification:()=>{},sendNotification:()=>{}});function N3(){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((m,o)=>{if(!a.current)return;const l=new Notification(m,{body:o});l.onclick=()=>{window.focus(),l.close()}},[]);return{enabled:s,supported:e,toggleNotification:u,sendNotification:f}}function up(){return S.useContext(S1)}let L3=0;const k1=S.createContext(null);function D3({children:e}){const[s,i]=S.useState([]),a=S.useRef(new Map),u=S.useRef(new Map),f=S.useRef(new Map),m=S.useCallback(b=>{i(x=>x.filter(y=>y.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}`,y=u.current.get(x);if(y)return y;const _=`toast-${++L3}`;u.current.set(x,_),f.current.set(_,x),i(E=>[...E,{id:_,message:b,type:C,duration:k}]);const w=setTimeout(()=>m(_),k);return a.current.set(_,w),_},[m]),l=S.useCallback((b,C)=>o(b,"success",C),[o]),d=S.useCallback((b,C)=>o(b,"error",C),[o]),p=S.useCallback((b,C)=>o(b,"info",C),[o]),h=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:l,error:d,info:p,warning:h,dismiss:m}),[s,o,l,d,p,h,m]);return S.createElement(k1.Provider,{value:g},e)}function Ls(){const e=S.useContext(k1);if(!e)throw new Error("useToast must be used within ToastProvider");return e}function Hs(...e){return e.filter(Boolean).join(" ")}const T3={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:m}){const o=S.useRef(null);return S.useEffect(()=>{if(!e||u)return;const l=d=>{d.key==="Escape"&&s()};return document.addEventListener("keydown",l),()=>document.removeEventListener("keydown",l)},[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:l=>{!f&&l.target===o.current&&s()},children:t.jsx("div",{className:Hs("w-full",T3[i]),children:m})}),document.body):null}const R3={default:"btn",primary:"btn-primary",secondary:"btn-secondary",danger:"btn-danger",ghost:"btn-ghost"},M3={sm:"btn-sm",md:"btn-md",lg:"btn-lg"},Bt=S.forwardRef(function({variant:s="default",size:i,type:a="button",className:u,...f},m){return t.jsx("button",{ref:m,type:a,className:Hs(R3[s],i&&M3[i],u),...f})}),C1=S.createContext(null);let ub=0;function A3({children:e}){const[s,i]=S.useState(null),a=S.useRef(null),u=S.useCallback(d=>{const p=a.current;p&&(p.kind==="confirm"?p.resolve(!1):p.resolve(null)),a.current=d,i(d)},[]),f=S.useCallback(()=>{a.current=null,i(null)},[]),m=S.useCallback(d=>{const p=typeof d=="string"?{message:d}:d;return new Promise(h=>{u({id:++ub,kind:"confirm",options:p,resolve:h})})},[u]),o=S.useCallback(d=>{const p=typeof d=="string"?{message:d}:d;return new Promise(h=>{u({id:++ub,kind:"prompt",options:p,resolve:h})})},[u]),l=S.useMemo(()=>({confirm:m,prompt:o}),[m,o]);return t.jsxs(C1.Provider,{value:l,children:[e,s&&t.jsx(z3,{dialog:s,onSettled:f},s.id)]})}function z3({dialog:e,onSettled:s}){const{t:i}=ht(),[a,u]=S.useState(e.kind==="prompt"?e.options.initialValue??"":""),f=()=>{e.kind==="confirm"?e.resolve(!1):e.resolve(null),s()},m=()=>{e.kind==="confirm"?e.resolve(!0):e.resolve(a),s()},o=e.kind==="confirm"&&!!e.options.danger,l=e.kind==="confirm"&&e.options.confirmLabel||i("common.ok"),d=e.kind==="confirm"&&e.options.cancelLabel||i("common.cancel"),p=t.jsxs("div",{className:"mt-4 flex justify-end gap-2",children:[t.jsx(Bt,{size:"sm",onClick:f,autoFocus:o,children:d}),t.jsx(Bt,{variant:o?"danger":"primary",size:"sm",type:e.kind==="prompt"?"submit":"button",onClick:e.kind==="prompt"?void 0:m,autoFocus:e.kind==="confirm"&&!o,children:l})]});return t.jsx(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:h=>{h.preventDefault(),m()},children:[t.jsx("input",{autoFocus:!0,value:a,onChange:h=>u(h.target.value),placeholder:e.options.placeholder,className:"input-field mt-3"}),p]}):p]})})}function qn(){const e=S.useContext(C1);if(!e)throw new Error("useDialog must be used within DialogProvider");return e}function j1({onSubmit:e,onCancel:s}){const[i,a]=S.useState(""),[u,f]=S.useState(""),[m,o]=S.useState(!1),[l,d]=S.useState(!1),[p,h]=S.useState(""),{t:g}=ht(),b=async k=>{if(k.preventDefault(),!(!i.trim()||!u.trim())){h(""),d(!0);try{await e(i.trim(),u.trim())}catch(x){const y=x instanceof Error?x.message:String(x);h(y||g("form.createError"))}finally{d(!1)}}},C=async()=>{o(!0);try{const k=await FN(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:m,className:"btn-ghost text-sm px-3 shrink-0",title:g("browse.title"),children:m?t.jsx(hi,{size:16,className:"animate-spin"}):t.jsx($u,{size:16})})]})]}),p&&t.jsx("p",{className:"text-sm mb-4",style:{color:"var(--color-danger, #ef4444)"},children:p}),t.jsxs("div",{className:"flex justify-end gap-3",children:[t.jsx("button",{type:"button",onClick:s,className:"btn-ghost text-sm",children:g("form.cancel")}),t.jsx("button",{type:"submit",disabled:!i.trim()||!u.trim()||l,className:"btn-primary text-sm",children:g(l?"form.creating":"form.create")})]})]})]})})}const O3=[{value:"executable",icon:ip},{value:"command",icon:gi},{value:"url",icon:fl}];function B3(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 db(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 P3({initial:e,onSubmit:s,onCancel:i}){const{t:a}=ht(),[u,f]=S.useState((e==null?void 0:e.name)??""),[m,o]=S.useState((e==null?void 0:e.type)??"executable"),[l,d]=S.useState((e==null?void 0:e.target)??""),[p,h]=S.useState(db((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"),d((e==null?void 0:e.target)??""),h(db((e==null?void 0:e.args)??null)),b((e==null?void 0:e.cwd)??"")},[e]);const[x,y]=S.useState(!1),_=m==="executable",w=async()=>{y(!0);try{const{path:B}=await _3(l||void 0);if(!B)return;if(d(B),!u.trim()){const O=B.replace(/\\/g,"/").split("/").pop()||"";f(O.replace(/\.[^.]+$/,""))}}catch{}finally{y(!1)}},E=!!e,T=u.trim(),j=l.trim(),D=m!=="url"||/^https?:\/\//i.test(j),N=!!T&&!!j&&D&&!C,R=async B=>{if(B.preventDefault(),!!N){k(!0);try{const O={name:T,type:m,target:j,args:m==="executable"&&p.trim()?B3(p.trim()):null,cwd:m!=="url"&&g.trim()?g.trim():null};await s(O)}finally{k(!1)}}},A=a(m==="executable"?"favorites.form.targetHint.executable":m==="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:R,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:O3.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:m===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:l,onChange:B=>d(B.target.value),className:"input-field text-sm font-mono flex-1",placeholder:A}),_&&t.jsxs("button",{type:"button",onClick:w,disabled:x,className:"btn-ghost text-sm whitespace-nowrap flex items-center gap-1.5 disabled:opacity-50",children:[t.jsx($u,{size:14}),a("favorites.form.browse")]})]}),t.jsx("p",{className:"mt-1 text-2xs",style:{color:"var(--color-text-muted)"},children:A})]}),m==="executable"&&t.jsxs("div",{className:"mb-5",children:[t.jsx("label",{className:"block text-sm font-medium text-warm-600 mb-2",children:a("favorites.form.args")}),t.jsx("input",{type:"text",value:p,onChange:B=>h(B.target.value),className:"input-field text-sm font-mono",placeholder:'--flag value "with spaces"'})]}),m!=="url"&&t.jsxs("div",{className:"mb-5",children:[t.jsx("label",{className:"block text-sm font-medium text-warm-600 mb-2",children:a("favorites.form.cwd")}),t.jsx("input",{type:"text",value:g,onChange: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 I3=/^([a-z0-9]([a-z0-9-]*[a-z0-9])?\.)+[a-z]{2,}$/i;function F3({onClose:e}){const{t:s}=ht(),{error:i,success:a}=Ls(),[u,f]=S.useState(""),[m,o]=S.useState(""),[l,d]=S.useState(""),[p,h]=S.useState(""),[g,b]=S.useState(!1),[C,k]=S.useState(!1),[x,y]=S.useState(!1),[_,w]=S.useState(null);S.useEffect(()=>{let O=!1;return Promise.all([S3(),vm()]).then(([F,U])=>{O||(f(F.tunnelName),o(F.customHostname),d(F.tunnelName),h(F.customHostname),w(U))}).catch(()=>{}),()=>{O=!0}},[]);const E=u.trim(),T=m.trim(),j=E!==l.trim()||T!==p.trim(),D=!!T&&(!I3.test(T)||T.toLowerCase()==="localhost"||T.toLowerCase()==="127.0.0.1"),N=!!T&&!E,R=j&&!C&&!D&&!N,A=async()=>{if(R){k(!0);try{const O=await k3({tunnelName:E,customHostname:T});d(O.tunnelName),h(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()=>{y(!0);try{try{await C3()}catch{}const O=await w1();w({status:"running",url:O.url}),a(s("tunnel.restarted"))}catch(O){i(O instanceof Error?O.message:s("tunnel.restartFailed"))}finally{y(!1)}};return t.jsxs("div",{className:"p-8",children:[t.jsx("h2",{className:"text-lg font-semibold text-warm-800 mb-1",children:s("tunnel.title")}),t.jsx("p",{className:"text-xs text-warm-400 mb-6",children:s("tunnel.description")}),_&&t.jsxs("div",{className:"mb-5 p-3 rounded-lg text-xs flex items-center gap-2",style:{backgroundColor:"var(--color-bg-hover)",color:"var(--color-text-tertiary)"},children:[t.jsx("span",{className:`w-2 h-2 rounded-full ${_.status==="running"?"bg-status-success":_.status==="error"?"bg-status-error":"bg-status-pending"}`}),t.jsx("span",{className:"font-medium",children:s(`tunnel.status.${_.status}`)}),_.url&&t.jsx("a",{href:_.url,target:"_blank",rel:"noreferrer",className:"ml-auto font-mono truncate hover:underline",style:{color:"var(--color-accent)"},children:_.url})]}),t.jsxs("div",{className:"mb-4",children:[t.jsx("label",{className:"block text-sm font-medium text-warm-600 mb-2",children:s("tunnel.name.label")}),t.jsx("input",{type:"text",value:u,onChange:O=>f(O.target.value),placeholder:s("tunnel.name.placeholder"),className:"input-field text-sm font-mono"}),t.jsx("p",{className:"mt-1 text-2xs",style:{color:"var(--color-text-muted)"},children:s("tunnel.name.hint")})]}),t.jsxs("div",{className:"mb-4",children:[t.jsx("label",{className:"block text-sm font-medium text-warm-600 mb-2",children:s("tunnel.hostname.label")}),t.jsx("input",{type:"text",value:m,onChange:O=>o(O.target.value),placeholder:s("tunnel.hostname.placeholder"),className:"input-field text-sm font-mono"}),t.jsx("p",{className:"mt-1 text-2xs",style:{color:"var(--color-text-muted)"},children:s("tunnel.hostname.hint")}),D&&t.jsx("p",{className:"mt-1 text-2xs text-status-error",children:s("tunnel.hostname.invalid")}),N&&t.jsx("p",{className:"mt-1 text-2xs text-status-error",children:s("tunnel.hostname.needsName")})]}),t.jsxs("div",{className:"mb-5",children:[t.jsxs("button",{type:"button",onClick:()=>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?(_==null?void 0:_.status)==="running"?s("tunnel.restarting"):s("tunnel.starting"):(_==null?void 0:_.status)==="running"?s("tunnel.restart"):s("tunnel.start")}),t.jsxs("div",{className:"flex gap-3",children:[e&&t.jsx("button",{type:"button",onClick:e,className:"btn-ghost text-sm",children:s("tunnel.close")}),t.jsx("button",{type:"button",onClick:A,disabled:!R,className:"btn-primary text-sm",children:s(C?"tunnel.saving":"tunnel.save")})]})]})]})}const hb=8;function H3({onClose:e}){const{t:s}=ht(),{error:i,success:a}=Ls(),[u,f]=S.useState(""),[m,o]=S.useState(""),[l,d]=S.useState(""),[p,h]=S.useState(!1),g=m.length>0&&m.length<hb,b=l.length>0&&m!==l,C=!!u&&m.length>=hb&&m===l&&!p,k=()=>{f(""),o(""),d("")},x=async()=>{if(C){h(!0);try{await Kw(u,m,l),a(s("account.saved")),k()}catch(y){i(y instanceof Error&&y.message?y.message:s("account.saveFailed"))}finally{h(!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:y=>f(y.target.value),className:"input-field text-sm",autoComplete:"current-password"})]}),t.jsxs("div",{className:"mb-4",children:[t.jsx("label",{className:"block text-sm font-medium text-warm-600 mb-2",children:s("account.newPassword")}),t.jsx("input",{type:"password",value:m,onChange:y=>o(y.target.value),className:"input-field text-sm",autoComplete:"new-password"}),g&&t.jsx("p",{className:"mt-1 text-2xs text-status-error",children:s("account.tooShort")})]}),t.jsxs("div",{className:"mb-6",children:[t.jsx("label",{className:"block text-sm font-medium text-warm-600 mb-2",children:s("account.confirm")}),t.jsx("input",{type:"password",value:l,onChange:y=>d(y.target.value),className:"input-field text-sm",autoComplete:"new-password"}),b&&t.jsx("p",{className:"mt-1 text-2xs text-status-error",children:s("account.mismatch")})]}),t.jsxs("div",{className:"flex items-center justify-end gap-3",children:[e&&t.jsx("button",{type:"button",onClick:e,className:"btn-ghost text-sm",children:s("account.close")}),t.jsx("button",{type:"button",onClick:x,disabled:!C,className:"btn-primary text-sm",children:s(p?"account.saving":"account.save")})]})]})}function dp(){return xt("/api/session-tags")}function $3(e){return it("/api/session-tags",e)}function U3(e,s){return dn(`/api/session-tags/${e}`,s)}function W3(e){return Wn(`/api/session-tags/${e}`)}function E1(){return xt("/api/session-aliases")}function N1(e){return it("/api/session-aliases",e)}function q3(e,s){return dn(`/api/session-aliases/${e}`,s)}function G3(e){return Wn(`/api/session-aliases/${e}`)}function hp(){return xt("/api/session-settings")}function xf(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",fp=13,nl=8,sl=28,Ga=new Map,Ui=new Map;let ku=fp;function mp(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);Ga.delete(s);const i=Ui.get(s);if(i){const u=rl(s);i.forEach(f=>f(u))}});function bm(e){return Number.isFinite(e)?Math.max(nl,Math.min(sl,Math.round(e))):ku}function K3(e){if(Ga.has(e))return!0;try{return localStorage.getItem(mp(e))!==null}catch{return!1}}function rl(e){const s=Ga.get(e);if(s!==void 0)return s;let i=null;try{const a=localStorage.getItem(mp(e));if(a!==null){const u=parseInt(a,10);Number.isFinite(u)&&(i=bm(u))}}catch{}return i===null?bm(ku):(Ga.set(e,i),i)}function ym(e,s){const i=bm(s);if(Ga.get(e)===i)return;Ga.set(e,i);try{localStorage.setItem(mp(e),String(i))}catch{}const a=Ui.get(e);a&&a.forEach(u=>u(i))}function Go(e,s){ym(e,rl(e)+s)}function du(e){const s=Math.max(nl,Math.min(sl,Math.round(e)));Number.isFinite(s)&&s!==ku&&(ku=s,Ui.forEach((i,a)=>{K3(a)||i.forEach(u=>u(s))}))}function L1(e){const[s,i]=S.useState(()=>rl(e));S.useEffect(()=>{i(rl(e));let f=Ui.get(e);return f||(f=new Set,Ui.set(e,f)),f.add(i),()=>{const m=Ui.get(e);m&&(m.delete(i),m.size===0&&Ui.delete(e))}},[e]);const a=S.useCallback(f=>ym(e,f),[e]),u=S.useCallback(f=>ym(e,rl(e)+f),[e]);return[s,a,u]}const il=["#A78BFA","#F472B6","#FB923C","#FBBF24","#34D399","#60A5FA","#F87171","#94A3B8"];function fb(e){for(const s of il)if(!e.some(i=>i.color.toLowerCase()===s.toLowerCase()))return s;return il[e.length%il.length]}function V3({onClose:e}){const{t:s}=ht(),{confirm:i}=qn(),{error:a,success:u}=Ls(),[f,m]=S.useState([]),[o,l]=S.useState(!1),[d,p]=S.useState(fp),[h,g]=S.useState(!1),[b,C]=S.useState(!1),[k,x]=S.useState(!1),[y,_]=S.useState(!1),w=S.useRef(null),[E,T]=S.useState(""),[j,D]=S.useState(il[0]),[N,R]=S.useState(!1),[A,B]=S.useState(null),[O,F]=S.useState(""),[U,I]=S.useState(il[0]),[H,W]=S.useState(!1),[K,P]=S.useState([]),[z,$]=S.useState(""),[Y,q]=S.useState(""),[oe,ce]=S.useState(!1),[ne,te]=S.useState(null),[G,de]=S.useState(""),[he,be]=S.useState(""),[ae,De]=S.useState(!1);S.useEffect(()=>{let J=!1;return Promise.all([dp(),hp(),E1()]).then(([ee,pe,we])=>{J||(m(ee),l(pe.defaultUseWorktree),p(pe.defaultFontSize),du(pe.defaultFontSize),g(pe.imeDebug),D(fb(ee)),P(we),C(!0))}).catch(ee=>{J||a(ee instanceof Error?ee.message:"Failed to load")}),()=>{J=!0}},[a]);const Re=E.trim(),ve=!!Re&&!N,Me=S.useMemo(()=>[...f].sort((J,ee)=>J.sort_order-ee.sort_order||J.name.localeCompare(ee.name)),[f]);S.useEffect(()=>()=>{w.current&&clearTimeout(w.current)},[]);const Oe=J=>{if(!Number.isFinite(J))return;const ee=Math.max(nl,Math.min(sl,Math.round(J)));p(ee),du(ee),w.current&&clearTimeout(w.current),w.current=setTimeout(()=>{xf({defaultFontSize:ee}).then(pe=>{p(pe.defaultFontSize),du(pe.defaultFontSize)}).catch(pe=>a(pe instanceof Error?pe.message:"Save failed"))},350)},tt=async J=>{x(!0);try{const ee=await xf({defaultUseWorktree:J});l(ee.defaultUseWorktree),u(s("sessionSettings.saved"))}catch(ee){a(ee instanceof Error?ee.message:"Save failed")}finally{x(!1)}},nt=async J=>{var ee,pe;_(!0);try{const we=await xf({imeDebug:J});g(we.imeDebug),(pe=(ee=window.electronAPI)==null?void 0:ee.imeSetDebug)==null||pe.call(ee,we.imeDebug),u(s("sessionSettings.saved"))}catch(we){a(we instanceof Error?we.message:"Save failed")}finally{_(!1)}},ke=async()=>{if(ve){R(!0);try{const J=await $3({name:Re,color:j});m(ee=>[...ee,J]),T(""),D(fb([...f,J]))}catch(J){a(J instanceof Error?J.message:"Create failed")}finally{R(!1)}}},fe=J=>{B(J.id),F(J.name),I(J.color)},Te=()=>{B(null),F("")},Ce=async()=>{if(!A)return;const J=O.trim();if(J){W(!0);try{const ee=await U3(A,{name:J,color:U});m(pe=>pe.map(we=>we.id===ee.id?ee:we)),Te()}catch(ee){a(ee instanceof Error?ee.message:"Save failed")}finally{W(!1)}}},Ke=async J=>{if(await i({message:s("sessionSettings.tags.deleteConfirm").replace("{name}",J.name),danger:!0}))try{await W3(J.id),m(ee=>ee.filter(pe=>pe.id!==J.id))}catch(ee){a(ee instanceof Error?ee.message:"Delete failed")}},Ze=z.trim(),ye=Y.trim(),Be=!!Ze&&!!ye&&!oe,Z=S.useMemo(()=>[...K].sort((J,ee)=>J.sort_order-ee.sort_order||J.name.localeCompare(ee.name)),[K]),_e=async()=>{if(Be){ce(!0);try{const J=await N1({name:Ze,command_template:ye});P(ee=>[...ee,J]),$(""),q("")}catch(J){a(J instanceof Error?J.message:"Create failed")}finally{ce(!1)}}},X=J=>{te(J.id),de(J.name),be(J.command_template)},me=()=>{te(null),de(""),be("")},se=async()=>{if(!ne)return;const J=G.trim(),ee=he.trim();if(!(!J||!ee)){De(!0);try{const pe=await q3(ne,{name:J,command_template:ee});P(we=>we.map(je=>je.id===pe.id?pe:je)),me()}catch(pe){a(pe instanceof Error?pe.message:"Save failed")}finally{De(!1)}}},ie=async J=>{if(await i({message:s("sessionSettings.aliases.deleteConfirm").replace("{name}",J.name),danger:!0}))try{await G3(J.id),P(ee=>ee.filter(pe=>pe.id!==J.id))}catch(ee){a(ee instanceof Error?ee.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(EN,{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:d,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:d,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=>D(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=>T(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(vn,{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 ee=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:ee?t.jsxs(t.Fragment,{children:[t.jsx("input",{type:"color",value:U,onChange:pe=>I(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(ir,{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(Vt,{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(mi,{size:14})}),t.jsx("button",{type:"button",onClick:()=>Ke(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=>$(J.target.value),placeholder:s("sessionSettings.aliases.namePlaceholder"),className:"input text-sm w-44",maxLength:64}),t.jsx("input",{type:"text",value:Y,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(vn,{size:14}),s("sessionSettings.aliases.add")]})]}),Z.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:Z.map(J=>{const ee=ne===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:ee?t.jsxs(t.Fragment,{children:[t.jsx("input",{type:"text",value:G,onChange:pe=>de(pe.target.value),className:"input text-sm w-44",maxLength:64}),t.jsx("input",{type:"text",value:he,onChange:pe=>be(pe.target.value),onKeyDown:pe=>{pe.key==="Enter"&&(pe.preventDefault(),se()),pe.key==="Escape"&&me()},autoFocus:!0,className:"input text-sm flex-1 font-mono",maxLength:1024}),t.jsx("button",{type:"button",onClick:se,disabled:ae||!G.trim()||!he.trim(),className:"p-1.5 text-status-success hover:bg-status-success/10 rounded-md",title:s("common.save"),children:t.jsx(ir,{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(Vt,{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(mi,{size:14})}),t.jsx("button",{type:"button",onClick:()=>ie(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(v5,{size:14}),"IME 디버그 로그"]}),t.jsxs("label",{className:"flex items-center gap-2 cursor-pointer select-none",children:[t.jsx("input",{type:"checkbox",checked:h,disabled:y||!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 Y3(){return xt("/api/mcp/connection")}function X3({onClose:e}){const{t:s}=ht(),{success:i,error:a}=Ls(),[u,f]=S.useState(null),[m,o]=S.useState(null);S.useEffect(()=>{let g=!1;return Y3().then(b=>{g||f(b)}).catch(()=>{}),()=>{g=!0}},[]);const l=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"))}},d=u?JSON.stringify(u.config,null,2):"",p=({label:g,text:b})=>t.jsxs("button",{type:"button",onClick:()=>l(g,b),className:"btn-ghost text-xs flex items-center gap-1",children:[m===g?t.jsx(ir,{size:14}):t.jsx(J5,{size:14}),s("mcp.copy")]}),h={backgroundColor:"var(--color-bg-hover)",color:"var(--color-text-secondary)"};return t.jsxs("div",{className:"p-8",children:[t.jsx("h2",{className:"text-lg font-semibold text-warm-800 mb-1",children:s("mcp.title")}),t.jsx("p",{className:"text-xs text-warm-400 mb-6",children:s("mcp.description")}),u?t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"mb-5",children:[t.jsxs("div",{className:"flex items-center justify-between mb-2",children:[t.jsx("label",{className:"block text-sm font-medium text-warm-600",children:s("mcp.config.label")}),t.jsx(p,{label:"config",text:d})]}),t.jsx("pre",{className:"p-3 rounded-lg text-2xs font-mono overflow-x-auto",style:h,children:d})]}),t.jsxs("div",{className:"mb-5",children:[t.jsx("label",{className:"block text-sm font-medium text-warm-600 mb-1",children:s("mcp.commands.label")}),t.jsx("p",{className:"text-2xs text-warm-400 mb-3",children:s("mcp.commands.hint")}),t.jsx("div",{className:"space-y-3",children:u.commands.map(g=>t.jsxs("div",{children:[t.jsxs("div",{className:"flex items-center justify-between mb-1",children:[t.jsx("span",{className:"text-xs text-warm-500",children:g.label}),t.jsx(p,{label:`command:${g.id}`,text:g.command})]}),t.jsx("pre",{className:"p-3 rounded-lg text-2xs font-mono overflow-x-auto",style:h,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 mb({open:e,onClose:s}){const{t:i}=ht(),[a,u]=S.useState("account");if(!e)return null;const f=[{id:"account",label:i("settings.tabs.account"),icon:NE},{id:"session",label:i("settings.tabs.session"),icon:ml},{id:"tunnel",label:i("settings.tabs.tunnel"),icon:n1},{id:"mcp",label:i("settings.tabs.mcp"),icon:oN}];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:m,label:o,icon:l})=>{const d=a===m;return t.jsxs("button",{type:"button",onClick:()=>u(m),className:"flex items-center gap-2 px-4 py-2.5 text-sm transition-colors text-left",style:{color:d?"var(--color-accent)":"var(--color-text-secondary)",backgroundColor:d?"var(--color-bg-primary)":"transparent",fontWeight:d?600:400},children:[t.jsx(l,{size:14}),t.jsx("span",{children:o})]},m)})}),t.jsxs("div",{className:"px-4 py-3 mt-auto text-[11px] tracking-wide",style:{color:"var(--color-text-muted)"},children:["v","0.2.57"]})]}),t.jsxs("div",{className:"flex-1 min-w-0",children:[a==="account"&&t.jsx(H3,{onClose:s}),a==="session"&&t.jsx(V3,{onClose:s}),a==="tunnel"&&t.jsx(F3,{onClose:s}),a==="mcp"&&t.jsx(X3,{onClose:s})]})]})})})}const wm=["#55708F","#4F7A68","#9A783F","#A15F5A","#74658A","#925F73","#477B7D","#747A50"];function J3(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 Ka(e){return e.color&&/^#[0-9a-f]{6}$/i.test(e.color)?e.color:wm[J3(e.id,wm.length)]}const pb=192,Q3=88,$c=8;function Z3({project:e,anchorX:s,anchorY:i,onPick:a,onClose:u}){const f=S.useRef(null),[m,o]=S.useState({left:s,top:i}),l=Ka(e);return S.useLayoutEffect(()=>{const d=Math.min(Math.max(s,$c),window.innerWidth-pb-$c),p=Math.min(Math.max(i,$c),window.innerHeight-Q3-$c);o({left:d,top:p})},[s,i]),S.useEffect(()=>{const d=h=>{var g;(g=f.current)!=null&&g.contains(h.target)||u()},p=h=>{h.key==="Escape"&&u()};return window.addEventListener("mousedown",d),window.addEventListener("keydown",p),()=>{window.removeEventListener("mousedown",d),window.removeEventListener("keydown",p)}},[u]),rn.createPortal(t.jsxs("div",{ref:f,role:"menu",className:"z-tooltip",style:{position:"fixed",left:m.left,top:m.top,width:pb,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:wm.map(d=>{const p=e.color?d.toLowerCase()===e.color.toLowerCase():d===l&&!e.color;return t.jsx("button",{onClick:()=>a(d),"aria-label":d,style:{width:20,height:20,borderRadius:6,background:d,border:p?"2px solid var(--color-text-primary)":"2px solid transparent",cursor:"pointer",padding:0}},d)})}),t.jsx("button",{onClick:()=>a(null),style:{width:"100%",background:"transparent",border:"1px solid var(--color-border)",color:"var(--color-text-tertiary)",padding:"4px 8px",borderRadius:6,fontSize:11,cursor:"pointer"},children:"자동 색 (기본값)"})]}),document.body)}function al(e,s){return e instanceof Error&&e.message.trim()?e.message:typeof e=="string"&&e.trim()?e:s}function e4(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 t4={sm:"btn-icon-sm",md:"btn-icon-md",lg:"btn-icon-lg"},n4={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:m,className:o,...l},d){return t.jsx("button",{ref:d,type:f,"aria-label":s,"aria-pressed":u,title:m??s,className:Hs("btn-icon",t4[i],n4[a],o),...l})});function s4(e){return e==="executable"?ip:e==="command"?gi:fl}function r4({onLogout:e,authRequired:s,connected:i,onEvent:a,onClose:u,collapsed:f=!1,onToggleCollapsed:m}){var Be;const[o,l]=S.useState([]),[d,p]=S.useState({}),[h,g]=S.useState(null),[b,C]=S.useState(!1),[k,x]=S.useState(null),[y,_]=S.useState([]),[w,E]=S.useState(!1),[T,j]=S.useState(null),[D,N]=S.useState(!1),[R,A]=S.useState(null),[B,O]=S.useState(!1),[F,U]=S.useState(null),[I,H]=S.useState(null),W=qs(),K=vi(),{t:P,toggleLang:z}=ht(),{theme:$,toggleTheme:Y}=E3(),{enabled:q,supported:oe,toggleNotification:ce}=up(),{error:ne,success:te,info:G,warning:de}=Ls(),{confirm:he}=qn(),be=((Be=W.pathname.match(/^\/projects\/([^/]+)/))==null?void 0:Be[1])||null;S.useEffect(()=>{nt(),De(),vm().then(A).catch(()=>{})},[]);async function ae(){if(!B){O(!0);try{const Z=await vm();if(A(Z),Z.status==="running"&&Z.url){await navigator.clipboard.writeText(Z.url),te(P("tunnel.urlCopied"));return}const _e=await w1(),X={status:"running",url:_e.url};A(X);try{await navigator.clipboard.writeText(_e.url),te(P("tunnel.urlCopied"))}catch{te(_e.url)}}catch(Z){ne(Z instanceof Error?Z.message:P("tunnel.restartFailed"))}finally{O(!1)}}}function De(){x3().then(_).catch(()=>{})}const Re=async Z=>{try{T?await b3(T.id,Z):await v3(Z),E(!1),j(null),De()}catch(_e){ne(_e instanceof Error?_e.message:"Failed to save favorite")}},ve=async Z=>{try{await w3(Z)}catch(_e){const X=_e instanceof Error?_e.message:P("favorites.launchFailed");ne(`${P("favorites.launchFailed")}: ${X}`)}},Me=async(Z,_e)=>{if(_e.preventDefault(),_e.stopPropagation(),!!await he({message:P("favorites.deleteConfirm"),danger:!0}))try{await y3(Z),_(X=>X.filter(me=>me.id!==Z))}catch(X){ne(X instanceof Error?X.message:"Failed to delete favorite")}},Oe=(Z,_e)=>{_e.preventDefault(),_e.stopPropagation(),j(Z),E(!0)};S.useEffect(()=>{const Z=()=>nt();return window.addEventListener("projects:changed",Z),()=>window.removeEventListener("projects:changed",Z)},[]),S.useEffect(()=>{const Z=()=>tt();return window.addEventListener("review:changed",Z),()=>window.removeEventListener("review:changed",Z)},[]),S.useEffect(()=>a(Z=>{var _e;if(Z.type==="project:status-changed"&&Z.projectId&&p(X=>({...X,[Z.projectId]:{running:Z.running??0,completed:Z.completed??0,total:Z.total??0,running_sessions:Z.running_sessions??0,running_discussions:Z.running_discussions??0}})),Z.type==="todo:status-changed"&&tt(),Z.type==="memory:ingest-finished"){const X=o.find(je=>je.id===Z.projectId),me=(X==null?void 0:X.name)??"",se=Z.sourceTitle?`“${Z.sourceTitle}”`:Z.sourceType??"",ie=me?`[${me}] `:"";if(Z.error){ne(`${ie}${P("wiki.ingest.toast.failed")}: ${Z.error}`,6e3);return}const J=Z.created??0,ee=Z.updated??0,pe=Z.edgesAdded??0;if(J+ee+pe>0){const je=P("wiki.ingest.toast.success").replace("{source}",se).replace("{created}",String(J)).replace("{updated}",String(ee)).replace("{edges}",String(pe));te(`${ie}${je}`)}else(_e=Z.skipped)!=null&&_e.parseFailed?de(`${ie}${P("wiki.ingest.toast.parseFailed").replace("{source}",se)}`,5e3):G(`${ie}${P("wiki.ingest.toast.empty").replace("{source}",se)}`,4e3)}}),[a,o,P,ne,G,te,de]),S.useEffect(()=>{tt()},[]);function tt(){y1({hours:24}).then(Z=>g(Z.total_todos)).catch(()=>{})}function nt(){Wu().then(Z=>{l(Z),Z.forEach(_e=>{d1(_e.id).then(X=>{p(me=>({...me,[_e.id]:X}))}).catch(()=>{})})}).catch(()=>{})}const ke=()=>{u==null||u()},fe=async(Z,_e)=>{await c1({name:Z,path:_e}),C(!1),window.dispatchEvent(new Event("projects:changed"))},Te=S.useCallback(async(Z,_e)=>{const X=o.map(je=>je.id),me=X.indexOf(Z);if(me<0)return;const se=X.filter(je=>je!==Z),ie=_e>me?_e-1:_e;if(ie===me)return;const J=[...se.slice(0,ie),Z,...se.slice(ie)],ee=o,pe=new Map(o.map(je=>[je.id,je])),we=J.map(je=>pe.get(je)).filter(Boolean);l(we);try{await qN(J)}catch(je){l(ee),ne(je instanceof Error?je.message:"Failed to reorder projects")}},[o,ne]),Ce=S.useRef(!1),Ke=S.useCallback((Z,_e)=>{if(_e.button!==0||_e.target.closest("button"))return;_e.preventDefault();const me=_e.clientX,se=_e.clientY,ie=6;let J=!1,ee=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-se)<ie)return;J=!0,U(Z)}const Ee=pe(qe.clientY);Ee!==ee&&(ee=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=ee;U(null),H(null),qe!==null&&Te(Z,qe)},Je=qe=>{qe.key==="Escape"&&(je(),U(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(Z,_e)=>{if(_e.preventDefault(),_e.stopPropagation(),!!await he({message:P("projects.deleteConfirm"),danger:!0}))try{await u1(Z),l(X=>X.filter(me=>me.id!==Z)),window.dispatchEvent(new Event("projects:changed")),be===String(Z)&&K("/")}catch(X){ne(al(X,P("errors.projectDelete")))}},ye=Z=>t.jsx("div",{className:"pointer-events-none absolute left-2 right-2 h-0.5 rounded-full",style:{backgroundColor:"var(--color-accent)",zIndex:10,...Z==="above"?{top:-1}:{bottom:-1}}});if(f){const Z=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:m,label:P("sidebar.expand"),size:"lg",children:t.jsx(l1,{size:16})}),Z,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:P("sidebar.home"),children:t.jsx(J0,{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:P("sidebar.review"),children:[t.jsx(wu,{size:16}),h!==null&&h>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:P("sidebar.agenda"),children:t.jsx(om,{size:16})}),Z,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=d[_e.id],me=be===String(_e.id),se=X?X.running+X.running_sessions+X.running_discussions:0,ie=se>0,J=Ka(_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:ie?`${_e.name} · ${se} ${P("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] ${ie?"workspace-dot-pulse":""}`,style:{backgroundColor:J,opacity:me||ie?1:.55}})]},_e.id)})}),Z,t.jsx("span",{className:`w-1.5 h-1.5 rounded-full my-1 ${i?"bg-status-success":"bg-status-error"}`,title:i?P("detail.live"):"Disconnected"}),t.jsx(Sn,{onClick:Y,label:P($==="light"?"theme.dark":"theme.light"),size:"lg",children:$==="light"?t.jsx(Z0,{size:16}):t.jsx(tb,{size:16})}),t.jsx(Sn,{onClick:()=>N(!0),label:P("settings.title"),size:"lg",children:t.jsx(Su,{size:16})}),t.jsx(mb,{open:D,onClose:()=>N(!1)})]})}return t.jsxs("div",{className:"flex flex-col h-full bg-theme-bg-secondary border-none",onDragStart:Z=>Z.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:m,label:P("sidebar.collapse"),size:"sm",className:"hidden md:inline-flex flex-shrink-0",children:t.jsx(o1,{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(J0,{size:16}),P("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(wu,{size:16}),t.jsx("span",{className:"flex-1",children:P("sidebar.review")}),h!==null&&h>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:h})]}),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(om,{size:16}),P("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:P("sidebar.workspaces")}),t.jsx(Sn,{onClick:()=>C(!0),label:P("projects.new"),size:"sm",children:t.jsx(vn,{size:14})})]}),t.jsx("div",{className:"space-y-0.5",children:o.map((Z,_e)=>{const X=d[Z.id],me=be===String(Z.id),se=X?X.running+X.running_sessions+X.running_discussions:0,ie=se>0,J=Ka(Z),ee=F===Z.id,pe=F!==null&&I===_e,we=F!==null&&_e===o.length-1&&I===o.length;return t.jsxs("div",{className:"relative","data-workspace-item":!0,children:[pe&&ye("above"),t.jsxs(Un,{to:`/projects/${Z.id}`,draggable:!1,onDragStart:je=>je.preventDefault(),onClick:je=>{if(Ce.current){je.preventDefault();return}ke()},onMouseDown:je=>Ke(Z.id,je),onContextMenu:je=>{je.preventDefault(),x({project:Z,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":""} ${ee?"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 ${ie?"workspace-dot-pulse":""}`,style:{backgroundColor:J,opacity:me||ie?1:.55},title:ie?`${P("sidebar.workspaces")} · ${se} ${P("detail.live")}`:Z.name}),t.jsx("span",{className:"truncate flex-1",children:Z.name}),t.jsx(Sn,{onClick:je=>Ze(Z.id,je),label:P("projects.delete"),size:"sm",variant:"danger",className:"flex-shrink-0 opacity-0 group-hover:opacity-100 focus-visible:opacity-100",children:t.jsx(Vt,{size:12})})]}),we&&ye("below")]},Z.id)})})]}),b&&t.jsx(j1,{onSubmit:(Z,_e)=>fe(Z,_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:P("sidebar.favorites")}),t.jsx(Sn,{onClick:()=>{j(null),E(!0)},label:P("favorites.add"),size:"sm",children:t.jsx(vn,{size:14})})]}),t.jsx("div",{className:"space-y-0.5 max-h-48 overflow-y-auto",children:y.map(Z=>{const _e=s4(Z.type);return t.jsxs("button",{onClick:()=>ve(Z.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:Z.target,children:[t.jsx(_e,{size:14,className:"flex-shrink-0"}),t.jsx("span",{className:"truncate flex-1 text-left",children:Z.name}),t.jsx("span",{onClick:X=>Oe(Z,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:P("favorites.edit"),children:t.jsx(dm,{size:12})}),t.jsx("span",{onClick:X=>Me(Z.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:P("favorites.delete"),children:t.jsx(Vt,{size:12})})]},Z.id)})})]}),w&&t.jsx(P3,{initial:T??void 0,onSubmit:Re,onCancel:()=>{E(!1),j(null)}}),k&&t.jsx(Z3,{project:k.project,anchorX:k.x,anchorY:k.y,onPick:async Z=>{try{const _e=await fm(k.project.id,{color:Z});l(X=>X.map(me=>me.id===_e.id?{...me,color:_e.color}:me)),window.dispatchEvent(new Event("projects:changed"))}catch(_e){ne(_e instanceof Error?_e.message:"Failed to update color")}x(null)},onClose:()=>x(null)}),t.jsx(mb,{open:D,onClose:()=>N(!1)}),t.jsx("div",{className:"px-3 pb-4 pt-2",style:{borderTop:"1px solid var(--color-border)"},children:t.jsxs("div",{className:"flex items-center gap-1 px-1",children:[t.jsx("span",{className:`w-1.5 h-1.5 rounded-full flex-shrink-0 mr-1 ${i?"bg-status-success":"bg-status-error"}`,title:i?P("detail.live"):"Disconnected"}),t.jsx(Sn,{onClick:Y,label:P($==="light"?"theme.dark":"theme.light"),children:$==="light"?t.jsx(Z0,{size:16}):t.jsx(tb,{size:16})}),t.jsx(Sn,{onClick:z,label:P("lang.toggle"),className:"text-xs font-medium",children:P("lang.toggle")}),oe&&t.jsx(Sn,{onClick:ce,label:"Notification"in window&&Notification.permission==="denied"?P("notification.blocked"):P("notification.toggle"),variant:q?"active":"default",pressed:q,children:q?t.jsx(g5,{size:16}):t.jsx(m5,{size:16})}),t.jsx(Sn,{onClick:ae,disabled:B,label:P("tunnel.start"),variant:(R==null?void 0:R.status)==="running"?"active":"default",pressed:(R==null?void 0:R.status)==="running",title:(R==null?void 0:R.status)==="running"&&R.url?`${R.url} — ${P("tunnel.urlCopied")}`:P(B?"tunnel.starting":"tunnel.start"),children:t.jsx(n1,{size:16})}),t.jsx(Sn,{onClick:()=>N(!0),label:P("settings.title"),children:t.jsx(Su,{size:16})}),s&&t.jsx(Sn,{onClick:e,label:P("projects.logout"),variant:"danger",className:"ml-auto",children:t.jsx(HE,{size:16})})]})})]})}function i4({children:e,onLogout:s,authRequired:i,connected:a,onEvent:u}){const[f,m]=S.useState(!1),{t:o}=ht(),[l,d]=S.useState(()=>localStorage.getItem("sidebarCollapsed")==="1"),p=()=>{d(h=>{const g=!h;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 @@ ${B.message}
|
|
|
657
657
|
`)?"":`
|
|
658
658
|
`;await p8(e,a+m+u+`
|
|
659
659
|
`)}async function LP(e,s,i){await it(`/api/projects/${e}/vault/ignore/unhide`,{path:s,isDir:i})}function g8(e){return e<1024?`${e}B`:e<1024*1024?`${(e/1024).toFixed(1)}KB`:`${(e/1024/1024).toFixed(2)}MB`}function x8(e){const s=new Map,i=new Map;for(const u of e){const f=u.stem.toLowerCase(),m=u.title.toLowerCase(),o=s.get(f)??[];o.push(u.relativePath),s.set(f,o);const l=i.get(m)??[];l.push(u.relativePath),i.set(m,l)}const a=new Map;for(const u of e){const f=u.relativePath.includes("/")?u.relativePath.slice(0,u.relativePath.lastIndexOf("/")+1):"",m=[];for(const o of u.wikilinks){const l=o.toLowerCase(),d=s.get(l)??i.get(l)??[];if(d.length===0)continue;const p=d.length===1?d[0]:d.find(h=>h.startsWith(f))??d[0];p&&p!==u.relativePath&&!m.includes(p)&&m.push(p)}a.set(u.relativePath,m)}return a}function Ap({projectId:e,mode:s,selectedPaths:i,includeLinked:a,onChange:u}){const{t:f}=ht(),[m,o]=S.useState([]),[l,d]=S.useState(!1),[p,h]=S.useState(!1),[g,b]=S.useState(""),[C,k]=S.useState(!1),[x,y]=S.useState("");S.useEffect(()=>{let D=!1;return h8(e).then(N=>{D||(o(N.files),d(!0))}).catch(N=>{console.error("Load vault files failed",N),d(!0)}),()=>{D=!0}},[e]);const _=S.useMemo(()=>{const D=x.toLowerCase(),N=D?m.filter(A=>A.stem.toLowerCase().includes(D)||A.title.toLowerCase().includes(D)||A.relativePath.toLowerCase().includes(D)):m,R={};for(const A of N){const B=A.relativePath.includes("/")?A.relativePath.split("/").slice(0,-1).join("/"):".";R[B]||(R[B]=[]),R[B].push(A)}return R},[m,x]),w=S.useMemo(()=>x8(m),[m]),E=D=>{const N=new Set(i);if(N.has(D))N.delete(D);else if(N.add(D),a){const R=w.get(D)??[];for(const A of R)N.add(A)}u("selected",Array.from(N),a)},T=async()=>{k(!0);try{const N=await f8(e,s==="auto"?"all":s,i);b(N.block||f("vault.empty"))}catch(D){b(D instanceof Error?D.message:"Preview failed")}finally{k(!1)}},j=s!=="none"&&s!=="auto";return S.useEffect(()=>{p&&j&&T()},[p,s,i]),t.jsxs("div",{className:"rounded-lg border border-warm-200 bg-warm-50 p-3",children:[t.jsxs("div",{className:"flex items-center justify-between mb-2",children:[t.jsx("div",{className:"text-sm font-medium text-warm-800",children:f("vaultInject.title")}),j&&t.jsxs("button",{type:"button",onClick:()=>h(D=>!D),className:"inline-flex items-center gap-1 text-xs text-warm-600 hover:text-warm-800",children:[p?t.jsx(nE,{size:12}):t.jsx(um,{size:12}),f("vaultInject.previewToggle")]})]}),t.jsx("div",{className:"flex flex-wrap gap-1.5 mb-2",children:["none","auto","all","selected"].map(D=>t.jsx("button",{type:"button",onClick:()=>u(D,D==="selected"?i:[],a),className:`px-3 py-1.5 rounded-md text-xs ${s===D?"bg-warm-700 text-warm-50":"bg-warm-100 text-warm-700 hover:bg-warm-200"}`,children:f(`vaultInject.mode${D.charAt(0).toUpperCase()+D.slice(1)}`)},D))}),s==="auto"&&t.jsx("div",{className:"text-xs text-warm-500 mt-1 leading-snug",children:f("vaultInject.autoHint").replace("{count}",String(m.length))}),s==="selected"&&t.jsx("div",{className:"mt-2",children:l?m.length===0?t.jsx("div",{className:"text-xs text-warm-500 italic",children:f("vaultInject.empty")}):t.jsxs(t.Fragment,{children:[t.jsxs("label",{className:"flex items-center gap-2 text-xs text-warm-600 mb-2 cursor-pointer select-none",children:[t.jsx("input",{type:"checkbox",checked:a,onChange:D=>u(s,i,D.target.checked)}),f("vaultInject.includeLinked")]}),t.jsx("input",{value:x,onChange:D=>y(D.target.value),placeholder:f("vaultInject.searchPlaceholder"),className:"w-full px-2 py-1.5 rounded-md border border-warm-200 bg-warm-0 text-sm focus:outline-none focus:ring-2 focus:ring-warm-400 mb-2"}),t.jsx("div",{className:"max-h-56 overflow-y-auto border border-warm-200 rounded-md",children:Object.keys(_).length===0?t.jsx("div",{className:"text-xs text-warm-500 italic px-2 py-2",children:f("vaultInject.noResults")}):Object.entries(_).sort(([D],[N])=>D.localeCompare(N)).map(([D,N])=>t.jsxs("div",{children:[t.jsx("div",{className:"text-[10px] uppercase tracking-wide text-warm-500 px-2 py-1 bg-warm-100 sticky top-0 font-mono",children:D}),t.jsx("div",{className:"divide-y divide-warm-100",children:N.map(R=>{const A=(w.get(R.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(R.relativePath),onChange:()=>E(R.relativePath)}),R.kind==="html"?t.jsx(ip,{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:R.relativePath,children:R.title||R.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:R.wikilinks.join(", "),children:f("vaultInject.linkedAdded").replace("{n}",String(A))}),t.jsx("span",{className:"text-[10px] text-warm-500 font-mono shrink-0",children:g8(R.size)})]},R.relativePath)})})]},D))}),t.jsx("div",{className:"text-xs text-warm-500 mt-1.5",children:f("vaultInject.injectedCount").replace("{count}",String(i.length))})]}):t.jsx("div",{className:"text-xs text-warm-500",children:f("vaultInject.loading")})}),s==="all"&&m.length>0&&t.jsx("div",{className:"text-xs text-warm-500 mt-1",children:f("vaultInject.allCount").replace("{count}",String(m.length))}),p&&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 v8(e){if(!e)return[];try{const s=JSON.parse(e);return Array.isArray(s)?s.map(String).filter(Boolean):[]}catch{return[]}}let b8=0;function Q_({onSave:e,onCancel:s,initialTitle:i="",initialDescription:a="",initialCliTool:u,initialDependsOn:f,initialMaxTurns:m,initialUseWorktree:o=null,initialMemoryInjectMode:l="none",initialMemoryRawFilePaths:d=null,projectId:p,projectCliTool:h="claude",projectIsGitRepo:g=!1,projectUseWorktree:b=!0,existingImages:C=[],todoId:k,onDeleteImage:x,availableTodos:y=[]}){const[_,w]=S.useState(i),[E,T]=S.useState(a),[j,D]=S.useState(u||h||"claude"),[N,R]=S.useState(f??""),[A,B]=S.useState((m==null?void 0:m.toString())??""),[O,F]=S.useState(o===1?"force-on":o===0?"force-off":"inherit"),[U,I]=S.useState(l),[H,W]=S.useState(v8(d)),[K,P]=S.useState(!1),[z,$]=S.useState([]),[Y,q]=S.useState(C),oe=S.useRef(null),ce=S.useRef(null),{t:ne}=ht(),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-${++b8}`;$(fe=>[...fe,{id:ke,name:Oe.name,data:nt,preview:nt}])},tt.readAsDataURL(Oe)}},[]),G=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]),de=S.useCallback(ve=>{var Me;ve.preventDefault(),ve.stopPropagation(),(Me=ve.dataTransfer)!=null&&Me.files&&te(ve.dataTransfer.files)},[te]),he=S.useCallback(ve=>{ve.preventDefault(),ve.stopPropagation()},[]),be=ve=>{$(Me=>Me.filter(Oe=>Oe.id!==ve))},ae=ve=>{x&&x(ve),q(Me=>Me.filter(Oe=>Oe.id!==ve))},De=ve=>{if(ve.preventDefault(),!_.trim())return;const Me=A?parseInt(A,10):void 0,Oe=O==="force-on"?1:O==="force-off"?0:null;e(_.trim(),E.trim(),j,z.length>0?z:void 0,N||void 0,Me||void 0,Oe,U,[],H)},Re=Y.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:ne("todoForm.titlePlaceholder"),value:_,onChange:ve=>w(ve.target.value),className:"input-field",autoFocus:!0})}),t.jsxs("div",{className:"mb-4",children:[t.jsx("textarea",{ref:oe,placeholder:ne("todoForm.descPlaceholder"),value:E,onChange:ve=>T(ve.target.value),onPaste:G,onDrop:de,onDragOver:he,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=ce.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}),ne("todoForm.addImage")]}),t.jsx("span",{className:"text-2xs text-warm-300",children:ne("todoForm.pasteHint")})]}),t.jsx("input",{ref:ce,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:ne("todoForm.images")}),t.jsxs("span",{className:"text-2xs text-warm-400",children:["(",Re,")"]})]}),t.jsxs("div",{className:"flex flex-wrap gap-2",children:[Y.map(ve=>t.jsxs("div",{className:"relative group",children:[t.jsx("img",{src:k?Sm(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:()=>ae(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(Vt,{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:()=>be(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(Vt,{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:ne("todoForm.cliTool")}),t.jsx("select",{value:j,onChange:ve=>D(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:ne("todoForm.maxTurns")}),t.jsx("input",{type:"number",min:"1",max:"500",placeholder:ne("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:ne("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:ne("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:[ne("todoForm.worktreeInherit"),t.jsxs("span",{className:"text-2xs text-warm-400 ml-1",children:["(",ne(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:ne("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:ne("todoForm.worktreeForceOff")})]})]}),(O==="force-off"||O==="inherit"&&!b)&&t.jsx("p",{className:"text-2xs text-status-warning mt-1.5",children:ne("todoForm.worktreeMainWarning")})]}),y.length>0&&t.jsxs("div",{className:"mb-4",children:[t.jsx("label",{className:"block text-xs font-medium text-warm-500 mb-1.5",children:ne("todoForm.dependsOn")}),t.jsxs("select",{value:N,onChange:ve=>R(ve.target.value),className:"input-field text-sm",children:[t.jsx("option",{value:"",children:ne("todoForm.noDependency")}),y.map(ve=>t.jsxs("option",{value:ve.id,children:[ve.title," (",ne(`status.${ve.status}`),")"]},ve.id))]}),N&&t.jsx("p",{className:"text-2xs text-warm-400 mt-1",children:ne("todoForm.dependsOnHint")})]}),p&&t.jsx("div",{className:"mb-4",children:t.jsx(Ap,{projectId:p,mode:U,selectedPaths:H,includeLinked:K,onChange:(ve,Me,Oe)=>{I(ve),W(Me),P(Oe)}})}),t.jsxs("div",{className:"flex gap-3 justify-end",children:[t.jsx("button",{type:"button",onClick:s,className:"btn-ghost text-sm",children:ne("todoForm.cancel")}),t.jsx("button",{type:"submit",disabled:!_.trim(),className:"btn-primary text-sm",children:ne("todoForm.save")})]})]})}const en="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",zp="flex items-center gap-2 w-full px-3 py-1.5 text-xs text-status-error hover:bg-status-error/10 rounded-md transition-colors text-left disabled:opacity-30 disabled:cursor-not-allowed";function Z_(){return t.jsx("div",{className:"my-1 border-t border-warm-200"})}function xi(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 Ws({x:e,y:s,onClose:i,children:a}){const u=S.useRef(null),[f,m]=S.useState({top:s,left:e,visible:!1});return S.useLayoutEffect(()=>{const o=u.current;if(!o)return;const l=window.innerWidth,d=window.innerHeight;let p=e,h=s;p+o.offsetWidth>l-8&&(p=Math.max(8,l-8-o.offsetWidth)),h+o.offsetHeight>d-8&&(h=Math.max(8,d-8-o.offsetHeight)),p<8&&(p=8),h<8&&(h=8),m({top:h,left:p,visible:!0})},[e,s]),S.useEffect(()=>{const o=p=>{var h;(h=u.current)!=null&&h.contains(p.target)||i()},l=p=>{p.key==="Escape"&&i()},d=()=>i();return document.addEventListener("mousedown",o),document.addEventListener("keydown",l),window.addEventListener("scroll",d,!0),window.addEventListener("resize",i),()=>{document.removeEventListener("mousedown",o),document.removeEventListener("keydown",l),window.removeEventListener("scroll",d,!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 y8({children:e}){const[s,i]=S.useState(!1),[a,u]=S.useState(!1),f=S.useRef(null),m=S.useRef(null),[o,l]=S.useState({top:0,left:0}),d=S.useCallback(()=>{if(!f.current)return;const h=f.current.getBoundingClientRect(),g=window.innerWidth,b=window.innerHeight;let C=h.bottom+4;const k=m.current;if(k){const x=k.offsetWidth,y=k.offsetHeight;let _=h.right-x;_<8&&(_=8),_+x>g-8&&(_=g-8-x),C+y>b-8&&(C=h.top-y-4),l({top:C,left:_}),u(!0)}else l({top:C,left:Math.max(8,h.right-180)})},[]);S.useEffect(()=>{if(!s){u(!1);return}d();const h=requestAnimationFrame(d),g=b=>{var k,x;const C=b.target;(k=f.current)!=null&&k.contains(C)||(x=m.current)!=null&&x.contains(C)||i(!1)};return document.addEventListener("mousedown",g),window.addEventListener("scroll",d,!0),window.addEventListener("resize",d),()=>{cancelAnimationFrame(h),document.removeEventListener("mousedown",g),window.removeEventListener("scroll",d,!0),window.removeEventListener("resize",d)}},[s,d]);const p=(Array.isArray(e)?e:[e]).filter(Boolean);return p.length===0?null:t.jsxs(t.Fragment,{children:[t.jsx("button",{ref:f,onClick:()=>i(!s),className:"p-1.5 text-warm-400 hover:text-warm-600 hover:bg-theme-hover rounded-lg transition-colors",title:"More",children:t.jsx(rp,{size:14})}),s&&rn.createPortal(t.jsx("div",{ref:m,className:"fixed z-tooltip min-w-[160px] rounded-xl py-1 shadow-elevated",style:{top:o.top,left:o.left,opacity:a?1:0,backgroundColor:"var(--color-bg-card)",border:"1px solid var(--color-border)"},onClick:()=>i(!1),children:p}),document.body)]})}function w8({todo:e,allTodos:s=[],projectCliTool:i,projectIsGitRepo:a,projectUseWorktree:u,onStart:f,onStop:m,onDelete:o,onEdit:l,onMerge:d,onCleanup:p,onRetry:h,onContinue:g,onFix:b,onSchedule:C,onScheduleOnReset:k,resetsAt:x,onEvent:y,isInteractive:_,onSendInput:w,isDragSource:E,isDragging:T,isDragOver:j,isValidDropTarget:D,onDragStart:N,onDragEnd:R,onDragOverTarget:A,onDragLeaveTarget:B,onDropTarget:O,onRemoveDependency:F,debugLogging:U,showTokenUsage:I,isChainMember:H}){const[W,K]=S.useState(!1),[P,z]=S.useState(!1),[$,Y]=S.useState([]),[q,oe]=S.useState(!1),[ce,ne]=S.useState(!1),[te,G]=S.useState(null),[de,he]=S.useState(!1),[be,ae]=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,Ke]=S.useState(null),[Ze,ye]=S.useState(!1),[Be,Z]=S.useState(""),[_e,X]=S.useState(!1),[me,se]=S.useState(null),[ie,J]=S.useState(!1),[ee,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"),It=String(ge.getHours()).padStart(2,"0"),As=String(ge.getMinutes()).padStart(2,"0");return`${Ae}-${rt}-${_t}T${It}:${As}`}),[vt,Tt]=S.useState(!1),[Xe,ut]=S.useState(null),{t:Q}=ht(),{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),ft=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,Gt=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(()=>{_&&e.status==="running"&&!W&&K(!0)},[_,e.status]),S.useEffect(()=>{W&&!q&&T1(e.id).then(ge=>{Y(ge),oe(!0)}).catch(()=>{})},[W,q,e.id]),S.useEffect(()=>{W&&an&&!st&&h4(e.id).then(ge=>{Ee(ge),lt(!0)}).catch(()=>{lt(!0)})},[W,an,st,e.id]),S.useEffect(()=>y(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()};Y(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()};Y(rt=>[...rt,Ae])}}),[y,e.id]);const Pn=async()=>{try{const{files:ge}=await WN(e.project_id,e.id);ge.length>0&&window.open(`/api/projects/${e.project_id}/debug-logs/${encodeURIComponent(ge[0].name)}`,"_blank")}catch{}},bn=async()=>{if(ce){ne(!1);return}he(!0),ae(null);try{const ge=await d4(e.id);G(ge),ne(!0),K(!0)}catch(ge){ae(ge instanceof Error?ge.message:"Failed to load diff"),K(!0)}finally{he(!1)}},Xn=async()=>{Re(!0),Me(null);try{await d(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 p(e.id,ge)}catch(Ae){ke(Ae instanceof Error?Ae.message:"Cleanup failed")}finally{tt(!1)}},xs=async(ge="headless")=>{Te(!0),Ke(null),Y([]),oe(!1),G(null),ne(!1),Ee(null),lt(!1);try{await h(e.id,ge)}catch(Ae){Ke(Ae instanceof Error?Ae.message:"Retry failed")}finally{Te(!1)}},hn=async(ge="headless")=>{if(!g)return;const Ae=Be.trim();if(!Ae){se(Q("todo.continuePromptRequired"));return}X(!0),se(null);try{await g(e.id,Ae,ge),ye(!1),Z(""),Y([]),oe(!1)}catch(rt){se(rt instanceof Error?rt.message:"Continue failed")}finally{X(!1)}},Gs=async()=>{if(!(!k||!ee.trim())){je(!0),Je(null);try{await k(e.id,ee.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),It=Ae%60;return It>0?`${_t}h ${It}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",Vs=jm(Qi).supportsInteractive;if(P)return t.jsx(Q_,{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 p4(e.id,ge)},onSave:async(ge,Ae,rt,_t,It,As,Mr,Ll,Dl,Ar)=>{await l(e.id,ge,Ae,rt,It,As,Mr,Ll,Dl,Ar),_t&&_t.length>0&&await z1(e.id,_t.map(Tl=>({name:Tl.name,data:Tl.data}))),z(!1)},onCancel:()=>z(!1)});const cr=ge=>{ge.dataTransfer.setData("text/plain",e.id),ge.dataTransfer.effectAllowed="link",N==null||N(e.id)},Gn=()=>{R==null||R()},En=ge=>{!T||E||(ge.preventDefault(),ge.dataTransfer.dropEffect=D?"link":"none",A==null||A(e.id))},Zi=()=>{B==null||B(e.id)},ea=ge=>{ge.preventDefault(),!(!T||E||!D)&&(O==null||O(e.id))},le=T&&!E&&j&&D,We=T&&!E&&j&&!D;return t.jsxs("div",{className:`relative transition-opacity duration-200 ${E?"opacity-40":""}`,onDragOver:En,onDragLeave:Zi,onDrop:ea,onContextMenu:ge=>{xi(ge)||(ge.preventDefault(),ge.stopPropagation(),ut({x:ge.clientX,y:ge.clientY}))},children:[t.jsxs("div",{className:`card overflow-hidden transition-all duration-200 ${le?"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:()=>K(!W),children:[t.jsx("div",{draggable:!0,onDragStart:cr,onDragEnd:Gn,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(a1,{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(Vt,{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:jm(e.cli_tool||"claude").label}),t.jsx(IL,{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})}),ft&&t.jsx("button",{onClick:()=>m(e.id),className:"p-1.5 text-status-error/60 hover:text-status-error hover:bg-status-error/10 rounded-lg transition-colors",title:Q("todo.stop"),children:t.jsx(Gi,{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(yu,{size:14})}),Ct&&t.jsx("button",{onClick:()=>{ye(ge=>!ge),se(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(Y0,{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(pi,{size:14})}),t.jsxs(y8,{children:[ue&&Vs&&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(gi,{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(um,{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(lm,{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(qi,{size:14}),Q("todo.scheduleOnReset")]}),Ne&&t.jsxs("button",{onClick:bn,disabled:de,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")]}),U&&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(eb,{size:14}),Q("todo.viewDebugLog")]}),Gt&&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(bu,{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(mi,{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=>Z(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:()=>{ye(!1),se(null)},disabled:_e,className:"btn-ghost text-xs py-1.5",children:Q("scheduleForm.cancel")})]})]})}),ie&&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:ee,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:Gs,disabled:we||!ee.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:Sm(e.id,ge.id),target:"_blank",rel:"noopener noreferrer",children:t.jsx("img",{src:Sm(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"&&$.length>0&&(()=>{var _t;const ge=$.filter(It=>It.log_type==="error");if(ge.length===0)return null;const Ae=ge.find(It=>/exited with code (\d+)/.test(It.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(It=>t.jsxs("div",{children:[t.jsx("span",{style:{color:Ue.dim},children:new Date(It.created_at).toLocaleTimeString()})," ",t.jsx("span",{style:{color:Ue.error},children:It.message})]},It.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(qi,{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(pE,{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]})]}),I&&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,It;return rt>=5e5?(_t=Q("result.levelHeavy"),It="text-status-error"):rt>=3e5?(_t=Q("result.levelHigh"),It="text-status-warning"):rt>=1e5?(_t=Q("result.levelModerate"),It="text-status-warning"):(_t=Q("result.levelLight"),It="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 ${It}`,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:bn,disabled:de,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 ${ce?"rotate-90":""}`}),t.jsx("span",{children:Q(ce?"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]}),be&&t.jsxs("div",{className:"rounded-md bg-status-error/10 text-status-error text-xs px-3 py-2",children:[Q("todo.diffError"),": ",be]}),ce&&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(J_,{logs:$,interactive:_&&e.status==="running",todoId:e.id,onSendInput:w,embedded:!0})]})]})})]}),le&&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(h5,{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(Ws,{x:Xe.x,y:Xe.y,onClose:()=>ut(null),children:[ue&&t.jsxs("button",{onClick:()=>f(e.id,"headless"),className:en,title:Q("todo.startHeadless"),children:[t.jsx(Tr,{size:14}),Q("todo.start")]}),ue&&Vs&&t.jsxs("button",{onClick:()=>f(e.id,"interactive"),className:en,title:Q("todo.startInteractiveDesc"),children:[t.jsx(gi,{size:14}),Q("todo.startInteractive")]}),ue&&t.jsxs("button",{onClick:()=>f(e.id,"verbose"),className:en,title:Q("todo.startVerboseDesc"),children:[t.jsx(um,{size:14}),Q("todo.startVerbose")]}),ft&&t.jsxs("button",{onClick:()=>m(e.id),className:en,children:[t.jsx(Gi,{size:14}),Q("todo.stop")]}),at&&t.jsxs("button",{onClick:Xn,disabled:De,className:en,children:[t.jsx(yu,{size:14}),Q("todo.merge")]}),Ct&&t.jsxs("button",{onClick:()=>{ye(!0),se(null)},disabled:_e,className:en,children:[t.jsx(Y0,{size:14}),Q("todo.continue")]}),bt&&t.jsxs("button",{onClick:()=>xs("headless"),disabled:fe,className:en,children:[t.jsx(pi,{size:14}),Q("todo.retry")]}),Fe&&t.jsxs("button",{onClick:()=>mt(!0),className:en,title:Q("todo.scheduleDesc"),children:[t.jsx(lm,{size:14}),Q("todo.schedule")]}),Ve&&t.jsxs("button",{onClick:()=>{J(!0),Je(null)},className:en,title:Q("todo.scheduleOnResetDesc"),children:[t.jsx(qi,{size:14}),Q("todo.scheduleOnReset")]}),Ne&&t.jsxs("button",{onClick:bn,disabled:de,className:en,children:[t.jsx(tl,{size:14}),Q("todo.viewDiff")]}),U&&an&&t.jsxs("button",{onClick:Pn,className:en,children:[t.jsx(eb,{size:14}),Q("todo.viewDebugLog")]}),Gt&&t.jsxs("button",{onClick:Ds,disabled:Oe,className:en,children:[t.jsx(bu,{size:14}),Q("todo.cleanup")]}),t.jsx(Z_,{}),t.jsxs("button",{onClick:()=>z(!0),className:en,children:[t.jsx(mi,{size:14}),Q("todo.edit")]}),t.jsxs("button",{onClick:()=>o(e.id),className:zp,children:[t.jsx(An,{size:14}),Q("todo.delete")]})]})]})}const _8=S.lazy(()=>qu(()=>import("./TaskGraph-BX64vM3H.js"),__vite__mapDeps([0,1,2,3,4]))),Xc={all:null,active:["pending","running"],completed:["completed","merged"],cancelled:["stopped","failed"]};function by(e,s,i){let a=i;const u=new Set;for(;a;){if(a===s)return!0;if(u.has(a))return!1;u.add(a);const f=e.find(m=>m.id===a);a=(f==null?void 0:f.depends_on)??null}return!1}function S8({todos:e,projectId:s,projectCliTool:i,projectIsGitRepo:a,projectUseWorktree:u,onAddTodo:f,onStartAll:m,onStopAll:o,onStartTodo:l,onStopTodo:d,onDeleteTodo:p,onEditTodo:h,onMergeTodo:g,onMergeChain:b,onCleanupTodo:C,onRetryTodo:k,onContinueTodo:x,onFixTodo:y,onScheduleTodo:_,onScheduleOnResetTodo:w,resetsAt:E,onUpdateDependency:T,onUpdatePosition:j,onReorderTodos:D,onEvent:N,onSendInput:R,interactiveTodos:A,debugLogging:B,showTokenUsage:O}){var qe;const[F,U]=S.useState(!1),[I,H]=S.useState(null),[W,K]=S.useState(null),[P,z]=S.useState(null),[$,Y]=S.useState(null),[q,oe]=S.useState(()=>{try{return localStorage.getItem("todoViewMode")||"list"}catch{return"list"}}),[ce,ne]=S.useState(()=>{try{return localStorage.getItem("todoStatusFilter")||"all"}catch{return"all"}}),[te,G]=S.useState(()=>{try{return localStorage.getItem("todoStackModeEnabled")==="true"}catch{return!1}}),[de,he]=S.useState(()=>{try{return localStorage.getItem("todoStackCollapsed")==="true"}catch{return!1}}),{t:be}=ht(),ae=S.useCallback(Ee=>{oe(Ee);try{localStorage.setItem("todoViewMode",Ee)}catch{}},[]),De=S.useCallback(Ee=>{ne(Ee);try{localStorage.setItem("todoStatusFilter",Ee)}catch{}},[]),Re=S.useCallback(()=>{G(Ee=>{const st=!Ee;try{localStorage.setItem("todoStackModeEnabled",String(st))}catch{}if(!st){he(!1);try{localStorage.setItem("todoStackCollapsed","false")}catch{}}return st})},[]),ve=S.useCallback(()=>{he(Ee=>{const st=!Ee;try{localStorage.setItem("todoStackCollapsed",String(st))}catch{}return st})},[]),Me=te&&de&&q==="list",Oe=S.useMemo(()=>({all:e.length,active:e.filter(Ee=>Xc.active.includes(Ee.status)).length,completed:e.filter(Ee=>Xc.completed.includes(Ee.status)).length,cancelled:e.filter(Ee=>Xc.cancelled.includes(Ee.status)).length}),[e]),tt=S.useMemo(()=>{const Ee=Xc[ce];return Ee?e.filter(st=>Ee.includes(st.status)):e},[e,ce]),nt=(()=>{const Ee=[...tt].sort((dt,kt)=>dt.priority-kt.priority);if(ce!=="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),[Ke,Ze]=S.useState(null),ye=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),Z=S.useCallback(Ee=>{Be.current=!1,K(Ee)},[]),_e=S.useCallback(async()=>{if(!Be.current&&W&&T){const Ee=e.find(st=>st.id===W);Ee!=null&&Ee.depends_on&&await T(W,null)}K(null),z(null),Y(null)},[W,e,T]),X=S.useCallback(Ee=>{z(Ee),Y(null)},[]),me=S.useCallback(Ee=>{z(st=>st===Ee?null:st)},[]),se=S.useCallback(async Ee=>{!W||!T||W!==Ee&&(by(e,W,Ee)||(Be.current=!0,await T(W,Ee),K(null),z(null),Y(null)))},[W,e,T]),ie=S.useCallback(async Ee=>{T&&await T(Ee,null)},[T]),J=S.useCallback(Ee=>!W||W===Ee?!1:!by(e,W,Ee),[W,e]),ee=S.useCallback(Ee=>{Y(Ee),z(null)},[]),pe=S.useCallback(Ee=>{Y(st=>st===Ee?null:st)},[]),we=S.useCallback(async(Ee,st)=>{if(!W||!D)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){Y(null);return}const pt=[...yt.slice(0,mt),W,...yt.slice(mt)];Be.current=!0,await D(pt),K(null),Y(null),z(null)},[W,D]),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:m,disabled:!je,className:"btn-ghost text-sm",children:[t.jsx(Tr,{size:14}),be("header.runAll")]}),t.jsxs("button",{onClick:o,disabled:!$e,className:"btn-ghost text-sm",children:[t.jsx(Gi,{size:14}),be("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:be("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:()=>ae("list"),label:be("graph.listView"),size:"sm",children:t.jsx(_u,{size:14})}),t.jsx(Sn,{onClick:()=>ae("graph"),label:be("graph.graphView"),size:"sm",variant:"active",pressed:!0,children:t.jsx(Q0,{size:14})})]}),Je]})]}),t.jsx(S.Suspense,{fallback:null,children:t.jsx(_8,{todos:e,projectId:s,projectCliTool:i,projectIsGitRepo:a,projectUseWorktree:u,onAddTodo:f,onStartTodo:l,onStopTodo:d,onDeleteTodo:p,onEditTodo:h,onMergeTodo:g,onCleanupTodo:C,onRetryTodo:k,onContinueTodo:x,onFixTodo:y,onUpdateDependency:T,onUpdatePosition:j,onEvent:N,onSendInput:R,interactiveTodos:A,debugLogging:B,showTokenUsage:O})})]}):t.jsxs("div",{className:"min-h-[50vh]",onContextMenu:Ee=>{xi(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:be("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:()=>ae("list"),label:be("graph.listView"),size:"sm",variant:"active",pressed:!0,children:t.jsx(_u,{size:14})}),t.jsx(Sn,{onClick:()=>ae("graph"),label:be("graph.graphView"),size:"sm",children:t.jsx(Q0,{size:14})})]}),t.jsx(Sn,{onClick:Re,label:be(te?"todos.stackModeOn":"todos.stackModeOff"),size:"sm",variant:te?"active":"default",pressed:te,children:t.jsx(DE,{size:14})}),te&&!de&&q==="list"&&nt.length>0&&t.jsx(Sn,{onClick:ve,label:be("todos.collapseStack"),size:"sm",children:t.jsx(A5,{size:14})}),Je,!F&&t.jsxs("button",{onClick:()=>U(!0),className:"btn-primary text-xs py-2",children:[t.jsx(vn,{size:14}),be("todos.add")]})]})]}),F&&t.jsx("div",{className:"mb-5",children:t.jsx(Q_,{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),U(!1)},onCancel:()=>U(!1)})}),t.jsx("div",{className:"flex items-center gap-1 mb-4 bg-warm-100 rounded-lg p-0.5 w-fit",children:["all","active","completed","cancelled"].map(Ee=>{const st=ce===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:be(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?be("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:t1,title:be(ce==="all"?"todos.empty":"todos.filterEmpty"),description:ce==="all"?be("todos.emptyHint"):void 0})}):(()=>{const Ee=nt.map(({todo:lt})=>lt.id),st=lt=>{if(Me||!D)return null;const yt=W!==null&&$===lt;return t.jsx("div",{onDragEnter:mt=>{mt.preventDefault(),ee(lt)},onDragOver:mt=>{mt.preventDefault(),mt.stopPropagation(),mt.dataTransfer.dropEffect="link",ee(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:be("todo.chainComplete")}),t.jsx("span",{className:"text-2xs font-mono text-warm-400",children:be("todo.chainTasks").replace("{count}",String(ke.get(lt.id)))}),t.jsxs("div",{className:"ml-auto flex items-center gap-2",children:[Ke&&Te===null&&t.jsx("span",{className:"text-2xs text-status-error",children:Ke}),t.jsxs("button",{onClick:()=>ye(lt.id),disabled:Te===lt.id,className:"btn-secondary text-xs py-1.5 disabled:opacity-50",title:be("todo.mergeChainDesc"),children:[t.jsx(o5,{size:14}),Te===lt.id?"...":be("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(w8,{todo:lt,allTodos:e,projectCliTool:i,projectIsGitRepo:a,projectUseWorktree:u,onStart:l,onStop:d,onDelete:p,onEdit:h,onMerge:g,onCleanup:C,onRetry:k,onContinue:x,onFix:y,onSchedule:_,onScheduleOnReset:w,resetsAt:E,onEvent:N,isInteractive:A.has(lt.id),onSendInput:R,isDragSource:W===lt.id,isDragging:W!==null,isDragOver:P===lt.id,isValidDropTarget:J(lt.id),onDragStart:Z,onDragEnd:_e,onDragOverTarget:X,onDragLeaveTarget:me,onDropTarget:se,onRemoveDependency:T?ie: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&&T&&(Be.current=!0,T(W,null))},children:[t.jsx(LN,{size:20,className:"mx-auto mb-1"}),be("dnd.dropToRemoveDep")]}),I&&t.jsx(Ws,{x:I.x,y:I.y,onClose:()=>H(null),children:t.jsxs("button",{onClick:()=>U(!0),className:en,children:[t.jsx(vn,{size:14}),be("todos.add")]})})]})}const k8=[{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 C8(e){const s={mode:"daily",everyMinutes:30,hourlyMinute:0,dailyHour:9,dailyMinute:0,weeklyDays:[1,2,3,4,5],weeklyHour:9,weeklyMinute:0,monthlyDay:1,monthlyHour:9,monthlyMinute:0};if(!e)return s;const i=e.trim().split(/\s+/);if(i.length!==5)return{...s,mode:"custom"};const[a,u,f,,m]=i,o=a.match(/^\*\/(\d+)$/);if(o&&u==="*"&&f==="*"&&m==="*")return{...s,mode:"minutes",everyMinutes:parseInt(o[1])};if(/^\d+$/.test(a)&&u==="*"&&f==="*"&&m==="*")return{...s,mode:"hourly",hourlyMinute:parseInt(a)};const l=/^\d+$/.test(a)?parseInt(a):-1,d=/^\d+$/.test(u)?parseInt(u):-1;if(l<0||d<0)return{...s,mode:"custom"};if(f==="*"&&m!=="*"){const p=m.split(",").map(h=>{const g=parseInt(h);return isNaN(g)?-1:g}).filter(h=>h>=0);if(p.length>0)return{...s,mode:"weekly",weeklyDays:p,weeklyHour:d,weeklyMinute:l}}return/^\d+$/.test(f)&&m==="*"?{...s,mode:"monthly",monthlyDay:parseInt(f),monthlyHour:d,monthlyMinute:l}:f==="*"&&m==="*"?{...s,mode:"daily",dailyHour:d,dailyMinute:l}:{...s,mode:"custom"}}function yy(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 j8({value:e,onChange:s}){const{t:i}=ht(),[a,u]=S.useState(()=>C8(e)),[f,m]=S.useState(e);S.useEffect(()=>{if(a.mode==="custom")s(f);else{const b=yy(a);s(b)}},[a,f]);const o=b=>{u(C=>({...C,...b}))},l=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}})},d=[{value:"minutes",labelKey:"cron.everyMinutes"},{value:"hourly",labelKey:"cron.hourly"},{value:"daily",labelKey:"cron.daily"},{value:"weekly",labelKey:"cron.weekly"},{value:"monthly",labelKey:"cron.monthly"},{value:"custom",labelKey:"cron.custom"}],p="bg-warm-50 border border-warm-300 rounded-lg px-2 py-1.5 text-sm text-warm-800 font-mono text-center transition-all duration-200 focus:border-accent focus:outline-none focus:ring-2 focus:ring-accent/20",h=(b,C,k,x)=>t.jsxs("div",{className:"flex items-center gap-1.5",children:[t.jsx("select",{value:b,onChange:y=>k(parseInt(y.target.value)),className:`${p} w-16`,children:Array.from({length:24},(y,_)=>t.jsx("option",{value:_,children:String(_).padStart(2,"0")},_))}),t.jsx("span",{className:"text-warm-500 font-mono",children:":"}),t.jsx("select",{value:C,onChange:y=>x(parseInt(y.target.value)),className:`${p} w-16`,children:Array.from({length:12},(y,_)=>_*5).map(y=>t.jsx("option",{value:y,children:String(y).padStart(2,"0")},y))})]}),g=a.mode==="custom"?f:yy(a);return t.jsxs("div",{className:"space-y-3",children:[t.jsx("div",{className:"flex flex-wrap gap-1.5",children:d.map(b=>t.jsx("button",{type:"button",onClick:()=>o({mode:b.value}),className:`px-2.5 py-1 rounded-md text-xs font-medium transition-colors ${a.mode===b.value?"bg-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:`${p} w-20`,children:[5,10,15,20,30].map(b=>t.jsx("option",{value:b,children:b},b))}),t.jsx("span",{className:"text-sm text-warm-600",children:i("cron.minutesLabel")})]}),a.mode==="hourly"&&t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("span",{className:"text-sm text-warm-600",children:i("cron.everyHourAt")}),t.jsx("select",{value:a.hourlyMinute,onChange:b=>o({hourlyMinute:parseInt(b.target.value)}),className:`${p} w-16`,children:Array.from({length:12},(b,C)=>C*5).map(b=>t.jsx("option",{value:b,children:String(b).padStart(2,"0")},b))}),t.jsx("span",{className:"text-sm text-warm-600",children:i("cron.minutesPast")})]}),a.mode==="daily"&&t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("span",{className:"text-sm text-warm-600",children:i("cron.everyDayAt")}),h(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:k8.map(b=>t.jsx("button",{type:"button",onClick:()=>l(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")}),h(a.weeklyHour,a.weeklyMinute,b=>o({weeklyHour:b}),b=>o({weeklyMinute:b}))]})]}),a.mode==="monthly"&&t.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[t.jsx("span",{className:"text-sm text-warm-600",children:i("cron.everyMonthOn")}),t.jsx("select",{value:a.monthlyDay,onChange:b=>o({monthlyDay:parseInt(b.target.value)}),className:`${p} w-16`,children:Array.from({length:28},(b,C)=>C+1).map(b=>t.jsx("option",{value:b,children:b},b))}),t.jsx("span",{className:"text-sm text-warm-600",children:i("cron.dayAt")}),h(a.monthlyHour,a.monthlyMinute,b=>o({monthlyHour:b}),b=>o({monthlyMinute:b}))]}),a.mode==="custom"&&t.jsxs("div",{children:[t.jsx("input",{type:"text",placeholder:"*/30 * * * *",value:f,onChange:b=>m(b.target.value),className:"bg-warm-50 border border-warm-300 rounded-lg px-3 py-1.5 w-full text-sm text-warm-800 font-mono transition-all duration-200 focus:border-accent focus:outline-none focus:ring-2 focus:ring-accent/20"}),t.jsx("p",{className:"text-2xs text-warm-400 mt-1",children:i("schedule.cronHint")})]})]}),a.mode!=="custom"&&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 E8(){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 N8(e){const s=new Date(e),i=s.getFullYear(),a=String(s.getMonth()+1).padStart(2,"0"),u=String(s.getDate()).padStart(2,"0"),f=String(s.getHours()).padStart(2,"0"),m=String(s.getMinutes()).padStart(2,"0");return`${i}-${a}-${u}T${f}:${m}`}function eS({onSave:e,onCancel:s,initialTitle:i="",initialDescription:a="",initialCronExpression:u="",initialCliTool:f,initialSkipIfRunning:m=!0,initialScheduleType:o="recurring",initialRunAt:l,projectCliTool:d="claude"}){const[p,h]=S.useState(i),[g,b]=S.useState(a),[C,k]=S.useState(u),[x,y]=S.useState(f||d||"claude"),[_,w]=S.useState(m),[E,T]=S.useState(o),[j,D]=S.useState(l?N8(l):E8()),{t:N}=ht(),R=E==="once",A=p.trim()&&(R?!!j:!!C.trim()),B=O=>{O.preventDefault(),A&&e({title:p.trim(),description:g.trim(),cronExpression:R?"":C.trim(),cliTool:x,skipIfRunning:_,scheduleType:E,runAt:R?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:p,onChange:O=>h(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:()=>T("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:()=>T("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")})]})]}),R?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=>D(O.target.value),className:"input-field text-sm font-mono",min:new Date().toISOString().slice(0,16)})]}):t.jsxs("div",{className:"mb-3",children:[t.jsx("label",{className:"block text-xs font-medium text-warm-500 mb-1.5",children:N("schedule.cronExpression")}),t.jsx(j8,{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=>y(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))})]})}),!R&&t.jsx("div",{className:"mb-4",children:t.jsxs("label",{className:"flex items-center gap-2 text-sm text-warm-600 cursor-pointer",children:[t.jsx("input",{type:"checkbox",checked:_,onChange:O=>w(O.target.checked),className:"rounded-md border-warm-300 text-accent focus:ring-accent"}),N("schedule.skipIfRunning")]})}),t.jsxs("div",{className:"flex gap-3 justify-end",children:[t.jsx("button",{type:"button",onClick:s,className:"btn-ghost text-sm",children:N("scheduleForm.cancel")}),t.jsx("button",{type:"submit",disabled:!A,className:"btn-primary text-sm",children:N("scheduleForm.save")})]})]})}function L8({schedule:e,onToggle:s,onDelete:i,onEdit:a,onTrigger:u,onMergeRun:f,onCleanupRun:m}){const[o,l]=S.useState(!1),[d,p]=S.useState(!1),[h,g]=S.useState([]),[b,C]=S.useState(!1),[k,x]=S.useState(!1),[y,_]=S.useState(null),{t:w}=ht(),E=async()=>{try{const U=await bf(e.id);g(U)}catch{}},T=async U=>{if(!(!U.todo_id||!f)){_(U.id);try{await f(U.todo_id),await E()}finally{_(null)}}},j=async U=>{if(!(!U.todo_id||!m)){_(U.id);try{await m(U.todo_id),await E()}finally{_(null)}}},D=e.schedule_type==="once",N=async()=>{if(!b)try{const U=await bf(e.id);g(U),C(!0)}catch{}},R=()=>{const U=!o;l(U),U&&N()},A=async()=>{x(!0);try{await u(e.id);const U=await bf(e.id);g(U),C(!0)}finally{x(!1)}};if(d)return t.jsx(eS,{initialTitle:e.title,initialDescription:e.description??"",initialCronExpression:D?"":e.cron_expression,initialCliTool:e.cli_tool??void 0,initialSkipIfRunning:!!e.skip_if_running,initialScheduleType:e.schedule_type,initialRunAt:e.run_at??void 0,onSave:async U=>{await a(e.id,{title:U.title,description:U.description,cron_expression:U.cronExpression||void 0,cli_tool:U.cliTool,skip_if_running:U.skipIfRunning,schedule_type:U.scheduleType,run_at:U.runAt}),p(!1)},onCancel:()=>p(!1)});const B={triggered:"bg-status-running",skipped:"bg-status-warning",completed:"bg-status-success",failed:"bg-status-error"},O={triggered:w("schedule.runTriggered"),skipped:w("schedule.runSkipped"),completed:w("schedule.runCompleted"),failed:w("schedule.runFailed")},F=U=>U?new Date(U).toLocaleString():"";return t.jsxs("div",{className:"card overflow-hidden",children:[t.jsxs("div",{className:"flex items-start gap-3 px-4 py-3.5 cursor-pointer hover:bg-warm-50 transition-colors",onClick:R,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(qi,{size:12}),D?F(e.run_at):e.cron_expression]}),t.jsx("span",{"aria-hidden":"true",children:"·"}),t.jsx("span",{children:w(D?"schedule.once":"schedule.recurring")}),t.jsx("span",{"aria-hidden":"true",children:"·"}),t.jsxs("span",{className:"inline-flex items-center gap-1.5 text-warm-500",children:[t.jsx("span",{"aria-hidden":"true",className:`h-1.5 w-1.5 rounded-full ${e.is_active?"bg-status-success":"bg-warm-400"}`}),e.is_active?w("schedule.active"):w("schedule.paused")]})]})]}),t.jsxs("div",{className:"flex items-center gap-0.5 ml-2",onClick:U=>U.stopPropagation(),children:[t.jsx("button",{onClick: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:w("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?w("schedule.pause"):w("schedule.activate"),children:e.is_active?t.jsx(op,{size:14}):t.jsx(ir,{size:14})}),t.jsx("button",{onClick:()=>p(!0),className:"p-1.5 text-warm-400 hover:text-accent hover:bg-accent/10 rounded-lg transition-colors",title:w("schedule.edit"),children:t.jsx(mi,{size:14})}),t.jsx("button",{onClick:()=>i(e.id),className:"p-1.5 text-warm-400 hover:text-status-error hover:bg-status-error/10 rounded-lg transition-colors",title:w("schedule.delete"),children:t.jsx(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:w(D?"schedule.runAtLabel":"schedule.cronExpression")}),t.jsx("span",{className:"min-w-0 truncate font-mono text-warm-600",children:D?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:w("schedule.lastRun")}),t.jsx("span",{className:"min-w-0 truncate text-warm-600",children:e.last_run_at?new Date(e.last_run_at).toLocaleString():w("schedule.never")})]}),!D&&e.skip_if_running&&t.jsxs("div",{className:"flex items-center gap-2 text-warm-500 sm:col-span-2",children:[t.jsx("span",{"aria-hidden":"true",className:"h-1.5 w-1.5 rounded-full bg-warm-400"}),w("schedule.skipIfRunning")]})]}),t.jsxs("div",{children:[t.jsx("h4",{className:"text-xs font-semibold text-warm-500 uppercase tracking-wider mb-2",children:w("schedule.runs")}),h.length===0?t.jsx("p",{className:"text-xs text-warm-400 italic",children:w("schedule.noRuns")}):t.jsx("div",{className:"max-h-48 overflow-auto space-y-1",children:h.map(U=>{const I=U.todo_id&&U.todo_status==="completed"&&!!U.todo_branch_name,H=U.todo_id&&U.todo_status!=="running"&&U.todo_status!=="pending"&&(U.todo_worktree_path||U.todo_branch_name),W=y===U.id;return t.jsxs("div",{className:"flex items-center gap-3 text-xs py-1.5 px-3 rounded-lg bg-theme-hover",children:[t.jsxs("span",{className:"inline-flex items-center gap-1.5 font-medium text-warm-600",children:[t.jsx("span",{"aria-hidden":"true",className:`h-1.5 w-1.5 rounded-full ${B[U.status]||"bg-warm-400"}`}),O[U.status]||U.status]}),U.skipped_reason&&t.jsxs("span",{className:"text-warm-400",children:["(",U.skipped_reason,")"]}),t.jsxs("div",{className:"flex items-center gap-0.5 ml-auto",children:[I&&f&&t.jsx("button",{onClick:()=>T(U),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:w("todo.merge"),children:t.jsx(yu,{size:12})}),H&&m&&t.jsx("button",{onClick:()=>j(U),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:w("todo.cleanup"),children:t.jsx(An,{size:12})})]}),t.jsx("span",{className:"text-warm-400 font-mono flex-shrink-0",children:new Date(U.started_at).toLocaleString()})]},U.id)})})]})]})]})}function D8({schedules:e,projectCliTool:s,onAddSchedule:i,onToggleSchedule:a,onDeleteSchedule:u,onEditSchedule:f,onTriggerSchedule:m,onMergeRun:o,onCleanupRun:l}){const[d,p]=S.useState(!1),[h,g]=S.useState(null),{t:b}=ht();return t.jsxs("div",{className:"min-h-[50vh]",onContextMenu:C=>{xi(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")}),!d&&t.jsxs("button",{onClick:()=>p(!0),className:"btn-primary btn-sm",children:[t.jsx(vn,{size:14}),b("schedules.add")]})]}),d&&t.jsx("div",{className:"mb-5",children:t.jsx(eS,{projectCliTool:s,onSave:async C=>{await i(C),p(!1)},onCancel:()=>p(!1)})}),t.jsx("div",{className:"space-y-3",children:e.length===0?t.jsx("div",{className:"card",children:t.jsx(Yi,{icon:y5,title:b("schedules.empty"),description:b("schedules.emptyHint")})}):e.map((C,k)=>t.jsx("div",{children:t.jsx(L8,{schedule:C,onToggle:a,onDelete:u,onEdit:f,onTrigger:m,onMergeRun:o,onCleanupRun:l})},C.id))}),h&&t.jsx(Ws,{x:h.x,y:h.y,onClose:()=>g(null),children:t.jsxs("button",{type:"button",className:en,onClick:()=>p(!0),children:[t.jsx(vn,{size:14}),b("schedules.add")]})})]})}function tS(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 wy="__custom__";function T8({open:e,onClose:s,projectId:i,projectName:a,onPushed:u}){const{t:f}=ht(),[m,o]=S.useState(!1),[l,d]=S.useState(!1),[p,h]=S.useState(null),[g,b]=S.useState([]),[C,k]=S.useState("origin"),[x,y]=S.useState([]),[_,w]=S.useState([]),[E,T]=S.useState(!0),[j,D]=S.useState(!1);S.useEffect(()=>{if(!e)return;let I=!1;return o(!0),h(null),Promise.all([ZN(i),mm(i)]).then(([H,W])=>{var ce,ne;if(I)return;const K=H.remotes||[];b(K);const P=((ce=K.find(te=>te.name==="origin"))==null?void 0:ce.name)||((ne=K[0])==null?void 0:ne.name)||"origin";k(P);const z=W.branches||[],$=z.filter(te=>!te.remote),Y=`remotes/${P}/`,q=z.filter(te=>te.remote&&te.name.startsWith(Y)).map(te=>te.name.slice(Y.length)).filter(te=>te&&te!=="HEAD");w(q);const oe=new Set(q);y($.map(te=>{const G=oe.has(te.name);return{local:te.name,current:te.current,remote:te.name,customRemote:!1,setUpstream:!G,checked:te.current}}))}).catch(H=>{I||h(H instanceof Error?H.message:"Failed to load remotes")}).finally(()=>{I||o(!1)}),()=>{I=!0}},[e,i]),S.useEffect(()=>{if(!e||!C)return;let I=!1;return mm(i).then(H=>{if(I)return;const W=`remotes/${C}/`,K=(H.branches||[]).filter(P=>P.remote&&P.name.startsWith(W)).map(P=>P.name.slice(W.length)).filter(P=>P&&P!=="HEAD");w(K)}).catch(()=>{}),()=>{I=!0}},[C,i,e]);const N=x.length>0&&x.every(I=>I.checked),R=x.some(I=>I.checked),A=x.filter(I=>I.checked).length,B=S.useMemo(()=>{var I;return((I=g.find(H=>H.name===C))==null?void 0:I.url)||""},[g,C]),O=(I,H)=>{y(W=>W.map(K=>K.local===I?{...K,...H}:K))},F=()=>{const I=!N;y(H=>H.map(W=>({...W,checked:I})))},U=async()=>{h(null);const I=x.filter(W=>W.checked);if(I.length===0){h(f("git.pushDialog.errorRequireBranch"));return}const H=I.map(W=>({local:W.local,remote:(W.remote||"").trim()||W.local,setUpstream:W.setUpstream}));d(!0);try{await cp(i,{remote:C,branches:H,pushAllTags:E,force:j}),u==null||u(),s()}catch(W){h(W instanceof Error?W.message:"Push failed")}finally{d(!1)}};return t.jsx(jn,{open:e,onClose:l?()=>{}:s,size:"2xl",disableBackdropClose:!0,disableEscClose:l,children:t.jsxs("div",{className:"card p-5 space-y-4",children:[t.jsxs("h3",{className:"text-base font-semibold",style:{color:"var(--color-text-primary)"},children:["Push : ",a]}),t.jsxs("div",{className:"flex items-center gap-3",children:[t.jsx("label",{className:"text-xs font-medium text-warm-500 whitespace-nowrap",children:f("git.pushDialog.targetRemote")}),t.jsxs("select",{value:C,onChange:I=>k(I.target.value),className:"input-field text-xs py-1.5 px-3 w-auto",disabled:m||l||g.length===0,children:[g.length===0&&t.jsx("option",{value:"origin",children:"origin"}),g.map(I=>t.jsx("option",{value:I.name,children:I.name},I.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:[m&&t.jsx("tr",{children:t.jsx("td",{colSpan:4,className:"py-6 text-center text-xs text-warm-500",children:f("git.pushDialog.loading")})}),!m&&x.length===0&&t.jsx("tr",{children:t.jsx("td",{colSpan:4,className:"py-6 text-center text-xs text-warm-500",children:f("git.pushDialog.noLocalBranches")})}),x.map(I=>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:I.checked,onChange:H=>O(I.local,{checked:H.target.checked}),disabled:l,className:"cursor-pointer"})}),t.jsxs("td",{className:"py-2 px-3 font-mono text-xs",style:{color:"var(--color-text-primary)"},children:[I.local,I.current&&t.jsx("span",{className:"ml-1.5 text-[10px] text-status-warning",children:"●"})]}),t.jsx("td",{className:"py-2 px-3",children:I.customRemote?t.jsx("input",{type:"text",value:I.remote,onChange:H=>O(I.local,{remote:H.target.value}),placeholder:I.local,className:"input-field text-xs font-mono py-1 px-2 w-full",disabled:l}):t.jsxs("select",{value:_.includes(I.remote)||I.remote?I.remote:"",onChange:H=>{const W=H.target.value;W===wy?O(I.local,{customRemote:!0}):O(I.local,{remote:W})},className:"input-field text-xs font-mono py-1 px-2 w-full",disabled:l,children:[!_.includes(I.remote)&&I.remote&&t.jsxs("option",{value:I.remote,children:[I.remote," (",f("git.pushDialog.newBranch"),")"]}),_.map(H=>t.jsx("option",{value:H,children:H},H)),t.jsx("option",{value:wy,children:f("git.pushDialog.customRemote")})]})}),t.jsx("td",{className:"py-2 px-3",children:t.jsx("input",{type:"checkbox",checked:I.setUpstream,onChange:H=>O(I.local,{setUpstream:H.target.checked}),disabled:l,className:"cursor-pointer"})})]},I.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:I=>{I&&(I.indeterminate=!N&&R)},onChange:F,disabled:l||x.length===0,className:"cursor-pointer"}),f("git.pushDialog.selectAll")]}),t.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[t.jsx("input",{type:"checkbox",checked:E,onChange:I=>T(I.target.checked),disabled:l,className:"cursor-pointer"}),f("git.pushDialog.allTags")]}),t.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[t.jsx("input",{type:"checkbox",checked:j,onChange:I=>D(I.target.checked),disabled:l,className:"cursor-pointer"}),t.jsx("span",{title:f("git.pushDialog.forceHint"),children:f("git.pushDialog.force")})]})]}),p&&t.jsx("div",{className:"text-xs text-status-error font-medium",children:p}),t.jsxs("div",{className:"flex items-center justify-end gap-2 pt-1",children:[t.jsx("button",{type:"button",onClick:s,disabled:l,className:"btn-secondary btn-md",children:f("git.pushDialog.cancel")}),t.jsx("button",{type:"button",onClick:U,disabled:l||m||A===0,className:"btn-primary btn-md",children:f(l?"git.pushDialog.pushing":"git.pushDialog.submit")})]})]})})}function R8(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 Ju({files:e,loading:s,selectedFile:i,onFileClick:a,commitHash:u}){const{t:f}=ht();return t.jsxs("div",{className:"h-full flex flex-col",children:[t.jsxs("div",{className:"px-3 py-2 border-b border-warm-100 flex items-center justify-between shrink-0",children:[t.jsx("span",{className:"text-[11px] font-semibold text-warm-500 uppercase tracking-wider",children:f("git.changedFiles")}),t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsxs("span",{className:"text-2xs text-warm-400",children:[e.length," ",f("git.files")]}),u&&t.jsx("span",{className:"text-2xs font-mono text-warm-400",children:u.substring(0,7)})]})]}),s?t.jsx("div",{className:"flex-1 flex items-center justify-center",children:t.jsx("span",{className:"text-xs text-warm-400",children:f("git.loadingFiles")})}):e.length===0?t.jsx("div",{className:"flex-1 flex items-center justify-center",children:t.jsx("span",{className:"text-xs text-warm-400",children:f("git.noFilesChanged")})}):t.jsx("div",{className:"flex-1 overflow-y-auto",children:e.map(m=>{const o=R8(m.status),l=i===m.path;return t.jsxs("div",{onClick:()=>a(m.path),className:`flex items-center gap-2 px-3 py-1.5 cursor-pointer text-xs hover:bg-warm-50/50 transition-colors ${l?"bg-accent/10 border-l-2 border-accent":""}`,children:[t.jsx("span",{className:`font-mono font-bold text-2xs w-3 shrink-0 ${o.color}`,children:o.label}),t.jsxs("span",{className:"truncate flex-1 text-warm-600",title:m.path,children:[m.path.split("/").pop(),t.jsx("span",{className:"text-warm-400 ml-1 text-2xs",children:m.path.includes("/")?m.path.substring(0,m.path.lastIndexOf("/")):""})]}),t.jsxs("span",{className:"shrink-0 text-2xs text-status-success",children:["+",m.additions]}),t.jsxs("span",{className:"shrink-0 text-2xs text-status-error",children:["-",m.deletions]})]},m.path)})})]})}function eo({diff:e,loading:s,selectedFile:i,fileHeaders:a}){const{t:u}=ht(),[f,m]=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:()=>m(o=>!o),title:u("git.wrapLines")||"Wrap lines",className:`p-1 rounded-md shrink-0 hover:bg-gray-700 ${f?"text-accent":"text-gray-500"}`,children:t.jsx(SN,{size:14})})]}),t.jsx("div",{className:"flex-1 overflow-auto",children:t.jsx("div",{className:"p-3 font-mono text-xs leading-relaxed",children:e?(()=>{let o=0,l=0,d=!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(J_,{logs:$,interactive:_&&e.status==="running",todoId:e.id,onSendInput:w,embedded:!0})]})]})})]}),le&&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(h5,{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(Ws,{x:Xe.x,y:Xe.y,onClose:()=>ut(null),children:[ue&&t.jsxs("button",{onClick:()=>f(e.id,"headless"),className:en,title:Q("todo.startHeadless"),children:[t.jsx(Tr,{size:14}),Q("todo.start")]}),ue&&Vs&&t.jsxs("button",{onClick:()=>f(e.id,"interactive"),className:en,title:Q("todo.startInteractiveDesc"),children:[t.jsx(gi,{size:14}),Q("todo.startInteractive")]}),ue&&t.jsxs("button",{onClick:()=>f(e.id,"verbose"),className:en,title:Q("todo.startVerboseDesc"),children:[t.jsx(um,{size:14}),Q("todo.startVerbose")]}),ft&&t.jsxs("button",{onClick:()=>m(e.id),className:en,children:[t.jsx(Gi,{size:14}),Q("todo.stop")]}),at&&t.jsxs("button",{onClick:Xn,disabled:De,className:en,children:[t.jsx(yu,{size:14}),Q("todo.merge")]}),Ct&&t.jsxs("button",{onClick:()=>{ye(!0),se(null)},disabled:_e,className:en,children:[t.jsx(Y0,{size:14}),Q("todo.continue")]}),bt&&t.jsxs("button",{onClick:()=>xs("headless"),disabled:fe,className:en,children:[t.jsx(pi,{size:14}),Q("todo.retry")]}),Fe&&t.jsxs("button",{onClick:()=>mt(!0),className:en,title:Q("todo.scheduleDesc"),children:[t.jsx(lm,{size:14}),Q("todo.schedule")]}),Ve&&t.jsxs("button",{onClick:()=>{J(!0),Je(null)},className:en,title:Q("todo.scheduleOnResetDesc"),children:[t.jsx(qi,{size:14}),Q("todo.scheduleOnReset")]}),Ne&&t.jsxs("button",{onClick:bn,disabled:de,className:en,children:[t.jsx(tl,{size:14}),Q("todo.viewDiff")]}),U&&an&&t.jsxs("button",{onClick:Pn,className:en,children:[t.jsx(eb,{size:14}),Q("todo.viewDebugLog")]}),Gt&&t.jsxs("button",{onClick:Ds,disabled:Oe,className:en,children:[t.jsx(bu,{size:14}),Q("todo.cleanup")]}),t.jsx(Z_,{}),t.jsxs("button",{onClick:()=>z(!0),className:en,children:[t.jsx(mi,{size:14}),Q("todo.edit")]}),t.jsxs("button",{onClick:()=>o(e.id),className:zp,children:[t.jsx(An,{size:14}),Q("todo.delete")]})]})]})}const _8=S.lazy(()=>qu(()=>import("./TaskGraph-ChBjtlXm.js"),__vite__mapDeps([0,1,2,3,4]))),Xc={all:null,active:["pending","running"],completed:["completed","merged"],cancelled:["stopped","failed"]};function by(e,s,i){let a=i;const u=new Set;for(;a;){if(a===s)return!0;if(u.has(a))return!1;u.add(a);const f=e.find(m=>m.id===a);a=(f==null?void 0:f.depends_on)??null}return!1}function S8({todos:e,projectId:s,projectCliTool:i,projectIsGitRepo:a,projectUseWorktree:u,onAddTodo:f,onStartAll:m,onStopAll:o,onStartTodo:l,onStopTodo:d,onDeleteTodo:p,onEditTodo:h,onMergeTodo:g,onMergeChain:b,onCleanupTodo:C,onRetryTodo:k,onContinueTodo:x,onFixTodo:y,onScheduleTodo:_,onScheduleOnResetTodo:w,resetsAt:E,onUpdateDependency:T,onUpdatePosition:j,onReorderTodos:D,onEvent:N,onSendInput:R,interactiveTodos:A,debugLogging:B,showTokenUsage:O}){var qe;const[F,U]=S.useState(!1),[I,H]=S.useState(null),[W,K]=S.useState(null),[P,z]=S.useState(null),[$,Y]=S.useState(null),[q,oe]=S.useState(()=>{try{return localStorage.getItem("todoViewMode")||"list"}catch{return"list"}}),[ce,ne]=S.useState(()=>{try{return localStorage.getItem("todoStatusFilter")||"all"}catch{return"all"}}),[te,G]=S.useState(()=>{try{return localStorage.getItem("todoStackModeEnabled")==="true"}catch{return!1}}),[de,he]=S.useState(()=>{try{return localStorage.getItem("todoStackCollapsed")==="true"}catch{return!1}}),{t:be}=ht(),ae=S.useCallback(Ee=>{oe(Ee);try{localStorage.setItem("todoViewMode",Ee)}catch{}},[]),De=S.useCallback(Ee=>{ne(Ee);try{localStorage.setItem("todoStatusFilter",Ee)}catch{}},[]),Re=S.useCallback(()=>{G(Ee=>{const st=!Ee;try{localStorage.setItem("todoStackModeEnabled",String(st))}catch{}if(!st){he(!1);try{localStorage.setItem("todoStackCollapsed","false")}catch{}}return st})},[]),ve=S.useCallback(()=>{he(Ee=>{const st=!Ee;try{localStorage.setItem("todoStackCollapsed",String(st))}catch{}return st})},[]),Me=te&&de&&q==="list",Oe=S.useMemo(()=>({all:e.length,active:e.filter(Ee=>Xc.active.includes(Ee.status)).length,completed:e.filter(Ee=>Xc.completed.includes(Ee.status)).length,cancelled:e.filter(Ee=>Xc.cancelled.includes(Ee.status)).length}),[e]),tt=S.useMemo(()=>{const Ee=Xc[ce];return Ee?e.filter(st=>Ee.includes(st.status)):e},[e,ce]),nt=(()=>{const Ee=[...tt].sort((dt,kt)=>dt.priority-kt.priority);if(ce!=="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),[Ke,Ze]=S.useState(null),ye=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),Z=S.useCallback(Ee=>{Be.current=!1,K(Ee)},[]),_e=S.useCallback(async()=>{if(!Be.current&&W&&T){const Ee=e.find(st=>st.id===W);Ee!=null&&Ee.depends_on&&await T(W,null)}K(null),z(null),Y(null)},[W,e,T]),X=S.useCallback(Ee=>{z(Ee),Y(null)},[]),me=S.useCallback(Ee=>{z(st=>st===Ee?null:st)},[]),se=S.useCallback(async Ee=>{!W||!T||W!==Ee&&(by(e,W,Ee)||(Be.current=!0,await T(W,Ee),K(null),z(null),Y(null)))},[W,e,T]),ie=S.useCallback(async Ee=>{T&&await T(Ee,null)},[T]),J=S.useCallback(Ee=>!W||W===Ee?!1:!by(e,W,Ee),[W,e]),ee=S.useCallback(Ee=>{Y(Ee),z(null)},[]),pe=S.useCallback(Ee=>{Y(st=>st===Ee?null:st)},[]),we=S.useCallback(async(Ee,st)=>{if(!W||!D)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){Y(null);return}const pt=[...yt.slice(0,mt),W,...yt.slice(mt)];Be.current=!0,await D(pt),K(null),Y(null),z(null)},[W,D]),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:m,disabled:!je,className:"btn-ghost text-sm",children:[t.jsx(Tr,{size:14}),be("header.runAll")]}),t.jsxs("button",{onClick:o,disabled:!$e,className:"btn-ghost text-sm",children:[t.jsx(Gi,{size:14}),be("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:be("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:()=>ae("list"),label:be("graph.listView"),size:"sm",children:t.jsx(_u,{size:14})}),t.jsx(Sn,{onClick:()=>ae("graph"),label:be("graph.graphView"),size:"sm",variant:"active",pressed:!0,children:t.jsx(Q0,{size:14})})]}),Je]})]}),t.jsx(S.Suspense,{fallback:null,children:t.jsx(_8,{todos:e,projectId:s,projectCliTool:i,projectIsGitRepo:a,projectUseWorktree:u,onAddTodo:f,onStartTodo:l,onStopTodo:d,onDeleteTodo:p,onEditTodo:h,onMergeTodo:g,onCleanupTodo:C,onRetryTodo:k,onContinueTodo:x,onFixTodo:y,onUpdateDependency:T,onUpdatePosition:j,onEvent:N,onSendInput:R,interactiveTodos:A,debugLogging:B,showTokenUsage:O})})]}):t.jsxs("div",{className:"min-h-[50vh]",onContextMenu:Ee=>{xi(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:be("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:()=>ae("list"),label:be("graph.listView"),size:"sm",variant:"active",pressed:!0,children:t.jsx(_u,{size:14})}),t.jsx(Sn,{onClick:()=>ae("graph"),label:be("graph.graphView"),size:"sm",children:t.jsx(Q0,{size:14})})]}),t.jsx(Sn,{onClick:Re,label:be(te?"todos.stackModeOn":"todos.stackModeOff"),size:"sm",variant:te?"active":"default",pressed:te,children:t.jsx(DE,{size:14})}),te&&!de&&q==="list"&&nt.length>0&&t.jsx(Sn,{onClick:ve,label:be("todos.collapseStack"),size:"sm",children:t.jsx(A5,{size:14})}),Je,!F&&t.jsxs("button",{onClick:()=>U(!0),className:"btn-primary text-xs py-2",children:[t.jsx(vn,{size:14}),be("todos.add")]})]})]}),F&&t.jsx("div",{className:"mb-5",children:t.jsx(Q_,{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),U(!1)},onCancel:()=>U(!1)})}),t.jsx("div",{className:"flex items-center gap-1 mb-4 bg-warm-100 rounded-lg p-0.5 w-fit",children:["all","active","completed","cancelled"].map(Ee=>{const st=ce===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:be(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?be("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:t1,title:be(ce==="all"?"todos.empty":"todos.filterEmpty"),description:ce==="all"?be("todos.emptyHint"):void 0})}):(()=>{const Ee=nt.map(({todo:lt})=>lt.id),st=lt=>{if(Me||!D)return null;const yt=W!==null&&$===lt;return t.jsx("div",{onDragEnter:mt=>{mt.preventDefault(),ee(lt)},onDragOver:mt=>{mt.preventDefault(),mt.stopPropagation(),mt.dataTransfer.dropEffect="link",ee(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:be("todo.chainComplete")}),t.jsx("span",{className:"text-2xs font-mono text-warm-400",children:be("todo.chainTasks").replace("{count}",String(ke.get(lt.id)))}),t.jsxs("div",{className:"ml-auto flex items-center gap-2",children:[Ke&&Te===null&&t.jsx("span",{className:"text-2xs text-status-error",children:Ke}),t.jsxs("button",{onClick:()=>ye(lt.id),disabled:Te===lt.id,className:"btn-secondary text-xs py-1.5 disabled:opacity-50",title:be("todo.mergeChainDesc"),children:[t.jsx(o5,{size:14}),Te===lt.id?"...":be("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(w8,{todo:lt,allTodos:e,projectCliTool:i,projectIsGitRepo:a,projectUseWorktree:u,onStart:l,onStop:d,onDelete:p,onEdit:h,onMerge:g,onCleanup:C,onRetry:k,onContinue:x,onFix:y,onSchedule:_,onScheduleOnReset:w,resetsAt:E,onEvent:N,isInteractive:A.has(lt.id),onSendInput:R,isDragSource:W===lt.id,isDragging:W!==null,isDragOver:P===lt.id,isValidDropTarget:J(lt.id),onDragStart:Z,onDragEnd:_e,onDragOverTarget:X,onDragLeaveTarget:me,onDropTarget:se,onRemoveDependency:T?ie: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&&T&&(Be.current=!0,T(W,null))},children:[t.jsx(LN,{size:20,className:"mx-auto mb-1"}),be("dnd.dropToRemoveDep")]}),I&&t.jsx(Ws,{x:I.x,y:I.y,onClose:()=>H(null),children:t.jsxs("button",{onClick:()=>U(!0),className:en,children:[t.jsx(vn,{size:14}),be("todos.add")]})})]})}const k8=[{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 C8(e){const s={mode:"daily",everyMinutes:30,hourlyMinute:0,dailyHour:9,dailyMinute:0,weeklyDays:[1,2,3,4,5],weeklyHour:9,weeklyMinute:0,monthlyDay:1,monthlyHour:9,monthlyMinute:0};if(!e)return s;const i=e.trim().split(/\s+/);if(i.length!==5)return{...s,mode:"custom"};const[a,u,f,,m]=i,o=a.match(/^\*\/(\d+)$/);if(o&&u==="*"&&f==="*"&&m==="*")return{...s,mode:"minutes",everyMinutes:parseInt(o[1])};if(/^\d+$/.test(a)&&u==="*"&&f==="*"&&m==="*")return{...s,mode:"hourly",hourlyMinute:parseInt(a)};const l=/^\d+$/.test(a)?parseInt(a):-1,d=/^\d+$/.test(u)?parseInt(u):-1;if(l<0||d<0)return{...s,mode:"custom"};if(f==="*"&&m!=="*"){const p=m.split(",").map(h=>{const g=parseInt(h);return isNaN(g)?-1:g}).filter(h=>h>=0);if(p.length>0)return{...s,mode:"weekly",weeklyDays:p,weeklyHour:d,weeklyMinute:l}}return/^\d+$/.test(f)&&m==="*"?{...s,mode:"monthly",monthlyDay:parseInt(f),monthlyHour:d,monthlyMinute:l}:f==="*"&&m==="*"?{...s,mode:"daily",dailyHour:d,dailyMinute:l}:{...s,mode:"custom"}}function yy(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 j8({value:e,onChange:s}){const{t:i}=ht(),[a,u]=S.useState(()=>C8(e)),[f,m]=S.useState(e);S.useEffect(()=>{if(a.mode==="custom")s(f);else{const b=yy(a);s(b)}},[a,f]);const o=b=>{u(C=>({...C,...b}))},l=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}})},d=[{value:"minutes",labelKey:"cron.everyMinutes"},{value:"hourly",labelKey:"cron.hourly"},{value:"daily",labelKey:"cron.daily"},{value:"weekly",labelKey:"cron.weekly"},{value:"monthly",labelKey:"cron.monthly"},{value:"custom",labelKey:"cron.custom"}],p="bg-warm-50 border border-warm-300 rounded-lg px-2 py-1.5 text-sm text-warm-800 font-mono text-center transition-all duration-200 focus:border-accent focus:outline-none focus:ring-2 focus:ring-accent/20",h=(b,C,k,x)=>t.jsxs("div",{className:"flex items-center gap-1.5",children:[t.jsx("select",{value:b,onChange:y=>k(parseInt(y.target.value)),className:`${p} w-16`,children:Array.from({length:24},(y,_)=>t.jsx("option",{value:_,children:String(_).padStart(2,"0")},_))}),t.jsx("span",{className:"text-warm-500 font-mono",children:":"}),t.jsx("select",{value:C,onChange:y=>x(parseInt(y.target.value)),className:`${p} w-16`,children:Array.from({length:12},(y,_)=>_*5).map(y=>t.jsx("option",{value:y,children:String(y).padStart(2,"0")},y))})]}),g=a.mode==="custom"?f:yy(a);return t.jsxs("div",{className:"space-y-3",children:[t.jsx("div",{className:"flex flex-wrap gap-1.5",children:d.map(b=>t.jsx("button",{type:"button",onClick:()=>o({mode:b.value}),className:`px-2.5 py-1 rounded-md text-xs font-medium transition-colors ${a.mode===b.value?"bg-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:`${p} w-20`,children:[5,10,15,20,30].map(b=>t.jsx("option",{value:b,children:b},b))}),t.jsx("span",{className:"text-sm text-warm-600",children:i("cron.minutesLabel")})]}),a.mode==="hourly"&&t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("span",{className:"text-sm text-warm-600",children:i("cron.everyHourAt")}),t.jsx("select",{value:a.hourlyMinute,onChange:b=>o({hourlyMinute:parseInt(b.target.value)}),className:`${p} w-16`,children:Array.from({length:12},(b,C)=>C*5).map(b=>t.jsx("option",{value:b,children:String(b).padStart(2,"0")},b))}),t.jsx("span",{className:"text-sm text-warm-600",children:i("cron.minutesPast")})]}),a.mode==="daily"&&t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("span",{className:"text-sm text-warm-600",children:i("cron.everyDayAt")}),h(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:k8.map(b=>t.jsx("button",{type:"button",onClick:()=>l(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")}),h(a.weeklyHour,a.weeklyMinute,b=>o({weeklyHour:b}),b=>o({weeklyMinute:b}))]})]}),a.mode==="monthly"&&t.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[t.jsx("span",{className:"text-sm text-warm-600",children:i("cron.everyMonthOn")}),t.jsx("select",{value:a.monthlyDay,onChange:b=>o({monthlyDay:parseInt(b.target.value)}),className:`${p} w-16`,children:Array.from({length:28},(b,C)=>C+1).map(b=>t.jsx("option",{value:b,children:b},b))}),t.jsx("span",{className:"text-sm text-warm-600",children:i("cron.dayAt")}),h(a.monthlyHour,a.monthlyMinute,b=>o({monthlyHour:b}),b=>o({monthlyMinute:b}))]}),a.mode==="custom"&&t.jsxs("div",{children:[t.jsx("input",{type:"text",placeholder:"*/30 * * * *",value:f,onChange:b=>m(b.target.value),className:"bg-warm-50 border border-warm-300 rounded-lg px-3 py-1.5 w-full text-sm text-warm-800 font-mono transition-all duration-200 focus:border-accent focus:outline-none focus:ring-2 focus:ring-accent/20"}),t.jsx("p",{className:"text-2xs text-warm-400 mt-1",children:i("schedule.cronHint")})]})]}),a.mode!=="custom"&&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 E8(){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 N8(e){const s=new Date(e),i=s.getFullYear(),a=String(s.getMonth()+1).padStart(2,"0"),u=String(s.getDate()).padStart(2,"0"),f=String(s.getHours()).padStart(2,"0"),m=String(s.getMinutes()).padStart(2,"0");return`${i}-${a}-${u}T${f}:${m}`}function eS({onSave:e,onCancel:s,initialTitle:i="",initialDescription:a="",initialCronExpression:u="",initialCliTool:f,initialSkipIfRunning:m=!0,initialScheduleType:o="recurring",initialRunAt:l,projectCliTool:d="claude"}){const[p,h]=S.useState(i),[g,b]=S.useState(a),[C,k]=S.useState(u),[x,y]=S.useState(f||d||"claude"),[_,w]=S.useState(m),[E,T]=S.useState(o),[j,D]=S.useState(l?N8(l):E8()),{t:N}=ht(),R=E==="once",A=p.trim()&&(R?!!j:!!C.trim()),B=O=>{O.preventDefault(),A&&e({title:p.trim(),description:g.trim(),cronExpression:R?"":C.trim(),cliTool:x,skipIfRunning:_,scheduleType:E,runAt:R?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:p,onChange:O=>h(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:()=>T("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:()=>T("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")})]})]}),R?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=>D(O.target.value),className:"input-field text-sm font-mono",min:new Date().toISOString().slice(0,16)})]}):t.jsxs("div",{className:"mb-3",children:[t.jsx("label",{className:"block text-xs font-medium text-warm-500 mb-1.5",children:N("schedule.cronExpression")}),t.jsx(j8,{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=>y(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))})]})}),!R&&t.jsx("div",{className:"mb-4",children:t.jsxs("label",{className:"flex items-center gap-2 text-sm text-warm-600 cursor-pointer",children:[t.jsx("input",{type:"checkbox",checked:_,onChange:O=>w(O.target.checked),className:"rounded-md border-warm-300 text-accent focus:ring-accent"}),N("schedule.skipIfRunning")]})}),t.jsxs("div",{className:"flex gap-3 justify-end",children:[t.jsx("button",{type:"button",onClick:s,className:"btn-ghost text-sm",children:N("scheduleForm.cancel")}),t.jsx("button",{type:"submit",disabled:!A,className:"btn-primary text-sm",children:N("scheduleForm.save")})]})]})}function L8({schedule:e,onToggle:s,onDelete:i,onEdit:a,onTrigger:u,onMergeRun:f,onCleanupRun:m}){const[o,l]=S.useState(!1),[d,p]=S.useState(!1),[h,g]=S.useState([]),[b,C]=S.useState(!1),[k,x]=S.useState(!1),[y,_]=S.useState(null),{t:w}=ht(),E=async()=>{try{const U=await bf(e.id);g(U)}catch{}},T=async U=>{if(!(!U.todo_id||!f)){_(U.id);try{await f(U.todo_id),await E()}finally{_(null)}}},j=async U=>{if(!(!U.todo_id||!m)){_(U.id);try{await m(U.todo_id),await E()}finally{_(null)}}},D=e.schedule_type==="once",N=async()=>{if(!b)try{const U=await bf(e.id);g(U),C(!0)}catch{}},R=()=>{const U=!o;l(U),U&&N()},A=async()=>{x(!0);try{await u(e.id);const U=await bf(e.id);g(U),C(!0)}finally{x(!1)}};if(d)return t.jsx(eS,{initialTitle:e.title,initialDescription:e.description??"",initialCronExpression:D?"":e.cron_expression,initialCliTool:e.cli_tool??void 0,initialSkipIfRunning:!!e.skip_if_running,initialScheduleType:e.schedule_type,initialRunAt:e.run_at??void 0,onSave:async U=>{await a(e.id,{title:U.title,description:U.description,cron_expression:U.cronExpression||void 0,cli_tool:U.cliTool,skip_if_running:U.skipIfRunning,schedule_type:U.scheduleType,run_at:U.runAt}),p(!1)},onCancel:()=>p(!1)});const B={triggered:"bg-status-running",skipped:"bg-status-warning",completed:"bg-status-success",failed:"bg-status-error"},O={triggered:w("schedule.runTriggered"),skipped:w("schedule.runSkipped"),completed:w("schedule.runCompleted"),failed:w("schedule.runFailed")},F=U=>U?new Date(U).toLocaleString():"";return t.jsxs("div",{className:"card overflow-hidden",children:[t.jsxs("div",{className:"flex items-start gap-3 px-4 py-3.5 cursor-pointer hover:bg-warm-50 transition-colors",onClick:R,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(qi,{size:12}),D?F(e.run_at):e.cron_expression]}),t.jsx("span",{"aria-hidden":"true",children:"·"}),t.jsx("span",{children:w(D?"schedule.once":"schedule.recurring")}),t.jsx("span",{"aria-hidden":"true",children:"·"}),t.jsxs("span",{className:"inline-flex items-center gap-1.5 text-warm-500",children:[t.jsx("span",{"aria-hidden":"true",className:`h-1.5 w-1.5 rounded-full ${e.is_active?"bg-status-success":"bg-warm-400"}`}),e.is_active?w("schedule.active"):w("schedule.paused")]})]})]}),t.jsxs("div",{className:"flex items-center gap-0.5 ml-2",onClick:U=>U.stopPropagation(),children:[t.jsx("button",{onClick: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:w("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?w("schedule.pause"):w("schedule.activate"),children:e.is_active?t.jsx(op,{size:14}):t.jsx(ir,{size:14})}),t.jsx("button",{onClick:()=>p(!0),className:"p-1.5 text-warm-400 hover:text-accent hover:bg-accent/10 rounded-lg transition-colors",title:w("schedule.edit"),children:t.jsx(mi,{size:14})}),t.jsx("button",{onClick:()=>i(e.id),className:"p-1.5 text-warm-400 hover:text-status-error hover:bg-status-error/10 rounded-lg transition-colors",title:w("schedule.delete"),children:t.jsx(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:w(D?"schedule.runAtLabel":"schedule.cronExpression")}),t.jsx("span",{className:"min-w-0 truncate font-mono text-warm-600",children:D?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:w("schedule.lastRun")}),t.jsx("span",{className:"min-w-0 truncate text-warm-600",children:e.last_run_at?new Date(e.last_run_at).toLocaleString():w("schedule.never")})]}),!D&&e.skip_if_running&&t.jsxs("div",{className:"flex items-center gap-2 text-warm-500 sm:col-span-2",children:[t.jsx("span",{"aria-hidden":"true",className:"h-1.5 w-1.5 rounded-full bg-warm-400"}),w("schedule.skipIfRunning")]})]}),t.jsxs("div",{children:[t.jsx("h4",{className:"text-xs font-semibold text-warm-500 uppercase tracking-wider mb-2",children:w("schedule.runs")}),h.length===0?t.jsx("p",{className:"text-xs text-warm-400 italic",children:w("schedule.noRuns")}):t.jsx("div",{className:"max-h-48 overflow-auto space-y-1",children:h.map(U=>{const I=U.todo_id&&U.todo_status==="completed"&&!!U.todo_branch_name,H=U.todo_id&&U.todo_status!=="running"&&U.todo_status!=="pending"&&(U.todo_worktree_path||U.todo_branch_name),W=y===U.id;return t.jsxs("div",{className:"flex items-center gap-3 text-xs py-1.5 px-3 rounded-lg bg-theme-hover",children:[t.jsxs("span",{className:"inline-flex items-center gap-1.5 font-medium text-warm-600",children:[t.jsx("span",{"aria-hidden":"true",className:`h-1.5 w-1.5 rounded-full ${B[U.status]||"bg-warm-400"}`}),O[U.status]||U.status]}),U.skipped_reason&&t.jsxs("span",{className:"text-warm-400",children:["(",U.skipped_reason,")"]}),t.jsxs("div",{className:"flex items-center gap-0.5 ml-auto",children:[I&&f&&t.jsx("button",{onClick:()=>T(U),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:w("todo.merge"),children:t.jsx(yu,{size:12})}),H&&m&&t.jsx("button",{onClick:()=>j(U),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:w("todo.cleanup"),children:t.jsx(An,{size:12})})]}),t.jsx("span",{className:"text-warm-400 font-mono flex-shrink-0",children:new Date(U.started_at).toLocaleString()})]},U.id)})})]})]})]})}function D8({schedules:e,projectCliTool:s,onAddSchedule:i,onToggleSchedule:a,onDeleteSchedule:u,onEditSchedule:f,onTriggerSchedule:m,onMergeRun:o,onCleanupRun:l}){const[d,p]=S.useState(!1),[h,g]=S.useState(null),{t:b}=ht();return t.jsxs("div",{className:"min-h-[50vh]",onContextMenu:C=>{xi(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")}),!d&&t.jsxs("button",{onClick:()=>p(!0),className:"btn-primary btn-sm",children:[t.jsx(vn,{size:14}),b("schedules.add")]})]}),d&&t.jsx("div",{className:"mb-5",children:t.jsx(eS,{projectCliTool:s,onSave:async C=>{await i(C),p(!1)},onCancel:()=>p(!1)})}),t.jsx("div",{className:"space-y-3",children:e.length===0?t.jsx("div",{className:"card",children:t.jsx(Yi,{icon:y5,title:b("schedules.empty"),description:b("schedules.emptyHint")})}):e.map((C,k)=>t.jsx("div",{children:t.jsx(L8,{schedule:C,onToggle:a,onDelete:u,onEdit:f,onTrigger:m,onMergeRun:o,onCleanupRun:l})},C.id))}),h&&t.jsx(Ws,{x:h.x,y:h.y,onClose:()=>g(null),children:t.jsxs("button",{type:"button",className:en,onClick:()=>p(!0),children:[t.jsx(vn,{size:14}),b("schedules.add")]})})]})}function tS(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 wy="__custom__";function T8({open:e,onClose:s,projectId:i,projectName:a,onPushed:u}){const{t:f}=ht(),[m,o]=S.useState(!1),[l,d]=S.useState(!1),[p,h]=S.useState(null),[g,b]=S.useState([]),[C,k]=S.useState("origin"),[x,y]=S.useState([]),[_,w]=S.useState([]),[E,T]=S.useState(!0),[j,D]=S.useState(!1);S.useEffect(()=>{if(!e)return;let I=!1;return o(!0),h(null),Promise.all([ZN(i),mm(i)]).then(([H,W])=>{var ce,ne;if(I)return;const K=H.remotes||[];b(K);const P=((ce=K.find(te=>te.name==="origin"))==null?void 0:ce.name)||((ne=K[0])==null?void 0:ne.name)||"origin";k(P);const z=W.branches||[],$=z.filter(te=>!te.remote),Y=`remotes/${P}/`,q=z.filter(te=>te.remote&&te.name.startsWith(Y)).map(te=>te.name.slice(Y.length)).filter(te=>te&&te!=="HEAD");w(q);const oe=new Set(q);y($.map(te=>{const G=oe.has(te.name);return{local:te.name,current:te.current,remote:te.name,customRemote:!1,setUpstream:!G,checked:te.current}}))}).catch(H=>{I||h(H instanceof Error?H.message:"Failed to load remotes")}).finally(()=>{I||o(!1)}),()=>{I=!0}},[e,i]),S.useEffect(()=>{if(!e||!C)return;let I=!1;return mm(i).then(H=>{if(I)return;const W=`remotes/${C}/`,K=(H.branches||[]).filter(P=>P.remote&&P.name.startsWith(W)).map(P=>P.name.slice(W.length)).filter(P=>P&&P!=="HEAD");w(K)}).catch(()=>{}),()=>{I=!0}},[C,i,e]);const N=x.length>0&&x.every(I=>I.checked),R=x.some(I=>I.checked),A=x.filter(I=>I.checked).length,B=S.useMemo(()=>{var I;return((I=g.find(H=>H.name===C))==null?void 0:I.url)||""},[g,C]),O=(I,H)=>{y(W=>W.map(K=>K.local===I?{...K,...H}:K))},F=()=>{const I=!N;y(H=>H.map(W=>({...W,checked:I})))},U=async()=>{h(null);const I=x.filter(W=>W.checked);if(I.length===0){h(f("git.pushDialog.errorRequireBranch"));return}const H=I.map(W=>({local:W.local,remote:(W.remote||"").trim()||W.local,setUpstream:W.setUpstream}));d(!0);try{await cp(i,{remote:C,branches:H,pushAllTags:E,force:j}),u==null||u(),s()}catch(W){h(W instanceof Error?W.message:"Push failed")}finally{d(!1)}};return t.jsx(jn,{open:e,onClose:l?()=>{}:s,size:"2xl",disableBackdropClose:!0,disableEscClose:l,children:t.jsxs("div",{className:"card p-5 space-y-4",children:[t.jsxs("h3",{className:"text-base font-semibold",style:{color:"var(--color-text-primary)"},children:["Push : ",a]}),t.jsxs("div",{className:"flex items-center gap-3",children:[t.jsx("label",{className:"text-xs font-medium text-warm-500 whitespace-nowrap",children:f("git.pushDialog.targetRemote")}),t.jsxs("select",{value:C,onChange:I=>k(I.target.value),className:"input-field text-xs py-1.5 px-3 w-auto",disabled:m||l||g.length===0,children:[g.length===0&&t.jsx("option",{value:"origin",children:"origin"}),g.map(I=>t.jsx("option",{value:I.name,children:I.name},I.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:[m&&t.jsx("tr",{children:t.jsx("td",{colSpan:4,className:"py-6 text-center text-xs text-warm-500",children:f("git.pushDialog.loading")})}),!m&&x.length===0&&t.jsx("tr",{children:t.jsx("td",{colSpan:4,className:"py-6 text-center text-xs text-warm-500",children:f("git.pushDialog.noLocalBranches")})}),x.map(I=>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:I.checked,onChange:H=>O(I.local,{checked:H.target.checked}),disabled:l,className:"cursor-pointer"})}),t.jsxs("td",{className:"py-2 px-3 font-mono text-xs",style:{color:"var(--color-text-primary)"},children:[I.local,I.current&&t.jsx("span",{className:"ml-1.5 text-[10px] text-status-warning",children:"●"})]}),t.jsx("td",{className:"py-2 px-3",children:I.customRemote?t.jsx("input",{type:"text",value:I.remote,onChange:H=>O(I.local,{remote:H.target.value}),placeholder:I.local,className:"input-field text-xs font-mono py-1 px-2 w-full",disabled:l}):t.jsxs("select",{value:_.includes(I.remote)||I.remote?I.remote:"",onChange:H=>{const W=H.target.value;W===wy?O(I.local,{customRemote:!0}):O(I.local,{remote:W})},className:"input-field text-xs font-mono py-1 px-2 w-full",disabled:l,children:[!_.includes(I.remote)&&I.remote&&t.jsxs("option",{value:I.remote,children:[I.remote," (",f("git.pushDialog.newBranch"),")"]}),_.map(H=>t.jsx("option",{value:H,children:H},H)),t.jsx("option",{value:wy,children:f("git.pushDialog.customRemote")})]})}),t.jsx("td",{className:"py-2 px-3",children:t.jsx("input",{type:"checkbox",checked:I.setUpstream,onChange:H=>O(I.local,{setUpstream:H.target.checked}),disabled:l,className:"cursor-pointer"})})]},I.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:I=>{I&&(I.indeterminate=!N&&R)},onChange:F,disabled:l||x.length===0,className:"cursor-pointer"}),f("git.pushDialog.selectAll")]}),t.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[t.jsx("input",{type:"checkbox",checked:E,onChange:I=>T(I.target.checked),disabled:l,className:"cursor-pointer"}),f("git.pushDialog.allTags")]}),t.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[t.jsx("input",{type:"checkbox",checked:j,onChange:I=>D(I.target.checked),disabled:l,className:"cursor-pointer"}),t.jsx("span",{title:f("git.pushDialog.forceHint"),children:f("git.pushDialog.force")})]})]}),p&&t.jsx("div",{className:"text-xs text-status-error font-medium",children:p}),t.jsxs("div",{className:"flex items-center justify-end gap-2 pt-1",children:[t.jsx("button",{type:"button",onClick:s,disabled:l,className:"btn-secondary btn-md",children:f("git.pushDialog.cancel")}),t.jsx("button",{type:"button",onClick:U,disabled:l||m||A===0,className:"btn-primary btn-md",children:f(l?"git.pushDialog.pushing":"git.pushDialog.submit")})]})]})})}function R8(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 Ju({files:e,loading:s,selectedFile:i,onFileClick:a,commitHash:u}){const{t:f}=ht();return t.jsxs("div",{className:"h-full flex flex-col",children:[t.jsxs("div",{className:"px-3 py-2 border-b border-warm-100 flex items-center justify-between shrink-0",children:[t.jsx("span",{className:"text-[11px] font-semibold text-warm-500 uppercase tracking-wider",children:f("git.changedFiles")}),t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsxs("span",{className:"text-2xs text-warm-400",children:[e.length," ",f("git.files")]}),u&&t.jsx("span",{className:"text-2xs font-mono text-warm-400",children:u.substring(0,7)})]})]}),s?t.jsx("div",{className:"flex-1 flex items-center justify-center",children:t.jsx("span",{className:"text-xs text-warm-400",children:f("git.loadingFiles")})}):e.length===0?t.jsx("div",{className:"flex-1 flex items-center justify-center",children:t.jsx("span",{className:"text-xs text-warm-400",children:f("git.noFilesChanged")})}):t.jsx("div",{className:"flex-1 overflow-y-auto",children:e.map(m=>{const o=R8(m.status),l=i===m.path;return t.jsxs("div",{onClick:()=>a(m.path),className:`flex items-center gap-2 px-3 py-1.5 cursor-pointer text-xs hover:bg-warm-50/50 transition-colors ${l?"bg-accent/10 border-l-2 border-accent":""}`,children:[t.jsx("span",{className:`font-mono font-bold text-2xs w-3 shrink-0 ${o.color}`,children:o.label}),t.jsxs("span",{className:"truncate flex-1 text-warm-600",title:m.path,children:[m.path.split("/").pop(),t.jsx("span",{className:"text-warm-400 ml-1 text-2xs",children:m.path.includes("/")?m.path.substring(0,m.path.lastIndexOf("/")):""})]}),t.jsxs("span",{className:"shrink-0 text-2xs text-status-success",children:["+",m.additions]}),t.jsxs("span",{className:"shrink-0 text-2xs text-status-error",children:["-",m.deletions]})]},m.path)})})]})}function eo({diff:e,loading:s,selectedFile:i,fileHeaders:a}){const{t:u}=ht(),[f,m]=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:()=>m(o=>!o),title:u("git.wrapLines")||"Wrap lines",className:`p-1 rounded-md shrink-0 hover:bg-gray-700 ${f?"text-accent":"text-gray-500"}`,children:t.jsx(SN,{size:14})})]}),t.jsx("div",{className:"flex-1 overflow-auto",children:t.jsx("div",{className:"p-3 font-mono text-xs leading-relaxed",children:e?(()=>{let o=0,l=0,d=!1;return e.split(`
|
|
661
661
|
`).map((p,h)=>{if(a&&p.startsWith("Index: "))return d=!1,t.jsx("div",{className:"mt-3 first:mt-0 mb-1 pb-1 border-b border-gray-700 font-semibold text-gray-100",children:p.slice(7)},h);if(p.startsWith("@@")){const k=/@@ -(\d+)(?:,\d+)? \+(\d+)(?:,\d+)? @@/.exec(p);return k&&(o=parseInt(k[1],10),l=parseInt(k[2],10),d=!0),null}if(!d)return null;let g="text-gray-200",b=null,C=null;if(p.startsWith("+")&&!p.startsWith("+++"))g="text-gray-100 bg-green-500/20",C=l++;else if(p.startsWith("-")&&!p.startsWith("---"))g="text-gray-100 bg-red-500/20",b=o++;else if(p.startsWith(" "))b=o++,C=l++;else return null;return t.jsxs("div",{className:`flex items-start ${g}`,children:[t.jsx("span",{className:"select-none shrink-0 w-9 pr-2 text-right text-gray-500",children: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:p||" "})]},h)})})():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 M8(e){const s=e.split(`
|
|
662
662
|
`),i=[];let a=[];const u=()=>{a.length&&(i.push({kind:"text",lines:a}),a=[])};let f=0;for(;f<s.length;){const m=s[f];if(m.startsWith("<<<<<<<")){u();const o=m.slice(7).trim()||"HEAD";f++;const l=[];for(;f<s.length&&!s[f].startsWith("|||||||")&&!s[f].startsWith("=======");)l.push(s[f]),f++;if(f<s.length&&s[f].startsWith("|||||||"))for(f++;f<s.length&&!s[f].startsWith("=======");)f++;f<s.length&&s[f].startsWith("=======")&&f++;const d=[];for(;f<s.length&&!s[f].startsWith(">>>>>>>");)d.push(s[f]),f++;f<s.length&&s[f].startsWith(">>>>>>>")&&f++,i.push({kind:"conflict",ours:l,theirs:d,label:o})}else a.push(m),f++}return u(),i}function A8(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 z8=/^(<{7}|>{7})/m;function Pf({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 O8({projectId:e,worktreePath:s,filePath:i,onResolved:a,onError:u}){const{t:f}=ht(),[m,o]=S.useState(null),[l,d]=S.useState({}),[p,h]=S.useState(!1),[g,b]=S.useState(""),[C,k]=S.useState(!0),[x,y]=S.useState(!1),[_,w]=S.useState(!1);S.useEffect(()=>{let U=!1;return k(!0),h(!1),d({}),w(!1),e3(e,i,s).then(I=>{U||o(M8(I.content))}).catch(()=>{U||w(!0)}).finally(()=>{U||k(!1)}),()=>{U=!0}},[e,s,i]);const E=S.useMemo(()=>m?m.map((U,I)=>U.kind==="conflict"?I:-1).filter(U=>U>=0):[],[m]),T=E.filter(U=>l[U]).length,j=E.length-T,D=S.useMemo(()=>m?A8(m,l):"",[m,l]),N=p?g:D,R=z8.test(N),A=x||R||!p&&j>0,B=(U,I)=>d(H=>({...H,[U]:I})),O=()=>{b(D),h(!0)},F=async()=>{y(!0),u(null);try{await t3(e,i,N,s),a()}catch(U){u(U instanceof Error?U.message:"Failed to save resolution")}finally{y(!1)}};return t.jsxs("div",{className:"h-full flex flex-col bg-[#1A1A1A] text-gray-200",children:[t.jsxs("div",{className:"px-3 py-2 border-b border-gray-700 shrink-0 flex items-center gap-2",children:[t.jsx("span",{className:"text-xs font-mono text-gray-100 truncate flex-1",title:i,children:i}),!C&&!_&&t.jsxs(t.Fragment,{children:[t.jsx("span",{className:`text-2xs ${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:()=>p?h(!1):O(),children:f(p?"git.cr.guided":"git.cr.manual")}),t.jsx("button",{className:"text-2xs px-2 py-0.5 rounded-md bg-accent text-white disabled:opacity-40",disabled:A,onClick:F,title:R?f("git.cr.markersRemain"):void 0,children:x?"…":f("git.cr.save")})]})]}),C?t.jsx("div",{className:"flex-1 flex items-center justify-center text-xs text-gray-400",children:f("git.loadingDiff")}):_?t.jsx("div",{className:"flex-1 flex items-center justify-center text-xs text-status-error",children:f("git.cr.loadFailed")}):p?t.jsx("textarea",{className:"flex-1 w-full bg-[#1A1A1A] text-gray-100 font-mono text-xs p-3 resize-none focus:outline-none",value:g,onChange:U=>b(U.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:m.map((U,I)=>U.kind==="text"?t.jsx(Pf,{lines:U.lines,tint:"text-gray-500"},I):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(I,H),className:`text-2xs px-2 py-0.5 rounded-md border transition-colors ${l[I]===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:l[I]==="theirs"?"opacity-40":"",children:[t.jsx("div",{className:"px-3 pt-1 text-2xs text-emerald-400",children:f("git.cr.ours")}),t.jsx(Pf,{lines:U.ours,tint:"text-gray-100 bg-emerald-500/10"})]}),t.jsxs("div",{className:l[I]==="ours"?"opacity-40":"",children:[t.jsx("div",{className:"px-3 pt-1 text-2xs text-sky-400",children:f("git.cr.theirs")}),t.jsx(Pf,{lines:U.theirs,tint:"text-gray-100 bg-sky-500/10"})]})]},I))})]})}const za=["#B08A3E","#4B8DFF","#7A8797","#5E748A","#8B8178","#667085","#78909C","#9A8F7F"];function B8(e){const s=new Map;e.forEach((u,f)=>s.set(u.hash,f));const i=[],a=[];for(let u=0;u<e.length;u++){const f=e[u];let m=i.indexOf(f.hash);m===-1&&(m=i.indexOf(null),m===-1&&(m=i.length,i.push(null))),i[m]=null;const o=za[m%za.length],l=[];for(let d=0;d<f.parentHashes.length;d++){const p=f.parentHashes[d],h=s.get(p);if(h===void 0)continue;let g=i.indexOf(p);if(g!==-1)l.push({fromLane:m,toLane:g,toRow:h,color:za[g%za.length]});else if(d===0)i[m]=p,l.push({fromLane:m,toLane:m,toRow:h,color:o});else{let b=i.indexOf(null);b===-1&&(b=i.length,i.push(null)),i[b]=p,l.push({fromLane:m,toLane:b,toRow:h,color:za[b%za.length]})}}a.push({lane:m,color:o,connections:l})}return a}function P8({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,Pi=16,I8=4,F8=10;function H8({graphNodes:e,totalRows:s}){const a=(Math.min(F8,e.reduce((u,f)=>{const m=f.connections.reduce((o,l)=>Math.max(o,l.fromLane,l.toLane),0);return Math.max(u,f.lane,m)},0)+1)+1)*Pi+8;return t.jsxs("svg",{width:a,height:s*di,className:"shrink-0",style:{minWidth:a},children:[e.map((u,f)=>u.connections.map((m,o)=>{const l=m.fromLane*Pi+Pi/2+4,d=f*di+di/2,p=m.toLane*Pi+Pi/2+4,h=m.toRow*di+di/2;if(l===p)return t.jsx("line",{x1:l,y1:d,x2:p,y2:h,stroke:m.color,strokeWidth:2,strokeOpacity:.7},`${f}-${o}`);{const g=(d+h)/2;return t.jsx("path",{d:`M${l},${d} C${l},${g} ${p},${g} ${p},${h}`,fill:"none",stroke:m.color,strokeWidth:2,strokeOpacity:.7},`${f}-${o}`)}})),e.map((u,f)=>{const m=u.lane*Pi+Pi/2+4,o=f*di+di/2;return t.jsx("circle",{cx:m,cy:o,r:I8,fill:u.color,stroke:"white",strokeWidth:1.5},`dot-${f}`)})]})}function $8({projectId:e,projectName:s,onRefresh:i,busy:a,setBusy:u,branches:f,statusFiles:m,worktreePath:o}){const{t:l}=ht(),{confirm:d}=qn(),[p,h]=S.useState(null),[g,b]=S.useState(""),[C,k]=S.useState(""),[x,y]=S.useState(null),_=()=>{h(null),b(""),k(""),y(null)},w=async O=>{u(!0),y(null);try{await O(),_(),i()}catch(F){y(F instanceof Error?F.message:"Error")}finally{u(!1)}},E=m.some(O=>O.index!==" "&&O.index!=="?"),T=({label:O,onClick:F,icon:U,badge:I})=>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:U}),t.jsx("span",{className:"text-2xs text-warm-600 whitespace-nowrap",children:O}),I!==void 0&&I>0&&t.jsx("span",{className:"absolute -top-0.5 -right-0.5 bg-accent text-white text-[9px] font-bold rounded-full h-3.5 min-w-[14px] flex items-center justify-center px-0.5",children:I})]}),j=({title:O,children:F})=>t.jsx(jn,{open:!0,onClose:_,size:"sm",children:t.jsxs("div",{className:"bg-theme-card border border-theme-border rounded-2xl shadow-elevated w-80 max-w-[90vw]",children:[t.jsxs("div",{className:"flex items-center justify-between px-4 py-3 border-b border-warm-100",children:[t.jsx("span",{className:"text-sm font-semibold text-warm-700",children:O}),t.jsx("button",{onClick:_,className:"text-warm-400 hover:text-warm-600",children:t.jsx("svg",{className:"h-4 w-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M6 18L18 6M6 6l12 12"})})})]}),t.jsxs("div",{className:"p-4 space-y-3",children:[x&&t.jsx("p",{className:"text-status-error text-xs",children:x}),F]})]})}),D=f.filter(O=>!O.remote),N=f.find(O=>!O.remote&&O.current),R=m.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(T,{label:l("git.commit"),onClick:()=>h("commit"),icon:t.jsx("svg",{fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:1.5,className:"h-5 w-5",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M12 9v6m3-3H9m12 0a9 9 0 11-18 0 9 9 0 0118 0z"})}),badge:R}),t.jsx(T,{label:l("git.pull"),onClick:()=>w(()=>m1(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(T,{label:l("git.push"),onClick:()=>h("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(T,{label:l("git.fetch"),onClick:()=>w(()=>p1(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(T,{label:l("git.branch"),onClick:()=>h("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(T,{label:l("git.merge"),onClick:()=>h("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(T,{label:l("git.stash"),onClick:()=>h("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(T,{label:l("git.discard"),onClick:async()=>{m.length!==0&&await d({message:l("git.confirmDiscard"),danger:!0})&&w(()=>o3(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(T,{label:l("git.tag"),onClick:()=>h("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(T8,{open:p==="push",onClose:_,projectId:e,projectName:s,onPushed:i}),p==="commit"&&t.jsxs(j,{title:l("git.commit"),children:[t.jsx("textarea",{className:"w-full border border-warm-200 rounded-md px-3 py-2 text-sm resize-none focus:outline-none focus:ring-1 focus:ring-accent",rows:3,placeholder:l("git.commitMessage"),value:g,onChange:O=>b(O.target.value),autoFocus:!0}),t.jsxs("button",{className:"w-full btn-primary text-sm py-2",disabled:a||!g.trim()||!E,onClick:()=>w(()=>f1(e,g.trim(),o)),children:[l("git.commit")," ",!E&&t.jsxs("span",{className:"text-xs opacity-70 ml-1",children:["(",l("git.staged"),": 0)"]})]})]}),p==="branch"&&t.jsxs(j,{title:l("git.newBranch"),children:[t.jsx("input",{className:"w-full border border-warm-200 rounded-md px-3 py-2 text-sm focus:outline-none focus:ring-1 focus:ring-accent",placeholder:l("git.branchName"),value:g,onChange:O=>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:()=>w(()=>g1(e,g.trim())),children:l("git.create")})}),D.length>0&&t.jsxs("div",{className:"border-t border-warm-100 pt-2 mt-1",children:[t.jsx("p",{className:"text-2xs text-warm-400 uppercase tracking-wider mb-1",children:l("git.selectBranch")}),t.jsx("div",{className:"max-h-32 overflow-y-auto space-y-px",children:D.filter(O=>!O.current).map(O=>t.jsxs("div",{className:"flex items-center justify-between px-2 py-1 text-xs hover:bg-warm-50 rounded-md group",children:[t.jsx("button",{className:"truncate text-warm-600 hover:text-accent",onClick:()=>w(()=>gm(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 d({message:l("git.confirmDelete").replace("{name}",O.name),danger:!0})&&w(()=>pm(e,O.name))},children:l("git.delete")})]},O.name))})]})]}),p==="merge"&&t.jsxs(j,{title:l("git.merge"),children:[t.jsx("p",{className:"text-xs text-warm-500",children:l("git.selectBranch")}),t.jsx("div",{className:"max-h-48 overflow-y-auto space-y-px",children:D.filter(O=>!O.current).map(O=>t.jsx("button",{className:"w-full text-left px-3 py-2 text-sm hover:bg-warm-50 rounded-md text-warm-600 truncate",disabled:a,onClick:()=>w(()=>x1(e,O.name)),children:O.name},O.name))})]}),p==="stash"&&t.jsx(U8,{projectId:e,busy:a,exec:w,inputValue:g,setInputValue:b}),p==="tag"&&t.jsxs(j,{title:l("git.tag"),children:[t.jsx("input",{className:"w-full border border-warm-200 rounded-md px-3 py-2 text-sm focus:outline-none focus:ring-1 focus:ring-accent",placeholder:l("git.tagName"),value:g,onChange:O=>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:l("git.tagMessage"),value:C,onChange:O=>k(O.target.value)}),t.jsx("button",{className:"w-full btn-primary text-sm py-2",disabled:a||!g.trim(),onClick:()=>w(()=>v1(e,g.trim(),C.trim()||void 0)),children:l("git.create")})]})]})}function U8({projectId:e,busy:s,exec:i,inputValue:a,setInputValue:u}){const{t:f}=ht(),[m,o]=S.useState([]);return S.useEffect(()=>{a3(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:l=>u(l.target.value),autoFocus:!0}),t.jsx("button",{className:"btn-primary text-sm px-3 py-2",disabled:s,onClick:()=>i(()=>r3(e,a.trim()||void 0)),children:f("git.stash")})]}),m.length>0?t.jsx("div",{className:"space-y-px max-h-40 overflow-y-auto",children:m.map(l=>t.jsxs("div",{className:"flex items-center justify-between px-2 py-1.5 text-xs hover:bg-warm-50 rounded-md",children:[t.jsx("span",{className:"text-warm-600 truncate flex-1",children:l.message||`stash@{${l.index}}`}),t.jsx("button",{className:"text-accent hover:underline text-[11px] ml-2 shrink-0",disabled:s,onClick:()=>i(()=>i3(e,l.index)),children:f("git.stashPop")})]},l.index))}):t.jsx("p",{className:"text-xs text-warm-400 text-center",children:f("git.noStashes")})]})]})})}function _y(e,s){if(e==="?"&&s==="?")return{label:"U",color:"text-warm-400",type:"untracked"};const a=e!==" "&&e!=="?",u=a?e:s;let f="text-accent",m=u;return u==="A"?f="text-status-success":u==="D"?f="text-status-error":u==="R"?f="text-status-merged":u==="C"?f="text-accent":(f="text-accent",m="M"),{label:m,color:f,type:a?"staged":"unstaged"}}function Sy({file:e,pane:s,selected:i,checked:a,onClick:u,onToggleCheck:f,onContextMenu:m}){const o=s==="staged"?_y(e.index," "):_y(" ",e.working_dir==="?"?"?":e.working_dir),l=s==="unstaged"&&e.index==="?"&&e.working_dir==="?"?{label:"U",color:"text-warm-400"}:o;return t.jsxs("div",{onClick:u,onContextMenu:m,className:`flex items-center gap-2 px-3 py-1 cursor-pointer text-xs select-none transition-colors ${i?"bg-accent/15 text-accent":"hover:bg-warm-50 text-warm-700"}`,children:[t.jsx("input",{type:"checkbox",checked:a,onChange:f,onClick:d=>d.stopPropagation(),className:"h-3 w-3 shrink-0 cursor-pointer","aria-label":e.path}),t.jsx("span",{className:`shrink-0 w-4 h-4 flex items-center justify-center rounded-md text-[10px] font-mono font-bold ${s==="staged"?"bg-status-success/15":"bg-warm-200"} ${l.color}`,children:s==="staged"||l.label==="U"?"+":"−"}),t.jsx("span",{className:"truncate flex-1",title:e.path,children:e.path})]})}function W8({diff:e,loading:s,file:i}){const{t:a}=ht();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(`
|
|
@@ -678,7 +678,7 @@ WARNING: This link could potentially be dangerous`)){const y=window.open();if(y)
|
|
|
678
678
|
`)&&G(Z),ae.current=!0,ne(!0)},Re=S.useRef(De);Re.current=De;const ve=()=>{var Z,_e;ae.current=!1,ne(!1),(Z=q.current)==null||Z.clearDecorations(),he({index:-1,count:0});try{(_e=D.current)==null||_e.focus()}catch{}},Me=S.useRef(ve);Me.current=ve;const Oe=S.useRef(0),tt=(Z,_e,X)=>{const me=++Oe.current,se=Date.now();Y({dataUrl:Z,bytes:_e});const ie=()=>{const J=Math.max(0,600-(Date.now()-se));setTimeout(()=>{Oe.current===me&&Y(null)},J)};X.then(ie,ie)},nt=S.useRef(tt);nt.current=tt;const{warning:ke}=Ls(),fe=S.useRef(ke);fe.current=ke;const[Te,Ce]=S.useState(null),Ke=S.useRef(()=>{});S.useEffect(()=>{if(!Te)return;const Z=()=>Ce(null),_e=X=>{X.key==="Escape"&&Z()};return window.addEventListener("keydown",_e,!0),window.addEventListener("resize",Z),window.addEventListener("scroll",Z,!0),()=>{window.removeEventListener("keydown",_e,!0),window.removeEventListener("resize",Z),window.removeEventListener("scroll",Z,!0)}},[Te]),S.useEffect(()=>{var ze;const Z=j.current;if(!Z)return;const _e=ue=>{const Fe=ue.type;y.current&&Fe==="session:terminal-input"||u(ue)},X=new Mz.Terminal({fontFamily:Ot,fontSize:l,lineHeight:1,cursorBlink:s,convertEol:!1,scrollback:5e3,theme:x.current??Zc,minimumContrastRatio:Hy(x.current??Zc),allowProposedApi:!0,macOptionIsMeta:!0}),me=/Mac|iPhone|iPad|iPod/.test(navigator.platform);let se=0;const ie=async()=>{var Fe;if(y.current){console.debug("[paste] inputBlocked → ignored");return}if(!window.isSecureContext)return;if(se=Date.now(),!_.current)try{const Ve=await navigator.clipboard.read();for(const ft of Ve){const Ne=ft.types.find(at=>at.startsWith("image/"));if(Ne){const at=await ft.getType(Ne),bt=new FileReader;bt.onload=()=>{const Ct=bt.result;console.debug("[paste] image via clipboard.read(), bytes=",at.size);const Gt=H1(e,Ct);Gt.catch(an=>console.warn("[paste] pasteImage failed:",an)),nt.current(Ct,at.size,Gt)},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(`
|
|
679
679
|
`);console.debug("[paste] sending text, len=",ue.length,"multiline=",Ve),_e({type:"session:terminal-input",sessionId:e,input:mS(ue)});return}try{const Ve=await X4(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,ft=Fe&&!Ve&&!ue.altKey&&!ue.shiftKey,Ne=Fe&&!Ve&&!ue.altKey&&ue.shiftKey,at=ue.key.toLowerCase();if(at==="tab"&&(ft||Ne)&&w.current)return ue.preventDefault(),w.current(Ne?"prev":"next"),!1;if(at==="f"&&ft)return ue.preventDefault(),Re.current(),!1;if(at==="t"&&ft||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(ft&&at==="c"){const Ct=X.getSelection();return Ct?(ue.preventDefault(),(bt=navigator.clipboard)==null||bt.writeText(Ct).catch(()=>{}),X.clearSelection(),!1):!me}if(ft&&at==="v"||ue.altKey&&!ue.ctrlKey&&!ue.metaKey&&!ue.shiftKey&&at==="v")return ue.preventDefault(),ie(),!1;if((ue.ctrlKey||ue.metaKey)&&!ue.altKey){if(ue.key==="+"||ue.key==="=")return ue.preventDefault(),Go(e,1),!1;if(ue.key==="-"||ue.key==="_")return ue.preventDefault(),Go(e,-1),!1}return!0});const J=new zz.FitAddon;X.loadAddon(J),X.open(Z),D.current=X,N.current=J;try{const ue=new By.CanvasAddon;X.loadAddon(ue),R.current=ue}catch{R.current=null}const ee=new Pz.SearchAddon;X.loadAddon(ee),q.current=ee;const pe=ee.onDidChangeResults(({resultIndex:ue,resultCount:Fe})=>{be.current({index:ue,count:Fe})}),we=()=>{ae.current&&Me.current()};Z.addEventListener("focusin",we),X.attachCustomWheelEventHandler(ue=>!ue.ctrlKey&&!ue.metaKey?!0:(ue.preventDefault(),ue.__zoomHandled=!0,ue.deltaY!==0&&Go(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;Go(e,ue.deltaY<0?1:-1);return}ue.stopPropagation()};Z.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=Z.matches(":hover"),Ve=document.querySelector("[data-term-container]:hover")!==null,ft=!!X.textarea&&document.activeElement===X.textarea;(Ne=$e.imeLog)==null||Ne.call($e,{reason:"zoom:recv",dir:ue,hovered:Fe,anyTermHovered:Ve,focused:ft,path:window.location.pathname}),(Fe||!Ve&&ft)&&Go(e,ue==="in"?1:-1)});Ke.current=()=>{ie()};const qe=ue=>{ue.preventDefault(),Ce({x:ue.clientX,y:ue.clientY,hasSelection:X.hasSelection()})};Z.addEventListener("contextmenu",qe);try{J.fit()}catch{}if(h){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}))};I.current=Ee;const st=f(e,ue=>{try{X.write(ue)}catch{}}),lt=m(ue=>{ue.type==="session:replay-end"&&ue.sessionId===e&&W(!1)}),yt=()=>Date.now()-se<300,mt=()=>_.current,pt=ue=>z.current(ue),dt=(ue,Fe,Ve)=>nt.current(ue,Fe,Ve),kt=Uz()?Xz({container:Z,term:X,sessionId:e,sendMessage:_e}):Yz({container:Z,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=Z.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=U.current)==null||Ve.call(U,X.cols,X.rows)),B.current&&clearTimeout(B.current),B.current=setTimeout(Ee,150)}})},ue)});return Q.observe(Z),()=>{var ue;Q.disconnect(),vt!==null&&clearTimeout(vt),B.current&&clearTimeout(B.current),O.current&&clearTimeout(O.current),Z.removeEventListener("wheel",je),Je==null||Je(),Z.removeEventListener("contextmenu",qe),Ce(null),kt(),st(),lt();try{u({type:"session:unsubscribe",sessionId:e})}catch{}Z.removeEventListener("focusin",we),pe.dispose(),q.current=null,(ue=R.current)==null||ue.dispose(),R.current=null,X.dispose(),D.current=null,N.current=null,I.current=null,F.current=!1}},[e]),S.useEffect(()=>{if(!i||F.current)return;F.current=!0;const Z=D.current;Z&&Z.cols>0&&Z.rows>0&&(A.current={cols:0,rows:0},u({type:"session:resize",sessionId:e,cols:Z.cols,rows:Z.rows})),u({type:"session:subscribe",sessionId:e})},[i,e,u]),S.useEffect(()=>{D.current&&(D.current.options.cursorBlink=s)},[s]),S.useEffect(()=>{var me;if(!h)return;const Z=document.activeElement;if(!(!(!!Z&&Z.classList.contains("xterm-helper-textarea"))&&!!Z&&(Z.tagName==="INPUT"||Z.tagName==="TEXTAREA"||Z.tagName==="SELECT"||Z.isContentEditable)))try{(me=D.current)==null||me.focus()}catch{}},[h]),S.useEffect(()=>{const Z=D.current,_e=N.current;if(!Z||!_e||Z.options.fontSize===l)return;if(Z.options.fontSize=l,R.current){try{R.current.dispose()}catch{}R.current=null;try{const me=new By.CanvasAddon;Z.loadAddon(me),R.current=me}catch{}}if(Z.buffer.active.type==="alternate"){O.current&&clearTimeout(O.current),O.current=setTimeout(()=>{var me;(me=T.current)==null||me.call(T)},500);return}try{_e.fit(),Z.refresh(0,Z.rows-1)}catch{}Z.cols===A.current.cols&&Z.rows===A.current.rows||(O.current&&clearTimeout(O.current),O.current=setTimeout(()=>{var me;(me=I.current)==null||me.call(I)},300))},[l,e]),S.useEffect(()=>{const Z=D.current;if(Z){Z.options.theme=d??Zc,Z.options.minimumContrastRatio=Hy(d??Zc);try{Z.refresh(0,Z.rows-1)}catch{}}},[d]),S.useEffect(()=>{if(!ce)return;const Z=q.current;if(!Z)return;const _e=setTimeout(()=>{te?Z.findNext(te,{...Yf,incremental:!0}):(Z.clearDecorations(),he({index:-1,count:0}))},120);return()=>clearTimeout(_e)},[te,ce]),S.useEffect(()=>{var Z;ce&&((Z=oe.current)==null||Z.select())},[ce]);const Ze=(d==null?void 0:d.background)??Ue.bg,ye=()=>{var Z;te&&((Z=q.current)==null||Z.findNext(te,Yf))},Be=()=>{var Z;te&&((Z=q.current)==null||Z.findPrevious(te,Yf))};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%"}}),ce&&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:Z=>G(Z.target.value),onKeyDown:Z=>{Z.key==="Enter"?(Z.preventDefault(),Z.shiftKey?Be():ye()):Z.key==="Escape"&&(Z.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?de.count>0?`${de.index+1}/${de.count}`:"0/0":""}),[{label:"↑",title:"이전 (Shift+Enter)",onClick:Be},{label:"↓",title:"다음 (Enter)",onClick:ye},{label:"×",title:"닫기 (Esc)",onClick:ve}].map(Z=>t.jsx("button",{type:"button",title:Z.title,onClick:Z.onClick,className:"px-1.5 rounded-md hover:bg-white/10",style:{color:Ue.bright,lineHeight:"18px"},children:Z.label},Z.label))]}),(K||$)&&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:[$&&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:$.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:["이미지 붙여넣음 · ",Hz($.bytes)]})]}),K&&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,l),color:Ue.bright,lineHeight:1.3,whiteSpace:"pre",overflow:"hidden",textOverflow:"ellipsis"},children:K})]}),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)),se=()=>Ce(null),ie=()=>{var we,je;const pe=((we=D.current)==null?void 0:we.getSelection())??"";pe&&((je=navigator.clipboard)==null||je.writeText(pe).catch(()=>{})),se()},J=()=>{Ke.current(),se()},ee=()=>{var pe;(pe=D.current)==null||pe.selectAll(),se()};return t.jsxs(t.Fragment,{children:[t.jsx("div",{style:{position:"fixed",inset:0,zIndex:2147483646},onMouseDown:se,onContextMenu:pe=>{pe.preventDefault(),se()}}),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:ie,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:ee,className:"w-full text-left px-3 py-1.5 rounded-md hover:bg-white/10",style:{color:Ue.bright},children:"전체 선택"})]})]})})(),document.body)]})}function Uz(){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 pu=[12593,12594,12596,12599,12600,12601,12609,12610,12611,12613,12614,12615,12616,12617,12618,12619,12620,12621,12622],pS=[12623,12624,12625,12626,12627,12628,12629,12630,12631,12632,12633,12634,12635,12636,12637,12638,12639,12640,12641,12642,12643],$y=[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 gS(e){return e>=12593&&e<=12622}function xS(e){return e>=12623&&e<=12643}function Wz(e){return gS(e)||xS(e)}function qz(e){return e>=44032&&e<=55203}function Gz(){return{cho:-1,jung:-1,jong:0}}function Bp(e){return e.cho<0&&e.jung<0&&e.jong===0}function Nr(e){return Bp(e)?"":e.cho>=0&&e.jung>=0?String.fromCharCode(44032+(e.cho*21+e.jung)*28+e.jong):e.cho>=0?String.fromCharCode(pu[e.cho]):e.jung>=0?String.fromCharCode(pS[e.jung]):""}function Uy(e){const s=Nr(e);return e.cho=-1,e.jung=-1,e.jong=0,s}function Kz(e,s){if(xS(s)){const i=pS.indexOf(s);if(i<0)return"";if(e.cho<0&&e.jung<0||e.cho>=0&&e.jung<0)return e.jung=i,"";if(e.cho<0&&e.jung>=0){const m=Nr(e);return e.jung=i,m}if(e.jong===0){const m=Nr(e);return e.cho=-1,e.jung=i,e.jong=0,m}const a=$y[e.jong],u=pu.indexOf(a);e.jong=0;const f=Nr(e);return u>=0?(e.cho=u,e.jung=i,e.jong=0):(e.cho=-1,e.jung=i,e.jong=0),f}if(gS(s)){const i=pu.indexOf(s),a=$y.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(pu[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=Nr(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=Nr(e);return e.cho=i>=0?i:-1,e.jung=-1,e.jong=0,f}const u=Nr(e);return e.cho=i>=0?i:-1,e.jung=-1,e.jong=0,i<0?u+String.fromCharCode(s):u}return""}function Vz(e,s){const i=Nr(e),a=s-44032;return e.cho=Math.floor(a/588),e.jung=Math.floor(a/28)%21,e.jong=a%28,i}function Wy(e){return Bp(e)?!1:(e.cho=-1,e.jung=-1,e.jong=0,!0)}function Yz({container:e,term:s,sessionId:i,sendMessage:a,isPasteAlreadyHandled:u,isImagePasteDisabled:f,onComposingChange:m,onImagePasted:o}){let l=!1;const d=R=>{try{m==null||m(R)}catch{}};let p=null;const h=(R,A={})=>{var B,O;try{(O=(B=window.electronAPI)==null?void 0:B.imeLog)==null||O.call(B,{reason:R,path:window.location.pathname,...A})}catch{}},g=(R=!1)=>{try{const A=e.querySelector(".xterm-helper-textarea"),B=e.querySelector(".xterm-screen");if(!A||!B){R||h("pos:no-dom",{hasHelper:!!A,hasScreen:!!B});return}const O=s.cols,F=s.rows;if(O<=0||F<=0){R||h("pos:no-grid",{cols:O,rows:F});return}const U=B.getBoundingClientRect();if(U.width===0||U.height===0){R||h("pos:zero-screen",{w:U.width,h:U.height});return}const I=U.width/O,H=U.height/F,W=s.buffer.active,K=Math.min(W.cursorX,O-1),P=Math.max(0,Math.min(W.cursorY,F-1));A.style.left=`${K*I}px`,A.style.top=`${P*H}px`,A.style.width=`${Math.max(I,1)}px`,A.style.height=`${Math.max(H,1)}px`,R||h("pos:applied",{cursorX:K,cursorY:P,left:K*I,top:P*H})}catch{}};g();let b=0;const C=()=>{b||(b=requestAnimationFrame(()=>{b=0,g(!0)}))},k=s.onCursorMove(C),x=()=>{var R;l=!0,g(),d("");try{const A=document.activeElement,B=e.querySelector(".xterm-helper-textarea"),O=B==null?void 0:B.getBoundingClientRect();h("compositionstart",{activeTag:A==null?void 0:A.tagName,activeClass:A==null?void 0:A.className,activeIsHelper:!!A&&((R=A.classList)==null?void 0:R.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{}},y=R=>{d(R.data??""),h("compositionupdate",{data:R.data??""})},_=R=>{l=!1,d("");const A=R.data;h("compositionend",{data:A??"",sent:!!A}),A&&(p=A,a({type:"session:terminal-input",sessionId:i,input:A}))},w=R=>{var O,F;if(u()){R.preventDefault();return}const A=(O=R.clipboardData)==null?void 0:O.items;if(A&&!(f!=null&&f())){for(let U=0;U<A.length;U++)if(A[U].type.startsWith("image/")){R.preventDefault();const I=A[U].getAsFile();if(!I)return;const H=new FileReader;H.onload=()=>{const W=H.result;console.debug("[paste-fallback] image via paste event, bytes=",I.size);const K=H1(i,W,I.name);K.catch(P=>console.warn("[paste-fallback] pasteImage failed:",P)),o==null||o(W,I.size,K)},H.readAsDataURL(I);return}}const B=(F=R.clipboardData)==null?void 0:F.getData("text/plain");if(B){R.preventDefault();const U=B.includes(`
|
|
680
680
|
`);console.debug("[paste-fallback] sending text, len=",B.length,"multiline=",U),a({type:"session:terminal-input",sessionId:i,input:mS(B)})}else console.debug("[paste-fallback] paste event had no usable text/image")},E=R=>{var U,I;const A=(U=R.dataTransfer)==null?void 0:U.files;if(!A||A.length===0)return;R.preventDefault();const B=(I=window.electronAPI)==null?void 0:I.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=Fz(O);F&&a({type:"session:terminal-input",sessionId:i,input:F})},T=R=>{var A,B;(B=(A=R.dataTransfer)==null?void 0:A.types)!=null&&B.includes("Files")&&(R.preventDefault(),R.dataTransfer.dropEffect="copy")},j=()=>{if(l)return;Op(()=>{try{s.focus()}catch{}})&&h("focus-rescue")},D=R=>{var A,B;h("keydown",{key:R.key,composing:l,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",D,!0),e.addEventListener("compositionstart",x,!0),e.addEventListener("compositionupdate",y,!0),e.addEventListener("compositionend",_,!0),e.addEventListener("paste",w,!0),e.addEventListener("dragover",T),e.addEventListener("drop",E);const N=s.onData(R=>{if(!l){if(p!==null&&R===p){p=null;return}p=null,a({type:"session:terminal-input",sessionId:i,input:R})}});return()=>{N.dispose(),k.dispose(),b&&cancelAnimationFrame(b),e.removeEventListener("keydown",D,!0),e.removeEventListener("compositionstart",x,!0),e.removeEventListener("compositionupdate",y,!0),e.removeEventListener("compositionend",_,!0),e.removeEventListener("paste",w,!0),e.removeEventListener("dragover",T),e.removeEventListener("drop",E),d("")}}function Xz({container:e,term:s,sessionId:i,sendMessage:a}){const u=e.querySelector(".xterm-helper-textarea");let f="",m=0;u&&(f=u.style.display,m=u.tabIndex,u.style.display="none",u.tabIndex=-1),getComputedStyle(e).position==="static"&&(e.style.position="relative");const o=document.createElement("textarea");o.setAttribute("autocomplete","off"),o.setAttribute("lang","ko"),o.setAttribute("inputmode","text"),o.rows=1,Object.assign(o.style,{position:"absolute",background:"transparent",border:"none",outline:"none",padding:"0",margin:"0",fontFamily:Ot,fontSize:"16px",lineHeight:"1.2",resize:"none",overflow:"hidden",whiteSpace:"pre",caretColor:"rgba(255,255,255,0.001)",zIndex:"5"});const l=()=>{Object.assign(o.style,{inset:"0",left:"auto",top:"auto",width:"100%",height:"100%",color:"transparent"})},d=()=>{const j=e.querySelector(".xterm-screen");if(!j)return;const D=s.cols,N=s.rows;if(D<=0||N<=0)return;const R=j.clientWidth/D,A=j.clientHeight/N,B=s.buffer.active.cursorX,O=s.buffer.active.cursorY,F=j.getBoundingClientRect(),U=e.getBoundingClientRect();Object.assign(o.style,{inset:"auto",left:`${F.left-U.left+B*R}px`,top:`${F.top-U.top+O*A}px`,width:`${Math.max(R*30,240)}px`,height:`${Math.max(A,20)}px`,color:Ue.text})};l(),e.appendChild(o);let p=!1;const h=Gz();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=Uy(h);j&&C(j)},x=()=>{const j=Nr(h);o.value=j,j?d():l()},y=()=>{b(),g=setTimeout(()=>{g=null,k(),o.value="",l()},600)},_=()=>{p=!0,b(),k(),d()},w=j=>{p=!1,j.data&&C(j.data),o.value="",l()};o.addEventListener("compositionstart",_),o.addEventListener("compositionend",w);const E=j=>{if(p)return;const D=j;switch(D.inputType){case"insertCompositionText":case"insertFromComposition":return;case"deleteContentBackward":b(),Wy(h)?x():(C(""),o.value="",l());return;case"insertLineBreak":case"insertParagraph":b(),k(),C("\r"),o.value="",l();return;default:if(!D.data){x();return}b();let N="";for(const R of D.data){const A=R.codePointAt(0);Wz(A)?N+=Kz(h,A):qz(A)?N+=Vz(h,A):(N+=Uy(h),N+=R)}C(N),x(),Bp(h)||y()}};o.addEventListener("input",E);const T=j=>{if(p||j.isComposing)return;let D=null;switch(j.key){case"Enter":D="\r";break;case"Backspace":D="";break;case"Tab":D=" ";break;case"Escape":D="\x1B";break;case"ArrowUp":D="\x1B[A";break;case"ArrowDown":D="\x1B[B";break;case"ArrowRight":D="\x1B[C";break;case"ArrowLeft":D="\x1B[D";break;case"Home":D="\x1B[H";break;case"End":D="\x1B[F";break}if(D){if(j.preventDefault(),b(),j.key==="Backspace"){if(Wy(h)){x();return}}else k();C(D),o.value="",l();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="",l())}};return o.addEventListener("keydown",T),()=>{b(),k(),o.remove(),u&&(u.style.display=f,u.tabIndex=m)}}function Jz({sessionId:e,onClose:s,projectId:i,onEvent:a,sendMessage:u}){const{t:f}=ht(),[m,o]=S.useState([]),[l,d]=S.useState(!0),[p,h]=S.useState(null),[g,b]=S.useState(!1),[C,k]=S.useState(null),[x,y]=S.useState(""),[_,w]=S.useState(!1),[E,T]=S.useState(0),[j,D]=S.useState([]),[N,R]=S.useState(null),[A,B]=S.useState(!1),[O,F]=S.useState({from:null,now:null}),U=S.useRef(new Map),I=S.useCallback(()=>T(K=>K+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(K=>{K.type==="git:changed"&&K.projectId===i&&I()})},[a,i,I]),S.useEffect(()=>{let K=!1;return H4(e).then(P=>{K||D(P.snapshots??[])}).catch(()=>{K||D([])}),()=>{K=!0}},[e,E]),S.useEffect(()=>{let K=!1;return b(!0),I4(e,N??void 0).then(P=>{if(K)return;d(P.available),h(P.reason??null);const z=P.available&&P.files?P.files.map($=>({path:$.path,status:$.status,additions:$.insertions,deletions:$.deletions})):[];o(z),U.current.clear(),F({from:N,now:P.now??null}),k($=>$&&z.some(Y=>Y.path===$)?$:z.length>0?z[0].path:null)}).catch(()=>{K||(d(!1),h("error"),o([]))}).finally(()=>{K||b(!1)}),()=>{K=!0}},[e,N,E]),S.useEffect(()=>{if(!C){y("");return}const K=`${O.now??""}:${C}`,P=U.current.get(K);if(P!==void 0){y(P),w(!1);return}let z=!1;return w(!0),y(""),F4(e,C,O.from??void 0,O.now??void 0).then($=>{if(z)return;const Y=$.available&&$.diff?$.diff:"";U.current.set(K,Y),y(Y)}).catch(()=>{z||y("")}).finally(()=>{z||w(!1)}),()=>{z=!0}},[e,C,O]);const H=S.useCallback(()=>{B(!0),$4(e).then(K=>{if(K.available&&K.snapshots){D(K.snapshots);const P=K.snapshots[K.snapshots.length-1];P&&R(P.sha)}}).catch(()=>{}).finally(()=>B(!1))},[e]),W=K=>{const P=new Date(K);return Number.isNaN(P.getTime())?K:P.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||!l,title:f("session.diff.capture")||"Capture snapshot",className:"p-1 rounded-md hover:bg-warm-100 text-warm-500 disabled:opacity-40",children:t.jsx(k5,{size:14,className:A?"animate-pulse":""})}),t.jsx("button",{onClick:I,title:f("common.refresh")||"Refresh",className:"p-1 rounded-md hover:bg-warm-100 text-warm-500",children:t.jsx(lp,{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(Vt,{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(qy,{active:N===null,onClick:()=>R(null),label:f("session.diff.pageStart")||"From start"}),j.map(K=>t.jsx(qy,{active:N===K.sha,onClick:()=>R(K.sha),label:`#${K.seq} ${W(K.at)}`},K.sha))]}),l?t.jsxs("div",{className:"flex-1 flex min-h-0",children:[t.jsx("div",{className:"w-2/5 min-w-[180px] max-w-[320px] border-r border-warm-100 overflow-hidden",children:t.jsx(Ju,{files:m,loading:g,selectedFile:C,onFileClick:k})}),t.jsx("div",{className:"flex-1 min-w-0",children:t.jsx(eo,{diff:x,loading:_,selectedFile:C})})]}):t.jsx("div",{className:"flex-1 flex items-center justify-center px-4 text-center",children:t.jsx("span",{className:"text-xs text-warm-400",children:p==="not-git"?f("session.diff.notGit")||"Not a git repository":f("session.diff.unavailable")||"Diff unavailable"})})]})}function qy({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 Qz={presetId:fS},xl=new Map,Fa=new Map;function vS(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=Fm(s);i.forEach(f=>f(u))}});function Zz(e){return typeof e!="string"?!1:e==="custom"||e in On}function Fm(e){const s=xl.get(e);if(s!==void 0)return s;let i=Qz;try{const a=localStorage.getItem(vS(e));if(a!==null){const u=JSON.parse(a);u&&Zz(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 eO(e,s){const i=xl.get(e);if(i&&i.presetId===s.presetId&&tO(i.custom,s.custom))return;xl.set(e,s);try{localStorage.setItem(vS(e),JSON.stringify(s))}catch{}const a=Fa.get(e);a&&a.forEach(u=>u(s))}function tO(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 nO(e){if(e.presetId!=="custom")return Fy(e.presetId).theme;const s=Fy(fS).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 bS(e){const[s,i]=S.useState(()=>Fm(e));S.useEffect(()=>{i(Fm(e));let f=Fa.get(e);return f||(f=new Set,Fa.set(e,f)),f.add(i),()=>{const m=Fa.get(e);m&&(m.delete(i),m.size===0&&Fa.delete(e))}},[e]);const a=S.useCallback(f=>eO(e,f),[e]),u=S.useMemo(()=>nO(s),[s]);return[s,u,a]}function yS({session:e,visible:s,intent:i,intentNonce:a,onClose:u,sendMessage:f,subscribeBinary:m,onEvent:o,onCycleTab:l,remountKey:d=0}){const{t:p}=ht(),h=e.status==="running"||i==="start"||i==="resume"?"pendingFit":"replay-only",[g,b]=S.useState(h),[C,k]=S.useState(null),[x,y]=S.useState(!1),[_,w]=S.useState(480),E=!!e.is_git_repo,T=S.useRef(null),j=S.useCallback(ve=>{ve.preventDefault();const Me=T.current;if(!Me)return;const Oe=nt=>{const ke=Me.getBoundingClientRect(),fe=240,Te=Math.max(fe,ke.width-200);w(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"},[]),[D,N]=S.useState(0),R=S.useCallback(()=>N(ve=>ve+1),[]),A=S.useRef(null),B=S.useRef(!1),O=S.useRef(a),[F,U]=S.useState(null),[I,H]=S.useState(null),[W,K]=S.useState(!1),[P,z]=S.useState(null),[$,Y]=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),Y(null);try{const Me=await q4(e.id,ve,i==="resume"?{continueSession:!0}:void 0);b("subscribed"),Me.pendingInitialPrompt?(U(Me.pendingInitialPromptLength??0),H(null),K(!1)):(U(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]),ce=S.useCallback(async()=>{if(W){K(!1);return}if(K(!0),I===null)try{const ve=await G4(e.id);H(ve.prompt??"")}catch(ve){Y(ve instanceof Error?ve.message:String(ve))}},[W,I,e.id]),ne=S.useCallback(async()=>{if(!P){z("send"),Y(null);try{await K4(e.id),U(null),H(null),K(!1)}catch(ve){Y(ve instanceof Error?ve.message:String(ve))}finally{z(null)}}},[P,e.id]),te=S.useCallback(async()=>{if(!P){z("skip"),Y(null);try{await V4(e.id),U(null),H(null),K(!1)}catch(ve){Y(ve instanceof Error?ve.message:String(ve))}finally{z(null)}}},[P,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 G=S.useCallback(()=>{A.current?oe():b("pendingFit")},[oe]),de=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]),he=e.status==="running",be=g==="subscribed",[ae]=L1(e.id),[,De]=bS(e.id),Re=g==="starting"||g==="pendingFit"?t.jsxs("div",{style:{...eu,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:p("session.starting")||"starting…"})]}),t.jsx("span",{style:{color:Ue.dim,fontFamily:Ot,fontSize:10,marginTop:6},children:p("session.starting.typeAhead")||"type-ahead is captured and replayed once ready"})]}):g==="stopping"?t.jsx("div",{style:{...eu,pointerEvents:"none"},children:t.jsx("span",{style:{color:Ue.dim,fontFamily:Ot,fontSize:12},children:p("session.stopping")||"stopping…"})}):g==="replay-only"?t.jsx("div",{style:eu,children:t.jsxs("button",{onClick:G,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})," ",p("session.startInWindow")||"Start"]})}):g==="error"?t.jsxs("div",{style:eu,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})," ",p("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:p("common.retry")||"Retry"})]}):null;return t.jsxs("div",{ref:T,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($z,{sessionId:e.id,isRunning:he,subscribed:be,onFitted:de,sendMessage:f,subscribeBinary:m,onEvent:o,fontSize:ae,theme:De,inputBlocked:F!==null,autoFocusOnMount:s,onRequestRefresh:R,disableImagePaste:e.cli_tool==="raw-shell",onCycleTab:l,onToggleDiff:()=>{E&&y(ve=>!ve)}},`${d}:${D}`),Re,E&&!x&&t.jsxs("button",{onClick:()=>y(!0),title:`${p("session.diff.title")||"Diff"} (${navigator.platform.startsWith("Mac")?"⌘":"Ctrl"}+Shift+D)`,style:{position:"absolute",top:4,right:8,zIndex:1002,display:"inline-flex",alignItems:"center",gap:4,fontFamily: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(vE,{size:12})," Diff"]}),F!==null&&t.jsxs("div",{style:sO,children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[t.jsx($5,{"aria-hidden":!0,size:14,style:{color:Ue.info}}),t.jsxs("span",{style:{flex:1},children:[p("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:p("session.initialPrompt.blocked")||"Press Send or Skip before typing — keystrokes are ignored until then."})]}),t.jsxs("button",{onClick:ce,style:Xf("neutral"),title:W?p("session.initialPrompt.hidePreview")||"Hide preview":p("session.initialPrompt.preview")||"Preview",children:[W?t.jsx(Jw,{size:12}):t.jsx(Ja,{size:12}),W?p("session.initialPrompt.hidePreview")||"Hide":p("session.initialPrompt.preview")||"Preview"]}),t.jsxs("button",{onClick:ne,disabled:P!==null,style:Xf("primary"),children:[P==="send"?t.jsx(hi,{size:12,style:{animation:"spin 1s linear infinite"}}):t.jsx(pN,{size:12}),p("session.initialPrompt.send")||"Send"]}),t.jsx("button",{onClick:te,disabled:P!==null,style:Xf("danger"),children:p("session.initialPrompt.skip")||"Skip"})]}),$&&t.jsx("div",{style:{color:Ue.error,fontSize:10,marginTop:4},children:$}),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:I===null?p("session.initialPrompt.loading")||"loading…":I})]})]}),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:_,flexShrink:0,minWidth:0,height:"100%"},children:t.jsx(Jz,{sessionId:e.id,projectId:e.project_id,onEvent:o,sendMessage:f,onClose:()=>y(!1)})})]})]})}const sO={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 Xf(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 eu={position:"absolute",inset:0,background:"rgba(12,12,12,0.85)",display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",zIndex:1e3},Gy=340;function rO({sessionId:e}){var C,k,x,y,_,w;const[s,,i]=bS(e),[a,u]=S.useState(!1),[f,m]=S.useState(!1),[o,l]=S.useState({top:0,left:0}),d=S.useRef(null),p=S.useRef(null),h=S.useCallback(()=>{if(!d.current)return;const E=d.current.getBoundingClientRect(),T=window.innerWidth,j=window.innerHeight,D=p.current;let N=E.bottom+4,R=E.right-Gy;if(D){const A=D.offsetHeight,B=D.offsetWidth;R=E.right-B,R<8&&(R=8),R+B>T-8&&(R=T-8-B),N+A>j-8&&(N=Math.max(8,E.top-A-4))}else R<8&&(R=8);l({top:N,left:R}),m(!0)},[]);S.useEffect(()=>{if(!a){m(!1);return}h();const E=requestAnimationFrame(h),T=D=>{var R,A;const N=D.target;(R=d.current)!=null&&R.contains(N)||(A=p.current)!=null&&A.contains(N)||u(!1)},j=D=>{D.key==="Escape"&&u(!1)};return document.addEventListener("mousedown",T),document.addEventListener("keydown",j),window.addEventListener("scroll",h,!0),window.addEventListener("resize",h),()=>{cancelAnimationFrame(E),document.removeEventListener("mousedown",T),document.removeEventListener("keydown",j),window.removeEventListener("scroll",h,!0),window.removeEventListener("resize",h)}},[a,h]);const g=E=>{if(E==="custom"){const T=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:T})}else i({presetId:E,custom:s.custom}),u(!1)},b=E=>{const T={...s.custom??{},...E};i({presetId:"custom",custom:T})};return t.jsxs(t.Fragment,{children:[t.jsx("button",{ref:d,"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(ZE,{size:14})}),a&&rn.createPortal(t.jsxs("div",{ref:p,className:"z-tooltip",style:{position:"fixed",top:o.top,left:o.left,width:Gy,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:Iy.filter(E=>!On[E].light).map(E=>t.jsx(Ky,{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:[Iy.filter(E=>On[E].light).map(E=>t.jsx(Ky,{preset:On[E],selected:s.presetId===E,onClick:()=>g(E)},E)),t.jsx(iO,{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:((y=s.custom)==null?void 0:y.cursor)??On.default.theme.cursor??"#f2f2f2",onChange:E=>b({cursor:E})}),t.jsx(Jo,{label:"Selection",value:((_=s.custom)==null?void 0:_.selectionBackground)??On.default.theme.selectionBackground??"#264f78",onChange:E=>b({selectionBackground:E})}),t.jsx(Jo,{label:"Accent",value:((w=s.custom)==null?void 0:w.accent)??On.default.theme.brightBlue??"#569cd6",onChange:E=>b({accent:E})})]})]}),document.body)]})}function Ky({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(ir,{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 iO({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(ir,{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=m=>{u(m);const o=m.startsWith("#")?m:`#${m}`;(/^#[0-9a-fA-F]{6}$/.test(o)||/^#[0-9a-fA-F]{3}$/.test(o))&&i(Vy(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:m=>f(m.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:Vy(s),onChange:m=>i(m.target.value),style:{width:28,height:22,padding:0,border:`1px solid ${Ue.separator}`,borderRadius:3,background:"transparent",cursor:"pointer"}})]})}function Vy(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 Yy=360;function aO({sessionId:e,sendMessage:s}){const[i,a]=S.useState(!1),[u,f]=S.useState(!1),[m,o]=S.useState({top:0,left:0}),[l,d]=S.useState(null),[p,h]=S.useState(""),[g,b]=S.useState(!1),[C,k]=S.useState(""),[x,y]=S.useState(""),[_,w]=S.useState(!1),[E,T]=S.useState(null),j=S.useRef(null),D=S.useRef(null),N=S.useRef(null),R=S.useCallback(()=>{if(!j.current)return;const I=j.current.getBoundingClientRect(),H=window.innerWidth,W=window.innerHeight,K=D.current;let P=I.bottom+4,z=I.right-Yy;if(K){const $=K.offsetHeight,Y=K.offsetWidth;z=I.right-Y,z<8&&(z=8),z+Y>H-8&&(z=H-8-Y),P+$>W-8&&(P=Math.max(8,I.top-$-4))}else z<8&&(z=8);o({top:P,left:z}),f(!0)},[]);S.useEffect(()=>{if(!i)return;let I=!1;return E1().then(H=>{I||d(H)}).catch(H=>{I||T(H instanceof Error?H.message:"Failed to load")}),()=>{I=!0}},[i]),S.useEffect(()=>{if(!i){f(!1);return}R();const I=requestAnimationFrame(R),H=requestAnimationFrame(()=>{requestAnimationFrame(()=>{var P;return(P=N.current)==null?void 0:P.focus()})}),W=P=>{var $,Y;const z=P.target;($=j.current)!=null&&$.contains(z)||(Y=D.current)!=null&&Y.contains(z)||a(!1)},K=P=>{P.key==="Escape"&&a(!1)};return document.addEventListener("mousedown",W),document.addEventListener("keydown",K),window.addEventListener("scroll",R,!0),window.addEventListener("resize",R),()=>{cancelAnimationFrame(I),cancelAnimationFrame(H),document.removeEventListener("mousedown",W),document.removeEventListener("keydown",K),window.removeEventListener("scroll",R,!0),window.removeEventListener("resize",R)}},[i,R]),S.useEffect(()=>{i||(h(""),b(!1),k(""),y(""),T(null))},[i]);const A=S.useMemo(()=>{if(!l)return[];const I=p.trim().toLowerCase();return I?l.filter(H=>H.name.toLowerCase().includes(I)||H.command_template.toLowerCase().includes(I)):l},[l,p]),B=I=>{s({type:"session:terminal-input",sessionId:e,input:I.command_template}),a(!1)},O=I=>{I.key==="Enter"&&A.length>0&&(I.preventDefault(),B(A[0]))},F=!!C.trim()&&!!x.trim()&&!_,U=async()=>{if(F){w(!0),T(null);try{const I=await N1({name:C.trim(),command_template:x.trim()});d(H=>H?[I,...H]:[I]),k(""),y(""),b(!1)}catch(I){T(I instanceof Error?I.message:"Failed")}finally{w(!1)}}};return t.jsxs(t.Fragment,{children:[t.jsx("button",{ref:j,"data-no-drag":!0,onMouseDown:I=>I.stopPropagation(),onClick:()=>a(I=>!I),"aria-label":"alias-inserter",title:"Insert saved command (alias) (Ctrl+Shift+A)",style:oO,children:t.jsx(Y5,{size:14})}),i&&rn.createPortal(t.jsxs("div",{ref:D,className:"z-tooltip",style:{position:"fixed",top:m.top,left:m.left,width:Yy,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:I=>I.stopPropagation(),children:[t.jsx("input",{ref:N,type:"text",value:p,onChange:I=>h(I.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:l===null?t.jsx("div",{style:Xy,children:"Loading…"}):A.length===0?t.jsx("div",{style:Xy,children:l.length===0?"No aliases yet — add one below.":"No matches."}):A.map(I=>t.jsxs("button",{onClick:()=>B(I),style:lO,onMouseEnter:H=>H.currentTarget.style.background="rgba(255,255,255,0.06)",onMouseLeave:H=>H.currentTarget.style.background="transparent",title:`Insert: ${I.command_template}`,children:[t.jsx("span",{style:{fontSize:11,color:Ue.bright,fontWeight:600},children:I.name}),t.jsx("code",{style:{fontSize:10,color:Ue.dim,marginLeft:8,flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:I.command_template})]},I.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:I=>k(I.target.value),placeholder:"Name (e.g. git status)",maxLength:64,style:Jy}),t.jsx("input",{type:"text",value:x,onChange:I=>y(I.target.value),onKeyDown:I=>{I.key==="Enter"&&(I.preventDefault(),U())},placeholder:"Command (e.g. git status -sb)",maxLength:1024,style:{...Jy,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),T(null)},style:wS,children:[t.jsx(Vt,{size:12})," Cancel"]}),t.jsx("button",{type:"button",onClick:U,disabled:!F,style:{...cO,opacity:F?1:.5},children:"Save"})]})]}):t.jsxs("button",{type:"button",onClick:()=>{b(!0),T(null)},style:uO,children:[t.jsx(vn,{size:12})," New alias"]})})]}),document.body)]})}const oO={background:"transparent",border:"none",color:Ue.titleText,cursor:"pointer",padding:"0 6px",display:"flex",alignItems:"center",justifyContent:"center",borderRadius:0,flexShrink:0,height:"100%"},Xy={fontSize:11,color:Ue.dim,padding:"12px 4px",textAlign:"center"},lO={display:"flex",alignItems:"center",width:"100%",background:"transparent",border:"none",padding:"6px 8px",cursor:"pointer",textAlign:"left",borderRadius:3,transition:"background 80ms"},Jy={width:"100%",boxSizing:"border-box",background:"#0c0c0c",border:`1px solid ${Ue.separator}`,borderRadius:4,color:Ue.bright,fontSize:11,padding:"5px 7px",outline:"none"},wS={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"},cO={...wS,background:"rgba(86,156,214,0.13)",border:"1px solid #569cd6",color:Ue.bright},uO={display:"inline-flex",alignItems:"center",gap:4,background:"transparent",border:"none",color:Ue.dim,fontFamily:Ot,fontSize:11,padding:"4px 0",cursor:"pointer"},dO=26;function Pp({stack:e,path:s,groupId:i,sessionsById:a,colors:u,intents:f,onTabClick:m,onTabClose:o,onTabMouseDown:l,onPaneAutoClose:d,registerRect:p,sendMessage:h,subscribeBinary:g,onEvent:b,focusedSessionId:C,groupTopmost:k,onFocusStack:x,groupActions:y}){const{t:_}=ht(),[w,,E]=L1(e.activeTab),[T,j]=S.useState({}),D=()=>{const H=e.activeTab;H&&j(W=>({...W,[H]:(W[H]||0)+1}))},N=TO(),R=k===void 0?!0:k&&(!C||C===e.activeTab),A=k===!0&&!R,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()},U=e.tabs.length>1?H=>{const W=e.tabs.indexOf(e.activeTab);if(W<0)return;const K=e.tabs.length,P=H==="next"?(W+1)%K:(W-1+K)%K;m(e.tabs[P])}:void 0,I=H=>{var oe;const W=/Mac|iPhone|iPad|iPod/.test(navigator.platform),K=W?H.metaKey:H.ctrlKey,P=W?H.ctrlKey:H.metaKey,z=K&&!P&&!H.altKey&&H.shiftKey,$=H.key.toLowerCase();if(H.key==="F5"&&!H.ctrlKey&&!H.metaKey&&!H.altKey&&!H.shiftKey||z&&$==="r"){H.preventDefault(),D();return}if(!z||$!=="a"&&$!=="p")return;H.preventDefault();const q=$==="a"?"alias-inserter":"terminal-theme";(oe=H.currentTarget.querySelector(`[aria-label="${q}"]`))==null||oe.click()};return t.jsxs("div",{onKeyDown:I,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:R?`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=y==null?void 0:y.onToggleMaximize)==null||W.call(y)},style:{display:"flex",height:dO,background:R?"#323a42":Ue.titleBg,borderBottom:`1px solid ${Ue.separator}`,flexShrink:0,overflowX:"auto",overflowY:"hidden"},children:[e.tabs.map(H=>{const W=a.get(H),K=H===e.activeTab,P=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,$=[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:Y=>{if(Y.button===0){if(y){m(H);return}Y.stopPropagation(),m(H),l(H,s,Y)}},style:{display:"flex",alignItems:"center",gap:6,padding:"0 6px 0 10px",fontFamily:Ot,fontSize:11,color:K?Ue.bright:Ue.titleText,background:K?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}${$?`
|
|
681
|
-
${$}`:""}`,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:P,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:Y=>Y.stopPropagation(),onClick:Y=>{Y.stopPropagation(),o(H)},"aria-label":"close-tab",title:_("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(Vt,{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:`${_("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(vn,{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(aO,{sessionId:e.activeTab,sendMessage:h}),t.jsx("button",{"data-no-drag":!0,onMouseDown:H=>H.stopPropagation(),onClick:D,"aria-label":"refresh-terminal",title:`${_("session.refresh")||"Refresh rendering"} (F5 · Ctrl+Shift+R) — ${_("session.refresh.hint")||"Rebuild the terminal view (PTY stays running)"}`,style:er,children:t.jsx(hN,{size:12})}),t.jsx("button",{"data-no-drag":!0,onMouseDown:H=>H.stopPropagation(),onClick:()=>E(-1),"aria-label":"decrease-font",title:`${_("session.fontDecrease")||"Decrease font size"} (${w}px) · Ctrl+- · Ctrl+wheel`,style:er,children:t.jsx(BN,{size:14})}),t.jsx("button",{"data-no-drag":!0,onMouseDown:H=>H.stopPropagation(),onClick:()=>E(1),"aria-label":"increase-font",title:`${_("session.fontIncrease")||"Increase font size"} (${w}px) · Ctrl+= · Ctrl+wheel`,style:er,children:t.jsx(zN,{size:14})}),t.jsx(rO,{sessionId:e.activeTab}),y&&t.jsxs(t.Fragment,{children:[e.tabs.length>1&&y.onApplyLayoutPreset&&t.jsxs(t.Fragment,{children:[t.jsx("button",{"data-no-drag":!0,onMouseDown:H=>H.stopPropagation(),onClick:()=>{var H;return(H=y.onApplyLayoutPreset)==null?void 0:H.call(y,"single")},"aria-label":"single-pane",title:_("session.layout.single"),style:er,children:t.jsx(Gi,{size:12})}),t.jsx("button",{"data-no-drag":!0,onMouseDown:H=>H.stopPropagation(),onClick:()=>{var H;return(H=y.onApplyLayoutPreset)==null?void 0:H.call(y,"columns")},"aria-label":"two-columns",title:_("session.layout.columns"),style:er,children:t.jsx(s1,{size:14})}),t.jsx("button",{"data-no-drag":!0,onMouseDown:H=>H.stopPropagation(),onClick:()=>{var H;return(H=y.onApplyLayoutPreset)==null?void 0:H.call(y,"grid")},"aria-label":"grid-layout",title:_("session.layout.grid"),style:er,children:t.jsx(i1,{size:14})})]}),y.onToggleMaximize&&t.jsx("button",{"data-no-drag":!0,onMouseDown:H=>H.stopPropagation(),onClick:y.onToggleMaximize,"aria-label":"toggle-maximize",title:`${y.isMaximized?_("session.restoreSize"):_("session.maximize")} · ${_("session.maximizeHint")}`,style:er,children:y.isMaximized?t.jsx(Cl,{size:14}):t.jsx(fi,{size:14})}),y.onPopOutGroup&&t.jsx("button",{"data-no-drag":!0,onMouseDown:H=>H.stopPropagation(),onClick:y.onPopOutGroup,"aria-label":"pop-out",title:`${_("session.popOut")||"Pop out to separate window"} (Ctrl+Shift+O)`,style:er,children:t.jsx(ar,{size:14})}),t.jsx("button",{"data-no-drag":!0,onMouseDown:H=>H.stopPropagation(),onClick:y.onMinimizeGroup,"aria-label":"minimize",title:`${_("session.minimize")||"Minimize"} (Ctrl+Shift+M)`,style:er,children:t.jsx(ap,{size:14})}),t.jsx("button",{"data-no-drag":!0,onMouseDown:H=>H.stopPropagation(),onClick:y.onCloseGroup,"aria-label":"close",title:`${_("session.close")||"Close"} (Ctrl+Shift+X)`,style:er,children:t.jsx(Vt,{size:14})})]})]}),t.jsx("div",{"data-group-id":i,"data-stack-path":s.join("."),ref:H=>{if(!H){p(s,null);return}const W=H.getBoundingClientRect();p(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 K=f[H]||{intent:"open",nonce:0};return t.jsx(yS,{session:W,visible:H===e.activeTab,intent:K.intent,intentNonce:K.nonce,onClose:()=>d(H),sendMessage:h,subscribeBinary:g,onEvent:b,onCycleTab:U,remountKey:T[H]||0},H)})})]})}const er={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 hO({orientation:e,onDragStart:s,onDrag:i,onDragEnd:a}){const u=S.useCallback(m=>{if(m.button!==0)return;m.preventDefault(),m.stopPropagation();const o=m.clientX,l=m.clientY;s();let d=!1;const p=()=>{d||(d=!0,window.removeEventListener("mousemove",C),window.removeEventListener("mouseup",k),window.removeEventListener("blur",h),window.removeEventListener("keydown",g),document.removeEventListener("visibilitychange",b))},h=()=>{p(),a()},g=x=>{x.key==="Escape"&&h()},b=()=>{document.hidden&&h()},C=x=>{const y=e==="horizontal"?x.clientX-o:x.clientY-l;i(y)},k=()=>{p(),a()};window.addEventListener("mousemove",C),window.addEventListener("mouseup",k),window.addEventListener("blur",h),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 Ip(e){const{node:s,path:i,onSplitSizes:a,...u}=e;return s.kind==="stack"?t.jsx(Pp,{stack:s,path:i,...u}):t.jsx(fO,{split:s,path:i,onSplitSizes:a,stackProps:u})}const Qy=80;function fO({split:e,path:s,onSplitSizes:i,stackProps:a}){const u=e.orientation==="horizontal",f=S.useRef(null),m=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((l,d)=>t.jsxs(S.Fragment,{children:[t.jsx("div",{ref:p=>{m.current[d]=p},style:{flex:`0 0 ${e.sizes[d]}%`,display:"flex",flexDirection:"column",minWidth:0,minHeight:0,overflow:"hidden"},children:t.jsx(Ip,{node:l,path:[...s,d],onSplitSizes:i,...a})}),d<e.children.length-1&&t.jsx(hO,{orientation:e.orientation,onDragStart:()=>{const p=f.current;if(!p)return;const h=e.sizes.slice();o.current={i:d,initialSizes:h,finalSizes:h.slice(),total:u?p.clientWidth:p.clientHeight}},onDrag:p=>{const h=o.current;if(!h||h.total<=0)return;const g=h.initialSizes[h.i]/100*h.total,b=h.initialSizes[h.i+1]/100*h.total,C=g+b,k=Math.max(Qy,Math.min(C-Qy,g+p)),x=C-k,y=k/h.total*100,_=x/h.total*100,w=m.current[h.i],E=m.current[h.i+1];w&&(w.style.flexBasis=`${y}%`),E&&(E.style.flexBasis=`${_}%`);const T=h.initialSizes.slice();T[h.i]=y,T[h.i+1]=_,h.finalSizes=T},onDragEnd:()=>{const p=o.current;p&&i(s,p.finalSizes),o.current=null}})]},d))})}const Et=28,un=68;function Zu(e,s,i){const a=e-i.x,u=s-i.y;if(a<0||u<0||a>i.w||u>i.h)return null;const f=a-i.w/2,m=u-i.h/2;return Math.abs(f)<=Et&&Math.abs(m)<=Et?"center":f>=-un-Et&&f<=-un+Et&&Math.abs(m)<=Et?"left":f>=un-Et&&f<=un+Et&&Math.abs(m)<=Et?"right":m>=-un-Et&&m<=-un+Et&&Math.abs(f)<=Et?"top":m>=un-Et&&m<=un+Et&&Math.abs(f)<=Et?"bottom":null}function Tu(e,s){const i=document.elementsFromPoint(e,s);for(const a of i){const u=a.closest("[data-group-id][data-stack-path]");if(!u)continue;const f=u.dataset.stackPath||"",m=f===""?[]:f.split(".").map(Number),o=u.getBoundingClientRect(),l={x:o.left,y:o.top,w:o.width,h:o.height};return{groupId:u.dataset.groupId||"",path:m,rect:l,zone:Zu(e,s,l)}}return null}function mO(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 Hm=un*2+12;function _S(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>=-Hm-Et&&f<=-Hm+Et&&Math.abs(u)<=Et?"popout":null}function SS(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 SS(e,u,s,i,a)}function Ha(){const e=document.querySelector("[data-app-sidebar]");return Math.max(0,e?e.getBoundingClientRect().right:0)}function kS({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-Hm-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?mO(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",m=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 ${m}`,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(pO,{kind:a,fill:f})})}function pO({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(ar,{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 Lr(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 ed(e,s){if(e.kind==="stack")return e.tabs.includes(s)?[]:null;for(let i=0;i<e.children.length;i++){const a=ed(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 Ru(e){return e.kind==="stack"?[e.activeTab]:e.children.flatMap(Ru)}function gO(e,s){const i=gn(e);if(i.length<=1||s==="single")return Lr(i,Ru(e)[0]||i[0]);const a=Math.min(s==="columns"?2:4,i.length),u=Array.from({length:a},()=>[]);i.forEach((h,g)=>u[g%a].push(h));const f=new Set(Ru(e)),m=u.map(h=>Lr(h,h.find(g=>f.has(g))||h[0]));if(s==="columns"||m.length<=2)return{kind:"split",orientation:"horizontal",children:m,sizes:m.map(()=>100/m.length)};const o=m.slice(0,2),l=m.slice(2),d=h=>h.length===1?h[0]:{kind:"split",orientation:"horizontal",children:h,sizes:h.map(()=>100/h.length)};return{kind:"split",orientation:"vertical",children:[d(o),d(l)],sizes:[50,50]}}function Wi(e,s){return CS(e,s)}function CS(e,s){if(e.kind==="stack"){if(!e.tabs.includes(s))return e;const f=e.tabs.filter(o=>o!==s);if(f.length===0)return null;const m=e.activeTab===s?f[0]:e.activeTab;return{kind:"stack",tabs:f,activeTab:m}}const i=[],a=[];for(let f=0;f<e.children.length;f++){const m=CS(e.children[f],s);m!==null&&(i.push(m),a.push(e.sizes[f]))}if(i.length===0)return null;if(i.length===1)return i[0];const u=a.reduce((f,m)=>f+m,0)||1;return{kind:"split",orientation:e.orientation,children:i,sizes:a.map(f=>f/u*100)}}function $i(e,s,i){return td(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 td(e,s,m=>({kind:"split",orientation:u,children:f?[a,m]:[m,a],sizes:[50,50]}))}function td(e,s,i){if(s.length===0)return Mu(i(e));if(e.kind!=="split")throw new Error("replaceAt: path traverses non-split");const[a,...u]=s;if(a<0||a>=e.children.length)throw new Error("replaceAt: bad path");const f=e.children.map((m,o)=>o===a?td(m,u,i):m);return Mu({...e,children:f})}function Mu(e){if(e.kind==="stack")return e;const s=e.children.map(Mu),i=[],a=[];for(let f=0;f<s.length;f++){const m=s[f],o=e.sizes[f]??100/s.length;if(m.kind==="split"&&m.orientation===e.orientation){const l=m.sizes.reduce((d,p)=>d+p,0)||1;for(let d=0;d<m.children.length;d++)i.push(m.children[d]),a.push(m.sizes[d]/l*o)}else i.push(m),a.push(o)}if(i.length===1)return i[0];const u=a.reduce((f,m)=>f+m,0)||1;return{kind:"split",orientation:e.orientation,children:i,sizes:a.map(f=>f/u*100)}}function 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 jS(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=>jS(a,s,i))}}function ES(e,s,i){return td(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 xO(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(d=>d!==s);if(!f)return null;const m=Wi(e,s);if(!m)return null;const o=ed(m,f);if(!o)return null;const l=a==="center"?$i(m,o,s):$a(m,o,a,Lr([s]));return Ps(l,s)}function vO(e,s){const i=gn(e);let a=e;for(const u of i){if(!a)break;s.has(u)||(a=Wi(a,u))}return a}const tu=320,nu=200,su=80,ru=22,bO=4,Zy=8,ii=10,iu=60,yO=12;function ai(e,s,i){return Math.max(s,Math.min(i,e))}function wO(e,s,i,a){const u=e<=Zy,f=e>=i-Zy;if(!u&&!f)return null;const m=a/3,o=a*2/3;return u?s<m?"top-left":s>o?"bottom-left":"left":s<m?"top-right":s>o?"bottom-right":"right"}function ew(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 _O(e,s,i,a,u){let f=e,m=s;const o=f,l=f+i,d=m,p=m+a;for(const h of u){const g=h.x,b=h.x+h.w,C=h.y,k=h.y+h.h;d<k&&p>C&&(Math.abs(o-b)<=ii?f=b:Math.abs(l-g)<=ii?f=g-i:Math.abs(o-g)<=ii?f=g:Math.abs(l-b)<=ii&&(f=b-i)),o<b&&l>g&&(Math.abs(d-k)<=ii?m=k:Math.abs(p-C)<=ii?m=C-a:Math.abs(d-C)<=ii?m=C:Math.abs(p-k)<=ii&&(m=k-a))}return{x:f,y:m}}function SO({group:e,sessionsById:s,neighbors:i,isTopmost:a,zIndex:u,sendMessage:f,subscribeBinary:m,onEvent:o}){const{t:l}=ht(),d=tS("(max-width: 767px)"),p=RS(),h=S.useRef(null),[g,b]=S.useState(!1),C=S.useRef(null),[k,x]=S.useState(null),y=S.useRef({x:e.x,y:e.y,w:e.w,h:e.h});y.current={x:e.x,y:e.y,w:e.w,h:e.h};const[_,w]=S.useState(null),E=S.useRef(null),[T,j]=S.useState(!1),[D,N]=S.useState(null),R=S.useRef(null),A=S.useRef(i);A.current=i;const[B,O]=S.useState(null),F=S.useRef(null),U=S.useCallback((ae,De)=>{if(d||g||ae.button!==0||ae.target.closest("[data-no-drag]"))return;ae.preventDefault(),p.focus(gn(e.root)[0]||"");const ve=ae.clientX,Me=ae.clientY,Oe={...y.current},tt=h.current,nt=window.innerWidth,ke=window.innerHeight,fe=Ha();let Te=!1,Ce="";De&&tt&&(Ce=tt.style.pointerEvents,tt.style.pointerEvents="none");let Ke=!1;const Ze=()=>{Ke||(Ke=!0,window.removeEventListener("mousemove",X),window.removeEventListener("mouseup",me),window.removeEventListener("blur",ye),window.removeEventListener("keydown",Be),document.removeEventListener("visibilitychange",Z),De&&tt&&(tt.style.pointerEvents=Ce))},ye=()=>{Ze(),F.current=null,O(null),E.current=null,w(null),R.current=null,N(null),j(!1),p.setGroupGeometry(e.id,{...y.current})},Be=se=>{se.key==="Escape"&&ye()},Z=()=>{document.hidden&&ye()};let _e=!1;const X=se=>{if(_e)return;{const qe=window.screenX,Ee=window.screenY,st=qe+window.outerWidth,lt=Ee+window.outerHeight;if(se.screenX<qe-iu||se.screenX>st+iu||se.screenY<Ee-iu||se.screenY>lt+iu){_e=!0,Ze(),F.current=null,O(null),E.current=null,w(null),R.current=null,N(null),j(!1),p.setGroupGeometry(e.id,{...y.current}),p.popOutGroup(e.id,{atScreenX:se.screenX,atScreenY:se.screenY});return}}const ie=se.clientX-ve,J=se.clientY-Me;let ee=ai(Oe.x+ie,-(Oe.w-su),nt-su),pe=ai(Oe.y+J,0,ke-ru);const we=A.current;if(we.length>0){const qe=_O(ee,pe,Oe.w,Oe.h,we);ee=qe.x,pe=qe.y}if(tt&&(tt.style.left=`${ee}px`,tt.style.top=`${pe}px`),y.current.x=ee,y.current.y=pe,De){let qe=null;const Ee=document.elementFromPoint(se.clientX,se.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:Zu(se.clientX,se.clientY,dt)}}}F.current=qe,O(qe?{rect:qe.rect,zone:qe.zone}:null)}!Te&&Math.hypot(se.clientX-ve,se.clientY-Me)>=yO&&(Te=!0,j(!0),e.dock&&p.setGroupDock(e.id,null));const je=De&&F.current&&F.current.zone,$e=je||!Te?null:_S(se.clientX,se.clientY,nt,ke);$e!==R.current&&(R.current=$e,N($e));const Je=je||$e?null:wO(se.clientX,se.clientY,nt,ke);Je!==E.current&&(E.current=Je,w(Je))},me=se=>{Ze(),j(!1);const ie=R.current;if(R.current=null,N(null),De&&F.current&&F.current.zone){const ee=F.current;p.dockGroup(e.id,ee.groupId,ee.path,ee.zone),F.current=null,O(null),E.current=null,w(null);return}if(ie==="popout"){F.current=null,O(null),E.current=null,w(null),p.setGroupGeometry(e.id,{...y.current}),p.popOutGroup(e.id,{atScreenX:se.screenX,atScreenY:se.screenY});return}if(ie&&ie!=="max"){const ee=vl(ie,nt,ke,fe);tt&&(tt.style.left=`${ee.x}px`,tt.style.top=`${ee.y}px`,tt.style.width=`${ee.w}px`,tt.style.height=`${ee.h}px`),y.current=ee,F.current=null,O(null),E.current=null,w(null),p.setGroupDock(e.id,ie);return}const J=ie?vl(ie,nt,ke,fe):E.current?ew(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`),y.current=J,E.current=null,w(null)),F.current=null,O(null),p.setGroupGeometry(e.id,{...y.current})};window.addEventListener("mousemove",X),window.addEventListener("mouseup",me),window.addEventListener("blur",ye),window.addEventListener("keydown",Be),document.addEventListener("visibilitychange",Z)},[d,g,p,e.id,e.root,e.dock]),I=S.useCallback(ae=>U(ae,!1),[U]),H=S.useCallback(ae=>U(ae,!0),[U]),W=S.useCallback(ae=>De=>{if(d||g||De.button!==0)return;De.preventDefault(),De.stopPropagation();const Re=De.clientX,ve=De.clientY,Me={...y.current},Oe=h.current,tt=window.innerWidth,nt=window.innerHeight,ke=Be=>{const Z=Be.clientX-Re,_e=Be.clientY-ve;let X=Me.x,me=Me.y,se=Me.w,ie=Me.h;ae.includes("e")?se=ai(Me.w+Z,tu,Math.max(tu,tt-Me.x)):ae.includes("w")&&(X=ai(Me.x+Z,0,Me.x+Me.w-tu),se=Me.x+Me.w-X),ae.includes("s")?ie=ai(Me.h+_e,nu,Math.max(nu,nt-Me.y)):ae.includes("n")&&(me=ai(Me.y+_e,0,Me.y+Me.h-nu),ie=Me.y+Me.h-me),Oe&&(Oe.style.left=`${X}px`,Oe.style.top=`${me}px`,Oe.style.width=`${se}px`,Oe.style.height=`${ie}px`),y.current={x:X,y:me,w:se,h:ie}};let fe=!1;const Te=()=>{fe||(fe=!0,window.removeEventListener("mousemove",ke),window.removeEventListener("mouseup",ye),window.removeEventListener("blur",Ce),window.removeEventListener("keydown",Ke),document.removeEventListener("visibilitychange",Ze))},Ce=()=>{Te(),p.setGroupGeometry(e.id,{...y.current})},Ke=Be=>{Be.key==="Escape"&&Ce()},Ze=()=>{document.hidden&&Ce()},ye=()=>{Te(),p.setGroupGeometry(e.id,{...y.current})};window.addEventListener("mousemove",ke),window.addEventListener("mouseup",ye),window.addEventListener("blur",Ce),window.addEventListener("keydown",Ke),document.addEventListener("visibilitychange",Ze)},[d,g,p,e.id]);S.useEffect(()=>{if(d||e.dock)return;const ae=()=>{const De=window.innerWidth,Re=window.innerHeight,ve=y.current,Me=ai(ve.x,-(ve.w-su),De-su),Oe=ai(ve.y,0,Re-ru);(Me!==ve.x||Oe!==ve.y)&&p.setGroupGeometry(e.id,{...ve,x:Me,y:Oe})};return window.addEventListener("resize",ae),()=>window.removeEventListener("resize",ae)},[d,p,e.id,e.dock]);const K=S.useCallback(ae=>{x(ae),p.setActiveTab(e.id,ae),p.focus(ae)},[p,e.id]),P=S.useCallback(ae=>{x(ae),p.focus(ae)},[p]),z=S.useCallback(ae=>{p.close(ae)},[p]),$=S.useCallback((ae,De,Re)=>{p.beginTabDrag(e.id,ae,De,Re)},[p,e.id]),Y=S.useCallback(ae=>{p.close(ae)},[p]),q=S.useCallback((ae,De)=>{p.setSplitSizes(e.id,ae,De)},[p,e.id]),oe=Ru(e.root),ce=gn(e.root);S.useEffect(()=>{k&&ce.includes(k)||x(oe[0]||ce[0]||null)},[k,oe,ce]);const ne=S.useCallback(()=>{if(g){const ae=C.current;ae&&p.setGroupGeometry(e.id,ae),C.current=null,b(!1);return}C.current={...y.current},e.dock&&p.setGroupDock(e.id,null),p.setGroupGeometry(e.id,{x:6,y:6,w:Math.max(tu,window.innerWidth-12),h:Math.max(nu,window.innerHeight-12)}),b(!0)},[p,e.id,g,e.dock]),te=ae=>{const De=/Mac|iPhone|iPad|iPod/.test(navigator.platform),Re=De?ae.metaKey:ae.ctrlKey,ve=De?ae.ctrlKey:ae.metaKey;if(!Re||ve||ae.altKey||!ae.shiftKey)return;const Me=ae.key.toLowerCase();Me==="o"?(ae.preventDefault(),p.popOutGroup(e.id)):Me==="m"?(ae.preventDefault(),p.minimizeGroup(e.id)):Me==="x"&&(ae.preventDefault(),p.closeGroup(e.id))};if(d){const ae=oe[0],De=ae?s.get(ae):null;if(!De)return null;const Re=e.intents[ae]??{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:ru,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:()=>p.closeGroup(e.id),style:oi,"aria-label":"close",children:t.jsx(Vt,{size:14})})]}),t.jsx("div",{style:{flex:1,position:"relative",minHeight:0},children:t.jsx(yS,{session:De,visible:!0,intent:Re.intent,intentNonce:Re.nonce,onClose:()=>p.close(ae),sendMessage:f,subscribeBinary:m,onEvent:o})})]}),document.body)}const G=_?(()=>{const ae=window.innerWidth,De=window.innerHeight,Re=ew(_,ae,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,de=(()=>{var De;if(ce.length===0)return"";const ae=((De=s.get(ce[0]))==null?void 0:De.title)||ce[0];return ce.length===1?ae:`${ae} +${ce.length-1}`})(),he=e.root.kind==="split",be=rn.createPortal(t.jsxs("div",{ref:h,onKeyDown:te,onMouseDown:he?()=>p.focus(ce[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:[he&&t.jsxs("div",{onMouseDown:I,onDoubleClick:ae=>{ae.target.closest("button")||ne()},style:{height:ru,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:bO,flexShrink:0},children:oe.map((ae,De)=>t.jsx("div",{style:{flex:1,background:e.colors[ae]||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:de}),ce.length>1&&t.jsxs(t.Fragment,{children:[t.jsx("button",{"data-no-drag":!0,onMouseDown:ae=>ae.stopPropagation(),onClick:()=>p.applyLayoutPreset(e.id,"single"),style:oi,"aria-label":"single-pane",title:l("session.layout.single"),children:t.jsx(Gi,{size:12})}),t.jsx("button",{"data-no-drag":!0,onMouseDown:ae=>ae.stopPropagation(),onClick:()=>p.applyLayoutPreset(e.id,"columns"),style:oi,"aria-label":"two-columns",title:l("session.layout.columns"),children:t.jsx(s1,{size:14})}),t.jsx("button",{"data-no-drag":!0,onMouseDown:ae=>ae.stopPropagation(),onClick:()=>p.applyLayoutPreset(e.id,"grid"),style:oi,"aria-label":"grid-layout",title:l("session.layout.grid"),children:t.jsx(i1,{size:14})})]}),t.jsx("button",{"data-no-drag":!0,onMouseDown:ae=>ae.stopPropagation(),onClick:ne,style:oi,"aria-label":"toggle-maximize",title:`${l(g?"session.restoreSize":"session.maximize")} · ${l("session.maximizeHint")}`,children:g?t.jsx(Cl,{size:14}):t.jsx(fi,{size:14})}),t.jsx("button",{"data-no-drag":!0,onMouseDown:ae=>ae.stopPropagation(),onClick:()=>p.popOutGroup(e.id),style:oi,"aria-label":"pop-out",title:`${l("session.popOut")||"Pop out to separate window"} (Ctrl+Shift+O)`,children:t.jsx(ar,{size:14})}),t.jsx("button",{"data-no-drag":!0,onClick:()=>p.minimizeGroup(e.id),style:oi,"aria-label":"minimize",title:`${l("session.minimize")||"Minimize"} (Ctrl+Shift+M)`,children:t.jsx(ap,{size:14})}),t.jsx("button",{"data-no-drag":!0,onClick:()=>p.closeGroup(e.id),style:oi,"aria-label":"close",title:`${l("session.close")||"Close"} (Ctrl+Shift+X)`,children:t.jsx(Vt,{size:14})})]})]}),t.jsx("div",{style:{flex:1,display:"flex",minHeight:0,minWidth:0},children:e.root.kind==="split"?t.jsx(Ip,{node:e.root,path:[],groupId:e.id,sessionsById:s,colors:e.colors,intents:e.intents,onTabClick:K,onTabClose:z,onTabMouseDown:$,onPaneAutoClose:Y,registerRect:()=>{},onSplitSizes:q,sendMessage:f,subscribeBinary:m,onEvent:o,focusedSessionId:k||void 0,groupTopmost:a,onFocusStack:P}):t.jsx(Pp,{stack:e.root,path:[],groupId:e.id,sessionsById:s,colors:e.colors,intents:e.intents,onTabClick:K,onTabClose:z,onTabMouseDown:$,onPaneAutoClose:Y,registerRect:()=>{},sendMessage:f,subscribeBinary:m,onEvent:o,focusedSessionId:k||void 0,groupTopmost:a,onFocusStack:P,groupActions:{onMinimizeGroup:()=>p.minimizeGroup(e.id),onCloseGroup:()=>p.closeGroup(e.id),onPopOutGroup:()=>p.popOutGroup(e.id),onToggleMaximize:ne,isMaximized:g,onApplyLayoutPreset:ae=>p.applyLayoutPreset(e.id,ae)}})}),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:[be,G,T&&!(B!=null&&B.zone)&&t.jsx(kS,{activeZone:D}),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},Jf=["#3b82f6","#22c55e","#eab308","#ef4444","#a855f7","#06b6d4","#f97316","#ec4899"];function Hi(e){for(const s of Jf)if(!e.includes(s))return s;return Jf[e.length%Jf.length]}const kO="clitrigger:session-windows:global";function Fp(){if(typeof BroadcastChannel>"u")return{post:()=>{},subscribe:()=>()=>{},close:()=>{}};const e=new BroadcastChannel(kO),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 Pt="main",$m=new Map;function CO(e,s){$m.set(e,s)}function jO(e){const s=$m.get(e);if(!s||s.closed)return $m.delete(e),!1;try{return s.focus(),!0}catch{return!1}}function EO(){return`popout_${Math.random().toString(36).slice(2,10)}_${Date.now().toString(36)}`}const Hp=5e3,NS=15e3;let Ia=null;function LS(){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 Au(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 zu(e){return e.x>=0&&e.y>=0&&e.x<=window.innerWidth&&e.y<=window.innerHeight}const Um="clitrigger:popout-alive:";function NO(e){return`${Um}${e}`}function $p(){return typeof navigator<"u"&&!!navigator.locks&&typeof navigator.locks.query=="function"}function LO(e){if(!$p())return()=>{};let s=()=>{};return navigator.locks.request(NO(e),()=>new Promise(i=>{s=i})).catch(()=>{}),()=>s()}async function DS(){var e;if(!$p())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(Um)&&i.add(a.name.slice(Um.length));return i}catch{return new Set}}const Up=S.createContext(null),TS=S.createContext({});function RS(){const e=S.useContext(Up);if(!e)throw new Error("useSessionWindows must be used within SessionWindowsHost");return e}function DO(){return S.useContext(TS)}function TO(){return S.useContext(Up)}const Ou=720,Wp=460,RO=320,MO=200,tw=30,MS=80,AS=80,dl=80,Wm=28;function AO(e){const s=typeof window<"u"?window.innerWidth:1280,i=typeof window<"u"?window.innerHeight:800;let a=Number.isFinite(e.w)&&e.w>=RO?e.w:Ou,u=Number.isFinite(e.h)&&e.h>=MO?e.h:Wp;a=Math.min(a,s),u=Math.min(u,i);let f=Number.isFinite(e.x)?e.x:MS,m=Number.isFinite(e.y)?e.y:AS;return f=Math.max(Math.min(f,s-dl),-(a-dl)),m=Math.max(Math.min(m,i-Wm),0),{x:f,y:m,w:a,h:u}}const nw=12,au=60;function zS(e){return`sessionGroups:${e}`}function gu(e){try{const s=localStorage.getItem(zS(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 qm(e,s){try{localStorage.setItem(zS(e),JSON.stringify(s))}catch{}}function zO(e,s){const i=gu(e);!i||!i.groups.some(a=>a.id===s)||(qm(e,{...i,groups:i.groups.filter(a=>a.id!==s)}),window.dispatchEvent(new CustomEvent("session-windows:changed")))}function OO(e){const s=e%8;return{x:MS+s*tw,y:AS+s*tw,w:Ou,h:Wp}}function ou(e,s,i){return Math.max(s,Math.min(i,e))}function sw(){return`g_${Math.random().toString(36).slice(2,10)}_${Date.now().toString(36)}`}function li(e,s){for(const i of e)if(ed(i.root,s))return i;return null}function BO({projectId:e,sessions:s,sendMessage:i,subscribeBinary:a,onEvent:u,onAddSession:f,children:m}){const{t:o}=ht(),{warning:l}=Ls(),{confirm:d}=qn(),[p]=S.useState(()=>{const se=gu(e);if(!se)return{groups:[],zCounter:0};const ie=se.groups.map(J=>{const ee=gn(J.root),pe=new Set(ee),we={};for(const qe of Object.keys(J.colors||{}))pe.has(qe)&&(we[qe]=J.colors[qe]);const je={};for(const qe of ee)je[qe]={intent:"open",nonce:0},we[qe]||(we[qe]=Hi(Object.values(we)));const $e=AO({x:J.x,y:J.y,w:J.w,h:J.h}),Je=J.ownerWindowId||Pt;return{...J,...$e,colors:we,intents:je,minimized:!!J.minimized,ownerWindowId:Je}});return{groups:ie,zCounter:se.zCounter||ie.length}}),[h,g]=S.useState(p.groups),b=S.useRef(p.zCounter),C=S.useRef(h);C.current=h;const k=S.useRef(s);k.current=s;const[x,y]=S.useState(null),_=S.useRef(null);_.current=x;const[w,E]=S.useState({}),T=S.useRef(w);T.current=w,S.useEffect(()=>{var ee;const se={},ie=((ee=gu(e))==null?void 0:ee.sessionProjects)??{},J={};for(const pe of h)for(const we of gn(pe.root)){const je=s.find(Je=>Je.id===we)||w[we];je!=null&&je.title&&(se[we]=je.title);const $e=(je==null?void 0:je.project_id)||ie[we];$e&&(J[we]=$e)}qm(e,{groups:h,zCounter:b.current,titles:se,sessionProjects:J}),window.dispatchEvent(new CustomEvent("session-windows:changed"))},[e,h,s,w]),S.useEffect(()=>()=>{var je;const se=C.current;if(se.length===0)return;let ie=!1;const J=se.map($e=>($e.ownerWindowId||Pt)!==Pt||$e.minimized?$e:(ie=!0,{...$e,minimized:!0}));if(!ie)return;const ee={},pe=((je=gu(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)||T.current[Je];qe!=null&&qe.title&&(ee[Je]=qe.title);const Ee=(qe==null?void 0:qe.project_id)||pe[Je];Ee&&(we[Je]=Ee)}qm(e,{groups:J,zCounter:b.current,titles:ee,sessionProjects:we}),window.dispatchEvent(new CustomEvent("session-windows:changed"))},[e]),S.useEffect(()=>{const se=document.documentElement.style,ie={left:0,right:0,top:0,bottom:0};for(const J of h)!J.dock||J.minimized||(J.ownerWindowId||Pt)!==Pt||(J.dock==="left"?ie.left=Math.max(ie.left,J.x+J.w-Ha()):J.dock==="right"?ie.right=Math.max(ie.right,window.innerWidth-J.x):J.dock==="top"?ie.top=Math.max(ie.top,J.y+J.h):ie.bottom=Math.max(ie.bottom,window.innerHeight-J.y));for(const J of["left","right","top","bottom"])se.setProperty(`--dock-inset-${J}`,`${Math.max(0,Math.round(ie[J]))}px`);return()=>{for(const J of["left","right","top","bottom"])se.removeProperty(`--dock-inset-${J}`)}},[h]),S.useEffect(()=>{const se=()=>{const ee=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=SS(qe.dock,Ee,ee,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})};se();const ie=document.querySelector("main"),J=ie?new ResizeObserver(se):null;return ie&&J&&J.observe(ie),window.addEventListener("resize",se),()=>{J==null||J.disconnect(),window.removeEventListener("resize",se)}},[]);const[j,D]=S.useState(()=>new Set),N=S.useRef(new Set);S.useEffect(()=>{if(s.length===0)return;const se=s.filter(J=>J.project_id===e);if(se.length===0)return;const ie=new Set(se.map(J=>J.id));for(const J of h)for(const ee of gn(J.root))ie.has(ee)||w[ee]||j.has(ee)||N.current.has(ee)||(N.current.add(ee),F1(ee).then(pe=>E(we=>({...we,[ee]:pe}))).catch(pe=>{pe instanceof vu&&pe.status===404&&D(we=>new Set(we).add(ee))}).finally(()=>N.current.delete(ee)))},[h,s,e,w,j]),S.useEffect(()=>u(ie=>{ie.type!=="session:status-changed"||!ie.sessionId||E(J=>{const ee=J[ie.sessionId];if(!ee)return J;const pe={status:ie.status};return ie.worktree_path!==void 0&&(pe.worktree_path=ie.worktree_path),ie.branch_name!==void 0&&(pe.branch_name=ie.branch_name),{...J,[ee.id]:{...ee,...pe}}})}),[u]),S.useEffect(()=>{j.size!==0&&g(se=>{let ie=!1;const J=[];for(const ee of se){const pe=gn(ee.root);if(!pe.some(Ee=>j.has(Ee))){J.push(ee);continue}ie=!0;const we=new Set(pe.filter(Ee=>!j.has(Ee))),je=vO(ee.root,we);if(!je)continue;const $e=new Set(gn(je)),Je={};for(const Ee of Object.keys(ee.colors))$e.has(Ee)&&(Je[Ee]=ee.colors[Ee]);const qe={};for(const Ee of Object.keys(ee.intents))$e.has(Ee)&&(qe[Ee]=ee.intents[Ee]);J.push({...ee,root:je,colors:Je,intents:qe})}return ie?J:se})},[j]);const R=S.useCallback((se,ie)=>{const J=C.current.length,ee=OO(J);b.current+=1;const pe=b.current;return{id:sw(),...ee,z:pe,minimized:!1,root:Lr([se],se),colors:{[se]:Hi([])},intents:{[se]:{intent:ie,nonce:0}},ownerWindowId:Pt}},[]),A=S.useCallback((se,ie="open")=>{g(J=>{const ee=li(J,se);b.current+=1;const pe=b.current;return ee?J.map(we=>{var Ee,st,lt;if(we.id!==ee.id)return we;const je=((Ee=we.intents[se])==null?void 0:Ee.intent)??"open",$e=ie==="start"||ie==="resume",Je=$e?ie:je,qe=Je!==je||$e;return{...we,z:pe,minimized:!1,root:Ps(we.root,se),intents:{...we.intents,[se]:{intent:Je,nonce:qe?(((st=we.intents[se])==null?void 0:st.nonce)??0)+1:((lt=we.intents[se])==null?void 0:lt.nonce)??0}}}}):[...J,R(se,ie)]})},[R]),B=S.useCallback(se=>{g(ie=>{const J=li(ie,se);if(!J)return ie;const ee=ie.reduce((we,je)=>je.z>we?je.z:we,0);if(J.z===ee&&!J.minimized)return ie;b.current+=1;const pe=b.current;return ie.map(we=>we.id===J.id?{...we,z:pe,minimized:!1}:we)})},[]),O=S.useCallback(async se=>{const ie=se.map(J=>k.current.find(ee=>ee.id===J)||T.current[J]).filter(J=>!!J&&J.status==="running");if(ie.length===0)return!0;if(!await d({message:o("session.confirmStop"),danger:!0}))return!1;for(const J of ie)Cu(J.id).catch(()=>{});return!0},[o,d]),F=S.useCallback(async se=>{await O([se])&&g(ie=>{const J=li(ie,se);if(!J)return ie;const ee=Wi(J.root,se);if(!ee)return ie.filter(je=>je.id!==J.id);new Set(gn(ee));const pe={...J.colors};delete pe[se];const we={...J.intents};return delete we[se],ie.map(je=>je.id===J.id?{...je,root:ee,colors:pe,intents:we}:je)})},[O]),U=S.useCallback(se=>{g(ie=>{const J=li(ie,se);return J?ie.map(ee=>ee.id===J.id?{...ee,minimized:!0}:ee):ie})},[]),I=S.useCallback(se=>{g(ie=>{const J=li(ie,se);if(!J)return ie;b.current+=1;const ee=b.current;return ie.map(pe=>pe.id===J.id?{...pe,minimized:!1,z:ee}:pe)})},[]),H=S.useCallback(se=>!!li(C.current,se),[]),W=S.useCallback(async se=>{const ie=C.current.find(J=>J.id===se);ie&&!await O(gn(ie.root))||g(J=>J.filter(ee=>ee.id!==se))},[O]),K=S.useCallback(se=>{g(ie=>ie.map(J=>J.id===se?{...J,minimized:!0}:J))},[]);S.useEffect(()=>{const se=J=>{const ee=J.detail;!(ee!=null&&ee.projectId)||!ee.groupId||ee.projectId===e&&g(pe=>{if(!pe.find($e=>$e.id===ee.groupId))return pe;b.current+=1;const je=b.current;return pe.map($e=>$e.id===ee.groupId?{...$e,minimized:!1,z:je}:$e)})},ie=async J=>{var je;const ee=J.detail;if(!(ee!=null&&ee.projectId)||!ee.groupId||ee.projectId!==e)return;const pe=C.current.find($e=>$e.id===ee.groupId);if(pe&&!await O(gn(pe.root)))return;const we=(pe==null?void 0:pe.ownerWindowId)||Pt;we!==Pt&&(he.current.delete(we),Me.current.delete(ee.groupId),(je=de.current)==null||je.post({t:"group-reclaimed",popoutId:we,groupIds:[ee.groupId],reason:"late-return"})),g($e=>$e.filter(Je=>Je.id!==ee.groupId))};return window.addEventListener("session-windows:restore",se),window.addEventListener("session-windows:close",ie),()=>{window.removeEventListener("session-windows:restore",se),window.removeEventListener("session-windows:close",ie)}},[e,O]),S.useEffect(()=>{const se=sessionStorage.getItem("pendingSessionRestore");if(se)try{const ie=JSON.parse(se);if(ie.projectId!==e||!ie.groupId)return;sessionStorage.removeItem("pendingSessionRestore"),g(J=>{if(!J.find(we=>we.id===ie.groupId))return J;b.current+=1;const pe=b.current;return J.map(we=>we.id===ie.groupId?{...we,minimized:!1,z:pe}:we)})}catch{}},[e]);const P=S.useCallback(se=>{g(ie=>{if(!ie.find(pe=>pe.id===se))return ie;b.current+=1;const ee=b.current;return ie.map(pe=>pe.id===se?{...pe,minimized:!1,z:ee}:pe)})},[]),z=S.useCallback((se,ie)=>{g(J=>J.map(ee=>ee.id===se?{...ee,...ie}:ee))},[]),$=S.useCallback((se,ie)=>{g(J=>J.map(ee=>{if(ee.id===se){if(!ie)return ee.dock?{...ee,dock:void 0}:ee;const pe=vl(ie,window.innerWidth,window.innerHeight,Ha());return{...ee,...pe,dock:ie}}return ie&&ee.dock===ie?{...ee,dock:void 0}:ee}))},[]),Y=S.useCallback((se,ie,J)=>{g(ee=>ee.map(pe=>pe.id===se?{...pe,root:ES(pe.root,ie,J)}:pe))},[]),q=S.useCallback((se,ie)=>{g(J=>J.map(ee=>ee.id===se?{...ee,root:Ps(ee.root,ie)}:ee))},[]),oe=S.useCallback((se,ie)=>{g(J=>J.map(ee=>ee.id===se?{...ee,root:gO(ee.root,ie)}:ee))},[]),ce=S.useCallback((se,ie,J)=>{g(ee=>ee.map(pe=>pe.id===se?{...pe,root:jS(pe.root,ie,J)}:pe))},[]),ne=S.useCallback((se,ie,J,ee)=>{if(ee.button!==0||!C.current.find(gt=>gt.id===se))return;ee.preventDefault();const we=ee.clientX,je=ee.clientY;let $e=null;y({groupId:se,sessionId:ie,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=sw();$e=Tt;const Xe=window.innerWidth,ut=window.innerHeight,Q={x:ou(gt-60,-Ou+dl,Xe-dl),y:ou(vt-12,0,ut-Wm),w:Ou,h:Wp};g(ze=>{const ue=ze.find(Ct=>Ct.id===se);if(!ue)return ze;const Fe=Wi(ue.root,ie),Ve=ue.colors[ie]||Hi([]),ft=ue.intents[ie]??{intent:"open",nonce:0};b.current+=1;const Ne=b.current,at={id:Tt,...Q,z:Ne,minimized:!1,root:Lr([ie],ie),colors:{[ie]:Ve},intents:{[ie]:ft},ownerWindowId:Pt},bt=[];for(const Ct of ze)if(Ct.id===se){if(Fe){const Gt=new Set(gn(Fe)),an={};for(const bn of Object.keys(Ct.colors))Gt.has(bn)&&(an[bn]=Ct.colors[bn]);const Pn={};for(const bn of Object.keys(Ct.intents))Gt.has(bn)&&(Pn[bn]=Ct.intents[bn]);bt.push({...Ct,root:Mu(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-au||gt.screenX>Xe+au||gt.screenY<Tt-au||gt.screenY>ut+au},st=gt=>{if(qe)return;const vt=_.current;if(!vt)return;if(!$e)Math.hypot(gt.clientX-we,gt.clientY-je)>=nw&&Je(gt.clientX,gt.clientY);else{const Fe=window.innerWidth,Ve=window.innerHeight,ft=ou(gt.clientX-60,-640,Fe-dl),Ne=ou(gt.clientY-12,0,Ve-Wm);g(at=>at.map(bt=>bt.id===$e?{...bt,x:ft,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(),y(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 ft=Ve.dataset.groupId||"",Ne=Ve.dataset.stackPath||"";if($e?ft===$e:ft===vt.groupId&&Ne===vt.fromPath.join("."))continue;const bt=Ne===""?[]:Ne.split(".").map(Number),Ct=Ve.getBoundingClientRect();Tt=ft,Xe=bt,ut={x:Ct.left,y:Ct.top,w:Ct.width,h:Ct.height},Q=Zu(gt.clientX,gt.clientY,ut);break}const ue=Q||!$e?null:_S(gt.clientX,gt.clientY,window.innerWidth,window.innerHeight);y({...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(),y(null)},pt=gt=>{gt.key==="Escape"&&mt()},dt=()=>{document.hidden&&mt()},kt=gt=>{var Xe;yt();const vt=_.current;if(y(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 $(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((se,ie,J,ee,pe)=>{g(we=>{const je=we.find(pt=>pt.id===se),$e=we.find(pt=>pt.id===J);if(!je||!$e)return we;if(se===J){const pt=ul(je.root,ee);if(!pt||pt.kind!=="stack")return we;const dt=pt.tabs.find(Tt=>Tt!==ie);if(!dt)return we;const kt=Wi(je.root,ie);if(!kt)return we;const gt=ed(kt,dt);if(!gt)return we;let vt;return pe==="center"?vt=$i(kt,gt,ie):vt=$a(kt,gt,pe,Lr([ie])),vt=Ps(vt,ie),we.map(Tt=>Tt.id!==se?Tt:(b.current+=1,{...Tt,root:vt,z:b.current,minimized:!1}))}const Je=Wi(je.root,ie),qe=je.colors[ie],Ee=je.intents[ie]??{intent:"open",nonce:0};let st;if(pe==="center")st=$i($e.root,ee,ie);else{const pt=Lr([ie]);st=$a($e.root,ee,pe,pt)}st=Ps(st,ie);const lt={...$e.colors};lt[ie]||(lt[ie]=qe||Hi(Object.values(lt)));const yt={...$e.intents,[ie]:Ee},mt=[];for(const pt of we)if(pt.id===se){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})},[]),G=S.useCallback((se,ie,J,ee)=>{g(pe=>{if(se===ie)return pe;const we=pe.find(lt=>lt.id===se),je=pe.find(lt=>lt.id===ie);if(!we||!je||we.root.kind!=="stack")return pe;const $e=we.root;let Je;ee==="center"?Je=$e.tabs.reduce((lt,yt)=>$i(lt,J,yt),je.root):Je=$a(je.root,J,ee,$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!==se&&(lt.id===ie?(b.current+=1,st.push({...lt,root:Je,colors:qe,intents:Ee,z:b.current,minimized:!1})):st.push(lt));return st})},[]),de=S.useRef(null),he=S.useRef(new Map),[be,ae]=S.useState(null),De=S.useRef(be);De.current=be;const Re=S.useRef(null),ve=S.useRef(typeof document<"u"&&document.hasFocus()?Date.now():0);S.useEffect(()=>{const se=()=>{ve.current=Date.now()};window.addEventListener("focus",se);const ie=LS();return()=>{window.removeEventListener("focus",se),ie(),Re.current&&clearTimeout(Re.current)}},[]);const Me=S.useRef(new Map),Oe=S.useRef(null),tt=S.useCallback((se,ie)=>{var st;const J=C.current.find(lt=>lt.id===se);if(!J)return;const ee=EO(),pe={...J,ownerWindowId:ee,dock:void 0};Me.current.set(se,pe),he.current.set(ee,Date.now()),g(lt=>lt.map(yt=>yt.id===se?{...yt,ownerWindowId:ee,dock:void 0}:yt)),(st=de.current)==null||st.post({t:"group-handoff",to:ee,groupId:se,group:pe});const we=ie&&(typeof ie.atScreenX=="number"||typeof ie.atScreenY=="number"),je=we?Math.max(0,((ie==null?void 0:ie.atScreenX)??window.screenX+J.x)-40):Math.max(0,window.screenX+J.x),$e=we?Math.max(0,((ie==null?void 0:ie.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(se)}?wid=${encodeURIComponent(ee)}`,Ee=window.open(qe,"_blank",Je);if(!Ee){Me.current.delete(se),he.current.delete(ee),g(lt=>lt.map(yt=>yt.id===se?{...yt,ownerWindowId:Pt}:yt)),l(o("session.popout.blocked"));return}CO(ee,Ee)},[e,o,l]);Oe.current=tt;const nt=S.useCallback(se=>{var ee;const ie=C.current.find(pe=>pe.id===se);if(!ie)return;const J=ie.ownerWindowId||Pt;if(J===Pt){P(se);return}(ee=de.current)==null||ee.post({t:"group-recall",popoutId:J,groupId:se}),setTimeout(()=>{var je;const pe=C.current.find($e=>$e.id===se);if(!pe||(pe.ownerWindowId||Pt)===Pt)return;he.current.delete(J),Me.current.delete(se),(je=de.current)==null||je.post({t:"group-reclaimed",popoutId:J,groupIds:[se],reason:"late-return"}),b.current+=1;const we=b.current;g($e=>$e.map(Je=>Je.id===se?{...Je,ownerWindowId:Pt,minimized:!1,z:we}:Je))},1500)},[P]),ke=S.useCallback(se=>{const ie=li(C.current,se);ie&&nt(ie.id)},[nt]);S.useEffect(()=>{const se=ie=>{const J=ie.detail;!(J!=null&&J.projectId)||!J.groupId||J.projectId!==e||nt(J.groupId)};return window.addEventListener("session-windows:recall",se),()=>window.removeEventListener("session-windows:recall",se)},[e,nt]),S.useEffect(()=>{const se=sessionStorage.getItem("pendingSessionRecall");if(se)try{const ie=JSON.parse(se);if(ie.projectId!==e||!ie.groupId)return;sessionStorage.removeItem("pendingSessionRecall");const J=ie.groupId;setTimeout(()=>nt(J),0)}catch{}},[e,nt]);const fe=S.useCallback(se=>se.kind==="stack"?[]:[0,...fe(se.children[0])],[]),Te=S.useCallback((se,ie,J)=>{const ee=ie?C.current.find($e=>$e.id===ie):null,pe=ee&&(ee.ownerWindowId||Pt)===Pt;if(!ee||!pe){A(se,"start");return}const we=(()=>{if(J){const $e=ul(ee.root,J);if($e&&$e.kind==="stack")return J}return fe(ee.root)})();b.current+=1;const je=b.current;g($e=>$e.map(Je=>{if(Je.id!==ee.id)return Je;const qe=Ps($i(Je.root,we,se),se);return{...Je,root:qe,z:je,minimized:!1,colors:{...Je.colors,[se]:Hi(Object.values(Je.colors))},intents:{...Je.intents,[se]:{intent:"start",nonce:0}}}}))},[A,fe]),Ce=S.useCallback(async(se,ie)=>{const J=new Date,ee=String(J.getHours()).padStart(2,"0"),pe=String(J.getMinutes()).padStart(2,"0"),we=String(J.getSeconds()).padStart(2,"0"),je=await km(e,{title:`Shell ${ee}:${pe}:${we}`,cli_tool:"raw-shell",use_worktree:!1,memory_inject_mode:"none"});return f==null||f(je),Te(je.id,se,ie),je.id},[e,f,Te]);S.useEffect(()=>{const se=Fp();de.current=se;const ie=ee=>{var pe;if(ee.t==="hello"){const we=Me.current.get(ee.groupId);if(we&&we.ownerWindowId===ee.from)se.post({t:"group-handoff",to:ee.from,groupId:ee.groupId,group:we});else{const je=C.current.find($e=>$e.id===ee.groupId);je&&je.ownerWindowId===ee.from&&se.post({t:"group-handoff",to:ee.from,groupId:ee.groupId,group:je})}}else if(ee.t==="group-return"||ee.t==="bye")if(ee.t==="group-return"){const we=ee.group;we&&we.id===ee.groupId&&(Me.current.delete(ee.groupId),he.current.delete(ee.from),ee.projectId&&ee.projectId!==e&&zO(ee.projectId,ee.groupId),g(je=>{const $e=je.find(qe=>qe.id===ee.groupId),Je={...we,ownerWindowId:Pt,dock:void 0};return $e?je.map(qe=>qe.id===ee.groupId?Je:qe):[...je,Je]}))}else he.current.delete(ee.from),g(we=>we.map(je=>je.ownerWindowId===ee.from?{...je,ownerWindowId:Pt}:je));else if(ee.t==="group-close")Me.current.delete(ee.groupId),g(we=>we.filter(je=>je.id!==ee.groupId));else if(ee.t==="heartbeat")he.current.set(ee.from,Date.now());else if(ee.t==="group-update"){const we=ee.patch;g(je=>je.map($e=>$e.id===ee.groupId?{...$e,...we}:$e))}else if(ee.t==="dock-probe"){if(document.visibilityState!=="visible")return;const we=Au(ee.x,ee.y),je=zu(we)?Tu(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("."))&&ae({rect:je.rect,zone:je.zone,path:je.path,groupId:je.groupId}),Re.current&&clearTimeout(Re.current),Re.current=setTimeout(()=>ae(null),800),se.post({t:"dock-probe-result",from:Pt,to:ee.from,hit:!0,focusAt:ve.current})}else De.current&&ae(null),se.post({t:"dock-probe-result",from:Pt,to:ee.from,hit:!1,focusAt:ve.current})}else if(ee.t==="dock-end")ae(null);else if(ee.t==="dock-commit"&&ee.to===Pt){const we=Au(ee.x,ee.y),je=zu(we)?Tu(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||Pt)===Pt);if($e&&$e.zone&&!li(qe,ee.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"?$i(dt.root,yt,ee.sessionId):$a(dt.root,yt,lt,Lr([ee.sessionId])),gt=Ps(kt,ee.sessionId),vt={...dt.colors};vt[ee.sessionId]||(vt[ee.sessionId]=ee.color||Hi(Object.values(vt)));const Tt={...dt.intents,[ee.sessionId]:ee.intentInfo??{intent:"open",nonce:0}};return{...dt,root:gt,colors:vt,intents:Tt,z:mt,minimized:!1}}))}}ae(null),se.post({t:"dock-commit-ack",from:Pt,to:ee.from,sessionId:ee.sessionId,accepted:Je})}},J=se.subscribe(ie);return()=>{J(),se.close(),de.current=null}},[e]),S.useEffect(()=>{const se=Date.now();for(const ie of p.groups)ie.ownerWindowId&&ie.ownerWindowId!==Pt&&he.current.set(ie.ownerWindowId,se)},[]),S.useEffect(()=>{const se=async()=>{var $e;const J=Date.now(),ee=[];for(const[Je,qe]of he.current.entries())J-qe>NS&&ee.push(Je);if(ee.length===0)return;const pe=await DS(),we=ee.filter(Je=>pe.has(Je)?(he.current.set(Je,J),!1):!0);if(we.length===0)return;for(const Je of we)he.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=de.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:Pt}:qe))},ie=setInterval(()=>{se()},Hp);return()=>clearInterval(ie)},[]);const Ke=S.useCallback((se,ie)=>{i({type:"session:terminal-input",sessionId:se,input:ie})},[i]),Ze=S.useCallback(()=>{var J,ee;const se=C.current.filter(pe=>(pe.ownerWindowId||Pt)===Pt).slice().sort((pe,we)=>we.z-pe.z),ie=[];for(const pe of se)for(const we of gn(pe.root)){const je=((J=k.current.find($e=>$e.id===we))==null?void 0:J.title)||((ee=T.current[we])==null?void 0:ee.title)||we;ie.push({sessionId:we,label:je})}return ie},[]),ye=S.useCallback(async(se,ie)=>{const ee=C.current.filter(we=>!we.minimized&&(we.ownerWindowId||Pt)===Pt).reduce((we,je)=>we&&we.z>=je.z?we:je,null),pe=await km(e,{title:ie||"",description:se,use_worktree:!1,memory_inject_mode:"none"});f==null||f(pe),Te(pe.id,(ee==null?void 0:ee.id)??null)},[e,f,Te]),Be=S.useMemo(()=>({openOrFocus:A,close:F,focus:B,minimize:U,restore:I,isOpen:H,recallPopout:ke,closeGroup:W,minimizeGroup:K,restoreGroup:P,setGroupGeometry:z,setGroupDock:$,setSplitSizes:Y,setActiveTab:q,applyLayoutPreset:oe,reorderTab:ce,beginTabDrag:ne,dockGroup:G,popOutGroup:tt,createRawShellTab:Ce,sendToSession:Ke,listOpenTerminals:Ze,sendToNewTerminal:ye}),[A,F,B,U,I,H,ke,W,K,P,z,$,Y,q,oe,ce,ne,G,tt,Ce,Ke,Ze,ye]),Z=S.useMemo(()=>{const se={};for(const ie of h){const ee=(ie.ownerWindowId||Pt)!==Pt?"popped":ie.minimized?"minimized":"floating";for(const pe of gn(ie.root))se[pe]=ee}return se},[h]);S.useEffect(()=>{const se=ie=>{const J=/Mac|iPhone|iPad|iPod/.test(navigator.platform),ee=J?ie.metaKey:ie.ctrlKey,pe=J?ie.ctrlKey:ie.metaKey;if(!ee||pe||ie.altKey||ie.shiftKey||ie.key.toLowerCase()!=="t")return;ie.preventDefault();const je=C.current.filter($e=>!$e.minimized&&($e.ownerWindowId||Pt)===Pt).reduce(($e,Je)=>$e&&$e.z>=Je.z?$e:Je,null);Ce((je==null?void 0:je.id)??null).catch(()=>{})};return window.addEventListener("keydown",se),()=>window.removeEventListener("keydown",se)},[Ce]);const _e=S.useMemo(()=>{const se=new Map;for(const ie of Object.values(w))se.set(ie.id,ie);for(const ie of s)se.set(ie.id,ie);return se},[s,w]),X=h.filter(se=>!se.minimized&&(se.ownerWindowId||Pt)===Pt),me=X.reduce((se,ie)=>ie.z>se.z?{id:ie.id,z:ie.z}:se,{id:null,z:-1/0}).id;return t.jsx(Up.Provider,{value:Be,children:t.jsxs(TS.Provider,{value:Z,children:[m,(()=>{const se=new Map(X.slice().sort((ie,J)=>ie.z-J.z).map((ie,J)=>[ie.id,J+1]));return X.map(ie=>{const J=X.filter(ee=>ee.id!==ie.id).map(({x:ee,y:pe,w:we,h:je})=>({x:ee,y:pe,w:we,h:je}));return t.jsx(SO,{group:ie,sessionsById:_e,neighbors:J,isTopmost:ie.id===me,zIndex:se.get(ie.id)??1,sendMessage:i,subscribeBinary:a,onEvent:u},ie.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)>=nw&&t.jsx(kS,{activeZone:x.viewportZone}),be&&t.jsx(bl,{targetRect:be.rect,activeZone:be.zone})]})})}function PO(e){if(!e)return[];try{const s=JSON.parse(e);return Array.isArray(s)?s.map(String).filter(Boolean):[]}catch{return[]}}const IO={pending:"bg-warm-400",running:"bg-status-success",completed:"bg-accent",failed:"bg-status-error",stopped:"bg-status-warning"};function FO({projectId:e,sessions:s,projectCliTool:i,isGitRepo:a,projectUseWorktree:u,projectDefaultBranch:f,onAddSession:m,onUpdateSession:o,onStopSession:l,onDeleteSession:d,onCleanupSession:p}){const{t:h}=ht(),{confirm:g}=qn(),{openOrFocus:b,recallPopout:C}=RS(),k=DO(),[x,y]=S.useState(!1),[_,w]=S.useState(!1),[E,T]=S.useState(null),[j,D]=S.useState(!1),[N,R]=S.useState(null),[A,B]=S.useState([]),[O,F]=S.useState(""),[U,I]=S.useState(null);S.useEffect(()=>{let oe=!1;return dp().then(ce=>{oe||B(ce)}).catch(()=>{}),()=>{oe=!0}},[]),S.useEffect(()=>{if(!a)return;let oe=!1;return h1(e).then(ce=>{oe||F(ce.branch||"")}).catch(()=>{}),()=>{oe=!0}},[e,a]);const H=S.useMemo(()=>{const oe=new Map;for(const ce of A)oe.set(ce.id,ce);return oe},[A]),W=S.useMemo(()=>E?s.find(oe=>oe.id===E)??null:null,[E,s]),K=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:Tz(W.memory_node_ids??null),memoryRawFilePaths:PO(W.memory_raw_file_paths??null),tagId:W.tag_id??null}},[W]),P=S.useCallback(()=>{T(null),R(null),y(oe=>!oe)},[]),z=S.useCallback(oe=>{y(!1),R(null),T(oe)},[]),$=S.useCallback(()=>{y(!1),T(null),R(null)},[]),Y=S.useCallback(async(oe,ce,ne,te,G,de,he,be)=>{w(!0);try{const ae=await km(e,{title:oe,description:ce||void 0,cli_tool:ne,use_worktree:te,memory_inject_mode:G,memory_node_ids:de,memory_raw_file_paths:he,tag_id:be??null});m(ae),y(!1)}finally{w(!1)}},[e,m]),q=S.useCallback(async(oe,ce,ne,te,G,de,he,be)=>{if(E){D(!0),R(null);try{const ae=await U4(E,{title:oe,description:ce||void 0,cli_tool:ne,use_worktree:te,memory_inject_mode:G,memory_node_ids:de,memory_raw_file_paths:he,tag_id:be??null});o(ae),T(null)}catch(ae){R(ae instanceof Error?ae.message:String(ae))}finally{D(!1)}}},[E,o]);return t.jsxs("div",{className:"space-y-4 min-h-[50vh]",onContextMenu:oe=>{xi(oe)||(oe.preventDefault(),I({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:h("tabs.sessions")}),t.jsxs("button",{onClick:P,className:"btn-primary text-xs py-2",disabled:_,children:["+ ",h("session.new")]})]}),x&&t.jsx(My,{projectId:e,onSave:Y,onCancel:$,projectCliTool:i,isGitRepo:a,projectUseWorktree:u}),K&&E&&t.jsxs("div",{className:"space-y-2",children:[t.jsx(My,{projectId:e,initial:K,onSave:q,onCancel:$,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:h("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:h("session.empty"),description:h("session.emptyHint")})}):t.jsx("div",{className:"space-y-3",children:s.map((oe,ce)=>{const ne=["pending","failed","stopped","completed"].includes(oe.status),te=oe.status==="running",G=oe.status!=="running",de=["stopped","failed","completed"].includes(oe.status)&&(oe.cli_tool??"claude")==="claude"&&!!oe.worktree_path,he=E===oe.id,be=k[oe.id]??"closed",ae=be==="popped";return t.jsx("div",{className:`card overflow-hidden ${he?"border-l-4 border-accent bg-warm-100/30":""}`,onContextMenu:De=>{xi(De)||(De.preventDefault(),De.stopPropagation(),I({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:()=>ae?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 ${IO[oe.status]||"bg-warm-400"}`}),h(`status.${oe.status}`)||oe.status]}),be!=="closed"&&t.jsxs("span",{className:"inline-flex items-center gap-1 text-2xs text-warm-400 whitespace-nowrap",title:ae?h("session.dock.poppedHint"):void 0,children:[ae?t.jsx(ar,{size:12}):t.jsx("span",{"aria-hidden":"true",children:"·"}),h(`session.windowState.${be}`)]})]}),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:[ae&&t.jsx("button",{onClick:()=>C(oe.id),className:"p-1.5 text-accent hover:bg-accent/10 rounded-md transition-colors",title:h("session.recallToMain"),children:t.jsx(fi,{size:16})}),ne&&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:h("session.start"),children:t.jsx(Tr,{size:16})}),de&&t.jsx("button",{onClick:()=>b(oe.id,"resume"),className:"p-1.5 text-accent hover:bg-accent/10 rounded-md transition-colors",title:h("session.resumeHint")||h("session.resume"),children:t.jsx(pi,{size:16})}),t.jsx("button",{onClick:()=>z(oe.id),disabled:!G,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:h(G?"session.edit":"session.editDisabledRunning"),children:t.jsx(dm,{size:16})}),te&&t.jsx("button",{onClick:()=>l(oe.id),className:"p-1.5 text-status-warning hover:bg-status-warning/10 rounded-md transition-colors",title:h("session.stop"),children:t.jsx(Gi,{size:16})}),oe.status!=="running"&&(!!oe.worktree_path||!!oe.branch_name)&&t.jsx("button",{onClick:async()=>{const De=oe.branch_name?await g({message:h("cleanup.confirmDeleteBranch").replace("{name}",oe.branch_name),danger:!0}):!1;p(oe.id,De)},className:"p-1.5 text-warm-400 hover:text-status-warning rounded-md transition-colors",title:h("session.cleanup"),children:t.jsx(bu,{size:16})}),t.jsx("button",{onClick:()=>d(oe.id),className:"p-1.5 text-warm-400 hover:text-status-error rounded-md transition-colors",title:h("session.delete"),children:t.jsx(An,{size:16})})]})]})})},oe.id)})}),U&&(()=>{const oe=()=>I(null),ce=U.sessionId?s.find(Re=>Re.id===U.sessionId):void 0;if(!ce)return t.jsx(Ws,{x:U.x,y:U.y,onClose:oe,children:t.jsxs("button",{type:"button",onClick:()=>{T(null),R(null),y(!0)},className:en,children:[t.jsx(vn,{size:14}),h("session.new")]})});const ne=["pending","failed","stopped","completed"].includes(ce.status),te=ce.status==="running",G=ce.status!=="running",de=["stopped","failed","completed"].includes(ce.status)&&(ce.cli_tool??"claude")==="claude"&&!!ce.worktree_path,he=ce.status!=="running"&&(!!ce.worktree_path||!!ce.branch_name),be=k[ce.id]??"closed",ae=be==="popped",De=h(ae?"session.recallToMain":be==="minimized"?"session.restoreWindow":be==="floating"?"session.focusWindow":"session.openWindow");return t.jsxs(Ws,{x:U.x,y:U.y,onClose:oe,children:[t.jsxs("button",{type:"button",onClick:()=>ae?C(ce.id):b(ce.id,"open"),className:en,children:[ae?t.jsx(fi,{size:14}):t.jsx(ml,{size:14}),De]}),ne&&t.jsxs("button",{type:"button",onClick:()=>b(ce.id,"start"),className:en,children:[t.jsx(Tr,{size:14}),h("session.start")]}),de&&t.jsxs("button",{type:"button",onClick:()=>b(ce.id,"resume"),className:en,title:h("session.resumeHint")||h("session.resume"),children:[t.jsx(pi,{size:14}),h("session.resume")]}),G&&t.jsxs("button",{type:"button",onClick:()=>z(ce.id),className:en,children:[t.jsx(dm,{size:14}),h("session.edit")]}),te&&t.jsxs("button",{type:"button",onClick:()=>l(ce.id),className:en,children:[t.jsx(Gi,{size:14}),h("session.stop")]}),he&&t.jsxs("button",{type:"button",onClick:async()=>{const Re=ce.branch_name?await g({message:h("cleanup.confirmDeleteBranch").replace("{name}",ce.branch_name),danger:!0}):!1;p(ce.id,Re)},className:en,children:[t.jsx(bu,{size:14}),h("session.cleanup")]}),t.jsx(Z_,{}),t.jsxs("button",{type:"button",onClick:()=>d(ce.id),className:zp,children:[t.jsx(An,{size:14}),h("session.delete")]})]})})()]})}const Bu={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"}},HO=Object.keys(Bu),Pu={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=Bu[e]||Bu.default;return`${s.bg} ${s.text}`}function qp({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(Vt,{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 Gm({anchorRef:e,width:s,onClose:i,className:a,style:u,children:f}){const m=S.useRef(null),[o,l]=S.useState(null);return S.useLayoutEffect(()=>{const d=e.current;if(!d)return;const p=d.getBoundingClientRect();let h=p.left;h+s>window.innerWidth-8&&(h=Math.max(8,window.innerWidth-8-s)),h<8&&(h=8),l({top:p.bottom+4,left:h})},[e,s]),S.useEffect(()=>{const d=h=>{var b,C;const g=h.target;(b=m.current)!=null&&b.contains(g)||(C=e.current)!=null&&C.contains(g)||i()},p=()=>i();return document.addEventListener("mousedown",d),window.addEventListener("scroll",p,!0),window.addEventListener("resize",p),()=>{document.removeEventListener("mousedown",d),window.removeEventListener("scroll",p,!0),window.removeEventListener("resize",p)}},[i,e]),o?rn.createPortal(t.jsx("div",{ref:m,className:a,style:{position:"fixed",top:o.top,left:o.left,width:s,...u},children:f}),document.body):null}const rw={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 $O({item:e,tagColors:s,existingTags:i,onSave:a,onDelete:u,onConvertToTodo:f,onConvertToSchedule:m,onConvertToSession:o,onUpdateTag:l}){var Z,_e;const{t:d}=ht(),{confirm:p}=qn(),[h,g]=S.useState(!1),[b,C]=S.useState(!1),[k,x]=S.useState(!1),y=S.useRef(null),_=S.useRef(null),[w,E]=S.useState({top:0,left:0}),[T,j]=S.useState(e.title),[D,N]=S.useState(e.description??""),[R,A]=S.useState(e.priority),[B,O]=S.useState(e.due_date??""),[F,U]=S.useState(e.status),[I,H]=S.useState(()=>{try{return e.tags?JSON.parse(e.tags):[]}catch{return[]}}),[W,K]=S.useState(""),[P,z]=S.useState(!1),[$,Y]=S.useState(null),[q,oe]=S.useState(null),ce=S.useRef(null),ne=S.useRef(null),[te,G]=S.useState(()=>{try{return e.images?JSON.parse(e.images):[]}catch{return[]}}),de=S.useRef(null);S.useEffect(()=>{j(e.title),N(e.description??""),A(e.priority),O(e.due_date??""),U(e.status);try{H(e.tags?JSON.parse(e.tags):[])}catch{H([])}try{G(e.images?JSON.parse(e.images):[])}catch{G([])}},[e]);const he=I,be=e.status==="moved",ae=e.due_date&&new Date(e.due_date)<new Date&&!be&&e.status!=="done",De=S.useCallback(X=>{a(e.id,X)},[e.id,a]),Re=()=>{const X=T.trim();X&&X!==e.title?De({title:X}):j(e.title)},ve=()=>{const X=D.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;U(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 se;const me=X.trim();if(me&&!I.includes(me)&&(nt([...I,me]),!s.has(me)&&l)){const ie=["blue","green","orange","purple","pink","red","yellow","brown"],J=ie[s.size%ie.length];l(me,{color:J})}K(""),(se=ce.current)==null||se.focus()},fe=X=>nt(I.filter(me=>me!==X)),Te=i.filter(X=>!I.includes(X)&&(!W||X.toLowerCase().includes(W.toLowerCase()))),Ce=S.useCallback(X=>{const me=Array.from(X).filter(J=>J.type.startsWith("image/")),se=[];let ie=0;for(const J of me){const ee=new FileReader;ee.onload=()=>{se.push({name:J.name,data:ee.result}),ie++,ie===me.length&&$1(e.id,se).then(pe=>G(pe.images))},ee.readAsDataURL(J)}},[e.id]),Ke=S.useCallback(X=>{var ie;const me=(ie=X.clipboardData)==null?void 0:ie.items;if(!me)return;const se=[];for(let J=0;J<me.length;J++)if(me[J].type.startsWith("image/")){const ee=me[J].getAsFile();ee&&se.push(ee)}se.length!==0&&(X.preventDefault(),Ce(se))},[Ce]),Ze=S.useCallback(X=>{var me;X.preventDefault(),X.stopPropagation(),(me=X.dataTransfer)!=null&&me.files&&Ce(X.dataTransfer.files)},[Ce]),ye=S.useCallback(X=>{U1(e.id,X).then(()=>{G(me=>me.filter(se=>se.id!==X))})},[e.id]),Be=S.useCallback(()=>{if(!y.current)return;const X=y.current.getBoundingClientRect(),me=window.innerWidth,se=window.innerHeight;let ie=X.bottom+4;const J=_.current;if(J){const ee=J.offsetWidth,pe=J.offsetHeight;let we=X.right-ee;we<8&&(we=8),we+ee>me-8&&(we=me-8-ee),ie+pe>se-8&&(ie=X.top-pe-4),E({top:ie,left:we}),x(!0)}else E({top:ie,left:Math.max(8,X.right-180)})},[]);return S.useEffect(()=>{if(!h){x(!1);return}Be();const X=requestAnimationFrame(Be),me=se=>{var J,ee;const ie=se.target;(J=y.current)!=null&&J.contains(ie)||(ee=_.current)!=null&&ee.contains(ie)||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)}},[h,Be]),t.jsxs("div",{className:`${be?"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}),be&&e.converted_type&&t.jsxs("span",{className:"text-2xs text-status-merged",children:["→ ",e.converted_type==="todo"?d("planner.movedToTodo"):e.converted_type==="session"?d("planner.movedToSession"):d("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:d("planner.fromDiscussion"),children:[t.jsx(VE,{size:12}),d("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]}),he.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 ${((Z=rw[e.priority])==null?void 0:Z.style)??"text-warm-300"}`,children:((_e=rw[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 ${ae?"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:d("planner.noDueDate")})}),t.jsx("div",{className:"w-16 flex-shrink-0",children:t.jsx("span",{className:`inline-flex items-center px-2 py-0.5 rounded-full text-2xs font-semibold ${Pu[e.status]||Pu.pending}`,children:d(`plannerStatus.${e.status}`)})}),t.jsxs("div",{className:"w-8 flex-shrink-0",children:[t.jsx("button",{ref:y,onClick:X=>{X.stopPropagation(),g(!h)},className:"p-1.5 text-warm-400 hover:text-warm-600 hover:bg-warm-100/50 rounded-lg transition-colors",children:t.jsx(rp,{size:14})}),h&&rn.createPortal(t.jsxs("div",{ref:_,className:"fixed z-tooltip min-w-[160px] rounded-xl py-1 shadow-elevated",style:{top:w.top,left:w.left,opacity:k?1:0,backgroundColor:"var(--color-bg-card)",border:"1px solid var(--color-border)"},onClick:()=>g(!1),children:[!be&&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(Xw,{size:12})," ",d("planner.convertToTask")]}),t.jsxs("button",{onClick:m,className:"flex items-center gap-2 w-full px-3 py-1.5 text-xs hover:bg-warm-100 rounded-md transition-colors text-left",style:{color:"var(--color-text-primary)"},children:[t.jsx(qi,{size:12})," ",d("planner.convertToSchedule")]}),t.jsxs("button",{onClick:o,className:"flex items-center gap-2 w-full px-3 py-1.5 text-xs hover:bg-warm-100 rounded-md transition-colors text-left",style:{color:"var(--color-text-primary)"},children:[t.jsx(gi,{size:12})," ",d("planner.convertToTerminal")]})]}),t.jsxs("button",{onClick:async()=>{await p({message:d("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})," ",d("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:T,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:d("plannerForm.descPlaceholder"),value:D,onChange:X=>N(X.target.value),onPaste:Ke,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=de.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}),d("plannerForm.addImage")]}),t.jsx("span",{className:"text-[10px] text-warm-300",children:d("plannerForm.pasteHint")})]}),t.jsx("input",{ref:de,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:ju(e.id,X.id),alt:X.originalName,onClick:()=>oe(ju(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:()=>ye(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(Vt,{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:d("plannerForm.tags")}),t.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[I.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=>{ne.current=me.currentTarget,Y($===X?null:X)},children:[X,t.jsx("button",{onClick:me=>{me.stopPropagation(),fe(X)},className:"opacity-60 hover:opacity-100",children:t.jsx(Vt,{size:12})})]}),$===X&&t.jsxs(Gm,{anchorRef:ne,width:180,onClose:()=>Y(null),className:"p-2 rounded-lg shadow-elevated z-tooltip",style:{backgroundColor:"var(--color-bg-card)",border:"1px solid var(--color-border)"},children:[t.jsx("div",{className:"text-2xs text-warm-400 mb-1.5",children:d("plannerTag.color")}),t.jsx("div",{className:"grid grid-cols-5 gap-1.5",children:HO.map(me=>t.jsx("button",{onClick:async()=>{l&&await l(X,{color:me}),Y(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:d(`plannerTag.color.${me}`),children:t.jsx("div",{className:`w-5 h-5 rounded-md ${Bu[me].swatch}`})},me))})]})]},X)),t.jsxs("div",{className:"relative",children:[t.jsx("input",{ref:ce,className:"bg-transparent text-xs outline-none w-24",style:{color:"var(--color-text-primary)"},placeholder:"+",value:W,onChange:X=>{K(X.target.value),z(!0)},onKeyDown:X=>{(X.key==="Enter"||X.key===",")&&W.trim()&&(X.preventDefault(),ke(W.replace(",",""))),X.key==="Backspace"&&!W&&I.length>0&&fe(I[I.length-1])},onFocus:()=>z(!0),onBlur:()=>setTimeout(()=>z(!1),150)}),P&&Te.length>0&&t.jsx(Gm,{anchorRef:ce,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:d("plannerForm.priority")}),t.jsxs("select",{className:"input-field text-xs w-full py-1",value:R,onChange:X=>Me(Number(X.target.value)),children:[t.jsx("option",{value:0,children:d("plannerForm.priorityLow")}),t.jsx("option",{value:1,children:d("plannerForm.priorityNormal")}),t.jsx("option",{value:2,children:d("plannerForm.priorityHigh")}),t.jsx("option",{value:3,children:d("plannerForm.priorityCritical")})]})]}),t.jsxs("div",{children:[t.jsx("label",{className:"text-2xs text-warm-400 mb-1 block",children:d("plannerForm.dueDate")}),t.jsx("input",{type:"date",className:"input-field text-xs w-full py-1",value:B,onChange:X=>Oe(X.target.value)})]}),t.jsxs("div",{children:[t.jsx("label",{className:"text-2xs text-warm-400 mb-1 block",children:d("plannerForm.status")}),t.jsxs("select",{className:"input-field text-xs w-full py-1",value:F,onChange:X=>tt(X.target.value),children:[t.jsx("option",{value:"pending",children:d("plannerStatus.pending")}),t.jsx("option",{value:"in_progress",children:d("plannerStatus.in_progress")}),t.jsx("option",{value:"done",children:d("plannerStatus.done")})]})]})]})]})}),q&&t.jsx(qp,{src:q,onClose:()=>oe(null)})]})}let UO=0;function WO({existingTags:e,editItem:s,initialDueDate:i,onSave:a,onCancel:u,onUpdateTag:f}){const{t:m}=ht(),[o,l]=S.useState(""),[d,p]=S.useState(""),[h,g]=S.useState([]),[b,C]=S.useState(""),[k,x]=S.useState(i??""),[y,_]=S.useState(0),[w,E]=S.useState("pending"),[T,j]=S.useState(!1),[D,N]=S.useState(!1),[R,A]=S.useState([]),[B,O]=S.useState([]),[F,U]=S.useState(null),I=S.useRef(null),H=S.useRef(null),W=S.useRef(null),[K,P]=S.useState(new Map),z=new Map([...e.map(ae=>[ae.name,ae.color]),...K]),$=["blue","green","orange","purple","pink","red","yellow","brown"];S.useEffect(()=>{var ae;if(s){l(s.title),p(s.description??""),g(s.tags?JSON.parse(s.tags):[]),x(s.due_date??""),_(s.priority),E(s.status);try{O(s.images?JSON.parse(s.images):[])}catch{O([])}}(ae=I.current)==null||ae.focus()},[s]);const Y=e.filter(ae=>!h.includes(ae.name)&&(!b||ae.name.toLowerCase().includes(b.toLowerCase()))),q=ae=>{var Re;const De=ae.trim();De&&!h.includes(De)&&g(ve=>{const Me=[...ve,De];if(!z.has(De)){const Oe=$[z.size%$.length];P(tt=>new Map([...tt,[De,Oe]]))}return Me}),C(""),N(!0),(Re=H.current)==null||Re.focus()},oe=ae=>g(h.filter(De=>De!==ae)),ce=S.useCallback(ae=>{const De=Array.from(ae).filter(Re=>Re.type.startsWith("image/"));for(const Re of De){const ve=new FileReader;ve.onload=()=>{const Me=ve.result,Oe=`pending-${++UO}`;A(tt=>[...tt,{id:Oe,name:Re.name,data:Me,preview:Me}])},ve.readAsDataURL(Re)}},[]),ne=S.useCallback(ae=>{var ve;const De=(ve=ae.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&&(ae.preventDefault(),ce(Re))},[ce]),te=S.useCallback(ae=>{var De;ae.preventDefault(),ae.stopPropagation(),(De=ae.dataTransfer)!=null&&De.files&&ce(ae.dataTransfer.files)},[ce]),G=ae=>A(De=>De.filter(Re=>Re.id!==ae)),de=ae=>{s&&U1(s.id,ae),O(De=>De.filter(Re=>Re.id!==ae))},he=B.length+R.length,be=async()=>{if(o.trim()){j(!0);try{const ae=await a({title:o.trim(),description:d.trim()||void 0,tags:h.length>0?JSON.stringify(h):void 0,due_date:k||void 0,priority:y,...s?{status:w}:{}});if(f&&K.size>0&&await Promise.all([...K.entries()].map(([De,Re])=>f(De,{color:Re}))),R.length>0){const De=(s==null?void 0:s.id)??(ae==null?void 0:ae.id);De&&await $1(De,R.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:I,className:"input-field text-sm w-full mb-3",placeholder:m("plannerForm.titlePlaceholder"),value:o,onChange:ae=>l(ae.target.value),onKeyDown:ae=>{ae.key==="Enter"&&ae.preventDefault()}}),t.jsx("textarea",{className:"input-field text-sm w-full mb-3 min-h-[76px] max-h-[320px] resize-y [field-sizing:content]",rows:3,placeholder:m("plannerForm.descPlaceholder"),value:d,onChange:ae=>p(ae.target.value),onPaste:ne,onDrop:te,onDragOver:ae=>{ae.preventDefault(),ae.stopPropagation()}}),t.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[t.jsxs("button",{type:"button",onClick:()=>{var ae;return(ae=W.current)==null?void 0:ae.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}),m("plannerForm.addImage")]}),t.jsx("span",{className:"text-[10px] text-warm-300",children:m("plannerForm.pasteHint")})]}),t.jsx("input",{ref:W,type:"file",accept:"image/*",multiple:!0,className:"hidden",onChange:ae=>{ae.target.files&&ce(ae.target.files),ae.target.value=""}}),he>0&&t.jsxs("div",{className:"mb-4",children:[t.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[t.jsx("h4",{className:"text-xs font-semibold text-warm-500 uppercase tracking-wider",children:m("plannerForm.images")}),t.jsxs("span",{className:"text-[10px] text-warm-400",children:["(",he,")"]})]}),t.jsxs("div",{className:"flex flex-wrap gap-2",children:[B.map(ae=>t.jsxs("div",{className:"relative group",children:[t.jsx("img",{src:s?ju(s.id,ae.id):"",alt:ae.originalName,onClick:()=>s&&U(ju(s.id,ae.id)),className:"h-20 w-20 object-cover rounded-lg border border-warm-200 cursor-zoom-in"}),t.jsx("button",{type:"button",onClick:()=>de(ae.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(Vt,{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:ae.originalName})})]},ae.id)),R.map(ae=>t.jsxs("div",{className:"relative group",children:[t.jsx("img",{src:ae.preview,alt:ae.name,onClick:()=>U(ae.preview),className:"h-20 w-20 object-cover rounded-lg border border-accent/30 cursor-zoom-in"}),t.jsx("button",{type:"button",onClick:()=>G(ae.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(Vt,{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:ae.name})})]},ae.id))]})]}),t.jsxs("div",{className:"mb-4",children:[t.jsx("label",{className:"text-xs font-medium text-warm-500 mb-1.5 block",children:m("plannerForm.tags")}),t.jsxs("div",{className:"flex flex-wrap items-center gap-1.5 p-2 rounded-xl",style:{backgroundColor:"var(--color-bg-input)",border:"1px solid var(--color-border-strong)"},children:[h.map(ae=>t.jsxs("span",{className:`inline-flex items-center gap-1 px-2 py-0.5 rounded-md text-[11px] font-medium ${Wa(z.get(ae)||"default")}`,children:[ae,t.jsx("button",{onClick:()=>oe(ae),className:"opacity-60 hover:opacity-100",children:t.jsx(Vt,{size:12})})]},ae)),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:h.length===0?m("plannerForm.tagsPlaceholder"):"",value:b,onChange:ae=>{C(ae.target.value),N(!0)},onKeyDown:ae=>{(ae.key==="Enter"||ae.key===",")&&b.trim()&&(ae.preventDefault(),q(b.replace(",",""))),ae.key==="Backspace"&&!b&&h.length>0&&oe(h[h.length-1])},onFocus:()=>N(!0),onBlur:()=>setTimeout(()=>N(!1),150)}),D&&(Y.length>0||b.trim())&&t.jsxs(Gm,{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:[Y.slice(0,10).map(ae=>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(ae.name),children:t.jsx("span",{className:`px-2 py-0.5 rounded-md text-[11px] font-medium ${Wa(ae.color)}`,children:ae.name})},ae.name)),b.trim()&&!e.some(ae=>ae.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:m("plannerForm.dueDate")}),t.jsx("input",{type:"date",className:"input-field text-xs w-full",value:k,onChange:ae=>x(ae.target.value)})]}),t.jsxs("div",{children:[t.jsx("label",{className:"text-xs font-medium text-warm-500 mb-1.5 block",children:m("plannerForm.priority")}),t.jsxs("select",{className:"input-field text-xs w-full",value:y,onChange:ae=>_(Number(ae.target.value)),children:[t.jsx("option",{value:0,children:m("plannerForm.priorityLow")}),t.jsx("option",{value:1,children:m("plannerForm.priorityNormal")}),t.jsx("option",{value:2,children:m("plannerForm.priorityHigh")}),t.jsx("option",{value:3,children:m("plannerForm.priorityCritical")})]})]}),s&&t.jsxs("div",{children:[t.jsx("label",{className:"text-xs font-medium text-warm-500 mb-1.5 block",children:m("plannerForm.status")}),t.jsxs("select",{className:"input-field text-xs w-full",value:w,onChange:ae=>E(ae.target.value),children:[t.jsx("option",{value:"pending",children:m("plannerStatus.pending")}),t.jsx("option",{value:"in_progress",children:m("plannerStatus.in_progress")}),t.jsx("option",{value:"done",children:m("plannerStatus.done")})]})]})]}),t.jsxs("div",{className:"flex justify-end gap-3",children:[t.jsx("button",{className:"btn-ghost text-xs",onClick:u,children:m("plannerForm.cancel")}),t.jsx("button",{className:"btn-primary text-xs py-2",onClick:be,disabled:!o.trim()||T,children:m("plannerForm.save")})]}),F&&t.jsx(qp,{src:F,onClose:()=>U(null)})]})}function OS({item:e,mode:s,projectCliTool:i,onConvert:a,onClose:u}){const{t:f}=ht(),[m,o]=S.useState(i||"claude"),[l,d]=S.useState(""),[p,h]=S.useState(!1),[g,b]=S.useState("once"),[C,k]=S.useState("0 0 * * *"),[x,y]=S.useState(""),[_,w]=S.useState(!1),E=async()=>{w(!0);try{s==="todo"?await a({cli_tool:m,max_turns:l?Number(l):void 0}):s==="session"?await a({cli_tool:m,use_worktree:p}):await a({cli_tool:m,schedule_type:g,cron_expression:g==="recurring"?C:void 0,run_at:g==="once"?x:void 0})}finally{w(!1)}};return t.jsx(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:m,onChange:T=>o(T.target.value),children:[t.jsx("option",{value:"claude",children:"Claude"}),t.jsx("option",{value:"antigravity",children:"Antigravity"}),t.jsx("option",{value:"codex",children:"Codex"})]})]}),s==="todo"&&t.jsxs("div",{className:"mb-4",children:[t.jsx("label",{className:"text-xs font-medium text-warm-500 mb-1.5 block",children:f("plannerConvert.maxTurns")}),t.jsx("input",{type:"number",min:"1",className:"input-field text-xs w-full",placeholder:"—",value:l,onChange:T=>d(T.target.value)})]}),s==="session"&&t.jsxs("label",{className:"flex items-center gap-2 mb-4 cursor-pointer",children:[t.jsx("input",{type:"checkbox",checked:p,onChange:T=>h(T.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:T=>y(T.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:T=>k(T.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:_||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 iw(e){return xn(new Date(e))}function aw(e){return new Date(e.getFullYear(),e.getMonth(),1)}function BS(e){return new Date(e.getFullYear(),e.getMonth(),e.getDate())}function sr(e,s){const i=BS(e);return i.setDate(i.getDate()+s),i}function PS(e){return sr(e,-e.getDay())}function qO(e,s){return Math.round((new Date(s+"T00:00").getTime()-new Date(e+"T00:00").getTime())/864e5)}function GO(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=qO(a,i),f=m=>xn(sr(new Date(m+"T00:00"),u));return{startKey:f(s.startKey),endKey:f(s.endKey)}}function KO(e,s){if(e==="day"){const f=BS(s);return{rangeStart:xn(f),rangeEnd:xn(sr(f,1)),gridDays:[f],cols:1,dimOutOfMonth:!1}}if(e==="week"){const f=PS(s),m=Array.from({length:7},(o,l)=>sr(f,l));return{rangeStart:xn(f),rangeEnd:xn(sr(f,7)),gridDays:m,cols:7,dimOutOfMonth:!1}}if(e==="table"){const f=aw(s),m=new Date(s.getFullYear(),s.getMonth()+1,1);return{rangeStart:xn(f),rangeEnd:xn(m),gridDays:[],cols:7,dimOutOfMonth:!1}}const i=aw(s),a=sr(i,-i.getDay()),u=Array.from({length:42},(f,m)=>sr(a,m));return{rangeStart:xn(a),rangeEnd:xn(sr(a,42)),gridDays:u,cols:7,dimOutOfMonth:!0}}function IS(e,s){return S.useMemo(()=>KO(e,s),[e,s])}function FS(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 HS(e,s,i){if(s==="month"||s==="table")return e.toLocaleDateString(i,{year:"numeric",month:"long"});if(s==="week"){const a=PS(e);return`${a.toLocaleDateString(i,{month:"short",day:"numeric"})} – ${sr(a,6).toLocaleDateString(i,{month:"short",day:"numeric"})}`}return e.toLocaleDateString(i,{year:"numeric",month:"long",day:"numeric",weekday:"short"})}function $S(){const{lang:e}=ht();return S.useMemo(()=>{const s=new Date(2024,5,2);return Array.from({length:7},(i,a)=>sr(s,a).toLocaleDateString(e,{weekday:"short"}))},[e])}const VO=420,YO=140,XO=220,JO=26,Qf=16,ow=2;function QO(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 l=o.startKey<i?i:o.startKey,d=o.endKey>a?a:o.endKey;return{bar:o,startCol:e.findIndex(p=>xn(p)===l),endCol:e.findIndex(p=>xn(p)===d),contStart:o.startKey<i,contEnd:o.endKey>a}}).filter(o=>o.startCol>=0&&o.endCol>=0).sort((o,l)=>o.startCol-l.startCol||l.endCol-l.startCol-(o.endCol-o.startCol)),f=[];return{placed:u.map(o=>{let l=0;for(;l<f.length&&f[l]>=o.startCol;)l++;return f[l]=o.endCol,{...o,lane:l}}),laneCount:f.length}}function US({view:e,gridDays:s,cols:i,dimOutOfMonth:a,monthIdx:u,todayKey:f,selectedDate:m,chipsByDay:o,maxChips:l,weekdayLabels:d,addItemLabel:p,bars:h,onBarClick:g,onSelectDate:b,onQuickAdd:C,onChipClick:k,onCellContextMenu:x,onChipContextMenu:y,onBarContextMenu:_,onBarDrag:w,onChipDrag:E,monthCellHeight:T=92}){const{lang:j}=ht(),[D,N]=S.useState(null),[R,A]=S.useState(!1),B=S.useRef(null),O=S.useRef(null),F=()=>{O.current&&(clearTimeout(O.current),O.current=null)},U=(ne,te)=>{F(),B.current&&clearTimeout(B.current);const G=te.getBoundingClientRect();B.current=window.setTimeout(()=>N({key:ne,rect:G}),VO)},I=()=>{B.current&&(clearTimeout(B.current),B.current=null),O.current=window.setTimeout(()=>N(null),YO)};S.useEffect(()=>{if(!D){A(!1);return}const ne=requestAnimationFrame(()=>A(!0));return()=>cancelAnimationFrame(ne)},[D]),S.useEffect(()=>()=>{B.current&&clearTimeout(B.current),O.current&&clearTimeout(O.current)},[]),S.useEffect(()=>{if(!D)return;const ne=()=>N(null);return window.addEventListener("scroll",ne,!0),window.addEventListener("resize",ne),()=>{window.removeEventListener("scroll",ne,!0),window.removeEventListener("resize",ne)}},[D]);const H=D?o.get(D.key)??[]:[],[W,K]=S.useState(null),P=S.useRef(!1),z=4,$=(ne,te)=>{var G,de;return((de=(G=document.elementFromPoint(ne,te))==null?void 0:G.closest("[data-daykey]"))==null?void 0:de.getAttribute("data-daykey"))??null},Y=(ne,te,G)=>{ne.preventDefault(),ne.stopPropagation();const de=$(ne.clientX,ne.clientY)??G.origStart,he=ne.clientX,be=ne.clientY,ae=te!=="move";let De=ae,Re={startKey:G.origStart,endKey:G.origEnd};const ve=()=>K({kind:G.kind,entryKey:G.entryKey,curStart:Re.startKey,curEnd:Re.endKey,title:G.title,bg:G.bg,fg:G.fg,done:G.done}),Me=()=>{document.body.style.cursor=ae?"ew-resize":"grabbing",document.body.style.userSelect="none"};ae&&(Me(),ve());const Oe=nt=>{if(!De){if(Math.abs(nt.clientX-he)<z&&Math.abs(nt.clientY-be)<z)return;De=!0,Me()}const ke=$(nt.clientX,nt.clientY);ke&&(Re=GO(te,{startKey:G.origStart,endKey:G.origEnd},ke,de),ve())},tt=()=>{window.removeEventListener("pointermove",Oe),window.removeEventListener("pointerup",tt),document.body.style.cursor="",document.body.style.userSelect="",K(null),De&&(P.current=!0,setTimeout(()=>{P.current=!1},0),!(Re.startKey===G.origStart&&Re.endKey===G.origEnd)&&(G.kind==="bar"&&G.bar?w==null||w(G.bar,Re.startKey,Re.endKey):G.kind==="chip"&&G.chip&&(E==null||E(G.chip,Re.startKey,Re.endKey))))};window.addEventListener("pointermove",Oe),window.addEventListener("pointerup",tt)},q=(()=>{const ne=h??[];return W?W.kind==="bar"?ne.map(te=>te.key===W.entryKey?{...te,startKey:W.curStart,endKey:W.curEnd}:te):[...ne,{key:`__drag__${W.entryKey}`,title:W.title,startKey:W.curStart,endKey:W.curEnd,bg:W.bg,fg:W.fg,done:W.done}]:ne})(),oe=(ne,te)=>{const G=xn(ne),de=o.get(G)??[],he=!a||ne.getMonth()===u,be=G===f,ae=G===m,De=e==="week"?"min-h-[360px]":e==="day"?"min-h-[480px]":"",Re=e==="month"&&de.length>l;return t.jsxs("div",{"data-daykey":G,onClick:()=>{P.current||b(G)},onContextMenu:x?ve=>x(G,ve):void 0,onMouseEnter:Re?ve=>U(G,ve.currentTarget):void 0,onMouseLeave:Re?I:void 0,className:`group relative ${De} text-left p-1.5 flex flex-col gap-1 transition-colors cursor-pointer`,style:{minHeight:e==="month"?T+te:void 0,backgroundColor:ae?"var(--color-bg-hover)":"var(--color-bg-card)",opacity:he?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:ne.toLocaleDateString(j,{weekday:"short"})}),t.jsx("span",{className:"text-xs font-medium w-5 h-5 flex items-center justify-center rounded-full",style:be?{backgroundColor:"var(--color-accent)",color:"#fff"}:{color:"var(--color-text-secondary)"},children:ne.getDate()})]}),t.jsx("button",{onClick:ve=>{ve.stopPropagation(),C(G)},className:"absolute top-1 right-1 opacity-0 group-hover:opacity-100 transition-opacity rounded-md w-5 h-5 flex items-center justify-center hover:bg-theme-hover",title:p,style:{backgroundColor:"var(--color-bg-secondary)",color:"var(--color-text-secondary)",border:"1px solid var(--color-border)"},children:t.jsx(vn,{size:14})}),t.jsxs("div",{className:"flex flex-col gap-0.5 overflow-hidden",style:{marginTop:te||void 0},children:[de.slice(0,l).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:G,origEnd:G,title:ve.title,bg:ve.bg,fg:ve.fg,done:ve.done,chip:ve};return t.jsxs("span",{onClick:tt=>{tt.stopPropagation(),!P.current&&k(ve)},onPointerDown:Me?tt=>Y(tt,"move",Oe):void 0,onContextMenu:y?tt=>y(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(),Y(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)}),de.length>l&&t.jsxs("span",{className:"text-2xs px-1",style:{color:"var(--color-text-muted)"},children:["+",de.length-l]})]})]},G)},ce=[];if(e==="month")for(let ne=0;ne<s.length;ne+=i)ce.push(s.slice(ne,ne+i));return t.jsxs(t.Fragment,{children:[(e==="month"||e==="week")&&t.jsx("div",{className:"grid gap-px text-2xs uppercase tracking-wider mb-1",style:{gridTemplateColumns:`repeat(${i}, minmax(0, 1fr))`,color:"var(--color-text-muted)"},children:d.map(ne=>t.jsx("div",{className:"px-2 py-1",children:ne},ne))}),e==="month"?t.jsx("div",{className:"flex flex-col gap-px rounded-xl overflow-hidden",style:{backgroundColor:"var(--color-border)"},children:ce.map((ne,te)=>{const{placed:G,laneCount:de}=QO(ne,q),he=de*(Qf+ow);return t.jsxs("div",{className:"relative grid gap-px",style:{gridTemplateColumns:`repeat(${i}, minmax(0, 1fr))`,backgroundColor:"var(--color-border)"},children:[ne.map(be=>oe(be,he)),G.map(({bar:be,startCol:ae,endCol:De,lane:Re,contStart:ve,contEnd:Me})=>{const Oe=!!w&&!be.key.startsWith("__drag__"),tt={kind:"bar",entryKey:be.key,origStart:be.startKey,origEnd:be.endKey,title:be.title,bg:be.bg,fg:be.fg,done:be.done,bar:be};return t.jsxs("div",{onClick:nt=>{nt.stopPropagation(),!P.current&&(g==null||g(be))},onPointerDown:Oe?nt=>Y(nt,"move",tt):void 0,onContextMenu:_?nt=>_(be,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(${ae} / ${i} * 100% + 2px)`,width:`calc(${De-ae+1} / ${i} * 100% - 4px)`,top:JO+Re*(Qf+ow),height:Qf,backgroundColor:be.bg,color:be.fg,textDecoration:be.done?"line-through":"none",borderRadius:4,borderTopLeftRadius:ve?0:4,borderBottomLeftRadius:ve?0:4,borderTopRightRadius:Me?0:4,borderBottomRightRadius:Me?0:4},title:be.title,children:[ve?"◀ ":"",be.title,Me?" ▶":"",Oe&&!ve&&t.jsx("span",{onPointerDown:nt=>{nt.stopPropagation(),Y(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(),Y(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)"}})]},be.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(ne=>oe(ne,0))}),D&&(()=>{const ne=Math.max(D.rect.width,XO),te=Math.min(Math.max(8,D.rect.left),window.innerWidth-ne-8),G=Math.max(8,Math.min(D.rect.top,window.innerHeight-120)),de=window.innerHeight-G-16,he=Number(D.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:G,width:ne,maxHeight:de,overflowY:"auto",backgroundColor:"var(--color-bg-card)",border:"1px solid var(--color-border)",padding:6,transformOrigin:"top left",transform:R?"scale(1)":"scale(0.96)",opacity:R?1:0,transition:"transform 140ms ease, opacity 140ms ease"},children:[t.jsx("div",{className:"text-xs font-semibold px-1 pb-1",style:{color:"var(--color-text-secondary)"},children:he}),t.jsx("div",{className:"flex flex-col gap-0.5",children:H.map(be=>t.jsxs("span",{onClick:ae=>{ae.stopPropagation(),k(be),N(null)},onContextMenu:y?ae=>y(be,ae):void 0,className:"text-2xs truncate px-1 py-0.5 rounded-md cursor-pointer hover:opacity-80 transition-opacity",style:{backgroundColor:be.bg,color:be.fg,textDecoration:be.done?"line-through":"none"},title:be.title,children:[be.prefix??"",be.time?`${be.time} `:"",be.title]},be.key))})]}),document.body)})()]})}function ZO(e){if(!e)return[];try{const s=JSON.parse(e);return Array.isArray(s)?s.filter(i=>typeof i=="string"):[]}catch{return[]}}function eB({view:e,items:s,tagColors:i,onQuickAdd:a,onEditItem:u,onConvert:f,onDeleteItem:m,onUpdateRange:o}){const{t:l,lang:d}=ht(),[p,h]=S.useState(()=>new Date),[g,b]=S.useState(()=>xn(new Date)),[C,k]=S.useState(null),x=$S(),{gridDays:y,cols:_,dimOutOfMonth:w}=IS(e,p),E=xn(new Date),T=p.getMonth(),j=e==="month"?3:99,D=ce=>h(ne=>FS(ne,e,ce)),N=()=>{h(new Date),b(xn(new Date))},R=HS(p,e,d);S.useEffect(()=>{e==="day"&&b(xn(p))},[e,p]);const A=260,B=760,O=S.useRef(null),[F,U]=S.useState(()=>{const ce=parseInt(localStorage.getItem("plannerCalendarPanelWidth")||"",10);return Number.isFinite(ce)&&ce>=A&&ce<=B?ce:320});S.useEffect(()=>{try{localStorage.setItem("plannerCalendarPanelWidth",String(F))}catch{}},[F]);const I=ce=>{ce.preventDefault();const ne=G=>{var he;const de=(he=O.current)==null?void 0:he.getBoundingClientRect();de&&U(Math.min(B,Math.max(A,de.right-G.clientX)))},te=()=>{window.removeEventListener("pointermove",ne),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",ne),window.addEventListener("pointerup",te)},[H,W]=S.useState(new Map);S.useEffect(()=>{W(new Map)},[s]);const K=S.useMemo(()=>H.size===0?s:s.map(ce=>{const ne=H.get(ce.id);return ne?{...ce,due_date:ne.due_date,end_date:ne.end_date}:ce}),[s,H]),P=S.useCallback((ce,ne,te)=>{W(G=>new Map(G).set(ce,{due_date:ne,end_date:te})),o(ce,ne,te)},[o]),z=ce=>!!(ce.due_date&&ce.end_date&&ce.end_date.slice(0,10)>ce.due_date.slice(0,10)),$=S.useMemo(()=>{const ce=new Map;for(const ne of K){if(!ne.due_date||e==="month"&&z(ne))continue;const te=ne.due_date.slice(0,10),G=ne.status==="done",de=ce.get(te)??[];de.push({key:ne.id,title:ne.title,bg:"var(--color-bg-secondary)",fg:G?"var(--color-text-muted)":"var(--color-text-secondary)",done:G,payload:ne,draggable:!0}),ce.set(te,de)}return ce},[K,e]),Y=S.useMemo(()=>e!=="month"?[]:K.filter(z).map(ce=>{const ne=ce.status==="done";return{key:ce.id,title:ce.title,startKey:ce.due_date.slice(0,10),endKey:ce.end_date.slice(0,10),bg:"var(--color-bg-secondary)",fg:ne?"var(--color-text-muted)":"var(--color-text-secondary)",done:ne,payload:ce}}),[K,e]),q=S.useMemo(()=>s.filter(ce=>ce.due_date&&ce.due_date.slice(0,10)===g),[s,g]),oe=S.useMemo(()=>s.filter(ce=>!ce.due_date),[s]);return t.jsxs("div",{ref:O,className:"card flex overflow-hidden",style:{minHeight:520},children:[t.jsxs("div",{className:"flex-1 flex flex-col overflow-hidden min-w-0",children:[t.jsxs("div",{className:"px-4 pt-3 pb-2 flex items-center gap-2",children:[t.jsx("button",{onClick:()=>D(-1),className:"btn-ghost p-1.5","aria-label":"prev",children:t.jsx(sp,{size:16})}),t.jsx("div",{className:"text-sm font-semibold min-w-[8rem] text-center",style:{color:"var(--color-text-primary)"},children:R}),t.jsx("button",{onClick:()=>D(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:l("agenda.today")})]}),t.jsx("div",{className:"flex-1 overflow-auto px-4 pb-4",children:t.jsx(US,{view:e,gridDays:y,cols:_,dimOutOfMonth:w,monthIdx:T,todayKey:E,selectedDate:g,chipsByDay:$,maxChips:j,weekdayLabels:x,addItemLabel:l("agenda.addItem"),onSelectDate:b,onQuickAdd:a,onChipClick:ce=>u(ce.payload),onCellContextMenu:(ce,ne)=>{ne.preventDefault(),k({x:ne.clientX,y:ne.clientY,dateKey:ce})},bars:Y,onBarClick:ce=>u(ce.payload),onBarDrag:(ce,ne,te)=>P(ce.payload.id,ne,te),onChipDrag:(ce,ne,te)=>P(ce.payload.id,ne,te)})})]}),t.jsx("div",{onPointerDown:I,className:"w-1.5 flex-shrink-0 cursor-col-resize hover:bg-accent/40 transition-colors",style:{backgroundColor:"var(--color-border)"},title:l("agenda.resizePanel")}),t.jsxs("div",{className:"flex-shrink-0 flex flex-col overflow-hidden",style:{width: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(d,{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(vn,{size:14}),l("agenda.add")]})]}),t.jsxs("div",{className:"flex-1 overflow-auto px-4 pb-4 flex flex-col gap-4",children:[t.jsxs("div",{className:"flex flex-col gap-1.5",children:[q.length===0&&t.jsx("p",{className:"text-xs py-2",style:{color:"var(--color-text-muted)"},children:l("agenda.dayEmpty")}),q.map(ce=>t.jsx(lw,{item:ce,tagColors:i,onEdit:u,onConvert:f,onDelete:m},ce.id))]}),t.jsxs("div",{children:[t.jsx("h4",{className:"text-2xs uppercase tracking-wider mb-1.5",style:{color:"var(--color-text-muted)"},children:l("agenda.backlog")}),t.jsxs("div",{className:"flex flex-col gap-1.5",children:[oe.length===0&&t.jsx("p",{className:"text-xs py-1",style:{color:"var(--color-text-muted)"},children:l("agenda.backlogEmpty")}),oe.map(ce=>t.jsx(lw,{item:ce,tagColors:i,onEdit:u,onConvert:f,onDelete:m},ce.id))]})]})]})]}),C&&t.jsx(Ws,{x:C.x,y:C.y,onClose:()=>k(null),children:t.jsxs("button",{type:"button",className:en,onClick:()=>a(C.dateKey),children:[t.jsx(vn,{size:14}),l("planner.add")]})})]})}function lw({item:e,tagColors:s,onEdit:i,onConvert:a,onDelete:u}){const{t:f}=ht(),{confirm:m}=qn(),[o,l]=S.useState(!1),[d,p]=S.useState(!1),[h,g]=S.useState({top:0,left:0}),b=S.useRef(null),C=S.useRef(null),k=ZO(e.tags),x=e.status==="moved",y=S.useCallback(()=>{if(!b.current)return;const _=b.current.getBoundingClientRect(),w=window.innerWidth,E=window.innerHeight;let T=_.bottom+4;const j=C.current;if(j){const D=j.offsetWidth,N=j.offsetHeight;let R=_.right-D;R<8&&(R=8),R+D>w-8&&(R=w-8-D),T+N>E-8&&(T=_.top-N-4),g({top:T,left:R}),p(!0)}else g({top:T,left:Math.max(8,_.right-180)})},[]);return S.useEffect(()=>{if(!o){p(!1);return}y();const _=requestAnimationFrame(y),w=E=>{var j,D;const T=E.target;(j=b.current)!=null&&j.contains(T)||(D=C.current)!=null&&D.contains(T)||l(!1)};return document.addEventListener("mousedown",w),window.addEventListener("scroll",y,!0),window.addEventListener("resize",y),()=>{cancelAnimationFrame(_),document.removeEventListener("mousedown",w),window.removeEventListener("scroll",y,!0),window.removeEventListener("resize",y)}},[o,y]),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 ${Pu[e.status]||Pu.pending}`,children:f(`plannerStatus.${e.status}`)}),k.map(_=>t.jsx("span",{className:`px-1.5 py-0.5 rounded-md text-2xs font-medium ${Wa(s.get(_)||"default")}`,children:_},_))]})]}),t.jsxs("div",{className:"flex-shrink-0",children:[t.jsx("button",{ref:b,onClick:_=>{_.stopPropagation(),l(!o)},className:"p-1 text-warm-400 hover:text-warm-600 hover:bg-warm-100/50 rounded-lg transition-colors opacity-0 group-hover:opacity-100",children:t.jsx(rp,{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:h.top,left:h.left,opacity:d?1:0,backgroundColor:"var(--color-bg-card)",border:"1px solid var(--color-border)"},onClick:()=>l(!1),children:[!x&&t.jsxs(t.Fragment,{children:[t.jsxs("button",{onClick:()=>a(e,"todo"),className:"flex items-center gap-2 w-full px-3 py-1.5 text-xs hover:bg-warm-100 rounded-md transition-colors text-left",style:{color:"var(--color-text-primary)"},children:[t.jsx(Xw,{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(qi,{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(gi,{size:12})," ",f("planner.convertToTerminal")]})]}),t.jsxs("button",{onClick:async()=>{await m({message:f("planner.deleteConfirm"),danger:!0})&&u(e.id)},className:"flex items-center gap-2 w-full px-3 py-1.5 text-xs text-status-error hover:bg-status-error/10 rounded-md transition-colors text-left",children:[t.jsx(An,{size:12})," ",f("planner.delete")]})]}),document.body)]})]})}const cw={pending:0,in_progress:1,done:2,moved:3};function tB({plannerItems:e,existingTags:s,projectCliTool:i,onAddItem:a,onEditItem:u,onDeleteItem:f,onConvertToTodo:m,onConvertToSchedule:o,onConvertToSession:l,onUpdateTag:d,onDeleteTag:p,onExport:h,onImport:g,view:b,onChangeView:C}){const{t:k}=ht(),{warning:x}=Ls(),[y,_]=S.useState(!1),[w,E]=S.useState(null),[T,j]=S.useState(void 0),[D,N]=S.useState(""),[R,A]=S.useState(""),[B,O]=S.useState("created_at"),[F,U]=S.useState("desc"),[I,H]=S.useState(null),[W,K]=S.useState("todo"),[P,z]=S.useState(!1),[$,Y]=S.useState(!1),[q,oe]=S.useState(null),ce=S.useRef(null),ne=S.useRef(0),te=async()=>{if(!(!h||P)){z(!0);try{await h()}finally{z(!1)}}},G=()=>{var fe;!g||P||(fe=ce.current)==null||fe.click()},de=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)}}},he=fe=>!!(/\.(md|markdown)$/i.test(fe.name)||fe.type==="text/markdown"),be=fe=>Array.from(fe.dataTransfer.types).includes("Files"),ae=fe=>{!g||P||be(fe)&&(fe.preventDefault(),ne.current++,Y(!0))},De=fe=>{!g||P||be(fe)&&(fe.preventDefault(),fe.dataTransfer.dropEffect="copy")},Re=fe=>{g&&(fe.preventDefault(),ne.current=Math.max(0,ne.current-1),ne.current===0&&Y(!1))},ve=async fe=>{var Ce;if(!g||(fe.preventDefault(),ne.current=0,Y(!1),P))return;const Te=(Ce=fe.dataTransfer.files)==null?void 0:Ce[0];if(Te){if(!he(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=>!(R&&Te.status!==R||D&&!(Te.tags?(()=>{try{return JSON.parse(Te.tags)}catch{return[]}})():[]).includes(D)));return fe=[...fe].sort((Te,Ce)=>{let Ke=0;switch(B){case"title":Ke=Te.title.localeCompare(Ce.title);break;case"tags":{const Ze=Te.tags?(()=>{try{return JSON.parse(Te.tags).join(",")}catch{return""}})():"",ye=Ce.tags?(()=>{try{return JSON.parse(Ce.tags).join(",")}catch{return""}})():"";Ke=(Ze||"zzz").localeCompare(ye||"zzz");break}case"priority":Ke=Te.priority-Ce.priority;break;case"due_date":{const Ze=Te.due_date||"9999",ye=Ce.due_date||"9999";Ke=Ze.localeCompare(ye);break}case"status":Ke=(cw[Te.status]??9)-(cw[Ce.status]??9);break;case"created_at":Ke=Te.created_at.localeCompare(Ce.created_at);break}return F==="asc"?Ke:-Ke}),fe},[e,D,R,B,F]),nt=fe=>{B===fe?U(Te=>Te==="asc"?"desc":"asc"):(O(fe),U(fe==="priority"?"desc":"asc"))},ke=({field:fe})=>B!==fe?null:F==="asc"?t.jsx(u5,{size:12,className:"inline ml-0.5"}):t.jsx(i5,{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:D,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:R,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")})]}),h&&t.jsxs("button",{onClick:te,disabled:P||e.length===0,className:"btn-secondary text-xs py-2 whitespace-nowrap shrink-0 disabled:opacity-50",title:k("planner.exportTooltip"),children:[t.jsx(cm,{size:14,className:"inline-block shrink-0"}),k("planner.export")]}),g&&t.jsxs(t.Fragment,{children:[t.jsxs("button",{onClick:G,disabled:P,className:"btn-secondary text-xs py-2 whitespace-nowrap shrink-0 disabled:opacity-50",title:k("planner.importTooltip"),children:[t.jsx(nb,{size:14,className:"inline-block shrink-0"}),k("planner.import")]}),t.jsx("input",{ref:ce,type:"file",accept:".md,.markdown,text/markdown",className:"hidden",onChange:de})]}),!y&&!w&&t.jsxs("button",{onClick:()=>_(!0),className:"btn-primary text-xs py-2 whitespace-nowrap shrink-0",children:[t.jsx(vn,{size:14,className:"inline-block shrink-0"}),k("planner.add")]})]})]}),(y||w)&&t.jsx("div",{className:"mb-5",children:t.jsx(WO,{existingTags:s,editItem:w,initialDueDate:T,onSave:async fe=>{if(w){await u(w.id,fe),E(null);return}else{const Te=await a(fe);return _(!1),j(void 0),Te}},onCancel:()=>{_(!1),E(null),j(void 0)},onUpdateTag:d})}),b==="table"?t.jsxs("div",{className:"card relative",onDragEnter:g?ae:void 0,onDragOver:g?De:void 0,onDragLeave:g?Re:void 0,onDrop:g?ve:void 0,onContextMenu:fe=>{xi(fe)||(fe.preventDefault(),oe({x:fe.clientX,y:fe.clientY}))},children:[$&&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(nb,{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:AE,title:k("planner.empty"),description:k("planner.emptyHint")}):tt.map((fe,Te)=>t.jsx("div",{children:t.jsx($O,{item:fe,tagColors:Oe,existingTags:Me,onSave:async(Ce,Ke)=>{await u(Ce,Ke)},onDelete:()=>f(fe.id),onConvertToTodo:()=>{H(fe),K("todo")},onConvertToSchedule:()=>{H(fe),K("schedule")},onConvertToSession:()=>{H(fe),K("session")},onUpdateTag:d})},fe.id))]}):t.jsx(eB,{view:b,items:tt,tagColors:Oe,onQuickAdd:fe=>{E(null),j(fe),_(!0)},onEditItem:fe=>{_(!1),E(fe)},onConvert:(fe,Te)=>{H(fe),K(Te)},onDeleteItem:f,onUpdateRange:(fe,Te,Ce)=>{u(fe,{due_date:Te,end_date:Ce})}}),I&&t.jsx(OS,{item:I,mode:W,projectCliTool:i,onConvert:async fe=>{W==="todo"?await m(I.id,fe):W==="session"?await l(I.id,fe):await o(I.id,fe),H(null)},onClose:()=>H(null)}),q&&t.jsx(Ws,{x:q.x,y:q.y,onClose:()=>oe(null),children:t.jsxs("button",{type:"button",className:en,onClick:()=>{E(null),j(void 0),_(!0)},children:[t.jsx(vn,{size:14}),k("planner.add")]})})]})}const WS=S.createContext(null),nB=WS.Provider;function DP(){const e=S.useContext(WS);if(!e)throw new Error("usePlannerPage must be used within a PlannerPageProvider");return e}const sB=S.lazy(()=>qu(()=>import("./PlannerPageEditor-D6h0rQqh.js").then(e=>e.a),__vite__mapDeps([5,3,6,7,8]))),rB=800;function iB({pageId:e,projectId:s,projectCliTool:i,existingTags:a,onTitleChange:u,onConvertToTodo:f,onConvertToSchedule:m,onConvertToSession:o}){const{t:l}=ht(),[d,p]=S.useState(null),[h,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 rL(e).then(D=>{j||(p(D),k.current={title:D.title,content:D.content??null})}),()=>{j=!0}},[e]);const y=S.useCallback(()=>{x.current&&(clearTimeout(x.current),x.current=null);const{title:j,content:D}=k.current;return g("saving"),iL(e,{title:j,content:D??void 0}).then(()=>g("saved"))},[e]);S.useEffect(()=>()=>{x.current&&y()},[y]);const _=S.useCallback(()=>{x.current&&clearTimeout(x.current),g("saving"),x.current=setTimeout(()=>{y()},rB)},[y]),w=j=>{k.current.title=j,p(D=>D&&{...D,title:j}),u(e,j),_()},E=j=>{k.current.content=j,_()},T=S.useCallback((j,D,N)=>{C({item:j,mode:D,onDone:N})},[]);return d?t.jsxs(nB,{value:{projectId:s,pageId:e,projectCliTool:i,existingTags:a,openConvert:T},children:[t.jsxs("div",{className:"flex-1 min-w-0 flex flex-col",children:[t.jsxs("div",{className:"flex items-center gap-3 px-6 pt-5 pb-2",children:[t.jsx("input",{value:d.title,onChange:j=>w(j.target.value),placeholder:l("planner.pages.untitled"),className:"flex-1 bg-transparent text-2xl font-bold outline-none",style:{color:"var(--color-text-primary)"}}),t.jsx("span",{className:"text-2xs text-warm-400 flex-shrink-0",children:h==="saving"?l("planner.pages.saving"):h==="saved"?l("planner.pages.saved"):""})]}),t.jsx("div",{className:"flex-1 overflow-y-auto pb-6",children:t.jsx(S.Suspense,{fallback:null,children:t.jsx(sB,{pageId:e,initialContent:d.content??null,onChange:E})})})]}),b&&t.jsx(OS,{item:b.item,mode:b.mode,projectCliTool:i,onConvert:async j=>{const{item:D,mode:N,onDone:R}=b;N==="todo"?await f(D.id,j):N==="session"?await o(D.id,j):await m(D.id,j),R==null||R(),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"},uw=e=>({type:"bulletListItem"}),Fi=e=>({type:"checkListItem"}),dw=()=>({type:"tasklist"}),hw=()=>({type:"calendar"}),aB=[{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,"안건"),uw(),Rn(2,"논의"),Qo(),Rn(2,"액션 아이템"),dw()]},{id:"project",labelKey:"planner.tpl.project",descKey:"planner.tpl.project.desc",title:"프로젝트 플랜",blocks:[Rn(1,"프로젝트 플랜"),Rn(2,"개요"),Qo(),Rn(2,"마일스톤"),dw(),Rn(2,"일정"),hw(),Rn(2,"리스크 / 메모"),Qo()]},{id:"weekly",labelKey:"planner.tpl.weekly",descKey:"planner.tpl.weekly.desc",title:"위클리 플래너",blocks:[Rn(1,"위클리 플래너"),Rn(2,"이번 주 목표"),uw(),Rn(2,"요일별 할 일"),Rn(3,"월요일"),Fi(),Rn(3,"화요일"),Fi(),Rn(3,"수요일"),Fi(),Rn(3,"목요일"),Fi(),Rn(3,"금요일"),Fi(),Rn(3,"토요일"),Fi(),Rn(3,"일요일"),Fi(),Rn(2,"주간 일정"),hw()]}];function oB({onResize:e}){return t.jsx("div",{role:"separator","aria-orientation":"vertical",onPointerDown:s=>{s.preventDefault();const i=s.currentTarget;i.setPointerCapture(s.pointerId),document.body.style.cursor="col-resize",document.body.style.userSelect="none";let a=null,u=null;const f=()=>{if(a=null,u===null)return;const l=u;u=null,e(l)},m=l=>{u=l.clientX,a===null&&(a=requestAnimationFrame(f))},o=l=>{a!==null&&cancelAnimationFrame(a),a=null,l.type==="pointerup"&&u!==null&&f(),u=null,document.body.style.cursor="",document.body.style.userSelect="",i.removeEventListener("pointermove",m),i.removeEventListener("pointerup",o),i.removeEventListener("pointercancel",o)};i.addEventListener("pointermove",m),i.addEventListener("pointerup",o),i.addEventListener("pointercancel",o)},className:"w-1.5 shrink-0 cursor-col-resize bg-warm-300 hover:bg-accent active:bg-accent transition-colors"})}const fw=160,mw=480,pw="plannerSidebarWidth",gw="plannerSidebarCollapsed";function lB({projectId:e,...s}){const{t:i}=ht(),{confirm:a}=qn(),[u,f]=S.useState([]),[m,o]=S.useState({kind:"work"}),[l,d]=S.useState("table"),[p,h]=S.useState(!1),[g,b]=S.useState({top:0,left:0}),C=S.useRef(null),k=S.useRef(null),x=S.useRef(!1),[y,_]=S.useState(()=>{const K=Number(localStorage.getItem(pw));return K>=fw&&K<=mw?K:208}),w=S.useCallback(K=>{var $;const P=(($=k.current)==null?void 0:$.getBoundingClientRect().left)??0,z=Math.round(Math.max(fw,Math.min(mw,K-P)));_(z),localStorage.setItem(pw,String(z))},[]),[E,T]=S.useState(()=>localStorage.getItem(gw)==="1"),j=()=>T(K=>(localStorage.setItem(gw,K?"0":"1"),!K)),D=240,N=()=>{var P;const K=(P=C.current)==null?void 0:P.getBoundingClientRect();if(K){const z=Math.min(K.left,window.innerWidth-D-8);b({top:K.bottom+4,left:Math.max(8,z)})}h(!0)};S.useEffect(()=>{if(!p)return;const K=()=>h(!1),P=z=>{var $;($=C.current)!=null&&$.contains(z.target)||z.target.closest("[data-template-picker]")||h(!1)};return document.addEventListener("mousedown",P),window.addEventListener("scroll",K,!0),window.addEventListener("resize",K),()=>{document.removeEventListener("mousedown",P),window.removeEventListener("scroll",K,!0),window.removeEventListener("resize",K)}},[p]),S.useEffect(()=>{nL(e).then(K=>{f(K),x.current||(x.current=!0,K.length>0&&o({kind:"page",id:K[0].id}))})},[e]);const R=async K=>{h(!1);const P=await sL(e,K.title||i("planner.pages.untitled"),K.blocks?JSON.stringify(K.blocks):void 0);f(z=>[...z,P]),o({kind:"page",id:P.id})},A=async K=>{await a({message:i("planner.pages.deleteConfirm"),danger:!0})&&(await aL(K),f(P=>P.filter(z=>z.id!==K)),o(P=>P.kind==="page"&&P.id===K?{kind:"work"}:P))},B=S.useCallback((K,P)=>{f(z=>z.map($=>$.id===K?{...$,title:P}:$))},[]),O=()=>{o({kind:"work"}),d(K=>K==="table"?"month":K)},F=()=>{o({kind:"work"}),d("table")},U=m.kind==="work",I=U&&l!=="table",H=U&&l==="table",W=(K,P,z,$,Y)=>t.jsxs("div",{onClick:P,className:`group flex items-center gap-2 px-2.5 py-1.5 rounded-lg cursor-pointer transition-colors ${K?"":"hover:bg-warm-50"}`,style:K?{backgroundColor:"var(--color-bg-tertiary)"}:void 0,children:[z,t.jsx("span",{className:"flex-1 text-sm truncate",style:{color:"var(--color-text-primary)"},children:$}),Y]});return t.jsxs("div",{className:"flex gap-4",style:{minHeight:"70vh"},children:[E?t.jsx("div",{className:"flex-shrink-0 flex flex-col items-center card p-1.5",children:t.jsx("button",{onClick:j,className:"p-1 text-warm-400 hover:text-warm-600 transition-colors",title:i("sidebar.expand"),children:t.jsx(l1,{size:14})})}):t.jsxs(t.Fragment,{children:[t.jsxs("div",{ref:k,className:"flex-shrink-0 flex flex-col card p-2 overflow-y-auto",style:{width:y},children:[t.jsxs("div",{className:"flex items-center justify-between px-2.5 pt-1 pb-1",children:[t.jsx("span",{className:"text-2xs font-semibold uppercase tracking-wider text-warm-400",children:i("planner.view.pages")}),t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("button",{ref:C,onClick:()=>p?h(!1):N(),className:"text-warm-400 hover:text-warm-600 transition-colors",title:i("planner.pages.new"),children:t.jsx(vn,{size:14})}),t.jsx("button",{onClick:j,className:"text-warm-400 hover:text-warm-600 transition-colors",title:i("sidebar.collapse"),children:t.jsx(o1,{size:14})})]})]}),u.map(K=>W(m.kind==="page"&&m.id===K.id,()=>o({kind:"page",id:K.id}),t.jsx(tl,{size:14,className:"text-warm-400 flex-shrink-0"}),K.title||i("planner.pages.untitled"),t.jsx("button",{onClick:P=>{P.stopPropagation(),A(K.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")}),W(I,O,t.jsx(lm,{size:14,className:"text-warm-400 flex-shrink-0"}),i("planner.nav.calendar")),W(H,F,t.jsx(_u,{size:14,className:"text-warm-400 flex-shrink-0"}),i("planner.nav.list"))]}),t.jsx(oB,{onResize:w})]}),t.jsx("div",{className:"flex-1 min-w-0 flex flex-col",children:m.kind==="page"?t.jsx("div",{className:"card flex flex-col flex-1",children:t.jsx(iB,{pageId:m.id,projectId:e,projectCliTool:s.projectCliTool,existingTags:s.existingTags,onTitleChange:B,onConvertToTodo:s.onConvertToTodo,onConvertToSchedule:s.onConvertToSchedule,onConvertToSession:s.onConvertToSession},m.id)}):t.jsx(tB,{...s,view:l,onChangeView:d})}),p&&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:D,backgroundColor:"var(--color-bg-card)",border:"1px solid var(--color-border)"},children:aB.map(K=>t.jsxs("button",{onClick:()=>R(K),className:"w-full text-left px-3 py-2 hover:bg-warm-100 transition-colors",children:[t.jsx("div",{className:"text-sm font-medium",style:{color:"var(--color-text-primary)"},children:i(K.labelKey)}),t.jsx("div",{className:"text-2xs text-warm-400 mt-0.5",children:i(K.descKey)})]},K.id))}),document.body)]})}const qS="webPanelTabs",cB="plannerWebPanelUrl",Gp="https://www.notion.so",uB="electronAPI"in window;function dB(e){const s=e.trim();return s?/^https?:\/\//i.test(s)?s:`https://${s}`:Gp}function Km(e=""){return{id:Date.now().toString(36)+Math.random().toString(36).slice(2,8),src:e,url:e,title:""}}function hB(){var s;try{const i=JSON.parse(localStorage.getItem(qS)||"");if((s=i.tabs)!=null&&s.length){const a=i.tabs.map(({id:f,url:m})=>({id:f,src:m,url:m,title:""})),u=a.some(f=>f.id===i.activeId)?i.activeId:a[0].id;return{tabs:a,activeId:u}}}catch{}const e=Km(localStorage.getItem(cB)||Gp);return{tabs:[e],activeId:e.id}}function fB(){const{t:e}=ht(),[{tabs:s,activeId:i},a]=S.useState(hB),u=s.find(y=>y.id===i)??s[0],[f,m]=S.useState(u.url),[o,l]=S.useState(!1),d=S.useRef(null),p=S.useRef(null);S.useEffect(()=>{localStorage.setItem(qS,JSON.stringify({tabs:s.map(({id:y,url:_})=>({id:y,url:_})),activeId:i}))},[s,i]),S.useEffect(()=>{m(u.url)},[u.id,u.url]);const h=S.useCallback((y,_)=>{a(w=>({...w,tabs:w.tabs.map(E=>E.id===y?{...E,..._}:E)}))},[]),g=S.useCallback((y="")=>{var w;const _=Km(y);a(E=>({tabs:[...E.tabs,_],activeId:_.id})),y||(w=d.current)==null||w.focus()},[]),b=y=>{a(_=>{const w=_.tabs.findIndex(T=>T.id===y),E=_.tabs.filter(T=>T.id!==y);if(E.length===0){const T=Km();return{tabs:[T],activeId:T.id}}return _.activeId!==y?{..._,tabs:E}:{tabs:E,activeId:E[Math.min(w,E.length-1)].id}})},C=()=>{const y=dB(f);m(y),h(u.id,{src:y,url:y})};S.useEffect(()=>{var _;const y=window.electronAPI;return(_=y==null?void 0:y.onWebPanelOpenUrl)==null?void 0:_.call(y,w=>g(w))},[g]),S.useEffect(()=>{const y=p.current;if(!y)return;const _=()=>{y.style.pointerEvents="none"},w=()=>{y.style.pointerEvents=""};return window.addEventListener("mousedown",_,!0),window.addEventListener("mouseup",w,!0),window.addEventListener("blur",w),()=>{window.removeEventListener("mousedown",_,!0),window.removeEventListener("mouseup",w,!0),window.removeEventListener("blur",w)}},[]);const k=S.useCallback(y=>{if(!y)return;const _=y.dataset.tabId,w=T=>h(_,{title:T.title}),E=T=>{const{url:j,isMainFrame:D}=T;D!==!1&&h(_,{url:j})};return y.addEventListener("page-title-updated",w),y.addEventListener("did-navigate",E),y.addEventListener("did-navigate-in-page",E),()=>{y.removeEventListener("page-title-updated",w),y.removeEventListener("did-navigate",E),y.removeEventListener("did-navigate-in-page",E)}},[h]),x=y=>{if(y.title)return y.title;try{return new URL(y.url).hostname}catch{return e("web.newTab")}};return t.jsxs("div",{className:o?"fixed inset-0 z-modal flex flex-col":"flex flex-col flex-1 min-h-0",style:o?{backgroundColor:"var(--color-bg-card)"}:void 0,children:[t.jsxs("div",{role:"tablist",className:"flex items-end gap-0.5 px-2 border-b border-theme-border overflow-x-auto",children:[s.map(y=>t.jsxs("div",{role:"tab","aria-selected":y.id===i,onClick:()=>a(_=>({..._,activeId:y.id})),className:`flex items-center gap-1 px-3 py-1.5 text-xs whitespace-nowrap cursor-pointer transition-colors ${y.id===i?"border-b-2 border-accent text-accent font-medium":"text-theme-text-secondary hover:text-theme-text"}`,children:[t.jsx("span",{className:"truncate max-w-[160px]",children:x(y)}),t.jsx("button",{type:"button",onClick:_=>{_.stopPropagation(),b(y.id)},className:"p-0.5 rounded hover:bg-theme-hover",title:e("web.closeTab"),"aria-label":e("web.closeTab"),children:t.jsx(Vt,{size:12})})]},y.id)),t.jsx("button",{type:"button",onClick:()=>g(),className:"p-1 mb-1 text-warm-400 hover:text-warm-600 hover:bg-warm-100 rounded-md transition-colors flex-shrink-0",title:e("web.newTab"),"aria-label":e("web.newTab"),children:t.jsx(vn,{size:14})})]}),t.jsxs("form",{onSubmit:y=>{y.preventDefault(),C()},className:"flex items-center gap-2 p-2 border-b border-theme-border",children:[t.jsx("input",{ref:d,value:f,onChange:y=>m(y.target.value),placeholder:e("web.urlPlaceholder"),className:"input-field flex-1",spellCheck:!1}),t.jsx(Bt,{type:"submit",size:"sm",children:e("web.go")}),t.jsx("button",{type:"button",onClick:()=>l(y=>!y),className:"p-1 text-warm-400 hover:text-warm-600 hover:bg-warm-100 rounded-md transition-colors flex-shrink-0",title:e(o?"web.exitFullscreen":"web.fullscreen"),children:o?t.jsx(Cl,{size:14}):t.jsx(fi,{size:14})})]}),t.jsx("div",{ref:p,className:"flex-1 min-h-0 flex flex-col",children:uB?s.map(y=>y.src?S.createElement("webview",{key:y.id,ref:k,"data-tab-id":y.id,src:y.src,partition:"persist:webpanel",allowpopups:"",className:y.id===i?"flex-1 min-h-0":"hidden"}):y.id===i&&t.jsx("div",{className:"flex-1 flex items-center justify-center text-sm text-theme-text-secondary",children:e("web.emptyTab")},y.id)):t.jsxs("div",{className:"flex-1 flex flex-col items-center justify-center gap-3 text-sm text-theme-text-secondary",children:[t.jsx("span",{children:e("web.desktopOnly")}),t.jsxs(Bt,{size:"sm",className:"flex items-center gap-1.5",onClick:()=>window.open(u.url||Gp,"_blank","noopener"),children:[t.jsx(ar,{size:14}),e("web.openExternal")]})]})})]})}const mB=S.lazy(()=>qu(()=>import("./AnalyticsPanel-CulPdMvq.js"),__vite__mapDeps([9,7,3,2]))),pB=S.lazy(()=>qu(()=>import("./VaultLayout-CvzS1rr3.js"),__vite__mapDeps([10,6,1,2,3,4])));function gB({onEvent:e,connected:s,sendMessage:i,subscribeBinary:a}){const{id:u}=Jm(),[f,m]=S.useState(null),[o,l]=S.useState([]),[d,p]=S.useState([]),[h,g]=S.useState(null),[b,C]=S.useState([]),[k,x]=S.useState([]),[y,_]=S.useState([]),[w,E]=S.useState([]),[T,j]=Gw(),D=["tasks","discussions","schedules","analytics"],N=T.get("tab")||"tasks",[R,A]=S.useState(D.includes(N)?"automation":N),[B,O]=S.useState(D.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]),U=S.useCallback(Q=>{A("automation"),O(Q),j(Q==="tasks"?{}:{tab:Q},{replace:!0})},[j]),[I,H]=S.useState(!0),[W,K]=S.useState(!1),[P,z]=S.useState(new Set),[$,Y]=S.useState(0),{t:q}=ht(),{success:oe,error:ce,info:ne}=Ls(),{sendNotification:te}=up(),G=S.useRef([]);S.useEffect(()=>{G.current=b},[b]),S.useEffect(()=>{u&&Promise.all([$N(u),vf(u),bb(u),yb(u),S4(),I1(u),Wc(u),qc(u)]).then(([Q,ze,ue,Fe,Ve,ft,Ne,at])=>{m(Q),l(ze),p(ue),C(Fe),x(ft),_(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(()=>K(!0)).finally(()=>H(!1))},[u]);const de=S.useRef(o);de.current=o,S.useEffect(()=>{if(!u)return;const Q=setInterval(()=>{de.current.some(ue=>ue.status==="running")&&vf(u).then(ue=>{l(Fe=>Fe.map(Ve=>{const ft=ue.find(Ne=>Ne.id===Ve.id);return ft&&ft.status!==Ve.status?ft:Ve}))}).catch(()=>{})},5e3);return()=>clearInterval(Q)},[u]);const he=S.useRef(s);S.useEffect(()=>{s&&!he.current&&u&&Promise.all([vf(u),bb(u),yb(u)]).then(([Q,ze,ue])=>{l(Q),p(ze),C(ue)}).catch(()=>{}),he.current=s},[s,u]),S.useEffect(()=>e(Q=>{if(Q.type==="todo:status-changed"&&Q.todoId&&Q.status){if(l(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")&&Y(ze=>ze+1),Q.status==="completed"||Q.status==="failed"){const ze=de.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;l(ue=>ue.some(Fe=>Fe.id===ze.id)?ue:[...ue,ze])}if(Q.type==="schedule:status-changed"&&Q.scheduleId&&p(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=G.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 be=S.useCallback(async(Q,ze,ue,Fe,Ve,ft,Ne,at,bt,Ct)=>{if(!u)return;const Gt=await xb(u,{title:Q,description:ze,cli_tool:ue,depends_on:Ve,max_turns:ft??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 z1(Gt.id,Fe.map(Pn=>({name:Pn.name,data:Pn.data})));Gt.images=JSON.stringify(an.images)}l(an=>[...an,Gt])},[u]),ae=S.useCallback((Q,ze=[])=>{const ue=Q.split("/").filter(Boolean).pop()??Q,Fe=[Q,...ze].map(Ve=>`@${Ve}`).join(`
|
|
681
|
+
${$}`:""}`,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:P,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:Y=>Y.stopPropagation(),onClick:Y=>{Y.stopPropagation(),o(H)},"aria-label":"close-tab",title:_("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(Vt,{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:`${_("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(vn,{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(aO,{sessionId:e.activeTab,sendMessage:h}),t.jsx("button",{"data-no-drag":!0,onMouseDown:H=>H.stopPropagation(),onClick:D,"aria-label":"refresh-terminal",title:`${_("session.refresh")||"Refresh rendering"} (F5 · Ctrl+Shift+R) — ${_("session.refresh.hint")||"Rebuild the terminal view (PTY stays running)"}`,style:er,children:t.jsx(hN,{size:12})}),t.jsx("button",{"data-no-drag":!0,onMouseDown:H=>H.stopPropagation(),onClick:()=>E(-1),"aria-label":"decrease-font",title:`${_("session.fontDecrease")||"Decrease font size"} (${w}px) · Ctrl+- · Ctrl+wheel`,style:er,children:t.jsx(BN,{size:14})}),t.jsx("button",{"data-no-drag":!0,onMouseDown:H=>H.stopPropagation(),onClick:()=>E(1),"aria-label":"increase-font",title:`${_("session.fontIncrease")||"Increase font size"} (${w}px) · Ctrl+= · Ctrl+wheel`,style:er,children:t.jsx(zN,{size:14})}),t.jsx(rO,{sessionId:e.activeTab}),y&&t.jsxs(t.Fragment,{children:[e.tabs.length>1&&y.onApplyLayoutPreset&&t.jsxs(t.Fragment,{children:[t.jsx("button",{"data-no-drag":!0,onMouseDown:H=>H.stopPropagation(),onClick:()=>{var H;return(H=y.onApplyLayoutPreset)==null?void 0:H.call(y,"single")},"aria-label":"single-pane",title:_("session.layout.single"),style:er,children:t.jsx(Gi,{size:12})}),t.jsx("button",{"data-no-drag":!0,onMouseDown:H=>H.stopPropagation(),onClick:()=>{var H;return(H=y.onApplyLayoutPreset)==null?void 0:H.call(y,"columns")},"aria-label":"two-columns",title:_("session.layout.columns"),style:er,children:t.jsx(s1,{size:14})}),t.jsx("button",{"data-no-drag":!0,onMouseDown:H=>H.stopPropagation(),onClick:()=>{var H;return(H=y.onApplyLayoutPreset)==null?void 0:H.call(y,"grid")},"aria-label":"grid-layout",title:_("session.layout.grid"),style:er,children:t.jsx(i1,{size:14})})]}),y.onToggleMaximize&&t.jsx("button",{"data-no-drag":!0,onMouseDown:H=>H.stopPropagation(),onClick:y.onToggleMaximize,"aria-label":"toggle-maximize",title:`${y.isMaximized?_("session.restoreSize"):_("session.maximize")} · ${_("session.maximizeHint")}`,style:er,children:y.isMaximized?t.jsx(Cl,{size:14}):t.jsx(fi,{size:14})}),y.onPopOutGroup&&t.jsx("button",{"data-no-drag":!0,onMouseDown:H=>H.stopPropagation(),onClick:y.onPopOutGroup,"aria-label":"pop-out",title:`${_("session.popOut")||"Pop out to separate window"} (Ctrl+Shift+O)`,style:er,children:t.jsx(ar,{size:14})}),t.jsx("button",{"data-no-drag":!0,onMouseDown:H=>H.stopPropagation(),onClick:y.onMinimizeGroup,"aria-label":"minimize",title:`${_("session.minimize")||"Minimize"} (Ctrl+Shift+M)`,style:er,children:t.jsx(ap,{size:14})}),t.jsx("button",{"data-no-drag":!0,onMouseDown:H=>H.stopPropagation(),onClick:y.onCloseGroup,"aria-label":"close",title:`${_("session.close")||"Close"} (Ctrl+Shift+X)`,style:er,children:t.jsx(Vt,{size:14})})]})]}),t.jsx("div",{"data-group-id":i,"data-stack-path":s.join("."),ref:H=>{if(!H){p(s,null);return}const W=H.getBoundingClientRect();p(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 K=f[H]||{intent:"open",nonce:0};return t.jsx(yS,{session:W,visible:H===e.activeTab,intent:K.intent,intentNonce:K.nonce,onClose:()=>d(H),sendMessage:h,subscribeBinary:g,onEvent:b,onCycleTab:U,remountKey:T[H]||0},H)})})]})}const er={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 hO({orientation:e,onDragStart:s,onDrag:i,onDragEnd:a}){const u=S.useCallback(m=>{if(m.button!==0)return;m.preventDefault(),m.stopPropagation();const o=m.clientX,l=m.clientY;s();let d=!1;const p=()=>{d||(d=!0,window.removeEventListener("mousemove",C),window.removeEventListener("mouseup",k),window.removeEventListener("blur",h),window.removeEventListener("keydown",g),document.removeEventListener("visibilitychange",b))},h=()=>{p(),a()},g=x=>{x.key==="Escape"&&h()},b=()=>{document.hidden&&h()},C=x=>{const y=e==="horizontal"?x.clientX-o:x.clientY-l;i(y)},k=()=>{p(),a()};window.addEventListener("mousemove",C),window.addEventListener("mouseup",k),window.addEventListener("blur",h),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 Ip(e){const{node:s,path:i,onSplitSizes:a,...u}=e;return s.kind==="stack"?t.jsx(Pp,{stack:s,path:i,...u}):t.jsx(fO,{split:s,path:i,onSplitSizes:a,stackProps:u})}const Qy=80;function fO({split:e,path:s,onSplitSizes:i,stackProps:a}){const u=e.orientation==="horizontal",f=S.useRef(null),m=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((l,d)=>t.jsxs(S.Fragment,{children:[t.jsx("div",{ref:p=>{m.current[d]=p},style:{flex:`0 0 ${e.sizes[d]}%`,display:"flex",flexDirection:"column",minWidth:0,minHeight:0,overflow:"hidden"},children:t.jsx(Ip,{node:l,path:[...s,d],onSplitSizes:i,...a})}),d<e.children.length-1&&t.jsx(hO,{orientation:e.orientation,onDragStart:()=>{const p=f.current;if(!p)return;const h=e.sizes.slice();o.current={i:d,initialSizes:h,finalSizes:h.slice(),total:u?p.clientWidth:p.clientHeight}},onDrag:p=>{const h=o.current;if(!h||h.total<=0)return;const g=h.initialSizes[h.i]/100*h.total,b=h.initialSizes[h.i+1]/100*h.total,C=g+b,k=Math.max(Qy,Math.min(C-Qy,g+p)),x=C-k,y=k/h.total*100,_=x/h.total*100,w=m.current[h.i],E=m.current[h.i+1];w&&(w.style.flexBasis=`${y}%`),E&&(E.style.flexBasis=`${_}%`);const T=h.initialSizes.slice();T[h.i]=y,T[h.i+1]=_,h.finalSizes=T},onDragEnd:()=>{const p=o.current;p&&i(s,p.finalSizes),o.current=null}})]},d))})}const Et=28,un=68;function Zu(e,s,i){const a=e-i.x,u=s-i.y;if(a<0||u<0||a>i.w||u>i.h)return null;const f=a-i.w/2,m=u-i.h/2;return Math.abs(f)<=Et&&Math.abs(m)<=Et?"center":f>=-un-Et&&f<=-un+Et&&Math.abs(m)<=Et?"left":f>=un-Et&&f<=un+Et&&Math.abs(m)<=Et?"right":m>=-un-Et&&m<=-un+Et&&Math.abs(f)<=Et?"top":m>=un-Et&&m<=un+Et&&Math.abs(f)<=Et?"bottom":null}function Tu(e,s){const i=document.elementsFromPoint(e,s);for(const a of i){const u=a.closest("[data-group-id][data-stack-path]");if(!u)continue;const f=u.dataset.stackPath||"",m=f===""?[]:f.split(".").map(Number),o=u.getBoundingClientRect(),l={x:o.left,y:o.top,w:o.width,h:o.height};return{groupId:u.dataset.groupId||"",path:m,rect:l,zone:Zu(e,s,l)}}return null}function mO(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 Hm=un*2+12;function _S(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>=-Hm-Et&&f<=-Hm+Et&&Math.abs(u)<=Et?"popout":null}function SS(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 SS(e,u,s,i,a)}function Ha(){const e=document.querySelector("[data-app-sidebar]");return Math.max(0,e?e.getBoundingClientRect().right:0)}function kS({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-Hm-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?mO(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",m=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 ${m}`,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(pO,{kind:a,fill:f})})}function pO({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(ar,{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 Lr(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 ed(e,s){if(e.kind==="stack")return e.tabs.includes(s)?[]:null;for(let i=0;i<e.children.length;i++){const a=ed(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 Ru(e){return e.kind==="stack"?[e.activeTab]:e.children.flatMap(Ru)}function gO(e,s){const i=gn(e);if(i.length<=1||s==="single")return Lr(i,Ru(e)[0]||i[0]);const a=Math.min(s==="columns"?2:4,i.length),u=Array.from({length:a},()=>[]);i.forEach((h,g)=>u[g%a].push(h));const f=new Set(Ru(e)),m=u.map(h=>Lr(h,h.find(g=>f.has(g))||h[0]));if(s==="columns"||m.length<=2)return{kind:"split",orientation:"horizontal",children:m,sizes:m.map(()=>100/m.length)};const o=m.slice(0,2),l=m.slice(2),d=h=>h.length===1?h[0]:{kind:"split",orientation:"horizontal",children:h,sizes:h.map(()=>100/h.length)};return{kind:"split",orientation:"vertical",children:[d(o),d(l)],sizes:[50,50]}}function Wi(e,s){return CS(e,s)}function CS(e,s){if(e.kind==="stack"){if(!e.tabs.includes(s))return e;const f=e.tabs.filter(o=>o!==s);if(f.length===0)return null;const m=e.activeTab===s?f[0]:e.activeTab;return{kind:"stack",tabs:f,activeTab:m}}const i=[],a=[];for(let f=0;f<e.children.length;f++){const m=CS(e.children[f],s);m!==null&&(i.push(m),a.push(e.sizes[f]))}if(i.length===0)return null;if(i.length===1)return i[0];const u=a.reduce((f,m)=>f+m,0)||1;return{kind:"split",orientation:e.orientation,children:i,sizes:a.map(f=>f/u*100)}}function $i(e,s,i){return td(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 td(e,s,m=>({kind:"split",orientation:u,children:f?[a,m]:[m,a],sizes:[50,50]}))}function td(e,s,i){if(s.length===0)return Mu(i(e));if(e.kind!=="split")throw new Error("replaceAt: path traverses non-split");const[a,...u]=s;if(a<0||a>=e.children.length)throw new Error("replaceAt: bad path");const f=e.children.map((m,o)=>o===a?td(m,u,i):m);return Mu({...e,children:f})}function Mu(e){if(e.kind==="stack")return e;const s=e.children.map(Mu),i=[],a=[];for(let f=0;f<s.length;f++){const m=s[f],o=e.sizes[f]??100/s.length;if(m.kind==="split"&&m.orientation===e.orientation){const l=m.sizes.reduce((d,p)=>d+p,0)||1;for(let d=0;d<m.children.length;d++)i.push(m.children[d]),a.push(m.sizes[d]/l*o)}else i.push(m),a.push(o)}if(i.length===1)return i[0];const u=a.reduce((f,m)=>f+m,0)||1;return{kind:"split",orientation:e.orientation,children:i,sizes:a.map(f=>f/u*100)}}function 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 jS(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=>jS(a,s,i))}}function ES(e,s,i){return td(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 xO(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(d=>d!==s);if(!f)return null;const m=Wi(e,s);if(!m)return null;const o=ed(m,f);if(!o)return null;const l=a==="center"?$i(m,o,s):$a(m,o,a,Lr([s]));return Ps(l,s)}function vO(e,s){const i=gn(e);let a=e;for(const u of i){if(!a)break;s.has(u)||(a=Wi(a,u))}return a}const tu=320,nu=200,su=80,ru=22,bO=4,Zy=8,ii=10,iu=60,yO=12;function ai(e,s,i){return Math.max(s,Math.min(i,e))}function wO(e,s,i,a){const u=e<=Zy,f=e>=i-Zy;if(!u&&!f)return null;const m=a/3,o=a*2/3;return u?s<m?"top-left":s>o?"bottom-left":"left":s<m?"top-right":s>o?"bottom-right":"right"}function ew(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 _O(e,s,i,a,u){let f=e,m=s;const o=f,l=f+i,d=m,p=m+a;for(const h of u){const g=h.x,b=h.x+h.w,C=h.y,k=h.y+h.h;d<k&&p>C&&(Math.abs(o-b)<=ii?f=b:Math.abs(l-g)<=ii?f=g-i:Math.abs(o-g)<=ii?f=g:Math.abs(l-b)<=ii&&(f=b-i)),o<b&&l>g&&(Math.abs(d-k)<=ii?m=k:Math.abs(p-C)<=ii?m=C-a:Math.abs(d-C)<=ii?m=C:Math.abs(p-k)<=ii&&(m=k-a))}return{x:f,y:m}}function SO({group:e,sessionsById:s,neighbors:i,isTopmost:a,zIndex:u,sendMessage:f,subscribeBinary:m,onEvent:o}){const{t:l}=ht(),d=tS("(max-width: 767px)"),p=RS(),h=S.useRef(null),[g,b]=S.useState(!1),C=S.useRef(null),[k,x]=S.useState(null),y=S.useRef({x:e.x,y:e.y,w:e.w,h:e.h});y.current={x:e.x,y:e.y,w:e.w,h:e.h};const[_,w]=S.useState(null),E=S.useRef(null),[T,j]=S.useState(!1),[D,N]=S.useState(null),R=S.useRef(null),A=S.useRef(i);A.current=i;const[B,O]=S.useState(null),F=S.useRef(null),U=S.useCallback((ae,De)=>{if(d||g||ae.button!==0||ae.target.closest("[data-no-drag]"))return;ae.preventDefault(),p.focus(gn(e.root)[0]||"");const ve=ae.clientX,Me=ae.clientY,Oe={...y.current},tt=h.current,nt=window.innerWidth,ke=window.innerHeight,fe=Ha();let Te=!1,Ce="";De&&tt&&(Ce=tt.style.pointerEvents,tt.style.pointerEvents="none");let Ke=!1;const Ze=()=>{Ke||(Ke=!0,window.removeEventListener("mousemove",X),window.removeEventListener("mouseup",me),window.removeEventListener("blur",ye),window.removeEventListener("keydown",Be),document.removeEventListener("visibilitychange",Z),De&&tt&&(tt.style.pointerEvents=Ce))},ye=()=>{Ze(),F.current=null,O(null),E.current=null,w(null),R.current=null,N(null),j(!1),p.setGroupGeometry(e.id,{...y.current})},Be=se=>{se.key==="Escape"&&ye()},Z=()=>{document.hidden&&ye()};let _e=!1;const X=se=>{if(_e)return;{const qe=window.screenX,Ee=window.screenY,st=qe+window.outerWidth,lt=Ee+window.outerHeight;if(se.screenX<qe-iu||se.screenX>st+iu||se.screenY<Ee-iu||se.screenY>lt+iu){_e=!0,Ze(),F.current=null,O(null),E.current=null,w(null),R.current=null,N(null),j(!1),p.setGroupGeometry(e.id,{...y.current}),p.popOutGroup(e.id,{atScreenX:se.screenX,atScreenY:se.screenY});return}}const ie=se.clientX-ve,J=se.clientY-Me;let ee=ai(Oe.x+ie,-(Oe.w-su),nt-su),pe=ai(Oe.y+J,0,ke-ru);const we=A.current;if(we.length>0){const qe=_O(ee,pe,Oe.w,Oe.h,we);ee=qe.x,pe=qe.y}if(tt&&(tt.style.left=`${ee}px`,tt.style.top=`${pe}px`),y.current.x=ee,y.current.y=pe,De){let qe=null;const Ee=document.elementFromPoint(se.clientX,se.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:Zu(se.clientX,se.clientY,dt)}}}F.current=qe,O(qe?{rect:qe.rect,zone:qe.zone}:null)}!Te&&Math.hypot(se.clientX-ve,se.clientY-Me)>=yO&&(Te=!0,j(!0),e.dock&&p.setGroupDock(e.id,null));const je=De&&F.current&&F.current.zone,$e=je||!Te?null:_S(se.clientX,se.clientY,nt,ke);$e!==R.current&&(R.current=$e,N($e));const Je=je||$e?null:wO(se.clientX,se.clientY,nt,ke);Je!==E.current&&(E.current=Je,w(Je))},me=se=>{Ze(),j(!1);const ie=R.current;if(R.current=null,N(null),De&&F.current&&F.current.zone){const ee=F.current;p.dockGroup(e.id,ee.groupId,ee.path,ee.zone),F.current=null,O(null),E.current=null,w(null);return}if(ie==="popout"){F.current=null,O(null),E.current=null,w(null),p.setGroupGeometry(e.id,{...y.current}),p.popOutGroup(e.id,{atScreenX:se.screenX,atScreenY:se.screenY});return}if(ie&&ie!=="max"){const ee=vl(ie,nt,ke,fe);tt&&(tt.style.left=`${ee.x}px`,tt.style.top=`${ee.y}px`,tt.style.width=`${ee.w}px`,tt.style.height=`${ee.h}px`),y.current=ee,F.current=null,O(null),E.current=null,w(null),p.setGroupDock(e.id,ie);return}const J=ie?vl(ie,nt,ke,fe):E.current?ew(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`),y.current=J,E.current=null,w(null)),F.current=null,O(null),p.setGroupGeometry(e.id,{...y.current})};window.addEventListener("mousemove",X),window.addEventListener("mouseup",me),window.addEventListener("blur",ye),window.addEventListener("keydown",Be),document.addEventListener("visibilitychange",Z)},[d,g,p,e.id,e.root,e.dock]),I=S.useCallback(ae=>U(ae,!1),[U]),H=S.useCallback(ae=>U(ae,!0),[U]),W=S.useCallback(ae=>De=>{if(d||g||De.button!==0)return;De.preventDefault(),De.stopPropagation();const Re=De.clientX,ve=De.clientY,Me={...y.current},Oe=h.current,tt=window.innerWidth,nt=window.innerHeight,ke=Be=>{const Z=Be.clientX-Re,_e=Be.clientY-ve;let X=Me.x,me=Me.y,se=Me.w,ie=Me.h;ae.includes("e")?se=ai(Me.w+Z,tu,Math.max(tu,tt-Me.x)):ae.includes("w")&&(X=ai(Me.x+Z,0,Me.x+Me.w-tu),se=Me.x+Me.w-X),ae.includes("s")?ie=ai(Me.h+_e,nu,Math.max(nu,nt-Me.y)):ae.includes("n")&&(me=ai(Me.y+_e,0,Me.y+Me.h-nu),ie=Me.y+Me.h-me),Oe&&(Oe.style.left=`${X}px`,Oe.style.top=`${me}px`,Oe.style.width=`${se}px`,Oe.style.height=`${ie}px`),y.current={x:X,y:me,w:se,h:ie}};let fe=!1;const Te=()=>{fe||(fe=!0,window.removeEventListener("mousemove",ke),window.removeEventListener("mouseup",ye),window.removeEventListener("blur",Ce),window.removeEventListener("keydown",Ke),document.removeEventListener("visibilitychange",Ze))},Ce=()=>{Te(),p.setGroupGeometry(e.id,{...y.current})},Ke=Be=>{Be.key==="Escape"&&Ce()},Ze=()=>{document.hidden&&Ce()},ye=()=>{Te(),p.setGroupGeometry(e.id,{...y.current})};window.addEventListener("mousemove",ke),window.addEventListener("mouseup",ye),window.addEventListener("blur",Ce),window.addEventListener("keydown",Ke),document.addEventListener("visibilitychange",Ze)},[d,g,p,e.id]);S.useEffect(()=>{if(d||e.dock)return;const ae=()=>{const De=window.innerWidth,Re=window.innerHeight,ve=y.current,Me=ai(ve.x,-(ve.w-su),De-su),Oe=ai(ve.y,0,Re-ru);(Me!==ve.x||Oe!==ve.y)&&p.setGroupGeometry(e.id,{...ve,x:Me,y:Oe})};return window.addEventListener("resize",ae),()=>window.removeEventListener("resize",ae)},[d,p,e.id,e.dock]);const K=S.useCallback(ae=>{x(ae),p.setActiveTab(e.id,ae),p.focus(ae)},[p,e.id]),P=S.useCallback(ae=>{x(ae),p.focus(ae)},[p]),z=S.useCallback(ae=>{p.close(ae)},[p]),$=S.useCallback((ae,De,Re)=>{p.beginTabDrag(e.id,ae,De,Re)},[p,e.id]),Y=S.useCallback(ae=>{p.close(ae)},[p]),q=S.useCallback((ae,De)=>{p.setSplitSizes(e.id,ae,De)},[p,e.id]),oe=Ru(e.root),ce=gn(e.root);S.useEffect(()=>{k&&ce.includes(k)||x(oe[0]||ce[0]||null)},[k,oe,ce]);const ne=S.useCallback(()=>{if(g){const ae=C.current;ae&&p.setGroupGeometry(e.id,ae),C.current=null,b(!1);return}C.current={...y.current},e.dock&&p.setGroupDock(e.id,null),p.setGroupGeometry(e.id,{x:6,y:6,w:Math.max(tu,window.innerWidth-12),h:Math.max(nu,window.innerHeight-12)}),b(!0)},[p,e.id,g,e.dock]),te=ae=>{const De=/Mac|iPhone|iPad|iPod/.test(navigator.platform),Re=De?ae.metaKey:ae.ctrlKey,ve=De?ae.ctrlKey:ae.metaKey;if(!Re||ve||ae.altKey||!ae.shiftKey)return;const Me=ae.key.toLowerCase();Me==="o"?(ae.preventDefault(),p.popOutGroup(e.id)):Me==="m"?(ae.preventDefault(),p.minimizeGroup(e.id)):Me==="x"&&(ae.preventDefault(),p.closeGroup(e.id))};if(d){const ae=oe[0],De=ae?s.get(ae):null;if(!De)return null;const Re=e.intents[ae]??{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:ru,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:()=>p.closeGroup(e.id),style:oi,"aria-label":"close",children:t.jsx(Vt,{size:14})})]}),t.jsx("div",{style:{flex:1,position:"relative",minHeight:0},children:t.jsx(yS,{session:De,visible:!0,intent:Re.intent,intentNonce:Re.nonce,onClose:()=>p.close(ae),sendMessage:f,subscribeBinary:m,onEvent:o})})]}),document.body)}const G=_?(()=>{const ae=window.innerWidth,De=window.innerHeight,Re=ew(_,ae,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,de=(()=>{var De;if(ce.length===0)return"";const ae=((De=s.get(ce[0]))==null?void 0:De.title)||ce[0];return ce.length===1?ae:`${ae} +${ce.length-1}`})(),he=e.root.kind==="split",be=rn.createPortal(t.jsxs("div",{ref:h,onKeyDown:te,onMouseDown:he?()=>p.focus(ce[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:[he&&t.jsxs("div",{onMouseDown:I,onDoubleClick:ae=>{ae.target.closest("button")||ne()},style:{height:ru,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:bO,flexShrink:0},children:oe.map((ae,De)=>t.jsx("div",{style:{flex:1,background:e.colors[ae]||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:de}),ce.length>1&&t.jsxs(t.Fragment,{children:[t.jsx("button",{"data-no-drag":!0,onMouseDown:ae=>ae.stopPropagation(),onClick:()=>p.applyLayoutPreset(e.id,"single"),style:oi,"aria-label":"single-pane",title:l("session.layout.single"),children:t.jsx(Gi,{size:12})}),t.jsx("button",{"data-no-drag":!0,onMouseDown:ae=>ae.stopPropagation(),onClick:()=>p.applyLayoutPreset(e.id,"columns"),style:oi,"aria-label":"two-columns",title:l("session.layout.columns"),children:t.jsx(s1,{size:14})}),t.jsx("button",{"data-no-drag":!0,onMouseDown:ae=>ae.stopPropagation(),onClick:()=>p.applyLayoutPreset(e.id,"grid"),style:oi,"aria-label":"grid-layout",title:l("session.layout.grid"),children:t.jsx(i1,{size:14})})]}),t.jsx("button",{"data-no-drag":!0,onMouseDown:ae=>ae.stopPropagation(),onClick:ne,style:oi,"aria-label":"toggle-maximize",title:`${l(g?"session.restoreSize":"session.maximize")} · ${l("session.maximizeHint")}`,children:g?t.jsx(Cl,{size:14}):t.jsx(fi,{size:14})}),t.jsx("button",{"data-no-drag":!0,onMouseDown:ae=>ae.stopPropagation(),onClick:()=>p.popOutGroup(e.id),style:oi,"aria-label":"pop-out",title:`${l("session.popOut")||"Pop out to separate window"} (Ctrl+Shift+O)`,children:t.jsx(ar,{size:14})}),t.jsx("button",{"data-no-drag":!0,onClick:()=>p.minimizeGroup(e.id),style:oi,"aria-label":"minimize",title:`${l("session.minimize")||"Minimize"} (Ctrl+Shift+M)`,children:t.jsx(ap,{size:14})}),t.jsx("button",{"data-no-drag":!0,onClick:()=>p.closeGroup(e.id),style:oi,"aria-label":"close",title:`${l("session.close")||"Close"} (Ctrl+Shift+X)`,children:t.jsx(Vt,{size:14})})]})]}),t.jsx("div",{style:{flex:1,display:"flex",minHeight:0,minWidth:0},children:e.root.kind==="split"?t.jsx(Ip,{node:e.root,path:[],groupId:e.id,sessionsById:s,colors:e.colors,intents:e.intents,onTabClick:K,onTabClose:z,onTabMouseDown:$,onPaneAutoClose:Y,registerRect:()=>{},onSplitSizes:q,sendMessage:f,subscribeBinary:m,onEvent:o,focusedSessionId:k||void 0,groupTopmost:a,onFocusStack:P}):t.jsx(Pp,{stack:e.root,path:[],groupId:e.id,sessionsById:s,colors:e.colors,intents:e.intents,onTabClick:K,onTabClose:z,onTabMouseDown:$,onPaneAutoClose:Y,registerRect:()=>{},sendMessage:f,subscribeBinary:m,onEvent:o,focusedSessionId:k||void 0,groupTopmost:a,onFocusStack:P,groupActions:{onMinimizeGroup:()=>p.minimizeGroup(e.id),onCloseGroup:()=>p.closeGroup(e.id),onPopOutGroup:()=>p.popOutGroup(e.id),onToggleMaximize:ne,isMaximized:g,onApplyLayoutPreset:ae=>p.applyLayoutPreset(e.id,ae)}})}),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:[be,G,T&&!(B!=null&&B.zone)&&t.jsx(kS,{activeZone:D}),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},Jf=["#3b82f6","#22c55e","#eab308","#ef4444","#a855f7","#06b6d4","#f97316","#ec4899"];function Hi(e){for(const s of Jf)if(!e.includes(s))return s;return Jf[e.length%Jf.length]}const kO="clitrigger:session-windows:global";function Fp(){if(typeof BroadcastChannel>"u")return{post:()=>{},subscribe:()=>()=>{},close:()=>{}};const e=new BroadcastChannel(kO),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 Pt="main",$m=new Map;function CO(e,s){$m.set(e,s)}function jO(e){const s=$m.get(e);if(!s||s.closed)return $m.delete(e),!1;try{return s.focus(),!0}catch{return!1}}function EO(){return`popout_${Math.random().toString(36).slice(2,10)}_${Date.now().toString(36)}`}const Hp=5e3,NS=15e3;let Ia=null;function LS(){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 Au(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 zu(e){return e.x>=0&&e.y>=0&&e.x<=window.innerWidth&&e.y<=window.innerHeight}const Um="clitrigger:popout-alive:";function NO(e){return`${Um}${e}`}function $p(){return typeof navigator<"u"&&!!navigator.locks&&typeof navigator.locks.query=="function"}function LO(e){if(!$p())return()=>{};let s=()=>{};return navigator.locks.request(NO(e),()=>new Promise(i=>{s=i})).catch(()=>{}),()=>s()}async function DS(){var e;if(!$p())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(Um)&&i.add(a.name.slice(Um.length));return i}catch{return new Set}}const Up=S.createContext(null),TS=S.createContext({});function RS(){const e=S.useContext(Up);if(!e)throw new Error("useSessionWindows must be used within SessionWindowsHost");return e}function DO(){return S.useContext(TS)}function TO(){return S.useContext(Up)}const Ou=720,Wp=460,RO=320,MO=200,tw=30,MS=80,AS=80,dl=80,Wm=28;function AO(e){const s=typeof window<"u"?window.innerWidth:1280,i=typeof window<"u"?window.innerHeight:800;let a=Number.isFinite(e.w)&&e.w>=RO?e.w:Ou,u=Number.isFinite(e.h)&&e.h>=MO?e.h:Wp;a=Math.min(a,s),u=Math.min(u,i);let f=Number.isFinite(e.x)?e.x:MS,m=Number.isFinite(e.y)?e.y:AS;return f=Math.max(Math.min(f,s-dl),-(a-dl)),m=Math.max(Math.min(m,i-Wm),0),{x:f,y:m,w:a,h:u}}const nw=12,au=60;function zS(e){return`sessionGroups:${e}`}function gu(e){try{const s=localStorage.getItem(zS(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 qm(e,s){try{localStorage.setItem(zS(e),JSON.stringify(s))}catch{}}function zO(e,s){const i=gu(e);!i||!i.groups.some(a=>a.id===s)||(qm(e,{...i,groups:i.groups.filter(a=>a.id!==s)}),window.dispatchEvent(new CustomEvent("session-windows:changed")))}function OO(e){const s=e%8;return{x:MS+s*tw,y:AS+s*tw,w:Ou,h:Wp}}function ou(e,s,i){return Math.max(s,Math.min(i,e))}function sw(){return`g_${Math.random().toString(36).slice(2,10)}_${Date.now().toString(36)}`}function li(e,s){for(const i of e)if(ed(i.root,s))return i;return null}function BO({projectId:e,sessions:s,sendMessage:i,subscribeBinary:a,onEvent:u,onAddSession:f,children:m}){const{t:o}=ht(),{warning:l}=Ls(),{confirm:d}=qn(),[p]=S.useState(()=>{const se=gu(e);if(!se)return{groups:[],zCounter:0};const ie=se.groups.map(J=>{const ee=gn(J.root),pe=new Set(ee),we={};for(const qe of Object.keys(J.colors||{}))pe.has(qe)&&(we[qe]=J.colors[qe]);const je={};for(const qe of ee)je[qe]={intent:"open",nonce:0},we[qe]||(we[qe]=Hi(Object.values(we)));const $e=AO({x:J.x,y:J.y,w:J.w,h:J.h}),Je=J.ownerWindowId||Pt;return{...J,...$e,colors:we,intents:je,minimized:!!J.minimized,ownerWindowId:Je}});return{groups:ie,zCounter:se.zCounter||ie.length}}),[h,g]=S.useState(p.groups),b=S.useRef(p.zCounter),C=S.useRef(h);C.current=h;const k=S.useRef(s);k.current=s;const[x,y]=S.useState(null),_=S.useRef(null);_.current=x;const[w,E]=S.useState({}),T=S.useRef(w);T.current=w,S.useEffect(()=>{var ee;const se={},ie=((ee=gu(e))==null?void 0:ee.sessionProjects)??{},J={};for(const pe of h)for(const we of gn(pe.root)){const je=s.find(Je=>Je.id===we)||w[we];je!=null&&je.title&&(se[we]=je.title);const $e=(je==null?void 0:je.project_id)||ie[we];$e&&(J[we]=$e)}qm(e,{groups:h,zCounter:b.current,titles:se,sessionProjects:J}),window.dispatchEvent(new CustomEvent("session-windows:changed"))},[e,h,s,w]),S.useEffect(()=>()=>{var je;const se=C.current;if(se.length===0)return;let ie=!1;const J=se.map($e=>($e.ownerWindowId||Pt)!==Pt||$e.minimized?$e:(ie=!0,{...$e,minimized:!0}));if(!ie)return;const ee={},pe=((je=gu(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)||T.current[Je];qe!=null&&qe.title&&(ee[Je]=qe.title);const Ee=(qe==null?void 0:qe.project_id)||pe[Je];Ee&&(we[Je]=Ee)}qm(e,{groups:J,zCounter:b.current,titles:ee,sessionProjects:we}),window.dispatchEvent(new CustomEvent("session-windows:changed"))},[e]),S.useEffect(()=>{const se=document.documentElement.style,ie={left:0,right:0,top:0,bottom:0};for(const J of h)!J.dock||J.minimized||(J.ownerWindowId||Pt)!==Pt||(J.dock==="left"?ie.left=Math.max(ie.left,J.x+J.w-Ha()):J.dock==="right"?ie.right=Math.max(ie.right,window.innerWidth-J.x):J.dock==="top"?ie.top=Math.max(ie.top,J.y+J.h):ie.bottom=Math.max(ie.bottom,window.innerHeight-J.y));for(const J of["left","right","top","bottom"])se.setProperty(`--dock-inset-${J}`,`${Math.max(0,Math.round(ie[J]))}px`);return()=>{for(const J of["left","right","top","bottom"])se.removeProperty(`--dock-inset-${J}`)}},[h]),S.useEffect(()=>{const se=()=>{const ee=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=SS(qe.dock,Ee,ee,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})};se();const ie=document.querySelector("main"),J=ie?new ResizeObserver(se):null;return ie&&J&&J.observe(ie),window.addEventListener("resize",se),()=>{J==null||J.disconnect(),window.removeEventListener("resize",se)}},[]);const[j,D]=S.useState(()=>new Set),N=S.useRef(new Set);S.useEffect(()=>{if(s.length===0)return;const se=s.filter(J=>J.project_id===e);if(se.length===0)return;const ie=new Set(se.map(J=>J.id));for(const J of h)for(const ee of gn(J.root))ie.has(ee)||w[ee]||j.has(ee)||N.current.has(ee)||(N.current.add(ee),F1(ee).then(pe=>E(we=>({...we,[ee]:pe}))).catch(pe=>{pe instanceof vu&&pe.status===404&&D(we=>new Set(we).add(ee))}).finally(()=>N.current.delete(ee)))},[h,s,e,w,j]),S.useEffect(()=>u(ie=>{ie.type!=="session:status-changed"||!ie.sessionId||E(J=>{const ee=J[ie.sessionId];if(!ee)return J;const pe={status:ie.status};return ie.worktree_path!==void 0&&(pe.worktree_path=ie.worktree_path),ie.branch_name!==void 0&&(pe.branch_name=ie.branch_name),{...J,[ee.id]:{...ee,...pe}}})}),[u]),S.useEffect(()=>{j.size!==0&&g(se=>{let ie=!1;const J=[];for(const ee of se){const pe=gn(ee.root);if(!pe.some(Ee=>j.has(Ee))){J.push(ee);continue}ie=!0;const we=new Set(pe.filter(Ee=>!j.has(Ee))),je=vO(ee.root,we);if(!je)continue;const $e=new Set(gn(je)),Je={};for(const Ee of Object.keys(ee.colors))$e.has(Ee)&&(Je[Ee]=ee.colors[Ee]);const qe={};for(const Ee of Object.keys(ee.intents))$e.has(Ee)&&(qe[Ee]=ee.intents[Ee]);J.push({...ee,root:je,colors:Je,intents:qe})}return ie?J:se})},[j]);const R=S.useCallback((se,ie)=>{const J=C.current.length,ee=OO(J);b.current+=1;const pe=b.current;return{id:sw(),...ee,z:pe,minimized:!1,root:Lr([se],se),colors:{[se]:Hi([])},intents:{[se]:{intent:ie,nonce:0}},ownerWindowId:Pt}},[]),A=S.useCallback((se,ie="open")=>{g(J=>{const ee=li(J,se);b.current+=1;const pe=b.current;return ee?J.map(we=>{var Ee,st,lt;if(we.id!==ee.id)return we;const je=((Ee=we.intents[se])==null?void 0:Ee.intent)??"open",$e=ie==="start"||ie==="resume",Je=$e?ie:je,qe=Je!==je||$e;return{...we,z:pe,minimized:!1,root:Ps(we.root,se),intents:{...we.intents,[se]:{intent:Je,nonce:qe?(((st=we.intents[se])==null?void 0:st.nonce)??0)+1:((lt=we.intents[se])==null?void 0:lt.nonce)??0}}}}):[...J,R(se,ie)]})},[R]),B=S.useCallback(se=>{g(ie=>{const J=li(ie,se);if(!J)return ie;const ee=ie.reduce((we,je)=>je.z>we?je.z:we,0);if(J.z===ee&&!J.minimized)return ie;b.current+=1;const pe=b.current;return ie.map(we=>we.id===J.id?{...we,z:pe,minimized:!1}:we)})},[]),O=S.useCallback(async se=>{const ie=se.map(J=>k.current.find(ee=>ee.id===J)||T.current[J]).filter(J=>!!J&&J.status==="running");if(ie.length===0)return!0;if(!await d({message:o("session.confirmStop"),danger:!0}))return!1;for(const J of ie)Cu(J.id).catch(()=>{});return!0},[o,d]),F=S.useCallback(async se=>{await O([se])&&g(ie=>{const J=li(ie,se);if(!J)return ie;const ee=Wi(J.root,se);if(!ee)return ie.filter(je=>je.id!==J.id);new Set(gn(ee));const pe={...J.colors};delete pe[se];const we={...J.intents};return delete we[se],ie.map(je=>je.id===J.id?{...je,root:ee,colors:pe,intents:we}:je)})},[O]),U=S.useCallback(se=>{g(ie=>{const J=li(ie,se);return J?ie.map(ee=>ee.id===J.id?{...ee,minimized:!0}:ee):ie})},[]),I=S.useCallback(se=>{g(ie=>{const J=li(ie,se);if(!J)return ie;b.current+=1;const ee=b.current;return ie.map(pe=>pe.id===J.id?{...pe,minimized:!1,z:ee}:pe)})},[]),H=S.useCallback(se=>!!li(C.current,se),[]),W=S.useCallback(async se=>{const ie=C.current.find(J=>J.id===se);ie&&!await O(gn(ie.root))||g(J=>J.filter(ee=>ee.id!==se))},[O]),K=S.useCallback(se=>{g(ie=>ie.map(J=>J.id===se?{...J,minimized:!0}:J))},[]);S.useEffect(()=>{const se=J=>{const ee=J.detail;!(ee!=null&&ee.projectId)||!ee.groupId||ee.projectId===e&&g(pe=>{if(!pe.find($e=>$e.id===ee.groupId))return pe;b.current+=1;const je=b.current;return pe.map($e=>$e.id===ee.groupId?{...$e,minimized:!1,z:je}:$e)})},ie=async J=>{var je;const ee=J.detail;if(!(ee!=null&&ee.projectId)||!ee.groupId||ee.projectId!==e)return;const pe=C.current.find($e=>$e.id===ee.groupId);if(pe&&!await O(gn(pe.root)))return;const we=(pe==null?void 0:pe.ownerWindowId)||Pt;we!==Pt&&(he.current.delete(we),Me.current.delete(ee.groupId),(je=de.current)==null||je.post({t:"group-reclaimed",popoutId:we,groupIds:[ee.groupId],reason:"late-return"})),g($e=>$e.filter(Je=>Je.id!==ee.groupId))};return window.addEventListener("session-windows:restore",se),window.addEventListener("session-windows:close",ie),()=>{window.removeEventListener("session-windows:restore",se),window.removeEventListener("session-windows:close",ie)}},[e,O]),S.useEffect(()=>{const se=sessionStorage.getItem("pendingSessionRestore");if(se)try{const ie=JSON.parse(se);if(ie.projectId!==e||!ie.groupId)return;sessionStorage.removeItem("pendingSessionRestore"),g(J=>{if(!J.find(we=>we.id===ie.groupId))return J;b.current+=1;const pe=b.current;return J.map(we=>we.id===ie.groupId?{...we,minimized:!1,z:pe}:we)})}catch{}},[e]);const P=S.useCallback(se=>{g(ie=>{if(!ie.find(pe=>pe.id===se))return ie;b.current+=1;const ee=b.current;return ie.map(pe=>pe.id===se?{...pe,minimized:!1,z:ee}:pe)})},[]),z=S.useCallback((se,ie)=>{g(J=>J.map(ee=>ee.id===se?{...ee,...ie}:ee))},[]),$=S.useCallback((se,ie)=>{g(J=>J.map(ee=>{if(ee.id===se){if(!ie)return ee.dock?{...ee,dock:void 0}:ee;const pe=vl(ie,window.innerWidth,window.innerHeight,Ha());return{...ee,...pe,dock:ie}}return ie&&ee.dock===ie?{...ee,dock:void 0}:ee}))},[]),Y=S.useCallback((se,ie,J)=>{g(ee=>ee.map(pe=>pe.id===se?{...pe,root:ES(pe.root,ie,J)}:pe))},[]),q=S.useCallback((se,ie)=>{g(J=>J.map(ee=>ee.id===se?{...ee,root:Ps(ee.root,ie)}:ee))},[]),oe=S.useCallback((se,ie)=>{g(J=>J.map(ee=>ee.id===se?{...ee,root:gO(ee.root,ie)}:ee))},[]),ce=S.useCallback((se,ie,J)=>{g(ee=>ee.map(pe=>pe.id===se?{...pe,root:jS(pe.root,ie,J)}:pe))},[]),ne=S.useCallback((se,ie,J,ee)=>{if(ee.button!==0||!C.current.find(gt=>gt.id===se))return;ee.preventDefault();const we=ee.clientX,je=ee.clientY;let $e=null;y({groupId:se,sessionId:ie,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=sw();$e=Tt;const Xe=window.innerWidth,ut=window.innerHeight,Q={x:ou(gt-60,-Ou+dl,Xe-dl),y:ou(vt-12,0,ut-Wm),w:Ou,h:Wp};g(ze=>{const ue=ze.find(Ct=>Ct.id===se);if(!ue)return ze;const Fe=Wi(ue.root,ie),Ve=ue.colors[ie]||Hi([]),ft=ue.intents[ie]??{intent:"open",nonce:0};b.current+=1;const Ne=b.current,at={id:Tt,...Q,z:Ne,minimized:!1,root:Lr([ie],ie),colors:{[ie]:Ve},intents:{[ie]:ft},ownerWindowId:Pt},bt=[];for(const Ct of ze)if(Ct.id===se){if(Fe){const Gt=new Set(gn(Fe)),an={};for(const bn of Object.keys(Ct.colors))Gt.has(bn)&&(an[bn]=Ct.colors[bn]);const Pn={};for(const bn of Object.keys(Ct.intents))Gt.has(bn)&&(Pn[bn]=Ct.intents[bn]);bt.push({...Ct,root:Mu(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-au||gt.screenX>Xe+au||gt.screenY<Tt-au||gt.screenY>ut+au},st=gt=>{if(qe)return;const vt=_.current;if(!vt)return;if(!$e)Math.hypot(gt.clientX-we,gt.clientY-je)>=nw&&Je(gt.clientX,gt.clientY);else{const Fe=window.innerWidth,Ve=window.innerHeight,ft=ou(gt.clientX-60,-640,Fe-dl),Ne=ou(gt.clientY-12,0,Ve-Wm);g(at=>at.map(bt=>bt.id===$e?{...bt,x:ft,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(),y(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 ft=Ve.dataset.groupId||"",Ne=Ve.dataset.stackPath||"";if($e?ft===$e:ft===vt.groupId&&Ne===vt.fromPath.join("."))continue;const bt=Ne===""?[]:Ne.split(".").map(Number),Ct=Ve.getBoundingClientRect();Tt=ft,Xe=bt,ut={x:Ct.left,y:Ct.top,w:Ct.width,h:Ct.height},Q=Zu(gt.clientX,gt.clientY,ut);break}const ue=Q||!$e?null:_S(gt.clientX,gt.clientY,window.innerWidth,window.innerHeight);y({...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(),y(null)},pt=gt=>{gt.key==="Escape"&&mt()},dt=()=>{document.hidden&&mt()},kt=gt=>{var Xe;yt();const vt=_.current;if(y(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 $(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((se,ie,J,ee,pe)=>{g(we=>{const je=we.find(pt=>pt.id===se),$e=we.find(pt=>pt.id===J);if(!je||!$e)return we;if(se===J){const pt=ul(je.root,ee);if(!pt||pt.kind!=="stack")return we;const dt=pt.tabs.find(Tt=>Tt!==ie);if(!dt)return we;const kt=Wi(je.root,ie);if(!kt)return we;const gt=ed(kt,dt);if(!gt)return we;let vt;return pe==="center"?vt=$i(kt,gt,ie):vt=$a(kt,gt,pe,Lr([ie])),vt=Ps(vt,ie),we.map(Tt=>Tt.id!==se?Tt:(b.current+=1,{...Tt,root:vt,z:b.current,minimized:!1}))}const Je=Wi(je.root,ie),qe=je.colors[ie],Ee=je.intents[ie]??{intent:"open",nonce:0};let st;if(pe==="center")st=$i($e.root,ee,ie);else{const pt=Lr([ie]);st=$a($e.root,ee,pe,pt)}st=Ps(st,ie);const lt={...$e.colors};lt[ie]||(lt[ie]=qe||Hi(Object.values(lt)));const yt={...$e.intents,[ie]:Ee},mt=[];for(const pt of we)if(pt.id===se){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})},[]),G=S.useCallback((se,ie,J,ee)=>{g(pe=>{if(se===ie)return pe;const we=pe.find(lt=>lt.id===se),je=pe.find(lt=>lt.id===ie);if(!we||!je||we.root.kind!=="stack")return pe;const $e=we.root;let Je;ee==="center"?Je=$e.tabs.reduce((lt,yt)=>$i(lt,J,yt),je.root):Je=$a(je.root,J,ee,$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!==se&&(lt.id===ie?(b.current+=1,st.push({...lt,root:Je,colors:qe,intents:Ee,z:b.current,minimized:!1})):st.push(lt));return st})},[]),de=S.useRef(null),he=S.useRef(new Map),[be,ae]=S.useState(null),De=S.useRef(be);De.current=be;const Re=S.useRef(null),ve=S.useRef(typeof document<"u"&&document.hasFocus()?Date.now():0);S.useEffect(()=>{const se=()=>{ve.current=Date.now()};window.addEventListener("focus",se);const ie=LS();return()=>{window.removeEventListener("focus",se),ie(),Re.current&&clearTimeout(Re.current)}},[]);const Me=S.useRef(new Map),Oe=S.useRef(null),tt=S.useCallback((se,ie)=>{var st;const J=C.current.find(lt=>lt.id===se);if(!J)return;const ee=EO(),pe={...J,ownerWindowId:ee,dock:void 0};Me.current.set(se,pe),he.current.set(ee,Date.now()),g(lt=>lt.map(yt=>yt.id===se?{...yt,ownerWindowId:ee,dock:void 0}:yt)),(st=de.current)==null||st.post({t:"group-handoff",to:ee,groupId:se,group:pe});const we=ie&&(typeof ie.atScreenX=="number"||typeof ie.atScreenY=="number"),je=we?Math.max(0,((ie==null?void 0:ie.atScreenX)??window.screenX+J.x)-40):Math.max(0,window.screenX+J.x),$e=we?Math.max(0,((ie==null?void 0:ie.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(se)}?wid=${encodeURIComponent(ee)}`,Ee=window.open(qe,"_blank",Je);if(!Ee){Me.current.delete(se),he.current.delete(ee),g(lt=>lt.map(yt=>yt.id===se?{...yt,ownerWindowId:Pt}:yt)),l(o("session.popout.blocked"));return}CO(ee,Ee)},[e,o,l]);Oe.current=tt;const nt=S.useCallback(se=>{var ee;const ie=C.current.find(pe=>pe.id===se);if(!ie)return;const J=ie.ownerWindowId||Pt;if(J===Pt){P(se);return}(ee=de.current)==null||ee.post({t:"group-recall",popoutId:J,groupId:se}),setTimeout(()=>{var je;const pe=C.current.find($e=>$e.id===se);if(!pe||(pe.ownerWindowId||Pt)===Pt)return;he.current.delete(J),Me.current.delete(se),(je=de.current)==null||je.post({t:"group-reclaimed",popoutId:J,groupIds:[se],reason:"late-return"}),b.current+=1;const we=b.current;g($e=>$e.map(Je=>Je.id===se?{...Je,ownerWindowId:Pt,minimized:!1,z:we}:Je))},1500)},[P]),ke=S.useCallback(se=>{const ie=li(C.current,se);ie&&nt(ie.id)},[nt]);S.useEffect(()=>{const se=ie=>{const J=ie.detail;!(J!=null&&J.projectId)||!J.groupId||J.projectId!==e||nt(J.groupId)};return window.addEventListener("session-windows:recall",se),()=>window.removeEventListener("session-windows:recall",se)},[e,nt]),S.useEffect(()=>{const se=sessionStorage.getItem("pendingSessionRecall");if(se)try{const ie=JSON.parse(se);if(ie.projectId!==e||!ie.groupId)return;sessionStorage.removeItem("pendingSessionRecall");const J=ie.groupId;setTimeout(()=>nt(J),0)}catch{}},[e,nt]);const fe=S.useCallback(se=>se.kind==="stack"?[]:[0,...fe(se.children[0])],[]),Te=S.useCallback((se,ie,J)=>{const ee=ie?C.current.find($e=>$e.id===ie):null,pe=ee&&(ee.ownerWindowId||Pt)===Pt;if(!ee||!pe){A(se,"start");return}const we=(()=>{if(J){const $e=ul(ee.root,J);if($e&&$e.kind==="stack")return J}return fe(ee.root)})();b.current+=1;const je=b.current;g($e=>$e.map(Je=>{if(Je.id!==ee.id)return Je;const qe=Ps($i(Je.root,we,se),se);return{...Je,root:qe,z:je,minimized:!1,colors:{...Je.colors,[se]:Hi(Object.values(Je.colors))},intents:{...Je.intents,[se]:{intent:"start",nonce:0}}}}))},[A,fe]),Ce=S.useCallback(async(se,ie)=>{const J=new Date,ee=String(J.getHours()).padStart(2,"0"),pe=String(J.getMinutes()).padStart(2,"0"),we=String(J.getSeconds()).padStart(2,"0"),je=await km(e,{title:`Shell ${ee}:${pe}:${we}`,cli_tool:"raw-shell",use_worktree:!1,memory_inject_mode:"none"});return f==null||f(je),Te(je.id,se,ie),je.id},[e,f,Te]);S.useEffect(()=>{const se=Fp();de.current=se;const ie=ee=>{var pe;if(ee.t==="hello"){const we=Me.current.get(ee.groupId);if(we&&we.ownerWindowId===ee.from)se.post({t:"group-handoff",to:ee.from,groupId:ee.groupId,group:we});else{const je=C.current.find($e=>$e.id===ee.groupId);je&&je.ownerWindowId===ee.from&&se.post({t:"group-handoff",to:ee.from,groupId:ee.groupId,group:je})}}else if(ee.t==="group-return"||ee.t==="bye")if(ee.t==="group-return"){const we=ee.group;we&&we.id===ee.groupId&&(Me.current.delete(ee.groupId),he.current.delete(ee.from),ee.projectId&&ee.projectId!==e&&zO(ee.projectId,ee.groupId),g(je=>{const $e=je.find(qe=>qe.id===ee.groupId),Je={...we,ownerWindowId:Pt,dock:void 0};return $e?je.map(qe=>qe.id===ee.groupId?Je:qe):[...je,Je]}))}else he.current.delete(ee.from),g(we=>we.map(je=>je.ownerWindowId===ee.from?{...je,ownerWindowId:Pt}:je));else if(ee.t==="group-close")Me.current.delete(ee.groupId),g(we=>we.filter(je=>je.id!==ee.groupId));else if(ee.t==="heartbeat")he.current.set(ee.from,Date.now());else if(ee.t==="group-update"){const we=ee.patch;g(je=>je.map($e=>$e.id===ee.groupId?{...$e,...we}:$e))}else if(ee.t==="dock-probe"){if(document.visibilityState!=="visible")return;const we=Au(ee.x,ee.y),je=zu(we)?Tu(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("."))&&ae({rect:je.rect,zone:je.zone,path:je.path,groupId:je.groupId}),Re.current&&clearTimeout(Re.current),Re.current=setTimeout(()=>ae(null),800),se.post({t:"dock-probe-result",from:Pt,to:ee.from,hit:!0,focusAt:ve.current})}else De.current&&ae(null),se.post({t:"dock-probe-result",from:Pt,to:ee.from,hit:!1,focusAt:ve.current})}else if(ee.t==="dock-end")ae(null);else if(ee.t==="dock-commit"&&ee.to===Pt){const we=Au(ee.x,ee.y),je=zu(we)?Tu(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||Pt)===Pt);if($e&&$e.zone&&!li(qe,ee.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"?$i(dt.root,yt,ee.sessionId):$a(dt.root,yt,lt,Lr([ee.sessionId])),gt=Ps(kt,ee.sessionId),vt={...dt.colors};vt[ee.sessionId]||(vt[ee.sessionId]=ee.color||Hi(Object.values(vt)));const Tt={...dt.intents,[ee.sessionId]:ee.intentInfo??{intent:"open",nonce:0}};return{...dt,root:gt,colors:vt,intents:Tt,z:mt,minimized:!1}}))}}ae(null),se.post({t:"dock-commit-ack",from:Pt,to:ee.from,sessionId:ee.sessionId,accepted:Je})}},J=se.subscribe(ie);return()=>{J(),se.close(),de.current=null}},[e]),S.useEffect(()=>{const se=Date.now();for(const ie of p.groups)ie.ownerWindowId&&ie.ownerWindowId!==Pt&&he.current.set(ie.ownerWindowId,se)},[]),S.useEffect(()=>{const se=async()=>{var $e;const J=Date.now(),ee=[];for(const[Je,qe]of he.current.entries())J-qe>NS&&ee.push(Je);if(ee.length===0)return;const pe=await DS(),we=ee.filter(Je=>pe.has(Je)?(he.current.set(Je,J),!1):!0);if(we.length===0)return;for(const Je of we)he.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=de.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:Pt}:qe))},ie=setInterval(()=>{se()},Hp);return()=>clearInterval(ie)},[]);const Ke=S.useCallback((se,ie)=>{i({type:"session:terminal-input",sessionId:se,input:ie})},[i]),Ze=S.useCallback(()=>{var J,ee;const se=C.current.filter(pe=>(pe.ownerWindowId||Pt)===Pt).slice().sort((pe,we)=>we.z-pe.z),ie=[];for(const pe of se)for(const we of gn(pe.root)){const je=((J=k.current.find($e=>$e.id===we))==null?void 0:J.title)||((ee=T.current[we])==null?void 0:ee.title)||we;ie.push({sessionId:we,label:je})}return ie},[]),ye=S.useCallback(async(se,ie)=>{const ee=C.current.filter(we=>!we.minimized&&(we.ownerWindowId||Pt)===Pt).reduce((we,je)=>we&&we.z>=je.z?we:je,null),pe=await km(e,{title:ie||"",description:se,use_worktree:!1,memory_inject_mode:"none"});f==null||f(pe),Te(pe.id,(ee==null?void 0:ee.id)??null)},[e,f,Te]),Be=S.useMemo(()=>({openOrFocus:A,close:F,focus:B,minimize:U,restore:I,isOpen:H,recallPopout:ke,closeGroup:W,minimizeGroup:K,restoreGroup:P,setGroupGeometry:z,setGroupDock:$,setSplitSizes:Y,setActiveTab:q,applyLayoutPreset:oe,reorderTab:ce,beginTabDrag:ne,dockGroup:G,popOutGroup:tt,createRawShellTab:Ce,sendToSession:Ke,listOpenTerminals:Ze,sendToNewTerminal:ye}),[A,F,B,U,I,H,ke,W,K,P,z,$,Y,q,oe,ce,ne,G,tt,Ce,Ke,Ze,ye]),Z=S.useMemo(()=>{const se={};for(const ie of h){const ee=(ie.ownerWindowId||Pt)!==Pt?"popped":ie.minimized?"minimized":"floating";for(const pe of gn(ie.root))se[pe]=ee}return se},[h]);S.useEffect(()=>{const se=ie=>{const J=/Mac|iPhone|iPad|iPod/.test(navigator.platform),ee=J?ie.metaKey:ie.ctrlKey,pe=J?ie.ctrlKey:ie.metaKey;if(!ee||pe||ie.altKey||ie.shiftKey||ie.key.toLowerCase()!=="t")return;ie.preventDefault();const je=C.current.filter($e=>!$e.minimized&&($e.ownerWindowId||Pt)===Pt).reduce(($e,Je)=>$e&&$e.z>=Je.z?$e:Je,null);Ce((je==null?void 0:je.id)??null).catch(()=>{})};return window.addEventListener("keydown",se),()=>window.removeEventListener("keydown",se)},[Ce]);const _e=S.useMemo(()=>{const se=new Map;for(const ie of Object.values(w))se.set(ie.id,ie);for(const ie of s)se.set(ie.id,ie);return se},[s,w]),X=h.filter(se=>!se.minimized&&(se.ownerWindowId||Pt)===Pt),me=X.reduce((se,ie)=>ie.z>se.z?{id:ie.id,z:ie.z}:se,{id:null,z:-1/0}).id;return t.jsx(Up.Provider,{value:Be,children:t.jsxs(TS.Provider,{value:Z,children:[m,(()=>{const se=new Map(X.slice().sort((ie,J)=>ie.z-J.z).map((ie,J)=>[ie.id,J+1]));return X.map(ie=>{const J=X.filter(ee=>ee.id!==ie.id).map(({x:ee,y:pe,w:we,h:je})=>({x:ee,y:pe,w:we,h:je}));return t.jsx(SO,{group:ie,sessionsById:_e,neighbors:J,isTopmost:ie.id===me,zIndex:se.get(ie.id)??1,sendMessage:i,subscribeBinary:a,onEvent:u},ie.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)>=nw&&t.jsx(kS,{activeZone:x.viewportZone}),be&&t.jsx(bl,{targetRect:be.rect,activeZone:be.zone})]})})}function PO(e){if(!e)return[];try{const s=JSON.parse(e);return Array.isArray(s)?s.map(String).filter(Boolean):[]}catch{return[]}}const IO={pending:"bg-warm-400",running:"bg-status-success",completed:"bg-accent",failed:"bg-status-error",stopped:"bg-status-warning"};function FO({projectId:e,sessions:s,projectCliTool:i,isGitRepo:a,projectUseWorktree:u,projectDefaultBranch:f,onAddSession:m,onUpdateSession:o,onStopSession:l,onDeleteSession:d,onCleanupSession:p}){const{t:h}=ht(),{confirm:g}=qn(),{openOrFocus:b,recallPopout:C}=RS(),k=DO(),[x,y]=S.useState(!1),[_,w]=S.useState(!1),[E,T]=S.useState(null),[j,D]=S.useState(!1),[N,R]=S.useState(null),[A,B]=S.useState([]),[O,F]=S.useState(""),[U,I]=S.useState(null);S.useEffect(()=>{let oe=!1;return dp().then(ce=>{oe||B(ce)}).catch(()=>{}),()=>{oe=!0}},[]),S.useEffect(()=>{if(!a)return;let oe=!1;return h1(e).then(ce=>{oe||F(ce.branch||"")}).catch(()=>{}),()=>{oe=!0}},[e,a]);const H=S.useMemo(()=>{const oe=new Map;for(const ce of A)oe.set(ce.id,ce);return oe},[A]),W=S.useMemo(()=>E?s.find(oe=>oe.id===E)??null:null,[E,s]),K=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:Tz(W.memory_node_ids??null),memoryRawFilePaths:PO(W.memory_raw_file_paths??null),tagId:W.tag_id??null}},[W]),P=S.useCallback(()=>{T(null),R(null),y(oe=>!oe)},[]),z=S.useCallback(oe=>{y(!1),R(null),T(oe)},[]),$=S.useCallback(()=>{y(!1),T(null),R(null)},[]),Y=S.useCallback(async(oe,ce,ne,te,G,de,he,be)=>{w(!0);try{const ae=await km(e,{title:oe,description:ce||void 0,cli_tool:ne,use_worktree:te,memory_inject_mode:G,memory_node_ids:de,memory_raw_file_paths:he,tag_id:be??null});m(ae),y(!1)}finally{w(!1)}},[e,m]),q=S.useCallback(async(oe,ce,ne,te,G,de,he,be)=>{if(E){D(!0),R(null);try{const ae=await U4(E,{title:oe,description:ce||void 0,cli_tool:ne,use_worktree:te,memory_inject_mode:G,memory_node_ids:de,memory_raw_file_paths:he,tag_id:be??null});o(ae),T(null)}catch(ae){R(ae instanceof Error?ae.message:String(ae))}finally{D(!1)}}},[E,o]);return t.jsxs("div",{className:"space-y-4 min-h-[50vh]",onContextMenu:oe=>{xi(oe)||(oe.preventDefault(),I({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:h("tabs.sessions")}),t.jsxs("button",{onClick:P,className:"btn-primary text-xs py-2",disabled:_,children:["+ ",h("session.new")]})]}),x&&t.jsx(My,{projectId:e,onSave:Y,onCancel:$,projectCliTool:i,isGitRepo:a,projectUseWorktree:u}),K&&E&&t.jsxs("div",{className:"space-y-2",children:[t.jsx(My,{projectId:e,initial:K,onSave:q,onCancel:$,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:h("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:h("session.empty"),description:h("session.emptyHint")})}):t.jsx("div",{className:"space-y-3",children:s.map((oe,ce)=>{const ne=["pending","failed","stopped","completed"].includes(oe.status),te=oe.status==="running",G=oe.status!=="running",de=["stopped","failed","completed"].includes(oe.status)&&(oe.cli_tool??"claude")==="claude"&&!!oe.worktree_path,he=E===oe.id,be=k[oe.id]??"closed",ae=be==="popped";return t.jsx("div",{className:`card overflow-hidden ${he?"border-l-4 border-accent bg-warm-100/30":""}`,onContextMenu:De=>{xi(De)||(De.preventDefault(),De.stopPropagation(),I({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:()=>ae?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 ${IO[oe.status]||"bg-warm-400"}`}),h(`status.${oe.status}`)||oe.status]}),be!=="closed"&&t.jsxs("span",{className:"inline-flex items-center gap-1 text-2xs text-warm-400 whitespace-nowrap",title:ae?h("session.dock.poppedHint"):void 0,children:[ae?t.jsx(ar,{size:12}):t.jsx("span",{"aria-hidden":"true",children:"·"}),h(`session.windowState.${be}`)]})]}),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:[ae&&t.jsx("button",{onClick:()=>C(oe.id),className:"p-1.5 text-accent hover:bg-accent/10 rounded-md transition-colors",title:h("session.recallToMain"),children:t.jsx(fi,{size:16})}),ne&&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:h("session.start"),children:t.jsx(Tr,{size:16})}),de&&t.jsx("button",{onClick:()=>b(oe.id,"resume"),className:"p-1.5 text-accent hover:bg-accent/10 rounded-md transition-colors",title:h("session.resumeHint")||h("session.resume"),children:t.jsx(pi,{size:16})}),t.jsx("button",{onClick:()=>z(oe.id),disabled:!G,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:h(G?"session.edit":"session.editDisabledRunning"),children:t.jsx(dm,{size:16})}),te&&t.jsx("button",{onClick:()=>l(oe.id),className:"p-1.5 text-status-warning hover:bg-status-warning/10 rounded-md transition-colors",title:h("session.stop"),children:t.jsx(Gi,{size:16})}),oe.status!=="running"&&(!!oe.worktree_path||!!oe.branch_name)&&t.jsx("button",{onClick:async()=>{const De=oe.branch_name?await g({message:h("cleanup.confirmDeleteBranch").replace("{name}",oe.branch_name),danger:!0}):!1;p(oe.id,De)},className:"p-1.5 text-warm-400 hover:text-status-warning rounded-md transition-colors",title:h("session.cleanup"),children:t.jsx(bu,{size:16})}),t.jsx("button",{onClick:()=>d(oe.id),className:"p-1.5 text-warm-400 hover:text-status-error rounded-md transition-colors",title:h("session.delete"),children:t.jsx(An,{size:16})})]})]})})},oe.id)})}),U&&(()=>{const oe=()=>I(null),ce=U.sessionId?s.find(Re=>Re.id===U.sessionId):void 0;if(!ce)return t.jsx(Ws,{x:U.x,y:U.y,onClose:oe,children:t.jsxs("button",{type:"button",onClick:()=>{T(null),R(null),y(!0)},className:en,children:[t.jsx(vn,{size:14}),h("session.new")]})});const ne=["pending","failed","stopped","completed"].includes(ce.status),te=ce.status==="running",G=ce.status!=="running",de=["stopped","failed","completed"].includes(ce.status)&&(ce.cli_tool??"claude")==="claude"&&!!ce.worktree_path,he=ce.status!=="running"&&(!!ce.worktree_path||!!ce.branch_name),be=k[ce.id]??"closed",ae=be==="popped",De=h(ae?"session.recallToMain":be==="minimized"?"session.restoreWindow":be==="floating"?"session.focusWindow":"session.openWindow");return t.jsxs(Ws,{x:U.x,y:U.y,onClose:oe,children:[t.jsxs("button",{type:"button",onClick:()=>ae?C(ce.id):b(ce.id,"open"),className:en,children:[ae?t.jsx(fi,{size:14}):t.jsx(ml,{size:14}),De]}),ne&&t.jsxs("button",{type:"button",onClick:()=>b(ce.id,"start"),className:en,children:[t.jsx(Tr,{size:14}),h("session.start")]}),de&&t.jsxs("button",{type:"button",onClick:()=>b(ce.id,"resume"),className:en,title:h("session.resumeHint")||h("session.resume"),children:[t.jsx(pi,{size:14}),h("session.resume")]}),G&&t.jsxs("button",{type:"button",onClick:()=>z(ce.id),className:en,children:[t.jsx(dm,{size:14}),h("session.edit")]}),te&&t.jsxs("button",{type:"button",onClick:()=>l(ce.id),className:en,children:[t.jsx(Gi,{size:14}),h("session.stop")]}),he&&t.jsxs("button",{type:"button",onClick:async()=>{const Re=ce.branch_name?await g({message:h("cleanup.confirmDeleteBranch").replace("{name}",ce.branch_name),danger:!0}):!1;p(ce.id,Re)},className:en,children:[t.jsx(bu,{size:14}),h("session.cleanup")]}),t.jsx(Z_,{}),t.jsxs("button",{type:"button",onClick:()=>d(ce.id),className:zp,children:[t.jsx(An,{size:14}),h("session.delete")]})]})})()]})}const Bu={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"}},HO=Object.keys(Bu),Pu={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=Bu[e]||Bu.default;return`${s.bg} ${s.text}`}function qp({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(Vt,{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 Gm({anchorRef:e,width:s,onClose:i,className:a,style:u,children:f}){const m=S.useRef(null),[o,l]=S.useState(null);return S.useLayoutEffect(()=>{const d=e.current;if(!d)return;const p=d.getBoundingClientRect();let h=p.left;h+s>window.innerWidth-8&&(h=Math.max(8,window.innerWidth-8-s)),h<8&&(h=8),l({top:p.bottom+4,left:h})},[e,s]),S.useEffect(()=>{const d=h=>{var b,C;const g=h.target;(b=m.current)!=null&&b.contains(g)||(C=e.current)!=null&&C.contains(g)||i()},p=()=>i();return document.addEventListener("mousedown",d),window.addEventListener("scroll",p,!0),window.addEventListener("resize",p),()=>{document.removeEventListener("mousedown",d),window.removeEventListener("scroll",p,!0),window.removeEventListener("resize",p)}},[i,e]),o?rn.createPortal(t.jsx("div",{ref:m,className:a,style:{position:"fixed",top:o.top,left:o.left,width:s,...u},children:f}),document.body):null}const rw={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 $O({item:e,tagColors:s,existingTags:i,onSave:a,onDelete:u,onConvertToTodo:f,onConvertToSchedule:m,onConvertToSession:o,onUpdateTag:l}){var Z,_e;const{t:d}=ht(),{confirm:p}=qn(),[h,g]=S.useState(!1),[b,C]=S.useState(!1),[k,x]=S.useState(!1),y=S.useRef(null),_=S.useRef(null),[w,E]=S.useState({top:0,left:0}),[T,j]=S.useState(e.title),[D,N]=S.useState(e.description??""),[R,A]=S.useState(e.priority),[B,O]=S.useState(e.due_date??""),[F,U]=S.useState(e.status),[I,H]=S.useState(()=>{try{return e.tags?JSON.parse(e.tags):[]}catch{return[]}}),[W,K]=S.useState(""),[P,z]=S.useState(!1),[$,Y]=S.useState(null),[q,oe]=S.useState(null),ce=S.useRef(null),ne=S.useRef(null),[te,G]=S.useState(()=>{try{return e.images?JSON.parse(e.images):[]}catch{return[]}}),de=S.useRef(null);S.useEffect(()=>{j(e.title),N(e.description??""),A(e.priority),O(e.due_date??""),U(e.status);try{H(e.tags?JSON.parse(e.tags):[])}catch{H([])}try{G(e.images?JSON.parse(e.images):[])}catch{G([])}},[e]);const he=I,be=e.status==="moved",ae=e.due_date&&new Date(e.due_date)<new Date&&!be&&e.status!=="done",De=S.useCallback(X=>{a(e.id,X)},[e.id,a]),Re=()=>{const X=T.trim();X&&X!==e.title?De({title:X}):j(e.title)},ve=()=>{const X=D.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;U(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 se;const me=X.trim();if(me&&!I.includes(me)&&(nt([...I,me]),!s.has(me)&&l)){const ie=["blue","green","orange","purple","pink","red","yellow","brown"],J=ie[s.size%ie.length];l(me,{color:J})}K(""),(se=ce.current)==null||se.focus()},fe=X=>nt(I.filter(me=>me!==X)),Te=i.filter(X=>!I.includes(X)&&(!W||X.toLowerCase().includes(W.toLowerCase()))),Ce=S.useCallback(X=>{const me=Array.from(X).filter(J=>J.type.startsWith("image/")),se=[];let ie=0;for(const J of me){const ee=new FileReader;ee.onload=()=>{se.push({name:J.name,data:ee.result}),ie++,ie===me.length&&$1(e.id,se).then(pe=>G(pe.images))},ee.readAsDataURL(J)}},[e.id]),Ke=S.useCallback(X=>{var ie;const me=(ie=X.clipboardData)==null?void 0:ie.items;if(!me)return;const se=[];for(let J=0;J<me.length;J++)if(me[J].type.startsWith("image/")){const ee=me[J].getAsFile();ee&&se.push(ee)}se.length!==0&&(X.preventDefault(),Ce(se))},[Ce]),Ze=S.useCallback(X=>{var me;X.preventDefault(),X.stopPropagation(),(me=X.dataTransfer)!=null&&me.files&&Ce(X.dataTransfer.files)},[Ce]),ye=S.useCallback(X=>{U1(e.id,X).then(()=>{G(me=>me.filter(se=>se.id!==X))})},[e.id]),Be=S.useCallback(()=>{if(!y.current)return;const X=y.current.getBoundingClientRect(),me=window.innerWidth,se=window.innerHeight;let ie=X.bottom+4;const J=_.current;if(J){const ee=J.offsetWidth,pe=J.offsetHeight;let we=X.right-ee;we<8&&(we=8),we+ee>me-8&&(we=me-8-ee),ie+pe>se-8&&(ie=X.top-pe-4),E({top:ie,left:we}),x(!0)}else E({top:ie,left:Math.max(8,X.right-180)})},[]);return S.useEffect(()=>{if(!h){x(!1);return}Be();const X=requestAnimationFrame(Be),me=se=>{var J,ee;const ie=se.target;(J=y.current)!=null&&J.contains(ie)||(ee=_.current)!=null&&ee.contains(ie)||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)}},[h,Be]),t.jsxs("div",{className:`${be?"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}),be&&e.converted_type&&t.jsxs("span",{className:"text-2xs text-status-merged",children:["→ ",e.converted_type==="todo"?d("planner.movedToTodo"):e.converted_type==="session"?d("planner.movedToSession"):d("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:d("planner.fromDiscussion"),children:[t.jsx(VE,{size:12}),d("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]}),he.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 ${((Z=rw[e.priority])==null?void 0:Z.style)??"text-warm-300"}`,children:((_e=rw[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 ${ae?"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:d("planner.noDueDate")})}),t.jsx("div",{className:"w-16 flex-shrink-0",children:t.jsx("span",{className:`inline-flex items-center px-2 py-0.5 rounded-full text-2xs font-semibold ${Pu[e.status]||Pu.pending}`,children:d(`plannerStatus.${e.status}`)})}),t.jsxs("div",{className:"w-8 flex-shrink-0",children:[t.jsx("button",{ref:y,onClick:X=>{X.stopPropagation(),g(!h)},className:"p-1.5 text-warm-400 hover:text-warm-600 hover:bg-warm-100/50 rounded-lg transition-colors",children:t.jsx(rp,{size:14})}),h&&rn.createPortal(t.jsxs("div",{ref:_,className:"fixed z-tooltip min-w-[160px] rounded-xl py-1 shadow-elevated",style:{top:w.top,left:w.left,opacity:k?1:0,backgroundColor:"var(--color-bg-card)",border:"1px solid var(--color-border)"},onClick:()=>g(!1),children:[!be&&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(Xw,{size:12})," ",d("planner.convertToTask")]}),t.jsxs("button",{onClick:m,className:"flex items-center gap-2 w-full px-3 py-1.5 text-xs hover:bg-warm-100 rounded-md transition-colors text-left",style:{color:"var(--color-text-primary)"},children:[t.jsx(qi,{size:12})," ",d("planner.convertToSchedule")]}),t.jsxs("button",{onClick:o,className:"flex items-center gap-2 w-full px-3 py-1.5 text-xs hover:bg-warm-100 rounded-md transition-colors text-left",style:{color:"var(--color-text-primary)"},children:[t.jsx(gi,{size:12})," ",d("planner.convertToTerminal")]})]}),t.jsxs("button",{onClick:async()=>{await p({message:d("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})," ",d("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:T,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:d("plannerForm.descPlaceholder"),value:D,onChange:X=>N(X.target.value),onPaste:Ke,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=de.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}),d("plannerForm.addImage")]}),t.jsx("span",{className:"text-[10px] text-warm-300",children:d("plannerForm.pasteHint")})]}),t.jsx("input",{ref:de,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:ju(e.id,X.id),alt:X.originalName,onClick:()=>oe(ju(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:()=>ye(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(Vt,{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:d("plannerForm.tags")}),t.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[I.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=>{ne.current=me.currentTarget,Y($===X?null:X)},children:[X,t.jsx("button",{onClick:me=>{me.stopPropagation(),fe(X)},className:"opacity-60 hover:opacity-100",children:t.jsx(Vt,{size:12})})]}),$===X&&t.jsxs(Gm,{anchorRef:ne,width:180,onClose:()=>Y(null),className:"p-2 rounded-lg shadow-elevated z-tooltip",style:{backgroundColor:"var(--color-bg-card)",border:"1px solid var(--color-border)"},children:[t.jsx("div",{className:"text-2xs text-warm-400 mb-1.5",children:d("plannerTag.color")}),t.jsx("div",{className:"grid grid-cols-5 gap-1.5",children:HO.map(me=>t.jsx("button",{onClick:async()=>{l&&await l(X,{color:me}),Y(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:d(`plannerTag.color.${me}`),children:t.jsx("div",{className:`w-5 h-5 rounded-md ${Bu[me].swatch}`})},me))})]})]},X)),t.jsxs("div",{className:"relative",children:[t.jsx("input",{ref:ce,className:"bg-transparent text-xs outline-none w-24",style:{color:"var(--color-text-primary)"},placeholder:"+",value:W,onChange:X=>{K(X.target.value),z(!0)},onKeyDown:X=>{(X.key==="Enter"||X.key===",")&&W.trim()&&(X.preventDefault(),ke(W.replace(",",""))),X.key==="Backspace"&&!W&&I.length>0&&fe(I[I.length-1])},onFocus:()=>z(!0),onBlur:()=>setTimeout(()=>z(!1),150)}),P&&Te.length>0&&t.jsx(Gm,{anchorRef:ce,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:d("plannerForm.priority")}),t.jsxs("select",{className:"input-field text-xs w-full py-1",value:R,onChange:X=>Me(Number(X.target.value)),children:[t.jsx("option",{value:0,children:d("plannerForm.priorityLow")}),t.jsx("option",{value:1,children:d("plannerForm.priorityNormal")}),t.jsx("option",{value:2,children:d("plannerForm.priorityHigh")}),t.jsx("option",{value:3,children:d("plannerForm.priorityCritical")})]})]}),t.jsxs("div",{children:[t.jsx("label",{className:"text-2xs text-warm-400 mb-1 block",children:d("plannerForm.dueDate")}),t.jsx("input",{type:"date",className:"input-field text-xs w-full py-1",value:B,onChange:X=>Oe(X.target.value)})]}),t.jsxs("div",{children:[t.jsx("label",{className:"text-2xs text-warm-400 mb-1 block",children:d("plannerForm.status")}),t.jsxs("select",{className:"input-field text-xs w-full py-1",value:F,onChange:X=>tt(X.target.value),children:[t.jsx("option",{value:"pending",children:d("plannerStatus.pending")}),t.jsx("option",{value:"in_progress",children:d("plannerStatus.in_progress")}),t.jsx("option",{value:"done",children:d("plannerStatus.done")})]})]})]})]})}),q&&t.jsx(qp,{src:q,onClose:()=>oe(null)})]})}let UO=0;function WO({existingTags:e,editItem:s,initialDueDate:i,onSave:a,onCancel:u,onUpdateTag:f}){const{t:m}=ht(),[o,l]=S.useState(""),[d,p]=S.useState(""),[h,g]=S.useState([]),[b,C]=S.useState(""),[k,x]=S.useState(i??""),[y,_]=S.useState(0),[w,E]=S.useState("pending"),[T,j]=S.useState(!1),[D,N]=S.useState(!1),[R,A]=S.useState([]),[B,O]=S.useState([]),[F,U]=S.useState(null),I=S.useRef(null),H=S.useRef(null),W=S.useRef(null),[K,P]=S.useState(new Map),z=new Map([...e.map(ae=>[ae.name,ae.color]),...K]),$=["blue","green","orange","purple","pink","red","yellow","brown"];S.useEffect(()=>{var ae;if(s){l(s.title),p(s.description??""),g(s.tags?JSON.parse(s.tags):[]),x(s.due_date??""),_(s.priority),E(s.status);try{O(s.images?JSON.parse(s.images):[])}catch{O([])}}(ae=I.current)==null||ae.focus()},[s]);const Y=e.filter(ae=>!h.includes(ae.name)&&(!b||ae.name.toLowerCase().includes(b.toLowerCase()))),q=ae=>{var Re;const De=ae.trim();De&&!h.includes(De)&&g(ve=>{const Me=[...ve,De];if(!z.has(De)){const Oe=$[z.size%$.length];P(tt=>new Map([...tt,[De,Oe]]))}return Me}),C(""),N(!0),(Re=H.current)==null||Re.focus()},oe=ae=>g(h.filter(De=>De!==ae)),ce=S.useCallback(ae=>{const De=Array.from(ae).filter(Re=>Re.type.startsWith("image/"));for(const Re of De){const ve=new FileReader;ve.onload=()=>{const Me=ve.result,Oe=`pending-${++UO}`;A(tt=>[...tt,{id:Oe,name:Re.name,data:Me,preview:Me}])},ve.readAsDataURL(Re)}},[]),ne=S.useCallback(ae=>{var ve;const De=(ve=ae.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&&(ae.preventDefault(),ce(Re))},[ce]),te=S.useCallback(ae=>{var De;ae.preventDefault(),ae.stopPropagation(),(De=ae.dataTransfer)!=null&&De.files&&ce(ae.dataTransfer.files)},[ce]),G=ae=>A(De=>De.filter(Re=>Re.id!==ae)),de=ae=>{s&&U1(s.id,ae),O(De=>De.filter(Re=>Re.id!==ae))},he=B.length+R.length,be=async()=>{if(o.trim()){j(!0);try{const ae=await a({title:o.trim(),description:d.trim()||void 0,tags:h.length>0?JSON.stringify(h):void 0,due_date:k||void 0,priority:y,...s?{status:w}:{}});if(f&&K.size>0&&await Promise.all([...K.entries()].map(([De,Re])=>f(De,{color:Re}))),R.length>0){const De=(s==null?void 0:s.id)??(ae==null?void 0:ae.id);De&&await $1(De,R.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:I,className:"input-field text-sm w-full mb-3",placeholder:m("plannerForm.titlePlaceholder"),value:o,onChange:ae=>l(ae.target.value),onKeyDown:ae=>{ae.key==="Enter"&&ae.preventDefault()}}),t.jsx("textarea",{className:"input-field text-sm w-full mb-3 min-h-[76px] max-h-[320px] resize-y [field-sizing:content]",rows:3,placeholder:m("plannerForm.descPlaceholder"),value:d,onChange:ae=>p(ae.target.value),onPaste:ne,onDrop:te,onDragOver:ae=>{ae.preventDefault(),ae.stopPropagation()}}),t.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[t.jsxs("button",{type:"button",onClick:()=>{var ae;return(ae=W.current)==null?void 0:ae.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}),m("plannerForm.addImage")]}),t.jsx("span",{className:"text-[10px] text-warm-300",children:m("plannerForm.pasteHint")})]}),t.jsx("input",{ref:W,type:"file",accept:"image/*",multiple:!0,className:"hidden",onChange:ae=>{ae.target.files&&ce(ae.target.files),ae.target.value=""}}),he>0&&t.jsxs("div",{className:"mb-4",children:[t.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[t.jsx("h4",{className:"text-xs font-semibold text-warm-500 uppercase tracking-wider",children:m("plannerForm.images")}),t.jsxs("span",{className:"text-[10px] text-warm-400",children:["(",he,")"]})]}),t.jsxs("div",{className:"flex flex-wrap gap-2",children:[B.map(ae=>t.jsxs("div",{className:"relative group",children:[t.jsx("img",{src:s?ju(s.id,ae.id):"",alt:ae.originalName,onClick:()=>s&&U(ju(s.id,ae.id)),className:"h-20 w-20 object-cover rounded-lg border border-warm-200 cursor-zoom-in"}),t.jsx("button",{type:"button",onClick:()=>de(ae.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(Vt,{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:ae.originalName})})]},ae.id)),R.map(ae=>t.jsxs("div",{className:"relative group",children:[t.jsx("img",{src:ae.preview,alt:ae.name,onClick:()=>U(ae.preview),className:"h-20 w-20 object-cover rounded-lg border border-accent/30 cursor-zoom-in"}),t.jsx("button",{type:"button",onClick:()=>G(ae.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(Vt,{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:ae.name})})]},ae.id))]})]}),t.jsxs("div",{className:"mb-4",children:[t.jsx("label",{className:"text-xs font-medium text-warm-500 mb-1.5 block",children:m("plannerForm.tags")}),t.jsxs("div",{className:"flex flex-wrap items-center gap-1.5 p-2 rounded-xl",style:{backgroundColor:"var(--color-bg-input)",border:"1px solid var(--color-border-strong)"},children:[h.map(ae=>t.jsxs("span",{className:`inline-flex items-center gap-1 px-2 py-0.5 rounded-md text-[11px] font-medium ${Wa(z.get(ae)||"default")}`,children:[ae,t.jsx("button",{onClick:()=>oe(ae),className:"opacity-60 hover:opacity-100",children:t.jsx(Vt,{size:12})})]},ae)),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:h.length===0?m("plannerForm.tagsPlaceholder"):"",value:b,onChange:ae=>{C(ae.target.value),N(!0)},onKeyDown:ae=>{(ae.key==="Enter"||ae.key===",")&&b.trim()&&(ae.preventDefault(),q(b.replace(",",""))),ae.key==="Backspace"&&!b&&h.length>0&&oe(h[h.length-1])},onFocus:()=>N(!0),onBlur:()=>setTimeout(()=>N(!1),150)}),D&&(Y.length>0||b.trim())&&t.jsxs(Gm,{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:[Y.slice(0,10).map(ae=>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(ae.name),children:t.jsx("span",{className:`px-2 py-0.5 rounded-md text-[11px] font-medium ${Wa(ae.color)}`,children:ae.name})},ae.name)),b.trim()&&!e.some(ae=>ae.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:m("plannerForm.dueDate")}),t.jsx("input",{type:"date",className:"input-field text-xs w-full",value:k,onChange:ae=>x(ae.target.value)})]}),t.jsxs("div",{children:[t.jsx("label",{className:"text-xs font-medium text-warm-500 mb-1.5 block",children:m("plannerForm.priority")}),t.jsxs("select",{className:"input-field text-xs w-full",value:y,onChange:ae=>_(Number(ae.target.value)),children:[t.jsx("option",{value:0,children:m("plannerForm.priorityLow")}),t.jsx("option",{value:1,children:m("plannerForm.priorityNormal")}),t.jsx("option",{value:2,children:m("plannerForm.priorityHigh")}),t.jsx("option",{value:3,children:m("plannerForm.priorityCritical")})]})]}),s&&t.jsxs("div",{children:[t.jsx("label",{className:"text-xs font-medium text-warm-500 mb-1.5 block",children:m("plannerForm.status")}),t.jsxs("select",{className:"input-field text-xs w-full",value:w,onChange:ae=>E(ae.target.value),children:[t.jsx("option",{value:"pending",children:m("plannerStatus.pending")}),t.jsx("option",{value:"in_progress",children:m("plannerStatus.in_progress")}),t.jsx("option",{value:"done",children:m("plannerStatus.done")})]})]})]}),t.jsxs("div",{className:"flex justify-end gap-3",children:[t.jsx("button",{className:"btn-ghost text-xs",onClick:u,children:m("plannerForm.cancel")}),t.jsx("button",{className:"btn-primary text-xs py-2",onClick:be,disabled:!o.trim()||T,children:m("plannerForm.save")})]}),F&&t.jsx(qp,{src:F,onClose:()=>U(null)})]})}function OS({item:e,mode:s,projectCliTool:i,onConvert:a,onClose:u}){const{t:f}=ht(),[m,o]=S.useState(i||"claude"),[l,d]=S.useState(""),[p,h]=S.useState(!1),[g,b]=S.useState("once"),[C,k]=S.useState("0 0 * * *"),[x,y]=S.useState(""),[_,w]=S.useState(!1),E=async()=>{w(!0);try{s==="todo"?await a({cli_tool:m,max_turns:l?Number(l):void 0}):s==="session"?await a({cli_tool:m,use_worktree:p}):await a({cli_tool:m,schedule_type:g,cron_expression:g==="recurring"?C:void 0,run_at:g==="once"?x:void 0})}finally{w(!1)}};return t.jsx(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:m,onChange:T=>o(T.target.value),children:[t.jsx("option",{value:"claude",children:"Claude"}),t.jsx("option",{value:"antigravity",children:"Antigravity"}),t.jsx("option",{value:"codex",children:"Codex"})]})]}),s==="todo"&&t.jsxs("div",{className:"mb-4",children:[t.jsx("label",{className:"text-xs font-medium text-warm-500 mb-1.5 block",children:f("plannerConvert.maxTurns")}),t.jsx("input",{type:"number",min:"1",className:"input-field text-xs w-full",placeholder:"—",value:l,onChange:T=>d(T.target.value)})]}),s==="session"&&t.jsxs("label",{className:"flex items-center gap-2 mb-4 cursor-pointer",children:[t.jsx("input",{type:"checkbox",checked:p,onChange:T=>h(T.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:T=>y(T.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:T=>k(T.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:_||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 iw(e){return xn(new Date(e))}function aw(e){return new Date(e.getFullYear(),e.getMonth(),1)}function BS(e){return new Date(e.getFullYear(),e.getMonth(),e.getDate())}function sr(e,s){const i=BS(e);return i.setDate(i.getDate()+s),i}function PS(e){return sr(e,-e.getDay())}function qO(e,s){return Math.round((new Date(s+"T00:00").getTime()-new Date(e+"T00:00").getTime())/864e5)}function GO(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=qO(a,i),f=m=>xn(sr(new Date(m+"T00:00"),u));return{startKey:f(s.startKey),endKey:f(s.endKey)}}function KO(e,s){if(e==="day"){const f=BS(s);return{rangeStart:xn(f),rangeEnd:xn(sr(f,1)),gridDays:[f],cols:1,dimOutOfMonth:!1}}if(e==="week"){const f=PS(s),m=Array.from({length:7},(o,l)=>sr(f,l));return{rangeStart:xn(f),rangeEnd:xn(sr(f,7)),gridDays:m,cols:7,dimOutOfMonth:!1}}if(e==="table"){const f=aw(s),m=new Date(s.getFullYear(),s.getMonth()+1,1);return{rangeStart:xn(f),rangeEnd:xn(m),gridDays:[],cols:7,dimOutOfMonth:!1}}const i=aw(s),a=sr(i,-i.getDay()),u=Array.from({length:42},(f,m)=>sr(a,m));return{rangeStart:xn(a),rangeEnd:xn(sr(a,42)),gridDays:u,cols:7,dimOutOfMonth:!0}}function IS(e,s){return S.useMemo(()=>KO(e,s),[e,s])}function FS(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 HS(e,s,i){if(s==="month"||s==="table")return e.toLocaleDateString(i,{year:"numeric",month:"long"});if(s==="week"){const a=PS(e);return`${a.toLocaleDateString(i,{month:"short",day:"numeric"})} – ${sr(a,6).toLocaleDateString(i,{month:"short",day:"numeric"})}`}return e.toLocaleDateString(i,{year:"numeric",month:"long",day:"numeric",weekday:"short"})}function $S(){const{lang:e}=ht();return S.useMemo(()=>{const s=new Date(2024,5,2);return Array.from({length:7},(i,a)=>sr(s,a).toLocaleDateString(e,{weekday:"short"}))},[e])}const VO=420,YO=140,XO=220,JO=26,Qf=16,ow=2;function QO(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 l=o.startKey<i?i:o.startKey,d=o.endKey>a?a:o.endKey;return{bar:o,startCol:e.findIndex(p=>xn(p)===l),endCol:e.findIndex(p=>xn(p)===d),contStart:o.startKey<i,contEnd:o.endKey>a}}).filter(o=>o.startCol>=0&&o.endCol>=0).sort((o,l)=>o.startCol-l.startCol||l.endCol-l.startCol-(o.endCol-o.startCol)),f=[];return{placed:u.map(o=>{let l=0;for(;l<f.length&&f[l]>=o.startCol;)l++;return f[l]=o.endCol,{...o,lane:l}}),laneCount:f.length}}function US({view:e,gridDays:s,cols:i,dimOutOfMonth:a,monthIdx:u,todayKey:f,selectedDate:m,chipsByDay:o,maxChips:l,weekdayLabels:d,addItemLabel:p,bars:h,onBarClick:g,onSelectDate:b,onQuickAdd:C,onChipClick:k,onCellContextMenu:x,onChipContextMenu:y,onBarContextMenu:_,onBarDrag:w,onChipDrag:E,monthCellHeight:T=92}){const{lang:j}=ht(),[D,N]=S.useState(null),[R,A]=S.useState(!1),B=S.useRef(null),O=S.useRef(null),F=()=>{O.current&&(clearTimeout(O.current),O.current=null)},U=(ne,te)=>{F(),B.current&&clearTimeout(B.current);const G=te.getBoundingClientRect();B.current=window.setTimeout(()=>N({key:ne,rect:G}),VO)},I=()=>{B.current&&(clearTimeout(B.current),B.current=null),O.current=window.setTimeout(()=>N(null),YO)};S.useEffect(()=>{if(!D){A(!1);return}const ne=requestAnimationFrame(()=>A(!0));return()=>cancelAnimationFrame(ne)},[D]),S.useEffect(()=>()=>{B.current&&clearTimeout(B.current),O.current&&clearTimeout(O.current)},[]),S.useEffect(()=>{if(!D)return;const ne=()=>N(null);return window.addEventListener("scroll",ne,!0),window.addEventListener("resize",ne),()=>{window.removeEventListener("scroll",ne,!0),window.removeEventListener("resize",ne)}},[D]);const H=D?o.get(D.key)??[]:[],[W,K]=S.useState(null),P=S.useRef(!1),z=4,$=(ne,te)=>{var G,de;return((de=(G=document.elementFromPoint(ne,te))==null?void 0:G.closest("[data-daykey]"))==null?void 0:de.getAttribute("data-daykey"))??null},Y=(ne,te,G)=>{ne.preventDefault(),ne.stopPropagation();const de=$(ne.clientX,ne.clientY)??G.origStart,he=ne.clientX,be=ne.clientY,ae=te!=="move";let De=ae,Re={startKey:G.origStart,endKey:G.origEnd};const ve=()=>K({kind:G.kind,entryKey:G.entryKey,curStart:Re.startKey,curEnd:Re.endKey,title:G.title,bg:G.bg,fg:G.fg,done:G.done}),Me=()=>{document.body.style.cursor=ae?"ew-resize":"grabbing",document.body.style.userSelect="none"};ae&&(Me(),ve());const Oe=nt=>{if(!De){if(Math.abs(nt.clientX-he)<z&&Math.abs(nt.clientY-be)<z)return;De=!0,Me()}const ke=$(nt.clientX,nt.clientY);ke&&(Re=GO(te,{startKey:G.origStart,endKey:G.origEnd},ke,de),ve())},tt=()=>{window.removeEventListener("pointermove",Oe),window.removeEventListener("pointerup",tt),document.body.style.cursor="",document.body.style.userSelect="",K(null),De&&(P.current=!0,setTimeout(()=>{P.current=!1},0),!(Re.startKey===G.origStart&&Re.endKey===G.origEnd)&&(G.kind==="bar"&&G.bar?w==null||w(G.bar,Re.startKey,Re.endKey):G.kind==="chip"&&G.chip&&(E==null||E(G.chip,Re.startKey,Re.endKey))))};window.addEventListener("pointermove",Oe),window.addEventListener("pointerup",tt)},q=(()=>{const ne=h??[];return W?W.kind==="bar"?ne.map(te=>te.key===W.entryKey?{...te,startKey:W.curStart,endKey:W.curEnd}:te):[...ne,{key:`__drag__${W.entryKey}`,title:W.title,startKey:W.curStart,endKey:W.curEnd,bg:W.bg,fg:W.fg,done:W.done}]:ne})(),oe=(ne,te)=>{const G=xn(ne),de=o.get(G)??[],he=!a||ne.getMonth()===u,be=G===f,ae=G===m,De=e==="week"?"min-h-[360px]":e==="day"?"min-h-[480px]":"",Re=e==="month"&&de.length>l;return t.jsxs("div",{"data-daykey":G,onClick:()=>{P.current||b(G)},onContextMenu:x?ve=>x(G,ve):void 0,onMouseEnter:Re?ve=>U(G,ve.currentTarget):void 0,onMouseLeave:Re?I:void 0,className:`group relative ${De} text-left p-1.5 flex flex-col gap-1 transition-colors cursor-pointer`,style:{minHeight:e==="month"?T+te:void 0,backgroundColor:ae?"var(--color-bg-hover)":"var(--color-bg-card)",opacity:he?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:ne.toLocaleDateString(j,{weekday:"short"})}),t.jsx("span",{className:"text-xs font-medium w-5 h-5 flex items-center justify-center rounded-full",style:be?{backgroundColor:"var(--color-accent)",color:"#fff"}:{color:"var(--color-text-secondary)"},children:ne.getDate()})]}),t.jsx("button",{onClick:ve=>{ve.stopPropagation(),C(G)},className:"absolute top-1 right-1 opacity-0 group-hover:opacity-100 transition-opacity rounded-md w-5 h-5 flex items-center justify-center hover:bg-theme-hover",title:p,style:{backgroundColor:"var(--color-bg-secondary)",color:"var(--color-text-secondary)",border:"1px solid var(--color-border)"},children:t.jsx(vn,{size:14})}),t.jsxs("div",{className:"flex flex-col gap-0.5 overflow-hidden",style:{marginTop:te||void 0},children:[de.slice(0,l).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:G,origEnd:G,title:ve.title,bg:ve.bg,fg:ve.fg,done:ve.done,chip:ve};return t.jsxs("span",{onClick:tt=>{tt.stopPropagation(),!P.current&&k(ve)},onPointerDown:Me?tt=>Y(tt,"move",Oe):void 0,onContextMenu:y?tt=>y(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(),Y(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)}),de.length>l&&t.jsxs("span",{className:"text-2xs px-1",style:{color:"var(--color-text-muted)"},children:["+",de.length-l]})]})]},G)},ce=[];if(e==="month")for(let ne=0;ne<s.length;ne+=i)ce.push(s.slice(ne,ne+i));return t.jsxs(t.Fragment,{children:[(e==="month"||e==="week")&&t.jsx("div",{className:"grid gap-px text-2xs uppercase tracking-wider mb-1",style:{gridTemplateColumns:`repeat(${i}, minmax(0, 1fr))`,color:"var(--color-text-muted)"},children:d.map(ne=>t.jsx("div",{className:"px-2 py-1",children:ne},ne))}),e==="month"?t.jsx("div",{className:"flex flex-col gap-px rounded-xl overflow-hidden",style:{backgroundColor:"var(--color-border)"},children:ce.map((ne,te)=>{const{placed:G,laneCount:de}=QO(ne,q),he=de*(Qf+ow);return t.jsxs("div",{className:"relative grid gap-px",style:{gridTemplateColumns:`repeat(${i}, minmax(0, 1fr))`,backgroundColor:"var(--color-border)"},children:[ne.map(be=>oe(be,he)),G.map(({bar:be,startCol:ae,endCol:De,lane:Re,contStart:ve,contEnd:Me})=>{const Oe=!!w&&!be.key.startsWith("__drag__"),tt={kind:"bar",entryKey:be.key,origStart:be.startKey,origEnd:be.endKey,title:be.title,bg:be.bg,fg:be.fg,done:be.done,bar:be};return t.jsxs("div",{onClick:nt=>{nt.stopPropagation(),!P.current&&(g==null||g(be))},onPointerDown:Oe?nt=>Y(nt,"move",tt):void 0,onContextMenu:_?nt=>_(be,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(${ae} / ${i} * 100% + 2px)`,width:`calc(${De-ae+1} / ${i} * 100% - 4px)`,top:JO+Re*(Qf+ow),height:Qf,backgroundColor:be.bg,color:be.fg,textDecoration:be.done?"line-through":"none",borderRadius:4,borderTopLeftRadius:ve?0:4,borderBottomLeftRadius:ve?0:4,borderTopRightRadius:Me?0:4,borderBottomRightRadius:Me?0:4},title:be.title,children:[ve?"◀ ":"",be.title,Me?" ▶":"",Oe&&!ve&&t.jsx("span",{onPointerDown:nt=>{nt.stopPropagation(),Y(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(),Y(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)"}})]},be.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(ne=>oe(ne,0))}),D&&(()=>{const ne=Math.max(D.rect.width,XO),te=Math.min(Math.max(8,D.rect.left),window.innerWidth-ne-8),G=Math.max(8,Math.min(D.rect.top,window.innerHeight-120)),de=window.innerHeight-G-16,he=Number(D.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:G,width:ne,maxHeight:de,overflowY:"auto",backgroundColor:"var(--color-bg-card)",border:"1px solid var(--color-border)",padding:6,transformOrigin:"top left",transform:R?"scale(1)":"scale(0.96)",opacity:R?1:0,transition:"transform 140ms ease, opacity 140ms ease"},children:[t.jsx("div",{className:"text-xs font-semibold px-1 pb-1",style:{color:"var(--color-text-secondary)"},children:he}),t.jsx("div",{className:"flex flex-col gap-0.5",children:H.map(be=>t.jsxs("span",{onClick:ae=>{ae.stopPropagation(),k(be),N(null)},onContextMenu:y?ae=>y(be,ae):void 0,className:"text-2xs truncate px-1 py-0.5 rounded-md cursor-pointer hover:opacity-80 transition-opacity",style:{backgroundColor:be.bg,color:be.fg,textDecoration:be.done?"line-through":"none"},title:be.title,children:[be.prefix??"",be.time?`${be.time} `:"",be.title]},be.key))})]}),document.body)})()]})}function ZO(e){if(!e)return[];try{const s=JSON.parse(e);return Array.isArray(s)?s.filter(i=>typeof i=="string"):[]}catch{return[]}}function eB({view:e,items:s,tagColors:i,onQuickAdd:a,onEditItem:u,onConvert:f,onDeleteItem:m,onUpdateRange:o}){const{t:l,lang:d}=ht(),[p,h]=S.useState(()=>new Date),[g,b]=S.useState(()=>xn(new Date)),[C,k]=S.useState(null),x=$S(),{gridDays:y,cols:_,dimOutOfMonth:w}=IS(e,p),E=xn(new Date),T=p.getMonth(),j=e==="month"?3:99,D=ce=>h(ne=>FS(ne,e,ce)),N=()=>{h(new Date),b(xn(new Date))},R=HS(p,e,d);S.useEffect(()=>{e==="day"&&b(xn(p))},[e,p]);const A=260,B=760,O=S.useRef(null),[F,U]=S.useState(()=>{const ce=parseInt(localStorage.getItem("plannerCalendarPanelWidth")||"",10);return Number.isFinite(ce)&&ce>=A&&ce<=B?ce:320});S.useEffect(()=>{try{localStorage.setItem("plannerCalendarPanelWidth",String(F))}catch{}},[F]);const I=ce=>{ce.preventDefault();const ne=G=>{var he;const de=(he=O.current)==null?void 0:he.getBoundingClientRect();de&&U(Math.min(B,Math.max(A,de.right-G.clientX)))},te=()=>{window.removeEventListener("pointermove",ne),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",ne),window.addEventListener("pointerup",te)},[H,W]=S.useState(new Map);S.useEffect(()=>{W(new Map)},[s]);const K=S.useMemo(()=>H.size===0?s:s.map(ce=>{const ne=H.get(ce.id);return ne?{...ce,due_date:ne.due_date,end_date:ne.end_date}:ce}),[s,H]),P=S.useCallback((ce,ne,te)=>{W(G=>new Map(G).set(ce,{due_date:ne,end_date:te})),o(ce,ne,te)},[o]),z=ce=>!!(ce.due_date&&ce.end_date&&ce.end_date.slice(0,10)>ce.due_date.slice(0,10)),$=S.useMemo(()=>{const ce=new Map;for(const ne of K){if(!ne.due_date||e==="month"&&z(ne))continue;const te=ne.due_date.slice(0,10),G=ne.status==="done",de=ce.get(te)??[];de.push({key:ne.id,title:ne.title,bg:"var(--color-bg-secondary)",fg:G?"var(--color-text-muted)":"var(--color-text-secondary)",done:G,payload:ne,draggable:!0}),ce.set(te,de)}return ce},[K,e]),Y=S.useMemo(()=>e!=="month"?[]:K.filter(z).map(ce=>{const ne=ce.status==="done";return{key:ce.id,title:ce.title,startKey:ce.due_date.slice(0,10),endKey:ce.end_date.slice(0,10),bg:"var(--color-bg-secondary)",fg:ne?"var(--color-text-muted)":"var(--color-text-secondary)",done:ne,payload:ce}}),[K,e]),q=S.useMemo(()=>s.filter(ce=>ce.due_date&&ce.due_date.slice(0,10)===g),[s,g]),oe=S.useMemo(()=>s.filter(ce=>!ce.due_date),[s]);return t.jsxs("div",{ref:O,className:"card flex overflow-hidden",style:{minHeight:520},children:[t.jsxs("div",{className:"flex-1 flex flex-col overflow-hidden min-w-0",children:[t.jsxs("div",{className:"px-4 pt-3 pb-2 flex items-center gap-2",children:[t.jsx("button",{onClick:()=>D(-1),className:"btn-ghost p-1.5","aria-label":"prev",children:t.jsx(sp,{size:16})}),t.jsx("div",{className:"text-sm font-semibold min-w-[8rem] text-center",style:{color:"var(--color-text-primary)"},children:R}),t.jsx("button",{onClick:()=>D(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:l("agenda.today")})]}),t.jsx("div",{className:"flex-1 overflow-auto px-4 pb-4",children:t.jsx(US,{view:e,gridDays:y,cols:_,dimOutOfMonth:w,monthIdx:T,todayKey:E,selectedDate:g,chipsByDay:$,maxChips:j,weekdayLabels:x,addItemLabel:l("agenda.addItem"),onSelectDate:b,onQuickAdd:a,onChipClick:ce=>u(ce.payload),onCellContextMenu:(ce,ne)=>{ne.preventDefault(),k({x:ne.clientX,y:ne.clientY,dateKey:ce})},bars:Y,onBarClick:ce=>u(ce.payload),onBarDrag:(ce,ne,te)=>P(ce.payload.id,ne,te),onChipDrag:(ce,ne,te)=>P(ce.payload.id,ne,te)})})]}),t.jsx("div",{onPointerDown:I,className:"w-1.5 flex-shrink-0 cursor-col-resize hover:bg-accent/40 transition-colors",style:{backgroundColor:"var(--color-border)"},title:l("agenda.resizePanel")}),t.jsxs("div",{className:"flex-shrink-0 flex flex-col overflow-hidden",style:{width: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(d,{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(vn,{size:14}),l("agenda.add")]})]}),t.jsxs("div",{className:"flex-1 overflow-auto px-4 pb-4 flex flex-col gap-4",children:[t.jsxs("div",{className:"flex flex-col gap-1.5",children:[q.length===0&&t.jsx("p",{className:"text-xs py-2",style:{color:"var(--color-text-muted)"},children:l("agenda.dayEmpty")}),q.map(ce=>t.jsx(lw,{item:ce,tagColors:i,onEdit:u,onConvert:f,onDelete:m},ce.id))]}),t.jsxs("div",{children:[t.jsx("h4",{className:"text-2xs uppercase tracking-wider mb-1.5",style:{color:"var(--color-text-muted)"},children:l("agenda.backlog")}),t.jsxs("div",{className:"flex flex-col gap-1.5",children:[oe.length===0&&t.jsx("p",{className:"text-xs py-1",style:{color:"var(--color-text-muted)"},children:l("agenda.backlogEmpty")}),oe.map(ce=>t.jsx(lw,{item:ce,tagColors:i,onEdit:u,onConvert:f,onDelete:m},ce.id))]})]})]})]}),C&&t.jsx(Ws,{x:C.x,y:C.y,onClose:()=>k(null),children:t.jsxs("button",{type:"button",className:en,onClick:()=>a(C.dateKey),children:[t.jsx(vn,{size:14}),l("planner.add")]})})]})}function lw({item:e,tagColors:s,onEdit:i,onConvert:a,onDelete:u}){const{t:f}=ht(),{confirm:m}=qn(),[o,l]=S.useState(!1),[d,p]=S.useState(!1),[h,g]=S.useState({top:0,left:0}),b=S.useRef(null),C=S.useRef(null),k=ZO(e.tags),x=e.status==="moved",y=S.useCallback(()=>{if(!b.current)return;const _=b.current.getBoundingClientRect(),w=window.innerWidth,E=window.innerHeight;let T=_.bottom+4;const j=C.current;if(j){const D=j.offsetWidth,N=j.offsetHeight;let R=_.right-D;R<8&&(R=8),R+D>w-8&&(R=w-8-D),T+N>E-8&&(T=_.top-N-4),g({top:T,left:R}),p(!0)}else g({top:T,left:Math.max(8,_.right-180)})},[]);return S.useEffect(()=>{if(!o){p(!1);return}y();const _=requestAnimationFrame(y),w=E=>{var j,D;const T=E.target;(j=b.current)!=null&&j.contains(T)||(D=C.current)!=null&&D.contains(T)||l(!1)};return document.addEventListener("mousedown",w),window.addEventListener("scroll",y,!0),window.addEventListener("resize",y),()=>{cancelAnimationFrame(_),document.removeEventListener("mousedown",w),window.removeEventListener("scroll",y,!0),window.removeEventListener("resize",y)}},[o,y]),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 ${Pu[e.status]||Pu.pending}`,children:f(`plannerStatus.${e.status}`)}),k.map(_=>t.jsx("span",{className:`px-1.5 py-0.5 rounded-md text-2xs font-medium ${Wa(s.get(_)||"default")}`,children:_},_))]})]}),t.jsxs("div",{className:"flex-shrink-0",children:[t.jsx("button",{ref:b,onClick:_=>{_.stopPropagation(),l(!o)},className:"p-1 text-warm-400 hover:text-warm-600 hover:bg-warm-100/50 rounded-lg transition-colors opacity-0 group-hover:opacity-100",children:t.jsx(rp,{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:h.top,left:h.left,opacity:d?1:0,backgroundColor:"var(--color-bg-card)",border:"1px solid var(--color-border)"},onClick:()=>l(!1),children:[!x&&t.jsxs(t.Fragment,{children:[t.jsxs("button",{onClick:()=>a(e,"todo"),className:"flex items-center gap-2 w-full px-3 py-1.5 text-xs hover:bg-warm-100 rounded-md transition-colors text-left",style:{color:"var(--color-text-primary)"},children:[t.jsx(Xw,{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(qi,{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(gi,{size:12})," ",f("planner.convertToTerminal")]})]}),t.jsxs("button",{onClick:async()=>{await m({message:f("planner.deleteConfirm"),danger:!0})&&u(e.id)},className:"flex items-center gap-2 w-full px-3 py-1.5 text-xs text-status-error hover:bg-status-error/10 rounded-md transition-colors text-left",children:[t.jsx(An,{size:12})," ",f("planner.delete")]})]}),document.body)]})]})}const cw={pending:0,in_progress:1,done:2,moved:3};function tB({plannerItems:e,existingTags:s,projectCliTool:i,onAddItem:a,onEditItem:u,onDeleteItem:f,onConvertToTodo:m,onConvertToSchedule:o,onConvertToSession:l,onUpdateTag:d,onDeleteTag:p,onExport:h,onImport:g,view:b,onChangeView:C}){const{t:k}=ht(),{warning:x}=Ls(),[y,_]=S.useState(!1),[w,E]=S.useState(null),[T,j]=S.useState(void 0),[D,N]=S.useState(""),[R,A]=S.useState(""),[B,O]=S.useState("created_at"),[F,U]=S.useState("desc"),[I,H]=S.useState(null),[W,K]=S.useState("todo"),[P,z]=S.useState(!1),[$,Y]=S.useState(!1),[q,oe]=S.useState(null),ce=S.useRef(null),ne=S.useRef(0),te=async()=>{if(!(!h||P)){z(!0);try{await h()}finally{z(!1)}}},G=()=>{var fe;!g||P||(fe=ce.current)==null||fe.click()},de=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)}}},he=fe=>!!(/\.(md|markdown)$/i.test(fe.name)||fe.type==="text/markdown"),be=fe=>Array.from(fe.dataTransfer.types).includes("Files"),ae=fe=>{!g||P||be(fe)&&(fe.preventDefault(),ne.current++,Y(!0))},De=fe=>{!g||P||be(fe)&&(fe.preventDefault(),fe.dataTransfer.dropEffect="copy")},Re=fe=>{g&&(fe.preventDefault(),ne.current=Math.max(0,ne.current-1),ne.current===0&&Y(!1))},ve=async fe=>{var Ce;if(!g||(fe.preventDefault(),ne.current=0,Y(!1),P))return;const Te=(Ce=fe.dataTransfer.files)==null?void 0:Ce[0];if(Te){if(!he(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=>!(R&&Te.status!==R||D&&!(Te.tags?(()=>{try{return JSON.parse(Te.tags)}catch{return[]}})():[]).includes(D)));return fe=[...fe].sort((Te,Ce)=>{let Ke=0;switch(B){case"title":Ke=Te.title.localeCompare(Ce.title);break;case"tags":{const Ze=Te.tags?(()=>{try{return JSON.parse(Te.tags).join(",")}catch{return""}})():"",ye=Ce.tags?(()=>{try{return JSON.parse(Ce.tags).join(",")}catch{return""}})():"";Ke=(Ze||"zzz").localeCompare(ye||"zzz");break}case"priority":Ke=Te.priority-Ce.priority;break;case"due_date":{const Ze=Te.due_date||"9999",ye=Ce.due_date||"9999";Ke=Ze.localeCompare(ye);break}case"status":Ke=(cw[Te.status]??9)-(cw[Ce.status]??9);break;case"created_at":Ke=Te.created_at.localeCompare(Ce.created_at);break}return F==="asc"?Ke:-Ke}),fe},[e,D,R,B,F]),nt=fe=>{B===fe?U(Te=>Te==="asc"?"desc":"asc"):(O(fe),U(fe==="priority"?"desc":"asc"))},ke=({field:fe})=>B!==fe?null:F==="asc"?t.jsx(u5,{size:12,className:"inline ml-0.5"}):t.jsx(i5,{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:D,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:R,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")})]}),h&&t.jsxs("button",{onClick:te,disabled:P||e.length===0,className:"btn-secondary text-xs py-2 whitespace-nowrap shrink-0 disabled:opacity-50",title:k("planner.exportTooltip"),children:[t.jsx(cm,{size:14,className:"inline-block shrink-0"}),k("planner.export")]}),g&&t.jsxs(t.Fragment,{children:[t.jsxs("button",{onClick:G,disabled:P,className:"btn-secondary text-xs py-2 whitespace-nowrap shrink-0 disabled:opacity-50",title:k("planner.importTooltip"),children:[t.jsx(nb,{size:14,className:"inline-block shrink-0"}),k("planner.import")]}),t.jsx("input",{ref:ce,type:"file",accept:".md,.markdown,text/markdown",className:"hidden",onChange:de})]}),!y&&!w&&t.jsxs("button",{onClick:()=>_(!0),className:"btn-primary text-xs py-2 whitespace-nowrap shrink-0",children:[t.jsx(vn,{size:14,className:"inline-block shrink-0"}),k("planner.add")]})]})]}),(y||w)&&t.jsx("div",{className:"mb-5",children:t.jsx(WO,{existingTags:s,editItem:w,initialDueDate:T,onSave:async fe=>{if(w){await u(w.id,fe),E(null);return}else{const Te=await a(fe);return _(!1),j(void 0),Te}},onCancel:()=>{_(!1),E(null),j(void 0)},onUpdateTag:d})}),b==="table"?t.jsxs("div",{className:"card relative",onDragEnter:g?ae:void 0,onDragOver:g?De:void 0,onDragLeave:g?Re:void 0,onDrop:g?ve:void 0,onContextMenu:fe=>{xi(fe)||(fe.preventDefault(),oe({x:fe.clientX,y:fe.clientY}))},children:[$&&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(nb,{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:AE,title:k("planner.empty"),description:k("planner.emptyHint")}):tt.map((fe,Te)=>t.jsx("div",{children:t.jsx($O,{item:fe,tagColors:Oe,existingTags:Me,onSave:async(Ce,Ke)=>{await u(Ce,Ke)},onDelete:()=>f(fe.id),onConvertToTodo:()=>{H(fe),K("todo")},onConvertToSchedule:()=>{H(fe),K("schedule")},onConvertToSession:()=>{H(fe),K("session")},onUpdateTag:d})},fe.id))]}):t.jsx(eB,{view:b,items:tt,tagColors:Oe,onQuickAdd:fe=>{E(null),j(fe),_(!0)},onEditItem:fe=>{_(!1),E(fe)},onConvert:(fe,Te)=>{H(fe),K(Te)},onDeleteItem:f,onUpdateRange:(fe,Te,Ce)=>{u(fe,{due_date:Te,end_date:Ce})}}),I&&t.jsx(OS,{item:I,mode:W,projectCliTool:i,onConvert:async fe=>{W==="todo"?await m(I.id,fe):W==="session"?await l(I.id,fe):await o(I.id,fe),H(null)},onClose:()=>H(null)}),q&&t.jsx(Ws,{x:q.x,y:q.y,onClose:()=>oe(null),children:t.jsxs("button",{type:"button",className:en,onClick:()=>{E(null),j(void 0),_(!0)},children:[t.jsx(vn,{size:14}),k("planner.add")]})})]})}const WS=S.createContext(null),nB=WS.Provider;function DP(){const e=S.useContext(WS);if(!e)throw new Error("usePlannerPage must be used within a PlannerPageProvider");return e}const sB=S.lazy(()=>qu(()=>import("./PlannerPageEditor-BcGssFyo.js").then(e=>e.a),__vite__mapDeps([5,3,6,7,8]))),rB=800;function iB({pageId:e,projectId:s,projectCliTool:i,existingTags:a,onTitleChange:u,onConvertToTodo:f,onConvertToSchedule:m,onConvertToSession:o}){const{t:l}=ht(),[d,p]=S.useState(null),[h,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 rL(e).then(D=>{j||(p(D),k.current={title:D.title,content:D.content??null})}),()=>{j=!0}},[e]);const y=S.useCallback(()=>{x.current&&(clearTimeout(x.current),x.current=null);const{title:j,content:D}=k.current;return g("saving"),iL(e,{title:j,content:D??void 0}).then(()=>g("saved"))},[e]);S.useEffect(()=>()=>{x.current&&y()},[y]);const _=S.useCallback(()=>{x.current&&clearTimeout(x.current),g("saving"),x.current=setTimeout(()=>{y()},rB)},[y]),w=j=>{k.current.title=j,p(D=>D&&{...D,title:j}),u(e,j),_()},E=j=>{k.current.content=j,_()},T=S.useCallback((j,D,N)=>{C({item:j,mode:D,onDone:N})},[]);return d?t.jsxs(nB,{value:{projectId:s,pageId:e,projectCliTool:i,existingTags:a,openConvert:T},children:[t.jsxs("div",{className:"flex-1 min-w-0 flex flex-col",children:[t.jsxs("div",{className:"flex items-center gap-3 px-6 pt-5 pb-2",children:[t.jsx("input",{value:d.title,onChange:j=>w(j.target.value),placeholder:l("planner.pages.untitled"),className:"flex-1 bg-transparent text-2xl font-bold outline-none",style:{color:"var(--color-text-primary)"}}),t.jsx("span",{className:"text-2xs text-warm-400 flex-shrink-0",children:h==="saving"?l("planner.pages.saving"):h==="saved"?l("planner.pages.saved"):""})]}),t.jsx("div",{className:"flex-1 overflow-y-auto pb-6",children:t.jsx(S.Suspense,{fallback:null,children:t.jsx(sB,{pageId:e,initialContent:d.content??null,onChange:E})})})]}),b&&t.jsx(OS,{item:b.item,mode:b.mode,projectCliTool:i,onConvert:async j=>{const{item:D,mode:N,onDone:R}=b;N==="todo"?await f(D.id,j):N==="session"?await o(D.id,j):await m(D.id,j),R==null||R(),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"},uw=e=>({type:"bulletListItem"}),Fi=e=>({type:"checkListItem"}),dw=()=>({type:"tasklist"}),hw=()=>({type:"calendar"}),aB=[{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,"안건"),uw(),Rn(2,"논의"),Qo(),Rn(2,"액션 아이템"),dw()]},{id:"project",labelKey:"planner.tpl.project",descKey:"planner.tpl.project.desc",title:"프로젝트 플랜",blocks:[Rn(1,"프로젝트 플랜"),Rn(2,"개요"),Qo(),Rn(2,"마일스톤"),dw(),Rn(2,"일정"),hw(),Rn(2,"리스크 / 메모"),Qo()]},{id:"weekly",labelKey:"planner.tpl.weekly",descKey:"planner.tpl.weekly.desc",title:"위클리 플래너",blocks:[Rn(1,"위클리 플래너"),Rn(2,"이번 주 목표"),uw(),Rn(2,"요일별 할 일"),Rn(3,"월요일"),Fi(),Rn(3,"화요일"),Fi(),Rn(3,"수요일"),Fi(),Rn(3,"목요일"),Fi(),Rn(3,"금요일"),Fi(),Rn(3,"토요일"),Fi(),Rn(3,"일요일"),Fi(),Rn(2,"주간 일정"),hw()]}];function oB({onResize:e}){return t.jsx("div",{role:"separator","aria-orientation":"vertical",onPointerDown:s=>{s.preventDefault();const i=s.currentTarget;i.setPointerCapture(s.pointerId),document.body.style.cursor="col-resize",document.body.style.userSelect="none";let a=null,u=null;const f=()=>{if(a=null,u===null)return;const l=u;u=null,e(l)},m=l=>{u=l.clientX,a===null&&(a=requestAnimationFrame(f))},o=l=>{a!==null&&cancelAnimationFrame(a),a=null,l.type==="pointerup"&&u!==null&&f(),u=null,document.body.style.cursor="",document.body.style.userSelect="",i.removeEventListener("pointermove",m),i.removeEventListener("pointerup",o),i.removeEventListener("pointercancel",o)};i.addEventListener("pointermove",m),i.addEventListener("pointerup",o),i.addEventListener("pointercancel",o)},className:"w-1.5 shrink-0 cursor-col-resize bg-warm-300 hover:bg-accent active:bg-accent transition-colors"})}const fw=160,mw=480,pw="plannerSidebarWidth",gw="plannerSidebarCollapsed";function lB({projectId:e,...s}){const{t:i}=ht(),{confirm:a}=qn(),[u,f]=S.useState([]),[m,o]=S.useState({kind:"work"}),[l,d]=S.useState("table"),[p,h]=S.useState(!1),[g,b]=S.useState({top:0,left:0}),C=S.useRef(null),k=S.useRef(null),x=S.useRef(!1),[y,_]=S.useState(()=>{const K=Number(localStorage.getItem(pw));return K>=fw&&K<=mw?K:208}),w=S.useCallback(K=>{var $;const P=(($=k.current)==null?void 0:$.getBoundingClientRect().left)??0,z=Math.round(Math.max(fw,Math.min(mw,K-P)));_(z),localStorage.setItem(pw,String(z))},[]),[E,T]=S.useState(()=>localStorage.getItem(gw)==="1"),j=()=>T(K=>(localStorage.setItem(gw,K?"0":"1"),!K)),D=240,N=()=>{var P;const K=(P=C.current)==null?void 0:P.getBoundingClientRect();if(K){const z=Math.min(K.left,window.innerWidth-D-8);b({top:K.bottom+4,left:Math.max(8,z)})}h(!0)};S.useEffect(()=>{if(!p)return;const K=()=>h(!1),P=z=>{var $;($=C.current)!=null&&$.contains(z.target)||z.target.closest("[data-template-picker]")||h(!1)};return document.addEventListener("mousedown",P),window.addEventListener("scroll",K,!0),window.addEventListener("resize",K),()=>{document.removeEventListener("mousedown",P),window.removeEventListener("scroll",K,!0),window.removeEventListener("resize",K)}},[p]),S.useEffect(()=>{nL(e).then(K=>{f(K),x.current||(x.current=!0,K.length>0&&o({kind:"page",id:K[0].id}))})},[e]);const R=async K=>{h(!1);const P=await sL(e,K.title||i("planner.pages.untitled"),K.blocks?JSON.stringify(K.blocks):void 0);f(z=>[...z,P]),o({kind:"page",id:P.id})},A=async K=>{await a({message:i("planner.pages.deleteConfirm"),danger:!0})&&(await aL(K),f(P=>P.filter(z=>z.id!==K)),o(P=>P.kind==="page"&&P.id===K?{kind:"work"}:P))},B=S.useCallback((K,P)=>{f(z=>z.map($=>$.id===K?{...$,title:P}:$))},[]),O=()=>{o({kind:"work"}),d(K=>K==="table"?"month":K)},F=()=>{o({kind:"work"}),d("table")},U=m.kind==="work",I=U&&l!=="table",H=U&&l==="table",W=(K,P,z,$,Y)=>t.jsxs("div",{onClick:P,className:`group flex items-center gap-2 px-2.5 py-1.5 rounded-lg cursor-pointer transition-colors ${K?"":"hover:bg-warm-50"}`,style:K?{backgroundColor:"var(--color-bg-tertiary)"}:void 0,children:[z,t.jsx("span",{className:"flex-1 text-sm truncate",style:{color:"var(--color-text-primary)"},children:$}),Y]});return t.jsxs("div",{className:"flex gap-4",style:{minHeight:"70vh"},children:[E?t.jsx("div",{className:"flex-shrink-0 flex flex-col items-center card p-1.5",children:t.jsx("button",{onClick:j,className:"p-1 text-warm-400 hover:text-warm-600 transition-colors",title:i("sidebar.expand"),children:t.jsx(l1,{size:14})})}):t.jsxs(t.Fragment,{children:[t.jsxs("div",{ref:k,className:"flex-shrink-0 flex flex-col card p-2 overflow-y-auto",style:{width:y},children:[t.jsxs("div",{className:"flex items-center justify-between px-2.5 pt-1 pb-1",children:[t.jsx("span",{className:"text-2xs font-semibold uppercase tracking-wider text-warm-400",children:i("planner.view.pages")}),t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("button",{ref:C,onClick:()=>p?h(!1):N(),className:"text-warm-400 hover:text-warm-600 transition-colors",title:i("planner.pages.new"),children:t.jsx(vn,{size:14})}),t.jsx("button",{onClick:j,className:"text-warm-400 hover:text-warm-600 transition-colors",title:i("sidebar.collapse"),children:t.jsx(o1,{size:14})})]})]}),u.map(K=>W(m.kind==="page"&&m.id===K.id,()=>o({kind:"page",id:K.id}),t.jsx(tl,{size:14,className:"text-warm-400 flex-shrink-0"}),K.title||i("planner.pages.untitled"),t.jsx("button",{onClick:P=>{P.stopPropagation(),A(K.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")}),W(I,O,t.jsx(lm,{size:14,className:"text-warm-400 flex-shrink-0"}),i("planner.nav.calendar")),W(H,F,t.jsx(_u,{size:14,className:"text-warm-400 flex-shrink-0"}),i("planner.nav.list"))]}),t.jsx(oB,{onResize:w})]}),t.jsx("div",{className:"flex-1 min-w-0 flex flex-col",children:m.kind==="page"?t.jsx("div",{className:"card flex flex-col flex-1",children:t.jsx(iB,{pageId:m.id,projectId:e,projectCliTool:s.projectCliTool,existingTags:s.existingTags,onTitleChange:B,onConvertToTodo:s.onConvertToTodo,onConvertToSchedule:s.onConvertToSchedule,onConvertToSession:s.onConvertToSession},m.id)}):t.jsx(tB,{...s,view:l,onChangeView:d})}),p&&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:D,backgroundColor:"var(--color-bg-card)",border:"1px solid var(--color-border)"},children:aB.map(K=>t.jsxs("button",{onClick:()=>R(K),className:"w-full text-left px-3 py-2 hover:bg-warm-100 transition-colors",children:[t.jsx("div",{className:"text-sm font-medium",style:{color:"var(--color-text-primary)"},children:i(K.labelKey)}),t.jsx("div",{className:"text-2xs text-warm-400 mt-0.5",children:i(K.descKey)})]},K.id))}),document.body)]})}const qS="webPanelTabs",cB="plannerWebPanelUrl",Gp="https://www.notion.so",uB="electronAPI"in window;function dB(e){const s=e.trim();return s?/^https?:\/\//i.test(s)?s:`https://${s}`:Gp}function Km(e=""){return{id:Date.now().toString(36)+Math.random().toString(36).slice(2,8),src:e,url:e,title:""}}function hB(){var s;try{const i=JSON.parse(localStorage.getItem(qS)||"");if((s=i.tabs)!=null&&s.length){const a=i.tabs.map(({id:f,url:m})=>({id:f,src:m,url:m,title:""})),u=a.some(f=>f.id===i.activeId)?i.activeId:a[0].id;return{tabs:a,activeId:u}}}catch{}const e=Km(localStorage.getItem(cB)||Gp);return{tabs:[e],activeId:e.id}}function fB(){const{t:e}=ht(),[{tabs:s,activeId:i},a]=S.useState(hB),u=s.find(y=>y.id===i)??s[0],[f,m]=S.useState(u.url),[o,l]=S.useState(!1),d=S.useRef(null),p=S.useRef(null);S.useEffect(()=>{localStorage.setItem(qS,JSON.stringify({tabs:s.map(({id:y,url:_})=>({id:y,url:_})),activeId:i}))},[s,i]),S.useEffect(()=>{m(u.url)},[u.id,u.url]);const h=S.useCallback((y,_)=>{a(w=>({...w,tabs:w.tabs.map(E=>E.id===y?{...E,..._}:E)}))},[]),g=S.useCallback((y="")=>{var w;const _=Km(y);a(E=>({tabs:[...E.tabs,_],activeId:_.id})),y||(w=d.current)==null||w.focus()},[]),b=y=>{a(_=>{const w=_.tabs.findIndex(T=>T.id===y),E=_.tabs.filter(T=>T.id!==y);if(E.length===0){const T=Km();return{tabs:[T],activeId:T.id}}return _.activeId!==y?{..._,tabs:E}:{tabs:E,activeId:E[Math.min(w,E.length-1)].id}})},C=()=>{const y=dB(f);m(y),h(u.id,{src:y,url:y})};S.useEffect(()=>{var _;const y=window.electronAPI;return(_=y==null?void 0:y.onWebPanelOpenUrl)==null?void 0:_.call(y,w=>g(w))},[g]),S.useEffect(()=>{const y=p.current;if(!y)return;const _=()=>{y.style.pointerEvents="none"},w=()=>{y.style.pointerEvents=""};return window.addEventListener("mousedown",_,!0),window.addEventListener("mouseup",w,!0),window.addEventListener("blur",w),()=>{window.removeEventListener("mousedown",_,!0),window.removeEventListener("mouseup",w,!0),window.removeEventListener("blur",w)}},[]);const k=S.useCallback(y=>{if(!y)return;const _=y.dataset.tabId,w=T=>h(_,{title:T.title}),E=T=>{const{url:j,isMainFrame:D}=T;D!==!1&&h(_,{url:j})};return y.addEventListener("page-title-updated",w),y.addEventListener("did-navigate",E),y.addEventListener("did-navigate-in-page",E),()=>{y.removeEventListener("page-title-updated",w),y.removeEventListener("did-navigate",E),y.removeEventListener("did-navigate-in-page",E)}},[h]),x=y=>{if(y.title)return y.title;try{return new URL(y.url).hostname}catch{return e("web.newTab")}};return t.jsxs("div",{className:o?"fixed inset-0 z-modal flex flex-col":"flex flex-col flex-1 min-h-0",style:o?{backgroundColor:"var(--color-bg-card)"}:void 0,children:[t.jsxs("div",{role:"tablist",className:"flex items-end gap-0.5 px-2 border-b border-theme-border overflow-x-auto",children:[s.map(y=>t.jsxs("div",{role:"tab","aria-selected":y.id===i,onClick:()=>a(_=>({..._,activeId:y.id})),className:`flex items-center gap-1 px-3 py-1.5 text-xs whitespace-nowrap cursor-pointer transition-colors ${y.id===i?"border-b-2 border-accent text-accent font-medium":"text-theme-text-secondary hover:text-theme-text"}`,children:[t.jsx("span",{className:"truncate max-w-[160px]",children:x(y)}),t.jsx("button",{type:"button",onClick:_=>{_.stopPropagation(),b(y.id)},className:"p-0.5 rounded hover:bg-theme-hover",title:e("web.closeTab"),"aria-label":e("web.closeTab"),children:t.jsx(Vt,{size:12})})]},y.id)),t.jsx("button",{type:"button",onClick:()=>g(),className:"p-1 mb-1 text-warm-400 hover:text-warm-600 hover:bg-warm-100 rounded-md transition-colors flex-shrink-0",title:e("web.newTab"),"aria-label":e("web.newTab"),children:t.jsx(vn,{size:14})})]}),t.jsxs("form",{onSubmit:y=>{y.preventDefault(),C()},className:"flex items-center gap-2 p-2 border-b border-theme-border",children:[t.jsx("input",{ref:d,value:f,onChange:y=>m(y.target.value),placeholder:e("web.urlPlaceholder"),className:"input-field flex-1",spellCheck:!1}),t.jsx(Bt,{type:"submit",size:"sm",children:e("web.go")}),t.jsx("button",{type:"button",onClick:()=>l(y=>!y),className:"p-1 text-warm-400 hover:text-warm-600 hover:bg-warm-100 rounded-md transition-colors flex-shrink-0",title:e(o?"web.exitFullscreen":"web.fullscreen"),children:o?t.jsx(Cl,{size:14}):t.jsx(fi,{size:14})})]}),t.jsx("div",{ref:p,className:"flex-1 min-h-0 flex flex-col",children:uB?s.map(y=>y.src?S.createElement("webview",{key:y.id,ref:k,"data-tab-id":y.id,src:y.src,partition:"persist:webpanel",allowpopups:"",className:y.id===i?"flex-1 min-h-0":"hidden"}):y.id===i&&t.jsx("div",{className:"flex-1 flex items-center justify-center text-sm text-theme-text-secondary",children:e("web.emptyTab")},y.id)):t.jsxs("div",{className:"flex-1 flex flex-col items-center justify-center gap-3 text-sm text-theme-text-secondary",children:[t.jsx("span",{children:e("web.desktopOnly")}),t.jsxs(Bt,{size:"sm",className:"flex items-center gap-1.5",onClick:()=>window.open(u.url||Gp,"_blank","noopener"),children:[t.jsx(ar,{size:14}),e("web.openExternal")]})]})})]})}const mB=S.lazy(()=>qu(()=>import("./AnalyticsPanel-BqveBWb3.js"),__vite__mapDeps([9,7,3,2]))),pB=S.lazy(()=>qu(()=>import("./VaultLayout-D_BWNBzo.js"),__vite__mapDeps([10,6,1,2,3,4])));function gB({onEvent:e,connected:s,sendMessage:i,subscribeBinary:a}){const{id:u}=Jm(),[f,m]=S.useState(null),[o,l]=S.useState([]),[d,p]=S.useState([]),[h,g]=S.useState(null),[b,C]=S.useState([]),[k,x]=S.useState([]),[y,_]=S.useState([]),[w,E]=S.useState([]),[T,j]=Gw(),D=["tasks","discussions","schedules","analytics"],N=T.get("tab")||"tasks",[R,A]=S.useState(D.includes(N)?"automation":N),[B,O]=S.useState(D.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]),U=S.useCallback(Q=>{A("automation"),O(Q),j(Q==="tasks"?{}:{tab:Q},{replace:!0})},[j]),[I,H]=S.useState(!0),[W,K]=S.useState(!1),[P,z]=S.useState(new Set),[$,Y]=S.useState(0),{t:q}=ht(),{success:oe,error:ce,info:ne}=Ls(),{sendNotification:te}=up(),G=S.useRef([]);S.useEffect(()=>{G.current=b},[b]),S.useEffect(()=>{u&&Promise.all([$N(u),vf(u),bb(u),yb(u),S4(),I1(u),Wc(u),qc(u)]).then(([Q,ze,ue,Fe,Ve,ft,Ne,at])=>{m(Q),l(ze),p(ue),C(Fe),x(ft),_(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(()=>K(!0)).finally(()=>H(!1))},[u]);const de=S.useRef(o);de.current=o,S.useEffect(()=>{if(!u)return;const Q=setInterval(()=>{de.current.some(ue=>ue.status==="running")&&vf(u).then(ue=>{l(Fe=>Fe.map(Ve=>{const ft=ue.find(Ne=>Ne.id===Ve.id);return ft&&ft.status!==Ve.status?ft:Ve}))}).catch(()=>{})},5e3);return()=>clearInterval(Q)},[u]);const he=S.useRef(s);S.useEffect(()=>{s&&!he.current&&u&&Promise.all([vf(u),bb(u),yb(u)]).then(([Q,ze,ue])=>{l(Q),p(ze),C(ue)}).catch(()=>{}),he.current=s},[s,u]),S.useEffect(()=>e(Q=>{if(Q.type==="todo:status-changed"&&Q.todoId&&Q.status){if(l(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")&&Y(ze=>ze+1),Q.status==="completed"||Q.status==="failed"){const ze=de.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;l(ue=>ue.some(Fe=>Fe.id===ze.id)?ue:[...ue,ze])}if(Q.type==="schedule:status-changed"&&Q.scheduleId&&p(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=G.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 be=S.useCallback(async(Q,ze,ue,Fe,Ve,ft,Ne,at,bt,Ct)=>{if(!u)return;const Gt=await xb(u,{title:Q,description:ze,cli_tool:ue,depends_on:Ve,max_turns:ft??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 z1(Gt.id,Fe.map(Pn=>({name:Pn.name,data:Pn.data})));Gt.images=JSON.stringify(an.images)}l(an=>[...an,Gt])},[u]),ae=S.useCallback((Q,ze=[])=>{const ue=Q.split("/").filter(Boolean).pop()??Q,Fe=[Q,...ze].map(Ve=>`@${Ve}`).join(`
|
|
682
682
|
`);return be(ue,`다음 파일을 참고하세요:
|
|
683
683
|
${Fe}`)},[be]),De=S.useCallback(async(Q,ze)=>{const ue=ze==="interactive";ue&&z(Fe=>new Set(Fe).add(Q));try{const Fe=await vb(Q,ze);l(Ve=>Ve.map(ft=>ft.id===Q?Fe:ft))}catch(Fe){throw ue&&z(Ve=>{const ft=new Set(Ve);return ft.delete(Q),ft}),Fe}},[]),Re=S.useCallback(async Q=>{const ze=await u4(Q);l(ue=>ue.map(Fe=>Fe.id===Q?ze:Fe))},[]),ve=S.useCallback(async Q=>{await D1(Q),l(ze=>ze.filter(ue=>ue.id!==Q))},[]),Me=S.useCallback(async(Q,ze,ue,Fe,Ve,ft,Ne,at,bt,Ct)=>{const Gt=await Uc(Q,{title:ze,description:ue,cli_tool:Fe,depends_on:Ve??null,max_turns:ft??null,use_worktree:Ne===void 0?null:Ne,...at?{memory_inject_mode:at}:{},...bt?{memory_node_ids:bt}:{},...Ct?{memory_raw_file_paths:Ct}:{}});l(an=>an.map(Pn=>Pn.id===Q?Gt:Pn))},[]),Oe=S.useCallback(async Q=>{await R1(Q),l(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 f4(Q),ue=new Set(ze.mergedIds);l(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 M1(Q,ze),l(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 m4(Q,ze);l(Ve=>Ve.map(ft=>ft.id===Q?Fe:ft))}catch(Fe){throw ue&&z(Ve=>{const ft=new Set(Ve);return ft.delete(Q),ft}),Fe}},[]),fe=S.useCallback(async(Q,ze,ue)=>{const Fe=ue==="interactive";Fe&&z(Ve=>new Set(Ve).add(Q));try{const Ve=await A1(Q,ze,ue);l(ft=>ft.map(Ne=>Ne.id===Q?Ve:Ne))}catch(Ve){throw Fe&&z(ft=>{const Ne=new Set(ft);return Ne.delete(Q),Ne}),Ve}},[]),Te=S.useCallback(async(Q,ze,ue)=>{const Fe=await v4(Q,ze,ue);Fe.original_deleted&&l(Ve=>Ve.filter(ft=>ft.id!==Q)),p(Ve=>[Fe.schedule,...Ve])},[]),Ce=S.useCallback(async(Q,ze)=>{const ue=await k4(Q,ze);p(Fe=>[ue.schedule,...Fe])},[]),Ke=S.useCallback((Q,ze)=>{i({type:"todo:stdin",todoId:Q,input:ze})},[i]),Ze=S.useCallback(async(Q,ze)=>{const ue=await Uc(Q,{depends_on:ze});l(Fe=>Fe.map(Ve=>Ve.id===Q?ue:Ve))},[]),ye=S.useCallback(async Q=>{const ze=Q.map((ue,Fe)=>({id:ue,priority:Fe}));l(ue=>ue.map(Fe=>{const Ve=ze.find(ft=>ft.id===Fe.id);return Ve?{...Fe,priority:Ve.priority}:Fe})),await Promise.all(ze.map(ue=>Uc(ue.id,{priority:ue.priority})))},[]),Be=S.useCallback(async(Q,ze,ue)=>{await Uc(Q,{position_x:ze,position_y:ue}),l(Fe=>Fe.map(Ve=>Ve.id===Q?{...Ve,position_x:ze,position_y:ue}:Ve))},[]),Z=S.useCallback(async(Q,ze)=>{if(!u)return;const ue=ze.map(Ne=>Ne.message).join(`
|
|
684
684
|
`),Fe=`The previous task "${Q.title}" failed with the following errors:
|
|
@@ -688,7 +688,7 @@ ${ue}
|
|
|
688
688
|
---
|
|
689
689
|
|
|
690
690
|
Please analyze the failure above and fix the issue. The original task description was:
|
|
691
|
-
${Q.description||"(no description)"}`,Ve=`[Fix] ${Q.title}`,ft=await xb(u,{title:Ve.slice(0,200),description:Fe,cli_tool:Q.cli_tool??void 0});l(Ne=>[...Ne,ft]);try{const Ne=await vb(ft.id,"headless");l(at=>at.map(bt=>bt.id===ft.id?Ne:bt))}catch{}},[u]),_e=S.useCallback(async Q=>{if(!u)return;const ze=await g4(u,{title:Q.title,description:Q.description,cron_expression:Q.cronExpression||void 0,cli_tool:Q.cliTool,skip_if_running:Q.skipIfRunning,schedule_type:Q.scheduleType,run_at:Q.runAt});p(ue=>[ze,...ue])},[u]),X=S.useCallback(async(Q,ze)=>{const ue=ze?await y4(Q):await w4(Q);p(Fe=>Fe.map(Ve=>Ve.id===Q?ue:Ve))},[]),me=S.useCallback(async Q=>{await b4(Q),p(ze=>ze.filter(ue=>ue.id!==Q))},[]),se=S.useCallback(async(Q,ze)=>{const ue=await x4(Q,ze);p(Fe=>Fe.map(Ve=>Ve.id===Q?ue:Ve))},[]),ie=S.useCallback(async Q=>{await _4(Q)},[]),J=S.useCallback(async Q=>{if(!u)throw new Error("No project id");const ze=await Z4(u,Q);if(_(ue=>[ze,...ue]),Q.tags){const ue=await qc(u);E(ue)}return ze},[u]),ee=S.useCallback(async(Q,ze)=>{const ue=await eL(Q,ze);_(Fe=>Fe.map(Ve=>Ve.id===Q?ue:Ve))},[]),pe=S.useCallback(async Q=>{await tL(Q),_(ze=>ze.filter(ue=>ue.id!==Q))},[]),we=S.useCallback(async(Q,ze)=>{const ue=await oL(Q,ze);_(Fe=>Fe.map(Ve=>Ve.id===Q?ue.plannerItem:Ve)),l(Fe=>[...Fe,ue.todo])},[]),je=S.useCallback(async(Q,ze)=>{const ue=await lL(Q,ze);_(Fe=>Fe.map(Ve=>Ve.id===Q?ue.plannerItem:Ve)),p(Fe=>[ue.schedule,...Fe])},[]),$e=S.useCallback(async(Q,ze)=>{const ue=await cL(Q,ze);_(Fe=>Fe.map(Ve=>Ve.id===Q?ue.plannerItem:Ve)),x(Fe=>[ue.session,...Fe])},[]),Je=S.useCallback(async(Q,ze)=>{if(!u)return;const ue=await J4(u,Q,ze);if(E(ue),ze.new_name&&ze.new_name!==Q){const Fe=await Wc(u);_(Fe)}},[u]),qe=S.useCallback(async Q=>{if(!u)return;await Q4(u,Q);const[ze,ue]=await Promise.all([qc(u),Wc(u)]);E(ze),_(ue)},[u]),Ee=S.useCallback(async()=>{if(u)try{const{blob:Q,filename:ze}=await uL(u),ue=URL.createObjectURL(Q),Fe=document.createElement("a");Fe.href=ue,Fe.download=ze,document.body.appendChild(Fe),Fe.click(),document.body.removeChild(Fe),URL.revokeObjectURL(ue),y.some(ft=>ft.images)&&ne(q("planner.importNoImages"))}catch(Q){const ze=Q instanceof Error?Q.message:String(Q);ce(`${q("planner.exportError")}: ${ze}`)}},[u,y,q,ne,ce]),st=S.useCallback(async Q=>{if(u)try{const ze=await Q.text();if(!ze.trim())throw new Error(q("planner.importInvalidMarkdown"));const ue=await dL(u,ze),[Fe,Ve]=await Promise.all([qc(u),Wc(u)]);E(Fe),_(Ve),oe(q("planner.importSuccess").replace("{items}",String(ue.imported_items)).replace("{tags}",String(ue.imported_tags)))}catch(ze){const ue=ze instanceof Error?ze.message:String(ze);ce(`${q("planner.importError")}: ${ue}`)}},[u,q,oe,ce]),lt=S.useCallback(Q=>{C(ze=>[Q,...ze])},[]),yt=S.useCallback(async Q=>{await B1(Q),C(ze=>ze.map(ue=>ue.id===Q?{...ue,status:"running",updated_at:new Date().toISOString()}:ue))},[]),mt=S.useCallback(async Q=>{await P1(Q),C(ze=>ze.map(ue=>ue.id===Q?{...ue,status:"paused",updated_at:new Date().toISOString()}:ue))},[]),pt=S.useCallback(async Q=>{await D4(Q),C(ze=>ze.filter(ue=>ue.id!==Q))},[]),dt=S.useCallback(Q=>{x(ze=>[Q,...ze])},[]),kt=S.useCallback(Q=>{x(ze=>ze.map(ue=>ue.id===Q.id?Q:ue))},[]),gt=S.useCallback(async Q=>{await Cu(Q),x(ze=>ze.map(ue=>ue.id===Q?{...ue,status:"stopped",updated_at:new Date().toISOString()}:ue))},[]),vt=S.useCallback(async Q=>{await W4(Q),x(ze=>ze.filter(ue=>ue.id!==Q))},[]),Tt=S.useCallback(async(Q,ze)=>{const ue=await Y4(Q,ze);x(Ve=>Ve.map(ft=>{if(ft.id!==Q)return ft;const Ne={};return ue.worktreeRemoved&&(Ne.worktree_path=null),ze&&ue.branchDeleted&&(Ne.branch_name=null),{...ft,...Ne}}));const Fe=[];ue.worktreeRemoved||Fe.push(`worktree: ${ue.worktreeError||"unknown error"}`),ze&&!ue.branchDeleted&&Fe.push(`branch: ${ue.branchError||"unknown error"}`),Fe.length>0&&ce(q("projects.cleanupPartialFailed").replace("{details}",Fe.join("; ")),7e3)},[q,ce]),Xe=S.useCallback(async()=>{u&&(await GN(u),l(Q=>Q.map(ze=>ze.status==="pending"||ze.status==="failed"||ze.status==="stopped"?{...ze,status:"running",updated_at:new Date().toISOString()}:ze)))},[u]),ut=S.useCallback(async()=>{u&&(await KN(u),l(Q=>Q.map(ze=>ze.status==="running"?{...ze,status:"stopped",updated_at:new Date().toISOString()}:ze)))},[u]);return I?t.jsxs("div",{className:"px-6 py-6 sm:px-8 sm:py-8 space-y-6",children:[t.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center justify-between gap-4",children:[t.jsxs("div",{className:"space-y-2",children:[t.jsx(Nt,{className:"h-8 w-48"}),t.jsx(Nt,{className:"h-4 w-32"})]}),t.jsxs("div",{className:"flex gap-2",children:[t.jsx(Nt,{className:"h-10 w-24"}),t.jsx(Nt,{className:"h-10 w-24"})]})]}),t.jsxs("div",{className:"space-y-2",children:[t.jsxs("div",{className:"flex justify-between",children:[t.jsx(Nt,{className:"h-4 w-16"}),t.jsx(Nt,{className:"h-4 w-12"})]}),t.jsx(Nt,{className:"h-3 w-full rounded-full"})]}),t.jsxs("div",{className:"flex gap-4 border-b border-theme-border pb-px",children:[t.jsx(Nt,{className:"h-10 w-20"}),t.jsx(Nt,{className:"h-10 w-24"}),t.jsx(Nt,{className:"h-10 w-24"})]}),t.jsx("div",{className:"space-y-4",children:[...Array(3)].map((Q,ze)=>t.jsxs("div",{className:"card p-4 space-y-3",children:[t.jsxs("div",{className:"flex justify-between",children:[t.jsx(Nt,{className:"h-5 w-1/3"}),t.jsx(Nt,{className:"h-5 w-20"})]}),t.jsx(Nt,{className:"h-4 w-2/3"}),t.jsxs("div",{className:"flex gap-2",children:[t.jsx(Nt,{className:"h-4 w-16"}),t.jsx(Nt,{className:"h-4 w-16"})]})]},ze))})]}):W||!f?t.jsx("div",{className:"px-6 py-6 sm:px-8 sm:py-8",children:t.jsxs("div",{className:"card p-16 text-center",children:[t.jsx("p",{className:"text-status-error font-medium text-lg",children:q("detail.notFound")}),t.jsx(Un,{to:"/",className:"mt-4 inline-block text-sm text-accent hover:text-accent-dark transition-colors",children:q("detail.backToProjects")})]})}):t.jsx(BO,{projectId:u,sessions:k,sendMessage:i,subscribeBinary:a,onEvent:e,onAddSession:dt,children:t.jsxs("div",{className:"px-6 py-6 sm:px-8 sm:py-8",children:[t.jsx(PL,{project:f,todos:o,sessions:k,onProjectUpdate:Q=>m(Q)}),t.jsx("nav",{role:"tablist","aria-label":q("tabs.projectNavigation"),className:"flex items-center gap-1 mb-5 p-1 rounded-xl overflow-x-auto -mx-4 px-4 sm:mx-0 sm:px-1",style:{backgroundColor:"var(--color-bg-tertiary)"},children:[{key:"files",label:q("tabs.files"),help:q("tabs.files.help")},{key:"planner",label:q("tabs.planner"),help:q("tabs.planner.help"),count:y.length},{key:"sessions",label:q("tabs.sessions"),help:q("tabs.sessions.help"),count:k.length},{key:"automation",label:q("tabs.automation"),help:q("tabs.automation.help"),count:o.length+b.length+d.length},{key:"web",label:q("tabs.web"),help:q("tabs.web.help")},...f.is_git_repo?[{key:"git",label:q("tabs.git"),help:q("tabs.git.help")}]:[],...f.svn_enabled?[{key:"svn",label:q("tabs.svn"),help:q("tabs.svn.help")}]:[]].map(Q=>t.jsx(_m,{title:Q.label,body:Q.help,children:t.jsxs("button",{type:"button",role:"tab","aria-selected":R===Q.key,onClick:()=>F(Q.key),className:`inline-flex items-center px-3 sm:px-4 py-1.5 sm:py-2 text-xs whitespace-nowrap rounded-lg transition-all duration-200 ${R===Q.key?"bg-theme-card text-theme-text font-semibold shadow-soft":"text-theme-text-secondary font-medium hover:bg-theme-hover hover:text-theme-text"}`,children:[Q.label,"count"in Q&&typeof Q.count=="number"&&t.jsx("span",{className:`ml-1.5 min-w-4 rounded-full px-1 py-px text-[9px] leading-3 text-center ${R===Q.key?"bg-theme-bg-tertiary text-theme-text-secondary":"bg-theme-active/70 text-theme-muted"}`,children:Q.count})]})},Q.key))}),R==="automation"&&t.jsx("div",{role:"tablist","aria-label":q("tabs.automation"),className:"flex gap-0.5 mb-4 p-1 rounded-xl w-fit overflow-x-auto",style:{backgroundColor:"var(--color-bg-tertiary)"},children:[{key:"tasks",label:q("tabs.tasks"),help:q("tabs.tasks.help"),count:o.length},{key:"discussions",label:q("tabs.discussions"),help:q("tabs.discussions.help"),count:b.length},{key:"schedules",label:q("tabs.schedules"),help:q("tabs.schedules.help"),count:d.length},{key:"analytics",label:q("tabs.analytics"),help:q("tabs.analytics.help")}].map(Q=>t.jsx(_m,{title:Q.label,body:Q.help,children:t.jsxs("button",{type:"button",role:"tab","aria-selected":B===Q.key,onClick:()=>U(Q.key),className:`px-3 sm:px-4 py-1.5 sm:py-2 text-xs whitespace-nowrap rounded-lg transition-all duration-200 ${B===Q.key?"text-theme-text font-semibold shadow-soft":"text-theme-text-secondary font-medium hover:text-theme-text"}`,style:B===Q.key?{backgroundColor:"var(--color-bg-card)"}:void 0,children:[Q.label,"count"in Q&&typeof Q.count=="number"&&t.jsx("span",{className:`ml-1 ${B===Q.key?"text-theme-text-tertiary":"text-theme-muted"}`,children:Q.count})]})},Q.key))}),R==="automation"&&B==="tasks"&&t.jsx(S8,{todos:o,projectId:u,projectCliTool:f.cli_tool,projectIsGitRepo:!!f.is_git_repo,projectUseWorktree:f.use_worktree!==0,onAddTodo:be,onStartAll:Xe,onStopAll:ut,onStartTodo:De,onStopTodo:Re,onDeleteTodo:ve,onEditTodo:Me,onMergeTodo:Oe,onMergeChain:tt,onCleanupTodo:nt,onRetryTodo:ke,onContinueTodo:fe,onFixTodo:Z,onScheduleTodo:Te,onScheduleOnResetTodo:Ce,resetsAt:h,onUpdateDependency:Ze,onUpdatePosition:Be,onReorderTodos:ye,onEvent:e,onSendInput:Ke,interactiveTodos:P,debugLogging:!!f.debug_logging,showTokenUsage:!!f.show_token_usage}),R==="sessions"&&u&&t.jsx(FO,{projectId:u,sessions:k,projectCliTool:f.cli_tool,isGitRepo:!!f.is_git_repo,projectUseWorktree:f.use_worktree!==0,projectDefaultBranch:f.default_branch,onAddSession:dt,onUpdateSession:kt,onStopSession:gt,onDeleteSession:vt,onCleanupSession:Tt}),R==="automation"&&B==="discussions"&&u&&t.jsx(Dz,{projectId:u,discussions:b,isGitRepo:!!f.is_git_repo,projectUseWorktree:f.use_worktree!==0,onAddDiscussion:lt,onStartDiscussion:yt,onStopDiscussion:mt,onDeleteDiscussion:pt}),R==="automation"&&B==="analytics"&&u&&t.jsx(S.Suspense,{fallback:null,children:t.jsx(mB,{projectId:u})}),R==="git"&&f.is_git_repo?t.jsx(Y8,{project:f,refreshTrigger:$,onEvent:e,sendMessage:i,connected:s},f.id):null,R==="svn"&&f.svn_enabled?t.jsx(gz,{project:f,refreshTrigger:$},f.id):null,R==="files"&&u&&t.jsx(S.Suspense,{fallback:null,children:t.jsx(pB,{projectId:u,onCreateTask:ae,onEvent:e,sendMessage:i,connected:s})}),R==="automation"&&B==="schedules"&&t.jsx(D8,{schedules:d,projectCliTool:f.cli_tool,onAddSchedule:_e,onToggleSchedule:X,onDeleteSchedule:me,onEditSchedule:se,onTriggerSchedule:ie,onMergeRun:Oe,onCleanupRun:nt}),t.jsx("div",{className:R==="web"?"card-static flex flex-col h-[calc(100vh-220px)]":"hidden",children:t.jsx(fB,{})}),R==="planner"&&t.jsx(lB,{plannerItems:y,existingTags:w,projectId:u,projectCliTool:f.cli_tool,onAddItem:J,onEditItem:ee,onDeleteItem:pe,onConvertToTodo:we,onConvertToSchedule:je,onConvertToSession:$e,onUpdateTag:Je,onDeleteTag:qe,onExport:Ee,onImport:st})]})},u)}const xB={pending:"bg-warm-200 text-warm-600",running:"bg-status-success/10 text-status-success",paused:"bg-status-warning/10 text-status-warning",completed:"bg-accent/10 text-accent",failed:"bg-status-error/10 text-status-error",merged:"bg-accent/10 text-accent"};function vB(e){try{const s=JSON.parse(e);return Array.isArray(s)?s:[]}catch{return[]}}function xw(e){return e==="pending"||e==="failed"?{canEdit:!0,allowAdvancedFields:!0}:e==="paused"||e==="completed"?{canEdit:!0,allowAdvancedFields:!1}:{canEdit:!1,allowAdvancedFields:!1}}function bB({onEvent:e,connected:s}){const{id:i,discussionId:a}=Jm(),u=vi(),{t:f,lang:m}=ht(),{sendNotification:o}=up(),[l,d]=S.useState(null),[p,h]=S.useState([]),[g,b]=S.useState(!0),[C,k]=S.useState(new Map),[x,y]=S.useState(""),[_,w]=S.useState(!1),[E,T]=S.useState(!1),[j,D]=S.useState(!1),[N,R]=S.useState(new Set),[A,B]=S.useState(""),[O,F]=S.useState([]),[U,I]=S.useState(!1),[H,W]=S.useState(!1),[K,P]=S.useState([]),[z,$]=S.useState(!1),Y=S.useRef(null),q=S.useCallback(X=>{R(me=>{const se=new Set(me);return se.has(X)?se.delete(X):se.add(X),se})},[]),oe=S.useCallback(()=>{if(!l)return;const X=new Set(l.messages.filter(me=>me.content&&me.status==="completed").map(me=>me.id));R(X)},[l]),ce=S.useCallback(()=>{R(new Set)},[]),ne=X=>{const me=X.split(`
|
|
691
|
+
${Q.description||"(no description)"}`,Ve=`[Fix] ${Q.title}`,ft=await xb(u,{title:Ve.slice(0,200),description:Fe,cli_tool:Q.cli_tool??void 0});l(Ne=>[...Ne,ft]);try{const Ne=await vb(ft.id,"headless");l(at=>at.map(bt=>bt.id===ft.id?Ne:bt))}catch{}},[u]),_e=S.useCallback(async Q=>{if(!u)return;const ze=await g4(u,{title:Q.title,description:Q.description,cron_expression:Q.cronExpression||void 0,cli_tool:Q.cliTool,skip_if_running:Q.skipIfRunning,schedule_type:Q.scheduleType,run_at:Q.runAt});p(ue=>[ze,...ue])},[u]),X=S.useCallback(async(Q,ze)=>{const ue=ze?await y4(Q):await w4(Q);p(Fe=>Fe.map(Ve=>Ve.id===Q?ue:Ve))},[]),me=S.useCallback(async Q=>{await b4(Q),p(ze=>ze.filter(ue=>ue.id!==Q))},[]),se=S.useCallback(async(Q,ze)=>{const ue=await x4(Q,ze);p(Fe=>Fe.map(Ve=>Ve.id===Q?ue:Ve))},[]),ie=S.useCallback(async Q=>{await _4(Q)},[]),J=S.useCallback(async Q=>{if(!u)throw new Error("No project id");const ze=await Z4(u,Q);if(_(ue=>[ze,...ue]),Q.tags){const ue=await qc(u);E(ue)}return ze},[u]),ee=S.useCallback(async(Q,ze)=>{const ue=await eL(Q,ze);_(Fe=>Fe.map(Ve=>Ve.id===Q?ue:Ve))},[]),pe=S.useCallback(async Q=>{await tL(Q),_(ze=>ze.filter(ue=>ue.id!==Q))},[]),we=S.useCallback(async(Q,ze)=>{const ue=await oL(Q,ze);_(Fe=>Fe.map(Ve=>Ve.id===Q?ue.plannerItem:Ve)),l(Fe=>[...Fe,ue.todo])},[]),je=S.useCallback(async(Q,ze)=>{const ue=await lL(Q,ze);_(Fe=>Fe.map(Ve=>Ve.id===Q?ue.plannerItem:Ve)),p(Fe=>[ue.schedule,...Fe])},[]),$e=S.useCallback(async(Q,ze)=>{const ue=await cL(Q,ze);_(Fe=>Fe.map(Ve=>Ve.id===Q?ue.plannerItem:Ve)),x(Fe=>[ue.session,...Fe])},[]),Je=S.useCallback(async(Q,ze)=>{if(!u)return;const ue=await J4(u,Q,ze);if(E(ue),ze.new_name&&ze.new_name!==Q){const Fe=await Wc(u);_(Fe)}},[u]),qe=S.useCallback(async Q=>{if(!u)return;await Q4(u,Q);const[ze,ue]=await Promise.all([qc(u),Wc(u)]);E(ze),_(ue)},[u]),Ee=S.useCallback(async()=>{if(u)try{const{blob:Q,filename:ze}=await uL(u),ue=URL.createObjectURL(Q),Fe=document.createElement("a");Fe.href=ue,Fe.download=ze,document.body.appendChild(Fe),Fe.click(),document.body.removeChild(Fe),URL.revokeObjectURL(ue),y.some(ft=>ft.images)&&ne(q("planner.importNoImages"))}catch(Q){const ze=Q instanceof Error?Q.message:String(Q);ce(`${q("planner.exportError")}: ${ze}`)}},[u,y,q,ne,ce]),st=S.useCallback(async Q=>{if(u)try{const ze=await Q.text();if(!ze.trim())throw new Error(q("planner.importInvalidMarkdown"));const ue=await dL(u,ze),[Fe,Ve]=await Promise.all([qc(u),Wc(u)]);E(Fe),_(Ve),oe(q("planner.importSuccess").replace("{items}",String(ue.imported_items)).replace("{tags}",String(ue.imported_tags)))}catch(ze){const ue=ze instanceof Error?ze.message:String(ze);ce(`${q("planner.importError")}: ${ue}`)}},[u,q,oe,ce]),lt=S.useCallback(Q=>{C(ze=>[Q,...ze])},[]),yt=S.useCallback(async Q=>{await B1(Q),C(ze=>ze.map(ue=>ue.id===Q?{...ue,status:"running",updated_at:new Date().toISOString()}:ue))},[]),mt=S.useCallback(async Q=>{await P1(Q),C(ze=>ze.map(ue=>ue.id===Q?{...ue,status:"paused",updated_at:new Date().toISOString()}:ue))},[]),pt=S.useCallback(async Q=>{await D4(Q),C(ze=>ze.filter(ue=>ue.id!==Q))},[]),dt=S.useCallback(Q=>{x(ze=>[Q,...ze])},[]),kt=S.useCallback(Q=>{x(ze=>ze.map(ue=>ue.id===Q.id?Q:ue))},[]),gt=S.useCallback(async Q=>{await Cu(Q),x(ze=>ze.map(ue=>ue.id===Q?{...ue,status:"stopped",updated_at:new Date().toISOString()}:ue))},[]),vt=S.useCallback(async Q=>{await W4(Q),x(ze=>ze.filter(ue=>ue.id!==Q))},[]),Tt=S.useCallback(async(Q,ze)=>{const ue=await Y4(Q,ze);x(Ve=>Ve.map(ft=>{if(ft.id!==Q)return ft;const Ne={};return ue.worktreeRemoved&&(Ne.worktree_path=null),ze&&ue.branchDeleted&&(Ne.branch_name=null),{...ft,...Ne}}));const Fe=[];ue.worktreeRemoved||Fe.push(`worktree: ${ue.worktreeError||"unknown error"}`),ze&&!ue.branchDeleted&&Fe.push(`branch: ${ue.branchError||"unknown error"}`),Fe.length>0&&ce(q("projects.cleanupPartialFailed").replace("{details}",Fe.join("; ")),7e3)},[q,ce]),Xe=S.useCallback(async()=>{u&&(await GN(u),l(Q=>Q.map(ze=>ze.status==="pending"||ze.status==="failed"||ze.status==="stopped"?{...ze,status:"running",updated_at:new Date().toISOString()}:ze)))},[u]),ut=S.useCallback(async()=>{u&&(await KN(u),l(Q=>Q.map(ze=>ze.status==="running"?{...ze,status:"stopped",updated_at:new Date().toISOString()}:ze)))},[u]);return I?t.jsxs("div",{className:"px-6 py-6 sm:px-8 sm:py-8 space-y-6",children:[t.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center justify-between gap-4",children:[t.jsxs("div",{className:"space-y-2",children:[t.jsx(Nt,{className:"h-8 w-48"}),t.jsx(Nt,{className:"h-4 w-32"})]}),t.jsxs("div",{className:"flex gap-2",children:[t.jsx(Nt,{className:"h-10 w-24"}),t.jsx(Nt,{className:"h-10 w-24"})]})]}),t.jsxs("div",{className:"space-y-2",children:[t.jsxs("div",{className:"flex justify-between",children:[t.jsx(Nt,{className:"h-4 w-16"}),t.jsx(Nt,{className:"h-4 w-12"})]}),t.jsx(Nt,{className:"h-3 w-full rounded-full"})]}),t.jsxs("div",{className:"flex gap-4 border-b border-theme-border pb-px",children:[t.jsx(Nt,{className:"h-10 w-20"}),t.jsx(Nt,{className:"h-10 w-24"}),t.jsx(Nt,{className:"h-10 w-24"})]}),t.jsx("div",{className:"space-y-4",children:[...Array(3)].map((Q,ze)=>t.jsxs("div",{className:"card p-4 space-y-3",children:[t.jsxs("div",{className:"flex justify-between",children:[t.jsx(Nt,{className:"h-5 w-1/3"}),t.jsx(Nt,{className:"h-5 w-20"})]}),t.jsx(Nt,{className:"h-4 w-2/3"}),t.jsxs("div",{className:"flex gap-2",children:[t.jsx(Nt,{className:"h-4 w-16"}),t.jsx(Nt,{className:"h-4 w-16"})]})]},ze))})]}):W||!f?t.jsx("div",{className:"px-6 py-6 sm:px-8 sm:py-8",children:t.jsxs("div",{className:"card p-16 text-center",children:[t.jsx("p",{className:"text-status-error font-medium text-lg",children:q("detail.notFound")}),t.jsx(Un,{to:"/",className:"mt-4 inline-block text-sm text-accent hover:text-accent-dark transition-colors",children:q("detail.backToProjects")})]})}):t.jsx(BO,{projectId:u,sessions:k,sendMessage:i,subscribeBinary:a,onEvent:e,onAddSession:dt,children:t.jsxs("div",{className:"px-6 py-6 sm:px-8 sm:py-8",children:[t.jsx(PL,{project:f,todos:o,sessions:k,onProjectUpdate:Q=>m(Q)}),t.jsx("nav",{role:"tablist","aria-label":q("tabs.projectNavigation"),className:"flex items-center gap-1 mb-5 p-1 rounded-xl overflow-x-auto -mx-4 px-4 sm:mx-0 sm:px-1",style:{backgroundColor:"var(--color-bg-tertiary)"},children:[{key:"web",label:q("tabs.web"),help:q("tabs.web.help")},{key:"files",label:q("tabs.files"),help:q("tabs.files.help")},{key:"planner",label:q("tabs.planner"),help:q("tabs.planner.help"),count:y.length},{key:"sessions",label:q("tabs.sessions"),help:q("tabs.sessions.help"),count:k.length},{key:"automation",label:q("tabs.automation"),help:q("tabs.automation.help"),count:o.length+b.length+d.length},...f.is_git_repo?[{key:"git",label:q("tabs.git"),help:q("tabs.git.help")}]:[],...f.svn_enabled?[{key:"svn",label:q("tabs.svn"),help:q("tabs.svn.help")}]:[]].map(Q=>t.jsx(_m,{title:Q.label,body:Q.help,children:t.jsxs("button",{type:"button",role:"tab","aria-selected":R===Q.key,onClick:()=>F(Q.key),className:`inline-flex items-center px-3 sm:px-4 py-1.5 sm:py-2 text-xs whitespace-nowrap rounded-lg transition-all duration-200 ${R===Q.key?"bg-theme-card text-theme-text font-semibold shadow-soft":"text-theme-text-secondary font-medium hover:bg-theme-hover hover:text-theme-text"}`,children:[Q.label,"count"in Q&&typeof Q.count=="number"&&t.jsx("span",{className:`ml-1.5 min-w-4 rounded-full px-1 py-px text-[9px] leading-3 text-center ${R===Q.key?"bg-theme-bg-tertiary text-theme-text-secondary":"bg-theme-active/70 text-theme-muted"}`,children:Q.count})]})},Q.key))}),R==="automation"&&t.jsx("div",{role:"tablist","aria-label":q("tabs.automation"),className:"flex gap-0.5 mb-4 p-1 rounded-xl w-fit overflow-x-auto",style:{backgroundColor:"var(--color-bg-tertiary)"},children:[{key:"tasks",label:q("tabs.tasks"),help:q("tabs.tasks.help"),count:o.length},{key:"discussions",label:q("tabs.discussions"),help:q("tabs.discussions.help"),count:b.length},{key:"schedules",label:q("tabs.schedules"),help:q("tabs.schedules.help"),count:d.length},{key:"analytics",label:q("tabs.analytics"),help:q("tabs.analytics.help")}].map(Q=>t.jsx(_m,{title:Q.label,body:Q.help,children:t.jsxs("button",{type:"button",role:"tab","aria-selected":B===Q.key,onClick:()=>U(Q.key),className:`px-3 sm:px-4 py-1.5 sm:py-2 text-xs whitespace-nowrap rounded-lg transition-all duration-200 ${B===Q.key?"text-theme-text font-semibold shadow-soft":"text-theme-text-secondary font-medium hover:text-theme-text"}`,style:B===Q.key?{backgroundColor:"var(--color-bg-card)"}:void 0,children:[Q.label,"count"in Q&&typeof Q.count=="number"&&t.jsx("span",{className:`ml-1 ${B===Q.key?"text-theme-text-tertiary":"text-theme-muted"}`,children:Q.count})]})},Q.key))}),R==="automation"&&B==="tasks"&&t.jsx(S8,{todos:o,projectId:u,projectCliTool:f.cli_tool,projectIsGitRepo:!!f.is_git_repo,projectUseWorktree:f.use_worktree!==0,onAddTodo:be,onStartAll:Xe,onStopAll:ut,onStartTodo:De,onStopTodo:Re,onDeleteTodo:ve,onEditTodo:Me,onMergeTodo:Oe,onMergeChain:tt,onCleanupTodo:nt,onRetryTodo:ke,onContinueTodo:fe,onFixTodo:Z,onScheduleTodo:Te,onScheduleOnResetTodo:Ce,resetsAt:h,onUpdateDependency:Ze,onUpdatePosition:Be,onReorderTodos:ye,onEvent:e,onSendInput:Ke,interactiveTodos:P,debugLogging:!!f.debug_logging,showTokenUsage:!!f.show_token_usage}),R==="sessions"&&u&&t.jsx(FO,{projectId:u,sessions:k,projectCliTool:f.cli_tool,isGitRepo:!!f.is_git_repo,projectUseWorktree:f.use_worktree!==0,projectDefaultBranch:f.default_branch,onAddSession:dt,onUpdateSession:kt,onStopSession:gt,onDeleteSession:vt,onCleanupSession:Tt}),R==="automation"&&B==="discussions"&&u&&t.jsx(Dz,{projectId:u,discussions:b,isGitRepo:!!f.is_git_repo,projectUseWorktree:f.use_worktree!==0,onAddDiscussion:lt,onStartDiscussion:yt,onStopDiscussion:mt,onDeleteDiscussion:pt}),R==="automation"&&B==="analytics"&&u&&t.jsx(S.Suspense,{fallback:null,children:t.jsx(mB,{projectId:u})}),R==="git"&&f.is_git_repo?t.jsx(Y8,{project:f,refreshTrigger:$,onEvent:e,sendMessage:i,connected:s},f.id):null,R==="svn"&&f.svn_enabled?t.jsx(gz,{project:f,refreshTrigger:$},f.id):null,R==="files"&&u&&t.jsx(S.Suspense,{fallback:null,children:t.jsx(pB,{projectId:u,onCreateTask:ae,onEvent:e,sendMessage:i,connected:s})}),R==="automation"&&B==="schedules"&&t.jsx(D8,{schedules:d,projectCliTool:f.cli_tool,onAddSchedule:_e,onToggleSchedule:X,onDeleteSchedule:me,onEditSchedule:se,onTriggerSchedule:ie,onMergeRun:Oe,onCleanupRun:nt}),t.jsx("div",{className:R==="web"?"card-static flex flex-col h-[calc(100vh-220px)]":"hidden",children:t.jsx(fB,{})}),R==="planner"&&t.jsx(lB,{plannerItems:y,existingTags:w,projectId:u,projectCliTool:f.cli_tool,onAddItem:J,onEditItem:ee,onDeleteItem:pe,onConvertToTodo:we,onConvertToSchedule:je,onConvertToSession:$e,onUpdateTag:Je,onDeleteTag:qe,onExport:Ee,onImport:st})]})},u)}const xB={pending:"bg-warm-200 text-warm-600",running:"bg-status-success/10 text-status-success",paused:"bg-status-warning/10 text-status-warning",completed:"bg-accent/10 text-accent",failed:"bg-status-error/10 text-status-error",merged:"bg-accent/10 text-accent"};function vB(e){try{const s=JSON.parse(e);return Array.isArray(s)?s:[]}catch{return[]}}function xw(e){return e==="pending"||e==="failed"?{canEdit:!0,allowAdvancedFields:!0}:e==="paused"||e==="completed"?{canEdit:!0,allowAdvancedFields:!1}:{canEdit:!1,allowAdvancedFields:!1}}function bB({onEvent:e,connected:s}){const{id:i,discussionId:a}=Jm(),u=vi(),{t:f,lang:m}=ht(),{sendNotification:o}=up(),[l,d]=S.useState(null),[p,h]=S.useState([]),[g,b]=S.useState(!0),[C,k]=S.useState(new Map),[x,y]=S.useState(""),[_,w]=S.useState(!1),[E,T]=S.useState(!1),[j,D]=S.useState(!1),[N,R]=S.useState(new Set),[A,B]=S.useState(""),[O,F]=S.useState([]),[U,I]=S.useState(!1),[H,W]=S.useState(!1),[K,P]=S.useState([]),[z,$]=S.useState(!1),Y=S.useRef(null),q=S.useCallback(X=>{R(me=>{const se=new Set(me);return se.has(X)?se.delete(X):se.add(X),se})},[]),oe=S.useCallback(()=>{if(!l)return;const X=new Set(l.messages.filter(me=>me.content&&me.status==="completed").map(me=>me.id));R(X)},[l]),ce=S.useCallback(()=>{R(new Set)},[]),ne=X=>{const me=X.split(`
|
|
692
692
|
`).find(se=>se.trim())||"";return me.length>120?`${me.slice(0,120)}...`:me};S.useEffect(()=>{a&&Oi(a).then(d).catch(()=>{}).finally(()=>b(!1))},[a]),S.useEffect(()=>{i&&O1(i).then(h).catch(()=>{})},[i]),S.useEffect(()=>e(X=>{a&&(X.type==="discussion:status-changed"&&X.discussionId===a&&((X.status==="completed"||X.status==="failed")&&o(X.status==="completed"?f("notification.discussionCompleted"):f("notification.discussionFailed"),(l==null?void 0:l.title)??""),d(me=>me&&{...me,status:X.status,current_round:X.currentRound??me.current_round,current_agent_id:X.currentAgentId??me.current_agent_id})),X.type==="discussion:message-changed"&&X.discussionId===a&&(d(me=>me&&{...me,messages:me.messages.map(se=>se.id===X.messageId?{...se,status:X.status}:se)}),(X.status==="completed"||X.status==="failed")&&Oi(a).then(d).catch(()=>{})),X.type==="discussion:log"&&X.discussionId===a&&X.messageId&&k(me=>{const se=new Map(me),ie=X.messageId,J=se.get(ie)||[];return se.set(ie,[...J,X.message||""]),se}))}),[e,a,o,f,l==null?void 0:l.title]),S.useEffect(()=>{var X;(X=Y.current)==null||X.scrollIntoView({behavior:"smooth"})},[l==null?void 0:l.messages,C]),S.useEffect(()=>{!a||!l||(l.status==="failed"?A4(a).then(X=>F(X.filter(me=>me.log_type==="error"))).catch(()=>{}):F([]))},[a,l==null?void 0:l.status]);const te=S.useCallback(async()=>{if(!a)return;const X=await B1(a);d(X),B("")},[a]),G=S.useCallback(async()=>{if(!a)return;await P1(a);const X=await Oi(a);d(X),B("")},[a]),de=S.useCallback(async()=>{if(!a||!x.trim())return;await T4(a,x),y("");const X=await Oi(a);d(X),B("")},[a,x]),he=S.useCallback(async()=>{if(!a)return;const X=await R4(a);d(X),B("")},[a]),be=S.useCallback(async X=>{if(!a)return;w(!1);const me=await M4(a,X);d(me),B("")},[a]),ae=S.useCallback(async()=>{if(!a)return;await z4(a);const X=await Oi(a);d(X),B("")},[a]),De=S.useCallback(async()=>{if(!a)return;await O4(a);const X=await Oi(a);d(X),B("")},[a]),Re=S.useCallback(async()=>{if(a){I(!0),W(!0),P([]);try{const{items:X}=await B4(a);P(X.map(me=>({...me,selected:!0}))),B("")}catch(X){B(X instanceof Error?X.message:m==="ko"?"추출에 실패했습니다.":"Extraction failed."),I(!1)}finally{W(!1)}}},[a,m]),ve=S.useCallback(async()=>{if(!a||!i)return;const X=K.filter(me=>me.selected&&me.title.trim()).map(me=>({title:me.title.trim(),description:me.description,priority:me.priority}));if(X.length===0){B(m==="ko"?"항목을 하나 이상 선택해 주세요.":"Select at least one item.");return}$(!0);try{await P4(a,X),I(!1),P([]),u(`/projects/${i}?tab=planner`)}catch(me){B(me instanceof Error?me.message:m==="ko"?"Planner 변환에 실패했습니다.":"Failed to create planner items.")}finally{$(!1)}},[a,i,K,m,u]),Me=S.useCallback(async X=>{if(!(!a||!l)){D(!0);try{const{allowAdvancedFields:me}=xw(l.status),se=me?{title:X.title,description:X.description,agent_ids:X.agent_ids,max_rounds:X.max_rounds,auto_implement:X.auto_implement,implement_agent_id:X.auto_implement?X.implement_agent_id:null}:{title:X.title,description:X.description};await L4(a,se);const ie=await Oi(a);d(ie),T(!1),B("")}catch(me){B(me instanceof Error?me.message:m==="ko"?"토론 저장에 실패했습니다.":"Failed to save discussion.")}finally{D(!1)}}},[a,l,m]);if(g)return t.jsxs("div",{className:"mx-auto max-w-4xl px-4 sm:px-6 py-6 sm:py-8 space-y-6",children:[t.jsxs("div",{className:"flex items-center gap-3",children:[t.jsx(Nt,{className:"h-4 w-16"}),t.jsx(Nt,{className:"h-4 w-4"}),t.jsx(Nt,{className:"h-4 w-32"})]}),t.jsxs("div",{className:"card p-6 space-y-4",children:[t.jsx(Nt,{className:"h-7 w-1/3"}),t.jsx(Nt,{className:"h-4 w-full",count:2}),t.jsxs("div",{className:"flex gap-4 pt-2",children:[t.jsx(Nt,{className:"h-3 w-24"}),t.jsx(Nt,{className:"h-3 w-24"})]})]}),t.jsx("div",{className:"space-y-8",children:[...Array(3)].map((X,me)=>t.jsxs("div",{className:"flex gap-3",children:[t.jsx(Nt,{variant:"circular",width:32,height:32}),t.jsxs("div",{className:"flex-1 space-y-2",children:[t.jsx(Nt,{className:"h-4 w-24"}),t.jsxs("div",{className:"card p-4 space-y-2",children:[t.jsx(Nt,{className:"h-3 w-full"}),t.jsx(Nt,{className:"h-3 w-5/6"}),t.jsx(Nt,{className:"h-3 w-4/6"})]})]})]},me))})]});if(!l)return t.jsxs("div",{className:"mx-auto max-w-4xl px-4 py-8 text-center",children:[t.jsx("p",{className:"text-status-error",children:f("discussions.notFound")}),t.jsx(Un,{to:`/projects/${i}?tab=discussions`,className:"text-sm text-accent mt-2 inline-block",children:f("discussions.back")})]});const Oe=new Map(l.agents.map(X=>[X.id,X])),tt=l.status==="pending"||l.status==="paused"||l.status==="failed",nt=l.status==="running",ke=l.status==="completed"||l.status==="paused",fe=l.status==="completed",Te=l.status==="paused"||l.status==="running",Ce=!nt&&!!l.branch_name,{canEdit:Ke,allowAdvancedFields:Ze}=xw(l.status),ye=X=>{if(!X)return[];try{const me=JSON.parse(X);return Array.isArray(me)?me.filter(se=>typeof se=="string"):[]}catch{return[]}},Be={title:l.title,description:l.description,agent_ids:vB(l.agent_ids),max_rounds:l.max_rounds,auto_implement:l.auto_implement===1,implement_agent_id:l.implement_agent_id||"",memory_inject_mode:l.memory_inject_mode||"none",memory_node_ids:ye(l.memory_node_ids),memory_raw_file_paths:ye(l.memory_raw_file_paths),use_worktree:l.use_worktree==null?!0:l.use_worktree===1},Z=new Map;for(const X of l.messages){const me=Z.get(X.round_number)||[];me.push(X),Z.set(X.round_number,me)}const _e=[...Z.keys()].sort((X,me)=>X-me);return t.jsxs("div",{className:"mx-auto max-w-4xl px-4 sm:px-6 py-6 sm:py-8 flex flex-col",style:{height:"calc(100vh - 2rem)"},children:[t.jsxs("div",{className:"flex items-center gap-3 mb-4",children:[t.jsxs(Un,{to:`/projects/${i}?tab=discussions`,className:"inline-flex items-center gap-1 text-sm text-warm-500 hover:text-accent transition-colors",children:[t.jsx(sp,{size:16}),f("discussions.back")]}),t.jsx("span",{className:"text-warm-300",children:"/"}),t.jsx("span",{className:"text-sm font-medium text-warm-700 truncate",children:l.title}),t.jsx("span",{className:`px-1.5 py-0.5 rounded-md text-2xs font-semibold uppercase ${xB[l.status]}`,children:f(`status.${l.status}`)||l.status}),l.status==="running"&&t.jsxs("span",{className:"text-2xs text-status-success animate-pulse",children:[f("discussions.round")," ",l.current_round,"/",l.max_rounds]}),s&&t.jsx("span",{className:"ml-auto inline-flex items-center gap-1 text-xs text-status-success",children:t.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-status-success animate-pulse"})})]}),t.jsxs("div",{className:"mb-4 rounded-xl border border-warm-150 bg-warm-50/80 p-4",children:[t.jsxs("div",{className:"flex items-start justify-between gap-3",children:[t.jsxs("div",{className:"min-w-0",children:[t.jsx("h1",{className:"text-lg font-semibold text-warm-800",children:l.title}),t.jsx("p",{className:"mt-2 whitespace-pre-wrap text-sm leading-relaxed text-warm-500",children:l.description})]}),Ke&&t.jsx("button",{onClick:()=>T(!0),className:"btn-secondary text-xs py-2 flex-shrink-0",children:f("todo.edit")})]}),t.jsxs("div",{className:"mt-3 flex flex-wrap gap-3 text-[11px] text-warm-400",children:[t.jsxs("span",{children:[f("discussions.maxRounds"),": ",l.max_rounds]}),t.jsxs("span",{children:[f("discussions.agents"),": ",l.agents.map(X=>X.name).join(", ")||"-"]}),t.jsxs("span",{children:[f("discussions.autoImplement"),": ",l.auto_implement?m==="ko"?"사용":"Enabled":m==="ko"?"사용 안 함":"Disabled"]})]}),A&&t.jsx("p",{className:"mt-3 text-xs text-status-error",children:A})]}),l.status==="failed"&&(()=>{const X=l.messages.find(se=>se.status==="failed"),me=X?Oe.get(X.agent_id):null;return t.jsxs("div",{className:"mb-4 rounded-xl border border-status-error/30 bg-status-error/5 overflow-hidden",children:[t.jsxs("div",{className:"flex items-center justify-between px-4 py-2.5 bg-status-error/10 border-b border-status-error/20",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(Uu,{size:16,className:"text-status-error"}),t.jsx("h4",{className:"text-xs font-semibold text-status-error uppercase tracking-wider",children:f("discussions.failureTitle")}),me&&t.jsxs("span",{className:"inline-flex items-center gap-1 text-2xs font-mono px-1.5 py-0.5 rounded-md bg-status-error/15 text-status-error",children:[t.jsx("span",{className:"w-3 h-3 rounded-full inline-block",style:{backgroundColor:me.avatar_color||"#94a3b8"}}),me.name]}),X&&t.jsxs("span",{className:"text-2xs font-mono px-1.5 py-0.5 rounded-md bg-status-error/15 text-status-error",children:[f("discussions.round")," ",X.round_number]})]}),t.jsxs("button",{onClick:te,className:"inline-flex items-center gap-1.5 px-3 py-1.5 rounded-lg text-xs font-medium bg-status-success/15 text-status-success hover:bg-status-success/25 border border-status-success/30 transition-colors",children:[t.jsx(pi,{size:14}),f("discussions.retry")]})]}),t.jsx("div",{className:"px-4 py-3 space-y-1.5 max-h-48 overflow-y-auto",children:O.length>0?O.map(se=>t.jsxs("div",{className:"flex items-start gap-2 text-xs",children:[t.jsx("span",{className:"text-warm-500 font-mono flex-shrink-0",children:new Date(se.created_at).toLocaleTimeString()}),t.jsx("span",{className:"text-status-error font-mono whitespace-pre-wrap break-all",children:se.message})]},se.id)):t.jsx("span",{className:"text-xs text-warm-400 italic",children:f("discussions.noErrorLogs")})})]})})(),t.jsxs("div",{className:"flex items-center gap-2 mb-4 flex-wrap",children:[tt&&t.jsxs("button",{onClick:te,className:"btn-primary text-sm",children:[t.jsx(Tr,{size:16}),l.status==="pending"?f("header.runAll"):f("discussions.resume")]}),nt&&t.jsxs("button",{onClick:G,className:"btn-danger text-sm",children:[t.jsx(op,{size:16}),f("discussions.pause")]}),nt&&t.jsx("button",{onClick:he,className:"btn btn-sm text-xs text-warm-500",children:f("discussions.skipTurn")}),ke&&t.jsxs("button",{onClick:()=>w(!0),className:"btn-primary text-sm",children:[t.jsx(G5,{size:16}),f("discussions.implement")]}),fe&&l.branch_name&&t.jsxs("button",{onClick:ae,className:"btn-primary text-sm",children:[t.jsx(yu,{size:16}),f("todos.merge")]}),l.status==="completed"&&t.jsxs("button",{onClick:Re,className:"btn-primary text-sm",children:[t.jsx(t1,{size:16}),f("discussions.toPlanner")]}),Ce&&t.jsxs("button",{onClick:De,className:"btn-danger text-sm",children:[t.jsx(An,{size:16}),f("todo.cleanup")]}),l.messages.some(X=>X.content&&X.status==="completed")&&t.jsx("button",{onClick:N.size>0?ce:oe,className:"btn btn-sm text-xs text-warm-500",children:N.size>0?f("discussions.expandAll"):f("discussions.collapseAll")}),t.jsx("div",{className:"ml-auto flex items-center gap-1",children:l.agents.map(X=>t.jsx("div",{className:`w-7 h-7 rounded-full flex items-center justify-center text-white text-2xs font-bold transition-all ${l.current_agent_id===X.id?"ring-2 ring-status-success ring-offset-1 scale-110":"opacity-60"}`,style:{backgroundColor:X.avatar_color||"#6366f1"},title:`${X.name} (${X.role})`,children:X.name.charAt(0)},X.id))})]}),t.jsxs("div",{className:"flex-1 overflow-y-auto space-y-1 pb-4",children:[_e.map(X=>{const me=Z.get(X),se=X>l.max_rounds;return t.jsxs("div",{children:[t.jsxs("div",{className:"flex items-center gap-3 my-4",children:[t.jsx("div",{className:"flex-1 h-px bg-warm-200"}),t.jsx("span",{className:"text-2xs font-semibold text-warm-400 uppercase tracking-wider",children:se?f("discussions.implementation"):`${f("discussions.round")} ${X}`}),t.jsx("div",{className:"flex-1 h-px bg-warm-200"})]}),me.map(ie=>{const J=Oe.get(ie.agent_id),ee=ie.agent_id==="user",pe=ie.status==="running",we=C.get(ie.id)||[],je=N.has(ie.id),$e=!!ie.content&&ie.status==="completed"&&!ee;return t.jsxs("div",{className:`flex gap-3 py-3 ${ee?"justify-end":""}`,children:[!ee&&t.jsx("div",{className:`w-8 h-8 rounded-full flex items-center justify-center text-white text-xs font-bold flex-shrink-0 ${pe?"ring-2 ring-status-success ring-offset-1 animate-pulse":""}`,style:{backgroundColor:(J==null?void 0:J.avatar_color)||"#94a3b8"},children:ie.agent_name.charAt(0)}),t.jsxs("div",{className:`flex-1 min-w-0 ${ee?"max-w-[80%]":""}`,children:[!ee&&t.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[t.jsx("span",{className:"text-xs font-semibold text-warm-700",children:ie.agent_name}),t.jsx("span",{className:"text-2xs text-warm-400",children:f(`agents.roles.${ie.role}`)||ie.role}),ie.status==="skipped"&&t.jsx("span",{className:"text-2xs text-warm-300 italic",children:f("status.skipped")}),$e&&t.jsxs("button",{onClick:()=>q(ie.id),className:"text-2xs text-warm-300 hover:text-accent transition-colors flex items-center gap-0.5",children:[t.jsx(Es,{size:12,className:`transition-transform ${je?"":"rotate-90"}`}),f(je?"discussions.expand":"discussions.collapse")]})]}),t.jsxs("div",{className:`rounded-xl p-3 text-sm ${ee?"bg-accent/10 text-warm-700 ml-auto":ie.status==="failed"?"bg-status-error/5 border border-status-error/20":"bg-warm-50 border border-warm-150"} ${$e?"cursor-pointer":""}`,onClick:$e?()=>{const Je=window.getSelection();Je&&Je.toString().length>0||q(ie.id)}:void 0,children:[je&&ie.content&&t.jsx("div",{className:"text-xs text-warm-400 italic truncate",children:ne(ie.content)}),!je&&ie.content&&t.jsx(X_,{content:ie.content}),pe&&we.length>0&&t.jsx("div",{className:"text-xs text-warm-500 whitespace-pre-wrap leading-relaxed max-h-60 overflow-y-auto font-mono",children:we.slice(-50).join(`
|
|
693
693
|
`)}),pe&&we.length===0&&t.jsxs("div",{className:"flex items-center gap-2 text-xs text-status-success",children:[t.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-status-success animate-pulse"}),f("discussions.speaking")]}),ie.status==="pending"&&!ie.content&&t.jsx("div",{className:"text-xs text-warm-300 italic",children:f("discussions.waiting")})]})]}),ee&&t.jsx("div",{className:"w-8 h-8 rounded-full bg-warm-300 flex items-center justify-center text-white text-xs font-bold flex-shrink-0",children:"U"})]},ie.id)})]},X)}),t.jsx("div",{ref:Y})]}),Te&&t.jsxs("div",{className:"border-t border-warm-200 pt-3 flex gap-2",children:[t.jsx("input",{type:"text",value:x,onChange:X=>y(X.target.value),onKeyDown:X=>{X.key==="Enter"&&!X.shiftKey&&(X.preventDefault(),de())},placeholder:f("discussions.userMessage"),className:"input flex-1 text-sm"}),t.jsx("button",{onClick:de,disabled:!x.trim(),className:"btn btn-primary btn-sm text-xs",children:f("discussions.inject")})]}),E&&t.jsx(jn,{open:!0,onClose:()=>T(!1),size:"xl",children:t.jsx("div",{className:"max-h-[90vh] overflow-y-auto",children:t.jsx(uS,{agents:Ze?p:l.agents,projectId:l.project_id,initialValues:Be,mode:"edit",allowAdvancedFields:Ze,submitting:j,onSubmit:Me,onCancel:()=>T(!1)})})}),_&&t.jsx(jn,{open:!0,onClose:()=>w(!1),size:"sm",children:t.jsxs("div",{className:"bg-theme-card border border-theme-border rounded-2xl p-6 shadow-elevated space-y-4",children:[t.jsx("h3",{className:"text-sm font-semibold text-warm-700",children:f("discussions.selectAgent")}),t.jsx("p",{className:"text-xs text-warm-400",children:f("discussions.implementHint")}),t.jsx("div",{className:"space-y-2",children:l.agents.map(X=>t.jsxs("button",{onClick:()=>be(X.id),className:"w-full flex items-center gap-3 p-3 rounded-lg border border-warm-200 hover:border-accent hover:bg-accent/5 transition-colors",children:[t.jsx("div",{className:"w-8 h-8 rounded-full flex items-center justify-center text-white text-xs font-bold",style:{backgroundColor:X.avatar_color||"#6366f1"},children:X.name.charAt(0)}),t.jsxs("div",{className:"text-left",children:[t.jsx("div",{className:"text-sm font-medium text-warm-700",children:X.name}),t.jsx("div",{className:"text-xs text-warm-400",children:f(`agents.roles.${X.role}`)||X.role})]})]},X.id))}),t.jsx("button",{onClick:()=>w(!1),className:"btn btn-sm text-xs text-warm-500 w-full",children:f("header.cancel")})]})}),U&&t.jsx(jn,{open:!0,onClose:()=>!z&&!H&&I(!1),size:"lg",children:t.jsxs("div",{className:"bg-theme-card border border-theme-border rounded-2xl p-6 shadow-elevated space-y-4 max-h-[85vh] flex flex-col",children:[t.jsxs("div",{children:[t.jsx("h3",{className:"text-sm font-semibold text-warm-700",children:f("discussions.extractTitle")}),t.jsx("p",{className:"text-xs text-warm-400 mt-1",children:f("discussions.extractHint")})]}),H?t.jsxs("div",{className:"py-12 flex flex-col items-center justify-center gap-3 text-sm text-warm-400",children:[t.jsx(hi,{size:32,className:"animate-spin text-accent"}),t.jsx("span",{children:f("discussions.extractLoading")}),t.jsx("span",{className:"text-xs text-warm-300",children:f("discussions.extractLoadingHint")})]}):K.length===0?t.jsx("div",{className:"py-12 text-center text-sm text-warm-400",children:f("discussions.extractEmpty")}):t.jsx("div",{className:"space-y-2 overflow-y-auto pr-1",children:K.map((X,me)=>t.jsxs("div",{className:"flex items-start gap-2 p-3 rounded-lg border border-warm-200",children:[t.jsx("input",{type:"checkbox",checked:X.selected,onChange:se=>P(ie=>ie.map((J,ee)=>ee===me?{...J,selected:se.target.checked}:J)),className:"mt-1.5 cursor-pointer"}),t.jsxs("div",{className:"flex-1 space-y-1.5",children:[t.jsx("input",{type:"text",value:X.title,onChange:se=>P(ie=>ie.map((J,ee)=>ee===me?{...J,title:se.target.value}:J)),className:"w-full text-sm font-medium bg-transparent border-b border-warm-200 focus:border-accent outline-none py-1",placeholder:f("plannerForm.titlePlaceholder")}),t.jsx("textarea",{value:X.description,onChange:se=>P(ie=>ie.map((J,ee)=>ee===me?{...J,description:se.target.value}:J)),rows:2,className:"w-full text-xs text-warm-500 bg-transparent border border-warm-200 rounded-md p-1.5 focus:border-accent outline-none min-h-[48px] max-h-[240px] resize-y [field-sizing:content]",placeholder:f("plannerForm.descPlaceholder")}),t.jsxs("select",{value:X.priority,onChange:se=>P(ie=>ie.map((J,ee)=>ee===me?{...J,priority:Number(se.target.value)}:J)),className:"text-xs bg-transparent border border-warm-200 rounded-md px-2 py-1",children:[t.jsx("option",{value:0,children:f("discussions.priorityLow")}),t.jsx("option",{value:1,children:f("discussions.priorityMedium")}),t.jsx("option",{value:2,children:f("discussions.priorityHigh")}),t.jsx("option",{value:3,children:f("discussions.priorityUrgent")})]})]})]},me))}),t.jsxs("div",{className:"flex items-center justify-end gap-2 pt-2 border-t border-warm-200",children:[t.jsx("button",{onClick:()=>I(!1),disabled:z||H,className:"btn btn-sm text-xs text-warm-500 disabled:opacity-50 disabled:cursor-not-allowed",children:f("header.cancel")}),t.jsx("button",{onClick:ve,disabled:z||H||K.filter(X=>X.selected).length===0,className:"btn-primary text-sm",children:f(z?"discussions.extractSaving":"discussions.extractConfirm")})]})]})})]})}const yB={low:{dot:"bg-status-success",label:"review.risk.low"},medium:{dot:"bg-status-warning",label:"review.risk.medium"},high:{dot:"bg-status-error",label:"review.risk.high"}};function wB(e){return e?e<.01?"<$0.01":`$${e.toFixed(2)}`:"$0.00"}function _B(e,s){const i=Date.now()-new Date(e).getTime();if(i<0)return s("review.justNow");const a=Math.floor(i/6e4);if(a<1)return s("review.justNow");if(a<60)return`${a}${s("review.minAgo")}`;const u=Math.floor(a/60);return u<24?`${u}${s("review.hourAgo")}`:`${Math.floor(u/24)}${s("review.dayAgo")}`}function SB({status:e}){return e==="completed"?t.jsx(Zw,{size:14,className:"text-status-success"}):e==="failed"?t.jsx(e1,{size:14,className:"text-status-error"}):e==="stopped"?t.jsx(P5,{size:14,className:"text-status-warning"}):t.jsx(Uu,{size:14,className:"text-status-warning"})}function kB(e){switch(e){case"todo-not-found":return"review.diff.notFound";case"no-branch":return"review.diff.noBranch";case"branch-missing":return"review.diff.branchMissing";case"base-branch-missing":return"review.diff.baseBranchMissing"}}function CB({item:e,focused:s,expanded:i,onFocus:a,onToggleExpand:u,onOpen:f,onApprove:m,onContinue:o,onDiscard:l,busy:d}){const{t:p}=ht(),[h,g]=S.useState(!1),[b,C]=S.useState(""),k=yB[e.risk],[x,y]=S.useState(null),[_,w]=S.useState(!1),[E,T]=S.useState(null),[j,D]=S.useState(""),[N,R]=S.useState(!1),A=e.status==="completed"&&!!e.branch_name&&!!e.worktree_path,B=e.status==="completed"&&!!e.worktree_path;S.useEffect(()=>{if(!i||x!==null)return;let U=!1;return w(!0),p3(e.id).then(I=>{U||(y(I),I.available&&I.files.length>0&&T(I.files[0].path))}).catch(()=>{U||y({available:!1,reason:"branch-missing"})}).finally(()=>{U||w(!1)}),()=>{U=!0}},[i,x,e.id]),S.useEffect(()=>{if(!i||!E)return;let U=!1;return R(!0),D(""),g3(e.id,E).then(I=>{U||D(I.available?I.diff:"")}).catch(()=>{U||D("")}).finally(()=>{U||R(!1)}),()=>{U=!0}},[i,E,e.id]);const O=S.useCallback(()=>{a(),u()},[a,u]),F=x!=null&&x.available?x.files.map(U=>({path:U.path,status:U.status,additions:U.insertions,deletions:U.deletions})):[];return t.jsxs("div",{onClick:O,className:`card p-4 cursor-pointer transition-all ${s?"ring-2":""}`,style:{borderColor:s?"var(--color-accent)":void 0,boxShadow:s?"var(--shadow-soft)":void 0},children:[t.jsxs("div",{className:"flex items-start gap-3",children:[t.jsx("span",{className:`mt-1.5 w-2 h-2 rounded-full flex-shrink-0 ${k.dot}`,title:p(k.label)}),t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsxs("div",{className:"flex items-center gap-2 text-2xs tracking-wide mb-0.5",style:{color:"var(--color-text-muted)"},children:[t.jsx(r1,{size:12}),t.jsx("span",{className:"truncate",children:e.project_name}),e.branch_name&&t.jsxs(t.Fragment,{children:[t.jsx("span",{children:"·"}),t.jsx(Vi,{size:12}),t.jsx("span",{className:"truncate font-mono",children:e.branch_name})]})]}),t.jsxs("h3",{className:"font-medium truncate flex items-center gap-1.5",style:{color:"var(--color-text-primary)"},children:[i?t.jsx(Ja,{size:14,className:"flex-shrink-0 opacity-60"}):t.jsx(Es,{size:14,className:"flex-shrink-0 opacity-60"}),t.jsx("span",{className:"truncate",children:e.title})]})]}),t.jsxs("div",{className:"flex-shrink-0 flex items-center gap-1.5 text-xs",style:{color:"var(--color-text-tertiary)"},children:[t.jsx(SB,{status:e.status}),t.jsx("span",{children:_B(e.updated_at,p)})]})]}),e.summary&&t.jsx("p",{className:"mt-2 text-sm line-clamp-2",style:{color:"var(--color-text-secondary)"},children:e.summary}),t.jsxs("div",{className:"mt-3 flex flex-wrap items-center gap-x-4 gap-y-1 text-xs",style:{color:"var(--color-text-tertiary)"},children:[t.jsx("span",{children:e.cli_tool||"claude"}),t.jsx("span",{children:"·"}),t.jsx("span",{children:wB(e.total_cost_usd)}),(e.diff_files||0)>0&&t.jsxs(t.Fragment,{children:[t.jsx("span",{children:"·"}),t.jsxs("span",{children:[e.diff_files," ",p("review.files"),", +",Math.max(0,e.diff_lines??0)," ",p("review.lines")]})]}),e.round_count&&e.round_count>1&&t.jsxs(t.Fragment,{children:[t.jsx("span",{children:"·"}),t.jsxs("span",{children:[p("review.rounds")," ",e.round_count]})]})]}),t.jsxs("div",{className:"mt-3 flex flex-wrap items-center gap-2",children:[t.jsx("button",{onClick:U=>{U.stopPropagation(),f()},className:"btn-ghost text-xs px-3 py-1.5",children:p("review.viewDetails")}),A&&t.jsx("button",{onClick:U=>{U.stopPropagation(),m()},disabled:d,className:"btn-primary text-xs px-3 py-1.5 disabled:opacity-50",children:d?t.jsx(hi,{size:12,className:"animate-spin"}):p("review.approve")}),B&&t.jsx("button",{onClick:U=>{U.stopPropagation(),g(I=>!I)},className:"btn-ghost text-xs px-3 py-1.5",children:p("review.requestChanges")}),t.jsx("button",{onClick:U=>{U.stopPropagation(),l()},disabled:d,className:"btn-ghost text-xs px-3 py-1.5 ml-auto text-status-error hover:text-status-error",children:p("review.discard")})]}),h&&B&&t.jsxs("div",{className:"mt-3 space-y-2",onClick:U=>U.stopPropagation(),children:[t.jsx("textarea",{value:b,onChange:U=>C(U.target.value),placeholder:p("review.continuePlaceholder"),rows:3,className:"w-full text-sm rounded-lg p-2 resize-y",style:{backgroundColor:"var(--color-bg-secondary)",color:"var(--color-text-primary)",border:"1px solid var(--color-border)"}}),t.jsxs("div",{className:"flex gap-2 justify-end",children:[t.jsx("button",{onClick:()=>{g(!1),C("")},className:"btn-ghost text-xs px-3 py-1.5",children:p("review.cancel")}),t.jsx("button",{onClick:async()=>{const U=b.trim();U&&(await o(U),C(""),g(!1))},disabled:d||!b.trim(),className:"btn-primary text-xs px-3 py-1.5 disabled:opacity-50",children:d?t.jsx(hi,{size:12,className:"animate-spin"}):p("review.send")})]})]}),i&&t.jsx("div",{className:"mt-3 rounded-lg overflow-hidden",style:{border:"1px solid var(--color-border)",backgroundColor:"var(--color-bg-primary)"},onClick:U=>U.stopPropagation(),children:!x||_?t.jsx("div",{className:"h-24 flex items-center justify-center",children:t.jsx(hi,{size:16,className:"animate-spin",style:{color:"var(--color-text-muted)"}})}):x.available?x.files.length===0?t.jsx("div",{className:"px-4 py-6 text-center text-sm",style:{color:"var(--color-text-muted)"},children:p("review.diff.empty")}):t.jsxs("div",{className:"flex",style:{height:384},children:[t.jsx("div",{className:"w-56 shrink-0 border-r overflow-hidden",style:{borderColor:"var(--color-border)"},children:t.jsx(Ju,{files:F,loading:!1,selectedFile:E,onFileClick:U=>T(U)})}),t.jsx("div",{className:"flex-1 min-w-0 overflow-hidden bg-warm-900",children:t.jsx(eo,{diff:j,loading:N,selectedFile:E})})]}):t.jsxs("div",{className:"px-4 py-6 space-y-2 text-sm",style:{color:"var(--color-text-muted)"},children:[t.jsx("div",{className:"text-center",children:p(kB(x.reason))}),x.debug&&t.jsx("pre",{className:"text-xs font-mono whitespace-pre-wrap break-all p-2 rounded-md",style:{backgroundColor:"var(--color-bg-secondary)",color:"var(--color-text-tertiary)"},children:`worktree_path: ${x.debug.worktree_path??"(null)"}
|
|
694
694
|
worktree_exists: ${x.debug.worktree_exists}
|