@markus-global/cli 0.8.1-rc.0 → 0.8.1

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.
@@ -655,7 +655,7 @@ l0,-`+(r+144)+`c-2,-159.3,-10,-310.7,-24,-454c-53.3,-528,-210,-949.7,
655
655
 
656
656
  `)}),ut.toolCalls?.length)for(let An=0;An<ut.toolCalls.length;An++){const pr=ut.toolCalls[An];xn.push({type:"tool",key:`${pr.tool}_${An}`,tool:pr.tool,status:pr.status==="error"?"error":"done",args:pr.arguments,result:pr.result,durationMs:pr.durationMs})}xn.length>0&&(xn.push({type:"text",content:Je}),Rn.segments=xn)}let Kt;if(ze.startsWith("notes:"))Kt=`dm:${ze.slice(6)}`;else if(ze.startsWith("dm:")){const xn=ze.slice(3).split(":");Kt=`dm:${xn.find(pr=>pr!==(t?.id??""))??xn[0]??""}`}else Kt=`ch:${ze}`;kn(Kt,xn=>[...xn,Rn]),Kt===rt.current&&!aa.current&&(Rt.current+=1,hr(Rt.current),dt(!0)),wt==="agent"&&Kt===`ch:${fe}`&&Zt(xn=>{const An=xn.filter(pr=>pr.id!==Pt);return An.length===0&&cn.current&&(clearTimeout(cn.current),cn.current=null),An})}),[r,kn,t?.id,fe]),g.useEffect(()=>r?void 0:pn.on("chat:agent_no_response",Me=>{const ge=Me.payload,ze=ge.channel??"",wt=ge.agentId??"";ze&&wt&&`ch:${fe}`==`ch:${ze}`&&Zt(Je=>{const Pt=Je.filter(zt=>zt.id!==wt);return Pt.length===0&&cn.current&&(clearTimeout(cn.current),cn.current=null),Pt})}),[r,fe]),g.useEffect(()=>r?void 0:pn.on("chat:proactive_message",Me=>{const ge=Me.payload,ze=ge.targetUserId;if(ze&&ze!==t?.id)return;const wt=ge.agentId??"",Je=ge.agentName??a("page.fallbackAgent"),Pt=ge.message??"";ge.sessionId;const zt=ge.metadata??{};if(!wt||!Pt||Pt==="[cancelled]"||Pt==="[Stream cancelled]")return;const ut=!!zt.activityLog||Pt.startsWith("[ACTIVITY:"),{cleaned:St,priority:rn}=QS(Pt),Rn=!!zt.notifyUser||St!==Pt,Kt={id:`proactive_${Date.now()}`,sender:"agent",text:St,time:new Date().toLocaleTimeString(),agentName:Je,agentId:wt,...Rn?{isNotification:!0,notifyPriority:zt.priority??rn}:{},...ut?{isActivityLog:!0,activityType:zt.activityType,outcome:zt.outcome,mailboxItemId:zt.mailboxItemId,taskId:zt.taskId,requirementId:zt.requirementId}:{},...!ut&&zt.taskId?{taskId:zt.taskId}:{},...!ut&&zt.requirementId?{requirementId:zt.requirementId}:{}},xn=Ts("direct",wt,"","");kn(xn,An=>[...An,Kt])}),[r,kn,a]),ds.find(ae=>ae.id===ri),g.useEffect(()=>{za(null)},[be]);const le=ae=>rG(ae),Ie=()=>{qr.current?.abort(),qr.current=null;const ae=rt.current;gt.current.delete(ae),nt.current.delete(ae),vn(!1),Wt([]),ne==="direct"&&be&&ie.agents.cancelProcessing(be).catch(()=>{})},st=async(ae,Me)=>{const ge=(ae??Re).trim();if(!ge&&Dn.length===0||ne==="direct"&&!be)return;if(aa.current=!0,en){qr.current?.abort(),qr.current=null,ne==="direct"&&be&&ie.agents.cancelProcessing(be).catch(()=>{});const ut=rt.current;gt.current.delete(ut),nt.current.delete(ut),kn(ut,St=>{const rn=[...St];for(let Rn=rn.length-1;Rn>=0;Rn--)if(rn[Rn].sender==="agent"&&!rn[Rn].isStopped&&!rn[Rn].isError){const Kt=rn[Rn];if(!(Kt.text?.trim()||(Kt.segments??[]).some(An=>An.type==="text"&&(An.content||An.thinking)||An.type==="tool")))rn.splice(Rn,1);else{const An=(Kt.segments??[]).map(pr=>pr.type==="tool"&&pr.status==="running"?{...pr,status:"stopped"}:pr);rn[Rn]={...Kt,isStopped:!0,segments:An}}break}return rn}),vn(!1),Wt([]),await new Promise(St=>setTimeout(St,50))}const ze=Dn.length>0?Dn.map(ut=>ut.dataUrl):void 0,wt=Dn.length>0?Dn.map(ut=>ut.name):void 0,Je=Ts(ne,be,fe,Ae),Pt=Vt;ae||We(""),$n([]),Ls(!1),ln(null);const zt=ne==="dm";if(gt.current.add(Je),nt.current.set(Je,[]),rt.current===Je&&!zt&&(vn(!0),Wt([])),ne==="dm"){const ut=Xn(t?.id??"",Ae),St=`opt_${Date.now()}`,rn={id:St,sender:"user",text:ge,time:new Date().toLocaleTimeString()};Pt&&(rn.replyToId=Pt.id,rn.replyToSender=Pt.sender,rn.replyToText=Pt.text),kn(Je,Rn=>[...Rn,rn]);try{const Rn=await ie.channels.sendMessage(ut,{text:ge,senderName:t?.name??a("page.fallbackYou"),senderId:t?.id,mentions:[],orgId:"default",humanOnly:!0});Rn.userMessage&&Fe(Rn.userMessage.id),kn(Je,Kt=>{const xn=Kt.filter(pr=>pr.id!==St),An=[];return Rn.userMessage&&An.push(Yl(Rn.userMessage,t?.id)),An.length>0?[...xn,...An]:Kt})}catch(Rn){kn(Je,Kt=>[...Kt,{id:`err_${Date.now()}`,sender:"agent",text:a("page.errorWithMessage",{message:String(Rn)}),time:new Date().toLocaleTimeString(),agentName:a("page.systemName"),isError:!0}])}gt.current.delete(Je),rt.current===Je&&vn(!1)}else if(ne==="channel"){const ut=`opt_${Date.now()}`,St={id:ut,sender:"user",text:ge,time:new Date().toLocaleTimeString()};Pt&&(St.replyToId=Pt.id,St.replyToSender=Pt.sender,St.replyToText=Pt.text),kn(Je,Kt=>[...Kt,St]);const rn=le(ge),Rn=Dt.find(Kt=>Kt.channelKey===fe);if(fe.startsWith("group:")){const Kt=[];if(Rn?.members){for(const xn of Rn.members)if(xn.type==="agent"){const An=u.find(pr=>pr.id===xn.id);An&&Kt.push({id:An.id,name:An.name,avatarUrl:An.avatarUrl})}}Kt.length>0&&(cn.current&&clearTimeout(cn.current),Zt(Kt),cn.current=setTimeout(()=>Zt([]),12e4))}try{const Kt=await ie.channels.sendMessage(fe,{text:ge,senderName:t?.name??a("page.fallbackYou"),mentions:rn,senderId:t?.id,orgId:"default",replyToId:Pt?.id});Kt.userMessage&&Fe(Kt.userMessage.id),Kt.agentMessage&&Fe(Kt.agentMessage.id),kn(Je,xn=>{const An=xn.filter(Zs=>Zs.id!==ut),pr=[];return Kt.userMessage&&pr.push(Yl(Kt.userMessage,t?.id)),Kt.agentMessage&&pr.push(Yl(Kt.agentMessage,t?.id)),pr.length>0?[...An,...pr]:xn})}catch(Kt){const xn=Wk(Kt,a)||a("page.errorWithMessage",{message:String(Kt)});kn(Je,An=>[...An,{id:`err_${Date.now()}`,sender:"agent",text:xn,time:new Date().toLocaleTimeString(),agentName:a("page.systemName"),isError:!0}]),cn.current&&(clearTimeout(cn.current),cn.current=null),Zt([])}gt.current.delete(Je),rt.current===Je&&vn(!1)}else{const ut=`a_${Date.now()}`;if(Me?.isResume){const It=new Date().toISOString();kn(Je,Gt=>[...Gt,{id:ut,sender:"agent",text:"",time:new Date().toLocaleTimeString(),rawCreatedAt:It,segments:[]}])}else{const It=new Date().toISOString(),Gt={id:`u_${Date.now()}`,sender:"user",text:ge,time:new Date().toLocaleTimeString()};ze?.length&&(Gt.images=ze),Pt&&(Gt.replyToId=Pt.id,Gt.replyToSender=Pt.sender,Gt.replyToText=Pt.text),kn(Je,_t=>[..._t,Gt,{id:ut,sender:"agent",text:"",time:new Date().toLocaleTimeString(),rawCreatedAt:It,segments:[]}])}let St=!1;const rn=It=>{Ge.current=Date.now(),_s(Je,Gt=>{const _t=[...Gt],Mt=_t.findIndex(Ba=>Ba.id===ut);if(Mt<0)return Gt;const Ot=_t[Mt].segments??[],Ut=Ot[Ot.length-1],Qt=Ut?.type==="text"?Ut.thinking??"":"";let yn="",Kn="",Jn=It;for(;Jn.length>0;)if(St){const Ba=Jn.indexOf("</think>");Ba>=0?(yn+=Jn.slice(0,Ba),Jn=Jn.slice(Ba+8),St=!1):(yn+=Jn,Jn="")}else{const Ba=Jn.indexOf("<think>");Ba>=0?(Kn+=Jn.slice(0,Ba),Jn=Jn.slice(Ba+7),St=!0):(Kn+=Jn,Jn="")}const wi=Qt+yn||void 0,oa=Ut?.type==="text"?[...Ot.slice(0,-1),{type:"text",content:Ut.content+Kn,thinking:wi,createdAt:Ut.createdAt}]:[...Ot,{type:"text",content:Kn,thinking:wi,createdAt:new Date().toISOString()}];return _t[Mt]={..._t[Mt],text:_t[Mt].text+Kn,segments:oa},_t})},Rn=It=>{if(Ge.current=Date.now(),It.type==="session_start"&&It.sessionId){rt.current===Je&&(tt(It.sessionId),Zn(Gt=>Gt.map(_t=>_t.id===Qn?{..._t,id:It.sessionId}:_t)));return}kn(Je,Gt=>{const _t=[...Gt],Mt=_t.findIndex(Ut=>Ut.id===ut);if(Mt<0)return Gt;const Ot=[..._t[Mt].committedSegments??[]];return It.type==="thinking_commit"?Ot.push({type:"text",content:"",thinking:It.content,createdAt:It.createdAt}):Ot.push({type:"text",content:It.content,createdAt:It.createdAt}),_t[Mt]={..._t[Mt],committedSegments:Ot},_t})},Kt=It=>{Ge.current=Date.now(),It.phase!=="heartbeat"&&((It.phase==="start"||It.phase==="end")&&Fs(Je,{...It,phase:It.phase,ts:Date.now()}),It.phase==="start"?kn(Je,Gt=>{const _t=[...Gt],Mt=_t.findIndex(Jn=>Jn.id===ut);if(Mt<0)return Gt;const Ot=[..._t[Mt].segments??[]];let Ut=!1;if(It.arguments)for(let Jn=Ot.length-1;Jn>=0;Jn--){const wi=Ot[Jn];if(wi.type==="tool"&&wi.tool===It.tool&&wi.status==="running"){Ot[Jn]={...wi,args:It.arguments},Ut=!0;break}}const Qt=`${It.tool}_${Date.now()}`,yn=new Date().toISOString();Ut||Ot.push({type:"tool",key:Qt,tool:It.tool,status:"running",args:It.arguments,createdAt:yn});const Kn=[..._t[Mt].committedSegments??[]];return It.arguments!==void 0&&Kn.push({type:"tool",key:Qt,tool:It.tool,status:"running",args:It.arguments,createdAt:yn}),_t[Mt]={..._t[Mt],segments:Ot,committedSegments:Kn},_t}):It.phase==="output"?kn(Je,Gt=>{const _t=[...Gt],Mt=_t.findIndex(Ut=>Ut.id===ut);if(Mt<0)return Gt;const Ot=[..._t[Mt].segments??[]];for(let Ut=Ot.length-1;Ut>=0;Ut--){const Qt=Ot[Ut];if(Qt.type==="tool"&&Qt.tool===It.tool&&Qt.status==="running"){Ot[Ut]={...Qt,liveOutput:(Qt.liveOutput??"")+(It.output??"")};break}}return _t[Mt]={..._t[Mt],segments:Ot},_t}):It.phase==="subagent_progress"&&It.subagentEvent?kn(Je,Gt=>{const _t=[...Gt],Mt=_t.findIndex(Ut=>Ut.id===ut);if(Mt<0)return Gt;const Ot=[..._t[Mt].segments??[]];for(let Ut=Ot.length-1;Ut>=0;Ut--){const Qt=Ot[Ut];if(Qt.type==="tool"&&(Qt.tool==="spawn_subagent"||Qt.tool==="spawn_subagents")&&Qt.status==="running"){Ot[Ut]={...Qt,subagentLogs:[...Qt.subagentLogs??[],It.subagentEvent]};break}}return _t[Mt]={..._t[Mt],segments:Ot},_t}):kn(Je,Gt=>{const _t=[...Gt],Mt=_t.findIndex(yn=>yn.id===ut);if(Mt<0)return Gt;const Ot=new Date().toISOString(),Ut=[..._t[Mt].segments??[]];for(let yn=Ut.length-1;yn>=0;yn--){const Kn=Ut[yn];if(Kn.type==="tool"&&Kn.tool===It.tool&&Kn.status==="running"){Ut[yn]={...Kn,status:It.success===!1?"error":"done",args:It.arguments,result:It.result,error:It.error,durationMs:It.durationMs,liveOutput:void 0,createdAt:Ot};break}}const Qt=[..._t[Mt].committedSegments??[]];for(let yn=Qt.length-1;yn>=0;yn--){const Kn=Qt[yn];if(Kn.type==="tool"&&Kn.tool===It.tool&&Kn.status==="running"){Qt[yn]={...Kn,status:It.success===!1?"error":"done",args:It.arguments,result:It.result,error:It.error,durationMs:It.durationMs,liveOutput:void 0,createdAt:Ot};break}}return _t[Mt]={..._t[Mt],segments:Ut,committedSegments:Qt},_t}))},xn=new AbortController;qr.current=xn;try{Ge.current=Date.now();const It=ve===Qn?null:ve,Gt=await ie.agents.messageStream(be,ge,rn,Kt,xn.signal,ze,It,Me?.isRetry,Me?.isResume,Rn,wt);rt.current===Je&&(Gt.merged&&kn(Je,_t=>_t.filter(Mt=>Mt.id!==ut)),!Gt.merged&&Gt.segments?.length&&kn(Je,_t=>{const Mt=[..._t],Ot=Mt.findIndex(yn=>yn.id===ut);if(Ot<0)return _t;const Ut=Gt.segments.map((yn,Kn)=>yn.type==="tool"?{type:"tool",key:`${yn.tool}_${Kn}`,tool:yn.tool,status:yn.status,args:yn.arguments,result:yn.result,error:yn.error,durationMs:yn.durationMs,createdAt:yn.createdAt}:{type:"text",content:yn.content,thinking:yn.thinking,createdAt:yn.createdAt});let Qt=Gt.content||Mt[Ot].text;return Qt||(Qt=Ut.filter(yn=>yn.type==="text").map(yn=>yn.content).join("")),Mt[Ot]={...Mt[Ot],text:Qt,segments:Ut,committedSegments:Ut},Mt}),!Gt.merged&&!Gt.segments?.length&&kn(Je,_t=>{const Mt=[..._t],Ot=Mt.findIndex(Jn=>Jn.id===ut);if(Ot<0)return _t;const Ut=Mt[Ot],Qt=Ut.committedSegments??[],Kn=Qt.filter(Jn=>Jn.type==="text"&&!!Jn.content).map(Jn=>Jn.content).join("")||Gt.content||Ut.text;return(Qt.length>0||Kn)&&(Mt[Ot]={...Ut,text:Kn,segments:Qt.length>0?Qt:Ut.segments}),Mt}),Gt.sessionId&&(tt(Gt.sessionId),Zn(_t=>_t.map(Mt=>Mt.id===Qn?{...Mt,id:Gt.sessionId}:Mt))),fs(be).then(_t=>{if(rt.current===Je&&(Ct(_t),Gt.sessionId)){const Mt=_t.find(Ot=>Ot.id===Gt.sessionId);Mt&&Zn(Ot=>Ot.some(Qt=>Qt.id===Mt.id)?Ot.map(Qt=>Qt.id===Mt.id?Mt:Qt):[Mt,...Ot.filter(Qt=>Qt.id!==Qn)])}}))}catch(It){const Gt=It?.sessionId;Gt&&ne==="direct"&&rt.current===Je&&(tt(Gt),Zn(Mt=>Mt.map(Ot=>Ot.id===Qn?{...Ot,id:Gt}:Ot)),fs(be).then(Mt=>{if(rt.current!==Je)return;Ct(Mt);const Ot=Mt.find(Ut=>Ut.id===Gt);Ot&&Zn(Ut=>Ut.some(yn=>yn.id===Ot.id)?Ut.map(yn=>yn.id===Ot.id?Ot:yn):[Ot,...Ut])}));const _t=Wk(It,a);_t?kn(Je,Mt=>{const Ot=[...Mt],Ut=Ot.findIndex(Qt=>Qt.id===ut);if(Ut>=0){const Qt=Ot[Ut].segments??[];Ot[Ut]={...Ot[Ut],text:_t,isError:!0,segments:[...Qt,{type:"text",content:_t}]}}return Ot}):kn(Je,Mt=>{const Ot=[...Mt],Ut=Ot.findIndex(Qt=>Qt.id===ut);if(Ut>=0){const Qt=Ot[Ut];if(!(Qt.text||Qt.segments&&Qt.segments.length>0&&Qt.segments.some(Kn=>Kn.type==="text"&&(Kn.content||Kn.thinking)||Kn.type==="tool")))return Mt.filter(Kn=>Kn.id!==ut);Ot[Ut]={...Qt,isStopped:!0}}return Ot})}kn(Je,It=>{const Gt=[...It],_t=Gt.findIndex(Mt=>Mt.id===ut);if(_t>=0){const Mt=(Gt[_t].segments??[]).map(Ot=>Ot.type==="tool"&&Ot.status==="running"?{...Ot,status:"stopped"}:Ot);Gt[_t]={...Gt[_t],segments:Mt}}return Gt}),xn.signal.aborted&&kn(Je,It=>{const Gt=[...It],_t=Gt.findIndex(Mt=>Mt.id===ut);if(_t>=0){const Mt=Gt[_t];if(!(Mt.text||Mt.segments&&Mt.segments.length>0&&Mt.segments.some(Ut=>Ut.type==="text"&&(Ut.content||Ut.thinking)||Ut.type==="tool")))return It.filter(Ut=>Ut.id!==ut);Gt[_t]={...Mt,isStopped:!0}}return Gt});const pr=(Ve.current.get(Je)??[]).find(It=>It.id===ut),Zs=ve&&ve!==Qn?ve:null,jc=pr?.text||pr?.segments?.some(It=>It.type==="text"&&It.content||It.type==="tool");pr&&!jc&&ne==="direct"&&Zs&&!xn.signal.aborted&&await(async(Gt,_t)=>{for(let Mt=0;Mt<Gt;Mt++){await new Promise(Ot=>setTimeout(Ot,_t));try{const Ut=(await ie.sessions.getMessages(Zs,2)).messages.find(Qt=>Qt.role==="assistant");if(Ut?.content){const Qt=Ux(Ut);kn(Je,yn=>{const Kn=[...yn],Jn=Kn.findIndex(wi=>wi.id===ut);return Jn>=0&&(Kn[Jn]={...Kn[Jn],text:Qt.text,segments:Qt.segments}),Kn});return}}catch{}}})(5,3e3),(qr.current===xn||qr.current===null)&&(qr.current=null,gt.current.delete(Je),nt.current.delete(Je),rt.current===Je&&(vn(!1),Wt([])))}};ai.current=st;const[hn,Cn]=g.useState(null),[,$s]=g.useState(new Set),ro=g.useMemo(()=>{for(let ae=Et.length-1;ae>=0;ae--)if(Et[ae]?.sender==="agent"&&!Et[ae]?.isActivityLog)return Et[ae].id;return null},[Et]),z0=g.useCallback(ae=>{const Me=ae.segments?ae.segments.filter(ge=>ge.type==="text").map(ge=>ge.content).join(`
657
657
  `):ae.text;navigator.clipboard.writeText(Me),Cn(ae.id),setTimeout(()=>Cn(ge=>ge===ae.id?null:ge),2e3)},[]),$0=g.useCallback(ae=>{const Me=rt.current,ge=Ve.current.get(Me)??Et,ze=ge.findIndex(ut=>ut.id===ae.id);if(ze<0)return;let wt=null;for(let ut=ze-1;ut>=0;ut--)if(ge[ut]?.sender==="user"){wt=ge[ut];break}const Je=wt?.text??"";if(!Je)return;if(ze<ge.length-1){const ut=ge.length-1-ze;if(!window.confirm(ut===1?a("page.retryConfirmSingular"):a("page.retryConfirmPlural",{count:ut})))return}const zt=wt&&ze>0&&ge[ze-1]?.id===wt.id;kn(Me,ut=>{const St=ut.findIndex(rn=>rn.id===(zt?wt.id:ae.id));return St>=0?ut.slice(0,St):ut}),st(Je,{isRetry:!0})},[Et,kn,a]),B0=g.useCallback(ae=>{const Me=rt.current;(Ve.current.get(Me)??Et).findIndex(wt=>wt.id===ae.id)<0||(kn(Me,wt=>{const Je=[...wt],Pt=Je.findIndex(St=>St.id===ae.id);if(Pt<0)return wt;const zt=Je[Pt],ut=[...zt.segments??[]];for(;ut.length>0;){const St=ut[ut.length-1];if(St.type==="tool"&&(St.status==="stopped"||St.status==="running"))ut.pop();else if(St.type==="text"&&!St.content)ut.pop();else break}return Je[Pt]={...zt,segments:ut,isStopped:!1,isError:!1},Je}),st("[Continue from where you left off. Do not repeat content already generated.]",{isResume:!0}))},[Et,kn]),$o=g.useCallback(ae=>{const Me=ae.sender==="user"?t?.name??a("page.fallbackYou"):ae.agentName??a("page.fallbackAgent");if(ln({id:ae.id,sender:Me,text:ae.text.slice(0,120)}),ne==="channel"&&ae.sender==="agent"&&ae.agentName){const ge=`@${ae.agentName} `;We(ze=>ze.startsWith(ge)?ze:ge+ze)}Bn.current?.focus()},[t?.name,ne,a]),vc=async ae=>{tt(ae.id),$t(!1),zn(!1),Bt.current=null;const Me=rt.current;Ve.current.delete(Me),je([]),Zn(ge=>ge.some(ze=>ze.id===ae.id)?ge:[...ge,ae]),await Vr(ae.id,Me)},ip=ae=>{if(Zn(Me=>Me.filter(ge=>ge.id!==ae)),ve===ae){const Me=sn.filter(ge=>ge.id!==ae);Me.length>0?vc(Me[Me.length-1]):so()}},H0=g.useCallback(async ae=>{if(ae.length<2){fr([]);return}ga(!0);try{const Me=ne==="channel"?"channel":ne==="direct"?"direct":"all",ge=ne==="channel"?fe:void 0,{results:ze}=await ie.messages.search(ae,{scope:Me,channel:ge,limit:30});fr(ze)}catch{fr([])}ga(!1)},[ne,fe]),F0=g.useCallback(ae=>{dr(ae),xa.current&&clearTimeout(xa.current),xa.current=setTimeout(()=>H0(ae),300)},[H0]),q0=g.useCallback(ae=>{cr(!1),dr(""),fr([]),ae.source==="channel"&&ae.channel?(me("channel"),He(ae.channel)):ae.source==="direct"&&ae.agentId&&(me("direct"),se(ae.agentId)),setTimeout(()=>{const Me=document.getElementById(`msg-${ae.id}`);Me&&(Me.scrollIntoView({behavior:"smooth",block:"center"}),Me.classList.add("bg-brand-500/10"),setTimeout(()=>Me.classList.remove("bg-brand-500/10"),2e3))},500)},[]),so=()=>{tt(Qn);const ae=rt.current;Ve.current.delete(ae),je([]),zn(!1),Bt.current=null,$t(!1),Zn(Me=>{const ge=Me.filter(ze=>ze.id!==Qn);return[{id:Qn,agentId:be??"",userId:null,title:a("page.newChat"),createdAt:new Date().toISOString(),lastMessageAt:new Date().toISOString()},...ge]})},El=ae=>{if(We(ae),ne!=="channel"){Ls(!1);return}const Me=Bn.current?.selectionStart??ae.length,ge=ae.slice(0,Me),ze=ge.lastIndexOf("@");if(ze>=0){const wt=ze===0?"":ge[ze-1];if(ze===0||/[\s\n,,。!?!?;;::、()()\[\]【】]/.test(wt)){const Pt=ge.slice(ze+1);if(!Pt.includes(" ")&&!Pt.includes(`
658
- `)){Ls(!0),Ns(Pt.toLowerCase()),Ss(0);return}}}Ls(!1)},U0=ae=>{const Me=Bn.current?.selectionStart??Re.length,ze=Re.slice(0,Me).lastIndexOf("@"),wt=Re.slice(Me),Je=ae.includes(" ")?`@[${ae}]`:`@${ae}`,Pt=Re.slice(0,ze)+Je+" "+wt;We(Pt),Ls(!1),Ss(0);const zt=ze+Je.length+1;requestAnimationFrame(()=>{Bn.current?.setSelectionRange(zt,zt)})},wc=10*1024*1024,Hd=5,V0=new Set(["application/pdf","application/vnd.openxmlformats-officedocument.wordprocessingml.document","application/vnd.openxmlformats-officedocument.spreadsheetml.sheet","application/vnd.openxmlformats-officedocument.presentationml.presentation","application/vnd.ms-excel","application/msword","text/csv","text/html","application/json","application/xml","text/xml","application/epub+zip"]),Li=g.useCallback(ae=>ae.type.startsWith("image/")||V0.has(ae.type),[]),Ml=ae=>ae.dataUrl.startsWith("data:image/"),K0=(ae,Me)=>{if(Ml({dataUrl:Me}))return null;const ge=ae.split(".").pop()?.toLowerCase()??"";return{pdf:"📄",docx:"📝",doc:"📝",xlsx:"📊",xls:"📊",pptx:"📎",csv:"📊",json:"🔧",xml:"🔧",html:"🌐",epub:"📚"}[ge]??"📁"},Bo=g.useCallback(ae=>{const Me=Array.from(ae).filter(Li);if(Me.length!==0)for(const ge of Me){if(ge.size>wc)continue;const ze=new FileReader;ze.onload=()=>{const wt=ze.result;$n(Je=>Je.length>=Hd||Je.some(Pt=>Pt.dataUrl===wt)?Je:[...Je,{id:`img_${Date.now()}_${Math.random().toString(36).slice(2,6)}`,dataUrl:wt,name:ge.name}])},ze.readAsDataURL(ge)}},[Li]),W0=g.useCallback(ae=>{$n(Me=>Me.filter(ge=>ge.id!==ae))},[]),op=g.useCallback(ae=>{const Me=ae.clipboardData?.files;if(Me&&Me.length>0){const ge=Array.from(Me).filter(Li);ge.length>0&&(ae.preventDefault(),Bo(ge))}},[Bo,Li]),lp=g.useCallback(ae=>{ae.preventDefault();const Me=ae.dataTransfer?.files;Me&&Me.length>0&&Bo(Array.from(Me).filter(Li))},[Bo,Li]),cp=g.useCallback(ae=>{ae.preventDefault()},[]),Jr=u.find(ae=>ae.id===be),Fd=t?.name??a("page.fallbackYou"),Qs=un[un.length-1],Dl=en&&Qs?.sender==="agent",G0=Gn&&Qs?.sender==="agent",qd=g.useMemo(()=>{if(ne!=="channel")return null;if(fe.startsWith("group:custom:")){const Me=Dt.find(ge=>ge.channelKey===fe);return Me?.members?new Set(Me.members.filter(ge=>ge.type==="agent").map(ge=>ge.id)):null}if(!yr)return null;const ae=Pr.find(Me=>Me.id===yr);return ae?new Set(ae.members.filter(Me=>Me.type==="agent").map(Me=>Me.id)):null},[ne,fe,yr,Pr,Dt]),Pi=u.filter(ae=>qd?qd.has(ae.id):!0).filter(ae=>ae.name.toLowerCase().includes(Yn)),kc=h.find(ae=>ae.id===Ae),Rl=Ae===t?.id||!Ae,ia=Dt.find(ae=>ae.channelKey===fe);g.useEffect(()=>{if(r||!fe.startsWith("group:custom:"))return;const ae=Dt.find(Me=>Me.channelKey===fe);!ae||ae.members||ie.groupChats.getById(ae.id).then(Me=>{Me.chat.members&&Pn(ge=>ge.map(ze=>ze.id===ae.id?{...ze,members:Me.chat.members}:ze))}).catch(()=>{})},[r,fe,Dt]);const ao=ne==="channel"?ia?.name??fe:ne==="direct"?Jr?.name??a("page.selectAgent"):ne==="dm"?Rl?a("chat.myNotes"):kc?.name??a("page.directMessage"):a("page.chatTitle"),Ud=ne==="channel"?ia?a("page.placeholder.channel",{name:ia.name}):a("page.placeholder.channelWithMention",{name:fe}):ne==="dm"?Rl?a("page.placeholder.dmSelf"):a("page.placeholder.dmOther",{name:kc?.name??""}):a(be?"page.placeholder.direct":"page.placeholder.noAgent"),Il=v&&N==="chat";return n.jsxs("div",{ref:L,className:"flex-1 overflow-hidden flex relative",children:[n.jsx(cG,{authUser:t,agents:u,teams:Pr,humans:h,tasks:ds,externalAgents:ba,groupChats:Dt,chatMode:ne,selectedAgent:be,activeChannel:fe,activeDmUserId:Ae,previewMode:r,onSelectAgent:ae=>{me("direct"),se(ae),z("chat"),On(!1),v&&E()},onSelectChannel:ae=>{me("channel"),He(ae),z("chat"),On(!1),v&&E()},onSelectDm:ae=>{me("dm"),et(ae),z("chat"),On(!1),v&&E()},onSelectTeam:ae=>{const Me=Dt.find(ge=>ge.type==="team"&&ge.teamId===ae);v?R(ae):Me&&(me("channel"),He(Me.channelKey),z("chat"),On(!1),!V&&!O&&Y(!0))},selectedTeamId:yr??(ne==="direct"&&Jr?.teamId?Jr.teamId:null),onRefreshTeams:zs,onRefreshAgents:Zr,onRefreshHumans:Sa,onRefreshGroupChats:ka,onViewProfile:it,onManageGroupMembers:ae=>{me("channel"),He(ae),z("chat"),On(!0),v&&E()},unreadByAgent:wa,unreadByChannel:zr,width:v?void 0:D.width,onResizeStart:v?void 0:D.onResizeStart,hidden:v&&N!=="roster",initialLoading:y}),v&&N==="team"&&S&&(()=>{const ae=Pr.find(ze=>ze.id===S);if(!ae)return null;const Me=u.filter(ze=>ze.teamId===S),ge=Dt.find(ze=>ze.type==="team"&&ze.teamId===S);return n.jsxs("div",{className:"flex-1 overflow-hidden flex flex-col min-w-0",children:[n.jsxs("div",{className:"flex items-center gap-2 px-3 h-12 shrink-0 border-b border-border-default",children:[n.jsx("button",{onClick:()=>{window.location.hash=De.TEAM},className:"p-1.5 -ml-1 rounded-lg hover:bg-surface-overlay transition-colors shrink-0 text-fg-secondary",children:n.jsx("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:n.jsx("polyline",{points:"15 18 9 12 15 6"})})}),n.jsxs("div",{className:"flex items-center gap-2 flex-1 min-w-0",children:[n.jsx("div",{className:"w-8 h-8 rounded-lg bg-brand-500/15 flex items-center justify-center shrink-0",children:n.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:"text-brand-500",children:[n.jsx("path",{d:"M17 21v-2a4 4 0 0 0-4-4H5a4 4 0 0 0-4 4v2"}),n.jsx("circle",{cx:"9",cy:"7",r:"4"}),n.jsx("path",{d:"M23 21v-2a4 4 0 0 0-3-3.87"}),n.jsx("path",{d:"M16 3.13a4 4 0 0 1 0 7.75"})]})}),n.jsxs("div",{className:"min-w-0",children:[n.jsx("h3",{className:"text-sm font-semibold text-fg-primary truncate",children:ae.name}),n.jsx("p",{className:"text-[10px] text-fg-tertiary",children:a("chat.members_other",{count:ae.members?.length||Me.length})})]})]})]}),n.jsxs("div",{className:"flex-1 overflow-y-auto px-3 py-3 space-y-1",children:[ge&&(()=>{const ze=zr[ge.channelKey]??0;return n.jsxs("button",{onClick:()=>{me("channel"),He(ge.channelKey),z("chat"),E()},className:"w-full flex items-center gap-2.5 px-2.5 py-2.5 rounded-xl hover:bg-surface-overlay transition-colors",children:[n.jsx("div",{className:"w-9 h-9 rounded-xl bg-brand-500/15 flex items-center justify-center shrink-0",children:n.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:"text-brand-500",children:n.jsx("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"})})}),n.jsxs("div",{className:"flex-1 min-w-0 text-left",children:[n.jsx("div",{className:"text-sm font-medium text-fg-primary truncate",children:ge.name}),n.jsx("div",{className:"text-[10px] text-fg-tertiary",children:a("chat.groupChat")})]}),ze>0?n.jsx("span",{className:"min-w-[16px] h-[16px] flex items-center justify-center text-[9px] font-semibold text-white bg-red-500 rounded-full px-1 leading-none shrink-0",children:ze}):n.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"text-fg-tertiary shrink-0",children:n.jsx("polyline",{points:"9 18 15 12 9 6"})})]})})(),Me.length>0&&n.jsxs(n.Fragment,{children:[n.jsx("p",{className:"text-[10px] font-semibold text-fg-muted uppercase tracking-wider px-2.5 pt-2",children:a("chat.agents")}),Me.map(ze=>{const wt=wa.get(ze.id)??0;return n.jsxs("button",{onClick:()=>{me("direct"),se(ze.id),z("chat"),E()},className:"w-full flex items-center gap-2.5 px-2.5 py-2.5 rounded-xl hover:bg-surface-overlay transition-colors",children:[n.jsx(Nr,{name:ze.name||"Agent",avatarUrl:ze.avatarUrl,size:36}),n.jsxs("div",{className:"flex-1 min-w-0 text-left",children:[n.jsx("div",{className:"text-sm font-medium text-fg-primary truncate",children:ze.name}),n.jsx("div",{className:"text-[10px] text-fg-tertiary truncate",children:ze.role||ze.status})]}),wt>0?n.jsx("span",{className:"min-w-[16px] h-[16px] flex items-center justify-center text-[9px] font-semibold text-white bg-red-500 rounded-full px-1 leading-none shrink-0",children:wt}):n.jsx("span",{className:`w-2 h-2 rounded-full shrink-0 ${ze.status==="active"||ze.status==="idle"?"bg-green-500":ze.status==="working"||ze.status==="busy"?"bg-blue-500":ze.status==="paused"?"bg-amber-500":"bg-gray-400"}`})]},ze.id)})]})]})]})})(),V&&!O&&!v&&(()=>{const ae=yr??(ne==="direct"?Jr?.teamId:void 0);if(!ae)return null;const Me=Pr.find(ze=>ze.id===ae);if(!Me)return null;const ge=Dt.find(ze=>ze.type==="team"&&ze.teamId===ae);return n.jsx(bk,{team:Me,agents:u,humans:h,authUser:t,groupChat:ge,chatMode:ne,selectedAgent:be,activeChannel:fe,teams:Pr,onSelectAgent:ze=>{me("direct"),se(ze),z("chat"),On(!1)},onSelectChannel:ze=>{me("channel"),He(ze),z("chat"),On(!1)},onSelectDm:ze=>{me("dm"),et(ze),z("chat"),On(!1)},onBack:()=>Y(!1),onViewProfile:it,onRefreshAgents:Zr,onRefreshTeams:zs,unreadByAgent:wa,width:F.width,onResizeStart:F.onResizeStart})})(),$&&!v&&(()=>{const ae=yr??(ne==="direct"?Jr?.teamId:void 0);if(!ae)return null;const Me=Pr.find(ze=>ze.id===ae);if(!Me)return null;const ge=Dt.find(ze=>ze.type==="team"&&ze.teamId===ae);return n.jsxs("div",{"data-l2-floating":!0,className:"absolute z-30 inset-0",style:{left:D.width+6},children:[n.jsx("div",{className:"absolute inset-0 bg-black/20",onClick:()=>W(!1)}),n.jsx("div",{className:"relative h-full",style:{width:F.width+8},children:n.jsx(bk,{team:Me,agents:u,humans:h,authUser:t,groupChat:ge,chatMode:ne,selectedAgent:be,activeChannel:fe,teams:Pr,onSelectAgent:ze=>{me("direct"),se(ze),z("chat"),On(!1),W(!1)},onSelectChannel:ze=>{me("channel"),He(ze),z("chat"),On(!1),W(!1)},onSelectDm:ze=>{me("dm"),et(ze),z("chat"),On(!1),W(!1)},onBack:()=>W(!1),onViewProfile:ze=>{it(ze),W(!1)},onRefreshAgents:Zr,onRefreshTeams:zs,unreadByAgent:wa,width:F.width})})]})})(),(!v||Il)&&n.jsxs("div",{className:`flex-1 overflow-hidden flex flex-col ${v?"min-w-0":"min-w-[400px]"}`,children:[n.jsxs("div",{className:"shrink-0 relative pb-2",children:[v?n.jsxs(n.Fragment,{children:[n.jsxs("div",{className:"flex items-center px-3 h-11 gap-2",children:[n.jsx("button",{onClick:()=>{window.location.hash=T.current},className:"text-fg-secondary hover:text-fg-primary transition-colors p-1 -ml-1 shrink-0",children:n.jsx("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:n.jsx("polyline",{points:"15 18 9 12 15 6"})})}),n.jsx("span",{className:"font-semibold text-sm truncate min-w-0 flex-1",children:ao}),ne==="direct"&&Jr&&n.jsx(Xk,{agent:Jr,tasks:ds,onViewProfile:it})]}),n.jsxs("div",{className:"flex items-center px-3 h-9 gap-1 border-t border-border-default/40",children:[n.jsx("button",{onClick:()=>{No(I)?history.back():z("chat")},className:`px-2.5 py-1 text-xs font-medium rounded-md transition-colors ${I==="chat"?"bg-brand-500/15 text-brand-500":"text-fg-tertiary"}`,children:a("page.chatTitle")}),n.jsx("button",{onClick:()=>{No(I)||Ee()},className:`px-2.5 py-1 text-xs font-medium rounded-md transition-colors ${No(I)?"bg-brand-500/15 text-brand-500":"text-fg-tertiary"}`,children:a(ne==="channel"?"page.teamTab":"page.profileTab")}),n.jsx("div",{className:"flex-1"}),n.jsx("button",{onClick:()=>{cr(!on),on||(dr(""),fr([]))},className:`p-1 rounded-md transition-colors shrink-0 ${on?"bg-brand-500/15 text-brand-500":"text-fg-tertiary"}`,children:n.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,children:n.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M21 21l-5.197-5.197m0 0A7.5 7.5 0 105.196 5.196a7.5 7.5 0 0010.607 10.607z"})})}),ne==="channel"&&ia?.type==="custom"&&n.jsxs("button",{onClick:()=>On(!nr),className:`text-[11px] px-2 py-1 rounded-md font-medium shrink-0 flex items-center gap-1 ${nr?"bg-brand-500/15 text-brand-500":"text-fg-tertiary"}`,children:[n.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("path",{d:"M17 21v-2a4 4 0 0 0-4-4H5a4 4 0 0 0-4 4v2"}),n.jsx("circle",{cx:"9",cy:"7",r:"4"}),n.jsx("path",{d:"M23 21v-2a4 4 0 0 0-3-3.87"}),n.jsx("path",{d:"M16 3.13a4 4 0 0 1 0 7.75"})]}),ia.members?.length??ia.memberCount??0]}),ne==="direct"&&!No(I)&&n.jsxs(n.Fragment,{children:[n.jsx("button",{onClick:so,className:"text-[11px] text-brand-500 px-2 py-1 rounded-md bg-brand-500/10 font-medium shrink-0",children:a("page.newChatPlus")}),n.jsx("button",{ref:lt,onClick:()=>$t(!Tt),className:`p-1 rounded-md transition-colors shrink-0 ${Tt?"bg-surface-overlay text-fg-primary":"text-fg-tertiary"}`,title:a("page.historyTitle"),children:n.jsx("svg",{className:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:1.5,children:n.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M12 6v6h4.5m4.5 0a9 9 0 11-18 0 9 9 0 0118 0z"})})})]})]})]}):(()=>{const ae=yr?Pr.find(St=>St.id===yr):void 0,Me=ne==="direct"&&be?GG:ne==="channel"&&yr?YG:["chat"],ge=async()=>{const St=G.trim();if(!St){te(!1);return}try{ne==="direct"&&be?(await ie.agents.updateConfig(be,{name:St}),Zr()):ne==="channel"&&yr&&(await ie.teams.update(yr,{name:St}),zs())}catch{}te(!1)},ze=async()=>{try{ne==="direct"&&be?(await ie.agents.updateConfig(be,{roleDescription:Be}),Zr()):ne==="channel"&&yr&&(await ie.teams.update(yr,{description:Be}),zs())}catch{}Ce(!1)},wt=ne==="direct"?Jr?.name:ne==="channel"?ae?.name??ia?.name:kc?.name??"",Je=ne==="direct"?Jr?.role||"":ne==="channel"&&ae?.description||"",Pt=ne==="direct"?Jr?.avatarUrl:void 0,zt=wt||"U",ut=ne==="direct"&&be||ne==="channel"&&yr;return n.jsxs("div",{className:"flex flex-col",children:[n.jsxs("div",{className:"flex items-center px-4 h-14 gap-2.5",children:[(!V||O)&&(ne==="channel"&&yr||ne==="direct"&&Jr?.teamId)&&n.jsx("button",{onClick:U,className:`w-8 h-8 flex items-center justify-center rounded-lg transition-colors shrink-0 ${$?"bg-brand-500/15 text-brand-500":"text-fg-tertiary hover:text-fg-secondary hover:bg-surface-elevated"}`,title:"Toggle team panel",children:n.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2",ry:"2"}),n.jsx("line",{x1:"9",y1:"3",x2:"9",y2:"21"})]})}),ut&&(ne==="channel"&&yr?n.jsx("div",{className:"w-9 h-9 rounded-xl bg-brand-600 text-white flex items-center justify-center text-sm font-bold shrink-0",children:n.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("path",{d:"M17 21v-2a4 4 0 0 0-4-4H5a4 4 0 0 0-4 4v2"}),n.jsx("circle",{cx:"9",cy:"7",r:"4"}),n.jsx("path",{d:"M23 21v-2a4 4 0 0 0-3-3.87"}),n.jsx("path",{d:"M16 3.13a4 4 0 0 1 0 7.75"})]})}):n.jsx(Nr,{name:zt,avatarUrl:Pt,size:36,className:"rounded-xl shrink-0"})),ut?n.jsxs("div",{className:"flex-1 min-w-0",children:[n.jsxs("div",{className:"flex items-center gap-2",children:[ee?n.jsx("input",{ref:he,value:G,onChange:St=>ue(St.target.value),onBlur:ge,onKeyDown:St=>{St.key==="Enter"&&ge(),St.key==="Escape"&&te(!1)},className:"text-sm font-semibold bg-transparent border-b border-brand-500 outline-none py-0 px-0 min-w-[80px] max-w-[240px]",autoFocus:!0}):n.jsx("span",{className:"text-sm font-semibold truncate cursor-pointer hover:text-brand-500 transition-colors",onClick:()=>{ue(wt??""),te(!0)},title:"Click to edit name",children:wt}),ne==="direct"&&Jr&&n.jsx(Xk,{agent:Jr,tasks:ds,onViewProfile:it})]}),(ne==="direct"||ne==="channel"&&yr)&&(Se?n.jsx("input",{ref:_e,value:Be,onChange:St=>Ne(St.target.value),onBlur:ze,onKeyDown:St=>{St.key==="Enter"&&ze(),St.key==="Escape"&&Ce(!1)},className:"text-[11px] text-fg-tertiary bg-transparent border-b border-brand-500/50 outline-none py-0 px-0 w-full max-w-[400px] mt-0.5",placeholder:"Add description...",autoFocus:!0}):n.jsx("div",{className:"text-[11px] text-fg-tertiary truncate cursor-pointer hover:text-fg-secondary transition-colors mt-0.5",onClick:()=>{Ne(Je),Ce(!0)},title:"Click to edit description",children:Je||"No description"}))]}):n.jsxs("div",{className:"flex-1 min-w-0 flex items-center gap-2",children:[n.jsx("span",{className:"font-semibold text-sm truncate",children:ao}),ne==="dm"&&n.jsx("span",{className:"text-xs text-fg-tertiary",children:Rl?a("page.privateNotepad"):""})]}),n.jsxs("div",{className:"ml-auto flex items-center gap-2 shrink-0",children:[n.jsx("button",{onClick:()=>{cr(!on),on||(dr(""),fr([]))},className:`p-1.5 rounded-md transition-colors ${on?"bg-brand-500/15 text-brand-500":"text-fg-tertiary hover:text-fg-secondary hover:bg-surface-elevated"}`,title:a("page.searchMessages"),children:n.jsx("svg",{className:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:1.5,children:n.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M21 21l-5.197-5.197m0 0A7.5 7.5 0 105.196 5.196a7.5 7.5 0 0010.607 10.607z"})})}),ne==="channel"&&ia?.type==="custom"&&n.jsxs("button",{onClick:()=>On(!nr),className:`text-xs px-2.5 py-1 rounded-md border transition-colors flex items-center gap-1.5 ${nr?"bg-brand-500/15 text-brand-500 border-brand-500/30":"text-fg-secondary hover:text-fg-primary border-border-default hover:bg-surface-elevated"}`,children:[n.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("path",{d:"M17 21v-2a4 4 0 0 0-4-4H5a4 4 0 0 0-4 4v2"}),n.jsx("circle",{cx:"9",cy:"7",r:"4"}),n.jsx("path",{d:"M23 21v-2a4 4 0 0 0-3-3.87"}),n.jsx("path",{d:"M16 3.13a4 4 0 0 1 0 7.75"})]}),ia.members?.length??ia.memberCount??0]}),ne==="direct"&&Jr&&I==="chat"&&n.jsxs("div",{className:"flex items-center gap-1.5",children:[n.jsx("button",{onClick:so,className:"text-xs text-brand-500 hover:text-brand-500 px-2.5 py-1 rounded-md hover:bg-brand-500/10 border border-brand-500/20 transition-colors flex items-center gap-1",children:a("page.newChatButton")}),n.jsx("button",{ref:lt,onClick:()=>$t(!Tt),className:`p-1.5 rounded-md transition-colors ${Tt?"bg-surface-overlay text-fg-primary":"text-fg-tertiary hover:text-fg-secondary hover:bg-surface-elevated"}`,title:a("page.historyTitle"),children:n.jsx("svg",{className:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:1.5,children:n.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M12 6v6h4.5m4.5 0a9 9 0 11-18 0 9 9 0 0118 0z"})})})]})]})]}),Me.length>1&&n.jsx("div",{className:"flex items-center gap-1 px-4 pb-1.5 overflow-x-auto scrollbar-hide",children:Me.map(St=>n.jsxs("button",{onClick:()=>z(St),className:`px-3 py-1.5 text-xs font-medium rounded-md transition-colors whitespace-nowrap flex items-center gap-1 ${I===St?"bg-brand-500/15 text-brand-500":"text-fg-tertiary hover:text-fg-secondary hover:bg-surface-elevated/50"}`,children:[n.jsx("span",{children:QG(St)}),XG(St,a)]},St))})]})})(),on&&n.jsxs("div",{className:"border-b border-border-default bg-surface-secondary/50 px-4 py-2 space-y-2 animate-in slide-in-from-top-2 duration-200",children:[n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsxs("div",{className:"flex-1 relative",children:[n.jsx("svg",{className:"absolute left-2.5 top-1/2 -translate-y-1/2 w-3.5 h-3.5 text-fg-tertiary",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:n.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M21 21l-5.197-5.197m0 0A7.5 7.5 0 105.196 5.196a7.5 7.5 0 0010.607 10.607z"})}),n.jsx("input",{autoFocus:!0,value:Fr,onChange:ae=>F0(ae.target.value),onKeyDown:ae=>{ae.key==="Escape"&&(cr(!1),dr(""),fr([]))},placeholder:a("page.searchPlaceholder"),className:"w-full pl-8 pr-3 py-1.5 text-xs bg-surface-primary border border-border-default rounded-lg outline-none focus:border-brand-500/50 transition-colors"})]}),n.jsx("button",{onClick:()=>{cr(!1),dr(""),fr([])},className:"text-fg-tertiary hover:text-fg-secondary text-xs px-1",children:"✕"})]}),Is&&n.jsxs("div",{className:"flex items-center gap-2 text-xs text-fg-tertiary py-1",children:[n.jsxs("svg",{className:"animate-spin h-3 w-3",viewBox:"0 0 24 24",fill:"none",children:[n.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),n.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"})]}),a("page.searching")]}),!Is&&Fr.length>=2&&br.length===0&&n.jsx("div",{className:"text-xs text-fg-tertiary py-1",children:a("page.noSearchResults")}),br.length>0&&n.jsx("div",{className:"max-h-60 overflow-y-auto space-y-0.5",children:br.map(ae=>n.jsxs("button",{onClick:()=>q0(ae),className:"w-full text-left px-3 py-2 rounded-lg hover:bg-surface-elevated transition-colors group",children:[n.jsxs("div",{className:"flex items-center gap-2 text-[11px] text-fg-tertiary mb-0.5",children:[n.jsx("span",{className:`px-1.5 py-0.5 rounded text-[10px] font-medium ${ae.source==="channel"?"bg-blue-500/10 text-blue-500":"bg-emerald-500/10 text-emerald-500"}`,children:ae.source==="channel"?"#":"1:1"}),ae.senderName&&n.jsx("span",{children:ae.senderName}),n.jsx("span",{children:new Date(ae.createdAt).toLocaleDateString(void 0,{month:"short",day:"numeric"})})]}),n.jsx("div",{className:"text-xs text-fg-secondary line-clamp-2 group-hover:text-fg-primary transition-colors",children:ae.text.length>200?ae.text.slice(0,200)+"…":ae.text})]},ae.id))})]}),ne==="direct"&&be&&I==="chat"&&sn.length>1&&n.jsx("div",{className:"flex items-center gap-0 px-3 overflow-x-auto scrollbar-hide",children:sn.map(ae=>n.jsxs("div",{className:`group flex items-center gap-1.5 px-3 py-1.5 text-xs cursor-pointer rounded-md transition-colors shrink-0 max-w-[180px] ${ae.id===ve?"text-brand-500 bg-brand-500/10":"text-fg-tertiary hover:text-fg-secondary hover:bg-surface-elevated/50"}`,onClick:()=>{if(ae.id===Qn){tt(Qn);const Me=rt.current;Ve.current.delete(Me),je([])}else vc(ae)},children:[ae.isMain&&n.jsx("span",{className:"text-[10px] opacity-50 shrink-0",children:"●"}),n.jsx("span",{className:"truncate",children:ae.id===Qn?a("page.newChat"):ae.isMain?a("page.sessionMain"):ae.title||a("page.sessionConversation")}),!ae.isMain&&n.jsx("button",{onClick:Me=>{Me.stopPropagation(),ip(ae.id)},className:"opacity-0 group-hover:opacity-100 text-fg-tertiary hover:text-fg-secondary transition-opacity shrink-0",children:"✕"})]},ae.id))}),ne==="channel"&&ia?.type==="custom"&&nr&&(()=>{const ae=ia,Me=ae.members??[],ge=[];for(const ze of u)Me.some(wt=>wt.id===ze.id)||ge.push({id:ze.id,name:ze.name,type:"agent",subtitle:ze.role||"Agent"});for(const ze of h)Me.some(wt=>wt.id===ze.id)||ge.push({id:ze.id,name:ze.name,type:"human",subtitle:ze.email||ze.role||""});return n.jsxs("div",{className:"bg-surface-secondary/80 px-4 py-3 flex flex-col gap-2",children:[n.jsxs("div",{className:"flex items-center justify-between",children:[n.jsxs("span",{className:"text-xs font-semibold text-fg-secondary",children:[a("page.members")," (",Me.length,")"]}),n.jsx("button",{onClick:()=>On(!1),className:"text-fg-tertiary hover:text-fg-secondary text-xs",children:n.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),n.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]}),n.jsx("div",{className:"flex flex-wrap gap-1.5",children:Me.map(ze=>n.jsxs("span",{className:`inline-flex items-center gap-1.5 px-2 py-1 rounded-full text-[11px] font-medium ${ze.type==="agent"?"bg-brand-500/10 text-brand-500":"bg-green-500/10 text-green-600"}`,children:[n.jsx(Nr,{name:ze.name,size:16,bgClass:ze.type==="agent"?"bg-brand-500/15 text-brand-500":"bg-green-500/15 text-green-600"}),ze.name,ze.id!==t?.id&&n.jsx("button",{onClick:async()=>{try{await ie.groupChats.removeMember(ae.id,ze.id),Pn(wt=>wt.map(Je=>Je.id===ae.id?{...Je,members:(Je.members??[]).filter(Pt=>Pt.id!==ze.id),memberCount:(Je.memberCount??1)-1}:Je))}catch{}},className:"ml-0.5 hover:text-red-500 transition-colors",title:a("common:remove"),children:n.jsxs("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),n.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]},ze.id))}),ge.length>0&&n.jsx("div",{className:"mt-1",children:n.jsxs("select",{className:"w-full bg-surface-primary border border-border-default rounded-lg px-2.5 py-1.5 text-xs text-fg-primary outline-none focus:ring-1 focus:ring-brand-500/50",value:"",onChange:async ze=>{const wt=ze.target.value;if(!wt)return;const Je=ge.find(Pt=>Pt.id===wt);if(Je)try{await ie.groupChats.addMember(ae.id,Je.id,Je.type,Je.name),Pn(Pt=>Pt.map(zt=>zt.id===ae.id?{...zt,members:[...zt.members??[],{id:Je.id,name:Je.name,type:Je.type}],memberCount:(zt.memberCount??0)+1}:zt))}catch{}},children:[n.jsx("option",{value:"",children:a("page.addMemberPlaceholder")}),ge.map(ze=>n.jsxs("option",{value:ze.id,children:["[",ze.type==="agent"?"Agent":"Human","] ",ze.name]},ze.id))]})})]})})(),ne==="direct"&&be&&Tt&&n.jsxs("div",{ref:vt,className:"absolute right-4 top-full mt-1 w-72 max-h-[420px] bg-surface-secondary border border-border-default rounded-xl shadow-2xl shadow-black/40 z-50 flex flex-col overflow-hidden",children:[n.jsxs("div",{className:"px-4 py-3 border-b border-border-default flex items-center justify-between",children:[n.jsx("span",{className:"text-xs font-semibold text-fg-secondary uppercase tracking-wider",children:a("page.historyTitle")}),n.jsx("button",{onClick:()=>$t(!1),className:"text-fg-tertiary hover:text-fg-secondary text-xs",children:"✕"})]}),n.jsxs("div",{className:"flex-1 overflow-y-auto p-2",children:[Pe.length===0&&n.jsx("div",{className:"text-xs text-fg-tertiary text-center py-6",children:a("page.noConversationsYet")}),(()=>{const ae=new Date,Me=new Date(ae.getFullYear(),ae.getMonth(),ae.getDate()).getTime(),ge=Me-864e5,ze=Me-7*864e5,wt=[],Je=[],Pt=[],zt=[],ut=[];for(const St of Pe){const rn=new Date(St.lastMessageAt).getTime();rn>=Me?Je.push(St):rn>=ge?Pt.push(St):rn>=ze?zt.push(St):ut.push(St)}return Je.length>0&&wt.push({label:a("page.dateToday"),items:Je}),Pt.length>0&&wt.push({label:a("page.dateYesterday"),items:Pt}),zt.length>0&&wt.push({label:a("page.datePrevious7Days"),items:zt}),ut.length>0&&wt.push({label:a("page.dateOlder"),items:ut}),wt.map(St=>n.jsxs("div",{className:"mb-2",children:[n.jsx("div",{className:"text-[10px] font-semibold text-fg-tertiary uppercase tracking-wider px-3 py-1.5",children:St.label}),St.items.map(rn=>n.jsxs("button",{onClick:()=>{vc(rn)},className:`w-full text-left px-3 py-2.5 rounded-lg text-xs mb-0.5 transition-colors ${rn.id===ve?"bg-brand-600/20 text-brand-500":"text-fg-secondary hover:bg-surface-elevated"}`,children:[n.jsxs("div",{className:"truncate font-medium flex items-center gap-1",children:[rn.isMain&&n.jsx("span",{className:"text-[10px] text-brand-500 opacity-80",children:"●"}),rn.isMain?a("page.sessionMain"):rn.title||a("page.sessionConversation")]}),n.jsx("div",{className:"text-fg-tertiary text-[10px] mt-0.5",children:new Date(rn.lastMessageAt).toLocaleString()})]},rn.id))]},St.label))})()]})]})]}),v&&I==="profile"&&ne==="direct"&&be&&n.jsx("div",{className:"flex-1 overflow-y-auto",children:n.jsx(Tk,{agentId:be,onBack:()=>z("chat"),inline:!0,defaultTab:Z,highlightMailboxId:J,onSwipeBack:()=>{No(B.current)?history.back():z("chat")},authUser:t})}),v&&I==="profile"&&ne==="channel"&&yr&&n.jsx("div",{className:"flex-1 overflow-y-auto",onTouchStart:v?mt.onTouchStart:void 0,onTouchEnd:v?mt.onTouchEnd:void 0,children:n.jsx(qk,{teamId:yr,onBack:()=>z("chat"),inline:!0,onSelectAgent:ae=>{me("direct"),se(ae),Ee()}})}),!v&&No(I)&&ne==="direct"&&be&&n.jsx("div",{className:"flex-1 overflow-y-auto",children:n.jsx(Tk,{agentId:be,onBack:()=>z("chat"),inline:!0,headless:!0,activeTab:I,highlightMailboxId:J,authUser:t})}),!v&&No(I)&&ne==="channel"&&yr&&n.jsx("div",{className:"flex-1 flex flex-col min-h-0",children:n.jsx(qk,{teamId:yr,onBack:()=>z("chat"),inline:!0,headless:!0,activeTab:I,onSelectAgent:ae=>{me("direct"),se(ae),z("overview"),!V&&!O&&Y(!0)}})}),n.jsxs("div",{className:`flex-1 overflow-hidden flex flex-col relative ${I!=="chat"?"hidden":""}`,children:[Mn&&n.jsxs("div",{className:"absolute top-0 left-0 right-0 z-10 flex justify-center items-center gap-2 py-2 bg-gradient-to-b from-surface-primary/90 to-transparent pointer-events-none",children:[n.jsxs("svg",{className:"animate-spin h-3.5 w-3.5 text-brand-400",viewBox:"0 0 24 24",fill:"none",children:[n.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),n.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"})]}),n.jsx("span",{className:"text-xs text-fg-tertiary",children:a("page.loadingEarlierMessages")})]}),n.jsxs("div",{ref:is,className:`flex-1 overflow-y-auto ${v?"p-2.5":"p-5 2xl:pr-[280px]"}`,onScroll:no,onTouchStart:v?mt.onTouchStart:void 0,onTouchEnd:v?mt.onTouchEnd:void 0,children:[un.length===0&&!en&&n.jsxs("div",{className:"flex flex-col items-center justify-center h-full text-fg-tertiary text-sm space-y-2",children:[n.jsx("div",{className:"opacity-40",children:n.jsx("svg",{width:"40",height:"40",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:ne==="channel"?n.jsxs(n.Fragment,{children:[n.jsx("path",{d:"M4 4h16c1.1 0 2 .9 2 2v12c0 1.1-.9 2-2 2H6l-4 4V6c0-1.1.9-2 2-2z"}),n.jsx("line",{x1:"8",y1:"10",x2:"16",y2:"10"}),n.jsx("line",{x1:"8",y1:"14",x2:"13",y2:"14"})]}):n.jsx("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"})})}),ne==="channel"&&n.jsx("div",{children:a("page.emptyChannel",{name:ia?.name??fe})}),ne==="direct"&&!be&&n.jsx("div",{children:a("page.emptySelectAgent")}),ne==="direct"&&be&&n.jsx("div",{children:a("page.emptyNewConversation",{name:Jr?.name??""})})]}),un.length>0&&n.jsx("div",{style:{height:yt.getTotalSize(),width:"100%",position:"relative"},children:yt.getVirtualItems().map(ae=>{const Me=ae.index,ge=un[Me],ze=Me>0?un[Me-1]:null,wt=Vk(ge.rawCreatedAt),Je=ze?Vk(ze.rawCreatedAt):"",Pt=wt&&wt!==Je,zt=Me===un.length-1,St=Dl&&zt&&en,rn=G0&&zt||St,Rn=ne==="channel"||!St||ge.isStopped;return n.jsx("div",{"data-index":Me,ref:yt.measureElement,style:{position:"absolute",top:0,left:0,width:"100%",transform:`translateY(${ae.start}px)`},children:n.jsxs("div",{className:"pb-3",children:[Pt&&n.jsxs("div",{className:"flex items-center gap-3 py-2 my-1",children:[n.jsx("div",{className:"flex-1 h-px bg-border-default"}),n.jsx("span",{className:"text-[10px] text-fg-tertiary font-medium uppercase tracking-wider shrink-0",children:BG(ge.rawCreatedAt,l)}),n.jsx("div",{className:"flex-1 h-px bg-border-default"})]}),n.jsxs("div",{id:`msg-${ge.id}`,className:"group/msg flex gap-3 transition-colors rounded-lg",children:[ne==="channel"?n.jsx("div",{className:"shrink-0 cursor-pointer",onClick:Kt=>{if(ge.sender==="agent"&&ge.agentId){const xn=Kt.currentTarget.getBoundingClientRect();q({agentId:ge.agentId,top:xn.top,left:xn.right+8})}},children:n.jsx(Nr,{name:ge.sender==="user"?Fd:ge.agentName??a("page.fallbackAgent"),avatarUrl:ge.sender==="user"?t?.avatarUrl:u.find(Kt=>Kt.id===ge.agentId)?.avatarUrl,size:32,bgClass:ge.sender==="user"?"bg-brand-600":"bg-brand-500/15 text-brand-600",className:ge.sender==="agent"?"hover:ring-1 hover:ring-brand-500/40 rounded-lg":"rounded-lg"})}):n.jsx("div",{className:"shrink-0",children:n.jsx(Nr,{name:ge.sender==="user"?Fd:ge.agentName??(ne==="direct"?Jr?.name??a("page.fallbackAgent"):a("page.fallbackAgent")),avatarUrl:ge.sender==="user"?t?.avatarUrl:u.find(Kt=>Kt.id===(ge.agentId??(ne==="direct"?Jr?.id:void 0)))?.avatarUrl,size:32,bgClass:ge.sender==="user"?"bg-brand-600":"bg-brand-500/15 text-brand-600",className:"rounded-lg"})}),n.jsxs("div",{className:"min-w-0 flex-1",children:[n.jsxs("div",{className:"flex items-baseline gap-2",children:[n.jsx("span",{className:"text-sm font-medium text-fg-primary",children:ge.sender==="user"?Fd:ne==="channel"?ge.agentName??a("page.fallbackAgent"):n.jsx(UG,{name:ge.agentName??(ne==="direct"?Jr?.name??a("page.fallbackAgent"):a("page.fallbackAgent")),agentId:ge.agentId??(ne==="direct"?Jr?.id:void 0),agents:u,onViewProfile:it})}),n.jsx("span",{className:"text-xs text-fg-tertiary",title:ge.rawCreatedAt?new Date(ge.rawCreatedAt).toLocaleString():"",children:$G(ge.time,ge.rawCreatedAt,l)})]}),ge.replyToId&&ge.replyToSender&&n.jsxs("button",{onClick:()=>{const Kt=document.getElementById(`msg-${ge.replyToId}`);Kt&&(Kt.scrollIntoView({behavior:"smooth",block:"center"}),Kt.classList.add("bg-brand-500/10"),setTimeout(()=>Kt.classList.remove("bg-brand-500/10"),1500))},className:"flex items-center gap-1.5 mt-0.5 mb-1 pl-2 py-0.5 border-l-2 border-brand-500/40 text-xs text-fg-tertiary hover:text-fg-secondary transition-colors cursor-pointer",children:[n.jsx("span",{className:"font-medium text-brand-500",children:ge.replyToSender}),n.jsx("span",{className:"truncate max-w-[250px]",children:ge.replyToText??"..."})]}),n.jsxs("div",{className:`mt-0.5 ${ge.sender==="agent"?"bg-surface-chat-bubble rounded-2xl px-3.5 py-2.5":""} ${ge.isError||ge.sender==="agent"&&ge.text.startsWith("⚠")?"border-b-2 border-red-500/60":""} ${rn&&ge.sender==="agent"?"streaming-bubble":""}`,children:[ge.sender==="user"?n.jsxs("div",{className:"text-sm text-fg-secondary whitespace-pre-wrap",children:[ge.images&&ge.images.length>0&&n.jsx("div",{className:"flex flex-wrap gap-1.5 mb-1",children:ge.images.map((Kt,xn)=>n.jsx("img",{src:Kt,alt:"",className:"max-w-[200px] max-h-[150px] rounded-lg object-cover cursor-pointer hover:opacity-80 transition-opacity",onClick:()=>window.open(Kt,"_blank")},xn))}),ne==="channel"?xk(ge.text,u,(Kt,xn)=>{const An=xn.currentTarget.getBoundingClientRect();q({agentId:Kt.id,top:An.bottom,left:An.left})}):ge.text&&n.jsx("span",{className:"leading-relaxed",children:xk(ge.text,u,(Kt,xn)=>{const An=xn.currentTarget.getBoundingClientRect();q({agentId:Kt.id,top:An.bottom,left:An.left})})})]}):ge.sender==="agent"&&ne==="channel"&&!(ge.segments&&ge.segments.length>0)?n.jsx(Wr,{content:ge.text,className:"text-sm text-fg-secondary",onMentionClick:Lt,knownNames:ht}):n.jsx(WG,{msg:ge,isStreaming:St,liveActivities:St?Ht:[],onViewModeChange:Kt=>$s(xn=>{const An=new Set(xn);return Kt==="full"?An.add(ge.id):An.delete(ge.id),An}),onMentionClick:Lt,knownNames:ht}),ge.isNotification&&n.jsx(qG,{priority:ge.notifyPriority})]}),Rn&&!r&&n.jsx("div",{className:`transition-opacity ${ge.isStopped||v?"opacity-100":"opacity-0 group-hover/msg:opacity-100"}`,children:n.jsx(KG,{msg:ge,onCopy:z0,onRetry:$0,onResume:B0,onReply:$o,isCopied:hn===ge.id,isLastAgentMsg:ge.id===ro})})]})]})]})},ge.id)})}),ne==="channel"&&In.length>0&&n.jsx("div",{className:"flex flex-col gap-1.5 py-2",children:In.map(ae=>n.jsxs("div",{className:"flex items-center gap-2.5 px-3 py-1.5 rounded-lg cursor-pointer hover:bg-surface-elevated/60 transition-colors group/think",onClick:()=>it(ae.id,{tab:"overview"}),children:[n.jsxs("div",{className:"relative shrink-0",children:[n.jsx(Nr,{name:ae.name,avatarUrl:ae.avatarUrl,size:28,bgClass:"bg-brand-500/15 text-brand-600"}),n.jsx("span",{className:"absolute -bottom-0.5 -right-0.5 w-2.5 h-2.5 rounded-full bg-blue-500 animate-pulse ring-2 ring-surface-primary"})]}),n.jsxs("div",{className:"flex items-center gap-1.5 min-w-0",children:[n.jsx("span",{className:"text-sm font-medium text-fg-secondary truncate",children:ae.name}),n.jsxs("span",{className:"flex items-center gap-0.5",children:[n.jsx("span",{className:"w-1 h-1 rounded-full bg-blue-400 animate-bounce"}),n.jsx("span",{className:"w-1 h-1 rounded-full bg-blue-400 animate-bounce",style:{animationDelay:"0.15s"}}),n.jsx("span",{className:"w-1 h-1 rounded-full bg-blue-400 animate-bounce",style:{animationDelay:"0.3s"}})]}),n.jsx("span",{className:"text-xs text-fg-tertiary",children:a("page.agentThinking")})]}),n.jsx("span",{className:"ml-auto text-[10px] text-fg-tertiary opacity-0 group-hover/think:opacity-100 transition-opacity",children:"→"})]},ae.id))}),n.jsx("div",{ref:Ps})]}),Qe&&I==="chat"&&n.jsxs("button",{onClick:()=>{aa.current=!0,us("smooth"),dt(!1),Rt.current=0,hr(0)},className:`absolute ${v?"bottom-4":"bottom-20"} left-1/2 -translate-x-1/2 z-10 flex items-center gap-1.5 px-3.5 py-2 bg-surface-secondary/95 backdrop-blur-sm border border-border-default rounded-full shadow-lg hover:bg-surface-elevated transition-colors text-xs text-fg-secondary`,children:[n.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:n.jsx("polyline",{points:"6 9 12 15 18 9"})}),fn>0?a("page.newMessages",{count:fn}):a("page.scrollToBottom")]})]}),H&&(()=>{const ae=u.find(Me=>Me.id===H.agentId);return ae?n.jsx(VG,{agent:ae,anchorRect:{top:H.top,left:H.left},onClose:()=>q(null),onViewProfile:it}):null})(),n.jsx("div",{className:`${v?"px-3 py-2":"px-5 py-3 2xl:pr-[280px]"} relative shrink-0 ${I!=="chat"?"hidden":""}`,onDrop:lp,onDragOver:cp,children:n.jsxs("div",{className:`bg-surface-primary border border-border-default shadow-lg shadow-black/5 ${v?"rounded-2xl p-3":"rounded-2xl p-3 max-w-3xl"}`,children:[ya&&Pi.length>0&&n.jsxs("div",{className:"absolute bottom-full left-4 mb-1 bg-surface-elevated border border-border-default rounded-lg shadow-xl overflow-hidden z-10 max-h-48 overflow-y-auto",children:[n.jsx("div",{className:"px-3 py-1.5 text-[10px] text-fg-tertiary font-medium uppercase tracking-wider border-b border-border-default",children:a("page.mentionAgent")}),Pi.map((ae,Me)=>n.jsxs("button",{ref:ge=>{Me===va&&ge&&ge.scrollIntoView({block:"nearest"})},onClick:()=>U0(ae.name),onMouseEnter:()=>Ss(Me),className:`w-full text-left px-4 py-2 text-sm flex items-center gap-2 transition-colors ${Me===va?"bg-brand-500/15 text-brand-500":"text-fg-secondary hover:bg-surface-overlay"}`,children:[n.jsx(Nr,{name:ae.name,avatarUrl:ae.avatarUrl,size:24,bgClass:"bg-brand-500/20 text-brand-500"}),n.jsx("span",{className:"flex-1 min-w-0",children:ae.name}),n.jsx("span",{className:"text-xs text-fg-tertiary ml-auto",children:ae.role})]},ae.id))]}),Dn.length>0&&n.jsxs("div",{className:"flex items-center gap-2 mb-2 overflow-x-auto pb-1",children:[Dn.map(ae=>n.jsxs("div",{className:"relative group/img shrink-0",children:[Ml(ae)?n.jsx("img",{src:ae.dataUrl,alt:ae.name,className:"w-16 h-16 rounded-lg object-cover border border-border-default"}):n.jsxs("div",{className:"w-16 h-16 rounded-lg border border-border-default bg-surface-elevated flex flex-col items-center justify-center gap-0.5",title:ae.name,children:[n.jsx("span",{className:"text-xl leading-none",children:K0(ae.name,ae.dataUrl)}),n.jsx("span",{className:"text-[9px] text-fg-tertiary truncate max-w-[56px] px-0.5",children:ae.name.split(".").pop()?.toUpperCase()})]}),n.jsx("button",{onClick:()=>W0(ae.id),className:"absolute -top-1.5 -right-1.5 w-5 h-5 bg-surface-secondary border border-gray-600 rounded-full flex items-center justify-center text-fg-secondary hover:text-red-500 hover:border-red-500 text-xs opacity-0 group-hover/img:opacity-100 transition-opacity",children:"×"})]},ae.id)),Dn.length<Hd&&n.jsx("button",{onClick:()=>Sn.current?.click(),className:"w-16 h-16 rounded-lg border border-dashed border-gray-600 flex items-center justify-center text-fg-tertiary hover:text-fg-secondary hover:border-gray-400 transition-colors shrink-0",title:a("page.addMoreFiles"),children:n.jsx("svg",{className:"w-5 h-5",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:n.jsx("path",{d:"M12 5v14M5 12h14"})})})]}),Dn.length>0&&Dn.some(ae=>Ml(ae))&&Jr&&Jr.modelSupportsVision===!1&&n.jsxs("div",{className:"text-[10px] text-amber-500/80 mb-1.5 flex items-center gap-1",children:[n.jsx("svg",{className:"w-3 h-3 shrink-0",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:n.jsx("path",{d:"M12 9v4m0 4h.01M12 2L2 22h20L12 2z",strokeLinecap:"round",strokeLinejoin:"round"})}),a("page.visionWarning")]}),n.jsx("input",{ref:Sn,type:"file",accept:"image/*,.pdf,.docx,.xlsx,.pptx,.xls,.doc,.csv,.json,.xml,.html,.epub",multiple:!0,className:"hidden",onChange:ae=>{ae.target.files&&Bo(ae.target.files),ae.target.value=""}}),Vt&&n.jsxs("div",{className:"flex items-center gap-2 mb-2 px-3 py-1.5 bg-surface-elevated rounded-lg border border-border-default/50",children:[n.jsxs("div",{className:"flex-1 min-w-0 pl-2 border-l-2 border-brand-500/50",children:[n.jsx("span",{className:"text-[11px] font-medium text-brand-500",children:Vt.sender}),n.jsx("p",{className:"text-[11px] text-fg-tertiary truncate",children:Vt.text})]}),n.jsx("button",{onClick:()=>ln(null),className:"text-fg-tertiary hover:text-fg-secondary shrink-0 p-0.5",children:n.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),n.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]}),n.jsxs("div",{className:"flex gap-2 items-end",children:[n.jsx("button",{onClick:()=>Sn.current?.click(),disabled:ne==="direct"&&!be,className:"px-2.5 py-2.5 text-fg-tertiary hover:text-fg-secondary disabled:opacity-40 transition-colors rounded-xl hover:bg-surface-elevated",title:a("page.attachFilesTitle"),children:n.jsx("svg",{className:"w-5 h-5",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:n.jsx("path",{d:"M21.44 11.05l-9.19 9.19a6 6 0 01-8.49-8.49l9.19-9.19a4 4 0 015.66 5.66l-9.2 9.19a2 2 0 01-2.83-2.83l8.49-8.48",strokeLinecap:"round",strokeLinejoin:"round"})})}),n.jsx("textarea",{ref:Bn,value:Re,onChange:ae=>{El(ae.target.value),Vn()},onKeyDown:ae=>{if(ya&&Pi.length>0){const Me=ae.key==="ArrowUp"||ae.ctrlKey&&ae.key==="p",ge=ae.key==="ArrowDown"||ae.ctrlKey&&ae.key==="n",ze=ae.key==="Enter"||ae.key==="Tab",wt=ae.key==="Escape";if(Me){ae.preventDefault(),Ss(Je=>(Je-1+Pi.length)%Pi.length);return}if(ge){ae.preventDefault(),Ss(Je=>(Je+1)%Pi.length);return}if(ze){ae.preventDefault();const Je=Pi[va];Je&&U0(Je.name);return}if(wt){ae.preventDefault(),Ls(!1);return}}ae.key==="Enter"&&!ae.shiftKey&&(ae.preventDefault(),st())},onPaste:op,placeholder:Ud,disabled:ne==="direct"&&!be,rows:2,className:"flex-1 px-4 py-3 bg-transparent rounded-xl text-sm outline-none disabled:opacity-40 transition-colors resize-none overflow-hidden leading-relaxed placeholder:text-fg-tertiary/60",style:{minHeight:"52px",maxHeight:"120px"}}),en&&ne!=="dm"&&n.jsx("button",{onClick:Ie,className:"px-3 py-2.5 bg-red-600 hover:bg-red-500 text-white text-sm rounded-xl transition-colors flex items-center gap-1.5",title:a("page.stopAgent"),children:n.jsx("svg",{className:"w-3.5 h-3.5",viewBox:"0 0 24 24",fill:"currentColor",children:n.jsx("rect",{x:"4",y:"4",width:"16",height:"16",rx:"2"})})}),n.jsx("button",{onClick:()=>{st()},disabled:ne==="direct"&&!be||!Re.trim()&&Dn.length===0,className:"px-5 py-2.5 bg-brand-600 hover:bg-brand-500 disabled:opacity-40 text-white text-sm rounded-xl transition-colors",children:a("common:send")})]})]})})]})]})}function Xk({agent:e,tasks:t,onViewProfile:r}){const{t:s}=pt(["team","common"]),[a,i]=g.useState(!1),l=g.useRef(null),d=g.useRef(null),u=e.status==="working",m=e.status==="error",h=!m&&!!e.lastError&&!!e.lastErrorAt&&Date.now()-new Date(e.lastErrorAt).getTime()<1800*1e3,p=u?t.find(C=>C.assignedAgentId===e.id&&C.status==="in_progress"):null,y=e.currentActivity;g.useEffect(()=>{if(!a)return;const C=w=>{l.current&&!l.current.contains(w.target)&&i(!1)};return document.addEventListener("mousedown",C),()=>document.removeEventListener("mousedown",C)},[a]),g.useLayoutEffect(()=>{if(!a||!d.current)return;const C=d.current,w=C.getBoundingClientRect(),N=window.innerWidth;w.right>N-8&&(C.style.left="auto",C.style.right="0"),w.left<8&&(C.style.left="0",C.style.right="auto");const S=N-16;w.width>S&&(C.style.width=`${S}px`)},[a]);const x=m?"bg-red-400 animate-pulse":h?"bg-amber-400":u?"bg-blue-400 animate-pulse":"bg-green-400",v=s(m?"common:status.error":u?"common:status.working":"common:status.idle"),j=y?y.type==="heartbeat"?s("page.activityHeartbeat",{name:y.heartbeatName??y.label}):y.type==="chat"?y.label:y.type==="task"?s("page.activityTask",{label:y.label}):y.label:s("page.processing");return n.jsxs("div",{className:"relative",ref:l,children:[n.jsxs("button",{onClick:()=>i(C=>!C),className:`flex items-center gap-1.5 px-2 py-0.5 rounded-full transition-colors ${u&&!h?"bg-blue-500/10 border border-blue-500/20 hover:bg-blue-500/20":m?"bg-red-500/10 border border-red-500/20 hover:bg-red-500/20":h?"bg-amber-500/10 border border-amber-500/20 hover:bg-amber-500/20":"bg-green-500/10 border border-green-500/20 hover:bg-green-500/20"}`,children:[n.jsx("span",{className:`w-2 h-2 rounded-full ${x}`}),n.jsx("span",{className:`text-xs ${m?"text-red-500":h?"text-amber-600":u?"text-blue-500":"text-green-600"}`,children:v}),h&&n.jsx("span",{className:"text-[9px] text-amber-500",children:"⚠"}),e.mailboxDepth!=null&&e.mailboxDepth>0&&n.jsx("span",{className:"text-[9px] bg-fg-tertiary/20 text-fg-tertiary rounded-full px-1.5",children:e.mailboxDepth})]}),a&&m&&n.jsxs("div",{ref:d,className:"absolute top-full left-0 mt-1.5 bg-surface-secondary border border-red-500/30 rounded-xl shadow-2xl z-30 w-80 max-w-[calc(100vw-1rem)] p-3 space-y-2",children:[n.jsx("p",{className:"text-[10px] text-red-500 uppercase font-semibold",children:s("page.errorDetails")}),n.jsxs("div",{className:"bg-red-500/10 border border-red-500/20 rounded-lg p-2.5",children:[n.jsx("pre",{className:"text-[10px] text-red-500/80 leading-relaxed whitespace-pre-wrap break-all font-mono line-clamp-6",children:e.lastError||s("page.agentErrorFallback")}),e.lastErrorAt&&n.jsx("div",{className:"text-[9px] text-red-500/50 mt-1.5 border-t border-red-500/10 pt-1",children:new Date(e.lastErrorAt).toLocaleString()})]}),n.jsx("button",{onClick:()=>{i(!1),r?.(e.id)},className:"w-full text-center text-[10px] text-red-500 hover:text-red-500 border border-red-500/30 hover:border-red-500/50 rounded-lg py-1 transition-colors",children:s("page.viewAgentProfileArrow")})]}),a&&h&&n.jsxs("div",{ref:d,className:"absolute top-full left-0 mt-1.5 bg-surface-secondary border border-amber-500/30 rounded-xl shadow-2xl z-30 w-80 max-w-[calc(100vw-1rem)] p-3 space-y-2",children:[n.jsx("p",{className:"text-[10px] text-amber-600 uppercase font-semibold",children:s("page.recentErrorDetails")}),n.jsxs("div",{className:"bg-amber-500/10 border border-amber-500/20 rounded-lg p-2.5",children:[n.jsx("pre",{className:"text-[10px] text-amber-600/80 leading-relaxed whitespace-pre-wrap break-all font-mono line-clamp-6",children:e.lastError}),e.lastErrorAt&&n.jsx("div",{className:"text-[9px] text-amber-500/50 mt-1.5 border-t border-amber-500/10 pt-1",children:new Date(e.lastErrorAt).toLocaleString()})]}),n.jsx("div",{className:"text-[10px] text-fg-tertiary",children:s("page.errorRecovered")})]}),a&&u&&n.jsxs("div",{ref:d,className:"absolute top-full left-0 mt-1.5 bg-surface-secondary border border-border-default rounded-xl shadow-2xl z-30 w-80 max-w-[calc(100vw-1rem)] p-3 space-y-2",children:[n.jsx("p",{className:"text-[10px] text-fg-tertiary uppercase font-semibold",children:s("page.currentActivity")}),p?n.jsxs("div",{className:"flex items-center gap-2 p-2 rounded-lg bg-brand-500/10 border border-brand-500/30 cursor-pointer hover:bg-brand-500/10 transition-colors",onClick:()=>{i(!1),bt.navigate(De.WORK,{openTask:p.id})},children:[n.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-brand-400 animate-pulse shrink-0"}),n.jsxs("div",{className:"flex-1 min-w-0",children:[n.jsx("div",{className:"text-xs text-brand-500 truncate",children:p.title}),n.jsx("div",{className:"text-[10px] text-fg-tertiary",children:s("page.workingOnTaskHint")})]}),n.jsx("span",{className:"text-[10px] text-fg-tertiary",children:"→"})]}):n.jsxs("div",{className:"flex items-center gap-2 p-2 rounded-lg bg-surface-elevated/50",children:[n.jsx("span",{className:`w-1.5 h-1.5 rounded-full shrink-0 ${y?.type==="heartbeat"||y?.type==="chat","bg-blue-400 animate-pulse"}`}),n.jsxs("div",{className:"flex-1 min-w-0",children:[n.jsx("div",{className:"text-xs text-fg-secondary",children:j}),n.jsx("div",{className:"text-[10px] text-fg-tertiary",children:y?.type==="heartbeat"?s("page.activityDescHeartbeat"):y?.type==="chat"?s("page.activityDescChat"):s("page.activityDescFallback")})]})]}),n.jsx("button",{onClick:()=>{i(!1),r?.(e.id,{tab:"overview"})},className:"w-full text-center text-[10px] text-brand-500 hover:text-brand-500 border border-border-default hover:border-gray-600 rounded-lg py-1.5 transition-colors",children:s("page.viewMindArrow")})]})]})}const eY=[{value:"system",label:"System"},{value:"light",label:"Light"},{value:"dark",label:"Dark"},{value:"cyberpunk",label:"Cyberpunk"},{value:"mono",label:"Mono"}],Jb="markus-theme";function Qk(e){const t=document.documentElement;t.classList.remove("light","dark","cyberpunk","mono"),e==="light"?t.classList.add("light"):e==="dark"?t.classList.add("dark"):e==="cyberpunk"?t.classList.add("cyberpunk"):e==="mono"&&t.classList.add("mono")}function tY(){try{const e=localStorage.getItem(Jb);if(e==="midnight")return localStorage.setItem(Jb,"dark"),"dark";if(e==="light"||e==="dark"||e==="system"||e==="cyberpunk"||e==="mono")return e}catch{}return"system"}function nY(){const[e,t]=g.useState(tY),r=g.useCallback(s=>{t(s);try{localStorage.setItem(Jb,s)}catch{}Qk(s)},[]);return g.useEffect(()=>{Qk(e)},[e]),{mode:e,setMode:r}}function rY(e){return e>=1e6?`${(e/1e6).toFixed(e%1e6===0?0:1)}M`:e>=1e3?`${(e/1e3).toFixed((e%1e3===0,0))}K`:String(e)}function Zk(e){return e===0?"-":e<.01?`$${e.toFixed(4)}`:e<1?`$${e.toFixed(2)}`:`$${e.toFixed(e%1===0?0:2)}`}function sY(e){return e.maxInputTokens>0||e.inputCostPer1MTokens>0||e.outputCostPer1MTokens>0}function dh({models:e,selectedModel:t,onSelect:r,loading:s,compact:a,maxVisible:i}){const[l,d]=g.useState(""),[u,m]=g.useState(!1),h=g.useMemo(()=>{if(!l)return e;const v=l.toLowerCase();return e.filter(j=>j.id.toLowerCase().includes(v))},[e,l]),p=i??(a?5:10),y=u?h:h.slice(0,p),x=h.length>p;return s?n.jsxs("div",{className:"flex items-center gap-2 py-4 text-sm text-fg-tertiary",children:[n.jsx("div",{className:"w-4 h-4 border-2 border-brand-500 border-t-transparent rounded-full animate-spin"}),"Loading models..."]}):e.length===0?n.jsx("div",{className:"py-3 text-sm text-fg-tertiary",children:"No models available for this provider."}):n.jsxs("div",{className:"space-y-2",children:[e.length>5&&n.jsx("input",{type:"text",value:l,onChange:v=>{d(v.target.value),m(!1)},placeholder:"Filter models...",className:"w-full px-3 py-1.5 bg-surface-overlay border border-border-default rounded-lg text-xs text-fg-primary placeholder:text-fg-tertiary focus:outline-none focus:border-brand-500"}),n.jsx("div",{className:`space-y-1 ${a?"max-h-[280px] overflow-y-auto":""}`,children:y.map(v=>{const j=v.id===t;return n.jsxs("button",{type:"button",onClick:()=>r(v.id),className:`w-full text-left px-3 py-2 rounded-lg transition-colors ${j?"bg-brand-500/10 border border-brand-500/30":"hover:bg-surface-overlay border border-transparent"}`,children:[n.jsxs("div",{className:"flex items-center justify-between",children:[n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx("div",{className:`w-3 h-3 rounded-full border-2 flex items-center justify-center ${j?"border-brand-500":"border-border-default"}`,children:j&&n.jsx("div",{className:"w-1.5 h-1.5 rounded-full bg-brand-500"})}),n.jsx("span",{className:`text-xs font-medium ${j?"text-brand-500":"text-fg-primary"}`,children:v.id})]}),j&&n.jsx("span",{className:"text-[10px] text-brand-500 font-medium",children:"Active"})]}),sY(v)&&n.jsxs("div",{className:"ml-5 mt-0.5 flex items-center gap-2 text-[10px] text-fg-tertiary flex-wrap",children:[v.maxInputTokens>0&&n.jsxs("span",{children:[rY(v.maxInputTokens)," ctx"]}),v.maxInputTokens>0&&(v.inputCostPer1MTokens>0||v.outputCostPer1MTokens>0)&&n.jsx("span",{className:"text-fg-quaternary",children:"|"}),(v.inputCostPer1MTokens>0||v.outputCostPer1MTokens>0)&&n.jsxs("span",{children:[Zk(v.inputCostPer1MTokens),"/",Zk(v.outputCostPer1MTokens)," per 1M"]})]}),!a&&n.jsxs("div",{className:"ml-5 mt-1 flex items-center gap-1.5 flex-wrap",children:[v.capabilities.functionCalling&&n.jsx(Mu,{label:"Tools"}),v.capabilities.vision&&n.jsx(Mu,{label:"Vision"}),v.capabilities.reasoning&&n.jsx(Mu,{label:"Reasoning"}),v.capabilities.promptCaching&&n.jsx(Mu,{label:"Caching"}),v.capabilities.webSearch&&n.jsx(Mu,{label:"Search"})]})]},v.id)})}),x&&!u&&n.jsxs("button",{type:"button",onClick:()=>m(!0),className:"text-xs text-brand-500 hover:text-brand-400 px-3",children:["Show all ",h.length," models..."]}),u&&x&&n.jsx("button",{type:"button",onClick:()=>m(!1),className:"text-xs text-fg-tertiary hover:text-fg-secondary px-3",children:"Show less"})]})}function Mu({label:e}){return n.jsx("span",{className:"px-1.5 py-0.5 rounded text-[9px] bg-surface-overlay text-fg-tertiary border border-border-default",children:e})}const Bu=[{id:"anthropic",label:"Anthropic",envKey:"ANTHROPIC_API_KEY",defaultModel:"claude-opus-4-6"},{id:"openai",label:"OpenAI",envKey:"OPENAI_API_KEY",defaultModel:"gpt-5.4"},{id:"google",label:"Google Gemini",envKey:"GOOGLE_API_KEY",defaultModel:"gemini-3-1-pro"},{id:"deepseek",label:"DeepSeek",envKey:"DEEPSEEK_API_KEY",baseUrl:"https://api.deepseek.com",defaultModel:"deepseek-v4-flash"},{id:"siliconflow",label:"SiliconFlow",envKey:"SILICONFLOW_API_KEY",baseUrl:"https://api.siliconflow.cn/v1",defaultModel:"Qwen/Qwen3.5-35B-A3B"},{id:"minimax",label:"MiniMax",envKey:"MINIMAX_API_KEY",baseUrl:"https://api.minimax.io/v1",defaultModel:"MiniMax-M2.7"},{id:"openrouter",label:"OpenRouter",envKey:"OPENROUTER_API_KEY",baseUrl:"https://openrouter.ai/api/v1",defaultModel:"xiaomi/mimo-v2-pro:free"},{id:"zai",label:"ZAI (GLM)",envKey:"ZAI_API_KEY",baseUrl:"https://api.z.ai/api/paas/v4",defaultModel:"glm-5.1"},{id:"xai",label:"xAI (Grok)",envKey:"XAI_API_KEY",baseUrl:"https://api.x.ai/v1",defaultModel:"grok-3"},{id:"mistral",label:"Mistral AI",envKey:"MISTRAL_API_KEY",baseUrl:"https://api.mistral.ai/v1",defaultModel:"mistral-large-latest"},{id:"groq",label:"Groq",envKey:"GROQ_API_KEY",baseUrl:"https://api.groq.com/openai/v1",defaultModel:"llama-3.3-70b-versatile"},{id:"perplexity",label:"Perplexity",envKey:"PERPLEXITY_API_KEY",baseUrl:"https://api.perplexity.ai",defaultModel:"sonar-pro"},{id:"cohere",label:"Cohere",envKey:"COHERE_API_KEY",baseUrl:"https://api.cohere.ai/compatibility/v1",defaultModel:"command-r-plus"},{id:"together_ai",label:"Together AI",envKey:"TOGETHER_API_KEY",baseUrl:"https://api.together.xyz/v1",defaultModel:"meta-llama/Llama-3.3-70B-Instruct-Turbo"},{id:"fireworks_ai",label:"Fireworks AI",envKey:"FIREWORKS_API_KEY",baseUrl:"https://api.fireworks.ai/inference/v1",defaultModel:"accounts/fireworks/models/llama-v3p3-70b-instruct"},{id:"moonshot",label:"Moonshot (Kimi)",envKey:"MOONSHOT_API_KEY",baseUrl:"https://api.moonshot.cn/v1",defaultModel:"moonshot-v1-auto"},{id:"volcengine",label:"Volcengine (Doubao)",envKey:"VOLCENGINE_API_KEY",baseUrl:"https://ark.cn-beijing.volces.com/api/v3",defaultModel:"doubao-1.5-pro-32k"},{id:"dashscope",label:"DashScope (Qwen)",envKey:"DASHSCOPE_API_KEY",baseUrl:"https://dashscope.aliyuncs.com/compatible-mode/v1",defaultModel:"qwen-max"},{id:"ollama",label:"Ollama (Local)",envKey:"OLLAMA_BASE_URL",baseUrl:"http://localhost:11434/v1",defaultModel:"llama3"}],JS=[{id:"appearance",labelKey:"nav.appearance"},{id:"providers",labelKey:"nav.providers",adminOnly:!0},{id:"execution",labelKey:"nav.execution",adminOnly:!0},{id:"browser",labelKey:"nav.browser",adminOnly:!0},{id:"search",labelKey:"nav.search",adminOnly:!0},{id:"storage",labelKey:"nav.storage",adminOnly:!0},{id:"account",labelKey:"nav.account"},{id:"remote",labelKey:"nav.remote",adminOnly:!0}],aY={users:"account",organization:"account",license:"account"};function Jk(){const t=window.location.hash.slice(1).split("/");if(t[0]==="settings"&&t[1]){const r=t[1],a=aY[r]??r;if(JS.some(i=>i.id===a))return a}return null}function ej({theme:e,onThemeChange:t,authUser:r,onLogout:s,onUserUpdated:a}={}){const{t:i,i18n:l}=pt(["settings","common"]),d=Rs(),[u,m]=g.useState(!1),[h,p]=g.useState(!1),y=g.useRef(null),[x,v]=g.useState(Jk);g.useEffect(()=>{const le=()=>v(Jk());return window.addEventListener("hashchange",le),()=>window.removeEventListener("hashchange",le)},[]);const j=g.useCallback(le=>{v(le),history.pushState(null,"",`#settings/${le}`)},[]),C=g.useCallback(()=>{v(null),history.pushState(null,"","#settings")},[]),w=x??(d?null:"appearance");g.useEffect(()=>{const le=()=>p(!0);return window.addEventListener("markus:open-edit-profile",le),()=>window.removeEventListener("markus:open-edit-profile",le)},[]),g.useEffect(()=>{if(!u)return;const le=Ie=>{y.current&&!y.current.contains(Ie.target)&&m(!1)};return document.addEventListener("mousedown",le),()=>document.removeEventListener("mousedown",le)},[u]);const[N,S]=g.useState(null),[T,E]=g.useState(null),[R,I]=g.useState(""),[z,B]=g.useState(!1),[D,V]=g.useState(null),[Y,F]=g.useState(null),[L,O]=g.useState(null),[M,$]=g.useState({}),[W,U]=g.useState(null),[H,q]=g.useState(null),[Z,_]=g.useState(!1),[J,X]=g.useState(null),[ee,te]=g.useState(null),[G,ue]=g.useState(!1),[Se,Ce]=g.useState(null),[Be,Ne]=g.useState({}),[he,_e]=g.useState(!1),[Ee,Ye]=g.useState(null),[Ze,mt]=g.useState(!1),[it,Lt]=g.useState(""),[ht,ne]=g.useState(!1),[me,be]=g.useState(null),[se,fe]=g.useState([]),[He,Ae]=g.useState([]),[et,pe]=g.useState(null),[Fe,Ve]=g.useState(null),[nt,gt]=g.useState(""),[rt,Et]=g.useState(null),je=g.useRef(null),Re=g.useRef(!1),[We,Vt]=g.useState(!1),[ln,en]=g.useState(200),[vn,In]=g.useState(!1),[Zt,cn]=g.useState(null),[Gn,Ln]=g.useState(!1),[Lr,Qr]=g.useState(1),[mr,Ge]=g.useState(!1),[Ht,Wt]=g.useState(null),[tn,zn]=g.useState(!1),[Mn,wn]=g.useState(0),[Dn,$n]=g.useState(!0),[Sn,Bn]=g.useState(!1),[Vn,Qn]=g.useState(!1),[Pe,Ct]=g.useState(9333),[ve,tt]=g.useState(!1),[Tt,$t]=g.useState(null),[sn,Zn]=g.useState(null),[Xt,ye]=g.useState({serperApiKey:"",tavilyApiKey:"",bingApiKey:"",googleSearchApiKey:"",googleSearchCx:"",serpApiKey:"",braveApiKey:"",exaApiKey:"",bochaApiKey:""}),[lt,vt]=g.useState(!1),[Bt,dn]=g.useState(null),[Dt,Pn]=g.useState(null),[tr,Hn]=g.useState(!1),[nr,On]=g.useState(new Set),[on,cr]=g.useState(null),[Fr,dr]=g.useState(!1),br=()=>({"Content-Type":"application/json",Authorization:`Bearer ${localStorage.getItem("markus_token")??""}`}),fr=g.useCallback(()=>{ie.health().then(S).catch(()=>{}),fetch("/api/settings/llm").then(le=>le.ok?le.json():Promise.reject(le.status)).then(le=>{le&&typeof le=="object"&&"providers"in le&&(E(le),I(le.defaultProvider))}).catch(()=>{})},[]),Is=g.useCallback(()=>{fetch("/api/settings/oauth/providers").then(le=>le.ok?le.json():Promise.reject(le.status)).then(le=>fe(le.providers??[])).catch(()=>{})},[]),ga=g.useCallback(()=>{fetch("/api/settings/oauth/profiles",{headers:br()}).then(le=>le.ok?le.json():Promise.reject(le.status)).then(le=>Ae(le.profiles??[])).catch(()=>{})},[]),xa=g.useCallback(()=>{ie.settings.getAgent().then(le=>{le&&typeof le.maxToolIterations=="number"&&en(le.maxToolIterations),le?.cognitive&&(Ln(le.cognitive.enabled??!1),Qr(le.cognitive.maxDepth??1))}).catch(()=>{})},[]),Pr=g.useCallback(()=>{ie.settings.getBrowser().then(le=>{le&&(zn(le.bringToFront??!1),wn(le.remoteDebuggingPort??0),$n(le.autoCloseTabs??!0),Bn(le.autoClickAllowDialog??!1),Qn(le.extensionConnected??!1),Ct(le.extensionBridgePort??9333))}).catch(()=>{})},[]),ti=g.useCallback(()=>{ie.settings.getSearch().then(le=>{le&&Zn(le)}).catch(()=>{})},[]),ba=g.useCallback(()=>{Hn(!0),ie.system.storage().then(Pn).catch(()=>{}).finally(()=>Hn(!1)),ie.system.orphans().then(cr).catch(()=>{})},[]);g.useEffect(()=>{fr(),Is(),ga(),xa(),Pr(),ti(),ba()},[fr,Is,ga,xa,Pr,ti,ba]),g.useEffect(()=>{const le=()=>ba();return window.addEventListener("markus:data-changed",le),()=>window.removeEventListener("markus:data-changed",le)},[ba]),g.useEffect(()=>{!Y||M[Y]||(U(Y),ie.modelCatalog.getLive(Y).then(le=>{$(Ie=>({...Ie,[Y]:le.models}))}).catch(()=>{ie.modelCatalog.getByProvider(Y).then(le=>{$(Ie=>({...Ie,[Y]:le.models}))}).catch(()=>{})}).finally(()=>U(null)))},[Y]);const ra=g.useCallback(async()=>{ue(!0),Ce(null),te(null),Ne({});try{const le=await fetch("/api/settings/env-models",{headers:br()});if(!le.ok){Ce({type:"err",text:i("envConfig.detectionFailedHttp",{status:le.status})});return}const Ie=await le.json();if(te(Ie),Ie.detected.length===0)Ce({type:"err",text:i("envConfig.noKeysFound")});else{const st={};for(const hn of Ie.detected)st[hn.provider]=!0;Ne(st)}}catch{Ce({type:"err",text:i("envConfig.failedToDetect")})}finally{ue(!1)}},[i]),ds=g.useCallback(async()=>{mt(!0),be(null),Ye(null);try{const le=await fetch("/api/settings/detect-ollama",{headers:br()});if(!le.ok){be({type:"err",text:i("ollama.detectFailed")});return}const Ie=await le.json();Ye(Ie),Ie.found&&Ie.models&&Ie.models.length>0?Lt(Ie.models[0].name):Ie.found||be({type:"err",text:Ie.error||i("ollama.notRunning")})}catch{be({type:"err",text:i("ollama.detectFailed")})}finally{mt(!1)}},[i]),ni=T?Object.values(T.providers).some(le=>le.configured):!1;g.useEffect(()=>{T&&!ni&&!Re.current&&(Re.current=!0,ra(),ds())},[T,ni,ra,ds]);const ri=async()=>{if(!(!R||R===T?.defaultProvider)){B(!0),V(null);try{const le=await fetch("/api/settings/llm",{method:"POST",headers:br(),body:JSON.stringify({defaultProvider:R})}),Ie=await le.json();le.ok?(E(Ie),V({type:"ok",text:i("defaultProvider.updated",{name:Ie.defaultProvider})})):V({type:"err",text:Ie.error??i("modelProviders.saveFailed")})}catch{V({type:"err",text:i("common:networkError")})}finally{B(!1)}}},za=async(le,Ie)=>{O(le);try{const st=await fetch(`/api/settings/llm/providers/${le}/toggle`,{method:"POST",headers:br(),body:JSON.stringify({enabled:Ie})});if(st.ok){const hn=await st.json();E(hn)}}catch{}finally{O(null)}},vi=async()=>{_(!0),X(null);try{const Ie=await(await fetch("/api/settings/import/openclaw",{method:"POST",headers:br(),body:JSON.stringify({preview:!0})})).json();"error"in Ie?X({type:"err",text:Ie.error}):q(Ie)}catch{X({type:"err",text:i("openClaw.detectFailed")})}finally{_(!1)}},si=async()=>{_(!0),X(null);try{const Ie=await(await fetch("/api/settings/import/openclaw",{method:"POST",headers:br(),body:JSON.stringify({preview:!1})})).json();"error"in Ie?X({type:"err",text:Ie.error}):(X({type:"ok",text:i("openClaw.importedFrom",{count:Ie.appliedModels})}),fr())}catch{X({type:"err",text:i("openClaw.importFailed")})}finally{_(!1)}},sa=async()=>{if(!ee)return;const le=ee.detected.filter(Ie=>Be[Ie.provider]);if(le.length===0){Ce({type:"err",text:i("envConfig.selectAtLeastOne")});return}_e(!0),Ce(null);try{const Ie=await fetch("/api/settings/env-models",{method:"POST",headers:br(),body:JSON.stringify({providers:le.map(hn=>({provider:hn.provider,model:hn.model,baseUrl:hn.baseUrl,enabled:!0}))})});if(!Ie.ok){Ce({type:"err",text:i("envConfig.applyFailed",{status:Ie.status})});return}const st=await Ie.json();Ce({type:"ok",text:st.message}),te(null),Ne({}),fr()}catch{Ce({type:"err",text:i("envConfig.failedToApply")})}finally{_e(!1)}},Ys=async()=>{if(!(!Ee?.found||!it)){ne(!0),be(null);try{const le=await fetch("/api/settings/llm/providers",{method:"POST",headers:br(),body:JSON.stringify({name:"ollama",model:it,baseUrl:Ee.baseUrl||"http://localhost:11434"})});if(le.ok){const Ie=await le.json();E(Ie),be({type:"ok",text:i("ollama.configured",{model:it})}),Ye(null)}else{const Ie=await le.json();be({type:"err",text:Ie.error||i("ollama.applyFailed")})}}catch{be({type:"err",text:i("ollama.applyFailed")})}finally{ne(!1)}}};g.useEffect(()=>()=>{je.current&&clearInterval(je.current)},[]),g.useEffect(()=>{if(w!=="browser"||Vn)return;const le=setInterval(async()=>{try{(await ie.settings.getBrowser()).extensionConnected&&(Qn(!0),clearInterval(le))}catch{}},5e3);return()=>clearInterval(le)},[w,Vn]);const[ya,Ls]=g.useState(!1),[Yn,Ns]=g.useState({name:"",apiKey:"",baseUrl:"",model:"",contextWindow:128e3,maxOutputTokens:16384,costInput:1,costOutput:5}),[va,Ss]=g.useState(!1),[yr,Ps]=g.useState(null),[is,qr]=g.useState([]),[ai,Cs]=g.useState(!1),[aa,$a]=g.useState(null),[Xn,Ts]=g.useState({apiKey:"",baseUrl:"",model:"",contextWindow:0,maxOutputTokens:0,costInput:0,costOutput:0}),[Os,Di]=g.useState(!1),[Or,kn]=g.useState(null),[_s,Fs]=g.useState(""),[ii,oi]=g.useState(!1),[Xs,zr]=g.useState(null),[qs,wa]=g.useState(null),[Us,Zr]=g.useState({id:"",name:"",contextWindow:128e3,maxOutputTokens:16384,costInput:1,costOutput:5,reasoning:!1,vision:!1}),[zs,ka]=g.useState(!1),Ri=async(le,Ie)=>{if(!le||le==="__custom__")return;Cs(!0),zr(null);const st=Bu.find(Cn=>Cn.id===le),hn=Yn.baseUrl||st?.baseUrl;try{if(Ie){const Cn=await ie.modelCatalog.validateKey(le,Ie,hn||void 0);!Cn.valid&&Cn.error&&zr({type:"err",text:Cn.error}),qr(Cn.models)}else{const Cn=await ie.modelCatalog.getByProvider(le);qr(Cn.models)}}catch{qr([])}finally{Cs(!1)}},ja=async()=>{if(!(!Yn.name||!Yn.model)){Ss(!0),Ps(null),zr(null);try{const le=await fetch("/api/settings/llm/providers",{method:"POST",headers:br(),body:JSON.stringify({name:Yn.name,apiKey:Yn.apiKey||void 0,baseUrl:Yn.baseUrl||void 0,model:Yn.model,contextWindow:Yn.contextWindow||void 0,maxOutputTokens:Yn.maxOutputTokens||void 0,cost:Yn.costInput||Yn.costOutput?{input:Yn.costInput,output:Yn.costOutput}:void 0})}),Ie=await le.json();le.ok?(E(Ie),Ls(!1),Fs(""),qr([]),Ns({name:"",apiKey:"",baseUrl:"",model:"",contextWindow:128e3,maxOutputTokens:16384,costInput:1,costOutput:5}),zr({type:"ok",text:i("modelProviders.providerAdded",{name:Yn.name})})):zr({type:"err",text:Ie.error??i("modelProviders.failedToAdd")})}catch{zr({type:"err",text:i("common:networkError")})}finally{Ss(!1)}}},Na=async(le,Ie)=>{if(!_s.trim())return;oi(!0),zr(null);const st=Bu.find($s=>$s.id===le),hn=st?.defaultModel??le,Cn=st?.baseUrl;try{const $s=await fetch("/api/settings/llm/providers",{method:"POST",headers:br(),body:JSON.stringify({name:le,apiKey:_s.trim(),model:hn,baseUrl:Cn})}),ro=await $s.json();$s.ok?(E(ro),Fs(""),qr([]),zr({type:"ok",text:i("modelProviders.quickSetupSuccess",{name:st?.label??le})})):zr({type:"err",text:ro.error??i("modelProviders.failedToAdd")})}catch{zr({type:"err",text:i("common:networkError")})}finally{oi(!1)}},Sa=(le,Ie)=>{$a(le),Ts({apiKey:"",baseUrl:Ie.baseUrl??"",model:Ie.model,contextWindow:Ie.contextWindow??0,maxOutputTokens:Ie.maxOutputTokens??0,costInput:Ie.cost?.input??0,costOutput:Ie.cost?.output??0})},oe=async le=>{Di(!0);try{const Ie={};Xn.apiKey&&(Ie.apiKey=Xn.apiKey),Xn.baseUrl!==void 0&&(Ie.baseUrl=Xn.baseUrl),Xn.model&&(Ie.model=Xn.model),Xn.contextWindow&&(Ie.contextWindow=Xn.contextWindow),Xn.maxOutputTokens&&(Ie.maxOutputTokens=Xn.maxOutputTokens),(Xn.costInput||Xn.costOutput)&&(Ie.cost={input:Xn.costInput,output:Xn.costOutput});const st=await fetch(`/api/settings/llm/providers/${le}`,{method:"PUT",headers:br(),body:JSON.stringify(Ie)});if(st.ok){const hn=await st.json();E(hn),$a(null)}}catch{}finally{Di(!1)}},Qe=async le=>{kn(le);try{const Ie=await fetch(`/api/settings/llm/providers/${le}`,{method:"DELETE",headers:br()});if(Ie.ok){const st=await Ie.json();E(st),I(st.defaultProvider)}}catch{}finally{kn(null)}},dt=async le=>{if(!(!Us.id||!Us.name)){ka(!0);try{const Ie=await fetch(`/api/settings/llm/providers/${le}/models`,{method:"POST",headers:br(),body:JSON.stringify({id:Us.id,name:Us.name,contextWindow:Us.contextWindow,maxOutputTokens:Us.maxOutputTokens,cost:{input:Us.costInput,output:Us.costOutput},reasoning:Us.reasoning||void 0,inputTypes:Us.vision?["text","image"]:["text"]})});if(Ie.ok){const st=await Ie.json();E(st),wa(null),Zr({id:"",name:"",contextWindow:128e3,maxOutputTokens:16384,costInput:1,costOutput:5,reasoning:!1,vision:!1})}}catch{}finally{ka(!1)}}},Rt=async(le,Ie)=>{try{const st=await fetch(`/api/settings/llm/providers/${le}/models/${encodeURIComponent(Ie)}`,{method:"DELETE",headers:br()});if(st.ok){const hn=await st.json();E(hn)}}catch{}},fn=new Set(["claude-opus-4-6","claude-sonnet-4-20250514","claude-3-5-haiku-20241022","gpt-5.4","gpt-4o","o4-mini","gemini-3-1-pro","gemini-2.5-flash","MiniMax-M2.7","MiniMax-M2.5","xiaomi/mimo-v2-pro","anthropic/claude-opus-4-6","openai/gpt-5.4","google/gemini-3-1-pro","deepseek-v4-flash","deepseek-v4-pro","deepseek-chat","deepseek-reasoner"]),[hr,un]=g.useState(null),[yt,us]=g.useState(null),[Ur,ms]=g.useState({}),os=async le=>{us(le),ms(Ie=>{const st={...Ie};return delete st[le],st});try{const Ie=await fetch(`/api/settings/llm/providers/${le}/test`,{method:"POST",headers:br()});if(!Ie.ok){const hn=await Ie.json().catch(()=>({}));ms(Cn=>({...Cn,[le]:{ok:!1,error:hn.error??`HTTP ${Ie.status}`,errorCode:Ie.status}}));return}const st=await Ie.json();ms(hn=>({...hn,[le]:st}))}catch{ms(Ie=>({...Ie,[le]:{ok:!1,error:i("common:networkError")}}))}finally{us(null)}},Vr=async(le,Ie)=>{un(`${le}:${Ie}`);try{const st=await fetch(`/api/settings/llm/providers/${le}/model`,{method:"POST",headers:br(),body:JSON.stringify({model:Ie})});if(st.ok){const hn=await st.json();E(hn)}}catch{}finally{un(null)}},fs=async()=>{if(Xt.serperApiKey||Xt.tavilyApiKey||Xt.bingApiKey||Xt.googleSearchApiKey||Xt.googleSearchCx||Xt.serpApiKey||Xt.braveApiKey||Xt.exaApiKey||Xt.bochaApiKey){vt(!0),dn(null);try{const Ie={};Xt.serperApiKey&&(Ie.serperApiKey=Xt.serperApiKey),Xt.tavilyApiKey&&(Ie.tavilyApiKey=Xt.tavilyApiKey),Xt.bingApiKey&&(Ie.bingApiKey=Xt.bingApiKey),Xt.googleSearchApiKey&&(Ie.googleSearchApiKey=Xt.googleSearchApiKey),Xt.googleSearchCx&&(Ie.googleSearchCx=Xt.googleSearchCx),Xt.serpApiKey&&(Ie.serpApiKey=Xt.serpApiKey),Xt.braveApiKey&&(Ie.braveApiKey=Xt.braveApiKey),Xt.exaApiKey&&(Ie.exaApiKey=Xt.exaApiKey),Xt.bochaApiKey&&(Ie.bochaApiKey=Xt.bochaApiKey);const st=await ie.settings.updateSearch(Ie);Zn(st),ye({serperApiKey:"",tavilyApiKey:"",bingApiKey:"",googleSearchApiKey:"",googleSearchCx:"",serpApiKey:"",braveApiKey:"",exaApiKey:"",bochaApiKey:""}),dn({type:"ok",text:i("searchApi.saved")})}catch{dn({type:"err",text:i("searchApi.failedToSave")})}finally{vt(!1)}}},jr=T?.providers?Object.entries(T.providers).filter(([,le])=>le.configured&&le.enabled).map(([le])=>le):[],to=T&&!ni&&!We,Ii=r?.role==="owner"||r?.role==="admin",no=JS.filter(le=>!le.adminOnly||Ii);return n.jsxs("div",{className:"flex-1 flex overflow-hidden",children:[h&&r&&n.jsx(dY,{authUser:r,onClose:()=>p(!1),onSaved:le=>{p(!1),a?.(le)}}),n.jsxs("aside",{className:"hidden md:flex flex-col w-56 shrink-0 border-r border-border-default bg-surface-secondary overflow-y-auto",children:[n.jsx("div",{className:"px-3 pt-4 pb-2",children:n.jsxs("button",{onClick:()=>{bt.navigate(De.HOME)},className:"flex items-center gap-2 px-2 py-1.5 rounded-lg text-sm text-fg-secondary hover:text-fg-primary hover:bg-surface-overlay transition-colors",children:[n.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("path",{d:"M19 12H5"}),n.jsx("polyline",{points:"12 19 5 12 12 5"})]}),i("common:back",{defaultValue:"Back"})]})}),n.jsx("div",{className:"px-5 pb-4",children:n.jsx("h2",{className:"text-base font-semibold text-fg-primary",children:i("title")})}),n.jsx("nav",{className:"flex-1 px-3 pb-4 space-y-0.5",children:no.map(le=>n.jsx("button",{onClick:()=>j(le.id),className:`w-full text-left px-3 py-2 rounded-lg text-sm transition-colors ${w===le.id?"bg-brand-600/10 text-brand-600 dark:text-brand-400 font-medium":"text-fg-secondary hover:text-fg-primary hover:bg-surface-overlay"}`,children:i(`settings:${le.labelKey}`)},le.id))}),r&&n.jsx("div",{className:"px-3 pb-4 border-t border-border-default pt-3",children:n.jsxs("div",{ref:y,className:"relative",children:[n.jsxs("button",{onClick:()=>m(!u),className:"w-full flex items-center gap-2.5 px-3 py-2 rounded-lg hover:bg-surface-overlay transition-colors",children:[n.jsx(Nr,{name:r.name||i("common:userPlaceholder"),avatarUrl:r.avatarUrl,size:24}),n.jsx("span",{className:"text-sm text-fg-secondary truncate flex-1 text-left",children:r.name||i("common:userPlaceholder")})]}),u&&n.jsxs("div",{className:"absolute left-0 bottom-full mb-1 bg-surface-secondary border border-border-default rounded-xl shadow-xl z-50 overflow-hidden",style:{minWidth:200},children:[n.jsxs("div",{className:"px-4 py-3 border-b border-border-default",children:[n.jsx("div",{className:"text-sm font-medium text-fg-primary",children:r.name||i("common:userPlaceholder")}),n.jsx("div",{className:"text-xs text-fg-tertiary mt-0.5",children:r.email||r.role})]}),n.jsxs("div",{className:"py-1",children:[n.jsxs("button",{onClick:()=>{m(!1),p(!0)},className:"w-full flex items-center gap-2.5 px-4 py-2 text-sm text-fg-secondary hover:bg-surface-overlay transition-colors",children:[n.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("path",{d:"M20 21v-2a4 4 0 0 0-4-4H8a4 4 0 0 0-4 4v2"}),n.jsx("circle",{cx:"12",cy:"7",r:"4"})]}),i("common:profile.editProfile")]}),s&&n.jsxs("button",{onClick:()=>{m(!1),s()},className:"w-full flex items-center gap-2.5 px-4 py-2 text-sm text-red-500 hover:bg-red-500/10 transition-colors",children:[n.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("path",{d:"M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4"}),n.jsx("polyline",{points:"16 17 21 12 16 7"}),n.jsx("line",{x1:"21",y1:"12",x2:"9",y2:"12"})]}),i("common:signOut",{defaultValue:"Sign Out"})]})]})]})]})})]}),n.jsxs("div",{className:"flex-1 overflow-y-auto",children:[d&&w===null&&n.jsxs("div",{className:"flex flex-col h-full",children:[n.jsxs("div",{className:"flex items-center gap-3 px-4 py-3 border-b border-border-default bg-surface-secondary",children:[n.jsx("button",{onClick:()=>bt.navigate(De.HOME),className:"p-1.5 rounded-lg hover:bg-surface-overlay transition-colors",children:n.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("path",{d:"M19 12H5"}),n.jsx("polyline",{points:"12 19 5 12 12 5"})]})}),n.jsx("h1",{className:"text-base font-semibold text-fg-primary",children:i("title")})]}),n.jsx("nav",{className:"flex-1 overflow-y-auto py-2 px-3",children:no.map(le=>n.jsxs("button",{onClick:()=>j(le.id),className:"w-full flex items-center justify-between px-4 py-3 rounded-lg text-sm text-fg-primary hover:bg-surface-overlay transition-colors",children:[n.jsx("span",{children:i(`settings:${le.labelKey}`)}),n.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",className:"text-fg-tertiary",children:n.jsx("polyline",{points:"9 18 15 12 9 6"})})]},le.id))})]}),d&&w!==null&&n.jsxs("div",{className:"flex items-center gap-3 px-4 py-3 border-b border-border-default bg-surface-secondary sticky top-0 z-10",children:[n.jsx("button",{onClick:C,className:"p-1.5 rounded-lg hover:bg-surface-overlay transition-colors",children:n.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("path",{d:"M19 12H5"}),n.jsx("polyline",{points:"12 19 5 12 12 5"})]})}),n.jsx("h1",{className:"text-base font-semibold text-fg-primary",children:i(`settings:${no.find(le=>le.id===w)?.labelKey||"title"}`)})]}),w!==null&&n.jsxs("div",{className:"p-7 space-y-10 max-w-4xl mx-auto w-full",children:[w==="appearance"&&n.jsx(pi,{title:i("appearance.title"),children:n.jsxs("div",{className:"bg-surface-elevated rounded-xl p-5",children:[n.jsxs("div",{className:"flex flex-col gap-3 md:flex-row md:items-center md:justify-between",children:[n.jsxs("div",{children:[n.jsx("div",{className:"text-sm font-medium",children:i("appearance.theme")}),n.jsx("div",{className:"text-xs text-fg-tertiary mt-0.5",children:i("appearance.themeDesc")})]}),n.jsx("div",{className:"flex flex-wrap gap-1 bg-surface-elevated rounded-lg p-0.5",children:eY.map(({value:le})=>n.jsx("button",{onClick:()=>t?.(le),className:`px-3 py-1.5 text-xs rounded-md transition-colors ${e===le?"bg-brand-600 text-white":"text-fg-secondary hover:text-fg-primary"}`,children:i(`appearance.modes.${le}`)},le))})]}),n.jsxs("div",{className:"flex flex-col gap-3 md:flex-row md:items-center md:justify-between mt-5 pt-5 border-t border-border-default/50",children:[n.jsxs("div",{children:[n.jsx("div",{className:"text-sm font-medium",children:i("appearance.language")}),n.jsx("div",{className:"text-xs text-fg-tertiary mt-0.5",children:i("appearance.languageDesc")})]}),n.jsx("div",{className:"flex flex-wrap gap-1 bg-surface-elevated rounded-lg p-0.5",children:fw.map(({code:le,label:Ie})=>n.jsx("button",{onClick:()=>{l.changeLanguage(le)},className:`px-3 py-1.5 text-xs rounded-md transition-colors ${l.language===le||le==="en"&&!fw.some(st=>st.code===l.language)?"bg-brand-600 text-white":"text-fg-secondary hover:text-fg-primary"}`,children:Ie},le))})]})]})}),Ii&&n.jsxs(n.Fragment,{children:[w==="providers"&&n.jsxs(n.Fragment,{children:[to&&n.jsxs("div",{className:"relative bg-gradient-to-br from-brand-500/10 to-surface-secondary border border-brand-500/20 rounded-2xl p-6 space-y-5",children:[n.jsx("button",{onClick:()=>Vt(!0),className:"absolute top-4 right-4 text-fg-tertiary hover:text-fg-secondary text-xs",children:i("setupGuide.skip")}),n.jsxs("div",{children:[n.jsx("h3",{className:"text-base font-semibold text-fg-primary",children:i("setupGuide.title")}),n.jsx("p",{className:"text-sm text-fg-secondary mt-1",children:i("setupGuide.subtitle")})]}),n.jsxs(Du,{step:i("setupGuide.fromEnv.step"),title:i("setupGuide.fromEnv.title"),description:i("setupGuide.fromEnv.description"),active:!!(ee&&ee.detected.length>0),children:[G&&n.jsx("div",{className:"text-xs text-fg-tertiary",children:i("common:detecting")}),ee&&ee.detected.length>0&&n.jsxs("div",{className:"space-y-2",children:[ee.detected.map(le=>n.jsxs("label",{className:"flex items-center gap-3 bg-surface-elevated/30 rounded-lg px-3 py-2 cursor-pointer hover:bg-surface-elevated/50 transition-colors",children:[n.jsx("input",{type:"checkbox",checked:Be[le.provider]??!1,onChange:Ie=>Ne({...Be,[le.provider]:Ie.target.checked}),className:"w-4 h-4 rounded bg-surface-overlay border-gray-600 text-brand-500 focus:ring-brand-500"}),n.jsxs("div",{className:"flex-1 min-w-0",children:[n.jsx("span",{className:"text-sm text-fg-primary",children:le.displayName}),n.jsx("span",{className:"text-xs text-fg-tertiary ml-2",children:le.model})]}),n.jsx("code",{className:"text-[10px] text-fg-tertiary",children:le.apiKeyPreview})]},le.provider)),n.jsx("button",{onClick:()=>{sa()},disabled:he||Object.values(Be).filter(Boolean).length===0,className:"w-full px-4 py-2 bg-brand-600 hover:bg-brand-500 disabled:opacity-40 text-white text-sm rounded-lg transition-colors",children:he?i("common:applying"):i("setupGuide.applyProviders",{count:Object.values(Be).filter(Boolean).length})})]}),ee&&ee.detected.length===0&&n.jsx("div",{className:"text-xs text-fg-tertiary",children:n.jsx(n0,{i18nKey:"settings:setupGuide.fromEnv.noKeysHint",components:{code:n.jsx("code",{className:"text-fg-secondary"})}})}),Se&&n.jsx(Ka,{type:Se.type,text:Se.text})]}),n.jsxs(Du,{step:i("setupGuide.fromOllama.step"),title:i("setupGuide.fromOllama.title"),description:i("setupGuide.fromOllama.description"),active:!!Ee?.found,children:[Ze&&n.jsx("div",{className:"text-xs text-fg-tertiary",children:i("common:detecting")}),Ee?.found&&Ee.models&&Ee.models.length>0&&n.jsxs("div",{className:"space-y-2",children:[n.jsx("div",{className:"text-xs text-green-600",children:i("ollama.foundModels",{count:Ee.models.length,url:Ee.baseUrl})}),n.jsx("select",{value:it,onChange:le=>Lt(le.target.value),className:"w-full px-3 py-2 bg-surface-overlay border border-border-default rounded-lg text-sm text-fg-primary focus:outline-none focus:ring-2 focus:ring-brand-500",children:Ee.models.map(le=>n.jsxs("option",{value:le.name,children:[le.name,le.parameterSize?` (${le.parameterSize})`:"",le.family?` — ${le.family}`:""]},le.name))}),n.jsx("button",{onClick:()=>{Ys()},disabled:ht||!it,className:"w-full px-4 py-2 bg-brand-600 hover:bg-brand-500 disabled:opacity-40 text-white text-sm rounded-lg transition-colors",children:ht?i("common:applying"):i("ollama.useModel",{model:it})})]}),!Ze&&!Ee&&n.jsx("button",{onClick:()=>{ds()},className:"px-4 py-2 border border-border-default hover:bg-surface-elevated text-fg-secondary text-sm rounded-lg transition-colors",children:i("ollama.detect")}),Ee&&!Ee.found&&n.jsx("div",{className:"text-xs text-fg-tertiary",children:i("ollama.notRunning")}),me&&n.jsx(Ka,{type:me.type,text:me.text})]}),n.jsxs(Du,{step:i("setupGuide.fromOpenClaw.step"),title:i("setupGuide.fromOpenClaw.title"),description:i("setupGuide.fromOpenClaw.description"),children:[H?H.found?n.jsxs("div",{className:"space-y-2",children:[n.jsxs("div",{className:"text-xs text-green-600",children:[i("setupGuide.foundPrefix")," ",n.jsx("code",{className:"text-fg-secondary",children:H.summary.configPath})]}),H.summary.models&&n.jsx("div",{className:"text-xs text-fg-secondary",children:i("openClaw.providersModels",{providers:H.summary.models.providerCount,models:H.summary.models.providers.reduce((le,Ie)=>le+Ie.modelCount,0)})}),n.jsx("button",{onClick:()=>{si()},disabled:Z,className:"w-full px-4 py-2 bg-brand-600 hover:bg-brand-500 disabled:opacity-40 text-white text-sm rounded-lg transition-colors",children:i(Z?"common:importing":"openClaw.importConfigs")})]}):n.jsx("div",{className:"text-xs text-fg-tertiary",children:i("openClaw.notFound")}):n.jsx("button",{onClick:()=>{vi()},disabled:Z,className:"px-4 py-2 border border-border-default hover:bg-surface-elevated disabled:opacity-40 text-fg-secondary text-sm rounded-lg transition-colors",children:i(Z?"common:detecting":"openClaw.detectShort")}),J&&n.jsx(Ka,{type:J.type,text:J.text})]}),n.jsx(Du,{step:i("setupGuide.manual.step"),title:i("setupGuide.manual.title"),description:n.jsx(n0,{i18nKey:"settings:setupGuide.manual.description",components:{code:n.jsx("code",{className:"text-fg-secondary"})}})}),/Chrome\/\d/.test(navigator.userAgent)&&!/Edg\//.test(navigator.userAgent)&&n.jsx(Du,{step:i("setupGuide.browserExtension.step"),title:i("setupGuide.browserExtension.title"),description:i("setupGuide.browserExtension.description"),active:Vn,children:Vn?n.jsxs("div",{className:"flex items-center gap-1.5 text-xs text-green-400",children:[n.jsx("svg",{className:"w-3.5 h-3.5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:n.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 13l4 4L19 7"})}),i("setupGuide.browserExtension.alreadyConnected")]}):n.jsxs("div",{className:"space-y-2",children:[n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsxs("button",{disabled:ve,onClick:async()=>{tt(!0);try{await ie.settings.downloadExtensionZip()}catch{}tt(!1)},className:"px-3 py-1.5 text-xs bg-brand-500 text-white rounded-lg hover:bg-brand-600 transition-colors disabled:opacity-40 inline-flex items-center gap-1.5",children:[n.jsx("svg",{className:"w-3.5 h-3.5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:n.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 16v1a3 3 0 003 3h10a3 3 0 003-3v-1m-4-4l-4 4m0 0l-4-4m4 4V4"})}),i("setupGuide.browserExtension.downloadBtn")]}),navigator.platform.toUpperCase().includes("WIN")?n.jsxs("span",{className:"px-3 py-1.5 text-xs text-fg-secondary inline-flex items-center gap-1.5",children:[i("setupGuide.browserExtension.openChromeBtn"),":",n.jsx("code",{className:"px-1.5 py-0.5 bg-surface-elevated rounded text-fg-primary font-mono text-[11px] select-all",children:"chrome://extensions"})]}):n.jsxs("button",{disabled:ve,onClick:async()=>{try{await ie.settings.openExtensionsPage()}catch{}},className:"px-3 py-1.5 text-xs border border-border-default text-fg-primary rounded-lg hover:bg-surface-elevated transition-colors disabled:opacity-40 inline-flex items-center gap-1.5",children:[n.jsx("svg",{className:"w-3.5 h-3.5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:n.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M10 6H6a2 2 0 00-2 2v10a2 2 0 002 2h10a2 2 0 002-2v-4M14 4h6m0 0v6m0-6L10 14"})}),i("setupGuide.browserExtension.openChromeBtn")]})]}),n.jsx("div",{className:"text-xs text-fg-tertiary",children:i("setupGuide.browserExtension.loadHint")})]})})]}),n.jsx(pi,{title:i("systemStatus.title"),children:N?n.jsxs("div",{className:"grid grid-cols-3 gap-4",children:[n.jsx(Kx,{label:i("systemStatus.status"),value:N.status==="ok"?i("systemStatus.healthy"):N.status,color:"green"}),n.jsx(Kx,{label:i("systemStatus.version"),value:N.version,color:"indigo"}),n.jsx(Kx,{label:i("systemStatus.activeAgents"),value:String(N.agents),color:"purple"})]}):n.jsx("div",{className:"text-sm text-fg-tertiary",children:i("common:loading")})}),n.jsx(pi,{title:i("defaultProvider.title"),children:n.jsxs("div",{className:"bg-surface-elevated rounded-xl p-5 space-y-4",children:[n.jsxs("div",{className:"flex items-center justify-between",children:[n.jsxs("div",{children:[n.jsx("div",{className:"text-sm font-medium",children:i("defaultProvider.primaryProvider")}),n.jsx("div",{className:"text-xs text-fg-tertiary mt-0.5",children:i("defaultProvider.primaryProviderDesc")})]}),n.jsxs("div",{className:"flex items-center gap-3",children:[T?n.jsx("select",{value:R,onChange:le=>{I(le.target.value),V(null)},className:"px-3 py-1.5 bg-surface-elevated border border-border-default rounded-lg text-sm w-48 focus:border-brand-500 outline-none",children:jr.length>0?jr.map(le=>n.jsx("option",{value:le,children:T.providers[le]?.displayName??le},le)):n.jsx("option",{value:"",children:i("defaultProvider.noProviders")})}):n.jsx("div",{className:"text-xs text-fg-tertiary",children:i("common:loading")}),R!==T?.defaultProvider&&n.jsx("button",{onClick:()=>{ri()},disabled:z,className:"px-3 py-1.5 text-xs bg-brand-600 hover:bg-brand-500 disabled:opacity-40 text-white rounded-lg transition-colors",children:i(z?"common:saving":"common:save")})]})]}),D&&n.jsx(Ka,{type:D.type,text:D.text}),n.jsxs("div",{className:"flex items-center justify-between border-t border-border-default pt-4",children:[n.jsxs("div",{children:[n.jsx("div",{className:"text-sm font-medium text-fg-primary",children:i("defaultProvider.autoFallback")}),n.jsx("div",{className:"text-xs text-fg-tertiary mt-0.5",children:i("defaultProvider.autoFallbackDesc")})]}),n.jsx("button",{onClick:async()=>{const le=!(T?.autoFallback??!0);try{const Ie=await fetch("/api/settings/llm",{method:"POST",headers:br(),body:JSON.stringify({autoFallback:le})});if(Ie.ok){const st=await Ie.json();E(st)}}catch{}},className:`relative inline-flex h-5 w-9 items-center rounded-full transition-colors ${T?.autoFallback??!0?"bg-green-500":"bg-gray-600"}`,children:n.jsx("span",{className:`inline-block h-3.5 w-3.5 rounded-full bg-white transition-transform ${T?.autoFallback??!0?"translate-x-4":"translate-x-1"}`})})]})]})}),n.jsxs(pi,{title:i("modelProviders.title"),children:[n.jsx("div",{className:"space-y-3",children:T&&(()=>{const le=[],Ie=new Set;for(const[st,hn]of Object.entries(T.providers))le.push([st,hn]),Ie.add(st);for(const st of Bu)Ie.has(st.id)||(le.push([st.id,{name:st.id,displayName:st.label,model:st.defaultModel,configured:!1,enabled:!1}]),Ie.add(st.id));return le})().map(([le,Ie])=>n.jsxs("div",{className:`bg-surface-secondary border rounded-xl overflow-hidden transition-colors ${Ie.configured?"border-border-default hover:border-gray-600":"border-border-default/50 hover:border-brand-500/30"}`,children:[n.jsxs("div",{className:"flex items-center justify-between px-5 py-4 cursor-pointer",onClick:()=>{F(Y===le?null:le),Fs(""),zr(null),qr([]),Ns(st=>({...st,name:"",model:""}))},children:[n.jsxs("div",{className:"flex items-center gap-3",children:[n.jsx("span",{className:`w-2 h-2 rounded-full ${Ie.configured&&Ie.enabled?"bg-green-400":Ie.configured?"bg-amber-400":"bg-gray-600"}`}),n.jsxs("div",{children:[n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx("span",{className:"text-sm font-medium",children:Ie.displayName??le}),le===T.defaultProvider&&n.jsx("span",{className:"text-[10px] bg-brand-500/15 text-brand-500 px-1.5 py-0.5 rounded",children:i("modelProviders.badgeDefault")}),Ie.configured&&!Ie.enabled&&n.jsx("span",{className:"text-[10px] bg-amber-500/15 text-amber-600 px-1.5 py-0.5 rounded",children:i("modelProviders.disabled")}),Ie.oauthConnected&&n.jsx("span",{className:"text-[10px] bg-green-500/15 text-green-600 px-1.5 py-0.5 rounded",children:i("modelProviders.badgeOAuth")}),Ur[le]?.ok===!0&&n.jsx("span",{className:"text-[10px] bg-green-500/15 text-green-600 px-1.5 py-0.5 rounded",children:i("modelProviders.testOk",{ms:Ur[le].durationMs})}),Ur[le]?.ok===!1&&n.jsx("span",{className:"text-[10px] bg-red-500/15 text-red-500 px-1.5 py-0.5 rounded",title:Ur[le].error,children:Ur[le].errorCode?i("modelProviders.testFailedCode",{code:Ur[le].errorCode}):i("modelProviders.testFailed")})]}),n.jsx("div",{className:"text-xs text-fg-tertiary mt-0.5",children:Ie.configured?n.jsxs(n.Fragment,{children:[Ie.model,Ie.apiKeyPreview&&n.jsxs(n.Fragment,{children:[" · ",n.jsx("code",{className:"text-fg-secondary",children:Ie.apiKeyPreview})]})]}):i("modelProviders.notConfigured")})]})]}),n.jsxs("div",{className:"flex items-center gap-4",children:[Ie.configured&&n.jsx("button",{onClick:st=>{st.stopPropagation(),za(le,!Ie.enabled)},disabled:L===le,className:`relative inline-flex h-5 w-9 items-center rounded-full transition-colors ${Ie.enabled?"bg-green-500":"bg-gray-600"} ${L===le?"opacity-50":""}`,title:Ie.enabled?i("modelProviders.clickToDisable"):i("modelProviders.clickToEnable"),children:n.jsx("span",{className:`inline-block h-3.5 w-3.5 rounded-full bg-white transition-transform ${Ie.enabled?"translate-x-4":"translate-x-1"}`})}),Ie.contextWindow!=null&&Ie.contextWindow>0&&n.jsx("span",{className:"text-[10px] text-fg-tertiary",children:i("modelProviders.ctxTokens",{size:(Ie.contextWindow/1e3).toFixed(0)})}),Ie.cost&&(Ie.cost.input>0||Ie.cost.output>0)&&n.jsx("span",{className:"text-[10px] text-fg-tertiary",children:i("modelProviders.costPerMillion",{input:Ie.cost.input,output:Ie.cost.output})}),n.jsx("span",{className:"text-fg-tertiary text-xs",children:Y===le?"▲":"▼"})]})]}),Y===le&&n.jsxs("div",{className:"px-5 pb-4 border-t border-border-default pt-4 space-y-4",children:[Ie.configured&&n.jsxs(n.Fragment,{children:[n.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-3",children:[n.jsx(ml,{label:i("modelProviders.model"),value:Ie.model}),n.jsx(ml,{label:i("modelProviders.contextWindow"),value:Ie.contextWindow?i("modelProviders.kTokens",{k:(Ie.contextWindow/1e3).toFixed(0)}):i("modelProviders.notApplicable")}),n.jsx(ml,{label:i("modelProviders.maxOutput"),value:Ie.maxOutputTokens?i("modelProviders.kTokens",{k:(Ie.maxOutputTokens/1e3).toFixed(0)}):i("modelProviders.notApplicable")}),n.jsx(ml,{label:i("modelProviders.baseUrlLabel"),value:Ie.baseUrl??i("modelProviders.baseUrlDisplayDefault")})]}),aa===le?n.jsxs("div",{className:"bg-surface-elevated/40 rounded-lg p-4 space-y-3",children:[n.jsx("div",{className:"text-[10px] text-fg-tertiary uppercase tracking-wider",children:i("modelProviders.editProvider")}),n.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-3",children:[n.jsxs("div",{children:[n.jsx("label",{className:"text-[10px] text-fg-tertiary uppercase block mb-1",children:i("modelProviders.apiKey")}),n.jsx("input",{type:"password",value:Xn.apiKey,onChange:st=>Ts({...Xn,apiKey:st.target.value}),placeholder:i("modelProviders.apiKeyPlaceholder"),className:"w-full px-3 py-1.5 text-xs bg-surface-primary border border-border-default rounded-lg text-fg-primary placeholder-fg-tertiary focus:border-brand-500 outline-none"})]}),n.jsxs("div",{children:[n.jsx("label",{className:"text-[10px] text-fg-tertiary uppercase block mb-1",children:i("modelProviders.baseUrl")}),n.jsx("input",{type:"text",value:Xn.baseUrl,onChange:st=>Ts({...Xn,baseUrl:st.target.value}),placeholder:i("modelProviders.baseUrlDisplayDefault"),className:"w-full px-3 py-1.5 text-xs bg-surface-primary border border-border-default rounded-lg text-fg-primary placeholder-fg-tertiary focus:border-brand-500 outline-none"})]}),n.jsxs("div",{children:[n.jsx("label",{className:"text-[10px] text-fg-tertiary uppercase block mb-1",children:i("modelProviders.model")}),n.jsx("input",{type:"text",value:Xn.model,onChange:st=>Ts({...Xn,model:st.target.value}),className:"w-full px-3 py-1.5 text-xs bg-surface-primary border border-border-default rounded-lg text-fg-primary focus:border-brand-500 outline-none"})]})]}),n.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-3",children:[n.jsxs("div",{children:[n.jsx("label",{className:"text-[10px] text-fg-tertiary uppercase block mb-1",children:i("modelProviders.contextWindow")}),n.jsx("input",{type:"number",value:Xn.contextWindow||"",onChange:st=>Ts({...Xn,contextWindow:Number(st.target.value)}),placeholder:i("modelProviders.placeholderContextExample"),className:"w-full px-3 py-1.5 text-xs bg-surface-primary border border-border-default rounded-lg text-fg-primary placeholder-fg-tertiary focus:border-brand-500 outline-none"})]}),n.jsxs("div",{children:[n.jsx("label",{className:"text-[10px] text-fg-tertiary uppercase block mb-1",children:i("modelProviders.maxOutputTokens")}),n.jsx("input",{type:"number",value:Xn.maxOutputTokens||"",onChange:st=>Ts({...Xn,maxOutputTokens:Number(st.target.value)}),placeholder:i("modelProviders.placeholderMaxOutputExample"),className:"w-full px-3 py-1.5 text-xs bg-surface-primary border border-border-default rounded-lg text-fg-primary placeholder-fg-tertiary focus:border-brand-500 outline-none"})]}),n.jsxs("div",{children:[n.jsx("label",{className:"text-[10px] text-fg-tertiary uppercase block mb-1",children:i("modelProviders.inputCost")}),n.jsx("input",{type:"number",step:"0.01",value:Xn.costInput||"",onChange:st=>Ts({...Xn,costInput:Number(st.target.value)}),placeholder:i("modelProviders.placeholderCostInput"),className:"w-full px-3 py-1.5 text-xs bg-surface-primary border border-border-default rounded-lg text-fg-primary placeholder-fg-tertiary focus:border-brand-500 outline-none"})]}),n.jsxs("div",{children:[n.jsx("label",{className:"text-[10px] text-fg-tertiary uppercase block mb-1",children:i("modelProviders.outputCost")}),n.jsx("input",{type:"number",step:"0.01",value:Xn.costOutput||"",onChange:st=>Ts({...Xn,costOutput:Number(st.target.value)}),placeholder:i("modelProviders.placeholderCostOutput"),className:"w-full px-3 py-1.5 text-xs bg-surface-primary border border-border-default rounded-lg text-fg-primary placeholder-fg-tertiary focus:border-brand-500 outline-none"})]})]}),n.jsxs("div",{className:"flex gap-2",children:[n.jsx("button",{onClick:()=>{oe(le)},disabled:Os,className:"px-3 py-1.5 text-xs bg-brand-600 hover:bg-brand-500 disabled:opacity-40 text-white rounded-lg transition-colors",children:i(Os?"common:saving":"common:save")}),n.jsx("button",{onClick:()=>$a(null),className:"px-3 py-1.5 text-xs border border-border-default text-fg-secondary hover:bg-surface-elevated rounded-lg transition-colors",children:i("common:cancel")})]})]}):n.jsxs("div",{className:"flex gap-2",children:[n.jsx("button",{onClick:st=>{st.stopPropagation(),os(le)},disabled:yt===le,className:"px-3 py-1.5 text-xs border border-green-500/30 text-green-500 hover:bg-green-500/10 rounded-lg transition-colors disabled:opacity-40 flex items-center gap-1.5",children:yt===le?n.jsxs(n.Fragment,{children:[n.jsxs("svg",{className:"w-3 h-3 animate-spin",fill:"none",viewBox:"0 0 24 24",children:[n.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),n.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8v4a4 4 0 00-4 4H4z"})]}),i("modelProviders.testing")]}):i("modelProviders.test")}),n.jsx("button",{onClick:st=>{st.stopPropagation(),Sa(le,Ie)},className:"px-3 py-1.5 text-xs border border-border-default text-fg-secondary hover:bg-surface-elevated rounded-lg transition-colors",children:i("common:edit")}),n.jsx("button",{onClick:st=>{st.stopPropagation(),confirm(i("modelProviders.deleteConfirm",{name:Ie.displayName??le}))&&Qe(le)},disabled:Or===le,className:"px-3 py-1.5 text-xs border border-red-500/30 text-red-400 hover:bg-red-500/10 rounded-lg transition-colors disabled:opacity-40",children:i(Or===le?"common:deleting":"common:delete")})]}),Ur[le]&&n.jsx("div",{className:`text-xs px-3 py-2 rounded-lg ${Ur[le].ok?"bg-green-500/10 text-green-600 border border-green-500/30":"bg-red-500/10 text-red-500 border border-red-500/30"}`,children:Ur[le].ok?i("modelProviders.testSuccess",{ms:Ur[le].durationMs,reply:Ur[le].reply}):Ur[le].error})]}),Ie.cost&&n.jsxs("div",{className:"bg-surface-elevated/40 rounded-lg p-3",children:[n.jsx("div",{className:"text-[10px] text-fg-tertiary uppercase tracking-wider mb-2",children:i("modelProviders.pricingTitle")}),n.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-3",children:[n.jsx(ml,{label:i("modelProviders.input"),value:`$${Ie.cost.input}`}),n.jsx(ml,{label:i("modelProviders.output"),value:`$${Ie.cost.output}`}),Ie.cost.cacheRead!=null&&n.jsx(ml,{label:i("modelProviders.cacheRead"),value:`$${Ie.cost.cacheRead}`}),Ie.cost.cacheWrite!=null&&n.jsx(ml,{label:i("modelProviders.cacheWrite"),value:`$${Ie.cost.cacheWrite}`})]})]}),n.jsxs("div",{children:[n.jsxs("div",{className:"flex items-center justify-between mb-2",children:[n.jsx("div",{className:"text-[10px] text-fg-tertiary uppercase tracking-wider",children:i("modelProviders.availableModels")}),Ie.configured&&qs!==le&&n.jsx("button",{onClick:()=>{wa(le),Zr({id:"",name:"",contextWindow:128e3,maxOutputTokens:16384,costInput:1,costOutput:5,reasoning:!1,vision:!1})},className:"text-[10px] text-brand-500 hover:text-brand-400 transition-colors",children:i("modelProviders.addModel")})]}),qs===le&&n.jsx("div",{className:"bg-surface-elevated/40 rounded-lg p-3 mb-2 space-y-2",children:n.jsx(lY,{providerName:le,addModelForm:Us,setAddModelForm:Zr,addModelSaving:zs,onAdd:()=>{dt(le)},onCancel:()=>wa(null),t:i})}),Ie.models&&Ie.models.length>0&&n.jsx("div",{className:"space-y-1.5",children:Ie.models.map(st=>{const hn=st.id===Ie.model,Cn=hr===`${le}:${st.id}`,$s=!fn.has(st.id);return n.jsxs("div",{className:`flex items-center justify-between px-3 py-2 rounded-lg text-xs transition-colors ${hn?"bg-brand-500/15 border border-brand-500/30":Ie.configured?"bg-surface-elevated/30 hover:bg-surface-elevated/60 cursor-pointer":"bg-surface-elevated/30"}`,onClick:()=>{!hn&&Ie.configured&&!Cn&&Vr(le,st.id)},children:[n.jsxs("div",{className:"flex items-center gap-2",children:[hn&&n.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-brand-500 shrink-0"}),n.jsx("span",{className:hn?"text-brand-500 font-medium":"text-fg-secondary",children:st.name}),st.reasoning&&n.jsx("span",{className:"text-[9px] bg-amber-500/15 text-amber-600 px-1 py-0.5 rounded",children:i("modelProviders.reasoning")}),st.inputTypes?.includes("image")&&n.jsx("span",{className:"text-[9px] bg-blue-500/15 text-blue-600 px-1 py-0.5 rounded",children:i("modelProviders.vision")}),$s&&n.jsx("span",{className:"text-[9px] bg-purple-500/15 text-purple-400 px-1 py-0.5 rounded",children:i("modelProviders.custom")})]}),n.jsxs("div",{className:"flex items-center gap-3 text-fg-tertiary",children:[st.contextWindow>0&&n.jsx("span",{children:i("modelProviders.ctxTokens",{size:(st.contextWindow/1e3).toFixed(0)})}),(st.cost.input>0||st.cost.output>0)&&n.jsx("span",{children:i("modelProviders.costPair",{input:st.cost.input,output:st.cost.output})}),Ie.configured&&!hn&&n.jsx("span",{className:`text-[9px] px-1.5 py-0.5 rounded transition-colors ${Cn?"bg-brand-500/30 text-brand-400":"bg-surface-overlay text-fg-tertiary hover:bg-brand-500/20 hover:text-brand-500"}`,children:i(Cn?"modelProviders.switching":"modelProviders.use")}),hn&&n.jsx("span",{className:"text-[9px] bg-brand-500/15 text-brand-500 px-1.5 py-0.5 rounded",children:i("modelProviders.active")}),$s&&!hn&&n.jsx("button",{onClick:ro=>{ro.stopPropagation(),Rt(le,st.id)},className:"text-red-400 hover:text-red-300 transition-colors",title:i("modelProviders.deleteCustomModelTitle"),children:n.jsx("svg",{className:"w-3 h-3",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:n.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]})]},st.id)})}),Ie.configured&&W===le&&n.jsxs("div",{className:"flex items-center gap-2 mt-2 text-xs text-fg-tertiary",children:[n.jsx("div",{className:"w-3 h-3 border-2 border-brand-500 border-t-transparent rounded-full animate-spin"}),i("modelProviders.loadingCatalog")]}),Ie.configured&&M[le]&&M[le].length>0&&(()=>{const st=new Set(Ie.models?.map(Cn=>Cn.id)??[]),hn=M[le].filter(Cn=>!st.has(Cn.id));return hn.length===0?null:n.jsxs("details",{className:"mt-2 group",children:[n.jsx("summary",{className:"text-[10px] text-fg-tertiary cursor-pointer hover:text-fg-secondary select-none",children:i("modelProviders.moreCatalogModels",{count:hn.length})}),n.jsx("div",{className:"mt-1.5 space-y-1",children:hn.map(Cn=>{const $s=hr===`${le}:${Cn.id}`;return n.jsxs("div",{onClick:()=>{$s||Vr(le,Cn.id)},className:"flex items-center justify-between px-3 py-1.5 rounded-lg text-xs bg-surface-elevated/20 hover:bg-surface-elevated/50 cursor-pointer transition-colors",children:[n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx("span",{className:"text-fg-secondary",children:Cn.id}),Cn.capabilities.reasoning&&n.jsx("span",{className:"text-[9px] bg-amber-500/15 text-amber-600 px-1 py-0.5 rounded",children:i("modelProviders.reasoning")}),Cn.capabilities.vision&&n.jsx("span",{className:"text-[9px] bg-blue-500/15 text-blue-600 px-1 py-0.5 rounded",children:i("modelProviders.vision")})]}),n.jsxs("div",{className:"flex items-center gap-3 text-fg-tertiary",children:[Cn.maxInputTokens>0&&n.jsxs("span",{children:[Math.round(Cn.maxInputTokens/1e3),"K ctx"]}),(Cn.inputCostPer1MTokens>0||Cn.outputCostPer1MTokens>0)&&n.jsxs("span",{children:["$",Cn.inputCostPer1MTokens,"/",Cn.outputCostPer1MTokens]}),n.jsx("span",{className:`text-[9px] px-1.5 py-0.5 rounded transition-colors ${$s?"bg-brand-500/30 text-brand-400":"bg-surface-overlay text-fg-tertiary hover:bg-brand-500/20 hover:text-brand-500"}`,children:i($s?"modelProviders.switching":"modelProviders.use")})]})]},Cn.id)})})]})})()]}),!Ie.configured&&n.jsxs("div",{className:"space-y-3",children:[n.jsx("div",{className:"text-xs text-fg-secondary",children:i("modelProviders.quickSetupHint")}),n.jsxs("div",{children:[n.jsx("label",{className:"text-[10px] text-fg-tertiary uppercase block mb-1",children:i("modelProviders.apiKey")}),n.jsx("input",{type:"password",value:Y===le?_s:"",onChange:st=>Fs(st.target.value),placeholder:i("modelProviders.quickSetupPlaceholder"),className:"w-full px-3 py-2 text-sm bg-surface-elevated border border-border-default rounded-lg text-fg-primary placeholder-fg-tertiary focus:border-brand-500 outline-none",onBlur:()=>{_s.trim().length>=8&&Y===le&&Ri(le,_s.trim())},onKeyDown:st=>{st.key==="Enter"&&_s.trim().length>=8&&Ri(le,_s.trim())}}),ai&&Y===le&&n.jsxs("div",{className:"flex items-center gap-2 mt-1.5 text-xs text-fg-tertiary",children:[n.jsx("div",{className:"w-3 h-3 border-2 border-brand-500 border-t-transparent rounded-full animate-spin"}),i("modelProviders.validatingKey")]})]}),Y===le&&is.length>0&&n.jsxs("div",{children:[n.jsx("label",{className:"text-[10px] text-fg-tertiary uppercase block mb-2",children:i("modelProviders.selectModel")}),n.jsx(dh,{provider:le,models:is,selectedModel:Yn.model,onSelect:st=>{const hn=is.find(Cn=>Cn.id===st);Ns(Cn=>({...Cn,name:le,model:st,apiKey:_s.trim(),baseUrl:Bu.find($s=>$s.id===le)?.baseUrl??"",contextWindow:hn?.maxInputTokens??Cn.contextWindow,maxOutputTokens:hn?.maxOutputTokens??Cn.maxOutputTokens,costInput:hn?.inputCostPer1MTokens??Cn.costInput,costOutput:hn?.outputCostPer1MTokens??Cn.costOutput}))},compact:!0,maxVisible:8})]}),Y===le&&_s.trim()&&n.jsx("button",{onClick:()=>{Yn.model&&Yn.name===le?ja():Na(le)},disabled:ii||va,className:"px-4 py-2 text-sm bg-brand-600 hover:bg-brand-500 disabled:opacity-40 text-white rounded-lg transition-colors",children:i(ii||va?"modelProviders.quickSetupSaving":"modelProviders.quickSetupSubmit")}),Xs&&Y===le&&n.jsx(Ka,{type:Xs.type,text:Xs.text})]})]})]},le))}),ya?n.jsxs("div",{className:"mt-3 bg-surface-secondary border border-brand-500/30 rounded-xl p-4 space-y-3",children:[n.jsx("div",{className:"text-xs font-medium text-fg-primary",children:i("modelProviders.customProvider")}),n.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-3",children:[n.jsxs("div",{children:[n.jsx("label",{className:"text-[10px] text-fg-tertiary uppercase block mb-1",children:i("modelProviders.providerName")}),n.jsx("input",{type:"text",value:Yn.name==="__custom__"?"":Yn.name,onChange:le=>Ns(Ie=>({...Ie,name:le.target.value||"__custom__"})),placeholder:"my-provider",className:"w-full px-3 py-2 text-sm bg-surface-elevated border border-border-default rounded-lg text-fg-primary placeholder-fg-tertiary focus:border-brand-500 outline-none"})]}),n.jsxs("div",{children:[n.jsx("label",{className:"text-[10px] text-fg-tertiary uppercase block mb-1",children:i("modelProviders.baseUrl")}),n.jsx("input",{type:"text",value:Yn.baseUrl,onChange:le=>Ns({...Yn,baseUrl:le.target.value}),placeholder:"https://api.example.com/v1",className:"w-full px-3 py-2 text-sm bg-surface-elevated border border-border-default rounded-lg text-fg-primary placeholder-fg-tertiary focus:border-brand-500 outline-none"})]})]}),n.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-3",children:[n.jsxs("div",{children:[n.jsx("label",{className:"text-[10px] text-fg-tertiary uppercase block mb-1",children:i("modelProviders.apiKey")}),n.jsx("input",{type:"password",value:Yn.apiKey,onChange:le=>Ns({...Yn,apiKey:le.target.value}),placeholder:i("modelProviders.placeholderApiKeySk"),className:"w-full px-3 py-2 text-sm bg-surface-elevated border border-border-default rounded-lg text-fg-primary placeholder-fg-tertiary focus:border-brand-500 outline-none"})]}),n.jsxs("div",{children:[n.jsx("label",{className:"text-[10px] text-fg-tertiary uppercase block mb-1",children:i("modelProviders.defaultModel")}),n.jsx("input",{type:"text",value:Yn.model,onChange:le=>Ns({...Yn,model:le.target.value}),placeholder:"gpt-4o",className:"w-full px-3 py-2 text-sm bg-surface-elevated border border-border-default rounded-lg text-fg-primary placeholder-fg-tertiary focus:border-brand-500 outline-none"})]})]}),n.jsxs("div",{className:"flex gap-2",children:[n.jsx("button",{onClick:()=>{ja()},disabled:va||!Yn.name||Yn.name==="__custom__"||!Yn.model,className:"px-4 py-2 text-sm bg-brand-600 hover:bg-brand-500 disabled:opacity-40 text-white rounded-lg transition-colors",children:i(va?"modelProviders.adding":"modelProviders.addProviderSubmit")}),n.jsx("button",{onClick:()=>{Ls(!1),Ps(null),qr([]),Ns({name:"",apiKey:"",baseUrl:"",model:"",contextWindow:128e3,maxOutputTokens:16384,costInput:1,costOutput:5})},className:"px-4 py-2 text-sm border border-border-default text-fg-secondary hover:bg-surface-elevated rounded-lg transition-colors",children:i("common:cancel")})]}),yr&&n.jsx(Ka,{type:yr.type,text:yr.text})]}):n.jsxs("button",{onClick:()=>Ls(!0),className:"w-full mt-3 px-4 py-2.5 border border-dashed border-border-default hover:border-brand-500/50 hover:bg-brand-500/5 rounded-xl text-xs text-fg-tertiary hover:text-brand-500 transition-colors",children:["+ ",i("modelProviders.customProvider")]})]}),n.jsx("div",{className:"border-t border-border-default"}),n.jsx(pi,{title:i("autoDetect.title"),children:n.jsxs("div",{className:"bg-surface-elevated rounded-xl p-5 space-y-5",children:[n.jsx("div",{className:"text-sm text-fg-secondary",children:i("autoDetect.description")}),n.jsxs("div",{className:"space-y-3",children:[n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx("h4",{className:"text-xs font-semibold text-fg-secondary uppercase tracking-wider",children:i("envConfig.title")}),n.jsxs("button",{onClick:()=>{ra()},disabled:G,className:"px-3 py-1 border border-border-default hover:bg-surface-elevated disabled:opacity-40 text-fg-tertiary text-xs rounded-md transition-colors flex items-center gap-1.5",children:[n.jsx("svg",{className:`w-3.5 h-3.5 ${G?"animate-spin":""}`,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:n.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"})}),i(G?"common:detecting":"envConfig.refreshEnv")]})]}),ee&&ee.detected.length>0&&n.jsxs("div",{className:"space-y-2",children:[ee.detected.map(le=>n.jsxs("label",{className:"flex items-center justify-between bg-surface-elevated/30 rounded-lg px-4 py-3 cursor-pointer hover:bg-surface-elevated/50 transition-colors",children:[n.jsxs("div",{className:"flex items-center gap-3",children:[n.jsx("input",{type:"checkbox",checked:Be[le.provider]??!1,onChange:Ie=>Ne({...Be,[le.provider]:Ie.target.checked}),className:"w-4 h-4 rounded bg-surface-overlay border-gray-600 text-brand-500 focus:ring-brand-500"}),n.jsxs("div",{children:[n.jsx("div",{className:"text-sm text-fg-primary font-medium",children:le.displayName}),n.jsxs("div",{className:"text-xs text-fg-tertiary mt-0.5",children:[i("envConfig.keyLabel")," ",n.jsx("code",{className:"text-fg-secondary",children:le.apiKeyPreview})," / ",i("envConfig.modelLabel")," ",n.jsx("code",{className:"text-fg-secondary",children:le.model}),le.baseUrl&&n.jsxs(n.Fragment,{children:[" / ",i("envConfig.urlLabel")," ",n.jsx("code",{className:"text-fg-secondary",children:le.baseUrl})]})]})]})]}),n.jsx("div",{className:"text-xs text-fg-tertiary",children:Object.keys(le.envVars).map(Ie=>n.jsx("div",{children:n.jsx("code",{children:Ie})},Ie))})]},le.provider)),ee.timeoutMs&&n.jsx("div",{className:"text-xs text-fg-tertiary",children:i("envConfig.llmTimeout",{ms:ee.timeoutMs})}),n.jsx("button",{onClick:()=>{sa()},disabled:he||Object.values(Be).filter(Boolean).length===0,className:"px-4 py-2 bg-brand-600 hover:bg-brand-500 disabled:opacity-40 text-white text-sm rounded-lg transition-colors",children:he?i("common:applying"):i("envConfig.applyToConfig",{count:Object.values(Be).filter(Boolean).length})})]}),Se&&n.jsx(Ka,{type:Se.type,text:Se.text})]}),n.jsx("div",{className:"border-t border-border-default"}),n.jsxs("div",{className:"space-y-3",children:[n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx("h4",{className:"text-xs font-semibold text-fg-secondary uppercase tracking-wider",children:i("ollama.title")}),n.jsxs("button",{onClick:()=>{ds()},disabled:Ze,className:"px-3 py-1 border border-border-default hover:bg-surface-elevated disabled:opacity-40 text-fg-tertiary text-xs rounded-md transition-colors flex items-center gap-1.5",children:[n.jsx("svg",{className:`w-3.5 h-3.5 ${Ze?"animate-spin":""}`,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:n.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"})}),i(Ze?"common:detecting":"ollama.detect")]})]}),Ee?.found&&Ee.models&&Ee.models.length>0&&n.jsxs("div",{className:"space-y-2",children:[n.jsx("div",{className:"text-xs text-green-600",children:i("ollama.foundModels",{count:Ee.models.length,url:Ee.baseUrl})}),n.jsx("div",{className:"space-y-1",children:Ee.models.map(le=>n.jsx("label",{className:`flex items-center justify-between rounded-lg px-4 py-3 cursor-pointer transition-colors ${it===le.name?"bg-brand-500/15 border border-brand-500/40":"bg-surface-elevated/30 hover:bg-surface-elevated/50"}`,children:n.jsxs("div",{className:"flex items-center gap-3",children:[n.jsx("input",{type:"radio",name:"ollama-model",value:le.name,checked:it===le.name,onChange:()=>Lt(le.name),className:"w-4 h-4 text-brand-500 focus:ring-brand-500"}),n.jsxs("div",{children:[n.jsx("div",{className:"text-sm text-fg-primary font-medium",children:le.name}),n.jsxs("div",{className:"text-xs text-fg-tertiary mt-0.5",children:[le.parameterSize&&n.jsx("span",{children:le.parameterSize}),le.family&&n.jsx("span",{className:"ml-2",children:le.family}),le.quantization&&n.jsx("span",{className:"ml-2",children:le.quantization}),le.size&&n.jsx("span",{className:"ml-2",children:nd(le.size)})]})]})]})},le.name))}),n.jsx("button",{onClick:()=>{Ys()},disabled:ht||!it,className:"px-4 py-2 bg-brand-600 hover:bg-brand-500 disabled:opacity-40 text-white text-sm rounded-lg transition-colors",children:ht?i("common:applying"):i("ollama.useModel",{model:it})})]}),Ee&&!Ee.found&&n.jsx("div",{className:"text-xs text-fg-tertiary",children:Ee.error||i("ollama.notRunning")}),me&&n.jsx(Ka,{type:me.type,text:me.text})]}),n.jsx("div",{className:"border-t border-border-default"}),n.jsxs("div",{className:"space-y-3",children:[n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx("h4",{className:"text-xs font-semibold text-fg-secondary uppercase tracking-wider",children:i("openClaw.title")}),n.jsx("button",{onClick:()=>{vi()},disabled:Z,className:"px-3 py-1 border border-border-default hover:bg-surface-elevated disabled:opacity-40 text-fg-tertiary text-xs rounded-md transition-colors flex items-center gap-1.5",children:i(Z?"common:detecting":"openClaw.detectShort")})]}),H&&H.found&&n.jsxs("div",{className:"space-y-2",children:[n.jsxs("div",{className:"text-xs text-green-600",children:[i("openClaw.foundAt")," ",n.jsx("code",{className:"text-fg-secondary",children:H.summary.configPath})]}),H.summary.models&&n.jsxs("div",{className:"bg-surface-elevated/30 rounded-lg p-3",children:[n.jsx("div",{className:"text-xs text-fg-tertiary mb-2",children:i("openClaw.modelProvidersFound",{count:H.summary.models.providerCount})}),n.jsx("div",{className:"space-y-1",children:H.summary.models.providers.map(le=>n.jsxs("div",{className:"flex items-center justify-between text-xs",children:[n.jsx("span",{className:"text-fg-secondary",children:le.name}),n.jsxs("span",{className:"text-fg-tertiary",children:[i("openClaw.modelsCountSuffix",{count:le.modelCount}),le.baseUrl?i("openClaw.withBaseUrl",{url:le.baseUrl}):""]})]},le.name))})]}),H.summary.channels&&H.summary.channels.length>0&&n.jsx("div",{className:"bg-surface-elevated/30 rounded-lg p-3",children:n.jsxs("div",{className:"text-xs text-fg-tertiary mb-1",children:[i("openClaw.channelsPrefix")," ",H.summary.channels.join(", ")]})}),n.jsx("button",{onClick:()=>{si()},disabled:Z,className:"px-4 py-2 bg-brand-600 hover:bg-brand-500 disabled:opacity-40 text-white text-sm rounded-lg transition-colors",children:i(Z?"common:importing":"openClaw.importConfigs")})]}),J&&n.jsx(Ka,{type:J.type,text:J.text})]})]})})]}),w==="execution"&&n.jsxs(n.Fragment,{children:[n.jsx(pi,{title:i("agentExecution.title"),children:n.jsxs("div",{className:"bg-surface-elevated rounded-xl p-5 space-y-4",children:[n.jsxs("div",{className:"flex items-center justify-between",children:[n.jsxs("div",{children:[n.jsx("div",{className:"text-sm font-medium text-fg-primary",children:i("agentExecution.maxToolIterations")}),n.jsx("div",{className:"text-xs text-fg-tertiary mt-0.5",children:i("agentExecution.maxToolIterationsDesc")})]}),n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx("input",{type:"number",min:0,value:ln,onChange:le=>{en(Number(le.target.value)),cn(null)},className:"w-24 px-3 py-1.5 text-sm border border-border-default rounded-lg bg-surface-primary text-fg-primary text-right"}),n.jsx("button",{disabled:vn,onClick:async()=>{In(!0),cn(null);try{const le=await ie.settings.updateAgent({maxToolIterations:ln});en(le.maxToolIterations),cn({type:"ok",text:i("agentExecution.saved")})}catch{cn({type:"err",text:i("agentExecution.failedToSave")})}In(!1)},className:"px-3 py-1.5 text-xs bg-brand-500 text-white rounded-lg hover:bg-brand-600 transition-colors disabled:opacity-40",children:i(vn?"common:saving":"common:save")})]})]}),Zt&&n.jsx(Ka,{type:Zt.type,text:Zt.text})]})}),n.jsx(pi,{title:i("cognitive.title"),children:n.jsxs("div",{className:"bg-surface-elevated rounded-xl p-5 space-y-4",children:[n.jsx("div",{className:"text-xs text-fg-tertiary",children:i("cognitive.description")}),n.jsxs("div",{className:"flex items-center justify-between",children:[n.jsxs("div",{children:[n.jsx("div",{className:"text-sm font-medium text-fg-primary",children:i("cognitive.enabled")}),n.jsx("div",{className:"text-xs text-fg-tertiary mt-0.5",children:i("cognitive.enabledDesc")})]}),n.jsx("button",{onClick:()=>{Ln(!Gn),Wt(null)},className:`relative w-10 h-5 rounded-full transition-colors ${Gn?"bg-brand-500":"bg-fg-quaternary"}`,children:n.jsx("span",{className:`absolute top-0.5 left-0.5 w-4 h-4 bg-white rounded-full shadow transition-transform ${Gn?"translate-x-5":""}`})})]}),n.jsxs("div",{className:"flex items-center justify-between",children:[n.jsxs("div",{children:[n.jsx("div",{className:"text-sm font-medium text-fg-primary",children:i("cognitive.maxDepth")}),n.jsx("div",{className:"text-xs text-fg-tertiary mt-0.5",children:i("cognitive.maxDepthDesc")})]}),n.jsxs("select",{value:Lr,onChange:le=>{Qr(Number(le.target.value)),Wt(null)},className:"px-3 py-1.5 text-sm border border-border-default rounded-lg bg-surface-primary text-fg-primary",children:[n.jsxs("option",{value:1,children:["D1 — ",i("cognitive.depthD1")]}),n.jsxs("option",{value:2,children:["D2 — ",i("cognitive.depthD2")]}),n.jsxs("option",{value:3,children:["D3 — ",i("cognitive.depthD3")]})]})]}),n.jsx("div",{className:"flex items-center justify-end gap-2",children:n.jsx("button",{disabled:mr,onClick:async()=>{Ge(!0),Wt(null);try{const le=await ie.settings.updateAgent({cognitive:{enabled:Gn,maxDepth:Lr}});Ln(le.cognitive.enabled),Qr(le.cognitive.maxDepth??1),Wt({type:"ok",text:i("cognitive.saved")})}catch{Wt({type:"err",text:i("cognitive.failedToSave")})}Ge(!1)},className:"px-3 py-1.5 text-xs bg-brand-500 text-white rounded-lg hover:bg-brand-600 transition-colors disabled:opacity-40",children:i(mr?"common:saving":"common:save")})}),Ht&&n.jsx(Ka,{type:Ht.type,text:Ht.text})]})})]}),w==="browser"&&n.jsxs(n.Fragment,{children:[n.jsxs(pi,{title:i("browserAutomation.title"),children:[n.jsxs("div",{className:`rounded-xl p-4 mb-4 flex items-start gap-3 ${Vn?"bg-green-500/10 border border-green-500/20":Mn>0?"bg-blue-500/10 border border-blue-500/20":Sn?"bg-amber-500/10 border border-amber-500/20":"bg-surface-elevated border border-border-default"}`,children:[n.jsx("div",{className:`mt-0.5 w-2.5 h-2.5 rounded-full shrink-0 ${Vn?"bg-green-400":Mn>0?"bg-blue-400":Sn?"bg-amber-400":"bg-gray-400"}`}),n.jsxs("div",{className:"flex-1 min-w-0",children:[n.jsx("div",{className:`text-sm font-semibold ${Vn?"text-green-400":Mn>0?"text-blue-400":Sn?"text-amber-400":"text-fg-secondary"}`,children:Vn?i("browserAutomation.modeExtension"):Mn>0?i("browserAutomation.modeDebuggingPort",{port:Mn}):i(Sn?"browserAutomation.modeAutoClick":"browserAutomation.modeManual")}),n.jsx("div",{className:"text-xs text-fg-tertiary mt-0.5",children:Vn?i("browserAutomation.modeExtensionDesc"):Mn>0?i("browserAutomation.modeDebuggingPortDesc"):i(Sn?"browserAutomation.modeAutoClickDesc":"browserAutomation.modeManualDesc")})]})]}),n.jsxs("div",{className:"bg-surface-elevated rounded-xl p-5 space-y-4 mb-4",children:[n.jsx("div",{className:"text-xs font-medium text-fg-secondary uppercase tracking-wider",children:i("browserAutomation.generalSettings")}),n.jsxs("div",{className:"flex items-center justify-between",children:[n.jsxs("div",{children:[n.jsx("div",{className:"text-sm font-medium text-fg-primary",children:i("browserAutomation.bringToFront")}),n.jsx("div",{className:"text-xs text-fg-tertiary mt-0.5",children:i("browserAutomation.bringToFrontDesc")})]}),n.jsx("button",{onClick:async()=>{const le=!tn;zn(le),tt(!0),$t(null);try{const Ie=await ie.settings.updateBrowser({bringToFront:le});zn(Ie.bringToFront),$t({type:"ok",text:i(le?"browserAutomation.tabsForeground":"browserAutomation.tabsBackground")})}catch{$t({type:"err",text:i("agentExecution.failedToSave")}),zn(!le)}tt(!1)},disabled:ve,className:`relative inline-flex h-5 w-9 items-center rounded-full transition-colors ${tn?"bg-green-500":"bg-gray-600"} ${ve?"opacity-50":""}`,children:n.jsx("span",{className:`inline-block h-3.5 w-3.5 rounded-full bg-white transition-transform ${tn?"translate-x-4":"translate-x-1"}`})})]}),n.jsxs("div",{className:"flex items-center justify-between border-t border-border-default pt-4",children:[n.jsxs("div",{children:[n.jsx("div",{className:"text-sm font-medium text-fg-primary",children:i("browserAutomation.autoCloseTabs")}),n.jsx("div",{className:"text-xs text-fg-tertiary mt-0.5",children:i("browserAutomation.autoCloseTabsDesc")})]}),n.jsx("button",{onClick:async()=>{const le=!Dn;$n(le),tt(!0),$t(null);try{const Ie=await ie.settings.updateBrowser({autoCloseTabs:le});$n(Ie.autoCloseTabs),$t({type:"ok",text:i("agentExecution.saved")})}catch{$t({type:"err",text:i("agentExecution.failedToSave")}),$n(!le)}tt(!1)},disabled:ve,className:`relative inline-flex h-5 w-9 items-center rounded-full transition-colors ${Dn?"bg-green-500":"bg-gray-600"} ${ve?"opacity-50":""}`,children:n.jsx("span",{className:`inline-block h-3.5 w-3.5 rounded-full bg-white transition-transform ${Dn?"translate-x-4":"translate-x-1"}`})})]})]}),n.jsxs("div",{className:`rounded-xl p-5 mb-4 transition-colors ${Vn?"bg-green-500/5 border border-green-500/20":"bg-surface-elevated"}`,children:[n.jsxs("div",{className:"flex items-center justify-between mb-2",children:[n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx("div",{className:"text-sm font-medium text-fg-primary",children:i("browserAutomation.extensionStatus")}),n.jsxs("span",{className:"text-xs text-fg-tertiary",children:["(",i("browserAutomation.modeRecommended"),")"]})]}),n.jsxs("span",{className:`inline-flex items-center gap-1.5 px-2.5 py-1 rounded-full text-xs font-medium ${Vn?"bg-green-500/20 text-green-400":"bg-gray-600/20 text-gray-400"}`,children:[n.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${Vn?"bg-green-400":"bg-gray-400"}`}),i(Vn?"browserAutomation.extensionConnected":"browserAutomation.extensionDisconnected")]})]}),n.jsx("div",{className:"text-xs text-fg-tertiary",children:i("browserAutomation.extensionStatusDesc")}),Vn?n.jsxs("div",{className:"mt-3 flex items-center gap-1.5 text-xs text-green-400",children:[n.jsx("svg",{className:"w-3.5 h-3.5 shrink-0",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:n.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 13l4 4L19 7"})}),i("browserAutomation.extensionActiveNote")]}):n.jsxs("div",{className:"mt-4 space-y-3",children:[n.jsx("div",{className:"text-xs font-medium text-fg-secondary uppercase tracking-wider",children:i("browserAutomation.extensionSetupTitle")}),n.jsxs("div",{className:"flex items-start gap-3 p-3 rounded-lg bg-surface-primary/50",children:[n.jsx("span",{className:"flex items-center justify-center w-5 h-5 rounded-full bg-brand-500 text-white text-[10px] font-bold shrink-0 mt-0.5",children:"1"}),n.jsxs("div",{className:"flex-1 min-w-0",children:[n.jsx("div",{className:"text-sm font-medium text-fg-primary",children:i("browserAutomation.extensionStep1")}),n.jsx("div",{className:"text-xs text-fg-tertiary mt-0.5",children:i("browserAutomation.extensionStep1Desc")}),n.jsxs("button",{disabled:ve,onClick:async()=>{tt(!0),$t(null);try{await ie.settings.downloadExtensionZip()}catch{$t({type:"err",text:i("browserAutomation.extensionDownloadError")})}tt(!1)},className:"mt-2 inline-flex items-center gap-1.5 px-3 py-1.5 text-xs bg-brand-500 text-white rounded-lg hover:bg-brand-600 transition-colors disabled:opacity-40",children:[n.jsx("svg",{className:"w-3.5 h-3.5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:n.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 16v1a3 3 0 003 3h10a3 3 0 003-3v-1m-4-4l-4 4m0 0l-4-4m4 4V4"})}),i(ve?"browserAutomation.extensionStep1Downloading":"browserAutomation.extensionStep1Btn")]})]})]}),n.jsxs("div",{className:"flex items-start gap-3 p-3 rounded-lg bg-surface-primary/50",children:[n.jsx("span",{className:"flex items-center justify-center w-5 h-5 rounded-full bg-brand-500 text-white text-[10px] font-bold shrink-0 mt-0.5",children:"2"}),n.jsxs("div",{className:"flex-1 min-w-0",children:[n.jsx("div",{className:"text-sm font-medium text-fg-primary",children:i("browserAutomation.extensionStep2")}),n.jsx("div",{className:"text-xs text-fg-tertiary mt-0.5",children:i("browserAutomation.extensionStep2Desc")}),navigator.platform.toUpperCase().includes("WIN")?n.jsxs("div",{className:"mt-2 text-xs text-fg-secondary",children:[i("browserAutomation.extensionStep2Desc"),":",n.jsx("code",{className:"ml-1.5 px-1.5 py-0.5 bg-surface-elevated rounded text-fg-primary font-mono text-[11px] select-all",children:"chrome://extensions"})]}):n.jsxs("button",{disabled:ve,onClick:async()=>{tt(!0),$t(null);try{await ie.settings.openExtensionsPage()}catch{$t({type:"err",text:i("browserAutomation.extensionOpenError")})}tt(!1)},className:"mt-2 inline-flex items-center gap-1.5 px-3 py-1.5 text-xs bg-surface-primary border border-border-default text-fg-primary rounded-lg hover:bg-surface-elevated transition-colors disabled:opacity-40",children:[n.jsx("svg",{className:"w-3.5 h-3.5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:n.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M10 6H6a2 2 0 00-2 2v10a2 2 0 002 2h10a2 2 0 002-2v-4M14 4h6m0 0v6m0-6L10 14"})}),i("browserAutomation.extensionStep2Btn")]})]})]}),n.jsxs("div",{className:"flex items-start gap-3 p-3 rounded-lg bg-surface-primary/50",children:[n.jsx("span",{className:"flex items-center justify-center w-5 h-5 rounded-full bg-brand-500 text-white text-[10px] font-bold shrink-0 mt-0.5",children:"3"}),n.jsxs("div",{className:"flex-1 min-w-0",children:[n.jsx("div",{className:"text-sm font-medium text-fg-primary",children:i("browserAutomation.extensionStep3")}),n.jsx("div",{className:"text-xs text-fg-tertiary mt-0.5",children:i("browserAutomation.extensionStep3Desc")})]})]})]})]}),!Vn&&n.jsxs("div",{className:"bg-surface-elevated rounded-xl p-5 space-y-4",children:[n.jsx("div",{className:"text-xs font-medium text-fg-secondary uppercase tracking-wider",children:i("browserAutomation.fallbackModes")}),n.jsx("div",{children:n.jsxs("div",{className:"flex items-center justify-between",children:[n.jsxs("div",{className:"flex-1 mr-4",children:[n.jsx("div",{className:"text-sm font-medium text-fg-primary",children:i("browserAutomation.autoClickAllowDialog")}),n.jsx("div",{className:"text-xs text-fg-tertiary mt-0.5",children:i("browserAutomation.autoClickAllowDialogDesc")}),n.jsxs("div",{className:"text-xs text-fg-tertiary mt-2 space-y-0.5",children:[n.jsx("div",{children:i("browserAutomation.autoClickAllowDialogMacNote")}),n.jsx("div",{children:i("browserAutomation.autoClickAllowDialogWinNote")}),n.jsx("div",{children:i("browserAutomation.autoClickAllowDialogLinuxNote")})]})]}),n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx("button",{disabled:ve,onClick:async()=>{tt(!0),$t(null);try{const le=await ie.settings.testAutoClick(),Ie={success:{type:"ok",text:i("browserAutomation.autoClickTestSuccess",{title:le.pageTitle||"example.com"})},no_permission:{type:"err",text:i("browserAutomation.autoClickTestNoPermission")},chrome_not_running:{type:"err",text:i("browserAutomation.autoClickTestChromeNotRunning")},unsupported:{type:"err",text:i("browserAutomation.autoClickTestUnsupported")},error:{type:"err",text:i("browserAutomation.autoClickTestError",{error:le.error||"unknown"})}};$t(Ie[le.clickResult]??{type:"err",text:le.clickResult})}catch{$t({type:"err",text:i("browserAutomation.autoClickTestError",{error:"request failed"})})}tt(!1)},className:"px-3 py-1.5 text-xs bg-surface-primary border border-border-default text-fg-primary rounded-lg hover:bg-surface-elevated transition-colors disabled:opacity-40",children:i(ve?"browserAutomation.autoClickTesting":"browserAutomation.autoClickTest")}),n.jsx("button",{onClick:async()=>{const le=!Sn;Bn(le),tt(!0),$t(null);try{const Ie=await ie.settings.updateBrowser({autoClickAllowDialog:le});Bn(Ie.autoClickAllowDialog),$t({type:"ok",text:i("agentExecution.saved")})}catch{$t({type:"err",text:i("agentExecution.failedToSave")}),Bn(!le)}tt(!1)},disabled:ve,className:`relative inline-flex h-5 w-9 items-center rounded-full transition-colors ${Sn?"bg-green-500":"bg-gray-600"} ${ve?"opacity-50":""}`,children:n.jsx("span",{className:`inline-block h-3.5 w-3.5 rounded-full bg-white transition-transform ${Sn?"translate-x-4":"translate-x-1"}`})})]})]})}),n.jsx("div",{className:"border-t border-border-default pt-4",children:n.jsxs("div",{className:"flex items-center justify-between",children:[n.jsxs("div",{children:[n.jsx("div",{className:"text-sm font-medium text-fg-primary",children:i("browserAutomation.remoteDebuggingPort")}),n.jsxs("div",{className:"text-xs text-fg-tertiary mt-0.5",children:[i("browserAutomation.remoteDebuggingPortDescLead")," ",n.jsx("code",{className:"text-fg-secondary bg-surface-primary px-1 rounded",children:"--remote-debugging-port=9222"})," ",i("browserAutomation.remoteDebuggingPortDescTail")]})]}),n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx("input",{type:"number",min:0,max:65535,value:Mn,onChange:le=>{wn(Number(le.target.value)),$t(null)},className:"w-24 px-3 py-1.5 text-sm border border-border-default rounded-lg bg-surface-primary text-fg-primary text-right",placeholder:"0"}),n.jsx("button",{disabled:ve,onClick:async()=>{tt(!0),$t(null);try{const le=await ie.settings.updateBrowser({remoteDebuggingPort:Mn});wn(le.remoteDebuggingPort),$t({type:"ok",text:le.remoteDebuggingPort>0?i("browserAutomation.usingPort",{port:le.remoteDebuggingPort}):i("browserAutomation.usingAutoConnect")})}catch{$t({type:"err",text:i("agentExecution.failedToSave")})}tt(!1)},className:"px-3 py-1.5 text-xs bg-brand-500 text-white rounded-lg hover:bg-brand-600 transition-colors disabled:opacity-40",children:i(ve?"common:saving":"common:save")})]})]})})]}),Tt&&n.jsx("div",{className:"mt-4",children:n.jsx(Ka,{type:Tt.type,text:Tt.text})})]}),!1]}),w==="search"&&n.jsx(n.Fragment,{children:n.jsx(pi,{title:i("searchApi.title"),children:n.jsxs("div",{className:"bg-surface-elevated rounded-xl p-5 space-y-5",children:[n.jsx("div",{className:"text-xs text-fg-tertiary",children:i("searchApi.description")}),[{id:"serper",label:i("searchApi.serper"),hint:i("searchApi.serperHint"),field:"serperApiKey"},{id:"tavily",label:i("searchApi.tavily"),hint:i("searchApi.tavilyHint"),field:"tavilyApiKey"},{id:"bing",label:i("searchApi.bing"),hint:i("searchApi.bingHint"),field:"bingApiKey"},{id:"google",label:i("searchApi.google"),hint:i("searchApi.googleHint"),field:"googleSearchApiKey",extraField:"googleSearchCx",extraPlaceholder:i("searchApi.googleCxPlaceholder")},{id:"serpapi",label:i("searchApi.serpapi"),hint:i("searchApi.serpapiHint"),field:"serpApiKey"},{id:"brave",label:i("searchApi.brave"),hint:i("searchApi.braveHint"),field:"braveApiKey"},{id:"exa",label:i("searchApi.exa"),hint:i("searchApi.exaHint"),field:"exaApiKey"},{id:"bocha",label:i("searchApi.bocha"),hint:i("searchApi.bochaHint"),field:"bochaApiKey"}].map((le,Ie)=>n.jsxs("div",{className:Ie>0?"border-t border-border-default pt-4":"",children:[n.jsxs("div",{className:"flex items-center justify-between mb-2",children:[n.jsxs("div",{children:[n.jsx("div",{className:"text-sm font-medium text-fg-primary",children:le.label}),n.jsx("div",{className:"text-xs text-fg-tertiary mt-0.5",children:le.hint})]}),n.jsxs("div",{className:"flex items-center gap-2",children:[sn?.[le.id]?.configured&&n.jsxs(n.Fragment,{children:[n.jsx("span",{className:"w-2 h-2 rounded-full bg-green-400"}),n.jsx("span",{className:"text-xs text-green-600",children:i("searchApi.configured")}),n.jsx("code",{className:"text-[10px] text-fg-tertiary",children:sn[le.id].preview})]}),sn&&!sn[le.id]?.configured&&n.jsxs(n.Fragment,{children:[n.jsx("span",{className:"w-2 h-2 rounded-full bg-gray-500"}),n.jsx("span",{className:"text-xs text-fg-tertiary",children:i("searchApi.notConfigured")})]})]})]}),n.jsx("input",{type:"password",value:Xt[le.field],onChange:st=>ye({...Xt,[le.field]:st.target.value}),placeholder:sn?.[le.id]?.configured?i("modelProviders.apiKeyPlaceholder"):i("searchApi.apiKeyPlaceholder"),className:"w-full px-3 py-1.5 text-xs bg-surface-primary border border-border-default rounded-lg text-fg-primary placeholder-fg-tertiary focus:border-brand-500 outline-none"}),le.extraField&&n.jsx("input",{type:"text",value:Xt[le.extraField],onChange:st=>ye({...Xt,[le.extraField]:st.target.value}),placeholder:le.extraPlaceholder??"",className:"w-full mt-2 px-3 py-1.5 text-xs bg-surface-primary border border-border-default rounded-lg text-fg-primary placeholder-fg-tertiary focus:border-brand-500 outline-none"})]},le.id)),n.jsx("div",{className:"text-xs text-fg-tertiary italic",children:i("searchApi.freeBackend")}),n.jsxs("div",{className:"flex items-center justify-between pt-2 border-t border-border-default",children:[Bt&&n.jsx(Ka,{type:Bt.type,text:Bt.text}),!Bt&&n.jsx("div",{}),n.jsx("button",{disabled:lt||!Xt.serperApiKey&&!Xt.tavilyApiKey&&!Xt.bingApiKey&&!Xt.googleSearchApiKey&&!Xt.googleSearchCx&&!Xt.serpApiKey&&!Xt.braveApiKey&&!Xt.exaApiKey&&!Xt.bochaApiKey,onClick:()=>{fs()},className:"px-4 py-1.5 text-xs bg-brand-500 text-white rounded-lg hover:bg-brand-600 transition-colors disabled:opacity-40",children:i(lt?"common:saving":"common:save")})]})]})})}),w==="storage"&&n.jsx(n.Fragment,{children:n.jsx(pi,{title:i("dataStorage.title"),children:n.jsxs("div",{className:"bg-surface-elevated rounded-xl p-5 space-y-5",children:[tr&&!Dt&&n.jsx("div",{className:"text-sm text-fg-tertiary",children:i("dataStorage.scanning")}),Dt&&n.jsxs(n.Fragment,{children:[n.jsxs("div",{className:"flex items-center justify-between",children:[n.jsxs("div",{children:[n.jsx("div",{className:"text-lg font-semibold text-fg-primary",children:nd(Dt.totalSize,i)}),n.jsx("div",{className:"text-xs text-fg-tertiary font-mono mt-0.5",children:Dt.dataDir})]}),n.jsxs("div",{className:"flex gap-2",children:[n.jsx("button",{onClick:()=>ba(),disabled:tr,className:"px-3 py-1.5 text-xs border border-border-default hover:bg-surface-elevated rounded-lg text-fg-secondary transition-colors disabled:opacity-40",children:i(tr?"dataStorage.scanning":"common:refresh")}),n.jsx("button",{onClick:()=>{ie.system.openPath(Dt.dataDir)},className:"px-3 py-1.5 text-xs border border-border-default hover:bg-surface-elevated rounded-lg text-fg-secondary transition-colors",children:i("dataStorage.openInFinder")})]})]}),n.jsxs("div",{className:"border-t border-border-default pt-4",children:[n.jsx("h4",{className:"text-xs font-semibold text-fg-secondary mb-3",children:i("dataStorage.storageBreakdown")}),n.jsx("div",{className:"space-y-1.5",children:Dt.breakdown.filter(le=>le.size>0).map(le=>n.jsxs("div",{className:"flex items-center justify-between py-1.5 px-3 rounded-lg bg-surface-elevated/40",children:[n.jsxs("div",{className:"min-w-0",children:[n.jsx("span",{className:"text-sm text-fg-primary",children:le.name}),n.jsx("span",{className:"text-xs text-fg-tertiary ml-2",children:le.description})]}),n.jsx("span",{className:"text-sm font-medium text-fg-secondary tabular-nums shrink-0 ml-3",children:nd(le.size,i)})]},le.name))})]}),Dt.agents.length>0&&n.jsxs("div",{className:"border-t border-border-default pt-4",children:[n.jsx("h4",{className:"text-xs font-semibold text-fg-secondary mb-3",children:i("dataStorage.agentStorage",{count:Dt.agents.length})}),n.jsx("div",{className:"space-y-1",children:Dt.agents.map(le=>{const Ie=nr.has(le.id);return n.jsxs("div",{className:"rounded-lg bg-surface-elevated/40 overflow-hidden",children:[n.jsxs("div",{className:"flex items-center justify-between py-2 px-3 cursor-pointer hover:bg-surface-elevated/70",onClick:()=>On(st=>{const hn=new Set(st);return hn.has(le.id)?hn.delete(le.id):hn.add(le.id),hn}),children:[n.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[n.jsx("span",{className:"text-[10px] text-fg-tertiary",children:Ie?"▼":"▶"}),n.jsx("button",{onClick:st=>{st.stopPropagation(),bt.navigate(De.TEAM,{agentId:le.id})},className:"text-sm text-brand-500 hover:text-brand-400 truncate",children:le.name}),n.jsx("span",{className:"text-[10px] text-fg-tertiary font-mono truncate",children:le.id})]}),n.jsx("span",{className:"text-xs font-medium text-fg-secondary tabular-nums shrink-0 ml-3",children:nd(le.size,i)})]}),Ie&&n.jsxs("div",{className:"px-3 pb-2 pt-0.5 space-y-0.5",children:[le.subItems.filter(st=>st.size>0).map(st=>n.jsxs("div",{className:"flex items-center justify-between text-xs py-0.5 pl-5",children:[n.jsx("span",{className:"text-fg-tertiary",children:st.name}),n.jsx("span",{className:"text-fg-secondary tabular-nums",children:nd(st.size,i)})]},st.name)),n.jsx("div",{className:"pl-5 pt-1",children:n.jsx("button",{onClick:()=>{ie.system.openPath(Dt.dataDir+"/agents/"+le.id)},className:"text-[10px] text-fg-tertiary hover:text-fg-secondary underline",children:i("dataStorage.openFolder")})})]})]},le.id)})})]}),on&&(on.orphanAgents.length>0||on.orphanTeams.length>0)&&n.jsx(cY,{orphanInfo:on,dataDir:Dt.dataDir,onPurged:ba,formatBytes:le=>nd(le,i)})]})]})})}),(w==="account"||w==="users"||w==="organization"||w==="license")&&n.jsx(hY,{authUser:r}),w==="remote"&&n.jsx(uY,{})]}),n.jsx("div",{className:"h-8"})]})]})]})}const tj=["owner","admin","member","guest"],iY={owner:"bg-amber-500/10 text-amber-600 border-amber-500/30",admin:"bg-brand-500/10 text-brand-500 border-brand-500/30",member:"bg-green-500/10 text-green-600 border-green-500/30",guest:"bg-gray-500/10 text-gray-500 border-gray-500/30"};function oY({authUser:e}){const{t}=pt(["settings","common"]),[r,s]=g.useState([]),[a,i]=g.useState(null),[l,d]=g.useState(""),[u,m]=g.useState(""),[h,p]=g.useState(""),[y,x]=g.useState(null),[v,j]=g.useState(""),[C,w]=g.useState(null),[N,S]=g.useState(null),[T,E]=g.useState(null),[R,I]=g.useState(!1),[z,B]=g.useState(""),[D,V]=g.useState(""),[Y,F]=g.useState("member"),[L,O]=g.useState(""),M=g.useCallback(()=>{ie.users.list(e?.orgId).then(Z=>s(Z.users)).catch(()=>{})},[e?.orgId]);g.useEffect(()=>{M()},[M]);const $=Z=>{i(Z.id),d(Z.name),m(Z.role),p(Z.email??""),E(null)},W=async()=>{if(a)try{await ie.users.update(a,{name:l,role:u,email:h||void 0}),i(null),E({type:"ok",text:t("settings:userManagement.updateSuccess")}),M()}catch(Z){E({type:"err",text:`${t("settings:userManagement.error")}: ${String(Z)}`})}},U=async()=>{if(!(!y||!v))try{await ie.users.resetPassword(y,v),x(null),j(""),E({type:"ok",text:t("settings:userManagement.resetSuccess")})}catch(Z){E({type:"err",text:`${t("settings:userManagement.error")}: ${String(Z)}`})}},H=async Z=>{if(Z===e?.id){E({type:"err",text:t("settings:userManagement.cannotDeleteSelf")}),w(null);return}if(r.find(J=>J.id===Z)?.role==="owner"){E({type:"err",text:t("settings:userManagement.cannotDeleteOwner")}),w(null);return}try{await ie.users.remove(Z),w(null),E({type:"ok",text:t("settings:userManagement.deleteSuccess")}),M()}catch(J){E({type:"err",text:`${t("settings:userManagement.error")}: ${String(J)}`})}},q=async()=>{if(z.trim())try{const Z=await ie.users.create(z.trim(),Y,void 0,D.trim()||void 0,L||void 0);I(!1),B(""),V(""),F("member"),O(""),E({type:"ok",text:t("settings:userManagement.addSuccess",{defaultValue:"User created"})}),Z.inviteToken&&S(`${window.location.origin}/#invite?token=${Z.inviteToken}`),M()}catch(Z){E({type:"err",text:`${t("settings:userManagement.error")}: ${Z instanceof Error?Z.message:String(Z)}`})}};return n.jsxs(pi,{title:t("settings:userManagement.title"),children:[n.jsxs("div",{className:"mb-3",children:[n.jsx("p",{className:"text-xs text-fg-tertiary leading-relaxed",children:t("settings:userManagement.sharedInstanceDesc")}),n.jsx("p",{className:"text-xs text-fg-tertiary mt-1",children:t("settings:userManagement.orgHint")})]}),R?n.jsxs("div",{className:"mb-3 p-4 rounded-lg border border-border-default space-y-3",children:[n.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[n.jsxs("div",{children:[n.jsx("label",{className:"text-[11px] text-fg-tertiary mb-1 block",children:t("settings:userManagement.name")}),n.jsx("input",{value:z,onChange:Z=>B(Z.target.value),autoFocus:!0,className:"w-full px-3 py-1.5 text-sm bg-surface-elevated border border-border-default rounded-md text-fg-primary"})]}),n.jsxs("div",{children:[n.jsx("label",{className:"text-[11px] text-fg-tertiary mb-1 block",children:t("settings:userManagement.email")}),n.jsx("input",{value:D,onChange:Z=>V(Z.target.value),type:"email",className:"w-full px-3 py-1.5 text-sm bg-surface-elevated border border-border-default rounded-md text-fg-primary"})]}),n.jsxs("div",{children:[n.jsx("label",{className:"text-[11px] text-fg-tertiary mb-1 block",children:t("settings:userManagement.role")}),n.jsx("select",{value:Y,onChange:Z=>F(Z.target.value),className:"w-full px-3 py-1.5 text-sm bg-surface-elevated border border-border-default rounded-md text-fg-primary",children:tj.map(Z=>n.jsx("option",{value:Z,children:t(`settings:userManagement.roles.${Z}`)},Z))})]}),n.jsxs("div",{children:[n.jsx("label",{className:"text-[11px] text-fg-tertiary mb-1 block",children:t("settings:userManagement.password",{defaultValue:"Password"})}),n.jsx("input",{value:L,onChange:Z=>O(Z.target.value),type:"password",className:"w-full px-3 py-1.5 text-sm bg-surface-elevated border border-border-default rounded-md text-fg-primary"})]})]}),n.jsxs("div",{className:"flex gap-2 justify-end",children:[n.jsx("button",{onClick:()=>{I(!1),B(""),V(""),F("member"),O("")},className:"px-3 py-1.5 text-xs text-fg-tertiary hover:text-fg-secondary",children:t("settings:userManagement.cancel")}),n.jsx("button",{onClick:q,disabled:!z.trim(),className:"px-4 py-1.5 bg-brand-600 hover:bg-brand-500 disabled:opacity-40 text-white text-xs font-medium rounded-lg",children:t("settings:userManagement.save")})]})]}):n.jsx("button",{onClick:()=>I(!0),className:"mb-3 px-4 py-2 bg-brand-600 hover:bg-brand-500 text-white text-xs font-medium rounded-lg transition-colors",children:t("settings:userManagement.addUser",{defaultValue:"Add User"})}),n.jsxs("div",{className:"bg-surface-elevated rounded-xl overflow-hidden",children:[T&&n.jsx("div",{className:`px-4 py-2 text-xs border-b ${T.type==="ok"?"bg-green-500/10 text-green-600 border-green-500/20":"bg-red-500/10 text-red-500 border-red-500/20"}`,children:T.text}),N&&n.jsxs("div",{className:"px-4 py-3 bg-brand-500/5 border-b border-brand-500/20 flex items-center gap-3",children:[n.jsxs("div",{className:"flex-1 min-w-0",children:[n.jsx("div",{className:"text-[11px] text-fg-tertiary mb-1",children:t("settings:userManagement.copyInviteLink")}),n.jsx("code",{className:"text-[10px] text-brand-500 bg-surface-elevated px-2 py-1 rounded block truncate",children:N})]}),n.jsx("button",{onClick:()=>{navigator.clipboard.writeText(N),E({type:"ok",text:t("settings:userManagement.linkCopied")})},className:"shrink-0 px-3 py-1.5 text-[11px] bg-brand-600 hover:bg-brand-500 text-white rounded-lg font-medium",children:t("settings:userManagement.copy")}),n.jsx("button",{onClick:()=>S(null),className:"shrink-0 text-fg-tertiary hover:text-fg-secondary text-sm",children:"×"})]}),n.jsxs("table",{className:"w-full text-sm",children:[n.jsx("thead",{children:n.jsxs("tr",{className:"border-b border-border-default/60 text-fg-tertiary text-[11px] uppercase tracking-wider",children:[n.jsx("th",{className:"text-left px-4 py-2.5 font-medium",children:t("settings:userManagement.name")}),n.jsx("th",{className:"text-left px-4 py-2.5 font-medium",children:t("settings:userManagement.email")}),n.jsx("th",{className:"text-left px-4 py-2.5 font-medium",children:t("settings:userManagement.role")}),n.jsx("th",{className:"text-right px-4 py-2.5 font-medium",children:t("settings:userManagement.actions")})]})}),n.jsxs("tbody",{children:[r.length===0&&n.jsx("tr",{children:n.jsx("td",{colSpan:4,className:"px-4 py-6 text-center text-fg-tertiary text-xs",children:t("settings:userManagement.noUsers")})}),r.map(Z=>{const _=a===Z.id,J=y===Z.id,X=C===Z.id,ee=Z.id===e?.id,te=Z.role==="owner";return n.jsxs("tr",{className:"border-b border-border-default/40 last:border-b-0 hover:bg-surface-elevated/40 transition-colors",children:[n.jsx("td",{className:"px-4 py-2.5",children:_?n.jsx("input",{value:l,onChange:G=>d(G.target.value),className:"w-full px-2 py-1 text-xs bg-surface-primary border border-border-default rounded-md focus:outline-none focus:ring-1 focus:ring-brand-500/50"}):n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx("span",{className:"text-fg-primary font-medium text-xs",children:Z.name}),ee&&n.jsx("span",{className:"text-[9px] px-1.5 py-0.5 rounded-full bg-brand-500/10 text-brand-500",children:"you"})]})}),n.jsx("td",{className:"px-4 py-2.5",children:_?n.jsx("input",{value:h,onChange:G=>p(G.target.value),placeholder:"email@example.com",className:"w-full px-2 py-1 text-xs bg-surface-primary border border-border-default rounded-md focus:outline-none focus:ring-1 focus:ring-brand-500/50"}):n.jsx("span",{className:"text-fg-secondary text-xs",children:Z.email||"—"})}),n.jsx("td",{className:"px-4 py-2.5",children:_?n.jsx("select",{value:u,onChange:G=>m(G.target.value),className:"px-2 py-1 text-xs bg-surface-primary border border-border-default rounded-md focus:outline-none focus:ring-1 focus:ring-brand-500/50",children:tj.map(G=>n.jsx("option",{value:G,children:t(`settings:userManagement.roles.${G}`)},G))}):n.jsx("span",{className:`inline-block text-[10px] px-2 py-0.5 rounded-full border font-medium ${iY[Z.role]??""}`,children:t(`settings:userManagement.roles.${Z.role}`)})}),n.jsx("td",{className:"px-4 py-2.5 text-right",children:_?n.jsxs("div",{className:"flex items-center justify-end gap-2",children:[n.jsx("button",{onClick:()=>i(null),className:"text-[11px] text-fg-tertiary hover:text-fg-secondary",children:t("settings:userManagement.cancel")}),n.jsx("button",{onClick:W,className:"text-[11px] text-brand-500 hover:text-brand-400 font-medium",children:t("settings:userManagement.save")})]}):J?n.jsxs("div",{className:"flex items-center justify-end gap-2",children:[n.jsx("input",{type:"password",value:v,onChange:G=>j(G.target.value),placeholder:t("settings:userManagement.newPassword"),autoFocus:!0,className:"w-32 px-2 py-1 text-xs bg-surface-primary border border-border-default rounded-md focus:outline-none focus:ring-1 focus:ring-brand-500/50"}),n.jsx("button",{onClick:()=>{x(null),j("")},className:"text-[11px] text-fg-tertiary hover:text-fg-secondary",children:t("settings:userManagement.cancel")}),n.jsx("button",{onClick:U,disabled:v.length<6,className:"text-[11px] text-brand-500 hover:text-brand-400 font-medium disabled:opacity-40",children:t("settings:userManagement.confirmReset")})]}):X?n.jsxs("div",{className:"flex items-center justify-end gap-2",children:[n.jsx("span",{className:"text-[10px] text-red-500",children:t("settings:userManagement.confirmDelete")}),n.jsx("button",{onClick:()=>w(null),className:"text-[11px] text-fg-tertiary hover:text-fg-secondary",children:t("settings:userManagement.cancel")}),n.jsx("button",{onClick:()=>H(Z.id),className:"text-[11px] text-red-500 hover:text-red-400 font-medium",children:t("settings:userManagement.deleteUser")})]}):n.jsxs("div",{className:"flex items-center justify-end gap-1.5",children:[n.jsx("button",{onClick:()=>$(Z),className:"text-[11px] text-fg-tertiary hover:text-fg-secondary px-1.5 py-0.5 rounded hover:bg-surface-elevated",children:t("settings:userManagement.editUser")}),Z.email&&n.jsx("button",{onClick:()=>{x(Z.id),j(""),E(null)},className:"text-[11px] text-fg-tertiary hover:text-fg-secondary px-1.5 py-0.5 rounded hover:bg-surface-elevated",children:t("settings:userManagement.resetPassword")}),Z.email&&!te&&!Z.hasJoined&&n.jsx("button",{onClick:async()=>{try{const{inviteToken:G}=await ie.users.reinvite(Z.id),ue=`${window.location.origin}/#invite?token=${G}`;S(ue),E({type:"ok",text:t("settings:userManagement.inviteLinkGenerated")})}catch(G){E({type:"err",text:String(G)})}},className:"text-[11px] text-brand-400 hover:text-brand-500 px-1.5 py-0.5 rounded hover:bg-brand-500/10",children:t("settings:userManagement.inviteLink")}),!te&&!ee&&n.jsx("button",{onClick:()=>{w(Z.id),E(null)},className:"text-[11px] text-red-400 hover:text-red-500 px-1.5 py-0.5 rounded hover:bg-red-500/10",children:t("settings:userManagement.deleteUser")})]})})]},Z.id)})]})]})]})]})}function lY({providerName:e,addModelForm:t,setAddModelForm:r,addModelSaving:s,onAdd:a,onCancel:i,t:l}){const[d,u]=g.useState([]),[m,h]=g.useState(!1),[p,y]=g.useState(!1),x=async()=>{h(!0);try{const v=await ie.modelCatalog.getByProvider(e);u(v.models),y(!0)}catch{u([])}finally{h(!1)}};return n.jsxs(n.Fragment,{children:[n.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[n.jsx("span",{className:"text-[10px] text-fg-secondary",children:l("modelProviders.addModelTitle")}),n.jsx("button",{onClick:()=>{x()},disabled:m,className:"text-[10px] text-brand-500 hover:text-brand-400 disabled:opacity-40 transition-colors",children:m?"...":l("modelProviders.browseFromCatalog")})]}),p&&d.length>0&&n.jsx("div",{className:"border border-border-default rounded-lg p-2 mb-2",children:n.jsx(dh,{provider:e,models:d,selectedModel:t.id,onSelect:v=>{const j=d.find(C=>C.id===v);j&&r(C=>({...C,id:j.id,name:j.id,contextWindow:j.maxInputTokens,maxOutputTokens:j.maxOutputTokens,costInput:j.inputCostPer1MTokens,costOutput:j.outputCostPer1MTokens,reasoning:j.capabilities.reasoning,vision:j.capabilities.vision}))},compact:!0,maxVisible:5})}),n.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-2",children:[n.jsx("input",{type:"text",placeholder:l("modelProviders.modelId"),value:t.id,onChange:v=>r({...t,id:v.target.value}),className:"px-2 py-1 text-xs bg-surface-primary border border-border-default rounded text-fg-primary placeholder-fg-tertiary focus:border-brand-500 outline-none"}),n.jsx("input",{type:"text",placeholder:l("modelProviders.displayName"),value:t.name,onChange:v=>r({...t,name:v.target.value}),className:"px-2 py-1 text-xs bg-surface-primary border border-border-default rounded text-fg-primary placeholder-fg-tertiary focus:border-brand-500 outline-none"}),n.jsx("input",{type:"number",placeholder:l("modelProviders.placeholderContextTokens"),value:t.contextWindow,onChange:v=>r({...t,contextWindow:Number(v.target.value)}),className:"px-2 py-1 text-xs bg-surface-primary border border-border-default rounded text-fg-primary focus:border-brand-500 outline-none"}),n.jsx("input",{type:"number",placeholder:l("modelProviders.maxOutput"),value:t.maxOutputTokens,onChange:v=>r({...t,maxOutputTokens:Number(v.target.value)}),className:"px-2 py-1 text-xs bg-surface-primary border border-border-default rounded text-fg-primary focus:border-brand-500 outline-none"})]}),n.jsxs("div",{className:"flex items-center gap-3",children:[n.jsxs("div",{className:"flex items-center gap-1",children:[n.jsx("span",{className:"text-[10px] text-fg-tertiary",children:l("modelProviders.costPerMillionIn")}),n.jsx("input",{type:"number",step:"0.01",value:t.costInput,onChange:v=>r({...t,costInput:Number(v.target.value)}),className:"w-16 px-2 py-1 text-xs bg-surface-primary border border-border-default rounded text-fg-primary focus:border-brand-500 outline-none"})]}),n.jsxs("div",{className:"flex items-center gap-1",children:[n.jsx("span",{className:"text-[10px] text-fg-tertiary",children:l("modelProviders.costPerMillionOut")}),n.jsx("input",{type:"number",step:"0.01",value:t.costOutput,onChange:v=>r({...t,costOutput:Number(v.target.value)}),className:"w-16 px-2 py-1 text-xs bg-surface-primary border border-border-default rounded text-fg-primary focus:border-brand-500 outline-none"})]}),n.jsxs("label",{className:"flex items-center gap-1 text-[10px] text-fg-tertiary cursor-pointer",children:[n.jsx("input",{type:"checkbox",checked:t.reasoning,onChange:v=>r({...t,reasoning:v.target.checked}),className:"rounded"}),l("modelProviders.reasoning")]}),n.jsxs("label",{className:"flex items-center gap-1 text-[10px] text-fg-tertiary cursor-pointer",children:[n.jsx("input",{type:"checkbox",checked:t.vision,onChange:v=>r({...t,vision:v.target.checked}),className:"rounded"}),l("modelProviders.vision")]}),n.jsx("div",{className:"flex-1"}),n.jsx("button",{onClick:a,disabled:s||!t.id||!t.name,className:"px-2 py-1 text-[10px] bg-brand-600 hover:bg-brand-500 disabled:opacity-40 text-white rounded transition-colors",children:l(s?"modelProviders.adding":"common:create")}),n.jsx("button",{onClick:i,className:"px-2 py-1 text-[10px] border border-border-default text-fg-secondary hover:bg-surface-elevated rounded transition-colors",children:l("common:cancel")})]})]})}function Du({step:e,title:t,description:r,active:s,children:a}){return n.jsxs("div",{className:`rounded-xl p-4 space-y-3 transition-colors ${s?"ring-1 ring-brand-500/60 bg-brand-500/10":"bg-surface-elevated"}`,children:[n.jsxs("div",{className:"flex items-start gap-3",children:[n.jsx("span",{className:"flex-none w-6 h-6 rounded-full bg-surface-overlay flex items-center justify-center text-xs font-bold text-fg-secondary",children:e}),n.jsxs("div",{className:"min-w-0",children:[n.jsx("div",{className:"text-sm font-medium text-fg-primary",children:t}),n.jsx("div",{className:"text-xs text-fg-tertiary mt-0.5",children:r})]})]}),a&&n.jsx("div",{className:"pl-9",children:a})]})}function Ka({type:e,text:t}){return n.jsx("div",{className:`text-xs px-3 py-2 rounded-lg ${e==="ok"?"bg-green-500/10 text-green-600 border border-green-500/30":"bg-red-500/10 text-red-500 border border-red-500/30"}`,children:t})}function pi({title:e,children:t}){return n.jsxs("section",{children:[n.jsx("h3",{className:"text-sm font-semibold text-fg-secondary uppercase tracking-wider mb-4",children:e}),n.jsx("div",{className:"space-y-4",children:t})]})}function Kx({label:e,value:t,color:r}){const s=r==="green"?"bg-green-500/10 text-green-600":"bg-brand-500/10 text-brand-500";return n.jsxs("div",{className:`rounded-xl px-5 py-4 ${s}`,children:[n.jsx("div",{className:"text-2xl font-bold",children:t}),n.jsx("div",{className:"text-xs mt-1 opacity-70",children:e})]})}function ml({label:e,value:t}){return n.jsxs("div",{children:[n.jsx("div",{className:"text-[10px] text-fg-tertiary uppercase",children:e}),n.jsx("div",{className:"text-xs text-fg-secondary mt-0.5 truncate",children:t})]})}function nd(e,t){if(e===0)return t?t("dataStorage.bytesZero"):"0 B";const r=t?[t("dataStorage.unitB"),t("dataStorage.unitKB"),t("dataStorage.unitMB"),t("dataStorage.unitGB")]:["B","KB","MB","GB"],s=Math.min(Math.floor(Math.log(e)/Math.log(1024)),r.length-1),a=e/Math.pow(1024,s);return`${a<10?a.toFixed(1):Math.round(a)} ${r[s]}`}function cY({orphanInfo:e,dataDir:t,onPurged:r,formatBytes:s}){const{t:a}=pt(["settings","common"]),i=[...e.orphanAgents.map(w=>({...w,kind:"agent"})),...e.orphanTeams.map(w=>({...w,kind:"team"}))],[l,d]=g.useState(new Set),[u,m]=g.useState(!1),[h,p]=g.useState(null),y=w=>d(N=>{const S=new Set(N);return S.has(w)?S.delete(w):S.add(w),S}),x=l.size===i.length&&i.length>0,v=()=>d(x?new Set:new Set(i.map(w=>w.id))),j=i.filter(w=>l.has(w.id)).reduce((w,N)=>w+N.size,0),C=async w=>{m(!0),p(null);try{const N=await ie.system.purgeOrphans(w),S=N.purgedAgents.length+N.purgedTeams.length,T=a("dataStorage.cleaned",{count:S,size:s(N.freedBytes)});p(N.failures.length?a("dataStorage.cleanedWithFailureNote",{base:T,count:N.failures.length}):T),d(new Set),r()}catch{p(a("dataStorage.cleanupFailed"))}finally{m(!1)}};return n.jsxs("div",{className:"border-t border-border-default pt-4",children:[n.jsx("h4",{className:"text-xs font-semibold text-amber-500 mb-2",children:a("dataStorage.orphanedDirectories")}),n.jsxs("p",{className:"text-xs text-fg-tertiary mb-3",children:[a("dataStorage.orphanedDesc")," ",a("dataStorage.orphanedTotal",{size:s(e.totalOrphanSize),count:i.length})]}),n.jsxs("div",{className:"flex items-center gap-2 mb-2 px-1",children:[n.jsxs("label",{className:"flex items-center gap-1.5 text-[10px] text-fg-tertiary cursor-pointer select-none",children:[n.jsx("input",{type:"checkbox",checked:x,onChange:v,className:"rounded"}),a("common:selectAll")]}),l.size>0&&n.jsx("span",{className:"text-[10px] text-fg-secondary",children:a("dataStorage.selectedWithSize",{count:l.size,size:s(j)})})]}),n.jsx("div",{className:"space-y-0.5 mb-3 max-h-52 overflow-y-auto",children:i.map(w=>n.jsxs("div",{className:`flex items-center gap-2 text-xs py-1.5 px-2 rounded transition-colors ${l.has(w.id)?"bg-amber-500/10":"bg-surface-elevated/30 hover:bg-surface-elevated/50"}`,children:[n.jsx("input",{type:"checkbox",checked:l.has(w.id),onChange:()=>y(w.id),className:"rounded shrink-0"}),w.kind==="team"&&n.jsx("span",{className:"text-[10px] text-fg-tertiary shrink-0",children:a("dataStorage.teamKind")}),n.jsx("span",{className:"text-fg-tertiary font-mono truncate min-w-0 flex-1",children:w.id}),n.jsx("span",{className:"text-fg-secondary tabular-nums shrink-0",children:s(w.size)}),n.jsx("button",{onClick:()=>{ie.system.openPath(w.path)},className:"text-[10px] text-fg-tertiary hover:text-fg-secondary shrink-0 underline",children:a("common:open")})]},w.id))}),n.jsxs("div",{className:"flex gap-2 items-center flex-wrap",children:[l.size>0&&n.jsx("button",{disabled:u,onClick:()=>{C([...l])},className:"px-3 py-1.5 text-xs bg-amber-600 hover:bg-amber-500 text-white rounded-lg transition-colors disabled:opacity-50",children:u?a("dataStorage.cleaning"):a("dataStorage.cleanSelected",{size:s(j)})}),n.jsx("button",{disabled:u,onClick:()=>{C()},className:"px-3 py-1.5 text-xs border border-amber-600/50 hover:bg-amber-600/10 text-amber-500 rounded-lg transition-colors disabled:opacity-50",children:u?a("dataStorage.cleaning"):a("dataStorage.cleanAll",{size:s(e.totalOrphanSize)})})]}),h&&n.jsx("div",{className:"text-xs text-fg-tertiary mt-2",children:h})]})}function dY({authUser:e,onClose:t,onSaved:r}){const{t:s}=pt("common"),[a,i]=g.useState(e.name||""),[l,d]=g.useState(e.email||""),[u,m]=g.useState(!1),[h,p]=g.useState(""),[y,x]=g.useState(e.avatarUrl),v=async j=>{if(j.preventDefault(),!a.trim()){p(s("profile.nameRequired"));return}if(l&&!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(l.trim())){p(s("profile.invalidEmail"));return}m(!0),p("");try{const{user:C}=await ie.auth.updateProfile(a.trim(),l.trim());r({...C,avatarUrl:y??C.avatarUrl})}catch{p(s("profile.failedToSave"))}finally{m(!1)}};return n.jsx("div",{className:"fixed inset-0 bg-black/60 flex items-center justify-center z-50",onClick:t,children:n.jsxs("form",{onSubmit:v,className:"bg-surface-secondary border border-border-default rounded-xl p-6 w-[400px] shadow-2xl",onClick:j=>j.stopPropagation(),children:[n.jsx("h3",{className:"text-base font-semibold mb-5",children:s("profile.editProfile")}),n.jsx("div",{className:"flex justify-center mb-5",children:n.jsx(y6,{currentUrl:y,name:a,size:72,targetType:"user",targetId:e.id,onUploaded:j=>x(j)})}),n.jsxs("div",{className:"space-y-3",children:[n.jsxs("div",{children:[n.jsx("label",{className:"block text-xs text-fg-tertiary font-medium mb-1",children:s("profile.name")}),n.jsx("input",{value:a,onChange:j=>i(j.target.value),className:"w-full px-3 py-2 bg-surface-elevated border border-border-default rounded-lg text-sm text-fg-primary focus:border-brand-500 outline-none"})]}),n.jsxs("div",{children:[n.jsx("label",{className:"block text-xs text-fg-tertiary font-medium mb-1",children:s("profile.email")}),n.jsx("input",{value:l,onChange:j=>d(j.target.value),type:"email",className:"w-full px-3 py-2 bg-surface-elevated border border-border-default rounded-lg text-sm text-fg-primary focus:border-brand-500 outline-none"})]}),h&&n.jsx("div",{className:"text-xs text-red-500 bg-red-500/10 border border-red-500/30 rounded-lg px-3 py-2",children:h})]}),n.jsxs("div",{className:"flex justify-end gap-3 mt-5",children:[n.jsx("button",{type:"button",onClick:t,className:"px-4 py-2 text-sm border border-border-default rounded-lg hover:bg-surface-elevated",children:s("cancel")}),n.jsx("button",{type:"submit",disabled:u,className:"px-4 py-2 text-sm bg-brand-600 hover:bg-brand-500 disabled:opacity-50 text-white rounded-lg",children:s(u?"saving":"save")})]})]})})}function uY(){const{t:e}=pt(["settings","common"]),[t,r]=g.useState(null),[s,a]=g.useState(!0),[i,l]=g.useState(!1),[d,u]=g.useState(null),[m,h]=g.useState(!1),p=Ch(),y=g.useCallback(async()=>{try{const N=await ie.settings.getRemote();r(N)}catch{r(null)}finally{a(!1)}},[]);g.useEffect(()=>{y()},[y]),g.useEffect(()=>pn.on("remote:status",N=>{const S=N.payload;S&&(r(S),l(!1))}),[]);const x=async()=>{l(!0),u(null);try{t?.enabled?(await ie.settings.disableRemote(),await y(),l(!1)):(Wn.isAuthenticated()||await da(),await ie.settings.enableRemote())}catch(N){u(String(N instanceof Error?N.message:N)),l(!1)}},v=async()=>{try{await da(),await y()}catch{}},j=()=>{t?.remoteUrl&&(navigator.clipboard.writeText(t.remoteUrl),h(!0),setTimeout(()=>h(!1),2e3))},C=i||t?.enabled&&!t?.connected&&t?.state!=="idle",w=t?.remoteUrl??null;return n.jsx(pi,{title:e("settings:remoteAccess.title"),children:n.jsxs("div",{className:"space-y-4",children:[n.jsx("p",{className:"text-sm text-content-secondary",children:e("settings:remoteAccess.description")}),Wn.isAuthenticated()?n.jsxs("div",{className:"flex items-center gap-2 text-sm text-content-secondary",children:[n.jsx("span",{className:"w-2 h-2 rounded-full bg-green-500"}),e("settings:remoteAccess.signedInAs")," ",n.jsx("strong",{children:p?.username??p?.displayName})]}):n.jsxs("div",{className:"flex items-center gap-3 p-3 rounded-lg bg-amber-500/10 border border-amber-500/20",children:[n.jsx("svg",{className:"w-5 h-5 text-amber-500 shrink-0",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:n.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 9v2m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"})}),n.jsx("span",{className:"text-sm text-amber-600 dark:text-amber-400",children:e("settings:remoteAccess.loginRequired")}),n.jsx("button",{onClick:v,className:"ml-auto px-3 py-1.5 text-xs font-medium bg-brand-600 hover:bg-brand-500 text-white rounded-lg transition-colors",children:e("settings:remoteAccess.signIn")})]}),Wn.isAuthenticated()&&n.jsxs("div",{className:"space-y-4",children:[n.jsxs("div",{className:"flex items-center justify-between",children:[n.jsxs("div",{className:"flex items-center gap-3",children:[n.jsx("button",{onClick:x,disabled:i||s,className:`relative w-12 h-6 rounded-full transition-colors duration-200 ${t?.enabled?"bg-brand-600":"bg-gray-300 dark:bg-gray-600"} ${i||s?"opacity-50 cursor-not-allowed":"cursor-pointer"}`,children:n.jsx("span",{className:`block w-5 h-5 bg-white rounded-full shadow transform transition-transform duration-200 ${t?.enabled?"translate-x-6":"translate-x-0.5"}`})}),n.jsx("span",{className:"text-sm font-medium",children:C?e("settings:remoteAccess.connecting"):t?.enabled?e("settings:remoteAccess.enabled"):e("settings:remoteAccess.disabled")}),C&&n.jsx(nj,{})]}),t?.enabled&&n.jsxs("div",{className:`flex items-center gap-1.5 text-xs ${t.connected?"text-green-600 dark:text-green-400":t.state==="registering"||t.state==="connecting"?"text-blue-600 dark:text-blue-400":"text-amber-600 dark:text-amber-400"}`,children:[n.jsx("span",{className:`w-2 h-2 rounded-full ${t.connected?"bg-green-500 animate-pulse":t.state==="registering"||t.state==="connecting"?"bg-blue-500 animate-pulse":"bg-amber-500"}`}),t.connected?e("settings:remoteAccess.connected"):t.state==="registering"?e("settings:remoteAccess.registering"):t.state==="connecting"?e("settings:remoteAccess.connecting"):e("settings:remoteAccess.disconnected"),t.connected&&t.peerCount>0&&n.jsxs(n.Fragment,{children:[" · ",e("settings:remoteAccess.peerCount",{count:t.peerCount})]}),(t.state==="registering"||t.state==="connecting")&&n.jsx(nj,{})]})]}),d&&n.jsx("div",{className:"p-2 rounded-lg bg-red-500/10 text-red-500 text-sm",children:d}),t?.enabled&&t.peers&&t.peers.length>0&&n.jsxs("div",{className:"p-4 rounded-lg bg-surface-elevated border border-border-default space-y-2",children:[n.jsx("label",{className:"text-xs text-content-tertiary uppercase tracking-wider",children:e("settings:remoteAccess.connectedPeers")}),n.jsx("div",{className:"space-y-2 mt-1",children:t.peers.map(N=>n.jsxs("div",{className:"flex items-center gap-3 px-3 py-2 rounded-lg bg-surface-inset",children:[n.jsx("span",{className:`w-2 h-2 rounded-full shrink-0 ${N.transport==="p2p"?"bg-green-500":N.transport==="relay"?"bg-blue-500":"bg-amber-500 animate-pulse"}`}),n.jsxs("div",{className:"flex-1 min-w-0",children:[n.jsxs("div",{className:"text-sm font-mono text-content-primary truncate",children:[N.peerId.slice(0,8),"..."]}),n.jsx("div",{className:"text-xs text-content-tertiary",children:e("settings:remoteAccess.connectedSince",{time:new Date(N.connectedAt).toLocaleTimeString()})})]}),n.jsx("span",{className:`px-2 py-0.5 text-xs font-medium rounded-full ${N.transport==="p2p"?"bg-green-500/10 text-green-600 dark:text-green-400":N.transport==="relay"?"bg-blue-500/10 text-blue-600 dark:text-blue-400":"bg-amber-500/10 text-amber-600 dark:text-amber-400"}`,children:N.transport==="p2p"?"P2P":N.transport==="relay"?"Relay":e("settings:remoteAccess.peerConnecting")})]},N.peerId))})]}),t?.enabled&&t.remoteUrl&&n.jsxs("div",{className:"p-4 rounded-lg bg-surface-elevated border border-border-default space-y-3",children:[n.jsxs("div",{children:[n.jsx("label",{className:"text-xs text-content-tertiary uppercase tracking-wider",children:e("settings:remoteAccess.url")}),n.jsxs("div",{className:"flex items-center gap-2 mt-1",children:[n.jsx("code",{className:"flex-1 px-3 py-1.5 text-sm bg-surface-inset rounded font-mono truncate",children:t.remoteUrl}),n.jsx("button",{onClick:j,className:`px-2 py-1.5 text-xs border rounded transition-colors ${m?"border-green-500 text-green-600 dark:text-green-400":"border-border-default hover:bg-surface-elevated"}`,children:e(m?"settings:remoteAccess.copied":"settings:remoteAccess.copy")})]})]}),w&&n.jsxs("div",{children:[n.jsx("label",{className:"text-xs text-content-tertiary uppercase tracking-wider",children:e("settings:remoteAccess.qrCode")}),n.jsx("p",{className:"text-xs text-content-secondary mt-0.5 mb-2",children:e("settings:remoteAccess.scanQr")}),n.jsx(mY,{url:w})]})]})]})]})})}function nj(){return n.jsxs("svg",{className:"w-4 h-4 animate-spin text-content-secondary",viewBox:"0 0 24 24",fill:"none",children:[n.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),n.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"})]})}function mY({url:e}){const t=g.useRef(null),[r,s]=g.useState(!1);return g.useEffect(()=>{const a=t.current;a&&(s(!1),Bd(()=>import("./browser-C8s_Cnn0.js").then(i=>i.b),[]).then(i=>{i.toCanvas(a,e,{width:200,margin:2,color:{dark:"#000000",light:"#ffffff"},errorCorrectionLevel:"M"})}).catch(()=>s(!0)))},[e]),r?n.jsx("a",{href:e,target:"_blank",rel:"noopener",className:"text-sm text-brand-500 underline",children:e}):n.jsx("div",{className:"inline-block p-2 bg-white rounded-lg",children:n.jsx("canvas",{ref:t,className:"block",style:{width:160,height:160}})})}const fY={multi_user:"👥",unlimited_teams:"🏢",unlimited_tools:"⚡",sso:"🔐",audit_enhanced:"📋",multi_instance:"🌐",offline_license:"📡"};function hY({authUser:e}){const{t}=pt(["settings","common"]),r=()=>window.location.hash.slice(1).split("/")[1]==="users"?"users":"orgLicense",[s,a]=g.useState(r),i=[{id:"orgLicense",label:t("account.sectionOrgLicense")},{id:"users",label:t("account.sectionUsers")}];return n.jsxs("div",{className:"space-y-6",children:[n.jsxs("div",{children:[n.jsx("h2",{className:"text-lg font-semibold text-fg-primary mb-1",children:t("account.title")}),n.jsx("p",{className:"text-xs text-fg-tertiary",children:t("account.subtitle")})]}),n.jsx("div",{className:"flex gap-1 p-1 bg-surface-elevated rounded-lg border border-border-default",children:i.map(l=>n.jsx("button",{onClick:()=>a(l.id),className:`flex-1 px-3 py-2 text-xs font-medium rounded-md transition-all ${s===l.id?"bg-surface-primary text-fg-primary shadow-sm border border-border-default":"text-fg-tertiary hover:text-fg-secondary"}`,children:l.label},l.id))}),s==="orgLicense"&&n.jsx(pY,{}),s==="users"&&n.jsx(oY,{authUser:e})]})}function pY(){const{t:e}=pt(["settings","common"]),[t,r]=g.useState([]),[s,a]=g.useState(()=>{try{return localStorage.getItem("markus_selected_org_id")}catch{return null}}),i=g.useCallback(je=>{a(Re=>{const We=typeof je=="function"?je(Re):je;try{We?localStorage.setItem("markus_selected_org_id",We):localStorage.removeItem("markus_selected_org_id")}catch{}return We})},[]),[l,d]=g.useState([]),[u,m]=g.useState([]),[h,p]=g.useState(""),[y,x]=g.useState(""),[v,j]=g.useState("member"),[C,w]=g.useState(!1),[N,S]=g.useState(!1),[T,E]=g.useState(null),[R,I]=g.useState(!0),[z,B]=g.useState(!1),[D,V]=g.useState(null),[Y,F]=g.useState(null),[L,O]=g.useState(""),[M,$]=g.useState(!1),[W,U]=g.useState(!1),[H,q]=g.useState(null);g.useRef(null);const Z=g.useCallback((je=!1)=>{I(!0);let Re=!1;Promise.all([ie.hubOrgs.mine().catch(We=>(Re=!0,je&&E({type:"err",text:We instanceof Error?We.message:e("org.loadFailed")}),{orgs:[]})),ie.hubOrgs.invitations().catch(()=>({invitations:[]}))]).then(([We,Vt])=>{r(We.orgs),m(Vt.invitations),We.orgs.length>0?(i(ln=>ln&&We.orgs.some(vn=>vn.id===ln)?ln:We.orgs.find(vn=>vn.license?.plan==="enterprise")?.id??We.orgs[0].id),p(ln=>ln||(We.orgs.find(vn=>vn.license?.plan==="enterprise")?.name??We.orgs[0].name))):je&&!Re&&E({type:"err",text:e("org.noOrgAfterConnect")})}).finally(()=>I(!1))},[i,e]);g.useEffect(()=>{if(!Ch()&&!gi()){I(!1);return}Z()},[Z]),g.useEffect(()=>{if(!s)return;ie.hubOrgs.members(s).then(Re=>d(Re.members)).catch(()=>{});const je=t.find(Re=>Re.id===s);je&&p(je.name)},[s]);const _=t.find(je=>je.id===s),J=_?.role==="owner",X=_?.role==="admin",ee=J||X,te={owner:e("org.roleOwner"),admin:e("org.roleAdmin"),member:e("org.roleMember")},G=je=>te[je]??je,ue={"Trial already used for this account":"license.trialAlreadyUsed","License not found or not active":"license.licenseNotFound","Instance limit reached":"license.instanceLimitReached"},Se=je=>{const Re=ue[je];return Re?e(Re):je},Ce=g.useCallback((je=!1)=>{U(!0),(je?ie.license.refresh():ie.license.get()).then(We=>V(We)).catch(()=>{}).finally(()=>setTimeout(()=>U(!1),400))},[]);g.useEffect(()=>{Ce(!0)},[Ce]);const Be=t.length>0,Ne=_?.license?.plan==="enterprise",he=s&&Be?Ne:D?.plan==="enterprise",_e=!Be||he&&D?.orgId!=null&&D.orgId===s,Ee=!Be||J,Ye=_e?D?.validUntil:_?.license?.validUntil,Ze=_e?D?.maxSeats:_?.license?.maxSeats,mt=_e?D?.usedSeats??0:_?.memberCount??0,it=Ye?Math.max(0,Math.ceil((new Date(Ye).getTime()-Date.now())/864e5)):null,Lt=he&&Ee&&it!==null&&it<=60,ht=["multi_user","multi_instance"],ne={multi_user:e("license.featureMultiUser"),multi_instance:e("license.featureMultiInstance")},me=async()=>{if(!(!s||!h.trim()))try{await ie.hubOrgs.update(s,{name:h.trim()}),r(je=>je.map(Re=>Re.id===s?{...Re,name:h.trim()}:Re)),E({type:"ok",text:e("org.nameSaved")})}catch(je){E({type:"err",text:je instanceof Error?je.message:"Failed"})}},be=_?.license?.maxSeats!=null&&_.memberCount>=_.license.maxSeats,se=async()=>{if(!s||!y.trim())return;const je=y.trim().toLowerCase();if(!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(je)){E({type:"err",text:e("org.invalidEmail")});return}w(!0),E(null);try{await ie.hubOrgs.invite(s,{email:je,role:v}),x(""),j("member"),E({type:"ok",text:e("org.invited")}),ie.hubOrgs.members(s).then(Re=>d(Re.members)).catch(()=>{})}catch(Re){const We=Re instanceof Error?Re.message:"",Vt={"User not found":e("org.errorUserNotFound"),"User is already a member or has a pending invitation":e("org.errorAlreadyMember"),"An invitation has already been sent to this email":e("org.errorAlreadySent")};E({type:"err",text:Vt[We]??(We||e("org.errorInviteFailed"))})}finally{w(!1)}},fe=async je=>{if(s)try{await ie.hubOrgs.removeMember(s,je),d(Re=>Re.filter(We=>We.userId!==je))}catch(Re){E({type:"err",text:Re instanceof Error?Re.message:"Failed"})}},He=async je=>{try{await ie.hubOrgs.acceptInvitation(je),m(We=>We.filter(Vt=>Vt.orgId!==je));const Re=await ie.hubOrgs.mine();r(Re.orgs)}catch(Re){E({type:"err",text:Re instanceof Error?Re.message:"Failed"})}},Ae=async()=>{if(s)try{await ie.hubOrgs.leave(s),S(!1),r(je=>je.filter(Re=>Re.id!==s)),i(t.length>1?t.find(je=>je.id!==s).id:null)}catch(je){E({type:"err",text:je instanceof Error?je.message:"Failed"}),S(!1)}},et=async(je,Re)=>{if(s)try{await ie.hubOrgs.updateMemberRole(s,je,Re),d(We=>We.map(Vt=>Vt.userId===je?{...Vt,role:Re}:Vt)),E({type:"ok",text:e("org.roleUpdated")})}catch(We){E({type:"err",text:We instanceof Error?We.message:"Failed"})}},pe=async()=>{if(L.trim()){$(!0),q(null);try{await da()}catch{q({type:"err",text:e("license.activationFailed")}),$(!1);return}try{const je=await ie.license.activate(L.trim());je.success?(q({type:"ok",text:e("license.activated")}),O(""),Ce(!0)):q({type:"err",text:Se(je.error??e("license.activationFailed"))})}catch(je){q({type:"err",text:Se(je instanceof Error&&je.message||e("license.activationFailed"))})}finally{$(!1)}}},Fe=async()=>{$(!0),q(null);try{await da()}catch{q({type:"err",text:e("license.trialFailed")}),$(!1);return}try{const je=await ie.license.trial();je.success?(q({type:"ok",text:e("license.trialActivated")}),Ce(!0)):q({type:"err",text:Se(je.error??e("license.trialFailed"))})}catch(je){q({type:"err",text:Se(je instanceof Error&&je.message||e("license.trialFailed"))})}finally{$(!1)}},Ve=(je,Re)=>{navigator.clipboard.writeText(je).then(()=>{F(Re),setTimeout(()=>F(null),2e3)}).catch(()=>{})},nt=()=>{const Re=[[e("license.username"),D?.username],[e("license.userId",{defaultValue:"User ID"}),D?.hubUserId],[e("license.orgId",{defaultValue:"Org ID"}),D?.orgId],[e("license.licenseKey"),D?.licenseKey],[e("license.instanceId"),D?.instanceId]].filter(([,We])=>We).map(([We,Vt])=>`${We}: ${Vt}`).join(`
658
+ `)){Ls(!0),Ns(Pt.toLowerCase()),Ss(0);return}}}Ls(!1)},U0=ae=>{const Me=Bn.current?.selectionStart??Re.length,ze=Re.slice(0,Me).lastIndexOf("@"),wt=Re.slice(Me),Je=ae.includes(" ")?`@[${ae}]`:`@${ae}`,Pt=Re.slice(0,ze)+Je+" "+wt;We(Pt),Ls(!1),Ss(0);const zt=ze+Je.length+1;requestAnimationFrame(()=>{Bn.current?.setSelectionRange(zt,zt)})},wc=10*1024*1024,Hd=5,V0=new Set(["application/pdf","application/vnd.openxmlformats-officedocument.wordprocessingml.document","application/vnd.openxmlformats-officedocument.spreadsheetml.sheet","application/vnd.openxmlformats-officedocument.presentationml.presentation","application/vnd.ms-excel","application/msword","text/csv","text/html","application/json","application/xml","text/xml","application/epub+zip"]),Li=g.useCallback(ae=>ae.type.startsWith("image/")||V0.has(ae.type),[]),Ml=ae=>ae.dataUrl.startsWith("data:image/"),K0=(ae,Me)=>{if(Ml({dataUrl:Me}))return null;const ge=ae.split(".").pop()?.toLowerCase()??"";return{pdf:"📄",docx:"📝",doc:"📝",xlsx:"📊",xls:"📊",pptx:"📎",csv:"📊",json:"🔧",xml:"🔧",html:"🌐",epub:"📚"}[ge]??"📁"},Bo=g.useCallback(ae=>{const Me=Array.from(ae).filter(Li);if(Me.length!==0)for(const ge of Me){if(ge.size>wc)continue;const ze=new FileReader;ze.onload=()=>{const wt=ze.result;$n(Je=>Je.length>=Hd||Je.some(Pt=>Pt.dataUrl===wt)?Je:[...Je,{id:`img_${Date.now()}_${Math.random().toString(36).slice(2,6)}`,dataUrl:wt,name:ge.name}])},ze.readAsDataURL(ge)}},[Li]),W0=g.useCallback(ae=>{$n(Me=>Me.filter(ge=>ge.id!==ae))},[]),op=g.useCallback(ae=>{const Me=ae.clipboardData?.files;if(Me&&Me.length>0){const ge=Array.from(Me).filter(Li);ge.length>0&&(ae.preventDefault(),Bo(ge))}},[Bo,Li]),lp=g.useCallback(ae=>{ae.preventDefault();const Me=ae.dataTransfer?.files;Me&&Me.length>0&&Bo(Array.from(Me).filter(Li))},[Bo,Li]),cp=g.useCallback(ae=>{ae.preventDefault()},[]),Jr=u.find(ae=>ae.id===be),Fd=t?.name??a("page.fallbackYou"),Qs=un[un.length-1],Dl=en&&Qs?.sender==="agent",G0=Gn&&Qs?.sender==="agent",qd=g.useMemo(()=>{if(ne!=="channel")return null;if(fe.startsWith("group:custom:")){const Me=Dt.find(ge=>ge.channelKey===fe);return Me?.members?new Set(Me.members.filter(ge=>ge.type==="agent").map(ge=>ge.id)):null}if(!yr)return null;const ae=Pr.find(Me=>Me.id===yr);return ae?new Set(ae.members.filter(Me=>Me.type==="agent").map(Me=>Me.id)):null},[ne,fe,yr,Pr,Dt]),Pi=u.filter(ae=>qd?qd.has(ae.id):!0).filter(ae=>ae.name.toLowerCase().includes(Yn)),kc=h.find(ae=>ae.id===Ae),Rl=Ae===t?.id||!Ae,ia=Dt.find(ae=>ae.channelKey===fe);g.useEffect(()=>{if(r||!fe.startsWith("group:custom:"))return;const ae=Dt.find(Me=>Me.channelKey===fe);!ae||ae.members||ie.groupChats.getById(ae.id).then(Me=>{Me.chat.members&&Pn(ge=>ge.map(ze=>ze.id===ae.id?{...ze,members:Me.chat.members}:ze))}).catch(()=>{})},[r,fe,Dt]);const ao=ne==="channel"?ia?.name??fe:ne==="direct"?Jr?.name??a("page.selectAgent"):ne==="dm"?Rl?a("chat.myNotes"):kc?.name??a("page.directMessage"):a("page.chatTitle"),Ud=ne==="channel"?ia?a("page.placeholder.channel",{name:ia.name}):a("page.placeholder.channelWithMention",{name:fe}):ne==="dm"?Rl?a("page.placeholder.dmSelf"):a("page.placeholder.dmOther",{name:kc?.name??""}):a(be?"page.placeholder.direct":"page.placeholder.noAgent"),Il=v&&N==="chat";return n.jsxs("div",{ref:L,className:"flex-1 overflow-hidden flex relative",children:[n.jsx(cG,{authUser:t,agents:u,teams:Pr,humans:h,tasks:ds,externalAgents:ba,groupChats:Dt,chatMode:ne,selectedAgent:be,activeChannel:fe,activeDmUserId:Ae,previewMode:r,onSelectAgent:ae=>{me("direct"),se(ae),z("chat"),On(!1),v&&E()},onSelectChannel:ae=>{me("channel"),He(ae),z("chat"),On(!1),v&&E()},onSelectDm:ae=>{me("dm"),et(ae),z("chat"),On(!1),v&&E()},onSelectTeam:ae=>{const Me=Dt.find(ge=>ge.type==="team"&&ge.teamId===ae);v?R(ae):Me&&(me("channel"),He(Me.channelKey),z("chat"),On(!1),!V&&!O&&Y(!0))},selectedTeamId:yr??(ne==="direct"&&Jr?.teamId?Jr.teamId:null),onRefreshTeams:zs,onRefreshAgents:Zr,onRefreshHumans:Sa,onRefreshGroupChats:ka,onViewProfile:it,onManageGroupMembers:ae=>{me("channel"),He(ae),z("chat"),On(!0),v&&E()},unreadByAgent:wa,unreadByChannel:zr,width:v?void 0:D.width,onResizeStart:v?void 0:D.onResizeStart,hidden:v&&N!=="roster",initialLoading:y}),v&&N==="team"&&S&&(()=>{const ae=Pr.find(ze=>ze.id===S);if(!ae)return null;const Me=u.filter(ze=>ze.teamId===S),ge=Dt.find(ze=>ze.type==="team"&&ze.teamId===S);return n.jsxs("div",{className:"flex-1 overflow-hidden flex flex-col min-w-0",children:[n.jsxs("div",{className:"flex items-center gap-2 px-3 h-12 shrink-0 border-b border-border-default",children:[n.jsx("button",{onClick:()=>{window.location.hash=De.TEAM},className:"p-1.5 -ml-1 rounded-lg hover:bg-surface-overlay transition-colors shrink-0 text-fg-secondary",children:n.jsx("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:n.jsx("polyline",{points:"15 18 9 12 15 6"})})}),n.jsxs("div",{className:"flex items-center gap-2 flex-1 min-w-0",children:[n.jsx("div",{className:"w-8 h-8 rounded-lg bg-brand-500/15 flex items-center justify-center shrink-0",children:n.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:"text-brand-500",children:[n.jsx("path",{d:"M17 21v-2a4 4 0 0 0-4-4H5a4 4 0 0 0-4 4v2"}),n.jsx("circle",{cx:"9",cy:"7",r:"4"}),n.jsx("path",{d:"M23 21v-2a4 4 0 0 0-3-3.87"}),n.jsx("path",{d:"M16 3.13a4 4 0 0 1 0 7.75"})]})}),n.jsxs("div",{className:"min-w-0",children:[n.jsx("h3",{className:"text-sm font-semibold text-fg-primary truncate",children:ae.name}),n.jsx("p",{className:"text-[10px] text-fg-tertiary",children:a("chat.members_other",{count:ae.members?.length||Me.length})})]})]})]}),n.jsxs("div",{className:"flex-1 overflow-y-auto px-3 py-3 space-y-1",children:[ge&&(()=>{const ze=zr[ge.channelKey]??0;return n.jsxs("button",{onClick:()=>{me("channel"),He(ge.channelKey),z("chat"),E()},className:"w-full flex items-center gap-2.5 px-2.5 py-2.5 rounded-xl hover:bg-surface-overlay transition-colors",children:[n.jsx("div",{className:"w-9 h-9 rounded-xl bg-brand-500/15 flex items-center justify-center shrink-0",children:n.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:"text-brand-500",children:n.jsx("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"})})}),n.jsxs("div",{className:"flex-1 min-w-0 text-left",children:[n.jsx("div",{className:"text-sm font-medium text-fg-primary truncate",children:ge.name}),n.jsx("div",{className:"text-[10px] text-fg-tertiary",children:a("chat.groupChat")})]}),ze>0?n.jsx("span",{className:"min-w-[16px] h-[16px] flex items-center justify-center text-[9px] font-semibold text-white bg-red-500 rounded-full px-1 leading-none shrink-0",children:ze}):n.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"text-fg-tertiary shrink-0",children:n.jsx("polyline",{points:"9 18 15 12 9 6"})})]})})(),Me.length>0&&n.jsxs(n.Fragment,{children:[n.jsx("p",{className:"text-[10px] font-semibold text-fg-muted uppercase tracking-wider px-2.5 pt-2",children:a("chat.agents")}),Me.map(ze=>{const wt=wa.get(ze.id)??0;return n.jsxs("button",{onClick:()=>{me("direct"),se(ze.id),z("chat"),E()},className:"w-full flex items-center gap-2.5 px-2.5 py-2.5 rounded-xl hover:bg-surface-overlay transition-colors",children:[n.jsx(Nr,{name:ze.name||"Agent",avatarUrl:ze.avatarUrl,size:36}),n.jsxs("div",{className:"flex-1 min-w-0 text-left",children:[n.jsx("div",{className:"text-sm font-medium text-fg-primary truncate",children:ze.name}),n.jsx("div",{className:"text-[10px] text-fg-tertiary truncate",children:ze.role||ze.status})]}),wt>0?n.jsx("span",{className:"min-w-[16px] h-[16px] flex items-center justify-center text-[9px] font-semibold text-white bg-red-500 rounded-full px-1 leading-none shrink-0",children:wt}):n.jsx("span",{className:`w-2 h-2 rounded-full shrink-0 ${ze.status==="active"||ze.status==="idle"?"bg-green-500":ze.status==="working"||ze.status==="busy"?"bg-blue-500":ze.status==="paused"?"bg-amber-500":"bg-gray-400"}`})]},ze.id)})]})]})]})})(),V&&!O&&!v&&(()=>{const ae=yr??(ne==="direct"?Jr?.teamId:void 0);if(!ae)return null;const Me=Pr.find(ze=>ze.id===ae);if(!Me)return null;const ge=Dt.find(ze=>ze.type==="team"&&ze.teamId===ae);return n.jsx(bk,{team:Me,agents:u,humans:h,authUser:t,groupChat:ge,chatMode:ne,selectedAgent:be,activeChannel:fe,teams:Pr,onSelectAgent:ze=>{me("direct"),se(ze),z("chat"),On(!1)},onSelectChannel:ze=>{me("channel"),He(ze),z("chat"),On(!1)},onSelectDm:ze=>{me("dm"),et(ze),z("chat"),On(!1)},onBack:()=>Y(!1),onViewProfile:it,onRefreshAgents:Zr,onRefreshTeams:zs,unreadByAgent:wa,width:F.width,onResizeStart:F.onResizeStart})})(),$&&!v&&(()=>{const ae=yr??(ne==="direct"?Jr?.teamId:void 0);if(!ae)return null;const Me=Pr.find(ze=>ze.id===ae);if(!Me)return null;const ge=Dt.find(ze=>ze.type==="team"&&ze.teamId===ae);return n.jsxs("div",{"data-l2-floating":!0,className:"absolute z-30 inset-0",style:{left:D.width+6},children:[n.jsx("div",{className:"absolute inset-0 bg-black/20",onClick:()=>W(!1)}),n.jsx("div",{className:"relative h-full",style:{width:F.width+8},children:n.jsx(bk,{team:Me,agents:u,humans:h,authUser:t,groupChat:ge,chatMode:ne,selectedAgent:be,activeChannel:fe,teams:Pr,onSelectAgent:ze=>{me("direct"),se(ze),z("chat"),On(!1),W(!1)},onSelectChannel:ze=>{me("channel"),He(ze),z("chat"),On(!1),W(!1)},onSelectDm:ze=>{me("dm"),et(ze),z("chat"),On(!1),W(!1)},onBack:()=>W(!1),onViewProfile:ze=>{it(ze),W(!1)},onRefreshAgents:Zr,onRefreshTeams:zs,unreadByAgent:wa,width:F.width})})]})})(),(!v||Il)&&n.jsxs("div",{className:`flex-1 overflow-hidden flex flex-col ${v?"min-w-0":"min-w-[400px]"}`,children:[n.jsxs("div",{className:"shrink-0 relative pb-2",children:[v?n.jsxs(n.Fragment,{children:[n.jsxs("div",{className:"flex items-center px-3 h-11 gap-2",children:[n.jsx("button",{onClick:()=>{window.location.hash=T.current},className:"text-fg-secondary hover:text-fg-primary transition-colors p-1 -ml-1 shrink-0",children:n.jsx("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:n.jsx("polyline",{points:"15 18 9 12 15 6"})})}),n.jsx("span",{className:"font-semibold text-sm truncate min-w-0 flex-1",children:ao}),ne==="direct"&&Jr&&n.jsx(Xk,{agent:Jr,tasks:ds,onViewProfile:it})]}),n.jsxs("div",{className:"flex items-center px-3 h-9 gap-1 border-t border-border-default/40",children:[n.jsx("button",{onClick:()=>{No(I)?history.back():z("chat")},className:`px-2.5 py-1 text-xs font-medium rounded-md transition-colors ${I==="chat"?"bg-brand-500/15 text-brand-500":"text-fg-tertiary"}`,children:a("page.chatTitle")}),n.jsx("button",{onClick:()=>{No(I)||Ee()},className:`px-2.5 py-1 text-xs font-medium rounded-md transition-colors ${No(I)?"bg-brand-500/15 text-brand-500":"text-fg-tertiary"}`,children:a(ne==="channel"?"page.teamTab":"page.profileTab")}),n.jsx("div",{className:"flex-1"}),n.jsx("button",{onClick:()=>{cr(!on),on||(dr(""),fr([]))},className:`p-1 rounded-md transition-colors shrink-0 ${on?"bg-brand-500/15 text-brand-500":"text-fg-tertiary"}`,children:n.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,children:n.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M21 21l-5.197-5.197m0 0A7.5 7.5 0 105.196 5.196a7.5 7.5 0 0010.607 10.607z"})})}),ne==="channel"&&ia?.type==="custom"&&n.jsxs("button",{onClick:()=>On(!nr),className:`text-[11px] px-2 py-1 rounded-md font-medium shrink-0 flex items-center gap-1 ${nr?"bg-brand-500/15 text-brand-500":"text-fg-tertiary"}`,children:[n.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("path",{d:"M17 21v-2a4 4 0 0 0-4-4H5a4 4 0 0 0-4 4v2"}),n.jsx("circle",{cx:"9",cy:"7",r:"4"}),n.jsx("path",{d:"M23 21v-2a4 4 0 0 0-3-3.87"}),n.jsx("path",{d:"M16 3.13a4 4 0 0 1 0 7.75"})]}),ia.members?.length??ia.memberCount??0]}),ne==="direct"&&!No(I)&&n.jsxs(n.Fragment,{children:[n.jsx("button",{onClick:so,className:"text-[11px] text-brand-500 px-2 py-1 rounded-md bg-brand-500/10 font-medium shrink-0",children:a("page.newChatPlus")}),n.jsx("button",{ref:lt,onClick:()=>$t(!Tt),className:`p-1 rounded-md transition-colors shrink-0 ${Tt?"bg-surface-overlay text-fg-primary":"text-fg-tertiary"}`,title:a("page.historyTitle"),children:n.jsx("svg",{className:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:1.5,children:n.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M12 6v6h4.5m4.5 0a9 9 0 11-18 0 9 9 0 0118 0z"})})})]})]})]}):(()=>{const ae=yr?Pr.find(St=>St.id===yr):void 0,Me=ne==="direct"&&be?GG:ne==="channel"&&yr?YG:["chat"],ge=async()=>{const St=G.trim();if(!St){te(!1);return}try{ne==="direct"&&be?(await ie.agents.updateConfig(be,{name:St}),Zr()):ne==="channel"&&yr&&(await ie.teams.update(yr,{name:St}),zs())}catch{}te(!1)},ze=async()=>{try{ne==="direct"&&be?(await ie.agents.updateConfig(be,{roleDescription:Be}),Zr()):ne==="channel"&&yr&&(await ie.teams.update(yr,{description:Be}),zs())}catch{}Ce(!1)},wt=ne==="direct"?Jr?.name:ne==="channel"?ae?.name??ia?.name:kc?.name??"",Je=ne==="direct"?Jr?.role||"":ne==="channel"&&ae?.description||"",Pt=ne==="direct"?Jr?.avatarUrl:void 0,zt=wt||"U",ut=ne==="direct"&&be||ne==="channel"&&yr;return n.jsxs("div",{className:"flex flex-col",children:[n.jsxs("div",{className:"flex items-center px-4 h-14 gap-2.5",children:[(!V||O)&&(ne==="channel"&&yr||ne==="direct"&&Jr?.teamId)&&n.jsx("button",{onClick:U,className:`w-8 h-8 flex items-center justify-center rounded-lg transition-colors shrink-0 ${$?"bg-brand-500/15 text-brand-500":"text-fg-tertiary hover:text-fg-secondary hover:bg-surface-elevated"}`,title:"Toggle team panel",children:n.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2",ry:"2"}),n.jsx("line",{x1:"9",y1:"3",x2:"9",y2:"21"})]})}),ut&&(ne==="channel"&&yr?n.jsx("div",{className:"w-9 h-9 rounded-xl bg-brand-600 text-white flex items-center justify-center text-sm font-bold shrink-0",children:n.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("path",{d:"M17 21v-2a4 4 0 0 0-4-4H5a4 4 0 0 0-4 4v2"}),n.jsx("circle",{cx:"9",cy:"7",r:"4"}),n.jsx("path",{d:"M23 21v-2a4 4 0 0 0-3-3.87"}),n.jsx("path",{d:"M16 3.13a4 4 0 0 1 0 7.75"})]})}):n.jsx(Nr,{name:zt,avatarUrl:Pt,size:36,className:"rounded-xl shrink-0"})),ut?n.jsxs("div",{className:"flex-1 min-w-0",children:[n.jsxs("div",{className:"flex items-center gap-2",children:[ee?n.jsx("input",{ref:he,value:G,onChange:St=>ue(St.target.value),onBlur:ge,onKeyDown:St=>{St.key==="Enter"&&ge(),St.key==="Escape"&&te(!1)},className:"text-sm font-semibold bg-transparent border-b border-brand-500 outline-none py-0 px-0 min-w-[80px] max-w-[240px]",autoFocus:!0}):n.jsx("span",{className:"text-sm font-semibold truncate cursor-pointer hover:text-brand-500 transition-colors",onClick:()=>{ue(wt??""),te(!0)},title:"Click to edit name",children:wt}),ne==="direct"&&Jr&&n.jsx(Xk,{agent:Jr,tasks:ds,onViewProfile:it})]}),(ne==="direct"||ne==="channel"&&yr)&&(Se?n.jsx("input",{ref:_e,value:Be,onChange:St=>Ne(St.target.value),onBlur:ze,onKeyDown:St=>{St.key==="Enter"&&ze(),St.key==="Escape"&&Ce(!1)},className:"text-[11px] text-fg-tertiary bg-transparent border-b border-brand-500/50 outline-none py-0 px-0 w-full max-w-[400px] mt-0.5",placeholder:"Add description...",autoFocus:!0}):n.jsx("div",{className:"text-[11px] text-fg-tertiary truncate cursor-pointer hover:text-fg-secondary transition-colors mt-0.5",onClick:()=>{Ne(Je),Ce(!0)},title:"Click to edit description",children:Je||"No description"}))]}):n.jsxs("div",{className:"flex-1 min-w-0 flex items-center gap-2",children:[n.jsx("span",{className:"font-semibold text-sm truncate",children:ao}),ne==="dm"&&n.jsx("span",{className:"text-xs text-fg-tertiary",children:Rl?a("page.privateNotepad"):""})]}),n.jsxs("div",{className:"ml-auto flex items-center gap-2 shrink-0",children:[n.jsx("button",{onClick:()=>{cr(!on),on||(dr(""),fr([]))},className:`p-1.5 rounded-md transition-colors ${on?"bg-brand-500/15 text-brand-500":"text-fg-tertiary hover:text-fg-secondary hover:bg-surface-elevated"}`,title:a("page.searchMessages"),children:n.jsx("svg",{className:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:1.5,children:n.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M21 21l-5.197-5.197m0 0A7.5 7.5 0 105.196 5.196a7.5 7.5 0 0010.607 10.607z"})})}),ne==="channel"&&ia?.type==="custom"&&n.jsxs("button",{onClick:()=>On(!nr),className:`text-xs px-2.5 py-1 rounded-md border transition-colors flex items-center gap-1.5 ${nr?"bg-brand-500/15 text-brand-500 border-brand-500/30":"text-fg-secondary hover:text-fg-primary border-border-default hover:bg-surface-elevated"}`,children:[n.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("path",{d:"M17 21v-2a4 4 0 0 0-4-4H5a4 4 0 0 0-4 4v2"}),n.jsx("circle",{cx:"9",cy:"7",r:"4"}),n.jsx("path",{d:"M23 21v-2a4 4 0 0 0-3-3.87"}),n.jsx("path",{d:"M16 3.13a4 4 0 0 1 0 7.75"})]}),ia.members?.length??ia.memberCount??0]}),ne==="direct"&&Jr&&I==="chat"&&n.jsxs("div",{className:"flex items-center gap-1.5",children:[n.jsx("button",{onClick:so,className:"text-xs text-brand-500 hover:text-brand-500 px-2.5 py-1 rounded-md hover:bg-brand-500/10 border border-brand-500/20 transition-colors flex items-center gap-1",children:a("page.newChatButton")}),n.jsx("button",{ref:lt,onClick:()=>$t(!Tt),className:`p-1.5 rounded-md transition-colors ${Tt?"bg-surface-overlay text-fg-primary":"text-fg-tertiary hover:text-fg-secondary hover:bg-surface-elevated"}`,title:a("page.historyTitle"),children:n.jsx("svg",{className:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:1.5,children:n.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M12 6v6h4.5m4.5 0a9 9 0 11-18 0 9 9 0 0118 0z"})})})]})]})]}),Me.length>1&&n.jsx("div",{className:"flex items-center gap-1 px-4 pb-1.5 overflow-x-auto scrollbar-hide",children:Me.map(St=>n.jsxs("button",{onClick:()=>z(St),className:`px-3 py-1.5 text-xs font-medium rounded-md transition-colors whitespace-nowrap flex items-center gap-1 ${I===St?"bg-brand-500/15 text-brand-500":"text-fg-tertiary hover:text-fg-secondary hover:bg-surface-elevated/50"}`,children:[n.jsx("span",{children:QG(St)}),XG(St,a)]},St))})]})})(),on&&n.jsxs("div",{className:"border-b border-border-default bg-surface-secondary/50 px-4 py-2 space-y-2 animate-in slide-in-from-top-2 duration-200",children:[n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsxs("div",{className:"flex-1 relative",children:[n.jsx("svg",{className:"absolute left-2.5 top-1/2 -translate-y-1/2 w-3.5 h-3.5 text-fg-tertiary",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:n.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M21 21l-5.197-5.197m0 0A7.5 7.5 0 105.196 5.196a7.5 7.5 0 0010.607 10.607z"})}),n.jsx("input",{autoFocus:!0,value:Fr,onChange:ae=>F0(ae.target.value),onKeyDown:ae=>{ae.key==="Escape"&&(cr(!1),dr(""),fr([]))},placeholder:a("page.searchPlaceholder"),className:"w-full pl-8 pr-3 py-1.5 text-xs bg-surface-primary border border-border-default rounded-lg outline-none focus:border-brand-500/50 transition-colors"})]}),n.jsx("button",{onClick:()=>{cr(!1),dr(""),fr([])},className:"text-fg-tertiary hover:text-fg-secondary text-xs px-1",children:"✕"})]}),Is&&n.jsxs("div",{className:"flex items-center gap-2 text-xs text-fg-tertiary py-1",children:[n.jsxs("svg",{className:"animate-spin h-3 w-3",viewBox:"0 0 24 24",fill:"none",children:[n.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),n.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"})]}),a("page.searching")]}),!Is&&Fr.length>=2&&br.length===0&&n.jsx("div",{className:"text-xs text-fg-tertiary py-1",children:a("page.noSearchResults")}),br.length>0&&n.jsx("div",{className:"max-h-60 overflow-y-auto space-y-0.5",children:br.map(ae=>n.jsxs("button",{onClick:()=>q0(ae),className:"w-full text-left px-3 py-2 rounded-lg hover:bg-surface-elevated transition-colors group",children:[n.jsxs("div",{className:"flex items-center gap-2 text-[11px] text-fg-tertiary mb-0.5",children:[n.jsx("span",{className:`px-1.5 py-0.5 rounded text-[10px] font-medium ${ae.source==="channel"?"bg-blue-500/10 text-blue-500":"bg-emerald-500/10 text-emerald-500"}`,children:ae.source==="channel"?"#":"1:1"}),ae.senderName&&n.jsx("span",{children:ae.senderName}),n.jsx("span",{children:new Date(ae.createdAt).toLocaleDateString(void 0,{month:"short",day:"numeric"})})]}),n.jsx("div",{className:"text-xs text-fg-secondary line-clamp-2 group-hover:text-fg-primary transition-colors",children:ae.text.length>200?ae.text.slice(0,200)+"…":ae.text})]},ae.id))})]}),ne==="direct"&&be&&I==="chat"&&sn.length>1&&n.jsx("div",{className:"flex items-center gap-0 px-3 overflow-x-auto scrollbar-hide",children:sn.map(ae=>n.jsxs("div",{className:`group flex items-center gap-1.5 px-3 py-1.5 text-xs cursor-pointer rounded-md transition-colors shrink-0 max-w-[180px] ${ae.id===ve?"text-brand-500 bg-brand-500/10":"text-fg-tertiary hover:text-fg-secondary hover:bg-surface-elevated/50"}`,onClick:()=>{if(ae.id===Qn){tt(Qn);const Me=rt.current;Ve.current.delete(Me),je([])}else vc(ae)},children:[ae.isMain&&n.jsx("span",{className:"text-[10px] opacity-50 shrink-0",children:"●"}),n.jsx("span",{className:"truncate",children:ae.id===Qn?a("page.newChat"):ae.isMain?a("page.sessionMain"):ae.title||a("page.sessionConversation")}),!ae.isMain&&n.jsx("button",{onClick:Me=>{Me.stopPropagation(),ip(ae.id)},className:"opacity-0 group-hover:opacity-100 text-fg-tertiary hover:text-fg-secondary transition-opacity shrink-0",children:"✕"})]},ae.id))}),ne==="channel"&&ia?.type==="custom"&&nr&&(()=>{const ae=ia,Me=ae.members??[],ge=[];for(const ze of u)Me.some(wt=>wt.id===ze.id)||ge.push({id:ze.id,name:ze.name,type:"agent",subtitle:ze.role||"Agent"});for(const ze of h)Me.some(wt=>wt.id===ze.id)||ge.push({id:ze.id,name:ze.name,type:"human",subtitle:ze.email||ze.role||""});return n.jsxs("div",{className:"bg-surface-secondary/80 px-4 py-3 flex flex-col gap-2",children:[n.jsxs("div",{className:"flex items-center justify-between",children:[n.jsxs("span",{className:"text-xs font-semibold text-fg-secondary",children:[a("page.members")," (",Me.length,")"]}),n.jsx("button",{onClick:()=>On(!1),className:"text-fg-tertiary hover:text-fg-secondary text-xs",children:n.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),n.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]}),n.jsx("div",{className:"flex flex-wrap gap-1.5",children:Me.map(ze=>n.jsxs("span",{className:`inline-flex items-center gap-1.5 px-2 py-1 rounded-full text-[11px] font-medium ${ze.type==="agent"?"bg-brand-500/10 text-brand-500":"bg-green-500/10 text-green-600"}`,children:[n.jsx(Nr,{name:ze.name,size:16,bgClass:ze.type==="agent"?"bg-brand-500/15 text-brand-500":"bg-green-500/15 text-green-600"}),ze.name,ze.id!==t?.id&&n.jsx("button",{onClick:async()=>{try{await ie.groupChats.removeMember(ae.id,ze.id),Pn(wt=>wt.map(Je=>Je.id===ae.id?{...Je,members:(Je.members??[]).filter(Pt=>Pt.id!==ze.id),memberCount:(Je.memberCount??1)-1}:Je))}catch{}},className:"ml-0.5 hover:text-red-500 transition-colors",title:a("common:remove"),children:n.jsxs("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),n.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]},ze.id))}),ge.length>0&&n.jsx("div",{className:"mt-1",children:n.jsxs("select",{className:"w-full bg-surface-primary border border-border-default rounded-lg px-2.5 py-1.5 text-xs text-fg-primary outline-none focus:ring-1 focus:ring-brand-500/50",value:"",onChange:async ze=>{const wt=ze.target.value;if(!wt)return;const Je=ge.find(Pt=>Pt.id===wt);if(Je)try{await ie.groupChats.addMember(ae.id,Je.id,Je.type,Je.name),Pn(Pt=>Pt.map(zt=>zt.id===ae.id?{...zt,members:[...zt.members??[],{id:Je.id,name:Je.name,type:Je.type}],memberCount:(zt.memberCount??0)+1}:zt))}catch{}},children:[n.jsx("option",{value:"",children:a("page.addMemberPlaceholder")}),ge.map(ze=>n.jsxs("option",{value:ze.id,children:["[",ze.type==="agent"?"Agent":"Human","] ",ze.name]},ze.id))]})})]})})(),ne==="direct"&&be&&Tt&&n.jsxs("div",{ref:vt,className:"absolute right-4 top-full mt-1 w-72 max-h-[420px] bg-surface-secondary border border-border-default rounded-xl shadow-2xl shadow-black/40 z-50 flex flex-col overflow-hidden",children:[n.jsxs("div",{className:"px-4 py-3 border-b border-border-default flex items-center justify-between",children:[n.jsx("span",{className:"text-xs font-semibold text-fg-secondary uppercase tracking-wider",children:a("page.historyTitle")}),n.jsx("button",{onClick:()=>$t(!1),className:"text-fg-tertiary hover:text-fg-secondary text-xs",children:"✕"})]}),n.jsxs("div",{className:"flex-1 overflow-y-auto p-2",children:[Pe.length===0&&n.jsx("div",{className:"text-xs text-fg-tertiary text-center py-6",children:a("page.noConversationsYet")}),(()=>{const ae=new Date,Me=new Date(ae.getFullYear(),ae.getMonth(),ae.getDate()).getTime(),ge=Me-864e5,ze=Me-7*864e5,wt=[],Je=[],Pt=[],zt=[],ut=[];for(const St of Pe){const rn=new Date(St.lastMessageAt).getTime();rn>=Me?Je.push(St):rn>=ge?Pt.push(St):rn>=ze?zt.push(St):ut.push(St)}return Je.length>0&&wt.push({label:a("page.dateToday"),items:Je}),Pt.length>0&&wt.push({label:a("page.dateYesterday"),items:Pt}),zt.length>0&&wt.push({label:a("page.datePrevious7Days"),items:zt}),ut.length>0&&wt.push({label:a("page.dateOlder"),items:ut}),wt.map(St=>n.jsxs("div",{className:"mb-2",children:[n.jsx("div",{className:"text-[10px] font-semibold text-fg-tertiary uppercase tracking-wider px-3 py-1.5",children:St.label}),St.items.map(rn=>n.jsxs("button",{onClick:()=>{vc(rn)},className:`w-full text-left px-3 py-2.5 rounded-lg text-xs mb-0.5 transition-colors ${rn.id===ve?"bg-brand-600/20 text-brand-500":"text-fg-secondary hover:bg-surface-elevated"}`,children:[n.jsxs("div",{className:"truncate font-medium flex items-center gap-1",children:[rn.isMain&&n.jsx("span",{className:"text-[10px] text-brand-500 opacity-80",children:"●"}),rn.isMain?a("page.sessionMain"):rn.title||a("page.sessionConversation")]}),n.jsx("div",{className:"text-fg-tertiary text-[10px] mt-0.5",children:new Date(rn.lastMessageAt).toLocaleString()})]},rn.id))]},St.label))})()]})]})]}),v&&I==="profile"&&ne==="direct"&&be&&n.jsx("div",{className:"flex-1 overflow-y-auto",children:n.jsx(Tk,{agentId:be,onBack:()=>z("chat"),inline:!0,defaultTab:Z,highlightMailboxId:J,onSwipeBack:()=>{No(B.current)?history.back():z("chat")},authUser:t})}),v&&I==="profile"&&ne==="channel"&&yr&&n.jsx("div",{className:"flex-1 overflow-y-auto",onTouchStart:v?mt.onTouchStart:void 0,onTouchEnd:v?mt.onTouchEnd:void 0,children:n.jsx(qk,{teamId:yr,onBack:()=>z("chat"),inline:!0,onSelectAgent:ae=>{me("direct"),se(ae),Ee()}})}),!v&&No(I)&&ne==="direct"&&be&&n.jsx("div",{className:"flex-1 overflow-y-auto",children:n.jsx(Tk,{agentId:be,onBack:()=>z("chat"),inline:!0,headless:!0,activeTab:I,highlightMailboxId:J,authUser:t})}),!v&&No(I)&&ne==="channel"&&yr&&n.jsx("div",{className:"flex-1 flex flex-col min-h-0",children:n.jsx(qk,{teamId:yr,onBack:()=>z("chat"),inline:!0,headless:!0,activeTab:I,onSelectAgent:ae=>{me("direct"),se(ae),z("overview"),!V&&!O&&Y(!0)}})}),n.jsxs("div",{className:`flex-1 overflow-hidden flex flex-col relative ${I!=="chat"?"hidden":""}`,children:[Mn&&n.jsxs("div",{className:"absolute top-0 left-0 right-0 z-10 flex justify-center items-center gap-2 py-2 bg-gradient-to-b from-surface-primary/90 to-transparent pointer-events-none",children:[n.jsxs("svg",{className:"animate-spin h-3.5 w-3.5 text-brand-400",viewBox:"0 0 24 24",fill:"none",children:[n.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),n.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"})]}),n.jsx("span",{className:"text-xs text-fg-tertiary",children:a("page.loadingEarlierMessages")})]}),n.jsxs("div",{ref:is,className:`flex-1 overflow-y-auto ${v?"p-2.5":"p-5 2xl:pr-[280px]"}`,onScroll:no,onTouchStart:v?mt.onTouchStart:void 0,onTouchEnd:v?mt.onTouchEnd:void 0,children:[un.length===0&&!en&&n.jsxs("div",{className:"flex flex-col items-center justify-center h-full text-fg-tertiary text-sm space-y-2",children:[n.jsx("div",{className:"opacity-40",children:n.jsx("svg",{width:"40",height:"40",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:ne==="channel"?n.jsxs(n.Fragment,{children:[n.jsx("path",{d:"M4 4h16c1.1 0 2 .9 2 2v12c0 1.1-.9 2-2 2H6l-4 4V6c0-1.1.9-2 2-2z"}),n.jsx("line",{x1:"8",y1:"10",x2:"16",y2:"10"}),n.jsx("line",{x1:"8",y1:"14",x2:"13",y2:"14"})]}):n.jsx("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"})})}),ne==="channel"&&n.jsx("div",{children:a("page.emptyChannel",{name:ia?.name??fe})}),ne==="direct"&&!be&&n.jsx("div",{children:a("page.emptySelectAgent")}),ne==="direct"&&be&&n.jsx("div",{children:a("page.emptyNewConversation",{name:Jr?.name??""})})]}),un.length>0&&n.jsx("div",{style:{height:yt.getTotalSize(),width:"100%",position:"relative"},children:yt.getVirtualItems().map(ae=>{const Me=ae.index,ge=un[Me],ze=Me>0?un[Me-1]:null,wt=Vk(ge.rawCreatedAt),Je=ze?Vk(ze.rawCreatedAt):"",Pt=wt&&wt!==Je,zt=Me===un.length-1,St=Dl&&zt&&en,rn=G0&&zt||St,Rn=ne==="channel"||!St||ge.isStopped;return n.jsx("div",{"data-index":Me,ref:yt.measureElement,style:{position:"absolute",top:0,left:0,width:"100%",transform:`translateY(${ae.start}px)`},children:n.jsxs("div",{className:"pb-3",children:[Pt&&n.jsxs("div",{className:"flex items-center gap-3 py-2 my-1",children:[n.jsx("div",{className:"flex-1 h-px bg-border-default"}),n.jsx("span",{className:"text-[10px] text-fg-tertiary font-medium uppercase tracking-wider shrink-0",children:BG(ge.rawCreatedAt,l)}),n.jsx("div",{className:"flex-1 h-px bg-border-default"})]}),n.jsxs("div",{id:`msg-${ge.id}`,className:"group/msg flex gap-3 transition-colors rounded-lg",children:[ne==="channel"?n.jsx("div",{className:"shrink-0 cursor-pointer",onClick:Kt=>{if(ge.sender==="agent"&&ge.agentId){const xn=Kt.currentTarget.getBoundingClientRect();q({agentId:ge.agentId,top:xn.top,left:xn.right+8})}},children:n.jsx(Nr,{name:ge.sender==="user"?Fd:ge.agentName??a("page.fallbackAgent"),avatarUrl:ge.sender==="user"?t?.avatarUrl:u.find(Kt=>Kt.id===ge.agentId)?.avatarUrl,size:32,bgClass:ge.sender==="user"?"bg-brand-600":"bg-brand-500/15 text-brand-600",className:ge.sender==="agent"?"hover:ring-1 hover:ring-brand-500/40 rounded-lg":"rounded-lg"})}):n.jsx("div",{className:"shrink-0",children:n.jsx(Nr,{name:ge.sender==="user"?Fd:ge.agentName??(ne==="direct"?Jr?.name??a("page.fallbackAgent"):a("page.fallbackAgent")),avatarUrl:ge.sender==="user"?t?.avatarUrl:u.find(Kt=>Kt.id===(ge.agentId??(ne==="direct"?Jr?.id:void 0)))?.avatarUrl,size:32,bgClass:ge.sender==="user"?"bg-brand-600":"bg-brand-500/15 text-brand-600",className:"rounded-lg"})}),n.jsxs("div",{className:"min-w-0 flex-1",children:[n.jsxs("div",{className:"flex items-baseline gap-2",children:[n.jsx("span",{className:"text-sm font-medium text-fg-primary",children:ge.sender==="user"?Fd:ne==="channel"?ge.agentName??a("page.fallbackAgent"):n.jsx(UG,{name:ge.agentName??(ne==="direct"?Jr?.name??a("page.fallbackAgent"):a("page.fallbackAgent")),agentId:ge.agentId??(ne==="direct"?Jr?.id:void 0),agents:u,onViewProfile:it})}),n.jsx("span",{className:"text-xs text-fg-tertiary",title:ge.rawCreatedAt?new Date(ge.rawCreatedAt).toLocaleString():"",children:$G(ge.time,ge.rawCreatedAt,l)})]}),ge.replyToId&&ge.replyToSender&&n.jsxs("button",{onClick:()=>{const Kt=document.getElementById(`msg-${ge.replyToId}`);Kt&&(Kt.scrollIntoView({behavior:"smooth",block:"center"}),Kt.classList.add("bg-brand-500/10"),setTimeout(()=>Kt.classList.remove("bg-brand-500/10"),1500))},className:"flex items-center gap-1.5 mt-0.5 mb-1 pl-2 py-0.5 border-l-2 border-brand-500/40 text-xs text-fg-tertiary hover:text-fg-secondary transition-colors cursor-pointer",children:[n.jsx("span",{className:"font-medium text-brand-500",children:ge.replyToSender}),n.jsx("span",{className:"truncate max-w-[250px]",children:ge.replyToText??"..."})]}),n.jsxs("div",{className:`mt-0.5 ${ge.sender==="agent"?"bg-surface-chat-bubble rounded-2xl px-3.5 py-2.5":""} ${ge.isError||ge.sender==="agent"&&ge.text.startsWith("⚠")?"border-b-2 border-red-500/60":""} ${rn&&ge.sender==="agent"?"streaming-bubble":""}`,children:[ge.sender==="user"?n.jsxs("div",{className:"text-sm text-fg-secondary whitespace-pre-wrap",children:[ge.images&&ge.images.length>0&&n.jsx("div",{className:"flex flex-wrap gap-1.5 mb-1",children:ge.images.map((Kt,xn)=>n.jsx("img",{src:Kt,alt:"",className:"max-w-[200px] max-h-[150px] rounded-lg object-cover cursor-pointer hover:opacity-80 transition-opacity",onClick:()=>window.open(Kt,"_blank")},xn))}),ne==="channel"?xk(ge.text,u,(Kt,xn)=>{const An=xn.currentTarget.getBoundingClientRect();q({agentId:Kt.id,top:An.bottom,left:An.left})}):ge.text&&n.jsx("span",{className:"leading-relaxed",children:xk(ge.text,u,(Kt,xn)=>{const An=xn.currentTarget.getBoundingClientRect();q({agentId:Kt.id,top:An.bottom,left:An.left})})})]}):ge.sender==="agent"&&ne==="channel"&&!(ge.segments&&ge.segments.length>0)?n.jsx(Wr,{content:ge.text,className:"text-sm text-fg-secondary",onMentionClick:Lt,knownNames:ht}):n.jsx(WG,{msg:ge,isStreaming:St,liveActivities:St?Ht:[],onViewModeChange:Kt=>$s(xn=>{const An=new Set(xn);return Kt==="full"?An.add(ge.id):An.delete(ge.id),An}),onMentionClick:Lt,knownNames:ht}),ge.isNotification&&n.jsx(qG,{priority:ge.notifyPriority})]}),Rn&&!r&&n.jsx("div",{className:`transition-opacity ${ge.isStopped||v?"opacity-100":"opacity-0 group-hover/msg:opacity-100"}`,children:n.jsx(KG,{msg:ge,onCopy:z0,onRetry:$0,onResume:B0,onReply:$o,isCopied:hn===ge.id,isLastAgentMsg:ge.id===ro})})]})]})]})},ge.id)})}),ne==="channel"&&In.length>0&&n.jsx("div",{className:"flex flex-col gap-1.5 py-2",children:In.map(ae=>n.jsxs("div",{className:"flex items-center gap-2.5 px-3 py-1.5 rounded-lg cursor-pointer hover:bg-surface-elevated/60 transition-colors group/think",onClick:()=>it(ae.id,{tab:"overview"}),children:[n.jsxs("div",{className:"relative shrink-0",children:[n.jsx(Nr,{name:ae.name,avatarUrl:ae.avatarUrl,size:28,bgClass:"bg-brand-500/15 text-brand-600"}),n.jsx("span",{className:"absolute -bottom-0.5 -right-0.5 w-2.5 h-2.5 rounded-full bg-blue-500 animate-pulse ring-2 ring-surface-primary"})]}),n.jsxs("div",{className:"flex items-center gap-1.5 min-w-0",children:[n.jsx("span",{className:"text-sm font-medium text-fg-secondary truncate",children:ae.name}),n.jsxs("span",{className:"flex items-center gap-0.5",children:[n.jsx("span",{className:"w-1 h-1 rounded-full bg-blue-400 animate-bounce"}),n.jsx("span",{className:"w-1 h-1 rounded-full bg-blue-400 animate-bounce",style:{animationDelay:"0.15s"}}),n.jsx("span",{className:"w-1 h-1 rounded-full bg-blue-400 animate-bounce",style:{animationDelay:"0.3s"}})]}),n.jsx("span",{className:"text-xs text-fg-tertiary",children:a("page.agentThinking")})]}),n.jsx("span",{className:"ml-auto text-[10px] text-fg-tertiary opacity-0 group-hover/think:opacity-100 transition-opacity",children:"→"})]},ae.id))}),n.jsx("div",{ref:Ps})]}),Qe&&I==="chat"&&n.jsxs("button",{onClick:()=>{aa.current=!0,us("smooth"),dt(!1),Rt.current=0,hr(0)},className:`absolute ${v?"bottom-4":"bottom-20"} left-1/2 -translate-x-1/2 z-10 flex items-center gap-1.5 px-3.5 py-2 bg-surface-secondary/95 backdrop-blur-sm border border-border-default rounded-full shadow-lg hover:bg-surface-elevated transition-colors text-xs text-fg-secondary`,children:[n.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:n.jsx("polyline",{points:"6 9 12 15 18 9"})}),fn>0?a("page.newMessages",{count:fn}):a("page.scrollToBottom")]})]}),H&&(()=>{const ae=u.find(Me=>Me.id===H.agentId);return ae?n.jsx(VG,{agent:ae,anchorRect:{top:H.top,left:H.left},onClose:()=>q(null),onViewProfile:it}):null})(),n.jsx("div",{className:`${v?"px-3 py-2":"px-5 py-3 2xl:pr-[280px]"} relative shrink-0 ${I!=="chat"?"hidden":""}`,onDrop:lp,onDragOver:cp,children:n.jsxs("div",{className:`bg-surface-primary border border-border-default shadow-lg shadow-black/5 ${v?"rounded-2xl p-3":"rounded-2xl p-3 max-w-3xl"}`,children:[ya&&Pi.length>0&&n.jsxs("div",{className:"absolute bottom-full left-4 mb-1 bg-surface-elevated border border-border-default rounded-lg shadow-xl overflow-hidden z-10 max-h-48 overflow-y-auto",children:[n.jsx("div",{className:"px-3 py-1.5 text-[10px] text-fg-tertiary font-medium uppercase tracking-wider border-b border-border-default",children:a("page.mentionAgent")}),Pi.map((ae,Me)=>n.jsxs("button",{ref:ge=>{Me===va&&ge&&ge.scrollIntoView({block:"nearest"})},onClick:()=>U0(ae.name),onMouseEnter:()=>Ss(Me),className:`w-full text-left px-4 py-2 text-sm flex items-center gap-2 transition-colors ${Me===va?"bg-brand-500/15 text-brand-500":"text-fg-secondary hover:bg-surface-overlay"}`,children:[n.jsx(Nr,{name:ae.name,avatarUrl:ae.avatarUrl,size:24,bgClass:"bg-brand-500/20 text-brand-500"}),n.jsx("span",{className:"flex-1 min-w-0",children:ae.name}),n.jsx("span",{className:"text-xs text-fg-tertiary ml-auto",children:ae.role})]},ae.id))]}),Dn.length>0&&n.jsxs("div",{className:"flex items-center gap-2 mb-2 overflow-x-auto pb-1",children:[Dn.map(ae=>n.jsxs("div",{className:"relative group/img shrink-0",children:[Ml(ae)?n.jsx("img",{src:ae.dataUrl,alt:ae.name,className:"w-16 h-16 rounded-lg object-cover border border-border-default"}):n.jsxs("div",{className:"w-16 h-16 rounded-lg border border-border-default bg-surface-elevated flex flex-col items-center justify-center gap-0.5",title:ae.name,children:[n.jsx("span",{className:"text-xl leading-none",children:K0(ae.name,ae.dataUrl)}),n.jsx("span",{className:"text-[9px] text-fg-tertiary truncate max-w-[56px] px-0.5",children:ae.name.split(".").pop()?.toUpperCase()})]}),n.jsx("button",{onClick:()=>W0(ae.id),className:"absolute -top-1.5 -right-1.5 w-5 h-5 bg-surface-secondary border border-gray-600 rounded-full flex items-center justify-center text-fg-secondary hover:text-red-500 hover:border-red-500 text-xs opacity-0 group-hover/img:opacity-100 transition-opacity",children:"×"})]},ae.id)),Dn.length<Hd&&n.jsx("button",{onClick:()=>Sn.current?.click(),className:"w-16 h-16 rounded-lg border border-dashed border-gray-600 flex items-center justify-center text-fg-tertiary hover:text-fg-secondary hover:border-gray-400 transition-colors shrink-0",title:a("page.addMoreFiles"),children:n.jsx("svg",{className:"w-5 h-5",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:n.jsx("path",{d:"M12 5v14M5 12h14"})})})]}),Dn.length>0&&Dn.some(ae=>Ml(ae))&&Jr&&Jr.modelSupportsVision===!1&&n.jsxs("div",{className:"text-[10px] text-amber-500/80 mb-1.5 flex items-center gap-1",children:[n.jsx("svg",{className:"w-3 h-3 shrink-0",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:n.jsx("path",{d:"M12 9v4m0 4h.01M12 2L2 22h20L12 2z",strokeLinecap:"round",strokeLinejoin:"round"})}),a("page.visionWarning")]}),n.jsx("input",{ref:Sn,type:"file",accept:"image/*,.pdf,.docx,.xlsx,.pptx,.xls,.doc,.csv,.json,.xml,.html,.epub",multiple:!0,className:"hidden",onChange:ae=>{ae.target.files&&Bo(ae.target.files),ae.target.value=""}}),Vt&&n.jsxs("div",{className:"flex items-center gap-2 mb-2 px-3 py-1.5 bg-surface-elevated rounded-lg border border-border-default/50",children:[n.jsxs("div",{className:"flex-1 min-w-0 pl-2 border-l-2 border-brand-500/50",children:[n.jsx("span",{className:"text-[11px] font-medium text-brand-500",children:Vt.sender}),n.jsx("p",{className:"text-[11px] text-fg-tertiary truncate",children:Vt.text})]}),n.jsx("button",{onClick:()=>ln(null),className:"text-fg-tertiary hover:text-fg-secondary shrink-0 p-0.5",children:n.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),n.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]}),n.jsxs("div",{className:"flex gap-2 items-end",children:[n.jsx("button",{onClick:()=>Sn.current?.click(),disabled:ne==="direct"&&!be,className:"px-2.5 py-2.5 text-fg-tertiary hover:text-fg-secondary disabled:opacity-40 transition-colors rounded-xl hover:bg-surface-elevated",title:a("page.attachFilesTitle"),children:n.jsx("svg",{className:"w-5 h-5",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:n.jsx("path",{d:"M21.44 11.05l-9.19 9.19a6 6 0 01-8.49-8.49l9.19-9.19a4 4 0 015.66 5.66l-9.2 9.19a2 2 0 01-2.83-2.83l8.49-8.48",strokeLinecap:"round",strokeLinejoin:"round"})})}),n.jsx("textarea",{ref:Bn,value:Re,onChange:ae=>{El(ae.target.value),Vn()},onKeyDown:ae=>{if(ya&&Pi.length>0){const Me=ae.key==="ArrowUp"||ae.ctrlKey&&ae.key==="p",ge=ae.key==="ArrowDown"||ae.ctrlKey&&ae.key==="n",ze=ae.key==="Enter"||ae.key==="Tab",wt=ae.key==="Escape";if(Me){ae.preventDefault(),Ss(Je=>(Je-1+Pi.length)%Pi.length);return}if(ge){ae.preventDefault(),Ss(Je=>(Je+1)%Pi.length);return}if(ze){ae.preventDefault();const Je=Pi[va];Je&&U0(Je.name);return}if(wt){ae.preventDefault(),Ls(!1);return}}ae.key==="Enter"&&!ae.shiftKey&&(ae.preventDefault(),st())},onPaste:op,placeholder:Ud,disabled:ne==="direct"&&!be,rows:2,className:"flex-1 px-4 py-3 bg-transparent rounded-xl text-sm outline-none disabled:opacity-40 transition-colors resize-none overflow-hidden leading-relaxed placeholder:text-fg-tertiary/60",style:{minHeight:"52px",maxHeight:"120px"}}),en&&ne!=="dm"&&n.jsx("button",{onClick:Ie,className:"px-3 py-2.5 bg-red-600 hover:bg-red-500 text-white text-sm rounded-xl transition-colors flex items-center gap-1.5",title:a("page.stopAgent"),children:n.jsx("svg",{className:"w-3.5 h-3.5",viewBox:"0 0 24 24",fill:"currentColor",children:n.jsx("rect",{x:"4",y:"4",width:"16",height:"16",rx:"2"})})}),n.jsx("button",{onClick:()=>{st()},disabled:ne==="direct"&&!be||!Re.trim()&&Dn.length===0,className:"px-5 py-2.5 bg-brand-600 hover:bg-brand-500 disabled:opacity-40 text-white text-sm rounded-xl transition-colors",children:a("common:send")})]})]})})]})]})}function Xk({agent:e,tasks:t,onViewProfile:r}){const{t:s}=pt(["team","common"]),[a,i]=g.useState(!1),l=g.useRef(null),d=g.useRef(null),u=e.status==="working",m=e.status==="error",h=!m&&!!e.lastError&&!!e.lastErrorAt&&Date.now()-new Date(e.lastErrorAt).getTime()<1800*1e3,p=u?t.find(C=>C.assignedAgentId===e.id&&C.status==="in_progress"):null,y=e.currentActivity;g.useEffect(()=>{if(!a)return;const C=w=>{l.current&&!l.current.contains(w.target)&&i(!1)};return document.addEventListener("mousedown",C),()=>document.removeEventListener("mousedown",C)},[a]),g.useLayoutEffect(()=>{if(!a||!d.current)return;const C=d.current,w=C.getBoundingClientRect(),N=window.innerWidth;w.right>N-8&&(C.style.left="auto",C.style.right="0"),w.left<8&&(C.style.left="0",C.style.right="auto");const S=N-16;w.width>S&&(C.style.width=`${S}px`)},[a]);const x=m?"bg-red-400 animate-pulse":h?"bg-amber-400":u?"bg-blue-400 animate-pulse":"bg-green-400",v=s(m?"common:status.error":u?"common:status.working":"common:status.idle"),j=y?y.type==="heartbeat"?s("page.activityHeartbeat",{name:y.heartbeatName??y.label}):y.type==="chat"?y.label:y.type==="task"?s("page.activityTask",{label:y.label}):y.label:s("page.processing");return n.jsxs("div",{className:"relative",ref:l,children:[n.jsxs("button",{onClick:()=>i(C=>!C),className:`flex items-center gap-1.5 px-2 py-0.5 rounded-full transition-colors ${u&&!h?"bg-blue-500/10 border border-blue-500/20 hover:bg-blue-500/20":m?"bg-red-500/10 border border-red-500/20 hover:bg-red-500/20":h?"bg-amber-500/10 border border-amber-500/20 hover:bg-amber-500/20":"bg-green-500/10 border border-green-500/20 hover:bg-green-500/20"}`,children:[n.jsx("span",{className:`w-2 h-2 rounded-full ${x}`}),n.jsx("span",{className:`text-xs ${m?"text-red-500":h?"text-amber-600":u?"text-blue-500":"text-green-600"}`,children:v}),h&&n.jsx("span",{className:"text-[9px] text-amber-500",children:"⚠"}),e.mailboxDepth!=null&&e.mailboxDepth>0&&n.jsx("span",{className:"text-[9px] bg-fg-tertiary/20 text-fg-tertiary rounded-full px-1.5",children:e.mailboxDepth})]}),a&&m&&n.jsxs("div",{ref:d,className:"absolute top-full left-0 mt-1.5 bg-surface-secondary border border-red-500/30 rounded-xl shadow-2xl z-30 w-80 max-w-[calc(100vw-1rem)] p-3 space-y-2",children:[n.jsx("p",{className:"text-[10px] text-red-500 uppercase font-semibold",children:s("page.errorDetails")}),n.jsxs("div",{className:"bg-red-500/10 border border-red-500/20 rounded-lg p-2.5",children:[n.jsx("pre",{className:"text-[10px] text-red-500/80 leading-relaxed whitespace-pre-wrap break-all font-mono line-clamp-6",children:e.lastError||s("page.agentErrorFallback")}),e.lastErrorAt&&n.jsx("div",{className:"text-[9px] text-red-500/50 mt-1.5 border-t border-red-500/10 pt-1",children:new Date(e.lastErrorAt).toLocaleString()})]}),n.jsx("button",{onClick:()=>{i(!1),r?.(e.id)},className:"w-full text-center text-[10px] text-red-500 hover:text-red-500 border border-red-500/30 hover:border-red-500/50 rounded-lg py-1 transition-colors",children:s("page.viewAgentProfileArrow")})]}),a&&h&&n.jsxs("div",{ref:d,className:"absolute top-full left-0 mt-1.5 bg-surface-secondary border border-amber-500/30 rounded-xl shadow-2xl z-30 w-80 max-w-[calc(100vw-1rem)] p-3 space-y-2",children:[n.jsx("p",{className:"text-[10px] text-amber-600 uppercase font-semibold",children:s("page.recentErrorDetails")}),n.jsxs("div",{className:"bg-amber-500/10 border border-amber-500/20 rounded-lg p-2.5",children:[n.jsx("pre",{className:"text-[10px] text-amber-600/80 leading-relaxed whitespace-pre-wrap break-all font-mono line-clamp-6",children:e.lastError}),e.lastErrorAt&&n.jsx("div",{className:"text-[9px] text-amber-500/50 mt-1.5 border-t border-amber-500/10 pt-1",children:new Date(e.lastErrorAt).toLocaleString()})]}),n.jsx("div",{className:"text-[10px] text-fg-tertiary",children:s("page.errorRecovered")})]}),a&&u&&n.jsxs("div",{ref:d,className:"absolute top-full left-0 mt-1.5 bg-surface-secondary border border-border-default rounded-xl shadow-2xl z-30 w-80 max-w-[calc(100vw-1rem)] p-3 space-y-2",children:[n.jsx("p",{className:"text-[10px] text-fg-tertiary uppercase font-semibold",children:s("page.currentActivity")}),p?n.jsxs("div",{className:"flex items-center gap-2 p-2 rounded-lg bg-brand-500/10 border border-brand-500/30 cursor-pointer hover:bg-brand-500/10 transition-colors",onClick:()=>{i(!1),bt.navigate(De.WORK,{openTask:p.id})},children:[n.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-brand-400 animate-pulse shrink-0"}),n.jsxs("div",{className:"flex-1 min-w-0",children:[n.jsx("div",{className:"text-xs text-brand-500 truncate",children:p.title}),n.jsx("div",{className:"text-[10px] text-fg-tertiary",children:s("page.workingOnTaskHint")})]}),n.jsx("span",{className:"text-[10px] text-fg-tertiary",children:"→"})]}):n.jsxs("div",{className:"flex items-center gap-2 p-2 rounded-lg bg-surface-elevated/50",children:[n.jsx("span",{className:`w-1.5 h-1.5 rounded-full shrink-0 ${y?.type==="heartbeat"||y?.type==="chat","bg-blue-400 animate-pulse"}`}),n.jsxs("div",{className:"flex-1 min-w-0",children:[n.jsx("div",{className:"text-xs text-fg-secondary",children:j}),n.jsx("div",{className:"text-[10px] text-fg-tertiary",children:y?.type==="heartbeat"?s("page.activityDescHeartbeat"):y?.type==="chat"?s("page.activityDescChat"):s("page.activityDescFallback")})]})]}),n.jsx("button",{onClick:()=>{i(!1),r?.(e.id,{tab:"overview"})},className:"w-full text-center text-[10px] text-brand-500 hover:text-brand-500 border border-border-default hover:border-gray-600 rounded-lg py-1.5 transition-colors",children:s("page.viewMindArrow")})]})]})}const eY=[{value:"system",label:"System"},{value:"light",label:"Light"},{value:"dark",label:"Dark"},{value:"cyberpunk",label:"Cyberpunk"},{value:"mono",label:"Mono"}],Jb="markus-theme";function Qk(e){const t=document.documentElement;t.classList.remove("light","dark","cyberpunk","mono"),e==="light"?t.classList.add("light"):e==="dark"?t.classList.add("dark"):e==="cyberpunk"?t.classList.add("cyberpunk"):e==="mono"&&t.classList.add("mono")}function tY(){try{const e=localStorage.getItem(Jb);if(e==="midnight")return localStorage.setItem(Jb,"dark"),"dark";if(e==="light"||e==="dark"||e==="system"||e==="cyberpunk"||e==="mono")return e}catch{}return"system"}function nY(){const[e,t]=g.useState(tY),r=g.useCallback(s=>{t(s);try{localStorage.setItem(Jb,s)}catch{}Qk(s)},[]);return g.useEffect(()=>{Qk(e)},[e]),{mode:e,setMode:r}}function rY(e){return e>=1e6?`${(e/1e6).toFixed(e%1e6===0?0:1)}M`:e>=1e3?`${(e/1e3).toFixed((e%1e3===0,0))}K`:String(e)}function Zk(e){return e===0?"-":e<.01?`$${e.toFixed(4)}`:e<1?`$${e.toFixed(2)}`:`$${e.toFixed(e%1===0?0:2)}`}function sY(e){return e.maxInputTokens>0||e.inputCostPer1MTokens>0||e.outputCostPer1MTokens>0}function dh({models:e,selectedModel:t,onSelect:r,loading:s,compact:a,maxVisible:i}){const[l,d]=g.useState(""),[u,m]=g.useState(!1),h=g.useMemo(()=>{if(!l)return e;const v=l.toLowerCase();return e.filter(j=>j.id.toLowerCase().includes(v))},[e,l]),p=i??(a?5:10),y=u?h:h.slice(0,p),x=h.length>p;return s?n.jsxs("div",{className:"flex items-center gap-2 py-4 text-sm text-fg-tertiary",children:[n.jsx("div",{className:"w-4 h-4 border-2 border-brand-500 border-t-transparent rounded-full animate-spin"}),"Loading models..."]}):e.length===0?n.jsx("div",{className:"py-3 text-sm text-fg-tertiary",children:"No models available for this provider."}):n.jsxs("div",{className:"space-y-2",children:[e.length>5&&n.jsx("input",{type:"text",value:l,onChange:v=>{d(v.target.value),m(!1)},placeholder:"Filter models...",className:"w-full px-3 py-1.5 bg-surface-overlay border border-border-default rounded-lg text-xs text-fg-primary placeholder:text-fg-tertiary focus:outline-none focus:border-brand-500"}),n.jsx("div",{className:`space-y-1 ${a?"max-h-[280px] overflow-y-auto":""}`,children:y.map(v=>{const j=v.id===t;return n.jsxs("button",{type:"button",onClick:()=>r(v.id),className:`w-full text-left px-3 py-2 rounded-lg transition-colors ${j?"bg-brand-500/10 border border-brand-500/30":"hover:bg-surface-overlay border border-transparent"}`,children:[n.jsxs("div",{className:"flex items-center justify-between",children:[n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx("div",{className:`w-3 h-3 rounded-full border-2 flex items-center justify-center ${j?"border-brand-500":"border-border-default"}`,children:j&&n.jsx("div",{className:"w-1.5 h-1.5 rounded-full bg-brand-500"})}),n.jsx("span",{className:`text-xs font-medium ${j?"text-brand-500":"text-fg-primary"}`,children:v.id})]}),j&&n.jsx("span",{className:"text-[10px] text-brand-500 font-medium",children:"Active"})]}),sY(v)&&n.jsxs("div",{className:"ml-5 mt-0.5 flex items-center gap-2 text-[10px] text-fg-tertiary flex-wrap",children:[v.maxInputTokens>0&&n.jsxs("span",{children:[rY(v.maxInputTokens)," ctx"]}),v.maxInputTokens>0&&(v.inputCostPer1MTokens>0||v.outputCostPer1MTokens>0)&&n.jsx("span",{className:"text-fg-quaternary",children:"|"}),(v.inputCostPer1MTokens>0||v.outputCostPer1MTokens>0)&&n.jsxs("span",{children:[Zk(v.inputCostPer1MTokens),"/",Zk(v.outputCostPer1MTokens)," per 1M"]})]}),!a&&n.jsxs("div",{className:"ml-5 mt-1 flex items-center gap-1.5 flex-wrap",children:[v.capabilities.functionCalling&&n.jsx(Mu,{label:"Tools"}),v.capabilities.vision&&n.jsx(Mu,{label:"Vision"}),v.capabilities.reasoning&&n.jsx(Mu,{label:"Reasoning"}),v.capabilities.promptCaching&&n.jsx(Mu,{label:"Caching"}),v.capabilities.webSearch&&n.jsx(Mu,{label:"Search"})]})]},v.id)})}),x&&!u&&n.jsxs("button",{type:"button",onClick:()=>m(!0),className:"text-xs text-brand-500 hover:text-brand-400 px-3",children:["Show all ",h.length," models..."]}),u&&x&&n.jsx("button",{type:"button",onClick:()=>m(!1),className:"text-xs text-fg-tertiary hover:text-fg-secondary px-3",children:"Show less"})]})}function Mu({label:e}){return n.jsx("span",{className:"px-1.5 py-0.5 rounded text-[9px] bg-surface-overlay text-fg-tertiary border border-border-default",children:e})}const Bu=[{id:"anthropic",label:"Anthropic",envKey:"ANTHROPIC_API_KEY",defaultModel:"claude-opus-4-6"},{id:"openai",label:"OpenAI",envKey:"OPENAI_API_KEY",defaultModel:"gpt-5.4"},{id:"google",label:"Google Gemini",envKey:"GOOGLE_API_KEY",defaultModel:"gemini-3-1-pro"},{id:"deepseek",label:"DeepSeek",envKey:"DEEPSEEK_API_KEY",baseUrl:"https://api.deepseek.com",defaultModel:"deepseek-v4-flash"},{id:"siliconflow",label:"SiliconFlow",envKey:"SILICONFLOW_API_KEY",baseUrl:"https://api.siliconflow.cn/v1",defaultModel:"Qwen/Qwen3.5-35B-A3B"},{id:"minimax",label:"MiniMax",envKey:"MINIMAX_API_KEY",baseUrl:"https://api.minimax.io/v1",defaultModel:"MiniMax-M2.7"},{id:"openrouter",label:"OpenRouter",envKey:"OPENROUTER_API_KEY",baseUrl:"https://openrouter.ai/api/v1",defaultModel:"xiaomi/mimo-v2-pro:free"},{id:"zai",label:"ZAI (GLM)",envKey:"ZAI_API_KEY",baseUrl:"https://api.z.ai/api/paas/v4",defaultModel:"glm-5.1"},{id:"xai",label:"xAI (Grok)",envKey:"XAI_API_KEY",baseUrl:"https://api.x.ai/v1",defaultModel:"grok-3"},{id:"mistral",label:"Mistral AI",envKey:"MISTRAL_API_KEY",baseUrl:"https://api.mistral.ai/v1",defaultModel:"mistral-large-latest"},{id:"groq",label:"Groq",envKey:"GROQ_API_KEY",baseUrl:"https://api.groq.com/openai/v1",defaultModel:"llama-3.3-70b-versatile"},{id:"perplexity",label:"Perplexity",envKey:"PERPLEXITY_API_KEY",baseUrl:"https://api.perplexity.ai",defaultModel:"sonar-pro"},{id:"cohere",label:"Cohere",envKey:"COHERE_API_KEY",baseUrl:"https://api.cohere.ai/compatibility/v1",defaultModel:"command-r-plus"},{id:"together_ai",label:"Together AI",envKey:"TOGETHER_API_KEY",baseUrl:"https://api.together.xyz/v1",defaultModel:"meta-llama/Llama-3.3-70B-Instruct-Turbo"},{id:"fireworks_ai",label:"Fireworks AI",envKey:"FIREWORKS_API_KEY",baseUrl:"https://api.fireworks.ai/inference/v1",defaultModel:"accounts/fireworks/models/llama-v3p3-70b-instruct"},{id:"moonshot",label:"Moonshot (Kimi)",envKey:"MOONSHOT_API_KEY",baseUrl:"https://api.moonshot.cn/v1",defaultModel:"moonshot-v1-auto"},{id:"volcengine",label:"Volcengine (Doubao)",envKey:"VOLCENGINE_API_KEY",baseUrl:"https://ark.cn-beijing.volces.com/api/v3",defaultModel:"doubao-1.5-pro-32k"},{id:"dashscope",label:"DashScope (Qwen)",envKey:"DASHSCOPE_API_KEY",baseUrl:"https://dashscope.aliyuncs.com/compatible-mode/v1",defaultModel:"qwen-max"},{id:"ollama",label:"Ollama (Local)",envKey:"OLLAMA_BASE_URL",baseUrl:"http://localhost:11434/v1",defaultModel:"llama3"}],JS=[{id:"appearance",labelKey:"nav.appearance"},{id:"providers",labelKey:"nav.providers",adminOnly:!0},{id:"execution",labelKey:"nav.execution",adminOnly:!0},{id:"browser",labelKey:"nav.browser",adminOnly:!0},{id:"search",labelKey:"nav.search",adminOnly:!0},{id:"storage",labelKey:"nav.storage",adminOnly:!0},{id:"account",labelKey:"nav.account"},{id:"remote",labelKey:"nav.remote",adminOnly:!0}],aY={users:"account",organization:"account",license:"account"};function Jk(){const t=window.location.hash.slice(1).split("/");if(t[0]==="settings"&&t[1]){const r=t[1],a=aY[r]??r;if(JS.some(i=>i.id===a))return a}return null}function ej({theme:e,onThemeChange:t,authUser:r,onLogout:s,onUserUpdated:a}={}){const{t:i,i18n:l}=pt(["settings","common"]),d=Rs(),[u,m]=g.useState(!1),[h,p]=g.useState(!1),y=g.useRef(null),[x,v]=g.useState(Jk);g.useEffect(()=>{const le=()=>v(Jk());return window.addEventListener("hashchange",le),()=>window.removeEventListener("hashchange",le)},[]);const j=g.useCallback(le=>{v(le),history.pushState(null,"",`#settings/${le}`)},[]),C=g.useCallback(()=>{v(null),history.pushState(null,"","#settings")},[]),w=x??(d?null:"appearance");g.useEffect(()=>{const le=()=>p(!0);return window.addEventListener("markus:open-edit-profile",le),()=>window.removeEventListener("markus:open-edit-profile",le)},[]),g.useEffect(()=>{if(!u)return;const le=Ie=>{y.current&&!y.current.contains(Ie.target)&&m(!1)};return document.addEventListener("mousedown",le),()=>document.removeEventListener("mousedown",le)},[u]);const[N,S]=g.useState(null),[T,E]=g.useState(null),[R,I]=g.useState(""),[z,B]=g.useState(!1),[D,V]=g.useState(null),[Y,F]=g.useState(null),[L,O]=g.useState(null),[M,$]=g.useState({}),[W,U]=g.useState(null),[H,q]=g.useState(null),[Z,_]=g.useState(!1),[J,X]=g.useState(null),[ee,te]=g.useState(null),[G,ue]=g.useState(!1),[Se,Ce]=g.useState(null),[Be,Ne]=g.useState({}),[he,_e]=g.useState(!1),[Ee,Ye]=g.useState(null),[Ze,mt]=g.useState(!1),[it,Lt]=g.useState(""),[ht,ne]=g.useState(!1),[me,be]=g.useState(null),[se,fe]=g.useState([]),[He,Ae]=g.useState([]),[et,pe]=g.useState(null),[Fe,Ve]=g.useState(null),[nt,gt]=g.useState(""),[rt,Et]=g.useState(null),je=g.useRef(null),Re=g.useRef(!1),[We,Vt]=g.useState(!1),[ln,en]=g.useState(200),[vn,In]=g.useState(!1),[Zt,cn]=g.useState(null),[Gn,Ln]=g.useState(!1),[Lr,Qr]=g.useState(1),[mr,Ge]=g.useState(!1),[Ht,Wt]=g.useState(null),[tn,zn]=g.useState(!1),[Mn,wn]=g.useState(0),[Dn,$n]=g.useState(!0),[Sn,Bn]=g.useState(!1),[Vn,Qn]=g.useState(!1),[Pe,Ct]=g.useState(9333),[ve,tt]=g.useState(!1),[Tt,$t]=g.useState(null),[sn,Zn]=g.useState(null),[Xt,ye]=g.useState({serperApiKey:"",tavilyApiKey:"",bingApiKey:"",googleSearchApiKey:"",googleSearchCx:"",serpApiKey:"",braveApiKey:"",exaApiKey:"",bochaApiKey:""}),[lt,vt]=g.useState(!1),[Bt,dn]=g.useState(null),[Dt,Pn]=g.useState(null),[tr,Hn]=g.useState(!1),[nr,On]=g.useState(new Set),[on,cr]=g.useState(null),[Fr,dr]=g.useState(!1),br=()=>({"Content-Type":"application/json",Authorization:`Bearer ${localStorage.getItem("markus_token")??""}`}),fr=g.useCallback(()=>{ie.health().then(S).catch(()=>{}),fetch("/api/settings/llm").then(le=>le.ok?le.json():Promise.reject(le.status)).then(le=>{le&&typeof le=="object"&&"providers"in le&&(E(le),I(le.defaultProvider))}).catch(()=>{})},[]),Is=g.useCallback(()=>{fetch("/api/settings/oauth/providers").then(le=>le.ok?le.json():Promise.reject(le.status)).then(le=>fe(le.providers??[])).catch(()=>{})},[]),ga=g.useCallback(()=>{fetch("/api/settings/oauth/profiles",{headers:br()}).then(le=>le.ok?le.json():Promise.reject(le.status)).then(le=>Ae(le.profiles??[])).catch(()=>{})},[]),xa=g.useCallback(()=>{ie.settings.getAgent().then(le=>{le&&typeof le.maxToolIterations=="number"&&en(le.maxToolIterations),le?.cognitive&&(Ln(le.cognitive.enabled??!1),Qr(le.cognitive.maxDepth??1))}).catch(()=>{})},[]),Pr=g.useCallback(()=>{ie.settings.getBrowser().then(le=>{le&&(zn(le.bringToFront??!1),wn(le.remoteDebuggingPort??0),$n(le.autoCloseTabs??!0),Bn(le.autoClickAllowDialog??!1),Qn(le.extensionConnected??!1),Ct(le.extensionBridgePort??9333))}).catch(()=>{})},[]),ti=g.useCallback(()=>{ie.settings.getSearch().then(le=>{le&&Zn(le)}).catch(()=>{})},[]),ba=g.useCallback(()=>{Hn(!0),ie.system.storage().then(Pn).catch(()=>{}).finally(()=>Hn(!1)),ie.system.orphans().then(cr).catch(()=>{})},[]);g.useEffect(()=>{fr(),Is(),ga(),xa(),Pr(),ti(),ba()},[fr,Is,ga,xa,Pr,ti,ba]),g.useEffect(()=>{const le=()=>ba();return window.addEventListener("markus:data-changed",le),()=>window.removeEventListener("markus:data-changed",le)},[ba]),g.useEffect(()=>{!Y||M[Y]||(U(Y),ie.modelCatalog.getLive(Y).then(le=>{$(Ie=>({...Ie,[Y]:le.models}))}).catch(()=>{ie.modelCatalog.getByProvider(Y).then(le=>{$(Ie=>({...Ie,[Y]:le.models}))}).catch(()=>{})}).finally(()=>U(null)))},[Y]);const ra=g.useCallback(async()=>{ue(!0),Ce(null),te(null),Ne({});try{const le=await fetch("/api/settings/env-models",{headers:br()});if(!le.ok){Ce({type:"err",text:i("envConfig.detectionFailedHttp",{status:le.status})});return}const Ie=await le.json();if(te(Ie),Ie.detected.length===0)Ce({type:"err",text:i("envConfig.noKeysFound")});else{const st={};for(const hn of Ie.detected)st[hn.provider]=!0;Ne(st)}}catch{Ce({type:"err",text:i("envConfig.failedToDetect")})}finally{ue(!1)}},[i]),ds=g.useCallback(async()=>{mt(!0),be(null),Ye(null);try{const le=await fetch("/api/settings/detect-ollama",{headers:br()});if(!le.ok){be({type:"err",text:i("ollama.detectFailed")});return}const Ie=await le.json();Ye(Ie),Ie.found&&Ie.models&&Ie.models.length>0?Lt(Ie.models[0].name):Ie.found||be({type:"err",text:Ie.error||i("ollama.notRunning")})}catch{be({type:"err",text:i("ollama.detectFailed")})}finally{mt(!1)}},[i]),ni=T?Object.values(T.providers).some(le=>le.configured):!1;g.useEffect(()=>{T&&!ni&&!Re.current&&(Re.current=!0,ra(),ds())},[T,ni,ra,ds]);const ri=async()=>{if(!(!R||R===T?.defaultProvider)){B(!0),V(null);try{const le=await fetch("/api/settings/llm",{method:"POST",headers:br(),body:JSON.stringify({defaultProvider:R})}),Ie=await le.json();le.ok?(E(Ie),V({type:"ok",text:i("defaultProvider.updated",{name:Ie.defaultProvider})})):V({type:"err",text:Ie.error??i("modelProviders.saveFailed")})}catch{V({type:"err",text:i("common:networkError")})}finally{B(!1)}}},za=async(le,Ie)=>{O(le);try{const st=await fetch(`/api/settings/llm/providers/${le}/toggle`,{method:"POST",headers:br(),body:JSON.stringify({enabled:Ie})});if(st.ok){const hn=await st.json();E(hn)}}catch{}finally{O(null)}},vi=async()=>{_(!0),X(null);try{const Ie=await(await fetch("/api/settings/import/openclaw",{method:"POST",headers:br(),body:JSON.stringify({preview:!0})})).json();"error"in Ie?X({type:"err",text:Ie.error}):q(Ie)}catch{X({type:"err",text:i("openClaw.detectFailed")})}finally{_(!1)}},si=async()=>{_(!0),X(null);try{const Ie=await(await fetch("/api/settings/import/openclaw",{method:"POST",headers:br(),body:JSON.stringify({preview:!1})})).json();"error"in Ie?X({type:"err",text:Ie.error}):(X({type:"ok",text:i("openClaw.importedFrom",{count:Ie.appliedModels})}),fr())}catch{X({type:"err",text:i("openClaw.importFailed")})}finally{_(!1)}},sa=async()=>{if(!ee)return;const le=ee.detected.filter(Ie=>Be[Ie.provider]);if(le.length===0){Ce({type:"err",text:i("envConfig.selectAtLeastOne")});return}_e(!0),Ce(null);try{const Ie=await fetch("/api/settings/env-models",{method:"POST",headers:br(),body:JSON.stringify({providers:le.map(hn=>({provider:hn.provider,model:hn.model,baseUrl:hn.baseUrl,enabled:!0}))})});if(!Ie.ok){Ce({type:"err",text:i("envConfig.applyFailed",{status:Ie.status})});return}const st=await Ie.json();Ce({type:"ok",text:st.message}),te(null),Ne({}),fr()}catch{Ce({type:"err",text:i("envConfig.failedToApply")})}finally{_e(!1)}},Ys=async()=>{if(!(!Ee?.found||!it)){ne(!0),be(null);try{const le=await fetch("/api/settings/llm/providers",{method:"POST",headers:br(),body:JSON.stringify({name:"ollama",model:it,baseUrl:Ee.baseUrl||"http://localhost:11434"})});if(le.ok){const Ie=await le.json();E(Ie),be({type:"ok",text:i("ollama.configured",{model:it})}),Ye(null)}else{const Ie=await le.json();be({type:"err",text:Ie.error||i("ollama.applyFailed")})}}catch{be({type:"err",text:i("ollama.applyFailed")})}finally{ne(!1)}}};g.useEffect(()=>()=>{je.current&&clearInterval(je.current)},[]),g.useEffect(()=>{if(w!=="browser"||Vn)return;const le=setInterval(async()=>{try{(await ie.settings.getBrowser()).extensionConnected&&(Qn(!0),clearInterval(le))}catch{}},5e3);return()=>clearInterval(le)},[w,Vn]);const[ya,Ls]=g.useState(!1),[Yn,Ns]=g.useState({name:"",apiKey:"",baseUrl:"",model:"",contextWindow:128e3,maxOutputTokens:16384,costInput:1,costOutput:5}),[va,Ss]=g.useState(!1),[yr,Ps]=g.useState(null),[is,qr]=g.useState([]),[ai,Cs]=g.useState(!1),[aa,$a]=g.useState(null),[Xn,Ts]=g.useState({apiKey:"",baseUrl:"",model:"",contextWindow:0,maxOutputTokens:0,costInput:0,costOutput:0}),[Os,Di]=g.useState(!1),[Or,kn]=g.useState(null),[_s,Fs]=g.useState(""),[ii,oi]=g.useState(!1),[Xs,zr]=g.useState(null),[qs,wa]=g.useState(null),[Us,Zr]=g.useState({id:"",name:"",contextWindow:128e3,maxOutputTokens:16384,costInput:1,costOutput:5,reasoning:!1,vision:!1}),[zs,ka]=g.useState(!1),Ri=async(le,Ie)=>{if(!le||le==="__custom__")return;Cs(!0),zr(null);const st=Bu.find(Cn=>Cn.id===le),hn=Yn.baseUrl||st?.baseUrl;try{if(Ie){const Cn=await ie.modelCatalog.validateKey(le,Ie,hn||void 0);!Cn.valid&&Cn.error&&zr({type:"err",text:Cn.error}),qr(Cn.models)}else{const Cn=await ie.modelCatalog.getByProvider(le);qr(Cn.models)}}catch{qr([])}finally{Cs(!1)}},ja=async()=>{if(!(!Yn.name||!Yn.model)){Ss(!0),Ps(null),zr(null);try{const le=await fetch("/api/settings/llm/providers",{method:"POST",headers:br(),body:JSON.stringify({name:Yn.name,apiKey:Yn.apiKey||void 0,baseUrl:Yn.baseUrl||void 0,model:Yn.model,contextWindow:Yn.contextWindow||void 0,maxOutputTokens:Yn.maxOutputTokens||void 0,cost:Yn.costInput||Yn.costOutput?{input:Yn.costInput,output:Yn.costOutput}:void 0})}),Ie=await le.json();le.ok?(E(Ie),Ls(!1),Fs(""),qr([]),Ns({name:"",apiKey:"",baseUrl:"",model:"",contextWindow:128e3,maxOutputTokens:16384,costInput:1,costOutput:5}),zr({type:"ok",text:i("modelProviders.providerAdded",{name:Yn.name})})):zr({type:"err",text:Ie.error??i("modelProviders.failedToAdd")})}catch{zr({type:"err",text:i("common:networkError")})}finally{Ss(!1)}}},Na=async(le,Ie)=>{if(!_s.trim())return;oi(!0),zr(null);const st=Bu.find($s=>$s.id===le),hn=st?.defaultModel??le,Cn=st?.baseUrl;try{const $s=await fetch("/api/settings/llm/providers",{method:"POST",headers:br(),body:JSON.stringify({name:le,apiKey:_s.trim(),model:hn,baseUrl:Cn})}),ro=await $s.json();$s.ok?(E(ro),Fs(""),qr([]),zr({type:"ok",text:i("modelProviders.quickSetupSuccess",{name:st?.label??le})})):zr({type:"err",text:ro.error??i("modelProviders.failedToAdd")})}catch{zr({type:"err",text:i("common:networkError")})}finally{oi(!1)}},Sa=(le,Ie)=>{$a(le),Ts({apiKey:"",baseUrl:Ie.baseUrl??"",model:Ie.model,contextWindow:Ie.contextWindow??0,maxOutputTokens:Ie.maxOutputTokens??0,costInput:Ie.cost?.input??0,costOutput:Ie.cost?.output??0})},oe=async le=>{Di(!0);try{const Ie={};Xn.apiKey&&(Ie.apiKey=Xn.apiKey),Xn.baseUrl!==void 0&&(Ie.baseUrl=Xn.baseUrl),Xn.model&&(Ie.model=Xn.model),Xn.contextWindow&&(Ie.contextWindow=Xn.contextWindow),Xn.maxOutputTokens&&(Ie.maxOutputTokens=Xn.maxOutputTokens),(Xn.costInput||Xn.costOutput)&&(Ie.cost={input:Xn.costInput,output:Xn.costOutput});const st=await fetch(`/api/settings/llm/providers/${le}`,{method:"PUT",headers:br(),body:JSON.stringify(Ie)});if(st.ok){const hn=await st.json();E(hn),$a(null)}}catch{}finally{Di(!1)}},Qe=async le=>{kn(le);try{const Ie=await fetch(`/api/settings/llm/providers/${le}`,{method:"DELETE",headers:br()});if(Ie.ok){const st=await Ie.json();E(st),I(st.defaultProvider)}}catch{}finally{kn(null)}},dt=async le=>{if(!(!Us.id||!Us.name)){ka(!0);try{const Ie=await fetch(`/api/settings/llm/providers/${le}/models`,{method:"POST",headers:br(),body:JSON.stringify({id:Us.id,name:Us.name,contextWindow:Us.contextWindow,maxOutputTokens:Us.maxOutputTokens,cost:{input:Us.costInput,output:Us.costOutput},reasoning:Us.reasoning||void 0,inputTypes:Us.vision?["text","image"]:["text"]})});if(Ie.ok){const st=await Ie.json();E(st),wa(null),Zr({id:"",name:"",contextWindow:128e3,maxOutputTokens:16384,costInput:1,costOutput:5,reasoning:!1,vision:!1})}}catch{}finally{ka(!1)}}},Rt=async(le,Ie)=>{try{const st=await fetch(`/api/settings/llm/providers/${le}/models/${encodeURIComponent(Ie)}`,{method:"DELETE",headers:br()});if(st.ok){const hn=await st.json();E(hn)}}catch{}},fn=new Set(["claude-opus-4-6","claude-sonnet-4-20250514","claude-3-5-haiku-20241022","gpt-5.4","gpt-4o","o4-mini","gemini-3-1-pro","gemini-2.5-flash","MiniMax-M2.7","MiniMax-M2.5","xiaomi/mimo-v2-pro","anthropic/claude-opus-4-6","openai/gpt-5.4","google/gemini-3-1-pro","deepseek-v4-flash","deepseek-v4-pro","deepseek-chat","deepseek-reasoner"]),[hr,un]=g.useState(null),[yt,us]=g.useState(null),[Ur,ms]=g.useState({}),os=async le=>{us(le),ms(Ie=>{const st={...Ie};return delete st[le],st});try{const Ie=await fetch(`/api/settings/llm/providers/${le}/test`,{method:"POST",headers:br()});if(!Ie.ok){const hn=await Ie.json().catch(()=>({}));ms(Cn=>({...Cn,[le]:{ok:!1,error:hn.error??`HTTP ${Ie.status}`,errorCode:Ie.status}}));return}const st=await Ie.json();ms(hn=>({...hn,[le]:st}))}catch{ms(Ie=>({...Ie,[le]:{ok:!1,error:i("common:networkError")}}))}finally{us(null)}},Vr=async(le,Ie)=>{un(`${le}:${Ie}`);try{const st=await fetch(`/api/settings/llm/providers/${le}/model`,{method:"POST",headers:br(),body:JSON.stringify({model:Ie})});if(st.ok){const hn=await st.json();E(hn)}}catch{}finally{un(null)}},fs=async()=>{if(Xt.serperApiKey||Xt.tavilyApiKey||Xt.bingApiKey||Xt.googleSearchApiKey||Xt.googleSearchCx||Xt.serpApiKey||Xt.braveApiKey||Xt.exaApiKey||Xt.bochaApiKey){vt(!0),dn(null);try{const Ie={};Xt.serperApiKey&&(Ie.serperApiKey=Xt.serperApiKey),Xt.tavilyApiKey&&(Ie.tavilyApiKey=Xt.tavilyApiKey),Xt.bingApiKey&&(Ie.bingApiKey=Xt.bingApiKey),Xt.googleSearchApiKey&&(Ie.googleSearchApiKey=Xt.googleSearchApiKey),Xt.googleSearchCx&&(Ie.googleSearchCx=Xt.googleSearchCx),Xt.serpApiKey&&(Ie.serpApiKey=Xt.serpApiKey),Xt.braveApiKey&&(Ie.braveApiKey=Xt.braveApiKey),Xt.exaApiKey&&(Ie.exaApiKey=Xt.exaApiKey),Xt.bochaApiKey&&(Ie.bochaApiKey=Xt.bochaApiKey);const st=await ie.settings.updateSearch(Ie);Zn(st),ye({serperApiKey:"",tavilyApiKey:"",bingApiKey:"",googleSearchApiKey:"",googleSearchCx:"",serpApiKey:"",braveApiKey:"",exaApiKey:"",bochaApiKey:""}),dn({type:"ok",text:i("searchApi.saved")})}catch{dn({type:"err",text:i("searchApi.failedToSave")})}finally{vt(!1)}}},jr=T?.providers?Object.entries(T.providers).filter(([,le])=>le.configured&&le.enabled).map(([le])=>le):[],to=T&&!ni&&!We,Ii=r?.role==="owner"||r?.role==="admin",no=JS.filter(le=>!le.adminOnly||Ii);return n.jsxs("div",{className:"flex-1 flex overflow-hidden",children:[h&&r&&n.jsx(dY,{authUser:r,onClose:()=>p(!1),onSaved:le=>{p(!1),a?.(le)}}),n.jsxs("aside",{className:"hidden md:flex flex-col w-56 shrink-0 border-r border-border-default bg-surface-secondary overflow-y-auto",children:[n.jsx("div",{className:"px-3 pt-4 pb-2",children:n.jsxs("button",{onClick:()=>{bt.navigate(De.HOME)},className:"flex items-center gap-2 px-2 py-1.5 rounded-lg text-sm text-fg-secondary hover:text-fg-primary hover:bg-surface-overlay transition-colors",children:[n.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("path",{d:"M19 12H5"}),n.jsx("polyline",{points:"12 19 5 12 12 5"})]}),i("common:back",{defaultValue:"Back"})]})}),n.jsx("div",{className:"px-5 pb-4",children:n.jsx("h2",{className:"text-base font-semibold text-fg-primary",children:i("title")})}),n.jsx("nav",{className:"flex-1 px-3 pb-4 space-y-0.5",children:no.map(le=>n.jsx("button",{onClick:()=>j(le.id),className:`w-full text-left px-3 py-2 rounded-lg text-sm transition-colors ${w===le.id?"bg-brand-600/10 text-brand-600 dark:text-brand-400 font-medium":"text-fg-secondary hover:text-fg-primary hover:bg-surface-overlay"}`,children:i(`settings:${le.labelKey}`)},le.id))}),r&&n.jsx("div",{className:"px-3 pb-4 border-t border-border-default pt-3",children:n.jsxs("div",{ref:y,className:"relative",children:[n.jsxs("button",{onClick:()=>m(!u),className:"w-full flex items-center gap-2.5 px-3 py-2 rounded-lg hover:bg-surface-overlay transition-colors",children:[n.jsx(Nr,{name:r.name||i("common:userPlaceholder"),avatarUrl:r.avatarUrl,size:24}),n.jsx("span",{className:"text-sm text-fg-secondary truncate flex-1 text-left",children:r.name||i("common:userPlaceholder")})]}),u&&n.jsxs("div",{className:"absolute left-0 bottom-full mb-1 bg-surface-secondary border border-border-default rounded-xl shadow-xl z-50 overflow-hidden",style:{minWidth:200},children:[n.jsxs("div",{className:"px-4 py-3 border-b border-border-default",children:[n.jsx("div",{className:"text-sm font-medium text-fg-primary",children:r.name||i("common:userPlaceholder")}),n.jsx("div",{className:"text-xs text-fg-tertiary mt-0.5",children:r.email||r.role})]}),n.jsxs("div",{className:"py-1",children:[n.jsxs("button",{onClick:()=>{m(!1),p(!0)},className:"w-full flex items-center gap-2.5 px-4 py-2 text-sm text-fg-secondary hover:bg-surface-overlay transition-colors",children:[n.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("path",{d:"M20 21v-2a4 4 0 0 0-4-4H8a4 4 0 0 0-4 4v2"}),n.jsx("circle",{cx:"12",cy:"7",r:"4"})]}),i("common:profile.editProfile")]}),s&&n.jsxs("button",{onClick:()=>{m(!1),s()},className:"w-full flex items-center gap-2.5 px-4 py-2 text-sm text-red-500 hover:bg-red-500/10 transition-colors",children:[n.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("path",{d:"M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4"}),n.jsx("polyline",{points:"16 17 21 12 16 7"}),n.jsx("line",{x1:"21",y1:"12",x2:"9",y2:"12"})]}),i("common:signOut",{defaultValue:"Sign Out"})]})]})]})]})})]}),n.jsxs("div",{className:"flex-1 overflow-y-auto",children:[d&&w===null&&n.jsxs("div",{className:"flex flex-col h-full",children:[n.jsxs("div",{className:"flex items-center gap-3 px-4 py-3 border-b border-border-default bg-surface-secondary",children:[n.jsx("button",{onClick:()=>bt.navigate(De.HOME),className:"p-1.5 rounded-lg hover:bg-surface-overlay transition-colors",children:n.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("path",{d:"M19 12H5"}),n.jsx("polyline",{points:"12 19 5 12 12 5"})]})}),n.jsx("h1",{className:"text-base font-semibold text-fg-primary",children:i("title")})]}),n.jsx("nav",{className:"flex-1 overflow-y-auto py-2 px-3",children:no.map(le=>n.jsxs("button",{onClick:()=>j(le.id),className:"w-full flex items-center justify-between px-4 py-3 rounded-lg text-sm text-fg-primary hover:bg-surface-overlay transition-colors",children:[n.jsx("span",{children:i(`settings:${le.labelKey}`)}),n.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",className:"text-fg-tertiary",children:n.jsx("polyline",{points:"9 18 15 12 9 6"})})]},le.id))})]}),d&&w!==null&&n.jsxs("div",{className:"flex items-center gap-3 px-4 py-3 border-b border-border-default bg-surface-secondary sticky top-0 z-10",children:[n.jsx("button",{onClick:C,className:"p-1.5 rounded-lg hover:bg-surface-overlay transition-colors",children:n.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("path",{d:"M19 12H5"}),n.jsx("polyline",{points:"12 19 5 12 12 5"})]})}),n.jsx("h1",{className:"text-base font-semibold text-fg-primary",children:i(`settings:${no.find(le=>le.id===w)?.labelKey||"title"}`)})]}),w!==null&&n.jsxs("div",{className:"p-7 space-y-10 max-w-4xl mx-auto w-full",children:[w==="appearance"&&n.jsx(pi,{title:i("appearance.title"),children:n.jsxs("div",{className:"bg-surface-elevated rounded-xl p-5",children:[n.jsxs("div",{className:"flex flex-col gap-3 md:flex-row md:items-center md:justify-between",children:[n.jsxs("div",{children:[n.jsx("div",{className:"text-sm font-medium",children:i("appearance.theme")}),n.jsx("div",{className:"text-xs text-fg-tertiary mt-0.5",children:i("appearance.themeDesc")})]}),n.jsx("div",{className:"flex flex-wrap gap-1 bg-surface-elevated rounded-lg p-0.5",children:eY.map(({value:le})=>n.jsx("button",{onClick:()=>t?.(le),className:`px-3 py-1.5 text-xs rounded-md transition-colors ${e===le?"bg-brand-600 text-white":"text-fg-secondary hover:text-fg-primary"}`,children:i(`appearance.modes.${le}`)},le))})]}),n.jsxs("div",{className:"flex flex-col gap-3 md:flex-row md:items-center md:justify-between mt-5 pt-5 border-t border-border-default/50",children:[n.jsxs("div",{children:[n.jsx("div",{className:"text-sm font-medium",children:i("appearance.language")}),n.jsx("div",{className:"text-xs text-fg-tertiary mt-0.5",children:i("appearance.languageDesc")})]}),n.jsx("div",{className:"flex flex-wrap gap-1 bg-surface-elevated rounded-lg p-0.5",children:fw.map(({code:le,label:Ie})=>n.jsx("button",{onClick:()=>{l.changeLanguage(le)},className:`px-3 py-1.5 text-xs rounded-md transition-colors ${l.language===le||le==="en"&&!fw.some(st=>st.code===l.language)?"bg-brand-600 text-white":"text-fg-secondary hover:text-fg-primary"}`,children:Ie},le))})]})]})}),Ii&&n.jsxs(n.Fragment,{children:[w==="providers"&&n.jsxs(n.Fragment,{children:[to&&n.jsxs("div",{className:"relative bg-gradient-to-br from-brand-500/10 to-surface-secondary border border-brand-500/20 rounded-2xl p-6 space-y-5",children:[n.jsx("button",{onClick:()=>Vt(!0),className:"absolute top-4 right-4 text-fg-tertiary hover:text-fg-secondary text-xs",children:i("setupGuide.skip")}),n.jsxs("div",{children:[n.jsx("h3",{className:"text-base font-semibold text-fg-primary",children:i("setupGuide.title")}),n.jsx("p",{className:"text-sm text-fg-secondary mt-1",children:i("setupGuide.subtitle")})]}),n.jsxs(Du,{step:i("setupGuide.fromEnv.step"),title:i("setupGuide.fromEnv.title"),description:i("setupGuide.fromEnv.description"),active:!!(ee&&ee.detected.length>0),children:[G&&n.jsx("div",{className:"text-xs text-fg-tertiary",children:i("common:detecting")}),ee&&ee.detected.length>0&&n.jsxs("div",{className:"space-y-2",children:[ee.detected.map(le=>n.jsxs("label",{className:"flex items-center gap-3 bg-surface-elevated/30 rounded-lg px-3 py-2 cursor-pointer hover:bg-surface-elevated/50 transition-colors",children:[n.jsx("input",{type:"checkbox",checked:Be[le.provider]??!1,onChange:Ie=>Ne({...Be,[le.provider]:Ie.target.checked}),className:"w-4 h-4 rounded bg-surface-overlay border-gray-600 text-brand-500 focus:ring-brand-500"}),n.jsxs("div",{className:"flex-1 min-w-0",children:[n.jsx("span",{className:"text-sm text-fg-primary",children:le.displayName}),n.jsx("span",{className:"text-xs text-fg-tertiary ml-2",children:le.model})]}),n.jsx("code",{className:"text-[10px] text-fg-tertiary",children:le.apiKeyPreview})]},le.provider)),n.jsx("button",{onClick:()=>{sa()},disabled:he||Object.values(Be).filter(Boolean).length===0,className:"w-full px-4 py-2 bg-brand-600 hover:bg-brand-500 disabled:opacity-40 text-white text-sm rounded-lg transition-colors",children:he?i("common:applying"):i("setupGuide.applyProviders",{count:Object.values(Be).filter(Boolean).length})})]}),ee&&ee.detected.length===0&&n.jsx("div",{className:"text-xs text-fg-tertiary",children:n.jsx(n0,{i18nKey:"settings:setupGuide.fromEnv.noKeysHint",components:{code:n.jsx("code",{className:"text-fg-secondary"})}})}),Se&&n.jsx(Ka,{type:Se.type,text:Se.text})]}),n.jsxs(Du,{step:i("setupGuide.fromOllama.step"),title:i("setupGuide.fromOllama.title"),description:i("setupGuide.fromOllama.description"),active:!!Ee?.found,children:[Ze&&n.jsx("div",{className:"text-xs text-fg-tertiary",children:i("common:detecting")}),Ee?.found&&Ee.models&&Ee.models.length>0&&n.jsxs("div",{className:"space-y-2",children:[n.jsx("div",{className:"text-xs text-green-600",children:i("ollama.foundModels",{count:Ee.models.length,url:Ee.baseUrl})}),n.jsx("select",{value:it,onChange:le=>Lt(le.target.value),className:"w-full px-3 py-2 bg-surface-overlay border border-border-default rounded-lg text-sm text-fg-primary focus:outline-none focus:ring-2 focus:ring-brand-500",children:Ee.models.map(le=>n.jsxs("option",{value:le.name,children:[le.name,le.parameterSize?` (${le.parameterSize})`:"",le.family?` — ${le.family}`:""]},le.name))}),n.jsx("button",{onClick:()=>{Ys()},disabled:ht||!it,className:"w-full px-4 py-2 bg-brand-600 hover:bg-brand-500 disabled:opacity-40 text-white text-sm rounded-lg transition-colors",children:ht?i("common:applying"):i("ollama.useModel",{model:it})})]}),!Ze&&!Ee&&n.jsx("button",{onClick:()=>{ds()},className:"px-4 py-2 border border-border-default hover:bg-surface-elevated text-fg-secondary text-sm rounded-lg transition-colors",children:i("ollama.detect")}),Ee&&!Ee.found&&n.jsx("div",{className:"text-xs text-fg-tertiary",children:i("ollama.notRunning")}),me&&n.jsx(Ka,{type:me.type,text:me.text})]}),n.jsxs(Du,{step:i("setupGuide.fromOpenClaw.step"),title:i("setupGuide.fromOpenClaw.title"),description:i("setupGuide.fromOpenClaw.description"),children:[H?H.found?n.jsxs("div",{className:"space-y-2",children:[n.jsxs("div",{className:"text-xs text-green-600",children:[i("setupGuide.foundPrefix")," ",n.jsx("code",{className:"text-fg-secondary",children:H.summary.configPath})]}),H.summary.models&&n.jsx("div",{className:"text-xs text-fg-secondary",children:i("openClaw.providersModels",{providers:H.summary.models.providerCount,models:H.summary.models.providers.reduce((le,Ie)=>le+Ie.modelCount,0)})}),n.jsx("button",{onClick:()=>{si()},disabled:Z,className:"w-full px-4 py-2 bg-brand-600 hover:bg-brand-500 disabled:opacity-40 text-white text-sm rounded-lg transition-colors",children:i(Z?"common:importing":"openClaw.importConfigs")})]}):n.jsx("div",{className:"text-xs text-fg-tertiary",children:i("openClaw.notFound")}):n.jsx("button",{onClick:()=>{vi()},disabled:Z,className:"px-4 py-2 border border-border-default hover:bg-surface-elevated disabled:opacity-40 text-fg-secondary text-sm rounded-lg transition-colors",children:i(Z?"common:detecting":"openClaw.detectShort")}),J&&n.jsx(Ka,{type:J.type,text:J.text})]}),n.jsx(Du,{step:i("setupGuide.manual.step"),title:i("setupGuide.manual.title"),description:n.jsx(n0,{i18nKey:"settings:setupGuide.manual.description",components:{code:n.jsx("code",{className:"text-fg-secondary"})}})}),/Chrome\/\d/.test(navigator.userAgent)&&!/Edg\//.test(navigator.userAgent)&&n.jsx(Du,{step:i("setupGuide.browserExtension.step"),title:i("setupGuide.browserExtension.title"),description:i("setupGuide.browserExtension.description"),active:Vn,children:Vn?n.jsxs("div",{className:"flex items-center gap-1.5 text-xs text-green-400",children:[n.jsx("svg",{className:"w-3.5 h-3.5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:n.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 13l4 4L19 7"})}),i("setupGuide.browserExtension.alreadyConnected")]}):n.jsxs("div",{className:"space-y-2",children:[n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsxs("button",{disabled:ve,onClick:async()=>{tt(!0);try{await ie.settings.downloadExtensionZip()}catch{}tt(!1)},className:"px-3 py-1.5 text-xs bg-brand-500 text-white rounded-lg hover:bg-brand-600 transition-colors disabled:opacity-40 inline-flex items-center gap-1.5",children:[n.jsx("svg",{className:"w-3.5 h-3.5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:n.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 16v1a3 3 0 003 3h10a3 3 0 003-3v-1m-4-4l-4 4m0 0l-4-4m4 4V4"})}),i("setupGuide.browserExtension.downloadBtn")]}),navigator.platform.toUpperCase().includes("WIN")?n.jsxs("span",{className:"px-3 py-1.5 text-xs text-fg-secondary inline-flex items-center gap-1.5",children:[i("setupGuide.browserExtension.openChromeBtn"),":",n.jsx("code",{className:"px-1.5 py-0.5 bg-surface-elevated rounded text-fg-primary font-mono text-[11px] select-all",children:"chrome://extensions"})]}):n.jsxs("button",{disabled:ve,onClick:async()=>{try{await ie.settings.openExtensionsPage()}catch{}},className:"px-3 py-1.5 text-xs border border-border-default text-fg-primary rounded-lg hover:bg-surface-elevated transition-colors disabled:opacity-40 inline-flex items-center gap-1.5",children:[n.jsx("svg",{className:"w-3.5 h-3.5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:n.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M10 6H6a2 2 0 00-2 2v10a2 2 0 002 2h10a2 2 0 002-2v-4M14 4h6m0 0v6m0-6L10 14"})}),i("setupGuide.browserExtension.openChromeBtn")]})]}),n.jsx("div",{className:"text-xs text-fg-tertiary",children:i("setupGuide.browserExtension.loadHint")})]})})]}),n.jsx(pi,{title:i("systemStatus.title"),children:N?n.jsxs("div",{className:"grid grid-cols-3 gap-4",children:[n.jsx(Kx,{label:i("systemStatus.status"),value:N.status==="ok"?i("systemStatus.healthy"):N.status,color:"green"}),n.jsx(Kx,{label:i("systemStatus.version"),value:N.version,color:"indigo"}),n.jsx(Kx,{label:i("systemStatus.activeAgents"),value:String(N.agents),color:"purple"})]}):n.jsx("div",{className:"text-sm text-fg-tertiary",children:i("common:loading")})}),n.jsx(pi,{title:i("defaultProvider.title"),children:n.jsxs("div",{className:"bg-surface-elevated rounded-xl p-5 space-y-4",children:[n.jsxs("div",{className:"flex items-center justify-between",children:[n.jsxs("div",{children:[n.jsx("div",{className:"text-sm font-medium",children:i("defaultProvider.primaryProvider")}),n.jsx("div",{className:"text-xs text-fg-tertiary mt-0.5",children:i("defaultProvider.primaryProviderDesc")})]}),n.jsxs("div",{className:"flex items-center gap-3",children:[T?n.jsx("select",{value:R,onChange:le=>{I(le.target.value),V(null)},className:"px-3 py-1.5 bg-surface-elevated border border-border-default rounded-lg text-sm w-48 focus:border-brand-500 outline-none",children:jr.length>0?jr.map(le=>n.jsx("option",{value:le,children:T.providers[le]?.displayName??le},le)):n.jsx("option",{value:"",children:i("defaultProvider.noProviders")})}):n.jsx("div",{className:"text-xs text-fg-tertiary",children:i("common:loading")}),R!==T?.defaultProvider&&n.jsx("button",{onClick:()=>{ri()},disabled:z,className:"px-3 py-1.5 text-xs bg-brand-600 hover:bg-brand-500 disabled:opacity-40 text-white rounded-lg transition-colors",children:i(z?"common:saving":"common:save")})]})]}),D&&n.jsx(Ka,{type:D.type,text:D.text}),n.jsxs("div",{className:"flex items-center justify-between border-t border-border-default pt-4",children:[n.jsxs("div",{children:[n.jsx("div",{className:"text-sm font-medium text-fg-primary",children:i("defaultProvider.autoFallback")}),n.jsx("div",{className:"text-xs text-fg-tertiary mt-0.5",children:i("defaultProvider.autoFallbackDesc")})]}),n.jsx("button",{onClick:async()=>{const le=!(T?.autoFallback??!0);try{const Ie=await fetch("/api/settings/llm",{method:"POST",headers:br(),body:JSON.stringify({autoFallback:le})});if(Ie.ok){const st=await Ie.json();E(st)}}catch{}},className:`relative inline-flex h-5 w-9 items-center rounded-full transition-colors ${T?.autoFallback??!0?"bg-green-500":"bg-gray-600"}`,children:n.jsx("span",{className:`inline-block h-3.5 w-3.5 rounded-full bg-white transition-transform ${T?.autoFallback??!0?"translate-x-4":"translate-x-1"}`})})]})]})}),n.jsxs(pi,{title:i("modelProviders.title"),children:[n.jsx("div",{className:"space-y-3",children:T&&(()=>{const le=[],Ie=new Set;for(const[st,hn]of Object.entries(T.providers))le.push([st,hn]),Ie.add(st);for(const st of Bu)Ie.has(st.id)||(le.push([st.id,{name:st.id,displayName:st.label,model:st.defaultModel,configured:!1,enabled:!1}]),Ie.add(st.id));return le})().map(([le,Ie])=>n.jsxs("div",{className:`bg-surface-secondary border rounded-xl overflow-hidden transition-colors ${Ie.configured?"border-border-default hover:border-gray-600":"border-border-default/50 hover:border-brand-500/30"}`,children:[n.jsxs("div",{className:"flex items-center justify-between px-5 py-4 cursor-pointer",onClick:()=>{F(Y===le?null:le),Fs(""),zr(null),qr([]),Ns(st=>({...st,name:"",model:""}))},children:[n.jsxs("div",{className:"flex items-center gap-3",children:[n.jsx("span",{className:`w-2 h-2 rounded-full ${Ie.configured&&Ie.enabled?"bg-green-400":Ie.configured?"bg-amber-400":"bg-gray-600"}`}),n.jsxs("div",{children:[n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx("span",{className:"text-sm font-medium",children:Ie.displayName??le}),le===T.defaultProvider&&n.jsx("span",{className:"text-[10px] bg-brand-500/15 text-brand-500 px-1.5 py-0.5 rounded",children:i("modelProviders.badgeDefault")}),Ie.configured&&!Ie.enabled&&n.jsx("span",{className:"text-[10px] bg-amber-500/15 text-amber-600 px-1.5 py-0.5 rounded",children:i("modelProviders.disabled")}),Ie.oauthConnected&&n.jsx("span",{className:"text-[10px] bg-green-500/15 text-green-600 px-1.5 py-0.5 rounded",children:i("modelProviders.badgeOAuth")}),Ur[le]?.ok===!0&&n.jsx("span",{className:"text-[10px] bg-green-500/15 text-green-600 px-1.5 py-0.5 rounded",children:i("modelProviders.testOk",{ms:Ur[le].durationMs})}),Ur[le]?.ok===!1&&n.jsx("span",{className:"text-[10px] bg-red-500/15 text-red-500 px-1.5 py-0.5 rounded",title:Ur[le].error,children:Ur[le].errorCode?i("modelProviders.testFailedCode",{code:Ur[le].errorCode}):i("modelProviders.testFailed")})]}),n.jsx("div",{className:"text-xs text-fg-tertiary mt-0.5",children:Ie.configured?n.jsxs(n.Fragment,{children:[Ie.model,Ie.apiKeyPreview&&n.jsxs(n.Fragment,{children:[" · ",n.jsx("code",{className:"text-fg-secondary",children:Ie.apiKeyPreview})]})]}):i("modelProviders.notConfigured")})]})]}),n.jsxs("div",{className:"flex items-center gap-4",children:[Ie.configured&&n.jsx("button",{onClick:st=>{st.stopPropagation(),za(le,!Ie.enabled)},disabled:L===le,className:`relative inline-flex h-5 w-9 items-center rounded-full transition-colors ${Ie.enabled?"bg-green-500":"bg-gray-600"} ${L===le?"opacity-50":""}`,title:Ie.enabled?i("modelProviders.clickToDisable"):i("modelProviders.clickToEnable"),children:n.jsx("span",{className:`inline-block h-3.5 w-3.5 rounded-full bg-white transition-transform ${Ie.enabled?"translate-x-4":"translate-x-1"}`})}),Ie.contextWindow!=null&&Ie.contextWindow>0&&n.jsx("span",{className:"text-[10px] text-fg-tertiary",children:i("modelProviders.ctxTokens",{size:(Ie.contextWindow/1e3).toFixed(0)})}),Ie.cost&&(Ie.cost.input>0||Ie.cost.output>0)&&n.jsx("span",{className:"text-[10px] text-fg-tertiary",children:i("modelProviders.costPerMillion",{input:Ie.cost.input,output:Ie.cost.output})}),n.jsx("span",{className:"text-fg-tertiary text-xs",children:Y===le?"▲":"▼"})]})]}),Y===le&&n.jsxs("div",{className:"px-5 pb-4 border-t border-border-default pt-4 space-y-4",children:[Ie.configured&&n.jsxs(n.Fragment,{children:[n.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-3",children:[n.jsx(ml,{label:i("modelProviders.model"),value:Ie.model}),n.jsx(ml,{label:i("modelProviders.contextWindow"),value:Ie.contextWindow?i("modelProviders.kTokens",{k:(Ie.contextWindow/1e3).toFixed(0)}):i("modelProviders.notApplicable")}),n.jsx(ml,{label:i("modelProviders.maxOutput"),value:Ie.maxOutputTokens?i("modelProviders.kTokens",{k:(Ie.maxOutputTokens/1e3).toFixed(0)}):i("modelProviders.notApplicable")}),n.jsx(ml,{label:i("modelProviders.baseUrlLabel"),value:Ie.baseUrl??i("modelProviders.baseUrlDisplayDefault")})]}),aa===le?n.jsxs("div",{className:"bg-surface-elevated/40 rounded-lg p-4 space-y-3",children:[n.jsx("div",{className:"text-[10px] text-fg-tertiary uppercase tracking-wider",children:i("modelProviders.editProvider")}),n.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-3",children:[n.jsxs("div",{children:[n.jsx("label",{className:"text-[10px] text-fg-tertiary uppercase block mb-1",children:i("modelProviders.apiKey")}),n.jsx("input",{type:"password",value:Xn.apiKey,onChange:st=>Ts({...Xn,apiKey:st.target.value}),placeholder:i("modelProviders.apiKeyPlaceholder"),className:"w-full px-3 py-1.5 text-xs bg-surface-primary border border-border-default rounded-lg text-fg-primary placeholder-fg-tertiary focus:border-brand-500 outline-none"})]}),n.jsxs("div",{children:[n.jsx("label",{className:"text-[10px] text-fg-tertiary uppercase block mb-1",children:i("modelProviders.baseUrl")}),n.jsx("input",{type:"text",value:Xn.baseUrl,onChange:st=>Ts({...Xn,baseUrl:st.target.value}),placeholder:i("modelProviders.baseUrlDisplayDefault"),className:"w-full px-3 py-1.5 text-xs bg-surface-primary border border-border-default rounded-lg text-fg-primary placeholder-fg-tertiary focus:border-brand-500 outline-none"})]}),n.jsxs("div",{children:[n.jsx("label",{className:"text-[10px] text-fg-tertiary uppercase block mb-1",children:i("modelProviders.model")}),n.jsx("input",{type:"text",value:Xn.model,onChange:st=>Ts({...Xn,model:st.target.value}),className:"w-full px-3 py-1.5 text-xs bg-surface-primary border border-border-default rounded-lg text-fg-primary focus:border-brand-500 outline-none"})]})]}),n.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-3",children:[n.jsxs("div",{children:[n.jsx("label",{className:"text-[10px] text-fg-tertiary uppercase block mb-1",children:i("modelProviders.contextWindow")}),n.jsx("input",{type:"number",value:Xn.contextWindow||"",onChange:st=>Ts({...Xn,contextWindow:Number(st.target.value)}),placeholder:i("modelProviders.placeholderContextExample"),className:"w-full px-3 py-1.5 text-xs bg-surface-primary border border-border-default rounded-lg text-fg-primary placeholder-fg-tertiary focus:border-brand-500 outline-none"})]}),n.jsxs("div",{children:[n.jsx("label",{className:"text-[10px] text-fg-tertiary uppercase block mb-1",children:i("modelProviders.maxOutputTokens")}),n.jsx("input",{type:"number",value:Xn.maxOutputTokens||"",onChange:st=>Ts({...Xn,maxOutputTokens:Number(st.target.value)}),placeholder:i("modelProviders.placeholderMaxOutputExample"),className:"w-full px-3 py-1.5 text-xs bg-surface-primary border border-border-default rounded-lg text-fg-primary placeholder-fg-tertiary focus:border-brand-500 outline-none"})]}),n.jsxs("div",{children:[n.jsx("label",{className:"text-[10px] text-fg-tertiary uppercase block mb-1",children:i("modelProviders.inputCost")}),n.jsx("input",{type:"number",step:"0.01",value:Xn.costInput||"",onChange:st=>Ts({...Xn,costInput:Number(st.target.value)}),placeholder:i("modelProviders.placeholderCostInput"),className:"w-full px-3 py-1.5 text-xs bg-surface-primary border border-border-default rounded-lg text-fg-primary placeholder-fg-tertiary focus:border-brand-500 outline-none"})]}),n.jsxs("div",{children:[n.jsx("label",{className:"text-[10px] text-fg-tertiary uppercase block mb-1",children:i("modelProviders.outputCost")}),n.jsx("input",{type:"number",step:"0.01",value:Xn.costOutput||"",onChange:st=>Ts({...Xn,costOutput:Number(st.target.value)}),placeholder:i("modelProviders.placeholderCostOutput"),className:"w-full px-3 py-1.5 text-xs bg-surface-primary border border-border-default rounded-lg text-fg-primary placeholder-fg-tertiary focus:border-brand-500 outline-none"})]})]}),n.jsxs("div",{className:"flex gap-2",children:[n.jsx("button",{onClick:()=>{oe(le)},disabled:Os,className:"px-3 py-1.5 text-xs bg-brand-600 hover:bg-brand-500 disabled:opacity-40 text-white rounded-lg transition-colors",children:i(Os?"common:saving":"common:save")}),n.jsx("button",{onClick:()=>$a(null),className:"px-3 py-1.5 text-xs border border-border-default text-fg-secondary hover:bg-surface-elevated rounded-lg transition-colors",children:i("common:cancel")})]})]}):n.jsxs("div",{className:"flex gap-2",children:[n.jsx("button",{onClick:st=>{st.stopPropagation(),os(le)},disabled:yt===le,className:"px-3 py-1.5 text-xs border border-green-500/30 text-green-500 hover:bg-green-500/10 rounded-lg transition-colors disabled:opacity-40 flex items-center gap-1.5",children:yt===le?n.jsxs(n.Fragment,{children:[n.jsxs("svg",{className:"w-3 h-3 animate-spin",fill:"none",viewBox:"0 0 24 24",children:[n.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),n.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8v4a4 4 0 00-4 4H4z"})]}),i("modelProviders.testing")]}):i("modelProviders.test")}),n.jsx("button",{onClick:st=>{st.stopPropagation(),Sa(le,Ie)},className:"px-3 py-1.5 text-xs border border-border-default text-fg-secondary hover:bg-surface-elevated rounded-lg transition-colors",children:i("common:edit")}),n.jsx("button",{onClick:st=>{st.stopPropagation(),confirm(i("modelProviders.deleteConfirm",{name:Ie.displayName??le}))&&Qe(le)},disabled:Or===le,className:"px-3 py-1.5 text-xs border border-red-500/30 text-red-400 hover:bg-red-500/10 rounded-lg transition-colors disabled:opacity-40",children:i(Or===le?"common:deleting":"common:delete")})]}),Ur[le]&&n.jsx("div",{className:`text-xs px-3 py-2 rounded-lg ${Ur[le].ok?"bg-green-500/10 text-green-600 border border-green-500/30":"bg-red-500/10 text-red-500 border border-red-500/30"}`,children:Ur[le].ok?i("modelProviders.testSuccess",{ms:Ur[le].durationMs,reply:Ur[le].reply}):Ur[le].error})]}),Ie.cost&&n.jsxs("div",{className:"bg-surface-elevated/40 rounded-lg p-3",children:[n.jsx("div",{className:"text-[10px] text-fg-tertiary uppercase tracking-wider mb-2",children:i("modelProviders.pricingTitle")}),n.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-3",children:[n.jsx(ml,{label:i("modelProviders.input"),value:`$${Ie.cost.input}`}),n.jsx(ml,{label:i("modelProviders.output"),value:`$${Ie.cost.output}`}),Ie.cost.cacheRead!=null&&n.jsx(ml,{label:i("modelProviders.cacheRead"),value:`$${Ie.cost.cacheRead}`}),Ie.cost.cacheWrite!=null&&n.jsx(ml,{label:i("modelProviders.cacheWrite"),value:`$${Ie.cost.cacheWrite}`})]})]}),n.jsxs("div",{children:[n.jsxs("div",{className:"flex items-center justify-between mb-2",children:[n.jsx("div",{className:"text-[10px] text-fg-tertiary uppercase tracking-wider",children:i("modelProviders.availableModels")}),Ie.configured&&qs!==le&&n.jsx("button",{onClick:()=>{wa(le),Zr({id:"",name:"",contextWindow:128e3,maxOutputTokens:16384,costInput:1,costOutput:5,reasoning:!1,vision:!1})},className:"text-[10px] text-brand-500 hover:text-brand-400 transition-colors",children:i("modelProviders.addModel")})]}),qs===le&&n.jsx("div",{className:"bg-surface-elevated/40 rounded-lg p-3 mb-2 space-y-2",children:n.jsx(lY,{providerName:le,addModelForm:Us,setAddModelForm:Zr,addModelSaving:zs,onAdd:()=>{dt(le)},onCancel:()=>wa(null),t:i})}),Ie.models&&Ie.models.length>0&&n.jsx("div",{className:"space-y-1.5",children:Ie.models.map(st=>{const hn=st.id===Ie.model,Cn=hr===`${le}:${st.id}`,$s=!fn.has(st.id);return n.jsxs("div",{className:`flex items-center justify-between px-3 py-2 rounded-lg text-xs transition-colors ${hn?"bg-brand-500/15 border border-brand-500/30":Ie.configured?"bg-surface-elevated/30 hover:bg-surface-elevated/60 cursor-pointer":"bg-surface-elevated/30"}`,onClick:()=>{!hn&&Ie.configured&&!Cn&&Vr(le,st.id)},children:[n.jsxs("div",{className:"flex items-center gap-2",children:[hn&&n.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-brand-500 shrink-0"}),n.jsx("span",{className:hn?"text-brand-500 font-medium":"text-fg-secondary",children:st.name}),st.reasoning&&n.jsx("span",{className:"text-[9px] bg-amber-500/15 text-amber-600 px-1 py-0.5 rounded",children:i("modelProviders.reasoning")}),st.inputTypes?.includes("image")&&n.jsx("span",{className:"text-[9px] bg-blue-500/15 text-blue-600 px-1 py-0.5 rounded",children:i("modelProviders.vision")}),$s&&n.jsx("span",{className:"text-[9px] bg-purple-500/15 text-purple-400 px-1 py-0.5 rounded",children:i("modelProviders.custom")})]}),n.jsxs("div",{className:"flex items-center gap-3 text-fg-tertiary",children:[st.contextWindow>0&&n.jsx("span",{children:i("modelProviders.ctxTokens",{size:(st.contextWindow/1e3).toFixed(0)})}),(st.cost.input>0||st.cost.output>0)&&n.jsx("span",{children:i("modelProviders.costPair",{input:st.cost.input,output:st.cost.output})}),Ie.configured&&!hn&&n.jsx("span",{className:`text-[9px] px-1.5 py-0.5 rounded transition-colors ${Cn?"bg-brand-500/30 text-brand-400":"bg-surface-overlay text-fg-tertiary hover:bg-brand-500/20 hover:text-brand-500"}`,children:i(Cn?"modelProviders.switching":"modelProviders.use")}),hn&&n.jsx("span",{className:"text-[9px] bg-brand-500/15 text-brand-500 px-1.5 py-0.5 rounded",children:i("modelProviders.active")}),$s&&!hn&&n.jsx("button",{onClick:ro=>{ro.stopPropagation(),Rt(le,st.id)},className:"text-red-400 hover:text-red-300 transition-colors",title:i("modelProviders.deleteCustomModelTitle"),children:n.jsx("svg",{className:"w-3 h-3",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:n.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]})]},st.id)})}),Ie.configured&&W===le&&n.jsxs("div",{className:"flex items-center gap-2 mt-2 text-xs text-fg-tertiary",children:[n.jsx("div",{className:"w-3 h-3 border-2 border-brand-500 border-t-transparent rounded-full animate-spin"}),i("modelProviders.loadingCatalog")]}),Ie.configured&&M[le]&&M[le].length>0&&(()=>{const st=new Set(Ie.models?.map(Cn=>Cn.id)??[]),hn=M[le].filter(Cn=>!st.has(Cn.id));return hn.length===0?null:n.jsxs("details",{className:"mt-2 group",children:[n.jsx("summary",{className:"text-[10px] text-fg-tertiary cursor-pointer hover:text-fg-secondary select-none",children:i("modelProviders.moreCatalogModels",{count:hn.length})}),n.jsx("div",{className:"mt-1.5 space-y-1",children:hn.map(Cn=>{const $s=hr===`${le}:${Cn.id}`;return n.jsxs("div",{onClick:()=>{$s||Vr(le,Cn.id)},className:"flex items-center justify-between px-3 py-1.5 rounded-lg text-xs bg-surface-elevated/20 hover:bg-surface-elevated/50 cursor-pointer transition-colors",children:[n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx("span",{className:"text-fg-secondary",children:Cn.id}),Cn.capabilities.reasoning&&n.jsx("span",{className:"text-[9px] bg-amber-500/15 text-amber-600 px-1 py-0.5 rounded",children:i("modelProviders.reasoning")}),Cn.capabilities.vision&&n.jsx("span",{className:"text-[9px] bg-blue-500/15 text-blue-600 px-1 py-0.5 rounded",children:i("modelProviders.vision")})]}),n.jsxs("div",{className:"flex items-center gap-3 text-fg-tertiary",children:[Cn.maxInputTokens>0&&n.jsxs("span",{children:[Math.round(Cn.maxInputTokens/1e3),"K ctx"]}),(Cn.inputCostPer1MTokens>0||Cn.outputCostPer1MTokens>0)&&n.jsxs("span",{children:["$",Cn.inputCostPer1MTokens,"/",Cn.outputCostPer1MTokens]}),n.jsx("span",{className:`text-[9px] px-1.5 py-0.5 rounded transition-colors ${$s?"bg-brand-500/30 text-brand-400":"bg-surface-overlay text-fg-tertiary hover:bg-brand-500/20 hover:text-brand-500"}`,children:i($s?"modelProviders.switching":"modelProviders.use")})]})]},Cn.id)})})]})})()]}),!Ie.configured&&n.jsxs("div",{className:"space-y-3",children:[n.jsx("div",{className:"text-xs text-fg-secondary",children:i("modelProviders.quickSetupHint")}),n.jsxs("div",{children:[n.jsx("label",{className:"text-[10px] text-fg-tertiary uppercase block mb-1",children:i("modelProviders.apiKey")}),n.jsx("input",{type:"password",value:Y===le?_s:"",onChange:st=>Fs(st.target.value),placeholder:i("modelProviders.quickSetupPlaceholder"),className:"w-full px-3 py-2 text-sm bg-surface-elevated border border-border-default rounded-lg text-fg-primary placeholder-fg-tertiary focus:border-brand-500 outline-none",onBlur:()=>{_s.trim().length>=8&&Y===le&&Ri(le,_s.trim())},onKeyDown:st=>{st.key==="Enter"&&_s.trim().length>=8&&Ri(le,_s.trim())}}),ai&&Y===le&&n.jsxs("div",{className:"flex items-center gap-2 mt-1.5 text-xs text-fg-tertiary",children:[n.jsx("div",{className:"w-3 h-3 border-2 border-brand-500 border-t-transparent rounded-full animate-spin"}),i("modelProviders.validatingKey")]})]}),Y===le&&is.length>0&&n.jsxs("div",{children:[n.jsx("label",{className:"text-[10px] text-fg-tertiary uppercase block mb-2",children:i("modelProviders.selectModel")}),n.jsx(dh,{provider:le,models:is,selectedModel:Yn.model,onSelect:st=>{const hn=is.find(Cn=>Cn.id===st);Ns(Cn=>({...Cn,name:le,model:st,apiKey:_s.trim(),baseUrl:Bu.find($s=>$s.id===le)?.baseUrl??"",contextWindow:hn?.maxInputTokens??Cn.contextWindow,maxOutputTokens:hn?.maxOutputTokens??Cn.maxOutputTokens,costInput:hn?.inputCostPer1MTokens??Cn.costInput,costOutput:hn?.outputCostPer1MTokens??Cn.costOutput}))},compact:!0,maxVisible:8})]}),Y===le&&_s.trim()&&n.jsx("button",{onClick:()=>{Yn.model&&Yn.name===le?ja():Na(le)},disabled:ii||va,className:"px-4 py-2 text-sm bg-brand-600 hover:bg-brand-500 disabled:opacity-40 text-white rounded-lg transition-colors",children:i(ii||va?"modelProviders.quickSetupSaving":"modelProviders.quickSetupSubmit")}),Xs&&Y===le&&n.jsx(Ka,{type:Xs.type,text:Xs.text})]})]})]},le))}),ya?n.jsxs("div",{className:"mt-3 bg-surface-secondary border border-brand-500/30 rounded-xl p-4 space-y-3",children:[n.jsx("div",{className:"text-xs font-medium text-fg-primary",children:i("modelProviders.customProvider")}),n.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-3",children:[n.jsxs("div",{children:[n.jsx("label",{className:"text-[10px] text-fg-tertiary uppercase block mb-1",children:i("modelProviders.providerName")}),n.jsx("input",{type:"text",value:Yn.name==="__custom__"?"":Yn.name,onChange:le=>Ns(Ie=>({...Ie,name:le.target.value||"__custom__"})),placeholder:"my-provider",className:"w-full px-3 py-2 text-sm bg-surface-elevated border border-border-default rounded-lg text-fg-primary placeholder-fg-tertiary focus:border-brand-500 outline-none"})]}),n.jsxs("div",{children:[n.jsx("label",{className:"text-[10px] text-fg-tertiary uppercase block mb-1",children:i("modelProviders.baseUrl")}),n.jsx("input",{type:"text",value:Yn.baseUrl,onChange:le=>Ns({...Yn,baseUrl:le.target.value}),placeholder:"https://api.example.com/v1",className:"w-full px-3 py-2 text-sm bg-surface-elevated border border-border-default rounded-lg text-fg-primary placeholder-fg-tertiary focus:border-brand-500 outline-none"})]})]}),n.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-3",children:[n.jsxs("div",{children:[n.jsx("label",{className:"text-[10px] text-fg-tertiary uppercase block mb-1",children:i("modelProviders.apiKey")}),n.jsx("input",{type:"password",value:Yn.apiKey,onChange:le=>Ns({...Yn,apiKey:le.target.value}),placeholder:i("modelProviders.placeholderApiKeySk"),className:"w-full px-3 py-2 text-sm bg-surface-elevated border border-border-default rounded-lg text-fg-primary placeholder-fg-tertiary focus:border-brand-500 outline-none"})]}),n.jsxs("div",{children:[n.jsx("label",{className:"text-[10px] text-fg-tertiary uppercase block mb-1",children:i("modelProviders.defaultModel")}),n.jsx("input",{type:"text",value:Yn.model,onChange:le=>Ns({...Yn,model:le.target.value}),placeholder:"gpt-4o",className:"w-full px-3 py-2 text-sm bg-surface-elevated border border-border-default rounded-lg text-fg-primary placeholder-fg-tertiary focus:border-brand-500 outline-none"})]})]}),n.jsxs("div",{className:"flex gap-2",children:[n.jsx("button",{onClick:()=>{ja()},disabled:va||!Yn.name||Yn.name==="__custom__"||!Yn.model,className:"px-4 py-2 text-sm bg-brand-600 hover:bg-brand-500 disabled:opacity-40 text-white rounded-lg transition-colors",children:i(va?"modelProviders.adding":"modelProviders.addProviderSubmit")}),n.jsx("button",{onClick:()=>{Ls(!1),Ps(null),qr([]),Ns({name:"",apiKey:"",baseUrl:"",model:"",contextWindow:128e3,maxOutputTokens:16384,costInput:1,costOutput:5})},className:"px-4 py-2 text-sm border border-border-default text-fg-secondary hover:bg-surface-elevated rounded-lg transition-colors",children:i("common:cancel")})]}),yr&&n.jsx(Ka,{type:yr.type,text:yr.text})]}):n.jsxs("button",{onClick:()=>Ls(!0),className:"w-full mt-3 px-4 py-2.5 border border-dashed border-border-default hover:border-brand-500/50 hover:bg-brand-500/5 rounded-xl text-xs text-fg-tertiary hover:text-brand-500 transition-colors",children:["+ ",i("modelProviders.customProvider")]})]}),n.jsx("div",{className:"border-t border-border-default"}),n.jsx(pi,{title:i("autoDetect.title"),children:n.jsxs("div",{className:"bg-surface-elevated rounded-xl p-5 space-y-5",children:[n.jsx("div",{className:"text-sm text-fg-secondary",children:i("autoDetect.description")}),n.jsxs("div",{className:"space-y-3",children:[n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx("h4",{className:"text-xs font-semibold text-fg-secondary uppercase tracking-wider",children:i("envConfig.title")}),n.jsxs("button",{onClick:()=>{ra()},disabled:G,className:"px-3 py-1 border border-border-default hover:bg-surface-elevated disabled:opacity-40 text-fg-tertiary text-xs rounded-md transition-colors flex items-center gap-1.5",children:[n.jsx("svg",{className:`w-3.5 h-3.5 ${G?"animate-spin":""}`,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:n.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"})}),i(G?"common:detecting":"envConfig.refreshEnv")]})]}),ee&&ee.detected.length>0&&n.jsxs("div",{className:"space-y-2",children:[ee.detected.map(le=>n.jsxs("label",{className:"flex items-center justify-between bg-surface-elevated/30 rounded-lg px-4 py-3 cursor-pointer hover:bg-surface-elevated/50 transition-colors",children:[n.jsxs("div",{className:"flex items-center gap-3",children:[n.jsx("input",{type:"checkbox",checked:Be[le.provider]??!1,onChange:Ie=>Ne({...Be,[le.provider]:Ie.target.checked}),className:"w-4 h-4 rounded bg-surface-overlay border-gray-600 text-brand-500 focus:ring-brand-500"}),n.jsxs("div",{children:[n.jsx("div",{className:"text-sm text-fg-primary font-medium",children:le.displayName}),n.jsxs("div",{className:"text-xs text-fg-tertiary mt-0.5",children:[i("envConfig.keyLabel")," ",n.jsx("code",{className:"text-fg-secondary",children:le.apiKeyPreview})," / ",i("envConfig.modelLabel")," ",n.jsx("code",{className:"text-fg-secondary",children:le.model}),le.baseUrl&&n.jsxs(n.Fragment,{children:[" / ",i("envConfig.urlLabel")," ",n.jsx("code",{className:"text-fg-secondary",children:le.baseUrl})]})]})]})]}),n.jsx("div",{className:"text-xs text-fg-tertiary",children:Object.keys(le.envVars).map(Ie=>n.jsx("div",{children:n.jsx("code",{children:Ie})},Ie))})]},le.provider)),ee.timeoutMs&&n.jsx("div",{className:"text-xs text-fg-tertiary",children:i("envConfig.llmTimeout",{ms:ee.timeoutMs})}),n.jsx("button",{onClick:()=>{sa()},disabled:he||Object.values(Be).filter(Boolean).length===0,className:"px-4 py-2 bg-brand-600 hover:bg-brand-500 disabled:opacity-40 text-white text-sm rounded-lg transition-colors",children:he?i("common:applying"):i("envConfig.applyToConfig",{count:Object.values(Be).filter(Boolean).length})})]}),Se&&n.jsx(Ka,{type:Se.type,text:Se.text})]}),n.jsx("div",{className:"border-t border-border-default"}),n.jsxs("div",{className:"space-y-3",children:[n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx("h4",{className:"text-xs font-semibold text-fg-secondary uppercase tracking-wider",children:i("ollama.title")}),n.jsxs("button",{onClick:()=>{ds()},disabled:Ze,className:"px-3 py-1 border border-border-default hover:bg-surface-elevated disabled:opacity-40 text-fg-tertiary text-xs rounded-md transition-colors flex items-center gap-1.5",children:[n.jsx("svg",{className:`w-3.5 h-3.5 ${Ze?"animate-spin":""}`,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:n.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"})}),i(Ze?"common:detecting":"ollama.detect")]})]}),Ee?.found&&Ee.models&&Ee.models.length>0&&n.jsxs("div",{className:"space-y-2",children:[n.jsx("div",{className:"text-xs text-green-600",children:i("ollama.foundModels",{count:Ee.models.length,url:Ee.baseUrl})}),n.jsx("div",{className:"space-y-1",children:Ee.models.map(le=>n.jsx("label",{className:`flex items-center justify-between rounded-lg px-4 py-3 cursor-pointer transition-colors ${it===le.name?"bg-brand-500/15 border border-brand-500/40":"bg-surface-elevated/30 hover:bg-surface-elevated/50"}`,children:n.jsxs("div",{className:"flex items-center gap-3",children:[n.jsx("input",{type:"radio",name:"ollama-model",value:le.name,checked:it===le.name,onChange:()=>Lt(le.name),className:"w-4 h-4 text-brand-500 focus:ring-brand-500"}),n.jsxs("div",{children:[n.jsx("div",{className:"text-sm text-fg-primary font-medium",children:le.name}),n.jsxs("div",{className:"text-xs text-fg-tertiary mt-0.5",children:[le.parameterSize&&n.jsx("span",{children:le.parameterSize}),le.family&&n.jsx("span",{className:"ml-2",children:le.family}),le.quantization&&n.jsx("span",{className:"ml-2",children:le.quantization}),le.size&&n.jsx("span",{className:"ml-2",children:nd(le.size)})]})]})]})},le.name))}),n.jsx("button",{onClick:()=>{Ys()},disabled:ht||!it,className:"px-4 py-2 bg-brand-600 hover:bg-brand-500 disabled:opacity-40 text-white text-sm rounded-lg transition-colors",children:ht?i("common:applying"):i("ollama.useModel",{model:it})})]}),Ee&&!Ee.found&&n.jsx("div",{className:"text-xs text-fg-tertiary",children:Ee.error||i("ollama.notRunning")}),me&&n.jsx(Ka,{type:me.type,text:me.text})]}),n.jsx("div",{className:"border-t border-border-default"}),n.jsxs("div",{className:"space-y-3",children:[n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx("h4",{className:"text-xs font-semibold text-fg-secondary uppercase tracking-wider",children:i("openClaw.title")}),n.jsx("button",{onClick:()=>{vi()},disabled:Z,className:"px-3 py-1 border border-border-default hover:bg-surface-elevated disabled:opacity-40 text-fg-tertiary text-xs rounded-md transition-colors flex items-center gap-1.5",children:i(Z?"common:detecting":"openClaw.detectShort")})]}),H&&H.found&&n.jsxs("div",{className:"space-y-2",children:[n.jsxs("div",{className:"text-xs text-green-600",children:[i("openClaw.foundAt")," ",n.jsx("code",{className:"text-fg-secondary",children:H.summary.configPath})]}),H.summary.models&&n.jsxs("div",{className:"bg-surface-elevated/30 rounded-lg p-3",children:[n.jsx("div",{className:"text-xs text-fg-tertiary mb-2",children:i("openClaw.modelProvidersFound",{count:H.summary.models.providerCount})}),n.jsx("div",{className:"space-y-1",children:H.summary.models.providers.map(le=>n.jsxs("div",{className:"flex items-center justify-between text-xs",children:[n.jsx("span",{className:"text-fg-secondary",children:le.name}),n.jsxs("span",{className:"text-fg-tertiary",children:[i("openClaw.modelsCountSuffix",{count:le.modelCount}),le.baseUrl?i("openClaw.withBaseUrl",{url:le.baseUrl}):""]})]},le.name))})]}),H.summary.channels&&H.summary.channels.length>0&&n.jsx("div",{className:"bg-surface-elevated/30 rounded-lg p-3",children:n.jsxs("div",{className:"text-xs text-fg-tertiary mb-1",children:[i("openClaw.channelsPrefix")," ",H.summary.channels.join(", ")]})}),n.jsx("button",{onClick:()=>{si()},disabled:Z,className:"px-4 py-2 bg-brand-600 hover:bg-brand-500 disabled:opacity-40 text-white text-sm rounded-lg transition-colors",children:i(Z?"common:importing":"openClaw.importConfigs")})]}),J&&n.jsx(Ka,{type:J.type,text:J.text})]})]})})]}),w==="execution"&&n.jsxs(n.Fragment,{children:[n.jsx(pi,{title:i("agentExecution.title"),children:n.jsxs("div",{className:"bg-surface-elevated rounded-xl p-5 space-y-4",children:[n.jsxs("div",{className:"flex items-center justify-between",children:[n.jsxs("div",{children:[n.jsx("div",{className:"text-sm font-medium text-fg-primary",children:i("agentExecution.maxToolIterations")}),n.jsx("div",{className:"text-xs text-fg-tertiary mt-0.5",children:i("agentExecution.maxToolIterationsDesc")})]}),n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx("input",{type:"number",min:0,value:ln,onChange:le=>{en(Number(le.target.value)),cn(null)},className:"w-24 px-3 py-1.5 text-sm border border-border-default rounded-lg bg-surface-primary text-fg-primary text-right"}),n.jsx("button",{disabled:vn,onClick:async()=>{In(!0),cn(null);try{const le=await ie.settings.updateAgent({maxToolIterations:ln});en(le.maxToolIterations),cn({type:"ok",text:i("agentExecution.saved")})}catch{cn({type:"err",text:i("agentExecution.failedToSave")})}In(!1)},className:"px-3 py-1.5 text-xs bg-brand-500 text-white rounded-lg hover:bg-brand-600 transition-colors disabled:opacity-40",children:i(vn?"common:saving":"common:save")})]})]}),Zt&&n.jsx(Ka,{type:Zt.type,text:Zt.text})]})}),n.jsx(pi,{title:i("cognitive.title"),children:n.jsxs("div",{className:"bg-surface-elevated rounded-xl p-5 space-y-4",children:[n.jsx("div",{className:"text-xs text-fg-tertiary",children:i("cognitive.description")}),n.jsxs("div",{className:"flex items-center justify-between",children:[n.jsxs("div",{children:[n.jsx("div",{className:"text-sm font-medium text-fg-primary",children:i("cognitive.enabled")}),n.jsx("div",{className:"text-xs text-fg-tertiary mt-0.5",children:i("cognitive.enabledDesc")})]}),n.jsx("button",{onClick:()=>{Ln(!Gn),Wt(null)},className:`relative w-10 h-5 rounded-full transition-colors ${Gn?"bg-brand-500":"bg-fg-quaternary"}`,children:n.jsx("span",{className:`absolute top-0.5 left-0.5 w-4 h-4 bg-white rounded-full shadow transition-transform ${Gn?"translate-x-5":""}`})})]}),n.jsxs("div",{className:"flex items-center justify-between",children:[n.jsxs("div",{children:[n.jsx("div",{className:"text-sm font-medium text-fg-primary",children:i("cognitive.maxDepth")}),n.jsx("div",{className:"text-xs text-fg-tertiary mt-0.5",children:i("cognitive.maxDepthDesc")})]}),n.jsxs("select",{value:Lr,onChange:le=>{Qr(Number(le.target.value)),Wt(null)},className:"px-3 py-1.5 text-sm border border-border-default rounded-lg bg-surface-primary text-fg-primary",children:[n.jsxs("option",{value:1,children:["D1 — ",i("cognitive.depthD1")]}),n.jsxs("option",{value:2,children:["D2 — ",i("cognitive.depthD2")]}),n.jsxs("option",{value:3,children:["D3 — ",i("cognitive.depthD3")]})]})]}),n.jsx("div",{className:"flex items-center justify-end gap-2",children:n.jsx("button",{disabled:mr,onClick:async()=>{Ge(!0),Wt(null);try{const le=await ie.settings.updateAgent({cognitive:{enabled:Gn,maxDepth:Lr}});Ln(le.cognitive.enabled),Qr(le.cognitive.maxDepth??1),Wt({type:"ok",text:i("cognitive.saved")})}catch{Wt({type:"err",text:i("cognitive.failedToSave")})}Ge(!1)},className:"px-3 py-1.5 text-xs bg-brand-500 text-white rounded-lg hover:bg-brand-600 transition-colors disabled:opacity-40",children:i(mr?"common:saving":"common:save")})}),Ht&&n.jsx(Ka,{type:Ht.type,text:Ht.text})]})})]}),w==="browser"&&n.jsxs(n.Fragment,{children:[n.jsxs(pi,{title:i("browserAutomation.title"),children:[n.jsxs("div",{className:`rounded-xl p-4 mb-4 flex items-start gap-3 ${Vn?"bg-green-500/10 border border-green-500/20":Mn>0?"bg-blue-500/10 border border-blue-500/20":Sn?"bg-amber-500/10 border border-amber-500/20":"bg-surface-elevated border border-border-default"}`,children:[n.jsx("div",{className:`mt-0.5 w-2.5 h-2.5 rounded-full shrink-0 ${Vn?"bg-green-400":Mn>0?"bg-blue-400":Sn?"bg-amber-400":"bg-gray-400"}`}),n.jsxs("div",{className:"flex-1 min-w-0",children:[n.jsx("div",{className:`text-sm font-semibold ${Vn?"text-green-400":Mn>0?"text-blue-400":Sn?"text-amber-400":"text-fg-secondary"}`,children:Vn?i("browserAutomation.modeExtension"):Mn>0?i("browserAutomation.modeDebuggingPort",{port:Mn}):i(Sn?"browserAutomation.modeAutoClick":"browserAutomation.modeManual")}),n.jsx("div",{className:"text-xs text-fg-tertiary mt-0.5",children:Vn?i("browserAutomation.modeExtensionDesc"):Mn>0?i("browserAutomation.modeDebuggingPortDesc"):i(Sn?"browserAutomation.modeAutoClickDesc":"browserAutomation.modeManualDesc")})]})]}),n.jsxs("div",{className:"bg-surface-elevated rounded-xl p-5 space-y-4 mb-4",children:[n.jsx("div",{className:"text-xs font-medium text-fg-secondary uppercase tracking-wider",children:i("browserAutomation.generalSettings")}),n.jsxs("div",{className:"flex items-center justify-between",children:[n.jsxs("div",{children:[n.jsx("div",{className:"text-sm font-medium text-fg-primary",children:i("browserAutomation.bringToFront")}),n.jsx("div",{className:"text-xs text-fg-tertiary mt-0.5",children:i("browserAutomation.bringToFrontDesc")})]}),n.jsx("button",{onClick:async()=>{const le=!tn;zn(le),tt(!0),$t(null);try{const Ie=await ie.settings.updateBrowser({bringToFront:le});zn(Ie.bringToFront),$t({type:"ok",text:i(le?"browserAutomation.tabsForeground":"browserAutomation.tabsBackground")})}catch{$t({type:"err",text:i("agentExecution.failedToSave")}),zn(!le)}tt(!1)},disabled:ve,className:`relative inline-flex h-5 w-9 items-center rounded-full transition-colors ${tn?"bg-green-500":"bg-gray-600"} ${ve?"opacity-50":""}`,children:n.jsx("span",{className:`inline-block h-3.5 w-3.5 rounded-full bg-white transition-transform ${tn?"translate-x-4":"translate-x-1"}`})})]}),n.jsxs("div",{className:"flex items-center justify-between border-t border-border-default pt-4",children:[n.jsxs("div",{children:[n.jsx("div",{className:"text-sm font-medium text-fg-primary",children:i("browserAutomation.autoCloseTabs")}),n.jsx("div",{className:"text-xs text-fg-tertiary mt-0.5",children:i("browserAutomation.autoCloseTabsDesc")})]}),n.jsx("button",{onClick:async()=>{const le=!Dn;$n(le),tt(!0),$t(null);try{const Ie=await ie.settings.updateBrowser({autoCloseTabs:le});$n(Ie.autoCloseTabs),$t({type:"ok",text:i("agentExecution.saved")})}catch{$t({type:"err",text:i("agentExecution.failedToSave")}),$n(!le)}tt(!1)},disabled:ve,className:`relative inline-flex h-5 w-9 items-center rounded-full transition-colors ${Dn?"bg-green-500":"bg-gray-600"} ${ve?"opacity-50":""}`,children:n.jsx("span",{className:`inline-block h-3.5 w-3.5 rounded-full bg-white transition-transform ${Dn?"translate-x-4":"translate-x-1"}`})})]})]}),n.jsxs("div",{className:`rounded-xl p-5 mb-4 transition-colors ${Vn?"bg-green-500/5 border border-green-500/20":"bg-surface-elevated"}`,children:[n.jsxs("div",{className:"flex items-center justify-between mb-2",children:[n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx("div",{className:"text-sm font-medium text-fg-primary",children:i("browserAutomation.extensionStatus")}),n.jsxs("span",{className:"text-xs text-fg-tertiary",children:["(",i("browserAutomation.modeRecommended"),")"]})]}),n.jsxs("span",{className:`inline-flex items-center gap-1.5 px-2.5 py-1 rounded-full text-xs font-medium ${Vn?"bg-green-500/20 text-green-400":"bg-gray-600/20 text-gray-400"}`,children:[n.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${Vn?"bg-green-400":"bg-gray-400"}`}),i(Vn?"browserAutomation.extensionConnected":"browserAutomation.extensionDisconnected")]})]}),n.jsx("div",{className:"text-xs text-fg-tertiary",children:i("browserAutomation.extensionStatusDesc")}),Vn?n.jsxs("div",{className:"mt-3 flex items-center gap-1.5 text-xs text-green-400",children:[n.jsx("svg",{className:"w-3.5 h-3.5 shrink-0",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:n.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 13l4 4L19 7"})}),i("browserAutomation.extensionActiveNote")]}):n.jsxs("div",{className:"mt-4 space-y-3",children:[n.jsx("div",{className:"text-xs font-medium text-fg-secondary uppercase tracking-wider",children:i("browserAutomation.extensionSetupTitle")}),n.jsxs("div",{className:"flex items-start gap-3 p-3 rounded-lg bg-surface-primary/50",children:[n.jsx("span",{className:"flex items-center justify-center w-5 h-5 rounded-full bg-brand-500 text-white text-[10px] font-bold shrink-0 mt-0.5",children:"1"}),n.jsxs("div",{className:"flex-1 min-w-0",children:[n.jsx("div",{className:"text-sm font-medium text-fg-primary",children:i("browserAutomation.extensionStep1")}),n.jsx("div",{className:"text-xs text-fg-tertiary mt-0.5",children:i("browserAutomation.extensionStep1Desc")}),n.jsxs("button",{disabled:ve,onClick:async()=>{tt(!0),$t(null);try{await ie.settings.downloadExtensionZip()}catch{$t({type:"err",text:i("browserAutomation.extensionDownloadError")})}tt(!1)},className:"mt-2 inline-flex items-center gap-1.5 px-3 py-1.5 text-xs bg-brand-500 text-white rounded-lg hover:bg-brand-600 transition-colors disabled:opacity-40",children:[n.jsx("svg",{className:"w-3.5 h-3.5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:n.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 16v1a3 3 0 003 3h10a3 3 0 003-3v-1m-4-4l-4 4m0 0l-4-4m4 4V4"})}),i(ve?"browserAutomation.extensionStep1Downloading":"browserAutomation.extensionStep1Btn")]})]})]}),n.jsxs("div",{className:"flex items-start gap-3 p-3 rounded-lg bg-surface-primary/50",children:[n.jsx("span",{className:"flex items-center justify-center w-5 h-5 rounded-full bg-brand-500 text-white text-[10px] font-bold shrink-0 mt-0.5",children:"2"}),n.jsxs("div",{className:"flex-1 min-w-0",children:[n.jsx("div",{className:"text-sm font-medium text-fg-primary",children:i("browserAutomation.extensionStep2")}),n.jsx("div",{className:"text-xs text-fg-tertiary mt-0.5",children:i("browserAutomation.extensionStep2Desc")}),navigator.platform.toUpperCase().includes("WIN")?n.jsxs("div",{className:"mt-2 text-xs text-fg-secondary",children:[i("browserAutomation.extensionStep2Desc"),":",n.jsx("code",{className:"ml-1.5 px-1.5 py-0.5 bg-surface-elevated rounded text-fg-primary font-mono text-[11px] select-all",children:"chrome://extensions"})]}):n.jsxs("button",{disabled:ve,onClick:async()=>{tt(!0),$t(null);try{await ie.settings.openExtensionsPage()}catch{$t({type:"err",text:i("browserAutomation.extensionOpenError")})}tt(!1)},className:"mt-2 inline-flex items-center gap-1.5 px-3 py-1.5 text-xs bg-surface-primary border border-border-default text-fg-primary rounded-lg hover:bg-surface-elevated transition-colors disabled:opacity-40",children:[n.jsx("svg",{className:"w-3.5 h-3.5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:n.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M10 6H6a2 2 0 00-2 2v10a2 2 0 002 2h10a2 2 0 002-2v-4M14 4h6m0 0v6m0-6L10 14"})}),i("browserAutomation.extensionStep2Btn")]})]})]}),n.jsxs("div",{className:"flex items-start gap-3 p-3 rounded-lg bg-surface-primary/50",children:[n.jsx("span",{className:"flex items-center justify-center w-5 h-5 rounded-full bg-brand-500 text-white text-[10px] font-bold shrink-0 mt-0.5",children:"3"}),n.jsxs("div",{className:"flex-1 min-w-0",children:[n.jsx("div",{className:"text-sm font-medium text-fg-primary",children:i("browserAutomation.extensionStep3")}),n.jsx("div",{className:"text-xs text-fg-tertiary mt-0.5",children:i("browserAutomation.extensionStep3Desc")})]})]})]})]}),!Vn&&n.jsxs("div",{className:"bg-surface-elevated rounded-xl p-5 space-y-4",children:[n.jsx("div",{className:"text-xs font-medium text-fg-secondary uppercase tracking-wider",children:i("browserAutomation.fallbackModes")}),n.jsx("div",{children:n.jsxs("div",{className:"flex items-center justify-between",children:[n.jsxs("div",{className:"flex-1 mr-4",children:[n.jsx("div",{className:"text-sm font-medium text-fg-primary",children:i("browserAutomation.autoClickAllowDialog")}),n.jsx("div",{className:"text-xs text-fg-tertiary mt-0.5",children:i("browserAutomation.autoClickAllowDialogDesc")}),n.jsxs("div",{className:"text-xs text-fg-tertiary mt-2 space-y-0.5",children:[n.jsx("div",{children:i("browserAutomation.autoClickAllowDialogMacNote")}),n.jsx("div",{children:i("browserAutomation.autoClickAllowDialogWinNote")}),n.jsx("div",{children:i("browserAutomation.autoClickAllowDialogLinuxNote")})]})]}),n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx("button",{disabled:ve,onClick:async()=>{tt(!0),$t(null);try{const le=await ie.settings.testAutoClick(),Ie={success:{type:"ok",text:i("browserAutomation.autoClickTestSuccess",{title:le.pageTitle||"example.com"})},no_permission:{type:"err",text:i("browserAutomation.autoClickTestNoPermission")},chrome_not_running:{type:"err",text:i("browserAutomation.autoClickTestChromeNotRunning")},unsupported:{type:"err",text:i("browserAutomation.autoClickTestUnsupported")},error:{type:"err",text:i("browserAutomation.autoClickTestError",{error:le.error||"unknown"})}};$t(Ie[le.clickResult]??{type:"err",text:le.clickResult})}catch{$t({type:"err",text:i("browserAutomation.autoClickTestError",{error:"request failed"})})}tt(!1)},className:"px-3 py-1.5 text-xs bg-surface-primary border border-border-default text-fg-primary rounded-lg hover:bg-surface-elevated transition-colors disabled:opacity-40",children:i(ve?"browserAutomation.autoClickTesting":"browserAutomation.autoClickTest")}),n.jsx("button",{onClick:async()=>{const le=!Sn;Bn(le),tt(!0),$t(null);try{const Ie=await ie.settings.updateBrowser({autoClickAllowDialog:le});Bn(Ie.autoClickAllowDialog),$t({type:"ok",text:i("agentExecution.saved")})}catch{$t({type:"err",text:i("agentExecution.failedToSave")}),Bn(!le)}tt(!1)},disabled:ve,className:`relative inline-flex h-5 w-9 items-center rounded-full transition-colors ${Sn?"bg-green-500":"bg-gray-600"} ${ve?"opacity-50":""}`,children:n.jsx("span",{className:`inline-block h-3.5 w-3.5 rounded-full bg-white transition-transform ${Sn?"translate-x-4":"translate-x-1"}`})})]})]})}),n.jsx("div",{className:"border-t border-border-default pt-4",children:n.jsxs("div",{className:"flex items-center justify-between",children:[n.jsxs("div",{children:[n.jsx("div",{className:"text-sm font-medium text-fg-primary",children:i("browserAutomation.remoteDebuggingPort")}),n.jsxs("div",{className:"text-xs text-fg-tertiary mt-0.5",children:[i("browserAutomation.remoteDebuggingPortDescLead")," ",n.jsx("code",{className:"text-fg-secondary bg-surface-primary px-1 rounded",children:"--remote-debugging-port=9222"})," ",i("browserAutomation.remoteDebuggingPortDescTail")]})]}),n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx("input",{type:"number",min:0,max:65535,value:Mn,onChange:le=>{wn(Number(le.target.value)),$t(null)},className:"w-24 px-3 py-1.5 text-sm border border-border-default rounded-lg bg-surface-primary text-fg-primary text-right",placeholder:"0"}),n.jsx("button",{disabled:ve,onClick:async()=>{tt(!0),$t(null);try{const le=await ie.settings.updateBrowser({remoteDebuggingPort:Mn});wn(le.remoteDebuggingPort),$t({type:"ok",text:le.remoteDebuggingPort>0?i("browserAutomation.usingPort",{port:le.remoteDebuggingPort}):i("browserAutomation.usingAutoConnect")})}catch{$t({type:"err",text:i("agentExecution.failedToSave")})}tt(!1)},className:"px-3 py-1.5 text-xs bg-brand-500 text-white rounded-lg hover:bg-brand-600 transition-colors disabled:opacity-40",children:i(ve?"common:saving":"common:save")})]})]})})]}),Tt&&n.jsx("div",{className:"mt-4",children:n.jsx(Ka,{type:Tt.type,text:Tt.text})})]}),!1]}),w==="search"&&n.jsx(n.Fragment,{children:n.jsx(pi,{title:i("searchApi.title"),children:n.jsxs("div",{className:"bg-surface-elevated rounded-xl p-5 space-y-5",children:[n.jsx("div",{className:"text-xs text-fg-tertiary",children:i("searchApi.description")}),[{id:"serper",label:i("searchApi.serper"),hint:i("searchApi.serperHint"),field:"serperApiKey"},{id:"tavily",label:i("searchApi.tavily"),hint:i("searchApi.tavilyHint"),field:"tavilyApiKey"},{id:"bing",label:i("searchApi.bing"),hint:i("searchApi.bingHint"),field:"bingApiKey"},{id:"google",label:i("searchApi.google"),hint:i("searchApi.googleHint"),field:"googleSearchApiKey",extraField:"googleSearchCx",extraPlaceholder:i("searchApi.googleCxPlaceholder")},{id:"serpapi",label:i("searchApi.serpapi"),hint:i("searchApi.serpapiHint"),field:"serpApiKey"},{id:"brave",label:i("searchApi.brave"),hint:i("searchApi.braveHint"),field:"braveApiKey"},{id:"exa",label:i("searchApi.exa"),hint:i("searchApi.exaHint"),field:"exaApiKey"},{id:"bocha",label:i("searchApi.bocha"),hint:i("searchApi.bochaHint"),field:"bochaApiKey"}].map((le,Ie)=>n.jsxs("div",{className:Ie>0?"border-t border-border-default pt-4":"",children:[n.jsxs("div",{className:"flex items-center justify-between mb-2",children:[n.jsxs("div",{children:[n.jsx("div",{className:"text-sm font-medium text-fg-primary",children:le.label}),n.jsx("div",{className:"text-xs text-fg-tertiary mt-0.5",children:le.hint})]}),n.jsxs("div",{className:"flex items-center gap-2",children:[sn?.[le.id]?.configured&&n.jsxs(n.Fragment,{children:[n.jsx("span",{className:"w-2 h-2 rounded-full bg-green-400"}),n.jsx("span",{className:"text-xs text-green-600",children:i("searchApi.configured")}),n.jsx("code",{className:"text-[10px] text-fg-tertiary",children:sn[le.id].preview})]}),sn&&!sn[le.id]?.configured&&n.jsxs(n.Fragment,{children:[n.jsx("span",{className:"w-2 h-2 rounded-full bg-gray-500"}),n.jsx("span",{className:"text-xs text-fg-tertiary",children:i("searchApi.notConfigured")})]})]})]}),n.jsx("input",{type:"password",value:Xt[le.field],onChange:st=>ye({...Xt,[le.field]:st.target.value}),placeholder:sn?.[le.id]?.configured?i("modelProviders.apiKeyPlaceholder"):i("searchApi.apiKeyPlaceholder"),className:"w-full px-3 py-1.5 text-xs bg-surface-primary border border-border-default rounded-lg text-fg-primary placeholder-fg-tertiary focus:border-brand-500 outline-none"}),le.extraField&&n.jsx("input",{type:"text",value:Xt[le.extraField],onChange:st=>ye({...Xt,[le.extraField]:st.target.value}),placeholder:le.extraPlaceholder??"",className:"w-full mt-2 px-3 py-1.5 text-xs bg-surface-primary border border-border-default rounded-lg text-fg-primary placeholder-fg-tertiary focus:border-brand-500 outline-none"})]},le.id)),n.jsx("div",{className:"text-xs text-fg-tertiary italic",children:i("searchApi.freeBackend")}),n.jsxs("div",{className:"flex items-center justify-between pt-2 border-t border-border-default",children:[Bt&&n.jsx(Ka,{type:Bt.type,text:Bt.text}),!Bt&&n.jsx("div",{}),n.jsx("button",{disabled:lt||!Xt.serperApiKey&&!Xt.tavilyApiKey&&!Xt.bingApiKey&&!Xt.googleSearchApiKey&&!Xt.googleSearchCx&&!Xt.serpApiKey&&!Xt.braveApiKey&&!Xt.exaApiKey&&!Xt.bochaApiKey,onClick:()=>{fs()},className:"px-4 py-1.5 text-xs bg-brand-500 text-white rounded-lg hover:bg-brand-600 transition-colors disabled:opacity-40",children:i(lt?"common:saving":"common:save")})]})]})})}),w==="storage"&&n.jsx(n.Fragment,{children:n.jsx(pi,{title:i("dataStorage.title"),children:n.jsxs("div",{className:"bg-surface-elevated rounded-xl p-5 space-y-5",children:[tr&&!Dt&&n.jsx("div",{className:"text-sm text-fg-tertiary",children:i("dataStorage.scanning")}),Dt&&n.jsxs(n.Fragment,{children:[n.jsxs("div",{className:"flex items-center justify-between",children:[n.jsxs("div",{children:[n.jsx("div",{className:"text-lg font-semibold text-fg-primary",children:nd(Dt.totalSize,i)}),n.jsx("div",{className:"text-xs text-fg-tertiary font-mono mt-0.5",children:Dt.dataDir})]}),n.jsxs("div",{className:"flex gap-2",children:[n.jsx("button",{onClick:()=>ba(),disabled:tr,className:"px-3 py-1.5 text-xs border border-border-default hover:bg-surface-elevated rounded-lg text-fg-secondary transition-colors disabled:opacity-40",children:i(tr?"dataStorage.scanning":"common:refresh")}),n.jsx("button",{onClick:()=>{ie.system.openPath(Dt.dataDir)},className:"px-3 py-1.5 text-xs border border-border-default hover:bg-surface-elevated rounded-lg text-fg-secondary transition-colors",children:i("dataStorage.openInFinder")})]})]}),n.jsxs("div",{className:"border-t border-border-default pt-4",children:[n.jsx("h4",{className:"text-xs font-semibold text-fg-secondary mb-3",children:i("dataStorage.storageBreakdown")}),n.jsx("div",{className:"space-y-1.5",children:Dt.breakdown.filter(le=>le.size>0).map(le=>n.jsxs("div",{className:"flex items-center justify-between py-1.5 px-3 rounded-lg bg-surface-elevated/40",children:[n.jsxs("div",{className:"min-w-0",children:[n.jsx("span",{className:"text-sm text-fg-primary",children:le.name}),n.jsx("span",{className:"text-xs text-fg-tertiary ml-2",children:le.description})]}),n.jsx("span",{className:"text-sm font-medium text-fg-secondary tabular-nums shrink-0 ml-3",children:nd(le.size,i)})]},le.name))})]}),Dt.agents.length>0&&n.jsxs("div",{className:"border-t border-border-default pt-4",children:[n.jsx("h4",{className:"text-xs font-semibold text-fg-secondary mb-3",children:i("dataStorage.agentStorage",{count:Dt.agents.length})}),n.jsx("div",{className:"space-y-1",children:Dt.agents.map(le=>{const Ie=nr.has(le.id);return n.jsxs("div",{className:"rounded-lg bg-surface-elevated/40 overflow-hidden",children:[n.jsxs("div",{className:"flex items-center justify-between py-2 px-3 cursor-pointer hover:bg-surface-elevated/70",onClick:()=>On(st=>{const hn=new Set(st);return hn.has(le.id)?hn.delete(le.id):hn.add(le.id),hn}),children:[n.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[n.jsx("span",{className:"text-[10px] text-fg-tertiary",children:Ie?"▼":"▶"}),n.jsx("button",{onClick:st=>{st.stopPropagation(),bt.navigate(De.TEAM,{agentId:le.id})},className:"text-sm text-brand-500 hover:text-brand-400 truncate",children:le.name}),n.jsx("span",{className:"text-[10px] text-fg-tertiary font-mono truncate",children:le.id})]}),n.jsx("span",{className:"text-xs font-medium text-fg-secondary tabular-nums shrink-0 ml-3",children:nd(le.size,i)})]}),Ie&&n.jsxs("div",{className:"px-3 pb-2 pt-0.5 space-y-0.5",children:[le.subItems.filter(st=>st.size>0).map(st=>n.jsxs("div",{className:"flex items-center justify-between text-xs py-0.5 pl-5",children:[n.jsx("span",{className:"text-fg-tertiary",children:st.name}),n.jsx("span",{className:"text-fg-secondary tabular-nums",children:nd(st.size,i)})]},st.name)),n.jsx("div",{className:"pl-5 pt-1",children:n.jsx("button",{onClick:()=>{ie.system.openPath(Dt.dataDir+"/agents/"+le.id)},className:"text-[10px] text-fg-tertiary hover:text-fg-secondary underline",children:i("dataStorage.openFolder")})})]})]},le.id)})})]}),on&&(on.orphanAgents.length>0||on.orphanTeams.length>0)&&n.jsx(cY,{orphanInfo:on,dataDir:Dt.dataDir,onPurged:ba,formatBytes:le=>nd(le,i)})]})]})})}),(w==="account"||w==="users"||w==="organization"||w==="license")&&n.jsx(hY,{authUser:r}),w==="remote"&&n.jsx(uY,{})]}),n.jsx("div",{className:"h-8"})]})]})]})}const tj=["owner","admin","member","guest"],iY={owner:"bg-amber-500/10 text-amber-600 border-amber-500/30",admin:"bg-brand-500/10 text-brand-500 border-brand-500/30",member:"bg-green-500/10 text-green-600 border-green-500/30",guest:"bg-gray-500/10 text-gray-500 border-gray-500/30"};function oY({authUser:e}){const{t}=pt(["settings","common"]),[r,s]=g.useState([]),[a,i]=g.useState(null),[l,d]=g.useState(""),[u,m]=g.useState(""),[h,p]=g.useState(""),[y,x]=g.useState(null),[v,j]=g.useState(""),[C,w]=g.useState(null),[N,S]=g.useState(null),[T,E]=g.useState(null),[R,I]=g.useState(!1),[z,B]=g.useState(""),[D,V]=g.useState(""),[Y,F]=g.useState("member"),[L,O]=g.useState(""),M=g.useCallback(()=>{ie.users.list(e?.orgId).then(Z=>s(Z.users)).catch(()=>{})},[e?.orgId]);g.useEffect(()=>{M()},[M]);const $=Z=>{i(Z.id),d(Z.name),m(Z.role),p(Z.email??""),E(null)},W=async()=>{if(a)try{await ie.users.update(a,{name:l,role:u,email:h||void 0}),i(null),E({type:"ok",text:t("settings:userManagement.updateSuccess")}),M()}catch(Z){E({type:"err",text:`${t("settings:userManagement.error")}: ${String(Z)}`})}},U=async()=>{if(!(!y||!v))try{await ie.users.resetPassword(y,v),x(null),j(""),E({type:"ok",text:t("settings:userManagement.resetSuccess")})}catch(Z){E({type:"err",text:`${t("settings:userManagement.error")}: ${String(Z)}`})}},H=async Z=>{if(Z===e?.id){E({type:"err",text:t("settings:userManagement.cannotDeleteSelf")}),w(null);return}if(r.find(J=>J.id===Z)?.role==="owner"){E({type:"err",text:t("settings:userManagement.cannotDeleteOwner")}),w(null);return}try{await ie.users.remove(Z),w(null),E({type:"ok",text:t("settings:userManagement.deleteSuccess")}),M()}catch(J){E({type:"err",text:`${t("settings:userManagement.error")}: ${String(J)}`})}},q=async()=>{if(z.trim())try{const Z=await ie.users.create(z.trim(),Y,void 0,D.trim()||void 0,L||void 0);I(!1),B(""),V(""),F("member"),O(""),E({type:"ok",text:t("settings:userManagement.addSuccess",{defaultValue:"User created"})}),Z.inviteToken&&S(`${window.location.origin}/#invite?token=${Z.inviteToken}`),M()}catch(Z){E({type:"err",text:`${t("settings:userManagement.error")}: ${Z instanceof Error?Z.message:String(Z)}`})}};return n.jsxs(pi,{title:t("settings:userManagement.title"),children:[n.jsxs("div",{className:"mb-3",children:[n.jsx("p",{className:"text-xs text-fg-tertiary leading-relaxed",children:t("settings:userManagement.sharedInstanceDesc")}),n.jsx("p",{className:"text-xs text-fg-tertiary mt-1",children:t("settings:userManagement.orgHint")})]}),R?n.jsxs("div",{className:"mb-3 p-4 rounded-lg border border-border-default space-y-3",children:[n.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[n.jsxs("div",{children:[n.jsx("label",{className:"text-[11px] text-fg-tertiary mb-1 block",children:t("settings:userManagement.name")}),n.jsx("input",{value:z,onChange:Z=>B(Z.target.value),autoFocus:!0,className:"w-full px-3 py-1.5 text-sm bg-surface-elevated border border-border-default rounded-md text-fg-primary"})]}),n.jsxs("div",{children:[n.jsx("label",{className:"text-[11px] text-fg-tertiary mb-1 block",children:t("settings:userManagement.email")}),n.jsx("input",{value:D,onChange:Z=>V(Z.target.value),type:"email",className:"w-full px-3 py-1.5 text-sm bg-surface-elevated border border-border-default rounded-md text-fg-primary"})]}),n.jsxs("div",{children:[n.jsx("label",{className:"text-[11px] text-fg-tertiary mb-1 block",children:t("settings:userManagement.role")}),n.jsx("select",{value:Y,onChange:Z=>F(Z.target.value),className:"w-full px-3 py-1.5 text-sm bg-surface-elevated border border-border-default rounded-md text-fg-primary",children:tj.map(Z=>n.jsx("option",{value:Z,children:t(`settings:userManagement.roles.${Z}`)},Z))})]}),n.jsxs("div",{children:[n.jsx("label",{className:"text-[11px] text-fg-tertiary mb-1 block",children:t("settings:userManagement.password",{defaultValue:"Password"})}),n.jsx("input",{value:L,onChange:Z=>O(Z.target.value),type:"password",className:"w-full px-3 py-1.5 text-sm bg-surface-elevated border border-border-default rounded-md text-fg-primary"})]})]}),n.jsxs("div",{className:"flex gap-2 justify-end",children:[n.jsx("button",{onClick:()=>{I(!1),B(""),V(""),F("member"),O("")},className:"px-3 py-1.5 text-xs text-fg-tertiary hover:text-fg-secondary",children:t("settings:userManagement.cancel")}),n.jsx("button",{onClick:q,disabled:!z.trim(),className:"px-4 py-1.5 bg-brand-600 hover:bg-brand-500 disabled:opacity-40 text-white text-xs font-medium rounded-lg",children:t("settings:userManagement.save")})]})]}):n.jsx("button",{onClick:()=>I(!0),className:"mb-3 px-4 py-2 bg-brand-600 hover:bg-brand-500 text-white text-xs font-medium rounded-lg transition-colors",children:t("settings:userManagement.addUser",{defaultValue:"Add User"})}),n.jsxs("div",{className:"bg-surface-elevated rounded-xl overflow-hidden",children:[T&&n.jsx("div",{className:`px-4 py-2 text-xs border-b ${T.type==="ok"?"bg-green-500/10 text-green-600 border-green-500/20":"bg-red-500/10 text-red-500 border-red-500/20"}`,children:T.text}),N&&n.jsxs("div",{className:"px-4 py-3 bg-brand-500/5 border-b border-brand-500/20 flex items-center gap-3",children:[n.jsxs("div",{className:"flex-1 min-w-0",children:[n.jsx("div",{className:"text-[11px] text-fg-tertiary mb-1",children:t("settings:userManagement.copyInviteLink")}),n.jsx("code",{className:"text-[10px] text-brand-500 bg-surface-elevated px-2 py-1 rounded block truncate",children:N})]}),n.jsx("button",{onClick:()=>{navigator.clipboard.writeText(N),E({type:"ok",text:t("settings:userManagement.linkCopied")})},className:"shrink-0 px-3 py-1.5 text-[11px] bg-brand-600 hover:bg-brand-500 text-white rounded-lg font-medium",children:t("settings:userManagement.copy")}),n.jsx("button",{onClick:()=>S(null),className:"shrink-0 text-fg-tertiary hover:text-fg-secondary text-sm",children:"×"})]}),n.jsxs("table",{className:"w-full text-sm",children:[n.jsx("thead",{children:n.jsxs("tr",{className:"border-b border-border-default/60 text-fg-tertiary text-[11px] uppercase tracking-wider",children:[n.jsx("th",{className:"text-left px-4 py-2.5 font-medium",children:t("settings:userManagement.name")}),n.jsx("th",{className:"text-left px-4 py-2.5 font-medium",children:t("settings:userManagement.email")}),n.jsx("th",{className:"text-left px-4 py-2.5 font-medium",children:t("settings:userManagement.role")}),n.jsx("th",{className:"text-right px-4 py-2.5 font-medium",children:t("settings:userManagement.actions")})]})}),n.jsxs("tbody",{children:[r.length===0&&n.jsx("tr",{children:n.jsx("td",{colSpan:4,className:"px-4 py-6 text-center text-fg-tertiary text-xs",children:t("settings:userManagement.noUsers")})}),r.map(Z=>{const _=a===Z.id,J=y===Z.id,X=C===Z.id,ee=Z.id===e?.id,te=Z.role==="owner";return n.jsxs("tr",{className:"border-b border-border-default/40 last:border-b-0 hover:bg-surface-elevated/40 transition-colors",children:[n.jsx("td",{className:"px-4 py-2.5",children:_?n.jsx("input",{value:l,onChange:G=>d(G.target.value),className:"w-full px-2 py-1 text-xs bg-surface-primary border border-border-default rounded-md focus:outline-none focus:ring-1 focus:ring-brand-500/50"}):n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx("span",{className:"text-fg-primary font-medium text-xs",children:Z.name}),ee&&n.jsx("span",{className:"text-[9px] px-1.5 py-0.5 rounded-full bg-brand-500/10 text-brand-500",children:"you"})]})}),n.jsx("td",{className:"px-4 py-2.5",children:_?n.jsx("input",{value:h,onChange:G=>p(G.target.value),placeholder:"email@example.com",className:"w-full px-2 py-1 text-xs bg-surface-primary border border-border-default rounded-md focus:outline-none focus:ring-1 focus:ring-brand-500/50"}):n.jsx("span",{className:"text-fg-secondary text-xs",children:Z.email||"—"})}),n.jsx("td",{className:"px-4 py-2.5",children:_?n.jsx("select",{value:u,onChange:G=>m(G.target.value),className:"px-2 py-1 text-xs bg-surface-primary border border-border-default rounded-md focus:outline-none focus:ring-1 focus:ring-brand-500/50",children:tj.map(G=>n.jsx("option",{value:G,children:t(`settings:userManagement.roles.${G}`)},G))}):n.jsx("span",{className:`inline-block text-[10px] px-2 py-0.5 rounded-full border font-medium ${iY[Z.role]??""}`,children:t(`settings:userManagement.roles.${Z.role}`)})}),n.jsx("td",{className:"px-4 py-2.5 text-right",children:_?n.jsxs("div",{className:"flex items-center justify-end gap-2",children:[n.jsx("button",{onClick:()=>i(null),className:"text-[11px] text-fg-tertiary hover:text-fg-secondary",children:t("settings:userManagement.cancel")}),n.jsx("button",{onClick:W,className:"text-[11px] text-brand-500 hover:text-brand-400 font-medium",children:t("settings:userManagement.save")})]}):J?n.jsxs("div",{className:"flex items-center justify-end gap-2",children:[n.jsx("input",{type:"password",value:v,onChange:G=>j(G.target.value),placeholder:t("settings:userManagement.newPassword"),autoFocus:!0,className:"w-32 px-2 py-1 text-xs bg-surface-primary border border-border-default rounded-md focus:outline-none focus:ring-1 focus:ring-brand-500/50"}),n.jsx("button",{onClick:()=>{x(null),j("")},className:"text-[11px] text-fg-tertiary hover:text-fg-secondary",children:t("settings:userManagement.cancel")}),n.jsx("button",{onClick:U,disabled:v.length<6,className:"text-[11px] text-brand-500 hover:text-brand-400 font-medium disabled:opacity-40",children:t("settings:userManagement.confirmReset")})]}):X?n.jsxs("div",{className:"flex items-center justify-end gap-2",children:[n.jsx("span",{className:"text-[10px] text-red-500",children:t("settings:userManagement.confirmDelete")}),n.jsx("button",{onClick:()=>w(null),className:"text-[11px] text-fg-tertiary hover:text-fg-secondary",children:t("settings:userManagement.cancel")}),n.jsx("button",{onClick:()=>H(Z.id),className:"text-[11px] text-red-500 hover:text-red-400 font-medium",children:t("settings:userManagement.deleteUser")})]}):n.jsxs("div",{className:"flex items-center justify-end gap-1.5",children:[n.jsx("button",{onClick:()=>$(Z),className:"text-[11px] text-fg-tertiary hover:text-fg-secondary px-1.5 py-0.5 rounded hover:bg-surface-elevated",children:t("settings:userManagement.editUser")}),Z.email&&n.jsx("button",{onClick:()=>{x(Z.id),j(""),E(null)},className:"text-[11px] text-fg-tertiary hover:text-fg-secondary px-1.5 py-0.5 rounded hover:bg-surface-elevated",children:t("settings:userManagement.resetPassword")}),Z.email&&!te&&!Z.hasJoined&&n.jsx("button",{onClick:async()=>{try{const{inviteToken:G}=await ie.users.reinvite(Z.id),ue=`${window.location.origin}/#invite?token=${G}`;S(ue),E({type:"ok",text:t("settings:userManagement.inviteLinkGenerated")})}catch(G){E({type:"err",text:String(G)})}},className:"text-[11px] text-brand-400 hover:text-brand-500 px-1.5 py-0.5 rounded hover:bg-brand-500/10",children:t("settings:userManagement.inviteLink")}),!te&&!ee&&n.jsx("button",{onClick:()=>{w(Z.id),E(null)},className:"text-[11px] text-red-400 hover:text-red-500 px-1.5 py-0.5 rounded hover:bg-red-500/10",children:t("settings:userManagement.deleteUser")})]})})]},Z.id)})]})]})]})]})}function lY({providerName:e,addModelForm:t,setAddModelForm:r,addModelSaving:s,onAdd:a,onCancel:i,t:l}){const[d,u]=g.useState([]),[m,h]=g.useState(!1),[p,y]=g.useState(!1),x=async()=>{h(!0);try{const v=await ie.modelCatalog.getByProvider(e);u(v.models),y(!0)}catch{u([])}finally{h(!1)}};return n.jsxs(n.Fragment,{children:[n.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[n.jsx("span",{className:"text-[10px] text-fg-secondary",children:l("modelProviders.addModelTitle")}),n.jsx("button",{onClick:()=>{x()},disabled:m,className:"text-[10px] text-brand-500 hover:text-brand-400 disabled:opacity-40 transition-colors",children:m?"...":l("modelProviders.browseFromCatalog")})]}),p&&d.length>0&&n.jsx("div",{className:"border border-border-default rounded-lg p-2 mb-2",children:n.jsx(dh,{provider:e,models:d,selectedModel:t.id,onSelect:v=>{const j=d.find(C=>C.id===v);j&&r(C=>({...C,id:j.id,name:j.id,contextWindow:j.maxInputTokens,maxOutputTokens:j.maxOutputTokens,costInput:j.inputCostPer1MTokens,costOutput:j.outputCostPer1MTokens,reasoning:j.capabilities.reasoning,vision:j.capabilities.vision}))},compact:!0,maxVisible:5})}),n.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-2",children:[n.jsx("input",{type:"text",placeholder:l("modelProviders.modelId"),value:t.id,onChange:v=>r({...t,id:v.target.value}),className:"px-2 py-1 text-xs bg-surface-primary border border-border-default rounded text-fg-primary placeholder-fg-tertiary focus:border-brand-500 outline-none"}),n.jsx("input",{type:"text",placeholder:l("modelProviders.displayName"),value:t.name,onChange:v=>r({...t,name:v.target.value}),className:"px-2 py-1 text-xs bg-surface-primary border border-border-default rounded text-fg-primary placeholder-fg-tertiary focus:border-brand-500 outline-none"}),n.jsx("input",{type:"number",placeholder:l("modelProviders.placeholderContextTokens"),value:t.contextWindow,onChange:v=>r({...t,contextWindow:Number(v.target.value)}),className:"px-2 py-1 text-xs bg-surface-primary border border-border-default rounded text-fg-primary focus:border-brand-500 outline-none"}),n.jsx("input",{type:"number",placeholder:l("modelProviders.maxOutput"),value:t.maxOutputTokens,onChange:v=>r({...t,maxOutputTokens:Number(v.target.value)}),className:"px-2 py-1 text-xs bg-surface-primary border border-border-default rounded text-fg-primary focus:border-brand-500 outline-none"})]}),n.jsxs("div",{className:"flex items-center gap-3",children:[n.jsxs("div",{className:"flex items-center gap-1",children:[n.jsx("span",{className:"text-[10px] text-fg-tertiary",children:l("modelProviders.costPerMillionIn")}),n.jsx("input",{type:"number",step:"0.01",value:t.costInput,onChange:v=>r({...t,costInput:Number(v.target.value)}),className:"w-16 px-2 py-1 text-xs bg-surface-primary border border-border-default rounded text-fg-primary focus:border-brand-500 outline-none"})]}),n.jsxs("div",{className:"flex items-center gap-1",children:[n.jsx("span",{className:"text-[10px] text-fg-tertiary",children:l("modelProviders.costPerMillionOut")}),n.jsx("input",{type:"number",step:"0.01",value:t.costOutput,onChange:v=>r({...t,costOutput:Number(v.target.value)}),className:"w-16 px-2 py-1 text-xs bg-surface-primary border border-border-default rounded text-fg-primary focus:border-brand-500 outline-none"})]}),n.jsxs("label",{className:"flex items-center gap-1 text-[10px] text-fg-tertiary cursor-pointer",children:[n.jsx("input",{type:"checkbox",checked:t.reasoning,onChange:v=>r({...t,reasoning:v.target.checked}),className:"rounded"}),l("modelProviders.reasoning")]}),n.jsxs("label",{className:"flex items-center gap-1 text-[10px] text-fg-tertiary cursor-pointer",children:[n.jsx("input",{type:"checkbox",checked:t.vision,onChange:v=>r({...t,vision:v.target.checked}),className:"rounded"}),l("modelProviders.vision")]}),n.jsx("div",{className:"flex-1"}),n.jsx("button",{onClick:a,disabled:s||!t.id||!t.name,className:"px-2 py-1 text-[10px] bg-brand-600 hover:bg-brand-500 disabled:opacity-40 text-white rounded transition-colors",children:l(s?"modelProviders.adding":"common:create")}),n.jsx("button",{onClick:i,className:"px-2 py-1 text-[10px] border border-border-default text-fg-secondary hover:bg-surface-elevated rounded transition-colors",children:l("common:cancel")})]})]})}function Du({step:e,title:t,description:r,active:s,children:a}){return n.jsxs("div",{className:`rounded-xl p-4 space-y-3 transition-colors ${s?"ring-1 ring-brand-500/60 bg-brand-500/10":"bg-surface-elevated"}`,children:[n.jsxs("div",{className:"flex items-start gap-3",children:[n.jsx("span",{className:"flex-none w-6 h-6 rounded-full bg-surface-overlay flex items-center justify-center text-xs font-bold text-fg-secondary",children:e}),n.jsxs("div",{className:"min-w-0",children:[n.jsx("div",{className:"text-sm font-medium text-fg-primary",children:t}),n.jsx("div",{className:"text-xs text-fg-tertiary mt-0.5",children:r})]})]}),a&&n.jsx("div",{className:"pl-9",children:a})]})}function Ka({type:e,text:t}){return n.jsx("div",{className:`text-xs px-3 py-2 rounded-lg ${e==="ok"?"bg-green-500/10 text-green-600 border border-green-500/30":"bg-red-500/10 text-red-500 border border-red-500/30"}`,children:t})}function pi({title:e,children:t}){return n.jsxs("section",{children:[n.jsx("h3",{className:"text-sm font-semibold text-fg-secondary uppercase tracking-wider mb-4",children:e}),n.jsx("div",{className:"space-y-4",children:t})]})}function Kx({label:e,value:t,color:r}){const s=r==="green"?"bg-green-500/10 text-green-600":"bg-brand-500/10 text-brand-500";return n.jsxs("div",{className:`rounded-xl px-5 py-4 ${s}`,children:[n.jsx("div",{className:"text-2xl font-bold",children:t}),n.jsx("div",{className:"text-xs mt-1 opacity-70",children:e})]})}function ml({label:e,value:t}){return n.jsxs("div",{children:[n.jsx("div",{className:"text-[10px] text-fg-tertiary uppercase",children:e}),n.jsx("div",{className:"text-xs text-fg-secondary mt-0.5 truncate",children:t})]})}function nd(e,t){if(e===0)return t?t("dataStorage.bytesZero"):"0 B";const r=t?[t("dataStorage.unitB"),t("dataStorage.unitKB"),t("dataStorage.unitMB"),t("dataStorage.unitGB")]:["B","KB","MB","GB"],s=Math.min(Math.floor(Math.log(e)/Math.log(1024)),r.length-1),a=e/Math.pow(1024,s);return`${a<10?a.toFixed(1):Math.round(a)} ${r[s]}`}function cY({orphanInfo:e,dataDir:t,onPurged:r,formatBytes:s}){const{t:a}=pt(["settings","common"]),i=[...e.orphanAgents.map(w=>({...w,kind:"agent"})),...e.orphanTeams.map(w=>({...w,kind:"team"}))],[l,d]=g.useState(new Set),[u,m]=g.useState(!1),[h,p]=g.useState(null),y=w=>d(N=>{const S=new Set(N);return S.has(w)?S.delete(w):S.add(w),S}),x=l.size===i.length&&i.length>0,v=()=>d(x?new Set:new Set(i.map(w=>w.id))),j=i.filter(w=>l.has(w.id)).reduce((w,N)=>w+N.size,0),C=async w=>{m(!0),p(null);try{const N=await ie.system.purgeOrphans(w),S=N.purgedAgents.length+N.purgedTeams.length,T=a("dataStorage.cleaned",{count:S,size:s(N.freedBytes)});p(N.failures.length?a("dataStorage.cleanedWithFailureNote",{base:T,count:N.failures.length}):T),d(new Set),r()}catch{p(a("dataStorage.cleanupFailed"))}finally{m(!1)}};return n.jsxs("div",{className:"border-t border-border-default pt-4",children:[n.jsx("h4",{className:"text-xs font-semibold text-amber-500 mb-2",children:a("dataStorage.orphanedDirectories")}),n.jsxs("p",{className:"text-xs text-fg-tertiary mb-3",children:[a("dataStorage.orphanedDesc")," ",a("dataStorage.orphanedTotal",{size:s(e.totalOrphanSize),count:i.length})]}),n.jsxs("div",{className:"flex items-center gap-2 mb-2 px-1",children:[n.jsxs("label",{className:"flex items-center gap-1.5 text-[10px] text-fg-tertiary cursor-pointer select-none",children:[n.jsx("input",{type:"checkbox",checked:x,onChange:v,className:"rounded"}),a("common:selectAll")]}),l.size>0&&n.jsx("span",{className:"text-[10px] text-fg-secondary",children:a("dataStorage.selectedWithSize",{count:l.size,size:s(j)})})]}),n.jsx("div",{className:"space-y-0.5 mb-3 max-h-52 overflow-y-auto",children:i.map(w=>n.jsxs("div",{className:`flex items-center gap-2 text-xs py-1.5 px-2 rounded transition-colors ${l.has(w.id)?"bg-amber-500/10":"bg-surface-elevated/30 hover:bg-surface-elevated/50"}`,children:[n.jsx("input",{type:"checkbox",checked:l.has(w.id),onChange:()=>y(w.id),className:"rounded shrink-0"}),w.kind==="team"&&n.jsx("span",{className:"text-[10px] text-fg-tertiary shrink-0",children:a("dataStorage.teamKind")}),n.jsx("span",{className:"text-fg-tertiary font-mono truncate min-w-0 flex-1",children:w.id}),n.jsx("span",{className:"text-fg-secondary tabular-nums shrink-0",children:s(w.size)}),n.jsx("button",{onClick:()=>{ie.system.openPath(w.path)},className:"text-[10px] text-fg-tertiary hover:text-fg-secondary shrink-0 underline",children:a("common:open")})]},w.id))}),n.jsxs("div",{className:"flex gap-2 items-center flex-wrap",children:[l.size>0&&n.jsx("button",{disabled:u,onClick:()=>{C([...l])},className:"px-3 py-1.5 text-xs bg-amber-600 hover:bg-amber-500 text-white rounded-lg transition-colors disabled:opacity-50",children:u?a("dataStorage.cleaning"):a("dataStorage.cleanSelected",{size:s(j)})}),n.jsx("button",{disabled:u,onClick:()=>{C()},className:"px-3 py-1.5 text-xs border border-amber-600/50 hover:bg-amber-600/10 text-amber-500 rounded-lg transition-colors disabled:opacity-50",children:u?a("dataStorage.cleaning"):a("dataStorage.cleanAll",{size:s(e.totalOrphanSize)})})]}),h&&n.jsx("div",{className:"text-xs text-fg-tertiary mt-2",children:h})]})}function dY({authUser:e,onClose:t,onSaved:r}){const{t:s}=pt("common"),[a,i]=g.useState(e.name||""),[l,d]=g.useState(e.email||""),[u,m]=g.useState(!1),[h,p]=g.useState(""),[y,x]=g.useState(e.avatarUrl),v=async j=>{if(j.preventDefault(),!a.trim()){p(s("profile.nameRequired"));return}if(l&&!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(l.trim())){p(s("profile.invalidEmail"));return}m(!0),p("");try{const{user:C}=await ie.auth.updateProfile(a.trim(),l.trim());r({...C,avatarUrl:y??C.avatarUrl})}catch{p(s("profile.failedToSave"))}finally{m(!1)}};return n.jsx("div",{className:"fixed inset-0 bg-black/60 flex items-center justify-center z-50",onClick:t,children:n.jsxs("form",{onSubmit:v,className:"bg-surface-secondary border border-border-default rounded-xl p-6 w-[400px] shadow-2xl",onClick:j=>j.stopPropagation(),children:[n.jsx("h3",{className:"text-base font-semibold mb-5",children:s("profile.editProfile")}),n.jsx("div",{className:"flex justify-center mb-5",children:n.jsx(y6,{currentUrl:y,name:a,size:72,targetType:"user",targetId:e.id,onUploaded:j=>x(j)})}),n.jsxs("div",{className:"space-y-3",children:[n.jsxs("div",{children:[n.jsx("label",{className:"block text-xs text-fg-tertiary font-medium mb-1",children:s("profile.name")}),n.jsx("input",{value:a,onChange:j=>i(j.target.value),className:"w-full px-3 py-2 bg-surface-elevated border border-border-default rounded-lg text-sm text-fg-primary focus:border-brand-500 outline-none"})]}),n.jsxs("div",{children:[n.jsx("label",{className:"block text-xs text-fg-tertiary font-medium mb-1",children:s("profile.email")}),n.jsx("input",{value:l,onChange:j=>d(j.target.value),type:"email",className:"w-full px-3 py-2 bg-surface-elevated border border-border-default rounded-lg text-sm text-fg-primary focus:border-brand-500 outline-none"})]}),h&&n.jsx("div",{className:"text-xs text-red-500 bg-red-500/10 border border-red-500/30 rounded-lg px-3 py-2",children:h})]}),n.jsxs("div",{className:"flex justify-end gap-3 mt-5",children:[n.jsx("button",{type:"button",onClick:t,className:"px-4 py-2 text-sm border border-border-default rounded-lg hover:bg-surface-elevated",children:s("cancel")}),n.jsx("button",{type:"submit",disabled:u,className:"px-4 py-2 text-sm bg-brand-600 hover:bg-brand-500 disabled:opacity-50 text-white rounded-lg",children:s(u?"saving":"save")})]})]})})}function uY(){const{t:e}=pt(["settings","common"]),[t,r]=g.useState(null),[s,a]=g.useState(!0),[i,l]=g.useState(!1),[d,u]=g.useState(null),[m,h]=g.useState(!1),p=Ch(),y=g.useCallback(async()=>{try{const N=await ie.settings.getRemote();r(N)}catch{r(null)}finally{a(!1)}},[]);g.useEffect(()=>{y()},[y]),g.useEffect(()=>pn.on("remote:status",N=>{const S=N.payload;S&&(r(S),l(!1))}),[]);const x=async()=>{l(!0),u(null);try{t?.enabled?(await ie.settings.disableRemote(),await y(),l(!1)):(Wn.isAuthenticated()||await da(),await ie.settings.enableRemote())}catch(N){u(String(N instanceof Error?N.message:N)),l(!1)}},v=async()=>{try{await da(),await y()}catch{}},j=()=>{t?.remoteUrl&&(navigator.clipboard.writeText(t.remoteUrl),h(!0),setTimeout(()=>h(!1),2e3))},C=i||t?.enabled&&!t?.connected&&t?.state!=="idle",w=t?.remoteUrl??null;return n.jsx(pi,{title:e("settings:remoteAccess.title"),children:n.jsxs("div",{className:"space-y-4",children:[n.jsx("p",{className:"text-sm text-content-secondary",children:e("settings:remoteAccess.description")}),Wn.isAuthenticated()?n.jsxs("div",{className:"flex items-center gap-2 text-sm text-content-secondary",children:[n.jsx("span",{className:"w-2 h-2 rounded-full bg-green-500"}),e("settings:remoteAccess.signedInAs")," ",n.jsx("strong",{children:p?.username??p?.displayName})]}):n.jsxs("div",{className:"flex items-center gap-3 p-3 rounded-lg bg-amber-500/10 border border-amber-500/20",children:[n.jsx("svg",{className:"w-5 h-5 text-amber-500 shrink-0",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:n.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 9v2m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"})}),n.jsx("span",{className:"text-sm text-amber-600 dark:text-amber-400",children:e("settings:remoteAccess.loginRequired")}),n.jsx("button",{onClick:v,className:"ml-auto px-3 py-1.5 text-xs font-medium bg-brand-600 hover:bg-brand-500 text-white rounded-lg transition-colors",children:e("settings:remoteAccess.signIn")})]}),Wn.isAuthenticated()&&n.jsxs("div",{className:"space-y-4",children:[n.jsxs("div",{className:"flex items-center justify-between",children:[n.jsxs("div",{className:"flex items-center gap-3",children:[n.jsx("button",{onClick:x,disabled:i||s,className:`relative w-12 h-6 rounded-full transition-colors duration-200 ${t?.enabled?"bg-brand-600":"bg-gray-300 dark:bg-gray-600"} ${i||s?"opacity-50 cursor-not-allowed":"cursor-pointer"}`,children:n.jsx("span",{className:`block w-5 h-5 bg-white rounded-full shadow transform transition-transform duration-200 ${t?.enabled?"translate-x-6":"translate-x-0.5"}`})}),n.jsx("span",{className:"text-sm font-medium",children:C?e("settings:remoteAccess.connecting"):t?.enabled?e("settings:remoteAccess.enabled"):e("settings:remoteAccess.disabled")}),C&&n.jsx(nj,{})]}),t?.enabled&&n.jsxs("div",{className:`flex items-center gap-1.5 text-xs ${t.connected?"text-green-600 dark:text-green-400":t.state==="registering"||t.state==="connecting"?"text-blue-600 dark:text-blue-400":"text-amber-600 dark:text-amber-400"}`,children:[n.jsx("span",{className:`w-2 h-2 rounded-full ${t.connected?"bg-green-500 animate-pulse":t.state==="registering"||t.state==="connecting"?"bg-blue-500 animate-pulse":"bg-amber-500"}`}),t.connected?e("settings:remoteAccess.connected"):t.state==="registering"?e("settings:remoteAccess.registering"):t.state==="connecting"?e("settings:remoteAccess.connecting"):e("settings:remoteAccess.disconnected"),t.connected&&t.peerCount>0&&n.jsxs(n.Fragment,{children:[" · ",e("settings:remoteAccess.peerCount",{count:t.peerCount})]}),(t.state==="registering"||t.state==="connecting")&&n.jsx(nj,{})]})]}),d&&n.jsx("div",{className:"p-2 rounded-lg bg-red-500/10 text-red-500 text-sm",children:d}),t?.enabled&&t.peers&&t.peers.length>0&&n.jsxs("div",{className:"p-4 rounded-lg bg-surface-elevated border border-border-default space-y-2",children:[n.jsx("label",{className:"text-xs text-content-tertiary uppercase tracking-wider",children:e("settings:remoteAccess.connectedPeers")}),n.jsx("div",{className:"space-y-2 mt-1",children:t.peers.map(N=>n.jsxs("div",{className:"flex items-center gap-3 px-3 py-2 rounded-lg bg-surface-inset",children:[n.jsx("span",{className:`w-2 h-2 rounded-full shrink-0 ${N.transport==="p2p"?"bg-green-500":N.transport==="relay"?"bg-blue-500":"bg-amber-500 animate-pulse"}`}),n.jsxs("div",{className:"flex-1 min-w-0",children:[n.jsxs("div",{className:"text-sm font-mono text-content-primary truncate",children:[N.peerId.slice(0,8),"..."]}),n.jsx("div",{className:"text-xs text-content-tertiary",children:e("settings:remoteAccess.connectedSince",{time:new Date(N.connectedAt).toLocaleTimeString()})})]}),n.jsx("span",{className:`px-2 py-0.5 text-xs font-medium rounded-full ${N.transport==="p2p"?"bg-green-500/10 text-green-600 dark:text-green-400":N.transport==="relay"?"bg-blue-500/10 text-blue-600 dark:text-blue-400":"bg-amber-500/10 text-amber-600 dark:text-amber-400"}`,children:N.transport==="p2p"?"P2P":N.transport==="relay"?"Relay":e("settings:remoteAccess.peerConnecting")})]},N.peerId))})]}),t?.enabled&&t.remoteUrl&&n.jsxs("div",{className:"p-4 rounded-lg bg-surface-elevated border border-border-default space-y-3",children:[n.jsxs("div",{children:[n.jsx("label",{className:"text-xs text-content-tertiary uppercase tracking-wider",children:e("settings:remoteAccess.url")}),n.jsxs("div",{className:"flex items-center gap-2 mt-1",children:[n.jsx("code",{className:"flex-1 px-3 py-1.5 text-sm bg-surface-inset rounded font-mono truncate",children:t.remoteUrl}),n.jsx("button",{onClick:j,className:`px-2 py-1.5 text-xs border rounded transition-colors ${m?"border-green-500 text-green-600 dark:text-green-400":"border-border-default hover:bg-surface-elevated"}`,children:e(m?"settings:remoteAccess.copied":"settings:remoteAccess.copy")})]})]}),w&&n.jsxs("div",{children:[n.jsx("label",{className:"text-xs text-content-tertiary uppercase tracking-wider",children:e("settings:remoteAccess.qrCode")}),n.jsx("p",{className:"text-xs text-content-secondary mt-0.5 mb-2",children:e("settings:remoteAccess.scanQr")}),n.jsx(mY,{url:w})]})]})]})]})})}function nj(){return n.jsxs("svg",{className:"w-4 h-4 animate-spin text-content-secondary",viewBox:"0 0 24 24",fill:"none",children:[n.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),n.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"})]})}function mY({url:e}){const t=g.useRef(null),[r,s]=g.useState(!1);return g.useEffect(()=>{const a=t.current;a&&(s(!1),Bd(()=>import("./browser-DMM1ORh5.js").then(i=>i.b),[]).then(i=>{i.toCanvas(a,e,{width:200,margin:2,color:{dark:"#000000",light:"#ffffff"},errorCorrectionLevel:"M"})}).catch(()=>s(!0)))},[e]),r?n.jsx("a",{href:e,target:"_blank",rel:"noopener",className:"text-sm text-brand-500 underline",children:e}):n.jsx("div",{className:"inline-block p-2 bg-white rounded-lg",children:n.jsx("canvas",{ref:t,className:"block",style:{width:160,height:160}})})}const fY={multi_user:"👥",unlimited_teams:"🏢",unlimited_tools:"⚡",sso:"🔐",audit_enhanced:"📋",multi_instance:"🌐",offline_license:"📡"};function hY({authUser:e}){const{t}=pt(["settings","common"]),r=()=>window.location.hash.slice(1).split("/")[1]==="users"?"users":"orgLicense",[s,a]=g.useState(r),i=[{id:"orgLicense",label:t("account.sectionOrgLicense")},{id:"users",label:t("account.sectionUsers")}];return n.jsxs("div",{className:"space-y-6",children:[n.jsxs("div",{children:[n.jsx("h2",{className:"text-lg font-semibold text-fg-primary mb-1",children:t("account.title")}),n.jsx("p",{className:"text-xs text-fg-tertiary",children:t("account.subtitle")})]}),n.jsx("div",{className:"flex gap-1 p-1 bg-surface-elevated rounded-lg border border-border-default",children:i.map(l=>n.jsx("button",{onClick:()=>a(l.id),className:`flex-1 px-3 py-2 text-xs font-medium rounded-md transition-all ${s===l.id?"bg-surface-primary text-fg-primary shadow-sm border border-border-default":"text-fg-tertiary hover:text-fg-secondary"}`,children:l.label},l.id))}),s==="orgLicense"&&n.jsx(pY,{}),s==="users"&&n.jsx(oY,{authUser:e})]})}function pY(){const{t:e}=pt(["settings","common"]),[t,r]=g.useState([]),[s,a]=g.useState(()=>{try{return localStorage.getItem("markus_selected_org_id")}catch{return null}}),i=g.useCallback(je=>{a(Re=>{const We=typeof je=="function"?je(Re):je;try{We?localStorage.setItem("markus_selected_org_id",We):localStorage.removeItem("markus_selected_org_id")}catch{}return We})},[]),[l,d]=g.useState([]),[u,m]=g.useState([]),[h,p]=g.useState(""),[y,x]=g.useState(""),[v,j]=g.useState("member"),[C,w]=g.useState(!1),[N,S]=g.useState(!1),[T,E]=g.useState(null),[R,I]=g.useState(!0),[z,B]=g.useState(!1),[D,V]=g.useState(null),[Y,F]=g.useState(null),[L,O]=g.useState(""),[M,$]=g.useState(!1),[W,U]=g.useState(!1),[H,q]=g.useState(null);g.useRef(null);const Z=g.useCallback((je=!1)=>{I(!0);let Re=!1;Promise.all([ie.hubOrgs.mine().catch(We=>(Re=!0,je&&E({type:"err",text:We instanceof Error?We.message:e("org.loadFailed")}),{orgs:[]})),ie.hubOrgs.invitations().catch(()=>({invitations:[]}))]).then(([We,Vt])=>{r(We.orgs),m(Vt.invitations),We.orgs.length>0?(i(ln=>ln&&We.orgs.some(vn=>vn.id===ln)?ln:We.orgs.find(vn=>vn.license?.plan==="enterprise")?.id??We.orgs[0].id),p(ln=>ln||(We.orgs.find(vn=>vn.license?.plan==="enterprise")?.name??We.orgs[0].name))):je&&!Re&&E({type:"err",text:e("org.noOrgAfterConnect")})}).finally(()=>I(!1))},[i,e]);g.useEffect(()=>{if(!Ch()&&!gi()){I(!1);return}Z()},[Z]),g.useEffect(()=>{if(!s)return;ie.hubOrgs.members(s).then(Re=>d(Re.members)).catch(()=>{});const je=t.find(Re=>Re.id===s);je&&p(je.name)},[s]);const _=t.find(je=>je.id===s),J=_?.role==="owner",X=_?.role==="admin",ee=J||X,te={owner:e("org.roleOwner"),admin:e("org.roleAdmin"),member:e("org.roleMember")},G=je=>te[je]??je,ue={"Trial already used for this account":"license.trialAlreadyUsed","License not found or not active":"license.licenseNotFound","Instance limit reached":"license.instanceLimitReached"},Se=je=>{const Re=ue[je];return Re?e(Re):je},Ce=g.useCallback((je=!1)=>{U(!0),(je?ie.license.refresh():ie.license.get()).then(We=>V(We)).catch(()=>{}).finally(()=>setTimeout(()=>U(!1),400))},[]);g.useEffect(()=>{Ce(!0)},[Ce]);const Be=t.length>0,Ne=_?.license?.plan==="enterprise",he=s&&Be?Ne:D?.plan==="enterprise",_e=!Be||he&&D?.orgId!=null&&D.orgId===s,Ee=!Be||J,Ye=_e?D?.validUntil:_?.license?.validUntil,Ze=_e?D?.maxSeats:_?.license?.maxSeats,mt=_e?D?.usedSeats??0:_?.memberCount??0,it=Ye?Math.max(0,Math.ceil((new Date(Ye).getTime()-Date.now())/864e5)):null,Lt=he&&Ee&&it!==null&&it<=60,ht=["multi_user","multi_instance"],ne={multi_user:e("license.featureMultiUser"),multi_instance:e("license.featureMultiInstance")},me=async()=>{if(!(!s||!h.trim()))try{await ie.hubOrgs.update(s,{name:h.trim()}),r(je=>je.map(Re=>Re.id===s?{...Re,name:h.trim()}:Re)),E({type:"ok",text:e("org.nameSaved")})}catch(je){E({type:"err",text:je instanceof Error?je.message:"Failed"})}},be=_?.license?.maxSeats!=null&&_.memberCount>=_.license.maxSeats,se=async()=>{if(!s||!y.trim())return;const je=y.trim().toLowerCase();if(!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(je)){E({type:"err",text:e("org.invalidEmail")});return}w(!0),E(null);try{await ie.hubOrgs.invite(s,{email:je,role:v}),x(""),j("member"),E({type:"ok",text:e("org.invited")}),ie.hubOrgs.members(s).then(Re=>d(Re.members)).catch(()=>{})}catch(Re){const We=Re instanceof Error?Re.message:"",Vt={"User not found":e("org.errorUserNotFound"),"User is already a member or has a pending invitation":e("org.errorAlreadyMember"),"An invitation has already been sent to this email":e("org.errorAlreadySent")};E({type:"err",text:Vt[We]??(We||e("org.errorInviteFailed"))})}finally{w(!1)}},fe=async je=>{if(s)try{await ie.hubOrgs.removeMember(s,je),d(Re=>Re.filter(We=>We.userId!==je))}catch(Re){E({type:"err",text:Re instanceof Error?Re.message:"Failed"})}},He=async je=>{try{await ie.hubOrgs.acceptInvitation(je),m(We=>We.filter(Vt=>Vt.orgId!==je));const Re=await ie.hubOrgs.mine();r(Re.orgs)}catch(Re){E({type:"err",text:Re instanceof Error?Re.message:"Failed"})}},Ae=async()=>{if(s)try{await ie.hubOrgs.leave(s),S(!1),r(je=>je.filter(Re=>Re.id!==s)),i(t.length>1?t.find(je=>je.id!==s).id:null)}catch(je){E({type:"err",text:je instanceof Error?je.message:"Failed"}),S(!1)}},et=async(je,Re)=>{if(s)try{await ie.hubOrgs.updateMemberRole(s,je,Re),d(We=>We.map(Vt=>Vt.userId===je?{...Vt,role:Re}:Vt)),E({type:"ok",text:e("org.roleUpdated")})}catch(We){E({type:"err",text:We instanceof Error?We.message:"Failed"})}},pe=async()=>{if(L.trim()){$(!0),q(null);try{await da()}catch{q({type:"err",text:e("license.activationFailed")}),$(!1);return}try{const je=await ie.license.activate(L.trim());je.success?(q({type:"ok",text:e("license.activated")}),O(""),Ce(!0)):q({type:"err",text:Se(je.error??e("license.activationFailed"))})}catch(je){q({type:"err",text:Se(je instanceof Error&&je.message||e("license.activationFailed"))})}finally{$(!1)}}},Fe=async()=>{$(!0),q(null);try{await da()}catch{q({type:"err",text:e("license.trialFailed")}),$(!1);return}try{const je=await ie.license.trial();je.success?(q({type:"ok",text:e("license.trialActivated")}),Ce(!0)):q({type:"err",text:Se(je.error??e("license.trialFailed"))})}catch(je){q({type:"err",text:Se(je instanceof Error&&je.message||e("license.trialFailed"))})}finally{$(!1)}},Ve=(je,Re)=>{navigator.clipboard.writeText(je).then(()=>{F(Re),setTimeout(()=>F(null),2e3)}).catch(()=>{})},nt=()=>{const Re=[[e("license.username"),D?.username],[e("license.userId",{defaultValue:"User ID"}),D?.hubUserId],[e("license.orgId",{defaultValue:"Org ID"}),D?.orgId],[e("license.licenseKey"),D?.licenseKey],[e("license.instanceId"),D?.instanceId]].filter(([,We])=>We).map(([We,Vt])=>`${We}: ${Vt}`).join(`
659
659
  `);Ve(Re,"allDetails")},gt=({label:je,value:Re})=>Re?n.jsxs("div",{className:"flex items-center gap-3 py-1.5",children:[n.jsx("span",{className:"text-xs text-fg-tertiary w-24 shrink-0",children:je}),n.jsx("code",{className:"text-xs text-fg-secondary font-mono bg-surface-primary/60 px-2 py-0.5 rounded select-all truncate max-w-[280px]",children:Re})]}):null,rt=D?.orgId||s,Et=[D?.username&&`Username: ${D.username}`,D?.hubUserId&&`User ID: ${D.hubUserId}`,rt&&`Org ID: ${rt}`,D?.instanceId&&`Instance ID: ${D.instanceId}`].filter(Boolean).join(`
660
660
  `);return R?n.jsx("div",{className:"text-center py-8 text-fg-tertiary text-sm",children:e("common:loading")}):t.length===0&&u.length===0?n.jsxs("div",{className:"space-y-6",children:[n.jsx(rj,{isEnterprise:D?.plan==="enterprise",licenseInfo:D,licenseOwnedBySelectedOrg:!0,daysRemaining:D?.validUntil?Math.max(0,Math.ceil((new Date(D.validUntil).getTime()-Date.now())/864e5)):null,effectiveValidUntil:D?.validUntil,effectiveMaxSeats:D?.maxSeats,effectiveUsedSeats:D?.usedSeats??0,effectiveOrgName:D?.orgName,featureKeys:ht,featureI18n:ne,t:e}),n.jsxs("div",{className:"text-center py-8 space-y-4",children:[n.jsx("div",{className:"text-3xl",children:"🏢"}),n.jsx("div",{className:"text-sm text-fg-tertiary",children:e("org.noOrg")}),n.jsxs("button",{disabled:z,onClick:()=>{E(null),B(!0),da().then(()=>Z(!0)).catch(je=>{const Re=je instanceof Error?je.message:String(je),We=Re.includes("Popup blocked")?e("org.popupBlocked"):Re.includes("cancelled")?e("org.loginCancelled"):Re;E({type:"err",text:We})}).finally(()=>B(!1))},className:"px-5 py-2.5 bg-brand-600 hover:bg-brand-500 disabled:opacity-60 text-white text-sm font-medium rounded-lg transition-colors inline-flex items-center gap-2",children:[z&&n.jsx("svg",{className:"w-4 h-4 animate-spin",viewBox:"0 0 24 24",fill:"none",children:n.jsx("circle",{cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"3",strokeDasharray:"30 70",strokeLinecap:"round"})}),e(z?"org.connecting":"org.connectHub")]}),T&&n.jsx("div",{className:`inline-block px-4 py-2 rounded-lg text-xs ${T.type==="ok"?"bg-green-500/10 text-green-600 border border-green-500/20":"bg-red-500/10 text-red-500 border border-red-500/20"}`,children:T.text})]})]}):n.jsxs("div",{className:"space-y-6",children:[(T||H)&&n.jsx("div",{className:"space-y-2",children:[T,H].filter(Boolean).map((je,Re)=>n.jsxs("div",{className:`flex items-center gap-2 text-sm px-4 py-3 rounded-lg ${je.type==="ok"?"bg-green-500/10 text-green-600 border border-green-500/20":"bg-red-500/10 text-red-500 border border-red-500/20"}`,children:[n.jsx("span",{children:je.type==="ok"?"✓":"✕"}),n.jsx("span",{children:je.text})]},Re))}),u.length>0&&n.jsx("div",{className:"space-y-2",children:u.map(je=>n.jsxs("div",{className:"flex items-center justify-between px-4 py-3 rounded-lg border border-amber-500/20 bg-amber-500/5",children:[n.jsxs("div",{className:"text-sm",children:[n.jsx("span",{className:"font-medium text-fg-primary",children:je.orgName}),n.jsxs("span",{className:"text-fg-tertiary ml-1",children:["— ",e("org.invitedBy")," ",je.invitedBy]})]}),n.jsx("button",{onClick:()=>{He(je.orgId)},className:"px-3 py-1.5 bg-brand-600 hover:bg-brand-500 text-white text-xs font-medium rounded-lg transition-colors",children:e("org.accept")})]},je.orgId))}),t.length>1&&n.jsxs("div",{className:"flex items-center gap-3",children:[n.jsx("span",{className:"text-sm text-fg-secondary whitespace-nowrap font-medium",children:e("org.switchOrg")}),n.jsx("select",{value:s??"",onChange:je=>i(je.target.value),className:"flex-1 px-3 py-2 rounded-lg border border-border-default bg-surface-elevated text-sm text-fg-primary",children:t.map(je=>n.jsxs("option",{value:je.id,children:[je.name," (",G(je.role),")"]},je.id))})]}),n.jsxs("div",{children:[n.jsxs("div",{className:"flex items-center mb-3",children:[n.jsx("h3",{className:"text-sm font-semibold text-fg-secondary uppercase tracking-wider",children:e("license.title")}),n.jsxs("button",{onClick:()=>Ce(!0),disabled:W,className:"ml-auto flex items-center gap-1.5 text-xs text-fg-tertiary hover:text-fg-secondary disabled:opacity-50 transition-colors",children:[n.jsx("svg",{className:`w-3.5 h-3.5 ${W?"animate-spin":""}`,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:n.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M4 4v5h5M20 20v-5h-5M4.05 11A8 8 0 0119.95 9M19.95 13A8 8 0 014.05 15"})}),e("license.refresh")]})]}),n.jsxs("div",{className:"space-y-4",children:[n.jsx(rj,{isEnterprise:he,licenseInfo:D,licenseOwnedBySelectedOrg:_e,daysRemaining:it,effectiveValidUntil:Ye,effectiveMaxSeats:Ze,effectiveUsedSeats:mt,effectiveOrgName:_?.name??D?.orgName,hubMemberCount:_?.memberCount,featureKeys:ht,featureI18n:ne,t:e}),he?n.jsxs(n.Fragment,{children:[Lt&&n.jsxs("div",{className:`px-4 py-3 rounded-lg border ${it===0?"bg-red-500/8 border-red-500/15 text-red-600":it<=7?"bg-amber-500/8 border-amber-500/15 text-amber-600":"bg-amber-500/5 border-amber-500/10 text-amber-600"}`,children:[n.jsx("div",{className:"text-sm font-medium",children:it===0?e("license.expiredWarning"):e("license.renewalWarning",{count:it})}),n.jsx("div",{className:"text-[11px] mt-1 opacity-75",children:e("license.renewalHint")}),n.jsxs("div",{className:"flex gap-2 mt-3",children:[n.jsx("input",{type:"text",value:L,onChange:je=>O(je.target.value),onKeyDown:je=>je.key==="Enter"&&pe(),placeholder:e("license.keyPlaceholder"),className:"flex-1 px-3 py-1.5 bg-surface-primary border border-border-default rounded-lg text-sm text-fg-primary focus:border-brand-500 outline-none transition-colors placeholder:text-fg-tertiary font-mono"}),n.jsx("button",{onClick:pe,disabled:M||!L.trim(),className:"px-4 py-1.5 bg-brand-600 hover:bg-brand-500 disabled:opacity-50 text-white text-sm font-medium rounded-lg transition-all whitespace-nowrap",children:e("license.renew")})]})]}),Ee?n.jsx(n.Fragment,{children:n.jsxs("div",{className:"rounded-lg border border-border-default",children:[n.jsxs("div",{className:"px-5 py-3 border-b border-border-default/50 flex items-center justify-between",children:[n.jsx("span",{className:"text-xs font-medium text-fg-secondary uppercase tracking-wider",children:e("license.details")}),n.jsx("button",{onClick:nt,className:"text-xs text-fg-tertiary hover:text-fg-secondary transition-colors flex items-center gap-1",children:Y==="allDetails"?"✓ "+e("license.copied"):"⧉ "+e("license.copyInfo")})]}),n.jsxs("div",{className:"px-5 py-2 divide-y divide-border-default/30",children:[n.jsx(gt,{label:e("license.username"),value:D?.username}),D?.hubUserId&&n.jsx(gt,{label:e("license.userId",{defaultValue:"User ID"}),value:D.hubUserId}),D?.orgId&&n.jsx(gt,{label:e("license.orgId",{defaultValue:"Org ID"}),value:D.orgId}),n.jsx(gt,{label:e("license.licenseKey"),value:D?.licenseKey}),n.jsx(gt,{label:e("license.instanceId"),value:D?.instanceId})]})]})}):n.jsx("div",{className:"px-4 py-3 rounded-lg bg-surface-elevated border border-border-default/50 text-xs text-fg-tertiary",children:e("license.notOwnedHint")})]}):n.jsxs(n.Fragment,{children:[n.jsxs("button",{onClick:Fe,disabled:M,className:"w-full flex items-center justify-between px-5 py-4 rounded-lg border border-brand-500/20 bg-brand-600/5 hover:bg-brand-600/10 transition-all text-left disabled:opacity-50",children:[n.jsxs("div",{children:[n.jsx("div",{className:"text-sm font-semibold text-fg-primary",children:e("license.tryEnterprise")}),n.jsx("div",{className:"text-[11px] text-fg-tertiary mt-0.5",children:e("license.trialDesc")})]}),n.jsx("span",{className:"text-brand-500 text-lg shrink-0 ml-4",children:"→"})]}),n.jsxs("div",{className:"rounded-lg border border-border-default p-5",children:[n.jsx("div",{className:"text-sm font-medium text-fg-primary",children:e("license.upgrade")}),n.jsx("div",{className:"text-[11px] text-fg-tertiary mt-1",children:e("license.activateDesc")}),n.jsxs("div",{className:"flex gap-2 mt-3",children:[n.jsx("input",{type:"text",value:L,onChange:je=>O(je.target.value),onKeyDown:je=>je.key==="Enter"&&pe(),placeholder:e("license.keyPlaceholder"),className:"flex-1 px-3 py-2 bg-surface-primary border border-border-default rounded-lg text-sm text-fg-primary focus:border-brand-500 outline-none transition-colors placeholder:text-fg-tertiary font-mono"}),n.jsx("button",{onClick:pe,disabled:M||!L.trim(),className:"px-4 py-2 bg-brand-600 hover:bg-brand-500 disabled:opacity-50 text-white text-sm font-medium rounded-lg transition-all whitespace-nowrap",children:e("license.activate")})]})]}),n.jsxs("div",{className:"rounded-lg border border-border-default p-5",children:[n.jsx("div",{className:"text-sm font-medium text-fg-primary",children:e("license.contactSales")}),n.jsx("div",{className:"text-[11px] text-fg-tertiary mt-1 mb-3",children:e("license.contactSalesDesc",{email:e("license.salesEmail")})}),Et&&n.jsxs("div",{className:"flex gap-2 items-start",children:[n.jsxs("div",{className:"relative flex-1",children:[n.jsx("pre",{className:"text-[11px] text-fg-secondary font-mono bg-surface-primary border border-border-default/50 rounded-lg px-3 py-2.5 leading-relaxed select-all whitespace-pre-wrap",children:Et}),n.jsx("button",{onClick:()=>Ve(Et,"salesInfo"),className:"absolute top-1.5 right-1.5 text-xs text-fg-tertiary hover:text-fg-secondary transition-colors bg-surface-primary/90 border border-border-default/50 px-2 py-1 rounded-md",children:Y==="salesInfo"?"✓ "+e("license.copied"):e("license.copyInfo")})]}),n.jsx("a",{href:`mailto:${e("license.salesEmail")}?subject=Enterprise%20License%20Request&body=${encodeURIComponent(Et)}`,className:"shrink-0 inline-flex items-center gap-1.5 px-4 py-2 bg-brand-600 hover:bg-brand-500 text-white text-sm font-medium rounded-lg transition-all no-underline whitespace-nowrap",children:e("license.emailSales")})]})]})]})]})]}),_&&n.jsxs("div",{children:[n.jsx("h3",{className:"text-sm font-semibold text-fg-secondary uppercase tracking-wider mb-3",children:e("org.title")}),n.jsxs("div",{className:"space-y-4",children:[n.jsxs("div",{className:"rounded-lg border border-border-default p-5 space-y-4",children:[n.jsxs("div",{className:"space-y-2",children:[n.jsx("label",{className:"text-xs text-fg-tertiary font-medium",children:e("org.nameLabel")}),J?n.jsxs("div",{className:"flex gap-2",children:[n.jsx("input",{value:h,onChange:je=>p(je.target.value),className:"flex-1 px-3 py-2 bg-surface-elevated border border-border-default rounded-lg text-sm text-fg-primary"}),n.jsx("button",{onClick:()=>{me()},disabled:h===_.name||!h.trim(),className:"px-3 py-2 bg-brand-600 hover:bg-brand-500 disabled:opacity-40 text-white text-xs rounded-lg transition-colors",children:e("common:save")})]}):n.jsx("div",{className:"text-sm text-fg-primary",children:_.name})]}),n.jsxs("div",{className:"flex items-center justify-between text-xs",children:[n.jsx("span",{className:"text-fg-tertiary",children:e("org.orgId")}),n.jsx("code",{className:"px-1.5 py-0.5 rounded bg-surface-elevated text-fg-secondary",children:_.id})]})]}),n.jsxs("div",{className:"rounded-lg border border-border-default overflow-hidden",children:[n.jsx("div",{className:"px-5 py-3 flex items-center justify-between",style:{borderBottom:"1px solid var(--border-default, #e5e7eb)"},children:n.jsxs("h3",{className:"text-sm font-medium text-fg-primary",children:[e("org.members")," (",l.filter(je=>je.status==="active").length,")"]})}),n.jsxs("div",{className:"divide-y divide-border-default",children:[l.map(je=>n.jsxs("div",{className:"flex items-center justify-between px-5 py-3",children:[n.jsxs("div",{className:"flex items-center gap-3",children:[je.avatarUrl?n.jsx("img",{src:je.avatarUrl,alt:"",className:"w-8 h-8 rounded-full object-cover"}):n.jsx("div",{className:"w-8 h-8 rounded-full bg-brand-600/20 flex items-center justify-center text-xs font-bold text-brand-500",children:(je.displayName??je.username)?.[0]?.toUpperCase()}),n.jsxs("div",{children:[n.jsx("div",{className:"text-sm font-medium text-fg-primary",children:je.displayName??je.username}),n.jsxs("div",{className:"text-[11px] text-fg-tertiary",children:["@",je.username,je.status==="pending"?` (${e("org.pending")})`:""]})]})]}),n.jsxs("div",{className:"flex items-center gap-2",children:[J&&je.role!=="owner"?n.jsxs("select",{value:je.role,onChange:Re=>{et(je.userId,Re.target.value)},className:"px-2 py-1 rounded border border-border-default bg-surface-elevated text-xs text-fg-secondary",children:[n.jsx("option",{value:"admin",children:e("org.roleAdmin")}),n.jsx("option",{value:"member",children:e("org.roleMember")})]}):n.jsx("span",{className:"text-xs text-fg-tertiary",children:G(je.role)}),J&&je.role!=="owner"&&n.jsx("button",{onClick:()=>{fe(je.userId)},className:"text-xs text-red-500 hover:text-red-400 transition-colors",children:e("org.remove")})]})]},je.id)),l.length===0&&n.jsx("div",{className:"px-5 py-6 text-center text-xs text-fg-tertiary",children:e("org.noMembers")})]})]}),ee&&n.jsxs("div",{className:"rounded-lg border border-border-default p-5 space-y-3",children:[n.jsx("label",{className:"text-xs text-fg-tertiary font-medium",children:e("org.inviteLabel")}),be?n.jsx("p",{className:"text-xs text-amber-500",children:e("org.seatsFullHint")}):n.jsxs("div",{className:"flex gap-2",children:[n.jsx("input",{value:y,onChange:je=>x(je.target.value),type:"email",placeholder:e("org.invitePlaceholder"),className:"flex-1 px-3 py-2 bg-surface-elevated border border-border-default rounded-lg text-sm text-fg-primary placeholder:text-fg-quaternary",onKeyDown:je=>{je.key==="Enter"&&se()}}),n.jsxs("select",{value:v,onChange:je=>j(je.target.value),className:"px-2 py-2 rounded-lg border border-border-default bg-surface-elevated text-xs text-fg-secondary",children:[n.jsx("option",{value:"member",children:e("org.roleMember")}),n.jsx("option",{value:"admin",children:e("org.roleAdmin")})]}),n.jsx("button",{onClick:()=>{se()},disabled:C||!y.trim(),className:"px-4 py-2 bg-brand-600 hover:bg-brand-500 disabled:opacity-40 text-white text-xs font-medium rounded-lg transition-colors",children:e(C?"common:saving":"org.invite")})]})]}),!J&&n.jsx("button",{onClick:()=>S(!0),className:"text-xs text-red-500 hover:text-red-400 transition-colors border border-red-500/30 rounded-lg px-3 py-1.5 hover:bg-red-500/5",children:e("org.leave")})]})]}),N&&n.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm",onClick:()=>S(!1),children:n.jsxs("div",{className:"bg-surface-secondary border border-border-default rounded-2xl max-w-sm w-full mx-4 p-6 shadow-2xl",onClick:je=>je.stopPropagation(),children:[n.jsxs("div",{className:"flex items-start gap-3 mb-4",children:[n.jsx("span",{className:"flex items-center justify-center w-10 h-10 rounded-xl bg-red-500/10 text-red-500 shrink-0",children:n.jsxs("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("path",{d:"M10.29 3.86L1.82 18a2 2 0 001.71 3h16.94a2 2 0 001.71-3L13.71 3.86a2 2 0 00-3.42 0z"}),n.jsx("line",{x1:"12",y1:"9",x2:"12",y2:"13"}),n.jsx("line",{x1:"12",y1:"17",x2:"12.01",y2:"17"})]})}),n.jsxs("div",{children:[n.jsx("h3",{className:"text-base font-semibold text-fg-primary",children:e("org.leaveConfirmTitle")}),n.jsx("p",{className:"text-sm text-fg-secondary mt-1",children:e("org.leaveConfirmMsg",{name:_?.name??""})})]})]}),n.jsxs("div",{className:"flex justify-end gap-2.5 pt-2 border-t border-border-default",children:[n.jsx("button",{onClick:()=>S(!1),className:"px-4 py-2 text-xs font-medium rounded-lg border border-border-default text-fg-secondary hover:bg-surface-elevated transition-colors",children:e("org.leaveCancel")}),n.jsx("button",{onClick:()=>{Ae()},className:"px-4 py-2 text-xs font-medium rounded-lg bg-red-600 hover:bg-red-500 text-white shadow-sm shadow-red-600/20 transition-colors",children:e("org.leaveConfirmBtn")})]})]})}),n.jsxs("div",{className:"flex items-center gap-4 text-[11px] text-fg-tertiary pt-1",children:[n.jsx("a",{href:"https://markus.global",target:"_blank",rel:"noopener noreferrer",className:"hover:text-fg-secondary transition-colors",children:e("license.website")}),n.jsx("a",{href:`mailto:${e("license.salesEmail")}`,className:"hover:text-fg-secondary transition-colors",children:e("license.salesEmail")})]})]})}function rj({isEnterprise:e,licenseInfo:t,licenseOwnedBySelectedOrg:r,daysRemaining:s,effectiveValidUntil:a,effectiveMaxSeats:i,effectiveUsedSeats:l,effectiveOrgName:d,hubMemberCount:u,featureKeys:m,featureI18n:h,t:p}){const y=u??t?.usage?.users??0;return e?n.jsx("div",{className:"rounded-lg border border-brand-500/20 overflow-hidden",children:n.jsxs("div",{className:"px-5 py-4 bg-gradient-to-r from-brand-600/5 to-transparent",children:[n.jsxs("div",{className:"flex items-center justify-between",children:[n.jsxs("div",{className:"flex items-center gap-2.5",children:[n.jsx("span",{className:"text-base font-semibold text-fg-primary",children:p("license.planEnterprise")}),n.jsx("span",{className:"px-1.5 py-0.5 rounded text-[10px] font-medium bg-green-500/12 text-green-600 border border-green-500/15",children:p("license.statusActive")}),r&&t?.isTrial&&n.jsx("span",{className:"px-1.5 py-0.5 rounded text-[10px] font-medium bg-amber-500/12 text-amber-600 border border-amber-500/15",children:p("license.trial")}),r&&t?.isOffline&&n.jsx("span",{className:"px-1.5 py-0.5 rounded text-[10px] font-medium bg-cyan-500/12 text-cyan-600 border border-cyan-500/15",children:p("license.offline")})]}),s!==null&&n.jsxs("div",{className:"text-right",children:[n.jsx("div",{className:`text-sm font-semibold tabular-nums ${s===0?"text-red-500":s<=7?"text-amber-500":s<=60?"text-amber-600":"text-fg-primary"}`,children:s>0?p("license.daysRemaining",{count:s}):p("license.expired")}),n.jsx("div",{className:"text-[11px] text-fg-tertiary mt-0.5",children:p("license.expiresOn",{date:new Date(a).toLocaleDateString()})})]})]}),n.jsxs("div",{className:"mt-4 grid grid-cols-3 gap-px rounded-lg overflow-hidden border border-border-default/50",children:[n.jsxs("div",{className:"bg-surface-primary/40 px-3 py-2.5 text-center",children:[n.jsxs("div",{className:"text-sm font-semibold text-fg-primary tabular-nums",children:[t?.usage?.teams??0," ",n.jsx("span",{className:"text-fg-tertiary font-normal",children:"/ ∞"})]}),n.jsx("div",{className:"text-[10px] text-fg-tertiary mt-0.5",children:p("license.limitTeams")})]}),n.jsxs("div",{className:"bg-surface-primary/40 px-3 py-2.5 text-center",children:[n.jsxs("div",{className:"text-sm font-semibold text-fg-primary tabular-nums",children:[t?.usage?.toolCallsToday??0," ",n.jsx("span",{className:"text-fg-tertiary font-normal",children:"/ ∞"})]}),n.jsxs("div",{className:"text-[10px] text-fg-tertiary mt-0.5",children:[p("license.limitToolCalls"),p("license.perDay")]})]}),n.jsxs("div",{className:"bg-surface-primary/40 px-3 py-2.5 text-center",children:[n.jsxs("div",{className:"text-sm font-semibold text-fg-primary tabular-nums",children:[y," ",n.jsxs("span",{className:"text-fg-tertiary font-normal",children:["/ ",i??"∞"]})]}),n.jsx("div",{className:"text-[10px] text-fg-tertiary mt-0.5",children:p("license.limitUsers")})]})]}),n.jsx("div",{className:"mt-3 flex flex-wrap gap-1.5",children:m.map(x=>n.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-0.5 rounded text-[10px] font-medium text-brand-500 bg-brand-600/6 border border-brand-500/10",children:[fY[x]," ",h[x]]},x))}),d&&n.jsxs("div",{className:"mt-3 grid grid-cols-2 gap-3 text-xs",children:[n.jsxs("div",{className:"flex items-center justify-between px-3 py-2 rounded-lg bg-surface-primary/40 border border-border-default/30",children:[n.jsx("span",{className:"text-fg-tertiary",children:p("license.organization")}),n.jsx("span",{className:"font-medium text-fg-primary",children:d})]}),i!=null&&n.jsxs("div",{className:"flex items-center justify-between px-3 py-2 rounded-lg bg-surface-primary/40 border border-border-default/30",children:[n.jsx("span",{className:"text-fg-tertiary",children:p("license.seats")}),n.jsxs("span",{className:"font-medium text-fg-primary",children:[l," / ",i]})]})]})]})}):n.jsx("div",{className:"rounded-lg border border-border-default",children:n.jsxs("div",{className:"px-5 py-4",children:[n.jsxs("div",{className:"flex items-center gap-2.5",children:[n.jsx("span",{className:"text-base font-semibold text-fg-primary",children:p("license.planFree")}),n.jsx("span",{className:"text-[11px] text-fg-tertiary",children:p("license.freeFeaturesDesc")})]}),n.jsxs("div",{className:"mt-3 grid grid-cols-3 gap-px rounded-lg overflow-hidden border border-border-default/50",children:[n.jsxs("div",{className:"bg-surface-primary/40 px-3 py-2.5 text-center",children:[n.jsxs("div",{className:"text-lg font-semibold text-fg-primary tabular-nums",children:[t?.usage?.teams??0," ",n.jsx("span",{className:"text-fg-tertiary font-normal text-xs",children:"/ 1"})]}),n.jsx("div",{className:"text-[10px] text-fg-tertiary mt-0.5",children:p("license.limitTeams")})]}),n.jsxs("div",{className:"bg-surface-primary/40 px-3 py-2.5 text-center",children:[n.jsxs("div",{className:"text-lg font-semibold text-fg-primary tabular-nums",children:[t?.usage?.toolCallsToday??0," ",n.jsx("span",{className:"text-fg-tertiary font-normal text-xs",children:"/ 500"})]}),n.jsxs("div",{className:"text-[10px] text-fg-tertiary mt-0.5",children:[p("license.limitToolCalls"),p("license.perDay")]})]}),n.jsxs("div",{className:"bg-surface-primary/40 px-3 py-2.5 text-center",children:[n.jsxs("div",{className:"text-lg font-semibold text-fg-primary tabular-nums",children:[y," ",n.jsx("span",{className:"text-fg-tertiary font-normal text-xs",children:"/ 1"})]}),n.jsx("div",{className:"text-[10px] text-fg-tertiary mt-0.5",children:p("license.limitUsers")})]})]})]})})}const uh=new Map;function Xl(e,t){uh.has(e)||uh.set(e,t().catch(()=>{}))}function rc(e){const t=uh.get(e);return uh.delete(e),t}const La={builderArtifacts:"builder.artifacts",builderAgents:"builder.agents",builderHubMyItems:"builder.hubMyItems",builderInstalled:"builder.installed",hubAgents:"hub.agents",hubTeams:"hub.teams",hubSkills:"hub.skills"};function gY(e){const t=e.indexOf(".markus/builder-artifacts/");return t>=0?"~/"+e.slice(t):e}const xY=[{id:"hireAgent",icon:"✦",color:"from-brand-500 to-purple-600",borderColor:"border-brand-500/30 hover:border-brand-400/50",bgColor:"bg-brand-500/10"},{id:"buildTeam",icon:"◈",color:"from-blue-500 to-blue-600",borderColor:"border-blue-500/30 hover:border-blue-400/50",bgColor:"bg-blue-500/10"},{id:"createSkill",icon:"⬡",color:"from-green-500 to-green-600",borderColor:"border-green-500/30 hover:border-green-400/50",bgColor:"bg-green-500/10"}],sj={agent:{icon:"✦",color:"text-brand-500",bg:"bg-brand-500/10"},team:{icon:"◈",color:"text-blue-600",bg:"bg-blue-500/10"},skill:{icon:"⬡",color:"text-green-600",bg:"bg-green-500/10"}};function aj({title:e,message:t,cancelLabel:r,confirmLabel:s,onConfirm:a,onCancel:i}){return n.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60",onClick:i,children:n.jsxs("div",{className:"bg-surface-secondary border border-border-default rounded-xl p-6 max-w-sm mx-4 shadow-2xl",onClick:l=>l.stopPropagation(),children:[n.jsxs("div",{className:"flex items-center gap-3 mb-4",children:[n.jsx("div",{className:"w-10 h-10 rounded-full bg-red-500/15 flex items-center justify-center shrink-0",children:n.jsxs("svg",{className:"w-5 h-5 text-red-500",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("circle",{cx:"12",cy:"12",r:"10"}),n.jsx("line",{x1:"15",y1:"9",x2:"9",y2:"15"}),n.jsx("line",{x1:"9",y1:"9",x2:"15",y2:"15"})]})}),n.jsxs("div",{children:[n.jsx("div",{className:"text-sm font-medium text-fg-primary",children:e}),n.jsx("div",{className:"text-xs text-fg-secondary mt-0.5",children:t})]})]}),n.jsxs("div",{className:"flex justify-end gap-2",children:[n.jsx("button",{onClick:i,className:"px-4 py-1.5 text-xs text-fg-secondary hover:text-fg-primary border border-border-default hover:border-gray-600 rounded-lg transition-colors",children:r}),n.jsx("button",{onClick:a,className:"px-4 py-1.5 text-xs bg-red-600 hover:bg-red-500 text-white rounded-lg transition-colors",children:s})]})]})})}function bY(){const[e,t]=g.useState(()=>{const s=window.location.hash.slice(1).split("/");return s[0]==="builder"&&s[1]&&s[2]?{type:s[1],name:decodeURIComponent(s[2])}:null});return g.useEffect(()=>{const r=()=>{const a=window.location.hash.slice(1).split("/");a[0]==="builder"&&a[1]&&a[2]?t({type:a[1],name:decodeURIComponent(a[2])}):t(null)};return window.addEventListener("hashchange",r),()=>window.removeEventListener("hashchange",r)},[]),e}function e7({authUser:e}={}){const{t}=pt(["builder","common"]),r=Rs(),s=bY(),[a,i]=g.useState([]),[l,d]=g.useState([]),[u,m]=g.useState(!1),[h,p]=g.useState("all"),[y,x]=g.useState(null),[v,j]=g.useState(new Map),[C,w]=g.useState(null),[N,S]=g.useState(new Map),[T,E]=g.useState(null),[R,I]=g.useState(null),[z,B]=g.useState(null),D=g.useCallback(()=>{m(!0),Promise.all([(rc(La.builderArtifacts)??ie.builder.artifacts.list()).then(U=>U?.artifacts??[]).catch(()=>[]),(rc(La.builderAgents)??ie.agents.list()).then(U=>U?.agents??[]).catch(()=>[]),(rc(La.builderHubMyItems)??Wn.myItems()).then(U=>U?.items??[]).catch(()=>[]),(rc(La.builderInstalled)??ie.builder.artifacts.installed()).then(U=>U?.installed??{}).catch(()=>({}))]).then(([U,H,q,Z])=>{if(d(U),i(H),q.length>0){const J=new Map;for(const X of q){const ee=X.itemType==="agent"?"agent":X.itemType==="team"?"team":"skill";for(const te of U)te.type===ee&&(X.slug===te.name||X.name===(te.meta.displayName||te.meta.name||te.name))&&J.set(`${te.type}/${te.name}`,{id:X.id,name:X.name,slug:X.slug||te.name,version:X.version||"1.0.0"})}J.size>0&&S(X=>{const ee=new Map(X);for(const[te,G]of J)ee.set(te,G);return ee})}const _=new Map;for(const J of U){const X=`${J.type}/${J.name}`,ee=Z[X];ee&&_.set(X,{agentId:ee.agentId,agentIds:ee.agentIds,teamId:ee.teamId})}j(_)}).finally(()=>m(!1))},[]);g.useEffect(()=>{D();const U=H=>{H.detail?.page===De.BUILDER&&D()};return window.addEventListener("markus:navigate",U),()=>window.removeEventListener("markus:navigate",U)},[D]);const V=U=>{const H=a.find(q=>q.role==="Secretary"||q.name==="Secretary");H?bt.navigate(De.TEAM,{agentId:H.id,prefillMessage:U}):bt.navigate(De.TEAM,{prefillMessage:U})},Y=async U=>{const H=`${U.type}/${U.name}`;if(!v.has(H)){x({key:H,action:"install"});try{const q=await ie.builder.artifacts.install(U.type,U.name),Z={};q.agent&&typeof q.agent=="object"&&(Z.agentId=q.agent.id),q.team&&typeof q.team=="object"&&(Z.teamId=q.team.id),Array.isArray(q.agents)&&(Z.agentIds=q.agents.map(_=>_.id)),j(_=>new Map(_).set(H,Z)),window.dispatchEvent(new CustomEvent("markus:data-changed"))}catch(q){console.error("Install failed:",q),alert(t("installFailed",{error:String(q)}))}finally{x(null)}}},F=async U=>{const H=`${U.type}/${U.name}`;if(v.has(H)){x({key:H,action:"uninstall"});try{await ie.builder.artifacts.uninstall(U.type,U.name),j(q=>{const Z=new Map(q);return Z.delete(H),Z}),window.dispatchEvent(new CustomEvent("markus:data-changed"))}catch(q){console.error("Uninstall failed:",q),alert(t("uninstallFailed",{error:String(q)}))}finally{x(null)}}},L=async(U,H)=>{const q=`${U.type}/${U.name}`;x({key:q,action:"share"});try{const Z=await ie.builder.artifacts.get(U.type,U.name),_=U.meta.displayName||U.meta.name||U.name,J=U.meta.description||"",X=U.meta.category||"general",ee=Array.isArray(U.meta.tags)?U.meta.tags:[],te=U.name;let G=U.meta.icon||void 0;const ue=U.meta.version||"1.0.0";if(G&&!G.startsWith("http")&&/\.(png|jpe?g|gif|webp|svg)$/i.test(G)){const he=G.split("/").pop()??G;try{const _e=await fetch(`/api/builder/artifacts/${U.type}s/${encodeURIComponent(U.name)}/images/${encodeURIComponent(he)}`);if(_e.ok){const Ee=await _e.blob(),Ye=new File([Ee],he,{type:Ee.type}),Ze=await Wn.uploadImage(Ye);Ze?.url&&(G=Ze.url)}}catch{}}let Se;const Ce=[],Be=Array.isArray(U.meta.screenshots)?U.meta.screenshots:[];for(let he=0;he<Be.length;he++){const _e=Be[he],Ee=_e.split("/").pop()??_e;try{const Ye=await fetch(`/api/builder/artifacts/${U.type}s/${encodeURIComponent(U.name)}/images/${encodeURIComponent(Ee)}`);if(Ye.ok){const Ze=await Ye.blob(),mt=new File([Ze],Ee,{type:Ze.type}),it=await Wn.uploadImage(mt);it?.url&&(Ce.push({url:it.url,alt:Ee,order:he}),(he===0||U.meta.thumbnail===_e)&&(Se=it.url))}}catch{}}const Ne=await Wn.publishViaProxy({itemType:U.type==="team"?"team":U.type==="skill"?"skill":"agent",name:_,slug:te,description:J,category:X,tags:ee,icon:G,version:ue,config:U.meta,files:Z.files&&Object.keys(Z.files).length>0?Z.files:void 0,thumbnailUrl:Se,images:Ce.length>0?Ce:void 0,priceCents:H?.priceCents,donationsEnabled:H?.donationsEnabled});Ne.id&&S(he=>{const _e=new Map(he);return _e.set(q,{id:Ne.id,name:_,slug:Ne.slug??te,version:ue}),_e})}catch(Z){console.error("Share failed:",Z),alert(t("shareFailed",{error:String(Z)}))}finally{x(null)}},O=async()=>{if(!T)return;const{key:U}=T,H=N.get(U);if(E(null),!H)return;const q=H.id;x({key:U,action:"hubDelete"});try{await Wn.deleteItem(q),S(Z=>{const _=new Map(Z);return _.delete(U),_})}catch(Z){console.error("Hub delete failed:",Z),alert(t("hubDeleteFailed",{error:String(Z)}))}finally{x(null)}},M=async()=>{if(!C)return;const U=C,H=`${U.type}/${U.name}`;w(null),x({key:H,action:"delete"});try{await ie.builder.artifacts.delete(U.type,U.name),d(q=>q.filter(Z=>!(Z.type===U.type&&Z.name===U.name))),j(q=>{const Z=new Map(q);return Z.delete(H),Z}),window.dispatchEvent(new CustomEvent("markus:data-changed"))}catch(q){console.error("Delete failed:",q)}finally{x(null)}},$=h==="all"?l:l.filter(U=>U.type===h),W=U=>{history.pushState(null,"",`#builder/${U.type}/${encodeURIComponent(U.name)}`),window.dispatchEvent(new HashChangeEvent("hashchange"))};return s?n.jsx(uc,{type:s.type,name:s.name,authUser:e,onBack:()=>{history.pushState(null,"","#builder"),window.dispatchEvent(new HashChangeEvent("hashchange"))}}):n.jsx("div",{className:"flex-1 overflow-y-auto",children:n.jsxs("div",{className:`max-w-5xl mx-auto w-full ${r?"px-4 py-5":"px-6 py-6"}`,children:[n.jsxs("div",{className:"mb-6",children:[n.jsxs("div",{className:"flex items-center justify-between mb-4",children:[n.jsxs("div",{children:[n.jsx("h1",{className:"text-xl font-bold text-fg-primary",children:t("title")}),n.jsx("p",{className:"text-xs text-fg-tertiary mt-1",children:t("subtitle")})]}),n.jsx("button",{onClick:D,className:"text-xs text-fg-tertiary hover:text-fg-secondary transition-colors px-3 py-1.5 rounded-lg border border-border-default hover:border-gray-600",children:t("common:refresh")})]}),n.jsx("div",{className:`grid ${r?"grid-cols-1 gap-2":"grid-cols-3 gap-3"}`,children:xY.map(U=>{const H=t(`prompts.${U.id}Prompt`),q=t(`prompts.${U.id}Examples`,{returnObjects:!0}),Z=Array.isArray(q)?q:[];return n.jsx("button",{onClick:()=>V(H),className:`group text-left w-full rounded-xl border ${U.borderColor} bg-surface-secondary/60 p-4 transition-all hover:bg-surface-secondary/80 hover:shadow-lg`,children:n.jsxs("div",{className:"flex items-start gap-3",children:[n.jsx("div",{className:`w-10 h-10 text-xl rounded-lg ${U.bgColor} flex items-center justify-center shrink-0`,children:U.icon}),n.jsxs("div",{className:"flex-1 min-w-0",children:[n.jsx("h3",{className:`text-sm font-semibold bg-gradient-to-r ${U.color} bg-clip-text text-transparent`,children:t(`prompts.${U.id}`)}),n.jsx("p",{className:"text-[11px] text-fg-tertiary mt-1 leading-relaxed",children:t(`prompts.${U.id}Desc`)}),Z.length>0&&n.jsx("div",{className:"mt-2 flex flex-wrap gap-1.5",children:Z.slice(0,2).map((_,J)=>n.jsxs("span",{className:"text-[10px] text-fg-muted bg-surface-elevated/60 rounded-full px-2 py-0.5 border border-border-default",onClick:X=>{X.stopPropagation(),V(H+_)},children:["“",_,"”"]},J))})]})]})},U.id)})})]}),n.jsx("div",{className:"mb-3",children:n.jsxs("div",{className:"flex items-center justify-between",children:[n.jsx("h2",{className:"text-sm font-semibold text-fg-secondary",children:t("myCreations.title")}),n.jsx("div",{className:"flex gap-1.5",children:["all","agent","team","skill"].map(U=>n.jsx("button",{onClick:()=>p(U),className:`text-xs px-2.5 py-1 rounded-lg transition-colors ${h===U?"bg-brand-600 text-white":"text-fg-tertiary hover:text-fg-secondary hover:bg-surface-elevated"}`,children:t(U==="all"?"myCreations.filterAll":U==="agent"?"myCreations.filterAgents":U==="team"?"myCreations.filterTeams":"myCreations.filterSkills")},U))})]})}),u&&l.length===0?n.jsx("div",{className:"text-center text-fg-tertiary py-12 text-sm",children:t("myCreations.loadingArtifacts")}):$.length===0?n.jsxs("div",{className:"text-center py-12",children:[n.jsx("div",{className:"text-fg-tertiary text-sm",children:t("myCreations.noArtifacts")}),n.jsx("div",{className:"text-fg-muted text-xs mt-1",children:t("myCreations.noArtifactsHint")})]}):n.jsx("div",{className:"grid gap-3",children:$.map(U=>{const H=sj[U.type]??sj.agent,q=U.meta.displayName||U.meta.name||U.name,Z=U.meta.description||"",_=`${U.type}/${U.name}`,J=y?.key===_?y.action:null,X=N.get(_),ee=U.meta.version||"1.0.0",te=!!X,G=te&&X.version!==ee,ue=()=>{const Ce=Wn.getUser();return!X||!Ce?null:`${Wn.getUrl()}/@${encodeURIComponent(Ce.username)}/${encodeURIComponent(X.slug)}`},Se=n.jsxs("div",{className:`flex items-center gap-1.5 ${r?"flex-wrap":"shrink-0"}`,onClick:Ce=>Ce.stopPropagation(),children:[v.has(_)?n.jsx("button",{onClick:()=>F(U),disabled:!!J,className:"text-xs px-3 py-1.5 rounded-lg border border-green-600/30 text-green-600 hover:bg-red-500/10 hover:text-red-500 hover:border-red-500/30 transition-colors disabled:opacity-50",children:t(J==="uninstall"?"common:uninstalling":"common:uninstall")}):n.jsx("button",{onClick:()=>Y(U),disabled:!!J,className:"text-xs px-3 py-1.5 rounded-lg bg-brand-600 hover:bg-brand-500 text-white transition-colors disabled:opacity-50",children:t(J==="install"?"common:installing":"common:install")}),te&&G?n.jsx("button",{onClick:()=>B(U),disabled:!!J,className:"text-xs px-3 py-1.5 rounded-lg border border-amber-500/30 text-amber-400 hover:bg-amber-500/10 hover:border-amber-500/50 transition-colors disabled:opacity-50",children:J==="share"?t("common:sharing"):t("share.updateVersion",{version:ee})}):te?n.jsxs("div",{className:"flex items-center gap-1",children:[n.jsxs("a",{href:ue()??"#",target:"_blank",rel:"noopener noreferrer",className:"text-xs px-3 py-1.5 rounded-lg border border-green-600/30 text-green-600 hover:text-green-500 hover:border-green-500/40 transition-colors inline-flex items-center gap-1",children:[n.jsxs("svg",{className:"w-3 h-3",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("path",{d:"M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"}),n.jsx("polyline",{points:"15 3 21 3 21 9"}),n.jsx("line",{x1:"10",y1:"14",x2:"21",y2:"3"})]}),t("common:shared")]}),n.jsx("button",{onClick:()=>E({key:_,name:q}),disabled:!!J,className:"text-xs px-1.5 py-1.5 rounded-lg text-fg-tertiary hover:text-red-500 hover:bg-red-500/10 transition-colors disabled:opacity-50",title:t("removeFromHubTooltip"),children:n.jsxs("svg",{className:"w-3.5 h-3.5",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("polyline",{points:"3 6 5 6 21 6"}),n.jsx("path",{d:"M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"})]})})]}):n.jsx("button",{onClick:async()=>{await Wn.ensureAuth(),Array.isArray(U.meta.screenshots)&&U.meta.screenshots.length>0?L(U):I(U)},disabled:!!J,className:"text-xs px-3 py-1.5 rounded-lg border border-border-default text-fg-secondary hover:text-green-600 hover:border-green-500/30 transition-colors disabled:opacity-50",children:t(J==="share"?"common:sharing":"common:share")}),n.jsx("button",{onClick:()=>w(U),disabled:!!J,className:"text-xs px-2 py-1.5 rounded-lg text-fg-tertiary hover:text-red-500 hover:bg-red-500/10 transition-colors disabled:opacity-50",title:t("common:delete"),children:n.jsxs("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("polyline",{points:"3 6 5 6 21 6"}),n.jsx("path",{d:"M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"})]})})]});return n.jsxs("div",{onClick:()=>W(U),className:"group rounded-lg bg-surface-elevated p-4 hover:bg-surface-overlay transition-all overflow-hidden cursor-pointer",children:[n.jsxs("div",{className:"flex items-start gap-3 min-w-0",children:[(()=>{const Ce=U.meta.icon,Ne=Ce&&(Ce.startsWith("http")||Ce.startsWith("/")||/\.(png|jpe?g|gif|webp|svg)$/i.test(Ce))?Ce.startsWith("http")||Ce.startsWith("/")?Ce:`/api/builder/artifacts/${U.type}s/${encodeURIComponent(U.name)}/images/${encodeURIComponent(Ce.split("/").pop()??"")}`:null;return n.jsx("div",{className:`w-9 h-9 rounded-lg ${H.bg} flex items-center justify-center text-lg shrink-0 overflow-hidden`,children:Ne?n.jsx("img",{src:Ne,alt:"",className:"w-full h-full object-cover"}):Ce?n.jsx("span",{children:Ce}):H.icon})})(),n.jsxs("div",{className:"flex-1 min-w-0",children:[n.jsxs("div",{className:"flex items-center gap-2 mb-0.5",children:[n.jsx("span",{className:"text-sm font-medium text-fg-primary truncate",children:q}),n.jsx("span",{className:`text-[10px] font-medium uppercase tracking-wider ${H.color}`,children:U.type})]}),Z&&n.jsx("p",{className:"text-xs text-fg-tertiary line-clamp-2",children:Z}),n.jsxs("div",{className:"flex items-center gap-3 mt-2 text-[10px] text-fg-tertiary min-w-0",children:[n.jsx("button",{onClick:Ce=>{Ce.stopPropagation(),ie.system.openPath(U.path).catch(()=>{})},className:"hover:text-fg-secondary transition-colors truncate min-w-0",title:U.path,children:gY(U.path)}),n.jsx("span",{className:"shrink-0",children:new Date(U.updatedAt).toLocaleDateString()})]})]}),!r&&Se]}),r&&n.jsx("div",{className:"mt-3 pt-3 border-t border-border-default/50",children:Se})]},_)})}),C&&n.jsx(aj,{title:t("confirmDelete"),message:t("deleteCannotUndo",{name:C.meta.displayName||C.meta.name||C.name}),cancelLabel:t("common:cancel"),confirmLabel:t("common:delete"),onConfirm:M,onCancel:()=>w(null)}),T&&n.jsx(aj,{title:t("confirmDelete"),message:t("removeFromHub",{name:T.name}),cancelLabel:t("common:cancel"),confirmLabel:t("common:delete"),onConfirm:()=>{O()},onCancel:()=>E(null)}),R&&n.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm",onClick:()=>I(null),children:n.jsxs("div",{className:"bg-surface-secondary border border-border-default rounded-xl max-w-sm w-full mx-4 p-6 shadow-2xl",onClick:U=>U.stopPropagation(),children:[n.jsx("h3",{className:"text-base font-semibold text-fg-primary mb-2",children:t("common:share")}),n.jsx("p",{className:"text-sm text-fg-secondary mb-5",children:t("share.imagePrompt")}),n.jsxs("div",{className:"flex gap-3",children:[n.jsx("button",{onClick:()=>{const U=R;I(null),L(U)},className:"flex-1 text-sm px-4 py-2 rounded-lg border border-border-default text-fg-secondary hover:text-fg-primary hover:border-fg-tertiary transition-colors",children:t("share.directly")}),n.jsx("button",{onClick:()=>{const U=R;I(null),W(U)},className:"flex-1 text-sm px-4 py-2 rounded-lg bg-brand-600 hover:bg-brand-500 text-white transition-colors",children:t("share.addImagesFirst")})]})]})}),z&&n.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm",onClick:()=>B(null),children:n.jsx("div",{className:"bg-surface-secondary border border-border-default rounded-xl max-w-sm w-full mx-4 p-6 shadow-2xl",onClick:U=>U.stopPropagation(),children:n.jsx(yY,{isUpdate:N.has(`${z.type}/${z.name}`),onCancel:()=>B(null),onConfirm:(U,H)=>{const q=z;B(null),L(q,{donationsEnabled:U==="donation",priceCents:U==="paid"?H:void 0})}})})})]})})}function yY({isUpdate:e,onCancel:t,onConfirm:r}){const{t:s}=pt(["builder","common"]),[a,i]=g.useState("free"),[l,d]=g.useState("");return n.jsxs(n.Fragment,{children:[n.jsx("h3",{className:"text-base font-semibold text-fg-primary mb-4",children:s(e?"shareMode.titleUpdate":"shareMode.title")}),n.jsxs("div",{className:"space-y-2 mb-5",children:[n.jsxs("label",{className:`flex items-center gap-3 p-3 rounded-lg border cursor-pointer transition-colors ${a==="free"?"border-brand-500 bg-brand-500/10":"border-border-default hover:border-gray-600"}`,children:[n.jsx("input",{type:"radio",name:"shareMode",checked:a==="free",onChange:()=>i("free"),className:"accent-brand-500"}),n.jsxs("div",{children:[n.jsx("div",{className:"text-sm font-medium text-fg-primary",children:s("shareMode.free")}),n.jsx("div",{className:"text-[11px] text-fg-tertiary",children:s("shareMode.freeDesc")})]})]}),n.jsxs("label",{className:`flex items-center gap-3 p-3 rounded-lg border cursor-pointer transition-colors ${a==="donation"?"border-brand-500 bg-brand-500/10":"border-border-default hover:border-gray-600"}`,children:[n.jsx("input",{type:"radio",name:"shareMode",checked:a==="donation",onChange:()=>i("donation"),className:"accent-brand-500"}),n.jsxs("div",{children:[n.jsx("div",{className:"text-sm font-medium text-fg-primary",children:s("shareMode.donation")}),n.jsx("div",{className:"text-[11px] text-fg-tertiary",children:s("shareMode.donationDesc")})]})]}),n.jsxs("label",{className:`flex items-center gap-3 p-3 rounded-lg border cursor-pointer transition-colors ${a==="paid"?"border-brand-500 bg-brand-500/10":"border-border-default hover:border-gray-600"}`,children:[n.jsx("input",{type:"radio",name:"shareMode",checked:a==="paid",onChange:()=>i("paid"),className:"accent-brand-500"}),n.jsxs("div",{children:[n.jsx("div",{className:"text-sm font-medium text-fg-primary",children:s("shareMode.paid")}),n.jsx("div",{className:"text-[11px] text-fg-tertiary",children:s("shareMode.paidDesc")})]})]})]}),a==="paid"&&n.jsxs("div",{className:"mb-5",children:[n.jsx("label",{className:"text-xs text-fg-secondary block mb-1.5",children:s("shareMode.priceLabel")}),n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx("span",{className:"text-sm text-fg-tertiary",children:"$"}),n.jsx("input",{type:"number",min:"0.5",step:"0.5",value:l,onChange:u=>d(u.target.value),placeholder:s("shareMode.pricePlaceholder"),className:"flex-1 text-sm px-3 py-2 rounded-lg bg-surface-elevated border border-border-default text-fg-primary placeholder:text-fg-muted"})]})]}),n.jsxs("div",{className:"flex gap-3",children:[n.jsx("button",{onClick:t,className:"flex-1 text-sm px-4 py-2 rounded-lg border border-border-default text-fg-secondary hover:text-fg-primary hover:border-gray-600 transition-colors",children:s("common:cancel")}),n.jsx("button",{onClick:()=>r(a,a==="paid"?Math.round(Number(l)*100):0),disabled:a==="paid"&&(!l||Number(l)<=0),className:"flex-1 text-sm px-4 py-2 rounded-lg bg-brand-600 hover:bg-brand-500 text-white transition-colors disabled:opacity-50 disabled:cursor-not-allowed",children:s(e?"shareMode.update":"shareMode.share")})]})]})}const ij={agent:{icon:"✦",label:"Agent",color:"text-brand-500",gradient:"from-brand-500 to-purple-600",bg:"bg-brand-500/10",ring:"ring-brand-500/30"},team:{icon:"◈",label:"Team",color:"text-blue-600",gradient:"from-blue-500 to-blue-600",bg:"bg-blue-500/10",ring:"ring-blue-500/30"},skill:{icon:"⬡",label:"Skill",color:"text-green-600",gradient:"from-green-500 to-green-600",bg:"bg-green-500/10",ring:"ring-green-500/30"}},vY=["development","devops","management","productivity","browser","custom","general"],wY=[{label:"Tech",emojis:["✦","◈","⬡","⚡","🤖","🧠","💡","🎯","🔧","📦","🚀","💻","🛠️","⭐","🔥","💎","⚙️","🧩","🔌","💾","🖥️","📡","🔬","🧪","🏗️","📱","🎮","🕹️","📟","💽","🖨️","⌨️"]},{label:"People",emojis:["👤","👥","🧑‍💻","👨‍💼","👩‍🔬","🧙","🦸","🤝","💪","🎓","👷","🕵️","🧑‍🎨","🧑‍🏫","👨‍🚀","🥷","🧑‍🏭","🧑‍⚕️","🧑‍🔧","🧑‍🍳","👨‍🎤","🦹","🧝","🧞","🧑‍✈️","💂","🤴","👸","🧛","🧟","🧜","🧚"]},{label:"Objects",emojis:["📝","📊","🗂️","📁","🔍","🔑","🌐","💬","🔒","🎨","📐","🗃️","📋","✏️","🖊️","📌","📎","🧲","🪝","🧰","🪜","🧬","🔭","💊","🩺","📕","📗","📘","📙","📓","🗒️","📰"]},{label:"Symbols",emojis:["❤️","🧡","💛","💚","💙","💜","🖤","🤍","♠️","♥️","♦️","♣️","🎵","🎶","💯","✅","❌","⭕","🔴","🟠","🟡","🟢","🔵","🟣","⚫","⚪","🟤","🔶","🔷","▶️","⏸️","⏹️"]},{label:"Nature",emojis:["🌟","🌈","🌊","🌿","🍀","🔮","💫","✨","🌙","☀️","🦋","🐉","🦊","🐺","🦅","🐙","🦁","🐯","🦄","🐲","🌸","🌺","🍄","🌵","🎄","🌴","🍁","🌻","🐝","🦎","🐍","🦈"]},{label:"Activity",emojis:["🎯","🏆","🥇","🎖️","🏅","🎪","🎭","🎬","🎤","🎧","🎼","🎹","🥁","🎸","🎺","🎻","⚽","🏀","🎾","🏐","🎲","🧸","🪁","🎰","🎳","🏹","🥊","🤺","⛷️","🏄","🚴","🧗"]}],kY={shell:{icon:">",color:"bg-amber-500/15 text-amber-400 border-amber-500/30"},file:{icon:"◫",color:"bg-blue-500/15 text-blue-400 border-blue-500/30"},network:{icon:"◎",color:"bg-purple-500/15 text-purple-400 border-purple-500/30"},browser:{icon:"◉",color:"bg-cyan-500/15 text-cyan-400 border-cyan-500/30"}};function Wx({value:e,onChange:t,renderAs:r="span",className:s,editClassName:a,placeholder:i,multiline:l,readOnly:d}){if(d){const S=e||i,E=`${s??""} ${!e?"text-fg-muted italic":""}`;return r==="h1"?n.jsx("h1",{className:E,children:S}):r==="p"?n.jsx("p",{className:E,children:S}):n.jsx("span",{className:E,children:S})}const[u,m]=g.useState(!1),[h,p]=g.useState(e),y=g.useRef(null);g.useEffect(()=>{p(e)},[e]),g.useEffect(()=>{u&&y.current?.focus()},[u]);const x=()=>{m(!1),h!==e&&t(h)},v=()=>{p(e),m(!1)},j=S=>{S.key==="Escape"&&v(),S.key==="Enter"&&!l&&x()};if(u){const S=`bg-transparent outline-none w-full ${a??s??""} ring-1 ring-brand-500/50 rounded px-1 -mx-1`;return l?n.jsx("textarea",{ref:y,value:h,onChange:T=>p(T.target.value),onBlur:x,onKeyDown:j,className:`${S} resize-y min-h-[60px]`,placeholder:i}):n.jsx("input",{ref:y,value:h,onChange:T=>p(T.target.value),onBlur:x,onKeyDown:j,className:S,placeholder:i})}const C=e||i,w=!e,N="cursor-text hover:ring-1 hover:ring-border-default rounded px-1 -mx-1 transition-all";return r==="h1"?n.jsx("h1",{onClick:()=>m(!0),className:`${s??""} ${N} ${w?"text-fg-muted italic":""}`,children:C}):r==="p"?n.jsx("p",{onClick:()=>m(!0),className:`${s??""} ${N} ${w?"text-fg-muted italic":""}`,children:C}):r==="badge"?n.jsx("span",{onClick:()=>m(!0),className:`${s??""} ${N} ${w?"text-fg-muted italic":""}`,children:C}):n.jsx("span",{onClick:()=>m(!0),className:`${s??""} ${N} ${w?"text-fg-muted italic":""}`,children:C})}function jY({value:e,options:t,onChange:r,className:s,readOnly:a}){if(a)return n.jsx("span",{className:s,children:e});const[i,l]=g.useState(!1),[d,u]=g.useState(e),m=g.useRef(null),h=g.useRef(null);g.useEffect(()=>{i&&(u(e),setTimeout(()=>m.current?.focus(),0))},[i,e]);const p=t.filter(x=>x.toLowerCase().includes(d.toLowerCase())),y=x=>{const v=x.trim();v&&v!==e&&r(v),l(!1)};return i?n.jsxs("div",{ref:h,className:"relative inline-block",children:[n.jsx("input",{ref:m,value:d,onChange:x=>u(x.target.value),onKeyDown:x=>{x.key==="Enter"?(x.preventDefault(),y(d)):x.key==="Escape"&&l(!1)},onBlur:x=>{h.current?.contains(x.relatedTarget)||y(d)},className:`${s??""} bg-transparent outline-none ring-1 ring-brand-500/50 rounded w-28`}),p.length>0&&n.jsx("div",{className:"absolute top-full left-0 mt-1 z-50 bg-surface-elevated border border-border-default rounded-lg shadow-xl py-1 min-w-[120px] max-h-40 overflow-y-auto",children:p.map(x=>n.jsx("button",{onMouseDown:v=>{v.preventDefault(),y(x)},className:`block w-full text-left px-3 py-1.5 text-xs hover:bg-surface-secondary/80 transition-colors ${x===e?"text-brand-400 font-medium":"text-fg-secondary"}`,children:x},x))})]}):n.jsx("span",{onClick:()=>l(!0),className:`${s??""} cursor-pointer hover:ring-1 hover:ring-border-default rounded px-1 -mx-1 transition-all`,children:e})}function NY({tags:e,onChange:t,readOnly:r}){if(r)return n.jsx("div",{className:"flex flex-wrap items-center gap-1.5 min-h-[24px]",children:e.map(h=>n.jsx("span",{className:"text-[10px] px-2 py-0.5 bg-surface-elevated text-fg-muted rounded-full border border-border-default",children:h},h))});const{t:s}=pt(["builder"]),[a,i]=g.useState(!1),[l,d]=g.useState(""),u=g.useRef(null);g.useEffect(()=>{a&&u.current?.focus()},[a]);const m=h=>{if((h.key==="Enter"||h.key===",")&&l.trim()){h.preventDefault();const p=l.trim().toLowerCase();e.includes(p)||t([...e,p]),d("")}else h.key==="Backspace"&&!l&&e.length>0?t(e.slice(0,-1)):h.key==="Escape"&&(i(!1),d(""))};return a?n.jsxs("div",{className:"flex flex-wrap items-center gap-1.5 ring-1 ring-brand-500/50 rounded px-2 py-1 -mx-1 min-h-[32px]",children:[e.map(h=>n.jsxs("span",{className:"inline-flex items-center gap-1 text-[10px] bg-surface-elevated text-fg-secondary rounded-full px-2 py-0.5 border border-border-default",children:[h,n.jsx("button",{onClick:()=>t(e.filter(p=>p!==h)),className:"text-fg-muted hover:text-red-500",children:"×"})]},h)),n.jsx("input",{ref:u,value:l,onChange:h=>d(h.target.value),onKeyDown:m,onBlur:()=>{l||i(!1)},className:"flex-1 min-w-[80px] bg-transparent text-xs text-fg-primary placeholder:text-fg-muted focus:outline-none",placeholder:s("detail.typeTagAndEnter")})]}):n.jsx("div",{onClick:()=>i(!0),className:"flex flex-wrap items-center gap-1.5 cursor-text hover:ring-1 hover:ring-border-default rounded px-1 -mx-1 py-0.5 transition-all min-h-[24px]",children:e.length>0?e.map(h=>n.jsx("span",{className:"text-[10px] px-2 py-0.5 bg-surface-elevated text-fg-muted rounded-full border border-border-default",children:h},h)):n.jsx("span",{className:"text-[10px] text-fg-muted italic",children:s("detail.typeTagAndEnter")})})}function e1({content:e}){return n.jsx("div",{className:`prose prose-invert prose-sm max-w-none
661
661
  prose-headings:text-fg-primary prose-headings:font-semibold
@@ -708,4 +708,4 @@ l0,-`+(r+144)+`c-2,-159.3,-10,-310.7,-24,-454c-53.3,-528,-210,-949.7,
708
708
  `)),h=m.reduce((p,y)=>p.concat(...y),[]);return[m,h]}return[[],[]]},[e]);return g.useEffect(()=>{const u=t?.target??e3,m=t?.actInsideInputWithModifier??!0;if(e!==null){const h=x=>{if(a.current=x.ctrlKey||x.metaKey||x.shiftKey||x.altKey,(!a.current||a.current&&!m)&&J7(x))return!1;const j=n3(x.code,d);if(i.current.add(x[j]),t3(l,i.current,!1)){const C=x.composedPath?.()?.[0]||x.target,w=C?.nodeName==="BUTTON"||C?.nodeName==="A";t.preventDefault!==!1&&(a.current||!w)&&x.preventDefault(),s(!0)}},p=x=>{const v=n3(x.code,d);t3(l,i.current,!0)?(s(!1),i.current.clear()):i.current.delete(x[v]),x.key==="Meta"&&i.current.clear(),a.current=!1},y=()=>{i.current.clear(),s(!1)};return u?.addEventListener("keydown",h),u?.addEventListener("keyup",p),window.addEventListener("blur",y),window.addEventListener("contextmenu",y),()=>{u?.removeEventListener("keydown",h),u?.removeEventListener("keyup",p),window.removeEventListener("blur",y),window.removeEventListener("contextmenu",y)}}},[e,s]),r}function t3(e,t,r){return e.filter(s=>r||s.length===t.size).some(s=>s.every(a=>t.has(a)))}function n3(e,t){return t.includes(e)?"code":"key"}const Qee=()=>{const e=Hr();return g.useMemo(()=>({zoomIn:t=>{const{panZoom:r}=e.getState();return r?r.scaleBy(1.2,{duration:t?.duration}):Promise.resolve(!1)},zoomOut:t=>{const{panZoom:r}=e.getState();return r?r.scaleBy(1/1.2,{duration:t?.duration}):Promise.resolve(!1)},zoomTo:(t,r)=>{const{panZoom:s}=e.getState();return s?s.scaleTo(t,{duration:r?.duration}):Promise.resolve(!1)},getZoom:()=>e.getState().transform[2],setViewport:async(t,r)=>{const{transform:[s,a,i],panZoom:l}=e.getState();return l?(await l.setViewport({x:t.x??s,y:t.y??a,zoom:t.zoom??i},r),Promise.resolve(!0)):Promise.resolve(!1)},getViewport:()=>{const[t,r,s]=e.getState().transform;return{x:t,y:r,zoom:s}},setCenter:async(t,r,s)=>e.getState().setCenter(t,r,s),fitBounds:async(t,r)=>{const{width:s,height:a,minZoom:i,maxZoom:l,panZoom:d}=e.getState(),u=jy(t,s,a,i,l,r?.padding??.1);return d?(await d.setViewport(u,{duration:r?.duration,ease:r?.ease,interpolate:r?.interpolate}),Promise.resolve(!0)):Promise.resolve(!1)},screenToFlowPosition:(t,r={})=>{const{transform:s,snapGrid:a,snapToGrid:i,domNode:l}=e.getState();if(!l)return t;const{x:d,y:u}=l.getBoundingClientRect(),m={x:t.x-d,y:t.y-u},h=r.snapGrid??a,p=r.snapToGrid??i;return _0(m,s,p,h)},flowToScreenPosition:t=>{const{transform:r,domNode:s}=e.getState();if(!s)return t;const{x:a,y:i}=s.getBoundingClientRect(),l=kh(t,r);return{x:l.x+a,y:l.y+i}}}),[])};function w8(e,t){const r=[],s=new Map,a=[];for(const i of e)if(i.type==="add"){a.push(i);continue}else if(i.type==="remove"||i.type==="replace")s.set(i.id,[i]);else{const l=s.get(i.id);l?l.push(i):s.set(i.id,[i])}for(const i of t){const l=s.get(i.id);if(!l){r.push(i);continue}if(l[0].type==="remove")continue;if(l[0].type==="replace"){r.push({...l[0].item});continue}const d={...i};for(const u of l)Zee(u,d);r.push(d)}return a.length&&a.forEach(i=>{i.index!==void 0?r.splice(i.index,0,{...i.item}):r.push({...i.item})}),r}function Zee(e,t){switch(e.type){case"select":{t.selected=e.selected;break}case"position":{typeof e.position<"u"&&(t.position=e.position),typeof e.dragging<"u"&&(t.dragging=e.dragging);break}case"dimensions":{typeof e.dimensions<"u"&&(t.measured={...e.dimensions},e.setAttributes&&((e.setAttributes===!0||e.setAttributes==="width")&&(t.width=e.dimensions.width),(e.setAttributes===!0||e.setAttributes==="height")&&(t.height=e.dimensions.height))),typeof e.resizing=="boolean"&&(t.resizing=e.resizing);break}}}function k8(e,t){return w8(e,t)}function j8(e,t){return w8(e,t)}function Jl(e,t){return{id:e,type:"select",selected:t}}function fd(e,t=new Set,r=!1){const s=[];for(const[a,i]of e){const l=t.has(a);!(i.selected===void 0&&!l)&&i.selected!==l&&(r&&(i.selected=l),s.push(Jl(i.id,l)))}return s}function r3({items:e=[],lookup:t}){const r=[],s=new Map(e.map(a=>[a.id,a]));for(const[a,i]of e.entries()){const l=t.get(i.id),d=l?.internals?.userNode??l;d!==void 0&&d!==i&&r.push({id:i.id,item:i,type:"replace"}),d===void 0&&r.push({item:i,type:"add",index:a})}for(const[a]of t)s.get(a)===void 0&&r.push({id:a,type:"remove"});return r}function s3(e){return{id:e.id,type:"remove"}}const a3=e=>NJ(e),Jee=e=>V7(e);function N8(e){return g.forwardRef(e)}const ete=typeof window<"u"?g.useLayoutEffect:g.useEffect;function i3(e){const[t,r]=g.useState(BigInt(0)),[s]=g.useState(()=>tte(()=>r(a=>a+BigInt(1))));return ete(()=>{const a=s.get();a.length&&(e(a),s.reset())},[t]),s}function tte(e){let t=[];return{get:()=>t,reset:()=>{t=[]},push:r=>{t.push(r),e()}}}const S8=g.createContext(null);function nte({children:e}){const t=Hr(),r=g.useCallback(d=>{const{nodes:u=[],setNodes:m,hasDefaultNodes:h,onNodesChange:p,nodeLookup:y,fitViewQueued:x,onNodesChangeMiddlewareMap:v}=t.getState();let j=u;for(const w of d)j=typeof w=="function"?w(j):w;let C=r3({items:j,lookup:y});for(const w of v.values())C=w(C);h&&m(j),C.length>0?p?.(C):x&&window.requestAnimationFrame(()=>{const{fitViewQueued:w,nodes:N,setNodes:S}=t.getState();w&&S(N)})},[]),s=i3(r),a=g.useCallback(d=>{const{edges:u=[],setEdges:m,hasDefaultEdges:h,onEdgesChange:p,edgeLookup:y}=t.getState();let x=u;for(const v of d)x=typeof v=="function"?v(x):v;h?m(x):p&&p(r3({items:x,lookup:y}))},[]),i=i3(a),l=g.useMemo(()=>({nodeQueue:s,edgeQueue:i}),[]);return n.jsx(S8.Provider,{value:l,children:e})}function rte(){const e=g.useContext(S8);if(!e)throw new Error("useBatchContext must be used within a BatchProvider");return e}const ste=e=>!!e.panZoom;function My(){const e=Qee(),t=Hr(),r=rte(),s=ur(ste),a=g.useMemo(()=>{const i=p=>t.getState().nodeLookup.get(p),l=p=>{r.nodeQueue.push(p)},d=p=>{r.edgeQueue.push(p)},u=p=>{const{nodeLookup:y,nodeOrigin:x}=t.getState(),v=a3(p)?p:y.get(p.id),j=v.parentId?Q7(v.position,v.measured,v.parentId,y,x):v.position,C={...v,position:j,width:v.measured?.width??v.width,height:v.measured?.height??v.height};return Ed(C)},m=(p,y,x={replace:!1})=>{l(v=>v.map(j=>{if(j.id===p){const C=typeof y=="function"?y(j):y;return x.replace&&a3(C)?C:{...j,...C}}return j}))},h=(p,y,x={replace:!1})=>{d(v=>v.map(j=>{if(j.id===p){const C=typeof y=="function"?y(j):y;return x.replace&&Jee(C)?C:{...j,...C}}return j}))};return{getNodes:()=>t.getState().nodes.map(p=>({...p})),getNode:p=>i(p)?.internals.userNode,getInternalNode:i,getEdges:()=>{const{edges:p=[]}=t.getState();return p.map(y=>({...y}))},getEdge:p=>t.getState().edgeLookup.get(p),setNodes:l,setEdges:d,addNodes:p=>{const y=Array.isArray(p)?p:[p];r.nodeQueue.push(x=>[...x,...y])},addEdges:p=>{const y=Array.isArray(p)?p:[p];r.edgeQueue.push(x=>[...x,...y])},toObject:()=>{const{nodes:p=[],edges:y=[],transform:x}=t.getState(),[v,j,C]=x;return{nodes:p.map(w=>({...w})),edges:y.map(w=>({...w})),viewport:{x:v,y:j,zoom:C}}},deleteElements:async({nodes:p=[],edges:y=[]})=>{const{nodes:x,edges:v,onNodesDelete:j,onEdgesDelete:C,triggerNodeChanges:w,triggerEdgeChanges:N,onDelete:S,onBeforeDelete:T}=t.getState(),{nodes:E,edges:R}=await EJ({nodesToRemove:p,edgesToRemove:y,nodes:x,edges:v,onBeforeDelete:T}),I=R.length>0,z=E.length>0;if(I){const B=R.map(s3);C?.(R),N(B)}if(z){const B=E.map(s3);j?.(E),w(B)}return(z||I)&&S?.({nodes:E,edges:R}),{deletedNodes:E,deletedEdges:R}},getIntersectingNodes:(p,y=!0,x)=>{const v=Ij(p),j=v?p:u(p),C=x!==void 0;return j?(x||t.getState().nodes).filter(w=>{const N=t.getState().nodeLookup.get(w.id);if(N&&!v&&(w.id===p.id||!N.internals.positionAbsolute))return!1;const S=Ed(C?w:N),T=v0(S,j);return y&&T>0||T>=S.width*S.height||T>=j.width*j.height}):[]},isNodeIntersecting:(p,y,x=!0)=>{const j=Ij(p)?p:u(p);if(!j)return!1;const C=v0(j,y);return x&&C>0||C>=y.width*y.height||C>=j.width*j.height},updateNode:m,updateNodeData:(p,y,x={replace:!1})=>{m(p,v=>{const j=typeof y=="function"?y(v):y;return x.replace?{...v,data:j}:{...v,data:{...v.data,...j}}},x)},updateEdge:h,updateEdgeData:(p,y,x={replace:!1})=>{h(p,v=>{const j=typeof y=="function"?y(v):y;return x.replace?{...v,data:j}:{...v,data:{...v.data,...j}}},x)},getNodesBounds:p=>{const{nodeLookup:y,nodeOrigin:x}=t.getState();return SJ(p,{nodeLookup:y,nodeOrigin:x})},getHandleConnections:({type:p,id:y,nodeId:x})=>Array.from(t.getState().connectionLookup.get(`${x}-${p}${y?`-${y}`:""}`)?.values()??[]),getNodeConnections:({type:p,handleId:y,nodeId:x})=>Array.from(t.getState().connectionLookup.get(`${x}${p?y?`-${p}-${y}`:`-${p}`:""}`)?.values()??[]),fitView:async p=>{const y=t.getState().fitViewResolver??IJ();return t.setState({fitViewQueued:!0,fitViewOptions:p,fitViewResolver:y}),r.nodeQueue.push(x=>[...x]),y.promise}}},[]);return g.useMemo(()=>({...a,...e,viewportInitialized:s}),[s])}const o3=e=>e.selected,ate=typeof window<"u"?window:void 0;function ite({deleteKeyCode:e,multiSelectionKeyCode:t}){const r=Hr(),{deleteElements:s}=My(),a=k0(e,{actInsideInputWithModifier:!1}),i=k0(t,{target:ate});g.useEffect(()=>{if(a){const{edges:l,nodes:d}=r.getState();s({nodes:d.filter(o3),edges:l.filter(o3)}),r.setState({nodesSelectionActive:!1})}},[a]),g.useEffect(()=>{r.setState({multiSelectionActive:i})},[i])}function ote(e){const t=Hr();g.useEffect(()=>{const r=()=>{if(!e.current||!(e.current.checkVisibility?.()??!0))return!1;const s=Ny(e.current);(s.height===0||s.width===0)&&t.getState().onError?.("004",Yi.error004()),t.setState({width:s.width||500,height:s.height||500})};if(e.current){r(),window.addEventListener("resize",r);const s=new ResizeObserver(()=>r());return s.observe(e.current),()=>{window.removeEventListener("resize",r),s&&e.current&&s.unobserve(e.current)}}},[])}const sp={position:"absolute",width:"100%",height:"100%",top:0,left:0},lte=e=>({userSelectionActive:e.userSelectionActive,lib:e.lib,connectionInProgress:e.connection.inProgress});function cte({onPaneContextMenu:e,zoomOnScroll:t=!0,zoomOnPinch:r=!0,panOnScroll:s=!1,panOnScrollSpeed:a=.5,panOnScrollMode:i=oc.Free,zoomOnDoubleClick:l=!0,panOnDrag:d=!0,defaultViewport:u,translateExtent:m,minZoom:h,maxZoom:p,zoomActivationKeyCode:y,preventScrolling:x=!0,children:v,noWheelClassName:j,noPanClassName:C,onViewportChange:w,isControlledViewport:N,paneClickDistance:S,selectionOnDrag:T}){const E=Hr(),R=g.useRef(null),{userSelectionActive:I,lib:z,connectionInProgress:B}=ur(lte,Yr),D=k0(y),V=g.useRef();ote(R);const Y=g.useCallback(F=>{w?.({x:F[0],y:F[1],zoom:F[2]}),N||E.setState({transform:F})},[w,N]);return g.useEffect(()=>{if(R.current){V.current=gee({domNode:R.current,minZoom:h,maxZoom:p,translateExtent:m,viewport:u,onDraggingChange:M=>E.setState($=>$.paneDragging===M?$:{paneDragging:M}),onPanZoomStart:(M,$)=>{const{onViewportChangeStart:W,onMoveStart:U}=E.getState();U?.(M,$),W?.($)},onPanZoom:(M,$)=>{const{onViewportChange:W,onMove:U}=E.getState();U?.(M,$),W?.($)},onPanZoomEnd:(M,$)=>{const{onViewportChangeEnd:W,onMoveEnd:U}=E.getState();U?.(M,$),W?.($)}});const{x:F,y:L,zoom:O}=V.current.getViewport();return E.setState({panZoom:V.current,transform:[F,L,O],domNode:R.current.closest(".react-flow")}),()=>{V.current?.destroy()}}},[]),g.useEffect(()=>{V.current?.update({onPaneContextMenu:e,zoomOnScroll:t,zoomOnPinch:r,panOnScroll:s,panOnScrollSpeed:a,panOnScrollMode:i,zoomOnDoubleClick:l,panOnDrag:d,zoomActivationKeyPressed:D,preventScrolling:x,noPanClassName:C,userSelectionActive:I,noWheelClassName:j,lib:z,onTransformChange:Y,connectionInProgress:B,selectionOnDrag:T,paneClickDistance:S})},[e,t,r,s,a,i,l,d,D,x,C,I,j,z,Y,B,T,S]),n.jsx("div",{className:"react-flow__renderer",ref:R,style:sp,children:v})}const dte=e=>({userSelectionActive:e.userSelectionActive,userSelectionRect:e.userSelectionRect});function ute(){const{userSelectionActive:e,userSelectionRect:t}=ur(dte,Yr);return e&&t?n.jsx("div",{className:"react-flow__selection react-flow__container",style:{width:t.width,height:t.height,transform:`translate(${t.x}px, ${t.y}px)`}}):null}const ib=(e,t)=>r=>{r.target===t.current&&e?.(r)},mte=e=>({userSelectionActive:e.userSelectionActive,elementsSelectable:e.elementsSelectable,connectionInProgress:e.connection.inProgress,dragging:e.paneDragging});function fte({isSelecting:e,selectionKeyPressed:t,selectionMode:r=y0.Full,panOnDrag:s,paneClickDistance:a,selectionOnDrag:i,onSelectionStart:l,onSelectionEnd:d,onPaneClick:u,onPaneContextMenu:m,onPaneScroll:h,onPaneMouseEnter:p,onPaneMouseMove:y,onPaneMouseLeave:x,children:v}){const j=Hr(),{userSelectionActive:C,elementsSelectable:w,dragging:N,connectionInProgress:S}=ur(mte,Yr),T=w&&(e||C),E=g.useRef(null),R=g.useRef(),I=g.useRef(new Set),z=g.useRef(new Set),B=g.useRef(!1),D=W=>{if(B.current||S){B.current=!1;return}u?.(W),j.getState().resetSelectedElements(),j.setState({nodesSelectionActive:!1})},V=W=>{if(Array.isArray(s)&&s?.includes(2)){W.preventDefault();return}m?.(W)},Y=h?W=>h(W):void 0,F=W=>{B.current&&(W.stopPropagation(),B.current=!1)},L=W=>{const{domNode:U}=j.getState();if(R.current=U?.getBoundingClientRect(),!R.current)return;const H=W.target===E.current;if(!H&&!!W.target.closest(".nokey")||!e||!(i&&H||t)||W.button!==0||!W.isPrimary)return;W.target?.setPointerCapture?.(W.pointerId),B.current=!1;const{x:_,y:J}=Ti(W.nativeEvent,R.current);j.setState({userSelectionRect:{width:0,height:0,startX:_,startY:J,x:_,y:J}}),H||(W.stopPropagation(),W.preventDefault())},O=W=>{const{userSelectionRect:U,transform:H,nodeLookup:q,edgeLookup:Z,connectionLookup:_,triggerNodeChanges:J,triggerEdgeChanges:X,defaultEdgeOptions:ee,resetSelectedElements:te}=j.getState();if(!R.current||!U)return;const{x:G,y:ue}=Ti(W.nativeEvent,R.current),{startX:Se,startY:Ce}=U;if(!B.current){const Ee=t?0:a;if(Math.hypot(G-Se,ue-Ce)<=Ee)return;te(),l?.(W)}B.current=!0;const Be={startX:Se,startY:Ce,x:G<Se?G:Se,y:ue<Ce?ue:Ce,width:Math.abs(G-Se),height:Math.abs(ue-Ce)},Ne=I.current,he=z.current;I.current=new Set(ky(q,Be,H,r===y0.Partial,!0).map(Ee=>Ee.id)),z.current=new Set;const _e=ee?.selectable??!0;for(const Ee of I.current){const Ye=_.get(Ee);if(Ye)for(const{edgeId:Ze}of Ye.values()){const mt=Z.get(Ze);mt&&(mt.selectable??_e)&&z.current.add(Ze)}}if(!Lj(Ne,I.current)){const Ee=fd(q,I.current,!0);J(Ee)}if(!Lj(he,z.current)){const Ee=fd(Z,z.current);X(Ee)}j.setState({userSelectionRect:Be,userSelectionActive:!0,nodesSelectionActive:!1})},M=W=>{W.button===0&&(W.target?.releasePointerCapture?.(W.pointerId),!C&&W.target===E.current&&j.getState().userSelectionRect&&D?.(W),j.setState({userSelectionActive:!1,userSelectionRect:null}),B.current&&(d?.(W),j.setState({nodesSelectionActive:I.current.size>0})))},$=s===!0||Array.isArray(s)&&s.includes(0);return n.jsxs("div",{className:js(["react-flow__pane",{draggable:$,dragging:N,selection:e}]),onClick:T?void 0:ib(D,E),onContextMenu:ib(V,E),onWheel:ib(Y,E),onPointerEnter:T?void 0:p,onPointerMove:T?O:y,onPointerUp:T?M:void 0,onPointerDownCapture:T?L:void 0,onClickCapture:T?F:void 0,onPointerLeave:x,ref:E,style:sp,children:[v,n.jsx(ute,{})]})}function b1({id:e,store:t,unselect:r=!1,nodeRef:s}){const{addSelectedNodes:a,unselectNodesAndEdges:i,multiSelectionActive:l,nodeLookup:d,onError:u}=t.getState(),m=d.get(e);if(!m){u?.("012",Yi.error012(e));return}t.setState({nodesSelectionActive:!1}),m.selected?(r||m.selected&&l)&&(i({nodes:[m],edges:[]}),requestAnimationFrame(()=>s?.current?.blur())):a([e])}function C8({nodeRef:e,disabled:t=!1,noDragClassName:r,handleSelector:s,nodeId:a,isSelectable:i,nodeClickDistance:l}){const d=Hr(),[u,m]=g.useState(!1),h=g.useRef();return g.useEffect(()=>{h.current=nee({getStoreItems:()=>d.getState(),onNodeMouseDown:p=>{b1({id:p,store:d,nodeRef:e})},onDragStart:()=>{m(!0)},onDragStop:()=>{m(!1)}})},[]),g.useEffect(()=>{if(!(t||!e.current||!h.current))return h.current.update({noDragClassName:r,handleSelector:s,domNode:e.current,isSelectable:i,nodeId:a,nodeClickDistance:l}),()=>{h.current?.destroy()}},[r,s,t,i,e,a,l]),u}const hte=e=>t=>t.selected&&(t.draggable||e&&typeof t.draggable>"u");function T8(){const e=Hr();return g.useCallback(r=>{const{nodeExtent:s,snapToGrid:a,snapGrid:i,nodesDraggable:l,onError:d,updateNodePositions:u,nodeLookup:m,nodeOrigin:h}=e.getState(),p=new Map,y=hte(l),x=a?i[0]:5,v=a?i[1]:5,j=r.direction.x*x*r.factor,C=r.direction.y*v*r.factor;for(const[,w]of m){if(!y(w))continue;let N={x:w.internals.positionAbsolute.x+j,y:w.internals.positionAbsolute.y+C};a&&(N=O0(N,i));const{position:S,positionAbsolute:T}=K7({nodeId:w.id,nextPosition:N,nodeLookup:m,nodeExtent:s,nodeOrigin:h,onError:d});w.position=S,w.internals.positionAbsolute=T,p.set(w.id,w)}u(p)},[])}const Dy=g.createContext(null),pte=Dy.Provider;Dy.Consumer;const A8=()=>g.useContext(Dy),gte=e=>({connectOnClick:e.connectOnClick,noPanClassName:e.noPanClassName,rfId:e.rfId}),xte=(e,t,r)=>s=>{const{connectionClickStartHandle:a,connectionMode:i,connection:l}=s,{fromHandle:d,toHandle:u,isValid:m}=l,h=u?.nodeId===e&&u?.id===t&&u?.type===r;return{connectingFrom:d?.nodeId===e&&d?.id===t&&d?.type===r,connectingTo:h,clickConnecting:a?.nodeId===e&&a?.id===t&&a?.type===r,isPossibleEndHandle:i===Cd.Strict?d?.type!==r:e!==d?.nodeId||t!==d?.id,connectionInProcess:!!d,clickConnectionInProcess:!!a,valid:h&&m}};function bte({type:e="source",position:t=Jt.Top,isValidConnection:r,isConnectable:s=!0,isConnectableStart:a=!0,isConnectableEnd:i=!0,id:l,onConnect:d,children:u,className:m,onMouseDown:h,onTouchStart:p,...y},x){const v=l||null,j=e==="target",C=Hr(),w=A8(),{connectOnClick:N,noPanClassName:S,rfId:T}=ur(gte,Yr),{connectingFrom:E,connectingTo:R,clickConnecting:I,isPossibleEndHandle:z,connectionInProcess:B,clickConnectionInProcess:D,valid:V}=ur(xte(w,v,e),Yr);w||C.getState().onError?.("010",Yi.error010());const Y=O=>{const{defaultEdgeOptions:M,onConnect:$,hasDefaultEdges:W}=C.getState(),U={...M,...O};if(W){const{edges:H,setEdges:q}=C.getState();q(BJ(U,H))}$?.(U),d?.(U)},F=O=>{if(!w)return;const M=e8(O.nativeEvent);if(a&&(M&&O.button===0||!M)){const $=C.getState();x1.onPointerDown(O.nativeEvent,{handleDomNode:O.currentTarget,autoPanOnConnect:$.autoPanOnConnect,connectionMode:$.connectionMode,connectionRadius:$.connectionRadius,domNode:$.domNode,nodeLookup:$.nodeLookup,lib:$.lib,isTarget:j,handleId:v,nodeId:w,flowId:$.rfId,panBy:$.panBy,cancelConnection:$.cancelConnection,onConnectStart:$.onConnectStart,onConnectEnd:(...W)=>C.getState().onConnectEnd?.(...W),updateConnection:$.updateConnection,onConnect:Y,isValidConnection:r||((...W)=>C.getState().isValidConnection?.(...W)??!0),getTransform:()=>C.getState().transform,getFromHandle:()=>C.getState().connection.fromHandle,autoPanSpeed:$.autoPanSpeed,dragThreshold:$.connectionDragThreshold})}M?h?.(O):p?.(O)},L=O=>{const{onClickConnectStart:M,onClickConnectEnd:$,connectionClickStartHandle:W,connectionMode:U,isValidConnection:H,lib:q,rfId:Z,nodeLookup:_,connection:J}=C.getState();if(!w||!W&&!a)return;if(!W){M?.(O.nativeEvent,{nodeId:w,handleId:v,handleType:e}),C.setState({connectionClickStartHandle:{nodeId:w,type:e,id:v}});return}const X=Z7(O.target),ee=r||H,{connection:te,isValid:G}=x1.isValid(O.nativeEvent,{handle:{nodeId:w,id:v,type:e},connectionMode:U,fromNodeId:W.nodeId,fromHandleId:W.id||null,fromType:W.type,isValidConnection:ee,flowId:Z,doc:X,lib:q,nodeLookup:_});G&&te&&Y(te);const ue=structuredClone(J);delete ue.inProgress,ue.toPosition=ue.toHandle?ue.toHandle.position:null,$?.(O,ue),C.setState({connectionClickStartHandle:null})};return n.jsx("div",{"data-handleid":v,"data-nodeid":w,"data-handlepos":t,"data-id":`${T}-${w}-${v}-${e}`,className:js(["react-flow__handle",`react-flow__handle-${t}`,"nodrag",S,m,{source:!j,target:j,connectable:s,connectablestart:a,connectableend:i,clickconnecting:I,connectingfrom:E,connectingto:R,valid:V,connectionindicator:s&&(!B||z)&&(B||D?i:a)}]),onMouseDown:F,onTouchStart:F,onClick:N?L:void 0,ref:x,...y,children:u})}const Cl=g.memo(N8(bte));function yte({data:e,isConnectable:t,sourcePosition:r=Jt.Bottom}){return n.jsxs(n.Fragment,{children:[e?.label,n.jsx(Cl,{type:"source",position:r,isConnectable:t})]})}function vte({data:e,isConnectable:t,targetPosition:r=Jt.Top,sourcePosition:s=Jt.Bottom}){return n.jsxs(n.Fragment,{children:[n.jsx(Cl,{type:"target",position:r,isConnectable:t}),e?.label,n.jsx(Cl,{type:"source",position:s,isConnectable:t})]})}function wte(){return null}function kte({data:e,isConnectable:t,targetPosition:r=Jt.Top}){return n.jsxs(n.Fragment,{children:[n.jsx(Cl,{type:"target",position:r,isConnectable:t}),e?.label]})}const jh={ArrowUp:{x:0,y:-1},ArrowDown:{x:0,y:1},ArrowLeft:{x:-1,y:0},ArrowRight:{x:1,y:0}},l3={input:yte,default:vte,output:kte,group:wte};function jte(e){return e.internals.handleBounds===void 0?{width:e.width??e.initialWidth??e.style?.width,height:e.height??e.initialHeight??e.style?.height}:{width:e.width??e.style?.width,height:e.height??e.style?.height}}const Nte=e=>{const{width:t,height:r,x:s,y:a}=P0(e.nodeLookup,{filter:i=>!!i.selected});return{width:Ci(t)?t:null,height:Ci(r)?r:null,userSelectionActive:e.userSelectionActive,transformString:`translate(${e.transform[0]}px,${e.transform[1]}px) scale(${e.transform[2]}) translate(${s}px,${a}px)`}};function Ste({onSelectionContextMenu:e,noPanClassName:t,disableKeyboardA11y:r}){const s=Hr(),{width:a,height:i,transformString:l,userSelectionActive:d}=ur(Nte,Yr),u=T8(),m=g.useRef(null);g.useEffect(()=>{r||m.current?.focus({preventScroll:!0})},[r]);const h=!d&&a!==null&&i!==null;if(C8({nodeRef:m,disabled:!h}),!h)return null;const p=e?x=>{const v=s.getState().nodes.filter(j=>j.selected);e(x,v)}:void 0,y=x=>{Object.prototype.hasOwnProperty.call(jh,x.key)&&(x.preventDefault(),u({direction:jh[x.key],factor:x.shiftKey?4:1}))};return n.jsx("div",{className:js(["react-flow__nodesselection","react-flow__container",t]),style:{transform:l},children:n.jsx("div",{ref:m,className:"react-flow__nodesselection-rect",onContextMenu:p,tabIndex:r?void 0:-1,onKeyDown:r?void 0:y,style:{width:a,height:i}})})}const c3=typeof window<"u"?window:void 0,Cte=e=>({nodesSelectionActive:e.nodesSelectionActive,userSelectionActive:e.userSelectionActive});function E8({children:e,onPaneClick:t,onPaneMouseEnter:r,onPaneMouseMove:s,onPaneMouseLeave:a,onPaneContextMenu:i,onPaneScroll:l,paneClickDistance:d,deleteKeyCode:u,selectionKeyCode:m,selectionOnDrag:h,selectionMode:p,onSelectionStart:y,onSelectionEnd:x,multiSelectionKeyCode:v,panActivationKeyCode:j,zoomActivationKeyCode:C,elementsSelectable:w,zoomOnScroll:N,zoomOnPinch:S,panOnScroll:T,panOnScrollSpeed:E,panOnScrollMode:R,zoomOnDoubleClick:I,panOnDrag:z,defaultViewport:B,translateExtent:D,minZoom:V,maxZoom:Y,preventScrolling:F,onSelectionContextMenu:L,noWheelClassName:O,noPanClassName:M,disableKeyboardA11y:$,onViewportChange:W,isControlledViewport:U}){const{nodesSelectionActive:H,userSelectionActive:q}=ur(Cte,Yr),Z=k0(m,{target:c3}),_=k0(j,{target:c3}),J=_||z,X=_||T,ee=h&&J!==!0,te=Z||q||ee;return ite({deleteKeyCode:u,multiSelectionKeyCode:v}),n.jsx(cte,{onPaneContextMenu:i,elementsSelectable:w,zoomOnScroll:N,zoomOnPinch:S,panOnScroll:X,panOnScrollSpeed:E,panOnScrollMode:R,zoomOnDoubleClick:I,panOnDrag:!Z&&J,defaultViewport:B,translateExtent:D,minZoom:V,maxZoom:Y,zoomActivationKeyCode:C,preventScrolling:F,noWheelClassName:O,noPanClassName:M,onViewportChange:W,isControlledViewport:U,paneClickDistance:d,selectionOnDrag:ee,children:n.jsxs(fte,{onSelectionStart:y,onSelectionEnd:x,onPaneClick:t,onPaneMouseEnter:r,onPaneMouseMove:s,onPaneMouseLeave:a,onPaneContextMenu:i,onPaneScroll:l,panOnDrag:J,isSelecting:!!te,selectionMode:p,selectionKeyPressed:Z,paneClickDistance:d,selectionOnDrag:ee,children:[e,H&&n.jsx(Ste,{onSelectionContextMenu:L,noPanClassName:M,disableKeyboardA11y:$})]})})}E8.displayName="FlowRenderer";const Tte=g.memo(E8),Ate=e=>t=>e?ky(t.nodeLookup,{x:0,y:0,width:t.width,height:t.height},t.transform,!0).map(r=>r.id):Array.from(t.nodeLookup.keys());function Ete(e){return ur(g.useCallback(Ate(e),[e]),Yr)}const Mte=e=>e.updateNodeInternals;function Dte(){const e=ur(Mte),[t]=g.useState(()=>typeof ResizeObserver>"u"?null:new ResizeObserver(r=>{const s=new Map;r.forEach(a=>{const i=a.target.getAttribute("data-id");s.set(i,{id:i,nodeElement:a.target,force:!0})}),e(s)}));return g.useEffect(()=>()=>{t?.disconnect()},[t]),t}function Rte({node:e,nodeType:t,hasDimensions:r,resizeObserver:s}){const a=Hr(),i=g.useRef(null),l=g.useRef(null),d=g.useRef(e.sourcePosition),u=g.useRef(e.targetPosition),m=g.useRef(t),h=r&&!!e.internals.handleBounds;return g.useEffect(()=>{i.current&&!e.hidden&&(!h||l.current!==i.current)&&(l.current&&s?.unobserve(l.current),s?.observe(i.current),l.current=i.current)},[h,e.hidden]),g.useEffect(()=>()=>{l.current&&(s?.unobserve(l.current),l.current=null)},[]),g.useEffect(()=>{if(i.current){const p=m.current!==t,y=d.current!==e.sourcePosition,x=u.current!==e.targetPosition;(p||y||x)&&(m.current=t,d.current=e.sourcePosition,u.current=e.targetPosition,a.getState().updateNodeInternals(new Map([[e.id,{id:e.id,nodeElement:i.current,force:!0}]])))}},[e.id,t,e.sourcePosition,e.targetPosition]),i}function Ite({id:e,onClick:t,onMouseEnter:r,onMouseMove:s,onMouseLeave:a,onContextMenu:i,onDoubleClick:l,nodesDraggable:d,elementsSelectable:u,nodesConnectable:m,nodesFocusable:h,resizeObserver:p,noDragClassName:y,noPanClassName:x,disableKeyboardA11y:v,rfId:j,nodeTypes:C,nodeClickDistance:w,onError:N}){const{node:S,internals:T,isParent:E}=ur(G=>{const ue=G.nodeLookup.get(e),Se=G.parentLookup.has(e);return{node:ue,internals:ue.internals,isParent:Se}},Yr);let R=S.type||"default",I=C?.[R]||l3[R];I===void 0&&(N?.("003",Yi.error003(R)),R="default",I=C?.default||l3.default);const z=!!(S.draggable||d&&typeof S.draggable>"u"),B=!!(S.selectable||u&&typeof S.selectable>"u"),D=!!(S.connectable||m&&typeof S.connectable>"u"),V=!!(S.focusable||h&&typeof S.focusable>"u"),Y=Hr(),F=X7(S),L=Rte({node:S,nodeType:R,hasDimensions:F,resizeObserver:p}),O=C8({nodeRef:L,disabled:S.hidden||!z,noDragClassName:y,handleSelector:S.dragHandle,nodeId:e,isSelectable:B,nodeClickDistance:w}),M=T8();if(S.hidden)return null;const $=zo(S),W=jte(S),U=B||z||t||r||s||a,H=r?G=>r(G,{...T.userNode}):void 0,q=s?G=>s(G,{...T.userNode}):void 0,Z=a?G=>a(G,{...T.userNode}):void 0,_=i?G=>i(G,{...T.userNode}):void 0,J=l?G=>l(G,{...T.userNode}):void 0,X=G=>{const{selectNodesOnDrag:ue,nodeDragThreshold:Se}=Y.getState();B&&(!ue||!z||Se>0)&&b1({id:e,store:Y,nodeRef:L}),t&&t(G,{...T.userNode})},ee=G=>{if(!(J7(G.nativeEvent)||v)){if(H7.includes(G.key)&&B){const ue=G.key==="Escape";b1({id:e,store:Y,unselect:ue,nodeRef:L})}else if(z&&S.selected&&Object.prototype.hasOwnProperty.call(jh,G.key)){G.preventDefault();const{ariaLabelConfig:ue}=Y.getState();Y.setState({ariaLiveMessage:ue["node.a11yDescription.ariaLiveMessage"]({direction:G.key.replace("Arrow","").toLowerCase(),x:~~T.positionAbsolute.x,y:~~T.positionAbsolute.y})}),M({direction:jh[G.key],factor:G.shiftKey?4:1})}}},te=()=>{if(v||!L.current?.matches(":focus-visible"))return;const{transform:G,width:ue,height:Se,autoPanOnNodeFocus:Ce,setCenter:Be}=Y.getState();if(!Ce)return;ky(new Map([[e,S]]),{x:0,y:0,width:ue,height:Se},G,!0).length>0||Be(S.position.x+$.width/2,S.position.y+$.height/2,{zoom:G[2]})};return n.jsx("div",{className:js(["react-flow__node",`react-flow__node-${R}`,{[x]:z},S.className,{selected:S.selected,selectable:B,parent:E,draggable:z,dragging:O}]),ref:L,style:{zIndex:T.z,transform:`translate(${T.positionAbsolute.x}px,${T.positionAbsolute.y}px)`,pointerEvents:U?"all":"none",visibility:F?"visible":"hidden",...S.style,...W},"data-id":e,"data-testid":`rf__node-${e}`,onMouseEnter:H,onMouseMove:q,onMouseLeave:Z,onContextMenu:_,onClick:X,onDoubleClick:J,onKeyDown:V?ee:void 0,tabIndex:V?0:void 0,onFocus:V?te:void 0,role:S.ariaRole??(V?"group":void 0),"aria-roledescription":"node","aria-describedby":v?void 0:`${b8}-${j}`,"aria-label":S.ariaLabel,...S.domAttributes,children:n.jsx(pte,{value:e,children:n.jsx(I,{id:e,data:S.data,type:R,positionAbsoluteX:T.positionAbsolute.x,positionAbsoluteY:T.positionAbsolute.y,selected:S.selected??!1,selectable:B,draggable:z,deletable:S.deletable??!0,isConnectable:D,sourcePosition:S.sourcePosition,targetPosition:S.targetPosition,dragging:O,dragHandle:S.dragHandle,zIndex:T.z,parentId:S.parentId,...$})})})}var Lte=g.memo(Ite);const Pte=e=>({nodesDraggable:e.nodesDraggable,nodesConnectable:e.nodesConnectable,nodesFocusable:e.nodesFocusable,elementsSelectable:e.elementsSelectable,onError:e.onError});function M8(e){const{nodesDraggable:t,nodesConnectable:r,nodesFocusable:s,elementsSelectable:a,onError:i}=ur(Pte,Yr),l=Ete(e.onlyRenderVisibleElements),d=Dte();return n.jsx("div",{className:"react-flow__nodes",style:sp,children:l.map(u=>n.jsx(Lte,{id:u,nodeTypes:e.nodeTypes,nodeExtent:e.nodeExtent,onClick:e.onNodeClick,onMouseEnter:e.onNodeMouseEnter,onMouseMove:e.onNodeMouseMove,onMouseLeave:e.onNodeMouseLeave,onContextMenu:e.onNodeContextMenu,onDoubleClick:e.onNodeDoubleClick,noDragClassName:e.noDragClassName,noPanClassName:e.noPanClassName,rfId:e.rfId,disableKeyboardA11y:e.disableKeyboardA11y,resizeObserver:d,nodesDraggable:t,nodesConnectable:r,nodesFocusable:s,elementsSelectable:a,nodeClickDistance:e.nodeClickDistance,onError:i},u))})}M8.displayName="NodeRenderer";const Ote=g.memo(M8);function _te(e){return ur(g.useCallback(r=>{if(!e)return r.edges.map(a=>a.id);const s=[];if(r.width&&r.height)for(const a of r.edges){const i=r.nodeLookup.get(a.source),l=r.nodeLookup.get(a.target);i&&l&&_J({sourceNode:i,targetNode:l,width:r.width,height:r.height,transform:r.transform})&&s.push(a.id)}return s},[e]),Yr)}const zte=({color:e="none",strokeWidth:t=1})=>{const r={strokeWidth:t,...e&&{stroke:e}};return n.jsx("polyline",{className:"arrow",style:r,strokeLinecap:"round",fill:"none",strokeLinejoin:"round",points:"-5,-4 0,0 -5,4"})},$te=({color:e="none",strokeWidth:t=1})=>{const r={strokeWidth:t,...e&&{stroke:e,fill:e}};return n.jsx("polyline",{className:"arrowclosed",style:r,strokeLinecap:"round",strokeLinejoin:"round",points:"-5,-4 0,0 -5,4 -5,-4"})},d3={[Td.Arrow]:zte,[Td.ArrowClosed]:$te};function Bte(e){const t=Hr();return g.useMemo(()=>Object.prototype.hasOwnProperty.call(d3,e)?d3[e]:(t.getState().onError?.("009",Yi.error009(e)),null),[e])}const Hte=({id:e,type:t,color:r,width:s=12.5,height:a=12.5,markerUnits:i="strokeWidth",strokeWidth:l,orient:d="auto-start-reverse"})=>{const u=Bte(t);return u?n.jsx("marker",{className:"react-flow__arrowhead",id:e,markerWidth:`${s}`,markerHeight:`${a}`,viewBox:"-10 -10 20 20",markerUnits:i,orient:d,refX:"0",refY:"0",children:n.jsx(u,{color:r,strokeWidth:l})}):null},D8=({defaultColor:e,rfId:t})=>{const r=ur(i=>i.edges),s=ur(i=>i.defaultEdgeOptions),a=g.useMemo(()=>VJ(r,{id:t,defaultColor:e,defaultMarkerStart:s?.markerStart,defaultMarkerEnd:s?.markerEnd}),[r,s,t,e]);return a.length?n.jsx("svg",{className:"react-flow__marker","aria-hidden":"true",children:n.jsx("defs",{children:a.map(i=>n.jsx(Hte,{id:i.id,type:i.type,color:i.color,width:i.width,height:i.height,markerUnits:i.markerUnits,strokeWidth:i.strokeWidth,orient:i.orient},i.id))})}):null};D8.displayName="MarkerDefinitions";var Fte=g.memo(D8);function R8({x:e,y:t,label:r,labelStyle:s,labelShowBg:a=!0,labelBgStyle:i,labelBgPadding:l=[2,4],labelBgBorderRadius:d=2,children:u,className:m,...h}){const[p,y]=g.useState({x:1,y:0,width:0,height:0}),x=js(["react-flow__edge-textwrapper",m]),v=g.useRef(null);return g.useEffect(()=>{if(v.current){const j=v.current.getBBox();y({x:j.x,y:j.y,width:j.width,height:j.height})}},[r]),r?n.jsxs("g",{transform:`translate(${e-p.width/2} ${t-p.height/2})`,className:x,visibility:p.width?"visible":"hidden",...h,children:[a&&n.jsx("rect",{width:p.width+2*l[0],x:-l[0],y:-l[1],height:p.height+2*l[1],className:"react-flow__edge-textbg",style:i,rx:d,ry:d}),n.jsx("text",{className:"react-flow__edge-text",y:p.height/2,dy:"0.3em",ref:v,style:s,children:r}),u]}):null}R8.displayName="EdgeText";const qte=g.memo(R8);function ap({path:e,labelX:t,labelY:r,label:s,labelStyle:a,labelShowBg:i,labelBgStyle:l,labelBgPadding:d,labelBgBorderRadius:u,interactionWidth:m=20,...h}){return n.jsxs(n.Fragment,{children:[n.jsx("path",{...h,d:e,fill:"none",className:js(["react-flow__edge-path",h.className])}),m?n.jsx("path",{d:e,fill:"none",strokeOpacity:0,strokeWidth:m,className:"react-flow__edge-interaction"}):null,s&&Ci(t)&&Ci(r)?n.jsx(qte,{x:t,y:r,label:s,labelStyle:a,labelShowBg:i,labelBgStyle:l,labelBgPadding:d,labelBgBorderRadius:u}):null]})}function u3({pos:e,x1:t,y1:r,x2:s,y2:a}){return e===Jt.Left||e===Jt.Right?[.5*(t+s),r]:[t,.5*(r+a)]}function I8({sourceX:e,sourceY:t,sourcePosition:r=Jt.Bottom,targetX:s,targetY:a,targetPosition:i=Jt.Top}){const[l,d]=u3({pos:r,x1:e,y1:t,x2:s,y2:a}),[u,m]=u3({pos:i,x1:s,y1:a,x2:e,y2:t}),[h,p,y,x]=t8({sourceX:e,sourceY:t,targetX:s,targetY:a,sourceControlX:l,sourceControlY:d,targetControlX:u,targetControlY:m});return[`M${e},${t} C${l},${d} ${u},${m} ${s},${a}`,h,p,y,x]}function L8(e){return g.memo(({id:t,sourceX:r,sourceY:s,targetX:a,targetY:i,sourcePosition:l,targetPosition:d,label:u,labelStyle:m,labelShowBg:h,labelBgStyle:p,labelBgPadding:y,labelBgBorderRadius:x,style:v,markerEnd:j,markerStart:C,interactionWidth:w})=>{const[N,S,T]=I8({sourceX:r,sourceY:s,sourcePosition:l,targetX:a,targetY:i,targetPosition:d}),E=e.isInternal?void 0:t;return n.jsx(ap,{id:E,path:N,labelX:S,labelY:T,label:u,labelStyle:m,labelShowBg:h,labelBgStyle:p,labelBgPadding:y,labelBgBorderRadius:x,style:v,markerEnd:j,markerStart:C,interactionWidth:w})})}const Ute=L8({isInternal:!1}),P8=L8({isInternal:!0});Ute.displayName="SimpleBezierEdge";P8.displayName="SimpleBezierEdgeInternal";function O8(e){return g.memo(({id:t,sourceX:r,sourceY:s,targetX:a,targetY:i,label:l,labelStyle:d,labelShowBg:u,labelBgStyle:m,labelBgPadding:h,labelBgBorderRadius:p,style:y,sourcePosition:x=Jt.Bottom,targetPosition:v=Jt.Top,markerEnd:j,markerStart:C,pathOptions:w,interactionWidth:N})=>{const[S,T,E]=h1({sourceX:r,sourceY:s,sourcePosition:x,targetX:a,targetY:i,targetPosition:v,borderRadius:w?.borderRadius,offset:w?.offset,stepPosition:w?.stepPosition}),R=e.isInternal?void 0:t;return n.jsx(ap,{id:R,path:S,labelX:T,labelY:E,label:l,labelStyle:d,labelShowBg:u,labelBgStyle:m,labelBgPadding:h,labelBgBorderRadius:p,style:y,markerEnd:j,markerStart:C,interactionWidth:N})})}const _8=O8({isInternal:!1}),z8=O8({isInternal:!0});_8.displayName="SmoothStepEdge";z8.displayName="SmoothStepEdgeInternal";function $8(e){return g.memo(({id:t,...r})=>{const s=e.isInternal?void 0:t;return n.jsx(_8,{...r,id:s,pathOptions:g.useMemo(()=>({borderRadius:0,offset:r.pathOptions?.offset}),[r.pathOptions?.offset])})})}const Vte=$8({isInternal:!1}),B8=$8({isInternal:!0});Vte.displayName="StepEdge";B8.displayName="StepEdgeInternal";function H8(e){return g.memo(({id:t,sourceX:r,sourceY:s,targetX:a,targetY:i,label:l,labelStyle:d,labelShowBg:u,labelBgStyle:m,labelBgPadding:h,labelBgBorderRadius:p,style:y,markerEnd:x,markerStart:v,interactionWidth:j})=>{const[C,w,N]=s8({sourceX:r,sourceY:s,targetX:a,targetY:i}),S=e.isInternal?void 0:t;return n.jsx(ap,{id:S,path:C,labelX:w,labelY:N,label:l,labelStyle:d,labelShowBg:u,labelBgStyle:m,labelBgPadding:h,labelBgBorderRadius:p,style:y,markerEnd:x,markerStart:v,interactionWidth:j})})}const Kte=H8({isInternal:!1}),F8=H8({isInternal:!0});Kte.displayName="StraightEdge";F8.displayName="StraightEdgeInternal";function q8(e){return g.memo(({id:t,sourceX:r,sourceY:s,targetX:a,targetY:i,sourcePosition:l=Jt.Bottom,targetPosition:d=Jt.Top,label:u,labelStyle:m,labelShowBg:h,labelBgStyle:p,labelBgPadding:y,labelBgBorderRadius:x,style:v,markerEnd:j,markerStart:C,pathOptions:w,interactionWidth:N})=>{const[S,T,E]=n8({sourceX:r,sourceY:s,sourcePosition:l,targetX:a,targetY:i,targetPosition:d,curvature:w?.curvature}),R=e.isInternal?void 0:t;return n.jsx(ap,{id:R,path:S,labelX:T,labelY:E,label:u,labelStyle:m,labelShowBg:h,labelBgStyle:p,labelBgPadding:y,labelBgBorderRadius:x,style:v,markerEnd:j,markerStart:C,interactionWidth:N})})}const Wte=q8({isInternal:!1}),U8=q8({isInternal:!0});Wte.displayName="BezierEdge";U8.displayName="BezierEdgeInternal";const m3={default:U8,straight:F8,step:B8,smoothstep:z8,simplebezier:P8},f3={sourceX:null,sourceY:null,targetX:null,targetY:null,sourcePosition:null,targetPosition:null},Gte=(e,t,r)=>r===Jt.Left?e-t:r===Jt.Right?e+t:e,Yte=(e,t,r)=>r===Jt.Top?e-t:r===Jt.Bottom?e+t:e,h3="react-flow__edgeupdater";function p3({position:e,centerX:t,centerY:r,radius:s=10,onMouseDown:a,onMouseEnter:i,onMouseOut:l,type:d}){return n.jsx("circle",{onMouseDown:a,onMouseEnter:i,onMouseOut:l,className:js([h3,`${h3}-${d}`]),cx:Gte(t,s,e),cy:Yte(r,s,e),r:s,stroke:"transparent",fill:"transparent"})}function Xte({isReconnectable:e,reconnectRadius:t,edge:r,sourceX:s,sourceY:a,targetX:i,targetY:l,sourcePosition:d,targetPosition:u,onReconnect:m,onReconnectStart:h,onReconnectEnd:p,setReconnecting:y,setUpdateHover:x}){const v=Hr(),j=(T,E)=>{if(T.button!==0)return;const{autoPanOnConnect:R,domNode:I,connectionMode:z,connectionRadius:B,lib:D,onConnectStart:V,cancelConnection:Y,nodeLookup:F,rfId:L,panBy:O,updateConnection:M}=v.getState(),$=E.type==="target",W=(q,Z)=>{y(!1),p?.(q,r,E.type,Z)},U=q=>m?.(r,q),H=(q,Z)=>{y(!0),h?.(T,r,E.type),V?.(q,Z)};x1.onPointerDown(T.nativeEvent,{autoPanOnConnect:R,connectionMode:z,connectionRadius:B,domNode:I,handleId:E.id,nodeId:E.nodeId,nodeLookup:F,isTarget:$,edgeUpdaterType:E.type,lib:D,flowId:L,cancelConnection:Y,panBy:O,isValidConnection:(...q)=>v.getState().isValidConnection?.(...q)??!0,onConnect:U,onConnectStart:H,onConnectEnd:(...q)=>v.getState().onConnectEnd?.(...q),onReconnectEnd:W,updateConnection:M,getTransform:()=>v.getState().transform,getFromHandle:()=>v.getState().connection.fromHandle,dragThreshold:v.getState().connectionDragThreshold,handleDomNode:T.currentTarget})},C=T=>j(T,{nodeId:r.target,id:r.targetHandle??null,type:"target"}),w=T=>j(T,{nodeId:r.source,id:r.sourceHandle??null,type:"source"}),N=()=>x(!0),S=()=>x(!1);return n.jsxs(n.Fragment,{children:[(e===!0||e==="source")&&n.jsx(p3,{position:d,centerX:s,centerY:a,radius:t,onMouseDown:C,onMouseEnter:N,onMouseOut:S,type:"source"}),(e===!0||e==="target")&&n.jsx(p3,{position:u,centerX:i,centerY:l,radius:t,onMouseDown:w,onMouseEnter:N,onMouseOut:S,type:"target"})]})}function Qte({id:e,edgesFocusable:t,edgesReconnectable:r,elementsSelectable:s,onClick:a,onDoubleClick:i,onContextMenu:l,onMouseEnter:d,onMouseMove:u,onMouseLeave:m,reconnectRadius:h,onReconnect:p,onReconnectStart:y,onReconnectEnd:x,rfId:v,edgeTypes:j,noPanClassName:C,onError:w,disableKeyboardA11y:N}){let S=ur(Be=>Be.edgeLookup.get(e));const T=ur(Be=>Be.defaultEdgeOptions);S=T?{...T,...S}:S;let E=S.type||"default",R=j?.[E]||m3[E];R===void 0&&(w?.("011",Yi.error011(E)),E="default",R=j?.default||m3.default);const I=!!(S.focusable||t&&typeof S.focusable>"u"),z=typeof p<"u"&&(S.reconnectable||r&&typeof S.reconnectable>"u"),B=!!(S.selectable||s&&typeof S.selectable>"u"),D=g.useRef(null),[V,Y]=g.useState(!1),[F,L]=g.useState(!1),O=Hr(),{zIndex:M,sourceX:$,sourceY:W,targetX:U,targetY:H,sourcePosition:q,targetPosition:Z}=ur(g.useCallback(Be=>{const Ne=Be.nodeLookup.get(S.source),he=Be.nodeLookup.get(S.target);if(!Ne||!he)return{zIndex:S.zIndex,...f3};const _e=UJ({id:e,sourceNode:Ne,targetNode:he,sourceHandle:S.sourceHandle||null,targetHandle:S.targetHandle||null,connectionMode:Be.connectionMode,onError:w});return{zIndex:OJ({selected:S.selected,zIndex:S.zIndex,sourceNode:Ne,targetNode:he,elevateOnSelect:Be.elevateEdgesOnSelect,zIndexMode:Be.zIndexMode}),..._e||f3}},[S.source,S.target,S.sourceHandle,S.targetHandle,S.selected,S.zIndex]),Yr),_=g.useMemo(()=>S.markerStart?`url('#${p1(S.markerStart,v)}')`:void 0,[S.markerStart,v]),J=g.useMemo(()=>S.markerEnd?`url('#${p1(S.markerEnd,v)}')`:void 0,[S.markerEnd,v]);if(S.hidden||$===null||W===null||U===null||H===null)return null;const X=Be=>{const{addSelectedEdges:Ne,unselectNodesAndEdges:he,multiSelectionActive:_e}=O.getState();B&&(O.setState({nodesSelectionActive:!1}),S.selected&&_e?(he({nodes:[],edges:[S]}),D.current?.blur()):Ne([e])),a&&a(Be,S)},ee=i?Be=>{i(Be,{...S})}:void 0,te=l?Be=>{l(Be,{...S})}:void 0,G=d?Be=>{d(Be,{...S})}:void 0,ue=u?Be=>{u(Be,{...S})}:void 0,Se=m?Be=>{m(Be,{...S})}:void 0,Ce=Be=>{if(!N&&H7.includes(Be.key)&&B){const{unselectNodesAndEdges:Ne,addSelectedEdges:he}=O.getState();Be.key==="Escape"?(D.current?.blur(),Ne({edges:[S]})):he([e])}};return n.jsx("svg",{style:{zIndex:M},children:n.jsxs("g",{className:js(["react-flow__edge",`react-flow__edge-${E}`,S.className,C,{selected:S.selected,animated:S.animated,inactive:!B&&!a,updating:V,selectable:B}]),onClick:X,onDoubleClick:ee,onContextMenu:te,onMouseEnter:G,onMouseMove:ue,onMouseLeave:Se,onKeyDown:I?Ce:void 0,tabIndex:I?0:void 0,role:S.ariaRole??(I?"group":"img"),"aria-roledescription":"edge","data-id":e,"data-testid":`rf__edge-${e}`,"aria-label":S.ariaLabel===null?void 0:S.ariaLabel||`Edge from ${S.source} to ${S.target}`,"aria-describedby":I?`${y8}-${v}`:void 0,ref:D,...S.domAttributes,children:[!F&&n.jsx(R,{id:e,source:S.source,target:S.target,type:S.type,selected:S.selected,animated:S.animated,selectable:B,deletable:S.deletable??!0,label:S.label,labelStyle:S.labelStyle,labelShowBg:S.labelShowBg,labelBgStyle:S.labelBgStyle,labelBgPadding:S.labelBgPadding,labelBgBorderRadius:S.labelBgBorderRadius,sourceX:$,sourceY:W,targetX:U,targetY:H,sourcePosition:q,targetPosition:Z,data:S.data,style:S.style,sourceHandleId:S.sourceHandle,targetHandleId:S.targetHandle,markerStart:_,markerEnd:J,pathOptions:"pathOptions"in S?S.pathOptions:void 0,interactionWidth:S.interactionWidth}),z&&n.jsx(Xte,{edge:S,isReconnectable:z,reconnectRadius:h,onReconnect:p,onReconnectStart:y,onReconnectEnd:x,sourceX:$,sourceY:W,targetX:U,targetY:H,sourcePosition:q,targetPosition:Z,setUpdateHover:Y,setReconnecting:L})]})})}var Zte=g.memo(Qte);const Jte=e=>({edgesFocusable:e.edgesFocusable,edgesReconnectable:e.edgesReconnectable,elementsSelectable:e.elementsSelectable,connectionMode:e.connectionMode,onError:e.onError});function V8({defaultMarkerColor:e,onlyRenderVisibleElements:t,rfId:r,edgeTypes:s,noPanClassName:a,onReconnect:i,onEdgeContextMenu:l,onEdgeMouseEnter:d,onEdgeMouseMove:u,onEdgeMouseLeave:m,onEdgeClick:h,reconnectRadius:p,onEdgeDoubleClick:y,onReconnectStart:x,onReconnectEnd:v,disableKeyboardA11y:j}){const{edgesFocusable:C,edgesReconnectable:w,elementsSelectable:N,onError:S}=ur(Jte,Yr),T=_te(t);return n.jsxs("div",{className:"react-flow__edges",children:[n.jsx(Fte,{defaultColor:e,rfId:r}),T.map(E=>n.jsx(Zte,{id:E,edgesFocusable:C,edgesReconnectable:w,elementsSelectable:N,noPanClassName:a,onReconnect:i,onContextMenu:l,onMouseEnter:d,onMouseMove:u,onMouseLeave:m,onClick:h,reconnectRadius:p,onDoubleClick:y,onReconnectStart:x,onReconnectEnd:v,rfId:r,onError:S,edgeTypes:s,disableKeyboardA11y:j},E))]})}V8.displayName="EdgeRenderer";const ene=g.memo(V8),tne=e=>`translate(${e.transform[0]}px,${e.transform[1]}px) scale(${e.transform[2]})`;function nne({children:e}){const t=ur(tne);return n.jsx("div",{className:"react-flow__viewport xyflow__viewport react-flow__container",style:{transform:t},children:e})}function rne(e){const t=My(),r=g.useRef(!1);g.useEffect(()=>{!r.current&&t.viewportInitialized&&e&&(setTimeout(()=>e(t),1),r.current=!0)},[e,t.viewportInitialized])}const sne=e=>e.panZoom?.syncViewport;function ane(e){const t=ur(sne),r=Hr();return g.useEffect(()=>{e&&(t?.(e),r.setState({transform:[e.x,e.y,e.zoom]}))},[e,t]),null}function ine(e){return e.connection.inProgress?{...e.connection,to:_0(e.connection.to,e.transform)}:{...e.connection}}function one(e){return ine}function lne(e){const t=one();return ur(t,Yr)}const cne=e=>({nodesConnectable:e.nodesConnectable,isValid:e.connection.isValid,inProgress:e.connection.inProgress,width:e.width,height:e.height});function dne({containerStyle:e,style:t,type:r,component:s}){const{nodesConnectable:a,width:i,height:l,isValid:d,inProgress:u}=ur(cne,Yr);return!(i&&a&&u)?null:n.jsx("svg",{style:e,width:i,height:l,className:"react-flow__connectionline react-flow__container",children:n.jsx("g",{className:js(["react-flow__connection",U7(d)]),children:n.jsx(K8,{style:t,type:r,CustomComponent:s,isValid:d})})})}const K8=({style:e,type:t=xl.Bezier,CustomComponent:r,isValid:s})=>{const{inProgress:a,from:i,fromNode:l,fromHandle:d,fromPosition:u,to:m,toNode:h,toHandle:p,toPosition:y,pointer:x}=lne();if(!a)return;if(r)return n.jsx(r,{connectionLineType:t,connectionLineStyle:e,fromNode:l,fromHandle:d,fromX:i.x,fromY:i.y,toX:m.x,toY:m.y,fromPosition:u,toPosition:y,connectionStatus:U7(s),toNode:h,toHandle:p,pointer:x});let v="";const j={sourceX:i.x,sourceY:i.y,sourcePosition:u,targetX:m.x,targetY:m.y,targetPosition:y};switch(t){case xl.Bezier:[v]=n8(j);break;case xl.SimpleBezier:[v]=I8(j);break;case xl.Step:[v]=h1({...j,borderRadius:0});break;case xl.SmoothStep:[v]=h1(j);break;default:[v]=s8(j)}return n.jsx("path",{d:v,fill:"none",className:"react-flow__connection-path",style:e})};K8.displayName="ConnectionLine";const une={};function g3(e=une){g.useRef(e),Hr(),g.useEffect(()=>{},[e])}function mne(){Hr(),g.useRef(!1),g.useEffect(()=>{},[])}function W8({nodeTypes:e,edgeTypes:t,onInit:r,onNodeClick:s,onEdgeClick:a,onNodeDoubleClick:i,onEdgeDoubleClick:l,onNodeMouseEnter:d,onNodeMouseMove:u,onNodeMouseLeave:m,onNodeContextMenu:h,onSelectionContextMenu:p,onSelectionStart:y,onSelectionEnd:x,connectionLineType:v,connectionLineStyle:j,connectionLineComponent:C,connectionLineContainerStyle:w,selectionKeyCode:N,selectionOnDrag:S,selectionMode:T,multiSelectionKeyCode:E,panActivationKeyCode:R,zoomActivationKeyCode:I,deleteKeyCode:z,onlyRenderVisibleElements:B,elementsSelectable:D,defaultViewport:V,translateExtent:Y,minZoom:F,maxZoom:L,preventScrolling:O,defaultMarkerColor:M,zoomOnScroll:$,zoomOnPinch:W,panOnScroll:U,panOnScrollSpeed:H,panOnScrollMode:q,zoomOnDoubleClick:Z,panOnDrag:_,onPaneClick:J,onPaneMouseEnter:X,onPaneMouseMove:ee,onPaneMouseLeave:te,onPaneScroll:G,onPaneContextMenu:ue,paneClickDistance:Se,nodeClickDistance:Ce,onEdgeContextMenu:Be,onEdgeMouseEnter:Ne,onEdgeMouseMove:he,onEdgeMouseLeave:_e,reconnectRadius:Ee,onReconnect:Ye,onReconnectStart:Ze,onReconnectEnd:mt,noDragClassName:it,noWheelClassName:Lt,noPanClassName:ht,disableKeyboardA11y:ne,nodeExtent:me,rfId:be,viewport:se,onViewportChange:fe}){return g3(e),g3(t),mne(),rne(r),ane(se),n.jsx(Tte,{onPaneClick:J,onPaneMouseEnter:X,onPaneMouseMove:ee,onPaneMouseLeave:te,onPaneContextMenu:ue,onPaneScroll:G,paneClickDistance:Se,deleteKeyCode:z,selectionKeyCode:N,selectionOnDrag:S,selectionMode:T,onSelectionStart:y,onSelectionEnd:x,multiSelectionKeyCode:E,panActivationKeyCode:R,zoomActivationKeyCode:I,elementsSelectable:D,zoomOnScroll:$,zoomOnPinch:W,zoomOnDoubleClick:Z,panOnScroll:U,panOnScrollSpeed:H,panOnScrollMode:q,panOnDrag:_,defaultViewport:V,translateExtent:Y,minZoom:F,maxZoom:L,onSelectionContextMenu:p,preventScrolling:O,noDragClassName:it,noWheelClassName:Lt,noPanClassName:ht,disableKeyboardA11y:ne,onViewportChange:fe,isControlledViewport:!!se,children:n.jsxs(nne,{children:[n.jsx(ene,{edgeTypes:t,onEdgeClick:a,onEdgeDoubleClick:l,onReconnect:Ye,onReconnectStart:Ze,onReconnectEnd:mt,onlyRenderVisibleElements:B,onEdgeContextMenu:Be,onEdgeMouseEnter:Ne,onEdgeMouseMove:he,onEdgeMouseLeave:_e,reconnectRadius:Ee,defaultMarkerColor:M,noPanClassName:ht,disableKeyboardA11y:ne,rfId:be}),n.jsx(dne,{style:j,type:v,component:C,containerStyle:w}),n.jsx("div",{className:"react-flow__edgelabel-renderer"}),n.jsx(Ote,{nodeTypes:e,onNodeClick:s,onNodeDoubleClick:i,onNodeMouseEnter:d,onNodeMouseMove:u,onNodeMouseLeave:m,onNodeContextMenu:h,nodeClickDistance:Ce,onlyRenderVisibleElements:B,noPanClassName:ht,noDragClassName:it,disableKeyboardA11y:ne,nodeExtent:me,rfId:be}),n.jsx("div",{className:"react-flow__viewport-portal"})]})})}W8.displayName="GraphView";const fne=g.memo(W8),x3=({nodes:e,edges:t,defaultNodes:r,defaultEdges:s,width:a,height:i,fitView:l,fitViewOptions:d,minZoom:u=.5,maxZoom:m=2,nodeOrigin:h,nodeExtent:p,zIndexMode:y="basic"}={})=>{const x=new Map,v=new Map,j=new Map,C=new Map,w=s??t??[],N=r??e??[],S=h??[0,0],T=p??b0;o8(j,C,w);const E=g1(N,x,v,{nodeOrigin:S,nodeExtent:T,zIndexMode:y});let R=[0,0,1];if(l&&a&&i){const I=P0(x,{filter:V=>!!((V.width||V.initialWidth)&&(V.height||V.initialHeight))}),{x:z,y:B,zoom:D}=jy(I,a,i,u,m,d?.padding??.1);R=[z,B,D]}return{rfId:"1",width:a??0,height:i??0,transform:R,nodes:N,nodesInitialized:E,nodeLookup:x,parentLookup:v,edges:w,edgeLookup:C,connectionLookup:j,onNodesChange:null,onEdgesChange:null,hasDefaultNodes:r!==void 0,hasDefaultEdges:s!==void 0,panZoom:null,minZoom:u,maxZoom:m,translateExtent:b0,nodeExtent:T,nodesSelectionActive:!1,userSelectionActive:!1,userSelectionRect:null,connectionMode:Cd.Strict,domNode:null,paneDragging:!1,noPanClassName:"nopan",nodeOrigin:S,nodeDragThreshold:1,connectionDragThreshold:1,snapGrid:[15,15],snapToGrid:!1,nodesDraggable:!0,nodesConnectable:!0,nodesFocusable:!0,edgesFocusable:!0,edgesReconnectable:!0,elementsSelectable:!0,elevateNodesOnSelect:!0,elevateEdgesOnSelect:!0,selectNodesOnDrag:!0,multiSelectionActive:!1,fitViewQueued:l??!1,fitViewOptions:d,fitViewResolver:null,connection:{...q7},connectionClickStartHandle:null,connectOnClick:!0,ariaLiveMessage:"",autoPanOnConnect:!0,autoPanOnNodeDrag:!0,autoPanOnNodeFocus:!0,autoPanSpeed:15,connectionRadius:20,onError:MJ,isValidConnection:void 0,onSelectionChangeHandlers:[],lib:"react",debug:!1,ariaLabelConfig:F7,zIndexMode:y,onNodesChangeMiddlewareMap:new Map,onEdgesChangeMiddlewareMap:new Map}},hne=({nodes:e,edges:t,defaultNodes:r,defaultEdges:s,width:a,height:i,fitView:l,fitViewOptions:d,minZoom:u,maxZoom:m,nodeOrigin:h,nodeExtent:p,zIndexMode:y})=>Ree((x,v)=>{async function j(){const{nodeLookup:C,panZoom:w,fitViewOptions:N,fitViewResolver:S,width:T,height:E,minZoom:R,maxZoom:I}=v();w&&(await AJ({nodes:C,width:T,height:E,panZoom:w,minZoom:R,maxZoom:I},N),S?.resolve(!0),x({fitViewResolver:null}))}return{...x3({nodes:e,edges:t,width:a,height:i,fitView:l,fitViewOptions:d,minZoom:u,maxZoom:m,nodeOrigin:h,nodeExtent:p,defaultNodes:r,defaultEdges:s,zIndexMode:y}),setNodes:C=>{const{nodeLookup:w,parentLookup:N,nodeOrigin:S,elevateNodesOnSelect:T,fitViewQueued:E,zIndexMode:R}=v(),I=g1(C,w,N,{nodeOrigin:S,nodeExtent:p,elevateNodesOnSelect:T,checkEquality:!0,zIndexMode:R});E&&I?(j(),x({nodes:C,nodesInitialized:I,fitViewQueued:!1,fitViewOptions:void 0})):x({nodes:C,nodesInitialized:I})},setEdges:C=>{const{connectionLookup:w,edgeLookup:N}=v();o8(w,N,C),x({edges:C})},setDefaultNodesAndEdges:(C,w)=>{if(C){const{setNodes:N}=v();N(C),x({hasDefaultNodes:!0})}if(w){const{setEdges:N}=v();N(w),x({hasDefaultEdges:!0})}},updateNodeInternals:C=>{const{triggerNodeChanges:w,nodeLookup:N,parentLookup:S,domNode:T,nodeOrigin:E,nodeExtent:R,debug:I,fitViewQueued:z,zIndexMode:B}=v(),{changes:D,updatedInternals:V}=ZJ(C,N,S,T,E,R,B);V&&(GJ(N,S,{nodeOrigin:E,nodeExtent:R,zIndexMode:B}),z?(j(),x({fitViewQueued:!1,fitViewOptions:void 0})):x({}),D?.length>0&&(I&&console.log("React Flow: trigger node changes",D),w?.(D)))},updateNodePositions:(C,w=!1)=>{const N=[];let S=[];const{nodeLookup:T,triggerNodeChanges:E,connection:R,updateConnection:I,onNodesChangeMiddlewareMap:z}=v();for(const[B,D]of C){const V=T.get(B),Y=!!(V?.expandParent&&V?.parentId&&D?.position),F={id:B,type:"position",position:Y?{x:Math.max(0,D.position.x),y:Math.max(0,D.position.y)}:D.position,dragging:w};if(V&&R.inProgress&&R.fromNode.id===V.id){const L=pc(V,R.fromHandle,Jt.Left,!0);I({...R,from:L})}Y&&V.parentId&&N.push({id:B,parentId:V.parentId,rect:{...D.internals.positionAbsolute,width:D.measured.width??0,height:D.measured.height??0}}),S.push(F)}if(N.length>0){const{parentLookup:B,nodeOrigin:D}=v(),V=Ey(N,T,B,D);S.push(...V)}for(const B of z.values())S=B(S);E(S)},triggerNodeChanges:C=>{const{onNodesChange:w,setNodes:N,nodes:S,hasDefaultNodes:T,debug:E}=v();if(C?.length){if(T){const R=k8(C,S);N(R)}E&&console.log("React Flow: trigger node changes",C),w?.(C)}},triggerEdgeChanges:C=>{const{onEdgesChange:w,setEdges:N,edges:S,hasDefaultEdges:T,debug:E}=v();if(C?.length){if(T){const R=j8(C,S);N(R)}E&&console.log("React Flow: trigger edge changes",C),w?.(C)}},addSelectedNodes:C=>{const{multiSelectionActive:w,edgeLookup:N,nodeLookup:S,triggerNodeChanges:T,triggerEdgeChanges:E}=v();if(w){const R=C.map(I=>Jl(I,!0));T(R);return}T(fd(S,new Set([...C]),!0)),E(fd(N))},addSelectedEdges:C=>{const{multiSelectionActive:w,edgeLookup:N,nodeLookup:S,triggerNodeChanges:T,triggerEdgeChanges:E}=v();if(w){const R=C.map(I=>Jl(I,!0));E(R);return}E(fd(N,new Set([...C]))),T(fd(S,new Set,!0))},unselectNodesAndEdges:({nodes:C,edges:w}={})=>{const{edges:N,nodes:S,nodeLookup:T,triggerNodeChanges:E,triggerEdgeChanges:R}=v(),I=C||S,z=w||N,B=[];for(const V of I){if(!V.selected)continue;const Y=T.get(V.id);Y&&(Y.selected=!1),B.push(Jl(V.id,!1))}const D=[];for(const V of z)V.selected&&D.push(Jl(V.id,!1));E(B),R(D)},setMinZoom:C=>{const{panZoom:w,maxZoom:N}=v();w?.setScaleExtent([C,N]),x({minZoom:C})},setMaxZoom:C=>{const{panZoom:w,minZoom:N}=v();w?.setScaleExtent([N,C]),x({maxZoom:C})},setTranslateExtent:C=>{v().panZoom?.setTranslateExtent(C),x({translateExtent:C})},resetSelectedElements:()=>{const{edges:C,nodes:w,triggerNodeChanges:N,triggerEdgeChanges:S,elementsSelectable:T}=v();if(!T)return;const E=w.reduce((I,z)=>z.selected?[...I,Jl(z.id,!1)]:I,[]),R=C.reduce((I,z)=>z.selected?[...I,Jl(z.id,!1)]:I,[]);N(E),S(R)},setNodeExtent:C=>{const{nodes:w,nodeLookup:N,parentLookup:S,nodeOrigin:T,elevateNodesOnSelect:E,nodeExtent:R,zIndexMode:I}=v();C[0][0]===R[0][0]&&C[0][1]===R[0][1]&&C[1][0]===R[1][0]&&C[1][1]===R[1][1]||(g1(w,N,S,{nodeOrigin:T,nodeExtent:C,elevateNodesOnSelect:E,checkEquality:!1,zIndexMode:I}),x({nodeExtent:C}))},panBy:C=>{const{transform:w,width:N,height:S,panZoom:T,translateExtent:E}=v();return JJ({delta:C,panZoom:T,transform:w,translateExtent:E,width:N,height:S})},setCenter:async(C,w,N)=>{const{width:S,height:T,maxZoom:E,panZoom:R}=v();if(!R)return Promise.resolve(!1);const I=typeof N?.zoom<"u"?N.zoom:E;return await R.setViewport({x:S/2-C*I,y:T/2-w*I,zoom:I},{duration:N?.duration,ease:N?.ease,interpolate:N?.interpolate}),Promise.resolve(!0)},cancelConnection:()=>{x({connection:{...q7}})},updateConnection:C=>{x({connection:C})},reset:()=>x({...x3()})}},Object.is);function pne({initialNodes:e,initialEdges:t,defaultNodes:r,defaultEdges:s,initialWidth:a,initialHeight:i,initialMinZoom:l,initialMaxZoom:d,initialFitViewOptions:u,fitView:m,nodeOrigin:h,nodeExtent:p,zIndexMode:y,children:x}){const[v]=g.useState(()=>hne({nodes:e,edges:t,defaultNodes:r,defaultEdges:s,width:a,height:i,fitView:m,minZoom:l,maxZoom:d,fitViewOptions:u,nodeOrigin:h,nodeExtent:p,zIndexMode:y}));return n.jsx(Iee,{value:v,children:n.jsx(nte,{children:x})})}function gne({children:e,nodes:t,edges:r,defaultNodes:s,defaultEdges:a,width:i,height:l,fitView:d,fitViewOptions:u,minZoom:m,maxZoom:h,nodeOrigin:p,nodeExtent:y,zIndexMode:x}){return g.useContext(np)?n.jsx(n.Fragment,{children:e}):n.jsx(pne,{initialNodes:t,initialEdges:r,defaultNodes:s,defaultEdges:a,initialWidth:i,initialHeight:l,fitView:d,initialFitViewOptions:u,initialMinZoom:m,initialMaxZoom:h,nodeOrigin:p,nodeExtent:y,zIndexMode:x,children:e})}const xne={width:"100%",height:"100%",overflow:"hidden",position:"relative",zIndex:0};function bne({nodes:e,edges:t,defaultNodes:r,defaultEdges:s,className:a,nodeTypes:i,edgeTypes:l,onNodeClick:d,onEdgeClick:u,onInit:m,onMove:h,onMoveStart:p,onMoveEnd:y,onConnect:x,onConnectStart:v,onConnectEnd:j,onClickConnectStart:C,onClickConnectEnd:w,onNodeMouseEnter:N,onNodeMouseMove:S,onNodeMouseLeave:T,onNodeContextMenu:E,onNodeDoubleClick:R,onNodeDragStart:I,onNodeDrag:z,onNodeDragStop:B,onNodesDelete:D,onEdgesDelete:V,onDelete:Y,onSelectionChange:F,onSelectionDragStart:L,onSelectionDrag:O,onSelectionDragStop:M,onSelectionContextMenu:$,onSelectionStart:W,onSelectionEnd:U,onBeforeDelete:H,connectionMode:q,connectionLineType:Z=xl.Bezier,connectionLineStyle:_,connectionLineComponent:J,connectionLineContainerStyle:X,deleteKeyCode:ee="Backspace",selectionKeyCode:te="Shift",selectionOnDrag:G=!1,selectionMode:ue=y0.Full,panActivationKeyCode:Se="Space",multiSelectionKeyCode:Ce=w0()?"Meta":"Control",zoomActivationKeyCode:Be=w0()?"Meta":"Control",snapToGrid:Ne,snapGrid:he,onlyRenderVisibleElements:_e=!1,selectNodesOnDrag:Ee,nodesDraggable:Ye,autoPanOnNodeFocus:Ze,nodesConnectable:mt,nodesFocusable:it,nodeOrigin:Lt=v8,edgesFocusable:ht,edgesReconnectable:ne,elementsSelectable:me=!0,defaultViewport:be=Kee,minZoom:se=.5,maxZoom:fe=2,translateExtent:He=b0,preventScrolling:Ae=!0,nodeExtent:et,defaultMarkerColor:pe="#b1b1b7",zoomOnScroll:Fe=!0,zoomOnPinch:Ve=!0,panOnScroll:nt=!1,panOnScrollSpeed:gt=.5,panOnScrollMode:rt=oc.Free,zoomOnDoubleClick:Et=!0,panOnDrag:je=!0,onPaneClick:Re,onPaneMouseEnter:We,onPaneMouseMove:Vt,onPaneMouseLeave:ln,onPaneScroll:en,onPaneContextMenu:vn,paneClickDistance:In=1,nodeClickDistance:Zt=0,children:cn,onReconnect:Gn,onReconnectStart:Ln,onReconnectEnd:Lr,onEdgeContextMenu:Qr,onEdgeDoubleClick:mr,onEdgeMouseEnter:Ge,onEdgeMouseMove:Ht,onEdgeMouseLeave:Wt,reconnectRadius:tn=10,onNodesChange:zn,onEdgesChange:Mn,noDragClassName:wn="nodrag",noWheelClassName:Dn="nowheel",noPanClassName:$n="nopan",fitView:Sn,fitViewOptions:Bn,connectOnClick:Vn,attributionPosition:Qn,proOptions:Pe,defaultEdgeOptions:Ct,elevateNodesOnSelect:ve=!0,elevateEdgesOnSelect:tt=!1,disableKeyboardA11y:Tt=!1,autoPanOnConnect:$t,autoPanOnNodeDrag:sn,autoPanSpeed:Zn,connectionRadius:Xt,isValidConnection:ye,onError:lt,style:vt,id:Bt,nodeDragThreshold:dn,connectionDragThreshold:Dt,viewport:Pn,onViewportChange:tr,width:Hn,height:nr,colorMode:On="light",debug:on,onScroll:cr,ariaLabelConfig:Fr,zIndexMode:dr="basic",...br},fr){const Is=Bt||"1",ga=Xee(On),xa=g.useCallback(Pr=>{Pr.currentTarget.scrollTo({top:0,left:0,behavior:"instant"}),cr?.(Pr)},[cr]);return n.jsx("div",{"data-testid":"rf__wrapper",...br,onScroll:xa,style:{...vt,...xne},ref:fr,className:js(["react-flow",a,ga]),id:Bt,role:"application",children:n.jsxs(gne,{nodes:e,edges:t,width:Hn,height:nr,fitView:Sn,fitViewOptions:Bn,minZoom:se,maxZoom:fe,nodeOrigin:Lt,nodeExtent:et,zIndexMode:dr,children:[n.jsx(fne,{onInit:m,onNodeClick:d,onEdgeClick:u,onNodeMouseEnter:N,onNodeMouseMove:S,onNodeMouseLeave:T,onNodeContextMenu:E,onNodeDoubleClick:R,nodeTypes:i,edgeTypes:l,connectionLineType:Z,connectionLineStyle:_,connectionLineComponent:J,connectionLineContainerStyle:X,selectionKeyCode:te,selectionOnDrag:G,selectionMode:ue,deleteKeyCode:ee,multiSelectionKeyCode:Ce,panActivationKeyCode:Se,zoomActivationKeyCode:Be,onlyRenderVisibleElements:_e,defaultViewport:be,translateExtent:He,minZoom:se,maxZoom:fe,preventScrolling:Ae,zoomOnScroll:Fe,zoomOnPinch:Ve,zoomOnDoubleClick:Et,panOnScroll:nt,panOnScrollSpeed:gt,panOnScrollMode:rt,panOnDrag:je,onPaneClick:Re,onPaneMouseEnter:We,onPaneMouseMove:Vt,onPaneMouseLeave:ln,onPaneScroll:en,onPaneContextMenu:vn,paneClickDistance:In,nodeClickDistance:Zt,onSelectionContextMenu:$,onSelectionStart:W,onSelectionEnd:U,onReconnect:Gn,onReconnectStart:Ln,onReconnectEnd:Lr,onEdgeContextMenu:Qr,onEdgeDoubleClick:mr,onEdgeMouseEnter:Ge,onEdgeMouseMove:Ht,onEdgeMouseLeave:Wt,reconnectRadius:tn,defaultMarkerColor:pe,noDragClassName:wn,noWheelClassName:Dn,noPanClassName:$n,rfId:Is,disableKeyboardA11y:Tt,nodeExtent:et,viewport:Pn,onViewportChange:tr}),n.jsx(Yee,{nodes:e,edges:t,defaultNodes:r,defaultEdges:s,onConnect:x,onConnectStart:v,onConnectEnd:j,onClickConnectStart:C,onClickConnectEnd:w,nodesDraggable:Ye,autoPanOnNodeFocus:Ze,nodesConnectable:mt,nodesFocusable:it,edgesFocusable:ht,edgesReconnectable:ne,elementsSelectable:me,elevateNodesOnSelect:ve,elevateEdgesOnSelect:tt,minZoom:se,maxZoom:fe,nodeExtent:et,onNodesChange:zn,onEdgesChange:Mn,snapToGrid:Ne,snapGrid:he,connectionMode:q,translateExtent:He,connectOnClick:Vn,defaultEdgeOptions:Ct,fitView:Sn,fitViewOptions:Bn,onNodesDelete:D,onEdgesDelete:V,onDelete:Y,onNodeDragStart:I,onNodeDrag:z,onNodeDragStop:B,onSelectionDrag:O,onSelectionDragStart:L,onSelectionDragStop:M,onMove:h,onMoveStart:p,onMoveEnd:y,noPanClassName:$n,nodeOrigin:Lt,rfId:Is,autoPanOnConnect:$t,autoPanOnNodeDrag:sn,autoPanSpeed:Zn,onError:lt,connectionRadius:Xt,isValidConnection:ye,selectNodesOnDrag:Ee,nodeDragThreshold:dn,connectionDragThreshold:Dt,onBeforeDelete:H,debug:on,ariaLabelConfig:Fr,zIndexMode:dr}),n.jsx(Vee,{onSelectionChange:F}),cn,n.jsx(Bee,{proOptions:Pe,position:Qn}),n.jsx($ee,{rfId:Is,disableKeyboardA11y:Tt})]})})}var yne=N8(bne);function vne(){const e=Hr();return g.useCallback(t=>{const{domNode:r,updateNodeInternals:s}=e.getState(),a=Array.isArray(t)?t:[t],i=new Map;a.forEach(l=>{const d=r?.querySelector(`.react-flow__node[data-id="${l}"]`);d&&i.set(l,{id:l,nodeElement:d,force:!0})}),requestAnimationFrame(()=>s(i,{triggerFitView:!1}))},[])}function wne(e){const[t,r]=g.useState(e),s=g.useCallback(a=>r(i=>k8(a,i)),[]);return[t,r,s]}function kne(e){const[t,r]=g.useState(e),s=g.useCallback(a=>r(i=>j8(a,i)),[]);return[t,r,s]}function jne({dimensions:e,lineWidth:t,variant:r,className:s}){return n.jsx("path",{strokeWidth:t,d:`M${e[0]/2} 0 V${e[1]} M0 ${e[1]/2} H${e[0]}`,className:js(["react-flow__background-pattern",r,s])})}function Nne({radius:e,className:t}){return n.jsx("circle",{cx:e,cy:e,r:e,className:js(["react-flow__background-pattern","dots",t])})}var vl;(function(e){e.Lines="lines",e.Dots="dots",e.Cross="cross"})(vl||(vl={}));const Sne={[vl.Dots]:1,[vl.Lines]:1,[vl.Cross]:6},Cne=e=>({transform:e.transform,patternId:`pattern-${e.rfId}`});function G8({id:e,variant:t=vl.Dots,gap:r=20,size:s,lineWidth:a=1,offset:i=0,color:l,bgColor:d,style:u,className:m,patternClassName:h}){const p=g.useRef(null),{transform:y,patternId:x}=ur(Cne,Yr),v=s||Sne[t],j=t===vl.Dots,C=t===vl.Cross,w=Array.isArray(r)?r:[r,r],N=[w[0]*y[2]||1,w[1]*y[2]||1],S=v*y[2],T=Array.isArray(i)?i:[i,i],E=C?[S,S]:N,R=[T[0]*y[2]||1+E[0]/2,T[1]*y[2]||1+E[1]/2],I=`${x}${e||""}`;return n.jsxs("svg",{className:js(["react-flow__background",m]),style:{...u,...sp,"--xy-background-color-props":d,"--xy-background-pattern-color-props":l},ref:p,"data-testid":"rf__background",children:[n.jsx("pattern",{id:I,x:y[0]%N[0],y:y[1]%N[1],width:N[0],height:N[1],patternUnits:"userSpaceOnUse",patternTransform:`translate(-${R[0]},-${R[1]})`,children:j?n.jsx(Nne,{radius:S/2,className:h}):n.jsx(jne,{dimensions:E,lineWidth:a,variant:t,className:h})}),n.jsx("rect",{x:"0",y:"0",width:"100%",height:"100%",fill:`url(#${I})`})]})}G8.displayName="Background";const Tne=g.memo(G8);function Ane(){return n.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 32 32",children:n.jsx("path",{d:"M32 18.133H18.133V32h-4.266V18.133H0v-4.266h13.867V0h4.266v13.867H32z"})})}function Ene(){return n.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 32 5",children:n.jsx("path",{d:"M0 0h32v4.2H0z"})})}function Mne(){return n.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 32 30",children:n.jsx("path",{d:"M3.692 4.63c0-.53.4-.938.939-.938h5.215V0H4.708C2.13 0 0 2.054 0 4.63v5.216h3.692V4.631zM27.354 0h-5.2v3.692h5.17c.53 0 .984.4.984.939v5.215H32V4.631A4.624 4.624 0 0027.354 0zm.954 24.83c0 .532-.4.94-.939.94h-5.215v3.768h5.215c2.577 0 4.631-2.13 4.631-4.707v-5.139h-3.692v5.139zm-23.677.94c-.531 0-.939-.4-.939-.94v-5.138H0v5.139c0 2.577 2.13 4.707 4.708 4.707h5.138V25.77H4.631z"})})}function Dne(){return n.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 25 32",children:n.jsx("path",{d:"M21.333 10.667H19.81V7.619C19.81 3.429 16.38 0 12.19 0 8 0 4.571 3.429 4.571 7.619v3.048H3.048A3.056 3.056 0 000 13.714v15.238A3.056 3.056 0 003.048 32h18.285a3.056 3.056 0 003.048-3.048V13.714a3.056 3.056 0 00-3.048-3.047zM12.19 24.533a3.056 3.056 0 01-3.047-3.047 3.056 3.056 0 013.047-3.048 3.056 3.056 0 013.048 3.048 3.056 3.056 0 01-3.048 3.047zm4.724-13.866H7.467V7.619c0-2.59 2.133-4.724 4.723-4.724 2.591 0 4.724 2.133 4.724 4.724v3.048z"})})}function Rne(){return n.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 25 32",children:n.jsx("path",{d:"M21.333 10.667H19.81V7.619C19.81 3.429 16.38 0 12.19 0c-4.114 1.828-1.37 2.133.305 2.438 1.676.305 4.42 2.59 4.42 5.181v3.048H3.047A3.056 3.056 0 000 13.714v15.238A3.056 3.056 0 003.048 32h18.285a3.056 3.056 0 003.048-3.048V13.714a3.056 3.056 0 00-3.048-3.047zM12.19 24.533a3.056 3.056 0 01-3.047-3.047 3.056 3.056 0 013.047-3.048 3.056 3.056 0 013.048 3.048 3.056 3.056 0 01-3.048 3.047z"})})}function Nf({children:e,className:t,...r}){return n.jsx("button",{type:"button",className:js(["react-flow__controls-button",t]),...r,children:e})}const Ine=e=>({isInteractive:e.nodesDraggable||e.nodesConnectable||e.elementsSelectable,minZoomReached:e.transform[2]<=e.minZoom,maxZoomReached:e.transform[2]>=e.maxZoom,ariaLabelConfig:e.ariaLabelConfig});function Y8({style:e,showZoom:t=!0,showFitView:r=!0,showInteractive:s=!0,fitViewOptions:a,onZoomIn:i,onZoomOut:l,onFitView:d,onInteractiveChange:u,className:m,children:h,position:p="bottom-left",orientation:y="vertical","aria-label":x}){const v=Hr(),{isInteractive:j,minZoomReached:C,maxZoomReached:w,ariaLabelConfig:N}=ur(Ine,Yr),{zoomIn:S,zoomOut:T,fitView:E}=My(),R=()=>{S(),i?.()},I=()=>{T(),l?.()},z=()=>{E(a),d?.()},B=()=>{v.setState({nodesDraggable:!j,nodesConnectable:!j,elementsSelectable:!j}),u?.(!j)},D=y==="horizontal"?"horizontal":"vertical";return n.jsxs(rp,{className:js(["react-flow__controls",D,m]),position:p,style:e,"data-testid":"rf__controls","aria-label":x??N["controls.ariaLabel"],children:[t&&n.jsxs(n.Fragment,{children:[n.jsx(Nf,{onClick:R,className:"react-flow__controls-zoomin",title:N["controls.zoomIn.ariaLabel"],"aria-label":N["controls.zoomIn.ariaLabel"],disabled:w,children:n.jsx(Ane,{})}),n.jsx(Nf,{onClick:I,className:"react-flow__controls-zoomout",title:N["controls.zoomOut.ariaLabel"],"aria-label":N["controls.zoomOut.ariaLabel"],disabled:C,children:n.jsx(Ene,{})})]}),r&&n.jsx(Nf,{className:"react-flow__controls-fitview",onClick:z,title:N["controls.fitView.ariaLabel"],"aria-label":N["controls.fitView.ariaLabel"],children:n.jsx(Mne,{})}),s&&n.jsx(Nf,{className:"react-flow__controls-interactive",onClick:B,title:N["controls.interactive.ariaLabel"],"aria-label":N["controls.interactive.ariaLabel"],children:j?n.jsx(Rne,{}):n.jsx(Dne,{})}),h]})}Y8.displayName="Controls";const Lne=g.memo(Y8);function Pne({id:e,x:t,y:r,width:s,height:a,style:i,color:l,strokeColor:d,strokeWidth:u,className:m,borderRadius:h,shapeRendering:p,selected:y,onClick:x}){const{background:v,backgroundColor:j}=i||{},C=l||v||j;return n.jsx("rect",{className:js(["react-flow__minimap-node",{selected:y},m]),x:t,y:r,rx:h,ry:h,width:s,height:a,style:{fill:C,stroke:d,strokeWidth:u},shapeRendering:p,onClick:x?w=>x(w,e):void 0})}const One=g.memo(Pne),_ne=e=>e.nodes.map(t=>t.id),ob=e=>e instanceof Function?e:()=>e;function zne({nodeStrokeColor:e,nodeColor:t,nodeClassName:r="",nodeBorderRadius:s=5,nodeStrokeWidth:a,nodeComponent:i=One,onClick:l}){const d=ur(_ne,Yr),u=ob(t),m=ob(e),h=ob(r),p=typeof window>"u"||window.chrome?"crispEdges":"geometricPrecision";return n.jsx(n.Fragment,{children:d.map(y=>n.jsx(Bne,{id:y,nodeColorFunc:u,nodeStrokeColorFunc:m,nodeClassNameFunc:h,nodeBorderRadius:s,nodeStrokeWidth:a,NodeComponent:i,onClick:l,shapeRendering:p},y))})}function $ne({id:e,nodeColorFunc:t,nodeStrokeColorFunc:r,nodeClassNameFunc:s,nodeBorderRadius:a,nodeStrokeWidth:i,shapeRendering:l,NodeComponent:d,onClick:u}){const{node:m,x:h,y:p,width:y,height:x}=ur(v=>{const j=v.nodeLookup.get(e);if(!j)return{node:void 0,x:0,y:0,width:0,height:0};const C=j.internals.userNode,{x:w,y:N}=j.internals.positionAbsolute,{width:S,height:T}=zo(C);return{node:C,x:w,y:N,width:S,height:T}},Yr);return!m||m.hidden||!X7(m)?null:n.jsx(d,{x:h,y:p,width:y,height:x,style:m.style,selected:!!m.selected,className:s(m),color:t(m),borderRadius:a,strokeColor:r(m),strokeWidth:i,shapeRendering:l,onClick:u,id:m.id})}const Bne=g.memo($ne);var Hne=g.memo(zne);const Fne=200,qne=150,Une=e=>!e.hidden,Vne=e=>{const t={x:-e.transform[0]/e.transform[2],y:-e.transform[1]/e.transform[2],width:e.width/e.transform[2],height:e.height/e.transform[2]};return{viewBB:t,boundingRect:e.nodeLookup.size>0?Y7(P0(e.nodeLookup,{filter:Une}),t):t,rfId:e.rfId,panZoom:e.panZoom,translateExtent:e.translateExtent,flowWidth:e.width,flowHeight:e.height,ariaLabelConfig:e.ariaLabelConfig}},Kne="react-flow__minimap-desc";function X8({style:e,className:t,nodeStrokeColor:r,nodeColor:s,nodeClassName:a="",nodeBorderRadius:i=5,nodeStrokeWidth:l,nodeComponent:d,bgColor:u,maskColor:m,maskStrokeColor:h,maskStrokeWidth:p,position:y="bottom-right",onClick:x,onNodeClick:v,pannable:j=!1,zoomable:C=!1,ariaLabel:w,inversePan:N,zoomStep:S=1,offsetScale:T=5}){const E=Hr(),R=g.useRef(null),{boundingRect:I,viewBB:z,rfId:B,panZoom:D,translateExtent:V,flowWidth:Y,flowHeight:F,ariaLabelConfig:L}=ur(Vne,Yr),O=e?.width??Fne,M=e?.height??qne,$=I.width/O,W=I.height/M,U=Math.max($,W),H=U*O,q=U*M,Z=T*U,_=I.x-(H-I.width)/2-Z,J=I.y-(q-I.height)/2-Z,X=H+Z*2,ee=q+Z*2,te=`${Kne}-${B}`,G=g.useRef(0),ue=g.useRef();G.current=U,g.useEffect(()=>{if(R.current&&D)return ue.current=lee({domNode:R.current,panZoom:D,getTransform:()=>E.getState().transform,getViewScale:()=>G.current}),()=>{ue.current?.destroy()}},[D]),g.useEffect(()=>{ue.current?.update({translateExtent:V,width:Y,height:F,inversePan:N,pannable:j,zoomStep:S,zoomable:C})},[j,C,N,S,V,Y,F]);const Se=x?Ne=>{const[he,_e]=ue.current?.pointer(Ne)||[0,0];x(Ne,{x:he,y:_e})}:void 0,Ce=v?g.useCallback((Ne,he)=>{const _e=E.getState().nodeLookup.get(he).internals.userNode;v(Ne,_e)},[]):void 0,Be=w??L["minimap.ariaLabel"];return n.jsx(rp,{position:y,style:{...e,"--xy-minimap-background-color-props":typeof u=="string"?u:void 0,"--xy-minimap-mask-background-color-props":typeof m=="string"?m:void 0,"--xy-minimap-mask-stroke-color-props":typeof h=="string"?h:void 0,"--xy-minimap-mask-stroke-width-props":typeof p=="number"?p*U:void 0,"--xy-minimap-node-background-color-props":typeof s=="string"?s:void 0,"--xy-minimap-node-stroke-color-props":typeof r=="string"?r:void 0,"--xy-minimap-node-stroke-width-props":typeof l=="number"?l:void 0},className:js(["react-flow__minimap",t]),"data-testid":"rf__minimap",children:n.jsxs("svg",{width:O,height:M,viewBox:`${_} ${J} ${X} ${ee}`,className:"react-flow__minimap-svg",role:"img","aria-labelledby":te,ref:R,onClick:Se,children:[Be&&n.jsx("title",{id:te,children:Be}),n.jsx(Hne,{onClick:Ce,nodeColor:s,nodeStrokeColor:r,nodeBorderRadius:i,nodeClassName:a,nodeStrokeWidth:l,nodeComponent:d}),n.jsx("path",{className:"react-flow__minimap-mask",d:`M${_-Z},${J-Z}h${X+Z*2}v${ee+Z*2}h${-X-Z*2}z
709
709
  M${z.x},${z.y}h${z.width}v${z.height}h${-z.width}z`,fillRule:"evenodd",pointerEvents:"none"})]})})}X8.displayName="MiniMap";const Wne=g.memo(X8),Gne=e=>t=>e?`${Math.max(1/t.transform[2],1)}`:void 0,Yne={[Dd.Line]:"right",[Dd.Handle]:"bottom-right"};function Xne({nodeId:e,position:t,variant:r=Dd.Handle,className:s,style:a=void 0,children:i,color:l,minWidth:d=10,minHeight:u=10,maxWidth:m=Number.MAX_VALUE,maxHeight:h=Number.MAX_VALUE,keepAspectRatio:p=!1,resizeDirection:y,autoScale:x=!0,shouldResize:v,onResizeStart:j,onResize:C,onResizeEnd:w}){const N=A8(),S=typeof e=="string"?e:N,T=Hr(),E=g.useRef(null),R=r===Dd.Handle,I=ur(g.useCallback(Gne(R&&x),[R,x]),Yr),z=g.useRef(null),B=t??Yne[r];g.useEffect(()=>{if(!(!E.current||!S))return z.current||(z.current=kee({domNode:E.current,nodeId:S,getStoreItems:()=>{const{nodeLookup:V,transform:Y,snapGrid:F,snapToGrid:L,nodeOrigin:O,domNode:M}=T.getState();return{nodeLookup:V,transform:Y,snapGrid:F,snapToGrid:L,nodeOrigin:O,paneDomNode:M}},onChange:(V,Y)=>{const{triggerNodeChanges:F,nodeLookup:L,parentLookup:O,nodeOrigin:M}=T.getState(),$=[],W={x:V.x,y:V.y},U=L.get(S);if(U&&U.expandParent&&U.parentId){const H=U.origin??M,q=V.width??U.measured.width??0,Z=V.height??U.measured.height??0,_={id:U.id,parentId:U.parentId,rect:{width:q,height:Z,...Q7({x:V.x??U.position.x,y:V.y??U.position.y},{width:q,height:Z},U.parentId,L,H)}},J=Ey([_],L,O,M);$.push(...J),W.x=V.x?Math.max(H[0]*q,V.x):void 0,W.y=V.y?Math.max(H[1]*Z,V.y):void 0}if(W.x!==void 0&&W.y!==void 0){const H={id:S,type:"position",position:{...W}};$.push(H)}if(V.width!==void 0&&V.height!==void 0){const q={id:S,type:"dimensions",resizing:!0,setAttributes:y?y==="horizontal"?"width":"height":!0,dimensions:{width:V.width,height:V.height}};$.push(q)}for(const H of Y){const q={...H,type:"position"};$.push(q)}F($)},onEnd:({width:V,height:Y})=>{const F={id:S,type:"dimensions",resizing:!1,dimensions:{width:V,height:Y}};T.getState().triggerNodeChanges([F])}})),z.current.update({controlPosition:B,boundaries:{minWidth:d,minHeight:u,maxWidth:m,maxHeight:h},keepAspectRatio:p,resizeDirection:y,onResizeStart:j,onResize:C,onResizeEnd:w,shouldResize:v}),()=>{z.current?.destroy()}},[B,d,u,m,h,p,j,C,w,v]);const D=B.split("-");return n.jsx("div",{className:js(["react-flow__resize-control","nodrag",...D,r,s]),ref:E,style:{...a,scale:I,...l&&{[R?"backgroundColor":"borderColor"]:l}},children:i})}g.memo(Xne);var Tr=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),Ei=Tr((e,t)=>{var r=Object.defineProperty,s=(F,L,O)=>L in F?r(F,L,{enumerable:!0,configurable:!0,writable:!0,value:O}):F[L]=O,a=(F,L)=>()=>(L||F((L={exports:{}}).exports,L),L.exports),i=(F,L,O)=>s(F,typeof L!="symbol"?L+"":L,O),l=a((F,L)=>{var O="\0",M="\0",$="",W=class{constructor(J){i(this,"_isDirected",!0),i(this,"_isMultigraph",!1),i(this,"_isCompound",!1),i(this,"_label"),i(this,"_defaultNodeLabelFn",()=>{}),i(this,"_defaultEdgeLabelFn",()=>{}),i(this,"_nodes",{}),i(this,"_in",{}),i(this,"_preds",{}),i(this,"_out",{}),i(this,"_sucs",{}),i(this,"_edgeObjs",{}),i(this,"_edgeLabels",{}),i(this,"_nodeCount",0),i(this,"_edgeCount",0),i(this,"_parent"),i(this,"_children"),J&&(this._isDirected=Object.hasOwn(J,"directed")?J.directed:!0,this._isMultigraph=Object.hasOwn(J,"multigraph")?J.multigraph:!1,this._isCompound=Object.hasOwn(J,"compound")?J.compound:!1),this._isCompound&&(this._parent={},this._children={},this._children[M]={})}isDirected(){return this._isDirected}isMultigraph(){return this._isMultigraph}isCompound(){return this._isCompound}setGraph(J){return this._label=J,this}graph(){return this._label}setDefaultNodeLabel(J){return this._defaultNodeLabelFn=J,typeof J!="function"&&(this._defaultNodeLabelFn=()=>J),this}nodeCount(){return this._nodeCount}nodes(){return Object.keys(this._nodes)}sources(){var J=this;return this.nodes().filter(X=>Object.keys(J._in[X]).length===0)}sinks(){var J=this;return this.nodes().filter(X=>Object.keys(J._out[X]).length===0)}setNodes(J,X){var ee=arguments,te=this;return J.forEach(function(G){ee.length>1?te.setNode(G,X):te.setNode(G)}),this}setNode(J,X){return Object.hasOwn(this._nodes,J)?(arguments.length>1&&(this._nodes[J]=X),this):(this._nodes[J]=arguments.length>1?X:this._defaultNodeLabelFn(J),this._isCompound&&(this._parent[J]=M,this._children[J]={},this._children[M][J]=!0),this._in[J]={},this._preds[J]={},this._out[J]={},this._sucs[J]={},++this._nodeCount,this)}node(J){return this._nodes[J]}hasNode(J){return Object.hasOwn(this._nodes,J)}removeNode(J){var X=this;if(Object.hasOwn(this._nodes,J)){var ee=te=>X.removeEdge(X._edgeObjs[te]);delete this._nodes[J],this._isCompound&&(this._removeFromParentsChildList(J),delete this._parent[J],this.children(J).forEach(function(te){X.setParent(te)}),delete this._children[J]),Object.keys(this._in[J]).forEach(ee),delete this._in[J],delete this._preds[J],Object.keys(this._out[J]).forEach(ee),delete this._out[J],delete this._sucs[J],--this._nodeCount}return this}setParent(J,X){if(!this._isCompound)throw new Error("Cannot set parent in a non-compound graph");if(X===void 0)X=M;else{X+="";for(var ee=X;ee!==void 0;ee=this.parent(ee))if(ee===J)throw new Error("Setting "+X+" as parent of "+J+" would create a cycle");this.setNode(X)}return this.setNode(J),this._removeFromParentsChildList(J),this._parent[J]=X,this._children[X][J]=!0,this}_removeFromParentsChildList(J){delete this._children[this._parent[J]][J]}parent(J){if(this._isCompound){var X=this._parent[J];if(X!==M)return X}}children(J=M){if(this._isCompound){var X=this._children[J];if(X)return Object.keys(X)}else{if(J===M)return this.nodes();if(this.hasNode(J))return[]}}predecessors(J){var X=this._preds[J];if(X)return Object.keys(X)}successors(J){var X=this._sucs[J];if(X)return Object.keys(X)}neighbors(J){var X=this.predecessors(J);if(X){let te=new Set(X);for(var ee of this.successors(J))te.add(ee);return Array.from(te.values())}}isLeaf(J){var X;return this.isDirected()?X=this.successors(J):X=this.neighbors(J),X.length===0}filterNodes(J){var X=new this.constructor({directed:this._isDirected,multigraph:this._isMultigraph,compound:this._isCompound});X.setGraph(this.graph());var ee=this;Object.entries(this._nodes).forEach(function([ue,Se]){J(ue)&&X.setNode(ue,Se)}),Object.values(this._edgeObjs).forEach(function(ue){X.hasNode(ue.v)&&X.hasNode(ue.w)&&X.setEdge(ue,ee.edge(ue))});var te={};function G(ue){var Se=ee.parent(ue);return Se===void 0||X.hasNode(Se)?(te[ue]=Se,Se):Se in te?te[Se]:G(Se)}return this._isCompound&&X.nodes().forEach(ue=>X.setParent(ue,G(ue))),X}setDefaultEdgeLabel(J){return this._defaultEdgeLabelFn=J,typeof J!="function"&&(this._defaultEdgeLabelFn=()=>J),this}edgeCount(){return this._edgeCount}edges(){return Object.values(this._edgeObjs)}setPath(J,X){var ee=this,te=arguments;return J.reduce(function(G,ue){return te.length>1?ee.setEdge(G,ue,X):ee.setEdge(G,ue),ue}),this}setEdge(){var J,X,ee,te,G=!1,ue=arguments[0];typeof ue=="object"&&ue!==null&&"v"in ue?(J=ue.v,X=ue.w,ee=ue.name,arguments.length===2&&(te=arguments[1],G=!0)):(J=ue,X=arguments[1],ee=arguments[3],arguments.length>2&&(te=arguments[2],G=!0)),J=""+J,X=""+X,ee!==void 0&&(ee=""+ee);var Se=q(this._isDirected,J,X,ee);if(Object.hasOwn(this._edgeLabels,Se))return G&&(this._edgeLabels[Se]=te),this;if(ee!==void 0&&!this._isMultigraph)throw new Error("Cannot set a named edge when isMultigraph = false");this.setNode(J),this.setNode(X),this._edgeLabels[Se]=G?te:this._defaultEdgeLabelFn(J,X,ee);var Ce=Z(this._isDirected,J,X,ee);return J=Ce.v,X=Ce.w,Object.freeze(Ce),this._edgeObjs[Se]=Ce,U(this._preds[X],J),U(this._sucs[J],X),this._in[X][Se]=Ce,this._out[J][Se]=Ce,this._edgeCount++,this}edge(J,X,ee){var te=arguments.length===1?_(this._isDirected,arguments[0]):q(this._isDirected,J,X,ee);return this._edgeLabels[te]}edgeAsObj(){let J=this.edge(...arguments);return typeof J!="object"?{label:J}:J}hasEdge(J,X,ee){var te=arguments.length===1?_(this._isDirected,arguments[0]):q(this._isDirected,J,X,ee);return Object.hasOwn(this._edgeLabels,te)}removeEdge(J,X,ee){var te=arguments.length===1?_(this._isDirected,arguments[0]):q(this._isDirected,J,X,ee),G=this._edgeObjs[te];return G&&(J=G.v,X=G.w,delete this._edgeLabels[te],delete this._edgeObjs[te],H(this._preds[X],J),H(this._sucs[J],X),delete this._in[X][te],delete this._out[J][te],this._edgeCount--),this}inEdges(J,X){return this.isDirected()?this.filterEdges(this._in[J],J,X):this.nodeEdges(J,X)}outEdges(J,X){return this.isDirected()?this.filterEdges(this._out[J],J,X):this.nodeEdges(J,X)}nodeEdges(J,X){if(J in this._nodes)return this.filterEdges({...this._in[J],...this._out[J]},J,X)}filterEdges(J,X,ee){if(J){var te=Object.values(J);return ee?te.filter(function(G){return G.v===X&&G.w===ee||G.v===ee&&G.w===X}):te}}};function U(J,X){J[X]?J[X]++:J[X]=1}function H(J,X){--J[X]||delete J[X]}function q(J,X,ee,te){var G=""+X,ue=""+ee;if(!J&&G>ue){var Se=G;G=ue,ue=Se}return G+$+ue+$+(te===void 0?O:te)}function Z(J,X,ee,te){var G=""+X,ue=""+ee;if(!J&&G>ue){var Se=G;G=ue,ue=Se}var Ce={v:G,w:ue};return te&&(Ce.name=te),Ce}function _(J,X){return q(J,X.v,X.w,X.name)}L.exports=W}),d=a((F,L)=>{L.exports="3.0.2"}),u=a((F,L)=>{L.exports={Graph:l(),version:d()}}),m=a((F,L)=>{var O=l();L.exports={write:M,read:U};function M(H){var q={options:{directed:H.isDirected(),multigraph:H.isMultigraph(),compound:H.isCompound()},nodes:$(H),edges:W(H)};return H.graph()!==void 0&&(q.value=structuredClone(H.graph())),q}function $(H){return H.nodes().map(function(q){var Z=H.node(q),_=H.parent(q),J={v:q};return Z!==void 0&&(J.value=Z),_!==void 0&&(J.parent=_),J})}function W(H){return H.edges().map(function(q){var Z=H.edge(q),_={v:q.v,w:q.w};return q.name!==void 0&&(_.name=q.name),Z!==void 0&&(_.value=Z),_})}function U(H){var q=new O(H.options).setGraph(H.value);return H.nodes.forEach(function(Z){q.setNode(Z.v,Z.value),Z.parent&&q.setParent(Z.v,Z.parent)}),H.edges.forEach(function(Z){q.setEdge({v:Z.v,w:Z.w,name:Z.name},Z.value)}),q}}),h=a((F,L)=>{L.exports=M;var O=()=>1;function M(W,U,H,q){return $(W,String(U),H||O,q||function(Z){return W.outEdges(Z)})}function $(W,U,H,q){var Z={},_=!0,J=0,X=W.nodes(),ee=function(Se){var Ce=H(Se);Z[Se.v].distance+Ce<Z[Se.w].distance&&(Z[Se.w]={distance:Z[Se.v].distance+Ce,predecessor:Se.v},_=!0)},te=function(){X.forEach(function(Se){q(Se).forEach(function(Ce){var Be=Ce.v===Se?Ce.v:Ce.w,Ne=Be===Ce.v?Ce.w:Ce.v;ee({v:Be,w:Ne})})})};X.forEach(function(Se){var Ce=Se===U?0:Number.POSITIVE_INFINITY;Z[Se]={distance:Ce}});for(var G=X.length,ue=1;ue<G&&(_=!1,J++,te(),!!_);ue++);if(J===G-1&&(_=!1,te(),_))throw new Error("The graph contains a negative weight cycle");return Z}}),p=a((F,L)=>{L.exports=O;function O(M){var $={},W=[],U;function H(q){Object.hasOwn($,q)||($[q]=!0,U.push(q),M.successors(q).forEach(H),M.predecessors(q).forEach(H))}return M.nodes().forEach(function(q){U=[],H(q),U.length&&W.push(U)}),W}}),y=a((F,L)=>{var O=class{constructor(){i(this,"_arr",[]),i(this,"_keyIndices",{})}size(){return this._arr.length}keys(){return this._arr.map(function(M){return M.key})}has(M){return Object.hasOwn(this._keyIndices,M)}priority(M){var $=this._keyIndices[M];if($!==void 0)return this._arr[$].priority}min(){if(this.size()===0)throw new Error("Queue underflow");return this._arr[0].key}add(M,$){var W=this._keyIndices;if(M=String(M),!Object.hasOwn(W,M)){var U=this._arr,H=U.length;return W[M]=H,U.push({key:M,priority:$}),this._decrease(H),!0}return!1}removeMin(){this._swap(0,this._arr.length-1);var M=this._arr.pop();return delete this._keyIndices[M.key],this._heapify(0),M.key}decrease(M,$){var W=this._keyIndices[M];if($>this._arr[W].priority)throw new Error("New priority is greater than current priority. Key: "+M+" Old: "+this._arr[W].priority+" New: "+$);this._arr[W].priority=$,this._decrease(W)}_heapify(M){var $=this._arr,W=2*M,U=W+1,H=M;W<$.length&&(H=$[W].priority<$[H].priority?W:H,U<$.length&&(H=$[U].priority<$[H].priority?U:H),H!==M&&(this._swap(M,H),this._heapify(H)))}_decrease(M){for(var $=this._arr,W=$[M].priority,U;M!==0&&(U=M>>1,!($[U].priority<W));)this._swap(M,U),M=U}_swap(M,$){var W=this._arr,U=this._keyIndices,H=W[M],q=W[$];W[M]=q,W[$]=H,U[q.key]=M,U[H.key]=$}};L.exports=O}),x=a((F,L)=>{var O=y();L.exports=$;var M=()=>1;function $(U,H,q,Z){var _=function(J){return U.outEdges(J)};return W(U,String(H),q||M,Z||_)}function W(U,H,q,Z){var _={},J=new O,X,ee,te=function(G){var ue=G.v!==X?G.v:G.w,Se=_[ue],Ce=q(G),Be=ee.distance+Ce;if(Ce<0)throw new Error("dijkstra does not allow negative edge weights. Bad edge: "+G+" Weight: "+Ce);Be<Se.distance&&(Se.distance=Be,Se.predecessor=X,J.decrease(ue,Be))};for(U.nodes().forEach(function(G){var ue=G===H?0:Number.POSITIVE_INFINITY;_[G]={distance:ue},J.add(G,ue)});J.size()>0&&(X=J.removeMin(),ee=_[X],ee.distance!==Number.POSITIVE_INFINITY);)Z(X).forEach(te);return _}}),v=a((F,L)=>{var O=x();L.exports=M;function M($,W,U){return $.nodes().reduce(function(H,q){return H[q]=O($,q,W,U),H},{})}}),j=a((F,L)=>{L.exports=O;function O($,W,U){if($[W].predecessor!==void 0)throw new Error("Invalid source vertex");if($[U].predecessor===void 0&&U!==W)throw new Error("Invalid destination vertex");return{weight:$[U].distance,path:M($,W,U)}}function M($,W,U){for(var H=[],q=U;q!==W;)H.push(q),q=$[q].predecessor;return H.push(W),H.reverse()}}),C=a((F,L)=>{L.exports=O;function O(M){var $=0,W=[],U={},H=[];function q(Z){var _=U[Z]={onStack:!0,lowlink:$,index:$++};if(W.push(Z),M.successors(Z).forEach(function(ee){Object.hasOwn(U,ee)?U[ee].onStack&&(_.lowlink=Math.min(_.lowlink,U[ee].index)):(q(ee),_.lowlink=Math.min(_.lowlink,U[ee].lowlink))}),_.lowlink===_.index){var J=[],X;do X=W.pop(),U[X].onStack=!1,J.push(X);while(Z!==X);H.push(J)}}return M.nodes().forEach(function(Z){Object.hasOwn(U,Z)||q(Z)}),H}}),w=a((F,L)=>{var O=C();L.exports=M;function M($){return O($).filter(function(W){return W.length>1||W.length===1&&$.hasEdge(W[0],W[0])})}}),N=a((F,L)=>{L.exports=M;var O=()=>1;function M(W,U,H){return $(W,U||O,H||function(q){return W.outEdges(q)})}function $(W,U,H){var q={},Z=W.nodes();return Z.forEach(function(_){q[_]={},q[_][_]={distance:0},Z.forEach(function(J){_!==J&&(q[_][J]={distance:Number.POSITIVE_INFINITY})}),H(_).forEach(function(J){var X=J.v===_?J.w:J.v,ee=U(J);q[_][X]={distance:ee,predecessor:_}})}),Z.forEach(function(_){var J=q[_];Z.forEach(function(X){var ee=q[X];Z.forEach(function(te){var G=ee[_],ue=J[te],Se=ee[te],Ce=G.distance+ue.distance;Ce<Se.distance&&(Se.distance=Ce,Se.predecessor=ue.predecessor)})})}),q}}),S=a((F,L)=>{function O($){var W={},U={},H=[];function q(Z){if(Object.hasOwn(U,Z))throw new M;Object.hasOwn(W,Z)||(U[Z]=!0,W[Z]=!0,$.predecessors(Z).forEach(q),delete U[Z],H.push(Z))}if($.sinks().forEach(q),Object.keys(W).length!==$.nodeCount())throw new M;return H}var M=class extends Error{constructor(){super(...arguments)}};L.exports=O,O.CycleException=M}),T=a((F,L)=>{var O=S();L.exports=M;function M($){try{O($)}catch(W){if(W instanceof O.CycleException)return!1;throw W}return!0}}),E=a((F,L)=>{L.exports=O;function O($,W,U,H,q){Array.isArray(W)||(W=[W]);var Z=($.isDirected()?$.successors:$.neighbors).bind($),_={};return W.forEach(function(J){if(!$.hasNode(J))throw new Error("Graph does not have node: "+J);q=M($,J,U==="post",_,Z,H,q)}),q}function M($,W,U,H,q,Z,_){return Object.hasOwn(H,W)||(H[W]=!0,U||(_=Z(_,W)),q(W).forEach(function(J){_=M($,J,U,H,q,Z,_)}),U&&(_=Z(_,W))),_}}),R=a((F,L)=>{var O=E();L.exports=M;function M($,W,U){return O($,W,U,function(H,q){return H.push(q),H},[])}}),I=a((F,L)=>{var O=R();L.exports=M;function M($,W){return O($,W,"post")}}),z=a((F,L)=>{var O=R();L.exports=M;function M($,W){return O($,W,"pre")}}),B=a((F,L)=>{var O=l(),M=y();L.exports=$;function $(W,U){var H=new O,q={},Z=new M,_;function J(ee){var te=ee.v===_?ee.w:ee.v,G=Z.priority(te);if(G!==void 0){var ue=U(ee);ue<G&&(q[te]=_,Z.decrease(te,ue))}}if(W.nodeCount()===0)return H;W.nodes().forEach(function(ee){Z.add(ee,Number.POSITIVE_INFINITY),H.setNode(ee)}),Z.decrease(W.nodes()[0],0);for(var X=!1;Z.size()>0;){if(_=Z.removeMin(),Object.hasOwn(q,_))H.setEdge(_,q[_]);else{if(X)throw new Error("Input graph is not connected: "+W);X=!0}W.nodeEdges(_).forEach(J)}return H}}),D=a((F,L)=>{var O=x(),M=h();L.exports=$;function $(U,H,q,Z){return W(U,H,q,Z||function(_){return U.outEdges(_)})}function W(U,H,q,Z){if(q===void 0)return O(U,H,q,Z);for(var _=!1,J=U.nodes(),X=0;X<J.length;X++){for(var ee=Z(J[X]),te=0;te<ee.length;te++){var G=ee[te],ue=G.v===J[X]?G.v:G.w,Se=ue===G.v?G.w:G.v;q({v:ue,w:Se})<0&&(_=!0)}if(_)return M(U,H,q,Z)}return O(U,H,q,Z)}}),V=a((F,L)=>{L.exports={bellmanFord:h(),components:p(),dijkstra:x(),dijkstraAll:v(),extractPath:j(),findCycles:w(),floydWarshall:N(),isAcyclic:T(),postorder:I(),preorder:z(),prim:B(),shortestPaths:D(),reduce:E(),tarjan:C(),topsort:S()}}),Y=u();t.exports={Graph:Y.Graph,json:m(),alg:V(),version:Y.version}}),Qne=Tr((e,t)=>{var r=class{constructor(){let i={};i._next=i._prev=i,this._sentinel=i}dequeue(){let i=this._sentinel,l=i._prev;if(l!==i)return s(l),l}enqueue(i){let l=this._sentinel;i._prev&&i._next&&s(i),i._next=l._next,l._next._prev=i,l._next=i,i._prev=l}toString(){let i=[],l=this._sentinel,d=l._prev;for(;d!==l;)i.push(JSON.stringify(d,a)),d=d._prev;return"["+i.join(", ")+"]"}};function s(i){i._prev._next=i._next,i._next._prev=i._prev,delete i._next,delete i._prev}function a(i,l){if(i!=="_next"&&i!=="_prev")return l}t.exports=r}),Zne=Tr((e,t)=>{var r=Ei().Graph,s=Qne();t.exports=i;var a=()=>1;function i(p,y){if(p.nodeCount()<=1)return[];let x=u(p,y||a);return l(x.graph,x.buckets,x.zeroIdx).flatMap(v=>p.outEdges(v.v,v.w))}function l(p,y,x){let v=[],j=y[y.length-1],C=y[0],w;for(;p.nodeCount();){for(;w=C.dequeue();)d(p,y,x,w);for(;w=j.dequeue();)d(p,y,x,w);if(p.nodeCount()){for(let N=y.length-2;N>0;--N)if(w=y[N].dequeue(),w){v=v.concat(d(p,y,x,w,!0));break}}}return v}function d(p,y,x,v,j){let C=j?[]:void 0;return p.inEdges(v.v).forEach(w=>{let N=p.edge(w),S=p.node(w.v);j&&C.push({v:w.v,w:w.w}),S.out-=N,m(y,x,S)}),p.outEdges(v.v).forEach(w=>{let N=p.edge(w),S=w.w,T=p.node(S);T.in-=N,m(y,x,T)}),p.removeNode(v.v),C}function u(p,y){let x=new r,v=0,j=0;p.nodes().forEach(N=>{x.setNode(N,{v:N,in:0,out:0})}),p.edges().forEach(N=>{let S=x.edge(N.v,N.w)||0,T=y(N),E=S+T;x.setEdge(N.v,N.w,E),j=Math.max(j,x.node(N.v).out+=T),v=Math.max(v,x.node(N.w).in+=T)});let C=h(j+v+3).map(()=>new s),w=v+1;return x.nodes().forEach(N=>{m(C,w,x.node(N))}),{graph:x,buckets:C,zeroIdx:w}}function m(p,y,x){x.out?x.in?p[x.out-x.in+y].enqueue(x):p[p.length-1].enqueue(x):p[0].enqueue(x)}function h(p){let y=[];for(let x=0;x<p;x++)y.push(x);return y}}),ws=Tr((e,t)=>{var r=Ei().Graph;t.exports={addBorderNode:y,addDummyNode:s,applyWithChunking:j,asNonCompoundGraph:i,buildLayerMatrix:m,intersectRect:u,mapValues:z,maxRank:C,normalizeRanks:h,notime:S,partition:w,pick:I,predecessorWeights:d,range:R,removeEmptyRanks:p,simplify:a,successorWeights:l,time:N,uniqueId:E,zipObject:B};function s(D,V,Y,F){for(var L=F;D.hasNode(L);)L=E(F);return Y.dummy=V,D.setNode(L,Y),L}function a(D){let V=new r().setGraph(D.graph());return D.nodes().forEach(Y=>V.setNode(Y,D.node(Y))),D.edges().forEach(Y=>{let F=V.edge(Y.v,Y.w)||{weight:0,minlen:1},L=D.edge(Y);V.setEdge(Y.v,Y.w,{weight:F.weight+L.weight,minlen:Math.max(F.minlen,L.minlen)})}),V}function i(D){let V=new r({multigraph:D.isMultigraph()}).setGraph(D.graph());return D.nodes().forEach(Y=>{D.children(Y).length||V.setNode(Y,D.node(Y))}),D.edges().forEach(Y=>{V.setEdge(Y,D.edge(Y))}),V}function l(D){let V=D.nodes().map(Y=>{let F={};return D.outEdges(Y).forEach(L=>{F[L.w]=(F[L.w]||0)+D.edge(L).weight}),F});return B(D.nodes(),V)}function d(D){let V=D.nodes().map(Y=>{let F={};return D.inEdges(Y).forEach(L=>{F[L.v]=(F[L.v]||0)+D.edge(L).weight}),F});return B(D.nodes(),V)}function u(D,V){let Y=D.x,F=D.y,L=V.x-Y,O=V.y-F,M=D.width/2,$=D.height/2;if(!L&&!O)throw new Error("Not possible to find intersection inside of the rectangle");let W,U;return Math.abs(O)*M>Math.abs(L)*$?(O<0&&($=-$),W=$*L/O,U=$):(L<0&&(M=-M),W=M,U=M*O/L),{x:Y+W,y:F+U}}function m(D){let V=R(C(D)+1).map(()=>[]);return D.nodes().forEach(Y=>{let F=D.node(Y),L=F.rank;L!==void 0&&(V[L][F.order]=Y)}),V}function h(D){let V=D.nodes().map(F=>{let L=D.node(F).rank;return L===void 0?Number.MAX_VALUE:L}),Y=j(Math.min,V);D.nodes().forEach(F=>{let L=D.node(F);Object.hasOwn(L,"rank")&&(L.rank-=Y)})}function p(D){let V=D.nodes().map(M=>D.node(M).rank).filter(M=>M!==void 0),Y=j(Math.min,V),F=[];D.nodes().forEach(M=>{let $=D.node(M).rank-Y;F[$]||(F[$]=[]),F[$].push(M)});let L=0,O=D.graph().nodeRankFactor;Array.from(F).forEach((M,$)=>{M===void 0&&$%O!==0?--L:M!==void 0&&L&&M.forEach(W=>D.node(W).rank+=L)})}function y(D,V,Y,F){let L={width:0,height:0};return arguments.length>=4&&(L.rank=Y,L.order=F),s(D,"border",L,V)}function x(D,V=v){let Y=[];for(let F=0;F<D.length;F+=V){let L=D.slice(F,F+V);Y.push(L)}return Y}var v=65535;function j(D,V){if(V.length>v){let Y=x(V);return D.apply(null,Y.map(F=>D.apply(null,F)))}else return D.apply(null,V)}function C(D){let V=D.nodes().map(Y=>{let F=D.node(Y).rank;return F===void 0?Number.MIN_VALUE:F});return j(Math.max,V)}function w(D,V){let Y={lhs:[],rhs:[]};return D.forEach(F=>{V(F)?Y.lhs.push(F):Y.rhs.push(F)}),Y}function N(D,V){let Y=Date.now();try{return V()}finally{console.log(D+" time: "+(Date.now()-Y)+"ms")}}function S(D,V){return V()}var T=0;function E(D){var V=++T;return D+(""+V)}function R(D,V,Y=1){V==null&&(V=D,D=0);let F=O=>O<V;Y<0&&(F=O=>V<O);let L=[];for(let O=D;F(O);O+=Y)L.push(O);return L}function I(D,V){let Y={};for(let F of V)D[F]!==void 0&&(Y[F]=D[F]);return Y}function z(D,V){let Y=V;return typeof V=="string"&&(Y=F=>F[V]),Object.entries(D).reduce((F,[L,O])=>(F[L]=Y(O,L),F),{})}function B(D,V){return D.reduce((Y,F,L)=>(Y[F]=V[L],Y),{})}}),Jne=Tr((e,t)=>{var r=Zne(),s=ws().uniqueId;t.exports={run:a,undo:l};function a(d){(d.graph().acyclicer==="greedy"?r(d,u(d)):i(d)).forEach(m=>{let h=d.edge(m);d.removeEdge(m),h.forwardName=m.name,h.reversed=!0,d.setEdge(m.w,m.v,h,s("rev"))});function u(m){return h=>m.edge(h).weight}}function i(d){let u=[],m={},h={};function p(y){Object.hasOwn(h,y)||(h[y]=!0,m[y]=!0,d.outEdges(y).forEach(x=>{Object.hasOwn(m,x.w)?u.push(x):p(x.w)}),delete m[y])}return d.nodes().forEach(p),u}function l(d){d.edges().forEach(u=>{let m=d.edge(u);if(m.reversed){d.removeEdge(u);let h=m.forwardName;delete m.reversed,delete m.forwardName,d.setEdge(u.w,u.v,m,h)}})}}),ere=Tr((e,t)=>{var r=ws();t.exports={run:s,undo:i};function s(l){l.graph().dummyChains=[],l.edges().forEach(d=>a(l,d))}function a(l,d){let u=d.v,m=l.node(u).rank,h=d.w,p=l.node(h).rank,y=d.name,x=l.edge(d),v=x.labelRank;if(p===m+1)return;l.removeEdge(d);let j,C,w;for(w=0,++m;m<p;++w,++m)x.points=[],C={width:0,height:0,edgeLabel:x,edgeObj:d,rank:m},j=r.addDummyNode(l,"edge",C,"_d"),m===v&&(C.width=x.width,C.height=x.height,C.dummy="edge-label",C.labelpos=x.labelpos),l.setEdge(u,j,{weight:x.weight},y),w===0&&l.graph().dummyChains.push(j),u=j;l.setEdge(u,h,{weight:x.weight},y)}function i(l){l.graph().dummyChains.forEach(d=>{let u=l.node(d),m=u.edgeLabel,h;for(l.setEdge(u.edgeObj,m);u.dummy;)h=l.successors(d)[0],l.removeNode(d),m.points.push({x:u.x,y:u.y}),u.dummy==="edge-label"&&(m.x=u.x,m.y=u.y,m.width=u.width,m.height=u.height),d=h,u=l.node(d)})}}),Nh=Tr((e,t)=>{var{applyWithChunking:r}=ws();t.exports={longestPath:s,slack:a};function s(i){var l={};function d(u){var m=i.node(u);if(Object.hasOwn(l,u))return m.rank;l[u]=!0;let h=i.outEdges(u).map(y=>y==null?Number.POSITIVE_INFINITY:d(y.w)-i.edge(y).minlen);var p=r(Math.min,h);return p===Number.POSITIVE_INFINITY&&(p=0),m.rank=p}i.sources().forEach(d)}function a(i,l){return i.node(l.w).rank-i.node(l.v).rank-i.edge(l).minlen}}),Q8=Tr((e,t)=>{var r=Ei().Graph,s=Nh().slack;t.exports=a;function a(u){var m=new r({directed:!1}),h=u.nodes()[0],p=u.nodeCount();m.setNode(h,{});for(var y,x;i(m,u)<p;)y=l(m,u),x=m.hasNode(y.v)?s(u,y):-s(u,y),d(m,u,x);return m}function i(u,m){function h(p){m.nodeEdges(p).forEach(y=>{var x=y.v,v=p===x?y.w:x;!u.hasNode(v)&&!s(m,y)&&(u.setNode(v,{}),u.setEdge(p,v,{}),h(v))})}return u.nodes().forEach(h),u.nodeCount()}function l(u,m){return m.edges().reduce((h,p)=>{let y=Number.POSITIVE_INFINITY;return u.hasNode(p.v)!==u.hasNode(p.w)&&(y=s(m,p)),y<h[0]?[y,p]:h},[Number.POSITIVE_INFINITY,null])[1]}function d(u,m,h){u.nodes().forEach(p=>m.node(p).rank+=h)}}),tre=Tr((e,t)=>{var r=Q8(),s=Nh().slack,a=Nh().longestPath,i=Ei().alg.preorder,l=Ei().alg.postorder,d=ws().simplify;t.exports=u,u.initLowLimValues=y,u.initCutValues=m,u.calcCutValue=p,u.leaveEdge=v,u.enterEdge=j,u.exchangeEdges=C;function u(T){T=d(T),a(T);var E=r(T);y(E),m(E,T);for(var R,I;R=v(E);)I=j(E,T,R),C(E,T,R,I)}function m(T,E){var R=l(T,T.nodes());R=R.slice(0,R.length-1),R.forEach(I=>h(T,E,I))}function h(T,E,R){var I=T.node(R),z=I.parent;T.edge(R,z).cutvalue=p(T,E,R)}function p(T,E,R){var I=T.node(R),z=I.parent,B=!0,D=E.edge(R,z),V=0;return D||(B=!1,D=E.edge(z,R)),V=D.weight,E.nodeEdges(R).forEach(Y=>{var F=Y.v===R,L=F?Y.w:Y.v;if(L!==z){var O=F===B,M=E.edge(Y).weight;if(V+=O?M:-M,N(T,R,L)){var $=T.edge(R,L).cutvalue;V+=O?-$:$}}}),V}function y(T,E){arguments.length<2&&(E=T.nodes()[0]),x(T,{},1,E)}function x(T,E,R,I,z){var B=R,D=T.node(I);return E[I]=!0,T.neighbors(I).forEach(V=>{Object.hasOwn(E,V)||(R=x(T,E,R,V,I))}),D.low=B,D.lim=R++,z?D.parent=z:delete D.parent,R}function v(T){return T.edges().find(E=>T.edge(E).cutvalue<0)}function j(T,E,R){var I=R.v,z=R.w;E.hasEdge(I,z)||(I=R.w,z=R.v);var B=T.node(I),D=T.node(z),V=B,Y=!1;B.lim>D.lim&&(V=D,Y=!0);var F=E.edges().filter(L=>Y===S(T,T.node(L.v),V)&&Y!==S(T,T.node(L.w),V));return F.reduce((L,O)=>s(E,O)<s(E,L)?O:L)}function C(T,E,R,I){var z=R.v,B=R.w;T.removeEdge(z,B),T.setEdge(I.v,I.w,{}),y(T),m(T,E),w(T,E)}function w(T,E){var R=T.nodes().find(z=>!E.node(z).parent),I=i(T,R);I=I.slice(1),I.forEach(z=>{var B=T.node(z).parent,D=E.edge(z,B),V=!1;D||(D=E.edge(B,z),V=!0),E.node(z).rank=E.node(B).rank+(V?D.minlen:-D.minlen)})}function N(T,E,R){return T.hasEdge(E,R)}function S(T,E,R){return R.low<=E.lim&&E.lim<=R.lim}}),nre=Tr((e,t)=>{var r=Nh(),s=r.longestPath,a=Q8(),i=tre();t.exports=l;function l(h){var p=h.graph().ranker;if(p instanceof Function)return p(h);switch(h.graph().ranker){case"network-simplex":m(h);break;case"tight-tree":u(h);break;case"longest-path":d(h);break;case"none":break;default:m(h)}}var d=s;function u(h){s(h),a(h)}function m(h){i(h)}}),rre=Tr((e,t)=>{t.exports=r;function r(i){let l=a(i);i.graph().dummyChains.forEach(d=>{let u=i.node(d),m=u.edgeObj,h=s(i,l,m.v,m.w),p=h.path,y=h.lca,x=0,v=p[x],j=!0;for(;d!==m.w;){if(u=i.node(d),j){for(;(v=p[x])!==y&&i.node(v).maxRank<u.rank;)x++;v===y&&(j=!1)}if(!j){for(;x<p.length-1&&i.node(v=p[x+1]).minRank<=u.rank;)x++;v=p[x]}i.setParent(d,v),d=i.successors(d)[0]}})}function s(i,l,d,u){let m=[],h=[],p=Math.min(l[d].low,l[u].low),y=Math.max(l[d].lim,l[u].lim),x,v;x=d;do x=i.parent(x),m.push(x);while(x&&(l[x].low>p||y>l[x].lim));for(v=x,x=u;(x=i.parent(x))!==v;)h.push(x);return{path:m.concat(h.reverse()),lca:v}}function a(i){let l={},d=0;function u(m){let h=d;i.children(m).forEach(u),l[m]={low:h,lim:d++}}return i.children().forEach(u),l}}),sre=Tr((e,t)=>{var r=ws();t.exports={run:s,cleanup:d};function s(u){let m=r.addDummyNode(u,"root",{},"_root"),h=i(u),p=Object.values(h),y=r.applyWithChunking(Math.max,p)-1,x=2*y+1;u.graph().nestingRoot=m,u.edges().forEach(j=>u.edge(j).minlen*=x);let v=l(u)+1;u.children().forEach(j=>a(u,m,x,v,y,h,j)),u.graph().nodeRankFactor=x}function a(u,m,h,p,y,x,v){let j=u.children(v);if(!j.length){v!==m&&u.setEdge(m,v,{weight:0,minlen:h});return}let C=r.addBorderNode(u,"_bt"),w=r.addBorderNode(u,"_bb"),N=u.node(v);u.setParent(C,v),N.borderTop=C,u.setParent(w,v),N.borderBottom=w,j.forEach(S=>{a(u,m,h,p,y,x,S);let T=u.node(S),E=T.borderTop?T.borderTop:S,R=T.borderBottom?T.borderBottom:S,I=T.borderTop?p:2*p,z=E!==R?1:y-x[v]+1;u.setEdge(C,E,{weight:I,minlen:z,nestingEdge:!0}),u.setEdge(R,w,{weight:I,minlen:z,nestingEdge:!0})}),u.parent(v)||u.setEdge(m,C,{weight:0,minlen:y+x[v]})}function i(u){var m={};function h(p,y){var x=u.children(p);x&&x.length&&x.forEach(v=>h(v,y+1)),m[p]=y}return u.children().forEach(p=>h(p,1)),m}function l(u){return u.edges().reduce((m,h)=>m+u.edge(h).weight,0)}function d(u){var m=u.graph();u.removeNode(m.nestingRoot),delete m.nestingRoot,u.edges().forEach(h=>{var p=u.edge(h);p.nestingEdge&&u.removeEdge(h)})}}),are=Tr((e,t)=>{var r=ws();t.exports=s;function s(i){function l(d){let u=i.children(d),m=i.node(d);if(u.length&&u.forEach(l),Object.hasOwn(m,"minRank")){m.borderLeft=[],m.borderRight=[];for(let h=m.minRank,p=m.maxRank+1;h<p;++h)a(i,"borderLeft","_bl",d,m,h),a(i,"borderRight","_br",d,m,h)}}i.children().forEach(l)}function a(i,l,d,u,m,h){let p={width:0,height:0,rank:h,borderType:l},y=m[l][h-1],x=r.addDummyNode(i,"border",p,d);m[l][h]=x,i.setParent(x,u),y&&i.setEdge(y,x,{weight:1})}}),ire=Tr((e,t)=>{t.exports={adjust:r,undo:s};function r(h){let p=h.graph().rankdir.toLowerCase();(p==="lr"||p==="rl")&&a(h)}function s(h){let p=h.graph().rankdir.toLowerCase();(p==="bt"||p==="rl")&&l(h),(p==="lr"||p==="rl")&&(u(h),a(h))}function a(h){h.nodes().forEach(p=>i(h.node(p))),h.edges().forEach(p=>i(h.edge(p)))}function i(h){let p=h.width;h.width=h.height,h.height=p}function l(h){h.nodes().forEach(p=>d(h.node(p))),h.edges().forEach(p=>{let y=h.edge(p);y.points.forEach(d),Object.hasOwn(y,"y")&&d(y)})}function d(h){h.y=-h.y}function u(h){h.nodes().forEach(p=>m(h.node(p))),h.edges().forEach(p=>{let y=h.edge(p);y.points.forEach(m),Object.hasOwn(y,"x")&&m(y)})}function m(h){let p=h.x;h.x=h.y,h.y=p}}),ore=Tr((e,t)=>{var r=ws();t.exports=s;function s(a){let i={},l=a.nodes().filter(p=>!a.children(p).length),d=l.map(p=>a.node(p).rank),u=r.applyWithChunking(Math.max,d),m=r.range(u+1).map(()=>[]);function h(p){if(i[p])return;i[p]=!0;let y=a.node(p);m[y.rank].push(p),a.successors(p).forEach(h)}return l.sort((p,y)=>a.node(p).rank-a.node(y).rank).forEach(h),m}}),lre=Tr((e,t)=>{var r=ws().zipObject;t.exports=s;function s(i,l){let d=0;for(let u=1;u<l.length;++u)d+=a(i,l[u-1],l[u]);return d}function a(i,l,d){let u=r(d,d.map((v,j)=>j)),m=l.flatMap(v=>i.outEdges(v).map(j=>({pos:u[j.w],weight:i.edge(j).weight})).sort((j,C)=>j.pos-C.pos)),h=1;for(;h<d.length;)h<<=1;let p=2*h-1;h-=1;let y=new Array(p).fill(0),x=0;return m.forEach(v=>{let j=v.pos+h;y[j]+=v.weight;let C=0;for(;j>0;)j%2&&(C+=y[j+1]),j=j-1>>1,y[j]+=v.weight;x+=v.weight*C}),x}}),cre=Tr((e,t)=>{t.exports=r;function r(s,a=[]){return a.map(i=>{let l=s.inEdges(i);if(l.length){let d=l.reduce((u,m)=>{let h=s.edge(m),p=s.node(m.v);return{sum:u.sum+h.weight*p.order,weight:u.weight+h.weight}},{sum:0,weight:0});return{v:i,barycenter:d.sum/d.weight,weight:d.weight}}else return{v:i}})}}),dre=Tr((e,t)=>{var r=ws();t.exports=s;function s(l,d){let u={};l.forEach((h,p)=>{let y=u[h.v]={indegree:0,in:[],out:[],vs:[h.v],i:p};h.barycenter!==void 0&&(y.barycenter=h.barycenter,y.weight=h.weight)}),d.edges().forEach(h=>{let p=u[h.v],y=u[h.w];p!==void 0&&y!==void 0&&(y.indegree++,p.out.push(u[h.w]))});let m=Object.values(u).filter(h=>!h.indegree);return a(m)}function a(l){let d=[];function u(h){return p=>{p.merged||(p.barycenter===void 0||h.barycenter===void 0||p.barycenter>=h.barycenter)&&i(h,p)}}function m(h){return p=>{p.in.push(h),--p.indegree===0&&l.push(p)}}for(;l.length;){let h=l.pop();d.push(h),h.in.reverse().forEach(u(h)),h.out.forEach(m(h))}return d.filter(h=>!h.merged).map(h=>r.pick(h,["vs","i","barycenter","weight"]))}function i(l,d){let u=0,m=0;l.weight&&(u+=l.barycenter*l.weight,m+=l.weight),d.weight&&(u+=d.barycenter*d.weight,m+=d.weight),l.vs=d.vs.concat(l.vs),l.barycenter=u/m,l.weight=m,l.i=Math.min(d.i,l.i),d.merged=!0}}),ure=Tr((e,t)=>{var r=ws();t.exports=s;function s(l,d){let u=r.partition(l,C=>Object.hasOwn(C,"barycenter")),m=u.lhs,h=u.rhs.sort((C,w)=>w.i-C.i),p=[],y=0,x=0,v=0;m.sort(i(!!d)),v=a(p,h,v),m.forEach(C=>{v+=C.vs.length,p.push(C.vs),y+=C.barycenter*C.weight,x+=C.weight,v=a(p,h,v)});let j={vs:p.flat(!0)};return x&&(j.barycenter=y/x,j.weight=x),j}function a(l,d,u){let m;for(;d.length&&(m=d[d.length-1]).i<=u;)d.pop(),l.push(m.vs),u++;return u}function i(l){return(d,u)=>d.barycenter<u.barycenter?-1:d.barycenter>u.barycenter?1:l?u.i-d.i:d.i-u.i}}),mre=Tr((e,t)=>{var r=cre(),s=dre(),a=ure();t.exports=i;function i(u,m,h,p){let y=u.children(m),x=u.node(m),v=x?x.borderLeft:void 0,j=x?x.borderRight:void 0,C={};v&&(y=y.filter(T=>T!==v&&T!==j));let w=r(u,y);w.forEach(T=>{if(u.children(T.v).length){let E=i(u,T.v,h,p);C[T.v]=E,Object.hasOwn(E,"barycenter")&&d(T,E)}});let N=s(w,h);l(N,C);let S=a(N,p);if(v&&(S.vs=[v,S.vs,j].flat(!0),u.predecessors(v).length)){let T=u.node(u.predecessors(v)[0]),E=u.node(u.predecessors(j)[0]);Object.hasOwn(S,"barycenter")||(S.barycenter=0,S.weight=0),S.barycenter=(S.barycenter*S.weight+T.order+E.order)/(S.weight+2),S.weight+=2}return S}function l(u,m){u.forEach(h=>{h.vs=h.vs.flatMap(p=>m[p]?m[p].vs:p)})}function d(u,m){u.barycenter!==void 0?(u.barycenter=(u.barycenter*u.weight+m.barycenter*m.weight)/(u.weight+m.weight),u.weight+=m.weight):(u.barycenter=m.barycenter,u.weight=m.weight)}}),fre=Tr((e,t)=>{var r=Ei().Graph,s=ws();t.exports=a;function a(l,d,u,m){m||(m=l.nodes());let h=i(l),p=new r({compound:!0}).setGraph({root:h}).setDefaultNodeLabel(y=>l.node(y));return m.forEach(y=>{let x=l.node(y),v=l.parent(y);(x.rank===d||x.minRank<=d&&d<=x.maxRank)&&(p.setNode(y),p.setParent(y,v||h),l[u](y).forEach(j=>{let C=j.v===y?j.w:j.v,w=p.edge(C,y),N=w!==void 0?w.weight:0;p.setEdge(C,y,{weight:l.edge(j).weight+N})}),Object.hasOwn(x,"minRank")&&p.setNode(y,{borderLeft:x.borderLeft[d],borderRight:x.borderRight[d]}))}),p}function i(l){for(var d;l.hasNode(d=s.uniqueId("_root")););return d}}),hre=Tr((e,t)=>{t.exports=r;function r(s,a,i){let l={},d;i.forEach(u=>{let m=s.parent(u),h,p;for(;m;){if(h=s.parent(m),h?(p=l[h],l[h]=m):(p=d,d=m),p&&p!==m){a.setEdge(p,m);return}m=h}})}}),pre=Tr((e,t)=>{var r=ore(),s=lre(),a=mre(),i=fre(),l=hre(),d=Ei().Graph,u=ws();t.exports=m;function m(x,v={}){if(typeof v.customOrder=="function"){v.customOrder(x,m);return}let j=u.maxRank(x),C=h(x,u.range(1,j+1),"inEdges"),w=h(x,u.range(j-1,-1,-1),"outEdges"),N=r(x);if(y(x,N),v.disableOptimalOrderHeuristic)return;let S=Number.POSITIVE_INFINITY,T,E=v.constraints||[];for(let R=0,I=0;I<4;++R,++I){p(R%2?C:w,R%4>=2,E),N=u.buildLayerMatrix(x);let z=s(x,N);z<S?(I=0,T=Object.assign({},N),S=z):z===S&&(T=structuredClone(N))}y(x,T)}function h(x,v,j){let C=new Map,w=(N,S)=>{C.has(N)||C.set(N,[]),C.get(N).push(S)};for(let N of x.nodes()){let S=x.node(N);if(typeof S.rank=="number"&&w(S.rank,N),typeof S.minRank=="number"&&typeof S.maxRank=="number")for(let T=S.minRank;T<=S.maxRank;T++)T!==S.rank&&w(T,N)}return v.map(function(N){return i(x,N,j,C.get(N)||[])})}function p(x,v,j){let C=new d;x.forEach(function(w){j.forEach(T=>C.setEdge(T.left,T.right));let N=w.graph().root,S=a(w,N,C,v);S.vs.forEach((T,E)=>w.node(T).order=E),l(w,C,S.vs)})}function y(x,v){Object.values(v).forEach(j=>j.forEach((C,w)=>x.node(C).order=w))}}),gre=Tr((e,t)=>{var r=Ei().Graph,s=ws();t.exports={positionX:j,findType1Conflicts:a,findType2Conflicts:i,addConflict:d,hasConflict:u,verticalAlignment:m,horizontalCompaction:h,alignCoordinates:x,findSmallestWidthAlignment:y,balance:v};function a(N,S){let T={};function E(R,I){let z=0,B=0,D=R.length,V=I[I.length-1];return I.forEach((Y,F)=>{let L=l(N,Y),O=L?N.node(L).order:D;(L||Y===V)&&(I.slice(B,F+1).forEach(M=>{N.predecessors(M).forEach($=>{let W=N.node($),U=W.order;(U<z||O<U)&&!(W.dummy&&N.node(M).dummy)&&d(T,$,M)})}),B=F+1,z=O)}),I}return S.length&&S.reduce(E),T}function i(N,S){let T={};function E(I,z,B,D,V){let Y;s.range(z,B).forEach(F=>{Y=I[F],N.node(Y).dummy&&N.predecessors(Y).forEach(L=>{let O=N.node(L);O.dummy&&(O.order<D||O.order>V)&&d(T,L,Y)})})}function R(I,z){let B=-1,D,V=0;return z.forEach((Y,F)=>{if(N.node(Y).dummy==="border"){let L=N.predecessors(Y);L.length&&(D=N.node(L[0]).order,E(z,V,F,B,D),V=F,B=D)}E(z,V,z.length,D,I.length)}),z}return S.length&&S.reduce(R),T}function l(N,S){if(N.node(S).dummy)return N.predecessors(S).find(T=>N.node(T).dummy)}function d(N,S,T){if(S>T){let R=S;S=T,T=R}let E=N[S];E||(N[S]=E={}),E[T]=!0}function u(N,S,T){if(S>T){let E=S;S=T,T=E}return!!N[S]&&Object.hasOwn(N[S],T)}function m(N,S,T,E){let R={},I={},z={};return S.forEach(B=>{B.forEach((D,V)=>{R[D]=D,I[D]=D,z[D]=V})}),S.forEach(B=>{let D=-1;B.forEach(V=>{let Y=E(V);if(Y.length){Y=Y.sort((L,O)=>z[L]-z[O]);let F=(Y.length-1)/2;for(let L=Math.floor(F),O=Math.ceil(F);L<=O;++L){let M=Y[L];I[V]===V&&D<z[M]&&!u(T,V,M)&&(I[M]=V,I[V]=R[V]=R[M],D=z[M])}}})}),{root:R,align:I}}function h(N,S,T,E,R){let I={},z=p(N,S,T,R),B=R?"borderLeft":"borderRight";function D(F,L){let O=z.nodes().slice(),M={},$=O.pop();for(;$;){if(M[$])F($);else{M[$]=!0,O.push($);for(let W of L($))O.push(W)}$=O.pop()}}function V(F){I[F]=z.inEdges(F).reduce((L,O)=>Math.max(L,I[O.v]+z.edge(O)),0)}function Y(F){let L=z.outEdges(F).reduce((M,$)=>Math.min(M,I[$.w]-z.edge($)),Number.POSITIVE_INFINITY),O=N.node(F);L!==Number.POSITIVE_INFINITY&&O.borderType!==B&&(I[F]=Math.max(I[F],L))}return D(V,z.predecessors.bind(z)),D(Y,z.successors.bind(z)),Object.keys(E).forEach(F=>I[F]=I[T[F]]),I}function p(N,S,T,E){let R=new r,I=N.graph(),z=C(I.nodesep,I.edgesep,E);return S.forEach(B=>{let D;B.forEach(V=>{let Y=T[V];if(R.setNode(Y),D){var F=T[D],L=R.edge(F,Y);R.setEdge(F,Y,Math.max(z(N,V,D),L||0))}D=V})}),R}function y(N,S){return Object.values(S).reduce((T,E)=>{let R=Number.NEGATIVE_INFINITY,I=Number.POSITIVE_INFINITY;Object.entries(E).forEach(([B,D])=>{let V=w(N,B)/2;R=Math.max(D+V,R),I=Math.min(D-V,I)});let z=R-I;return z<T[0]&&(T=[z,E]),T},[Number.POSITIVE_INFINITY,null])[1]}function x(N,S){let T=Object.values(S),E=s.applyWithChunking(Math.min,T),R=s.applyWithChunking(Math.max,T);["u","d"].forEach(I=>{["l","r"].forEach(z=>{let B=I+z,D=N[B];if(D===S)return;let V=Object.values(D),Y=E-s.applyWithChunking(Math.min,V);z!=="l"&&(Y=R-s.applyWithChunking(Math.max,V)),Y&&(N[B]=s.mapValues(D,F=>F+Y))})})}function v(N,S){return s.mapValues(N.ul,(T,E)=>{if(S)return N[S.toLowerCase()][E];{let R=Object.values(N).map(I=>I[E]).sort((I,z)=>I-z);return(R[1]+R[2])/2}})}function j(N){let S=s.buildLayerMatrix(N),T=Object.assign(a(N,S),i(N,S)),E={},R;["u","d"].forEach(z=>{R=z==="u"?S:Object.values(S).reverse(),["l","r"].forEach(B=>{B==="r"&&(R=R.map(F=>Object.values(F).reverse()));let D=(z==="u"?N.predecessors:N.successors).bind(N),V=m(N,R,T,D),Y=h(N,R,V.root,V.align,B==="r");B==="r"&&(Y=s.mapValues(Y,F=>-F)),E[z+B]=Y})});let I=y(N,E);return x(E,I),v(E,N.graph().align)}function C(N,S,T){return(E,R,I)=>{let z=E.node(R),B=E.node(I),D=0,V;if(D+=z.width/2,Object.hasOwn(z,"labelpos"))switch(z.labelpos.toLowerCase()){case"l":V=-z.width/2;break;case"r":V=z.width/2;break}if(V&&(D+=T?V:-V),V=0,D+=(z.dummy?S:N)/2,D+=(B.dummy?S:N)/2,D+=B.width/2,Object.hasOwn(B,"labelpos"))switch(B.labelpos.toLowerCase()){case"l":V=B.width/2;break;case"r":V=-B.width/2;break}return V&&(D+=T?V:-V),V=0,D}}function w(N,S){return N.node(S).width}}),xre=Tr((e,t)=>{var r=ws(),s=gre().positionX;t.exports=a;function a(l){l=r.asNonCompoundGraph(l),i(l),Object.entries(s(l)).forEach(([d,u])=>l.node(d).x=u)}function i(l){let d=r.buildLayerMatrix(l),u=l.graph().ranksep,m=l.graph().rankalign,h=0;d.forEach(p=>{let y=p.reduce((x,v)=>{let j=l.node(v).height;return x>j?x:j},0);p.forEach(x=>{let v=l.node(x);m==="top"?v.y=h+v.height/2:m==="bottom"?v.y=h+y-v.height/2:v.y=h+y/2}),h+=y+u})}}),bre=Tr((e,t)=>{var r=Jne(),s=ere(),a=nre(),i=ws().normalizeRanks,l=rre(),d=ws().removeEmptyRanks,u=sre(),m=are(),h=ire(),p=pre(),y=xre(),x=ws(),v=Ei().Graph;t.exports=j;function j(X,ee={}){let te=ee.debugTiming?x.time:x.notime;return te("layout",()=>{let G=te(" buildLayoutGraph",()=>D(X));return te(" runLayout",()=>C(G,te,ee)),te(" updateInputGraph",()=>w(X,G)),G})}function C(X,ee,te){ee(" makeSpaceForEdgeLabels",()=>V(X)),ee(" removeSelfEdges",()=>H(X)),ee(" acyclic",()=>r.run(X)),ee(" nestingGraph.run",()=>u.run(X)),ee(" rank",()=>a(x.asNonCompoundGraph(X))),ee(" injectEdgeLabelProxies",()=>Y(X)),ee(" removeEmptyRanks",()=>d(X)),ee(" nestingGraph.cleanup",()=>u.cleanup(X)),ee(" normalizeRanks",()=>i(X)),ee(" assignRankMinMax",()=>F(X)),ee(" removeEdgeLabelProxies",()=>L(X)),ee(" normalize.run",()=>s.run(X)),ee(" parentDummyChains",()=>l(X)),ee(" addBorderSegments",()=>m(X)),ee(" order",()=>p(X,te)),ee(" insertSelfEdges",()=>q(X)),ee(" adjustCoordinateSystem",()=>h.adjust(X)),ee(" position",()=>y(X)),ee(" positionSelfEdges",()=>Z(X)),ee(" removeBorderNodes",()=>U(X)),ee(" normalize.undo",()=>s.undo(X)),ee(" fixupEdgeLabelCoords",()=>$(X)),ee(" undoCoordinateSystem",()=>h.undo(X)),ee(" translateGraph",()=>O(X)),ee(" assignNodeIntersects",()=>M(X)),ee(" reversePoints",()=>W(X)),ee(" acyclic.undo",()=>r.undo(X))}function w(X,ee){X.nodes().forEach(te=>{let G=X.node(te),ue=ee.node(te);G&&(G.x=ue.x,G.y=ue.y,G.order=ue.order,G.rank=ue.rank,ee.children(te).length&&(G.width=ue.width,G.height=ue.height))}),X.edges().forEach(te=>{let G=X.edge(te),ue=ee.edge(te);G.points=ue.points,Object.hasOwn(ue,"x")&&(G.x=ue.x,G.y=ue.y)}),X.graph().width=ee.graph().width,X.graph().height=ee.graph().height}var N=["nodesep","edgesep","ranksep","marginx","marginy"],S={ranksep:50,edgesep:20,nodesep:50,rankdir:"tb",rankalign:"center"},T=["acyclicer","ranker","rankdir","align","rankalign"],E=["width","height","rank"],R={width:0,height:0},I=["minlen","weight","width","height","labeloffset"],z={minlen:1,weight:1,width:0,height:0,labeloffset:10,labelpos:"r"},B=["labelpos"];function D(X){let ee=new v({multigraph:!0,compound:!0}),te=J(X.graph());return ee.setGraph(Object.assign({},S,_(te,N),x.pick(te,T))),X.nodes().forEach(G=>{let ue=J(X.node(G)),Se=_(ue,E);Object.keys(R).forEach(Ce=>{Se[Ce]===void 0&&(Se[Ce]=R[Ce])}),ee.setNode(G,Se),ee.setParent(G,X.parent(G))}),X.edges().forEach(G=>{let ue=J(X.edge(G));ee.setEdge(G,Object.assign({},z,_(ue,I),x.pick(ue,B)))}),ee}function V(X){let ee=X.graph();ee.ranksep/=2,X.edges().forEach(te=>{let G=X.edge(te);G.minlen*=2,G.labelpos.toLowerCase()!=="c"&&(ee.rankdir==="TB"||ee.rankdir==="BT"?G.width+=G.labeloffset:G.height+=G.labeloffset)})}function Y(X){X.edges().forEach(ee=>{let te=X.edge(ee);if(te.width&&te.height){let G=X.node(ee.v),ue={rank:(X.node(ee.w).rank-G.rank)/2+G.rank,e:ee};x.addDummyNode(X,"edge-proxy",ue,"_ep")}})}function F(X){let ee=0;X.nodes().forEach(te=>{let G=X.node(te);G.borderTop&&(G.minRank=X.node(G.borderTop).rank,G.maxRank=X.node(G.borderBottom).rank,ee=Math.max(ee,G.maxRank))}),X.graph().maxRank=ee}function L(X){X.nodes().forEach(ee=>{let te=X.node(ee);te.dummy==="edge-proxy"&&(X.edge(te.e).labelRank=te.rank,X.removeNode(ee))})}function O(X){let ee=Number.POSITIVE_INFINITY,te=0,G=Number.POSITIVE_INFINITY,ue=0,Se=X.graph(),Ce=Se.marginx||0,Be=Se.marginy||0;function Ne(he){let _e=he.x,Ee=he.y,Ye=he.width,Ze=he.height;ee=Math.min(ee,_e-Ye/2),te=Math.max(te,_e+Ye/2),G=Math.min(G,Ee-Ze/2),ue=Math.max(ue,Ee+Ze/2)}X.nodes().forEach(he=>Ne(X.node(he))),X.edges().forEach(he=>{let _e=X.edge(he);Object.hasOwn(_e,"x")&&Ne(_e)}),ee-=Ce,G-=Be,X.nodes().forEach(he=>{let _e=X.node(he);_e.x-=ee,_e.y-=G}),X.edges().forEach(he=>{let _e=X.edge(he);_e.points.forEach(Ee=>{Ee.x-=ee,Ee.y-=G}),Object.hasOwn(_e,"x")&&(_e.x-=ee),Object.hasOwn(_e,"y")&&(_e.y-=G)}),Se.width=te-ee+Ce,Se.height=ue-G+Be}function M(X){X.edges().forEach(ee=>{let te=X.edge(ee),G=X.node(ee.v),ue=X.node(ee.w),Se,Ce;te.points?(Se=te.points[0],Ce=te.points[te.points.length-1]):(te.points=[],Se=ue,Ce=G),te.points.unshift(x.intersectRect(G,Se)),te.points.push(x.intersectRect(ue,Ce))})}function $(X){X.edges().forEach(ee=>{let te=X.edge(ee);if(Object.hasOwn(te,"x"))switch((te.labelpos==="l"||te.labelpos==="r")&&(te.width-=te.labeloffset),te.labelpos){case"l":te.x-=te.width/2+te.labeloffset;break;case"r":te.x+=te.width/2+te.labeloffset;break}})}function W(X){X.edges().forEach(ee=>{let te=X.edge(ee);te.reversed&&te.points.reverse()})}function U(X){X.nodes().forEach(ee=>{if(X.children(ee).length){let te=X.node(ee),G=X.node(te.borderTop),ue=X.node(te.borderBottom),Se=X.node(te.borderLeft[te.borderLeft.length-1]),Ce=X.node(te.borderRight[te.borderRight.length-1]);te.width=Math.abs(Ce.x-Se.x),te.height=Math.abs(ue.y-G.y),te.x=Se.x+te.width/2,te.y=G.y+te.height/2}}),X.nodes().forEach(ee=>{X.node(ee).dummy==="border"&&X.removeNode(ee)})}function H(X){X.edges().forEach(ee=>{if(ee.v===ee.w){var te=X.node(ee.v);te.selfEdges||(te.selfEdges=[]),te.selfEdges.push({e:ee,label:X.edge(ee)}),X.removeEdge(ee)}})}function q(X){var ee=x.buildLayerMatrix(X);ee.forEach(te=>{var G=0;te.forEach((ue,Se)=>{var Ce=X.node(ue);Ce.order=Se+G,(Ce.selfEdges||[]).forEach(Be=>{x.addDummyNode(X,"selfedge",{width:Be.label.width,height:Be.label.height,rank:Ce.rank,order:Se+ ++G,e:Be.e,label:Be.label},"_se")}),delete Ce.selfEdges})})}function Z(X){X.nodes().forEach(ee=>{var te=X.node(ee);if(te.dummy==="selfedge"){var G=X.node(te.e.v),ue=G.x+G.width/2,Se=G.y,Ce=te.x-ue,Be=G.height/2;X.setEdge(te.e,te.label),X.removeNode(ee),te.label.points=[{x:ue+2*Ce/3,y:Se-Be},{x:ue+5*Ce/6,y:Se-Be},{x:ue+Ce,y:Se},{x:ue+5*Ce/6,y:Se+Be},{x:ue+2*Ce/3,y:Se+Be}],te.label.x=te.x,te.label.y=te.y}})}function _(X,ee){return x.mapValues(x.pick(X,ee),Number)}function J(X){var ee={};return X&&Object.entries(X).forEach(([te,G])=>{typeof te=="string"&&(te=te.toLowerCase()),ee[te]=G}),ee}}),yre=Tr((e,t)=>{var r=ws(),s=Ei().Graph;t.exports={debugOrdering:a};function a(i){let l=r.buildLayerMatrix(i),d=new s({compound:!0,multigraph:!0}).setGraph({});return i.nodes().forEach(u=>{d.setNode(u,{label:u}),d.setParent(u,"layer"+i.node(u).rank)}),i.edges().forEach(u=>d.setEdge(u.v,u.w,{},u.name)),l.forEach((u,m)=>{let h="layer"+m;d.setNode(h,{rank:"same"}),u.reduce((p,y)=>(d.setEdge(p,y,{style:"invis"}),y))}),d}}),vre=Tr((e,t)=>{t.exports="2.0.4"}),wre=Tr((e,t)=>{t.exports={graphlib:Ei(),layout:bre(),debug:yre(),util:{time:ws().time,notime:ws().notime},version:vre()}});const b3=wre();const y3={pending:{bg:"bg-blue-500/10",border:"border-blue-500/30",text:"text-blue-500"},in_progress:{bg:"bg-amber-500/10",border:"border-amber-500/30",text:"text-amber-600"},blocked:{bg:"bg-red-500/8",border:"border-red-500/25",text:"text-red-500"},review:{bg:"bg-brand-500/10",border:"border-brand-500/30",text:"text-brand-500"},completed:{bg:"bg-green-500/10",border:"border-green-500/30",text:"text-green-600"},failed:{bg:"bg-red-500/10",border:"border-red-500/30",text:"text-red-500"},rejected:{bg:"bg-red-500/8",border:"border-red-500/25",text:"text-red-500"},cancelled:{bg:"bg-gray-500/8",border:"border-gray-500/20",text:"text-fg-tertiary"},archived:{bg:"bg-gray-500/5",border:"border-gray-500/15",text:"text-fg-tertiary"}},kre={critical:"bg-red-500",high:"bg-amber-500",medium:"bg-amber-500",low:"bg-blue-500"};function jre({data:e}){const{t}=pt(["work","common"]),{task:r,agentName:s,selected:a,direction:i="TB",isExpandedRoot:l,onCollapse:d}=e,u=y3[r.status]??y3.pending,m=r.taskType==="scheduled"&&!!r.scheduleConfig,h=m?r.scheduleConfig.every?t("work:task.everyInterval",{interval:r.scheduleConfig.every}):r.scheduleConfig.cron?t("work:task.cronLabel"):"":"",p=i==="LR"?Jt.Left:Jt.Top,y=i==="LR"?Jt.Right:Jt.Bottom;return n.jsxs("div",{className:`relative rounded-lg border px-3 py-2 min-w-[180px] max-w-[220px] shadow-md backdrop-blur-sm ${m?`${u.bg} border-blue-500/40 ring-1 ring-blue-500/20`:`${u.bg} ${u.border}`} ${a?"ring-2 ring-brand-500 shadow-brand-500/25 shadow-lg":""}`,children:[n.jsx(Cl,{type:"target",position:p,className:"!bg-border-default !w-2 !h-2"}),n.jsxs("div",{className:"flex items-center gap-1.5 mb-1",children:[n.jsx("span",{className:`w-2 h-2 rounded-full shrink-0 ${kre[r.priority]??"bg-gray-500"}`}),n.jsx("span",{className:`text-[10px] font-medium uppercase tracking-wider ${u.text}`,children:t(`work:status.task.${r.status}`,{defaultValue:r.status.replace("_"," ")})}),m&&n.jsxs("span",{className:"text-[9px] px-1 py-0.5 rounded bg-blue-500/15 text-blue-600 ml-auto whitespace-nowrap inline-flex items-center gap-0.5",children:[n.jsx("svg",{className:"w-2.5 h-2.5",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"3",strokeLinecap:"round",strokeLinejoin:"round",children:n.jsx("path",{d:"M21.5 2v6h-6M2.5 22v-6h6M2 11.5a10 10 0 0 1 18.8-4.3M22 12.5a10 10 0 0 1-18.8 4.3"})}),h]})]}),n.jsx("div",{className:"text-xs font-medium text-fg-primary leading-snug line-clamp-2 mb-1",children:r.title}),s&&n.jsx("div",{className:"text-[10px] text-fg-tertiary truncate",children:s}),r.blockedBy&&r.blockedBy.length>0&&n.jsx("div",{className:"text-[10px] text-fg-tertiary mt-0.5",children:t("work:dag.depCount",{count:r.blockedBy.length})}),n.jsx(Cl,{type:"source",position:y,className:"!bg-border-default !w-2 !h-2"}),l&&d&&n.jsx("button",{onClick:x=>{x.stopPropagation(),d()},className:"absolute top-1/2 -translate-y-1/2 -right-7 w-5 h-5 rounded-full bg-surface-secondary border border-border-default flex items-center justify-center text-fg-tertiary hover:text-fg-primary hover:bg-surface-overlay transition-colors shadow-sm",title:t("work:dag.backToOverview"),children:n.jsx("svg",{className:"w-3 h-3",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:n.jsx("path",{d:"M15 3h6v6M9 21H3v-6M21 3l-7 7M3 21l7-7"})})})]})}const v3={pending:{bg:"bg-amber-500/10",border:"border-amber-500/30",text:"text-amber-600"},in_progress:{bg:"bg-brand-500/10",border:"border-brand-500/30",text:"text-brand-500"},completed:{bg:"bg-green-500/10",border:"border-green-500/30",text:"text-green-600"},rejected:{bg:"bg-red-500/10",border:"border-red-500/30",text:"text-red-500"},cancelled:{bg:"bg-gray-500/8",border:"border-gray-500/20",text:"text-fg-tertiary"}},w3={pending:"todo",in_progress:"in_progress",completed:"done",rejected:"done",cancelled:"done",archived:"done"};function Nre({data:e}){const{t}=pt(["work","common"]),{req:r,selected:s,direction:a="TB",isExpandedRoot:i,onCollapse:l}=e,d=v3[r.status]??v3.pending,u=a==="LR"?Jt.Left:Jt.Top,m=a==="LR"?Jt.Right:Jt.Bottom;return n.jsxs("div",{className:`relative rounded-lg border-2 border-dashed px-3 py-2 min-w-[180px] max-w-[220px] shadow-lg ${d.bg} ${d.border} ${s?"ring-2 ring-brand-500 shadow-brand-500/25":""}`,children:[n.jsx(Cl,{type:"target",position:u,className:"!bg-border-default !w-2 !h-2"}),n.jsxs("div",{className:"flex items-center gap-1.5 mb-1",children:[n.jsx("span",{className:"text-[9px] px-1 py-0.5 rounded font-semibold bg-amber-500/15 text-amber-600",children:t("work:dag.reqLabel")}),n.jsx("span",{className:`text-[10px] font-medium uppercase tracking-wider ${d.text}`,children:t(`work:status.requirement.${r.status}`,{defaultValue:r.status.replace("_"," ")})})]}),n.jsx("div",{className:"text-xs font-medium text-fg-primary leading-snug line-clamp-2 mb-1",children:r.title}),r.taskIds.length>0&&n.jsx("div",{className:"text-[10px] text-fg-tertiary",children:t("work:dag.taskCount",{count:r.taskIds.length})}),n.jsx(Cl,{type:"source",position:m,className:"!bg-border-default !w-2 !h-2"}),i&&l&&n.jsx("button",{onClick:h=>{h.stopPropagation(),l()},className:"absolute top-1/2 -translate-y-1/2 -right-7 w-5 h-5 rounded-full bg-surface-secondary border border-border-default flex items-center justify-center text-fg-tertiary hover:text-fg-primary hover:bg-surface-overlay transition-colors shadow-sm",title:t("work:dag.backToOverview"),children:n.jsx("svg",{className:"w-3 h-3",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:n.jsx("path",{d:"M15 3h6v6M9 21H3v-6M21 3l-7 7M3 21l7-7"})})})]})}const Sre={task:jre,requirement:Nre};function Cre({nodeIds:e,rfRef:t}){const r=vne();return g.useEffect(()=>{if(e.length===0)return;const s=setTimeout(()=>{r(e),requestAnimationFrame(()=>{t.current?.fitView({padding:.2})})},300);return()=>clearTimeout(s)},[e.length]),null}const Tre=()=>document.documentElement.classList.contains("light")||!document.documentElement.classList.contains("dark")&&!document.documentElement.classList.contains("cyberpunk")&&!document.documentElement.classList.contains("mono")&&window.matchMedia("(prefers-color-scheme: light)").matches,Are=e=>{const t=new MutationObserver(e);t.observe(document.documentElement,{attributes:!0,attributeFilter:["class"]});const r=window.matchMedia("(prefers-color-scheme: light)");return r.addEventListener("change",e),()=>{t.disconnect(),r.removeEventListener("change",e)}};function Ere(){return g.useSyncExternalStore(Are,Tre,()=>!1)}const Uf=200,Vf=80;function k3(e,t,r="TB"){const s=i=>{const l=new b3.graphlib.Graph;l.setDefaultEdgeLabel(()=>({})),l.setGraph({rankdir:i,nodesep:40,ranksep:60});for(const d of e)l.setNode(d.id,{width:Uf,height:Vf});for(const d of t)l.setEdge(d.source,d.target);return b3.layout(l),e.map(d=>{const u=l.node(d.id);return{...d,position:{x:(u?.x??0)-Uf/2,y:(u?.y??0)-Vf/2}}})},a=s(r);if(t.length>0&&e.length>4){let i=1/0,l=-1/0,d=1/0,u=-1/0;for(const y of a)i=Math.min(i,y.position.x),l=Math.max(l,y.position.x+Uf),d=Math.min(d,y.position.y),u=Math.max(u,y.position.y+Vf);const m=l-i,h=u-d,p=r==="TB"?"LR":"TB";if(m>h*3)return{nodes:s(p),direction:p}}return{nodes:a,direction:r}}function Mre(e,t){const r=new Map,s=new Map;for(const l of e)s.set(l.id,l),r.set(l.id,new Set);for(const l of t)r.get(l.source)?.add(l.target),r.get(l.target)?.add(l.source);const a=new Set,i=[];for(const l of e){if(a.has(l.id))continue;const d=new Set,u=[l.id];for(;u.length>0;){const m=u.pop();if(!a.has(m)){a.add(m),d.add(m);for(const h of r.get(m)??[])a.has(h)||u.push(h)}}i.push({nodes:e.filter(m=>d.has(m.id)),edges:t.filter(m=>d.has(m.source)&&d.has(m.target))})}return i}function j3(e,t){if(e.length===0)return{nodes:[],direction:"TB"};const r=Mre(e,t);if(r.length===1)return k3(e,t);let s="TB";const a=r.map(y=>{const{nodes:x,direction:v}=k3(y.nodes,y.edges);s=v;let j=1/0,C=-1/0,w=1/0,N=-1/0;for(const S of x)j=Math.min(j,S.position.x),C=Math.max(C,S.position.x+Uf),w=Math.min(w,S.position.y),N=Math.max(N,S.position.y+Vf);for(const S of x)S.position.x-=j,S.position.y-=w;return{nodes:x,w:C-j,h:N-w}});a.sort((y,x)=>x.h-y.h);const i=60,l=a.reduce((y,x)=>y+(x.w+i)*(x.h+i),0),d=Math.sqrt(l)*1.1,u=[];let m=0,h=0,p=0;for(const y of a){m>0&&m+y.w>d&&(m=0,h+=p+i,p=0);for(const x of y.nodes)u.push({...x,position:{x:x.position.x+m,y:x.position.y+h}});m+=y.w+i,p=Math.max(p,y.h)}return{nodes:u,direction:s}}function Dre(e,t,r){const s=new Set,a=[t];for(;a.length>0;){const i=a.pop();if(i===r)return!0;if(s.has(i))continue;s.add(i);const l=e.get(i);if(l?.blockedBy)for(const d of l.blockedBy)a.push(d)}return!1}const hd=[{id:"todo",statuses:new Set(["pending"]),color:{bg:"bg-blue-500/10",border:"border-blue-500/30",text:"text-blue-500"}},{id:"in_progress",statuses:new Set(["in_progress","blocked"]),color:{bg:"bg-amber-500/10",border:"border-amber-500/30",text:"text-amber-600"}},{id:"review",statuses:new Set(["review"]),color:{bg:"bg-brand-500/10",border:"border-brand-500/30",text:"text-brand-500"}},{id:"done",statuses:new Set(["completed","failed","rejected","cancelled","archived"]),color:{bg:"bg-green-500/10",border:"border-green-500/30",text:"text-green-600"}}];new Set(hd.map(e=>e.id));const Sf=new Set(hd.filter(e=>e.id!=="done").map(e=>e.id)),N3=e=>e.status==="archived";function Rre(e,t,r,s){const a=new Set,i=[e];for(;i.length>0;){const l=i.pop();if(!a.has(l))if(a.add(l),l.startsWith("req-")){const d=r.get(l.slice(4));if(d)for(const u of d.taskIds)i.push(u)}else{const d=t.get(l);if(d?.blockedBy)for(const u of d.blockedBy)i.push(u);d?.requirementId&&i.push(`req-${d.requirementId}`)}}for(const l of s)l.requirementId&&a.has(l.id)&&a.add(`req-${l.requirementId}`);return a}function Ire({tasks:e,requirements:t=[],agents:r,showArchived:s,onShowArchivedChange:a,onTaskClick:i,onReqClick:l,onCollapseDAG:d,onDependencyChange:u,selectedTaskId:m,selectedReqId:h,hasDetailPanel:p,defaultExpandedNodeId:y,previewMode:x}){const{t:v}=pt(["work","common"]),j=Ere(),[C,w]=g.useState(null),[N,S]=g.useState(null),[T,E]=g.useState(()=>new Set(Sf)),[R,I]=g.useState(y??null),[z,B]=g.useState(s??!1),D=s??z,V=g.useCallback(ne=>{const me=typeof ne=="function"?ne(D):ne;B(me),a?.(me)},[D,a]);g.useEffect(()=>{s!==void 0&&B(s)},[s]),g.useEffect(()=>{y&&I(y)},[y]);const Y=g.useMemo(()=>e.filter(ne=>N3(ne)).length,[e]),F=g.useMemo(()=>{const ne=new Set;for(const me of hd)if(T.has(me.id))for(const be of me.statuses)ne.add(be);return ne},[T]),L=g.useMemo(()=>{const ne=new Set;for(const me of e)for(const be of hd)if(be.statuses.has(me.status)){ne.add(be.id);break}for(const me of t){const be=w3[me.status];be&&ne.add(be)}return hd.filter(me=>ne.has(me.id))},[e,t]),O=g.useCallback(ne=>{E(me=>{const be=new Set(me);return be.has(ne)?be.delete(ne):be.add(ne),be})},[]),M=g.useCallback((ne,me="success")=>{w({msg:ne,type:me}),setTimeout(()=>w(null),2500)},[]),$=g.useMemo(()=>{const ne=new Map;for(const me of r)ne.set(me.id,me.name);return ne},[r]),W=g.useMemo(()=>{const ne=new Map;for(const me of e)ne.set(me.id,me);return ne},[e]),U=g.useMemo(()=>{const ne=new Map;for(const me of t)ne.set(me.id,me);return ne},[t]),H=g.useRef(!1),q=g.useCallback(()=>{H.current=!1,I(null),d?.()},[d]),Z=j?"#94a3b8":"#6b7280",_=g.useCallback((ne,me,be)=>({id:`${ne}->${me}`,source:ne,target:me,animated:be==="blocked",markerEnd:{type:Td.ArrowClosed,width:14,height:14,color:be==="blocked"?"#ef4444":Z},style:{stroke:be==="blocked"?"#ef4444":Z,strokeWidth:1.5,cursor:"pointer"}}),[Z]),{initialNodes:J,initialEdges:X,topLevelIds:ee}=g.useMemo(()=>{const ne=(Re,We)=>{const Vt=new Set,ln=Re.map(Zt=>(Vt.add(Zt.id),{id:Zt.id,type:"task",data:{task:Zt,agentName:Zt.assignedAgentId?$.get(Zt.assignedAgentId):void 0,selected:Zt.id===m},position:{x:0,y:0}}));for(const Zt of We){const cn=`req-${Zt.id}`;Vt.add(cn),ln.push({id:cn,type:"requirement",data:{req:Zt,selected:Zt.id===h},position:{x:0,y:0}})}const en=[];for(const Zt of Re)if(Zt.blockedBy)for(const cn of Zt.blockedBy)Vt.has(cn)&&en.push(_(cn,Zt.id,Zt.status));const vn=new Set,In=(Zt,cn)=>{const Gn=`${Zt}->${cn}`;vn.has(Gn)||(vn.add(Gn),en.push({id:Gn,source:Zt,target:cn,markerEnd:{type:Td.ArrowClosed,width:14,height:14,color:"#8b5cf6"},style:{stroke:"#8b5cf6",strokeWidth:1.5,strokeDasharray:"4 2"}}))};for(const Zt of We){const cn=`req-${Zt.id}`;for(const Gn of Zt.taskIds)Vt.has(Gn)&&In(cn,Gn)}for(const Zt of Re)if(Zt.requirementId){const cn=`req-${Zt.requirementId}`;Vt.has(cn)&&In(cn,Zt.id)}return{nodes:ln,edges:en}},me=e.filter(Re=>F.has(Re.status)&&(D||!N3(Re))),be=new Set;for(const Re of hd)T.has(Re.id)&&be.add(Re.id);const se=t.filter(Re=>{const We=w3[Re.status];return We&&be.has(We)}),{nodes:fe,edges:He}=ne(me,se),Ae=new Set;for(const Re of He)Ae.add(Re.target);const et=new Set(fe.filter(Re=>!Ae.has(Re.id)).map(Re=>Re.id));if(!R||!et.has(R)){const Re=fe.filter(en=>et.has(en.id)),{nodes:We,direction:Vt}=j3(Re,[]);return{initialNodes:We.map(en=>({...en,data:{...en.data,direction:Vt}})),initialEdges:[],topLevelIds:et}}const{nodes:pe,edges:Fe}=ne(e,t),Ve=Rre(R,W,U,e),nt=pe.filter(Re=>Ve.has(Re.id)).map(Re=>Re.id===R?{...Re,data:{...Re.data,isExpandedRoot:!0,onCollapse:q}}:Re),gt=Fe.filter(Re=>Ve.has(Re.source)&&Ve.has(Re.target)),{nodes:rt,direction:Et}=j3(nt,gt);return{initialNodes:rt.map(Re=>({...Re,data:{...Re.data,direction:Et}})),initialEdges:gt,topLevelIds:et}},[e,t,$,W,U,_,F,T,D,m,h,R,q]),[te,G,ue]=wne(J),[Se,Ce,Be]=kne(X),Ne=g.useRef(null),he=g.useRef({groupFilter:T,showArchived:D});g.useEffect(()=>{const ne=he.current;(ne.groupFilter!==T||ne.showArchived!==D)&&(H.current=!1,I(null),he.current={groupFilter:T,showArchived:D})},[T,D]),g.useEffect(()=>{G(J),Ce(X),H.current||requestAnimationFrame(()=>{Ne.current?.fitView({padding:.2,duration:300})})},[J,X,G,Ce]),g.useEffect(()=>{const ne=setTimeout(()=>{Ne.current?.fitView({padding:.2,duration:300})},50);return()=>clearTimeout(ne)},[p]);const _e=g.useCallback(ne=>{ne&&(H.current=!0)},[]),Ee=g.useCallback((ne,me)=>{if(!R&&ee.has(me.id)&&(H.current=!1,I(me.id)),me.id.startsWith("req-")){const be=U.get(me.id.slice(4));be&&l&&l(be)}else{const be=W.get(me.id);be&&i&&i(be)}},[W,U,i,l,ee,R]),Ye=g.useCallback(async ne=>{const{source:me,target:be}=ne;if(!me||!be||me===be)return;const se=W.get(be);if(!se)return;if(se.blockedBy?.includes(me)){M(v("work:dag.toast.dependencyExists"),"error");return}if(Dre(W,me,be)){M(v("work:dag.toast.cycleError"),"error");return}const fe=[...se.blockedBy??[],me];try{await ie.tasks.update(be,{blockedBy:fe}),M(v("work:dag.toast.dependencyAdded")),u?.()}catch(He){M(v("work:dag.toast.failed",{message:He instanceof Error?He.message:String(He)}),"error")}},[W,M,u,v]),Ze=g.useCallback((ne,me)=>{S(me)},[]),mt=g.useCallback(async()=>{if(!N)return;const ne=W.get(N.target);if(!ne){S(null);return}const me=(ne.blockedBy??[]).filter(be=>be!==N.source);try{await ie.tasks.update(N.target,{blockedBy:me}),M(v("work:dag.toast.dependencyRemoved")),u?.()}catch(be){M(v("work:dag.toast.failed",{message:be instanceof Error?be.message:String(be)}),"error")}S(null)},[N,W,M,u,v]);if(e.length===0)return n.jsx("div",{className:"flex-1 flex items-center justify-center text-fg-tertiary text-sm",children:v("work:dag.noTasks")});const it=T.size===Sf.size&&[...Sf].every(ne=>T.has(ne))&&!D,Lt=N?W.get(N.source):null,ht=N?W.get(N.target):null;return n.jsxs("div",{className:"flex-1 min-h-0 relative",style:{height:"100%"},children:[n.jsxs(yne,{nodes:te,edges:Se,onNodesChange:ue,onEdgesChange:Be,onNodeClick:Ee,onConnect:Ye,onEdgeClick:Ze,onMoveEnd:_e,onInit:ne=>{Ne.current=ne},nodeTypes:Sre,fitView:!0,minZoom:.3,maxZoom:2,proOptions:{hideAttribution:!0},connectionLineStyle:{stroke:"#818cf8",strokeWidth:2,strokeDasharray:"6 3"},children:[x&&n.jsx(Cre,{nodeIds:te.map(ne=>ne.id),rfRef:Ne}),n.jsx(Tne,{color:j?"#cbd5e1":"#374151",gap:20,size:1}),n.jsx(Lne,{showInteractive:!1,className:"!bg-surface-secondary !border-border-default !shadow-xl [&>button]:!bg-surface-elevated [&>button]:!border-border-default [&>button]:!text-fg-secondary [&>button:hover]:!bg-surface-overlay"}),n.jsx(Wne,{nodeColor:ne=>{const me=ne.data?.task,be=me?.status;return me?.taskType==="scheduled"?"#06b6d4":be==="completed"||be==="accepted"?"#10b981":be==="in_progress"?"#f59e0b":be==="blocked"||be==="failed"?"#ef4444":j?"#94a3b8":"#6b7280"},maskColor:j?"rgba(255,255,255,0.7)":"rgba(0,0,0,0.7)",className:"!bg-surface-secondary !border-border-default"})]}),n.jsxs("div",{className:"absolute top-2 left-1/2 -translate-x-1/2 px-3 py-1.5 bg-surface-secondary/90 border border-border-default rounded-lg backdrop-blur-sm z-10 flex flex-col items-center gap-1",children:[n.jsxs("div",{className:"flex items-center gap-1 flex-wrap justify-center",children:[L.map(ne=>{const me=T.has(ne.id);return n.jsx("button",{onClick:()=>O(ne.id),className:`text-[10px] px-1.5 py-0.5 rounded border transition-colors ${me?`${ne.color.bg} ${ne.color.border} ${ne.color.text}`:"bg-surface-elevated/50 border-border-default/50 text-fg-tertiary"}`,children:v(`work:dag.filter.${ne.id}`)},ne.id)}),Y>0&&n.jsx("button",{onClick:()=>V(ne=>!ne),className:`text-[10px] px-1.5 py-0.5 rounded border transition-colors ${D?"bg-surface-overlay/60 border-gray-500/50 text-fg-secondary":"bg-surface-elevated/50 border-border-default/50 text-fg-tertiary"}`,children:v("work:dag.archivedToggle",{count:Y})}),!it&&n.jsx("button",{onClick:()=>{E(new Set(Sf)),V(!1)},className:"text-[10px] text-fg-tertiary hover:text-fg-secondary px-1",children:v("work:dag.reset")})]}),n.jsxs("div",{className:"text-[10px] text-fg-tertiary select-none flex items-center gap-2",children:[R?n.jsx("button",{onClick:q,className:"text-brand-500 hover:text-brand-400 transition-colors",children:v("work:dag.backToOverview")}):n.jsx("span",{children:v("work:dag.expandHint")}),n.jsx("span",{className:"text-fg-tertiary/50",children:"·"}),n.jsx("span",{children:v("work:dag.dragHint")})]})]}),C&&n.jsx("div",{className:`absolute bottom-4 left-1/2 -translate-x-1/2 px-4 py-2 rounded-lg text-xs font-medium shadow-xl border backdrop-blur-sm transition-opacity ${C.type==="success"?"bg-green-500/15 border-green-500/30 text-green-600":"bg-red-500/15 border-red-500/30 text-red-600"}`,children:C.msg}),N&&n.jsx("div",{className:"absolute inset-0 bg-black/40 flex items-center justify-center z-50 backdrop-blur-[2px]",onClick:()=>S(null),children:n.jsxs("div",{className:"bg-surface-secondary border border-border-default rounded-xl p-5 shadow-2xl max-w-sm",onClick:ne=>ne.stopPropagation(),children:[n.jsx("h4",{className:"text-sm font-semibold text-fg-primary mb-2",children:v("work:dag.removeDependencyTitle")}),n.jsx("p",{className:"text-xs text-fg-secondary mb-4 leading-relaxed",children:v("work:dag.removeDependencyBody",{target:ht?.title??N.target.slice(-8),source:Lt?.title??N.source.slice(-8)})}),n.jsxs("div",{className:"flex justify-end gap-2",children:[n.jsx("button",{onClick:()=>S(null),className:"px-3 py-1.5 text-xs text-fg-secondary hover:text-fg-primary bg-surface-elevated rounded-lg border border-border-default hover:border-gray-600 transition-colors",children:v("common:cancel")}),n.jsx("button",{onClick:mt,className:"px-3 py-1.5 text-xs text-red-500 bg-red-600/20 hover:bg-red-600/30 rounded-lg border border-red-500/40 hover:border-red-500/60 transition-colors",children:v("common:remove")})]})]})})]})}function Lre({orgId:e,onCreated:t,onClose:r}){const{t:s}=pt(["work","common"]),[a,i]=g.useState(""),[l,d]=g.useState(""),[u,m]=g.useState(""),[h,p]=g.useState("main"),[y,x]=g.useState([]),[v,j]=g.useState([]),[C,w]=g.useState(!1),[N,S]=g.useState(""),[T,E]=g.useState(!1),R=Rs();g.useEffect(()=>{ie.teams.list().then(B=>j(B.teams)).catch(()=>{})},[]);const I=g.useCallback(async B=>{if(B?.preventDefault(),E(!0),!(!a.trim()||C)){w(!0),S("");try{const D=u.trim()?[{url:u.trim(),defaultBranch:h.trim()||"main"}]:[],V=await ie.projects.create({name:a.trim(),description:l.trim()||void 0,repositories:D.length>0?D:void 0,teamIds:y.length>0?y:void 0,orgId:e??"default"});t(V.project)}catch(D){S(D instanceof Error?D.message:s("project.failedToCreate"))}w(!1)}},[a,l,u,h,y,e,C,t,s]),z=T&&!a.trim();return lc.createPortal(n.jsx("div",{className:"fixed inset-0 bg-black/60 flex items-center justify-center z-50 p-3",onClick:r,children:n.jsxs("form",{className:`bg-surface-secondary border border-border-default rounded-xl p-6 shadow-2xl max-h-[90dvh] overflow-y-auto ${R?"w-full":"w-[520px]"}`,onClick:B=>B.stopPropagation(),onSubmit:I,children:[n.jsx("h3",{className:"text-base font-semibold mb-5",children:s("project.newProject")}),n.jsxs("div",{className:"space-y-4",children:[n.jsxs("div",{children:[n.jsx("label",{className:"block text-xs text-fg-secondary mb-1.5 font-medium",children:s("project.projectName")}),n.jsx("input",{value:a,onChange:B=>{i(B.target.value),S("")},onBlur:()=>E(!0),placeholder:s("project.projectNamePlaceholder"),className:`input ${z?"!border-red-500 focus:!ring-red-500/25":""}`,autoFocus:!R}),z&&n.jsx("p",{className:"text-[11px] text-red-400 mt-1",children:s("project.projectNameRequired")})]}),n.jsxs("div",{children:[n.jsx("label",{className:"block text-xs text-fg-secondary mb-1.5 font-medium",children:s("project.description")}),n.jsx("textarea",{value:l,onChange:B=>d(B.target.value),placeholder:s("project.descriptionPlaceholder"),className:"input",rows:3})]}),v.length>0&&n.jsxs("div",{children:[n.jsx("label",{className:"block text-xs text-fg-secondary mb-1.5 font-medium",children:s("project.assignTeams")}),n.jsx("div",{className:"space-y-1 max-h-32 overflow-y-auto",children:v.map(B=>{const D=y.includes(B.id);return n.jsxs("label",{className:"flex items-center gap-2 text-xs text-fg-secondary cursor-pointer hover:text-fg-primary py-0.5",children:[n.jsx("input",{type:"checkbox",checked:D,onChange:()=>x(V=>D?V.filter(Y=>Y!==B.id):[...V,B.id]),className:"accent-brand-500"}),n.jsx("span",{className:"truncate",children:B.name})]},B.id)})})]}),n.jsxs("div",{className:"grid grid-cols-[1fr_auto] gap-3",children:[n.jsxs("div",{children:[n.jsx("label",{className:"block text-xs text-fg-secondary mb-1.5 font-medium",children:s("project.repositoryUrl")}),n.jsx("input",{value:u,onChange:B=>m(B.target.value),placeholder:s("project.repositoryPlaceholder"),className:"input"})]}),u.trim()&&n.jsxs("div",{children:[n.jsx("label",{className:"block text-xs text-fg-secondary mb-1.5 font-medium",children:s("project.branch")}),n.jsx("input",{value:h,onChange:B=>p(B.target.value),placeholder:s("project.branchPlaceholder"),className:"input !w-24"})]})]}),N&&n.jsx("div",{className:"text-xs text-red-400 bg-red-500/10 rounded-lg px-3 py-2",children:N}),n.jsxs("div",{className:"flex justify-end gap-3 pt-2",children:[n.jsx("button",{type:"button",onClick:r,className:"px-4 py-2 text-sm border border-border-default rounded-lg hover:bg-surface-elevated text-fg-secondary",children:s("common:cancel")}),n.jsx("button",{type:"submit",disabled:!a.trim()||C,className:"px-4 py-2 text-sm bg-brand-600 hover:bg-brand-500 disabled:opacity-40 rounded-lg text-white",children:s(C?"common:creating":"project.createProject")})]})]})]})}),document.body)}function Z8(e,t){const[r,s]=g.useState(null);return g.useEffect(()=>{if(!t||!e.current){s(null);return}const a=()=>{const i=e.current?.getBoundingClientRect();if(!i)return;const l=240,d=window.innerHeight-i.bottom-8,u=i.top-8,m=d<l&&u>d;s(m?{top:i.top-4,left:i.left,width:i.width,flipUp:!0}:{top:i.bottom+4,left:i.left,width:i.width,flipUp:!1})};return a(),window.addEventListener("scroll",a,!0),window.addEventListener("resize",a),()=>{window.removeEventListener("scroll",a,!0),window.removeEventListener("resize",a)}},[t,e]),r}function Lu({options:e,value:t,onChange:r,placeholder:s,noMatchesText:a,className:i}){const[l,d]=g.useState(!1),[u,m]=g.useState(""),h=g.useRef(null),p=g.useRef(null),y=g.useRef(null),x=g.useRef(null),v=Z8(p,l);g.useEffect(()=>{const w=N=>{h.current&&!h.current.contains(N.target)&&x.current&&!x.current.contains(N.target)&&d(!1)};return document.addEventListener("mousedown",w),()=>document.removeEventListener("mousedown",w)},[]);const j=e.find(w=>w.value===t)?.label??"",C=u?e.filter(w=>w.label.toLowerCase().includes(u.toLowerCase())):e;return n.jsxs("div",{ref:h,className:i??"",children:[n.jsxs("div",{ref:p,onClick:()=>{d(!l),m(""),setTimeout(()=>y.current?.focus(),0)},className:"w-full px-3 py-2 bg-surface-elevated border border-border-default rounded-lg text-sm focus-within:border-brand-500 outline-none flex items-center cursor-pointer",children:[l?n.jsx("input",{ref:y,value:u,onChange:w=>m(w.target.value),onClick:w=>w.stopPropagation(),className:"w-full bg-transparent outline-none text-fg-primary text-sm",placeholder:j||s,autoFocus:!0}):n.jsx("span",{className:j?"text-fg-primary":"text-fg-tertiary",children:j||s}),n.jsx("svg",{className:"w-4 h-4 ml-auto text-fg-tertiary shrink-0",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:n.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})})]}),l&&v&&n.jsx("div",{ref:x,className:"fixed z-[100] max-h-60 overflow-y-auto bg-surface-elevated border border-border-default rounded-lg shadow-lg",style:v.flipUp?{bottom:window.innerHeight-v.top,left:v.left,width:v.width}:{top:v.top,left:v.left,width:v.width},children:C.length===0?n.jsx("div",{className:"px-3 py-2 text-sm text-fg-tertiary",children:a??"No matches"}):C.map(w=>n.jsx("div",{onClick:()=>{r(w.value),d(!1),m("")},className:`px-3 py-2 text-sm cursor-pointer hover:bg-brand-500/10 ${w.value===t?"bg-brand-500/10 text-brand-500 font-medium":"text-fg-primary"}`,children:w.label},w.value))})]})}function Pre({options:e,selected:t,onAdd:r,placeholder:s,noMatchesText:a,className:i}){const[l,d]=g.useState(!1),[u,m]=g.useState(""),h=g.useRef(null),p=g.useRef(null),y=g.useRef(null),x=g.useRef(null),v=Z8(p,l);g.useEffect(()=>{const w=N=>{h.current&&!h.current.contains(N.target)&&x.current&&!x.current.contains(N.target)&&d(!1)};return document.addEventListener("mousedown",w),()=>document.removeEventListener("mousedown",w)},[]);const j=e.filter(w=>!t.includes(w.value)),C=u?j.filter(w=>w.label.toLowerCase().includes(u.toLowerCase())):j;return n.jsxs("div",{ref:h,className:i??"",children:[n.jsxs("div",{ref:p,onClick:()=>{d(!l),m(""),setTimeout(()=>y.current?.focus(),0)},className:"w-full px-3 py-2 bg-surface-elevated border border-border-default rounded-lg text-sm focus-within:border-brand-500 outline-none flex items-center cursor-pointer",children:[l?n.jsx("input",{ref:y,value:u,onChange:w=>m(w.target.value),onClick:w=>w.stopPropagation(),className:"w-full bg-transparent outline-none text-fg-primary text-sm",placeholder:s,autoFocus:!0}):n.jsx("span",{className:"text-fg-tertiary",children:s}),n.jsx("svg",{className:"w-4 h-4 ml-auto text-fg-tertiary shrink-0",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:n.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})})]}),l&&v&&n.jsx("div",{ref:x,className:"fixed z-[100] max-h-60 overflow-y-auto bg-surface-elevated border border-border-default rounded-lg shadow-lg",style:v.flipUp?{bottom:window.innerHeight-v.top,left:v.left,width:v.width}:{top:v.top,left:v.left,width:v.width},children:C.length===0?n.jsx("div",{className:"px-3 py-2 text-sm text-fg-tertiary",children:a??"No matches"}):C.map(w=>n.jsx("div",{onClick:()=>{r(w.value),m("")},className:"px-3 py-2 text-sm cursor-pointer hover:bg-brand-500/10 text-fg-primary",children:w.label},w.value))})]})}function Rd(e,t,r,s="Admin"){if(!e)return null;const a=t.find(l=>l.id===e);if(a)return a.name;const i=r.find(l=>l.id===e);return i?i.name:e==="anonymous"?s:null}function S3({value:e,onSave:t,className:r,placeholder:s}){const{t:a}=pt(["work","common"]),[i,l]=g.useState(!1),[d,u]=g.useState(e),m=g.useRef(null);g.useEffect(()=>{u(e)},[e]),g.useEffect(()=>{i&&m.current?.focus()},[i]);const h=async()=>{l(!1);const p=d.trim();if(p&&p!==e)try{await t(p)}catch{u(e)}else u(e)};return i?n.jsx("input",{ref:m,value:d,onChange:p=>u(p.target.value),onBlur:()=>{h()},onKeyDown:p=>{p.key==="Enter"&&h(),p.key==="Escape"&&(u(e),l(!1))},className:`bg-transparent border-b border-brand-500/50 outline-none ${r??""}`,placeholder:s}):n.jsx("span",{onClick:()=>l(!0),className:`cursor-pointer hover:border-b hover:border-gray-600 transition-colors ${r??""}`,title:a("work:task.clickToEdit"),children:e||n.jsx("span",{className:"text-fg-tertiary italic",children:s??a("work:task.clickToEdit")})})}function Ore({value:e,onSave:t,className:r,placeholder:s}){const{t:a}=pt(["work","common"]),[i,l]=g.useState(!1),[d,u]=g.useState(e),m=g.useRef(null);g.useEffect(()=>{u(e)},[e]),g.useEffect(()=>{i&&m.current&&(m.current.focus(),m.current.style.height="auto",m.current.style.height=m.current.scrollHeight+"px")},[i]);const h=async()=>{l(!1);const p=d.trim();if(p!==e)try{await t(p)}catch{u(e)}else u(e)};return i?n.jsx("textarea",{ref:m,value:d,onChange:p=>{u(p.target.value),p.target.style.height="auto",p.target.style.height=p.target.scrollHeight+"px"},onBlur:()=>{h()},onKeyDown:p=>{p.key==="Escape"&&(u(e),l(!1))},className:`bg-transparent border border-brand-500/30 rounded-lg p-2 outline-none resize-none w-full ${r??""}`,placeholder:s,rows:2}):n.jsx("p",{onClick:()=>l(!0),className:`cursor-pointer hover:bg-surface-elevated/50 rounded-lg transition-colors px-2 py-1 -mx-2 -my-1 ${r??""}`,title:a("work:task.clickToEdit"),children:e||n.jsx("span",{className:"text-fg-tertiary italic",children:s??a("work:task.addDescription")})})}const _re=/^\[([^\]]+?)(?:\s+by\s+([^\]]+))?\]\s*([\s\S]*)$/;function J8(e){const t=e.match(_re);return t?{timestamp:t[1].trim(),author:t[2]?.trim()??"System",content:t[3].trim()}:{timestamp:"",author:"",content:e}}function zre(e,t){if(!e)return"";const r=e.match(/^(\d{4})[/-](\d{2})[/-](\d{2})\s+(\d{2}):(\d{2})(?::(\d{2}))?/);if(!r)return e;const s=new Date,a=+r[1],i=+r[2]-1,l=+r[3],d=+r[4],u=+r[5],m=new Date(a,i,l,d,u),h=s.getTime()-m.getTime();return h<6e4?t("work:relative.justNow"):h<36e5?t("work:relative.minutesAgo",{count:Math.floor(h/6e4)}):h<864e5?t("work:relative.hoursAgo",{count:Math.floor(h/36e5)}):h<6048e5?t("work:relative.daysAgo",{count:Math.floor(h/864e5)}):`${a}-${String(i+1).padStart(2,"0")}-${String(l).padStart(2,"0")}`}const C3=[{bg:"bg-brand-600/30",text:"text-brand-500",border:"border-brand-500/30"},{bg:"bg-blue-600/30",text:"text-blue-400",border:"border-blue-500/30"},{bg:"bg-green-600/30",text:"text-green-400",border:"border-green-500/30"},{bg:"bg-amber-600/30",text:"text-amber-400",border:"border-amber-500/30"},{bg:"bg-purple-600/30",text:"text-purple-400",border:"border-purple-500/30"},{bg:"bg-pink-600/30",text:"text-pink-400",border:"border-pink-500/30"}];function $re(e){let t=0;for(let r=0;r<e.length;r++)t=(t<<5)-t+e.charCodeAt(r)|0;return C3[Math.abs(t)%C3.length]}function Bre({note:e,compact:t}){const{t:r}=pt(["work","common"]),s=J8(e),a=r("work:task.systemAuthor"),i=$re(s.author||a),l=s.author?s.author.split(/[\s_-]+/).map(m=>m[0]).join("").slice(0,2).toUpperCase():"SY",d=zre(s.timestamp,r),u=!s.author||s.author==="System";return t?n.jsxs("div",{className:"flex gap-2.5 group",children:[n.jsx("div",{className:`w-6 h-6 rounded-full ${i.bg} flex items-center justify-center text-[9px] font-bold ${i.text} shrink-0 mt-0.5`,children:l}),n.jsxs("div",{className:"flex-1 min-w-0",children:[n.jsxs("div",{className:"flex items-baseline gap-1.5 mb-0.5",children:[n.jsx("span",{className:`text-[11px] font-medium ${u?"text-fg-tertiary":i.text}`,children:u?a:s.author}),d&&n.jsx("span",{className:"text-[10px] text-fg-tertiary",children:d})]}),n.jsx("div",{className:"text-xs text-fg-secondary",children:n.jsx(Wr,{content:s.content,className:"text-xs text-fg-secondary"})})]})]}):n.jsxs("div",{className:"flex gap-3 group",children:[n.jsxs("div",{className:"flex flex-col items-center shrink-0",children:[n.jsx("div",{className:`w-7 h-7 rounded-full ${i.bg} flex items-center justify-center text-[10px] font-bold ${i.text}`,children:l}),n.jsx("div",{className:"w-px flex-1 bg-border-default/60 mt-1.5"})]}),n.jsx("div",{className:"flex-1 min-w-0 pb-4",children:n.jsxs("div",{className:`border ${i.border} rounded-lg overflow-hidden`,children:[n.jsxs("div",{className:`flex items-center gap-2 px-3 py-1.5 ${i.bg} border-b ${i.border}`,children:[n.jsx("span",{className:`text-[11px] font-medium ${u?"text-fg-secondary":i.text}`,children:u?a:s.author}),d&&n.jsx("span",{className:"text-[10px] text-fg-tertiary",children:d})]}),n.jsx("div",{className:"px-3 py-2.5",children:n.jsx(Wr,{content:s.content,className:"text-xs text-fg-secondary"})})]})})]})}const Hre=new Set(["rejected","cancelled","archived"]),Ry=[{id:"failed",statuses:["failed"],accent:"border-t-red-500",dropStatus:"failed"},{id:"todo",statuses:["pending"],accent:"border-t-amber-500",dropStatus:"pending"},{id:"in_progress",statuses:["in_progress","blocked"],accent:"border-t-brand-500",dropStatus:"in_progress"},{id:"review",statuses:["review"],accent:"border-t-purple-500",dropStatus:"review"},{id:"done",statuses:["completed"],accent:"border-t-green-500",dropStatus:"completed"},{id:"closed",statuses:["rejected","cancelled","archived"],accent:"border-t-gray-500",dropStatus:"cancelled"}],T3={pending:"bg-amber-500/15 text-amber-600",blocked:"bg-amber-500/15 text-amber-600",failed:"bg-red-500/15 text-red-500",rejected:"bg-red-500/15 text-red-500"},A3={pending:"bg-amber-500/15 text-amber-600",in_progress:"bg-blue-500/15 text-blue-500",blocked:"bg-orange-500/15 text-orange-500",review:"bg-purple-500/15 text-purple-500",revision:"bg-amber-500/15 text-amber-600",completed:"bg-green-500/15 text-green-600",failed:"bg-red-500/15 text-red-500",rejected:"bg-red-500/15 text-red-500",cancelled:"bg-gray-500/15 text-fg-tertiary",archived:"bg-gray-500/15 text-fg-tertiary"},E3={low:"bg-gray-500/15 text-fg-tertiary",medium:"bg-blue-500/15 text-blue-500",high:"bg-amber-500/15 text-amber-600",urgent:"bg-red-500/15 text-red-500"},M3={pending:"bg-amber-500/15 text-amber-600",in_progress:"bg-brand-500/15 text-brand-500",completed:"bg-green-500/15 text-green-600",rejected:"bg-red-500/15 text-red-500",cancelled:"bg-gray-600/15 text-fg-tertiary",archived:"bg-gray-600/10 text-fg-tertiary/60"};function eC(e){return Object.keys(A3).reduce((t,r)=>(t[r]={label:e(`work:status.task.${r}`),cls:A3[r]},t),{})}function tC(e){return Object.keys(T3).reduce((t,r)=>(t[r]={label:e(`work:status.sub.${r}`),cls:T3[r]},t),{})}function Fre(e){return Object.keys(E3).reduce((t,r)=>(t[r]={label:e(`work:priority.${r}`),cls:E3[r]},t),{})}function Iy(e){return Object.keys(M3).reduce((t,r)=>(t[r]={label:e(`work:status.requirement.${r}`),cls:M3[r]},t),{})}const D3=["low","medium","high","urgent"],R3=["pending","in_progress","blocked","review","completed","failed","rejected","cancelled"],I3=["pending","in_progress","completed","rejected","cancelled"],L3={pending:new Set(["in_progress","blocked","rejected","cancelled"]),in_progress:new Set(["review","blocked","failed","cancelled"]),blocked:new Set(["in_progress","cancelled"]),review:new Set(["completed","in_progress","cancelled"]),completed:new Set(["archived","in_progress"]),failed:new Set(["in_progress","archived"]),rejected:new Set(["archived"]),cancelled:new Set(["archived"]),archived:new Set([])},y1={pending:new Set(["in_progress","rejected","cancelled"]),in_progress:new Set(["completed","cancelled"]),completed:new Set([]),rejected:new Set([]),cancelled:new Set([])},j0={idle:"bg-green-400",working:"bg-blue-400",error:"bg-red-400",paused:"bg-amber-400",offline:"bg-gray-600",pending:"bg-amber-400",in_progress:"bg-brand-400",blocked:"bg-amber-400",review:"bg-brand-400",completed:"bg-green-400",failed:"bg-red-400",rejected:"bg-red-400",cancelled:"bg-gray-600",archived:"bg-surface-overlay"},P3={idle:"text-green-500",working:"text-blue-500",error:"text-red-500",paused:"text-amber-500",offline:"text-fg-muted"};function qre({agent:e,anchorRect:t,onClose:r}){const{t:s}=pt(["work","common"]),a=g.useRef(null);g.useEffect(()=>{const u=m=>{a.current&&!a.current.contains(m.target)&&r()};return document.addEventListener("mousedown",u),()=>document.removeEventListener("mousedown",u)},[r]);const i=e.status!=="error"&&!!e.lastError&&!!e.lastErrorAt&&Date.now()-new Date(e.lastErrorAt).getTime()<1800*1e3,l=e.status==="idle"&&!i?"bg-green-400":e.status==="working"&&!i?"bg-blue-400 animate-pulse":e.status==="error"?"bg-red-400":i?"bg-amber-400":"bg-gray-500",d=e.status==="idle"?s("work:task.online"):e.status==="working"?s("work:task.working"):e.status==="error"?s("work:task.error"):e.status==="paused"?s("work:task.paused"):s("work:task.offline");return n.jsxs("div",{ref:a,className:"fixed z-50 w-56 bg-surface-secondary border border-border-default rounded-xl shadow-2xl p-3 space-y-2",style:{top:t.top+4,left:t.left},children:[n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx("div",{className:"w-7 h-7 rounded-full bg-brand-500/15 flex items-center justify-center text-[10px] font-bold text-brand-600 shrink-0",children:e.name.slice(0,2).toUpperCase()}),n.jsxs("div",{className:"flex-1 min-w-0",children:[n.jsx("div",{className:"text-xs text-fg-primary font-medium truncate",children:e.name}),n.jsx("div",{className:"text-[10px] text-fg-tertiary",children:e.role}),n.jsxs("div",{className:"flex items-center gap-1.5 mt-0.5",children:[n.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${l}`}),n.jsx("span",{className:"text-[10px] text-fg-secondary",children:d})]})]})]}),n.jsx("button",{onClick:()=>{r(),bt.navigate(De.TEAM,{selectAgent:e.id})},className:"w-full text-center text-[10px] text-brand-500 hover:text-brand-500 border border-border-default hover:border-gray-600 rounded-lg py-1 transition-colors",children:s("work:task.viewProfile")})]})}function Ju({comment:e,agents:t,onReply:r}){const{t:s}=pt(["work","common"]),a=e.authorType==="agent"||e.authorType==="system",i=new Date(e.createdAt),l=i.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}),d=i.toLocaleDateString([],{month:"short",day:"numeric"}),[u,m]=g.useState(null),[h,p]=g.useState(!1),[y,x]=g.useState([]),[v,j]=g.useState(!1),C=g.useCallback((E,R)=>{const I=t.find(z=>z.name.toLowerCase()===E.toLowerCase());if(I){const z=R.target.getBoundingClientRect();m({agent:I,top:z.bottom,left:z.left})}},[t]),w=g.useMemo(()=>t.map(E=>E.name),[t]),N=g.useCallback(E=>{const R=t.find(I=>I.name.toLowerCase()===e.authorName.toLowerCase());if(R){const I=E.currentTarget.getBoundingClientRect();m({agent:R,top:I.bottom,left:I.left})}},[t,e.authorName]),S=g.useCallback(async()=>{if(h){p(!1);return}const E=e.activityId;if(E&&(p(!0),!(y.length>0))){j(!0);try{const{logs:R}=await ie.agents.getActivityLogs(e.authorId,E),I=R.map(z=>g6(z,E,e.authorId)).filter(z=>z!==null).map(z=>({...z,ts:new Date(z.createdAt).getTime()}));x(I)}catch{}j(!1)}},[h,y.length,e]),T=g.useMemo(()=>d0(y.map(u0).filter(E=>E!==null)),[y]);return n.jsxs("div",{className:"flex gap-2.5 group py-1",id:`comment-${e.id}`,children:[n.jsx("div",{onClick:N,className:`flex-shrink-0 w-6 h-6 rounded-full flex items-center justify-center text-[10px] mt-0.5 cursor-pointer transition-all hover:ring-1 hover:ring-brand-500/40 ${a?"bg-indigo-500/20 text-indigo-400":"bg-blue-500/20 text-blue-400"}`,children:e.authorName.slice(0,2).toUpperCase()}),n.jsxs("div",{className:"flex-1 min-w-0",children:[n.jsxs("div",{className:"flex items-baseline gap-1.5 mb-0.5",children:[n.jsx("span",{className:`text-[11px] font-medium cursor-pointer hover:underline ${a?"text-indigo-400":"text-blue-400"}`,onClick:N,children:e.authorName}),n.jsxs("span",{className:"text-fg-tertiary text-[10px]",children:[d," ",l]}),r&&n.jsx("button",{onClick:()=>r(e),className:"text-fg-tertiary hover:text-fg-secondary text-[10px] opacity-0 group-hover:opacity-100 transition-opacity ml-1",children:s("work:task.reply")}),e.activityId&&a&&n.jsx("button",{onClick:S,className:"text-fg-tertiary hover:text-brand-400 text-[10px] opacity-0 group-hover:opacity-100 transition-opacity ml-1",children:s(h?"work:task.hideLog":"work:task.viewLog")})]}),e.replyTo&&e.replyToAuthor&&n.jsxs("button",{onClick:()=>{const E=document.getElementById(`comment-${e.replyTo}`);E&&(E.scrollIntoView({behavior:"smooth",block:"center"}),E.classList.add("bg-brand-500/10"),setTimeout(()=>E.classList.remove("bg-brand-500/10"),1500))},className:"flex items-center gap-1.5 mb-1 pl-2 py-0.5 border-l-2 border-brand-500/40 text-[10px] text-fg-tertiary hover:text-fg-secondary transition-colors cursor-pointer",children:[n.jsx("span",{className:"font-medium text-brand-500/70",children:e.replyToAuthor}),n.jsx("span",{className:"truncate max-w-[200px]",children:e.replyToContent??"..."})]}),n.jsx(Wr,{content:e.content,className:"text-xs text-fg-primary",onMentionClick:C,knownNames:w}),e.attachments?.map((E,R)=>E.type==="image"?n.jsx("img",{src:E.url,alt:E.name,className:"mt-1 max-w-[200px] rounded"},R):null),h&&n.jsx("div",{className:"mt-2 border border-border-subtle rounded-lg overflow-hidden bg-surface-secondary/30",children:v?n.jsx("div",{className:"p-3 text-xs text-fg-tertiary",children:s("work:task.loadingExecutionLog")}):T.length===0?n.jsx("div",{className:"p-3 text-xs text-fg-tertiary",children:s("work:task.noExecutionLogAvailable")}):n.jsx(Kh,{entries:y,isActive:!1,onCollapse:()=>p(!1),embedded:!0})})]}),u&&n.jsx(qre,{agent:u.agent,anchorRect:{top:u.top,left:u.left},onClose:()=>m(null)})]})}function Ure({task:e,agents:t,users:r,authUser:s}){const{t:a}=pt(["work","common"]),[i,l]=g.useState([]),[d,u]=g.useState([]),m=g.useRef(null),[h,p]=g.useState(new Map);g.useEffect(()=>{u([]),p(new Map),m.current&&(clearTimeout(m.current),m.current=null),ie.tasks.getComments(e.id).then(w=>l(w.comments)).catch(()=>{})},[e.id]),g.useEffect(()=>pn.on("task:comment",N=>{if(N.payload?.taskId===e.id&&N.payload.comment){const S=N.payload.comment;l(T=>T.some(E=>E.id===S.id)?T:[...T,S]),(S.authorType==="agent"||S.authorId?.startsWith("agt_"))&&(u(T=>{const E=T.filter(R=>R.id!==S.authorId);return E.length===0&&m.current&&(clearTimeout(m.current),m.current=null),E}),p(T=>{const E=new Map(T);return E.delete(S.authorId),E}))}}),[e.id]),g.useEffect(()=>{if(d.length===0)return;const w=new Set(d.map(S=>S.id));return pn.on("agent:activity_log",S=>{const T=S.payload;if(!T)return;const E=T.agentId;if(!w.has(E))return;const R=T.type;if(R==="tool_start"||R==="tool_end"){const z={tool:T.content??T.metadata?.tool??"",phase:R==="tool_start"?"start":"end",success:R==="tool_end"?T.metadata?.success!==!1:void 0,ts:Date.now()};p(B=>{const D=new Map(B),V=[...D.get(E)??[],z];return D.set(E,V),D})}})},[d]);const y=g.useMemo(()=>{const w=[];for(const N of e.notes??[]){const S=J8(N);let T;if(S.timestamp){const E=S.timestamp.match(/^(\d{4})[/-](\d{2})[/-](\d{2})\s+(\d{2}):(\d{2})(?::(\d{2}))?/);T=E?new Date(+E[1],+E[2]-1,+E[3],+E[4],+E[5],+(E[6]??0)):new Date(0)}else T=new Date(0);w.push({type:"note",note:N,ts:T})}for(const N of i)w.push({type:"comment",comment:N,ts:new Date(N.createdAt)});return w.sort((N,S)=>N.ts.getTime()-S.ts.getTime()),w},[e.notes,i]),[x,v]=g.useState(null),j=async(w,N,S,T)=>{let E;S.length>0&&(E=(await ie.uploads.upload(S.map(D=>({dataUrl:D.dataUrl,name:D.name})),"comments")).files.map(D=>({type:"image",url:D.url,name:D.name}))),await ie.tasks.addComment(e.id,w,s?.name,E,s?.id,N.length>0?N:void 0,T);const R=[],I=new Set,z=B=>{if(I.has(B)||B===s?.id)return;I.add(B);const D=t.find(V=>V.id===B);D&&R.push({id:D.id,name:D.name,avatarUrl:D.avatarUrl})};for(const B of N){const D=t.find(V=>V.name.toLowerCase()===B.toLowerCase());D&&z(D.id)}e.assignedAgentId&&z(e.assignedAgentId),e.createdBy?.startsWith("agt_")&&e.status!=="in_progress"&&z(e.createdBy),R.length>0&&(m.current&&clearTimeout(m.current),u(R),m.current=setTimeout(()=>u([]),12e4))},C=g.useCallback(w=>{v({id:w.id,authorName:w.authorName,content:w.content.slice(0,100)})},[]);return n.jsxs("div",{className:"mt-5",children:[n.jsx("p",{className:"text-xs font-semibold text-fg-tertiary uppercase tracking-wider mb-3",children:a("work:task.activityCommentsHeading")}),n.jsxs("div",{className:"space-y-0.5 mb-3",children:[y.length===0&&n.jsx("div",{className:"text-xs text-fg-tertiary text-center py-6",children:a("work:task.noActivityYet")}),y.map((w,N)=>w.type==="note"?n.jsx(Bre,{note:w.note,compact:!0},`n-${N}`):n.jsx(Ju,{comment:w.comment,agents:t,onReply:C},`c-${w.comment.id}`)),d.length>0&&n.jsx("div",{className:"flex flex-col gap-1.5 pt-1",children:d.map(w=>{const N=h.get(w.id)??[];return n.jsxs("div",{className:"px-2 py-1.5 rounded-lg cursor-pointer hover:bg-surface-elevated/60 transition-colors",onClick:()=>bt.navigate(De.TEAM,{agentId:w.id,profileTab:"mind"}),children:[n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsxs("div",{className:"relative shrink-0",children:[n.jsx(Nr,{name:w.name,avatarUrl:w.avatarUrl,size:22,bgClass:"bg-brand-500/15 text-brand-600"}),n.jsx("span",{className:"absolute -bottom-0.5 -right-0.5 w-2 h-2 rounded-full bg-blue-500 animate-pulse ring-2 ring-surface-primary"})]}),n.jsx("span",{className:"text-xs font-medium text-fg-secondary",children:w.name}),N.length===0&&n.jsxs("span",{className:"flex items-center gap-0.5",children:[n.jsx("span",{className:"w-1 h-1 rounded-full bg-blue-400 animate-bounce"}),n.jsx("span",{className:"w-1 h-1 rounded-full bg-blue-400 animate-bounce",style:{animationDelay:"0.15s"}}),n.jsx("span",{className:"w-1 h-1 rounded-full bg-blue-400 animate-bounce",style:{animationDelay:"0.3s"}})]}),n.jsx("span",{className:"text-[10px] text-fg-tertiary",children:a("work:task.agentProcessing")}),n.jsx("span",{className:"ml-auto text-[10px] text-fg-tertiary",children:"→"})]}),N.length>0&&n.jsx("div",{className:"ml-8 mt-1",children:n.jsx(Wh,{activities:N,isActive:!0})})]},w.id)})})]}),n.jsx($S,{agents:t,humans:r,onSubmit:j,replyTo:x,onCancelReply:()=>v(null),placeholder:a("work:task.commentPlaceholder")})]})}function Vre({task:e,isRunning:t,authUser:r,agents:s}){const a=e.id,{t:i}=pt(["work","common"]),[l,d]=g.useState([]),[u,m]=g.useState(new Map),[h,p]=g.useState(new Set),[y,x]=g.useState([]),[v,j]=g.useState(""),[C,w]=g.useState(t),[N,S]=g.useState(!0),[T,E]=g.useState(new Set),[R,I]=g.useState(""),[z,B]=g.useState(!1),[D,V]=g.useState([]),Y=g.useRef(null),[F,L]=g.useState(new Map),[O,M]=g.useState([]),[$,W]=g.useState([]),[U,H]=g.useState(!1),q=g.useRef(null),Z=g.useRef(null);g.useEffect(()=>{w(t)},[t]),g.useEffect(()=>{V([]),L(new Map),Y.current&&(clearTimeout(Y.current),Y.current=null)},[a]),g.useEffect(()=>{S(!0),Promise.all([ie.tasks.getLogsSummary(a).catch(()=>({rounds:[]})),ie.tasks.getComments(a).catch(()=>({comments:[]}))]).then(([Ne,he])=>{const _e=Ne.rounds;if(d(_e),x(he.comments),_e.length===0){S(!1);return}const Ee=_e[_e.length-1].round;E(new Set([Ee])),ie.tasks.getLogs(a,Ee).catch(()=>({logs:[]})).then(Ye=>{m(new Map([[Ee,Ye.logs]])),S(!1)})})},[a]),g.useEffect(()=>{const Ne=e.assignedAgentId;Ne&&(H(!0),ie.agents.getActivities(Ne,{taskId:a,limit:20}).then(he=>W(he.activities)).catch(()=>W([])).finally(()=>H(!1)))},[a,e.assignedAgentId]);const _=g.useCallback(Ne=>{u.has(Ne)||h.has(Ne)||(p(he=>new Set(he).add(Ne)),ie.tasks.getLogs(a,Ne).catch(()=>({logs:[]})).then(he=>{m(_e=>new Map(_e).set(Ne,he.logs)),p(_e=>{const Ee=new Set(_e);return Ee.delete(Ne),Ee})}))},[a,u,h]),J=g.useCallback(Ne=>{E(he=>{const _e=new Set(he);return _e.has(Ne)?_e.delete(Ne):(_e.add(Ne),u.has(Ne)||_(Ne)),_e})},[u,_]);g.useEffect(()=>{const Ne=pn.on("task:log",Ee=>{const Ye=Ee.payload;if(Ye.taskId!==a)return;const Ze={id:Ye.id,taskId:Ye.taskId,agentId:Ye.agentId,seq:Ye.seq,type:Ye.logType,content:Ye.content,metadata:Ye.metadata,executionRound:Ye.executionRound,createdAt:Ye.createdAt},mt=Ze.executionRound??1;d(it=>it.find(ht=>ht.round===mt)?it:[...it,{round:mt,logCount:0,toolCount:0,firstAt:Ze.createdAt,lastAt:Ze.createdAt,status:"running"}]),E(it=>it.has(mt)?it:new Set(it).add(mt)),m(it=>{const Lt=it.get(mt)??[];return Ze.id&&Lt.some(ht=>ht.id===Ze.id)?it:new Map(it).set(mt,[...Lt,Ze])}),Ze.type==="text"&&j(""),Ze.type==="status"&&(Ze.content==="started"||Ze.content==="resumed"?w(!0):["completed","failed","cancelled","execution_finished"].includes(Ze.content)&&(w(!1),d(it=>it.map(Lt=>Lt.round===mt?{...Lt,status:Ze.content}:Lt)))),Ze.type==="error"&&w(!1)}),he=pn.on("task:log:delta",Ee=>{const Ye=Ee.payload;Ye.taskId===a&&j(Ze=>Ze+Ye.text)}),_e=pn.on("task:comment",Ee=>{const Ye=Ee.payload;if(Ye.taskId!==a)return;const Ze=Ye.comment;x(mt=>mt.some(it=>it.id===Ze.id)?mt:[...mt,Ze]),(Ze.authorType==="agent"||Ze.authorId?.startsWith("agt_"))&&(V(mt=>{const it=mt.filter(Lt=>Lt.id!==Ze.authorId);return it.length===0&&Y.current&&(clearTimeout(Y.current),Y.current=null),it}),L(mt=>{const it=new Map(mt);return it.delete(Ze.authorId),it}))});return()=>{Ne(),he(),_e()}},[a]),g.useEffect(()=>{if(D.length===0)return;const Ne=new Set(D.map(_e=>_e.id));return pn.on("agent:activity_log",_e=>{const Ee=_e.payload;if(!Ee)return;const Ye=Ee.agentId;if(!Ne.has(Ye))return;const Ze=Ee.type;if(Ze==="tool_start"||Ze==="tool_end"){const it={tool:Ee.content??Ee.metadata?.tool??"",phase:Ze==="tool_start"?"start":"end",success:Ze==="tool_end"?Ee.metadata?.success!==!1:void 0,ts:Date.now()};L(Lt=>{const ht=new Map(Lt),ne=[...ht.get(Ye)??[],it];return ht.set(Ye,ne),ht})}})},[D]);const X=g.useMemo(()=>{const Ne=[];for(const[,he]of u)Ne.push(...he);return Ne.sort((he,_e)=>he.seq-_e.seq),Ne},[u]),ee=g.useMemo(()=>X.map(Ne=>gb(Ne)),[X]),te=l.length>1,G=Ne=>{const he=Ne.target.files;if(he){for(const _e of Array.from(he)){if(!_e.type.startsWith("image/"))continue;const Ee=new FileReader;Ee.onload=()=>{M(Ye=>[...Ye,{type:"image",url:Ee.result,name:_e.name}])},Ee.readAsDataURL(_e)}Ne.target.value=""}},ue=async()=>{if(!(!R.trim()&&O.length===0)){B(!0);try{let Ne;O.length>0&&(Ne=(await ie.uploads.upload(O.map(mt=>({dataUrl:mt.url,name:mt.name})),"comments")).files.map(mt=>({type:"image",url:mt.url,name:mt.name})));const he=await ie.tasks.addComment(a,R,r?.name,Ne,r?.id);he.comment&&x(Ze=>Ze.some(mt=>mt.id===he.comment.id)?Ze:[...Ze,he.comment]),I(""),M([]);const _e=[],Ee=new Set,Ye=Ze=>{if(Ee.has(Ze)||Ze===r?.id)return;Ee.add(Ze);const mt=s.find(it=>it.id===Ze);mt&&_e.push({id:mt.id,name:mt.name,avatarUrl:mt.avatarUrl})};e.assignedAgentId&&Ye(e.assignedAgentId),e.createdBy?.startsWith("agt_")&&e.status!=="in_progress"&&Ye(e.createdBy),_e.length>0&&(Y.current&&clearTimeout(Y.current),V(_e),Y.current=setTimeout(()=>V([]),12e4))}catch{}B(!1)}},Se=n.jsxs("div",{className:"border-t border-border-default px-4 py-3 sticky bottom-0 bg-surface-primary z-10",children:[O.length>0&&n.jsx("div",{className:"flex gap-2 mb-2 flex-wrap",children:O.map((Ne,he)=>n.jsxs("div",{className:"relative group",children:[n.jsx("img",{src:Ne.url,alt:Ne.name,className:"w-16 h-16 object-cover rounded-lg border border-border-default"}),n.jsx("button",{onClick:()=>M(_e=>_e.filter((Ee,Ye)=>Ye!==he)),className:"absolute -top-1 -right-1 w-4 h-4 rounded-full bg-red-600 text-white text-[10px] flex items-center justify-center opacity-0 group-hover:opacity-100",children:"×"})]},he))}),n.jsxs("div",{className:"flex gap-2",children:[n.jsx("input",{type:"text",value:R,onChange:Ne=>I(Ne.target.value),onKeyDown:Ne=>{Ne.key==="Enter"&&!Ne.shiftKey&&(Ne.preventDefault(),ue())},placeholder:i("work:task.commentInstructionPlaceholder"),className:"flex-1 px-3 py-1.5 bg-surface-elevated border border-border-default rounded-lg text-sm focus:border-blue-500 outline-none text-fg-primary placeholder-gray-600"}),n.jsx("input",{type:"file",ref:q,accept:"image/*",multiple:!0,onChange:G,className:"hidden"}),n.jsx("button",{onClick:()=>q.current?.click(),className:"px-2 py-1.5 bg-surface-elevated border border-border-default rounded-lg text-fg-secondary hover:text-fg-primary text-sm",title:i("work:task.attachImage"),children:"📎"}),n.jsx("button",{onClick:()=>{ue()},disabled:z||!R.trim()&&O.length===0,className:"px-3 py-1.5 bg-blue-600 hover:bg-blue-500 rounded-lg text-white text-xs disabled:opacity-50",children:i("common:send")})]})]});if(N)return n.jsx("div",{className:"flex-1 flex items-center justify-center text-xs text-fg-tertiary",children:i("work:task.loadingLogs")});if(l.length===0&&!v){const Ne=e.assignedAgentId?s.find(ht=>ht.id===e.assignedAgentId):void 0,he=$.length>0,_e=Ne&&Ne.currentTaskId&&Ne.currentTaskId!==e.id,Ee=e.status==="pending",Ye=e.status==="in_progress",Ze=!e.assignedAgentId;let mt="📋",it=i("work:task.emptyLogs.default"),Lt=i("work:task.emptyLogs.defaultHint");return Ze?(mt="👤",it=i("work:task.emptyLogs.noAgent"),Lt=i("work:task.emptyLogs.noAgentHint")):Ee?(mt="⏳",it=i("work:task.emptyLogs.pending"),Lt=i("work:task.emptyLogs.pendingHint")):Ye&&_e?(mt="🔄",it=i("work:task.emptyLogs.agentBusy",{agent:Ne?.name??e.assignedAgentId}),Lt=i("work:task.emptyLogs.agentBusyHint")):Ye&&(mt="⏳",it=i("work:task.emptyLogs.starting"),Lt=i("work:task.emptyLogs.startingHint")),n.jsxs("div",{className:"flex flex-col min-h-full",children:[n.jsx("div",{className:"flex-1 overflow-y-auto",children:U?n.jsx("div",{className:"flex items-center justify-center py-8 text-xs text-fg-tertiary",children:i("work:task.loadingLogs")}):he?n.jsxs("div",{className:"px-4 py-4",children:[n.jsxs("div",{className:"text-xs text-fg-secondary mb-3 flex items-center gap-1.5",children:[n.jsx("span",{className:"inline-block w-1.5 h-1.5 rounded-full bg-blue-500"}),i("work:task.relatedSessions",{agent:Ne?.name??i("work:task.agent"),count:$.length})]}),n.jsx("div",{className:"space-y-1.5",children:$.map(ht=>{const ne=!ht.endedAt,me=ht.type==="task"?"🔧":ht.type==="chat"||ht.type==="respond_in_session"?"💬":ht.type==="heartbeat"?"💓":"📋";return n.jsxs("button",{className:"w-full flex items-center gap-2 px-3 py-2 rounded-lg bg-surface-elevated hover:bg-surface-elevated/80 border border-border-default/50 text-left transition-colors group",onClick:()=>bt.navigate(De.TEAM,{agentId:e.assignedAgentId}),children:[n.jsx("span",{className:"text-sm shrink-0",children:me}),n.jsxs("div",{className:"flex-1 min-w-0",children:[n.jsx("div",{className:"text-xs text-fg-primary truncate",children:ht.label}),n.jsxs("div",{className:"text-[10px] text-fg-tertiary",children:[new Date(ht.startedAt).toLocaleString(),ht.endedAt?` — ${ht.totalTools} tools, ${ht.totalTokens.toLocaleString()} tokens`:""]})]}),ne&&n.jsxs("span",{className:"shrink-0 flex items-center gap-1 text-[10px] text-green-500 font-medium",children:[n.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-green-500 animate-pulse"}),i("work:task.sessionLive")]}),!ne&&n.jsx("span",{className:`shrink-0 text-[10px] ${ht.success?"text-fg-tertiary":"text-red-400"}`,children:ht.success?"✓":"✗"}),n.jsx("span",{className:"shrink-0 text-fg-tertiary text-[10px] opacity-0 group-hover:opacity-100 transition-opacity",children:"→"})]},ht.id)})})]}):n.jsx("div",{className:"flex items-center justify-center py-8",children:n.jsxs("div",{className:"text-center text-fg-tertiary",children:[n.jsx("div",{className:"text-2xl mb-2",children:mt}),n.jsxs("div",{className:"text-xs",children:[it,n.jsx("br",{}),n.jsx("span",{className:"text-fg-muted",children:Lt})]})]})})}),Se]})}if(!te){const Ne=ee.map(Ee=>u0(Ee)).filter(Ee=>Ee!==null),he=wk(X,d0(Ne)),_e=[...he.map(Ee=>({kind:"entry",entry:Ee,ts:Ee.timestamp?new Date(Ee.timestamp).getTime():0})),...y.map(Ee=>({kind:"comment",comment:Ee,ts:new Date(Ee.createdAt).getTime()}))];return _e.sort((Ee,Ye)=>Ee.ts-Ye.ts),n.jsxs("div",{className:"flex flex-col min-h-full",children:[n.jsxs("div",{className:"px-4 py-3 flex-1 space-y-0.5",children:[_e.map((Ee,Ye)=>Ee.kind==="comment"?n.jsx(Ju,{comment:Ee.comment,agents:s},`c-${Ee.comment.id}`):n.jsx(oh,{entry:Ee.entry,showTime:!0,isLast:Ye===_e.length-1},`e-${Ye}`)),C&&v&&n.jsx(Yb,{content:v}),C&&!v&&he.length>0&&n.jsx(Gb,{})]}),Se]})}const Ce=(Ne,he)=>{const _e=Ne.firstAt?new Date(Ne.firstAt).getTime():0,Ee=he?.firstAt?new Date(he.firstAt).getTime():1/0;return y.filter(Ye=>{const Ze=new Date(Ye.createdAt).getTime();return Ze>=_e&&Ze<Ee})},Be=l.length>0?y.filter(Ne=>new Date(Ne.createdAt).getTime()<new Date(l[0].firstAt).getTime()):[];return n.jsxs("div",{className:"flex flex-col min-h-full",children:[n.jsx("div",{ref:Z}),n.jsxs("div",{className:"px-4 py-3 flex-1 space-y-2",children:[Be.length>0&&n.jsx("div",{className:"space-y-0.5",children:Be.map(Ne=>n.jsx(Ju,{comment:Ne,agents:s},Ne.id))}),l.map((Ne,he)=>{const _e=T.has(Ne.round),Ee=Ne.round===l[l.length-1].round,Ye=u.get(Ne.round),Ze=h.has(Ne.round),mt=Ce(Ne,l[he+1]),it=Ne.status==="completed"||Ne.status==="execution_finished"?"✅":Ne.status==="failed"?"❌":Ne.status==="cancelled"?"⏹":"🔄",Lt=Ne.lastAt&&Ne.firstAt?Math.max(0,new Date(Ne.lastAt).getTime()-new Date(Ne.firstAt).getTime()):0,ht=Lt>=6e4?`${Math.floor(Lt/6e4)}m ${Math.floor(Lt%6e4/1e3)}s`:Lt>=1e3?`${Math.floor(Lt/1e3)}s`:"";return n.jsxs("div",{className:"border border-border-default/50 rounded-lg overflow-hidden",children:[n.jsxs("button",{onClick:()=>J(Ne.round),className:"w-full flex items-center justify-between px-3 py-2 bg-surface-elevated/30 hover:bg-surface-elevated/50 transition-colors",children:[n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx("span",{className:"text-sm",children:it}),n.jsx("span",{className:"text-xs text-fg-secondary font-medium",children:i("work:task.roundHeader",{n:Ne.round})}),mt.length>0&&n.jsxs("span",{className:"text-[10px] text-blue-400",children:["💬 ",mt.length]}),Ee&&C&&n.jsxs("svg",{className:"w-3 h-3 animate-spin text-brand-500",viewBox:"0 0 24 24",fill:"none",children:[n.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),n.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"})]})]}),n.jsxs("div",{className:"flex items-center gap-3",children:[n.jsx("span",{className:"text-[10px] text-fg-tertiary",children:i("work:task.toolCount",{count:Ne.toolCount})}),ht&&n.jsx("span",{className:"text-[10px] text-fg-tertiary tabular-nums",children:ht}),n.jsx("svg",{className:`w-3 h-3 text-fg-tertiary transition-transform ${_e?"rotate-180":""}`,viewBox:"0 0 20 20",fill:"currentColor",children:n.jsx("path",{fillRule:"evenodd",d:"M5.23 7.21a.75.75 0 011.06.02L10 11.168l3.71-3.938a.75.75 0 111.08 1.04l-4.25 4.5a.75.75 0 01-1.08 0l-4.25-4.5a.75.75 0 01.02-1.06z",clipRule:"evenodd"})})]})]}),_e&&n.jsxs("div",{className:"px-3 py-1.5 space-y-0.5",children:[Ze&&n.jsx("div",{className:"text-xs text-fg-tertiary py-2 text-center",children:i("work:task.loadingRound",{n:Ne.round})}),Ye&&(()=>{const me=Ye.map(fe=>gb(fe)).map(fe=>u0(fe)).filter(fe=>fe!==null),se=[...wk(Ye,d0(me)).map(fe=>({kind:"entry",entry:fe,ts:fe.timestamp?new Date(fe.timestamp).getTime():0})),...mt.map(fe=>({kind:"comment",comment:fe,ts:new Date(fe.createdAt).getTime()}))];return se.sort((fe,He)=>fe.ts-He.ts),se.map((fe,He)=>fe.kind==="comment"?n.jsx(Ju,{comment:fe.comment,agents:s},`c-${fe.comment.id}`):n.jsx(oh,{entry:fe.entry,showTime:!0,isLast:He===se.length-1},`e-${He}`))})(),Ee&&C&&v&&n.jsx(Yb,{content:v}),Ee&&C&&!v&&!Ze&&n.jsx(Gb,{})]})]},Ne.round)}),D.length>0&&n.jsx("div",{className:"flex flex-col gap-1.5 mt-2",children:D.map(Ne=>{const he=F.get(Ne.id)??[];return n.jsxs("div",{className:"px-3 py-2 rounded-lg cursor-pointer hover:bg-surface-elevated/60 transition-colors",onClick:()=>bt.navigate(De.TEAM,{agentId:Ne.id,profileTab:"mind"}),children:[n.jsxs("div",{className:"flex items-center gap-2.5",children:[n.jsxs("div",{className:"relative shrink-0",children:[n.jsx(Nr,{name:Ne.name,avatarUrl:Ne.avatarUrl,size:24,bgClass:"bg-brand-500/15 text-brand-600"}),n.jsx("span",{className:"absolute -bottom-0.5 -right-0.5 w-2 h-2 rounded-full bg-blue-500 animate-pulse ring-2 ring-surface-primary"})]}),n.jsxs("div",{className:"flex items-center gap-1.5 min-w-0",children:[n.jsx("span",{className:"text-xs font-medium text-fg-secondary truncate",children:Ne.name}),he.length===0&&n.jsxs("span",{className:"flex items-center gap-0.5",children:[n.jsx("span",{className:"w-1 h-1 rounded-full bg-blue-400 animate-bounce"}),n.jsx("span",{className:"w-1 h-1 rounded-full bg-blue-400 animate-bounce",style:{animationDelay:"0.15s"}}),n.jsx("span",{className:"w-1 h-1 rounded-full bg-blue-400 animate-bounce",style:{animationDelay:"0.3s"}})]}),n.jsx("span",{className:"text-[10px] text-fg-tertiary",children:i("work:task.agentProcessing")})]}),n.jsx("span",{className:"ml-auto text-[10px] text-fg-tertiary",children:"→"})]}),he.length>0&&n.jsx("div",{className:"ml-9 mt-1",children:n.jsx(Wh,{activities:he,isActive:!0})})]},Ne.id)})})]}),Se]})}const O3=new Set([".md",".markdown",".txt",".json",".yaml",".yml",".toml",".csv",".xml",".html",".htm",".css",".js",".ts",".jsx",".tsx",".py",".sh",".log",".env",".cfg",".ini",".png",".jpg",".jpeg",".gif",".webp",".svg"]);function Kre(e){return e==null?"":e<1024?`${e} B`:e<1024*1024?`${(e/1024).toFixed(1)} KB`:`${(e/(1024*1024)).toFixed(1)} MB`}function Wre({filePath:e,onClose:t,onOpenExternal:r}){const{t:s}=pt(["work","common"]),[a,i]=g.useState([e]),l=a[a.length-1],[d,u]=g.useState(null),[m,h]=g.useState(null),[p,y]=g.useState(!0);g.useEffect(()=>{y(!0),h(null),u(null),ie.files.preview(l).then(E=>u(E)).catch(E=>h(String(E))).finally(()=>y(!1))},[l]);const x=E=>i(R=>[...R,E]),v=()=>i(E=>E.length>1?E.slice(0,-1):E),j=a.length>1,C=E=>{ie.files.reveal(E).catch(()=>{})},w=E=>{E.isDirectory||O3.has(E.ext)?x(E.path):C(E.path)},N=l.split("/").pop()??l,S=d?.type==="directory",T=(E,R)=>{if(R)return"📁";const I=[".md",".markdown"],z=[".png",".jpg",".jpeg",".gif",".webp",".svg"];return I.includes(E)?"📝":z.includes(E)?"🖼":[".json",".yaml",".yml",".toml",".xml"].includes(E)?"⚙":[".js",".ts",".jsx",".tsx",".py",".sh"].includes(E)?"💻":"📄"};return n.jsx("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-[60]",onClick:t,children:n.jsxs("div",{className:"bg-surface-secondary border border-border-default rounded-xl w-[720px] max-w-[92vw] max-h-[85vh] flex flex-col shadow-2xl",onClick:E=>E.stopPropagation(),children:[n.jsxs("div",{className:"flex items-center justify-between px-5 py-3 border-b border-border-default shrink-0",children:[n.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[j&&n.jsx("button",{onClick:v,className:"text-fg-tertiary hover:text-fg-primary text-sm shrink-0 p-1 -ml-1 rounded hover:bg-surface-elevated/60 transition-colors",title:s("common:back"),children:n.jsx("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:n.jsx("polyline",{points:"15 18 9 12 15 6"})})}),S?n.jsx("svg",{className:"w-4 h-4 text-amber-500 shrink-0",viewBox:"0 0 16 16",fill:"currentColor",children:n.jsx("path",{d:"M1 3.5A1.5 1.5 0 012.5 2h3.879a1.5 1.5 0 011.06.44l.872.87A.5.5 0 008.665 3.5H13.5A1.5 1.5 0 0115 5v8.5a1.5 1.5 0 01-1.5 1.5h-11A1.5 1.5 0 011 13.5v-10z"})}):n.jsxs("svg",{className:"w-4 h-4 text-fg-tertiary shrink-0",viewBox:"0 0 16 16",fill:"currentColor",children:[n.jsx("path",{d:"M3 1h7l4 4v10H3V1zm7 1H4v12h10V5.5L10 2z"}),n.jsx("path",{d:"M10 1v4h4",fill:"none",stroke:"currentColor",strokeWidth:"1"})]}),n.jsx("span",{className:"text-sm font-medium text-fg-primary truncate",children:N}),S&&d.entries&&n.jsxs("span",{className:"text-[10px] text-fg-tertiary shrink-0",children:["(",d.entries.length,")"]})]}),n.jsxs("div",{className:"flex items-center gap-1 shrink-0 ml-3",children:[n.jsx("button",{onClick:()=>r?r():C(l),className:"text-fg-tertiary hover:text-fg-primary p-1.5 rounded hover:bg-surface-elevated/60 transition-colors",title:s(r?"work:task.openInDeliverables":"work:task.openInFinder"),children:n.jsxs("svg",{className:"w-3.5 h-3.5",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("path",{d:"M18 13v6a2 2 0 01-2 2H5a2 2 0 01-2-2V8a2 2 0 012-2h6"}),n.jsx("polyline",{points:"15 3 21 3 21 9"}),n.jsx("line",{x1:"10",y1:"14",x2:"21",y2:"3"})]})}),n.jsx("button",{onClick:t,className:"text-fg-tertiary hover:text-fg-secondary text-lg shrink-0",children:"×"})]})]}),n.jsx("div",{className:"px-4 py-1 border-b border-border-default/60",children:n.jsx("p",{className:"text-[10px] text-fg-tertiary font-mono truncate",children:l})}),n.jsxs("div",{className:"flex-1 overflow-auto min-h-0",children:[p&&n.jsx("div",{className:"text-sm text-fg-tertiary text-center py-8",children:s("work:task.filePreviewLoading")}),m&&n.jsx("div",{className:"text-sm text-red-500 text-center py-8",children:m}),d?.type==="directory"&&d.entries&&n.jsxs("div",{className:"divide-y divide-border-default/50",children:[d.entries.length===0&&n.jsx("div",{className:"text-sm text-fg-tertiary text-center py-8",children:s("work:task.emptyDirectory")}),d.entries.map(E=>n.jsxs("button",{onClick:()=>w(E),className:"w-full flex items-center gap-3 px-5 py-2.5 hover:bg-surface-elevated/40 transition-colors text-left group",children:[n.jsx("span",{className:"text-sm shrink-0",children:T(E.ext,E.isDirectory)}),n.jsx("span",{className:"flex-1 min-w-0 truncate text-sm text-fg-primary group-hover:text-brand-400 transition-colors",children:E.name}),!E.isDirectory&&E.size!=null&&n.jsx("span",{className:"text-[10px] text-fg-tertiary shrink-0",children:Kre(E.size)}),E.isDirectory&&n.jsx("svg",{className:"w-3.5 h-3.5 text-fg-tertiary shrink-0",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:n.jsx("polyline",{points:"9 18 15 12 9 6"})}),!E.isDirectory&&!O3.has(E.ext)&&n.jsxs("svg",{className:"w-3 h-3 text-fg-tertiary shrink-0 opacity-0 group-hover:opacity-100 transition-opacity",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("path",{d:"M18 13v6a2 2 0 01-2 2H5a2 2 0 01-2-2V8a2 2 0 012-2h6"}),n.jsx("polyline",{points:"15 3 21 3 21 9"}),n.jsx("line",{x1:"10",y1:"14",x2:"21",y2:"3"})]})]},E.path))]}),d&&d.type!=="directory"&&n.jsx("div",{className:"p-5",children:d.type==="image"?n.jsx("div",{className:"flex justify-center",children:n.jsx("img",{src:`data:${d.mimeType};base64,${d.content}`,alt:d.name,className:"max-w-full max-h-[60vh] rounded-lg"})}):n.jsx(fy,{content:d.content,format:d.type==="text"?"text":d.type,className:"text-sm text-fg-secondary leading-relaxed"})})]})]})})}function _3({task:e,agents:t,projects:r,requirements:s,allTasks:a,users:i,onClose:l,onRefresh:d,authUser:u,scrollToComments:m,onScrollToCommentsDone:h,onReqClick:p,onProjectClick:y}){const{t:x}=pt(["work","common"]),v=g.useMemo(()=>eC(x),[x]),[j,C]=g.useState([]),[w,N]=g.useState(""),[S,T]=g.useState(!1),[E,R]=g.useState(!1),[I,z]=g.useState(null),[B,D]=g.useState(null),[V,Y]=g.useState(!1),[F,L]=g.useState(!1),[O,M]=g.useState(!1),[$,W]=g.useState("every"),[U,H]=g.useState(""),[q,Z]=g.useState(""),[_,J]=g.useState(""),[X,ee]=g.useState(!1),[te,G]=g.useState("details"),ue=g.useRef(null),[Se,Ce]=g.useState("none"),Be=g.useCallback(Pe=>{G(Pe),requestAnimationFrame(()=>{ue.current?.scrollTo({top:0,behavior:"instant"})})},[]),Ne=g.useMemo(()=>[{id:"details"},{id:"logs"},{id:"deliverables"},{id:"history"}],[]),he=Sl(Ne,te,Be);g.useEffect(()=>{const Pe=ue.current;if(!Pe)return;const Ct=()=>{const{scrollTop:tt,scrollHeight:Tt,clientHeight:$t}=Pe;if(!(Tt>$t+50)){Ce("none");return}const Zn=tt<30,Xt=tt+$t>=Tt-30;Ce(Zn?"top":Xt?"bottom":"middle")};Ct(),Pe.addEventListener("scroll",Ct,{passive:!0});const ve=new ResizeObserver(Ct);return ve.observe(Pe),()=>{Pe.removeEventListener("scroll",Ct),ve.disconnect()}},[te]),g.useEffect(()=>{if(!m)return;G("details");const Pe=setTimeout(()=>{const Ct=ue.current;Ct&&Ct.scrollTo({top:Ct.scrollHeight,behavior:"smooth"}),h?.()},300);return()=>clearTimeout(Pe)},[m,h]);const[_e,Ee]=g.useState(null),[Ye,Ze]=g.useState(!1),[mt,it]=g.useState(null),[Lt,ht]=g.useState(!1),[ne,me]=g.useState(e.description),be=g.useRef(null),se=g.useRef(null),fe=g.useRef(80);g.useEffect(()=>{if(Lt&&se.current){const Pe=se.current;Pe.style.height="auto",Pe.style.height=Math.max(Pe.scrollHeight,fe.current)+"px",Pe.focus()}},[Lt]);const[He,Ae]=g.useState(!1),[et,pe]=g.useState(""),[Fe,Ve]=g.useState(1),[nt,gt]=g.useState(!1),rt=Rs(),Et=20,je=g.useCallback(async()=>{try{const Pe=await ie.tasks.listSubtasks(e.id);C(Pe.subtasks)}catch{}},[e.id]);g.useEffect(()=>{je()},[je]);const Re=async Pe=>{if(!X){ee(!0);try{await Pe(),d(),await je()}catch(Ct){Ee(String(Ct).replace("Error: ",""))}finally{ee(!1)}}},We=Pe=>Re(()=>ie.tasks.update(e.id,{priority:Pe})),Vt=Pe=>Re(()=>ie.tasks.assign(e.id,Pe||null)),ln=Pe=>Re(()=>ie.tasks.update(e.id,{projectId:Pe||null})),en=async()=>{if(!X){ee(!0);try{await ie.tasks.pause(e.id),d()}finally{ee(!1)}}},vn=async()=>{if(!X){ee(!0),Ee(null),Be("logs");try{await ie.tasks.resume(e.id),d()}catch(Pe){Ee(String(Pe).replace("Error: API error: 400","Server error").replace("Error: ",""))}finally{ee(!1)}}},In=async()=>{w.trim()&&(await ie.tasks.createSubtask(e.id,w.trim()),N(""),T(!1),je(),d())},Zt=async Pe=>{Pe.status==="completed"?await ie.tasks.cancelSubtask(e.id,Pe.id):await ie.tasks.completeSubtask(e.id,Pe.id),je(),d()},cn=async Pe=>{await ie.tasks.deleteSubtask(e.id,Pe.id),z(null),je(),d()},Gn=async()=>{if(!X){ee(!0);try{await ie.tasks.updateStatus(e.id,"in_progress"),d()}finally{ee(!1)}}},Ln=async()=>{if(!X){ee(!0),Ee(null),Be("logs");try{await ie.tasks.retry(e.id),d()}catch(Pe){Ee(String(Pe).replace("Error: API error: 400","Server error").replace("Error: ",""))}finally{ee(!1)}}},Lr=async()=>{if(!X){ee(!0),Ee(null),Be("logs");try{await ie.tasks.runNow(e.id),d()}catch(Pe){Ee(String(Pe).replace("Error: API error: 400","Server error").replace("Error: ","")),d()}finally{ee(!1)}}},Qr=g.useRef(d);Qr.current=d,g.useEffect(()=>pn.on("task:update",Ct=>{Ct.payload.taskId===e.id&&(je(),Qr.current())}),[e.id,je]);const mr=j.filter(Pe=>Pe.status==="completed").length,Ge=e.status==="in_progress",Ht=e.status==="blocked",Wt=Ht&&(!e.blockedBy||e.blockedBy.length===0||e.blockedBy.every(Pe=>{const Ct=a.find(ve=>ve.id===Pe);return Ct&&Ct.status==="completed"})),tn=e.status==="completed",zn=e.status==="failed",Mn=e.status==="rejected",wn=e.status==="cancelled",Dn=e.status==="archived",$n=tn||zn||Mn||wn||Dn,Sn=e.taskType==="scheduled"&&!!e.scheduleConfig,Bn=Sn&&!!e.scheduleConfig?.paused,Vn=(()=>{const Pe=r.find(Ct=>Ct.id===e.projectId);return Pe&&Pe.name!=="default"?Pe:void 0})(),Qn=s.find(Pe=>Pe.id===e.requirementId);return t.find(Pe=>Pe.id===e.assignedAgentId),n.jsxs("div",{className:"flex flex-col w-full h-full overflow-hidden bg-surface-primary shadow-xl shadow-black/8 ring-1 ring-border-default/20",children:[n.jsxs("div",{className:"flex items-start justify-between gap-4 px-6 pt-5 pb-3 border-b border-border-default shrink-0",children:[n.jsxs("div",{className:"flex items-center gap-2 flex-1 min-w-0",children:[rt&&n.jsx("button",{onClick:()=>history.back(),className:"text-fg-secondary hover:text-fg-primary transition-colors p-1 -ml-1 shrink-0",children:n.jsx("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:n.jsx("polyline",{points:"15 18 9 12 15 6"})})}),n.jsxs("h3",{className:"flex-1 min-w-0 text-base font-semibold leading-snug text-fg-primary",children:[e.title," ",(()=>{const Pe=v[e.status];return Pe?n.jsx("span",{className:`text-[10px] px-2 py-0.5 rounded-full font-medium whitespace-nowrap align-middle ${Pe.cls}`,children:Pe.label}):n.jsx("span",{className:"text-[10px] px-2 py-0.5 rounded-full font-medium bg-gray-500/15 text-fg-tertiary whitespace-nowrap align-middle",children:e.status.replace(/_/g," ")})})(),Wt&&n.jsx("span",{className:"text-[10px] px-2 py-0.5 rounded-full font-medium whitespace-nowrap align-middle bg-red-500/15 text-red-500",children:x("work:task.abnormalBlock")})]})]}),n.jsx("button",{onClick:l,className:"text-fg-tertiary hover:text-fg-secondary text-xl leading-none shrink-0 mt-1",children:"×"})]}),n.jsxs("div",{className:"flex gap-1 px-6 pt-2 pb-0 shrink-0",children:[n.jsx("button",{onClick:()=>Be("details"),className:`px-3 py-1.5 text-xs rounded-t-md transition-colors ${te==="details"?"bg-surface-elevated text-fg-primary font-medium":"text-fg-tertiary hover:text-fg-secondary"}`,children:x("work:task.detailsTab")}),n.jsxs("button",{onClick:()=>Be("logs"),className:`px-3 py-1.5 text-xs rounded-t-md transition-colors flex items-center gap-1.5 ${te==="logs"?"bg-surface-elevated text-fg-primary font-medium":"text-fg-tertiary hover:text-fg-secondary"}`,children:[x("work:task.executionLogTab"),Ge&&n.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-brand-400 animate-pulse"})]}),n.jsx("button",{onClick:()=>Be("deliverables"),className:`px-3 py-1.5 text-xs rounded-t-md transition-colors flex items-center gap-1.5 ${te==="deliverables"?"bg-surface-elevated text-fg-primary font-medium":"text-fg-tertiary hover:text-fg-secondary"}`,children:(()=>{const Pe=(e.deliverables??[]).filter(Ct=>Ct.type!=="branch"&&typeof Ct.reference=="string"&&Ct.reference.length>0).length;return Pe>0?x("work:task.deliverablesCount",{count:Pe}):x("work:task.deliverables")})()}),n.jsx("button",{onClick:()=>Be("history"),className:`px-3 py-1.5 text-xs rounded-t-md transition-colors ${te==="history"?"bg-surface-elevated text-fg-primary font-medium":"text-fg-tertiary hover:text-fg-secondary"}`,children:x("work:task.historyTab")})]}),n.jsxs("div",{className:"flex-1 min-h-0 relative",children:[n.jsxs("div",{ref:ue,className:"h-full overflow-y-auto overflow-x-hidden",onTouchStart:he.onTouchStart,onTouchEnd:he.onTouchEnd,children:[n.jsxs("div",{className:te==="logs"?"min-w-0 min-h-full":"hidden",children:[_e&&n.jsxs("div",{className:"mx-4 mt-3 px-3 py-2 bg-red-500/10 border border-red-500/30 rounded-lg text-xs text-red-500",children:[n.jsx("span",{className:"font-medium",children:x("work:task.failedToStart")})," ",_e]}),n.jsx(Vre,{task:e,isRunning:e.status==="in_progress",authUser:u,agents:t})]}),n.jsxs("div",{className:te==="details"?"":"hidden",children:[n.jsx("div",{className:"px-6 pt-4 pb-3 border-b border-border-default",children:Lt?n.jsx("textarea",{ref:se,value:ne,onChange:Pe=>{me(Pe.target.value);const Ct=Pe.target;Ct.style.height="auto",Ct.style.height=Ct.scrollHeight+"px"},onBlur:()=>{ne!==e.description&&Re(()=>ie.tasks.update(e.id,{description:ne})),ht(!1)},onKeyDown:Pe=>{Pe.key==="Escape"&&(Pe.preventDefault(),me(e.description),ht(!1))},className:"w-full bg-transparent border border-brand-500/30 rounded-lg text-sm text-fg-primary focus:border-brand-500 outline-none resize-none -mx-2 px-2 -my-1 py-1",placeholder:x("work:task.addDescription")}):n.jsx("div",{ref:be,className:"group relative cursor-pointer rounded-lg -mx-2 px-2 -my-1 py-1 hover:bg-surface-elevated/50 transition-colors",onClick:Pe=>{Pe.target.closest("a, button, [data-entity-link]")||(fe.current=Math.max(be.current?.offsetHeight??80,60),me(e.description),ht(!0))},role:"button",tabIndex:0,onKeyDown:Pe=>Pe.key==="Enter"&&(me(e.description),ht(!0)),children:e.description?n.jsxs("div",{children:[n.jsx("div",{className:rt&&!nt?"line-clamp-3":"",children:n.jsx(Wr,{content:e.description,className:"text-sm text-fg-secondary leading-relaxed"})}),rt&&e.description.length>150&&n.jsx("button",{onClick:Pe=>{Pe.stopPropagation(),gt(!nt)},className:"text-[11px] text-brand-500 mt-1 font-medium",children:x(nt?"work:task.collapse":"common:showMore")})]}):n.jsx("p",{className:"text-sm text-fg-tertiary italic",children:x("work:task.noDescription")})})}),(Vn||Qn)&&n.jsxs("div",{className:"px-6 py-2.5 border-b border-border-default flex flex-wrap items-center gap-2",children:[Vn&&n.jsxs("span",{className:`flex items-center gap-1 text-[11px] px-2 py-0.5 bg-brand-500/10 text-brand-500 rounded-full ${y?"cursor-pointer hover:bg-brand-500/20 transition-colors":""}`,onClick:y?()=>y(Vn.id):void 0,role:y?"button":void 0,tabIndex:y?0:void 0,onKeyDown:y?Pe=>Pe.key==="Enter"&&y(Vn.id):void 0,children:[n.jsx("span",{className:"text-[9px] text-brand-500/60",children:x("work:task.projectLabel")}),Vn.name]}),Qn&&n.jsxs("span",{className:`flex items-center gap-1 text-[11px] px-2 py-0.5 bg-brand-500/10 text-brand-500 rounded-full ${p?"cursor-pointer hover:bg-brand-500/20 transition-colors":""}`,onClick:p?()=>p(Qn):void 0,role:p?"button":void 0,tabIndex:p?0:void 0,onKeyDown:p?Pe=>Pe.key==="Enter"&&p(Qn):void 0,children:[n.jsx("span",{className:"text-[9px] text-brand-500/60",children:x("work:task.requirementLabel")}),Qn.title.length>40?Qn.title.slice(0,40)+"…":Qn.title]})]}),n.jsxs("div",{className:"px-6 py-2.5 border-b border-border-default",children:[n.jsx("div",{className:"flex items-center justify-between mb-1.5",children:n.jsx("span",{className:"text-[10px] font-semibold text-fg-tertiary uppercase tracking-wider",children:x("work:task.dependencies")})}),e.blockedBy&&e.blockedBy.length>0?n.jsx("div",{className:"flex flex-wrap gap-1.5 mb-2",children:e.blockedBy.map(Pe=>{const Ct=a.find(tt=>tt.id===Pe),ve=Ct&&(Ct.status==="completed"||Ct.status==="cancelled");return n.jsxs("span",{className:`inline-flex items-center gap-1 text-[11px] px-2 py-1 rounded-full ${ve?"bg-green-500/10 text-green-600":"bg-amber-500/10 text-amber-600"}`,children:[n.jsx("span",{className:"text-[9px]",children:ve?"✓":"⏳"}),n.jsx("span",{className:`font-mono ${ve?"line-through opacity-60":""}`,children:Ct?Ct.title.slice(0,30):Pe.slice(-8)}),!$n&&n.jsx("button",{onClick:async()=>{const tt=(e.blockedBy??[]).filter(Tt=>Tt!==Pe);await ie.tasks.update(e.id,{blockedBy:tt}),d()},className:"ml-0.5 text-current opacity-40 hover:opacity-100 transition-opacity",title:x("work:task.removeDependency"),children:"×"})]},Pe)})}):n.jsx("p",{className:"text-[11px] text-fg-tertiary mb-2",children:x("work:task.noDependencies")}),Wt&&n.jsxs("div",{className:"flex items-center gap-1.5 px-2.5 py-1.5 bg-red-500/10 border border-red-500/20 rounded-lg text-xs text-red-500 mb-2",children:[n.jsxs("svg",{className:"w-3.5 h-3.5 shrink-0",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("path",{d:"M10.29 3.86L1.82 18a2 2 0 001.71 3h16.94a2 2 0 001.71-3L13.71 3.86a2 2 0 00-3.42 0z"}),n.jsx("line",{x1:"12",y1:"9",x2:"12",y2:"13"}),n.jsx("line",{x1:"12",y1:"17",x2:"12.01",y2:"17"})]}),n.jsx("span",{children:x("work:task.abnormalBlockHint")})]}),!$n&&n.jsxs("select",{value:"",onChange:async Pe=>{const Ct=Pe.target.value;if(!Ct)return;const ve=[...e.blockedBy??[],Ct];await ie.tasks.update(e.id,{blockedBy:ve}),d()},className:"w-full px-2 py-1.5 bg-surface-elevated border border-border-default rounded-lg text-[11px] text-fg-secondary focus:border-brand-500 outline-none",children:[n.jsx("option",{value:"",children:x("work:task.addDependency")}),a.filter(Pe=>Pe.id!==e.id&&!(e.blockedBy??[]).includes(Pe.id)).map(Pe=>n.jsx("option",{value:Pe.id,children:Pe.title},Pe.id))]})]}),n.jsxs("div",{className:"px-6 py-4 border-b border-border-default/60 space-y-3",children:[n.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[n.jsxs("div",{children:[n.jsx("label",{className:"block text-[10px] font-semibold text-fg-tertiary uppercase tracking-wider mb-1",children:x("work:task.projectLabel")}),n.jsxs("select",{value:e.projectId??"",onChange:Pe=>{ln(Pe.target.value)},disabled:X,className:"w-full px-2 py-1.5 bg-surface-elevated border border-border-default rounded-lg text-xs text-fg-primary focus:border-brand-500 outline-none disabled:opacity-50 cursor-pointer",children:[n.jsx("option",{value:"",children:x("work:task.noProject")}),r.map(Pe=>n.jsx("option",{value:Pe.id,children:Pe.name},Pe.id))]})]}),n.jsxs("div",{children:[n.jsx("label",{className:"block text-[10px] font-semibold text-fg-tertiary uppercase tracking-wider mb-1",children:x("work:task.requirementLabel")}),n.jsxs("select",{value:e.requirementId??"",onChange:Pe=>Re(()=>ie.tasks.update(e.id,{requirementId:Pe.target.value||null})),disabled:X,className:"w-full px-2 py-1.5 bg-surface-elevated border border-border-default rounded-lg text-xs text-fg-primary focus:border-brand-500 outline-none disabled:opacity-50 cursor-pointer",children:[n.jsx("option",{value:"",children:x("work:task.noRequirement")}),s.filter(Pe=>!e.projectId||Pe.projectId===e.projectId).map(Pe=>n.jsx("option",{value:Pe.id,children:Pe.title},Pe.id))]})]})]}),n.jsxs("div",{className:"grid grid-cols-3 gap-4",children:[n.jsxs("div",{children:[n.jsx("label",{className:"block text-[10px] font-semibold text-fg-tertiary uppercase tracking-wider mb-1",children:x("work:task.assignee")}),n.jsxs("select",{value:e.assignedAgentId??"",onChange:Pe=>{Vt(Pe.target.value)},disabled:X,className:"w-full px-2 py-1.5 bg-surface-elevated border border-border-default rounded-lg text-xs text-fg-primary focus:border-brand-500 outline-none disabled:opacity-50 cursor-pointer",children:[n.jsx("option",{value:"",children:x("work:task.unassigned")}),t.map(Pe=>n.jsxs("option",{value:Pe.id,children:[Pe.name," (",Pe.status,")"]},Pe.id))]})]}),n.jsxs("div",{children:[n.jsx("label",{className:"block text-[10px] font-semibold text-fg-tertiary uppercase tracking-wider mb-1",children:x("work:task.reviewer")}),n.jsxs("select",{value:`${e.reviewerType??"agent"}:${e.reviewerId??""}`,onChange:Pe=>{const Ct=Pe.target.value;if(!Ct)return;const ve=Ct.startsWith("human:"),tt=Ct.replace(/^(human|agent):/,"");(tt!==e.reviewerId||(ve?"human":"agent")!==(e.reviewerType??"agent"))&&Re(()=>ie.tasks.update(e.id,{reviewerId:tt,reviewerType:ve?"human":"agent"}))},disabled:X,className:"w-full px-2 py-1.5 bg-surface-elevated border border-border-default rounded-lg text-xs text-fg-primary focus:border-brand-500 outline-none disabled:opacity-50 cursor-pointer",children:[i.map(Pe=>n.jsx("option",{value:`human:${Pe.id}`,children:Pe.name},`human:${Pe.id}`)),t.map(Pe=>n.jsx("option",{value:`agent:${Pe.id}`,children:Pe.name},`agent:${Pe.id}`))]})]}),n.jsxs("div",{children:[n.jsx("label",{className:"block text-[10px] font-semibold text-fg-tertiary uppercase tracking-wider mb-1",children:x("work:task.priority")}),n.jsxs("select",{value:e.priority,onChange:Pe=>{We(Pe.target.value)},disabled:X,className:"w-full px-2 py-1.5 bg-surface-elevated border border-border-default rounded-lg text-xs text-fg-primary focus:border-brand-500 outline-none disabled:opacity-50 cursor-pointer",children:[n.jsx("option",{value:"low",children:x("work:priority.low")}),n.jsx("option",{value:"medium",children:x("work:priority.medium")}),n.jsx("option",{value:"high",children:x("work:priority.high")}),n.jsx("option",{value:"urgent",children:x("work:priority.urgent")})]})]})]})]}),n.jsxs("div",{className:"px-6 py-3 border-b border-border-default/60 flex flex-wrap items-center gap-x-4 gap-y-1.5 text-[11px] text-fg-tertiary",children:[e.createdBy&&n.jsx("span",{children:x("work:task.createdBy",{name:Rd(e.createdBy,t,i)??e.createdBy})}),e.updatedBy&&n.jsx("span",{children:x("work:task.updatedBy",{name:Rd(e.updatedBy,t,i)??e.updatedBy})}),e.createdAt&&n.jsx("span",{children:new Date(e.createdAt).toLocaleDateString()}),e.startedAt&&n.jsx("span",{children:x("work:task.started",{date:new Date(e.startedAt).toLocaleDateString()})}),e.updatedAt&&n.jsx("span",{children:x("work:task.updatedMeta",{date:new Date(e.updatedAt).toLocaleDateString()})}),e.projectId&&n.jsxs("span",{className:"font-mono text-blue-600/70",children:["task/",e.id]}),(e.executionRound??1)>1&&n.jsx("span",{className:"text-amber-600",children:x("work:task.executionRound",{n:e.executionRound})})]}),n.jsxs("div",{className:"px-6 py-4",children:[n.jsxs("div",{className:"flex items-center justify-between mb-3",children:[n.jsxs("span",{className:"text-xs font-semibold text-fg-secondary uppercase tracking-wider",children:[x("work:task.subtasks")," ",j.length>0&&n.jsx("span",{className:"ml-1.5 text-fg-tertiary font-normal normal-case",children:x("work:task.subtasksProgress",{done:mr,total:j.length})})]}),n.jsxs("div",{className:"flex items-center gap-2",children:[mr>0&&n.jsx("button",{onClick:()=>R(Pe=>!Pe),className:`text-[10px] px-2 py-0.5 rounded-full border transition-colors ${E?"bg-brand-500/15 text-brand-500 border-brand-500/30":"text-fg-tertiary border-border-default hover:text-fg-secondary"}`,children:E?x("work:task.hideCompleted"):x("work:task.showCompleted",{count:mr})}),n.jsx("button",{onClick:()=>T(!0),className:"text-xs text-brand-500 hover:text-brand-500 transition-colors",children:x("work:task.addSubtask")})]})]}),(()=>{const Pe=E?j:j.filter(Ct=>Ct.status!=="completed");return Pe.length>0?n.jsx("div",{className:"space-y-1.5 mb-3",children:Pe.map(Ct=>n.jsxs("div",{className:"group flex items-center gap-2.5 py-1.5 px-2 rounded-lg hover:bg-surface-elevated/50 transition-colors",children:[n.jsx("button",{onClick:()=>{Zt(Ct)},className:`shrink-0 w-4 h-4 rounded border flex items-center justify-center transition-colors ${Ct.status==="completed"?"bg-green-600 border-green-600 text-white":"border-gray-600 hover:border-brand-500"}`,children:Ct.status==="completed"&&n.jsx("svg",{className:"w-2.5 h-2.5",viewBox:"0 0 12 12",fill:"none",children:n.jsx("path",{d:"M2 6l3 3 5-5",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})}),n.jsx("span",{className:`flex-1 text-sm ${Ct.status==="completed"?"line-through text-fg-tertiary":"text-fg-secondary"}`,children:Ct.title}),n.jsx("button",{onClick:()=>z(Ct),className:"shrink-0 opacity-0 group-hover:opacity-100 text-fg-tertiary hover:text-red-500 transition-all text-xs",children:"✕"})]},Ct.id))}):null})(),j.length===0&&!S&&n.jsx("div",{className:"text-xs text-fg-tertiary text-center py-4",children:x("work:task.noSubtasksYet")}),S&&n.jsxs("div",{className:"flex gap-2 mt-2",children:[n.jsx("input",{autoFocus:!0,value:w,onChange:Pe=>N(Pe.target.value),onKeyDown:Pe=>{Pe.key==="Enter"&&In(),Pe.key==="Escape"&&(T(!1),N(""))},placeholder:x("work:task.subtaskTitlePlaceholder"),className:"flex-1 px-3 py-1.5 bg-surface-elevated border border-border-default rounded-lg text-sm focus:border-brand-500 outline-none"}),n.jsx("button",{onClick:()=>{In()},className:"px-3 py-1.5 bg-brand-600 hover:bg-brand-500 text-white text-xs rounded-lg",children:x("work:task.add")}),n.jsx("button",{onClick:()=>{T(!1),N("")},className:"px-3 py-1.5 border border-border-default text-xs rounded-lg hover:bg-surface-elevated",children:x("common:cancel")})]}),(()=>{const Pe=(e.deliverables??[]).filter(tt=>tt.type!=="branch"&&typeof tt.reference=="string"&&tt.reference.length>0);if(Pe.length===0)return null;const Ct={file:"bg-blue-500/15 text-blue-600",document:"bg-blue-500/15 text-blue-600",report:"bg-brand-500/15 text-brand-500",directory:"bg-green-500/15 text-green-600",url:"bg-brand-500/15 text-brand-500",text:"bg-gray-500/15 text-fg-secondary"},ve=Pe.slice(0,3);return n.jsxs("div",{className:"mt-5",children:[n.jsxs("div",{className:"flex items-center justify-between mb-2",children:[n.jsx("p",{className:"text-xs font-semibold text-fg-tertiary uppercase tracking-wider",children:x("work:task.deliverablesCount",{count:Pe.length})}),Pe.length>3&&n.jsx("button",{onClick:()=>Be("deliverables"),className:"text-[10px] text-brand-500 hover:text-brand-500",children:x("work:task.viewAll")})]}),n.jsx("div",{className:"space-y-1.5",children:ve.map((tt,Tt)=>{const $t=/^https?:\/\//i.test(tt.reference),sn=$t?tt.summary||tt.reference:tt.reference.split("/").pop()??tt.reference;return n.jsxs("div",{className:"flex items-start gap-2.5 bg-surface-elevated/60 rounded-lg px-3 py-2 group hover:bg-surface-elevated/80 transition-colors",children:[n.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded font-medium shrink-0 mt-0.5 ${Ct[tt.type]??"bg-gray-500/15 text-fg-secondary"}`,children:tt.type}),n.jsxs("div",{className:"flex-1 min-w-0",children:[$t?n.jsxs("a",{href:tt.reference,target:"_blank",rel:"noopener noreferrer",className:"text-sm text-brand-500 hover:text-brand-500 font-medium truncate block max-w-full text-left hover:underline",title:tt.reference,children:[sn," ",n.jsxs("svg",{className:"w-3 h-3 inline -mt-0.5 ml-0.5 opacity-60",viewBox:"0 0 12 12",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("path",{d:"M9 6.5v3a.5.5 0 0 1-.5.5h-6a.5.5 0 0 1-.5-.5v-6A.5.5 0 0 1 2.5 3H6"}),n.jsx("path",{d:"M7 2h3v3"}),n.jsx("path",{d:"M5 7 10 2"})]})]}):n.jsx("button",{onClick:()=>it(tt.reference),className:"text-sm text-brand-500 hover:text-brand-500 font-medium truncate block max-w-full text-left hover:underline",title:tt.reference,children:sn}),tt.summary&&!$t&&n.jsx("p",{className:"text-[11px] text-fg-secondary mt-0.5 line-clamp-2",children:tt.summary}),n.jsx("p",{className:"text-[10px] text-fg-tertiary font-mono truncate mt-0.5",children:tt.reference})]})]},Tt)})})]})})(),n.jsx(Ure,{task:e,agents:t,users:i,authUser:u})]})]}),n.jsx("div",{className:te==="history"?"":"hidden",children:n.jsx(sC,{entityType:"task",entityId:e.id})}),n.jsx("div",{className:te==="deliverables"?"px-6 py-4":"hidden",children:(()=>{const Pe=(e.deliverables??[]).filter(Tt=>Tt.type!=="branch"&&typeof Tt.reference=="string"&&Tt.reference.length>0);if(Pe.length===0)return n.jsx("div",{className:"flex items-center justify-center py-12 text-xs text-fg-tertiary",children:x("work:task.noDeliverablesYet")});const Ct={file:"bg-blue-500/15 text-blue-600",document:"bg-blue-500/15 text-blue-600",report:"bg-brand-500/15 text-brand-500",directory:"bg-green-500/15 text-green-600",url:"bg-brand-500/15 text-brand-500",text:"bg-gray-500/15 text-fg-secondary"},ve=Math.ceil(Pe.length/Et),tt=Pe.slice((Fe-1)*Et,Fe*Et);return n.jsxs(n.Fragment,{children:[n.jsxs("div",{className:"flex items-center justify-between mb-3",children:[n.jsx("p",{className:"text-xs font-semibold text-fg-tertiary uppercase tracking-wider",children:x("work:task.deliverablesCount",{count:Pe.length})}),ve>1&&n.jsxs("div",{className:"flex items-center gap-1.5 text-[10px] text-fg-tertiary",children:[n.jsx("button",{disabled:Fe<=1,onClick:()=>Ve(Tt=>Tt-1),className:"px-1.5 py-0.5 rounded bg-surface-elevated hover:bg-surface-overlay disabled:opacity-30",children:"‹"}),n.jsxs("span",{children:[Fe,"/",ve]}),n.jsx("button",{disabled:Fe>=ve,onClick:()=>Ve(Tt=>Tt+1),className:"px-1.5 py-0.5 rounded bg-surface-elevated hover:bg-surface-overlay disabled:opacity-30",children:"›"})]})]}),n.jsx("div",{className:"space-y-1.5",children:tt.map((Tt,$t)=>{const sn=/^https?:\/\//i.test(Tt.reference),Zn=sn?Tt.summary||Tt.reference:Tt.reference.split("/").pop()??Tt.reference;return n.jsxs("div",{className:"flex items-start gap-2.5 bg-surface-elevated/60 rounded-lg px-3 py-2 group hover:bg-surface-elevated/80 transition-colors",children:[n.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded font-medium shrink-0 mt-0.5 ${Ct[Tt.type]??"bg-gray-500/15 text-fg-secondary"}`,children:Tt.type}),n.jsxs("div",{className:"flex-1 min-w-0",children:[sn?n.jsxs("a",{href:Tt.reference,target:"_blank",rel:"noopener noreferrer",className:"text-sm text-brand-500 hover:text-brand-500 font-medium truncate block max-w-full text-left hover:underline",title:Tt.reference,children:[Zn," ",n.jsxs("svg",{className:"w-3 h-3 inline -mt-0.5 ml-0.5 opacity-60",viewBox:"0 0 12 12",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("path",{d:"M9 6.5v3a.5.5 0 0 1-.5.5h-6a.5.5 0 0 1-.5-.5v-6A.5.5 0 0 1 2.5 3H6"}),n.jsx("path",{d:"M7 2h3v3"}),n.jsx("path",{d:"M5 7 10 2"})]})]}):n.jsx("button",{onClick:()=>it(Tt.reference),className:"text-sm text-brand-500 hover:text-brand-500 font-medium truncate block max-w-full text-left hover:underline",title:Tt.reference,children:Zn}),Tt.summary&&!sn&&n.jsx("p",{className:"text-[11px] text-fg-secondary mt-0.5 line-clamp-2",children:Tt.summary}),n.jsx("p",{className:"text-[10px] text-fg-tertiary font-mono truncate mt-0.5",children:Tt.reference})]})]},$t)})})]})})()})]}),Se!=="none"&&Se!=="top"&&n.jsx("button",{onClick:()=>ue.current?.scrollTo({top:0,behavior:"smooth"}),className:"absolute bottom-36 right-4 md:bottom-28 md:right-3 z-10 w-12 h-12 md:w-8 md:h-8 rounded-full bg-brand-500 md:bg-brand-600/90 border border-brand-400/60 shadow-xl shadow-brand-500/30 md:shadow-lg md:shadow-brand-500/20 flex items-center justify-center text-white hover:bg-brand-400 transition-colors backdrop-blur-sm",title:x("work:task.scrollToTop"),children:n.jsx("svg",{className:"w-6 h-6 md:w-4 md:h-4",viewBox:"0 0 20 20",fill:"currentColor",children:n.jsx("path",{fillRule:"evenodd",d:"M14.77 12.79a.75.75 0 01-1.06-.02L10 8.832l-3.71 3.938a.75.75 0 11-1.08-1.04l4.25-4.5a.75.75 0 011.08 0l4.25 4.5a.75.75 0 01-.02 1.06z",clipRule:"evenodd"})})}),Se!=="none"&&Se!=="bottom"&&n.jsx("button",{onClick:()=>{const Pe=ue.current;Pe&&Pe.scrollTo({top:Pe.scrollHeight,behavior:"smooth"})},className:"absolute bottom-22 right-4 md:bottom-18 md:right-3 z-10 w-12 h-12 md:w-8 md:h-8 rounded-full bg-brand-500 md:bg-brand-600/90 border border-brand-400/60 shadow-xl shadow-brand-500/30 md:shadow-lg md:shadow-brand-500/20 flex items-center justify-center text-white hover:bg-brand-400 transition-colors backdrop-blur-sm",title:x("work:task.scrollToBottom"),children:n.jsx("svg",{className:"w-6 h-6 md:w-4 md:h-4",viewBox:"0 0 20 20",fill:"currentColor",children:n.jsx("path",{fillRule:"evenodd",d:"M5.23 7.21a.75.75 0 011.06.02L10 11.168l3.71-3.938a.75.75 0 111.08 1.04l-4.25 4.5a.75.75 0 01-1.08 0l-4.25-4.5a.75.75 0 01.02-1.06z",clipRule:"evenodd"})})})]}),Sn&&e.scheduleConfig&&n.jsxs("div",{className:`mx-6 mt-3 mb-0 px-4 py-2.5 rounded-lg border text-xs ${Bn?"bg-amber-500/5 border-amber-500/20":"bg-brand-500/5 border-brand-500/20"} ${!Ge&&!O&&!e.scheduleConfig.runAt?"cursor-pointer hover:border-brand-500/40 transition-colors":""}`,onClick:()=>{Ge||O||e.scheduleConfig?.runAt||(W(e.scheduleConfig?.cron?"cron":"every"),H(e.scheduleConfig?.every??"4h"),Z(e.scheduleConfig?.cron??""),J(e.scheduleConfig?.maxRuns&&e.scheduleConfig.maxRuns>0?String(e.scheduleConfig.maxRuns):""),M(!0))},children:[n.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[n.jsx("span",{className:Bn?"text-amber-600":"text-brand-500",children:Bn?x("work:task.schedulePaused"):n.jsxs(n.Fragment,{children:[n.jsx("svg",{className:"w-3.5 h-3.5 inline -mt-0.5",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:n.jsx("path",{d:"M21.5 2v6h-6M2.5 22v-6h6M2 11.5a10 10 0 0 1 18.8-4.3M22 12.5a10 10 0 0 1-18.8 4.3"})})," ",x("work:task.scheduled")]})}),n.jsx("span",{className:"text-fg-tertiary",children:"·"}),n.jsx("span",{className:"text-fg-secondary",children:e.scheduleConfig.every?x("work:task.scheduleEvery",{interval:e.scheduleConfig.every}):e.scheduleConfig.cron?x("work:task.scheduleCron",{expr:e.scheduleConfig.cron}):e.scheduleConfig.runAt?x("work:task.scheduleOneShot"):x("work:task.scheduleNA")}),!Bn&&e.scheduleConfig.nextRunAt&&n.jsxs(n.Fragment,{children:[n.jsx("span",{className:"text-fg-tertiary",children:"·"}),n.jsx("span",{className:"text-fg-secondary",children:x("work:task.scheduleNext",{when:(()=>{const Pe=new Date(e.scheduleConfig.nextRunAt).getTime()-Date.now();if(Pe<=0)return x("work:task.scheduleDueNow");const Ct=Math.floor(Pe/6e4);if(Ct<60)return x("work:task.scheduleInMinutes",{count:Ct});const ve=Math.floor(Ct/60);return ve<24?x("work:task.scheduleInHoursMinutes",{h:ve,m:Ct%60}):x("work:task.scheduleInDaysHours",{d:Math.floor(ve/24),h:ve%24})})()})})]}),!Ge&&!O&&!e.scheduleConfig.runAt&&n.jsxs("svg",{className:"w-3 h-3 text-brand-500 ml-auto shrink-0",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("path",{d:"M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"}),n.jsx("path",{d:"M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z"})]})]}),O?n.jsxs("div",{className:"mt-2 pt-2 border-t border-border-default/50 space-y-2",onClick:Pe=>Pe.stopPropagation(),children:[n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsxs("select",{value:$,onChange:Pe=>W(Pe.target.value),className:"px-2 py-1 text-xs bg-surface-elevated border border-border-default rounded-lg",children:[n.jsx("option",{value:"every",children:x("work:task.scheduleEveryMode")}),n.jsx("option",{value:"cron",children:x("work:task.scheduleCronMode")})]}),$==="every"?n.jsxs("select",{value:U,onChange:Pe=>H(Pe.target.value),className:"flex-1 px-2 py-1 text-xs bg-surface-elevated border border-border-default rounded-lg",children:[n.jsx("option",{value:"30m",children:x("work:task.freq30m")}),n.jsx("option",{value:"1h",children:x("work:task.freq1h")}),n.jsx("option",{value:"2h",children:x("work:task.freq2h")}),n.jsx("option",{value:"4h",children:x("work:task.freq4h")}),n.jsx("option",{value:"8h",children:x("work:task.freq8h")}),n.jsx("option",{value:"12h",children:x("work:task.freq12h")}),n.jsx("option",{value:"1d",children:x("work:task.freq1d")}),n.jsx("option",{value:"1w",children:x("work:task.freq1w")})]}):n.jsx("input",{value:q,onChange:Pe=>Z(Pe.target.value),placeholder:"0 9 * * 1-5",className:"flex-1 px-2 py-1 text-xs bg-surface-elevated border border-border-default rounded-lg outline-none focus:border-brand-500"})]}),n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx("label",{className:"text-fg-tertiary shrink-0",children:x("work:task.scheduleMaxRuns")}),n.jsx("input",{value:_,onChange:Pe=>J(Pe.target.value.replace(/\D/g,"")),placeholder:x("work:task.scheduleMaxRunsPlaceholder"),className:"w-20 px-2 py-1 text-xs bg-surface-elevated border border-border-default rounded-lg outline-none focus:border-brand-500"})]}),n.jsxs("div",{className:"flex items-center gap-2 pt-1",children:[n.jsx("button",{onClick:async()=>{const Pe={};$==="every"?Pe.every=U:Pe.cron=q.trim(),_&&(Pe.maxRuns=parseInt(_,10)),await Re(()=>ie.tasks.updateSchedule(e.id,Pe)),M(!1)},disabled:X,className:"px-3 py-1 text-xs bg-brand-600 hover:bg-brand-500 rounded-lg text-white disabled:opacity-50",children:x("common:save")}),n.jsx("button",{onClick:()=>M(!1),className:"px-3 py-1 text-xs text-fg-secondary hover:text-fg-primary",children:x("common:cancel")})]})]}):n.jsxs("div",{className:"flex items-center gap-2 mt-1 text-fg-tertiary",children:[n.jsx("span",{children:x("work:task.scheduleRuns",{current:e.scheduleConfig.currentRuns??0,max:e.scheduleConfig.maxRuns&&e.scheduleConfig.maxRuns>0?x("work:task.scheduleRunsMax",{max:e.scheduleConfig.maxRuns}):""})}),e.scheduleConfig.lastRunAt&&n.jsxs(n.Fragment,{children:[n.jsx("span",{children:"·"}),n.jsx("span",{children:x("work:task.scheduleLast",{when:(()=>{const Pe=Date.now()-new Date(e.scheduleConfig.lastRunAt).getTime(),Ct=Math.floor(Pe/6e4);if(Ct<1)return x("work:task.noteTimeJustNow");if(Ct<60)return x("work:task.noteTimeMinutes",{count:Ct});const ve=Math.floor(Ct/60);return ve<24?x("work:task.noteTimeHours",{count:ve}):x("work:task.noteTimeDays",{count:Math.floor(ve/24)})})()})})]})]})]}),n.jsx("div",{className:"px-6 py-4 border-t border-border-default flex items-center justify-between gap-2",children:n.jsxs("div",{className:"flex gap-2 flex-wrap",children:[e.status==="pending"&&n.jsxs(n.Fragment,{children:[n.jsx("button",{onClick:()=>{if(Sn){Ze(!0);return}Re(()=>ie.tasks.approve(e.id))},disabled:X,className:"px-3 py-1.5 text-xs bg-green-600 hover:bg-green-500 rounded-lg text-white disabled:opacity-50",children:e.createdBy&&!e.createdBy.startsWith("agt_")?x("work:task.startExecution"):x("work:task.approve")}),e.createdBy&&!e.createdBy.startsWith("agt_")?n.jsx("button",{onClick:()=>{Re(()=>ie.tasks.cancel(e.id))},disabled:X,className:"px-3 py-1.5 text-xs text-red-500 border border-red-500/30 rounded-lg hover:bg-red-500/10 disabled:opacity-50",children:x("work:task.cancelTask")}):n.jsx("button",{onClick:()=>Y(!0),disabled:X,className:"px-3 py-1.5 text-xs text-red-500 border border-red-500/30 rounded-lg hover:bg-red-500/10 disabled:opacity-50",children:x("work:task.reject")})]}),e.status==="review"&&n.jsxs(n.Fragment,{children:[n.jsx("button",{onClick:()=>{Re(()=>ie.tasks.accept(e.id,u?.id))},disabled:X,className:"px-3 py-1.5 text-xs bg-green-600 hover:bg-green-500 rounded-lg text-white disabled:opacity-50",children:x("work:task.approveCheck")}),He?n.jsxs("div",{className:"flex items-center gap-1.5",children:[n.jsx("input",{type:"text",value:et,onChange:Pe=>pe(Pe.target.value),onKeyDown:Pe=>{Pe.key==="Enter"&&et.trim()&&(Re(()=>ie.tasks.revision(e.id,et.trim(),u?.id)),Ae(!1),pe(""))},placeholder:x("work:task.revisionReasonPlaceholder"),autoFocus:!0,className:"px-2 py-1 text-xs bg-surface-elevated border border-amber-500/40 rounded-lg text-fg-primary focus:border-amber-400 outline-none w-48"}),n.jsx("button",{onClick:()=>{Re(()=>ie.tasks.revision(e.id,et.trim()||x("work:task.revisionsNeededDefault"),u?.id)),Ae(!1),pe("")},disabled:X,className:"px-2.5 py-1 text-xs bg-amber-600 hover:bg-amber-500 rounded-lg text-white disabled:opacity-50",children:x("common:send")}),n.jsx("button",{onClick:()=>{Ae(!1),pe("")},className:"px-1.5 py-1 text-xs text-fg-secondary hover:text-fg-primary",children:"✕"})]}):n.jsx("button",{onClick:()=>Ae(!0),disabled:X,className:"px-3 py-1.5 text-xs bg-amber-600 hover:bg-amber-500 rounded-lg text-white disabled:opacity-50",children:x("work:task.requestRevision")})]}),Ge&&n.jsxs(n.Fragment,{children:[n.jsxs("button",{onClick:()=>{en()},disabled:X,className:"px-3 py-1.5 text-xs border border-amber-500/30 text-amber-600 rounded-lg hover:bg-amber-500/10 disabled:opacity-50 flex items-center gap-1",children:[n.jsxs("svg",{className:"w-3 h-3",viewBox:"0 0 12 12",fill:"currentColor",children:[n.jsx("rect",{x:"2",y:"1.5",width:"3",height:"9",rx:"0.5"}),n.jsx("rect",{x:"7",y:"1.5",width:"3",height:"9",rx:"0.5"})]}),x("work:task.pause")]}),n.jsxs("button",{onClick:()=>{Ln()},disabled:X,className:"px-3 py-1.5 text-xs border border-blue-500/30 text-blue-600 rounded-lg hover:bg-blue-500/10 disabled:opacity-50 flex items-center gap-1",children:[n.jsxs("svg",{className:"w-3 h-3",viewBox:"0 0 12 12",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:[n.jsx("path",{d:"M1.5 6a4.5 4.5 0 1 1 1.3 3.2",strokeLinecap:"round"}),n.jsx("path",{d:"M1 3.5V6h2.5",strokeLinecap:"round",strokeLinejoin:"round"})]}),x("work:task.retry")]})]}),Ht&&n.jsx("button",{onClick:()=>{vn()},disabled:X,className:"px-3 py-1.5 text-xs bg-green-600 hover:bg-green-500 rounded-lg text-white disabled:opacity-50 flex items-center gap-1",children:X?n.jsx(n.Fragment,{children:x("work:task.resuming")}):n.jsxs(n.Fragment,{children:[n.jsx("svg",{className:"w-3 h-3",viewBox:"0 0 12 12",fill:"currentColor",children:n.jsx("path",{d:"M3 1.5v9l7-4.5-7-4.5z"})}),x("work:task.resume")]})}),zn&&!Sn&&n.jsxs(n.Fragment,{children:[n.jsxs("button",{onClick:()=>{Ln()},disabled:X,className:"px-3 py-1.5 text-xs bg-blue-600 hover:bg-blue-500 rounded-lg text-white disabled:opacity-50 flex items-center gap-1",children:[n.jsxs("svg",{className:"w-3 h-3",viewBox:"0 0 12 12",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:[n.jsx("path",{d:"M1.5 6a4.5 4.5 0 1 1 1.3 3.2",strokeLinecap:"round"}),n.jsx("path",{d:"M1 3.5V6h2.5",strokeLinecap:"round",strokeLinejoin:"round"})]}),x("work:task.retry")]}),n.jsxs("button",{onClick:()=>{Gn()},disabled:X,className:"px-3 py-1.5 text-xs bg-green-600 hover:bg-green-500 rounded-lg text-white disabled:opacity-50 flex items-center gap-1",children:[n.jsx("svg",{className:"w-3 h-3",viewBox:"0 0 12 12",fill:"currentColor",children:n.jsx("path",{d:"M3 1.5v9l7-4.5-7-4.5z"})}),x("work:task.continueTask")]})]}),Sn&&(tn||zn)&&!Dn&&n.jsx("button",{onClick:()=>{Lr()},disabled:X,className:"px-3 py-1.5 text-xs bg-brand-600 hover:bg-brand-500 rounded-lg text-white disabled:opacity-50 flex items-center gap-1.5",children:X?n.jsx(n.Fragment,{children:x("work:task.running")}):n.jsxs(n.Fragment,{children:[n.jsx("svg",{className:"w-3 h-3",viewBox:"0 0 12 12",fill:"currentColor",children:n.jsx("path",{d:"M3 1.5v9l7-4.5-7-4.5z"})}),x("work:task.runNow")]})}),Sn&&!Ge&&!Dn&&!Mn&&(Bn?n.jsx("button",{onClick:()=>{Re(()=>ie.tasks.resumeSchedule(e.id))},disabled:X,className:"px-3 py-1.5 text-xs bg-green-600 hover:bg-green-500 rounded-lg text-white disabled:opacity-50",children:x("work:task.resumeSchedule")}):n.jsx("button",{onClick:()=>{Re(()=>ie.tasks.pauseSchedule(e.id))},disabled:X,className:"px-3 py-1.5 text-xs border border-amber-500/30 text-amber-600 rounded-lg hover:bg-amber-500/10 disabled:opacity-50",children:x("work:task.pauseSchedule")})),(tn||zn||Mn||wn)&&n.jsx("button",{onClick:()=>L(!0),disabled:X,className:"px-3 py-1.5 text-xs bg-gray-600 hover:bg-gray-500 rounded-lg text-white disabled:opacity-50",children:x("work:task.archive")}),tn&&!Sn&&n.jsx("button",{onClick:()=>{Gn()},disabled:X,className:"px-3 py-1.5 text-xs border border-border-default hover:bg-surface-elevated rounded-lg text-fg-secondary disabled:opacity-50",children:x("work:task.reopen")}),!$n&&e.status!=="pending"&&n.jsx("button",{onClick:async()=>{const{count:Pe}=await ie.tasks.getDependentCount(e.id);D({dependentCount:Pe})},disabled:X,className:"px-3 py-1.5 text-xs text-red-500 border border-red-500/30 rounded-lg hover:bg-red-500/10 disabled:opacity-50",children:x("work:task.cancelTask")})]})}),I&&n.jsx(ud,{title:x("work:task.deleteSubtaskTitle",{title:I.title}),message:x("work:task.deleteSubtaskMessage"),confirmLabel:x("common:delete"),onConfirm:()=>{cn(I)},onCancel:()=>z(null)}),V&&n.jsx(ud,{title:x("work:task.rejectConfirmTitle"),message:x("work:task.rejectConfirmMessage"),confirmLabel:x("work:task.reject"),onConfirm:()=>{Y(!1),Re(()=>ie.tasks.reject(e.id))},onCancel:()=>Y(!1)}),F&&n.jsx(ud,{title:x("work:task.archiveConfirmTitle"),message:x(Sn?"work:task.archiveScheduledConfirmMessage":"work:task.archiveConfirmMessage"),confirmLabel:x("work:task.archive"),onConfirm:()=>{L(!1),Re(()=>ie.tasks.archive(e.id))},onCancel:()=>L(!1)}),B&&B.dependentCount>0?n.jsx("div",{className:"fixed inset-0 bg-black/60 flex items-center justify-center z-[60]",onClick:()=>D(null),children:n.jsxs("div",{className:"bg-surface-default border border-border-default rounded-xl p-6 max-w-md w-full shadow-2xl",onClick:Pe=>Pe.stopPropagation(),children:[n.jsx("h3",{className:"text-base font-semibold text-fg-primary mb-2",children:x("work:task.cancelTaskModalTitle")}),n.jsx("p",{className:"text-sm text-fg-secondary mb-4",children:x("work:task.cancelTaskDependent",{count:B.dependentCount})}),n.jsxs("div",{className:"flex flex-col gap-2",children:[n.jsxs("button",{onClick:()=>{D(null),Re(()=>ie.tasks.cancel(e.id,!1))},className:"w-full px-4 py-2.5 text-sm bg-surface-elevated border border-border-default rounded-lg hover:bg-surface-overlay text-fg-primary text-left",children:[n.jsx("span",{className:"font-medium",children:x("work:task.cancelTaskOnly")}),n.jsx("span",{className:"block text-xs text-fg-tertiary mt-0.5",children:x("work:task.cancelTaskOnlyHint")})]}),n.jsxs("button",{onClick:()=>{D(null),Re(()=>ie.tasks.cancel(e.id,!0))},className:"w-full px-4 py-2.5 text-sm bg-red-500/10 border border-red-500/30 rounded-lg hover:bg-red-500/20 text-red-500 text-left",children:[n.jsx("span",{className:"font-medium",children:x("work:task.cancelWithDependents")}),n.jsx("span",{className:"block text-xs text-red-500/70 mt-0.5",children:x("work:task.cancelWithDependentsHint",{count:B.dependentCount})})]}),n.jsx("button",{onClick:()=>D(null),className:"w-full px-4 py-2 text-sm text-fg-tertiary hover:text-fg-secondary",children:x("work:task.keepTaskRunning")})]})]})}):B&&n.jsx(ud,{title:x("work:task.cancelTaskModalTitle"),message:x("work:task.cancelConfirmMessage"),confirmLabel:x("work:task.cancelTask"),onConfirm:()=>{D(null),Re(()=>ie.tasks.cancel(e.id))},onCancel:()=>D(null)}),mt&&n.jsx(Wre,{filePath:mt,onClose:()=>it(null),onOpenExternal:()=>{it(null),ie.deliverables.search({taskId:e.id,limit:100}).then(({results:Pe})=>{const Ct=Pe.find(ve=>ve.reference===mt);Ct?bt.navigate(De.DELIVERABLES,{openDeliverable:Ct.id}):bt.navigate(De.DELIVERABLES)}).catch(()=>bt.navigate(De.DELIVERABLES))}}),Ye&&e.scheduleConfig&&n.jsx("div",{className:"fixed inset-0 bg-black/60 flex items-center justify-center z-[60]",onClick:()=>Ze(!1),children:n.jsxs("div",{className:"bg-surface-secondary border border-border-default rounded-xl p-6 w-[380px] shadow-2xl",onClick:Pe=>Pe.stopPropagation(),children:[n.jsx("h3",{className:"font-semibold text-base mb-2",children:x("work:task.scheduleApproveTitle")}),n.jsx("p",{className:"text-sm text-fg-secondary mb-5 leading-relaxed",children:x("work:task.scheduleApproveDesc",{schedule:e.scheduleConfig.cron?`Cron: ${e.scheduleConfig.cron}`:e.scheduleConfig.every?x("work:task.scheduleEvery",{interval:e.scheduleConfig.every}):"",nextRun:e.scheduleConfig.nextRunAt?new Date(e.scheduleConfig.nextRunAt).toLocaleString():x("work:task.scheduleNA")})}),n.jsxs("div",{className:"flex flex-col gap-2",children:[n.jsx("button",{disabled:X,onClick:()=>{Ze(!1),Re(()=>ie.tasks.approve(e.id,!0))},className:"w-full px-4 py-2.5 text-sm bg-green-600 hover:bg-green-500 text-white rounded-lg font-medium transition-colors disabled:opacity-50",children:x("work:task.scheduleApproveRunNow")}),n.jsx("button",{disabled:X,onClick:()=>{Ze(!1),Re(()=>ie.tasks.approve(e.id,!1))},className:"w-full px-4 py-2.5 text-sm bg-brand-600 hover:bg-brand-500 text-white rounded-lg font-medium transition-colors disabled:opacity-50",children:x("work:task.scheduleApproveWait")}),n.jsx("button",{onClick:()=>Ze(!1),className:"w-full px-4 py-2 text-sm text-fg-tertiary hover:text-fg-secondary",children:x("common:cancel")})]})]})})]})}function Gre({project:e,tasks:t,requirements:r,agents:s,onDeleteProject:a,onUpdateProject:i,onRefresh:l}){const d=g.useMemo(()=>t.filter(B=>B.projectId===e.id),[t,e.id]),u=g.useMemo(()=>r.filter(B=>B.projectId===e.id),[r,e.id]),m=g.useMemo(()=>{const B={total:d.length,completed:0,inProgress:0,inReview:0,blocked:0,pending:0,failed:0,reqs:u.length,reqsDone:0};for(const D of d)D.status==="completed"||D.status==="accepted"?B.completed++:D.status==="in_progress"?B.inProgress++:D.status==="review"||D.status==="revision"?B.inReview++:D.status==="blocked"?B.blocked++:D.status==="failed"?B.failed++:B.pending++;for(const D of u)D.status==="completed"&&B.reqsDone++;return B},[d,u]),h=g.useMemo(()=>new Set(d.map(B=>B.assignedAgentId).filter(Boolean)),[d]),p=g.useMemo(()=>s.filter(B=>h.has(B.id)),[s,h]),[y,x]=g.useState(!1),[v,j]=g.useState(""),[C,w]=g.useState("main"),[N,S]=g.useState(!1),{t:T}=pt(["work","common"]),E=[{value:"active",label:T("work:project.statusActive"),desc:T("work:project.statusActiveDesc")},{value:"paused",label:T("work:project.statusPaused"),desc:T("work:project.statusPausedDesc")},{value:"archived",label:T("work:project.statusArchived"),desc:T("work:project.statusArchivedDesc")}],R=async B=>{if(B!==e.status){S(!0);try{await i({status:B}),l()}finally{S(!1)}}},I=async()=>{const B=v.trim();if(!B)return;const D=[...e.repositories??[],{url:"",localPath:B,defaultBranch:C||"main"}];await i({repositories:D}),j(""),w("main"),x(!1),l()},z=async B=>{const D=(e.repositories??[]).filter((V,Y)=>Y!==B);await i({repositories:D}),l()};return n.jsxs("div",{className:"p-5 space-y-5 max-w-3xl",children:[n.jsxs("div",{className:"space-y-3",children:[n.jsx(Ore,{value:e.description??"",onSave:async B=>{await i({description:B}),l()},className:"text-sm text-fg-secondary",placeholder:T("work:project.descriptionPlaceholderLong")}),n.jsxs("div",{className:"flex items-center gap-3 text-xs text-fg-tertiary",children:[e.createdAt&&n.jsxs("span",{children:[T("work:project.createdLabel")," ",new Date(e.createdAt).toLocaleDateString()]}),e.updatedAt&&n.jsxs("span",{children:[T("work:project.updatedLabel")," ",new Date(e.updatedAt).toLocaleDateString()]})]})]}),n.jsxs("div",{className:"bg-surface-elevated rounded-xl p-4",children:[n.jsx("h4",{className:"text-xs font-semibold text-fg-secondary mb-3",children:T("work:project.projectStatusHeading")}),n.jsx("div",{className:"flex gap-2",children:E.map(B=>n.jsxs("button",{disabled:N,onClick:()=>R(B.value),className:`flex-1 px-3 py-2 rounded-lg text-xs font-medium transition-all ${e.status===B.value?B.value==="active"?"bg-green-500/15 text-green-600 ring-1 ring-green-500/30":B.value==="paused"?"bg-amber-500/15 text-amber-600 ring-1 ring-amber-500/30":"bg-gray-500/15 text-fg-tertiary ring-1 ring-gray-500/30":"bg-surface-elevated text-fg-tertiary hover:text-fg-secondary hover:bg-surface-overlay"} ${N?"opacity-50 cursor-not-allowed":"cursor-pointer"}`,children:[n.jsx("div",{children:B.label}),n.jsx("div",{className:"text-[10px] opacity-70 mt-0.5",children:B.desc})]},B.value))})]}),n.jsxs("div",{className:"bg-surface-elevated rounded-xl p-4",children:[n.jsx("h4",{className:"text-xs font-semibold text-fg-secondary mb-3",children:T("work:project.taskOverview")}),n.jsxs("div",{className:"grid grid-cols-3 sm:grid-cols-6 gap-3",children:[n.jsx(Co,{label:T("work:project.statTotal"),value:m.total,color:"text-fg-primary"}),n.jsx(Co,{label:T("work:project.statCompleted"),value:m.completed,color:"text-green-600"}),n.jsx(Co,{label:T("work:project.statInProgress"),value:m.inProgress,color:"text-brand-500"}),n.jsx(Co,{label:T("work:project.statInReview"),value:m.inReview,color:"text-brand-500"}),n.jsx(Co,{label:T("work:project.statBlocked"),value:m.blocked,color:"text-amber-600"}),n.jsx(Co,{label:T("work:project.statFailed"),value:m.failed,color:"text-red-500"})]}),m.total>0&&n.jsxs("div",{className:"mt-3 flex h-2 rounded-full overflow-hidden bg-surface-elevated",children:[m.completed>0&&n.jsx("div",{className:"bg-green-500",style:{width:`${m.completed/m.total*100}%`}}),m.inProgress>0&&n.jsx("div",{className:"bg-brand-500",style:{width:`${m.inProgress/m.total*100}%`}}),m.inReview>0&&n.jsx("div",{className:"bg-brand-500",style:{width:`${m.inReview/m.total*100}%`}}),m.blocked>0&&n.jsx("div",{className:"bg-amber-500",style:{width:`${m.blocked/m.total*100}%`}}),m.pending>0&&n.jsx("div",{className:"bg-blue-500/40",style:{width:`${m.pending/m.total*100}%`}}),m.failed>0&&n.jsx("div",{className:"bg-red-500",style:{width:`${m.failed/m.total*100}%`}})]})]}),n.jsxs("div",{className:"bg-surface-elevated rounded-xl p-4",children:[n.jsx("h4",{className:"text-xs font-semibold text-fg-secondary mb-3",children:T("work:project.requirementsHeading")}),n.jsxs("div",{className:"grid grid-cols-3 gap-3",children:[n.jsx(Co,{label:T("work:project.statTotal"),value:m.reqs,color:"text-fg-primary"}),n.jsx(Co,{label:T("work:project.statCompleted"),value:m.reqsDone,color:"text-green-600"}),n.jsx(Co,{label:T("work:project.statActive"),value:m.reqs-m.reqsDone,color:"text-brand-500"})]})]}),p.length>0&&n.jsxs("div",{className:"bg-surface-elevated rounded-xl p-4",children:[n.jsx("h4",{className:"text-xs font-semibold text-fg-secondary mb-3",children:T("work:project.agentsHeading",{count:p.length})}),n.jsx("div",{className:"flex flex-wrap gap-2",children:p.map(B=>{const D=d.filter(Y=>Y.assignedAgentId===B.id),V=D.filter(Y=>!["completed","failed","cancelled","archived"].includes(Y.status));return n.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 bg-surface-elevated/60 rounded-lg",children:[n.jsx("span",{className:`w-2 h-2 rounded-full shrink-0 ${B.status==="working"?"bg-blue-500":B.status==="idle"?"bg-green-500":"bg-gray-500"}`}),n.jsx("span",{className:"text-xs text-fg-secondary",children:B.name}),n.jsx("span",{className:"text-[10px] text-fg-tertiary",children:T("work:project.agentTaskCounts",{active:V.length,total:D.length})})]},B.id)})})]}),n.jsxs("div",{className:"bg-surface-elevated rounded-xl p-4",children:[n.jsxs("div",{className:"flex items-center justify-between mb-3",children:[n.jsx("h4",{className:"text-xs font-semibold text-fg-secondary",children:T("work:project.repositories")}),n.jsx("button",{onClick:()=>x(!y),className:"text-[10px] text-brand-500 hover:text-brand-500",children:T(y?"common:cancel":"work:project.addRepo")})]}),(e.repositories??[]).length===0&&!y&&n.jsx("p",{className:"text-xs text-fg-tertiary",children:T("work:project.noReposLinked")}),(e.repositories??[]).map((B,D)=>n.jsxs("div",{className:"flex items-center gap-2 py-1.5 group",children:[n.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"text-fg-tertiary shrink-0",children:[n.jsx("path",{d:"M15 22v-4a4.8 4.8 0 0 0-1-3.5c3 0 6-2 6-5.5.08-1.25-.27-2.48-1-3.5.28-1.15.28-2.35 0-3.5 0 0-1 0-3 1.5-2.64-.5-5.36-.5-8 0C6 2 5 2 5 2c-.3 1.15-.3 2.35 0 3.5A5.403 5.403 0 0 0 4 9c0 3.5 3 5.5 6 5.5-.39.49-.68 1.05-.85 1.65-.17.6-.22 1.23-.15 1.85v4"}),n.jsx("path",{d:"M9 18c-4.51 2-5-2-7-2"})]}),n.jsx("span",{className:"text-xs text-fg-secondary flex-1 min-w-0 truncate",children:B.url||B.localPath}),n.jsx("span",{className:"text-[10px] text-fg-tertiary shrink-0",children:B.defaultBranch}),n.jsx("button",{onClick:()=>z(D),className:"text-fg-tertiary hover:text-red-500 opacity-0 group-hover:opacity-100 transition-opacity shrink-0",title:T("work:project.removeRepo"),children:n.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[n.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),n.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]},D)),y&&n.jsxs("div",{className:"mt-2 space-y-2 p-3 bg-surface-elevated rounded-lg border border-border-default",children:[n.jsx("input",{value:v,onChange:B=>j(B.target.value),placeholder:T("work:project.repoPathPlaceholder"),className:"w-full px-2.5 py-1.5 text-xs bg-surface-primary border border-border-default rounded-md text-fg-primary placeholder:text-fg-tertiary"}),n.jsxs("div",{className:"flex gap-2",children:[n.jsx("input",{value:C,onChange:B=>w(B.target.value),placeholder:T("work:project.repoBranchPlaceholder"),className:"flex-1 px-2.5 py-1.5 text-xs bg-surface-primary border border-border-default rounded-md text-fg-primary placeholder:text-fg-tertiary"}),n.jsx("button",{onClick:I,disabled:!v.trim(),className:"px-3 py-1.5 text-xs bg-brand-600 text-white rounded-md hover:bg-brand-700 disabled:opacity-40 disabled:cursor-not-allowed transition-colors",children:T("work:task.add")})]})]})]}),n.jsxs("div",{className:"border border-red-500/20 rounded-xl p-4",children:[n.jsx("h4",{className:"text-xs font-semibold text-red-500/80 mb-2",children:T("work:project.dangerZone")}),n.jsx("p",{className:"text-[11px] text-fg-tertiary mb-3",children:T("work:project.dangerZoneDeleteHint")}),n.jsx("button",{onClick:a,className:"px-3 py-1.5 text-xs text-red-500 border border-red-500/30 hover:bg-red-500/10 rounded-lg transition-colors",children:T("work:project.deleteProject")})]})]})}function Co({label:e,value:t,color:r}){return n.jsxs("div",{className:"text-center py-2",children:[n.jsx("div",{className:`text-xl font-bold ${r}`,children:t}),n.jsx("div",{className:"text-[10px] text-fg-tertiary mt-0.5",children:e})]})}const nC={pending:"todo",in_progress:"in_progress",completed:"done",rejected:"closed",cancelled:"closed",archived:"closed"},rC={failed:"rejected",todo:"pending",in_progress:"in_progress",review:"in_progress",done:"completed",closed:"cancelled"},Yre={urgent:0,high:1,medium:2,low:3},z3={failed:0,todo:1,in_progress:2,review:3,done:4,closed:5},$3={failed:"border-l-red-500 bg-red-500/5",todo:"border-l-blue-500 bg-blue-500/5",in_progress:"border-l-brand-500 bg-brand-500/5",review:"border-l-purple-500 bg-brand-500/5",done:"border-l-green-500 bg-green-500/5",closed:"border-l-gray-500 bg-gray-500/5"},Xre={failed:"border-l-red-500 text-red-500",todo:"border-l-blue-500 text-blue-600",in_progress:"border-l-brand-500 text-brand-500",review:"border-l-purple-500 text-brand-500",done:"border-l-green-500 text-green-600",closed:"border-l-gray-500 text-fg-tertiary"},Qre=["pending","in_progress","completed","rejected","cancelled","archived"];function Zre(e){for(const t of Ry)if(t.statuses.includes(e))return t.id;return"closed"}function B3(e,t){const r=Date.now()-new Date(e).getTime(),s=Math.floor(r/6e4);if(s<1)return t("work:relative.justNow");if(s<60)return t("work:relative.minutesAgo",{count:s});const a=Math.floor(s/60);if(a<24)return t("work:relative.hoursAgo",{count:a});const i=Math.floor(a/24);return t("work:relative.daysAgo",{count:i})}function Cf({value:e,options:t,onSelect:r,allowedValues:s}){const[a,i]=g.useState(!1),l=g.useRef(null),d=g.useRef(null),u=t.find(m=>m.value===e);return g.useEffect(()=>{if(!a)return;const m=h=>{d.current&&!d.current.contains(h.target)&&l.current&&!l.current.contains(h.target)&&i(!1)};return document.addEventListener("mousedown",m),()=>document.removeEventListener("mousedown",m)},[a]),n.jsxs("div",{className:"relative",children:[n.jsx("button",{ref:l,onClick:()=>i(m=>!m),className:`text-[11px] px-2 py-0.5 rounded-full font-medium transition-colors cursor-pointer hover:ring-1 hover:ring-current/30 ${u?.cls??"bg-gray-500/15 text-fg-tertiary"}`,children:u?.label??e}),a&&n.jsx("div",{ref:d,className:"absolute top-full left-0 mt-1 w-40 bg-surface-overlay border border-border-default rounded-lg shadow-xl z-50 py-1 max-h-64 overflow-y-auto",children:t.map(m=>{const h=m.value===e,p=h||!s||s.has(m.value);return n.jsxs("button",{disabled:!p,onClick:()=>{!h&&p&&r(m.value),i(!1)},className:`w-full text-left px-3 py-1.5 text-[11px] flex items-center gap-2 transition-colors ${h?"bg-surface-elevated":p?"hover:bg-surface-elevated/60":"opacity-35 cursor-not-allowed"}`,children:[n.jsx("span",{className:`inline-block w-2 h-2 rounded-full shrink-0 ${p?m.cls.split(" ")[0]:"bg-gray-600"}`}),n.jsx("span",{className:`font-medium ${h?"text-fg-primary":p?"text-fg-secondary":"text-fg-muted"}`,children:m.label}),h&&n.jsx("svg",{className:"w-3 h-3 ml-auto text-brand-500",viewBox:"0 0 12 12",fill:"none",children:n.jsx("path",{d:"M2 6l3 3 5-5",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})]},m.value)})})]})}function H3({row:e,idx:t,dragIdx:r,agentMap:s,projMap:a,onTaskClick:i,onReqClick:l,onRowDragStart:d,onRowDragEnd:u,handleStatusChange:m,handlePriorityChange:h,selected:p,isMobile:y,isAbnormalBlocked:x}){const{t:v}=pt(["work","common"]),j=g.useMemo(()=>eC(v),[v]),C=g.useMemo(()=>Iy(v),[v]),w=g.useMemo(()=>Fre(v),[v]),N=e.data.status,S=e.data.priority,T=e.kind==="task"?s.get(e.data.assignedAgentId??""):void 0,E=(()=>{const I=a.get((e.kind==="task",e.data.projectId??""));return I&&I.name!=="default"?I:void 0})(),R=e.kind==="req"?n.jsx("span",{className:"text-[9px] px-1.5 py-0.5 rounded font-semibold bg-amber-500/15 text-amber-600",children:v("work:task.requirementShort")}):e.data.taskType==="scheduled"?n.jsx("span",{className:"text-[9px] px-1.5 py-0.5 rounded font-semibold bg-blue-500/15 text-blue-600",children:v("work:task.schedShort")}):n.jsx("span",{className:"text-[9px] px-1.5 py-0.5 rounded font-semibold bg-gray-500/15 text-fg-secondary",children:v("work:task.taskShort")});return y?n.jsxs("div",{onClick:()=>e.kind==="task"?i(e.data):l(e.data),className:`px-3 py-2 border-b border-border-default/40 cursor-pointer transition-colors border-l-2 ${$3[e.group]??"border-l-gray-700"} ${p?"bg-brand-500/10 border-l-brand-500":"active:bg-surface-elevated/50"}`,children:[n.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[R,x&&n.jsx("span",{className:"text-[9px] px-1.5 py-0.5 rounded font-semibold bg-red-500/15 text-red-500",children:"⚠"}),n.jsx("span",{className:"text-sm text-fg-primary truncate flex-1",children:e.data.title})]}),n.jsxs("div",{className:"flex items-center gap-2 mt-1.5 flex-wrap",children:[n.jsx("div",{onClick:I=>I.stopPropagation(),children:n.jsx(Cf,{value:N,options:e.kind==="task"?R3.map(I=>({value:I,label:j[I]?.label??I,cls:j[I]?.cls??"bg-gray-500/15 text-fg-tertiary"})):I3.map(I=>({value:I,label:C[I]?.label??I,cls:C[I]?.cls??"bg-gray-500/15 text-fg-tertiary"})),allowedValues:e.kind==="task"?L3[N]:y1[N],onSelect:I=>{m(e,I)}})}),n.jsx("div",{onClick:I=>I.stopPropagation(),children:n.jsx(Cf,{value:S,options:D3.map(I=>({value:I,label:w[I]?.label??I,cls:w[I]?.cls??"bg-gray-500/15 text-fg-tertiary"})),onSelect:I=>{h(e,I)}})}),T&&n.jsxs("span",{className:"flex items-center gap-1 text-[10px]",children:[n.jsx("span",{className:`w-1.5 h-1.5 rounded-full shrink-0 ${j0[T.status]??"bg-gray-500"}`}),n.jsx("span",{className:`${P3[T.status]??"text-fg-secondary"}`,children:T.name})]}),E?.name&&n.jsx("span",{className:"text-[10px] text-brand-400/70 truncate max-w-[80px]",children:E.name}),n.jsx("span",{className:"text-[9px] text-fg-muted ml-auto",children:B3(e.data.updatedAt??"",v)})]})]}):n.jsxs("div",{draggable:!0,onDragStart:I=>d(I,t),onDragEnd:u,onClick:()=>e.kind==="task"?i(e.data):l(e.data),className:`flex items-center gap-2 px-6 py-2 border-b border-border-default/40 cursor-pointer transition-colors border-l-2 ${$3[e.group]??"border-l-gray-700"} ${r===t?"opacity-40":""} ${p?"bg-brand-500/10 border-l-brand-500 hover:bg-brand-500/15":"hover:bg-surface-elevated/50"}`,children:[n.jsx("div",{className:"w-12 shrink-0",children:R}),n.jsxs("div",{className:"flex-1 min-w-[200px] text-sm text-fg-primary truncate flex items-center gap-1.5",children:[n.jsx("span",{className:"truncate",children:e.data.title}),x&&n.jsx("span",{className:"text-[9px] px-1.5 py-0.5 rounded font-semibold bg-red-500/15 text-red-500 shrink-0",children:"⚠"})]}),n.jsx("div",{className:"w-[130px] shrink-0",onClick:I=>I.stopPropagation(),children:n.jsx(Cf,{value:N,options:e.kind==="task"?R3.map(I=>({value:I,label:j[I]?.label??I,cls:j[I]?.cls??"bg-gray-500/15 text-fg-tertiary"})):I3.map(I=>({value:I,label:C[I]?.label??I,cls:C[I]?.cls??"bg-gray-500/15 text-fg-tertiary"})),allowedValues:e.kind==="task"?L3[N]:y1[N],onSelect:I=>{m(e,I)}})}),n.jsx("div",{className:"w-[100px] shrink-0",onClick:I=>I.stopPropagation(),children:n.jsx(Cf,{value:S,options:D3.map(I=>({value:I,label:w[I]?.label??I,cls:w[I]?.cls??"bg-gray-500/15 text-fg-tertiary"})),onSelect:I=>{h(e,I)}})}),n.jsx("div",{className:"w-[120px] shrink-0 text-[11px] truncate",children:T?n.jsxs("span",{className:"flex items-center gap-1.5",children:[n.jsx("span",{className:`w-1.5 h-1.5 rounded-full shrink-0 ${j0[T.status]??"bg-gray-500"}`}),n.jsx("span",{className:`font-medium ${P3[T.status]??"text-fg-secondary"}`,children:T.name})]}):n.jsx("span",{className:"text-fg-muted",children:"—"})}),n.jsx("div",{className:"w-[120px] shrink-0 text-[11px] truncate",children:E?.name?n.jsx("span",{className:"text-brand-400/70",children:E.name}):n.jsx("span",{className:"text-fg-muted",children:"—"})}),n.jsx("div",{className:"w-[90px] shrink-0 text-[10px] text-fg-muted text-right",children:B3(e.data.updatedAt??"",v)})]})}function Jre({tasks:e,requirements:t,agents:r,projects:s,onTaskClick:a,onReqClick:i,onRefresh:l,selectedTaskId:d,selectedReqId:u}){const{t:m}=pt(["work","common"]),h=Rs(),[p,y]=g.useState("status"),[x,v]=g.useState(null),[j,C]=g.useState(null),w=g.useMemo(()=>{const $=new Map;for(const W of e)$.set(W.id,W);return $},[e]),N=g.useCallback($=>$.status!=="blocked"?!1:!$.blockedBy||$.blockedBy.length===0?!0:$.blockedBy.every(W=>{const U=w.get(W);return U&&U.status==="completed"}),[w]),S=g.useMemo(()=>{const $=[];for(const W of e){const U=Zre(W.status);$.push({kind:"task",data:W,group:U,groupOrder:z3[U]??5})}for(const W of t){const U=nC[W.status]??"todo";$.push({kind:"req",data:W,group:U,groupOrder:z3[U]??5})}if(p==="status")$.sort((W,U)=>{if(W.groupOrder!==U.groupOrder)return W.groupOrder-U.groupOrder;const H=new Date(W.data.updatedAt??0).getTime();return new Date(U.data.updatedAt??0).getTime()-H});else{const W=U=>Yre[U.data.priority]??2;$.sort((U,H)=>{const q=W(U),Z=W(H);return q!==Z?q-Z:new Date(H.data.updatedAt??0).getTime()-new Date(U.data.updatedAt??0).getTime()})}return $},[e,t,p]),T=async($,W)=>{try{$.kind==="task"?await ie.tasks.updateStatus($.data.id,W):await ie.requirements.updateStatus($.data.id,W),l()}catch{}},E=async($,W)=>{try{$.kind==="task"?await ie.tasks.update($.data.id,{priority:W}):await ie.requirements.update($.data.id,{priority:W}),l()}catch{}},R=($,W)=>{v(W),$.dataTransfer.effectAllowed="move",$.dataTransfer.setData("text/plain",String(W)),$.currentTarget.style.opacity="0.4"},I=$=>{$.currentTarget.style.opacity="1",v(null),C(null)},z=($,W)=>{$.preventDefault(),$.dataTransfer.dropEffect="move",j!==W&&C(W)},B=async($,W)=>{if($.preventDefault(),C(null),x==null)return;const U=S[x];if(!U||U.group===W)return;const H=Ry.find(q=>q.id===W);if(H){try{if(U.kind==="task"){if(U.data.status==="pending")return;await ie.tasks.updateStatus(U.data.id,H.dropStatus)}else{const q=rC[W];q&&await ie.requirements.updateStatus(U.data.id,q)}l()}catch{}v(null)}},D=g.useMemo(()=>new Map(r.map($=>[$.id,$])),[r]),V=g.useMemo(()=>new Map(s.map($=>[$.id,$])),[s]),Y=["todo","in_progress","review","done"],F=g.useMemo(()=>{const $={};for(const W of S)$[W.group]=($[W.group]??0)+1;return $},[S]),{rowsByGroup:L,rowIndexMap:O}=g.useMemo(()=>{const $=new Map,W=new Map;for(let U=0;U<S.length;U++){const H=S[U];W.set(H,U);const q=$.get(H.group)??[];q.push(H),$.set(H.group,q)}return{rowsByGroup:$,rowIndexMap:W}},[S]),M=g.useMemo(()=>{if(p!=="status")return null;const $=new Set(S.map(H=>H.group)),W=[],U=new Set;$.has("failed")&&(W.push("failed"),U.add("failed"));for(const H of Y)W.push(H),U.add(H);for(const H of S)U.has(H.group)||(W.push(H.group),U.add(H.group));return W},[S,p]);return n.jsx("div",{className:`flex-1 min-h-0 overflow-auto bg-surface-primary ${h?"overflow-x-hidden w-full":""}`,children:n.jsxs("div",{className:h?"w-full":"w-fit min-w-full",children:[!h&&n.jsxs("div",{className:"flex items-center gap-2 px-6 py-2 border-b border-border-default text-[10px] font-semibold text-fg-tertiary uppercase tracking-wider sticky top-0 z-20 bg-surface-primary",children:[n.jsx("div",{className:"w-12 shrink-0 text-fg-muted normal-case font-normal",children:S.length}),n.jsx("div",{className:"flex-1 min-w-[200px]",children:m("work:task.backlogTitle")}),n.jsxs("button",{onClick:()=>y("status"),className:`w-[130px] shrink-0 text-left flex items-center gap-1 transition-colors ${p==="status"?"text-brand-500":"hover:text-fg-secondary"}`,children:[m("work:filters.status")," ",p==="status"&&n.jsx("span",{className:"text-[8px]",children:"▼"})]}),n.jsxs("button",{onClick:()=>y("priority"),className:`w-[100px] shrink-0 text-left flex items-center gap-1 transition-colors ${p==="priority"?"text-brand-500":"hover:text-fg-secondary"}`,children:[m("work:filters.priority")," ",p==="priority"&&n.jsx("span",{className:"text-[8px]",children:"▼"})]}),n.jsx("div",{className:"w-[120px] shrink-0",children:m("work:filters.assignee")}),n.jsx("div",{className:"w-[120px] shrink-0",children:m("work:task.projectLabel")}),n.jsx("div",{className:"w-[90px] shrink-0 text-right",children:m("work:task.backlogUpdated")})]}),n.jsxs("div",{children:[p==="status"&&M?M.map($=>{const W=L.get($)??[];return n.jsxs("div",{children:[n.jsxs("div",{className:`flex items-center gap-2 px-6 py-2 border-l-2 bg-surface-primary/80 sticky top-0 z-10 ${Xre[$]??""} ${j===$?"ring-1 ring-brand-500/40":""}`,onDragOver:U=>z(U,$),onDragLeave:()=>C(null),onDrop:U=>{B(U,$)},children:[n.jsx("span",{className:"text-[11px] font-semibold uppercase tracking-wider",children:m(`work:boardColumn.${$}`)}),n.jsx("span",{className:"text-[10px] text-fg-tertiary",children:F[$]??0})]}),W.map(U=>n.jsx(H3,{row:U,idx:O.get(U)??0,dragIdx:x,agentMap:D,projMap:V,onTaskClick:a,onReqClick:i,onRowDragStart:R,onRowDragEnd:I,handleStatusChange:T,handlePriorityChange:E,selected:U.kind==="task"?U.data.id===d:U.data.id===u,isMobile:h,isAbnormalBlocked:U.kind==="task"?N(U.data):!1},`${U.kind}-${U.data.id}`))]},$)}):S.map(($,W)=>n.jsx(H3,{row:$,idx:W,dragIdx:x,agentMap:D,projMap:V,onTaskClick:a,onReqClick:i,onRowDragStart:R,onRowDragEnd:I,handleStatusChange:T,handlePriorityChange:E,selected:$.kind==="task"?$.data.id===d:$.data.id===u,isMobile:h,isAbnormalBlocked:$.kind==="task"?N($.data):!1},`${$.kind}-${$.data.id}`)),S.length===0&&n.jsx("div",{className:"flex items-center justify-center py-16 text-sm text-fg-tertiary",children:m("work:task.noItems")})]})]})})}function F3({authUser:e,previewMode:t,previewData:r}={}){const{t:s}=pt(["work","common"]),a=Id(De.WORK),i=g.useMemo(()=>Ry.map(oe=>({...oe,label:s(`work:boardColumn.${oe.id}`)})),[s]),l=g.useMemo(()=>tC(s),[s]),d=g.useMemo(()=>Iy(s),[s]),u=Rs(),m=g.useRef(null),[h,p]=g.useState(0);g.useEffect(()=>{const oe=m.current;if(!oe)return;const Qe=new ResizeObserver(([dt])=>p(dt.contentRect.width));return Qe.observe(oe),p(oe.clientWidth),()=>Qe.disconnect()},[]);const y=h||window.innerWidth,x=g.useRef(!1),v=f0({side:"right",defaultWidth:Math.round(y/2),minWidth:380,maxWidth:Math.round(y*.8),storageKey:"markus_projects_detail_v4"});g.useEffect(()=>{h>0&&!x.current&&(x.current=!0,v.setWidth(Math.round(h/2)))},[h]);const[j,C]=g.useState(!1),w=g.useRef(j);w.current=j;const[N,S]=g.useState(r?.projects??[]),[T,E]=g.useState("all"),[R,I]=g.useState(null),[z,B]=g.useState(r?.board??{}),[D,V]=g.useState(r?.agents??[]),[Y,F]=g.useState(r?.users??[]),[L,O]=g.useState(r?.allRequirements??[]),[M,$]=g.useState(!r),[W,U]=g.useState(""),[H,q]=g.useState(!1),[Z,_]=g.useState(null),J=g.useCallback(()=>{tt(R??""),$n(!0)},[R]),[X,ee]=g.useState(!1),[te,G]=g.useState(!1),[ue,Se]=g.useState(""),[Ce,Be]=g.useState(""),[Ne,he]=g.useState("medium"),[_e,Ee]=g.useState(""),[Ye,Ze]=g.useState(""),[mt,it]=g.useState(""),[Lt,ht]=g.useState(""),[ne,me]=g.useState([]),[be,se]=g.useState("standard"),[fe,He]=g.useState("4h"),[Ae,et]=g.useState(""),[pe,Fe]=g.useState(null),[Ve,nt]=g.useState(()=>r?.initialSelectedReqId&&r.allRequirements?r.allRequirements.find(oe=>oe.id===r.initialSelectedReqId)??null:null),[gt,rt]=g.useState(new Set),[Et,je]=g.useState(!1),[Re,We]=g.useState(new Set),Vt=g.useRef(new Set),ln=g.useRef(new Set),[en,vn]=g.useState(null),[In,Zt]=g.useState(r?.initialBoardType??"backlog"),cn=g.useMemo(()=>[{id:"backlog"},{id:"kanban"},{id:"dag"}],[]),Gn=Sl(cn,In,Zt),Ln=g.useRef(null),Lr=g.useMemo(()=>({scrollContainerRef:Ln}),[]),Qr=Sl(cn,In,Zt,Lr),[mr,Ge]=g.useState(!1),[Ht,Wt]=g.useState(null),[tn,zn]=g.useState(!1),Mn=g.useRef(null),wn=g.useRef(null),[Dn,$n]=g.useState(!1),[Sn,Bn]=g.useState(""),[Vn,Qn]=g.useState(""),[Pe,Ct]=g.useState("medium"),[ve,tt]=g.useState(""),[Tt,$t]=g.useState(null),[sn,Zn]=g.useState(""),[Xt,ye]=g.useState(""),[lt,vt]=g.useState(""),[Bt,dn]=g.useState(null),Dt=oe=>{U(oe),setTimeout(()=>U(""),3e3)},Pn=N.find(oe=>oe.id===R)??null,tr=Pn??N.find(oe=>oe.id===Z)??null,Hn=g.useCallback(()=>{q(!1),_(null)},[]),nr=g.useCallback(oe=>{if(H&&(R===oe||Z===oe)){Hn();return}R||_(oe),q(!0)},[H,R,Z,Hn]);g.useEffect(()=>{ln.current=Re},[Re]);const On=g.useCallback(async()=>{try{const{projects:oe}=await ie.projects.list();S(oe)}catch{}},[]),on=g.useCallback(async()=>{const oe={};T==="project"&&R&&(oe.projectId=R);try{const{board:Qe}=await ie.tasks.board(oe);B(Qe)}catch{}},[T,R]),cr=g.useCallback(async()=>{try{const{agents:oe}=await ie.agents.list();V(oe)}catch{}},[]),Fr=g.useCallback(async()=>{try{const{users:oe}=await ie.users.list(e?.orgId);F(oe)}catch{}},[e?.orgId]),dr=g.useCallback(async()=>{try{const{requirements:oe}=await ie.requirements.list({});O(oe)}catch{}},[]),br=g.useCallback(async()=>{await Promise.all([On(),on(),cr(),Fr(),dr()]),$(!1)},[On,on,cr,Fr,dr]);g.useEffect(()=>{t||br()},[t,br]),g.useEffect(()=>{!t||!r||(S(r.projects??[]),B(r.board??{}),V(r.agents??[]),F(r.users??[]),O(r.allRequirements??[]))},[t,r]);const fr=g.useCallback(oe=>{Fe(Qe=>Qe?.id===oe.id?(u&&w.current&&C(!1),null):(u&&(C(!0),history.pushState({mobileDetail:De.WORK},"",window.location.hash)),oe)),nt(null)},[u]),Is=g.useCallback(oe=>{nt(Qe=>Qe?.id===oe.id?(u&&w.current&&C(!1),null):(u&&(C(!0),history.pushState({mobileDetail:De.WORK},"",window.location.hash)),oe)),Fe(null)},[u]),ga=g.useCallback(()=>{Fe(null),nt(null),u&&w.current&&C(!1)},[u]),xa=g.useCallback(()=>{Fe(null),!ti.current&&u&&w.current&&C(!1)},[u]);g.useEffect(()=>{if(!u)return;const oe=()=>{w.current&&(C(!1),Fe(null),nt(null))};return window.addEventListener("popstate",oe),()=>window.removeEventListener("popstate",oe)},[u]);const Pr=g.useRef(pe);Pr.current=pe;const ti=g.useRef(Ve);ti.current=Ve,g.useEffect(()=>{const oe=Qe=>{if(Qe.key!=="Escape")return;const dt=Qe.target?.tagName;if(!(dt==="INPUT"||dt==="TEXTAREA"||dt==="SELECT")){if(Pr.current){Fe(null);return}if(ti.current){nt(null);return}}};return window.addEventListener("keydown",oe),()=>window.removeEventListener("keydown",oe)},[]),g.useEffect(()=>{if(t||!a)return;const oe=Pr.current?12e4:45e3,Qe=setInterval(()=>{on(),cr(),dr()},oe);let dt=null;const Rt=()=>{dt||(dt=setTimeout(()=>{dt=null,on()},800))};let fn=null;const hr=()=>{fn||(fn=setTimeout(()=>{fn=null,dr()},800))},un=pn.on("task:update",os=>{Rt();const Vr=os?.payload;Vr?.taskId&&Fe(fs=>{if(!fs||fs.id!==Vr.taskId)return fs;const jr={};return typeof Vr.status=="string"&&(jr.status=Vr.status),Array.isArray(Vr.deliverables)&&(jr.deliverables=Vr.deliverables),Array.isArray(Vr.notes)&&(jr.notes=Vr.notes),Vr.result!==void 0&&(jr.result=Vr.result),{...fs,...jr}})}),yt=pn.on("task:create",()=>{Rt()}),Ur=["requirement:created","requirement:approved","requirement:rejected","requirement:updated","requirement:completed","requirement:cancelled","requirement:resubmitted"].map(os=>pn.on(os,()=>{hr()})),ms=()=>{pl("/taskboard"),on(),dr()};return window.addEventListener("markus:data-changed",ms),()=>{clearInterval(Qe),un(),yt(),Ur.forEach(os=>os()),window.removeEventListener("markus:data-changed",ms),dt&&clearTimeout(dt),fn&&clearTimeout(fn)}},[t,a,on,cr,dr]);const ba=g.useRef(z);ba.current=z;const ra=g.useRef(L);ra.current=L;const ds=g.useCallback(oe=>{if(!oe)return;const Qe=ln.current;Qe.size>0&&!Qe.has(oe)&&We(dt=>new Set([...dt,oe]))},[]),[ni,ri]=g.useState(!1),za=g.useCallback((oe,Qe)=>{Fe(oe),nt(null),Qe?.scrollToComments&&ri(!0),u&&C(!0)},[u]),vi=g.useCallback((oe,Qe)=>{nt(oe),Fe(null),Qe?.scrollToComments&&ri(!0),u&&C(!0)},[u]),si=g.useRef(null);g.useEffect(()=>{const oe=si.current||localStorage.getItem("markus_nav_openTask");if(!oe)return;const dt=Object.values(z).flat().find(Rt=>Rt.id===oe);dt?(si.current=null,ds(dt.projectId),za(dt),localStorage.removeItem("markus_nav_openTask")):si.current||(si.current=oe,localStorage.removeItem("markus_nav_openTask"),ie.tasks.get(oe).then(Rt=>{Rt.task&&(si.current=null,ds(Rt.task.projectId),za(Rt.task))}).catch(()=>{si.current=null}))},[z,za,ds]);const sa=g.useRef(null);g.useEffect(()=>{const oe=sa.current||localStorage.getItem("markus_nav_openRequirement");if(!oe)return;const Qe=L.find(dt=>dt.id===oe);Qe?(sa.current=null,ds(Qe.projectId),vi(Qe),localStorage.removeItem("markus_nav_openRequirement")):sa.current||(sa.current=oe,localStorage.removeItem("markus_nav_openRequirement"),ie.requirements.get(oe).then(dt=>{dt.requirement&&(sa.current=null,ds(dt.requirement.projectId),vi(dt.requirement))}).catch(()=>{sa.current=null}))},[L,vi,ds]),g.useEffect(()=>{const oe=window.location.hash.slice(1).split("/");if(nc(oe[0])===De.WORK&&oe[1])ya(oe[1]);else{const Qe=localStorage.getItem("markus_nav_projectId");Qe&&(localStorage.removeItem("markus_nav_projectId"),ya(Qe))}},[]);const Ys=g.useRef(nc(window.location.hash.slice(1).split("/")[0]));g.useEffect(()=>{if(t)return;const oe=()=>{const dt=window.location.hash.slice(1).split("/"),Rt=nc(dt[0]),fn=Ys.current===De.WORK;Ys.current=Rt,Rt===De.WORK&&(Rt===De.WORK&&dt[1]?ya(dt[1]):fn&&Ls())},Qe=async dt=>{const Rt=dt.detail;if(nc(Rt.page)===De.WORK){if(Rt.params?.openTask){const fn=Rt.params.openTask,hr=Rt.params.scrollToComments==="true";localStorage.removeItem("markus_nav_openTask");let un=Object.values(ba.current).flat().find(yt=>yt.id===fn);if(!un)try{un=(await ie.tasks.get(fn)).task}catch{}un&&(ds(un.projectId),za(un,{scrollToComments:hr}))}if(Rt.params?.openRequirement){const fn=Rt.params.openRequirement,hr=Rt.params.scrollToComments==="true";let un=ra.current.find(yt=>yt.id===fn);if(!un)try{un=(await ie.requirements.get(fn)).requirement}catch{}un&&(ds(un.projectId),vi(un,{scrollToComments:hr}))}if(Rt.params?.projectId&&ya(Rt.params.projectId),Rt.params?.statusFilter){const fn=Rt.params.statusFilter;localStorage.removeItem("markus_nav_statusFilter"),Hre.has(fn)&&Ge(!0),Wt(fn)}}};return window.addEventListener("markus:navigate",Qe),window.addEventListener("hashchange",oe),()=>{window.removeEventListener("markus:navigate",Qe),window.removeEventListener("hashchange",oe)}},[t]);const ya=oe=>{ln.current.size>0&&(Vt.current=new Set(ln.current)),We(new Set),I(oe),E("project"),_(null),q(!1),history.replaceState(null,"",hw(De.WORK,oe))},Ls=()=>{We(Vt.current),I(null),E("all"),_(null),q(!1),history.replaceState(null,"",hw(De.WORK))},Yn=()=>{ee(!1),Dt(s("work:task.projectCreated")),On()},Ns=async oe=>{if(confirm("Delete this project and unlink all its tasks?"))try{await ie.projects.delete(oe),R===oe&&Ls(),Dt("Project deleted"),On(),on()}catch(Qe){Dt(`Error: ${Qe}`)}},va=async()=>{if(!ue||!_e||!Ye)return;et("");const oe=Ye.startsWith("human:"),Qe=Ye.replace(/^(human|agent):/,"");if(_e===Qe&&!oe){Dt(s("work:task.assignedReviewerDifferent"));return}const dt=mt||void 0,Rt=Lt||void 0;try{const{task:fn}=await ie.tasks.create(ue,Ce,_e,Qe,Ne,dt,ne.length>0?ne:void 0,Rt,be!=="standard"?be:void 0,be==="scheduled"?{every:fe}:void 0,oe?"human":"agent");Se(""),Be(""),me([]),ht(""),se("standard"),He("4h"),G(!1),on(),fn&&za(fn)}catch(fn){const un=`work:task.errorCode_${(fn instanceof p6?fn.code:void 0)||"unknown"}`,yt=s(un,{defaultValue:""});et(yt||s("work:task.errorCreatingTask",{message:fn instanceof Error?fn.message:String(fn)}))}},Ss=oe=>{window.dispatchEvent(new CustomEvent("markus:mark-read-by-ref",{detail:oe}))},yr=()=>{on(),pe&&(Ss({taskId:pe.id}),setTimeout(()=>{const oe={};T==="project"&&R&&(oe.projectId=R),ie.tasks.board(oe).then(Qe=>{const Rt=Object.values(Qe.board).flat().find(fn=>fn.id===pe.id);Fe(Rt||null)}).catch(()=>{})},150))},Ps=()=>{dr(),Ve&&setTimeout(()=>{ie.requirements.list({}).then(({requirements:oe})=>{const Qe=oe.find(dt=>dt.id===Ve.id);nt(Qe||null)}).catch(()=>{})},150)},is=async()=>{if(!Sn.trim()){ye(s("work:task.pleaseReqTitle"));return}if(!Vn.trim()){ye(s("work:task.pleaseReqDesc"));return}if(!ve){ye(s("work:task.pleaseReqProject"));return}ye("");try{const{requirement:oe}=await ie.requirements.create({title:Sn.trim(),description:Vn.trim(),priority:Pe,projectId:ve});Dt(s("work:task.requirementCreated")),Bn(""),Qn(""),$n(!1),dr(),oe&&vi(oe)}catch(oe){ye(oe instanceof Error?oe.message:String(oe))}},qr=async oe=>{try{await ie.requirements.approve(oe),Dt("Requirement approved"),Ss({requirementId:oe}),Ps(),on()}catch(Qe){Dt(`Error: ${Qe}`)}},ai=async()=>{if(Tt){vt("");try{await ie.requirements.reject(Tt,sn),Dt("Requirement rejected"),Ss({requirementId:Tt}),$t(null),Zn(""),vt(""),Ps()}catch(oe){vt(oe instanceof Error?oe.message:String(oe))}}},Cs=async oe=>{try{await ie.requirements.cancel(oe),Dt("Requirement cancelled"),Ss({requirementId:oe}),Ps()}catch(Qe){Dt(`Error: ${Qe}`)}},aa=(oe,Qe)=>{Mn.current=Qe,wn.current=null,oe.dataTransfer.effectAllowed="move",oe.dataTransfer.setData("text/plain",`task:${Qe.id}`),oe.currentTarget.style.opacity="0.4"},$a=(oe,Qe)=>{wn.current=Qe,Mn.current=null,oe.dataTransfer.effectAllowed="move",oe.dataTransfer.setData("text/plain",`req:${Qe.id}`),oe.currentTarget.style.opacity="0.4"},Xn=oe=>{oe.currentTarget.style.opacity="1",Mn.current=null,wn.current=null,vn(null)},Ts=(oe,Qe)=>{oe.preventDefault(),oe.dataTransfer.dropEffect="move",en!==Qe&&vn(Qe)},Os=(oe,Qe)=>{const dt=oe.currentTarget.getBoundingClientRect(),{clientX:Rt,clientY:fn}=oe;(Rt<dt.left||Rt>dt.right||fn<dt.top||fn>dt.bottom)&&en===Qe&&vn(null)},Di=async(oe,Qe)=>{oe.preventDefault(),vn(null);const dt=Mn.current,Rt=wn.current;if(dt){const fn=i.find(un=>un.id===Qe);if(!fn)return;const hr=fn.dropStatus;if(dt.status===hr||dt.status==="pending")return;try{await ie.tasks.updateStatus(dt.id,hr),on()}catch{}}else if(Rt){const fn=rC[Qe];if(!fn||Rt.status===fn)return;try{await ie.requirements.updateStatus(Rt.id,fn),dr()}catch{}}},Or=oe=>{rt(Qe=>{const dt=new Set(Qe);return dt.has(oe)?dt.delete(oe):dt.add(oe),dt})},kn=oe=>{T==="project"?R===oe?Ls():ya(oe):We(Qe=>{const dt=new Set(Qe);return dt.has(oe)?dt.delete(oe):dt.add(oe),dt})},_s=new Set(["rejected","cancelled","archived"]),Fs=oe=>_s.has(oe.status),ii=(oe,Qe=!1)=>{let dt=oe.filter(Rt=>mr||!Fs(Rt));return Ht&&(dt=dt.filter(Rt=>Rt.status===Ht)),T==="project"&&R&&(dt=dt.filter(Rt=>Rt.projectId===R)),Re.size>0&&(dt=dt.filter(Rt=>Rt.projectId&&Re.has(Rt.projectId))),gt.size>0&&(dt=dt.filter(Rt=>Rt.assignedAgentId&&gt.has(Rt.assignedAgentId))),Et&&e?.id&&(dt=dt.filter(Rt=>Rt.createdBy===e.id)),dt},oi=g.useMemo(()=>{const oe=new Map;for(const Qe of Object.values(z))for(const dt of Qe)oe.set(dt.id,dt);return oe},[z]),Xs=g.useMemo(()=>new Set(D.map(oe=>oe.id)),[D]),zr=oe=>oe.statuses.flatMap(Qe=>ii(z[Qe]??[])),qs=g.useMemo(()=>{let oe=L;if(mr||(oe=oe.filter(Qe=>!Fs(Qe))),T==="project"&&R&&(oe=oe.filter(Qe=>Qe.projectId===R)),Re.size>0&&(oe=oe.filter(Qe=>Qe.projectId&&Re.has(Qe.projectId))),gt.size>0){const Qe=e?.id;oe=oe.filter(dt=>gt.has(dt.createdBy)||Qe!=null&&dt.createdBy===Qe||!Xs.has(dt.createdBy))}return Et&&e?.id&&(oe=oe.filter(Qe=>Qe.createdBy===e.id)),oe},[L,mr,T,R,Re,gt,Et,e?.id,Xs]),wa=g.useCallback(oe=>qs.filter(Qe=>nC[Qe.status]===oe.id),[qs]),Us=i.filter(oe=>{if(oe.id==="failed"||oe.id==="closed"){const Qe=zr(oe),dt=wa(oe);return Qe.length+dt.length>0}return!0}),Zr=Object.values(z).flat().filter(oe=>Fs(oe)).length+L.filter(oe=>Fs(oe)).length,zs=g.useMemo(()=>{const oe=new Set(["completed","failed","cancelled","archived"]),Qe=Object.values(z).flat(),dt=new Set;for(const Rt of Qe)Rt.assignedAgentId&&!oe.has(Rt.status)&&(!R||Rt.projectId===R)&&dt.add(Rt.assignedAgentId);return[...D].sort((Rt,fn)=>{const hr=dt.has(Rt.id)?0:1,un=dt.has(fn.id)?0:1;return hr-un})},[D,z,R]),ka=g.useMemo(()=>{const oe=new Set(["completed","failed","cancelled","archived"]),Qe=Object.values(z).flat(),dt=new Set;for(const Rt of Qe)Rt.projectId&&!oe.has(Rt.status)&&dt.add(Rt.projectId);return[...N].sort((Rt,fn)=>{const hr=Rt.status==="archived"?1:0,un=fn.status==="archived"?1:0;if(hr!==un)return hr-un;const yt=dt.has(Rt.id)?0:1,us=dt.has(fn.id)?0:1;return yt!==us?yt-us:Rt.name.localeCompare(fn.name)})},[N,z]),Ri=g.useMemo(()=>{const oe={};for(const Qe of Object.values(z))for(const dt of Qe){const Rt=dt.projectId??"__none__";oe[Rt]=(oe[Rt]??0)+1}return oe},[z]),ja=Object.values(Ri).reduce((oe,Qe)=>oe+Qe,0);if(M)return n.jsx("div",{className:"flex-1 flex items-center justify-center text-fg-tertiary",children:s("work:task.loadingPage")});const Na=!!(pe||Ve),Sa=!u&&!!(pe&&Ve);return n.jsxs("div",{ref:m,className:"flex-1 overflow-hidden flex bg-surface-primary",children:[n.jsxs("div",{className:`${u?"flex-1 min-w-0":Na?"shrink-0 min-w-0":"flex-1"} overflow-hidden flex flex-col bg-surface-primary`,style:u?j?{display:"none"}:void 0:Sa?{width:0}:Na?{width:`calc(100% - ${v.width}px - 4px)`}:void 0,children:[W&&n.jsx("div",{className:"mx-6 mt-2 px-3 py-1.5 bg-green-500/15 text-green-600 text-xs rounded-lg",children:W}),u?n.jsxs("div",{className:"shrink-0",children:[n.jsxs("div",{className:"flex items-center gap-2 px-3 h-11",children:[n.jsx(gc,{}),Pn?n.jsxs("div",{className:"flex items-center gap-1 min-w-0 flex-1",children:[n.jsx("span",{className:"text-sm font-semibold text-fg-primary truncate",children:Pn.name}),n.jsx("button",{onClick:()=>nr(Pn.id),className:`w-6 h-6 flex items-center justify-center rounded-md transition-colors shrink-0 ${H?"bg-surface-overlay text-fg-primary":"text-fg-tertiary"}`,children:n.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("circle",{cx:"12",cy:"12",r:"3"}),n.jsx("path",{d:"M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 1 1-2.83 2.83l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 0 1-4 0v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 1 1-2.83-2.83l.06-.06A1.65 1.65 0 0 0 4.68 15a1.65 1.65 0 0 0-1.51-1H3a2 2 0 0 1 0-4h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 1 1 2.83-2.83l.06.06A1.65 1.65 0 0 0 9 4.68a1.65 1.65 0 0 0 1-1.51V3a2 2 0 0 1 4 0v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 1 1 2.83 2.83l-.06.06A1.65 1.65 0 0 0 19.4 9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 0 1 0 4h-.09a1.65 1.65 0 0 0-1.51 1z"})]})})]}):n.jsx("h2",{className:"text-sm font-semibold text-fg-primary min-w-0 flex-1 truncate",children:N.length===1?N[0].name:s("work:task.projectsCount",{count:N.length})}),n.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[n.jsx("button",{onClick:()=>ee(!0),className:"px-2 py-1 text-[11px] bg-teal-600 text-white rounded-md",children:s("work:task.shortProject")}),n.jsx("button",{onClick:J,className:"px-2 py-1 text-[11px] bg-brand-600 text-white rounded-md",children:s("work:task.shortReq")}),n.jsx("button",{onClick:()=>{it(R??""),G(!0)},className:"px-2 py-1 text-[11px] border border-amber-500/60 text-amber-600 rounded-md",children:s("work:task.shortTask")})]})]}),n.jsxs("div",{className:"flex items-center gap-2 px-3 h-9",children:[n.jsx("div",{className:"flex items-center border border-border-default/60 rounded-md overflow-hidden shrink-0",children:["backlog","kanban","dag"].map(oe=>n.jsx("button",{onClick:()=>Zt(oe),className:`px-2 py-0.5 text-[10px] font-medium transition-colors ${In===oe?"bg-brand-600/25 text-brand-500":"text-fg-tertiary"}`,children:s(oe==="backlog"?"work:task.backlog":oe==="kanban"?"work:task.kanban":"work:task.dag")},oe))}),Zr>0&&n.jsx("button",{onClick:()=>Ge(oe=>!oe),className:`text-[10px] shrink-0 px-2 py-0.5 rounded-md transition-colors ${mr?"bg-surface-overlay text-fg-secondary":"text-fg-tertiary"}`,children:mr?s("work:task.hideArchived"):s("work:task.archivedCount",{count:Zr})}),n.jsx("div",{className:"flex-1"}),Ht&&n.jsxs("button",{onClick:()=>Wt(null),className:"px-2 py-0.5 text-[11px] rounded-md font-medium bg-brand-600/20 text-brand-500 ring-1 ring-brand-500/30 flex items-center gap-1",children:[s(`common:status.${Ht==="in_progress"?"inProgress":Ht}`),n.jsxs("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"3",strokeLinecap:"round",children:[n.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),n.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})]}),(Re.size>0||gt.size>0||Et||N.length>1||D.length>0)&&n.jsxs("button",{onClick:()=>zn(!0),className:`px-2 py-1 text-[11px] rounded-md font-medium transition-colors flex items-center gap-1 ${Re.size>0||gt.size>0||Et?"bg-brand-600/20 text-brand-500 ring-1 ring-brand-500/30":"border border-border-default text-fg-secondary"}`,children:[n.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:n.jsx("polygon",{points:"22 3 2 3 10 12.46 10 19 14 21 14 12.46 22 3"})}),Re.size+gt.size+(Et?1:0)>0?s("work:task.filterWithCount",{count:Re.size+gt.size+(Et?1:0)}):s("work:task.filter")]})]})]}):n.jsxs("div",{className:"flex items-center gap-3 px-6 h-14 shrink-0",children:[Pn?n.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[n.jsx(S3,{value:Pn.name,onSave:async oe=>{await ie.projects.update(Pn.id,{name:oe}),On()},className:"text-sm font-semibold text-fg-primary"}),n.jsx("button",{onClick:()=>nr(Pn.id),className:`w-6 h-6 flex items-center justify-center rounded-md transition-colors ${H?"bg-surface-overlay text-fg-primary":"text-fg-tertiary hover:text-fg-secondary hover:bg-surface-elevated"}`,title:s("work:project.settingsTitle"),children:n.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("circle",{cx:"12",cy:"12",r:"3"}),n.jsx("path",{d:"M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 1 1-2.83 2.83l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 0 1-4 0v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 1 1-2.83-2.83l.06-.06A1.65 1.65 0 0 0 4.68 15a1.65 1.65 0 0 0-1.51-1H3a2 2 0 0 1 0-4h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 1 1 2.83-2.83l.06.06A1.65 1.65 0 0 0 9 4.68a1.65 1.65 0 0 0 1-1.51V3a2 2 0 0 1 4 0v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 1 1 2.83 2.83l-.06.06A1.65 1.65 0 0 0 19.4 9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 0 1 0 4h-.09a1.65 1.65 0 0 0-1.51 1z"})]})})]}):n.jsx("h2",{className:"text-sm font-semibold text-fg-primary shrink-0",children:N.length===1?N[0].name:s("work:task.projectsCount",{count:N.length})}),Zr>0&&n.jsx("button",{onClick:()=>Ge(oe=>!oe),className:`text-[10px] shrink-0 px-2 py-0.5 rounded-md transition-colors ${mr?"bg-surface-overlay text-fg-secondary":"text-fg-tertiary hover:text-fg-secondary"}`,children:mr?s("work:task.hideArchivedWithCount",{count:Zr}):s("work:task.archivedCount",{count:Zr})}),n.jsx("div",{className:"flex items-center border border-border-default/60 rounded-md overflow-hidden shrink-0",children:["backlog","kanban","dag"].map(oe=>n.jsx("button",{onClick:()=>Zt(oe),className:`px-2.5 py-1 text-[10px] font-medium transition-colors ${In===oe?"bg-brand-600/25 text-brand-500":"text-fg-tertiary hover:text-fg-secondary hover:bg-surface-elevated"}`,children:s(oe==="backlog"?"work:task.backlog":oe==="kanban"?"work:task.kanban":"work:task.dag")},oe))}),n.jsxs("div",{className:"flex items-center gap-1.5 shrink-0",children:[n.jsx("button",{onClick:()=>ee(!0),className:"px-3 py-1.5 bg-teal-600 hover:bg-teal-500 text-white text-xs rounded-lg font-medium transition-colors",children:s("work:task.shortProject")}),n.jsx("button",{onClick:J,className:"px-3 py-1.5 bg-brand-600 hover:bg-brand-500 text-white text-xs rounded-lg font-medium transition-colors",children:s("work:task.newRequirement")}),n.jsx("button",{onClick:()=>{it(R??""),G(!0)},className:"px-3 py-1.5 border border-amber-500/60 text-amber-600 hover:bg-amber-500/10 text-xs rounded-lg font-medium transition-colors",children:s("work:task.newTaskBtn")})]}),n.jsx("div",{className:"flex-1"})]}),!u&&N.length>1&&!R&&!H&&(ja>0||L.length>0)&&n.jsxs("div",{className:"px-6 py-1.5 flex items-center gap-1.5 overflow-x-auto scrollbar-hide shrink-0",children:[n.jsx("button",{onClick:()=>We(new Set),className:`text-[10px] text-fg-tertiary hover:text-fg-secondary px-2 py-1 rounded-md bg-surface-elevated/60 hover:bg-surface-overlay shrink-0 transition-all ${Re.size>0?"visible opacity-100":"invisible opacity-0"}`,children:s("work:task.clear")}),ka.map(oe=>{const Qe=Re.has(oe.id),dt=Ri[oe.id]??0,Rt=H&&Z===oe.id;return n.jsxs("div",{className:`flex items-center shrink-0 rounded-md overflow-hidden transition-all ${Qe?"bg-brand-500/15 ring-1 ring-brand-500/30":""}`,children:[n.jsxs("button",{onClick:()=>kn(oe.id),className:`flex items-center gap-1.5 px-2.5 py-1 text-[11px] shrink-0 transition-all ${Qe?"text-brand-600":"text-fg-tertiary hover:bg-surface-elevated hover:text-fg-secondary"}`,children:[n.jsx("span",{className:`w-4 h-4 rounded-sm flex items-center justify-center text-[9px] font-bold shrink-0 ${Qe?"bg-brand-600 text-white":"bg-surface-overlay text-fg-secondary"}`,children:oe.name[0]?.toUpperCase()}),oe.name,dt>0&&n.jsx("span",{className:"text-[9px] text-fg-tertiary ml-0.5",children:dt})]}),Qe&&n.jsx("button",{onClick:()=>nr(oe.id),className:`px-1.5 py-1 self-stretch flex items-center border-l border-brand-500/20 transition-colors ${Rt?"text-fg-primary bg-surface-overlay":"text-fg-tertiary hover:text-brand-600 hover:bg-brand-500/10"}`,title:s("work:project.editProject"),children:n.jsxs("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("path",{d:"M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"}),n.jsx("path",{d:"M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z"})]})})]},oe.id)})]}),!u&&(D.length>0||e?.id)&&!H&&(ja>0||L.length>0)&&n.jsxs("div",{className:"px-6 py-1.5 flex items-center gap-1.5 overflow-x-auto scrollbar-hide shrink-0",children:[n.jsx("button",{type:"button",onClick:()=>{rt(new Set),je(!1)},className:`text-[10px] text-fg-tertiary hover:text-fg-secondary px-2 py-1 rounded-md bg-surface-elevated/60 hover:bg-surface-overlay shrink-0 transition-all ${gt.size>0||Et?"visible opacity-100":"invisible opacity-0"}`,children:s("work:task.clear")}),e?.id&&n.jsx("button",{type:"button",onClick:()=>je(oe=>!oe),className:`flex items-center gap-1.5 px-2.5 py-1 rounded-md text-[11px] shrink-0 transition-all ${Et?"bg-green-600/20 text-green-500 ring-1 ring-green-500/40":"text-fg-tertiary hover:bg-surface-elevated hover:text-fg-secondary"}`,children:s("work:task.myTasks")}),zs.map(oe=>{const Qe=gt.has(oe.id);return n.jsxs("button",{onClick:()=>Or(oe.id),className:`flex items-center gap-1.5 px-2.5 py-1 rounded-md text-[11px] shrink-0 transition-all ${Qe?"bg-brand-600/20 text-brand-500 ring-1 ring-brand-500/40":"text-fg-tertiary hover:bg-surface-elevated hover:text-fg-secondary"}`,children:[n.jsx("span",{className:`w-4 h-4 rounded-full flex items-center justify-center text-[9px] font-bold shrink-0 ${Qe?"bg-brand-600 text-white":"bg-surface-overlay text-fg-secondary"}`,children:oe.name[0]?.toUpperCase()}),oe.name]},oe.id)})]}),H&&tr?n.jsxs("div",{className:"flex-1 overflow-y-auto",children:[!Pn&&n.jsxs("div",{className:"px-6 py-2 flex items-center gap-2 border-b border-border-default/60 shrink-0",children:[n.jsxs("button",{onClick:Hn,className:"text-[11px] text-brand-500 hover:text-brand-400 font-medium flex items-center gap-1 shrink-0",children:[n.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:n.jsx("polyline",{points:"15 18 9 12 15 6"})}),s("common:back")]}),n.jsx(S3,{value:tr.name,onSave:async oe=>{await ie.projects.update(tr.id,{name:oe}),On()},className:"text-sm font-semibold text-fg-primary truncate min-w-0"})]}),n.jsx(Gre,{project:tr,tasks:Object.values(z).flat(),requirements:L,agents:D,onDeleteProject:()=>Ns(tr.id),onUpdateProject:async oe=>{await ie.projects.update(tr.id,oe)},onRefresh:()=>{On()}})]}):ja===0&&qs.length===0?n.jsx("div",{className:"flex-1 flex items-center justify-center p-8",children:N.length===0?n.jsxs("div",{className:"max-w-sm w-full text-center space-y-3",children:[n.jsx("div",{className:"w-12 h-12 mx-auto rounded-xl bg-brand-500/10 flex items-center justify-center",children:n.jsx("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",className:"text-brand-500",children:n.jsx("path",{d:"M22 19a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h5l2 3h9a2 2 0 0 1 2 2z"})})}),n.jsx("h3",{className:"text-sm font-medium text-fg-secondary",children:s("work:task.emptyNoProjectsTitle")}),n.jsx("p",{className:"text-xs text-fg-tertiary leading-relaxed",children:s("work:task.emptyNoProjectsHint")}),n.jsx("button",{onClick:()=>ee(!0),className:"inline-flex items-center gap-1.5 px-4 py-2 text-xs bg-brand-600 hover:bg-brand-500 text-white rounded-lg font-medium transition-colors",children:s("work:project.newProject")})]}):n.jsxs("div",{className:"max-w-sm w-full text-center space-y-3",children:[n.jsx("div",{className:"w-12 h-12 mx-auto rounded-xl bg-brand-500/10 flex items-center justify-center",children:n.jsxs("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",className:"text-brand-500",children:[n.jsx("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),n.jsx("polyline",{points:"14 2 14 8 20 8"}),n.jsx("line",{x1:"12",y1:"18",x2:"12",y2:"12"}),n.jsx("line",{x1:"9",y1:"15",x2:"15",y2:"15"})]})}),n.jsx("h3",{className:"text-sm font-medium text-fg-secondary",children:s("work:task.emptyNoReqsTitle")}),n.jsx("p",{className:"text-xs text-fg-tertiary leading-relaxed whitespace-pre-line",children:s("work:task.emptyNoReqsHint")}),n.jsx("button",{onClick:J,className:"inline-flex items-center gap-1.5 px-4 py-2 text-xs bg-brand-600 hover:bg-brand-500 text-white rounded-lg font-medium transition-colors",children:s("work:task.createRequirementCta")})]})}):In==="backlog"?n.jsx("div",{className:"flex-1 min-h-0 flex flex-col",onTouchStart:u?Gn.onTouchStart:void 0,onTouchEnd:u?Gn.onTouchEnd:void 0,children:n.jsx(Jre,{tasks:ii(Object.values(z).flat()),requirements:qs,agents:D,projects:N,onTaskClick:oe=>fr(oe),onReqClick:oe=>Is(oe),onRefresh:()=>{on(),dr()},selectedTaskId:pe?.id,selectedReqId:Ve?.id})}):In==="dag"?n.jsxs("div",{className:"flex-1 min-h-0 flex flex-col relative",onTouchStart:u?Gn.onTouchStart:void 0,onTouchEnd:u?Gn.onTouchEnd:void 0,children:[n.jsx(Ire,{tasks:(()=>{const oe=ii(Object.values(z).flat(),!0);if(t&&Ve){const Qe=new Set(Ve.taskIds??[]);return oe.filter(dt=>Qe.has(dt.id))}return oe})(),requirements:t&&Ve?[Ve]:qs,agents:D,showArchived:mr,onShowArchivedChange:Ge,onTaskClick:oe=>fr(oe),onReqClick:oe=>Is(oe),onCollapseDAG:()=>{Fe(null),nt(null)},onDependencyChange:on,selectedTaskId:pe?.id,selectedReqId:Ve?.id,hasDetailPanel:Na,defaultExpandedNodeId:t&&Ve?`req-${Ve.id}`:void 0,previewMode:t}),u&&n.jsx("button",{onClick:()=>Zt("kanban"),className:"absolute left-3 top-1/2 -translate-y-1/2 w-11 h-11 rounded-full bg-brand-500 border border-brand-400/60 shadow-xl shadow-brand-500/30 flex items-center justify-center text-white active:bg-brand-400 backdrop-blur-sm z-10",title:s("work:task.backToKanban"),children:n.jsx("svg",{className:"w-5 h-5",viewBox:"0 0 20 20",fill:"currentColor",children:n.jsx("path",{fillRule:"evenodd",d:"M12.79 5.23a.75.75 0 01-.02 1.06L8.832 10l3.938 3.71a.75.75 0 11-1.04 1.08l-4.5-4.25a.75.75 0 010-1.08l4.5-4.25a.75.75 0 011.06.02z",clipRule:"evenodd"})})})]}):n.jsx("div",{ref:Ln,className:"flex-1 min-h-0 overflow-x-auto overflow-y-hidden px-4 py-5",onTouchStart:u?Qr.onTouchStart:void 0,onTouchEnd:u?Qr.onTouchEnd:void 0,children:n.jsx("div",{className:"flex gap-3 h-full",children:Us.map(oe=>{const Qe=zr(oe),dt=wa(oe),Rt=Qe.length+dt.length,fn=en===oe.id;return n.jsxs("div",{className:`w-[280px] shrink-0 rounded-xl flex flex-col h-full transition-colors ${fn?"bg-surface-elevated/60 ring-1 ring-brand-500/30":"bg-surface-secondary/50"}`,onDragOver:hr=>Ts(hr,oe.id),onDragLeave:hr=>Os(hr,oe.id),onDrop:hr=>{Di(hr,oe.id)},children:[n.jsxs("div",{className:"flex justify-between items-center px-3 py-2.5 shrink-0 border-b border-border-default/30",children:[n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx("span",{className:`w-2 h-2 rounded-full ${oe.accent.replace("border-t-","bg-")}`}),n.jsx("span",{className:"text-xs font-semibold text-fg-secondary uppercase tracking-wider",children:oe.label})]}),n.jsx("span",{className:"text-[11px] text-fg-tertiary font-medium tabular-nums",children:Rt})]}),n.jsx("div",{className:"space-y-2 flex-1 min-h-0 overflow-y-auto scrollbar-thin px-2 py-2",children:(()=>{const hr=[...dt.map(un=>({kind:"req",data:un,time:new Date(un.updatedAt??un.createdAt).getTime()})),...Qe.map(un=>({kind:"task",data:un,time:new Date(un.updatedAt??un.createdAt??0).getTime()}))];return hr.sort((un,yt)=>yt.time-un.time),hr.map(un=>{if(un.kind==="req"){const yt=un.data,us=d[yt.status]??{label:yt.status,cls:"bg-gray-500/15 text-fg-secondary"},ms=yt.source==="agent"&&yt.status==="pending",os=T==="all"&&yt.projectId?N.find(jr=>jr.id===yt.projectId):null,Vr=Rd(yt.createdBy,D,Y)??yt.createdBy.slice(0,10),fs=Ve?.id===yt.id;return n.jsxs("div",{role:"button",tabIndex:0,draggable:!0,onDragStart:jr=>$a(jr,yt),onDragEnd:Xn,onClick:()=>Is(yt),onKeyDown:jr=>jr.key==="Enter"&&Is(yt),className:`group rounded-lg p-2.5 border border-transparent transition-all cursor-grab active:cursor-grabbing
710
710
  ${ms?"bg-amber-500/[0.06] border-amber-500/30 ring-1 ring-amber-500/15":"bg-surface-elevated/80 hover:bg-surface-elevated border-border-default/50 hover:border-brand-400/40"}
711
- ${fs?"ring-2 ring-brand-500/50 border-brand-500/40":""}`,children:[n.jsxs("div",{className:"flex items-center gap-1.5 mb-1",children:[n.jsx("span",{className:"w-1 h-1 rounded-full bg-purple-500 shrink-0"}),n.jsx("span",{className:"text-[10px] font-semibold text-purple-500 uppercase tracking-wide shrink-0",children:s("work:task.requirementShort")}),n.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded-md shrink-0 ml-auto ${us.cls}`,children:us.label})]}),n.jsx("div",{className:"text-[13px] font-medium leading-snug text-fg-primary line-clamp-2 mb-1",children:yt.title}),yt.description&&n.jsx("div",{className:"text-[11px] text-fg-tertiary line-clamp-1 mb-1.5",children:yt.description}),n.jsxs("div",{className:"flex items-center justify-between mt-auto pt-1.5 border-t border-border-default/20",children:[n.jsxs("div",{className:"flex items-center gap-1.5",children:[os&&n.jsx("span",{className:"text-[10px] px-1.5 py-0.5 bg-surface-overlay/60 text-fg-secondary rounded truncate max-w-[90px]",title:os.name,children:os.name}),n.jsx("span",{className:"text-[10px] text-fg-tertiary",children:yt.priority}),n.jsxs("span",{className:"text-[10px] text-fg-quaternary",children:["by ",Vr]})]}),n.jsx("div",{className:"flex items-center gap-1",children:yt.taskIds.length>0&&n.jsxs("span",{className:"text-[10px] text-brand-500/70 bg-brand-500/8 px-1.5 py-0.5 rounded-md",children:["📋 ",yt.taskIds.length]})})]}),ms&&n.jsxs("div",{className:"flex items-center gap-2 mt-2 pt-2 border-t border-amber-500/15",children:[n.jsx("button",{onClick:jr=>{jr.stopPropagation(),qr(yt.id)},className:"flex-1 py-1 bg-green-600 hover:bg-green-500 text-white text-[10px] rounded-md font-medium transition-colors",children:s("work:task.approve")}),n.jsx("button",{onClick:jr=>{jr.stopPropagation(),$t(yt.id)},className:"flex-1 py-1 border border-red-500/30 hover:bg-red-500/10 text-red-500 text-[10px] rounded-md font-medium transition-colors",children:s("work:task.reject")})]})]},`req-${yt.id}`)}else{const yt=un.data,us=yt.subtasks?.length??0,Ur=l[yt.status],ms=yt.status==="pending",os=yt.taskType==="scheduled"&&!!yt.scheduleConfig,Vr=os?yt.scheduleConfig.every?s("work:task.everyInterval",{interval:yt.scheduleConfig.every}):yt.scheduleConfig.cron?s("work:task.cronLabel"):s("work:task.scheduledShort"):null,fs=T==="all"&&yt.projectId?(()=>{const Ie=N.find(st=>st.id===yt.projectId)?.name;return Ie&&Ie!=="default"?Ie:null})():null,jr=yt.requirementId?L.find(Ie=>Ie.id===yt.requirementId)?.title:null,to=yt.createdBy?Rd(yt.createdBy,D,Y)??yt.createdBy:null,Ii=pe?.id===yt.id,no={urgent:"bg-red-500",high:"bg-amber-500",medium:"bg-blue-500",low:"bg-gray-400"},le=yt.status==="blocked"&&(!yt.blockedBy||yt.blockedBy.length===0||yt.blockedBy.every(Ie=>{const st=oi.get(Ie);return st&&st.status==="completed"}));return n.jsxs("div",{role:"button",tabIndex:0,"aria-label":yt.title,draggable:!ms,onDragStart:Ie=>!ms&&aa(Ie,yt),onDragEnd:Xn,onClick:()=>fr(yt),onKeyDown:Ie=>Ie.key==="Enter"&&fr(yt),className:`group rounded-lg p-2.5 border border-transparent transition-all ${le?"bg-red-500/[0.06] border-red-500/30 ring-1 ring-red-500/15 cursor-pointer":ms?"bg-amber-500/[0.06] border-amber-500/30 ring-1 ring-amber-500/15 cursor-pointer":os?"bg-blue-500/[0.04] border-blue-500/20 hover:border-blue-400/40 cursor-pointer":"bg-surface-elevated/80 hover:bg-surface-elevated border-border-default/50 hover:border-brand-400/40 cursor-grab active:cursor-grabbing"} ${Ii?"ring-2 ring-brand-500/50 border-brand-500/40":""}`,children:[n.jsxs("div",{className:"flex items-center gap-1.5 mb-1",children:[n.jsx("span",{className:`w-1.5 h-1.5 rounded-full shrink-0 ${no[yt.priority]??"bg-gray-400"}`,title:yt.priority}),os&&n.jsx("span",{className:"text-blue-500 shrink-0",title:Vr??"Scheduled",children:n.jsx("svg",{className:"w-3 h-3",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:n.jsx("path",{d:"M21.5 2v6h-6M2.5 22v-6h6M2 11.5a10 10 0 0 1 18.8-4.3M22 12.5a10 10 0 0 1-18.8 4.3"})})}),os&&Vr&&n.jsx("span",{className:"text-[9px] px-1.5 py-0.5 rounded-md bg-blue-500/10 text-blue-500 whitespace-nowrap",children:Vr}),Ur&&n.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded-md ml-auto shrink-0 ${Ur.cls}`,children:Ur.label}),le&&n.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded-md shrink-0 bg-red-500/15 text-red-500 font-medium",children:"⚠"})]}),n.jsx("div",{className:"text-[13px] font-medium leading-snug text-fg-primary line-clamp-2 mb-1",children:yt.title}),yt.description&&n.jsx("div",{className:"text-[11px] text-fg-tertiary line-clamp-1 mb-1.5",children:yt.description}),(fs||jr||yt.blockedBy&&yt.blockedBy.length>0)&&n.jsxs("div",{className:"flex flex-wrap gap-1 mb-1.5",children:[fs&&n.jsx("span",{className:"text-[10px] px-1.5 py-0.5 bg-surface-overlay/60 text-fg-secondary rounded-md truncate max-w-[100px]",title:fs,children:fs}),jr&&n.jsxs("span",{className:"text-[10px] px-1.5 py-0.5 bg-brand-500/8 text-brand-500 rounded-md truncate max-w-[110px]",title:jr,children:["# ",jr]}),yt.blockedBy&&yt.blockedBy.length>0&&n.jsxs("span",{className:"text-[10px] px-1.5 py-0.5 bg-amber-500/10 text-amber-600 rounded-md",children:["⏳ ",yt.blockedBy.length," dep",yt.blockedBy.length>1?"s":""]})]}),n.jsxs("div",{className:"flex items-center justify-between mt-auto pt-1.5 border-t border-border-default/20",children:[n.jsx("div",{className:"flex items-center gap-1.5",children:to&&n.jsxs("span",{className:"text-[10px] text-fg-quaternary",title:`by ${to}`,children:["by ",to]})}),n.jsxs("div",{className:"flex items-center gap-1.5",children:[us>0&&n.jsxs("span",{className:"text-[10px] text-fg-tertiary",children:["⋮ ",us]}),yt.notes&&yt.notes.length>0&&n.jsxs("span",{className:"text-[10px] text-fg-tertiary",children:["📝 ",yt.notes.length]}),yt.assignedAgentId&&n.jsxs("span",{className:"text-[10px] text-brand-500 bg-brand-500/8 px-1.5 py-0.5 rounded-md flex items-center gap-1",children:[n.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${j0[D.find(Ie=>Ie.id===yt.assignedAgentId)?.status??""]??"bg-gray-500"}`}),D.find(Ie=>Ie.id===yt.assignedAgentId)?.name??yt.assignedAgentId.slice(0,8)]})]})]})]},yt.id)}})})()}),fn&&n.jsx("div",{className:"mx-2 mb-2 border-2 border-dashed border-brand-500/25 rounded-lg h-10 flex items-center justify-center shrink-0",children:n.jsx("span",{className:"text-[11px] text-brand-500/50",children:s("work:task.dropHere")})})]},oe.id)})})})]}),!u&&Na&&n.jsx("div",{className:"w-1.5 shrink-0 cursor-col-resize group relative flex items-center justify-center",onMouseDown:v.onResizeStart,children:n.jsx("div",{className:"w-px h-2/3 border-l border-dashed border-transparent group-hover:border-border-default group-active:border-fg-tertiary transition-colors"})}),(!u||j)&&Na&&n.jsx("div",{className:`${u||Sa?"flex-1":"shrink-0"} overflow-hidden min-w-0 flex`,style:u||Sa?void 0:{width:v.width},children:Sa?n.jsxs(n.Fragment,{children:[n.jsx("div",{className:"flex-1 min-w-0 overflow-hidden",children:n.jsx(q3,{req:Ve,agents:D,projects:N,allTasks:Object.values(z).flat(),users:Y,onClose:()=>{nt(null)},onApprove:oe=>{qr(oe)},onReject:oe=>{$t(oe)},onCancel:oe=>{Cs(oe),nt(null)},onStatusChange:async(oe,Qe)=>{try{await ie.requirements.updateStatus(oe,Qe),Dt(`Requirement status → ${Qe}`),Ss({requirementId:oe}),Ps(),on()}catch(dt){Dt(`Error: ${dt}`)}},onRefresh:Ps,authUser:e,onTaskClick:oe=>{Fe(oe)},onCreateTask:(oe,Qe)=>{ht(oe),Qe&&it(Qe),G(!0)},onProjectClick:kn,previewMode:t})}),n.jsx("div",{className:"w-px shrink-0 bg-border-default"}),n.jsx("div",{className:"flex-1 min-w-0 overflow-hidden",children:n.jsx(_3,{task:pe,agents:D,projects:N,requirements:L,allTasks:Object.values(z).flat(),users:Y,onClose:xa,onRefresh:yr,authUser:e,scrollToComments:ni,onScrollToCommentsDone:()=>ri(!1),onReqClick:oe=>{nt(Qe=>Qe?.id===oe.id?null:oe)},onProjectClick:kn})})]}):pe?n.jsx(_3,{task:pe,agents:D,projects:N,requirements:L,allTasks:Object.values(z).flat(),users:Y,onClose:ga,onRefresh:yr,authUser:e,scrollToComments:ni,onScrollToCommentsDone:()=>ri(!1),onReqClick:oe=>{nt(Qe=>Qe?.id===oe.id?null:oe)},onProjectClick:kn}):Ve?n.jsx(q3,{req:Ve,agents:D,projects:N,allTasks:Object.values(z).flat(),users:Y,onClose:ga,onApprove:oe=>{qr(oe)},onReject:oe=>{$t(oe)},onCancel:oe=>{Cs(oe),ga()},onStatusChange:async(oe,Qe)=>{try{await ie.requirements.updateStatus(oe,Qe),Dt(`Requirement status → ${Qe}`),Ss({requirementId:oe}),Ps(),on()}catch(dt){Dt(`Error: ${dt}`)}},scrollToComments:ni,onScrollToCommentsDone:()=>ri(!1),onRefresh:Ps,authUser:e,onTaskClick:oe=>{Fe(oe),u&&(C(!0),history.pushState({mobileDetail:De.WORK},"",window.location.hash))},onCreateTask:(oe,Qe)=>{ht(oe),Qe&&it(Qe),G(!0)},onProjectClick:kn,previewMode:t}):null}),X&&n.jsx(Lre,{orgId:e?.orgId,onCreated:Yn,onClose:()=>ee(!1)}),te&&n.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 p-3",onClick:()=>{G(!1),et("")},children:n.jsxs("div",{className:`bg-surface-secondary border border-border-default rounded-xl p-6 space-y-4 max-h-[90dvh] overflow-y-auto ${u?"w-full":"w-[28rem]"}`,onClick:oe=>oe.stopPropagation(),children:[n.jsx("h3",{className:"text-base font-semibold text-fg-primary",children:s("work:task.newTask")}),n.jsxs("div",{children:[n.jsx("label",{className:"block text-sm text-fg-secondary mb-1.5",children:s("work:task.titleLabel")}),n.jsx("input",{autoFocus:!u,value:ue,onChange:oe=>Se(oe.target.value),onKeyDown:oe=>{oe.key==="Enter"&&va()},className:"w-full px-3 py-2 bg-surface-elevated border border-border-default rounded-lg text-sm focus:border-brand-500 outline-none"})]}),n.jsxs("div",{children:[n.jsx("label",{className:"block text-sm text-fg-secondary mb-1.5",children:s("work:task.descriptionField")}),n.jsx("textarea",{value:Ce,onChange:oe=>Be(oe.target.value),rows:2,className:"w-full px-3 py-2 bg-surface-elevated border border-border-default rounded-lg text-sm focus:border-brand-500 outline-none resize-none"})]}),n.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[n.jsxs("div",{children:[n.jsx("label",{className:"block text-sm text-fg-secondary mb-1.5",children:s("work:task.projectLabel")}),n.jsx(Lu,{options:[{value:"",label:s("work:task.noProject")},...N.map(oe=>({value:oe.id,label:oe.name}))],value:mt,onChange:oe=>{it(oe),ht("")},placeholder:s("work:task.noProject"),noMatchesText:s("work:task.noMatches")})]}),n.jsxs("div",{children:[n.jsx("label",{className:"block text-sm text-fg-secondary mb-1.5",children:s("work:task.requirementLabel")}),n.jsx(Lu,{options:[{value:"",label:s("work:task.selectRequirement")},...L.filter(oe=>oe.status==="in_progress"&&(!mt||oe.projectId===mt)).map(oe=>({value:oe.id,label:oe.title}))],value:Lt,onChange:ht,placeholder:s("work:task.selectRequirement"),noMatchesText:s("work:task.noMatches")})]})]}),n.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[n.jsxs("div",{children:[n.jsxs("label",{className:"block text-sm text-fg-secondary mb-1.5",children:[s("work:task.assignToRequired")," ",n.jsx("span",{className:"text-red-500",children:"*"})]}),n.jsx(Lu,{options:D.map(oe=>({value:oe.id,label:`${oe.name} (${oe.status})`})),value:_e,onChange:Ee,placeholder:s("work:task.selectAgent"),noMatchesText:s("work:task.noMatches")})]}),n.jsxs("div",{children:[n.jsxs("label",{className:"block text-sm text-fg-secondary mb-1.5",children:[s("work:task.reviewerRequired")," ",n.jsx("span",{className:"text-red-500",children:"*"})]}),n.jsx(Lu,{options:[...Y.map(oe=>({value:`human:${oe.id}`,label:oe.name})),...D.filter(oe=>oe.id!==_e).map(oe=>({value:`agent:${oe.id}`,label:`${oe.name} (${oe.status})`}))],value:Ye,onChange:Ze,placeholder:s("work:task.selectReviewer"),noMatchesText:s("work:task.noMatches")})]})]}),n.jsxs("div",{className:`grid gap-4 ${be==="scheduled"?"grid-cols-3":"grid-cols-2"}`,children:[n.jsxs("div",{children:[n.jsx("label",{className:"block text-sm text-fg-secondary mb-1.5",children:s("work:task.priorityField")}),n.jsxs("select",{value:Ne,onChange:oe=>he(oe.target.value),className:"w-full px-3 py-2 bg-surface-elevated border border-border-default rounded-lg text-sm focus:border-brand-500 outline-none",children:[n.jsx("option",{value:"low",children:s("work:priority.low")}),n.jsx("option",{value:"medium",children:s("work:priority.medium")}),n.jsx("option",{value:"high",children:s("work:priority.high")}),n.jsx("option",{value:"urgent",children:s("work:priority.urgent")})]})]}),n.jsxs("div",{children:[n.jsx("label",{className:"block text-sm text-fg-secondary mb-1.5",children:s("work:task.taskType")}),n.jsxs("select",{value:be,onChange:oe=>se(oe.target.value),className:"w-full px-3 py-2 bg-surface-elevated border border-border-default rounded-lg text-sm focus:border-brand-500 outline-none",children:[n.jsx("option",{value:"standard",children:s("work:task.taskTypeStandard")}),n.jsx("option",{value:"scheduled",children:s("work:task.taskTypeScheduled")})]})]}),be==="scheduled"&&n.jsxs("div",{children:[n.jsx("label",{className:"block text-sm text-fg-secondary mb-1.5",children:s("work:task.frequency")}),n.jsxs("select",{value:fe,onChange:oe=>He(oe.target.value),className:"w-full px-3 py-2 bg-surface-elevated border border-border-default rounded-lg text-sm focus:border-brand-500 outline-none",children:[n.jsx("option",{value:"30m",children:s("work:task.freq30m")}),n.jsx("option",{value:"1h",children:s("work:task.freq1h")}),n.jsx("option",{value:"2h",children:s("work:task.freq2h")}),n.jsx("option",{value:"4h",children:s("work:task.freq4h")}),n.jsx("option",{value:"8h",children:s("work:task.freq8h")}),n.jsx("option",{value:"12h",children:s("work:task.freq12h")}),n.jsx("option",{value:"1d",children:s("work:task.freq1d")}),n.jsx("option",{value:"1w",children:s("work:task.freq1w")})]})]})]}),n.jsxs("div",{children:[n.jsx("label",{className:"block text-sm text-fg-secondary mb-1.5",children:s("work:task.blockedBy")}),n.jsx(Pre,{options:Object.values(z).flat().filter(oe=>oe.status!=="completed"&&oe.status!=="cancelled").map(oe=>({value:oe.id,label:oe.title})),selected:ne,onAdd:oe=>me([...ne,oe]),placeholder:s("work:task.selectDependency"),noMatchesText:s("work:task.noMatches")}),ne.length>0&&n.jsx("div",{className:"mt-2 flex flex-wrap gap-1.5",children:ne.map(oe=>{const Qe=Object.values(z).flat().find(dt=>dt.id===oe);return n.jsxs("span",{className:"inline-flex items-center gap-1 text-[11px] px-2 py-1 bg-amber-500/10 text-amber-600 rounded-full",children:[Qe?Qe.title.slice(0,30):oe.slice(-8),n.jsx("button",{onClick:()=>me(ne.filter(dt=>dt!==oe)),className:"ml-0.5 text-amber-600/60 hover:text-amber-600",children:"×"})]},oe)})})]}),Ae&&n.jsx("div",{className:"px-3 py-2 bg-red-500/15 text-red-500 text-xs rounded-lg",children:Ae}),n.jsxs("div",{className:"flex justify-end gap-3 pt-1",children:[n.jsx("button",{onClick:()=>{G(!1),et("")},className:"px-4 py-2 text-sm border border-border-default rounded-lg hover:bg-surface-elevated text-fg-secondary",children:s("common:cancel")}),n.jsx("button",{onClick:()=>{va()},disabled:!ue.trim()||!_e||!Ye,className:"px-4 py-2 text-sm bg-brand-600 hover:bg-brand-500 rounded-lg text-white disabled:opacity-50",children:s("common:create")})]})]})}),Dn&&n.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 p-3",onClick:()=>{$n(!1),Bn(""),Qn(""),ye("")},children:n.jsxs("div",{className:`bg-surface-secondary border border-border-default rounded-xl p-6 space-y-4 max-h-[90dvh] overflow-y-auto ${u?"w-full":"w-[28rem]"}`,onClick:oe=>oe.stopPropagation(),children:[n.jsxs("div",{children:[n.jsx("h3",{className:"text-base font-semibold text-fg-primary",children:s("work:task.newRequirementModalTitle")}),n.jsx("p",{className:"text-xs text-fg-tertiary mt-1",children:s("work:task.newRequirementModalHint")})]}),n.jsxs("div",{children:[n.jsxs("label",{className:"block text-sm text-fg-secondary mb-1.5",children:[s("work:task.projectLabel")," ",n.jsx("span",{className:"text-red-500",children:"*"})]}),n.jsx(Lu,{options:N.map(oe=>({value:oe.id,label:oe.name})),value:ve,onChange:tt,placeholder:s("work:task.selectProject"),noMatchesText:s("work:task.noMatches")})]}),n.jsxs("div",{children:[n.jsxs("label",{className:"block text-sm text-fg-secondary mb-1.5",children:[s("work:task.titleField")," ",n.jsx("span",{className:"text-red-500",children:"*"})]}),n.jsx("input",{value:Sn,onChange:oe=>Bn(oe.target.value),placeholder:s("work:task.reqTitleExample"),className:"w-full px-3 py-2 bg-surface-elevated border border-border-default rounded-lg text-sm text-fg-primary focus:border-brand-500 outline-none",autoFocus:!u,onKeyDown:oe=>{oe.key==="Enter"&&Sn.trim()&&is()}})]}),n.jsxs("div",{children:[n.jsxs("label",{className:"block text-sm text-fg-secondary mb-1.5",children:[s("work:task.descriptionField")," ",n.jsx("span",{className:"text-red-500",children:"*"})]}),n.jsx("textarea",{value:Vn,onChange:oe=>Qn(oe.target.value),placeholder:s("work:task.reqDescPlaceholder"),rows:3,className:"w-full px-3 py-2 bg-surface-elevated border border-border-default rounded-lg text-sm text-fg-primary focus:border-brand-500 outline-none resize-none"})]}),n.jsxs("div",{children:[n.jsx("label",{className:"block text-sm text-fg-secondary mb-1.5",children:s("work:task.priorityField")}),n.jsxs("select",{value:Pe,onChange:oe=>Ct(oe.target.value),className:"w-full px-3 py-2 bg-surface-elevated border border-border-default rounded-lg text-sm text-fg-primary focus:border-brand-500 outline-none",children:[n.jsx("option",{value:"low",children:s("work:priority.low")}),n.jsx("option",{value:"medium",children:s("work:priority.medium")}),n.jsx("option",{value:"high",children:s("work:priority.high")}),n.jsx("option",{value:"urgent",children:s("work:priority.urgent")})]})]}),Xt&&n.jsx("div",{className:"px-3 py-2 bg-red-500/15 text-red-500 text-xs rounded-lg",children:Xt}),n.jsxs("div",{className:"flex justify-end gap-3 pt-1",children:[n.jsx("button",{onClick:()=>{$n(!1),Bn(""),Qn(""),ye("")},className:"px-4 py-2 text-sm border border-border-default rounded-lg hover:bg-surface-elevated text-fg-secondary",children:s("common:cancel")}),n.jsx("button",{onClick:()=>{is()},disabled:!Sn.trim()||!Vn.trim()||!ve,className:"px-4 py-2 text-sm bg-brand-600 hover:bg-brand-500 rounded-lg text-white disabled:opacity-40 disabled:cursor-not-allowed",children:s("common:create")})]})]})}),Tt&&n.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 p-3",onClick:()=>{$t(null),vt("")},children:n.jsxs("div",{className:`bg-surface-secondary border border-border-default rounded-xl p-6 space-y-4 ${u?"w-full":"w-96"}`,onClick:oe=>oe.stopPropagation(),children:[n.jsx("h3",{className:"text-base font-semibold text-fg-primary",children:s("work:task.rejectRequirementTitle")}),n.jsxs("div",{children:[n.jsx("label",{className:"block text-sm text-fg-secondary mb-1.5",children:s("work:task.rejectReasonLabel")}),n.jsx("textarea",{value:sn,onChange:oe=>Zn(oe.target.value),placeholder:s("work:task.rejectReasonPlaceholder"),rows:3,className:"w-full px-3 py-2 bg-surface-elevated border border-border-default rounded-lg text-sm text-fg-primary focus:border-red-500 outline-none resize-none",autoFocus:!u})]}),lt&&n.jsx("div",{className:"px-3 py-2 bg-red-500/15 text-red-500 text-xs rounded-lg",children:lt}),n.jsxs("div",{className:"flex justify-end gap-3",children:[n.jsx("button",{onClick:()=>{$t(null),vt("")},className:"px-4 py-2 text-sm border border-border-default rounded-lg hover:bg-surface-elevated text-fg-secondary",children:s("common:cancel")}),n.jsx("button",{onClick:()=>{ai()},className:"px-4 py-2 text-sm bg-red-600 hover:bg-red-500 rounded-lg text-white",children:s("work:task.reject")})]})]})}),tn&&n.jsxs("div",{className:"fixed inset-0 z-[60] flex flex-col justify-end",onClick:()=>zn(!1),children:[n.jsx("div",{className:"absolute inset-0 bg-black/50"}),n.jsxs("div",{className:"relative bg-surface-secondary rounded-t-2xl border-t border-border-default max-h-[70vh] overflow-y-auto pb-16",onClick:oe=>oe.stopPropagation(),children:[n.jsxs("div",{className:"sticky top-0 bg-surface-secondary z-10 px-4 pt-3 pb-2 flex items-center justify-between border-b border-border-default/60",children:[n.jsx("h3",{className:"text-sm font-semibold text-fg-primary",children:s("work:task.filtersSheetTitle")}),n.jsxs("div",{className:"flex items-center gap-2",children:[(Re.size>0||gt.size>0||Et)&&n.jsx("button",{onClick:()=>{We(new Set),rt(new Set),je(!1)},className:"text-[11px] text-brand-500 font-medium",children:s("work:task.clearAll")}),n.jsx("button",{onClick:()=>zn(!1),className:"w-7 h-7 flex items-center justify-center rounded-full bg-surface-elevated text-fg-tertiary",children:n.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),n.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]})]}),N.length>1&&n.jsxs("div",{className:"px-4 py-3",children:[n.jsx("div",{className:"text-[11px] text-fg-tertiary font-medium uppercase tracking-wider mb-2",children:s("work:task.projectsFilterGroup")}),n.jsx("div",{className:"flex flex-wrap gap-1.5",children:ka.map(oe=>{const Qe=Re.has(oe.id),dt=Ri[oe.id]??0;return n.jsxs("div",{className:`flex items-center rounded-lg overflow-hidden transition-all ${Qe?"bg-brand-500/15 ring-1 ring-brand-500/30":""}`,children:[n.jsxs("button",{onClick:()=>kn(oe.id),className:`flex items-center gap-1.5 px-2.5 py-1.5 text-[11px] transition-all ${Qe?"text-brand-600":"bg-surface-elevated text-fg-secondary"}`,children:[n.jsx("span",{className:`w-4 h-4 rounded-sm flex items-center justify-center text-[9px] font-bold shrink-0 ${Qe?"bg-brand-600 text-white":"bg-surface-overlay text-fg-tertiary"}`,children:oe.name[0]?.toUpperCase()}),oe.name,dt>0&&n.jsx("span",{className:"text-[9px] text-fg-tertiary",children:dt})]}),Qe&&n.jsx("button",{onClick:()=>{zn(!1),nr(oe.id)},className:"px-2 py-1.5 self-stretch flex items-center border-l border-brand-500/20 text-fg-tertiary hover:text-brand-600",title:s("work:project.editProject"),children:n.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("path",{d:"M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"}),n.jsx("path",{d:"M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z"})]})})]},oe.id)})})]}),e?.id&&n.jsx("div",{className:"px-4 py-3 border-t border-border-default/40",children:n.jsx("button",{type:"button",onClick:()=>je(oe=>!oe),className:`w-full text-left px-2.5 py-1.5 rounded-lg text-[11px] transition-all ${Et?"bg-green-600/20 text-green-500 ring-1 ring-green-500/40":"bg-surface-elevated text-fg-secondary"}`,children:s("work:task.myTasks")})}),D.length>0&&n.jsxs("div",{className:"px-4 py-3 border-t border-border-default/40",children:[n.jsx("div",{className:"text-[11px] text-fg-tertiary font-medium uppercase tracking-wider mb-2",children:s("work:task.agentsFilterGroup")}),n.jsx("div",{className:"flex flex-wrap gap-1.5",children:zs.map(oe=>{const Qe=gt.has(oe.id);return n.jsxs("button",{onClick:()=>Or(oe.id),className:`flex items-center gap-1.5 px-2.5 py-1.5 rounded-lg text-[11px] transition-all ${Qe?"bg-brand-600/20 text-brand-500 ring-1 ring-brand-500/40":"bg-surface-elevated text-fg-secondary"}`,children:[n.jsx("span",{className:`w-4 h-4 rounded-full flex items-center justify-center text-[9px] font-bold shrink-0 ${Qe?"bg-brand-600 text-white":"bg-surface-overlay text-fg-tertiary"}`,children:oe.name[0]?.toUpperCase()}),oe.name]},oe.id)})})]}),n.jsx("div",{className:"h-[env(safe-area-inset-bottom,0px)]"})]})]})]})}function ese({requirementId:e,createdBy:t,agents:r,users:s,authUser:a}){const{t:i}=pt(["work","common"]),[l,d]=g.useState([]),[u,m]=g.useState([]),h=g.useRef(null),[p,y]=g.useState(new Map);g.useEffect(()=>{m([]),y(new Map),h.current&&(clearTimeout(h.current),h.current=null),ie.requirements.getComments(e).then(w=>d(w.comments)).catch(()=>{})},[e]),g.useEffect(()=>pn.on("requirement:comment",N=>{if(N.payload?.requirementId===e&&N.payload.comment){const S=N.payload.comment;d(T=>T.some(E=>E.id===S.id)?T:[...T,S]),(S.authorType==="agent"||S.authorId?.startsWith("agt_"))&&(m(T=>{const E=T.filter(R=>R.id!==S.authorId);return E.length===0&&h.current&&(clearTimeout(h.current),h.current=null),E}),y(T=>{const E=new Map(T);return E.delete(S.authorId),E}))}}),[e]),g.useEffect(()=>{if(u.length===0)return;const w=new Set(u.map(S=>S.id));return pn.on("agent:activity_log",S=>{const T=S.payload;if(!T)return;const E=T.agentId;if(!w.has(E))return;const R=T.type;if(R==="tool_start"||R==="tool_end"){const z={tool:T.content??T.metadata?.tool??"",phase:R==="tool_start"?"start":"end",success:R==="tool_end"?T.metadata?.success!==!1:void 0,ts:Date.now()};y(B=>{const D=new Map(B),V=[...D.get(E)??[],z];return D.set(E,V),D})}})},[u]);const[x,v]=g.useState(null),j=async(w,N,S,T)=>{let E;S.length>0&&(E=(await ie.uploads.upload(S.map(D=>({dataUrl:D.dataUrl,name:D.name})),"comments")).files.map(D=>({type:"image",url:D.url,name:D.name}))),await ie.requirements.addComment(e,w,a?.name,E,a?.id,N.length>0?N:void 0,T);const R=[],I=new Set,z=B=>{if(I.has(B)||B===a?.id)return;I.add(B);const D=r.find(V=>V.id===B);D&&R.push({id:D.id,name:D.name,avatarUrl:D.avatarUrl})};for(const B of N){const D=r.find(V=>V.name.toLowerCase()===B.toLowerCase());D&&z(D.id)}t?.startsWith("agt_")&&z(t),R.length>0&&(h.current&&clearTimeout(h.current),m(R),h.current=setTimeout(()=>m([]),12e4))},C=g.useCallback(w=>{v({id:w.id,authorName:w.authorName,content:w.content.slice(0,100)})},[]);return n.jsxs("div",{children:[n.jsx("label",{className:"text-[10px] font-semibold text-fg-tertiary uppercase tracking-wider mb-2 block",children:l.length>0?i("work:task.commentsWithCount",{count:l.length}):i("work:task.comments")}),n.jsxs("div",{className:"space-y-0.5 mb-3",children:[l.length===0&&n.jsx("p",{className:"text-xs text-fg-tertiary text-center py-4",children:i("work:task.noCommentsYet")}),l.map(w=>n.jsx(Ju,{comment:w,agents:r,onReply:C},w.id)),u.length>0&&n.jsx("div",{className:"flex flex-col gap-1.5 pt-1",children:u.map(w=>{const N=p.get(w.id)??[];return n.jsxs("div",{className:"px-2 py-1.5 rounded-lg cursor-pointer hover:bg-surface-elevated/60 transition-colors",onClick:()=>bt.navigate(De.TEAM,{agentId:w.id,profileTab:"mind"}),children:[n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsxs("div",{className:"relative shrink-0",children:[n.jsx(Nr,{name:w.name,avatarUrl:w.avatarUrl,size:22,bgClass:"bg-brand-500/15 text-brand-600"}),n.jsx("span",{className:"absolute -bottom-0.5 -right-0.5 w-2 h-2 rounded-full bg-blue-500 animate-pulse ring-2 ring-surface-primary"})]}),n.jsx("span",{className:"text-xs font-medium text-fg-secondary",children:w.name}),N.length===0&&n.jsxs("span",{className:"flex items-center gap-0.5",children:[n.jsx("span",{className:"w-1 h-1 rounded-full bg-blue-400 animate-bounce"}),n.jsx("span",{className:"w-1 h-1 rounded-full bg-blue-400 animate-bounce",style:{animationDelay:"0.15s"}}),n.jsx("span",{className:"w-1 h-1 rounded-full bg-blue-400 animate-bounce",style:{animationDelay:"0.3s"}})]}),n.jsx("span",{className:"text-[10px] text-fg-tertiary",children:i("work:task.agentProcessing")}),n.jsx("span",{className:"ml-auto text-[10px] text-fg-tertiary",children:"→"})]}),N.length>0&&n.jsx("div",{className:"ml-8 mt-1",children:n.jsx(Wh,{activities:N,isActive:!0})})]},w.id)})})]}),n.jsx($S,{agents:r,humans:s,onSubmit:j,replyTo:x,onCancelReply:()=>v(null)})]})}function q3({req:e,agents:t,projects:r,allTasks:s,users:a,onClose:i,onApprove:l,onReject:d,onCancel:u,onStatusChange:m,onRefresh:h,authUser:p,scrollToComments:y,onScrollToCommentsDone:x,onTaskClick:v,onCreateTask:j,onProjectClick:C,previewMode:w}){const{t:N}=pt(["work","common"]),S=g.useMemo(()=>Iy(N),[N]),T=g.useMemo(()=>tC(N),[N]),E=Rs(),[R,I]=g.useState(!1),[z,B]=g.useState(e.description),[D,V]=g.useState(!1),[Y,F]=g.useState(!1),L=g.useRef(null),[O,M]=g.useState("none"),$=g.useRef(null),W=g.useRef(null),U=g.useRef(80);g.useEffect(()=>{const G=L.current;if(!G)return;const ue=()=>{const{scrollTop:Ce,scrollHeight:Be,clientHeight:Ne}=G;if(!(Be>Ne+50)){M("none");return}const _e=Ce<30,Ee=Ce+Ne>=Be-30;M(_e?"top":Ee?"bottom":"middle")};ue(),G.addEventListener("scroll",ue,{passive:!0});const Se=new ResizeObserver(ue);return Se.observe(G),()=>{G.removeEventListener("scroll",ue),Se.disconnect()}},[]),g.useEffect(()=>{if(R&&W.current){const G=W.current;G.style.height="auto",G.style.height=Math.max(G.scrollHeight,U.current)+"px",G.focus()}},[R]),g.useEffect(()=>{if(!y)return;const G=setTimeout(()=>{const ue=L.current;ue&&ue.scrollTo({top:ue.scrollHeight,behavior:"smooth"}),x?.()},300);return()=>clearTimeout(G)},[y,x]);const H=S[e.status]??{label:e.status,cls:"bg-gray-500/15 text-fg-secondary"},q=e.source==="agent",Z=q&&e.status==="pending",_=e.status==="pending"||e.status==="in_progress",J=e.status==="completed"||e.status==="rejected"||e.status==="cancelled"||e.status==="archived",X=e.projectId?r.find(G=>G.id===e.projectId):null,ee=Rd(e.createdBy,t,a)??e.createdBy.slice(0,12),te=s.filter(G=>e.taskIds.includes(G.id));return g.useEffect(()=>{B(e.description),I(!1)},[e.id,e.description]),n.jsxs("div",{className:"flex flex-col w-full h-full overflow-hidden bg-surface-primary shadow-xl shadow-black/8 ring-1 ring-border-default/20",children:[n.jsxs("div",{className:"flex items-start justify-between gap-4 p-5 pb-0 border-b border-border-default",children:[n.jsxs("div",{className:"flex items-center gap-2 flex-1 min-w-0",children:[E&&n.jsx("button",{onClick:()=>history.back(),className:"text-fg-secondary hover:text-fg-primary transition-colors p-1 -ml-1 shrink-0",children:n.jsx("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:n.jsx("polyline",{points:"15 18 9 12 15 6"})})}),n.jsxs("h2",{className:"flex-1 min-w-0 pb-4 text-lg font-semibold text-fg-primary leading-snug",children:[e.title," ",n.jsx("span",{className:"text-[10px] font-bold text-brand-500 bg-brand-500/15 px-2 py-0.5 rounded align-middle",children:N("work:task.requirementShort")})," ",n.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded-full font-medium align-middle ${H.cls}`,children:H.label})," ",e.priority==="high"||e.priority==="urgent"?n.jsx("span",{className:`text-[10px] font-medium align-middle ${e.priority==="urgent"?"text-red-500":"text-amber-600"}`,children:N("common:priority."+e.priority,{defaultValue:e.priority})}):n.jsx("span",{className:"text-[10px] text-fg-tertiary align-middle",children:N("common:priority."+e.priority,{defaultValue:e.priority})})]})]}),n.jsx("button",{onClick:i,className:"text-fg-tertiary hover:text-fg-secondary text-xl leading-none shrink-0 mt-1",children:"×"})]}),n.jsxs("div",{className:"flex-1 min-h-0 relative",children:[n.jsxs("div",{ref:L,className:"h-full overflow-y-auto p-5 space-y-4",children:[n.jsxs("div",{children:[n.jsx("label",{className:"text-[10px] font-semibold text-fg-tertiary uppercase tracking-wider mb-1 block",children:N("work:task.requirementDetailDescription")}),R?n.jsx("textarea",{ref:W,value:z,onChange:G=>{B(G.target.value);const ue=G.target;ue.style.height="auto",ue.style.height=ue.scrollHeight+"px"},onBlur:async()=>{if(z!==e.description){V(!0);try{await ie.requirements.update(e.id,{description:z}),h?.()}catch{}finally{V(!1)}}I(!1)},onKeyDown:G=>{G.key==="Escape"&&(G.preventDefault(),B(e.description),I(!1))},className:"w-full bg-transparent border border-brand-500/30 rounded-lg text-sm text-fg-primary focus:border-brand-500 outline-none resize-none -mx-2 px-2 -my-1 py-1",placeholder:N("work:task.requirementDetailDescription")}):n.jsx("div",{ref:$,className:`group relative rounded-lg -mx-2 px-2 -my-1 py-1 transition-colors ${J?"":"cursor-pointer hover:bg-surface-elevated/50"}`,onClick:J?void 0:G=>{G.target.closest("a, button, [data-entity-link]")||(U.current=Math.max($.current?.offsetHeight??80,60),B(e.description),I(!0))},role:J?void 0:"button",tabIndex:J?void 0:0,onKeyDown:J?void 0:G=>G.key==="Enter"&&(B(e.description),I(!0)),children:e.description?n.jsx(Wr,{content:e.description,className:"text-sm text-fg-secondary leading-relaxed"}):n.jsx("p",{className:"text-sm text-fg-tertiary italic",children:N("work:task.requirementNoDescription")})})]}),n.jsxs("div",{className:"grid grid-cols-2 gap-3 text-xs",children:[n.jsxs("div",{className:"bg-surface-elevated/60 rounded-lg p-2.5",children:[n.jsx("span",{className:"text-[10px] text-fg-tertiary block mb-1",children:N("work:task.createdByLabel")}),n.jsx("span",{className:"text-fg-secondary",children:ee}),q&&n.jsx("span",{className:"text-[10px] text-brand-500 ml-1.5",children:N("work:task.agentTag")})]}),n.jsxs("div",{className:"bg-surface-elevated/60 rounded-lg p-2.5",children:[n.jsx("span",{className:"text-[10px] text-fg-tertiary block mb-1",children:N("work:task.createdLabel")}),n.jsx("span",{className:"text-fg-secondary",children:new Date(e.createdAt).toLocaleString()})]}),X&&n.jsxs("div",{className:`bg-surface-elevated/60 rounded-lg p-2.5 ${C?"cursor-pointer hover:bg-surface-elevated transition-colors":""}`,onClick:C?()=>C(X.id):void 0,role:C?"button":void 0,tabIndex:C?0:void 0,onKeyDown:C?G=>G.key==="Enter"&&C(X.id):void 0,children:[n.jsx("span",{className:"text-[10px] text-fg-tertiary block mb-1",children:N("work:task.projectLabel")}),n.jsx("span",{className:"text-fg-secondary",children:X.name})]}),e.approvedBy&&n.jsxs("div",{className:"bg-surface-elevated/60 rounded-lg p-2.5",children:[n.jsx("span",{className:"text-[10px] text-fg-tertiary block mb-1",children:N("work:task.approvedBy")}),n.jsx("span",{className:"text-fg-secondary",children:Rd(e.approvedBy,t,a)??e.approvedBy.slice(0,12)}),e.approvedAt&&n.jsx("span",{className:"text-[10px] text-fg-tertiary ml-1",children:new Date(e.approvedAt).toLocaleDateString()})]})]}),e.rejectedReason&&n.jsxs("div",{className:"bg-red-500/10 border border-red-500/20 rounded-lg p-3",children:[n.jsx("span",{className:"text-[10px] font-semibold text-red-500 uppercase tracking-wider block mb-1",children:N("work:task.rejectionReason")}),n.jsx("p",{className:"text-sm text-red-500/80",children:e.rejectedReason})]}),Array.isArray(e.tags)&&e.tags.length>0&&n.jsx("div",{className:"flex flex-wrap gap-1",children:e.tags.map(G=>n.jsxs("span",{className:"text-[10px] bg-surface-elevated text-fg-secondary px-2 py-0.5 rounded-full",children:["#",G]},G))}),n.jsxs("div",{children:[n.jsxs("div",{className:"flex items-center justify-between mb-2",children:[n.jsx("label",{className:"text-[10px] font-semibold text-fg-tertiary uppercase tracking-wider",children:N("work:task.linkedTasks",{count:te.length})}),!J&&j&&n.jsxs("button",{onClick:()=>j(e.id,e.projectId),className:"text-[11px] text-amber-500 hover:text-amber-400 font-medium flex items-center gap-1",children:[n.jsx("svg",{className:"w-3 h-3",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:n.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 4v16m8-8H4"})}),N("work:requirement.createTask")]})]}),te.length>0?(()=>{const G=new Map(te.map(he=>[he.id,he]));if(!te.some(he=>he.blockedBy?.some(_e=>G.has(_e))))return n.jsx("div",{className:"space-y-1.5",children:te.map(he=>{const _e=T[he.status];return n.jsxs("div",{onClick:()=>v?.(he),className:`flex items-center gap-2 bg-surface-elevated/60 rounded-lg px-3 py-2 ${v?"cursor-pointer hover:bg-surface-elevated transition-colors":""}`,children:[n.jsx("span",{className:`w-1.5 h-1.5 rounded-full shrink-0 ${j0[he.status]??"bg-gray-500"}`}),n.jsx("span",{className:"text-xs text-fg-secondary flex-1 truncate",children:he.title}),_e&&n.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded shrink-0 ${_e.cls}`,children:_e.label})]},he.id)})});const Se=new Map,Ce=new Set;for(const he of te)for(const _e of he.blockedBy??[])if(G.has(_e)){Ce.add(he.id);const Ee=Se.get(_e)??[];Ee.push(he.id),Se.set(_e,Ee)}const Be=te.filter(he=>!Ce.has(he.id)),Ne=(he,_e)=>{const Ee=T[he.status],Ye=(Se.get(he.id)??[]).map(Ze=>G.get(Ze)).filter(Boolean);return n.jsxs("div",{children:[n.jsxs("div",{onClick:()=>v?.(he),className:`flex items-center gap-2 bg-surface-elevated/60 rounded-lg px-3 py-2 ${v?"cursor-pointer hover:bg-surface-elevated transition-colors":""}`,style:_e>0?{marginLeft:_e*20}:void 0,children:[_e>0&&n.jsx("span",{className:"text-fg-quaternary text-[10px] shrink-0",children:"↳"}),n.jsx("span",{className:`w-1.5 h-1.5 rounded-full shrink-0 ${j0[he.status]??"bg-gray-500"}`}),n.jsx("span",{className:"text-xs text-fg-secondary flex-1 truncate",children:he.title}),Ee&&n.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded shrink-0 ${Ee.cls}`,children:Ee.label})]}),Ye.map(Ze=>Ne(Ze,_e+1))]},he.id)};return n.jsx("div",{className:"space-y-1.5",children:Be.map(he=>Ne(he,0))})})():n.jsx("div",{className:"text-xs text-fg-tertiary italic py-2",children:N("work:requirement.noLinkedTasks")})]}),!w&&n.jsx(ese,{requirementId:e.id,createdBy:e.createdBy,agents:t,users:a,authUser:p}),!w&&n.jsx(sC,{entityType:"requirement",entityId:e.id})]}),O!=="none"&&O!=="top"&&n.jsx("button",{onClick:()=>L.current?.scrollTo({top:0,behavior:"smooth"}),className:"absolute bottom-20 right-4 md:bottom-14 md:right-3 z-10 w-12 h-12 md:w-8 md:h-8 rounded-full bg-brand-500 md:bg-brand-600/90 border border-brand-400/60 shadow-xl shadow-brand-500/30 md:shadow-lg md:shadow-brand-500/20 flex items-center justify-center text-white hover:bg-brand-400 transition-colors backdrop-blur-sm",title:N("work:task.scrollToTop"),children:n.jsx("svg",{className:"w-6 h-6 md:w-4 md:h-4",viewBox:"0 0 20 20",fill:"currentColor",children:n.jsx("path",{fillRule:"evenodd",d:"M14.77 12.79a.75.75 0 01-1.06-.02L10 8.832l-3.71 3.938a.75.75 0 11-1.08-1.04l4.25-4.5a.75.75 0 011.08 0l4.25 4.5a.75.75 0 01-.02 1.06z",clipRule:"evenodd"})})}),O!=="none"&&O!=="bottom"&&n.jsx("button",{onClick:()=>{const G=L.current;G&&G.scrollTo({top:G.scrollHeight,behavior:"smooth"})},className:"absolute bottom-6 right-4 md:bottom-4 md:right-3 z-10 w-12 h-12 md:w-8 md:h-8 rounded-full bg-brand-500 md:bg-brand-600/90 border border-brand-400/60 shadow-xl shadow-brand-500/30 md:shadow-lg md:shadow-brand-500/20 flex items-center justify-center text-white hover:bg-brand-400 transition-colors backdrop-blur-sm",title:N("work:task.scrollToBottom"),children:n.jsx("svg",{className:"w-6 h-6 md:w-4 md:h-4",viewBox:"0 0 20 20",fill:"currentColor",children:n.jsx("path",{fillRule:"evenodd",d:"M5.23 7.21a.75.75 0 011.06.02L10 11.168l3.71-3.938a.75.75 0 111.08 1.04l-4.25 4.5a.75.75 0 01-1.08 0l-4.25-4.5a.75.75 0 01.02-1.06z",clipRule:"evenodd"})})})]}),n.jsxs("div",{className:"flex items-center gap-2 p-5 pt-3 border-t border-border-default",children:[Z&&n.jsxs(n.Fragment,{children:[n.jsx("button",{onClick:()=>l(e.id),className:"px-4 py-2 bg-green-600 hover:bg-green-500 text-white text-sm rounded-lg font-medium transition-colors",children:N("work:requirement.approveRequirement")}),n.jsx("button",{onClick:()=>d(e.id),className:"px-4 py-2 border border-red-500/30 hover:bg-red-500/10 text-red-500 text-sm rounded-lg font-medium transition-colors",children:N("work:requirement.rejectRequirement")})]}),!Z&&m&&!J&&n.jsx("select",{value:e.status,onChange:G=>{G.target.value!==e.status&&m(e.id,G.target.value)},className:"px-2 py-1.5 text-xs bg-surface-elevated border border-border-default rounded-lg text-fg-secondary cursor-pointer hover:border-gray-500 transition-colors",children:Qre.map(G=>{const ue=S[G],Se=G===e.status||(y1[e.status]?.has(G)??!1);return n.jsx("option",{value:G,disabled:!Se,children:ue?.label??G},G)})}),J&&m&&n.jsx("button",{onClick:()=>m(e.id,"in_progress"),className:"px-3 py-1.5 text-xs border border-border-default hover:bg-surface-elevated rounded-lg text-fg-secondary transition-colors",children:N("work:task.reopen")}),n.jsx("div",{className:"flex-1"}),_&&!Z&&n.jsx("button",{onClick:()=>F(!0),className:"px-3 py-1.5 text-xs text-red-500/70 hover:text-red-500 hover:bg-red-500/10 border border-transparent hover:border-red-500/20 rounded-lg transition-colors",children:N("work:task.cancelRequirement")})]}),Y&&n.jsx(ud,{title:N("work:requirement.cancelConfirmTitle","Cancel Requirement"),message:N("work:requirement.cancelConfirmMessage","Are you sure you want to cancel this requirement? This action cannot be undone."),confirmLabel:N("work:requirement.cancelConfirmLabel","Cancel Requirement"),onConfirm:()=>{F(!1),u(e.id)},onCancel:()=>F(!1)})]})}function sC({entityType:e,entityId:t}){const{t:r}=pt(["work"]),[s,a]=g.useState([]),[i,l]=g.useState(!0),[d,u]=g.useState(!1);if(g.useEffect(()=>{l(!0),(e==="task"?ie.tasks.getHistory:ie.requirements.getHistory)(t).then(x=>a(x.history)).catch(()=>a([])).finally(()=>l(!1))},[e,t]),i)return n.jsx("div",{className:"px-6 py-4 text-xs text-fg-tertiary",children:r("work:task.loadingHistory","Loading history...")});if(s.length===0)return n.jsx("div",{className:"px-6 py-4 text-xs text-fg-tertiary italic",children:r("work:task.noHistory","No status change history.")});const m=d?s:s.slice(-5),h=s.length>5&&!d,p=y=>{const x=y.changedByName||y.changedById||(y.changedByType==="human"?"User":y.changedByType==="agent"?"Agent":"System"),v=y.changedByType==="human"?"bg-blue-500/20 text-blue-500":y.changedByType==="agent"?"bg-brand-500/20 text-brand-500":"bg-gray-500/20 text-fg-tertiary";return n.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded-full font-medium shrink-0 ${v}`,children:x})};return n.jsxs("div",{className:"px-6 py-4",children:[n.jsx("p",{className:"text-xs font-semibold text-fg-tertiary uppercase tracking-wider mb-3",children:r("work:task.statusHistory","Status History")}),h&&n.jsx("button",{onClick:()=>u(!0),className:"text-[11px] text-brand-500 hover:underline mb-2",children:r("work:task.showAllHistory",{count:s.length})}),n.jsxs("div",{className:"relative ml-2",children:[n.jsx("div",{className:"absolute left-[2.5px] top-1 bottom-1 w-px bg-border-default"}),n.jsx("div",{className:"space-y-3",children:m.map(y=>n.jsxs("div",{className:"flex items-start gap-3 relative",children:[n.jsx("div",{className:"w-1.5 h-1.5 rounded-full mt-[7px] shrink-0 relative z-10",style:{background:y.changedByType==="human"?"#3b82f6":y.changedByType==="agent"?"var(--color-brand-500)":"#6b7280"}}),n.jsxs("div",{className:"flex-1 min-w-0",children:[n.jsxs("div",{className:"flex items-center gap-1.5 flex-wrap",children:[p(y),n.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded bg-surface-elevated text-fg-tertiary line-through",children:y.fromStatus}),n.jsx("span",{className:"text-[10px] text-fg-tertiary",children:"→"}),n.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded bg-brand-500/15 text-brand-500 font-medium",children:y.toStatus})]}),y.reason&&n.jsx("p",{className:"text-[10px] text-fg-secondary mt-0.5 leading-snug",children:y.reason}),n.jsx("p",{className:"text-[9px] text-fg-tertiary mt-0.5",children:new Date(y.createdAt).toLocaleString()})]})]},y.id))})]})]})}function Hi(e){return Array.isArray(e)?e.map(t=>String(t).trim()).filter(Boolean):typeof e=="string"&&e?e.split(",").map(t=>t.trim()).filter(Boolean):[]}function tse(e){return e.files&&typeof e.files=="object"&&!Array.isArray(e.files)?e.files:null}function Ql({label:e,value:t}){return t?n.jsxs("div",{children:[n.jsx("span",{className:"text-[10px] text-fg-tertiary uppercase tracking-wider",children:e}),n.jsx("div",{className:"text-xs text-fg-secondary mt-0.5",children:t})]}):null}function sd({label:e,value:t,color:r}){if(!t)return null;const s={purple:"bg-brand-500/15 text-brand-500",cyan:"bg-blue-500/15 text-blue-600",indigo:"bg-brand-500/15 text-brand-500",gray:"bg-gray-500/15 text-fg-secondary",emerald:"bg-green-500/15 text-green-600"};return n.jsxs("div",{children:[n.jsx("span",{className:"text-[10px] text-fg-tertiary uppercase tracking-wider",children:e}),n.jsx("div",{className:`mt-0.5 px-2 py-0.5 rounded-full text-[10px] font-medium ${s[r]??s.gray} capitalize inline-block`,children:t})]})}function lb({files:e}){const{t}=pt(["builder","common"]),[r,s]=g.useState(Object.keys(e)[0]??""),a=Object.keys(e);return a.length===0?null:n.jsxs("div",{children:[n.jsx("span",{className:"text-[10px] text-fg-tertiary uppercase tracking-wider",children:t("builder:artifact.files",{count:a.length})}),n.jsxs("div",{className:"mt-1 bg-surface-elevated/50 rounded-lg border border-border-default/30 overflow-hidden",children:[n.jsx("div",{className:"flex gap-0.5 px-1.5 py-1 border-b border-border-default/30 overflow-x-auto",children:a.map(i=>n.jsx("button",{onClick:()=>s(i),className:`px-2 py-0.5 text-[10px] rounded whitespace-nowrap transition-colors ${r===i?"bg-brand-600/30 text-brand-500":"text-fg-tertiary hover:text-fg-secondary"}`,children:i},i))}),r&&e[r]!=null&&n.jsx("pre",{className:"p-2 text-[10px] text-fg-secondary max-h-[120px] overflow-auto whitespace-pre-wrap font-mono",children:e[r]})]})]})}function nse({artifact:e,mode:t}){const{t:r}=pt(["builder","common"]),s=tse(e),a=e.agent,i=e.team,l=e.dependencies,d=e.displayName??e.name;if(t==="agent"){const u=a?.roleName,m=a?.agentRole,h=a?.llmProvider,p=a?.llmModel,y=Hi(l?.env),x=Hi(l?.skills);return n.jsxs("div",{className:"space-y-3 text-sm",children:[n.jsx(Ql,{label:r("builder:artifact.name"),value:d}),n.jsx(Ql,{label:r("builder:artifact.description"),value:e.description}),n.jsxs("div",{className:"flex flex-wrap gap-2",children:[u&&n.jsx(sd,{label:r("builder:artifact.baseTemplate"),value:u,color:"indigo"}),n.jsx(sd,{label:r("builder:artifact.agentRole"),value:m,color:m==="manager"?"purple":"cyan"})]}),Hi(e.tags).length>0&&n.jsx("div",{className:"flex flex-wrap gap-1",children:Hi(e.tags).map(v=>n.jsx("span",{className:"px-1.5 py-0.5 text-[10px] bg-surface-elevated text-fg-tertiary rounded",children:v},v))}),(h||p)&&n.jsxs("div",{className:"flex gap-2",children:[h&&n.jsx(sd,{label:r("builder:artifact.llmProvider"),value:h,color:"gray"}),p&&n.jsx(sd,{label:r("builder:artifact.llmModel"),value:p,color:"gray"})]}),y.length>0&&n.jsxs("div",{children:[n.jsx("span",{className:"text-[10px] text-fg-tertiary uppercase tracking-wider",children:r("builder:artifact.requiredEnv")}),n.jsx("div",{className:"flex flex-wrap gap-1 mt-1",children:y.map(v=>n.jsx("span",{className:"px-1.5 py-0.5 text-[10px] bg-amber-500/10 text-amber-600 rounded font-mono",children:v},v))})]}),x.length>0&&n.jsx(Ql,{label:r("builder:artifact.skills"),value:x.join(", ")}),s&&n.jsx(lb,{files:s})]})}if(t==="team"){const m=i?.members??[];return n.jsxs("div",{className:"space-y-3 text-sm",children:[n.jsx(Ql,{label:r("builder:artifact.name"),value:d}),n.jsx(Ql,{label:r("builder:artifact.description"),value:e.description}),n.jsx("div",{className:"flex flex-wrap gap-2",children:n.jsx(sd,{label:r("builder:artifact.category"),value:e.category,color:"indigo"})}),Hi(e.tags).length>0&&n.jsx("div",{className:"flex flex-wrap gap-1",children:Hi(e.tags).map(h=>n.jsx("span",{className:"px-1.5 py-0.5 text-[10px] bg-surface-elevated text-fg-tertiary rounded",children:h},h))}),s&&n.jsx(lb,{files:s}),n.jsxs("div",{children:[n.jsx("span",{className:"text-[10px] text-fg-tertiary uppercase tracking-wider",children:r("builder:artifact.members",{count:m.length})}),n.jsx("div",{className:"mt-1.5 space-y-1.5",children:m.map((h,p)=>n.jsxs("div",{className:"bg-surface-elevated/30 rounded-lg px-2 py-1.5 border border-border-default/20",children:[n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx("span",{className:`w-5 h-5 rounded flex items-center justify-center text-[10px] font-bold ${h.role==="manager"?"bg-brand-500/20 text-brand-500":"bg-blue-500/20 text-blue-600"}`,children:h.role==="manager"?"★":p+1}),n.jsx("span",{className:"text-xs text-fg-secondary flex-1 truncate",children:h.name}),typeof h.roleName=="string"&&h.roleName&&n.jsx("span",{className:"text-[10px] text-brand-500/70 font-mono",children:h.roleName}),n.jsxs("span",{className:"text-[10px] text-fg-tertiary",children:["x",String(h.count??1)]})]}),Hi(h.skills).length>0&&n.jsx("div",{className:"mt-1 ml-7 flex flex-wrap gap-1",children:Hi(h.skills).map(y=>n.jsx("span",{className:"px-1 py-0.5 text-[9px] bg-green-500/10 text-green-600 rounded font-mono",children:y},y))})]},p))})]})]})}return n.jsxs("div",{className:"space-y-3 text-sm",children:[n.jsx(Ql,{label:r("builder:artifact.name"),value:d}),n.jsx(Ql,{label:r("builder:artifact.description"),value:e.description}),n.jsx("div",{className:"flex gap-2",children:n.jsx(sd,{label:r("builder:artifact.category"),value:e.category,color:"indigo"})}),s&&n.jsx(lb,{files:s}),Hi(e.tags).length>0&&n.jsx("div",{className:"flex flex-wrap gap-1",children:Hi(e.tags).map(u=>n.jsx("span",{className:"px-1.5 py-0.5 text-[10px] bg-surface-elevated text-fg-tertiary rounded",children:u},u))})]})}const Pu={file:{icon:"📄",color:"bg-green-500/10 text-green-600"},directory:{icon:"📁",color:"bg-blue-500/10 text-blue-600"}},rse={active:{color:"text-green-600 bg-green-500/10"},verified:{color:"text-blue-600 bg-blue-500/10"},outdated:{color:"text-red-500 bg-red-500/10"}},sse=["file","directory"];function Tf(e){return/^https?:\/\//i.test(e)}const Zl={agent:{icon:"✦",color:"bg-brand-500/10 text-brand-500"},team:{icon:"◈",color:"bg-blue-500/10 text-blue-600"},skill:{icon:"⬡",color:"bg-amber-500/10 text-amber-600"}};function U3({authUser:e,previewMode:t,previewData:r}={}){const{t:s}=pt(["deliverables","common"]),a=Rs(),i=Id(De.DELIVERABLES),l=f0({side:"left",defaultWidth:384,minWidth:280,maxWidth:600,storageKey:"markus_deliverables_list"}),[d,u]=g.useState(!1),m=g.useRef(d);m.current=d,g.useEffect(()=>{if(!a)return;const Ge=()=>{m.current&&u(!1)};return window.addEventListener("popstate",Ge),()=>window.removeEventListener("popstate",Ge)},[a]);const h=100,[p,y]=g.useState(r?.items??[]),[x,v]=g.useState(r?.items?.length??0),[j,C]=g.useState(!1),[w,N]=g.useState(r?.projects??[]),[S,T]=g.useState(r?.agents??[]),[E,R]=g.useState(!r),[I,z]=g.useState(""),[B,D]=g.useState(""),[V,Y]=g.useState(""),[F,L]=g.useState(""),[O,M]=g.useState(""),[$,W]=g.useState(""),[U,H]=g.useState(""),[q,Z]=g.useState("date"),[_,J]=g.useState(()=>r?.initialSelectedId&&r.items?r.items.find(Ge=>Ge.id===r.initialSelectedId)??r.items[0]??null:r?.items?.[0]??null),[X,ee]=g.useState(null),[te,G]=g.useState(""),[ue,Se]=g.useState(new Set),Ce=g.useMemo(()=>[{id:"date"},{id:"project"},{id:"agent"},{id:"type"}],[]),Be=g.useCallback(Ge=>{Z(Ge),Se(new Set)},[]),Ne=Sl(Ce,q,Be),he=g.useRef(null),[_e,Ee]=g.useState(null),[Ye,Ze]=g.useState("markdown"),[mt,it]=g.useState(null),[Lt,ht]=g.useState(!1),[ne,me]=g.useState(!1),[be,se]=g.useState(!1),[fe,He]=g.useState(null),[Ae,et]=g.useState(""),[pe,Fe]=g.useState(new Set),Ve=g.useRef(void 0),nt=(Ge,Ht)=>{ee({type:Ge,text:Ht}),setTimeout(()=>ee(null),3e3)},gt=async Ge=>{await iy(Ge)?(se(!0),setTimeout(()=>se(!1),1500)):nt("error",s("detail.copyFailed"))},rt=g.useMemo(()=>new Map(S.map(Ge=>[Ge.id,Ge])),[S]),Et=g.useMemo(()=>new Map(w.map(Ge=>[Ge.id,Ge])),[w]),je=g.useCallback(Ge=>{if(!Ge||Ge==="default")return null;const Ht=Et.get(Ge)?.name;return!Ht||Ht==="default"?null:Ht},[Et]);g.useEffect(()=>{t||(ie.projects.list().then(Ge=>N(Ge.projects)).catch(()=>{}),ie.agents.list().then(Ge=>T(Ge.agents??[])).catch(()=>{}),ie.system.storage().then(Ge=>et(Ge.dataDir+"/shared")).catch(()=>{}),ie.deliverables.checkHealth().then(Ge=>Fe(new Set(Ge.missingFiles))).catch(()=>{}))},[t]),g.useEffect(()=>(Ve.current=setTimeout(()=>D(I),300),()=>clearTimeout(Ve.current)),[I]);const Re=g.useMemo(()=>({q:B||void 0,projectId:F||void 0,agentId:O||void 0,type:V||void 0,status:$||void 0,artifactType:U||void 0}),[B,F,O,V,$,U]),We=g.useCallback(async()=>{R(!0);try{const{results:Ge,total:Ht}=await ie.deliverables.search({...Re,offset:0,limit:h});y(Ge),v(Ht)}catch{y([]),v(0)}R(!1)},[Re]),Vt=g.useCallback(async()=>{if(!(j||p.length>=x)){C(!0);try{const{results:Ge,total:Ht}=await ie.deliverables.search({...Re,offset:p.length,limit:h});y(Wt=>[...Wt,...Ge]),v(Ht)}catch{}C(!1)}},[Re,p.length,x,j]);g.useEffect(()=>{t||We()},[We,t]),g.useEffect(()=>{!t||!r||(y(r.items??[]),v(r.items?.length??0),N(r.projects??[]),T(r.agents??[]),r.initialSelectedId&&J(r.items?.find(Ge=>Ge.id===r.initialSelectedId)??r.items?.[0]??null))},[t,r]),g.useEffect(()=>{if(t||!i)return;const Ge=pn.on("deliverable:created",()=>We()),Ht=pn.on("deliverable:updated",()=>We()),Wt=pn.on("deliverable:removed",()=>We());return()=>{Ge(),Ht(),Wt()}},[We,i,t]);const ln=g.useRef(null),en=g.useRef(p);en.current=p;const vn=g.useCallback(Ge=>{const Ht=tn=>{J(tn),a&&(u(!0),history.pushState({mobileDetail:De.DELIVERABLES},"",window.location.hash))},Wt=en.current.find(tn=>tn.id===Ge);if(Wt){Ht(Wt);return}ie.deliverables.get(Ge).then(tn=>{tn.deliverable&&Ht(tn.deliverable)}).catch(()=>{})},[a]);g.useEffect(()=>{if(t)return;const Ge=localStorage.getItem("markus_nav_openDeliverable");Ge&&(localStorage.removeItem("markus_nav_openDeliverable"),en.current.length>0?vn(Ge):ln.current=Ge);const Ht=Wt=>{const tn=Wt.detail;tn?.params?.openDeliverable&&(localStorage.removeItem("markus_nav_openDeliverable"),vn(tn.params.openDeliverable))};return window.addEventListener("markus:navigate",Ht),()=>window.removeEventListener("markus:navigate",Ht)},[vn,t]),g.useEffect(()=>{const Ge=ln.current;!Ge||p.length===0||(ln.current=null,vn(Ge))},[p,vn]);const In=g.useCallback(()=>{const Ge=he.current;!Ge||E||j||p.length>=x||Ge.scrollHeight<=Ge.clientHeight+100&&Vt()},[E,j,p.length,x,Vt]);g.useEffect(()=>{const Ge=he.current;if(!Ge)return;const Ht=()=>{Ge.scrollTop+Ge.clientHeight>=Ge.scrollHeight-100&&Vt()};return Ge.addEventListener("scroll",Ht,{passive:!0}),()=>Ge.removeEventListener("scroll",Ht)},[Vt]),g.useEffect(()=>{In()},[In,ue]);const Zt=g.useMemo(()=>{const Ge=new Map;for(const Wt of p){let tn,zn;if(q==="project"){const Mn=je(Wt.projectId);tn=Mn?Wt.projectId??"_none":"_none",zn=Mn??s("noProject")}else if(q==="agent")tn=Wt.agentId??"_none",zn=Wt.agentId?rt.get(Wt.agentId)?.name??Wt.agentId:s("common:unknown");else if(q==="type")tn=Wt.type,zn=Wt.type.charAt(0).toUpperCase()+Wt.type.slice(1);else{const Mn=new Date(Wt.updatedAt);tn=`${Mn.getFullYear()}-${String(Mn.getMonth()+1).padStart(2,"0")}-${String(Mn.getDate()).padStart(2,"0")}`,zn=tn}Ge.has(tn)||Ge.set(tn,{label:zn,items:[]}),Ge.get(tn).items.push(Wt)}const Ht=[...Ge.entries()];return q==="date"?Ht.sort((Wt,tn)=>tn[0].localeCompare(Wt[0])):Ht.sort((Wt,tn)=>Wt[1].label.localeCompare(tn[1].label)),Ht},[p,q,Et,rt,s]),cn=async Ge=>{G("remove");try{await ie.deliverables.remove(Ge.id),nt("success",s("removed")),J(null),We()}catch(Ht){nt("error",s("common:error",{message:String(Ht)}))}G("")},Gn=()=>{bt.navigate(De.BUILDER)},Ln=async Ge=>{if(Ge.reference&&!Tf(Ge.reference)){if(Ge.type==="directory"){me(!0);return}ht(!0);try{const Ht=await ie.files.preview(Ge.reference);Ht.type==="image"&&Ht.mimeType?it({src:`data:${Ht.mimeType};base64,${Ht.content}`,name:Ht.name}):(Ee(Ht.content),Ze(d7({format:Ge.format,reference:Ge.reference,content:Ht.content})))}catch{Ee(null),Ge.type==="file"&&me(!0)}ht(!1)}};g.useEffect(()=>{t||(Ee(null),Ze("markdown"),it(null),me(!1),_&&Ln(_))},[_?.id,t]);const Lr=g.useCallback(Ge=>{Se(Ht=>{const Wt=new Set(Ht);return Wt.has(Ge)?Wt.delete(Ge):Wt.add(Ge),Wt})},[]),Qr=g.useCallback(()=>{ue.size===Zt.length?Se(new Set):Se(new Set(Zt.map(([Ge])=>Ge)))},[ue.size,Zt]),mr=Ge=>{J(Ge),a&&(u(!0),history.pushState({mobileDetail:De.DELIVERABLES},"",window.location.hash))};return n.jsxs("div",{className:"flex-1 overflow-hidden flex",children:[n.jsxs("div",{className:`${a?"flex-1 min-w-0":"shrink-0"} flex flex-col bg-surface-secondary rounded-xl m-1 mr-0`,style:a?d?{display:"none"}:void 0:{width:l.width},children:[n.jsxs("div",{className:"p-4 space-y-3",children:[n.jsx("div",{className:"flex items-center justify-between gap-2",children:n.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[a&&n.jsx(gc,{}),n.jsxs("h2",{className:"text-sm font-semibold text-fg-secondary truncate",children:[s("title"),x>0&&n.jsxs("span",{className:"ml-1.5 text-fg-tertiary font-normal",children:["(",x,")"]})]})]})}),n.jsx("input",{value:I,onChange:Ge=>z(Ge.target.value),placeholder:s("searchPlaceholder"),className:"w-full bg-surface-elevated border border-border-default rounded-lg px-3 py-2 text-sm text-fg-primary focus:border-brand-500 focus:outline-none transition-colors"}),Ae&&n.jsxs("div",{className:"flex items-center gap-2 px-2.5 py-1.5 bg-surface-elevated rounded-lg text-[10px] text-fg-tertiary",children:[n.jsx("span",{className:"truncate font-mono",children:Ae}),n.jsx("button",{onClick:()=>{ie.system.openPath(Ae)},className:"shrink-0 underline hover:text-fg-secondary transition-colors",children:s("common:open")})]}),n.jsxs("div",{className:"flex gap-1 overflow-x-auto scrollbar-hide",children:[n.jsx(Ou,{label:s("filters.allTypes"),value:"",current:V||U||"",onClick:()=>{Y(""),H("")}}),sse.map(Ge=>n.jsx(Ou,{label:`${Pu[Ge]?.icon??""} ${Ge}`,value:Ge,current:V,onClick:Ht=>{Y(Ht),H("")}},Ge)),["agent","team","skill"].map(Ge=>n.jsx(Ou,{label:`${Zl[Ge].icon} ${s(`artifactTypes.${Ge}`)}`,value:Ge,current:U,onClick:Ht=>{H(Ht),Y("")}},Ge))]}),w.length>0&&n.jsxs("div",{className:"flex gap-1 overflow-x-auto scrollbar-hide",children:[n.jsx(Ou,{label:s("filters.allProjects"),value:"",current:F,onClick:L}),w.map(Ge=>n.jsx(Ou,{label:Ge.name,value:Ge.id,current:F,onClick:L},Ge.id))]}),n.jsxs("div",{className:"flex gap-1.5 items-center",children:[n.jsx("span",{className:"text-[10px] text-fg-tertiary",children:s("filters.group")}),["date","project","agent","type"].map(Ge=>n.jsx("button",{onClick:()=>{Z(Ge),Se(new Set)},className:`px-2 py-1 rounded text-xs transition-colors ${q===Ge?"bg-brand-600 text-white":"bg-surface-elevated text-fg-secondary hover:bg-surface-overlay"}`,children:s(`groupBy.${Ge}`)},Ge)),Zt.length>1&&n.jsx("button",{onClick:Qr,className:"ml-auto px-1.5 py-1 rounded text-[10px] text-fg-tertiary hover:text-fg-secondary hover:bg-surface-elevated transition-colors",title:ue.size===Zt.length?s("expandAllTooltip"):s("collapseAllTooltip"),children:ue.size===Zt.length?s("expandAll"):s("collapseAll")})]})]}),X&&n.jsx("div",{className:`mx-4 mt-2 px-3 py-1.5 text-xs rounded-lg ${X.type==="success"?"bg-green-500/15 text-green-600":"bg-red-500/15 text-red-500"}`,children:X.text}),n.jsxs("div",{ref:he,className:"flex-1 overflow-y-auto p-2 space-y-1",onTouchStart:a?Ne.onTouchStart:void 0,onTouchEnd:a?Ne.onTouchEnd:void 0,children:[E?n.jsx("div",{className:"p-4 space-y-3",children:[1,2,3].map(Ge=>n.jsxs("div",{className:"animate-pulse space-y-2",children:[n.jsx("div",{className:"h-4 bg-surface-elevated rounded w-3/4"}),n.jsx("div",{className:"h-3 bg-surface-elevated rounded w-1/2"})]},Ge))}):p.length===0?n.jsxs("div",{className:"flex flex-col items-center justify-center py-16 px-6 text-center",children:[n.jsx("svg",{className:"w-12 h-12 text-fg-muted mb-3",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:1,children:n.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M19.5 14.25v-2.625a3.375 3.375 0 00-3.375-3.375h-1.5A1.125 1.125 0 0113.5 7.125v-1.5a3.375 3.375 0 00-3.375-3.375H8.25m0 12.75h7.5m-7.5 3H12M10.5 2.25H5.625c-.621 0-1.125.504-1.125 1.125v17.25c0 .621.504 1.125 1.125 1.125h12.75c.621 0 1.125-.504 1.125-1.125V11.25a9 9 0 00-9-9z"})}),n.jsx("p",{className:"text-sm text-fg-secondary",children:s("empty.title")}),n.jsx("p",{className:"text-xs text-fg-tertiary mt-1 mb-3",children:s("empty.subtitle")}),n.jsx("button",{onClick:()=>bt.navigate(De.WORK),className:"text-xs px-3 py-1.5 rounded-lg bg-brand-600 hover:bg-brand-500 text-white transition-colors",children:s("empty.goToWork")})]}):Zt.map(([Ge,Ht])=>{const Wt=ue.has(Ge);return n.jsxs("div",{children:[n.jsxs("button",{onClick:()=>Lr(Ge),className:"w-full flex items-center gap-1.5 px-2 py-1.5 rounded-md hover:bg-surface-elevated/50 transition-colors group/header",children:[n.jsx("svg",{className:`w-3 h-3 text-fg-tertiary transition-transform duration-200 shrink-0 ${Wt?"":"rotate-90"}`,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2.5,children:n.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M9 5l7 7-7 7"})}),n.jsx("span",{className:"text-[10px] font-medium text-fg-tertiary uppercase tracking-wider truncate",children:Ht.label}),n.jsxs("span",{className:"text-[10px] text-fg-tertiary shrink-0",children:["(",Ht.items.length,")"]})]}),!Wt&&Ht.items.map(tn=>n.jsx("button",{onClick:()=>mr(tn),className:`w-full text-left px-3 py-2 rounded-lg transition-colors ${_?.id===tn.id?"bg-brand-600/20 border border-brand-500/30":"hover:bg-surface-elevated/60 border border-transparent"}`,children:n.jsxs("div",{className:"flex items-center gap-1.5 min-w-0",children:[tn.artifactType&&Zl[tn.artifactType]?n.jsx("span",{className:`text-[10px] px-1 py-0.5 rounded font-medium shrink-0 ${Zl[tn.artifactType].color}`,children:Zl[tn.artifactType].icon}):n.jsx("span",{className:`text-[10px] px-1 py-0.5 rounded font-medium uppercase shrink-0 ${Pu[tn.type]?.color??"bg-surface-overlay text-fg-secondary"}`,children:Pu[tn.type]?.icon??tn.type.charAt(0)}),n.jsx("span",{className:"text-sm font-medium text-fg-primary truncate",children:tn.title}),pe.has(tn.id)&&n.jsx("span",{className:"shrink-0 text-amber-500",title:s("detail.fileMissing"),children:n.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("path",{d:"M10.29 3.86L1.82 18a2 2 0 001.71 3h16.94a2 2 0 001.71-3L13.71 3.86a2 2 0 00-3.42 0z"}),n.jsx("line",{x1:"12",y1:"9",x2:"12",y2:"13"}),n.jsx("line",{x1:"12",y1:"17",x2:"12.01",y2:"17"})]})}),n.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded shrink-0 ${rse[tn.status]?.color??"bg-surface-elevated text-fg-tertiary"}`,children:s(`common:status.${tn.status}`,{defaultValue:tn.status})})]})},tn.id))]},Ge)}),j&&n.jsxs("div",{className:"flex items-center justify-center gap-2 py-3 text-fg-tertiary",children:[n.jsx(V3,{})," ",n.jsx("span",{className:"text-[10px]",children:s("common:loadingMore")})]}),!E&&p.length>0&&n.jsx("div",{className:"text-center text-[10px] text-fg-tertiary py-2",children:p.length<x?s("count.partial",{loaded:p.length,total:x}):s("count.total",{total:x})})]})]}),!a&&n.jsx("div",{className:"w-1.5 shrink-0 cursor-col-resize group relative flex items-center justify-center",onMouseDown:l.onResizeStart,children:n.jsx("div",{className:"w-px h-2/3 border-l border-dashed border-transparent group-hover:border-border-default group-active:border-fg-tertiary transition-colors"})}),(!a||d)&&n.jsxs("div",{className:"flex-1 overflow-y-auto min-w-0",children:[a&&n.jsxs("div",{className:"sticky top-0 z-10 bg-surface-secondary px-4 py-2.5 flex items-center gap-2",children:[n.jsx("button",{onClick:()=>history.back(),className:"text-fg-secondary hover:text-fg-primary transition-colors p-1 -ml-1",children:n.jsx("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:n.jsx("polyline",{points:"15 18 9 12 15 6"})})}),n.jsx("span",{className:"text-sm font-medium truncate",children:_?.title??s("detail.details")})]}),_?n.jsxs("div",{className:"p-6 space-y-4",children:[!t&&pe.has(_.id)&&n.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 bg-amber-500/10 border border-amber-500/20 rounded-lg text-amber-600 text-xs",children:[n.jsxs("svg",{className:"w-4 h-4 shrink-0",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("path",{d:"M10.29 3.86L1.82 18a2 2 0 001.71 3h16.94a2 2 0 001.71-3L13.71 3.86a2 2 0 00-3.42 0z"}),n.jsx("line",{x1:"12",y1:"9",x2:"12",y2:"13"}),n.jsx("line",{x1:"12",y1:"17",x2:"12.01",y2:"17"})]}),n.jsx("span",{children:s("detail.fileMissing")})]}),n.jsxs("div",{className:"space-y-3",children:[n.jsxs("div",{className:"flex items-start justify-between gap-3",children:[n.jsx("h2",{className:"text-xl font-semibold text-fg-primary",children:_.title}),!t&&n.jsx("button",{onClick:()=>He(_),disabled:!!te,className:"p-1.5 rounded-lg text-fg-tertiary hover:text-red-500 hover:bg-red-500/10 transition-colors disabled:opacity-50 shrink-0",title:s("common:remove"),children:n.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("polyline",{points:"3 6 5 6 21 6"}),n.jsx("path",{d:"M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"})]})})]}),n.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[n.jsxs("span",{className:`px-2 py-0.5 rounded text-xs font-medium uppercase ${Pu[_.type]?.color??"bg-surface-overlay text-fg-secondary"}`,children:[Pu[_.type]?.icon??""," ",_.type]}),_.artifactType&&Zl[_.artifactType]&&n.jsxs("span",{className:`px-2 py-0.5 rounded text-xs font-medium ${Zl[_.artifactType].color}`,children:[Zl[_.artifactType].icon," ",s("detail.builderWithType",{type:s(`artifactTypes.${_.artifactType}`)})]}),_.tags.length>0&&_.tags.map(Ge=>n.jsx("span",{className:"px-2 py-0.5 text-xs bg-surface-elevated text-fg-secondary rounded",children:Ge},Ge))]}),(_.taskId||_.agentId||je(_.projectId))&&n.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[_.taskId&&n.jsx("button",{onClick:()=>bt.navigate(De.WORK,{openTask:_.taskId}),className:"text-xs text-brand-500 hover:underline bg-brand-500/10 px-2 py-0.5 rounded",children:s("links.task",{id:`${_.taskId.slice(0,12)}...`})}),_.agentId&&n.jsx("button",{onClick:()=>bt.navigate(De.TEAM,{selectAgent:_.agentId}),className:"text-xs text-blue-600 hover:underline bg-blue-500/10 px-2 py-0.5 rounded",children:s("links.agent",{name:rt.get(_.agentId)?.name??_.agentId.slice(0,12)})}),je(_.projectId)&&n.jsx("button",{onClick:()=>bt.navigate(De.WORK,{projectId:_.projectId}),className:"text-xs text-blue-600 hover:underline bg-blue-500/10 px-2 py-0.5 rounded",children:s("links.project",{name:je(_.projectId)})})]}),(_.diffStats||_.testResults)&&n.jsxs("div",{className:"flex gap-3 flex-wrap",children:[_.diffStats&&n.jsxs("div",{className:"bg-surface-elevated rounded-lg px-3 py-2 text-xs flex items-center gap-2",children:[n.jsxs("span",{className:"text-fg-tertiary font-medium",children:[s("diffStats.title"),":"]}),n.jsx("span",{className:"text-fg-secondary",children:s("diffStats.files",{count:_.diffStats.filesChanged})}),n.jsxs("span",{className:"text-green-600",children:["+",_.diffStats.additions]}),n.jsxs("span",{className:"text-red-500",children:["-",_.diffStats.deletions]})]}),_.testResults&&n.jsxs("div",{className:"bg-surface-elevated rounded-lg px-3 py-2 text-xs flex items-center gap-2",children:[n.jsxs("span",{className:"text-fg-tertiary font-medium",children:[s("testResults.title"),":"]}),n.jsx("span",{className:"text-green-600",children:s("testResults.passed",{count:_.testResults.passed})}),n.jsx("span",{className:"text-red-500",children:s("testResults.failed",{count:_.testResults.failed})}),n.jsx("span",{className:"text-fg-secondary",children:s("testResults.skipped",{count:_.testResults.skipped})})]})]}),n.jsxs("div",{className:"flex items-center gap-4 text-[10px] text-fg-tertiary flex-wrap",children:[n.jsxs("span",{children:[s("metadata.created")," ",new Date(_.createdAt).toLocaleDateString()]}),n.jsxs("span",{children:[s("metadata.updated")," ",new Date(_.updatedAt).toLocaleDateString()]}),n.jsx("span",{className:"text-fg-muted select-all",children:_.id.slice(0,12)})]}),_.reference&&!Tf(_.reference)&&_.type==="file"&&n.jsxs("div",{className:"flex items-center gap-2 bg-surface-elevated rounded-lg px-3 py-2",children:[n.jsx("button",{onClick:()=>{ie.files.reveal(_.reference).catch(()=>nt("error",s("detail.failedToOpenBrowser")))},className:"text-xs font-mono text-brand-500 hover:text-brand-500 hover:underline truncate flex-1 text-left cursor-pointer",title:s("detail.openInFileBrowser"),children:_.reference}),n.jsx("button",{onClick:()=>{ie.files.reveal(_.reference).catch(()=>nt("error",s("detail.failedToOpenBrowser")))},className:"px-2 py-1 text-[10px] rounded bg-brand-600/20 text-brand-500 hover:bg-brand-600/30 transition-colors shrink-0",title:s("detail.revealInFinder"),children:s("common:open")}),n.jsx("button",{onClick:()=>gt(_.reference),className:`px-2 py-1 text-[10px] rounded transition-colors shrink-0 ${be?"bg-green-500/20 text-green-600":"bg-surface-overlay/50 text-fg-secondary hover:bg-surface-overlay"}`,title:s("detail.copyPath"),children:s(be?"common:copied":"common:copy")})]}),_.reference&&!Tf(_.reference)&&_.type!=="file"&&_.type!=="directory"&&n.jsx("span",{className:"text-xs text-fg-tertiary font-mono break-all",children:_.reference})]}),_.artifactType&&_.artifactData?n.jsxs("div",{className:"space-y-4",children:[n.jsx("div",{className:"bg-surface-elevated rounded-xl p-5",children:n.jsx(nse,{artifact:_.artifactData,mode:_.artifactType})}),_.reference&&n.jsxs("div",{className:"px-3 py-2 bg-surface-elevated rounded-lg",children:[n.jsx("span",{className:"text-[10px] text-fg-tertiary uppercase tracking-wider block mb-1",children:s("detail.artifactDirectory")}),n.jsx("span",{className:"text-xs text-fg-secondary font-mono break-all",children:_.reference})]}),n.jsx("div",{className:"flex gap-2",children:n.jsx("button",{onClick:Gn,className:"flex-1 px-4 py-2.5 bg-brand-600 hover:bg-brand-500 text-white text-sm font-medium rounded-lg transition-colors",children:s("detail.openInBuilder")})}),_.summary&&n.jsx("div",{className:"bg-surface-elevated rounded-xl p-5",children:n.jsx(Wr,{content:_.summary,className:"text-fg-secondary text-sm"})})]}):_.reference&&Tf(_.reference)?n.jsxs("div",{className:"space-y-4",children:[_.summary&&n.jsx("div",{className:"bg-surface-elevated rounded-xl p-5",children:n.jsx(Wr,{content:_.summary,className:"text-fg-secondary text-sm"})}),n.jsxs("div",{className:"flex flex-col items-center justify-center py-10",children:[n.jsxs("svg",{className:"w-10 h-10 text-fg-muted mb-3",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("path",{d:"M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"}),n.jsx("polyline",{points:"15 3 21 3 21 9"}),n.jsx("line",{x1:"10",y1:"14",x2:"21",y2:"3"})]}),n.jsx("p",{className:"text-xs text-fg-tertiary font-mono mb-4 px-4 text-center break-all select-all",children:_.reference}),n.jsx("button",{onClick:()=>window.open(_.reference,"_blank","noopener,noreferrer"),className:"px-6 py-2.5 bg-brand-600 hover:bg-brand-500 text-white text-sm font-medium rounded-lg transition-colors",children:s("detail.openUrl")})]})]}):_.type==="directory"&&_.reference?n.jsxs("div",{className:"space-y-4",children:[_.summary&&n.jsx("div",{className:"bg-surface-elevated rounded-xl p-5",children:n.jsx(Wr,{content:_.summary,className:"text-fg-secondary text-sm"})}),n.jsxs("div",{className:"flex flex-col items-center justify-center py-10",children:[n.jsx("svg",{className:"w-10 h-10 text-fg-muted mb-3",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:n.jsx("path",{d:"M22 19a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h5l2 3h9a2 2 0 0 1 2 2z"})}),n.jsx("p",{className:"text-xs text-fg-tertiary font-mono mb-4 px-4 text-center break-all select-all",children:_.reference}),n.jsx("button",{onClick:()=>{ie.files.reveal(_.reference).catch(()=>nt("error",s("detail.failedToOpenBrowser")))},className:"px-6 py-2.5 bg-brand-600 hover:bg-brand-500 text-white text-sm font-medium rounded-lg transition-colors",children:s("detail.openInFileBrowser")})]})]}):n.jsx("div",{className:"bg-surface-elevated rounded-xl p-5",children:Lt?n.jsxs("div",{className:"flex items-center gap-2 text-fg-tertiary text-sm",children:[n.jsx(V3,{})," ",s("detail.loadingPreview")]}):mt?n.jsxs("div",{className:"flex flex-col items-center gap-2",children:[n.jsx("img",{src:mt.src,alt:mt.name,className:"max-w-full max-h-[60vh] rounded-lg object-contain"}),n.jsx("span",{className:"text-xs text-fg-tertiary",children:mt.name})]}):_e?n.jsx(fy,{content:_e,format:Ye,className:"text-fg-secondary text-sm"}):ne?n.jsxs("div",{className:"space-y-3",children:[n.jsx("p",{className:"text-sm text-fg-secondary",children:s("detail.cannotPreview",{type:_.type})}),n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx("button",{onClick:()=>{ie.files.reveal(_.reference).catch(()=>nt("error",s("detail.failedToOpen")))},className:"text-xs bg-surface-elevated px-3 py-2 rounded text-brand-500 hover:text-brand-500 hover:underline flex-1 truncate text-left cursor-pointer font-mono",title:s("detail.openInFileBrowser"),children:_.reference}),n.jsx("button",{onClick:()=>{ie.files.reveal(_.reference).catch(()=>nt("error",s("detail.failedToOpen")))},className:"px-3 py-2 text-xs rounded-lg bg-brand-600/20 text-brand-500 hover:bg-brand-600/30 transition-colors shrink-0",children:s("common:open")}),n.jsx("button",{onClick:()=>gt(_.reference),className:`px-3 py-2 text-xs rounded-lg transition-colors shrink-0 ${be?"bg-green-500/20 text-green-600":"bg-surface-overlay/50 text-fg-secondary hover:bg-surface-overlay"}`,children:s(be?"common:copied":"common:copy")})]})]}):_.summary?n.jsx(Wr,{content:_.summary,className:"text-fg-secondary text-sm"}):n.jsx("p",{className:"text-sm text-fg-tertiary italic",children:s("detail.noContent")})})]}):n.jsx("div",{className:"flex-1 flex items-center justify-center h-full",children:n.jsxs("div",{className:"text-center text-fg-tertiary space-y-2",children:[n.jsx("svg",{className:"w-12 h-12 mx-auto text-fg-muted",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:1,children:n.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M19.5 14.25v-2.625a3.375 3.375 0 00-3.375-3.375h-1.5A1.125 1.125 0 0113.5 7.125v-1.5a3.375 3.375 0 00-3.375-3.375H8.25m0 12.75h7.5m-7.5 3H12M10.5 2.25H5.625c-.621 0-1.125.504-1.125 1.125v17.25c0 .621.504 1.125 1.125 1.125h12.75c.621 0 1.125-.504 1.125-1.125V11.25a9 9 0 00-9-9z"})}),n.jsx("p",{className:"text-sm",children:s("detail.selectToView")})]})})]}),fe&&n.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60",onClick:()=>He(null),children:n.jsxs("div",{className:"bg-surface-secondary border border-border-default rounded-xl p-6 max-w-sm mx-4 shadow-2xl",onClick:Ge=>Ge.stopPropagation(),children:[n.jsxs("div",{className:"flex items-center gap-3 mb-4",children:[n.jsx("div",{className:"w-10 h-10 rounded-full bg-red-500/15 flex items-center justify-center shrink-0",children:n.jsxs("svg",{className:"w-5 h-5 text-red-500",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("polyline",{points:"3 6 5 6 21 6"}),n.jsx("path",{d:"M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"})]})}),n.jsxs("div",{children:[n.jsx("div",{className:"text-sm font-medium text-fg-primary",children:s("detail.confirmRemoveTitle")}),n.jsx("div",{className:"text-xs text-fg-secondary mt-0.5",children:s("detail.confirmRemoveMessage",{name:fe.title})})]})]}),n.jsxs("div",{className:"flex justify-end gap-2",children:[n.jsx("button",{onClick:()=>He(null),className:"px-4 py-1.5 text-xs text-fg-secondary hover:text-fg-primary border border-border-default hover:border-gray-600 rounded-lg transition-colors",children:s("common:cancel")}),n.jsx("button",{onClick:()=>{const Ge=fe;He(null),cn(Ge)},disabled:!!te,className:"px-4 py-1.5 text-xs bg-red-600 hover:bg-red-500 text-white rounded-lg transition-colors disabled:opacity-50",children:s("common:remove")})]})]})})]})}function Ou({label:e,value:t,current:r,onClick:s}){return n.jsx("button",{onClick:()=>s(r===t?"":t),className:`px-2 py-1 rounded text-xs whitespace-nowrap shrink-0 transition-colors ${r===t?"bg-brand-600 text-white":"bg-surface-elevated text-fg-secondary hover:bg-surface-overlay"}`,children:e})}function V3(){return n.jsxs("svg",{className:"animate-spin h-3.5 w-3.5",viewBox:"0 0 24 24",fill:"none",children:[n.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),n.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"})]})}function To(e){return e.toLocaleString()}function cd(e){return e<.01?`$${e.toFixed(4)}`:`$${e.toFixed(2)}`}function ase(e){return e>=1024*1024*1024?`${(e/(1024*1024*1024)).toFixed(1)} GB`:e>=1024*1024?`${(e/(1024*1024)).toFixed(1)} MB`:e>=1024?`${(e/1024).toFixed(1)} KB`:`${e} B`}function K3({authUser:e}){const{t}=pt(["reports","common"]),r=Rs(),s=Id(De.REPORTS),[a,i]=g.useState("weekly"),[l,d]=g.useState(null),[u,m]=g.useState(!0),[h,p]=g.useState(""),[y,x]=g.useState(null),[v,j]=g.useState([]),[C,w]=g.useState("totalTokens"),[N,S]=g.useState(!0),[T,E]=g.useState("generate"),[R,I]=g.useState([]),[z,B]=g.useState(null),[D,V]=g.useState([]),[Y,F]=g.useState(""),[L,O]=g.useState(""),M=G=>{O(G),setTimeout(()=>O(""),3e3)},$=g.useCallback(async G=>{m(!0),p("");try{const{report:ue}=await ie.reports.generate({period:G,scope:"org",orgId:"default"});d(ue)}catch(ue){p(String(ue)),d(null)}m(!1)},[]),W=g.useCallback(()=>{ie.usage.summary().then(G=>x(G.usage)).catch(()=>{}),ie.usage.agents().then(G=>j(G.agents)).catch(()=>{})},[]),U=g.useCallback(async()=>{try{const{reports:G}=await ie.reports.list();I(G)}catch{}},[]),H=g.useCallback(async G=>{B(G);try{const{feedback:ue}=await ie.reports.getFeedback(G.id);V(ue)}catch{V([])}},[]);g.useEffect(()=>{$(a)},[a,$]),g.useEffect(()=>{if(!s)return;W();const G=setInterval(W,3e4);return()=>clearInterval(G)},[W,s]),g.useEffect(()=>{T==="history"&&U()},[T,U]);const q=g.useMemo(()=>[...v].sort((G,ue)=>{const Se=G[C],Ce=ue[C];return N?Ce-Se:Se-Ce}),[v,C,N]),Z=v.reduce((G,ue)=>G+ue.estimatedCost,0),_=v.reduce((G,ue)=>G+ue.tokensUsedToday,0),J=v.reduce((G,ue)=>G+(ue.costToday??0),0),X=Math.max(1,...v.map(G=>G.totalTokens)),ee=G=>{C===G?S(!N):(w(G),S(!0))},te=g.useMemo(()=>({daily:t("period.today"),weekly:t("period.thisWeek"),monthly:t("period.thisMonth")}),[t]);return n.jsx("div",{className:"flex-1 overflow-y-auto",children:n.jsxs("div",{className:"max-w-5xl mx-auto w-full p-6 space-y-6",children:[n.jsxs("div",{className:"flex flex-col gap-3 md:flex-row md:items-center md:justify-between",children:[n.jsxs("div",{className:"flex items-center gap-4 flex-wrap",children:[r&&n.jsx(gc,{}),n.jsx("h1",{className:"text-xl font-semibold text-fg-primary",children:t("title")}),n.jsxs("div",{className:"flex gap-1 bg-surface-elevated rounded-lg p-0.5",children:[n.jsx("button",{onClick:()=>E("generate"),className:`px-3 py-1.5 text-xs rounded-md transition-colors ${T==="generate"?"bg-surface-overlay text-fg-primary shadow-sm":"text-fg-tertiary hover:text-fg-secondary"}`,children:t("tabs.generate")}),n.jsxs("button",{onClick:()=>E("history"),className:`px-3 py-1.5 text-xs rounded-md transition-colors ${T==="history"?"bg-surface-overlay text-fg-primary shadow-sm":"text-fg-tertiary hover:text-fg-secondary"}`,children:[t("tabs.history"),R.length>0?` (${R.length})`:""]})]})]}),n.jsxs("div",{className:"flex items-center gap-3 flex-wrap",children:[L&&n.jsx("span",{className:"px-2.5 py-1 bg-green-500/10 text-green-600 text-xs rounded-lg",children:L}),T==="generate"&&n.jsx("div",{className:"flex gap-1 bg-surface-elevated rounded-lg p-0.5",children:["daily","weekly","monthly"].map(G=>n.jsx("button",{onClick:()=>i(G),className:`px-3 py-1.5 text-xs rounded-md transition-colors ${a===G?"bg-surface-overlay text-fg-primary shadow-sm":"text-fg-tertiary hover:text-fg-secondary"}`,children:t(`period.${G}`)},G))})]})]}),T==="history"&&!z&&n.jsx("section",{className:"bg-surface-elevated rounded-xl overflow-hidden",children:R.length===0?n.jsx("div",{className:"p-8 text-center text-fg-tertiary text-sm",children:t("noReportsYet")}):n.jsx("div",{className:"divide-y divide-border-default/50",children:R.map(G=>n.jsxs("button",{onClick:()=>H(G),className:"w-full text-left px-5 py-3 flex items-center gap-4 hover:bg-surface-elevated/30 transition-colors",children:[n.jsxs("div",{className:"flex-1 min-w-0",children:[n.jsx("div",{className:"text-sm font-medium text-fg-primary",children:t("reportType",{type:G.type})}),n.jsxs("div",{className:"text-xs text-fg-tertiary mt-0.5",children:[new Date(G.periodStart).toLocaleDateString()," — ",new Date(G.periodEnd).toLocaleDateString()]})]}),G.plan&&n.jsx("span",{className:`px-2 py-0.5 rounded-full text-[10px] font-medium shrink-0 ${G.plan.status==="approved"?"bg-green-500/10 text-green-600":G.plan.status==="rejected"?"bg-red-500/10 text-red-500":"bg-amber-500/10 text-amber-600"}`,children:G.plan.status==="pending"?t("upcomingPlan.planPending"):t("upcomingPlan.planStatus",{status:G.plan.status})}),n.jsx("span",{className:"text-[10px] text-fg-tertiary shrink-0",children:new Date(G.generatedAt).toLocaleDateString()})]},G.id))})}),T==="history"&&z&&n.jsxs(n.Fragment,{children:[n.jsxs("div",{className:"flex items-center gap-3",children:[n.jsx("button",{onClick:()=>{B(null),V([])},className:"text-xs text-fg-tertiary hover:text-fg-secondary",children:t("backToList")}),n.jsx("span",{className:"text-sm font-medium text-fg-primary",children:t("reportType",{type:z.type})}),n.jsxs("span",{className:"text-xs text-fg-tertiary",children:[new Date(z.periodStart).toLocaleDateString()," — ",new Date(z.periodEnd).toLocaleDateString()]})]}),z.metrics&&n.jsxs("section",{className:"bg-surface-elevated rounded-xl p-5",children:[n.jsx("h3",{className:"text-xs font-semibold text-fg-secondary mb-3",children:t("taskMetrics.title")}),n.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-5 gap-4",children:[n.jsx(Fi,{label:t("taskMetrics.completed"),value:z.metrics.tasksCompleted,color:"text-green-600"}),n.jsx(Fi,{label:t("taskMetrics.inProgress"),value:z.metrics.tasksInProgress,color:"text-brand-500"}),n.jsx(Fi,{label:t("taskMetrics.created"),value:z.metrics.tasksCreated,color:"text-blue-600"}),n.jsx(Fi,{label:t("taskMetrics.blocked"),value:z.metrics.tasksBlocked,color:"text-amber-600"}),n.jsx(Fi,{label:t("taskMetrics.failed"),value:z.metrics.tasksFailed,color:"text-red-500"})]})]}),z.costSummary&&n.jsxs("section",{className:"bg-surface-elevated rounded-xl p-5",children:[n.jsx("h3",{className:"text-xs font-semibold text-fg-secondary mb-3",children:t("costOverview.title")}),n.jsxs("div",{className:"grid grid-cols-2 lg:grid-cols-3 gap-4",children:[n.jsxs("div",{children:[n.jsx("div",{className:"text-2xl font-bold text-fg-primary",children:z.costSummary.totalTokens.toLocaleString()}),n.jsx("div",{className:"text-xs text-fg-tertiary",children:t("costOverview.totalTokens")})]}),n.jsxs("div",{children:[n.jsx("div",{className:"text-2xl font-bold text-fg-primary",children:cd(z.costSummary.totalEstimatedCost)}),n.jsx("div",{className:"text-xs text-fg-tertiary",children:t("costOverview.estimatedCost")})]}),n.jsxs("div",{children:[n.jsxs("div",{className:`text-2xl font-bold ${z.costSummary.trend==="decreasing"?"text-green-600":z.costSummary.trend==="increasing"?"text-red-500":"text-fg-primary"}`,children:[z.costSummary.trend==="decreasing"?"↓":z.costSummary.trend==="increasing"?"↑":"→"," ",z.costSummary.trend]}),n.jsx("div",{className:"text-xs text-fg-tertiary",children:t("costOverview.trend")})]})]}),z.costSummary.byAgent&&z.costSummary.byAgent.length>0&&n.jsx("div",{className:"mt-4 pt-3 border-t border-border-default/50 space-y-1.5",children:z.costSummary.byAgent.map((G,ue)=>n.jsxs("div",{className:"flex items-center justify-between text-xs",children:[n.jsx("span",{className:"text-fg-secondary",children:G.agentId}),n.jsx("span",{className:"text-fg-tertiary tabular-nums",children:t("costOverview.byAgentRow",{tokens:To(G.tokens),cost:cd(G.cost)})})]},ue))})]}),z.taskSummary&&n.jsxs("section",{className:"bg-surface-elevated rounded-xl p-5 overflow-hidden",children:[n.jsx("h3",{className:"text-xs font-semibold text-fg-secondary mb-3",children:t("taskSummary.title")}),n.jsxs("div",{className:"space-y-4 min-w-0",children:[z.taskSummary.completed.length>0&&n.jsx(ad,{title:t("taskSummary.completedCount",{count:z.taskSummary.completed.length}),color:"emerald",items:z.taskSummary.completed.map(G=>({id:G.id,label:G.title,sub:G.agent}))}),z.taskSummary.inProgress.length>0&&n.jsx(ad,{title:t("taskSummary.inProgressCount",{count:z.taskSummary.inProgress.length}),color:"indigo",items:z.taskSummary.inProgress.map(G=>({id:G.id,label:G.title,sub:G.agent}))}),z.taskSummary.blocked.length>0&&n.jsx(ad,{title:t("taskSummary.blockedCount",{count:z.taskSummary.blocked.length}),color:"amber",items:z.taskSummary.blocked.map(G=>({id:G.id,label:G.title,sub:G.reason||G.agent}))}),z.taskSummary.completed.length===0&&z.taskSummary.inProgress.length===0&&z.taskSummary.blocked.length===0&&n.jsx("p",{className:"text-sm text-fg-tertiary",children:t("taskSummary.noTasksInPeriod")})]})]}),z.highlights&&z.highlights.length>0&&n.jsxs("section",{className:"bg-surface-elevated rounded-xl p-5",children:[n.jsx("h3",{className:"text-xs font-semibold text-fg-secondary mb-2",children:t("highlights")}),n.jsx("ul",{className:"list-disc list-inside space-y-1 text-sm text-fg-secondary",children:z.highlights.map((G,ue)=>n.jsx("li",{children:G},ue))})]}),z.blockers&&z.blockers.length>0&&n.jsxs("section",{className:"bg-surface-secondary border border-amber-500/20 rounded-xl p-5",children:[n.jsx("h3",{className:"text-xs font-semibold text-amber-600 mb-2",children:t("blockers")}),n.jsx("ul",{className:"list-disc list-inside space-y-1 text-sm text-fg-secondary",children:z.blockers.map((G,ue)=>n.jsx("li",{children:G},ue))})]}),z.plan&&n.jsxs("section",{className:"bg-surface-elevated rounded-xl p-5",children:[n.jsxs("div",{className:"flex items-center justify-between mb-3",children:[n.jsxs("h3",{className:"text-xs font-semibold text-fg-secondary",children:[t("upcomingPlan.title"),n.jsx("span",{className:`ml-2 px-1.5 py-0.5 rounded text-[10px] font-medium ${z.plan.status==="approved"?"bg-green-500/10 text-green-600":z.plan.status==="rejected"?"bg-red-500/10 text-red-500":"bg-amber-500/10 text-amber-600"}`,children:t(`common:status.${z.plan.status}`,{defaultValue:z.plan.status})})]}),z.plan.status==="pending"&&n.jsxs("div",{className:"flex gap-2",children:[n.jsx("button",{onClick:async()=>{try{const{report:G}=await ie.reports.approvePlan(z.id,{approvedBy:e?.id??"unknown"});B(G),M(t("upcomingPlan.planApproved")),U()}catch(G){M(t("common:error",{message:String(G)}))}},className:"px-3 py-1.5 text-xs font-medium bg-green-600 text-white rounded-lg hover:bg-green-500 transition-colors",children:t("upcomingPlan.approvePlan")}),n.jsx("button",{onClick:async()=>{const G=prompt(t("upcomingPlan.rejectionReason"));if(G)try{const{report:ue}=await ie.reports.rejectPlan(z.id,{rejectedBy:e?.id??"unknown",reason:G});B(ue),M(t("upcomingPlan.planRejected")),U()}catch(ue){M(t("common:error",{message:String(ue)}))}},className:"px-3 py-1.5 text-xs font-medium border border-border-default text-fg-secondary rounded-lg hover:bg-surface-overlay transition-colors",children:t("upcomingPlan.rejectPlan")})]})]}),z.plan.items&&z.plan.items.length>0&&n.jsx("div",{className:"space-y-1.5",children:z.plan.items.map((G,ue)=>n.jsxs("div",{className:"flex items-center gap-2 text-sm text-fg-secondary",children:[n.jsx("span",{className:`px-1.5 py-0.5 rounded text-[10px] font-medium ${G.priority==="high"?"bg-red-500/10 text-red-500":G.priority==="medium"?"bg-amber-500/10 text-amber-600":"bg-gray-500/10 text-fg-tertiary"}`,children:G.priority}),n.jsx("span",{children:G.title}),G.assignee&&n.jsx("span",{className:"text-[10px] text-fg-tertiary ml-auto",children:G.assignee})]},ue))})]}),!z.metrics&&!z.taskSummary&&!z.costSummary&&n.jsx("section",{className:"bg-surface-elevated rounded-xl p-8 text-center",children:n.jsx("p",{className:"text-sm text-fg-tertiary",children:t("noDetailedMetrics")})}),n.jsxs("section",{className:"bg-surface-elevated rounded-xl p-5",children:[n.jsx("h3",{className:"text-xs font-semibold text-fg-secondary mb-3",children:t("feedback.title",{count:D.length})}),D.length>0&&n.jsx("div",{className:"space-y-2 mb-4",children:D.map(G=>n.jsxs("div",{className:"p-3 bg-surface-elevated/50 rounded-lg",children:[n.jsxs("div",{className:"flex items-center gap-2 text-[10px] text-fg-tertiary mb-1",children:[n.jsx("span",{className:"font-medium text-fg-secondary",children:G.authorName}),n.jsx("span",{children:G.type}),n.jsx("span",{children:new Date(G.createdAt).toLocaleDateString()})]}),n.jsx("p",{className:"text-xs text-fg-secondary",children:G.content})]},G.id))}),n.jsxs("div",{className:"flex gap-2",children:[n.jsx("input",{value:Y,onChange:G=>F(G.target.value),placeholder:t("feedback.placeholder"),className:"flex-1 px-3 py-2 text-xs bg-surface-elevated border border-border-default rounded-lg text-fg-primary placeholder:text-fg-tertiary",onKeyDown:G=>{G.key==="Enter"&&Y.trim()&&ie.reports.addFeedback(z.id,{author:e?.id??"unknown",type:"comment",content:Y.trim()}).then(({feedback:ue})=>{V(Se=>[...Se,ue]),F(""),M(t("feedback.added"))}).catch(ue=>M(t("common:error",{message:String(ue)})))}}),n.jsx("button",{onClick:()=>{Y.trim()&&ie.reports.addFeedback(z.id,{author:e?.id??"unknown",type:"comment",content:Y.trim()}).then(({feedback:G})=>{V(ue=>[...ue,G]),F(""),M(t("feedback.added"))}).catch(G=>M(t("common:error",{message:String(G)})))},disabled:!Y.trim(),className:"px-3 py-2 text-xs bg-brand-600 text-white rounded-lg hover:bg-brand-500 disabled:opacity-40 disabled:cursor-not-allowed transition-colors",children:t("common:send")})]})]})]}),T==="generate"&&y&&n.jsxs("div",{className:`grid gap-4 ${y.storageBytes>0?"grid-cols-2 lg:grid-cols-4":"grid-cols-3"}`,children:[n.jsx(Af,{label:t("usage.llmTokens"),value:To(y.llmTokens),color:"text-brand-500"}),n.jsx(Af,{label:t("usage.toolCalls"),value:To(y.toolCalls),color:"text-blue-600"}),n.jsx(Af,{label:t("usage.messages"),value:To(y.messages),color:"text-green-600"}),y.storageBytes>0&&n.jsx(Af,{label:t("usage.storage"),value:ase(y.storageBytes),color:"text-amber-600"})]}),T==="generate"&&(u?n.jsx("div",{className:"flex items-center justify-center h-32 text-fg-tertiary text-sm",children:t("common:loading")}):h?n.jsx("div",{className:"flex items-center justify-center h-32 text-red-500 text-sm",children:h}):l?n.jsxs(n.Fragment,{children:[n.jsxs("div",{className:"text-xs text-fg-tertiary",children:[te[a]," · ",new Date(l.periodStart).toLocaleDateString()," — ",new Date(l.periodEnd).toLocaleDateString()]}),l.metrics&&n.jsxs("section",{className:"bg-surface-elevated rounded-xl p-5",children:[n.jsx("h3",{className:"text-xs font-semibold text-fg-secondary mb-3",children:t("taskMetrics.title")}),n.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-5 gap-4",children:[n.jsx(Fi,{label:t("taskMetrics.completed"),value:l.metrics.tasksCompleted,color:"text-green-600"}),n.jsx(Fi,{label:t("taskMetrics.inProgress"),value:l.metrics.tasksInProgress,color:"text-brand-500"}),n.jsx(Fi,{label:t("taskMetrics.created"),value:l.metrics.tasksCreated,color:"text-blue-600"}),n.jsx(Fi,{label:t("taskMetrics.blocked"),value:l.metrics.tasksBlocked,color:"text-amber-600"}),n.jsx(Fi,{label:t("taskMetrics.failed"),value:l.metrics.tasksFailed,color:"text-red-500"})]})]}),n.jsxs("section",{className:"bg-surface-elevated rounded-xl p-5",children:[n.jsx("h3",{className:"text-xs font-semibold text-fg-secondary mb-3",children:t("costOverview.title")}),n.jsxs("div",{className:"grid grid-cols-3 gap-4",children:[n.jsxs("div",{children:[n.jsx("div",{className:"text-2xl font-bold text-fg-primary",children:cd(Z)}),n.jsx("div",{className:"text-xs text-fg-tertiary",children:t("costOverview.estCostAllTime")})]}),n.jsxs("div",{children:[n.jsx("div",{className:"text-2xl font-bold text-fg-primary",children:To(_)}),n.jsx("div",{className:"text-xs text-fg-tertiary",children:t("costOverview.tokensToday")})]}),n.jsxs("div",{children:[n.jsx("div",{className:"text-2xl font-bold text-fg-primary",children:cd(J)}),n.jsx("div",{className:"text-xs text-fg-tertiary",children:t("costOverview.costToday")})]})]})]}),l.taskSummary&&n.jsxs("section",{className:"bg-surface-elevated rounded-xl p-5",children:[n.jsx("h3",{className:"text-xs font-semibold text-fg-secondary mb-3",children:t("taskSummary.title")}),n.jsxs("div",{className:"space-y-4",children:[l.taskSummary.completed.length>0&&n.jsx(ad,{title:t("taskSummary.completedCount",{count:l.taskSummary.completed.length}),color:"emerald",items:l.taskSummary.completed.map(G=>({id:G.id,label:G.title,sub:G.agent}))}),l.taskSummary.inProgress.length>0&&n.jsx(ad,{title:t("taskSummary.inProgressCount",{count:l.taskSummary.inProgress.length}),color:"indigo",items:l.taskSummary.inProgress.map(G=>({id:G.id,label:G.title,sub:G.agent}))}),l.taskSummary.blocked.length>0&&n.jsx(ad,{title:t("taskSummary.blockedCount",{count:l.taskSummary.blocked.length}),color:"amber",items:l.taskSummary.blocked.map(G=>({id:G.id,label:G.title,sub:G.reason||G.agent}))}),l.taskSummary.completed.length===0&&l.taskSummary.inProgress.length===0&&l.taskSummary.blocked.length===0&&n.jsx("p",{className:"text-sm text-fg-tertiary",children:t("taskSummary.noTasksInPeriod")})]})]})]}):null),T==="generate"&&n.jsxs("section",{className:"bg-surface-elevated rounded-xl overflow-hidden",children:[n.jsx("div",{className:"px-5 py-4 border-b border-border-default",children:n.jsx("h3",{className:"text-sm font-semibold text-fg-secondary",children:t("perAgentUsage.title")})}),v.length===0?n.jsx("div",{className:"p-8 text-center text-fg-tertiary text-sm",children:t("perAgentUsage.noData")}):n.jsx("div",{className:"overflow-x-auto",children:n.jsxs("table",{className:"w-full",children:[n.jsx("thead",{children:n.jsxs("tr",{className:"border-b border-border-default text-xs text-fg-tertiary uppercase tracking-wider",children:[n.jsx("th",{className:"px-4 py-3 text-left font-medium",children:t("perAgentUsage.agent")}),n.jsx(_u,{label:t("perAgentUsage.totalTokens"),col:"totalTokens",current:C,desc:N,onSort:ee}),n.jsx(_u,{label:t("perAgentUsage.today"),col:"tokensUsedToday",current:C,desc:N,onSort:ee}),n.jsx(_u,{label:t("perAgentUsage.requests"),col:"requestCount",current:C,desc:N,onSort:ee}),n.jsx(_u,{label:t("perAgentUsage.toolCalls"),col:"toolCalls",current:C,desc:N,onSort:ee}),n.jsx(_u,{label:t("perAgentUsage.estCost"),col:"estimatedCost",current:C,desc:N,onSort:ee,align:"right"})]})}),n.jsx("tbody",{children:q.map(G=>n.jsx(ise,{agent:G,maxTokens:X},G.agentId))}),n.jsx("tfoot",{children:n.jsxs("tr",{className:"border-t border-border-default bg-surface-elevated/30",children:[n.jsx("td",{className:"px-4 py-3 text-sm font-medium text-fg-secondary",children:t("perAgentUsage.totalAgents",{count:v.length})}),n.jsx("td",{className:"px-4 py-3 text-sm font-medium text-fg-secondary tabular-nums",children:To(v.reduce((G,ue)=>G+ue.totalTokens,0))}),n.jsx("td",{className:"px-4 py-3 text-sm font-medium text-fg-secondary tabular-nums",children:To(_)}),n.jsx("td",{className:"px-4 py-3 text-sm font-medium text-fg-secondary tabular-nums",children:v.reduce((G,ue)=>G+ue.requestCount,0)}),n.jsx("td",{className:"px-4 py-3 text-sm font-medium text-fg-secondary tabular-nums",children:v.reduce((G,ue)=>G+ue.toolCalls,0)}),n.jsx("td",{className:"px-4 py-3 text-sm font-medium text-right text-fg-secondary tabular-nums",children:cd(Z)})]})})]})})]})]})})}function Fi({label:e,value:t,color:r}){return n.jsxs("div",{className:"text-center",children:[n.jsx("div",{className:`text-2xl font-bold ${r}`,children:t}),n.jsx("div",{className:"text-[10px] text-fg-tertiary mt-0.5",children:e})]})}function ad({title:e,color:t,items:r}){return n.jsxs("div",{className:"min-w-0 overflow-hidden",children:[n.jsx("div",{className:`text-xs font-medium text-${t}-400 mb-1.5`,children:e}),n.jsx("div",{className:"space-y-1.5",children:r.map((s,a)=>n.jsxs("div",{className:`text-sm text-fg-secondary min-w-0 ${s.id?"cursor-pointer hover:text-fg-primary group":""}`,onClick:s.id?()=>bt.navigate(De.WORK,{openTask:s.id}):void 0,children:[n.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[n.jsx("span",{className:`w-1.5 h-1.5 rounded-full bg-${t}-500 shrink-0`}),n.jsx("span",{className:`truncate min-w-0 ${s.id?"group-hover:text-brand-500 transition-colors":""}`,children:s.label})]}),s.sub&&s.sub!=="unassigned"&&n.jsx("div",{className:"text-[10px] text-fg-tertiary ml-3.5 mt-0.5 break-all line-clamp-2",children:s.sub})]},s.id??a))})]})}function Af({label:e,value:t,color:r}){return n.jsxs("div",{className:"bg-surface-elevated rounded-xl p-5",children:[n.jsx("div",{className:"text-sm text-fg-secondary mb-2",children:e}),n.jsx("div",{className:`text-2xl font-bold ${r}`,children:t})]})}function _u({label:e,col:t,current:r,desc:s,onSort:a,align:i}){const l=r===t?s?"↓":"↑":"↕",d=r===t?"text-brand-500":"text-fg-muted";return n.jsxs("th",{className:`px-4 py-3 ${i==="right"?"text-right":"text-left"} font-medium cursor-pointer select-none hover:text-fg-secondary`,onClick:()=>a(t),children:[e,n.jsx("span",{className:`ml-1 ${d}`,children:l})]})}function ise({agent:e,maxTokens:t}){const r=t>0?Math.min(100,e.totalTokens/t*100):0,s=e.status==="working"?"bg-blue-500":e.status==="idle"?"bg-green-500":e.status==="paused"?"bg-amber-500":e.status==="error"?"bg-red-500":"bg-gray-600";return n.jsxs("tr",{className:"border-b border-border-default/50 hover:bg-surface-elevated/30 transition-colors cursor-pointer",onClick:()=>bt.navigate(De.TEAM,{selectAgent:e.agentId}),children:[n.jsx("td",{className:"px-4 py-3",children:n.jsxs("div",{className:"flex items-center gap-2.5",children:[n.jsx("div",{className:`w-2 h-2 rounded-full ${s}`}),n.jsxs("div",{children:[n.jsx("div",{className:"text-sm font-medium text-fg-primary hover:text-brand-500 transition-colors",children:e.agentName}),n.jsx("div",{className:"text-xs text-fg-tertiary",children:e.role})]})]})}),n.jsx("td",{className:"px-4 py-3",children:n.jsxs("div",{className:"flex items-center gap-3",children:[n.jsx("div",{className:"flex-1 bg-surface-elevated rounded-full h-1.5 overflow-hidden max-w-[120px]",children:n.jsx("div",{className:"h-full bg-brand-500 rounded-full",style:{width:`${r}%`}})}),n.jsx("span",{className:"text-sm text-fg-secondary tabular-nums",children:To(e.totalTokens)})]})}),n.jsx("td",{className:"px-4 py-3 text-sm text-fg-secondary tabular-nums",children:To(e.tokensUsedToday)}),n.jsx("td",{className:"px-4 py-3 text-sm text-fg-secondary tabular-nums",children:e.requestCount}),n.jsx("td",{className:"px-4 py-3 text-sm text-fg-secondary tabular-nums",children:e.toolCalls}),n.jsx("td",{className:"px-4 py-3 text-sm text-right text-fg-secondary tabular-nums",children:cd(e.estimatedCost)})]})}const Ef={urgent:"bg-red-500",high:"bg-amber-500",normal:"bg-blue-500",low:"bg-gray-400"},id={approval_request:"M9 12l2 2 4-4 M21 12a9 9 0 1 1-18 0 9 9 0 0 1 18 0z",task_completed:"M22 11.08V12a10 10 0 1 1-5.93-9.14 M22 4L12 14.01l-3-3",task_created:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z M14 2v6h6 M16 13H8 M16 17H8 M10 9H8",task_review:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z M14 2v6h6 M16 13H8 M16 17H8 M10 9H8",task_failed:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z M14 2v6h6 M16 13H8 M16 17H8 M10 9H8",requirement_created:"M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7 M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z",requirement_decision:"M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10z",agent_report:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z M14 2v6h6 M16 13H8 M16 17H8",direct_message:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z",group_message:"M17 21v-2a4 4 0 0 0-4-4H5a4 4 0 0 0-4 4v2 M9 7a4 4 0 1 0 0-8 4 4 0 0 0 0 8z M23 21v-2a4 4 0 0 0-3-3.87 M16 3.13a4 4 0 0 1 0 7.75",system:"M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10z"},W3={approval_request:"text-amber-500",task_completed:"text-green-500",task_failed:"text-red-500",task_created:"text-blue-500",task_review:"text-purple-500",requirement_created:"text-amber-500",requirement_decision:"text-green-500",agent_report:"text-blue-500",direct_message:"text-green-500",group_message:"text-brand-500",system:"text-fg-tertiary"};function od(e,t){const r=Date.now()-new Date(e).getTime(),s=Math.floor(r/6e4);if(s<1)return t("common:time.now");if(s<60)return t("common:time.minutesAgo",{count:s});const a=Math.floor(s/60);return a<24?t("common:time.hoursAgo",{count:a}):t("common:time.daysAgo",{count:Math.floor(a/24)})}function Mf(e,t){const r=e.actionType;if(r==="open_chat")return t("team:notifications.actionHints.openChat");if(r==="navigate")return t("team:notifications.actionHints.viewDetails");const s=e.metadata??{};switch(e.type){case"task_completed":case"task_created":case"task_review":case"task_failed":return s.taskId?t("team:notifications.actionHints.viewTask"):null;case"requirement_created":case"requirement_decision":return s.requirementId?t("team:notifications.actionHints.viewRequirement"):null;case"agent_report":return s.agentId?t("team:notifications.actionHints.viewAgent"):null;case"direct_message":return t("team:notifications.actionHints.openChat");case"group_message":return t("team:notifications.actionHints.openChat");case"approval_request":return t("team:notifications.actionHints.viewApproval");default:return s.taskId?t("team:notifications.actionHints.viewTask"):s.requirementId?t("team:notifications.actionHints.viewRequirement"):s.agentId?t("team:notifications.actionHints.viewAgent"):null}}function ose(){try{const e=new AudioContext,t=e.currentTime,r=e.createGain();r.connect(e.destination),r.gain.setValueAtTime(.15,t),r.gain.exponentialRampToValueAtTime(.01,t+.6);const s=e.createOscillator();s.type="sine",s.frequency.setValueAtTime(880,t),s.frequency.setValueAtTime(1174.66,t+.15),s.connect(r),s.start(t),s.stop(t+.6),s.onended=()=>e.close()}catch{}}function aC({collapsed:e,userId:t,embeddedMode:r,onClose:s,sidebarMode:a,isActive:i,label:l,iconPath:d}){const{t:u}=pt(["team","common"]),[m,h]=g.useState(!1),[p,y]=g.useState("approvals"),[x,v]=g.useState([]),[j,C]=g.useState([]),[w,N]=g.useState(null),[S,T]=g.useState(null),[E,R]=g.useState({}),[I,z]=g.useState(0),B=g.useRef(null),D=g.useRef(null),[V,Y]=g.useState({top:0,left:0,width:448,maxHeight:576}),F=g.useRef(null),L=g.useRef(!1),[O,M]=g.useState(!0),[$,W]=g.useState(!1),U=g.useRef(null),H=g.useRef("approvals"),q=30,Z=g.useCallback(async()=>{try{const[se,fe]=await Promise.all([ie.notifications.list(t,!1,{limit:q,offset:0}),ie.approvals.list()]);if(v(se.notifications),z(se.unreadCount??se.notifications.filter(He=>!He.read).length),M(se.totalCount!=null?se.notifications.length<se.totalCount:se.notifications.length>=q),C(fe.approvals),!L.current){const He=fe.approvals.filter(Ae=>Ae.status==="pending").length;F.current=He,L.current=!0}}catch{}},[t]),_=g.useCallback(async()=>{if(!($||!O)){W(!0);try{const se=await ie.notifications.list(t,!1,{limit:q,offset:x.length});se.notifications.length>0&&v(fe=>[...fe,...se.notifications.filter(He=>!fe.some(Ae=>Ae.id===He.id))]),M(se.totalCount!=null?x.length+se.notifications.length<se.totalCount:se.notifications.length>=q)}catch{}W(!1)}},[t,x.length,$,O]),J=g.useCallback(se=>{const fe=se.detail;if(!fe)return;const{taskId:He,requirementId:Ae}=fe;!He&&!Ae||v(et=>{const pe=et.filter(Fe=>!Fe.read&&(He&&Fe.metadata?.taskId===He||Ae&&Fe.metadata?.requirementId===Ae));if(pe.length===0)return et;for(const Fe of pe)ie.notifications.markRead(Fe.id).catch(()=>{});return z(Fe=>Math.max(0,Fe-pe.length)),et.map(Fe=>pe.some(Ve=>Ve.id===Fe.id)?{...Fe,read:!0}:Fe)})},[]);g.useEffect(()=>{Z();const se=setInterval(Z,6e4),fe=()=>Z(),He=()=>{h(!0),Z()};window.addEventListener("markus:notifications-changed",fe),window.addEventListener("markus:mark-read-by-ref",J),window.addEventListener("markus:open-notifications",He);const Ae=pn.on("notification:created",()=>Z()),et=pn.on("approval:created",()=>Z());return()=>{clearInterval(se),window.removeEventListener("markus:notifications-changed",fe),window.removeEventListener("markus:mark-read-by-ref",J),window.removeEventListener("markus:open-notifications",He),Ae(),et()}},[Z,J]);const X=g.useCallback(()=>{if(!B.current)return;const se=B.current.getBoundingClientRect(),fe=window.innerWidth,He=window.innerHeight,Ae=Math.min(448,fe-16),et=Math.min(576,He-16);let pe=se.right+8,Fe=se.top;pe+Ae>fe-8&&(pe=Math.max(8,fe-Ae-8)),Fe+et>He-8&&(Fe=Math.max(8,He-et-8)),Y({top:Fe,left:pe,width:Ae,maxHeight:et})},[]);g.useLayoutEffect(()=>{m&&X()},[m,X]),g.useEffect(()=>{if(m)return window.addEventListener("resize",X),()=>window.removeEventListener("resize",X)},[m,X]),g.useEffect(()=>{if(!m)return;const se=fe=>{B.current?.contains(fe.target)||D.current?.contains(fe.target)||h(!1)};return document.addEventListener("mousedown",se),()=>document.removeEventListener("mousedown",se)},[m]),g.useEffect(()=>{if(!m)return;const se=j.some(He=>He.status==="pending"),fe=x.some(He=>!He.read);y(se&&!fe?"approvals":!se&&fe?"notifications":H.current)},[m]);const ee=new Set(j.filter(se=>se.status==="pending").map(se=>se.id)),te=new Set(j.map(se=>se.id)),G=x.filter(se=>!(se.type==="approval_request"&&se.metadata?.approvalId&&te.has(se.metadata.approvalId))),ue=x.filter(se=>se.type==="approval_request"&&!se.read&&se.metadata?.approvalId&&ee.has(se.metadata.approvalId)).length,Se=Math.max(0,I-ue),Ce=ee.size,Be=Se+Ce;g.useEffect(()=>{F.current!==null&&Ce>F.current&&ose(),F.current=Ce},[Ce]);const Ne=async se=>{await ie.notifications.markRead(se),v(fe=>fe.map(He=>He.id===se?{...He,read:!0}:He)),z(fe=>Math.max(0,fe-1))},he=se=>{const fe=se.metadata??{},He=se.actionType,Ae=se.actionTarget;if(He==="open_chat"&&Ae)try{const et=typeof Ae=="string"?JSON.parse(Ae):Ae;if(et.agentId){const pe={agentId:et.agentId};et.sessionId&&(pe.sessionId=et.sessionId),bt.navigate(De.TEAM,pe);return}}catch{}if(He==="navigate"&&Ae)try{const et=typeof Ae=="string"?JSON.parse(Ae):Ae;if(et.path){if(et.path.startsWith("/team")){const pe={},Fe=new URLSearchParams(et.path.split("?")[1]||"");for(const[Ve,nt]of Fe.entries())pe[Ve]=nt;bt.navigate(De.TEAM,pe);return}if(et.path.startsWith("/work")){const pe={},Fe=new URLSearchParams(et.path.split("?")[1]||"");for(const[Ve,nt]of Fe.entries())pe[Ve]=nt;bt.navigate(De.WORK,pe);return}}}catch{}switch(se.type){case"approval_request":{const et=fe.approvalId,pe=et?j.find(gt=>gt.id===et):void 0,Fe=pe?.details?.taskId??fe.taskId,Ve=pe?.details?.requirementId??fe.requirementId,nt=pe?.details?.agentId??pe?.agentId;Fe?bt.navigate(De.WORK,{openTask:Fe}):Ve?bt.navigate(De.WORK,{openRequirement:Ve}):nt?bt.navigate(De.TEAM,{agentId:nt}):bt.navigate(De.WORK);break}case"task_completed":case"task_created":case"task_review":case"task_failed":fe.taskId?bt.navigate(De.WORK,{openTask:fe.taskId}):bt.navigate(De.WORK);break;case"requirement_created":case"requirement_decision":fe.requirementId?bt.navigate(De.WORK,{openRequirement:fe.requirementId}):bt.navigate(De.WORK);break;case"agent_report":case"system":{if(fe.agentId){const et={agentId:fe.agentId};fe.sessionId&&(et.sessionId=fe.sessionId),bt.navigate(De.TEAM,et)}else bt.navigate(De.TEAM);break}case"direct_message":{const et=fe.senderId;et?bt.navigate(De.TEAM,{dm:et}):bt.navigate(De.TEAM);break}case"group_message":{const et=fe.channel;et?bt.navigate(De.TEAM,{channel:et}):bt.navigate(De.TEAM);break}default:fe.taskId?bt.navigate(De.WORK,{openTask:fe.taskId}):fe.requirementId?bt.navigate(De.WORK,{openRequirement:fe.requirementId}):fe.projectId?bt.navigate(De.WORK,{projectId:fe.projectId}):fe.agentId&&bt.navigate(De.TEAM,{agentId:fe.agentId});break}},_e=async se=>{se.read||Ne(se.id);const fe=se.metadata??{},He=fe.taskId,Ae=fe.requirementId;if(He||Ae){const et=x.filter(pe=>pe.id!==se.id&&!pe.read&&(He&&pe.metadata?.taskId===He||Ae&&pe.metadata?.requirementId===Ae));for(const pe of et)Ne(pe.id)}he(se)},Ee=async(se,fe,He,Ae)=>{N(se);try{const{approval:et}=await ie.approvals.respond(se,fe,t,He,Ae);C(nt=>nt.map(gt=>gt.id===se?et:gt)),T(null),R(nt=>{const gt={...nt};return delete gt[se],gt});const pe=et.details?.taskId,Fe=et.details?.requirementId,Ve=x.filter(nt=>!nt.read&&(nt.type==="approval_request"&&nt.metadata?.approvalId===se||pe&&nt.metadata?.taskId===pe||Fe&&nt.metadata?.requirementId===Fe));if(Ve.length>0){for(const gt of Ve)ie.notifications.markRead(gt.id).catch(()=>{});const nt=new Set(Ve.map(gt=>gt.id));v(gt=>gt.map(rt=>nt.has(rt.id)?{...rt,read:!0}:rt)),z(gt=>Math.max(0,gt-Ve.length))}pl("/approvals"),pl("/notifications"),pl("/tasks"),pl("/taskboard"),pl("/requirements"),window.dispatchEvent(new CustomEvent("markus:data-changed")),window.dispatchEvent(new CustomEvent("markus:notifications-changed")),setTimeout(()=>Z(),800)}catch{}N(null)},Ye=async()=>{try{if(!t)return;await ie.notifications.markAllRead(t),v(se=>se.map(fe=>({...fe,read:!0}))),z(0),pl("/notifications")}catch{const se=G.filter(fe=>!fe.read);await Promise.all(se.map(fe=>ie.notifications.markRead(fe.id))),v(fe=>fe.map(He=>({...He,read:!0}))),z(0),pl("/notifications")}},Ze=se=>{const fe=se.details?.subType;return fe==="requirement_resubmit"?u("team:notifications.approvalType.requirementResubmit"):fe==="requirement"||se.details?.requirementId?u("team:notifications.approvalType.requirement"):fe==="task_review"?u("team:notifications.approvalType.taskReview"):fe==="task"||se.details?.taskId?u("team:notifications.approvalType.task"):se.details?.toolName?u("team:notifications.approvalType.toolExecution"):null},mt=se=>{const fe=[];fe.push(se.agentName);const He=se.details?.taskTitle,Ae=se.details?.taskId;He?fe.push(He):Ae&&fe.push(`Task ${Ae.slice(0,8)}`);const et=se.details?.requirementId;return et&&!Ae&&fe.push(`Req ${et.slice(0,8)}`),fe.join(" · ")},it=[...j].sort((se,fe)=>new Date(fe.requestedAt).getTime()-new Date(se.requestedAt).getTime()),Lt=it.filter(se=>se.status==="pending"),ht=it.filter(se=>se.status!=="pending"),ne=se=>{const fe=se.details?.taskId,He=se.details?.requirementId,Ae=se.details?.agentId??se.agentId;fe?bt.navigate(De.WORK,{openTask:fe}):He?bt.navigate(De.WORK,{openRequirement:He}):Ae?bt.navigate(De.TEAM,{agentId:Ae}):bt.navigate(De.WORK)},me=()=>{h(!1),s?.()},be=n.jsxs(n.Fragment,{children:[n.jsxs("div",{className:"flex border-b border-border-default shrink-0",children:[n.jsxs("button",{onClick:()=>{y("approvals"),H.current="approvals"},className:`flex-1 px-3 py-2.5 text-xs font-medium transition-colors ${p==="approvals"?"text-fg-primary border-b-2 border-brand-500":"text-fg-tertiary hover:text-fg-secondary"}`,children:[u("team:notifications.approvals"),Ce>0?` (${Ce})`:""]}),n.jsxs("button",{onClick:()=>{y("notifications"),H.current="notifications"},className:`flex-1 px-3 py-2.5 text-xs font-medium transition-colors ${p==="notifications"?"text-fg-primary border-b-2 border-brand-500":"text-fg-tertiary hover:text-fg-secondary"}`,children:[u("team:notifications.notifications"),Se>0?` (${Se})`:""]}),n.jsx("button",{onClick:me,className:"px-2 py-2 text-fg-tertiary hover:text-fg-primary transition-colors shrink-0",title:u("common:close"),children:n.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("path",{d:"M18 6L6 18"}),n.jsx("path",{d:"M6 6l12 12"})]})})]}),p==="notifications"&&I>0&&n.jsx("div",{className:"flex justify-end px-3 py-1.5 border-b border-border-default/50 shrink-0",children:n.jsx("button",{onClick:Ye,className:"text-[10px] text-brand-500 hover:text-brand-400 transition-colors",children:u("team:notifications.markAllRead")})}),n.jsxs("div",{ref:U,className:"flex-1 overflow-y-auto",onScroll:se=>{if(p!=="notifications"||!O||$)return;const fe=se.currentTarget;fe.scrollTop+fe.clientHeight>=fe.scrollHeight-80&&_()},children:[p==="approvals"&&(j.length===0?n.jsx("div",{className:"p-6 text-center text-xs text-fg-tertiary",children:u("team:notifications.noApprovals")}):n.jsxs("div",{className:"divide-y divide-border-default/50",children:[Lt.map(se=>{const fe=se.details?.command,He=fe?se.description.replace(/\s*Command:.*$/,""):se.description;return n.jsxs("div",{className:"px-3 py-3 space-y-2.5",children:[n.jsxs("div",{className:"cursor-pointer hover:bg-surface-overlay/50 -mx-3 -mt-3 px-3 pt-3 pb-1 rounded-t-md transition-colors",onClick:()=>ne(se),children:[n.jsxs("div",{className:"flex items-start gap-2",children:[n.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"text-amber-500 mt-0.5 shrink-0",children:n.jsx("path",{d:id.approval_request})}),n.jsxs("div",{className:"flex-1 min-w-0",children:[n.jsxs("div",{className:"flex items-center gap-2",children:[Ze(se)&&n.jsx("span",{className:"text-[10px] text-amber-500 font-medium shrink-0",children:Ze(se)}),n.jsx("span",{className:"text-xs text-fg-primary font-medium truncate",children:se.title}),n.jsx("span",{className:"text-[10px] text-fg-tertiary shrink-0",children:od(se.requestedAt,u)})]}),n.jsx("div",{className:"text-[11px] text-fg-tertiary mt-0.5",children:se.agentName})]})]}),n.jsx("div",{className:"mt-2.5 text-[11px] text-fg-secondary leading-relaxed",children:n.jsx(Wr,{content:He,className:"text-[11px] [&_h1]:text-xs [&_h2]:text-[11px] [&_h3]:text-[11px] [&_p]:text-[11px] [&_li]:text-[11px]"})}),fe&&n.jsx("pre",{className:"text-[11px] text-fg-primary bg-surface-overlay border border-border-default rounded-md px-2.5 py-2 overflow-x-auto whitespace-pre-wrap break-all font-mono leading-relaxed mt-2",children:fe})]}),(()=>{const Ae=se.details?.subType,et=Ae==="task"||Ae==="requirement"||Ae==="requirement_resubmit",pe=se.options&&se.options.length>0,Fe=(E[se.id]??"").trim();return pe?n.jsxs("div",{className:"space-y-1.5",children:[se.options.map((Ve,nt)=>n.jsxs("button",{disabled:w===se.id,onClick:()=>Ee(se.id,Ve.id!=="reject",Fe||void 0,Ve.id),className:`w-full px-3 py-2 text-left text-[11px] font-medium rounded-md disabled:opacity-50 transition-colors flex items-center gap-2 ${Ve.id==="reject"||Ve.id==="request_changes"?"border border-border-default text-fg-secondary hover:bg-surface-overlay":"bg-brand-600 text-white hover:bg-brand-700"}`,title:Ve.description,children:[n.jsx("span",{className:"w-5 h-5 rounded-full bg-white/20 flex items-center justify-center text-[10px] font-bold shrink-0",children:String.fromCharCode(65+nt)}),Ve.label]},Ve.id)),n.jsxs("div",{className:"flex gap-1.5 mt-1",children:[n.jsx("input",{type:"text",placeholder:u("team:notifications.freeformPlaceholder"),value:E[se.id]??"",onChange:Ve=>R(nt=>({...nt,[se.id]:Ve.target.value})),onKeyDown:Ve=>{Ve.key==="Enter"&&(E[se.id]??"").trim()&&Ee(se.id,!0,(E[se.id]??"").trim(),"custom")},className:"flex-1 px-2.5 py-1.5 text-[11px] bg-surface-overlay border border-border-default rounded-md text-fg-primary placeholder:text-fg-tertiary focus:outline-none focus:ring-1 focus:ring-brand-500/50"}),n.jsx("button",{disabled:w===se.id||!(E[se.id]??"").trim(),onClick:()=>Ee(se.id,!0,(E[se.id]??"").trim(),"custom"),className:"px-2.5 py-1.5 text-[11px] font-medium bg-brand-600 text-white rounded-md hover:bg-brand-700 disabled:opacity-50 transition-colors",children:u("common:send")})]})]}):et?n.jsxs("div",{className:"space-y-1.5",children:[n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsxs("button",{disabled:w===se.id,onClick:()=>Ee(se.id,!0,void 0,"approve"),className:"px-3 py-1.5 text-[11px] font-medium bg-green-600 text-white rounded-md hover:bg-green-700 disabled:opacity-50 transition-colors inline-flex items-center gap-1.5",children:[n.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:n.jsx("path",{d:"M20 6L9 17l-5-5"})}),u("common:approve")]}),n.jsxs("button",{disabled:w===se.id,onClick:()=>Ee(se.id,!1,void 0,"reject"),className:"px-3 py-1.5 text-[11px] font-medium bg-red-600/80 text-white rounded-md hover:bg-red-700 disabled:opacity-50 transition-colors inline-flex items-center gap-1.5",children:[n.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("path",{d:"M18 6L6 18"}),n.jsx("path",{d:"M6 6l12 12"})]}),u("common:reject")]}),S!==se.id&&n.jsxs("button",{disabled:w===se.id,onClick:()=>T(se.id),className:"px-3 py-1.5 text-[11px] font-medium border border-amber-500/50 text-amber-500 rounded-md hover:bg-amber-500/10 disabled:opacity-50 transition-colors inline-flex items-center gap-1.5",children:[n.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("path",{d:"M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"}),n.jsx("path",{d:"M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z"})]}),u("team:notifications.needsAdjustment")]})]}),S===se.id&&n.jsxs("div",{className:"space-y-1.5",children:[n.jsx("input",{type:"text",autoFocus:!0,placeholder:u("team:notifications.adjustmentPlaceholder"),value:E[se.id]??"",onChange:Ve=>R(nt=>({...nt,[se.id]:Ve.target.value})),onKeyDown:Ve=>{Ve.key==="Enter"&&(E[se.id]??"").trim()&&Ee(se.id,!1,(E[se.id]??"").trim(),"needs_adjustment"),Ve.key==="Escape"&&T(null)},className:"w-full px-2.5 py-1.5 text-[11px] bg-surface-overlay border border-border-default rounded-md text-fg-primary placeholder:text-fg-tertiary focus:outline-none focus:ring-1 focus:ring-amber-500/50"}),n.jsxs("div",{className:"flex gap-2",children:[n.jsx("button",{disabled:w===se.id||!(E[se.id]??"").trim(),onClick:()=>Ee(se.id,!1,(E[se.id]??"").trim(),"needs_adjustment"),className:"px-2.5 py-1.5 text-[11px] font-medium bg-amber-600 text-white rounded-md hover:bg-amber-700 disabled:opacity-50 transition-colors",children:u("team:notifications.confirmAdjustment")}),n.jsx("button",{onClick:()=>T(null),className:"px-2.5 py-1.5 text-[11px] font-medium border border-border-default text-fg-secondary rounded-md hover:bg-surface-overlay transition-colors",children:u("common:cancel")})]})]})]}):n.jsxs("div",{className:"space-y-1.5",children:[n.jsx("input",{type:"text",placeholder:u("team:notifications.commentPlaceholder"),value:E[se.id]??"",onChange:Ve=>R(nt=>({...nt,[se.id]:Ve.target.value})),onKeyDown:Ve=>{Ve.key==="Enter"&&Ee(se.id,!0,Fe||void 0,"approve")},className:"w-full px-2.5 py-1.5 text-[11px] bg-surface-overlay border border-border-default rounded-md text-fg-primary placeholder:text-fg-tertiary focus:outline-none focus:ring-1 focus:ring-brand-500/50"}),n.jsxs("div",{className:"flex gap-2",children:[n.jsx("button",{disabled:w===se.id,onClick:()=>Ee(se.id,!0,Fe||void 0,"approve"),className:"flex-1 px-2.5 py-1.5 text-[11px] font-medium bg-green-600 text-white rounded-md hover:bg-green-700 disabled:opacity-50 transition-colors",children:u("common:approve")}),n.jsx("button",{disabled:w===se.id,onClick:()=>Ee(se.id,!1,Fe||void 0,"reject"),className:"flex-1 px-2.5 py-1.5 text-[11px] font-medium border border-border-default text-fg-secondary rounded-md hover:bg-surface-overlay disabled:opacity-50 transition-colors",children:u("common:reject")})]})]})})()]},se.id)}),ht.length>0&&n.jsxs(n.Fragment,{children:[Lt.length>0&&n.jsx("div",{className:"px-3 py-1.5 text-[10px] font-medium text-fg-tertiary uppercase tracking-wider bg-surface-overlay/30",children:u("team:notifications.approvalHistory")}),ht.slice(0,50).map(se=>n.jsxs("button",{onClick:()=>ne(se),className:"w-full text-left px-3 py-2.5 hover:bg-surface-overlay/50 transition-colors group",children:[n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx("span",{className:`w-1.5 h-1.5 rounded-full shrink-0 ${se.status==="approved"?"bg-green-500":se.status==="cancelled"||se.status==="expired"?"bg-gray-400":"bg-red-500"}`}),Ze(se)&&n.jsx("span",{className:"text-[10px] text-fg-tertiary font-medium shrink-0",children:Ze(se)}),n.jsx("span",{className:"text-xs text-fg-secondary truncate flex-1 group-hover:text-fg-primary",children:se.title}),n.jsx("span",{className:`text-[10px] font-medium shrink-0 ${se.status==="approved"?"text-green-500":se.status==="cancelled"||se.status==="expired"?"text-fg-muted":"text-red-500"}`,children:u(`common:status.${se.status}`,{defaultValue:se.status})})]}),n.jsxs("div",{className:"flex items-center gap-1.5 mt-0.5 pl-3.5",children:[n.jsx("span",{className:"text-[10px] text-fg-muted truncate",children:mt(se)}),n.jsx("span",{className:"text-[10px] text-fg-muted shrink-0",children:"·"}),n.jsx("span",{className:"text-[10px] text-fg-muted shrink-0",children:od(se.respondedAt??se.requestedAt,u)})]}),se.responseComment&&n.jsxs("p",{className:"text-[10px] text-fg-muted mt-0.5 pl-3.5 truncate",children:["“",se.responseComment,"”"]})]},se.id))]})]})),p==="notifications"&&(G.length===0?n.jsx("div",{className:"p-6 text-center text-xs text-fg-tertiary",children:u("team:notifications.noNotifications")}):n.jsxs("div",{className:"divide-y divide-border-default/50",children:[G.map(se=>{const fe=W3[se.type]??"text-fg-tertiary";return n.jsxs("div",{role:"button",tabIndex:0,onClick:()=>_e(se),onKeyDown:He=>{(He.key==="Enter"||He.key===" ")&&(He.preventDefault(),_e(se))},className:`w-full text-left px-3 py-2.5 flex gap-2.5 transition-colors cursor-pointer ${se.read?"opacity-50 hover:opacity-70":"hover:bg-surface-overlay"}`,children:[n.jsx("div",{className:"shrink-0 mt-0.5",children:n.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:fe,children:n.jsx("path",{d:id[se.type]??id.system})})}),n.jsxs("div",{className:"flex-1 min-w-0",children:[n.jsxs("div",{className:"flex items-center gap-1.5",children:[!se.read&&n.jsx("span",{className:`w-1.5 h-1.5 rounded-full shrink-0 ${Ef[se.priority]??Ef.normal}`}),n.jsx("span",{className:"text-xs text-fg-primary font-medium truncate",children:se.title})]}),n.jsx("div",{className:"text-[11px] text-fg-tertiary mt-0.5 ",children:n.jsx(Wr,{content:se.body,className:"text-[11px] [&_h1]:text-xs [&_h2]:text-[11px] [&_h3]:text-[11px] [&_p]:text-[11px] [&_li]:text-[11px] [&_p]:text-fg-tertiary"})}),n.jsxs("div",{className:"flex items-center gap-2 mt-0.5",children:[n.jsx("span",{className:"text-[10px] text-fg-muted",children:od(se.createdAt,u)}),Mf(se,u)&&n.jsx("span",{className:`text-[10px] font-medium ${fe}`,children:Mf(se,u)})]})]})]},se.id)}),$&&n.jsx("div",{className:"py-3 text-center",children:n.jsxs("svg",{className:"animate-spin h-4 w-4 text-fg-tertiary mx-auto",viewBox:"0 0 24 24",fill:"none",children:[n.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),n.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"})]})})]}))]})]});if(r){const se=["approvals","notifications"],fe=se.indexOf(p),He=(()=>{let Ae=0,et=0;return{onTouchStart:pe=>{Ae=pe.touches[0].clientX,et=pe.touches[0].clientY},onTouchEnd:pe=>{const Fe=pe.changedTouches[0].clientX-Ae,Ve=pe.changedTouches[0].clientY-et;Math.abs(Fe)>60&&Math.abs(Fe)>Math.abs(Ve)*1.5&&(Fe<0&&fe<se.length-1&&y(se[fe+1]),Fe>0&&fe>0&&y(se[fe-1]))}}})();return n.jsxs("div",{className:"flex flex-col h-full overflow-hidden",children:[n.jsx("div",{className:"flex border-b border-border-default shrink-0",children:se.map(Ae=>n.jsx("button",{onClick:()=>y(Ae),className:`flex-1 px-3 py-3 text-sm font-medium transition-colors ${p===Ae?"text-fg-primary border-b-2 border-brand-500":"text-fg-tertiary"}`,children:Ae==="approvals"?n.jsxs(n.Fragment,{children:[u("team:notifications.approvals"),Ce>0?` (${Ce})`:""]}):n.jsxs(n.Fragment,{children:[u("team:notifications.notifications"),Se>0?` (${Se})`:""]})},Ae))}),p==="notifications"&&I>0&&n.jsx("div",{className:"flex justify-end px-3 py-1.5 border-b border-border-default/50 shrink-0",children:n.jsx("button",{onClick:Ye,className:"text-[10px] text-brand-500 hover:text-brand-400 transition-colors",children:u("team:notifications.markAllRead")})}),n.jsx("div",{className:"flex-1 overflow-hidden relative",...He,children:n.jsxs("div",{className:"flex h-full transition-transform duration-300 ease-out",style:{transform:`translateX(-${fe*100}%)`},children:[n.jsx("div",{className:"w-full shrink-0 h-full overflow-y-auto scrollbar-thin",children:j.length===0?n.jsx("div",{className:"p-6 text-center text-xs text-fg-tertiary",children:u("team:notifications.noApprovals")}):n.jsxs("div",{className:"divide-y divide-border-default/50",children:[Lt.map(Ae=>{const et=Ae.details?.command,pe=et?Ae.description.replace(/\s*Command:.*$/,""):Ae.description;return n.jsxs("div",{className:"px-3 py-3 space-y-2.5",children:[n.jsxs("div",{className:"cursor-pointer hover:bg-surface-overlay/50 -mx-3 -mt-3 px-3 pt-3 pb-1 rounded-t-md transition-colors",onClick:()=>ne(Ae),children:[n.jsxs("div",{className:"flex items-start gap-2",children:[n.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"text-amber-500 mt-0.5 shrink-0",children:n.jsx("path",{d:id.approval_request})}),n.jsxs("div",{className:"flex-1 min-w-0",children:[n.jsxs("div",{className:"flex items-center gap-2",children:[Ze(Ae)&&n.jsx("span",{className:"text-[10px] text-amber-500 font-medium shrink-0",children:Ze(Ae)}),n.jsx("span",{className:"text-xs text-fg-primary font-medium truncate",children:Ae.title}),n.jsx("span",{className:"text-[10px] text-fg-tertiary shrink-0",children:od(Ae.requestedAt,u)})]}),n.jsx("div",{className:"text-[11px] text-fg-tertiary mt-0.5",children:Ae.agentName})]})]}),n.jsx("div",{className:"mt-2.5 text-[11px] text-fg-secondary leading-relaxed",children:n.jsx(Wr,{content:pe,className:"text-[11px] [&_h1]:text-xs [&_h2]:text-[11px] [&_h3]:text-[11px] [&_p]:text-[11px] [&_li]:text-[11px]"})}),et&&n.jsx("pre",{className:"text-[11px] text-fg-primary bg-surface-overlay border border-border-default rounded-md px-2.5 py-2 overflow-x-auto whitespace-pre-wrap break-all font-mono leading-relaxed mt-2",children:et})]}),(()=>{const Fe=Ae.details?.subType,Ve=Fe==="task"||Fe==="requirement"||Fe==="requirement_resubmit",nt=Ae.options&&Ae.options.length>0,gt=(E[Ae.id]??"").trim();return nt?n.jsxs("div",{className:"space-y-1.5",children:[Ae.options.map((rt,Et)=>n.jsxs("button",{disabled:w===Ae.id,onClick:()=>Ee(Ae.id,rt.id!=="reject",gt||void 0,rt.id),className:`w-full px-3 py-2 text-left text-[11px] font-medium rounded-md disabled:opacity-50 transition-colors flex items-center gap-2 ${rt.id==="reject"||rt.id==="request_changes"?"border border-border-default text-fg-secondary hover:bg-surface-overlay":"bg-brand-600 text-white hover:bg-brand-700"}`,title:rt.description,children:[n.jsx("span",{className:"w-5 h-5 rounded-full bg-white/20 flex items-center justify-center text-[10px] font-bold shrink-0",children:String.fromCharCode(65+Et)}),rt.label]},rt.id)),n.jsxs("div",{className:"flex gap-1.5 mt-1",children:[n.jsx("input",{type:"text",placeholder:u("team:notifications.freeformPlaceholder"),value:E[Ae.id]??"",onChange:rt=>R(Et=>({...Et,[Ae.id]:rt.target.value})),onKeyDown:rt=>{rt.key==="Enter"&&(E[Ae.id]??"").trim()&&Ee(Ae.id,!0,(E[Ae.id]??"").trim(),"custom")},className:"flex-1 px-2.5 py-1.5 text-[11px] bg-surface-overlay border border-border-default rounded-md text-fg-primary placeholder:text-fg-tertiary focus:outline-none focus:ring-1 focus:ring-brand-500/50"}),n.jsx("button",{disabled:w===Ae.id||!(E[Ae.id]??"").trim(),onClick:()=>Ee(Ae.id,!0,(E[Ae.id]??"").trim(),"custom"),className:"px-2.5 py-1.5 text-[11px] font-medium bg-brand-600 text-white rounded-md hover:bg-brand-700 disabled:opacity-50 transition-colors",children:u("common:send")})]})]}):Ve?n.jsxs("div",{className:"space-y-1.5",children:[n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsxs("button",{disabled:w===Ae.id,onClick:()=>Ee(Ae.id,!0,void 0,"approve"),className:"px-3 py-1.5 text-[11px] font-medium bg-green-600 text-white rounded-md hover:bg-green-700 disabled:opacity-50 transition-colors inline-flex items-center gap-1.5",children:[n.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:n.jsx("path",{d:"M20 6L9 17l-5-5"})}),u("common:approve")]}),n.jsxs("button",{disabled:w===Ae.id,onClick:()=>Ee(Ae.id,!1,void 0,"reject"),className:"px-3 py-1.5 text-[11px] font-medium bg-red-600/80 text-white rounded-md hover:bg-red-700 disabled:opacity-50 transition-colors inline-flex items-center gap-1.5",children:[n.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("path",{d:"M18 6L6 18"}),n.jsx("path",{d:"M6 6l12 12"})]}),u("common:reject")]}),S!==Ae.id&&n.jsxs("button",{disabled:w===Ae.id,onClick:()=>T(Ae.id),className:"px-3 py-1.5 text-[11px] font-medium border border-amber-500/50 text-amber-500 rounded-md hover:bg-amber-500/10 disabled:opacity-50 transition-colors inline-flex items-center gap-1.5",children:[n.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("path",{d:"M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"}),n.jsx("path",{d:"M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z"})]}),u("team:notifications.needsAdjustment")]})]}),S===Ae.id&&n.jsxs("div",{className:"space-y-1.5",children:[n.jsx("input",{type:"text",autoFocus:!0,placeholder:u("team:notifications.adjustmentPlaceholder"),value:E[Ae.id]??"",onChange:rt=>R(Et=>({...Et,[Ae.id]:rt.target.value})),onKeyDown:rt=>{rt.key==="Enter"&&(E[Ae.id]??"").trim()&&Ee(Ae.id,!1,(E[Ae.id]??"").trim(),"needs_adjustment"),rt.key==="Escape"&&T(null)},className:"w-full px-2.5 py-1.5 text-[11px] bg-surface-overlay border border-border-default rounded-md text-fg-primary placeholder:text-fg-tertiary focus:outline-none focus:ring-1 focus:ring-amber-500/50"}),n.jsxs("div",{className:"flex gap-2",children:[n.jsx("button",{disabled:w===Ae.id||!(E[Ae.id]??"").trim(),onClick:()=>Ee(Ae.id,!1,(E[Ae.id]??"").trim(),"needs_adjustment"),className:"px-2.5 py-1.5 text-[11px] font-medium bg-amber-600 text-white rounded-md hover:bg-amber-700 disabled:opacity-50 transition-colors",children:u("team:notifications.confirmAdjustment")}),n.jsx("button",{onClick:()=>T(null),className:"px-2.5 py-1.5 text-[11px] font-medium border border-border-default text-fg-secondary rounded-md hover:bg-surface-overlay transition-colors",children:u("common:cancel")})]})]})]}):n.jsxs("div",{className:"space-y-1.5",children:[n.jsx("input",{type:"text",placeholder:u("team:notifications.commentPlaceholder"),value:E[Ae.id]??"",onChange:rt=>R(Et=>({...Et,[Ae.id]:rt.target.value})),onKeyDown:rt=>{rt.key==="Enter"&&Ee(Ae.id,!0,gt||void 0,"approve")},className:"w-full px-2.5 py-1.5 text-[11px] bg-surface-overlay border border-border-default rounded-md text-fg-primary placeholder:text-fg-tertiary focus:outline-none focus:ring-1 focus:ring-brand-500/50"}),n.jsxs("div",{className:"flex gap-2",children:[n.jsx("button",{disabled:w===Ae.id,onClick:()=>Ee(Ae.id,!0,gt||void 0,"approve"),className:"flex-1 px-2.5 py-1.5 text-[11px] font-medium bg-green-600 text-white rounded-md hover:bg-green-700 disabled:opacity-50 transition-colors",children:u("common:approve")}),n.jsx("button",{disabled:w===Ae.id,onClick:()=>Ee(Ae.id,!1,gt||void 0,"reject"),className:"flex-1 px-2.5 py-1.5 text-[11px] font-medium border border-border-default text-fg-secondary rounded-md hover:bg-surface-overlay disabled:opacity-50 transition-colors",children:u("common:reject")})]})]})})()]},Ae.id)}),ht.length>0&&n.jsxs(n.Fragment,{children:[Lt.length>0&&n.jsx("div",{className:"px-3 py-1.5 text-[10px] font-medium text-fg-tertiary uppercase tracking-wider bg-surface-overlay/30",children:u("team:notifications.approvalHistory")}),ht.slice(0,50).map(Ae=>n.jsxs("button",{onClick:()=>ne(Ae),className:"w-full text-left px-3 py-2.5 hover:bg-surface-overlay/50 transition-colors",children:[n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx("span",{className:`w-1.5 h-1.5 rounded-full shrink-0 ${Ae.status==="approved"?"bg-green-500":Ae.status==="cancelled"||Ae.status==="expired"?"bg-gray-400":"bg-red-500"}`}),n.jsx("span",{className:"text-xs text-fg-secondary truncate flex-1",children:Ae.title}),n.jsx("span",{className:`text-[10px] font-medium shrink-0 ${Ae.status==="approved"?"text-green-500":Ae.status==="cancelled"||Ae.status==="expired"?"text-fg-muted":"text-red-500"}`,children:u(`common:status.${Ae.status}`,{defaultValue:Ae.status})})]}),n.jsxs("div",{className:"flex items-center gap-1.5 mt-0.5 pl-3.5",children:[n.jsx("span",{className:"text-[10px] text-fg-muted truncate",children:mt(Ae)}),n.jsx("span",{className:"text-[10px] text-fg-muted shrink-0",children:"·"}),n.jsx("span",{className:"text-[10px] text-fg-muted shrink-0",children:od(Ae.respondedAt??Ae.requestedAt,u)})]})]},Ae.id))]})]})}),n.jsx("div",{className:"w-full shrink-0 h-full overflow-y-auto scrollbar-thin",children:G.length===0?n.jsx("div",{className:"p-6 text-center text-xs text-fg-tertiary",children:u("team:notifications.noNotifications")}):n.jsx("div",{className:"divide-y divide-border-default/50",children:G.slice(0,50).map(Ae=>{const et=W3[Ae.type]??"text-fg-tertiary";return n.jsxs("button",{onClick:()=>_e(Ae),className:`w-full text-left px-3 py-2.5 flex gap-2.5 transition-colors ${Ae.read?"opacity-50 hover:opacity-70":"hover:bg-surface-overlay"}`,children:[n.jsx("div",{className:"shrink-0 mt-0.5",children:n.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:et,children:n.jsx("path",{d:id[Ae.type]??id.system})})}),n.jsxs("div",{className:"flex-1 min-w-0",children:[n.jsxs("div",{className:"flex items-center gap-1.5",children:[!Ae.read&&n.jsx("span",{className:`w-1.5 h-1.5 rounded-full shrink-0 ${Ef[Ae.priority]??Ef.normal}`}),n.jsx("span",{className:"text-xs text-fg-primary font-medium truncate",children:Ae.title})]}),n.jsx("div",{className:"text-[11px] text-fg-tertiary mt-0.5 ",children:n.jsx(Wr,{content:Ae.body,className:"text-[11px] [&_h1]:text-xs [&_h2]:text-[11px] [&_h3]:text-[11px] [&_p]:text-[11px] [&_li]:text-[11px] [&_p]:text-fg-tertiary"})}),n.jsxs("div",{className:"flex items-center gap-2 mt-0.5",children:[n.jsx("span",{className:"text-[10px] text-fg-muted",children:od(Ae.createdAt,u)}),Mf(Ae,u)&&n.jsx("span",{className:`text-[10px] font-medium ${et}`,children:Mf(Ae,u)})]})]})]},Ae.id)})})})]})})]})}if(a){const se=d||"M18 8A6 6 0 0 0 6 8c0 7-3 9-3 9h18s-3-2-3-9 M13.73 21a2 2 0 0 1-3.46 0";return n.jsxs(n.Fragment,{children:[n.jsxs("button",{ref:B,onClick:()=>{h(!m),m||Z()},title:e?l||u("team:notifications.bellTitle"):void 0,className:`w-full flex items-center ${e?"flex-col justify-center px-1 py-1.5 gap-0.5":"gap-3 px-3 py-[7px]"} rounded-xl text-[13px] mb-0.5 transition-all relative ${m||i?"bg-brand-600 text-white shadow-sm shadow-brand-900/30 font-medium":"text-fg-secondary hover:bg-surface-overlay hover:text-fg-primary"}`,children:[n.jsx("svg",{width:e?16:18,height:e?16:18,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:"shrink-0",children:n.jsx("path",{d:se})}),e?n.jsx("span",{className:"text-[9px] leading-tight truncate w-full text-center",children:l}):n.jsx("span",{className:"truncate",children:l}),Be>0&&n.jsx("span",{className:`absolute ${e?"top-0.5 right-1":"top-1 left-[22px]"} min-w-[16px] h-4 px-1 rounded-full bg-red-500 text-white text-[10px] font-bold flex items-center justify-center leading-none`,children:Be>99?u("common:badgeOverLimit"):Be})]}),m&&lc.createPortal(n.jsx("div",{ref:D,className:"fixed bg-surface-secondary border border-border-default rounded-xl shadow-2xl z-[9999] flex flex-col overflow-hidden",style:{top:V.top,left:V.left,width:V.width,maxHeight:V.maxHeight},children:be}),document.body)]})}return n.jsxs(n.Fragment,{children:[n.jsxs("button",{ref:B,onClick:()=>{h(!m),m||Z()},className:`relative flex items-center justify-center rounded-md transition-colors ${e?"w-8 h-8":"w-7 h-7"} ${m?"bg-surface-overlay text-fg-primary":"text-fg-tertiary hover:text-fg-secondary hover:bg-surface-overlay"}`,title:u("team:notifications.bellTitle"),children:[n.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("path",{d:"M18 8A6 6 0 0 0 6 8c0 7-3 9-3 9h18s-3-2-3-9"}),n.jsx("path",{d:"M13.73 21a2 2 0 0 1-3.46 0"})]}),Be>0&&n.jsx("span",{className:"absolute -top-0.5 -right-0.5 min-w-[16px] h-4 px-1 rounded-full bg-red-500 text-white text-[10px] font-bold flex items-center justify-center leading-none",children:Be>99?u("common:badgeOverLimit"):Be})]}),m&&lc.createPortal(n.jsx("div",{ref:D,className:"fixed bg-surface-secondary border border-border-default rounded-xl shadow-2xl z-[9999] flex flex-col overflow-hidden",style:{top:V.top,left:V.left,width:V.width,maxHeight:V.maxHeight},children:be}),document.body)]})}function lse({authUser:e}){const{t}=pt("nav"),r=Rs();return n.jsxs("div",{className:"flex-1 flex flex-col overflow-hidden",children:[n.jsxs("div",{className:"flex items-center gap-2 px-4 h-14",children:[r&&n.jsx(gc,{}),n.jsx("h2",{className:"text-base font-bold",children:t("notifications")})]}),n.jsx("div",{className:"flex-1 overflow-hidden",children:n.jsx(aC,{collapsed:!1,userId:e?.id,embeddedMode:!0})})]})}function cse(){const{t:e}=pt(["common","home","work"]),[t,r]=g.useState(""),[s,a]=g.useState("all"),[i,l]=g.useState({agents:[],tasks:[],requirements:[],projects:[],deliverables:[]}),[d,u]=g.useState(!1),[m,h]=g.useState(!1),p=g.useRef(null),y=g.useRef(void 0);g.useEffect(()=>{setTimeout(()=>p.current?.focus(),100)},[]);const x=g.useCallback(async w=>{if(!w.trim()){l({agents:[],tasks:[],requirements:[],projects:[],deliverables:[]}),h(!1);return}u(!0),h(!0);const N=w.toLowerCase();try{const[S,T,E,R,I]=await Promise.allSettled([ie.agents.list(),ie.tasks.list({search:w,pageSize:20}),ie.requirements.list(),ie.projects.list(),ie.deliverables.search({q:w,limit:20})]),z=S.status==="fulfilled"?S.value.agents.filter(F=>F.name?.toLowerCase().includes(N)||F.role?.toLowerCase().includes(N)):[],B=T.status==="fulfilled"?T.value.tasks:[],D=E.status==="fulfilled"?E.value.requirements.filter(F=>F.title?.toLowerCase().includes(N)||F.description?.toLowerCase().includes(N)):[],V=R.status==="fulfilled"?R.value.projects.filter(F=>F.name?.toLowerCase().includes(N)||F.description?.toLowerCase().includes(N)):[],Y=I.status==="fulfilled"?I.value.results:[];l({agents:z,tasks:B,requirements:D,projects:V,deliverables:Y})}catch{l({agents:[],tasks:[],requirements:[],projects:[],deliverables:[]})}finally{u(!1)}},[]),v=w=>{r(w),y.current&&clearTimeout(y.current),y.current=setTimeout(()=>x(w),400)},j=[{id:"all",label:e("common:all",{defaultValue:"全部"})},{id:"agents",label:e("common:agents",{defaultValue:"智能体"})},{id:"tasks",label:e("common:tasks",{defaultValue:"任务"})},{id:"requirements",label:e("common:requirements",{defaultValue:"需求"})},{id:"projects",label:e("common:projects",{defaultValue:"项目"})},{id:"deliverables",label:e("common:deliverables",{defaultValue:"交付物"})}],C=i.agents.length>0||i.tasks.length>0||i.requirements.length>0||i.projects.length>0||i.deliverables.length>0;return n.jsxs("div",{className:"flex-1 flex flex-col overflow-hidden",children:[n.jsxs("div",{className:"shrink-0 px-4 pt-4 pb-2 space-y-3",children:[n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx("button",{onClick:()=>bt.navigate(De.HOME),className:"p-1.5 rounded-lg hover:bg-surface-overlay transition-colors shrink-0",children:n.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("path",{d:"M19 12H5"}),n.jsx("polyline",{points:"12 19 5 12 12 5"})]})}),n.jsxs("div",{className:"flex-1 relative",children:[n.jsxs("svg",{className:"absolute left-3 top-1/2 -translate-y-1/2 text-fg-tertiary",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("circle",{cx:"11",cy:"11",r:"8"}),n.jsx("line",{x1:"21",y1:"21",x2:"16.65",y2:"16.65"})]}),n.jsx("input",{ref:p,value:t,onChange:w=>v(w.target.value),placeholder:e("common:search"),className:"w-full bg-surface-elevated border border-border-default rounded-xl pl-9 pr-3 py-2.5 text-sm text-fg-primary placeholder:text-fg-tertiary focus:border-brand-500 focus:outline-none transition-colors"}),t&&n.jsx("button",{onClick:()=>{r(""),l({agents:[],tasks:[],requirements:[],projects:[],deliverables:[]}),h(!1),p.current?.focus()},className:"absolute right-3 top-1/2 -translate-y-1/2 text-fg-tertiary hover:text-fg-secondary",children:n.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),n.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]})]}),n.jsx("div",{className:"flex gap-1 overflow-x-auto scrollbar-hide",children:j.map(w=>n.jsx("button",{onClick:()=>a(w.id),className:`px-3 py-1.5 text-xs rounded-lg whitespace-nowrap transition-colors ${s===w.id?"bg-brand-600 text-white":"bg-surface-elevated text-fg-secondary hover:text-fg-primary"}`,children:w.label},w.id))})]}),n.jsxs("div",{className:"flex-1 overflow-y-auto px-4 pb-4",children:[d&&n.jsx("div",{className:"flex items-center justify-center py-12",children:n.jsx("div",{className:"text-fg-tertiary text-sm animate-pulse",children:e("common:loading")})}),!d&&m&&!C&&n.jsxs("div",{className:"flex flex-col items-center justify-center py-12 text-center",children:[n.jsxs("svg",{width:"40",height:"40",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",className:"text-fg-tertiary mb-3",children:[n.jsx("circle",{cx:"11",cy:"11",r:"8"}),n.jsx("line",{x1:"21",y1:"21",x2:"16.65",y2:"16.65"})]}),n.jsx("p",{className:"text-sm text-fg-tertiary",children:e("common:noResults",{defaultValue:"没有找到相关结果"})})]}),!d&&C&&n.jsxs("div",{className:"space-y-4",children:[(s==="all"||s==="agents")&&i.agents.length>0&&n.jsxs("section",{children:[n.jsx("h3",{className:"text-xs font-medium text-fg-tertiary uppercase mb-2",children:e("common:agents",{defaultValue:"智能体"})}),n.jsx("div",{className:"space-y-1",children:(s==="all"?i.agents.slice(0,8):i.agents).map(w=>n.jsxs("button",{onClick:()=>bt.navigate(De.TEAM,{agentId:w.id}),className:"w-full flex items-center gap-3 px-3 py-2.5 rounded-xl hover:bg-surface-overlay transition-colors text-left",children:[n.jsx(Nr,{name:w.name||"Agent",avatarUrl:w.avatarUrl,size:32}),n.jsxs("div",{className:"flex-1 min-w-0",children:[n.jsx("div",{className:"text-sm font-medium text-fg-primary truncate",children:w.name}),n.jsx("div",{className:"text-xs text-fg-tertiary truncate",children:w.role||w.status})]}),n.jsx(dse,{status:w.status})]},w.id))}),s==="all"&&i.agents.length>8&&n.jsxs("button",{onClick:()=>a("agents"),className:"mt-1 w-full text-xs text-brand-500 hover:text-brand-400 py-1.5 rounded-lg hover:bg-surface-overlay transition-colors",children:[e("common:showAll",{defaultValue:"查看全部"})," (",i.agents.length,")"]})]}),(s==="all"||s==="tasks")&&i.tasks.length>0&&n.jsxs("section",{children:[n.jsx("h3",{className:"text-xs font-medium text-fg-tertiary uppercase mb-2",children:e("common:tasks",{defaultValue:"任务"})}),n.jsx("div",{className:"space-y-1",children:(s==="all"?i.tasks.slice(0,8):i.tasks).map(w=>n.jsxs("button",{onClick:()=>bt.navigate(De.WORK,{openTask:w.id}),className:"w-full flex items-center gap-3 px-3 py-2.5 rounded-xl hover:bg-surface-overlay transition-colors text-left",children:[n.jsx(use,{status:w.status}),n.jsxs("div",{className:"flex-1 min-w-0",children:[n.jsx("div",{className:"text-sm text-fg-primary truncate",children:w.title}),n.jsxs("div",{className:"text-xs text-fg-tertiary truncate",children:[w.status," · ",w.priority||""]})]})]},w.id))}),s==="all"&&i.tasks.length>8&&n.jsxs("button",{onClick:()=>a("tasks"),className:"mt-1 w-full text-xs text-brand-500 hover:text-brand-400 py-1.5 rounded-lg hover:bg-surface-overlay transition-colors",children:[e("common:showAll",{defaultValue:"查看全部"})," (",i.tasks.length,")"]})]}),(s==="all"||s==="requirements")&&i.requirements.length>0&&n.jsxs("section",{children:[n.jsx("h3",{className:"text-xs font-medium text-fg-tertiary uppercase mb-2",children:e("common:requirements",{defaultValue:"需求"})}),n.jsx("div",{className:"space-y-1",children:(s==="all"?i.requirements.slice(0,8):i.requirements).map(w=>n.jsxs("button",{onClick:()=>bt.navigate(De.WORK,{openRequirement:w.id}),className:"w-full flex items-center gap-3 px-3 py-2.5 rounded-xl hover:bg-surface-overlay transition-colors text-left",children:[n.jsx("div",{className:`w-8 h-8 rounded-lg flex items-center justify-center shrink-0 ${w.status==="approved"?"text-green-500 bg-green-500/15":w.status==="pending"?"text-amber-500 bg-amber-500/15":w.status==="rejected"?"text-red-500 bg-red-500/15":"text-fg-tertiary bg-surface-elevated"}`,children:n.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[n.jsx("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),n.jsx("polyline",{points:"14 2 14 8 20 8"}),n.jsx("line",{x1:"16",y1:"13",x2:"8",y2:"13"}),n.jsx("line",{x1:"16",y1:"17",x2:"8",y2:"17"})]})}),n.jsxs("div",{className:"flex-1 min-w-0",children:[n.jsx("div",{className:"text-sm text-fg-primary truncate",children:w.title}),n.jsxs("div",{className:"text-xs text-fg-tertiary truncate",children:[w.status," · ",w.priority||""]})]})]},w.id))}),s==="all"&&i.requirements.length>8&&n.jsxs("button",{onClick:()=>a("requirements"),className:"mt-1 w-full text-xs text-brand-500 hover:text-brand-400 py-1.5 rounded-lg hover:bg-surface-overlay transition-colors",children:[e("common:showAll",{defaultValue:"查看全部"})," (",i.requirements.length,")"]})]}),(s==="all"||s==="projects")&&i.projects.length>0&&n.jsxs("section",{children:[n.jsx("h3",{className:"text-xs font-medium text-fg-tertiary uppercase mb-2",children:e("common:projects",{defaultValue:"项目"})}),n.jsx("div",{className:"space-y-1",children:(s==="all"?i.projects.slice(0,8):i.projects).map(w=>n.jsxs("button",{onClick:()=>bt.navigate(De.WORK,{projectId:w.id}),className:"w-full flex items-center gap-3 px-3 py-2.5 rounded-xl hover:bg-surface-overlay transition-colors text-left",children:[n.jsx("div",{className:"w-8 h-8 rounded-lg bg-teal-500/15 flex items-center justify-center shrink-0",children:n.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:"text-teal-500",children:n.jsx("path",{d:"M22 19a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h5l2 3h9a2 2 0 0 1 2 2z"})})}),n.jsxs("div",{className:"flex-1 min-w-0",children:[n.jsx("div",{className:"text-sm text-fg-primary truncate",children:w.name}),w.description&&n.jsx("div",{className:"text-xs text-fg-tertiary truncate",children:w.description})]})]},w.id))}),s==="all"&&i.projects.length>8&&n.jsxs("button",{onClick:()=>a("projects"),className:"mt-1 w-full text-xs text-brand-500 hover:text-brand-400 py-1.5 rounded-lg hover:bg-surface-overlay transition-colors",children:[e("common:showAll",{defaultValue:"查看全部"})," (",i.projects.length,")"]})]}),(s==="all"||s==="deliverables")&&i.deliverables.length>0&&n.jsxs("section",{children:[n.jsx("h3",{className:"text-xs font-medium text-fg-tertiary uppercase mb-2",children:e("common:deliverables",{defaultValue:"交付物"})}),n.jsx("div",{className:"space-y-1",children:(s==="all"?i.deliverables.slice(0,8):i.deliverables).map(w=>n.jsxs("button",{onClick:()=>bt.navigate(De.DELIVERABLES,{openDeliverable:w.id}),className:"w-full flex items-center gap-3 px-3 py-2.5 rounded-xl hover:bg-surface-overlay transition-colors text-left",children:[n.jsx("div",{className:"w-8 h-8 rounded-lg bg-purple-500/15 flex items-center justify-center shrink-0",children:n.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:"text-purple-500",children:[n.jsx("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),n.jsx("polyline",{points:"14 2 14 8 20 8"})]})}),n.jsxs("div",{className:"flex-1 min-w-0",children:[n.jsx("div",{className:"text-sm text-fg-primary truncate",children:w.title}),n.jsxs("div",{className:"text-xs text-fg-tertiary truncate",children:[w.type," · ",w.status]})]})]},w.id))}),s==="all"&&i.deliverables.length>8&&n.jsxs("button",{onClick:()=>a("deliverables"),className:"mt-1 w-full text-xs text-brand-500 hover:text-brand-400 py-1.5 rounded-lg hover:bg-surface-overlay transition-colors",children:[e("common:showAll",{defaultValue:"查看全部"})," (",i.deliverables.length,")"]})]})]}),!d&&!m&&n.jsxs("div",{className:"flex flex-col items-center justify-center py-12 text-center",children:[n.jsxs("svg",{width:"40",height:"40",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",className:"text-fg-tertiary mb-3",children:[n.jsx("circle",{cx:"11",cy:"11",r:"8"}),n.jsx("line",{x1:"21",y1:"21",x2:"16.65",y2:"16.65"})]}),n.jsx("p",{className:"text-sm text-fg-tertiary",children:e("common:search")})]})]})]})}function dse({status:e}){const t=e==="active"||e==="idle"?"bg-green-500":e==="working"||e==="busy"?"bg-blue-500":e==="paused"?"bg-amber-500":"bg-gray-400";return n.jsx("span",{className:`w-2 h-2 rounded-full shrink-0 ${t}`})}function use({status:e}){const t=e==="completed"?"text-green-500 bg-green-500/15":e==="in_progress"?"text-blue-500 bg-blue-500/15":e==="pending"?"text-amber-500 bg-amber-500/15":"text-fg-tertiary bg-surface-elevated";return n.jsx("div",{className:`w-8 h-8 rounded-lg flex items-center justify-center shrink-0 ${t}`,children:n.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[n.jsx("path",{d:"M9 11l3 3L22 4"}),n.jsx("path",{d:"M21 12v7a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h11"})]})})}function mse({d:e,size:t=18}){return n.jsx("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:"shrink-0",children:n.jsx("path",{d:e})})}function fse({currentPage:e,onNavigate:t,authUser:r,collapsed:s,onToggleCollapse:a}){const{t:i}=pt(["nav","common"]);return n.jsxs("aside",{className:"h-dvh bg-surface-secondary flex flex-col shrink-0 overflow-hidden rounded-r-2xl",children:[n.jsx("div",{className:`flex items-center ${s?"px-2 py-3.5 justify-center":"px-4 h-14 justify-between"}`,children:n.jsxs("button",{onClick:a,title:i(s?"sidebar.expandSidebar":"sidebar.collapseSidebar"),className:"flex items-center gap-2.5 min-w-0 group",children:[n.jsx("img",{src:"/logo.png",alt:"Markus",className:"w-8 h-8 rounded-lg shadow-md shadow-black/30 shrink-0 group-hover:ring-2 group-hover:ring-brand-500/40 transition-all"}),!s&&n.jsx("span",{className:"text-[15px] font-bold tracking-tight text-fg-primary whitespace-nowrap",children:"Markus"})]})}),n.jsx("nav",{className:`${s?"p-1":"px-3 py-2"} flex-1 overflow-y-auto scrollbar-thin`,children:B_.map((l,d)=>{const u=i(`sections.${l.key}`);return n.jsx("div",{children:n.jsxs("div",{className:d>0?"mt-3":"",children:[!s&&u&&n.jsx("div",{className:"px-3 py-1.5 mb-1 text-[10px] font-semibold text-fg-muted uppercase tracking-[0.1em]",children:u}),s&&d>0&&n.jsx("div",{className:"my-3"}),H_.filter(m=>m.section===l.key).map(m=>{if(m.id===De.NOTIFICATIONS)return n.jsx(aC,{sidebarMode:!0,collapsed:s,userId:r?.id,label:i(m.id),iconPath:pb[m.id],isActive:e===m.id},m.id);const h=e===m.id;return n.jsxs("button",{onClick:()=>t(m.id),title:s?i(m.id):void 0,className:`w-full flex items-center ${s?"flex-col justify-center px-1 py-1.5 gap-0.5":"gap-3 px-3 py-[7px]"} rounded-xl text-[13px] mb-0.5 transition-all ${h?"bg-brand-600 text-white shadow-sm shadow-brand-900/30 font-medium":"text-fg-secondary hover:bg-surface-overlay hover:text-fg-primary"}`,children:[n.jsx(mse,{d:pb[m.id]??"",size:s?16:18}),s?n.jsx("span",{className:"text-[9px] leading-tight truncate w-full text-center",children:i(m.id)}):n.jsx("span",{className:"truncate",children:i(m.id)})]},m.id)})]})},l.key)})}),!s&&n.jsxs("div",{className:"px-4 pb-2 text-[10px] text-fg-muted",children:["v","0.8.1-rc.0"]})]})}function hse({currentPage:e,onNavigate:t,userId:r}){const{t:s}=pt("nav"),[a,i]=g.useState(0),{counts:l}=XS({enabled:!0}),d=g.useMemo(()=>{let m=0;for(const h of Object.values(l))m+=h;return m},[l]),u=g.useCallback(async()=>{try{const m=await ie.notifications.list(r,!1);i(m.unreadCount??m.notifications.filter(h=>!h.read).length)}catch{}},[r]);return g.useEffect(()=>{u();const m=setInterval(u,15e3),h=()=>u();return window.addEventListener("markus:notifications-changed",h),()=>{clearInterval(m),window.removeEventListener("markus:notifications-changed",h)}},[u]),n.jsx("nav",{className:"fixed bottom-0 left-0 right-0 z-50 bg-surface-secondary flex items-stretch h-14 safe-area-bottom",children:F_.map(m=>{const h=m.group.includes(e),p=m.id===De.NOTIFICATIONS,y=m.id===De.TEAM;return n.jsxs("button",{onClick:()=>t(m.id),className:`flex-1 flex flex-col items-center justify-center gap-0.5 transition-colors ${h?"text-brand-500":"text-fg-tertiary active:text-fg-secondary"}`,children:[n.jsxs("div",{className:"relative",children:[n.jsx("svg",{width:20,height:20,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:h?2:1.75,strokeLinecap:"round",strokeLinejoin:"round",className:"shrink-0",children:n.jsx("path",{d:pb[m.id]})}),p&&a>0&&n.jsx("span",{className:"absolute -top-1.5 -right-2 min-w-[16px] h-4 px-1 flex items-center justify-center bg-red-500 text-white text-[9px] font-bold rounded-full leading-none",children:a>99?"99+":a}),y&&d>0&&n.jsx("span",{className:"absolute -top-1.5 -right-2 min-w-[16px] h-4 px-1 flex items-center justify-center bg-red-500 text-white text-[9px] font-bold rounded-full leading-none",children:d>99?"99+":d})]}),n.jsx("span",{className:`text-[10px] leading-tight ${h?"font-semibold":""}`,children:s(m.id)})]},m.id)})})}const iC=["builder","agents","teams","skills"];function pse(){const e=localStorage.getItem("markus_nav_storeTab");return e&&(localStorage.removeItem("markus_nav_storeTab"),iC.includes(e))?e:"builder"}function gse({authUser:e}){const{t}=pt(["nav","common"]),r=g.useMemo(()=>[{id:"builder",label:t("nav:builder")},{id:"agents",label:t("nav:tabs.agents")},{id:"teams",label:t("nav:tabs.teams")},{id:"skills",label:t("nav:tabs.skills")}],[t]),[s,a]=g.useState(pse),i=Sl(r,s,a);return g.useEffect(()=>{const l=d=>{const u=d.detail;u.params?.storeTab&&iC.includes(u.params.storeTab)&&a(u.params.storeTab)};return window.addEventListener("markus:navigate",l),()=>window.removeEventListener("markus:navigate",l)},[]),n.jsxs("div",{className:"flex-1 overflow-hidden flex flex-col",onTouchStart:i.onTouchStart,onTouchEnd:i.onTouchEnd,children:[n.jsxs("div",{className:"flex items-center shrink-0 overflow-x-auto scrollbar-hide",children:[n.jsx(gc,{className:"ml-2"}),r.map(l=>n.jsx("button",{onClick:()=>a(l.id),className:`flex-1 min-w-0 px-3 py-2.5 text-xs font-medium text-center whitespace-nowrap transition-colors border-b-2 ${s===l.id?"border-brand-500 text-brand-500":"border-transparent text-fg-tertiary"}`,children:l.label},l.id))]}),n.jsxs("div",{className:"flex-1 overflow-hidden flex flex-col",children:[s==="builder"&&n.jsx(e7,{}),s==="agents"&&n.jsx(r7,{authUser:e}),s==="teams"&&n.jsx(i7,{}),s==="skills"&&n.jsx(o7,{})]})]})}const G3="usageType",cb="profile",Y3="llm",X3="search";function xse({onComplete:e,theme:t,onThemeChange:r,skipProfile:s}){const{t:a}=pt(["onboarding","common"]),[i,l]=g.useState(0),[d,u]=g.useState(""),[m,h]=g.useState(""),[p,y]=g.useState(""),[x,v]=g.useState(""),[j,C]=g.useState(!1),[w,N]=g.useState(""),[S,T]=g.useState(!1),[E,R]=g.useState(null);g.useEffect(()=>{ie.auth.me().then(({user:ve})=>{ve.name&&u(ve.name),ve.email&&h(ve.email),ve.avatarUrl&&R(ve.avatarUrl);const tt=ve.name||ve.email?.split("@")[0]||"";tt&&be(a("usageType.defaultOrgName",{name:tt}))}).catch(()=>{}),ie.hubOrgs.invitations().then(ve=>{ve.invitations?.length>0&&pe(ve.invitations)}).catch(()=>{})},[]);const[I,z]=g.useState(null),[B,D]=g.useState(!1),[V,Y]=g.useState({}),[F,L]=g.useState(!1),[O,M]=g.useState(!1),[$,W]=g.useState([]),[U,H]=g.useState(null),[q,Z]=g.useState(!0),[_,J]=g.useState(""),X=g.useRef(!1),[ee,te]=g.useState({}),[G,ue]=g.useState({}),[Se,Ce]=g.useState("anthropic"),[Be,Ne]=g.useState(""),[he,_e]=g.useState(!1),[Ee,Ye]=g.useState([]),[Ze,mt]=g.useState(""),[it,Lt]=g.useState(""),[ht,ne]=g.useState(null),[me,be]=g.useState(""),[se,fe]=g.useState(!1),[He,Ae]=g.useState(!1),[et,pe]=g.useState([]),[Fe,Ve]=g.useState(null),[nt,gt]=g.useState(null),[rt,Et]=g.useState(!0),[je,Re]=g.useState(null),[We,Vt]=g.useState({serperApiKey:"",tavilyApiKey:"",bingApiKey:"",googleSearchApiKey:"",googleSearchCx:"",serpApiKey:"",braveApiKey:"",exaApiKey:"",bochaApiKey:""}),[ln,en]=g.useState(!1),[vn,In]=g.useState(!1),[Zt,cn]=g.useState(null),Gn=g.useRef(!1),Ln=()=>({"Content-Type":"application/json",Authorization:`Bearer ${localStorage.getItem("markus_token")??""}`});g.useEffect(()=>{fetch("/api/settings/llm").then(ve=>ve.ok?ve.json():null).then(ve=>{if(ve?.providers){const tt=Object.entries(ve.providers).filter(([,Tt])=>Tt.configured).map(([Tt,$t])=>({name:Tt,displayName:$t.displayName??Tt,model:$t.model??"",apiKeyPreview:$t.apiKeyPreview}));tt.length>0&&(M(!0),W(tt))}ve?.defaultProvider&&J(ve.defaultProvider),typeof ve?.autoFallback=="boolean"&&Z(ve.autoFallback)}).catch(()=>{})},[]);const Lr=s?3:4;g.useEffect(()=>{i===Lr&&!X.current&&!O&&(X.current=!0,mr())},[i,O,Lr]);const Qr=s?4:5;g.useEffect(()=>{i===Qr&&!Gn.current&&(Gn.current=!0,tn())},[i,Qr]);const mr=async()=>{D(!0);try{const ve=await fetch("/api/settings/env-models",{headers:Ln()});if(ve.ok){const tt=await ve.json();if(z(tt),tt.detected.length>0){const Tt={},$t={};for(const sn of tt.detected)Tt[sn.provider]=!0,$t[sn.provider]=sn.model;Y(Tt),ue($t);for(const sn of tt.detected)ie.modelCatalog.getByProvider(sn.provider).then(Zn=>{te(Xt=>({...Xt,[sn.provider]:Zn.models}))}).catch(()=>{})}}}catch{}finally{D(!1)}},Ge=async()=>{if(Be.trim()){_e(!0),Lt(""),Ye([]);try{const ve=await ie.modelCatalog.validateKey(Se,Be.trim());ve.valid?(Ye(ve.models),ve.models.length>0&&mt(ve.models[0].id)):(Lt(ve.error||"Invalid API key"),ve.models.length>0&&(Ye(ve.models),mt(ve.models[0].id)))}catch(ve){Lt(ve instanceof Error?ve.message:"Validation failed")}finally{_e(!1)}}},Ht=async()=>{if(Ze){L(!0),H(null);try{const ve=await fetch("/api/settings/llm/providers",{method:"POST",headers:Ln(),body:JSON.stringify({name:Se,apiKey:Be.trim(),model:Ze})});if(ve.ok)M(!0),J(Se),W([{name:Se,displayName:Se,model:Ze}]),H({type:"ok",text:`Provider ${Se} configured successfully`});else{const tt=await ve.json();H({type:"err",text:tt.error||"Failed to add provider"})}}catch{H({type:"err",text:"Network error"})}finally{L(!1)}}},Wt=async()=>{if(!I)return;const ve=I.detected.filter(tt=>V[tt.provider]);if(ve.length!==0){L(!0),H(null);try{const tt=await fetch("/api/settings/env-models",{method:"POST",headers:Ln(),body:JSON.stringify({providers:ve.map(Tt=>({provider:Tt.provider,model:G[Tt.provider]||Tt.model,baseUrl:Tt.baseUrl,enabled:!0}))})});if(tt.ok){const Tt=await tt.json();if(Tt.settings?.providers){const sn=Object.entries(Tt.settings.providers).filter(([,Zn])=>Zn.configured).map(([Zn,Xt])=>({name:Zn,displayName:Xt.displayName??Zn,model:Xt.model??"",apiKeyPreview:Xt.apiKeyPreview}));W(sn)}else W(ve.map(sn=>({name:sn.provider,displayName:sn.displayName,model:sn.model,apiKeyPreview:sn.apiKeyPreview})));const $t=Tt.settings?.defaultProvider||Tt.applied[0]||ve[0]?.provider||"";J($t),$t&&fetch("/api/settings/llm",{method:"POST",headers:Ln(),body:JSON.stringify({defaultProvider:$t})}).catch(()=>{}),H({type:"ok",text:Tt.message}),M(!0)}else H({type:"err",text:a("llm.failedToApply")})}catch{H({type:"err",text:a("common:networkError")})}finally{L(!1)}}},tn=async()=>{try{const ve=await fetch("/api/settings/search",{headers:Ln()});if(ve.ok){const tt=await ve.json();Re(tt),tt&&(tt.serper.configured||tt.tavily.configured||tt.bing.configured||tt.google.configured||tt.serpapi.configured||tt.brave.configured||tt.exa.configured||tt.bocha.configured)&&In(!0)}}catch{}},zn=async()=>{if(We.serperApiKey||We.tavilyApiKey||We.bingApiKey||We.googleSearchApiKey||We.googleSearchCx||We.serpApiKey||We.braveApiKey||We.exaApiKey||We.bochaApiKey){en(!0),cn(null);try{const tt={};We.serperApiKey&&(tt.serperApiKey=We.serperApiKey),We.tavilyApiKey&&(tt.tavilyApiKey=We.tavilyApiKey),We.bingApiKey&&(tt.bingApiKey=We.bingApiKey),We.googleSearchApiKey&&(tt.googleSearchApiKey=We.googleSearchApiKey),We.googleSearchCx&&(tt.googleSearchCx=We.googleSearchCx),We.serpApiKey&&(tt.serpApiKey=We.serpApiKey),We.braveApiKey&&(tt.braveApiKey=We.braveApiKey),We.exaApiKey&&(tt.exaApiKey=We.exaApiKey),We.bochaApiKey&&(tt.bochaApiKey=We.bochaApiKey);const Tt=await fetch("/api/settings/search",{method:"POST",headers:Ln(),body:JSON.stringify(tt)});if(Tt.ok){const $t=await Tt.json();Re($t),In(!0),Vt({serperApiKey:"",tavilyApiKey:"",bingApiKey:"",googleSearchApiKey:"",googleSearchCx:"",serpApiKey:"",braveApiKey:"",exaApiKey:"",bochaApiKey:""}),cn({type:"ok",text:a("search.saved")})}else cn({type:"err",text:a("search.failedToSave")})}catch{cn({type:"err",text:a("common:networkError")})}finally{en(!1)}}},Mn=async()=>{if(N(""),!d.trim()){N(a("profile.errors.nameRequired"));return}if(!m.trim()){N(a("profile.errors.emailRequired"));return}if(!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(m.trim())){N(a("profile.errors.emailInvalid"));return}if(p&&p.length<6){N(a("profile.errors.passwordTooShort"));return}if(p&&p!==x){N(a("profile.errors.passwordMismatch"));return}C(!0);try{await ie.auth.updateProfile(d.trim(),m.trim()),p&&await ie.auth.changePassword("",p),T(!0)}catch{N(a("profile.errors.saveFailed"))}finally{C(!1)}},wn=[{value:"system",label:a("theme.system"),icon:"💻",desc:a("theme.systemDesc")},{value:"light",label:a("theme.light"),icon:"☀️",desc:a("theme.lightDesc")},{value:"dark",label:a("theme.dark"),icon:"🌊",desc:a("theme.darkDesc")},{value:"cyberpunk",label:a("theme.cyberpunk"),icon:"🔮",desc:a("theme.cyberpunkDesc")},{value:"mono",label:a("theme.mono"),icon:"⬛",desc:a("theme.monoDesc")}],Dn=[{id:"welcome",title:a("welcome.title"),subtitle:a("welcome.subtitle"),content:n.jsxs("div",{className:"space-y-4 text-fg-secondary text-sm leading-relaxed",children:[n.jsx("p",{className:"text-fg-secondary",children:n.jsx(n0,{i18nKey:"welcome.description",ns:"onboarding",components:{strong:n.jsx("strong",{className:"text-fg-primary"})}})}),n.jsx("div",{className:"grid grid-cols-2 gap-3 mt-6",children:[[a("welcome.features.operation"),a("welcome.features.operationDesc")],[a("welcome.features.collaboration"),a("welcome.features.collaborationDesc")],[a("welcome.features.memory"),a("welcome.features.memoryDesc")],[a("welcome.features.anyLlm"),a("welcome.features.anyLlmDesc")]].map(([ve,tt])=>n.jsxs("div",{className:"bg-surface-elevated/50 rounded-lg p-3",children:[n.jsx("div",{className:"font-medium text-fg-primary text-xs",children:ve}),n.jsx("div",{className:"text-fg-secondary text-xs mt-1",children:tt})]},ve))})]})},{id:G3,title:a("usageType.title",{defaultValue:"How will you use Markus?"}),subtitle:a("usageType.subtitle",{defaultValue:"This helps us tailor your experience."}),content:n.jsxs("div",{className:"space-y-4",children:[n.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[n.jsxs("button",{onClick:()=>{ne("personal"),Ae(!0)},className:`flex flex-col items-center gap-3 rounded-xl border-2 p-5 transition-all text-left ${ht==="personal"?"border-brand-500 bg-brand-500/10":"border-border-default hover:border-fg-tertiary bg-surface-elevated/30"}`,children:[n.jsx("span",{className:"text-2xl",children:"👤"}),n.jsxs("div",{children:[n.jsx("div",{className:"font-medium text-fg-primary text-sm text-center",children:a("usageType.personal",{defaultValue:"Personal"})}),n.jsx("div",{className:"text-[11px] text-fg-tertiary mt-1 text-center",children:a("usageType.personalDesc",{defaultValue:"Individual use with your own AI agents."})})]})]}),n.jsxs("button",{onClick:()=>{ne("organization"),Ae(!1)},className:`flex flex-col items-center gap-3 rounded-xl border-2 p-5 transition-all text-left ${ht==="organization"?"border-brand-500 bg-brand-500/10":"border-border-default hover:border-fg-tertiary bg-surface-elevated/30"}`,children:[n.jsx("span",{className:"text-2xl",children:"🏢"}),n.jsxs("div",{children:[n.jsx("div",{className:"font-medium text-fg-primary text-sm text-center",children:a("usageType.organization",{defaultValue:"Team & Enterprise"})}),n.jsx("div",{className:"text-[11px] text-fg-tertiary mt-1 text-center",children:a("usageType.organizationDesc",{defaultValue:"For teams sharing licenses and collaborating."})})]})]})]}),ht==="organization"&&n.jsxs("div",{className:"space-y-4 mt-4",children:[et.length>0&&n.jsxs("div",{className:"space-y-2",children:[n.jsx("div",{className:"text-xs text-fg-tertiary font-medium",children:a("usageType.pendingInvitations")}),et.map(ve=>n.jsxs("div",{className:"flex items-center justify-between px-4 py-3 rounded-xl border border-amber-500/20 bg-amber-500/5",children:[n.jsxs("div",{children:[n.jsx("div",{className:"text-sm font-medium text-fg-primary",children:ve.orgName}),n.jsx("div",{className:"text-[11px] text-fg-tertiary",children:a("usageType.invitedBy",{name:ve.invitedBy})})]}),n.jsx("button",{onClick:async()=>{Ve(ve.orgId);try{await ie.hubOrgs.acceptInvitation(ve.orgId),gt(ve.orgId),Ae(!0)}catch{}finally{Ve(null)}},disabled:Fe===ve.orgId||nt===ve.orgId,className:"px-3 py-1.5 text-xs rounded-lg bg-brand-600 hover:bg-brand-500 disabled:opacity-40 text-white transition-colors",children:nt===ve.orgId?a("usageType.accepted"):Fe===ve.orgId?a("usageType.accepting"):a("usageType.acceptAndJoin")})]},ve.orgId)),n.jsx("div",{className:"text-[11px] text-fg-tertiary text-center pt-1",children:a("usageType.orCreateNew")})]}),n.jsxs("div",{className:"space-y-1",children:[n.jsx("label",{className:"text-xs text-fg-tertiary font-medium",children:a("usageType.orgNameLabel")}),n.jsx("input",{type:"text",value:me,onChange:ve=>{be(ve.target.value),Ae(!1)},placeholder:a("usageType.orgNamePlaceholder"),className:"w-full px-4 py-2.5 bg-surface-elevated border border-border-default rounded-xl text-sm text-fg-primary focus:border-brand-500 outline-none transition-colors"})]}),n.jsx("button",{onClick:async()=>{if(me.trim()){fe(!0);try{const tt=(await ie.license.get()).defaultOrg;tt?.id&&await ie.hubOrgs.update(tt.id,{name:me.trim()}),Ae(!0)}catch{}finally{fe(!1)}}},disabled:se||!me.trim()||He,className:"w-full px-4 py-2.5 bg-brand-600 hover:bg-brand-500 disabled:opacity-40 text-white text-sm rounded-xl transition-colors",children:a(se?"common:saving":He?"usageType.orgNameSaved":"usageType.setOrgName")})]})]})},{id:cb,title:a("profile.title"),subtitle:a("profile.subtitle"),content:S?n.jsxs("div",{className:"flex items-center gap-3 bg-green-500/10 border border-green-500/30 rounded-xl p-4",children:[n.jsx("span",{className:"text-green-600 text-lg",children:"✓"}),n.jsxs("div",{children:[n.jsx("div",{className:"text-sm font-medium text-green-600",children:a("profile.saved")}),n.jsxs("div",{className:"text-xs text-fg-secondary mt-0.5",children:[d," · ",m]})]})]}):n.jsxs("div",{className:"space-y-4",children:[n.jsx("div",{className:"flex justify-center",children:n.jsx(y6,{currentUrl:E,name:d,size:64,targetType:"user"})}),n.jsxs("div",{className:"space-y-1",children:[n.jsxs("label",{className:"text-xs text-fg-tertiary font-medium",children:[a("profile.nameLabel")," ",n.jsx("span",{className:"text-red-500",children:"*"})]}),n.jsx("input",{type:"text",value:d,onChange:ve=>u(ve.target.value),placeholder:a("profile.namePlaceholder"),className:"w-full px-4 py-2.5 bg-surface-elevated border border-border-default rounded-xl text-sm text-fg-primary focus:border-brand-500 outline-none transition-colors",autoFocus:!0})]}),n.jsxs("div",{className:"space-y-1",children:[n.jsxs("label",{className:"text-xs text-fg-tertiary font-medium",children:[a("profile.emailLabel")," ",n.jsx("span",{className:"text-red-500",children:"*"})]}),n.jsx("input",{type:"email",value:m,onChange:ve=>h(ve.target.value),placeholder:a("profile.emailPlaceholder"),className:"w-full px-4 py-2.5 bg-surface-elevated border border-border-default rounded-xl text-sm text-fg-primary focus:border-brand-500 outline-none transition-colors"})]}),n.jsxs("div",{className:"space-y-1",children:[n.jsx("label",{className:"text-xs text-fg-tertiary font-medium",children:a("profile.newPasswordLabel")}),n.jsx("input",{type:"password",value:p,onChange:ve=>y(ve.target.value),placeholder:a("profile.newPasswordPlaceholder"),className:"w-full px-4 py-2.5 bg-surface-elevated border border-border-default rounded-xl text-sm text-fg-primary focus:border-brand-500 outline-none transition-colors"})]}),p&&n.jsxs("div",{className:"space-y-1",children:[n.jsx("label",{className:"text-xs text-fg-tertiary font-medium",children:a("profile.confirmPasswordLabel")}),n.jsx("input",{type:"password",value:x,onChange:ve=>v(ve.target.value),placeholder:a("profile.confirmPasswordPlaceholder"),className:"w-full px-4 py-2.5 bg-surface-elevated border border-border-default rounded-xl text-sm text-fg-primary focus:border-brand-500 outline-none transition-colors"})]}),w&&n.jsx("div",{className:"px-3 py-2 bg-red-500/10 border border-red-500/30 rounded-lg text-xs text-red-500",children:w}),n.jsx("button",{onClick:()=>{Mn()},disabled:j||!d.trim()||!m.trim(),className:"w-full px-4 py-2.5 bg-brand-600 hover:bg-brand-500 disabled:opacity-40 text-white text-sm rounded-xl transition-colors",children:a(j?"common:saving":"profile.saveProfile")})]})},{id:"theme",title:a("theme.title"),subtitle:a("theme.subtitle"),content:n.jsx("div",{className:"grid grid-cols-3 gap-3",children:wn.map(ve=>n.jsxs("button",{onClick:()=>r(ve.value),className:`flex flex-col items-center gap-2 rounded-xl border-2 p-5 transition-all ${t===ve.value?"border-brand-500 bg-brand-500/10":"border-border-default hover:border-fg-tertiary bg-surface-elevated/30"}`,children:[n.jsx("span",{className:"text-2xl",children:ve.icon}),n.jsx("span",{className:"text-sm font-medium text-fg-primary",children:ve.label}),n.jsx("span",{className:"text-[11px] text-fg-tertiary leading-tight text-center",children:ve.desc})]},ve.value))})},{id:Y3,title:a("llm.title"),subtitle:a("llm.subtitle"),content:O?n.jsxs("div",{className:"space-y-2",children:[n.jsxs("div",{className:"flex items-center gap-2 text-green-600 text-sm font-medium mb-1",children:[n.jsx("span",{children:"✓"}),n.jsx("span",{children:a("llm.configured")})]}),$.length>1&&n.jsx("div",{className:"text-xs text-fg-secondary mb-1",children:a("llm.selectDefault")}),$.map(ve=>{const tt=_===ve.name;return n.jsxs("button",{onClick:async()=>{const Tt=_;J(ve.name);try{await fetch("/api/settings/llm",{method:"POST",headers:Ln(),body:JSON.stringify({defaultProvider:ve.name})})}catch{J(Tt)}},className:`w-full flex items-center justify-between rounded-lg px-4 py-2.5 text-left transition-colors ${tt?"bg-brand-500/15 border-2 border-brand-500":"bg-green-500/10 border border-green-500/30 hover:border-brand-500/50"}`,children:[n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx("span",{className:`w-3.5 h-3.5 rounded-full border-2 flex items-center justify-center shrink-0 ${tt?"border-brand-500":"border-fg-tertiary"}`,children:tt&&n.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-brand-500"})}),n.jsx("span",{className:"text-sm text-fg-primary font-medium",children:ve.displayName}),ve.model&&n.jsx("span",{className:"text-xs text-fg-tertiary",children:ve.model}),tt&&n.jsx("span",{className:"text-[10px] text-brand-500 font-medium",children:a("llm.default")})]}),ve.apiKeyPreview&&n.jsx("code",{className:"text-[10px] text-fg-tertiary",children:ve.apiKeyPreview})]},ve.name)}),n.jsx("div",{className:"text-xs text-fg-secondary mt-1",children:a("llm.configuredHint")}),n.jsxs("div",{className:"flex items-center justify-between bg-surface-elevated/40 rounded-lg px-4 py-3 mt-3",children:[n.jsxs("div",{children:[n.jsx("div",{className:"text-xs font-medium text-fg-primary",children:a("llm.autoFallback")}),n.jsx("div",{className:"text-[11px] text-fg-tertiary mt-0.5",children:a("llm.autoFallbackDesc")})]}),n.jsx("button",{onClick:async()=>{const ve=!q;Z(ve);try{await fetch("/api/settings/llm",{method:"POST",headers:Ln(),body:JSON.stringify({autoFallback:ve})})}catch{Z(!ve)}},className:`relative inline-flex h-5 w-9 items-center rounded-full transition-colors shrink-0 ${q?"bg-green-500":"bg-gray-600"}`,children:n.jsx("span",{className:`inline-block h-3.5 w-3.5 rounded-full bg-white transition-transform ${q?"translate-x-4":"translate-x-1"}`})})]})]}):n.jsxs("div",{className:"space-y-4",children:[B&&n.jsxs("div",{className:"flex items-center gap-2 text-xs text-fg-tertiary animate-pulse",children:[n.jsx("div",{className:"w-3 h-3 border-2 border-brand-500 border-t-transparent rounded-full animate-spin"}),a("llm.detectingKeys")]}),I&&I.detected.length>0&&n.jsxs("div",{className:"space-y-3",children:[n.jsxs("div",{className:"flex items-center gap-2 text-green-600 text-xs font-medium",children:[n.jsx("span",{children:"✓"}),n.jsx("span",{children:a("llm.fromEnv")})]}),I.detected.map(ve=>n.jsxs("div",{className:"border border-border-default rounded-lg overflow-hidden",children:[n.jsxs("label",{className:"flex items-center gap-3 px-3 py-2.5 bg-surface-elevated/40 cursor-pointer hover:bg-surface-elevated/60 transition-colors",children:[n.jsx("input",{type:"checkbox",checked:V[ve.provider]??!1,onChange:tt=>Y({...V,[ve.provider]:tt.target.checked}),className:"w-4 h-4 rounded bg-surface-overlay border-gray-600 text-brand-500 focus:ring-brand-500"}),n.jsx("div",{className:"flex-1 min-w-0",children:n.jsx("span",{className:"text-sm text-fg-primary font-medium",children:ve.displayName})}),n.jsx("code",{className:"text-[10px] text-fg-tertiary",children:ve.apiKeyPreview})]}),V[ve.provider]&&n.jsx("div",{className:"px-3 py-2 border-t border-border-default",children:n.jsx(dh,{provider:ve.provider,models:ee[ve.provider]??[],selectedModel:G[ve.provider]||ve.model,onSelect:tt=>ue(Tt=>({...Tt,[ve.provider]:tt})),loading:!ee[ve.provider],compact:!0,maxVisible:4})})]},ve.provider)),I.detected.filter(ve=>V[ve.provider]).length>1&&n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx("span",{className:"text-xs text-fg-secondary",children:"Default:"}),n.jsx("select",{value:_||I.detected[0]?.provider||"",onChange:ve=>J(ve.target.value),className:"px-2 py-1 bg-surface-overlay border border-border-default rounded text-xs text-fg-primary",children:I.detected.filter(ve=>V[ve.provider]).map(ve=>n.jsx("option",{value:ve.provider,children:ve.displayName},ve.provider))})]}),n.jsx("button",{onClick:()=>{Wt()},disabled:F||Object.values(V).filter(Boolean).length===0,className:"w-full px-4 py-2 bg-brand-600 hover:bg-brand-500 disabled:opacity-40 text-white text-sm rounded-lg transition-colors",children:F?a("common:applying"):a("llm.applyProviders",{count:Object.values(V).filter(Boolean).length})})]}),I&&I.detected.length===0&&!B&&n.jsxs("div",{className:"space-y-3",children:[n.jsx("div",{className:"text-xs text-fg-tertiary",children:n.jsx(n0,{i18nKey:"llm.noKeysFound",ns:"onboarding",components:{code:n.jsx("code",{className:"text-fg-secondary"})}})}),n.jsxs("div",{className:"space-y-2",children:[n.jsx("label",{className:"text-xs text-fg-secondary",children:"Provider"}),n.jsx("select",{value:Se,onChange:ve=>{Ce(ve.target.value),Ye([]),Lt(""),mt("")},className:"w-full px-3 py-2 bg-surface-overlay border border-border-default rounded-lg text-sm text-fg-primary",children:Bu.map(ve=>n.jsx("option",{value:ve.id,children:ve.label},ve.id))})]}),n.jsxs("div",{className:"space-y-2",children:[n.jsx("label",{className:"text-xs text-fg-secondary",children:"API Key"}),n.jsxs("div",{className:"flex gap-2",children:[n.jsx("input",{type:"password",value:Be,onChange:ve=>Ne(ve.target.value),onBlur:()=>{Be.trim().length>=8&&Ge()},onKeyDown:ve=>{ve.key==="Enter"&&Be.trim().length>=8&&Ge()},placeholder:"sk-...",className:"flex-1 px-3 py-2 bg-surface-overlay border border-border-default rounded-lg text-sm text-fg-primary placeholder:text-fg-tertiary"}),n.jsx("button",{onClick:()=>{Ge()},disabled:he||!Be.trim(),className:"px-3 py-2 bg-brand-600 hover:bg-brand-500 disabled:opacity-40 text-white text-xs rounded-lg transition-colors whitespace-nowrap",children:he?"Validating...":"Validate"})]})]}),it&&n.jsx("div",{className:"text-xs px-3 py-2 rounded-lg bg-red-500/10 text-red-500 border border-red-500/30",children:it}),Ee.length>0&&n.jsxs("div",{className:"border border-border-default rounded-lg p-3",children:[n.jsx("div",{className:"text-xs text-fg-secondary mb-2",children:"Select Model"}),n.jsx(dh,{provider:Se,models:Ee,selectedModel:Ze,onSelect:mt,compact:!0,maxVisible:5}),n.jsx("button",{onClick:()=>{Ht()},disabled:F||!Ze,className:"w-full mt-3 px-4 py-2 bg-brand-600 hover:bg-brand-500 disabled:opacity-40 text-white text-sm rounded-lg transition-colors",children:F?a("common:applying"):"Activate Provider"})]})]}),U&&n.jsx("div",{className:`text-xs px-3 py-2 rounded-lg ${U.type==="ok"?"bg-green-500/10 text-green-600 border border-green-500/30":"bg-red-500/10 text-red-500 border border-red-500/30"}`,children:U.text})]})},{id:X3,title:a("search.title"),subtitle:a("search.subtitle"),content:vn?n.jsxs("div",{className:"space-y-2",children:[n.jsxs("div",{className:"flex items-center gap-2 text-green-600 text-sm font-medium mb-1",children:[n.jsx("span",{children:"✓"}),n.jsx("span",{children:a("search.saved")})]}),je&&[{id:"serper",label:a("search.serper")},{id:"tavily",label:a("search.tavily")},{id:"bing",label:a("search.bing")},{id:"google",label:a("search.google")},{id:"serpapi",label:a("search.serpapi")},{id:"brave",label:a("search.brave")},{id:"exa",label:a("search.exa")},{id:"bocha",label:a("search.bocha")}].filter(ve=>je[ve.id]?.configured).map(ve=>n.jsxs("div",{className:"flex items-center justify-between bg-green-500/10 border border-green-500/30 rounded-lg px-4 py-2.5",children:[n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx("span",{className:"w-2 h-2 rounded-full bg-green-400"}),n.jsx("span",{className:"text-sm text-fg-primary font-medium",children:ve.label})]}),n.jsx("code",{className:"text-[10px] text-fg-tertiary",children:je[ve.id].preview})]},ve.id)),n.jsx("div",{className:"text-xs text-fg-secondary mt-1",children:a("search.savedHint")})]}):n.jsxs("div",{className:"space-y-4",children:[n.jsx("div",{className:"text-xs text-fg-secondary",children:a("search.description")}),je&&(je.serper.configured||je.tavily.configured||je.bing.configured||je.google.configured||je.serpapi.configured||je.brave.configured||je.exa.configured||je.bocha.configured)&&n.jsxs("div",{className:"space-y-2",children:[n.jsx("div",{className:"text-xs text-fg-secondary uppercase tracking-wider",children:a("search.detected")}),[{id:"serper",label:a("search.serper")},{id:"tavily",label:a("search.tavily")},{id:"bing",label:a("search.bing")},{id:"google",label:a("search.google")},{id:"serpapi",label:a("search.serpapi")},{id:"brave",label:a("search.brave")},{id:"exa",label:a("search.exa")},{id:"bocha",label:a("search.bocha")}].filter(ve=>je[ve.id]?.configured).map(ve=>n.jsxs("div",{className:"flex items-center justify-between bg-green-500/10 border border-green-500/30 rounded-lg px-3 py-2",children:[n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx("span",{className:"w-2 h-2 rounded-full bg-green-400"}),n.jsx("span",{className:"text-sm text-fg-primary",children:ve.label})]}),n.jsx("code",{className:"text-[10px] text-fg-tertiary",children:je[ve.id].preview})]},ve.id))]}),n.jsx("div",{className:"space-y-3",children:[{label:a("search.serper"),field:"serperApiKey"},{label:a("search.tavily"),field:"tavilyApiKey"},{label:a("search.bing"),field:"bingApiKey"},{label:a("search.google"),field:"googleSearchApiKey"},{label:a("search.serpapi"),field:"serpApiKey"},{label:a("search.brave"),field:"braveApiKey"},{label:a("search.exa"),field:"exaApiKey"},{label:a("search.bocha"),field:"bochaApiKey"}].map(ve=>n.jsxs("div",{className:"space-y-1",children:[n.jsx("label",{className:"text-xs text-fg-tertiary font-medium",children:ve.label}),n.jsx("input",{type:"password",value:We[ve.field],onChange:tt=>Vt({...We,[ve.field]:tt.target.value}),placeholder:a("search.apiKeyPlaceholder"),className:"w-full px-4 py-2 bg-surface-elevated border border-border-default rounded-xl text-sm text-fg-primary focus:border-brand-500 outline-none transition-colors"})]},ve.field))}),n.jsx("button",{onClick:()=>{zn()},disabled:ln||!We.serperApiKey&&!We.tavilyApiKey&&!We.bingApiKey&&!We.googleSearchApiKey&&!We.serpApiKey&&!We.braveApiKey&&!We.exaApiKey&&!We.bochaApiKey,className:"w-full px-4 py-2.5 bg-brand-600 hover:bg-brand-500 disabled:opacity-40 text-white text-sm rounded-xl transition-colors",children:a(ln?"search.saving":"search.save")}),Zt&&n.jsx("div",{className:`text-xs px-3 py-2 rounded-lg ${Zt.type==="ok"?"bg-green-500/10 text-green-600 border border-green-500/30":"bg-red-500/10 text-red-500 border border-red-500/30"}`,children:Zt.text})]})},{id:"done",title:a("done.title"),subtitle:a("done.subtitle"),content:n.jsxs("div",{className:"space-y-3 text-fg-secondary text-sm",children:[[[a("done.chat"),a("done.chatDesc")],[a("done.projects"),a("done.projectsDesc")],[a("done.builder"),a("done.builderDesc")],[a("done.settings"),a("done.settingsDesc")]].map(([ve,tt])=>n.jsxs("div",{className:"flex gap-3 bg-surface-elevated/50 rounded-lg p-3",children:[n.jsx("div",{className:"text-brand-500 mt-0.5 shrink-0",children:"→"}),n.jsxs("div",{children:[n.jsx("div",{className:"font-medium text-fg-primary text-xs",children:ve}),n.jsx("div",{className:"text-fg-secondary text-xs",children:tt})]})]},ve)),n.jsxs("label",{className:"flex items-start gap-2.5 p-3 bg-surface-elevated/30 rounded-lg cursor-pointer group mt-2",children:[n.jsx("input",{type:"checkbox",checked:rt,onChange:ve=>Et(ve.target.checked),className:"mt-0.5 accent-brand-500 shrink-0"}),n.jsxs("div",{className:"text-[11px] text-fg-tertiary leading-relaxed",children:[a("done.telemetry"),n.jsx("br",{}),n.jsx("span",{className:"text-fg-quaternary",children:a("done.telemetryNote")})]})]})]})}],$n=s?Dn.filter(ve=>ve.id!==cb):Dn,Sn=$n.findIndex(ve=>ve.id===G3),Bn=$n.findIndex(ve=>ve.id===cb),Vn=$n.findIndex(ve=>ve.id===Y3),Qn=$n.findIndex(ve=>ve.id===X3),Pe=()=>{i===Sn&&Sn>=0&&!ht||i===Sn&&ht==="organization"&&!He||i===Bn&&Bn>=0&&!S||(i<$n.length-1?l(i+1):(fetch("/api/settings/telemetry",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({enabled:rt})}).catch(()=>{}),e()))},Ct=$n[i];return n.jsx("div",{className:"min-h-dvh bg-surface-primary flex items-center justify-center p-4",children:n.jsx("div",{className:"w-full max-w-lg",children:n.jsxs("div",{className:"bg-surface-elevated rounded-2xl p-8",children:[n.jsx("div",{className:"flex gap-1.5 mb-8",children:$n.map((ve,tt)=>n.jsx("div",{className:`h-1 flex-1 rounded-full transition-colors ${tt<=i?"bg-brand-500":"bg-surface-elevated"}`},tt))}),n.jsx("h2",{className:"text-2xl font-bold text-fg-primary",children:Ct.title}),n.jsx("p",{className:"text-sm text-fg-secondary mt-1 mb-6",children:Ct.subtitle}),Ct.content,n.jsxs("div",{className:"flex justify-between mt-8",children:[i>0?n.jsx("button",{onClick:()=>l(i-1),className:"px-4 py-2 text-sm text-fg-secondary hover:text-fg-primary transition-colors",children:a("common:back")}):n.jsx("button",{onClick:e,className:"px-4 py-2 text-sm text-fg-tertiary hover:text-fg-secondary transition-colors",children:a("common:skip")}),n.jsxs("div",{className:"flex items-center gap-3",children:[Sn>=0&&i===Sn&&!ht&&n.jsx("button",{onClick:()=>{ne("personal"),Ae(!0),l(i+1)},className:"px-4 py-2 text-sm text-fg-tertiary hover:text-fg-secondary transition-colors",children:a("llm.skipForNow")}),Bn>=0&&i===Bn&&!S&&n.jsx("button",{onClick:()=>l(i+1),className:"px-4 py-2 text-sm text-fg-tertiary hover:text-fg-secondary transition-colors",children:a("llm.skipForNow")}),Vn>=0&&i===Vn&&!O&&n.jsx("button",{onClick:Pe,className:"px-4 py-2 text-sm text-fg-tertiary hover:text-fg-secondary transition-colors",children:a("llm.skipForNow")}),Qn>=0&&i===Qn&&!vn&&n.jsx("button",{onClick:Pe,className:"px-4 py-2 text-sm text-fg-tertiary hover:text-fg-secondary transition-colors",children:a("search.skipForNow")}),n.jsx("button",{onClick:Pe,disabled:Bn>=0&&i===Bn&&!S||Sn>=0&&i===Sn&&(!ht||ht==="organization"&&!He),className:`px-6 py-2.5 text-white text-sm rounded-xl transition-colors ${Bn>=0&&i===Bn&&!S||Sn>=0&&i===Sn&&(!ht||ht==="organization"&&!He)?"bg-brand-600/40 cursor-not-allowed":"bg-brand-600 hover:bg-brand-500"}`,children:i===$n.length-1?a("getStarted"):a("common:next")})]})]})]})})})}function bse({onLogin:e,hasOwner:t,hasMultipleUsers:r}){const{t:s}=pt("auth"),[a,i]=g.useState(null),[l,d]=g.useState(""),[u,m]=g.useState(!1),[h,p]=g.useState(""),[y,x]=g.useState(""),v=async(w,N=!1)=>{d(""),i(w??"hub");try{await da(w);const S=gi(),T=Ch();if(!S||!T){d(s("login.hubUnavailable"));return}const{user:E,needsOnboarding:R}=await ie.auth.hubLogin(S,T);e(E,R??!1,{fromHub:!0})}catch(S){const T=S instanceof Error?S.message:"";if(!T.includes("cancelled")){if(!N&&gi())return r0(),v(w,!0);d(T||s("login.hubUnavailable"))}}finally{i(null)}},j=async w=>{if(w.preventDefault(),!(!h.trim()||!y)){d(""),i("local");try{const{user:N,needsOnboarding:S}=await ie.auth.login(h.trim(),y);e(N,S??!1)}catch{d(s("login.invalidCredentials"))}finally{i(null)}}},C=s(t?"login.welcomeBack":"login.getStarted");return n.jsxs("div",{className:"min-h-dvh bg-surface-primary flex flex-col items-center justify-center p-4 relative overflow-hidden",children:[n.jsx("div",{className:"absolute inset-0 bg-[radial-gradient(ellipse_at_top,_var(--tw-gradient-stops))] from-brand-950/50 via-transparent to-transparent"}),n.jsxs("div",{className:"w-full max-w-sm relative z-10 flex-1 flex flex-col justify-center",children:[n.jsxs("div",{className:"text-center mb-8",children:[n.jsx("img",{src:"/logo.png",alt:"Markus",className:"w-14 h-14 mx-auto mb-3 rounded-xl shadow-lg shadow-black/40"}),n.jsx("div",{className:"text-2xl font-extrabold tracking-tight text-fg-primary mb-1",children:"Markus"}),n.jsx("div",{className:"text-sm text-fg-tertiary",children:C})]}),n.jsx("div",{className:"bg-surface-secondary/80 backdrop-blur-sm border border-border-default rounded-2xl p-8 space-y-4 shadow-2xl shadow-black/30",children:u?n.jsxs(n.Fragment,{children:[n.jsxs("form",{onSubmit:j,className:"space-y-3",children:[n.jsx("div",{className:"space-y-1",children:n.jsx("input",{type:"email",value:h,onChange:w=>p(w.target.value),autoComplete:"email",autoFocus:!0,placeholder:s("login.email"),className:"w-full px-4 py-2.5 bg-surface-elevated border border-border-default rounded-xl text-sm text-fg-primary focus:border-brand-500 outline-none transition-colors placeholder:text-fg-tertiary",required:!0})}),n.jsx("div",{className:"space-y-1",children:n.jsx("input",{type:"password",value:y,onChange:w=>x(w.target.value),autoComplete:"current-password",placeholder:s("login.password"),className:"w-full px-4 py-2.5 bg-surface-elevated border border-border-default rounded-xl text-sm text-fg-primary focus:border-brand-500 outline-none transition-colors placeholder:text-fg-tertiary",required:!0})}),l&&n.jsx("div",{className:"px-3 py-2 bg-red-500/10 border border-red-500/30 rounded-lg text-xs text-red-500",children:l}),t&&!r&&n.jsx("p",{className:"text-[11px] text-fg-tertiary",children:s("login.defaultCredentials")}),n.jsx("button",{type:"submit",disabled:a==="local"||!h||!y,className:"w-full py-2.5 bg-brand-600 hover:bg-brand-500 disabled:opacity-50 text-white text-sm font-medium rounded-xl transition-all",children:s(a==="local"?"login.signingIn":"login.signIn")})]}),n.jsx("div",{className:"pt-1 text-center",children:n.jsx("button",{onClick:()=>{m(!1),d("")},className:"text-xs text-fg-tertiary hover:text-fg-secondary transition-colors",children:s("login.backToHub")})})]}):n.jsxs(n.Fragment,{children:[n.jsxs("button",{onClick:()=>v("google"),disabled:!!a,className:"w-full flex items-center justify-center gap-3 py-2.5 px-4 bg-surface-elevated hover:bg-surface-elevated/80 border border-border-default rounded-xl text-sm text-fg-primary font-medium transition-all disabled:opacity-50",children:[n.jsxs("svg",{className:"w-5 h-5",viewBox:"0 0 24 24",children:[n.jsx("path",{fill:"#4285F4",d:"M22.56 12.25c0-.78-.07-1.53-.2-2.25H12v4.26h5.92a5.06 5.06 0 01-2.2 3.32v2.77h3.57c2.08-1.92 3.28-4.74 3.28-8.1z"}),n.jsx("path",{fill:"#34A853",d:"M12 23c2.97 0 5.46-.98 7.28-2.66l-3.57-2.77c-.98.66-2.23 1.06-3.71 1.06-2.86 0-5.29-1.93-6.16-4.53H2.18v2.84C3.99 20.53 7.7 23 12 23z"}),n.jsx("path",{fill:"#FBBC05",d:"M5.84 14.09c-.22-.66-.35-1.36-.35-2.09s.13-1.43.35-2.09V7.07H2.18C1.43 8.55 1 10.22 1 12s.43 3.45 1.18 4.93l2.85-2.22.81-.62z"}),n.jsx("path",{fill:"#EA4335",d:"M12 5.38c1.62 0 3.06.56 4.21 1.64l3.15-3.15C17.45 2.09 14.97 1 12 1 7.7 1 3.99 3.47 2.18 7.07l3.66 2.84c.87-2.6 3.3-4.53 6.16-4.53z"})]}),s(a==="google"?"login.connectingHub":"login.withGoogle")]}),n.jsxs("button",{onClick:()=>v("github"),disabled:!!a,className:"w-full flex items-center justify-center gap-3 py-2.5 px-4 bg-surface-elevated hover:bg-surface-elevated/80 border border-border-default rounded-xl text-sm text-fg-primary font-medium transition-all disabled:opacity-50",children:[n.jsx("svg",{className:"w-5 h-5",viewBox:"0 0 24 24",fill:"currentColor",children:n.jsx("path",{d:"M12 0C5.37 0 0 5.37 0 12c0 5.31 3.435 9.795 8.205 11.385.6.105.825-.255.825-.57 0-.285-.015-1.23-.015-2.235-3.015.555-3.795-.735-4.035-1.41-.135-.345-.72-1.41-1.23-1.695-.42-.225-1.02-.78-.015-.795.945-.015 1.62.87 1.845 1.23 1.08 1.815 2.805 1.305 3.495.99.105-.78.42-1.305.765-1.605-2.67-.3-5.46-1.335-5.46-5.925 0-1.305.465-2.385 1.23-3.225-.12-.3-.54-1.53.12-3.18 0 0 1.005-.315 3.3 1.23.96-.27 1.98-.405 3-.405s2.04.135 3 .405c2.295-1.56 3.3-1.23 3.3-1.23.66 1.65.24 2.88.12 3.18.765.84 1.23 1.905 1.23 3.225 0 4.605-2.805 5.625-5.475 5.925.435.375.81 1.095.81 2.22 0 1.605-.015 2.895-.015 3.3 0 .315.225.69.825.57A12.02 12.02 0 0024 12c0-6.63-5.37-12-12-12z"})}),s(a==="github"?"login.connectingHub":"login.withGithub")]}),n.jsxs("button",{onClick:()=>v("email"),disabled:!!a,className:"w-full flex items-center justify-center gap-3 py-2.5 px-4 bg-surface-elevated hover:bg-surface-elevated/80 border border-border-default rounded-xl text-sm text-fg-primary font-medium transition-all disabled:opacity-50",children:[n.jsx("svg",{className:"w-5 h-5",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:1.5,children:n.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M21.75 6.75v10.5a2.25 2.25 0 01-2.25 2.25h-15a2.25 2.25 0 01-2.25-2.25V6.75m19.5 0A2.25 2.25 0 0019.5 4.5h-15a2.25 2.25 0 00-2.25 2.25m19.5 0v.243a2.25 2.25 0 01-1.07 1.916l-7.5 4.615a2.25 2.25 0 01-2.36 0L3.32 8.91a2.25 2.25 0 01-1.07-1.916V6.75"})}),s(a==="email"?"login.connectingHub":"login.withEmail")]}),n.jsx("p",{className:"text-center text-[11px] text-fg-tertiary pt-1",children:s("login.terms")}),l&&n.jsx("div",{className:"px-3 py-2 bg-red-500/10 border border-red-500/30 rounded-lg text-xs text-red-500",children:l}),n.jsx("div",{className:"pt-1 text-center",children:n.jsx("button",{onClick:()=>m(!0),className:"text-xs text-fg-tertiary hover:text-fg-secondary transition-colors",children:s("login.useLocalAccount")})})]})})]}),n.jsxs("div",{className:"relative z-10 flex flex-wrap items-center justify-center gap-x-5 gap-y-1 py-6 text-[11px] text-fg-tertiary",children:[n.jsx("a",{href:"https://markus.global",target:"_blank",rel:"noopener noreferrer",className:"hover:text-fg-secondary transition-colors",children:"markus.global"}),n.jsx("a",{href:"mailto:business@markus.global",className:"hover:text-fg-secondary transition-colors",children:s("login.contactSales")})]})]})}function yse({token:e,onComplete:t}){const{t:r}=pt("auth"),[s,a]=g.useState(null),[i,l]=g.useState(""),[d,u]=g.useState(""),[m,h]=g.useState(""),[p,y]=g.useState(!1),[x,v]=g.useState(!1),[j,C]=g.useState(!1);g.useEffect(()=>{ie.auth.inviteInfo(e).then(N=>a(N)).catch(()=>C(!0))},[e]);const w=async N=>{if(N.preventDefault(),h(""),i.length<6){h(r("invite.passwordMinLength"));return}if(i!==d){h(r("invite.passwordsDoNotMatch"));return}y(!0);try{await ie.auth.setup(e,i),v(!0),setTimeout(()=>{window.location.hash="",t()},2e3)}catch{h(r("invite.error"))}finally{y(!1)}};return n.jsxs("div",{className:"min-h-dvh bg-surface-primary flex items-center justify-center p-4 relative overflow-hidden",children:[n.jsx("div",{className:"absolute inset-0 bg-[radial-gradient(ellipse_at_top,_var(--tw-gradient-stops))] from-brand-950/50 via-transparent to-transparent"}),n.jsxs("div",{className:"w-full max-w-sm relative z-10",children:[n.jsxs("div",{className:"text-center mb-8",children:[n.jsx("img",{src:"/logo.png",alt:"Markus",className:"w-14 h-14 mx-auto mb-3 rounded-xl shadow-lg shadow-black/40"}),n.jsx("div",{className:"text-2xl font-extrabold tracking-tight text-fg-primary mb-1",children:"Markus"}),n.jsx("div",{className:"text-sm text-fg-tertiary",children:r("invite.subtitle")})]}),n.jsx("div",{className:"bg-surface-secondary/80 backdrop-blur-sm border border-border-default rounded-2xl p-8 space-y-5 shadow-2xl shadow-black/30",children:j?n.jsxs("div",{className:"text-center space-y-3",children:[n.jsx("div",{className:"text-red-500 text-3xl",children:"⚠"}),n.jsx("p",{className:"text-sm text-fg-secondary",children:r("invite.invalidLink")}),n.jsx("button",{onClick:()=>{window.location.hash="",t()},className:"text-sm text-brand-500 hover:text-brand-400",children:r("login.signIn")})]}):x?n.jsxs("div",{className:"text-center space-y-3",children:[n.jsx("div",{className:"text-green-500 text-3xl",children:"✓"}),n.jsx("p",{className:"text-sm text-fg-secondary",children:r("invite.setupComplete")})]}):s?n.jsxs("form",{onSubmit:w,className:"space-y-5",children:[n.jsx("h2",{className:"text-lg font-semibold text-fg-primary text-center",children:r("invite.greeting",{name:s.name})}),n.jsx("p",{className:"text-xs text-fg-tertiary text-center",children:s.email}),n.jsxs("div",{className:"space-y-1",children:[n.jsx("label",{className:"text-xs text-fg-tertiary font-medium",children:r("invite.setPassword")}),n.jsx("input",{type:"password",value:i,onChange:N=>l(N.target.value),autoComplete:"new-password",autoFocus:!0,className:"w-full px-4 py-2.5 bg-surface-elevated border border-border-default rounded-xl text-sm text-fg-primary focus:border-brand-500 outline-none transition-colors",required:!0})]}),n.jsxs("div",{className:"space-y-1",children:[n.jsx("label",{className:"text-xs text-fg-tertiary font-medium",children:r("invite.confirmPassword")}),n.jsx("input",{type:"password",value:d,onChange:N=>u(N.target.value),autoComplete:"new-password",className:"w-full px-4 py-2.5 bg-surface-elevated border border-border-default rounded-xl text-sm text-fg-primary focus:border-brand-500 outline-none transition-colors",required:!0})]}),m&&n.jsx("div",{className:"px-3 py-2 bg-red-500/10 border border-red-500/30 rounded-lg text-xs text-red-500",children:m}),n.jsx("button",{type:"submit",disabled:p||!i||!d,className:"w-full py-2.5 bg-brand-600 hover:bg-brand-500 disabled:opacity-50 text-white text-sm font-medium rounded-xl transition-all shadow-md shadow-brand-900/40 hover:shadow-lg hover:shadow-brand-900/50",children:r(p?"invite.settingUp":"invite.setupAccount")})]}):n.jsx("div",{className:"text-center text-fg-tertiary text-sm animate-pulse py-4",children:"Loading…"})})]})]})}function vse({onComplete:e,isFirstTime:t}){const{t:r}=pt("auth"),[s,a]=g.useState(""),[i,l]=g.useState(""),[d,u]=g.useState(""),[m,h]=g.useState(""),[p,y]=g.useState(!1),x=async v=>{if(v.preventDefault(),h(""),i.length<6){h(r("changePassword.passwordMinLength"));return}if(i!==d){h(r("changePassword.passwordsDoNotMatch"));return}y(!0);try{await ie.auth.changePassword(s,i),e()}catch{h(r("changePassword.failedToChange"))}finally{y(!1)}};return n.jsxs("div",{className:"min-h-dvh bg-surface-primary flex items-center justify-center p-4 relative overflow-hidden",children:[n.jsx("div",{className:"absolute inset-0 bg-[radial-gradient(ellipse_at_top,_var(--tw-gradient-stops))] from-brand-950/50 via-transparent to-transparent"}),n.jsxs("div",{className:"w-full max-w-sm relative z-10",children:[n.jsxs("div",{className:"text-center mb-8",children:[n.jsx("img",{src:"/logo.png",alt:"Markus",className:"w-14 h-14 mx-auto mb-3 rounded-xl shadow-lg shadow-black/40"}),n.jsx("div",{className:"text-2xl font-extrabold tracking-tight text-fg-primary mb-1",children:"Markus"}),n.jsx("div",{className:"text-sm text-fg-tertiary",children:r("login.subtitle")})]}),n.jsxs("form",{onSubmit:x,className:"bg-surface-secondary/80 backdrop-blur-sm border border-border-default rounded-2xl p-8 space-y-5 shadow-2xl shadow-black/30",children:[n.jsxs("div",{children:[n.jsx("h2",{className:"text-lg font-semibold text-fg-primary text-center",children:r(t?"changePassword.setYourPassword":"changePassword.changePassword")}),t&&n.jsx("p",{className:"text-xs text-amber-600/80 text-center mt-2",children:r("changePassword.defaultPasswordWarning")})]}),!t&&n.jsxs("div",{className:"space-y-1",children:[n.jsx("label",{className:"text-xs text-fg-tertiary font-medium",children:r("changePassword.currentPassword")}),n.jsx("input",{type:"password",value:s,onChange:v=>a(v.target.value),autoComplete:"current-password",className:"w-full px-4 py-2.5 bg-surface-elevated border border-border-default rounded-xl text-sm text-fg-primary focus:border-brand-500 outline-none transition-colors"})]}),n.jsxs("div",{className:"space-y-1",children:[n.jsx("label",{className:"text-xs text-fg-tertiary font-medium",children:r("changePassword.newPassword")}),n.jsx("input",{type:"password",value:i,onChange:v=>l(v.target.value),autoComplete:"new-password",className:"w-full px-4 py-2.5 bg-surface-elevated border border-border-default rounded-xl text-sm text-fg-primary focus:border-brand-500 outline-none transition-colors",required:!0,minLength:6})]}),n.jsxs("div",{className:"space-y-1",children:[n.jsx("label",{className:"text-xs text-fg-tertiary font-medium",children:r("changePassword.confirmNewPassword")}),n.jsx("input",{type:"password",value:d,onChange:v=>u(v.target.value),autoComplete:"new-password",className:"w-full px-4 py-2.5 bg-surface-elevated border border-border-default rounded-xl text-sm text-fg-primary focus:border-brand-500 outline-none transition-colors",required:!0})]}),m&&n.jsx("div",{className:"px-3 py-2 bg-red-500/10 border border-red-500/30 rounded-lg text-xs text-red-500",children:m}),n.jsx("button",{type:"submit",disabled:p||!i||!d,className:"w-full py-2.5 bg-brand-600 hover:bg-brand-500 disabled:opacity-50 text-white text-sm font-medium rounded-xl transition-colors",children:r(p?"changePassword.saving":t?"changePassword.setPasswordAndContinue":"changePassword.changePassword")})]})]})]})}const Kf={agents:[],tasks:[],requirements:[],projects:[],deliverables:[]},wse={team:["agents","tasks","requirements","projects","deliverables"],work:["projects","requirements","tasks","agents","deliverables"],deliverables:["deliverables","agents","tasks","requirements","projects"]},kse=["agents","tasks","requirements","projects","deliverables"];let Q3="",Z3="all",J3=Kf,e6=!1;function jse({onClose:e,currentPage:t}){const{t:r}=pt(["common","home","work"]),[s,a]=g.useState(Q3),[i,l]=g.useState(Z3),[d,u]=g.useState(J3),[m,h]=g.useState(!1),[p,y]=g.useState(e6),[x,v]=g.useState(-1);g.useEffect(()=>{Q3=s},[s]),g.useEffect(()=>{Z3=i},[i]),g.useEffect(()=>{J3=d},[d]),g.useEffect(()=>{e6=p},[p]);const j=g.useRef(null),C=g.useRef(void 0),w=g.useRef(null),N=g.useRef(null);g.useEffect(()=>{setTimeout(()=>{j.current?.focus(),j.current?.select()},100)},[]);const S=g.useCallback(async F=>{if(!F.trim()){u(Kf),y(!1),v(-1);return}h(!0),y(!0),v(-1);const L=F.toLowerCase();try{const[O,M,$,W,U]=await Promise.allSettled([ie.agents.list(),ie.tasks.list({search:F,pageSize:20}),ie.requirements.list(),ie.projects.list(),ie.deliverables.search({q:F,limit:20})]),H=O.status==="fulfilled"?O.value.agents.filter(X=>X.name?.toLowerCase().includes(L)||X.role?.toLowerCase().includes(L)):[],q=M.status==="fulfilled"?M.value.tasks:[],Z=$.status==="fulfilled"?$.value.requirements.filter(X=>X.title?.toLowerCase().includes(L)||X.description?.toLowerCase().includes(L)):[],_=W.status==="fulfilled"?W.value.projects.filter(X=>X.name?.toLowerCase().includes(L)||X.description?.toLowerCase().includes(L)):[],J=U.status==="fulfilled"?U.value.results:[];u({agents:H,tasks:q,requirements:Z,projects:_,deliverables:J})}catch{u(Kf)}finally{h(!1)}},[]),T=F=>{a(F),C.current&&clearTimeout(C.current),C.current=setTimeout(()=>S(F),400)},E=g.useCallback((F,L)=>{e(),bt.navigate(F,L)},[e]),R=[{id:"all",label:r("common:all",{defaultValue:"全部"})},{id:"agents",label:r("common:agents",{defaultValue:"智能体"})},{id:"tasks",label:r("common:tasks",{defaultValue:"任务"})},{id:"requirements",label:r("common:requirements",{defaultValue:"需求"})},{id:"projects",label:r("common:projects",{defaultValue:"项目"})},{id:"deliverables",label:r("common:deliverables",{defaultValue:"交付物"})}],I=g.useMemo(()=>wse[t||""]||kse,[t]),z=g.useMemo(()=>{const F=[],L=i==="all"?8:void 0,O=M=>{if(i!=="all"&&i!==M)return;const $=d[M==="agents"?"agents":M==="tasks"?"tasks":M==="requirements"?"requirements":M==="projects"?"projects":"deliverables"],W=L?$.slice(0,L):$;for(const U of W)switch(M){case"agents":F.push({id:U.id,type:"agent",page:De.TEAM,params:{agentId:U.id}});break;case"tasks":F.push({id:U.id,type:"task",page:De.WORK,params:{openTask:U.id}});break;case"requirements":F.push({id:U.id,type:"requirement",page:De.WORK,params:{openRequirement:U.id}});break;case"projects":F.push({id:U.id,type:"project",page:De.WORK,params:{projectId:U.id}});break;case"deliverables":F.push({id:U.id,type:"deliverable",page:De.DELIVERABLES,params:{openDeliverable:U.id}});break}L&&$.length>L&&F.push({id:`more_${M}`,type:"showMore",page:"",expandCategory:M,totalCount:$.length})};for(const M of I)O(M);return F},[d,i,I]),B=g.useCallback(F=>{if(F.type==="showMore"&&F.expandCategory){l(F.expandCategory),v(-1);return}E(F.page,F.params)},[E]);g.useEffect(()=>{const F=N.current;if(!F||x<0)return;const L=F.querySelector(`[data-idx="${x}"]`);L&&L.scrollIntoView({block:"nearest"})},[x]);const D=g.useCallback(F=>{if(F.key==="Escape"){e();return}if(F.key==="Tab"){F.preventDefault();const M=R.map(U=>U.id),$=M.indexOf(i),W=F.shiftKey?$<=0?M.length-1:$-1:$>=M.length-1?0:$+1;l(M[W]),v(-1);return}const L=F.ctrlKey&&F.key==="n"||F.key==="ArrowDown",O=F.ctrlKey&&F.key==="p"||F.key==="ArrowUp";if(L||O){F.preventDefault(),v(M=>{const $=z.length-1;return $<0?-1:L?M>=$?0:M+1:M<=0?$:M-1});return}F.key==="Enter"&&(F.preventDefault(),x>=0&&x<z.length&&B(z[x]))},[e,z,x,B,R,i]);g.useEffect(()=>(document.addEventListener("keydown",D),()=>document.removeEventListener("keydown",D)),[D]);const V=z.length>0;let Y=0;return n.jsx("div",{ref:w,className:"fixed inset-0 bg-black/50 flex items-start justify-center z-50 pt-[8vh]",onClick:F=>{F.target===w.current&&e()},children:n.jsxs("div",{className:"bg-surface-primary border border-border-default rounded-2xl shadow-2xl w-full max-w-3xl max-h-[78vh] flex flex-col overflow-hidden animate-fadeIn",children:[n.jsxs("div",{className:"shrink-0 px-5 pt-4 pb-3 border-b border-border-default space-y-3",children:[n.jsxs("div",{className:"relative",children:[n.jsxs("svg",{className:"absolute left-3 top-1/2 -translate-y-1/2 text-fg-tertiary",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("circle",{cx:"11",cy:"11",r:"8"}),n.jsx("line",{x1:"21",y1:"21",x2:"16.65",y2:"16.65"})]}),n.jsx("input",{ref:j,value:s,onChange:F=>T(F.target.value),placeholder:r("common:search"),className:"w-full bg-surface-elevated border border-border-default rounded-xl pl-9 pr-9 py-2.5 text-sm text-fg-primary placeholder:text-fg-tertiary focus:border-brand-500 focus:outline-none transition-colors"}),s&&n.jsx("button",{onClick:()=>{a(""),u(Kf),y(!1),v(-1),j.current?.focus()},className:"absolute right-3 top-1/2 -translate-y-1/2 text-fg-tertiary hover:text-fg-secondary",children:n.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),n.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]}),n.jsx("div",{className:"flex gap-1 overflow-x-auto scrollbar-hide",children:R.map(F=>n.jsx("button",{onClick:()=>{l(F.id),v(-1)},className:`px-3 py-1.5 text-xs rounded-lg whitespace-nowrap transition-colors ${i===F.id?"bg-brand-600 text-white":"bg-surface-elevated text-fg-secondary hover:text-fg-primary"}`,children:F.label},F.id))})]}),n.jsxs("div",{ref:N,className:"flex-1 overflow-y-auto px-5 py-3",children:[m&&n.jsx("div",{className:"flex items-center justify-center py-8",children:n.jsx("div",{className:"text-fg-tertiary text-sm animate-pulse",children:r("common:loading")})}),!m&&p&&!V&&n.jsxs("div",{className:"flex flex-col items-center justify-center py-8 text-center",children:[n.jsxs("svg",{width:"36",height:"36",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",className:"text-fg-tertiary mb-2",children:[n.jsx("circle",{cx:"11",cy:"11",r:"8"}),n.jsx("line",{x1:"21",y1:"21",x2:"16.65",y2:"16.65"})]}),n.jsx("p",{className:"text-sm text-fg-tertiary",children:r("common:noResults",{defaultValue:"没有找到相关结果"})})]}),!m&&V&&n.jsx("div",{className:"space-y-4",children:I.map(F=>{if(i!=="all"&&i!==F)return null;const L=i==="all"?8:void 0,O=M=>{const $=Y++,W=M==="agents"?d.agents.length:M==="tasks"?d.tasks.length:M==="requirements"?d.requirements.length:M==="projects"?d.projects.length:d.deliverables.length;return n.jsxs("button",{"data-idx":$,onClick:()=>{l(M),v(-1)},className:`mt-1 w-full text-xs py-1.5 rounded-lg transition-colors ${$===x?"bg-brand-600/15 ring-1 ring-brand-500/40 text-brand-500":"text-brand-500 hover:text-brand-400 hover:bg-surface-overlay"}`,children:[r("common:showAll",{defaultValue:"查看全部"})," (",W,")"]})};return F==="agents"&&d.agents.length>0?n.jsxs("section",{children:[n.jsx("h3",{className:"text-xs font-medium text-fg-tertiary uppercase mb-2",children:r("common:agents",{defaultValue:"智能体"})}),n.jsx("div",{className:"space-y-0.5",children:(L?d.agents.slice(0,L):d.agents).map(M=>{const $=Y++;return n.jsxs("button",{"data-idx":$,onClick:()=>E(De.TEAM,{agentId:M.id}),className:`w-full flex items-center gap-3 px-3 py-2 rounded-xl transition-colors text-left ${$===x?"bg-brand-600/15 ring-1 ring-brand-500/40":"hover:bg-surface-overlay"}`,children:[n.jsx(Nr,{name:M.name||"Agent",avatarUrl:M.avatarUrl,size:28}),n.jsxs("div",{className:"flex-1 min-w-0",children:[n.jsx("div",{className:"text-sm font-medium text-fg-primary truncate",children:M.name}),n.jsx("div",{className:"text-xs text-fg-tertiary truncate",children:M.role||M.status})]}),n.jsx(Nse,{status:M.status})]},M.id)})}),L&&d.agents.length>L&&O("agents")]},"agents"):F==="tasks"&&d.tasks.length>0?n.jsxs("section",{children:[n.jsx("h3",{className:"text-xs font-medium text-fg-tertiary uppercase mb-2",children:r("common:tasks",{defaultValue:"任务"})}),n.jsx("div",{className:"space-y-0.5",children:(L?d.tasks.slice(0,L):d.tasks).map(M=>{const $=Y++;return n.jsxs("button",{"data-idx":$,onClick:()=>E(De.WORK,{openTask:M.id}),className:`w-full flex items-center gap-3 px-3 py-2 rounded-xl transition-colors text-left ${$===x?"bg-brand-600/15 ring-1 ring-brand-500/40":"hover:bg-surface-overlay"}`,children:[n.jsx(Sse,{status:M.status}),n.jsxs("div",{className:"flex-1 min-w-0",children:[n.jsx("div",{className:"text-sm text-fg-primary truncate",children:M.title}),n.jsxs("div",{className:"text-xs text-fg-tertiary truncate",children:[M.status," · ",M.priority||""]})]})]},M.id)})}),L&&d.tasks.length>L&&O("tasks")]},"tasks"):F==="requirements"&&d.requirements.length>0?n.jsxs("section",{children:[n.jsx("h3",{className:"text-xs font-medium text-fg-tertiary uppercase mb-2",children:r("common:requirements",{defaultValue:"需求"})}),n.jsx("div",{className:"space-y-0.5",children:(L?d.requirements.slice(0,L):d.requirements).map(M=>{const $=Y++;return n.jsxs("button",{"data-idx":$,onClick:()=>E(De.WORK,{openRequirement:M.id}),className:`w-full flex items-center gap-3 px-3 py-2 rounded-xl transition-colors text-left ${$===x?"bg-brand-600/15 ring-1 ring-brand-500/40":"hover:bg-surface-overlay"}`,children:[n.jsx("div",{className:`w-7 h-7 rounded-lg flex items-center justify-center shrink-0 ${M.status==="approved"?"text-green-500 bg-green-500/15":M.status==="pending"?"text-amber-500 bg-amber-500/15":M.status==="rejected"?"text-red-500 bg-red-500/15":"text-fg-tertiary bg-surface-elevated"}`,children:n.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[n.jsx("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),n.jsx("polyline",{points:"14 2 14 8 20 8"}),n.jsx("line",{x1:"16",y1:"13",x2:"8",y2:"13"}),n.jsx("line",{x1:"16",y1:"17",x2:"8",y2:"17"})]})}),n.jsxs("div",{className:"flex-1 min-w-0",children:[n.jsx("div",{className:"text-sm text-fg-primary truncate",children:M.title}),n.jsxs("div",{className:"text-xs text-fg-tertiary truncate",children:[M.status," · ",M.priority||""]})]})]},M.id)})}),L&&d.requirements.length>L&&O("requirements")]},"requirements"):F==="projects"&&d.projects.length>0?n.jsxs("section",{children:[n.jsx("h3",{className:"text-xs font-medium text-fg-tertiary uppercase mb-2",children:r("common:projects",{defaultValue:"项目"})}),n.jsx("div",{className:"space-y-0.5",children:(L?d.projects.slice(0,L):d.projects).map(M=>{const $=Y++;return n.jsxs("button",{"data-idx":$,onClick:()=>E(De.WORK,{projectId:M.id}),className:`w-full flex items-center gap-3 px-3 py-2 rounded-xl transition-colors text-left ${$===x?"bg-brand-600/15 ring-1 ring-brand-500/40":"hover:bg-surface-overlay"}`,children:[n.jsx("div",{className:"w-7 h-7 rounded-lg bg-teal-500/15 flex items-center justify-center shrink-0",children:n.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:"text-teal-500",children:n.jsx("path",{d:"M22 19a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h5l2 3h9a2 2 0 0 1 2 2z"})})}),n.jsxs("div",{className:"flex-1 min-w-0",children:[n.jsx("div",{className:"text-sm text-fg-primary truncate",children:M.name}),M.description&&n.jsx("div",{className:"text-xs text-fg-tertiary truncate",children:M.description})]})]},M.id)})}),L&&d.projects.length>L&&O("projects")]},"projects"):F==="deliverables"&&d.deliverables.length>0?n.jsxs("section",{children:[n.jsx("h3",{className:"text-xs font-medium text-fg-tertiary uppercase mb-2",children:r("common:deliverables",{defaultValue:"交付物"})}),n.jsx("div",{className:"space-y-0.5",children:(L?d.deliverables.slice(0,L):d.deliverables).map(M=>{const $=Y++;return n.jsxs("button",{"data-idx":$,onClick:()=>E(De.DELIVERABLES,{openDeliverable:M.id}),className:`w-full flex items-center gap-3 px-3 py-2 rounded-xl transition-colors text-left ${$===x?"bg-brand-600/15 ring-1 ring-brand-500/40":"hover:bg-surface-overlay"}`,children:[n.jsx("div",{className:"w-7 h-7 rounded-lg bg-purple-500/15 flex items-center justify-center shrink-0",children:n.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:"text-purple-500",children:[n.jsx("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),n.jsx("polyline",{points:"14 2 14 8 20 8"})]})}),n.jsxs("div",{className:"flex-1 min-w-0",children:[n.jsx("div",{className:"text-sm text-fg-primary truncate",children:M.title}),n.jsxs("div",{className:"text-xs text-fg-tertiary truncate",children:[M.type," · ",M.status]})]})]},M.id)})}),L&&d.deliverables.length>L&&O("deliverables")]},"deliverables"):null})}),!m&&!p&&n.jsxs("div",{className:"flex flex-col items-center justify-center py-8 text-center",children:[n.jsxs("svg",{width:"36",height:"36",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",className:"text-fg-tertiary mb-2",children:[n.jsx("circle",{cx:"11",cy:"11",r:"8"}),n.jsx("line",{x1:"21",y1:"21",x2:"16.65",y2:"16.65"})]}),n.jsx("p",{className:"text-sm text-fg-tertiary",children:r("common:searchHint",{defaultValue:"输入关键词搜索"})})]})]}),n.jsxs("div",{className:"shrink-0 px-5 py-2 border-t border-border-default flex items-center gap-4 text-xs text-fg-tertiary flex-wrap",children:[n.jsxs("span",{children:[n.jsx("kbd",{className:"px-1.5 py-0.5 rounded bg-surface-elevated border border-border-default text-[11px] font-medium",children:navigator.platform.toUpperCase().includes("MAC")?"Cmd+P":"Ctrl+P"})," ",r("common:toggle",{defaultValue:"唤起/关闭"})]}),n.jsxs("span",{children:[n.jsx("kbd",{className:"px-1.5 py-0.5 rounded bg-surface-elevated border border-border-default text-[11px] font-medium",children:"Tab"})," ",r("common:switchTab",{defaultValue:"切换分类"})]}),n.jsxs("span",{children:[n.jsx("kbd",{className:"px-1.5 py-0.5 rounded bg-surface-elevated border border-border-default text-[11px] font-medium",children:"↑↓"})," ",r("common:navigate",{defaultValue:"导航"})]}),n.jsxs("span",{children:[n.jsx("kbd",{className:"px-1.5 py-0.5 rounded bg-surface-elevated border border-border-default text-[11px] font-medium",children:"Enter"})," ",r("common:open",{defaultValue:"打开"})]}),n.jsxs("span",{children:[n.jsx("kbd",{className:"px-1.5 py-0.5 rounded bg-surface-elevated border border-border-default text-[11px] font-medium",children:"Esc"})," ",r("common:close",{defaultValue:"关闭"})]})]})]})})}function Nse({status:e}){const t=e==="active"||e==="idle"?"bg-green-500":e==="working"||e==="busy"?"bg-blue-500":e==="paused"?"bg-amber-500":"bg-gray-400";return n.jsx("span",{className:`w-2 h-2 rounded-full shrink-0 ${t}`})}function Sse({status:e}){const t=e==="completed"?"text-green-500 bg-green-500/15":e==="in_progress"?"text-blue-500 bg-blue-500/15":e==="pending"?"text-amber-500 bg-amber-500/15":"text-fg-tertiary bg-surface-elevated";return n.jsx("div",{className:`w-7 h-7 rounded-lg flex items-center justify-center shrink-0 ${t}`,children:n.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[n.jsx("path",{d:"M9 11l3 3L22 4"}),n.jsx("path",{d:"M21 12v7a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h11"})]})})}const Cse={visibility:"hidden",position:"absolute",inset:0,pointerEvents:"none",zIndex:-1},Tse=g.memo(function({id:t,activePage:r,children:s}){const a=t===r;return n.jsx("div",{className:"flex-1 overflow-hidden flex flex-col",style:a?void 0:Cse,children:s})},(e,t)=>{const r=e.id===e.activePage,s=t.id===t.activePage;return r!==s?!1:s?e.children===t.children:!0}),db={};function Ase(){const{t:e}=pt("common"),[t,r]=g.useState(ec),[s,a]=g.useState(()=>!localStorage.getItem("markus_onboarded")),[i,l]=g.useState(!0),d=Rs(),u=nY(),m=f0({side:"left",defaultWidth:160,minWidth:140,maxWidth:400,collapsedWidth:64,storageKey:"markus_sidebar"}),[h,p]=g.useState(()=>new Set([ec()])),[y,x]=g.useState("loading"),[v,j]=g.useState(null),[C,w]=g.useState({hasOwner:!1,hasMultipleUsers:!1}),[N,S]=g.useState(!1),[T,E]=g.useState(!1),[R,I]=g.useState(null),[z,B]=g.useState(!1),[D,V]=g.useState(null),[Y,F]=g.useState(()=>{const te=localStorage.getItem("markus_update_dismissed");return te||null}),[L,O]=g.useState(null),[M,$]=g.useState(!1),W=g.useCallback(()=>{ie.license.get().then(te=>{if(te.plan==="enterprise"){O(null);return}if(te.usage&&te.limits){const G=te.limits.maxTeams>0&&te.usage.teams>=te.limits.maxTeams,ue=te.limits.maxToolCallsPerDay>0&&te.usage.toolCallsToday>=te.limits.maxToolCallsPerDay;G||ue?(O({teams:G||void 0,toolCalls:ue||void 0}),$(!1)):O(null)}}).catch(()=>{})},[]);g.useEffect(()=>{const te=()=>{document.visibilityState==="visible"&&W()};window.addEventListener("markus:check-license-limits",W),document.addEventListener("visibilitychange",te);const G=setInterval(W,300*1e3);return()=>{window.removeEventListener("markus:check-license-limits",W),document.removeEventListener("visibilitychange",te),clearInterval(G)}},[W]);const[U,H]=g.useState(!1);g.useEffect(()=>{if(d)return;const te=navigator.platform.toUpperCase().includes("MAC"),G=Se=>{te&&Se.metaKey&&!Se.ctrlKey&&Se.key==="p"?(Se.preventDefault(),H(Ce=>!Ce)):!te&&Se.ctrlKey&&!Se.metaKey&&Se.key==="p"&&(Se.preventDefault(),H(Ce=>!Ce))},ue=()=>H(!0);return document.addEventListener("keydown",G),window.addEventListener("markus:open-search",ue),()=>{document.removeEventListener("keydown",G),window.removeEventListener("markus:open-search",ue)}},[d]);const q=g.useCallback(te=>{let G=nc(te);d?G=$_[G]??G:G===De.NOTIFICATIONS&&(G=De.HOME);const ue=ec(),Se=window.location.hash.slice(1);Se!==ue?db[ue]=Se:delete db[ue];const Ce=G!==De.WORK?db[G]:void 0;Ce&&Ce!==G?(history.pushState(null,"","#"+G),history.pushState(null,"","#"+Ce)):history.pushState(null,"","#"+G),window.dispatchEvent(new HashChangeEvent("hashchange")),r(G),p(Be=>Be.has(G)?Be:new Set([...Be,G]))},[d]);g.useEffect(()=>{bt.setHandler(te=>q(te))},[q]);const Z=g.useCallback(()=>{fetch("/api/settings/llm").then(te=>te.ok?te.json():null).then(te=>{if(te?.providers){const G=Object.values(te.providers).some(ue=>ue.configured);I(G)}}).catch(()=>{})},[]);g.useEffect(()=>{const te=new URLSearchParams(window.location.search),G=te.get("install");if(G&&ec()!==De.STORE){const Ce=te.get("type"),Ne=Ce&&{agent:"agents",team:"teams",skill:"skills"}[Ce]||"agents";localStorage.setItem("markus_nav_installItem",G),localStorage.setItem("markus_nav_storeTab",Ne),te.delete("install"),te.delete("type");const he=te.toString();window.history.replaceState(null,"",window.location.pathname+(he?`?${he}`:"")+"#store"),setTimeout(()=>bt.navigate(De.STORE,{storeTab:Ne,installItem:G}),300)}ie.auth.me().then(({user:Ce})=>{x(Ce),j(!0),pn.connect(Ce.id),Z(),ie.health().then(Ne=>{Ne.updateAvailable&&Ne.latestVersion&&V({latestVersion:Ne.latestVersion,currentVersion:Ne.version})}).catch(()=>{}),W();const Be=()=>{Xl(La.builderArtifacts,()=>ie.builder.artifacts.list()),Xl(La.builderAgents,()=>ie.agents.list()),Xl(La.builderHubMyItems,()=>Wn.myItems()),Xl(La.builderInstalled,()=>ie.builder.artifacts.installed()),Xl(La.hubAgents,()=>Wn.search({type:"agent",limit:50})),Xl(La.hubTeams,()=>Wn.search({type:"team",limit:50})),Xl(La.hubSkills,()=>Wn.search({type:"skill",limit:50}))};typeof requestIdleCallback=="function"?requestIdleCallback(Be,{timeout:5e3}):setTimeout(Be,3e3)}).catch(()=>{x(null),ie.auth.status().then(({initialized:Ce,hasOwner:Be,hasMultipleUsers:Ne})=>{j(Ce),w({hasOwner:Be,hasMultipleUsers:Ne})}).catch(()=>j(!0))}),pn.connect();const ue=pn.on("notification",()=>{window.dispatchEvent(new CustomEvent("markus:notifications-changed"))}),Se=()=>{const Ce=ec();r(Ce),p(Be=>Be.has(Ce)?Be:new Set([...Be,Ce]))};return window.addEventListener("hashchange",Se),window.addEventListener("popstate",Se),()=>{ue(),pn.disconnect(),window.removeEventListener("hashchange",Se),window.removeEventListener("popstate",Se)}},[]);const _=y!=="loading"&&y!==null?y:void 0,J=g.useMemo(()=>d?{[De.HOME]:n.jsx(bw,{authUser:_}),[De.TEAM]:n.jsx(Yk,{authUser:_}),[De.BUILDER]:n.jsx(gse,{authUser:_}),[De.SETTINGS]:n.jsx(ej,{theme:u.mode,onThemeChange:u.setMode,authUser:_,onLogout:()=>{ie.auth.logout().catch(()=>{}),r0(),x(null)},onUserUpdated:te=>x(te)}),[De.WORK]:n.jsx(F3,{authUser:_}),[De.DELIVERABLES]:n.jsx(U3,{authUser:_}),[De.NOTIFICATIONS]:n.jsx(lse,{authUser:_}),[De.REPORTS]:n.jsx(K3,{authUser:_}),[De.SEARCH]:n.jsx(cse,{})}:{[De.HOME]:n.jsx(bw,{authUser:_}),[De.TEAM]:n.jsx(Yk,{authUser:_}),[De.SETTINGS]:n.jsx(ej,{theme:u.mode,onThemeChange:u.setMode,authUser:_,onLogout:()=>{ie.auth.logout().catch(()=>{}),r0(),x(null)},onUserUpdated:te=>x(te)}),[De.STORE]:n.jsx(BY,{authUser:_}),[De.BUILDER]:n.jsx(e7,{authUser:_}),[De.WORK]:n.jsx(F3,{authUser:_}),[De.DELIVERABLES]:n.jsx(U3,{authUser:_}),[De.REPORTS]:n.jsx(K3,{authUser:_})},[_?.id,_?.role,u.mode,d]);if(y==="loading"||y===null&&v===null)return n.jsx("div",{className:"min-h-dvh bg-surface-primary flex items-center justify-center",children:n.jsx("div",{className:"text-fg-tertiary text-sm animate-pulse",children:e("loading")})});const ee=(typeof window<"u"?window.location.hash:"").match(/^#invite\?token=([a-f0-9]+)/);return ee?n.jsx(yse,{token:ee[1],onComplete:()=>{window.location.hash="",localStorage.removeItem("markus_onboarded"),a(!0),S(!0),x("loading"),ie.auth.me().then(te=>x(te.user)).catch(()=>x(null))}}):y===null?n.jsx(bse,{hasOwner:C.hasOwner,hasMultipleUsers:C.hasMultipleUsers,onLogin:(te,G,ue)=>{x(te),G?(localStorage.removeItem("markus_onboarded"),a(!0),ue?.fromHub&&S(!0)):localStorage.getItem("markus_onboarded")||(localStorage.setItem("markus_onboarded","1"),a(!1))}}):T?n.jsx(vse,{onComplete:()=>E(!1),isFirstTime:!0}):s?n.jsx(xse,{theme:u.mode,onThemeChange:u.setMode,skipProfile:N,onComplete:()=>{localStorage.setItem("markus_onboarded","1"),a(!1),S(!1),Z(),q(De.HOME)}}):n.jsxs("div",{className:`flex h-dvh bg-surface-primary text-fg-primary overflow-x-hidden ${d?"flex-col":""}`,children:[!d&&t!==De.SETTINGS&&n.jsxs(n.Fragment,{children:[n.jsx("div",{className:"relative z-40 shrink-0",style:{width:m.width},children:n.jsx(fse,{currentPage:t,onNavigate:te=>{q(te),l(!1)},authUser:y,collapsed:m.collapsed,onToggleCollapse:m.toggle})}),n.jsx("div",{className:`${m.collapsed?"w-0":"w-1.5 cursor-col-resize"} shrink-0 group relative z-10 flex items-center justify-center`,onMouseDown:m.collapsed?void 0:m.onResizeStart,children:!m.collapsed&&n.jsx("div",{className:"w-px h-2/3 border-l border-dashed border-transparent group-hover:border-border-default group-active:border-fg-tertiary transition-colors"})})]}),n.jsxs("div",{className:`flex-1 overflow-hidden flex flex-col min-w-0 ${d&&t!==De.SETTINGS&&t!==De.SEARCH?"pb-14":""}`,children:[R===!1&&!z&&t!==De.SETTINGS&&n.jsxs("div",{className:"flex items-center justify-between px-4 py-2 bg-amber-500/10 border-b border-amber-500/30 text-amber-600 text-sm shrink-0",children:[n.jsx("span",{className:d?"text-xs":"",children:"No LLM provider configured — agents cannot process requests."}),n.jsxs("div",{className:"flex items-center gap-3",children:[n.jsx("button",{onClick:()=>{q(De.SETTINGS)},className:"px-3 py-1 bg-amber-700/50 hover:bg-amber-700/70 text-white text-xs rounded-lg transition-colors",children:"Go to Settings"}),n.jsx("button",{onClick:()=>B(!0),className:"text-amber-500 hover:text-amber-600 text-xs",children:e("dismiss")})]})]}),D&&Y!==D.latestVersion&&n.jsxs("div",{className:"flex items-center justify-between px-4 py-2 bg-brand-500/10 border-b border-brand-500/30 text-brand-400 text-sm shrink-0",children:[n.jsx("span",{className:d?"text-xs":"",children:e("update.available",{latest:D.latestVersion,current:D.currentVersion})}),n.jsxs("span",{className:"flex items-center gap-3 shrink-0",children:[n.jsx("a",{href:"https://markus.global/download",target:"_blank",rel:"noopener noreferrer",className:"text-xs font-medium text-brand-400 hover:text-brand-300 transition-colors",children:e("update.download")}),n.jsx("button",{onClick:()=>{F(D.latestVersion),localStorage.setItem("markus_update_dismissed",D.latestVersion)},className:"text-fg-tertiary hover:text-fg-secondary text-xs shrink-0",children:e("dismiss")})]})]}),L&&!M&&t!==De.SETTINGS&&n.jsxs("div",{className:"flex items-center justify-between px-4 py-2 bg-orange-500/10 border-b border-orange-500/30 text-orange-400 text-sm shrink-0",children:[n.jsx("span",{className:d?"text-xs":"",children:L.teams&&L.toolCalls?e("license.limitReachedBoth"):L.teams?e("license.limitReachedTeams"):e("license.limitReachedToolCalls")}),n.jsxs("span",{className:"flex items-center gap-3 shrink-0",children:[n.jsx("button",{onClick:()=>{window.location.hash="settings/account"},className:"px-3 py-1 bg-orange-600/50 hover:bg-orange-600/70 text-white text-xs rounded-lg transition-colors",children:e("license.upgradeLicense")}),n.jsx("button",{onClick:()=>$(!0),className:"text-fg-tertiary hover:text-fg-secondary text-xs shrink-0",children:e("dismiss")})]})]}),n.jsx("main",{className:"flex-1 overflow-hidden flex flex-col relative",children:Object.keys(J).map(te=>h.has(te)?n.jsx(Tse,{id:te,activePage:t,children:J[te]},te):null)})]}),d&&t!==De.SETTINGS&&t!==De.SEARCH&&n.jsx(hse,{currentPage:t,onNavigate:q,userId:_?.id}),d&&n.jsx(V_,{authUser:_,onNavigate:q}),!d&&U&&n.jsx(jse,{onClose:()=>H(!1),currentPage:t})]})}R9.createRoot(document.getElementById("root")).render(n.jsx(g.StrictMode,{children:n.jsx(Ase,{})}));export{N0 as g};
711
+ ${fs?"ring-2 ring-brand-500/50 border-brand-500/40":""}`,children:[n.jsxs("div",{className:"flex items-center gap-1.5 mb-1",children:[n.jsx("span",{className:"w-1 h-1 rounded-full bg-purple-500 shrink-0"}),n.jsx("span",{className:"text-[10px] font-semibold text-purple-500 uppercase tracking-wide shrink-0",children:s("work:task.requirementShort")}),n.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded-md shrink-0 ml-auto ${us.cls}`,children:us.label})]}),n.jsx("div",{className:"text-[13px] font-medium leading-snug text-fg-primary line-clamp-2 mb-1",children:yt.title}),yt.description&&n.jsx("div",{className:"text-[11px] text-fg-tertiary line-clamp-1 mb-1.5",children:yt.description}),n.jsxs("div",{className:"flex items-center justify-between mt-auto pt-1.5 border-t border-border-default/20",children:[n.jsxs("div",{className:"flex items-center gap-1.5",children:[os&&n.jsx("span",{className:"text-[10px] px-1.5 py-0.5 bg-surface-overlay/60 text-fg-secondary rounded truncate max-w-[90px]",title:os.name,children:os.name}),n.jsx("span",{className:"text-[10px] text-fg-tertiary",children:yt.priority}),n.jsxs("span",{className:"text-[10px] text-fg-quaternary",children:["by ",Vr]})]}),n.jsx("div",{className:"flex items-center gap-1",children:yt.taskIds.length>0&&n.jsxs("span",{className:"text-[10px] text-brand-500/70 bg-brand-500/8 px-1.5 py-0.5 rounded-md",children:["📋 ",yt.taskIds.length]})})]}),ms&&n.jsxs("div",{className:"flex items-center gap-2 mt-2 pt-2 border-t border-amber-500/15",children:[n.jsx("button",{onClick:jr=>{jr.stopPropagation(),qr(yt.id)},className:"flex-1 py-1 bg-green-600 hover:bg-green-500 text-white text-[10px] rounded-md font-medium transition-colors",children:s("work:task.approve")}),n.jsx("button",{onClick:jr=>{jr.stopPropagation(),$t(yt.id)},className:"flex-1 py-1 border border-red-500/30 hover:bg-red-500/10 text-red-500 text-[10px] rounded-md font-medium transition-colors",children:s("work:task.reject")})]})]},`req-${yt.id}`)}else{const yt=un.data,us=yt.subtasks?.length??0,Ur=l[yt.status],ms=yt.status==="pending",os=yt.taskType==="scheduled"&&!!yt.scheduleConfig,Vr=os?yt.scheduleConfig.every?s("work:task.everyInterval",{interval:yt.scheduleConfig.every}):yt.scheduleConfig.cron?s("work:task.cronLabel"):s("work:task.scheduledShort"):null,fs=T==="all"&&yt.projectId?(()=>{const Ie=N.find(st=>st.id===yt.projectId)?.name;return Ie&&Ie!=="default"?Ie:null})():null,jr=yt.requirementId?L.find(Ie=>Ie.id===yt.requirementId)?.title:null,to=yt.createdBy?Rd(yt.createdBy,D,Y)??yt.createdBy:null,Ii=pe?.id===yt.id,no={urgent:"bg-red-500",high:"bg-amber-500",medium:"bg-blue-500",low:"bg-gray-400"},le=yt.status==="blocked"&&(!yt.blockedBy||yt.blockedBy.length===0||yt.blockedBy.every(Ie=>{const st=oi.get(Ie);return st&&st.status==="completed"}));return n.jsxs("div",{role:"button",tabIndex:0,"aria-label":yt.title,draggable:!ms,onDragStart:Ie=>!ms&&aa(Ie,yt),onDragEnd:Xn,onClick:()=>fr(yt),onKeyDown:Ie=>Ie.key==="Enter"&&fr(yt),className:`group rounded-lg p-2.5 border border-transparent transition-all ${le?"bg-red-500/[0.06] border-red-500/30 ring-1 ring-red-500/15 cursor-pointer":ms?"bg-amber-500/[0.06] border-amber-500/30 ring-1 ring-amber-500/15 cursor-pointer":os?"bg-blue-500/[0.04] border-blue-500/20 hover:border-blue-400/40 cursor-pointer":"bg-surface-elevated/80 hover:bg-surface-elevated border-border-default/50 hover:border-brand-400/40 cursor-grab active:cursor-grabbing"} ${Ii?"ring-2 ring-brand-500/50 border-brand-500/40":""}`,children:[n.jsxs("div",{className:"flex items-center gap-1.5 mb-1",children:[n.jsx("span",{className:`w-1.5 h-1.5 rounded-full shrink-0 ${no[yt.priority]??"bg-gray-400"}`,title:yt.priority}),os&&n.jsx("span",{className:"text-blue-500 shrink-0",title:Vr??"Scheduled",children:n.jsx("svg",{className:"w-3 h-3",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:n.jsx("path",{d:"M21.5 2v6h-6M2.5 22v-6h6M2 11.5a10 10 0 0 1 18.8-4.3M22 12.5a10 10 0 0 1-18.8 4.3"})})}),os&&Vr&&n.jsx("span",{className:"text-[9px] px-1.5 py-0.5 rounded-md bg-blue-500/10 text-blue-500 whitespace-nowrap",children:Vr}),Ur&&n.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded-md ml-auto shrink-0 ${Ur.cls}`,children:Ur.label}),le&&n.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded-md shrink-0 bg-red-500/15 text-red-500 font-medium",children:"⚠"})]}),n.jsx("div",{className:"text-[13px] font-medium leading-snug text-fg-primary line-clamp-2 mb-1",children:yt.title}),yt.description&&n.jsx("div",{className:"text-[11px] text-fg-tertiary line-clamp-1 mb-1.5",children:yt.description}),(fs||jr||yt.blockedBy&&yt.blockedBy.length>0)&&n.jsxs("div",{className:"flex flex-wrap gap-1 mb-1.5",children:[fs&&n.jsx("span",{className:"text-[10px] px-1.5 py-0.5 bg-surface-overlay/60 text-fg-secondary rounded-md truncate max-w-[100px]",title:fs,children:fs}),jr&&n.jsxs("span",{className:"text-[10px] px-1.5 py-0.5 bg-brand-500/8 text-brand-500 rounded-md truncate max-w-[110px]",title:jr,children:["# ",jr]}),yt.blockedBy&&yt.blockedBy.length>0&&n.jsxs("span",{className:"text-[10px] px-1.5 py-0.5 bg-amber-500/10 text-amber-600 rounded-md",children:["⏳ ",yt.blockedBy.length," dep",yt.blockedBy.length>1?"s":""]})]}),n.jsxs("div",{className:"flex items-center justify-between mt-auto pt-1.5 border-t border-border-default/20",children:[n.jsx("div",{className:"flex items-center gap-1.5",children:to&&n.jsxs("span",{className:"text-[10px] text-fg-quaternary",title:`by ${to}`,children:["by ",to]})}),n.jsxs("div",{className:"flex items-center gap-1.5",children:[us>0&&n.jsxs("span",{className:"text-[10px] text-fg-tertiary",children:["⋮ ",us]}),yt.notes&&yt.notes.length>0&&n.jsxs("span",{className:"text-[10px] text-fg-tertiary",children:["📝 ",yt.notes.length]}),yt.assignedAgentId&&n.jsxs("span",{className:"text-[10px] text-brand-500 bg-brand-500/8 px-1.5 py-0.5 rounded-md flex items-center gap-1",children:[n.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${j0[D.find(Ie=>Ie.id===yt.assignedAgentId)?.status??""]??"bg-gray-500"}`}),D.find(Ie=>Ie.id===yt.assignedAgentId)?.name??yt.assignedAgentId.slice(0,8)]})]})]})]},yt.id)}})})()}),fn&&n.jsx("div",{className:"mx-2 mb-2 border-2 border-dashed border-brand-500/25 rounded-lg h-10 flex items-center justify-center shrink-0",children:n.jsx("span",{className:"text-[11px] text-brand-500/50",children:s("work:task.dropHere")})})]},oe.id)})})})]}),!u&&Na&&n.jsx("div",{className:"w-1.5 shrink-0 cursor-col-resize group relative flex items-center justify-center",onMouseDown:v.onResizeStart,children:n.jsx("div",{className:"w-px h-2/3 border-l border-dashed border-transparent group-hover:border-border-default group-active:border-fg-tertiary transition-colors"})}),(!u||j)&&Na&&n.jsx("div",{className:`${u||Sa?"flex-1":"shrink-0"} overflow-hidden min-w-0 flex`,style:u||Sa?void 0:{width:v.width},children:Sa?n.jsxs(n.Fragment,{children:[n.jsx("div",{className:"flex-1 min-w-0 overflow-hidden",children:n.jsx(q3,{req:Ve,agents:D,projects:N,allTasks:Object.values(z).flat(),users:Y,onClose:()=>{nt(null)},onApprove:oe=>{qr(oe)},onReject:oe=>{$t(oe)},onCancel:oe=>{Cs(oe),nt(null)},onStatusChange:async(oe,Qe)=>{try{await ie.requirements.updateStatus(oe,Qe),Dt(`Requirement status → ${Qe}`),Ss({requirementId:oe}),Ps(),on()}catch(dt){Dt(`Error: ${dt}`)}},onRefresh:Ps,authUser:e,onTaskClick:oe=>{Fe(oe)},onCreateTask:(oe,Qe)=>{ht(oe),Qe&&it(Qe),G(!0)},onProjectClick:kn,previewMode:t})}),n.jsx("div",{className:"w-px shrink-0 bg-border-default"}),n.jsx("div",{className:"flex-1 min-w-0 overflow-hidden",children:n.jsx(_3,{task:pe,agents:D,projects:N,requirements:L,allTasks:Object.values(z).flat(),users:Y,onClose:xa,onRefresh:yr,authUser:e,scrollToComments:ni,onScrollToCommentsDone:()=>ri(!1),onReqClick:oe=>{nt(Qe=>Qe?.id===oe.id?null:oe)},onProjectClick:kn})})]}):pe?n.jsx(_3,{task:pe,agents:D,projects:N,requirements:L,allTasks:Object.values(z).flat(),users:Y,onClose:ga,onRefresh:yr,authUser:e,scrollToComments:ni,onScrollToCommentsDone:()=>ri(!1),onReqClick:oe=>{nt(Qe=>Qe?.id===oe.id?null:oe)},onProjectClick:kn}):Ve?n.jsx(q3,{req:Ve,agents:D,projects:N,allTasks:Object.values(z).flat(),users:Y,onClose:ga,onApprove:oe=>{qr(oe)},onReject:oe=>{$t(oe)},onCancel:oe=>{Cs(oe),ga()},onStatusChange:async(oe,Qe)=>{try{await ie.requirements.updateStatus(oe,Qe),Dt(`Requirement status → ${Qe}`),Ss({requirementId:oe}),Ps(),on()}catch(dt){Dt(`Error: ${dt}`)}},scrollToComments:ni,onScrollToCommentsDone:()=>ri(!1),onRefresh:Ps,authUser:e,onTaskClick:oe=>{Fe(oe),u&&(C(!0),history.pushState({mobileDetail:De.WORK},"",window.location.hash))},onCreateTask:(oe,Qe)=>{ht(oe),Qe&&it(Qe),G(!0)},onProjectClick:kn,previewMode:t}):null}),X&&n.jsx(Lre,{orgId:e?.orgId,onCreated:Yn,onClose:()=>ee(!1)}),te&&n.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 p-3",onClick:()=>{G(!1),et("")},children:n.jsxs("div",{className:`bg-surface-secondary border border-border-default rounded-xl p-6 space-y-4 max-h-[90dvh] overflow-y-auto ${u?"w-full":"w-[28rem]"}`,onClick:oe=>oe.stopPropagation(),children:[n.jsx("h3",{className:"text-base font-semibold text-fg-primary",children:s("work:task.newTask")}),n.jsxs("div",{children:[n.jsx("label",{className:"block text-sm text-fg-secondary mb-1.5",children:s("work:task.titleLabel")}),n.jsx("input",{autoFocus:!u,value:ue,onChange:oe=>Se(oe.target.value),onKeyDown:oe=>{oe.key==="Enter"&&va()},className:"w-full px-3 py-2 bg-surface-elevated border border-border-default rounded-lg text-sm focus:border-brand-500 outline-none"})]}),n.jsxs("div",{children:[n.jsx("label",{className:"block text-sm text-fg-secondary mb-1.5",children:s("work:task.descriptionField")}),n.jsx("textarea",{value:Ce,onChange:oe=>Be(oe.target.value),rows:2,className:"w-full px-3 py-2 bg-surface-elevated border border-border-default rounded-lg text-sm focus:border-brand-500 outline-none resize-none"})]}),n.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[n.jsxs("div",{children:[n.jsx("label",{className:"block text-sm text-fg-secondary mb-1.5",children:s("work:task.projectLabel")}),n.jsx(Lu,{options:[{value:"",label:s("work:task.noProject")},...N.map(oe=>({value:oe.id,label:oe.name}))],value:mt,onChange:oe=>{it(oe),ht("")},placeholder:s("work:task.noProject"),noMatchesText:s("work:task.noMatches")})]}),n.jsxs("div",{children:[n.jsx("label",{className:"block text-sm text-fg-secondary mb-1.5",children:s("work:task.requirementLabel")}),n.jsx(Lu,{options:[{value:"",label:s("work:task.selectRequirement")},...L.filter(oe=>oe.status==="in_progress"&&(!mt||oe.projectId===mt)).map(oe=>({value:oe.id,label:oe.title}))],value:Lt,onChange:ht,placeholder:s("work:task.selectRequirement"),noMatchesText:s("work:task.noMatches")})]})]}),n.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[n.jsxs("div",{children:[n.jsxs("label",{className:"block text-sm text-fg-secondary mb-1.5",children:[s("work:task.assignToRequired")," ",n.jsx("span",{className:"text-red-500",children:"*"})]}),n.jsx(Lu,{options:D.map(oe=>({value:oe.id,label:`${oe.name} (${oe.status})`})),value:_e,onChange:Ee,placeholder:s("work:task.selectAgent"),noMatchesText:s("work:task.noMatches")})]}),n.jsxs("div",{children:[n.jsxs("label",{className:"block text-sm text-fg-secondary mb-1.5",children:[s("work:task.reviewerRequired")," ",n.jsx("span",{className:"text-red-500",children:"*"})]}),n.jsx(Lu,{options:[...Y.map(oe=>({value:`human:${oe.id}`,label:oe.name})),...D.filter(oe=>oe.id!==_e).map(oe=>({value:`agent:${oe.id}`,label:`${oe.name} (${oe.status})`}))],value:Ye,onChange:Ze,placeholder:s("work:task.selectReviewer"),noMatchesText:s("work:task.noMatches")})]})]}),n.jsxs("div",{className:`grid gap-4 ${be==="scheduled"?"grid-cols-3":"grid-cols-2"}`,children:[n.jsxs("div",{children:[n.jsx("label",{className:"block text-sm text-fg-secondary mb-1.5",children:s("work:task.priorityField")}),n.jsxs("select",{value:Ne,onChange:oe=>he(oe.target.value),className:"w-full px-3 py-2 bg-surface-elevated border border-border-default rounded-lg text-sm focus:border-brand-500 outline-none",children:[n.jsx("option",{value:"low",children:s("work:priority.low")}),n.jsx("option",{value:"medium",children:s("work:priority.medium")}),n.jsx("option",{value:"high",children:s("work:priority.high")}),n.jsx("option",{value:"urgent",children:s("work:priority.urgent")})]})]}),n.jsxs("div",{children:[n.jsx("label",{className:"block text-sm text-fg-secondary mb-1.5",children:s("work:task.taskType")}),n.jsxs("select",{value:be,onChange:oe=>se(oe.target.value),className:"w-full px-3 py-2 bg-surface-elevated border border-border-default rounded-lg text-sm focus:border-brand-500 outline-none",children:[n.jsx("option",{value:"standard",children:s("work:task.taskTypeStandard")}),n.jsx("option",{value:"scheduled",children:s("work:task.taskTypeScheduled")})]})]}),be==="scheduled"&&n.jsxs("div",{children:[n.jsx("label",{className:"block text-sm text-fg-secondary mb-1.5",children:s("work:task.frequency")}),n.jsxs("select",{value:fe,onChange:oe=>He(oe.target.value),className:"w-full px-3 py-2 bg-surface-elevated border border-border-default rounded-lg text-sm focus:border-brand-500 outline-none",children:[n.jsx("option",{value:"30m",children:s("work:task.freq30m")}),n.jsx("option",{value:"1h",children:s("work:task.freq1h")}),n.jsx("option",{value:"2h",children:s("work:task.freq2h")}),n.jsx("option",{value:"4h",children:s("work:task.freq4h")}),n.jsx("option",{value:"8h",children:s("work:task.freq8h")}),n.jsx("option",{value:"12h",children:s("work:task.freq12h")}),n.jsx("option",{value:"1d",children:s("work:task.freq1d")}),n.jsx("option",{value:"1w",children:s("work:task.freq1w")})]})]})]}),n.jsxs("div",{children:[n.jsx("label",{className:"block text-sm text-fg-secondary mb-1.5",children:s("work:task.blockedBy")}),n.jsx(Pre,{options:Object.values(z).flat().filter(oe=>oe.status!=="completed"&&oe.status!=="cancelled").map(oe=>({value:oe.id,label:oe.title})),selected:ne,onAdd:oe=>me([...ne,oe]),placeholder:s("work:task.selectDependency"),noMatchesText:s("work:task.noMatches")}),ne.length>0&&n.jsx("div",{className:"mt-2 flex flex-wrap gap-1.5",children:ne.map(oe=>{const Qe=Object.values(z).flat().find(dt=>dt.id===oe);return n.jsxs("span",{className:"inline-flex items-center gap-1 text-[11px] px-2 py-1 bg-amber-500/10 text-amber-600 rounded-full",children:[Qe?Qe.title.slice(0,30):oe.slice(-8),n.jsx("button",{onClick:()=>me(ne.filter(dt=>dt!==oe)),className:"ml-0.5 text-amber-600/60 hover:text-amber-600",children:"×"})]},oe)})})]}),Ae&&n.jsx("div",{className:"px-3 py-2 bg-red-500/15 text-red-500 text-xs rounded-lg",children:Ae}),n.jsxs("div",{className:"flex justify-end gap-3 pt-1",children:[n.jsx("button",{onClick:()=>{G(!1),et("")},className:"px-4 py-2 text-sm border border-border-default rounded-lg hover:bg-surface-elevated text-fg-secondary",children:s("common:cancel")}),n.jsx("button",{onClick:()=>{va()},disabled:!ue.trim()||!_e||!Ye,className:"px-4 py-2 text-sm bg-brand-600 hover:bg-brand-500 rounded-lg text-white disabled:opacity-50",children:s("common:create")})]})]})}),Dn&&n.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 p-3",onClick:()=>{$n(!1),Bn(""),Qn(""),ye("")},children:n.jsxs("div",{className:`bg-surface-secondary border border-border-default rounded-xl p-6 space-y-4 max-h-[90dvh] overflow-y-auto ${u?"w-full":"w-[28rem]"}`,onClick:oe=>oe.stopPropagation(),children:[n.jsxs("div",{children:[n.jsx("h3",{className:"text-base font-semibold text-fg-primary",children:s("work:task.newRequirementModalTitle")}),n.jsx("p",{className:"text-xs text-fg-tertiary mt-1",children:s("work:task.newRequirementModalHint")})]}),n.jsxs("div",{children:[n.jsxs("label",{className:"block text-sm text-fg-secondary mb-1.5",children:[s("work:task.projectLabel")," ",n.jsx("span",{className:"text-red-500",children:"*"})]}),n.jsx(Lu,{options:N.map(oe=>({value:oe.id,label:oe.name})),value:ve,onChange:tt,placeholder:s("work:task.selectProject"),noMatchesText:s("work:task.noMatches")})]}),n.jsxs("div",{children:[n.jsxs("label",{className:"block text-sm text-fg-secondary mb-1.5",children:[s("work:task.titleField")," ",n.jsx("span",{className:"text-red-500",children:"*"})]}),n.jsx("input",{value:Sn,onChange:oe=>Bn(oe.target.value),placeholder:s("work:task.reqTitleExample"),className:"w-full px-3 py-2 bg-surface-elevated border border-border-default rounded-lg text-sm text-fg-primary focus:border-brand-500 outline-none",autoFocus:!u,onKeyDown:oe=>{oe.key==="Enter"&&Sn.trim()&&is()}})]}),n.jsxs("div",{children:[n.jsxs("label",{className:"block text-sm text-fg-secondary mb-1.5",children:[s("work:task.descriptionField")," ",n.jsx("span",{className:"text-red-500",children:"*"})]}),n.jsx("textarea",{value:Vn,onChange:oe=>Qn(oe.target.value),placeholder:s("work:task.reqDescPlaceholder"),rows:3,className:"w-full px-3 py-2 bg-surface-elevated border border-border-default rounded-lg text-sm text-fg-primary focus:border-brand-500 outline-none resize-none"})]}),n.jsxs("div",{children:[n.jsx("label",{className:"block text-sm text-fg-secondary mb-1.5",children:s("work:task.priorityField")}),n.jsxs("select",{value:Pe,onChange:oe=>Ct(oe.target.value),className:"w-full px-3 py-2 bg-surface-elevated border border-border-default rounded-lg text-sm text-fg-primary focus:border-brand-500 outline-none",children:[n.jsx("option",{value:"low",children:s("work:priority.low")}),n.jsx("option",{value:"medium",children:s("work:priority.medium")}),n.jsx("option",{value:"high",children:s("work:priority.high")}),n.jsx("option",{value:"urgent",children:s("work:priority.urgent")})]})]}),Xt&&n.jsx("div",{className:"px-3 py-2 bg-red-500/15 text-red-500 text-xs rounded-lg",children:Xt}),n.jsxs("div",{className:"flex justify-end gap-3 pt-1",children:[n.jsx("button",{onClick:()=>{$n(!1),Bn(""),Qn(""),ye("")},className:"px-4 py-2 text-sm border border-border-default rounded-lg hover:bg-surface-elevated text-fg-secondary",children:s("common:cancel")}),n.jsx("button",{onClick:()=>{is()},disabled:!Sn.trim()||!Vn.trim()||!ve,className:"px-4 py-2 text-sm bg-brand-600 hover:bg-brand-500 rounded-lg text-white disabled:opacity-40 disabled:cursor-not-allowed",children:s("common:create")})]})]})}),Tt&&n.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 p-3",onClick:()=>{$t(null),vt("")},children:n.jsxs("div",{className:`bg-surface-secondary border border-border-default rounded-xl p-6 space-y-4 ${u?"w-full":"w-96"}`,onClick:oe=>oe.stopPropagation(),children:[n.jsx("h3",{className:"text-base font-semibold text-fg-primary",children:s("work:task.rejectRequirementTitle")}),n.jsxs("div",{children:[n.jsx("label",{className:"block text-sm text-fg-secondary mb-1.5",children:s("work:task.rejectReasonLabel")}),n.jsx("textarea",{value:sn,onChange:oe=>Zn(oe.target.value),placeholder:s("work:task.rejectReasonPlaceholder"),rows:3,className:"w-full px-3 py-2 bg-surface-elevated border border-border-default rounded-lg text-sm text-fg-primary focus:border-red-500 outline-none resize-none",autoFocus:!u})]}),lt&&n.jsx("div",{className:"px-3 py-2 bg-red-500/15 text-red-500 text-xs rounded-lg",children:lt}),n.jsxs("div",{className:"flex justify-end gap-3",children:[n.jsx("button",{onClick:()=>{$t(null),vt("")},className:"px-4 py-2 text-sm border border-border-default rounded-lg hover:bg-surface-elevated text-fg-secondary",children:s("common:cancel")}),n.jsx("button",{onClick:()=>{ai()},className:"px-4 py-2 text-sm bg-red-600 hover:bg-red-500 rounded-lg text-white",children:s("work:task.reject")})]})]})}),tn&&n.jsxs("div",{className:"fixed inset-0 z-[60] flex flex-col justify-end",onClick:()=>zn(!1),children:[n.jsx("div",{className:"absolute inset-0 bg-black/50"}),n.jsxs("div",{className:"relative bg-surface-secondary rounded-t-2xl border-t border-border-default max-h-[70vh] overflow-y-auto pb-16",onClick:oe=>oe.stopPropagation(),children:[n.jsxs("div",{className:"sticky top-0 bg-surface-secondary z-10 px-4 pt-3 pb-2 flex items-center justify-between border-b border-border-default/60",children:[n.jsx("h3",{className:"text-sm font-semibold text-fg-primary",children:s("work:task.filtersSheetTitle")}),n.jsxs("div",{className:"flex items-center gap-2",children:[(Re.size>0||gt.size>0||Et)&&n.jsx("button",{onClick:()=>{We(new Set),rt(new Set),je(!1)},className:"text-[11px] text-brand-500 font-medium",children:s("work:task.clearAll")}),n.jsx("button",{onClick:()=>zn(!1),className:"w-7 h-7 flex items-center justify-center rounded-full bg-surface-elevated text-fg-tertiary",children:n.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),n.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]})]}),N.length>1&&n.jsxs("div",{className:"px-4 py-3",children:[n.jsx("div",{className:"text-[11px] text-fg-tertiary font-medium uppercase tracking-wider mb-2",children:s("work:task.projectsFilterGroup")}),n.jsx("div",{className:"flex flex-wrap gap-1.5",children:ka.map(oe=>{const Qe=Re.has(oe.id),dt=Ri[oe.id]??0;return n.jsxs("div",{className:`flex items-center rounded-lg overflow-hidden transition-all ${Qe?"bg-brand-500/15 ring-1 ring-brand-500/30":""}`,children:[n.jsxs("button",{onClick:()=>kn(oe.id),className:`flex items-center gap-1.5 px-2.5 py-1.5 text-[11px] transition-all ${Qe?"text-brand-600":"bg-surface-elevated text-fg-secondary"}`,children:[n.jsx("span",{className:`w-4 h-4 rounded-sm flex items-center justify-center text-[9px] font-bold shrink-0 ${Qe?"bg-brand-600 text-white":"bg-surface-overlay text-fg-tertiary"}`,children:oe.name[0]?.toUpperCase()}),oe.name,dt>0&&n.jsx("span",{className:"text-[9px] text-fg-tertiary",children:dt})]}),Qe&&n.jsx("button",{onClick:()=>{zn(!1),nr(oe.id)},className:"px-2 py-1.5 self-stretch flex items-center border-l border-brand-500/20 text-fg-tertiary hover:text-brand-600",title:s("work:project.editProject"),children:n.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("path",{d:"M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"}),n.jsx("path",{d:"M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z"})]})})]},oe.id)})})]}),e?.id&&n.jsx("div",{className:"px-4 py-3 border-t border-border-default/40",children:n.jsx("button",{type:"button",onClick:()=>je(oe=>!oe),className:`w-full text-left px-2.5 py-1.5 rounded-lg text-[11px] transition-all ${Et?"bg-green-600/20 text-green-500 ring-1 ring-green-500/40":"bg-surface-elevated text-fg-secondary"}`,children:s("work:task.myTasks")})}),D.length>0&&n.jsxs("div",{className:"px-4 py-3 border-t border-border-default/40",children:[n.jsx("div",{className:"text-[11px] text-fg-tertiary font-medium uppercase tracking-wider mb-2",children:s("work:task.agentsFilterGroup")}),n.jsx("div",{className:"flex flex-wrap gap-1.5",children:zs.map(oe=>{const Qe=gt.has(oe.id);return n.jsxs("button",{onClick:()=>Or(oe.id),className:`flex items-center gap-1.5 px-2.5 py-1.5 rounded-lg text-[11px] transition-all ${Qe?"bg-brand-600/20 text-brand-500 ring-1 ring-brand-500/40":"bg-surface-elevated text-fg-secondary"}`,children:[n.jsx("span",{className:`w-4 h-4 rounded-full flex items-center justify-center text-[9px] font-bold shrink-0 ${Qe?"bg-brand-600 text-white":"bg-surface-overlay text-fg-tertiary"}`,children:oe.name[0]?.toUpperCase()}),oe.name]},oe.id)})})]}),n.jsx("div",{className:"h-[env(safe-area-inset-bottom,0px)]"})]})]})]})}function ese({requirementId:e,createdBy:t,agents:r,users:s,authUser:a}){const{t:i}=pt(["work","common"]),[l,d]=g.useState([]),[u,m]=g.useState([]),h=g.useRef(null),[p,y]=g.useState(new Map);g.useEffect(()=>{m([]),y(new Map),h.current&&(clearTimeout(h.current),h.current=null),ie.requirements.getComments(e).then(w=>d(w.comments)).catch(()=>{})},[e]),g.useEffect(()=>pn.on("requirement:comment",N=>{if(N.payload?.requirementId===e&&N.payload.comment){const S=N.payload.comment;d(T=>T.some(E=>E.id===S.id)?T:[...T,S]),(S.authorType==="agent"||S.authorId?.startsWith("agt_"))&&(m(T=>{const E=T.filter(R=>R.id!==S.authorId);return E.length===0&&h.current&&(clearTimeout(h.current),h.current=null),E}),y(T=>{const E=new Map(T);return E.delete(S.authorId),E}))}}),[e]),g.useEffect(()=>{if(u.length===0)return;const w=new Set(u.map(S=>S.id));return pn.on("agent:activity_log",S=>{const T=S.payload;if(!T)return;const E=T.agentId;if(!w.has(E))return;const R=T.type;if(R==="tool_start"||R==="tool_end"){const z={tool:T.content??T.metadata?.tool??"",phase:R==="tool_start"?"start":"end",success:R==="tool_end"?T.metadata?.success!==!1:void 0,ts:Date.now()};y(B=>{const D=new Map(B),V=[...D.get(E)??[],z];return D.set(E,V),D})}})},[u]);const[x,v]=g.useState(null),j=async(w,N,S,T)=>{let E;S.length>0&&(E=(await ie.uploads.upload(S.map(D=>({dataUrl:D.dataUrl,name:D.name})),"comments")).files.map(D=>({type:"image",url:D.url,name:D.name}))),await ie.requirements.addComment(e,w,a?.name,E,a?.id,N.length>0?N:void 0,T);const R=[],I=new Set,z=B=>{if(I.has(B)||B===a?.id)return;I.add(B);const D=r.find(V=>V.id===B);D&&R.push({id:D.id,name:D.name,avatarUrl:D.avatarUrl})};for(const B of N){const D=r.find(V=>V.name.toLowerCase()===B.toLowerCase());D&&z(D.id)}t?.startsWith("agt_")&&z(t),R.length>0&&(h.current&&clearTimeout(h.current),m(R),h.current=setTimeout(()=>m([]),12e4))},C=g.useCallback(w=>{v({id:w.id,authorName:w.authorName,content:w.content.slice(0,100)})},[]);return n.jsxs("div",{children:[n.jsx("label",{className:"text-[10px] font-semibold text-fg-tertiary uppercase tracking-wider mb-2 block",children:l.length>0?i("work:task.commentsWithCount",{count:l.length}):i("work:task.comments")}),n.jsxs("div",{className:"space-y-0.5 mb-3",children:[l.length===0&&n.jsx("p",{className:"text-xs text-fg-tertiary text-center py-4",children:i("work:task.noCommentsYet")}),l.map(w=>n.jsx(Ju,{comment:w,agents:r,onReply:C},w.id)),u.length>0&&n.jsx("div",{className:"flex flex-col gap-1.5 pt-1",children:u.map(w=>{const N=p.get(w.id)??[];return n.jsxs("div",{className:"px-2 py-1.5 rounded-lg cursor-pointer hover:bg-surface-elevated/60 transition-colors",onClick:()=>bt.navigate(De.TEAM,{agentId:w.id,profileTab:"mind"}),children:[n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsxs("div",{className:"relative shrink-0",children:[n.jsx(Nr,{name:w.name,avatarUrl:w.avatarUrl,size:22,bgClass:"bg-brand-500/15 text-brand-600"}),n.jsx("span",{className:"absolute -bottom-0.5 -right-0.5 w-2 h-2 rounded-full bg-blue-500 animate-pulse ring-2 ring-surface-primary"})]}),n.jsx("span",{className:"text-xs font-medium text-fg-secondary",children:w.name}),N.length===0&&n.jsxs("span",{className:"flex items-center gap-0.5",children:[n.jsx("span",{className:"w-1 h-1 rounded-full bg-blue-400 animate-bounce"}),n.jsx("span",{className:"w-1 h-1 rounded-full bg-blue-400 animate-bounce",style:{animationDelay:"0.15s"}}),n.jsx("span",{className:"w-1 h-1 rounded-full bg-blue-400 animate-bounce",style:{animationDelay:"0.3s"}})]}),n.jsx("span",{className:"text-[10px] text-fg-tertiary",children:i("work:task.agentProcessing")}),n.jsx("span",{className:"ml-auto text-[10px] text-fg-tertiary",children:"→"})]}),N.length>0&&n.jsx("div",{className:"ml-8 mt-1",children:n.jsx(Wh,{activities:N,isActive:!0})})]},w.id)})})]}),n.jsx($S,{agents:r,humans:s,onSubmit:j,replyTo:x,onCancelReply:()=>v(null)})]})}function q3({req:e,agents:t,projects:r,allTasks:s,users:a,onClose:i,onApprove:l,onReject:d,onCancel:u,onStatusChange:m,onRefresh:h,authUser:p,scrollToComments:y,onScrollToCommentsDone:x,onTaskClick:v,onCreateTask:j,onProjectClick:C,previewMode:w}){const{t:N}=pt(["work","common"]),S=g.useMemo(()=>Iy(N),[N]),T=g.useMemo(()=>tC(N),[N]),E=Rs(),[R,I]=g.useState(!1),[z,B]=g.useState(e.description),[D,V]=g.useState(!1),[Y,F]=g.useState(!1),L=g.useRef(null),[O,M]=g.useState("none"),$=g.useRef(null),W=g.useRef(null),U=g.useRef(80);g.useEffect(()=>{const G=L.current;if(!G)return;const ue=()=>{const{scrollTop:Ce,scrollHeight:Be,clientHeight:Ne}=G;if(!(Be>Ne+50)){M("none");return}const _e=Ce<30,Ee=Ce+Ne>=Be-30;M(_e?"top":Ee?"bottom":"middle")};ue(),G.addEventListener("scroll",ue,{passive:!0});const Se=new ResizeObserver(ue);return Se.observe(G),()=>{G.removeEventListener("scroll",ue),Se.disconnect()}},[]),g.useEffect(()=>{if(R&&W.current){const G=W.current;G.style.height="auto",G.style.height=Math.max(G.scrollHeight,U.current)+"px",G.focus()}},[R]),g.useEffect(()=>{if(!y)return;const G=setTimeout(()=>{const ue=L.current;ue&&ue.scrollTo({top:ue.scrollHeight,behavior:"smooth"}),x?.()},300);return()=>clearTimeout(G)},[y,x]);const H=S[e.status]??{label:e.status,cls:"bg-gray-500/15 text-fg-secondary"},q=e.source==="agent",Z=q&&e.status==="pending",_=e.status==="pending"||e.status==="in_progress",J=e.status==="completed"||e.status==="rejected"||e.status==="cancelled"||e.status==="archived",X=e.projectId?r.find(G=>G.id===e.projectId):null,ee=Rd(e.createdBy,t,a)??e.createdBy.slice(0,12),te=s.filter(G=>e.taskIds.includes(G.id));return g.useEffect(()=>{B(e.description),I(!1)},[e.id,e.description]),n.jsxs("div",{className:"flex flex-col w-full h-full overflow-hidden bg-surface-primary shadow-xl shadow-black/8 ring-1 ring-border-default/20",children:[n.jsxs("div",{className:"flex items-start justify-between gap-4 p-5 pb-0 border-b border-border-default",children:[n.jsxs("div",{className:"flex items-center gap-2 flex-1 min-w-0",children:[E&&n.jsx("button",{onClick:()=>history.back(),className:"text-fg-secondary hover:text-fg-primary transition-colors p-1 -ml-1 shrink-0",children:n.jsx("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:n.jsx("polyline",{points:"15 18 9 12 15 6"})})}),n.jsxs("h2",{className:"flex-1 min-w-0 pb-4 text-lg font-semibold text-fg-primary leading-snug",children:[e.title," ",n.jsx("span",{className:"text-[10px] font-bold text-brand-500 bg-brand-500/15 px-2 py-0.5 rounded align-middle",children:N("work:task.requirementShort")})," ",n.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded-full font-medium align-middle ${H.cls}`,children:H.label})," ",e.priority==="high"||e.priority==="urgent"?n.jsx("span",{className:`text-[10px] font-medium align-middle ${e.priority==="urgent"?"text-red-500":"text-amber-600"}`,children:N("common:priority."+e.priority,{defaultValue:e.priority})}):n.jsx("span",{className:"text-[10px] text-fg-tertiary align-middle",children:N("common:priority."+e.priority,{defaultValue:e.priority})})]})]}),n.jsx("button",{onClick:i,className:"text-fg-tertiary hover:text-fg-secondary text-xl leading-none shrink-0 mt-1",children:"×"})]}),n.jsxs("div",{className:"flex-1 min-h-0 relative",children:[n.jsxs("div",{ref:L,className:"h-full overflow-y-auto p-5 space-y-4",children:[n.jsxs("div",{children:[n.jsx("label",{className:"text-[10px] font-semibold text-fg-tertiary uppercase tracking-wider mb-1 block",children:N("work:task.requirementDetailDescription")}),R?n.jsx("textarea",{ref:W,value:z,onChange:G=>{B(G.target.value);const ue=G.target;ue.style.height="auto",ue.style.height=ue.scrollHeight+"px"},onBlur:async()=>{if(z!==e.description){V(!0);try{await ie.requirements.update(e.id,{description:z}),h?.()}catch{}finally{V(!1)}}I(!1)},onKeyDown:G=>{G.key==="Escape"&&(G.preventDefault(),B(e.description),I(!1))},className:"w-full bg-transparent border border-brand-500/30 rounded-lg text-sm text-fg-primary focus:border-brand-500 outline-none resize-none -mx-2 px-2 -my-1 py-1",placeholder:N("work:task.requirementDetailDescription")}):n.jsx("div",{ref:$,className:`group relative rounded-lg -mx-2 px-2 -my-1 py-1 transition-colors ${J?"":"cursor-pointer hover:bg-surface-elevated/50"}`,onClick:J?void 0:G=>{G.target.closest("a, button, [data-entity-link]")||(U.current=Math.max($.current?.offsetHeight??80,60),B(e.description),I(!0))},role:J?void 0:"button",tabIndex:J?void 0:0,onKeyDown:J?void 0:G=>G.key==="Enter"&&(B(e.description),I(!0)),children:e.description?n.jsx(Wr,{content:e.description,className:"text-sm text-fg-secondary leading-relaxed"}):n.jsx("p",{className:"text-sm text-fg-tertiary italic",children:N("work:task.requirementNoDescription")})})]}),n.jsxs("div",{className:"grid grid-cols-2 gap-3 text-xs",children:[n.jsxs("div",{className:"bg-surface-elevated/60 rounded-lg p-2.5",children:[n.jsx("span",{className:"text-[10px] text-fg-tertiary block mb-1",children:N("work:task.createdByLabel")}),n.jsx("span",{className:"text-fg-secondary",children:ee}),q&&n.jsx("span",{className:"text-[10px] text-brand-500 ml-1.5",children:N("work:task.agentTag")})]}),n.jsxs("div",{className:"bg-surface-elevated/60 rounded-lg p-2.5",children:[n.jsx("span",{className:"text-[10px] text-fg-tertiary block mb-1",children:N("work:task.createdLabel")}),n.jsx("span",{className:"text-fg-secondary",children:new Date(e.createdAt).toLocaleString()})]}),X&&n.jsxs("div",{className:`bg-surface-elevated/60 rounded-lg p-2.5 ${C?"cursor-pointer hover:bg-surface-elevated transition-colors":""}`,onClick:C?()=>C(X.id):void 0,role:C?"button":void 0,tabIndex:C?0:void 0,onKeyDown:C?G=>G.key==="Enter"&&C(X.id):void 0,children:[n.jsx("span",{className:"text-[10px] text-fg-tertiary block mb-1",children:N("work:task.projectLabel")}),n.jsx("span",{className:"text-fg-secondary",children:X.name})]}),e.approvedBy&&n.jsxs("div",{className:"bg-surface-elevated/60 rounded-lg p-2.5",children:[n.jsx("span",{className:"text-[10px] text-fg-tertiary block mb-1",children:N("work:task.approvedBy")}),n.jsx("span",{className:"text-fg-secondary",children:Rd(e.approvedBy,t,a)??e.approvedBy.slice(0,12)}),e.approvedAt&&n.jsx("span",{className:"text-[10px] text-fg-tertiary ml-1",children:new Date(e.approvedAt).toLocaleDateString()})]})]}),e.rejectedReason&&n.jsxs("div",{className:"bg-red-500/10 border border-red-500/20 rounded-lg p-3",children:[n.jsx("span",{className:"text-[10px] font-semibold text-red-500 uppercase tracking-wider block mb-1",children:N("work:task.rejectionReason")}),n.jsx("p",{className:"text-sm text-red-500/80",children:e.rejectedReason})]}),Array.isArray(e.tags)&&e.tags.length>0&&n.jsx("div",{className:"flex flex-wrap gap-1",children:e.tags.map(G=>n.jsxs("span",{className:"text-[10px] bg-surface-elevated text-fg-secondary px-2 py-0.5 rounded-full",children:["#",G]},G))}),n.jsxs("div",{children:[n.jsxs("div",{className:"flex items-center justify-between mb-2",children:[n.jsx("label",{className:"text-[10px] font-semibold text-fg-tertiary uppercase tracking-wider",children:N("work:task.linkedTasks",{count:te.length})}),!J&&j&&n.jsxs("button",{onClick:()=>j(e.id,e.projectId),className:"text-[11px] text-amber-500 hover:text-amber-400 font-medium flex items-center gap-1",children:[n.jsx("svg",{className:"w-3 h-3",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:n.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 4v16m8-8H4"})}),N("work:requirement.createTask")]})]}),te.length>0?(()=>{const G=new Map(te.map(he=>[he.id,he]));if(!te.some(he=>he.blockedBy?.some(_e=>G.has(_e))))return n.jsx("div",{className:"space-y-1.5",children:te.map(he=>{const _e=T[he.status];return n.jsxs("div",{onClick:()=>v?.(he),className:`flex items-center gap-2 bg-surface-elevated/60 rounded-lg px-3 py-2 ${v?"cursor-pointer hover:bg-surface-elevated transition-colors":""}`,children:[n.jsx("span",{className:`w-1.5 h-1.5 rounded-full shrink-0 ${j0[he.status]??"bg-gray-500"}`}),n.jsx("span",{className:"text-xs text-fg-secondary flex-1 truncate",children:he.title}),_e&&n.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded shrink-0 ${_e.cls}`,children:_e.label})]},he.id)})});const Se=new Map,Ce=new Set;for(const he of te)for(const _e of he.blockedBy??[])if(G.has(_e)){Ce.add(he.id);const Ee=Se.get(_e)??[];Ee.push(he.id),Se.set(_e,Ee)}const Be=te.filter(he=>!Ce.has(he.id)),Ne=(he,_e)=>{const Ee=T[he.status],Ye=(Se.get(he.id)??[]).map(Ze=>G.get(Ze)).filter(Boolean);return n.jsxs("div",{children:[n.jsxs("div",{onClick:()=>v?.(he),className:`flex items-center gap-2 bg-surface-elevated/60 rounded-lg px-3 py-2 ${v?"cursor-pointer hover:bg-surface-elevated transition-colors":""}`,style:_e>0?{marginLeft:_e*20}:void 0,children:[_e>0&&n.jsx("span",{className:"text-fg-quaternary text-[10px] shrink-0",children:"↳"}),n.jsx("span",{className:`w-1.5 h-1.5 rounded-full shrink-0 ${j0[he.status]??"bg-gray-500"}`}),n.jsx("span",{className:"text-xs text-fg-secondary flex-1 truncate",children:he.title}),Ee&&n.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded shrink-0 ${Ee.cls}`,children:Ee.label})]}),Ye.map(Ze=>Ne(Ze,_e+1))]},he.id)};return n.jsx("div",{className:"space-y-1.5",children:Be.map(he=>Ne(he,0))})})():n.jsx("div",{className:"text-xs text-fg-tertiary italic py-2",children:N("work:requirement.noLinkedTasks")})]}),!w&&n.jsx(ese,{requirementId:e.id,createdBy:e.createdBy,agents:t,users:a,authUser:p}),!w&&n.jsx(sC,{entityType:"requirement",entityId:e.id})]}),O!=="none"&&O!=="top"&&n.jsx("button",{onClick:()=>L.current?.scrollTo({top:0,behavior:"smooth"}),className:"absolute bottom-20 right-4 md:bottom-14 md:right-3 z-10 w-12 h-12 md:w-8 md:h-8 rounded-full bg-brand-500 md:bg-brand-600/90 border border-brand-400/60 shadow-xl shadow-brand-500/30 md:shadow-lg md:shadow-brand-500/20 flex items-center justify-center text-white hover:bg-brand-400 transition-colors backdrop-blur-sm",title:N("work:task.scrollToTop"),children:n.jsx("svg",{className:"w-6 h-6 md:w-4 md:h-4",viewBox:"0 0 20 20",fill:"currentColor",children:n.jsx("path",{fillRule:"evenodd",d:"M14.77 12.79a.75.75 0 01-1.06-.02L10 8.832l-3.71 3.938a.75.75 0 11-1.08-1.04l4.25-4.5a.75.75 0 011.08 0l4.25 4.5a.75.75 0 01-.02 1.06z",clipRule:"evenodd"})})}),O!=="none"&&O!=="bottom"&&n.jsx("button",{onClick:()=>{const G=L.current;G&&G.scrollTo({top:G.scrollHeight,behavior:"smooth"})},className:"absolute bottom-6 right-4 md:bottom-4 md:right-3 z-10 w-12 h-12 md:w-8 md:h-8 rounded-full bg-brand-500 md:bg-brand-600/90 border border-brand-400/60 shadow-xl shadow-brand-500/30 md:shadow-lg md:shadow-brand-500/20 flex items-center justify-center text-white hover:bg-brand-400 transition-colors backdrop-blur-sm",title:N("work:task.scrollToBottom"),children:n.jsx("svg",{className:"w-6 h-6 md:w-4 md:h-4",viewBox:"0 0 20 20",fill:"currentColor",children:n.jsx("path",{fillRule:"evenodd",d:"M5.23 7.21a.75.75 0 011.06.02L10 11.168l3.71-3.938a.75.75 0 111.08 1.04l-4.25 4.5a.75.75 0 01-1.08 0l-4.25-4.5a.75.75 0 01.02-1.06z",clipRule:"evenodd"})})})]}),n.jsxs("div",{className:"flex items-center gap-2 p-5 pt-3 border-t border-border-default",children:[Z&&n.jsxs(n.Fragment,{children:[n.jsx("button",{onClick:()=>l(e.id),className:"px-4 py-2 bg-green-600 hover:bg-green-500 text-white text-sm rounded-lg font-medium transition-colors",children:N("work:requirement.approveRequirement")}),n.jsx("button",{onClick:()=>d(e.id),className:"px-4 py-2 border border-red-500/30 hover:bg-red-500/10 text-red-500 text-sm rounded-lg font-medium transition-colors",children:N("work:requirement.rejectRequirement")})]}),!Z&&m&&!J&&n.jsx("select",{value:e.status,onChange:G=>{G.target.value!==e.status&&m(e.id,G.target.value)},className:"px-2 py-1.5 text-xs bg-surface-elevated border border-border-default rounded-lg text-fg-secondary cursor-pointer hover:border-gray-500 transition-colors",children:Qre.map(G=>{const ue=S[G],Se=G===e.status||(y1[e.status]?.has(G)??!1);return n.jsx("option",{value:G,disabled:!Se,children:ue?.label??G},G)})}),J&&m&&n.jsx("button",{onClick:()=>m(e.id,"in_progress"),className:"px-3 py-1.5 text-xs border border-border-default hover:bg-surface-elevated rounded-lg text-fg-secondary transition-colors",children:N("work:task.reopen")}),n.jsx("div",{className:"flex-1"}),_&&!Z&&n.jsx("button",{onClick:()=>F(!0),className:"px-3 py-1.5 text-xs text-red-500/70 hover:text-red-500 hover:bg-red-500/10 border border-transparent hover:border-red-500/20 rounded-lg transition-colors",children:N("work:task.cancelRequirement")})]}),Y&&n.jsx(ud,{title:N("work:requirement.cancelConfirmTitle","Cancel Requirement"),message:N("work:requirement.cancelConfirmMessage","Are you sure you want to cancel this requirement? This action cannot be undone."),confirmLabel:N("work:requirement.cancelConfirmLabel","Cancel Requirement"),onConfirm:()=>{F(!1),u(e.id)},onCancel:()=>F(!1)})]})}function sC({entityType:e,entityId:t}){const{t:r}=pt(["work"]),[s,a]=g.useState([]),[i,l]=g.useState(!0),[d,u]=g.useState(!1);if(g.useEffect(()=>{l(!0),(e==="task"?ie.tasks.getHistory:ie.requirements.getHistory)(t).then(x=>a(x.history)).catch(()=>a([])).finally(()=>l(!1))},[e,t]),i)return n.jsx("div",{className:"px-6 py-4 text-xs text-fg-tertiary",children:r("work:task.loadingHistory","Loading history...")});if(s.length===0)return n.jsx("div",{className:"px-6 py-4 text-xs text-fg-tertiary italic",children:r("work:task.noHistory","No status change history.")});const m=d?s:s.slice(-5),h=s.length>5&&!d,p=y=>{const x=y.changedByName||y.changedById||(y.changedByType==="human"?"User":y.changedByType==="agent"?"Agent":"System"),v=y.changedByType==="human"?"bg-blue-500/20 text-blue-500":y.changedByType==="agent"?"bg-brand-500/20 text-brand-500":"bg-gray-500/20 text-fg-tertiary";return n.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded-full font-medium shrink-0 ${v}`,children:x})};return n.jsxs("div",{className:"px-6 py-4",children:[n.jsx("p",{className:"text-xs font-semibold text-fg-tertiary uppercase tracking-wider mb-3",children:r("work:task.statusHistory","Status History")}),h&&n.jsx("button",{onClick:()=>u(!0),className:"text-[11px] text-brand-500 hover:underline mb-2",children:r("work:task.showAllHistory",{count:s.length})}),n.jsxs("div",{className:"relative ml-2",children:[n.jsx("div",{className:"absolute left-[2.5px] top-1 bottom-1 w-px bg-border-default"}),n.jsx("div",{className:"space-y-3",children:m.map(y=>n.jsxs("div",{className:"flex items-start gap-3 relative",children:[n.jsx("div",{className:"w-1.5 h-1.5 rounded-full mt-[7px] shrink-0 relative z-10",style:{background:y.changedByType==="human"?"#3b82f6":y.changedByType==="agent"?"var(--color-brand-500)":"#6b7280"}}),n.jsxs("div",{className:"flex-1 min-w-0",children:[n.jsxs("div",{className:"flex items-center gap-1.5 flex-wrap",children:[p(y),n.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded bg-surface-elevated text-fg-tertiary line-through",children:y.fromStatus}),n.jsx("span",{className:"text-[10px] text-fg-tertiary",children:"→"}),n.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded bg-brand-500/15 text-brand-500 font-medium",children:y.toStatus})]}),y.reason&&n.jsx("p",{className:"text-[10px] text-fg-secondary mt-0.5 leading-snug",children:y.reason}),n.jsx("p",{className:"text-[9px] text-fg-tertiary mt-0.5",children:new Date(y.createdAt).toLocaleString()})]})]},y.id))})]})]})}function Hi(e){return Array.isArray(e)?e.map(t=>String(t).trim()).filter(Boolean):typeof e=="string"&&e?e.split(",").map(t=>t.trim()).filter(Boolean):[]}function tse(e){return e.files&&typeof e.files=="object"&&!Array.isArray(e.files)?e.files:null}function Ql({label:e,value:t}){return t?n.jsxs("div",{children:[n.jsx("span",{className:"text-[10px] text-fg-tertiary uppercase tracking-wider",children:e}),n.jsx("div",{className:"text-xs text-fg-secondary mt-0.5",children:t})]}):null}function sd({label:e,value:t,color:r}){if(!t)return null;const s={purple:"bg-brand-500/15 text-brand-500",cyan:"bg-blue-500/15 text-blue-600",indigo:"bg-brand-500/15 text-brand-500",gray:"bg-gray-500/15 text-fg-secondary",emerald:"bg-green-500/15 text-green-600"};return n.jsxs("div",{children:[n.jsx("span",{className:"text-[10px] text-fg-tertiary uppercase tracking-wider",children:e}),n.jsx("div",{className:`mt-0.5 px-2 py-0.5 rounded-full text-[10px] font-medium ${s[r]??s.gray} capitalize inline-block`,children:t})]})}function lb({files:e}){const{t}=pt(["builder","common"]),[r,s]=g.useState(Object.keys(e)[0]??""),a=Object.keys(e);return a.length===0?null:n.jsxs("div",{children:[n.jsx("span",{className:"text-[10px] text-fg-tertiary uppercase tracking-wider",children:t("builder:artifact.files",{count:a.length})}),n.jsxs("div",{className:"mt-1 bg-surface-elevated/50 rounded-lg border border-border-default/30 overflow-hidden",children:[n.jsx("div",{className:"flex gap-0.5 px-1.5 py-1 border-b border-border-default/30 overflow-x-auto",children:a.map(i=>n.jsx("button",{onClick:()=>s(i),className:`px-2 py-0.5 text-[10px] rounded whitespace-nowrap transition-colors ${r===i?"bg-brand-600/30 text-brand-500":"text-fg-tertiary hover:text-fg-secondary"}`,children:i},i))}),r&&e[r]!=null&&n.jsx("pre",{className:"p-2 text-[10px] text-fg-secondary max-h-[120px] overflow-auto whitespace-pre-wrap font-mono",children:e[r]})]})]})}function nse({artifact:e,mode:t}){const{t:r}=pt(["builder","common"]),s=tse(e),a=e.agent,i=e.team,l=e.dependencies,d=e.displayName??e.name;if(t==="agent"){const u=a?.roleName,m=a?.agentRole,h=a?.llmProvider,p=a?.llmModel,y=Hi(l?.env),x=Hi(l?.skills);return n.jsxs("div",{className:"space-y-3 text-sm",children:[n.jsx(Ql,{label:r("builder:artifact.name"),value:d}),n.jsx(Ql,{label:r("builder:artifact.description"),value:e.description}),n.jsxs("div",{className:"flex flex-wrap gap-2",children:[u&&n.jsx(sd,{label:r("builder:artifact.baseTemplate"),value:u,color:"indigo"}),n.jsx(sd,{label:r("builder:artifact.agentRole"),value:m,color:m==="manager"?"purple":"cyan"})]}),Hi(e.tags).length>0&&n.jsx("div",{className:"flex flex-wrap gap-1",children:Hi(e.tags).map(v=>n.jsx("span",{className:"px-1.5 py-0.5 text-[10px] bg-surface-elevated text-fg-tertiary rounded",children:v},v))}),(h||p)&&n.jsxs("div",{className:"flex gap-2",children:[h&&n.jsx(sd,{label:r("builder:artifact.llmProvider"),value:h,color:"gray"}),p&&n.jsx(sd,{label:r("builder:artifact.llmModel"),value:p,color:"gray"})]}),y.length>0&&n.jsxs("div",{children:[n.jsx("span",{className:"text-[10px] text-fg-tertiary uppercase tracking-wider",children:r("builder:artifact.requiredEnv")}),n.jsx("div",{className:"flex flex-wrap gap-1 mt-1",children:y.map(v=>n.jsx("span",{className:"px-1.5 py-0.5 text-[10px] bg-amber-500/10 text-amber-600 rounded font-mono",children:v},v))})]}),x.length>0&&n.jsx(Ql,{label:r("builder:artifact.skills"),value:x.join(", ")}),s&&n.jsx(lb,{files:s})]})}if(t==="team"){const m=i?.members??[];return n.jsxs("div",{className:"space-y-3 text-sm",children:[n.jsx(Ql,{label:r("builder:artifact.name"),value:d}),n.jsx(Ql,{label:r("builder:artifact.description"),value:e.description}),n.jsx("div",{className:"flex flex-wrap gap-2",children:n.jsx(sd,{label:r("builder:artifact.category"),value:e.category,color:"indigo"})}),Hi(e.tags).length>0&&n.jsx("div",{className:"flex flex-wrap gap-1",children:Hi(e.tags).map(h=>n.jsx("span",{className:"px-1.5 py-0.5 text-[10px] bg-surface-elevated text-fg-tertiary rounded",children:h},h))}),s&&n.jsx(lb,{files:s}),n.jsxs("div",{children:[n.jsx("span",{className:"text-[10px] text-fg-tertiary uppercase tracking-wider",children:r("builder:artifact.members",{count:m.length})}),n.jsx("div",{className:"mt-1.5 space-y-1.5",children:m.map((h,p)=>n.jsxs("div",{className:"bg-surface-elevated/30 rounded-lg px-2 py-1.5 border border-border-default/20",children:[n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx("span",{className:`w-5 h-5 rounded flex items-center justify-center text-[10px] font-bold ${h.role==="manager"?"bg-brand-500/20 text-brand-500":"bg-blue-500/20 text-blue-600"}`,children:h.role==="manager"?"★":p+1}),n.jsx("span",{className:"text-xs text-fg-secondary flex-1 truncate",children:h.name}),typeof h.roleName=="string"&&h.roleName&&n.jsx("span",{className:"text-[10px] text-brand-500/70 font-mono",children:h.roleName}),n.jsxs("span",{className:"text-[10px] text-fg-tertiary",children:["x",String(h.count??1)]})]}),Hi(h.skills).length>0&&n.jsx("div",{className:"mt-1 ml-7 flex flex-wrap gap-1",children:Hi(h.skills).map(y=>n.jsx("span",{className:"px-1 py-0.5 text-[9px] bg-green-500/10 text-green-600 rounded font-mono",children:y},y))})]},p))})]})]})}return n.jsxs("div",{className:"space-y-3 text-sm",children:[n.jsx(Ql,{label:r("builder:artifact.name"),value:d}),n.jsx(Ql,{label:r("builder:artifact.description"),value:e.description}),n.jsx("div",{className:"flex gap-2",children:n.jsx(sd,{label:r("builder:artifact.category"),value:e.category,color:"indigo"})}),s&&n.jsx(lb,{files:s}),Hi(e.tags).length>0&&n.jsx("div",{className:"flex flex-wrap gap-1",children:Hi(e.tags).map(u=>n.jsx("span",{className:"px-1.5 py-0.5 text-[10px] bg-surface-elevated text-fg-tertiary rounded",children:u},u))})]})}const Pu={file:{icon:"📄",color:"bg-green-500/10 text-green-600"},directory:{icon:"📁",color:"bg-blue-500/10 text-blue-600"}},rse={active:{color:"text-green-600 bg-green-500/10"},verified:{color:"text-blue-600 bg-blue-500/10"},outdated:{color:"text-red-500 bg-red-500/10"}},sse=["file","directory"];function Tf(e){return/^https?:\/\//i.test(e)}const Zl={agent:{icon:"✦",color:"bg-brand-500/10 text-brand-500"},team:{icon:"◈",color:"bg-blue-500/10 text-blue-600"},skill:{icon:"⬡",color:"bg-amber-500/10 text-amber-600"}};function U3({authUser:e,previewMode:t,previewData:r}={}){const{t:s}=pt(["deliverables","common"]),a=Rs(),i=Id(De.DELIVERABLES),l=f0({side:"left",defaultWidth:384,minWidth:280,maxWidth:600,storageKey:"markus_deliverables_list"}),[d,u]=g.useState(!1),m=g.useRef(d);m.current=d,g.useEffect(()=>{if(!a)return;const Ge=()=>{m.current&&u(!1)};return window.addEventListener("popstate",Ge),()=>window.removeEventListener("popstate",Ge)},[a]);const h=100,[p,y]=g.useState(r?.items??[]),[x,v]=g.useState(r?.items?.length??0),[j,C]=g.useState(!1),[w,N]=g.useState(r?.projects??[]),[S,T]=g.useState(r?.agents??[]),[E,R]=g.useState(!r),[I,z]=g.useState(""),[B,D]=g.useState(""),[V,Y]=g.useState(""),[F,L]=g.useState(""),[O,M]=g.useState(""),[$,W]=g.useState(""),[U,H]=g.useState(""),[q,Z]=g.useState("date"),[_,J]=g.useState(()=>r?.initialSelectedId&&r.items?r.items.find(Ge=>Ge.id===r.initialSelectedId)??r.items[0]??null:r?.items?.[0]??null),[X,ee]=g.useState(null),[te,G]=g.useState(""),[ue,Se]=g.useState(new Set),Ce=g.useMemo(()=>[{id:"date"},{id:"project"},{id:"agent"},{id:"type"}],[]),Be=g.useCallback(Ge=>{Z(Ge),Se(new Set)},[]),Ne=Sl(Ce,q,Be),he=g.useRef(null),[_e,Ee]=g.useState(null),[Ye,Ze]=g.useState("markdown"),[mt,it]=g.useState(null),[Lt,ht]=g.useState(!1),[ne,me]=g.useState(!1),[be,se]=g.useState(!1),[fe,He]=g.useState(null),[Ae,et]=g.useState(""),[pe,Fe]=g.useState(new Set),Ve=g.useRef(void 0),nt=(Ge,Ht)=>{ee({type:Ge,text:Ht}),setTimeout(()=>ee(null),3e3)},gt=async Ge=>{await iy(Ge)?(se(!0),setTimeout(()=>se(!1),1500)):nt("error",s("detail.copyFailed"))},rt=g.useMemo(()=>new Map(S.map(Ge=>[Ge.id,Ge])),[S]),Et=g.useMemo(()=>new Map(w.map(Ge=>[Ge.id,Ge])),[w]),je=g.useCallback(Ge=>{if(!Ge||Ge==="default")return null;const Ht=Et.get(Ge)?.name;return!Ht||Ht==="default"?null:Ht},[Et]);g.useEffect(()=>{t||(ie.projects.list().then(Ge=>N(Ge.projects)).catch(()=>{}),ie.agents.list().then(Ge=>T(Ge.agents??[])).catch(()=>{}),ie.system.storage().then(Ge=>et(Ge.dataDir+"/shared")).catch(()=>{}),ie.deliverables.checkHealth().then(Ge=>Fe(new Set(Ge.missingFiles))).catch(()=>{}))},[t]),g.useEffect(()=>(Ve.current=setTimeout(()=>D(I),300),()=>clearTimeout(Ve.current)),[I]);const Re=g.useMemo(()=>({q:B||void 0,projectId:F||void 0,agentId:O||void 0,type:V||void 0,status:$||void 0,artifactType:U||void 0}),[B,F,O,V,$,U]),We=g.useCallback(async()=>{R(!0);try{const{results:Ge,total:Ht}=await ie.deliverables.search({...Re,offset:0,limit:h});y(Ge),v(Ht)}catch{y([]),v(0)}R(!1)},[Re]),Vt=g.useCallback(async()=>{if(!(j||p.length>=x)){C(!0);try{const{results:Ge,total:Ht}=await ie.deliverables.search({...Re,offset:p.length,limit:h});y(Wt=>[...Wt,...Ge]),v(Ht)}catch{}C(!1)}},[Re,p.length,x,j]);g.useEffect(()=>{t||We()},[We,t]),g.useEffect(()=>{!t||!r||(y(r.items??[]),v(r.items?.length??0),N(r.projects??[]),T(r.agents??[]),r.initialSelectedId&&J(r.items?.find(Ge=>Ge.id===r.initialSelectedId)??r.items?.[0]??null))},[t,r]),g.useEffect(()=>{if(t||!i)return;const Ge=pn.on("deliverable:created",()=>We()),Ht=pn.on("deliverable:updated",()=>We()),Wt=pn.on("deliverable:removed",()=>We());return()=>{Ge(),Ht(),Wt()}},[We,i,t]);const ln=g.useRef(null),en=g.useRef(p);en.current=p;const vn=g.useCallback(Ge=>{const Ht=tn=>{J(tn),a&&(u(!0),history.pushState({mobileDetail:De.DELIVERABLES},"",window.location.hash))},Wt=en.current.find(tn=>tn.id===Ge);if(Wt){Ht(Wt);return}ie.deliverables.get(Ge).then(tn=>{tn.deliverable&&Ht(tn.deliverable)}).catch(()=>{})},[a]);g.useEffect(()=>{if(t)return;const Ge=localStorage.getItem("markus_nav_openDeliverable");Ge&&(localStorage.removeItem("markus_nav_openDeliverable"),en.current.length>0?vn(Ge):ln.current=Ge);const Ht=Wt=>{const tn=Wt.detail;tn?.params?.openDeliverable&&(localStorage.removeItem("markus_nav_openDeliverable"),vn(tn.params.openDeliverable))};return window.addEventListener("markus:navigate",Ht),()=>window.removeEventListener("markus:navigate",Ht)},[vn,t]),g.useEffect(()=>{const Ge=ln.current;!Ge||p.length===0||(ln.current=null,vn(Ge))},[p,vn]);const In=g.useCallback(()=>{const Ge=he.current;!Ge||E||j||p.length>=x||Ge.scrollHeight<=Ge.clientHeight+100&&Vt()},[E,j,p.length,x,Vt]);g.useEffect(()=>{const Ge=he.current;if(!Ge)return;const Ht=()=>{Ge.scrollTop+Ge.clientHeight>=Ge.scrollHeight-100&&Vt()};return Ge.addEventListener("scroll",Ht,{passive:!0}),()=>Ge.removeEventListener("scroll",Ht)},[Vt]),g.useEffect(()=>{In()},[In,ue]);const Zt=g.useMemo(()=>{const Ge=new Map;for(const Wt of p){let tn,zn;if(q==="project"){const Mn=je(Wt.projectId);tn=Mn?Wt.projectId??"_none":"_none",zn=Mn??s("noProject")}else if(q==="agent")tn=Wt.agentId??"_none",zn=Wt.agentId?rt.get(Wt.agentId)?.name??Wt.agentId:s("common:unknown");else if(q==="type")tn=Wt.type,zn=Wt.type.charAt(0).toUpperCase()+Wt.type.slice(1);else{const Mn=new Date(Wt.updatedAt);tn=`${Mn.getFullYear()}-${String(Mn.getMonth()+1).padStart(2,"0")}-${String(Mn.getDate()).padStart(2,"0")}`,zn=tn}Ge.has(tn)||Ge.set(tn,{label:zn,items:[]}),Ge.get(tn).items.push(Wt)}const Ht=[...Ge.entries()];return q==="date"?Ht.sort((Wt,tn)=>tn[0].localeCompare(Wt[0])):Ht.sort((Wt,tn)=>Wt[1].label.localeCompare(tn[1].label)),Ht},[p,q,Et,rt,s]),cn=async Ge=>{G("remove");try{await ie.deliverables.remove(Ge.id),nt("success",s("removed")),J(null),We()}catch(Ht){nt("error",s("common:error",{message:String(Ht)}))}G("")},Gn=()=>{bt.navigate(De.BUILDER)},Ln=async Ge=>{if(Ge.reference&&!Tf(Ge.reference)){if(Ge.type==="directory"){me(!0);return}ht(!0);try{const Ht=await ie.files.preview(Ge.reference);Ht.type==="image"&&Ht.mimeType?it({src:`data:${Ht.mimeType};base64,${Ht.content}`,name:Ht.name}):(Ee(Ht.content),Ze(d7({format:Ge.format,reference:Ge.reference,content:Ht.content})))}catch{Ee(null),Ge.type==="file"&&me(!0)}ht(!1)}};g.useEffect(()=>{t||(Ee(null),Ze("markdown"),it(null),me(!1),_&&Ln(_))},[_?.id,t]);const Lr=g.useCallback(Ge=>{Se(Ht=>{const Wt=new Set(Ht);return Wt.has(Ge)?Wt.delete(Ge):Wt.add(Ge),Wt})},[]),Qr=g.useCallback(()=>{ue.size===Zt.length?Se(new Set):Se(new Set(Zt.map(([Ge])=>Ge)))},[ue.size,Zt]),mr=Ge=>{J(Ge),a&&(u(!0),history.pushState({mobileDetail:De.DELIVERABLES},"",window.location.hash))};return n.jsxs("div",{className:"flex-1 overflow-hidden flex",children:[n.jsxs("div",{className:`${a?"flex-1 min-w-0":"shrink-0"} flex flex-col bg-surface-secondary rounded-xl m-1 mr-0`,style:a?d?{display:"none"}:void 0:{width:l.width},children:[n.jsxs("div",{className:"p-4 space-y-3",children:[n.jsx("div",{className:"flex items-center justify-between gap-2",children:n.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[a&&n.jsx(gc,{}),n.jsxs("h2",{className:"text-sm font-semibold text-fg-secondary truncate",children:[s("title"),x>0&&n.jsxs("span",{className:"ml-1.5 text-fg-tertiary font-normal",children:["(",x,")"]})]})]})}),n.jsx("input",{value:I,onChange:Ge=>z(Ge.target.value),placeholder:s("searchPlaceholder"),className:"w-full bg-surface-elevated border border-border-default rounded-lg px-3 py-2 text-sm text-fg-primary focus:border-brand-500 focus:outline-none transition-colors"}),Ae&&n.jsxs("div",{className:"flex items-center gap-2 px-2.5 py-1.5 bg-surface-elevated rounded-lg text-[10px] text-fg-tertiary",children:[n.jsx("span",{className:"truncate font-mono",children:Ae}),n.jsx("button",{onClick:()=>{ie.system.openPath(Ae)},className:"shrink-0 underline hover:text-fg-secondary transition-colors",children:s("common:open")})]}),n.jsxs("div",{className:"flex gap-1 overflow-x-auto scrollbar-hide",children:[n.jsx(Ou,{label:s("filters.allTypes"),value:"",current:V||U||"",onClick:()=>{Y(""),H("")}}),sse.map(Ge=>n.jsx(Ou,{label:`${Pu[Ge]?.icon??""} ${Ge}`,value:Ge,current:V,onClick:Ht=>{Y(Ht),H("")}},Ge)),["agent","team","skill"].map(Ge=>n.jsx(Ou,{label:`${Zl[Ge].icon} ${s(`artifactTypes.${Ge}`)}`,value:Ge,current:U,onClick:Ht=>{H(Ht),Y("")}},Ge))]}),w.length>0&&n.jsxs("div",{className:"flex gap-1 overflow-x-auto scrollbar-hide",children:[n.jsx(Ou,{label:s("filters.allProjects"),value:"",current:F,onClick:L}),w.map(Ge=>n.jsx(Ou,{label:Ge.name,value:Ge.id,current:F,onClick:L},Ge.id))]}),n.jsxs("div",{className:"flex gap-1.5 items-center",children:[n.jsx("span",{className:"text-[10px] text-fg-tertiary",children:s("filters.group")}),["date","project","agent","type"].map(Ge=>n.jsx("button",{onClick:()=>{Z(Ge),Se(new Set)},className:`px-2 py-1 rounded text-xs transition-colors ${q===Ge?"bg-brand-600 text-white":"bg-surface-elevated text-fg-secondary hover:bg-surface-overlay"}`,children:s(`groupBy.${Ge}`)},Ge)),Zt.length>1&&n.jsx("button",{onClick:Qr,className:"ml-auto px-1.5 py-1 rounded text-[10px] text-fg-tertiary hover:text-fg-secondary hover:bg-surface-elevated transition-colors",title:ue.size===Zt.length?s("expandAllTooltip"):s("collapseAllTooltip"),children:ue.size===Zt.length?s("expandAll"):s("collapseAll")})]})]}),X&&n.jsx("div",{className:`mx-4 mt-2 px-3 py-1.5 text-xs rounded-lg ${X.type==="success"?"bg-green-500/15 text-green-600":"bg-red-500/15 text-red-500"}`,children:X.text}),n.jsxs("div",{ref:he,className:"flex-1 overflow-y-auto p-2 space-y-1",onTouchStart:a?Ne.onTouchStart:void 0,onTouchEnd:a?Ne.onTouchEnd:void 0,children:[E?n.jsx("div",{className:"p-4 space-y-3",children:[1,2,3].map(Ge=>n.jsxs("div",{className:"animate-pulse space-y-2",children:[n.jsx("div",{className:"h-4 bg-surface-elevated rounded w-3/4"}),n.jsx("div",{className:"h-3 bg-surface-elevated rounded w-1/2"})]},Ge))}):p.length===0?n.jsxs("div",{className:"flex flex-col items-center justify-center py-16 px-6 text-center",children:[n.jsx("svg",{className:"w-12 h-12 text-fg-muted mb-3",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:1,children:n.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M19.5 14.25v-2.625a3.375 3.375 0 00-3.375-3.375h-1.5A1.125 1.125 0 0113.5 7.125v-1.5a3.375 3.375 0 00-3.375-3.375H8.25m0 12.75h7.5m-7.5 3H12M10.5 2.25H5.625c-.621 0-1.125.504-1.125 1.125v17.25c0 .621.504 1.125 1.125 1.125h12.75c.621 0 1.125-.504 1.125-1.125V11.25a9 9 0 00-9-9z"})}),n.jsx("p",{className:"text-sm text-fg-secondary",children:s("empty.title")}),n.jsx("p",{className:"text-xs text-fg-tertiary mt-1 mb-3",children:s("empty.subtitle")}),n.jsx("button",{onClick:()=>bt.navigate(De.WORK),className:"text-xs px-3 py-1.5 rounded-lg bg-brand-600 hover:bg-brand-500 text-white transition-colors",children:s("empty.goToWork")})]}):Zt.map(([Ge,Ht])=>{const Wt=ue.has(Ge);return n.jsxs("div",{children:[n.jsxs("button",{onClick:()=>Lr(Ge),className:"w-full flex items-center gap-1.5 px-2 py-1.5 rounded-md hover:bg-surface-elevated/50 transition-colors group/header",children:[n.jsx("svg",{className:`w-3 h-3 text-fg-tertiary transition-transform duration-200 shrink-0 ${Wt?"":"rotate-90"}`,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2.5,children:n.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M9 5l7 7-7 7"})}),n.jsx("span",{className:"text-[10px] font-medium text-fg-tertiary uppercase tracking-wider truncate",children:Ht.label}),n.jsxs("span",{className:"text-[10px] text-fg-tertiary shrink-0",children:["(",Ht.items.length,")"]})]}),!Wt&&Ht.items.map(tn=>n.jsx("button",{onClick:()=>mr(tn),className:`w-full text-left px-3 py-2 rounded-lg transition-colors ${_?.id===tn.id?"bg-brand-600/20 border border-brand-500/30":"hover:bg-surface-elevated/60 border border-transparent"}`,children:n.jsxs("div",{className:"flex items-center gap-1.5 min-w-0",children:[tn.artifactType&&Zl[tn.artifactType]?n.jsx("span",{className:`text-[10px] px-1 py-0.5 rounded font-medium shrink-0 ${Zl[tn.artifactType].color}`,children:Zl[tn.artifactType].icon}):n.jsx("span",{className:`text-[10px] px-1 py-0.5 rounded font-medium uppercase shrink-0 ${Pu[tn.type]?.color??"bg-surface-overlay text-fg-secondary"}`,children:Pu[tn.type]?.icon??tn.type.charAt(0)}),n.jsx("span",{className:"text-sm font-medium text-fg-primary truncate",children:tn.title}),pe.has(tn.id)&&n.jsx("span",{className:"shrink-0 text-amber-500",title:s("detail.fileMissing"),children:n.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("path",{d:"M10.29 3.86L1.82 18a2 2 0 001.71 3h16.94a2 2 0 001.71-3L13.71 3.86a2 2 0 00-3.42 0z"}),n.jsx("line",{x1:"12",y1:"9",x2:"12",y2:"13"}),n.jsx("line",{x1:"12",y1:"17",x2:"12.01",y2:"17"})]})}),n.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded shrink-0 ${rse[tn.status]?.color??"bg-surface-elevated text-fg-tertiary"}`,children:s(`common:status.${tn.status}`,{defaultValue:tn.status})})]})},tn.id))]},Ge)}),j&&n.jsxs("div",{className:"flex items-center justify-center gap-2 py-3 text-fg-tertiary",children:[n.jsx(V3,{})," ",n.jsx("span",{className:"text-[10px]",children:s("common:loadingMore")})]}),!E&&p.length>0&&n.jsx("div",{className:"text-center text-[10px] text-fg-tertiary py-2",children:p.length<x?s("count.partial",{loaded:p.length,total:x}):s("count.total",{total:x})})]})]}),!a&&n.jsx("div",{className:"w-1.5 shrink-0 cursor-col-resize group relative flex items-center justify-center",onMouseDown:l.onResizeStart,children:n.jsx("div",{className:"w-px h-2/3 border-l border-dashed border-transparent group-hover:border-border-default group-active:border-fg-tertiary transition-colors"})}),(!a||d)&&n.jsxs("div",{className:"flex-1 overflow-y-auto min-w-0",children:[a&&n.jsxs("div",{className:"sticky top-0 z-10 bg-surface-secondary px-4 py-2.5 flex items-center gap-2",children:[n.jsx("button",{onClick:()=>history.back(),className:"text-fg-secondary hover:text-fg-primary transition-colors p-1 -ml-1",children:n.jsx("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:n.jsx("polyline",{points:"15 18 9 12 15 6"})})}),n.jsx("span",{className:"text-sm font-medium truncate",children:_?.title??s("detail.details")})]}),_?n.jsxs("div",{className:"p-6 space-y-4",children:[!t&&pe.has(_.id)&&n.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 bg-amber-500/10 border border-amber-500/20 rounded-lg text-amber-600 text-xs",children:[n.jsxs("svg",{className:"w-4 h-4 shrink-0",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("path",{d:"M10.29 3.86L1.82 18a2 2 0 001.71 3h16.94a2 2 0 001.71-3L13.71 3.86a2 2 0 00-3.42 0z"}),n.jsx("line",{x1:"12",y1:"9",x2:"12",y2:"13"}),n.jsx("line",{x1:"12",y1:"17",x2:"12.01",y2:"17"})]}),n.jsx("span",{children:s("detail.fileMissing")})]}),n.jsxs("div",{className:"space-y-3",children:[n.jsxs("div",{className:"flex items-start justify-between gap-3",children:[n.jsx("h2",{className:"text-xl font-semibold text-fg-primary",children:_.title}),!t&&n.jsx("button",{onClick:()=>He(_),disabled:!!te,className:"p-1.5 rounded-lg text-fg-tertiary hover:text-red-500 hover:bg-red-500/10 transition-colors disabled:opacity-50 shrink-0",title:s("common:remove"),children:n.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("polyline",{points:"3 6 5 6 21 6"}),n.jsx("path",{d:"M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"})]})})]}),n.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[n.jsxs("span",{className:`px-2 py-0.5 rounded text-xs font-medium uppercase ${Pu[_.type]?.color??"bg-surface-overlay text-fg-secondary"}`,children:[Pu[_.type]?.icon??""," ",_.type]}),_.artifactType&&Zl[_.artifactType]&&n.jsxs("span",{className:`px-2 py-0.5 rounded text-xs font-medium ${Zl[_.artifactType].color}`,children:[Zl[_.artifactType].icon," ",s("detail.builderWithType",{type:s(`artifactTypes.${_.artifactType}`)})]}),_.tags.length>0&&_.tags.map(Ge=>n.jsx("span",{className:"px-2 py-0.5 text-xs bg-surface-elevated text-fg-secondary rounded",children:Ge},Ge))]}),(_.taskId||_.agentId||je(_.projectId))&&n.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[_.taskId&&n.jsx("button",{onClick:()=>bt.navigate(De.WORK,{openTask:_.taskId}),className:"text-xs text-brand-500 hover:underline bg-brand-500/10 px-2 py-0.5 rounded",children:s("links.task",{id:`${_.taskId.slice(0,12)}...`})}),_.agentId&&n.jsx("button",{onClick:()=>bt.navigate(De.TEAM,{selectAgent:_.agentId}),className:"text-xs text-blue-600 hover:underline bg-blue-500/10 px-2 py-0.5 rounded",children:s("links.agent",{name:rt.get(_.agentId)?.name??_.agentId.slice(0,12)})}),je(_.projectId)&&n.jsx("button",{onClick:()=>bt.navigate(De.WORK,{projectId:_.projectId}),className:"text-xs text-blue-600 hover:underline bg-blue-500/10 px-2 py-0.5 rounded",children:s("links.project",{name:je(_.projectId)})})]}),(_.diffStats||_.testResults)&&n.jsxs("div",{className:"flex gap-3 flex-wrap",children:[_.diffStats&&n.jsxs("div",{className:"bg-surface-elevated rounded-lg px-3 py-2 text-xs flex items-center gap-2",children:[n.jsxs("span",{className:"text-fg-tertiary font-medium",children:[s("diffStats.title"),":"]}),n.jsx("span",{className:"text-fg-secondary",children:s("diffStats.files",{count:_.diffStats.filesChanged})}),n.jsxs("span",{className:"text-green-600",children:["+",_.diffStats.additions]}),n.jsxs("span",{className:"text-red-500",children:["-",_.diffStats.deletions]})]}),_.testResults&&n.jsxs("div",{className:"bg-surface-elevated rounded-lg px-3 py-2 text-xs flex items-center gap-2",children:[n.jsxs("span",{className:"text-fg-tertiary font-medium",children:[s("testResults.title"),":"]}),n.jsx("span",{className:"text-green-600",children:s("testResults.passed",{count:_.testResults.passed})}),n.jsx("span",{className:"text-red-500",children:s("testResults.failed",{count:_.testResults.failed})}),n.jsx("span",{className:"text-fg-secondary",children:s("testResults.skipped",{count:_.testResults.skipped})})]})]}),n.jsxs("div",{className:"flex items-center gap-4 text-[10px] text-fg-tertiary flex-wrap",children:[n.jsxs("span",{children:[s("metadata.created")," ",new Date(_.createdAt).toLocaleDateString()]}),n.jsxs("span",{children:[s("metadata.updated")," ",new Date(_.updatedAt).toLocaleDateString()]}),n.jsx("span",{className:"text-fg-muted select-all",children:_.id.slice(0,12)})]}),_.reference&&!Tf(_.reference)&&_.type==="file"&&n.jsxs("div",{className:"flex items-center gap-2 bg-surface-elevated rounded-lg px-3 py-2",children:[n.jsx("button",{onClick:()=>{ie.files.reveal(_.reference).catch(()=>nt("error",s("detail.failedToOpenBrowser")))},className:"text-xs font-mono text-brand-500 hover:text-brand-500 hover:underline truncate flex-1 text-left cursor-pointer",title:s("detail.openInFileBrowser"),children:_.reference}),n.jsx("button",{onClick:()=>{ie.files.reveal(_.reference).catch(()=>nt("error",s("detail.failedToOpenBrowser")))},className:"px-2 py-1 text-[10px] rounded bg-brand-600/20 text-brand-500 hover:bg-brand-600/30 transition-colors shrink-0",title:s("detail.revealInFinder"),children:s("common:open")}),n.jsx("button",{onClick:()=>gt(_.reference),className:`px-2 py-1 text-[10px] rounded transition-colors shrink-0 ${be?"bg-green-500/20 text-green-600":"bg-surface-overlay/50 text-fg-secondary hover:bg-surface-overlay"}`,title:s("detail.copyPath"),children:s(be?"common:copied":"common:copy")})]}),_.reference&&!Tf(_.reference)&&_.type!=="file"&&_.type!=="directory"&&n.jsx("span",{className:"text-xs text-fg-tertiary font-mono break-all",children:_.reference})]}),_.artifactType&&_.artifactData?n.jsxs("div",{className:"space-y-4",children:[n.jsx("div",{className:"bg-surface-elevated rounded-xl p-5",children:n.jsx(nse,{artifact:_.artifactData,mode:_.artifactType})}),_.reference&&n.jsxs("div",{className:"px-3 py-2 bg-surface-elevated rounded-lg",children:[n.jsx("span",{className:"text-[10px] text-fg-tertiary uppercase tracking-wider block mb-1",children:s("detail.artifactDirectory")}),n.jsx("span",{className:"text-xs text-fg-secondary font-mono break-all",children:_.reference})]}),n.jsx("div",{className:"flex gap-2",children:n.jsx("button",{onClick:Gn,className:"flex-1 px-4 py-2.5 bg-brand-600 hover:bg-brand-500 text-white text-sm font-medium rounded-lg transition-colors",children:s("detail.openInBuilder")})}),_.summary&&n.jsx("div",{className:"bg-surface-elevated rounded-xl p-5",children:n.jsx(Wr,{content:_.summary,className:"text-fg-secondary text-sm"})})]}):_.reference&&Tf(_.reference)?n.jsxs("div",{className:"space-y-4",children:[_.summary&&n.jsx("div",{className:"bg-surface-elevated rounded-xl p-5",children:n.jsx(Wr,{content:_.summary,className:"text-fg-secondary text-sm"})}),n.jsxs("div",{className:"flex flex-col items-center justify-center py-10",children:[n.jsxs("svg",{className:"w-10 h-10 text-fg-muted mb-3",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("path",{d:"M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"}),n.jsx("polyline",{points:"15 3 21 3 21 9"}),n.jsx("line",{x1:"10",y1:"14",x2:"21",y2:"3"})]}),n.jsx("p",{className:"text-xs text-fg-tertiary font-mono mb-4 px-4 text-center break-all select-all",children:_.reference}),n.jsx("button",{onClick:()=>window.open(_.reference,"_blank","noopener,noreferrer"),className:"px-6 py-2.5 bg-brand-600 hover:bg-brand-500 text-white text-sm font-medium rounded-lg transition-colors",children:s("detail.openUrl")})]})]}):_.type==="directory"&&_.reference?n.jsxs("div",{className:"space-y-4",children:[_.summary&&n.jsx("div",{className:"bg-surface-elevated rounded-xl p-5",children:n.jsx(Wr,{content:_.summary,className:"text-fg-secondary text-sm"})}),n.jsxs("div",{className:"flex flex-col items-center justify-center py-10",children:[n.jsx("svg",{className:"w-10 h-10 text-fg-muted mb-3",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:n.jsx("path",{d:"M22 19a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h5l2 3h9a2 2 0 0 1 2 2z"})}),n.jsx("p",{className:"text-xs text-fg-tertiary font-mono mb-4 px-4 text-center break-all select-all",children:_.reference}),n.jsx("button",{onClick:()=>{ie.files.reveal(_.reference).catch(()=>nt("error",s("detail.failedToOpenBrowser")))},className:"px-6 py-2.5 bg-brand-600 hover:bg-brand-500 text-white text-sm font-medium rounded-lg transition-colors",children:s("detail.openInFileBrowser")})]})]}):n.jsx("div",{className:"bg-surface-elevated rounded-xl p-5",children:Lt?n.jsxs("div",{className:"flex items-center gap-2 text-fg-tertiary text-sm",children:[n.jsx(V3,{})," ",s("detail.loadingPreview")]}):mt?n.jsxs("div",{className:"flex flex-col items-center gap-2",children:[n.jsx("img",{src:mt.src,alt:mt.name,className:"max-w-full max-h-[60vh] rounded-lg object-contain"}),n.jsx("span",{className:"text-xs text-fg-tertiary",children:mt.name})]}):_e?n.jsx(fy,{content:_e,format:Ye,className:"text-fg-secondary text-sm"}):ne?n.jsxs("div",{className:"space-y-3",children:[n.jsx("p",{className:"text-sm text-fg-secondary",children:s("detail.cannotPreview",{type:_.type})}),n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx("button",{onClick:()=>{ie.files.reveal(_.reference).catch(()=>nt("error",s("detail.failedToOpen")))},className:"text-xs bg-surface-elevated px-3 py-2 rounded text-brand-500 hover:text-brand-500 hover:underline flex-1 truncate text-left cursor-pointer font-mono",title:s("detail.openInFileBrowser"),children:_.reference}),n.jsx("button",{onClick:()=>{ie.files.reveal(_.reference).catch(()=>nt("error",s("detail.failedToOpen")))},className:"px-3 py-2 text-xs rounded-lg bg-brand-600/20 text-brand-500 hover:bg-brand-600/30 transition-colors shrink-0",children:s("common:open")}),n.jsx("button",{onClick:()=>gt(_.reference),className:`px-3 py-2 text-xs rounded-lg transition-colors shrink-0 ${be?"bg-green-500/20 text-green-600":"bg-surface-overlay/50 text-fg-secondary hover:bg-surface-overlay"}`,children:s(be?"common:copied":"common:copy")})]})]}):_.summary?n.jsx(Wr,{content:_.summary,className:"text-fg-secondary text-sm"}):n.jsx("p",{className:"text-sm text-fg-tertiary italic",children:s("detail.noContent")})})]}):n.jsx("div",{className:"flex-1 flex items-center justify-center h-full",children:n.jsxs("div",{className:"text-center text-fg-tertiary space-y-2",children:[n.jsx("svg",{className:"w-12 h-12 mx-auto text-fg-muted",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:1,children:n.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M19.5 14.25v-2.625a3.375 3.375 0 00-3.375-3.375h-1.5A1.125 1.125 0 0113.5 7.125v-1.5a3.375 3.375 0 00-3.375-3.375H8.25m0 12.75h7.5m-7.5 3H12M10.5 2.25H5.625c-.621 0-1.125.504-1.125 1.125v17.25c0 .621.504 1.125 1.125 1.125h12.75c.621 0 1.125-.504 1.125-1.125V11.25a9 9 0 00-9-9z"})}),n.jsx("p",{className:"text-sm",children:s("detail.selectToView")})]})})]}),fe&&n.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60",onClick:()=>He(null),children:n.jsxs("div",{className:"bg-surface-secondary border border-border-default rounded-xl p-6 max-w-sm mx-4 shadow-2xl",onClick:Ge=>Ge.stopPropagation(),children:[n.jsxs("div",{className:"flex items-center gap-3 mb-4",children:[n.jsx("div",{className:"w-10 h-10 rounded-full bg-red-500/15 flex items-center justify-center shrink-0",children:n.jsxs("svg",{className:"w-5 h-5 text-red-500",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("polyline",{points:"3 6 5 6 21 6"}),n.jsx("path",{d:"M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"})]})}),n.jsxs("div",{children:[n.jsx("div",{className:"text-sm font-medium text-fg-primary",children:s("detail.confirmRemoveTitle")}),n.jsx("div",{className:"text-xs text-fg-secondary mt-0.5",children:s("detail.confirmRemoveMessage",{name:fe.title})})]})]}),n.jsxs("div",{className:"flex justify-end gap-2",children:[n.jsx("button",{onClick:()=>He(null),className:"px-4 py-1.5 text-xs text-fg-secondary hover:text-fg-primary border border-border-default hover:border-gray-600 rounded-lg transition-colors",children:s("common:cancel")}),n.jsx("button",{onClick:()=>{const Ge=fe;He(null),cn(Ge)},disabled:!!te,className:"px-4 py-1.5 text-xs bg-red-600 hover:bg-red-500 text-white rounded-lg transition-colors disabled:opacity-50",children:s("common:remove")})]})]})})]})}function Ou({label:e,value:t,current:r,onClick:s}){return n.jsx("button",{onClick:()=>s(r===t?"":t),className:`px-2 py-1 rounded text-xs whitespace-nowrap shrink-0 transition-colors ${r===t?"bg-brand-600 text-white":"bg-surface-elevated text-fg-secondary hover:bg-surface-overlay"}`,children:e})}function V3(){return n.jsxs("svg",{className:"animate-spin h-3.5 w-3.5",viewBox:"0 0 24 24",fill:"none",children:[n.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),n.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"})]})}function To(e){return e.toLocaleString()}function cd(e){return e<.01?`$${e.toFixed(4)}`:`$${e.toFixed(2)}`}function ase(e){return e>=1024*1024*1024?`${(e/(1024*1024*1024)).toFixed(1)} GB`:e>=1024*1024?`${(e/(1024*1024)).toFixed(1)} MB`:e>=1024?`${(e/1024).toFixed(1)} KB`:`${e} B`}function K3({authUser:e}){const{t}=pt(["reports","common"]),r=Rs(),s=Id(De.REPORTS),[a,i]=g.useState("weekly"),[l,d]=g.useState(null),[u,m]=g.useState(!0),[h,p]=g.useState(""),[y,x]=g.useState(null),[v,j]=g.useState([]),[C,w]=g.useState("totalTokens"),[N,S]=g.useState(!0),[T,E]=g.useState("generate"),[R,I]=g.useState([]),[z,B]=g.useState(null),[D,V]=g.useState([]),[Y,F]=g.useState(""),[L,O]=g.useState(""),M=G=>{O(G),setTimeout(()=>O(""),3e3)},$=g.useCallback(async G=>{m(!0),p("");try{const{report:ue}=await ie.reports.generate({period:G,scope:"org",orgId:"default"});d(ue)}catch(ue){p(String(ue)),d(null)}m(!1)},[]),W=g.useCallback(()=>{ie.usage.summary().then(G=>x(G.usage)).catch(()=>{}),ie.usage.agents().then(G=>j(G.agents)).catch(()=>{})},[]),U=g.useCallback(async()=>{try{const{reports:G}=await ie.reports.list();I(G)}catch{}},[]),H=g.useCallback(async G=>{B(G);try{const{feedback:ue}=await ie.reports.getFeedback(G.id);V(ue)}catch{V([])}},[]);g.useEffect(()=>{$(a)},[a,$]),g.useEffect(()=>{if(!s)return;W();const G=setInterval(W,3e4);return()=>clearInterval(G)},[W,s]),g.useEffect(()=>{T==="history"&&U()},[T,U]);const q=g.useMemo(()=>[...v].sort((G,ue)=>{const Se=G[C],Ce=ue[C];return N?Ce-Se:Se-Ce}),[v,C,N]),Z=v.reduce((G,ue)=>G+ue.estimatedCost,0),_=v.reduce((G,ue)=>G+ue.tokensUsedToday,0),J=v.reduce((G,ue)=>G+(ue.costToday??0),0),X=Math.max(1,...v.map(G=>G.totalTokens)),ee=G=>{C===G?S(!N):(w(G),S(!0))},te=g.useMemo(()=>({daily:t("period.today"),weekly:t("period.thisWeek"),monthly:t("period.thisMonth")}),[t]);return n.jsx("div",{className:"flex-1 overflow-y-auto",children:n.jsxs("div",{className:"max-w-5xl mx-auto w-full p-6 space-y-6",children:[n.jsxs("div",{className:"flex flex-col gap-3 md:flex-row md:items-center md:justify-between",children:[n.jsxs("div",{className:"flex items-center gap-4 flex-wrap",children:[r&&n.jsx(gc,{}),n.jsx("h1",{className:"text-xl font-semibold text-fg-primary",children:t("title")}),n.jsxs("div",{className:"flex gap-1 bg-surface-elevated rounded-lg p-0.5",children:[n.jsx("button",{onClick:()=>E("generate"),className:`px-3 py-1.5 text-xs rounded-md transition-colors ${T==="generate"?"bg-surface-overlay text-fg-primary shadow-sm":"text-fg-tertiary hover:text-fg-secondary"}`,children:t("tabs.generate")}),n.jsxs("button",{onClick:()=>E("history"),className:`px-3 py-1.5 text-xs rounded-md transition-colors ${T==="history"?"bg-surface-overlay text-fg-primary shadow-sm":"text-fg-tertiary hover:text-fg-secondary"}`,children:[t("tabs.history"),R.length>0?` (${R.length})`:""]})]})]}),n.jsxs("div",{className:"flex items-center gap-3 flex-wrap",children:[L&&n.jsx("span",{className:"px-2.5 py-1 bg-green-500/10 text-green-600 text-xs rounded-lg",children:L}),T==="generate"&&n.jsx("div",{className:"flex gap-1 bg-surface-elevated rounded-lg p-0.5",children:["daily","weekly","monthly"].map(G=>n.jsx("button",{onClick:()=>i(G),className:`px-3 py-1.5 text-xs rounded-md transition-colors ${a===G?"bg-surface-overlay text-fg-primary shadow-sm":"text-fg-tertiary hover:text-fg-secondary"}`,children:t(`period.${G}`)},G))})]})]}),T==="history"&&!z&&n.jsx("section",{className:"bg-surface-elevated rounded-xl overflow-hidden",children:R.length===0?n.jsx("div",{className:"p-8 text-center text-fg-tertiary text-sm",children:t("noReportsYet")}):n.jsx("div",{className:"divide-y divide-border-default/50",children:R.map(G=>n.jsxs("button",{onClick:()=>H(G),className:"w-full text-left px-5 py-3 flex items-center gap-4 hover:bg-surface-elevated/30 transition-colors",children:[n.jsxs("div",{className:"flex-1 min-w-0",children:[n.jsx("div",{className:"text-sm font-medium text-fg-primary",children:t("reportType",{type:G.type})}),n.jsxs("div",{className:"text-xs text-fg-tertiary mt-0.5",children:[new Date(G.periodStart).toLocaleDateString()," — ",new Date(G.periodEnd).toLocaleDateString()]})]}),G.plan&&n.jsx("span",{className:`px-2 py-0.5 rounded-full text-[10px] font-medium shrink-0 ${G.plan.status==="approved"?"bg-green-500/10 text-green-600":G.plan.status==="rejected"?"bg-red-500/10 text-red-500":"bg-amber-500/10 text-amber-600"}`,children:G.plan.status==="pending"?t("upcomingPlan.planPending"):t("upcomingPlan.planStatus",{status:G.plan.status})}),n.jsx("span",{className:"text-[10px] text-fg-tertiary shrink-0",children:new Date(G.generatedAt).toLocaleDateString()})]},G.id))})}),T==="history"&&z&&n.jsxs(n.Fragment,{children:[n.jsxs("div",{className:"flex items-center gap-3",children:[n.jsx("button",{onClick:()=>{B(null),V([])},className:"text-xs text-fg-tertiary hover:text-fg-secondary",children:t("backToList")}),n.jsx("span",{className:"text-sm font-medium text-fg-primary",children:t("reportType",{type:z.type})}),n.jsxs("span",{className:"text-xs text-fg-tertiary",children:[new Date(z.periodStart).toLocaleDateString()," — ",new Date(z.periodEnd).toLocaleDateString()]})]}),z.metrics&&n.jsxs("section",{className:"bg-surface-elevated rounded-xl p-5",children:[n.jsx("h3",{className:"text-xs font-semibold text-fg-secondary mb-3",children:t("taskMetrics.title")}),n.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-5 gap-4",children:[n.jsx(Fi,{label:t("taskMetrics.completed"),value:z.metrics.tasksCompleted,color:"text-green-600"}),n.jsx(Fi,{label:t("taskMetrics.inProgress"),value:z.metrics.tasksInProgress,color:"text-brand-500"}),n.jsx(Fi,{label:t("taskMetrics.created"),value:z.metrics.tasksCreated,color:"text-blue-600"}),n.jsx(Fi,{label:t("taskMetrics.blocked"),value:z.metrics.tasksBlocked,color:"text-amber-600"}),n.jsx(Fi,{label:t("taskMetrics.failed"),value:z.metrics.tasksFailed,color:"text-red-500"})]})]}),z.costSummary&&n.jsxs("section",{className:"bg-surface-elevated rounded-xl p-5",children:[n.jsx("h3",{className:"text-xs font-semibold text-fg-secondary mb-3",children:t("costOverview.title")}),n.jsxs("div",{className:"grid grid-cols-2 lg:grid-cols-3 gap-4",children:[n.jsxs("div",{children:[n.jsx("div",{className:"text-2xl font-bold text-fg-primary",children:z.costSummary.totalTokens.toLocaleString()}),n.jsx("div",{className:"text-xs text-fg-tertiary",children:t("costOverview.totalTokens")})]}),n.jsxs("div",{children:[n.jsx("div",{className:"text-2xl font-bold text-fg-primary",children:cd(z.costSummary.totalEstimatedCost)}),n.jsx("div",{className:"text-xs text-fg-tertiary",children:t("costOverview.estimatedCost")})]}),n.jsxs("div",{children:[n.jsxs("div",{className:`text-2xl font-bold ${z.costSummary.trend==="decreasing"?"text-green-600":z.costSummary.trend==="increasing"?"text-red-500":"text-fg-primary"}`,children:[z.costSummary.trend==="decreasing"?"↓":z.costSummary.trend==="increasing"?"↑":"→"," ",z.costSummary.trend]}),n.jsx("div",{className:"text-xs text-fg-tertiary",children:t("costOverview.trend")})]})]}),z.costSummary.byAgent&&z.costSummary.byAgent.length>0&&n.jsx("div",{className:"mt-4 pt-3 border-t border-border-default/50 space-y-1.5",children:z.costSummary.byAgent.map((G,ue)=>n.jsxs("div",{className:"flex items-center justify-between text-xs",children:[n.jsx("span",{className:"text-fg-secondary",children:G.agentId}),n.jsx("span",{className:"text-fg-tertiary tabular-nums",children:t("costOverview.byAgentRow",{tokens:To(G.tokens),cost:cd(G.cost)})})]},ue))})]}),z.taskSummary&&n.jsxs("section",{className:"bg-surface-elevated rounded-xl p-5 overflow-hidden",children:[n.jsx("h3",{className:"text-xs font-semibold text-fg-secondary mb-3",children:t("taskSummary.title")}),n.jsxs("div",{className:"space-y-4 min-w-0",children:[z.taskSummary.completed.length>0&&n.jsx(ad,{title:t("taskSummary.completedCount",{count:z.taskSummary.completed.length}),color:"emerald",items:z.taskSummary.completed.map(G=>({id:G.id,label:G.title,sub:G.agent}))}),z.taskSummary.inProgress.length>0&&n.jsx(ad,{title:t("taskSummary.inProgressCount",{count:z.taskSummary.inProgress.length}),color:"indigo",items:z.taskSummary.inProgress.map(G=>({id:G.id,label:G.title,sub:G.agent}))}),z.taskSummary.blocked.length>0&&n.jsx(ad,{title:t("taskSummary.blockedCount",{count:z.taskSummary.blocked.length}),color:"amber",items:z.taskSummary.blocked.map(G=>({id:G.id,label:G.title,sub:G.reason||G.agent}))}),z.taskSummary.completed.length===0&&z.taskSummary.inProgress.length===0&&z.taskSummary.blocked.length===0&&n.jsx("p",{className:"text-sm text-fg-tertiary",children:t("taskSummary.noTasksInPeriod")})]})]}),z.highlights&&z.highlights.length>0&&n.jsxs("section",{className:"bg-surface-elevated rounded-xl p-5",children:[n.jsx("h3",{className:"text-xs font-semibold text-fg-secondary mb-2",children:t("highlights")}),n.jsx("ul",{className:"list-disc list-inside space-y-1 text-sm text-fg-secondary",children:z.highlights.map((G,ue)=>n.jsx("li",{children:G},ue))})]}),z.blockers&&z.blockers.length>0&&n.jsxs("section",{className:"bg-surface-secondary border border-amber-500/20 rounded-xl p-5",children:[n.jsx("h3",{className:"text-xs font-semibold text-amber-600 mb-2",children:t("blockers")}),n.jsx("ul",{className:"list-disc list-inside space-y-1 text-sm text-fg-secondary",children:z.blockers.map((G,ue)=>n.jsx("li",{children:G},ue))})]}),z.plan&&n.jsxs("section",{className:"bg-surface-elevated rounded-xl p-5",children:[n.jsxs("div",{className:"flex items-center justify-between mb-3",children:[n.jsxs("h3",{className:"text-xs font-semibold text-fg-secondary",children:[t("upcomingPlan.title"),n.jsx("span",{className:`ml-2 px-1.5 py-0.5 rounded text-[10px] font-medium ${z.plan.status==="approved"?"bg-green-500/10 text-green-600":z.plan.status==="rejected"?"bg-red-500/10 text-red-500":"bg-amber-500/10 text-amber-600"}`,children:t(`common:status.${z.plan.status}`,{defaultValue:z.plan.status})})]}),z.plan.status==="pending"&&n.jsxs("div",{className:"flex gap-2",children:[n.jsx("button",{onClick:async()=>{try{const{report:G}=await ie.reports.approvePlan(z.id,{approvedBy:e?.id??"unknown"});B(G),M(t("upcomingPlan.planApproved")),U()}catch(G){M(t("common:error",{message:String(G)}))}},className:"px-3 py-1.5 text-xs font-medium bg-green-600 text-white rounded-lg hover:bg-green-500 transition-colors",children:t("upcomingPlan.approvePlan")}),n.jsx("button",{onClick:async()=>{const G=prompt(t("upcomingPlan.rejectionReason"));if(G)try{const{report:ue}=await ie.reports.rejectPlan(z.id,{rejectedBy:e?.id??"unknown",reason:G});B(ue),M(t("upcomingPlan.planRejected")),U()}catch(ue){M(t("common:error",{message:String(ue)}))}},className:"px-3 py-1.5 text-xs font-medium border border-border-default text-fg-secondary rounded-lg hover:bg-surface-overlay transition-colors",children:t("upcomingPlan.rejectPlan")})]})]}),z.plan.items&&z.plan.items.length>0&&n.jsx("div",{className:"space-y-1.5",children:z.plan.items.map((G,ue)=>n.jsxs("div",{className:"flex items-center gap-2 text-sm text-fg-secondary",children:[n.jsx("span",{className:`px-1.5 py-0.5 rounded text-[10px] font-medium ${G.priority==="high"?"bg-red-500/10 text-red-500":G.priority==="medium"?"bg-amber-500/10 text-amber-600":"bg-gray-500/10 text-fg-tertiary"}`,children:G.priority}),n.jsx("span",{children:G.title}),G.assignee&&n.jsx("span",{className:"text-[10px] text-fg-tertiary ml-auto",children:G.assignee})]},ue))})]}),!z.metrics&&!z.taskSummary&&!z.costSummary&&n.jsx("section",{className:"bg-surface-elevated rounded-xl p-8 text-center",children:n.jsx("p",{className:"text-sm text-fg-tertiary",children:t("noDetailedMetrics")})}),n.jsxs("section",{className:"bg-surface-elevated rounded-xl p-5",children:[n.jsx("h3",{className:"text-xs font-semibold text-fg-secondary mb-3",children:t("feedback.title",{count:D.length})}),D.length>0&&n.jsx("div",{className:"space-y-2 mb-4",children:D.map(G=>n.jsxs("div",{className:"p-3 bg-surface-elevated/50 rounded-lg",children:[n.jsxs("div",{className:"flex items-center gap-2 text-[10px] text-fg-tertiary mb-1",children:[n.jsx("span",{className:"font-medium text-fg-secondary",children:G.authorName}),n.jsx("span",{children:G.type}),n.jsx("span",{children:new Date(G.createdAt).toLocaleDateString()})]}),n.jsx("p",{className:"text-xs text-fg-secondary",children:G.content})]},G.id))}),n.jsxs("div",{className:"flex gap-2",children:[n.jsx("input",{value:Y,onChange:G=>F(G.target.value),placeholder:t("feedback.placeholder"),className:"flex-1 px-3 py-2 text-xs bg-surface-elevated border border-border-default rounded-lg text-fg-primary placeholder:text-fg-tertiary",onKeyDown:G=>{G.key==="Enter"&&Y.trim()&&ie.reports.addFeedback(z.id,{author:e?.id??"unknown",type:"comment",content:Y.trim()}).then(({feedback:ue})=>{V(Se=>[...Se,ue]),F(""),M(t("feedback.added"))}).catch(ue=>M(t("common:error",{message:String(ue)})))}}),n.jsx("button",{onClick:()=>{Y.trim()&&ie.reports.addFeedback(z.id,{author:e?.id??"unknown",type:"comment",content:Y.trim()}).then(({feedback:G})=>{V(ue=>[...ue,G]),F(""),M(t("feedback.added"))}).catch(G=>M(t("common:error",{message:String(G)})))},disabled:!Y.trim(),className:"px-3 py-2 text-xs bg-brand-600 text-white rounded-lg hover:bg-brand-500 disabled:opacity-40 disabled:cursor-not-allowed transition-colors",children:t("common:send")})]})]})]}),T==="generate"&&y&&n.jsxs("div",{className:`grid gap-4 ${y.storageBytes>0?"grid-cols-2 lg:grid-cols-4":"grid-cols-3"}`,children:[n.jsx(Af,{label:t("usage.llmTokens"),value:To(y.llmTokens),color:"text-brand-500"}),n.jsx(Af,{label:t("usage.toolCalls"),value:To(y.toolCalls),color:"text-blue-600"}),n.jsx(Af,{label:t("usage.messages"),value:To(y.messages),color:"text-green-600"}),y.storageBytes>0&&n.jsx(Af,{label:t("usage.storage"),value:ase(y.storageBytes),color:"text-amber-600"})]}),T==="generate"&&(u?n.jsx("div",{className:"flex items-center justify-center h-32 text-fg-tertiary text-sm",children:t("common:loading")}):h?n.jsx("div",{className:"flex items-center justify-center h-32 text-red-500 text-sm",children:h}):l?n.jsxs(n.Fragment,{children:[n.jsxs("div",{className:"text-xs text-fg-tertiary",children:[te[a]," · ",new Date(l.periodStart).toLocaleDateString()," — ",new Date(l.periodEnd).toLocaleDateString()]}),l.metrics&&n.jsxs("section",{className:"bg-surface-elevated rounded-xl p-5",children:[n.jsx("h3",{className:"text-xs font-semibold text-fg-secondary mb-3",children:t("taskMetrics.title")}),n.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-5 gap-4",children:[n.jsx(Fi,{label:t("taskMetrics.completed"),value:l.metrics.tasksCompleted,color:"text-green-600"}),n.jsx(Fi,{label:t("taskMetrics.inProgress"),value:l.metrics.tasksInProgress,color:"text-brand-500"}),n.jsx(Fi,{label:t("taskMetrics.created"),value:l.metrics.tasksCreated,color:"text-blue-600"}),n.jsx(Fi,{label:t("taskMetrics.blocked"),value:l.metrics.tasksBlocked,color:"text-amber-600"}),n.jsx(Fi,{label:t("taskMetrics.failed"),value:l.metrics.tasksFailed,color:"text-red-500"})]})]}),n.jsxs("section",{className:"bg-surface-elevated rounded-xl p-5",children:[n.jsx("h3",{className:"text-xs font-semibold text-fg-secondary mb-3",children:t("costOverview.title")}),n.jsxs("div",{className:"grid grid-cols-3 gap-4",children:[n.jsxs("div",{children:[n.jsx("div",{className:"text-2xl font-bold text-fg-primary",children:cd(Z)}),n.jsx("div",{className:"text-xs text-fg-tertiary",children:t("costOverview.estCostAllTime")})]}),n.jsxs("div",{children:[n.jsx("div",{className:"text-2xl font-bold text-fg-primary",children:To(_)}),n.jsx("div",{className:"text-xs text-fg-tertiary",children:t("costOverview.tokensToday")})]}),n.jsxs("div",{children:[n.jsx("div",{className:"text-2xl font-bold text-fg-primary",children:cd(J)}),n.jsx("div",{className:"text-xs text-fg-tertiary",children:t("costOverview.costToday")})]})]})]}),l.taskSummary&&n.jsxs("section",{className:"bg-surface-elevated rounded-xl p-5",children:[n.jsx("h3",{className:"text-xs font-semibold text-fg-secondary mb-3",children:t("taskSummary.title")}),n.jsxs("div",{className:"space-y-4",children:[l.taskSummary.completed.length>0&&n.jsx(ad,{title:t("taskSummary.completedCount",{count:l.taskSummary.completed.length}),color:"emerald",items:l.taskSummary.completed.map(G=>({id:G.id,label:G.title,sub:G.agent}))}),l.taskSummary.inProgress.length>0&&n.jsx(ad,{title:t("taskSummary.inProgressCount",{count:l.taskSummary.inProgress.length}),color:"indigo",items:l.taskSummary.inProgress.map(G=>({id:G.id,label:G.title,sub:G.agent}))}),l.taskSummary.blocked.length>0&&n.jsx(ad,{title:t("taskSummary.blockedCount",{count:l.taskSummary.blocked.length}),color:"amber",items:l.taskSummary.blocked.map(G=>({id:G.id,label:G.title,sub:G.reason||G.agent}))}),l.taskSummary.completed.length===0&&l.taskSummary.inProgress.length===0&&l.taskSummary.blocked.length===0&&n.jsx("p",{className:"text-sm text-fg-tertiary",children:t("taskSummary.noTasksInPeriod")})]})]})]}):null),T==="generate"&&n.jsxs("section",{className:"bg-surface-elevated rounded-xl overflow-hidden",children:[n.jsx("div",{className:"px-5 py-4 border-b border-border-default",children:n.jsx("h3",{className:"text-sm font-semibold text-fg-secondary",children:t("perAgentUsage.title")})}),v.length===0?n.jsx("div",{className:"p-8 text-center text-fg-tertiary text-sm",children:t("perAgentUsage.noData")}):n.jsx("div",{className:"overflow-x-auto",children:n.jsxs("table",{className:"w-full",children:[n.jsx("thead",{children:n.jsxs("tr",{className:"border-b border-border-default text-xs text-fg-tertiary uppercase tracking-wider",children:[n.jsx("th",{className:"px-4 py-3 text-left font-medium",children:t("perAgentUsage.agent")}),n.jsx(_u,{label:t("perAgentUsage.totalTokens"),col:"totalTokens",current:C,desc:N,onSort:ee}),n.jsx(_u,{label:t("perAgentUsage.today"),col:"tokensUsedToday",current:C,desc:N,onSort:ee}),n.jsx(_u,{label:t("perAgentUsage.requests"),col:"requestCount",current:C,desc:N,onSort:ee}),n.jsx(_u,{label:t("perAgentUsage.toolCalls"),col:"toolCalls",current:C,desc:N,onSort:ee}),n.jsx(_u,{label:t("perAgentUsage.estCost"),col:"estimatedCost",current:C,desc:N,onSort:ee,align:"right"})]})}),n.jsx("tbody",{children:q.map(G=>n.jsx(ise,{agent:G,maxTokens:X},G.agentId))}),n.jsx("tfoot",{children:n.jsxs("tr",{className:"border-t border-border-default bg-surface-elevated/30",children:[n.jsx("td",{className:"px-4 py-3 text-sm font-medium text-fg-secondary",children:t("perAgentUsage.totalAgents",{count:v.length})}),n.jsx("td",{className:"px-4 py-3 text-sm font-medium text-fg-secondary tabular-nums",children:To(v.reduce((G,ue)=>G+ue.totalTokens,0))}),n.jsx("td",{className:"px-4 py-3 text-sm font-medium text-fg-secondary tabular-nums",children:To(_)}),n.jsx("td",{className:"px-4 py-3 text-sm font-medium text-fg-secondary tabular-nums",children:v.reduce((G,ue)=>G+ue.requestCount,0)}),n.jsx("td",{className:"px-4 py-3 text-sm font-medium text-fg-secondary tabular-nums",children:v.reduce((G,ue)=>G+ue.toolCalls,0)}),n.jsx("td",{className:"px-4 py-3 text-sm font-medium text-right text-fg-secondary tabular-nums",children:cd(Z)})]})})]})})]})]})})}function Fi({label:e,value:t,color:r}){return n.jsxs("div",{className:"text-center",children:[n.jsx("div",{className:`text-2xl font-bold ${r}`,children:t}),n.jsx("div",{className:"text-[10px] text-fg-tertiary mt-0.5",children:e})]})}function ad({title:e,color:t,items:r}){return n.jsxs("div",{className:"min-w-0 overflow-hidden",children:[n.jsx("div",{className:`text-xs font-medium text-${t}-400 mb-1.5`,children:e}),n.jsx("div",{className:"space-y-1.5",children:r.map((s,a)=>n.jsxs("div",{className:`text-sm text-fg-secondary min-w-0 ${s.id?"cursor-pointer hover:text-fg-primary group":""}`,onClick:s.id?()=>bt.navigate(De.WORK,{openTask:s.id}):void 0,children:[n.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[n.jsx("span",{className:`w-1.5 h-1.5 rounded-full bg-${t}-500 shrink-0`}),n.jsx("span",{className:`truncate min-w-0 ${s.id?"group-hover:text-brand-500 transition-colors":""}`,children:s.label})]}),s.sub&&s.sub!=="unassigned"&&n.jsx("div",{className:"text-[10px] text-fg-tertiary ml-3.5 mt-0.5 break-all line-clamp-2",children:s.sub})]},s.id??a))})]})}function Af({label:e,value:t,color:r}){return n.jsxs("div",{className:"bg-surface-elevated rounded-xl p-5",children:[n.jsx("div",{className:"text-sm text-fg-secondary mb-2",children:e}),n.jsx("div",{className:`text-2xl font-bold ${r}`,children:t})]})}function _u({label:e,col:t,current:r,desc:s,onSort:a,align:i}){const l=r===t?s?"↓":"↑":"↕",d=r===t?"text-brand-500":"text-fg-muted";return n.jsxs("th",{className:`px-4 py-3 ${i==="right"?"text-right":"text-left"} font-medium cursor-pointer select-none hover:text-fg-secondary`,onClick:()=>a(t),children:[e,n.jsx("span",{className:`ml-1 ${d}`,children:l})]})}function ise({agent:e,maxTokens:t}){const r=t>0?Math.min(100,e.totalTokens/t*100):0,s=e.status==="working"?"bg-blue-500":e.status==="idle"?"bg-green-500":e.status==="paused"?"bg-amber-500":e.status==="error"?"bg-red-500":"bg-gray-600";return n.jsxs("tr",{className:"border-b border-border-default/50 hover:bg-surface-elevated/30 transition-colors cursor-pointer",onClick:()=>bt.navigate(De.TEAM,{selectAgent:e.agentId}),children:[n.jsx("td",{className:"px-4 py-3",children:n.jsxs("div",{className:"flex items-center gap-2.5",children:[n.jsx("div",{className:`w-2 h-2 rounded-full ${s}`}),n.jsxs("div",{children:[n.jsx("div",{className:"text-sm font-medium text-fg-primary hover:text-brand-500 transition-colors",children:e.agentName}),n.jsx("div",{className:"text-xs text-fg-tertiary",children:e.role})]})]})}),n.jsx("td",{className:"px-4 py-3",children:n.jsxs("div",{className:"flex items-center gap-3",children:[n.jsx("div",{className:"flex-1 bg-surface-elevated rounded-full h-1.5 overflow-hidden max-w-[120px]",children:n.jsx("div",{className:"h-full bg-brand-500 rounded-full",style:{width:`${r}%`}})}),n.jsx("span",{className:"text-sm text-fg-secondary tabular-nums",children:To(e.totalTokens)})]})}),n.jsx("td",{className:"px-4 py-3 text-sm text-fg-secondary tabular-nums",children:To(e.tokensUsedToday)}),n.jsx("td",{className:"px-4 py-3 text-sm text-fg-secondary tabular-nums",children:e.requestCount}),n.jsx("td",{className:"px-4 py-3 text-sm text-fg-secondary tabular-nums",children:e.toolCalls}),n.jsx("td",{className:"px-4 py-3 text-sm text-right text-fg-secondary tabular-nums",children:cd(e.estimatedCost)})]})}const Ef={urgent:"bg-red-500",high:"bg-amber-500",normal:"bg-blue-500",low:"bg-gray-400"},id={approval_request:"M9 12l2 2 4-4 M21 12a9 9 0 1 1-18 0 9 9 0 0 1 18 0z",task_completed:"M22 11.08V12a10 10 0 1 1-5.93-9.14 M22 4L12 14.01l-3-3",task_created:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z M14 2v6h6 M16 13H8 M16 17H8 M10 9H8",task_review:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z M14 2v6h6 M16 13H8 M16 17H8 M10 9H8",task_failed:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z M14 2v6h6 M16 13H8 M16 17H8 M10 9H8",requirement_created:"M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7 M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z",requirement_decision:"M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10z",agent_report:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z M14 2v6h6 M16 13H8 M16 17H8",direct_message:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z",group_message:"M17 21v-2a4 4 0 0 0-4-4H5a4 4 0 0 0-4 4v2 M9 7a4 4 0 1 0 0-8 4 4 0 0 0 0 8z M23 21v-2a4 4 0 0 0-3-3.87 M16 3.13a4 4 0 0 1 0 7.75",system:"M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10z"},W3={approval_request:"text-amber-500",task_completed:"text-green-500",task_failed:"text-red-500",task_created:"text-blue-500",task_review:"text-purple-500",requirement_created:"text-amber-500",requirement_decision:"text-green-500",agent_report:"text-blue-500",direct_message:"text-green-500",group_message:"text-brand-500",system:"text-fg-tertiary"};function od(e,t){const r=Date.now()-new Date(e).getTime(),s=Math.floor(r/6e4);if(s<1)return t("common:time.now");if(s<60)return t("common:time.minutesAgo",{count:s});const a=Math.floor(s/60);return a<24?t("common:time.hoursAgo",{count:a}):t("common:time.daysAgo",{count:Math.floor(a/24)})}function Mf(e,t){const r=e.actionType;if(r==="open_chat")return t("team:notifications.actionHints.openChat");if(r==="navigate")return t("team:notifications.actionHints.viewDetails");const s=e.metadata??{};switch(e.type){case"task_completed":case"task_created":case"task_review":case"task_failed":return s.taskId?t("team:notifications.actionHints.viewTask"):null;case"requirement_created":case"requirement_decision":return s.requirementId?t("team:notifications.actionHints.viewRequirement"):null;case"agent_report":return s.agentId?t("team:notifications.actionHints.viewAgent"):null;case"direct_message":return t("team:notifications.actionHints.openChat");case"group_message":return t("team:notifications.actionHints.openChat");case"approval_request":return t("team:notifications.actionHints.viewApproval");default:return s.taskId?t("team:notifications.actionHints.viewTask"):s.requirementId?t("team:notifications.actionHints.viewRequirement"):s.agentId?t("team:notifications.actionHints.viewAgent"):null}}function ose(){try{const e=new AudioContext,t=e.currentTime,r=e.createGain();r.connect(e.destination),r.gain.setValueAtTime(.15,t),r.gain.exponentialRampToValueAtTime(.01,t+.6);const s=e.createOscillator();s.type="sine",s.frequency.setValueAtTime(880,t),s.frequency.setValueAtTime(1174.66,t+.15),s.connect(r),s.start(t),s.stop(t+.6),s.onended=()=>e.close()}catch{}}function aC({collapsed:e,userId:t,embeddedMode:r,onClose:s,sidebarMode:a,isActive:i,label:l,iconPath:d}){const{t:u}=pt(["team","common"]),[m,h]=g.useState(!1),[p,y]=g.useState("approvals"),[x,v]=g.useState([]),[j,C]=g.useState([]),[w,N]=g.useState(null),[S,T]=g.useState(null),[E,R]=g.useState({}),[I,z]=g.useState(0),B=g.useRef(null),D=g.useRef(null),[V,Y]=g.useState({top:0,left:0,width:448,maxHeight:576}),F=g.useRef(null),L=g.useRef(!1),[O,M]=g.useState(!0),[$,W]=g.useState(!1),U=g.useRef(null),H=g.useRef("approvals"),q=30,Z=g.useCallback(async()=>{try{const[se,fe]=await Promise.all([ie.notifications.list(t,!1,{limit:q,offset:0}),ie.approvals.list()]);if(v(se.notifications),z(se.unreadCount??se.notifications.filter(He=>!He.read).length),M(se.totalCount!=null?se.notifications.length<se.totalCount:se.notifications.length>=q),C(fe.approvals),!L.current){const He=fe.approvals.filter(Ae=>Ae.status==="pending").length;F.current=He,L.current=!0}}catch{}},[t]),_=g.useCallback(async()=>{if(!($||!O)){W(!0);try{const se=await ie.notifications.list(t,!1,{limit:q,offset:x.length});se.notifications.length>0&&v(fe=>[...fe,...se.notifications.filter(He=>!fe.some(Ae=>Ae.id===He.id))]),M(se.totalCount!=null?x.length+se.notifications.length<se.totalCount:se.notifications.length>=q)}catch{}W(!1)}},[t,x.length,$,O]),J=g.useCallback(se=>{const fe=se.detail;if(!fe)return;const{taskId:He,requirementId:Ae}=fe;!He&&!Ae||v(et=>{const pe=et.filter(Fe=>!Fe.read&&(He&&Fe.metadata?.taskId===He||Ae&&Fe.metadata?.requirementId===Ae));if(pe.length===0)return et;for(const Fe of pe)ie.notifications.markRead(Fe.id).catch(()=>{});return z(Fe=>Math.max(0,Fe-pe.length)),et.map(Fe=>pe.some(Ve=>Ve.id===Fe.id)?{...Fe,read:!0}:Fe)})},[]);g.useEffect(()=>{Z();const se=setInterval(Z,6e4),fe=()=>Z(),He=()=>{h(!0),Z()};window.addEventListener("markus:notifications-changed",fe),window.addEventListener("markus:mark-read-by-ref",J),window.addEventListener("markus:open-notifications",He);const Ae=pn.on("notification:created",()=>Z()),et=pn.on("approval:created",()=>Z());return()=>{clearInterval(se),window.removeEventListener("markus:notifications-changed",fe),window.removeEventListener("markus:mark-read-by-ref",J),window.removeEventListener("markus:open-notifications",He),Ae(),et()}},[Z,J]);const X=g.useCallback(()=>{if(!B.current)return;const se=B.current.getBoundingClientRect(),fe=window.innerWidth,He=window.innerHeight,Ae=Math.min(448,fe-16),et=Math.min(576,He-16);let pe=se.right+8,Fe=se.top;pe+Ae>fe-8&&(pe=Math.max(8,fe-Ae-8)),Fe+et>He-8&&(Fe=Math.max(8,He-et-8)),Y({top:Fe,left:pe,width:Ae,maxHeight:et})},[]);g.useLayoutEffect(()=>{m&&X()},[m,X]),g.useEffect(()=>{if(m)return window.addEventListener("resize",X),()=>window.removeEventListener("resize",X)},[m,X]),g.useEffect(()=>{if(!m)return;const se=fe=>{B.current?.contains(fe.target)||D.current?.contains(fe.target)||h(!1)};return document.addEventListener("mousedown",se),()=>document.removeEventListener("mousedown",se)},[m]),g.useEffect(()=>{if(!m)return;const se=j.some(He=>He.status==="pending"),fe=x.some(He=>!He.read);y(se&&!fe?"approvals":!se&&fe?"notifications":H.current)},[m]);const ee=new Set(j.filter(se=>se.status==="pending").map(se=>se.id)),te=new Set(j.map(se=>se.id)),G=x.filter(se=>!(se.type==="approval_request"&&se.metadata?.approvalId&&te.has(se.metadata.approvalId))),ue=x.filter(se=>se.type==="approval_request"&&!se.read&&se.metadata?.approvalId&&ee.has(se.metadata.approvalId)).length,Se=Math.max(0,I-ue),Ce=ee.size,Be=Se+Ce;g.useEffect(()=>{F.current!==null&&Ce>F.current&&ose(),F.current=Ce},[Ce]);const Ne=async se=>{await ie.notifications.markRead(se),v(fe=>fe.map(He=>He.id===se?{...He,read:!0}:He)),z(fe=>Math.max(0,fe-1))},he=se=>{const fe=se.metadata??{},He=se.actionType,Ae=se.actionTarget;if(He==="open_chat"&&Ae)try{const et=typeof Ae=="string"?JSON.parse(Ae):Ae;if(et.agentId){const pe={agentId:et.agentId};et.sessionId&&(pe.sessionId=et.sessionId),bt.navigate(De.TEAM,pe);return}}catch{}if(He==="navigate"&&Ae)try{const et=typeof Ae=="string"?JSON.parse(Ae):Ae;if(et.path){if(et.path.startsWith("/team")){const pe={},Fe=new URLSearchParams(et.path.split("?")[1]||"");for(const[Ve,nt]of Fe.entries())pe[Ve]=nt;bt.navigate(De.TEAM,pe);return}if(et.path.startsWith("/work")){const pe={},Fe=new URLSearchParams(et.path.split("?")[1]||"");for(const[Ve,nt]of Fe.entries())pe[Ve]=nt;bt.navigate(De.WORK,pe);return}}}catch{}switch(se.type){case"approval_request":{const et=fe.approvalId,pe=et?j.find(gt=>gt.id===et):void 0,Fe=pe?.details?.taskId??fe.taskId,Ve=pe?.details?.requirementId??fe.requirementId,nt=pe?.details?.agentId??pe?.agentId;Fe?bt.navigate(De.WORK,{openTask:Fe}):Ve?bt.navigate(De.WORK,{openRequirement:Ve}):nt?bt.navigate(De.TEAM,{agentId:nt}):bt.navigate(De.WORK);break}case"task_completed":case"task_created":case"task_review":case"task_failed":fe.taskId?bt.navigate(De.WORK,{openTask:fe.taskId}):bt.navigate(De.WORK);break;case"requirement_created":case"requirement_decision":fe.requirementId?bt.navigate(De.WORK,{openRequirement:fe.requirementId}):bt.navigate(De.WORK);break;case"agent_report":case"system":{if(fe.agentId){const et={agentId:fe.agentId};fe.sessionId&&(et.sessionId=fe.sessionId),bt.navigate(De.TEAM,et)}else bt.navigate(De.TEAM);break}case"direct_message":{const et=fe.senderId;et?bt.navigate(De.TEAM,{dm:et}):bt.navigate(De.TEAM);break}case"group_message":{const et=fe.channel;et?bt.navigate(De.TEAM,{channel:et}):bt.navigate(De.TEAM);break}default:fe.taskId?bt.navigate(De.WORK,{openTask:fe.taskId}):fe.requirementId?bt.navigate(De.WORK,{openRequirement:fe.requirementId}):fe.projectId?bt.navigate(De.WORK,{projectId:fe.projectId}):fe.agentId&&bt.navigate(De.TEAM,{agentId:fe.agentId});break}},_e=async se=>{se.read||Ne(se.id);const fe=se.metadata??{},He=fe.taskId,Ae=fe.requirementId;if(He||Ae){const et=x.filter(pe=>pe.id!==se.id&&!pe.read&&(He&&pe.metadata?.taskId===He||Ae&&pe.metadata?.requirementId===Ae));for(const pe of et)Ne(pe.id)}he(se)},Ee=async(se,fe,He,Ae)=>{N(se);try{const{approval:et}=await ie.approvals.respond(se,fe,t,He,Ae);C(nt=>nt.map(gt=>gt.id===se?et:gt)),T(null),R(nt=>{const gt={...nt};return delete gt[se],gt});const pe=et.details?.taskId,Fe=et.details?.requirementId,Ve=x.filter(nt=>!nt.read&&(nt.type==="approval_request"&&nt.metadata?.approvalId===se||pe&&nt.metadata?.taskId===pe||Fe&&nt.metadata?.requirementId===Fe));if(Ve.length>0){for(const gt of Ve)ie.notifications.markRead(gt.id).catch(()=>{});const nt=new Set(Ve.map(gt=>gt.id));v(gt=>gt.map(rt=>nt.has(rt.id)?{...rt,read:!0}:rt)),z(gt=>Math.max(0,gt-Ve.length))}pl("/approvals"),pl("/notifications"),pl("/tasks"),pl("/taskboard"),pl("/requirements"),window.dispatchEvent(new CustomEvent("markus:data-changed")),window.dispatchEvent(new CustomEvent("markus:notifications-changed")),setTimeout(()=>Z(),800)}catch{}N(null)},Ye=async()=>{try{if(!t)return;await ie.notifications.markAllRead(t),v(se=>se.map(fe=>({...fe,read:!0}))),z(0),pl("/notifications")}catch{const se=G.filter(fe=>!fe.read);await Promise.all(se.map(fe=>ie.notifications.markRead(fe.id))),v(fe=>fe.map(He=>({...He,read:!0}))),z(0),pl("/notifications")}},Ze=se=>{const fe=se.details?.subType;return fe==="requirement_resubmit"?u("team:notifications.approvalType.requirementResubmit"):fe==="requirement"||se.details?.requirementId?u("team:notifications.approvalType.requirement"):fe==="task_review"?u("team:notifications.approvalType.taskReview"):fe==="task"||se.details?.taskId?u("team:notifications.approvalType.task"):se.details?.toolName?u("team:notifications.approvalType.toolExecution"):null},mt=se=>{const fe=[];fe.push(se.agentName);const He=se.details?.taskTitle,Ae=se.details?.taskId;He?fe.push(He):Ae&&fe.push(`Task ${Ae.slice(0,8)}`);const et=se.details?.requirementId;return et&&!Ae&&fe.push(`Req ${et.slice(0,8)}`),fe.join(" · ")},it=[...j].sort((se,fe)=>new Date(fe.requestedAt).getTime()-new Date(se.requestedAt).getTime()),Lt=it.filter(se=>se.status==="pending"),ht=it.filter(se=>se.status!=="pending"),ne=se=>{const fe=se.details?.taskId,He=se.details?.requirementId,Ae=se.details?.agentId??se.agentId;fe?bt.navigate(De.WORK,{openTask:fe}):He?bt.navigate(De.WORK,{openRequirement:He}):Ae?bt.navigate(De.TEAM,{agentId:Ae}):bt.navigate(De.WORK)},me=()=>{h(!1),s?.()},be=n.jsxs(n.Fragment,{children:[n.jsxs("div",{className:"flex border-b border-border-default shrink-0",children:[n.jsxs("button",{onClick:()=>{y("approvals"),H.current="approvals"},className:`flex-1 px-3 py-2.5 text-xs font-medium transition-colors ${p==="approvals"?"text-fg-primary border-b-2 border-brand-500":"text-fg-tertiary hover:text-fg-secondary"}`,children:[u("team:notifications.approvals"),Ce>0?` (${Ce})`:""]}),n.jsxs("button",{onClick:()=>{y("notifications"),H.current="notifications"},className:`flex-1 px-3 py-2.5 text-xs font-medium transition-colors ${p==="notifications"?"text-fg-primary border-b-2 border-brand-500":"text-fg-tertiary hover:text-fg-secondary"}`,children:[u("team:notifications.notifications"),Se>0?` (${Se})`:""]}),n.jsx("button",{onClick:me,className:"px-2 py-2 text-fg-tertiary hover:text-fg-primary transition-colors shrink-0",title:u("common:close"),children:n.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("path",{d:"M18 6L6 18"}),n.jsx("path",{d:"M6 6l12 12"})]})})]}),p==="notifications"&&I>0&&n.jsx("div",{className:"flex justify-end px-3 py-1.5 border-b border-border-default/50 shrink-0",children:n.jsx("button",{onClick:Ye,className:"text-[10px] text-brand-500 hover:text-brand-400 transition-colors",children:u("team:notifications.markAllRead")})}),n.jsxs("div",{ref:U,className:"flex-1 overflow-y-auto",onScroll:se=>{if(p!=="notifications"||!O||$)return;const fe=se.currentTarget;fe.scrollTop+fe.clientHeight>=fe.scrollHeight-80&&_()},children:[p==="approvals"&&(j.length===0?n.jsx("div",{className:"p-6 text-center text-xs text-fg-tertiary",children:u("team:notifications.noApprovals")}):n.jsxs("div",{className:"divide-y divide-border-default/50",children:[Lt.map(se=>{const fe=se.details?.command,He=fe?se.description.replace(/\s*Command:.*$/,""):se.description;return n.jsxs("div",{className:"px-3 py-3 space-y-2.5",children:[n.jsxs("div",{className:"cursor-pointer hover:bg-surface-overlay/50 -mx-3 -mt-3 px-3 pt-3 pb-1 rounded-t-md transition-colors",onClick:()=>ne(se),children:[n.jsxs("div",{className:"flex items-start gap-2",children:[n.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"text-amber-500 mt-0.5 shrink-0",children:n.jsx("path",{d:id.approval_request})}),n.jsxs("div",{className:"flex-1 min-w-0",children:[n.jsxs("div",{className:"flex items-center gap-2",children:[Ze(se)&&n.jsx("span",{className:"text-[10px] text-amber-500 font-medium shrink-0",children:Ze(se)}),n.jsx("span",{className:"text-xs text-fg-primary font-medium truncate",children:se.title}),n.jsx("span",{className:"text-[10px] text-fg-tertiary shrink-0",children:od(se.requestedAt,u)})]}),n.jsx("div",{className:"text-[11px] text-fg-tertiary mt-0.5",children:se.agentName})]})]}),n.jsx("div",{className:"mt-2.5 text-[11px] text-fg-secondary leading-relaxed",children:n.jsx(Wr,{content:He,className:"text-[11px] [&_h1]:text-xs [&_h2]:text-[11px] [&_h3]:text-[11px] [&_p]:text-[11px] [&_li]:text-[11px]"})}),fe&&n.jsx("pre",{className:"text-[11px] text-fg-primary bg-surface-overlay border border-border-default rounded-md px-2.5 py-2 overflow-x-auto whitespace-pre-wrap break-all font-mono leading-relaxed mt-2",children:fe})]}),(()=>{const Ae=se.details?.subType,et=Ae==="task"||Ae==="requirement"||Ae==="requirement_resubmit",pe=se.options&&se.options.length>0,Fe=(E[se.id]??"").trim();return pe?n.jsxs("div",{className:"space-y-1.5",children:[se.options.map((Ve,nt)=>n.jsxs("button",{disabled:w===se.id,onClick:()=>Ee(se.id,Ve.id!=="reject",Fe||void 0,Ve.id),className:`w-full px-3 py-2 text-left text-[11px] font-medium rounded-md disabled:opacity-50 transition-colors flex items-center gap-2 ${Ve.id==="reject"||Ve.id==="request_changes"?"border border-border-default text-fg-secondary hover:bg-surface-overlay":"bg-brand-600 text-white hover:bg-brand-700"}`,title:Ve.description,children:[n.jsx("span",{className:"w-5 h-5 rounded-full bg-white/20 flex items-center justify-center text-[10px] font-bold shrink-0",children:String.fromCharCode(65+nt)}),Ve.label]},Ve.id)),n.jsxs("div",{className:"flex gap-1.5 mt-1",children:[n.jsx("input",{type:"text",placeholder:u("team:notifications.freeformPlaceholder"),value:E[se.id]??"",onChange:Ve=>R(nt=>({...nt,[se.id]:Ve.target.value})),onKeyDown:Ve=>{Ve.key==="Enter"&&(E[se.id]??"").trim()&&Ee(se.id,!0,(E[se.id]??"").trim(),"custom")},className:"flex-1 px-2.5 py-1.5 text-[11px] bg-surface-overlay border border-border-default rounded-md text-fg-primary placeholder:text-fg-tertiary focus:outline-none focus:ring-1 focus:ring-brand-500/50"}),n.jsx("button",{disabled:w===se.id||!(E[se.id]??"").trim(),onClick:()=>Ee(se.id,!0,(E[se.id]??"").trim(),"custom"),className:"px-2.5 py-1.5 text-[11px] font-medium bg-brand-600 text-white rounded-md hover:bg-brand-700 disabled:opacity-50 transition-colors",children:u("common:send")})]})]}):et?n.jsxs("div",{className:"space-y-1.5",children:[n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsxs("button",{disabled:w===se.id,onClick:()=>Ee(se.id,!0,void 0,"approve"),className:"px-3 py-1.5 text-[11px] font-medium bg-green-600 text-white rounded-md hover:bg-green-700 disabled:opacity-50 transition-colors inline-flex items-center gap-1.5",children:[n.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:n.jsx("path",{d:"M20 6L9 17l-5-5"})}),u("common:approve")]}),n.jsxs("button",{disabled:w===se.id,onClick:()=>Ee(se.id,!1,void 0,"reject"),className:"px-3 py-1.5 text-[11px] font-medium bg-red-600/80 text-white rounded-md hover:bg-red-700 disabled:opacity-50 transition-colors inline-flex items-center gap-1.5",children:[n.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("path",{d:"M18 6L6 18"}),n.jsx("path",{d:"M6 6l12 12"})]}),u("common:reject")]}),S!==se.id&&n.jsxs("button",{disabled:w===se.id,onClick:()=>T(se.id),className:"px-3 py-1.5 text-[11px] font-medium border border-amber-500/50 text-amber-500 rounded-md hover:bg-amber-500/10 disabled:opacity-50 transition-colors inline-flex items-center gap-1.5",children:[n.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("path",{d:"M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"}),n.jsx("path",{d:"M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z"})]}),u("team:notifications.needsAdjustment")]})]}),S===se.id&&n.jsxs("div",{className:"space-y-1.5",children:[n.jsx("input",{type:"text",autoFocus:!0,placeholder:u("team:notifications.adjustmentPlaceholder"),value:E[se.id]??"",onChange:Ve=>R(nt=>({...nt,[se.id]:Ve.target.value})),onKeyDown:Ve=>{Ve.key==="Enter"&&(E[se.id]??"").trim()&&Ee(se.id,!1,(E[se.id]??"").trim(),"needs_adjustment"),Ve.key==="Escape"&&T(null)},className:"w-full px-2.5 py-1.5 text-[11px] bg-surface-overlay border border-border-default rounded-md text-fg-primary placeholder:text-fg-tertiary focus:outline-none focus:ring-1 focus:ring-amber-500/50"}),n.jsxs("div",{className:"flex gap-2",children:[n.jsx("button",{disabled:w===se.id||!(E[se.id]??"").trim(),onClick:()=>Ee(se.id,!1,(E[se.id]??"").trim(),"needs_adjustment"),className:"px-2.5 py-1.5 text-[11px] font-medium bg-amber-600 text-white rounded-md hover:bg-amber-700 disabled:opacity-50 transition-colors",children:u("team:notifications.confirmAdjustment")}),n.jsx("button",{onClick:()=>T(null),className:"px-2.5 py-1.5 text-[11px] font-medium border border-border-default text-fg-secondary rounded-md hover:bg-surface-overlay transition-colors",children:u("common:cancel")})]})]})]}):n.jsxs("div",{className:"space-y-1.5",children:[n.jsx("input",{type:"text",placeholder:u("team:notifications.commentPlaceholder"),value:E[se.id]??"",onChange:Ve=>R(nt=>({...nt,[se.id]:Ve.target.value})),onKeyDown:Ve=>{Ve.key==="Enter"&&Ee(se.id,!0,Fe||void 0,"approve")},className:"w-full px-2.5 py-1.5 text-[11px] bg-surface-overlay border border-border-default rounded-md text-fg-primary placeholder:text-fg-tertiary focus:outline-none focus:ring-1 focus:ring-brand-500/50"}),n.jsxs("div",{className:"flex gap-2",children:[n.jsx("button",{disabled:w===se.id,onClick:()=>Ee(se.id,!0,Fe||void 0,"approve"),className:"flex-1 px-2.5 py-1.5 text-[11px] font-medium bg-green-600 text-white rounded-md hover:bg-green-700 disabled:opacity-50 transition-colors",children:u("common:approve")}),n.jsx("button",{disabled:w===se.id,onClick:()=>Ee(se.id,!1,Fe||void 0,"reject"),className:"flex-1 px-2.5 py-1.5 text-[11px] font-medium border border-border-default text-fg-secondary rounded-md hover:bg-surface-overlay disabled:opacity-50 transition-colors",children:u("common:reject")})]})]})})()]},se.id)}),ht.length>0&&n.jsxs(n.Fragment,{children:[Lt.length>0&&n.jsx("div",{className:"px-3 py-1.5 text-[10px] font-medium text-fg-tertiary uppercase tracking-wider bg-surface-overlay/30",children:u("team:notifications.approvalHistory")}),ht.slice(0,50).map(se=>n.jsxs("button",{onClick:()=>ne(se),className:"w-full text-left px-3 py-2.5 hover:bg-surface-overlay/50 transition-colors group",children:[n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx("span",{className:`w-1.5 h-1.5 rounded-full shrink-0 ${se.status==="approved"?"bg-green-500":se.status==="cancelled"||se.status==="expired"?"bg-gray-400":"bg-red-500"}`}),Ze(se)&&n.jsx("span",{className:"text-[10px] text-fg-tertiary font-medium shrink-0",children:Ze(se)}),n.jsx("span",{className:"text-xs text-fg-secondary truncate flex-1 group-hover:text-fg-primary",children:se.title}),n.jsx("span",{className:`text-[10px] font-medium shrink-0 ${se.status==="approved"?"text-green-500":se.status==="cancelled"||se.status==="expired"?"text-fg-muted":"text-red-500"}`,children:u(`common:status.${se.status}`,{defaultValue:se.status})})]}),n.jsxs("div",{className:"flex items-center gap-1.5 mt-0.5 pl-3.5",children:[n.jsx("span",{className:"text-[10px] text-fg-muted truncate",children:mt(se)}),n.jsx("span",{className:"text-[10px] text-fg-muted shrink-0",children:"·"}),n.jsx("span",{className:"text-[10px] text-fg-muted shrink-0",children:od(se.respondedAt??se.requestedAt,u)})]}),se.responseComment&&n.jsxs("p",{className:"text-[10px] text-fg-muted mt-0.5 pl-3.5 truncate",children:["“",se.responseComment,"”"]})]},se.id))]})]})),p==="notifications"&&(G.length===0?n.jsx("div",{className:"p-6 text-center text-xs text-fg-tertiary",children:u("team:notifications.noNotifications")}):n.jsxs("div",{className:"divide-y divide-border-default/50",children:[G.map(se=>{const fe=W3[se.type]??"text-fg-tertiary";return n.jsxs("div",{role:"button",tabIndex:0,onClick:()=>_e(se),onKeyDown:He=>{(He.key==="Enter"||He.key===" ")&&(He.preventDefault(),_e(se))},className:`w-full text-left px-3 py-2.5 flex gap-2.5 transition-colors cursor-pointer ${se.read?"opacity-50 hover:opacity-70":"hover:bg-surface-overlay"}`,children:[n.jsx("div",{className:"shrink-0 mt-0.5",children:n.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:fe,children:n.jsx("path",{d:id[se.type]??id.system})})}),n.jsxs("div",{className:"flex-1 min-w-0",children:[n.jsxs("div",{className:"flex items-center gap-1.5",children:[!se.read&&n.jsx("span",{className:`w-1.5 h-1.5 rounded-full shrink-0 ${Ef[se.priority]??Ef.normal}`}),n.jsx("span",{className:"text-xs text-fg-primary font-medium truncate",children:se.title})]}),n.jsx("div",{className:"text-[11px] text-fg-tertiary mt-0.5 ",children:n.jsx(Wr,{content:se.body,className:"text-[11px] [&_h1]:text-xs [&_h2]:text-[11px] [&_h3]:text-[11px] [&_p]:text-[11px] [&_li]:text-[11px] [&_p]:text-fg-tertiary"})}),n.jsxs("div",{className:"flex items-center gap-2 mt-0.5",children:[n.jsx("span",{className:"text-[10px] text-fg-muted",children:od(se.createdAt,u)}),Mf(se,u)&&n.jsx("span",{className:`text-[10px] font-medium ${fe}`,children:Mf(se,u)})]})]})]},se.id)}),$&&n.jsx("div",{className:"py-3 text-center",children:n.jsxs("svg",{className:"animate-spin h-4 w-4 text-fg-tertiary mx-auto",viewBox:"0 0 24 24",fill:"none",children:[n.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),n.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"})]})})]}))]})]});if(r){const se=["approvals","notifications"],fe=se.indexOf(p),He=(()=>{let Ae=0,et=0;return{onTouchStart:pe=>{Ae=pe.touches[0].clientX,et=pe.touches[0].clientY},onTouchEnd:pe=>{const Fe=pe.changedTouches[0].clientX-Ae,Ve=pe.changedTouches[0].clientY-et;Math.abs(Fe)>60&&Math.abs(Fe)>Math.abs(Ve)*1.5&&(Fe<0&&fe<se.length-1&&y(se[fe+1]),Fe>0&&fe>0&&y(se[fe-1]))}}})();return n.jsxs("div",{className:"flex flex-col h-full overflow-hidden",children:[n.jsx("div",{className:"flex border-b border-border-default shrink-0",children:se.map(Ae=>n.jsx("button",{onClick:()=>y(Ae),className:`flex-1 px-3 py-3 text-sm font-medium transition-colors ${p===Ae?"text-fg-primary border-b-2 border-brand-500":"text-fg-tertiary"}`,children:Ae==="approvals"?n.jsxs(n.Fragment,{children:[u("team:notifications.approvals"),Ce>0?` (${Ce})`:""]}):n.jsxs(n.Fragment,{children:[u("team:notifications.notifications"),Se>0?` (${Se})`:""]})},Ae))}),p==="notifications"&&I>0&&n.jsx("div",{className:"flex justify-end px-3 py-1.5 border-b border-border-default/50 shrink-0",children:n.jsx("button",{onClick:Ye,className:"text-[10px] text-brand-500 hover:text-brand-400 transition-colors",children:u("team:notifications.markAllRead")})}),n.jsx("div",{className:"flex-1 overflow-hidden relative",...He,children:n.jsxs("div",{className:"flex h-full transition-transform duration-300 ease-out",style:{transform:`translateX(-${fe*100}%)`},children:[n.jsx("div",{className:"w-full shrink-0 h-full overflow-y-auto scrollbar-thin",children:j.length===0?n.jsx("div",{className:"p-6 text-center text-xs text-fg-tertiary",children:u("team:notifications.noApprovals")}):n.jsxs("div",{className:"divide-y divide-border-default/50",children:[Lt.map(Ae=>{const et=Ae.details?.command,pe=et?Ae.description.replace(/\s*Command:.*$/,""):Ae.description;return n.jsxs("div",{className:"px-3 py-3 space-y-2.5",children:[n.jsxs("div",{className:"cursor-pointer hover:bg-surface-overlay/50 -mx-3 -mt-3 px-3 pt-3 pb-1 rounded-t-md transition-colors",onClick:()=>ne(Ae),children:[n.jsxs("div",{className:"flex items-start gap-2",children:[n.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"text-amber-500 mt-0.5 shrink-0",children:n.jsx("path",{d:id.approval_request})}),n.jsxs("div",{className:"flex-1 min-w-0",children:[n.jsxs("div",{className:"flex items-center gap-2",children:[Ze(Ae)&&n.jsx("span",{className:"text-[10px] text-amber-500 font-medium shrink-0",children:Ze(Ae)}),n.jsx("span",{className:"text-xs text-fg-primary font-medium truncate",children:Ae.title}),n.jsx("span",{className:"text-[10px] text-fg-tertiary shrink-0",children:od(Ae.requestedAt,u)})]}),n.jsx("div",{className:"text-[11px] text-fg-tertiary mt-0.5",children:Ae.agentName})]})]}),n.jsx("div",{className:"mt-2.5 text-[11px] text-fg-secondary leading-relaxed",children:n.jsx(Wr,{content:pe,className:"text-[11px] [&_h1]:text-xs [&_h2]:text-[11px] [&_h3]:text-[11px] [&_p]:text-[11px] [&_li]:text-[11px]"})}),et&&n.jsx("pre",{className:"text-[11px] text-fg-primary bg-surface-overlay border border-border-default rounded-md px-2.5 py-2 overflow-x-auto whitespace-pre-wrap break-all font-mono leading-relaxed mt-2",children:et})]}),(()=>{const Fe=Ae.details?.subType,Ve=Fe==="task"||Fe==="requirement"||Fe==="requirement_resubmit",nt=Ae.options&&Ae.options.length>0,gt=(E[Ae.id]??"").trim();return nt?n.jsxs("div",{className:"space-y-1.5",children:[Ae.options.map((rt,Et)=>n.jsxs("button",{disabled:w===Ae.id,onClick:()=>Ee(Ae.id,rt.id!=="reject",gt||void 0,rt.id),className:`w-full px-3 py-2 text-left text-[11px] font-medium rounded-md disabled:opacity-50 transition-colors flex items-center gap-2 ${rt.id==="reject"||rt.id==="request_changes"?"border border-border-default text-fg-secondary hover:bg-surface-overlay":"bg-brand-600 text-white hover:bg-brand-700"}`,title:rt.description,children:[n.jsx("span",{className:"w-5 h-5 rounded-full bg-white/20 flex items-center justify-center text-[10px] font-bold shrink-0",children:String.fromCharCode(65+Et)}),rt.label]},rt.id)),n.jsxs("div",{className:"flex gap-1.5 mt-1",children:[n.jsx("input",{type:"text",placeholder:u("team:notifications.freeformPlaceholder"),value:E[Ae.id]??"",onChange:rt=>R(Et=>({...Et,[Ae.id]:rt.target.value})),onKeyDown:rt=>{rt.key==="Enter"&&(E[Ae.id]??"").trim()&&Ee(Ae.id,!0,(E[Ae.id]??"").trim(),"custom")},className:"flex-1 px-2.5 py-1.5 text-[11px] bg-surface-overlay border border-border-default rounded-md text-fg-primary placeholder:text-fg-tertiary focus:outline-none focus:ring-1 focus:ring-brand-500/50"}),n.jsx("button",{disabled:w===Ae.id||!(E[Ae.id]??"").trim(),onClick:()=>Ee(Ae.id,!0,(E[Ae.id]??"").trim(),"custom"),className:"px-2.5 py-1.5 text-[11px] font-medium bg-brand-600 text-white rounded-md hover:bg-brand-700 disabled:opacity-50 transition-colors",children:u("common:send")})]})]}):Ve?n.jsxs("div",{className:"space-y-1.5",children:[n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsxs("button",{disabled:w===Ae.id,onClick:()=>Ee(Ae.id,!0,void 0,"approve"),className:"px-3 py-1.5 text-[11px] font-medium bg-green-600 text-white rounded-md hover:bg-green-700 disabled:opacity-50 transition-colors inline-flex items-center gap-1.5",children:[n.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:n.jsx("path",{d:"M20 6L9 17l-5-5"})}),u("common:approve")]}),n.jsxs("button",{disabled:w===Ae.id,onClick:()=>Ee(Ae.id,!1,void 0,"reject"),className:"px-3 py-1.5 text-[11px] font-medium bg-red-600/80 text-white rounded-md hover:bg-red-700 disabled:opacity-50 transition-colors inline-flex items-center gap-1.5",children:[n.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("path",{d:"M18 6L6 18"}),n.jsx("path",{d:"M6 6l12 12"})]}),u("common:reject")]}),S!==Ae.id&&n.jsxs("button",{disabled:w===Ae.id,onClick:()=>T(Ae.id),className:"px-3 py-1.5 text-[11px] font-medium border border-amber-500/50 text-amber-500 rounded-md hover:bg-amber-500/10 disabled:opacity-50 transition-colors inline-flex items-center gap-1.5",children:[n.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("path",{d:"M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"}),n.jsx("path",{d:"M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z"})]}),u("team:notifications.needsAdjustment")]})]}),S===Ae.id&&n.jsxs("div",{className:"space-y-1.5",children:[n.jsx("input",{type:"text",autoFocus:!0,placeholder:u("team:notifications.adjustmentPlaceholder"),value:E[Ae.id]??"",onChange:rt=>R(Et=>({...Et,[Ae.id]:rt.target.value})),onKeyDown:rt=>{rt.key==="Enter"&&(E[Ae.id]??"").trim()&&Ee(Ae.id,!1,(E[Ae.id]??"").trim(),"needs_adjustment"),rt.key==="Escape"&&T(null)},className:"w-full px-2.5 py-1.5 text-[11px] bg-surface-overlay border border-border-default rounded-md text-fg-primary placeholder:text-fg-tertiary focus:outline-none focus:ring-1 focus:ring-amber-500/50"}),n.jsxs("div",{className:"flex gap-2",children:[n.jsx("button",{disabled:w===Ae.id||!(E[Ae.id]??"").trim(),onClick:()=>Ee(Ae.id,!1,(E[Ae.id]??"").trim(),"needs_adjustment"),className:"px-2.5 py-1.5 text-[11px] font-medium bg-amber-600 text-white rounded-md hover:bg-amber-700 disabled:opacity-50 transition-colors",children:u("team:notifications.confirmAdjustment")}),n.jsx("button",{onClick:()=>T(null),className:"px-2.5 py-1.5 text-[11px] font-medium border border-border-default text-fg-secondary rounded-md hover:bg-surface-overlay transition-colors",children:u("common:cancel")})]})]})]}):n.jsxs("div",{className:"space-y-1.5",children:[n.jsx("input",{type:"text",placeholder:u("team:notifications.commentPlaceholder"),value:E[Ae.id]??"",onChange:rt=>R(Et=>({...Et,[Ae.id]:rt.target.value})),onKeyDown:rt=>{rt.key==="Enter"&&Ee(Ae.id,!0,gt||void 0,"approve")},className:"w-full px-2.5 py-1.5 text-[11px] bg-surface-overlay border border-border-default rounded-md text-fg-primary placeholder:text-fg-tertiary focus:outline-none focus:ring-1 focus:ring-brand-500/50"}),n.jsxs("div",{className:"flex gap-2",children:[n.jsx("button",{disabled:w===Ae.id,onClick:()=>Ee(Ae.id,!0,gt||void 0,"approve"),className:"flex-1 px-2.5 py-1.5 text-[11px] font-medium bg-green-600 text-white rounded-md hover:bg-green-700 disabled:opacity-50 transition-colors",children:u("common:approve")}),n.jsx("button",{disabled:w===Ae.id,onClick:()=>Ee(Ae.id,!1,gt||void 0,"reject"),className:"flex-1 px-2.5 py-1.5 text-[11px] font-medium border border-border-default text-fg-secondary rounded-md hover:bg-surface-overlay disabled:opacity-50 transition-colors",children:u("common:reject")})]})]})})()]},Ae.id)}),ht.length>0&&n.jsxs(n.Fragment,{children:[Lt.length>0&&n.jsx("div",{className:"px-3 py-1.5 text-[10px] font-medium text-fg-tertiary uppercase tracking-wider bg-surface-overlay/30",children:u("team:notifications.approvalHistory")}),ht.slice(0,50).map(Ae=>n.jsxs("button",{onClick:()=>ne(Ae),className:"w-full text-left px-3 py-2.5 hover:bg-surface-overlay/50 transition-colors",children:[n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx("span",{className:`w-1.5 h-1.5 rounded-full shrink-0 ${Ae.status==="approved"?"bg-green-500":Ae.status==="cancelled"||Ae.status==="expired"?"bg-gray-400":"bg-red-500"}`}),n.jsx("span",{className:"text-xs text-fg-secondary truncate flex-1",children:Ae.title}),n.jsx("span",{className:`text-[10px] font-medium shrink-0 ${Ae.status==="approved"?"text-green-500":Ae.status==="cancelled"||Ae.status==="expired"?"text-fg-muted":"text-red-500"}`,children:u(`common:status.${Ae.status}`,{defaultValue:Ae.status})})]}),n.jsxs("div",{className:"flex items-center gap-1.5 mt-0.5 pl-3.5",children:[n.jsx("span",{className:"text-[10px] text-fg-muted truncate",children:mt(Ae)}),n.jsx("span",{className:"text-[10px] text-fg-muted shrink-0",children:"·"}),n.jsx("span",{className:"text-[10px] text-fg-muted shrink-0",children:od(Ae.respondedAt??Ae.requestedAt,u)})]})]},Ae.id))]})]})}),n.jsx("div",{className:"w-full shrink-0 h-full overflow-y-auto scrollbar-thin",children:G.length===0?n.jsx("div",{className:"p-6 text-center text-xs text-fg-tertiary",children:u("team:notifications.noNotifications")}):n.jsx("div",{className:"divide-y divide-border-default/50",children:G.slice(0,50).map(Ae=>{const et=W3[Ae.type]??"text-fg-tertiary";return n.jsxs("button",{onClick:()=>_e(Ae),className:`w-full text-left px-3 py-2.5 flex gap-2.5 transition-colors ${Ae.read?"opacity-50 hover:opacity-70":"hover:bg-surface-overlay"}`,children:[n.jsx("div",{className:"shrink-0 mt-0.5",children:n.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:et,children:n.jsx("path",{d:id[Ae.type]??id.system})})}),n.jsxs("div",{className:"flex-1 min-w-0",children:[n.jsxs("div",{className:"flex items-center gap-1.5",children:[!Ae.read&&n.jsx("span",{className:`w-1.5 h-1.5 rounded-full shrink-0 ${Ef[Ae.priority]??Ef.normal}`}),n.jsx("span",{className:"text-xs text-fg-primary font-medium truncate",children:Ae.title})]}),n.jsx("div",{className:"text-[11px] text-fg-tertiary mt-0.5 ",children:n.jsx(Wr,{content:Ae.body,className:"text-[11px] [&_h1]:text-xs [&_h2]:text-[11px] [&_h3]:text-[11px] [&_p]:text-[11px] [&_li]:text-[11px] [&_p]:text-fg-tertiary"})}),n.jsxs("div",{className:"flex items-center gap-2 mt-0.5",children:[n.jsx("span",{className:"text-[10px] text-fg-muted",children:od(Ae.createdAt,u)}),Mf(Ae,u)&&n.jsx("span",{className:`text-[10px] font-medium ${et}`,children:Mf(Ae,u)})]})]})]},Ae.id)})})})]})})]})}if(a){const se=d||"M18 8A6 6 0 0 0 6 8c0 7-3 9-3 9h18s-3-2-3-9 M13.73 21a2 2 0 0 1-3.46 0";return n.jsxs(n.Fragment,{children:[n.jsxs("button",{ref:B,onClick:()=>{h(!m),m||Z()},title:e?l||u("team:notifications.bellTitle"):void 0,className:`w-full flex items-center ${e?"flex-col justify-center px-1 py-1.5 gap-0.5":"gap-3 px-3 py-[7px]"} rounded-xl text-[13px] mb-0.5 transition-all relative ${m||i?"bg-brand-600 text-white shadow-sm shadow-brand-900/30 font-medium":"text-fg-secondary hover:bg-surface-overlay hover:text-fg-primary"}`,children:[n.jsx("svg",{width:e?16:18,height:e?16:18,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:"shrink-0",children:n.jsx("path",{d:se})}),e?n.jsx("span",{className:"text-[9px] leading-tight truncate w-full text-center",children:l}):n.jsx("span",{className:"truncate",children:l}),Be>0&&n.jsx("span",{className:`absolute ${e?"top-0.5 right-1":"top-1 left-[22px]"} min-w-[16px] h-4 px-1 rounded-full bg-red-500 text-white text-[10px] font-bold flex items-center justify-center leading-none`,children:Be>99?u("common:badgeOverLimit"):Be})]}),m&&lc.createPortal(n.jsx("div",{ref:D,className:"fixed bg-surface-secondary border border-border-default rounded-xl shadow-2xl z-[9999] flex flex-col overflow-hidden",style:{top:V.top,left:V.left,width:V.width,maxHeight:V.maxHeight},children:be}),document.body)]})}return n.jsxs(n.Fragment,{children:[n.jsxs("button",{ref:B,onClick:()=>{h(!m),m||Z()},className:`relative flex items-center justify-center rounded-md transition-colors ${e?"w-8 h-8":"w-7 h-7"} ${m?"bg-surface-overlay text-fg-primary":"text-fg-tertiary hover:text-fg-secondary hover:bg-surface-overlay"}`,title:u("team:notifications.bellTitle"),children:[n.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("path",{d:"M18 8A6 6 0 0 0 6 8c0 7-3 9-3 9h18s-3-2-3-9"}),n.jsx("path",{d:"M13.73 21a2 2 0 0 1-3.46 0"})]}),Be>0&&n.jsx("span",{className:"absolute -top-0.5 -right-0.5 min-w-[16px] h-4 px-1 rounded-full bg-red-500 text-white text-[10px] font-bold flex items-center justify-center leading-none",children:Be>99?u("common:badgeOverLimit"):Be})]}),m&&lc.createPortal(n.jsx("div",{ref:D,className:"fixed bg-surface-secondary border border-border-default rounded-xl shadow-2xl z-[9999] flex flex-col overflow-hidden",style:{top:V.top,left:V.left,width:V.width,maxHeight:V.maxHeight},children:be}),document.body)]})}function lse({authUser:e}){const{t}=pt("nav"),r=Rs();return n.jsxs("div",{className:"flex-1 flex flex-col overflow-hidden",children:[n.jsxs("div",{className:"flex items-center gap-2 px-4 h-14",children:[r&&n.jsx(gc,{}),n.jsx("h2",{className:"text-base font-bold",children:t("notifications")})]}),n.jsx("div",{className:"flex-1 overflow-hidden",children:n.jsx(aC,{collapsed:!1,userId:e?.id,embeddedMode:!0})})]})}function cse(){const{t:e}=pt(["common","home","work"]),[t,r]=g.useState(""),[s,a]=g.useState("all"),[i,l]=g.useState({agents:[],tasks:[],requirements:[],projects:[],deliverables:[]}),[d,u]=g.useState(!1),[m,h]=g.useState(!1),p=g.useRef(null),y=g.useRef(void 0);g.useEffect(()=>{setTimeout(()=>p.current?.focus(),100)},[]);const x=g.useCallback(async w=>{if(!w.trim()){l({agents:[],tasks:[],requirements:[],projects:[],deliverables:[]}),h(!1);return}u(!0),h(!0);const N=w.toLowerCase();try{const[S,T,E,R,I]=await Promise.allSettled([ie.agents.list(),ie.tasks.list({search:w,pageSize:20}),ie.requirements.list(),ie.projects.list(),ie.deliverables.search({q:w,limit:20})]),z=S.status==="fulfilled"?S.value.agents.filter(F=>F.name?.toLowerCase().includes(N)||F.role?.toLowerCase().includes(N)):[],B=T.status==="fulfilled"?T.value.tasks:[],D=E.status==="fulfilled"?E.value.requirements.filter(F=>F.title?.toLowerCase().includes(N)||F.description?.toLowerCase().includes(N)):[],V=R.status==="fulfilled"?R.value.projects.filter(F=>F.name?.toLowerCase().includes(N)||F.description?.toLowerCase().includes(N)):[],Y=I.status==="fulfilled"?I.value.results:[];l({agents:z,tasks:B,requirements:D,projects:V,deliverables:Y})}catch{l({agents:[],tasks:[],requirements:[],projects:[],deliverables:[]})}finally{u(!1)}},[]),v=w=>{r(w),y.current&&clearTimeout(y.current),y.current=setTimeout(()=>x(w),400)},j=[{id:"all",label:e("common:all",{defaultValue:"全部"})},{id:"agents",label:e("common:agents",{defaultValue:"智能体"})},{id:"tasks",label:e("common:tasks",{defaultValue:"任务"})},{id:"requirements",label:e("common:requirements",{defaultValue:"需求"})},{id:"projects",label:e("common:projects",{defaultValue:"项目"})},{id:"deliverables",label:e("common:deliverables",{defaultValue:"交付物"})}],C=i.agents.length>0||i.tasks.length>0||i.requirements.length>0||i.projects.length>0||i.deliverables.length>0;return n.jsxs("div",{className:"flex-1 flex flex-col overflow-hidden",children:[n.jsxs("div",{className:"shrink-0 px-4 pt-4 pb-2 space-y-3",children:[n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx("button",{onClick:()=>bt.navigate(De.HOME),className:"p-1.5 rounded-lg hover:bg-surface-overlay transition-colors shrink-0",children:n.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("path",{d:"M19 12H5"}),n.jsx("polyline",{points:"12 19 5 12 12 5"})]})}),n.jsxs("div",{className:"flex-1 relative",children:[n.jsxs("svg",{className:"absolute left-3 top-1/2 -translate-y-1/2 text-fg-tertiary",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("circle",{cx:"11",cy:"11",r:"8"}),n.jsx("line",{x1:"21",y1:"21",x2:"16.65",y2:"16.65"})]}),n.jsx("input",{ref:p,value:t,onChange:w=>v(w.target.value),placeholder:e("common:search"),className:"w-full bg-surface-elevated border border-border-default rounded-xl pl-9 pr-3 py-2.5 text-sm text-fg-primary placeholder:text-fg-tertiary focus:border-brand-500 focus:outline-none transition-colors"}),t&&n.jsx("button",{onClick:()=>{r(""),l({agents:[],tasks:[],requirements:[],projects:[],deliverables:[]}),h(!1),p.current?.focus()},className:"absolute right-3 top-1/2 -translate-y-1/2 text-fg-tertiary hover:text-fg-secondary",children:n.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),n.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]})]}),n.jsx("div",{className:"flex gap-1 overflow-x-auto scrollbar-hide",children:j.map(w=>n.jsx("button",{onClick:()=>a(w.id),className:`px-3 py-1.5 text-xs rounded-lg whitespace-nowrap transition-colors ${s===w.id?"bg-brand-600 text-white":"bg-surface-elevated text-fg-secondary hover:text-fg-primary"}`,children:w.label},w.id))})]}),n.jsxs("div",{className:"flex-1 overflow-y-auto px-4 pb-4",children:[d&&n.jsx("div",{className:"flex items-center justify-center py-12",children:n.jsx("div",{className:"text-fg-tertiary text-sm animate-pulse",children:e("common:loading")})}),!d&&m&&!C&&n.jsxs("div",{className:"flex flex-col items-center justify-center py-12 text-center",children:[n.jsxs("svg",{width:"40",height:"40",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",className:"text-fg-tertiary mb-3",children:[n.jsx("circle",{cx:"11",cy:"11",r:"8"}),n.jsx("line",{x1:"21",y1:"21",x2:"16.65",y2:"16.65"})]}),n.jsx("p",{className:"text-sm text-fg-tertiary",children:e("common:noResults",{defaultValue:"没有找到相关结果"})})]}),!d&&C&&n.jsxs("div",{className:"space-y-4",children:[(s==="all"||s==="agents")&&i.agents.length>0&&n.jsxs("section",{children:[n.jsx("h3",{className:"text-xs font-medium text-fg-tertiary uppercase mb-2",children:e("common:agents",{defaultValue:"智能体"})}),n.jsx("div",{className:"space-y-1",children:(s==="all"?i.agents.slice(0,8):i.agents).map(w=>n.jsxs("button",{onClick:()=>bt.navigate(De.TEAM,{agentId:w.id}),className:"w-full flex items-center gap-3 px-3 py-2.5 rounded-xl hover:bg-surface-overlay transition-colors text-left",children:[n.jsx(Nr,{name:w.name||"Agent",avatarUrl:w.avatarUrl,size:32}),n.jsxs("div",{className:"flex-1 min-w-0",children:[n.jsx("div",{className:"text-sm font-medium text-fg-primary truncate",children:w.name}),n.jsx("div",{className:"text-xs text-fg-tertiary truncate",children:w.role||w.status})]}),n.jsx(dse,{status:w.status})]},w.id))}),s==="all"&&i.agents.length>8&&n.jsxs("button",{onClick:()=>a("agents"),className:"mt-1 w-full text-xs text-brand-500 hover:text-brand-400 py-1.5 rounded-lg hover:bg-surface-overlay transition-colors",children:[e("common:showAll",{defaultValue:"查看全部"})," (",i.agents.length,")"]})]}),(s==="all"||s==="tasks")&&i.tasks.length>0&&n.jsxs("section",{children:[n.jsx("h3",{className:"text-xs font-medium text-fg-tertiary uppercase mb-2",children:e("common:tasks",{defaultValue:"任务"})}),n.jsx("div",{className:"space-y-1",children:(s==="all"?i.tasks.slice(0,8):i.tasks).map(w=>n.jsxs("button",{onClick:()=>bt.navigate(De.WORK,{openTask:w.id}),className:"w-full flex items-center gap-3 px-3 py-2.5 rounded-xl hover:bg-surface-overlay transition-colors text-left",children:[n.jsx(use,{status:w.status}),n.jsxs("div",{className:"flex-1 min-w-0",children:[n.jsx("div",{className:"text-sm text-fg-primary truncate",children:w.title}),n.jsxs("div",{className:"text-xs text-fg-tertiary truncate",children:[w.status," · ",w.priority||""]})]})]},w.id))}),s==="all"&&i.tasks.length>8&&n.jsxs("button",{onClick:()=>a("tasks"),className:"mt-1 w-full text-xs text-brand-500 hover:text-brand-400 py-1.5 rounded-lg hover:bg-surface-overlay transition-colors",children:[e("common:showAll",{defaultValue:"查看全部"})," (",i.tasks.length,")"]})]}),(s==="all"||s==="requirements")&&i.requirements.length>0&&n.jsxs("section",{children:[n.jsx("h3",{className:"text-xs font-medium text-fg-tertiary uppercase mb-2",children:e("common:requirements",{defaultValue:"需求"})}),n.jsx("div",{className:"space-y-1",children:(s==="all"?i.requirements.slice(0,8):i.requirements).map(w=>n.jsxs("button",{onClick:()=>bt.navigate(De.WORK,{openRequirement:w.id}),className:"w-full flex items-center gap-3 px-3 py-2.5 rounded-xl hover:bg-surface-overlay transition-colors text-left",children:[n.jsx("div",{className:`w-8 h-8 rounded-lg flex items-center justify-center shrink-0 ${w.status==="approved"?"text-green-500 bg-green-500/15":w.status==="pending"?"text-amber-500 bg-amber-500/15":w.status==="rejected"?"text-red-500 bg-red-500/15":"text-fg-tertiary bg-surface-elevated"}`,children:n.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[n.jsx("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),n.jsx("polyline",{points:"14 2 14 8 20 8"}),n.jsx("line",{x1:"16",y1:"13",x2:"8",y2:"13"}),n.jsx("line",{x1:"16",y1:"17",x2:"8",y2:"17"})]})}),n.jsxs("div",{className:"flex-1 min-w-0",children:[n.jsx("div",{className:"text-sm text-fg-primary truncate",children:w.title}),n.jsxs("div",{className:"text-xs text-fg-tertiary truncate",children:[w.status," · ",w.priority||""]})]})]},w.id))}),s==="all"&&i.requirements.length>8&&n.jsxs("button",{onClick:()=>a("requirements"),className:"mt-1 w-full text-xs text-brand-500 hover:text-brand-400 py-1.5 rounded-lg hover:bg-surface-overlay transition-colors",children:[e("common:showAll",{defaultValue:"查看全部"})," (",i.requirements.length,")"]})]}),(s==="all"||s==="projects")&&i.projects.length>0&&n.jsxs("section",{children:[n.jsx("h3",{className:"text-xs font-medium text-fg-tertiary uppercase mb-2",children:e("common:projects",{defaultValue:"项目"})}),n.jsx("div",{className:"space-y-1",children:(s==="all"?i.projects.slice(0,8):i.projects).map(w=>n.jsxs("button",{onClick:()=>bt.navigate(De.WORK,{projectId:w.id}),className:"w-full flex items-center gap-3 px-3 py-2.5 rounded-xl hover:bg-surface-overlay transition-colors text-left",children:[n.jsx("div",{className:"w-8 h-8 rounded-lg bg-teal-500/15 flex items-center justify-center shrink-0",children:n.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:"text-teal-500",children:n.jsx("path",{d:"M22 19a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h5l2 3h9a2 2 0 0 1 2 2z"})})}),n.jsxs("div",{className:"flex-1 min-w-0",children:[n.jsx("div",{className:"text-sm text-fg-primary truncate",children:w.name}),w.description&&n.jsx("div",{className:"text-xs text-fg-tertiary truncate",children:w.description})]})]},w.id))}),s==="all"&&i.projects.length>8&&n.jsxs("button",{onClick:()=>a("projects"),className:"mt-1 w-full text-xs text-brand-500 hover:text-brand-400 py-1.5 rounded-lg hover:bg-surface-overlay transition-colors",children:[e("common:showAll",{defaultValue:"查看全部"})," (",i.projects.length,")"]})]}),(s==="all"||s==="deliverables")&&i.deliverables.length>0&&n.jsxs("section",{children:[n.jsx("h3",{className:"text-xs font-medium text-fg-tertiary uppercase mb-2",children:e("common:deliverables",{defaultValue:"交付物"})}),n.jsx("div",{className:"space-y-1",children:(s==="all"?i.deliverables.slice(0,8):i.deliverables).map(w=>n.jsxs("button",{onClick:()=>bt.navigate(De.DELIVERABLES,{openDeliverable:w.id}),className:"w-full flex items-center gap-3 px-3 py-2.5 rounded-xl hover:bg-surface-overlay transition-colors text-left",children:[n.jsx("div",{className:"w-8 h-8 rounded-lg bg-purple-500/15 flex items-center justify-center shrink-0",children:n.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:"text-purple-500",children:[n.jsx("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),n.jsx("polyline",{points:"14 2 14 8 20 8"})]})}),n.jsxs("div",{className:"flex-1 min-w-0",children:[n.jsx("div",{className:"text-sm text-fg-primary truncate",children:w.title}),n.jsxs("div",{className:"text-xs text-fg-tertiary truncate",children:[w.type," · ",w.status]})]})]},w.id))}),s==="all"&&i.deliverables.length>8&&n.jsxs("button",{onClick:()=>a("deliverables"),className:"mt-1 w-full text-xs text-brand-500 hover:text-brand-400 py-1.5 rounded-lg hover:bg-surface-overlay transition-colors",children:[e("common:showAll",{defaultValue:"查看全部"})," (",i.deliverables.length,")"]})]})]}),!d&&!m&&n.jsxs("div",{className:"flex flex-col items-center justify-center py-12 text-center",children:[n.jsxs("svg",{width:"40",height:"40",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",className:"text-fg-tertiary mb-3",children:[n.jsx("circle",{cx:"11",cy:"11",r:"8"}),n.jsx("line",{x1:"21",y1:"21",x2:"16.65",y2:"16.65"})]}),n.jsx("p",{className:"text-sm text-fg-tertiary",children:e("common:search")})]})]})]})}function dse({status:e}){const t=e==="active"||e==="idle"?"bg-green-500":e==="working"||e==="busy"?"bg-blue-500":e==="paused"?"bg-amber-500":"bg-gray-400";return n.jsx("span",{className:`w-2 h-2 rounded-full shrink-0 ${t}`})}function use({status:e}){const t=e==="completed"?"text-green-500 bg-green-500/15":e==="in_progress"?"text-blue-500 bg-blue-500/15":e==="pending"?"text-amber-500 bg-amber-500/15":"text-fg-tertiary bg-surface-elevated";return n.jsx("div",{className:`w-8 h-8 rounded-lg flex items-center justify-center shrink-0 ${t}`,children:n.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[n.jsx("path",{d:"M9 11l3 3L22 4"}),n.jsx("path",{d:"M21 12v7a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h11"})]})})}function mse({d:e,size:t=18}){return n.jsx("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:"shrink-0",children:n.jsx("path",{d:e})})}function fse({currentPage:e,onNavigate:t,authUser:r,collapsed:s,onToggleCollapse:a}){const{t:i}=pt(["nav","common"]);return n.jsxs("aside",{className:"h-dvh bg-surface-secondary flex flex-col shrink-0 overflow-hidden rounded-r-2xl",children:[n.jsx("div",{className:`flex items-center ${s?"px-2 py-3.5 justify-center":"px-4 h-14 justify-between"}`,children:n.jsxs("button",{onClick:a,title:i(s?"sidebar.expandSidebar":"sidebar.collapseSidebar"),className:"flex items-center gap-2.5 min-w-0 group",children:[n.jsx("img",{src:"/logo.png",alt:"Markus",className:"w-8 h-8 rounded-lg shadow-md shadow-black/30 shrink-0 group-hover:ring-2 group-hover:ring-brand-500/40 transition-all"}),!s&&n.jsx("span",{className:"text-[15px] font-bold tracking-tight text-fg-primary whitespace-nowrap",children:"Markus"})]})}),n.jsx("nav",{className:`${s?"p-1":"px-3 py-2"} flex-1 overflow-y-auto scrollbar-thin`,children:B_.map((l,d)=>{const u=i(`sections.${l.key}`);return n.jsx("div",{children:n.jsxs("div",{className:d>0?"mt-3":"",children:[!s&&u&&n.jsx("div",{className:"px-3 py-1.5 mb-1 text-[10px] font-semibold text-fg-muted uppercase tracking-[0.1em]",children:u}),s&&d>0&&n.jsx("div",{className:"my-3"}),H_.filter(m=>m.section===l.key).map(m=>{if(m.id===De.NOTIFICATIONS)return n.jsx(aC,{sidebarMode:!0,collapsed:s,userId:r?.id,label:i(m.id),iconPath:pb[m.id],isActive:e===m.id},m.id);const h=e===m.id;return n.jsxs("button",{onClick:()=>t(m.id),title:s?i(m.id):void 0,className:`w-full flex items-center ${s?"flex-col justify-center px-1 py-1.5 gap-0.5":"gap-3 px-3 py-[7px]"} rounded-xl text-[13px] mb-0.5 transition-all ${h?"bg-brand-600 text-white shadow-sm shadow-brand-900/30 font-medium":"text-fg-secondary hover:bg-surface-overlay hover:text-fg-primary"}`,children:[n.jsx(mse,{d:pb[m.id]??"",size:s?16:18}),s?n.jsx("span",{className:"text-[9px] leading-tight truncate w-full text-center",children:i(m.id)}):n.jsx("span",{className:"truncate",children:i(m.id)})]},m.id)})]})},l.key)})}),!s&&n.jsxs("div",{className:"px-4 pb-2 text-[10px] text-fg-muted",children:["v","0.8.1"]})]})}function hse({currentPage:e,onNavigate:t,userId:r}){const{t:s}=pt("nav"),[a,i]=g.useState(0),{counts:l}=XS({enabled:!0}),d=g.useMemo(()=>{let m=0;for(const h of Object.values(l))m+=h;return m},[l]),u=g.useCallback(async()=>{try{const m=await ie.notifications.list(r,!1);i(m.unreadCount??m.notifications.filter(h=>!h.read).length)}catch{}},[r]);return g.useEffect(()=>{u();const m=setInterval(u,15e3),h=()=>u();return window.addEventListener("markus:notifications-changed",h),()=>{clearInterval(m),window.removeEventListener("markus:notifications-changed",h)}},[u]),n.jsx("nav",{className:"fixed bottom-0 left-0 right-0 z-50 bg-surface-secondary flex items-stretch h-14 safe-area-bottom",children:F_.map(m=>{const h=m.group.includes(e),p=m.id===De.NOTIFICATIONS,y=m.id===De.TEAM;return n.jsxs("button",{onClick:()=>t(m.id),className:`flex-1 flex flex-col items-center justify-center gap-0.5 transition-colors ${h?"text-brand-500":"text-fg-tertiary active:text-fg-secondary"}`,children:[n.jsxs("div",{className:"relative",children:[n.jsx("svg",{width:20,height:20,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:h?2:1.75,strokeLinecap:"round",strokeLinejoin:"round",className:"shrink-0",children:n.jsx("path",{d:pb[m.id]})}),p&&a>0&&n.jsx("span",{className:"absolute -top-1.5 -right-2 min-w-[16px] h-4 px-1 flex items-center justify-center bg-red-500 text-white text-[9px] font-bold rounded-full leading-none",children:a>99?"99+":a}),y&&d>0&&n.jsx("span",{className:"absolute -top-1.5 -right-2 min-w-[16px] h-4 px-1 flex items-center justify-center bg-red-500 text-white text-[9px] font-bold rounded-full leading-none",children:d>99?"99+":d})]}),n.jsx("span",{className:`text-[10px] leading-tight ${h?"font-semibold":""}`,children:s(m.id)})]},m.id)})})}const iC=["builder","agents","teams","skills"];function pse(){const e=localStorage.getItem("markus_nav_storeTab");return e&&(localStorage.removeItem("markus_nav_storeTab"),iC.includes(e))?e:"builder"}function gse({authUser:e}){const{t}=pt(["nav","common"]),r=g.useMemo(()=>[{id:"builder",label:t("nav:builder")},{id:"agents",label:t("nav:tabs.agents")},{id:"teams",label:t("nav:tabs.teams")},{id:"skills",label:t("nav:tabs.skills")}],[t]),[s,a]=g.useState(pse),i=Sl(r,s,a);return g.useEffect(()=>{const l=d=>{const u=d.detail;u.params?.storeTab&&iC.includes(u.params.storeTab)&&a(u.params.storeTab)};return window.addEventListener("markus:navigate",l),()=>window.removeEventListener("markus:navigate",l)},[]),n.jsxs("div",{className:"flex-1 overflow-hidden flex flex-col",onTouchStart:i.onTouchStart,onTouchEnd:i.onTouchEnd,children:[n.jsxs("div",{className:"flex items-center shrink-0 overflow-x-auto scrollbar-hide",children:[n.jsx(gc,{className:"ml-2"}),r.map(l=>n.jsx("button",{onClick:()=>a(l.id),className:`flex-1 min-w-0 px-3 py-2.5 text-xs font-medium text-center whitespace-nowrap transition-colors border-b-2 ${s===l.id?"border-brand-500 text-brand-500":"border-transparent text-fg-tertiary"}`,children:l.label},l.id))]}),n.jsxs("div",{className:"flex-1 overflow-hidden flex flex-col",children:[s==="builder"&&n.jsx(e7,{}),s==="agents"&&n.jsx(r7,{authUser:e}),s==="teams"&&n.jsx(i7,{}),s==="skills"&&n.jsx(o7,{})]})]})}const G3="usageType",cb="profile",Y3="llm",X3="search";function xse({onComplete:e,theme:t,onThemeChange:r,skipProfile:s}){const{t:a}=pt(["onboarding","common"]),[i,l]=g.useState(0),[d,u]=g.useState(""),[m,h]=g.useState(""),[p,y]=g.useState(""),[x,v]=g.useState(""),[j,C]=g.useState(!1),[w,N]=g.useState(""),[S,T]=g.useState(!1),[E,R]=g.useState(null);g.useEffect(()=>{ie.auth.me().then(({user:ve})=>{ve.name&&u(ve.name),ve.email&&h(ve.email),ve.avatarUrl&&R(ve.avatarUrl);const tt=ve.name||ve.email?.split("@")[0]||"";tt&&be(a("usageType.defaultOrgName",{name:tt}))}).catch(()=>{}),ie.hubOrgs.invitations().then(ve=>{ve.invitations?.length>0&&pe(ve.invitations)}).catch(()=>{})},[]);const[I,z]=g.useState(null),[B,D]=g.useState(!1),[V,Y]=g.useState({}),[F,L]=g.useState(!1),[O,M]=g.useState(!1),[$,W]=g.useState([]),[U,H]=g.useState(null),[q,Z]=g.useState(!0),[_,J]=g.useState(""),X=g.useRef(!1),[ee,te]=g.useState({}),[G,ue]=g.useState({}),[Se,Ce]=g.useState("anthropic"),[Be,Ne]=g.useState(""),[he,_e]=g.useState(!1),[Ee,Ye]=g.useState([]),[Ze,mt]=g.useState(""),[it,Lt]=g.useState(""),[ht,ne]=g.useState(null),[me,be]=g.useState(""),[se,fe]=g.useState(!1),[He,Ae]=g.useState(!1),[et,pe]=g.useState([]),[Fe,Ve]=g.useState(null),[nt,gt]=g.useState(null),[rt,Et]=g.useState(!0),[je,Re]=g.useState(null),[We,Vt]=g.useState({serperApiKey:"",tavilyApiKey:"",bingApiKey:"",googleSearchApiKey:"",googleSearchCx:"",serpApiKey:"",braveApiKey:"",exaApiKey:"",bochaApiKey:""}),[ln,en]=g.useState(!1),[vn,In]=g.useState(!1),[Zt,cn]=g.useState(null),Gn=g.useRef(!1),Ln=()=>({"Content-Type":"application/json",Authorization:`Bearer ${localStorage.getItem("markus_token")??""}`});g.useEffect(()=>{fetch("/api/settings/llm").then(ve=>ve.ok?ve.json():null).then(ve=>{if(ve?.providers){const tt=Object.entries(ve.providers).filter(([,Tt])=>Tt.configured).map(([Tt,$t])=>({name:Tt,displayName:$t.displayName??Tt,model:$t.model??"",apiKeyPreview:$t.apiKeyPreview}));tt.length>0&&(M(!0),W(tt))}ve?.defaultProvider&&J(ve.defaultProvider),typeof ve?.autoFallback=="boolean"&&Z(ve.autoFallback)}).catch(()=>{})},[]);const Lr=s?3:4;g.useEffect(()=>{i===Lr&&!X.current&&!O&&(X.current=!0,mr())},[i,O,Lr]);const Qr=s?4:5;g.useEffect(()=>{i===Qr&&!Gn.current&&(Gn.current=!0,tn())},[i,Qr]);const mr=async()=>{D(!0);try{const ve=await fetch("/api/settings/env-models",{headers:Ln()});if(ve.ok){const tt=await ve.json();if(z(tt),tt.detected.length>0){const Tt={},$t={};for(const sn of tt.detected)Tt[sn.provider]=!0,$t[sn.provider]=sn.model;Y(Tt),ue($t);for(const sn of tt.detected)ie.modelCatalog.getByProvider(sn.provider).then(Zn=>{te(Xt=>({...Xt,[sn.provider]:Zn.models}))}).catch(()=>{})}}}catch{}finally{D(!1)}},Ge=async()=>{if(Be.trim()){_e(!0),Lt(""),Ye([]);try{const ve=await ie.modelCatalog.validateKey(Se,Be.trim());ve.valid?(Ye(ve.models),ve.models.length>0&&mt(ve.models[0].id)):(Lt(ve.error||"Invalid API key"),ve.models.length>0&&(Ye(ve.models),mt(ve.models[0].id)))}catch(ve){Lt(ve instanceof Error?ve.message:"Validation failed")}finally{_e(!1)}}},Ht=async()=>{if(Ze){L(!0),H(null);try{const ve=await fetch("/api/settings/llm/providers",{method:"POST",headers:Ln(),body:JSON.stringify({name:Se,apiKey:Be.trim(),model:Ze})});if(ve.ok)M(!0),J(Se),W([{name:Se,displayName:Se,model:Ze}]),H({type:"ok",text:`Provider ${Se} configured successfully`});else{const tt=await ve.json();H({type:"err",text:tt.error||"Failed to add provider"})}}catch{H({type:"err",text:"Network error"})}finally{L(!1)}}},Wt=async()=>{if(!I)return;const ve=I.detected.filter(tt=>V[tt.provider]);if(ve.length!==0){L(!0),H(null);try{const tt=await fetch("/api/settings/env-models",{method:"POST",headers:Ln(),body:JSON.stringify({providers:ve.map(Tt=>({provider:Tt.provider,model:G[Tt.provider]||Tt.model,baseUrl:Tt.baseUrl,enabled:!0}))})});if(tt.ok){const Tt=await tt.json();if(Tt.settings?.providers){const sn=Object.entries(Tt.settings.providers).filter(([,Zn])=>Zn.configured).map(([Zn,Xt])=>({name:Zn,displayName:Xt.displayName??Zn,model:Xt.model??"",apiKeyPreview:Xt.apiKeyPreview}));W(sn)}else W(ve.map(sn=>({name:sn.provider,displayName:sn.displayName,model:sn.model,apiKeyPreview:sn.apiKeyPreview})));const $t=Tt.settings?.defaultProvider||Tt.applied[0]||ve[0]?.provider||"";J($t),$t&&fetch("/api/settings/llm",{method:"POST",headers:Ln(),body:JSON.stringify({defaultProvider:$t})}).catch(()=>{}),H({type:"ok",text:Tt.message}),M(!0)}else H({type:"err",text:a("llm.failedToApply")})}catch{H({type:"err",text:a("common:networkError")})}finally{L(!1)}}},tn=async()=>{try{const ve=await fetch("/api/settings/search",{headers:Ln()});if(ve.ok){const tt=await ve.json();Re(tt),tt&&(tt.serper.configured||tt.tavily.configured||tt.bing.configured||tt.google.configured||tt.serpapi.configured||tt.brave.configured||tt.exa.configured||tt.bocha.configured)&&In(!0)}}catch{}},zn=async()=>{if(We.serperApiKey||We.tavilyApiKey||We.bingApiKey||We.googleSearchApiKey||We.googleSearchCx||We.serpApiKey||We.braveApiKey||We.exaApiKey||We.bochaApiKey){en(!0),cn(null);try{const tt={};We.serperApiKey&&(tt.serperApiKey=We.serperApiKey),We.tavilyApiKey&&(tt.tavilyApiKey=We.tavilyApiKey),We.bingApiKey&&(tt.bingApiKey=We.bingApiKey),We.googleSearchApiKey&&(tt.googleSearchApiKey=We.googleSearchApiKey),We.googleSearchCx&&(tt.googleSearchCx=We.googleSearchCx),We.serpApiKey&&(tt.serpApiKey=We.serpApiKey),We.braveApiKey&&(tt.braveApiKey=We.braveApiKey),We.exaApiKey&&(tt.exaApiKey=We.exaApiKey),We.bochaApiKey&&(tt.bochaApiKey=We.bochaApiKey);const Tt=await fetch("/api/settings/search",{method:"POST",headers:Ln(),body:JSON.stringify(tt)});if(Tt.ok){const $t=await Tt.json();Re($t),In(!0),Vt({serperApiKey:"",tavilyApiKey:"",bingApiKey:"",googleSearchApiKey:"",googleSearchCx:"",serpApiKey:"",braveApiKey:"",exaApiKey:"",bochaApiKey:""}),cn({type:"ok",text:a("search.saved")})}else cn({type:"err",text:a("search.failedToSave")})}catch{cn({type:"err",text:a("common:networkError")})}finally{en(!1)}}},Mn=async()=>{if(N(""),!d.trim()){N(a("profile.errors.nameRequired"));return}if(!m.trim()){N(a("profile.errors.emailRequired"));return}if(!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(m.trim())){N(a("profile.errors.emailInvalid"));return}if(p&&p.length<6){N(a("profile.errors.passwordTooShort"));return}if(p&&p!==x){N(a("profile.errors.passwordMismatch"));return}C(!0);try{await ie.auth.updateProfile(d.trim(),m.trim()),p&&await ie.auth.changePassword("",p),T(!0)}catch{N(a("profile.errors.saveFailed"))}finally{C(!1)}},wn=[{value:"system",label:a("theme.system"),icon:"💻",desc:a("theme.systemDesc")},{value:"light",label:a("theme.light"),icon:"☀️",desc:a("theme.lightDesc")},{value:"dark",label:a("theme.dark"),icon:"🌊",desc:a("theme.darkDesc")},{value:"cyberpunk",label:a("theme.cyberpunk"),icon:"🔮",desc:a("theme.cyberpunkDesc")},{value:"mono",label:a("theme.mono"),icon:"⬛",desc:a("theme.monoDesc")}],Dn=[{id:"welcome",title:a("welcome.title"),subtitle:a("welcome.subtitle"),content:n.jsxs("div",{className:"space-y-4 text-fg-secondary text-sm leading-relaxed",children:[n.jsx("p",{className:"text-fg-secondary",children:n.jsx(n0,{i18nKey:"welcome.description",ns:"onboarding",components:{strong:n.jsx("strong",{className:"text-fg-primary"})}})}),n.jsx("div",{className:"grid grid-cols-2 gap-3 mt-6",children:[[a("welcome.features.operation"),a("welcome.features.operationDesc")],[a("welcome.features.collaboration"),a("welcome.features.collaborationDesc")],[a("welcome.features.memory"),a("welcome.features.memoryDesc")],[a("welcome.features.anyLlm"),a("welcome.features.anyLlmDesc")]].map(([ve,tt])=>n.jsxs("div",{className:"bg-surface-elevated/50 rounded-lg p-3",children:[n.jsx("div",{className:"font-medium text-fg-primary text-xs",children:ve}),n.jsx("div",{className:"text-fg-secondary text-xs mt-1",children:tt})]},ve))})]})},{id:G3,title:a("usageType.title",{defaultValue:"How will you use Markus?"}),subtitle:a("usageType.subtitle",{defaultValue:"This helps us tailor your experience."}),content:n.jsxs("div",{className:"space-y-4",children:[n.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[n.jsxs("button",{onClick:()=>{ne("personal"),Ae(!0)},className:`flex flex-col items-center gap-3 rounded-xl border-2 p-5 transition-all text-left ${ht==="personal"?"border-brand-500 bg-brand-500/10":"border-border-default hover:border-fg-tertiary bg-surface-elevated/30"}`,children:[n.jsx("span",{className:"text-2xl",children:"👤"}),n.jsxs("div",{children:[n.jsx("div",{className:"font-medium text-fg-primary text-sm text-center",children:a("usageType.personal",{defaultValue:"Personal"})}),n.jsx("div",{className:"text-[11px] text-fg-tertiary mt-1 text-center",children:a("usageType.personalDesc",{defaultValue:"Individual use with your own AI agents."})})]})]}),n.jsxs("button",{onClick:()=>{ne("organization"),Ae(!1)},className:`flex flex-col items-center gap-3 rounded-xl border-2 p-5 transition-all text-left ${ht==="organization"?"border-brand-500 bg-brand-500/10":"border-border-default hover:border-fg-tertiary bg-surface-elevated/30"}`,children:[n.jsx("span",{className:"text-2xl",children:"🏢"}),n.jsxs("div",{children:[n.jsx("div",{className:"font-medium text-fg-primary text-sm text-center",children:a("usageType.organization",{defaultValue:"Team & Enterprise"})}),n.jsx("div",{className:"text-[11px] text-fg-tertiary mt-1 text-center",children:a("usageType.organizationDesc",{defaultValue:"For teams sharing licenses and collaborating."})})]})]})]}),ht==="organization"&&n.jsxs("div",{className:"space-y-4 mt-4",children:[et.length>0&&n.jsxs("div",{className:"space-y-2",children:[n.jsx("div",{className:"text-xs text-fg-tertiary font-medium",children:a("usageType.pendingInvitations")}),et.map(ve=>n.jsxs("div",{className:"flex items-center justify-between px-4 py-3 rounded-xl border border-amber-500/20 bg-amber-500/5",children:[n.jsxs("div",{children:[n.jsx("div",{className:"text-sm font-medium text-fg-primary",children:ve.orgName}),n.jsx("div",{className:"text-[11px] text-fg-tertiary",children:a("usageType.invitedBy",{name:ve.invitedBy})})]}),n.jsx("button",{onClick:async()=>{Ve(ve.orgId);try{await ie.hubOrgs.acceptInvitation(ve.orgId),gt(ve.orgId),Ae(!0)}catch{}finally{Ve(null)}},disabled:Fe===ve.orgId||nt===ve.orgId,className:"px-3 py-1.5 text-xs rounded-lg bg-brand-600 hover:bg-brand-500 disabled:opacity-40 text-white transition-colors",children:nt===ve.orgId?a("usageType.accepted"):Fe===ve.orgId?a("usageType.accepting"):a("usageType.acceptAndJoin")})]},ve.orgId)),n.jsx("div",{className:"text-[11px] text-fg-tertiary text-center pt-1",children:a("usageType.orCreateNew")})]}),n.jsxs("div",{className:"space-y-1",children:[n.jsx("label",{className:"text-xs text-fg-tertiary font-medium",children:a("usageType.orgNameLabel")}),n.jsx("input",{type:"text",value:me,onChange:ve=>{be(ve.target.value),Ae(!1)},placeholder:a("usageType.orgNamePlaceholder"),className:"w-full px-4 py-2.5 bg-surface-elevated border border-border-default rounded-xl text-sm text-fg-primary focus:border-brand-500 outline-none transition-colors"})]}),n.jsx("button",{onClick:async()=>{if(me.trim()){fe(!0);try{const tt=(await ie.license.get()).defaultOrg;tt?.id&&await ie.hubOrgs.update(tt.id,{name:me.trim()}),Ae(!0)}catch{}finally{fe(!1)}}},disabled:se||!me.trim()||He,className:"w-full px-4 py-2.5 bg-brand-600 hover:bg-brand-500 disabled:opacity-40 text-white text-sm rounded-xl transition-colors",children:a(se?"common:saving":He?"usageType.orgNameSaved":"usageType.setOrgName")})]})]})},{id:cb,title:a("profile.title"),subtitle:a("profile.subtitle"),content:S?n.jsxs("div",{className:"flex items-center gap-3 bg-green-500/10 border border-green-500/30 rounded-xl p-4",children:[n.jsx("span",{className:"text-green-600 text-lg",children:"✓"}),n.jsxs("div",{children:[n.jsx("div",{className:"text-sm font-medium text-green-600",children:a("profile.saved")}),n.jsxs("div",{className:"text-xs text-fg-secondary mt-0.5",children:[d," · ",m]})]})]}):n.jsxs("div",{className:"space-y-4",children:[n.jsx("div",{className:"flex justify-center",children:n.jsx(y6,{currentUrl:E,name:d,size:64,targetType:"user"})}),n.jsxs("div",{className:"space-y-1",children:[n.jsxs("label",{className:"text-xs text-fg-tertiary font-medium",children:[a("profile.nameLabel")," ",n.jsx("span",{className:"text-red-500",children:"*"})]}),n.jsx("input",{type:"text",value:d,onChange:ve=>u(ve.target.value),placeholder:a("profile.namePlaceholder"),className:"w-full px-4 py-2.5 bg-surface-elevated border border-border-default rounded-xl text-sm text-fg-primary focus:border-brand-500 outline-none transition-colors",autoFocus:!0})]}),n.jsxs("div",{className:"space-y-1",children:[n.jsxs("label",{className:"text-xs text-fg-tertiary font-medium",children:[a("profile.emailLabel")," ",n.jsx("span",{className:"text-red-500",children:"*"})]}),n.jsx("input",{type:"email",value:m,onChange:ve=>h(ve.target.value),placeholder:a("profile.emailPlaceholder"),className:"w-full px-4 py-2.5 bg-surface-elevated border border-border-default rounded-xl text-sm text-fg-primary focus:border-brand-500 outline-none transition-colors"})]}),n.jsxs("div",{className:"space-y-1",children:[n.jsx("label",{className:"text-xs text-fg-tertiary font-medium",children:a("profile.newPasswordLabel")}),n.jsx("input",{type:"password",value:p,onChange:ve=>y(ve.target.value),placeholder:a("profile.newPasswordPlaceholder"),className:"w-full px-4 py-2.5 bg-surface-elevated border border-border-default rounded-xl text-sm text-fg-primary focus:border-brand-500 outline-none transition-colors"})]}),p&&n.jsxs("div",{className:"space-y-1",children:[n.jsx("label",{className:"text-xs text-fg-tertiary font-medium",children:a("profile.confirmPasswordLabel")}),n.jsx("input",{type:"password",value:x,onChange:ve=>v(ve.target.value),placeholder:a("profile.confirmPasswordPlaceholder"),className:"w-full px-4 py-2.5 bg-surface-elevated border border-border-default rounded-xl text-sm text-fg-primary focus:border-brand-500 outline-none transition-colors"})]}),w&&n.jsx("div",{className:"px-3 py-2 bg-red-500/10 border border-red-500/30 rounded-lg text-xs text-red-500",children:w}),n.jsx("button",{onClick:()=>{Mn()},disabled:j||!d.trim()||!m.trim(),className:"w-full px-4 py-2.5 bg-brand-600 hover:bg-brand-500 disabled:opacity-40 text-white text-sm rounded-xl transition-colors",children:a(j?"common:saving":"profile.saveProfile")})]})},{id:"theme",title:a("theme.title"),subtitle:a("theme.subtitle"),content:n.jsx("div",{className:"grid grid-cols-3 gap-3",children:wn.map(ve=>n.jsxs("button",{onClick:()=>r(ve.value),className:`flex flex-col items-center gap-2 rounded-xl border-2 p-5 transition-all ${t===ve.value?"border-brand-500 bg-brand-500/10":"border-border-default hover:border-fg-tertiary bg-surface-elevated/30"}`,children:[n.jsx("span",{className:"text-2xl",children:ve.icon}),n.jsx("span",{className:"text-sm font-medium text-fg-primary",children:ve.label}),n.jsx("span",{className:"text-[11px] text-fg-tertiary leading-tight text-center",children:ve.desc})]},ve.value))})},{id:Y3,title:a("llm.title"),subtitle:a("llm.subtitle"),content:O?n.jsxs("div",{className:"space-y-2",children:[n.jsxs("div",{className:"flex items-center gap-2 text-green-600 text-sm font-medium mb-1",children:[n.jsx("span",{children:"✓"}),n.jsx("span",{children:a("llm.configured")})]}),$.length>1&&n.jsx("div",{className:"text-xs text-fg-secondary mb-1",children:a("llm.selectDefault")}),$.map(ve=>{const tt=_===ve.name;return n.jsxs("button",{onClick:async()=>{const Tt=_;J(ve.name);try{await fetch("/api/settings/llm",{method:"POST",headers:Ln(),body:JSON.stringify({defaultProvider:ve.name})})}catch{J(Tt)}},className:`w-full flex items-center justify-between rounded-lg px-4 py-2.5 text-left transition-colors ${tt?"bg-brand-500/15 border-2 border-brand-500":"bg-green-500/10 border border-green-500/30 hover:border-brand-500/50"}`,children:[n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx("span",{className:`w-3.5 h-3.5 rounded-full border-2 flex items-center justify-center shrink-0 ${tt?"border-brand-500":"border-fg-tertiary"}`,children:tt&&n.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-brand-500"})}),n.jsx("span",{className:"text-sm text-fg-primary font-medium",children:ve.displayName}),ve.model&&n.jsx("span",{className:"text-xs text-fg-tertiary",children:ve.model}),tt&&n.jsx("span",{className:"text-[10px] text-brand-500 font-medium",children:a("llm.default")})]}),ve.apiKeyPreview&&n.jsx("code",{className:"text-[10px] text-fg-tertiary",children:ve.apiKeyPreview})]},ve.name)}),n.jsx("div",{className:"text-xs text-fg-secondary mt-1",children:a("llm.configuredHint")}),n.jsxs("div",{className:"flex items-center justify-between bg-surface-elevated/40 rounded-lg px-4 py-3 mt-3",children:[n.jsxs("div",{children:[n.jsx("div",{className:"text-xs font-medium text-fg-primary",children:a("llm.autoFallback")}),n.jsx("div",{className:"text-[11px] text-fg-tertiary mt-0.5",children:a("llm.autoFallbackDesc")})]}),n.jsx("button",{onClick:async()=>{const ve=!q;Z(ve);try{await fetch("/api/settings/llm",{method:"POST",headers:Ln(),body:JSON.stringify({autoFallback:ve})})}catch{Z(!ve)}},className:`relative inline-flex h-5 w-9 items-center rounded-full transition-colors shrink-0 ${q?"bg-green-500":"bg-gray-600"}`,children:n.jsx("span",{className:`inline-block h-3.5 w-3.5 rounded-full bg-white transition-transform ${q?"translate-x-4":"translate-x-1"}`})})]})]}):n.jsxs("div",{className:"space-y-4",children:[B&&n.jsxs("div",{className:"flex items-center gap-2 text-xs text-fg-tertiary animate-pulse",children:[n.jsx("div",{className:"w-3 h-3 border-2 border-brand-500 border-t-transparent rounded-full animate-spin"}),a("llm.detectingKeys")]}),I&&I.detected.length>0&&n.jsxs("div",{className:"space-y-3",children:[n.jsxs("div",{className:"flex items-center gap-2 text-green-600 text-xs font-medium",children:[n.jsx("span",{children:"✓"}),n.jsx("span",{children:a("llm.fromEnv")})]}),I.detected.map(ve=>n.jsxs("div",{className:"border border-border-default rounded-lg overflow-hidden",children:[n.jsxs("label",{className:"flex items-center gap-3 px-3 py-2.5 bg-surface-elevated/40 cursor-pointer hover:bg-surface-elevated/60 transition-colors",children:[n.jsx("input",{type:"checkbox",checked:V[ve.provider]??!1,onChange:tt=>Y({...V,[ve.provider]:tt.target.checked}),className:"w-4 h-4 rounded bg-surface-overlay border-gray-600 text-brand-500 focus:ring-brand-500"}),n.jsx("div",{className:"flex-1 min-w-0",children:n.jsx("span",{className:"text-sm text-fg-primary font-medium",children:ve.displayName})}),n.jsx("code",{className:"text-[10px] text-fg-tertiary",children:ve.apiKeyPreview})]}),V[ve.provider]&&n.jsx("div",{className:"px-3 py-2 border-t border-border-default",children:n.jsx(dh,{provider:ve.provider,models:ee[ve.provider]??[],selectedModel:G[ve.provider]||ve.model,onSelect:tt=>ue(Tt=>({...Tt,[ve.provider]:tt})),loading:!ee[ve.provider],compact:!0,maxVisible:4})})]},ve.provider)),I.detected.filter(ve=>V[ve.provider]).length>1&&n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx("span",{className:"text-xs text-fg-secondary",children:"Default:"}),n.jsx("select",{value:_||I.detected[0]?.provider||"",onChange:ve=>J(ve.target.value),className:"px-2 py-1 bg-surface-overlay border border-border-default rounded text-xs text-fg-primary",children:I.detected.filter(ve=>V[ve.provider]).map(ve=>n.jsx("option",{value:ve.provider,children:ve.displayName},ve.provider))})]}),n.jsx("button",{onClick:()=>{Wt()},disabled:F||Object.values(V).filter(Boolean).length===0,className:"w-full px-4 py-2 bg-brand-600 hover:bg-brand-500 disabled:opacity-40 text-white text-sm rounded-lg transition-colors",children:F?a("common:applying"):a("llm.applyProviders",{count:Object.values(V).filter(Boolean).length})})]}),I&&I.detected.length===0&&!B&&n.jsxs("div",{className:"space-y-3",children:[n.jsx("div",{className:"text-xs text-fg-tertiary",children:n.jsx(n0,{i18nKey:"llm.noKeysFound",ns:"onboarding",components:{code:n.jsx("code",{className:"text-fg-secondary"})}})}),n.jsxs("div",{className:"space-y-2",children:[n.jsx("label",{className:"text-xs text-fg-secondary",children:"Provider"}),n.jsx("select",{value:Se,onChange:ve=>{Ce(ve.target.value),Ye([]),Lt(""),mt("")},className:"w-full px-3 py-2 bg-surface-overlay border border-border-default rounded-lg text-sm text-fg-primary",children:Bu.map(ve=>n.jsx("option",{value:ve.id,children:ve.label},ve.id))})]}),n.jsxs("div",{className:"space-y-2",children:[n.jsx("label",{className:"text-xs text-fg-secondary",children:"API Key"}),n.jsxs("div",{className:"flex gap-2",children:[n.jsx("input",{type:"password",value:Be,onChange:ve=>Ne(ve.target.value),onBlur:()=>{Be.trim().length>=8&&Ge()},onKeyDown:ve=>{ve.key==="Enter"&&Be.trim().length>=8&&Ge()},placeholder:"sk-...",className:"flex-1 px-3 py-2 bg-surface-overlay border border-border-default rounded-lg text-sm text-fg-primary placeholder:text-fg-tertiary"}),n.jsx("button",{onClick:()=>{Ge()},disabled:he||!Be.trim(),className:"px-3 py-2 bg-brand-600 hover:bg-brand-500 disabled:opacity-40 text-white text-xs rounded-lg transition-colors whitespace-nowrap",children:he?"Validating...":"Validate"})]})]}),it&&n.jsx("div",{className:"text-xs px-3 py-2 rounded-lg bg-red-500/10 text-red-500 border border-red-500/30",children:it}),Ee.length>0&&n.jsxs("div",{className:"border border-border-default rounded-lg p-3",children:[n.jsx("div",{className:"text-xs text-fg-secondary mb-2",children:"Select Model"}),n.jsx(dh,{provider:Se,models:Ee,selectedModel:Ze,onSelect:mt,compact:!0,maxVisible:5}),n.jsx("button",{onClick:()=>{Ht()},disabled:F||!Ze,className:"w-full mt-3 px-4 py-2 bg-brand-600 hover:bg-brand-500 disabled:opacity-40 text-white text-sm rounded-lg transition-colors",children:F?a("common:applying"):"Activate Provider"})]})]}),U&&n.jsx("div",{className:`text-xs px-3 py-2 rounded-lg ${U.type==="ok"?"bg-green-500/10 text-green-600 border border-green-500/30":"bg-red-500/10 text-red-500 border border-red-500/30"}`,children:U.text})]})},{id:X3,title:a("search.title"),subtitle:a("search.subtitle"),content:vn?n.jsxs("div",{className:"space-y-2",children:[n.jsxs("div",{className:"flex items-center gap-2 text-green-600 text-sm font-medium mb-1",children:[n.jsx("span",{children:"✓"}),n.jsx("span",{children:a("search.saved")})]}),je&&[{id:"serper",label:a("search.serper")},{id:"tavily",label:a("search.tavily")},{id:"bing",label:a("search.bing")},{id:"google",label:a("search.google")},{id:"serpapi",label:a("search.serpapi")},{id:"brave",label:a("search.brave")},{id:"exa",label:a("search.exa")},{id:"bocha",label:a("search.bocha")}].filter(ve=>je[ve.id]?.configured).map(ve=>n.jsxs("div",{className:"flex items-center justify-between bg-green-500/10 border border-green-500/30 rounded-lg px-4 py-2.5",children:[n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx("span",{className:"w-2 h-2 rounded-full bg-green-400"}),n.jsx("span",{className:"text-sm text-fg-primary font-medium",children:ve.label})]}),n.jsx("code",{className:"text-[10px] text-fg-tertiary",children:je[ve.id].preview})]},ve.id)),n.jsx("div",{className:"text-xs text-fg-secondary mt-1",children:a("search.savedHint")})]}):n.jsxs("div",{className:"space-y-4",children:[n.jsx("div",{className:"text-xs text-fg-secondary",children:a("search.description")}),je&&(je.serper.configured||je.tavily.configured||je.bing.configured||je.google.configured||je.serpapi.configured||je.brave.configured||je.exa.configured||je.bocha.configured)&&n.jsxs("div",{className:"space-y-2",children:[n.jsx("div",{className:"text-xs text-fg-secondary uppercase tracking-wider",children:a("search.detected")}),[{id:"serper",label:a("search.serper")},{id:"tavily",label:a("search.tavily")},{id:"bing",label:a("search.bing")},{id:"google",label:a("search.google")},{id:"serpapi",label:a("search.serpapi")},{id:"brave",label:a("search.brave")},{id:"exa",label:a("search.exa")},{id:"bocha",label:a("search.bocha")}].filter(ve=>je[ve.id]?.configured).map(ve=>n.jsxs("div",{className:"flex items-center justify-between bg-green-500/10 border border-green-500/30 rounded-lg px-3 py-2",children:[n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx("span",{className:"w-2 h-2 rounded-full bg-green-400"}),n.jsx("span",{className:"text-sm text-fg-primary",children:ve.label})]}),n.jsx("code",{className:"text-[10px] text-fg-tertiary",children:je[ve.id].preview})]},ve.id))]}),n.jsx("div",{className:"space-y-3",children:[{label:a("search.serper"),field:"serperApiKey"},{label:a("search.tavily"),field:"tavilyApiKey"},{label:a("search.bing"),field:"bingApiKey"},{label:a("search.google"),field:"googleSearchApiKey"},{label:a("search.serpapi"),field:"serpApiKey"},{label:a("search.brave"),field:"braveApiKey"},{label:a("search.exa"),field:"exaApiKey"},{label:a("search.bocha"),field:"bochaApiKey"}].map(ve=>n.jsxs("div",{className:"space-y-1",children:[n.jsx("label",{className:"text-xs text-fg-tertiary font-medium",children:ve.label}),n.jsx("input",{type:"password",value:We[ve.field],onChange:tt=>Vt({...We,[ve.field]:tt.target.value}),placeholder:a("search.apiKeyPlaceholder"),className:"w-full px-4 py-2 bg-surface-elevated border border-border-default rounded-xl text-sm text-fg-primary focus:border-brand-500 outline-none transition-colors"})]},ve.field))}),n.jsx("button",{onClick:()=>{zn()},disabled:ln||!We.serperApiKey&&!We.tavilyApiKey&&!We.bingApiKey&&!We.googleSearchApiKey&&!We.serpApiKey&&!We.braveApiKey&&!We.exaApiKey&&!We.bochaApiKey,className:"w-full px-4 py-2.5 bg-brand-600 hover:bg-brand-500 disabled:opacity-40 text-white text-sm rounded-xl transition-colors",children:a(ln?"search.saving":"search.save")}),Zt&&n.jsx("div",{className:`text-xs px-3 py-2 rounded-lg ${Zt.type==="ok"?"bg-green-500/10 text-green-600 border border-green-500/30":"bg-red-500/10 text-red-500 border border-red-500/30"}`,children:Zt.text})]})},{id:"done",title:a("done.title"),subtitle:a("done.subtitle"),content:n.jsxs("div",{className:"space-y-3 text-fg-secondary text-sm",children:[[[a("done.chat"),a("done.chatDesc")],[a("done.projects"),a("done.projectsDesc")],[a("done.builder"),a("done.builderDesc")],[a("done.settings"),a("done.settingsDesc")]].map(([ve,tt])=>n.jsxs("div",{className:"flex gap-3 bg-surface-elevated/50 rounded-lg p-3",children:[n.jsx("div",{className:"text-brand-500 mt-0.5 shrink-0",children:"→"}),n.jsxs("div",{children:[n.jsx("div",{className:"font-medium text-fg-primary text-xs",children:ve}),n.jsx("div",{className:"text-fg-secondary text-xs",children:tt})]})]},ve)),n.jsxs("label",{className:"flex items-start gap-2.5 p-3 bg-surface-elevated/30 rounded-lg cursor-pointer group mt-2",children:[n.jsx("input",{type:"checkbox",checked:rt,onChange:ve=>Et(ve.target.checked),className:"mt-0.5 accent-brand-500 shrink-0"}),n.jsxs("div",{className:"text-[11px] text-fg-tertiary leading-relaxed",children:[a("done.telemetry"),n.jsx("br",{}),n.jsx("span",{className:"text-fg-quaternary",children:a("done.telemetryNote")})]})]})]})}],$n=s?Dn.filter(ve=>ve.id!==cb):Dn,Sn=$n.findIndex(ve=>ve.id===G3),Bn=$n.findIndex(ve=>ve.id===cb),Vn=$n.findIndex(ve=>ve.id===Y3),Qn=$n.findIndex(ve=>ve.id===X3),Pe=()=>{i===Sn&&Sn>=0&&!ht||i===Sn&&ht==="organization"&&!He||i===Bn&&Bn>=0&&!S||(i<$n.length-1?l(i+1):(fetch("/api/settings/telemetry",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({enabled:rt})}).catch(()=>{}),e()))},Ct=$n[i];return n.jsx("div",{className:"min-h-dvh bg-surface-primary flex items-center justify-center p-4",children:n.jsx("div",{className:"w-full max-w-lg",children:n.jsxs("div",{className:"bg-surface-elevated rounded-2xl p-8",children:[n.jsx("div",{className:"flex gap-1.5 mb-8",children:$n.map((ve,tt)=>n.jsx("div",{className:`h-1 flex-1 rounded-full transition-colors ${tt<=i?"bg-brand-500":"bg-surface-elevated"}`},tt))}),n.jsx("h2",{className:"text-2xl font-bold text-fg-primary",children:Ct.title}),n.jsx("p",{className:"text-sm text-fg-secondary mt-1 mb-6",children:Ct.subtitle}),Ct.content,n.jsxs("div",{className:"flex justify-between mt-8",children:[i>0?n.jsx("button",{onClick:()=>l(i-1),className:"px-4 py-2 text-sm text-fg-secondary hover:text-fg-primary transition-colors",children:a("common:back")}):n.jsx("button",{onClick:e,className:"px-4 py-2 text-sm text-fg-tertiary hover:text-fg-secondary transition-colors",children:a("common:skip")}),n.jsxs("div",{className:"flex items-center gap-3",children:[Sn>=0&&i===Sn&&!ht&&n.jsx("button",{onClick:()=>{ne("personal"),Ae(!0),l(i+1)},className:"px-4 py-2 text-sm text-fg-tertiary hover:text-fg-secondary transition-colors",children:a("llm.skipForNow")}),Bn>=0&&i===Bn&&!S&&n.jsx("button",{onClick:()=>l(i+1),className:"px-4 py-2 text-sm text-fg-tertiary hover:text-fg-secondary transition-colors",children:a("llm.skipForNow")}),Vn>=0&&i===Vn&&!O&&n.jsx("button",{onClick:Pe,className:"px-4 py-2 text-sm text-fg-tertiary hover:text-fg-secondary transition-colors",children:a("llm.skipForNow")}),Qn>=0&&i===Qn&&!vn&&n.jsx("button",{onClick:Pe,className:"px-4 py-2 text-sm text-fg-tertiary hover:text-fg-secondary transition-colors",children:a("search.skipForNow")}),n.jsx("button",{onClick:Pe,disabled:Bn>=0&&i===Bn&&!S||Sn>=0&&i===Sn&&(!ht||ht==="organization"&&!He),className:`px-6 py-2.5 text-white text-sm rounded-xl transition-colors ${Bn>=0&&i===Bn&&!S||Sn>=0&&i===Sn&&(!ht||ht==="organization"&&!He)?"bg-brand-600/40 cursor-not-allowed":"bg-brand-600 hover:bg-brand-500"}`,children:i===$n.length-1?a("getStarted"):a("common:next")})]})]})]})})})}function bse({onLogin:e,hasOwner:t,hasMultipleUsers:r}){const{t:s}=pt("auth"),[a,i]=g.useState(null),[l,d]=g.useState(""),[u,m]=g.useState(!1),[h,p]=g.useState(""),[y,x]=g.useState(""),v=async(w,N=!1)=>{d(""),i(w??"hub");try{await da(w);const S=gi(),T=Ch();if(!S||!T){d(s("login.hubUnavailable"));return}const{user:E,needsOnboarding:R}=await ie.auth.hubLogin(S,T);e(E,R??!1,{fromHub:!0})}catch(S){const T=S instanceof Error?S.message:"";if(!T.includes("cancelled")){if(!N&&gi())return r0(),v(w,!0);d(T||s("login.hubUnavailable"))}}finally{i(null)}},j=async w=>{if(w.preventDefault(),!(!h.trim()||!y)){d(""),i("local");try{const{user:N,needsOnboarding:S}=await ie.auth.login(h.trim(),y);e(N,S??!1)}catch{d(s("login.invalidCredentials"))}finally{i(null)}}},C=s(t?"login.welcomeBack":"login.getStarted");return n.jsxs("div",{className:"min-h-dvh bg-surface-primary flex flex-col items-center justify-center p-4 relative overflow-hidden",children:[n.jsx("div",{className:"absolute inset-0 bg-[radial-gradient(ellipse_at_top,_var(--tw-gradient-stops))] from-brand-950/50 via-transparent to-transparent"}),n.jsxs("div",{className:"w-full max-w-sm relative z-10 flex-1 flex flex-col justify-center",children:[n.jsxs("div",{className:"text-center mb-8",children:[n.jsx("img",{src:"/logo.png",alt:"Markus",className:"w-14 h-14 mx-auto mb-3 rounded-xl shadow-lg shadow-black/40"}),n.jsx("div",{className:"text-2xl font-extrabold tracking-tight text-fg-primary mb-1",children:"Markus"}),n.jsx("div",{className:"text-sm text-fg-tertiary",children:C})]}),n.jsx("div",{className:"bg-surface-secondary/80 backdrop-blur-sm border border-border-default rounded-2xl p-8 space-y-4 shadow-2xl shadow-black/30",children:u?n.jsxs(n.Fragment,{children:[n.jsxs("form",{onSubmit:j,className:"space-y-3",children:[n.jsx("div",{className:"space-y-1",children:n.jsx("input",{type:"email",value:h,onChange:w=>p(w.target.value),autoComplete:"email",autoFocus:!0,placeholder:s("login.email"),className:"w-full px-4 py-2.5 bg-surface-elevated border border-border-default rounded-xl text-sm text-fg-primary focus:border-brand-500 outline-none transition-colors placeholder:text-fg-tertiary",required:!0})}),n.jsx("div",{className:"space-y-1",children:n.jsx("input",{type:"password",value:y,onChange:w=>x(w.target.value),autoComplete:"current-password",placeholder:s("login.password"),className:"w-full px-4 py-2.5 bg-surface-elevated border border-border-default rounded-xl text-sm text-fg-primary focus:border-brand-500 outline-none transition-colors placeholder:text-fg-tertiary",required:!0})}),l&&n.jsx("div",{className:"px-3 py-2 bg-red-500/10 border border-red-500/30 rounded-lg text-xs text-red-500",children:l}),t&&!r&&n.jsx("p",{className:"text-[11px] text-fg-tertiary",children:s("login.defaultCredentials")}),n.jsx("button",{type:"submit",disabled:a==="local"||!h||!y,className:"w-full py-2.5 bg-brand-600 hover:bg-brand-500 disabled:opacity-50 text-white text-sm font-medium rounded-xl transition-all",children:s(a==="local"?"login.signingIn":"login.signIn")})]}),n.jsx("div",{className:"pt-1 text-center",children:n.jsx("button",{onClick:()=>{m(!1),d("")},className:"text-xs text-fg-tertiary hover:text-fg-secondary transition-colors",children:s("login.backToHub")})})]}):n.jsxs(n.Fragment,{children:[n.jsxs("button",{onClick:()=>v("google"),disabled:!!a,className:"w-full flex items-center justify-center gap-3 py-2.5 px-4 bg-surface-elevated hover:bg-surface-elevated/80 border border-border-default rounded-xl text-sm text-fg-primary font-medium transition-all disabled:opacity-50",children:[n.jsxs("svg",{className:"w-5 h-5",viewBox:"0 0 24 24",children:[n.jsx("path",{fill:"#4285F4",d:"M22.56 12.25c0-.78-.07-1.53-.2-2.25H12v4.26h5.92a5.06 5.06 0 01-2.2 3.32v2.77h3.57c2.08-1.92 3.28-4.74 3.28-8.1z"}),n.jsx("path",{fill:"#34A853",d:"M12 23c2.97 0 5.46-.98 7.28-2.66l-3.57-2.77c-.98.66-2.23 1.06-3.71 1.06-2.86 0-5.29-1.93-6.16-4.53H2.18v2.84C3.99 20.53 7.7 23 12 23z"}),n.jsx("path",{fill:"#FBBC05",d:"M5.84 14.09c-.22-.66-.35-1.36-.35-2.09s.13-1.43.35-2.09V7.07H2.18C1.43 8.55 1 10.22 1 12s.43 3.45 1.18 4.93l2.85-2.22.81-.62z"}),n.jsx("path",{fill:"#EA4335",d:"M12 5.38c1.62 0 3.06.56 4.21 1.64l3.15-3.15C17.45 2.09 14.97 1 12 1 7.7 1 3.99 3.47 2.18 7.07l3.66 2.84c.87-2.6 3.3-4.53 6.16-4.53z"})]}),s(a==="google"?"login.connectingHub":"login.withGoogle")]}),n.jsxs("button",{onClick:()=>v("github"),disabled:!!a,className:"w-full flex items-center justify-center gap-3 py-2.5 px-4 bg-surface-elevated hover:bg-surface-elevated/80 border border-border-default rounded-xl text-sm text-fg-primary font-medium transition-all disabled:opacity-50",children:[n.jsx("svg",{className:"w-5 h-5",viewBox:"0 0 24 24",fill:"currentColor",children:n.jsx("path",{d:"M12 0C5.37 0 0 5.37 0 12c0 5.31 3.435 9.795 8.205 11.385.6.105.825-.255.825-.57 0-.285-.015-1.23-.015-2.235-3.015.555-3.795-.735-4.035-1.41-.135-.345-.72-1.41-1.23-1.695-.42-.225-1.02-.78-.015-.795.945-.015 1.62.87 1.845 1.23 1.08 1.815 2.805 1.305 3.495.99.105-.78.42-1.305.765-1.605-2.67-.3-5.46-1.335-5.46-5.925 0-1.305.465-2.385 1.23-3.225-.12-.3-.54-1.53.12-3.18 0 0 1.005-.315 3.3 1.23.96-.27 1.98-.405 3-.405s2.04.135 3 .405c2.295-1.56 3.3-1.23 3.3-1.23.66 1.65.24 2.88.12 3.18.765.84 1.23 1.905 1.23 3.225 0 4.605-2.805 5.625-5.475 5.925.435.375.81 1.095.81 2.22 0 1.605-.015 2.895-.015 3.3 0 .315.225.69.825.57A12.02 12.02 0 0024 12c0-6.63-5.37-12-12-12z"})}),s(a==="github"?"login.connectingHub":"login.withGithub")]}),n.jsxs("button",{onClick:()=>v("email"),disabled:!!a,className:"w-full flex items-center justify-center gap-3 py-2.5 px-4 bg-surface-elevated hover:bg-surface-elevated/80 border border-border-default rounded-xl text-sm text-fg-primary font-medium transition-all disabled:opacity-50",children:[n.jsx("svg",{className:"w-5 h-5",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:1.5,children:n.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M21.75 6.75v10.5a2.25 2.25 0 01-2.25 2.25h-15a2.25 2.25 0 01-2.25-2.25V6.75m19.5 0A2.25 2.25 0 0019.5 4.5h-15a2.25 2.25 0 00-2.25 2.25m19.5 0v.243a2.25 2.25 0 01-1.07 1.916l-7.5 4.615a2.25 2.25 0 01-2.36 0L3.32 8.91a2.25 2.25 0 01-1.07-1.916V6.75"})}),s(a==="email"?"login.connectingHub":"login.withEmail")]}),n.jsx("p",{className:"text-center text-[11px] text-fg-tertiary pt-1",children:s("login.terms")}),l&&n.jsx("div",{className:"px-3 py-2 bg-red-500/10 border border-red-500/30 rounded-lg text-xs text-red-500",children:l}),n.jsx("div",{className:"pt-1 text-center",children:n.jsx("button",{onClick:()=>m(!0),className:"text-xs text-fg-tertiary hover:text-fg-secondary transition-colors",children:s("login.useLocalAccount")})})]})})]}),n.jsxs("div",{className:"relative z-10 flex flex-wrap items-center justify-center gap-x-5 gap-y-1 py-6 text-[11px] text-fg-tertiary",children:[n.jsx("a",{href:"https://markus.global",target:"_blank",rel:"noopener noreferrer",className:"hover:text-fg-secondary transition-colors",children:"markus.global"}),n.jsx("a",{href:"mailto:business@markus.global",className:"hover:text-fg-secondary transition-colors",children:s("login.contactSales")})]})]})}function yse({token:e,onComplete:t}){const{t:r}=pt("auth"),[s,a]=g.useState(null),[i,l]=g.useState(""),[d,u]=g.useState(""),[m,h]=g.useState(""),[p,y]=g.useState(!1),[x,v]=g.useState(!1),[j,C]=g.useState(!1);g.useEffect(()=>{ie.auth.inviteInfo(e).then(N=>a(N)).catch(()=>C(!0))},[e]);const w=async N=>{if(N.preventDefault(),h(""),i.length<6){h(r("invite.passwordMinLength"));return}if(i!==d){h(r("invite.passwordsDoNotMatch"));return}y(!0);try{await ie.auth.setup(e,i),v(!0),setTimeout(()=>{window.location.hash="",t()},2e3)}catch{h(r("invite.error"))}finally{y(!1)}};return n.jsxs("div",{className:"min-h-dvh bg-surface-primary flex items-center justify-center p-4 relative overflow-hidden",children:[n.jsx("div",{className:"absolute inset-0 bg-[radial-gradient(ellipse_at_top,_var(--tw-gradient-stops))] from-brand-950/50 via-transparent to-transparent"}),n.jsxs("div",{className:"w-full max-w-sm relative z-10",children:[n.jsxs("div",{className:"text-center mb-8",children:[n.jsx("img",{src:"/logo.png",alt:"Markus",className:"w-14 h-14 mx-auto mb-3 rounded-xl shadow-lg shadow-black/40"}),n.jsx("div",{className:"text-2xl font-extrabold tracking-tight text-fg-primary mb-1",children:"Markus"}),n.jsx("div",{className:"text-sm text-fg-tertiary",children:r("invite.subtitle")})]}),n.jsx("div",{className:"bg-surface-secondary/80 backdrop-blur-sm border border-border-default rounded-2xl p-8 space-y-5 shadow-2xl shadow-black/30",children:j?n.jsxs("div",{className:"text-center space-y-3",children:[n.jsx("div",{className:"text-red-500 text-3xl",children:"⚠"}),n.jsx("p",{className:"text-sm text-fg-secondary",children:r("invite.invalidLink")}),n.jsx("button",{onClick:()=>{window.location.hash="",t()},className:"text-sm text-brand-500 hover:text-brand-400",children:r("login.signIn")})]}):x?n.jsxs("div",{className:"text-center space-y-3",children:[n.jsx("div",{className:"text-green-500 text-3xl",children:"✓"}),n.jsx("p",{className:"text-sm text-fg-secondary",children:r("invite.setupComplete")})]}):s?n.jsxs("form",{onSubmit:w,className:"space-y-5",children:[n.jsx("h2",{className:"text-lg font-semibold text-fg-primary text-center",children:r("invite.greeting",{name:s.name})}),n.jsx("p",{className:"text-xs text-fg-tertiary text-center",children:s.email}),n.jsxs("div",{className:"space-y-1",children:[n.jsx("label",{className:"text-xs text-fg-tertiary font-medium",children:r("invite.setPassword")}),n.jsx("input",{type:"password",value:i,onChange:N=>l(N.target.value),autoComplete:"new-password",autoFocus:!0,className:"w-full px-4 py-2.5 bg-surface-elevated border border-border-default rounded-xl text-sm text-fg-primary focus:border-brand-500 outline-none transition-colors",required:!0})]}),n.jsxs("div",{className:"space-y-1",children:[n.jsx("label",{className:"text-xs text-fg-tertiary font-medium",children:r("invite.confirmPassword")}),n.jsx("input",{type:"password",value:d,onChange:N=>u(N.target.value),autoComplete:"new-password",className:"w-full px-4 py-2.5 bg-surface-elevated border border-border-default rounded-xl text-sm text-fg-primary focus:border-brand-500 outline-none transition-colors",required:!0})]}),m&&n.jsx("div",{className:"px-3 py-2 bg-red-500/10 border border-red-500/30 rounded-lg text-xs text-red-500",children:m}),n.jsx("button",{type:"submit",disabled:p||!i||!d,className:"w-full py-2.5 bg-brand-600 hover:bg-brand-500 disabled:opacity-50 text-white text-sm font-medium rounded-xl transition-all shadow-md shadow-brand-900/40 hover:shadow-lg hover:shadow-brand-900/50",children:r(p?"invite.settingUp":"invite.setupAccount")})]}):n.jsx("div",{className:"text-center text-fg-tertiary text-sm animate-pulse py-4",children:"Loading…"})})]})]})}function vse({onComplete:e,isFirstTime:t}){const{t:r}=pt("auth"),[s,a]=g.useState(""),[i,l]=g.useState(""),[d,u]=g.useState(""),[m,h]=g.useState(""),[p,y]=g.useState(!1),x=async v=>{if(v.preventDefault(),h(""),i.length<6){h(r("changePassword.passwordMinLength"));return}if(i!==d){h(r("changePassword.passwordsDoNotMatch"));return}y(!0);try{await ie.auth.changePassword(s,i),e()}catch{h(r("changePassword.failedToChange"))}finally{y(!1)}};return n.jsxs("div",{className:"min-h-dvh bg-surface-primary flex items-center justify-center p-4 relative overflow-hidden",children:[n.jsx("div",{className:"absolute inset-0 bg-[radial-gradient(ellipse_at_top,_var(--tw-gradient-stops))] from-brand-950/50 via-transparent to-transparent"}),n.jsxs("div",{className:"w-full max-w-sm relative z-10",children:[n.jsxs("div",{className:"text-center mb-8",children:[n.jsx("img",{src:"/logo.png",alt:"Markus",className:"w-14 h-14 mx-auto mb-3 rounded-xl shadow-lg shadow-black/40"}),n.jsx("div",{className:"text-2xl font-extrabold tracking-tight text-fg-primary mb-1",children:"Markus"}),n.jsx("div",{className:"text-sm text-fg-tertiary",children:r("login.subtitle")})]}),n.jsxs("form",{onSubmit:x,className:"bg-surface-secondary/80 backdrop-blur-sm border border-border-default rounded-2xl p-8 space-y-5 shadow-2xl shadow-black/30",children:[n.jsxs("div",{children:[n.jsx("h2",{className:"text-lg font-semibold text-fg-primary text-center",children:r(t?"changePassword.setYourPassword":"changePassword.changePassword")}),t&&n.jsx("p",{className:"text-xs text-amber-600/80 text-center mt-2",children:r("changePassword.defaultPasswordWarning")})]}),!t&&n.jsxs("div",{className:"space-y-1",children:[n.jsx("label",{className:"text-xs text-fg-tertiary font-medium",children:r("changePassword.currentPassword")}),n.jsx("input",{type:"password",value:s,onChange:v=>a(v.target.value),autoComplete:"current-password",className:"w-full px-4 py-2.5 bg-surface-elevated border border-border-default rounded-xl text-sm text-fg-primary focus:border-brand-500 outline-none transition-colors"})]}),n.jsxs("div",{className:"space-y-1",children:[n.jsx("label",{className:"text-xs text-fg-tertiary font-medium",children:r("changePassword.newPassword")}),n.jsx("input",{type:"password",value:i,onChange:v=>l(v.target.value),autoComplete:"new-password",className:"w-full px-4 py-2.5 bg-surface-elevated border border-border-default rounded-xl text-sm text-fg-primary focus:border-brand-500 outline-none transition-colors",required:!0,minLength:6})]}),n.jsxs("div",{className:"space-y-1",children:[n.jsx("label",{className:"text-xs text-fg-tertiary font-medium",children:r("changePassword.confirmNewPassword")}),n.jsx("input",{type:"password",value:d,onChange:v=>u(v.target.value),autoComplete:"new-password",className:"w-full px-4 py-2.5 bg-surface-elevated border border-border-default rounded-xl text-sm text-fg-primary focus:border-brand-500 outline-none transition-colors",required:!0})]}),m&&n.jsx("div",{className:"px-3 py-2 bg-red-500/10 border border-red-500/30 rounded-lg text-xs text-red-500",children:m}),n.jsx("button",{type:"submit",disabled:p||!i||!d,className:"w-full py-2.5 bg-brand-600 hover:bg-brand-500 disabled:opacity-50 text-white text-sm font-medium rounded-xl transition-colors",children:r(p?"changePassword.saving":t?"changePassword.setPasswordAndContinue":"changePassword.changePassword")})]})]})]})}const Kf={agents:[],tasks:[],requirements:[],projects:[],deliverables:[]},wse={team:["agents","tasks","requirements","projects","deliverables"],work:["projects","requirements","tasks","agents","deliverables"],deliverables:["deliverables","agents","tasks","requirements","projects"]},kse=["agents","tasks","requirements","projects","deliverables"];let Q3="",Z3="all",J3=Kf,e6=!1;function jse({onClose:e,currentPage:t}){const{t:r}=pt(["common","home","work"]),[s,a]=g.useState(Q3),[i,l]=g.useState(Z3),[d,u]=g.useState(J3),[m,h]=g.useState(!1),[p,y]=g.useState(e6),[x,v]=g.useState(-1);g.useEffect(()=>{Q3=s},[s]),g.useEffect(()=>{Z3=i},[i]),g.useEffect(()=>{J3=d},[d]),g.useEffect(()=>{e6=p},[p]);const j=g.useRef(null),C=g.useRef(void 0),w=g.useRef(null),N=g.useRef(null);g.useEffect(()=>{setTimeout(()=>{j.current?.focus(),j.current?.select()},100)},[]);const S=g.useCallback(async F=>{if(!F.trim()){u(Kf),y(!1),v(-1);return}h(!0),y(!0),v(-1);const L=F.toLowerCase();try{const[O,M,$,W,U]=await Promise.allSettled([ie.agents.list(),ie.tasks.list({search:F,pageSize:20}),ie.requirements.list(),ie.projects.list(),ie.deliverables.search({q:F,limit:20})]),H=O.status==="fulfilled"?O.value.agents.filter(X=>X.name?.toLowerCase().includes(L)||X.role?.toLowerCase().includes(L)):[],q=M.status==="fulfilled"?M.value.tasks:[],Z=$.status==="fulfilled"?$.value.requirements.filter(X=>X.title?.toLowerCase().includes(L)||X.description?.toLowerCase().includes(L)):[],_=W.status==="fulfilled"?W.value.projects.filter(X=>X.name?.toLowerCase().includes(L)||X.description?.toLowerCase().includes(L)):[],J=U.status==="fulfilled"?U.value.results:[];u({agents:H,tasks:q,requirements:Z,projects:_,deliverables:J})}catch{u(Kf)}finally{h(!1)}},[]),T=F=>{a(F),C.current&&clearTimeout(C.current),C.current=setTimeout(()=>S(F),400)},E=g.useCallback((F,L)=>{e(),bt.navigate(F,L)},[e]),R=[{id:"all",label:r("common:all",{defaultValue:"全部"})},{id:"agents",label:r("common:agents",{defaultValue:"智能体"})},{id:"tasks",label:r("common:tasks",{defaultValue:"任务"})},{id:"requirements",label:r("common:requirements",{defaultValue:"需求"})},{id:"projects",label:r("common:projects",{defaultValue:"项目"})},{id:"deliverables",label:r("common:deliverables",{defaultValue:"交付物"})}],I=g.useMemo(()=>wse[t||""]||kse,[t]),z=g.useMemo(()=>{const F=[],L=i==="all"?8:void 0,O=M=>{if(i!=="all"&&i!==M)return;const $=d[M==="agents"?"agents":M==="tasks"?"tasks":M==="requirements"?"requirements":M==="projects"?"projects":"deliverables"],W=L?$.slice(0,L):$;for(const U of W)switch(M){case"agents":F.push({id:U.id,type:"agent",page:De.TEAM,params:{agentId:U.id}});break;case"tasks":F.push({id:U.id,type:"task",page:De.WORK,params:{openTask:U.id}});break;case"requirements":F.push({id:U.id,type:"requirement",page:De.WORK,params:{openRequirement:U.id}});break;case"projects":F.push({id:U.id,type:"project",page:De.WORK,params:{projectId:U.id}});break;case"deliverables":F.push({id:U.id,type:"deliverable",page:De.DELIVERABLES,params:{openDeliverable:U.id}});break}L&&$.length>L&&F.push({id:`more_${M}`,type:"showMore",page:"",expandCategory:M,totalCount:$.length})};for(const M of I)O(M);return F},[d,i,I]),B=g.useCallback(F=>{if(F.type==="showMore"&&F.expandCategory){l(F.expandCategory),v(-1);return}E(F.page,F.params)},[E]);g.useEffect(()=>{const F=N.current;if(!F||x<0)return;const L=F.querySelector(`[data-idx="${x}"]`);L&&L.scrollIntoView({block:"nearest"})},[x]);const D=g.useCallback(F=>{if(F.key==="Escape"){e();return}if(F.key==="Tab"){F.preventDefault();const M=R.map(U=>U.id),$=M.indexOf(i),W=F.shiftKey?$<=0?M.length-1:$-1:$>=M.length-1?0:$+1;l(M[W]),v(-1);return}const L=F.ctrlKey&&F.key==="n"||F.key==="ArrowDown",O=F.ctrlKey&&F.key==="p"||F.key==="ArrowUp";if(L||O){F.preventDefault(),v(M=>{const $=z.length-1;return $<0?-1:L?M>=$?0:M+1:M<=0?$:M-1});return}F.key==="Enter"&&(F.preventDefault(),x>=0&&x<z.length&&B(z[x]))},[e,z,x,B,R,i]);g.useEffect(()=>(document.addEventListener("keydown",D),()=>document.removeEventListener("keydown",D)),[D]);const V=z.length>0;let Y=0;return n.jsx("div",{ref:w,className:"fixed inset-0 bg-black/50 flex items-start justify-center z-50 pt-[8vh]",onClick:F=>{F.target===w.current&&e()},children:n.jsxs("div",{className:"bg-surface-primary border border-border-default rounded-2xl shadow-2xl w-full max-w-3xl max-h-[78vh] flex flex-col overflow-hidden animate-fadeIn",children:[n.jsxs("div",{className:"shrink-0 px-5 pt-4 pb-3 border-b border-border-default space-y-3",children:[n.jsxs("div",{className:"relative",children:[n.jsxs("svg",{className:"absolute left-3 top-1/2 -translate-y-1/2 text-fg-tertiary",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("circle",{cx:"11",cy:"11",r:"8"}),n.jsx("line",{x1:"21",y1:"21",x2:"16.65",y2:"16.65"})]}),n.jsx("input",{ref:j,value:s,onChange:F=>T(F.target.value),placeholder:r("common:search"),className:"w-full bg-surface-elevated border border-border-default rounded-xl pl-9 pr-9 py-2.5 text-sm text-fg-primary placeholder:text-fg-tertiary focus:border-brand-500 focus:outline-none transition-colors"}),s&&n.jsx("button",{onClick:()=>{a(""),u(Kf),y(!1),v(-1),j.current?.focus()},className:"absolute right-3 top-1/2 -translate-y-1/2 text-fg-tertiary hover:text-fg-secondary",children:n.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),n.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]}),n.jsx("div",{className:"flex gap-1 overflow-x-auto scrollbar-hide",children:R.map(F=>n.jsx("button",{onClick:()=>{l(F.id),v(-1)},className:`px-3 py-1.5 text-xs rounded-lg whitespace-nowrap transition-colors ${i===F.id?"bg-brand-600 text-white":"bg-surface-elevated text-fg-secondary hover:text-fg-primary"}`,children:F.label},F.id))})]}),n.jsxs("div",{ref:N,className:"flex-1 overflow-y-auto px-5 py-3",children:[m&&n.jsx("div",{className:"flex items-center justify-center py-8",children:n.jsx("div",{className:"text-fg-tertiary text-sm animate-pulse",children:r("common:loading")})}),!m&&p&&!V&&n.jsxs("div",{className:"flex flex-col items-center justify-center py-8 text-center",children:[n.jsxs("svg",{width:"36",height:"36",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",className:"text-fg-tertiary mb-2",children:[n.jsx("circle",{cx:"11",cy:"11",r:"8"}),n.jsx("line",{x1:"21",y1:"21",x2:"16.65",y2:"16.65"})]}),n.jsx("p",{className:"text-sm text-fg-tertiary",children:r("common:noResults",{defaultValue:"没有找到相关结果"})})]}),!m&&V&&n.jsx("div",{className:"space-y-4",children:I.map(F=>{if(i!=="all"&&i!==F)return null;const L=i==="all"?8:void 0,O=M=>{const $=Y++,W=M==="agents"?d.agents.length:M==="tasks"?d.tasks.length:M==="requirements"?d.requirements.length:M==="projects"?d.projects.length:d.deliverables.length;return n.jsxs("button",{"data-idx":$,onClick:()=>{l(M),v(-1)},className:`mt-1 w-full text-xs py-1.5 rounded-lg transition-colors ${$===x?"bg-brand-600/15 ring-1 ring-brand-500/40 text-brand-500":"text-brand-500 hover:text-brand-400 hover:bg-surface-overlay"}`,children:[r("common:showAll",{defaultValue:"查看全部"})," (",W,")"]})};return F==="agents"&&d.agents.length>0?n.jsxs("section",{children:[n.jsx("h3",{className:"text-xs font-medium text-fg-tertiary uppercase mb-2",children:r("common:agents",{defaultValue:"智能体"})}),n.jsx("div",{className:"space-y-0.5",children:(L?d.agents.slice(0,L):d.agents).map(M=>{const $=Y++;return n.jsxs("button",{"data-idx":$,onClick:()=>E(De.TEAM,{agentId:M.id}),className:`w-full flex items-center gap-3 px-3 py-2 rounded-xl transition-colors text-left ${$===x?"bg-brand-600/15 ring-1 ring-brand-500/40":"hover:bg-surface-overlay"}`,children:[n.jsx(Nr,{name:M.name||"Agent",avatarUrl:M.avatarUrl,size:28}),n.jsxs("div",{className:"flex-1 min-w-0",children:[n.jsx("div",{className:"text-sm font-medium text-fg-primary truncate",children:M.name}),n.jsx("div",{className:"text-xs text-fg-tertiary truncate",children:M.role||M.status})]}),n.jsx(Nse,{status:M.status})]},M.id)})}),L&&d.agents.length>L&&O("agents")]},"agents"):F==="tasks"&&d.tasks.length>0?n.jsxs("section",{children:[n.jsx("h3",{className:"text-xs font-medium text-fg-tertiary uppercase mb-2",children:r("common:tasks",{defaultValue:"任务"})}),n.jsx("div",{className:"space-y-0.5",children:(L?d.tasks.slice(0,L):d.tasks).map(M=>{const $=Y++;return n.jsxs("button",{"data-idx":$,onClick:()=>E(De.WORK,{openTask:M.id}),className:`w-full flex items-center gap-3 px-3 py-2 rounded-xl transition-colors text-left ${$===x?"bg-brand-600/15 ring-1 ring-brand-500/40":"hover:bg-surface-overlay"}`,children:[n.jsx(Sse,{status:M.status}),n.jsxs("div",{className:"flex-1 min-w-0",children:[n.jsx("div",{className:"text-sm text-fg-primary truncate",children:M.title}),n.jsxs("div",{className:"text-xs text-fg-tertiary truncate",children:[M.status," · ",M.priority||""]})]})]},M.id)})}),L&&d.tasks.length>L&&O("tasks")]},"tasks"):F==="requirements"&&d.requirements.length>0?n.jsxs("section",{children:[n.jsx("h3",{className:"text-xs font-medium text-fg-tertiary uppercase mb-2",children:r("common:requirements",{defaultValue:"需求"})}),n.jsx("div",{className:"space-y-0.5",children:(L?d.requirements.slice(0,L):d.requirements).map(M=>{const $=Y++;return n.jsxs("button",{"data-idx":$,onClick:()=>E(De.WORK,{openRequirement:M.id}),className:`w-full flex items-center gap-3 px-3 py-2 rounded-xl transition-colors text-left ${$===x?"bg-brand-600/15 ring-1 ring-brand-500/40":"hover:bg-surface-overlay"}`,children:[n.jsx("div",{className:`w-7 h-7 rounded-lg flex items-center justify-center shrink-0 ${M.status==="approved"?"text-green-500 bg-green-500/15":M.status==="pending"?"text-amber-500 bg-amber-500/15":M.status==="rejected"?"text-red-500 bg-red-500/15":"text-fg-tertiary bg-surface-elevated"}`,children:n.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[n.jsx("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),n.jsx("polyline",{points:"14 2 14 8 20 8"}),n.jsx("line",{x1:"16",y1:"13",x2:"8",y2:"13"}),n.jsx("line",{x1:"16",y1:"17",x2:"8",y2:"17"})]})}),n.jsxs("div",{className:"flex-1 min-w-0",children:[n.jsx("div",{className:"text-sm text-fg-primary truncate",children:M.title}),n.jsxs("div",{className:"text-xs text-fg-tertiary truncate",children:[M.status," · ",M.priority||""]})]})]},M.id)})}),L&&d.requirements.length>L&&O("requirements")]},"requirements"):F==="projects"&&d.projects.length>0?n.jsxs("section",{children:[n.jsx("h3",{className:"text-xs font-medium text-fg-tertiary uppercase mb-2",children:r("common:projects",{defaultValue:"项目"})}),n.jsx("div",{className:"space-y-0.5",children:(L?d.projects.slice(0,L):d.projects).map(M=>{const $=Y++;return n.jsxs("button",{"data-idx":$,onClick:()=>E(De.WORK,{projectId:M.id}),className:`w-full flex items-center gap-3 px-3 py-2 rounded-xl transition-colors text-left ${$===x?"bg-brand-600/15 ring-1 ring-brand-500/40":"hover:bg-surface-overlay"}`,children:[n.jsx("div",{className:"w-7 h-7 rounded-lg bg-teal-500/15 flex items-center justify-center shrink-0",children:n.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:"text-teal-500",children:n.jsx("path",{d:"M22 19a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h5l2 3h9a2 2 0 0 1 2 2z"})})}),n.jsxs("div",{className:"flex-1 min-w-0",children:[n.jsx("div",{className:"text-sm text-fg-primary truncate",children:M.name}),M.description&&n.jsx("div",{className:"text-xs text-fg-tertiary truncate",children:M.description})]})]},M.id)})}),L&&d.projects.length>L&&O("projects")]},"projects"):F==="deliverables"&&d.deliverables.length>0?n.jsxs("section",{children:[n.jsx("h3",{className:"text-xs font-medium text-fg-tertiary uppercase mb-2",children:r("common:deliverables",{defaultValue:"交付物"})}),n.jsx("div",{className:"space-y-0.5",children:(L?d.deliverables.slice(0,L):d.deliverables).map(M=>{const $=Y++;return n.jsxs("button",{"data-idx":$,onClick:()=>E(De.DELIVERABLES,{openDeliverable:M.id}),className:`w-full flex items-center gap-3 px-3 py-2 rounded-xl transition-colors text-left ${$===x?"bg-brand-600/15 ring-1 ring-brand-500/40":"hover:bg-surface-overlay"}`,children:[n.jsx("div",{className:"w-7 h-7 rounded-lg bg-purple-500/15 flex items-center justify-center shrink-0",children:n.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:"text-purple-500",children:[n.jsx("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),n.jsx("polyline",{points:"14 2 14 8 20 8"})]})}),n.jsxs("div",{className:"flex-1 min-w-0",children:[n.jsx("div",{className:"text-sm text-fg-primary truncate",children:M.title}),n.jsxs("div",{className:"text-xs text-fg-tertiary truncate",children:[M.type," · ",M.status]})]})]},M.id)})}),L&&d.deliverables.length>L&&O("deliverables")]},"deliverables"):null})}),!m&&!p&&n.jsxs("div",{className:"flex flex-col items-center justify-center py-8 text-center",children:[n.jsxs("svg",{width:"36",height:"36",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",className:"text-fg-tertiary mb-2",children:[n.jsx("circle",{cx:"11",cy:"11",r:"8"}),n.jsx("line",{x1:"21",y1:"21",x2:"16.65",y2:"16.65"})]}),n.jsx("p",{className:"text-sm text-fg-tertiary",children:r("common:searchHint",{defaultValue:"输入关键词搜索"})})]})]}),n.jsxs("div",{className:"shrink-0 px-5 py-2 border-t border-border-default flex items-center gap-4 text-xs text-fg-tertiary flex-wrap",children:[n.jsxs("span",{children:[n.jsx("kbd",{className:"px-1.5 py-0.5 rounded bg-surface-elevated border border-border-default text-[11px] font-medium",children:navigator.platform.toUpperCase().includes("MAC")?"Cmd+P":"Ctrl+P"})," ",r("common:toggle",{defaultValue:"唤起/关闭"})]}),n.jsxs("span",{children:[n.jsx("kbd",{className:"px-1.5 py-0.5 rounded bg-surface-elevated border border-border-default text-[11px] font-medium",children:"Tab"})," ",r("common:switchTab",{defaultValue:"切换分类"})]}),n.jsxs("span",{children:[n.jsx("kbd",{className:"px-1.5 py-0.5 rounded bg-surface-elevated border border-border-default text-[11px] font-medium",children:"↑↓"})," ",r("common:navigate",{defaultValue:"导航"})]}),n.jsxs("span",{children:[n.jsx("kbd",{className:"px-1.5 py-0.5 rounded bg-surface-elevated border border-border-default text-[11px] font-medium",children:"Enter"})," ",r("common:open",{defaultValue:"打开"})]}),n.jsxs("span",{children:[n.jsx("kbd",{className:"px-1.5 py-0.5 rounded bg-surface-elevated border border-border-default text-[11px] font-medium",children:"Esc"})," ",r("common:close",{defaultValue:"关闭"})]})]})]})})}function Nse({status:e}){const t=e==="active"||e==="idle"?"bg-green-500":e==="working"||e==="busy"?"bg-blue-500":e==="paused"?"bg-amber-500":"bg-gray-400";return n.jsx("span",{className:`w-2 h-2 rounded-full shrink-0 ${t}`})}function Sse({status:e}){const t=e==="completed"?"text-green-500 bg-green-500/15":e==="in_progress"?"text-blue-500 bg-blue-500/15":e==="pending"?"text-amber-500 bg-amber-500/15":"text-fg-tertiary bg-surface-elevated";return n.jsx("div",{className:`w-7 h-7 rounded-lg flex items-center justify-center shrink-0 ${t}`,children:n.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[n.jsx("path",{d:"M9 11l3 3L22 4"}),n.jsx("path",{d:"M21 12v7a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h11"})]})})}const Cse={visibility:"hidden",position:"absolute",inset:0,pointerEvents:"none",zIndex:-1},Tse=g.memo(function({id:t,activePage:r,children:s}){const a=t===r;return n.jsx("div",{className:"flex-1 overflow-hidden flex flex-col",style:a?void 0:Cse,children:s})},(e,t)=>{const r=e.id===e.activePage,s=t.id===t.activePage;return r!==s?!1:s?e.children===t.children:!0}),db={};function Ase(){const{t:e}=pt("common"),[t,r]=g.useState(ec),[s,a]=g.useState(()=>!localStorage.getItem("markus_onboarded")),[i,l]=g.useState(!0),d=Rs(),u=nY(),m=f0({side:"left",defaultWidth:160,minWidth:140,maxWidth:400,collapsedWidth:64,storageKey:"markus_sidebar"}),[h,p]=g.useState(()=>new Set([ec()])),[y,x]=g.useState("loading"),[v,j]=g.useState(null),[C,w]=g.useState({hasOwner:!1,hasMultipleUsers:!1}),[N,S]=g.useState(!1),[T,E]=g.useState(!1),[R,I]=g.useState(null),[z,B]=g.useState(!1),[D,V]=g.useState(null),[Y,F]=g.useState(()=>{const te=localStorage.getItem("markus_update_dismissed");return te||null}),[L,O]=g.useState(null),[M,$]=g.useState(!1),W=g.useCallback(()=>{ie.license.get().then(te=>{if(te.plan==="enterprise"){O(null);return}if(te.usage&&te.limits){const G=te.limits.maxTeams>0&&te.usage.teams>=te.limits.maxTeams,ue=te.limits.maxToolCallsPerDay>0&&te.usage.toolCallsToday>=te.limits.maxToolCallsPerDay;G||ue?(O({teams:G||void 0,toolCalls:ue||void 0}),$(!1)):O(null)}}).catch(()=>{})},[]);g.useEffect(()=>{const te=()=>{document.visibilityState==="visible"&&W()};window.addEventListener("markus:check-license-limits",W),document.addEventListener("visibilitychange",te);const G=setInterval(W,300*1e3);return()=>{window.removeEventListener("markus:check-license-limits",W),document.removeEventListener("visibilitychange",te),clearInterval(G)}},[W]);const[U,H]=g.useState(!1);g.useEffect(()=>{if(d)return;const te=navigator.platform.toUpperCase().includes("MAC"),G=Se=>{te&&Se.metaKey&&!Se.ctrlKey&&Se.key==="p"?(Se.preventDefault(),H(Ce=>!Ce)):!te&&Se.ctrlKey&&!Se.metaKey&&Se.key==="p"&&(Se.preventDefault(),H(Ce=>!Ce))},ue=()=>H(!0);return document.addEventListener("keydown",G),window.addEventListener("markus:open-search",ue),()=>{document.removeEventListener("keydown",G),window.removeEventListener("markus:open-search",ue)}},[d]);const q=g.useCallback(te=>{let G=nc(te);d?G=$_[G]??G:G===De.NOTIFICATIONS&&(G=De.HOME);const ue=ec(),Se=window.location.hash.slice(1);Se!==ue?db[ue]=Se:delete db[ue];const Ce=G!==De.WORK?db[G]:void 0;Ce&&Ce!==G?(history.pushState(null,"","#"+G),history.pushState(null,"","#"+Ce)):history.pushState(null,"","#"+G),window.dispatchEvent(new HashChangeEvent("hashchange")),r(G),p(Be=>Be.has(G)?Be:new Set([...Be,G]))},[d]);g.useEffect(()=>{bt.setHandler(te=>q(te))},[q]);const Z=g.useCallback(()=>{fetch("/api/settings/llm").then(te=>te.ok?te.json():null).then(te=>{if(te?.providers){const G=Object.values(te.providers).some(ue=>ue.configured);I(G)}}).catch(()=>{})},[]);g.useEffect(()=>{const te=new URLSearchParams(window.location.search),G=te.get("install");if(G&&ec()!==De.STORE){const Ce=te.get("type"),Ne=Ce&&{agent:"agents",team:"teams",skill:"skills"}[Ce]||"agents";localStorage.setItem("markus_nav_installItem",G),localStorage.setItem("markus_nav_storeTab",Ne),te.delete("install"),te.delete("type");const he=te.toString();window.history.replaceState(null,"",window.location.pathname+(he?`?${he}`:"")+"#store"),setTimeout(()=>bt.navigate(De.STORE,{storeTab:Ne,installItem:G}),300)}ie.auth.me().then(({user:Ce})=>{x(Ce),j(!0),pn.connect(Ce.id),Z(),ie.health().then(Ne=>{Ne.updateAvailable&&Ne.latestVersion&&V({latestVersion:Ne.latestVersion,currentVersion:Ne.version})}).catch(()=>{}),W();const Be=()=>{Xl(La.builderArtifacts,()=>ie.builder.artifacts.list()),Xl(La.builderAgents,()=>ie.agents.list()),Xl(La.builderHubMyItems,()=>Wn.myItems()),Xl(La.builderInstalled,()=>ie.builder.artifacts.installed()),Xl(La.hubAgents,()=>Wn.search({type:"agent",limit:50})),Xl(La.hubTeams,()=>Wn.search({type:"team",limit:50})),Xl(La.hubSkills,()=>Wn.search({type:"skill",limit:50}))};typeof requestIdleCallback=="function"?requestIdleCallback(Be,{timeout:5e3}):setTimeout(Be,3e3)}).catch(()=>{x(null),ie.auth.status().then(({initialized:Ce,hasOwner:Be,hasMultipleUsers:Ne})=>{j(Ce),w({hasOwner:Be,hasMultipleUsers:Ne})}).catch(()=>j(!0))}),pn.connect();const ue=pn.on("notification",()=>{window.dispatchEvent(new CustomEvent("markus:notifications-changed"))}),Se=()=>{const Ce=ec();r(Ce),p(Be=>Be.has(Ce)?Be:new Set([...Be,Ce]))};return window.addEventListener("hashchange",Se),window.addEventListener("popstate",Se),()=>{ue(),pn.disconnect(),window.removeEventListener("hashchange",Se),window.removeEventListener("popstate",Se)}},[]);const _=y!=="loading"&&y!==null?y:void 0,J=g.useMemo(()=>d?{[De.HOME]:n.jsx(bw,{authUser:_}),[De.TEAM]:n.jsx(Yk,{authUser:_}),[De.BUILDER]:n.jsx(gse,{authUser:_}),[De.SETTINGS]:n.jsx(ej,{theme:u.mode,onThemeChange:u.setMode,authUser:_,onLogout:()=>{ie.auth.logout().catch(()=>{}),r0(),x(null)},onUserUpdated:te=>x(te)}),[De.WORK]:n.jsx(F3,{authUser:_}),[De.DELIVERABLES]:n.jsx(U3,{authUser:_}),[De.NOTIFICATIONS]:n.jsx(lse,{authUser:_}),[De.REPORTS]:n.jsx(K3,{authUser:_}),[De.SEARCH]:n.jsx(cse,{})}:{[De.HOME]:n.jsx(bw,{authUser:_}),[De.TEAM]:n.jsx(Yk,{authUser:_}),[De.SETTINGS]:n.jsx(ej,{theme:u.mode,onThemeChange:u.setMode,authUser:_,onLogout:()=>{ie.auth.logout().catch(()=>{}),r0(),x(null)},onUserUpdated:te=>x(te)}),[De.STORE]:n.jsx(BY,{authUser:_}),[De.BUILDER]:n.jsx(e7,{authUser:_}),[De.WORK]:n.jsx(F3,{authUser:_}),[De.DELIVERABLES]:n.jsx(U3,{authUser:_}),[De.REPORTS]:n.jsx(K3,{authUser:_})},[_?.id,_?.role,u.mode,d]);if(y==="loading"||y===null&&v===null)return n.jsx("div",{className:"min-h-dvh bg-surface-primary flex items-center justify-center",children:n.jsx("div",{className:"text-fg-tertiary text-sm animate-pulse",children:e("loading")})});const ee=(typeof window<"u"?window.location.hash:"").match(/^#invite\?token=([a-f0-9]+)/);return ee?n.jsx(yse,{token:ee[1],onComplete:()=>{window.location.hash="",localStorage.removeItem("markus_onboarded"),a(!0),S(!0),x("loading"),ie.auth.me().then(te=>x(te.user)).catch(()=>x(null))}}):y===null?n.jsx(bse,{hasOwner:C.hasOwner,hasMultipleUsers:C.hasMultipleUsers,onLogin:(te,G,ue)=>{x(te),G?(localStorage.removeItem("markus_onboarded"),a(!0),ue?.fromHub&&S(!0)):localStorage.getItem("markus_onboarded")||(localStorage.setItem("markus_onboarded","1"),a(!1))}}):T?n.jsx(vse,{onComplete:()=>E(!1),isFirstTime:!0}):s?n.jsx(xse,{theme:u.mode,onThemeChange:u.setMode,skipProfile:N,onComplete:()=>{localStorage.setItem("markus_onboarded","1"),a(!1),S(!1),Z(),q(De.HOME)}}):n.jsxs("div",{className:`flex h-dvh bg-surface-primary text-fg-primary overflow-x-hidden ${d?"flex-col":""}`,children:[!d&&t!==De.SETTINGS&&n.jsxs(n.Fragment,{children:[n.jsx("div",{className:"relative z-40 shrink-0",style:{width:m.width},children:n.jsx(fse,{currentPage:t,onNavigate:te=>{q(te),l(!1)},authUser:y,collapsed:m.collapsed,onToggleCollapse:m.toggle})}),n.jsx("div",{className:`${m.collapsed?"w-0":"w-1.5 cursor-col-resize"} shrink-0 group relative z-10 flex items-center justify-center`,onMouseDown:m.collapsed?void 0:m.onResizeStart,children:!m.collapsed&&n.jsx("div",{className:"w-px h-2/3 border-l border-dashed border-transparent group-hover:border-border-default group-active:border-fg-tertiary transition-colors"})})]}),n.jsxs("div",{className:`flex-1 overflow-hidden flex flex-col min-w-0 ${d&&t!==De.SETTINGS&&t!==De.SEARCH?"pb-14":""}`,children:[R===!1&&!z&&t!==De.SETTINGS&&n.jsxs("div",{className:"flex items-center justify-between px-4 py-2 bg-amber-500/10 border-b border-amber-500/30 text-amber-600 text-sm shrink-0",children:[n.jsx("span",{className:d?"text-xs":"",children:"No LLM provider configured — agents cannot process requests."}),n.jsxs("div",{className:"flex items-center gap-3",children:[n.jsx("button",{onClick:()=>{q(De.SETTINGS)},className:"px-3 py-1 bg-amber-700/50 hover:bg-amber-700/70 text-white text-xs rounded-lg transition-colors",children:"Go to Settings"}),n.jsx("button",{onClick:()=>B(!0),className:"text-amber-500 hover:text-amber-600 text-xs",children:e("dismiss")})]})]}),D&&Y!==D.latestVersion&&n.jsxs("div",{className:"flex items-center justify-between px-4 py-2 bg-brand-500/10 border-b border-brand-500/30 text-brand-400 text-sm shrink-0",children:[n.jsx("span",{className:d?"text-xs":"",children:e("update.available",{latest:D.latestVersion,current:D.currentVersion})}),n.jsxs("span",{className:"flex items-center gap-3 shrink-0",children:[n.jsx("a",{href:"https://markus.global/download",target:"_blank",rel:"noopener noreferrer",className:"text-xs font-medium text-brand-400 hover:text-brand-300 transition-colors",children:e("update.download")}),n.jsx("button",{onClick:()=>{F(D.latestVersion),localStorage.setItem("markus_update_dismissed",D.latestVersion)},className:"text-fg-tertiary hover:text-fg-secondary text-xs shrink-0",children:e("dismiss")})]})]}),L&&!M&&t!==De.SETTINGS&&n.jsxs("div",{className:"flex items-center justify-between px-4 py-2 bg-orange-500/10 border-b border-orange-500/30 text-orange-400 text-sm shrink-0",children:[n.jsx("span",{className:d?"text-xs":"",children:L.teams&&L.toolCalls?e("license.limitReachedBoth"):L.teams?e("license.limitReachedTeams"):e("license.limitReachedToolCalls")}),n.jsxs("span",{className:"flex items-center gap-3 shrink-0",children:[n.jsx("button",{onClick:()=>{window.location.hash="settings/account"},className:"px-3 py-1 bg-orange-600/50 hover:bg-orange-600/70 text-white text-xs rounded-lg transition-colors",children:e("license.upgradeLicense")}),n.jsx("button",{onClick:()=>$(!0),className:"text-fg-tertiary hover:text-fg-secondary text-xs shrink-0",children:e("dismiss")})]})]}),n.jsx("main",{className:"flex-1 overflow-hidden flex flex-col relative",children:Object.keys(J).map(te=>h.has(te)?n.jsx(Tse,{id:te,activePage:t,children:J[te]},te):null)})]}),d&&t!==De.SETTINGS&&t!==De.SEARCH&&n.jsx(hse,{currentPage:t,onNavigate:q,userId:_?.id}),d&&n.jsx(V_,{authUser:_,onNavigate:q}),!d&&U&&n.jsx(jse,{onClose:()=>H(!1),currentPage:t})]})}R9.createRoot(document.getElementById("root")).render(n.jsx(g.StrictMode,{children:n.jsx(Ase,{})}));export{N0 as g};