@pixelbyte-software/pixcode 1.54.4 → 1.54.5
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.
|
@@ -256,7 +256,7 @@ import{j as i,a as X5,R as Q5,o as J5,_ as qR,b as KR,T as e4,P as t4,S as $l,E
|
|
|
256
256
|
*
|
|
257
257
|
* This source code is licensed under the ISC license.
|
|
258
258
|
* See the LICENSE file in the root directory of this source tree.
|
|
259
|
-
*/const SD=[["rect",{width:"8",height:"8",x:"3",y:"3",rx:"2",key:"by2w9f"}],["path",{d:"M7 11v4a2 2 0 0 0 2 2h4",key:"xkn7yn"}],["rect",{width:"8",height:"8",x:"13",y:"13",rx:"2",key:"1cgmvn"}]],CD=Et("workflow",SD),Z4=z4,ED=P7,Tw=R7,ND=w7,X4=N7,TD=F4,Dr=$4,Q4=g8,li=x8,AD=y8,tr=A7,la=F4,Ed=I7,J4=C7,mu=u8,hu=m8,eE=O7,nt=B4,Dt=B4,fu=B7,jD=F7,RD=kL,Bi=W8,Cn=q8,Ht=c8,Ki=o8,tE=cL,In=zL,Gl=V4,_D=V4,Nd=Q7,Zs=k8,gu=H4,dl=T8,kl=M8,$n=z8,On=rL,Sr=J8,ci=tL,ID=TL,LD=oL,nE=hL,PD=LL,DD=$7,OD=e8,MD=QL,rE=W4,jh=CL,Aw=W4,Gt=jL,En=eP,aE=U8,ja=xL,ht=q4,Rh=q4,FD=VL,Jf=K7,zD=V7,Td=G7,BD=H8,Wr=U4,UD=U4,$D=nP,Xs=aP,eg=a8,Sl=n8,tg=E8,Wl=X8,ng=Y8,Vr=iL,iE=H4,bu=G4,HD=G4,sE=pL,mr=gL,oE=yL,rg=L8,lE=ZL,cE=_L,go=ML,GD=DL,Pt=j8,Ad=b7,Vl=D8,Vn=$L,Ea=GL,dE=KL,_n=_8,ag=Z7,WD=hP,xu=yP,ig=Y4,VD=Y4,Nn=tD,rd=rD,vu=iD,hs=pP,fs=gP,qD=xP,Yo=kP,Us=CP,jw=TP,Zo=jP,_o=LP,KD=DP,uE=qP,_h=MP,$r=UP,Io=zP,Rw=HP,Lo=WP,Ih=YP,YD=XP,Lh=JP,Ds=oD,Xo=cD,Wa=uD,gs=mD,ZD=fD,Ph=bD,XD=yD,Po=kD,Cl=CD,yu=_P,QD=[{type:"key",id:"ctrl-c",label:"Ctrl-C",sequence:""},{type:"key",id:"ctrl-d",label:"Ctrl-D",sequence:""},{type:"key",id:"ctrl-l",label:"Ctrl-L",sequence:"\f"},{type:"key",id:"ctrl-z",label:"Ctrl-Z",sequence:""},{type:"key",id:"esc",label:"Esc",sequence:"\x1B"},{type:"key",id:"tab",label:"Tab",sequence:" "},{type:"key",id:"enter",label:"Enter",sequence:"\r"},{type:"key",id:"shift-tab",label:"⇧Tab",sequence:"\x1B[Z"},{type:"modifier",id:"ctrl",label:"CTRL",modifier:"ctrl"},{type:"modifier",id:"alt",label:"ALT",modifier:"alt"},{type:"arrow",id:"arrow-up",sequence:"\x1B[A",icon:"up"},{type:"arrow",id:"arrow-down",sequence:"\x1B[B",icon:"down"},{type:"arrow",id:"arrow-left",sequence:"\x1B[D",icon:"left"},{type:"arrow",id:"arrow-right",sequence:"\x1B[C",icon:"right"}],JD={up:ED,down:Z4,left:ND,right:X4},Do=e=>e.preventDefault(),_w="shrink-0 rounded-md border border-gray-600 bg-gray-700 px-2.5 py-1.5 text-xs font-medium text-gray-100 transition-colors select-none active:bg-blue-600 active:text-white active:border-blue-600 disabled:cursor-not-allowed disabled:opacity-40",eO="shrink-0 rounded-md border border-blue-500 bg-blue-600 px-2.5 py-1.5 text-xs font-medium text-white transition-colors select-none disabled:cursor-not-allowed disabled:opacity-40",xp="shrink-0 rounded-md border border-gray-600 bg-gray-700 p-1.5 text-gray-100 transition-colors select-none active:bg-blue-600 active:text-white active:border-blue-600 disabled:cursor-not-allowed disabled:opacity-40";function Iw({wsRef:e,terminalRef:t,isConnected:n,bottomOffset:r="bottom-0",placement:a="fixed"}){const{t:s}=Fe("settings"),[o,l]=m.useState(!1),[c,d]=m.useState(!1),[u,p]=m.useState(!1),f=m.useCallback(x=>{Cd(e.current,x)},[e]),h=m.useCallback(()=>{t.current?.scrollToBottom()},[t]),g=m.useCallback(async()=>{if(typeof navigator>"u"||!navigator.clipboard?.readText){p(!0);return}try{const x=await navigator.clipboard.readText();p(!1),x.length>0&&f(x)}catch{p(!0)}},[f]);m.useEffect(()=>{if(!u)return;const x=window.setTimeout(()=>p(!1),2500);return()=>window.clearTimeout(x)},[u]);const b=m.useCallback(x=>{let v=x;if(o&&x.length===1){const y=x.toLowerCase().charCodeAt(0);y>=97&&y<=122&&(v=String.fromCharCode(y-96)),l(!1)}c&&x.length===1&&(v="\x1B"+v,d(!1)),f(v)},[o,c,f]);return i.jsx("div",{className:`pointer-events-none ${a} inset-x-0 ${r} z-40 px-2 pb-[max(env(safe-area-inset-bottom),0px)] md:hidden`,children:i.jsxs("div",{className:"pointer-events-auto flex items-center gap-1 overflow-x-auto rounded-lg border border-gray-700/80 bg-gray-900/95 px-1.5 py-1.5 shadow-lg backdrop-blur-sm [-webkit-overflow-scrolling:touch] [scrollbar-width:none] [&::-webkit-scrollbar]:hidden",children:[u&&i.jsx("span",{className:"shrink-0 rounded-md border border-yellow-500/50 bg-yellow-500/15 px-2 py-1 text-[11px] text-yellow-100",children:"Clipboard blocked"}),i.jsx("button",{type:"button",onPointerDown:Do,onClick:()=>{g()},disabled:!n,className:xp,title:s("terminalShortcuts.paste",{defaultValue:"Paste"}),"aria-label":s("terminalShortcuts.paste",{defaultValue:"Paste"}),children:i.jsx(Zs,{className:"h-4 w-4"})}),QD.map(x=>{if(x.type==="modifier"){const v=x.modifier==="ctrl"?o:c,y=x.modifier==="ctrl"?()=>l(w=>!w):()=>d(w=>!w);return i.jsx("button",{type:"button",onPointerDown:Do,onClick:y,disabled:!n,className:v?eO:_w,children:x.label},x.id)}if(x.type==="arrow"){const v=JD[x.icon];return i.jsx("button",{type:"button",onPointerDown:Do,onClick:()=>f(x.sequence),disabled:!n,className:xp,children:i.jsx(v,{className:"h-4 w-4"})},x.id)}return i.jsx("button",{type:"button",onPointerDown:Do,onClick:()=>b(x.sequence),disabled:!n,className:_w,children:x.label},x.id)}),i.jsx("button",{type:"button",onPointerDown:Do,onClick:h,disabled:!n,className:xp,title:s("terminalShortcuts.scrollDown"),"aria-label":s("terminalShortcuts.scrollDown"),children:i.jsx(TD,{className:"h-4 w-4"})})]})})}function tO({tabId:e,selectedProject:t=null,selectedSession:n=null,initialCommand:r=null,isPlainShell:a=!1,onProcessComplete:s=null,minimal:o=!1,autoConnect:l=!1,forceNewSession:c=!1,startupInput:d=null,permissionOverride:u=null,provider:p=null,isActive:f=!0,layoutSignal:h=null,onClose:g=null,immersive:b=!1,showHeader:x=!0}){const{t:v}=Fe("chat"),[y,w]=m.useState(!1),[k,S]=m.useState(null),C=m.useRef(null),N=m.useRef(null),{terminalContainerRef:R,terminalRef:A,wsRef:j,isConnected:L,isInitialized:T,isConnecting:_,authUrl:E,authUrlVersion:O,connectToShell:$,disconnectFromShell:B,openAuthUrlInBrowser:K,copyAuthUrlToClipboard:Y}=u7({tabId:e,selectedProject:t,selectedSession:n,initialCommand:r,isPlainShell:a,minimal:o,autoConnect:l,forceNewSession:c,startupInput:d,permissionOverride:u,provider:p,isActive:f,layoutSignal:h,isRestarting:y,onProcessComplete:s,onOutputRef:N}),P=m.useCallback(()=>{const de=A.current;if(!de)return;const ce=de.buffer.active,V=ce.baseY+ce.cursorY,Z=Math.min(ce.baseY+ce.length-1,V+10),se=Math.max(0,V-yI),ge=[];for(let W=se;W<=Z;W++){const G=ce.getLine(W);G&&ge.push(G.translateToString().trimEnd())}let ee=-1;for(let W=ge.length-1;W>=0;W--)if(/esc to cancel/i.test(ge[W])||/enter to select/i.test(ge[W])){ee=W;break}if(ee===-1){S(null);return}const te=new Map,ve=Math.max(0,ee-wI);for(let W=ee-1;W>=ve;W--){const G=ge[W].match(/^\s*[❯›>]?\s*(\d+)\.\s+(.+)/);if(G){const ne=G[1],he=G[2].trim();parseInt(ne,10)<=kI&&he.length>0&&!te.has(ne)&&te.set(ne,he)}}const le=[];for(let W=1;W<=te.size&&te.has(String(W));W++)le.push({number:String(W),label:te.get(String(W))});S(le.length>=SI?le:null)},[A]),z=m.useCallback(()=>{C.current&&clearTimeout(C.current),C.current=setTimeout(P,vI)},[P]);m.useEffect(()=>{N.current=z},[z]),m.useEffect(()=>()=>{C.current&&clearTimeout(C.current)},[]),m.useEffect(()=>{L||(C.current&&(clearTimeout(C.current),C.current=null),S(null))},[L]),m.useEffect(()=>{if(!f||!T||!L)return;const de=()=>{A.current?.focus()},ce=window.requestAnimationFrame(de),V=window.setTimeout(de,0);return()=>{window.cancelAnimationFrame(ce),window.clearTimeout(V)}},[f,L,T,A]);const U=m.useCallback(de=>{Cd(j.current,de)},[j]),F=m.useMemo(()=>HI(n),[n]),J=m.useMemo(()=>p||(n?.__provider?n.__provider:window.localStorage.getItem("selected-provider")||"claude"),[p,n?.__provider]),ae=Rn[J]??"Claude Code",Q=m.useMemo(()=>F?F.slice(0,30):null,[F]),pe=m.useMemo(()=>F?F.slice(0,50):null,[F]),oe=m.useCallback(()=>{w(!0),window.setTimeout(()=>{w(!1)},bI)},[]),fe=m.useCallback(()=>{B(),g?.()},[B,g]);if(!t)return i.jsx(m7,{title:v("shell.selectProject.title"),description:v("shell.selectProject.description")});if(o)return i.jsxs(i.Fragment,{children:[i.jsx(f7,{terminalContainerRef:R,authUrl:E,authUrlVersion:O,initialCommand:r,isConnected:L,openAuthUrlInBrowser:K,copyAuthUrlToClipboard:Y}),i.jsx(Iw,{wsRef:j,terminalRef:A,isConnected:L,bottomOffset:"bottom-0"})]});const be=a?v("shell.runCommand",{command:r||v("shell.defaultCommand"),projectName:t.displayName}):n?v("shell.resumeSession",{displayName:pe}):v("shell.startProviderSession",{provider:ae,defaultValue:"Start a new {{provider}} session"}),Ce=a?v("shell.runCommand",{command:r||v("shell.defaultCommand"),projectName:t.displayName}):v("shell.startProviderCli",{provider:ae,projectName:t.displayName,defaultValue:"Starting {{provider}} in {{projectName}}"}),Se=T?_?"connecting":L?null:"connect":"loading",Te=Se==="connecting"?Ce:be,M=typeof h=="string"&&h.startsWith("right-cli:");return i.jsxs("div",{className:me("flex h-full min-w-0 w-full flex-col overflow-hidden bg-gray-900",b&&"bg-gray-950"),children:[x&&i.jsx(h7,{isConnected:L,isInitialized:T,isRestarting:y,hasSession:!!n,sessionDisplayNameShort:Q,onDisconnect:fe,onRestart:oe,statusNewSessionText:v("shell.status.newSession"),statusInitializingText:v("shell.status.initializing"),statusRestartingText:v("shell.status.restarting"),disconnectLabel:v("shell.actions.disconnect"),disconnectTitle:v("shell.actions.disconnectTitle"),restartLabel:v("shell.actions.restart"),restartTitle:v("shell.actions.restartTitle"),disableRestart:y||L}),i.jsxs("div",{className:me("relative min-h-0 min-w-0 flex-1 overflow-hidden",b?"p-0 pb-12 md:pb-0":"p-0 pb-16 md:pb-0"),children:[i.jsx("div",{ref:R,className:me("pixcode-shell-terminal h-full min-h-0 w-full min-w-0 max-w-full focus:outline-none",M&&"pixcode-shell-terminal--right-cli"),style:{outline:"none"}}),Se&&i.jsx(p7,{mode:Se,description:Te,loadingLabel:v("shell.loading"),connectLabel:v("shell.actions.connect"),connectTitle:v("shell.actions.connectTitle"),connectingLabel:v("shell.connecting"),onConnect:$}),k&&L&&i.jsx("div",{className:me("absolute inset-x-0 z-10 border-t border-gray-700/80 bg-gray-800/95 px-3 py-2 backdrop-blur-sm",b?"bottom-12 md:bottom-0":"bottom-14 md:bottom-0"),onMouseDown:de=>de.preventDefault(),children:i.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[k.map(de=>i.jsxs("button",{type:"button",onClick:()=>{U(`${de.number}\r`),S(null)},className:"max-w-36 truncate rounded bg-blue-600 px-3 py-1.5 text-xs font-medium text-white transition-colors hover:bg-blue-700",title:`${de.number}. ${de.label}`,children:[de.number,". ",de.label]},de.number)),i.jsx("button",{type:"button",onClick:()=>{U("\x1B"),S(null)},className:"rounded bg-gray-700 px-3 py-1.5 text-xs font-medium text-gray-200 transition-colors hover:bg-gray-600",children:"Esc"})]})})]}),i.jsx(Iw,{wsRef:j,terminalRef:A,isConnected:L,placement:b?"absolute":"fixed"})]})}function nO({className:e}){return i.jsx("div",{className:`flex h-full items-center justify-center ${e}`,children:i.jsxs("div",{className:"text-center text-gray-500 dark:text-gray-400",children:[i.jsx("div",{className:"mx-auto mb-4 flex h-16 w-16 items-center justify-center rounded-full bg-gray-100 dark:bg-gray-800",children:i.jsx("svg",{className:"h-8 w-8 text-gray-400",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:i.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 9l3 3-3 3m5 0h3M5 20h14a2 2 0 002-2V6a2 2 0 00-2-2H5a2 2 0 002 2z"})})}),i.jsx("h3",{className:"mb-2 text-lg font-semibold",children:"No Project Selected"}),i.jsx("p",{children:"A project is required to open a shell"})]})})}function rO({title:e,isCompleted:t,onClose:n=null}){return i.jsx("div",{className:"flex-shrink-0 border-b border-gray-700 bg-gray-800 px-4 py-2",children:i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{className:"flex items-center space-x-2",children:[i.jsx("h3",{className:"text-sm font-medium text-gray-200",children:e}),t&&i.jsx("span",{className:"text-xs text-green-400",children:"(Completed)"})]}),n&&i.jsx("button",{onClick:n,className:"text-gray-400 hover:text-white",title:"Close",children:i.jsx("svg",{className:"h-4 w-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:i.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]})})}function El({project:e=null,session:t=null,command:n=null,isPlainShell:r=null,isActive:a=!0,autoConnect:s=!0,onComplete:o=null,onClose:l=null,title:c=null,className:d="",showHeader:u=!0,compact:p=!1,minimal:f=!1,immersive:h=!1,forceNewSession:g=!1,startupInput:b=null,permissionOverride:x=null,provider:v=null,layoutSignal:y=null,tabId:w=null}){const[k,S]=m.useState(!1),C=m.useMemo(()=>w||`tab_${crypto.randomUUID()}`,[w]),N=r!==null?r:n!==null,R=m.useCallback(A=>{S(!0),o?.(A)},[o]);return e?i.jsxs("div",{className:`flex h-full w-full min-w-0 flex-col overflow-hidden ${d}`,children:[!f&&u&&c&&i.jsx(rO,{title:c,isCompleted:k,onClose:l}),i.jsx("div",{className:"min-h-0 w-full min-w-0 flex-1 overflow-hidden",children:i.jsx(tO,{tabId:C,selectedProject:e,selectedSession:t,initialCommand:n,isPlainShell:N,isActive:a,onProcessComplete:R,minimal:f,autoConnect:f?!0:s,forceNewSession:g,startupInput:b,permissionOverride:x,provider:v,layoutSignal:y,onClose:l,immersive:h,showHeader:u})})]}):i.jsx(nO,{className:d})}const aO=(e,t)=>t||(e==="claude"?"claude --dangerously-skip-permissions /login":e==="cursor"?"cursor-agent login":e==="codex"?"codex login":e==="qwen"?"qwen auth":e==="opencode"?"opencode auth login":"gemini"),iO={claude:{keyLabel:"Anthropic API Key",keyExample:"sk-ant-...",supportsBaseUrl:!0,baseUrlExample:"https://api.anthropic.com",keyConsoleUrl:"https://console.anthropic.com/settings/keys",keyConsoleLabel:"Anthropic Console"},codex:{keyLabel:"OpenAI API Key",keyExample:"sk-...",supportsBaseUrl:!0,baseUrlExample:"https://api.openai.com/v1",keyConsoleUrl:"https://platform.openai.com/api-keys",keyConsoleLabel:"OpenAI Platform"},gemini:{keyLabel:"Gemini API Key",keyExample:"AI...",supportsBaseUrl:!1,keyConsoleUrl:"https://aistudio.google.com/app/apikey",keyConsoleLabel:"Google AI Studio"},qwen:{keyLabel:"OpenAI-Compatible API Key",keyExample:"sk-... or sk-sp-...",supportsBaseUrl:!0,baseUrlExample:"https://dashscope-intl.aliyuncs.com/compatible-mode/v1",keyConsoleUrl:"https://github.com/QwenLM/qwen-code",keyConsoleLabel:"Qwen Code Docs",notes:"Accepts any OpenAI-compatible endpoint — Alibaba Cloud, ModelScope, OpenRouter, self-hosted, etc."},opencode:{keyLabel:"Anthropic API Key (default backend)",keyExample:"sk-ant-...",supportsBaseUrl:!0,baseUrlExample:"https://api.anthropic.com",keyConsoleUrl:"https://console.anthropic.com/settings/keys",keyConsoleLabel:"Anthropic Console",notes:"OpenCode is multi-provider — this sets the Anthropic credentials. Switch providers via `opencode auth login` or opencode.json."}};function Lw({active:e,children:t,onClick:n}){return i.jsx("button",{onClick:n,className:`flex-1 border-b-2 px-4 py-2.5 text-sm font-medium transition-colors ${e?"border-primary text-foreground":"border-transparent text-muted-foreground hover:text-foreground"}`,children:t})}function sO({provider:e}){const[t,n]=m.useState(""),[r,a]=m.useState(!1),[s,o]=m.useState("idle"),[l,c]=m.useState(null),d=async()=>{const u=t.trim();if(u){a(!0),c(null),o("idle");try{const p=await Ee(`/api/providers/${e}/oauth-paste`,{method:"POST",body:JSON.stringify({callbackUrl:u})}),f=await p.json().catch(()=>({}));if(!p.ok||!f?.success)throw new Error(f?.error||`Request failed (${p.status})`);o("ok"),n("")}catch(p){c(p?.message||"Forward failed"),o("error")}finally{a(!1)}}};return i.jsxs("div",{className:"mt-3 rounded-lg border border-border/60 bg-muted/30 p-3 text-sm",children:[i.jsx("div",{className:"mb-2 font-medium text-foreground",children:"Remote login? Paste the callback URL here"}),i.jsxs("p",{className:"mb-3 text-xs text-muted-foreground",children:["When the CLI shows ",i.jsx("code",{className:"rounded bg-background px-1 font-mono text-[11px]",children:"http://127.0.0.1:PORT/…"})," and your browser can't reach it (VPS setups), copy the failing URL from your address bar and paste it below. Pixcode forwards the token exchange to the CLI process on this host."]}),i.jsxs("div",{className:"flex gap-2",children:[i.jsx("input",{type:"url",value:t,onChange:u=>n(u.target.value),placeholder:"http://127.0.0.1:49312/callback?code=...",className:"flex-1 rounded-md border border-border bg-background px-3 py-2 font-mono text-xs text-foreground focus:border-primary focus:outline-none",onKeyDown:u=>{u.key==="Enter"&&d()}}),i.jsx("button",{onClick:()=>void d(),disabled:r||!t.trim(),className:"flex items-center gap-1.5 rounded-md bg-foreground px-3 py-2 text-xs font-medium text-background transition-opacity hover:opacity-90 disabled:opacity-40",children:r?i.jsx(Dt,{className:"h-3.5 w-3.5 animate-spin"}):"Forward"})]}),s==="ok"&&i.jsxs("div",{className:"mt-2 flex items-center gap-1.5 text-xs text-emerald-600 dark:text-emerald-400",children:[i.jsx(Ht,{className:"h-3.5 w-3.5"})," Forwarded — check the terminal above for the completion message."]}),s==="error"&&l&&i.jsx("div",{className:"mt-2 text-xs text-red-600 dark:text-red-400",children:l})]})}function oO({provider:e,onSaved:t}){const n=iO[e],[r,a]=m.useState(""),[s,o]=m.useState(""),[l,c]=m.useState(!1),[d,u]=m.useState("idle"),[p,f]=m.useState(null);m.useEffect(()=>{let g=!1;return(async()=>{try{const x=await(await Ee("/api/providers/credentials")).json().catch(()=>({}));if(g||!x?.success)return;const v=x.data?.[e];v?.baseUrl&&o(v.baseUrl)}catch{}})(),()=>{g=!0}},[e]);const h=async()=>{const g=r.trim();if(g){c(!0),f(null),u("idle");try{const b=await Ee(`/api/providers/${e}/auth/api-key`,{method:"POST",body:JSON.stringify({apiKey:g,baseUrl:n.supportsBaseUrl&&s.trim()?s.trim():""})}),x=await b.json().catch(()=>({}));if(!b.ok||!x?.success)throw new Error(x?.error||`Request failed (${b.status})`);u("ok"),a(""),t()}catch(b){f(b?.message||"Save failed"),u("error")}finally{c(!1)}}};return n?i.jsx("div",{className:"flex h-full flex-col overflow-y-auto p-6",children:i.jsxs("div",{className:"mx-auto w-full max-w-lg space-y-5",children:[i.jsxs("div",{className:"flex items-center gap-3",children:[i.jsx("div",{className:"flex h-10 w-10 items-center justify-center rounded-full bg-muted",children:i.jsx(HD,{className:"h-5 w-5 text-foreground"})}),i.jsxs("div",{children:[i.jsx("h4",{className:"text-base font-semibold text-foreground",children:n.keyLabel}),i.jsxs("a",{href:n.keyConsoleUrl,target:"_blank",rel:"noreferrer",className:"inline-flex items-center gap-1 text-xs text-muted-foreground hover:text-foreground",children:["Get a key from ",n.keyConsoleLabel,i.jsx(tr,{className:"h-3 w-3"})]})]})]}),n.notes&&i.jsx("div",{className:"rounded-md border border-border/60 bg-muted/40 p-3 text-xs text-muted-foreground",children:n.notes}),i.jsxs("div",{className:"space-y-1.5",children:[i.jsx("label",{className:"text-xs font-medium text-foreground",children:"API Key"}),i.jsx("input",{type:"password",value:r,onChange:g=>a(g.target.value),placeholder:n.keyExample,className:"w-full rounded-md border border-border bg-background px-3 py-2 font-mono text-sm text-foreground focus:border-primary focus:outline-none",autoComplete:"off",spellCheck:!1}),i.jsxs("p",{className:"text-[11px] text-muted-foreground",children:["Stored locally at ",i.jsx("code",{className:"rounded bg-muted px-1 font-mono text-[10px]",children:"~/.pixcode/provider-credentials.json"})," with 0600 permissions."]})]}),n.supportsBaseUrl&&i.jsxs("div",{className:"space-y-1.5",children:[i.jsxs("label",{className:"text-xs font-medium text-foreground",children:["Base URL ",i.jsx("span",{className:"font-normal text-muted-foreground",children:"(optional — use a custom endpoint)"})]}),i.jsx("input",{type:"url",value:s,onChange:g=>o(g.target.value),placeholder:n.baseUrlExample,className:"w-full rounded-md border border-border bg-background px-3 py-2 font-mono text-sm text-foreground focus:border-primary focus:outline-none",autoComplete:"off",spellCheck:!1}),i.jsx("p",{className:"text-[11px] text-muted-foreground",children:"Point at any OpenAI-compatible proxy (OpenRouter, local LLM, self-hosted, budget provider) to cut costs or hit different models."})]}),i.jsxs("div",{className:"flex items-center gap-3 pt-2",children:[i.jsxs("button",{onClick:()=>void h(),disabled:l||!r.trim(),className:"inline-flex items-center gap-2 rounded-md bg-foreground px-4 py-2 text-sm font-medium text-background transition-opacity hover:opacity-90 disabled:opacity-40",children:[l?i.jsx(Dt,{className:"h-4 w-4 animate-spin"}):i.jsx(Ht,{className:"h-4 w-4"}),"Save API Key"]}),d==="ok"&&i.jsx("span",{className:"text-xs text-emerald-600 dark:text-emerald-400",children:"Saved — reconnect to pick it up."}),d==="error"&&p&&i.jsx("span",{className:"text-xs text-red-600 dark:text-red-400",children:p})]})]})}):i.jsx("div",{className:"p-6 text-sm text-muted-foreground",children:"This provider uses OAuth only — use the Browser tab to log in."})}function pE({isOpen:e,onClose:t,provider:n="claude",onComplete:r,customCommand:a,isAuthenticated:s=!1}){const{t:o}=Fe("common"),l=n!=="cursor",[c,d]=m.useState(l?"apiKey":"browser");m.useEffect(()=>{e&&d(l?"apiKey":"browser")},[e,n,l]);const u=m.useMemo(()=>`${Rn[n]??n} Login`,[n]);if(!e)return null;const p=aO(n,a),f=h=>r?.(h);return i.jsx("div",{className:"fixed inset-0 z-[9999] flex items-center justify-center bg-black bg-opacity-50 max-md:items-stretch max-md:justify-stretch",children:i.jsxs("div",{className:"flex h-3/4 w-full max-w-4xl flex-col rounded-lg bg-white shadow-xl dark:bg-gray-800 max-md:m-0 max-md:h-full max-md:max-w-none max-md:rounded-none md:m-4 md:h-3/4 md:max-w-4xl md:rounded-lg",children:[i.jsxs("div",{className:"flex items-center justify-between border-b border-gray-200 p-4 dark:border-gray-700",children:[i.jsx("h3",{className:"text-lg font-semibold text-gray-900 dark:text-white",children:u}),i.jsx("button",{onClick:t,className:"text-gray-400 transition-colors hover:text-gray-600 dark:hover:text-gray-300","aria-label":"Close login modal",children:i.jsx(ht,{className:"h-6 w-6"})})]}),i.jsxs("div",{className:"flex border-b border-gray-200 dark:border-gray-700",children:[i.jsx(Lw,{active:c==="browser",onClick:()=>d("browser"),children:"Browser / OAuth"}),l&&i.jsx(Lw,{active:c==="apiKey",onClick:()=>d("apiKey"),children:"API Key"})]}),i.jsx("div",{className:"flex flex-1 flex-col overflow-hidden",children:c==="browser"?i.jsxs("div",{className:"flex flex-1 flex-col overflow-hidden",children:[i.jsx("div",{className:"min-h-0 flex-1",children:i.jsx(El,{project:S_,command:p,onComplete:f,minimal:!0})}),i.jsx("div",{className:"border-t border-border/40 bg-background/50 px-4 py-3",children:i.jsx(sO,{provider:n})})]}):i.jsx(oO,{provider:n,onSaved:()=>f(0)})})]})})}const lO=({className:e="w-5 h-5"})=>i.jsx("img",{src:"/icons/claude-ai-icon.svg",alt:"Claude",className:e}),cO=({className:e="w-5 h-5"})=>{const{isDarkMode:t}=Fa();return i.jsx("img",{src:t?"/icons/codex-white.svg":"/icons/codex.svg",alt:"Codex",className:e})},dO=({className:e="w-5 h-5"})=>{const{isDarkMode:t}=Fa();return i.jsx("img",{src:t?"/icons/cursor-white.svg":"/icons/cursor.svg",alt:"Cursor",className:e})},uO=({className:e="w-5 h-5"})=>i.jsx("img",{src:"/icons/gemini-ai-icon.svg",alt:"Gemini",className:e}),pO=({className:e="w-5 h-5"})=>{const{isDarkMode:t}=Fa(),n=t?"/icons/opencode-logo-dark.svg":"/icons/opencode-logo-light.svg";return i.jsx("img",{src:n,alt:"OpenCode",className:e})},mO=({className:e="w-5 h-5"})=>i.jsx("img",{src:"/icons/qwen-logo.svg",alt:"Qwen Code",className:e});function yn({provider:e="claude",className:t="w-5 h-5"}){return e==="cursor"?i.jsx(dO,{className:t}):e==="codex"?i.jsx(cO,{className:t}):e==="gemini"?i.jsx(uO,{className:t}):e==="qwen"?i.jsx(mO,{className:t}):e==="opencode"?i.jsx(pO,{className:t}):i.jsx(lO,{className:t})}function hO({provider:e,title:t,status:n,connectedClassName:r,iconContainerClassName:a,loginButtonClassName:s,onLogin:o}){const l=n.authenticated?r:"border-border bg-card",c=n.loading?"Checking...":n.authenticated?n.email||"Connected":n.error||"Not connected";return i.jsx("div",{className:`rounded-lg border p-4 transition-colors ${l}`,children:i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{className:"flex items-center gap-3",children:[i.jsx("div",{className:`flex h-10 w-10 items-center justify-center rounded-full ${a}`,children:i.jsx(yn,{provider:e,className:"h-5 w-5"})}),i.jsxs("div",{children:[i.jsxs("div",{className:"flex items-center gap-2 font-medium text-foreground",children:[t,n.authenticated&&i.jsx(Ht,{className:"h-4 w-4 text-green-500"})]}),i.jsx("div",{className:"text-xs text-muted-foreground",children:c})]})]}),!n.authenticated&&!n.loading&&i.jsx("button",{onClick:o,className:`${s} rounded-lg px-4 py-2 text-sm font-medium text-white transition-colors`,children:"Login"})]})})}const fO=[{provider:"claude",title:"Claude Code",connectedClassName:"bg-blue-50 dark:bg-blue-900/20 border-blue-200 dark:border-blue-800",iconContainerClassName:"bg-blue-100 dark:bg-blue-900/30",loginButtonClassName:"bg-blue-600 hover:bg-blue-700"},{provider:"cursor",title:"Cursor",connectedClassName:"bg-purple-50 dark:bg-purple-900/20 border-purple-200 dark:border-purple-800",iconContainerClassName:"bg-purple-100 dark:bg-purple-900/30",loginButtonClassName:"bg-purple-600 hover:bg-purple-700"},{provider:"codex",title:"OpenAI Codex",connectedClassName:"bg-gray-100 dark:bg-gray-800/50 border-gray-300 dark:border-gray-600",iconContainerClassName:"bg-gray-100 dark:bg-gray-800",loginButtonClassName:"bg-gray-800 hover:bg-gray-900 dark:bg-gray-700 dark:hover:bg-gray-600"},{provider:"gemini",title:"Gemini",connectedClassName:"bg-teal-50 dark:bg-teal-900/20 border-teal-200 dark:border-teal-800",iconContainerClassName:"bg-teal-100 dark:bg-teal-900/30",loginButtonClassName:"bg-teal-600 hover:bg-teal-700"},{provider:"qwen",title:"Qwen Code",connectedClassName:"bg-orange-50 dark:bg-orange-900/20 border-orange-200 dark:border-orange-800",iconContainerClassName:"bg-orange-100 dark:bg-orange-900/30",loginButtonClassName:"bg-orange-600 hover:bg-orange-700"}];function Pw({providerStatuses:e,onOpenProviderLogin:t}){return i.jsxs("div",{className:"space-y-6",children:[i.jsxs("div",{className:"mb-6 text-center",children:[i.jsx("h2",{className:"mb-2 text-2xl font-bold text-foreground",children:"Connect Your AI Agents"}),i.jsx("p",{className:"text-muted-foreground",children:"Login to one or more AI coding assistants. All are optional."})]}),i.jsx("div",{className:"space-y-3",children:fO.map(n=>i.jsx(hO,{provider:n.provider,title:n.title,status:e[n.provider],connectedClassName:n.connectedClassName,iconContainerClassName:n.iconContainerClassName,loginButtonClassName:n.loginButtonClassName,onLogin:()=>t(n.provider)},n.provider))}),i.jsx("div",{className:"pt-2 text-center text-sm text-muted-foreground",children:i.jsx("p",{children:"You can configure these later in Settings."})})]})}function gO({gitName:e,gitEmail:t,isSubmitting:n,onGitNameChange:r,onGitEmailChange:a}){return i.jsxs("div",{className:"space-y-6",children:[i.jsxs("div",{className:"mb-8 text-center",children:[i.jsx("div",{className:"mx-auto mb-4 flex h-16 w-16 items-center justify-center rounded-full bg-blue-100 dark:bg-blue-900/30",children:i.jsx(Nn,{className:"h-8 w-8 text-blue-600 dark:text-blue-400"})}),i.jsx("h2",{className:"mb-2 text-2xl font-bold text-foreground",children:"Git Configuration"}),i.jsx("p",{className:"text-muted-foreground",children:"Configure your git identity to ensure proper attribution for commits."})]}),i.jsxs("div",{className:"space-y-4",children:[i.jsxs("div",{children:[i.jsxs("label",{htmlFor:"gitName",className:"mb-2 flex items-center gap-2 text-sm font-medium text-foreground",children:[i.jsx($D,{className:"h-4 w-4"}),"Git Name ",i.jsx("span",{className:"text-red-500",children:"*"})]}),i.jsx("input",{type:"text",id:"gitName",value:e,onChange:s=>r(s.target.value),className:"w-full rounded-lg border border-border bg-background px-4 py-3 text-foreground focus:border-transparent focus:outline-none focus:ring-2 focus:ring-blue-500",placeholder:"John Doe",required:!0,disabled:n}),i.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:"Saved as `git config --global user.name`."})]}),i.jsxs("div",{children:[i.jsxs("label",{htmlFor:"gitEmail",className:"mb-2 flex items-center gap-2 text-sm font-medium text-foreground",children:[i.jsx(BD,{className:"h-4 w-4"}),"Git Email ",i.jsx("span",{className:"text-red-500",children:"*"})]}),i.jsx("input",{type:"email",id:"gitEmail",value:t,onChange:s=>a(s.target.value),className:"w-full rounded-lg border border-border bg-background px-4 py-3 text-foreground focus:border-transparent focus:outline-none focus:ring-2 focus:ring-blue-500",placeholder:"john@example.com",required:!0,disabled:n}),i.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:"Saved as `git config --global user.email`."})]})]})]})}const Dw=[{title:"Git Configuration",icon:Nn,required:!0},{title:"Connect Agents",icon:J4,required:!1}];function bO({currentStep:e}){return i.jsx("div",{className:"mb-8",children:i.jsx("div",{className:"flex items-center justify-between",children:Dw.map((t,n)=>{const r=n<e,a=n===e,s=t.icon;return i.jsxs("div",{className:"contents",children:[i.jsxs("div",{className:"flex flex-1 flex-col items-center",children:[i.jsx("div",{className:`flex h-12 w-12 items-center justify-center rounded-full border-2 transition-colors duration-200 ${r?"border-green-500 bg-green-500 text-white":a?"border-blue-600 bg-blue-600 text-white":"border-border bg-background text-muted-foreground"}`,children:r?i.jsx(Ht,{className:"h-6 w-6"}):i.jsx(s,{className:"h-6 w-6"})}),i.jsxs("div",{className:"mt-2 text-center",children:[i.jsx("p",{className:`text-sm font-medium ${a?"text-foreground":"text-muted-foreground"}`,children:t.title}),t.required&&i.jsx("span",{className:"text-xs text-red-500",children:"Required"})]})]}),n<Dw.length-1&&i.jsx("div",{className:`mx-2 h-0.5 flex-1 transition-colors duration-200 ${r?"bg-green-500":"bg-border"}`})]},t.title)})})})}const Ow=/^[^\s@]+@[^\s@]+\.[^\s@]+$/,Mw=async(e,t)=>{try{return(await e.json()).error||t}catch{return t}};function xO({onComplete:e}){const[t,n]=m.useState(0),[r,a]=m.useState(""),[s,o]=m.useState(""),[l,c]=m.useState(!1),[d,u]=m.useState(""),[p,f]=m.useState(null),{providerAuthStatus:h,checkProviderAuthStatus:g,refreshProviderAuthStatuses:b}=pu(),x=m.useRef(void 0),v=m.useCallback(async()=>{try{const R=await Ee("/api/user/git-config");if(!R.ok)return;const A=await R.json();A.gitName&&a(A.gitName),A.gitEmail&&o(A.gitEmail)}catch(R){console.error("Error loading git config:",R)}},[]);m.useEffect(()=>{v(),b()},[v,b]),m.useEffect(()=>{const R=x.current;x.current=p,R!=null&&p===null&&b()},[p,b]);const y=R=>{f(R)},w=R=>{R===0&&p&&g(p)},k=async()=>{if(u(""),t!==0){n(R=>R+1);return}if(!r.trim()||!s.trim()){u("Both git name and email are required.");return}if(!Ow.test(s)){u("Please enter a valid email address.");return}c(!0);try{const R=await Ee("/api/user/git-config",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({gitName:r,gitEmail:s})});if(!R.ok){const A=await Mw(R,"Failed to save git configuration");throw new Error(A)}n(A=>A+1)}catch(R){u(R instanceof Error?R.message:"Failed to save git configuration")}finally{c(!1)}},S=()=>{u(""),n(R=>R-1)},C=async()=>{c(!0),u("");try{const R=await Ee("/api/user/complete-onboarding",{method:"POST"});if(!R.ok){const A=await Mw(R,"Failed to complete onboarding");throw new Error(A)}await e?.()}catch(R){u(R instanceof Error?R.message:"Failed to complete onboarding")}finally{c(!1)}},N=t===0?!!(r.trim()&&s.trim()&&Ow.test(s)):!0;return i.jsxs(i.Fragment,{children:[i.jsx("div",{className:"flex min-h-screen items-center justify-center bg-background p-4",children:i.jsxs("div",{className:"w-full max-w-2xl",children:[i.jsx(bO,{currentStep:t}),i.jsxs("div",{className:"rounded-lg border border-border bg-card p-8 shadow-lg",children:[t===0?i.jsx(gO,{gitName:r,gitEmail:s,isSubmitting:l,onGitNameChange:a,onGitEmailChange:o}):t===1?i.jsx(Pw,{providerStatuses:h,onOpenProviderLogin:y}):i.jsx(Pw,{providerStatuses:h,onOpenProviderLogin:y}),d&&i.jsx("div",{className:"mt-6 rounded-lg border border-red-300 bg-red-100 p-4 dark:border-red-800 dark:bg-red-900/20",children:i.jsx("p",{className:"text-sm text-red-700 dark:text-red-400",children:d})}),i.jsxs("div",{className:"mt-8 flex items-center justify-between border-t border-border pt-6",children:[i.jsxs("button",{onClick:S,disabled:t===0||l,className:"flex items-center gap-2 px-4 py-2 text-sm font-medium text-muted-foreground transition-colors duration-200 hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",children:[i.jsx(Q4,{className:"h-4 w-4"}),"Previous"]}),i.jsx("div",{className:"flex items-center gap-3",children:t<1?i.jsx("button",{onClick:k,disabled:!N||l,className:"flex items-center gap-2 rounded-lg bg-blue-600 px-6 py-3 font-medium text-white transition-colors duration-200 hover:bg-blue-700 disabled:cursor-not-allowed disabled:bg-blue-400",children:l?i.jsxs(i.Fragment,{children:[i.jsx(Dt,{className:"h-4 w-4 animate-spin"}),"Saving..."]}):i.jsxs(i.Fragment,{children:["Next",i.jsx(li,{className:"h-4 w-4"})]})}):i.jsx("button",{onClick:C,disabled:l,className:"flex items-center gap-2 rounded-lg bg-green-600 px-6 py-3 font-medium text-white transition-colors duration-200 hover:bg-green-700 disabled:cursor-not-allowed disabled:bg-green-400",children:l?i.jsxs(i.Fragment,{children:[i.jsx(Dt,{className:"h-4 w-4 animate-spin"}),"Completing..."]}):i.jsxs(i.Fragment,{children:[i.jsx(Ht,{className:"h-4 w-4"}),"Complete Setup"]})})})]})]})]})}),p&&i.jsx(pE,{isOpen:!!p,onClose:()=>f(null),provider:p,onComplete:w})]})}const vO=["0s","0.1s","0.2s"];function yO(){return i.jsx("div",{className:"flex min-h-screen items-center justify-center bg-background p-4",children:i.jsxs("div",{className:"text-center",children:[i.jsx("div",{className:"mb-4 flex justify-center",children:i.jsx("div",{className:"flex h-16 w-16 items-center justify-center rounded-lg bg-primary shadow-sm",children:i.jsx(Wr,{className:"h-8 w-8 text-primary-foreground"})})}),i.jsx("h1",{className:"mb-2 text-2xl font-bold text-foreground",children:"Pixcode"}),i.jsx("div",{className:"flex items-center justify-center space-x-2",children:vO.map(e=>i.jsx("div",{className:"h-2 w-2 animate-bounce rounded-full bg-blue-500",style:{animationDelay:e}},e))}),i.jsx("p",{className:"mt-2 text-muted-foreground",children:"Loading..."})]})})}function mE({errorMessage:e}){return e?i.jsx("div",{className:"rounded-md border border-red-300 bg-red-100 p-3 dark:border-red-800 dark:bg-red-900/20",children:i.jsx("p",{className:"text-sm text-red-700 dark:text-red-400",children:e})}):null}function Pi({id:e,label:t,value:n,onChange:r,placeholder:a,isDisabled:s,type:o="text",name:l,autoComplete:c}){return i.jsxs("div",{children:[i.jsx("label",{htmlFor:e,className:"mb-1 block text-sm font-medium text-foreground",children:t}),i.jsx("input",{id:e,type:o,name:l??e,autoComplete:c,value:n,onChange:d=>r(d.target.value),className:"w-full rounded-md border border-border bg-background px-3 py-2 text-foreground focus:border-transparent focus:outline-none focus:ring-2 focus:ring-blue-500",placeholder:a,required:!0,disabled:s})]})}function hE({title:e,description:t,children:n,footerText:r,logo:a}){return i.jsx("div",{className:"flex min-h-screen items-center justify-center bg-background p-4",children:i.jsx("div",{className:"w-full max-w-md",children:i.jsxs("div",{className:"space-y-6 rounded-lg border border-border bg-card p-8 shadow-lg",children:[i.jsxs("div",{className:"text-center",children:[i.jsx("div",{className:"mb-4 flex justify-center",children:a??i.jsx("div",{className:"flex h-16 w-16 items-center justify-center rounded-lg bg-primary shadow-sm",children:i.jsx(Wr,{className:"h-8 w-8 text-primary-foreground"})})}),i.jsx("h1",{className:"text-2xl font-bold text-foreground",children:e}),i.jsx("p",{className:"mt-2 text-muted-foreground",children:t})]}),n,i.jsx("div",{className:"text-center",children:i.jsx("p",{className:"text-sm text-muted-foreground",children:r})}),i.jsxs("div",{className:"flex items-center justify-center gap-1.5 pt-2",children:[i.jsx("svg",{className:"h-3.5 w-3.5 text-muted-foreground/50",fill:"currentColor",viewBox:"0 0 24 24","aria-hidden":"true",children:i.jsx("path",{d:"M12 2C6.477 2 2 6.484 2 12.017c0 4.425 2.865 8.18 6.839 9.504.5.092.682-.217.682-.483 0-.237-.008-.868-.013-1.703-2.782.605-3.369-1.343-3.369-1.343-.454-1.158-1.11-1.466-1.11-1.466-.908-.62.069-.608.069-.608 1.003.07 1.531 1.032 1.531 1.032.892 1.53 2.341 1.088 2.91.832.092-.647.35-1.088.636-1.338-2.22-.253-4.555-1.113-4.555-4.951 0-1.093.39-1.988 1.029-2.688-.103-.253-.446-1.272.098-2.65 0 0 .84-.27 2.75 1.026A9.564 9.564 0 0112 6.844c.85.004 1.705.115 2.504.337 1.909-1.296 2.747-1.027 2.747-1.027.546 1.379.202 2.398.1 2.651.64.7 1.028 1.595 1.028 2.688 0 3.848-2.339 4.695-4.566 4.943.359.309.678.92.678 1.855 0 1.338-.012 2.419-.012 2.747 0 .268.18.58.688.482A10.019 10.019 0 0022 12.017C22 6.484 17.522 2 12 2z"})}),i.jsx("a",{href:"https://github.com/alicomert/pixcode",target:"_blank",rel:"noopener noreferrer",className:"text-xs text-muted-foreground/50 transition-colors hover:text-muted-foreground",children:"Pixcode is open source"})]})]})})})}const wO={username:"",password:""};function kO(){const{t:e}=Fe("auth"),{login:t}=Hl(),[n,r]=m.useState(wO),[a,s]=m.useState(""),[o,l]=m.useState(!1),c=m.useCallback((u,p)=>{r(f=>({...f,[u]:p}))},[]),d=m.useCallback(async u=>{if(u.preventDefault(),s(""),!n.username.trim()||!n.password){s(e("login.errors.requiredFields"));return}l(!0);const p=await t(n.username.trim(),n.password);p.success||s(p.error),l(!1)},[n.password,n.username,t,e]);return i.jsx(hE,{title:e("login.title"),description:e("login.description"),footerText:"Enter your credentials to access Pixcode",children:i.jsxs("form",{onSubmit:d,className:"space-y-4",children:[i.jsx(Pi,{id:"username",label:e("login.username"),value:n.username,onChange:u=>c("username",u),placeholder:e("login.placeholders.username"),isDisabled:o,autoComplete:"username"}),i.jsx(Pi,{id:"password",label:e("login.password"),value:n.password,onChange:u=>c("password",u),placeholder:e("login.placeholders.password"),isDisabled:o,type:"password",autoComplete:"current-password"}),i.jsx(mE,{errorMessage:a}),i.jsx("button",{type:"submit",disabled:o,className:"w-full rounded-md bg-blue-600 px-4 py-2 font-medium text-white transition-colors duration-200 hover:bg-blue-700 disabled:bg-blue-400",children:e(o?"login.loading":"login.submit")})]})})}const SO={username:"",password:"",confirmPassword:"",connectionMode:"local",remoteUrl:"",remoteApiKey:""};function CO(e){return!e.username.trim()||!e.password||!e.confirmPassword?"Please fill in all fields.":e.username.trim().length<3?"Username must be at least 3 characters long.":e.password.length<6?"Password must be at least 6 characters long.":e.password!==e.confirmPassword?"Passwords do not match.":e.connectionMode==="remote"&&!e.remoteUrl.trim()?"Remote Pixcode server URL is required.":null}function EO(){const{register:e}=Hl(),[t,n]=m.useState(SO),[r,a]=m.useState(""),[s,o]=m.useState(!1),l=m.useCallback((d,u)=>{n(p=>({...p,[d]:u}))},[]),c=m.useCallback(async d=>{d.preventDefault(),a("");const u=CO(t);if(u){a(u);return}o(!0);const p=await fetch("/api/auth/connection-mode",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({mode:t.connectionMode,remoteUrl:t.connectionMode==="remote"?t.remoteUrl.trim():null,apiKey:t.connectionMode==="remote"?t.remoteApiKey.trim():null})});if(!p.ok){const h=await p.json().catch(()=>null);a(h?.error||"Could not save connection mode."),o(!1);return}const f=await e(t.username.trim(),t.password);f.success||a(f.error),o(!1)},[t,e]);return i.jsx(hE,{title:"Welcome to Pixcode",description:"Create the first admin account to get started",footerText:"The first account becomes admin and can add more users later.",logo:i.jsx("img",{src:"/logo.svg",alt:"Pixcode",className:"h-16 w-16"}),children:i.jsxs("form",{onSubmit:c,className:"space-y-4",children:[i.jsxs("div",{className:"grid gap-2 rounded-lg border border-border/70 bg-muted/30 p-2 sm:grid-cols-2",children:[i.jsxs("button",{type:"button",onClick:()=>l("connectionMode","local"),disabled:s,className:`rounded-md px-3 py-2 text-left text-sm transition-colors ${t.connectionMode==="local"?"bg-background text-foreground shadow-sm":"text-muted-foreground hover:bg-background/60 hover:text-foreground"}`,children:[i.jsx("span",{className:"block font-medium",children:"Use this computer directly"}),i.jsx("span",{className:"block text-xs opacity-80",children:"Run Pixcode and CLIs on this machine."})]}),i.jsxs("button",{type:"button",onClick:()=>l("connectionMode","remote"),disabled:s,className:`rounded-md px-3 py-2 text-left text-sm transition-colors ${t.connectionMode==="remote"?"bg-background text-foreground shadow-sm":"text-muted-foreground hover:bg-background/60 hover:text-foreground"}`,children:[i.jsx("span",{className:"block font-medium",children:"Connect to a remote Pixcode server"}),i.jsx("span",{className:"block text-xs opacity-80",children:"Control another always-on Pixcode host by API."})]})]}),t.connectionMode==="remote"&&i.jsxs("div",{className:"space-y-3 rounded-lg border border-border/70 bg-muted/20 p-3",children:[i.jsx(Pi,{id:"remoteUrl",name:"remoteUrl",label:"Remote API URL",value:t.remoteUrl,onChange:d=>l("remoteUrl",d),placeholder:"https://your-server.example.com",isDisabled:s,autoComplete:"url"}),i.jsx(Pi,{id:"remoteApiKey",name:"remoteApiKey",label:"Remote API Key",value:t.remoteApiKey,onChange:d=>l("remoteApiKey",d),placeholder:"px_...",isDisabled:s,type:"password",autoComplete:"off"})]}),i.jsx(Pi,{id:"username",name:"username",label:"Username",value:t.username,onChange:d=>l("username",d),placeholder:"Enter your username",isDisabled:s,autoComplete:"username"}),i.jsx(Pi,{id:"password",name:"password",label:"Password",value:t.password,onChange:d=>l("password",d),placeholder:"Enter your password",isDisabled:s,type:"password",autoComplete:"new-password"}),i.jsx(Pi,{id:"confirmPassword",name:"confirmPassword",label:"Confirm Password",value:t.confirmPassword,onChange:d=>l("confirmPassword",d),placeholder:"Confirm your password",isDisabled:s,type:"password",autoComplete:"new-password"}),i.jsx(mE,{errorMessage:r}),i.jsx("button",{type:"submit",disabled:s,className:"w-full rounded-md bg-blue-600 px-4 py-2 font-medium text-white transition-colors duration-200 hover:bg-blue-700 disabled:bg-blue-400",children:s?"Setting up...":"Create Account"})]})})}function NO({children:e}){const{user:t,isLoading:n,needsSetup:r,hasCompletedOnboarding:a,refreshOnboardingStatus:s}=Hl();return n?i.jsx(yO,{}):r?i.jsx(EO,{}):t?a?i.jsx(i.Fragment,{children:e}):i.jsx(xO,{onComplete:s}):i.jsx(kO,{})}const fE=m.createContext(null),gE=()=>{const e=m.useContext(fE);if(!e)throw new Error("useWebSocket must be used within a WebSocketProvider");return e},TO=e=>{const t=window.location.protocol==="https:"?"wss:":"ws:";return e?`${t}//${window.location.host}/ws?token=${encodeURIComponent(e)}`:null},AO=()=>{const e=m.useRef(null),t=m.useRef(!1),n=m.useRef(!1),[r,a]=m.useState(null),[s,o]=m.useState(!1),l=m.useRef(null),{token:c}=Hl(),d=m.useCallback(()=>{if(!t.current)try{const f=TO(c);if(!f)return console.warn("No authentication token found for WebSocket connection");const h=new WebSocket(f);h.onopen=()=>{o(!0),e.current=h,n.current&&a({type:"websocket-reconnected",timestamp:Date.now()}),n.current=!0},h.onmessage=g=>{try{const b=JSON.parse(g.data);a(b)}catch(b){console.error("Error parsing WebSocket message:",b)}},h.onclose=()=>{o(!1),e.current=null,l.current=setTimeout(()=>{t.current||d()},3e3)},h.onerror=g=>{console.error("WebSocket error:",g)}}catch(f){console.error("Error creating WebSocket connection:",f)}},[c]);m.useEffect(()=>(d(),()=>{t.current=!0,l.current&&clearTimeout(l.current),e.current&&e.current.close()}),[d]);const u=m.useCallback(f=>{const h=e.current;h&&h.readyState===WebSocket.OPEN?h.send(JSON.stringify(f)):console.warn("WebSocket not connected")},[]);return m.useMemo(()=>({ws:e.current,sendMessage:u,latestMessage:r,isConnected:s}),[u,r,s])},jO=({children:e})=>{const t=AO();return i.jsx(fE.Provider,{value:t,children:e})},bE=m.createContext(null);function ql(){const e=m.useContext(bE);if(!e)throw new Error("usePlugins must be used within a PluginsProvider");return e}function RO({children:e}){const{user:t,token:n,isLoading:r}=Hl(),[a,s]=m.useState([]),[o,l]=m.useState(!0),[c,d]=m.useState(null),u=!!(t&&n),p=m.useCallback(async()=>{if(!u){s([]),d(null),l(!1);return}l(!0);try{const x=await Ee("/api/plugins");if(x.ok){const v=await x.json();s(v.plugins||[]),d(null)}else{let v=`Failed to fetch plugins (${x.status})`;try{const y=await x.json();v=y.details||y.error||v}catch{v=x.statusText||v}d(v)}}catch(x){const v=x instanceof Error?x.message:"Failed to fetch plugins";d(v),console.error("[Plugins] Failed to fetch plugins:",x)}finally{l(!1)}},[u]);m.useEffect(()=>{r||p()},[r,p]);const f=m.useCallback(async x=>{try{const v=await Ee("/api/plugins/install",{method:"POST",body:JSON.stringify({url:x})}),y=await v.json();return v.ok?(await p(),{success:!0}):{success:!1,error:y.details||y.error||"Install failed"}}catch(v){return{success:!1,error:v instanceof Error?v.message:"Install failed"}}},[p]),h=m.useCallback(async x=>{try{const v=await Ee(`/api/plugins/${encodeURIComponent(x)}`,{method:"DELETE"}),y=await v.json();return v.ok?(await p(),{success:!0}):{success:!1,error:y.details||y.error||"Uninstall failed"}}catch(v){return{success:!1,error:v instanceof Error?v.message:"Uninstall failed"}}},[p]),g=m.useCallback(async x=>{try{const v=await Ee(`/api/plugins/${encodeURIComponent(x)}/update`,{method:"POST"}),y=await v.json();return v.ok?(await p(),{success:!0}):{success:!1,error:y.details||y.error||"Update failed"}}catch(v){return{success:!1,error:v instanceof Error?v.message:"Update failed"}}},[p]),b=m.useCallback(async(x,v)=>{try{const y=await Ee(`/api/plugins/${encodeURIComponent(x)}/enable`,{method:"PUT",body:JSON.stringify({enabled:v})});if(!y.ok){let w=`Toggle failed (${y.status})`;try{const k=await y.json();w=k.details||k.error||w}catch{w=y.statusText||w}return{success:!1,error:w}}return await p(),{success:!0,error:null}}catch(y){return{success:!1,error:y instanceof Error?y.message:"Toggle failed"}}},[p]);return i.jsx(bE.Provider,{value:{plugins:a,loading:o,pluginsError:c,refreshPlugins:p,installPlugin:f,uninstallPlugin:h,updatePlugin:g,togglePlugin:b},children:e})}const Fw=e=>typeof window>"u"?!1:window.innerWidth<e,zw=()=>{if(typeof window>"u")return!1;const e=window.navigator;return window.matchMedia("(display-mode: standalone)").matches||!!e.standalone||document.referrer.includes("android-app://")};function wu(e={}){const{mobileBreakpoint:t=768,trackMobile:n=!0,trackPWA:r=!0}=e,[a,s]=m.useState(()=>n?Fw(t):!1),[o,l]=m.useState(()=>r?zw():!1);return m.useEffect(()=>{if(!n||typeof window>"u")return;const c=()=>{s(Fw(t))};return c(),window.addEventListener("resize",c),()=>{window.removeEventListener("resize",c)}},[t,n]),m.useEffect(()=>{if(!r||typeof window>"u")return;const c=window.matchMedia("(display-mode: standalone)"),d=()=>{l(zw())};return d(),typeof c.addEventListener=="function"?(c.addEventListener("change",d),()=>{c.removeEventListener("change",d)}):(c.addListener(d),()=>{c.removeListener(d)})},[r]),{isMobile:a,isPWA:o}}const sg="pixcode.updateCheck.preferences",Dh="pixcode:update-check-settings-changed",og=[{value:"30m",label:"Every 30 minutes",intervalMs:1800*1e3},{value:"24h",label:"Daily",intervalMs:1440*60*1e3},{value:"12h",label:"Every 12 hours",intervalMs:720*60*1e3},{value:"6h",label:"Every 6 hours",intervalMs:360*60*1e3},{value:"7d",label:"Weekly",intervalMs:10080*60*1e3},{value:"off",label:"Manual only",intervalMs:null}],Oh={frequency:"30m"};function Bw(e){return og.find(t=>t.value===e.frequency)?.intervalMs??null}function xE(e){if(!e||typeof e!="object")return Oh;const t=e.frequency;return og.some(n=>n.value===t)?{frequency:t}:Oh}function Uw(){try{const e=localStorage.getItem(sg);return xE(e?JSON.parse(e):null)}catch{return Oh}}function _O(e){const t=xE(e);localStorage.setItem(sg,JSON.stringify(t)),window.dispatchEvent(new CustomEvent(Dh,{detail:t}))}const vp=(e,t)=>{const n=e.split(".").map(Number),r=t.split(".").map(Number);for(let a=0;a<Math.max(n.length,r.length);a++){const s=n[a]||0,o=r[a]||0;if(s!==o)return s-o}return 0},IO="1.54.4",jd="pixcode:update-available",LO=360*60*1e3,yp=new Map;function vE(e,t){return`pixcode.updateCheck.cache.${e}.${t}`}function PO(e,t){try{const n=localStorage.getItem(vE(e,t));if(!n)return null;const r=JSON.parse(n);return{fetchedAt:typeof r.fetchedAt=="number"?r.fetchedAt:null,latestVersion:typeof r.latestVersion=="string"?r.latestVersion:null,releaseInfo:r.releaseInfo??null,rateLimitedUntil:typeof r.rateLimitedUntil=="number"?r.rateLimitedUntil:void 0}}catch{return null}}function $w(e,t,n){localStorage.setItem(vE(e,t),JSON.stringify(n))}function DO(e,t){const n=`${e}/${t}`,r=yp.get(n);if(r)return r;const a=fetch(`https://api.github.com/repos/${e}/${t}/releases/latest`,{cache:"no-store",headers:{Accept:"application/vnd.github+json"}}).then(async s=>({status:s.status,ok:s.ok,data:await s.json().catch(()=>({}))})).finally(()=>{yp.delete(n)});return yp.set(n,a),a}const lg=(e,t)=>{const[n,r]=m.useState(!1),[a,s]=m.useState(null),[o,l]=m.useState(null),[c,d]=m.useState("git"),[u,p]=m.useState("idle"),[f,h]=m.useState(null),[g,b]=m.useState(()=>Uw()),[x,v]=m.useState(IO),y=m.useRef(null),w=m.useCallback(S=>{_O(S),b(S)},[]);m.useEffect(()=>{const S=()=>b(Uw()),C=N=>{N.key===sg&&S()};return window.addEventListener("storage",C),window.addEventListener(Dh,S),()=>{window.removeEventListener("storage",C),window.removeEventListener(Dh,S)}},[]),m.useEffect(()=>{let S=!1;const C=async()=>{try{const A=await(await fetch("/health",{cache:"no-store"})).json();if(S)return;(A.installMode==="npm"||A.installMode==="git")&&d(A.installMode),typeof A.version=="string"&&/^\d+\.\d+\.\d+/.test(A.version)&&v(A.version)}catch{}};C();const N=()=>{C()};return window.addEventListener("focus",N),()=>{S=!0,window.removeEventListener("focus",N)}},[]),m.useEffect(()=>{if(!x)return;let S=!1;const C=(T,_,E,O)=>({updateAvailable:!!(T&&vp(T,x)>0),latestVersion:T,releaseInfo:_,currentVersion:x,checkedAt:E,status:O}),N=T=>{!T.updateAvailable||!T.latestVersion||!T.releaseInfo||window.dispatchEvent(new CustomEvent(jd,{detail:T}))},R=(T,_,E,O="success")=>{if(!T||!_)return r(!1),s(null),l(null),h(E),C(null,null,E,O);s(T),r(vp(T,x)>0),l(_),h(E);const $=C(T,_,E,O);return N($),$},A=async({force:T=!1}={})=>{const _=Bw(g),E=PO(e,t),O=Date.now();if(!T&&_===null)return p("idle"),R(E?.latestVersion??null,E?.releaseInfo??null,E?.fetchedAt??null,"idle");if(!T&&E?.fetchedAt&&_!==null&&O-E.fetchedAt<_)return p("success"),R(E.latestVersion,E.releaseInfo,E.fetchedAt,"success");if(!T&&E?.rateLimitedUntil&&E.rateLimitedUntil>O)return p("error"),R(E.latestVersion,E.releaseInfo,E.fetchedAt,"error");try{p("checking");const $=await DO(e,t);if(S)return C(E?.latestVersion??null,E?.releaseInfo??null,E?.fetchedAt??null,"idle");const B=$.data;if(!$.ok)return $.status===403&&$w(e,t,{fetchedAt:E?.fetchedAt??null,latestVersion:E?.latestVersion??null,releaseInfo:E?.releaseInfo??null,rateLimitedUntil:O+Math.max(_??0,LO)}),p("error"),R(E?.latestVersion??null,E?.releaseInfo??null,E?.fetchedAt??null,"error");if(B.tag_name){const K=B.tag_name.replace(/^v/,""),Y=vp(K,x)>0,P={title:B.name||B.tag_name,body:B.body||"",htmlUrl:B.html_url||`https://github.com/${e}/${t}/releases/latest`,publishedAt:B.published_at||""};$w(e,t,{fetchedAt:O,latestVersion:K,releaseInfo:P}),s(K),r(Y),Y&&b4({key:`app-update:${K}`,title:"Pixcode update available",body:`Pixcode ${x} can update to ${K}.`,tag:"pixcode-app-update",data:{type:"app-update",latestVersion:K,installMode:c}}),l(P),p("success"),h(O);const z=C(K,P,O,"success");return N(z),z}else return r(!1),s(null),l(null),p("error"),C(null,null,null,"error")}catch($){return console.error("Version check failed:",$),p("error"),R(E?.latestVersion??null,E?.releaseInfo??null,E?.fetchedAt??null,"error")}};y.current=A,A();const j=Bw(g),L=j===null?null:window.setInterval(()=>{A()},j);return()=>{S=!0,L!==null&&window.clearInterval(L)}},[e,t,x,c,g]);const k=m.useCallback(async()=>y.current?await y.current({force:!0}):null,[]);return{updateAvailable:n,latestVersion:a,currentVersion:x,releaseInfo:o,installMode:c,checkStatus:u,lastCheckedAt:f,manualCheck:k,updateCheckPreferences:g,updatePreferences:w}},Di={autoExpandTools:!1,showRawParameters:!1,showThinking:!0,autoScrollToBottom:!0,sendByCtrlEnter:!1,changeAwareness:!1,sidebarVisible:!0,historyView:"flat",autoShowAgentDiff:"always"},OO=["flat","grouped"],MO=e=>typeof e=="string"&&OO.includes(e),FO=["always","openOnly","off"],zO=e=>typeof e=="string"&&FO.includes(e),Rd=Object.keys(Di),BO=new Set(Rd),wp="ui-preferences:sync",UO=(e,t)=>{if(typeof e=="boolean")return e;if(typeof e=="string"){if(e==="true")return!0;if(e==="false")return!1}return t},_d=(e,t,n)=>e==="historyView"?MO(t)?t:n:e==="autoShowAgentDiff"?zO(t)?t:n:UO(t,n),$O=(e,t)=>{try{const n=localStorage.getItem(e);if(n===null)return t;const r=JSON.parse(n);return _d(e,r,t)}catch{return t}},HO=e=>{if(typeof window>"u")return Di;try{const t=localStorage.getItem(e);if(t){const n=JSON.parse(t);if(n&&typeof n=="object"&&!Array.isArray(n)){const r=n;return Rd.reduce((a,s)=>(a[s]=_d(s,r[s],Di[s]),a),{...Di})}}}catch{}return Rd.reduce((t,n)=>(t[n]=$O(n,Di[n]),t),{...Di})};function GO(e,t){switch(t.type){case"set":{const{key:n,value:r}=t;if(!BO.has(n))return e;const a=_d(n,r,e[n]);return e[n]===a?e:{...e,[n]:a}}case"set_many":{const n=t.value||{};let r=!1;const a={...e};for(const s of Rd){if(!(s in n))continue;const o=n[s],l=_d(s,o,e[s]);a[s]!==l&&(a[s]=l,r=!0)}return r?a:e}case"reset":return{...Di,...t.value||{}};default:return e}}function ku(e="uiPreferences"){const t=m.useRef(`ui-preferences-${Math.random().toString(36).slice(2)}`),[n,r]=m.useReducer(GO,e,HO);return m.useEffect(()=>{typeof window>"u"||(localStorage.setItem(e,JSON.stringify(n)),window.dispatchEvent(new CustomEvent(wp,{detail:{storageKey:e,sourceId:t.current,value:n}})))},[n,e]),m.useEffect(()=>{if(typeof window>"u")return;const l=u=>{!u||typeof u!="object"||Array.isArray(u)||r({type:"set_many",value:u})},c=u=>{if(!(u.key!==e||u.newValue===null))try{const p=JSON.parse(u.newValue);l(p)}catch{}},d=u=>{const f=u.detail;!f||f.storageKey!==e||f.sourceId===t.current||l(f.value)};return window.addEventListener("storage",c),window.addEventListener(wp,d),()=>{window.removeEventListener("storage",c),window.removeEventListener(wp,d)}},[e]),{preferences:n,setPreference:(l,c)=>{r({type:"set",key:l,value:c})},setPreferences:l=>{r({type:"set_many",value:l})},resetPreferences:l=>{r({type:"reset",value:l})},dispatch:r}}const WO=()=>{try{const e=localStorage.getItem("claude-settings");return e&&JSON.parse(e).projectSortOrder==="date"?"date":"name"}catch{return"name"}},VO=()=>{try{const e=localStorage.getItem("starredProjects");return e?new Set(JSON.parse(e)):new Set}catch{return new Set}},qO=e=>{try{localStorage.setItem("starredProjects",JSON.stringify([...e]))}catch{}},Hw=(e,t)=>`${e}::${t}`,KO=()=>{try{const e=localStorage.getItem("starredSessions");return e?new Set(JSON.parse(e)):new Set}catch{return new Set}},YO=e=>{try{localStorage.setItem("starredSessions",JSON.stringify([...e]))}catch{}},ZO=/(?:^|[\s/\\(\[`"'])([\w./-]+?\.(?:ts|tsx|js|jsx|mjs|cjs|py|rb|go|rs|java|kt|swift|c|cc|cpp|h|hpp|cs|php|sh|bash|zsh|json|ya?ml|toml|md|mdx|html?|css|scss|less|sql|prisma|graphql|gql|vue|svelte|astro|dart|lua|r|pl|ps1|tf|dockerfile|env))(?:$|[\s:,)\]`"'])/i,XO=e=>{if(!e)return[];const t=new Set,n=new RegExp(ZO.source,"gi");let r;for(;(r=n.exec(e))!==null;){const a=r[1],s=a.lastIndexOf(".");if(s>-1){const o=a.slice(s+1).toLowerCase();o&&o.length<=10&&t.add(o)}if(t.size>=3)break}return[...t]},Ui=e=>e.__provider==="cursor"?new Date(e.createdAt||0):e.__provider==="codex"?new Date(e.createdAt||e.lastActivity||0):new Date(e.lastActivity||e.createdAt||0),QO=(e,t)=>e.__provider==="cursor"?e.summary||e.name||t("projects.untitledSession"):e.__provider==="codex"?e.summary||e.name||t("projects.codexSession"):e.__provider==="gemini"||e.__provider==="qwen"||e.__provider==="opencode"?e.summary||e.name||t("projects.newSession"):e.summary||t("projects.newSession"),JO=e=>e.__provider==="cursor"?String(e.createdAt||""):e.__provider==="codex"?String(e.createdAt||e.lastActivity||""):String(e.lastActivity||e.createdAt||""),eM=(e,t,n)=>{const r=Ui(e),a=Math.floor((t.getTime()-r.getTime())/(1e3*60));return{isCursorSession:e.__provider==="cursor",isCodexSession:e.__provider==="codex",isGeminiSession:e.__provider==="gemini",isQwenSession:e.__provider==="qwen",isOpencodeSession:e.__provider==="opencode",isActive:a<10,sessionName:QO(e,n),sessionTime:JO(e),messageCount:Number(e.messageCount||0)}},yE=(e,t)=>{const n=[...e.sessions||[],...t[e.name]||[]].map(g=>({...g,__provider:"claude"})),r=(e.cursorSessions||[]).map(g=>({...g,__provider:"cursor"})),a=(e.codexSessions||[]).map(g=>({...g,__provider:"codex"})),s=g=>typeof g.id=="string"&&g.id.startsWith("qwen_")||g.provider==="qwen",o=g=>typeof g.id=="string"&&g.id.startsWith("opencode_")||g.provider==="opencode",l=e.geminiSessions||[],c=l.filter(g=>!s(g)&&!o(g)).map(g=>({...g,__provider:"gemini"})),d=l.filter(g=>s(g)).map(g=>({...g,__provider:"qwen"})),u=l.filter(g=>o(g)).map(g=>({...g,__provider:"opencode"})),p=[...(e.qwenSessions||[]).map(g=>({...g,__provider:"qwen"})),...d],f=[...(e.opencodeSessions||[]).map(g=>({...g,__provider:"opencode"})),...u],h=new Map;for(const g of[...n,...r,...a,...c,...p,...f])h.has(g.id)||h.set(g.id,g);return[...h.values()].sort((g,b)=>Ui(b).getTime()-Ui(g).getTime())},Gw=(e,t)=>{const n=yE(e,t);return n.length===0?new Date(0):n.reduce((r,a)=>{const s=Ui(a);return s>r?s:r},new Date(0))},tM=(e,t,n,r)=>{const a=[...e];return a.sort((s,o)=>{const l=n.has(s.name),c=n.has(o.name);return l&&!c?-1:!l&&c?1:t==="date"?Gw(o,r).getTime()-Gw(s,r).getTime():(s.displayName||s.name).localeCompare(o.displayName||o.name)}),a},nM=(e,t)=>{const n=t.trim().toLowerCase();return n?e.filter(r=>{const a=(r.displayName||r.name).toLowerCase(),s=r.name.toLowerCase();return a.includes(n)||s.includes(n)}):e},rM=e=>{const t=typeof e.fullPath=="string"&&e.fullPath.length>0?e.fullPath:typeof e.path=="string"?e.path:"";return{name:e.name,displayName:typeof e.displayName=="string"&&e.displayName.trim().length>0?e.displayName:e.name,fullPath:t,path:typeof e.path=="string"&&e.path.length>0?e.path:t}};function aM({projects:e,selectedProject:t,selectedSession:n,isLoading:r,isMobile:a,t:s,onRefresh:o,onProjectSelect:l,onSessionSelect:c,onSessionDelete:d,onProjectDelete:u,setSidebarVisible:p,sidebarVisible:f}){const[h,g]=m.useState(new Set),[b,x]=m.useState(null),[v,y]=m.useState(!1),[w,k]=m.useState(""),[S,C]=m.useState({}),[N,R]=m.useState({}),[A,j]=m.useState(new Set),[L,T]=m.useState(new Date),[_,E]=m.useState("name"),[O,$]=m.useState(!1),[B,K]=m.useState({}),[Y,P]=m.useState(null),[z,U]=m.useState(""),[F,J]=m.useState(""),[ae,Q]=m.useState(new Set),[pe,oe]=m.useState(null),[fe,be]=m.useState(null),[Ce,Se]=m.useState(!1),[Te,M]=m.useState(()=>VO()),[de,ce]=m.useState(()=>KO()),[V,Z]=m.useState("projects"),[se,ge]=m.useState(null),[ee,te]=m.useState(!1),[ve,le]=m.useState(null),W=m.useRef(null),G=m.useRef(0),ne=m.useRef(null),he=!a&&!f;m.useEffect(()=>{const Oe=setInterval(()=>{T(new Date)},6e4);return()=>clearInterval(Oe)},[]),m.useEffect(()=>{R({}),j(new Set),K({})},[e]),m.useEffect(()=>{t&&g(Oe=>{if(Oe.has(t.name))return Oe;const qe=new Set(Oe);return qe.add(t.name),qe})},[n,t]),m.useEffect(()=>{if(e.length>0&&!r){const Oe=new Set;e.forEach(qe=>{qe.sessions&&qe.sessions.length>=0&&Oe.add(qe.name)}),j(Oe)}},[e,r]),m.useEffect(()=>{const Oe=()=>{E(WO())};Oe();const qe=Qe=>{Qe.key==="claude-settings"&&Oe()},lt=()=>Oe();return window.addEventListener("storage",qe),window.addEventListener("pixcode:settings-changed",lt),()=>{window.removeEventListener("storage",qe),window.removeEventListener("pixcode:settings-changed",lt)}},[]),m.useEffect(()=>{W.current&&clearTimeout(W.current),ne.current&&(ne.current.close(),ne.current=null);const Oe=F.trim();if(V!=="conversations"||Oe.length<2){G.current+=1,ge(null),le(null),te(!1);return}te(!0);const qe=++G.current;return W.current=setTimeout(()=>{if(qe!==G.current)return;const lt=Tt.searchConversationsUrl(Oe),Qe=new EventSource(lt);ne.current=Qe;const xe=[];let De=0;Qe.addEventListener("result",we=>{if(qe!==G.current){Qe.close();return}try{const ke=JSON.parse(we.data);xe.push(ke.projectResult),De=ke.totalMatches,ge({results:[...xe],totalMatches:De,query:Oe}),le({scannedProjects:ke.scannedProjects,totalProjects:ke.totalProjects})}catch{}}),Qe.addEventListener("progress",we=>{if(qe!==G.current){Qe.close();return}try{const ke=JSON.parse(we.data);De=ke.totalMatches,le({scannedProjects:ke.scannedProjects,totalProjects:ke.totalProjects})}catch{}}),Qe.addEventListener("done",()=>{if(qe!==G.current){Qe.close();return}Qe.close(),ne.current=null,te(!1),le(null),xe.length===0&&ge({results:[],totalMatches:0,query:Oe})}),Qe.addEventListener("error",()=>{if(qe!==G.current){Qe.close();return}Qe.close(),ne.current=null,te(!1),le(null),xe.length===0&&ge({results:[],totalMatches:0,query:Oe})})},400),()=>{W.current&&clearTimeout(W.current),ne.current&&(ne.current.close(),ne.current=null)}},[F,V]);const Pe=m.useCallback(Oe=>{g(qe=>{const lt=new Set;return qe.has(Oe)||lt.add(Oe),lt})},[]),ze=m.useCallback((Oe,qe)=>{c({...Oe,__projectName:qe})},[c]),Ke=m.useCallback(Oe=>{M(qe=>{const lt=new Set(qe);return lt.has(Oe)?lt.delete(Oe):lt.add(Oe),qO(lt),lt})},[]),St=m.useCallback(Oe=>Te.has(Oe),[Te]),Je=m.useCallback((Oe,qe)=>{ce(lt=>{const Qe=Hw(Oe,qe),xe=new Set(lt);return xe.has(Qe)?xe.delete(Qe):xe.add(Qe),YO(xe),xe})},[]),bt=m.useCallback((Oe,qe)=>de.has(Hw(Oe,qe)),[de]),ft=m.useCallback(Oe=>yE(Oe,N),[N]),ot=m.useMemo(()=>e.map(Oe=>{const qe=B[Oe.name];return qe===void 0?Oe:{...Oe,sessionMeta:{...Oe.sessionMeta,hasMore:qe}}}),[B,e]),xt=m.useMemo(()=>tM(ot,_,Te,N),[N,_,ot,Te]),At=m.useMemo(()=>nM(xt,F),[F,xt]),Wt=m.useCallback(Oe=>{x(Oe.name),k(Oe.displayName)},[]),It=m.useCallback(()=>{x(null),k("")},[]),jn=m.useCallback(async Oe=>{try{(await Tt.renameProject(Oe,w)).ok?window.refreshProjects?await window.refreshProjects():window.location.reload():console.error("Failed to rename project")}catch(qe){console.error("Error renaming project:",qe)}finally{x(null),k("")}},[w]),He=m.useCallback((Oe,qe,lt,Qe="claude")=>{be({projectName:Oe,sessionId:qe,sessionTitle:lt,provider:Qe})},[]),it=m.useCallback(async()=>{if(!fe)return;const{projectName:Oe,sessionId:qe,provider:lt}=fe;be(null);try{let Qe;if(lt==="codex"?Qe=await Tt.deleteCodexSession(qe):lt==="gemini"?Qe=await Tt.deleteGeminiSession(qe):lt==="qwen"?Qe=await Tt.deleteQwenSession(qe):Qe=await Tt.deleteSession(Oe,qe),Qe.ok)d?.(qe);else{const xe=await Qe.text();console.error("[Sidebar] Failed to delete session:",{status:Qe.status,error:xe}),alert(s("messages.deleteSessionFailed"))}}catch(Qe){console.error("[Sidebar] Error deleting session:",Qe),alert(s("messages.deleteSessionError"))}},[d,fe,s]),vt=m.useCallback(Oe=>{oe({project:Oe,sessionCount:ft(Oe).length})},[ft]),Re=m.useCallback(async(Oe=!1)=>{if(!pe)return;const{project:qe,sessionCount:lt}=pe,Qe=lt===0;oe(null),Q(xe=>new Set([...xe,qe.name]));try{const xe=await Tt.deleteProject(qe.name,!Qe,Oe);if(xe.ok)u?.(qe.name);else{const De=await xe.json();alert(De.error||s("messages.deleteProjectFailed"))}}catch(xe){console.error("Error deleting project:",xe),alert(s("messages.deleteProjectError"))}finally{Q(xe=>{const De=new Set(xe);return De.delete(qe.name),De})}},[pe,u,s]),Ge=m.useCallback(async Oe=>{const qe=B[Oe.name];if(!(!(qe!==void 0?qe:Oe.sessionMeta?.hasMore===!0)||S[Oe.name])){C(Qe=>({...Qe,[Oe.name]:!0}));try{const Qe=(Oe.sessions?.length||0)+(N[Oe.name]?.length||0),xe=await Tt.sessions(Oe.name,5,Qe);if(!xe.ok)return;const De=await xe.json();R(we=>({...we,[Oe.name]:[...we[Oe.name]||[],...De.sessions||[]]})),De.hasMore===!1&&K(we=>({...we,[Oe.name]:!1}))}catch(Qe){console.error("Error loading more sessions:",Qe)}finally{C(Qe=>({...Qe,[Oe.name]:!1}))}}},[N,S,B]),Ye=m.useCallback(Oe=>{l(Oe)},[l]),Nt=m.useCallback(async()=>{$(!0);try{await o()}finally{$(!1)}},[o]),Lt=m.useCallback(async(Oe,qe,lt,Qe)=>{const xe=lt.trim();if(!xe){P(null),U("");return}try{const De=await Tt.renameSession(qe,xe,Qe);De.ok?await o():(console.error("[Sidebar] Failed to rename session:",De.status),alert(s("messages.renameSessionFailed")))}catch(De){console.error("[Sidebar] Error renaming session:",De),alert(s("messages.renameSessionError"))}finally{P(null),U("")}},[o,s]),wt=m.useCallback(()=>{p(!1)},[p]),Tr=m.useCallback(()=>{p(!0)},[p]);return{isSidebarCollapsed:he,expandedProjects:h,editingProject:b,showNewProject:v,editingName:w,loadingSessions:S,additionalSessions:N,initialSessionsLoaded:A,currentTime:L,projectSortOrder:_,isRefreshing:O,editingSession:Y,editingSessionName:z,searchFilter:F,deletingProjects:ae,deleteConfirmation:pe,sessionDeleteConfirmation:fe,showVersionModal:Ce,starredProjects:Te,starredSessions:de,filteredProjects:At,toggleProject:Pe,handleSessionClick:ze,toggleStarProject:Ke,isProjectStarred:St,toggleStarSession:Je,isSessionStarred:bt,getProjectSessions:ft,startEditing:Wt,cancelEditing:It,saveProjectName:jn,showDeleteSessionConfirmation:He,confirmDeleteSession:it,requestProjectDelete:vt,confirmDeleteProject:Re,loadMoreSessions:Ge,handleProjectSelect:Ye,refreshProjects:Nt,updateSessionSummary:Lt,collapseSidebar:wt,expandSidebar:Tr,setShowNewProject:y,setEditingName:k,setEditingSession:P,setEditingSessionName:U,searchMode:V,setSearchMode:Z,conversationResults:se,isSearching:ee,searchProgress:ve,clearConversationResults:m.useCallback(()=>{G.current+=1,ne.current&&(ne.current.close(),ne.current=null),te(!1),le(null),ge(null)},[]),setSearchFilter:J,setDeleteConfirmation:oe,setSessionDeleteConfirmation:be,setShowVersionModal:Se}}const iM="https://discord.gg/buxwujPNRE",sM="https://github.com/alicomert/pixcode/issues/new";function oM({className:e}){return i.jsx("svg",{className:e,fill:"currentColor",viewBox:"0 0 24 24","aria-hidden":"true",children:i.jsx("path",{d:"M20.317 4.37a19.791 19.791 0 0 0-4.885-1.515.074.074 0 0 0-.079.037c-.21.375-.444.864-.608 1.25a18.27 18.27 0 0 0-5.487 0 12.64 12.64 0 0 0-.617-1.25.077.077 0 0 0-.079-.037A19.736 19.736 0 0 0 3.677 4.37a.07.07 0 0 0-.032.027C.533 9.046-.32 13.58.099 18.057a.082.082 0 0 0 .031.057 19.9 19.9 0 0 0 5.993 3.03.078.078 0 0 0 .084-.028c.462-.63.874-1.295 1.226-1.994a.076.076 0 0 0-.041-.106 13.107 13.107 0 0 1-1.872-.892.077.077 0 0 1-.008-.128 10.2 10.2 0 0 0 .372-.292.074.074 0 0 1 .077-.01c3.928 1.793 8.18 1.793 12.062 0a.074.074 0 0 1 .078.01c.12.098.246.198.373.292a.077.077 0 0 1-.006.127 12.299 12.299 0 0 1-1.873.892.077.077 0 0 0-.041.107c.36.698.772 1.362 1.225 1.993a.076.076 0 0 0 .084.028 19.839 19.839 0 0 0 6.002-3.03.077.077 0 0 0 .032-.054c.5-5.177-.838-9.674-3.549-13.66a.061.061 0 0 0-.031-.03zM8.02 15.33c-1.183 0-2.157-1.085-2.157-2.419 0-1.333.956-2.419 2.157-2.419 1.21 0 2.176 1.095 2.157 2.42 0 1.333-.956 2.418-2.157 2.418zm7.975 0c-1.183 0-2.157-1.085-2.157-2.419 0-1.333.955-2.419 2.157-2.419 1.21 0 2.176 1.095 2.157 2.42 0 1.333-.946 2.418-2.157 2.418z"})})}function lM({onExpand:e,onOpenControlRoom:t,onShowSettings:n,updateAvailable:r,onShowVersionModal:a,t:s}){return i.jsxs("div",{className:"flex h-full w-12 flex-col items-center gap-1 bg-background/80 py-3 backdrop-blur-sm",children:[i.jsx("button",{onClick:e,className:"group flex h-8 w-8 items-center justify-center rounded-lg transition-colors hover:bg-accent/80","aria-label":s("common:versionUpdate.ariaLabels.showSidebar"),title:s("common:versionUpdate.ariaLabels.showSidebar"),children:i.jsx(hu,{className:"h-4 w-4 text-muted-foreground transition-colors group-hover:text-foreground"})}),i.jsx("div",{className:"nav-divider my-1 w-6"}),t&&i.jsx("button",{onClick:t,className:"group flex h-8 w-8 items-center justify-center rounded-lg border border-primary/25 bg-primary/10 transition-colors hover:bg-primary/15","aria-label":s("actions.controlRoom",{defaultValue:"Control Room"}),title:s("actions.controlRoom",{defaultValue:"Control Room"}),children:i.jsx(Vn,{className:"h-4 w-4 text-primary"})}),i.jsx("button",{onClick:n,className:"group flex h-8 w-8 items-center justify-center rounded-lg transition-colors hover:bg-accent/80","aria-label":s("actions.settings"),title:s("actions.settings"),children:i.jsx(Pt,{className:"h-4 w-4 text-muted-foreground transition-colors group-hover:text-foreground"})}),i.jsx("a",{href:sM,target:"_blank",rel:"noopener noreferrer",className:"group flex h-8 w-8 items-center justify-center rounded-lg transition-colors hover:bg-accent/80","aria-label":s("actions.reportIssue"),title:s("actions.reportIssue"),children:i.jsx(Sl,{className:"h-4 w-4 text-muted-foreground transition-colors group-hover:text-foreground"})}),i.jsx("a",{href:iM,target:"_blank",rel:"noopener noreferrer",className:"group flex h-8 w-8 items-center justify-center rounded-lg transition-colors hover:bg-accent/80","aria-label":s("actions.joinCommunity"),title:s("actions.joinCommunity"),children:i.jsx(oM,{className:"h-4 w-4 text-muted-foreground transition-colors group-hover:text-foreground"})}),r&&i.jsxs("button",{onClick:a,className:"relative flex h-8 w-8 items-center justify-center rounded-lg transition-colors hover:bg-accent/80","aria-label":s("common:versionUpdate.ariaLabels.updateAvailable"),title:s("common:versionUpdate.ariaLabels.updateAvailable"),children:[i.jsx(Vn,{className:"h-4 w-4 text-blue-500"}),i.jsx("span",{className:"absolute right-1.5 top-1.5 h-1.5 w-1.5 animate-pulse rounded-full bg-blue-500"})]})]})}const Ww=e=>typeof e=="boolean"?`${e}`:e===0?"0":e,Vw=S4,cg=(e,t)=>n=>{var r;if(t?.variants==null)return Vw(e,n?.class,n?.className);const{variants:a,defaultVariants:s}=t,o=Object.keys(a).map(d=>{const u=n?.[d],p=s?.[d];if(u===null)return null;const f=Ww(u)||Ww(p);return a[d][f]}),l=n&&Object.entries(n).reduce((d,u)=>{let[p,f]=u;return f===void 0||(d[p]=f),d},{}),c=t==null||(r=t.compoundVariants)===null||r===void 0?void 0:r.reduce((d,u)=>{let{class:p,className:f,...h}=u;return Object.entries(h).every(g=>{let[b,x]=g;return Array.isArray(x)?x.includes({...s,...l}[b]):{...s,...l}[b]===x})?[...d,p,f]:d},[]);return Vw(e,o,c,n?.class,n?.className)},cM=cg("relative grid w-full grid-cols-[0_1fr] items-start gap-y-0.5 rounded-lg border px-4 py-3 text-sm has-[>svg]:grid-cols-[calc(var(--spacing)*4)_1fr] has-[>svg]:gap-x-3 [&>svg]:size-4 [&>svg]:translate-y-0.5 [&>svg]:text-current",{variants:{variant:{default:"bg-card text-card-foreground",destructive:"bg-card text-destructive *:data-[slot=alert-description]:text-destructive/90 [&>svg]:text-current"}},defaultVariants:{variant:"default"}}),wE=m.forwardRef(({className:e,variant:t,...n},r)=>i.jsx("div",{ref:r,role:"alert","data-slot":"alert",className:me(cM({variant:t}),e),...n}));wE.displayName="Alert";const dM=m.forwardRef(({className:e,...t},n)=>i.jsx("div",{ref:n,"data-slot":"alert-title",className:me("col-start-2 line-clamp-1 min-h-4 font-medium tracking-tight",e),...t}));dM.displayName="AlertTitle";const uM=m.forwardRef(({className:e,...t},n)=>i.jsx("div",{ref:n,"data-slot":"alert-description",className:me("text-muted-foreground col-start-2 grid justify-items-start gap-1 text-sm [&_p]:leading-relaxed",e),...t}));uM.displayName="AlertDescription";const pM=cg("inline-flex items-center rounded-md border px-2.5 py-0.5 text-xs font-semibold transition-colors focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2",{variants:{variant:{default:"border-transparent bg-primary text-primary-foreground shadow hover:bg-primary/80",secondary:"border-transparent bg-secondary text-secondary-foreground hover:bg-secondary/80",destructive:"border-transparent bg-destructive text-destructive-foreground shadow hover:bg-destructive/80",outline:"text-foreground"}},defaultVariants:{variant:"default"}});function hn({className:e,variant:t,...n}){return i.jsx("div",{className:me(pM({variant:t}),e),...n})}const mM=cg("inline-flex touch-manipulation items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0",{variants:{variant:{default:"bg-primary text-primary-foreground shadow hover:bg-primary/90 active:bg-primary/80",destructive:"bg-destructive text-destructive-foreground shadow-sm hover:bg-destructive/90 active:bg-destructive/80",outline:"border border-input bg-background shadow-sm hover:bg-accent hover:text-accent-foreground active:bg-accent/80",secondary:"bg-secondary text-secondary-foreground shadow-sm hover:bg-secondary/80 active:bg-secondary/70",ghost:"hover:bg-accent hover:text-accent-foreground active:bg-accent/80",link:"text-primary underline-offset-4 hover:underline"},size:{default:"h-10 px-4 py-2",sm:"h-9 rounded-md px-3 text-sm",lg:"h-11 rounded-md px-8",icon:"h-10 w-10"}},defaultVariants:{variant:"default",size:"default"}}),Ae=m.forwardRef(({className:e,variant:t,size:n,...r},a)=>i.jsx("button",{className:me(mM({variant:t,size:n,className:e})),ref:a,...r}));Ae.displayName="Button";const kE=m.createContext(null),SE=()=>{const e=m.useContext(kE);if(!e)throw new Error("Confirmation components must be used within Confirmation");return e},CE=({className:e,approval:t="pending",children:n,...r})=>{const a=m.useMemo(()=>({approval:t}),[t]);return i.jsx(kE.Provider,{value:a,children:i.jsx(wE,{className:me("flex flex-col gap-2",e),...r,children:n})})};CE.displayName="Confirmation";const EE=({className:e,...t})=>i.jsx("div",{"data-slot":"confirmation-title",className:me("text-muted-foreground inline text-sm",e),...t});EE.displayName="ConfirmationTitle";const NE=({children:e})=>{const{approval:t}=SE();return t!=="pending"?null:i.jsx(i.Fragment,{children:e})};NE.displayName="ConfirmationRequest";const TE=({className:e,...t})=>{const{approval:n}=SE();return n!=="pending"?null:i.jsx("div",{"data-slot":"confirmation-actions",className:me("flex items-center justify-end gap-2 self-end",e),...t})};TE.displayName="ConfirmationActions";const ad=({variant:e="default",...t})=>i.jsx(Ae,{className:"h-8 px-3 text-sm",variant:e,type:"button",...t});ad.displayName="ConfirmationAction";const AE=m.forwardRef(({className:e,...t},n)=>i.jsx("div",{ref:n,className:me("rounded-xl border bg-card text-card-foreground shadow-sm",e),...t}));AE.displayName="Card";const jE=m.forwardRef(({className:e,...t},n)=>i.jsx("div",{ref:n,className:me("flex flex-col space-y-1.5 p-4",e),...t}));jE.displayName="CardHeader";const RE=m.forwardRef(({className:e,...t},n)=>i.jsx("h3",{ref:n,className:me("font-semibold leading-none tracking-tight",e),...t}));RE.displayName="CardTitle";const hM=m.forwardRef(({className:e,...t},n)=>i.jsx("p",{ref:n,className:me("text-sm text-muted-foreground",e),...t}));hM.displayName="CardDescription";const _E=m.forwardRef(({className:e,...t},n)=>i.jsx("div",{ref:n,className:me("p-4 pt-0",e),...t}));_E.displayName="CardContent";const IE=m.forwardRef(({className:e,...t},n)=>i.jsx("div",{ref:n,className:me("flex items-center p-4 pt-0",e),...t}));IE.displayName="CardFooter";const fM=m.forwardRef(({className:e,...t},n)=>i.jsx("div",{ref:n,className:me("ml-auto shrink-0",e),...t}));fM.displayName="CardAction";const LE=m.createContext(null);function PE(){const e=m.useContext(LE);if(!e)throw new Error("Collapsible components must be used within <Collapsible>");return e}const Yi=m.forwardRef(({defaultOpen:e=!1,open:t,onOpenChange:n,className:r,children:a,...s},o)=>{const[l,c]=m.useState(e),d=t!==void 0,u=d?t:l,p=m.useCallback(h=>{d||c(h),n?.(h)},[d,n]),f=m.useMemo(()=>({open:u,onOpenChange:p}),[u,p]);return i.jsx(LE.Provider,{value:f,children:i.jsx("div",{ref:o,"data-state":u?"open":"closed",className:r,...s,children:a})})});Yi.displayName="Collapsible";const di=m.forwardRef(({onClick:e,children:t,className:n,...r},a)=>{const{open:s,onOpenChange:o}=PE(),l=m.useCallback(c=>{o(!s),e?.(c)},[s,o,e]);return i.jsx("button",{ref:a,type:"button","aria-expanded":s,"data-state":s?"open":"closed",onClick:l,className:n,...r,children:t})});di.displayName="CollapsibleTrigger";const Zi=m.forwardRef(({className:e,children:t,...n},r)=>{const{open:a}=PE();return i.jsx("div",{ref:r,"data-state":a?"open":"closed",className:me("grid transition-[grid-template-rows] duration-200 ease-out",a?"grid-rows-[1fr]":"grid-rows-[0fr]",e),...n,children:i.jsx("div",{className:"overflow-hidden",children:t})})});Zi.displayName="CollapsibleContent";const DE=m.createContext(null);function dg(){const e=m.useContext(DE);if(!e)throw new Error("Command components must be used within <Command>");return e}const OE=m.forwardRef(({className:e,children:t,...n},r)=>{const[a,s]=m.useState(""),o=m.useRef(new Map),[l,c]=m.useState(0),d=m.useCallback(y=>{o.current.set(y.id,y),c(w=>w+1)},[]),u=m.useCallback(y=>{o.current.delete(y),c(w=>w+1)},[]),p=m.useCallback((y,w)=>{const k=o.current.get(y);k&&Object.assign(k,w)},[]),f=m.useMemo(()=>{const y=a.toLowerCase(),w=new Set;for(const[k,S]of o.current)(!y||S.value.includes(y))&&w.add(k);return w},[a,l]),h=m.useMemo(()=>{const y=[];for(const[,w]of o.current)f.has(w.id)&&y.push(w);return y},[f]),[g,b]=m.useState(null);m.useEffect(()=>{b(h.length>0?h[0].id:null)},[h]);const x=m.useCallback(y=>{if(y.key==="ArrowDown"||y.key==="ArrowUp"||y.key==="Enter")y.preventDefault();else return;const w=h;if(w.length===0)return;if(y.key==="Enter"){w.find(A=>A.id===g)?.onSelect();return}const k=w.findIndex(R=>R.id===g);let S;y.key==="ArrowDown"?S=k<w.length-1?k+1:0:S=k>0?k-1:w.length-1;const C=w[S].id;b(C),w[S].element?.scrollIntoView({block:"nearest"})},[h,g]),v=m.useMemo(()=>({search:a,setSearch:s,visibleIds:f,activeId:g,setActiveId:b,register:d,unregister:u,updateEntry:p}),[a,f,g,d,u,p]);return i.jsx(DE.Provider,{value:v,children:i.jsx("div",{ref:r,role:"combobox","aria-expanded":"true","aria-haspopup":"listbox",className:me("flex flex-col",e),onKeyDown:x,...n,children:t})})});OE.displayName="Command";const ME=m.forwardRef(({className:e,placeholder:t="Search...",...n},r)=>{const{search:a,setSearch:s}=dg();return i.jsxs("div",{className:"flex items-center border-b px-3",role:"presentation",children:[i.jsx(ja,{className:"mr-2 h-4 w-4 shrink-0 text-muted-foreground","aria-hidden":!0}),i.jsx("input",{ref:r,type:"text",role:"searchbox","aria-autocomplete":"list",autoComplete:"off",autoCorrect:"off",spellCheck:!1,value:a,onChange:o=>s(o.target.value),placeholder:t,className:me("flex h-11 w-full rounded-md bg-transparent py-3 text-sm outline-none","placeholder:text-muted-foreground disabled:cursor-not-allowed disabled:opacity-50",e),...n})]})});ME.displayName="CommandInput";const FE=m.forwardRef(({className:e,...t},n)=>i.jsx("div",{ref:n,role:"listbox",className:me("max-h-[300px] overflow-y-auto overflow-x-hidden",e),...t}));FE.displayName="CommandList";const zE=m.forwardRef(({className:e,...t},n)=>{const{search:r,visibleIds:a}=dg();return!r||a.size>0?null:i.jsx("div",{ref:n,className:me("py-6 text-center text-sm text-muted-foreground",e),...t})});zE.displayName="CommandEmpty";const BE=m.forwardRef(({className:e,heading:t,children:n,...r},a)=>i.jsxs("div",{ref:a,className:me("overflow-hidden p-1",e),role:"group","aria-label":typeof t=="string"?t:void 0,...r,children:[t&&i.jsx("div",{className:"px-2 py-1.5 text-xs font-medium text-muted-foreground",role:"presentation",children:t}),n]}));BE.displayName="CommandGroup";const UE=m.forwardRef(({className:e,value:t,onSelect:n,disabled:r,children:a,...s},o)=>{const{visibleIds:l,activeId:c,setActiveId:d,register:u,unregister:p,updateEntry:f}=dg(),h=m.useId(),g=m.useRef(null),b=t||(typeof a=="string"?a:"");m.useEffect(()=>(u({id:h,value:b.toLowerCase(),onSelect:n||(()=>{}),element:g.current}),()=>p(h)),[h,b,u,p]),m.useEffect(()=>{f(h,{onSelect:n||(()=>{})})},[h,n,f]);const x=m.useCallback(y=>{g.current=y,f(h,{element:y}),typeof o=="function"?o(y):o&&(o.current=y)},[h,f,o]);if(!l.has(h))return null;const v=c===h;return i.jsx("div",{ref:x,role:"option","aria-selected":v,"aria-disabled":r||void 0,"data-active":v||void 0,className:me("relative flex cursor-pointer select-none items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-none",v&&"bg-accent text-accent-foreground",r&&"pointer-events-none opacity-50",e),onPointerMove:()=>{!r&&c!==h&&d(h)},onClick:()=>!r&&n?.(),...s,children:a})});UE.displayName="CommandItem";const gM=m.forwardRef(({className:e,...t},n)=>i.jsx("div",{ref:n,className:me("-mx-1 h-px bg-border",e),...t}));gM.displayName="CommandSeparator";function Id({checked:e,onToggle:t,ariaLabel:n}){const{t:r}=Fe("settings"),{isDarkMode:a,toggleDarkMode:s}=Fa(),o=typeof e=="boolean",l=o?e:a,c=n||r("quickSettings.darkMode",{defaultValue:"Toggle dark mode"}),d=()=>{if(o){t?.(!l);return}s()};return i.jsxs("button",{onClick:d,className:me("relative inline-flex h-7 w-12 flex-shrink-0 touch-manipulation cursor-pointer items-center rounded-full border-2 transition-colors duration-200","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background",l?"border-primary bg-primary":"border-border bg-muted"),role:"switch","aria-checked":l,"aria-label":c,children:[i.jsx("span",{className:"sr-only",children:c}),i.jsx("span",{className:me("flex h-5 w-5 transform items-center justify-center rounded-full shadow-sm transition-transform duration-200",l?"translate-x-[22px] bg-white":"translate-x-[2px] bg-foreground/60 dark:bg-foreground/80"),children:l?i.jsx(oE,{className:"h-3 w-3 text-primary"}):i.jsx(dE,{className:"h-3 w-3 text-white dark:text-background"})})]})}const $E=m.createContext(null);function HE(){const e=m.useContext($E);if(!e)throw new Error("Dialog components must be used within <Dialog>");return e}const GE=({open:e,onOpenChange:t,defaultOpen:n=!1,children:r})=>{const[a,s]=m.useState(n),o=m.useRef(null),l=e!==void 0,c=l?e:a,d=m.useCallback(p=>{l||s(p),t?.(p)},[l,t]),u=m.useMemo(()=>({open:c,onOpenChange:d,triggerRef:o}),[c,d]);return i.jsx($E.Provider,{value:u,children:r})},bM=m.forwardRef(({onClick:e,children:t,asChild:n,...r},a)=>{const{onOpenChange:s,triggerRef:o}=HE(),l=m.useCallback(c=>{s(!0),e?.(c)},[s,e]);if(n&&m.isValidElement(t)){const c=t;return m.cloneElement(c,{onClick:d=>{s(!0),c.props.onClick?.(d)},ref:d=>{o.current=d,typeof a=="function"?a(d):a&&(a.current=d)}})}return i.jsx("button",{ref:c=>{o.current=c,typeof a=="function"?a(c):a&&(a.current=c)},type:"button",onClick:l,...r,children:t})});bM.displayName="DialogTrigger";const qw='a[href], button:not([disabled]), input:not([disabled]), textarea:not([disabled]), select:not([disabled]), [tabindex]:not([tabindex="-1"])',ug=m.forwardRef(({className:e,children:t,onEscapeKeyDown:n,onPointerDownOutside:r,...a},s)=>{const{open:o,onOpenChange:l,triggerRef:c}=HE(),d=m.useRef(null),u=m.useRef(null);return m.useEffect(()=>{o?u.current=document.activeElement:u.current&&((c.current||u.current)?.focus(),u.current=null)},[o,c]),m.useEffect(()=>{if(!o)return;const p=h=>{if(h.key==="Escape"){h.stopPropagation(),n?.(),l(!1);return}if(h.key==="Tab"&&d.current){const g=Array.from(d.current.querySelectorAll(qw));if(g.length===0)return;const b=g[0],x=g[g.length-1];h.shiftKey&&document.activeElement===b?(h.preventDefault(),x.focus()):!h.shiftKey&&document.activeElement===x&&(h.preventDefault(),b.focus())}};document.addEventListener("keydown",p,!0);const f=document.body.style.overflow;return document.body.style.overflow="hidden",()=>{document.removeEventListener("keydown",p,!0),document.body.style.overflow=f}},[o,l,n]),m.useEffect(()=>{o&&d.current&&requestAnimationFrame(()=>{d.current?.querySelector(qw)?.focus()})},[o]),o?du.createPortal(i.jsxs("div",{className:"fixed inset-0 z-50",children:[i.jsx("div",{className:"fixed inset-0 animate-dialog-overlay-show bg-black/50 backdrop-blur-sm",onClick:()=>{r?.(),l(!1)},"aria-hidden":!0}),i.jsx("div",{ref:p=>{d.current=p,typeof s=="function"?s(p):s&&(s.current=p)},role:"dialog","aria-modal":"true",className:me("fixed left-1/2 top-1/2 z-50 w-full max-w-lg -translate-x-1/2 -translate-y-1/2","rounded-xl border bg-popover text-popover-foreground shadow-lg","animate-dialog-content-show",e),...a,children:t})]}),document.body):null});ug.displayName="DialogContent";const pg=m.forwardRef(({className:e,...t},n)=>i.jsx("h2",{ref:n,className:me("sr-only",e),...t}));pg.displayName="DialogTitle";const Ze=m.forwardRef(({className:e,type:t,...n},r)=>i.jsx("input",{type:t,className:me("flex h-9 w-full rounded-md border border-input bg-transparent px-3 py-1 text-sm shadow-sm transition-colors file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50",e),ref:r,...n}));Ze.displayName="Input";const mg=m.forwardRef(({className:e,contentClassName:t,children:n,...r},a)=>i.jsx("div",{className:me("relative overflow-hidden",e),...r,children:i.jsx("div",{ref:a,className:me("h-full w-full overflow-auto rounded-[inherit]",t),style:{WebkitOverflowScrolling:"touch",touchAction:"pan-y"},children:n})}));mg.displayName="ScrollArea";const Ld=m.memo(({children:e,className:t,as:n="span"})=>i.jsx(n,{className:me("animate-shimmer inline-block bg-[length:250%_100%] bg-clip-text text-transparent","bg-[linear-gradient(90deg,transparent_33%,hsl(var(--foreground))_50%,transparent_67%),linear-gradient(hsl(var(--muted-foreground)),hsl(var(--muted-foreground)))]",t),children:e}));Ld.displayName="Shimmer";const WE=m.createContext(null),xM=()=>{const e=m.useContext(WE);if(!e)throw new Error("Reasoning components must be used within Reasoning");return e},vM=1e3,yM=1e3,Mh=m.memo(({className:e,isStreaming:t=!1,open:n,defaultOpen:r,onOpenChange:a,duration:s,children:o,...l})=>{const c=r??t,d=r===!1,[u,p]=m.useState(c),f=n!==void 0,h=f?n:u,g=m.useCallback(C=>{f||p(C),a?.(C)},[f,a]),[b,x]=m.useState(s),v=m.useRef(t),[y,w]=m.useState(!1),k=m.useRef(null);m.useEffect(()=>{s!==void 0&&x(s)},[s]),m.useEffect(()=>{t?(v.current=!0,k.current===null&&(k.current=Date.now())):k.current!==null&&(x(Math.ceil((Date.now()-k.current)/yM)),k.current=null)},[t]),m.useEffect(()=>{t&&!h&&!d&&g(!0)},[t,h,g,d]),m.useEffect(()=>{if(v.current&&!t&&h&&!y){const C=setTimeout(()=>{g(!1),w(!0)},vM);return()=>clearTimeout(C)}},[t,h,g,y]);const S=m.useMemo(()=>({duration:b,isOpen:h,isStreaming:t,setIsOpen:g}),[b,h,t,g]);return i.jsx(WE.Provider,{value:S,children:i.jsx(Yi,{open:h,onOpenChange:g,className:me("not-prose",e),...l,children:o})})});Mh.displayName="Reasoning";const wM=(e,t)=>e||t===0?i.jsx(Ld,{children:"Thinking..."}):t===void 0?i.jsx("p",{children:"Thought for a few seconds"}):i.jsxs("p",{children:["Thought for ",t," seconds"]}),Fh=m.memo(({className:e,children:t,getThinkingMessage:n=wM,...r})=>{const{isStreaming:a,isOpen:s,duration:o}=xM();return i.jsx(di,{className:me("flex w-full items-center gap-2 text-sm text-muted-foreground transition-colors hover:text-foreground",e),...r,children:t??i.jsxs(i.Fragment,{children:[i.jsx(VD,{className:"h-4 w-4"}),n(a,o),i.jsx($4,{className:me("h-4 w-4 transition-transform",s?"rotate-180":"rotate-0")})]})})});Fh.displayName="ReasoningTrigger";const zh=m.memo(({className:e,children:t,...n})=>i.jsx(Zi,{className:me("mt-4 text-sm text-muted-foreground",e),...n,children:t}));zh.displayName="ReasoningContent";function kM(e){switch(e){case"top":return"top-full left-1/2 transform -translate-x-1/2 border-t-gray-900 dark:border-t-gray-100";case"bottom":return"bottom-full left-1/2 transform -translate-x-1/2 border-b-gray-900 dark:border-b-gray-100";case"left":return"left-full top-1/2 transform -translate-y-1/2 border-l-gray-900 dark:border-l-gray-100";case"right":return"right-full top-1/2 transform -translate-y-1/2 border-r-gray-900 dark:border-r-gray-100";default:return"top-full left-1/2 transform -translate-x-1/2 border-t-gray-900 dark:border-t-gray-100"}}function Bh({children:e,content:t,position:n="top",className:r="",delay:a=350}){const[s,o]=m.useState(!1),l=m.useRef(null),c=m.useRef(!1),d=m.useRef(null),u=m.useRef(null),[p,f]=m.useState(null),h=m.useCallback(()=>{const w=d.current;if(!w)return;const k=w.getBoundingClientRect(),S=8,C={position:"fixed",zIndex:9999};switch(n){case"bottom":C.left=k.left+k.width/2,C.top=k.bottom+S,C.transform="translateX(-50%)";break;case"left":C.left=k.left-S,C.top=k.top+k.height/2,C.transform="translate(-100%, -50%)";break;case"right":C.left=k.right+S,C.top=k.top+k.height/2,C.transform="translateY(-50%)";break;case"top":default:C.left=k.left+k.width/2,C.top=k.top-S,C.transform="translate(-50%, -100%)";break}f(C)},[n]),g=()=>{l.current!==null&&(window.clearTimeout(l.current),l.current=null)},b=()=>{g(),l.current=window.setTimeout(()=>{o(!0)},a)},x=()=>{g(),o(!1)},v=()=>{g(),c.current=!1,l.current=window.setTimeout(()=>{c.current=!0,o(!0)},a)},y=()=>{g(),!c.current&&o(!1)};return m.useEffect(()=>()=>{g()},[]),m.useEffect(()=>{if(!s||typeof document>"u")return;const w=k=>{const S=k.target;S instanceof Node&&d.current?.contains(S)||(o(!1),c.current=!1)};return document.addEventListener("pointerdown",w,!0),()=>document.removeEventListener("pointerdown",w,!0)},[s]),m.useEffect(()=>{if(!s){f(null);return}const w=window.requestAnimationFrame(h),k=()=>h();return window.addEventListener("resize",k),window.addEventListener("scroll",k,!0),()=>{window.cancelAnimationFrame(w),window.removeEventListener("resize",k),window.removeEventListener("scroll",k,!0)}},[s,h]),t?i.jsxs("div",{ref:d,className:"relative inline-block",onMouseEnter:b,onMouseLeave:x,onTouchStart:v,onTouchEnd:y,onTouchCancel:y,children:[e,s&&typeof document<"u"&&du.createPortal(i.jsxs("div",{ref:u,style:p||{position:"fixed",top:"-9999px",left:"-9999px",opacity:0},className:me("px-2 py-1 text-xs font-medium text-white bg-gray-900 dark:bg-gray-100 dark:text-gray-900 rounded shadow-lg whitespace-nowrap pointer-events-none","animate-in fade-in-0 zoom-in-95 duration-200",r),children:[t,i.jsx("div",{className:me("absolute w-0 h-0 border-4 border-transparent",kM(n))})]}),document.body)]}):i.jsx(i.Fragment,{children:e})}const VE=m.createContext(null),qE=m.forwardRef(({className:e,status:t="ready",children:n,...r},a)=>{const s=m.useMemo(()=>({status:t}),[t]);return i.jsx(VE.Provider,{value:s,children:i.jsx("form",{ref:a,"data-slot":"prompt-input",className:me("relative overflow-hidden rounded-xl border border-border/70 bg-zinc-50/95 shadow-sm shadow-zinc-950/5 backdrop-blur-sm transition-all duration-200 focus-within:border-primary/40 focus-within:shadow-md focus-within:ring-1 focus-within:ring-primary/20 dark:bg-zinc-950/90",e),...r,children:n})})});qE.displayName="PromptInput";const KE=m.forwardRef(({className:e,...t},n)=>i.jsx("div",{ref:n,"data-slot":"prompt-input-header",className:me("px-3 pt-3",e),...t}));KE.displayName="PromptInputHeader";const YE=m.forwardRef(({className:e,...t},n)=>i.jsx("div",{ref:n,"data-slot":"prompt-input-body",className:me("relative",e),...t}));YE.displayName="PromptInputBody";const ZE=m.forwardRef(({className:e,...t},n)=>i.jsx("textarea",{ref:n,"data-slot":"prompt-input-textarea",className:me("chat-input-placeholder block max-h-[40vh] w-full resize-none overflow-y-auto bg-transparent px-4 py-2 font-mono text-sm leading-6 text-foreground placeholder-muted-foreground/50 focus:outline-none sm:max-h-[300px]",e),...t}));ZE.displayName="PromptInputTextarea";const XE=m.forwardRef(({className:e,...t},n)=>i.jsx("div",{ref:n,"data-slot":"prompt-input-footer",className:me("flex items-center justify-between border-t border-border/30 px-3 py-2",e),...t}));XE.displayName="PromptInputFooter";const QE=m.forwardRef(({className:e,...t},n)=>i.jsx("div",{ref:n,"data-slot":"prompt-input-tools",className:me("flex items-center gap-1",e),...t}));QE.displayName="PromptInputTools";const id=m.forwardRef(({className:e,tooltip:t,children:n,...r},a)=>{const s=i.jsx(Ae,{ref:a,type:"button",variant:"ghost",size:"icon",className:me("h-8 w-8 [&_svg]:size-4",e),...r,children:n});return t?i.jsx(Bh,{content:t.shortcut?i.jsxs("span",{className:"flex items-center gap-1.5",children:[t.content,i.jsx("kbd",{className:"rounded bg-white/20 px-1 text-[10px]",children:t.shortcut})]}):t.content,position:t.side??"top",children:s}):s});id.displayName="PromptInputButton";const JE=m.forwardRef(({className:e,status:t,children:n,...r},a)=>{const s=m.useContext(VE),o=t??s?.status??"ready",l=o==="submitted"||o==="streaming";return i.jsx(Ae,{ref:a,type:l?"button":"submit",variant:"default",size:"icon",className:me("h-8 w-8 rounded-lg",e),...r,children:n??(l?i.jsx(FD,{className:"h-3.5 w-3.5 fill-current"}):i.jsx(RD,{className:"h-4 w-4"}))})});JE.displayName="PromptInputSubmit";function hg({children:e,className:t}){return i.jsx("div",{className:me("inline-flex max-w-full items-center gap-1 rounded-lg bg-muted/60 p-1",t),children:e})}function fg({isActive:e,onClick:t,children:n,className:r}){return i.jsx("button",{type:"button",onClick:t,className:me("flex min-w-0 touch-manipulation items-center justify-center gap-1.5 rounded-md px-3 py-2 text-sm font-medium transition-all duration-150",e?"bg-background text-foreground shadow-sm":"text-muted-foreground active:bg-background/50",r),children:n})}const eN=m.createContext(null);function tN(){const e=m.useContext(eN);if(!e)throw new Error("QueueItem sub-components must be used within <QueueItem>");return e}const nN=m.forwardRef(({className:e,...t},n)=>i.jsx("div",{ref:n,"data-slot":"queue",role:"list",className:me("space-y-0.5",e),...t}));nN.displayName="Queue";const rN=m.forwardRef(({status:e="pending",className:t,children:n,...r},a)=>{const s=m.useMemo(()=>({status:e}),[e]);return i.jsx(eN.Provider,{value:s,children:i.jsx("div",{ref:a,"data-slot":"queue-item","data-status":e,role:"listitem",className:me("flex items-start gap-2 py-0.5",t),...r,children:n})})});rN.displayName="QueueItem";const aN=m.forwardRef(({className:e,...t},n)=>{const{status:r}=tN();return i.jsxs("div",{ref:n,"data-slot":"queue-item-indicator","aria-hidden":"true",className:me("mt-0.5 flex h-3.5 w-3.5 flex-shrink-0 items-center justify-center",e),...t,children:[r==="completed"&&i.jsx("svg",{className:"h-3.5 w-3.5 text-green-500 dark:text-green-400",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:i.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z"})}),r==="in_progress"&&i.jsx("span",{className:"h-2 w-2 animate-pulse rounded-full bg-blue-500 dark:bg-blue-400"}),r==="pending"&&i.jsx("svg",{className:"h-3.5 w-3.5 text-muted-foreground/50",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:i.jsx("circle",{cx:"12",cy:"12",r:"9",strokeWidth:2})})]})});aN.displayName="QueueItemIndicator";const iN=m.forwardRef(({className:e,children:t,...n},r)=>{const{status:a}=tN();return i.jsx("div",{ref:r,"data-slot":"queue-item-content",className:me("min-w-0 flex-1 text-xs",a==="completed"&&"text-muted-foreground line-through",a==="in_progress"&&"font-medium text-foreground",a==="pending"&&"text-foreground",e),...n,children:t})});iN.displayName="QueueItemContent";const Kw="https://github.com/alicomert/pixcode/issues/new",Yw="https://github.com/alicomert/pixcode",Zw="https://discord.gg/buxwujPNRE";function Xw({className:e}){return i.jsx("svg",{className:e,fill:"currentColor",viewBox:"0 0 24 24","aria-hidden":"true",children:i.jsx("path",{d:"M20.317 4.37a19.791 19.791 0 0 0-4.885-1.515.074.074 0 0 0-.079.037c-.21.375-.444.864-.608 1.25a18.27 18.27 0 0 0-5.487 0 12.64 12.64 0 0 0-.617-1.25.077.077 0 0 0-.079-.037A19.736 19.736 0 0 0 3.677 4.37a.07.07 0 0 0-.032.027C.533 9.046-.32 13.58.099 18.057a.082.082 0 0 0 .031.057 19.9 19.9 0 0 0 5.993 3.03.078.078 0 0 0 .084-.028c.462-.63.874-1.295 1.226-1.994a.076.076 0 0 0-.041-.106 13.107 13.107 0 0 1-1.872-.892.077.077 0 0 1-.008-.128 10.2 10.2 0 0 0 .372-.292.074.074 0 0 1 .077-.01c3.928 1.793 8.18 1.793 12.062 0a.074.074 0 0 1 .078.01c.12.098.246.198.373.292a.077.077 0 0 1-.006.127 12.299 12.299 0 0 1-1.873.892.077.077 0 0 0-.041.107c.36.698.772 1.362 1.225 1.993a.076.076 0 0 0 .084.028 19.839 19.839 0 0 0 6.002-3.03.077.077 0 0 0 .032-.054c.5-5.177-.838-9.674-3.549-13.66a.061.061 0 0 0-.031-.03zM8.02 15.33c-1.183 0-2.157-1.085-2.157-2.419 0-1.333.956-2.419 2.157-2.419 1.21 0 2.176 1.095 2.157 2.42 0 1.333-.956 2.418-2.157 2.418zm7.975 0c-1.183 0-2.157-1.085-2.157-2.419 0-1.333.955-2.419 2.157-2.419 1.21 0 2.176 1.095 2.157 2.42 0 1.333-.946 2.418-2.157 2.418z"})})}function SM({updateAvailable:e,releaseInfo:t,latestVersion:n,currentVersion:r,onShowVersionModal:a,onOpenControlRoom:s,onShowSettings:o,t:l}){return i.jsxs("div",{className:"flex-shrink-0",style:{paddingBottom:"env(safe-area-inset-bottom, 0)"},children:[e&&i.jsxs(i.Fragment,{children:[i.jsx("div",{className:"nav-divider"}),i.jsx("div",{className:"hidden px-2 py-1.5 md:block",children:i.jsxs("button",{className:"group flex w-full items-center gap-2.5 rounded-lg px-2.5 py-2 text-left transition-colors hover:bg-blue-50/80 dark:hover:bg-blue-900/15",onClick:a,children:[i.jsxs("div",{className:"relative flex-shrink-0",children:[i.jsx(Tw,{className:"h-4 w-4 text-blue-500 dark:text-blue-400"}),i.jsx("span",{className:"absolute -right-0.5 -top-0.5 h-1.5 w-1.5 animate-pulse rounded-full bg-blue-500"})]}),i.jsxs("div",{className:"min-w-0 flex-1",children:[i.jsx("span",{className:"block truncate text-sm font-medium text-blue-600 dark:text-blue-300",children:t?.title||`v${n}`}),i.jsx("span",{className:"text-[10px] text-blue-500/70 dark:text-blue-400/60",children:l("version.updateAvailable")})]})]})}),i.jsx("div",{className:"px-3 py-2 md:hidden",children:i.jsxs("button",{className:"flex h-11 w-full items-center gap-3 rounded-xl border border-blue-200/60 bg-blue-50/80 px-3.5 transition-all active:scale-[0.98] dark:border-blue-700/40 dark:bg-blue-900/15",onClick:a,children:[i.jsxs("div",{className:"relative flex-shrink-0",children:[i.jsx(Tw,{className:"w-4.5 h-4.5 text-blue-500 dark:text-blue-400"}),i.jsx("span",{className:"absolute -right-0.5 -top-0.5 h-1.5 w-1.5 animate-pulse rounded-full bg-blue-500"})]}),i.jsxs("div",{className:"min-w-0 flex-1 text-left",children:[i.jsx("span",{className:"block truncate text-sm font-medium text-blue-600 dark:text-blue-300",children:t?.title||`v${n}`}),i.jsx("span",{className:"text-xs text-blue-500/70 dark:text-blue-400/60",children:l("version.updateAvailable")})]})]})})]}),i.jsx("div",{className:"nav-divider"}),i.jsx("div",{className:"hidden px-2 pt-1.5 md:block",children:i.jsxs("a",{href:Kw,target:"_blank",rel:"noopener noreferrer",className:"flex w-full items-center gap-2 rounded-lg px-2.5 py-1.5 text-muted-foreground transition-colors hover:bg-accent/60 hover:text-foreground",children:[i.jsx(Sl,{className:"h-3.5 w-3.5"}),i.jsx("span",{className:"text-sm",children:l("actions.reportIssue")})]})}),i.jsx("div",{className:"hidden px-2 md:block",children:i.jsxs("a",{href:Zw,target:"_blank",rel:"noopener noreferrer",className:"flex w-full items-center gap-2 rounded-lg px-2.5 py-1.5 text-muted-foreground transition-colors hover:bg-accent/60 hover:text-foreground",children:[i.jsx(Xw,{className:"h-3.5 w-3.5"}),i.jsx("span",{className:"text-sm",children:l("actions.joinCommunity")})]})}),s&&i.jsx("div",{className:"hidden px-2 pt-1.5 md:block",children:i.jsxs("button",{className:"group flex w-full items-center gap-2.5 rounded-lg border border-primary/25 bg-primary/5 px-2.5 py-2 text-left transition-colors hover:bg-primary/10",onClick:s,children:[i.jsx("div",{className:"flex h-7 w-7 items-center justify-center rounded-md bg-primary/10 text-primary",children:i.jsx(Vn,{className:"h-3.5 w-3.5"})}),i.jsxs("div",{className:"min-w-0 flex-1",children:[i.jsx("span",{className:"block truncate text-sm font-semibold text-foreground",children:l("actions.controlRoom",{defaultValue:"Control Room"})}),i.jsx("span",{className:"block truncate text-[10px] text-muted-foreground",children:l("actions.controlRoomDescription",{defaultValue:"Admin, access, runs"})})]})]})}),i.jsx("div",{className:"hidden px-2 py-1.5 md:block",children:i.jsxs("button",{className:"flex w-full items-center gap-2 rounded-lg px-2.5 py-1.5 text-muted-foreground transition-colors hover:bg-accent/60 hover:text-foreground",onClick:o,children:[i.jsx(Pt,{className:"h-3.5 w-3.5"}),i.jsx("span",{className:"text-sm",children:l("actions.settings")})]})}),i.jsx("div",{className:"hidden px-3 py-2 text-center md:block",children:i.jsxs("a",{href:Yw,target:"_blank",rel:"noopener noreferrer",className:"text-[10px] text-muted-foreground/40 transition-colors hover:text-muted-foreground",children:["Pixcode v",r," – ",l("branding.openSource")]})}),i.jsxs("div",{className:"px-3 py-2 md:hidden",children:[i.jsxs("div",{className:`grid gap-1.5 ${s?"grid-cols-4":"grid-cols-3"}`,children:[i.jsxs("a",{href:Kw,target:"_blank",rel:"noopener noreferrer",className:"flex min-h-14 flex-col items-center justify-center gap-1 rounded-xl bg-muted/35 px-1 text-center text-[11px] font-medium text-foreground transition-colors active:bg-muted",children:[i.jsx(Sl,{className:"h-4 w-4 text-muted-foreground"}),i.jsx("span",{className:"line-clamp-2 leading-tight",children:l("actions.reportIssue")})]}),i.jsxs("a",{href:Zw,target:"_blank",rel:"noopener noreferrer",className:"flex min-h-14 flex-col items-center justify-center gap-1 rounded-xl bg-muted/35 px-1 text-center text-[11px] font-medium text-foreground transition-colors active:bg-muted",children:[i.jsx(Xw,{className:"h-4 w-4 text-muted-foreground"}),i.jsx("span",{className:"line-clamp-2 leading-tight",children:l("actions.joinCommunity")})]}),s&&i.jsxs("button",{type:"button",className:"flex min-h-14 flex-col items-center justify-center gap-1 rounded-xl border border-primary/20 bg-primary/10 px-1 text-center text-[11px] font-semibold text-primary transition-colors active:bg-primary/15",onClick:s,children:[i.jsx(Vn,{className:"h-4 w-4"}),i.jsx("span",{className:"line-clamp-2 leading-tight",children:l("actions.controlRoom",{defaultValue:"Control Room"})})]}),i.jsxs("button",{type:"button",className:"flex min-h-14 flex-col items-center justify-center gap-1 rounded-xl bg-muted/35 px-1 text-center text-[11px] font-medium text-foreground transition-colors active:bg-muted",onClick:o,children:[i.jsx(Pt,{className:"h-4 w-4 text-muted-foreground"}),i.jsx("span",{className:"line-clamp-2 leading-tight",children:l("actions.settings")})]})]}),i.jsxs("a",{href:Yw,target:"_blank",rel:"noopener noreferrer",className:"mt-1.5 block truncate text-center text-[10px] text-muted-foreground/45",children:["Pixcode v",r," · ",l("branding.openSource")]})]})]})}const Qw="PIXCODE_GITHUB_STARS",Jw="PIXCODE_HIDE_GITHUB_STAR",CM=3600*1e3,EM=(e,t)=>{const[n,r]=m.useState(null),[a,s]=m.useState(()=>{try{return localStorage.getItem(Jw)==="true"}catch{return!1}});m.useEffect(()=>{if(a)return;try{const d=localStorage.getItem(Qw);if(d){const u=JSON.parse(d);if(Date.now()-u.timestamp<CM){r(u.count);return}}}catch{}(async()=>{try{const d=await fetch(`https://api.github.com/repos/${e}/${t}`);if(!d.ok)return;const p=(await d.json()).stargazers_count;if(typeof p=="number"){r(p);try{localStorage.setItem(Qw,JSON.stringify({count:p,timestamp:Date.now()}))}catch{}}}catch{}})()},[e,t,a]);const o=m.useCallback(()=>{s(!0);try{localStorage.setItem(Jw,"true")}catch{}},[]),l=n!==null?n>=1e3?`${(n/1e3).toFixed(1)}k`:`${n}`:null;return{starCount:n,formattedCount:l,isDismissed:a,dismiss:o}},NM="https://github.com/alicomert/pixcode";function TM({className:e}){return i.jsx("svg",{className:e,fill:"currentColor",viewBox:"0 0 24 24","aria-hidden":"true",children:i.jsx("path",{d:"M12 2C6.477 2 2 6.484 2 12.017c0 4.425 2.865 8.18 6.839 9.504.5.092.682-.217.682-.483 0-.237-.008-.868-.013-1.703-2.782.605-3.369-1.343-3.369-1.343-.454-1.158-1.11-1.466-1.11-1.466-.908-.62.069-.608.069-.608 1.003.07 1.531 1.032 1.531 1.032.892 1.53 2.341 1.088 2.91.832.092-.647.35-1.088.636-1.338-2.22-.253-4.555-1.113-4.555-4.951 0-1.093.39-1.988 1.029-2.688-.103-.253-.446-1.272.098-2.65 0 0 .84-.27 2.75 1.026A9.564 9.564 0 0112 6.844c.85.004 1.705.115 2.504.337 1.909-1.296 2.747-1.027 2.747-1.027.546 1.379.202 2.398.1 2.651.64.7 1.028 1.595 1.028 2.688 0 3.848-2.339 4.695-4.566 4.943.359.309.678.92.678 1.855 0 1.338-.012 2.419-.012 2.747 0 .268.18.58.688.482A10.019 10.019 0 0022 12.017C22 6.484 17.522 2 12 2z"})})}function AM(){const{formattedCount:e,isDismissed:t,dismiss:n}=EM("alicomert","pixcode");return t?null:i.jsxs("div",{className:"group/star relative hidden md:block",children:[i.jsxs("a",{href:NM,target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-1.5 rounded-lg border border-border/50 bg-muted/30 px-2.5 py-1 text-xs text-muted-foreground transition-colors hover:bg-muted/50 hover:text-foreground",children:[i.jsx(TM,{className:"h-3.5 w-3.5"}),i.jsx(Ea,{className:"h-3 w-3"}),i.jsx("span",{className:"font-medium",children:"Star"}),e&&i.jsx("span",{className:"border-l border-border/50 pl-1.5 tabular-nums",children:e})]}),i.jsx("button",{onClick:r=>{r.preventDefault(),r.stopPropagation(),n()},className:"absolute -right-1.5 -top-1.5 hidden h-4 w-4 items-center justify-center rounded-full border border-border/50 bg-muted text-muted-foreground transition-colors hover:text-foreground group-hover/star:flex","aria-label":"Dismiss",children:i.jsx(ht,{className:"h-2.5 w-2.5"})})]})}function ek({value:e,onChange:t,t:n}){const r="flex flex-1 items-center justify-center gap-1 rounded-md px-2 py-1 text-[11px] font-medium transition-all";return i.jsxs("div",{role:"tablist","aria-label":n("tooltips.historyView",{defaultValue:"History view"}),className:"flex rounded-lg bg-muted/40 p-0.5",children:[i.jsxs("button",{type:"button",role:"tab","aria-selected":e==="flat",onClick:()=>t("flat"),className:me(r,e==="flat"?"bg-background text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"),title:n("tooltips.historyViewFlat",{defaultValue:"Recent conversations"}),children:[i.jsx(nE,{className:"h-3 w-3"}),n("historyView.flat",{defaultValue:"Recent"})]}),i.jsxs("button",{type:"button",role:"tab","aria-selected":e==="grouped",onClick:()=>t("grouped"),className:me(r,e==="grouped"?"bg-background text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"),title:n("tooltips.historyViewGrouped",{defaultValue:"Grouped by project"}),children:[i.jsx(DD,{className:"h-3 w-3"}),n("historyView.grouped",{defaultValue:"By project"})]})]})}function jM({isPWA:e,isMobile:t,isLoading:n,projectsCount:r,searchFilter:a,onSearchFilterChange:s,onClearSearchFilter:o,searchMode:l,onSearchModeChange:c,onRefresh:d,isRefreshing:u,onCreateProject:p,onQuickStartSession:f,onCollapseSidebar:h,historyView:g,onHistoryViewChange:b,t:x}){const v=()=>i.jsxs("div",{className:"flex min-w-0 items-center gap-2.5",children:[i.jsx("svg",{className:"h-6 w-6 flex-shrink-0",viewBox:"0 0 500 500","aria-hidden":"true",children:i.jsx("g",{transform:"translate(250 250) scale(1.25) translate(-250 -250)",children:i.jsxs("g",{transform:"translate(0 500) scale(0.1 -0.1)",fill:"#5C3FFC",children:[i.jsx("path",{d:"M2037 3800 c-104 -40 -191 -134 -231 -250 -23 -67 -20 -82 22 -109 31 -20 287 -177 1009 -618 40 -24 82 -56 93 -70 27 -34 27 -102 0 -136 -11 -13 -106 -78 -212 -143 -106 -64 -201 -124 -210 -132 -16 -14 -18 -41 -18 -302 0 -291 2 -310 38 -310 16 0 267 148 610 359 180 111 270 173 310 213 216 217 215 574 -3 793 -37 38 -107 89 -185 136 -69 42 -253 154 -410 249 -434 264 -509 307 -563 326 -57 20 -191 17 -250 -6z"}),i.jsx("path",{d:"M1803 2994 c-10 -5 -13 -156 -13 -709 0 -671 1 -706 20 -767 27 -89 93 -184 167 -240 89 -67 157 -90 281 -96 92 -4 105 -2 117 14 12 16 14 134 15 735 0 669 -1 718 -17 737 -20 23 -514 322 -541 327 -9 2 -23 2 -29 -1z"})]})})}),i.jsx("h1",{className:"truncate text-sm font-semibold tracking-tight text-foreground",children:x("app.title")})]});return i.jsxs("div",{className:"flex-shrink-0",children:[i.jsxs("div",{className:"hidden px-4 pb-3 pt-4 md:block",style:{},children:[i.jsxs("div",{className:"flex items-center justify-between gap-2",children:[i.jsx(v,{}),i.jsxs("div",{className:"flex flex-shrink-0 items-center gap-0.5",children:[i.jsx(Ae,{variant:"ghost",size:"sm",className:"h-8 w-8 rounded-lg p-0 text-muted-foreground hover:bg-accent/80 hover:text-foreground",onClick:d,disabled:u,title:x("tooltips.refresh"),children:i.jsx(nt,{className:`h-4 w-4 ${u?"animate-spin":""}`})}),i.jsx(Ae,{variant:"ghost",size:"sm",className:"h-8 w-8 rounded-lg p-0 text-muted-foreground hover:bg-accent/80 hover:text-foreground",onClick:p,title:x("tooltips.createProject"),children:i.jsx(Gt,{className:"h-4 w-4"})}),i.jsx(Ae,{variant:"ghost",size:"sm",className:"h-8 w-8 rounded-lg p-0 text-muted-foreground hover:bg-accent/80 hover:text-foreground",onClick:h,title:x("tooltips.hideSidebar"),children:i.jsx(mu,{className:"h-4 w-4"})})]})]}),i.jsx(AM,{}),f&&i.jsxs("button",{type:"button",onClick:()=>{f()},className:"mt-2.5 flex w-full items-center justify-center gap-2 rounded-lg border border-primary/20 bg-primary/5 px-3 py-2 text-sm font-medium text-primary transition-colors hover:bg-primary/10",children:[i.jsx(Vn,{className:"h-4 w-4"}),x("sidebar.newChat",{defaultValue:"New chat"})]}),r>0&&!n&&i.jsxs("div",{className:"mt-2.5 space-y-2",children:[i.jsx(ek,{value:g,onChange:b,t:x}),i.jsxs("div",{className:"flex rounded-lg bg-muted/50 p-0.5",children:[i.jsxs("button",{onClick:()=>c("projects"),"aria-pressed":l==="projects",className:me("flex-1 flex items-center justify-center gap-1.5 rounded-md px-2 py-1.5 text-xs font-medium transition-all",l==="projects"?"bg-background shadow-sm text-foreground":"text-muted-foreground hover:text-foreground"),children:[i.jsx(On,{className:"h-3 w-3"}),x("search.modeProjects")]}),i.jsxs("button",{onClick:()=>c("conversations"),"aria-pressed":l==="conversations",className:me("flex-1 flex items-center justify-center gap-1.5 rounded-md px-2 py-1.5 text-xs font-medium transition-all",l==="conversations"?"bg-background shadow-sm text-foreground":"text-muted-foreground hover:text-foreground"),children:[i.jsx(Wr,{className:"h-3 w-3"}),x("search.modeConversations")]})]}),i.jsxs("div",{className:"relative",children:[i.jsx(ja,{className:"pointer-events-none absolute left-3 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-muted-foreground/50"}),i.jsx(Ze,{type:"text",placeholder:x(l==="conversations"?"search.conversationsPlaceholder":"projects.searchPlaceholder"),value:a,onChange:y=>s(y.target.value),className:"nav-search-input h-9 rounded-xl border-0 pl-9 pr-8 text-sm transition-all duration-200 placeholder:text-muted-foreground/40 focus-visible:ring-0 focus-visible:ring-offset-0"}),a&&i.jsx("button",{onClick:o,"aria-label":x("tooltips.clearSearch"),className:"absolute right-2.5 top-1/2 -translate-y-1/2 rounded-md p-0.5 hover:bg-accent",children:i.jsx(ht,{className:"h-3 w-3 text-muted-foreground"})})]})]})]}),i.jsx("div",{className:"nav-divider hidden md:block"}),i.jsxs("div",{className:"p-3 pb-2 md:hidden",style:e&&t?{paddingTop:"16px"}:{},children:[i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsx(v,{}),i.jsxs("div",{className:"flex flex-shrink-0 gap-1.5",children:[i.jsx("button",{className:"flex h-8 w-8 items-center justify-center rounded-lg bg-muted/50 transition-all active:scale-95",onClick:d,disabled:u,children:i.jsx(nt,{className:`h-4 w-4 text-muted-foreground ${u?"animate-spin":""}`})}),i.jsx("button",{className:"flex h-8 w-8 items-center justify-center rounded-lg bg-primary/90 text-primary-foreground transition-all active:scale-95",onClick:p,children:i.jsx(ci,{className:"h-4 w-4"})})]})]}),f&&i.jsxs("button",{type:"button",onClick:()=>{f()},className:"mt-2 flex h-9 w-full items-center justify-center gap-2 rounded-xl border border-primary/20 bg-primary/5 px-3 text-sm font-medium text-primary transition-colors active:bg-primary/10",children:[i.jsx(Vn,{className:"h-4 w-4"}),x("sidebar.newChat",{defaultValue:"New chat"})]}),r>0&&!n&&i.jsxs("div",{className:"mt-2.5 space-y-2",children:[i.jsx(ek,{value:g,onChange:b,t:x}),i.jsxs("div",{className:"flex rounded-lg bg-muted/50 p-0.5",children:[i.jsxs("button",{onClick:()=>c("projects"),"aria-pressed":l==="projects",className:me("flex-1 flex items-center justify-center gap-1.5 rounded-md px-2 py-1.5 text-xs font-medium transition-all",l==="projects"?"bg-background shadow-sm text-foreground":"text-muted-foreground hover:text-foreground"),children:[i.jsx(On,{className:"h-3 w-3"}),x("search.modeProjects")]}),i.jsxs("button",{onClick:()=>c("conversations"),"aria-pressed":l==="conversations",className:me("flex-1 flex items-center justify-center gap-1.5 rounded-md px-2 py-1.5 text-xs font-medium transition-all",l==="conversations"?"bg-background shadow-sm text-foreground":"text-muted-foreground hover:text-foreground"),children:[i.jsx(Wr,{className:"h-3 w-3"}),x("search.modeConversations")]})]}),i.jsxs("div",{className:"relative",children:[i.jsx(ja,{className:"pointer-events-none absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground/50"}),i.jsx(Ze,{type:"text",placeholder:x(l==="conversations"?"search.conversationsPlaceholder":"projects.searchPlaceholder"),value:a,onChange:y=>s(y.target.value),className:"nav-search-input h-10 rounded-xl border-0 pl-10 pr-9 text-sm transition-all duration-200 placeholder:text-muted-foreground/40 focus-visible:ring-0 focus-visible:ring-offset-0"}),a&&i.jsx("button",{onClick:o,"aria-label":x("tooltips.clearSearch"),className:"absolute right-2.5 top-1/2 -translate-y-1/2 rounded-md p-1 hover:bg-accent",children:i.jsx(ht,{className:"h-3.5 w-3.5 text-muted-foreground"})})]})]})]}),i.jsx("div",{className:"nav-divider md:hidden"})]})}const RM=160,tk=180;function sN({actions:e,className:t,triggerLabel:n}){const[r,a]=m.useState(!1),[s,o]=m.useState(null),l=m.useRef(null),c=m.useRef(null);m.useLayoutEffect(()=>{if(!r||!l.current)return;const u=l.current.getBoundingClientRect();let p=u.right-RM;p<8&&(p=8);let f=u.bottom+4;f+tk>window.innerHeight&&(f=Math.max(8,u.top-4-tk)),o({top:f,left:p})},[r]),m.useEffect(()=>{if(!r)return;const u=h=>{const g=h.target;l.current?.contains(g)||c.current?.contains(g)||a(!1)},p=h=>{h.key==="Escape"&&a(!1)},f=()=>a(!1);return document.addEventListener("mousedown",u),document.addEventListener("keydown",p),window.addEventListener("scroll",f,!0),window.addEventListener("resize",f),()=>{document.removeEventListener("mousedown",u),document.removeEventListener("keydown",p),window.removeEventListener("scroll",f,!0),window.removeEventListener("resize",f)}},[r]);const d=u=>p=>{p.stopPropagation(),p.preventDefault(),a(!1),u.onClick()};return i.jsxs(i.Fragment,{children:[i.jsx("button",{ref:l,type:"button","aria-haspopup":"menu","aria-expanded":r,"aria-label":n||"Actions",title:n||"Actions",onClick:u=>{u.stopPropagation(),u.preventDefault(),a(p=>!p)},className:me("flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground","opacity-0 transition-all duration-150 hover:bg-accent hover:text-foreground","group-hover:opacity-100 focus-visible:opacity-100 focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-primary","touch:opacity-100",r&&"bg-accent text-foreground opacity-100",t),children:i.jsx(aE,{className:"h-3.5 w-3.5"})}),r&&s&&du.createPortal(i.jsx("div",{ref:c,role:"menu",style:{position:"fixed",top:s.top,left:s.left,zIndex:9999},className:me("w-40 rounded-xl border border-border/60 bg-popover p-1 shadow-lg","animate-in fade-in-0 zoom-in-95 duration-100"),onClick:u=>u.stopPropagation(),onMouseDown:u=>u.stopPropagation(),children:e.map((u,p)=>{const f=u.icon,h=e[p-1],g=p>0&&u.danger&&!h?.danger;return i.jsxs("div",{children:[g&&i.jsx("div",{className:"my-1 h-px bg-border/60"}),i.jsxs("button",{type:"button",role:"menuitem",onClick:d(u),className:me("flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left text-xs",u.danger?"text-red-600 hover:bg-red-50 dark:text-red-400 dark:hover:bg-red-900/20":"text-foreground hover:bg-accent"),children:[i.jsx(f,{className:"h-3 w-3"}),u.label]})]},u.id)})}),document.body)]})}const _M=(e,t,n)=>{const r=new Date(e),a=t;if(isNaN(r.getTime()))return n?n("status.unknown"):"Unknown";const s=a.getTime()-r.getTime(),o=Math.floor(s/1e3),l=Math.floor(s/(1e3*60)),c=Math.floor(s/(1e3*60*60)),d=Math.floor(s/(1e3*60*60*24));return o<60?n?n("time.justNow"):"Just now":l===1?n?n("time.oneMinuteAgo"):"1 min ago":l<60?n?n("time.minutesAgo",{count:l}):`${l} mins ago`:c===1?n?n("time.oneHourAgo"):"1 hour ago":c<24?n?n("time.hoursAgo",{count:c}):`${c} hours ago`:d===1?n?n("time.oneDayAgo"):"1 day ago":d<7?n?n("time.daysAgo",{count:d}):`${d} days ago`:r.toLocaleDateString()};function nk({isStarred:e,canDelete:t,onRename:n,onToggleStar:r,onDelete:a,t:s,className:o}){const l=d=>i.jsx(Ea,{className:`${d.className??""} ${e?"fill-yellow-400 text-yellow-500":""}`}),c=[{id:"rename",label:s("actions.rename"),icon:rE,onClick:n},{id:"star",label:e?s("actions.unstarSession",{defaultValue:"Remove star"}):s("actions.starSession",{defaultValue:"Star"}),icon:l,onClick:r}];return t&&c.push({id:"delete",label:s("actions.delete"),icon:En,onClick:a,danger:!0}),i.jsx(sN,{actions:c,className:o,triggerLabel:s("tooltips.sessionActions",{defaultValue:"Session actions"})})}const IM={claude:"Claude",cursor:"Cursor",codex:"Codex",gemini:"Gemini",qwen:"Qwen Code",opencode:"OpenCode"},rk={claude:"bg-orange-500/10 text-orange-600 dark:bg-orange-400/10 dark:text-orange-300 ring-1 ring-orange-500/15",cursor:"bg-sky-500/10 text-sky-600 dark:bg-sky-400/10 dark:text-sky-300 ring-1 ring-sky-500/15",codex:"bg-violet-500/10 text-violet-600 dark:bg-violet-400/10 dark:text-violet-300 ring-1 ring-violet-500/15",gemini:"bg-emerald-500/10 text-emerald-600 dark:bg-emerald-400/10 dark:text-emerald-300 ring-1 ring-emerald-500/15",qwen:"bg-amber-500/10 text-amber-600 dark:bg-amber-400/10 dark:text-amber-300 ring-1 ring-amber-500/15",opencode:"bg-teal-500/10 text-teal-600 dark:bg-teal-400/10 dark:text-teal-300 ring-1 ring-teal-500/15"};function oN({project:e,session:t,selectedSession:n,currentTime:r,editingSession:a,editingSessionName:s,isStarred:o,compact:l=!1,onEditingSessionNameChange:c,onStartEditingSession:d,onCancelEditingSession:u,onSaveEditingSession:p,onToggleStarSession:f,onProjectSelect:h,onSessionSelect:g,onDeleteSession:b,t:x}){const v=eM(t,r,x),y=n?.id===t.id,w=a===t.id,k=t.__provider,S=IM[k]??k,C=rk[k]??rk.claude,N=XO(v.sessionName),R=()=>{h(e),g(t,e.name)},A=()=>{p(e.name,t.id,s,k)},j=()=>{b(e.name,t.id,v.sessionName,k)},L=()=>d(t.id,v.sessionName),T=()=>f(e.name,t.id),_=i.jsxs("div",{className:"mt-0.5 flex min-w-0 flex-wrap items-center gap-1 text-[10px] leading-tight",children:[i.jsxs("span",{className:me("inline-flex items-center gap-1 rounded-full px-1.5 py-px font-medium",C),children:[i.jsx(yn,{provider:k,className:"h-2.5 w-2.5"}),S]}),i.jsx("span",{className:"text-muted-foreground/80",children:_M(v.sessionTime,r,x)}),v.isActive&&i.jsxs("span",{className:"inline-flex items-center gap-1 text-green-600 dark:text-green-400",children:[i.jsx("span",{className:"h-1.5 w-1.5 animate-pulse rounded-full bg-green-500"}),x("status.active",{defaultValue:"Active"})]}),N.slice(0,3).map(B=>i.jsxs("span",{className:"rounded-md bg-muted/60 px-1 py-px font-mono text-[9px] uppercase tracking-wide text-muted-foreground ring-1 ring-border/40",children:[".",B]},B))]}),E=i.jsxs(i.Fragment,{children:[i.jsx("input",{type:"text",value:s,onChange:B=>c(B.target.value),onKeyDown:B=>{B.stopPropagation(),B.key==="Enter"?A():B.key==="Escape"&&u()},onClick:B=>B.stopPropagation(),className:"w-full rounded-md border border-primary/40 bg-background px-2 py-1 text-xs focus:outline-none focus:ring-1 focus:ring-primary",autoFocus:!0}),i.jsx("button",{className:"flex h-6 w-6 items-center justify-center rounded-md bg-green-50 hover:bg-green-100 dark:bg-green-900/20 dark:hover:bg-green-900/40",onClick:B=>{B.stopPropagation(),A()},title:x("tooltips.save"),children:i.jsx(Ht,{className:"h-3 w-3 text-green-600 dark:text-green-400"})}),i.jsx("button",{className:"flex h-6 w-6 items-center justify-center rounded-md bg-gray-50 hover:bg-gray-100 dark:bg-gray-900/20 dark:hover:bg-gray-900/40",onClick:B=>{B.stopPropagation(),u()},title:x("tooltips.cancel"),children:i.jsx(ht,{className:"h-3 w-3 text-gray-600 dark:text-gray-400"})})]}),O=i.jsx("div",{className:"md:hidden",children:i.jsx("div",{className:me("relative mx-3 my-0.5 rounded-lg border border-border/30 bg-card p-2 transition-all duration-150 active:scale-[0.98]",y&&"border-primary/30 bg-primary/5 shadow-sm",!y&&v.isActive&&"border-green-500/25 bg-green-50/5 dark:bg-green-900/5",o&&!y&&"ring-1 ring-yellow-300/50 dark:ring-yellow-500/30"),onClick:w?void 0:R,children:w?i.jsx("div",{className:"flex items-center gap-1",children:E}):i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("div",{className:me("flex h-6 w-6 flex-shrink-0 items-center justify-center rounded-md",y?"bg-primary/10":"bg-muted/60"),children:i.jsx(yn,{provider:k,className:"h-3 w-3"})}),i.jsxs("div",{className:"min-w-0 flex-1",children:[i.jsxs("div",{className:"flex items-center gap-1",children:[o&&i.jsx("span",{className:"text-yellow-500","aria-hidden":!0,children:"★"}),i.jsx("span",{className:"truncate text-xs font-medium text-foreground",children:v.sessionName})]}),_]}),i.jsx("div",{className:"flex-shrink-0",onClick:B=>B.stopPropagation(),children:i.jsx(nk,{isStarred:o,canDelete:!v.isCursorSession,onRename:L,onToggleStar:T,onDelete:j,t:x,className:"!opacity-100"})})]})})}),$=i.jsxs("div",{className:me("group/item relative hidden md:block"),children:[i.jsxs(Ae,{variant:"ghost",className:me("relative h-auto w-full justify-start overflow-hidden p-0 text-left font-normal transition-colors duration-150","hover:bg-accent/60",y&&"bg-accent text-accent-foreground",o&&!y&&"bg-yellow-50/40 hover:bg-yellow-100/40 dark:bg-yellow-900/10 dark:hover:bg-yellow-900/20",l?"rounded-xl px-3 py-2.5":"rounded-lg px-3 py-2"),onClick:w?void 0:()=>g(t,e.name),children:[y&&i.jsx("span",{"aria-hidden":!0,className:"absolute left-0 top-1/2 h-5 w-0.5 -translate-y-1/2 rounded-r bg-primary"}),!y&&!w&&i.jsx("span",{"aria-hidden":!0,className:"session-item-accent"}),i.jsxs("div",{className:"flex w-full min-w-0 items-start gap-2 pr-6",children:[i.jsx("div",{className:me("mt-0.5 flex h-5 w-5 flex-shrink-0 items-center justify-center rounded-md",y?"bg-primary/10":"bg-muted/50 group-hover/item:bg-muted/80"),children:i.jsx(yn,{provider:k,className:"h-3 w-3"})}),i.jsx("div",{className:"min-w-0 flex-1",children:w?i.jsx("div",{className:"flex items-center gap-1",children:E}):i.jsxs(i.Fragment,{children:[i.jsxs("div",{className:"flex min-w-0 items-center gap-1",children:[o&&i.jsx("span",{className:"flex-shrink-0 text-yellow-500","aria-hidden":!0,children:"★"}),i.jsx("span",{className:"truncate text-xs font-medium text-foreground",children:v.sessionName})]}),_]})})]})]}),!w&&i.jsx("div",{className:"absolute right-1.5 top-1/2 -translate-y-1/2",onClick:B=>B.stopPropagation(),children:i.jsx(nk,{isStarred:o,canDelete:!v.isCursorSession,onRename:L,onToggleStar:T,onDelete:j,t:x,className:"opacity-0 focus-visible:opacity-100 group-hover/item:opacity-100"})})]});return i.jsxs("div",{className:"group relative",children:[O,$]})}function LM(){return i.jsx(i.Fragment,{children:Array.from({length:3}).map((e,t)=>i.jsx("div",{className:"rounded-md p-2",children:i.jsxs("div",{className:"flex items-start gap-2",children:[i.jsx("div",{className:"mt-0.5 h-3 w-3 animate-pulse rounded-full bg-muted"}),i.jsxs("div",{className:"flex-1 space-y-1",children:[i.jsx("div",{className:"h-3 animate-pulse rounded bg-muted",style:{width:`${60+t*15}%`}}),i.jsx("div",{className:"h-2 w-1/2 animate-pulse rounded bg-muted"})]})]})},t))})}function PM({project:e,isExpanded:t,sessions:n,selectedSession:r,initialSessionsLoaded:a,isLoadingSessions:s,currentTime:o,editingSession:l,editingSessionName:c,isSessionStarred:d,onEditingSessionNameChange:u,onStartEditingSession:p,onCancelEditingSession:f,onSaveEditingSession:h,onToggleStarSession:g,onProjectSelect:b,onSessionSelect:x,onDeleteSession:v,onLoadMoreSessions:y,onNewSession:w,t:k}){if(!t)return null;const S=n.length>0,C=e.sessionMeta?.hasMore===!0;return i.jsxs("div",{className:"ml-3 space-y-1 border-l border-border pl-3",children:[i.jsx("div",{className:"px-3 pb-1 pt-1 md:hidden",children:i.jsxs("button",{className:"flex h-8 w-full items-center justify-center gap-2 rounded-md bg-primary text-xs font-medium text-primary-foreground transition-all duration-150 hover:bg-primary/90 active:scale-[0.98]",onClick:()=>{b(e),w(e)},children:[i.jsx(Gt,{className:"h-3 w-3"}),k("sessions.newSession")]})}),i.jsxs(Ae,{variant:"default",size:"sm",className:"hidden h-8 w-full justify-start gap-2 bg-primary text-xs font-medium text-primary-foreground transition-colors hover:bg-primary/90 md:flex",onClick:()=>w(e),children:[i.jsx(Gt,{className:"h-3 w-3"}),k("sessions.newSession")]}),a?!S&&!s?i.jsx("div",{className:"px-3 py-2 text-left",children:i.jsx("p",{className:"text-xs text-muted-foreground",children:k("sessions.noSessions")})}):n.map(N=>i.jsx(oN,{project:e,session:N,selectedSession:r,currentTime:o,editingSession:l,editingSessionName:c,isStarred:d(e.name,N.id),onEditingSessionNameChange:u,onStartEditingSession:p,onCancelEditingSession:f,onSaveEditingSession:h,onToggleStarSession:g,onProjectSelect:b,onSessionSelect:x,onDeleteSession:v,t:k},N.id)):i.jsx(LM,{}),S&&C&&i.jsx(Ae,{variant:"ghost",size:"sm",className:"mt-2 w-full justify-center gap-2 text-muted-foreground",onClick:()=>y(e),disabled:s,children:s?i.jsxs(i.Fragment,{children:[i.jsx("div",{className:"h-3 w-3 animate-spin rounded-full border border-muted-foreground border-t-transparent"}),k("sessions.loading")]}):i.jsxs(i.Fragment,{children:[i.jsx(Dr,{className:"h-3 w-3"}),k("sessions.showMore")]})})]})}const DM=(e,t)=>{const n=e.length;return t&&n>=5?`${n}+`:`${n}`};function OM({project:e,selectedProject:t,selectedSession:n,isExpanded:r,isDeleting:a,isStarred:s,editingProject:o,editingName:l,sessions:c,initialSessionsLoaded:d,isLoadingSessions:u,currentTime:p,editingSession:f,editingSessionName:h,isSessionStarred:g,onEditingNameChange:b,onToggleProject:x,onProjectSelect:v,onToggleStarProject:y,onToggleStarSession:w,onStartEditingProject:k,onCancelEditingProject:S,onSaveProjectName:C,onDeleteProject:N,onSessionSelect:R,onDeleteSession:A,onLoadMoreSessions:j,onNewSession:L,onEditingSessionNameChange:T,onStartEditingSession:_,onCancelEditingSession:E,onSaveEditingSession:O,t:$}){const B=t?.name===e.name,K=o===e.name,Y=e.sessionMeta?.hasMore===!0,P=DM(c,Y),z=`${P} session${c.length===1?"":"s"}`,U=()=>x(e.name),F=()=>y(e.name),J=()=>{C(e.name)},ae=()=>{t?.name!==e.name&&v(e),U()};return i.jsxs("div",{className:me("md:space-y-1",a&&"opacity-50 pointer-events-none"),children:[i.jsxs("div",{className:"md:group group",children:[i.jsx("div",{className:"md:hidden",children:i.jsx("div",{className:me("p-3 mx-3 my-1 rounded-lg bg-card border border-border/50 active:scale-[0.98] transition-all duration-150",B&&"bg-primary/5 border-primary/20",s&&!B&&"bg-yellow-50/50 dark:bg-yellow-900/5 border-yellow-200/30 dark:border-yellow-800/30"),onClick:U,children:i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-3",children:[i.jsx("div",{className:me("w-8 h-8 rounded-lg flex items-center justify-center transition-colors",r?"bg-primary/10":"bg-muted"),children:r?i.jsx(Sr,{className:"h-4 w-4 text-primary"}):i.jsx(On,{className:"h-4 w-4 text-muted-foreground"})}),i.jsx("div",{className:"min-w-0 flex-1",children:K?i.jsx("input",{type:"text",value:l,onChange:Q=>b(Q.target.value),className:"w-full rounded-lg border-2 border-primary/40 bg-background px-3 py-2 text-sm text-foreground shadow-sm transition-all duration-200 focus:border-primary focus:shadow-md focus:outline-none",placeholder:$("projects.projectNamePlaceholder"),autoFocus:!0,autoComplete:"off",onClick:Q=>Q.stopPropagation(),onKeyDown:Q=>{Q.key==="Enter"&&J(),Q.key==="Escape"&&S()},style:{fontSize:"16px",WebkitAppearance:"none",borderRadius:"8px"}}):i.jsxs(i.Fragment,{children:[i.jsx("div",{className:"flex min-w-0 flex-1 items-center justify-between",children:i.jsx("h3",{className:"truncate text-sm font-medium text-foreground",children:e.displayName})}),i.jsx("p",{className:"text-xs text-muted-foreground",children:z})]})})]}),i.jsx("div",{className:"flex items-center gap-1",children:K?i.jsxs(i.Fragment,{children:[i.jsx("button",{className:"flex h-8 w-8 items-center justify-center rounded-lg bg-green-500 shadow-sm transition-all duration-150 active:scale-90 active:shadow-none dark:bg-green-600",onClick:Q=>{Q.stopPropagation(),J()},children:i.jsx(Ht,{className:"h-4 w-4 text-white"})}),i.jsx("button",{className:"flex h-8 w-8 items-center justify-center rounded-lg bg-gray-500 shadow-sm transition-all duration-150 active:scale-90 active:shadow-none dark:bg-gray-600",onClick:Q=>{Q.stopPropagation(),S()},children:i.jsx(ht,{className:"h-4 w-4 text-white"})})]}):i.jsxs(i.Fragment,{children:[i.jsx("button",{className:me("w-8 h-8 rounded-lg flex items-center justify-center active:scale-90 transition-all duration-150 border",s?"bg-yellow-500/10 dark:bg-yellow-900/30 border-yellow-200 dark:border-yellow-800":"bg-gray-500/10 dark:bg-gray-900/30 border-gray-200 dark:border-gray-800"),onClick:Q=>{Q.stopPropagation(),F()},title:$(s?"tooltips.removeFromFavorites":"tooltips.addToFavorites"),children:i.jsx(Ea,{className:me("w-4 h-4 transition-colors",s?"text-yellow-600 dark:text-yellow-400 fill-current":"text-gray-600 dark:text-gray-400")})}),i.jsx("button",{className:"flex h-8 w-8 items-center justify-center rounded-lg border border-red-200 bg-red-500/10 active:scale-90 dark:border-red-800 dark:bg-red-900/30",onClick:Q=>{Q.stopPropagation(),N(e)},children:i.jsx(En,{className:"h-4 w-4 text-red-600 dark:text-red-400"})}),i.jsx("button",{className:"flex h-8 w-8 items-center justify-center rounded-lg border border-primary/20 bg-primary/10 active:scale-90 dark:border-primary/30 dark:bg-primary/20",onClick:Q=>{Q.stopPropagation(),k(e)},children:i.jsx(jh,{className:"h-4 w-4 text-primary"})}),i.jsx("div",{className:"flex h-6 w-6 items-center justify-center rounded-md bg-muted/30",children:r?i.jsx(Dr,{className:"h-3 w-3 text-muted-foreground"}):i.jsx(li,{className:"h-3 w-3 text-muted-foreground"})})]})})]})})}),i.jsxs(Ae,{variant:"ghost",className:me("hidden md:flex w-full justify-between p-2 h-auto font-normal hover:bg-accent/50",B&&"bg-accent text-accent-foreground",s&&!B&&"bg-yellow-50/50 dark:bg-yellow-900/10 hover:bg-yellow-100/50 dark:hover:bg-yellow-900/20"),onClick:ae,children:[i.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-3",children:[r?i.jsx(Sr,{className:"h-4 w-4 flex-shrink-0 text-primary"}):i.jsx(On,{className:"h-4 w-4 flex-shrink-0 text-muted-foreground"}),i.jsx("div",{className:"min-w-0 flex-1 text-left",children:K?i.jsxs("div",{className:"space-y-1",children:[i.jsx("input",{type:"text",value:l,onChange:Q=>b(Q.target.value),className:"w-full rounded border border-border bg-background px-2 py-1 text-sm text-foreground focus:ring-2 focus:ring-primary/20",placeholder:$("projects.projectNamePlaceholder"),autoFocus:!0,onKeyDown:Q=>{Q.key==="Enter"&&J(),Q.key==="Escape"&&S()}}),i.jsx("div",{className:"truncate text-xs text-muted-foreground",title:e.fullPath,children:e.fullPath})]}):i.jsxs("div",{children:[i.jsx("div",{className:"truncate text-sm font-semibold text-foreground",title:e.displayName,children:e.displayName}),i.jsxs("div",{className:"text-xs text-muted-foreground",children:[P,e.fullPath!==e.displayName&&i.jsxs("span",{className:"ml-1 opacity-60",title:e.fullPath,children:[" - ",e.fullPath.length>25?`...${e.fullPath.slice(-22)}`:e.fullPath]})]})]})})]}),i.jsx("div",{className:"flex flex-shrink-0 items-center gap-1",children:K?i.jsxs(i.Fragment,{children:[i.jsx("div",{className:"flex h-6 w-6 cursor-pointer items-center justify-center rounded text-green-600 transition-colors hover:bg-green-50 hover:text-green-700 dark:hover:bg-green-900/20",onClick:Q=>{Q.stopPropagation(),J()},children:i.jsx(Ht,{className:"h-3 w-3"})}),i.jsx("div",{className:"flex h-6 w-6 cursor-pointer items-center justify-center rounded text-gray-500 transition-colors hover:bg-gray-50 hover:text-gray-700 dark:hover:bg-gray-800",onClick:Q=>{Q.stopPropagation(),S()},children:i.jsx(ht,{className:"h-3 w-3"})})]}):i.jsxs(i.Fragment,{children:[s&&i.jsx("div",{className:"flex h-6 w-6 cursor-pointer items-center justify-center rounded hover:bg-yellow-50 dark:hover:bg-yellow-900/20",onClick:Q=>{Q.stopPropagation(),F()},title:$("tooltips.removeFromFavorites"),children:i.jsx(Ea,{className:"h-3 w-3 fill-current text-yellow-600 dark:text-yellow-400"})}),i.jsx(sN,{triggerLabel:$("tooltips.projectActions",{defaultValue:"Project actions"}),actions:[{id:"rename",label:$("actions.rename"),icon:jh,onClick:()=>k(e)},{id:"star",label:$(s?"tooltips.removeFromFavorites":"tooltips.addToFavorites"),icon:Ea,onClick:F},{id:"delete",label:$("actions.delete",{defaultValue:"Delete"}),icon:En,onClick:()=>N(e),danger:!0}]}),r?i.jsx(Dr,{className:"h-4 w-4 text-muted-foreground transition-colors group-hover:text-foreground"}):i.jsx(li,{className:"h-4 w-4 text-muted-foreground transition-colors group-hover:text-foreground"})]})})]})]}),i.jsx(PM,{project:e,isExpanded:r,sessions:c,selectedSession:n,initialSessionsLoaded:d,isLoadingSessions:u,currentTime:p,editingSession:f,editingSessionName:h,isSessionStarred:g,onEditingSessionNameChange:T,onStartEditingSession:_,onCancelEditingSession:E,onSaveEditingSession:O,onToggleStarSession:w,onProjectSelect:v,onSessionSelect:R,onDeleteSession:A,onLoadMoreSessions:j,onNewSession:L,t:$})]})}function lN({isLoading:e,loadingProgress:t,projectsCount:n,filteredProjectsCount:r,t:a}){return e?i.jsxs("div",{className:"px-4 py-12 text-center md:py-8",children:[i.jsx("div",{className:"mx-auto mb-4 flex h-12 w-12 items-center justify-center rounded-lg bg-muted md:mb-3",children:i.jsx("div",{className:"h-6 w-6 animate-spin rounded-full border-2 border-muted-foreground border-t-transparent"})}),i.jsx("h3",{className:"mb-2 text-base font-medium text-foreground md:mb-1",children:a("projects.loadingProjects")}),t&&t.total>0?i.jsxs("div",{className:"space-y-2",children:[i.jsx("div",{className:"h-2 w-full overflow-hidden rounded-full bg-muted",children:i.jsx("div",{className:"h-full bg-primary transition-all duration-300 ease-out",style:{width:`${t.current/t.total*100}%`}})}),i.jsxs("p",{className:"text-sm text-muted-foreground",children:[t.current,"/",t.total," ",a("projects.projects")]}),t.currentProject&&i.jsx("p",{className:"mx-auto max-w-[200px] truncate text-xs text-muted-foreground/70",title:t.currentProject,children:t.currentProject.split("-").slice(-2).join("/")})]}):i.jsx("p",{className:"text-sm text-muted-foreground",children:a("projects.fetchingProjects")})]}):n===0?i.jsxs("div",{className:"px-4 py-12 text-center md:py-8",children:[i.jsx("div",{className:"mx-auto mb-4 flex h-12 w-12 items-center justify-center rounded-lg bg-muted md:mb-3",children:i.jsx(On,{className:"h-6 w-6 text-muted-foreground"})}),i.jsx("h3",{className:"mb-2 text-base font-medium text-foreground md:mb-1",children:a("projects.noProjects")}),i.jsx("p",{className:"text-sm text-muted-foreground",children:a("projects.runClaudeCli")})]}):r===0?i.jsxs("div",{className:"px-4 py-12 text-center md:py-8",children:[i.jsx("div",{className:"mx-auto mb-4 flex h-12 w-12 items-center justify-center rounded-lg bg-muted md:mb-3",children:i.jsx(ja,{className:"h-6 w-6 text-muted-foreground"})}),i.jsx("h3",{className:"mb-2 text-base font-medium text-foreground md:mb-1",children:a("projects.noMatchingProjects")}),i.jsx("p",{className:"text-sm text-muted-foreground",children:a("projects.tryDifferentSearch")})]}):null}function MM({projects:e,filteredProjects:t,selectedProject:n,selectedSession:r,isLoading:a,loadingProgress:s,expandedProjects:o,editingProject:l,editingName:c,loadingSessions:d,initialSessionsLoaded:u,currentTime:p,editingSession:f,editingSessionName:h,deletingProjects:g,getProjectSessions:b,isProjectStarred:x,isSessionStarred:v,onEditingNameChange:y,onToggleProject:w,onProjectSelect:k,onToggleStarProject:S,onToggleStarSession:C,onStartEditingProject:N,onCancelEditingProject:R,onSaveProjectName:A,onDeleteProject:j,onSessionSelect:L,onDeleteSession:T,onLoadMoreSessions:_,onNewSession:E,onEditingSessionNameChange:O,onStartEditingSession:$,onCancelEditingSession:B,onSaveEditingSession:K,t:Y}){const P=i.jsx(lN,{isLoading:a,loadingProgress:s,projectsCount:e.length,filteredProjectsCount:t.length,t:Y});m.useEffect(()=>{let Q="Pixcode";const pe=n?.displayName?.trim();pe&&(Q=`${pe} - ${Q}`),document.title=Q},[n]);const z=!a&&e.length>0&&t.length>0,U=Q=>Q.source==="history"||Q.autoDiscovered===!0&&Q.isManuallyAdded!==!0,F=t.filter(Q=>!U(Q)),J=t.filter(Q=>U(Q)),ae=Q=>i.jsx(OM,{project:Q,selectedProject:n,selectedSession:r,isExpanded:o.has(Q.name),isDeleting:g.has(Q.name),isStarred:x(Q.name),editingProject:l,editingName:c,sessions:b(Q),initialSessionsLoaded:u.has(Q.name),isLoadingSessions:!!d[Q.name],currentTime:p,editingSession:f,editingSessionName:h,isSessionStarred:v,onEditingNameChange:y,onToggleProject:w,onProjectSelect:k,onToggleStarProject:S,onToggleStarSession:C,onStartEditingProject:N,onCancelEditingProject:R,onSaveProjectName:A,onDeleteProject:j,onSessionSelect:L,onDeleteSession:T,onLoadMoreSessions:_,onNewSession:E,onEditingSessionNameChange:O,onStartEditingSession:$,onCancelEditingSession:B,onSaveEditingSession:K,t:Y},Q.name);return i.jsx("div",{className:"pb-safe-area-inset-bottom md:space-y-1",children:z?i.jsxs(i.Fragment,{children:[F.map(Q=>ae(Q)),J.length>0&&i.jsxs(i.Fragment,{children:[i.jsx("div",{className:"px-3 pb-1 pt-3 text-[11px] font-semibold uppercase tracking-wide text-gray-500 dark:text-gray-400",children:Y("projects.detectedFromHistory")}),J.map(Q=>ae(Q))]})]}):P})}function wa(e){if(e===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function cN(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,e.__proto__=t}/*!
|
|
259
|
+
*/const SD=[["rect",{width:"8",height:"8",x:"3",y:"3",rx:"2",key:"by2w9f"}],["path",{d:"M7 11v4a2 2 0 0 0 2 2h4",key:"xkn7yn"}],["rect",{width:"8",height:"8",x:"13",y:"13",rx:"2",key:"1cgmvn"}]],CD=Et("workflow",SD),Z4=z4,ED=P7,Tw=R7,ND=w7,X4=N7,TD=F4,Dr=$4,Q4=g8,li=x8,AD=y8,tr=A7,la=F4,Ed=I7,J4=C7,mu=u8,hu=m8,eE=O7,nt=B4,Dt=B4,fu=B7,jD=F7,RD=kL,Bi=W8,Cn=q8,Ht=c8,Ki=o8,tE=cL,In=zL,Gl=V4,_D=V4,Nd=Q7,Zs=k8,gu=H4,dl=T8,kl=M8,$n=z8,On=rL,Sr=J8,ci=tL,ID=TL,LD=oL,nE=hL,PD=LL,DD=$7,OD=e8,MD=QL,rE=W4,jh=CL,Aw=W4,Gt=jL,En=eP,aE=U8,ja=xL,ht=q4,Rh=q4,FD=VL,Jf=K7,zD=V7,Td=G7,BD=H8,Wr=U4,UD=U4,$D=nP,Xs=aP,eg=a8,Sl=n8,tg=E8,Wl=X8,ng=Y8,Vr=iL,iE=H4,bu=G4,HD=G4,sE=pL,mr=gL,oE=yL,rg=L8,lE=ZL,cE=_L,go=ML,GD=DL,Pt=j8,Ad=b7,Vl=D8,Vn=$L,Ea=GL,dE=KL,_n=_8,ag=Z7,WD=hP,xu=yP,ig=Y4,VD=Y4,Nn=tD,rd=rD,vu=iD,hs=pP,fs=gP,qD=xP,Yo=kP,Us=CP,jw=TP,Zo=jP,_o=LP,KD=DP,uE=qP,_h=MP,$r=UP,Io=zP,Rw=HP,Lo=WP,Ih=YP,YD=XP,Lh=JP,Ds=oD,Xo=cD,Wa=uD,gs=mD,ZD=fD,Ph=bD,XD=yD,Po=kD,Cl=CD,yu=_P,QD=[{type:"key",id:"ctrl-c",label:"Ctrl-C",sequence:""},{type:"key",id:"ctrl-d",label:"Ctrl-D",sequence:""},{type:"key",id:"ctrl-l",label:"Ctrl-L",sequence:"\f"},{type:"key",id:"ctrl-z",label:"Ctrl-Z",sequence:""},{type:"key",id:"esc",label:"Esc",sequence:"\x1B"},{type:"key",id:"tab",label:"Tab",sequence:" "},{type:"key",id:"enter",label:"Enter",sequence:"\r"},{type:"key",id:"shift-tab",label:"⇧Tab",sequence:"\x1B[Z"},{type:"modifier",id:"ctrl",label:"CTRL",modifier:"ctrl"},{type:"modifier",id:"alt",label:"ALT",modifier:"alt"},{type:"arrow",id:"arrow-up",sequence:"\x1B[A",icon:"up"},{type:"arrow",id:"arrow-down",sequence:"\x1B[B",icon:"down"},{type:"arrow",id:"arrow-left",sequence:"\x1B[D",icon:"left"},{type:"arrow",id:"arrow-right",sequence:"\x1B[C",icon:"right"}],JD={up:ED,down:Z4,left:ND,right:X4},Do=e=>e.preventDefault(),_w="shrink-0 rounded-md border border-gray-600 bg-gray-700 px-2.5 py-1.5 text-xs font-medium text-gray-100 transition-colors select-none active:bg-blue-600 active:text-white active:border-blue-600 disabled:cursor-not-allowed disabled:opacity-40",eO="shrink-0 rounded-md border border-blue-500 bg-blue-600 px-2.5 py-1.5 text-xs font-medium text-white transition-colors select-none disabled:cursor-not-allowed disabled:opacity-40",xp="shrink-0 rounded-md border border-gray-600 bg-gray-700 p-1.5 text-gray-100 transition-colors select-none active:bg-blue-600 active:text-white active:border-blue-600 disabled:cursor-not-allowed disabled:opacity-40";function Iw({wsRef:e,terminalRef:t,isConnected:n,bottomOffset:r="bottom-0",placement:a="fixed"}){const{t:s}=Fe("settings"),[o,l]=m.useState(!1),[c,d]=m.useState(!1),[u,p]=m.useState(!1),f=m.useCallback(x=>{Cd(e.current,x)},[e]),h=m.useCallback(()=>{t.current?.scrollToBottom()},[t]),g=m.useCallback(async()=>{if(typeof navigator>"u"||!navigator.clipboard?.readText){p(!0);return}try{const x=await navigator.clipboard.readText();p(!1),x.length>0&&f(x)}catch{p(!0)}},[f]);m.useEffect(()=>{if(!u)return;const x=window.setTimeout(()=>p(!1),2500);return()=>window.clearTimeout(x)},[u]);const b=m.useCallback(x=>{let v=x;if(o&&x.length===1){const y=x.toLowerCase().charCodeAt(0);y>=97&&y<=122&&(v=String.fromCharCode(y-96)),l(!1)}c&&x.length===1&&(v="\x1B"+v,d(!1)),f(v)},[o,c,f]);return i.jsx("div",{className:`pointer-events-none ${a} inset-x-0 ${r} z-40 px-2 pb-[max(env(safe-area-inset-bottom),0px)] md:hidden`,children:i.jsxs("div",{className:"pointer-events-auto flex items-center gap-1 overflow-x-auto rounded-lg border border-gray-700/80 bg-gray-900/95 px-1.5 py-1.5 shadow-lg backdrop-blur-sm [-webkit-overflow-scrolling:touch] [scrollbar-width:none] [&::-webkit-scrollbar]:hidden",children:[u&&i.jsx("span",{className:"shrink-0 rounded-md border border-yellow-500/50 bg-yellow-500/15 px-2 py-1 text-[11px] text-yellow-100",children:"Clipboard blocked"}),i.jsx("button",{type:"button",onPointerDown:Do,onClick:()=>{g()},disabled:!n,className:xp,title:s("terminalShortcuts.paste",{defaultValue:"Paste"}),"aria-label":s("terminalShortcuts.paste",{defaultValue:"Paste"}),children:i.jsx(Zs,{className:"h-4 w-4"})}),QD.map(x=>{if(x.type==="modifier"){const v=x.modifier==="ctrl"?o:c,y=x.modifier==="ctrl"?()=>l(w=>!w):()=>d(w=>!w);return i.jsx("button",{type:"button",onPointerDown:Do,onClick:y,disabled:!n,className:v?eO:_w,children:x.label},x.id)}if(x.type==="arrow"){const v=JD[x.icon];return i.jsx("button",{type:"button",onPointerDown:Do,onClick:()=>f(x.sequence),disabled:!n,className:xp,children:i.jsx(v,{className:"h-4 w-4"})},x.id)}return i.jsx("button",{type:"button",onPointerDown:Do,onClick:()=>b(x.sequence),disabled:!n,className:_w,children:x.label},x.id)}),i.jsx("button",{type:"button",onPointerDown:Do,onClick:h,disabled:!n,className:xp,title:s("terminalShortcuts.scrollDown"),"aria-label":s("terminalShortcuts.scrollDown"),children:i.jsx(TD,{className:"h-4 w-4"})})]})})}function tO({tabId:e,selectedProject:t=null,selectedSession:n=null,initialCommand:r=null,isPlainShell:a=!1,onProcessComplete:s=null,minimal:o=!1,autoConnect:l=!1,forceNewSession:c=!1,startupInput:d=null,permissionOverride:u=null,provider:p=null,isActive:f=!0,layoutSignal:h=null,onClose:g=null,immersive:b=!1,showHeader:x=!0}){const{t:v}=Fe("chat"),[y,w]=m.useState(!1),[k,S]=m.useState(null),C=m.useRef(null),N=m.useRef(null),{terminalContainerRef:R,terminalRef:A,wsRef:j,isConnected:L,isInitialized:T,isConnecting:_,authUrl:E,authUrlVersion:O,connectToShell:$,disconnectFromShell:B,openAuthUrlInBrowser:K,copyAuthUrlToClipboard:Y}=u7({tabId:e,selectedProject:t,selectedSession:n,initialCommand:r,isPlainShell:a,minimal:o,autoConnect:l,forceNewSession:c,startupInput:d,permissionOverride:u,provider:p,isActive:f,layoutSignal:h,isRestarting:y,onProcessComplete:s,onOutputRef:N}),P=m.useCallback(()=>{const de=A.current;if(!de)return;const ce=de.buffer.active,V=ce.baseY+ce.cursorY,Z=Math.min(ce.baseY+ce.length-1,V+10),se=Math.max(0,V-yI),ge=[];for(let W=se;W<=Z;W++){const G=ce.getLine(W);G&&ge.push(G.translateToString().trimEnd())}let ee=-1;for(let W=ge.length-1;W>=0;W--)if(/esc to cancel/i.test(ge[W])||/enter to select/i.test(ge[W])){ee=W;break}if(ee===-1){S(null);return}const te=new Map,ve=Math.max(0,ee-wI);for(let W=ee-1;W>=ve;W--){const G=ge[W].match(/^\s*[❯›>]?\s*(\d+)\.\s+(.+)/);if(G){const ne=G[1],he=G[2].trim();parseInt(ne,10)<=kI&&he.length>0&&!te.has(ne)&&te.set(ne,he)}}const le=[];for(let W=1;W<=te.size&&te.has(String(W));W++)le.push({number:String(W),label:te.get(String(W))});S(le.length>=SI?le:null)},[A]),z=m.useCallback(()=>{C.current&&clearTimeout(C.current),C.current=setTimeout(P,vI)},[P]);m.useEffect(()=>{N.current=z},[z]),m.useEffect(()=>()=>{C.current&&clearTimeout(C.current)},[]),m.useEffect(()=>{L||(C.current&&(clearTimeout(C.current),C.current=null),S(null))},[L]),m.useEffect(()=>{if(!f||!T||!L)return;const de=()=>{A.current?.focus()},ce=window.requestAnimationFrame(de),V=window.setTimeout(de,0);return()=>{window.cancelAnimationFrame(ce),window.clearTimeout(V)}},[f,L,T,A]);const U=m.useCallback(de=>{Cd(j.current,de)},[j]),F=m.useMemo(()=>HI(n),[n]),J=m.useMemo(()=>p||(n?.__provider?n.__provider:window.localStorage.getItem("selected-provider")||"claude"),[p,n?.__provider]),ae=Rn[J]??"Claude Code",Q=m.useMemo(()=>F?F.slice(0,30):null,[F]),pe=m.useMemo(()=>F?F.slice(0,50):null,[F]),oe=m.useCallback(()=>{w(!0),window.setTimeout(()=>{w(!1)},bI)},[]),fe=m.useCallback(()=>{B(),g?.()},[B,g]);if(!t)return i.jsx(m7,{title:v("shell.selectProject.title"),description:v("shell.selectProject.description")});if(o)return i.jsxs(i.Fragment,{children:[i.jsx(f7,{terminalContainerRef:R,authUrl:E,authUrlVersion:O,initialCommand:r,isConnected:L,openAuthUrlInBrowser:K,copyAuthUrlToClipboard:Y}),i.jsx(Iw,{wsRef:j,terminalRef:A,isConnected:L,bottomOffset:"bottom-0"})]});const be=a?v("shell.runCommand",{command:r||v("shell.defaultCommand"),projectName:t.displayName}):n?v("shell.resumeSession",{displayName:pe}):v("shell.startProviderSession",{provider:ae,defaultValue:"Start a new {{provider}} session"}),Ce=a?v("shell.runCommand",{command:r||v("shell.defaultCommand"),projectName:t.displayName}):v("shell.startProviderCli",{provider:ae,projectName:t.displayName,defaultValue:"Starting {{provider}} in {{projectName}}"}),Se=T?_?"connecting":L?null:"connect":"loading",Te=Se==="connecting"?Ce:be,M=typeof h=="string"&&h.startsWith("right-cli:");return i.jsxs("div",{className:me("flex h-full min-w-0 w-full flex-col overflow-hidden bg-gray-900",b&&"bg-gray-950"),children:[x&&i.jsx(h7,{isConnected:L,isInitialized:T,isRestarting:y,hasSession:!!n,sessionDisplayNameShort:Q,onDisconnect:fe,onRestart:oe,statusNewSessionText:v("shell.status.newSession"),statusInitializingText:v("shell.status.initializing"),statusRestartingText:v("shell.status.restarting"),disconnectLabel:v("shell.actions.disconnect"),disconnectTitle:v("shell.actions.disconnectTitle"),restartLabel:v("shell.actions.restart"),restartTitle:v("shell.actions.restartTitle"),disableRestart:y||L}),i.jsxs("div",{className:me("relative min-h-0 min-w-0 flex-1 overflow-hidden",b?"p-0 pb-12 md:pb-0":"p-0 pb-16 md:pb-0"),children:[i.jsx("div",{ref:R,className:me("pixcode-shell-terminal h-full min-h-0 w-full min-w-0 max-w-full focus:outline-none",M&&"pixcode-shell-terminal--right-cli"),style:{outline:"none"}}),Se&&i.jsx(p7,{mode:Se,description:Te,loadingLabel:v("shell.loading"),connectLabel:v("shell.actions.connect"),connectTitle:v("shell.actions.connectTitle"),connectingLabel:v("shell.connecting"),onConnect:$}),k&&L&&i.jsx("div",{className:me("absolute inset-x-0 z-10 border-t border-gray-700/80 bg-gray-800/95 px-3 py-2 backdrop-blur-sm",b?"bottom-12 md:bottom-0":"bottom-14 md:bottom-0"),onMouseDown:de=>de.preventDefault(),children:i.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[k.map(de=>i.jsxs("button",{type:"button",onClick:()=>{U(`${de.number}\r`),S(null)},className:"max-w-36 truncate rounded bg-blue-600 px-3 py-1.5 text-xs font-medium text-white transition-colors hover:bg-blue-700",title:`${de.number}. ${de.label}`,children:[de.number,". ",de.label]},de.number)),i.jsx("button",{type:"button",onClick:()=>{U("\x1B"),S(null)},className:"rounded bg-gray-700 px-3 py-1.5 text-xs font-medium text-gray-200 transition-colors hover:bg-gray-600",children:"Esc"})]})})]}),i.jsx(Iw,{wsRef:j,terminalRef:A,isConnected:L,placement:b?"absolute":"fixed"})]})}function nO({className:e}){return i.jsx("div",{className:`flex h-full items-center justify-center ${e}`,children:i.jsxs("div",{className:"text-center text-gray-500 dark:text-gray-400",children:[i.jsx("div",{className:"mx-auto mb-4 flex h-16 w-16 items-center justify-center rounded-full bg-gray-100 dark:bg-gray-800",children:i.jsx("svg",{className:"h-8 w-8 text-gray-400",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:i.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 9l3 3-3 3m5 0h3M5 20h14a2 2 0 002-2V6a2 2 0 00-2-2H5a2 2 0 002 2z"})})}),i.jsx("h3",{className:"mb-2 text-lg font-semibold",children:"No Project Selected"}),i.jsx("p",{children:"A project is required to open a shell"})]})})}function rO({title:e,isCompleted:t,onClose:n=null}){return i.jsx("div",{className:"flex-shrink-0 border-b border-gray-700 bg-gray-800 px-4 py-2",children:i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{className:"flex items-center space-x-2",children:[i.jsx("h3",{className:"text-sm font-medium text-gray-200",children:e}),t&&i.jsx("span",{className:"text-xs text-green-400",children:"(Completed)"})]}),n&&i.jsx("button",{onClick:n,className:"text-gray-400 hover:text-white",title:"Close",children:i.jsx("svg",{className:"h-4 w-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:i.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]})})}function El({project:e=null,session:t=null,command:n=null,isPlainShell:r=null,isActive:a=!0,autoConnect:s=!0,onComplete:o=null,onClose:l=null,title:c=null,className:d="",showHeader:u=!0,compact:p=!1,minimal:f=!1,immersive:h=!1,forceNewSession:g=!1,startupInput:b=null,permissionOverride:x=null,provider:v=null,layoutSignal:y=null,tabId:w=null}){const[k,S]=m.useState(!1),C=m.useMemo(()=>w||`tab_${crypto.randomUUID()}`,[w]),N=r!==null?r:n!==null,R=m.useCallback(A=>{S(!0),o?.(A)},[o]);return e?i.jsxs("div",{className:`flex h-full w-full min-w-0 flex-col overflow-hidden ${d}`,children:[!f&&u&&c&&i.jsx(rO,{title:c,isCompleted:k,onClose:l}),i.jsx("div",{className:"min-h-0 w-full min-w-0 flex-1 overflow-hidden",children:i.jsx(tO,{tabId:C,selectedProject:e,selectedSession:t,initialCommand:n,isPlainShell:N,isActive:a,onProcessComplete:R,minimal:f,autoConnect:f?!0:s,forceNewSession:g,startupInput:b,permissionOverride:x,provider:v,layoutSignal:y,onClose:l,immersive:h,showHeader:u})})]}):i.jsx(nO,{className:d})}const aO=(e,t)=>t||(e==="claude"?"claude --dangerously-skip-permissions /login":e==="cursor"?"cursor-agent login":e==="codex"?"codex login":e==="qwen"?"qwen auth":e==="opencode"?"opencode auth login":"gemini"),iO={claude:{keyLabel:"Anthropic API Key",keyExample:"sk-ant-...",supportsBaseUrl:!0,baseUrlExample:"https://api.anthropic.com",keyConsoleUrl:"https://console.anthropic.com/settings/keys",keyConsoleLabel:"Anthropic Console"},codex:{keyLabel:"OpenAI API Key",keyExample:"sk-...",supportsBaseUrl:!0,baseUrlExample:"https://api.openai.com/v1",keyConsoleUrl:"https://platform.openai.com/api-keys",keyConsoleLabel:"OpenAI Platform"},gemini:{keyLabel:"Gemini API Key",keyExample:"AI...",supportsBaseUrl:!1,keyConsoleUrl:"https://aistudio.google.com/app/apikey",keyConsoleLabel:"Google AI Studio"},qwen:{keyLabel:"OpenAI-Compatible API Key",keyExample:"sk-... or sk-sp-...",supportsBaseUrl:!0,baseUrlExample:"https://dashscope-intl.aliyuncs.com/compatible-mode/v1",keyConsoleUrl:"https://github.com/QwenLM/qwen-code",keyConsoleLabel:"Qwen Code Docs",notes:"Accepts any OpenAI-compatible endpoint — Alibaba Cloud, ModelScope, OpenRouter, self-hosted, etc."},opencode:{keyLabel:"Anthropic API Key (default backend)",keyExample:"sk-ant-...",supportsBaseUrl:!0,baseUrlExample:"https://api.anthropic.com",keyConsoleUrl:"https://console.anthropic.com/settings/keys",keyConsoleLabel:"Anthropic Console",notes:"OpenCode is multi-provider — this sets the Anthropic credentials. Switch providers via `opencode auth login` or opencode.json."}};function Lw({active:e,children:t,onClick:n}){return i.jsx("button",{onClick:n,className:`flex-1 border-b-2 px-4 py-2.5 text-sm font-medium transition-colors ${e?"border-primary text-foreground":"border-transparent text-muted-foreground hover:text-foreground"}`,children:t})}function sO({provider:e}){const[t,n]=m.useState(""),[r,a]=m.useState(!1),[s,o]=m.useState("idle"),[l,c]=m.useState(null),d=async()=>{const u=t.trim();if(u){a(!0),c(null),o("idle");try{const p=await Ee(`/api/providers/${e}/oauth-paste`,{method:"POST",body:JSON.stringify({callbackUrl:u})}),f=await p.json().catch(()=>({}));if(!p.ok||!f?.success)throw new Error(f?.error||`Request failed (${p.status})`);o("ok"),n("")}catch(p){c(p?.message||"Forward failed"),o("error")}finally{a(!1)}}};return i.jsxs("div",{className:"mt-3 rounded-lg border border-border/60 bg-muted/30 p-3 text-sm",children:[i.jsx("div",{className:"mb-2 font-medium text-foreground",children:"Remote login? Paste the callback URL here"}),i.jsxs("p",{className:"mb-3 text-xs text-muted-foreground",children:["When the CLI shows ",i.jsx("code",{className:"rounded bg-background px-1 font-mono text-[11px]",children:"http://127.0.0.1:PORT/…"})," and your browser can't reach it (VPS setups), copy the failing URL from your address bar and paste it below. Pixcode forwards the token exchange to the CLI process on this host."]}),i.jsxs("div",{className:"flex gap-2",children:[i.jsx("input",{type:"url",value:t,onChange:u=>n(u.target.value),placeholder:"http://127.0.0.1:49312/callback?code=...",className:"flex-1 rounded-md border border-border bg-background px-3 py-2 font-mono text-xs text-foreground focus:border-primary focus:outline-none",onKeyDown:u=>{u.key==="Enter"&&d()}}),i.jsx("button",{onClick:()=>void d(),disabled:r||!t.trim(),className:"flex items-center gap-1.5 rounded-md bg-foreground px-3 py-2 text-xs font-medium text-background transition-opacity hover:opacity-90 disabled:opacity-40",children:r?i.jsx(Dt,{className:"h-3.5 w-3.5 animate-spin"}):"Forward"})]}),s==="ok"&&i.jsxs("div",{className:"mt-2 flex items-center gap-1.5 text-xs text-emerald-600 dark:text-emerald-400",children:[i.jsx(Ht,{className:"h-3.5 w-3.5"})," Forwarded — check the terminal above for the completion message."]}),s==="error"&&l&&i.jsx("div",{className:"mt-2 text-xs text-red-600 dark:text-red-400",children:l})]})}function oO({provider:e,onSaved:t}){const n=iO[e],[r,a]=m.useState(""),[s,o]=m.useState(""),[l,c]=m.useState(!1),[d,u]=m.useState("idle"),[p,f]=m.useState(null);m.useEffect(()=>{let g=!1;return(async()=>{try{const x=await(await Ee("/api/providers/credentials")).json().catch(()=>({}));if(g||!x?.success)return;const v=x.data?.[e];v?.baseUrl&&o(v.baseUrl)}catch{}})(),()=>{g=!0}},[e]);const h=async()=>{const g=r.trim();if(g){c(!0),f(null),u("idle");try{const b=await Ee(`/api/providers/${e}/auth/api-key`,{method:"POST",body:JSON.stringify({apiKey:g,baseUrl:n.supportsBaseUrl&&s.trim()?s.trim():""})}),x=await b.json().catch(()=>({}));if(!b.ok||!x?.success)throw new Error(x?.error||`Request failed (${b.status})`);u("ok"),a(""),t()}catch(b){f(b?.message||"Save failed"),u("error")}finally{c(!1)}}};return n?i.jsx("div",{className:"flex h-full flex-col overflow-y-auto p-6",children:i.jsxs("div",{className:"mx-auto w-full max-w-lg space-y-5",children:[i.jsxs("div",{className:"flex items-center gap-3",children:[i.jsx("div",{className:"flex h-10 w-10 items-center justify-center rounded-full bg-muted",children:i.jsx(HD,{className:"h-5 w-5 text-foreground"})}),i.jsxs("div",{children:[i.jsx("h4",{className:"text-base font-semibold text-foreground",children:n.keyLabel}),i.jsxs("a",{href:n.keyConsoleUrl,target:"_blank",rel:"noreferrer",className:"inline-flex items-center gap-1 text-xs text-muted-foreground hover:text-foreground",children:["Get a key from ",n.keyConsoleLabel,i.jsx(tr,{className:"h-3 w-3"})]})]})]}),n.notes&&i.jsx("div",{className:"rounded-md border border-border/60 bg-muted/40 p-3 text-xs text-muted-foreground",children:n.notes}),i.jsxs("div",{className:"space-y-1.5",children:[i.jsx("label",{className:"text-xs font-medium text-foreground",children:"API Key"}),i.jsx("input",{type:"password",value:r,onChange:g=>a(g.target.value),placeholder:n.keyExample,className:"w-full rounded-md border border-border bg-background px-3 py-2 font-mono text-sm text-foreground focus:border-primary focus:outline-none",autoComplete:"off",spellCheck:!1}),i.jsxs("p",{className:"text-[11px] text-muted-foreground",children:["Stored locally at ",i.jsx("code",{className:"rounded bg-muted px-1 font-mono text-[10px]",children:"~/.pixcode/provider-credentials.json"})," with 0600 permissions."]})]}),n.supportsBaseUrl&&i.jsxs("div",{className:"space-y-1.5",children:[i.jsxs("label",{className:"text-xs font-medium text-foreground",children:["Base URL ",i.jsx("span",{className:"font-normal text-muted-foreground",children:"(optional — use a custom endpoint)"})]}),i.jsx("input",{type:"url",value:s,onChange:g=>o(g.target.value),placeholder:n.baseUrlExample,className:"w-full rounded-md border border-border bg-background px-3 py-2 font-mono text-sm text-foreground focus:border-primary focus:outline-none",autoComplete:"off",spellCheck:!1}),i.jsx("p",{className:"text-[11px] text-muted-foreground",children:"Point at any OpenAI-compatible proxy (OpenRouter, local LLM, self-hosted, budget provider) to cut costs or hit different models."})]}),i.jsxs("div",{className:"flex items-center gap-3 pt-2",children:[i.jsxs("button",{onClick:()=>void h(),disabled:l||!r.trim(),className:"inline-flex items-center gap-2 rounded-md bg-foreground px-4 py-2 text-sm font-medium text-background transition-opacity hover:opacity-90 disabled:opacity-40",children:[l?i.jsx(Dt,{className:"h-4 w-4 animate-spin"}):i.jsx(Ht,{className:"h-4 w-4"}),"Save API Key"]}),d==="ok"&&i.jsx("span",{className:"text-xs text-emerald-600 dark:text-emerald-400",children:"Saved — reconnect to pick it up."}),d==="error"&&p&&i.jsx("span",{className:"text-xs text-red-600 dark:text-red-400",children:p})]})]})}):i.jsx("div",{className:"p-6 text-sm text-muted-foreground",children:"This provider uses OAuth only — use the Browser tab to log in."})}function pE({isOpen:e,onClose:t,provider:n="claude",onComplete:r,customCommand:a,isAuthenticated:s=!1}){const{t:o}=Fe("common"),l=n!=="cursor",[c,d]=m.useState(l?"apiKey":"browser");m.useEffect(()=>{e&&d(l?"apiKey":"browser")},[e,n,l]);const u=m.useMemo(()=>`${Rn[n]??n} Login`,[n]);if(!e)return null;const p=aO(n,a),f=h=>r?.(h);return i.jsx("div",{className:"fixed inset-0 z-[9999] flex items-center justify-center bg-black bg-opacity-50 max-md:items-stretch max-md:justify-stretch",children:i.jsxs("div",{className:"flex h-3/4 w-full max-w-4xl flex-col rounded-lg bg-white shadow-xl dark:bg-gray-800 max-md:m-0 max-md:h-full max-md:max-w-none max-md:rounded-none md:m-4 md:h-3/4 md:max-w-4xl md:rounded-lg",children:[i.jsxs("div",{className:"flex items-center justify-between border-b border-gray-200 p-4 dark:border-gray-700",children:[i.jsx("h3",{className:"text-lg font-semibold text-gray-900 dark:text-white",children:u}),i.jsx("button",{onClick:t,className:"text-gray-400 transition-colors hover:text-gray-600 dark:hover:text-gray-300","aria-label":"Close login modal",children:i.jsx(ht,{className:"h-6 w-6"})})]}),i.jsxs("div",{className:"flex border-b border-gray-200 dark:border-gray-700",children:[i.jsx(Lw,{active:c==="browser",onClick:()=>d("browser"),children:"Browser / OAuth"}),l&&i.jsx(Lw,{active:c==="apiKey",onClick:()=>d("apiKey"),children:"API Key"})]}),i.jsx("div",{className:"flex flex-1 flex-col overflow-hidden",children:c==="browser"?i.jsxs("div",{className:"flex flex-1 flex-col overflow-hidden",children:[i.jsx("div",{className:"min-h-0 flex-1",children:i.jsx(El,{project:S_,command:p,onComplete:f,minimal:!0})}),i.jsx("div",{className:"border-t border-border/40 bg-background/50 px-4 py-3",children:i.jsx(sO,{provider:n})})]}):i.jsx(oO,{provider:n,onSaved:()=>f(0)})})]})})}const lO=({className:e="w-5 h-5"})=>i.jsx("img",{src:"/icons/claude-ai-icon.svg",alt:"Claude",className:e}),cO=({className:e="w-5 h-5"})=>{const{isDarkMode:t}=Fa();return i.jsx("img",{src:t?"/icons/codex-white.svg":"/icons/codex.svg",alt:"Codex",className:e})},dO=({className:e="w-5 h-5"})=>{const{isDarkMode:t}=Fa();return i.jsx("img",{src:t?"/icons/cursor-white.svg":"/icons/cursor.svg",alt:"Cursor",className:e})},uO=({className:e="w-5 h-5"})=>i.jsx("img",{src:"/icons/gemini-ai-icon.svg",alt:"Gemini",className:e}),pO=({className:e="w-5 h-5"})=>{const{isDarkMode:t}=Fa(),n=t?"/icons/opencode-logo-dark.svg":"/icons/opencode-logo-light.svg";return i.jsx("img",{src:n,alt:"OpenCode",className:e})},mO=({className:e="w-5 h-5"})=>i.jsx("img",{src:"/icons/qwen-logo.svg",alt:"Qwen Code",className:e});function yn({provider:e="claude",className:t="w-5 h-5"}){return e==="cursor"?i.jsx(dO,{className:t}):e==="codex"?i.jsx(cO,{className:t}):e==="gemini"?i.jsx(uO,{className:t}):e==="qwen"?i.jsx(mO,{className:t}):e==="opencode"?i.jsx(pO,{className:t}):i.jsx(lO,{className:t})}function hO({provider:e,title:t,status:n,connectedClassName:r,iconContainerClassName:a,loginButtonClassName:s,onLogin:o}){const l=n.authenticated?r:"border-border bg-card",c=n.loading?"Checking...":n.authenticated?n.email||"Connected":n.error||"Not connected";return i.jsx("div",{className:`rounded-lg border p-4 transition-colors ${l}`,children:i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{className:"flex items-center gap-3",children:[i.jsx("div",{className:`flex h-10 w-10 items-center justify-center rounded-full ${a}`,children:i.jsx(yn,{provider:e,className:"h-5 w-5"})}),i.jsxs("div",{children:[i.jsxs("div",{className:"flex items-center gap-2 font-medium text-foreground",children:[t,n.authenticated&&i.jsx(Ht,{className:"h-4 w-4 text-green-500"})]}),i.jsx("div",{className:"text-xs text-muted-foreground",children:c})]})]}),!n.authenticated&&!n.loading&&i.jsx("button",{onClick:o,className:`${s} rounded-lg px-4 py-2 text-sm font-medium text-white transition-colors`,children:"Login"})]})})}const fO=[{provider:"claude",title:"Claude Code",connectedClassName:"bg-blue-50 dark:bg-blue-900/20 border-blue-200 dark:border-blue-800",iconContainerClassName:"bg-blue-100 dark:bg-blue-900/30",loginButtonClassName:"bg-blue-600 hover:bg-blue-700"},{provider:"cursor",title:"Cursor",connectedClassName:"bg-purple-50 dark:bg-purple-900/20 border-purple-200 dark:border-purple-800",iconContainerClassName:"bg-purple-100 dark:bg-purple-900/30",loginButtonClassName:"bg-purple-600 hover:bg-purple-700"},{provider:"codex",title:"OpenAI Codex",connectedClassName:"bg-gray-100 dark:bg-gray-800/50 border-gray-300 dark:border-gray-600",iconContainerClassName:"bg-gray-100 dark:bg-gray-800",loginButtonClassName:"bg-gray-800 hover:bg-gray-900 dark:bg-gray-700 dark:hover:bg-gray-600"},{provider:"gemini",title:"Gemini",connectedClassName:"bg-teal-50 dark:bg-teal-900/20 border-teal-200 dark:border-teal-800",iconContainerClassName:"bg-teal-100 dark:bg-teal-900/30",loginButtonClassName:"bg-teal-600 hover:bg-teal-700"},{provider:"qwen",title:"Qwen Code",connectedClassName:"bg-orange-50 dark:bg-orange-900/20 border-orange-200 dark:border-orange-800",iconContainerClassName:"bg-orange-100 dark:bg-orange-900/30",loginButtonClassName:"bg-orange-600 hover:bg-orange-700"}];function Pw({providerStatuses:e,onOpenProviderLogin:t}){return i.jsxs("div",{className:"space-y-6",children:[i.jsxs("div",{className:"mb-6 text-center",children:[i.jsx("h2",{className:"mb-2 text-2xl font-bold text-foreground",children:"Connect Your AI Agents"}),i.jsx("p",{className:"text-muted-foreground",children:"Login to one or more AI coding assistants. All are optional."})]}),i.jsx("div",{className:"space-y-3",children:fO.map(n=>i.jsx(hO,{provider:n.provider,title:n.title,status:e[n.provider],connectedClassName:n.connectedClassName,iconContainerClassName:n.iconContainerClassName,loginButtonClassName:n.loginButtonClassName,onLogin:()=>t(n.provider)},n.provider))}),i.jsx("div",{className:"pt-2 text-center text-sm text-muted-foreground",children:i.jsx("p",{children:"You can configure these later in Settings."})})]})}function gO({gitName:e,gitEmail:t,isSubmitting:n,onGitNameChange:r,onGitEmailChange:a}){return i.jsxs("div",{className:"space-y-6",children:[i.jsxs("div",{className:"mb-8 text-center",children:[i.jsx("div",{className:"mx-auto mb-4 flex h-16 w-16 items-center justify-center rounded-full bg-blue-100 dark:bg-blue-900/30",children:i.jsx(Nn,{className:"h-8 w-8 text-blue-600 dark:text-blue-400"})}),i.jsx("h2",{className:"mb-2 text-2xl font-bold text-foreground",children:"Git Configuration"}),i.jsx("p",{className:"text-muted-foreground",children:"Configure your git identity to ensure proper attribution for commits."})]}),i.jsxs("div",{className:"space-y-4",children:[i.jsxs("div",{children:[i.jsxs("label",{htmlFor:"gitName",className:"mb-2 flex items-center gap-2 text-sm font-medium text-foreground",children:[i.jsx($D,{className:"h-4 w-4"}),"Git Name ",i.jsx("span",{className:"text-red-500",children:"*"})]}),i.jsx("input",{type:"text",id:"gitName",value:e,onChange:s=>r(s.target.value),className:"w-full rounded-lg border border-border bg-background px-4 py-3 text-foreground focus:border-transparent focus:outline-none focus:ring-2 focus:ring-blue-500",placeholder:"John Doe",required:!0,disabled:n}),i.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:"Saved as `git config --global user.name`."})]}),i.jsxs("div",{children:[i.jsxs("label",{htmlFor:"gitEmail",className:"mb-2 flex items-center gap-2 text-sm font-medium text-foreground",children:[i.jsx(BD,{className:"h-4 w-4"}),"Git Email ",i.jsx("span",{className:"text-red-500",children:"*"})]}),i.jsx("input",{type:"email",id:"gitEmail",value:t,onChange:s=>a(s.target.value),className:"w-full rounded-lg border border-border bg-background px-4 py-3 text-foreground focus:border-transparent focus:outline-none focus:ring-2 focus:ring-blue-500",placeholder:"john@example.com",required:!0,disabled:n}),i.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:"Saved as `git config --global user.email`."})]})]})]})}const Dw=[{title:"Git Configuration",icon:Nn,required:!0},{title:"Connect Agents",icon:J4,required:!1}];function bO({currentStep:e}){return i.jsx("div",{className:"mb-8",children:i.jsx("div",{className:"flex items-center justify-between",children:Dw.map((t,n)=>{const r=n<e,a=n===e,s=t.icon;return i.jsxs("div",{className:"contents",children:[i.jsxs("div",{className:"flex flex-1 flex-col items-center",children:[i.jsx("div",{className:`flex h-12 w-12 items-center justify-center rounded-full border-2 transition-colors duration-200 ${r?"border-green-500 bg-green-500 text-white":a?"border-blue-600 bg-blue-600 text-white":"border-border bg-background text-muted-foreground"}`,children:r?i.jsx(Ht,{className:"h-6 w-6"}):i.jsx(s,{className:"h-6 w-6"})}),i.jsxs("div",{className:"mt-2 text-center",children:[i.jsx("p",{className:`text-sm font-medium ${a?"text-foreground":"text-muted-foreground"}`,children:t.title}),t.required&&i.jsx("span",{className:"text-xs text-red-500",children:"Required"})]})]}),n<Dw.length-1&&i.jsx("div",{className:`mx-2 h-0.5 flex-1 transition-colors duration-200 ${r?"bg-green-500":"bg-border"}`})]},t.title)})})})}const Ow=/^[^\s@]+@[^\s@]+\.[^\s@]+$/,Mw=async(e,t)=>{try{return(await e.json()).error||t}catch{return t}};function xO({onComplete:e}){const[t,n]=m.useState(0),[r,a]=m.useState(""),[s,o]=m.useState(""),[l,c]=m.useState(!1),[d,u]=m.useState(""),[p,f]=m.useState(null),{providerAuthStatus:h,checkProviderAuthStatus:g,refreshProviderAuthStatuses:b}=pu(),x=m.useRef(void 0),v=m.useCallback(async()=>{try{const R=await Ee("/api/user/git-config");if(!R.ok)return;const A=await R.json();A.gitName&&a(A.gitName),A.gitEmail&&o(A.gitEmail)}catch(R){console.error("Error loading git config:",R)}},[]);m.useEffect(()=>{v(),b()},[v,b]),m.useEffect(()=>{const R=x.current;x.current=p,R!=null&&p===null&&b()},[p,b]);const y=R=>{f(R)},w=R=>{R===0&&p&&g(p)},k=async()=>{if(u(""),t!==0){n(R=>R+1);return}if(!r.trim()||!s.trim()){u("Both git name and email are required.");return}if(!Ow.test(s)){u("Please enter a valid email address.");return}c(!0);try{const R=await Ee("/api/user/git-config",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({gitName:r,gitEmail:s})});if(!R.ok){const A=await Mw(R,"Failed to save git configuration");throw new Error(A)}n(A=>A+1)}catch(R){u(R instanceof Error?R.message:"Failed to save git configuration")}finally{c(!1)}},S=()=>{u(""),n(R=>R-1)},C=async()=>{c(!0),u("");try{const R=await Ee("/api/user/complete-onboarding",{method:"POST"});if(!R.ok){const A=await Mw(R,"Failed to complete onboarding");throw new Error(A)}await e?.()}catch(R){u(R instanceof Error?R.message:"Failed to complete onboarding")}finally{c(!1)}},N=t===0?!!(r.trim()&&s.trim()&&Ow.test(s)):!0;return i.jsxs(i.Fragment,{children:[i.jsx("div",{className:"flex min-h-screen items-center justify-center bg-background p-4",children:i.jsxs("div",{className:"w-full max-w-2xl",children:[i.jsx(bO,{currentStep:t}),i.jsxs("div",{className:"rounded-lg border border-border bg-card p-8 shadow-lg",children:[t===0?i.jsx(gO,{gitName:r,gitEmail:s,isSubmitting:l,onGitNameChange:a,onGitEmailChange:o}):t===1?i.jsx(Pw,{providerStatuses:h,onOpenProviderLogin:y}):i.jsx(Pw,{providerStatuses:h,onOpenProviderLogin:y}),d&&i.jsx("div",{className:"mt-6 rounded-lg border border-red-300 bg-red-100 p-4 dark:border-red-800 dark:bg-red-900/20",children:i.jsx("p",{className:"text-sm text-red-700 dark:text-red-400",children:d})}),i.jsxs("div",{className:"mt-8 flex items-center justify-between border-t border-border pt-6",children:[i.jsxs("button",{onClick:S,disabled:t===0||l,className:"flex items-center gap-2 px-4 py-2 text-sm font-medium text-muted-foreground transition-colors duration-200 hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",children:[i.jsx(Q4,{className:"h-4 w-4"}),"Previous"]}),i.jsx("div",{className:"flex items-center gap-3",children:t<1?i.jsx("button",{onClick:k,disabled:!N||l,className:"flex items-center gap-2 rounded-lg bg-blue-600 px-6 py-3 font-medium text-white transition-colors duration-200 hover:bg-blue-700 disabled:cursor-not-allowed disabled:bg-blue-400",children:l?i.jsxs(i.Fragment,{children:[i.jsx(Dt,{className:"h-4 w-4 animate-spin"}),"Saving..."]}):i.jsxs(i.Fragment,{children:["Next",i.jsx(li,{className:"h-4 w-4"})]})}):i.jsx("button",{onClick:C,disabled:l,className:"flex items-center gap-2 rounded-lg bg-green-600 px-6 py-3 font-medium text-white transition-colors duration-200 hover:bg-green-700 disabled:cursor-not-allowed disabled:bg-green-400",children:l?i.jsxs(i.Fragment,{children:[i.jsx(Dt,{className:"h-4 w-4 animate-spin"}),"Completing..."]}):i.jsxs(i.Fragment,{children:[i.jsx(Ht,{className:"h-4 w-4"}),"Complete Setup"]})})})]})]})]})}),p&&i.jsx(pE,{isOpen:!!p,onClose:()=>f(null),provider:p,onComplete:w})]})}const vO=["0s","0.1s","0.2s"];function yO(){return i.jsx("div",{className:"flex min-h-screen items-center justify-center bg-background p-4",children:i.jsxs("div",{className:"text-center",children:[i.jsx("div",{className:"mb-4 flex justify-center",children:i.jsx("div",{className:"flex h-16 w-16 items-center justify-center rounded-lg bg-primary shadow-sm",children:i.jsx(Wr,{className:"h-8 w-8 text-primary-foreground"})})}),i.jsx("h1",{className:"mb-2 text-2xl font-bold text-foreground",children:"Pixcode"}),i.jsx("div",{className:"flex items-center justify-center space-x-2",children:vO.map(e=>i.jsx("div",{className:"h-2 w-2 animate-bounce rounded-full bg-blue-500",style:{animationDelay:e}},e))}),i.jsx("p",{className:"mt-2 text-muted-foreground",children:"Loading..."})]})})}function mE({errorMessage:e}){return e?i.jsx("div",{className:"rounded-md border border-red-300 bg-red-100 p-3 dark:border-red-800 dark:bg-red-900/20",children:i.jsx("p",{className:"text-sm text-red-700 dark:text-red-400",children:e})}):null}function Pi({id:e,label:t,value:n,onChange:r,placeholder:a,isDisabled:s,type:o="text",name:l,autoComplete:c}){return i.jsxs("div",{children:[i.jsx("label",{htmlFor:e,className:"mb-1 block text-sm font-medium text-foreground",children:t}),i.jsx("input",{id:e,type:o,name:l??e,autoComplete:c,value:n,onChange:d=>r(d.target.value),className:"w-full rounded-md border border-border bg-background px-3 py-2 text-foreground focus:border-transparent focus:outline-none focus:ring-2 focus:ring-blue-500",placeholder:a,required:!0,disabled:s})]})}function hE({title:e,description:t,children:n,footerText:r,logo:a}){return i.jsx("div",{className:"flex min-h-screen items-center justify-center bg-background p-4",children:i.jsx("div",{className:"w-full max-w-md",children:i.jsxs("div",{className:"space-y-6 rounded-lg border border-border bg-card p-8 shadow-lg",children:[i.jsxs("div",{className:"text-center",children:[i.jsx("div",{className:"mb-4 flex justify-center",children:a??i.jsx("div",{className:"flex h-16 w-16 items-center justify-center rounded-lg bg-primary shadow-sm",children:i.jsx(Wr,{className:"h-8 w-8 text-primary-foreground"})})}),i.jsx("h1",{className:"text-2xl font-bold text-foreground",children:e}),i.jsx("p",{className:"mt-2 text-muted-foreground",children:t})]}),n,i.jsx("div",{className:"text-center",children:i.jsx("p",{className:"text-sm text-muted-foreground",children:r})}),i.jsxs("div",{className:"flex items-center justify-center gap-1.5 pt-2",children:[i.jsx("svg",{className:"h-3.5 w-3.5 text-muted-foreground/50",fill:"currentColor",viewBox:"0 0 24 24","aria-hidden":"true",children:i.jsx("path",{d:"M12 2C6.477 2 2 6.484 2 12.017c0 4.425 2.865 8.18 6.839 9.504.5.092.682-.217.682-.483 0-.237-.008-.868-.013-1.703-2.782.605-3.369-1.343-3.369-1.343-.454-1.158-1.11-1.466-1.11-1.466-.908-.62.069-.608.069-.608 1.003.07 1.531 1.032 1.531 1.032.892 1.53 2.341 1.088 2.91.832.092-.647.35-1.088.636-1.338-2.22-.253-4.555-1.113-4.555-4.951 0-1.093.39-1.988 1.029-2.688-.103-.253-.446-1.272.098-2.65 0 0 .84-.27 2.75 1.026A9.564 9.564 0 0112 6.844c.85.004 1.705.115 2.504.337 1.909-1.296 2.747-1.027 2.747-1.027.546 1.379.202 2.398.1 2.651.64.7 1.028 1.595 1.028 2.688 0 3.848-2.339 4.695-4.566 4.943.359.309.678.92.678 1.855 0 1.338-.012 2.419-.012 2.747 0 .268.18.58.688.482A10.019 10.019 0 0022 12.017C22 6.484 17.522 2 12 2z"})}),i.jsx("a",{href:"https://github.com/alicomert/pixcode",target:"_blank",rel:"noopener noreferrer",className:"text-xs text-muted-foreground/50 transition-colors hover:text-muted-foreground",children:"Pixcode is open source"})]})]})})})}const wO={username:"",password:""};function kO(){const{t:e}=Fe("auth"),{login:t}=Hl(),[n,r]=m.useState(wO),[a,s]=m.useState(""),[o,l]=m.useState(!1),c=m.useCallback((u,p)=>{r(f=>({...f,[u]:p}))},[]),d=m.useCallback(async u=>{if(u.preventDefault(),s(""),!n.username.trim()||!n.password){s(e("login.errors.requiredFields"));return}l(!0);const p=await t(n.username.trim(),n.password);p.success||s(p.error),l(!1)},[n.password,n.username,t,e]);return i.jsx(hE,{title:e("login.title"),description:e("login.description"),footerText:"Enter your credentials to access Pixcode",children:i.jsxs("form",{onSubmit:d,className:"space-y-4",children:[i.jsx(Pi,{id:"username",label:e("login.username"),value:n.username,onChange:u=>c("username",u),placeholder:e("login.placeholders.username"),isDisabled:o,autoComplete:"username"}),i.jsx(Pi,{id:"password",label:e("login.password"),value:n.password,onChange:u=>c("password",u),placeholder:e("login.placeholders.password"),isDisabled:o,type:"password",autoComplete:"current-password"}),i.jsx(mE,{errorMessage:a}),i.jsx("button",{type:"submit",disabled:o,className:"w-full rounded-md bg-blue-600 px-4 py-2 font-medium text-white transition-colors duration-200 hover:bg-blue-700 disabled:bg-blue-400",children:e(o?"login.loading":"login.submit")})]})})}const SO={username:"",password:"",confirmPassword:"",connectionMode:"local",remoteUrl:"",remoteApiKey:""};function CO(e){return!e.username.trim()||!e.password||!e.confirmPassword?"Please fill in all fields.":e.username.trim().length<3?"Username must be at least 3 characters long.":e.password.length<6?"Password must be at least 6 characters long.":e.password!==e.confirmPassword?"Passwords do not match.":e.connectionMode==="remote"&&!e.remoteUrl.trim()?"Remote Pixcode server URL is required.":null}function EO(){const{register:e}=Hl(),[t,n]=m.useState(SO),[r,a]=m.useState(""),[s,o]=m.useState(!1),l=m.useCallback((d,u)=>{n(p=>({...p,[d]:u}))},[]),c=m.useCallback(async d=>{d.preventDefault(),a("");const u=CO(t);if(u){a(u);return}o(!0);const p=await fetch("/api/auth/connection-mode",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({mode:t.connectionMode,remoteUrl:t.connectionMode==="remote"?t.remoteUrl.trim():null,apiKey:t.connectionMode==="remote"?t.remoteApiKey.trim():null})});if(!p.ok){const h=await p.json().catch(()=>null);a(h?.error||"Could not save connection mode."),o(!1);return}const f=await e(t.username.trim(),t.password);f.success||a(f.error),o(!1)},[t,e]);return i.jsx(hE,{title:"Welcome to Pixcode",description:"Create the first admin account to get started",footerText:"The first account becomes admin and can add more users later.",logo:i.jsx("img",{src:"/logo.svg",alt:"Pixcode",className:"h-16 w-16"}),children:i.jsxs("form",{onSubmit:c,className:"space-y-4",children:[i.jsxs("div",{className:"grid gap-2 rounded-lg border border-border/70 bg-muted/30 p-2 sm:grid-cols-2",children:[i.jsxs("button",{type:"button",onClick:()=>l("connectionMode","local"),disabled:s,className:`rounded-md px-3 py-2 text-left text-sm transition-colors ${t.connectionMode==="local"?"bg-background text-foreground shadow-sm":"text-muted-foreground hover:bg-background/60 hover:text-foreground"}`,children:[i.jsx("span",{className:"block font-medium",children:"Use this computer directly"}),i.jsx("span",{className:"block text-xs opacity-80",children:"Run Pixcode and CLIs on this machine."})]}),i.jsxs("button",{type:"button",onClick:()=>l("connectionMode","remote"),disabled:s,className:`rounded-md px-3 py-2 text-left text-sm transition-colors ${t.connectionMode==="remote"?"bg-background text-foreground shadow-sm":"text-muted-foreground hover:bg-background/60 hover:text-foreground"}`,children:[i.jsx("span",{className:"block font-medium",children:"Connect to a remote Pixcode server"}),i.jsx("span",{className:"block text-xs opacity-80",children:"Control another always-on Pixcode host by API."})]})]}),t.connectionMode==="remote"&&i.jsxs("div",{className:"space-y-3 rounded-lg border border-border/70 bg-muted/20 p-3",children:[i.jsx(Pi,{id:"remoteUrl",name:"remoteUrl",label:"Remote API URL",value:t.remoteUrl,onChange:d=>l("remoteUrl",d),placeholder:"https://your-server.example.com",isDisabled:s,autoComplete:"url"}),i.jsx(Pi,{id:"remoteApiKey",name:"remoteApiKey",label:"Remote API Key",value:t.remoteApiKey,onChange:d=>l("remoteApiKey",d),placeholder:"px_...",isDisabled:s,type:"password",autoComplete:"off"})]}),i.jsx(Pi,{id:"username",name:"username",label:"Username",value:t.username,onChange:d=>l("username",d),placeholder:"Enter your username",isDisabled:s,autoComplete:"username"}),i.jsx(Pi,{id:"password",name:"password",label:"Password",value:t.password,onChange:d=>l("password",d),placeholder:"Enter your password",isDisabled:s,type:"password",autoComplete:"new-password"}),i.jsx(Pi,{id:"confirmPassword",name:"confirmPassword",label:"Confirm Password",value:t.confirmPassword,onChange:d=>l("confirmPassword",d),placeholder:"Confirm your password",isDisabled:s,type:"password",autoComplete:"new-password"}),i.jsx(mE,{errorMessage:r}),i.jsx("button",{type:"submit",disabled:s,className:"w-full rounded-md bg-blue-600 px-4 py-2 font-medium text-white transition-colors duration-200 hover:bg-blue-700 disabled:bg-blue-400",children:s?"Setting up...":"Create Account"})]})})}function NO({children:e}){const{user:t,isLoading:n,needsSetup:r,hasCompletedOnboarding:a,refreshOnboardingStatus:s}=Hl();return n?i.jsx(yO,{}):r?i.jsx(EO,{}):t?a?i.jsx(i.Fragment,{children:e}):i.jsx(xO,{onComplete:s}):i.jsx(kO,{})}const fE=m.createContext(null),gE=()=>{const e=m.useContext(fE);if(!e)throw new Error("useWebSocket must be used within a WebSocketProvider");return e},TO=e=>{const t=window.location.protocol==="https:"?"wss:":"ws:";return e?`${t}//${window.location.host}/ws?token=${encodeURIComponent(e)}`:null},AO=()=>{const e=m.useRef(null),t=m.useRef(!1),n=m.useRef(!1),[r,a]=m.useState(null),[s,o]=m.useState(!1),l=m.useRef(null),{token:c}=Hl(),d=m.useCallback(()=>{if(!t.current)try{const f=TO(c);if(!f)return console.warn("No authentication token found for WebSocket connection");const h=new WebSocket(f);h.onopen=()=>{o(!0),e.current=h,n.current&&a({type:"websocket-reconnected",timestamp:Date.now()}),n.current=!0},h.onmessage=g=>{try{const b=JSON.parse(g.data);a(b)}catch(b){console.error("Error parsing WebSocket message:",b)}},h.onclose=()=>{o(!1),e.current=null,l.current=setTimeout(()=>{t.current||d()},3e3)},h.onerror=g=>{console.error("WebSocket error:",g)}}catch(f){console.error("Error creating WebSocket connection:",f)}},[c]);m.useEffect(()=>(d(),()=>{t.current=!0,l.current&&clearTimeout(l.current),e.current&&e.current.close()}),[d]);const u=m.useCallback(f=>{const h=e.current;h&&h.readyState===WebSocket.OPEN?h.send(JSON.stringify(f)):console.warn("WebSocket not connected")},[]);return m.useMemo(()=>({ws:e.current,sendMessage:u,latestMessage:r,isConnected:s}),[u,r,s])},jO=({children:e})=>{const t=AO();return i.jsx(fE.Provider,{value:t,children:e})},bE=m.createContext(null);function ql(){const e=m.useContext(bE);if(!e)throw new Error("usePlugins must be used within a PluginsProvider");return e}function RO({children:e}){const{user:t,token:n,isLoading:r}=Hl(),[a,s]=m.useState([]),[o,l]=m.useState(!0),[c,d]=m.useState(null),u=!!(t&&n),p=m.useCallback(async()=>{if(!u){s([]),d(null),l(!1);return}l(!0);try{const x=await Ee("/api/plugins");if(x.ok){const v=await x.json();s(v.plugins||[]),d(null)}else{let v=`Failed to fetch plugins (${x.status})`;try{const y=await x.json();v=y.details||y.error||v}catch{v=x.statusText||v}d(v)}}catch(x){const v=x instanceof Error?x.message:"Failed to fetch plugins";d(v),console.error("[Plugins] Failed to fetch plugins:",x)}finally{l(!1)}},[u]);m.useEffect(()=>{r||p()},[r,p]);const f=m.useCallback(async x=>{try{const v=await Ee("/api/plugins/install",{method:"POST",body:JSON.stringify({url:x})}),y=await v.json();return v.ok?(await p(),{success:!0}):{success:!1,error:y.details||y.error||"Install failed"}}catch(v){return{success:!1,error:v instanceof Error?v.message:"Install failed"}}},[p]),h=m.useCallback(async x=>{try{const v=await Ee(`/api/plugins/${encodeURIComponent(x)}`,{method:"DELETE"}),y=await v.json();return v.ok?(await p(),{success:!0}):{success:!1,error:y.details||y.error||"Uninstall failed"}}catch(v){return{success:!1,error:v instanceof Error?v.message:"Uninstall failed"}}},[p]),g=m.useCallback(async x=>{try{const v=await Ee(`/api/plugins/${encodeURIComponent(x)}/update`,{method:"POST"}),y=await v.json();return v.ok?(await p(),{success:!0}):{success:!1,error:y.details||y.error||"Update failed"}}catch(v){return{success:!1,error:v instanceof Error?v.message:"Update failed"}}},[p]),b=m.useCallback(async(x,v)=>{try{const y=await Ee(`/api/plugins/${encodeURIComponent(x)}/enable`,{method:"PUT",body:JSON.stringify({enabled:v})});if(!y.ok){let w=`Toggle failed (${y.status})`;try{const k=await y.json();w=k.details||k.error||w}catch{w=y.statusText||w}return{success:!1,error:w}}return await p(),{success:!0,error:null}}catch(y){return{success:!1,error:y instanceof Error?y.message:"Toggle failed"}}},[p]);return i.jsx(bE.Provider,{value:{plugins:a,loading:o,pluginsError:c,refreshPlugins:p,installPlugin:f,uninstallPlugin:h,updatePlugin:g,togglePlugin:b},children:e})}const Fw=e=>typeof window>"u"?!1:window.innerWidth<e,zw=()=>{if(typeof window>"u")return!1;const e=window.navigator;return window.matchMedia("(display-mode: standalone)").matches||!!e.standalone||document.referrer.includes("android-app://")};function wu(e={}){const{mobileBreakpoint:t=768,trackMobile:n=!0,trackPWA:r=!0}=e,[a,s]=m.useState(()=>n?Fw(t):!1),[o,l]=m.useState(()=>r?zw():!1);return m.useEffect(()=>{if(!n||typeof window>"u")return;const c=()=>{s(Fw(t))};return c(),window.addEventListener("resize",c),()=>{window.removeEventListener("resize",c)}},[t,n]),m.useEffect(()=>{if(!r||typeof window>"u")return;const c=window.matchMedia("(display-mode: standalone)"),d=()=>{l(zw())};return d(),typeof c.addEventListener=="function"?(c.addEventListener("change",d),()=>{c.removeEventListener("change",d)}):(c.addListener(d),()=>{c.removeListener(d)})},[r]),{isMobile:a,isPWA:o}}const sg="pixcode.updateCheck.preferences",Dh="pixcode:update-check-settings-changed",og=[{value:"30m",label:"Every 30 minutes",intervalMs:1800*1e3},{value:"24h",label:"Daily",intervalMs:1440*60*1e3},{value:"12h",label:"Every 12 hours",intervalMs:720*60*1e3},{value:"6h",label:"Every 6 hours",intervalMs:360*60*1e3},{value:"7d",label:"Weekly",intervalMs:10080*60*1e3},{value:"off",label:"Manual only",intervalMs:null}],Oh={frequency:"30m"};function Bw(e){return og.find(t=>t.value===e.frequency)?.intervalMs??null}function xE(e){if(!e||typeof e!="object")return Oh;const t=e.frequency;return og.some(n=>n.value===t)?{frequency:t}:Oh}function Uw(){try{const e=localStorage.getItem(sg);return xE(e?JSON.parse(e):null)}catch{return Oh}}function _O(e){const t=xE(e);localStorage.setItem(sg,JSON.stringify(t)),window.dispatchEvent(new CustomEvent(Dh,{detail:t}))}const vp=(e,t)=>{const n=e.split(".").map(Number),r=t.split(".").map(Number);for(let a=0;a<Math.max(n.length,r.length);a++){const s=n[a]||0,o=r[a]||0;if(s!==o)return s-o}return 0},IO="1.54.5",jd="pixcode:update-available",LO=360*60*1e3,yp=new Map;function vE(e,t){return`pixcode.updateCheck.cache.${e}.${t}`}function PO(e,t){try{const n=localStorage.getItem(vE(e,t));if(!n)return null;const r=JSON.parse(n);return{fetchedAt:typeof r.fetchedAt=="number"?r.fetchedAt:null,latestVersion:typeof r.latestVersion=="string"?r.latestVersion:null,releaseInfo:r.releaseInfo??null,rateLimitedUntil:typeof r.rateLimitedUntil=="number"?r.rateLimitedUntil:void 0}}catch{return null}}function $w(e,t,n){localStorage.setItem(vE(e,t),JSON.stringify(n))}function DO(e,t){const n=`${e}/${t}`,r=yp.get(n);if(r)return r;const a=fetch(`https://api.github.com/repos/${e}/${t}/releases/latest`,{cache:"no-store",headers:{Accept:"application/vnd.github+json"}}).then(async s=>({status:s.status,ok:s.ok,data:await s.json().catch(()=>({}))})).finally(()=>{yp.delete(n)});return yp.set(n,a),a}const lg=(e,t)=>{const[n,r]=m.useState(!1),[a,s]=m.useState(null),[o,l]=m.useState(null),[c,d]=m.useState("git"),[u,p]=m.useState("idle"),[f,h]=m.useState(null),[g,b]=m.useState(()=>Uw()),[x,v]=m.useState(IO),y=m.useRef(null),w=m.useCallback(S=>{_O(S),b(S)},[]);m.useEffect(()=>{const S=()=>b(Uw()),C=N=>{N.key===sg&&S()};return window.addEventListener("storage",C),window.addEventListener(Dh,S),()=>{window.removeEventListener("storage",C),window.removeEventListener(Dh,S)}},[]),m.useEffect(()=>{let S=!1;const C=async()=>{try{const A=await(await fetch("/health",{cache:"no-store"})).json();if(S)return;(A.installMode==="npm"||A.installMode==="git")&&d(A.installMode),typeof A.version=="string"&&/^\d+\.\d+\.\d+/.test(A.version)&&v(A.version)}catch{}};C();const N=()=>{C()};return window.addEventListener("focus",N),()=>{S=!0,window.removeEventListener("focus",N)}},[]),m.useEffect(()=>{if(!x)return;let S=!1;const C=(T,_,E,O)=>({updateAvailable:!!(T&&vp(T,x)>0),latestVersion:T,releaseInfo:_,currentVersion:x,checkedAt:E,status:O}),N=T=>{!T.updateAvailable||!T.latestVersion||!T.releaseInfo||window.dispatchEvent(new CustomEvent(jd,{detail:T}))},R=(T,_,E,O="success")=>{if(!T||!_)return r(!1),s(null),l(null),h(E),C(null,null,E,O);s(T),r(vp(T,x)>0),l(_),h(E);const $=C(T,_,E,O);return N($),$},A=async({force:T=!1}={})=>{const _=Bw(g),E=PO(e,t),O=Date.now();if(!T&&_===null)return p("idle"),R(E?.latestVersion??null,E?.releaseInfo??null,E?.fetchedAt??null,"idle");if(!T&&E?.fetchedAt&&_!==null&&O-E.fetchedAt<_)return p("success"),R(E.latestVersion,E.releaseInfo,E.fetchedAt,"success");if(!T&&E?.rateLimitedUntil&&E.rateLimitedUntil>O)return p("error"),R(E.latestVersion,E.releaseInfo,E.fetchedAt,"error");try{p("checking");const $=await DO(e,t);if(S)return C(E?.latestVersion??null,E?.releaseInfo??null,E?.fetchedAt??null,"idle");const B=$.data;if(!$.ok)return $.status===403&&$w(e,t,{fetchedAt:E?.fetchedAt??null,latestVersion:E?.latestVersion??null,releaseInfo:E?.releaseInfo??null,rateLimitedUntil:O+Math.max(_??0,LO)}),p("error"),R(E?.latestVersion??null,E?.releaseInfo??null,E?.fetchedAt??null,"error");if(B.tag_name){const K=B.tag_name.replace(/^v/,""),Y=vp(K,x)>0,P={title:B.name||B.tag_name,body:B.body||"",htmlUrl:B.html_url||`https://github.com/${e}/${t}/releases/latest`,publishedAt:B.published_at||""};$w(e,t,{fetchedAt:O,latestVersion:K,releaseInfo:P}),s(K),r(Y),Y&&b4({key:`app-update:${K}`,title:"Pixcode update available",body:`Pixcode ${x} can update to ${K}.`,tag:"pixcode-app-update",data:{type:"app-update",latestVersion:K,installMode:c}}),l(P),p("success"),h(O);const z=C(K,P,O,"success");return N(z),z}else return r(!1),s(null),l(null),p("error"),C(null,null,null,"error")}catch($){return console.error("Version check failed:",$),p("error"),R(E?.latestVersion??null,E?.releaseInfo??null,E?.fetchedAt??null,"error")}};y.current=A,A();const j=Bw(g),L=j===null?null:window.setInterval(()=>{A()},j);return()=>{S=!0,L!==null&&window.clearInterval(L)}},[e,t,x,c,g]);const k=m.useCallback(async()=>y.current?await y.current({force:!0}):null,[]);return{updateAvailable:n,latestVersion:a,currentVersion:x,releaseInfo:o,installMode:c,checkStatus:u,lastCheckedAt:f,manualCheck:k,updateCheckPreferences:g,updatePreferences:w}},Di={autoExpandTools:!1,showRawParameters:!1,showThinking:!0,autoScrollToBottom:!0,sendByCtrlEnter:!1,changeAwareness:!1,sidebarVisible:!0,historyView:"flat",autoShowAgentDiff:"always"},OO=["flat","grouped"],MO=e=>typeof e=="string"&&OO.includes(e),FO=["always","openOnly","off"],zO=e=>typeof e=="string"&&FO.includes(e),Rd=Object.keys(Di),BO=new Set(Rd),wp="ui-preferences:sync",UO=(e,t)=>{if(typeof e=="boolean")return e;if(typeof e=="string"){if(e==="true")return!0;if(e==="false")return!1}return t},_d=(e,t,n)=>e==="historyView"?MO(t)?t:n:e==="autoShowAgentDiff"?zO(t)?t:n:UO(t,n),$O=(e,t)=>{try{const n=localStorage.getItem(e);if(n===null)return t;const r=JSON.parse(n);return _d(e,r,t)}catch{return t}},HO=e=>{if(typeof window>"u")return Di;try{const t=localStorage.getItem(e);if(t){const n=JSON.parse(t);if(n&&typeof n=="object"&&!Array.isArray(n)){const r=n;return Rd.reduce((a,s)=>(a[s]=_d(s,r[s],Di[s]),a),{...Di})}}}catch{}return Rd.reduce((t,n)=>(t[n]=$O(n,Di[n]),t),{...Di})};function GO(e,t){switch(t.type){case"set":{const{key:n,value:r}=t;if(!BO.has(n))return e;const a=_d(n,r,e[n]);return e[n]===a?e:{...e,[n]:a}}case"set_many":{const n=t.value||{};let r=!1;const a={...e};for(const s of Rd){if(!(s in n))continue;const o=n[s],l=_d(s,o,e[s]);a[s]!==l&&(a[s]=l,r=!0)}return r?a:e}case"reset":return{...Di,...t.value||{}};default:return e}}function ku(e="uiPreferences"){const t=m.useRef(`ui-preferences-${Math.random().toString(36).slice(2)}`),[n,r]=m.useReducer(GO,e,HO);return m.useEffect(()=>{typeof window>"u"||(localStorage.setItem(e,JSON.stringify(n)),window.dispatchEvent(new CustomEvent(wp,{detail:{storageKey:e,sourceId:t.current,value:n}})))},[n,e]),m.useEffect(()=>{if(typeof window>"u")return;const l=u=>{!u||typeof u!="object"||Array.isArray(u)||r({type:"set_many",value:u})},c=u=>{if(!(u.key!==e||u.newValue===null))try{const p=JSON.parse(u.newValue);l(p)}catch{}},d=u=>{const f=u.detail;!f||f.storageKey!==e||f.sourceId===t.current||l(f.value)};return window.addEventListener("storage",c),window.addEventListener(wp,d),()=>{window.removeEventListener("storage",c),window.removeEventListener(wp,d)}},[e]),{preferences:n,setPreference:(l,c)=>{r({type:"set",key:l,value:c})},setPreferences:l=>{r({type:"set_many",value:l})},resetPreferences:l=>{r({type:"reset",value:l})},dispatch:r}}const WO=()=>{try{const e=localStorage.getItem("claude-settings");return e&&JSON.parse(e).projectSortOrder==="date"?"date":"name"}catch{return"name"}},VO=()=>{try{const e=localStorage.getItem("starredProjects");return e?new Set(JSON.parse(e)):new Set}catch{return new Set}},qO=e=>{try{localStorage.setItem("starredProjects",JSON.stringify([...e]))}catch{}},Hw=(e,t)=>`${e}::${t}`,KO=()=>{try{const e=localStorage.getItem("starredSessions");return e?new Set(JSON.parse(e)):new Set}catch{return new Set}},YO=e=>{try{localStorage.setItem("starredSessions",JSON.stringify([...e]))}catch{}},ZO=/(?:^|[\s/\\(\[`"'])([\w./-]+?\.(?:ts|tsx|js|jsx|mjs|cjs|py|rb|go|rs|java|kt|swift|c|cc|cpp|h|hpp|cs|php|sh|bash|zsh|json|ya?ml|toml|md|mdx|html?|css|scss|less|sql|prisma|graphql|gql|vue|svelte|astro|dart|lua|r|pl|ps1|tf|dockerfile|env))(?:$|[\s:,)\]`"'])/i,XO=e=>{if(!e)return[];const t=new Set,n=new RegExp(ZO.source,"gi");let r;for(;(r=n.exec(e))!==null;){const a=r[1],s=a.lastIndexOf(".");if(s>-1){const o=a.slice(s+1).toLowerCase();o&&o.length<=10&&t.add(o)}if(t.size>=3)break}return[...t]},Ui=e=>e.__provider==="cursor"?new Date(e.createdAt||0):e.__provider==="codex"?new Date(e.createdAt||e.lastActivity||0):new Date(e.lastActivity||e.createdAt||0),QO=(e,t)=>e.__provider==="cursor"?e.summary||e.name||t("projects.untitledSession"):e.__provider==="codex"?e.summary||e.name||t("projects.codexSession"):e.__provider==="gemini"||e.__provider==="qwen"||e.__provider==="opencode"?e.summary||e.name||t("projects.newSession"):e.summary||t("projects.newSession"),JO=e=>e.__provider==="cursor"?String(e.createdAt||""):e.__provider==="codex"?String(e.createdAt||e.lastActivity||""):String(e.lastActivity||e.createdAt||""),eM=(e,t,n)=>{const r=Ui(e),a=Math.floor((t.getTime()-r.getTime())/(1e3*60));return{isCursorSession:e.__provider==="cursor",isCodexSession:e.__provider==="codex",isGeminiSession:e.__provider==="gemini",isQwenSession:e.__provider==="qwen",isOpencodeSession:e.__provider==="opencode",isActive:a<10,sessionName:QO(e,n),sessionTime:JO(e),messageCount:Number(e.messageCount||0)}},yE=(e,t)=>{const n=[...e.sessions||[],...t[e.name]||[]].map(g=>({...g,__provider:"claude"})),r=(e.cursorSessions||[]).map(g=>({...g,__provider:"cursor"})),a=(e.codexSessions||[]).map(g=>({...g,__provider:"codex"})),s=g=>typeof g.id=="string"&&g.id.startsWith("qwen_")||g.provider==="qwen",o=g=>typeof g.id=="string"&&g.id.startsWith("opencode_")||g.provider==="opencode",l=e.geminiSessions||[],c=l.filter(g=>!s(g)&&!o(g)).map(g=>({...g,__provider:"gemini"})),d=l.filter(g=>s(g)).map(g=>({...g,__provider:"qwen"})),u=l.filter(g=>o(g)).map(g=>({...g,__provider:"opencode"})),p=[...(e.qwenSessions||[]).map(g=>({...g,__provider:"qwen"})),...d],f=[...(e.opencodeSessions||[]).map(g=>({...g,__provider:"opencode"})),...u],h=new Map;for(const g of[...n,...r,...a,...c,...p,...f])h.has(g.id)||h.set(g.id,g);return[...h.values()].sort((g,b)=>Ui(b).getTime()-Ui(g).getTime())},Gw=(e,t)=>{const n=yE(e,t);return n.length===0?new Date(0):n.reduce((r,a)=>{const s=Ui(a);return s>r?s:r},new Date(0))},tM=(e,t,n,r)=>{const a=[...e];return a.sort((s,o)=>{const l=n.has(s.name),c=n.has(o.name);return l&&!c?-1:!l&&c?1:t==="date"?Gw(o,r).getTime()-Gw(s,r).getTime():(s.displayName||s.name).localeCompare(o.displayName||o.name)}),a},nM=(e,t)=>{const n=t.trim().toLowerCase();return n?e.filter(r=>{const a=(r.displayName||r.name).toLowerCase(),s=r.name.toLowerCase();return a.includes(n)||s.includes(n)}):e},rM=e=>{const t=typeof e.fullPath=="string"&&e.fullPath.length>0?e.fullPath:typeof e.path=="string"?e.path:"";return{name:e.name,displayName:typeof e.displayName=="string"&&e.displayName.trim().length>0?e.displayName:e.name,fullPath:t,path:typeof e.path=="string"&&e.path.length>0?e.path:t}};function aM({projects:e,selectedProject:t,selectedSession:n,isLoading:r,isMobile:a,t:s,onRefresh:o,onProjectSelect:l,onSessionSelect:c,onSessionDelete:d,onProjectDelete:u,setSidebarVisible:p,sidebarVisible:f}){const[h,g]=m.useState(new Set),[b,x]=m.useState(null),[v,y]=m.useState(!1),[w,k]=m.useState(""),[S,C]=m.useState({}),[N,R]=m.useState({}),[A,j]=m.useState(new Set),[L,T]=m.useState(new Date),[_,E]=m.useState("name"),[O,$]=m.useState(!1),[B,K]=m.useState({}),[Y,P]=m.useState(null),[z,U]=m.useState(""),[F,J]=m.useState(""),[ae,Q]=m.useState(new Set),[pe,oe]=m.useState(null),[fe,be]=m.useState(null),[Ce,Se]=m.useState(!1),[Te,M]=m.useState(()=>VO()),[de,ce]=m.useState(()=>KO()),[V,Z]=m.useState("projects"),[se,ge]=m.useState(null),[ee,te]=m.useState(!1),[ve,le]=m.useState(null),W=m.useRef(null),G=m.useRef(0),ne=m.useRef(null),he=!a&&!f;m.useEffect(()=>{const Oe=setInterval(()=>{T(new Date)},6e4);return()=>clearInterval(Oe)},[]),m.useEffect(()=>{R({}),j(new Set),K({})},[e]),m.useEffect(()=>{t&&g(Oe=>{if(Oe.has(t.name))return Oe;const qe=new Set(Oe);return qe.add(t.name),qe})},[n,t]),m.useEffect(()=>{if(e.length>0&&!r){const Oe=new Set;e.forEach(qe=>{qe.sessions&&qe.sessions.length>=0&&Oe.add(qe.name)}),j(Oe)}},[e,r]),m.useEffect(()=>{const Oe=()=>{E(WO())};Oe();const qe=Qe=>{Qe.key==="claude-settings"&&Oe()},lt=()=>Oe();return window.addEventListener("storage",qe),window.addEventListener("pixcode:settings-changed",lt),()=>{window.removeEventListener("storage",qe),window.removeEventListener("pixcode:settings-changed",lt)}},[]),m.useEffect(()=>{W.current&&clearTimeout(W.current),ne.current&&(ne.current.close(),ne.current=null);const Oe=F.trim();if(V!=="conversations"||Oe.length<2){G.current+=1,ge(null),le(null),te(!1);return}te(!0);const qe=++G.current;return W.current=setTimeout(()=>{if(qe!==G.current)return;const lt=Tt.searchConversationsUrl(Oe),Qe=new EventSource(lt);ne.current=Qe;const xe=[];let De=0;Qe.addEventListener("result",we=>{if(qe!==G.current){Qe.close();return}try{const ke=JSON.parse(we.data);xe.push(ke.projectResult),De=ke.totalMatches,ge({results:[...xe],totalMatches:De,query:Oe}),le({scannedProjects:ke.scannedProjects,totalProjects:ke.totalProjects})}catch{}}),Qe.addEventListener("progress",we=>{if(qe!==G.current){Qe.close();return}try{const ke=JSON.parse(we.data);De=ke.totalMatches,le({scannedProjects:ke.scannedProjects,totalProjects:ke.totalProjects})}catch{}}),Qe.addEventListener("done",()=>{if(qe!==G.current){Qe.close();return}Qe.close(),ne.current=null,te(!1),le(null),xe.length===0&&ge({results:[],totalMatches:0,query:Oe})}),Qe.addEventListener("error",()=>{if(qe!==G.current){Qe.close();return}Qe.close(),ne.current=null,te(!1),le(null),xe.length===0&&ge({results:[],totalMatches:0,query:Oe})})},400),()=>{W.current&&clearTimeout(W.current),ne.current&&(ne.current.close(),ne.current=null)}},[F,V]);const Pe=m.useCallback(Oe=>{g(qe=>{const lt=new Set;return qe.has(Oe)||lt.add(Oe),lt})},[]),ze=m.useCallback((Oe,qe)=>{c({...Oe,__projectName:qe})},[c]),Ke=m.useCallback(Oe=>{M(qe=>{const lt=new Set(qe);return lt.has(Oe)?lt.delete(Oe):lt.add(Oe),qO(lt),lt})},[]),St=m.useCallback(Oe=>Te.has(Oe),[Te]),Je=m.useCallback((Oe,qe)=>{ce(lt=>{const Qe=Hw(Oe,qe),xe=new Set(lt);return xe.has(Qe)?xe.delete(Qe):xe.add(Qe),YO(xe),xe})},[]),bt=m.useCallback((Oe,qe)=>de.has(Hw(Oe,qe)),[de]),ft=m.useCallback(Oe=>yE(Oe,N),[N]),ot=m.useMemo(()=>e.map(Oe=>{const qe=B[Oe.name];return qe===void 0?Oe:{...Oe,sessionMeta:{...Oe.sessionMeta,hasMore:qe}}}),[B,e]),xt=m.useMemo(()=>tM(ot,_,Te,N),[N,_,ot,Te]),At=m.useMemo(()=>nM(xt,F),[F,xt]),Wt=m.useCallback(Oe=>{x(Oe.name),k(Oe.displayName)},[]),It=m.useCallback(()=>{x(null),k("")},[]),jn=m.useCallback(async Oe=>{try{(await Tt.renameProject(Oe,w)).ok?window.refreshProjects?await window.refreshProjects():window.location.reload():console.error("Failed to rename project")}catch(qe){console.error("Error renaming project:",qe)}finally{x(null),k("")}},[w]),He=m.useCallback((Oe,qe,lt,Qe="claude")=>{be({projectName:Oe,sessionId:qe,sessionTitle:lt,provider:Qe})},[]),it=m.useCallback(async()=>{if(!fe)return;const{projectName:Oe,sessionId:qe,provider:lt}=fe;be(null);try{let Qe;if(lt==="codex"?Qe=await Tt.deleteCodexSession(qe):lt==="gemini"?Qe=await Tt.deleteGeminiSession(qe):lt==="qwen"?Qe=await Tt.deleteQwenSession(qe):Qe=await Tt.deleteSession(Oe,qe),Qe.ok)d?.(qe);else{const xe=await Qe.text();console.error("[Sidebar] Failed to delete session:",{status:Qe.status,error:xe}),alert(s("messages.deleteSessionFailed"))}}catch(Qe){console.error("[Sidebar] Error deleting session:",Qe),alert(s("messages.deleteSessionError"))}},[d,fe,s]),vt=m.useCallback(Oe=>{oe({project:Oe,sessionCount:ft(Oe).length})},[ft]),Re=m.useCallback(async(Oe=!1)=>{if(!pe)return;const{project:qe,sessionCount:lt}=pe,Qe=lt===0;oe(null),Q(xe=>new Set([...xe,qe.name]));try{const xe=await Tt.deleteProject(qe.name,!Qe,Oe);if(xe.ok)u?.(qe.name);else{const De=await xe.json();alert(De.error||s("messages.deleteProjectFailed"))}}catch(xe){console.error("Error deleting project:",xe),alert(s("messages.deleteProjectError"))}finally{Q(xe=>{const De=new Set(xe);return De.delete(qe.name),De})}},[pe,u,s]),Ge=m.useCallback(async Oe=>{const qe=B[Oe.name];if(!(!(qe!==void 0?qe:Oe.sessionMeta?.hasMore===!0)||S[Oe.name])){C(Qe=>({...Qe,[Oe.name]:!0}));try{const Qe=(Oe.sessions?.length||0)+(N[Oe.name]?.length||0),xe=await Tt.sessions(Oe.name,5,Qe);if(!xe.ok)return;const De=await xe.json();R(we=>({...we,[Oe.name]:[...we[Oe.name]||[],...De.sessions||[]]})),De.hasMore===!1&&K(we=>({...we,[Oe.name]:!1}))}catch(Qe){console.error("Error loading more sessions:",Qe)}finally{C(Qe=>({...Qe,[Oe.name]:!1}))}}},[N,S,B]),Ye=m.useCallback(Oe=>{l(Oe)},[l]),Nt=m.useCallback(async()=>{$(!0);try{await o()}finally{$(!1)}},[o]),Lt=m.useCallback(async(Oe,qe,lt,Qe)=>{const xe=lt.trim();if(!xe){P(null),U("");return}try{const De=await Tt.renameSession(qe,xe,Qe);De.ok?await o():(console.error("[Sidebar] Failed to rename session:",De.status),alert(s("messages.renameSessionFailed")))}catch(De){console.error("[Sidebar] Error renaming session:",De),alert(s("messages.renameSessionError"))}finally{P(null),U("")}},[o,s]),wt=m.useCallback(()=>{p(!1)},[p]),Tr=m.useCallback(()=>{p(!0)},[p]);return{isSidebarCollapsed:he,expandedProjects:h,editingProject:b,showNewProject:v,editingName:w,loadingSessions:S,additionalSessions:N,initialSessionsLoaded:A,currentTime:L,projectSortOrder:_,isRefreshing:O,editingSession:Y,editingSessionName:z,searchFilter:F,deletingProjects:ae,deleteConfirmation:pe,sessionDeleteConfirmation:fe,showVersionModal:Ce,starredProjects:Te,starredSessions:de,filteredProjects:At,toggleProject:Pe,handleSessionClick:ze,toggleStarProject:Ke,isProjectStarred:St,toggleStarSession:Je,isSessionStarred:bt,getProjectSessions:ft,startEditing:Wt,cancelEditing:It,saveProjectName:jn,showDeleteSessionConfirmation:He,confirmDeleteSession:it,requestProjectDelete:vt,confirmDeleteProject:Re,loadMoreSessions:Ge,handleProjectSelect:Ye,refreshProjects:Nt,updateSessionSummary:Lt,collapseSidebar:wt,expandSidebar:Tr,setShowNewProject:y,setEditingName:k,setEditingSession:P,setEditingSessionName:U,searchMode:V,setSearchMode:Z,conversationResults:se,isSearching:ee,searchProgress:ve,clearConversationResults:m.useCallback(()=>{G.current+=1,ne.current&&(ne.current.close(),ne.current=null),te(!1),le(null),ge(null)},[]),setSearchFilter:J,setDeleteConfirmation:oe,setSessionDeleteConfirmation:be,setShowVersionModal:Se}}const iM="https://discord.gg/buxwujPNRE",sM="https://github.com/alicomert/pixcode/issues/new";function oM({className:e}){return i.jsx("svg",{className:e,fill:"currentColor",viewBox:"0 0 24 24","aria-hidden":"true",children:i.jsx("path",{d:"M20.317 4.37a19.791 19.791 0 0 0-4.885-1.515.074.074 0 0 0-.079.037c-.21.375-.444.864-.608 1.25a18.27 18.27 0 0 0-5.487 0 12.64 12.64 0 0 0-.617-1.25.077.077 0 0 0-.079-.037A19.736 19.736 0 0 0 3.677 4.37a.07.07 0 0 0-.032.027C.533 9.046-.32 13.58.099 18.057a.082.082 0 0 0 .031.057 19.9 19.9 0 0 0 5.993 3.03.078.078 0 0 0 .084-.028c.462-.63.874-1.295 1.226-1.994a.076.076 0 0 0-.041-.106 13.107 13.107 0 0 1-1.872-.892.077.077 0 0 1-.008-.128 10.2 10.2 0 0 0 .372-.292.074.074 0 0 1 .077-.01c3.928 1.793 8.18 1.793 12.062 0a.074.074 0 0 1 .078.01c.12.098.246.198.373.292a.077.077 0 0 1-.006.127 12.299 12.299 0 0 1-1.873.892.077.077 0 0 0-.041.107c.36.698.772 1.362 1.225 1.993a.076.076 0 0 0 .084.028 19.839 19.839 0 0 0 6.002-3.03.077.077 0 0 0 .032-.054c.5-5.177-.838-9.674-3.549-13.66a.061.061 0 0 0-.031-.03zM8.02 15.33c-1.183 0-2.157-1.085-2.157-2.419 0-1.333.956-2.419 2.157-2.419 1.21 0 2.176 1.095 2.157 2.42 0 1.333-.956 2.418-2.157 2.418zm7.975 0c-1.183 0-2.157-1.085-2.157-2.419 0-1.333.955-2.419 2.157-2.419 1.21 0 2.176 1.095 2.157 2.42 0 1.333-.946 2.418-2.157 2.418z"})})}function lM({onExpand:e,onOpenControlRoom:t,onShowSettings:n,updateAvailable:r,onShowVersionModal:a,t:s}){return i.jsxs("div",{className:"flex h-full w-12 flex-col items-center gap-1 bg-background/80 py-3 backdrop-blur-sm",children:[i.jsx("button",{onClick:e,className:"group flex h-8 w-8 items-center justify-center rounded-lg transition-colors hover:bg-accent/80","aria-label":s("common:versionUpdate.ariaLabels.showSidebar"),title:s("common:versionUpdate.ariaLabels.showSidebar"),children:i.jsx(hu,{className:"h-4 w-4 text-muted-foreground transition-colors group-hover:text-foreground"})}),i.jsx("div",{className:"nav-divider my-1 w-6"}),t&&i.jsx("button",{onClick:t,className:"group flex h-8 w-8 items-center justify-center rounded-lg border border-primary/25 bg-primary/10 transition-colors hover:bg-primary/15","aria-label":s("actions.controlRoom",{defaultValue:"Control Room"}),title:s("actions.controlRoom",{defaultValue:"Control Room"}),children:i.jsx(Vn,{className:"h-4 w-4 text-primary"})}),i.jsx("button",{onClick:n,className:"group flex h-8 w-8 items-center justify-center rounded-lg transition-colors hover:bg-accent/80","aria-label":s("actions.settings"),title:s("actions.settings"),children:i.jsx(Pt,{className:"h-4 w-4 text-muted-foreground transition-colors group-hover:text-foreground"})}),i.jsx("a",{href:sM,target:"_blank",rel:"noopener noreferrer",className:"group flex h-8 w-8 items-center justify-center rounded-lg transition-colors hover:bg-accent/80","aria-label":s("actions.reportIssue"),title:s("actions.reportIssue"),children:i.jsx(Sl,{className:"h-4 w-4 text-muted-foreground transition-colors group-hover:text-foreground"})}),i.jsx("a",{href:iM,target:"_blank",rel:"noopener noreferrer",className:"group flex h-8 w-8 items-center justify-center rounded-lg transition-colors hover:bg-accent/80","aria-label":s("actions.joinCommunity"),title:s("actions.joinCommunity"),children:i.jsx(oM,{className:"h-4 w-4 text-muted-foreground transition-colors group-hover:text-foreground"})}),r&&i.jsxs("button",{onClick:a,className:"relative flex h-8 w-8 items-center justify-center rounded-lg transition-colors hover:bg-accent/80","aria-label":s("common:versionUpdate.ariaLabels.updateAvailable"),title:s("common:versionUpdate.ariaLabels.updateAvailable"),children:[i.jsx(Vn,{className:"h-4 w-4 text-blue-500"}),i.jsx("span",{className:"absolute right-1.5 top-1.5 h-1.5 w-1.5 animate-pulse rounded-full bg-blue-500"})]})]})}const Ww=e=>typeof e=="boolean"?`${e}`:e===0?"0":e,Vw=S4,cg=(e,t)=>n=>{var r;if(t?.variants==null)return Vw(e,n?.class,n?.className);const{variants:a,defaultVariants:s}=t,o=Object.keys(a).map(d=>{const u=n?.[d],p=s?.[d];if(u===null)return null;const f=Ww(u)||Ww(p);return a[d][f]}),l=n&&Object.entries(n).reduce((d,u)=>{let[p,f]=u;return f===void 0||(d[p]=f),d},{}),c=t==null||(r=t.compoundVariants)===null||r===void 0?void 0:r.reduce((d,u)=>{let{class:p,className:f,...h}=u;return Object.entries(h).every(g=>{let[b,x]=g;return Array.isArray(x)?x.includes({...s,...l}[b]):{...s,...l}[b]===x})?[...d,p,f]:d},[]);return Vw(e,o,c,n?.class,n?.className)},cM=cg("relative grid w-full grid-cols-[0_1fr] items-start gap-y-0.5 rounded-lg border px-4 py-3 text-sm has-[>svg]:grid-cols-[calc(var(--spacing)*4)_1fr] has-[>svg]:gap-x-3 [&>svg]:size-4 [&>svg]:translate-y-0.5 [&>svg]:text-current",{variants:{variant:{default:"bg-card text-card-foreground",destructive:"bg-card text-destructive *:data-[slot=alert-description]:text-destructive/90 [&>svg]:text-current"}},defaultVariants:{variant:"default"}}),wE=m.forwardRef(({className:e,variant:t,...n},r)=>i.jsx("div",{ref:r,role:"alert","data-slot":"alert",className:me(cM({variant:t}),e),...n}));wE.displayName="Alert";const dM=m.forwardRef(({className:e,...t},n)=>i.jsx("div",{ref:n,"data-slot":"alert-title",className:me("col-start-2 line-clamp-1 min-h-4 font-medium tracking-tight",e),...t}));dM.displayName="AlertTitle";const uM=m.forwardRef(({className:e,...t},n)=>i.jsx("div",{ref:n,"data-slot":"alert-description",className:me("text-muted-foreground col-start-2 grid justify-items-start gap-1 text-sm [&_p]:leading-relaxed",e),...t}));uM.displayName="AlertDescription";const pM=cg("inline-flex items-center rounded-md border px-2.5 py-0.5 text-xs font-semibold transition-colors focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2",{variants:{variant:{default:"border-transparent bg-primary text-primary-foreground shadow hover:bg-primary/80",secondary:"border-transparent bg-secondary text-secondary-foreground hover:bg-secondary/80",destructive:"border-transparent bg-destructive text-destructive-foreground shadow hover:bg-destructive/80",outline:"text-foreground"}},defaultVariants:{variant:"default"}});function hn({className:e,variant:t,...n}){return i.jsx("div",{className:me(pM({variant:t}),e),...n})}const mM=cg("inline-flex touch-manipulation items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0",{variants:{variant:{default:"bg-primary text-primary-foreground shadow hover:bg-primary/90 active:bg-primary/80",destructive:"bg-destructive text-destructive-foreground shadow-sm hover:bg-destructive/90 active:bg-destructive/80",outline:"border border-input bg-background shadow-sm hover:bg-accent hover:text-accent-foreground active:bg-accent/80",secondary:"bg-secondary text-secondary-foreground shadow-sm hover:bg-secondary/80 active:bg-secondary/70",ghost:"hover:bg-accent hover:text-accent-foreground active:bg-accent/80",link:"text-primary underline-offset-4 hover:underline"},size:{default:"h-10 px-4 py-2",sm:"h-9 rounded-md px-3 text-sm",lg:"h-11 rounded-md px-8",icon:"h-10 w-10"}},defaultVariants:{variant:"default",size:"default"}}),Ae=m.forwardRef(({className:e,variant:t,size:n,...r},a)=>i.jsx("button",{className:me(mM({variant:t,size:n,className:e})),ref:a,...r}));Ae.displayName="Button";const kE=m.createContext(null),SE=()=>{const e=m.useContext(kE);if(!e)throw new Error("Confirmation components must be used within Confirmation");return e},CE=({className:e,approval:t="pending",children:n,...r})=>{const a=m.useMemo(()=>({approval:t}),[t]);return i.jsx(kE.Provider,{value:a,children:i.jsx(wE,{className:me("flex flex-col gap-2",e),...r,children:n})})};CE.displayName="Confirmation";const EE=({className:e,...t})=>i.jsx("div",{"data-slot":"confirmation-title",className:me("text-muted-foreground inline text-sm",e),...t});EE.displayName="ConfirmationTitle";const NE=({children:e})=>{const{approval:t}=SE();return t!=="pending"?null:i.jsx(i.Fragment,{children:e})};NE.displayName="ConfirmationRequest";const TE=({className:e,...t})=>{const{approval:n}=SE();return n!=="pending"?null:i.jsx("div",{"data-slot":"confirmation-actions",className:me("flex items-center justify-end gap-2 self-end",e),...t})};TE.displayName="ConfirmationActions";const ad=({variant:e="default",...t})=>i.jsx(Ae,{className:"h-8 px-3 text-sm",variant:e,type:"button",...t});ad.displayName="ConfirmationAction";const AE=m.forwardRef(({className:e,...t},n)=>i.jsx("div",{ref:n,className:me("rounded-xl border bg-card text-card-foreground shadow-sm",e),...t}));AE.displayName="Card";const jE=m.forwardRef(({className:e,...t},n)=>i.jsx("div",{ref:n,className:me("flex flex-col space-y-1.5 p-4",e),...t}));jE.displayName="CardHeader";const RE=m.forwardRef(({className:e,...t},n)=>i.jsx("h3",{ref:n,className:me("font-semibold leading-none tracking-tight",e),...t}));RE.displayName="CardTitle";const hM=m.forwardRef(({className:e,...t},n)=>i.jsx("p",{ref:n,className:me("text-sm text-muted-foreground",e),...t}));hM.displayName="CardDescription";const _E=m.forwardRef(({className:e,...t},n)=>i.jsx("div",{ref:n,className:me("p-4 pt-0",e),...t}));_E.displayName="CardContent";const IE=m.forwardRef(({className:e,...t},n)=>i.jsx("div",{ref:n,className:me("flex items-center p-4 pt-0",e),...t}));IE.displayName="CardFooter";const fM=m.forwardRef(({className:e,...t},n)=>i.jsx("div",{ref:n,className:me("ml-auto shrink-0",e),...t}));fM.displayName="CardAction";const LE=m.createContext(null);function PE(){const e=m.useContext(LE);if(!e)throw new Error("Collapsible components must be used within <Collapsible>");return e}const Yi=m.forwardRef(({defaultOpen:e=!1,open:t,onOpenChange:n,className:r,children:a,...s},o)=>{const[l,c]=m.useState(e),d=t!==void 0,u=d?t:l,p=m.useCallback(h=>{d||c(h),n?.(h)},[d,n]),f=m.useMemo(()=>({open:u,onOpenChange:p}),[u,p]);return i.jsx(LE.Provider,{value:f,children:i.jsx("div",{ref:o,"data-state":u?"open":"closed",className:r,...s,children:a})})});Yi.displayName="Collapsible";const di=m.forwardRef(({onClick:e,children:t,className:n,...r},a)=>{const{open:s,onOpenChange:o}=PE(),l=m.useCallback(c=>{o(!s),e?.(c)},[s,o,e]);return i.jsx("button",{ref:a,type:"button","aria-expanded":s,"data-state":s?"open":"closed",onClick:l,className:n,...r,children:t})});di.displayName="CollapsibleTrigger";const Zi=m.forwardRef(({className:e,children:t,...n},r)=>{const{open:a}=PE();return i.jsx("div",{ref:r,"data-state":a?"open":"closed",className:me("grid transition-[grid-template-rows] duration-200 ease-out",a?"grid-rows-[1fr]":"grid-rows-[0fr]",e),...n,children:i.jsx("div",{className:"overflow-hidden",children:t})})});Zi.displayName="CollapsibleContent";const DE=m.createContext(null);function dg(){const e=m.useContext(DE);if(!e)throw new Error("Command components must be used within <Command>");return e}const OE=m.forwardRef(({className:e,children:t,...n},r)=>{const[a,s]=m.useState(""),o=m.useRef(new Map),[l,c]=m.useState(0),d=m.useCallback(y=>{o.current.set(y.id,y),c(w=>w+1)},[]),u=m.useCallback(y=>{o.current.delete(y),c(w=>w+1)},[]),p=m.useCallback((y,w)=>{const k=o.current.get(y);k&&Object.assign(k,w)},[]),f=m.useMemo(()=>{const y=a.toLowerCase(),w=new Set;for(const[k,S]of o.current)(!y||S.value.includes(y))&&w.add(k);return w},[a,l]),h=m.useMemo(()=>{const y=[];for(const[,w]of o.current)f.has(w.id)&&y.push(w);return y},[f]),[g,b]=m.useState(null);m.useEffect(()=>{b(h.length>0?h[0].id:null)},[h]);const x=m.useCallback(y=>{if(y.key==="ArrowDown"||y.key==="ArrowUp"||y.key==="Enter")y.preventDefault();else return;const w=h;if(w.length===0)return;if(y.key==="Enter"){w.find(A=>A.id===g)?.onSelect();return}const k=w.findIndex(R=>R.id===g);let S;y.key==="ArrowDown"?S=k<w.length-1?k+1:0:S=k>0?k-1:w.length-1;const C=w[S].id;b(C),w[S].element?.scrollIntoView({block:"nearest"})},[h,g]),v=m.useMemo(()=>({search:a,setSearch:s,visibleIds:f,activeId:g,setActiveId:b,register:d,unregister:u,updateEntry:p}),[a,f,g,d,u,p]);return i.jsx(DE.Provider,{value:v,children:i.jsx("div",{ref:r,role:"combobox","aria-expanded":"true","aria-haspopup":"listbox",className:me("flex flex-col",e),onKeyDown:x,...n,children:t})})});OE.displayName="Command";const ME=m.forwardRef(({className:e,placeholder:t="Search...",...n},r)=>{const{search:a,setSearch:s}=dg();return i.jsxs("div",{className:"flex items-center border-b px-3",role:"presentation",children:[i.jsx(ja,{className:"mr-2 h-4 w-4 shrink-0 text-muted-foreground","aria-hidden":!0}),i.jsx("input",{ref:r,type:"text",role:"searchbox","aria-autocomplete":"list",autoComplete:"off",autoCorrect:"off",spellCheck:!1,value:a,onChange:o=>s(o.target.value),placeholder:t,className:me("flex h-11 w-full rounded-md bg-transparent py-3 text-sm outline-none","placeholder:text-muted-foreground disabled:cursor-not-allowed disabled:opacity-50",e),...n})]})});ME.displayName="CommandInput";const FE=m.forwardRef(({className:e,...t},n)=>i.jsx("div",{ref:n,role:"listbox",className:me("max-h-[300px] overflow-y-auto overflow-x-hidden",e),...t}));FE.displayName="CommandList";const zE=m.forwardRef(({className:e,...t},n)=>{const{search:r,visibleIds:a}=dg();return!r||a.size>0?null:i.jsx("div",{ref:n,className:me("py-6 text-center text-sm text-muted-foreground",e),...t})});zE.displayName="CommandEmpty";const BE=m.forwardRef(({className:e,heading:t,children:n,...r},a)=>i.jsxs("div",{ref:a,className:me("overflow-hidden p-1",e),role:"group","aria-label":typeof t=="string"?t:void 0,...r,children:[t&&i.jsx("div",{className:"px-2 py-1.5 text-xs font-medium text-muted-foreground",role:"presentation",children:t}),n]}));BE.displayName="CommandGroup";const UE=m.forwardRef(({className:e,value:t,onSelect:n,disabled:r,children:a,...s},o)=>{const{visibleIds:l,activeId:c,setActiveId:d,register:u,unregister:p,updateEntry:f}=dg(),h=m.useId(),g=m.useRef(null),b=t||(typeof a=="string"?a:"");m.useEffect(()=>(u({id:h,value:b.toLowerCase(),onSelect:n||(()=>{}),element:g.current}),()=>p(h)),[h,b,u,p]),m.useEffect(()=>{f(h,{onSelect:n||(()=>{})})},[h,n,f]);const x=m.useCallback(y=>{g.current=y,f(h,{element:y}),typeof o=="function"?o(y):o&&(o.current=y)},[h,f,o]);if(!l.has(h))return null;const v=c===h;return i.jsx("div",{ref:x,role:"option","aria-selected":v,"aria-disabled":r||void 0,"data-active":v||void 0,className:me("relative flex cursor-pointer select-none items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-none",v&&"bg-accent text-accent-foreground",r&&"pointer-events-none opacity-50",e),onPointerMove:()=>{!r&&c!==h&&d(h)},onClick:()=>!r&&n?.(),...s,children:a})});UE.displayName="CommandItem";const gM=m.forwardRef(({className:e,...t},n)=>i.jsx("div",{ref:n,className:me("-mx-1 h-px bg-border",e),...t}));gM.displayName="CommandSeparator";function Id({checked:e,onToggle:t,ariaLabel:n}){const{t:r}=Fe("settings"),{isDarkMode:a,toggleDarkMode:s}=Fa(),o=typeof e=="boolean",l=o?e:a,c=n||r("quickSettings.darkMode",{defaultValue:"Toggle dark mode"}),d=()=>{if(o){t?.(!l);return}s()};return i.jsxs("button",{onClick:d,className:me("relative inline-flex h-7 w-12 flex-shrink-0 touch-manipulation cursor-pointer items-center rounded-full border-2 transition-colors duration-200","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background",l?"border-primary bg-primary":"border-border bg-muted"),role:"switch","aria-checked":l,"aria-label":c,children:[i.jsx("span",{className:"sr-only",children:c}),i.jsx("span",{className:me("flex h-5 w-5 transform items-center justify-center rounded-full shadow-sm transition-transform duration-200",l?"translate-x-[22px] bg-white":"translate-x-[2px] bg-foreground/60 dark:bg-foreground/80"),children:l?i.jsx(oE,{className:"h-3 w-3 text-primary"}):i.jsx(dE,{className:"h-3 w-3 text-white dark:text-background"})})]})}const $E=m.createContext(null);function HE(){const e=m.useContext($E);if(!e)throw new Error("Dialog components must be used within <Dialog>");return e}const GE=({open:e,onOpenChange:t,defaultOpen:n=!1,children:r})=>{const[a,s]=m.useState(n),o=m.useRef(null),l=e!==void 0,c=l?e:a,d=m.useCallback(p=>{l||s(p),t?.(p)},[l,t]),u=m.useMemo(()=>({open:c,onOpenChange:d,triggerRef:o}),[c,d]);return i.jsx($E.Provider,{value:u,children:r})},bM=m.forwardRef(({onClick:e,children:t,asChild:n,...r},a)=>{const{onOpenChange:s,triggerRef:o}=HE(),l=m.useCallback(c=>{s(!0),e?.(c)},[s,e]);if(n&&m.isValidElement(t)){const c=t;return m.cloneElement(c,{onClick:d=>{s(!0),c.props.onClick?.(d)},ref:d=>{o.current=d,typeof a=="function"?a(d):a&&(a.current=d)}})}return i.jsx("button",{ref:c=>{o.current=c,typeof a=="function"?a(c):a&&(a.current=c)},type:"button",onClick:l,...r,children:t})});bM.displayName="DialogTrigger";const qw='a[href], button:not([disabled]), input:not([disabled]), textarea:not([disabled]), select:not([disabled]), [tabindex]:not([tabindex="-1"])',ug=m.forwardRef(({className:e,children:t,onEscapeKeyDown:n,onPointerDownOutside:r,...a},s)=>{const{open:o,onOpenChange:l,triggerRef:c}=HE(),d=m.useRef(null),u=m.useRef(null);return m.useEffect(()=>{o?u.current=document.activeElement:u.current&&((c.current||u.current)?.focus(),u.current=null)},[o,c]),m.useEffect(()=>{if(!o)return;const p=h=>{if(h.key==="Escape"){h.stopPropagation(),n?.(),l(!1);return}if(h.key==="Tab"&&d.current){const g=Array.from(d.current.querySelectorAll(qw));if(g.length===0)return;const b=g[0],x=g[g.length-1];h.shiftKey&&document.activeElement===b?(h.preventDefault(),x.focus()):!h.shiftKey&&document.activeElement===x&&(h.preventDefault(),b.focus())}};document.addEventListener("keydown",p,!0);const f=document.body.style.overflow;return document.body.style.overflow="hidden",()=>{document.removeEventListener("keydown",p,!0),document.body.style.overflow=f}},[o,l,n]),m.useEffect(()=>{o&&d.current&&requestAnimationFrame(()=>{d.current?.querySelector(qw)?.focus()})},[o]),o?du.createPortal(i.jsxs("div",{className:"fixed inset-0 z-50",children:[i.jsx("div",{className:"fixed inset-0 animate-dialog-overlay-show bg-black/50 backdrop-blur-sm",onClick:()=>{r?.(),l(!1)},"aria-hidden":!0}),i.jsx("div",{ref:p=>{d.current=p,typeof s=="function"?s(p):s&&(s.current=p)},role:"dialog","aria-modal":"true",className:me("fixed left-1/2 top-1/2 z-50 w-full max-w-lg -translate-x-1/2 -translate-y-1/2","rounded-xl border bg-popover text-popover-foreground shadow-lg","animate-dialog-content-show",e),...a,children:t})]}),document.body):null});ug.displayName="DialogContent";const pg=m.forwardRef(({className:e,...t},n)=>i.jsx("h2",{ref:n,className:me("sr-only",e),...t}));pg.displayName="DialogTitle";const Ze=m.forwardRef(({className:e,type:t,...n},r)=>i.jsx("input",{type:t,className:me("flex h-9 w-full rounded-md border border-input bg-transparent px-3 py-1 text-sm shadow-sm transition-colors file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50",e),ref:r,...n}));Ze.displayName="Input";const mg=m.forwardRef(({className:e,contentClassName:t,children:n,...r},a)=>i.jsx("div",{className:me("relative overflow-hidden",e),...r,children:i.jsx("div",{ref:a,className:me("h-full w-full overflow-auto rounded-[inherit]",t),style:{WebkitOverflowScrolling:"touch",touchAction:"pan-y"},children:n})}));mg.displayName="ScrollArea";const Ld=m.memo(({children:e,className:t,as:n="span"})=>i.jsx(n,{className:me("animate-shimmer inline-block bg-[length:250%_100%] bg-clip-text text-transparent","bg-[linear-gradient(90deg,transparent_33%,hsl(var(--foreground))_50%,transparent_67%),linear-gradient(hsl(var(--muted-foreground)),hsl(var(--muted-foreground)))]",t),children:e}));Ld.displayName="Shimmer";const WE=m.createContext(null),xM=()=>{const e=m.useContext(WE);if(!e)throw new Error("Reasoning components must be used within Reasoning");return e},vM=1e3,yM=1e3,Mh=m.memo(({className:e,isStreaming:t=!1,open:n,defaultOpen:r,onOpenChange:a,duration:s,children:o,...l})=>{const c=r??t,d=r===!1,[u,p]=m.useState(c),f=n!==void 0,h=f?n:u,g=m.useCallback(C=>{f||p(C),a?.(C)},[f,a]),[b,x]=m.useState(s),v=m.useRef(t),[y,w]=m.useState(!1),k=m.useRef(null);m.useEffect(()=>{s!==void 0&&x(s)},[s]),m.useEffect(()=>{t?(v.current=!0,k.current===null&&(k.current=Date.now())):k.current!==null&&(x(Math.ceil((Date.now()-k.current)/yM)),k.current=null)},[t]),m.useEffect(()=>{t&&!h&&!d&&g(!0)},[t,h,g,d]),m.useEffect(()=>{if(v.current&&!t&&h&&!y){const C=setTimeout(()=>{g(!1),w(!0)},vM);return()=>clearTimeout(C)}},[t,h,g,y]);const S=m.useMemo(()=>({duration:b,isOpen:h,isStreaming:t,setIsOpen:g}),[b,h,t,g]);return i.jsx(WE.Provider,{value:S,children:i.jsx(Yi,{open:h,onOpenChange:g,className:me("not-prose",e),...l,children:o})})});Mh.displayName="Reasoning";const wM=(e,t)=>e||t===0?i.jsx(Ld,{children:"Thinking..."}):t===void 0?i.jsx("p",{children:"Thought for a few seconds"}):i.jsxs("p",{children:["Thought for ",t," seconds"]}),Fh=m.memo(({className:e,children:t,getThinkingMessage:n=wM,...r})=>{const{isStreaming:a,isOpen:s,duration:o}=xM();return i.jsx(di,{className:me("flex w-full items-center gap-2 text-sm text-muted-foreground transition-colors hover:text-foreground",e),...r,children:t??i.jsxs(i.Fragment,{children:[i.jsx(VD,{className:"h-4 w-4"}),n(a,o),i.jsx($4,{className:me("h-4 w-4 transition-transform",s?"rotate-180":"rotate-0")})]})})});Fh.displayName="ReasoningTrigger";const zh=m.memo(({className:e,children:t,...n})=>i.jsx(Zi,{className:me("mt-4 text-sm text-muted-foreground",e),...n,children:t}));zh.displayName="ReasoningContent";function kM(e){switch(e){case"top":return"top-full left-1/2 transform -translate-x-1/2 border-t-gray-900 dark:border-t-gray-100";case"bottom":return"bottom-full left-1/2 transform -translate-x-1/2 border-b-gray-900 dark:border-b-gray-100";case"left":return"left-full top-1/2 transform -translate-y-1/2 border-l-gray-900 dark:border-l-gray-100";case"right":return"right-full top-1/2 transform -translate-y-1/2 border-r-gray-900 dark:border-r-gray-100";default:return"top-full left-1/2 transform -translate-x-1/2 border-t-gray-900 dark:border-t-gray-100"}}function Bh({children:e,content:t,position:n="top",className:r="",delay:a=350}){const[s,o]=m.useState(!1),l=m.useRef(null),c=m.useRef(!1),d=m.useRef(null),u=m.useRef(null),[p,f]=m.useState(null),h=m.useCallback(()=>{const w=d.current;if(!w)return;const k=w.getBoundingClientRect(),S=8,C={position:"fixed",zIndex:9999};switch(n){case"bottom":C.left=k.left+k.width/2,C.top=k.bottom+S,C.transform="translateX(-50%)";break;case"left":C.left=k.left-S,C.top=k.top+k.height/2,C.transform="translate(-100%, -50%)";break;case"right":C.left=k.right+S,C.top=k.top+k.height/2,C.transform="translateY(-50%)";break;case"top":default:C.left=k.left+k.width/2,C.top=k.top-S,C.transform="translate(-50%, -100%)";break}f(C)},[n]),g=()=>{l.current!==null&&(window.clearTimeout(l.current),l.current=null)},b=()=>{g(),l.current=window.setTimeout(()=>{o(!0)},a)},x=()=>{g(),o(!1)},v=()=>{g(),c.current=!1,l.current=window.setTimeout(()=>{c.current=!0,o(!0)},a)},y=()=>{g(),!c.current&&o(!1)};return m.useEffect(()=>()=>{g()},[]),m.useEffect(()=>{if(!s||typeof document>"u")return;const w=k=>{const S=k.target;S instanceof Node&&d.current?.contains(S)||(o(!1),c.current=!1)};return document.addEventListener("pointerdown",w,!0),()=>document.removeEventListener("pointerdown",w,!0)},[s]),m.useEffect(()=>{if(!s){f(null);return}const w=window.requestAnimationFrame(h),k=()=>h();return window.addEventListener("resize",k),window.addEventListener("scroll",k,!0),()=>{window.cancelAnimationFrame(w),window.removeEventListener("resize",k),window.removeEventListener("scroll",k,!0)}},[s,h]),t?i.jsxs("div",{ref:d,className:"relative inline-block",onMouseEnter:b,onMouseLeave:x,onTouchStart:v,onTouchEnd:y,onTouchCancel:y,children:[e,s&&typeof document<"u"&&du.createPortal(i.jsxs("div",{ref:u,style:p||{position:"fixed",top:"-9999px",left:"-9999px",opacity:0},className:me("px-2 py-1 text-xs font-medium text-white bg-gray-900 dark:bg-gray-100 dark:text-gray-900 rounded shadow-lg whitespace-nowrap pointer-events-none","animate-in fade-in-0 zoom-in-95 duration-200",r),children:[t,i.jsx("div",{className:me("absolute w-0 h-0 border-4 border-transparent",kM(n))})]}),document.body)]}):i.jsx(i.Fragment,{children:e})}const VE=m.createContext(null),qE=m.forwardRef(({className:e,status:t="ready",children:n,...r},a)=>{const s=m.useMemo(()=>({status:t}),[t]);return i.jsx(VE.Provider,{value:s,children:i.jsx("form",{ref:a,"data-slot":"prompt-input",className:me("relative overflow-hidden rounded-xl border border-border/70 bg-zinc-50/95 shadow-sm shadow-zinc-950/5 backdrop-blur-sm transition-all duration-200 focus-within:border-primary/40 focus-within:shadow-md focus-within:ring-1 focus-within:ring-primary/20 dark:bg-zinc-950/90",e),...r,children:n})})});qE.displayName="PromptInput";const KE=m.forwardRef(({className:e,...t},n)=>i.jsx("div",{ref:n,"data-slot":"prompt-input-header",className:me("px-3 pt-3",e),...t}));KE.displayName="PromptInputHeader";const YE=m.forwardRef(({className:e,...t},n)=>i.jsx("div",{ref:n,"data-slot":"prompt-input-body",className:me("relative",e),...t}));YE.displayName="PromptInputBody";const ZE=m.forwardRef(({className:e,...t},n)=>i.jsx("textarea",{ref:n,"data-slot":"prompt-input-textarea",className:me("chat-input-placeholder block max-h-[40vh] w-full resize-none overflow-y-auto bg-transparent px-4 py-2 font-mono text-sm leading-6 text-foreground placeholder-muted-foreground/50 focus:outline-none sm:max-h-[300px]",e),...t}));ZE.displayName="PromptInputTextarea";const XE=m.forwardRef(({className:e,...t},n)=>i.jsx("div",{ref:n,"data-slot":"prompt-input-footer",className:me("flex items-center justify-between border-t border-border/30 px-3 py-2",e),...t}));XE.displayName="PromptInputFooter";const QE=m.forwardRef(({className:e,...t},n)=>i.jsx("div",{ref:n,"data-slot":"prompt-input-tools",className:me("flex items-center gap-1",e),...t}));QE.displayName="PromptInputTools";const id=m.forwardRef(({className:e,tooltip:t,children:n,...r},a)=>{const s=i.jsx(Ae,{ref:a,type:"button",variant:"ghost",size:"icon",className:me("h-8 w-8 [&_svg]:size-4",e),...r,children:n});return t?i.jsx(Bh,{content:t.shortcut?i.jsxs("span",{className:"flex items-center gap-1.5",children:[t.content,i.jsx("kbd",{className:"rounded bg-white/20 px-1 text-[10px]",children:t.shortcut})]}):t.content,position:t.side??"top",children:s}):s});id.displayName="PromptInputButton";const JE=m.forwardRef(({className:e,status:t,children:n,...r},a)=>{const s=m.useContext(VE),o=t??s?.status??"ready",l=o==="submitted"||o==="streaming";return i.jsx(Ae,{ref:a,type:l?"button":"submit",variant:"default",size:"icon",className:me("h-8 w-8 rounded-lg",e),...r,children:n??(l?i.jsx(FD,{className:"h-3.5 w-3.5 fill-current"}):i.jsx(RD,{className:"h-4 w-4"}))})});JE.displayName="PromptInputSubmit";function hg({children:e,className:t}){return i.jsx("div",{className:me("inline-flex max-w-full items-center gap-1 rounded-lg bg-muted/60 p-1",t),children:e})}function fg({isActive:e,onClick:t,children:n,className:r}){return i.jsx("button",{type:"button",onClick:t,className:me("flex min-w-0 touch-manipulation items-center justify-center gap-1.5 rounded-md px-3 py-2 text-sm font-medium transition-all duration-150",e?"bg-background text-foreground shadow-sm":"text-muted-foreground active:bg-background/50",r),children:n})}const eN=m.createContext(null);function tN(){const e=m.useContext(eN);if(!e)throw new Error("QueueItem sub-components must be used within <QueueItem>");return e}const nN=m.forwardRef(({className:e,...t},n)=>i.jsx("div",{ref:n,"data-slot":"queue",role:"list",className:me("space-y-0.5",e),...t}));nN.displayName="Queue";const rN=m.forwardRef(({status:e="pending",className:t,children:n,...r},a)=>{const s=m.useMemo(()=>({status:e}),[e]);return i.jsx(eN.Provider,{value:s,children:i.jsx("div",{ref:a,"data-slot":"queue-item","data-status":e,role:"listitem",className:me("flex items-start gap-2 py-0.5",t),...r,children:n})})});rN.displayName="QueueItem";const aN=m.forwardRef(({className:e,...t},n)=>{const{status:r}=tN();return i.jsxs("div",{ref:n,"data-slot":"queue-item-indicator","aria-hidden":"true",className:me("mt-0.5 flex h-3.5 w-3.5 flex-shrink-0 items-center justify-center",e),...t,children:[r==="completed"&&i.jsx("svg",{className:"h-3.5 w-3.5 text-green-500 dark:text-green-400",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:i.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z"})}),r==="in_progress"&&i.jsx("span",{className:"h-2 w-2 animate-pulse rounded-full bg-blue-500 dark:bg-blue-400"}),r==="pending"&&i.jsx("svg",{className:"h-3.5 w-3.5 text-muted-foreground/50",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:i.jsx("circle",{cx:"12",cy:"12",r:"9",strokeWidth:2})})]})});aN.displayName="QueueItemIndicator";const iN=m.forwardRef(({className:e,children:t,...n},r)=>{const{status:a}=tN();return i.jsx("div",{ref:r,"data-slot":"queue-item-content",className:me("min-w-0 flex-1 text-xs",a==="completed"&&"text-muted-foreground line-through",a==="in_progress"&&"font-medium text-foreground",a==="pending"&&"text-foreground",e),...n,children:t})});iN.displayName="QueueItemContent";const Kw="https://github.com/alicomert/pixcode/issues/new",Yw="https://github.com/alicomert/pixcode",Zw="https://discord.gg/buxwujPNRE";function Xw({className:e}){return i.jsx("svg",{className:e,fill:"currentColor",viewBox:"0 0 24 24","aria-hidden":"true",children:i.jsx("path",{d:"M20.317 4.37a19.791 19.791 0 0 0-4.885-1.515.074.074 0 0 0-.079.037c-.21.375-.444.864-.608 1.25a18.27 18.27 0 0 0-5.487 0 12.64 12.64 0 0 0-.617-1.25.077.077 0 0 0-.079-.037A19.736 19.736 0 0 0 3.677 4.37a.07.07 0 0 0-.032.027C.533 9.046-.32 13.58.099 18.057a.082.082 0 0 0 .031.057 19.9 19.9 0 0 0 5.993 3.03.078.078 0 0 0 .084-.028c.462-.63.874-1.295 1.226-1.994a.076.076 0 0 0-.041-.106 13.107 13.107 0 0 1-1.872-.892.077.077 0 0 1-.008-.128 10.2 10.2 0 0 0 .372-.292.074.074 0 0 1 .077-.01c3.928 1.793 8.18 1.793 12.062 0a.074.074 0 0 1 .078.01c.12.098.246.198.373.292a.077.077 0 0 1-.006.127 12.299 12.299 0 0 1-1.873.892.077.077 0 0 0-.041.107c.36.698.772 1.362 1.225 1.993a.076.076 0 0 0 .084.028 19.839 19.839 0 0 0 6.002-3.03.077.077 0 0 0 .032-.054c.5-5.177-.838-9.674-3.549-13.66a.061.061 0 0 0-.031-.03zM8.02 15.33c-1.183 0-2.157-1.085-2.157-2.419 0-1.333.956-2.419 2.157-2.419 1.21 0 2.176 1.095 2.157 2.42 0 1.333-.956 2.418-2.157 2.418zm7.975 0c-1.183 0-2.157-1.085-2.157-2.419 0-1.333.955-2.419 2.157-2.419 1.21 0 2.176 1.095 2.157 2.42 0 1.333-.946 2.418-2.157 2.418z"})})}function SM({updateAvailable:e,releaseInfo:t,latestVersion:n,currentVersion:r,onShowVersionModal:a,onOpenControlRoom:s,onShowSettings:o,t:l}){return i.jsxs("div",{className:"flex-shrink-0",style:{paddingBottom:"env(safe-area-inset-bottom, 0)"},children:[e&&i.jsxs(i.Fragment,{children:[i.jsx("div",{className:"nav-divider"}),i.jsx("div",{className:"hidden px-2 py-1.5 md:block",children:i.jsxs("button",{className:"group flex w-full items-center gap-2.5 rounded-lg px-2.5 py-2 text-left transition-colors hover:bg-blue-50/80 dark:hover:bg-blue-900/15",onClick:a,children:[i.jsxs("div",{className:"relative flex-shrink-0",children:[i.jsx(Tw,{className:"h-4 w-4 text-blue-500 dark:text-blue-400"}),i.jsx("span",{className:"absolute -right-0.5 -top-0.5 h-1.5 w-1.5 animate-pulse rounded-full bg-blue-500"})]}),i.jsxs("div",{className:"min-w-0 flex-1",children:[i.jsx("span",{className:"block truncate text-sm font-medium text-blue-600 dark:text-blue-300",children:t?.title||`v${n}`}),i.jsx("span",{className:"text-[10px] text-blue-500/70 dark:text-blue-400/60",children:l("version.updateAvailable")})]})]})}),i.jsx("div",{className:"px-3 py-2 md:hidden",children:i.jsxs("button",{className:"flex h-11 w-full items-center gap-3 rounded-xl border border-blue-200/60 bg-blue-50/80 px-3.5 transition-all active:scale-[0.98] dark:border-blue-700/40 dark:bg-blue-900/15",onClick:a,children:[i.jsxs("div",{className:"relative flex-shrink-0",children:[i.jsx(Tw,{className:"w-4.5 h-4.5 text-blue-500 dark:text-blue-400"}),i.jsx("span",{className:"absolute -right-0.5 -top-0.5 h-1.5 w-1.5 animate-pulse rounded-full bg-blue-500"})]}),i.jsxs("div",{className:"min-w-0 flex-1 text-left",children:[i.jsx("span",{className:"block truncate text-sm font-medium text-blue-600 dark:text-blue-300",children:t?.title||`v${n}`}),i.jsx("span",{className:"text-xs text-blue-500/70 dark:text-blue-400/60",children:l("version.updateAvailable")})]})]})})]}),i.jsx("div",{className:"nav-divider"}),i.jsx("div",{className:"hidden px-2 pt-1.5 md:block",children:i.jsxs("a",{href:Kw,target:"_blank",rel:"noopener noreferrer",className:"flex w-full items-center gap-2 rounded-lg px-2.5 py-1.5 text-muted-foreground transition-colors hover:bg-accent/60 hover:text-foreground",children:[i.jsx(Sl,{className:"h-3.5 w-3.5"}),i.jsx("span",{className:"text-sm",children:l("actions.reportIssue")})]})}),i.jsx("div",{className:"hidden px-2 md:block",children:i.jsxs("a",{href:Zw,target:"_blank",rel:"noopener noreferrer",className:"flex w-full items-center gap-2 rounded-lg px-2.5 py-1.5 text-muted-foreground transition-colors hover:bg-accent/60 hover:text-foreground",children:[i.jsx(Xw,{className:"h-3.5 w-3.5"}),i.jsx("span",{className:"text-sm",children:l("actions.joinCommunity")})]})}),s&&i.jsx("div",{className:"hidden px-2 pt-1.5 md:block",children:i.jsxs("button",{className:"group flex w-full items-center gap-2.5 rounded-lg border border-primary/25 bg-primary/5 px-2.5 py-2 text-left transition-colors hover:bg-primary/10",onClick:s,children:[i.jsx("div",{className:"flex h-7 w-7 items-center justify-center rounded-md bg-primary/10 text-primary",children:i.jsx(Vn,{className:"h-3.5 w-3.5"})}),i.jsxs("div",{className:"min-w-0 flex-1",children:[i.jsx("span",{className:"block truncate text-sm font-semibold text-foreground",children:l("actions.controlRoom",{defaultValue:"Control Room"})}),i.jsx("span",{className:"block truncate text-[10px] text-muted-foreground",children:l("actions.controlRoomDescription",{defaultValue:"Admin, access, runs"})})]})]})}),i.jsx("div",{className:"hidden px-2 py-1.5 md:block",children:i.jsxs("button",{className:"flex w-full items-center gap-2 rounded-lg px-2.5 py-1.5 text-muted-foreground transition-colors hover:bg-accent/60 hover:text-foreground",onClick:o,children:[i.jsx(Pt,{className:"h-3.5 w-3.5"}),i.jsx("span",{className:"text-sm",children:l("actions.settings")})]})}),i.jsx("div",{className:"hidden px-3 py-2 text-center md:block",children:i.jsxs("a",{href:Yw,target:"_blank",rel:"noopener noreferrer",className:"text-[10px] text-muted-foreground/40 transition-colors hover:text-muted-foreground",children:["Pixcode v",r," – ",l("branding.openSource")]})}),i.jsxs("div",{className:"px-3 py-2 md:hidden",children:[i.jsxs("div",{className:`grid gap-1.5 ${s?"grid-cols-4":"grid-cols-3"}`,children:[i.jsxs("a",{href:Kw,target:"_blank",rel:"noopener noreferrer",className:"flex min-h-14 flex-col items-center justify-center gap-1 rounded-xl bg-muted/35 px-1 text-center text-[11px] font-medium text-foreground transition-colors active:bg-muted",children:[i.jsx(Sl,{className:"h-4 w-4 text-muted-foreground"}),i.jsx("span",{className:"line-clamp-2 leading-tight",children:l("actions.reportIssue")})]}),i.jsxs("a",{href:Zw,target:"_blank",rel:"noopener noreferrer",className:"flex min-h-14 flex-col items-center justify-center gap-1 rounded-xl bg-muted/35 px-1 text-center text-[11px] font-medium text-foreground transition-colors active:bg-muted",children:[i.jsx(Xw,{className:"h-4 w-4 text-muted-foreground"}),i.jsx("span",{className:"line-clamp-2 leading-tight",children:l("actions.joinCommunity")})]}),s&&i.jsxs("button",{type:"button",className:"flex min-h-14 flex-col items-center justify-center gap-1 rounded-xl border border-primary/20 bg-primary/10 px-1 text-center text-[11px] font-semibold text-primary transition-colors active:bg-primary/15",onClick:s,children:[i.jsx(Vn,{className:"h-4 w-4"}),i.jsx("span",{className:"line-clamp-2 leading-tight",children:l("actions.controlRoom",{defaultValue:"Control Room"})})]}),i.jsxs("button",{type:"button",className:"flex min-h-14 flex-col items-center justify-center gap-1 rounded-xl bg-muted/35 px-1 text-center text-[11px] font-medium text-foreground transition-colors active:bg-muted",onClick:o,children:[i.jsx(Pt,{className:"h-4 w-4 text-muted-foreground"}),i.jsx("span",{className:"line-clamp-2 leading-tight",children:l("actions.settings")})]})]}),i.jsxs("a",{href:Yw,target:"_blank",rel:"noopener noreferrer",className:"mt-1.5 block truncate text-center text-[10px] text-muted-foreground/45",children:["Pixcode v",r," · ",l("branding.openSource")]})]})]})}const Qw="PIXCODE_GITHUB_STARS",Jw="PIXCODE_HIDE_GITHUB_STAR",CM=3600*1e3,EM=(e,t)=>{const[n,r]=m.useState(null),[a,s]=m.useState(()=>{try{return localStorage.getItem(Jw)==="true"}catch{return!1}});m.useEffect(()=>{if(a)return;try{const d=localStorage.getItem(Qw);if(d){const u=JSON.parse(d);if(Date.now()-u.timestamp<CM){r(u.count);return}}}catch{}(async()=>{try{const d=await fetch(`https://api.github.com/repos/${e}/${t}`);if(!d.ok)return;const p=(await d.json()).stargazers_count;if(typeof p=="number"){r(p);try{localStorage.setItem(Qw,JSON.stringify({count:p,timestamp:Date.now()}))}catch{}}}catch{}})()},[e,t,a]);const o=m.useCallback(()=>{s(!0);try{localStorage.setItem(Jw,"true")}catch{}},[]),l=n!==null?n>=1e3?`${(n/1e3).toFixed(1)}k`:`${n}`:null;return{starCount:n,formattedCount:l,isDismissed:a,dismiss:o}},NM="https://github.com/alicomert/pixcode";function TM({className:e}){return i.jsx("svg",{className:e,fill:"currentColor",viewBox:"0 0 24 24","aria-hidden":"true",children:i.jsx("path",{d:"M12 2C6.477 2 2 6.484 2 12.017c0 4.425 2.865 8.18 6.839 9.504.5.092.682-.217.682-.483 0-.237-.008-.868-.013-1.703-2.782.605-3.369-1.343-3.369-1.343-.454-1.158-1.11-1.466-1.11-1.466-.908-.62.069-.608.069-.608 1.003.07 1.531 1.032 1.531 1.032.892 1.53 2.341 1.088 2.91.832.092-.647.35-1.088.636-1.338-2.22-.253-4.555-1.113-4.555-4.951 0-1.093.39-1.988 1.029-2.688-.103-.253-.446-1.272.098-2.65 0 0 .84-.27 2.75 1.026A9.564 9.564 0 0112 6.844c.85.004 1.705.115 2.504.337 1.909-1.296 2.747-1.027 2.747-1.027.546 1.379.202 2.398.1 2.651.64.7 1.028 1.595 1.028 2.688 0 3.848-2.339 4.695-4.566 4.943.359.309.678.92.678 1.855 0 1.338-.012 2.419-.012 2.747 0 .268.18.58.688.482A10.019 10.019 0 0022 12.017C22 6.484 17.522 2 12 2z"})})}function AM(){const{formattedCount:e,isDismissed:t,dismiss:n}=EM("alicomert","pixcode");return t?null:i.jsxs("div",{className:"group/star relative hidden md:block",children:[i.jsxs("a",{href:NM,target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-1.5 rounded-lg border border-border/50 bg-muted/30 px-2.5 py-1 text-xs text-muted-foreground transition-colors hover:bg-muted/50 hover:text-foreground",children:[i.jsx(TM,{className:"h-3.5 w-3.5"}),i.jsx(Ea,{className:"h-3 w-3"}),i.jsx("span",{className:"font-medium",children:"Star"}),e&&i.jsx("span",{className:"border-l border-border/50 pl-1.5 tabular-nums",children:e})]}),i.jsx("button",{onClick:r=>{r.preventDefault(),r.stopPropagation(),n()},className:"absolute -right-1.5 -top-1.5 hidden h-4 w-4 items-center justify-center rounded-full border border-border/50 bg-muted text-muted-foreground transition-colors hover:text-foreground group-hover/star:flex","aria-label":"Dismiss",children:i.jsx(ht,{className:"h-2.5 w-2.5"})})]})}function ek({value:e,onChange:t,t:n}){const r="flex flex-1 items-center justify-center gap-1 rounded-md px-2 py-1 text-[11px] font-medium transition-all";return i.jsxs("div",{role:"tablist","aria-label":n("tooltips.historyView",{defaultValue:"History view"}),className:"flex rounded-lg bg-muted/40 p-0.5",children:[i.jsxs("button",{type:"button",role:"tab","aria-selected":e==="flat",onClick:()=>t("flat"),className:me(r,e==="flat"?"bg-background text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"),title:n("tooltips.historyViewFlat",{defaultValue:"Recent conversations"}),children:[i.jsx(nE,{className:"h-3 w-3"}),n("historyView.flat",{defaultValue:"Recent"})]}),i.jsxs("button",{type:"button",role:"tab","aria-selected":e==="grouped",onClick:()=>t("grouped"),className:me(r,e==="grouped"?"bg-background text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"),title:n("tooltips.historyViewGrouped",{defaultValue:"Grouped by project"}),children:[i.jsx(DD,{className:"h-3 w-3"}),n("historyView.grouped",{defaultValue:"By project"})]})]})}function jM({isPWA:e,isMobile:t,isLoading:n,projectsCount:r,searchFilter:a,onSearchFilterChange:s,onClearSearchFilter:o,searchMode:l,onSearchModeChange:c,onRefresh:d,isRefreshing:u,onCreateProject:p,onQuickStartSession:f,onCollapseSidebar:h,historyView:g,onHistoryViewChange:b,t:x}){const v=()=>i.jsxs("div",{className:"flex min-w-0 items-center gap-2.5",children:[i.jsx("svg",{className:"h-6 w-6 flex-shrink-0",viewBox:"0 0 500 500","aria-hidden":"true",children:i.jsx("g",{transform:"translate(250 250) scale(1.25) translate(-250 -250)",children:i.jsxs("g",{transform:"translate(0 500) scale(0.1 -0.1)",fill:"#5C3FFC",children:[i.jsx("path",{d:"M2037 3800 c-104 -40 -191 -134 -231 -250 -23 -67 -20 -82 22 -109 31 -20 287 -177 1009 -618 40 -24 82 -56 93 -70 27 -34 27 -102 0 -136 -11 -13 -106 -78 -212 -143 -106 -64 -201 -124 -210 -132 -16 -14 -18 -41 -18 -302 0 -291 2 -310 38 -310 16 0 267 148 610 359 180 111 270 173 310 213 216 217 215 574 -3 793 -37 38 -107 89 -185 136 -69 42 -253 154 -410 249 -434 264 -509 307 -563 326 -57 20 -191 17 -250 -6z"}),i.jsx("path",{d:"M1803 2994 c-10 -5 -13 -156 -13 -709 0 -671 1 -706 20 -767 27 -89 93 -184 167 -240 89 -67 157 -90 281 -96 92 -4 105 -2 117 14 12 16 14 134 15 735 0 669 -1 718 -17 737 -20 23 -514 322 -541 327 -9 2 -23 2 -29 -1z"})]})})}),i.jsx("h1",{className:"truncate text-sm font-semibold tracking-tight text-foreground",children:x("app.title")})]});return i.jsxs("div",{className:"flex-shrink-0",children:[i.jsxs("div",{className:"hidden px-4 pb-3 pt-4 md:block",style:{},children:[i.jsxs("div",{className:"flex items-center justify-between gap-2",children:[i.jsx(v,{}),i.jsxs("div",{className:"flex flex-shrink-0 items-center gap-0.5",children:[i.jsx(Ae,{variant:"ghost",size:"sm",className:"h-8 w-8 rounded-lg p-0 text-muted-foreground hover:bg-accent/80 hover:text-foreground",onClick:d,disabled:u,title:x("tooltips.refresh"),children:i.jsx(nt,{className:`h-4 w-4 ${u?"animate-spin":""}`})}),i.jsx(Ae,{variant:"ghost",size:"sm",className:"h-8 w-8 rounded-lg p-0 text-muted-foreground hover:bg-accent/80 hover:text-foreground",onClick:p,title:x("tooltips.createProject"),children:i.jsx(Gt,{className:"h-4 w-4"})}),i.jsx(Ae,{variant:"ghost",size:"sm",className:"h-8 w-8 rounded-lg p-0 text-muted-foreground hover:bg-accent/80 hover:text-foreground",onClick:h,title:x("tooltips.hideSidebar"),children:i.jsx(mu,{className:"h-4 w-4"})})]})]}),i.jsx(AM,{}),f&&i.jsxs("button",{type:"button",onClick:()=>{f()},className:"mt-2.5 flex w-full items-center justify-center gap-2 rounded-lg border border-primary/20 bg-primary/5 px-3 py-2 text-sm font-medium text-primary transition-colors hover:bg-primary/10",children:[i.jsx(Vn,{className:"h-4 w-4"}),x("sidebar.newChat",{defaultValue:"New chat"})]}),r>0&&!n&&i.jsxs("div",{className:"mt-2.5 space-y-2",children:[i.jsx(ek,{value:g,onChange:b,t:x}),i.jsxs("div",{className:"flex rounded-lg bg-muted/50 p-0.5",children:[i.jsxs("button",{onClick:()=>c("projects"),"aria-pressed":l==="projects",className:me("flex-1 flex items-center justify-center gap-1.5 rounded-md px-2 py-1.5 text-xs font-medium transition-all",l==="projects"?"bg-background shadow-sm text-foreground":"text-muted-foreground hover:text-foreground"),children:[i.jsx(On,{className:"h-3 w-3"}),x("search.modeProjects")]}),i.jsxs("button",{onClick:()=>c("conversations"),"aria-pressed":l==="conversations",className:me("flex-1 flex items-center justify-center gap-1.5 rounded-md px-2 py-1.5 text-xs font-medium transition-all",l==="conversations"?"bg-background shadow-sm text-foreground":"text-muted-foreground hover:text-foreground"),children:[i.jsx(Wr,{className:"h-3 w-3"}),x("search.modeConversations")]})]}),i.jsxs("div",{className:"relative",children:[i.jsx(ja,{className:"pointer-events-none absolute left-3 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-muted-foreground/50"}),i.jsx(Ze,{type:"text",placeholder:x(l==="conversations"?"search.conversationsPlaceholder":"projects.searchPlaceholder"),value:a,onChange:y=>s(y.target.value),className:"nav-search-input h-9 rounded-xl border-0 pl-9 pr-8 text-sm transition-all duration-200 placeholder:text-muted-foreground/40 focus-visible:ring-0 focus-visible:ring-offset-0"}),a&&i.jsx("button",{onClick:o,"aria-label":x("tooltips.clearSearch"),className:"absolute right-2.5 top-1/2 -translate-y-1/2 rounded-md p-0.5 hover:bg-accent",children:i.jsx(ht,{className:"h-3 w-3 text-muted-foreground"})})]})]})]}),i.jsx("div",{className:"nav-divider hidden md:block"}),i.jsxs("div",{className:"p-3 pb-2 md:hidden",style:e&&t?{paddingTop:"16px"}:{},children:[i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsx(v,{}),i.jsxs("div",{className:"flex flex-shrink-0 gap-1.5",children:[i.jsx("button",{className:"flex h-8 w-8 items-center justify-center rounded-lg bg-muted/50 transition-all active:scale-95",onClick:d,disabled:u,children:i.jsx(nt,{className:`h-4 w-4 text-muted-foreground ${u?"animate-spin":""}`})}),i.jsx("button",{className:"flex h-8 w-8 items-center justify-center rounded-lg bg-primary/90 text-primary-foreground transition-all active:scale-95",onClick:p,children:i.jsx(ci,{className:"h-4 w-4"})})]})]}),f&&i.jsxs("button",{type:"button",onClick:()=>{f()},className:"mt-2 flex h-9 w-full items-center justify-center gap-2 rounded-xl border border-primary/20 bg-primary/5 px-3 text-sm font-medium text-primary transition-colors active:bg-primary/10",children:[i.jsx(Vn,{className:"h-4 w-4"}),x("sidebar.newChat",{defaultValue:"New chat"})]}),r>0&&!n&&i.jsxs("div",{className:"mt-2.5 space-y-2",children:[i.jsx(ek,{value:g,onChange:b,t:x}),i.jsxs("div",{className:"flex rounded-lg bg-muted/50 p-0.5",children:[i.jsxs("button",{onClick:()=>c("projects"),"aria-pressed":l==="projects",className:me("flex-1 flex items-center justify-center gap-1.5 rounded-md px-2 py-1.5 text-xs font-medium transition-all",l==="projects"?"bg-background shadow-sm text-foreground":"text-muted-foreground hover:text-foreground"),children:[i.jsx(On,{className:"h-3 w-3"}),x("search.modeProjects")]}),i.jsxs("button",{onClick:()=>c("conversations"),"aria-pressed":l==="conversations",className:me("flex-1 flex items-center justify-center gap-1.5 rounded-md px-2 py-1.5 text-xs font-medium transition-all",l==="conversations"?"bg-background shadow-sm text-foreground":"text-muted-foreground hover:text-foreground"),children:[i.jsx(Wr,{className:"h-3 w-3"}),x("search.modeConversations")]})]}),i.jsxs("div",{className:"relative",children:[i.jsx(ja,{className:"pointer-events-none absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground/50"}),i.jsx(Ze,{type:"text",placeholder:x(l==="conversations"?"search.conversationsPlaceholder":"projects.searchPlaceholder"),value:a,onChange:y=>s(y.target.value),className:"nav-search-input h-10 rounded-xl border-0 pl-10 pr-9 text-sm transition-all duration-200 placeholder:text-muted-foreground/40 focus-visible:ring-0 focus-visible:ring-offset-0"}),a&&i.jsx("button",{onClick:o,"aria-label":x("tooltips.clearSearch"),className:"absolute right-2.5 top-1/2 -translate-y-1/2 rounded-md p-1 hover:bg-accent",children:i.jsx(ht,{className:"h-3.5 w-3.5 text-muted-foreground"})})]})]})]}),i.jsx("div",{className:"nav-divider md:hidden"})]})}const RM=160,tk=180;function sN({actions:e,className:t,triggerLabel:n}){const[r,a]=m.useState(!1),[s,o]=m.useState(null),l=m.useRef(null),c=m.useRef(null);m.useLayoutEffect(()=>{if(!r||!l.current)return;const u=l.current.getBoundingClientRect();let p=u.right-RM;p<8&&(p=8);let f=u.bottom+4;f+tk>window.innerHeight&&(f=Math.max(8,u.top-4-tk)),o({top:f,left:p})},[r]),m.useEffect(()=>{if(!r)return;const u=h=>{const g=h.target;l.current?.contains(g)||c.current?.contains(g)||a(!1)},p=h=>{h.key==="Escape"&&a(!1)},f=()=>a(!1);return document.addEventListener("mousedown",u),document.addEventListener("keydown",p),window.addEventListener("scroll",f,!0),window.addEventListener("resize",f),()=>{document.removeEventListener("mousedown",u),document.removeEventListener("keydown",p),window.removeEventListener("scroll",f,!0),window.removeEventListener("resize",f)}},[r]);const d=u=>p=>{p.stopPropagation(),p.preventDefault(),a(!1),u.onClick()};return i.jsxs(i.Fragment,{children:[i.jsx("button",{ref:l,type:"button","aria-haspopup":"menu","aria-expanded":r,"aria-label":n||"Actions",title:n||"Actions",onClick:u=>{u.stopPropagation(),u.preventDefault(),a(p=>!p)},className:me("flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground","opacity-0 transition-all duration-150 hover:bg-accent hover:text-foreground","group-hover:opacity-100 focus-visible:opacity-100 focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-primary","touch:opacity-100",r&&"bg-accent text-foreground opacity-100",t),children:i.jsx(aE,{className:"h-3.5 w-3.5"})}),r&&s&&du.createPortal(i.jsx("div",{ref:c,role:"menu",style:{position:"fixed",top:s.top,left:s.left,zIndex:9999},className:me("w-40 rounded-xl border border-border/60 bg-popover p-1 shadow-lg","animate-in fade-in-0 zoom-in-95 duration-100"),onClick:u=>u.stopPropagation(),onMouseDown:u=>u.stopPropagation(),children:e.map((u,p)=>{const f=u.icon,h=e[p-1],g=p>0&&u.danger&&!h?.danger;return i.jsxs("div",{children:[g&&i.jsx("div",{className:"my-1 h-px bg-border/60"}),i.jsxs("button",{type:"button",role:"menuitem",onClick:d(u),className:me("flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left text-xs",u.danger?"text-red-600 hover:bg-red-50 dark:text-red-400 dark:hover:bg-red-900/20":"text-foreground hover:bg-accent"),children:[i.jsx(f,{className:"h-3 w-3"}),u.label]})]},u.id)})}),document.body)]})}const _M=(e,t,n)=>{const r=new Date(e),a=t;if(isNaN(r.getTime()))return n?n("status.unknown"):"Unknown";const s=a.getTime()-r.getTime(),o=Math.floor(s/1e3),l=Math.floor(s/(1e3*60)),c=Math.floor(s/(1e3*60*60)),d=Math.floor(s/(1e3*60*60*24));return o<60?n?n("time.justNow"):"Just now":l===1?n?n("time.oneMinuteAgo"):"1 min ago":l<60?n?n("time.minutesAgo",{count:l}):`${l} mins ago`:c===1?n?n("time.oneHourAgo"):"1 hour ago":c<24?n?n("time.hoursAgo",{count:c}):`${c} hours ago`:d===1?n?n("time.oneDayAgo"):"1 day ago":d<7?n?n("time.daysAgo",{count:d}):`${d} days ago`:r.toLocaleDateString()};function nk({isStarred:e,canDelete:t,onRename:n,onToggleStar:r,onDelete:a,t:s,className:o}){const l=d=>i.jsx(Ea,{className:`${d.className??""} ${e?"fill-yellow-400 text-yellow-500":""}`}),c=[{id:"rename",label:s("actions.rename"),icon:rE,onClick:n},{id:"star",label:e?s("actions.unstarSession",{defaultValue:"Remove star"}):s("actions.starSession",{defaultValue:"Star"}),icon:l,onClick:r}];return t&&c.push({id:"delete",label:s("actions.delete"),icon:En,onClick:a,danger:!0}),i.jsx(sN,{actions:c,className:o,triggerLabel:s("tooltips.sessionActions",{defaultValue:"Session actions"})})}const IM={claude:"Claude",cursor:"Cursor",codex:"Codex",gemini:"Gemini",qwen:"Qwen Code",opencode:"OpenCode"},rk={claude:"bg-orange-500/10 text-orange-600 dark:bg-orange-400/10 dark:text-orange-300 ring-1 ring-orange-500/15",cursor:"bg-sky-500/10 text-sky-600 dark:bg-sky-400/10 dark:text-sky-300 ring-1 ring-sky-500/15",codex:"bg-violet-500/10 text-violet-600 dark:bg-violet-400/10 dark:text-violet-300 ring-1 ring-violet-500/15",gemini:"bg-emerald-500/10 text-emerald-600 dark:bg-emerald-400/10 dark:text-emerald-300 ring-1 ring-emerald-500/15",qwen:"bg-amber-500/10 text-amber-600 dark:bg-amber-400/10 dark:text-amber-300 ring-1 ring-amber-500/15",opencode:"bg-teal-500/10 text-teal-600 dark:bg-teal-400/10 dark:text-teal-300 ring-1 ring-teal-500/15"};function oN({project:e,session:t,selectedSession:n,currentTime:r,editingSession:a,editingSessionName:s,isStarred:o,compact:l=!1,onEditingSessionNameChange:c,onStartEditingSession:d,onCancelEditingSession:u,onSaveEditingSession:p,onToggleStarSession:f,onProjectSelect:h,onSessionSelect:g,onDeleteSession:b,t:x}){const v=eM(t,r,x),y=n?.id===t.id,w=a===t.id,k=t.__provider,S=IM[k]??k,C=rk[k]??rk.claude,N=XO(v.sessionName),R=()=>{h(e),g(t,e.name)},A=()=>{p(e.name,t.id,s,k)},j=()=>{b(e.name,t.id,v.sessionName,k)},L=()=>d(t.id,v.sessionName),T=()=>f(e.name,t.id),_=i.jsxs("div",{className:"mt-0.5 flex min-w-0 flex-wrap items-center gap-1 text-[10px] leading-tight",children:[i.jsxs("span",{className:me("inline-flex items-center gap-1 rounded-full px-1.5 py-px font-medium",C),children:[i.jsx(yn,{provider:k,className:"h-2.5 w-2.5"}),S]}),i.jsx("span",{className:"text-muted-foreground/80",children:_M(v.sessionTime,r,x)}),v.isActive&&i.jsxs("span",{className:"inline-flex items-center gap-1 text-green-600 dark:text-green-400",children:[i.jsx("span",{className:"h-1.5 w-1.5 animate-pulse rounded-full bg-green-500"}),x("status.active",{defaultValue:"Active"})]}),N.slice(0,3).map(B=>i.jsxs("span",{className:"rounded-md bg-muted/60 px-1 py-px font-mono text-[9px] uppercase tracking-wide text-muted-foreground ring-1 ring-border/40",children:[".",B]},B))]}),E=i.jsxs(i.Fragment,{children:[i.jsx("input",{type:"text",value:s,onChange:B=>c(B.target.value),onKeyDown:B=>{B.stopPropagation(),B.key==="Enter"?A():B.key==="Escape"&&u()},onClick:B=>B.stopPropagation(),className:"w-full rounded-md border border-primary/40 bg-background px-2 py-1 text-xs focus:outline-none focus:ring-1 focus:ring-primary",autoFocus:!0}),i.jsx("button",{className:"flex h-6 w-6 items-center justify-center rounded-md bg-green-50 hover:bg-green-100 dark:bg-green-900/20 dark:hover:bg-green-900/40",onClick:B=>{B.stopPropagation(),A()},title:x("tooltips.save"),children:i.jsx(Ht,{className:"h-3 w-3 text-green-600 dark:text-green-400"})}),i.jsx("button",{className:"flex h-6 w-6 items-center justify-center rounded-md bg-gray-50 hover:bg-gray-100 dark:bg-gray-900/20 dark:hover:bg-gray-900/40",onClick:B=>{B.stopPropagation(),u()},title:x("tooltips.cancel"),children:i.jsx(ht,{className:"h-3 w-3 text-gray-600 dark:text-gray-400"})})]}),O=i.jsx("div",{className:"md:hidden",children:i.jsx("div",{className:me("relative mx-3 my-0.5 rounded-lg border border-border/30 bg-card p-2 transition-all duration-150 active:scale-[0.98]",y&&"border-primary/30 bg-primary/5 shadow-sm",!y&&v.isActive&&"border-green-500/25 bg-green-50/5 dark:bg-green-900/5",o&&!y&&"ring-1 ring-yellow-300/50 dark:ring-yellow-500/30"),onClick:w?void 0:R,children:w?i.jsx("div",{className:"flex items-center gap-1",children:E}):i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("div",{className:me("flex h-6 w-6 flex-shrink-0 items-center justify-center rounded-md",y?"bg-primary/10":"bg-muted/60"),children:i.jsx(yn,{provider:k,className:"h-3 w-3"})}),i.jsxs("div",{className:"min-w-0 flex-1",children:[i.jsxs("div",{className:"flex items-center gap-1",children:[o&&i.jsx("span",{className:"text-yellow-500","aria-hidden":!0,children:"★"}),i.jsx("span",{className:"truncate text-xs font-medium text-foreground",children:v.sessionName})]}),_]}),i.jsx("div",{className:"flex-shrink-0",onClick:B=>B.stopPropagation(),children:i.jsx(nk,{isStarred:o,canDelete:!v.isCursorSession,onRename:L,onToggleStar:T,onDelete:j,t:x,className:"!opacity-100"})})]})})}),$=i.jsxs("div",{className:me("group/item relative hidden md:block"),children:[i.jsxs(Ae,{variant:"ghost",className:me("relative h-auto w-full justify-start overflow-hidden p-0 text-left font-normal transition-colors duration-150","hover:bg-accent/60",y&&"bg-accent text-accent-foreground",o&&!y&&"bg-yellow-50/40 hover:bg-yellow-100/40 dark:bg-yellow-900/10 dark:hover:bg-yellow-900/20",l?"rounded-xl px-3 py-2.5":"rounded-lg px-3 py-2"),onClick:w?void 0:()=>g(t,e.name),children:[y&&i.jsx("span",{"aria-hidden":!0,className:"absolute left-0 top-1/2 h-5 w-0.5 -translate-y-1/2 rounded-r bg-primary"}),!y&&!w&&i.jsx("span",{"aria-hidden":!0,className:"session-item-accent"}),i.jsxs("div",{className:"flex w-full min-w-0 items-start gap-2 pr-6",children:[i.jsx("div",{className:me("mt-0.5 flex h-5 w-5 flex-shrink-0 items-center justify-center rounded-md",y?"bg-primary/10":"bg-muted/50 group-hover/item:bg-muted/80"),children:i.jsx(yn,{provider:k,className:"h-3 w-3"})}),i.jsx("div",{className:"min-w-0 flex-1",children:w?i.jsx("div",{className:"flex items-center gap-1",children:E}):i.jsxs(i.Fragment,{children:[i.jsxs("div",{className:"flex min-w-0 items-center gap-1",children:[o&&i.jsx("span",{className:"flex-shrink-0 text-yellow-500","aria-hidden":!0,children:"★"}),i.jsx("span",{className:"truncate text-xs font-medium text-foreground",children:v.sessionName})]}),_]})})]})]}),!w&&i.jsx("div",{className:"absolute right-1.5 top-1/2 -translate-y-1/2",onClick:B=>B.stopPropagation(),children:i.jsx(nk,{isStarred:o,canDelete:!v.isCursorSession,onRename:L,onToggleStar:T,onDelete:j,t:x,className:"opacity-0 focus-visible:opacity-100 group-hover/item:opacity-100"})})]});return i.jsxs("div",{className:"group relative",children:[O,$]})}function LM(){return i.jsx(i.Fragment,{children:Array.from({length:3}).map((e,t)=>i.jsx("div",{className:"rounded-md p-2",children:i.jsxs("div",{className:"flex items-start gap-2",children:[i.jsx("div",{className:"mt-0.5 h-3 w-3 animate-pulse rounded-full bg-muted"}),i.jsxs("div",{className:"flex-1 space-y-1",children:[i.jsx("div",{className:"h-3 animate-pulse rounded bg-muted",style:{width:`${60+t*15}%`}}),i.jsx("div",{className:"h-2 w-1/2 animate-pulse rounded bg-muted"})]})]})},t))})}function PM({project:e,isExpanded:t,sessions:n,selectedSession:r,initialSessionsLoaded:a,isLoadingSessions:s,currentTime:o,editingSession:l,editingSessionName:c,isSessionStarred:d,onEditingSessionNameChange:u,onStartEditingSession:p,onCancelEditingSession:f,onSaveEditingSession:h,onToggleStarSession:g,onProjectSelect:b,onSessionSelect:x,onDeleteSession:v,onLoadMoreSessions:y,onNewSession:w,t:k}){if(!t)return null;const S=n.length>0,C=e.sessionMeta?.hasMore===!0;return i.jsxs("div",{className:"ml-3 space-y-1 border-l border-border pl-3",children:[i.jsx("div",{className:"px-3 pb-1 pt-1 md:hidden",children:i.jsxs("button",{className:"flex h-8 w-full items-center justify-center gap-2 rounded-md bg-primary text-xs font-medium text-primary-foreground transition-all duration-150 hover:bg-primary/90 active:scale-[0.98]",onClick:()=>{b(e),w(e)},children:[i.jsx(Gt,{className:"h-3 w-3"}),k("sessions.newSession")]})}),i.jsxs(Ae,{variant:"default",size:"sm",className:"hidden h-8 w-full justify-start gap-2 bg-primary text-xs font-medium text-primary-foreground transition-colors hover:bg-primary/90 md:flex",onClick:()=>w(e),children:[i.jsx(Gt,{className:"h-3 w-3"}),k("sessions.newSession")]}),a?!S&&!s?i.jsx("div",{className:"px-3 py-2 text-left",children:i.jsx("p",{className:"text-xs text-muted-foreground",children:k("sessions.noSessions")})}):n.map(N=>i.jsx(oN,{project:e,session:N,selectedSession:r,currentTime:o,editingSession:l,editingSessionName:c,isStarred:d(e.name,N.id),onEditingSessionNameChange:u,onStartEditingSession:p,onCancelEditingSession:f,onSaveEditingSession:h,onToggleStarSession:g,onProjectSelect:b,onSessionSelect:x,onDeleteSession:v,t:k},N.id)):i.jsx(LM,{}),S&&C&&i.jsx(Ae,{variant:"ghost",size:"sm",className:"mt-2 w-full justify-center gap-2 text-muted-foreground",onClick:()=>y(e),disabled:s,children:s?i.jsxs(i.Fragment,{children:[i.jsx("div",{className:"h-3 w-3 animate-spin rounded-full border border-muted-foreground border-t-transparent"}),k("sessions.loading")]}):i.jsxs(i.Fragment,{children:[i.jsx(Dr,{className:"h-3 w-3"}),k("sessions.showMore")]})})]})}const DM=(e,t)=>{const n=e.length;return t&&n>=5?`${n}+`:`${n}`};function OM({project:e,selectedProject:t,selectedSession:n,isExpanded:r,isDeleting:a,isStarred:s,editingProject:o,editingName:l,sessions:c,initialSessionsLoaded:d,isLoadingSessions:u,currentTime:p,editingSession:f,editingSessionName:h,isSessionStarred:g,onEditingNameChange:b,onToggleProject:x,onProjectSelect:v,onToggleStarProject:y,onToggleStarSession:w,onStartEditingProject:k,onCancelEditingProject:S,onSaveProjectName:C,onDeleteProject:N,onSessionSelect:R,onDeleteSession:A,onLoadMoreSessions:j,onNewSession:L,onEditingSessionNameChange:T,onStartEditingSession:_,onCancelEditingSession:E,onSaveEditingSession:O,t:$}){const B=t?.name===e.name,K=o===e.name,Y=e.sessionMeta?.hasMore===!0,P=DM(c,Y),z=`${P} session${c.length===1?"":"s"}`,U=()=>x(e.name),F=()=>y(e.name),J=()=>{C(e.name)},ae=()=>{t?.name!==e.name&&v(e),U()};return i.jsxs("div",{className:me("md:space-y-1",a&&"opacity-50 pointer-events-none"),children:[i.jsxs("div",{className:"md:group group",children:[i.jsx("div",{className:"md:hidden",children:i.jsx("div",{className:me("p-3 mx-3 my-1 rounded-lg bg-card border border-border/50 active:scale-[0.98] transition-all duration-150",B&&"bg-primary/5 border-primary/20",s&&!B&&"bg-yellow-50/50 dark:bg-yellow-900/5 border-yellow-200/30 dark:border-yellow-800/30"),onClick:U,children:i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-3",children:[i.jsx("div",{className:me("w-8 h-8 rounded-lg flex items-center justify-center transition-colors",r?"bg-primary/10":"bg-muted"),children:r?i.jsx(Sr,{className:"h-4 w-4 text-primary"}):i.jsx(On,{className:"h-4 w-4 text-muted-foreground"})}),i.jsx("div",{className:"min-w-0 flex-1",children:K?i.jsx("input",{type:"text",value:l,onChange:Q=>b(Q.target.value),className:"w-full rounded-lg border-2 border-primary/40 bg-background px-3 py-2 text-sm text-foreground shadow-sm transition-all duration-200 focus:border-primary focus:shadow-md focus:outline-none",placeholder:$("projects.projectNamePlaceholder"),autoFocus:!0,autoComplete:"off",onClick:Q=>Q.stopPropagation(),onKeyDown:Q=>{Q.key==="Enter"&&J(),Q.key==="Escape"&&S()},style:{fontSize:"16px",WebkitAppearance:"none",borderRadius:"8px"}}):i.jsxs(i.Fragment,{children:[i.jsx("div",{className:"flex min-w-0 flex-1 items-center justify-between",children:i.jsx("h3",{className:"truncate text-sm font-medium text-foreground",children:e.displayName})}),i.jsx("p",{className:"text-xs text-muted-foreground",children:z})]})})]}),i.jsx("div",{className:"flex items-center gap-1",children:K?i.jsxs(i.Fragment,{children:[i.jsx("button",{className:"flex h-8 w-8 items-center justify-center rounded-lg bg-green-500 shadow-sm transition-all duration-150 active:scale-90 active:shadow-none dark:bg-green-600",onClick:Q=>{Q.stopPropagation(),J()},children:i.jsx(Ht,{className:"h-4 w-4 text-white"})}),i.jsx("button",{className:"flex h-8 w-8 items-center justify-center rounded-lg bg-gray-500 shadow-sm transition-all duration-150 active:scale-90 active:shadow-none dark:bg-gray-600",onClick:Q=>{Q.stopPropagation(),S()},children:i.jsx(ht,{className:"h-4 w-4 text-white"})})]}):i.jsxs(i.Fragment,{children:[i.jsx("button",{className:me("w-8 h-8 rounded-lg flex items-center justify-center active:scale-90 transition-all duration-150 border",s?"bg-yellow-500/10 dark:bg-yellow-900/30 border-yellow-200 dark:border-yellow-800":"bg-gray-500/10 dark:bg-gray-900/30 border-gray-200 dark:border-gray-800"),onClick:Q=>{Q.stopPropagation(),F()},title:$(s?"tooltips.removeFromFavorites":"tooltips.addToFavorites"),children:i.jsx(Ea,{className:me("w-4 h-4 transition-colors",s?"text-yellow-600 dark:text-yellow-400 fill-current":"text-gray-600 dark:text-gray-400")})}),i.jsx("button",{className:"flex h-8 w-8 items-center justify-center rounded-lg border border-red-200 bg-red-500/10 active:scale-90 dark:border-red-800 dark:bg-red-900/30",onClick:Q=>{Q.stopPropagation(),N(e)},children:i.jsx(En,{className:"h-4 w-4 text-red-600 dark:text-red-400"})}),i.jsx("button",{className:"flex h-8 w-8 items-center justify-center rounded-lg border border-primary/20 bg-primary/10 active:scale-90 dark:border-primary/30 dark:bg-primary/20",onClick:Q=>{Q.stopPropagation(),k(e)},children:i.jsx(jh,{className:"h-4 w-4 text-primary"})}),i.jsx("div",{className:"flex h-6 w-6 items-center justify-center rounded-md bg-muted/30",children:r?i.jsx(Dr,{className:"h-3 w-3 text-muted-foreground"}):i.jsx(li,{className:"h-3 w-3 text-muted-foreground"})})]})})]})})}),i.jsxs(Ae,{variant:"ghost",className:me("hidden md:flex w-full justify-between p-2 h-auto font-normal hover:bg-accent/50",B&&"bg-accent text-accent-foreground",s&&!B&&"bg-yellow-50/50 dark:bg-yellow-900/10 hover:bg-yellow-100/50 dark:hover:bg-yellow-900/20"),onClick:ae,children:[i.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-3",children:[r?i.jsx(Sr,{className:"h-4 w-4 flex-shrink-0 text-primary"}):i.jsx(On,{className:"h-4 w-4 flex-shrink-0 text-muted-foreground"}),i.jsx("div",{className:"min-w-0 flex-1 text-left",children:K?i.jsxs("div",{className:"space-y-1",children:[i.jsx("input",{type:"text",value:l,onChange:Q=>b(Q.target.value),className:"w-full rounded border border-border bg-background px-2 py-1 text-sm text-foreground focus:ring-2 focus:ring-primary/20",placeholder:$("projects.projectNamePlaceholder"),autoFocus:!0,onKeyDown:Q=>{Q.key==="Enter"&&J(),Q.key==="Escape"&&S()}}),i.jsx("div",{className:"truncate text-xs text-muted-foreground",title:e.fullPath,children:e.fullPath})]}):i.jsxs("div",{children:[i.jsx("div",{className:"truncate text-sm font-semibold text-foreground",title:e.displayName,children:e.displayName}),i.jsxs("div",{className:"text-xs text-muted-foreground",children:[P,e.fullPath!==e.displayName&&i.jsxs("span",{className:"ml-1 opacity-60",title:e.fullPath,children:[" - ",e.fullPath.length>25?`...${e.fullPath.slice(-22)}`:e.fullPath]})]})]})})]}),i.jsx("div",{className:"flex flex-shrink-0 items-center gap-1",children:K?i.jsxs(i.Fragment,{children:[i.jsx("div",{className:"flex h-6 w-6 cursor-pointer items-center justify-center rounded text-green-600 transition-colors hover:bg-green-50 hover:text-green-700 dark:hover:bg-green-900/20",onClick:Q=>{Q.stopPropagation(),J()},children:i.jsx(Ht,{className:"h-3 w-3"})}),i.jsx("div",{className:"flex h-6 w-6 cursor-pointer items-center justify-center rounded text-gray-500 transition-colors hover:bg-gray-50 hover:text-gray-700 dark:hover:bg-gray-800",onClick:Q=>{Q.stopPropagation(),S()},children:i.jsx(ht,{className:"h-3 w-3"})})]}):i.jsxs(i.Fragment,{children:[s&&i.jsx("div",{className:"flex h-6 w-6 cursor-pointer items-center justify-center rounded hover:bg-yellow-50 dark:hover:bg-yellow-900/20",onClick:Q=>{Q.stopPropagation(),F()},title:$("tooltips.removeFromFavorites"),children:i.jsx(Ea,{className:"h-3 w-3 fill-current text-yellow-600 dark:text-yellow-400"})}),i.jsx(sN,{triggerLabel:$("tooltips.projectActions",{defaultValue:"Project actions"}),actions:[{id:"rename",label:$("actions.rename"),icon:jh,onClick:()=>k(e)},{id:"star",label:$(s?"tooltips.removeFromFavorites":"tooltips.addToFavorites"),icon:Ea,onClick:F},{id:"delete",label:$("actions.delete",{defaultValue:"Delete"}),icon:En,onClick:()=>N(e),danger:!0}]}),r?i.jsx(Dr,{className:"h-4 w-4 text-muted-foreground transition-colors group-hover:text-foreground"}):i.jsx(li,{className:"h-4 w-4 text-muted-foreground transition-colors group-hover:text-foreground"})]})})]})]}),i.jsx(PM,{project:e,isExpanded:r,sessions:c,selectedSession:n,initialSessionsLoaded:d,isLoadingSessions:u,currentTime:p,editingSession:f,editingSessionName:h,isSessionStarred:g,onEditingSessionNameChange:T,onStartEditingSession:_,onCancelEditingSession:E,onSaveEditingSession:O,onToggleStarSession:w,onProjectSelect:v,onSessionSelect:R,onDeleteSession:A,onLoadMoreSessions:j,onNewSession:L,t:$})]})}function lN({isLoading:e,loadingProgress:t,projectsCount:n,filteredProjectsCount:r,t:a}){return e?i.jsxs("div",{className:"px-4 py-12 text-center md:py-8",children:[i.jsx("div",{className:"mx-auto mb-4 flex h-12 w-12 items-center justify-center rounded-lg bg-muted md:mb-3",children:i.jsx("div",{className:"h-6 w-6 animate-spin rounded-full border-2 border-muted-foreground border-t-transparent"})}),i.jsx("h3",{className:"mb-2 text-base font-medium text-foreground md:mb-1",children:a("projects.loadingProjects")}),t&&t.total>0?i.jsxs("div",{className:"space-y-2",children:[i.jsx("div",{className:"h-2 w-full overflow-hidden rounded-full bg-muted",children:i.jsx("div",{className:"h-full bg-primary transition-all duration-300 ease-out",style:{width:`${t.current/t.total*100}%`}})}),i.jsxs("p",{className:"text-sm text-muted-foreground",children:[t.current,"/",t.total," ",a("projects.projects")]}),t.currentProject&&i.jsx("p",{className:"mx-auto max-w-[200px] truncate text-xs text-muted-foreground/70",title:t.currentProject,children:t.currentProject.split("-").slice(-2).join("/")})]}):i.jsx("p",{className:"text-sm text-muted-foreground",children:a("projects.fetchingProjects")})]}):n===0?i.jsxs("div",{className:"px-4 py-12 text-center md:py-8",children:[i.jsx("div",{className:"mx-auto mb-4 flex h-12 w-12 items-center justify-center rounded-lg bg-muted md:mb-3",children:i.jsx(On,{className:"h-6 w-6 text-muted-foreground"})}),i.jsx("h3",{className:"mb-2 text-base font-medium text-foreground md:mb-1",children:a("projects.noProjects")}),i.jsx("p",{className:"text-sm text-muted-foreground",children:a("projects.runClaudeCli")})]}):r===0?i.jsxs("div",{className:"px-4 py-12 text-center md:py-8",children:[i.jsx("div",{className:"mx-auto mb-4 flex h-12 w-12 items-center justify-center rounded-lg bg-muted md:mb-3",children:i.jsx(ja,{className:"h-6 w-6 text-muted-foreground"})}),i.jsx("h3",{className:"mb-2 text-base font-medium text-foreground md:mb-1",children:a("projects.noMatchingProjects")}),i.jsx("p",{className:"text-sm text-muted-foreground",children:a("projects.tryDifferentSearch")})]}):null}function MM({projects:e,filteredProjects:t,selectedProject:n,selectedSession:r,isLoading:a,loadingProgress:s,expandedProjects:o,editingProject:l,editingName:c,loadingSessions:d,initialSessionsLoaded:u,currentTime:p,editingSession:f,editingSessionName:h,deletingProjects:g,getProjectSessions:b,isProjectStarred:x,isSessionStarred:v,onEditingNameChange:y,onToggleProject:w,onProjectSelect:k,onToggleStarProject:S,onToggleStarSession:C,onStartEditingProject:N,onCancelEditingProject:R,onSaveProjectName:A,onDeleteProject:j,onSessionSelect:L,onDeleteSession:T,onLoadMoreSessions:_,onNewSession:E,onEditingSessionNameChange:O,onStartEditingSession:$,onCancelEditingSession:B,onSaveEditingSession:K,t:Y}){const P=i.jsx(lN,{isLoading:a,loadingProgress:s,projectsCount:e.length,filteredProjectsCount:t.length,t:Y});m.useEffect(()=>{let Q="Pixcode";const pe=n?.displayName?.trim();pe&&(Q=`${pe} - ${Q}`),document.title=Q},[n]);const z=!a&&e.length>0&&t.length>0,U=Q=>Q.source==="history"||Q.autoDiscovered===!0&&Q.isManuallyAdded!==!0,F=t.filter(Q=>!U(Q)),J=t.filter(Q=>U(Q)),ae=Q=>i.jsx(OM,{project:Q,selectedProject:n,selectedSession:r,isExpanded:o.has(Q.name),isDeleting:g.has(Q.name),isStarred:x(Q.name),editingProject:l,editingName:c,sessions:b(Q),initialSessionsLoaded:u.has(Q.name),isLoadingSessions:!!d[Q.name],currentTime:p,editingSession:f,editingSessionName:h,isSessionStarred:v,onEditingNameChange:y,onToggleProject:w,onProjectSelect:k,onToggleStarProject:S,onToggleStarSession:C,onStartEditingProject:N,onCancelEditingProject:R,onSaveProjectName:A,onDeleteProject:j,onSessionSelect:L,onDeleteSession:T,onLoadMoreSessions:_,onNewSession:E,onEditingSessionNameChange:O,onStartEditingSession:$,onCancelEditingSession:B,onSaveEditingSession:K,t:Y},Q.name);return i.jsx("div",{className:"pb-safe-area-inset-bottom md:space-y-1",children:z?i.jsxs(i.Fragment,{children:[F.map(Q=>ae(Q)),J.length>0&&i.jsxs(i.Fragment,{children:[i.jsx("div",{className:"px-3 pb-1 pt-3 text-[11px] font-semibold uppercase tracking-wide text-gray-500 dark:text-gray-400",children:Y("projects.detectedFromHistory")}),J.map(Q=>ae(Q))]})]}):P})}function wa(e){if(e===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function cN(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,e.__proto__=t}/*!
|
|
260
260
|
* GSAP 3.15.0
|
|
261
261
|
* https://gsap.com
|
|
262
262
|
*
|
package/dist/index.html
CHANGED
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
|
|
36
36
|
<!-- Prevent zoom on iOS -->
|
|
37
37
|
<meta name="format-detection" content="telephone=no" />
|
|
38
|
-
<script type="module" crossorigin src="/assets/index-
|
|
38
|
+
<script type="module" crossorigin src="/assets/index-C8DB6Dud.js"></script>
|
|
39
39
|
<link rel="modulepreload" crossorigin href="/assets/vendor-react-DB6V5Fl1.js">
|
|
40
40
|
<link rel="modulepreload" crossorigin href="/assets/vendor-codemirror-CIYNS698.js">
|
|
41
41
|
<link rel="modulepreload" crossorigin href="/assets/vendor-xterm-C7tpxJl7.js">
|
|
@@ -53,10 +53,15 @@ export const authRateLimiter = createRateLimiter({
|
|
|
53
53
|
max: 10,
|
|
54
54
|
message: 'Too many authentication attempts. Please try again in 15 minutes.',
|
|
55
55
|
});
|
|
56
|
+
// API rate limiter: only limits state-changing operations (POST/PUT/DELETE/PATCH).
|
|
57
|
+
// GET requests (polling, fetching sessions, file trees, update-state, etc.) are
|
|
58
|
+
// exempt — the frontend polls several endpoints frequently and 120/min was
|
|
59
|
+
// too low, causing false "rate limit" errors on active sessions.
|
|
56
60
|
export const apiRateLimiter = createRateLimiter({
|
|
57
61
|
windowMs: 60 * 1000,
|
|
58
|
-
max:
|
|
62
|
+
max: 300,
|
|
59
63
|
message: 'Too many API requests. Please slow down.',
|
|
64
|
+
skip: (req) => req.method === 'GET' || req.method === 'HEAD' || req.method === 'OPTIONS',
|
|
60
65
|
});
|
|
61
66
|
export { createRateLimiter };
|
|
62
67
|
//# sourceMappingURL=rate-limiter.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rate-limiter.js","sourceRoot":"","sources":["../../../server/middleware/rate-limiter.js"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAEpE,SAAS,iBAAiB,CAAC,OAAO,GAAG,EAAE;IACnC,MAAM,EACF,QAAQ,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,EACzB,GAAG,GAAG,GAAG,EACT,YAAY,GAAG,CAAC,GAAG,EAAE,EAAE,CAAC,WAAW,CAAC,GAAG,CAAC,EACxC,OAAO,GAAG,yDAAyD,EACnE,UAAU,GAAG,GAAG,EAChB,IAAI,GAAG,CAAC,IAAI,EAAE,EAAE,CAAC,KAAK,GACzB,GAAG,OAAO,CAAC;IAEZ,MAAM,IAAI,GAAG,IAAI,GAAG,EAAE,CAAC;IAEvB,SAAS,cAAc;QACnB,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QACvB,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,IAAI,CAAC,OAAO,EAAE,EAAE,CAAC;YACxC,IAAI,KAAK,CAAC,SAAS,IAAI,GAAG,EAAE,CAAC;gBACzB,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;YACrB,CAAC;QACL,CAAC;IACL,CAAC;IAED,MAAM,eAAe,GAAG,WAAW,CAAC,cAAc,EAAE,QAAQ,CAAC,CAAC;IAC9D,eAAe,CAAC,KAAK,EAAE,CAAC;IAExB,OAAO,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE;QACtB,IAAI,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;YACZ,OAAO,IAAI,EAAE,CAAC;QAClB,CAAC;QAED,MAAM,GAAG,GAAG,YAAY,CAAC,GAAG,CAAC,CAAC;QAC9B,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QAEvB,IAAI,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QAC1B,IAAI,CAAC,KAAK,IAAI,KAAK,CAAC,SAAS,IAAI,GAAG,EAAE,CAAC;YACnC,KAAK,GAAG;gBACJ,KAAK,EAAE,CAAC;gBACR,SAAS,EAAE,GAAG,GAAG,QAAQ;aAC5B,CAAC;YACF,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;QACzB,CAAC;QAED,KAAK,CAAC,KAAK,IAAI,CAAC,CAAC;QAEjB,GAAG,CAAC,SAAS,CAAC,mBAAmB,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;QAChD,GAAG,CAAC,SAAS,CAAC,uBAAuB,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,GAAG,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QAC/E,GAAG,CAAC,SAAS,CAAC,mBAAmB,EAAE,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,SAAS,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;QAE9E,IAAI,KAAK,CAAC,KAAK,GAAG,GAAG,EAAE,CAAC;YACpB,WAAW,CAAC,qBAAqB,EAAE;gBAC/B,EAAE,EAAE,WAAW,CAAC,GAAG,CAAC;gBACpB,QAAQ,EAAE,GAAG,CAAC,IAAI;gBAClB,MAAM,EAAE,GAAG,CAAC,MAAM;gBAClB,SAAS,EAAE,GAAG,CAAC,OAAO,CAAC,YAAY,CAAC;aACvC,CAAC,CAAC;YACH,OAAO,GAAG,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC;gBAC/B,OAAO,EAAE,KAAK;gBACd,KAAK,EAAE;oBACH,IAAI,EAAE,qBAAqB;oBAC3B,OAAO;iBACV;aACJ,CAAC,CAAC;QACP,CAAC;QAED,IAAI,EAAE,CAAC;IACX,CAAC,CAAC;AACN,CAAC;AAED,MAAM,CAAC,MAAM,eAAe,GAAG,iBAAiB,CAAC;IAC7C,QAAQ,EAAE,EAAE,GAAG,EAAE,GAAG,IAAI;IACxB,GAAG,EAAE,EAAE;IACP,OAAO,EAAE,mEAAmE;CAC/E,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,cAAc,GAAG,iBAAiB,CAAC;IAC5C,QAAQ,EAAE,EAAE,GAAG,IAAI;IACnB,GAAG,EAAE,GAAG;IACR,OAAO,EAAE,0CAA0C;
|
|
1
|
+
{"version":3,"file":"rate-limiter.js","sourceRoot":"","sources":["../../../server/middleware/rate-limiter.js"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAEpE,SAAS,iBAAiB,CAAC,OAAO,GAAG,EAAE;IACnC,MAAM,EACF,QAAQ,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,EACzB,GAAG,GAAG,GAAG,EACT,YAAY,GAAG,CAAC,GAAG,EAAE,EAAE,CAAC,WAAW,CAAC,GAAG,CAAC,EACxC,OAAO,GAAG,yDAAyD,EACnE,UAAU,GAAG,GAAG,EAChB,IAAI,GAAG,CAAC,IAAI,EAAE,EAAE,CAAC,KAAK,GACzB,GAAG,OAAO,CAAC;IAEZ,MAAM,IAAI,GAAG,IAAI,GAAG,EAAE,CAAC;IAEvB,SAAS,cAAc;QACnB,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QACvB,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,IAAI,CAAC,OAAO,EAAE,EAAE,CAAC;YACxC,IAAI,KAAK,CAAC,SAAS,IAAI,GAAG,EAAE,CAAC;gBACzB,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;YACrB,CAAC;QACL,CAAC;IACL,CAAC;IAED,MAAM,eAAe,GAAG,WAAW,CAAC,cAAc,EAAE,QAAQ,CAAC,CAAC;IAC9D,eAAe,CAAC,KAAK,EAAE,CAAC;IAExB,OAAO,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE;QACtB,IAAI,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;YACZ,OAAO,IAAI,EAAE,CAAC;QAClB,CAAC;QAED,MAAM,GAAG,GAAG,YAAY,CAAC,GAAG,CAAC,CAAC;QAC9B,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QAEvB,IAAI,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QAC1B,IAAI,CAAC,KAAK,IAAI,KAAK,CAAC,SAAS,IAAI,GAAG,EAAE,CAAC;YACnC,KAAK,GAAG;gBACJ,KAAK,EAAE,CAAC;gBACR,SAAS,EAAE,GAAG,GAAG,QAAQ;aAC5B,CAAC;YACF,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;QACzB,CAAC;QAED,KAAK,CAAC,KAAK,IAAI,CAAC,CAAC;QAEjB,GAAG,CAAC,SAAS,CAAC,mBAAmB,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;QAChD,GAAG,CAAC,SAAS,CAAC,uBAAuB,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,GAAG,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QAC/E,GAAG,CAAC,SAAS,CAAC,mBAAmB,EAAE,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,SAAS,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;QAE9E,IAAI,KAAK,CAAC,KAAK,GAAG,GAAG,EAAE,CAAC;YACpB,WAAW,CAAC,qBAAqB,EAAE;gBAC/B,EAAE,EAAE,WAAW,CAAC,GAAG,CAAC;gBACpB,QAAQ,EAAE,GAAG,CAAC,IAAI;gBAClB,MAAM,EAAE,GAAG,CAAC,MAAM;gBAClB,SAAS,EAAE,GAAG,CAAC,OAAO,CAAC,YAAY,CAAC;aACvC,CAAC,CAAC;YACH,OAAO,GAAG,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC;gBAC/B,OAAO,EAAE,KAAK;gBACd,KAAK,EAAE;oBACH,IAAI,EAAE,qBAAqB;oBAC3B,OAAO;iBACV;aACJ,CAAC,CAAC;QACP,CAAC;QAED,IAAI,EAAE,CAAC;IACX,CAAC,CAAC;AACN,CAAC;AAED,MAAM,CAAC,MAAM,eAAe,GAAG,iBAAiB,CAAC;IAC7C,QAAQ,EAAE,EAAE,GAAG,EAAE,GAAG,IAAI;IACxB,GAAG,EAAE,EAAE;IACP,OAAO,EAAE,mEAAmE;CAC/E,CAAC,CAAC;AAEH,mFAAmF;AACnF,gFAAgF;AAChF,2EAA2E;AAC3E,iEAAiE;AACjE,MAAM,CAAC,MAAM,cAAc,GAAG,iBAAiB,CAAC;IAC5C,QAAQ,EAAE,EAAE,GAAG,IAAI;IACnB,GAAG,EAAE,GAAG;IACR,OAAO,EAAE,0CAA0C;IACnD,IAAI,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,MAAM,KAAK,KAAK,IAAI,GAAG,CAAC,MAAM,KAAK,MAAM,IAAI,GAAG,CAAC,MAAM,KAAK,SAAS;CAC3F,CAAC,CAAC;AAEH,OAAO,EAAE,iBAAiB,EAAE,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pixelbyte-software/pixcode",
|
|
3
|
-
"version": "1.54.
|
|
3
|
+
"version": "1.54.5",
|
|
4
4
|
"description": "Self-hosted AI coding agent control room for Claude Code, Cursor CLI, OpenAI Codex, Gemini CLI, Qwen Code, and OpenCode with chat, files, shell, Git, orchestration, API keys, Telegram, MCP, plugins, themes, and desktop/server deployment.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist-server/server/index.js",
|
|
@@ -73,10 +73,15 @@ export const authRateLimiter = createRateLimiter({
|
|
|
73
73
|
message: 'Too many authentication attempts. Please try again in 15 minutes.',
|
|
74
74
|
});
|
|
75
75
|
|
|
76
|
+
// API rate limiter: only limits state-changing operations (POST/PUT/DELETE/PATCH).
|
|
77
|
+
// GET requests (polling, fetching sessions, file trees, update-state, etc.) are
|
|
78
|
+
// exempt — the frontend polls several endpoints frequently and 120/min was
|
|
79
|
+
// too low, causing false "rate limit" errors on active sessions.
|
|
76
80
|
export const apiRateLimiter = createRateLimiter({
|
|
77
81
|
windowMs: 60 * 1000,
|
|
78
|
-
max:
|
|
82
|
+
max: 300,
|
|
79
83
|
message: 'Too many API requests. Please slow down.',
|
|
84
|
+
skip: (req) => req.method === 'GET' || req.method === 'HEAD' || req.method === 'OPTIONS',
|
|
80
85
|
});
|
|
81
86
|
|
|
82
87
|
export { createRateLimiter };
|