clitrigger 0.2.68 → 0.2.69

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (22) hide show
  1. package/dist/client/assets/{AnalyticsPanel-Df6PTxhA.js → AnalyticsPanel-Dr9Zypd4.js} +1 -1
  2. package/dist/client/assets/{CalendarGrid-Bsrf2InF.js → CalendarGrid-BRVf7WJK.js} +1 -1
  3. package/dist/client/assets/{DiscussionDetail-CpPbB3D-.js → DiscussionDetail-DetjETsr.js} +1 -1
  4. package/dist/client/assets/{DiscussionForm-DASNXVl-.js → DiscussionForm-Bi4L47Ly.js} +1 -1
  5. package/dist/client/assets/{EmptyState-BauJBCrW.js → EmptyState--9RqKIk6.js} +1 -1
  6. package/dist/client/assets/{FloatingComposerController-5A3GJtK4-K4SWepH8.js → FloatingComposerController-5A3GJtK4-85zrcVy6.js} +1 -1
  7. package/dist/client/assets/{LogViewer-zauAgB6I.js → LogViewer-BDuckIDB.js} +1 -1
  8. package/dist/client/assets/{MarkdownContent-B3oEjGwC.js → MarkdownContent-CwGbW814.js} +1 -1
  9. package/dist/client/assets/{PersonalAgenda-C8P8R7BW.js → PersonalAgenda-JNpWPEDQ.js} +1 -1
  10. package/dist/client/assets/{PlannerPageEditor-DPXI3Zfq.js → PlannerPageEditor-9_jJ-l98.js} +3 -3
  11. package/dist/client/assets/{ProjectDetail-eFpOIAWj.js → ProjectDetail-DwN6S3uf.js} +4 -4
  12. package/dist/client/assets/{ProjectList-BJo-FMR3.js → ProjectList-LeZ7mrEM.js} +1 -1
  13. package/dist/client/assets/{ReviewQueue-Bc7VQ6Gf.js → ReviewQueue-DzTHqZdO.js} +1 -1
  14. package/dist/client/assets/{TaskGraph-B97ITa4c.js → TaskGraph-BrHxqYJn.js} +1 -1
  15. package/dist/client/assets/{VaultLayout-CUbPgHod.js → VaultLayout-DftlF-Gd.js} +1 -1
  16. package/dist/client/assets/{folder-git-2-BqhO_WrT.js → folder-git-2-DocDG5LN.js} +1 -1
  17. package/dist/client/assets/{index-DxjV2Q9W.js → index--CryAcdA.js} +3 -3
  18. package/dist/client/assets/{rotate-ccw-aXuj01G0.js → rotate-ccw-CY6Wl56G.js} +1 -1
  19. package/dist/client/assets/{style-9nX9ra-f.js → style-D7Mv0Jex.js} +1 -1
  20. package/dist/client/assets/{with-selector-vbW186xh.js → with-selector-bSOP5zTp.js} +1 -1
  21. package/dist/client/index.html +1 -1
  22. package/package.json +1 -1
@@ -1,4 +1,4 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/ProjectList-BJo-FMR3.js","assets/EmptyState-BauJBCrW.js","assets/ProjectDetail-eFpOIAWj.js","assets/CalendarGrid-Bsrf2InF.js","assets/LogViewer-zauAgB6I.js","assets/MarkdownContent-B3oEjGwC.js","assets/DiscussionForm-DASNXVl-.js","assets/rotate-ccw-aXuj01G0.js","assets/DiscussionDetail-CpPbB3D-.js","assets/ReviewQueue-Bc7VQ6Gf.js","assets/folder-git-2-BqhO_WrT.js","assets/PersonalAgenda-C8P8R7BW.js"])))=>i.map(i=>d[i]);
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/ProjectList-LeZ7mrEM.js","assets/EmptyState--9RqKIk6.js","assets/ProjectDetail-DwN6S3uf.js","assets/CalendarGrid-BRVf7WJK.js","assets/LogViewer-BDuckIDB.js","assets/MarkdownContent-CwGbW814.js","assets/DiscussionForm-Bi4L47Ly.js","assets/rotate-ccw-CY6Wl56G.js","assets/DiscussionDetail-DetjETsr.js","assets/ReviewQueue-DzTHqZdO.js","assets/folder-git-2-DocDG5LN.js","assets/PersonalAgenda-JNpWPEDQ.js"])))=>i.map(i=>d[i]);
2
2
  var Hb=Object.defineProperty;var Pb=(s,h,w)=>h in s?Hb(s,h,{enumerable:!0,configurable:!0,writable:!0,value:w}):s[h]=w;var jm=(s,h,w)=>Pb(s,typeof h!="symbol"?h+"":h,w);function Ib(s,h){for(var w=0;w<h.length;w++){const S=h[w];if(typeof S!="string"&&!Array.isArray(S)){for(const M in S)if(M!=="default"&&!(M in s)){const O=Object.getOwnPropertyDescriptor(S,M);O&&Object.defineProperty(s,M,O.get?O:{enumerable:!0,get:()=>S[M]})}}}return Object.freeze(Object.defineProperty(s,Symbol.toStringTag,{value:"Module"}))}(function(){const h=document.createElement("link").relList;if(h&&h.supports&&h.supports("modulepreload"))return;for(const M of document.querySelectorAll('link[rel="modulepreload"]'))S(M);new MutationObserver(M=>{for(const O of M)if(O.type==="childList")for(const A of O.addedNodes)A.tagName==="LINK"&&A.rel==="modulepreload"&&S(A)}).observe(document,{childList:!0,subtree:!0});function w(M){const O={};return M.integrity&&(O.integrity=M.integrity),M.referrerPolicy&&(O.referrerPolicy=M.referrerPolicy),M.crossOrigin==="use-credentials"?O.credentials="include":M.crossOrigin==="anonymous"?O.credentials="omit":O.credentials="same-origin",O}function S(M){if(M.ep)return;M.ep=!0;const O=w(M);fetch(M.href,O)}})();var X2=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function yh(s){return s&&s.__esModule&&Object.prototype.hasOwnProperty.call(s,"default")?s.default:s}var zu={exports:{}},go={};/**
3
3
  * @license React
4
4
  * react-jsx-runtime.production.js
@@ -399,7 +399,7 @@ Cancel = delete worktree only`,"todo.retry":"Retry","todo.retryDesc":"Cleans up
399
399
  *
400
400
  * This source code is licensed under the ISC license.
401
401
  * See the LICENSE file in the root directory of this source tree.
402
- */const ES=[["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"}]],LS=Qe("zoom-out",ES),ug=8;function RS({onLogin:s,onChangePassword:h}){const[w,S]=j.useState(""),[M,O]=j.useState(""),[A,r]=j.useState(""),[u,d]=j.useState(!1),[g,l]=j.useState(!1),[m,b]=j.useState(!1),[C,p]=j.useState(""),[o,c]=j.useState(!1),{t:a,toggleLang:f}=Tt(),y=u&&M.length>0&&M.length<ug,R=u&&A.length>0&&M!==A,k=u?!!w&&M.length>=ug&&M===A:!!w,D=()=>{d(L=>!L),O(""),r(""),p("")},E=async L=>{if(L.preventDefault(),!(!k||o)){p(""),c(!0);try{u?await h(w,M,A,m):await s(w,m)}catch(z){p(u&&z instanceof Error&&z.message?z.message:a("login.error"))}finally{c(!1)}}};return v.jsxs("div",{className:"min-h-screen bg-theme-bg flex items-center justify-center px-4 relative",children:[v.jsx("button",{onClick:f,className:"lang-toggle absolute top-6 right-6",children:a("lang.toggle")}),v.jsxs("div",{className:"w-full max-w-sm",children:[v.jsxs("div",{className:"text-center mb-10",children:[v.jsx("div",{className:"inline-flex items-center justify-center w-16 h-16 rounded-2xl bg-accent/10 mb-5",children:v.jsx(Ah,{size:32,className:"text-accent"})}),v.jsx("h1",{className:"text-2xl font-semibold text-theme-text",children:a("login.title")}),v.jsx("p",{className:"text-theme-muted text-sm mt-2",children:a("login.subtitle")})]}),v.jsx("form",{onSubmit:E,children:v.jsxs("div",{className:"card p-8",children:[v.jsx("label",{className:"block text-sm font-medium text-theme-text-secondary mb-2",children:a(u?"account.oldPassword":"login.password")}),v.jsx("input",{type:"password",value:w,onChange:L=>S(L.target.value),placeholder:"*************",className:"input-field text-base",autoComplete:"current-password",autoFocus:!0}),u&&v.jsxs(v.Fragment,{children:[v.jsx("label",{className:"block text-sm font-medium text-theme-text-secondary mb-2 mt-4",children:a("account.newPassword")}),v.jsx("input",{type:"password",value:M,onChange:L=>O(L.target.value),className:"input-field text-base",autoComplete:"new-password","aria-label":a("account.newPassword")}),y&&v.jsx("p",{className:"mt-1 text-2xs text-status-error",children:a("account.tooShort")}),v.jsx("label",{className:"block text-sm font-medium text-theme-text-secondary mb-2 mt-4",children:a("account.confirm")}),v.jsx("input",{type:"password",value:A,onChange:L=>r(L.target.value),className:"input-field text-base",autoComplete:"new-password","aria-label":a("account.confirm")}),R&&v.jsx("p",{className:"mt-1 text-2xs text-status-error",children:a("account.mismatch")})]}),C&&v.jsx("div",{className:"mt-4 py-2.5 px-4 bg-status-error/5 rounded-xl text-sm text-status-error",children:C}),v.jsxs("label",{className:"flex items-center gap-2 mt-5 text-sm text-theme-text-secondary cursor-pointer select-none",children:[v.jsx("input",{type:"checkbox",checked:m,onChange:L=>b(L.target.checked),className:"accent-accent w-4 h-4"}),a("login.rememberMe")]}),v.jsx("button",{type:"submit",disabled:!k||o,className:"btn-primary w-full mt-6 py-3",children:a(o?"login.loading":u?"login.changeSubmit":"login.submit")})]})}),v.jsxs("div",{className:"mt-4 flex items-center justify-center gap-5 text-xs",children:[v.jsx("button",{type:"button",onClick:D,className:"text-theme-muted hover:text-theme-text underline-offset-2 hover:underline",children:a(u?"login.backToLogin":"login.changePassword")}),v.jsx("button",{type:"button",onClick:()=>l(L=>!L),className:"text-theme-muted hover:text-theme-text underline-offset-2 hover:underline",children:a("login.forgot")})]}),g&&v.jsx("div",{className:"mt-3 px-4 py-3 rounded-xl text-xs text-theme-text-tertiary border leading-relaxed",children:a("login.forgotHint")}),v.jsx("div",{className:"mt-6 text-center text-xs text-theme-text-tertiary",children:a("login.footer")}),v.jsx("div",{className:"mt-4 px-2 py-3 rounded-xl text-xs text-theme-text-tertiary border leading-relaxed text-center",children:a("login.disclaimer")})]})]})}const hg=8;function DS({onSetup:s}){const[h,w]=j.useState(""),[S,M]=j.useState(""),[O,A]=j.useState(""),[r,u]=j.useState(!1),{t:d,toggleLang:g}=Tt(),l=h.length>0&&h.length<hg,m=S.length>0&&h!==S,b=h.length>=hg&&h===S&&!r,C=async p=>{if(p.preventDefault(),!!b){A(""),u(!0);try{await s(h,S)}catch(o){A(o instanceof Error&&o.message?o.message:d("setup.error"))}finally{u(!1)}}};return v.jsxs("div",{className:"min-h-screen bg-theme-bg flex items-center justify-center px-4 relative",children:[v.jsx("button",{onClick:g,className:"lang-toggle absolute top-6 right-6",children:d("lang.toggle")}),v.jsxs("div",{className:"w-full max-w-sm",children:[v.jsxs("div",{className:"text-center mb-10",children:[v.jsx("div",{className:"inline-flex items-center justify-center w-16 h-16 rounded-2xl bg-accent/10 mb-5",children:v.jsx(Ah,{size:32,className:"text-accent"})}),v.jsx("h1",{className:"text-2xl font-semibold text-theme-text",children:d("setup.title")}),v.jsx("p",{className:"text-theme-muted text-sm mt-2",children:d("setup.subtitle")})]}),v.jsx("form",{onSubmit:C,children:v.jsxs("div",{className:"card p-8",children:[v.jsx("label",{className:"block text-sm font-medium text-theme-text-secondary mb-2",children:d("setup.password")}),v.jsx("input",{type:"password",value:h,onChange:p=>w(p.target.value),placeholder:"*************",className:"input-field text-base",autoFocus:!0}),l&&v.jsx("p",{className:"mt-1 text-2xs text-status-error",children:d("setup.tooShort")}),v.jsx("label",{className:"block text-sm font-medium text-theme-text-secondary mb-2 mt-5",children:d("setup.confirm")}),v.jsx("input",{type:"password",value:S,onChange:p=>M(p.target.value),placeholder:"*************",className:"input-field text-base"}),m&&v.jsx("p",{className:"mt-1 text-2xs text-status-error",children:d("setup.mismatch")}),O&&v.jsx("div",{className:"mt-4 py-2.5 px-4 bg-status-error/5 rounded-xl text-sm text-status-error",children:O}),v.jsx("button",{type:"submit",disabled:!b,className:"btn-primary w-full mt-6 py-3",children:d(r?"setup.loading":"setup.submit")})]})}),v.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 TS(s){return nt("/api/projects/browse",{initialPath:s})}function Z2(s){return nt("/api/projects/open-folder",{path:s})}function Bv(){return bt("/api/projects")}function ek(s){return bt(`/api/projects/${s}`)}function MS(s){return nt("/api/projects",s)}function tk(s){return bt(`/api/projects/${s}/svn-detect`)}function AS(s,h){return Di(`/api/projects/${s}`,h)}function ik(s,h){const w=h?`?todoId=${encodeURIComponent(h)}`:"";return bt(`/api/projects/${s}/debug-logs${w}`)}function jS(s){return Cr(`/api/projects/${s}`)}function OS(s){return nt("/api/projects/reorder",{ids:s})}function sk(s){return nt(`/api/projects/${s}/start`)}function nk(s){return nt(`/api/projects/${s}/stop`)}function BS(s){return bt(`/api/projects/${s}/status`)}function rk(){return bt("/api/active-work")}function ok(s){return nt(`/api/projects/${s}/check-git`)}function ak(s,h){const w=h?`?worktreePath=${encodeURIComponent(h)}`:"";return bt(`/api/projects/${s}/git-status${w}`)}function lk(s,h=0,w=50,S){const M=new URLSearchParams({skip:String(h),limit:String(w)});return bt(`/api/projects/${s}/git-log?${M}`)}function ck(s,h){return bt(`/api/projects/${s}/git-refs`)}function uk(s,h,w){return nt(`/api/projects/${s}/git-stage`,{files:h,worktreePath:w})}function hk(s,h,w){return nt(`/api/projects/${s}/git-unstage`,{files:h,worktreePath:w})}function dk(s,h,w){return nt(`/api/projects/${s}/git-ignore`,{path:h,worktreePath:w})}function fk(s,h,w){return nt(`/api/projects/${s}/git-commit`,{message:h,worktreePath:w})}function pk(s,h,w){return nt(`/api/projects/${s}/git-pull`,{remote:h,branch:w})}function mk(s,h){return nt(`/api/projects/${s}/git-push`,h||{})}function gk(s){return bt(`/api/projects/${s}/git-remotes`)}function vk(s,h,w){return nt(`/api/projects/${s}/git-fetch`,{remote:h,prune:w})}function _k(s,h,w){return nt(`/api/projects/${s}/git-branch`,{name:h,startPoint:w})}function bk(s,h,w){return nt(`/api/projects/${s}/git-branch-delete`,{name:h,force:w})}function yk(s,h){return nt(`/api/projects/${s}/git-checkout`,{branch:h})}function wk(s,h){return nt(`/api/projects/${s}/git-merge`,{branch:h})}function Sk(s,h,w,S){return nt(`/api/projects/${s}/git-conflict-resolve`,{file:h,side:w,worktreePath:S})}function xk(s,h,w){const S=w?`&worktreePath=${encodeURIComponent(w)}`:"";return bt(`/api/projects/${s}/git-conflict-file?file=${encodeURIComponent(h)}${S}`)}function Ck(s,h,w,S){return nt(`/api/projects/${s}/git-conflict-file`,{file:h,content:w,worktreePath:S})}function kk(s){return nt(`/api/projects/${s}/git-conflict-continue`)}function Ek(s){return nt(`/api/projects/${s}/git-conflict-abort`)}function Lk(s,h){return nt(`/api/projects/${s}/git-stash`,{message:h})}function Rk(s,h){return nt(`/api/projects/${s}/git-stash-pop`,{index:h})}function Dk(s){return bt(`/api/projects/${s}/git-stash-list`)}function Tk(s,h,w,S){return nt(`/api/projects/${s}/git-discard`,{files:h,all:w,worktreePath:S})}function Mk(s,h,w,S){return nt(`/api/projects/${s}/git-tag`,{name:h,message:w,commit:S})}function Ak(s,h,w){return nt(`/api/projects/${s}/git-branch-rename`,{oldName:h,newName:w})}function jk(s,h){return nt(`/api/projects/${s}/git-rebase`,{onto:h})}function Ok(s,h){return nt(`/api/projects/${s}/git-revert`,{commit:h})}function Bk(s,h){return nt(`/api/projects/${s}/git-cherry-pick`,{commit:h})}function Nk(s,h,w){return nt(`/api/projects/${s}/git-reset`,{commit:h,mode:w})}function zk(s,h,w,S){const M=new URLSearchParams;return h&&M.set("file",h),w&&M.set("staged","true"),S&&M.set("worktreePath",S),bt(`/api/projects/${s}/git-diff?${M}`)}function Hk(s,h){const w=new URLSearchParams({hash:h});return bt(`/api/projects/${s}/git-commit-files?${w}`)}function Pk(s,h,w){const S=new URLSearchParams({hash:h});return w&&S.set("file",w),bt(`/api/projects/${s}/git-commit-diff?${S}`)}function Ik(s){return bt(`/api/projects/${s}/worktrees`)}function Fk(s,h,w){return nt(`/api/projects/${s}/worktree-cleanup`,{worktreePath:h,branchName:w})}function Nv(s){const h=new URLSearchParams;s.hours!==void 0&&h.set("hours",String(s.hours)),s.statuses&&s.statuses.length>0&&h.set("statuses",s.statuses.join(","));const w=h.toString();return w?`?${w}`:""}function Uk(s={}){return bt(`/api/review/queue${Nv(s)}`)}function NS(s={}){return bt(`/api/review/summary${Nv(s)}`)}function $k(s){return bt(`/api/review/diff/${encodeURIComponent(s)}`)}function Wk(s,h){return bt(`/api/review/diff/${encodeURIComponent(s)}/file?path=${encodeURIComponent(h)}`)}function zS(){return bt("/api/favorites")}function HS(s){return nt("/api/favorites",s)}function PS(s,h){return Di(`/api/favorites/${s}`,h)}function IS(s){return Cr(`/api/favorites/${s}`)}function FS(s){return nt(`/api/favorites/${s}/launch`)}function US(s){return nt("/api/favorites/browse-file",{initialPath:s})}function uh(){return bt("/api/tunnel/status")}function $S(){return bt("/api/tunnel/config")}function WS(s){return Di("/api/tunnel/config",s)}function zv(s){return nt("/api/tunnel/start",{})}function qS(){return nt("/api/tunnel/stop")}const Hv=j.createContext({theme:"light",toggleTheme:()=>{}});function GS(){const[s,h]=j.useState(()=>{const S=localStorage.getItem("theme");return S==="light"||S==="dark"?S:window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light"});j.useEffect(()=>{document.documentElement.setAttribute("data-theme",s),localStorage.setItem("theme",s)},[s]);const w=j.useCallback(()=>{h(S=>S==="light"?"dark":"light")},[]);return{theme:s,toggleTheme:w}}function YS(){return j.useContext(Hv)}const Pv=j.createContext({enabled:!1,supported:!1,toggleNotification:()=>{},sendNotification:()=>{}});function KS(){const s="Notification"in window,[h,w]=j.useState(()=>s?localStorage.getItem("clitrigger-notifications")==="on"&&Notification.permission==="granted":!1),S=j.useRef(h);j.useEffect(()=>{S.current=h},[h]);const M=j.useCallback(async()=>{if(s)if(S.current)localStorage.setItem("clitrigger-notifications","off"),w(!1);else{if(Notification.permission==="denied"||Notification.permission==="default"&&await Notification.requestPermission()!=="granted")return;localStorage.setItem("clitrigger-notifications","on"),w(!0)}},[s]),O=j.useCallback((A,r,u)=>{if(!S.current)return;const d=new Notification(A,{body:r});d.onclick=()=>{u==null||u();const g=window.electronAPI;g!=null&&g.windowFocus?g.windowFocus():window.focus(),d.close()}},[]);return{enabled:h,supported:s,toggleNotification:M,sendNotification:O}}function Ll(){return j.useContext(Pv)}let XS=0;const Iv=j.createContext(null);function VS({children:s}){const[h,w]=j.useState([]),S=j.useRef(new Map),M=j.useRef(new Map),O=j.useRef(new Map),A=j.useCallback(b=>{w(o=>o.filter(c=>c.id!==b));const C=O.current.get(b);C&&M.current.get(C)===b&&M.current.delete(C),O.current.delete(b);const p=S.current.get(b);p&&(clearTimeout(p),S.current.delete(b))},[]),r=j.useCallback((b,C="info",p=3500)=>{const o=`${C}:${b}`,c=M.current.get(o);if(c)return c;const a=`toast-${++XS}`;M.current.set(o,a),O.current.set(a,o),w(y=>[...y,{id:a,message:b,type:C,duration:p}]);const f=setTimeout(()=>A(a),p);return S.current.set(a,f),a},[A]),u=j.useCallback((b,C)=>r(b,"success",C),[r]),d=j.useCallback((b,C)=>r(b,"error",C),[r]),g=j.useCallback((b,C)=>r(b,"info",C),[r]),l=j.useCallback((b,C)=>r(b,"warning",C),[r]);j.useEffect(()=>()=>{S.current.forEach(clearTimeout),S.current.clear(),M.current.clear(),O.current.clear()},[]);const m=j.useMemo(()=>({toasts:h,show:r,success:u,error:d,info:g,warning:l,dismiss:A}),[h,r,u,d,g,l,A]);return j.createElement(Iv.Provider,{value:m},s)}function un(){const s=j.useContext(Iv);if(!s)throw new Error("useToast must be used within ToastProvider");return s}function Tn(...s){return s.filter(Boolean).join(" ")}const JS={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 Ho({open:s,onClose:h,size:w="md",position:S="center",disableEscClose:M=!1,disableBackdropClose:O=!1,children:A}){const r=j.useRef(null);return j.useEffect(()=>{if(!s||M)return;const u=d=>{d.key==="Escape"&&h()};return document.addEventListener("keydown",u),()=>document.removeEventListener("keydown",u)},[s,M,h]),s?zi.createPortal(v.jsx("div",{ref:r,className:Tn("fixed inset-0 bg-black/50 backdrop-blur-sm z-modal flex",S==="center"?"items-center justify-center p-4":"items-start justify-center px-4 pt-[20vh]"),onClick:u=>{!O&&u.target===r.current&&h()},children:v.jsx("div",{className:Tn("w-full",JS[w]),children:A})}),document.body):null}const QS={default:"btn",primary:"btn-primary",secondary:"btn-secondary",danger:"btn-danger",ghost:"btn-ghost"},ZS={sm:"btn-sm",md:"btn-md",lg:"btn-lg"},Li=j.forwardRef(function({variant:h="default",size:w,type:S="button",className:M,...O},A){return v.jsx("button",{ref:A,type:S,className:Tn(QS[h],w&&ZS[w],M),...O})}),Fv=j.createContext(null);let dg=0;function ex({children:s}){const[h,w]=j.useState(null),S=j.useRef(null),M=j.useCallback(d=>{const g=S.current;g&&(g.kind==="confirm"?g.resolve(!1):g.resolve(null)),S.current=d,w(d)},[]),O=j.useCallback(()=>{S.current=null,w(null)},[]),A=j.useCallback(d=>{const g=typeof d=="string"?{message:d}:d;return new Promise(l=>{M({id:++dg,kind:"confirm",options:g,resolve:l})})},[M]),r=j.useCallback(d=>{const g=typeof d=="string"?{message:d}:d;return new Promise(l=>{M({id:++dg,kind:"prompt",options:g,resolve:l})})},[M]),u=j.useMemo(()=>({confirm:A,prompt:r}),[A,r]);return v.jsxs(Fv.Provider,{value:u,children:[s,h&&v.jsx(tx,{dialog:h,onSettled:O},h.id)]})}function tx({dialog:s,onSettled:h}){const{t:w}=Tt(),[S,M]=j.useState(s.kind==="prompt"?s.options.initialValue??"":""),O=()=>{s.kind==="confirm"?s.resolve(!1):s.resolve(null),h()},A=()=>{s.kind==="confirm"?s.resolve(!0):s.resolve(S),h()},r=s.kind==="confirm"&&!!s.options.danger,u=s.kind==="confirm"&&s.options.confirmLabel||w("common.ok"),d=s.kind==="confirm"&&s.options.cancelLabel||w("common.cancel"),g=v.jsxs("div",{className:"mt-4 flex justify-end gap-2",children:[v.jsx(Li,{size:"sm",onClick:O,autoFocus:r,children:d}),v.jsx(Li,{variant:r?"danger":"primary",size:"sm",type:s.kind==="prompt"?"submit":"button",onClick:s.kind==="prompt"?void 0:A,autoFocus:s.kind==="confirm"&&!r,children:u})]});return v.jsx(Ho,{open:!0,onClose:O,size:"sm",children:v.jsxs("div",{className:"bg-theme-card border border-theme-border rounded-2xl shadow-elevated p-5",children:[s.options.title&&v.jsx("div",{className:"text-sm font-semibold text-theme-text mb-2",children:s.options.title}),v.jsx("p",{className:"text-sm text-theme-text-secondary whitespace-pre-line break-words",children:s.options.message}),s.kind==="prompt"?v.jsxs("form",{onSubmit:l=>{l.preventDefault(),A()},children:[v.jsx("input",{autoFocus:!0,value:S,onChange:l=>M(l.target.value),placeholder:s.options.placeholder,className:"input-field mt-3"}),g]}):g]})})}function kr(){const s=j.useContext(Fv);if(!s)throw new Error("useDialog must be used within DialogProvider");return s}function ix({onSubmit:s,onCancel:h}){const[w,S]=j.useState(""),[M,O]=j.useState(""),[A,r]=j.useState(!1),[u,d]=j.useState(!1),[g,l]=j.useState(""),{t:m}=Tt(),b=async p=>{if(p.preventDefault(),!(!w.trim()||!M.trim())){l(""),d(!0);try{await s(w.trim(),M.trim())}catch(o){const c=o instanceof Error?o.message:String(o);l(c||m("form.createError"))}finally{d(!1)}}},C=async()=>{r(!0);try{const p=await TS(M||void 0);p.path&&O(p.path)}catch{}r(!1)};return v.jsx(Ho,{open:!0,onClose:h,size:"md",children:v.jsxs("div",{className:"bg-theme-card border border-theme-border rounded-2xl shadow-elevated p-8",children:[v.jsx("h2",{className:"text-lg font-semibold text-warm-800 mb-6",children:m("form.newProject")}),v.jsxs("form",{onSubmit:b,children:[v.jsxs("div",{className:"mb-5",children:[v.jsx("label",{className:"block text-sm font-medium text-warm-600 mb-2",children:m("form.projectName")}),v.jsx("input",{type:"text",placeholder:"my-project",value:w,onChange:p=>S(p.target.value),className:"input-field",autoFocus:!0})]}),v.jsxs("div",{className:"mb-8",children:[v.jsx("label",{className:"block text-sm font-medium text-warm-600 mb-2",children:m("form.folderPath")}),v.jsxs("div",{className:"flex gap-2",children:[v.jsx("input",{type:"text",placeholder:"C:/Projects/my-project",value:M,onChange:p=>O(p.target.value),className:"input-field text-sm flex-1"}),v.jsx("button",{type:"button",onClick:C,disabled:A,className:"btn-ghost text-sm px-3 shrink-0",title:m("browse.title"),children:A?v.jsx(lh,{size:16,className:"animate-spin"}):v.jsx(Dv,{size:16})})]})]}),g&&v.jsx("p",{className:"text-sm mb-4",style:{color:"var(--color-danger, #ef4444)"},children:g}),v.jsxs("div",{className:"flex justify-end gap-3",children:[v.jsx("button",{type:"button",onClick:h,className:"btn-ghost text-sm",children:m("form.cancel")}),v.jsx("button",{type:"submit",disabled:!w.trim()||!M.trim()||u,className:"btn-primary text-sm",children:m(u?"form.creating":"form.create")})]})]})]})})}const sx=[{value:"executable",icon:Rv},{value:"command",icon:Ov},{value:"url",icon:Mv}];function nx(s){const h=[],w=/"([^"]*)"|(\S+)/g;let S;for(;(S=w.exec(s))!==null;)h.push(S[1]!==void 0?S[1]:S[2]);return h}function fg(s){if(!s)return"";try{const h=JSON.parse(s);if(Array.isArray(h))return h.map(w=>typeof w=="string"&&/\s/.test(w)?`"${w}"`:String(w)).join(" ")}catch{}return""}function rx({initial:s,onSubmit:h,onCancel:w}){const{t:S}=Tt(),[M,O]=j.useState((s==null?void 0:s.name)??""),[A,r]=j.useState((s==null?void 0:s.type)??"executable"),[u,d]=j.useState((s==null?void 0:s.target)??""),[g,l]=j.useState(fg((s==null?void 0:s.args)??null)),[m,b]=j.useState((s==null?void 0:s.cwd)??""),[C,p]=j.useState(!1);j.useEffect(()=>{O((s==null?void 0:s.name)??""),r((s==null?void 0:s.type)??"executable"),d((s==null?void 0:s.target)??""),l(fg((s==null?void 0:s.args)??null)),b((s==null?void 0:s.cwd)??"")},[s]);const[o,c]=j.useState(!1),a=A==="executable",f=async()=>{c(!0);try{const{path:H}=await US(u||void 0);if(!H)return;if(d(H),!M.trim()){const P=H.replace(/\\/g,"/").split("/").pop()||"";O(P.replace(/\.[^.]+$/,""))}}catch{}finally{c(!1)}},y=!!s,R=M.trim(),k=u.trim(),D=A!=="url"||/^https?:\/\//i.test(k),E=!!R&&!!k&&D&&!C,L=async H=>{if(H.preventDefault(),!!E){p(!0);try{const P={name:R,type:A,target:k,args:A==="executable"&&g.trim()?nx(g.trim()):null,cwd:A!=="url"&&m.trim()?m.trim():null};await h(P)}finally{p(!1)}}},z=S(A==="executable"?"favorites.form.targetHint.executable":A==="command"?"favorites.form.targetHint.command":"favorites.form.targetHint.url");return v.jsx(Ho,{open:!0,onClose:w,size:"md",children:v.jsxs("div",{className:"bg-theme-card border border-theme-border rounded-2xl shadow-elevated p-8",children:[v.jsx("h2",{className:"text-lg font-semibold text-warm-800 mb-6",children:S(y?"favorites.form.title.edit":"favorites.form.title.create")}),v.jsxs("form",{onSubmit:L,children:[v.jsxs("div",{className:"mb-5",children:[v.jsx("label",{className:"block text-sm font-medium text-warm-600 mb-2",children:S("favorites.form.type")}),v.jsx("div",{className:"grid grid-cols-3 gap-2",children:sx.map(({value:H,icon:P})=>v.jsxs("button",{type:"button",onClick:()=>r(H),className:"flex items-center justify-center gap-2 px-3 py-2 rounded-lg text-xs font-medium transition-all border",style:A===H?{backgroundColor:"var(--color-accent)",color:"white",borderColor:"var(--color-accent)"}:{color:"var(--color-text-tertiary)",borderColor:"var(--color-border)"},children:[v.jsx(P,{size:14}),S(`favorites.types.${H}`)]},H))})]}),v.jsxs("div",{className:"mb-5",children:[v.jsx("label",{className:"block text-sm font-medium text-warm-600 mb-2",children:S("favorites.form.name")}),v.jsx("input",{type:"text",value:M,onChange:H=>O(H.target.value),className:"input-field",autoFocus:!0})]}),v.jsxs("div",{className:"mb-5",children:[v.jsx("label",{className:"block text-sm font-medium text-warm-600 mb-2",children:S("favorites.form.target")}),v.jsxs("div",{className:"flex gap-2",children:[v.jsx("input",{type:"text",value:u,onChange:H=>d(H.target.value),className:"input-field text-sm font-mono flex-1",placeholder:z}),a&&v.jsxs("button",{type:"button",onClick:f,disabled:o,className:"btn-ghost text-sm whitespace-nowrap flex items-center gap-1.5 disabled:opacity-50",children:[v.jsx(Dv,{size:14}),S("favorites.form.browse")]})]}),v.jsx("p",{className:"mt-1 text-2xs",style:{color:"var(--color-text-muted)"},children:z})]}),A==="executable"&&v.jsxs("div",{className:"mb-5",children:[v.jsx("label",{className:"block text-sm font-medium text-warm-600 mb-2",children:S("favorites.form.args")}),v.jsx("input",{type:"text",value:g,onChange:H=>l(H.target.value),className:"input-field text-sm font-mono",placeholder:'--flag value "with spaces"'})]}),A!=="url"&&v.jsxs("div",{className:"mb-5",children:[v.jsx("label",{className:"block text-sm font-medium text-warm-600 mb-2",children:S("favorites.form.cwd")}),v.jsx("input",{type:"text",value:m,onChange:H=>b(H.target.value),className:"input-field text-sm font-mono",placeholder:"C:/Projects/my-project"})]}),v.jsx("p",{className:"mb-6 text-2xs leading-snug",style:{color:"var(--color-text-muted)"},children:S("favorites.security.notice")}),v.jsxs("div",{className:"flex justify-end gap-3",children:[v.jsx("button",{type:"button",onClick:w,className:"btn-ghost text-sm",children:S("favorites.form.cancel")}),v.jsx("button",{type:"submit",disabled:!E,className:"btn-primary text-sm",children:S(y?"favorites.form.save":"favorites.form.create")})]})]})]})})}const ox=/^([a-z0-9]([a-z0-9-]*[a-z0-9])?\.)+[a-z]{2,}$/i;function ax({onClose:s}){const{t:h}=Tt(),{error:w,success:S}=un(),[M,O]=j.useState(""),[A,r]=j.useState(""),[u,d]=j.useState(""),[g,l]=j.useState(""),[m,b]=j.useState(!1),[C,p]=j.useState(!1),[o,c]=j.useState(!1),[a,f]=j.useState(null);j.useEffect(()=>{let P=!1;return Promise.all([$S(),uh()]).then(([I,K])=>{P||(O(I.tunnelName),r(I.customHostname),d(I.tunnelName),l(I.customHostname),f(K))}).catch(()=>{}),()=>{P=!0}},[]);const y=M.trim(),R=A.trim(),k=y!==u.trim()||R!==g.trim(),D=!!R&&(!ox.test(R)||R.toLowerCase()==="localhost"||R.toLowerCase()==="127.0.0.1"),E=!!R&&!y,L=k&&!C&&!D&&!E,z=async()=>{if(L){p(!0);try{const P=await WS({tunnelName:y,customHostname:R});d(P.tunnelName),l(P.customHostname),O(P.tunnelName),r(P.customHostname),S(h("tunnel.saved"))}catch(P){w(P instanceof Error?P.message:h("tunnel.saveFailed"))}finally{p(!1)}}},H=async()=>{c(!0);try{try{await qS()}catch{}const P=await zv();f({status:"running",url:P.url}),S(h("tunnel.restarted"))}catch(P){w(P instanceof Error?P.message:h("tunnel.restartFailed"))}finally{c(!1)}};return v.jsxs("div",{className:"p-8",children:[v.jsx("h2",{className:"text-lg font-semibold text-warm-800 mb-1",children:h("tunnel.title")}),v.jsx("p",{className:"text-xs text-warm-400 mb-6",children:h("tunnel.description")}),a&&v.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:[v.jsx("span",{className:`w-2 h-2 rounded-full ${a.status==="running"?"bg-status-success":a.status==="error"?"bg-status-error":"bg-status-pending"}`}),v.jsx("span",{className:"font-medium",children:h(`tunnel.status.${a.status}`)}),a.url&&v.jsx("a",{href:a.url,target:"_blank",rel:"noreferrer",className:"ml-auto font-mono truncate hover:underline",style:{color:"var(--color-accent)"},children:a.url})]}),v.jsxs("div",{className:"mb-4",children:[v.jsx("label",{className:"block text-sm font-medium text-warm-600 mb-2",children:h("tunnel.name.label")}),v.jsx("input",{type:"text",value:M,onChange:P=>O(P.target.value),placeholder:h("tunnel.name.placeholder"),className:"input-field text-sm font-mono"}),v.jsx("p",{className:"mt-1 text-2xs",style:{color:"var(--color-text-muted)"},children:h("tunnel.name.hint")})]}),v.jsxs("div",{className:"mb-4",children:[v.jsx("label",{className:"block text-sm font-medium text-warm-600 mb-2",children:h("tunnel.hostname.label")}),v.jsx("input",{type:"text",value:A,onChange:P=>r(P.target.value),placeholder:h("tunnel.hostname.placeholder"),className:"input-field text-sm font-mono"}),v.jsx("p",{className:"mt-1 text-2xs",style:{color:"var(--color-text-muted)"},children:h("tunnel.hostname.hint")}),D&&v.jsx("p",{className:"mt-1 text-2xs text-status-error",children:h("tunnel.hostname.invalid")}),E&&v.jsx("p",{className:"mt-1 text-2xs text-status-error",children:h("tunnel.hostname.needsName")})]}),v.jsxs("div",{className:"mb-5",children:[v.jsxs("button",{type:"button",onClick:()=>b(!m),className:"flex items-center gap-1 text-xs text-accent-dark hover:text-accent transition-colors",children:[v.jsx("span",{className:`inline-block transition-transform ${m?"rotate-90":""}`,children:"▶"}),h("tunnel.guide.toggle")]}),m&&v.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:[v.jsx("p",{className:"font-semibold text-warm-700 mb-1",children:h("tunnel.guide.heading")}),v.jsxs("ol",{className:"list-decimal list-inside space-y-1 ml-1",children:[v.jsx("li",{children:v.jsx("code",{className:"font-mono",children:"cloudflared tunnel login"})}),v.jsx("li",{children:v.jsx("code",{className:"font-mono",children:"cloudflared tunnel create my-app"})}),v.jsx("li",{children:v.jsx("code",{className:"font-mono",children:"cloudflared tunnel route dns my-app app.your-domain.com"})}),v.jsx("li",{children:h("tunnel.guide.step4")})]}),v.jsx("p",{className:"text-2xs text-warm-400 pt-1",children:h("tunnel.guide.note")})]})]}),v.jsxs("div",{className:"flex items-center justify-between gap-3",children:[v.jsx("button",{type:"button",onClick:H,disabled:o,className:"btn-ghost text-sm disabled:opacity-50",children:o?(a==null?void 0:a.status)==="running"?h("tunnel.restarting"):h("tunnel.starting"):(a==null?void 0:a.status)==="running"?h("tunnel.restart"):h("tunnel.start")}),v.jsxs("div",{className:"flex gap-3",children:[s&&v.jsx("button",{type:"button",onClick:s,className:"btn-ghost text-sm",children:h("tunnel.close")}),v.jsx("button",{type:"button",onClick:z,disabled:!L,className:"btn-primary text-sm",children:h(C?"tunnel.saving":"tunnel.save")})]})]})]})}const pg=8;function lx({onClose:s}){const{t:h}=Tt(),{error:w,success:S}=un(),[M,O]=j.useState(""),[A,r]=j.useState(""),[u,d]=j.useState(""),[g,l]=j.useState(!1),m=A.length>0&&A.length<pg,b=u.length>0&&A!==u,C=!!M&&A.length>=pg&&A===u&&!g,p=()=>{O(""),r(""),d("")},o=async()=>{if(C){l(!0);try{await wv(M,A,u),S(h("account.saved")),p()}catch(c){w(c instanceof Error&&c.message?c.message:h("account.saveFailed"))}finally{l(!1)}}};return v.jsxs("div",{className:"p-8",children:[v.jsx("h2",{className:"text-lg font-semibold text-warm-800 mb-1",children:h("account.title")}),v.jsx("p",{className:"text-xs text-warm-400 mb-6",children:h("account.description")}),v.jsxs("div",{className:"mb-4",children:[v.jsx("label",{className:"block text-sm font-medium text-warm-600 mb-2",children:h("account.oldPassword")}),v.jsx("input",{type:"password",value:M,onChange:c=>O(c.target.value),className:"input-field text-sm",autoComplete:"current-password"})]}),v.jsxs("div",{className:"mb-4",children:[v.jsx("label",{className:"block text-sm font-medium text-warm-600 mb-2",children:h("account.newPassword")}),v.jsx("input",{type:"password",value:A,onChange:c=>r(c.target.value),className:"input-field text-sm",autoComplete:"new-password"}),m&&v.jsx("p",{className:"mt-1 text-2xs text-status-error",children:h("account.tooShort")})]}),v.jsxs("div",{className:"mb-6",children:[v.jsx("label",{className:"block text-sm font-medium text-warm-600 mb-2",children:h("account.confirm")}),v.jsx("input",{type:"password",value:u,onChange:c=>d(c.target.value),className:"input-field text-sm",autoComplete:"new-password"}),b&&v.jsx("p",{className:"mt-1 text-2xs text-status-error",children:h("account.mismatch")})]}),v.jsxs("div",{className:"flex items-center justify-end gap-3",children:[s&&v.jsx("button",{type:"button",onClick:s,className:"btn-ghost text-sm",children:h("account.close")}),v.jsx("button",{type:"button",onClick:o,disabled:!C,className:"btn-primary text-sm",children:h(g?"account.saving":"account.save")})]})]})}function cx(){return bt("/api/session-tags")}function ux(s){return nt("/api/session-tags",s)}function hx(s,h){return Di(`/api/session-tags/${s}`,h)}function dx(s){return Cr(`/api/session-tags/${s}`)}function Uv(){return bt("/api/session-aliases")}function $v(s){return nt("/api/session-aliases",s)}function fx(s,h){return Di(`/api/session-aliases/${s}`,h)}function px(s){return Cr(`/api/session-aliases/${s}`)}function Wv(){return bt("/api/session-settings")}function Yu(s){return Di("/api/session-settings",s)}const Ce={titleBg:"#2d2d2d",titleText:"#999",bg:"#0c0c0c",text:"#cccccc",dim:"#666666",bright:"#f2f2f2",prompt:"#16c60c",success:"#16c60c",error:"#f14c4c",warning:"#cca700",info:"#569cd6",separator:"#333333"},_t="'Cascadia Code', 'Cascadia Mono', ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, 'Courier New', monospace",jh=13,wo=8,So=28,br=new Map,Rn=new Map;let ml=jh;function Oh(s){return`sessionFontSize:${s}`}window.addEventListener("storage",s=>{var S;if(s.storageArea!==localStorage||!((S=s.key)!=null&&S.startsWith("sessionFontSize:")))return;const h=s.key.slice(16);br.delete(h);const w=Rn.get(h);if(w){const M=xo(h);w.forEach(O=>O(M))}});function hh(s){return Number.isFinite(s)?Math.max(wo,Math.min(So,Math.round(s))):ml}function mx(s){if(br.has(s))return!0;try{return localStorage.getItem(Oh(s))!==null}catch{return!1}}function xo(s){const h=br.get(s);if(h!==void 0)return h;let w=null;try{const S=localStorage.getItem(Oh(s));if(S!==null){const M=parseInt(S,10);Number.isFinite(M)&&(w=hh(M))}}catch{}return w===null?hh(ml):(br.set(s,w),w)}function dh(s,h){const w=hh(h);if(br.get(s)===w)return;br.set(s,w);try{localStorage.setItem(Oh(s),String(w))}catch{}const S=Rn.get(s);S&&S.forEach(M=>M(w))}function bo(s,h){dh(s,xo(s)+h)}function hl(s){const h=Math.max(wo,Math.min(So,Math.round(s)));Number.isFinite(h)&&h!==ml&&(ml=h,Rn.forEach((w,S)=>{mx(S)||w.forEach(M=>M(h))}))}function qv(s){const[h,w]=j.useState(()=>xo(s));j.useEffect(()=>{w(xo(s));let O=Rn.get(s);return O||(O=new Set,Rn.set(s,O)),O.add(w),()=>{const A=Rn.get(s);A&&(A.delete(w),A.size===0&&Rn.delete(s))}},[s]);const S=j.useCallback(O=>dh(s,O),[s]),M=j.useCallback(O=>dh(s,xo(s)+O),[s]);return[h,S,M]}const Co=["#A78BFA","#F472B6","#FB923C","#FBBF24","#34D399","#60A5FA","#F87171","#94A3B8"];function mg(s){for(const h of Co)if(!s.some(w=>w.color.toLowerCase()===h.toLowerCase()))return h;return Co[s.length%Co.length]}function gx({onClose:s}){const{t:h}=Tt(),{confirm:w}=kr(),{error:S,success:M}=un(),[O,A]=j.useState([]),[r,u]=j.useState(!1),[d,g]=j.useState(jh),[l,m]=j.useState(!1),[b,C]=j.useState(!1),[p,o]=j.useState(!1),[c,a]=j.useState(!1),f=j.useRef(null),[y,R]=j.useState(""),[k,D]=j.useState(Co[0]),[E,L]=j.useState(!1),[z,H]=j.useState(null),[P,I]=j.useState(""),[K,X]=j.useState(Co[0]),[Y,$]=j.useState(!1),[U,T]=j.useState([]),[F,B]=j.useState(""),[W,Z]=j.useState(""),[ne,ge]=j.useState(!1),[xe,J]=j.useState(null),[G,de]=j.useState(""),[oe,Ae]=j.useState(""),[Oe,Xe]=j.useState(!1);j.useEffect(()=>{let ee=!1;return Promise.all([cx(),Wv(),Uv()]).then(([be,he,He])=>{ee||(A(be),u(he.defaultUseWorktree),g(he.defaultFontSize),hl(he.defaultFontSize),m(he.imeDebug),D(mg(be)),T(He),C(!0))}).catch(be=>{ee||S(be instanceof Error?be.message:"Failed to load")}),()=>{ee=!0}},[S]);const We=y.trim(),rt=!!We&&!E,ye=j.useMemo(()=>[...O].sort((ee,be)=>ee.sort_order-be.sort_order||ee.name.localeCompare(be.name)),[O]);j.useEffect(()=>()=>{f.current&&clearTimeout(f.current)},[]);const Te=ee=>{if(!Number.isFinite(ee))return;const be=Math.max(wo,Math.min(So,Math.round(ee)));g(be),hl(be),f.current&&clearTimeout(f.current),f.current=setTimeout(()=>{Yu({defaultFontSize:be}).then(he=>{g(he.defaultFontSize),hl(he.defaultFontSize)}).catch(he=>S(he instanceof Error?he.message:"Save failed"))},350)},ct=async ee=>{o(!0);try{const be=await Yu({defaultUseWorktree:ee});u(be.defaultUseWorktree),M(h("sessionSettings.saved"))}catch(be){S(be instanceof Error?be.message:"Save failed")}finally{o(!1)}},it=async ee=>{var be,he;a(!0);try{const He=await Yu({imeDebug:ee});m(He.imeDebug),(he=(be=window.electronAPI)==null?void 0:be.imeSetDebug)==null||he.call(be,He.imeDebug),M(h("sessionSettings.saved"))}catch(He){S(He instanceof Error?He.message:"Save failed")}finally{a(!1)}},ze=async()=>{if(rt){L(!0);try{const ee=await ux({name:We,color:k});A(be=>[...be,ee]),R(""),D(mg([...O,ee]))}catch(ee){S(ee instanceof Error?ee.message:"Create failed")}finally{L(!1)}}},qe=ee=>{H(ee.id),I(ee.name),X(ee.color)},Fe=()=>{H(null),I("")},Be=async()=>{if(!z)return;const ee=P.trim();if(ee){$(!0);try{const be=await hx(z,{name:ee,color:K});A(he=>he.map(He=>He.id===be.id?be:He)),Fe()}catch(be){S(be instanceof Error?be.message:"Save failed")}finally{$(!1)}}},$e=async ee=>{if(await w({message:h("sessionSettings.tags.deleteConfirm").replace("{name}",ee.name),danger:!0}))try{await dx(ee.id),A(be=>be.filter(he=>he.id!==ee.id))}catch(be){S(be instanceof Error?be.message:"Delete failed")}},lt=F.trim(),st=W.trim(),St=!!lt&&!!st&&!ne,Se=j.useMemo(()=>[...U].sort((ee,be)=>ee.sort_order-be.sort_order||ee.name.localeCompare(be.name)),[U]),Ie=async()=>{if(St){ge(!0);try{const ee=await $v({name:lt,command_template:st});T(be=>[...be,ee]),B(""),Z("")}catch(ee){S(ee instanceof Error?ee.message:"Create failed")}finally{ge(!1)}}},le=ee=>{J(ee.id),de(ee.name),Ae(ee.command_template)},Ne=()=>{J(null),de(""),Ae("")},je=async()=>{if(!xe)return;const ee=G.trim(),be=oe.trim();if(!(!ee||!be)){Xe(!0);try{const he=await fx(xe,{name:ee,command_template:be});T(He=>He.map(Me=>Me.id===he.id?he:Me)),Ne()}catch(he){S(he instanceof Error?he.message:"Save failed")}finally{Xe(!1)}}},ue=async ee=>{if(await w({message:h("sessionSettings.aliases.deleteConfirm").replace("{name}",ee.name),danger:!0}))try{await px(ee.id),T(be=>be.filter(he=>he.id!==ee.id))}catch(be){S(be instanceof Error?be.message:"Delete failed")}};return v.jsxs("div",{className:"p-8",children:[v.jsx("h2",{className:"text-lg font-semibold text-warm-800 mb-1",children:h("sessionSettings.title")}),v.jsx("p",{className:"text-xs text-warm-400 mb-6",children:h("sessionSettings.description")}),v.jsxs("section",{className:"mb-7",children:[v.jsxs("h3",{className:"text-sm font-semibold text-warm-700 mb-2 flex items-center gap-1.5",children:[v.jsx(x1,{size:14}),h("sessionSettings.worktree.title")]}),v.jsxs("label",{className:"flex items-center gap-2 cursor-pointer select-none",children:[v.jsx("input",{type:"checkbox",checked:r,disabled:p||!b,onChange:ee=>ct(ee.target.checked),className:"rounded-md border-warm-300"}),v.jsx("span",{className:"text-sm text-warm-600",children:h("sessionSettings.worktree.label")})]}),v.jsx("p",{className:"mt-1 text-2xs ml-6",style:{color:"var(--color-text-muted)"},children:h("sessionSettings.worktree.hint")})]}),v.jsxs("section",{className:"mb-7",children:[v.jsxs("h3",{className:"text-sm font-semibold text-warm-700 mb-2 flex items-center gap-1.5",children:[v.jsx(SS,{size:14}),h("sessionSettings.fontSize.title")]}),v.jsxs("div",{className:"flex items-center gap-3",children:[v.jsx("input",{type:"range",min:wo,max:So,step:1,value:d,disabled:!b,onChange:ee=>Te(parseInt(ee.target.value,10)),className:"flex-1 max-w-xs","aria-label":h("sessionSettings.fontSize.label")}),v.jsx("input",{type:"number",min:wo,max:So,step:1,value:d,disabled:!b,onChange:ee=>Te(parseInt(ee.target.value,10)),className:"input text-sm w-20"}),v.jsx("span",{className:"text-xs text-warm-400",children:"px"})]}),v.jsx("p",{className:"mt-1 text-2xs",style:{color:"var(--color-text-muted)"},children:h("sessionSettings.fontSize.hint")})]}),v.jsxs("section",{children:[v.jsx("h3",{className:"text-sm font-semibold text-warm-700 mb-2",children:h("sessionSettings.tags.title")}),v.jsx("p",{className:"text-xs text-warm-400 mb-3",children:h("sessionSettings.tags.description")}),v.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[v.jsx("input",{type:"color",value:k,onChange:ee=>D(ee.target.value),className:"w-9 h-9 rounded-md cursor-pointer border border-warm-200",title:h("sessionSettings.tags.color")}),v.jsx("input",{type:"text",value:y,onChange:ee=>R(ee.target.value),onKeyDown:ee=>{ee.key==="Enter"&&(ee.preventDefault(),ze())},placeholder:h("sessionSettings.tags.namePlaceholder"),className:"input text-sm flex-1",maxLength:32}),v.jsxs("button",{type:"button",onClick:ze,disabled:!rt,className:"btn-primary text-sm py-1.5 px-3 inline-flex items-center gap-1",children:[v.jsx(Mn,{size:14}),h("sessionSettings.tags.add")]})]}),ye.length===0?v.jsx("p",{className:"text-xs text-warm-400 italic py-3",children:h("sessionSettings.tags.empty")}):v.jsx("ul",{className:"space-y-1.5",children:ye.map(ee=>{const be=z===ee.id;return v.jsx("li",{className:"flex items-center gap-2 px-3 py-2 rounded-lg border",style:{borderColor:"var(--color-border)"},children:be?v.jsxs(v.Fragment,{children:[v.jsx("input",{type:"color",value:K,onChange:he=>X(he.target.value),className:"w-7 h-7 rounded-md cursor-pointer border border-warm-200"}),v.jsx("input",{type:"text",value:P,onChange:he=>I(he.target.value),onKeyDown:he=>{he.key==="Enter"&&(he.preventDefault(),Be()),he.key==="Escape"&&Fe()},autoFocus:!0,className:"input text-sm flex-1",maxLength:32}),v.jsx("button",{type:"button",onClick:Be,disabled:Y||!P.trim(),className:"p-1.5 text-status-success hover:bg-status-success/10 rounded-md",title:h("sessionSettings.tags.save"),children:v.jsx(Do,{size:14})}),v.jsx("button",{type:"button",onClick:Fe,className:"p-1.5 text-warm-400 hover:bg-warm-100 rounded-md",title:h("sessionSettings.tags.cancel"),children:v.jsx(Ri,{size:14})})]}):v.jsxs(v.Fragment,{children:[v.jsx("span",{className:"w-4 h-4 rounded-full shrink-0 border",style:{backgroundColor:ee.color,borderColor:"rgba(0,0,0,0.08)"}}),v.jsx("span",{className:"text-sm text-warm-700 flex-1 truncate",children:ee.name}),v.jsx("button",{type:"button",onClick:()=>qe(ee),className:"p-1.5 text-warm-400 hover:text-warm-700 hover:bg-warm-100 rounded-md",title:h("sessionSettings.tags.edit"),children:v.jsx(ch,{size:14})}),v.jsx("button",{type:"button",onClick:()=>$e(ee),className:"p-1.5 text-warm-400 hover:text-status-error hover:bg-warm-100 rounded-md",title:h("sessionSettings.tags.delete"),children:v.jsx(cg,{size:14})})]})},ee.id)})})]}),v.jsxs("section",{className:"mt-7",children:[v.jsx("h3",{className:"text-sm font-semibold text-warm-700 mb-2",children:h("sessionSettings.aliases.title")}),v.jsx("p",{className:"text-xs text-warm-400 mb-3",children:h("sessionSettings.aliases.description")}),v.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[v.jsx("input",{type:"text",value:F,onChange:ee=>B(ee.target.value),placeholder:h("sessionSettings.aliases.namePlaceholder"),className:"input text-sm w-44",maxLength:64}),v.jsx("input",{type:"text",value:W,onChange:ee=>Z(ee.target.value),onKeyDown:ee=>{ee.key==="Enter"&&(ee.preventDefault(),Ie())},placeholder:h("sessionSettings.aliases.commandPlaceholder"),className:"input text-sm flex-1 font-mono",maxLength:1024}),v.jsxs("button",{type:"button",onClick:Ie,disabled:!St,className:"btn-primary text-sm py-1.5 px-3 inline-flex items-center gap-1",children:[v.jsx(Mn,{size:14}),h("sessionSettings.aliases.add")]})]}),Se.length===0?v.jsx("p",{className:"text-xs text-warm-400 italic py-3",children:h("sessionSettings.aliases.empty")}):v.jsx("ul",{className:"space-y-1.5",children:Se.map(ee=>{const be=xe===ee.id;return v.jsx("li",{className:"flex items-center gap-2 px-3 py-2 rounded-lg border",style:{borderColor:"var(--color-border)"},children:be?v.jsxs(v.Fragment,{children:[v.jsx("input",{type:"text",value:G,onChange:he=>de(he.target.value),className:"input text-sm w-44",maxLength:64}),v.jsx("input",{type:"text",value:oe,onChange:he=>Ae(he.target.value),onKeyDown:he=>{he.key==="Enter"&&(he.preventDefault(),je()),he.key==="Escape"&&Ne()},autoFocus:!0,className:"input text-sm flex-1 font-mono",maxLength:1024}),v.jsx("button",{type:"button",onClick:je,disabled:Oe||!G.trim()||!oe.trim(),className:"p-1.5 text-status-success hover:bg-status-success/10 rounded-md",title:h("common.save"),children:v.jsx(Do,{size:14})}),v.jsx("button",{type:"button",onClick:Ne,className:"p-1.5 text-warm-400 hover:bg-warm-100 rounded-md",title:h("common.cancel"),children:v.jsx(Ri,{size:14})})]}):v.jsxs(v.Fragment,{children:[v.jsx("span",{className:"text-sm text-warm-700 w-44 truncate",children:ee.name}),v.jsx("code",{className:"text-xs text-warm-500 flex-1 truncate font-mono",children:ee.command_template}),v.jsx("button",{type:"button",onClick:()=>le(ee),className:"p-1.5 text-warm-400 hover:text-warm-700 hover:bg-warm-100 rounded-md",title:h("common.edit"),children:v.jsx(ch,{size:14})}),v.jsx("button",{type:"button",onClick:()=>ue(ee),className:"p-1.5 text-warm-400 hover:text-status-error hover:bg-warm-100 rounded-md",title:h("common.delete"),children:v.jsx(cg,{size:14})})]})},ee.id)})})]}),v.jsxs("section",{className:"mt-7",children:[v.jsxs("h3",{className:"text-sm font-semibold text-warm-700 mb-2 flex items-center gap-1.5",children:[v.jsx(Jw,{size:14}),"IME 디버그 로그"]}),v.jsxs("label",{className:"flex items-center gap-2 cursor-pointer select-none",children:[v.jsx("input",{type:"checkbox",checked:l,disabled:c||!b,onChange:ee=>it(ee.target.checked),className:"rounded-md border-warm-300"}),v.jsx("span",{className:"text-sm text-warm-600",children:"한글 입력(IME) 진단 로그 기록"})]}),v.jsx("p",{className:"mt-1 text-2xs ml-6",style:{color:"var(--color-text-muted)"},children:"조합 창이 화면 좌상단에 뜨는 문제를 진단하기 위해 입력 시점 상태를 기록합니다. 데스크톱 앱에서만 동작하며, 로그는 앱 데이터 폴더의 ime-debug.log에 저장됩니다."})]}),s&&v.jsx("div",{className:"flex justify-end gap-3 mt-7",children:v.jsx("button",{type:"button",onClick:s,className:"btn-ghost text-sm",children:h("tunnel.close")})})]})}function vx(){return bt("/api/mcp/connection")}function _x({onClose:s}){const{t:h}=Tt(),{success:w,error:S}=un(),[M,O]=j.useState(null),[A,r]=j.useState(null);j.useEffect(()=>{let m=!1;return vx().then(b=>{m||O(b)}).catch(()=>{}),()=>{m=!0}},[]);const u=async(m,b)=>{try{await navigator.clipboard.writeText(b),r(m),setTimeout(()=>r(C=>C===m?null:C),1500),w(h("mcp.copied"))}catch{S(h("mcp.copyFailed"))}},d=M?JSON.stringify(M.config,null,2):"",g=({label:m,text:b})=>v.jsxs("button",{type:"button",onClick:()=>u(m,b),className:"btn-ghost text-xs flex items-center gap-1",children:[A===m?v.jsx(Do,{size:14}):v.jsx(_1,{size:14}),h("mcp.copy")]}),l={backgroundColor:"var(--color-bg-hover)",color:"var(--color-text-secondary)"};return v.jsxs("div",{className:"p-8",children:[v.jsx("h2",{className:"text-lg font-semibold text-warm-800 mb-1",children:h("mcp.title")}),v.jsx("p",{className:"text-xs text-warm-400 mb-6",children:h("mcp.description")}),M?v.jsxs(v.Fragment,{children:[v.jsxs("div",{className:"mb-5",children:[v.jsxs("div",{className:"flex items-center justify-between mb-2",children:[v.jsx("label",{className:"block text-sm font-medium text-warm-600",children:h("mcp.config.label")}),v.jsx(g,{label:"config",text:d})]}),v.jsx("pre",{className:"p-3 rounded-lg text-2xs font-mono overflow-x-auto",style:l,children:d})]}),v.jsxs("div",{className:"mb-5",children:[v.jsx("label",{className:"block text-sm font-medium text-warm-600 mb-1",children:h("mcp.commands.label")}),v.jsx("p",{className:"text-2xs text-warm-400 mb-3",children:h("mcp.commands.hint")}),v.jsx("div",{className:"space-y-3",children:M.commands.map(m=>v.jsxs("div",{children:[v.jsxs("div",{className:"flex items-center justify-between mb-1",children:[v.jsx("span",{className:"text-xs text-warm-500",children:m.label}),v.jsx(g,{label:`command:${m.id}`,text:m.command})]}),v.jsx("pre",{className:"p-3 rounded-lg text-2xs font-mono overflow-x-auto",style:l,children:m.command})]},m.id))})]}),v.jsx("p",{className:"text-2xs text-warm-400",children:h("mcp.tokenNote")})]}):v.jsx("p",{className:"text-sm text-warm-400",children:h("mcp.loading")}),s&&v.jsx("div",{className:"flex justify-end mt-6",children:v.jsx("button",{type:"button",onClick:s,className:"btn-ghost text-sm",children:h("mcp.close")})})]})}function gg({open:s,onClose:h}){const{t:w}=Tt(),[S,M]=j.useState("account");if(!s)return null;const O=[{id:"account",label:w("settings.tabs.account"),icon:j1},{id:"session",label:w("settings.tabs.session"),icon:Ah},{id:"tunnel",label:w("settings.tabs.tunnel"),icon:Ev},{id:"mcp",label:w("settings.tabs.mcp"),icon:sS}];return v.jsx(Ho,{open:s,onClose:h,size:"xl",children:v.jsx("div",{className:"bg-theme-card border border-theme-border rounded-2xl shadow-elevated overflow-hidden",children:v.jsxs("div",{className:"flex",style:{minHeight:460},children:[v.jsxs("aside",{className:"w-44 shrink-0 border-r flex flex-col",style:{borderColor:"var(--color-border)",backgroundColor:"var(--color-bg-hover)"},children:[v.jsx("div",{className:"px-4 pt-5 pb-3 text-xs font-semibold uppercase tracking-wider",style:{color:"var(--color-text-muted)"},children:w("settings.title")}),v.jsx("nav",{className:"flex flex-col",children:O.map(({id:A,label:r,icon:u})=>{const d=S===A;return v.jsxs("button",{type:"button",onClick:()=>M(A),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:[v.jsx(u,{size:14}),v.jsx("span",{children:r})]},A)})}),v.jsxs("div",{className:"px-4 py-3 mt-auto text-[11px] tracking-wide",style:{color:"var(--color-text-muted)"},children:["v","0.2.68"]})]}),v.jsxs("div",{className:"flex-1 min-w-0",children:[S==="account"&&v.jsx(lx,{onClose:h}),S==="session"&&v.jsx(gx,{onClose:h}),S==="tunnel"&&v.jsx(ax,{onClose:h}),S==="mcp"&&v.jsx(_x,{onClose:h})]})]})})})}const fh=["#55708F","#4F7A68","#9A783F","#A15F5A","#74658A","#925F73","#477B7D","#747A50"];function bx(s,h){let w=0;for(let S=0;S<s.length;S++)w=(w<<5)-w+s.charCodeAt(S)|0;return Math.abs(w)%h}function To(s){return s.color&&/^#[0-9a-f]{6}$/i.test(s.color)?s.color:fh[bx(s.id,fh.length)]}const vg=192,yx=88,Qa=8;function wx({project:s,anchorX:h,anchorY:w,onPick:S,onClose:M}){const O=j.useRef(null),[A,r]=j.useState({left:h,top:w}),u=To(s);return j.useLayoutEffect(()=>{const d=Math.min(Math.max(h,Qa),window.innerWidth-vg-Qa),g=Math.min(Math.max(w,Qa),window.innerHeight-yx-Qa);r({left:d,top:g})},[h,w]),j.useEffect(()=>{const d=l=>{var m;(m=O.current)!=null&&m.contains(l.target)||M()},g=l=>{l.key==="Escape"&&M()};return window.addEventListener("mousedown",d),window.addEventListener("keydown",g),()=>{window.removeEventListener("mousedown",d),window.removeEventListener("keydown",g)}},[M]),zi.createPortal(v.jsxs("div",{ref:O,role:"menu",className:"z-tooltip",style:{position:"fixed",left:A.left,top:A.top,width:vg,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:[v.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:8,marginBottom:8},children:fh.map(d=>{const g=s.color?d.toLowerCase()===s.color.toLowerCase():d===u&&!s.color;return v.jsx("button",{onClick:()=>S(d),"aria-label":d,style:{width:20,height:20,borderRadius:6,background:d,border:g?"2px solid var(--color-text-primary)":"2px solid transparent",cursor:"pointer",padding:0}},d)})}),v.jsx("button",{onClick:()=>S(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 Gv(s,h){return s instanceof Error&&s.message.trim()?s.message:typeof s=="string"&&s.trim()?s:h}function Sx(s){const h=s instanceof Error?s.message:typeof s=="string"?s:"";return/^ResizeObserver loop (?:limit exceeded|completed with undelivered notifications\.?)$/i.test(h.trim())}const xx={sm:"btn-icon-sm",md:"btn-icon-md",lg:"btn-icon-lg"},Cx={default:"",active:"btn-icon-active",danger:"btn-icon-danger"},Ei=j.forwardRef(function({label:h,size:w="md",variant:S="default",pressed:M,type:O="button",title:A,className:r,...u},d){return v.jsx("button",{ref:d,type:O,"aria-label":h,"aria-pressed":M,title:A??h,className:Tn("btn-icon",xx[w],Cx[S],r),...u})});function kx(s){return s==="executable"?Rv:s==="command"?Ov:Mv}function Ex({onLogout:s,authRequired:h,connected:w,onEvent:S,onClose:M,collapsed:O=!1,onToggleCollapsed:A}){var St;const[r,u]=j.useState([]),[d,g]=j.useState({}),[l,m]=j.useState(null),[b,C]=j.useState(!1),[p,o]=j.useState(null),[c,a]=j.useState([]),[f,y]=j.useState(!1),[R,k]=j.useState(null),[D,E]=j.useState(!1),[L,z]=j.useState(null),[H,P]=j.useState(!1),[I,K]=j.useState(null),[X,Y]=j.useState(null),$=ss(),U=xl(),{t:T,toggleLang:F}=Tt(),{theme:B,toggleTheme:W}=YS(),{enabled:Z,supported:ne,toggleNotification:ge}=Ll(),{error:xe,success:J,info:G,warning:de}=un(),{confirm:oe}=kr(),Ae=((St=$.pathname.match(/^\/projects\/([^/]+)/))==null?void 0:St[1])||null;j.useEffect(()=>{it(),Xe(),uh().then(z).catch(()=>{})},[]);async function Oe(){if(!H){P(!0);try{const Se=await uh();if(z(Se),Se.status==="running"&&Se.url){await navigator.clipboard.writeText(Se.url),J(T("tunnel.urlCopied"));return}const Ie=await zv(),le={status:"running",url:Ie.url};z(le);try{await navigator.clipboard.writeText(Ie.url),J(T("tunnel.urlCopied"))}catch{J(Ie.url)}}catch(Se){xe(Se instanceof Error?Se.message:T("tunnel.restartFailed"))}finally{P(!1)}}}function Xe(){zS().then(a).catch(()=>{})}const We=async Se=>{try{R?await PS(R.id,Se):await HS(Se),y(!1),k(null),Xe()}catch(Ie){xe(Ie instanceof Error?Ie.message:"Failed to save favorite")}},rt=async Se=>{try{await FS(Se)}catch(Ie){const le=Ie instanceof Error?Ie.message:T("favorites.launchFailed");xe(`${T("favorites.launchFailed")}: ${le}`)}},ye=async(Se,Ie)=>{if(Ie.preventDefault(),Ie.stopPropagation(),!!await oe({message:T("favorites.deleteConfirm"),danger:!0}))try{await IS(Se),a(le=>le.filter(Ne=>Ne.id!==Se))}catch(le){xe(le instanceof Error?le.message:"Failed to delete favorite")}},Te=(Se,Ie)=>{Ie.preventDefault(),Ie.stopPropagation(),k(Se),y(!0)};j.useEffect(()=>{const Se=()=>it();return window.addEventListener("projects:changed",Se),()=>window.removeEventListener("projects:changed",Se)},[]),j.useEffect(()=>{const Se=()=>ct();return window.addEventListener("review:changed",Se),()=>window.removeEventListener("review:changed",Se)},[]),j.useEffect(()=>S(Se=>{var Ie;if(Se.type==="project:status-changed"&&Se.projectId&&g(le=>({...le,[Se.projectId]:{running:Se.running??0,completed:Se.completed??0,total:Se.total??0,running_sessions:Se.running_sessions??0,running_discussions:Se.running_discussions??0}})),Se.type==="todo:status-changed"&&ct(),Se.type==="memory:ingest-finished"){const le=r.find(Me=>Me.id===Se.projectId),Ne=(le==null?void 0:le.name)??"",je=Se.sourceTitle?`“${Se.sourceTitle}”`:Se.sourceType??"",ue=Ne?`[${Ne}] `:"";if(Se.error){xe(`${ue}${T("wiki.ingest.toast.failed")}: ${Se.error}`,6e3);return}const ee=Se.created??0,be=Se.updated??0,he=Se.edgesAdded??0;if(ee+be+he>0){const Me=T("wiki.ingest.toast.success").replace("{source}",je).replace("{created}",String(ee)).replace("{updated}",String(be)).replace("{edges}",String(he));J(`${ue}${Me}`)}else(Ie=Se.skipped)!=null&&Ie.parseFailed?de(`${ue}${T("wiki.ingest.toast.parseFailed").replace("{source}",je)}`,5e3):G(`${ue}${T("wiki.ingest.toast.empty").replace("{source}",je)}`,4e3)}}),[S,r,T,xe,G,J,de]),j.useEffect(()=>{ct()},[]);function ct(){NS({hours:24}).then(Se=>m(Se.total_todos)).catch(()=>{})}function it(){Bv().then(Se=>{u(Se),Se.forEach(Ie=>{BS(Ie.id).then(le=>{g(Ne=>({...Ne,[Ie.id]:le}))}).catch(()=>{})})}).catch(()=>{})}const ze=()=>{M==null||M()},qe=async(Se,Ie)=>{await MS({name:Se,path:Ie}),C(!1),window.dispatchEvent(new Event("projects:changed"))},Fe=j.useCallback(async(Se,Ie)=>{const le=r.map(Me=>Me.id),Ne=le.indexOf(Se);if(Ne<0)return;const je=le.filter(Me=>Me!==Se),ue=Ie>Ne?Ie-1:Ie;if(ue===Ne)return;const ee=[...je.slice(0,ue),Se,...je.slice(ue)],be=r,he=new Map(r.map(Me=>[Me.id,Me])),He=ee.map(Me=>he.get(Me)).filter(Boolean);u(He);try{await OS(ee)}catch(Me){u(be),xe(Me instanceof Error?Me.message:"Failed to reorder projects")}},[r,xe]),Be=j.useRef(!1),$e=j.useCallback((Se,Ie)=>{if(Ie.button!==0||Ie.target.closest("button"))return;Ie.preventDefault();const Ne=Ie.clientX,je=Ie.clientY,ue=6;let ee=!1,be=null;const he=V=>{const ie=document.querySelectorAll("[data-workspace-item]");if(ie.length===0)return null;const Q=ie[0].getBoundingClientRect();if(V<Q.top)return 0;const ke=ie[ie.length-1].getBoundingClientRect();if(V>ke.bottom)return ie.length;for(let ce=0;ce<ie.length;ce++){const _e=ie[ce].getBoundingClientRect();if(V>=_e.top&&V<=_e.bottom){const Ee=_e.top+_e.height/2;return V<Ee?ce:ce+1}}return null},He=V=>{if(!ee){if(Math.hypot(V.clientX-Ne,V.clientY-je)<ue)return;ee=!0,K(Se)}const ie=he(V.clientY);ie!==be&&(be=ie,Y(ie))},Me=()=>{window.removeEventListener("mousemove",He),window.removeEventListener("mouseup",Ge),window.removeEventListener("keydown",se)},Ge=()=>{if(Me(),!ee)return;Be.current=!0,requestAnimationFrame(()=>{Be.current=!1});const V=be;K(null),Y(null),V!==null&&Fe(Se,V)},se=V=>{V.key==="Escape"&&(Me(),K(null),Y(null),ee&&(Be.current=!0,requestAnimationFrame(()=>{Be.current=!1})))};window.addEventListener("mousemove",He),window.addEventListener("mouseup",Ge),window.addEventListener("keydown",se)},[Fe]),lt=async(Se,Ie)=>{if(Ie.preventDefault(),Ie.stopPropagation(),!!await oe({message:T("projects.deleteConfirm"),danger:!0}))try{await jS(Se),u(le=>le.filter(Ne=>Ne.id!==Se)),window.dispatchEvent(new Event("projects:changed")),Ae===String(Se)&&U("/")}catch(le){xe(Gv(le,T("errors.projectDelete")))}},st=Se=>v.jsx("div",{className:"pointer-events-none absolute left-2 right-2 h-0.5 rounded-full",style:{backgroundColor:"var(--color-accent)",zIndex:10,...Se==="above"?{top:-1}:{bottom:-1}}});if(O){const Se=v.jsx("div",{className:"w-7 border-t my-1.5",style:{borderColor:"var(--color-border)"}});return v.jsxs("div",{className:"flex flex-col items-center h-full bg-theme-bg-secondary border-none py-3",children:[v.jsx(Ei,{onClick:A,label:T("sidebar.expand"),size:"lg",children:v.jsx(V1,{size:16})}),Se,v.jsx(es,{to:"/",onClick:ze,className:"relative flex items-center justify-center w-9 h-9 rounded-lg transition-colors hover:bg-theme-hover",style:$.pathname==="/"?{backgroundColor:"var(--color-bg-hover)",color:"var(--color-text-primary)"}:{color:"var(--color-text-tertiary)"},title:T("sidebar.home"),children:v.jsx(ng,{size:16})}),v.jsxs(es,{to:"/review",onClick:ze,className:"relative flex items-center justify-center w-9 h-9 rounded-lg transition-colors hover:bg-theme-hover mt-0.5",style:$.pathname==="/review"?{backgroundColor:"var(--color-bg-hover)",color:"var(--color-text-primary)"}:{color:"var(--color-text-tertiary)"},title:T("sidebar.review"),children:[v.jsx(sg,{size:16}),l!==null&&l>0&&v.jsx("span",{className:"absolute top-1 right-1 w-1.5 h-1.5 rounded-full",style:{backgroundColor:"var(--color-accent)"}})]}),v.jsx(es,{to:"/agenda",onClick:ze,className:"relative flex items-center justify-center w-9 h-9 rounded-lg transition-colors hover:bg-theme-hover mt-0.5",style:$.pathname==="/agenda"?{backgroundColor:"var(--color-bg-hover)",color:"var(--color-text-primary)"}:{color:"var(--color-text-tertiary)"},title:T("sidebar.agenda"),children:v.jsx(ig,{size:16})}),Se,v.jsx("div",{className:"flex-1 overflow-y-auto w-full flex flex-col items-center gap-1 py-1",children:r.map(Ie=>{const le=d[Ie.id],Ne=Ae===String(Ie.id),je=le?le.running+le.running_sessions+le.running_discussions:0,ue=je>0,ee=To(Ie);return v.jsxs(es,{to:`/projects/${Ie.id}`,onClick:ze,className:"relative flex items-center justify-center w-9 h-9 rounded-lg transition-colors hover:bg-theme-hover",style:Ne?{backgroundColor:"var(--color-bg-hover)"}:void 0,title:ue?`${Ie.name} · ${je} ${T("detail.live")}`:Ie.name,children:[Ne&&v.jsx("span",{className:"absolute left-0 top-1/4 bottom-1/4 w-[3px] rounded-r-full",style:{backgroundColor:ee}}),v.jsx("span",{className:`w-2.5 h-2.5 rounded-[3px] ${ue?"workspace-dot-pulse":""}`,style:{backgroundColor:ee,opacity:Ne||ue?1:.55}})]},Ie.id)})}),Se,v.jsx("span",{className:`w-1.5 h-1.5 rounded-full my-1 ${w?"bg-status-success":"bg-status-error"}`,title:w?T("detail.live"):"Disconnected"}),v.jsx(Ei,{onClick:W,label:T(B==="light"?"theme.dark":"theme.light"),size:"lg",children:B==="light"?v.jsx(rg,{size:16}):v.jsx(lg,{size:16})}),v.jsx(Ei,{onClick:()=>E(!0),label:T("settings.title"),size:"lg",children:v.jsx(ag,{size:16})}),v.jsx(gg,{open:D,onClose:()=>E(!1)})]})}return v.jsxs("div",{className:"flex flex-col h-full bg-theme-bg-secondary border-none",onDragStart:Se=>Se.preventDefault(),children:[v.jsxs("div",{className:"px-4 pt-5 pb-3 flex items-center justify-between",children:[v.jsxs(es,{to:"/",onClick:ze,className:"block font-mono text-[22px] leading-none whitespace-nowrap select-none",children:[v.jsxs("span",{className:"font-medium text-accent/50",children:[">","_ "]}),v.jsx("span",{className:"font-bold text-accent",children:"CLI"}),v.jsx("span",{className:"font-medium text-theme-text",children:"Trigger"})]}),v.jsx(Ei,{onClick:A,label:T("sidebar.collapse"),size:"sm",className:"hidden md:inline-flex flex-shrink-0",children:v.jsx(K1,{size:16})})]}),v.jsxs("nav",{className:"px-3 mb-2 space-y-0.5",children:[v.jsxs(es,{to:"/",onClick:ze,className:`relative flex items-center gap-3 px-3 py-2 rounded-lg text-sm transition-all duration-200 active:scale-95 ${$.pathname==="/"?"font-medium":""}`,style:$.pathname==="/"?{backgroundColor:"var(--color-bg-hover)",color:"var(--color-text-primary)",boxShadow:"var(--shadow-soft)"}:{color:"var(--color-text-tertiary)"},children:[$.pathname==="/"&&v.jsx("span",{className:"absolute left-0 top-1/4 bottom-1/4 w-[3px] rounded-r-full",style:{backgroundColor:"var(--color-accent)"}}),v.jsx(ng,{size:16}),T("sidebar.home")]}),v.jsxs(es,{to:"/review",onClick:ze,className:`relative flex items-center gap-3 px-3 py-2 rounded-lg text-sm transition-all duration-200 active:scale-95 ${$.pathname==="/review"?"font-medium":""}`,style:$.pathname==="/review"?{backgroundColor:"var(--color-bg-hover)",color:"var(--color-text-primary)",boxShadow:"var(--shadow-soft)"}:{color:"var(--color-text-tertiary)"},children:[$.pathname==="/review"&&v.jsx("span",{className:"absolute left-0 top-1/4 bottom-1/4 w-[3px] rounded-r-full",style:{backgroundColor:"var(--color-accent)"}}),v.jsx(sg,{size:16}),v.jsx("span",{className:"flex-1",children:T("sidebar.review")}),l!==null&&l>0&&v.jsx("span",{className:"text-2xs px-1.5 py-0.5 rounded-full font-medium",style:{backgroundColor:"var(--color-accent)",color:"white"},children:l})]}),v.jsxs(es,{to:"/agenda",onClick:ze,className:`relative flex items-center gap-3 px-3 py-2 rounded-lg text-sm transition-all duration-200 active:scale-95 ${$.pathname==="/agenda"?"font-medium":""}`,style:$.pathname==="/agenda"?{backgroundColor:"var(--color-bg-hover)",color:"var(--color-text-primary)",boxShadow:"var(--shadow-soft)"}:{color:"var(--color-text-tertiary)"},children:[$.pathname==="/agenda"&&v.jsx("span",{className:"absolute left-0 top-1/4 bottom-1/4 w-[3px] rounded-r-full",style:{backgroundColor:"var(--color-accent)"}}),v.jsx(ig,{size:16}),T("sidebar.agenda")]})]}),v.jsx("div",{className:"mx-4 border-t",style:{borderColor:"var(--color-border)"}}),v.jsxs("div",{className:"flex-1 overflow-y-auto px-3 pt-3",children:[v.jsxs("div",{className:"px-3 mb-2 flex items-center justify-between",children:[v.jsx("span",{className:"text-2xs font-semibold uppercase tracking-wider",style:{color:"var(--color-text-muted)"},children:T("sidebar.workspaces")}),v.jsx(Ei,{onClick:()=>C(!0),label:T("projects.new"),size:"sm",children:v.jsx(Mn,{size:14})})]}),v.jsx("div",{className:"space-y-0.5",children:r.map((Se,Ie)=>{const le=d[Se.id],Ne=Ae===String(Se.id),je=le?le.running+le.running_sessions+le.running_discussions:0,ue=je>0,ee=To(Se),be=I===Se.id,he=I!==null&&X===Ie,He=I!==null&&Ie===r.length-1&&X===r.length;return v.jsxs("div",{className:"relative","data-workspace-item":!0,children:[he&&st("above"),v.jsxs(es,{to:`/projects/${Se.id}`,draggable:!1,onDragStart:Me=>Me.preventDefault(),onClick:Me=>{if(Be.current){Me.preventDefault();return}ze()},onMouseDown:Me=>$e(Se.id,Me),onContextMenu:Me=>{Me.preventDefault(),o({project:Se,x:Me.clientX,y:Me.clientY})},className:`relative flex items-center gap-2.5 px-3 py-1.5 rounded-lg text-sm transition-all duration-200 hover:bg-theme-hover active:scale-95 group ${Ne?"font-medium":""} ${be?"opacity-50":""}`,style:Ne?{backgroundColor:"var(--color-bg-hover)",color:"var(--color-text-primary)",boxShadow:"var(--shadow-soft)",cursor:I?"grabbing":"pointer",userSelect:"none"}:{color:"var(--color-text-tertiary)",cursor:I?"grabbing":"pointer",userSelect:"none"},children:[Ne&&v.jsx("span",{className:"absolute left-0 top-1/4 bottom-1/4 w-[3px] rounded-r-full",style:{backgroundColor:ee}}),v.jsx("span",{className:`w-1.5 h-3 rounded-[2px] flex-shrink-0 ${ue?"workspace-dot-pulse":""}`,style:{backgroundColor:ee,opacity:Ne||ue?1:.55},title:ue?`${T("sidebar.workspaces")} · ${je} ${T("detail.live")}`:Se.name}),v.jsx("span",{className:"truncate flex-1",children:Se.name}),v.jsx(Ei,{onClick:Me=>lt(Se.id,Me),label:T("projects.delete"),size:"sm",variant:"danger",className:"flex-shrink-0 opacity-0 group-hover:opacity-100 focus-visible:opacity-100",children:v.jsx(Ri,{size:12})})]}),He&&st("below")]},Se.id)})})]}),b&&v.jsx(ix,{onSubmit:(Se,Ie)=>qe(Se,Ie),onCancel:()=>C(!1)}),v.jsxs("div",{className:"px-3 pt-3 pb-2 border-t",style:{borderColor:"var(--color-border)"},children:[v.jsxs("div",{className:"px-3 mb-2 flex items-center justify-between",children:[v.jsx("span",{className:"text-2xs font-semibold uppercase tracking-wider",style:{color:"var(--color-text-muted)"},children:T("sidebar.favorites")}),v.jsx(Ei,{onClick:()=>{k(null),y(!0)},label:T("favorites.add"),size:"sm",children:v.jsx(Mn,{size:14})})]}),v.jsx("div",{className:"space-y-0.5 max-h-48 overflow-y-auto",children:c.map(Se=>{const Ie=kx(Se.type);return v.jsxs("button",{onClick:()=>rt(Se.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:Se.target,children:[v.jsx(Ie,{size:14,className:"flex-shrink-0"}),v.jsx("span",{className:"truncate flex-1 text-left",children:Se.name}),v.jsx("span",{onClick:le=>Te(Se,le),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:T("favorites.edit"),children:v.jsx(Q1,{size:12})}),v.jsx("span",{onClick:le=>ye(Se.id,le),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:T("favorites.delete"),children:v.jsx(Ri,{size:12})})]},Se.id)})})]}),f&&v.jsx(rx,{initial:R??void 0,onSubmit:We,onCancel:()=>{y(!1),k(null)}}),p&&v.jsx(wx,{project:p.project,anchorX:p.x,anchorY:p.y,onPick:async Se=>{try{const Ie=await AS(p.project.id,{color:Se});u(le=>le.map(Ne=>Ne.id===Ie.id?{...Ne,color:Ie.color}:Ne)),window.dispatchEvent(new Event("projects:changed"))}catch(Ie){xe(Ie instanceof Error?Ie.message:"Failed to update color")}o(null)},onClose:()=>o(null)}),v.jsx(gg,{open:D,onClose:()=>E(!1)}),v.jsx("div",{className:"px-3 pb-4 pt-2",style:{borderTop:"1px solid var(--color-border)"},children:v.jsxs("div",{className:"flex items-center gap-1 px-1",children:[v.jsx("span",{className:`w-1.5 h-1.5 rounded-full flex-shrink-0 mr-1 ${w?"bg-status-success":"bg-status-error"}`,title:w?T("detail.live"):"Disconnected"}),v.jsx(Ei,{onClick:W,label:T(B==="light"?"theme.dark":"theme.light"),children:B==="light"?v.jsx(rg,{size:16}):v.jsx(lg,{size:16})}),v.jsx(Ei,{onClick:F,label:T("lang.toggle"),className:"text-xs font-medium",children:T("lang.toggle")}),ne&&v.jsx(Ei,{onClick:ge,label:"Notification"in window&&Notification.permission==="denied"?T("notification.blocked"):T("notification.toggle"),variant:Z?"active":"default",pressed:Z,children:Z?v.jsx(Xw,{size:16}):v.jsx(Yw,{size:16})}),v.jsx(Ei,{onClick:Oe,disabled:H,label:T("tunnel.start"),variant:(L==null?void 0:L.status)==="running"?"active":"default",pressed:(L==null?void 0:L.status)==="running",title:(L==null?void 0:L.status)==="running"&&L.url?`${L.url} — ${T("tunnel.urlCopied")}`:T(H?"tunnel.starting":"tunnel.start"),children:v.jsx(Ev,{size:16})}),v.jsx(Ei,{onClick:()=>E(!0),label:T("settings.title"),children:v.jsx(ag,{size:16})}),h&&v.jsx(Ei,{onClick:s,label:T("projects.logout"),variant:"danger",className:"ml-auto",children:v.jsx(H1,{size:16})})]})})]})}function Lx({children:s,onLogout:h,authRequired:w,connected:S,onEvent:M}){const[O,A]=j.useState(!1),{t:r}=Tt(),[u,d]=j.useState(()=>localStorage.getItem("sidebarCollapsed")==="1"),g=()=>{d(l=>{const m=!l;return localStorage.setItem("sidebarCollapsed",m?"1":"0"),m})};return v.jsxs("div",{className:"flex h-screen bg-theme-bg",children:[v.jsx("aside",{"data-app-sidebar":!0,className:`
402
+ */const ES=[["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"}]],LS=Qe("zoom-out",ES),ug=8;function RS({onLogin:s,onChangePassword:h}){const[w,S]=j.useState(""),[M,O]=j.useState(""),[A,r]=j.useState(""),[u,d]=j.useState(!1),[g,l]=j.useState(!1),[m,b]=j.useState(!1),[C,p]=j.useState(""),[o,c]=j.useState(!1),{t:a,toggleLang:f}=Tt(),y=u&&M.length>0&&M.length<ug,R=u&&A.length>0&&M!==A,k=u?!!w&&M.length>=ug&&M===A:!!w,D=()=>{d(L=>!L),O(""),r(""),p("")},E=async L=>{if(L.preventDefault(),!(!k||o)){p(""),c(!0);try{u?await h(w,M,A,m):await s(w,m)}catch(z){p(u&&z instanceof Error&&z.message?z.message:a("login.error"))}finally{c(!1)}}};return v.jsxs("div",{className:"min-h-screen bg-theme-bg flex items-center justify-center px-4 relative",children:[v.jsx("button",{onClick:f,className:"lang-toggle absolute top-6 right-6",children:a("lang.toggle")}),v.jsxs("div",{className:"w-full max-w-sm",children:[v.jsxs("div",{className:"text-center mb-10",children:[v.jsx("div",{className:"inline-flex items-center justify-center w-16 h-16 rounded-2xl bg-accent/10 mb-5",children:v.jsx(Ah,{size:32,className:"text-accent"})}),v.jsx("h1",{className:"text-2xl font-semibold text-theme-text",children:a("login.title")}),v.jsx("p",{className:"text-theme-muted text-sm mt-2",children:a("login.subtitle")})]}),v.jsx("form",{onSubmit:E,children:v.jsxs("div",{className:"card p-8",children:[v.jsx("label",{className:"block text-sm font-medium text-theme-text-secondary mb-2",children:a(u?"account.oldPassword":"login.password")}),v.jsx("input",{type:"password",value:w,onChange:L=>S(L.target.value),placeholder:"*************",className:"input-field text-base",autoComplete:"current-password",autoFocus:!0}),u&&v.jsxs(v.Fragment,{children:[v.jsx("label",{className:"block text-sm font-medium text-theme-text-secondary mb-2 mt-4",children:a("account.newPassword")}),v.jsx("input",{type:"password",value:M,onChange:L=>O(L.target.value),className:"input-field text-base",autoComplete:"new-password","aria-label":a("account.newPassword")}),y&&v.jsx("p",{className:"mt-1 text-2xs text-status-error",children:a("account.tooShort")}),v.jsx("label",{className:"block text-sm font-medium text-theme-text-secondary mb-2 mt-4",children:a("account.confirm")}),v.jsx("input",{type:"password",value:A,onChange:L=>r(L.target.value),className:"input-field text-base",autoComplete:"new-password","aria-label":a("account.confirm")}),R&&v.jsx("p",{className:"mt-1 text-2xs text-status-error",children:a("account.mismatch")})]}),C&&v.jsx("div",{className:"mt-4 py-2.5 px-4 bg-status-error/5 rounded-xl text-sm text-status-error",children:C}),v.jsxs("label",{className:"flex items-center gap-2 mt-5 text-sm text-theme-text-secondary cursor-pointer select-none",children:[v.jsx("input",{type:"checkbox",checked:m,onChange:L=>b(L.target.checked),className:"accent-accent w-4 h-4"}),a("login.rememberMe")]}),v.jsx("button",{type:"submit",disabled:!k||o,className:"btn-primary w-full mt-6 py-3",children:a(o?"login.loading":u?"login.changeSubmit":"login.submit")})]})}),v.jsxs("div",{className:"mt-4 flex items-center justify-center gap-5 text-xs",children:[v.jsx("button",{type:"button",onClick:D,className:"text-theme-muted hover:text-theme-text underline-offset-2 hover:underline",children:a(u?"login.backToLogin":"login.changePassword")}),v.jsx("button",{type:"button",onClick:()=>l(L=>!L),className:"text-theme-muted hover:text-theme-text underline-offset-2 hover:underline",children:a("login.forgot")})]}),g&&v.jsx("div",{className:"mt-3 px-4 py-3 rounded-xl text-xs text-theme-text-tertiary border leading-relaxed",children:a("login.forgotHint")}),v.jsx("div",{className:"mt-6 text-center text-xs text-theme-text-tertiary",children:a("login.footer")}),v.jsx("div",{className:"mt-4 px-2 py-3 rounded-xl text-xs text-theme-text-tertiary border leading-relaxed text-center",children:a("login.disclaimer")})]})]})}const hg=8;function DS({onSetup:s}){const[h,w]=j.useState(""),[S,M]=j.useState(""),[O,A]=j.useState(""),[r,u]=j.useState(!1),{t:d,toggleLang:g}=Tt(),l=h.length>0&&h.length<hg,m=S.length>0&&h!==S,b=h.length>=hg&&h===S&&!r,C=async p=>{if(p.preventDefault(),!!b){A(""),u(!0);try{await s(h,S)}catch(o){A(o instanceof Error&&o.message?o.message:d("setup.error"))}finally{u(!1)}}};return v.jsxs("div",{className:"min-h-screen bg-theme-bg flex items-center justify-center px-4 relative",children:[v.jsx("button",{onClick:g,className:"lang-toggle absolute top-6 right-6",children:d("lang.toggle")}),v.jsxs("div",{className:"w-full max-w-sm",children:[v.jsxs("div",{className:"text-center mb-10",children:[v.jsx("div",{className:"inline-flex items-center justify-center w-16 h-16 rounded-2xl bg-accent/10 mb-5",children:v.jsx(Ah,{size:32,className:"text-accent"})}),v.jsx("h1",{className:"text-2xl font-semibold text-theme-text",children:d("setup.title")}),v.jsx("p",{className:"text-theme-muted text-sm mt-2",children:d("setup.subtitle")})]}),v.jsx("form",{onSubmit:C,children:v.jsxs("div",{className:"card p-8",children:[v.jsx("label",{className:"block text-sm font-medium text-theme-text-secondary mb-2",children:d("setup.password")}),v.jsx("input",{type:"password",value:h,onChange:p=>w(p.target.value),placeholder:"*************",className:"input-field text-base",autoFocus:!0}),l&&v.jsx("p",{className:"mt-1 text-2xs text-status-error",children:d("setup.tooShort")}),v.jsx("label",{className:"block text-sm font-medium text-theme-text-secondary mb-2 mt-5",children:d("setup.confirm")}),v.jsx("input",{type:"password",value:S,onChange:p=>M(p.target.value),placeholder:"*************",className:"input-field text-base"}),m&&v.jsx("p",{className:"mt-1 text-2xs text-status-error",children:d("setup.mismatch")}),O&&v.jsx("div",{className:"mt-4 py-2.5 px-4 bg-status-error/5 rounded-xl text-sm text-status-error",children:O}),v.jsx("button",{type:"submit",disabled:!b,className:"btn-primary w-full mt-6 py-3",children:d(r?"setup.loading":"setup.submit")})]})}),v.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 TS(s){return nt("/api/projects/browse",{initialPath:s})}function Z2(s){return nt("/api/projects/open-folder",{path:s})}function Bv(){return bt("/api/projects")}function ek(s){return bt(`/api/projects/${s}`)}function MS(s){return nt("/api/projects",s)}function tk(s){return bt(`/api/projects/${s}/svn-detect`)}function AS(s,h){return Di(`/api/projects/${s}`,h)}function ik(s,h){const w=h?`?todoId=${encodeURIComponent(h)}`:"";return bt(`/api/projects/${s}/debug-logs${w}`)}function jS(s){return Cr(`/api/projects/${s}`)}function OS(s){return nt("/api/projects/reorder",{ids:s})}function sk(s){return nt(`/api/projects/${s}/start`)}function nk(s){return nt(`/api/projects/${s}/stop`)}function BS(s){return bt(`/api/projects/${s}/status`)}function rk(){return bt("/api/active-work")}function ok(s){return nt(`/api/projects/${s}/check-git`)}function ak(s,h){const w=h?`?worktreePath=${encodeURIComponent(h)}`:"";return bt(`/api/projects/${s}/git-status${w}`)}function lk(s,h=0,w=50,S){const M=new URLSearchParams({skip:String(h),limit:String(w)});return bt(`/api/projects/${s}/git-log?${M}`)}function ck(s,h){return bt(`/api/projects/${s}/git-refs`)}function uk(s,h,w){return nt(`/api/projects/${s}/git-stage`,{files:h,worktreePath:w})}function hk(s,h,w){return nt(`/api/projects/${s}/git-unstage`,{files:h,worktreePath:w})}function dk(s,h,w){return nt(`/api/projects/${s}/git-ignore`,{path:h,worktreePath:w})}function fk(s,h,w){return nt(`/api/projects/${s}/git-commit`,{message:h,worktreePath:w})}function pk(s,h,w){return nt(`/api/projects/${s}/git-pull`,{remote:h,branch:w})}function mk(s,h){return nt(`/api/projects/${s}/git-push`,h||{})}function gk(s){return bt(`/api/projects/${s}/git-remotes`)}function vk(s,h,w){return nt(`/api/projects/${s}/git-fetch`,{remote:h,prune:w})}function _k(s,h,w){return nt(`/api/projects/${s}/git-branch`,{name:h,startPoint:w})}function bk(s,h,w){return nt(`/api/projects/${s}/git-branch-delete`,{name:h,force:w})}function yk(s,h){return nt(`/api/projects/${s}/git-checkout`,{branch:h})}function wk(s,h){return nt(`/api/projects/${s}/git-merge`,{branch:h})}function Sk(s,h,w,S){return nt(`/api/projects/${s}/git-conflict-resolve`,{file:h,side:w,worktreePath:S})}function xk(s,h,w){const S=w?`&worktreePath=${encodeURIComponent(w)}`:"";return bt(`/api/projects/${s}/git-conflict-file?file=${encodeURIComponent(h)}${S}`)}function Ck(s,h,w,S){return nt(`/api/projects/${s}/git-conflict-file`,{file:h,content:w,worktreePath:S})}function kk(s){return nt(`/api/projects/${s}/git-conflict-continue`)}function Ek(s){return nt(`/api/projects/${s}/git-conflict-abort`)}function Lk(s,h){return nt(`/api/projects/${s}/git-stash`,{message:h})}function Rk(s,h){return nt(`/api/projects/${s}/git-stash-pop`,{index:h})}function Dk(s){return bt(`/api/projects/${s}/git-stash-list`)}function Tk(s,h,w,S){return nt(`/api/projects/${s}/git-discard`,{files:h,all:w,worktreePath:S})}function Mk(s,h,w,S){return nt(`/api/projects/${s}/git-tag`,{name:h,message:w,commit:S})}function Ak(s,h,w){return nt(`/api/projects/${s}/git-branch-rename`,{oldName:h,newName:w})}function jk(s,h){return nt(`/api/projects/${s}/git-rebase`,{onto:h})}function Ok(s,h){return nt(`/api/projects/${s}/git-revert`,{commit:h})}function Bk(s,h){return nt(`/api/projects/${s}/git-cherry-pick`,{commit:h})}function Nk(s,h,w){return nt(`/api/projects/${s}/git-reset`,{commit:h,mode:w})}function zk(s,h,w,S){const M=new URLSearchParams;return h&&M.set("file",h),w&&M.set("staged","true"),S&&M.set("worktreePath",S),bt(`/api/projects/${s}/git-diff?${M}`)}function Hk(s,h){const w=new URLSearchParams({hash:h});return bt(`/api/projects/${s}/git-commit-files?${w}`)}function Pk(s,h,w){const S=new URLSearchParams({hash:h});return w&&S.set("file",w),bt(`/api/projects/${s}/git-commit-diff?${S}`)}function Ik(s){return bt(`/api/projects/${s}/worktrees`)}function Fk(s,h,w){return nt(`/api/projects/${s}/worktree-cleanup`,{worktreePath:h,branchName:w})}function Nv(s){const h=new URLSearchParams;s.hours!==void 0&&h.set("hours",String(s.hours)),s.statuses&&s.statuses.length>0&&h.set("statuses",s.statuses.join(","));const w=h.toString();return w?`?${w}`:""}function Uk(s={}){return bt(`/api/review/queue${Nv(s)}`)}function NS(s={}){return bt(`/api/review/summary${Nv(s)}`)}function $k(s){return bt(`/api/review/diff/${encodeURIComponent(s)}`)}function Wk(s,h){return bt(`/api/review/diff/${encodeURIComponent(s)}/file?path=${encodeURIComponent(h)}`)}function zS(){return bt("/api/favorites")}function HS(s){return nt("/api/favorites",s)}function PS(s,h){return Di(`/api/favorites/${s}`,h)}function IS(s){return Cr(`/api/favorites/${s}`)}function FS(s){return nt(`/api/favorites/${s}/launch`)}function US(s){return nt("/api/favorites/browse-file",{initialPath:s})}function uh(){return bt("/api/tunnel/status")}function $S(){return bt("/api/tunnel/config")}function WS(s){return Di("/api/tunnel/config",s)}function zv(s){return nt("/api/tunnel/start",{})}function qS(){return nt("/api/tunnel/stop")}const Hv=j.createContext({theme:"light",toggleTheme:()=>{}});function GS(){const[s,h]=j.useState(()=>{const S=localStorage.getItem("theme");return S==="light"||S==="dark"?S:window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light"});j.useEffect(()=>{document.documentElement.setAttribute("data-theme",s),localStorage.setItem("theme",s)},[s]);const w=j.useCallback(()=>{h(S=>S==="light"?"dark":"light")},[]);return{theme:s,toggleTheme:w}}function YS(){return j.useContext(Hv)}const Pv=j.createContext({enabled:!1,supported:!1,toggleNotification:()=>{},sendNotification:()=>{}});function KS(){const s="Notification"in window,[h,w]=j.useState(()=>s?localStorage.getItem("clitrigger-notifications")==="on"&&Notification.permission==="granted":!1),S=j.useRef(h);j.useEffect(()=>{S.current=h},[h]);const M=j.useCallback(async()=>{if(s)if(S.current)localStorage.setItem("clitrigger-notifications","off"),w(!1);else{if(Notification.permission==="denied"||Notification.permission==="default"&&await Notification.requestPermission()!=="granted")return;localStorage.setItem("clitrigger-notifications","on"),w(!0)}},[s]),O=j.useCallback((A,r,u)=>{if(!S.current)return;const d=new Notification(A,{body:r});d.onclick=()=>{u==null||u();const g=window.electronAPI;g!=null&&g.windowFocus?g.windowFocus():window.focus(),d.close()}},[]);return{enabled:h,supported:s,toggleNotification:M,sendNotification:O}}function Ll(){return j.useContext(Pv)}let XS=0;const Iv=j.createContext(null);function VS({children:s}){const[h,w]=j.useState([]),S=j.useRef(new Map),M=j.useRef(new Map),O=j.useRef(new Map),A=j.useCallback(b=>{w(o=>o.filter(c=>c.id!==b));const C=O.current.get(b);C&&M.current.get(C)===b&&M.current.delete(C),O.current.delete(b);const p=S.current.get(b);p&&(clearTimeout(p),S.current.delete(b))},[]),r=j.useCallback((b,C="info",p=3500)=>{const o=`${C}:${b}`,c=M.current.get(o);if(c)return c;const a=`toast-${++XS}`;M.current.set(o,a),O.current.set(a,o),w(y=>[...y,{id:a,message:b,type:C,duration:p}]);const f=setTimeout(()=>A(a),p);return S.current.set(a,f),a},[A]),u=j.useCallback((b,C)=>r(b,"success",C),[r]),d=j.useCallback((b,C)=>r(b,"error",C),[r]),g=j.useCallback((b,C)=>r(b,"info",C),[r]),l=j.useCallback((b,C)=>r(b,"warning",C),[r]);j.useEffect(()=>()=>{S.current.forEach(clearTimeout),S.current.clear(),M.current.clear(),O.current.clear()},[]);const m=j.useMemo(()=>({toasts:h,show:r,success:u,error:d,info:g,warning:l,dismiss:A}),[h,r,u,d,g,l,A]);return j.createElement(Iv.Provider,{value:m},s)}function un(){const s=j.useContext(Iv);if(!s)throw new Error("useToast must be used within ToastProvider");return s}function Tn(...s){return s.filter(Boolean).join(" ")}const JS={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 Ho({open:s,onClose:h,size:w="md",position:S="center",disableEscClose:M=!1,disableBackdropClose:O=!1,children:A}){const r=j.useRef(null);return j.useEffect(()=>{if(!s||M)return;const u=d=>{d.key==="Escape"&&h()};return document.addEventListener("keydown",u),()=>document.removeEventListener("keydown",u)},[s,M,h]),s?zi.createPortal(v.jsx("div",{ref:r,className:Tn("fixed inset-0 bg-black/50 backdrop-blur-sm z-modal flex",S==="center"?"items-center justify-center p-4":"items-start justify-center px-4 pt-[20vh]"),onClick:u=>{!O&&u.target===r.current&&h()},children:v.jsx("div",{className:Tn("w-full",JS[w]),children:A})}),document.body):null}const QS={default:"btn",primary:"btn-primary",secondary:"btn-secondary",danger:"btn-danger",ghost:"btn-ghost"},ZS={sm:"btn-sm",md:"btn-md",lg:"btn-lg"},Li=j.forwardRef(function({variant:h="default",size:w,type:S="button",className:M,...O},A){return v.jsx("button",{ref:A,type:S,className:Tn(QS[h],w&&ZS[w],M),...O})}),Fv=j.createContext(null);let dg=0;function ex({children:s}){const[h,w]=j.useState(null),S=j.useRef(null),M=j.useCallback(d=>{const g=S.current;g&&(g.kind==="confirm"?g.resolve(!1):g.resolve(null)),S.current=d,w(d)},[]),O=j.useCallback(()=>{S.current=null,w(null)},[]),A=j.useCallback(d=>{const g=typeof d=="string"?{message:d}:d;return new Promise(l=>{M({id:++dg,kind:"confirm",options:g,resolve:l})})},[M]),r=j.useCallback(d=>{const g=typeof d=="string"?{message:d}:d;return new Promise(l=>{M({id:++dg,kind:"prompt",options:g,resolve:l})})},[M]),u=j.useMemo(()=>({confirm:A,prompt:r}),[A,r]);return v.jsxs(Fv.Provider,{value:u,children:[s,h&&v.jsx(tx,{dialog:h,onSettled:O},h.id)]})}function tx({dialog:s,onSettled:h}){const{t:w}=Tt(),[S,M]=j.useState(s.kind==="prompt"?s.options.initialValue??"":""),O=()=>{s.kind==="confirm"?s.resolve(!1):s.resolve(null),h()},A=()=>{s.kind==="confirm"?s.resolve(!0):s.resolve(S),h()},r=s.kind==="confirm"&&!!s.options.danger,u=s.kind==="confirm"&&s.options.confirmLabel||w("common.ok"),d=s.kind==="confirm"&&s.options.cancelLabel||w("common.cancel"),g=v.jsxs("div",{className:"mt-4 flex justify-end gap-2",children:[v.jsx(Li,{size:"sm",onClick:O,autoFocus:r,children:d}),v.jsx(Li,{variant:r?"danger":"primary",size:"sm",type:s.kind==="prompt"?"submit":"button",onClick:s.kind==="prompt"?void 0:A,autoFocus:s.kind==="confirm"&&!r,children:u})]});return v.jsx(Ho,{open:!0,onClose:O,size:"sm",children:v.jsxs("div",{className:"bg-theme-card border border-theme-border rounded-2xl shadow-elevated p-5",children:[s.options.title&&v.jsx("div",{className:"text-sm font-semibold text-theme-text mb-2",children:s.options.title}),v.jsx("p",{className:"text-sm text-theme-text-secondary whitespace-pre-line break-words",children:s.options.message}),s.kind==="prompt"?v.jsxs("form",{onSubmit:l=>{l.preventDefault(),A()},children:[v.jsx("input",{autoFocus:!0,value:S,onChange:l=>M(l.target.value),placeholder:s.options.placeholder,className:"input-field mt-3"}),g]}):g]})})}function kr(){const s=j.useContext(Fv);if(!s)throw new Error("useDialog must be used within DialogProvider");return s}function ix({onSubmit:s,onCancel:h}){const[w,S]=j.useState(""),[M,O]=j.useState(""),[A,r]=j.useState(!1),[u,d]=j.useState(!1),[g,l]=j.useState(""),{t:m}=Tt(),b=async p=>{if(p.preventDefault(),!(!w.trim()||!M.trim())){l(""),d(!0);try{await s(w.trim(),M.trim())}catch(o){const c=o instanceof Error?o.message:String(o);l(c||m("form.createError"))}finally{d(!1)}}},C=async()=>{r(!0);try{const p=await TS(M||void 0);p.path&&O(p.path)}catch{}r(!1)};return v.jsx(Ho,{open:!0,onClose:h,size:"md",children:v.jsxs("div",{className:"bg-theme-card border border-theme-border rounded-2xl shadow-elevated p-8",children:[v.jsx("h2",{className:"text-lg font-semibold text-warm-800 mb-6",children:m("form.newProject")}),v.jsxs("form",{onSubmit:b,children:[v.jsxs("div",{className:"mb-5",children:[v.jsx("label",{className:"block text-sm font-medium text-warm-600 mb-2",children:m("form.projectName")}),v.jsx("input",{type:"text",placeholder:"my-project",value:w,onChange:p=>S(p.target.value),className:"input-field",autoFocus:!0})]}),v.jsxs("div",{className:"mb-8",children:[v.jsx("label",{className:"block text-sm font-medium text-warm-600 mb-2",children:m("form.folderPath")}),v.jsxs("div",{className:"flex gap-2",children:[v.jsx("input",{type:"text",placeholder:"C:/Projects/my-project",value:M,onChange:p=>O(p.target.value),className:"input-field text-sm flex-1"}),v.jsx("button",{type:"button",onClick:C,disabled:A,className:"btn-ghost text-sm px-3 shrink-0",title:m("browse.title"),children:A?v.jsx(lh,{size:16,className:"animate-spin"}):v.jsx(Dv,{size:16})})]})]}),g&&v.jsx("p",{className:"text-sm mb-4",style:{color:"var(--color-danger, #ef4444)"},children:g}),v.jsxs("div",{className:"flex justify-end gap-3",children:[v.jsx("button",{type:"button",onClick:h,className:"btn-ghost text-sm",children:m("form.cancel")}),v.jsx("button",{type:"submit",disabled:!w.trim()||!M.trim()||u,className:"btn-primary text-sm",children:m(u?"form.creating":"form.create")})]})]})]})})}const sx=[{value:"executable",icon:Rv},{value:"command",icon:Ov},{value:"url",icon:Mv}];function nx(s){const h=[],w=/"([^"]*)"|(\S+)/g;let S;for(;(S=w.exec(s))!==null;)h.push(S[1]!==void 0?S[1]:S[2]);return h}function fg(s){if(!s)return"";try{const h=JSON.parse(s);if(Array.isArray(h))return h.map(w=>typeof w=="string"&&/\s/.test(w)?`"${w}"`:String(w)).join(" ")}catch{}return""}function rx({initial:s,onSubmit:h,onCancel:w}){const{t:S}=Tt(),[M,O]=j.useState((s==null?void 0:s.name)??""),[A,r]=j.useState((s==null?void 0:s.type)??"executable"),[u,d]=j.useState((s==null?void 0:s.target)??""),[g,l]=j.useState(fg((s==null?void 0:s.args)??null)),[m,b]=j.useState((s==null?void 0:s.cwd)??""),[C,p]=j.useState(!1);j.useEffect(()=>{O((s==null?void 0:s.name)??""),r((s==null?void 0:s.type)??"executable"),d((s==null?void 0:s.target)??""),l(fg((s==null?void 0:s.args)??null)),b((s==null?void 0:s.cwd)??"")},[s]);const[o,c]=j.useState(!1),a=A==="executable",f=async()=>{c(!0);try{const{path:H}=await US(u||void 0);if(!H)return;if(d(H),!M.trim()){const P=H.replace(/\\/g,"/").split("/").pop()||"";O(P.replace(/\.[^.]+$/,""))}}catch{}finally{c(!1)}},y=!!s,R=M.trim(),k=u.trim(),D=A!=="url"||/^https?:\/\//i.test(k),E=!!R&&!!k&&D&&!C,L=async H=>{if(H.preventDefault(),!!E){p(!0);try{const P={name:R,type:A,target:k,args:A==="executable"&&g.trim()?nx(g.trim()):null,cwd:A!=="url"&&m.trim()?m.trim():null};await h(P)}finally{p(!1)}}},z=S(A==="executable"?"favorites.form.targetHint.executable":A==="command"?"favorites.form.targetHint.command":"favorites.form.targetHint.url");return v.jsx(Ho,{open:!0,onClose:w,size:"md",children:v.jsxs("div",{className:"bg-theme-card border border-theme-border rounded-2xl shadow-elevated p-8",children:[v.jsx("h2",{className:"text-lg font-semibold text-warm-800 mb-6",children:S(y?"favorites.form.title.edit":"favorites.form.title.create")}),v.jsxs("form",{onSubmit:L,children:[v.jsxs("div",{className:"mb-5",children:[v.jsx("label",{className:"block text-sm font-medium text-warm-600 mb-2",children:S("favorites.form.type")}),v.jsx("div",{className:"grid grid-cols-3 gap-2",children:sx.map(({value:H,icon:P})=>v.jsxs("button",{type:"button",onClick:()=>r(H),className:"flex items-center justify-center gap-2 px-3 py-2 rounded-lg text-xs font-medium transition-all border",style:A===H?{backgroundColor:"var(--color-accent)",color:"white",borderColor:"var(--color-accent)"}:{color:"var(--color-text-tertiary)",borderColor:"var(--color-border)"},children:[v.jsx(P,{size:14}),S(`favorites.types.${H}`)]},H))})]}),v.jsxs("div",{className:"mb-5",children:[v.jsx("label",{className:"block text-sm font-medium text-warm-600 mb-2",children:S("favorites.form.name")}),v.jsx("input",{type:"text",value:M,onChange:H=>O(H.target.value),className:"input-field",autoFocus:!0})]}),v.jsxs("div",{className:"mb-5",children:[v.jsx("label",{className:"block text-sm font-medium text-warm-600 mb-2",children:S("favorites.form.target")}),v.jsxs("div",{className:"flex gap-2",children:[v.jsx("input",{type:"text",value:u,onChange:H=>d(H.target.value),className:"input-field text-sm font-mono flex-1",placeholder:z}),a&&v.jsxs("button",{type:"button",onClick:f,disabled:o,className:"btn-ghost text-sm whitespace-nowrap flex items-center gap-1.5 disabled:opacity-50",children:[v.jsx(Dv,{size:14}),S("favorites.form.browse")]})]}),v.jsx("p",{className:"mt-1 text-2xs",style:{color:"var(--color-text-muted)"},children:z})]}),A==="executable"&&v.jsxs("div",{className:"mb-5",children:[v.jsx("label",{className:"block text-sm font-medium text-warm-600 mb-2",children:S("favorites.form.args")}),v.jsx("input",{type:"text",value:g,onChange:H=>l(H.target.value),className:"input-field text-sm font-mono",placeholder:'--flag value "with spaces"'})]}),A!=="url"&&v.jsxs("div",{className:"mb-5",children:[v.jsx("label",{className:"block text-sm font-medium text-warm-600 mb-2",children:S("favorites.form.cwd")}),v.jsx("input",{type:"text",value:m,onChange:H=>b(H.target.value),className:"input-field text-sm font-mono",placeholder:"C:/Projects/my-project"})]}),v.jsx("p",{className:"mb-6 text-2xs leading-snug",style:{color:"var(--color-text-muted)"},children:S("favorites.security.notice")}),v.jsxs("div",{className:"flex justify-end gap-3",children:[v.jsx("button",{type:"button",onClick:w,className:"btn-ghost text-sm",children:S("favorites.form.cancel")}),v.jsx("button",{type:"submit",disabled:!E,className:"btn-primary text-sm",children:S(y?"favorites.form.save":"favorites.form.create")})]})]})]})})}const ox=/^([a-z0-9]([a-z0-9-]*[a-z0-9])?\.)+[a-z]{2,}$/i;function ax({onClose:s}){const{t:h}=Tt(),{error:w,success:S}=un(),[M,O]=j.useState(""),[A,r]=j.useState(""),[u,d]=j.useState(""),[g,l]=j.useState(""),[m,b]=j.useState(!1),[C,p]=j.useState(!1),[o,c]=j.useState(!1),[a,f]=j.useState(null);j.useEffect(()=>{let P=!1;return Promise.all([$S(),uh()]).then(([I,K])=>{P||(O(I.tunnelName),r(I.customHostname),d(I.tunnelName),l(I.customHostname),f(K))}).catch(()=>{}),()=>{P=!0}},[]);const y=M.trim(),R=A.trim(),k=y!==u.trim()||R!==g.trim(),D=!!R&&(!ox.test(R)||R.toLowerCase()==="localhost"||R.toLowerCase()==="127.0.0.1"),E=!!R&&!y,L=k&&!C&&!D&&!E,z=async()=>{if(L){p(!0);try{const P=await WS({tunnelName:y,customHostname:R});d(P.tunnelName),l(P.customHostname),O(P.tunnelName),r(P.customHostname),S(h("tunnel.saved"))}catch(P){w(P instanceof Error?P.message:h("tunnel.saveFailed"))}finally{p(!1)}}},H=async()=>{c(!0);try{try{await qS()}catch{}const P=await zv();f({status:"running",url:P.url}),S(h("tunnel.restarted"))}catch(P){w(P instanceof Error?P.message:h("tunnel.restartFailed"))}finally{c(!1)}};return v.jsxs("div",{className:"p-8",children:[v.jsx("h2",{className:"text-lg font-semibold text-warm-800 mb-1",children:h("tunnel.title")}),v.jsx("p",{className:"text-xs text-warm-400 mb-6",children:h("tunnel.description")}),a&&v.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:[v.jsx("span",{className:`w-2 h-2 rounded-full ${a.status==="running"?"bg-status-success":a.status==="error"?"bg-status-error":"bg-status-pending"}`}),v.jsx("span",{className:"font-medium",children:h(`tunnel.status.${a.status}`)}),a.url&&v.jsx("a",{href:a.url,target:"_blank",rel:"noreferrer",className:"ml-auto font-mono truncate hover:underline",style:{color:"var(--color-accent)"},children:a.url})]}),v.jsxs("div",{className:"mb-4",children:[v.jsx("label",{className:"block text-sm font-medium text-warm-600 mb-2",children:h("tunnel.name.label")}),v.jsx("input",{type:"text",value:M,onChange:P=>O(P.target.value),placeholder:h("tunnel.name.placeholder"),className:"input-field text-sm font-mono"}),v.jsx("p",{className:"mt-1 text-2xs",style:{color:"var(--color-text-muted)"},children:h("tunnel.name.hint")})]}),v.jsxs("div",{className:"mb-4",children:[v.jsx("label",{className:"block text-sm font-medium text-warm-600 mb-2",children:h("tunnel.hostname.label")}),v.jsx("input",{type:"text",value:A,onChange:P=>r(P.target.value),placeholder:h("tunnel.hostname.placeholder"),className:"input-field text-sm font-mono"}),v.jsx("p",{className:"mt-1 text-2xs",style:{color:"var(--color-text-muted)"},children:h("tunnel.hostname.hint")}),D&&v.jsx("p",{className:"mt-1 text-2xs text-status-error",children:h("tunnel.hostname.invalid")}),E&&v.jsx("p",{className:"mt-1 text-2xs text-status-error",children:h("tunnel.hostname.needsName")})]}),v.jsxs("div",{className:"mb-5",children:[v.jsxs("button",{type:"button",onClick:()=>b(!m),className:"flex items-center gap-1 text-xs text-accent-dark hover:text-accent transition-colors",children:[v.jsx("span",{className:`inline-block transition-transform ${m?"rotate-90":""}`,children:"▶"}),h("tunnel.guide.toggle")]}),m&&v.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:[v.jsx("p",{className:"font-semibold text-warm-700 mb-1",children:h("tunnel.guide.heading")}),v.jsxs("ol",{className:"list-decimal list-inside space-y-1 ml-1",children:[v.jsx("li",{children:v.jsx("code",{className:"font-mono",children:"cloudflared tunnel login"})}),v.jsx("li",{children:v.jsx("code",{className:"font-mono",children:"cloudflared tunnel create my-app"})}),v.jsx("li",{children:v.jsx("code",{className:"font-mono",children:"cloudflared tunnel route dns my-app app.your-domain.com"})}),v.jsx("li",{children:h("tunnel.guide.step4")})]}),v.jsx("p",{className:"text-2xs text-warm-400 pt-1",children:h("tunnel.guide.note")})]})]}),v.jsxs("div",{className:"flex items-center justify-between gap-3",children:[v.jsx("button",{type:"button",onClick:H,disabled:o,className:"btn-ghost text-sm disabled:opacity-50",children:o?(a==null?void 0:a.status)==="running"?h("tunnel.restarting"):h("tunnel.starting"):(a==null?void 0:a.status)==="running"?h("tunnel.restart"):h("tunnel.start")}),v.jsxs("div",{className:"flex gap-3",children:[s&&v.jsx("button",{type:"button",onClick:s,className:"btn-ghost text-sm",children:h("tunnel.close")}),v.jsx("button",{type:"button",onClick:z,disabled:!L,className:"btn-primary text-sm",children:h(C?"tunnel.saving":"tunnel.save")})]})]})]})}const pg=8;function lx({onClose:s}){const{t:h}=Tt(),{error:w,success:S}=un(),[M,O]=j.useState(""),[A,r]=j.useState(""),[u,d]=j.useState(""),[g,l]=j.useState(!1),m=A.length>0&&A.length<pg,b=u.length>0&&A!==u,C=!!M&&A.length>=pg&&A===u&&!g,p=()=>{O(""),r(""),d("")},o=async()=>{if(C){l(!0);try{await wv(M,A,u),S(h("account.saved")),p()}catch(c){w(c instanceof Error&&c.message?c.message:h("account.saveFailed"))}finally{l(!1)}}};return v.jsxs("div",{className:"p-8",children:[v.jsx("h2",{className:"text-lg font-semibold text-warm-800 mb-1",children:h("account.title")}),v.jsx("p",{className:"text-xs text-warm-400 mb-6",children:h("account.description")}),v.jsxs("div",{className:"mb-4",children:[v.jsx("label",{className:"block text-sm font-medium text-warm-600 mb-2",children:h("account.oldPassword")}),v.jsx("input",{type:"password",value:M,onChange:c=>O(c.target.value),className:"input-field text-sm",autoComplete:"current-password"})]}),v.jsxs("div",{className:"mb-4",children:[v.jsx("label",{className:"block text-sm font-medium text-warm-600 mb-2",children:h("account.newPassword")}),v.jsx("input",{type:"password",value:A,onChange:c=>r(c.target.value),className:"input-field text-sm",autoComplete:"new-password"}),m&&v.jsx("p",{className:"mt-1 text-2xs text-status-error",children:h("account.tooShort")})]}),v.jsxs("div",{className:"mb-6",children:[v.jsx("label",{className:"block text-sm font-medium text-warm-600 mb-2",children:h("account.confirm")}),v.jsx("input",{type:"password",value:u,onChange:c=>d(c.target.value),className:"input-field text-sm",autoComplete:"new-password"}),b&&v.jsx("p",{className:"mt-1 text-2xs text-status-error",children:h("account.mismatch")})]}),v.jsxs("div",{className:"flex items-center justify-end gap-3",children:[s&&v.jsx("button",{type:"button",onClick:s,className:"btn-ghost text-sm",children:h("account.close")}),v.jsx("button",{type:"button",onClick:o,disabled:!C,className:"btn-primary text-sm",children:h(g?"account.saving":"account.save")})]})]})}function cx(){return bt("/api/session-tags")}function ux(s){return nt("/api/session-tags",s)}function hx(s,h){return Di(`/api/session-tags/${s}`,h)}function dx(s){return Cr(`/api/session-tags/${s}`)}function Uv(){return bt("/api/session-aliases")}function $v(s){return nt("/api/session-aliases",s)}function fx(s,h){return Di(`/api/session-aliases/${s}`,h)}function px(s){return Cr(`/api/session-aliases/${s}`)}function Wv(){return bt("/api/session-settings")}function Yu(s){return Di("/api/session-settings",s)}const Ce={titleBg:"#2d2d2d",titleText:"#999",bg:"#0c0c0c",text:"#cccccc",dim:"#666666",bright:"#f2f2f2",prompt:"#16c60c",success:"#16c60c",error:"#f14c4c",warning:"#cca700",info:"#569cd6",separator:"#333333"},_t="'Cascadia Code', 'Cascadia Mono', ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, 'Courier New', monospace",jh=13,wo=8,So=28,br=new Map,Rn=new Map;let ml=jh;function Oh(s){return`sessionFontSize:${s}`}window.addEventListener("storage",s=>{var S;if(s.storageArea!==localStorage||!((S=s.key)!=null&&S.startsWith("sessionFontSize:")))return;const h=s.key.slice(16);br.delete(h);const w=Rn.get(h);if(w){const M=xo(h);w.forEach(O=>O(M))}});function hh(s){return Number.isFinite(s)?Math.max(wo,Math.min(So,Math.round(s))):ml}function mx(s){if(br.has(s))return!0;try{return localStorage.getItem(Oh(s))!==null}catch{return!1}}function xo(s){const h=br.get(s);if(h!==void 0)return h;let w=null;try{const S=localStorage.getItem(Oh(s));if(S!==null){const M=parseInt(S,10);Number.isFinite(M)&&(w=hh(M))}}catch{}return w===null?hh(ml):(br.set(s,w),w)}function dh(s,h){const w=hh(h);if(br.get(s)===w)return;br.set(s,w);try{localStorage.setItem(Oh(s),String(w))}catch{}const S=Rn.get(s);S&&S.forEach(M=>M(w))}function bo(s,h){dh(s,xo(s)+h)}function hl(s){const h=Math.max(wo,Math.min(So,Math.round(s)));Number.isFinite(h)&&h!==ml&&(ml=h,Rn.forEach((w,S)=>{mx(S)||w.forEach(M=>M(h))}))}function qv(s){const[h,w]=j.useState(()=>xo(s));j.useEffect(()=>{w(xo(s));let O=Rn.get(s);return O||(O=new Set,Rn.set(s,O)),O.add(w),()=>{const A=Rn.get(s);A&&(A.delete(w),A.size===0&&Rn.delete(s))}},[s]);const S=j.useCallback(O=>dh(s,O),[s]),M=j.useCallback(O=>dh(s,xo(s)+O),[s]);return[h,S,M]}const Co=["#A78BFA","#F472B6","#FB923C","#FBBF24","#34D399","#60A5FA","#F87171","#94A3B8"];function mg(s){for(const h of Co)if(!s.some(w=>w.color.toLowerCase()===h.toLowerCase()))return h;return Co[s.length%Co.length]}function gx({onClose:s}){const{t:h}=Tt(),{confirm:w}=kr(),{error:S,success:M}=un(),[O,A]=j.useState([]),[r,u]=j.useState(!1),[d,g]=j.useState(jh),[l,m]=j.useState(!1),[b,C]=j.useState(!1),[p,o]=j.useState(!1),[c,a]=j.useState(!1),f=j.useRef(null),[y,R]=j.useState(""),[k,D]=j.useState(Co[0]),[E,L]=j.useState(!1),[z,H]=j.useState(null),[P,I]=j.useState(""),[K,X]=j.useState(Co[0]),[Y,$]=j.useState(!1),[U,T]=j.useState([]),[F,B]=j.useState(""),[W,Z]=j.useState(""),[ne,ge]=j.useState(!1),[xe,J]=j.useState(null),[G,de]=j.useState(""),[oe,Ae]=j.useState(""),[Oe,Xe]=j.useState(!1);j.useEffect(()=>{let ee=!1;return Promise.all([cx(),Wv(),Uv()]).then(([be,he,He])=>{ee||(A(be),u(he.defaultUseWorktree),g(he.defaultFontSize),hl(he.defaultFontSize),m(he.imeDebug),D(mg(be)),T(He),C(!0))}).catch(be=>{ee||S(be instanceof Error?be.message:"Failed to load")}),()=>{ee=!0}},[S]);const We=y.trim(),rt=!!We&&!E,ye=j.useMemo(()=>[...O].sort((ee,be)=>ee.sort_order-be.sort_order||ee.name.localeCompare(be.name)),[O]);j.useEffect(()=>()=>{f.current&&clearTimeout(f.current)},[]);const Te=ee=>{if(!Number.isFinite(ee))return;const be=Math.max(wo,Math.min(So,Math.round(ee)));g(be),hl(be),f.current&&clearTimeout(f.current),f.current=setTimeout(()=>{Yu({defaultFontSize:be}).then(he=>{g(he.defaultFontSize),hl(he.defaultFontSize)}).catch(he=>S(he instanceof Error?he.message:"Save failed"))},350)},ct=async ee=>{o(!0);try{const be=await Yu({defaultUseWorktree:ee});u(be.defaultUseWorktree),M(h("sessionSettings.saved"))}catch(be){S(be instanceof Error?be.message:"Save failed")}finally{o(!1)}},it=async ee=>{var be,he;a(!0);try{const He=await Yu({imeDebug:ee});m(He.imeDebug),(he=(be=window.electronAPI)==null?void 0:be.imeSetDebug)==null||he.call(be,He.imeDebug),M(h("sessionSettings.saved"))}catch(He){S(He instanceof Error?He.message:"Save failed")}finally{a(!1)}},ze=async()=>{if(rt){L(!0);try{const ee=await ux({name:We,color:k});A(be=>[...be,ee]),R(""),D(mg([...O,ee]))}catch(ee){S(ee instanceof Error?ee.message:"Create failed")}finally{L(!1)}}},qe=ee=>{H(ee.id),I(ee.name),X(ee.color)},Fe=()=>{H(null),I("")},Be=async()=>{if(!z)return;const ee=P.trim();if(ee){$(!0);try{const be=await hx(z,{name:ee,color:K});A(he=>he.map(He=>He.id===be.id?be:He)),Fe()}catch(be){S(be instanceof Error?be.message:"Save failed")}finally{$(!1)}}},$e=async ee=>{if(await w({message:h("sessionSettings.tags.deleteConfirm").replace("{name}",ee.name),danger:!0}))try{await dx(ee.id),A(be=>be.filter(he=>he.id!==ee.id))}catch(be){S(be instanceof Error?be.message:"Delete failed")}},lt=F.trim(),st=W.trim(),St=!!lt&&!!st&&!ne,Se=j.useMemo(()=>[...U].sort((ee,be)=>ee.sort_order-be.sort_order||ee.name.localeCompare(be.name)),[U]),Ie=async()=>{if(St){ge(!0);try{const ee=await $v({name:lt,command_template:st});T(be=>[...be,ee]),B(""),Z("")}catch(ee){S(ee instanceof Error?ee.message:"Create failed")}finally{ge(!1)}}},le=ee=>{J(ee.id),de(ee.name),Ae(ee.command_template)},Ne=()=>{J(null),de(""),Ae("")},je=async()=>{if(!xe)return;const ee=G.trim(),be=oe.trim();if(!(!ee||!be)){Xe(!0);try{const he=await fx(xe,{name:ee,command_template:be});T(He=>He.map(Me=>Me.id===he.id?he:Me)),Ne()}catch(he){S(he instanceof Error?he.message:"Save failed")}finally{Xe(!1)}}},ue=async ee=>{if(await w({message:h("sessionSettings.aliases.deleteConfirm").replace("{name}",ee.name),danger:!0}))try{await px(ee.id),T(be=>be.filter(he=>he.id!==ee.id))}catch(be){S(be instanceof Error?be.message:"Delete failed")}};return v.jsxs("div",{className:"p-8",children:[v.jsx("h2",{className:"text-lg font-semibold text-warm-800 mb-1",children:h("sessionSettings.title")}),v.jsx("p",{className:"text-xs text-warm-400 mb-6",children:h("sessionSettings.description")}),v.jsxs("section",{className:"mb-7",children:[v.jsxs("h3",{className:"text-sm font-semibold text-warm-700 mb-2 flex items-center gap-1.5",children:[v.jsx(x1,{size:14}),h("sessionSettings.worktree.title")]}),v.jsxs("label",{className:"flex items-center gap-2 cursor-pointer select-none",children:[v.jsx("input",{type:"checkbox",checked:r,disabled:p||!b,onChange:ee=>ct(ee.target.checked),className:"rounded-md border-warm-300"}),v.jsx("span",{className:"text-sm text-warm-600",children:h("sessionSettings.worktree.label")})]}),v.jsx("p",{className:"mt-1 text-2xs ml-6",style:{color:"var(--color-text-muted)"},children:h("sessionSettings.worktree.hint")})]}),v.jsxs("section",{className:"mb-7",children:[v.jsxs("h3",{className:"text-sm font-semibold text-warm-700 mb-2 flex items-center gap-1.5",children:[v.jsx(SS,{size:14}),h("sessionSettings.fontSize.title")]}),v.jsxs("div",{className:"flex items-center gap-3",children:[v.jsx("input",{type:"range",min:wo,max:So,step:1,value:d,disabled:!b,onChange:ee=>Te(parseInt(ee.target.value,10)),className:"flex-1 max-w-xs","aria-label":h("sessionSettings.fontSize.label")}),v.jsx("input",{type:"number",min:wo,max:So,step:1,value:d,disabled:!b,onChange:ee=>Te(parseInt(ee.target.value,10)),className:"input text-sm w-20"}),v.jsx("span",{className:"text-xs text-warm-400",children:"px"})]}),v.jsx("p",{className:"mt-1 text-2xs",style:{color:"var(--color-text-muted)"},children:h("sessionSettings.fontSize.hint")})]}),v.jsxs("section",{children:[v.jsx("h3",{className:"text-sm font-semibold text-warm-700 mb-2",children:h("sessionSettings.tags.title")}),v.jsx("p",{className:"text-xs text-warm-400 mb-3",children:h("sessionSettings.tags.description")}),v.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[v.jsx("input",{type:"color",value:k,onChange:ee=>D(ee.target.value),className:"w-9 h-9 rounded-md cursor-pointer border border-warm-200",title:h("sessionSettings.tags.color")}),v.jsx("input",{type:"text",value:y,onChange:ee=>R(ee.target.value),onKeyDown:ee=>{ee.key==="Enter"&&(ee.preventDefault(),ze())},placeholder:h("sessionSettings.tags.namePlaceholder"),className:"input text-sm flex-1",maxLength:32}),v.jsxs("button",{type:"button",onClick:ze,disabled:!rt,className:"btn-primary text-sm py-1.5 px-3 inline-flex items-center gap-1",children:[v.jsx(Mn,{size:14}),h("sessionSettings.tags.add")]})]}),ye.length===0?v.jsx("p",{className:"text-xs text-warm-400 italic py-3",children:h("sessionSettings.tags.empty")}):v.jsx("ul",{className:"space-y-1.5",children:ye.map(ee=>{const be=z===ee.id;return v.jsx("li",{className:"flex items-center gap-2 px-3 py-2 rounded-lg border",style:{borderColor:"var(--color-border)"},children:be?v.jsxs(v.Fragment,{children:[v.jsx("input",{type:"color",value:K,onChange:he=>X(he.target.value),className:"w-7 h-7 rounded-md cursor-pointer border border-warm-200"}),v.jsx("input",{type:"text",value:P,onChange:he=>I(he.target.value),onKeyDown:he=>{he.key==="Enter"&&(he.preventDefault(),Be()),he.key==="Escape"&&Fe()},autoFocus:!0,className:"input text-sm flex-1",maxLength:32}),v.jsx("button",{type:"button",onClick:Be,disabled:Y||!P.trim(),className:"p-1.5 text-status-success hover:bg-status-success/10 rounded-md",title:h("sessionSettings.tags.save"),children:v.jsx(Do,{size:14})}),v.jsx("button",{type:"button",onClick:Fe,className:"p-1.5 text-warm-400 hover:bg-warm-100 rounded-md",title:h("sessionSettings.tags.cancel"),children:v.jsx(Ri,{size:14})})]}):v.jsxs(v.Fragment,{children:[v.jsx("span",{className:"w-4 h-4 rounded-full shrink-0 border",style:{backgroundColor:ee.color,borderColor:"rgba(0,0,0,0.08)"}}),v.jsx("span",{className:"text-sm text-warm-700 flex-1 truncate",children:ee.name}),v.jsx("button",{type:"button",onClick:()=>qe(ee),className:"p-1.5 text-warm-400 hover:text-warm-700 hover:bg-warm-100 rounded-md",title:h("sessionSettings.tags.edit"),children:v.jsx(ch,{size:14})}),v.jsx("button",{type:"button",onClick:()=>$e(ee),className:"p-1.5 text-warm-400 hover:text-status-error hover:bg-warm-100 rounded-md",title:h("sessionSettings.tags.delete"),children:v.jsx(cg,{size:14})})]})},ee.id)})})]}),v.jsxs("section",{className:"mt-7",children:[v.jsx("h3",{className:"text-sm font-semibold text-warm-700 mb-2",children:h("sessionSettings.aliases.title")}),v.jsx("p",{className:"text-xs text-warm-400 mb-3",children:h("sessionSettings.aliases.description")}),v.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[v.jsx("input",{type:"text",value:F,onChange:ee=>B(ee.target.value),placeholder:h("sessionSettings.aliases.namePlaceholder"),className:"input text-sm w-44",maxLength:64}),v.jsx("input",{type:"text",value:W,onChange:ee=>Z(ee.target.value),onKeyDown:ee=>{ee.key==="Enter"&&(ee.preventDefault(),Ie())},placeholder:h("sessionSettings.aliases.commandPlaceholder"),className:"input text-sm flex-1 font-mono",maxLength:1024}),v.jsxs("button",{type:"button",onClick:Ie,disabled:!St,className:"btn-primary text-sm py-1.5 px-3 inline-flex items-center gap-1",children:[v.jsx(Mn,{size:14}),h("sessionSettings.aliases.add")]})]}),Se.length===0?v.jsx("p",{className:"text-xs text-warm-400 italic py-3",children:h("sessionSettings.aliases.empty")}):v.jsx("ul",{className:"space-y-1.5",children:Se.map(ee=>{const be=xe===ee.id;return v.jsx("li",{className:"flex items-center gap-2 px-3 py-2 rounded-lg border",style:{borderColor:"var(--color-border)"},children:be?v.jsxs(v.Fragment,{children:[v.jsx("input",{type:"text",value:G,onChange:he=>de(he.target.value),className:"input text-sm w-44",maxLength:64}),v.jsx("input",{type:"text",value:oe,onChange:he=>Ae(he.target.value),onKeyDown:he=>{he.key==="Enter"&&(he.preventDefault(),je()),he.key==="Escape"&&Ne()},autoFocus:!0,className:"input text-sm flex-1 font-mono",maxLength:1024}),v.jsx("button",{type:"button",onClick:je,disabled:Oe||!G.trim()||!oe.trim(),className:"p-1.5 text-status-success hover:bg-status-success/10 rounded-md",title:h("common.save"),children:v.jsx(Do,{size:14})}),v.jsx("button",{type:"button",onClick:Ne,className:"p-1.5 text-warm-400 hover:bg-warm-100 rounded-md",title:h("common.cancel"),children:v.jsx(Ri,{size:14})})]}):v.jsxs(v.Fragment,{children:[v.jsx("span",{className:"text-sm text-warm-700 w-44 truncate",children:ee.name}),v.jsx("code",{className:"text-xs text-warm-500 flex-1 truncate font-mono",children:ee.command_template}),v.jsx("button",{type:"button",onClick:()=>le(ee),className:"p-1.5 text-warm-400 hover:text-warm-700 hover:bg-warm-100 rounded-md",title:h("common.edit"),children:v.jsx(ch,{size:14})}),v.jsx("button",{type:"button",onClick:()=>ue(ee),className:"p-1.5 text-warm-400 hover:text-status-error hover:bg-warm-100 rounded-md",title:h("common.delete"),children:v.jsx(cg,{size:14})})]})},ee.id)})})]}),v.jsxs("section",{className:"mt-7",children:[v.jsxs("h3",{className:"text-sm font-semibold text-warm-700 mb-2 flex items-center gap-1.5",children:[v.jsx(Jw,{size:14}),"IME 디버그 로그"]}),v.jsxs("label",{className:"flex items-center gap-2 cursor-pointer select-none",children:[v.jsx("input",{type:"checkbox",checked:l,disabled:c||!b,onChange:ee=>it(ee.target.checked),className:"rounded-md border-warm-300"}),v.jsx("span",{className:"text-sm text-warm-600",children:"한글 입력(IME) 진단 로그 기록"})]}),v.jsx("p",{className:"mt-1 text-2xs ml-6",style:{color:"var(--color-text-muted)"},children:"조합 창이 화면 좌상단에 뜨는 문제를 진단하기 위해 입력 시점 상태를 기록합니다. 데스크톱 앱에서만 동작하며, 로그는 앱 데이터 폴더의 ime-debug.log에 저장됩니다."})]}),s&&v.jsx("div",{className:"flex justify-end gap-3 mt-7",children:v.jsx("button",{type:"button",onClick:s,className:"btn-ghost text-sm",children:h("tunnel.close")})})]})}function vx(){return bt("/api/mcp/connection")}function _x({onClose:s}){const{t:h}=Tt(),{success:w,error:S}=un(),[M,O]=j.useState(null),[A,r]=j.useState(null);j.useEffect(()=>{let m=!1;return vx().then(b=>{m||O(b)}).catch(()=>{}),()=>{m=!0}},[]);const u=async(m,b)=>{try{await navigator.clipboard.writeText(b),r(m),setTimeout(()=>r(C=>C===m?null:C),1500),w(h("mcp.copied"))}catch{S(h("mcp.copyFailed"))}},d=M?JSON.stringify(M.config,null,2):"",g=({label:m,text:b})=>v.jsxs("button",{type:"button",onClick:()=>u(m,b),className:"btn-ghost text-xs flex items-center gap-1",children:[A===m?v.jsx(Do,{size:14}):v.jsx(_1,{size:14}),h("mcp.copy")]}),l={backgroundColor:"var(--color-bg-hover)",color:"var(--color-text-secondary)"};return v.jsxs("div",{className:"p-8",children:[v.jsx("h2",{className:"text-lg font-semibold text-warm-800 mb-1",children:h("mcp.title")}),v.jsx("p",{className:"text-xs text-warm-400 mb-6",children:h("mcp.description")}),M?v.jsxs(v.Fragment,{children:[v.jsxs("div",{className:"mb-5",children:[v.jsxs("div",{className:"flex items-center justify-between mb-2",children:[v.jsx("label",{className:"block text-sm font-medium text-warm-600",children:h("mcp.config.label")}),v.jsx(g,{label:"config",text:d})]}),v.jsx("pre",{className:"p-3 rounded-lg text-2xs font-mono overflow-x-auto",style:l,children:d})]}),v.jsxs("div",{className:"mb-5",children:[v.jsx("label",{className:"block text-sm font-medium text-warm-600 mb-1",children:h("mcp.commands.label")}),v.jsx("p",{className:"text-2xs text-warm-400 mb-3",children:h("mcp.commands.hint")}),v.jsx("div",{className:"space-y-3",children:M.commands.map(m=>v.jsxs("div",{children:[v.jsxs("div",{className:"flex items-center justify-between mb-1",children:[v.jsx("span",{className:"text-xs text-warm-500",children:m.label}),v.jsx(g,{label:`command:${m.id}`,text:m.command})]}),v.jsx("pre",{className:"p-3 rounded-lg text-2xs font-mono overflow-x-auto",style:l,children:m.command})]},m.id))})]}),v.jsx("p",{className:"text-2xs text-warm-400",children:h("mcp.tokenNote")})]}):v.jsx("p",{className:"text-sm text-warm-400",children:h("mcp.loading")}),s&&v.jsx("div",{className:"flex justify-end mt-6",children:v.jsx("button",{type:"button",onClick:s,className:"btn-ghost text-sm",children:h("mcp.close")})})]})}function gg({open:s,onClose:h}){const{t:w}=Tt(),[S,M]=j.useState("account");if(!s)return null;const O=[{id:"account",label:w("settings.tabs.account"),icon:j1},{id:"session",label:w("settings.tabs.session"),icon:Ah},{id:"tunnel",label:w("settings.tabs.tunnel"),icon:Ev},{id:"mcp",label:w("settings.tabs.mcp"),icon:sS}];return v.jsx(Ho,{open:s,onClose:h,size:"xl",children:v.jsx("div",{className:"bg-theme-card border border-theme-border rounded-2xl shadow-elevated overflow-hidden",children:v.jsxs("div",{className:"flex",style:{minHeight:460},children:[v.jsxs("aside",{className:"w-44 shrink-0 border-r flex flex-col",style:{borderColor:"var(--color-border)",backgroundColor:"var(--color-bg-hover)"},children:[v.jsx("div",{className:"px-4 pt-5 pb-3 text-xs font-semibold uppercase tracking-wider",style:{color:"var(--color-text-muted)"},children:w("settings.title")}),v.jsx("nav",{className:"flex flex-col",children:O.map(({id:A,label:r,icon:u})=>{const d=S===A;return v.jsxs("button",{type:"button",onClick:()=>M(A),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:[v.jsx(u,{size:14}),v.jsx("span",{children:r})]},A)})}),v.jsxs("div",{className:"px-4 py-3 mt-auto text-[11px] tracking-wide",style:{color:"var(--color-text-muted)"},children:["v","0.2.69"]})]}),v.jsxs("div",{className:"flex-1 min-w-0",children:[S==="account"&&v.jsx(lx,{onClose:h}),S==="session"&&v.jsx(gx,{onClose:h}),S==="tunnel"&&v.jsx(ax,{onClose:h}),S==="mcp"&&v.jsx(_x,{onClose:h})]})]})})})}const fh=["#55708F","#4F7A68","#9A783F","#A15F5A","#74658A","#925F73","#477B7D","#747A50"];function bx(s,h){let w=0;for(let S=0;S<s.length;S++)w=(w<<5)-w+s.charCodeAt(S)|0;return Math.abs(w)%h}function To(s){return s.color&&/^#[0-9a-f]{6}$/i.test(s.color)?s.color:fh[bx(s.id,fh.length)]}const vg=192,yx=88,Qa=8;function wx({project:s,anchorX:h,anchorY:w,onPick:S,onClose:M}){const O=j.useRef(null),[A,r]=j.useState({left:h,top:w}),u=To(s);return j.useLayoutEffect(()=>{const d=Math.min(Math.max(h,Qa),window.innerWidth-vg-Qa),g=Math.min(Math.max(w,Qa),window.innerHeight-yx-Qa);r({left:d,top:g})},[h,w]),j.useEffect(()=>{const d=l=>{var m;(m=O.current)!=null&&m.contains(l.target)||M()},g=l=>{l.key==="Escape"&&M()};return window.addEventListener("mousedown",d),window.addEventListener("keydown",g),()=>{window.removeEventListener("mousedown",d),window.removeEventListener("keydown",g)}},[M]),zi.createPortal(v.jsxs("div",{ref:O,role:"menu",className:"z-tooltip",style:{position:"fixed",left:A.left,top:A.top,width:vg,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:[v.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:8,marginBottom:8},children:fh.map(d=>{const g=s.color?d.toLowerCase()===s.color.toLowerCase():d===u&&!s.color;return v.jsx("button",{onClick:()=>S(d),"aria-label":d,style:{width:20,height:20,borderRadius:6,background:d,border:g?"2px solid var(--color-text-primary)":"2px solid transparent",cursor:"pointer",padding:0}},d)})}),v.jsx("button",{onClick:()=>S(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 Gv(s,h){return s instanceof Error&&s.message.trim()?s.message:typeof s=="string"&&s.trim()?s:h}function Sx(s){const h=s instanceof Error?s.message:typeof s=="string"?s:"";return/^ResizeObserver loop (?:limit exceeded|completed with undelivered notifications\.?)$/i.test(h.trim())}const xx={sm:"btn-icon-sm",md:"btn-icon-md",lg:"btn-icon-lg"},Cx={default:"",active:"btn-icon-active",danger:"btn-icon-danger"},Ei=j.forwardRef(function({label:h,size:w="md",variant:S="default",pressed:M,type:O="button",title:A,className:r,...u},d){return v.jsx("button",{ref:d,type:O,"aria-label":h,"aria-pressed":M,title:A??h,className:Tn("btn-icon",xx[w],Cx[S],r),...u})});function kx(s){return s==="executable"?Rv:s==="command"?Ov:Mv}function Ex({onLogout:s,authRequired:h,connected:w,onEvent:S,onClose:M,collapsed:O=!1,onToggleCollapsed:A}){var St;const[r,u]=j.useState([]),[d,g]=j.useState({}),[l,m]=j.useState(null),[b,C]=j.useState(!1),[p,o]=j.useState(null),[c,a]=j.useState([]),[f,y]=j.useState(!1),[R,k]=j.useState(null),[D,E]=j.useState(!1),[L,z]=j.useState(null),[H,P]=j.useState(!1),[I,K]=j.useState(null),[X,Y]=j.useState(null),$=ss(),U=xl(),{t:T,toggleLang:F}=Tt(),{theme:B,toggleTheme:W}=YS(),{enabled:Z,supported:ne,toggleNotification:ge}=Ll(),{error:xe,success:J,info:G,warning:de}=un(),{confirm:oe}=kr(),Ae=((St=$.pathname.match(/^\/projects\/([^/]+)/))==null?void 0:St[1])||null;j.useEffect(()=>{it(),Xe(),uh().then(z).catch(()=>{})},[]);async function Oe(){if(!H){P(!0);try{const Se=await uh();if(z(Se),Se.status==="running"&&Se.url){await navigator.clipboard.writeText(Se.url),J(T("tunnel.urlCopied"));return}const Ie=await zv(),le={status:"running",url:Ie.url};z(le);try{await navigator.clipboard.writeText(Ie.url),J(T("tunnel.urlCopied"))}catch{J(Ie.url)}}catch(Se){xe(Se instanceof Error?Se.message:T("tunnel.restartFailed"))}finally{P(!1)}}}function Xe(){zS().then(a).catch(()=>{})}const We=async Se=>{try{R?await PS(R.id,Se):await HS(Se),y(!1),k(null),Xe()}catch(Ie){xe(Ie instanceof Error?Ie.message:"Failed to save favorite")}},rt=async Se=>{try{await FS(Se)}catch(Ie){const le=Ie instanceof Error?Ie.message:T("favorites.launchFailed");xe(`${T("favorites.launchFailed")}: ${le}`)}},ye=async(Se,Ie)=>{if(Ie.preventDefault(),Ie.stopPropagation(),!!await oe({message:T("favorites.deleteConfirm"),danger:!0}))try{await IS(Se),a(le=>le.filter(Ne=>Ne.id!==Se))}catch(le){xe(le instanceof Error?le.message:"Failed to delete favorite")}},Te=(Se,Ie)=>{Ie.preventDefault(),Ie.stopPropagation(),k(Se),y(!0)};j.useEffect(()=>{const Se=()=>it();return window.addEventListener("projects:changed",Se),()=>window.removeEventListener("projects:changed",Se)},[]),j.useEffect(()=>{const Se=()=>ct();return window.addEventListener("review:changed",Se),()=>window.removeEventListener("review:changed",Se)},[]),j.useEffect(()=>S(Se=>{var Ie;if(Se.type==="project:status-changed"&&Se.projectId&&g(le=>({...le,[Se.projectId]:{running:Se.running??0,completed:Se.completed??0,total:Se.total??0,running_sessions:Se.running_sessions??0,running_discussions:Se.running_discussions??0}})),Se.type==="todo:status-changed"&&ct(),Se.type==="memory:ingest-finished"){const le=r.find(Me=>Me.id===Se.projectId),Ne=(le==null?void 0:le.name)??"",je=Se.sourceTitle?`“${Se.sourceTitle}”`:Se.sourceType??"",ue=Ne?`[${Ne}] `:"";if(Se.error){xe(`${ue}${T("wiki.ingest.toast.failed")}: ${Se.error}`,6e3);return}const ee=Se.created??0,be=Se.updated??0,he=Se.edgesAdded??0;if(ee+be+he>0){const Me=T("wiki.ingest.toast.success").replace("{source}",je).replace("{created}",String(ee)).replace("{updated}",String(be)).replace("{edges}",String(he));J(`${ue}${Me}`)}else(Ie=Se.skipped)!=null&&Ie.parseFailed?de(`${ue}${T("wiki.ingest.toast.parseFailed").replace("{source}",je)}`,5e3):G(`${ue}${T("wiki.ingest.toast.empty").replace("{source}",je)}`,4e3)}}),[S,r,T,xe,G,J,de]),j.useEffect(()=>{ct()},[]);function ct(){NS({hours:24}).then(Se=>m(Se.total_todos)).catch(()=>{})}function it(){Bv().then(Se=>{u(Se),Se.forEach(Ie=>{BS(Ie.id).then(le=>{g(Ne=>({...Ne,[Ie.id]:le}))}).catch(()=>{})})}).catch(()=>{})}const ze=()=>{M==null||M()},qe=async(Se,Ie)=>{await MS({name:Se,path:Ie}),C(!1),window.dispatchEvent(new Event("projects:changed"))},Fe=j.useCallback(async(Se,Ie)=>{const le=r.map(Me=>Me.id),Ne=le.indexOf(Se);if(Ne<0)return;const je=le.filter(Me=>Me!==Se),ue=Ie>Ne?Ie-1:Ie;if(ue===Ne)return;const ee=[...je.slice(0,ue),Se,...je.slice(ue)],be=r,he=new Map(r.map(Me=>[Me.id,Me])),He=ee.map(Me=>he.get(Me)).filter(Boolean);u(He);try{await OS(ee)}catch(Me){u(be),xe(Me instanceof Error?Me.message:"Failed to reorder projects")}},[r,xe]),Be=j.useRef(!1),$e=j.useCallback((Se,Ie)=>{if(Ie.button!==0||Ie.target.closest("button"))return;Ie.preventDefault();const Ne=Ie.clientX,je=Ie.clientY,ue=6;let ee=!1,be=null;const he=V=>{const ie=document.querySelectorAll("[data-workspace-item]");if(ie.length===0)return null;const Q=ie[0].getBoundingClientRect();if(V<Q.top)return 0;const ke=ie[ie.length-1].getBoundingClientRect();if(V>ke.bottom)return ie.length;for(let ce=0;ce<ie.length;ce++){const _e=ie[ce].getBoundingClientRect();if(V>=_e.top&&V<=_e.bottom){const Ee=_e.top+_e.height/2;return V<Ee?ce:ce+1}}return null},He=V=>{if(!ee){if(Math.hypot(V.clientX-Ne,V.clientY-je)<ue)return;ee=!0,K(Se)}const ie=he(V.clientY);ie!==be&&(be=ie,Y(ie))},Me=()=>{window.removeEventListener("mousemove",He),window.removeEventListener("mouseup",Ge),window.removeEventListener("keydown",se)},Ge=()=>{if(Me(),!ee)return;Be.current=!0,requestAnimationFrame(()=>{Be.current=!1});const V=be;K(null),Y(null),V!==null&&Fe(Se,V)},se=V=>{V.key==="Escape"&&(Me(),K(null),Y(null),ee&&(Be.current=!0,requestAnimationFrame(()=>{Be.current=!1})))};window.addEventListener("mousemove",He),window.addEventListener("mouseup",Ge),window.addEventListener("keydown",se)},[Fe]),lt=async(Se,Ie)=>{if(Ie.preventDefault(),Ie.stopPropagation(),!!await oe({message:T("projects.deleteConfirm"),danger:!0}))try{await jS(Se),u(le=>le.filter(Ne=>Ne.id!==Se)),window.dispatchEvent(new Event("projects:changed")),Ae===String(Se)&&U("/")}catch(le){xe(Gv(le,T("errors.projectDelete")))}},st=Se=>v.jsx("div",{className:"pointer-events-none absolute left-2 right-2 h-0.5 rounded-full",style:{backgroundColor:"var(--color-accent)",zIndex:10,...Se==="above"?{top:-1}:{bottom:-1}}});if(O){const Se=v.jsx("div",{className:"w-7 border-t my-1.5",style:{borderColor:"var(--color-border)"}});return v.jsxs("div",{className:"flex flex-col items-center h-full bg-theme-bg-secondary border-none py-3",children:[v.jsx(Ei,{onClick:A,label:T("sidebar.expand"),size:"lg",children:v.jsx(V1,{size:16})}),Se,v.jsx(es,{to:"/",onClick:ze,className:"relative flex items-center justify-center w-9 h-9 rounded-lg transition-colors hover:bg-theme-hover",style:$.pathname==="/"?{backgroundColor:"var(--color-bg-hover)",color:"var(--color-text-primary)"}:{color:"var(--color-text-tertiary)"},title:T("sidebar.home"),children:v.jsx(ng,{size:16})}),v.jsxs(es,{to:"/review",onClick:ze,className:"relative flex items-center justify-center w-9 h-9 rounded-lg transition-colors hover:bg-theme-hover mt-0.5",style:$.pathname==="/review"?{backgroundColor:"var(--color-bg-hover)",color:"var(--color-text-primary)"}:{color:"var(--color-text-tertiary)"},title:T("sidebar.review"),children:[v.jsx(sg,{size:16}),l!==null&&l>0&&v.jsx("span",{className:"absolute top-1 right-1 w-1.5 h-1.5 rounded-full",style:{backgroundColor:"var(--color-accent)"}})]}),v.jsx(es,{to:"/agenda",onClick:ze,className:"relative flex items-center justify-center w-9 h-9 rounded-lg transition-colors hover:bg-theme-hover mt-0.5",style:$.pathname==="/agenda"?{backgroundColor:"var(--color-bg-hover)",color:"var(--color-text-primary)"}:{color:"var(--color-text-tertiary)"},title:T("sidebar.agenda"),children:v.jsx(ig,{size:16})}),Se,v.jsx("div",{className:"flex-1 overflow-y-auto w-full flex flex-col items-center gap-1 py-1",children:r.map(Ie=>{const le=d[Ie.id],Ne=Ae===String(Ie.id),je=le?le.running+le.running_sessions+le.running_discussions:0,ue=je>0,ee=To(Ie);return v.jsxs(es,{to:`/projects/${Ie.id}`,onClick:ze,className:"relative flex items-center justify-center w-9 h-9 rounded-lg transition-colors hover:bg-theme-hover",style:Ne?{backgroundColor:"var(--color-bg-hover)"}:void 0,title:ue?`${Ie.name} · ${je} ${T("detail.live")}`:Ie.name,children:[Ne&&v.jsx("span",{className:"absolute left-0 top-1/4 bottom-1/4 w-[3px] rounded-r-full",style:{backgroundColor:ee}}),v.jsx("span",{className:`w-2.5 h-2.5 rounded-[3px] ${ue?"workspace-dot-pulse":""}`,style:{backgroundColor:ee,opacity:Ne||ue?1:.55}})]},Ie.id)})}),Se,v.jsx("span",{className:`w-1.5 h-1.5 rounded-full my-1 ${w?"bg-status-success":"bg-status-error"}`,title:w?T("detail.live"):"Disconnected"}),v.jsx(Ei,{onClick:W,label:T(B==="light"?"theme.dark":"theme.light"),size:"lg",children:B==="light"?v.jsx(rg,{size:16}):v.jsx(lg,{size:16})}),v.jsx(Ei,{onClick:()=>E(!0),label:T("settings.title"),size:"lg",children:v.jsx(ag,{size:16})}),v.jsx(gg,{open:D,onClose:()=>E(!1)})]})}return v.jsxs("div",{className:"flex flex-col h-full bg-theme-bg-secondary border-none",onDragStart:Se=>Se.preventDefault(),children:[v.jsxs("div",{className:"px-4 pt-5 pb-3 flex items-center justify-between",children:[v.jsxs(es,{to:"/",onClick:ze,className:"block font-mono text-[22px] leading-none whitespace-nowrap select-none",children:[v.jsxs("span",{className:"font-medium text-accent/50",children:[">","_ "]}),v.jsx("span",{className:"font-bold text-accent",children:"CLI"}),v.jsx("span",{className:"font-medium text-theme-text",children:"Trigger"})]}),v.jsx(Ei,{onClick:A,label:T("sidebar.collapse"),size:"sm",className:"hidden md:inline-flex flex-shrink-0",children:v.jsx(K1,{size:16})})]}),v.jsxs("nav",{className:"px-3 mb-2 space-y-0.5",children:[v.jsxs(es,{to:"/",onClick:ze,className:`relative flex items-center gap-3 px-3 py-2 rounded-lg text-sm transition-all duration-200 active:scale-95 ${$.pathname==="/"?"font-medium":""}`,style:$.pathname==="/"?{backgroundColor:"var(--color-bg-hover)",color:"var(--color-text-primary)",boxShadow:"var(--shadow-soft)"}:{color:"var(--color-text-tertiary)"},children:[$.pathname==="/"&&v.jsx("span",{className:"absolute left-0 top-1/4 bottom-1/4 w-[3px] rounded-r-full",style:{backgroundColor:"var(--color-accent)"}}),v.jsx(ng,{size:16}),T("sidebar.home")]}),v.jsxs(es,{to:"/review",onClick:ze,className:`relative flex items-center gap-3 px-3 py-2 rounded-lg text-sm transition-all duration-200 active:scale-95 ${$.pathname==="/review"?"font-medium":""}`,style:$.pathname==="/review"?{backgroundColor:"var(--color-bg-hover)",color:"var(--color-text-primary)",boxShadow:"var(--shadow-soft)"}:{color:"var(--color-text-tertiary)"},children:[$.pathname==="/review"&&v.jsx("span",{className:"absolute left-0 top-1/4 bottom-1/4 w-[3px] rounded-r-full",style:{backgroundColor:"var(--color-accent)"}}),v.jsx(sg,{size:16}),v.jsx("span",{className:"flex-1",children:T("sidebar.review")}),l!==null&&l>0&&v.jsx("span",{className:"text-2xs px-1.5 py-0.5 rounded-full font-medium",style:{backgroundColor:"var(--color-accent)",color:"white"},children:l})]}),v.jsxs(es,{to:"/agenda",onClick:ze,className:`relative flex items-center gap-3 px-3 py-2 rounded-lg text-sm transition-all duration-200 active:scale-95 ${$.pathname==="/agenda"?"font-medium":""}`,style:$.pathname==="/agenda"?{backgroundColor:"var(--color-bg-hover)",color:"var(--color-text-primary)",boxShadow:"var(--shadow-soft)"}:{color:"var(--color-text-tertiary)"},children:[$.pathname==="/agenda"&&v.jsx("span",{className:"absolute left-0 top-1/4 bottom-1/4 w-[3px] rounded-r-full",style:{backgroundColor:"var(--color-accent)"}}),v.jsx(ig,{size:16}),T("sidebar.agenda")]})]}),v.jsx("div",{className:"mx-4 border-t",style:{borderColor:"var(--color-border)"}}),v.jsxs("div",{className:"flex-1 overflow-y-auto px-3 pt-3",children:[v.jsxs("div",{className:"px-3 mb-2 flex items-center justify-between",children:[v.jsx("span",{className:"text-2xs font-semibold uppercase tracking-wider",style:{color:"var(--color-text-muted)"},children:T("sidebar.workspaces")}),v.jsx(Ei,{onClick:()=>C(!0),label:T("projects.new"),size:"sm",children:v.jsx(Mn,{size:14})})]}),v.jsx("div",{className:"space-y-0.5",children:r.map((Se,Ie)=>{const le=d[Se.id],Ne=Ae===String(Se.id),je=le?le.running+le.running_sessions+le.running_discussions:0,ue=je>0,ee=To(Se),be=I===Se.id,he=I!==null&&X===Ie,He=I!==null&&Ie===r.length-1&&X===r.length;return v.jsxs("div",{className:"relative","data-workspace-item":!0,children:[he&&st("above"),v.jsxs(es,{to:`/projects/${Se.id}`,draggable:!1,onDragStart:Me=>Me.preventDefault(),onClick:Me=>{if(Be.current){Me.preventDefault();return}ze()},onMouseDown:Me=>$e(Se.id,Me),onContextMenu:Me=>{Me.preventDefault(),o({project:Se,x:Me.clientX,y:Me.clientY})},className:`relative flex items-center gap-2.5 px-3 py-1.5 rounded-lg text-sm transition-all duration-200 hover:bg-theme-hover active:scale-95 group ${Ne?"font-medium":""} ${be?"opacity-50":""}`,style:Ne?{backgroundColor:"var(--color-bg-hover)",color:"var(--color-text-primary)",boxShadow:"var(--shadow-soft)",cursor:I?"grabbing":"pointer",userSelect:"none"}:{color:"var(--color-text-tertiary)",cursor:I?"grabbing":"pointer",userSelect:"none"},children:[Ne&&v.jsx("span",{className:"absolute left-0 top-1/4 bottom-1/4 w-[3px] rounded-r-full",style:{backgroundColor:ee}}),v.jsx("span",{className:`w-1.5 h-3 rounded-[2px] flex-shrink-0 ${ue?"workspace-dot-pulse":""}`,style:{backgroundColor:ee,opacity:Ne||ue?1:.55},title:ue?`${T("sidebar.workspaces")} · ${je} ${T("detail.live")}`:Se.name}),v.jsx("span",{className:"truncate flex-1",children:Se.name}),v.jsx(Ei,{onClick:Me=>lt(Se.id,Me),label:T("projects.delete"),size:"sm",variant:"danger",className:"flex-shrink-0 opacity-0 group-hover:opacity-100 focus-visible:opacity-100",children:v.jsx(Ri,{size:12})})]}),He&&st("below")]},Se.id)})})]}),b&&v.jsx(ix,{onSubmit:(Se,Ie)=>qe(Se,Ie),onCancel:()=>C(!1)}),v.jsxs("div",{className:"px-3 pt-3 pb-2 border-t",style:{borderColor:"var(--color-border)"},children:[v.jsxs("div",{className:"px-3 mb-2 flex items-center justify-between",children:[v.jsx("span",{className:"text-2xs font-semibold uppercase tracking-wider",style:{color:"var(--color-text-muted)"},children:T("sidebar.favorites")}),v.jsx(Ei,{onClick:()=>{k(null),y(!0)},label:T("favorites.add"),size:"sm",children:v.jsx(Mn,{size:14})})]}),v.jsx("div",{className:"space-y-0.5 max-h-48 overflow-y-auto",children:c.map(Se=>{const Ie=kx(Se.type);return v.jsxs("button",{onClick:()=>rt(Se.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:Se.target,children:[v.jsx(Ie,{size:14,className:"flex-shrink-0"}),v.jsx("span",{className:"truncate flex-1 text-left",children:Se.name}),v.jsx("span",{onClick:le=>Te(Se,le),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:T("favorites.edit"),children:v.jsx(Q1,{size:12})}),v.jsx("span",{onClick:le=>ye(Se.id,le),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:T("favorites.delete"),children:v.jsx(Ri,{size:12})})]},Se.id)})})]}),f&&v.jsx(rx,{initial:R??void 0,onSubmit:We,onCancel:()=>{y(!1),k(null)}}),p&&v.jsx(wx,{project:p.project,anchorX:p.x,anchorY:p.y,onPick:async Se=>{try{const Ie=await AS(p.project.id,{color:Se});u(le=>le.map(Ne=>Ne.id===Ie.id?{...Ne,color:Ie.color}:Ne)),window.dispatchEvent(new Event("projects:changed"))}catch(Ie){xe(Ie instanceof Error?Ie.message:"Failed to update color")}o(null)},onClose:()=>o(null)}),v.jsx(gg,{open:D,onClose:()=>E(!1)}),v.jsx("div",{className:"px-3 pb-4 pt-2",style:{borderTop:"1px solid var(--color-border)"},children:v.jsxs("div",{className:"flex items-center gap-1 px-1",children:[v.jsx("span",{className:`w-1.5 h-1.5 rounded-full flex-shrink-0 mr-1 ${w?"bg-status-success":"bg-status-error"}`,title:w?T("detail.live"):"Disconnected"}),v.jsx(Ei,{onClick:W,label:T(B==="light"?"theme.dark":"theme.light"),children:B==="light"?v.jsx(rg,{size:16}):v.jsx(lg,{size:16})}),v.jsx(Ei,{onClick:F,label:T("lang.toggle"),className:"text-xs font-medium",children:T("lang.toggle")}),ne&&v.jsx(Ei,{onClick:ge,label:"Notification"in window&&Notification.permission==="denied"?T("notification.blocked"):T("notification.toggle"),variant:Z?"active":"default",pressed:Z,children:Z?v.jsx(Xw,{size:16}):v.jsx(Yw,{size:16})}),v.jsx(Ei,{onClick:Oe,disabled:H,label:T("tunnel.start"),variant:(L==null?void 0:L.status)==="running"?"active":"default",pressed:(L==null?void 0:L.status)==="running",title:(L==null?void 0:L.status)==="running"&&L.url?`${L.url} — ${T("tunnel.urlCopied")}`:T(H?"tunnel.starting":"tunnel.start"),children:v.jsx(Ev,{size:16})}),v.jsx(Ei,{onClick:()=>E(!0),label:T("settings.title"),children:v.jsx(ag,{size:16})}),h&&v.jsx(Ei,{onClick:s,label:T("projects.logout"),variant:"danger",className:"ml-auto",children:v.jsx(H1,{size:16})})]})})]})}function Lx({children:s,onLogout:h,authRequired:w,connected:S,onEvent:M}){const[O,A]=j.useState(!1),{t:r}=Tt(),[u,d]=j.useState(()=>localStorage.getItem("sidebarCollapsed")==="1"),g=()=>{d(l=>{const m=!l;return localStorage.setItem("sidebarCollapsed",m?"1":"0"),m})};return v.jsxs("div",{className:"flex h-screen bg-theme-bg",children:[v.jsx("aside",{"data-app-sidebar":!0,className:`
403
403
  fixed inset-y-0 left-0 z-40 flex-shrink-0
404
404
  transition-[transform,width] duration-200 ease-in-out
405
405
  md:translate-x-0 md:static md:z-auto
@@ -419,7 +419,7 @@ WARNING: This link could potentially be dangerous`)){const c=window.open();if(c)
419
419
  `);console.debug("[paste] sending text, len=",fe.length,"multiline=",ht),Ne({type:"session:terminal-input",sessionId:s,input:d_(fe)});return}try{const ht=await uC(s);if(ht.path){console.debug("[paste] empty browser clipboard, using OS file path:",ht.path),Ne({type:"session:terminal-input",sessionId:s,input:ht.path});return}}catch(ht){console.debug("[paste] getClipboardImagePath failed:",ht)}console.warn("[paste] no content available (text empty, no image, no file path)"),(Ve=Be.current)==null||Ve.call(Be,"붙여넣을 내용을 클립보드에서 읽지 못했습니다. 우클릭 → 붙여넣기를 사용하세요.")};je.attachCustomKeyEventHandler(fe=>{var ei;if(fe.type!=="keydown")return!0;const Ve=ue?fe.metaKey:fe.ctrlKey,ht=ue?fe.ctrlKey:fe.metaKey,At=Ve&&!ht&&!fe.altKey&&!fe.shiftKey,Jt=Ve&&!ht&&!fe.altKey&&fe.shiftKey,jt=fe.key.toLowerCase();if(jt==="tab"&&(At||Jt)&&y.current)return fe.preventDefault(),y.current(Jt?"prev":"next"),!1;if(At&&/^[1-9]$/.test(jt)&&R.current)return fe.preventDefault(),R.current(Number(jt)-1),!1;if(jt==="f"&&At)return fe.preventDefault(),ye.current(),!1;if(jt==="t"&&At||jt==="r"&&Jt||jt==="f5"&&!fe.ctrlKey&&!fe.metaKey&&!fe.altKey&&!fe.shiftKey)return fe.preventDefault(),!1;if(jt==="d"&&Jt&&k.current)return fe.preventDefault(),k.current(),!1;if(Jt&&(["a","p","o","m","x","z"].includes(jt)||jt.startsWith("arrow")))return fe.preventDefault(),!1;if(At&&jt==="c"){const $t=je.getSelection();return $t?(fe.preventDefault(),(ei=navigator.clipboard)==null||ei.writeText($t).catch(()=>{}),je.clearSelection(),!1):!ue}if(At&&jt==="v"||fe.altKey&&!fe.ctrlKey&&!fe.metaKey&&!fe.shiftKey&&jt==="v")return fe.preventDefault(),be(),!1;if((fe.ctrlKey||fe.metaKey)&&!fe.altKey){if(fe.key==="+"||fe.key==="=")return fe.preventDefault(),bo(s,1),!1;if(fe.key==="-"||fe.key==="_")return fe.preventDefault(),bo(s,-1),!1}return!0});const he=new Jx.FitAddon;je.loadAddon(he),je.open(le),L.current=je,z.current=he;const He=new eC.SearchAddon;je.loadAddon(He),ge.current=He;const Me=He.onDidChangeResults(({resultIndex:fe,resultCount:Ve})=>{Xe.current({index:fe,count:Ve})}),Ge=()=>{We.current&&ct.current()};le.addEventListener("focusin",Ge),je.attachCustomWheelEventHandler(fe=>!fe.ctrlKey&&!fe.metaKey?!0:(fe.preventDefault(),fe.__zoomHandled=!0,fe.deltaY!==0&&bo(s,fe.deltaY<0?1:-1),!1));const se=fe=>{if(fe.ctrlKey||fe.metaKey){if(fe.preventDefault(),fe.stopPropagation(),fe.deltaY===0||fe.__zoomHandled)return;bo(s,fe.deltaY<0?1:-1);return}fe.stopPropagation()};le.addEventListener("wheel",se,{passive:!1});const V=window.electronAPI,ie=(Ze=V==null?void 0:V.onTerminalZoom)==null?void 0:Ze.call(V,fe=>{var ht;const Ve=le.matches(":hover");(ht=V.imeLog)==null||ht.call(V,{reason:"zoom:recv",dir:fe,hovered:Ve,path:window.location.pathname}),Ve&&bo(s,fe==="in"?1:-1)});st.current=()=>{be()};const Q=fe=>{fe.preventDefault(),lt({x:fe.clientX,y:fe.clientY,hasSelection:je.hasSelection()})};le.addEventListener("contextmenu",Q);try{he.fit()}catch{}if(l){const fe=document.activeElement;if(!(!!fe&&(fe.tagName==="INPUT"||fe.tagName==="TEXTAREA"||fe.tagName==="SELECT"||fe.isContentEditable))&&(fe===null||fe===document.body))try{je.focus()}catch{}}const ke=()=>{const fe=je.cols,Ve=je.rows;fe===P.current.cols&&Ve===P.current.rows||(P.current={cols:fe,rows:Ve},M({type:"session:resize",sessionId:s,cols:fe,rows:Ve}))};$.current=ke;const ce=O(s,fe=>{try{je.write(fe)}catch{}}),_e=A(fe=>{fe.type==="session:replay-end"&&fe.sessionId===s&&T(!1)}),Ee=()=>Date.now()-ee<300,Pe=()=>f.current,Ue=fe=>W.current(fe),ot=(fe,Ve,ht)=>qe.current(fe,Ve,ht),Ye=mC()?SC({container:le,term:je,sessionId:s,sendMessage:Ne}):wC({container:le,term:je,sessionId:s,sendMessage:Ne,isPasteAlreadyHandled:Ee,isImagePasteDisabled:Pe,onComposingChange:Ue,onImagePasted:ot}),ut=100;let ft=null,kt=0,vt=!1;const Vt={cols:je.cols,rows:je.rows},Nt=new ResizeObserver(()=>{if(ft!==null)return;const fe=Math.max(0,ut-(performance.now()-kt));ft=setTimeout(()=>{ft=null,requestAnimationFrame(()=>{var ht;kt=performance.now();const Ve=le.getBoundingClientRect();if(!(Ve.width===0||Ve.height===0)){try{he.fit(),(je.cols!==Vt.cols||je.rows!==Vt.rows)&&(Vt.cols=je.cols,Vt.rows=je.rows,je.refresh(0,je.rows-1))}catch{}!vt&&je.cols>=20&&je.rows>=5&&(vt=!0,(ht=Y.current)==null||ht.call(Y,je.cols,je.rows)),I.current&&clearTimeout(I.current),I.current=setTimeout(ke,150)}})},fe)});return Nt.observe(le),()=>{var fe;Nt.disconnect(),ft!==null&&clearTimeout(ft),I.current&&clearTimeout(I.current),K.current&&clearTimeout(K.current),le.removeEventListener("wheel",se),ie==null||ie(),le.removeEventListener("contextmenu",Q),lt(null),Ye(),ce(),_e();try{M({type:"session:unsubscribe",sessionId:s})}catch{}le.removeEventListener("focusin",Ge),Me.dispose(),ge.current=null,(fe=H.current)==null||fe.dispose(),H.current=null,je.dispose(),L.current=null,z.current=null,$.current=null,X.current=!1}},[s]),j.useEffect(()=>{const le=L.current;if(le){if(l&&!H.current)try{const Ne=new Cg.CanvasAddon;le.loadAddon(Ne),H.current=Ne}catch{H.current=null}else if(!l&&H.current){try{H.current.dispose()}catch{}H.current=null}}},[l,s]),j.useEffect(()=>{if(!w||X.current)return;X.current=!0;const le=L.current;le&&le.cols>0&&le.rows>0&&(P.current={cols:0,rows:0},M({type:"session:resize",sessionId:s,cols:le.cols,rows:le.rows})),M({type:"session:subscribe",sessionId:s})},[w,s,M]),j.useEffect(()=>{L.current&&(L.current.options.cursorBlink=h)},[h]),j.useEffect(()=>{var ue;if(!l)return;const le=document.activeElement;if(!(!(!!le&&le.classList.contains("xterm-helper-textarea"))&&!!le&&(le.tagName==="INPUT"||le.tagName==="TEXTAREA"||le.tagName==="SELECT"||le.isContentEditable)))try{(ue=L.current)==null||ue.focus()}catch{}},[l]),j.useEffect(()=>{const le=L.current,Ne=z.current;if(!le||!Ne||le.options.fontSize===u)return;if(le.options.fontSize=u,H.current){try{H.current.dispose()}catch{}H.current=null;try{const ue=new Cg.CanvasAddon;le.loadAddon(ue),H.current=ue}catch{}}if(le.buffer.active.type==="alternate"){K.current&&clearTimeout(K.current),K.current=setTimeout(()=>{var ue;(ue=D.current)==null||ue.call(D)},500);return}try{Ne.fit(),le.refresh(0,le.rows-1)}catch{}le.cols===P.current.cols&&le.rows===P.current.rows||(K.current&&clearTimeout(K.current),K.current=setTimeout(()=>{var ue;(ue=$.current)==null||ue.call($)},300))},[u,s]),j.useEffect(()=>{const le=L.current;if(le){le.options.theme=d??el,le.options.minimumContrastRatio=Dg(d??el);try{le.refresh(0,le.rows-1)}catch{}}},[d]),j.useEffect(()=>{if(!J)return;const le=ge.current;if(!le)return;const Ne=setTimeout(()=>{de?le.findNext(de,{...eh,incremental:!0}):(le.clearDecorations(),Oe({index:-1,count:0}))},120);return()=>clearTimeout(Ne)},[de,J]),j.useEffect(()=>{var le;J&&((le=xe.current)==null||le.select())},[J]);const St=(d==null?void 0:d.background)??Ce.bg,Se=()=>{var le;de&&((le=ge.current)==null||le.findNext(de,eh))},Ie=()=>{var le;de&&((le=ge.current)==null||le.findPrevious(de,eh))};return v.jsxs("div",{style:{position:"relative",background:St,padding:12,height:r,width:"100%",boxSizing:"border-box",overflow:"hidden"},children:[U&&w&&v.jsx("div",{style:{position:"absolute",top:8,right:12,fontFamily:_t,fontSize:11,color:Ce.dim,zIndex:1,pointerEvents:"none"},children:"loading history…"}),v.jsx("div",{ref:E,"data-term-container":!0,style:{height:"100%",width:"100%"}}),J&&v.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 ${Ce.separator}`,borderRadius:6,fontFamily:_t,fontSize:12,boxShadow:"0 4px 16px rgba(0,0,0,0.5)"},children:[v.jsx("input",{ref:xe,value:de,onChange:le=>oe(le.target.value),onKeyDown:le=>{le.key==="Enter"?(le.preventDefault(),le.shiftKey?Ie():Se()):le.key==="Escape"&&(le.preventDefault(),Te())},placeholder:"검색",spellCheck:!1,style:{width:160,background:"transparent",border:"none",outline:"none",color:Ce.bright,fontFamily:_t,fontSize:12}}),v.jsx("span",{style:{color:Ce.dim,minWidth:44,textAlign:"right",fontVariantNumeric:"tabular-nums"},children:de?Ae.count>0?`${Ae.index+1}/${Ae.count}`:"0/0":""}),[{label:"↑",title:"이전 (Shift+Enter)",onClick:Ie},{label:"↓",title:"다음 (Enter)",onClick:Se},{label:"×",title:"닫기 (Esc)",onClick:Te}].map(le=>v.jsx("button",{type:"button",title:le.title,onClick:le.onClick,className:"px-1.5 rounded-md hover:bg-white/10",style:{color:Ce.bright,lineHeight:"18px"},children:le.label},le.label))]}),(F||Z)&&v.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:[Z&&v.jsxs("div",{style:{padding:4,background:"rgba(0,0,0,0.72)",border:`1px solid ${Ce.separator}`,borderRadius:4,maxWidth:"100%"},children:[v.jsx("img",{src:Z.dataUrl,alt:"",style:{display:"block",maxWidth:220,maxHeight:140,borderRadius:2}}),v.jsxs("div",{style:{fontFamily:_t,fontSize:11,color:Ce.dim,marginTop:3},children:["이미지 붙여넣음 · ",fC(Z.bytes)]})]}),F&&v.jsx("div",{style:{maxWidth:"100%",padding:"3px 8px",background:"rgba(0,0,0,0.72)",border:`1px solid ${Ce.separator}`,borderRadius:4,fontFamily:_t,fontSize:Math.max(12,u),color:Ce.bright,lineHeight:1.3,whiteSpace:"pre",overflow:"hidden",textOverflow:"ellipsis"},children:F})]}),$e&&zi.createPortal((()=>{const je=Math.max(8,Math.min($e.x,window.innerWidth-184-8)),ue=Math.max(8,Math.min($e.y,window.innerHeight-116-8)),ee=()=>lt(null),be=()=>{var Ge,se;const Me=((Ge=L.current)==null?void 0:Ge.getSelection())??"";Me&&((se=navigator.clipboard)==null||se.writeText(Me).catch(()=>{})),ee()},he=()=>{st.current(),ee()},He=()=>{var Me;(Me=L.current)==null||Me.selectAll(),ee()};return v.jsxs(v.Fragment,{children:[v.jsx("div",{style:{position:"fixed",inset:0,zIndex:2147483646},onMouseDown:ee,onContextMenu:Me=>{Me.preventDefault(),ee()}}),v.jsxs("div",{role:"menu",style:{position:"fixed",left:je,top:ue,zIndex:2147483647,minWidth:168,background:Ce.bg,border:`1px solid ${Ce.separator}`,borderRadius:6,padding:4,fontFamily:_t,fontSize:13,boxShadow:"0 8px 24px rgba(0,0,0,0.5)"},children:[v.jsx("button",{type:"button",disabled:!$e.hasSelection,onClick:be,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:Ce.bright},children:"복사"}),v.jsx("button",{type:"button",onClick:he,className:"w-full text-left px-3 py-1.5 rounded-md hover:bg-white/10",style:{color:Ce.bright},children:"붙여넣기"}),v.jsx("button",{type:"button",onClick:He,className:"w-full text-left px-3 py-1.5 rounded-md hover:bg-white/10",style:{color:Ce.bright},children:"전체 선택"})]})]})})(),document.body)]})}function mC(){if(typeof navigator>"u")return!1;const s=navigator.userAgent;return/iPad|iPhone|iPod/.test(s)||/Mac/.test(s)&&navigator.maxTouchPoints>1||/Android/i.test(s)}const dl=[12593,12594,12596,12599,12600,12601,12609,12610,12611,12613,12614,12615,12616,12617,12618,12619,12620,12621,12622],f_=[12623,12624,12625,12626,12627,12628,12629,12630,12631,12632,12633,12634,12635,12636,12637,12638,12639,12640,12641,12642,12643],Tg=[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 p_(s){return s>=12593&&s<=12622}function m_(s){return s>=12623&&s<=12643}function gC(s){return p_(s)||m_(s)}function vC(s){return s>=44032&&s<=55203}function _C(){return{cho:-1,jung:-1,jong:0}}function Ih(s){return s.cho<0&&s.jung<0&&s.jong===0}function Ms(s){return Ih(s)?"":s.cho>=0&&s.jung>=0?String.fromCharCode(44032+(s.cho*21+s.jung)*28+s.jong):s.cho>=0?String.fromCharCode(dl[s.cho]):s.jung>=0?String.fromCharCode(f_[s.jung]):""}function Mg(s){const h=Ms(s);return s.cho=-1,s.jung=-1,s.jong=0,h}function bC(s,h){if(m_(h)){const w=f_.indexOf(h);if(w<0)return"";if(s.cho<0&&s.jung<0||s.cho>=0&&s.jung<0)return s.jung=w,"";if(s.cho<0&&s.jung>=0){const A=Ms(s);return s.jung=w,A}if(s.jong===0){const A=Ms(s);return s.cho=-1,s.jung=w,s.jong=0,A}const S=Tg[s.jong],M=dl.indexOf(S);s.jong=0;const O=Ms(s);return M>=0?(s.cho=M,s.jung=w,s.jong=0):(s.cho=-1,s.jung=w,s.jong=0),O}if(p_(h)){const w=dl.indexOf(h),S=Tg.indexOf(h);if(s.cho<0&&s.jung<0)return w>=0?(s.cho=w,""):String.fromCharCode(h);if(s.cho>=0&&s.jung<0){const O=String.fromCharCode(dl[s.cho]);return w>=0?(s.cho=w,O):(s.cho=-1,O+String.fromCharCode(h))}if(s.cho<0&&s.jung>=0){const O=Ms(s);return s.jung=-1,w>=0?(s.cho=w,O):O+String.fromCharCode(h)}if(s.jong===0){if(S>0)return s.jong=S,"";const O=Ms(s);return s.cho=w>=0?w:-1,s.jung=-1,s.jong=0,O}const M=Ms(s);return s.cho=w>=0?w:-1,s.jung=-1,s.jong=0,w<0?M+String.fromCharCode(h):M}return""}function yC(s,h){const w=Ms(s),S=h-44032;return s.cho=Math.floor(S/588),s.jung=Math.floor(S/28)%21,s.jong=S%28,w}function Ag(s){return Ih(s)?!1:(s.cho=-1,s.jung=-1,s.jong=0,!0)}function wC({container:s,term:h,sessionId:w,sendMessage:S,isPasteAlreadyHandled:M,isImagePasteDisabled:O,onComposingChange:A,onImagePasted:r}){let u=!1;const d=L=>{try{A==null||A(L)}catch{}};let g=null;const l=(L,z={})=>{var H,P;try{(P=(H=window.electronAPI)==null?void 0:H.imeLog)==null||P.call(H,{reason:L,path:window.location.pathname,...z})}catch{}},m=(L=!1)=>{try{const z=s.querySelector(".xterm-helper-textarea"),H=s.querySelector(".xterm-screen");if(!z||!H){L||l("pos:no-dom",{hasHelper:!!z,hasScreen:!!H});return}const P=h.cols,I=h.rows;if(P<=0||I<=0){L||l("pos:no-grid",{cols:P,rows:I});return}const K=H.getBoundingClientRect();if(K.width===0||K.height===0){L||l("pos:zero-screen",{w:K.width,h:K.height});return}const X=K.width/P,Y=K.height/I,$=h.buffer.active,U=Math.min($.cursorX,P-1),T=Math.max(0,Math.min($.cursorY,I-1));z.style.left=`${U*X}px`,z.style.top=`${T*Y}px`,z.style.width=`${Math.max(X,1)}px`,z.style.height=`${Math.max(Y,1)}px`,L||l("pos:applied",{cursorX:U,cursorY:T,left:U*X,top:T*Y})}catch{}};m();let b=0;const C=()=>{b||(b=requestAnimationFrame(()=>{b=0,m(!0)}))},p=h.onCursorMove(C),o=()=>{var L;u=!0,m(),d("");try{const z=document.activeElement,H=s.querySelector(".xterm-helper-textarea"),P=H==null?void 0:H.getBoundingClientRect();l("compositionstart",{activeTag:z==null?void 0:z.tagName,activeClass:z==null?void 0:z.className,activeIsHelper:!!z&&((L=z.classList)==null?void 0:L.contains("xterm-helper-textarea")),helperStyleLeft:H==null?void 0:H.style.left,helperStyleTop:H==null?void 0:H.style.top,helperRectLeft:P==null?void 0:P.left,helperRectTop:P==null?void 0:P.top,visibility:document.visibilityState,hasFocus:document.hasFocus(),cols:h.cols,rows:h.rows})}catch{}},c=L=>{d(L.data??""),l("compositionupdate",{data:L.data??""})},a=L=>{u=!1,d("");const z=L.data;l("compositionend",{data:z??"",sent:!!z}),z&&(g=z,S({type:"session:terminal-input",sessionId:w,input:z}))},f=L=>{var P,I;if(M()){L.preventDefault();return}const z=(P=L.clipboardData)==null?void 0:P.items;if(z&&!(O!=null&&O())){for(let K=0;K<z.length;K++)if(z[K].type.startsWith("image/")){L.preventDefault();const X=z[K].getAsFile();if(!X)return;const Y=new FileReader;Y.onload=()=>{const $=Y.result;console.debug("[paste-fallback] image via paste event, bytes=",X.size);const U=c_(w,$,X.name);U.catch(T=>console.warn("[paste-fallback] pasteImage failed:",T)),r==null||r($,X.size,U)},Y.readAsDataURL(X);return}}const H=(I=L.clipboardData)==null?void 0:I.getData("text/plain");if(H){L.preventDefault();const K=H.includes(`
420
420
  `);console.debug("[paste-fallback] sending text, len=",H.length,"multiline=",K),S({type:"session:terminal-input",sessionId:w,input:d_(H)})}else console.debug("[paste-fallback] paste event had no usable text/image")},y=L=>{var K,X;const z=(K=L.dataTransfer)==null?void 0:K.files;if(!z||z.length===0)return;L.preventDefault();const H=(X=window.electronAPI)==null?void 0:X.getDroppedFilePath;if(!H)return;const P=[];for(let Y=0;Y<z.length;Y++){const $=H(z[Y]);$&&P.push($)}const I=dC(P);I&&S({type:"session:terminal-input",sessionId:w,input:I})},R=L=>{var z,H;(H=(z=L.dataTransfer)==null?void 0:z.types)!=null&&H.includes("Files")&&(L.preventDefault(),L.dataTransfer.dropEffect="copy")},k=()=>{if(u)return;h_(()=>{try{h.focus()}catch{}})&&l("focus-rescue")},D=L=>{var z,H;l("keydown",{key:L.key,composing:u,activeIsHelper:!!((H=(z=document.activeElement)==null?void 0:z.classList)!=null&&H.contains("xterm-helper-textarea")),hasFocus:document.hasFocus()}),document.hasFocus()||k()};s.addEventListener("keydown",D,!0),s.addEventListener("compositionstart",o,!0),s.addEventListener("compositionupdate",c,!0),s.addEventListener("compositionend",a,!0),s.addEventListener("paste",f,!0),s.addEventListener("dragover",R),s.addEventListener("drop",y);const E=h.onData(L=>{if(!u){if(g!==null&&L===g){g=null;return}g=null,S({type:"session:terminal-input",sessionId:w,input:L})}});return()=>{E.dispose(),p.dispose(),b&&cancelAnimationFrame(b),s.removeEventListener("keydown",D,!0),s.removeEventListener("compositionstart",o,!0),s.removeEventListener("compositionupdate",c,!0),s.removeEventListener("compositionend",a,!0),s.removeEventListener("paste",f,!0),s.removeEventListener("dragover",R),s.removeEventListener("drop",y),d("")}}function SC({container:s,term:h,sessionId:w,sendMessage:S}){const M=s.querySelector(".xterm-helper-textarea");let O="",A=0;M&&(O=M.style.display,A=M.tabIndex,M.style.display="none",M.tabIndex=-1),getComputedStyle(s).position==="static"&&(s.style.position="relative");const r=document.createElement("textarea");r.setAttribute("autocomplete","off"),r.setAttribute("lang","ko"),r.setAttribute("inputmode","text"),r.rows=1,Object.assign(r.style,{position:"absolute",background:"transparent",border:"none",outline:"none",padding:"0",margin:"0",fontFamily:_t,fontSize:"16px",lineHeight:"1.2",resize:"none",overflow:"hidden",whiteSpace:"pre",caretColor:"rgba(255,255,255,0.001)",zIndex:"5"});const u=()=>{Object.assign(r.style,{inset:"0",left:"auto",top:"auto",width:"100%",height:"100%",color:"transparent"})},d=()=>{const k=s.querySelector(".xterm-screen");if(!k)return;const D=h.cols,E=h.rows;if(D<=0||E<=0)return;const L=k.clientWidth/D,z=k.clientHeight/E,H=h.buffer.active.cursorX,P=h.buffer.active.cursorY,I=k.getBoundingClientRect(),K=s.getBoundingClientRect();Object.assign(r.style,{inset:"auto",left:`${I.left-K.left+H*L}px`,top:`${I.top-K.top+P*z}px`,width:`${Math.max(L*30,240)}px`,height:`${Math.max(z,20)}px`,color:Ce.text})};u(),s.appendChild(r);let g=!1;const l=_C();let m=null;const b=()=>{m&&(clearTimeout(m),m=null)},C=k=>{k&&S({type:"session:terminal-input",sessionId:w,input:k})},p=()=>{const k=Mg(l);k&&C(k)},o=()=>{const k=Ms(l);r.value=k,k?d():u()},c=()=>{b(),m=setTimeout(()=>{m=null,p(),r.value="",u()},600)},a=()=>{g=!0,b(),p(),d()},f=k=>{g=!1,k.data&&C(k.data),r.value="",u()};r.addEventListener("compositionstart",a),r.addEventListener("compositionend",f);const y=k=>{if(g)return;const D=k;switch(D.inputType){case"insertCompositionText":case"insertFromComposition":return;case"deleteContentBackward":b(),Ag(l)?o():(C(""),r.value="",u());return;case"insertLineBreak":case"insertParagraph":b(),p(),C("\r"),r.value="",u();return;default:if(!D.data){o();return}b();let E="";for(const L of D.data){const z=L.codePointAt(0);gC(z)?E+=bC(l,z):vC(z)?E+=yC(l,z):(E+=Mg(l),E+=L)}C(E),o(),Ih(l)||c()}};r.addEventListener("input",y);const R=k=>{if(g||k.isComposing)return;let D=null;switch(k.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(k.preventDefault(),b(),k.key==="Backspace"){if(Ag(l)){o();return}}else p();C(D),r.value="",u();return}if(k.ctrlKey&&!k.metaKey&&!k.altKey&&k.key.length===1){const E=k.key.toUpperCase().charCodeAt(0);E>=64&&E<=95&&(k.preventDefault(),b(),p(),C(String.fromCharCode(E-64)),r.value="",u())}};return r.addEventListener("keydown",R),()=>{b(),p(),r.remove(),M&&(M.style.display=O,M.tabIndex=A)}}function xC(s){switch(s){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 CC({files:s,loading:h,selectedFile:w,onFileClick:S,commitHash:M}){const{t:O}=Tt();return v.jsxs("div",{className:"h-full flex flex-col",children:[v.jsxs("div",{className:"px-3 py-2 border-b border-warm-100 flex items-center justify-between shrink-0",children:[v.jsx("span",{className:"text-[11px] font-semibold text-warm-500 uppercase tracking-wider",children:O("git.changedFiles")}),v.jsxs("div",{className:"flex items-center gap-2",children:[v.jsxs("span",{className:"text-2xs text-warm-400",children:[s.length," ",O("git.files")]}),M&&v.jsx("span",{className:"text-2xs font-mono text-warm-400",children:M.substring(0,7)})]})]}),h?v.jsx("div",{className:"flex-1 flex items-center justify-center",children:v.jsx("span",{className:"text-xs text-warm-400",children:O("git.loadingFiles")})}):s.length===0?v.jsx("div",{className:"flex-1 flex items-center justify-center",children:v.jsx("span",{className:"text-xs text-warm-400",children:O("git.noFilesChanged")})}):v.jsx("div",{className:"flex-1 overflow-y-auto",children:s.map(A=>{const r=xC(A.status),u=w===A.path;return v.jsxs("div",{onClick:()=>S(A.path),className:`flex items-center gap-2 px-3 py-1.5 cursor-pointer text-xs hover:bg-warm-50/50 transition-colors ${u?"bg-accent/10 border-l-2 border-accent":""}`,children:[v.jsx("span",{className:`font-mono font-bold text-2xs w-3 shrink-0 ${r.color}`,children:r.label}),v.jsxs("span",{className:"truncate flex-1 text-warm-600",title:A.path,children:[A.path.split("/").pop(),v.jsx("span",{className:"text-warm-400 ml-1 text-2xs",children:A.path.includes("/")?A.path.substring(0,A.path.lastIndexOf("/")):""})]}),v.jsxs("span",{className:"shrink-0 text-2xs text-status-success",children:["+",A.additions]}),v.jsxs("span",{className:"shrink-0 text-2xs text-status-error",children:["-",A.deletions]})]},A.path)})})]})}function kC({diff:s,loading:h,selectedFile:w,fileHeaders:S}){const{t:M}=Tt(),[O,A]=j.useState(!0);return w?h?v.jsx("div",{className:"h-full flex items-center justify-center",children:v.jsx("span",{className:"text-xs text-warm-400",children:M("git.loadingDiff")})}):v.jsxs("div",{className:"h-full flex flex-col bg-[#1A1A1A]",children:[v.jsxs("div",{className:"px-3 py-2 border-b border-gray-700 shrink-0 flex items-center justify-between gap-2",children:[v.jsx("span",{className:"text-xs font-mono text-gray-100 truncate",title:w,children:w}),v.jsx("button",{onClick:()=>A(r=>!r),title:M("git.wrapLines")||"Wrap lines",className:`p-1 rounded-md shrink-0 hover:bg-gray-700 ${O?"text-accent":"text-gray-500"}`,children:v.jsx(vS,{size:14})})]}),v.jsx("div",{className:"flex-1 overflow-auto",children:v.jsx("div",{className:"p-3 font-mono text-xs leading-relaxed",children:s?(()=>{let r=0,u=0,d=!1;return s.split(`
421
421
  `).map((g,l)=>{if(S&&g.startsWith("Index: "))return d=!1,v.jsx("div",{className:"mt-3 first:mt-0 mb-1 pb-1 border-b border-gray-700 font-semibold text-gray-100",children:g.slice(7)},l);if(g.startsWith("@@")){const p=/@@ -(\d+)(?:,\d+)? \+(\d+)(?:,\d+)? @@/.exec(g);return p&&(r=parseInt(p[1],10),u=parseInt(p[2],10),d=!0),null}if(!d)return null;let m="text-gray-200",b=null,C=null;if(g.startsWith("+")&&!g.startsWith("+++"))m="text-gray-100 bg-green-500/20",C=u++;else if(g.startsWith("-")&&!g.startsWith("---"))m="text-gray-100 bg-red-500/20",b=r++;else if(g.startsWith(" "))b=r++,C=u++;else return null;return v.jsxs("div",{className:`flex items-start ${m}`,children:[v.jsx("span",{className:"select-none shrink-0 w-9 pr-2 text-right text-gray-500",children:b??""}),v.jsx("span",{className:"select-none shrink-0 w-9 pr-2 text-right text-gray-500",children:C??""}),v.jsx("span",{className:`flex-1 min-w-0 ${O?"whitespace-pre-wrap break-words":"whitespace-pre"}`,children:g||" "})]},l)})})():v.jsx("span",{className:"text-gray-400 italic",children:"No changes"})})})]}):v.jsx("div",{className:"h-full flex items-center justify-center",children:v.jsx("span",{className:"text-sm text-warm-400",children:M("git.selectFileToViewDiff")})})}function EC({sessionId:s,onClose:h,projectId:w,onEvent:S,sendMessage:M}){const{t:O}=Tt(),[A,r]=j.useState([]),[u,d]=j.useState(!0),[g,l]=j.useState(null),[m,b]=j.useState(!1),[C,p]=j.useState(null),[o,c]=j.useState(""),[a,f]=j.useState(!1),[y,R]=j.useState(0),[k,D]=j.useState([]),[E,L]=j.useState(null),[z,H]=j.useState(!1),[P,I]=j.useState({from:null,now:null}),K=j.useRef(new Map),X=j.useCallback(()=>R(U=>U+1),[]);j.useEffect(()=>{if(!(!M||!w))return M({type:"git:watch",projectId:w}),()=>M({type:"git:unwatch",projectId:w})},[M,w]),j.useEffect(()=>{if(!(!S||!w))return S(U=>{U.type==="git:changed"&&U.projectId===w&&X()})},[S,w,X]),j.useEffect(()=>{let U=!1;return nC(s).then(T=>{U||D(T.snapshots??[])}).catch(()=>{U||D([])}),()=>{U=!0}},[s,y]),j.useEffect(()=>{let U=!1;return b(!0),iC(s,E??void 0).then(T=>{if(U)return;d(T.available),l(T.reason??null);const F=T.available&&T.files?T.files.map(B=>({path:B.path,status:B.status,additions:B.insertions,deletions:B.deletions})):[];r(F),K.current.clear(),I({from:E,now:T.now??null}),p(B=>B&&F.some(W=>W.path===B)?B:F.length>0?F[0].path:null)}).catch(()=>{U||(d(!1),l("error"),r([]))}).finally(()=>{U||b(!1)}),()=>{U=!0}},[s,E,y]),j.useEffect(()=>{if(!C){c("");return}const U=`${P.now??""}:${C}`,T=K.current.get(U);if(T!==void 0){c(T),f(!1);return}let F=!1;return f(!0),c(""),sC(s,C,P.from??void 0,P.now??void 0).then(B=>{if(F)return;const W=B.available&&B.diff?B.diff:"";K.current.set(U,W),c(W)}).catch(()=>{F||c("")}).finally(()=>{F||f(!1)}),()=>{F=!0}},[s,C,P]);const Y=j.useCallback(()=>{H(!0),rC(s).then(U=>{if(U.available&&U.snapshots){D(U.snapshots);const T=U.snapshots[U.snapshots.length-1];T&&L(T.sha)}}).catch(()=>{}).finally(()=>H(!1))},[s]),$=U=>{const T=new Date(U);return Number.isNaN(T.getTime())?U:T.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})};return v.jsxs("div",{className:"h-full flex flex-col bg-warm-50",children:[v.jsxs("div",{className:"flex items-center justify-between px-3 py-2 border-b border-warm-100 shrink-0",children:[v.jsx("span",{className:"text-xs font-semibold text-warm-600",children:O("session.diff.title")||"Diff"}),v.jsxs("div",{className:"flex items-center gap-1",children:[v.jsx("button",{onClick:Y,disabled:z||!u,title:O("session.diff.capture")||"Capture snapshot",className:"p-1 rounded-md hover:bg-warm-100 text-warm-500 disabled:opacity-40",children:v.jsx(e1,{size:14,className:z?"animate-pulse":""})}),v.jsx("button",{onClick:X,title:O("common.refresh")||"Refresh",className:"p-1 rounded-md hover:bg-warm-100 text-warm-500",children:v.jsx(Av,{size:14,className:m?"animate-spin":""})}),v.jsx("button",{onClick:h,title:O("common.close")||"Close",className:"p-1 rounded-md hover:bg-warm-100 text-warm-500",children:v.jsx(Ri,{size:14})})]})]}),k.length>0&&v.jsxs("div",{className:"flex items-center gap-1 px-3 py-1.5 border-b border-warm-100 overflow-x-auto shrink-0",children:[v.jsx(jg,{active:E===null,onClick:()=>L(null),label:O("session.diff.pageStart")||"From start"}),k.map(U=>v.jsx(jg,{active:E===U.sha,onClick:()=>L(U.sha),label:`#${U.seq} ${$(U.at)}`},U.sha))]}),u?v.jsxs("div",{className:"flex-1 flex min-h-0",children:[v.jsx("div",{className:"w-2/5 min-w-[180px] max-w-[320px] border-r border-warm-100 overflow-hidden",children:v.jsx(CC,{files:A,loading:m,selectedFile:C,onFileClick:p})}),v.jsx("div",{className:"flex-1 min-w-0",children:v.jsx(kC,{diff:o,loading:a,selectedFile:C})})]}):v.jsx("div",{className:"flex-1 flex items-center justify-center px-4 text-center",children:v.jsx("span",{className:"text-xs text-warm-400",children:g==="not-git"?O("session.diff.notGit")||"Not a git repository":O("session.diff.unavailable")||"Diff unavailable"})})]})}function jg({active:s,onClick:h,label:w}){return v.jsx("button",{onClick:h,className:`px-2 py-0.5 rounded-md text-[11px] whitespace-nowrap shrink-0 ${s?"bg-warm-600 text-white":"bg-warm-100 text-warm-600 hover:bg-warm-200"}`,children:w})}const LC={presetId:u_},Ao=new Map,mr=new Map;function g_(s){return`sessionTheme:${s}`}window.addEventListener("storage",s=>{var S;if(s.storageArea!==localStorage||!((S=s.key)!=null&&S.startsWith("sessionTheme:")))return;const h=s.key.slice(13);Ao.delete(h);const w=mr.get(h);if(w){const M=vh(h);w.forEach(O=>O(M))}});function RC(s){return typeof s!="string"?!1:s==="custom"||s in oi}function vh(s){const h=Ao.get(s);if(h!==void 0)return h;let w=LC;try{const S=localStorage.getItem(g_(s));if(S!==null){const M=JSON.parse(S);M&&RC(M.presetId)&&(w={presetId:M.presetId,custom:M.custom&&typeof M.custom=="object"?M.custom:void 0})}}catch{}return Ao.set(s,w),w}function DC(s,h){const w=Ao.get(s);if(w&&w.presetId===h.presetId&&TC(w.custom,h.custom))return;Ao.set(s,h);try{localStorage.setItem(g_(s),JSON.stringify(h))}catch{}const S=mr.get(s);S&&S.forEach(M=>M(h))}function TC(s,h){return s===h?!0:!s||!h?!1:s.background===h.background&&s.foreground===h.foreground&&s.cursor===h.cursor&&s.selectionBackground===h.selectionBackground&&s.accent===h.accent}function MC(s){if(s.presetId!=="custom")return Rg(s.presetId).theme;const h=Rg(u_).theme,w=s.custom??{},S=w.cursor??w.accent??h.cursor;return{...h,background:w.background??h.background,foreground:w.foreground??h.foreground,cursor:S,cursorAccent:w.background??h.cursorAccent,selectionBackground:w.selectionBackground??h.selectionBackground,brightBlue:w.accent??h.brightBlue,blue:w.accent??h.blue}}function v_(s){const[h,w]=j.useState(()=>vh(s));j.useEffect(()=>{w(vh(s));let O=mr.get(s);return O||(O=new Set,mr.set(s,O)),O.add(w),()=>{const A=mr.get(s);A&&(A.delete(w),A.size===0&&mr.delete(s))}},[s]);const S=j.useCallback(O=>DC(s,O),[s]),M=j.useMemo(()=>MC(h),[h]);return[h,M,S]}function __({session:s,visible:h,intent:w,intentNonce:S,onClose:M,sendMessage:O,subscribeBinary:A,onEvent:r,onCycleTab:u,onSelectTab:d,remountKey:g=0}){const{t:l}=Tt(),m=s.status==="running"||w==="start"||w==="resume"?"pendingFit":"replay-only",[b,C]=j.useState(m),[p,o]=j.useState(null),[c,a]=j.useState(!1),[f,y]=j.useState(480),R=!!s.is_git_repo,k=j.useRef(null),D=j.useCallback(ye=>{ye.preventDefault();const Te=k.current;if(!Te)return;const ct=ze=>{const qe=Te.getBoundingClientRect(),Fe=240,Be=Math.max(Fe,qe.width-200);y(Math.min(Be,Math.max(Fe,qe.right-ze.clientX)))},it=()=>{window.removeEventListener("mousemove",ct),window.removeEventListener("mouseup",it),document.body.style.cursor="",document.body.style.userSelect=""};window.addEventListener("mousemove",ct),window.addEventListener("mouseup",it),document.body.style.cursor="col-resize",document.body.style.userSelect="none"},[]),[E,L]=j.useState(0),z=j.useCallback(()=>L(ye=>ye+1),[]),H=j.useRef(null),P=j.useRef(!1),I=j.useRef(S),[K,X]=j.useState(null),[Y,$]=j.useState(null),[U,T]=j.useState(!1),[F,B]=j.useState(null),[W,Z]=j.useState(null),ne=j.useRef(s.status==="running");j.useEffect(()=>{s.status==="running"&&b!=="subscribed"&&b!=="starting"&&b!=="pendingFit"&&(ne.current=!0,C("subscribed"))},[s.status,b]),j.useEffect(()=>{if(s.status==="running"||!ne.current||b!=="subscribed"&&b!=="stopping")return;const ye=setTimeout(()=>M(),300);return()=>clearTimeout(ye)},[s.status,b,M]);const ge=j.useCallback(async()=>{const ye=H.current;if(ye&&!P.current){P.current=!0,C("starting"),o(null),Z(null);try{const Te=await oC(s.id,ye,w==="resume"?{continueSession:!0}:void 0);C("subscribed"),Te.pendingInitialPrompt?(X(Te.pendingInitialPromptLength??0),$(null),T(!1)):(X(null),$(null))}catch(Te){const ct=Te instanceof Error?Te.message:String(Te);o(ct),C("error")}finally{P.current=!1}}},[s.id,w]),xe=j.useCallback(async()=>{if(U){T(!1);return}if(T(!0),Y===null)try{const ye=await aC(s.id);$(ye.prompt??"")}catch(ye){Z(ye instanceof Error?ye.message:String(ye))}},[U,Y,s.id]),J=j.useCallback(async()=>{if(!F){B("send"),Z(null);try{await lC(s.id),X(null),$(null),T(!1)}catch(ye){Z(ye instanceof Error?ye.message:String(ye))}finally{B(null)}}},[F,s.id]),G=j.useCallback(async()=>{if(!F){B("skip"),Z(null);try{await cC(s.id),X(null),$(null),T(!1)}catch(ye){Z(ye instanceof Error?ye.message:String(ye))}finally{B(null)}}},[F,s.id]);j.useEffect(()=>{if(S===I.current)return;I.current=S,(w==="start"||w==="resume")&&b==="replay-only"&&s.status!=="running"&&(H.current?ge():C("pendingFit"))},[S,w,b,s.status,ge]);const de=j.useCallback(()=>{H.current?ge():C("pendingFit")},[ge]),oe=j.useCallback((ye,Te)=>{H.current={cols:ye,rows:Te},b==="pendingFit"&&(s.status==="running"?(ne.current=!0,C("subscribed")):ge())},[b,ge,s.status]),Ae=s.status==="running",Oe=b==="subscribed",[Xe]=qv(s.id),[,We]=v_(s.id),rt=b==="starting"||b==="pendingFit"?v.jsxs("div",{style:{...tl,pointerEvents:"none"},children:[v.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[v.jsx(lh,{size:14,style:{animation:"spin 1s linear infinite",color:Ce.dim}}),v.jsx("span",{style:{color:Ce.dim,fontFamily:_t,fontSize:12},children:l("session.starting")||"starting…"})]}),v.jsx("span",{style:{color:Ce.dim,fontFamily:_t,fontSize:10,marginTop:6},children:l("session.starting.typeAhead")||"type-ahead is captured and replayed once ready"})]}):b==="stopping"?v.jsx("div",{style:{...tl,pointerEvents:"none"},children:v.jsx("span",{style:{color:Ce.dim,fontFamily:_t,fontSize:12},children:l("session.stopping")||"stopping…"})}):b==="replay-only"?v.jsx("div",{style:tl,children:v.jsxs("button",{onClick:de,style:{display:"flex",alignItems:"center",gap:8,fontFamily:_t,fontSize:14,color:Ce.bright,background:"transparent",border:`1px solid ${Ce.separator}`,padding:"10px 22px",borderRadius:6,cursor:"pointer"},children:[v.jsx(tS,{size:16})," ",l("session.startInWindow")||"Start"]})}):b==="error"?v.jsxs("div",{style:tl,children:[v.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,color:Ce.error,fontFamily:_t,fontSize:12,marginBottom:8},children:[v.jsx(kv,{size:14})," ",l("session.startFailed")||"failed to start"]}),p&&v.jsx("div",{style:{color:Ce.dim,fontFamily:_t,fontSize:11,marginBottom:8,maxWidth:360,textAlign:"center",wordBreak:"break-word"},children:p}),v.jsx("button",{onClick:()=>{ge()},style:{fontFamily:_t,fontSize:12,color:Ce.bright,background:"transparent",border:`1px solid ${Ce.separator}`,padding:"4px 12px",borderRadius:4,cursor:"pointer"},children:l("common.retry")||"Retry"})]}):null;return v.jsxs("div",{ref:k,style:{display:h?"flex":"none",flexDirection:"row",position:"absolute",inset:0,background:Ce.bg},children:[v.jsxs("div",{style:{position:"relative",flex:1,minWidth:0,height:"100%"},children:[v.jsx(pC,{sessionId:s.id,isRunning:Ae,subscribed:Oe,onFitted:oe,sendMessage:O,subscribeBinary:A,onEvent:r,fontSize:Xe,theme:We,inputBlocked:K!==null,autoFocusOnMount:h,onRequestRefresh:z,disableImagePaste:s.cli_tool==="raw-shell",onCycleTab:u,onSelectTab:d,onToggleDiff:()=>{R&&a(ye=>!ye)}},`${g}:${E}`),rt,R&&!c&&v.jsxs("button",{onClick:()=>a(!0),title:`${l("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:_t,fontSize:10,color:Ce.dim,background:"rgba(20,20,28,0.7)",border:`1px solid ${Ce.separator}`,padding:"2px 8px",borderRadius:4,cursor:"pointer"},children:[v.jsx(k1,{size:12})," Diff"]}),K!==null&&v.jsxs("div",{style:AC,children:[v.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[v.jsx(d1,{"aria-hidden":!0,size:14,style:{color:Ce.info}}),v.jsxs("span",{style:{flex:1},children:[l("session.initialPrompt.ready")||"Initial prompt ready",v.jsxs("span",{style:{color:Ce.dim,marginLeft:8},children:[K.toLocaleString()," chars"]}),v.jsx("div",{style:{color:Ce.warning,fontSize:10,marginTop:2},children:l("session.initialPrompt.blocked")||"Press Send or Skip before typing — keystrokes are ignored until then."})]}),v.jsxs("button",{onClick:xe,style:th("neutral"),title:U?l("session.initialPrompt.hidePreview")||"Hide preview":l("session.initialPrompt.preview")||"Preview",children:[U?v.jsx(Cv,{size:12}):v.jsx(Dh,{size:12}),U?l("session.initialPrompt.hidePreview")||"Hide":l("session.initialPrompt.preview")||"Preview"]}),v.jsxs("button",{onClick:J,disabled:F!==null,style:th("primary"),children:[F==="send"?v.jsx(lh,{size:12,style:{animation:"spin 1s linear infinite"}}):v.jsx(uS,{size:12}),l("session.initialPrompt.send")||"Send"]}),v.jsx("button",{onClick:G,disabled:F!==null,style:th("danger"),children:l("session.initialPrompt.skip")||"Skip"})]}),W&&v.jsx("div",{style:{color:Ce.error,fontSize:10,marginTop:4},children:W}),U&&v.jsx("pre",{style:{margin:0,marginTop:6,maxHeight:240,overflow:"auto",background:"rgba(0,0,0,0.4)",padding:8,fontFamily:_t,fontSize:10,color:Ce.bright,whiteSpace:"pre-wrap",wordBreak:"break-word",border:`1px solid ${Ce.separator}`,borderRadius:4},children:Y===null?l("session.initialPrompt.loading")||"loading…":Y})]})]}),R&&c&&v.jsxs(v.Fragment,{children:[v.jsx("div",{onMouseDown:D,style:{width:5,flexShrink:0,cursor:"col-resize",background:Ce.separator}}),v.jsx("div",{style:{width:f,flexShrink:0,minWidth:0,height:"100%"},children:v.jsx(EC,{sessionId:s.id,projectId:s.project_id,onEvent:r,sendMessage:O,onClose:()=>a(!1)})})]})]})}const AC={position:"absolute",top:0,left:0,right:0,background:"rgba(28,28,38,0.96)",borderBottom:`1px solid ${Ce.separator}`,borderLeft:`3px solid ${Ce.warning}`,padding:"8px 10px",color:Ce.bright,fontFamily:_t,fontSize:11,zIndex:3,display:"flex",flexDirection:"column"};function th(s){const h={display:"inline-flex",alignItems:"center",gap:4,fontFamily:_t,fontSize:10,padding:"3px 8px",borderRadius:4,cursor:"pointer",border:`1px solid ${Ce.separator}`,background:"transparent"};return s==="primary"?{...h,color:Ce.bright,borderColor:Ce.info,background:`${Ce.info}22`}:s==="danger"?{...h,color:Ce.dim}:{...h,color:Ce.bright}}const tl={position:"absolute",inset:0,background:"rgba(12,12,12,0.85)",display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",zIndex:1e3},Og=340;function jC({sessionId:s}){var C,p,o,c,a,f;const[h,,w]=v_(s),[S,M]=j.useState(!1),[O,A]=j.useState(!1),[r,u]=j.useState({top:0,left:0}),d=j.useRef(null),g=j.useRef(null),l=j.useCallback(()=>{if(!d.current)return;const y=d.current.getBoundingClientRect(),R=window.innerWidth,k=window.innerHeight,D=g.current;let E=y.bottom+4,L=y.right-Og;if(D){const z=D.offsetHeight,H=D.offsetWidth;L=y.right-H,L<8&&(L=8),L+H>R-8&&(L=R-8-H),E+z>k-8&&(E=Math.max(8,y.top-z-4))}else L<8&&(L=8);u({top:E,left:L}),A(!0)},[]);j.useEffect(()=>{if(!S){A(!1);return}l();const y=requestAnimationFrame(l),R=D=>{var L,z;const E=D.target;(L=d.current)!=null&&L.contains(E)||(z=g.current)!=null&&z.contains(E)||M(!1)},k=D=>{D.key==="Escape"&&M(!1)};return document.addEventListener("mousedown",R),document.addEventListener("keydown",k),window.addEventListener("scroll",l,!0),window.addEventListener("resize",l),()=>{cancelAnimationFrame(y),document.removeEventListener("mousedown",R),document.removeEventListener("keydown",k),window.removeEventListener("scroll",l,!0),window.removeEventListener("resize",l)}},[S,l]);const m=y=>{if(y==="custom"){const R=h.custom??{background:oi.default.theme.background,foreground:oi.default.theme.foreground,cursor:oi.default.theme.cursor,selectionBackground:oi.default.theme.selectionBackground,accent:oi.default.theme.brightBlue};w({presetId:"custom",custom:R})}else w({presetId:y,custom:h.custom}),M(!1)},b=y=>{const R={...h.custom??{},...y};w({presetId:"custom",custom:R})};return v.jsxs(v.Fragment,{children:[v.jsx("button",{ref:d,"data-no-drag":!0,onMouseDown:y=>y.stopPropagation(),onClick:()=>M(y=>!y),"aria-label":"terminal-theme",title:"Terminal theme (Ctrl+Shift+P)",style:{background:"transparent",border:"none",color:Ce.titleText,cursor:"pointer",padding:"0 6px",display:"flex",alignItems:"center",justifyContent:"center",borderRadius:0,flexShrink:0,height:"100%"},children:v.jsx(G1,{size:14})}),S&&zi.createPortal(v.jsxs("div",{ref:g,className:"z-tooltip",style:{position:"fixed",top:r.top,left:r.left,width:Og,background:"#1e1e1e",border:`1px solid ${Ce.separator}`,borderRadius:6,padding:10,fontFamily:_t,color:Ce.text,boxShadow:"0 8px 24px rgba(0,0,0,0.5)",opacity:O?1:0,transition:"opacity 80ms"},onMouseDown:y=>y.stopPropagation(),children:[v.jsx("div",{style:{fontSize:10,color:Ce.dim,marginBottom:6,letterSpacing:.5},children:"DARK"}),v.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(3, 1fr)",gap:6,marginBottom:10},children:Lg.filter(y=>!oi[y].light).map(y=>v.jsx(Bg,{preset:oi[y],selected:h.presetId===y,onClick:()=>m(y)},y))}),v.jsx("div",{style:{fontSize:10,color:Ce.dim,marginBottom:6,letterSpacing:.5},children:"LIGHT"}),v.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(3, 1fr)",gap:6,marginBottom:10},children:[Lg.filter(y=>oi[y].light).map(y=>v.jsx(Bg,{preset:oi[y],selected:h.presetId===y,onClick:()=>m(y)},y)),v.jsx(OC,{selected:h.presetId==="custom",accent:((C=h.custom)==null?void 0:C.accent)??oi.default.theme.brightBlue??"#569cd6",onClick:()=>m("custom")})]}),h.presetId==="custom"&&v.jsxs("div",{style:{borderTop:`1px solid ${Ce.separator}`,paddingTop:8},children:[v.jsx("div",{style:{fontSize:10,color:Ce.dim,marginBottom:6,letterSpacing:.5},children:"CUSTOM COLORS"}),v.jsx(yo,{label:"Background",value:((p=h.custom)==null?void 0:p.background)??oi.default.theme.background??"#0c0c0c",onChange:y=>b({background:y})}),v.jsx(yo,{label:"Foreground",value:((o=h.custom)==null?void 0:o.foreground)??oi.default.theme.foreground??"#cccccc",onChange:y=>b({foreground:y})}),v.jsx(yo,{label:"Cursor",value:((c=h.custom)==null?void 0:c.cursor)??oi.default.theme.cursor??"#f2f2f2",onChange:y=>b({cursor:y})}),v.jsx(yo,{label:"Selection",value:((a=h.custom)==null?void 0:a.selectionBackground)??oi.default.theme.selectionBackground??"#264f78",onChange:y=>b({selectionBackground:y})}),v.jsx(yo,{label:"Accent",value:((f=h.custom)==null?void 0:f.accent)??oi.default.theme.brightBlue??"#569cd6",onChange:y=>b({accent:y})})]})]}),document.body)]})}function Bg({preset:s,selected:h,onClick:w}){return v.jsxs("button",{onClick:w,style:{position:"relative",background:s.theme.background,border:`1px solid ${h?s.accent:Ce.separator}`,outline:h?`1px solid ${s.accent}`:"none",outlineOffset:-2,borderRadius:4,padding:"6px 8px",cursor:"pointer",fontFamily:_t,fontSize:10,color:s.theme.foreground,textAlign:"left",height:52,display:"flex",flexDirection:"column",justifyContent:"space-between",overflow:"hidden"},children:[v.jsxs("div",{style:{display:"flex",alignItems:"center",gap:4},children:[v.jsx("span",{style:{width:8,height:8,borderRadius:"50%",background:s.accent,flexShrink:0}}),v.jsx("span",{style:{fontWeight:600,fontSize:11,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:s.name}),h&&v.jsx(Do,{size:12,style:{marginLeft:"auto",flexShrink:0}})]}),v.jsxs("div",{style:{fontSize:9,opacity:.85,fontFamily:_t},children:[v.jsx("span",{style:{color:s.theme.green},children:"$"})," ",v.jsx("span",{style:{color:s.theme.brightBlue},children:"ls"})]})]})}function OC({selected:s,accent:h,onClick:w}){return v.jsxs("button",{onClick:w,style:{position:"relative",background:"#0c0c0c",border:`1px dashed ${s?h:Ce.separator}`,outline:s?`1px solid ${h}`:"none",outlineOffset:-2,borderRadius:4,padding:"6px 8px",cursor:"pointer",fontFamily:_t,fontSize:10,color:Ce.text,textAlign:"left",height:52,display:"flex",flexDirection:"column",justifyContent:"space-between",overflow:"hidden"},children:[v.jsxs("div",{style:{display:"flex",alignItems:"center",gap:4},children:[v.jsx("span",{style:{width:8,height:8,borderRadius:"50%",background:h,flexShrink:0}}),v.jsx("span",{style:{fontWeight:600,fontSize:11},children:"Custom"}),s&&v.jsx(Do,{size:12,style:{marginLeft:"auto",flexShrink:0}})]}),v.jsx("div",{style:{fontSize:9,opacity:.7},children:"edit colors"})]})}function yo({label:s,value:h,onChange:w}){const[S,M]=j.useState(h);j.useEffect(()=>{M(h)},[h]);const O=A=>{M(A);const r=A.startsWith("#")?A:`#${A}`;(/^#[0-9a-fA-F]{6}$/.test(r)||/^#[0-9a-fA-F]{3}$/.test(r))&&w(Ng(r))};return v.jsxs("label",{style:{display:"flex",alignItems:"center",gap:8,padding:"4px 0",fontSize:11,color:Ce.text},children:[v.jsx("span",{style:{flex:1},children:s}),v.jsx("input",{type:"text",value:S,onChange:A=>O(A.target.value),onBlur:()=>M(h),spellCheck:!1,style:{width:64,padding:"2px 4px",fontSize:10,fontFamily:_t,color:Ce.text,background:"transparent",border:`1px solid ${Ce.separator}`,borderRadius:3}}),v.jsx("input",{type:"color",value:Ng(h),onChange:A=>w(A.target.value),style:{width:28,height:22,padding:0,border:`1px solid ${Ce.separator}`,borderRadius:3,background:"transparent",cursor:"pointer"}})]})}function Ng(s){return/^#[0-9a-fA-F]{6}$/.test(s)?s.toLowerCase():/^#[0-9a-fA-F]{3}$/.test(s)?("#"+s.slice(1).split("").map(h=>h+h).join("")).toLowerCase():"#000000"}const zg=360;function BC({sessionId:s,sendMessage:h}){const[w,S]=j.useState(!1),[M,O]=j.useState(!1),[A,r]=j.useState({top:0,left:0}),[u,d]=j.useState(null),[g,l]=j.useState(""),[m,b]=j.useState(!1),[C,p]=j.useState(""),[o,c]=j.useState(""),[a,f]=j.useState(!1),[y,R]=j.useState(null),k=j.useRef(null),D=j.useRef(null),E=j.useRef(null),L=j.useCallback(()=>{if(!k.current)return;const X=k.current.getBoundingClientRect(),Y=window.innerWidth,$=window.innerHeight,U=D.current;let T=X.bottom+4,F=X.right-zg;if(U){const B=U.offsetHeight,W=U.offsetWidth;F=X.right-W,F<8&&(F=8),F+W>Y-8&&(F=Y-8-W),T+B>$-8&&(T=Math.max(8,X.top-B-4))}else F<8&&(F=8);r({top:T,left:F}),O(!0)},[]);j.useEffect(()=>{if(!w)return;let X=!1;return Uv().then(Y=>{X||d(Y)}).catch(Y=>{X||R(Y instanceof Error?Y.message:"Failed to load")}),()=>{X=!0}},[w]),j.useEffect(()=>{if(!w){O(!1);return}L();const X=requestAnimationFrame(L),Y=requestAnimationFrame(()=>{requestAnimationFrame(()=>{var T;return(T=E.current)==null?void 0:T.focus()})}),$=T=>{var B,W;const F=T.target;(B=k.current)!=null&&B.contains(F)||(W=D.current)!=null&&W.contains(F)||S(!1)},U=T=>{T.key==="Escape"&&S(!1)};return document.addEventListener("mousedown",$),document.addEventListener("keydown",U),window.addEventListener("scroll",L,!0),window.addEventListener("resize",L),()=>{cancelAnimationFrame(X),cancelAnimationFrame(Y),document.removeEventListener("mousedown",$),document.removeEventListener("keydown",U),window.removeEventListener("scroll",L,!0),window.removeEventListener("resize",L)}},[w,L]),j.useEffect(()=>{w||(l(""),b(!1),p(""),c(""),R(null))},[w]);const z=j.useMemo(()=>{if(!u)return[];const X=g.trim().toLowerCase();return X?u.filter(Y=>Y.name.toLowerCase().includes(X)||Y.command_template.toLowerCase().includes(X)):u},[u,g]),H=X=>{h({type:"session:terminal-input",sessionId:s,input:X.command_template}),S(!1)},P=X=>{X.key==="Enter"&&z.length>0&&(X.preventDefault(),H(z[0]))},I=!!C.trim()&&!!o.trim()&&!a,K=async()=>{if(I){f(!0),R(null);try{const X=await $v({name:C.trim(),command_template:o.trim()});d(Y=>Y?[X,...Y]:[X]),p(""),c(""),b(!1)}catch(X){R(X instanceof Error?X.message:"Failed")}finally{f(!1)}}};return v.jsxs(v.Fragment,{children:[v.jsx("button",{ref:k,"data-no-drag":!0,onMouseDown:X=>X.stopPropagation(),onClick:()=>S(X=>!X),"aria-label":"alias-inserter",title:"Insert saved command (alias) (Ctrl+Shift+A)",style:NC,children:v.jsx(g1,{size:14})}),w&&zi.createPortal(v.jsxs("div",{ref:D,className:"z-tooltip",style:{position:"fixed",top:A.top,left:A.left,width:zg,background:"#1e1e1e",border:`1px solid ${Ce.separator}`,borderRadius:6,padding:10,fontFamily:_t,color:Ce.text,boxShadow:"0 8px 24px rgba(0,0,0,0.5)",opacity:M?1:0,transition:"opacity 80ms"},onMouseDown:X=>X.stopPropagation(),children:[v.jsx("input",{ref:E,type:"text",value:g,onChange:X=>l(X.target.value),onKeyDown:P,placeholder:"Filter aliases… (Enter inserts first match)",style:{width:"100%",boxSizing:"border-box",background:"#0c0c0c",border:`1px solid ${Ce.separator}`,borderRadius:4,color:Ce.bright,fontFamily:_t,fontSize:11,padding:"6px 8px",outline:"none"}}),v.jsx("div",{style:{marginTop:8,maxHeight:280,overflowY:"auto"},children:u===null?v.jsx("div",{style:Hg,children:"Loading…"}):z.length===0?v.jsx("div",{style:Hg,children:u.length===0?"No aliases yet — add one below.":"No matches."}):z.map(X=>v.jsxs("button",{onClick:()=>H(X),style:zC,onMouseEnter:Y=>Y.currentTarget.style.background="rgba(255,255,255,0.06)",onMouseLeave:Y=>Y.currentTarget.style.background="transparent",title:`Insert: ${X.command_template}`,children:[v.jsx("span",{style:{fontSize:11,color:Ce.bright,fontWeight:600},children:X.name}),v.jsx("code",{style:{fontSize:10,color:Ce.dim,marginLeft:8,flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:X.command_template})]},X.id))}),v.jsx("div",{style:{borderTop:`1px solid ${Ce.separator}`,marginTop:8,paddingTop:8},children:m?v.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:6},children:[v.jsx("input",{type:"text",value:C,onChange:X=>p(X.target.value),placeholder:"Name (e.g. git status)",maxLength:64,style:Pg}),v.jsx("input",{type:"text",value:o,onChange:X=>c(X.target.value),onKeyDown:X=>{X.key==="Enter"&&(X.preventDefault(),K())},placeholder:"Command (e.g. git status -sb)",maxLength:1024,style:{...Pg,fontFamily:_t}}),y&&v.jsx("div",{style:{fontSize:10,color:"#f87171"},children:y}),v.jsxs("div",{style:{display:"flex",justifyContent:"flex-end",gap:6},children:[v.jsxs("button",{type:"button",onClick:()=>{b(!1),R(null)},style:b_,children:[v.jsx(Ri,{size:12})," Cancel"]}),v.jsx("button",{type:"button",onClick:K,disabled:!I,style:{...HC,opacity:I?1:.5},children:"Save"})]})]}):v.jsxs("button",{type:"button",onClick:()=>{b(!0),R(null)},style:PC,children:[v.jsx(Mn,{size:12})," New alias"]})})]}),document.body)]})}const NC={background:"transparent",border:"none",color:Ce.titleText,cursor:"pointer",padding:"0 6px",display:"flex",alignItems:"center",justifyContent:"center",borderRadius:0,flexShrink:0,height:"100%"},Hg={fontSize:11,color:Ce.dim,padding:"12px 4px",textAlign:"center"},zC={display:"flex",alignItems:"center",width:"100%",background:"transparent",border:"none",padding:"6px 8px",cursor:"pointer",textAlign:"left",borderRadius:3,transition:"background 80ms"},Pg={width:"100%",boxSizing:"border-box",background:"#0c0c0c",border:`1px solid ${Ce.separator}`,borderRadius:4,color:Ce.bright,fontSize:11,padding:"5px 7px",outline:"none"},b_={display:"inline-flex",alignItems:"center",gap:3,background:"transparent",border:`1px solid ${Ce.separator}`,color:Ce.dim,fontFamily:_t,fontSize:10,padding:"3px 8px",borderRadius:4,cursor:"pointer"},HC={...b_,background:"rgba(86,156,214,0.13)",border:"1px solid #569cd6",color:Ce.bright},PC={display:"inline-flex",alignItems:"center",gap:4,background:"transparent",border:"none",color:Ce.dim,fontFamily:_t,fontSize:11,padding:"4px 0",cursor:"pointer"};function IC({orientation:s,onDragStart:h,onDrag:w,onDragEnd:S}){const M=j.useCallback(A=>{if(A.button!==0)return;A.preventDefault(),A.stopPropagation();const r=A.clientX,u=A.clientY;h();let d=!1;const g=()=>{d||(d=!0,window.removeEventListener("mousemove",C),window.removeEventListener("mouseup",p),window.removeEventListener("blur",l),window.removeEventListener("keydown",m),document.removeEventListener("visibilitychange",b))},l=()=>{g(),S()},m=o=>{o.key==="Escape"&&l()},b=()=>{document.hidden&&l()},C=o=>{const c=s==="horizontal"?o.clientX-r:o.clientY-u;w(c)},p=()=>{g(),S()};window.addEventListener("mousemove",C),window.addEventListener("mouseup",p),window.addEventListener("blur",l),window.addEventListener("keydown",m),document.addEventListener("visibilitychange",b)},[s,h,w,S]),O=s==="horizontal";return v.jsx("div",{onMouseDown:M,style:{flex:"0 0 4px",background:Ce.separator,cursor:O?"col-resize":"row-resize",position:"relative",zIndex:1}})}function Fh(s){const{node:h,path:w,onSplitSizes:S,zoomPath:M,...O}=s;return h.kind==="stack"?v.jsx(Wh,{stack:h,path:w,...O}):v.jsx(FC,{split:h,path:w,onSplitSizes:S,zoomPath:M,stackProps:O})}const Ig=80;function FC({split:s,path:h,onSplitSizes:w,zoomPath:S,stackProps:M}){const O=s.orientation==="horizontal",A=j.useRef(null),r=j.useRef([]),u=j.useRef(null);return v.jsx("div",{ref:A,style:{display:"flex",flexDirection:O?"row":"column",flex:1,minWidth:0,minHeight:0},children:s.children.map((d,g)=>v.jsxs(j.Fragment,{children:[v.jsx("div",{ref:l=>{r.current[g]=l},style:{flex:S?"1 1 0%":`0 0 ${s.sizes[g]}%`,display:S&&S[h.length]!==g?"none":"flex",flexDirection:"column",minWidth:0,minHeight:0,overflow:"hidden"},children:v.jsx(Fh,{node:d,path:[...h,g],onSplitSizes:w,zoomPath:S,...M})}),!S&&g<s.children.length-1&&v.jsx(IC,{orientation:s.orientation,onDragStart:()=>{const l=A.current;if(!l)return;const m=s.sizes.slice();u.current={i:g,initialSizes:m,finalSizes:m.slice(),total:O?l.clientWidth:l.clientHeight}},onDrag:l=>{const m=u.current;if(!m||m.total<=0)return;const b=m.initialSizes[m.i]/100*m.total,C=m.initialSizes[m.i+1]/100*m.total,p=b+C,o=Math.max(Ig,Math.min(p-Ig,b+l)),c=p-o,a=o/m.total*100,f=c/m.total*100,y=r.current[m.i],R=r.current[m.i+1];y&&(y.style.flexBasis=`${a}%`),R&&(R.style.flexBasis=`${f}%`);const k=m.initialSizes.slice();k[m.i]=a,k[m.i+1]=f,m.finalSizes=k},onDragEnd:()=>{const l=u.current;l&&w(h,l.finalSizes),u.current=null}})]},g))})}const tt=28,Ut=68;function Dl(s,h,w){const S=s-w.x,M=h-w.y;if(S<0||M<0||S>w.w||M>w.h)return null;const O=S-w.w/2,A=M-w.h/2;return Math.abs(O)<=tt&&Math.abs(A)<=tt?"center":O>=-Ut-tt&&O<=-Ut+tt&&Math.abs(A)<=tt?"left":O>=Ut-tt&&O<=Ut+tt&&Math.abs(A)<=tt?"right":A>=-Ut-tt&&A<=-Ut+tt&&Math.abs(O)<=tt?"top":A>=Ut-tt&&A<=Ut+tt&&Math.abs(O)<=tt?"bottom":null}function bl(s,h){const w=document.elementsFromPoint(s,h);for(const S of w){const M=S.closest("[data-group-id][data-stack-path]");if(!M)continue;const O=M.dataset.stackPath||"",A=O===""?[]:O.split(".").map(Number),r=M.getBoundingClientRect(),u={x:r.left,y:r.top,w:r.width,h:r.height};return{groupId:M.dataset.groupId||"",path:A,rect:u,zone:Dl(s,h,u)}}return null}function UC(s,h){const w=s.w/2,S=s.h/2;switch(h){case"center":return s;case"left":return{x:s.x,y:s.y,w,h:s.h};case"right":return{x:s.x+w,y:s.y,w,h:s.h};case"top":return{x:s.x,y:s.y,w:s.w,h:S};case"bottom":return{x:s.x,y:s.y+S,w:s.w,h:S}}}const _h=Ut*2+12;function y_(s,h,w,S){const M=s-w/2,O=h-S/2;return Math.abs(M)<=tt&&Math.abs(O)<=tt?"max":M>=-Ut-tt&&M<=-Ut+tt&&Math.abs(O)<=tt?"left":M>=Ut-tt&&M<=Ut+tt&&Math.abs(O)<=tt?"right":O>=-Ut-tt&&O<=-Ut+tt&&Math.abs(M)<=tt?"top":O>=Ut-tt&&O<=Ut+tt&&Math.abs(M)<=tt?"bottom":O>=-_h-tt&&O<=-_h+tt&&Math.abs(M)<=tt?"popout":null}function w_(s,h,w,S,M){switch(s){case"left":return{x:M,y:0,w:h,h:S};case"right":return{x:w-h,y:0,w:h,h:S};case"top":return{x:M,y:0,w:w-M,h};case"bottom":return{x:M,y:S-h,w:w-M,h}}}function jo(s,h,w,S){if(s==="max")return{x:S,y:0,w:h-S,h:w};const M=Math.round(s==="left"||s==="right"?(h-S)/2:w/2);return w_(s,M,h,w,S)}function gr(){const s=document.querySelector("[data-app-sidebar]");return Math.max(0,s?s.getBoundingClientRect().right:0)}function S_({activeZone:s}){const h=window.innerWidth,w=window.innerHeight,S=h/2,M=w/2,O=s&&s!=="popout"?jo(s,h,w,gr()):null;return zi.createPortal(v.jsxs(v.Fragment,{children:[O&&v.jsx("div",{style:{position:"fixed",left:O.x,top:O.y,width:O.w,height:O.h,background:`${Ce.info}33`,border:`2px dashed ${Ce.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"}}),v.jsxs("div",{style:{position:"fixed",inset:0,pointerEvents:"none",zIndex:2500},children:[v.jsx(ts,{offsetX:S-tt,offsetY:M-tt,active:s==="max",kind:"center"}),v.jsx(ts,{offsetX:S-Ut-tt,offsetY:M-tt,active:s==="left",kind:"left"}),v.jsx(ts,{offsetX:S+Ut-tt,offsetY:M-tt,active:s==="right",kind:"right"}),v.jsx(ts,{offsetX:S-tt,offsetY:M-Ut-tt,active:s==="top",kind:"top"}),v.jsx(ts,{offsetX:S-tt,offsetY:M+Ut-tt,active:s==="bottom",kind:"bottom"}),v.jsx(ts,{offsetX:S-tt,offsetY:M-_h-tt,active:s==="popout",kind:"popout"})]})]}),document.body)}function vr({targetRect:s,activeZone:h}){const w=s.x+s.w/2,S=s.y+s.h/2,M=h?UC(s,h):null;return zi.createPortal(v.jsxs(v.Fragment,{children:[M&&v.jsx("div",{style:{position:"fixed",left:M.x,top:M.y,width:M.w,height:M.h,background:`${Ce.info}33`,border:`2px dashed ${Ce.info}`,borderRadius:4,pointerEvents:"none",zIndex:2400,boxSizing:"border-box"}}),(()=>{const O=Ut+tt;return v.jsxs("div",{style:{position:"fixed",left:w-O,top:S-O,width:O*2,height:O*2,pointerEvents:"none",zIndex:2500},children:[v.jsx(ts,{offsetX:O-tt,offsetY:O-tt,active:h==="center",kind:"center"}),v.jsx(ts,{offsetX:O-Ut-tt,offsetY:O-tt,active:h==="left",kind:"left"}),v.jsx(ts,{offsetX:O+Ut-tt,offsetY:O-tt,active:h==="right",kind:"right"}),v.jsx(ts,{offsetX:O-tt,offsetY:O-Ut-tt,active:h==="top",kind:"top"}),v.jsx(ts,{offsetX:O-tt,offsetY:O+Ut-tt,active:h==="bottom",kind:"bottom"})]})})()]}),document.body)}function ts({offsetX:s,offsetY:h,active:w,kind:S}){const M=tt*2,O=w?Ce.info:"#3a3a3a",A=w?Ce.bright:Ce.separator;return v.jsx("div",{style:{position:"absolute",left:s,top:h,width:M,height:M,background:"#1a1a1a",border:`1px solid ${A}`,borderRadius:4,boxShadow:w?`0 0 8px ${Ce.info}`:"0 1px 3px rgba(0,0,0,0.4)",boxSizing:"border-box",overflow:"hidden"},children:v.jsx($C,{kind:S,fill:O})})}function $C({kind:s,fill:h}){const w={position:"absolute",background:h};switch(s){case"center":return v.jsx("div",{style:{...w,inset:4}});case"popout":return v.jsx("div",{style:{position:"absolute",inset:0,display:"flex",alignItems:"center",justifyContent:"center"},children:v.jsx(_r,{size:24,color:h})});case"left":return v.jsxs(v.Fragment,{children:[v.jsx("div",{style:{...w,left:4,top:4,bottom:4,width:"calc(50% - 4px)"}}),v.jsx("div",{style:{position:"absolute",right:4,top:4,bottom:4,width:"calc(50% - 4px)",border:`1px dashed ${h}`,boxSizing:"border-box"}})]});case"right":return v.jsxs(v.Fragment,{children:[v.jsx("div",{style:{position:"absolute",left:4,top:4,bottom:4,width:"calc(50% - 4px)",border:`1px dashed ${h}`,boxSizing:"border-box"}}),v.jsx("div",{style:{...w,right:4,top:4,bottom:4,width:"calc(50% - 4px)"}})]});case"top":return v.jsxs(v.Fragment,{children:[v.jsx("div",{style:{...w,top:4,left:4,right:4,height:"calc(50% - 4px)"}}),v.jsx("div",{style:{position:"absolute",bottom:4,left:4,right:4,height:"calc(50% - 4px)",border:`1px dashed ${h}`,boxSizing:"border-box"}})]});case"bottom":return v.jsxs(v.Fragment,{children:[v.jsx("div",{style:{position:"absolute",top:4,left:4,right:4,height:"calc(50% - 4px)",border:`1px dashed ${h}`,boxSizing:"border-box"}}),v.jsx("div",{style:{...w,bottom:4,left:4,right:4,height:"calc(50% - 4px)"}})]})}}function WC(s){const[h,w]=j.useState(()=>typeof window>"u"||!window.matchMedia?!1:window.matchMedia(s).matches);return j.useEffect(()=>{if(typeof window>"u"||!window.matchMedia)return;const S=window.matchMedia(s),M=O=>w(O.matches);return w(S.matches),S.addEventListener("change",M),()=>S.removeEventListener("change",M)},[s]),h}const il=320,sl=200,nl=80,rl=22,qC=4,Fg=8,sn=10,ol=60,GC=12;function nn(s,h,w){return Math.max(h,Math.min(w,s))}function YC(s,h,w,S){const M=s<=Fg,O=s>=w-Fg;if(!M&&!O)return null;const A=S/3,r=S*2/3;return M?h<A?"top-left":h>r?"bottom-left":"left":h<A?"top-right":h>r?"bottom-right":"right"}function Ug(s,h,w){const S=Math.round(h/2),M=Math.round(w/2);switch(s){case"left":return{x:0,y:0,w:S,h:w};case"right":return{x:h-S,y:0,w:S,h:w};case"top-left":return{x:0,y:0,w:S,h:M};case"top-right":return{x:h-S,y:0,w:S,h:M};case"bottom-left":return{x:0,y:w-M,w:S,h:M};case"bottom-right":return{x:h-S,y:w-M,w:S,h:M}}}function KC(s,h,w,S,M){let O=s,A=h;const r=O,u=O+w,d=A,g=A+S;for(const l of M){const m=l.x,b=l.x+l.w,C=l.y,p=l.y+l.h;d<p&&g>C&&(Math.abs(r-b)<=sn?O=b:Math.abs(u-m)<=sn?O=m-w:Math.abs(r-m)<=sn?O=m:Math.abs(u-b)<=sn&&(O=b-w)),r<b&&u>m&&(Math.abs(d-p)<=sn?A=p:Math.abs(g-C)<=sn?A=C-S:Math.abs(d-C)<=sn?A=C:Math.abs(g-p)<=sn&&(A=p-S))}return{x:O,y:A}}function XC({group:s,sessionsById:h,neighbors:w,isTopmost:S,zIndex:M,sendMessage:O,subscribeBinary:A,onEvent:r}){const{t:u}=Tt(),d=WC("(max-width: 767px)"),g=VC(),l=j.useRef(null),[m,b]=j.useState(!1),C=j.useRef(null),[p,o]=j.useState(null),c=j.useRef({x:s.x,y:s.y,w:s.w,h:s.h});c.current={x:s.x,y:s.y,w:s.w,h:s.h};const[a,f]=j.useState(null),y=j.useRef(null),[R,k]=j.useState(!1),[D,E]=j.useState(null),L=j.useRef(null),z=j.useRef(w);z.current=w;const[H,P]=j.useState(null),I=j.useRef(null),K=j.useCallback((ye,Te)=>{if(d||m||ye.button!==0||ye.target.closest("[data-no-drag]"))return;ye.preventDefault(),g.focus(Ft(s.root)[0]||"");const it=ye.clientX,ze=ye.clientY,qe={...c.current},Fe=l.current,Be=window.innerWidth,$e=window.innerHeight,lt=gr();let st=!1,St="";Te&&Fe&&(St=Fe.style.pointerEvents,Fe.style.pointerEvents="none");let Se=!1;const Ie=()=>{Se||(Se=!0,window.removeEventListener("mousemove",ee),window.removeEventListener("mouseup",be),window.removeEventListener("blur",le),window.removeEventListener("keydown",Ne),document.removeEventListener("visibilitychange",je),Te&&Fe&&(Fe.style.pointerEvents=St))},le=()=>{Ie(),I.current=null,P(null),y.current=null,f(null),L.current=null,E(null),k(!1),g.setGroupGeometry(s.id,{...c.current})},Ne=he=>{he.key==="Escape"&&le()},je=()=>{document.hidden&&le()};let ue=!1;const ee=he=>{if(ue)return;{const ce=window.screenX,_e=window.screenY,Ee=ce+window.outerWidth,Pe=_e+window.outerHeight;if(he.screenX<ce-ol||he.screenX>Ee+ol||he.screenY<_e-ol||he.screenY>Pe+ol){ue=!0,Ie(),I.current=null,P(null),y.current=null,f(null),L.current=null,E(null),k(!1),g.setGroupGeometry(s.id,{...c.current}),g.popOutGroup(s.id,{atScreenX:he.screenX,atScreenY:he.screenY});return}}const He=he.clientX-it,Me=he.clientY-ze;let Ge=nn(qe.x+He,-(qe.w-nl),Be-nl),se=nn(qe.y+Me,0,$e-rl);const V=z.current;if(V.length>0){const ce=KC(Ge,se,qe.w,qe.h,V);Ge=ce.x,se=ce.y}if(Fe&&(Fe.style.left=`${Ge}px`,Fe.style.top=`${se}px`),c.current.x=Ge,c.current.y=se,Te){let ce=null;const _e=document.elementFromPoint(he.clientX,he.clientY),Ee=_e==null?void 0:_e.closest("[data-group-id][data-stack-path]");if(Ee){const Pe=Ee.dataset.groupId||"";if(Pe!==s.id){const Ue=Ee.dataset.stackPath||"",ot=Ue===""?[]:Ue.split(".").map(Number),Ye=Ee.getBoundingClientRect(),ut={x:Ye.left,y:Ye.top,w:Ye.width,h:Ye.height};ce={groupId:Pe,path:ot,rect:ut,zone:Dl(he.clientX,he.clientY,ut)}}}I.current=ce,P(ce?{rect:ce.rect,zone:ce.zone}:null)}!st&&Math.hypot(he.clientX-it,he.clientY-ze)>=GC&&(st=!0,k(!0),s.dock&&g.setGroupDock(s.id,null));const ie=Te&&I.current&&I.current.zone,Q=ie||!st?null:y_(he.clientX,he.clientY,Be,$e);Q!==L.current&&(L.current=Q,E(Q));const ke=ie||Q?null:YC(he.clientX,he.clientY,Be,$e);ke!==y.current&&(y.current=ke,f(ke))},be=he=>{Ie(),k(!1);const He=L.current;if(L.current=null,E(null),Te&&I.current&&I.current.zone){const Ge=I.current;g.dockGroup(s.id,Ge.groupId,Ge.path,Ge.zone),I.current=null,P(null),y.current=null,f(null);return}if(He==="popout"){I.current=null,P(null),y.current=null,f(null),g.setGroupGeometry(s.id,{...c.current}),g.popOutGroup(s.id,{atScreenX:he.screenX,atScreenY:he.screenY});return}if(He&&He!=="max"){const Ge=jo(He,Be,$e,lt);Fe&&(Fe.style.left=`${Ge.x}px`,Fe.style.top=`${Ge.y}px`,Fe.style.width=`${Ge.w}px`,Fe.style.height=`${Ge.h}px`),c.current=Ge,I.current=null,P(null),y.current=null,f(null),g.setGroupDock(s.id,He);return}const Me=He?jo(He,Be,$e,lt):y.current?Ug(y.current,Be,$e):null;Me&&(Fe&&(Fe.style.left=`${Me.x}px`,Fe.style.top=`${Me.y}px`,Fe.style.width=`${Me.w}px`,Fe.style.height=`${Me.h}px`),c.current=Me,y.current=null,f(null)),I.current=null,P(null),g.setGroupGeometry(s.id,{...c.current})};window.addEventListener("mousemove",ee),window.addEventListener("mouseup",be),window.addEventListener("blur",le),window.addEventListener("keydown",Ne),document.addEventListener("visibilitychange",je)},[d,m,g,s.id,s.root,s.dock]),X=j.useCallback(ye=>K(ye,!1),[K]),Y=j.useCallback(ye=>K(ye,!0),[K]),$=j.useCallback(ye=>Te=>{if(d||m||Te.button!==0)return;Te.preventDefault(),Te.stopPropagation();const ct=Te.clientX,it=Te.clientY,ze={...c.current},qe=l.current,Fe=window.innerWidth,Be=window.innerHeight,$e=Ne=>{const je=Ne.clientX-ct,ue=Ne.clientY-it;let ee=ze.x,be=ze.y,he=ze.w,He=ze.h;ye.includes("e")?he=nn(ze.w+je,il,Math.max(il,Fe-ze.x)):ye.includes("w")&&(ee=nn(ze.x+je,0,ze.x+ze.w-il),he=ze.x+ze.w-ee),ye.includes("s")?He=nn(ze.h+ue,sl,Math.max(sl,Be-ze.y)):ye.includes("n")&&(be=nn(ze.y+ue,0,ze.y+ze.h-sl),He=ze.y+ze.h-be),qe&&(qe.style.left=`${ee}px`,qe.style.top=`${be}px`,qe.style.width=`${he}px`,qe.style.height=`${He}px`),c.current={x:ee,y:be,w:he,h:He}};let lt=!1;const st=()=>{lt||(lt=!0,window.removeEventListener("mousemove",$e),window.removeEventListener("mouseup",le),window.removeEventListener("blur",St),window.removeEventListener("keydown",Se),document.removeEventListener("visibilitychange",Ie))},St=()=>{st(),g.setGroupGeometry(s.id,{...c.current})},Se=Ne=>{Ne.key==="Escape"&&St()},Ie=()=>{document.hidden&&St()},le=()=>{st(),g.setGroupGeometry(s.id,{...c.current})};window.addEventListener("mousemove",$e),window.addEventListener("mouseup",le),window.addEventListener("blur",St),window.addEventListener("keydown",Se),document.addEventListener("visibilitychange",Ie)},[d,m,g,s.id]);j.useEffect(()=>{if(d||s.dock)return;const ye=()=>{const Te=window.innerWidth,ct=window.innerHeight,it=c.current,ze=nn(it.x,-(it.w-nl),Te-nl),qe=nn(it.y,0,ct-rl);(ze!==it.x||qe!==it.y)&&g.setGroupGeometry(s.id,{...it,x:ze,y:qe})};return window.addEventListener("resize",ye),()=>window.removeEventListener("resize",ye)},[d,g,s.id,s.dock]);const U=j.useCallback(ye=>{o(ye),g.setActiveTab(s.id,ye),g.focus(ye)},[g,s.id]),T=j.useCallback(ye=>{o(ye),g.focus(ye)},[g]),F=j.useCallback(ye=>{g.close(ye)},[g]),B=j.useCallback((ye,Te,ct)=>{g.beginTabDrag(s.id,ye,Te,ct)},[g,s.id]),W=j.useCallback(ye=>{g.close(ye)},[g]),Z=j.useCallback((ye,Te)=>{g.setSplitSizes(s.id,ye,Te)},[g,s.id]),ne=wr(s.root),ge=Ft(s.root);j.useEffect(()=>{p&&ge.includes(p)||o(ne[0]||ge[0]||null)},[p,ne,ge]);const[xe,J]=j.useState(null),G=xe&&s.root.kind==="split"?yr(s.root,xe):null,de=!!xe&&!G;j.useEffect(()=>{de&&J(null)},[de]);const oe=j.useCallback(()=>{if(m){const ye=C.current;ye&&g.setGroupGeometry(s.id,ye),C.current=null,b(!1);return}C.current={...c.current},s.dock&&g.setGroupDock(s.id,null),g.setGroupGeometry(s.id,{x:6,y:6,w:Math.max(il,window.innerWidth-12),h:Math.max(sl,window.innerHeight-12)}),b(!0)},[g,s.id,m,s.dock]),Ae=ye=>{const Te=/Mac|iPhone|iPad|iPod/.test(navigator.platform),ct=Te?ye.metaKey:ye.ctrlKey,it=Te?ye.ctrlKey:ye.metaKey;if(!ct||it||ye.altKey||!ye.shiftKey)return;const ze=ye.key.toLowerCase();if(ze==="o")ye.preventDefault(),g.popOutGroup(s.id);else if(ze==="m")ye.preventDefault(),g.minimizeGroup(s.id);else if(ze==="x")ye.preventDefault(),g.closeGroup(s.id);else if(ze==="z")ye.preventDefault(),s.root.kind==="split"?J(qe=>qe?null:p):oe();else if(ze.startsWith("arrow")){ye.preventDefault();const qe=p?yr(s.root,p):null,Fe=qe?Dx(s.root,qe,ze.slice(5)):null,Be=Fe?cn(s.root,Fe):null;if(!Fe||!Be||Be.kind!=="stack")return;T(Be.activeTab),xe&&J(Be.activeTab);const $e=`[data-stack-path="${Fe.join(".")}"] .xterm-helper-textarea`;requestAnimationFrame(()=>{var st,St;(St=Array.from(((st=l.current)==null?void 0:st.querySelectorAll($e))??[]).find(Se=>Se.offsetParent!==null))==null||St.focus()})}};if(d){const ye=ne[0],Te=ye?h.get(ye):null;if(!Te)return null;const ct=s.intents[ye]??{intent:"open",nonce:0};return zi.createPortal(v.jsxs("div",{style:{position:"fixed",inset:0,background:Ce.bg,display:"flex",flexDirection:"column",zIndex:110},children:[v.jsxs("div",{style:{background:Ce.titleBg,height:rl,display:"flex",alignItems:"center",borderBottom:`1px solid ${Ce.separator}`},children:[v.jsx("span",{style:{flex:1,color:Ce.titleText,fontFamily:_t,fontSize:12,paddingLeft:8,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:Te.title}),v.jsx("button",{"data-no-drag":!0,onClick:()=>g.closeGroup(s.id),style:rn,"aria-label":"close",children:v.jsx(Ri,{size:14})})]}),v.jsx("div",{style:{flex:1,position:"relative",minHeight:0},children:v.jsx(__,{session:Te,visible:!0,intent:ct.intent,intentNonce:ct.nonce,onClose:()=>g.close(ye),sendMessage:O,subscribeBinary:A,onEvent:r})})]}),document.body)}const Oe=a?(()=>{const ye=window.innerWidth,Te=window.innerHeight,ct=Ug(a,ye,Te);return zi.createPortal(v.jsx("div",{style:{position:"fixed",left:ct.x,top:ct.y,width:ct.w,height:ct.h,background:`${Ce.info}33`,border:`2px dashed ${Ce.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,Xe=(()=>{var Te;if(ge.length===0)return"";const ye=((Te=h.get(ge[0]))==null?void 0:Te.title)||ge[0];return ge.length===1?ye:`${ye} +${ge.length-1}`})(),We=s.root.kind==="split",rt=zi.createPortal(v.jsxs("div",{ref:l,onKeyDown:Ae,onMouseDown:We?()=>g.focus(ge[0]||""):Y,style:{position:"fixed",left:s.x,top:s.y,width:s.w,height:s.h,zIndex:M,background:Ce.bg,border:`1px solid ${S?Ce.info:Ce.separator}`,borderRadius:8,boxShadow:S?`0 10px 40px rgba(0,0,0,0.45), 0 2px 6px rgba(0,0,0,0.3), 0 0 0 1px ${Ce.info}66, 0 0 18px ${Ce.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:S?1:.88,filter:S?"none":"saturate(0.82)",transition:"box-shadow 120ms ease-out, border-color 120ms ease-out, opacity 140ms ease-out, filter 140ms ease-out"},children:[We&&v.jsxs("div",{onMouseDown:X,onDoubleClick:ye=>{ye.target.closest("button")||oe()},style:{height:rl,flexShrink:0,display:"flex",flexDirection:"column",background:Ce.titleBg,borderBottom:`1px solid ${Ce.separator}`,userSelect:"none",cursor:"move"},children:[v.jsx("div",{style:{display:"flex",height:qC,flexShrink:0},children:ne.map((ye,Te)=>v.jsx("div",{style:{flex:1,background:s.colors[ye]||Ce.titleText}},Te))}),v.jsxs("div",{style:{flex:1,display:"flex",alignItems:"center",padding:"0 4px 0 8px",color:Ce.titleText,fontFamily:_t,fontSize:11},children:[v.jsx("span",{style:{color:Ce.info,fontWeight:600,letterSpacing:1,marginRight:8},"aria-hidden":!0,children:">_"}),v.jsx("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:Xe}),ge.length>1&&v.jsxs(v.Fragment,{children:[v.jsx("button",{"data-no-drag":!0,onMouseDown:ye=>ye.stopPropagation(),onClick:()=>g.applyLayoutPreset(s.id,"single"),style:rn,"aria-label":"single-pane",title:u("session.layout.single"),children:v.jsx(jv,{size:12})}),v.jsx("button",{"data-no-drag":!0,onMouseDown:ye=>ye.stopPropagation(),onClick:()=>g.applyLayoutPreset(s.id,"columns"),style:rn,"aria-label":"two-columns",title:u("session.layout.columns"),children:v.jsx(Lv,{size:14})}),v.jsx("button",{"data-no-drag":!0,onMouseDown:ye=>ye.stopPropagation(),onClick:()=>g.applyLayoutPreset(s.id,"grid"),style:rn,"aria-label":"grid-layout",title:u("session.layout.grid"),children:v.jsx(Tv,{size:14})})]}),v.jsx("button",{"data-no-drag":!0,onMouseDown:ye=>ye.stopPropagation(),onClick:oe,style:rn,"aria-label":"toggle-maximize",title:`${u(m?"session.restoreSize":"session.maximize")} · ${u("session.maximizeHint")}`,children:m?v.jsx(Th,{size:14}):v.jsx(El,{size:14})}),v.jsx("button",{"data-no-drag":!0,onMouseDown:ye=>ye.stopPropagation(),onClick:()=>g.popOutGroup(s.id),style:rn,"aria-label":"pop-out",title:`${u("session.popOut")||"Pop out to separate window"} (Ctrl+Shift+O)`,children:v.jsx(_r,{size:14})}),v.jsx("button",{"data-no-drag":!0,onClick:()=>g.minimizeGroup(s.id),style:rn,"aria-label":"minimize",title:`${u("session.minimize")||"Minimize"} (Ctrl+Shift+M)`,children:v.jsx(Mh,{size:14})}),v.jsx("button",{"data-no-drag":!0,onClick:()=>g.closeGroup(s.id),style:rn,"aria-label":"close",title:`${u("session.close")||"Close"} (Ctrl+Shift+X)`,children:v.jsx(Ri,{size:14})})]})]}),v.jsx("div",{style:{flex:1,display:"flex",minHeight:0,minWidth:0},children:s.root.kind==="split"?v.jsx(Fh,{node:s.root,path:[],groupId:s.id,sessionsById:h,colors:s.colors,intents:s.intents,onTabClick:U,onTabClose:F,onTabMouseDown:B,onPaneAutoClose:W,registerRect:()=>{},onSplitSizes:Z,zoomPath:G??void 0,sendMessage:O,subscribeBinary:A,onEvent:r,focusedSessionId:p||void 0,groupTopmost:S,onFocusStack:T}):v.jsx(Wh,{stack:s.root,path:[],groupId:s.id,sessionsById:h,colors:s.colors,intents:s.intents,onTabClick:U,onTabClose:F,onTabMouseDown:B,onPaneAutoClose:W,registerRect:()=>{},sendMessage:O,subscribeBinary:A,onEvent:r,focusedSessionId:p||void 0,groupTopmost:S,onFocusStack:T,groupActions:{onMinimizeGroup:()=>g.minimizeGroup(s.id),onCloseGroup:()=>g.closeGroup(s.id),onPopOutGroup:()=>g.popOutGroup(s.id),onToggleMaximize:oe,isMaximized:m,onApplyLayoutPreset:ye=>g.applyLayoutPreset(s.id,ye)}})}),v.jsx("div",{onMouseDown:$("n"),style:{position:"absolute",top:0,left:6,right:6,height:4,cursor:"ns-resize",zIndex:3}}),v.jsx("div",{onMouseDown:$("s"),style:{position:"absolute",bottom:0,left:6,right:6,height:4,cursor:"ns-resize",zIndex:3}}),v.jsx("div",{onMouseDown:$("w"),style:{position:"absolute",top:6,bottom:6,left:0,width:4,cursor:"ew-resize",zIndex:3}}),v.jsx("div",{onMouseDown:$("e"),style:{position:"absolute",top:6,bottom:6,right:0,width:4,cursor:"ew-resize",zIndex:3}}),v.jsx("div",{onMouseDown:$("nw"),style:{position:"absolute",top:0,left:0,width:10,height:10,cursor:"nwse-resize",zIndex:4}}),v.jsx("div",{onMouseDown:$("ne"),style:{position:"absolute",top:0,right:0,width:10,height:10,cursor:"nesw-resize",zIndex:4}}),v.jsx("div",{onMouseDown:$("sw"),style:{position:"absolute",bottom:0,left:0,width:10,height:10,cursor:"nesw-resize",zIndex:4}}),v.jsx("div",{onMouseDown:$("se"),title:"resize",style:{position:"absolute",right:0,bottom:0,width:14,height:14,cursor:"nwse-resize",background:"linear-gradient(135deg, transparent 50%, rgba(255,255,255,0.2) 50%)",zIndex:4}})]}),document.body);return v.jsxs(v.Fragment,{children:[rt,Oe,R&&!(H!=null&&H.zone)&&v.jsx(S_,{activeZone:D}),H&&v.jsx(vr,{targetRect:H.rect,activeZone:H.zone})]})}const rn={background:"transparent",border:"none",color:Ce.titleText,cursor:"pointer",padding:4,display:"flex",alignItems:"center",justifyContent:"center",borderRadius:4},ih=["#3b82f6","#22c55e","#eab308","#ef4444","#a855f7","#06b6d4","#f97316","#ec4899"];function Ln(s){for(const h of ih)if(!s.includes(h))return h;return ih[s.length%ih.length]}const Uh=j.createContext(null),x_=j.createContext({}),C_=j.createContext({});function VC(){const s=j.useContext(Uh);if(!s)throw new Error("useSessionWindows must be used within SessionWindowsHost");return s}function Xk(){return j.useContext(x_)}function Vk(){return j.useContext(C_)}function JC(){return j.useContext(Uh)}const yl=720,$h=460,QC=320,ZC=200,$g=30,k_=80,E_=80,Eo=80,bh=28;function e2(s){const h=typeof window<"u"?window.innerWidth:1280,w=typeof window<"u"?window.innerHeight:800;let S=Number.isFinite(s.w)&&s.w>=QC?s.w:yl,M=Number.isFinite(s.h)&&s.h>=ZC?s.h:$h;S=Math.min(S,h),M=Math.min(M,w);let O=Number.isFinite(s.x)?s.x:k_,A=Number.isFinite(s.y)?s.y:E_;return O=Math.max(Math.min(O,h-Eo),-(S-Eo)),A=Math.max(Math.min(A,w-bh),0),{x:O,y:A,w:S,h:M}}const Wg=12,al=60;function L_(s){return`sessionGroups:${s}`}function Lo(s){try{const h=localStorage.getItem(L_(s));if(!h)return null;const w=JSON.parse(h);if(Array.isArray(w==null?void 0:w.groups)&&typeof(w==null?void 0:w.zCounter)=="number")return w}catch{}return null}function wl(s,h){try{localStorage.setItem(L_(s),JSON.stringify(h))}catch{}}function qg(s,h){const w=Lo(s);!w||!w.groups.some(S=>S.id===h)||(wl(s,{...w,groups:w.groups.filter(S=>S.id!==h)}),window.dispatchEvent(new CustomEvent("session-windows:changed")))}function t2(s,h,w){const S=Lo(s);!S||!S.groups.some(M=>M.id===h)||(wl(s,{...S,groups:S.groups.map(M=>M.id===h?{...M,...w}:M)}),window.dispatchEvent(new CustomEvent("session-windows:changed")))}function i2(s){const h=s%8;return{x:k_+h*$g,y:E_+h*$g,w:yl,h:$h}}function ll(s,h,w){return Math.max(h,Math.min(w,s))}function Gg(){return`g_${Math.random().toString(36).slice(2,10)}_${Date.now().toString(36)}`}function Ts(s,h){for(const w of s)if(yr(w.root,h))return w;return null}function Jk({projectId:s,sessions:h,sendMessage:w,subscribeBinary:S,onEvent:M,onAddSession:O,children:A}){const{t:r}=Tt(),{warning:u}=un(),{confirm:d}=kr(),{sendNotification:g}=Ll(),[l]=j.useState(()=>{const se=Lo(s);if(!se)return{groups:[],zCounter:0};const V=se.groups.map(ie=>{const Q=Ft(ie.root),ke=new Set(Q),ce={};for(const Ue of Object.keys(ie.colors||{}))ke.has(Ue)&&(ce[Ue]=ie.colors[Ue]);const _e={};for(const Ue of Q)_e[Ue]={intent:"open",nonce:0},ce[Ue]||(ce[Ue]=Ln(Object.values(ce)));const Ee=e2({x:ie.x,y:ie.y,w:ie.w,h:ie.h}),Pe=ie.ownerWindowId||gt;return{...ie,...Ee,colors:ce,intents:_e,minimized:!!ie.minimized,ownerWindowId:Pe}});return{groups:_g(V),zCounter:se.zCounter||V.length}}),[m,b]=j.useState(l.groups),C=j.useRef(l.zCounter),p=j.useRef(m);p.current=m;const o=j.useRef(h);o.current=h;const[c,a]=j.useState(null),f=j.useRef(null);f.current=c;const[y,R]=j.useState({}),k=j.useRef(y);k.current=y,j.useEffect(()=>{var Q;const se={},V=((Q=Lo(s))==null?void 0:Q.sessionProjects)??{},ie={};for(const ke of m)for(const ce of Ft(ke.root)){const _e=h.find(Pe=>Pe.id===ce)||y[ce];_e!=null&&_e.title&&(se[ce]=_e.title);const Ee=(_e==null?void 0:_e.project_id)||V[ce];Ee&&(ie[ce]=Ee)}wl(s,{groups:m,zCounter:C.current,titles:se,sessionProjects:ie}),window.dispatchEvent(new CustomEvent("session-windows:changed"))},[s,m,h,y]),j.useEffect(()=>()=>{var _e;const se=p.current;if(se.length===0)return;let V=!1;const ie=se.map(Ee=>(Ee.ownerWindowId||gt)!==gt||Ee.minimized?Ee:(V=!0,{...Ee,minimized:!0}));if(!V)return;const Q={},ke=((_e=Lo(s))==null?void 0:_e.sessionProjects)??{},ce={};for(const Ee of ie)for(const Pe of Ft(Ee.root)){const Ue=o.current.find(Ye=>Ye.id===Pe)||k.current[Pe];Ue!=null&&Ue.title&&(Q[Pe]=Ue.title);const ot=(Ue==null?void 0:Ue.project_id)||ke[Pe];ot&&(ce[Pe]=ot)}wl(s,{groups:ie,zCounter:C.current,titles:Q,sessionProjects:ce}),window.dispatchEvent(new CustomEvent("session-windows:changed"))},[s]),j.useEffect(()=>{const se=document.documentElement.style,V={left:0,right:0,top:0,bottom:0};for(const ie of m)!ie.dock||ie.minimized||(ie.ownerWindowId||gt)!==gt||(ie.dock==="left"?V.left=Math.max(V.left,ie.x+ie.w-gr()):ie.dock==="right"?V.right=Math.max(V.right,window.innerWidth-ie.x):ie.dock==="top"?V.top=Math.max(V.top,ie.y+ie.h):V.bottom=Math.max(V.bottom,window.innerHeight-ie.y));for(const ie of["left","right","top","bottom"])se.setProperty(`--dock-inset-${ie}`,`${Math.max(0,Math.round(V[ie]))}px`);return()=>{for(const ie of["left","right","top","bottom"])se.removeProperty(`--dock-inset-${ie}`)}},[m]),j.useEffect(()=>{const se=()=>{const Q=window.innerWidth,ke=window.innerHeight,ce=gr();b(_e=>{let Ee=!1;const Pe=_e.map(Ue=>{if(!Ue.dock)return Ue;const ot=Ue.dock==="left"||Ue.dock==="right"?Ue.w:Ue.h,Ye=w_(Ue.dock,ot,Q,ke,ce);return Ye.x===Ue.x&&Ye.y===Ue.y&&Ye.w===Ue.w&&Ye.h===Ue.h?Ue:(Ee=!0,{...Ue,...Ye})});return Ee?Pe:_e})};se();const V=document.querySelector("main"),ie=V?new ResizeObserver(se):null;return V&&ie&&ie.observe(V),window.addEventListener("resize",se),()=>{ie==null||ie.disconnect(),window.removeEventListener("resize",se)}},[]);const[D,E]=j.useState(()=>new Set),L=j.useRef(new Set);j.useEffect(()=>{if(h.length===0)return;const se=h.filter(ie=>ie.project_id===s);if(se.length===0)return;const V=new Set(se.map(ie=>ie.id));for(const ie of m)for(const Q of Ft(ie.root))V.has(Q)||y[Q]||D.has(Q)||L.current.has(Q)||(L.current.add(Q),l_(Q).then(ke=>R(ce=>({...ce,[Q]:ke}))).catch(ke=>{ke instanceof pl&&ke.status===404&&E(ce=>new Set(ce).add(Q))}).finally(()=>L.current.delete(Q)))},[m,h,s,y,D]),j.useEffect(()=>M(V=>{V.type!=="session:status-changed"||!V.sessionId||R(ie=>{const Q=ie[V.sessionId];if(!Q)return ie;const ke={status:V.status};return V.worktree_path!==void 0&&(ke.worktree_path=V.worktree_path),V.branch_name!==void 0&&(ke.branch_name=V.branch_name),{...ie,[Q.id]:{...Q,...ke}}})}),[M]),j.useEffect(()=>{D.size!==0&&b(se=>{let V=!1;const ie=[];for(const Q of se){const ke=Ft(Q.root);if(!ke.some(ot=>D.has(ot))){ie.push(Q);continue}V=!0;const ce=new Set(ke.filter(ot=>!D.has(ot))),_e=Qv(Q.root,ce);if(!_e)continue;const Ee=new Set(Ft(_e)),Pe={};for(const ot of Object.keys(Q.colors))Ee.has(ot)&&(Pe[ot]=Q.colors[ot]);const Ue={};for(const ot of Object.keys(Q.intents))Ee.has(ot)&&(Ue[ot]=Q.intents[ot]);ie.push({...Q,root:_e,colors:Pe,intents:Ue})}return V?ie:se})},[D]);const z=j.useCallback((se,V)=>{const ie=p.current.length,Q=i2(ie);C.current+=1;const ke=C.current;return{id:Gg(),...Q,z:ke,minimized:!1,root:ln([se],se),colors:{[se]:Ln([])},intents:{[se]:{intent:V,nonce:0}},ownerWindowId:gt}},[]),H=j.useCallback((se,V="open")=>{b(ie=>{const Q=Ts(ie,se);C.current+=1;const ke=C.current;return Q?ie.map(ce=>{var ot,Ye,ut;if(ce.id!==Q.id)return ce;const _e=((ot=ce.intents[se])==null?void 0:ot.intent)??"open",Ee=V==="start"||V==="resume",Pe=Ee?V:_e,Ue=Pe!==_e||Ee;return{...ce,z:ke,minimized:!1,root:Ki(ce.root,se),intents:{...ce.intents,[se]:{intent:Pe,nonce:Ue?(((Ye=ce.intents[se])==null?void 0:Ye.nonce)??0)+1:((ut=ce.intents[se])==null?void 0:ut.nonce)??0}}}}):[...ie,z(se,V)]})},[z]),P=j.useCallback(se=>{b(V=>{const ie=Ts(V,se);if(!ie)return V;const Q=V.reduce((ce,_e)=>_e.z>ce?_e.z:ce,0);if(ie.z===Q&&!ie.minimized)return V;C.current+=1;const ke=C.current;return V.map(ce=>ce.id===ie.id?{...ce,z:ke,minimized:!1}:ce)})},[]),I=j.useCallback(async se=>{const V=se.map(ie=>o.current.find(Q=>Q.id===ie)||k.current[ie]).filter(ie=>!!ie&&ie.status==="running");if(V.length===0)return!0;if(!await d({message:r("session.confirmStop"),danger:!0}))return!1;for(const ie of V)gh(ie.id).catch(()=>{});return!0},[r,d]),K=j.useCallback(async se=>{await I([se])&&b(V=>{const ie=Ts(V,se);if(!ie)return V;const Q=Dn(ie.root,se);if(!Q)return V.filter(_e=>_e.id!==ie.id);new Set(Ft(Q));const ke={...ie.colors};delete ke[se];const ce={...ie.intents};return delete ce[se],V.map(_e=>_e.id===ie.id?{..._e,root:Q,colors:ke,intents:ce}:_e)})},[I]),X=j.useCallback(se=>{b(V=>{const ie=Ts(V,se);return ie?V.map(Q=>Q.id===ie.id?{...Q,minimized:!0}:Q):V})},[]),Y=j.useCallback(se=>{b(V=>{const ie=Ts(V,se);if(!ie)return V;C.current+=1;const Q=C.current;return V.map(ke=>ke.id===ie.id?{...ke,minimized:!1,z:Q}:ke)})},[]),$=j.useCallback(se=>!!Ts(p.current,se),[]),U=j.useCallback(async se=>{const V=p.current.find(ie=>ie.id===se);V&&!await I(Ft(V.root))||b(ie=>ie.filter(Q=>Q.id!==se))},[I]),T=j.useCallback(se=>{b(V=>V.map(ie=>ie.id===se?{...ie,minimized:!0}:ie))},[]);j.useEffect(()=>{const se=ie=>{const Q=ie.detail;!(Q!=null&&Q.projectId)||!Q.groupId||Q.projectId===s&&b(ke=>{if(!ke.find(Ee=>Ee.id===Q.groupId))return ke;C.current+=1;const _e=C.current;return ke.map(Ee=>Ee.id===Q.groupId?{...Ee,minimized:!1,z:_e,root:Q.sessionId?Ki(Ee.root,Q.sessionId):Ee.root}:Ee)})},V=async ie=>{var _e;const Q=ie.detail;if(!(Q!=null&&Q.projectId)||!Q.groupId||Q.projectId!==s)return;const ke=p.current.find(Ee=>Ee.id===Q.groupId);if(ke&&!await I(Ft(ke.root)))return;const ce=(ke==null?void 0:ke.ownerWindowId)||gt;ce!==gt&&(Ae.current.delete(ce),it.current.delete(Q.groupId),(_e=oe.current)==null||_e.post({t:"group-reclaimed",popoutId:ce,groupIds:[Q.groupId],reason:"late-return"})),b(Ee=>Ee.filter(Pe=>Pe.id!==Q.groupId))};return window.addEventListener("session-windows:restore",se),window.addEventListener("session-windows:close",V),()=>{window.removeEventListener("session-windows:restore",se),window.removeEventListener("session-windows:close",V)}},[s,I]),j.useEffect(()=>{const se=sessionStorage.getItem("pendingSessionRestore");if(se)try{const V=JSON.parse(se);if(V.projectId!==s||!V.groupId)return;sessionStorage.removeItem("pendingSessionRestore"),b(ie=>{if(!ie.find(ce=>ce.id===V.groupId))return ie;C.current+=1;const ke=C.current;return ie.map(ce=>ce.id===V.groupId?{...ce,minimized:!1,z:ke,root:V.sessionId?Ki(ce.root,V.sessionId):ce.root}:ce)})}catch{}},[s]);const F=j.useCallback(se=>{b(V=>{if(!V.find(ke=>ke.id===se))return V;C.current+=1;const Q=C.current;return V.map(ke=>ke.id===se?{...ke,minimized:!1,z:Q}:ke)})},[]),B=j.useCallback((se,V)=>{b(ie=>ie.map(Q=>Q.id===se?{...Q,...V}:Q))},[]),W=j.useCallback((se,V)=>{b(ie=>ie.map(Q=>{if(Q.id===se){if(!V)return Q.dock?{...Q,dock:void 0}:Q;const ke=jo(V,window.innerWidth,window.innerHeight,gr());return{...Q,...ke,dock:V}}return V&&Q.dock===V?{...Q,dock:void 0}:Q}))},[]),Z=j.useCallback((se,V,ie)=>{b(Q=>Q.map(ke=>ke.id===se?{...ke,root:Jv(ke.root,V,ie)}:ke))},[]),ne=j.useCallback((se,V)=>{b(ie=>ie.map(Q=>Q.id===se?{...Q,root:Ki(Q.root,V)}:Q))},[]),ge=j.useCallback((se,V)=>{b(ie=>ie.map(Q=>Q.id===se?{...Q,root:Yv(Q.root,V)}:Q))},[]),xe=j.useCallback((se,V,ie)=>{b(Q=>Q.map(ke=>ke.id===se?{...ke,root:Vv(ke.root,V,ie)}:ke))},[]),J=j.useCallback((se,V,ie,Q)=>{if(Q.button!==0||!p.current.find(Ze=>Ze.id===se))return;Q.preventDefault();const ce=Q.clientX,_e=Q.clientY;let Ee=null;a({groupId:se,sessionId:V,fromPath:ie,startX:ce,startY:_e,mouseX:ce,mouseY:_e,hoveredGroupId:null,hoveredPath:null,hoveredRect:null,zone:null,viewportZone:null});const Pe=(Ze,fe)=>{const Ve=Gg();Ee=Ve;const ht=window.innerWidth,At=window.innerHeight,Jt={x:ll(Ze-60,-yl+Eo,ht-Eo),y:ll(fe-12,0,At-bh),w:yl,h:$h};b(jt=>{const ei=jt.find(Lt=>Lt.id===se);if(!ei)return jt;const $t=Dn(ei.root,V),li=ei.colors[V]||Ln([]),mi=ei.intents[V]??{intent:"open",nonce:0};C.current+=1;const _i=C.current,ns={id:Ve,...Jt,z:_i,minimized:!1,root:ln([V],V),colors:{[V]:li},intents:{[V]:mi},ownerWindowId:gt},ci=[];for(const Lt of jt)if(Lt.id===se){if($t){const Er=new Set(Ft($t)),Lr={};for(const bi of Object.keys(Lt.colors))Er.has(bi)&&(Lr[bi]=Lt.colors[bi]);const rs={};for(const bi of Object.keys(Lt.intents))Er.has(bi)&&(rs[bi]=Lt.intents[bi]);ci.push({...Lt,root:gl($t),colors:Lr,intents:rs})}}else ci.push(Lt);return ci.push(ns),ci})};let Ue=!1;const ot=Ze=>{const fe=window.screenX,Ve=window.screenY,ht=fe+window.outerWidth,At=Ve+window.outerHeight;return Ze.screenX<fe-al||Ze.screenX>ht+al||Ze.screenY<Ve-al||Ze.screenY>At+al},Ye=Ze=>{if(Ue)return;const fe=f.current;if(!fe)return;if(!Ee)Math.hypot(Ze.clientX-ce,Ze.clientY-_e)>=Wg&&Pe(Ze.clientX,Ze.clientY);else{const $t=window.innerWidth,li=window.innerHeight,mi=ll(Ze.clientX-60,-640,$t-Eo),_i=ll(Ze.clientY-12,0,li-bh);b(ns=>ns.map(ci=>ci.id===Ee?{...ci,x:mi,y:_i}:ci))}if(Ee&&ot(Ze)&&p.current.some($t=>$t.id===Ee)){const $t=ze.current;if($t){Ue=!0;const li=Ee;ft(),a(null),$t(li,{atScreenX:Ze.screenX,atScreenY:Ze.screenY});return}}let Ve=null,ht=null,At=null,Jt=null;const jt=document.elementsFromPoint(Ze.clientX,Ze.clientY);for(const $t of jt){const li=$t.closest("[data-group-id][data-stack-path]");if(!li)continue;const mi=li.dataset.groupId||"",_i=li.dataset.stackPath||"";if(Ee?mi===Ee:mi===fe.groupId&&_i===fe.fromPath.join("."))continue;const ci=_i===""?[]:_i.split(".").map(Number),Lt=li.getBoundingClientRect();Ve=mi,ht=ci,At={x:Lt.left,y:Lt.top,w:Lt.width,h:Lt.height},Jt=Dl(Ze.clientX,Ze.clientY,At);break}const ei=Jt||!Ee?null:y_(Ze.clientX,Ze.clientY,window.innerWidth,window.innerHeight);a({...fe,mouseX:Ze.clientX,mouseY:Ze.clientY,hoveredGroupId:Ve,hoveredPath:ht,hoveredRect:At,zone:Jt,viewportZone:ei})};let ut=!1;const ft=()=>{ut||(ut=!0,window.removeEventListener("mousemove",Ye),window.removeEventListener("mouseup",Nt),window.removeEventListener("blur",kt),window.removeEventListener("keydown",vt),document.removeEventListener("visibilitychange",Vt))},kt=()=>{ft(),a(null)},vt=Ze=>{Ze.key==="Escape"&&kt()},Vt=()=>{document.hidden&&kt()},Nt=Ze=>{var ht;ft();const fe=f.current;if(a(null),!fe)return;if(fe.hoveredGroupId&&fe.hoveredPath&&fe.zone){const At=Ee||fe.groupId;G(At,fe.sessionId,fe.hoveredGroupId,fe.hoveredPath,fe.zone);return}const Ve=fe.viewportZone;if(Ve&&Ee&&p.current.some(At=>At.id===Ee)){const At=Ee;if(Ve==="popout")(ht=ze.current)==null||ht.call(ze,At,{atScreenX:Ze.screenX,atScreenY:Ze.screenY});else if(Ve==="max"){const Jt=jo(Ve,window.innerWidth,window.innerHeight,gr());b(jt=>jt.map(ei=>ei.id===At?{...ei,x:Jt.x,y:Jt.y,w:Jt.w,h:Jt.h}:ei))}else W(At,Ve);return}};window.addEventListener("mousemove",Ye),window.addEventListener("mouseup",Nt),window.addEventListener("blur",kt),window.addEventListener("keydown",vt),document.addEventListener("visibilitychange",Vt)},[]),G=j.useCallback((se,V,ie,Q,ke)=>{b(ce=>{const _e=ce.find(vt=>vt.id===se),Ee=ce.find(vt=>vt.id===ie);if(!_e||!Ee)return ce;if(se===ie){const vt=cn(_e.root,Q);if(!vt||vt.kind!=="stack")return ce;const Vt=vt.tabs.find(Ve=>Ve!==V);if(!Vt)return ce;const Nt=Dn(_e.root,V);if(!Nt)return ce;const Ze=yr(Nt,Vt);if(!Ze)return ce;let fe;return ke==="center"?fe=pr(Nt,Ze,V):fe=ko(Nt,Ze,ke,ln([V])),fe=Ki(fe,V),ce.map(Ve=>Ve.id!==se?Ve:(C.current+=1,{...Ve,root:fe,z:C.current,minimized:!1}))}const Pe=Dn(_e.root,V),Ue=_e.colors[V],ot=_e.intents[V]??{intent:"open",nonce:0};let Ye;if(ke==="center")Ye=pr(Ee.root,Q,V);else{const vt=ln([V]);Ye=ko(Ee.root,Q,ke,vt)}Ye=Ki(Ye,V);const ut={...Ee.colors};ut[V]||(ut[V]=Ue||Ln(Object.values(ut)));const ft={...Ee.intents,[V]:ot},kt=[];for(const vt of ce)if(vt.id===se){if(Pe){const Vt=new Set(Ft(Pe)),Nt={};for(const fe of Object.keys(vt.colors))Vt.has(fe)&&(Nt[fe]=vt.colors[fe]);const Ze={};for(const fe of Object.keys(vt.intents))Vt.has(fe)&&(Ze[fe]=vt.intents[fe]);kt.push({...vt,root:Pe,colors:Nt,intents:Ze})}}else vt.id===ie?(C.current+=1,kt.push({...vt,root:Ye,colors:ut,intents:ft,z:C.current,minimized:!1})):kt.push(vt);return kt})},[]),de=j.useCallback((se,V,ie,Q)=>{b(ke=>{if(se===V)return ke;const ce=ke.find(ut=>ut.id===se),_e=ke.find(ut=>ut.id===V);if(!ce||!_e||ce.root.kind!=="stack")return ke;const Ee=ce.root;let Pe;Q==="center"?Pe=Ee.tabs.reduce((ut,ft)=>pr(ut,ie,ft),_e.root):Pe=ko(_e.root,ie,Q,Ee),Pe=Ki(Pe,Ee.activeTab);const Ue={..._e.colors,...ce.colors},ot={..._e.intents,...ce.intents},Ye=[];for(const ut of ke)ut.id!==se&&(ut.id===V?(C.current+=1,Ye.push({...ut,root:Pe,colors:Ue,intents:ot,z:C.current,minimized:!1})):Ye.push(ut));return Ye})},[]),oe=j.useRef(null),Ae=j.useRef(new Map),[Oe,Xe]=j.useState(null),We=j.useRef(Oe);We.current=Oe;const rt=j.useRef(null),ye=j.useRef(typeof document<"u"&&document.hasFocus()?Date.now():0),[Te,ct]=j.useState(()=>typeof document<"u"&&document.hasFocus());j.useEffect(()=>{const se=()=>{ye.current=Date.now(),ct(!0)},V=()=>ct(!1);window.addEventListener("focus",se),window.addEventListener("blur",V);const ie=e_();return()=>{window.removeEventListener("focus",se),window.removeEventListener("blur",V),ie(),rt.current&&clearTimeout(rt.current)}},[]);const it=j.useRef(new Map),ze=j.useRef(null),qe=j.useCallback((se,V)=>{var Ye;const ie=p.current.find(ut=>ut.id===se);if(!ie)return;const Q=Bx(),ke={...ie,ownerWindowId:Q,dock:void 0};it.current.set(se,ke),Ae.current.set(Q,Date.now()),b(ut=>ut.map(ft=>ft.id===se?{...ft,ownerWindowId:Q,dock:void 0}:ft)),(Ye=oe.current)==null||Ye.post({t:"group-handoff",to:Q,groupId:se,group:ke});const ce=V&&(typeof V.atScreenX=="number"||typeof V.atScreenY=="number"),_e=ce?Math.max(0,((V==null?void 0:V.atScreenX)??window.screenX+ie.x)-40):Math.max(0,window.screenX+ie.x),Ee=ce?Math.max(0,((V==null?void 0:V.atScreenY)??window.screenY+ie.y)-12):Math.max(0,window.screenY+ie.y),Pe=["popup",`width=${Math.max(400,ie.w)}`,`height=${Math.max(300,ie.h+40)}`,`left=${_e}`,`top=${Ee}`].join(","),Ue=`/popout/${encodeURIComponent(s)}/${encodeURIComponent(se)}?wid=${encodeURIComponent(Q)}`,ot=window.open(Ue,"_blank",Pe);if(!ot){it.current.delete(se),Ae.current.delete(Q),b(ut=>ut.map(ft=>ft.id===se?{...ft,ownerWindowId:gt}:ft)),u(r("session.popout.blocked"));return}jx(Q,ot)},[s,r,u]);ze.current=qe;const Fe=j.useCallback(se=>{var Q;const V=p.current.find(ke=>ke.id===se);if(!V)return;const ie=V.ownerWindowId||gt;if(ie===gt){F(se);return}(Q=oe.current)==null||Q.post({t:"group-recall",popoutId:ie,groupId:se}),setTimeout(()=>{var _e;const ke=p.current.find(Ee=>Ee.id===se);if(!ke||(ke.ownerWindowId||gt)===gt)return;Ae.current.delete(ie),it.current.delete(se),(_e=oe.current)==null||_e.post({t:"group-reclaimed",popoutId:ie,groupIds:[se],reason:"late-return"}),C.current+=1;const ce=C.current;b(Ee=>Ee.map(Pe=>Pe.id===se?{...Pe,ownerWindowId:gt,minimized:!1,z:ce}:Pe))},1500)},[F]),Be=j.useCallback(se=>{const V=Ts(p.current,se);V&&Fe(V.id)},[Fe]);j.useEffect(()=>{const se=V=>{const ie=V.detail;!(ie!=null&&ie.projectId)||!ie.groupId||ie.projectId!==s||Fe(ie.groupId)};return window.addEventListener("session-windows:recall",se),()=>window.removeEventListener("session-windows:recall",se)},[s,Fe]),j.useEffect(()=>{const se=sessionStorage.getItem("pendingSessionRecall");if(se)try{const V=JSON.parse(se);if(V.projectId!==s||!V.groupId)return;sessionStorage.removeItem("pendingSessionRecall");const ie=V.groupId;setTimeout(()=>Fe(ie),0)}catch{}},[s,Fe]);const $e=j.useCallback(se=>se.kind==="stack"?[]:[0,...$e(se.children[0])],[]),lt=j.useCallback((se,V,ie)=>{const Q=V?p.current.find(Ee=>Ee.id===V):null,ke=Q&&(Q.ownerWindowId||gt)===gt;if(!Q||!ke){H(se,"start");return}const ce=(()=>{if(ie){const Ee=cn(Q.root,ie);if(Ee&&Ee.kind==="stack")return ie}return $e(Q.root)})();C.current+=1;const _e=C.current;b(Ee=>Ee.map(Pe=>{if(Pe.id!==Q.id)return Pe;const Ue=Ki(pr(Pe.root,ce,se),se);return{...Pe,root:Ue,z:_e,minimized:!1,colors:{...Pe.colors,[se]:Ln(Object.values(Pe.colors))},intents:{...Pe.intents,[se]:{intent:"start",nonce:0}}}}))},[H,$e]),st=j.useCallback(async(se,V)=>{const ie=new Date,Q=String(ie.getHours()).padStart(2,"0"),ke=String(ie.getMinutes()).padStart(2,"0"),ce=String(ie.getSeconds()).padStart(2,"0"),_e=await Eg(s,{title:`Shell ${Q}:${ke}:${ce}`,cli_tool:"raw-shell",use_worktree:!1,memory_inject_mode:"none"});return O==null||O(_e),lt(_e.id,se,V),_e.id},[s,O,lt]);j.useEffect(()=>{const se=Bh();oe.current=se;const V=Q=>{var ke;if(Q.t==="hello"){const ce=it.current.get(Q.groupId);if(ce&&ce.ownerWindowId===Q.from)se.post({t:"group-handoff",to:Q.from,groupId:Q.groupId,group:ce});else{const _e=p.current.find(Ee=>Ee.id===Q.groupId);_e&&_e.ownerWindowId===Q.from&&se.post({t:"group-handoff",to:Q.from,groupId:Q.groupId,group:_e})}}else if(Q.t==="group-return"||Q.t==="bye")if(Q.t==="group-return"){const ce=Q.group;ce&&ce.id===Q.groupId&&(it.current.delete(Q.groupId),Ae.current.delete(Q.from),Q.projectId&&Q.projectId!==s&&qg(Q.projectId,Q.groupId),b(_e=>{const Ee={...ce,ownerWindowId:gt,dock:void 0};return _g([..._e.filter(Pe=>Pe.id!==Q.groupId),Ee])}))}else Ae.current.delete(Q.from),b(ce=>ce.map(_e=>_e.ownerWindowId===Q.from?{..._e,ownerWindowId:gt}:_e));else if(Q.t==="group-close")it.current.delete(Q.groupId),Q.projectId&&Q.projectId!==s&&qg(Q.projectId,Q.groupId),b(ce=>ce.filter(_e=>_e.id!==Q.groupId));else if(Q.t==="heartbeat")Ae.current.set(Q.from,Date.now());else if(Q.t==="group-update"){const ce=Q.patch;Q.projectId&&Q.projectId!==s&&t2(Q.projectId,Q.groupId,ce),b(_e=>_e.map(Ee=>Ee.id===Q.groupId?{...Ee,...ce}:Ee))}else if(Q.t==="dock-probe"){if(document.visibilityState!=="visible")return;const ce=vl(Q.x,Q.y),_e=_l(ce)?bl(ce.x,ce.y):null;if(_e){const Ee=We.current;(!Ee||Ee.zone!==_e.zone||Ee.groupId!==_e.groupId||Ee.path.join(".")!==_e.path.join("."))&&Xe({rect:_e.rect,zone:_e.zone,path:_e.path,groupId:_e.groupId}),rt.current&&clearTimeout(rt.current),rt.current=setTimeout(()=>Xe(null),800);const Pe=An();se.post({t:"dock-probe-result",from:gt,to:Q.from,hit:!0,focusAt:ye.current,rect:{...i_(_e.rect.x,_e.rect.y),w:_e.rect.w*Pe,h:_e.rect.h*Pe},zone:_e.zone})}else We.current&&Xe(null),se.post({t:"dock-probe-result",from:gt,to:Q.from,hit:!1,focusAt:ye.current})}else if(Q.t==="dock-end")Xe(null);else if(Q.t==="dock-commit"&&Q.to===gt){const ce=vl(Q.x,Q.y),_e=_l(ce)?bl(ce.x,ce.y):null,Ee=_e&&_e.zone?_e:(ke=We.current)!=null&&ke.zone?We.current:null;let Pe=!1;const Ue=Q.sessions.map(Ye=>Ye.id),ot=p.current.filter(Ye=>(Ye.ownerWindowId||gt)===gt);if(Ee&&Ee.zone&&!Ue.some(Ye=>Ts(ot,Ye))){const Ye=p.current.find(ft=>ft.id===Ee.groupId),ut=Ye?cn(Ye.root,Ee.path):null;if(Ye&&ut&&ut.kind==="stack"){Pe=!0;const ft=Ee.zone,kt=Ee.path;C.current+=1;const vt=C.current;b(Vt=>Vt.map(Nt=>{if(Nt.id!==Ye.id)return Nt;const Ze=Xv(Nt.root,kt,ft,Ue,Q.activeId),fe={...Nt.colors},Ve={...Nt.intents};for(const ht of Q.sessions)fe[ht.id]||(fe[ht.id]=ht.color||Ln(Object.values(fe))),Ve[ht.id]=ht.intentInfo??{intent:"open",nonce:0};return{...Nt,root:Ze,colors:fe,intents:Ve,z:vt,minimized:!1}}))}}Xe(null),se.post({t:"dock-commit-ack",from:gt,to:Q.from,commitId:Q.commitId,accepted:Pe})}},ie=se.subscribe(V);return()=>{ie(),se.close(),oe.current=null}},[s]),j.useEffect(()=>{const se=Date.now();for(const V of l.groups)V.ownerWindowId&&V.ownerWindowId!==gt&&Ae.current.set(V.ownerWindowId,se)},[]),j.useEffect(()=>{const se=async()=>{var Ee;const ie=Date.now(),Q=[];for(const[Pe,Ue]of Ae.current.entries())ie-Ue>Zv&&Q.push(Pe);if(Q.length===0)return;const ke=await s_(),ce=Q.filter(Pe=>ke.has(Pe)?(Ae.current.set(Pe,ie),!1):!0);if(ce.length===0)return;for(const Pe of ce)Ae.current.delete(Pe);const _e=new Set(ce);for(const Pe of p.current)Pe.ownerWindowId&&_e.has(Pe.ownerWindowId)&&it.current.delete(Pe.id);for(const Pe of ce){const Ue=p.current.filter(ot=>ot.ownerWindowId===Pe).map(ot=>ot.id);Ue.length>0&&((Ee=oe.current)==null||Ee.post({t:"group-reclaimed",popoutId:Pe,groupIds:Ue,reason:"heartbeat-timeout"}))}b(Pe=>Pe.map(Ue=>Ue.ownerWindowId&&ce.includes(Ue.ownerWindowId)?{...Ue,ownerWindowId:gt}:Ue))},V=setInterval(()=>{se()},Nh);return()=>clearInterval(V)},[]);const St=j.useCallback((se,V)=>{w({type:"session:terminal-input",sessionId:se,input:V})},[w]),Se=j.useCallback(()=>{var ie,Q;const se=p.current.filter(ke=>(ke.ownerWindowId||gt)===gt).slice().sort((ke,ce)=>ce.z-ke.z),V=[];for(const ke of se)for(const ce of Ft(ke.root)){const _e=((ie=o.current.find(Ee=>Ee.id===ce))==null?void 0:ie.title)||((Q=k.current[ce])==null?void 0:Q.title)||ce;V.push({sessionId:ce,label:_e})}return V},[]),Ie=j.useCallback(async(se,V)=>{const Q=p.current.filter(ce=>!ce.minimized&&(ce.ownerWindowId||gt)===gt).reduce((ce,_e)=>ce&&ce.z>=_e.z?ce:_e,null),ke=await Eg(s,{title:V||"",description:se,use_worktree:!1,memory_inject_mode:"none"});O==null||O(ke),lt(ke.id,(Q==null?void 0:Q.id)??null)},[s,O,lt]),le=j.useMemo(()=>({openOrFocus:H,close:K,focus:P,minimize:X,restore:Y,isOpen:$,recallPopout:Be,closeGroup:U,minimizeGroup:T,restoreGroup:F,setGroupGeometry:B,setGroupDock:W,setSplitSizes:Z,setActiveTab:ne,applyLayoutPreset:ge,reorderTab:xe,beginTabDrag:J,dockGroup:de,popOutGroup:qe,createRawShellTab:st,sendToSession:St,listOpenTerminals:Se,sendToNewTerminal:Ie}),[H,K,P,X,Y,$,Be,U,T,F,B,W,Z,ne,ge,xe,J,de,qe,st,St,Se,Ie]),Ne=j.useMemo(()=>{const se={};for(const V of m){const Q=(V.ownerWindowId||gt)!==gt?"popped":V.minimized?"minimized":"floating";for(const ke of Ft(V.root))se[ke]=Q}return se},[m]),je=j.useMemo(()=>{const se={};for(const V of m)for(const ie of Ft(V.root))se[ie]=V.id;return se},[m]);j.useEffect(()=>{const se=V=>{const ie=/Mac|iPhone|iPad|iPod/.test(navigator.platform),Q=ie?V.metaKey:V.ctrlKey,ke=ie?V.ctrlKey:V.metaKey;if(!Q||ke||V.altKey||V.shiftKey||V.key.toLowerCase()!=="t")return;V.preventDefault();const _e=p.current.filter(Ee=>!Ee.minimized&&(Ee.ownerWindowId||gt)===gt).reduce((Ee,Pe)=>Ee&&Ee.z>=Pe.z?Ee:Pe,null);st((_e==null?void 0:_e.id)??null).catch(()=>{})};return window.addEventListener("keydown",se),()=>window.removeEventListener("keydown",se)},[st]);const ue=j.useMemo(()=>{const se=new Map;for(const V of Object.values(y))se.set(V.id,V);for(const V of h)se.set(V.id,V);return se},[h,y]),ee=m.filter(se=>!se.minimized&&(se.ownerWindowId||gt)===gt),be=ee.reduce((se,V)=>V.z>se.z?{id:V.id,z:V.z}:se,{id:null,z:-1/0}).id,he=ee.find(se=>se.id===be),He=Te&&he?wr(he.root).join(","):"",Me=j.useMemo(()=>new Set(He?He.split(","):[]),[He]),Ge=Ph(M,Me,(se,V)=>{var Q;const ie=Ts(p.current,se);!ie||ie.minimized||(ie.ownerWindowId||gt)!==gt||g(r(V==="blocked"?"notification.sessionBlocked":"notification.sessionDone"),((Q=ue.get(se))==null?void 0:Q.title)||se,()=>H(se))});return v.jsx(Uh.Provider,{value:le,children:v.jsx(x_.Provider,{value:Ne,children:v.jsx(C_.Provider,{value:je,children:v.jsxs(Hh.Provider,{value:Ge,children:[A,(()=>{const se=new Map(ee.slice().sort((V,ie)=>V.z-ie.z).map((V,ie)=>[V.id,ie+1]));return ee.map(V=>{const ie=ee.filter(Q=>Q.id!==V.id).map(({x:Q,y:ke,w:ce,h:_e})=>({x:Q,y:ke,w:ce,h:_e}));return v.jsx(XC,{group:V,sessionsById:ue,neighbors:ie,isTopmost:V.id===be,zIndex:se.get(V.id)??1,sendMessage:w,subscribeBinary:S,onEvent:M},V.id)})})(),c&&c.hoveredRect&&v.jsx(vr,{targetRect:c.hoveredRect,activeZone:c.zone}),c&&!c.zone&&Math.hypot(c.mouseX-c.startX,c.mouseY-c.startY)>=Wg&&v.jsx(S_,{activeZone:c.viewportZone}),Oe&&v.jsx(vr,{targetRect:Oe.rect,activeZone:Oe.zone})]})})})})}const s2=26;function Wh({stack:s,path:h,groupId:w,sessionsById:S,colors:M,intents:O,onTabClick:A,onTabClose:r,onTabMouseDown:u,onPaneAutoClose:d,registerRect:g,sendMessage:l,subscribeBinary:m,onEvent:b,focusedSessionId:C,groupTopmost:p,onFocusStack:o,groupActions:c}){const{t:a}=Tt(),[f,,y]=qv(s.activeTab),[R,k]=j.useState({}),D=()=>{const T=s.activeTab;T&&k(F=>({...F,[T]:(F[T]||0)+1}))},E=JC(),{states:L,attention:z}=j.useContext(Hh),H=p===void 0?!0:p&&(!C||C===s.activeTab),P=p===!0&&!H,I=S.get(s.activeTab),K=[[I==null?void 0:I.cli_tool,I==null?void 0:I.cli_model].filter(Boolean).join("/"),I==null?void 0:I.branch_name,I==null?void 0:I.status,I!=null&&I.total_tokens?`${I.total_tokens.toLocaleString()} tok`:""].filter(Boolean).join(" · "),X=T=>{T.button===0&&s.activeTab&&(o?o(s.activeTab):E==null||E.focus(s.activeTab)),T.stopPropagation()},Y=s.tabs.length>1?T=>{const F=s.tabs.indexOf(s.activeTab);if(F<0)return;const B=s.tabs.length,W=T==="next"?(F+1)%B:(F-1+B)%B;A(s.tabs[W])}:void 0,$=s.tabs.length>1?T=>{const F=s.tabs[T];F&&A(F)}:void 0,U=T=>{var J;const F=/Mac|iPhone|iPad|iPod/.test(navigator.platform),B=F?T.metaKey:T.ctrlKey,W=F?T.ctrlKey:T.metaKey,Z=B&&!W&&!T.altKey&&T.shiftKey,ne=T.key.toLowerCase();if(T.key==="F5"&&!T.ctrlKey&&!T.metaKey&&!T.altKey&&!T.shiftKey||Z&&ne==="r"){T.preventDefault(),D();return}if(!Z||ne!=="a"&&ne!=="p")return;T.preventDefault();const xe=ne==="a"?"alias-inserter":"terminal-theme";(J=T.currentTarget.querySelector(`[aria-label="${xe}"]`))==null||J.click()};return v.jsxs("div",{onKeyDown:U,style:{flex:1,display:"flex",flexDirection:"column",background:Ce.bg,minWidth:0,minHeight:0,position:"relative",overflow:"hidden",opacity:P?p?.78:.88:1,filter:P?"saturate(0.78)":"none",boxShadow:H?`inset 0 0 0 1px ${Ce.info}`:"inset 0 0 0 1px transparent",transition:"opacity 140ms ease-out, filter 140ms ease-out, box-shadow 140ms ease-out"},children:[v.jsxs("div",{onDoubleClick:T=>{var F;T.target.closest("button")||(F=c==null?void 0:c.onToggleMaximize)==null||F.call(c)},style:{display:"flex",height:s2,background:H?"#323a42":Ce.titleBg,borderBottom:`1px solid ${Ce.separator}`,flexShrink:0,overflowX:"auto",overflowY:"hidden"},children:[s.tabs.map((T,F)=>{const B=S.get(T),W=T===s.activeTab,Z=M[T]||Ce.titleText,ne=(B==null?void 0:B.status)==="running"?Ce.success:(B==null?void 0:B.status)==="failed"?Ce.error:(B==null?void 0:B.status)==="completed"?Ce.info:Ce.dim,ge=L[T]??(B==null?void 0:B.agent_state)??"unknown",xe=ge==="working"?Ce.info:ge==="blocked"?Ce.warning:ne,J=z.has(T),G=s.tabs.length>1&&F<9?`Ctrl+${F+1}`:"",de=[B==null?void 0:B.status,ge!=="unknown"?ge:"",B==null?void 0:B.cli_tool,B==null?void 0:B.cli_model,B==null?void 0:B.branch_name,G].filter(Boolean).join(" · ");return v.jsxs("div",{onMouseDown:oe=>{if(oe.button===0){if(c){A(T);return}oe.stopPropagation(),A(T),u(T,h,oe)}},style:{display:"flex",alignItems:"center",gap:6,padding:"0 6px 0 10px",fontFamily:_t,fontSize:11,color:W?Ce.bright:Ce.titleText,background:W?Ce.bg:"transparent",borderRight:`1px solid ${Ce.separator}`,cursor:"pointer",userSelect:"none",whiteSpace:"nowrap",maxWidth:200,position:"relative",boxShadow:J?`inset 0 -2px 0 ${xe}`:void 0},title:`${(B==null?void 0:B.title)||T}${de?`
422
- ${de}`:""}`,children:[v.jsx("span",{"aria-label":ge!=="unknown"?ge:(B==null?void 0:B.status)||"unknown",className:ge==="working"?"workspace-dot-pulse":void 0,style:{width:6,height:6,borderRadius:"50%",background:xe,flexShrink:0}}),v.jsx("span",{"aria-hidden":!0,style:{flexShrink:0,fontFamily:_t,fontSize:11,fontWeight:700,letterSpacing:-.5,lineHeight:1,color:Z,width:16,textAlign:"center"},children:">_"}),v.jsx("span",{style:{overflow:"hidden",textOverflow:"ellipsis",flex:1,color:J?xe:void 0,fontWeight:J?600:void 0},children:(B==null?void 0:B.title)||T}),v.jsx("button",{"data-no-drag":!0,onMouseDown:oe=>oe.stopPropagation(),onClick:oe=>{oe.stopPropagation(),r(T)},"aria-label":"close-tab",title:a("group.closeTab")||"Close tab",style:{background:"transparent",border:"none",color:Ce.titleText,cursor:"pointer",padding:1,display:"flex",alignItems:"center",justifyContent:"center",borderRadius:3,flexShrink:0},children:v.jsx(Ri,{size:12})})]},T)}),E&&v.jsx("button",{"data-no-drag":!0,onMouseDown:T=>T.stopPropagation(),onClick:()=>{E.createRawShellTab(w,h).catch(()=>{})},"aria-label":"new-tab",title:`${a("group.newTab")||"New shell tab"} (Ctrl+T)`,style:{background:"transparent",border:"none",borderRight:`1px solid ${Ce.separator}`,color:Ce.titleText,cursor:"pointer",padding:"0 8px",display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0,height:"100%"},children:v.jsx(Mn,{size:14})}),v.jsx("div",{style:{flex:1,minWidth:8}}),K&&v.jsx("span",{title:K,style:{maxWidth:260,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:Ce.dim,fontFamily:_t,fontSize:9,padding:"0 7px",flexShrink:1},children:K}),v.jsx(BC,{sessionId:s.activeTab,sendMessage:l}),v.jsx("button",{"data-no-drag":!0,onMouseDown:T=>T.stopPropagation(),onClick:D,"aria-label":"refresh-terminal",title:`${a("session.refresh")||"Refresh rendering"} (F5 · Ctrl+Shift+R) — ${a("session.refresh.hint")||"Rebuild the terminal view (PTY stays running)"}`,style:Zi,children:v.jsx(aS,{size:12})}),v.jsx("button",{"data-no-drag":!0,onMouseDown:T=>T.stopPropagation(),onClick:()=>y(-1),"aria-label":"decrease-font",title:`${a("session.fontDecrease")||"Decrease font size"} (${f}px) · Ctrl+- · Ctrl+wheel`,style:Zi,children:v.jsx(LS,{size:14})}),v.jsx("button",{"data-no-drag":!0,onMouseDown:T=>T.stopPropagation(),onClick:()=>y(1),"aria-label":"increase-font",title:`${a("session.fontIncrease")||"Increase font size"} (${f}px) · Ctrl+= · Ctrl+wheel`,style:Zi,children:v.jsx(kS,{size:14})}),v.jsx(jC,{sessionId:s.activeTab}),c&&v.jsxs(v.Fragment,{children:[s.tabs.length>1&&c.onApplyLayoutPreset&&v.jsxs(v.Fragment,{children:[v.jsx("button",{"data-no-drag":!0,onMouseDown:T=>T.stopPropagation(),onClick:()=>{var T;return(T=c.onApplyLayoutPreset)==null?void 0:T.call(c,"single")},"aria-label":"single-pane",title:a("session.layout.single"),style:Zi,children:v.jsx(jv,{size:12})}),v.jsx("button",{"data-no-drag":!0,onMouseDown:T=>T.stopPropagation(),onClick:()=>{var T;return(T=c.onApplyLayoutPreset)==null?void 0:T.call(c,"columns")},"aria-label":"two-columns",title:a("session.layout.columns"),style:Zi,children:v.jsx(Lv,{size:14})}),v.jsx("button",{"data-no-drag":!0,onMouseDown:T=>T.stopPropagation(),onClick:()=>{var T;return(T=c.onApplyLayoutPreset)==null?void 0:T.call(c,"grid")},"aria-label":"grid-layout",title:a("session.layout.grid"),style:Zi,children:v.jsx(Tv,{size:14})})]}),c.onToggleMaximize&&v.jsx("button",{"data-no-drag":!0,onMouseDown:T=>T.stopPropagation(),onClick:c.onToggleMaximize,"aria-label":"toggle-maximize",title:`${c.isMaximized?a("session.restoreSize"):a("session.maximize")} · ${a("session.maximizeHint")}`,style:Zi,children:c.isMaximized?v.jsx(Th,{size:14}):v.jsx(El,{size:14})}),c.onPopOutGroup&&v.jsx("button",{"data-no-drag":!0,onMouseDown:T=>T.stopPropagation(),onClick:c.onPopOutGroup,"aria-label":"pop-out",title:`${a("session.popOut")||"Pop out to separate window"} (Ctrl+Shift+O)`,style:Zi,children:v.jsx(_r,{size:14})}),c.onReDockGroup&&v.jsx("button",{"data-no-drag":!0,onMouseDown:T=>T.stopPropagation(),onClick:c.onReDockGroup,"aria-label":"redock",title:a("session.popout.redock")||"Re-dock to main window",style:Zi,children:v.jsx(_r,{size:14,style:{transform:"scaleX(-1)"}})}),c.onMinimizeGroup&&v.jsx("button",{"data-no-drag":!0,onMouseDown:T=>T.stopPropagation(),onClick:c.onMinimizeGroup,"aria-label":"minimize",title:`${a("session.minimize")||"Minimize"} (Ctrl+Shift+M)`,style:Zi,children:v.jsx(Mh,{size:14})}),v.jsx("button",{"data-no-drag":!0,onMouseDown:T=>T.stopPropagation(),onClick:c.onCloseGroup,"aria-label":"close",title:`${a("session.close")||"Close"} (Ctrl+Shift+X)`,style:Zi,children:v.jsx(Ri,{size:14})})]})]}),v.jsx("div",{"data-group-id":w,"data-stack-path":h.join("."),ref:T=>{if(!T){g(h,null);return}const F=T.getBoundingClientRect();g(h,{x:F.left,y:F.top,w:F.width,h:F.height})},onMouseDown:X,style:{flex:1,position:"relative",minHeight:0,minWidth:0},children:s.tabs.map(T=>{const F=S.get(T);if(!F)return null;const B=O[T]||{intent:"open",nonce:0};return v.jsx(__,{session:F,visible:T===s.activeTab,intent:B.intent,intentNonce:B.nonce,onClose:()=>d(T),sendMessage:l,subscribeBinary:m,onEvent:b,onCycleTab:Y,onSelectTab:$,remountKey:R[T]||0},T)})})]})}const Zi={background:"transparent",border:"none",color:Ce.titleText,cursor:"pointer",padding:"0 6px",display:"flex",alignItems:"center",justifyContent:"center",borderRadius:0,flexShrink:0,height:"100%"},Yg=28;function n2({sendMessage:s,subscribeBinary:h,onEvent:w}){var je;const{projectId:S="",groupId:M=""}=By(),[O]=kw(),A=O.get("wid")||"",{t:r}=Tt(),{confirm:u}=kr(),[d,g]=j.useState(null),[l,m]=j.useState([]),[b,C]=j.useState(null),[p,o]=j.useState(null),[c,a]=j.useState(0),f=j.useRef(0),y=j.useRef(0),R=j.useRef(0);j.useEffect(()=>{const ee=()=>{const Me=f.current;!Me||R.current===Me||Math.abs(y.current-Me)<=400&&(R.current=Me,a(Ge=>Ge+1))},be=()=>{f.current=Date.now(),D(!0),ee()},he=()=>D(!1),He=()=>{y.current=Date.now(),ee()};return window.addEventListener("focus",be),window.addEventListener("blur",he),window.addEventListener("pointerdown",He,!0),()=>{window.removeEventListener("focus",be),window.removeEventListener("blur",he),window.removeEventListener("pointerdown",He,!0)}},[]);const[k,D]=j.useState(()=>typeof document<"u"&&document.hasFocus()),{sendNotification:E}=Ll(),L=j.useRef(null);L.current=d;const z=j.useRef(null),H=j.useRef(!1);j.useEffect(()=>{if(!S)return;let ue=!1;return tC(S).then(ee=>{ue||m(ee)}).catch(ee=>{ue||C(String((ee==null?void 0:ee.message)||ee))}),()=>{ue=!0}},[S]);const P=j.useRef(new Set);j.useEffect(()=>{if(!d||l.length===0)return;const ue=new Set(l.map(ee=>ee.id));for(const ee of Ft(d.root))ue.has(ee)||P.current.has(ee)||(P.current.add(ee),l_(ee).then(be=>m(he=>he.some(He=>He.id===be.id)?he:[...he,be])).catch(()=>{}))},[d,l]),j.useEffect(()=>w(ee=>{ee.type==="session:status-changed"&&ee.sessionId&&m(be=>be.map(he=>{if(he.id!==ee.sessionId)return he;const He={status:ee.status,updated_at:new Date().toISOString()};return ee.worktree_path!==void 0&&(He.worktree_path=ee.worktree_path),ee.branch_name!==void 0&&(He.branch_name=ee.branch_name),{...he,...He}}))}),[w]),j.useEffect(()=>{if(!S||!M||!A)return;const ue=Bh();z.current=ue;const ee=ue.subscribe(Me=>{if(Me.t==="dock-probe"||Me.t==="dock-probe-result"||Me.t==="dock-end"||Me.t==="dock-commit"||Me.t==="dock-commit-ack"){ye.current(Me);return}if(Me.t==="group-handoff"&&Me.to===A&&Me.groupId===M){const Ge=Me.group;g({...Ge,x:0,y:0,w:window.innerWidth,h:Math.max(0,window.innerHeight-(Ge.root.kind==="split"?Yg:0)),minimized:!1,ownerWindowId:A})}else if(Me.t==="group-recall"&&Me.popoutId===A&&Me.groupId===M){const Ge=L.current;Ge&&ue.post({t:"group-return",from:A,groupId:Ge.id,group:Ge,projectId:S}),setTimeout(()=>{try{window.close()}catch{}},50)}else if(Me.t==="group-focus"&&Me.popoutId===A&&Me.groupId===M){const Ge=window.electronAPI;if(Ge!=null&&Ge.windowFocus)Ge.windowFocus();else try{window.focus()}catch{}}else Me.t==="group-reclaimed"&&Me.popoutId===A&&(g(null),o(r("session.popout.reclaimed")||"메인 윈도우가 이 터미널을 회수했습니다. 잠시 후 창이 닫힙니다."),setTimeout(()=>{try{window.close()}catch{}},1500))});ue.post({t:"hello",from:A,groupId:M});const be=zx(A),he=setInterval(()=>{const Me=L.current;ue.post({t:"heartbeat",from:A,ownedGroupIds:Me?[Me.id]:[M]})},Nh),He=()=>{const Me=L.current;Me&&!H.current&&ue.post({t:"group-return",from:A,groupId:Me.id,group:Me,projectId:S}),ue.post({t:"bye",from:A})};return window.addEventListener("beforeunload",He),()=>{clearInterval(he),be(),window.removeEventListener("beforeunload",He),ee(),ue.close(),z.current=null}},[S,M,A]);const I=j.useCallback(ue=>{!z.current||!L.current||z.current.post({t:"group-update",from:A,groupId:L.current.id,patch:ue,projectId:S})},[A,S]),K=j.useCallback(ue=>{g(ee=>{if(!ee)return ee;const be={...ee,root:Ki(ee.root,ue)};return I({root:be.root}),be})},[I]),X=j.useCallback(ue=>{g(ee=>{var se;if(!ee)return ee;const be=Dn(ee.root,ue);if(!be)return H.current=!0,(se=z.current)==null||se.post({t:"group-close",from:A,groupId:ee.id,projectId:S}),setTimeout(()=>window.close(),50),null;const he=new Set(Ft(be)),He={};for(const V of Object.keys(ee.colors))he.has(V)&&(He[V]=ee.colors[V]);const Me={};for(const V of Object.keys(ee.intents))he.has(V)&&(Me[V]=ee.intents[V]);const Ge={...ee,root:be,colors:He,intents:Me};return I({root:Ge.root,colors:Ge.colors,intents:Ge.intents}),Ge})},[I,A]),Y=j.useCallback(async ue=>{const ee=l.find(be=>be.id===ue);if((ee==null?void 0:ee.status)==="running"){if(!await u({message:r("session.confirmStop"),danger:!0}))return;gh(ue).catch(()=>{})}X(ue)},[l,r,X,u]),[$,U]=j.useState(null),T=j.useRef(null);T.current=$;const F=j.useRef(new Map),B=j.useRef(null),W=j.useRef(0),Z=j.useMemo(()=>({begin(){F.current.clear(),W.current=0},probe(ue){var ee;Date.now()-W.current<33||(W.current=Date.now(),(ee=z.current)==null||ee.post({t:"dock-probe",from:A,x:ue.screenX,y:ue.screenY}))},best(){const ue=Date.now();let ee=null;for(const[be,he]of F.current)!he.hit||ue-he.at>500||(!ee||he.focusAt>ee.focusAt)&&(ee={id:be,focusAt:he.focusAt,rect:he.rect,zone:he.zone});return ee},commit(ue,ee,be,he){var Me;const He=`${A}_${Date.now().toString(36)}_${Math.random().toString(36).slice(2,6)}`;B.current&&clearTimeout(B.current.timer),B.current={to:ue,commitId:He,ids:be.map(Ge=>Ge.id),timer:setTimeout(()=>{B.current=null},600)},(Me=z.current)==null||Me.post({t:"dock-commit",from:A,to:ue,x:ee.screenX,y:ee.screenY,commitId:He,sessions:be,activeId:he})},end(){var ue;F.current.clear(),(ue=z.current)==null||ue.post({t:"dock-end",from:A})}}),[A]),[ne,ge]=j.useState(null),xe=j.useRef(ne);xe.current=ne;const J=j.useRef(null),G=j.useRef(typeof document<"u"&&document.hasFocus()?Date.now():0);j.useEffect(()=>{const ue=()=>{G.current=Date.now()};window.addEventListener("focus",ue);const ee=e_();return()=>{window.removeEventListener("focus",ue),ee(),J.current&&clearTimeout(J.current)}},[]);const de=6,oe=j.useCallback((ue,ee,be)=>{if(be.button!==0||!L.current)return;be.preventDefault();const he=be.clientX,He=be.clientY;let Me=!1;Z.begin();const Ge=_e=>{if(!Me){if(Math.hypot(_e.clientX-he,_e.clientY-He)<de)return;Me=!0}if(!(_e.clientX>=0&&_e.clientY>=0&&_e.clientX<=window.innerWidth&&_e.clientY<=window.innerHeight)){U({sessionId:ue,fromPath:ee,hoveredPath:null,hoveredRect:null,zone:null}),Z.probe(_e);return}let Pe=null,Ue=null,ot=null;const Ye=document.elementsFromPoint(_e.clientX,_e.clientY);for(const ut of Ye){const ft=ut.closest("[data-group-id][data-stack-path]");if(!ft)continue;const kt=ft.dataset.stackPath||"",vt=kt===""?[]:kt.split(".").map(Number),Vt=kt===ee.join(".");if(Vt){const Ze=L.current,fe=Ze?cn(Ze.root,ee):null;if(!fe||fe.kind!=="stack"||fe.tabs.length<2)break}const Nt=ft.getBoundingClientRect();Pe=vt,Ue={x:Nt.left,y:Nt.top,w:Nt.width,h:Nt.height},ot=Dl(_e.clientX,_e.clientY,Ue),Vt&&ot==="center"&&(ot=null);break}U({sessionId:ue,fromPath:ee,hoveredPath:Pe,hoveredRect:Ue,zone:ot})};let se=!1;const V=()=>{se||(se=!0,window.removeEventListener("mousemove",Ge),window.removeEventListener("mouseup",ce),window.removeEventListener("blur",ie),window.removeEventListener("keydown",Q),document.removeEventListener("visibilitychange",ke))},ie=()=>{V(),U(null),Z.end()},Q=_e=>{_e.key==="Escape"&&ie()},ke=()=>{document.hidden&&ie()},ce=_e=>{V();const Ee=T.current;U(null);const Pe=Z.best();if(Z.end(),!Ee)return;if(Ee.hoveredPath&&Ee.zone){const ot=L.current;if(!ot)return;const Ye=Rx(ot.root,Ee.sessionId,Ee.hoveredPath,Ee.zone);if(!Ye)return;g({...ot,root:Ye}),I({root:Ye});return}if(!Pe)return;const Ue=L.current;Z.commit(Pe.id,_e,[{id:Ee.sessionId,color:Ue==null?void 0:Ue.colors[Ee.sessionId],intentInfo:Ue==null?void 0:Ue.intents[Ee.sessionId]}],Ee.sessionId)};window.addEventListener("mousemove",Ge),window.addEventListener("mouseup",ce),window.addEventListener("blur",ie),window.addEventListener("keydown",Q),document.addEventListener("visibilitychange",ke)},[I,Z]),[Ae,Oe]=j.useState(null),Xe=j.useCallback(ue=>{var ot;if(ue.button!==0||ue.target.closest("[data-no-drag]"))return;const ee=L.current;if(!ee||ee.root.kind!=="stack")return;ue.preventDefault();const be=ue.screenX,he=ue.screenY,He=window.screenX,Me=window.screenY,Ge=window.electronAPI;(ot=Ge==null?void 0:Ge.windowMoveStart)==null||ot.call(Ge),Z.begin();let se=!1,V=null,ie=0;const Q=()=>{if(ie=0,!!V)if(Ge!=null&&Ge.windowMoveBy)Ge.windowMoveBy(V.dx,V.dy);else try{window.moveTo(He+V.dx,Me+V.dy)}catch{}},ke=Ye=>{const ut=Ye.screenX-be,ft=Ye.screenY-he;if(!se){if(Math.hypot(ut,ft)<de)return;se=!0}V={dx:ut,dy:ft},ie||(ie=requestAnimationFrame(Q)),Z.probe(Ye);const kt=Z.best();if(kt!=null&&kt.rect){const vt=An();Oe({rect:{x:Ye.clientX+(kt.rect.x-Ye.screenX)/vt,y:Ye.clientY+(kt.rect.y-Ye.screenY)/vt,w:kt.rect.w/vt,h:kt.rect.h/vt},zone:kt.zone??null})}else Oe(null)};let ce=!1;const _e=()=>{ce||(ce=!0,window.removeEventListener("mousemove",ke),window.removeEventListener("mouseup",Ue),window.removeEventListener("blur",_e),window.removeEventListener("keydown",Ee),document.removeEventListener("visibilitychange",Pe),ie&&cancelAnimationFrame(ie),Oe(null),Z.end())},Ee=Ye=>{Ye.key==="Escape"&&_e()},Pe=()=>{document.hidden&&_e()},Ue=Ye=>{const ut=Z.best();if(_e(),!se||!(ut!=null&&ut.zone))return;const ft=L.current;!ft||ft.root.kind!=="stack"||Z.commit(ut.id,Ye,ft.root.tabs.map(kt=>({id:kt,color:ft.colors[kt],intentInfo:ft.intents[kt]})),ft.root.activeTab)};window.addEventListener("mousemove",ke),window.addEventListener("mouseup",Ue),window.addEventListener("blur",_e),window.addEventListener("keydown",Ee),document.addEventListener("visibilitychange",Pe)},[Z]),We=j.useCallback(ue=>{g(ee=>{if(!ee)return ee;const be={...ee,root:Yv(ee.root,ue)};return I({root:be.root}),be})},[I]),rt=ue=>{var be;const ee=z.current;if(ee){if(ue.t==="dock-probe"&&ue.from!==A){if(document.visibilityState!=="visible"||!L.current)return;const he=vl(ue.x,ue.y),He=_l(he)?bl(he.x,he.y):null;if(He&&He.groupId===L.current.id){const Me=xe.current;(!Me||Me.zone!==He.zone||Me.path.join(".")!==He.path.join("."))&&ge({rect:He.rect,zone:He.zone,path:He.path}),J.current&&clearTimeout(J.current),J.current=setTimeout(()=>ge(null),800);const Ge=An();ee.post({t:"dock-probe-result",from:A,to:ue.from,hit:!0,focusAt:G.current,rect:{...i_(He.rect.x,He.rect.y),w:He.rect.w*Ge,h:He.rect.h*Ge},zone:He.zone})}else xe.current&&ge(null),ee.post({t:"dock-probe-result",from:A,to:ue.from,hit:!1,focusAt:G.current})}else if(ue.t==="dock-probe-result"&&ue.to===A)F.current.set(ue.from,{hit:ue.hit,focusAt:ue.focusAt,at:Date.now(),rect:ue.rect,zone:ue.zone});else if(ue.t==="dock-end"&&ue.from!==A)ge(null);else if(ue.t==="dock-commit"&&ue.to===A){const he=L.current;let He=!1;const Me=ue.sessions.map(Ge=>Ge.id);if(he&&!Me.some(Ge=>Ft(he.root).includes(Ge))){const Ge=vl(ue.x,ue.y),se=_l(Ge)?bl(Ge.x,Ge.y):null,V=se&&se.groupId===he.id&&se.zone?{path:se.path,zone:se.zone}:(be=xe.current)!=null&&be.zone?{path:xe.current.path,zone:xe.current.zone}:null;if(V){const ie=Xv(he.root,V.path,V.zone,Me,ue.activeId),Q={...he.colors},ke={...he.intents};for(const ce of ue.sessions)Q[ce.id]||(Q[ce.id]=ce.color||Ln(Object.values(Q))),ke[ce.id]=ce.intentInfo??{intent:"open",nonce:0};g({...he,root:ie,colors:Q,intents:ke}),I({root:ie,colors:Q,intents:ke}),He=!0}}ge(null),ee.post({t:"dock-commit-ack",from:A,to:ue.from,commitId:ue.commitId,accepted:He})}else if(ue.t==="dock-commit-ack"&&ue.to===A){const he=B.current;if(he&&he.commitId===ue.commitId&&he.to===ue.from&&(clearTimeout(he.timer),B.current=null,ue.accepted))for(const He of he.ids)X(He)}}},ye=j.useRef(rt);ye.current=rt;const Te=j.useCallback(ue=>{Y(ue)},[Y]),ct=j.useCallback((ue,ee)=>{g(be=>{if(!be)return be;const he={...be,root:Jv(be.root,ue,ee)};return I({root:he.root}),he})},[I]),it=window.electronAPI,ze=!!(it!=null&&it.windowMinimize),qe=j.useCallback(()=>{var ue;(ue=it==null?void 0:it.windowMinimize)==null||ue.call(it)},[it]),Fe=j.useCallback(()=>{const ue=L.current;if(!ue||!z.current){window.close();return}z.current.post({t:"group-return",from:A,groupId:ue.id,group:ue,projectId:S}),setTimeout(()=>window.close(),50)},[A,S]),Be=j.useCallback(async()=>{const ue=L.current;if(!ue||!z.current){window.close();return}const be=Ft(ue.root).filter(he=>{var He;return((He=l.find(Me=>Me.id===he))==null?void 0:He.status)==="running"});be.length&&!await u({message:r("session.confirmStop"),danger:!0})||(be.forEach(he=>gh(he).catch(()=>{})),H.current=!0,z.current.post({t:"group-close",from:A,groupId:ue.id,projectId:S}),setTimeout(()=>window.close(),50))},[l,r,A,S,u]),$e=j.useMemo(()=>{const ue=new Map;for(const ee of l)ue.set(ee.id,ee);return ue},[l]),lt=k&&d?wr(d.root).join(","):"",st=j.useMemo(()=>new Set(lt?lt.split(","):[]),[lt]),St=Ph(w,st,(ue,ee)=>{var he;const be=L.current;!be||!Ft(be.root).includes(ue)||E(r(ee==="blocked"?"notification.sessionBlocked":"notification.sessionDone"),((he=$e.get(ue))==null?void 0:he.title)||ue,()=>K(ue))});if(b)return v.jsxs("div",{style:sh,children:[v.jsx("p",{children:r("session.popout.loadFailed")||"Failed to load popout window."}),v.jsx("p",{style:{fontSize:12,opacity:.7},children:b})]});if(!d)return p?v.jsx("div",{style:sh,children:v.jsx("p",{children:p})}):v.jsxs("div",{style:sh,children:[v.jsx("p",{children:r("session.popout.waiting")||"Waiting for main window…"}),v.jsx("p",{style:{fontSize:12,opacity:.7},children:r("session.popout.waitingHint")||"If the main app is not open, this window cannot start. Open the project in the main app and try Pop Out again."})]});const Se=Ft(d.root),Ie=Se.length>0?((je=$e.get(Se[0]))==null?void 0:je.title)||Se[0]:"",le=Se.length===1?Ie:`${Ie} +${Se.length-1}`,Ne=d.root.kind==="split";return v.jsxs("div",{style:{position:"fixed",inset:0,background:Ce.bg,display:"flex",flexDirection:"column"},children:[c>0&&v.jsx("div",{className:"popout-focus-flash","aria-hidden":!0},c),Ne&&v.jsxs("div",{style:{height:Yg,background:Ce.titleBg,borderBottom:`1px solid ${Ce.separator}`,display:"flex",alignItems:"center",padding:"0 4px 0 10px",color:Ce.titleText,fontFamily:_t,fontSize:11,flexShrink:0,userSelect:"none",WebkitAppRegion:"drag"},children:[v.jsx("span",{style:{color:Ce.info,fontWeight:600,letterSpacing:1,marginRight:8},"aria-hidden":!0,children:">_"}),v.jsx("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:le}),ze&&v.jsx("button",{onClick:qe,style:nh,"aria-label":"minimize-popout",title:r("session.popout.minimize")||"Minimize",children:v.jsx(Mh,{size:14})}),v.jsxs("button",{onClick:Fe,style:nh,"aria-label":"redock",title:r("session.popout.redock")||"Re-dock to main window",children:[v.jsx(_r,{size:14,style:{transform:"scaleX(-1)"}}),v.jsx("span",{style:{marginLeft:4},children:r("session.popout.redockShort")||"Re-dock"})]}),v.jsx("button",{onClick:Be,style:nh,"aria-label":"close-popout",title:r("session.popout.closeWindow")||"Close window",children:v.jsx(Ri,{size:14})})]}),v.jsx("div",{onMouseDown:Ne?void 0:Xe,style:{flex:1,display:"flex",minHeight:0,minWidth:0},children:v.jsx(Hh.Provider,{value:St,children:d.root.kind==="split"?v.jsx(Fh,{node:d.root,path:[],groupId:d.id,sessionsById:$e,colors:d.colors,intents:d.intents,onTabClick:K,onTabClose:Y,onTabMouseDown:oe,onPaneAutoClose:Te,registerRect:()=>{},onSplitSizes:ct,sendMessage:s,subscribeBinary:h,onEvent:w}):v.jsx(Wh,{stack:d.root,path:[],groupId:d.id,sessionsById:$e,colors:d.colors,intents:d.intents,onTabClick:K,onTabClose:Y,onTabMouseDown:oe,onPaneAutoClose:Te,registerRect:()=>{},sendMessage:s,subscribeBinary:h,onEvent:w,groupActions:{onMinimizeGroup:ze?qe:void 0,onReDockGroup:Fe,onCloseGroup:Be,onApplyLayoutPreset:We}})})}),$&&$.hoveredRect&&v.jsx(vr,{targetRect:$.hoveredRect,activeZone:$.zone}),Ae&&v.jsx(vr,{targetRect:Ae.rect,activeZone:Ae.zone}),ne&&v.jsx(vr,{targetRect:ne.rect,activeZone:ne.zone})]})}const sh={position:"fixed",inset:0,background:Ce.bg,color:Ce.titleText,fontFamily:_t,fontSize:12,display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",gap:8,padding:24,textAlign:"center"},nh={background:"transparent",border:"none",color:Ce.titleText,cursor:"pointer",padding:"4px 8px",display:"flex",alignItems:"center",justifyContent:"center",borderRadius:4,fontFamily:_t,fontSize:11,WebkitAppRegion:"no-drag"},r2=j.lazy(()=>Oo(()=>import("./ProjectList-BJo-FMR3.js"),__vite__mapDeps([0,1]))),o2=j.lazy(()=>Oo(()=>import("./ProjectDetail-eFpOIAWj.js").then(s=>s.l),__vite__mapDeps([2,3,4,5,6,7,1]))),a2=j.lazy(()=>Oo(()=>import("./DiscussionDetail-CpPbB3D-.js"),__vite__mapDeps([8,6,5,7]))),l2=j.lazy(()=>Oo(()=>import("./ReviewQueue-Bc7VQ6Gf.js"),__vite__mapDeps([9,4,5,10]))),c2=j.lazy(()=>Oo(()=>import("./PersonalAgenda-C8P8R7BW.js"),__vite__mapDeps([11,3,7,10])));function u2(){const{authenticated:s,authRequired:h,setupRequired:w,loading:S,login:M,logout:O,setup:A,changePassword:r}=jw(),{connected:u,onEvent:d,sendMessage:g,subscribeBinary:l}=Bw(s),{t:m}=Tt();return j.useEffect(()=>{s&&Wv().then(b=>{var C,p;hl(b.defaultFontSize),(p=(C=window.electronAPI)==null?void 0:C.imeSetDebug)==null||p.call(C,b.imeDebug)}).catch(()=>{})},[s]),j.useEffect(()=>{const b=window.electronAPI,C=f=>{var y;return!!f&&!((y=f.classList)!=null&&y.contains("xterm-helper-textarea"))&&(f.tagName==="INPUT"||f.tagName==="TEXTAREA"||f.isContentEditable)},p=f=>{var y;h_(()=>f.focus())&&((y=b==null?void 0:b.imeLog)==null||y.call(b,{src:"app",event:"focus-rescue",tag:f.tagName}))},o=f=>{var R;const y=f.target;if(C(y)){if(!document.hasFocus()){p(y);return}(R=b==null?void 0:b.imeReset)==null||R.call(b)}},c=f=>{if(document.hasFocus())return;const y=f.target;C(y)&&p(y)},a=()=>{if(document.hasFocus())return;const f=document.activeElement;C(f)&&p(f)};return document.addEventListener("focusin",o,!0),document.addEventListener("pointerdown",c,!0),document.addEventListener("keydown",a,!0),()=>{document.removeEventListener("focusin",o,!0),document.removeEventListener("pointerdown",c,!0),document.removeEventListener("keydown",a,!0)}},[]),S?v.jsxs("div",{className:"flex h-screen overflow-hidden",style:{backgroundColor:"var(--color-bg-primary)"},children:[v.jsxs("div",{className:"hidden md:flex flex-col w-64 border-r border-theme-border p-4 space-y-6",children:[v.jsx(pi,{className:"h-8 w-32 mb-4"}),v.jsxs("div",{className:"space-y-3",children:[v.jsx(pi,{className:"h-4 w-full"}),v.jsx(pi,{className:"h-4 w-5/6"}),v.jsx(pi,{className:"h-4 w-4/6"})]}),v.jsxs("div",{className:"mt-auto space-y-3 pt-4 border-t border-theme-border",children:[v.jsx(pi,{className:"h-4 w-1/2"}),v.jsxs("div",{className:"flex gap-2",children:[v.jsx(pi,{className:"h-8 w-8"}),v.jsx(pi,{className:"h-8 w-8"}),v.jsx(pi,{className:"h-8 w-8"})]})]})]}),v.jsxs("div",{className:"flex-1 flex flex-col overflow-hidden",children:[v.jsx("div",{className:"md:hidden h-14 border-b border-theme-border flex items-center px-4",children:v.jsx(pi,{className:"h-6 w-32"})}),v.jsxs("div",{className:"flex-1 overflow-y-auto p-6 space-y-8",children:[v.jsxs("div",{className:"flex justify-between items-center",children:[v.jsxs("div",{className:"space-y-2",children:[v.jsx(pi,{className:"h-8 w-48"}),v.jsx(pi,{className:"h-4 w-32"})]}),v.jsx(pi,{className:"h-10 w-24 rounded-xl"})]}),v.jsx(pi,{className:"h-12 w-full rounded-xl"}),v.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6",children:[...Array(6)].map((b,C)=>v.jsxs("div",{className:"card p-5 space-y-4",children:[v.jsx(pi,{className:"h-5 w-2/3"}),v.jsx(pi,{className:"h-3 w-full"}),v.jsxs("div",{className:"flex gap-2 pt-2",children:[v.jsx(pi,{className:"h-6 w-16"}),v.jsx(pi,{className:"h-6 w-16"})]})]},C))})]})]})]}):w?v.jsx(DS,{onSetup:A}):s?v.jsx(yw,{children:v.jsxs(Jm,{children:[v.jsx(an,{path:"/popout/:projectId/:groupId",element:v.jsx(n2,{sendMessage:g,subscribeBinary:l,onEvent:d})}),v.jsx(an,{path:"*",element:v.jsxs(v.Fragment,{children:[v.jsx(Lx,{onLogout:O,authRequired:h,connected:u,onEvent:d,children:v.jsx(j.Suspense,{fallback:null,children:v.jsxs(Jm,{children:[v.jsx(an,{path:"/",element:v.jsx(r2,{onEvent:d})}),v.jsx(an,{path:"/review",element:v.jsx(l2,{onEvent:d})}),v.jsx(an,{path:"/agenda",element:v.jsx(c2,{})}),v.jsx(an,{path:"/projects/:id",element:v.jsx(o2,{onEvent:d,connected:u,sendMessage:g,subscribeBinary:l})}),v.jsx(an,{path:"/projects/:id/discussions/:discussionId",element:v.jsx(a2,{onEvent:d,connected:u})})]})})}),v.jsx(Yx,{onEvent:d})]})})]})}):v.jsx(RS,{onLogin:M,onChangePassword:r})}function h2(s){return bt(`/api/harness/${s}`)}function Kg(s,h){return bt(`/api/harness/${s}/${h}`)}function d2(s,h,w){return Di(`/api/harness/${s}/${h}/settings`,w)}function f2(s,h,w){return Di(`/api/harness/${s}/${h}/memory`,{content:w})}function p2(s,h,w){return Di(`/api/harness/${s}/${h}/local-memory`,{content:w})}function m2(s,h,w){return Di(`/api/harness/${s}/${h}/hooks`,{hooks:w})}function g2(s,h,w,S,M){return nt(`/api/harness/${s}/${h}/hooks/toggle`,{event:w,index:S,enabled:M})}function v2(s,h,w,S){return nt(`/api/harness/${s}/${h}/skills/${encodeURIComponent(w)}/toggle`,{enabled:S})}function _2(s,h,w,S){return Di(`/api/harness/${s}/${h}/skills/${encodeURIComponent(w)}`,{content:S})}function b2(s,h){return nt(`/api/harness/${s}/${h}/port-from-claude`)}function y2(s,h,w){return Di(`/api/harness/${s}/${h}/mcp/${encodeURIComponent(w.alias)}`,w)}function w2(s,h,w){return Cr(`/api/harness/${s}/${h}/mcp/${encodeURIComponent(w)}`)}const S2={claude:["ask","accept","auto","bypassPermissions"],antigravity:["default","auto","all"],codex:["untrusted","on-request","on-failure","never"]},x2={claude:[],antigravity:["true","false","docker","podman"],codex:["read-only","workspace-write","danger-full-access"]};function C2({cli:s,settings:h,saving:w,onSave:S}){const{t:M}=Tt(),[O,A]=j.useState(h.model??""),[r,u]=j.useState(h.approvalMode??""),[d,g]=j.useState(h.sandbox??"");j.useEffect(()=>{A(h.model??""),u(h.approvalMode??""),g(h.sandbox??"")},[h.model,h.approvalMode,h.sandbox]);const l=(h.model??"")!==O||(h.approvalMode??"")!==r||(h.sandbox??"")!==d,m=async C=>{if(C.preventDefault(),!l||w)return;const p={};(h.model??"")!==O&&(p.model=O||void 0),(h.approvalMode??"")!==r&&(p.approvalMode=r||void 0),(h.sandbox??"")!==d&&(p.sandbox=d||void 0),await S(p)},b=x2[s];return v.jsxs("form",{onSubmit:m,className:"space-y-3 p-4 border border-warm-200 rounded-xl",children:[v.jsx("h4",{className:"text-sm font-semibold text-warm-700",children:M("harness.section.settings")}),v.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-3",children:[v.jsxs("div",{children:[v.jsx("label",{className:"text-xs text-warm-500 block mb-1",children:M("harness.field.model")}),v.jsx("input",{type:"text",value:O,onChange:C=>A(C.target.value),placeholder:M(`harness.field.modelPlaceholder.${s}`),className:"w-full px-3 py-1.5 text-xs border border-warm-200 rounded-lg bg-warm-50 text-warm-700 focus:ring-1 focus:ring-accent focus:border-accent"})]}),v.jsxs("div",{children:[v.jsx("label",{className:"text-xs text-warm-500 block mb-1",children:M("harness.field.approvalMode")}),v.jsxs("select",{value:r,onChange:C=>u(C.target.value),className:"w-full px-3 py-1.5 text-xs border border-warm-200 rounded-lg bg-warm-50 text-warm-700 focus:ring-1 focus:ring-accent focus:border-accent",children:[v.jsx("option",{value:"",children:M("harness.field.unset")}),S2[s].map(C=>v.jsx("option",{value:C,children:C},C))]})]}),b.length>0&&v.jsxs("div",{children:[v.jsx("label",{className:"text-xs text-warm-500 block mb-1",children:M("harness.field.sandbox")}),v.jsxs("select",{value:d,onChange:C=>g(C.target.value),className:"w-full px-3 py-1.5 text-xs border border-warm-200 rounded-lg bg-warm-50 text-warm-700 focus:ring-1 focus:ring-accent focus:border-accent",children:[v.jsx("option",{value:"",children:M("harness.field.unset")}),b.map(C=>v.jsx("option",{value:C,children:C},C))]})]})]}),v.jsxs("div",{className:"flex items-center gap-3",children:[v.jsx(Li,{type:"submit",variant:"primary",size:"sm",disabled:!l||w,children:M(w?"harness.saving":"harness.save")}),!l&&v.jsx("span",{className:"text-xs text-warm-400",children:M("harness.noChanges")})]})]})}function Xg(s,h){if(!h)return[];const w=[],S=s.toLowerCase(),M=h.toLowerCase();let O=S.indexOf(M);for(;O!==-1;)w.push(O),O=S.indexOf(M,O+M.length);return w}function Vg({filePath:s,content:h,saving:w,onSave:S}){const{t:M}=Tt(),[O,A]=j.useState(h),[r,u]=j.useState(!1),[d,g]=j.useState(!1),[l,m]=j.useState(""),[b,C]=j.useState(0),[p,o]=j.useState(null),c=j.useRef(null),a=j.useRef(null),f=j.useRef(null);j.useEffect(()=>{A(h)},[h]);const y=O!==h,R=s.split(/[\\/]/).pop()||s,k=j.useMemo(()=>Xg(O,l),[O,l]),D=k.length?Math.min(b,k.length-1):0,E=(U,T)=>{const F=c.current;if(!F)return;F.setSelectionRange(U,U+T);const B=parseFloat(getComputedStyle(F).lineHeight)||16,W=O.slice(0,U).split(`
422
+ ${de}`:""}`,children:[v.jsx("span",{"aria-label":ge!=="unknown"?ge:(B==null?void 0:B.status)||"unknown",className:ge==="working"?"workspace-dot-pulse":void 0,style:{width:6,height:6,borderRadius:"50%",background:xe,flexShrink:0}}),v.jsx("span",{"aria-hidden":!0,style:{flexShrink:0,fontFamily:_t,fontSize:11,fontWeight:700,letterSpacing:-.5,lineHeight:1,color:Z,width:16,textAlign:"center"},children:">_"}),v.jsx("span",{style:{overflow:"hidden",textOverflow:"ellipsis",flex:1,color:J?xe:void 0,fontWeight:J?600:void 0},children:(B==null?void 0:B.title)||T}),v.jsx("button",{"data-no-drag":!0,onMouseDown:oe=>oe.stopPropagation(),onClick:oe=>{oe.stopPropagation(),r(T)},"aria-label":"close-tab",title:a("group.closeTab")||"Close tab",style:{background:"transparent",border:"none",color:Ce.titleText,cursor:"pointer",padding:1,display:"flex",alignItems:"center",justifyContent:"center",borderRadius:3,flexShrink:0},children:v.jsx(Ri,{size:12})})]},T)}),E&&v.jsx("button",{"data-no-drag":!0,onMouseDown:T=>T.stopPropagation(),onClick:()=>{E.createRawShellTab(w,h).catch(()=>{})},"aria-label":"new-tab",title:`${a("group.newTab")||"New shell tab"} (Ctrl+T)`,style:{background:"transparent",border:"none",borderRight:`1px solid ${Ce.separator}`,color:Ce.titleText,cursor:"pointer",padding:"0 8px",display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0,height:"100%"},children:v.jsx(Mn,{size:14})}),v.jsx("div",{style:{flex:1,minWidth:8}}),K&&v.jsx("span",{title:K,style:{maxWidth:260,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:Ce.dim,fontFamily:_t,fontSize:9,padding:"0 7px",flexShrink:1},children:K}),v.jsx(BC,{sessionId:s.activeTab,sendMessage:l}),v.jsx("button",{"data-no-drag":!0,onMouseDown:T=>T.stopPropagation(),onClick:D,"aria-label":"refresh-terminal",title:`${a("session.refresh")||"Refresh rendering"} (F5 · Ctrl+Shift+R) — ${a("session.refresh.hint")||"Rebuild the terminal view (PTY stays running)"}`,style:Zi,children:v.jsx(aS,{size:12})}),v.jsx("button",{"data-no-drag":!0,onMouseDown:T=>T.stopPropagation(),onClick:()=>y(-1),"aria-label":"decrease-font",title:`${a("session.fontDecrease")||"Decrease font size"} (${f}px) · Ctrl+- · Ctrl+wheel`,style:Zi,children:v.jsx(LS,{size:14})}),v.jsx("button",{"data-no-drag":!0,onMouseDown:T=>T.stopPropagation(),onClick:()=>y(1),"aria-label":"increase-font",title:`${a("session.fontIncrease")||"Increase font size"} (${f}px) · Ctrl+= · Ctrl+wheel`,style:Zi,children:v.jsx(kS,{size:14})}),v.jsx(jC,{sessionId:s.activeTab}),c&&v.jsxs(v.Fragment,{children:[s.tabs.length>1&&c.onApplyLayoutPreset&&v.jsxs(v.Fragment,{children:[v.jsx("button",{"data-no-drag":!0,onMouseDown:T=>T.stopPropagation(),onClick:()=>{var T;return(T=c.onApplyLayoutPreset)==null?void 0:T.call(c,"single")},"aria-label":"single-pane",title:a("session.layout.single"),style:Zi,children:v.jsx(jv,{size:12})}),v.jsx("button",{"data-no-drag":!0,onMouseDown:T=>T.stopPropagation(),onClick:()=>{var T;return(T=c.onApplyLayoutPreset)==null?void 0:T.call(c,"columns")},"aria-label":"two-columns",title:a("session.layout.columns"),style:Zi,children:v.jsx(Lv,{size:14})}),v.jsx("button",{"data-no-drag":!0,onMouseDown:T=>T.stopPropagation(),onClick:()=>{var T;return(T=c.onApplyLayoutPreset)==null?void 0:T.call(c,"grid")},"aria-label":"grid-layout",title:a("session.layout.grid"),style:Zi,children:v.jsx(Tv,{size:14})})]}),c.onToggleMaximize&&v.jsx("button",{"data-no-drag":!0,onMouseDown:T=>T.stopPropagation(),onClick:c.onToggleMaximize,"aria-label":"toggle-maximize",title:`${c.isMaximized?a("session.restoreSize"):a("session.maximize")} · ${a("session.maximizeHint")}`,style:Zi,children:c.isMaximized?v.jsx(Th,{size:14}):v.jsx(El,{size:14})}),c.onPopOutGroup&&v.jsx("button",{"data-no-drag":!0,onMouseDown:T=>T.stopPropagation(),onClick:c.onPopOutGroup,"aria-label":"pop-out",title:`${a("session.popOut")||"Pop out to separate window"} (Ctrl+Shift+O)`,style:Zi,children:v.jsx(_r,{size:14})}),c.onReDockGroup&&v.jsx("button",{"data-no-drag":!0,onMouseDown:T=>T.stopPropagation(),onClick:c.onReDockGroup,"aria-label":"redock",title:a("session.popout.redock")||"Re-dock to main window",style:Zi,children:v.jsx(_r,{size:14,style:{transform:"scaleX(-1)"}})}),c.onMinimizeGroup&&v.jsx("button",{"data-no-drag":!0,onMouseDown:T=>T.stopPropagation(),onClick:c.onMinimizeGroup,"aria-label":"minimize",title:`${a("session.minimize")||"Minimize"} (Ctrl+Shift+M)`,style:Zi,children:v.jsx(Mh,{size:14})}),v.jsx("button",{"data-no-drag":!0,onMouseDown:T=>T.stopPropagation(),onClick:c.onCloseGroup,"aria-label":"close",title:`${a("session.close")||"Close"} (Ctrl+Shift+X)`,style:Zi,children:v.jsx(Ri,{size:14})})]})]}),v.jsx("div",{"data-group-id":w,"data-stack-path":h.join("."),ref:T=>{if(!T){g(h,null);return}const F=T.getBoundingClientRect();g(h,{x:F.left,y:F.top,w:F.width,h:F.height})},onMouseDown:X,style:{flex:1,position:"relative",minHeight:0,minWidth:0},children:s.tabs.map(T=>{const F=S.get(T);if(!F)return null;const B=O[T]||{intent:"open",nonce:0};return v.jsx(__,{session:F,visible:T===s.activeTab,intent:B.intent,intentNonce:B.nonce,onClose:()=>d(T),sendMessage:l,subscribeBinary:m,onEvent:b,onCycleTab:Y,onSelectTab:$,remountKey:R[T]||0},T)})})]})}const Zi={background:"transparent",border:"none",color:Ce.titleText,cursor:"pointer",padding:"0 6px",display:"flex",alignItems:"center",justifyContent:"center",borderRadius:0,flexShrink:0,height:"100%"},Yg=28;function n2({sendMessage:s,subscribeBinary:h,onEvent:w}){var je;const{projectId:S="",groupId:M=""}=By(),[O]=kw(),A=O.get("wid")||"",{t:r}=Tt(),{confirm:u}=kr(),[d,g]=j.useState(null),[l,m]=j.useState([]),[b,C]=j.useState(null),[p,o]=j.useState(null),[c,a]=j.useState(0),f=j.useRef(0),y=j.useRef(0),R=j.useRef(0);j.useEffect(()=>{const ee=()=>{const Me=f.current;!Me||R.current===Me||Math.abs(y.current-Me)<=400&&(R.current=Me,a(Ge=>Ge+1))},be=()=>{f.current=Date.now(),D(!0),ee()},he=()=>D(!1),He=()=>{y.current=Date.now(),ee()};return window.addEventListener("focus",be),window.addEventListener("blur",he),window.addEventListener("pointerdown",He,!0),()=>{window.removeEventListener("focus",be),window.removeEventListener("blur",he),window.removeEventListener("pointerdown",He,!0)}},[]);const[k,D]=j.useState(()=>typeof document<"u"&&document.hasFocus()),{sendNotification:E}=Ll(),L=j.useRef(null);L.current=d;const z=j.useRef(null),H=j.useRef(!1);j.useEffect(()=>{if(!S)return;let ue=!1;return tC(S).then(ee=>{ue||m(ee)}).catch(ee=>{ue||C(String((ee==null?void 0:ee.message)||ee))}),()=>{ue=!0}},[S]);const P=j.useRef(new Set);j.useEffect(()=>{if(!d||l.length===0)return;const ue=new Set(l.map(ee=>ee.id));for(const ee of Ft(d.root))ue.has(ee)||P.current.has(ee)||(P.current.add(ee),l_(ee).then(be=>m(he=>he.some(He=>He.id===be.id)?he:[...he,be])).catch(()=>{}))},[d,l]),j.useEffect(()=>w(ee=>{ee.type==="session:status-changed"&&ee.sessionId&&m(be=>be.map(he=>{if(he.id!==ee.sessionId)return he;const He={status:ee.status,updated_at:new Date().toISOString()};return ee.worktree_path!==void 0&&(He.worktree_path=ee.worktree_path),ee.branch_name!==void 0&&(He.branch_name=ee.branch_name),{...he,...He}}))}),[w]),j.useEffect(()=>{if(!S||!M||!A)return;const ue=Bh();z.current=ue;const ee=ue.subscribe(Me=>{if(Me.t==="dock-probe"||Me.t==="dock-probe-result"||Me.t==="dock-end"||Me.t==="dock-commit"||Me.t==="dock-commit-ack"){ye.current(Me);return}if(Me.t==="group-handoff"&&Me.to===A&&Me.groupId===M){const Ge=Me.group;g({...Ge,x:0,y:0,w:window.innerWidth,h:Math.max(0,window.innerHeight-(Ge.root.kind==="split"?Yg:0)),minimized:!1,ownerWindowId:A})}else if(Me.t==="group-recall"&&Me.popoutId===A&&Me.groupId===M){const Ge=L.current;Ge&&ue.post({t:"group-return",from:A,groupId:Ge.id,group:Ge,projectId:S}),setTimeout(()=>{try{window.close()}catch{}},50)}else if(Me.t==="group-focus"&&Me.popoutId===A&&Me.groupId===M){const Ge=window.electronAPI;if(Ge!=null&&Ge.windowFocus)Ge.windowFocus();else try{window.focus()}catch{}}else Me.t==="group-reclaimed"&&Me.popoutId===A&&(g(null),o(r("session.popout.reclaimed")||"메인 윈도우가 이 터미널을 회수했습니다. 잠시 후 창이 닫힙니다."),setTimeout(()=>{try{window.close()}catch{}},1500))});ue.post({t:"hello",from:A,groupId:M});const be=zx(A),he=setInterval(()=>{const Me=L.current;ue.post({t:"heartbeat",from:A,ownedGroupIds:Me?[Me.id]:[M]})},Nh),He=()=>{const Me=L.current;Me&&!H.current&&ue.post({t:"group-return",from:A,groupId:Me.id,group:Me,projectId:S}),ue.post({t:"bye",from:A})};return window.addEventListener("beforeunload",He),()=>{clearInterval(he),be(),window.removeEventListener("beforeunload",He),ee(),ue.close(),z.current=null}},[S,M,A]);const I=j.useCallback(ue=>{!z.current||!L.current||z.current.post({t:"group-update",from:A,groupId:L.current.id,patch:ue,projectId:S})},[A,S]),K=j.useCallback(ue=>{g(ee=>{if(!ee)return ee;const be={...ee,root:Ki(ee.root,ue)};return I({root:be.root}),be})},[I]),X=j.useCallback(ue=>{g(ee=>{var se;if(!ee)return ee;const be=Dn(ee.root,ue);if(!be)return H.current=!0,(se=z.current)==null||se.post({t:"group-close",from:A,groupId:ee.id,projectId:S}),setTimeout(()=>window.close(),50),null;const he=new Set(Ft(be)),He={};for(const V of Object.keys(ee.colors))he.has(V)&&(He[V]=ee.colors[V]);const Me={};for(const V of Object.keys(ee.intents))he.has(V)&&(Me[V]=ee.intents[V]);const Ge={...ee,root:be,colors:He,intents:Me};return I({root:Ge.root,colors:Ge.colors,intents:Ge.intents}),Ge})},[I,A]),Y=j.useCallback(async ue=>{const ee=l.find(be=>be.id===ue);if((ee==null?void 0:ee.status)==="running"){if(!await u({message:r("session.confirmStop"),danger:!0}))return;gh(ue).catch(()=>{})}X(ue)},[l,r,X,u]),[$,U]=j.useState(null),T=j.useRef(null);T.current=$;const F=j.useRef(new Map),B=j.useRef(null),W=j.useRef(0),Z=j.useMemo(()=>({begin(){F.current.clear(),W.current=0},probe(ue){var ee;Date.now()-W.current<33||(W.current=Date.now(),(ee=z.current)==null||ee.post({t:"dock-probe",from:A,x:ue.screenX,y:ue.screenY}))},best(){const ue=Date.now();let ee=null;for(const[be,he]of F.current)!he.hit||ue-he.at>500||(!ee||he.focusAt>ee.focusAt)&&(ee={id:be,focusAt:he.focusAt,rect:he.rect,zone:he.zone});return ee},commit(ue,ee,be,he){var Me;const He=`${A}_${Date.now().toString(36)}_${Math.random().toString(36).slice(2,6)}`;B.current&&clearTimeout(B.current.timer),B.current={to:ue,commitId:He,ids:be.map(Ge=>Ge.id),timer:setTimeout(()=>{B.current=null},600)},(Me=z.current)==null||Me.post({t:"dock-commit",from:A,to:ue,x:ee.screenX,y:ee.screenY,commitId:He,sessions:be,activeId:he})},end(){var ue;F.current.clear(),(ue=z.current)==null||ue.post({t:"dock-end",from:A})}}),[A]),[ne,ge]=j.useState(null),xe=j.useRef(ne);xe.current=ne;const J=j.useRef(null),G=j.useRef(typeof document<"u"&&document.hasFocus()?Date.now():0);j.useEffect(()=>{const ue=()=>{G.current=Date.now()};window.addEventListener("focus",ue);const ee=e_();return()=>{window.removeEventListener("focus",ue),ee(),J.current&&clearTimeout(J.current)}},[]);const de=6,oe=j.useCallback((ue,ee,be)=>{if(be.button!==0||!L.current)return;be.preventDefault();const he=be.clientX,He=be.clientY;let Me=!1;Z.begin();const Ge=_e=>{if(!Me){if(Math.hypot(_e.clientX-he,_e.clientY-He)<de)return;Me=!0}if(!(_e.clientX>=0&&_e.clientY>=0&&_e.clientX<=window.innerWidth&&_e.clientY<=window.innerHeight)){U({sessionId:ue,fromPath:ee,hoveredPath:null,hoveredRect:null,zone:null}),Z.probe(_e);return}let Pe=null,Ue=null,ot=null;const Ye=document.elementsFromPoint(_e.clientX,_e.clientY);for(const ut of Ye){const ft=ut.closest("[data-group-id][data-stack-path]");if(!ft)continue;const kt=ft.dataset.stackPath||"",vt=kt===""?[]:kt.split(".").map(Number),Vt=kt===ee.join(".");if(Vt){const Ze=L.current,fe=Ze?cn(Ze.root,ee):null;if(!fe||fe.kind!=="stack"||fe.tabs.length<2)break}const Nt=ft.getBoundingClientRect();Pe=vt,Ue={x:Nt.left,y:Nt.top,w:Nt.width,h:Nt.height},ot=Dl(_e.clientX,_e.clientY,Ue),Vt&&ot==="center"&&(ot=null);break}U({sessionId:ue,fromPath:ee,hoveredPath:Pe,hoveredRect:Ue,zone:ot})};let se=!1;const V=()=>{se||(se=!0,window.removeEventListener("mousemove",Ge),window.removeEventListener("mouseup",ce),window.removeEventListener("blur",ie),window.removeEventListener("keydown",Q),document.removeEventListener("visibilitychange",ke))},ie=()=>{V(),U(null),Z.end()},Q=_e=>{_e.key==="Escape"&&ie()},ke=()=>{document.hidden&&ie()},ce=_e=>{V();const Ee=T.current;U(null);const Pe=Z.best();if(Z.end(),!Ee)return;if(Ee.hoveredPath&&Ee.zone){const ot=L.current;if(!ot)return;const Ye=Rx(ot.root,Ee.sessionId,Ee.hoveredPath,Ee.zone);if(!Ye)return;g({...ot,root:Ye}),I({root:Ye});return}if(!Pe)return;const Ue=L.current;Z.commit(Pe.id,_e,[{id:Ee.sessionId,color:Ue==null?void 0:Ue.colors[Ee.sessionId],intentInfo:Ue==null?void 0:Ue.intents[Ee.sessionId]}],Ee.sessionId)};window.addEventListener("mousemove",Ge),window.addEventListener("mouseup",ce),window.addEventListener("blur",ie),window.addEventListener("keydown",Q),document.addEventListener("visibilitychange",ke)},[I,Z]),[Ae,Oe]=j.useState(null),Xe=j.useCallback(ue=>{var ot;if(ue.button!==0||ue.target.closest("[data-no-drag]"))return;const ee=L.current;if(!ee||ee.root.kind!=="stack")return;ue.preventDefault();const be=ue.screenX,he=ue.screenY,He=window.screenX,Me=window.screenY,Ge=window.electronAPI;(ot=Ge==null?void 0:Ge.windowMoveStart)==null||ot.call(Ge),Z.begin();let se=!1,V=null,ie=0;const Q=()=>{if(ie=0,!!V)if(Ge!=null&&Ge.windowMoveBy)Ge.windowMoveBy(V.dx,V.dy);else try{window.moveTo(He+V.dx,Me+V.dy)}catch{}},ke=Ye=>{const ut=Ye.screenX-be,ft=Ye.screenY-he;if(!se){if(Math.hypot(ut,ft)<de)return;se=!0}V={dx:ut,dy:ft},ie||(ie=requestAnimationFrame(Q)),Z.probe(Ye);const kt=Z.best();if(kt!=null&&kt.rect){const vt=An();Oe({rect:{x:Ye.clientX+(kt.rect.x-Ye.screenX)/vt,y:Ye.clientY+(kt.rect.y-Ye.screenY)/vt,w:kt.rect.w/vt,h:kt.rect.h/vt},zone:kt.zone??null})}else Oe(null)};let ce=!1;const _e=()=>{ce||(ce=!0,window.removeEventListener("mousemove",ke),window.removeEventListener("mouseup",Ue),window.removeEventListener("blur",_e),window.removeEventListener("keydown",Ee),document.removeEventListener("visibilitychange",Pe),ie&&cancelAnimationFrame(ie),Oe(null),Z.end())},Ee=Ye=>{Ye.key==="Escape"&&_e()},Pe=()=>{document.hidden&&_e()},Ue=Ye=>{const ut=Z.best();if(_e(),!se||!(ut!=null&&ut.zone))return;const ft=L.current;!ft||ft.root.kind!=="stack"||Z.commit(ut.id,Ye,ft.root.tabs.map(kt=>({id:kt,color:ft.colors[kt],intentInfo:ft.intents[kt]})),ft.root.activeTab)};window.addEventListener("mousemove",ke),window.addEventListener("mouseup",Ue),window.addEventListener("blur",_e),window.addEventListener("keydown",Ee),document.addEventListener("visibilitychange",Pe)},[Z]),We=j.useCallback(ue=>{g(ee=>{if(!ee)return ee;const be={...ee,root:Yv(ee.root,ue)};return I({root:be.root}),be})},[I]),rt=ue=>{var be;const ee=z.current;if(ee){if(ue.t==="dock-probe"&&ue.from!==A){if(document.visibilityState!=="visible"||!L.current)return;const he=vl(ue.x,ue.y),He=_l(he)?bl(he.x,he.y):null;if(He&&He.groupId===L.current.id){const Me=xe.current;(!Me||Me.zone!==He.zone||Me.path.join(".")!==He.path.join("."))&&ge({rect:He.rect,zone:He.zone,path:He.path}),J.current&&clearTimeout(J.current),J.current=setTimeout(()=>ge(null),800);const Ge=An();ee.post({t:"dock-probe-result",from:A,to:ue.from,hit:!0,focusAt:G.current,rect:{...i_(He.rect.x,He.rect.y),w:He.rect.w*Ge,h:He.rect.h*Ge},zone:He.zone})}else xe.current&&ge(null),ee.post({t:"dock-probe-result",from:A,to:ue.from,hit:!1,focusAt:G.current})}else if(ue.t==="dock-probe-result"&&ue.to===A)F.current.set(ue.from,{hit:ue.hit,focusAt:ue.focusAt,at:Date.now(),rect:ue.rect,zone:ue.zone});else if(ue.t==="dock-end"&&ue.from!==A)ge(null);else if(ue.t==="dock-commit"&&ue.to===A){const he=L.current;let He=!1;const Me=ue.sessions.map(Ge=>Ge.id);if(he&&!Me.some(Ge=>Ft(he.root).includes(Ge))){const Ge=vl(ue.x,ue.y),se=_l(Ge)?bl(Ge.x,Ge.y):null,V=se&&se.groupId===he.id&&se.zone?{path:se.path,zone:se.zone}:(be=xe.current)!=null&&be.zone?{path:xe.current.path,zone:xe.current.zone}:null;if(V){const ie=Xv(he.root,V.path,V.zone,Me,ue.activeId),Q={...he.colors},ke={...he.intents};for(const ce of ue.sessions)Q[ce.id]||(Q[ce.id]=ce.color||Ln(Object.values(Q))),ke[ce.id]=ce.intentInfo??{intent:"open",nonce:0};g({...he,root:ie,colors:Q,intents:ke}),I({root:ie,colors:Q,intents:ke}),He=!0}}ge(null),ee.post({t:"dock-commit-ack",from:A,to:ue.from,commitId:ue.commitId,accepted:He})}else if(ue.t==="dock-commit-ack"&&ue.to===A){const he=B.current;if(he&&he.commitId===ue.commitId&&he.to===ue.from&&(clearTimeout(he.timer),B.current=null,ue.accepted))for(const He of he.ids)X(He)}}},ye=j.useRef(rt);ye.current=rt;const Te=j.useCallback(ue=>{Y(ue)},[Y]),ct=j.useCallback((ue,ee)=>{g(be=>{if(!be)return be;const he={...be,root:Jv(be.root,ue,ee)};return I({root:he.root}),he})},[I]),it=window.electronAPI,ze=!!(it!=null&&it.windowMinimize),qe=j.useCallback(()=>{var ue;(ue=it==null?void 0:it.windowMinimize)==null||ue.call(it)},[it]),Fe=j.useCallback(()=>{const ue=L.current;if(!ue||!z.current){window.close();return}z.current.post({t:"group-return",from:A,groupId:ue.id,group:ue,projectId:S}),setTimeout(()=>window.close(),50)},[A,S]),Be=j.useCallback(async()=>{const ue=L.current;if(!ue||!z.current){window.close();return}const be=Ft(ue.root).filter(he=>{var He;return((He=l.find(Me=>Me.id===he))==null?void 0:He.status)==="running"});be.length&&!await u({message:r("session.confirmStop"),danger:!0})||(be.forEach(he=>gh(he).catch(()=>{})),H.current=!0,z.current.post({t:"group-close",from:A,groupId:ue.id,projectId:S}),setTimeout(()=>window.close(),50))},[l,r,A,S,u]),$e=j.useMemo(()=>{const ue=new Map;for(const ee of l)ue.set(ee.id,ee);return ue},[l]),lt=k&&d?wr(d.root).join(","):"",st=j.useMemo(()=>new Set(lt?lt.split(","):[]),[lt]),St=Ph(w,st,(ue,ee)=>{var he;const be=L.current;!be||!Ft(be.root).includes(ue)||E(r(ee==="blocked"?"notification.sessionBlocked":"notification.sessionDone"),((he=$e.get(ue))==null?void 0:he.title)||ue,()=>K(ue))});if(b)return v.jsxs("div",{style:sh,children:[v.jsx("p",{children:r("session.popout.loadFailed")||"Failed to load popout window."}),v.jsx("p",{style:{fontSize:12,opacity:.7},children:b})]});if(!d)return p?v.jsx("div",{style:sh,children:v.jsx("p",{children:p})}):v.jsxs("div",{style:sh,children:[v.jsx("p",{children:r("session.popout.waiting")||"Waiting for main window…"}),v.jsx("p",{style:{fontSize:12,opacity:.7},children:r("session.popout.waitingHint")||"If the main app is not open, this window cannot start. Open the project in the main app and try Pop Out again."})]});const Se=Ft(d.root),Ie=Se.length>0?((je=$e.get(Se[0]))==null?void 0:je.title)||Se[0]:"",le=Se.length===1?Ie:`${Ie} +${Se.length-1}`,Ne=d.root.kind==="split";return v.jsxs("div",{style:{position:"fixed",inset:0,background:Ce.bg,display:"flex",flexDirection:"column"},children:[c>0&&v.jsx("div",{className:"popout-focus-flash","aria-hidden":!0},c),Ne&&v.jsxs("div",{style:{height:Yg,background:Ce.titleBg,borderBottom:`1px solid ${Ce.separator}`,display:"flex",alignItems:"center",padding:"0 4px 0 10px",color:Ce.titleText,fontFamily:_t,fontSize:11,flexShrink:0,userSelect:"none",WebkitAppRegion:"drag"},children:[v.jsx("span",{style:{color:Ce.info,fontWeight:600,letterSpacing:1,marginRight:8},"aria-hidden":!0,children:">_"}),v.jsx("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:le}),ze&&v.jsx("button",{onClick:qe,style:nh,"aria-label":"minimize-popout",title:r("session.popout.minimize")||"Minimize",children:v.jsx(Mh,{size:14})}),v.jsxs("button",{onClick:Fe,style:nh,"aria-label":"redock",title:r("session.popout.redock")||"Re-dock to main window",children:[v.jsx(_r,{size:14,style:{transform:"scaleX(-1)"}}),v.jsx("span",{style:{marginLeft:4},children:r("session.popout.redockShort")||"Re-dock"})]}),v.jsx("button",{onClick:Be,style:nh,"aria-label":"close-popout",title:r("session.popout.closeWindow")||"Close window",children:v.jsx(Ri,{size:14})})]}),v.jsx("div",{onMouseDown:Ne?void 0:Xe,style:{flex:1,display:"flex",minHeight:0,minWidth:0},children:v.jsx(Hh.Provider,{value:St,children:d.root.kind==="split"?v.jsx(Fh,{node:d.root,path:[],groupId:d.id,sessionsById:$e,colors:d.colors,intents:d.intents,onTabClick:K,onTabClose:Y,onTabMouseDown:oe,onPaneAutoClose:Te,registerRect:()=>{},onSplitSizes:ct,sendMessage:s,subscribeBinary:h,onEvent:w}):v.jsx(Wh,{stack:d.root,path:[],groupId:d.id,sessionsById:$e,colors:d.colors,intents:d.intents,onTabClick:K,onTabClose:Y,onTabMouseDown:oe,onPaneAutoClose:Te,registerRect:()=>{},sendMessage:s,subscribeBinary:h,onEvent:w,groupActions:{onMinimizeGroup:ze?qe:void 0,onReDockGroup:Fe,onCloseGroup:Be,onApplyLayoutPreset:We}})})}),$&&$.hoveredRect&&v.jsx(vr,{targetRect:$.hoveredRect,activeZone:$.zone}),Ae&&v.jsx(vr,{targetRect:Ae.rect,activeZone:Ae.zone}),ne&&v.jsx(vr,{targetRect:ne.rect,activeZone:ne.zone})]})}const sh={position:"fixed",inset:0,background:Ce.bg,color:Ce.titleText,fontFamily:_t,fontSize:12,display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",gap:8,padding:24,textAlign:"center"},nh={background:"transparent",border:"none",color:Ce.titleText,cursor:"pointer",padding:"4px 8px",display:"flex",alignItems:"center",justifyContent:"center",borderRadius:4,fontFamily:_t,fontSize:11,WebkitAppRegion:"no-drag"},r2=j.lazy(()=>Oo(()=>import("./ProjectList-LeZ7mrEM.js"),__vite__mapDeps([0,1]))),o2=j.lazy(()=>Oo(()=>import("./ProjectDetail-DwN6S3uf.js").then(s=>s.l),__vite__mapDeps([2,3,4,5,6,7,1]))),a2=j.lazy(()=>Oo(()=>import("./DiscussionDetail-DetjETsr.js"),__vite__mapDeps([8,6,5,7]))),l2=j.lazy(()=>Oo(()=>import("./ReviewQueue-DzTHqZdO.js"),__vite__mapDeps([9,4,5,10]))),c2=j.lazy(()=>Oo(()=>import("./PersonalAgenda-JNpWPEDQ.js"),__vite__mapDeps([11,3,7,10])));function u2(){const{authenticated:s,authRequired:h,setupRequired:w,loading:S,login:M,logout:O,setup:A,changePassword:r}=jw(),{connected:u,onEvent:d,sendMessage:g,subscribeBinary:l}=Bw(s),{t:m}=Tt();return j.useEffect(()=>{s&&Wv().then(b=>{var C,p;hl(b.defaultFontSize),(p=(C=window.electronAPI)==null?void 0:C.imeSetDebug)==null||p.call(C,b.imeDebug)}).catch(()=>{})},[s]),j.useEffect(()=>{const b=window.electronAPI,C=f=>{var y;return!!f&&!((y=f.classList)!=null&&y.contains("xterm-helper-textarea"))&&(f.tagName==="INPUT"||f.tagName==="TEXTAREA"||f.isContentEditable)},p=f=>{var y;h_(()=>f.focus())&&((y=b==null?void 0:b.imeLog)==null||y.call(b,{src:"app",event:"focus-rescue",tag:f.tagName}))},o=f=>{var R;const y=f.target;if(C(y)){if(!document.hasFocus()){p(y);return}(R=b==null?void 0:b.imeReset)==null||R.call(b)}},c=f=>{if(document.hasFocus())return;const y=f.target;C(y)&&p(y)},a=()=>{if(document.hasFocus())return;const f=document.activeElement;C(f)&&p(f)};return document.addEventListener("focusin",o,!0),document.addEventListener("pointerdown",c,!0),document.addEventListener("keydown",a,!0),()=>{document.removeEventListener("focusin",o,!0),document.removeEventListener("pointerdown",c,!0),document.removeEventListener("keydown",a,!0)}},[]),S?v.jsxs("div",{className:"flex h-screen overflow-hidden",style:{backgroundColor:"var(--color-bg-primary)"},children:[v.jsxs("div",{className:"hidden md:flex flex-col w-64 border-r border-theme-border p-4 space-y-6",children:[v.jsx(pi,{className:"h-8 w-32 mb-4"}),v.jsxs("div",{className:"space-y-3",children:[v.jsx(pi,{className:"h-4 w-full"}),v.jsx(pi,{className:"h-4 w-5/6"}),v.jsx(pi,{className:"h-4 w-4/6"})]}),v.jsxs("div",{className:"mt-auto space-y-3 pt-4 border-t border-theme-border",children:[v.jsx(pi,{className:"h-4 w-1/2"}),v.jsxs("div",{className:"flex gap-2",children:[v.jsx(pi,{className:"h-8 w-8"}),v.jsx(pi,{className:"h-8 w-8"}),v.jsx(pi,{className:"h-8 w-8"})]})]})]}),v.jsxs("div",{className:"flex-1 flex flex-col overflow-hidden",children:[v.jsx("div",{className:"md:hidden h-14 border-b border-theme-border flex items-center px-4",children:v.jsx(pi,{className:"h-6 w-32"})}),v.jsxs("div",{className:"flex-1 overflow-y-auto p-6 space-y-8",children:[v.jsxs("div",{className:"flex justify-between items-center",children:[v.jsxs("div",{className:"space-y-2",children:[v.jsx(pi,{className:"h-8 w-48"}),v.jsx(pi,{className:"h-4 w-32"})]}),v.jsx(pi,{className:"h-10 w-24 rounded-xl"})]}),v.jsx(pi,{className:"h-12 w-full rounded-xl"}),v.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6",children:[...Array(6)].map((b,C)=>v.jsxs("div",{className:"card p-5 space-y-4",children:[v.jsx(pi,{className:"h-5 w-2/3"}),v.jsx(pi,{className:"h-3 w-full"}),v.jsxs("div",{className:"flex gap-2 pt-2",children:[v.jsx(pi,{className:"h-6 w-16"}),v.jsx(pi,{className:"h-6 w-16"})]})]},C))})]})]})]}):w?v.jsx(DS,{onSetup:A}):s?v.jsx(yw,{children:v.jsxs(Jm,{children:[v.jsx(an,{path:"/popout/:projectId/:groupId",element:v.jsx(n2,{sendMessage:g,subscribeBinary:l,onEvent:d})}),v.jsx(an,{path:"*",element:v.jsxs(v.Fragment,{children:[v.jsx(Lx,{onLogout:O,authRequired:h,connected:u,onEvent:d,children:v.jsx(j.Suspense,{fallback:null,children:v.jsxs(Jm,{children:[v.jsx(an,{path:"/",element:v.jsx(r2,{onEvent:d})}),v.jsx(an,{path:"/review",element:v.jsx(l2,{onEvent:d})}),v.jsx(an,{path:"/agenda",element:v.jsx(c2,{})}),v.jsx(an,{path:"/projects/:id",element:v.jsx(o2,{onEvent:d,connected:u,sendMessage:g,subscribeBinary:l})}),v.jsx(an,{path:"/projects/:id/discussions/:discussionId",element:v.jsx(a2,{onEvent:d,connected:u})})]})})}),v.jsx(Yx,{onEvent:d})]})})]})}):v.jsx(RS,{onLogin:M,onChangePassword:r})}function h2(s){return bt(`/api/harness/${s}`)}function Kg(s,h){return bt(`/api/harness/${s}/${h}`)}function d2(s,h,w){return Di(`/api/harness/${s}/${h}/settings`,w)}function f2(s,h,w){return Di(`/api/harness/${s}/${h}/memory`,{content:w})}function p2(s,h,w){return Di(`/api/harness/${s}/${h}/local-memory`,{content:w})}function m2(s,h,w){return Di(`/api/harness/${s}/${h}/hooks`,{hooks:w})}function g2(s,h,w,S,M){return nt(`/api/harness/${s}/${h}/hooks/toggle`,{event:w,index:S,enabled:M})}function v2(s,h,w,S){return nt(`/api/harness/${s}/${h}/skills/${encodeURIComponent(w)}/toggle`,{enabled:S})}function _2(s,h,w,S){return Di(`/api/harness/${s}/${h}/skills/${encodeURIComponent(w)}`,{content:S})}function b2(s,h){return nt(`/api/harness/${s}/${h}/port-from-claude`)}function y2(s,h,w){return Di(`/api/harness/${s}/${h}/mcp/${encodeURIComponent(w.alias)}`,w)}function w2(s,h,w){return Cr(`/api/harness/${s}/${h}/mcp/${encodeURIComponent(w)}`)}const S2={claude:["ask","accept","auto","bypassPermissions"],antigravity:["default","auto","all"],codex:["untrusted","on-request","on-failure","never"]},x2={claude:[],antigravity:["true","false","docker","podman"],codex:["read-only","workspace-write","danger-full-access"]};function C2({cli:s,settings:h,saving:w,onSave:S}){const{t:M}=Tt(),[O,A]=j.useState(h.model??""),[r,u]=j.useState(h.approvalMode??""),[d,g]=j.useState(h.sandbox??"");j.useEffect(()=>{A(h.model??""),u(h.approvalMode??""),g(h.sandbox??"")},[h.model,h.approvalMode,h.sandbox]);const l=(h.model??"")!==O||(h.approvalMode??"")!==r||(h.sandbox??"")!==d,m=async C=>{if(C.preventDefault(),!l||w)return;const p={};(h.model??"")!==O&&(p.model=O||void 0),(h.approvalMode??"")!==r&&(p.approvalMode=r||void 0),(h.sandbox??"")!==d&&(p.sandbox=d||void 0),await S(p)},b=x2[s];return v.jsxs("form",{onSubmit:m,className:"space-y-3 p-4 border border-warm-200 rounded-xl",children:[v.jsx("h4",{className:"text-sm font-semibold text-warm-700",children:M("harness.section.settings")}),v.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-3",children:[v.jsxs("div",{children:[v.jsx("label",{className:"text-xs text-warm-500 block mb-1",children:M("harness.field.model")}),v.jsx("input",{type:"text",value:O,onChange:C=>A(C.target.value),placeholder:M(`harness.field.modelPlaceholder.${s}`),className:"w-full px-3 py-1.5 text-xs border border-warm-200 rounded-lg bg-warm-50 text-warm-700 focus:ring-1 focus:ring-accent focus:border-accent"})]}),v.jsxs("div",{children:[v.jsx("label",{className:"text-xs text-warm-500 block mb-1",children:M("harness.field.approvalMode")}),v.jsxs("select",{value:r,onChange:C=>u(C.target.value),className:"w-full px-3 py-1.5 text-xs border border-warm-200 rounded-lg bg-warm-50 text-warm-700 focus:ring-1 focus:ring-accent focus:border-accent",children:[v.jsx("option",{value:"",children:M("harness.field.unset")}),S2[s].map(C=>v.jsx("option",{value:C,children:C},C))]})]}),b.length>0&&v.jsxs("div",{children:[v.jsx("label",{className:"text-xs text-warm-500 block mb-1",children:M("harness.field.sandbox")}),v.jsxs("select",{value:d,onChange:C=>g(C.target.value),className:"w-full px-3 py-1.5 text-xs border border-warm-200 rounded-lg bg-warm-50 text-warm-700 focus:ring-1 focus:ring-accent focus:border-accent",children:[v.jsx("option",{value:"",children:M("harness.field.unset")}),b.map(C=>v.jsx("option",{value:C,children:C},C))]})]})]}),v.jsxs("div",{className:"flex items-center gap-3",children:[v.jsx(Li,{type:"submit",variant:"primary",size:"sm",disabled:!l||w,children:M(w?"harness.saving":"harness.save")}),!l&&v.jsx("span",{className:"text-xs text-warm-400",children:M("harness.noChanges")})]})]})}function Xg(s,h){if(!h)return[];const w=[],S=s.toLowerCase(),M=h.toLowerCase();let O=S.indexOf(M);for(;O!==-1;)w.push(O),O=S.indexOf(M,O+M.length);return w}function Vg({filePath:s,content:h,saving:w,onSave:S}){const{t:M}=Tt(),[O,A]=j.useState(h),[r,u]=j.useState(!1),[d,g]=j.useState(!1),[l,m]=j.useState(""),[b,C]=j.useState(0),[p,o]=j.useState(null),c=j.useRef(null),a=j.useRef(null),f=j.useRef(null);j.useEffect(()=>{A(h)},[h]);const y=O!==h,R=s.split(/[\\/]/).pop()||s,k=j.useMemo(()=>Xg(O,l),[O,l]),D=k.length?Math.min(b,k.length-1):0,E=(U,T)=>{const F=c.current;if(!F)return;F.setSelectionRange(U,U+T);const B=parseFloat(getComputedStyle(F).lineHeight)||16,W=O.slice(0,U).split(`
423
423
  `).length-1;F.scrollTop=Math.max(0,W*B-F.clientHeight/2)},L=()=>{g(!0),requestAnimationFrame(()=>{var U;return(U=a.current)==null?void 0:U.select()})},z=()=>{var U;g(!1),(U=c.current)==null||U.focus()},H=U=>{m(U),C(0);const T=Xg(O,U);T.length&&E(T[0],U.length)},P=U=>{if(!k.length)return;const T=(D+U+k.length)%k.length;C(T),E(k[T],l.length)},I=U=>{(U.ctrlKey||U.metaKey)&&U.key.toLowerCase()==="f"&&(U.preventDefault(),L())},K=U=>{const T=c.current;T&&(U.preventDefault(),U.currentTarget.setPointerCapture(U.pointerId),f.current={startY:U.clientY,startHeight:T.getBoundingClientRect().height})},X=U=>{if(!f.current)return;const T=f.current.startHeight+(U.clientY-f.current.startY);o(Math.max(120,T))},Y=()=>{f.current=null},$=U=>{U.key==="Enter"?(U.preventDefault(),P(U.shiftKey?-1:1)):U.key==="Escape"&&(U.preventDefault(),z())};return v.jsxs("div",{className:"space-y-3 p-4 border border-warm-200 rounded-xl",onKeyDown:I,children:[v.jsxs("div",{className:"flex items-center justify-between gap-2",children:[v.jsx("h4",{className:"text-sm font-semibold text-warm-700 font-mono",children:R}),v.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[v.jsx("code",{className:"text-[10px] text-warm-400 truncate",title:s,children:s}),v.jsx("button",{type:"button",onClick:L,className:"p-1 text-warm-400 hover:text-warm-600 hover:bg-warm-100 rounded-md transition-colors flex-shrink-0",title:M("harness.find.open"),children:v.jsx(og,{size:14})}),v.jsx("button",{type:"button",onClick:()=>{u(U=>!U),o(null)},className:"p-1 text-warm-400 hover:text-warm-600 hover:bg-warm-100 rounded-md transition-colors flex-shrink-0",title:r?M("harness.memory.collapse")||"Collapse":M("harness.memory.expand")||"Expand",children:r?v.jsx(Th,{size:14}):v.jsx(El,{size:14})})]})]}),d&&v.jsxs("div",{className:"flex items-center gap-2 px-2 py-1.5 border border-warm-200 rounded-lg bg-warm-50",children:[v.jsx(og,{size:14,className:"text-warm-400 flex-shrink-0"}),v.jsx("input",{ref:a,type:"text",value:l,onChange:U=>H(U.target.value),onKeyDown:$,placeholder:M("harness.find.placeholder"),spellCheck:!1,className:"flex-1 min-w-0 text-xs bg-transparent text-warm-700 focus:outline-none"}),v.jsx("span",{className:"text-[11px] text-warm-400 tabular-nums flex-shrink-0",children:l?`${k.length?D+1:0}/${k.length}`:""}),v.jsx("button",{type:"button",onClick:()=>P(-1),disabled:!k.length,className:"p-0.5 text-warm-400 hover:text-warm-600 disabled:opacity-40 rounded-md transition-colors",title:M("harness.find.prev"),children:v.jsx(Cv,{size:14})}),v.jsx("button",{type:"button",onClick:()=>P(1),disabled:!k.length,className:"p-0.5 text-warm-400 hover:text-warm-600 disabled:opacity-40 rounded-md transition-colors",title:M("harness.find.next"),children:v.jsx(Dh,{size:14})}),v.jsx("button",{type:"button",onClick:z,className:"p-0.5 text-warm-400 hover:text-warm-600 rounded-md transition-colors",title:M("harness.find.close"),children:v.jsx(Ri,{size:14})})]}),v.jsx("textarea",{ref:c,value:O,onChange:U=>A(U.target.value),placeholder:M("harness.memory.placeholder"),spellCheck:!1,style:p!==null?{height:p}:void 0,className:`w-full px-3 py-2 text-xs font-mono leading-relaxed border border-warm-200 rounded-lg bg-warm-50 text-warm-700 focus:ring-1 focus:ring-accent focus:border-accent resize-none ${r?"h-[75vh]":"h-96"}`}),v.jsx("div",{onPointerDown:K,onPointerMove:X,onPointerUp:Y,onPointerCancel:Y,onDoubleClick:()=>o(null),className:"group flex items-center justify-center h-3 -mt-2 cursor-ns-resize touch-none select-none",title:M("harness.memory.resize"),children:v.jsx("div",{className:"w-12 h-1 rounded-full bg-warm-200 group-hover:bg-warm-400 transition-colors"})}),v.jsxs("div",{className:"flex items-center gap-3",children:[v.jsx(Li,{variant:"primary",size:"sm",onClick:()=>y&&!w&&S(O),disabled:!y||w,children:M(w?"harness.saving":"harness.save")}),!y&&v.jsx("span",{className:"text-xs text-warm-400",children:M("harness.noChanges")})]})]})}function Jg(s){return Array.isArray(s)?s.filter(h=>typeof h=="object"&&h!==null):null}function k2({hooks:s,disabledHooks:h,filePath:w,saving:S,onSave:M,onToggle:O}){const{t:A}=Tt(),[r,u]=j.useState(!1),[d,g]=j.useState(""),[l,m]=j.useState(null),b=Array.from(new Set([...Object.keys(s??{}),...Object.keys(h??{})])),C=b.length>0,p=Object.keys(h??{}).length>0,o=(a,f,y,R)=>v.jsxs("div",{className:"flex items-start gap-2 text-[11px]",children:[v.jsx("input",{type:"checkbox",checked:R,disabled:S,onChange:()=>O(a,y,!R),title:A(R?"harness.toggle.disable":"harness.toggle.enable"),className:"mt-0.5 flex-shrink-0 cursor-pointer"}),v.jsxs("div",{className:`min-w-0 flex-1${R?"":" opacity-50"}`,children:[f.matcher!==void 0&&f.matcher!==""&&v.jsx("span",{className:"inline-block px-1.5 py-0.5 mr-1.5 rounded-md bg-warm-200/60 text-warm-600 font-mono",children:f.matcher}),(f.hooks??[]).map((k,D)=>v.jsx("code",{className:"block mt-0.5 px-2 py-1 rounded-md bg-theme-card border border-warm-150 text-warm-600 font-mono whitespace-pre-wrap break-all",children:k.command??JSON.stringify(k)},D))]})]},`${R?"on":"off"}-${y}`);j.useEffect(()=>{g(JSON.stringify(s??{},null,2)),m(null)},[s]);const c=async()=>{let a;try{a=JSON.parse(d)}catch{m(A("harness.hooks.invalidJson")||"Invalid JSON");return}if(typeof a!="object"||a===null||Array.isArray(a)){m(A("harness.hooks.invalidJson")||"Invalid JSON");return}m(null);const f=a;await M(Object.keys(f).length===0?null:f),u(!1)};return v.jsxs("div",{className:"space-y-3 p-4 border border-warm-200 rounded-xl",children:[v.jsxs("div",{className:"flex items-center justify-between gap-2",children:[v.jsx("h4",{className:"text-sm font-semibold text-warm-700",children:"Hooks"}),v.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[v.jsx("code",{className:"text-[10px] text-warm-400 truncate",title:w,children:w}),!r&&v.jsxs(Li,{variant:"ghost",size:"sm",onClick:()=>u(!0),className:"flex-shrink-0",children:[v.jsx(ch,{size:12}),A("harness.hooks.editJson")||"Edit JSON"]})]})]}),r?v.jsxs(v.Fragment,{children:[v.jsx("textarea",{value:d,onChange:a=>g(a.target.value),spellCheck:!1,className:"w-full h-64 px-3 py-2 text-xs font-mono leading-relaxed border border-warm-200 rounded-lg bg-warm-50 text-warm-700 focus:ring-1 focus:ring-accent focus:border-accent resize-y"}),l&&v.jsx("p",{className:"text-xs text-status-error",children:l}),v.jsxs("div",{className:"flex items-center gap-3",children:[v.jsx(Li,{variant:"primary",size:"sm",onClick:c,disabled:S,children:A(S?"harness.saving":"harness.save")}),v.jsx(Li,{variant:"ghost",size:"sm",onClick:()=>{g(JSON.stringify(s??{},null,2)),m(null),u(!1)},children:A("harness.cancel")})]})]}):C?v.jsxs("div",{className:"space-y-2",children:[b.map(a=>{const f=s==null?void 0:s[a],y=f===void 0?[]:Jg(f),R=Jg(h==null?void 0:h[a])??[];return v.jsxs("div",{className:"p-2.5 bg-warm-50 border border-warm-150 rounded-lg",children:[v.jsx("div",{className:"text-xs font-semibold text-warm-700 font-mono mb-1.5",children:a}),v.jsxs("div",{className:"space-y-1.5",children:[y?y.map((k,D)=>o(a,k,D,!0)):v.jsx("pre",{className:"text-[11px] text-warm-500 font-mono whitespace-pre-wrap break-all",children:JSON.stringify(f,null,2)}),R.map((k,D)=>o(a,k,D,!1))]})]},a)}),p&&v.jsx("p",{className:"text-[11px] text-warm-400",children:A("harness.hooks.parkedNote")})]}):v.jsx("p",{className:"text-xs text-warm-400",children:A("harness.hooks.empty")||"No hooks configured."})]})}function E2({skills:s,saving:h,onSave:w,onToggle:S}){const{t:M}=Tt(),[O,A]=j.useState(null),[r,u]=j.useState(""),d=s??[],g=d.find(b=>b.name===O)??null,l=!!g&&r!==g.content,m=b=>{if(O===b.name){A(null);return}A(b.name),u(b.content)};return v.jsxs("div",{className:"space-y-3 p-4 border border-warm-200 rounded-xl",children:[v.jsxs("div",{className:"flex items-center justify-between",children:[v.jsx("h4",{className:"text-sm font-semibold text-warm-700",children:"Skills"}),v.jsx("code",{className:"text-[10px] text-warm-400",children:".claude/skills/"})]}),d.length===0?v.jsx("p",{className:"text-xs text-warm-400",children:M("harness.skills.empty")||"No skills found."}):v.jsx("div",{className:"space-y-1.5",children:d.map(b=>{const C=O===b.name;return v.jsxs("div",{className:"border border-warm-150 rounded-lg overflow-hidden",children:[v.jsxs("div",{className:"flex items-start gap-2 px-3 py-2 bg-warm-50 hover:bg-warm-100 transition-colors",children:[v.jsx("input",{type:"checkbox",checked:b.enabled,disabled:h,onChange:()=>S(b.name,!b.enabled),title:b.enabled?M("harness.toggle.disable"):M("harness.toggle.enable"),className:"mt-0.5 flex-shrink-0 cursor-pointer"}),v.jsxs("button",{type:"button",onClick:()=>m(b),className:`flex-1 min-w-0 flex items-start gap-2 text-left${b.enabled?"":" opacity-50"}`,children:[v.jsx("span",{className:"mt-0.5 text-warm-400 flex-shrink-0",children:C?v.jsx(Dh,{size:14}):v.jsx(n1,{size:14})}),v.jsxs("span",{className:"min-w-0",children:[v.jsxs("span",{className:"block text-xs font-semibold text-warm-700 font-mono",children:["/",b.name]}),b.description&&v.jsx("span",{className:"block text-[11px] text-warm-400 mt-0.5 line-clamp-2",children:b.description})]})]})]}),C&&v.jsxs("div",{className:"p-3 space-y-2 border-t border-warm-150",children:[v.jsx("code",{className:"block text-[10px] text-warm-400 truncate",title:b.path,children:b.path}),v.jsx("textarea",{value:r,onChange:p=>u(p.target.value),spellCheck:!1,className:"w-full h-80 px-3 py-2 text-xs font-mono leading-relaxed border border-warm-200 rounded-lg bg-warm-50 text-warm-700 focus:ring-1 focus:ring-accent focus:border-accent resize-y"}),v.jsxs("div",{className:"flex items-center gap-3",children:[v.jsx(Li,{variant:"primary",size:"sm",onClick:()=>l&&!h&&w(b.name,r),disabled:!l||h,children:M(h?"harness.saving":"harness.save")}),!l&&v.jsx("span",{className:"text-xs text-warm-400",children:M("harness.noChanges")})]})]})]},b.name)})})]})}function Qg(s){const h={};for(const w of s.split(`
424
424
  `)){const S=w.trim();if(!S)continue;const M=S.indexOf("=");if(M<0)continue;const O=S.slice(0,M).trim(),A=S.slice(M+1).trim();O&&(h[O]=A)}return h}function Zg(s){return s?Object.entries(s).map(([h,w])=>`${h}=${w}`).join(`
425
425
  `):""}function L2({open:s,initial:h,existingAliases:w,saving:S,onCancel:M,onSave:O}){const{t:A}=Tt(),[r,u]=j.useState(""),[d,g]=j.useState("stdio"),[l,m]=j.useState(""),[b,C]=j.useState(""),[p,o]=j.useState(""),[c,a]=j.useState(""),[f,y]=j.useState(""),[R,k]=j.useState(null);j.useEffect(()=>{s&&(u((h==null?void 0:h.alias)??""),g((h==null?void 0:h.transport)??"stdio"),m((h==null?void 0:h.command)??""),C(((h==null?void 0:h.args)??[]).join(" ")),o(Zg(h==null?void 0:h.env)),a((h==null?void 0:h.url)??""),y(Zg(h==null?void 0:h.headers)),k(null))},[s,h]);const D=!!h,E=async L=>{if(L.preventDefault(),S)return;if(!r.trim()){k(A("harness.mcp.errAlias"));return}if(!D&&w.includes(r.trim())){k(A("harness.mcp.errAliasExists"));return}const z={alias:r.trim(),transport:d};if(d==="stdio"){if(!l.trim()){k(A("harness.mcp.errCommand"));return}z.command=l.trim();const H=b.trim()?b.trim().split(/\s+/):[];H.length>0&&(z.args=H);const P=Qg(p);Object.keys(P).length>0&&(z.env=P)}else{if(!c.trim()){k(A("harness.mcp.errUrl"));return}z.url=c.trim();const H=Qg(f);Object.keys(H).length>0&&(z.headers=H)}try{await O(z)}catch(H){k(H instanceof Error?H.message:String(H))}};return v.jsx(Ho,{open:s,onClose:M,size:"lg",children:v.jsxs("form",{onSubmit:E,className:"bg-warm-0 rounded-2xl shadow-elevated p-5 space-y-4",children:[v.jsx("h3",{className:"text-base font-semibold text-warm-700",children:A(D?"harness.mcp.editTitle":"harness.mcp.addTitle")}),v.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[v.jsxs("div",{children:[v.jsx("label",{className:"text-xs text-warm-500 block mb-1",children:A("harness.mcp.alias")}),v.jsx("input",{type:"text",value:r,onChange:L=>u(L.target.value),disabled:D,placeholder:"memory",className:"w-full px-3 py-1.5 text-xs border border-warm-200 rounded-lg bg-warm-50 text-warm-700 focus:ring-1 focus:ring-accent focus:border-accent disabled:opacity-50"})]}),v.jsxs("div",{children:[v.jsx("label",{className:"text-xs text-warm-500 block mb-1",children:A("harness.mcp.transport")}),v.jsxs("select",{value:d,onChange:L=>g(L.target.value),className:"w-full px-3 py-1.5 text-xs border border-warm-200 rounded-lg bg-warm-50 text-warm-700 focus:ring-1 focus:ring-accent focus:border-accent",children:[v.jsx("option",{value:"stdio",children:"stdio"}),v.jsx("option",{value:"http",children:"http"}),v.jsx("option",{value:"sse",children:"sse"})]})]})]}),d==="stdio"?v.jsxs("div",{className:"space-y-3",children:[v.jsxs("div",{children:[v.jsx("label",{className:"text-xs text-warm-500 block mb-1",children:A("harness.mcp.command")}),v.jsx("input",{type:"text",value:l,onChange:L=>m(L.target.value),placeholder:"npx",className:"w-full px-3 py-1.5 text-xs font-mono border border-warm-200 rounded-lg bg-warm-50 text-warm-700 focus:ring-1 focus:ring-accent focus:border-accent"})]}),v.jsxs("div",{children:[v.jsx("label",{className:"text-xs text-warm-500 block mb-1",children:A("harness.mcp.args")}),v.jsx("input",{type:"text",value:b,onChange:L=>C(L.target.value),placeholder:"-y @modelcontextprotocol/server-memory",className:"w-full px-3 py-1.5 text-xs font-mono border border-warm-200 rounded-lg bg-warm-50 text-warm-700 focus:ring-1 focus:ring-accent focus:border-accent"})]}),v.jsxs("div",{children:[v.jsx("label",{className:"text-xs text-warm-500 block mb-1",children:A("harness.mcp.env")}),v.jsx("textarea",{value:p,onChange:L=>o(L.target.value),placeholder:`API_KEY=...