@markus-global/cli 0.7.5 → 0.7.6

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.
@@ -652,7 +652,7 @@ l0,-`+(r+144)+`c-2,-159.3,-10,-310.7,-24,-454c-53.3,-528,-210,-949.7,
652
652
 
653
653
  `)}),rt.toolCalls?.length)for(let Xn=0;Xn<rt.toolCalls.length;Xn++){const Qn=rt.toolCalls[Xn];xn.push({type:"tool",key:`${Qn.tool}_${Xn}`,tool:Qn.tool,status:Qn.status==="error"?"error":"done",args:Qn.arguments,result:Qn.result,durationMs:Qn.durationMs})}xn.length>0&&(xn.push({type:"text",content:We}),an.segments=xn)}let Dn;if(Ie.startsWith("notes:"))Dn=`dm:${Ie.slice(6)}`;else if(Ie.startsWith("dm:")){const xn=Ie.slice(3).split(":");Dn=`dm:${xn.find(Qn=>Qn!==(t?.id??""))??xn[0]??""}`}else Dn=`ch:${Ie}`;vn(Dn,xn=>[...xn,an]),wt==="agent"&&Dn===`ch:${ne}`&&zt(xn=>{const Xn=xn.filter(Qn=>Qn.id!==ht);return Xn.length===0&&cn.current&&(clearTimeout(cn.current),cn.current=null),Xn})}),[r,vn,t?.id,ne]),b.useEffect(()=>r?void 0:gn.on("chat:agent_no_response",ke=>{const Le=ke.payload,Ie=Le.channel??"",wt=Le.agentId??"";Ie&&wt&&`ch:${ne}`==`ch:${Ie}`&&zt(We=>{const ht=We.filter(Tt=>Tt.id!==wt);return ht.length===0&&cn.current&&(clearTimeout(cn.current),cn.current=null),ht})}),[r,ne]),b.useEffect(()=>r?void 0:gn.on("chat:proactive_message",ke=>{const Le=ke.payload,Ie=Le.targetUserId;if(Ie&&Ie!==t?.id)return;const wt=Le.agentId??"",We=Le.agentName??a("page.fallbackAgent"),ht=Le.message??"";Le.sessionId;const Tt=Le.metadata??{};if(!wt||!ht||ht==="[cancelled]"||ht==="[Stream cancelled]")return;const rt=!!Tt.activityLog||ht.startsWith("[ACTIVITY:"),{cleaned:jt,priority:an}=NS(ht),Dn=!!Tt.notifyUser||jt!==ht,xn={id:`proactive_${Date.now()}`,sender:"agent",text:jt,time:new Date().toLocaleTimeString(),agentName:We,agentId:wt,...Dn?{isNotification:!0,notifyPriority:Tt.priority??an}:{},...rt?{isActivityLog:!0,activityType:Tt.activityType,outcome:Tt.outcome,mailboxItemId:Tt.mailboxItemId,taskId:Tt.taskId,requirementId:Tt.requirementId}:{},...!rt&&Tt.taskId?{taskId:Tt.taskId}:{},...!rt&&Tt.requirementId?{requirementId:Tt.requirementId}:{}},Xn=Ms("direct",wt,"","");vn(Xn,Qn=>[...Qn,xn])}),[r,vn,a]),Bt.find(te=>te.id===Ir),b.useEffect(()=>{cr(null)},[fe]);const Ta=te=>hK(te),Ni=()=>{xs.current?.abort(),xs.current=null;const te=Ve.current;it.current.delete(te),et.current.delete(te),ct(!1),wr([])},ae=async(te,ke)=>{const Le=(te??nt).trim();if(!Le&&Ft.length===0||_e==="direct"&&!fe)return;if(xr.current=!0,Cs.current=!1,$e){xs.current?.abort(),xs.current=null;const rt=Ve.current;it.current.delete(rt),et.current.delete(rt),vn(rt,jt=>{const an=[...jt];for(let Dn=an.length-1;Dn>=0;Dn--)if(an[Dn].sender==="agent"&&!an[Dn].isStopped&&!an[Dn].isError){const xn=an[Dn];if(!(xn.text?.trim()||(xn.segments??[]).some(Qn=>Qn.type==="text"&&(Qn.content||Qn.thinking)||Qn.type==="tool")))an.splice(Dn,1);else{const Qn=(xn.segments??[]).map(ur=>ur.type==="tool"&&ur.status==="running"?{...ur,status:"stopped"}:ur);an[Dn]={...xn,isStopped:!0,segments:Qn}}break}return an}),ct(!1),wr([]),await new Promise(jt=>setTimeout(jt,50))}const Ie=Ft.length>0?Ft.map(rt=>rt.dataUrl):void 0,wt=Ft.length>0?Ft.map(rt=>rt.name):void 0,We=Ms(_e,fe,ne,Be),ht=Rt;te||ft(""),lr([]),Pr(!1),lt(null);const Tt=_e==="dm";if(it.current.add(We),et.current.set(We,[]),Ve.current===We&&!Tt&&(ct(!0),wr([])),_e==="dm"){const rt=wa(t?.id??"",Be),jt=`opt_${Date.now()}`,an={id:jt,sender:"user",text:Le,time:new Date().toLocaleTimeString()};ht&&(an.replyToId=ht.id,an.replyToSender=ht.sender,an.replyToText=ht.text),vn(We,Dn=>[...Dn,an]);try{const Dn=await le.channels.sendMessage(rt,{text:Le,senderName:t?.name??a("page.fallbackYou"),senderId:t?.id,mentions:[],orgId:"default",humanOnly:!0});vn(We,xn=>{const Xn=xn.filter(ur=>ur.id!==jt),Qn=[];return Dn.userMessage&&Qn.push($l(Dn.userMessage,t?.id)),Qn.length>0?[...Xn,...Qn]:xn})}catch(Dn){vn(We,xn=>[...xn,{id:`err_${Date.now()}`,sender:"agent",text:a("page.errorWithMessage",{message:String(Dn)}),time:new Date().toLocaleTimeString(),agentName:a("page.systemName"),isError:!0}])}it.current.delete(We),Ve.current===We&&ct(!1)}else if(_e==="channel"){const rt=`opt_${Date.now()}`,jt={id:rt,sender:"user",text:Le,time:new Date().toLocaleTimeString()};ht&&(jt.replyToId=ht.id,jt.replyToSender=ht.sender,jt.replyToText=ht.text),vn(We,xn=>[...xn,jt]);const an=Ta(Le),Dn=Qe.find(xn=>xn.channelKey===ne);if(ne.startsWith("group:")){const xn=[];if(Dn?.members){for(const Xn of Dn.members)if(Xn.type==="agent"){const Qn=d.find(ur=>ur.id===Xn.id);Qn&&xn.push({id:Qn.id,name:Qn.name,avatarUrl:Qn.avatarUrl})}}xn.length>0&&(cn.current&&clearTimeout(cn.current),zt(xn),cn.current=setTimeout(()=>zt([]),12e4))}try{const xn=await le.channels.sendMessage(ne,{text:Le,senderName:t?.name??a("page.fallbackYou"),mentions:an,senderId:t?.id,orgId:"default",replyToId:ht?.id});vn(We,Xn=>{const Qn=Xn.filter(Si=>Si.id!==rt),ur=[];return xn.userMessage&&ur.push($l(xn.userMessage,t?.id)),xn.agentMessage&&ur.push($l(xn.agentMessage,t?.id)),ur.length>0?[...Qn,...ur]:Xn})}catch(xn){const Xn=Ck(xn,a)||a("page.errorWithMessage",{message:String(xn)});vn(We,Qn=>[...Qn,{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([])}it.current.delete(We),Ve.current===We&&ct(!1)}else{const rt=`a_${Date.now()}`;if(ke?.isResume){const qt=new Date().toISOString();vn(We,Gt=>[...Gt,{id:rt,sender:"agent",text:"",time:new Date().toLocaleTimeString(),rawCreatedAt:qt,segments:[]}])}else{const qt=new Date().toISOString(),Gt={id:`u_${Date.now()}`,sender:"user",text:Le,time:new Date().toLocaleTimeString()};Ie?.length&&(Gt.images=Ie),ht&&(Gt.replyToId=ht.id,Gt.replyToSender=ht.sender,Gt.replyToText=ht.text),vn(We,It=>[...It,Gt,{id:rt,sender:"agent",text:"",time:new Date().toLocaleTimeString(),rawCreatedAt:qt,segments:[]}])}let jt=!1;const an=qt=>{vn(We,Gt=>{const It=[...Gt],Mt=It.findIndex(Ea=>Ea.id===rt);if(Mt<0)return Gt;const Pt=It[Mt].segments??[],$t=Pt[Pt.length-1],tn=$t?.type==="text"?$t.thinking??"":"";let mn="",Hn="",Jn=qt;for(;Jn.length>0;)if(jt){const Ea=Jn.indexOf("</think>");Ea>=0?(mn+=Jn.slice(0,Ea),Jn=Jn.slice(Ea+8),jt=!1):(mn+=Jn,Jn="")}else{const Ea=Jn.indexOf("<think>");Ea>=0?(Hn+=Jn.slice(0,Ea),Jn=Jn.slice(Ea+7),jt=!0):(Hn+=Jn,Jn="")}const Is=tn+mn||void 0,Ao=$t?.type==="text"?[...Pt.slice(0,-1),{type:"text",content:$t.content+Hn,thinking:Is,createdAt:$t.createdAt}]:[...Pt,{type:"text",content:Hn,thinking:Is,createdAt:new Date().toISOString()}];return It[Mt]={...It[Mt],text:It[Mt].text+Hn,segments:Ao},It})},Dn=qt=>{if(qt.type==="session_start"&&qt.sessionId){Ve.current===We&&(Ne(qt.sessionId),Jt(Gt=>Gt.map(It=>It.id===Cn?{...It,id:qt.sessionId}:It)));return}vn(We,Gt=>{const It=[...Gt],Mt=It.findIndex($t=>$t.id===rt);if(Mt<0)return Gt;const Pt=[...It[Mt].committedSegments??[]];return qt.type==="thinking_commit"?Pt.push({type:"text",content:"",thinking:qt.content,createdAt:qt.createdAt}):Pt.push({type:"text",content:qt.content,createdAt:qt.createdAt}),It[Mt]={...It[Mt],committedSegments:Pt},It})},xn=qt=>{(qt.phase==="start"||qt.phase==="end")&&Kn(We,{...qt,phase:qt.phase,ts:Date.now()}),qt.phase==="start"?vn(We,Gt=>{const It=[...Gt],Mt=It.findIndex(Jn=>Jn.id===rt);if(Mt<0)return Gt;const Pt=[...It[Mt].segments??[]];let $t=!1;if(qt.arguments)for(let Jn=Pt.length-1;Jn>=0;Jn--){const Is=Pt[Jn];if(Is.type==="tool"&&Is.tool===qt.tool&&Is.status==="running"){Pt[Jn]={...Is,args:qt.arguments},$t=!0;break}}const tn=`${qt.tool}_${Date.now()}`,mn=new Date().toISOString();$t||Pt.push({type:"tool",key:tn,tool:qt.tool,status:"running",args:qt.arguments,createdAt:mn});const Hn=[...It[Mt].committedSegments??[]];return qt.arguments!==void 0&&Hn.push({type:"tool",key:tn,tool:qt.tool,status:"running",args:qt.arguments,createdAt:mn}),It[Mt]={...It[Mt],segments:Pt,committedSegments:Hn},It}):qt.phase==="output"?vn(We,Gt=>{const It=[...Gt],Mt=It.findIndex($t=>$t.id===rt);if(Mt<0)return Gt;const Pt=[...It[Mt].segments??[]];for(let $t=Pt.length-1;$t>=0;$t--){const tn=Pt[$t];if(tn.type==="tool"&&tn.tool===qt.tool&&tn.status==="running"){Pt[$t]={...tn,liveOutput:(tn.liveOutput??"")+(qt.output??"")};break}}return It[Mt]={...It[Mt],segments:Pt},It}):qt.phase==="subagent_progress"&&qt.subagentEvent?vn(We,Gt=>{const It=[...Gt],Mt=It.findIndex($t=>$t.id===rt);if(Mt<0)return Gt;const Pt=[...It[Mt].segments??[]];for(let $t=Pt.length-1;$t>=0;$t--){const tn=Pt[$t];if(tn.type==="tool"&&(tn.tool==="spawn_subagent"||tn.tool==="spawn_subagents")&&tn.status==="running"){Pt[$t]={...tn,subagentLogs:[...tn.subagentLogs??[],qt.subagentEvent]};break}}return It[Mt]={...It[Mt],segments:Pt},It}):vn(We,Gt=>{const It=[...Gt],Mt=It.findIndex(mn=>mn.id===rt);if(Mt<0)return Gt;const Pt=new Date().toISOString(),$t=[...It[Mt].segments??[]];for(let mn=$t.length-1;mn>=0;mn--){const Hn=$t[mn];if(Hn.type==="tool"&&Hn.tool===qt.tool&&Hn.status==="running"){$t[mn]={...Hn,status:qt.success===!1?"error":"done",args:qt.arguments,result:qt.result,error:qt.error,durationMs:qt.durationMs,liveOutput:void 0,createdAt:Pt};break}}const tn=[...It[Mt].committedSegments??[]];for(let mn=tn.length-1;mn>=0;mn--){const Hn=tn[mn];if(Hn.type==="tool"&&Hn.tool===qt.tool&&Hn.status==="running"){tn[mn]={...Hn,status:qt.success===!1?"error":"done",args:qt.arguments,result:qt.result,error:qt.error,durationMs:qt.durationMs,liveOutput:void 0,createdAt:Pt};break}}return It[Mt]={...It[Mt],segments:$t,committedSegments:tn},It})},Xn=new AbortController;xs.current=Xn;try{const qt=hn===Cn?null:hn,Gt=await le.agents.messageStream(fe,Le,an,xn,Xn.signal,Ie,qt,ke?.isRetry,ke?.isResume,Dn,wt);Ve.current===We&&(Gt.merged&&vn(We,It=>It.filter(Mt=>Mt.id!==rt)),!Gt.merged&&Gt.segments?.length&&vn(We,It=>{const Mt=[...It],Pt=Mt.findIndex(mn=>mn.id===rt);if(Pt<0)return It;const $t=Gt.segments.map((mn,Hn)=>mn.type==="tool"?{type:"tool",key:`${mn.tool}_${Hn}`,tool:mn.tool,status:mn.status,args:mn.arguments,result:mn.result,error:mn.error,durationMs:mn.durationMs,createdAt:mn.createdAt}:{type:"text",content:mn.content,thinking:mn.thinking,createdAt:mn.createdAt});let tn=Gt.content||Mt[Pt].text;return tn||(tn=$t.filter(mn=>mn.type==="text").map(mn=>mn.content).join("")),Mt[Pt]={...Mt[Pt],text:tn,segments:$t,committedSegments:$t},Mt}),!Gt.merged&&!Gt.segments?.length&&vn(We,It=>{const Mt=[...It],Pt=Mt.findIndex(Jn=>Jn.id===rt);if(Pt<0)return It;const $t=Mt[Pt],tn=$t.committedSegments??[],Hn=tn.filter(Jn=>Jn.type==="text"&&!!Jn.content).map(Jn=>Jn.content).join("")||Gt.content||$t.text;return(tn.length>0||Hn)&&(Mt[Pt]={...$t,text:Hn,segments:tn.length>0?tn:$t.segments}),Mt}),Gt.sessionId&&(Ne(Gt.sessionId),Jt(It=>It.map(Mt=>Mt.id===Cn?{...Mt,id:Gt.sessionId}:Mt))),Ga(fe).then(It=>{if(Ve.current===We&&(Mr(It),Gt.sessionId)){const Mt=It.find(Pt=>Pt.id===Gt.sessionId);Mt&&Jt(Pt=>Pt.some(tn=>tn.id===Mt.id)?Pt.map(tn=>tn.id===Mt.id?Mt:tn):[Mt,...Pt.filter(tn=>tn.id!==Cn)])}}))}catch(qt){const Gt=qt?.sessionId;Gt&&_e==="direct"&&Ve.current===We&&(Ne(Gt),Jt(Mt=>Mt.map(Pt=>Pt.id===Cn?{...Pt,id:Gt}:Pt)),Ga(fe).then(Mt=>{if(Ve.current!==We)return;Mr(Mt);const Pt=Mt.find($t=>$t.id===Gt);Pt&&Jt($t=>$t.some(mn=>mn.id===Pt.id)?$t.map(mn=>mn.id===Pt.id?Pt:mn):[Pt,...$t])}));const It=Ck(qt,a);It?vn(We,Mt=>{const Pt=[...Mt],$t=Pt.findIndex(tn=>tn.id===rt);if($t>=0){const tn=Pt[$t].segments??[];Pt[$t]={...Pt[$t],text:It,isError:!0,segments:[...tn,{type:"text",content:It}]}}return Pt}):vn(We,Mt=>{const Pt=[...Mt],$t=Pt.findIndex(tn=>tn.id===rt);if($t>=0){const tn=Pt[$t];if(!(tn.text||tn.segments&&tn.segments.length>0&&tn.segments.some(Hn=>Hn.type==="text"&&(Hn.content||Hn.thinking)||Hn.type==="tool")))return Mt.filter(Hn=>Hn.id!==rt);Pt[$t]={...tn,isStopped:!0}}return Pt})}vn(We,qt=>{const Gt=[...qt],It=Gt.findIndex(Mt=>Mt.id===rt);if(It>=0){const Mt=(Gt[It].segments??[]).map(Pt=>Pt.type==="tool"&&Pt.status==="running"?{...Pt,status:"stopped"}:Pt);Gt[It]={...Gt[It],segments:Mt}}return Gt}),Xn.signal.aborted&&vn(We,qt=>{const Gt=[...qt],It=Gt.findIndex(Mt=>Mt.id===rt);if(It>=0){const Mt=Gt[It];if(!(Mt.text||Mt.segments&&Mt.segments.length>0&&Mt.segments.some($t=>$t.type==="text"&&($t.content||$t.thinking)||$t.type==="tool")))return qt.filter($t=>$t.id!==rt);Gt[It]={...Mt,isStopped:!0}}return Gt});const ur=(Ce.current.get(We)??[]).find(qt=>qt.id===rt),Si=hn&&hn!==Cn?hn:null,C0=ur?.text||ur?.segments?.some(qt=>qt.type==="text"&&qt.content||qt.type==="tool");ur&&!C0&&_e==="direct"&&Si&&!Xn.signal.aborted&&await(async(Gt,It)=>{for(let Mt=0;Mt<Gt;Mt++){await new Promise(Pt=>setTimeout(Pt,It));try{const $t=(await le.sessions.getMessages(Si,2)).messages.find(tn=>tn.role==="assistant");if($t?.content){const tn=Tx($t);vn(We,mn=>{const Hn=[...mn],Jn=Hn.findIndex(Is=>Is.id===rt);return Jn>=0&&(Hn[Jn]={...Hn[Jn],text:tn.text,segments:tn.segments}),Hn});return}}catch{}}})(5,3e3),(xs.current===Xn||xs.current===null)&&(xs.current=null,it.current.delete(We),et.current.delete(We),Ve.current===We&&(ct(!1),wr([])))}};li.current=ae;const[Ye,dt]=b.useState(null),[,Et]=b.useState(new Set),sn=b.useMemo(()=>{for(let te=Ge.length-1;te>=0;te--)if(Ge[te]?.sender==="agent"&&!Ge[te]?.isActivityLog)return Ge[te].id;return null},[Ge]),pr=b.useCallback(te=>{const ke=te.segments?te.segments.filter(Le=>Le.type==="text").map(Le=>Le.content).join(`
654
654
  `):te.text;navigator.clipboard.writeText(ke),dt(te.id),setTimeout(()=>dt(Le=>Le===te.id?null:Le),2e3)},[]),En=b.useCallback(te=>{const ke=Ve.current,Le=Ce.current.get(ke)??Ge,Ie=Le.findIndex(rt=>rt.id===te.id);if(Ie<0)return;let wt=null;for(let rt=Ie-1;rt>=0;rt--)if(Le[rt]?.sender==="user"){wt=Le[rt];break}const We=wt?.text??"";if(!We)return;if(Ie<Le.length-1){const rt=Le.length-1-Ie;if(!window.confirm(rt===1?a("page.retryConfirmSingular"):a("page.retryConfirmPlural",{count:rt})))return}const Tt=wt&&Ie>0&&Le[Ie-1]?.id===wt.id;vn(ke,rt=>{const jt=rt.findIndex(an=>an.id===(Tt?wt.id:te.id));return jt>=0?rt.slice(0,jt):rt}),ae(We,{isRetry:!0})},[Ge,vn,a]),Dt=b.useCallback(te=>{const ke=Ve.current;(Ce.current.get(ke)??Ge).findIndex(wt=>wt.id===te.id)<0||(vn(ke,wt=>{const We=[...wt],ht=We.findIndex(jt=>jt.id===te.id);if(ht<0)return wt;const Tt=We[ht],rt=[...Tt.segments??[]];for(;rt.length>0;){const jt=rt[rt.length-1];if(jt.type==="tool"&&(jt.status==="stopped"||jt.status==="running"))rt.pop();else if(jt.type==="text"&&!jt.content)rt.pop();else break}return We[ht]={...Tt,segments:rt,isStopped:!1,isError:!1},We}),ae("[Continue from where you left off. Do not repeat content already generated.]",{isResume:!0}))},[Ge,vn]),Rs=b.useCallback(te=>{const ke=te.sender==="user"?t?.name??a("page.fallbackYou"):te.agentName??a("page.fallbackAgent");if(lt({id:te.id,sender:ke,text:te.text.slice(0,120)}),_e==="channel"&&te.sender==="agent"&&te.agentName){const Le=`@${te.agentName} `;ft(Ie=>Ie.startsWith(Le)?Ie:Le+Ie)}dn.current?.focus()},[t?.name,_e,a]),Ls=async te=>{Ne(te.id),Vt(!1),Ue(!1),kr.current=null;const ke=Ve.current;Ce.current.delete(ke),ut([]),Jt(Le=>Le.some(Ie=>Ie.id===te.id)?Le:[...Le,te]),await Ys(te.id,ke)},Fs=te=>{if(Jt(ke=>ke.filter(Le=>Le.id!==te)),hn===te){const ke=rn.filter(Le=>Le.id!==te);ke.length>0?Ls(ke[ke.length-1]):Fr()}},Fr=()=>{Ne(Cn);const te=Ve.current;Ce.current.delete(te),ut([]),Ue(!1),kr.current=null,Vt(!1),Jt(ke=>{const Le=ke.filter(Ie=>Ie.id!==Cn);return[{id:Cn,agentId:fe??"",userId:null,title:a("page.newChat"),createdAt:new Date().toISOString(),lastMessageAt:new Date().toISOString()},...Le]})},ie=te=>{if(ft(te),_e!=="channel"){Pr(!1);return}const ke=dn.current?.selectionStart??te.length,Le=te.slice(0,ke),Ie=Le.lastIndexOf("@");if(Ie>=0){const wt=Ie===0?"":Le[Ie-1];if(Ie===0||/[\s\n,,。!?!?;;::、()()\[\]【】]/.test(wt)){const ht=Le.slice(Ie+1);if(!ht.includes(" ")&&!ht.includes(`
655
- `)){Pr(!0),Vi(ht.toLowerCase()),Es(0);return}}}Pr(!1)},Oe=te=>{const ke=dn.current?.selectionStart??nt.length,Ie=nt.slice(0,ke).lastIndexOf("@"),wt=nt.slice(ke),We=te.includes(" ")?`@[${te}]`:`@${te}`,ht=nt.slice(0,Ie)+We+" "+wt;ft(ht),Pr(!1),Es(0);const Tt=Ie+We.length+1;requestAnimationFrame(()=>{dn.current?.setSelectionRange(Tt,Tt)})},Je=10*1024*1024,Mn=5,ia=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"]),Aa=b.useCallback(te=>te.type.startsWith("image/")||ia.has(te.type),[]),rs=te=>te.dataUrl.startsWith("data:image/"),Cd=(te,ke)=>{if(rs({dataUrl:ke}))return null;const Le=te.split(".").pop()?.toLowerCase()??"";return{pdf:"📄",docx:"📝",doc:"📝",xlsx:"📊",xls:"📊",pptx:"📎",csv:"📊",json:"🔧",xml:"🔧",html:"🌐",epub:"📚"}[Le]??"📁"},bl=b.useCallback(te=>{const ke=Array.from(te).filter(Aa);if(ke.length!==0)for(const Le of ke){if(Le.size>Je)continue;const Ie=new FileReader;Ie.onload=()=>{const wt=Ie.result;lr(We=>We.length>=Mn||We.some(ht=>ht.dataUrl===wt)?We:[...We,{id:`img_${Date.now()}_${Math.random().toString(36).slice(2,6)}`,dataUrl:wt,name:Le.name}])},Ie.readAsDataURL(Le)}},[Aa]),Bh=b.useCallback(te=>{lr(ke=>ke.filter(Le=>Le.id!==te))},[]),Hh=b.useCallback(te=>{const ke=te.clipboardData?.files;if(ke&&ke.length>0){const Le=Array.from(ke).filter(Aa);Le.length>0&&(te.preventDefault(),bl(Le))}},[bl,Aa]),Td=b.useCallback(te=>{te.preventDefault();const ke=te.dataTransfer?.files;ke&&ke.length>0&&bl(Array.from(ke).filter(Aa))},[bl,Aa]),yl=b.useCallback(te=>{te.preventDefault()},[]),Qr=d.find(te=>te.id===fe),vl=t?.name??a("page.fallbackYou"),Ad=Ge[Ge.length-1],j0=$e&&Ad?.sender==="agent",N0=Ln&&Ad?.sender==="agent",Ed=b.useMemo(()=>{if(_e!=="channel")return null;if(ne.startsWith("group:custom:")){const ke=Qe.find(Le=>Le.channelKey===ne);return ke?.members?new Set(ke.members.filter(Le=>Le.type==="agent").map(Le=>Le.id)):null}if(!dr)return null;const te=jn.find(ke=>ke.id===dr);return te?new Set(te.members.filter(ke=>ke.type==="agent").map(ke=>ke.id)):null},[_e,ne,dr,jn,Qe]),oa=d.filter(te=>Ed?Ed.has(te.id):!0).filter(te=>te.name.toLowerCase().includes(Wa)),Md=m.find(te=>te.id===Be),Dd=Be===t?.id||!Be,Xs=Qe.find(te=>te.channelKey===ne);b.useEffect(()=>{if(r||!ne.startsWith("group:custom:"))return;const te=Qe.find(ke=>ke.channelKey===ne);!te||te.members||le.groupChats.getById(te.id).then(ke=>{ke.chat.members&&xt(Le=>Le.map(Ie=>Ie.id===te.id?{...Ie,members:ke.chat.members}:Ie))}).catch(()=>{})},[r,ne,Qe]);const Rd=_e==="channel"?Xs?.name??ne:_e==="direct"?Qr?.name??a("page.selectAgent"):_e==="dm"?Dd?a("chat.myNotes"):Md?.name??a("page.directMessage"):a("page.chatTitle"),S0=_e==="channel"?Xs?a("page.placeholder.channel",{name:Xs.name}):a("page.placeholder.channelWithMention",{name:ne}):_e==="dm"?Dd?a("page.placeholder.dmSelf"):a("page.placeholder.dmOther",{name:Md?.name??""}):a(fe?"page.placeholder.direct":"page.placeholder.noAgent"),wl=g&&k==="chat";return n.jsxs("div",{ref:q,className:"flex-1 overflow-hidden flex relative",children:[n.jsx(vK,{authUser:t,agents:d,teams:jn,humans:m,tasks:Bt,externalAgents:rr,groupChats:Qe,chatMode:_e,selectedAgent:fe,activeChannel:ne,activeDmUserId:Be,previewMode:r,onSelectAgent:te=>{ue("direct"),Me(te),_("chat"),un(!1),g&&T()},onSelectChannel:te=>{ue("channel"),he(te),_("chat"),un(!1),g&&T()},onSelectDm:te=>{ue("dm"),de(te),_("chat"),un(!1),g&&T()},onSelectTeam:te=>{const ke=Qe.find(Le=>Le.type==="team"&&Le.teamId===te);g?R(te):ke&&(ue("channel"),he(ke.channelKey),_("chat"),un(!1),!L&&!I&&U(!0))},selectedTeamId:dr??(_e==="direct"&&Qr?.teamId?Qr.teamId:null),onRefreshTeams:Cr,onRefreshAgents:Xr,onRefreshHumans:Sa,onRefreshGroupChats:Br,onViewProfile:at,onManageGroupMembers:te=>{ue("channel"),he(te),_("chat"),un(!0),g&&T()},unreadByAgent:Yr,unreadByChannel:Ka,width:g?void 0:z.width,onResizeStart:g?void 0:z.onResizeStart,hidden:g&&k!=="roster",initialLoading:h}),g&&k==="team"&&N&&(()=>{const te=jn.find(Ie=>Ie.id===N);if(!te)return null;const ke=d.filter(Ie=>Ie.teamId===N),Le=Qe.find(Ie=>Ie.type==="team"&&Ie.teamId===N);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=Se.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:te.name}),n.jsx("p",{className:"text-[10px] text-fg-tertiary",children:a("chat.members_other",{count:te.members?.length||ke.length})})]})]})]}),n.jsxs("div",{className:"flex-1 overflow-y-auto px-3 py-3 space-y-1",children:[Le&&(()=>{const Ie=Ka[Le.channelKey]??0;return n.jsxs("button",{onClick:()=>{ue("channel"),he(Le.channelKey),_("chat"),T()},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:Le.name}),n.jsx("div",{className:"text-[10px] text-fg-tertiary",children:a("chat.groupChat")})]}),Ie>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:Ie}):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"})})]})})(),ke.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")}),ke.map(Ie=>{const wt=Yr.get(Ie.id)??0;return n.jsxs("button",{onClick:()=>{ue("direct"),Me(Ie.id),_("chat"),T()},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(gr,{name:Ie.name||"Agent",avatarUrl:Ie.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:Ie.name}),n.jsx("div",{className:"text-[10px] text-fg-tertiary truncate",children:Ie.role||Ie.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 ${Ie.status==="active"||Ie.status==="idle"?"bg-green-500":Ie.status==="working"||Ie.status==="busy"?"bg-blue-500":Ie.status==="paused"?"bg-amber-500":"bg-gray-400"}`})]},Ie.id)})]})]})]})})(),L&&!I&&!g&&(()=>{const te=dr??(_e==="direct"?Qr?.teamId:void 0);if(!te)return null;const ke=jn.find(Ie=>Ie.id===te);if(!ke)return null;const Le=Qe.find(Ie=>Ie.type==="team"&&Ie.teamId===te);return n.jsx(ck,{team:ke,agents:d,humans:m,authUser:t,groupChat:Le,chatMode:_e,selectedAgent:fe,activeChannel:ne,teams:jn,onSelectAgent:Ie=>{ue("direct"),Me(Ie),_("chat"),un(!1)},onSelectChannel:Ie=>{ue("channel"),he(Ie),_("chat"),un(!1)},onSelectDm:Ie=>{ue("dm"),de(Ie),_("chat"),un(!1)},onBack:()=>U(!1),onViewProfile:at,onRefreshAgents:Xr,onRefreshTeams:Cr,unreadByAgent:Yr,width:K.width,onResizeStart:K.onResizeStart})})(),E&&!g&&(()=>{const te=dr??(_e==="direct"?Qr?.teamId:void 0);if(!te)return null;const ke=jn.find(Ie=>Ie.id===te);if(!ke)return null;const Le=Qe.find(Ie=>Ie.type==="team"&&Ie.teamId===te);return n.jsxs("div",{"data-l2-floating":!0,className:"absolute z-30 inset-0",style:{left:z.width+6},children:[n.jsx("div",{className:"absolute inset-0 bg-black/20",onClick:()=>$(!1)}),n.jsx("div",{className:"relative h-full",style:{width:K.width+8},children:n.jsx(ck,{team:ke,agents:d,humans:m,authUser:t,groupChat:Le,chatMode:_e,selectedAgent:fe,activeChannel:ne,teams:jn,onSelectAgent:Ie=>{ue("direct"),Me(Ie),_("chat"),un(!1),$(!1)},onSelectChannel:Ie=>{ue("channel"),he(Ie),_("chat"),un(!1),$(!1)},onSelectDm:Ie=>{ue("dm"),de(Ie),_("chat"),un(!1),$(!1)},onBack:()=>$(!1),onViewProfile:Ie=>{at(Ie),$(!1)},onRefreshAgents:Xr,onRefreshTeams:Cr,unreadByAgent:Yr,width:K.width})})]})})(),(!g||wl)&&n.jsxs("div",{className:`flex-1 overflow-hidden flex flex-col ${g?"min-w-0":"min-w-[400px]"}`,children:[n.jsxs("div",{className:"shrink-0 relative pb-2",children:[g?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=j.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:Rd}),_e==="direct"&&Qr&&n.jsx(Mk,{agent:Qr,tasks:Bt,onViewProfile:at})]}),n.jsxs("div",{className:"flex items-center px-3 h-9 gap-1 border-t border-border-default/40",children:[n.jsx("button",{onClick:()=>{uo(M)?history.back():_("chat")},className:`px-2.5 py-1 text-xs font-medium rounded-md transition-colors ${M==="chat"?"bg-brand-500/15 text-brand-500":"text-fg-tertiary"}`,children:a("page.chatTitle")}),n.jsx("button",{onClick:()=>{uo(M)||Pe()},className:`px-2.5 py-1 text-xs font-medium rounded-md transition-colors ${uo(M)?"bg-brand-500/15 text-brand-500":"text-fg-tertiary"}`,children:a(_e==="channel"?"page.teamTab":"page.profileTab")}),n.jsx("div",{className:"flex-1"}),_e==="channel"&&Xs?.type==="custom"&&n.jsxs("button",{onClick:()=>un(!en),className:`text-[11px] px-2 py-1 rounded-md font-medium shrink-0 flex items-center gap-1 ${en?"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"})]}),Xs.members?.length??Xs.memberCount??0]}),_e==="direct"&&!uo(M)&&n.jsxs(n.Fragment,{children:[n.jsx("button",{onClick:Fr,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:$n,onClick:()=>Vt(!At),className:`p-1 rounded-md transition-colors shrink-0 ${At?"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 te=dr?jn.find(jt=>jt.id===dr):void 0,ke=_e==="direct"&&fe?VK:_e==="channel"&&dr?WK:["chat"],Le=async()=>{const jt=se.trim();if(!jt){ee(!1);return}try{_e==="direct"&&fe?(await le.agents.updateConfig(fe,{name:jt}),Xr()):_e==="channel"&&dr&&(await le.teams.update(dr,{name:jt}),Cr())}catch{}ee(!1)},Ie=async()=>{try{_e==="direct"&&fe?(await le.agents.updateConfig(fe,{roleDescription:Re}),Xr()):_e==="channel"&&dr&&(await le.teams.update(dr,{description:Re}),Cr())}catch{}je(!1)},wt=_e==="direct"?Qr?.name:_e==="channel"?te?.name??Xs?.name:Md?.name??"",We=_e==="direct"?Qr?.role||"":_e==="channel"&&te?.description||"",ht=_e==="direct"?Qr?.avatarUrl:void 0,Tt=wt||"U",rt=_e==="direct"&&fe||_e==="channel"&&dr;return n.jsxs("div",{className:"flex flex-col",children:[n.jsxs("div",{className:"flex items-center px-4 h-14 gap-2.5",children:[(!L||I)&&(_e==="channel"&&dr||_e==="direct"&&Qr?.teamId)&&n.jsx("button",{onClick:Y,className:`w-8 h-8 flex items-center justify-center rounded-lg transition-colors shrink-0 ${E?"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"})]})}),rt&&(_e==="channel"&&dr?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(gr,{name:Tt,avatarUrl:ht,size:36,className:"rounded-xl shrink-0"})),rt?n.jsxs("div",{className:"flex-1 min-w-0",children:[n.jsxs("div",{className:"flex items-center gap-2",children:[Q?n.jsx("input",{ref:we,value:se,onChange:jt=>X(jt.target.value),onBlur:Le,onKeyDown:jt=>{jt.key==="Enter"&&Le(),jt.key==="Escape"&&ee(!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:()=>{X(wt??""),ee(!0)},title:"Click to edit name",children:wt}),_e==="direct"&&Qr&&n.jsx(Mk,{agent:Qr,tasks:Bt,onViewProfile:at})]}),(_e==="direct"||_e==="channel"&&dr)&&(me?n.jsx("input",{ref:pe,value:Re,onChange:jt=>Ee(jt.target.value),onBlur:Ie,onKeyDown:jt=>{jt.key==="Enter"&&Ie(),jt.key==="Escape"&&je(!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:()=>{Ee(We),je(!0)},title:"Click to edit description",children:We||"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:Rd}),_e==="dm"&&n.jsx("span",{className:"text-xs text-fg-tertiary",children:Dd?a("page.privateNotepad"):""})]}),n.jsxs("div",{className:"ml-auto flex items-center gap-2 shrink-0",children:[_e==="channel"&&Xs?.type==="custom"&&n.jsxs("button",{onClick:()=>un(!en),className:`text-xs px-2.5 py-1 rounded-md border transition-colors flex items-center gap-1.5 ${en?"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"})]}),Xs.members?.length??Xs.memberCount??0]}),_e==="direct"&&Qr&&M==="chat"&&n.jsxs("div",{className:"flex items-center gap-1.5",children:[n.jsx("button",{onClick:Fr,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:$n,onClick:()=>Vt(!At),className:`p-1.5 rounded-md transition-colors ${At?"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"})})})]})]})]}),ke.length>1&&n.jsx("div",{className:"flex items-center gap-1 px-4 pb-1.5 overflow-x-auto scrollbar-hide",children:ke.map(jt=>n.jsxs("button",{onClick:()=>_(jt),className:`px-3 py-1.5 text-xs font-medium rounded-md transition-colors whitespace-nowrap flex items-center gap-1 ${M===jt?"bg-brand-500/15 text-brand-500":"text-fg-tertiary hover:text-fg-secondary hover:bg-surface-elevated/50"}`,children:[n.jsx("span",{children:GK(jt)}),KK(jt,a)]},jt))})]})})(),_e==="direct"&&fe&&M==="chat"&&rn.length>1&&n.jsx("div",{className:"flex items-center gap-0 px-3 overflow-x-auto scrollbar-hide",children:rn.map(te=>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] ${te.id===hn?"text-brand-500 bg-brand-500/10":"text-fg-tertiary hover:text-fg-secondary hover:bg-surface-elevated/50"}`,onClick:()=>{if(te.id===Cn){Ne(Cn);const ke=Ve.current;Ce.current.delete(ke),ut([])}else Ls(te)},children:[te.isMain&&n.jsx("span",{className:"text-[10px] opacity-50 shrink-0",children:"●"}),n.jsx("span",{className:"truncate",children:te.id===Cn?a("page.newChat"):te.isMain?a("page.sessionMain"):te.title||a("page.sessionConversation")}),!te.isMain&&n.jsx("button",{onClick:ke=>{ke.stopPropagation(),Fs(te.id)},className:"opacity-0 group-hover:opacity-100 text-fg-tertiary hover:text-fg-secondary transition-opacity shrink-0",children:"✕"})]},te.id))}),_e==="channel"&&Xs?.type==="custom"&&en&&(()=>{const te=Xs,ke=te.members??[],Le=[];for(const Ie of d)ke.some(wt=>wt.id===Ie.id)||Le.push({id:Ie.id,name:Ie.name,type:"agent",subtitle:Ie.role||"Agent"});for(const Ie of m)ke.some(wt=>wt.id===Ie.id)||Le.push({id:Ie.id,name:Ie.name,type:"human",subtitle:Ie.email||Ie.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")," (",ke.length,")"]}),n.jsx("button",{onClick:()=>un(!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:ke.map(Ie=>n.jsxs("span",{className:`inline-flex items-center gap-1.5 px-2 py-1 rounded-full text-[11px] font-medium ${Ie.type==="agent"?"bg-brand-500/10 text-brand-500":"bg-green-500/10 text-green-600"}`,children:[n.jsx(gr,{name:Ie.name,size:16,bgClass:Ie.type==="agent"?"bg-brand-500/15 text-brand-500":"bg-green-500/15 text-green-600"}),Ie.name,Ie.id!==t?.id&&n.jsx("button",{onClick:async()=>{try{await le.groupChats.removeMember(te.id,Ie.id),xt(wt=>wt.map(We=>We.id===te.id?{...We,members:(We.members??[]).filter(ht=>ht.id!==Ie.id),memberCount:(We.memberCount??1)-1}:We))}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"})]})})]},Ie.id))}),Le.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 Ie=>{const wt=Ie.target.value;if(!wt)return;const We=Le.find(ht=>ht.id===wt);if(We)try{await le.groupChats.addMember(te.id,We.id,We.type,We.name),xt(ht=>ht.map(Tt=>Tt.id===te.id?{...Tt,members:[...Tt.members??[],{id:We.id,name:We.name,type:We.type}],memberCount:(Tt.memberCount??0)+1}:Tt))}catch{}},children:[n.jsx("option",{value:"",children:a("page.addMemberPlaceholder")}),Le.map(Ie=>n.jsxs("option",{value:Ie.id,children:["[",Ie.type==="agent"?"Agent":"Human","] ",Ie.name]},Ie.id))]})})]})})(),_e==="direct"&&fe&&At&&n.jsxs("div",{ref:js,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:()=>Vt(!1),className:"text-fg-tertiary hover:text-fg-secondary text-xs",children:"✕"})]}),n.jsxs("div",{className:"flex-1 overflow-y-auto p-2",children:[$r.length===0&&n.jsx("div",{className:"text-xs text-fg-tertiary text-center py-6",children:a("page.noConversationsYet")}),(()=>{const te=new Date,ke=new Date(te.getFullYear(),te.getMonth(),te.getDate()).getTime(),Le=ke-864e5,Ie=ke-7*864e5,wt=[],We=[],ht=[],Tt=[],rt=[];for(const jt of $r){const an=new Date(jt.lastMessageAt).getTime();an>=ke?We.push(jt):an>=Le?ht.push(jt):an>=Ie?Tt.push(jt):rt.push(jt)}return We.length>0&&wt.push({label:a("page.dateToday"),items:We}),ht.length>0&&wt.push({label:a("page.dateYesterday"),items:ht}),Tt.length>0&&wt.push({label:a("page.datePrevious7Days"),items:Tt}),rt.length>0&&wt.push({label:a("page.dateOlder"),items:rt}),wt.map(jt=>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:jt.label}),jt.items.map(an=>n.jsxs("button",{onClick:()=>{Ls(an)},className:`w-full text-left px-3 py-2.5 rounded-lg text-xs mb-0.5 transition-colors ${an.id===hn?"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:[an.isMain&&n.jsx("span",{className:"text-[10px] text-brand-500 opacity-80",children:"●"}),an.isMain?a("page.sessionMain"):an.title||a("page.sessionConversation")]}),n.jsx("div",{className:"text-fg-tertiary text-[10px] mt-0.5",children:new Date(an.lastMessageAt).toLocaleString()})]},an.id))]},jt.label))})()]})]})]}),g&&M==="profile"&&_e==="direct"&&fe&&n.jsx("div",{className:"flex-1 overflow-y-auto",children:n.jsx(dk,{agentId:fe,onBack:()=>_("chat"),inline:!0,defaultTab:H,highlightMailboxId:B,onSwipeBack:()=>{uo(F.current)?history.back():_("chat")},authUser:t})}),g&&M==="profile"&&_e==="channel"&&dr&&n.jsx("div",{className:"flex-1 overflow-y-auto",onTouchStart:g?Ze.onTouchStart:void 0,onTouchEnd:g?Ze.onTouchEnd:void 0,children:n.jsx(jk,{teamId:dr,onBack:()=>_("chat"),inline:!0,onSelectAgent:te=>{ue("direct"),Me(te),Pe()}})}),!g&&uo(M)&&_e==="direct"&&fe&&n.jsx("div",{className:"flex-1 overflow-y-auto",children:n.jsx(dk,{agentId:fe,onBack:()=>_("chat"),inline:!0,headless:!0,activeTab:M,highlightMailboxId:B,authUser:t})}),!g&&uo(M)&&_e==="channel"&&dr&&n.jsx("div",{className:"flex-1 flex flex-col min-h-0",children:n.jsx(jk,{teamId:dr,onBack:()=>_("chat"),inline:!0,headless:!0,activeTab:M,onSelectAgent:te=>{ue("direct"),Me(te),_("overview"),!L&&!I&&U(!0)}})}),n.jsxs("div",{className:`flex-1 overflow-hidden flex flex-col relative ${M!=="chat"?"hidden":""}`,children:[Lt&&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:Hs,className:`flex-1 overflow-y-auto space-y-3 ${g?"p-2.5":"p-5 2xl:pr-[280px]"}`,onScroll:Wi,onTouchStart:g?Ze.onTouchStart:void 0,onTouchEnd:g?Ze.onTouchEnd:void 0,children:[Ge.length===0&&!$e&&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:_e==="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"})})}),_e==="channel"&&n.jsx("div",{children:a("page.emptyChannel",{name:Xs?.name??ne})}),_e==="direct"&&!fe&&n.jsx("div",{children:a("page.emptySelectAgent")}),_e==="direct"&&fe&&n.jsx("div",{children:a("page.emptyNewConversation",{name:Qr?.name??""})})]}),_e==="channel"?Ge.map(te=>n.jsxs("div",{id:`msg-${te.id}`,className:"group/msg flex gap-3 transition-colors rounded-lg",children:[n.jsx("div",{className:"shrink-0 cursor-pointer",onClick:ke=>{if(te.sender==="agent"&&te.agentId){const Le=ke.currentTarget.getBoundingClientRect();O({agentId:te.agentId,top:Le.top,left:Le.right+8})}},children:n.jsx(gr,{name:te.sender==="user"?vl:te.agentName??a("page.fallbackAgent"),avatarUrl:te.sender==="user"?t?.avatarUrl:d.find(ke=>ke.id===te.agentId)?.avatarUrl,size:32,bgClass:te.sender==="user"?"bg-brand-600":"bg-brand-500/15 text-brand-600",className:te.sender==="agent"?"hover:ring-1 hover:ring-brand-500/40 rounded-lg":"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:te.sender==="user"?vl:te.agentName??a("page.fallbackAgent")}),n.jsx("span",{className:"text-xs text-fg-tertiary",children:te.time})]}),te.replyToId&&te.replyToSender&&n.jsxs("button",{onClick:()=>{const ke=document.getElementById(`msg-${te.replyToId}`);ke&&(ke.scrollIntoView({behavior:"smooth",block:"center"}),ke.classList.add("bg-brand-500/10"),setTimeout(()=>ke.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:te.replyToSender}),n.jsx("span",{className:"truncate max-w-[250px]",children:te.replyToText??"..."})]}),n.jsxs("div",{className:`mt-0.5 ${te.sender==="agent"?"bg-surface-chat-bubble rounded-2xl px-3.5 py-2.5":""} ${te.isError||te.sender==="agent"&&te.text.startsWith("⚠")?"border-b-2 border-red-500/60":""}`,children:[te.sender==="agent"?n.jsx(Ur,{content:te.text,className:"text-sm text-fg-secondary",onMentionClick:pt,knownNames:Ct}):n.jsxs("div",{className:"text-sm text-fg-secondary whitespace-pre-wrap",children:[te.images&&te.images.length>0&&n.jsx("div",{className:"flex flex-wrap gap-1.5 mb-1",children:te.images.map((ke,Le)=>n.jsx("img",{src:ke,alt:"",className:"max-w-[200px] max-h-[150px] rounded-lg object-cover cursor-pointer hover:opacity-80 transition-opacity",onClick:()=>window.open(ke,"_blank")},Le))}),lk(te.text,d,(ke,Le)=>{const Ie=Le.currentTarget.getBoundingClientRect();O({agentId:ke.id,top:Ie.bottom,left:Ie.left})})]}),te.isNotification&&n.jsx(Sk,{priority:te.notifyPriority})]}),!r&&n.jsx("div",{className:`transition-opacity ${g?"opacity-100":"opacity-0 group-hover/msg:opacity-100"}`,children:n.jsx(Tk,{msg:te,onCopy:pr,onRetry:En,onResume:Dt,onReply:Rs,isCopied:Ye===te.id,isLastAgentMsg:te.id===sn})})]})]},te.id)):Ge.map((te,ke)=>{const Ie=j0&&ke===Ge.length-1&&$e,wt=N0&&ke===Ge.length-1||Ie,We=!Ie||te.isStopped;return te.isActivityLog?null:n.jsxs("div",{id:`msg-${te.id}`,className:"group/msg flex gap-3 transition-colors rounded-lg",children:[n.jsx("div",{className:"shrink-0",children:n.jsx(gr,{name:te.sender==="user"?vl:te.agentName??(_e==="direct"?Qr?.name??a("page.fallbackAgent"):a("page.fallbackAgent")),avatarUrl:te.sender==="user"?t?.avatarUrl:d.find(ht=>ht.id===(te.agentId??(_e==="direct"?Qr?.id:void 0)))?.avatarUrl,size:32,bgClass:te.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:te.sender==="user"?vl:n.jsx(FK,{name:te.agentName??(_e==="direct"?Qr?.name??a("page.fallbackAgent"):a("page.fallbackAgent")),agentId:te.agentId??(_e==="direct"?Qr?.id:void 0),agents:d,onViewProfile:at})}),n.jsx("span",{className:"text-xs text-fg-tertiary",children:te.time})]}),te.replyToId&&te.replyToSender&&n.jsxs("button",{onClick:()=>{const ht=document.getElementById(`msg-${te.replyToId}`);ht&&(ht.scrollIntoView({behavior:"smooth",block:"center"}),ht.classList.add("bg-brand-500/10"),setTimeout(()=>ht.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:te.replyToSender}),n.jsx("span",{className:"truncate max-w-[250px]",children:te.replyToText??"..."})]}),n.jsxs("div",{className:`mt-0.5 ${te.sender==="agent"?"bg-surface-chat-bubble rounded-2xl px-3.5 py-2.5":""} ${te.isError||te.sender==="agent"&&te.text.startsWith("⚠")?"border-b-2 border-red-500/60":""} ${wt&&te.sender==="agent"?"streaming-bubble":""}`,children:[te.sender==="user"?n.jsxs("div",{className:"text-sm text-fg-secondary whitespace-pre-wrap",children:[te.images&&te.images.length>0&&n.jsx("div",{className:"flex flex-wrap gap-1.5 mb-1",children:te.images.map((ht,Tt)=>n.jsx("img",{src:ht,alt:"",className:"max-w-[200px] max-h-[150px] rounded-lg object-cover cursor-pointer hover:opacity-80 transition-opacity",onClick:()=>window.open(ht,"_blank")},Tt))}),te.text&&n.jsx("span",{className:"leading-relaxed",children:lk(te.text,d,(ht,Tt)=>{const rt=Tt.currentTarget.getBoundingClientRect();O({agentId:ht.id,top:rt.bottom,left:rt.left})})})]}):n.jsx(UK,{msg:te,isStreaming:Ie,liveActivities:Ie?gs:[],onViewModeChange:ht=>Et(Tt=>{const rt=new Set(Tt);return ht==="full"?rt.add(te.id):rt.delete(te.id),rt}),onMentionClick:pt,knownNames:Ct}),te.isNotification&&n.jsx(Sk,{priority:te.notifyPriority})]}),We&&!r&&n.jsx("div",{className:`transition-opacity ${te.isStopped||g?"opacity-100":"opacity-0 group-hover/msg:opacity-100"}`,children:n.jsx(Tk,{msg:te,onCopy:pr,onRetry:En,onResume:Dt,onReply:Rs,isCopied:Ye===te.id,isLastAgentMsg:te.id===sn})})]})]},te.id)}),_e==="channel"&&Ut.length>0&&n.jsx("div",{className:"flex flex-col gap-1.5 py-2",children:Ut.map(te=>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:()=>at(te.id,{tab:"overview"}),children:[n.jsxs("div",{className:"relative shrink-0",children:[n.jsx(gr,{name:te.name,avatarUrl:te.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:te.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:"→"})]},te.id))}),n.jsx("div",{ref:va})]})]}),W&&(()=>{const te=d.find(ke=>ke.id===W.agentId);return te?n.jsx(qK,{agent:te,anchorRect:{top:W.top,left:W.left},onClose:()=>O(null),onViewProfile:at}):null})(),n.jsx("div",{className:`${g?"px-3 py-2":"px-5 py-3 2xl:pr-[280px]"} relative shrink-0 ${M!=="chat"?"hidden":""}`,onDrop:Td,onDragOver:yl,children:n.jsxs("div",{className:`bg-surface-primary border border-border-default shadow-lg shadow-black/5 ${g?"rounded-2xl p-3":"rounded-2xl p-3 max-w-3xl"}`,children:[sa&&oa.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")}),oa.map((te,ke)=>n.jsxs("button",{ref:Le=>{ke===Ks&&Le&&Le.scrollIntoView({block:"nearest"})},onClick:()=>Oe(te.name),onMouseEnter:()=>Es(ke),className:`w-full text-left px-4 py-2 text-sm flex items-center gap-2 transition-colors ${ke===Ks?"bg-brand-500/15 text-brand-500":"text-fg-secondary hover:bg-surface-overlay"}`,children:[n.jsx(gr,{name:te.name,avatarUrl:te.avatarUrl,size:24,bgClass:"bg-brand-500/20 text-brand-500"}),n.jsx("span",{className:"flex-1 min-w-0",children:te.name}),n.jsx("span",{className:"text-xs text-fg-tertiary ml-auto",children:te.role})]},te.id))]}),Ft.length>0&&n.jsxs("div",{className:"flex items-center gap-2 mb-2 overflow-x-auto pb-1",children:[Ft.map(te=>n.jsxs("div",{className:"relative group/img shrink-0",children:[rs(te)?n.jsx("img",{src:te.dataUrl,alt:te.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:te.name,children:[n.jsx("span",{className:"text-xl leading-none",children:Cd(te.name,te.dataUrl)}),n.jsx("span",{className:"text-[9px] text-fg-tertiary truncate max-w-[56px] px-0.5",children:te.name.split(".").pop()?.toUpperCase()})]}),n.jsx("button",{onClick:()=>Bh(te.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:"×"})]},te.id)),Ft.length<Mn&&n.jsx("button",{onClick:()=>_n.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"})})})]}),Ft.length>0&&Ft.some(te=>rs(te))&&Qr&&Qr.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:_n,type:"file",accept:"image/*,.pdf,.docx,.xlsx,.pptx,.xls,.doc,.csv,.json,.xml,.html,.epub",multiple:!0,className:"hidden",onChange:te=>{te.target.files&&bl(te.target.files),te.target.value=""}}),Rt&&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:Rt.sender}),n.jsx("p",{className:"text-[11px] text-fg-tertiary truncate",children:Rt.text})]}),n.jsx("button",{onClick:()=>lt(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:()=>_n.current?.click(),disabled:_e==="direct"&&!fe,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:dn,value:nt,onChange:te=>{ie(te.target.value),Sn()},onKeyDown:te=>{if(sa&&oa.length>0){const ke=te.key==="ArrowUp"||te.ctrlKey&&te.key==="p",Le=te.key==="ArrowDown"||te.ctrlKey&&te.key==="n",Ie=te.key==="Enter"||te.key==="Tab",wt=te.key==="Escape";if(ke){te.preventDefault(),Es(We=>(We-1+oa.length)%oa.length);return}if(Le){te.preventDefault(),Es(We=>(We+1)%oa.length);return}if(Ie){te.preventDefault();const We=oa[Ks];We&&Oe(We.name);return}if(wt){te.preventDefault(),Pr(!1);return}}te.key==="Enter"&&!te.shiftKey&&(te.preventDefault(),ae())},onPaste:Hh,placeholder:S0,disabled:_e==="direct"&&!fe,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"}}),$e&&_e!=="dm"&&n.jsx("button",{onClick:Ni,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:()=>{ae()},disabled:_e==="direct"&&!fe||!nt.trim()&&Ft.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 Mk({agent:e,tasks:t,onViewProfile:r}){const{t:s}=kt(["team","common"]),[a,i]=b.useState(!1),l=b.useRef(null),d=b.useRef(null),u=e.status==="working",m=e.status==="error",p=!m&&!!e.lastError&&!!e.lastErrorAt&&Date.now()-new Date(e.lastErrorAt).getTime()<1800*1e3,h=u?t.find(C=>C.assignedAgentId===e.id&&C.status==="in_progress"):null,y=e.currentActivity;b.useEffect(()=>{if(!a)return;const C=k=>{l.current&&!l.current.contains(k.target)&&i(!1)};return document.addEventListener("mousedown",C),()=>document.removeEventListener("mousedown",C)},[a]),b.useLayoutEffect(()=>{if(!a||!d.current)return;const C=d.current,k=C.getBoundingClientRect(),N=window.innerWidth;k.right>N-8&&(C.style.left="auto",C.style.right="0"),k.left<8&&(C.style.left="0",C.style.right="auto");const j=N-16;k.width>j&&(C.style.width=`${j}px`)},[a]);const g=m?"bg-red-400 animate-pulse":p?"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"),S=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&&!p?"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":p?"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 ${g}`}),n.jsx("span",{className:`text-xs ${m?"text-red-500":p?"text-amber-600":u?"text-blue-500":"text-green-600"}`,children:v}),p&&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&&p&&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")}),h?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),Nt.navigate(Se.WORK,{openTask:h.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:h.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:S}),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 QK=[{value:"system",label:"System"},{value:"light",label:"Light"},{value:"dark",label:"Dark"},{value:"cyberpunk",label:"Cyberpunk"},{value:"mono",label:"Mono"}],Ib="markus-theme";function Dk(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 ZK(){try{const e=localStorage.getItem(Ib);if(e==="midnight")return localStorage.setItem(Ib,"dark"),"dark";if(e==="light"||e==="dark"||e==="system"||e==="cyberpunk"||e==="mono")return e}catch{}return"system"}function JK(){const[e,t]=b.useState(ZK),r=b.useCallback(s=>{t(s);try{localStorage.setItem(Ib,s)}catch{}Dk(s)},[]);return b.useEffect(()=>{Dk(e)},[e]),{mode:e,setMode:r}}const SS=[{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:"users",labelKey:"nav.users",adminOnly:!0},{id:"remote",labelKey:"nav.remote",adminOnly:!0}];function Rk(){const t=window.location.hash.slice(1).split("/");if(t[0]==="settings"&&t[1]){const r=t[1];if(SS.some(s=>s.id===r))return r}return null}function Lk({theme:e,onThemeChange:t,authUser:r,onLogout:s,onUserUpdated:a}={}){const{t:i,i18n:l}=kt(["settings","common"]),d=ks(),[u,m]=b.useState(!1),[p,h]=b.useState(!1),y=b.useRef(null),[g,v]=b.useState(Rk);b.useEffect(()=>{const ie=()=>v(Rk());return window.addEventListener("hashchange",ie),()=>window.removeEventListener("hashchange",ie)},[]);const S=b.useCallback(ie=>{v(ie),history.pushState(null,"",`#settings/${ie}`)},[]),C=b.useCallback(()=>{v(null),history.pushState(null,"","#settings")},[]),k=g??(d?null:"appearance");b.useEffect(()=>{const ie=()=>h(!0);return window.addEventListener("markus:open-edit-profile",ie),()=>window.removeEventListener("markus:open-edit-profile",ie)},[]),b.useEffect(()=>{if(!u)return;const ie=Oe=>{y.current&&!y.current.contains(Oe.target)&&m(!1)};return document.addEventListener("mousedown",ie),()=>document.removeEventListener("mousedown",ie)},[u]);const[N,j]=b.useState(null),[T,R]=b.useState(null),[M,_]=b.useState(""),[F,z]=b.useState(!1),[L,U]=b.useState(null),[K,q]=b.useState(null),[I,D]=b.useState(null),[E,$]=b.useState(null),[Y,W]=b.useState(!1),[O,H]=b.useState(null),[Z,B]=b.useState(null),[J,Q]=b.useState(!1),[ee,se]=b.useState(null),[X,me]=b.useState({}),[je,Re]=b.useState(!1),[Ee,we]=b.useState(null),[pe,Pe]=b.useState(!1),[Ae,Xe]=b.useState(""),[Ze,at]=b.useState(!1),[pt,Ct]=b.useState(null),[_e,ue]=b.useState([]),[fe,Me]=b.useState([]),[ne,he]=b.useState(null),[Be,de]=b.useState(null),[Ce,et]=b.useState(""),[it,Ve]=b.useState(null),Ge=b.useRef(null),ut=b.useRef(!1),[nt,ft]=b.useState(!1),[Rt,lt]=b.useState(200),[$e,ct]=b.useState(!1),[Ut,zt]=b.useState(null),[cn,Ln]=b.useState(!1),[Xt,kn]=b.useState(1),[tr,ir]=b.useState(!1),[gs,wr]=b.useState(null),[or,Ue]=b.useState(!1),[Lt,Zt]=b.useState(0),[Ft,lr]=b.useState(!0),[_n,dn]=b.useState(!1),[Sn,Cn]=b.useState(!1),[$r,Mr]=b.useState(9333),[hn,Ne]=b.useState(!1),[At,Vt]=b.useState(null),[rn,Jt]=b.useState(null),[Ot,Fn]=b.useState({serperApiKey:"",tavilyApiKey:"",bingApiKey:"",googleSearchApiKey:"",googleSearchCx:"",serpApiKey:"",braveApiKey:"",exaApiKey:"",bochaApiKey:""}),[$n,js]=b.useState(!1),[kr,xe]=b.useState(null),[Qe,xt]=b.useState(null),[Kt,on]=b.useState(!1),[en,un]=b.useState(new Set),[jn,Bn]=b.useState(null),[rr,Dr]=b.useState(!1),Bt=()=>({"Content-Type":"application/json",Authorization:`Bearer ${localStorage.getItem("markus_token")??""}`}),nr=b.useCallback(()=>{le.health().then(j).catch(()=>{}),fetch("/api/settings/llm").then(ie=>ie.ok?ie.json():Promise.reject(ie.status)).then(ie=>{ie&&typeof ie=="object"&&"providers"in ie&&(R(ie),_(ie.defaultProvider))}).catch(()=>{})},[]),Ir=b.useCallback(()=>{fetch("/api/settings/oauth/providers").then(ie=>ie.ok?ie.json():Promise.reject(ie.status)).then(ie=>ue(ie.providers??[])).catch(()=>{})},[]),cr=b.useCallback(()=>{fetch("/api/settings/oauth/profiles",{headers:Bt()}).then(ie=>ie.ok?ie.json():Promise.reject(ie.status)).then(ie=>Me(ie.profiles??[])).catch(()=>{})},[]),Va=b.useCallback(()=>{le.settings.getAgent().then(ie=>{ie&&typeof ie.maxToolIterations=="number"&&lt(ie.maxToolIterations),ie?.cognitive&&(Ln(ie.cognitive.enabled??!1),kn(ie.cognitive.maxDepth??1))}).catch(()=>{})},[]),Gr=b.useCallback(()=>{le.settings.getBrowser().then(ie=>{ie&&(Ue(ie.bringToFront??!1),Zt(ie.remoteDebuggingPort??0),lr(ie.autoCloseTabs??!0),dn(ie.autoClickAllowDialog??!1),Cn(ie.extensionConnected??!1),Mr(ie.extensionBridgePort??9333))}).catch(()=>{})},[]),$s=b.useCallback(()=>{le.settings.getSearch().then(ie=>{ie&&Jt(ie)}).catch(()=>{})},[]),Bs=b.useCallback(()=>{on(!0),le.system.storage().then(xt).catch(()=>{}).finally(()=>on(!1)),le.system.orphans().then(Bn).catch(()=>{})},[]);b.useEffect(()=>{nr(),Ir(),cr(),Va(),Gr(),$s(),Bs()},[nr,Ir,cr,Va,Gr,$s,Bs]),b.useEffect(()=>{const ie=()=>Bs();return window.addEventListener("markus:data-changed",ie),()=>window.removeEventListener("markus:data-changed",ie)},[Bs]);const sa=b.useCallback(async()=>{Q(!0),se(null),B(null),me({});try{const ie=await fetch("/api/settings/env-models",{headers:Bt()});if(!ie.ok){se({type:"err",text:i("envConfig.detectionFailedHttp",{status:ie.status})});return}const Oe=await ie.json();if(B(Oe),Oe.detected.length===0)se({type:"err",text:i("envConfig.noKeysFound")});else{const Je={};for(const Mn of Oe.detected)Je[Mn.provider]=!0;me(Je)}}catch{se({type:"err",text:i("envConfig.failedToDetect")})}finally{Q(!1)}},[i]),Pr=b.useCallback(async()=>{Pe(!0),Ct(null),we(null);try{const ie=await fetch("/api/settings/detect-ollama",{headers:Bt()});if(!ie.ok){Ct({type:"err",text:i("ollama.detectFailed")});return}const Oe=await ie.json();we(Oe),Oe.found&&Oe.models&&Oe.models.length>0?Xe(Oe.models[0].name):Oe.found||Ct({type:"err",text:Oe.error||i("ollama.notRunning")})}catch{Ct({type:"err",text:i("ollama.detectFailed")})}finally{Pe(!1)}},[i]),Wa=T?Object.values(T.providers).some(ie=>ie.configured):!1;b.useEffect(()=>{T&&!Wa&&!ut.current&&(ut.current=!0,sa(),Pr())},[T,Wa,sa,Pr]);const Vi=async()=>{if(!(!M||M===T?.defaultProvider)){z(!0),U(null);try{const ie=await fetch("/api/settings/llm",{method:"POST",headers:Bt(),body:JSON.stringify({defaultProvider:M})}),Oe=await ie.json();ie.ok?(R(Oe),U({type:"ok",text:i("defaultProvider.updated",{name:Oe.defaultProvider})})):U({type:"err",text:Oe.error??i("modelProviders.saveFailed")})}catch{U({type:"err",text:i("common:networkError")})}finally{z(!1)}}},Ks=async(ie,Oe)=>{D(ie);try{const Je=await fetch(`/api/settings/llm/providers/${ie}/toggle`,{method:"POST",headers:Bt(),body:JSON.stringify({enabled:Oe})});if(Je.ok){const Mn=await Je.json();R(Mn)}}catch{}finally{D(null)}},Es=async()=>{W(!0),H(null);try{const Oe=await(await fetch("/api/settings/import/openclaw",{method:"POST",headers:Bt(),body:JSON.stringify({preview:!0})})).json();"error"in Oe?H({type:"err",text:Oe.error}):$(Oe)}catch{H({type:"err",text:i("openClaw.detectFailed")})}finally{W(!1)}},dr=async()=>{W(!0),H(null);try{const Oe=await(await fetch("/api/settings/import/openclaw",{method:"POST",headers:Bt(),body:JSON.stringify({preview:!1})})).json();"error"in Oe?H({type:"err",text:Oe.error}):(H({type:"ok",text:i("openClaw.importedFrom",{count:Oe.appliedModels})}),nr())}catch{H({type:"err",text:i("openClaw.importFailed")})}finally{W(!1)}},va=async()=>{if(!Z)return;const ie=Z.detected.filter(Oe=>X[Oe.provider]);if(ie.length===0){se({type:"err",text:i("envConfig.selectAtLeastOne")});return}Re(!0),se(null);try{const Oe=await fetch("/api/settings/env-models",{method:"POST",headers:Bt(),body:JSON.stringify({providers:ie.map(Mn=>({provider:Mn.provider,model:Mn.model,baseUrl:Mn.baseUrl,enabled:!0}))})});if(!Oe.ok){se({type:"err",text:i("envConfig.applyFailed",{status:Oe.status})});return}const Je=await Oe.json();se({type:"ok",text:Je.message}),B(null),me({}),nr()}catch{se({type:"err",text:i("envConfig.failedToApply")})}finally{Re(!1)}},Hs=async()=>{if(!(!Ee?.found||!Ae)){at(!0),Ct(null);try{const ie=await fetch("/api/settings/llm/providers",{method:"POST",headers:Bt(),body:JSON.stringify({name:"ollama",model:Ae,baseUrl:Ee.baseUrl||"http://localhost:11434"})});if(ie.ok){const Oe=await ie.json();R(Oe),Ct({type:"ok",text:i("ollama.configured",{model:Ae})}),we(null)}else{const Oe=await ie.json();Ct({type:"err",text:Oe.error||i("ollama.applyFailed")})}}catch{Ct({type:"err",text:i("ollama.applyFailed")})}finally{at(!1)}}};b.useEffect(()=>()=>{Ge.current&&clearInterval(Ge.current)},[]),b.useEffect(()=>{if(k!=="browser"||Sn)return;const ie=setInterval(async()=>{try{(await le.settings.getBrowser()).extensionConnected&&(Cn(!0),clearInterval(ie))}catch{}},5e3);return()=>clearInterval(ie)},[k,Sn]);const[xs,li]=b.useState(!1),[yn,xr]=b.useState({name:"",apiKey:"",baseUrl:"",model:"",contextWindow:128e3,maxOutputTokens:16384,costInput:1,costOutput:5}),[ci,wa]=b.useState(!1),[Ms,Rr]=b.useState(null),[ji,vn]=b.useState(null),[Kn,Yr]=b.useState({apiKey:"",baseUrl:"",model:"",contextWindow:0,maxOutputTokens:0,costInput:0,costOutput:0}),[Ds,ka]=b.useState(!1),[ja,Ns]=b.useState(null),[Gs,Na]=b.useState(""),[di,Ka]=b.useState(!1),[Xr,Cr]=b.useState(null),[Br,Ss]=b.useState(null),[An,Hr]=b.useState({id:"",name:"",contextWindow:128e3,maxOutputTokens:16384,costInput:1,costOutput:5,reasoning:!1,vision:!1}),[Sa,Cs]=b.useState(!1),aa=async()=>{if(!(!yn.name||!yn.model)){wa(!0),Rr(null);try{const ie=await fetch("/api/settings/llm/providers",{method:"POST",headers:Bt(),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})}),Oe=await ie.json();ie.ok?(R(Oe),li(!1),xr({name:"",apiKey:"",baseUrl:"",model:"",contextWindow:128e3,maxOutputTokens:16384,costInput:1,costOutput:5}),Rr({type:"ok",text:i("modelProviders.providerAdded",{name:yn.name})})):Rr({type:"err",text:Oe.error??i("modelProviders.failedToAdd")})}catch{Rr({type:"err",text:i("common:networkError")})}finally{wa(!1)}}},Ca=async(ie,Oe)=>{if(!Gs.trim())return;Ka(!0),Cr(null);const Je=Oe.models?.[0]?.id??ie;try{const Mn=await fetch("/api/settings/llm/providers",{method:"POST",headers:Bt(),body:JSON.stringify({name:ie,apiKey:Gs.trim(),model:Je})}),ia=await Mn.json();Mn.ok?(R(ia),Na(""),Cr({type:"ok",text:i("modelProviders.quickSetupSuccess",{name:Oe.displayName??ie})})):Cr({type:"err",text:ia.error??i("modelProviders.failedToAdd")})}catch{Cr({type:"err",text:i("common:networkError")})}finally{Ka(!1)}},Ys=(ie,Oe)=>{vn(ie),Yr({apiKey:"",baseUrl:Oe.baseUrl??"",model:Oe.model,contextWindow:Oe.contextWindow??0,maxOutputTokens:Oe.maxOutputTokens??0,costInput:Oe.cost?.input??0,costOutput:Oe.cost?.output??0})},Ga=async ie=>{ka(!0);try{const Oe={};Kn.apiKey&&(Oe.apiKey=Kn.apiKey),Kn.baseUrl!==void 0&&(Oe.baseUrl=Kn.baseUrl),Kn.model&&(Oe.model=Kn.model),Kn.contextWindow&&(Oe.contextWindow=Kn.contextWindow),Kn.maxOutputTokens&&(Oe.maxOutputTokens=Kn.maxOutputTokens),(Kn.costInput||Kn.costOutput)&&(Oe.cost={input:Kn.costInput,output:Kn.costOutput});const Je=await fetch(`/api/settings/llm/providers/${ie}`,{method:"PUT",headers:Bt(),body:JSON.stringify(Oe)});if(Je.ok){const Mn=await Je.json();R(Mn),vn(null)}}catch{}finally{ka(!1)}},To=async ie=>{Ns(ie);try{const Oe=await fetch(`/api/settings/llm/providers/${ie}`,{method:"DELETE",headers:Bt()});if(Oe.ok){const Je=await Oe.json();R(Je),_(Je.defaultProvider)}}catch{}finally{Ns(null)}},ui=async ie=>{if(!(!An.id||!An.name)){Cs(!0);try{const Oe=await fetch(`/api/settings/llm/providers/${ie}/models`,{method:"POST",headers:Bt(),body:JSON.stringify({id:An.id,name:An.name,contextWindow:An.contextWindow,maxOutputTokens:An.maxOutputTokens,cost:{input:An.costInput,output:An.costOutput},reasoning:An.reasoning||void 0,inputTypes:An.vision?["text","image"]:["text"]})});if(Oe.ok){const Je=await Oe.json();R(Je),Ss(null),Hr({id:"",name:"",contextWindow:128e3,maxOutputTokens:16384,costInput:1,costOutput:5,reasoning:!1,vision:!1})}}catch{}finally{Cs(!1)}}},Wi=async(ie,Oe)=>{try{const Je=await fetch(`/api/settings/llm/providers/${ie}/models/${encodeURIComponent(Oe)}`,{method:"DELETE",headers:Bt()});if(Je.ok){const Mn=await Je.json();R(Mn)}}catch{}},Ta=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"]),[Ni,ae]=b.useState(null),[Ye,dt]=b.useState(null),[Et,sn]=b.useState({}),pr=async ie=>{dt(ie),sn(Oe=>{const Je={...Oe};return delete Je[ie],Je});try{const Oe=await fetch(`/api/settings/llm/providers/${ie}/test`,{method:"POST",headers:Bt()});if(!Oe.ok){const Mn=await Oe.json().catch(()=>({}));sn(ia=>({...ia,[ie]:{ok:!1,error:Mn.error??`HTTP ${Oe.status}`,errorCode:Oe.status}}));return}const Je=await Oe.json();sn(Mn=>({...Mn,[ie]:Je}))}catch{sn(Oe=>({...Oe,[ie]:{ok:!1,error:i("common:networkError")}}))}finally{dt(null)}},En=async(ie,Oe)=>{ae(`${ie}:${Oe}`);try{const Je=await fetch(`/api/settings/llm/providers/${ie}/model`,{method:"POST",headers:Bt(),body:JSON.stringify({model:Oe})});if(Je.ok){const Mn=await Je.json();R(Mn)}}catch{}finally{ae(null)}},Dt=async()=>{if(Ot.serperApiKey||Ot.tavilyApiKey||Ot.bingApiKey||Ot.googleSearchApiKey||Ot.googleSearchCx||Ot.serpApiKey||Ot.braveApiKey||Ot.exaApiKey||Ot.bochaApiKey){js(!0),xe(null);try{const Oe={};Ot.serperApiKey&&(Oe.serperApiKey=Ot.serperApiKey),Ot.tavilyApiKey&&(Oe.tavilyApiKey=Ot.tavilyApiKey),Ot.bingApiKey&&(Oe.bingApiKey=Ot.bingApiKey),Ot.googleSearchApiKey&&(Oe.googleSearchApiKey=Ot.googleSearchApiKey),Ot.googleSearchCx&&(Oe.googleSearchCx=Ot.googleSearchCx),Ot.serpApiKey&&(Oe.serpApiKey=Ot.serpApiKey),Ot.braveApiKey&&(Oe.braveApiKey=Ot.braveApiKey),Ot.exaApiKey&&(Oe.exaApiKey=Ot.exaApiKey),Ot.bochaApiKey&&(Oe.bochaApiKey=Ot.bochaApiKey);const Je=await le.settings.updateSearch(Oe);Jt(Je),Fn({serperApiKey:"",tavilyApiKey:"",bingApiKey:"",googleSearchApiKey:"",googleSearchCx:"",serpApiKey:"",braveApiKey:"",exaApiKey:"",bochaApiKey:""}),xe({type:"ok",text:i("searchApi.saved")})}catch{xe({type:"err",text:i("searchApi.failedToSave")})}finally{js(!1)}}},Rs=T?.providers?Object.entries(T.providers).filter(([,ie])=>ie.configured&&ie.enabled).map(([ie])=>ie):[],Ls=T&&!Wa&&!nt,Fs=r?.role==="owner"||r?.role==="admin",Fr=SS.filter(ie=>!ie.adminOnly||Fs);return n.jsxs("div",{className:"flex-1 flex overflow-hidden",children:[p&&r&&n.jsx(sG,{authUser:r,onClose:()=>h(!1),onSaved:ie=>{h(!1),a?.(ie)}}),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:()=>{Nt.navigate(Se.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:Fr.map(ie=>n.jsx("button",{onClick:()=>S(ie.id),className:`w-full text-left px-3 py-2 rounded-lg text-sm transition-colors ${k===ie.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:${ie.labelKey}`)},ie.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(gr,{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),h(!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&&k===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:()=>Nt.navigate(Se.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:Fr.map(ie=>n.jsxs("button",{onClick:()=>S(ie.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:${ie.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"})})]},ie.id))})]}),d&&k!==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:${Fr.find(ie=>ie.id===k)?.labelKey||"title"}`)})]}),k!==null&&n.jsxs("div",{className:"p-7 space-y-10 max-w-4xl mx-auto w-full",children:[k==="appearance"&&n.jsx(si,{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:QK.map(({value:ie})=>n.jsx("button",{onClick:()=>t?.(ie),className:`px-3 py-1.5 text-xs rounded-md transition-colors ${e===ie?"bg-brand-600 text-white":"text-fg-secondary hover:text-fg-primary"}`,children:i(`appearance.modes.${ie}`)},ie))})]}),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:tw.map(({code:ie,label:Oe})=>n.jsx("button",{onClick:()=>{l.changeLanguage(ie)},className:`px-3 py-1.5 text-xs rounded-md transition-colors ${l.language===ie||ie==="en"&&!tw.some(Je=>Je.code===l.language)?"bg-brand-600 text-white":"text-fg-secondary hover:text-fg-primary"}`,children:Oe},ie))})]})]})}),Fs&&n.jsxs(n.Fragment,{children:[k==="providers"&&n.jsxs(n.Fragment,{children:[Ls&&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:()=>ft(!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(yu,{step:i("setupGuide.fromEnv.step"),title:i("setupGuide.fromEnv.title"),description:i("setupGuide.fromEnv.description"),active:!!(Z&&Z.detected.length>0),children:[J&&n.jsx("div",{className:"text-xs text-fg-tertiary",children:i("common:detecting")}),Z&&Z.detected.length>0&&n.jsxs("div",{className:"space-y-2",children:[Z.detected.map(ie=>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:X[ie.provider]??!1,onChange:Oe=>me({...X,[ie.provider]:Oe.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:ie.displayName}),n.jsx("span",{className:"text-xs text-fg-tertiary ml-2",children:ie.model})]}),n.jsx("code",{className:"text-[10px] text-fg-tertiary",children:ie.apiKeyPreview})]},ie.provider)),n.jsx("button",{onClick:()=>{va()},disabled:je||Object.values(X).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:je?i("common:applying"):i("setupGuide.applyProviders",{count:Object.values(X).filter(Boolean).length})})]}),Z&&Z.detected.length===0&&n.jsx("div",{className:"text-xs text-fg-tertiary",children:n.jsx(Fu,{i18nKey:"settings:setupGuide.fromEnv.noKeysHint",components:{code:n.jsx("code",{className:"text-fg-secondary"})}})}),ee&&n.jsx(Oa,{type:ee.type,text:ee.text})]}),n.jsxs(yu,{step:i("setupGuide.fromOllama.step"),title:i("setupGuide.fromOllama.title"),description:i("setupGuide.fromOllama.description"),active:!!Ee?.found,children:[pe&&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:Ae,onChange:ie=>Xe(ie.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(ie=>n.jsxs("option",{value:ie.name,children:[ie.name,ie.parameterSize?` (${ie.parameterSize})`:"",ie.family?` — ${ie.family}`:""]},ie.name))}),n.jsx("button",{onClick:()=>{Hs()},disabled:Ze||!Ae,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:Ze?i("common:applying"):i("ollama.useModel",{model:Ae})})]}),!pe&&!Ee&&n.jsx("button",{onClick:()=>{Pr()},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")}),pt&&n.jsx(Oa,{type:pt.type,text:pt.text})]}),n.jsxs(yu,{step:i("setupGuide.fromOpenClaw.step"),title:i("setupGuide.fromOpenClaw.title"),description:i("setupGuide.fromOpenClaw.description"),children:[E?E.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:E.summary.configPath})]}),E.summary.models&&n.jsx("div",{className:"text-xs text-fg-secondary",children:i("openClaw.providersModels",{providers:E.summary.models.providerCount,models:E.summary.models.providers.reduce((ie,Oe)=>ie+Oe.modelCount,0)})}),n.jsx("button",{onClick:()=>{dr()},disabled:Y,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(Y?"common:importing":"openClaw.importConfigs")})]}):n.jsx("div",{className:"text-xs text-fg-tertiary",children:i("openClaw.notFound")}):n.jsx("button",{onClick:()=>{Es()},disabled:Y,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(Y?"common:detecting":"openClaw.detectShort")}),O&&n.jsx(Oa,{type:O.type,text:O.text})]}),n.jsx(yu,{step:i("setupGuide.manual.step"),title:i("setupGuide.manual.title"),description:n.jsx(Fu,{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(yu,{step:i("setupGuide.browserExtension.step"),title:i("setupGuide.browserExtension.title"),description:i("setupGuide.browserExtension.description"),active:Sn,children:Sn?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:hn,onClick:async()=>{Ne(!0);try{await le.settings.downloadExtensionZip()}catch{}Ne(!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")]}),n.jsxs("button",{disabled:hn,onClick:async()=>{try{await le.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(si,{title:i("systemStatus.title"),children:N?n.jsxs("div",{className:"grid grid-cols-3 gap-4",children:[n.jsx(Ax,{label:i("systemStatus.status"),value:N.status==="ok"?i("systemStatus.healthy"):N.status,color:"green"}),n.jsx(Ax,{label:i("systemStatus.version"),value:N.version,color:"indigo"}),n.jsx(Ax,{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(si,{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:M,onChange:ie=>{_(ie.target.value),U(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:Rs.length>0?Rs.map(ie=>n.jsx("option",{value:ie,children:T.providers[ie]?.displayName??ie},ie)):n.jsx("option",{value:"",children:i("defaultProvider.noProviders")})}):n.jsx("div",{className:"text-xs text-fg-tertiary",children:i("common:loading")}),M!==T?.defaultProvider&&n.jsx("button",{onClick:()=>{Vi()},disabled:F,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(F?"common:saving":"common:save")})]})]}),L&&n.jsx(Oa,{type:L.type,text:L.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 ie=!(T?.autoFallback??!0);try{const Oe=await fetch("/api/settings/llm",{method:"POST",headers:Bt(),body:JSON.stringify({autoFallback:ie})});if(Oe.ok){const Je=await Oe.json();R(Je)}}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(si,{title:i("modelProviders.title"),children:[n.jsx("div",{className:"space-y-3",children:T&&Object.entries(T.providers).map(([ie,Oe])=>n.jsxs("div",{className:`bg-surface-secondary border rounded-xl overflow-hidden transition-colors ${Oe.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:()=>{q(K===ie?null:ie),Na(""),Cr(null)},children:[n.jsxs("div",{className:"flex items-center gap-3",children:[n.jsx("span",{className:`w-2 h-2 rounded-full ${Oe.configured&&Oe.enabled?"bg-green-400":Oe.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:Oe.displayName??ie}),ie===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")}),Oe.configured&&!Oe.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")}),Oe.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")}),Et[ie]?.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:Et[ie].durationMs})}),Et[ie]?.ok===!1&&n.jsx("span",{className:"text-[10px] bg-red-500/15 text-red-500 px-1.5 py-0.5 rounded",title:Et[ie].error,children:Et[ie].errorCode?i("modelProviders.testFailedCode",{code:Et[ie].errorCode}):i("modelProviders.testFailed")})]}),n.jsx("div",{className:"text-xs text-fg-tertiary mt-0.5",children:Oe.configured?n.jsxs(n.Fragment,{children:[Oe.model,Oe.apiKeyPreview&&n.jsxs(n.Fragment,{children:[" · ",n.jsx("code",{className:"text-fg-secondary",children:Oe.apiKeyPreview})]})]}):i("modelProviders.notConfigured")})]})]}),n.jsxs("div",{className:"flex items-center gap-4",children:[Oe.configured&&n.jsx("button",{onClick:Je=>{Je.stopPropagation(),Ks(ie,!Oe.enabled)},disabled:I===ie,className:`relative inline-flex h-5 w-9 items-center rounded-full transition-colors ${Oe.enabled?"bg-green-500":"bg-gray-600"} ${I===ie?"opacity-50":""}`,title:Oe.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 ${Oe.enabled?"translate-x-4":"translate-x-1"}`})}),Oe.contextWindow&&n.jsx("span",{className:"text-[10px] text-fg-tertiary",children:i("modelProviders.ctxTokens",{size:(Oe.contextWindow/1e3).toFixed(0)})}),Oe.cost&&n.jsx("span",{className:"text-[10px] text-fg-tertiary",children:i("modelProviders.costPerMillion",{input:Oe.cost.input,output:Oe.cost.output})}),n.jsx("span",{className:"text-fg-tertiary text-xs",children:K===ie?"▲":"▼"})]})]}),K===ie&&n.jsxs("div",{className:"px-5 pb-4 border-t border-border-default pt-4 space-y-4",children:[Oe.configured&&n.jsxs(n.Fragment,{children:[n.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-3",children:[n.jsx(el,{label:i("modelProviders.model"),value:Oe.model}),n.jsx(el,{label:i("modelProviders.contextWindow"),value:Oe.contextWindow?i("modelProviders.kTokens",{k:(Oe.contextWindow/1e3).toFixed(0)}):i("modelProviders.notApplicable")}),n.jsx(el,{label:i("modelProviders.maxOutput"),value:Oe.maxOutputTokens?i("modelProviders.kTokens",{k:(Oe.maxOutputTokens/1e3).toFixed(0)}):i("modelProviders.notApplicable")}),n.jsx(el,{label:i("modelProviders.baseUrlLabel"),value:Oe.baseUrl??i("modelProviders.baseUrlDisplayDefault")})]}),ji===ie?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:Kn.apiKey,onChange:Je=>Yr({...Kn,apiKey:Je.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:Kn.baseUrl,onChange:Je=>Yr({...Kn,baseUrl:Je.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:Kn.model,onChange:Je=>Yr({...Kn,model:Je.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:Kn.contextWindow||"",onChange:Je=>Yr({...Kn,contextWindow:Number(Je.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:Kn.maxOutputTokens||"",onChange:Je=>Yr({...Kn,maxOutputTokens:Number(Je.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:Kn.costInput||"",onChange:Je=>Yr({...Kn,costInput:Number(Je.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:Kn.costOutput||"",onChange:Je=>Yr({...Kn,costOutput:Number(Je.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:()=>{Ga(ie)},disabled:Ds,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(Ds?"common:saving":"common:save")}),n.jsx("button",{onClick:()=>vn(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:Je=>{Je.stopPropagation(),pr(ie)},disabled:Ye===ie,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:Ye===ie?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:Je=>{Je.stopPropagation(),Ys(ie,Oe)},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:Je=>{Je.stopPropagation(),confirm(i("modelProviders.deleteConfirm",{name:Oe.displayName??ie}))&&To(ie)},disabled:ja===ie,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(ja===ie?"common:deleting":"common:delete")})]}),Et[ie]&&n.jsx("div",{className:`text-xs px-3 py-2 rounded-lg ${Et[ie].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:Et[ie].ok?i("modelProviders.testSuccess",{ms:Et[ie].durationMs,reply:Et[ie].reply}):Et[ie].error})]}),Oe.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(el,{label:i("modelProviders.input"),value:`$${Oe.cost.input}`}),n.jsx(el,{label:i("modelProviders.output"),value:`$${Oe.cost.output}`}),Oe.cost.cacheRead!=null&&n.jsx(el,{label:i("modelProviders.cacheRead"),value:`$${Oe.cost.cacheRead}`}),Oe.cost.cacheWrite!=null&&n.jsx(el,{label:i("modelProviders.cacheWrite"),value:`$${Oe.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")}),Oe.configured&&Br!==ie&&n.jsx("button",{onClick:()=>{Ss(ie),Hr({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")})]}),Br===ie&&n.jsxs("div",{className:"bg-surface-elevated/40 rounded-lg p-3 mb-2 space-y-2",children:[n.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-2",children:[n.jsx("input",{type:"text",placeholder:i("modelProviders.modelId"),value:An.id,onChange:Je=>Hr({...An,id:Je.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:i("modelProviders.displayName"),value:An.name,onChange:Je=>Hr({...An,name:Je.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:i("modelProviders.placeholderContextTokens"),value:An.contextWindow,onChange:Je=>Hr({...An,contextWindow:Number(Je.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:i("modelProviders.maxOutput"),value:An.maxOutputTokens,onChange:Je=>Hr({...An,maxOutputTokens:Number(Je.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:i("modelProviders.costPerMillionIn")}),n.jsx("input",{type:"number",step:"0.01",value:An.costInput,onChange:Je=>Hr({...An,costInput:Number(Je.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:i("modelProviders.costPerMillionOut")}),n.jsx("input",{type:"number",step:"0.01",value:An.costOutput,onChange:Je=>Hr({...An,costOutput:Number(Je.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:An.reasoning,onChange:Je=>Hr({...An,reasoning:Je.target.checked}),className:"rounded"}),i("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:An.vision,onChange:Je=>Hr({...An,vision:Je.target.checked}),className:"rounded"}),i("modelProviders.vision")]}),n.jsx("div",{className:"flex-1"}),n.jsx("button",{onClick:()=>{ui(ie)},disabled:Sa||!An.id||!An.name,className:"px-2 py-1 text-[10px] bg-brand-600 hover:bg-brand-500 disabled:opacity-40 text-white rounded transition-colors",children:i(Sa?"modelProviders.adding":"common:create")}),n.jsx("button",{onClick:()=>Ss(null),className:"px-2 py-1 text-[10px] border border-border-default text-fg-secondary hover:bg-surface-elevated rounded transition-colors",children:i("common:cancel")})]})]}),Oe.models&&Oe.models.length>0&&n.jsx("div",{className:"space-y-1.5",children:Oe.models.map(Je=>{const Mn=Je.id===Oe.model,ia=Ni===`${ie}:${Je.id}`,Aa=!Ta.has(Je.id);return n.jsxs("div",{className:`flex items-center justify-between px-3 py-2 rounded-lg text-xs transition-colors ${Mn?"bg-brand-500/15 border border-brand-500/30":Oe.configured?"bg-surface-elevated/30 hover:bg-surface-elevated/60 cursor-pointer":"bg-surface-elevated/30"}`,onClick:()=>{!Mn&&Oe.configured&&!ia&&En(ie,Je.id)},children:[n.jsxs("div",{className:"flex items-center gap-2",children:[Mn&&n.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-brand-500 shrink-0"}),n.jsx("span",{className:Mn?"text-brand-500 font-medium":"text-fg-secondary",children:Je.name}),Je.reasoning&&n.jsx("span",{className:"text-[9px] bg-amber-500/15 text-amber-600 px-1 py-0.5 rounded",children:i("modelProviders.reasoning")}),Je.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")}),Aa&&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:[n.jsx("span",{children:i("modelProviders.ctxTokens",{size:(Je.contextWindow/1e3).toFixed(0)})}),n.jsx("span",{children:i("modelProviders.costPair",{input:Je.cost.input,output:Je.cost.output})}),Oe.configured&&!Mn&&n.jsx("span",{className:`text-[9px] px-1.5 py-0.5 rounded transition-colors ${ia?"bg-brand-500/30 text-brand-400":"bg-surface-overlay text-fg-tertiary hover:bg-brand-500/20 hover:text-brand-500"}`,children:i(ia?"modelProviders.switching":"modelProviders.use")}),Mn&&n.jsx("span",{className:"text-[9px] bg-brand-500/15 text-brand-500 px-1.5 py-0.5 rounded",children:i("modelProviders.active")}),Aa&&!Mn&&n.jsx("button",{onClick:rs=>{rs.stopPropagation(),Wi(ie,Je.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"})})})]})]},Je.id)})})]}),!Oe.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",{className:"flex items-center gap-2",children:[n.jsx("input",{type:"password",value:K===ie?Gs:"",onChange:Je=>Na(Je.target.value),placeholder:i("modelProviders.quickSetupPlaceholder"),className:"flex-1 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",onKeyDown:Je=>{Je.key==="Enter"&&Gs.trim()&&Ca(ie,Oe)}}),n.jsx("button",{onClick:()=>{Ca(ie,Oe)},disabled:di||!Gs.trim(),className:"px-4 py-2 text-sm bg-brand-600 hover:bg-brand-500 disabled:opacity-40 text-white rounded-lg transition-colors whitespace-nowrap",children:i(di?"modelProviders.quickSetupSaving":"modelProviders.quickSetupSubmit")})]}),Xr&&K===ie&&n.jsx(Oa,{type:Xr.type,text:Xr.text})]})]})]},ie))}),xs?n.jsxs("div",{className:"mt-3 bg-surface-secondary border border-brand-500/30 rounded-xl p-5 space-y-4",children:[n.jsx("div",{className:"text-sm font-medium text-fg-primary",children:i("modelProviders.addNewProvider")}),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,onChange:ie=>xr({...yn,name:ie.target.value}),placeholder:i("modelProviders.placeholderProviderName"),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.jsx("div",{className:"text-[10px] text-fg-tertiary mt-1",children:i("modelProviders.providerNameHint")})]}),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:ie=>xr({...yn,apiKey:ie.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.baseUrl")}),n.jsx("input",{type:"text",value:yn.baseUrl,onChange:ie=>xr({...yn,baseUrl:ie.target.value}),placeholder:i("modelProviders.placeholderBaseUrl"),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:ie=>xr({...yn,model:ie.target.value}),placeholder:i("modelProviders.placeholderDefaultModel"),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-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:yn.contextWindow,onChange:ie=>xr({...yn,contextWindow:Number(ie.target.value)}),placeholder:"128000",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.maxOutputTokens")}),n.jsx("input",{type:"number",value:yn.maxOutputTokens,onChange:ie=>xr({...yn,maxOutputTokens:Number(ie.target.value)}),placeholder:"16384",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.inputCost")}),n.jsx("input",{type:"number",step:"0.01",value:yn.costInput,onChange:ie=>xr({...yn,costInput:Number(ie.target.value)}),placeholder:"1",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.outputCost")}),n.jsx("input",{type:"number",step:"0.01",value:yn.costOutput,onChange:ie=>xr({...yn,costOutput:Number(ie.target.value)}),placeholder:"5",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:()=>{aa()},disabled:ci||!yn.name||!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(ci?"modelProviders.adding":"modelProviders.addProviderSubmit")}),n.jsx("button",{onClick:()=>{li(!1),Rr(null)},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")})]}),Ms&&n.jsx(Oa,{type:Ms.type,text:Ms.text})]}):n.jsx("button",{onClick:()=>li(!0),className:"w-full mt-3 px-4 py-3 border border-dashed border-border-default hover:border-brand-500/50 hover:bg-brand-500/5 rounded-xl text-sm text-fg-tertiary hover:text-brand-500 transition-colors",children:i("modelProviders.addProvider")})]}),n.jsx("div",{className:"border-t border-border-default"}),n.jsx(si,{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:()=>{sa()},disabled:J,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 ${J?"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(J?"common:detecting":"envConfig.refreshEnv")]})]}),Z&&Z.detected.length>0&&n.jsxs("div",{className:"space-y-2",children:[Z.detected.map(ie=>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:X[ie.provider]??!1,onChange:Oe=>me({...X,[ie.provider]:Oe.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:ie.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:ie.apiKeyPreview})," / ",i("envConfig.modelLabel")," ",n.jsx("code",{className:"text-fg-secondary",children:ie.model}),ie.baseUrl&&n.jsxs(n.Fragment,{children:[" / ",i("envConfig.urlLabel")," ",n.jsx("code",{className:"text-fg-secondary",children:ie.baseUrl})]})]})]})]}),n.jsx("div",{className:"text-xs text-fg-tertiary",children:Object.keys(ie.envVars).map(Oe=>n.jsx("div",{children:n.jsx("code",{children:Oe})},Oe))})]},ie.provider)),Z.timeoutMs&&n.jsx("div",{className:"text-xs text-fg-tertiary",children:i("envConfig.llmTimeout",{ms:Z.timeoutMs})}),n.jsx("button",{onClick:()=>{va()},disabled:je||Object.values(X).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:je?i("common:applying"):i("envConfig.applyToConfig",{count:Object.values(X).filter(Boolean).length})})]}),ee&&n.jsx(Oa,{type:ee.type,text:ee.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:()=>{Pr()},disabled:pe,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 ${pe?"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(pe?"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(ie=>n.jsx("label",{className:`flex items-center justify-between rounded-lg px-4 py-3 cursor-pointer transition-colors ${Ae===ie.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:ie.name,checked:Ae===ie.name,onChange:()=>Xe(ie.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:ie.name}),n.jsxs("div",{className:"text-xs text-fg-tertiary mt-0.5",children:[ie.parameterSize&&n.jsx("span",{children:ie.parameterSize}),ie.family&&n.jsx("span",{className:"ml-2",children:ie.family}),ie.quantization&&n.jsx("span",{className:"ml-2",children:ie.quantization}),ie.size&&n.jsx("span",{className:"ml-2",children:Bc(ie.size)})]})]})]})},ie.name))}),n.jsx("button",{onClick:()=>{Hs()},disabled:Ze||!Ae,className:"px-4 py-2 bg-brand-600 hover:bg-brand-500 disabled:opacity-40 text-white text-sm rounded-lg transition-colors",children:Ze?i("common:applying"):i("ollama.useModel",{model:Ae})})]}),Ee&&!Ee.found&&n.jsx("div",{className:"text-xs text-fg-tertiary",children:Ee.error||i("ollama.notRunning")}),pt&&n.jsx(Oa,{type:pt.type,text:pt.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:()=>{Es()},disabled:Y,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(Y?"common:detecting":"openClaw.detectShort")})]}),E&&E.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:E.summary.configPath})]}),E.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:E.summary.models.providerCount})}),n.jsx("div",{className:"space-y-1",children:E.summary.models.providers.map(ie=>n.jsxs("div",{className:"flex items-center justify-between text-xs",children:[n.jsx("span",{className:"text-fg-secondary",children:ie.name}),n.jsxs("span",{className:"text-fg-tertiary",children:[i("openClaw.modelsCountSuffix",{count:ie.modelCount}),ie.baseUrl?i("openClaw.withBaseUrl",{url:ie.baseUrl}):""]})]},ie.name))})]}),E.summary.channels&&E.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")," ",E.summary.channels.join(", ")]})}),n.jsx("button",{onClick:()=>{dr()},disabled:Y,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(Y?"common:importing":"openClaw.importConfigs")})]}),O&&n.jsx(Oa,{type:O.type,text:O.text})]})]})})]}),k==="execution"&&n.jsxs(n.Fragment,{children:[n.jsx(si,{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:Rt,onChange:ie=>{lt(Number(ie.target.value)),zt(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:$e,onClick:async()=>{ct(!0),zt(null);try{const ie=await le.settings.updateAgent({maxToolIterations:Rt});lt(ie.maxToolIterations),zt({type:"ok",text:i("agentExecution.saved")})}catch{zt({type:"err",text:i("agentExecution.failedToSave")})}ct(!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($e?"common:saving":"common:save")})]})]}),Ut&&n.jsx(Oa,{type:Ut.type,text:Ut.text})]})}),n.jsx(si,{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(!cn),wr(null)},className:`relative w-10 h-5 rounded-full transition-colors ${cn?"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 ${cn?"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:Xt,onChange:ie=>{kn(Number(ie.target.value)),wr(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:tr,onClick:async()=>{ir(!0),wr(null);try{const ie=await le.settings.updateAgent({cognitive:{enabled:cn,maxDepth:Xt}});Ln(ie.cognitive.enabled),kn(ie.cognitive.maxDepth??1),wr({type:"ok",text:i("cognitive.saved")})}catch{wr({type:"err",text:i("cognitive.failedToSave")})}ir(!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(tr?"common:saving":"common:save")})}),gs&&n.jsx(Oa,{type:gs.type,text:gs.text})]})})]}),k==="browser"&&n.jsxs(n.Fragment,{children:[n.jsxs(si,{title:i("browserAutomation.title"),children:[n.jsxs("div",{className:`rounded-xl p-4 mb-4 flex items-start gap-3 ${Sn?"bg-green-500/10 border border-green-500/20":Lt>0?"bg-blue-500/10 border border-blue-500/20":_n?"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 ${Sn?"bg-green-400":Lt>0?"bg-blue-400":_n?"bg-amber-400":"bg-gray-400"}`}),n.jsxs("div",{className:"flex-1 min-w-0",children:[n.jsx("div",{className:`text-sm font-semibold ${Sn?"text-green-400":Lt>0?"text-blue-400":_n?"text-amber-400":"text-fg-secondary"}`,children:Sn?i("browserAutomation.modeExtension"):Lt>0?i("browserAutomation.modeDebuggingPort",{port:Lt}):i(_n?"browserAutomation.modeAutoClick":"browserAutomation.modeManual")}),n.jsx("div",{className:"text-xs text-fg-tertiary mt-0.5",children:Sn?i("browserAutomation.modeExtensionDesc"):Lt>0?i("browserAutomation.modeDebuggingPortDesc"):i(_n?"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 ie=!or;Ue(ie),Ne(!0),Vt(null);try{const Oe=await le.settings.updateBrowser({bringToFront:ie});Ue(Oe.bringToFront),Vt({type:"ok",text:i(ie?"browserAutomation.tabsForeground":"browserAutomation.tabsBackground")})}catch{Vt({type:"err",text:i("agentExecution.failedToSave")}),Ue(!ie)}Ne(!1)},disabled:hn,className:`relative inline-flex h-5 w-9 items-center rounded-full transition-colors ${or?"bg-green-500":"bg-gray-600"} ${hn?"opacity-50":""}`,children:n.jsx("span",{className:`inline-block h-3.5 w-3.5 rounded-full bg-white transition-transform ${or?"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 ie=!Ft;lr(ie),Ne(!0),Vt(null);try{const Oe=await le.settings.updateBrowser({autoCloseTabs:ie});lr(Oe.autoCloseTabs),Vt({type:"ok",text:i("agentExecution.saved")})}catch{Vt({type:"err",text:i("agentExecution.failedToSave")}),lr(!ie)}Ne(!1)},disabled:hn,className:`relative inline-flex h-5 w-9 items-center rounded-full transition-colors ${Ft?"bg-green-500":"bg-gray-600"} ${hn?"opacity-50":""}`,children:n.jsx("span",{className:`inline-block h-3.5 w-3.5 rounded-full bg-white transition-transform ${Ft?"translate-x-4":"translate-x-1"}`})})]})]}),n.jsxs("div",{className:`rounded-xl p-5 mb-4 transition-colors ${Sn?"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 ${Sn?"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 ${Sn?"bg-green-400":"bg-gray-400"}`}),i(Sn?"browserAutomation.extensionConnected":"browserAutomation.extensionDisconnected")]})]}),n.jsx("div",{className:"text-xs text-fg-tertiary",children:i("browserAutomation.extensionStatusDesc")}),Sn?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:hn,onClick:async()=>{Ne(!0),Vt(null);try{await le.settings.downloadExtensionZip()}catch{Vt({type:"err",text:i("browserAutomation.extensionDownloadError")})}Ne(!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(hn?"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")}),n.jsxs("button",{disabled:hn,onClick:async()=>{Ne(!0),Vt(null);try{await le.settings.openExtensionsPage()}catch{Vt({type:"err",text:i("browserAutomation.extensionOpenError")})}Ne(!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")})]})]})]})]}),!Sn&&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:hn,onClick:async()=>{Ne(!0),Vt(null);try{const ie=await le.settings.testAutoClick(),Oe={success:{type:"ok",text:i("browserAutomation.autoClickTestSuccess",{title:ie.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:ie.error||"unknown"})}};Vt(Oe[ie.clickResult]??{type:"err",text:ie.clickResult})}catch{Vt({type:"err",text:i("browserAutomation.autoClickTestError",{error:"request failed"})})}Ne(!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(hn?"browserAutomation.autoClickTesting":"browserAutomation.autoClickTest")}),n.jsx("button",{onClick:async()=>{const ie=!_n;dn(ie),Ne(!0),Vt(null);try{const Oe=await le.settings.updateBrowser({autoClickAllowDialog:ie});dn(Oe.autoClickAllowDialog),Vt({type:"ok",text:i("agentExecution.saved")})}catch{Vt({type:"err",text:i("agentExecution.failedToSave")}),dn(!ie)}Ne(!1)},disabled:hn,className:`relative inline-flex h-5 w-9 items-center rounded-full transition-colors ${_n?"bg-green-500":"bg-gray-600"} ${hn?"opacity-50":""}`,children:n.jsx("span",{className:`inline-block h-3.5 w-3.5 rounded-full bg-white transition-transform ${_n?"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:Lt,onChange:ie=>{Zt(Number(ie.target.value)),Vt(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:hn,onClick:async()=>{Ne(!0),Vt(null);try{const ie=await le.settings.updateBrowser({remoteDebuggingPort:Lt});Zt(ie.remoteDebuggingPort),Vt({type:"ok",text:ie.remoteDebuggingPort>0?i("browserAutomation.usingPort",{port:ie.remoteDebuggingPort}):i("browserAutomation.usingAutoConnect")})}catch{Vt({type:"err",text:i("agentExecution.failedToSave")})}Ne(!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(hn?"common:saving":"common:save")})]})]})})]}),At&&n.jsx("div",{className:"mt-4",children:n.jsx(Oa,{type:At.type,text:At.text})})]}),!1]}),k==="search"&&n.jsx(n.Fragment,{children:n.jsx(si,{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((ie,Oe)=>n.jsxs("div",{className:Oe>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:ie.label}),n.jsx("div",{className:"text-xs text-fg-tertiary mt-0.5",children:ie.hint})]}),n.jsxs("div",{className:"flex items-center gap-2",children:[rn?.[ie.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:rn[ie.id].preview})]}),rn&&!rn[ie.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:Ot[ie.field],onChange:Je=>Fn({...Ot,[ie.field]:Je.target.value}),placeholder:rn?.[ie.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"}),ie.extraField&&n.jsx("input",{type:"text",value:Ot[ie.extraField],onChange:Je=>Fn({...Ot,[ie.extraField]:Je.target.value}),placeholder:ie.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"})]},ie.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:[kr&&n.jsx(Oa,{type:kr.type,text:kr.text}),!kr&&n.jsx("div",{}),n.jsx("button",{disabled:$n||!Ot.serperApiKey&&!Ot.tavilyApiKey&&!Ot.bingApiKey&&!Ot.googleSearchApiKey&&!Ot.googleSearchCx&&!Ot.serpApiKey&&!Ot.braveApiKey&&!Ot.exaApiKey&&!Ot.bochaApiKey,onClick:()=>{Dt()},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($n?"common:saving":"common:save")})]})]})})}),k==="storage"&&n.jsx(n.Fragment,{children:n.jsx(si,{title:i("dataStorage.title"),children:n.jsxs("div",{className:"bg-surface-elevated rounded-xl p-5 space-y-5",children:[Kt&&!Qe&&n.jsx("div",{className:"text-sm text-fg-tertiary",children:i("dataStorage.scanning")}),Qe&&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:Bc(Qe.totalSize,i)}),n.jsx("div",{className:"text-xs text-fg-tertiary font-mono mt-0.5",children:Qe.dataDir})]}),n.jsxs("div",{className:"flex gap-2",children:[n.jsx("button",{onClick:()=>Bs(),disabled:Kt,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(Kt?"dataStorage.scanning":"common:refresh")}),n.jsx("button",{onClick:()=>{le.system.openPath(Qe.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:Qe.breakdown.filter(ie=>ie.size>0).map(ie=>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:ie.name}),n.jsx("span",{className:"text-xs text-fg-tertiary ml-2",children:ie.description})]}),n.jsx("span",{className:"text-sm font-medium text-fg-secondary tabular-nums shrink-0 ml-3",children:Bc(ie.size,i)})]},ie.name))})]}),Qe.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:Qe.agents.length})}),n.jsx("div",{className:"space-y-1",children:Qe.agents.map(ie=>{const Oe=en.has(ie.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:()=>un(Je=>{const Mn=new Set(Je);return Mn.has(ie.id)?Mn.delete(ie.id):Mn.add(ie.id),Mn}),children:[n.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[n.jsx("span",{className:"text-[10px] text-fg-tertiary",children:Oe?"▼":"▶"}),n.jsx("button",{onClick:Je=>{Je.stopPropagation(),Nt.navigate(Se.TEAM,{agentId:ie.id})},className:"text-sm text-brand-500 hover:text-brand-400 truncate",children:ie.name}),n.jsx("span",{className:"text-[10px] text-fg-tertiary font-mono truncate",children:ie.id})]}),n.jsx("span",{className:"text-xs font-medium text-fg-secondary tabular-nums shrink-0 ml-3",children:Bc(ie.size,i)})]}),Oe&&n.jsxs("div",{className:"px-3 pb-2 pt-0.5 space-y-0.5",children:[ie.subItems.filter(Je=>Je.size>0).map(Je=>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:Je.name}),n.jsx("span",{className:"text-fg-secondary tabular-nums",children:Bc(Je.size,i)})]},Je.name)),n.jsx("div",{className:"pl-5 pt-1",children:n.jsx("button",{onClick:()=>{le.system.openPath(Qe.dataDir+"/agents/"+ie.id)},className:"text-[10px] text-fg-tertiary hover:text-fg-secondary underline",children:i("dataStorage.openFolder")})})]})]},ie.id)})})]}),jn&&(jn.orphanAgents.length>0||jn.orphanTeams.length>0)&&n.jsx(rG,{orphanInfo:jn,dataDir:Qe.dataDir,onPurged:Bs,formatBytes:ie=>Bc(ie,i)})]})]})})}),k==="users"&&n.jsx(nG,{authUser:r}),k==="remote"&&n.jsx(aG,{})]}),n.jsx("div",{className:"h-8"})]})]})]})}const eG=["owner","admin","member","guest"],tG={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 nG({authUser:e}){const{t}=kt(["settings","common"]),[r,s]=b.useState([]),[a,i]=b.useState(null),[l,d]=b.useState(""),[u,m]=b.useState(""),[p,h]=b.useState(""),[y,g]=b.useState(null),[v,S]=b.useState(""),[C,k]=b.useState(null),[N,j]=b.useState(null),[T,R]=b.useState(null),M=b.useCallback(()=>{le.users.list(e?.orgId).then(U=>s(U.users)).catch(()=>{})},[e?.orgId]);b.useEffect(()=>{M()},[M]);const _=U=>{i(U.id),d(U.name),m(U.role),h(U.email??""),R(null)},F=async()=>{if(a)try{await le.users.update(a,{name:l,role:u,email:p||void 0}),i(null),R({type:"ok",text:t("settings:userManagement.updateSuccess")}),M()}catch(U){R({type:"err",text:`${t("settings:userManagement.error")}: ${String(U)}`})}},z=async()=>{if(!(!y||!v))try{await le.users.resetPassword(y,v),g(null),S(""),R({type:"ok",text:t("settings:userManagement.resetSuccess")})}catch(U){R({type:"err",text:`${t("settings:userManagement.error")}: ${String(U)}`})}},L=async U=>{if(U===e?.id){R({type:"err",text:t("settings:userManagement.cannotDeleteSelf")}),k(null);return}if(r.find(q=>q.id===U)?.role==="owner"){R({type:"err",text:t("settings:userManagement.cannotDeleteOwner")}),k(null);return}try{await le.users.remove(U),k(null),R({type:"ok",text:t("settings:userManagement.deleteSuccess")}),M()}catch(q){R({type:"err",text:`${t("settings:userManagement.error")}: ${String(q)}`})}};return n.jsx(si,{title:t("settings:userManagement.title"),children: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),R({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:()=>j(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(U=>{const K=a===U.id,q=y===U.id,I=C===U.id,D=U.id===e?.id,E=U.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:K?n.jsx("input",{value:l,onChange:$=>d($.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:U.name}),D&&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:K?n.jsx("input",{value:p,onChange:$=>h($.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:U.email||"—"})}),n.jsx("td",{className:"px-4 py-2.5",children:K?n.jsx("select",{value:u,onChange:$=>m($.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:eG.map($=>n.jsx("option",{value:$,children:t(`settings:userManagement.roles.${$}`)},$))}):n.jsx("span",{className:`inline-block text-[10px] px-2 py-0.5 rounded-full border font-medium ${tG[U.role]??""}`,children:t(`settings:userManagement.roles.${U.role}`)})}),n.jsx("td",{className:"px-4 py-2.5 text-right",children:K?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:F,className:"text-[11px] text-brand-500 hover:text-brand-400 font-medium",children:t("settings:userManagement.save")})]}):q?n.jsxs("div",{className:"flex items-center justify-end gap-2",children:[n.jsx("input",{type:"password",value:v,onChange:$=>S($.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:()=>{g(null),S("")},className:"text-[11px] text-fg-tertiary hover:text-fg-secondary",children:t("settings:userManagement.cancel")}),n.jsx("button",{onClick:z,disabled:v.length<6,className:"text-[11px] text-brand-500 hover:text-brand-400 font-medium disabled:opacity-40",children:t("settings:userManagement.confirmReset")})]}):I?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:()=>k(null),className:"text-[11px] text-fg-tertiary hover:text-fg-secondary",children:t("settings:userManagement.cancel")}),n.jsx("button",{onClick:()=>L(U.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:()=>_(U),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")}),U.email&&n.jsx("button",{onClick:()=>{g(U.id),S(""),R(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")}),U.email&&!E&&!U.hasJoined&&n.jsx("button",{onClick:async()=>{try{const{inviteToken:$}=await le.users.reinvite(U.id),Y=`${window.location.origin}/#invite?token=${$}`;j(Y),R({type:"ok",text:t("settings:userManagement.inviteLinkGenerated")})}catch($){R({type:"err",text:String($)})}},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")}),!E&&!D&&n.jsx("button",{onClick:()=>{k(U.id),R(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")})]})})]},U.id)})]})]})]})})}function yu({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 Oa({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 si({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 Ax({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 el({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 Bc(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 rG({orphanInfo:e,dataDir:t,onPurged:r,formatBytes:s}){const{t:a}=kt(["settings","common"]),i=[...e.orphanAgents.map(k=>({...k,kind:"agent"})),...e.orphanTeams.map(k=>({...k,kind:"team"}))],[l,d]=b.useState(new Set),[u,m]=b.useState(!1),[p,h]=b.useState(null),y=k=>d(N=>{const j=new Set(N);return j.has(k)?j.delete(k):j.add(k),j}),g=l.size===i.length&&i.length>0,v=()=>d(g?new Set:new Set(i.map(k=>k.id))),S=i.filter(k=>l.has(k.id)).reduce((k,N)=>k+N.size,0),C=async k=>{m(!0),h(null);try{const N=await le.system.purgeOrphans(k),j=N.purgedAgents.length+N.purgedTeams.length,T=a("dataStorage.cleaned",{count:j,size:s(N.freedBytes)});h(N.failures.length?a("dataStorage.cleanedWithFailureNote",{base:T,count:N.failures.length}):T),d(new Set),r()}catch{h(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:g,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(S)})})]}),n.jsx("div",{className:"space-y-0.5 mb-3 max-h-52 overflow-y-auto",children:i.map(k=>n.jsxs("div",{className:`flex items-center gap-2 text-xs py-1.5 px-2 rounded transition-colors ${l.has(k.id)?"bg-amber-500/10":"bg-surface-elevated/30 hover:bg-surface-elevated/50"}`,children:[n.jsx("input",{type:"checkbox",checked:l.has(k.id),onChange:()=>y(k.id),className:"rounded shrink-0"}),k.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:k.id}),n.jsx("span",{className:"text-fg-secondary tabular-nums shrink-0",children:s(k.size)}),n.jsx("button",{onClick:()=>{le.system.openPath(k.path)},className:"text-[10px] text-fg-tertiary hover:text-fg-secondary shrink-0 underline",children:a("common:open")})]},k.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(S)})}),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)})})]}),p&&n.jsx("div",{className:"text-xs text-fg-tertiary mt-2",children:p})]})}function sG({authUser:e,onClose:t,onSaved:r}){const{t:s}=kt("common"),[a,i]=b.useState(e.name||""),[l,d]=b.useState(e.email||""),[u,m]=b.useState(!1),[p,h]=b.useState(""),[y,g]=b.useState(e.avatarUrl),v=async S=>{if(S.preventDefault(),!a.trim()){h(s("profile.nameRequired"));return}if(l&&!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(l.trim())){h(s("profile.invalidEmail"));return}m(!0),h("");try{const{user:C}=await le.auth.updateProfile(a.trim(),l.trim());r({...C,avatarUrl:y??C.avatarUrl})}catch{h(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:S=>S.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(Qj,{currentUrl:y,name:a,size:72,targetType:"user",targetId:e.id,onUploaded:S=>g(S)})}),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:S=>i(S.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:S=>d(S.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"})]}),p&&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:p})]}),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 aG(){const{t:e}=kt(["settings","common"]),[t,r]=b.useState(null),[s,a]=b.useState(!0),[i,l]=b.useState(!1),[d,u]=b.useState(null),[m,p]=b.useState(!1),h=Kj(),y=b.useCallback(async()=>{try{const N=await le.settings.getRemote();r(N)}catch{r(null)}finally{a(!1)}},[]);b.useEffect(()=>{y()},[y]),b.useEffect(()=>gn.on("remote:status",N=>{const j=N.payload;j&&(r(j),l(!1))}),[]);const g=async()=>{l(!0),u(null);try{t?.enabled?(await le.settings.disableRemote(),await y(),l(!1)):(zn.isAuthenticated()||await pi(),await le.settings.enableRemote())}catch(N){u(String(N instanceof Error?N.message:N)),l(!1)}},v=async()=>{try{await pi(),await y()}catch{}},S=()=>{t?.remoteUrl&&(navigator.clipboard.writeText(t.remoteUrl),p(!0),setTimeout(()=>p(!1),2e3))},C=i||t?.enabled&&!t?.connected&&t?.state!=="idle",k=t?.remoteUrl??null;return n.jsx(si,{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")}),zn.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:h?.username??h?.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")})]}),zn.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:g,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(Ik,{})]}),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(Ik,{})]})]}),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:S,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")})]})]}),k&&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(iG,{url:k})]})]})]})]})})}function Ik(){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 iG({url:e}){const t=b.useRef(null),[r,s]=b.useState(!1);return b.useEffect(()=>{const a=t.current;a&&(s(!1),Sd(()=>import("./browser-BlsNdJA7.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 Wf=new Map;function Bl(e,t){Wf.has(e)||Wf.set(e,t().catch(()=>{}))}function Wl(e){const t=Wf.get(e);return Wf.delete(e),t}const ga={builderArtifacts:"builder.artifacts",builderAgents:"builder.agents",builderHubMyItems:"builder.hubMyItems",builderInstalled:"builder.installed",hubAgents:"hub.agents",hubTeams:"hub.teams",hubSkills:"hub.skills"};function oG(e){const t=e.indexOf(".markus/builder-artifacts/");return t>=0?"~/"+e.slice(t):e}const lG=[{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"}],Pk={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 Ok({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 cG(){const[e,t]=b.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 b.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 CS({authUser:e}={}){const{t}=kt(["builder","common"]),r=ks(),s=cG(),[a,i]=b.useState([]),[l,d]=b.useState([]),[u,m]=b.useState(!1),[p,h]=b.useState("all"),[y,g]=b.useState(null),[v,S]=b.useState(new Map),[C,k]=b.useState(null),[N,j]=b.useState(new Map),[T,R]=b.useState(null),[M,_]=b.useState(null),[F,z]=b.useState(null),L=b.useCallback(()=>{m(!0),Promise.all([(Wl(ga.builderArtifacts)??le.builder.artifacts.list()).then(W=>W?.artifacts??[]).catch(()=>[]),(Wl(ga.builderAgents)??le.agents.list()).then(W=>W?.agents??[]).catch(()=>[]),(Wl(ga.builderHubMyItems)??zn.myItems()).then(W=>W?.items??[]).catch(()=>[]),(Wl(ga.builderInstalled)??le.builder.artifacts.installed()).then(W=>W?.installed??{}).catch(()=>({}))]).then(([W,O,H,Z])=>{if(d(W),i(O),H.length>0){const J=new Map;for(const Q of H){const ee=Q.itemType==="agent"?"agent":Q.itemType==="team"?"team":"skill";for(const se of W)se.type===ee&&(Q.slug===se.name||Q.name===(se.meta.displayName||se.meta.name||se.name))&&J.set(`${se.type}/${se.name}`,{id:Q.id,name:Q.name,slug:Q.slug||se.name,version:Q.version||"1.0.0"})}J.size>0&&j(Q=>{const ee=new Map(Q);for(const[se,X]of J)ee.set(se,X);return ee})}const B=new Map;for(const J of W){const Q=`${J.type}/${J.name}`,ee=Z[Q];ee&&B.set(Q,{agentId:ee.agentId,agentIds:ee.agentIds,teamId:ee.teamId})}S(B)}).finally(()=>m(!1))},[]);b.useEffect(()=>{L();const W=O=>{O.detail?.page===Se.BUILDER&&L()};return window.addEventListener("markus:navigate",W),()=>window.removeEventListener("markus:navigate",W)},[L]);const U=W=>{const O=a.find(H=>H.role==="Secretary"||H.name==="Secretary");O?Nt.navigate(Se.TEAM,{agentId:O.id,prefillMessage:W}):Nt.navigate(Se.TEAM,{prefillMessage:W})},K=async W=>{const O=`${W.type}/${W.name}`;if(!v.has(O)){g({key:O,action:"install"});try{const H=await le.builder.artifacts.install(W.type,W.name),Z={};H.agent&&typeof H.agent=="object"&&(Z.agentId=H.agent.id),H.team&&typeof H.team=="object"&&(Z.teamId=H.team.id),Array.isArray(H.agents)&&(Z.agentIds=H.agents.map(B=>B.id)),S(B=>new Map(B).set(O,Z)),window.dispatchEvent(new CustomEvent("markus:data-changed"))}catch(H){console.error("Install failed:",H),alert(t("installFailed",{error:String(H)}))}finally{g(null)}}},q=async W=>{const O=`${W.type}/${W.name}`;if(v.has(O)){g({key:O,action:"uninstall"});try{await le.builder.artifacts.uninstall(W.type,W.name),S(H=>{const Z=new Map(H);return Z.delete(O),Z}),window.dispatchEvent(new CustomEvent("markus:data-changed"))}catch(H){console.error("Uninstall failed:",H),alert(t("uninstallFailed",{error:String(H)}))}finally{g(null)}}},I=async(W,O)=>{const H=`${W.type}/${W.name}`;g({key:H,action:"share"});try{const Z=await le.builder.artifacts.get(W.type,W.name),B=W.meta.displayName||W.meta.name||W.name,J=W.meta.description||"",Q=W.meta.category||"general",ee=Array.isArray(W.meta.tags)?W.meta.tags:[],se=W.name;let X=W.meta.icon||void 0;const me=W.meta.version||"1.0.0";if(X&&!X.startsWith("http")&&/\.(png|jpe?g|gif|webp|svg)$/i.test(X)){const pe=X.split("/").pop()??X;try{const Pe=await fetch(`/api/builder/artifacts/${W.type}s/${encodeURIComponent(W.name)}/images/${encodeURIComponent(pe)}`);if(Pe.ok){const Ae=await Pe.blob(),Xe=new File([Ae],pe,{type:Ae.type}),Ze=await zn.uploadImage(Xe);Ze?.url&&(X=Ze.url)}}catch{}}let je;const Re=[],Ee=Array.isArray(W.meta.screenshots)?W.meta.screenshots:[];for(let pe=0;pe<Ee.length;pe++){const Pe=Ee[pe],Ae=Pe.split("/").pop()??Pe;try{const Xe=await fetch(`/api/builder/artifacts/${W.type}s/${encodeURIComponent(W.name)}/images/${encodeURIComponent(Ae)}`);if(Xe.ok){const Ze=await Xe.blob(),at=new File([Ze],Ae,{type:Ze.type}),pt=await zn.uploadImage(at);pt?.url&&(Re.push({url:pt.url,alt:Ae,order:pe}),(pe===0||W.meta.thumbnail===Pe)&&(je=pt.url))}}catch{}}const we=await zn.publishViaProxy({itemType:W.type==="team"?"team":W.type==="skill"?"skill":"agent",name:B,slug:se,description:J,category:Q,tags:ee,icon:X,version:me,config:W.meta,files:Z.files&&Object.keys(Z.files).length>0?Z.files:void 0,thumbnailUrl:je,images:Re.length>0?Re:void 0,priceCents:O?.priceCents,donationsEnabled:O?.donationsEnabled});we.id&&j(pe=>{const Pe=new Map(pe);return Pe.set(H,{id:we.id,name:B,slug:we.slug??se,version:me}),Pe})}catch(Z){console.error("Share failed:",Z),alert(t("shareFailed",{error:String(Z)}))}finally{g(null)}},D=async()=>{if(!T)return;const{key:W}=T,O=N.get(W);if(R(null),!O)return;const H=O.id;g({key:W,action:"hubDelete"});try{await zn.deleteItem(H),j(Z=>{const B=new Map(Z);return B.delete(W),B})}catch(Z){console.error("Hub delete failed:",Z),alert(t("hubDeleteFailed",{error:String(Z)}))}finally{g(null)}},E=async()=>{if(!C)return;const W=C,O=`${W.type}/${W.name}`;k(null),g({key:O,action:"delete"});try{await le.builder.artifacts.delete(W.type,W.name),d(H=>H.filter(Z=>!(Z.type===W.type&&Z.name===W.name))),S(H=>{const Z=new Map(H);return Z.delete(O),Z}),window.dispatchEvent(new CustomEvent("markus:data-changed"))}catch(H){console.error("Delete failed:",H)}finally{g(null)}},$=p==="all"?l:l.filter(W=>W.type===p),Y=W=>{history.pushState(null,"",`#builder/${W.type}/${encodeURIComponent(W.name)}`),window.dispatchEvent(new HashChangeEvent("hashchange"))};return s?n.jsx(Jl,{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:L,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:lG.map(W=>{const O=t(`prompts.${W.id}Prompt`),H=t(`prompts.${W.id}Examples`,{returnObjects:!0}),Z=Array.isArray(H)?H:[];return n.jsx("button",{onClick:()=>U(O),className:`group text-left w-full rounded-xl border ${W.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 ${W.bgColor} flex items-center justify-center shrink-0`,children:W.icon}),n.jsxs("div",{className:"flex-1 min-w-0",children:[n.jsx("h3",{className:`text-sm font-semibold bg-gradient-to-r ${W.color} bg-clip-text text-transparent`,children:t(`prompts.${W.id}`)}),n.jsx("p",{className:"text-[11px] text-fg-tertiary mt-1 leading-relaxed",children:t(`prompts.${W.id}Desc`)}),Z.length>0&&n.jsx("div",{className:"mt-2 flex flex-wrap gap-1.5",children:Z.slice(0,2).map((B,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:Q=>{Q.stopPropagation(),U(O+B)},children:["“",B,"”"]},J))})]})]})},W.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(W=>n.jsx("button",{onClick:()=>h(W),className:`text-xs px-2.5 py-1 rounded-lg transition-colors ${p===W?"bg-brand-600 text-white":"text-fg-tertiary hover:text-fg-secondary hover:bg-surface-elevated"}`,children:t(W==="all"?"myCreations.filterAll":W==="agent"?"myCreations.filterAgents":W==="team"?"myCreations.filterTeams":"myCreations.filterSkills")},W))})]})}),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(W=>{const O=Pk[W.type]??Pk.agent,H=W.meta.displayName||W.meta.name||W.name,Z=W.meta.description||"",B=`${W.type}/${W.name}`,J=y?.key===B?y.action:null,Q=N.get(B),ee=W.meta.version||"1.0.0",se=!!Q,X=se&&Q.version!==ee,me=()=>{const Re=zn.getUser();return!Q||!Re?null:`${zn.getUrl()}/${encodeURIComponent(Re.username)}/${encodeURIComponent(Q.slug)}`},je=n.jsxs("div",{className:`flex items-center gap-1.5 ${r?"flex-wrap":"shrink-0"}`,onClick:Re=>Re.stopPropagation(),children:[v.has(B)?n.jsx("button",{onClick:()=>q(W),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:()=>K(W),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")}),se&&X?n.jsx("button",{onClick:()=>z(W),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})}):se?n.jsxs("div",{className:"flex items-center gap-1",children:[n.jsxs("a",{href:me()??"#",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:()=>R({key:B,name:H}),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 zn.ensureAuth(),Array.isArray(W.meta.screenshots)&&W.meta.screenshots.length>0?I(W):_(W)},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:()=>k(W),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:()=>Y(W),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 Re=W.meta.icon,we=Re&&(Re.startsWith("http")||Re.startsWith("/")||/\.(png|jpe?g|gif|webp|svg)$/i.test(Re))?Re.startsWith("http")||Re.startsWith("/")?Re:`/api/builder/artifacts/${W.type}s/${encodeURIComponent(W.name)}/images/${encodeURIComponent(Re.split("/").pop()??"")}`:null;return n.jsx("div",{className:`w-9 h-9 rounded-lg ${O.bg} flex items-center justify-center text-lg shrink-0 overflow-hidden`,children:we?n.jsx("img",{src:we,alt:"",className:"w-full h-full object-cover"}):Re?n.jsx("span",{children:Re}):O.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:H}),n.jsx("span",{className:`text-[10px] font-medium uppercase tracking-wider ${O.color}`,children:W.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:Re=>{Re.stopPropagation(),le.system.openPath(W.path).catch(()=>{})},className:"hover:text-fg-secondary transition-colors truncate min-w-0",title:W.path,children:oG(W.path)}),n.jsx("span",{className:"shrink-0",children:new Date(W.updatedAt).toLocaleDateString()})]})]}),!r&&je]}),r&&n.jsx("div",{className:"mt-3 pt-3 border-t border-border-default/50",children:je})]},B)})}),C&&n.jsx(Ok,{title:t("confirmDelete"),message:t("deleteCannotUndo",{name:C.meta.displayName||C.meta.name||C.name}),cancelLabel:t("common:cancel"),confirmLabel:t("common:delete"),onConfirm:E,onCancel:()=>k(null)}),T&&n.jsx(Ok,{title:t("confirmDelete"),message:t("removeFromHub",{name:T.name}),cancelLabel:t("common:cancel"),confirmLabel:t("common:delete"),onConfirm:()=>{D()},onCancel:()=>R(null)}),M&&n.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm",onClick:()=>_(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:W=>W.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 W=M;_(null),I(W)},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 W=M;_(null),Y(W)},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")})]})]})}),F&&n.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm",onClick:()=>z(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:W=>W.stopPropagation(),children:n.jsx(dG,{isUpdate:N.has(`${F.type}/${F.name}`),onCancel:()=>z(null),onConfirm:(W,O)=>{const H=F;z(null),I(H,{donationsEnabled:W==="donation",priceCents:W==="paid"?O:void 0})}})})})]})})}function dG({isUpdate:e,onCancel:t,onConfirm:r}){const{t:s}=kt(["builder","common"]),[a,i]=b.useState("free"),[l,d]=b.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 _k={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"}},uG=["development","devops","management","productivity","browser","custom","general"],mG=[{label:"Tech",emojis:["✦","◈","⬡","⚡","🤖","🧠","💡","🎯","🔧","📦","🚀","💻","🛠️","⭐","🔥","💎","⚙️","🧩","🔌","💾","🖥️","📡","🔬","🧪","🏗️","📱","🎮","🕹️","📟","💽","🖨️","⌨️"]},{label:"People",emojis:["👤","👥","🧑‍💻","👨‍💼","👩‍🔬","🧙","🦸","🤝","💪","🎓","👷","🕵️","🧑‍🎨","🧑‍🏫","👨‍🚀","🥷","🧑‍🏭","🧑‍⚕️","🧑‍🔧","🧑‍🍳","👨‍🎤","🦹","🧝","🧞","🧑‍✈️","💂","🤴","👸","🧛","🧟","🧜","🧚"]},{label:"Objects",emojis:["📝","📊","🗂️","📁","🔍","🔑","🌐","💬","🔒","🎨","📐","🗃️","📋","✏️","🖊️","📌","📎","🧲","🪝","🧰","🪜","🧬","🔭","💊","🩺","📕","📗","📘","📙","📓","🗒️","📰"]},{label:"Symbols",emojis:["❤️","🧡","💛","💚","💙","💜","🖤","🤍","♠️","♥️","♦️","♣️","🎵","🎶","💯","✅","❌","⭕","🔴","🟠","🟡","🟢","🔵","🟣","⚫","⚪","🟤","🔶","🔷","▶️","⏸️","⏹️"]},{label:"Nature",emojis:["🌟","🌈","🌊","🌿","🍀","🔮","💫","✨","🌙","☀️","🦋","🐉","🦊","🐺","🦅","🐙","🦁","🐯","🦄","🐲","🌸","🌺","🍄","🌵","🎄","🌴","🍁","🌻","🐝","🦎","🐍","🦈"]},{label:"Activity",emojis:["🎯","🏆","🥇","🎖️","🏅","🎪","🎭","🎬","🎤","🎧","🎼","🎹","🥁","🎸","🎺","🎻","⚽","🏀","🎾","🏐","🎲","🧸","🪁","🎰","🎳","🏹","🥊","🤺","⛷️","🏄","🚴","🧗"]}],fG={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 Ex({value:e,onChange:t,renderAs:r="span",className:s,editClassName:a,placeholder:i,multiline:l,readOnly:d}){if(d){const j=e||i,R=`${s??""} ${!e?"text-fg-muted italic":""}`;return r==="h1"?n.jsx("h1",{className:R,children:j}):r==="p"?n.jsx("p",{className:R,children:j}):n.jsx("span",{className:R,children:j})}const[u,m]=b.useState(!1),[p,h]=b.useState(e),y=b.useRef(null);b.useEffect(()=>{h(e)},[e]),b.useEffect(()=>{u&&y.current?.focus()},[u]);const g=()=>{m(!1),p!==e&&t(p)},v=()=>{h(e),m(!1)},S=j=>{j.key==="Escape"&&v(),j.key==="Enter"&&!l&&g()};if(u){const j=`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:p,onChange:T=>h(T.target.value),onBlur:g,onKeyDown:S,className:`${j} resize-y min-h-[60px]`,placeholder:i}):n.jsx("input",{ref:y,value:p,onChange:T=>h(T.target.value),onBlur:g,onKeyDown:S,className:j,placeholder:i})}const C=e||i,k=!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} ${k?"text-fg-muted italic":""}`,children:C}):r==="p"?n.jsx("p",{onClick:()=>m(!0),className:`${s??""} ${N} ${k?"text-fg-muted italic":""}`,children:C}):r==="badge"?n.jsx("span",{onClick:()=>m(!0),className:`${s??""} ${N} ${k?"text-fg-muted italic":""}`,children:C}):n.jsx("span",{onClick:()=>m(!0),className:`${s??""} ${N} ${k?"text-fg-muted italic":""}`,children:C})}function hG({value:e,options:t,onChange:r,className:s,readOnly:a}){if(a)return n.jsx("span",{className:s,children:e});const[i,l]=b.useState(!1),[d,u]=b.useState(e),m=b.useRef(null),p=b.useRef(null);b.useEffect(()=>{i&&(u(e),setTimeout(()=>m.current?.focus(),0))},[i,e]);const h=t.filter(g=>g.toLowerCase().includes(d.toLowerCase())),y=g=>{const v=g.trim();v&&v!==e&&r(v),l(!1)};return i?n.jsxs("div",{ref:p,className:"relative inline-block",children:[n.jsx("input",{ref:m,value:d,onChange:g=>u(g.target.value),onKeyDown:g=>{g.key==="Enter"?(g.preventDefault(),y(d)):g.key==="Escape"&&l(!1)},onBlur:g=>{p.current?.contains(g.relatedTarget)||y(d)},className:`${s??""} bg-transparent outline-none ring-1 ring-brand-500/50 rounded w-28`}),h.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:h.map(g=>n.jsx("button",{onMouseDown:v=>{v.preventDefault(),y(g)},className:`block w-full text-left px-3 py-1.5 text-xs hover:bg-surface-secondary/80 transition-colors ${g===e?"text-brand-400 font-medium":"text-fg-secondary"}`,children:g},g))})]}):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 pG({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(p=>n.jsx("span",{className:"text-[10px] px-2 py-0.5 bg-surface-elevated text-fg-muted rounded-full border border-border-default",children:p},p))});const{t:s}=kt(["builder"]),[a,i]=b.useState(!1),[l,d]=b.useState(""),u=b.useRef(null);b.useEffect(()=>{a&&u.current?.focus()},[a]);const m=p=>{if((p.key==="Enter"||p.key===",")&&l.trim()){p.preventDefault();const h=l.trim().toLowerCase();e.includes(h)||t([...e,h]),d("")}else p.key==="Backspace"&&!l&&e.length>0?t(e.slice(0,-1)):p.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(p=>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:[p,n.jsx("button",{onClick:()=>t(e.filter(h=>h!==p)),className:"text-fg-muted hover:text-red-500",children:"×"})]},p)),n.jsx("input",{ref:u,value:l,onChange:p=>d(p.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(p=>n.jsx("span",{className:"text-[10px] px-2 py-0.5 bg-surface-elevated text-fg-muted rounded-full border border-border-default",children:p},p)):n.jsx("span",{className:"text-[10px] text-fg-muted italic",children:s("detail.typeTagAndEnter")})})}function Pb({content:e}){return n.jsx("div",{className:`prose prose-invert prose-sm max-w-none
655
+ `)){Pr(!0),Vi(ht.toLowerCase()),Es(0);return}}}Pr(!1)},Oe=te=>{const ke=dn.current?.selectionStart??nt.length,Ie=nt.slice(0,ke).lastIndexOf("@"),wt=nt.slice(ke),We=te.includes(" ")?`@[${te}]`:`@${te}`,ht=nt.slice(0,Ie)+We+" "+wt;ft(ht),Pr(!1),Es(0);const Tt=Ie+We.length+1;requestAnimationFrame(()=>{dn.current?.setSelectionRange(Tt,Tt)})},Je=10*1024*1024,Mn=5,ia=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"]),Aa=b.useCallback(te=>te.type.startsWith("image/")||ia.has(te.type),[]),rs=te=>te.dataUrl.startsWith("data:image/"),Cd=(te,ke)=>{if(rs({dataUrl:ke}))return null;const Le=te.split(".").pop()?.toLowerCase()??"";return{pdf:"📄",docx:"📝",doc:"📝",xlsx:"📊",xls:"📊",pptx:"📎",csv:"📊",json:"🔧",xml:"🔧",html:"🌐",epub:"📚"}[Le]??"📁"},bl=b.useCallback(te=>{const ke=Array.from(te).filter(Aa);if(ke.length!==0)for(const Le of ke){if(Le.size>Je)continue;const Ie=new FileReader;Ie.onload=()=>{const wt=Ie.result;lr(We=>We.length>=Mn||We.some(ht=>ht.dataUrl===wt)?We:[...We,{id:`img_${Date.now()}_${Math.random().toString(36).slice(2,6)}`,dataUrl:wt,name:Le.name}])},Ie.readAsDataURL(Le)}},[Aa]),Bh=b.useCallback(te=>{lr(ke=>ke.filter(Le=>Le.id!==te))},[]),Hh=b.useCallback(te=>{const ke=te.clipboardData?.files;if(ke&&ke.length>0){const Le=Array.from(ke).filter(Aa);Le.length>0&&(te.preventDefault(),bl(Le))}},[bl,Aa]),Td=b.useCallback(te=>{te.preventDefault();const ke=te.dataTransfer?.files;ke&&ke.length>0&&bl(Array.from(ke).filter(Aa))},[bl,Aa]),yl=b.useCallback(te=>{te.preventDefault()},[]),Qr=d.find(te=>te.id===fe),vl=t?.name??a("page.fallbackYou"),Ad=Ge[Ge.length-1],j0=$e&&Ad?.sender==="agent",N0=Ln&&Ad?.sender==="agent",Ed=b.useMemo(()=>{if(_e!=="channel")return null;if(ne.startsWith("group:custom:")){const ke=Qe.find(Le=>Le.channelKey===ne);return ke?.members?new Set(ke.members.filter(Le=>Le.type==="agent").map(Le=>Le.id)):null}if(!dr)return null;const te=jn.find(ke=>ke.id===dr);return te?new Set(te.members.filter(ke=>ke.type==="agent").map(ke=>ke.id)):null},[_e,ne,dr,jn,Qe]),oa=d.filter(te=>Ed?Ed.has(te.id):!0).filter(te=>te.name.toLowerCase().includes(Wa)),Md=m.find(te=>te.id===Be),Dd=Be===t?.id||!Be,Xs=Qe.find(te=>te.channelKey===ne);b.useEffect(()=>{if(r||!ne.startsWith("group:custom:"))return;const te=Qe.find(ke=>ke.channelKey===ne);!te||te.members||le.groupChats.getById(te.id).then(ke=>{ke.chat.members&&xt(Le=>Le.map(Ie=>Ie.id===te.id?{...Ie,members:ke.chat.members}:Ie))}).catch(()=>{})},[r,ne,Qe]);const Rd=_e==="channel"?Xs?.name??ne:_e==="direct"?Qr?.name??a("page.selectAgent"):_e==="dm"?Dd?a("chat.myNotes"):Md?.name??a("page.directMessage"):a("page.chatTitle"),S0=_e==="channel"?Xs?a("page.placeholder.channel",{name:Xs.name}):a("page.placeholder.channelWithMention",{name:ne}):_e==="dm"?Dd?a("page.placeholder.dmSelf"):a("page.placeholder.dmOther",{name:Md?.name??""}):a(fe?"page.placeholder.direct":"page.placeholder.noAgent"),wl=g&&k==="chat";return n.jsxs("div",{ref:q,className:"flex-1 overflow-hidden flex relative",children:[n.jsx(vK,{authUser:t,agents:d,teams:jn,humans:m,tasks:Bt,externalAgents:rr,groupChats:Qe,chatMode:_e,selectedAgent:fe,activeChannel:ne,activeDmUserId:Be,previewMode:r,onSelectAgent:te=>{ue("direct"),Me(te),_("chat"),un(!1),g&&T()},onSelectChannel:te=>{ue("channel"),he(te),_("chat"),un(!1),g&&T()},onSelectDm:te=>{ue("dm"),de(te),_("chat"),un(!1),g&&T()},onSelectTeam:te=>{const ke=Qe.find(Le=>Le.type==="team"&&Le.teamId===te);g?R(te):ke&&(ue("channel"),he(ke.channelKey),_("chat"),un(!1),!L&&!I&&U(!0))},selectedTeamId:dr??(_e==="direct"&&Qr?.teamId?Qr.teamId:null),onRefreshTeams:Cr,onRefreshAgents:Xr,onRefreshHumans:Sa,onRefreshGroupChats:Br,onViewProfile:at,onManageGroupMembers:te=>{ue("channel"),he(te),_("chat"),un(!0),g&&T()},unreadByAgent:Yr,unreadByChannel:Ka,width:g?void 0:z.width,onResizeStart:g?void 0:z.onResizeStart,hidden:g&&k!=="roster",initialLoading:h}),g&&k==="team"&&N&&(()=>{const te=jn.find(Ie=>Ie.id===N);if(!te)return null;const ke=d.filter(Ie=>Ie.teamId===N),Le=Qe.find(Ie=>Ie.type==="team"&&Ie.teamId===N);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=Se.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:te.name}),n.jsx("p",{className:"text-[10px] text-fg-tertiary",children:a("chat.members_other",{count:te.members?.length||ke.length})})]})]})]}),n.jsxs("div",{className:"flex-1 overflow-y-auto px-3 py-3 space-y-1",children:[Le&&(()=>{const Ie=Ka[Le.channelKey]??0;return n.jsxs("button",{onClick:()=>{ue("channel"),he(Le.channelKey),_("chat"),T()},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:Le.name}),n.jsx("div",{className:"text-[10px] text-fg-tertiary",children:a("chat.groupChat")})]}),Ie>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:Ie}):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"})})]})})(),ke.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")}),ke.map(Ie=>{const wt=Yr.get(Ie.id)??0;return n.jsxs("button",{onClick:()=>{ue("direct"),Me(Ie.id),_("chat"),T()},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(gr,{name:Ie.name||"Agent",avatarUrl:Ie.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:Ie.name}),n.jsx("div",{className:"text-[10px] text-fg-tertiary truncate",children:Ie.role||Ie.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 ${Ie.status==="active"||Ie.status==="idle"?"bg-green-500":Ie.status==="working"||Ie.status==="busy"?"bg-blue-500":Ie.status==="paused"?"bg-amber-500":"bg-gray-400"}`})]},Ie.id)})]})]})]})})(),L&&!I&&!g&&(()=>{const te=dr??(_e==="direct"?Qr?.teamId:void 0);if(!te)return null;const ke=jn.find(Ie=>Ie.id===te);if(!ke)return null;const Le=Qe.find(Ie=>Ie.type==="team"&&Ie.teamId===te);return n.jsx(ck,{team:ke,agents:d,humans:m,authUser:t,groupChat:Le,chatMode:_e,selectedAgent:fe,activeChannel:ne,teams:jn,onSelectAgent:Ie=>{ue("direct"),Me(Ie),_("chat"),un(!1)},onSelectChannel:Ie=>{ue("channel"),he(Ie),_("chat"),un(!1)},onSelectDm:Ie=>{ue("dm"),de(Ie),_("chat"),un(!1)},onBack:()=>U(!1),onViewProfile:at,onRefreshAgents:Xr,onRefreshTeams:Cr,unreadByAgent:Yr,width:K.width,onResizeStart:K.onResizeStart})})(),E&&!g&&(()=>{const te=dr??(_e==="direct"?Qr?.teamId:void 0);if(!te)return null;const ke=jn.find(Ie=>Ie.id===te);if(!ke)return null;const Le=Qe.find(Ie=>Ie.type==="team"&&Ie.teamId===te);return n.jsxs("div",{"data-l2-floating":!0,className:"absolute z-30 inset-0",style:{left:z.width+6},children:[n.jsx("div",{className:"absolute inset-0 bg-black/20",onClick:()=>$(!1)}),n.jsx("div",{className:"relative h-full",style:{width:K.width+8},children:n.jsx(ck,{team:ke,agents:d,humans:m,authUser:t,groupChat:Le,chatMode:_e,selectedAgent:fe,activeChannel:ne,teams:jn,onSelectAgent:Ie=>{ue("direct"),Me(Ie),_("chat"),un(!1),$(!1)},onSelectChannel:Ie=>{ue("channel"),he(Ie),_("chat"),un(!1),$(!1)},onSelectDm:Ie=>{ue("dm"),de(Ie),_("chat"),un(!1),$(!1)},onBack:()=>$(!1),onViewProfile:Ie=>{at(Ie),$(!1)},onRefreshAgents:Xr,onRefreshTeams:Cr,unreadByAgent:Yr,width:K.width})})]})})(),(!g||wl)&&n.jsxs("div",{className:`flex-1 overflow-hidden flex flex-col ${g?"min-w-0":"min-w-[400px]"}`,children:[n.jsxs("div",{className:"shrink-0 relative pb-2",children:[g?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=j.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:Rd}),_e==="direct"&&Qr&&n.jsx(Mk,{agent:Qr,tasks:Bt,onViewProfile:at})]}),n.jsxs("div",{className:"flex items-center px-3 h-9 gap-1 border-t border-border-default/40",children:[n.jsx("button",{onClick:()=>{uo(M)?history.back():_("chat")},className:`px-2.5 py-1 text-xs font-medium rounded-md transition-colors ${M==="chat"?"bg-brand-500/15 text-brand-500":"text-fg-tertiary"}`,children:a("page.chatTitle")}),n.jsx("button",{onClick:()=>{uo(M)||Pe()},className:`px-2.5 py-1 text-xs font-medium rounded-md transition-colors ${uo(M)?"bg-brand-500/15 text-brand-500":"text-fg-tertiary"}`,children:a(_e==="channel"?"page.teamTab":"page.profileTab")}),n.jsx("div",{className:"flex-1"}),_e==="channel"&&Xs?.type==="custom"&&n.jsxs("button",{onClick:()=>un(!en),className:`text-[11px] px-2 py-1 rounded-md font-medium shrink-0 flex items-center gap-1 ${en?"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"})]}),Xs.members?.length??Xs.memberCount??0]}),_e==="direct"&&!uo(M)&&n.jsxs(n.Fragment,{children:[n.jsx("button",{onClick:Fr,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:$n,onClick:()=>Vt(!At),className:`p-1 rounded-md transition-colors shrink-0 ${At?"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 te=dr?jn.find(jt=>jt.id===dr):void 0,ke=_e==="direct"&&fe?VK:_e==="channel"&&dr?WK:["chat"],Le=async()=>{const jt=se.trim();if(!jt){ee(!1);return}try{_e==="direct"&&fe?(await le.agents.updateConfig(fe,{name:jt}),Xr()):_e==="channel"&&dr&&(await le.teams.update(dr,{name:jt}),Cr())}catch{}ee(!1)},Ie=async()=>{try{_e==="direct"&&fe?(await le.agents.updateConfig(fe,{roleDescription:Re}),Xr()):_e==="channel"&&dr&&(await le.teams.update(dr,{description:Re}),Cr())}catch{}je(!1)},wt=_e==="direct"?Qr?.name:_e==="channel"?te?.name??Xs?.name:Md?.name??"",We=_e==="direct"?Qr?.role||"":_e==="channel"&&te?.description||"",ht=_e==="direct"?Qr?.avatarUrl:void 0,Tt=wt||"U",rt=_e==="direct"&&fe||_e==="channel"&&dr;return n.jsxs("div",{className:"flex flex-col",children:[n.jsxs("div",{className:"flex items-center px-4 h-14 gap-2.5",children:[(!L||I)&&(_e==="channel"&&dr||_e==="direct"&&Qr?.teamId)&&n.jsx("button",{onClick:Y,className:`w-8 h-8 flex items-center justify-center rounded-lg transition-colors shrink-0 ${E?"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"})]})}),rt&&(_e==="channel"&&dr?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(gr,{name:Tt,avatarUrl:ht,size:36,className:"rounded-xl shrink-0"})),rt?n.jsxs("div",{className:"flex-1 min-w-0",children:[n.jsxs("div",{className:"flex items-center gap-2",children:[Q?n.jsx("input",{ref:we,value:se,onChange:jt=>X(jt.target.value),onBlur:Le,onKeyDown:jt=>{jt.key==="Enter"&&Le(),jt.key==="Escape"&&ee(!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:()=>{X(wt??""),ee(!0)},title:"Click to edit name",children:wt}),_e==="direct"&&Qr&&n.jsx(Mk,{agent:Qr,tasks:Bt,onViewProfile:at})]}),(_e==="direct"||_e==="channel"&&dr)&&(me?n.jsx("input",{ref:pe,value:Re,onChange:jt=>Ee(jt.target.value),onBlur:Ie,onKeyDown:jt=>{jt.key==="Enter"&&Ie(),jt.key==="Escape"&&je(!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:()=>{Ee(We),je(!0)},title:"Click to edit description",children:We||"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:Rd}),_e==="dm"&&n.jsx("span",{className:"text-xs text-fg-tertiary",children:Dd?a("page.privateNotepad"):""})]}),n.jsxs("div",{className:"ml-auto flex items-center gap-2 shrink-0",children:[_e==="channel"&&Xs?.type==="custom"&&n.jsxs("button",{onClick:()=>un(!en),className:`text-xs px-2.5 py-1 rounded-md border transition-colors flex items-center gap-1.5 ${en?"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"})]}),Xs.members?.length??Xs.memberCount??0]}),_e==="direct"&&Qr&&M==="chat"&&n.jsxs("div",{className:"flex items-center gap-1.5",children:[n.jsx("button",{onClick:Fr,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:$n,onClick:()=>Vt(!At),className:`p-1.5 rounded-md transition-colors ${At?"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"})})})]})]})]}),ke.length>1&&n.jsx("div",{className:"flex items-center gap-1 px-4 pb-1.5 overflow-x-auto scrollbar-hide",children:ke.map(jt=>n.jsxs("button",{onClick:()=>_(jt),className:`px-3 py-1.5 text-xs font-medium rounded-md transition-colors whitespace-nowrap flex items-center gap-1 ${M===jt?"bg-brand-500/15 text-brand-500":"text-fg-tertiary hover:text-fg-secondary hover:bg-surface-elevated/50"}`,children:[n.jsx("span",{children:GK(jt)}),KK(jt,a)]},jt))})]})})(),_e==="direct"&&fe&&M==="chat"&&rn.length>1&&n.jsx("div",{className:"flex items-center gap-0 px-3 overflow-x-auto scrollbar-hide",children:rn.map(te=>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] ${te.id===hn?"text-brand-500 bg-brand-500/10":"text-fg-tertiary hover:text-fg-secondary hover:bg-surface-elevated/50"}`,onClick:()=>{if(te.id===Cn){Ne(Cn);const ke=Ve.current;Ce.current.delete(ke),ut([])}else Ls(te)},children:[te.isMain&&n.jsx("span",{className:"text-[10px] opacity-50 shrink-0",children:"●"}),n.jsx("span",{className:"truncate",children:te.id===Cn?a("page.newChat"):te.isMain?a("page.sessionMain"):te.title||a("page.sessionConversation")}),!te.isMain&&n.jsx("button",{onClick:ke=>{ke.stopPropagation(),Fs(te.id)},className:"opacity-0 group-hover:opacity-100 text-fg-tertiary hover:text-fg-secondary transition-opacity shrink-0",children:"✕"})]},te.id))}),_e==="channel"&&Xs?.type==="custom"&&en&&(()=>{const te=Xs,ke=te.members??[],Le=[];for(const Ie of d)ke.some(wt=>wt.id===Ie.id)||Le.push({id:Ie.id,name:Ie.name,type:"agent",subtitle:Ie.role||"Agent"});for(const Ie of m)ke.some(wt=>wt.id===Ie.id)||Le.push({id:Ie.id,name:Ie.name,type:"human",subtitle:Ie.email||Ie.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")," (",ke.length,")"]}),n.jsx("button",{onClick:()=>un(!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:ke.map(Ie=>n.jsxs("span",{className:`inline-flex items-center gap-1.5 px-2 py-1 rounded-full text-[11px] font-medium ${Ie.type==="agent"?"bg-brand-500/10 text-brand-500":"bg-green-500/10 text-green-600"}`,children:[n.jsx(gr,{name:Ie.name,size:16,bgClass:Ie.type==="agent"?"bg-brand-500/15 text-brand-500":"bg-green-500/15 text-green-600"}),Ie.name,Ie.id!==t?.id&&n.jsx("button",{onClick:async()=>{try{await le.groupChats.removeMember(te.id,Ie.id),xt(wt=>wt.map(We=>We.id===te.id?{...We,members:(We.members??[]).filter(ht=>ht.id!==Ie.id),memberCount:(We.memberCount??1)-1}:We))}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"})]})})]},Ie.id))}),Le.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 Ie=>{const wt=Ie.target.value;if(!wt)return;const We=Le.find(ht=>ht.id===wt);if(We)try{await le.groupChats.addMember(te.id,We.id,We.type,We.name),xt(ht=>ht.map(Tt=>Tt.id===te.id?{...Tt,members:[...Tt.members??[],{id:We.id,name:We.name,type:We.type}],memberCount:(Tt.memberCount??0)+1}:Tt))}catch{}},children:[n.jsx("option",{value:"",children:a("page.addMemberPlaceholder")}),Le.map(Ie=>n.jsxs("option",{value:Ie.id,children:["[",Ie.type==="agent"?"Agent":"Human","] ",Ie.name]},Ie.id))]})})]})})(),_e==="direct"&&fe&&At&&n.jsxs("div",{ref:js,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:()=>Vt(!1),className:"text-fg-tertiary hover:text-fg-secondary text-xs",children:"✕"})]}),n.jsxs("div",{className:"flex-1 overflow-y-auto p-2",children:[$r.length===0&&n.jsx("div",{className:"text-xs text-fg-tertiary text-center py-6",children:a("page.noConversationsYet")}),(()=>{const te=new Date,ke=new Date(te.getFullYear(),te.getMonth(),te.getDate()).getTime(),Le=ke-864e5,Ie=ke-7*864e5,wt=[],We=[],ht=[],Tt=[],rt=[];for(const jt of $r){const an=new Date(jt.lastMessageAt).getTime();an>=ke?We.push(jt):an>=Le?ht.push(jt):an>=Ie?Tt.push(jt):rt.push(jt)}return We.length>0&&wt.push({label:a("page.dateToday"),items:We}),ht.length>0&&wt.push({label:a("page.dateYesterday"),items:ht}),Tt.length>0&&wt.push({label:a("page.datePrevious7Days"),items:Tt}),rt.length>0&&wt.push({label:a("page.dateOlder"),items:rt}),wt.map(jt=>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:jt.label}),jt.items.map(an=>n.jsxs("button",{onClick:()=>{Ls(an)},className:`w-full text-left px-3 py-2.5 rounded-lg text-xs mb-0.5 transition-colors ${an.id===hn?"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:[an.isMain&&n.jsx("span",{className:"text-[10px] text-brand-500 opacity-80",children:"●"}),an.isMain?a("page.sessionMain"):an.title||a("page.sessionConversation")]}),n.jsx("div",{className:"text-fg-tertiary text-[10px] mt-0.5",children:new Date(an.lastMessageAt).toLocaleString()})]},an.id))]},jt.label))})()]})]})]}),g&&M==="profile"&&_e==="direct"&&fe&&n.jsx("div",{className:"flex-1 overflow-y-auto",children:n.jsx(dk,{agentId:fe,onBack:()=>_("chat"),inline:!0,defaultTab:H,highlightMailboxId:B,onSwipeBack:()=>{uo(F.current)?history.back():_("chat")},authUser:t})}),g&&M==="profile"&&_e==="channel"&&dr&&n.jsx("div",{className:"flex-1 overflow-y-auto",onTouchStart:g?Ze.onTouchStart:void 0,onTouchEnd:g?Ze.onTouchEnd:void 0,children:n.jsx(jk,{teamId:dr,onBack:()=>_("chat"),inline:!0,onSelectAgent:te=>{ue("direct"),Me(te),Pe()}})}),!g&&uo(M)&&_e==="direct"&&fe&&n.jsx("div",{className:"flex-1 overflow-y-auto",children:n.jsx(dk,{agentId:fe,onBack:()=>_("chat"),inline:!0,headless:!0,activeTab:M,highlightMailboxId:B,authUser:t})}),!g&&uo(M)&&_e==="channel"&&dr&&n.jsx("div",{className:"flex-1 flex flex-col min-h-0",children:n.jsx(jk,{teamId:dr,onBack:()=>_("chat"),inline:!0,headless:!0,activeTab:M,onSelectAgent:te=>{ue("direct"),Me(te),_("overview"),!L&&!I&&U(!0)}})}),n.jsxs("div",{className:`flex-1 overflow-hidden flex flex-col relative ${M!=="chat"?"hidden":""}`,children:[Lt&&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:Hs,className:`flex-1 overflow-y-auto space-y-3 ${g?"p-2.5":"p-5 2xl:pr-[280px]"}`,onScroll:Wi,onTouchStart:g?Ze.onTouchStart:void 0,onTouchEnd:g?Ze.onTouchEnd:void 0,children:[Ge.length===0&&!$e&&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:_e==="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"})})}),_e==="channel"&&n.jsx("div",{children:a("page.emptyChannel",{name:Xs?.name??ne})}),_e==="direct"&&!fe&&n.jsx("div",{children:a("page.emptySelectAgent")}),_e==="direct"&&fe&&n.jsx("div",{children:a("page.emptyNewConversation",{name:Qr?.name??""})})]}),_e==="channel"?Ge.map(te=>n.jsxs("div",{id:`msg-${te.id}`,className:"group/msg flex gap-3 transition-colors rounded-lg",children:[n.jsx("div",{className:"shrink-0 cursor-pointer",onClick:ke=>{if(te.sender==="agent"&&te.agentId){const Le=ke.currentTarget.getBoundingClientRect();O({agentId:te.agentId,top:Le.top,left:Le.right+8})}},children:n.jsx(gr,{name:te.sender==="user"?vl:te.agentName??a("page.fallbackAgent"),avatarUrl:te.sender==="user"?t?.avatarUrl:d.find(ke=>ke.id===te.agentId)?.avatarUrl,size:32,bgClass:te.sender==="user"?"bg-brand-600":"bg-brand-500/15 text-brand-600",className:te.sender==="agent"?"hover:ring-1 hover:ring-brand-500/40 rounded-lg":"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:te.sender==="user"?vl:te.agentName??a("page.fallbackAgent")}),n.jsx("span",{className:"text-xs text-fg-tertiary",children:te.time})]}),te.replyToId&&te.replyToSender&&n.jsxs("button",{onClick:()=>{const ke=document.getElementById(`msg-${te.replyToId}`);ke&&(ke.scrollIntoView({behavior:"smooth",block:"center"}),ke.classList.add("bg-brand-500/10"),setTimeout(()=>ke.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:te.replyToSender}),n.jsx("span",{className:"truncate max-w-[250px]",children:te.replyToText??"..."})]}),n.jsxs("div",{className:`mt-0.5 ${te.sender==="agent"?"bg-surface-chat-bubble rounded-2xl px-3.5 py-2.5":""} ${te.isError||te.sender==="agent"&&te.text.startsWith("⚠")?"border-b-2 border-red-500/60":""}`,children:[te.sender==="agent"?n.jsx(Ur,{content:te.text,className:"text-sm text-fg-secondary",onMentionClick:pt,knownNames:Ct}):n.jsxs("div",{className:"text-sm text-fg-secondary whitespace-pre-wrap",children:[te.images&&te.images.length>0&&n.jsx("div",{className:"flex flex-wrap gap-1.5 mb-1",children:te.images.map((ke,Le)=>n.jsx("img",{src:ke,alt:"",className:"max-w-[200px] max-h-[150px] rounded-lg object-cover cursor-pointer hover:opacity-80 transition-opacity",onClick:()=>window.open(ke,"_blank")},Le))}),lk(te.text,d,(ke,Le)=>{const Ie=Le.currentTarget.getBoundingClientRect();O({agentId:ke.id,top:Ie.bottom,left:Ie.left})})]}),te.isNotification&&n.jsx(Sk,{priority:te.notifyPriority})]}),!r&&n.jsx("div",{className:`transition-opacity ${g?"opacity-100":"opacity-0 group-hover/msg:opacity-100"}`,children:n.jsx(Tk,{msg:te,onCopy:pr,onRetry:En,onResume:Dt,onReply:Rs,isCopied:Ye===te.id,isLastAgentMsg:te.id===sn})})]})]},te.id)):Ge.map((te,ke)=>{const Ie=j0&&ke===Ge.length-1&&$e,wt=N0&&ke===Ge.length-1||Ie,We=!Ie||te.isStopped;return te.isActivityLog?null:n.jsxs("div",{id:`msg-${te.id}`,className:"group/msg flex gap-3 transition-colors rounded-lg",children:[n.jsx("div",{className:"shrink-0",children:n.jsx(gr,{name:te.sender==="user"?vl:te.agentName??(_e==="direct"?Qr?.name??a("page.fallbackAgent"):a("page.fallbackAgent")),avatarUrl:te.sender==="user"?t?.avatarUrl:d.find(ht=>ht.id===(te.agentId??(_e==="direct"?Qr?.id:void 0)))?.avatarUrl,size:32,bgClass:te.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:te.sender==="user"?vl:n.jsx(FK,{name:te.agentName??(_e==="direct"?Qr?.name??a("page.fallbackAgent"):a("page.fallbackAgent")),agentId:te.agentId??(_e==="direct"?Qr?.id:void 0),agents:d,onViewProfile:at})}),n.jsx("span",{className:"text-xs text-fg-tertiary",children:te.time})]}),te.replyToId&&te.replyToSender&&n.jsxs("button",{onClick:()=>{const ht=document.getElementById(`msg-${te.replyToId}`);ht&&(ht.scrollIntoView({behavior:"smooth",block:"center"}),ht.classList.add("bg-brand-500/10"),setTimeout(()=>ht.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:te.replyToSender}),n.jsx("span",{className:"truncate max-w-[250px]",children:te.replyToText??"..."})]}),n.jsxs("div",{className:`mt-0.5 ${te.sender==="agent"?"bg-surface-chat-bubble rounded-2xl px-3.5 py-2.5":""} ${te.isError||te.sender==="agent"&&te.text.startsWith("⚠")?"border-b-2 border-red-500/60":""} ${wt&&te.sender==="agent"?"streaming-bubble":""}`,children:[te.sender==="user"?n.jsxs("div",{className:"text-sm text-fg-secondary whitespace-pre-wrap",children:[te.images&&te.images.length>0&&n.jsx("div",{className:"flex flex-wrap gap-1.5 mb-1",children:te.images.map((ht,Tt)=>n.jsx("img",{src:ht,alt:"",className:"max-w-[200px] max-h-[150px] rounded-lg object-cover cursor-pointer hover:opacity-80 transition-opacity",onClick:()=>window.open(ht,"_blank")},Tt))}),te.text&&n.jsx("span",{className:"leading-relaxed",children:lk(te.text,d,(ht,Tt)=>{const rt=Tt.currentTarget.getBoundingClientRect();O({agentId:ht.id,top:rt.bottom,left:rt.left})})})]}):n.jsx(UK,{msg:te,isStreaming:Ie,liveActivities:Ie?gs:[],onViewModeChange:ht=>Et(Tt=>{const rt=new Set(Tt);return ht==="full"?rt.add(te.id):rt.delete(te.id),rt}),onMentionClick:pt,knownNames:Ct}),te.isNotification&&n.jsx(Sk,{priority:te.notifyPriority})]}),We&&!r&&n.jsx("div",{className:`transition-opacity ${te.isStopped||g?"opacity-100":"opacity-0 group-hover/msg:opacity-100"}`,children:n.jsx(Tk,{msg:te,onCopy:pr,onRetry:En,onResume:Dt,onReply:Rs,isCopied:Ye===te.id,isLastAgentMsg:te.id===sn})})]})]},te.id)}),_e==="channel"&&Ut.length>0&&n.jsx("div",{className:"flex flex-col gap-1.5 py-2",children:Ut.map(te=>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:()=>at(te.id,{tab:"overview"}),children:[n.jsxs("div",{className:"relative shrink-0",children:[n.jsx(gr,{name:te.name,avatarUrl:te.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:te.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:"→"})]},te.id))}),n.jsx("div",{ref:va})]})]}),W&&(()=>{const te=d.find(ke=>ke.id===W.agentId);return te?n.jsx(qK,{agent:te,anchorRect:{top:W.top,left:W.left},onClose:()=>O(null),onViewProfile:at}):null})(),n.jsx("div",{className:`${g?"px-3 py-2":"px-5 py-3 2xl:pr-[280px]"} relative shrink-0 ${M!=="chat"?"hidden":""}`,onDrop:Td,onDragOver:yl,children:n.jsxs("div",{className:`bg-surface-primary border border-border-default shadow-lg shadow-black/5 ${g?"rounded-2xl p-3":"rounded-2xl p-3 max-w-3xl"}`,children:[sa&&oa.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")}),oa.map((te,ke)=>n.jsxs("button",{ref:Le=>{ke===Ks&&Le&&Le.scrollIntoView({block:"nearest"})},onClick:()=>Oe(te.name),onMouseEnter:()=>Es(ke),className:`w-full text-left px-4 py-2 text-sm flex items-center gap-2 transition-colors ${ke===Ks?"bg-brand-500/15 text-brand-500":"text-fg-secondary hover:bg-surface-overlay"}`,children:[n.jsx(gr,{name:te.name,avatarUrl:te.avatarUrl,size:24,bgClass:"bg-brand-500/20 text-brand-500"}),n.jsx("span",{className:"flex-1 min-w-0",children:te.name}),n.jsx("span",{className:"text-xs text-fg-tertiary ml-auto",children:te.role})]},te.id))]}),Ft.length>0&&n.jsxs("div",{className:"flex items-center gap-2 mb-2 overflow-x-auto pb-1",children:[Ft.map(te=>n.jsxs("div",{className:"relative group/img shrink-0",children:[rs(te)?n.jsx("img",{src:te.dataUrl,alt:te.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:te.name,children:[n.jsx("span",{className:"text-xl leading-none",children:Cd(te.name,te.dataUrl)}),n.jsx("span",{className:"text-[9px] text-fg-tertiary truncate max-w-[56px] px-0.5",children:te.name.split(".").pop()?.toUpperCase()})]}),n.jsx("button",{onClick:()=>Bh(te.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:"×"})]},te.id)),Ft.length<Mn&&n.jsx("button",{onClick:()=>_n.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"})})})]}),Ft.length>0&&Ft.some(te=>rs(te))&&Qr&&Qr.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:_n,type:"file",accept:"image/*,.pdf,.docx,.xlsx,.pptx,.xls,.doc,.csv,.json,.xml,.html,.epub",multiple:!0,className:"hidden",onChange:te=>{te.target.files&&bl(te.target.files),te.target.value=""}}),Rt&&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:Rt.sender}),n.jsx("p",{className:"text-[11px] text-fg-tertiary truncate",children:Rt.text})]}),n.jsx("button",{onClick:()=>lt(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:()=>_n.current?.click(),disabled:_e==="direct"&&!fe,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:dn,value:nt,onChange:te=>{ie(te.target.value),Sn()},onKeyDown:te=>{if(sa&&oa.length>0){const ke=te.key==="ArrowUp"||te.ctrlKey&&te.key==="p",Le=te.key==="ArrowDown"||te.ctrlKey&&te.key==="n",Ie=te.key==="Enter"||te.key==="Tab",wt=te.key==="Escape";if(ke){te.preventDefault(),Es(We=>(We-1+oa.length)%oa.length);return}if(Le){te.preventDefault(),Es(We=>(We+1)%oa.length);return}if(Ie){te.preventDefault();const We=oa[Ks];We&&Oe(We.name);return}if(wt){te.preventDefault(),Pr(!1);return}}te.key==="Enter"&&!te.shiftKey&&(te.preventDefault(),ae())},onPaste:Hh,placeholder:S0,disabled:_e==="direct"&&!fe,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"}}),$e&&_e!=="dm"&&n.jsx("button",{onClick:Ni,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:()=>{ae()},disabled:_e==="direct"&&!fe||!nt.trim()&&Ft.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 Mk({agent:e,tasks:t,onViewProfile:r}){const{t:s}=kt(["team","common"]),[a,i]=b.useState(!1),l=b.useRef(null),d=b.useRef(null),u=e.status==="working",m=e.status==="error",p=!m&&!!e.lastError&&!!e.lastErrorAt&&Date.now()-new Date(e.lastErrorAt).getTime()<1800*1e3,h=u?t.find(C=>C.assignedAgentId===e.id&&C.status==="in_progress"):null,y=e.currentActivity;b.useEffect(()=>{if(!a)return;const C=k=>{l.current&&!l.current.contains(k.target)&&i(!1)};return document.addEventListener("mousedown",C),()=>document.removeEventListener("mousedown",C)},[a]),b.useLayoutEffect(()=>{if(!a||!d.current)return;const C=d.current,k=C.getBoundingClientRect(),N=window.innerWidth;k.right>N-8&&(C.style.left="auto",C.style.right="0"),k.left<8&&(C.style.left="0",C.style.right="auto");const j=N-16;k.width>j&&(C.style.width=`${j}px`)},[a]);const g=m?"bg-red-400 animate-pulse":p?"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"),S=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&&!p?"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":p?"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 ${g}`}),n.jsx("span",{className:`text-xs ${m?"text-red-500":p?"text-amber-600":u?"text-blue-500":"text-green-600"}`,children:v}),p&&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&&p&&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")}),h?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),Nt.navigate(Se.WORK,{openTask:h.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:h.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:S}),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 QK=[{value:"system",label:"System"},{value:"light",label:"Light"},{value:"dark",label:"Dark"},{value:"cyberpunk",label:"Cyberpunk"},{value:"mono",label:"Mono"}],Ib="markus-theme";function Dk(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 ZK(){try{const e=localStorage.getItem(Ib);if(e==="midnight")return localStorage.setItem(Ib,"dark"),"dark";if(e==="light"||e==="dark"||e==="system"||e==="cyberpunk"||e==="mono")return e}catch{}return"system"}function JK(){const[e,t]=b.useState(ZK),r=b.useCallback(s=>{t(s);try{localStorage.setItem(Ib,s)}catch{}Dk(s)},[]);return b.useEffect(()=>{Dk(e)},[e]),{mode:e,setMode:r}}const SS=[{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:"users",labelKey:"nav.users",adminOnly:!0},{id:"remote",labelKey:"nav.remote",adminOnly:!0}];function Rk(){const t=window.location.hash.slice(1).split("/");if(t[0]==="settings"&&t[1]){const r=t[1];if(SS.some(s=>s.id===r))return r}return null}function Lk({theme:e,onThemeChange:t,authUser:r,onLogout:s,onUserUpdated:a}={}){const{t:i,i18n:l}=kt(["settings","common"]),d=ks(),[u,m]=b.useState(!1),[p,h]=b.useState(!1),y=b.useRef(null),[g,v]=b.useState(Rk);b.useEffect(()=>{const ie=()=>v(Rk());return window.addEventListener("hashchange",ie),()=>window.removeEventListener("hashchange",ie)},[]);const S=b.useCallback(ie=>{v(ie),history.pushState(null,"",`#settings/${ie}`)},[]),C=b.useCallback(()=>{v(null),history.pushState(null,"","#settings")},[]),k=g??(d?null:"appearance");b.useEffect(()=>{const ie=()=>h(!0);return window.addEventListener("markus:open-edit-profile",ie),()=>window.removeEventListener("markus:open-edit-profile",ie)},[]),b.useEffect(()=>{if(!u)return;const ie=Oe=>{y.current&&!y.current.contains(Oe.target)&&m(!1)};return document.addEventListener("mousedown",ie),()=>document.removeEventListener("mousedown",ie)},[u]);const[N,j]=b.useState(null),[T,R]=b.useState(null),[M,_]=b.useState(""),[F,z]=b.useState(!1),[L,U]=b.useState(null),[K,q]=b.useState(null),[I,D]=b.useState(null),[E,$]=b.useState(null),[Y,W]=b.useState(!1),[O,H]=b.useState(null),[Z,B]=b.useState(null),[J,Q]=b.useState(!1),[ee,se]=b.useState(null),[X,me]=b.useState({}),[je,Re]=b.useState(!1),[Ee,we]=b.useState(null),[pe,Pe]=b.useState(!1),[Ae,Xe]=b.useState(""),[Ze,at]=b.useState(!1),[pt,Ct]=b.useState(null),[_e,ue]=b.useState([]),[fe,Me]=b.useState([]),[ne,he]=b.useState(null),[Be,de]=b.useState(null),[Ce,et]=b.useState(""),[it,Ve]=b.useState(null),Ge=b.useRef(null),ut=b.useRef(!1),[nt,ft]=b.useState(!1),[Rt,lt]=b.useState(200),[$e,ct]=b.useState(!1),[Ut,zt]=b.useState(null),[cn,Ln]=b.useState(!1),[Xt,kn]=b.useState(1),[tr,ir]=b.useState(!1),[gs,wr]=b.useState(null),[or,Ue]=b.useState(!1),[Lt,Zt]=b.useState(0),[Ft,lr]=b.useState(!0),[_n,dn]=b.useState(!1),[Sn,Cn]=b.useState(!1),[$r,Mr]=b.useState(9333),[hn,Ne]=b.useState(!1),[At,Vt]=b.useState(null),[rn,Jt]=b.useState(null),[Ot,Fn]=b.useState({serperApiKey:"",tavilyApiKey:"",bingApiKey:"",googleSearchApiKey:"",googleSearchCx:"",serpApiKey:"",braveApiKey:"",exaApiKey:"",bochaApiKey:""}),[$n,js]=b.useState(!1),[kr,xe]=b.useState(null),[Qe,xt]=b.useState(null),[Kt,on]=b.useState(!1),[en,un]=b.useState(new Set),[jn,Bn]=b.useState(null),[rr,Dr]=b.useState(!1),Bt=()=>({"Content-Type":"application/json",Authorization:`Bearer ${localStorage.getItem("markus_token")??""}`}),nr=b.useCallback(()=>{le.health().then(j).catch(()=>{}),fetch("/api/settings/llm").then(ie=>ie.ok?ie.json():Promise.reject(ie.status)).then(ie=>{ie&&typeof ie=="object"&&"providers"in ie&&(R(ie),_(ie.defaultProvider))}).catch(()=>{})},[]),Ir=b.useCallback(()=>{fetch("/api/settings/oauth/providers").then(ie=>ie.ok?ie.json():Promise.reject(ie.status)).then(ie=>ue(ie.providers??[])).catch(()=>{})},[]),cr=b.useCallback(()=>{fetch("/api/settings/oauth/profiles",{headers:Bt()}).then(ie=>ie.ok?ie.json():Promise.reject(ie.status)).then(ie=>Me(ie.profiles??[])).catch(()=>{})},[]),Va=b.useCallback(()=>{le.settings.getAgent().then(ie=>{ie&&typeof ie.maxToolIterations=="number"&&lt(ie.maxToolIterations),ie?.cognitive&&(Ln(ie.cognitive.enabled??!1),kn(ie.cognitive.maxDepth??1))}).catch(()=>{})},[]),Gr=b.useCallback(()=>{le.settings.getBrowser().then(ie=>{ie&&(Ue(ie.bringToFront??!1),Zt(ie.remoteDebuggingPort??0),lr(ie.autoCloseTabs??!0),dn(ie.autoClickAllowDialog??!1),Cn(ie.extensionConnected??!1),Mr(ie.extensionBridgePort??9333))}).catch(()=>{})},[]),$s=b.useCallback(()=>{le.settings.getSearch().then(ie=>{ie&&Jt(ie)}).catch(()=>{})},[]),Bs=b.useCallback(()=>{on(!0),le.system.storage().then(xt).catch(()=>{}).finally(()=>on(!1)),le.system.orphans().then(Bn).catch(()=>{})},[]);b.useEffect(()=>{nr(),Ir(),cr(),Va(),Gr(),$s(),Bs()},[nr,Ir,cr,Va,Gr,$s,Bs]),b.useEffect(()=>{const ie=()=>Bs();return window.addEventListener("markus:data-changed",ie),()=>window.removeEventListener("markus:data-changed",ie)},[Bs]);const sa=b.useCallback(async()=>{Q(!0),se(null),B(null),me({});try{const ie=await fetch("/api/settings/env-models",{headers:Bt()});if(!ie.ok){se({type:"err",text:i("envConfig.detectionFailedHttp",{status:ie.status})});return}const Oe=await ie.json();if(B(Oe),Oe.detected.length===0)se({type:"err",text:i("envConfig.noKeysFound")});else{const Je={};for(const Mn of Oe.detected)Je[Mn.provider]=!0;me(Je)}}catch{se({type:"err",text:i("envConfig.failedToDetect")})}finally{Q(!1)}},[i]),Pr=b.useCallback(async()=>{Pe(!0),Ct(null),we(null);try{const ie=await fetch("/api/settings/detect-ollama",{headers:Bt()});if(!ie.ok){Ct({type:"err",text:i("ollama.detectFailed")});return}const Oe=await ie.json();we(Oe),Oe.found&&Oe.models&&Oe.models.length>0?Xe(Oe.models[0].name):Oe.found||Ct({type:"err",text:Oe.error||i("ollama.notRunning")})}catch{Ct({type:"err",text:i("ollama.detectFailed")})}finally{Pe(!1)}},[i]),Wa=T?Object.values(T.providers).some(ie=>ie.configured):!1;b.useEffect(()=>{T&&!Wa&&!ut.current&&(ut.current=!0,sa(),Pr())},[T,Wa,sa,Pr]);const Vi=async()=>{if(!(!M||M===T?.defaultProvider)){z(!0),U(null);try{const ie=await fetch("/api/settings/llm",{method:"POST",headers:Bt(),body:JSON.stringify({defaultProvider:M})}),Oe=await ie.json();ie.ok?(R(Oe),U({type:"ok",text:i("defaultProvider.updated",{name:Oe.defaultProvider})})):U({type:"err",text:Oe.error??i("modelProviders.saveFailed")})}catch{U({type:"err",text:i("common:networkError")})}finally{z(!1)}}},Ks=async(ie,Oe)=>{D(ie);try{const Je=await fetch(`/api/settings/llm/providers/${ie}/toggle`,{method:"POST",headers:Bt(),body:JSON.stringify({enabled:Oe})});if(Je.ok){const Mn=await Je.json();R(Mn)}}catch{}finally{D(null)}},Es=async()=>{W(!0),H(null);try{const Oe=await(await fetch("/api/settings/import/openclaw",{method:"POST",headers:Bt(),body:JSON.stringify({preview:!0})})).json();"error"in Oe?H({type:"err",text:Oe.error}):$(Oe)}catch{H({type:"err",text:i("openClaw.detectFailed")})}finally{W(!1)}},dr=async()=>{W(!0),H(null);try{const Oe=await(await fetch("/api/settings/import/openclaw",{method:"POST",headers:Bt(),body:JSON.stringify({preview:!1})})).json();"error"in Oe?H({type:"err",text:Oe.error}):(H({type:"ok",text:i("openClaw.importedFrom",{count:Oe.appliedModels})}),nr())}catch{H({type:"err",text:i("openClaw.importFailed")})}finally{W(!1)}},va=async()=>{if(!Z)return;const ie=Z.detected.filter(Oe=>X[Oe.provider]);if(ie.length===0){se({type:"err",text:i("envConfig.selectAtLeastOne")});return}Re(!0),se(null);try{const Oe=await fetch("/api/settings/env-models",{method:"POST",headers:Bt(),body:JSON.stringify({providers:ie.map(Mn=>({provider:Mn.provider,model:Mn.model,baseUrl:Mn.baseUrl,enabled:!0}))})});if(!Oe.ok){se({type:"err",text:i("envConfig.applyFailed",{status:Oe.status})});return}const Je=await Oe.json();se({type:"ok",text:Je.message}),B(null),me({}),nr()}catch{se({type:"err",text:i("envConfig.failedToApply")})}finally{Re(!1)}},Hs=async()=>{if(!(!Ee?.found||!Ae)){at(!0),Ct(null);try{const ie=await fetch("/api/settings/llm/providers",{method:"POST",headers:Bt(),body:JSON.stringify({name:"ollama",model:Ae,baseUrl:Ee.baseUrl||"http://localhost:11434"})});if(ie.ok){const Oe=await ie.json();R(Oe),Ct({type:"ok",text:i("ollama.configured",{model:Ae})}),we(null)}else{const Oe=await ie.json();Ct({type:"err",text:Oe.error||i("ollama.applyFailed")})}}catch{Ct({type:"err",text:i("ollama.applyFailed")})}finally{at(!1)}}};b.useEffect(()=>()=>{Ge.current&&clearInterval(Ge.current)},[]),b.useEffect(()=>{if(k!=="browser"||Sn)return;const ie=setInterval(async()=>{try{(await le.settings.getBrowser()).extensionConnected&&(Cn(!0),clearInterval(ie))}catch{}},5e3);return()=>clearInterval(ie)},[k,Sn]);const[xs,li]=b.useState(!1),[yn,xr]=b.useState({name:"",apiKey:"",baseUrl:"",model:"",contextWindow:128e3,maxOutputTokens:16384,costInput:1,costOutput:5}),[ci,wa]=b.useState(!1),[Ms,Rr]=b.useState(null),[ji,vn]=b.useState(null),[Kn,Yr]=b.useState({apiKey:"",baseUrl:"",model:"",contextWindow:0,maxOutputTokens:0,costInput:0,costOutput:0}),[Ds,ka]=b.useState(!1),[ja,Ns]=b.useState(null),[Gs,Na]=b.useState(""),[di,Ka]=b.useState(!1),[Xr,Cr]=b.useState(null),[Br,Ss]=b.useState(null),[An,Hr]=b.useState({id:"",name:"",contextWindow:128e3,maxOutputTokens:16384,costInput:1,costOutput:5,reasoning:!1,vision:!1}),[Sa,Cs]=b.useState(!1),aa=async()=>{if(!(!yn.name||!yn.model)){wa(!0),Rr(null);try{const ie=await fetch("/api/settings/llm/providers",{method:"POST",headers:Bt(),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})}),Oe=await ie.json();ie.ok?(R(Oe),li(!1),xr({name:"",apiKey:"",baseUrl:"",model:"",contextWindow:128e3,maxOutputTokens:16384,costInput:1,costOutput:5}),Rr({type:"ok",text:i("modelProviders.providerAdded",{name:yn.name})})):Rr({type:"err",text:Oe.error??i("modelProviders.failedToAdd")})}catch{Rr({type:"err",text:i("common:networkError")})}finally{wa(!1)}}},Ca=async(ie,Oe)=>{if(!Gs.trim())return;Ka(!0),Cr(null);const Je=Oe.models?.[0]?.id??ie;try{const Mn=await fetch("/api/settings/llm/providers",{method:"POST",headers:Bt(),body:JSON.stringify({name:ie,apiKey:Gs.trim(),model:Je})}),ia=await Mn.json();Mn.ok?(R(ia),Na(""),Cr({type:"ok",text:i("modelProviders.quickSetupSuccess",{name:Oe.displayName??ie})})):Cr({type:"err",text:ia.error??i("modelProviders.failedToAdd")})}catch{Cr({type:"err",text:i("common:networkError")})}finally{Ka(!1)}},Ys=(ie,Oe)=>{vn(ie),Yr({apiKey:"",baseUrl:Oe.baseUrl??"",model:Oe.model,contextWindow:Oe.contextWindow??0,maxOutputTokens:Oe.maxOutputTokens??0,costInput:Oe.cost?.input??0,costOutput:Oe.cost?.output??0})},Ga=async ie=>{ka(!0);try{const Oe={};Kn.apiKey&&(Oe.apiKey=Kn.apiKey),Kn.baseUrl!==void 0&&(Oe.baseUrl=Kn.baseUrl),Kn.model&&(Oe.model=Kn.model),Kn.contextWindow&&(Oe.contextWindow=Kn.contextWindow),Kn.maxOutputTokens&&(Oe.maxOutputTokens=Kn.maxOutputTokens),(Kn.costInput||Kn.costOutput)&&(Oe.cost={input:Kn.costInput,output:Kn.costOutput});const Je=await fetch(`/api/settings/llm/providers/${ie}`,{method:"PUT",headers:Bt(),body:JSON.stringify(Oe)});if(Je.ok){const Mn=await Je.json();R(Mn),vn(null)}}catch{}finally{ka(!1)}},To=async ie=>{Ns(ie);try{const Oe=await fetch(`/api/settings/llm/providers/${ie}`,{method:"DELETE",headers:Bt()});if(Oe.ok){const Je=await Oe.json();R(Je),_(Je.defaultProvider)}}catch{}finally{Ns(null)}},ui=async ie=>{if(!(!An.id||!An.name)){Cs(!0);try{const Oe=await fetch(`/api/settings/llm/providers/${ie}/models`,{method:"POST",headers:Bt(),body:JSON.stringify({id:An.id,name:An.name,contextWindow:An.contextWindow,maxOutputTokens:An.maxOutputTokens,cost:{input:An.costInput,output:An.costOutput},reasoning:An.reasoning||void 0,inputTypes:An.vision?["text","image"]:["text"]})});if(Oe.ok){const Je=await Oe.json();R(Je),Ss(null),Hr({id:"",name:"",contextWindow:128e3,maxOutputTokens:16384,costInput:1,costOutput:5,reasoning:!1,vision:!1})}}catch{}finally{Cs(!1)}}},Wi=async(ie,Oe)=>{try{const Je=await fetch(`/api/settings/llm/providers/${ie}/models/${encodeURIComponent(Oe)}`,{method:"DELETE",headers:Bt()});if(Je.ok){const Mn=await Je.json();R(Mn)}}catch{}},Ta=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"]),[Ni,ae]=b.useState(null),[Ye,dt]=b.useState(null),[Et,sn]=b.useState({}),pr=async ie=>{dt(ie),sn(Oe=>{const Je={...Oe};return delete Je[ie],Je});try{const Oe=await fetch(`/api/settings/llm/providers/${ie}/test`,{method:"POST",headers:Bt()});if(!Oe.ok){const Mn=await Oe.json().catch(()=>({}));sn(ia=>({...ia,[ie]:{ok:!1,error:Mn.error??`HTTP ${Oe.status}`,errorCode:Oe.status}}));return}const Je=await Oe.json();sn(Mn=>({...Mn,[ie]:Je}))}catch{sn(Oe=>({...Oe,[ie]:{ok:!1,error:i("common:networkError")}}))}finally{dt(null)}},En=async(ie,Oe)=>{ae(`${ie}:${Oe}`);try{const Je=await fetch(`/api/settings/llm/providers/${ie}/model`,{method:"POST",headers:Bt(),body:JSON.stringify({model:Oe})});if(Je.ok){const Mn=await Je.json();R(Mn)}}catch{}finally{ae(null)}},Dt=async()=>{if(Ot.serperApiKey||Ot.tavilyApiKey||Ot.bingApiKey||Ot.googleSearchApiKey||Ot.googleSearchCx||Ot.serpApiKey||Ot.braveApiKey||Ot.exaApiKey||Ot.bochaApiKey){js(!0),xe(null);try{const Oe={};Ot.serperApiKey&&(Oe.serperApiKey=Ot.serperApiKey),Ot.tavilyApiKey&&(Oe.tavilyApiKey=Ot.tavilyApiKey),Ot.bingApiKey&&(Oe.bingApiKey=Ot.bingApiKey),Ot.googleSearchApiKey&&(Oe.googleSearchApiKey=Ot.googleSearchApiKey),Ot.googleSearchCx&&(Oe.googleSearchCx=Ot.googleSearchCx),Ot.serpApiKey&&(Oe.serpApiKey=Ot.serpApiKey),Ot.braveApiKey&&(Oe.braveApiKey=Ot.braveApiKey),Ot.exaApiKey&&(Oe.exaApiKey=Ot.exaApiKey),Ot.bochaApiKey&&(Oe.bochaApiKey=Ot.bochaApiKey);const Je=await le.settings.updateSearch(Oe);Jt(Je),Fn({serperApiKey:"",tavilyApiKey:"",bingApiKey:"",googleSearchApiKey:"",googleSearchCx:"",serpApiKey:"",braveApiKey:"",exaApiKey:"",bochaApiKey:""}),xe({type:"ok",text:i("searchApi.saved")})}catch{xe({type:"err",text:i("searchApi.failedToSave")})}finally{js(!1)}}},Rs=T?.providers?Object.entries(T.providers).filter(([,ie])=>ie.configured&&ie.enabled).map(([ie])=>ie):[],Ls=T&&!Wa&&!nt,Fs=r?.role==="owner"||r?.role==="admin",Fr=SS.filter(ie=>!ie.adminOnly||Fs);return n.jsxs("div",{className:"flex-1 flex overflow-hidden",children:[p&&r&&n.jsx(sG,{authUser:r,onClose:()=>h(!1),onSaved:ie=>{h(!1),a?.(ie)}}),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:()=>{Nt.navigate(Se.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:Fr.map(ie=>n.jsx("button",{onClick:()=>S(ie.id),className:`w-full text-left px-3 py-2 rounded-lg text-sm transition-colors ${k===ie.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:${ie.labelKey}`)},ie.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(gr,{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),h(!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&&k===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:()=>Nt.navigate(Se.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:Fr.map(ie=>n.jsxs("button",{onClick:()=>S(ie.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:${ie.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"})})]},ie.id))})]}),d&&k!==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:${Fr.find(ie=>ie.id===k)?.labelKey||"title"}`)})]}),k!==null&&n.jsxs("div",{className:"p-7 space-y-10 max-w-4xl mx-auto w-full",children:[k==="appearance"&&n.jsx(si,{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:QK.map(({value:ie})=>n.jsx("button",{onClick:()=>t?.(ie),className:`px-3 py-1.5 text-xs rounded-md transition-colors ${e===ie?"bg-brand-600 text-white":"text-fg-secondary hover:text-fg-primary"}`,children:i(`appearance.modes.${ie}`)},ie))})]}),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:tw.map(({code:ie,label:Oe})=>n.jsx("button",{onClick:()=>{l.changeLanguage(ie)},className:`px-3 py-1.5 text-xs rounded-md transition-colors ${l.language===ie||ie==="en"&&!tw.some(Je=>Je.code===l.language)?"bg-brand-600 text-white":"text-fg-secondary hover:text-fg-primary"}`,children:Oe},ie))})]})]})}),Fs&&n.jsxs(n.Fragment,{children:[k==="providers"&&n.jsxs(n.Fragment,{children:[Ls&&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:()=>ft(!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(yu,{step:i("setupGuide.fromEnv.step"),title:i("setupGuide.fromEnv.title"),description:i("setupGuide.fromEnv.description"),active:!!(Z&&Z.detected.length>0),children:[J&&n.jsx("div",{className:"text-xs text-fg-tertiary",children:i("common:detecting")}),Z&&Z.detected.length>0&&n.jsxs("div",{className:"space-y-2",children:[Z.detected.map(ie=>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:X[ie.provider]??!1,onChange:Oe=>me({...X,[ie.provider]:Oe.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:ie.displayName}),n.jsx("span",{className:"text-xs text-fg-tertiary ml-2",children:ie.model})]}),n.jsx("code",{className:"text-[10px] text-fg-tertiary",children:ie.apiKeyPreview})]},ie.provider)),n.jsx("button",{onClick:()=>{va()},disabled:je||Object.values(X).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:je?i("common:applying"):i("setupGuide.applyProviders",{count:Object.values(X).filter(Boolean).length})})]}),Z&&Z.detected.length===0&&n.jsx("div",{className:"text-xs text-fg-tertiary",children:n.jsx(Fu,{i18nKey:"settings:setupGuide.fromEnv.noKeysHint",components:{code:n.jsx("code",{className:"text-fg-secondary"})}})}),ee&&n.jsx(Oa,{type:ee.type,text:ee.text})]}),n.jsxs(yu,{step:i("setupGuide.fromOllama.step"),title:i("setupGuide.fromOllama.title"),description:i("setupGuide.fromOllama.description"),active:!!Ee?.found,children:[pe&&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:Ae,onChange:ie=>Xe(ie.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(ie=>n.jsxs("option",{value:ie.name,children:[ie.name,ie.parameterSize?` (${ie.parameterSize})`:"",ie.family?` — ${ie.family}`:""]},ie.name))}),n.jsx("button",{onClick:()=>{Hs()},disabled:Ze||!Ae,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:Ze?i("common:applying"):i("ollama.useModel",{model:Ae})})]}),!pe&&!Ee&&n.jsx("button",{onClick:()=>{Pr()},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")}),pt&&n.jsx(Oa,{type:pt.type,text:pt.text})]}),n.jsxs(yu,{step:i("setupGuide.fromOpenClaw.step"),title:i("setupGuide.fromOpenClaw.title"),description:i("setupGuide.fromOpenClaw.description"),children:[E?E.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:E.summary.configPath})]}),E.summary.models&&n.jsx("div",{className:"text-xs text-fg-secondary",children:i("openClaw.providersModels",{providers:E.summary.models.providerCount,models:E.summary.models.providers.reduce((ie,Oe)=>ie+Oe.modelCount,0)})}),n.jsx("button",{onClick:()=>{dr()},disabled:Y,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(Y?"common:importing":"openClaw.importConfigs")})]}):n.jsx("div",{className:"text-xs text-fg-tertiary",children:i("openClaw.notFound")}):n.jsx("button",{onClick:()=>{Es()},disabled:Y,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(Y?"common:detecting":"openClaw.detectShort")}),O&&n.jsx(Oa,{type:O.type,text:O.text})]}),n.jsx(yu,{step:i("setupGuide.manual.step"),title:i("setupGuide.manual.title"),description:n.jsx(Fu,{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(yu,{step:i("setupGuide.browserExtension.step"),title:i("setupGuide.browserExtension.title"),description:i("setupGuide.browserExtension.description"),active:Sn,children:Sn?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:hn,onClick:async()=>{Ne(!0);try{await le.settings.downloadExtensionZip()}catch{}Ne(!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")]}),n.jsxs("button",{disabled:hn,onClick:async()=>{try{await le.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(si,{title:i("systemStatus.title"),children:N?n.jsxs("div",{className:"grid grid-cols-3 gap-4",children:[n.jsx(Ax,{label:i("systemStatus.status"),value:N.status==="ok"?i("systemStatus.healthy"):N.status,color:"green"}),n.jsx(Ax,{label:i("systemStatus.version"),value:N.version,color:"indigo"}),n.jsx(Ax,{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(si,{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:M,onChange:ie=>{_(ie.target.value),U(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:Rs.length>0?Rs.map(ie=>n.jsx("option",{value:ie,children:T.providers[ie]?.displayName??ie},ie)):n.jsx("option",{value:"",children:i("defaultProvider.noProviders")})}):n.jsx("div",{className:"text-xs text-fg-tertiary",children:i("common:loading")}),M!==T?.defaultProvider&&n.jsx("button",{onClick:()=>{Vi()},disabled:F,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(F?"common:saving":"common:save")})]})]}),L&&n.jsx(Oa,{type:L.type,text:L.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 ie=!(T?.autoFallback??!0);try{const Oe=await fetch("/api/settings/llm",{method:"POST",headers:Bt(),body:JSON.stringify({autoFallback:ie})});if(Oe.ok){const Je=await Oe.json();R(Je)}}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(si,{title:i("modelProviders.title"),children:[n.jsx("div",{className:"space-y-3",children:T&&Object.entries(T.providers).map(([ie,Oe])=>n.jsxs("div",{className:`bg-surface-secondary border rounded-xl overflow-hidden transition-colors ${Oe.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:()=>{q(K===ie?null:ie),Na(""),Cr(null)},children:[n.jsxs("div",{className:"flex items-center gap-3",children:[n.jsx("span",{className:`w-2 h-2 rounded-full ${Oe.configured&&Oe.enabled?"bg-green-400":Oe.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:Oe.displayName??ie}),ie===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")}),Oe.configured&&!Oe.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")}),Oe.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")}),Et[ie]?.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:Et[ie].durationMs})}),Et[ie]?.ok===!1&&n.jsx("span",{className:"text-[10px] bg-red-500/15 text-red-500 px-1.5 py-0.5 rounded",title:Et[ie].error,children:Et[ie].errorCode?i("modelProviders.testFailedCode",{code:Et[ie].errorCode}):i("modelProviders.testFailed")})]}),n.jsx("div",{className:"text-xs text-fg-tertiary mt-0.5",children:Oe.configured?n.jsxs(n.Fragment,{children:[Oe.model,Oe.apiKeyPreview&&n.jsxs(n.Fragment,{children:[" · ",n.jsx("code",{className:"text-fg-secondary",children:Oe.apiKeyPreview})]})]}):i("modelProviders.notConfigured")})]})]}),n.jsxs("div",{className:"flex items-center gap-4",children:[Oe.configured&&n.jsx("button",{onClick:Je=>{Je.stopPropagation(),Ks(ie,!Oe.enabled)},disabled:I===ie,className:`relative inline-flex h-5 w-9 items-center rounded-full transition-colors ${Oe.enabled?"bg-green-500":"bg-gray-600"} ${I===ie?"opacity-50":""}`,title:Oe.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 ${Oe.enabled?"translate-x-4":"translate-x-1"}`})}),Oe.contextWindow&&n.jsx("span",{className:"text-[10px] text-fg-tertiary",children:i("modelProviders.ctxTokens",{size:(Oe.contextWindow/1e3).toFixed(0)})}),Oe.cost&&n.jsx("span",{className:"text-[10px] text-fg-tertiary",children:i("modelProviders.costPerMillion",{input:Oe.cost.input,output:Oe.cost.output})}),n.jsx("span",{className:"text-fg-tertiary text-xs",children:K===ie?"▲":"▼"})]})]}),K===ie&&n.jsxs("div",{className:"px-5 pb-4 border-t border-border-default pt-4 space-y-4",children:[Oe.configured&&n.jsxs(n.Fragment,{children:[n.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-3",children:[n.jsx(el,{label:i("modelProviders.model"),value:Oe.model}),n.jsx(el,{label:i("modelProviders.contextWindow"),value:Oe.contextWindow?i("modelProviders.kTokens",{k:(Oe.contextWindow/1e3).toFixed(0)}):i("modelProviders.notApplicable")}),n.jsx(el,{label:i("modelProviders.maxOutput"),value:Oe.maxOutputTokens?i("modelProviders.kTokens",{k:(Oe.maxOutputTokens/1e3).toFixed(0)}):i("modelProviders.notApplicable")}),n.jsx(el,{label:i("modelProviders.baseUrlLabel"),value:Oe.baseUrl??i("modelProviders.baseUrlDisplayDefault")})]}),ji===ie?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:Kn.apiKey,onChange:Je=>Yr({...Kn,apiKey:Je.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:Kn.baseUrl,onChange:Je=>Yr({...Kn,baseUrl:Je.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:Kn.model,onChange:Je=>Yr({...Kn,model:Je.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:Kn.contextWindow||"",onChange:Je=>Yr({...Kn,contextWindow:Number(Je.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:Kn.maxOutputTokens||"",onChange:Je=>Yr({...Kn,maxOutputTokens:Number(Je.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:Kn.costInput||"",onChange:Je=>Yr({...Kn,costInput:Number(Je.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:Kn.costOutput||"",onChange:Je=>Yr({...Kn,costOutput:Number(Je.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:()=>{Ga(ie)},disabled:Ds,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(Ds?"common:saving":"common:save")}),n.jsx("button",{onClick:()=>vn(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:Je=>{Je.stopPropagation(),pr(ie)},disabled:Ye===ie,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:Ye===ie?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:Je=>{Je.stopPropagation(),Ys(ie,Oe)},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:Je=>{Je.stopPropagation(),confirm(i("modelProviders.deleteConfirm",{name:Oe.displayName??ie}))&&To(ie)},disabled:ja===ie,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(ja===ie?"common:deleting":"common:delete")})]}),Et[ie]&&n.jsx("div",{className:`text-xs px-3 py-2 rounded-lg ${Et[ie].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:Et[ie].ok?i("modelProviders.testSuccess",{ms:Et[ie].durationMs,reply:Et[ie].reply}):Et[ie].error})]}),Oe.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(el,{label:i("modelProviders.input"),value:`$${Oe.cost.input}`}),n.jsx(el,{label:i("modelProviders.output"),value:`$${Oe.cost.output}`}),Oe.cost.cacheRead!=null&&n.jsx(el,{label:i("modelProviders.cacheRead"),value:`$${Oe.cost.cacheRead}`}),Oe.cost.cacheWrite!=null&&n.jsx(el,{label:i("modelProviders.cacheWrite"),value:`$${Oe.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")}),Oe.configured&&Br!==ie&&n.jsx("button",{onClick:()=>{Ss(ie),Hr({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")})]}),Br===ie&&n.jsxs("div",{className:"bg-surface-elevated/40 rounded-lg p-3 mb-2 space-y-2",children:[n.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-2",children:[n.jsx("input",{type:"text",placeholder:i("modelProviders.modelId"),value:An.id,onChange:Je=>Hr({...An,id:Je.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:i("modelProviders.displayName"),value:An.name,onChange:Je=>Hr({...An,name:Je.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:i("modelProviders.placeholderContextTokens"),value:An.contextWindow,onChange:Je=>Hr({...An,contextWindow:Number(Je.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:i("modelProviders.maxOutput"),value:An.maxOutputTokens,onChange:Je=>Hr({...An,maxOutputTokens:Number(Je.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:i("modelProviders.costPerMillionIn")}),n.jsx("input",{type:"number",step:"0.01",value:An.costInput,onChange:Je=>Hr({...An,costInput:Number(Je.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:i("modelProviders.costPerMillionOut")}),n.jsx("input",{type:"number",step:"0.01",value:An.costOutput,onChange:Je=>Hr({...An,costOutput:Number(Je.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:An.reasoning,onChange:Je=>Hr({...An,reasoning:Je.target.checked}),className:"rounded"}),i("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:An.vision,onChange:Je=>Hr({...An,vision:Je.target.checked}),className:"rounded"}),i("modelProviders.vision")]}),n.jsx("div",{className:"flex-1"}),n.jsx("button",{onClick:()=>{ui(ie)},disabled:Sa||!An.id||!An.name,className:"px-2 py-1 text-[10px] bg-brand-600 hover:bg-brand-500 disabled:opacity-40 text-white rounded transition-colors",children:i(Sa?"modelProviders.adding":"common:create")}),n.jsx("button",{onClick:()=>Ss(null),className:"px-2 py-1 text-[10px] border border-border-default text-fg-secondary hover:bg-surface-elevated rounded transition-colors",children:i("common:cancel")})]})]}),Oe.models&&Oe.models.length>0&&n.jsx("div",{className:"space-y-1.5",children:Oe.models.map(Je=>{const Mn=Je.id===Oe.model,ia=Ni===`${ie}:${Je.id}`,Aa=!Ta.has(Je.id);return n.jsxs("div",{className:`flex items-center justify-between px-3 py-2 rounded-lg text-xs transition-colors ${Mn?"bg-brand-500/15 border border-brand-500/30":Oe.configured?"bg-surface-elevated/30 hover:bg-surface-elevated/60 cursor-pointer":"bg-surface-elevated/30"}`,onClick:()=>{!Mn&&Oe.configured&&!ia&&En(ie,Je.id)},children:[n.jsxs("div",{className:"flex items-center gap-2",children:[Mn&&n.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-brand-500 shrink-0"}),n.jsx("span",{className:Mn?"text-brand-500 font-medium":"text-fg-secondary",children:Je.name}),Je.reasoning&&n.jsx("span",{className:"text-[9px] bg-amber-500/15 text-amber-600 px-1 py-0.5 rounded",children:i("modelProviders.reasoning")}),Je.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")}),Aa&&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:[n.jsx("span",{children:i("modelProviders.ctxTokens",{size:(Je.contextWindow/1e3).toFixed(0)})}),n.jsx("span",{children:i("modelProviders.costPair",{input:Je.cost.input,output:Je.cost.output})}),Oe.configured&&!Mn&&n.jsx("span",{className:`text-[9px] px-1.5 py-0.5 rounded transition-colors ${ia?"bg-brand-500/30 text-brand-400":"bg-surface-overlay text-fg-tertiary hover:bg-brand-500/20 hover:text-brand-500"}`,children:i(ia?"modelProviders.switching":"modelProviders.use")}),Mn&&n.jsx("span",{className:"text-[9px] bg-brand-500/15 text-brand-500 px-1.5 py-0.5 rounded",children:i("modelProviders.active")}),Aa&&!Mn&&n.jsx("button",{onClick:rs=>{rs.stopPropagation(),Wi(ie,Je.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"})})})]})]},Je.id)})})]}),!Oe.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",{className:"flex items-center gap-2",children:[n.jsx("input",{type:"password",value:K===ie?Gs:"",onChange:Je=>Na(Je.target.value),placeholder:i("modelProviders.quickSetupPlaceholder"),className:"flex-1 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",onKeyDown:Je=>{Je.key==="Enter"&&Gs.trim()&&Ca(ie,Oe)}}),n.jsx("button",{onClick:()=>{Ca(ie,Oe)},disabled:di||!Gs.trim(),className:"px-4 py-2 text-sm bg-brand-600 hover:bg-brand-500 disabled:opacity-40 text-white rounded-lg transition-colors whitespace-nowrap",children:i(di?"modelProviders.quickSetupSaving":"modelProviders.quickSetupSubmit")})]}),Xr&&K===ie&&n.jsx(Oa,{type:Xr.type,text:Xr.text})]})]})]},ie))}),xs?n.jsxs("div",{className:"mt-3 bg-surface-secondary border border-brand-500/30 rounded-xl p-5 space-y-4",children:[n.jsx("div",{className:"text-sm font-medium text-fg-primary",children:i("modelProviders.addNewProvider")}),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,onChange:ie=>xr({...yn,name:ie.target.value}),placeholder:i("modelProviders.placeholderProviderName"),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.jsx("div",{className:"text-[10px] text-fg-tertiary mt-1",children:i("modelProviders.providerNameHint")})]}),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:ie=>xr({...yn,apiKey:ie.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.baseUrl")}),n.jsx("input",{type:"text",value:yn.baseUrl,onChange:ie=>xr({...yn,baseUrl:ie.target.value}),placeholder:i("modelProviders.placeholderBaseUrl"),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:ie=>xr({...yn,model:ie.target.value}),placeholder:i("modelProviders.placeholderDefaultModel"),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-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:yn.contextWindow,onChange:ie=>xr({...yn,contextWindow:Number(ie.target.value)}),placeholder:"128000",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.maxOutputTokens")}),n.jsx("input",{type:"number",value:yn.maxOutputTokens,onChange:ie=>xr({...yn,maxOutputTokens:Number(ie.target.value)}),placeholder:"16384",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.inputCost")}),n.jsx("input",{type:"number",step:"0.01",value:yn.costInput,onChange:ie=>xr({...yn,costInput:Number(ie.target.value)}),placeholder:"1",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.outputCost")}),n.jsx("input",{type:"number",step:"0.01",value:yn.costOutput,onChange:ie=>xr({...yn,costOutput:Number(ie.target.value)}),placeholder:"5",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:()=>{aa()},disabled:ci||!yn.name||!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(ci?"modelProviders.adding":"modelProviders.addProviderSubmit")}),n.jsx("button",{onClick:()=>{li(!1),Rr(null)},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")})]}),Ms&&n.jsx(Oa,{type:Ms.type,text:Ms.text})]}):n.jsx("button",{onClick:()=>li(!0),className:"w-full mt-3 px-4 py-3 border border-dashed border-border-default hover:border-brand-500/50 hover:bg-brand-500/5 rounded-xl text-sm text-fg-tertiary hover:text-brand-500 transition-colors",children:i("modelProviders.addProvider")})]}),n.jsx("div",{className:"border-t border-border-default"}),n.jsx(si,{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:()=>{sa()},disabled:J,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 ${J?"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(J?"common:detecting":"envConfig.refreshEnv")]})]}),Z&&Z.detected.length>0&&n.jsxs("div",{className:"space-y-2",children:[Z.detected.map(ie=>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:X[ie.provider]??!1,onChange:Oe=>me({...X,[ie.provider]:Oe.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:ie.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:ie.apiKeyPreview})," / ",i("envConfig.modelLabel")," ",n.jsx("code",{className:"text-fg-secondary",children:ie.model}),ie.baseUrl&&n.jsxs(n.Fragment,{children:[" / ",i("envConfig.urlLabel")," ",n.jsx("code",{className:"text-fg-secondary",children:ie.baseUrl})]})]})]})]}),n.jsx("div",{className:"text-xs text-fg-tertiary",children:Object.keys(ie.envVars).map(Oe=>n.jsx("div",{children:n.jsx("code",{children:Oe})},Oe))})]},ie.provider)),Z.timeoutMs&&n.jsx("div",{className:"text-xs text-fg-tertiary",children:i("envConfig.llmTimeout",{ms:Z.timeoutMs})}),n.jsx("button",{onClick:()=>{va()},disabled:je||Object.values(X).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:je?i("common:applying"):i("envConfig.applyToConfig",{count:Object.values(X).filter(Boolean).length})})]}),ee&&n.jsx(Oa,{type:ee.type,text:ee.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:()=>{Pr()},disabled:pe,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 ${pe?"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(pe?"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(ie=>n.jsx("label",{className:`flex items-center justify-between rounded-lg px-4 py-3 cursor-pointer transition-colors ${Ae===ie.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:ie.name,checked:Ae===ie.name,onChange:()=>Xe(ie.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:ie.name}),n.jsxs("div",{className:"text-xs text-fg-tertiary mt-0.5",children:[ie.parameterSize&&n.jsx("span",{children:ie.parameterSize}),ie.family&&n.jsx("span",{className:"ml-2",children:ie.family}),ie.quantization&&n.jsx("span",{className:"ml-2",children:ie.quantization}),ie.size&&n.jsx("span",{className:"ml-2",children:Bc(ie.size)})]})]})]})},ie.name))}),n.jsx("button",{onClick:()=>{Hs()},disabled:Ze||!Ae,className:"px-4 py-2 bg-brand-600 hover:bg-brand-500 disabled:opacity-40 text-white text-sm rounded-lg transition-colors",children:Ze?i("common:applying"):i("ollama.useModel",{model:Ae})})]}),Ee&&!Ee.found&&n.jsx("div",{className:"text-xs text-fg-tertiary",children:Ee.error||i("ollama.notRunning")}),pt&&n.jsx(Oa,{type:pt.type,text:pt.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:()=>{Es()},disabled:Y,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(Y?"common:detecting":"openClaw.detectShort")})]}),E&&E.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:E.summary.configPath})]}),E.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:E.summary.models.providerCount})}),n.jsx("div",{className:"space-y-1",children:E.summary.models.providers.map(ie=>n.jsxs("div",{className:"flex items-center justify-between text-xs",children:[n.jsx("span",{className:"text-fg-secondary",children:ie.name}),n.jsxs("span",{className:"text-fg-tertiary",children:[i("openClaw.modelsCountSuffix",{count:ie.modelCount}),ie.baseUrl?i("openClaw.withBaseUrl",{url:ie.baseUrl}):""]})]},ie.name))})]}),E.summary.channels&&E.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")," ",E.summary.channels.join(", ")]})}),n.jsx("button",{onClick:()=>{dr()},disabled:Y,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(Y?"common:importing":"openClaw.importConfigs")})]}),O&&n.jsx(Oa,{type:O.type,text:O.text})]})]})})]}),k==="execution"&&n.jsxs(n.Fragment,{children:[n.jsx(si,{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:Rt,onChange:ie=>{lt(Number(ie.target.value)),zt(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:$e,onClick:async()=>{ct(!0),zt(null);try{const ie=await le.settings.updateAgent({maxToolIterations:Rt});lt(ie.maxToolIterations),zt({type:"ok",text:i("agentExecution.saved")})}catch{zt({type:"err",text:i("agentExecution.failedToSave")})}ct(!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($e?"common:saving":"common:save")})]})]}),Ut&&n.jsx(Oa,{type:Ut.type,text:Ut.text})]})}),n.jsx(si,{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(!cn),wr(null)},className:`relative w-10 h-5 rounded-full transition-colors ${cn?"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 ${cn?"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:Xt,onChange:ie=>{kn(Number(ie.target.value)),wr(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:tr,onClick:async()=>{ir(!0),wr(null);try{const ie=await le.settings.updateAgent({cognitive:{enabled:cn,maxDepth:Xt}});Ln(ie.cognitive.enabled),kn(ie.cognitive.maxDepth??1),wr({type:"ok",text:i("cognitive.saved")})}catch{wr({type:"err",text:i("cognitive.failedToSave")})}ir(!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(tr?"common:saving":"common:save")})}),gs&&n.jsx(Oa,{type:gs.type,text:gs.text})]})})]}),k==="browser"&&n.jsxs(n.Fragment,{children:[n.jsxs(si,{title:i("browserAutomation.title"),children:[n.jsxs("div",{className:`rounded-xl p-4 mb-4 flex items-start gap-3 ${Sn?"bg-green-500/10 border border-green-500/20":Lt>0?"bg-blue-500/10 border border-blue-500/20":_n?"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 ${Sn?"bg-green-400":Lt>0?"bg-blue-400":_n?"bg-amber-400":"bg-gray-400"}`}),n.jsxs("div",{className:"flex-1 min-w-0",children:[n.jsx("div",{className:`text-sm font-semibold ${Sn?"text-green-400":Lt>0?"text-blue-400":_n?"text-amber-400":"text-fg-secondary"}`,children:Sn?i("browserAutomation.modeExtension"):Lt>0?i("browserAutomation.modeDebuggingPort",{port:Lt}):i(_n?"browserAutomation.modeAutoClick":"browserAutomation.modeManual")}),n.jsx("div",{className:"text-xs text-fg-tertiary mt-0.5",children:Sn?i("browserAutomation.modeExtensionDesc"):Lt>0?i("browserAutomation.modeDebuggingPortDesc"):i(_n?"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 ie=!or;Ue(ie),Ne(!0),Vt(null);try{const Oe=await le.settings.updateBrowser({bringToFront:ie});Ue(Oe.bringToFront),Vt({type:"ok",text:i(ie?"browserAutomation.tabsForeground":"browserAutomation.tabsBackground")})}catch{Vt({type:"err",text:i("agentExecution.failedToSave")}),Ue(!ie)}Ne(!1)},disabled:hn,className:`relative inline-flex h-5 w-9 items-center rounded-full transition-colors ${or?"bg-green-500":"bg-gray-600"} ${hn?"opacity-50":""}`,children:n.jsx("span",{className:`inline-block h-3.5 w-3.5 rounded-full bg-white transition-transform ${or?"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 ie=!Ft;lr(ie),Ne(!0),Vt(null);try{const Oe=await le.settings.updateBrowser({autoCloseTabs:ie});lr(Oe.autoCloseTabs),Vt({type:"ok",text:i("agentExecution.saved")})}catch{Vt({type:"err",text:i("agentExecution.failedToSave")}),lr(!ie)}Ne(!1)},disabled:hn,className:`relative inline-flex h-5 w-9 items-center rounded-full transition-colors ${Ft?"bg-green-500":"bg-gray-600"} ${hn?"opacity-50":""}`,children:n.jsx("span",{className:`inline-block h-3.5 w-3.5 rounded-full bg-white transition-transform ${Ft?"translate-x-4":"translate-x-1"}`})})]})]}),n.jsxs("div",{className:`rounded-xl p-5 mb-4 transition-colors ${Sn?"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 ${Sn?"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 ${Sn?"bg-green-400":"bg-gray-400"}`}),i(Sn?"browserAutomation.extensionConnected":"browserAutomation.extensionDisconnected")]})]}),n.jsx("div",{className:"text-xs text-fg-tertiary",children:i("browserAutomation.extensionStatusDesc")}),Sn?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:hn,onClick:async()=>{Ne(!0),Vt(null);try{await le.settings.downloadExtensionZip()}catch{Vt({type:"err",text:i("browserAutomation.extensionDownloadError")})}Ne(!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(hn?"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")}),n.jsxs("button",{disabled:hn,onClick:async()=>{Ne(!0),Vt(null);try{await le.settings.openExtensionsPage()}catch{Vt({type:"err",text:i("browserAutomation.extensionOpenError")})}Ne(!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")})]})]})]})]}),!Sn&&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:hn,onClick:async()=>{Ne(!0),Vt(null);try{const ie=await le.settings.testAutoClick(),Oe={success:{type:"ok",text:i("browserAutomation.autoClickTestSuccess",{title:ie.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:ie.error||"unknown"})}};Vt(Oe[ie.clickResult]??{type:"err",text:ie.clickResult})}catch{Vt({type:"err",text:i("browserAutomation.autoClickTestError",{error:"request failed"})})}Ne(!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(hn?"browserAutomation.autoClickTesting":"browserAutomation.autoClickTest")}),n.jsx("button",{onClick:async()=>{const ie=!_n;dn(ie),Ne(!0),Vt(null);try{const Oe=await le.settings.updateBrowser({autoClickAllowDialog:ie});dn(Oe.autoClickAllowDialog),Vt({type:"ok",text:i("agentExecution.saved")})}catch{Vt({type:"err",text:i("agentExecution.failedToSave")}),dn(!ie)}Ne(!1)},disabled:hn,className:`relative inline-flex h-5 w-9 items-center rounded-full transition-colors ${_n?"bg-green-500":"bg-gray-600"} ${hn?"opacity-50":""}`,children:n.jsx("span",{className:`inline-block h-3.5 w-3.5 rounded-full bg-white transition-transform ${_n?"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:Lt,onChange:ie=>{Zt(Number(ie.target.value)),Vt(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:hn,onClick:async()=>{Ne(!0),Vt(null);try{const ie=await le.settings.updateBrowser({remoteDebuggingPort:Lt});Zt(ie.remoteDebuggingPort),Vt({type:"ok",text:ie.remoteDebuggingPort>0?i("browserAutomation.usingPort",{port:ie.remoteDebuggingPort}):i("browserAutomation.usingAutoConnect")})}catch{Vt({type:"err",text:i("agentExecution.failedToSave")})}Ne(!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(hn?"common:saving":"common:save")})]})]})})]}),At&&n.jsx("div",{className:"mt-4",children:n.jsx(Oa,{type:At.type,text:At.text})})]}),!1]}),k==="search"&&n.jsx(n.Fragment,{children:n.jsx(si,{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((ie,Oe)=>n.jsxs("div",{className:Oe>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:ie.label}),n.jsx("div",{className:"text-xs text-fg-tertiary mt-0.5",children:ie.hint})]}),n.jsxs("div",{className:"flex items-center gap-2",children:[rn?.[ie.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:rn[ie.id].preview})]}),rn&&!rn[ie.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:Ot[ie.field],onChange:Je=>Fn({...Ot,[ie.field]:Je.target.value}),placeholder:rn?.[ie.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"}),ie.extraField&&n.jsx("input",{type:"text",value:Ot[ie.extraField],onChange:Je=>Fn({...Ot,[ie.extraField]:Je.target.value}),placeholder:ie.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"})]},ie.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:[kr&&n.jsx(Oa,{type:kr.type,text:kr.text}),!kr&&n.jsx("div",{}),n.jsx("button",{disabled:$n||!Ot.serperApiKey&&!Ot.tavilyApiKey&&!Ot.bingApiKey&&!Ot.googleSearchApiKey&&!Ot.googleSearchCx&&!Ot.serpApiKey&&!Ot.braveApiKey&&!Ot.exaApiKey&&!Ot.bochaApiKey,onClick:()=>{Dt()},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($n?"common:saving":"common:save")})]})]})})}),k==="storage"&&n.jsx(n.Fragment,{children:n.jsx(si,{title:i("dataStorage.title"),children:n.jsxs("div",{className:"bg-surface-elevated rounded-xl p-5 space-y-5",children:[Kt&&!Qe&&n.jsx("div",{className:"text-sm text-fg-tertiary",children:i("dataStorage.scanning")}),Qe&&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:Bc(Qe.totalSize,i)}),n.jsx("div",{className:"text-xs text-fg-tertiary font-mono mt-0.5",children:Qe.dataDir})]}),n.jsxs("div",{className:"flex gap-2",children:[n.jsx("button",{onClick:()=>Bs(),disabled:Kt,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(Kt?"dataStorage.scanning":"common:refresh")}),n.jsx("button",{onClick:()=>{le.system.openPath(Qe.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:Qe.breakdown.filter(ie=>ie.size>0).map(ie=>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:ie.name}),n.jsx("span",{className:"text-xs text-fg-tertiary ml-2",children:ie.description})]}),n.jsx("span",{className:"text-sm font-medium text-fg-secondary tabular-nums shrink-0 ml-3",children:Bc(ie.size,i)})]},ie.name))})]}),Qe.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:Qe.agents.length})}),n.jsx("div",{className:"space-y-1",children:Qe.agents.map(ie=>{const Oe=en.has(ie.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:()=>un(Je=>{const Mn=new Set(Je);return Mn.has(ie.id)?Mn.delete(ie.id):Mn.add(ie.id),Mn}),children:[n.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[n.jsx("span",{className:"text-[10px] text-fg-tertiary",children:Oe?"▼":"▶"}),n.jsx("button",{onClick:Je=>{Je.stopPropagation(),Nt.navigate(Se.TEAM,{agentId:ie.id})},className:"text-sm text-brand-500 hover:text-brand-400 truncate",children:ie.name}),n.jsx("span",{className:"text-[10px] text-fg-tertiary font-mono truncate",children:ie.id})]}),n.jsx("span",{className:"text-xs font-medium text-fg-secondary tabular-nums shrink-0 ml-3",children:Bc(ie.size,i)})]}),Oe&&n.jsxs("div",{className:"px-3 pb-2 pt-0.5 space-y-0.5",children:[ie.subItems.filter(Je=>Je.size>0).map(Je=>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:Je.name}),n.jsx("span",{className:"text-fg-secondary tabular-nums",children:Bc(Je.size,i)})]},Je.name)),n.jsx("div",{className:"pl-5 pt-1",children:n.jsx("button",{onClick:()=>{le.system.openPath(Qe.dataDir+"/agents/"+ie.id)},className:"text-[10px] text-fg-tertiary hover:text-fg-secondary underline",children:i("dataStorage.openFolder")})})]})]},ie.id)})})]}),jn&&(jn.orphanAgents.length>0||jn.orphanTeams.length>0)&&n.jsx(rG,{orphanInfo:jn,dataDir:Qe.dataDir,onPurged:Bs,formatBytes:ie=>Bc(ie,i)})]})]})})}),k==="users"&&n.jsx(nG,{authUser:r}),k==="remote"&&n.jsx(aG,{})]}),n.jsx("div",{className:"h-8"})]})]})]})}const eG=["owner","admin","member","guest"],tG={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 nG({authUser:e}){const{t}=kt(["settings","common"]),[r,s]=b.useState([]),[a,i]=b.useState(null),[l,d]=b.useState(""),[u,m]=b.useState(""),[p,h]=b.useState(""),[y,g]=b.useState(null),[v,S]=b.useState(""),[C,k]=b.useState(null),[N,j]=b.useState(null),[T,R]=b.useState(null),M=b.useCallback(()=>{le.users.list(e?.orgId).then(U=>s(U.users)).catch(()=>{})},[e?.orgId]);b.useEffect(()=>{M()},[M]);const _=U=>{i(U.id),d(U.name),m(U.role),h(U.email??""),R(null)},F=async()=>{if(a)try{await le.users.update(a,{name:l,role:u,email:p||void 0}),i(null),R({type:"ok",text:t("settings:userManagement.updateSuccess")}),M()}catch(U){R({type:"err",text:`${t("settings:userManagement.error")}: ${String(U)}`})}},z=async()=>{if(!(!y||!v))try{await le.users.resetPassword(y,v),g(null),S(""),R({type:"ok",text:t("settings:userManagement.resetSuccess")})}catch(U){R({type:"err",text:`${t("settings:userManagement.error")}: ${String(U)}`})}},L=async U=>{if(U===e?.id){R({type:"err",text:t("settings:userManagement.cannotDeleteSelf")}),k(null);return}if(r.find(q=>q.id===U)?.role==="owner"){R({type:"err",text:t("settings:userManagement.cannotDeleteOwner")}),k(null);return}try{await le.users.remove(U),k(null),R({type:"ok",text:t("settings:userManagement.deleteSuccess")}),M()}catch(q){R({type:"err",text:`${t("settings:userManagement.error")}: ${String(q)}`})}};return n.jsx(si,{title:t("settings:userManagement.title"),children: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),R({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:()=>j(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(U=>{const K=a===U.id,q=y===U.id,I=C===U.id,D=U.id===e?.id,E=U.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:K?n.jsx("input",{value:l,onChange:$=>d($.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:U.name}),D&&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:K?n.jsx("input",{value:p,onChange:$=>h($.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:U.email||"—"})}),n.jsx("td",{className:"px-4 py-2.5",children:K?n.jsx("select",{value:u,onChange:$=>m($.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:eG.map($=>n.jsx("option",{value:$,children:t(`settings:userManagement.roles.${$}`)},$))}):n.jsx("span",{className:`inline-block text-[10px] px-2 py-0.5 rounded-full border font-medium ${tG[U.role]??""}`,children:t(`settings:userManagement.roles.${U.role}`)})}),n.jsx("td",{className:"px-4 py-2.5 text-right",children:K?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:F,className:"text-[11px] text-brand-500 hover:text-brand-400 font-medium",children:t("settings:userManagement.save")})]}):q?n.jsxs("div",{className:"flex items-center justify-end gap-2",children:[n.jsx("input",{type:"password",value:v,onChange:$=>S($.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:()=>{g(null),S("")},className:"text-[11px] text-fg-tertiary hover:text-fg-secondary",children:t("settings:userManagement.cancel")}),n.jsx("button",{onClick:z,disabled:v.length<6,className:"text-[11px] text-brand-500 hover:text-brand-400 font-medium disabled:opacity-40",children:t("settings:userManagement.confirmReset")})]}):I?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:()=>k(null),className:"text-[11px] text-fg-tertiary hover:text-fg-secondary",children:t("settings:userManagement.cancel")}),n.jsx("button",{onClick:()=>L(U.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:()=>_(U),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")}),U.email&&n.jsx("button",{onClick:()=>{g(U.id),S(""),R(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")}),U.email&&!E&&!U.hasJoined&&n.jsx("button",{onClick:async()=>{try{const{inviteToken:$}=await le.users.reinvite(U.id),Y=`${window.location.origin}/#invite?token=${$}`;j(Y),R({type:"ok",text:t("settings:userManagement.inviteLinkGenerated")})}catch($){R({type:"err",text:String($)})}},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")}),!E&&!D&&n.jsx("button",{onClick:()=>{k(U.id),R(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")})]})})]},U.id)})]})]})]})})}function yu({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 Oa({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 si({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 Ax({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 el({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 Bc(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 rG({orphanInfo:e,dataDir:t,onPurged:r,formatBytes:s}){const{t:a}=kt(["settings","common"]),i=[...e.orphanAgents.map(k=>({...k,kind:"agent"})),...e.orphanTeams.map(k=>({...k,kind:"team"}))],[l,d]=b.useState(new Set),[u,m]=b.useState(!1),[p,h]=b.useState(null),y=k=>d(N=>{const j=new Set(N);return j.has(k)?j.delete(k):j.add(k),j}),g=l.size===i.length&&i.length>0,v=()=>d(g?new Set:new Set(i.map(k=>k.id))),S=i.filter(k=>l.has(k.id)).reduce((k,N)=>k+N.size,0),C=async k=>{m(!0),h(null);try{const N=await le.system.purgeOrphans(k),j=N.purgedAgents.length+N.purgedTeams.length,T=a("dataStorage.cleaned",{count:j,size:s(N.freedBytes)});h(N.failures.length?a("dataStorage.cleanedWithFailureNote",{base:T,count:N.failures.length}):T),d(new Set),r()}catch{h(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:g,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(S)})})]}),n.jsx("div",{className:"space-y-0.5 mb-3 max-h-52 overflow-y-auto",children:i.map(k=>n.jsxs("div",{className:`flex items-center gap-2 text-xs py-1.5 px-2 rounded transition-colors ${l.has(k.id)?"bg-amber-500/10":"bg-surface-elevated/30 hover:bg-surface-elevated/50"}`,children:[n.jsx("input",{type:"checkbox",checked:l.has(k.id),onChange:()=>y(k.id),className:"rounded shrink-0"}),k.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:k.id}),n.jsx("span",{className:"text-fg-secondary tabular-nums shrink-0",children:s(k.size)}),n.jsx("button",{onClick:()=>{le.system.openPath(k.path)},className:"text-[10px] text-fg-tertiary hover:text-fg-secondary shrink-0 underline",children:a("common:open")})]},k.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(S)})}),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)})})]}),p&&n.jsx("div",{className:"text-xs text-fg-tertiary mt-2",children:p})]})}function sG({authUser:e,onClose:t,onSaved:r}){const{t:s}=kt("common"),[a,i]=b.useState(e.name||""),[l,d]=b.useState(e.email||""),[u,m]=b.useState(!1),[p,h]=b.useState(""),[y,g]=b.useState(e.avatarUrl),v=async S=>{if(S.preventDefault(),!a.trim()){h(s("profile.nameRequired"));return}if(l&&!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(l.trim())){h(s("profile.invalidEmail"));return}m(!0),h("");try{const{user:C}=await le.auth.updateProfile(a.trim(),l.trim());r({...C,avatarUrl:y??C.avatarUrl})}catch{h(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:S=>S.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(Qj,{currentUrl:y,name:a,size:72,targetType:"user",targetId:e.id,onUploaded:S=>g(S)})}),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:S=>i(S.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:S=>d(S.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"})]}),p&&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:p})]}),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 aG(){const{t:e}=kt(["settings","common"]),[t,r]=b.useState(null),[s,a]=b.useState(!0),[i,l]=b.useState(!1),[d,u]=b.useState(null),[m,p]=b.useState(!1),h=Kj(),y=b.useCallback(async()=>{try{const N=await le.settings.getRemote();r(N)}catch{r(null)}finally{a(!1)}},[]);b.useEffect(()=>{y()},[y]),b.useEffect(()=>gn.on("remote:status",N=>{const j=N.payload;j&&(r(j),l(!1))}),[]);const g=async()=>{l(!0),u(null);try{t?.enabled?(await le.settings.disableRemote(),await y(),l(!1)):(zn.isAuthenticated()||await pi(),await le.settings.enableRemote())}catch(N){u(String(N instanceof Error?N.message:N)),l(!1)}},v=async()=>{try{await pi(),await y()}catch{}},S=()=>{t?.remoteUrl&&(navigator.clipboard.writeText(t.remoteUrl),p(!0),setTimeout(()=>p(!1),2e3))},C=i||t?.enabled&&!t?.connected&&t?.state!=="idle",k=t?.remoteUrl??null;return n.jsx(si,{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")}),zn.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:h?.username??h?.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")})]}),zn.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:g,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(Ik,{})]}),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(Ik,{})]})]}),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:S,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")})]})]}),k&&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(iG,{url:k})]})]})]})]})})}function Ik(){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 iG({url:e}){const t=b.useRef(null),[r,s]=b.useState(!1);return b.useEffect(()=>{const a=t.current;a&&(s(!1),Sd(()=>import("./browser-C-GL27EU.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 Wf=new Map;function Bl(e,t){Wf.has(e)||Wf.set(e,t().catch(()=>{}))}function Wl(e){const t=Wf.get(e);return Wf.delete(e),t}const ga={builderArtifacts:"builder.artifacts",builderAgents:"builder.agents",builderHubMyItems:"builder.hubMyItems",builderInstalled:"builder.installed",hubAgents:"hub.agents",hubTeams:"hub.teams",hubSkills:"hub.skills"};function oG(e){const t=e.indexOf(".markus/builder-artifacts/");return t>=0?"~/"+e.slice(t):e}const lG=[{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"}],Pk={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 Ok({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 cG(){const[e,t]=b.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 b.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 CS({authUser:e}={}){const{t}=kt(["builder","common"]),r=ks(),s=cG(),[a,i]=b.useState([]),[l,d]=b.useState([]),[u,m]=b.useState(!1),[p,h]=b.useState("all"),[y,g]=b.useState(null),[v,S]=b.useState(new Map),[C,k]=b.useState(null),[N,j]=b.useState(new Map),[T,R]=b.useState(null),[M,_]=b.useState(null),[F,z]=b.useState(null),L=b.useCallback(()=>{m(!0),Promise.all([(Wl(ga.builderArtifacts)??le.builder.artifacts.list()).then(W=>W?.artifacts??[]).catch(()=>[]),(Wl(ga.builderAgents)??le.agents.list()).then(W=>W?.agents??[]).catch(()=>[]),(Wl(ga.builderHubMyItems)??zn.myItems()).then(W=>W?.items??[]).catch(()=>[]),(Wl(ga.builderInstalled)??le.builder.artifacts.installed()).then(W=>W?.installed??{}).catch(()=>({}))]).then(([W,O,H,Z])=>{if(d(W),i(O),H.length>0){const J=new Map;for(const Q of H){const ee=Q.itemType==="agent"?"agent":Q.itemType==="team"?"team":"skill";for(const se of W)se.type===ee&&(Q.slug===se.name||Q.name===(se.meta.displayName||se.meta.name||se.name))&&J.set(`${se.type}/${se.name}`,{id:Q.id,name:Q.name,slug:Q.slug||se.name,version:Q.version||"1.0.0"})}J.size>0&&j(Q=>{const ee=new Map(Q);for(const[se,X]of J)ee.set(se,X);return ee})}const B=new Map;for(const J of W){const Q=`${J.type}/${J.name}`,ee=Z[Q];ee&&B.set(Q,{agentId:ee.agentId,agentIds:ee.agentIds,teamId:ee.teamId})}S(B)}).finally(()=>m(!1))},[]);b.useEffect(()=>{L();const W=O=>{O.detail?.page===Se.BUILDER&&L()};return window.addEventListener("markus:navigate",W),()=>window.removeEventListener("markus:navigate",W)},[L]);const U=W=>{const O=a.find(H=>H.role==="Secretary"||H.name==="Secretary");O?Nt.navigate(Se.TEAM,{agentId:O.id,prefillMessage:W}):Nt.navigate(Se.TEAM,{prefillMessage:W})},K=async W=>{const O=`${W.type}/${W.name}`;if(!v.has(O)){g({key:O,action:"install"});try{const H=await le.builder.artifacts.install(W.type,W.name),Z={};H.agent&&typeof H.agent=="object"&&(Z.agentId=H.agent.id),H.team&&typeof H.team=="object"&&(Z.teamId=H.team.id),Array.isArray(H.agents)&&(Z.agentIds=H.agents.map(B=>B.id)),S(B=>new Map(B).set(O,Z)),window.dispatchEvent(new CustomEvent("markus:data-changed"))}catch(H){console.error("Install failed:",H),alert(t("installFailed",{error:String(H)}))}finally{g(null)}}},q=async W=>{const O=`${W.type}/${W.name}`;if(v.has(O)){g({key:O,action:"uninstall"});try{await le.builder.artifacts.uninstall(W.type,W.name),S(H=>{const Z=new Map(H);return Z.delete(O),Z}),window.dispatchEvent(new CustomEvent("markus:data-changed"))}catch(H){console.error("Uninstall failed:",H),alert(t("uninstallFailed",{error:String(H)}))}finally{g(null)}}},I=async(W,O)=>{const H=`${W.type}/${W.name}`;g({key:H,action:"share"});try{const Z=await le.builder.artifacts.get(W.type,W.name),B=W.meta.displayName||W.meta.name||W.name,J=W.meta.description||"",Q=W.meta.category||"general",ee=Array.isArray(W.meta.tags)?W.meta.tags:[],se=W.name;let X=W.meta.icon||void 0;const me=W.meta.version||"1.0.0";if(X&&!X.startsWith("http")&&/\.(png|jpe?g|gif|webp|svg)$/i.test(X)){const pe=X.split("/").pop()??X;try{const Pe=await fetch(`/api/builder/artifacts/${W.type}s/${encodeURIComponent(W.name)}/images/${encodeURIComponent(pe)}`);if(Pe.ok){const Ae=await Pe.blob(),Xe=new File([Ae],pe,{type:Ae.type}),Ze=await zn.uploadImage(Xe);Ze?.url&&(X=Ze.url)}}catch{}}let je;const Re=[],Ee=Array.isArray(W.meta.screenshots)?W.meta.screenshots:[];for(let pe=0;pe<Ee.length;pe++){const Pe=Ee[pe],Ae=Pe.split("/").pop()??Pe;try{const Xe=await fetch(`/api/builder/artifacts/${W.type}s/${encodeURIComponent(W.name)}/images/${encodeURIComponent(Ae)}`);if(Xe.ok){const Ze=await Xe.blob(),at=new File([Ze],Ae,{type:Ze.type}),pt=await zn.uploadImage(at);pt?.url&&(Re.push({url:pt.url,alt:Ae,order:pe}),(pe===0||W.meta.thumbnail===Pe)&&(je=pt.url))}}catch{}}const we=await zn.publishViaProxy({itemType:W.type==="team"?"team":W.type==="skill"?"skill":"agent",name:B,slug:se,description:J,category:Q,tags:ee,icon:X,version:me,config:W.meta,files:Z.files&&Object.keys(Z.files).length>0?Z.files:void 0,thumbnailUrl:je,images:Re.length>0?Re:void 0,priceCents:O?.priceCents,donationsEnabled:O?.donationsEnabled});we.id&&j(pe=>{const Pe=new Map(pe);return Pe.set(H,{id:we.id,name:B,slug:we.slug??se,version:me}),Pe})}catch(Z){console.error("Share failed:",Z),alert(t("shareFailed",{error:String(Z)}))}finally{g(null)}},D=async()=>{if(!T)return;const{key:W}=T,O=N.get(W);if(R(null),!O)return;const H=O.id;g({key:W,action:"hubDelete"});try{await zn.deleteItem(H),j(Z=>{const B=new Map(Z);return B.delete(W),B})}catch(Z){console.error("Hub delete failed:",Z),alert(t("hubDeleteFailed",{error:String(Z)}))}finally{g(null)}},E=async()=>{if(!C)return;const W=C,O=`${W.type}/${W.name}`;k(null),g({key:O,action:"delete"});try{await le.builder.artifacts.delete(W.type,W.name),d(H=>H.filter(Z=>!(Z.type===W.type&&Z.name===W.name))),S(H=>{const Z=new Map(H);return Z.delete(O),Z}),window.dispatchEvent(new CustomEvent("markus:data-changed"))}catch(H){console.error("Delete failed:",H)}finally{g(null)}},$=p==="all"?l:l.filter(W=>W.type===p),Y=W=>{history.pushState(null,"",`#builder/${W.type}/${encodeURIComponent(W.name)}`),window.dispatchEvent(new HashChangeEvent("hashchange"))};return s?n.jsx(Jl,{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:L,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:lG.map(W=>{const O=t(`prompts.${W.id}Prompt`),H=t(`prompts.${W.id}Examples`,{returnObjects:!0}),Z=Array.isArray(H)?H:[];return n.jsx("button",{onClick:()=>U(O),className:`group text-left w-full rounded-xl border ${W.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 ${W.bgColor} flex items-center justify-center shrink-0`,children:W.icon}),n.jsxs("div",{className:"flex-1 min-w-0",children:[n.jsx("h3",{className:`text-sm font-semibold bg-gradient-to-r ${W.color} bg-clip-text text-transparent`,children:t(`prompts.${W.id}`)}),n.jsx("p",{className:"text-[11px] text-fg-tertiary mt-1 leading-relaxed",children:t(`prompts.${W.id}Desc`)}),Z.length>0&&n.jsx("div",{className:"mt-2 flex flex-wrap gap-1.5",children:Z.slice(0,2).map((B,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:Q=>{Q.stopPropagation(),U(O+B)},children:["“",B,"”"]},J))})]})]})},W.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(W=>n.jsx("button",{onClick:()=>h(W),className:`text-xs px-2.5 py-1 rounded-lg transition-colors ${p===W?"bg-brand-600 text-white":"text-fg-tertiary hover:text-fg-secondary hover:bg-surface-elevated"}`,children:t(W==="all"?"myCreations.filterAll":W==="agent"?"myCreations.filterAgents":W==="team"?"myCreations.filterTeams":"myCreations.filterSkills")},W))})]})}),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(W=>{const O=Pk[W.type]??Pk.agent,H=W.meta.displayName||W.meta.name||W.name,Z=W.meta.description||"",B=`${W.type}/${W.name}`,J=y?.key===B?y.action:null,Q=N.get(B),ee=W.meta.version||"1.0.0",se=!!Q,X=se&&Q.version!==ee,me=()=>{const Re=zn.getUser();return!Q||!Re?null:`${zn.getUrl()}/${encodeURIComponent(Re.username)}/${encodeURIComponent(Q.slug)}`},je=n.jsxs("div",{className:`flex items-center gap-1.5 ${r?"flex-wrap":"shrink-0"}`,onClick:Re=>Re.stopPropagation(),children:[v.has(B)?n.jsx("button",{onClick:()=>q(W),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:()=>K(W),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")}),se&&X?n.jsx("button",{onClick:()=>z(W),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})}):se?n.jsxs("div",{className:"flex items-center gap-1",children:[n.jsxs("a",{href:me()??"#",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:()=>R({key:B,name:H}),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 zn.ensureAuth(),Array.isArray(W.meta.screenshots)&&W.meta.screenshots.length>0?I(W):_(W)},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:()=>k(W),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:()=>Y(W),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 Re=W.meta.icon,we=Re&&(Re.startsWith("http")||Re.startsWith("/")||/\.(png|jpe?g|gif|webp|svg)$/i.test(Re))?Re.startsWith("http")||Re.startsWith("/")?Re:`/api/builder/artifacts/${W.type}s/${encodeURIComponent(W.name)}/images/${encodeURIComponent(Re.split("/").pop()??"")}`:null;return n.jsx("div",{className:`w-9 h-9 rounded-lg ${O.bg} flex items-center justify-center text-lg shrink-0 overflow-hidden`,children:we?n.jsx("img",{src:we,alt:"",className:"w-full h-full object-cover"}):Re?n.jsx("span",{children:Re}):O.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:H}),n.jsx("span",{className:`text-[10px] font-medium uppercase tracking-wider ${O.color}`,children:W.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:Re=>{Re.stopPropagation(),le.system.openPath(W.path).catch(()=>{})},className:"hover:text-fg-secondary transition-colors truncate min-w-0",title:W.path,children:oG(W.path)}),n.jsx("span",{className:"shrink-0",children:new Date(W.updatedAt).toLocaleDateString()})]})]}),!r&&je]}),r&&n.jsx("div",{className:"mt-3 pt-3 border-t border-border-default/50",children:je})]},B)})}),C&&n.jsx(Ok,{title:t("confirmDelete"),message:t("deleteCannotUndo",{name:C.meta.displayName||C.meta.name||C.name}),cancelLabel:t("common:cancel"),confirmLabel:t("common:delete"),onConfirm:E,onCancel:()=>k(null)}),T&&n.jsx(Ok,{title:t("confirmDelete"),message:t("removeFromHub",{name:T.name}),cancelLabel:t("common:cancel"),confirmLabel:t("common:delete"),onConfirm:()=>{D()},onCancel:()=>R(null)}),M&&n.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm",onClick:()=>_(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:W=>W.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 W=M;_(null),I(W)},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 W=M;_(null),Y(W)},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")})]})]})}),F&&n.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm",onClick:()=>z(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:W=>W.stopPropagation(),children:n.jsx(dG,{isUpdate:N.has(`${F.type}/${F.name}`),onCancel:()=>z(null),onConfirm:(W,O)=>{const H=F;z(null),I(H,{donationsEnabled:W==="donation",priceCents:W==="paid"?O:void 0})}})})})]})})}function dG({isUpdate:e,onCancel:t,onConfirm:r}){const{t:s}=kt(["builder","common"]),[a,i]=b.useState("free"),[l,d]=b.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 _k={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"}},uG=["development","devops","management","productivity","browser","custom","general"],mG=[{label:"Tech",emojis:["✦","◈","⬡","⚡","🤖","🧠","💡","🎯","🔧","📦","🚀","💻","🛠️","⭐","🔥","💎","⚙️","🧩","🔌","💾","🖥️","📡","🔬","🧪","🏗️","📱","🎮","🕹️","📟","💽","🖨️","⌨️"]},{label:"People",emojis:["👤","👥","🧑‍💻","👨‍💼","👩‍🔬","🧙","🦸","🤝","💪","🎓","👷","🕵️","🧑‍🎨","🧑‍🏫","👨‍🚀","🥷","🧑‍🏭","🧑‍⚕️","🧑‍🔧","🧑‍🍳","👨‍🎤","🦹","🧝","🧞","🧑‍✈️","💂","🤴","👸","🧛","🧟","🧜","🧚"]},{label:"Objects",emojis:["📝","📊","🗂️","📁","🔍","🔑","🌐","💬","🔒","🎨","📐","🗃️","📋","✏️","🖊️","📌","📎","🧲","🪝","🧰","🪜","🧬","🔭","💊","🩺","📕","📗","📘","📙","📓","🗒️","📰"]},{label:"Symbols",emojis:["❤️","🧡","💛","💚","💙","💜","🖤","🤍","♠️","♥️","♦️","♣️","🎵","🎶","💯","✅","❌","⭕","🔴","🟠","🟡","🟢","🔵","🟣","⚫","⚪","🟤","🔶","🔷","▶️","⏸️","⏹️"]},{label:"Nature",emojis:["🌟","🌈","🌊","🌿","🍀","🔮","💫","✨","🌙","☀️","🦋","🐉","🦊","🐺","🦅","🐙","🦁","🐯","🦄","🐲","🌸","🌺","🍄","🌵","🎄","🌴","🍁","🌻","🐝","🦎","🐍","🦈"]},{label:"Activity",emojis:["🎯","🏆","🥇","🎖️","🏅","🎪","🎭","🎬","🎤","🎧","🎼","🎹","🥁","🎸","🎺","🎻","⚽","🏀","🎾","🏐","🎲","🧸","🪁","🎰","🎳","🏹","🥊","🤺","⛷️","🏄","🚴","🧗"]}],fG={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 Ex({value:e,onChange:t,renderAs:r="span",className:s,editClassName:a,placeholder:i,multiline:l,readOnly:d}){if(d){const j=e||i,R=`${s??""} ${!e?"text-fg-muted italic":""}`;return r==="h1"?n.jsx("h1",{className:R,children:j}):r==="p"?n.jsx("p",{className:R,children:j}):n.jsx("span",{className:R,children:j})}const[u,m]=b.useState(!1),[p,h]=b.useState(e),y=b.useRef(null);b.useEffect(()=>{h(e)},[e]),b.useEffect(()=>{u&&y.current?.focus()},[u]);const g=()=>{m(!1),p!==e&&t(p)},v=()=>{h(e),m(!1)},S=j=>{j.key==="Escape"&&v(),j.key==="Enter"&&!l&&g()};if(u){const j=`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:p,onChange:T=>h(T.target.value),onBlur:g,onKeyDown:S,className:`${j} resize-y min-h-[60px]`,placeholder:i}):n.jsx("input",{ref:y,value:p,onChange:T=>h(T.target.value),onBlur:g,onKeyDown:S,className:j,placeholder:i})}const C=e||i,k=!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} ${k?"text-fg-muted italic":""}`,children:C}):r==="p"?n.jsx("p",{onClick:()=>m(!0),className:`${s??""} ${N} ${k?"text-fg-muted italic":""}`,children:C}):r==="badge"?n.jsx("span",{onClick:()=>m(!0),className:`${s??""} ${N} ${k?"text-fg-muted italic":""}`,children:C}):n.jsx("span",{onClick:()=>m(!0),className:`${s??""} ${N} ${k?"text-fg-muted italic":""}`,children:C})}function hG({value:e,options:t,onChange:r,className:s,readOnly:a}){if(a)return n.jsx("span",{className:s,children:e});const[i,l]=b.useState(!1),[d,u]=b.useState(e),m=b.useRef(null),p=b.useRef(null);b.useEffect(()=>{i&&(u(e),setTimeout(()=>m.current?.focus(),0))},[i,e]);const h=t.filter(g=>g.toLowerCase().includes(d.toLowerCase())),y=g=>{const v=g.trim();v&&v!==e&&r(v),l(!1)};return i?n.jsxs("div",{ref:p,className:"relative inline-block",children:[n.jsx("input",{ref:m,value:d,onChange:g=>u(g.target.value),onKeyDown:g=>{g.key==="Enter"?(g.preventDefault(),y(d)):g.key==="Escape"&&l(!1)},onBlur:g=>{p.current?.contains(g.relatedTarget)||y(d)},className:`${s??""} bg-transparent outline-none ring-1 ring-brand-500/50 rounded w-28`}),h.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:h.map(g=>n.jsx("button",{onMouseDown:v=>{v.preventDefault(),y(g)},className:`block w-full text-left px-3 py-1.5 text-xs hover:bg-surface-secondary/80 transition-colors ${g===e?"text-brand-400 font-medium":"text-fg-secondary"}`,children:g},g))})]}):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 pG({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(p=>n.jsx("span",{className:"text-[10px] px-2 py-0.5 bg-surface-elevated text-fg-muted rounded-full border border-border-default",children:p},p))});const{t:s}=kt(["builder"]),[a,i]=b.useState(!1),[l,d]=b.useState(""),u=b.useRef(null);b.useEffect(()=>{a&&u.current?.focus()},[a]);const m=p=>{if((p.key==="Enter"||p.key===",")&&l.trim()){p.preventDefault();const h=l.trim().toLowerCase();e.includes(h)||t([...e,h]),d("")}else p.key==="Backspace"&&!l&&e.length>0?t(e.slice(0,-1)):p.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(p=>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:[p,n.jsx("button",{onClick:()=>t(e.filter(h=>h!==p)),className:"text-fg-muted hover:text-red-500",children:"×"})]},p)),n.jsx("input",{ref:u,value:l,onChange:p=>d(p.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(p=>n.jsx("span",{className:"text-[10px] px-2 py-0.5 bg-surface-elevated text-fg-muted rounded-full border border-border-default",children:p},p)):n.jsx("span",{className:"text-[10px] text-fg-muted italic",children:s("detail.typeTagAndEnter")})})}function Pb({content:e}){return n.jsx("div",{className:`prose prose-invert prose-sm max-w-none
656
656
  prose-headings:text-fg-primary prose-headings:font-semibold
657
657
  prose-p:text-fg-secondary prose-p:leading-relaxed
658
658
  prose-a:text-brand-400 prose-a:no-underline hover:prose-a:underline
@@ -703,4 +703,4 @@ l0,-`+(r+144)+`c-2,-159.3,-10,-310.7,-24,-454c-53.3,-528,-210,-949.7,
703
703
  `)),p=m.reduce((h,y)=>h.concat(...y),[]);return[m,p]}return[[],[]]},[e]);return b.useEffect(()=>{const u=t?.target??D3,m=t?.actInsideInputWithModifier??!0;if(e!==null){const p=g=>{if(a.current=g.ctrlKey||g.metaKey||g.shiftKey||g.altKey,(!a.current||a.current&&!m)&&S8(g))return!1;const S=L3(g.code,d);if(i.current.add(g[S]),R3(l,i.current,!1)){const C=g.composedPath?.()?.[0]||g.target,k=C?.nodeName==="BUTTON"||C?.nodeName==="A";t.preventDefault!==!1&&(a.current||!k)&&g.preventDefault(),s(!0)}},h=g=>{const v=L3(g.code,d);R3(l,i.current,!0)?(s(!1),i.current.clear()):i.current.delete(g[v]),g.key==="Meta"&&i.current.clear(),a.current=!1},y=()=>{i.current.clear(),s(!1)};return u?.addEventListener("keydown",p),u?.addEventListener("keyup",h),window.addEventListener("blur",y),window.addEventListener("contextmenu",y),()=>{u?.removeEventListener("keydown",p),u?.removeEventListener("keyup",h),window.removeEventListener("blur",y),window.removeEventListener("contextmenu",y)}}},[e,s]),r}function R3(e,t,r){return e.filter(s=>r||s.length===t.size).some(s=>s.every(a=>t.has(a)))}function L3(e,t){return t.includes(e)?"code":"key"}const FJ=()=>{const e=zr();return b.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=sy(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},p=r.snapGrid??a,h=r.snapToGrid??i;return k0(m,s,h,p)},flowToScreenPosition:t=>{const{transform:r,domNode:s}=e.getState();if(!s)return t;const{x:a,y:i}=s.getBoundingClientRect(),l=rh(t,r);return{x:l.x+a,y:l.y+i}}}),[])};function K8(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)qJ(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 qJ(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 G8(e,t){return K8(e,t)}function Y8(e,t){return K8(e,t)}function ql(e,t){return{id:e,type:"select",selected:t}}function Qc(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(ql(i.id,l)))}return s}function I3({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 P3(e){return{id:e.id,type:"remove"}}const O3=e=>pZ(e),UJ=e=>x8(e);function X8(e){return b.forwardRef(e)}const VJ=typeof window<"u"?b.useLayoutEffect:b.useEffect;function _3(e){const[t,r]=b.useState(BigInt(0)),[s]=b.useState(()=>WJ(()=>r(a=>a+BigInt(1))));return VJ(()=>{const a=s.get();a.length&&(e(a),s.reset())},[t]),s}function WJ(e){let t=[];return{get:()=>t,reset:()=>{t=[]},push:r=>{t.push(r),e()}}}const Q8=b.createContext(null);function KJ({children:e}){const t=zr(),r=b.useCallback(d=>{const{nodes:u=[],setNodes:m,hasDefaultNodes:p,onNodesChange:h,nodeLookup:y,fitViewQueued:g,onNodesChangeMiddlewareMap:v}=t.getState();let S=u;for(const k of d)S=typeof k=="function"?k(S):k;let C=I3({items:S,lookup:y});for(const k of v.values())C=k(C);p&&m(S),C.length>0?h?.(C):g&&window.requestAnimationFrame(()=>{const{fitViewQueued:k,nodes:N,setNodes:j}=t.getState();k&&j(N)})},[]),s=_3(r),a=b.useCallback(d=>{const{edges:u=[],setEdges:m,hasDefaultEdges:p,onEdgesChange:h,edgeLookup:y}=t.getState();let g=u;for(const v of d)g=typeof v=="function"?v(g):v;p?m(g):h&&h(I3({items:g,lookup:y}))},[]),i=_3(a),l=b.useMemo(()=>({nodeQueue:s,edgeQueue:i}),[]);return n.jsx(Q8.Provider,{value:l,children:e})}function GJ(){const e=b.useContext(Q8);if(!e)throw new Error("useBatchContext must be used within a BatchProvider");return e}const YJ=e=>!!e.panZoom;function uy(){const e=FJ(),t=zr(),r=GJ(),s=er(YJ),a=b.useMemo(()=>{const i=h=>t.getState().nodeLookup.get(h),l=h=>{r.nodeQueue.push(h)},d=h=>{r.edgeQueue.push(h)},u=h=>{const{nodeLookup:y,nodeOrigin:g}=t.getState(),v=O3(h)?h:y.get(h.id),S=v.parentId?j8(v.position,v.measured,v.parentId,y,g):v.position,C={...v,position:S,width:v.measured?.width??v.width,height:v.measured?.height??v.height};return hd(C)},m=(h,y,g={replace:!1})=>{l(v=>v.map(S=>{if(S.id===h){const C=typeof y=="function"?y(S):y;return g.replace&&O3(C)?C:{...S,...C}}return S}))},p=(h,y,g={replace:!1})=>{d(v=>v.map(S=>{if(S.id===h){const C=typeof y=="function"?y(S):y;return g.replace&&UJ(C)?C:{...S,...C}}return S}))};return{getNodes:()=>t.getState().nodes.map(h=>({...h})),getNode:h=>i(h)?.internals.userNode,getInternalNode:i,getEdges:()=>{const{edges:h=[]}=t.getState();return h.map(y=>({...y}))},getEdge:h=>t.getState().edgeLookup.get(h),setNodes:l,setEdges:d,addNodes:h=>{const y=Array.isArray(h)?h:[h];r.nodeQueue.push(g=>[...g,...y])},addEdges:h=>{const y=Array.isArray(h)?h:[h];r.edgeQueue.push(g=>[...g,...y])},toObject:()=>{const{nodes:h=[],edges:y=[],transform:g}=t.getState(),[v,S,C]=g;return{nodes:h.map(k=>({...k})),edges:y.map(k=>({...k})),viewport:{x:v,y:S,zoom:C}}},deleteElements:async({nodes:h=[],edges:y=[]})=>{const{nodes:g,edges:v,onNodesDelete:S,onEdgesDelete:C,triggerNodeChanges:k,triggerEdgeChanges:N,onDelete:j,onBeforeDelete:T}=t.getState(),{nodes:R,edges:M}=await vZ({nodesToRemove:h,edgesToRemove:y,nodes:g,edges:v,onBeforeDelete:T}),_=M.length>0,F=R.length>0;if(_){const z=M.map(P3);C?.(M),N(z)}if(F){const z=R.map(P3);S?.(R),k(z)}return(F||_)&&j?.({nodes:R,edges:M}),{deletedNodes:R,deletedEdges:M}},getIntersectingNodes:(h,y=!0,g)=>{const v=d3(h),S=v?h:u(h),C=g!==void 0;return S?(g||t.getState().nodes).filter(k=>{const N=t.getState().nodeLookup.get(k.id);if(N&&!v&&(k.id===h.id||!N.internals.positionAbsolute))return!1;const j=hd(C?k:N),T=a0(j,S);return y&&T>0||T>=j.width*j.height||T>=S.width*S.height}):[]},isNodeIntersecting:(h,y,g=!0)=>{const S=d3(h)?h:u(h);if(!S)return!1;const C=a0(S,y);return g&&C>0||C>=y.width*y.height||C>=S.width*S.height},updateNode:m,updateNodeData:(h,y,g={replace:!1})=>{m(h,v=>{const S=typeof y=="function"?y(v):y;return g.replace?{...v,data:S}:{...v,data:{...v.data,...S}}},g)},updateEdge:p,updateEdgeData:(h,y,g={replace:!1})=>{p(h,v=>{const S=typeof y=="function"?y(v):y;return g.replace?{...v,data:S}:{...v,data:{...v.data,...S}}},g)},getNodesBounds:h=>{const{nodeLookup:y,nodeOrigin:g}=t.getState();return gZ(h,{nodeLookup:y,nodeOrigin:g})},getHandleConnections:({type:h,id:y,nodeId:g})=>Array.from(t.getState().connectionLookup.get(`${g}-${h}${y?`-${y}`:""}`)?.values()??[]),getNodeConnections:({type:h,handleId:y,nodeId:g})=>Array.from(t.getState().connectionLookup.get(`${g}${h?y?`-${h}-${y}`:`-${h}`:""}`)?.values()??[]),fitView:async h=>{const y=t.getState().fitViewResolver??NZ();return t.setState({fitViewQueued:!0,fitViewOptions:h,fitViewResolver:y}),r.nodeQueue.push(g=>[...g]),y.promise}}},[]);return b.useMemo(()=>({...a,...e,viewportInitialized:s}),[s])}const z3=e=>e.selected,XJ=typeof window<"u"?window:void 0;function QJ({deleteKeyCode:e,multiSelectionKeyCode:t}){const r=zr(),{deleteElements:s}=uy(),a=o0(e,{actInsideInputWithModifier:!1}),i=o0(t,{target:XJ});b.useEffect(()=>{if(a){const{edges:l,nodes:d}=r.getState();s({nodes:d.filter(z3),edges:l.filter(z3)}),r.setState({nodesSelectionActive:!1})}},[a]),b.useEffect(()=>{r.setState({multiSelectionActive:i})},[i])}function ZJ(e){const t=zr();b.useEffect(()=>{const r=()=>{if(!e.current||!(e.current.checkVisibility?.()??!0))return!1;const s=ay(e.current);(s.height===0||s.width===0)&&t.getState().onError?.("004",$i.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 zh={position:"absolute",width:"100%",height:"100%",top:0,left:0},JJ=e=>({userSelectionActive:e.userSelectionActive,lib:e.lib,connectionInProgress:e.connection.inProgress});function eee({onPaneContextMenu:e,zoomOnScroll:t=!0,zoomOnPinch:r=!0,panOnScroll:s=!1,panOnScrollSpeed:a=.5,panOnScrollMode:i=Xl.Free,zoomOnDoubleClick:l=!0,panOnDrag:d=!0,defaultViewport:u,translateExtent:m,minZoom:p,maxZoom:h,zoomActivationKeyCode:y,preventScrolling:g=!0,children:v,noWheelClassName:S,noPanClassName:C,onViewportChange:k,isControlledViewport:N,paneClickDistance:j,selectionOnDrag:T}){const R=zr(),M=b.useRef(null),{userSelectionActive:_,lib:F,connectionInProgress:z}=er(JJ,Wr),L=o0(y),U=b.useRef();ZJ(M);const K=b.useCallback(q=>{k?.({x:q[0],y:q[1],zoom:q[2]}),N||R.setState({transform:q})},[k,N]);return b.useEffect(()=>{if(M.current){U.current=oJ({domNode:M.current,minZoom:p,maxZoom:h,translateExtent:m,viewport:u,onDraggingChange:E=>R.setState($=>$.paneDragging===E?$:{paneDragging:E}),onPanZoomStart:(E,$)=>{const{onViewportChangeStart:Y,onMoveStart:W}=R.getState();W?.(E,$),Y?.($)},onPanZoom:(E,$)=>{const{onViewportChange:Y,onMove:W}=R.getState();W?.(E,$),Y?.($)},onPanZoomEnd:(E,$)=>{const{onViewportChangeEnd:Y,onMoveEnd:W}=R.getState();W?.(E,$),Y?.($)}});const{x:q,y:I,zoom:D}=U.current.getViewport();return R.setState({panZoom:U.current,transform:[q,I,D],domNode:M.current.closest(".react-flow")}),()=>{U.current?.destroy()}}},[]),b.useEffect(()=>{U.current?.update({onPaneContextMenu:e,zoomOnScroll:t,zoomOnPinch:r,panOnScroll:s,panOnScrollSpeed:a,panOnScrollMode:i,zoomOnDoubleClick:l,panOnDrag:d,zoomActivationKeyPressed:L,preventScrolling:g,noPanClassName:C,userSelectionActive:_,noWheelClassName:S,lib:F,onTransformChange:K,connectionInProgress:z,selectionOnDrag:T,paneClickDistance:j})},[e,t,r,s,a,i,l,d,L,g,C,_,S,F,K,z,T,j]),n.jsx("div",{className:"react-flow__renderer",ref:M,style:zh,children:v})}const tee=e=>({userSelectionActive:e.userSelectionActive,userSelectionRect:e.userSelectionRect});function nee(){const{userSelectionActive:e,userSelectionRect:t}=er(tee,Wr);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 Fx=(e,t)=>r=>{r.target===t.current&&e?.(r)},ree=e=>({userSelectionActive:e.userSelectionActive,elementsSelectable:e.elementsSelectable,connectionInProgress:e.connection.inProgress,dragging:e.paneDragging});function see({isSelecting:e,selectionKeyPressed:t,selectionMode:r=s0.Full,panOnDrag:s,paneClickDistance:a,selectionOnDrag:i,onSelectionStart:l,onSelectionEnd:d,onPaneClick:u,onPaneContextMenu:m,onPaneScroll:p,onPaneMouseEnter:h,onPaneMouseMove:y,onPaneMouseLeave:g,children:v}){const S=zr(),{userSelectionActive:C,elementsSelectable:k,dragging:N,connectionInProgress:j}=er(ree,Wr),T=k&&(e||C),R=b.useRef(null),M=b.useRef(),_=b.useRef(new Set),F=b.useRef(new Set),z=b.useRef(!1),L=Y=>{if(z.current||j){z.current=!1;return}u?.(Y),S.getState().resetSelectedElements(),S.setState({nodesSelectionActive:!1})},U=Y=>{if(Array.isArray(s)&&s?.includes(2)){Y.preventDefault();return}m?.(Y)},K=p?Y=>p(Y):void 0,q=Y=>{z.current&&(Y.stopPropagation(),z.current=!1)},I=Y=>{const{domNode:W}=S.getState();if(M.current=W?.getBoundingClientRect(),!M.current)return;const O=Y.target===R.current;if(!O&&!!Y.target.closest(".nokey")||!e||!(i&&O||t)||Y.button!==0||!Y.isPrimary)return;Y.target?.setPointerCapture?.(Y.pointerId),z.current=!1;const{x:B,y:J}=yi(Y.nativeEvent,M.current);S.setState({userSelectionRect:{width:0,height:0,startX:B,startY:J,x:B,y:J}}),O||(Y.stopPropagation(),Y.preventDefault())},D=Y=>{const{userSelectionRect:W,transform:O,nodeLookup:H,edgeLookup:Z,connectionLookup:B,triggerNodeChanges:J,triggerEdgeChanges:Q,defaultEdgeOptions:ee,resetSelectedElements:se}=S.getState();if(!M.current||!W)return;const{x:X,y:me}=yi(Y.nativeEvent,M.current),{startX:je,startY:Re}=W;if(!z.current){const Ae=t?0:a;if(Math.hypot(X-je,me-Re)<=Ae)return;se(),l?.(Y)}z.current=!0;const Ee={startX:je,startY:Re,x:X<je?X:je,y:me<Re?me:Re,width:Math.abs(X-je),height:Math.abs(me-Re)},we=_.current,pe=F.current;_.current=new Set(ry(H,Ee,O,r===s0.Partial,!0).map(Ae=>Ae.id)),F.current=new Set;const Pe=ee?.selectable??!0;for(const Ae of _.current){const Xe=B.get(Ae);if(Xe)for(const{edgeId:Ze}of Xe.values()){const at=Z.get(Ze);at&&(at.selectable??Pe)&&F.current.add(Ze)}}if(!u3(we,_.current)){const Ae=Qc(H,_.current,!0);J(Ae)}if(!u3(pe,F.current)){const Ae=Qc(Z,F.current);Q(Ae)}S.setState({userSelectionRect:Ee,userSelectionActive:!0,nodesSelectionActive:!1})},E=Y=>{Y.button===0&&(Y.target?.releasePointerCapture?.(Y.pointerId),!C&&Y.target===R.current&&S.getState().userSelectionRect&&L?.(Y),S.setState({userSelectionActive:!1,userSelectionRect:null}),z.current&&(d?.(Y),S.setState({nodesSelectionActive:_.current.size>0})))},$=s===!0||Array.isArray(s)&&s.includes(0);return n.jsxs("div",{className:ps(["react-flow__pane",{draggable:$,dragging:N,selection:e}]),onClick:T?void 0:Fx(L,R),onContextMenu:Fx(U,R),onWheel:Fx(K,R),onPointerEnter:T?void 0:h,onPointerMove:T?D:y,onPointerUp:T?E:void 0,onPointerDownCapture:T?I:void 0,onClickCapture:T?q:void 0,onPointerLeave:g,ref:R,style:zh,children:[v,n.jsx(nee,{})]})}function Jb({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",$i.error012(e));return}t.setState({nodesSelectionActive:!1}),m.selected?(r||m.selected&&l)&&(i({nodes:[m],edges:[]}),requestAnimationFrame(()=>s?.current?.blur())):a([e])}function Z8({nodeRef:e,disabled:t=!1,noDragClassName:r,handleSelector:s,nodeId:a,isSelectable:i,nodeClickDistance:l}){const d=zr(),[u,m]=b.useState(!1),p=b.useRef();return b.useEffect(()=>{p.current=KZ({getStoreItems:()=>d.getState(),onNodeMouseDown:h=>{Jb({id:h,store:d,nodeRef:e})},onDragStart:()=>{m(!0)},onDragStop:()=>{m(!1)}})},[]),b.useEffect(()=>{if(!(t||!e.current||!p.current))return p.current.update({noDragClassName:r,handleSelector:s,domNode:e.current,isSelectable:i,nodeId:a,nodeClickDistance:l}),()=>{p.current?.destroy()}},[r,s,t,i,e,a,l]),u}const aee=e=>t=>t.selected&&(t.draggable||e&&typeof t.draggable>"u");function J8(){const e=zr();return b.useCallback(r=>{const{nodeExtent:s,snapToGrid:a,snapGrid:i,nodesDraggable:l,onError:d,updateNodePositions:u,nodeLookup:m,nodeOrigin:p}=e.getState(),h=new Map,y=aee(l),g=a?i[0]:5,v=a?i[1]:5,S=r.direction.x*g*r.factor,C=r.direction.y*v*r.factor;for(const[,k]of m){if(!y(k))continue;let N={x:k.internals.positionAbsolute.x+S,y:k.internals.positionAbsolute.y+C};a&&(N=w0(N,i));const{position:j,positionAbsolute:T}=b8({nodeId:k.id,nextPosition:N,nodeLookup:m,nodeExtent:s,nodeOrigin:p,onError:d});k.position=j,k.internals.positionAbsolute=T,h.set(k.id,k)}u(h)},[])}const my=b.createContext(null),iee=my.Provider;my.Consumer;const e7=()=>b.useContext(my),oee=e=>({connectOnClick:e.connectOnClick,noPanClassName:e.noPanClassName,rfId:e.rfId}),lee=(e,t,r)=>s=>{const{connectionClickStartHandle:a,connectionMode:i,connection:l}=s,{fromHandle:d,toHandle:u,isValid:m}=l,p=u?.nodeId===e&&u?.id===t&&u?.type===r;return{connectingFrom:d?.nodeId===e&&d?.id===t&&d?.type===r,connectingTo:p,clickConnecting:a?.nodeId===e&&a?.id===t&&a?.type===r,isPossibleEndHandle:i===ud.Strict?d?.type!==r:e!==d?.nodeId||t!==d?.id,connectionInProcess:!!d,clickConnectionInProcess:!!a,valid:p&&m}};function cee({type:e="source",position:t=Yt.Top,isValidConnection:r,isConnectable:s=!0,isConnectableStart:a=!0,isConnectableEnd:i=!0,id:l,onConnect:d,children:u,className:m,onMouseDown:p,onTouchStart:h,...y},g){const v=l||null,S=e==="target",C=zr(),k=e7(),{connectOnClick:N,noPanClassName:j,rfId:T}=er(oee,Wr),{connectingFrom:R,connectingTo:M,clickConnecting:_,isPossibleEndHandle:F,connectionInProcess:z,clickConnectionInProcess:L,valid:U}=er(lee(k,v,e),Wr);k||C.getState().onError?.("010",$i.error010());const K=D=>{const{defaultEdgeOptions:E,onConnect:$,hasDefaultEdges:Y}=C.getState(),W={...E,...D};if(Y){const{edges:O,setEdges:H}=C.getState();H(DZ(W,O))}$?.(W),d?.(W)},q=D=>{if(!k)return;const E=C8(D.nativeEvent);if(a&&(E&&D.button===0||!E)){const $=C.getState();Zb.onPointerDown(D.nativeEvent,{handleDomNode:D.currentTarget,autoPanOnConnect:$.autoPanOnConnect,connectionMode:$.connectionMode,connectionRadius:$.connectionRadius,domNode:$.domNode,nodeLookup:$.nodeLookup,lib:$.lib,isTarget:S,handleId:v,nodeId:k,flowId:$.rfId,panBy:$.panBy,cancelConnection:$.cancelConnection,onConnectStart:$.onConnectStart,onConnectEnd:(...Y)=>C.getState().onConnectEnd?.(...Y),updateConnection:$.updateConnection,onConnect:K,isValidConnection:r||((...Y)=>C.getState().isValidConnection?.(...Y)??!0),getTransform:()=>C.getState().transform,getFromHandle:()=>C.getState().connection.fromHandle,autoPanSpeed:$.autoPanSpeed,dragThreshold:$.connectionDragThreshold})}E?p?.(D):h?.(D)},I=D=>{const{onClickConnectStart:E,onClickConnectEnd:$,connectionClickStartHandle:Y,connectionMode:W,isValidConnection:O,lib:H,rfId:Z,nodeLookup:B,connection:J}=C.getState();if(!k||!Y&&!a)return;if(!Y){E?.(D.nativeEvent,{nodeId:k,handleId:v,handleType:e}),C.setState({connectionClickStartHandle:{nodeId:k,type:e,id:v}});return}const Q=N8(D.target),ee=r||O,{connection:se,isValid:X}=Zb.isValid(D.nativeEvent,{handle:{nodeId:k,id:v,type:e},connectionMode:W,fromNodeId:Y.nodeId,fromHandleId:Y.id||null,fromType:Y.type,isValidConnection:ee,flowId:Z,doc:Q,lib:H,nodeLookup:B});X&&se&&K(se);const me=structuredClone(J);delete me.inProgress,me.toPosition=me.toHandle?me.toHandle.position:null,$?.(D,me),C.setState({connectionClickStartHandle:null})};return n.jsx("div",{"data-handleid":v,"data-nodeid":k,"data-handlepos":t,"data-id":`${T}-${k}-${v}-${e}`,className:ps(["react-flow__handle",`react-flow__handle-${t}`,"nodrag",j,m,{source:!S,target:S,connectable:s,connectablestart:a,connectableend:i,clickconnecting:_,connectingfrom:R,connectingto:M,valid:U,connectionindicator:s&&(!z||F)&&(z||L?i:a)}]),onMouseDown:q,onTouchStart:q,onClick:N?I:void 0,ref:g,...y,children:u})}const pl=b.memo(X8(cee));function dee({data:e,isConnectable:t,sourcePosition:r=Yt.Bottom}){return n.jsxs(n.Fragment,{children:[e?.label,n.jsx(pl,{type:"source",position:r,isConnectable:t})]})}function uee({data:e,isConnectable:t,targetPosition:r=Yt.Top,sourcePosition:s=Yt.Bottom}){return n.jsxs(n.Fragment,{children:[n.jsx(pl,{type:"target",position:r,isConnectable:t}),e?.label,n.jsx(pl,{type:"source",position:s,isConnectable:t})]})}function mee(){return null}function fee({data:e,isConnectable:t,targetPosition:r=Yt.Top}){return n.jsxs(n.Fragment,{children:[n.jsx(pl,{type:"target",position:r,isConnectable:t}),e?.label]})}const sh={ArrowUp:{x:0,y:-1},ArrowDown:{x:0,y:1},ArrowLeft:{x:-1,y:0},ArrowRight:{x:1,y:0}},$3={input:dee,default:uee,output:fee,group:mee};function hee(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 pee=e=>{const{width:t,height:r,x:s,y:a}=v0(e.nodeLookup,{filter:i=>!!i.selected});return{width:bi(t)?t:null,height:bi(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 gee({onSelectionContextMenu:e,noPanClassName:t,disableKeyboardA11y:r}){const s=zr(),{width:a,height:i,transformString:l,userSelectionActive:d}=er(pee,Wr),u=J8(),m=b.useRef(null);b.useEffect(()=>{r||m.current?.focus({preventScroll:!0})},[r]);const p=!d&&a!==null&&i!==null;if(Z8({nodeRef:m,disabled:!p}),!p)return null;const h=e?g=>{const v=s.getState().nodes.filter(S=>S.selected);e(g,v)}:void 0,y=g=>{Object.prototype.hasOwnProperty.call(sh,g.key)&&(g.preventDefault(),u({direction:sh[g.key],factor:g.shiftKey?4:1}))};return n.jsx("div",{className:ps(["react-flow__nodesselection","react-flow__container",t]),style:{transform:l},children:n.jsx("div",{ref:m,className:"react-flow__nodesselection-rect",onContextMenu:h,tabIndex:r?void 0:-1,onKeyDown:r?void 0:y,style:{width:a,height:i}})})}const B3=typeof window<"u"?window:void 0,xee=e=>({nodesSelectionActive:e.nodesSelectionActive,userSelectionActive:e.userSelectionActive});function t7({children:e,onPaneClick:t,onPaneMouseEnter:r,onPaneMouseMove:s,onPaneMouseLeave:a,onPaneContextMenu:i,onPaneScroll:l,paneClickDistance:d,deleteKeyCode:u,selectionKeyCode:m,selectionOnDrag:p,selectionMode:h,onSelectionStart:y,onSelectionEnd:g,multiSelectionKeyCode:v,panActivationKeyCode:S,zoomActivationKeyCode:C,elementsSelectable:k,zoomOnScroll:N,zoomOnPinch:j,panOnScroll:T,panOnScrollSpeed:R,panOnScrollMode:M,zoomOnDoubleClick:_,panOnDrag:F,defaultViewport:z,translateExtent:L,minZoom:U,maxZoom:K,preventScrolling:q,onSelectionContextMenu:I,noWheelClassName:D,noPanClassName:E,disableKeyboardA11y:$,onViewportChange:Y,isControlledViewport:W}){const{nodesSelectionActive:O,userSelectionActive:H}=er(xee,Wr),Z=o0(m,{target:B3}),B=o0(S,{target:B3}),J=B||F,Q=B||T,ee=p&&J!==!0,se=Z||H||ee;return QJ({deleteKeyCode:u,multiSelectionKeyCode:v}),n.jsx(eee,{onPaneContextMenu:i,elementsSelectable:k,zoomOnScroll:N,zoomOnPinch:j,panOnScroll:Q,panOnScrollSpeed:R,panOnScrollMode:M,zoomOnDoubleClick:_,panOnDrag:!Z&&J,defaultViewport:z,translateExtent:L,minZoom:U,maxZoom:K,zoomActivationKeyCode:C,preventScrolling:q,noWheelClassName:D,noPanClassName:E,onViewportChange:Y,isControlledViewport:W,paneClickDistance:d,selectionOnDrag:ee,children:n.jsxs(see,{onSelectionStart:y,onSelectionEnd:g,onPaneClick:t,onPaneMouseEnter:r,onPaneMouseMove:s,onPaneMouseLeave:a,onPaneContextMenu:i,onPaneScroll:l,panOnDrag:J,isSelecting:!!se,selectionMode:h,selectionKeyPressed:Z,paneClickDistance:d,selectionOnDrag:ee,children:[e,O&&n.jsx(gee,{onSelectionContextMenu:I,noPanClassName:E,disableKeyboardA11y:$})]})})}t7.displayName="FlowRenderer";const bee=b.memo(t7),yee=e=>t=>e?ry(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 vee(e){return er(b.useCallback(yee(e),[e]),Wr)}const wee=e=>e.updateNodeInternals;function kee(){const e=er(wee),[t]=b.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 b.useEffect(()=>()=>{t?.disconnect()},[t]),t}function jee({node:e,nodeType:t,hasDimensions:r,resizeObserver:s}){const a=zr(),i=b.useRef(null),l=b.useRef(null),d=b.useRef(e.sourcePosition),u=b.useRef(e.targetPosition),m=b.useRef(t),p=r&&!!e.internals.handleBounds;return b.useEffect(()=>{i.current&&!e.hidden&&(!p||l.current!==i.current)&&(l.current&&s?.unobserve(l.current),s?.observe(i.current),l.current=i.current)},[p,e.hidden]),b.useEffect(()=>()=>{l.current&&(s?.unobserve(l.current),l.current=null)},[]),b.useEffect(()=>{if(i.current){const h=m.current!==t,y=d.current!==e.sourcePosition,g=u.current!==e.targetPosition;(h||y||g)&&(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 Nee({id:e,onClick:t,onMouseEnter:r,onMouseMove:s,onMouseLeave:a,onContextMenu:i,onDoubleClick:l,nodesDraggable:d,elementsSelectable:u,nodesConnectable:m,nodesFocusable:p,resizeObserver:h,noDragClassName:y,noPanClassName:g,disableKeyboardA11y:v,rfId:S,nodeTypes:C,nodeClickDistance:k,onError:N}){const{node:j,internals:T,isParent:R}=er(X=>{const me=X.nodeLookup.get(e),je=X.parentLookup.has(e);return{node:me,internals:me.internals,isParent:je}},Wr);let M=j.type||"default",_=C?.[M]||$3[M];_===void 0&&(N?.("003",$i.error003(M)),M="default",_=C?.default||$3.default);const F=!!(j.draggable||d&&typeof j.draggable>"u"),z=!!(j.selectable||u&&typeof j.selectable>"u"),L=!!(j.connectable||m&&typeof j.connectable>"u"),U=!!(j.focusable||p&&typeof j.focusable>"u"),K=zr(),q=k8(j),I=jee({node:j,nodeType:M,hasDimensions:q,resizeObserver:h}),D=Z8({nodeRef:I,disabled:j.hidden||!F,noDragClassName:y,handleSelector:j.dragHandle,nodeId:e,isSelectable:z,nodeClickDistance:k}),E=J8();if(j.hidden)return null;const $=Co(j),Y=hee(j),W=z||F||t||r||s||a,O=r?X=>r(X,{...T.userNode}):void 0,H=s?X=>s(X,{...T.userNode}):void 0,Z=a?X=>a(X,{...T.userNode}):void 0,B=i?X=>i(X,{...T.userNode}):void 0,J=l?X=>l(X,{...T.userNode}):void 0,Q=X=>{const{selectNodesOnDrag:me,nodeDragThreshold:je}=K.getState();z&&(!me||!F||je>0)&&Jb({id:e,store:K,nodeRef:I}),t&&t(X,{...T.userNode})},ee=X=>{if(!(S8(X.nativeEvent)||v)){if(f8.includes(X.key)&&z){const me=X.key==="Escape";Jb({id:e,store:K,unselect:me,nodeRef:I})}else if(F&&j.selected&&Object.prototype.hasOwnProperty.call(sh,X.key)){X.preventDefault();const{ariaLabelConfig:me}=K.getState();K.setState({ariaLiveMessage:me["node.a11yDescription.ariaLiveMessage"]({direction:X.key.replace("Arrow","").toLowerCase(),x:~~T.positionAbsolute.x,y:~~T.positionAbsolute.y})}),E({direction:sh[X.key],factor:X.shiftKey?4:1})}}},se=()=>{if(v||!I.current?.matches(":focus-visible"))return;const{transform:X,width:me,height:je,autoPanOnNodeFocus:Re,setCenter:Ee}=K.getState();if(!Re)return;ry(new Map([[e,j]]),{x:0,y:0,width:me,height:je},X,!0).length>0||Ee(j.position.x+$.width/2,j.position.y+$.height/2,{zoom:X[2]})};return n.jsx("div",{className:ps(["react-flow__node",`react-flow__node-${M}`,{[g]:F},j.className,{selected:j.selected,selectable:z,parent:R,draggable:F,dragging:D}]),ref:I,style:{zIndex:T.z,transform:`translate(${T.positionAbsolute.x}px,${T.positionAbsolute.y}px)`,pointerEvents:W?"all":"none",visibility:q?"visible":"hidden",...j.style,...Y},"data-id":e,"data-testid":`rf__node-${e}`,onMouseEnter:O,onMouseMove:H,onMouseLeave:Z,onContextMenu:B,onClick:Q,onDoubleClick:J,onKeyDown:U?ee:void 0,tabIndex:U?0:void 0,onFocus:U?se:void 0,role:j.ariaRole??(U?"group":void 0),"aria-roledescription":"node","aria-describedby":v?void 0:`${U8}-${S}`,"aria-label":j.ariaLabel,...j.domAttributes,children:n.jsx(iee,{value:e,children:n.jsx(_,{id:e,data:j.data,type:M,positionAbsoluteX:T.positionAbsolute.x,positionAbsoluteY:T.positionAbsolute.y,selected:j.selected??!1,selectable:z,draggable:F,deletable:j.deletable??!0,isConnectable:L,sourcePosition:j.sourcePosition,targetPosition:j.targetPosition,dragging:D,dragHandle:j.dragHandle,zIndex:T.z,parentId:j.parentId,...$})})})}var See=b.memo(Nee);const Cee=e=>({nodesDraggable:e.nodesDraggable,nodesConnectable:e.nodesConnectable,nodesFocusable:e.nodesFocusable,elementsSelectable:e.elementsSelectable,onError:e.onError});function n7(e){const{nodesDraggable:t,nodesConnectable:r,nodesFocusable:s,elementsSelectable:a,onError:i}=er(Cee,Wr),l=vee(e.onlyRenderVisibleElements),d=kee();return n.jsx("div",{className:"react-flow__nodes",style:zh,children:l.map(u=>n.jsx(See,{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))})}n7.displayName="NodeRenderer";const Tee=b.memo(n7);function Aee(e){return er(b.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&&AZ({sourceNode:i,targetNode:l,width:r.width,height:r.height,transform:r.transform})&&s.push(a.id)}return s},[e]),Wr)}const Eee=({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"})},Mee=({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"})},H3={[md.Arrow]:Eee,[md.ArrowClosed]:Mee};function Dee(e){const t=zr();return b.useMemo(()=>Object.prototype.hasOwnProperty.call(H3,e)?H3[e]:(t.getState().onError?.("009",$i.error009(e)),null),[e])}const Ree=({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=Dee(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},r7=({defaultColor:e,rfId:t})=>{const r=er(i=>i.edges),s=er(i=>i.defaultEdgeOptions),a=b.useMemo(()=>OZ(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(Ree,{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};r7.displayName="MarkerDefinitions";var Lee=b.memo(r7);function s7({x:e,y:t,label:r,labelStyle:s,labelShowBg:a=!0,labelBgStyle:i,labelBgPadding:l=[2,4],labelBgBorderRadius:d=2,children:u,className:m,...p}){const[h,y]=b.useState({x:1,y:0,width:0,height:0}),g=ps(["react-flow__edge-textwrapper",m]),v=b.useRef(null);return b.useEffect(()=>{if(v.current){const S=v.current.getBBox();y({x:S.x,y:S.y,width:S.width,height:S.height})}},[r]),r?n.jsxs("g",{transform:`translate(${e-h.width/2} ${t-h.height/2})`,className:g,visibility:h.width?"visible":"hidden",...p,children:[a&&n.jsx("rect",{width:h.width+2*l[0],x:-l[0],y:-l[1],height:h.height+2*l[1],className:"react-flow__edge-textbg",style:i,rx:d,ry:d}),n.jsx("text",{className:"react-flow__edge-text",y:h.height/2,dy:"0.3em",ref:v,style:s,children:r}),u]}):null}s7.displayName="EdgeText";const Iee=b.memo(s7);function $h({path:e,labelX:t,labelY:r,label:s,labelStyle:a,labelShowBg:i,labelBgStyle:l,labelBgPadding:d,labelBgBorderRadius:u,interactionWidth:m=20,...p}){return n.jsxs(n.Fragment,{children:[n.jsx("path",{...p,d:e,fill:"none",className:ps(["react-flow__edge-path",p.className])}),m?n.jsx("path",{d:e,fill:"none",strokeOpacity:0,strokeWidth:m,className:"react-flow__edge-interaction"}):null,s&&bi(t)&&bi(r)?n.jsx(Iee,{x:t,y:r,label:s,labelStyle:a,labelShowBg:i,labelBgStyle:l,labelBgPadding:d,labelBgBorderRadius:u}):null]})}function F3({pos:e,x1:t,y1:r,x2:s,y2:a}){return e===Yt.Left||e===Yt.Right?[.5*(t+s),r]:[t,.5*(r+a)]}function a7({sourceX:e,sourceY:t,sourcePosition:r=Yt.Bottom,targetX:s,targetY:a,targetPosition:i=Yt.Top}){const[l,d]=F3({pos:r,x1:e,y1:t,x2:s,y2:a}),[u,m]=F3({pos:i,x1:s,y1:a,x2:e,y2:t}),[p,h,y,g]=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}`,p,h,y,g]}function i7(e){return b.memo(({id:t,sourceX:r,sourceY:s,targetX:a,targetY:i,sourcePosition:l,targetPosition:d,label:u,labelStyle:m,labelShowBg:p,labelBgStyle:h,labelBgPadding:y,labelBgBorderRadius:g,style:v,markerEnd:S,markerStart:C,interactionWidth:k})=>{const[N,j,T]=a7({sourceX:r,sourceY:s,sourcePosition:l,targetX:a,targetY:i,targetPosition:d}),R=e.isInternal?void 0:t;return n.jsx($h,{id:R,path:N,labelX:j,labelY:T,label:u,labelStyle:m,labelShowBg:p,labelBgStyle:h,labelBgPadding:y,labelBgBorderRadius:g,style:v,markerEnd:S,markerStart:C,interactionWidth:k})})}const Pee=i7({isInternal:!1}),o7=i7({isInternal:!0});Pee.displayName="SimpleBezierEdge";o7.displayName="SimpleBezierEdgeInternal";function l7(e){return b.memo(({id:t,sourceX:r,sourceY:s,targetX:a,targetY:i,label:l,labelStyle:d,labelShowBg:u,labelBgStyle:m,labelBgPadding:p,labelBgBorderRadius:h,style:y,sourcePosition:g=Yt.Bottom,targetPosition:v=Yt.Top,markerEnd:S,markerStart:C,pathOptions:k,interactionWidth:N})=>{const[j,T,R]=Yb({sourceX:r,sourceY:s,sourcePosition:g,targetX:a,targetY:i,targetPosition:v,borderRadius:k?.borderRadius,offset:k?.offset,stepPosition:k?.stepPosition}),M=e.isInternal?void 0:t;return n.jsx($h,{id:M,path:j,labelX:T,labelY:R,label:l,labelStyle:d,labelShowBg:u,labelBgStyle:m,labelBgPadding:p,labelBgBorderRadius:h,style:y,markerEnd:S,markerStart:C,interactionWidth:N})})}const c7=l7({isInternal:!1}),d7=l7({isInternal:!0});c7.displayName="SmoothStepEdge";d7.displayName="SmoothStepEdgeInternal";function u7(e){return b.memo(({id:t,...r})=>{const s=e.isInternal?void 0:t;return n.jsx(c7,{...r,id:s,pathOptions:b.useMemo(()=>({borderRadius:0,offset:r.pathOptions?.offset}),[r.pathOptions?.offset])})})}const Oee=u7({isInternal:!1}),m7=u7({isInternal:!0});Oee.displayName="StepEdge";m7.displayName="StepEdgeInternal";function f7(e){return b.memo(({id:t,sourceX:r,sourceY:s,targetX:a,targetY:i,label:l,labelStyle:d,labelShowBg:u,labelBgStyle:m,labelBgPadding:p,labelBgBorderRadius:h,style:y,markerEnd:g,markerStart:v,interactionWidth:S})=>{const[C,k,N]=M8({sourceX:r,sourceY:s,targetX:a,targetY:i}),j=e.isInternal?void 0:t;return n.jsx($h,{id:j,path:C,labelX:k,labelY:N,label:l,labelStyle:d,labelShowBg:u,labelBgStyle:m,labelBgPadding:p,labelBgBorderRadius:h,style:y,markerEnd:g,markerStart:v,interactionWidth:S})})}const _ee=f7({isInternal:!1}),h7=f7({isInternal:!0});_ee.displayName="StraightEdge";h7.displayName="StraightEdgeInternal";function p7(e){return b.memo(({id:t,sourceX:r,sourceY:s,targetX:a,targetY:i,sourcePosition:l=Yt.Bottom,targetPosition:d=Yt.Top,label:u,labelStyle:m,labelShowBg:p,labelBgStyle:h,labelBgPadding:y,labelBgBorderRadius:g,style:v,markerEnd:S,markerStart:C,pathOptions:k,interactionWidth:N})=>{const[j,T,R]=A8({sourceX:r,sourceY:s,sourcePosition:l,targetX:a,targetY:i,targetPosition:d,curvature:k?.curvature}),M=e.isInternal?void 0:t;return n.jsx($h,{id:M,path:j,labelX:T,labelY:R,label:u,labelStyle:m,labelShowBg:p,labelBgStyle:h,labelBgPadding:y,labelBgBorderRadius:g,style:v,markerEnd:S,markerStart:C,interactionWidth:N})})}const zee=p7({isInternal:!1}),g7=p7({isInternal:!0});zee.displayName="BezierEdge";g7.displayName="BezierEdgeInternal";const q3={default:g7,straight:h7,step:m7,smoothstep:d7,simplebezier:o7},U3={sourceX:null,sourceY:null,targetX:null,targetY:null,sourcePosition:null,targetPosition:null},$ee=(e,t,r)=>r===Yt.Left?e-t:r===Yt.Right?e+t:e,Bee=(e,t,r)=>r===Yt.Top?e-t:r===Yt.Bottom?e+t:e,V3="react-flow__edgeupdater";function W3({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:ps([V3,`${V3}-${d}`]),cx:$ee(t,s,e),cy:Bee(r,s,e),r:s,stroke:"transparent",fill:"transparent"})}function Hee({isReconnectable:e,reconnectRadius:t,edge:r,sourceX:s,sourceY:a,targetX:i,targetY:l,sourcePosition:d,targetPosition:u,onReconnect:m,onReconnectStart:p,onReconnectEnd:h,setReconnecting:y,setUpdateHover:g}){const v=zr(),S=(T,R)=>{if(T.button!==0)return;const{autoPanOnConnect:M,domNode:_,connectionMode:F,connectionRadius:z,lib:L,onConnectStart:U,cancelConnection:K,nodeLookup:q,rfId:I,panBy:D,updateConnection:E}=v.getState(),$=R.type==="target",Y=(H,Z)=>{y(!1),h?.(H,r,R.type,Z)},W=H=>m?.(r,H),O=(H,Z)=>{y(!0),p?.(T,r,R.type),U?.(H,Z)};Zb.onPointerDown(T.nativeEvent,{autoPanOnConnect:M,connectionMode:F,connectionRadius:z,domNode:_,handleId:R.id,nodeId:R.nodeId,nodeLookup:q,isTarget:$,edgeUpdaterType:R.type,lib:L,flowId:I,cancelConnection:K,panBy:D,isValidConnection:(...H)=>v.getState().isValidConnection?.(...H)??!0,onConnect:W,onConnectStart:O,onConnectEnd:(...H)=>v.getState().onConnectEnd?.(...H),onReconnectEnd:Y,updateConnection:E,getTransform:()=>v.getState().transform,getFromHandle:()=>v.getState().connection.fromHandle,dragThreshold:v.getState().connectionDragThreshold,handleDomNode:T.currentTarget})},C=T=>S(T,{nodeId:r.target,id:r.targetHandle??null,type:"target"}),k=T=>S(T,{nodeId:r.source,id:r.sourceHandle??null,type:"source"}),N=()=>g(!0),j=()=>g(!1);return n.jsxs(n.Fragment,{children:[(e===!0||e==="source")&&n.jsx(W3,{position:d,centerX:s,centerY:a,radius:t,onMouseDown:C,onMouseEnter:N,onMouseOut:j,type:"source"}),(e===!0||e==="target")&&n.jsx(W3,{position:u,centerX:i,centerY:l,radius:t,onMouseDown:k,onMouseEnter:N,onMouseOut:j,type:"target"})]})}function Fee({id:e,edgesFocusable:t,edgesReconnectable:r,elementsSelectable:s,onClick:a,onDoubleClick:i,onContextMenu:l,onMouseEnter:d,onMouseMove:u,onMouseLeave:m,reconnectRadius:p,onReconnect:h,onReconnectStart:y,onReconnectEnd:g,rfId:v,edgeTypes:S,noPanClassName:C,onError:k,disableKeyboardA11y:N}){let j=er(Ee=>Ee.edgeLookup.get(e));const T=er(Ee=>Ee.defaultEdgeOptions);j=T?{...T,...j}:j;let R=j.type||"default",M=S?.[R]||q3[R];M===void 0&&(k?.("011",$i.error011(R)),R="default",M=S?.default||q3.default);const _=!!(j.focusable||t&&typeof j.focusable>"u"),F=typeof h<"u"&&(j.reconnectable||r&&typeof j.reconnectable>"u"),z=!!(j.selectable||s&&typeof j.selectable>"u"),L=b.useRef(null),[U,K]=b.useState(!1),[q,I]=b.useState(!1),D=zr(),{zIndex:E,sourceX:$,sourceY:Y,targetX:W,targetY:O,sourcePosition:H,targetPosition:Z}=er(b.useCallback(Ee=>{const we=Ee.nodeLookup.get(j.source),pe=Ee.nodeLookup.get(j.target);if(!we||!pe)return{zIndex:j.zIndex,...U3};const Pe=PZ({id:e,sourceNode:we,targetNode:pe,sourceHandle:j.sourceHandle||null,targetHandle:j.targetHandle||null,connectionMode:Ee.connectionMode,onError:k});return{zIndex:TZ({selected:j.selected,zIndex:j.zIndex,sourceNode:we,targetNode:pe,elevateOnSelect:Ee.elevateEdgesOnSelect,zIndexMode:Ee.zIndexMode}),...Pe||U3}},[j.source,j.target,j.sourceHandle,j.targetHandle,j.selected,j.zIndex]),Wr),B=b.useMemo(()=>j.markerStart?`url('#${Xb(j.markerStart,v)}')`:void 0,[j.markerStart,v]),J=b.useMemo(()=>j.markerEnd?`url('#${Xb(j.markerEnd,v)}')`:void 0,[j.markerEnd,v]);if(j.hidden||$===null||Y===null||W===null||O===null)return null;const Q=Ee=>{const{addSelectedEdges:we,unselectNodesAndEdges:pe,multiSelectionActive:Pe}=D.getState();z&&(D.setState({nodesSelectionActive:!1}),j.selected&&Pe?(pe({nodes:[],edges:[j]}),L.current?.blur()):we([e])),a&&a(Ee,j)},ee=i?Ee=>{i(Ee,{...j})}:void 0,se=l?Ee=>{l(Ee,{...j})}:void 0,X=d?Ee=>{d(Ee,{...j})}:void 0,me=u?Ee=>{u(Ee,{...j})}:void 0,je=m?Ee=>{m(Ee,{...j})}:void 0,Re=Ee=>{if(!N&&f8.includes(Ee.key)&&z){const{unselectNodesAndEdges:we,addSelectedEdges:pe}=D.getState();Ee.key==="Escape"?(L.current?.blur(),we({edges:[j]})):pe([e])}};return n.jsx("svg",{style:{zIndex:E},children:n.jsxs("g",{className:ps(["react-flow__edge",`react-flow__edge-${R}`,j.className,C,{selected:j.selected,animated:j.animated,inactive:!z&&!a,updating:U,selectable:z}]),onClick:Q,onDoubleClick:ee,onContextMenu:se,onMouseEnter:X,onMouseMove:me,onMouseLeave:je,onKeyDown:_?Re:void 0,tabIndex:_?0:void 0,role:j.ariaRole??(_?"group":"img"),"aria-roledescription":"edge","data-id":e,"data-testid":`rf__edge-${e}`,"aria-label":j.ariaLabel===null?void 0:j.ariaLabel||`Edge from ${j.source} to ${j.target}`,"aria-describedby":_?`${V8}-${v}`:void 0,ref:L,...j.domAttributes,children:[!q&&n.jsx(M,{id:e,source:j.source,target:j.target,type:j.type,selected:j.selected,animated:j.animated,selectable:z,deletable:j.deletable??!0,label:j.label,labelStyle:j.labelStyle,labelShowBg:j.labelShowBg,labelBgStyle:j.labelBgStyle,labelBgPadding:j.labelBgPadding,labelBgBorderRadius:j.labelBgBorderRadius,sourceX:$,sourceY:Y,targetX:W,targetY:O,sourcePosition:H,targetPosition:Z,data:j.data,style:j.style,sourceHandleId:j.sourceHandle,targetHandleId:j.targetHandle,markerStart:B,markerEnd:J,pathOptions:"pathOptions"in j?j.pathOptions:void 0,interactionWidth:j.interactionWidth}),F&&n.jsx(Hee,{edge:j,isReconnectable:F,reconnectRadius:p,onReconnect:h,onReconnectStart:y,onReconnectEnd:g,sourceX:$,sourceY:Y,targetX:W,targetY:O,sourcePosition:H,targetPosition:Z,setUpdateHover:K,setReconnecting:I})]})})}var qee=b.memo(Fee);const Uee=e=>({edgesFocusable:e.edgesFocusable,edgesReconnectable:e.edgesReconnectable,elementsSelectable:e.elementsSelectable,connectionMode:e.connectionMode,onError:e.onError});function x7({defaultMarkerColor:e,onlyRenderVisibleElements:t,rfId:r,edgeTypes:s,noPanClassName:a,onReconnect:i,onEdgeContextMenu:l,onEdgeMouseEnter:d,onEdgeMouseMove:u,onEdgeMouseLeave:m,onEdgeClick:p,reconnectRadius:h,onEdgeDoubleClick:y,onReconnectStart:g,onReconnectEnd:v,disableKeyboardA11y:S}){const{edgesFocusable:C,edgesReconnectable:k,elementsSelectable:N,onError:j}=er(Uee,Wr),T=Aee(t);return n.jsxs("div",{className:"react-flow__edges",children:[n.jsx(Lee,{defaultColor:e,rfId:r}),T.map(R=>n.jsx(qee,{id:R,edgesFocusable:C,edgesReconnectable:k,elementsSelectable:N,noPanClassName:a,onReconnect:i,onContextMenu:l,onMouseEnter:d,onMouseMove:u,onMouseLeave:m,onClick:p,reconnectRadius:h,onDoubleClick:y,onReconnectStart:g,onReconnectEnd:v,rfId:r,onError:j,edgeTypes:s,disableKeyboardA11y:S},R))]})}x7.displayName="EdgeRenderer";const Vee=b.memo(x7),Wee=e=>`translate(${e.transform[0]}px,${e.transform[1]}px) scale(${e.transform[2]})`;function Kee({children:e}){const t=er(Wee);return n.jsx("div",{className:"react-flow__viewport xyflow__viewport react-flow__container",style:{transform:t},children:e})}function Gee(e){const t=uy(),r=b.useRef(!1);b.useEffect(()=>{!r.current&&t.viewportInitialized&&e&&(setTimeout(()=>e(t),1),r.current=!0)},[e,t.viewportInitialized])}const Yee=e=>e.panZoom?.syncViewport;function Xee(e){const t=er(Yee),r=zr();return b.useEffect(()=>{e&&(t?.(e),r.setState({transform:[e.x,e.y,e.zoom]}))},[e,t]),null}function Qee(e){return e.connection.inProgress?{...e.connection,to:k0(e.connection.to,e.transform)}:{...e.connection}}function Zee(e){return Qee}function Jee(e){const t=Zee();return er(t,Wr)}const ete=e=>({nodesConnectable:e.nodesConnectable,isValid:e.connection.isValid,inProgress:e.connection.inProgress,width:e.width,height:e.height});function tte({containerStyle:e,style:t,type:r,component:s}){const{nodesConnectable:a,width:i,height:l,isValid:d,inProgress:u}=er(ete,Wr);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:ps(["react-flow__connection",g8(d)]),children:n.jsx(b7,{style:t,type:r,CustomComponent:s,isValid:d})})})}const b7=({style:e,type:t=al.Bezier,CustomComponent:r,isValid:s})=>{const{inProgress:a,from:i,fromNode:l,fromHandle:d,fromPosition:u,to:m,toNode:p,toHandle:h,toPosition:y,pointer:g}=Jee();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:g8(s),toNode:p,toHandle:h,pointer:g});let v="";const S={sourceX:i.x,sourceY:i.y,sourcePosition:u,targetX:m.x,targetY:m.y,targetPosition:y};switch(t){case al.Bezier:[v]=A8(S);break;case al.SimpleBezier:[v]=a7(S);break;case al.Step:[v]=Yb({...S,borderRadius:0});break;case al.SmoothStep:[v]=Yb(S);break;default:[v]=M8(S)}return n.jsx("path",{d:v,fill:"none",className:"react-flow__connection-path",style:e})};b7.displayName="ConnectionLine";const nte={};function K3(e=nte){b.useRef(e),zr(),b.useEffect(()=>{},[e])}function rte(){zr(),b.useRef(!1),b.useEffect(()=>{},[])}function y7({nodeTypes:e,edgeTypes:t,onInit:r,onNodeClick:s,onEdgeClick:a,onNodeDoubleClick:i,onEdgeDoubleClick:l,onNodeMouseEnter:d,onNodeMouseMove:u,onNodeMouseLeave:m,onNodeContextMenu:p,onSelectionContextMenu:h,onSelectionStart:y,onSelectionEnd:g,connectionLineType:v,connectionLineStyle:S,connectionLineComponent:C,connectionLineContainerStyle:k,selectionKeyCode:N,selectionOnDrag:j,selectionMode:T,multiSelectionKeyCode:R,panActivationKeyCode:M,zoomActivationKeyCode:_,deleteKeyCode:F,onlyRenderVisibleElements:z,elementsSelectable:L,defaultViewport:U,translateExtent:K,minZoom:q,maxZoom:I,preventScrolling:D,defaultMarkerColor:E,zoomOnScroll:$,zoomOnPinch:Y,panOnScroll:W,panOnScrollSpeed:O,panOnScrollMode:H,zoomOnDoubleClick:Z,panOnDrag:B,onPaneClick:J,onPaneMouseEnter:Q,onPaneMouseMove:ee,onPaneMouseLeave:se,onPaneScroll:X,onPaneContextMenu:me,paneClickDistance:je,nodeClickDistance:Re,onEdgeContextMenu:Ee,onEdgeMouseEnter:we,onEdgeMouseMove:pe,onEdgeMouseLeave:Pe,reconnectRadius:Ae,onReconnect:Xe,onReconnectStart:Ze,onReconnectEnd:at,noDragClassName:pt,noWheelClassName:Ct,noPanClassName:_e,disableKeyboardA11y:ue,nodeExtent:fe,rfId:Me,viewport:ne,onViewportChange:he}){return K3(e),K3(t),rte(),Gee(r),Xee(ne),n.jsx(bee,{onPaneClick:J,onPaneMouseEnter:Q,onPaneMouseMove:ee,onPaneMouseLeave:se,onPaneContextMenu:me,onPaneScroll:X,paneClickDistance:je,deleteKeyCode:F,selectionKeyCode:N,selectionOnDrag:j,selectionMode:T,onSelectionStart:y,onSelectionEnd:g,multiSelectionKeyCode:R,panActivationKeyCode:M,zoomActivationKeyCode:_,elementsSelectable:L,zoomOnScroll:$,zoomOnPinch:Y,zoomOnDoubleClick:Z,panOnScroll:W,panOnScrollSpeed:O,panOnScrollMode:H,panOnDrag:B,defaultViewport:U,translateExtent:K,minZoom:q,maxZoom:I,onSelectionContextMenu:h,preventScrolling:D,noDragClassName:pt,noWheelClassName:Ct,noPanClassName:_e,disableKeyboardA11y:ue,onViewportChange:he,isControlledViewport:!!ne,children:n.jsxs(Kee,{children:[n.jsx(Vee,{edgeTypes:t,onEdgeClick:a,onEdgeDoubleClick:l,onReconnect:Xe,onReconnectStart:Ze,onReconnectEnd:at,onlyRenderVisibleElements:z,onEdgeContextMenu:Ee,onEdgeMouseEnter:we,onEdgeMouseMove:pe,onEdgeMouseLeave:Pe,reconnectRadius:Ae,defaultMarkerColor:E,noPanClassName:_e,disableKeyboardA11y:ue,rfId:Me}),n.jsx(tte,{style:S,type:v,component:C,containerStyle:k}),n.jsx("div",{className:"react-flow__edgelabel-renderer"}),n.jsx(Tee,{nodeTypes:e,onNodeClick:s,onNodeDoubleClick:i,onNodeMouseEnter:d,onNodeMouseMove:u,onNodeMouseLeave:m,onNodeContextMenu:p,nodeClickDistance:Re,onlyRenderVisibleElements:z,noPanClassName:_e,noDragClassName:pt,disableKeyboardA11y:ue,nodeExtent:fe,rfId:Me}),n.jsx("div",{className:"react-flow__viewport-portal"})]})})}y7.displayName="GraphView";const ste=b.memo(y7),G3=({nodes:e,edges:t,defaultNodes:r,defaultEdges:s,width:a,height:i,fitView:l,fitViewOptions:d,minZoom:u=.5,maxZoom:m=2,nodeOrigin:p,nodeExtent:h,zIndexMode:y="basic"}={})=>{const g=new Map,v=new Map,S=new Map,C=new Map,k=s??t??[],N=r??e??[],j=p??[0,0],T=h??r0;L8(S,C,k);const R=Qb(N,g,v,{nodeOrigin:j,nodeExtent:T,zIndexMode:y});let M=[0,0,1];if(l&&a&&i){const _=v0(g,{filter:U=>!!((U.width||U.initialWidth)&&(U.height||U.initialHeight))}),{x:F,y:z,zoom:L}=sy(_,a,i,u,m,d?.padding??.1);M=[F,z,L]}return{rfId:"1",width:a??0,height:i??0,transform:M,nodes:N,nodesInitialized:R,nodeLookup:g,parentLookup:v,edges:k,edgeLookup:C,connectionLookup:S,onNodesChange:null,onEdgesChange:null,hasDefaultNodes:r!==void 0,hasDefaultEdges:s!==void 0,panZoom:null,minZoom:u,maxZoom:m,translateExtent:r0,nodeExtent:T,nodesSelectionActive:!1,userSelectionActive:!1,userSelectionRect:null,connectionMode:ud.Strict,domNode:null,paneDragging:!1,noPanClassName:"nopan",nodeOrigin:j,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:{...p8},connectionClickStartHandle:null,connectOnClick:!0,ariaLiveMessage:"",autoPanOnConnect:!0,autoPanOnNodeDrag:!0,autoPanOnNodeFocus:!0,autoPanSpeed:15,connectionRadius:20,onError:wZ,isValidConnection:void 0,onSelectionChangeHandlers:[],lib:"react",debug:!1,ariaLabelConfig:h8,zIndexMode:y,onNodesChangeMiddlewareMap:new Map,onEdgesChangeMiddlewareMap:new Map}},ate=({nodes:e,edges:t,defaultNodes:r,defaultEdges:s,width:a,height:i,fitView:l,fitViewOptions:d,minZoom:u,maxZoom:m,nodeOrigin:p,nodeExtent:h,zIndexMode:y})=>jJ((g,v)=>{async function S(){const{nodeLookup:C,panZoom:k,fitViewOptions:N,fitViewResolver:j,width:T,height:R,minZoom:M,maxZoom:_}=v();k&&(await yZ({nodes:C,width:T,height:R,panZoom:k,minZoom:M,maxZoom:_},N),j?.resolve(!0),g({fitViewResolver:null}))}return{...G3({nodes:e,edges:t,width:a,height:i,fitView:l,fitViewOptions:d,minZoom:u,maxZoom:m,nodeOrigin:p,nodeExtent:h,defaultNodes:r,defaultEdges:s,zIndexMode:y}),setNodes:C=>{const{nodeLookup:k,parentLookup:N,nodeOrigin:j,elevateNodesOnSelect:T,fitViewQueued:R,zIndexMode:M}=v(),_=Qb(C,k,N,{nodeOrigin:j,nodeExtent:h,elevateNodesOnSelect:T,checkEquality:!0,zIndexMode:M});R&&_?(S(),g({nodes:C,nodesInitialized:_,fitViewQueued:!1,fitViewOptions:void 0})):g({nodes:C,nodesInitialized:_})},setEdges:C=>{const{connectionLookup:k,edgeLookup:N}=v();L8(k,N,C),g({edges:C})},setDefaultNodesAndEdges:(C,k)=>{if(C){const{setNodes:N}=v();N(C),g({hasDefaultNodes:!0})}if(k){const{setEdges:N}=v();N(k),g({hasDefaultEdges:!0})}},updateNodeInternals:C=>{const{triggerNodeChanges:k,nodeLookup:N,parentLookup:j,domNode:T,nodeOrigin:R,nodeExtent:M,debug:_,fitViewQueued:F,zIndexMode:z}=v(),{changes:L,updatedInternals:U}=qZ(C,N,j,T,R,M,z);U&&($Z(N,j,{nodeOrigin:R,nodeExtent:M,zIndexMode:z}),F?(S(),g({fitViewQueued:!1,fitViewOptions:void 0})):g({}),L?.length>0&&(_&&console.log("React Flow: trigger node changes",L),k?.(L)))},updateNodePositions:(C,k=!1)=>{const N=[];let j=[];const{nodeLookup:T,triggerNodeChanges:R,connection:M,updateConnection:_,onNodesChangeMiddlewareMap:F}=v();for(const[z,L]of C){const U=T.get(z),K=!!(U?.expandParent&&U?.parentId&&L?.position),q={id:z,type:"position",position:K?{x:Math.max(0,L.position.x),y:Math.max(0,L.position.y)}:L.position,dragging:k};if(U&&M.inProgress&&M.fromNode.id===U.id){const I=rc(U,M.fromHandle,Yt.Left,!0);_({...M,from:I})}K&&U.parentId&&N.push({id:z,parentId:U.parentId,rect:{...L.internals.positionAbsolute,width:L.measured.width??0,height:L.measured.height??0}}),j.push(q)}if(N.length>0){const{parentLookup:z,nodeOrigin:L}=v(),U=dy(N,T,z,L);j.push(...U)}for(const z of F.values())j=z(j);R(j)},triggerNodeChanges:C=>{const{onNodesChange:k,setNodes:N,nodes:j,hasDefaultNodes:T,debug:R}=v();if(C?.length){if(T){const M=G8(C,j);N(M)}R&&console.log("React Flow: trigger node changes",C),k?.(C)}},triggerEdgeChanges:C=>{const{onEdgesChange:k,setEdges:N,edges:j,hasDefaultEdges:T,debug:R}=v();if(C?.length){if(T){const M=Y8(C,j);N(M)}R&&console.log("React Flow: trigger edge changes",C),k?.(C)}},addSelectedNodes:C=>{const{multiSelectionActive:k,edgeLookup:N,nodeLookup:j,triggerNodeChanges:T,triggerEdgeChanges:R}=v();if(k){const M=C.map(_=>ql(_,!0));T(M);return}T(Qc(j,new Set([...C]),!0)),R(Qc(N))},addSelectedEdges:C=>{const{multiSelectionActive:k,edgeLookup:N,nodeLookup:j,triggerNodeChanges:T,triggerEdgeChanges:R}=v();if(k){const M=C.map(_=>ql(_,!0));R(M);return}R(Qc(N,new Set([...C]))),T(Qc(j,new Set,!0))},unselectNodesAndEdges:({nodes:C,edges:k}={})=>{const{edges:N,nodes:j,nodeLookup:T,triggerNodeChanges:R,triggerEdgeChanges:M}=v(),_=C||j,F=k||N,z=[];for(const U of _){if(!U.selected)continue;const K=T.get(U.id);K&&(K.selected=!1),z.push(ql(U.id,!1))}const L=[];for(const U of F)U.selected&&L.push(ql(U.id,!1));R(z),M(L)},setMinZoom:C=>{const{panZoom:k,maxZoom:N}=v();k?.setScaleExtent([C,N]),g({minZoom:C})},setMaxZoom:C=>{const{panZoom:k,minZoom:N}=v();k?.setScaleExtent([N,C]),g({maxZoom:C})},setTranslateExtent:C=>{v().panZoom?.setTranslateExtent(C),g({translateExtent:C})},resetSelectedElements:()=>{const{edges:C,nodes:k,triggerNodeChanges:N,triggerEdgeChanges:j,elementsSelectable:T}=v();if(!T)return;const R=k.reduce((_,F)=>F.selected?[..._,ql(F.id,!1)]:_,[]),M=C.reduce((_,F)=>F.selected?[..._,ql(F.id,!1)]:_,[]);N(R),j(M)},setNodeExtent:C=>{const{nodes:k,nodeLookup:N,parentLookup:j,nodeOrigin:T,elevateNodesOnSelect:R,nodeExtent:M,zIndexMode:_}=v();C[0][0]===M[0][0]&&C[0][1]===M[0][1]&&C[1][0]===M[1][0]&&C[1][1]===M[1][1]||(Qb(k,N,j,{nodeOrigin:T,nodeExtent:C,elevateNodesOnSelect:R,checkEquality:!1,zIndexMode:_}),g({nodeExtent:C}))},panBy:C=>{const{transform:k,width:N,height:j,panZoom:T,translateExtent:R}=v();return UZ({delta:C,panZoom:T,transform:k,translateExtent:R,width:N,height:j})},setCenter:async(C,k,N)=>{const{width:j,height:T,maxZoom:R,panZoom:M}=v();if(!M)return Promise.resolve(!1);const _=typeof N?.zoom<"u"?N.zoom:R;return await M.setViewport({x:j/2-C*_,y:T/2-k*_,zoom:_},{duration:N?.duration,ease:N?.ease,interpolate:N?.interpolate}),Promise.resolve(!0)},cancelConnection:()=>{g({connection:{...p8}})},updateConnection:C=>{g({connection:C})},reset:()=>g({...G3()})}},Object.is);function ite({initialNodes:e,initialEdges:t,defaultNodes:r,defaultEdges:s,initialWidth:a,initialHeight:i,initialMinZoom:l,initialMaxZoom:d,initialFitViewOptions:u,fitView:m,nodeOrigin:p,nodeExtent:h,zIndexMode:y,children:g}){const[v]=b.useState(()=>ate({nodes:e,edges:t,defaultNodes:r,defaultEdges:s,width:a,height:i,fitView:m,minZoom:l,maxZoom:d,fitViewOptions:u,nodeOrigin:p,nodeExtent:h,zIndexMode:y}));return n.jsx(NJ,{value:v,children:n.jsx(KJ,{children:g})})}function ote({children:e,nodes:t,edges:r,defaultNodes:s,defaultEdges:a,width:i,height:l,fitView:d,fitViewOptions:u,minZoom:m,maxZoom:p,nodeOrigin:h,nodeExtent:y,zIndexMode:g}){return b.useContext(Oh)?n.jsx(n.Fragment,{children:e}):n.jsx(ite,{initialNodes:t,initialEdges:r,defaultNodes:s,defaultEdges:a,initialWidth:i,initialHeight:l,fitView:d,initialFitViewOptions:u,initialMinZoom:m,initialMaxZoom:p,nodeOrigin:h,nodeExtent:y,zIndexMode:g,children:e})}const lte={width:"100%",height:"100%",overflow:"hidden",position:"relative",zIndex:0};function cte({nodes:e,edges:t,defaultNodes:r,defaultEdges:s,className:a,nodeTypes:i,edgeTypes:l,onNodeClick:d,onEdgeClick:u,onInit:m,onMove:p,onMoveStart:h,onMoveEnd:y,onConnect:g,onConnectStart:v,onConnectEnd:S,onClickConnectStart:C,onClickConnectEnd:k,onNodeMouseEnter:N,onNodeMouseMove:j,onNodeMouseLeave:T,onNodeContextMenu:R,onNodeDoubleClick:M,onNodeDragStart:_,onNodeDrag:F,onNodeDragStop:z,onNodesDelete:L,onEdgesDelete:U,onDelete:K,onSelectionChange:q,onSelectionDragStart:I,onSelectionDrag:D,onSelectionDragStop:E,onSelectionContextMenu:$,onSelectionStart:Y,onSelectionEnd:W,onBeforeDelete:O,connectionMode:H,connectionLineType:Z=al.Bezier,connectionLineStyle:B,connectionLineComponent:J,connectionLineContainerStyle:Q,deleteKeyCode:ee="Backspace",selectionKeyCode:se="Shift",selectionOnDrag:X=!1,selectionMode:me=s0.Full,panActivationKeyCode:je="Space",multiSelectionKeyCode:Re=i0()?"Meta":"Control",zoomActivationKeyCode:Ee=i0()?"Meta":"Control",snapToGrid:we,snapGrid:pe,onlyRenderVisibleElements:Pe=!1,selectNodesOnDrag:Ae,nodesDraggable:Xe,autoPanOnNodeFocus:Ze,nodesConnectable:at,nodesFocusable:pt,nodeOrigin:Ct=W8,edgesFocusable:_e,edgesReconnectable:ue,elementsSelectable:fe=!0,defaultViewport:Me=_J,minZoom:ne=.5,maxZoom:he=2,translateExtent:Be=r0,preventScrolling:de=!0,nodeExtent:Ce,defaultMarkerColor:et="#b1b1b7",zoomOnScroll:it=!0,zoomOnPinch:Ve=!0,panOnScroll:Ge=!1,panOnScrollSpeed:ut=.5,panOnScrollMode:nt=Xl.Free,zoomOnDoubleClick:ft=!0,panOnDrag:Rt=!0,onPaneClick:lt,onPaneMouseEnter:$e,onPaneMouseMove:ct,onPaneMouseLeave:Ut,onPaneScroll:zt,onPaneContextMenu:cn,paneClickDistance:Ln=1,nodeClickDistance:Xt=0,children:kn,onReconnect:tr,onReconnectStart:ir,onReconnectEnd:gs,onEdgeContextMenu:wr,onEdgeDoubleClick:or,onEdgeMouseEnter:Ue,onEdgeMouseMove:Lt,onEdgeMouseLeave:Zt,reconnectRadius:Ft=10,onNodesChange:lr,onEdgesChange:_n,noDragClassName:dn="nodrag",noWheelClassName:Sn="nowheel",noPanClassName:Cn="nopan",fitView:$r,fitViewOptions:Mr,connectOnClick:hn,attributionPosition:Ne,proOptions:At,defaultEdgeOptions:Vt,elevateNodesOnSelect:rn=!0,elevateEdgesOnSelect:Jt=!1,disableKeyboardA11y:Ot=!1,autoPanOnConnect:Fn,autoPanOnNodeDrag:$n,autoPanSpeed:js,connectionRadius:kr,isValidConnection:xe,onError:Qe,style:xt,id:Kt,nodeDragThreshold:on,connectionDragThreshold:en,viewport:un,onViewportChange:jn,width:Bn,height:rr,colorMode:Dr="light",debug:Bt,onScroll:nr,ariaLabelConfig:Ir,zIndexMode:cr="basic",...Va},Gr){const $s=Kt||"1",Bs=HJ(Dr),sa=b.useCallback(Pr=>{Pr.currentTarget.scrollTo({top:0,left:0,behavior:"instant"}),nr?.(Pr)},[nr]);return n.jsx("div",{"data-testid":"rf__wrapper",...Va,onScroll:sa,style:{...xt,...lte},ref:Gr,className:ps(["react-flow",a,Bs]),id:Kt,role:"application",children:n.jsxs(ote,{nodes:e,edges:t,width:Bn,height:rr,fitView:$r,fitViewOptions:Mr,minZoom:ne,maxZoom:he,nodeOrigin:Ct,nodeExtent:Ce,zIndexMode:cr,children:[n.jsx(ste,{onInit:m,onNodeClick:d,onEdgeClick:u,onNodeMouseEnter:N,onNodeMouseMove:j,onNodeMouseLeave:T,onNodeContextMenu:R,onNodeDoubleClick:M,nodeTypes:i,edgeTypes:l,connectionLineType:Z,connectionLineStyle:B,connectionLineComponent:J,connectionLineContainerStyle:Q,selectionKeyCode:se,selectionOnDrag:X,selectionMode:me,deleteKeyCode:ee,multiSelectionKeyCode:Re,panActivationKeyCode:je,zoomActivationKeyCode:Ee,onlyRenderVisibleElements:Pe,defaultViewport:Me,translateExtent:Be,minZoom:ne,maxZoom:he,preventScrolling:de,zoomOnScroll:it,zoomOnPinch:Ve,zoomOnDoubleClick:ft,panOnScroll:Ge,panOnScrollSpeed:ut,panOnScrollMode:nt,panOnDrag:Rt,onPaneClick:lt,onPaneMouseEnter:$e,onPaneMouseMove:ct,onPaneMouseLeave:Ut,onPaneScroll:zt,onPaneContextMenu:cn,paneClickDistance:Ln,nodeClickDistance:Xt,onSelectionContextMenu:$,onSelectionStart:Y,onSelectionEnd:W,onReconnect:tr,onReconnectStart:ir,onReconnectEnd:gs,onEdgeContextMenu:wr,onEdgeDoubleClick:or,onEdgeMouseEnter:Ue,onEdgeMouseMove:Lt,onEdgeMouseLeave:Zt,reconnectRadius:Ft,defaultMarkerColor:et,noDragClassName:dn,noWheelClassName:Sn,noPanClassName:Cn,rfId:$s,disableKeyboardA11y:Ot,nodeExtent:Ce,viewport:un,onViewportChange:jn}),n.jsx(BJ,{nodes:e,edges:t,defaultNodes:r,defaultEdges:s,onConnect:g,onConnectStart:v,onConnectEnd:S,onClickConnectStart:C,onClickConnectEnd:k,nodesDraggable:Xe,autoPanOnNodeFocus:Ze,nodesConnectable:at,nodesFocusable:pt,edgesFocusable:_e,edgesReconnectable:ue,elementsSelectable:fe,elevateNodesOnSelect:rn,elevateEdgesOnSelect:Jt,minZoom:ne,maxZoom:he,nodeExtent:Ce,onNodesChange:lr,onEdgesChange:_n,snapToGrid:we,snapGrid:pe,connectionMode:H,translateExtent:Be,connectOnClick:hn,defaultEdgeOptions:Vt,fitView:$r,fitViewOptions:Mr,onNodesDelete:L,onEdgesDelete:U,onDelete:K,onNodeDragStart:_,onNodeDrag:F,onNodeDragStop:z,onSelectionDrag:D,onSelectionDragStart:I,onSelectionDragStop:E,onMove:p,onMoveStart:h,onMoveEnd:y,noPanClassName:Cn,nodeOrigin:Ct,rfId:$s,autoPanOnConnect:Fn,autoPanOnNodeDrag:$n,autoPanSpeed:js,onError:Qe,connectionRadius:kr,isValidConnection:xe,selectNodesOnDrag:Ae,nodeDragThreshold:on,connectionDragThreshold:en,onBeforeDelete:O,debug:Bt,ariaLabelConfig:Ir,zIndexMode:cr}),n.jsx(OJ,{onSelectionChange:q}),kn,n.jsx(DJ,{proOptions:At,position:Ne}),n.jsx(MJ,{rfId:$s,disableKeyboardA11y:Ot})]})})}var dte=X8(cte);function ute(){const e=zr();return b.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 mte(e){const[t,r]=b.useState(e),s=b.useCallback(a=>r(i=>G8(a,i)),[]);return[t,r,s]}function fte(e){const[t,r]=b.useState(e),s=b.useCallback(a=>r(i=>Y8(a,i)),[]);return[t,r,s]}function hte({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:ps(["react-flow__background-pattern",r,s])})}function pte({radius:e,className:t}){return n.jsx("circle",{cx:e,cy:e,r:e,className:ps(["react-flow__background-pattern","dots",t])})}var cl;(function(e){e.Lines="lines",e.Dots="dots",e.Cross="cross"})(cl||(cl={}));const gte={[cl.Dots]:1,[cl.Lines]:1,[cl.Cross]:6},xte=e=>({transform:e.transform,patternId:`pattern-${e.rfId}`});function v7({id:e,variant:t=cl.Dots,gap:r=20,size:s,lineWidth:a=1,offset:i=0,color:l,bgColor:d,style:u,className:m,patternClassName:p}){const h=b.useRef(null),{transform:y,patternId:g}=er(xte,Wr),v=s||gte[t],S=t===cl.Dots,C=t===cl.Cross,k=Array.isArray(r)?r:[r,r],N=[k[0]*y[2]||1,k[1]*y[2]||1],j=v*y[2],T=Array.isArray(i)?i:[i,i],R=C?[j,j]:N,M=[T[0]*y[2]||1+R[0]/2,T[1]*y[2]||1+R[1]/2],_=`${g}${e||""}`;return n.jsxs("svg",{className:ps(["react-flow__background",m]),style:{...u,...zh,"--xy-background-color-props":d,"--xy-background-pattern-color-props":l},ref:h,"data-testid":"rf__background",children:[n.jsx("pattern",{id:_,x:y[0]%N[0],y:y[1]%N[1],width:N[0],height:N[1],patternUnits:"userSpaceOnUse",patternTransform:`translate(-${M[0]},-${M[1]})`,children:S?n.jsx(pte,{radius:j/2,className:p}):n.jsx(hte,{dimensions:R,lineWidth:a,variant:t,className:p})}),n.jsx("rect",{x:"0",y:"0",width:"100%",height:"100%",fill:`url(#${_})`})]})}v7.displayName="Background";const bte=b.memo(v7);function yte(){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 vte(){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 wte(){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 kte(){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 jte(){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 of({children:e,className:t,...r}){return n.jsx("button",{type:"button",className:ps(["react-flow__controls-button",t]),...r,children:e})}const Nte=e=>({isInteractive:e.nodesDraggable||e.nodesConnectable||e.elementsSelectable,minZoomReached:e.transform[2]<=e.minZoom,maxZoomReached:e.transform[2]>=e.maxZoom,ariaLabelConfig:e.ariaLabelConfig});function w7({style:e,showZoom:t=!0,showFitView:r=!0,showInteractive:s=!0,fitViewOptions:a,onZoomIn:i,onZoomOut:l,onFitView:d,onInteractiveChange:u,className:m,children:p,position:h="bottom-left",orientation:y="vertical","aria-label":g}){const v=zr(),{isInteractive:S,minZoomReached:C,maxZoomReached:k,ariaLabelConfig:N}=er(Nte,Wr),{zoomIn:j,zoomOut:T,fitView:R}=uy(),M=()=>{j(),i?.()},_=()=>{T(),l?.()},F=()=>{R(a),d?.()},z=()=>{v.setState({nodesDraggable:!S,nodesConnectable:!S,elementsSelectable:!S}),u?.(!S)},L=y==="horizontal"?"horizontal":"vertical";return n.jsxs(_h,{className:ps(["react-flow__controls",L,m]),position:h,style:e,"data-testid":"rf__controls","aria-label":g??N["controls.ariaLabel"],children:[t&&n.jsxs(n.Fragment,{children:[n.jsx(of,{onClick:M,className:"react-flow__controls-zoomin",title:N["controls.zoomIn.ariaLabel"],"aria-label":N["controls.zoomIn.ariaLabel"],disabled:k,children:n.jsx(yte,{})}),n.jsx(of,{onClick:_,className:"react-flow__controls-zoomout",title:N["controls.zoomOut.ariaLabel"],"aria-label":N["controls.zoomOut.ariaLabel"],disabled:C,children:n.jsx(vte,{})})]}),r&&n.jsx(of,{className:"react-flow__controls-fitview",onClick:F,title:N["controls.fitView.ariaLabel"],"aria-label":N["controls.fitView.ariaLabel"],children:n.jsx(wte,{})}),s&&n.jsx(of,{className:"react-flow__controls-interactive",onClick:z,title:N["controls.interactive.ariaLabel"],"aria-label":N["controls.interactive.ariaLabel"],children:S?n.jsx(jte,{}):n.jsx(kte,{})}),p]})}w7.displayName="Controls";const Ste=b.memo(w7);function Cte({id:e,x:t,y:r,width:s,height:a,style:i,color:l,strokeColor:d,strokeWidth:u,className:m,borderRadius:p,shapeRendering:h,selected:y,onClick:g}){const{background:v,backgroundColor:S}=i||{},C=l||v||S;return n.jsx("rect",{className:ps(["react-flow__minimap-node",{selected:y},m]),x:t,y:r,rx:p,ry:p,width:s,height:a,style:{fill:C,stroke:d,strokeWidth:u},shapeRendering:h,onClick:g?k=>g(k,e):void 0})}const Tte=b.memo(Cte),Ate=e=>e.nodes.map(t=>t.id),qx=e=>e instanceof Function?e:()=>e;function Ete({nodeStrokeColor:e,nodeColor:t,nodeClassName:r="",nodeBorderRadius:s=5,nodeStrokeWidth:a,nodeComponent:i=Tte,onClick:l}){const d=er(Ate,Wr),u=qx(t),m=qx(e),p=qx(r),h=typeof window>"u"||window.chrome?"crispEdges":"geometricPrecision";return n.jsx(n.Fragment,{children:d.map(y=>n.jsx(Dte,{id:y,nodeColorFunc:u,nodeStrokeColorFunc:m,nodeClassNameFunc:p,nodeBorderRadius:s,nodeStrokeWidth:a,NodeComponent:i,onClick:l,shapeRendering:h},y))})}function Mte({id:e,nodeColorFunc:t,nodeStrokeColorFunc:r,nodeClassNameFunc:s,nodeBorderRadius:a,nodeStrokeWidth:i,shapeRendering:l,NodeComponent:d,onClick:u}){const{node:m,x:p,y:h,width:y,height:g}=er(v=>{const S=v.nodeLookup.get(e);if(!S)return{node:void 0,x:0,y:0,width:0,height:0};const C=S.internals.userNode,{x:k,y:N}=S.internals.positionAbsolute,{width:j,height:T}=Co(C);return{node:C,x:k,y:N,width:j,height:T}},Wr);return!m||m.hidden||!k8(m)?null:n.jsx(d,{x:p,y:h,width:y,height:g,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 Dte=b.memo(Mte);var Rte=b.memo(Ete);const Lte=200,Ite=150,Pte=e=>!e.hidden,Ote=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?w8(v0(e.nodeLookup,{filter:Pte}),t):t,rfId:e.rfId,panZoom:e.panZoom,translateExtent:e.translateExtent,flowWidth:e.width,flowHeight:e.height,ariaLabelConfig:e.ariaLabelConfig}},_te="react-flow__minimap-desc";function k7({style:e,className:t,nodeStrokeColor:r,nodeColor:s,nodeClassName:a="",nodeBorderRadius:i=5,nodeStrokeWidth:l,nodeComponent:d,bgColor:u,maskColor:m,maskStrokeColor:p,maskStrokeWidth:h,position:y="bottom-right",onClick:g,onNodeClick:v,pannable:S=!1,zoomable:C=!1,ariaLabel:k,inversePan:N,zoomStep:j=1,offsetScale:T=5}){const R=zr(),M=b.useRef(null),{boundingRect:_,viewBB:F,rfId:z,panZoom:L,translateExtent:U,flowWidth:K,flowHeight:q,ariaLabelConfig:I}=er(Ote,Wr),D=e?.width??Lte,E=e?.height??Ite,$=_.width/D,Y=_.height/E,W=Math.max($,Y),O=W*D,H=W*E,Z=T*W,B=_.x-(O-_.width)/2-Z,J=_.y-(H-_.height)/2-Z,Q=O+Z*2,ee=H+Z*2,se=`${_te}-${z}`,X=b.useRef(0),me=b.useRef();X.current=W,b.useEffect(()=>{if(M.current&&L)return me.current=JZ({domNode:M.current,panZoom:L,getTransform:()=>R.getState().transform,getViewScale:()=>X.current}),()=>{me.current?.destroy()}},[L]),b.useEffect(()=>{me.current?.update({translateExtent:U,width:K,height:q,inversePan:N,pannable:S,zoomStep:j,zoomable:C})},[S,C,N,j,U,K,q]);const je=g?we=>{const[pe,Pe]=me.current?.pointer(we)||[0,0];g(we,{x:pe,y:Pe})}:void 0,Re=v?b.useCallback((we,pe)=>{const Pe=R.getState().nodeLookup.get(pe).internals.userNode;v(we,Pe)},[]):void 0,Ee=k??I["minimap.ariaLabel"];return n.jsx(_h,{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 p=="string"?p:void 0,"--xy-minimap-mask-stroke-width-props":typeof h=="number"?h*W: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:ps(["react-flow__minimap",t]),"data-testid":"rf__minimap",children:n.jsxs("svg",{width:D,height:E,viewBox:`${B} ${J} ${Q} ${ee}`,className:"react-flow__minimap-svg",role:"img","aria-labelledby":se,ref:M,onClick:je,children:[Ee&&n.jsx("title",{id:se,children:Ee}),n.jsx(Rte,{onClick:Re,nodeColor:s,nodeStrokeColor:r,nodeBorderRadius:i,nodeClassName:a,nodeStrokeWidth:l,nodeComponent:d}),n.jsx("path",{className:"react-flow__minimap-mask",d:`M${B-Z},${J-Z}h${Q+Z*2}v${ee+Z*2}h${-Q-Z*2}z
704
704
  M${F.x},${F.y}h${F.width}v${F.height}h${-F.width}z`,fillRule:"evenodd",pointerEvents:"none"})]})})}k7.displayName="MiniMap";const zte=b.memo(k7),$te=e=>t=>e?`${Math.max(1/t.transform[2],1)}`:void 0,Bte={[gd.Line]:"right",[gd.Handle]:"bottom-right"};function Hte({nodeId:e,position:t,variant:r=gd.Handle,className:s,style:a=void 0,children:i,color:l,minWidth:d=10,minHeight:u=10,maxWidth:m=Number.MAX_VALUE,maxHeight:p=Number.MAX_VALUE,keepAspectRatio:h=!1,resizeDirection:y,autoScale:g=!0,shouldResize:v,onResizeStart:S,onResize:C,onResizeEnd:k}){const N=e7(),j=typeof e=="string"?e:N,T=zr(),R=b.useRef(null),M=r===gd.Handle,_=er(b.useCallback($te(M&&g),[M,g]),Wr),F=b.useRef(null),z=t??Bte[r];b.useEffect(()=>{if(!(!R.current||!j))return F.current||(F.current=fJ({domNode:R.current,nodeId:j,getStoreItems:()=>{const{nodeLookup:U,transform:K,snapGrid:q,snapToGrid:I,nodeOrigin:D,domNode:E}=T.getState();return{nodeLookup:U,transform:K,snapGrid:q,snapToGrid:I,nodeOrigin:D,paneDomNode:E}},onChange:(U,K)=>{const{triggerNodeChanges:q,nodeLookup:I,parentLookup:D,nodeOrigin:E}=T.getState(),$=[],Y={x:U.x,y:U.y},W=I.get(j);if(W&&W.expandParent&&W.parentId){const O=W.origin??E,H=U.width??W.measured.width??0,Z=U.height??W.measured.height??0,B={id:W.id,parentId:W.parentId,rect:{width:H,height:Z,...j8({x:U.x??W.position.x,y:U.y??W.position.y},{width:H,height:Z},W.parentId,I,O)}},J=dy([B],I,D,E);$.push(...J),Y.x=U.x?Math.max(O[0]*H,U.x):void 0,Y.y=U.y?Math.max(O[1]*Z,U.y):void 0}if(Y.x!==void 0&&Y.y!==void 0){const O={id:j,type:"position",position:{...Y}};$.push(O)}if(U.width!==void 0&&U.height!==void 0){const H={id:j,type:"dimensions",resizing:!0,setAttributes:y?y==="horizontal"?"width":"height":!0,dimensions:{width:U.width,height:U.height}};$.push(H)}for(const O of K){const H={...O,type:"position"};$.push(H)}q($)},onEnd:({width:U,height:K})=>{const q={id:j,type:"dimensions",resizing:!1,dimensions:{width:U,height:K}};T.getState().triggerNodeChanges([q])}})),F.current.update({controlPosition:z,boundaries:{minWidth:d,minHeight:u,maxWidth:m,maxHeight:p},keepAspectRatio:h,resizeDirection:y,onResizeStart:S,onResize:C,onResizeEnd:k,shouldResize:v}),()=>{F.current?.destroy()}},[z,d,u,m,p,h,S,C,k,v]);const L=z.split("-");return n.jsx("div",{className:ps(["react-flow__resize-control","nodrag",...L,r,s]),ref:R,style:{...a,scale:_,...l&&{[M?"backgroundColor":"borderColor"]:l}},children:i})}b.memo(Hte);var vr=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),wi=vr((e,t)=>{var r=Object.defineProperty,s=(q,I,D)=>I in q?r(q,I,{enumerable:!0,configurable:!0,writable:!0,value:D}):q[I]=D,a=(q,I)=>()=>(I||q((I={exports:{}}).exports,I),I.exports),i=(q,I,D)=>s(q,typeof I!="symbol"?I+"":I,D),l=a((q,I)=>{var D="\0",E="\0",$="",Y=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[E]={})}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(Q=>Object.keys(J._in[Q]).length===0)}sinks(){var J=this;return this.nodes().filter(Q=>Object.keys(J._out[Q]).length===0)}setNodes(J,Q){var ee=arguments,se=this;return J.forEach(function(X){ee.length>1?se.setNode(X,Q):se.setNode(X)}),this}setNode(J,Q){return Object.hasOwn(this._nodes,J)?(arguments.length>1&&(this._nodes[J]=Q),this):(this._nodes[J]=arguments.length>1?Q:this._defaultNodeLabelFn(J),this._isCompound&&(this._parent[J]=E,this._children[J]={},this._children[E][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 Q=this;if(Object.hasOwn(this._nodes,J)){var ee=se=>Q.removeEdge(Q._edgeObjs[se]);delete this._nodes[J],this._isCompound&&(this._removeFromParentsChildList(J),delete this._parent[J],this.children(J).forEach(function(se){Q.setParent(se)}),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,Q){if(!this._isCompound)throw new Error("Cannot set parent in a non-compound graph");if(Q===void 0)Q=E;else{Q+="";for(var ee=Q;ee!==void 0;ee=this.parent(ee))if(ee===J)throw new Error("Setting "+Q+" as parent of "+J+" would create a cycle");this.setNode(Q)}return this.setNode(J),this._removeFromParentsChildList(J),this._parent[J]=Q,this._children[Q][J]=!0,this}_removeFromParentsChildList(J){delete this._children[this._parent[J]][J]}parent(J){if(this._isCompound){var Q=this._parent[J];if(Q!==E)return Q}}children(J=E){if(this._isCompound){var Q=this._children[J];if(Q)return Object.keys(Q)}else{if(J===E)return this.nodes();if(this.hasNode(J))return[]}}predecessors(J){var Q=this._preds[J];if(Q)return Object.keys(Q)}successors(J){var Q=this._sucs[J];if(Q)return Object.keys(Q)}neighbors(J){var Q=this.predecessors(J);if(Q){let se=new Set(Q);for(var ee of this.successors(J))se.add(ee);return Array.from(se.values())}}isLeaf(J){var Q;return this.isDirected()?Q=this.successors(J):Q=this.neighbors(J),Q.length===0}filterNodes(J){var Q=new this.constructor({directed:this._isDirected,multigraph:this._isMultigraph,compound:this._isCompound});Q.setGraph(this.graph());var ee=this;Object.entries(this._nodes).forEach(function([me,je]){J(me)&&Q.setNode(me,je)}),Object.values(this._edgeObjs).forEach(function(me){Q.hasNode(me.v)&&Q.hasNode(me.w)&&Q.setEdge(me,ee.edge(me))});var se={};function X(me){var je=ee.parent(me);return je===void 0||Q.hasNode(je)?(se[me]=je,je):je in se?se[je]:X(je)}return this._isCompound&&Q.nodes().forEach(me=>Q.setParent(me,X(me))),Q}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,Q){var ee=this,se=arguments;return J.reduce(function(X,me){return se.length>1?ee.setEdge(X,me,Q):ee.setEdge(X,me),me}),this}setEdge(){var J,Q,ee,se,X=!1,me=arguments[0];typeof me=="object"&&me!==null&&"v"in me?(J=me.v,Q=me.w,ee=me.name,arguments.length===2&&(se=arguments[1],X=!0)):(J=me,Q=arguments[1],ee=arguments[3],arguments.length>2&&(se=arguments[2],X=!0)),J=""+J,Q=""+Q,ee!==void 0&&(ee=""+ee);var je=H(this._isDirected,J,Q,ee);if(Object.hasOwn(this._edgeLabels,je))return X&&(this._edgeLabels[je]=se),this;if(ee!==void 0&&!this._isMultigraph)throw new Error("Cannot set a named edge when isMultigraph = false");this.setNode(J),this.setNode(Q),this._edgeLabels[je]=X?se:this._defaultEdgeLabelFn(J,Q,ee);var Re=Z(this._isDirected,J,Q,ee);return J=Re.v,Q=Re.w,Object.freeze(Re),this._edgeObjs[je]=Re,W(this._preds[Q],J),W(this._sucs[J],Q),this._in[Q][je]=Re,this._out[J][je]=Re,this._edgeCount++,this}edge(J,Q,ee){var se=arguments.length===1?B(this._isDirected,arguments[0]):H(this._isDirected,J,Q,ee);return this._edgeLabels[se]}edgeAsObj(){let J=this.edge(...arguments);return typeof J!="object"?{label:J}:J}hasEdge(J,Q,ee){var se=arguments.length===1?B(this._isDirected,arguments[0]):H(this._isDirected,J,Q,ee);return Object.hasOwn(this._edgeLabels,se)}removeEdge(J,Q,ee){var se=arguments.length===1?B(this._isDirected,arguments[0]):H(this._isDirected,J,Q,ee),X=this._edgeObjs[se];return X&&(J=X.v,Q=X.w,delete this._edgeLabels[se],delete this._edgeObjs[se],O(this._preds[Q],J),O(this._sucs[J],Q),delete this._in[Q][se],delete this._out[J][se],this._edgeCount--),this}inEdges(J,Q){return this.isDirected()?this.filterEdges(this._in[J],J,Q):this.nodeEdges(J,Q)}outEdges(J,Q){return this.isDirected()?this.filterEdges(this._out[J],J,Q):this.nodeEdges(J,Q)}nodeEdges(J,Q){if(J in this._nodes)return this.filterEdges({...this._in[J],...this._out[J]},J,Q)}filterEdges(J,Q,ee){if(J){var se=Object.values(J);return ee?se.filter(function(X){return X.v===Q&&X.w===ee||X.v===ee&&X.w===Q}):se}}};function W(J,Q){J[Q]?J[Q]++:J[Q]=1}function O(J,Q){--J[Q]||delete J[Q]}function H(J,Q,ee,se){var X=""+Q,me=""+ee;if(!J&&X>me){var je=X;X=me,me=je}return X+$+me+$+(se===void 0?D:se)}function Z(J,Q,ee,se){var X=""+Q,me=""+ee;if(!J&&X>me){var je=X;X=me,me=je}var Re={v:X,w:me};return se&&(Re.name=se),Re}function B(J,Q){return H(J,Q.v,Q.w,Q.name)}I.exports=Y}),d=a((q,I)=>{I.exports="3.0.2"}),u=a((q,I)=>{I.exports={Graph:l(),version:d()}}),m=a((q,I)=>{var D=l();I.exports={write:E,read:W};function E(O){var H={options:{directed:O.isDirected(),multigraph:O.isMultigraph(),compound:O.isCompound()},nodes:$(O),edges:Y(O)};return O.graph()!==void 0&&(H.value=structuredClone(O.graph())),H}function $(O){return O.nodes().map(function(H){var Z=O.node(H),B=O.parent(H),J={v:H};return Z!==void 0&&(J.value=Z),B!==void 0&&(J.parent=B),J})}function Y(O){return O.edges().map(function(H){var Z=O.edge(H),B={v:H.v,w:H.w};return H.name!==void 0&&(B.name=H.name),Z!==void 0&&(B.value=Z),B})}function W(O){var H=new D(O.options).setGraph(O.value);return O.nodes.forEach(function(Z){H.setNode(Z.v,Z.value),Z.parent&&H.setParent(Z.v,Z.parent)}),O.edges.forEach(function(Z){H.setEdge({v:Z.v,w:Z.w,name:Z.name},Z.value)}),H}}),p=a((q,I)=>{I.exports=E;var D=()=>1;function E(Y,W,O,H){return $(Y,String(W),O||D,H||function(Z){return Y.outEdges(Z)})}function $(Y,W,O,H){var Z={},B=!0,J=0,Q=Y.nodes(),ee=function(je){var Re=O(je);Z[je.v].distance+Re<Z[je.w].distance&&(Z[je.w]={distance:Z[je.v].distance+Re,predecessor:je.v},B=!0)},se=function(){Q.forEach(function(je){H(je).forEach(function(Re){var Ee=Re.v===je?Re.v:Re.w,we=Ee===Re.v?Re.w:Re.v;ee({v:Ee,w:we})})})};Q.forEach(function(je){var Re=je===W?0:Number.POSITIVE_INFINITY;Z[je]={distance:Re}});for(var X=Q.length,me=1;me<X&&(B=!1,J++,se(),!!B);me++);if(J===X-1&&(B=!1,se(),B))throw new Error("The graph contains a negative weight cycle");return Z}}),h=a((q,I)=>{I.exports=D;function D(E){var $={},Y=[],W;function O(H){Object.hasOwn($,H)||($[H]=!0,W.push(H),E.successors(H).forEach(O),E.predecessors(H).forEach(O))}return E.nodes().forEach(function(H){W=[],O(H),W.length&&Y.push(W)}),Y}}),y=a((q,I)=>{var D=class{constructor(){i(this,"_arr",[]),i(this,"_keyIndices",{})}size(){return this._arr.length}keys(){return this._arr.map(function(E){return E.key})}has(E){return Object.hasOwn(this._keyIndices,E)}priority(E){var $=this._keyIndices[E];if($!==void 0)return this._arr[$].priority}min(){if(this.size()===0)throw new Error("Queue underflow");return this._arr[0].key}add(E,$){var Y=this._keyIndices;if(E=String(E),!Object.hasOwn(Y,E)){var W=this._arr,O=W.length;return Y[E]=O,W.push({key:E,priority:$}),this._decrease(O),!0}return!1}removeMin(){this._swap(0,this._arr.length-1);var E=this._arr.pop();return delete this._keyIndices[E.key],this._heapify(0),E.key}decrease(E,$){var Y=this._keyIndices[E];if($>this._arr[Y].priority)throw new Error("New priority is greater than current priority. Key: "+E+" Old: "+this._arr[Y].priority+" New: "+$);this._arr[Y].priority=$,this._decrease(Y)}_heapify(E){var $=this._arr,Y=2*E,W=Y+1,O=E;Y<$.length&&(O=$[Y].priority<$[O].priority?Y:O,W<$.length&&(O=$[W].priority<$[O].priority?W:O),O!==E&&(this._swap(E,O),this._heapify(O)))}_decrease(E){for(var $=this._arr,Y=$[E].priority,W;E!==0&&(W=E>>1,!($[W].priority<Y));)this._swap(E,W),E=W}_swap(E,$){var Y=this._arr,W=this._keyIndices,O=Y[E],H=Y[$];Y[E]=H,Y[$]=O,W[H.key]=E,W[O.key]=$}};I.exports=D}),g=a((q,I)=>{var D=y();I.exports=$;var E=()=>1;function $(W,O,H,Z){var B=function(J){return W.outEdges(J)};return Y(W,String(O),H||E,Z||B)}function Y(W,O,H,Z){var B={},J=new D,Q,ee,se=function(X){var me=X.v!==Q?X.v:X.w,je=B[me],Re=H(X),Ee=ee.distance+Re;if(Re<0)throw new Error("dijkstra does not allow negative edge weights. Bad edge: "+X+" Weight: "+Re);Ee<je.distance&&(je.distance=Ee,je.predecessor=Q,J.decrease(me,Ee))};for(W.nodes().forEach(function(X){var me=X===O?0:Number.POSITIVE_INFINITY;B[X]={distance:me},J.add(X,me)});J.size()>0&&(Q=J.removeMin(),ee=B[Q],ee.distance!==Number.POSITIVE_INFINITY);)Z(Q).forEach(se);return B}}),v=a((q,I)=>{var D=g();I.exports=E;function E($,Y,W){return $.nodes().reduce(function(O,H){return O[H]=D($,H,Y,W),O},{})}}),S=a((q,I)=>{I.exports=D;function D($,Y,W){if($[Y].predecessor!==void 0)throw new Error("Invalid source vertex");if($[W].predecessor===void 0&&W!==Y)throw new Error("Invalid destination vertex");return{weight:$[W].distance,path:E($,Y,W)}}function E($,Y,W){for(var O=[],H=W;H!==Y;)O.push(H),H=$[H].predecessor;return O.push(Y),O.reverse()}}),C=a((q,I)=>{I.exports=D;function D(E){var $=0,Y=[],W={},O=[];function H(Z){var B=W[Z]={onStack:!0,lowlink:$,index:$++};if(Y.push(Z),E.successors(Z).forEach(function(ee){Object.hasOwn(W,ee)?W[ee].onStack&&(B.lowlink=Math.min(B.lowlink,W[ee].index)):(H(ee),B.lowlink=Math.min(B.lowlink,W[ee].lowlink))}),B.lowlink===B.index){var J=[],Q;do Q=Y.pop(),W[Q].onStack=!1,J.push(Q);while(Z!==Q);O.push(J)}}return E.nodes().forEach(function(Z){Object.hasOwn(W,Z)||H(Z)}),O}}),k=a((q,I)=>{var D=C();I.exports=E;function E($){return D($).filter(function(Y){return Y.length>1||Y.length===1&&$.hasEdge(Y[0],Y[0])})}}),N=a((q,I)=>{I.exports=E;var D=()=>1;function E(Y,W,O){return $(Y,W||D,O||function(H){return Y.outEdges(H)})}function $(Y,W,O){var H={},Z=Y.nodes();return Z.forEach(function(B){H[B]={},H[B][B]={distance:0},Z.forEach(function(J){B!==J&&(H[B][J]={distance:Number.POSITIVE_INFINITY})}),O(B).forEach(function(J){var Q=J.v===B?J.w:J.v,ee=W(J);H[B][Q]={distance:ee,predecessor:B}})}),Z.forEach(function(B){var J=H[B];Z.forEach(function(Q){var ee=H[Q];Z.forEach(function(se){var X=ee[B],me=J[se],je=ee[se],Re=X.distance+me.distance;Re<je.distance&&(je.distance=Re,je.predecessor=me.predecessor)})})}),H}}),j=a((q,I)=>{function D($){var Y={},W={},O=[];function H(Z){if(Object.hasOwn(W,Z))throw new E;Object.hasOwn(Y,Z)||(W[Z]=!0,Y[Z]=!0,$.predecessors(Z).forEach(H),delete W[Z],O.push(Z))}if($.sinks().forEach(H),Object.keys(Y).length!==$.nodeCount())throw new E;return O}var E=class extends Error{constructor(){super(...arguments)}};I.exports=D,D.CycleException=E}),T=a((q,I)=>{var D=j();I.exports=E;function E($){try{D($)}catch(Y){if(Y instanceof D.CycleException)return!1;throw Y}return!0}}),R=a((q,I)=>{I.exports=D;function D($,Y,W,O,H){Array.isArray(Y)||(Y=[Y]);var Z=($.isDirected()?$.successors:$.neighbors).bind($),B={};return Y.forEach(function(J){if(!$.hasNode(J))throw new Error("Graph does not have node: "+J);H=E($,J,W==="post",B,Z,O,H)}),H}function E($,Y,W,O,H,Z,B){return Object.hasOwn(O,Y)||(O[Y]=!0,W||(B=Z(B,Y)),H(Y).forEach(function(J){B=E($,J,W,O,H,Z,B)}),W&&(B=Z(B,Y))),B}}),M=a((q,I)=>{var D=R();I.exports=E;function E($,Y,W){return D($,Y,W,function(O,H){return O.push(H),O},[])}}),_=a((q,I)=>{var D=M();I.exports=E;function E($,Y){return D($,Y,"post")}}),F=a((q,I)=>{var D=M();I.exports=E;function E($,Y){return D($,Y,"pre")}}),z=a((q,I)=>{var D=l(),E=y();I.exports=$;function $(Y,W){var O=new D,H={},Z=new E,B;function J(ee){var se=ee.v===B?ee.w:ee.v,X=Z.priority(se);if(X!==void 0){var me=W(ee);me<X&&(H[se]=B,Z.decrease(se,me))}}if(Y.nodeCount()===0)return O;Y.nodes().forEach(function(ee){Z.add(ee,Number.POSITIVE_INFINITY),O.setNode(ee)}),Z.decrease(Y.nodes()[0],0);for(var Q=!1;Z.size()>0;){if(B=Z.removeMin(),Object.hasOwn(H,B))O.setEdge(B,H[B]);else{if(Q)throw new Error("Input graph is not connected: "+Y);Q=!0}Y.nodeEdges(B).forEach(J)}return O}}),L=a((q,I)=>{var D=g(),E=p();I.exports=$;function $(W,O,H,Z){return Y(W,O,H,Z||function(B){return W.outEdges(B)})}function Y(W,O,H,Z){if(H===void 0)return D(W,O,H,Z);for(var B=!1,J=W.nodes(),Q=0;Q<J.length;Q++){for(var ee=Z(J[Q]),se=0;se<ee.length;se++){var X=ee[se],me=X.v===J[Q]?X.v:X.w,je=me===X.v?X.w:X.v;H({v:me,w:je})<0&&(B=!0)}if(B)return E(W,O,H,Z)}return D(W,O,H,Z)}}),U=a((q,I)=>{I.exports={bellmanFord:p(),components:h(),dijkstra:g(),dijkstraAll:v(),extractPath:S(),findCycles:k(),floydWarshall:N(),isAcyclic:T(),postorder:_(),preorder:F(),prim:z(),shortestPaths:L(),reduce:R(),tarjan:C(),topsort:j()}}),K=u();t.exports={Graph:K.Graph,json:m(),alg:U(),version:K.version}}),Fte=vr((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}),qte=vr((e,t)=>{var r=wi().Graph,s=Fte();t.exports=i;var a=()=>1;function i(h,y){if(h.nodeCount()<=1)return[];let g=u(h,y||a);return l(g.graph,g.buckets,g.zeroIdx).flatMap(v=>h.outEdges(v.v,v.w))}function l(h,y,g){let v=[],S=y[y.length-1],C=y[0],k;for(;h.nodeCount();){for(;k=C.dequeue();)d(h,y,g,k);for(;k=S.dequeue();)d(h,y,g,k);if(h.nodeCount()){for(let N=y.length-2;N>0;--N)if(k=y[N].dequeue(),k){v=v.concat(d(h,y,g,k,!0));break}}}return v}function d(h,y,g,v,S){let C=S?[]:void 0;return h.inEdges(v.v).forEach(k=>{let N=h.edge(k),j=h.node(k.v);S&&C.push({v:k.v,w:k.w}),j.out-=N,m(y,g,j)}),h.outEdges(v.v).forEach(k=>{let N=h.edge(k),j=k.w,T=h.node(j);T.in-=N,m(y,g,T)}),h.removeNode(v.v),C}function u(h,y){let g=new r,v=0,S=0;h.nodes().forEach(N=>{g.setNode(N,{v:N,in:0,out:0})}),h.edges().forEach(N=>{let j=g.edge(N.v,N.w)||0,T=y(N),R=j+T;g.setEdge(N.v,N.w,R),S=Math.max(S,g.node(N.v).out+=T),v=Math.max(v,g.node(N.w).in+=T)});let C=p(S+v+3).map(()=>new s),k=v+1;return g.nodes().forEach(N=>{m(C,k,g.node(N))}),{graph:g,buckets:C,zeroIdx:k}}function m(h,y,g){g.out?g.in?h[g.out-g.in+y].enqueue(g):h[h.length-1].enqueue(g):h[0].enqueue(g)}function p(h){let y=[];for(let g=0;g<h;g++)y.push(g);return y}}),fs=vr((e,t)=>{var r=wi().Graph;t.exports={addBorderNode:y,addDummyNode:s,applyWithChunking:S,asNonCompoundGraph:i,buildLayerMatrix:m,intersectRect:u,mapValues:F,maxRank:C,normalizeRanks:p,notime:j,partition:k,pick:_,predecessorWeights:d,range:M,removeEmptyRanks:h,simplify:a,successorWeights:l,time:N,uniqueId:R,zipObject:z};function s(L,U,K,q){for(var I=q;L.hasNode(I);)I=R(q);return K.dummy=U,L.setNode(I,K),I}function a(L){let U=new r().setGraph(L.graph());return L.nodes().forEach(K=>U.setNode(K,L.node(K))),L.edges().forEach(K=>{let q=U.edge(K.v,K.w)||{weight:0,minlen:1},I=L.edge(K);U.setEdge(K.v,K.w,{weight:q.weight+I.weight,minlen:Math.max(q.minlen,I.minlen)})}),U}function i(L){let U=new r({multigraph:L.isMultigraph()}).setGraph(L.graph());return L.nodes().forEach(K=>{L.children(K).length||U.setNode(K,L.node(K))}),L.edges().forEach(K=>{U.setEdge(K,L.edge(K))}),U}function l(L){let U=L.nodes().map(K=>{let q={};return L.outEdges(K).forEach(I=>{q[I.w]=(q[I.w]||0)+L.edge(I).weight}),q});return z(L.nodes(),U)}function d(L){let U=L.nodes().map(K=>{let q={};return L.inEdges(K).forEach(I=>{q[I.v]=(q[I.v]||0)+L.edge(I).weight}),q});return z(L.nodes(),U)}function u(L,U){let K=L.x,q=L.y,I=U.x-K,D=U.y-q,E=L.width/2,$=L.height/2;if(!I&&!D)throw new Error("Not possible to find intersection inside of the rectangle");let Y,W;return Math.abs(D)*E>Math.abs(I)*$?(D<0&&($=-$),Y=$*I/D,W=$):(I<0&&(E=-E),Y=E,W=E*D/I),{x:K+Y,y:q+W}}function m(L){let U=M(C(L)+1).map(()=>[]);return L.nodes().forEach(K=>{let q=L.node(K),I=q.rank;I!==void 0&&(U[I][q.order]=K)}),U}function p(L){let U=L.nodes().map(q=>{let I=L.node(q).rank;return I===void 0?Number.MAX_VALUE:I}),K=S(Math.min,U);L.nodes().forEach(q=>{let I=L.node(q);Object.hasOwn(I,"rank")&&(I.rank-=K)})}function h(L){let U=L.nodes().map(E=>L.node(E).rank).filter(E=>E!==void 0),K=S(Math.min,U),q=[];L.nodes().forEach(E=>{let $=L.node(E).rank-K;q[$]||(q[$]=[]),q[$].push(E)});let I=0,D=L.graph().nodeRankFactor;Array.from(q).forEach((E,$)=>{E===void 0&&$%D!==0?--I:E!==void 0&&I&&E.forEach(Y=>L.node(Y).rank+=I)})}function y(L,U,K,q){let I={width:0,height:0};return arguments.length>=4&&(I.rank=K,I.order=q),s(L,"border",I,U)}function g(L,U=v){let K=[];for(let q=0;q<L.length;q+=U){let I=L.slice(q,q+U);K.push(I)}return K}var v=65535;function S(L,U){if(U.length>v){let K=g(U);return L.apply(null,K.map(q=>L.apply(null,q)))}else return L.apply(null,U)}function C(L){let U=L.nodes().map(K=>{let q=L.node(K).rank;return q===void 0?Number.MIN_VALUE:q});return S(Math.max,U)}function k(L,U){let K={lhs:[],rhs:[]};return L.forEach(q=>{U(q)?K.lhs.push(q):K.rhs.push(q)}),K}function N(L,U){let K=Date.now();try{return U()}finally{console.log(L+" time: "+(Date.now()-K)+"ms")}}function j(L,U){return U()}var T=0;function R(L){var U=++T;return L+(""+U)}function M(L,U,K=1){U==null&&(U=L,L=0);let q=D=>D<U;K<0&&(q=D=>U<D);let I=[];for(let D=L;q(D);D+=K)I.push(D);return I}function _(L,U){let K={};for(let q of U)L[q]!==void 0&&(K[q]=L[q]);return K}function F(L,U){let K=U;return typeof U=="string"&&(K=q=>q[U]),Object.entries(L).reduce((q,[I,D])=>(q[I]=K(D,I),q),{})}function z(L,U){return L.reduce((K,q,I)=>(K[q]=U[I],K),{})}}),Ute=vr((e,t)=>{var r=qte(),s=fs().uniqueId;t.exports={run:a,undo:l};function a(d){(d.graph().acyclicer==="greedy"?r(d,u(d)):i(d)).forEach(m=>{let p=d.edge(m);d.removeEdge(m),p.forwardName=m.name,p.reversed=!0,d.setEdge(m.w,m.v,p,s("rev"))});function u(m){return p=>m.edge(p).weight}}function i(d){let u=[],m={},p={};function h(y){Object.hasOwn(p,y)||(p[y]=!0,m[y]=!0,d.outEdges(y).forEach(g=>{Object.hasOwn(m,g.w)?u.push(g):h(g.w)}),delete m[y])}return d.nodes().forEach(h),u}function l(d){d.edges().forEach(u=>{let m=d.edge(u);if(m.reversed){d.removeEdge(u);let p=m.forwardName;delete m.reversed,delete m.forwardName,d.setEdge(u.w,u.v,m,p)}})}}),Vte=vr((e,t)=>{var r=fs();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,p=d.w,h=l.node(p).rank,y=d.name,g=l.edge(d),v=g.labelRank;if(h===m+1)return;l.removeEdge(d);let S,C,k;for(k=0,++m;m<h;++k,++m)g.points=[],C={width:0,height:0,edgeLabel:g,edgeObj:d,rank:m},S=r.addDummyNode(l,"edge",C,"_d"),m===v&&(C.width=g.width,C.height=g.height,C.dummy="edge-label",C.labelpos=g.labelpos),l.setEdge(u,S,{weight:g.weight},y),k===0&&l.graph().dummyChains.push(S),u=S;l.setEdge(u,p,{weight:g.weight},y)}function i(l){l.graph().dummyChains.forEach(d=>{let u=l.node(d),m=u.edgeLabel,p;for(l.setEdge(u.edgeObj,m);u.dummy;)p=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=p,u=l.node(d)})}}),ah=vr((e,t)=>{var{applyWithChunking:r}=fs();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 p=i.outEdges(u).map(y=>y==null?Number.POSITIVE_INFINITY:d(y.w)-i.edge(y).minlen);var h=r(Math.min,p);return h===Number.POSITIVE_INFINITY&&(h=0),m.rank=h}i.sources().forEach(d)}function a(i,l){return i.node(l.w).rank-i.node(l.v).rank-i.edge(l).minlen}}),j7=vr((e,t)=>{var r=wi().Graph,s=ah().slack;t.exports=a;function a(u){var m=new r({directed:!1}),p=u.nodes()[0],h=u.nodeCount();m.setNode(p,{});for(var y,g;i(m,u)<h;)y=l(m,u),g=m.hasNode(y.v)?s(u,y):-s(u,y),d(m,u,g);return m}function i(u,m){function p(h){m.nodeEdges(h).forEach(y=>{var g=y.v,v=h===g?y.w:g;!u.hasNode(v)&&!s(m,y)&&(u.setNode(v,{}),u.setEdge(h,v,{}),p(v))})}return u.nodes().forEach(p),u.nodeCount()}function l(u,m){return m.edges().reduce((p,h)=>{let y=Number.POSITIVE_INFINITY;return u.hasNode(h.v)!==u.hasNode(h.w)&&(y=s(m,h)),y<p[0]?[y,h]:p},[Number.POSITIVE_INFINITY,null])[1]}function d(u,m,p){u.nodes().forEach(h=>m.node(h).rank+=p)}}),Wte=vr((e,t)=>{var r=j7(),s=ah().slack,a=ah().longestPath,i=wi().alg.preorder,l=wi().alg.postorder,d=fs().simplify;t.exports=u,u.initLowLimValues=y,u.initCutValues=m,u.calcCutValue=h,u.leaveEdge=v,u.enterEdge=S,u.exchangeEdges=C;function u(T){T=d(T),a(T);var R=r(T);y(R),m(R,T);for(var M,_;M=v(R);)_=S(R,T,M),C(R,T,M,_)}function m(T,R){var M=l(T,T.nodes());M=M.slice(0,M.length-1),M.forEach(_=>p(T,R,_))}function p(T,R,M){var _=T.node(M),F=_.parent;T.edge(M,F).cutvalue=h(T,R,M)}function h(T,R,M){var _=T.node(M),F=_.parent,z=!0,L=R.edge(M,F),U=0;return L||(z=!1,L=R.edge(F,M)),U=L.weight,R.nodeEdges(M).forEach(K=>{var q=K.v===M,I=q?K.w:K.v;if(I!==F){var D=q===z,E=R.edge(K).weight;if(U+=D?E:-E,N(T,M,I)){var $=T.edge(M,I).cutvalue;U+=D?-$:$}}}),U}function y(T,R){arguments.length<2&&(R=T.nodes()[0]),g(T,{},1,R)}function g(T,R,M,_,F){var z=M,L=T.node(_);return R[_]=!0,T.neighbors(_).forEach(U=>{Object.hasOwn(R,U)||(M=g(T,R,M,U,_))}),L.low=z,L.lim=M++,F?L.parent=F:delete L.parent,M}function v(T){return T.edges().find(R=>T.edge(R).cutvalue<0)}function S(T,R,M){var _=M.v,F=M.w;R.hasEdge(_,F)||(_=M.w,F=M.v);var z=T.node(_),L=T.node(F),U=z,K=!1;z.lim>L.lim&&(U=L,K=!0);var q=R.edges().filter(I=>K===j(T,T.node(I.v),U)&&K!==j(T,T.node(I.w),U));return q.reduce((I,D)=>s(R,D)<s(R,I)?D:I)}function C(T,R,M,_){var F=M.v,z=M.w;T.removeEdge(F,z),T.setEdge(_.v,_.w,{}),y(T),m(T,R),k(T,R)}function k(T,R){var M=T.nodes().find(F=>!R.node(F).parent),_=i(T,M);_=_.slice(1),_.forEach(F=>{var z=T.node(F).parent,L=R.edge(F,z),U=!1;L||(L=R.edge(z,F),U=!0),R.node(F).rank=R.node(z).rank+(U?L.minlen:-L.minlen)})}function N(T,R,M){return T.hasEdge(R,M)}function j(T,R,M){return M.low<=R.lim&&R.lim<=M.lim}}),Kte=vr((e,t)=>{var r=ah(),s=r.longestPath,a=j7(),i=Wte();t.exports=l;function l(p){var h=p.graph().ranker;if(h instanceof Function)return h(p);switch(p.graph().ranker){case"network-simplex":m(p);break;case"tight-tree":u(p);break;case"longest-path":d(p);break;case"none":break;default:m(p)}}var d=s;function u(p){s(p),a(p)}function m(p){i(p)}}),Gte=vr((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,p=s(i,l,m.v,m.w),h=p.path,y=p.lca,g=0,v=h[g],S=!0;for(;d!==m.w;){if(u=i.node(d),S){for(;(v=h[g])!==y&&i.node(v).maxRank<u.rank;)g++;v===y&&(S=!1)}if(!S){for(;g<h.length-1&&i.node(v=h[g+1]).minRank<=u.rank;)g++;v=h[g]}i.setParent(d,v),d=i.successors(d)[0]}})}function s(i,l,d,u){let m=[],p=[],h=Math.min(l[d].low,l[u].low),y=Math.max(l[d].lim,l[u].lim),g,v;g=d;do g=i.parent(g),m.push(g);while(g&&(l[g].low>h||y>l[g].lim));for(v=g,g=u;(g=i.parent(g))!==v;)p.push(g);return{path:m.concat(p.reverse()),lca:v}}function a(i){let l={},d=0;function u(m){let p=d;i.children(m).forEach(u),l[m]={low:p,lim:d++}}return i.children().forEach(u),l}}),Yte=vr((e,t)=>{var r=fs();t.exports={run:s,cleanup:d};function s(u){let m=r.addDummyNode(u,"root",{},"_root"),p=i(u),h=Object.values(p),y=r.applyWithChunking(Math.max,h)-1,g=2*y+1;u.graph().nestingRoot=m,u.edges().forEach(S=>u.edge(S).minlen*=g);let v=l(u)+1;u.children().forEach(S=>a(u,m,g,v,y,p,S)),u.graph().nodeRankFactor=g}function a(u,m,p,h,y,g,v){let S=u.children(v);if(!S.length){v!==m&&u.setEdge(m,v,{weight:0,minlen:p});return}let C=r.addBorderNode(u,"_bt"),k=r.addBorderNode(u,"_bb"),N=u.node(v);u.setParent(C,v),N.borderTop=C,u.setParent(k,v),N.borderBottom=k,S.forEach(j=>{a(u,m,p,h,y,g,j);let T=u.node(j),R=T.borderTop?T.borderTop:j,M=T.borderBottom?T.borderBottom:j,_=T.borderTop?h:2*h,F=R!==M?1:y-g[v]+1;u.setEdge(C,R,{weight:_,minlen:F,nestingEdge:!0}),u.setEdge(M,k,{weight:_,minlen:F,nestingEdge:!0})}),u.parent(v)||u.setEdge(m,C,{weight:0,minlen:y+g[v]})}function i(u){var m={};function p(h,y){var g=u.children(h);g&&g.length&&g.forEach(v=>p(v,y+1)),m[h]=y}return u.children().forEach(h=>p(h,1)),m}function l(u){return u.edges().reduce((m,p)=>m+u.edge(p).weight,0)}function d(u){var m=u.graph();u.removeNode(m.nestingRoot),delete m.nestingRoot,u.edges().forEach(p=>{var h=u.edge(p);h.nestingEdge&&u.removeEdge(p)})}}),Xte=vr((e,t)=>{var r=fs();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 p=m.minRank,h=m.maxRank+1;p<h;++p)a(i,"borderLeft","_bl",d,m,p),a(i,"borderRight","_br",d,m,p)}}i.children().forEach(l)}function a(i,l,d,u,m,p){let h={width:0,height:0,rank:p,borderType:l},y=m[l][p-1],g=r.addDummyNode(i,"border",h,d);m[l][p]=g,i.setParent(g,u),y&&i.setEdge(y,g,{weight:1})}}),Qte=vr((e,t)=>{t.exports={adjust:r,undo:s};function r(p){let h=p.graph().rankdir.toLowerCase();(h==="lr"||h==="rl")&&a(p)}function s(p){let h=p.graph().rankdir.toLowerCase();(h==="bt"||h==="rl")&&l(p),(h==="lr"||h==="rl")&&(u(p),a(p))}function a(p){p.nodes().forEach(h=>i(p.node(h))),p.edges().forEach(h=>i(p.edge(h)))}function i(p){let h=p.width;p.width=p.height,p.height=h}function l(p){p.nodes().forEach(h=>d(p.node(h))),p.edges().forEach(h=>{let y=p.edge(h);y.points.forEach(d),Object.hasOwn(y,"y")&&d(y)})}function d(p){p.y=-p.y}function u(p){p.nodes().forEach(h=>m(p.node(h))),p.edges().forEach(h=>{let y=p.edge(h);y.points.forEach(m),Object.hasOwn(y,"x")&&m(y)})}function m(p){let h=p.x;p.x=p.y,p.y=h}}),Zte=vr((e,t)=>{var r=fs();t.exports=s;function s(a){let i={},l=a.nodes().filter(h=>!a.children(h).length),d=l.map(h=>a.node(h).rank),u=r.applyWithChunking(Math.max,d),m=r.range(u+1).map(()=>[]);function p(h){if(i[h])return;i[h]=!0;let y=a.node(h);m[y.rank].push(h),a.successors(h).forEach(p)}return l.sort((h,y)=>a.node(h).rank-a.node(y).rank).forEach(p),m}}),Jte=vr((e,t)=>{var r=fs().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,S)=>S)),m=l.flatMap(v=>i.outEdges(v).map(S=>({pos:u[S.w],weight:i.edge(S).weight})).sort((S,C)=>S.pos-C.pos)),p=1;for(;p<d.length;)p<<=1;let h=2*p-1;p-=1;let y=new Array(h).fill(0),g=0;return m.forEach(v=>{let S=v.pos+p;y[S]+=v.weight;let C=0;for(;S>0;)S%2&&(C+=y[S+1]),S=S-1>>1,y[S]+=v.weight;g+=v.weight*C}),g}}),ene=vr((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 p=s.edge(m),h=s.node(m.v);return{sum:u.sum+p.weight*h.order,weight:u.weight+p.weight}},{sum:0,weight:0});return{v:i,barycenter:d.sum/d.weight,weight:d.weight}}else return{v:i}})}}),tne=vr((e,t)=>{var r=fs();t.exports=s;function s(l,d){let u={};l.forEach((p,h)=>{let y=u[p.v]={indegree:0,in:[],out:[],vs:[p.v],i:h};p.barycenter!==void 0&&(y.barycenter=p.barycenter,y.weight=p.weight)}),d.edges().forEach(p=>{let h=u[p.v],y=u[p.w];h!==void 0&&y!==void 0&&(y.indegree++,h.out.push(u[p.w]))});let m=Object.values(u).filter(p=>!p.indegree);return a(m)}function a(l){let d=[];function u(p){return h=>{h.merged||(h.barycenter===void 0||p.barycenter===void 0||h.barycenter>=p.barycenter)&&i(p,h)}}function m(p){return h=>{h.in.push(p),--h.indegree===0&&l.push(h)}}for(;l.length;){let p=l.pop();d.push(p),p.in.reverse().forEach(u(p)),p.out.forEach(m(p))}return d.filter(p=>!p.merged).map(p=>r.pick(p,["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}}),nne=vr((e,t)=>{var r=fs();t.exports=s;function s(l,d){let u=r.partition(l,C=>Object.hasOwn(C,"barycenter")),m=u.lhs,p=u.rhs.sort((C,k)=>k.i-C.i),h=[],y=0,g=0,v=0;m.sort(i(!!d)),v=a(h,p,v),m.forEach(C=>{v+=C.vs.length,h.push(C.vs),y+=C.barycenter*C.weight,g+=C.weight,v=a(h,p,v)});let S={vs:h.flat(!0)};return g&&(S.barycenter=y/g,S.weight=g),S}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}}),rne=vr((e,t)=>{var r=ene(),s=tne(),a=nne();t.exports=i;function i(u,m,p,h){let y=u.children(m),g=u.node(m),v=g?g.borderLeft:void 0,S=g?g.borderRight:void 0,C={};v&&(y=y.filter(T=>T!==v&&T!==S));let k=r(u,y);k.forEach(T=>{if(u.children(T.v).length){let R=i(u,T.v,p,h);C[T.v]=R,Object.hasOwn(R,"barycenter")&&d(T,R)}});let N=s(k,p);l(N,C);let j=a(N,h);if(v&&(j.vs=[v,j.vs,S].flat(!0),u.predecessors(v).length)){let T=u.node(u.predecessors(v)[0]),R=u.node(u.predecessors(S)[0]);Object.hasOwn(j,"barycenter")||(j.barycenter=0,j.weight=0),j.barycenter=(j.barycenter*j.weight+T.order+R.order)/(j.weight+2),j.weight+=2}return j}function l(u,m){u.forEach(p=>{p.vs=p.vs.flatMap(h=>m[h]?m[h].vs:h)})}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)}}),sne=vr((e,t)=>{var r=wi().Graph,s=fs();t.exports=a;function a(l,d,u,m){m||(m=l.nodes());let p=i(l),h=new r({compound:!0}).setGraph({root:p}).setDefaultNodeLabel(y=>l.node(y));return m.forEach(y=>{let g=l.node(y),v=l.parent(y);(g.rank===d||g.minRank<=d&&d<=g.maxRank)&&(h.setNode(y),h.setParent(y,v||p),l[u](y).forEach(S=>{let C=S.v===y?S.w:S.v,k=h.edge(C,y),N=k!==void 0?k.weight:0;h.setEdge(C,y,{weight:l.edge(S).weight+N})}),Object.hasOwn(g,"minRank")&&h.setNode(y,{borderLeft:g.borderLeft[d],borderRight:g.borderRight[d]}))}),h}function i(l){for(var d;l.hasNode(d=s.uniqueId("_root")););return d}}),ane=vr((e,t)=>{t.exports=r;function r(s,a,i){let l={},d;i.forEach(u=>{let m=s.parent(u),p,h;for(;m;){if(p=s.parent(m),p?(h=l[p],l[p]=m):(h=d,d=m),h&&h!==m){a.setEdge(h,m);return}m=p}})}}),ine=vr((e,t)=>{var r=Zte(),s=Jte(),a=rne(),i=sne(),l=ane(),d=wi().Graph,u=fs();t.exports=m;function m(g,v={}){if(typeof v.customOrder=="function"){v.customOrder(g,m);return}let S=u.maxRank(g),C=p(g,u.range(1,S+1),"inEdges"),k=p(g,u.range(S-1,-1,-1),"outEdges"),N=r(g);if(y(g,N),v.disableOptimalOrderHeuristic)return;let j=Number.POSITIVE_INFINITY,T,R=v.constraints||[];for(let M=0,_=0;_<4;++M,++_){h(M%2?C:k,M%4>=2,R),N=u.buildLayerMatrix(g);let F=s(g,N);F<j?(_=0,T=Object.assign({},N),j=F):F===j&&(T=structuredClone(N))}y(g,T)}function p(g,v,S){let C=new Map,k=(N,j)=>{C.has(N)||C.set(N,[]),C.get(N).push(j)};for(let N of g.nodes()){let j=g.node(N);if(typeof j.rank=="number"&&k(j.rank,N),typeof j.minRank=="number"&&typeof j.maxRank=="number")for(let T=j.minRank;T<=j.maxRank;T++)T!==j.rank&&k(T,N)}return v.map(function(N){return i(g,N,S,C.get(N)||[])})}function h(g,v,S){let C=new d;g.forEach(function(k){S.forEach(T=>C.setEdge(T.left,T.right));let N=k.graph().root,j=a(k,N,C,v);j.vs.forEach((T,R)=>k.node(T).order=R),l(k,C,j.vs)})}function y(g,v){Object.values(v).forEach(S=>S.forEach((C,k)=>g.node(C).order=k))}}),one=vr((e,t)=>{var r=wi().Graph,s=fs();t.exports={positionX:S,findType1Conflicts:a,findType2Conflicts:i,addConflict:d,hasConflict:u,verticalAlignment:m,horizontalCompaction:p,alignCoordinates:g,findSmallestWidthAlignment:y,balance:v};function a(N,j){let T={};function R(M,_){let F=0,z=0,L=M.length,U=_[_.length-1];return _.forEach((K,q)=>{let I=l(N,K),D=I?N.node(I).order:L;(I||K===U)&&(_.slice(z,q+1).forEach(E=>{N.predecessors(E).forEach($=>{let Y=N.node($),W=Y.order;(W<F||D<W)&&!(Y.dummy&&N.node(E).dummy)&&d(T,$,E)})}),z=q+1,F=D)}),_}return j.length&&j.reduce(R),T}function i(N,j){let T={};function R(_,F,z,L,U){let K;s.range(F,z).forEach(q=>{K=_[q],N.node(K).dummy&&N.predecessors(K).forEach(I=>{let D=N.node(I);D.dummy&&(D.order<L||D.order>U)&&d(T,I,K)})})}function M(_,F){let z=-1,L,U=0;return F.forEach((K,q)=>{if(N.node(K).dummy==="border"){let I=N.predecessors(K);I.length&&(L=N.node(I[0]).order,R(F,U,q,z,L),U=q,z=L)}R(F,U,F.length,L,_.length)}),F}return j.length&&j.reduce(M),T}function l(N,j){if(N.node(j).dummy)return N.predecessors(j).find(T=>N.node(T).dummy)}function d(N,j,T){if(j>T){let M=j;j=T,T=M}let R=N[j];R||(N[j]=R={}),R[T]=!0}function u(N,j,T){if(j>T){let R=j;j=T,T=R}return!!N[j]&&Object.hasOwn(N[j],T)}function m(N,j,T,R){let M={},_={},F={};return j.forEach(z=>{z.forEach((L,U)=>{M[L]=L,_[L]=L,F[L]=U})}),j.forEach(z=>{let L=-1;z.forEach(U=>{let K=R(U);if(K.length){K=K.sort((I,D)=>F[I]-F[D]);let q=(K.length-1)/2;for(let I=Math.floor(q),D=Math.ceil(q);I<=D;++I){let E=K[I];_[U]===U&&L<F[E]&&!u(T,U,E)&&(_[E]=U,_[U]=M[U]=M[E],L=F[E])}}})}),{root:M,align:_}}function p(N,j,T,R,M){let _={},F=h(N,j,T,M),z=M?"borderLeft":"borderRight";function L(q,I){let D=F.nodes().slice(),E={},$=D.pop();for(;$;){if(E[$])q($);else{E[$]=!0,D.push($);for(let Y of I($))D.push(Y)}$=D.pop()}}function U(q){_[q]=F.inEdges(q).reduce((I,D)=>Math.max(I,_[D.v]+F.edge(D)),0)}function K(q){let I=F.outEdges(q).reduce((E,$)=>Math.min(E,_[$.w]-F.edge($)),Number.POSITIVE_INFINITY),D=N.node(q);I!==Number.POSITIVE_INFINITY&&D.borderType!==z&&(_[q]=Math.max(_[q],I))}return L(U,F.predecessors.bind(F)),L(K,F.successors.bind(F)),Object.keys(R).forEach(q=>_[q]=_[T[q]]),_}function h(N,j,T,R){let M=new r,_=N.graph(),F=C(_.nodesep,_.edgesep,R);return j.forEach(z=>{let L;z.forEach(U=>{let K=T[U];if(M.setNode(K),L){var q=T[L],I=M.edge(q,K);M.setEdge(q,K,Math.max(F(N,U,L),I||0))}L=U})}),M}function y(N,j){return Object.values(j).reduce((T,R)=>{let M=Number.NEGATIVE_INFINITY,_=Number.POSITIVE_INFINITY;Object.entries(R).forEach(([z,L])=>{let U=k(N,z)/2;M=Math.max(L+U,M),_=Math.min(L-U,_)});let F=M-_;return F<T[0]&&(T=[F,R]),T},[Number.POSITIVE_INFINITY,null])[1]}function g(N,j){let T=Object.values(j),R=s.applyWithChunking(Math.min,T),M=s.applyWithChunking(Math.max,T);["u","d"].forEach(_=>{["l","r"].forEach(F=>{let z=_+F,L=N[z];if(L===j)return;let U=Object.values(L),K=R-s.applyWithChunking(Math.min,U);F!=="l"&&(K=M-s.applyWithChunking(Math.max,U)),K&&(N[z]=s.mapValues(L,q=>q+K))})})}function v(N,j){return s.mapValues(N.ul,(T,R)=>{if(j)return N[j.toLowerCase()][R];{let M=Object.values(N).map(_=>_[R]).sort((_,F)=>_-F);return(M[1]+M[2])/2}})}function S(N){let j=s.buildLayerMatrix(N),T=Object.assign(a(N,j),i(N,j)),R={},M;["u","d"].forEach(F=>{M=F==="u"?j:Object.values(j).reverse(),["l","r"].forEach(z=>{z==="r"&&(M=M.map(q=>Object.values(q).reverse()));let L=(F==="u"?N.predecessors:N.successors).bind(N),U=m(N,M,T,L),K=p(N,M,U.root,U.align,z==="r");z==="r"&&(K=s.mapValues(K,q=>-q)),R[F+z]=K})});let _=y(N,R);return g(R,_),v(R,N.graph().align)}function C(N,j,T){return(R,M,_)=>{let F=R.node(M),z=R.node(_),L=0,U;if(L+=F.width/2,Object.hasOwn(F,"labelpos"))switch(F.labelpos.toLowerCase()){case"l":U=-F.width/2;break;case"r":U=F.width/2;break}if(U&&(L+=T?U:-U),U=0,L+=(F.dummy?j:N)/2,L+=(z.dummy?j:N)/2,L+=z.width/2,Object.hasOwn(z,"labelpos"))switch(z.labelpos.toLowerCase()){case"l":U=z.width/2;break;case"r":U=-z.width/2;break}return U&&(L+=T?U:-U),U=0,L}}function k(N,j){return N.node(j).width}}),lne=vr((e,t)=>{var r=fs(),s=one().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,p=0;d.forEach(h=>{let y=h.reduce((g,v)=>{let S=l.node(v).height;return g>S?g:S},0);h.forEach(g=>{let v=l.node(g);m==="top"?v.y=p+v.height/2:m==="bottom"?v.y=p+y-v.height/2:v.y=p+y/2}),p+=y+u})}}),cne=vr((e,t)=>{var r=Ute(),s=Vte(),a=Kte(),i=fs().normalizeRanks,l=Gte(),d=fs().removeEmptyRanks,u=Yte(),m=Xte(),p=Qte(),h=ine(),y=lne(),g=fs(),v=wi().Graph;t.exports=S;function S(Q,ee={}){let se=ee.debugTiming?g.time:g.notime;return se("layout",()=>{let X=se(" buildLayoutGraph",()=>L(Q));return se(" runLayout",()=>C(X,se,ee)),se(" updateInputGraph",()=>k(Q,X)),X})}function C(Q,ee,se){ee(" makeSpaceForEdgeLabels",()=>U(Q)),ee(" removeSelfEdges",()=>O(Q)),ee(" acyclic",()=>r.run(Q)),ee(" nestingGraph.run",()=>u.run(Q)),ee(" rank",()=>a(g.asNonCompoundGraph(Q))),ee(" injectEdgeLabelProxies",()=>K(Q)),ee(" removeEmptyRanks",()=>d(Q)),ee(" nestingGraph.cleanup",()=>u.cleanup(Q)),ee(" normalizeRanks",()=>i(Q)),ee(" assignRankMinMax",()=>q(Q)),ee(" removeEdgeLabelProxies",()=>I(Q)),ee(" normalize.run",()=>s.run(Q)),ee(" parentDummyChains",()=>l(Q)),ee(" addBorderSegments",()=>m(Q)),ee(" order",()=>h(Q,se)),ee(" insertSelfEdges",()=>H(Q)),ee(" adjustCoordinateSystem",()=>p.adjust(Q)),ee(" position",()=>y(Q)),ee(" positionSelfEdges",()=>Z(Q)),ee(" removeBorderNodes",()=>W(Q)),ee(" normalize.undo",()=>s.undo(Q)),ee(" fixupEdgeLabelCoords",()=>$(Q)),ee(" undoCoordinateSystem",()=>p.undo(Q)),ee(" translateGraph",()=>D(Q)),ee(" assignNodeIntersects",()=>E(Q)),ee(" reversePoints",()=>Y(Q)),ee(" acyclic.undo",()=>r.undo(Q))}function k(Q,ee){Q.nodes().forEach(se=>{let X=Q.node(se),me=ee.node(se);X&&(X.x=me.x,X.y=me.y,X.order=me.order,X.rank=me.rank,ee.children(se).length&&(X.width=me.width,X.height=me.height))}),Q.edges().forEach(se=>{let X=Q.edge(se),me=ee.edge(se);X.points=me.points,Object.hasOwn(me,"x")&&(X.x=me.x,X.y=me.y)}),Q.graph().width=ee.graph().width,Q.graph().height=ee.graph().height}var N=["nodesep","edgesep","ranksep","marginx","marginy"],j={ranksep:50,edgesep:20,nodesep:50,rankdir:"tb",rankalign:"center"},T=["acyclicer","ranker","rankdir","align","rankalign"],R=["width","height","rank"],M={width:0,height:0},_=["minlen","weight","width","height","labeloffset"],F={minlen:1,weight:1,width:0,height:0,labeloffset:10,labelpos:"r"},z=["labelpos"];function L(Q){let ee=new v({multigraph:!0,compound:!0}),se=J(Q.graph());return ee.setGraph(Object.assign({},j,B(se,N),g.pick(se,T))),Q.nodes().forEach(X=>{let me=J(Q.node(X)),je=B(me,R);Object.keys(M).forEach(Re=>{je[Re]===void 0&&(je[Re]=M[Re])}),ee.setNode(X,je),ee.setParent(X,Q.parent(X))}),Q.edges().forEach(X=>{let me=J(Q.edge(X));ee.setEdge(X,Object.assign({},F,B(me,_),g.pick(me,z)))}),ee}function U(Q){let ee=Q.graph();ee.ranksep/=2,Q.edges().forEach(se=>{let X=Q.edge(se);X.minlen*=2,X.labelpos.toLowerCase()!=="c"&&(ee.rankdir==="TB"||ee.rankdir==="BT"?X.width+=X.labeloffset:X.height+=X.labeloffset)})}function K(Q){Q.edges().forEach(ee=>{let se=Q.edge(ee);if(se.width&&se.height){let X=Q.node(ee.v),me={rank:(Q.node(ee.w).rank-X.rank)/2+X.rank,e:ee};g.addDummyNode(Q,"edge-proxy",me,"_ep")}})}function q(Q){let ee=0;Q.nodes().forEach(se=>{let X=Q.node(se);X.borderTop&&(X.minRank=Q.node(X.borderTop).rank,X.maxRank=Q.node(X.borderBottom).rank,ee=Math.max(ee,X.maxRank))}),Q.graph().maxRank=ee}function I(Q){Q.nodes().forEach(ee=>{let se=Q.node(ee);se.dummy==="edge-proxy"&&(Q.edge(se.e).labelRank=se.rank,Q.removeNode(ee))})}function D(Q){let ee=Number.POSITIVE_INFINITY,se=0,X=Number.POSITIVE_INFINITY,me=0,je=Q.graph(),Re=je.marginx||0,Ee=je.marginy||0;function we(pe){let Pe=pe.x,Ae=pe.y,Xe=pe.width,Ze=pe.height;ee=Math.min(ee,Pe-Xe/2),se=Math.max(se,Pe+Xe/2),X=Math.min(X,Ae-Ze/2),me=Math.max(me,Ae+Ze/2)}Q.nodes().forEach(pe=>we(Q.node(pe))),Q.edges().forEach(pe=>{let Pe=Q.edge(pe);Object.hasOwn(Pe,"x")&&we(Pe)}),ee-=Re,X-=Ee,Q.nodes().forEach(pe=>{let Pe=Q.node(pe);Pe.x-=ee,Pe.y-=X}),Q.edges().forEach(pe=>{let Pe=Q.edge(pe);Pe.points.forEach(Ae=>{Ae.x-=ee,Ae.y-=X}),Object.hasOwn(Pe,"x")&&(Pe.x-=ee),Object.hasOwn(Pe,"y")&&(Pe.y-=X)}),je.width=se-ee+Re,je.height=me-X+Ee}function E(Q){Q.edges().forEach(ee=>{let se=Q.edge(ee),X=Q.node(ee.v),me=Q.node(ee.w),je,Re;se.points?(je=se.points[0],Re=se.points[se.points.length-1]):(se.points=[],je=me,Re=X),se.points.unshift(g.intersectRect(X,je)),se.points.push(g.intersectRect(me,Re))})}function $(Q){Q.edges().forEach(ee=>{let se=Q.edge(ee);if(Object.hasOwn(se,"x"))switch((se.labelpos==="l"||se.labelpos==="r")&&(se.width-=se.labeloffset),se.labelpos){case"l":se.x-=se.width/2+se.labeloffset;break;case"r":se.x+=se.width/2+se.labeloffset;break}})}function Y(Q){Q.edges().forEach(ee=>{let se=Q.edge(ee);se.reversed&&se.points.reverse()})}function W(Q){Q.nodes().forEach(ee=>{if(Q.children(ee).length){let se=Q.node(ee),X=Q.node(se.borderTop),me=Q.node(se.borderBottom),je=Q.node(se.borderLeft[se.borderLeft.length-1]),Re=Q.node(se.borderRight[se.borderRight.length-1]);se.width=Math.abs(Re.x-je.x),se.height=Math.abs(me.y-X.y),se.x=je.x+se.width/2,se.y=X.y+se.height/2}}),Q.nodes().forEach(ee=>{Q.node(ee).dummy==="border"&&Q.removeNode(ee)})}function O(Q){Q.edges().forEach(ee=>{if(ee.v===ee.w){var se=Q.node(ee.v);se.selfEdges||(se.selfEdges=[]),se.selfEdges.push({e:ee,label:Q.edge(ee)}),Q.removeEdge(ee)}})}function H(Q){var ee=g.buildLayerMatrix(Q);ee.forEach(se=>{var X=0;se.forEach((me,je)=>{var Re=Q.node(me);Re.order=je+X,(Re.selfEdges||[]).forEach(Ee=>{g.addDummyNode(Q,"selfedge",{width:Ee.label.width,height:Ee.label.height,rank:Re.rank,order:je+ ++X,e:Ee.e,label:Ee.label},"_se")}),delete Re.selfEdges})})}function Z(Q){Q.nodes().forEach(ee=>{var se=Q.node(ee);if(se.dummy==="selfedge"){var X=Q.node(se.e.v),me=X.x+X.width/2,je=X.y,Re=se.x-me,Ee=X.height/2;Q.setEdge(se.e,se.label),Q.removeNode(ee),se.label.points=[{x:me+2*Re/3,y:je-Ee},{x:me+5*Re/6,y:je-Ee},{x:me+Re,y:je},{x:me+5*Re/6,y:je+Ee},{x:me+2*Re/3,y:je+Ee}],se.label.x=se.x,se.label.y=se.y}})}function B(Q,ee){return g.mapValues(g.pick(Q,ee),Number)}function J(Q){var ee={};return Q&&Object.entries(Q).forEach(([se,X])=>{typeof se=="string"&&(se=se.toLowerCase()),ee[se]=X}),ee}}),dne=vr((e,t)=>{var r=fs(),s=wi().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 p="layer"+m;d.setNode(p,{rank:"same"}),u.reduce((h,y)=>(d.setEdge(h,y,{style:"invis"}),y))}),d}}),une=vr((e,t)=>{t.exports="2.0.4"}),mne=vr((e,t)=>{t.exports={graphlib:wi(),layout:cne(),debug:dne(),util:{time:fs().time,notime:fs().notime},version:une()}});const Y3=mne();const X3={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"}},fne={critical:"bg-red-500",high:"bg-amber-500",medium:"bg-amber-500",low:"bg-blue-500"};function hne({data:e}){const{t}=kt(["work","common"]),{task:r,agentName:s,selected:a,direction:i="TB",isExpandedRoot:l,onCollapse:d}=e,u=X3[r.status]??X3.pending,m=r.taskType==="scheduled"&&!!r.scheduleConfig,p=m?r.scheduleConfig.every?t("work:task.everyInterval",{interval:r.scheduleConfig.every}):r.scheduleConfig.cron?t("work:task.cronLabel"):"":"",h=i==="LR"?Yt.Left:Yt.Top,y=i==="LR"?Yt.Right:Yt.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(pl,{type:"target",position:h,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 ${fne[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"})}),p]})]}),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(pl,{type:"source",position:y,className:"!bg-border-default !w-2 !h-2"}),l&&d&&n.jsx("button",{onClick:g=>{g.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 Q3={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"}},Z3={pending:"todo",in_progress:"in_progress",completed:"done",rejected:"done",cancelled:"done",archived:"done"};function pne({data:e}){const{t}=kt(["work","common"]),{req:r,selected:s,direction:a="TB",isExpandedRoot:i,onCollapse:l}=e,d=Q3[r.status]??Q3.pending,u=a==="LR"?Yt.Left:Yt.Top,m=a==="LR"?Yt.Right:Yt.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(pl,{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(pl,{type:"source",position:m,className:"!bg-border-default !w-2 !h-2"}),i&&l&&n.jsx("button",{onClick:p=>{p.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 gne={task:hne,requirement:pne};function xne({nodeIds:e,rfRef:t}){const r=ute();return b.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 bne=()=>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,yne=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 vne(){return b.useSyncExternalStore(yne,bne,()=>!1)}const Tf=200,Af=80;function J3(e,t,r="TB"){const s=i=>{const l=new Y3.graphlib.Graph;l.setDefaultEdgeLabel(()=>({})),l.setGraph({rankdir:i,nodesep:40,ranksep:60});for(const d of e)l.setNode(d.id,{width:Tf,height:Af});for(const d of t)l.setEdge(d.source,d.target);return Y3.layout(l),e.map(d=>{const u=l.node(d.id);return{...d,position:{x:(u?.x??0)-Tf/2,y:(u?.y??0)-Af/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+Tf),d=Math.min(d,y.position.y),u=Math.max(u,y.position.y+Af);const m=l-i,p=u-d,h=r==="TB"?"LR":"TB";if(m>p*3)return{nodes:s(h),direction:h}}return{nodes:a,direction:r}}function wne(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 p of r.get(m)??[])a.has(p)||u.push(p)}}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 ej(e,t){if(e.length===0)return{nodes:[],direction:"TB"};const r=wne(e,t);if(r.length===1)return J3(e,t);let s="TB";const a=r.map(y=>{const{nodes:g,direction:v}=J3(y.nodes,y.edges);s=v;let S=1/0,C=-1/0,k=1/0,N=-1/0;for(const j of g)S=Math.min(S,j.position.x),C=Math.max(C,j.position.x+Tf),k=Math.min(k,j.position.y),N=Math.max(N,j.position.y+Af);for(const j of g)j.position.x-=S,j.position.y-=k;return{nodes:g,w:C-S,h:N-k}});a.sort((y,g)=>g.h-y.h);const i=60,l=a.reduce((y,g)=>y+(g.w+i)*(g.h+i),0),d=Math.sqrt(l)*1.1,u=[];let m=0,p=0,h=0;for(const y of a){m>0&&m+y.w>d&&(m=0,p+=h+i,h=0);for(const g of y.nodes)u.push({...g,position:{x:g.position.x+m,y:g.position.y+p}});m+=y.w+i,h=Math.max(h,y.h)}return{nodes:u,direction:s}}function kne(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 Zc=[{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(Zc.map(e=>e.id));const lf=new Set(Zc.filter(e=>e.id!=="done").map(e=>e.id)),tj=e=>e.status==="archived";function jne(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 Nne({tasks:e,requirements:t=[],agents:r,showArchived:s,onShowArchivedChange:a,onTaskClick:i,onReqClick:l,onCollapseDAG:d,onDependencyChange:u,selectedTaskId:m,selectedReqId:p,hasDetailPanel:h,defaultExpandedNodeId:y,previewMode:g}){const{t:v}=kt(["work","common"]),S=vne(),[C,k]=b.useState(null),[N,j]=b.useState(null),[T,R]=b.useState(()=>new Set(lf)),[M,_]=b.useState(y??null),[F,z]=b.useState(s??!1),L=s??F,U=b.useCallback(ue=>{const fe=typeof ue=="function"?ue(L):ue;z(fe),a?.(fe)},[L,a]);b.useEffect(()=>{s!==void 0&&z(s)},[s]),b.useEffect(()=>{y&&_(y)},[y]);const K=b.useMemo(()=>e.filter(ue=>tj(ue)).length,[e]),q=b.useMemo(()=>{const ue=new Set;for(const fe of Zc)if(T.has(fe.id))for(const Me of fe.statuses)ue.add(Me);return ue},[T]),I=b.useMemo(()=>{const ue=new Set;for(const fe of e)for(const Me of Zc)if(Me.statuses.has(fe.status)){ue.add(Me.id);break}for(const fe of t){const Me=Z3[fe.status];Me&&ue.add(Me)}return Zc.filter(fe=>ue.has(fe.id))},[e,t]),D=b.useCallback(ue=>{R(fe=>{const Me=new Set(fe);return Me.has(ue)?Me.delete(ue):Me.add(ue),Me})},[]),E=b.useCallback((ue,fe="success")=>{k({msg:ue,type:fe}),setTimeout(()=>k(null),2500)},[]),$=b.useMemo(()=>{const ue=new Map;for(const fe of r)ue.set(fe.id,fe.name);return ue},[r]),Y=b.useMemo(()=>{const ue=new Map;for(const fe of e)ue.set(fe.id,fe);return ue},[e]),W=b.useMemo(()=>{const ue=new Map;for(const fe of t)ue.set(fe.id,fe);return ue},[t]),O=b.useRef(!1),H=b.useCallback(()=>{O.current=!1,_(null),d?.()},[d]),Z=S?"#94a3b8":"#6b7280",B=b.useCallback((ue,fe,Me)=>({id:`${ue}->${fe}`,source:ue,target:fe,animated:Me==="blocked",markerEnd:{type:md.ArrowClosed,width:14,height:14,color:Me==="blocked"?"#ef4444":Z},style:{stroke:Me==="blocked"?"#ef4444":Z,strokeWidth:1.5,cursor:"pointer"}}),[Z]),{initialNodes:J,initialEdges:Q,topLevelIds:ee}=b.useMemo(()=>{const ue=(lt,$e)=>{const ct=new Set,Ut=lt.map(Xt=>(ct.add(Xt.id),{id:Xt.id,type:"task",data:{task:Xt,agentName:Xt.assignedAgentId?$.get(Xt.assignedAgentId):void 0,selected:Xt.id===m},position:{x:0,y:0}}));for(const Xt of $e){const kn=`req-${Xt.id}`;ct.add(kn),Ut.push({id:kn,type:"requirement",data:{req:Xt,selected:Xt.id===p},position:{x:0,y:0}})}const zt=[];for(const Xt of lt)if(Xt.blockedBy)for(const kn of Xt.blockedBy)ct.has(kn)&&zt.push(B(kn,Xt.id,Xt.status));const cn=new Set,Ln=(Xt,kn)=>{const tr=`${Xt}->${kn}`;cn.has(tr)||(cn.add(tr),zt.push({id:tr,source:Xt,target:kn,markerEnd:{type:md.ArrowClosed,width:14,height:14,color:"#8b5cf6"},style:{stroke:"#8b5cf6",strokeWidth:1.5,strokeDasharray:"4 2"}}))};for(const Xt of $e){const kn=`req-${Xt.id}`;for(const tr of Xt.taskIds)ct.has(tr)&&Ln(kn,tr)}for(const Xt of lt)if(Xt.requirementId){const kn=`req-${Xt.requirementId}`;ct.has(kn)&&Ln(kn,Xt.id)}return{nodes:Ut,edges:zt}},fe=e.filter(lt=>q.has(lt.status)&&(L||!tj(lt))),Me=new Set;for(const lt of Zc)T.has(lt.id)&&Me.add(lt.id);const ne=t.filter(lt=>{const $e=Z3[lt.status];return $e&&Me.has($e)}),{nodes:he,edges:Be}=ue(fe,ne),de=new Set;for(const lt of Be)de.add(lt.target);const Ce=new Set(he.filter(lt=>!de.has(lt.id)).map(lt=>lt.id));if(!M||!Ce.has(M)){const lt=he.filter(zt=>Ce.has(zt.id)),{nodes:$e,direction:ct}=ej(lt,[]);return{initialNodes:$e.map(zt=>({...zt,data:{...zt.data,direction:ct}})),initialEdges:[],topLevelIds:Ce}}const{nodes:et,edges:it}=ue(e,t),Ve=jne(M,Y,W,e),Ge=et.filter(lt=>Ve.has(lt.id)).map(lt=>lt.id===M?{...lt,data:{...lt.data,isExpandedRoot:!0,onCollapse:H}}:lt),ut=it.filter(lt=>Ve.has(lt.source)&&Ve.has(lt.target)),{nodes:nt,direction:ft}=ej(Ge,ut);return{initialNodes:nt.map(lt=>({...lt,data:{...lt.data,direction:ft}})),initialEdges:ut,topLevelIds:Ce}},[e,t,$,Y,W,B,q,T,L,m,p,M,H]),[se,X,me]=mte(J),[je,Re,Ee]=fte(Q),we=b.useRef(null),pe=b.useRef({groupFilter:T,showArchived:L});b.useEffect(()=>{const ue=pe.current;(ue.groupFilter!==T||ue.showArchived!==L)&&(O.current=!1,_(null),pe.current={groupFilter:T,showArchived:L})},[T,L]),b.useEffect(()=>{X(J),Re(Q),O.current||requestAnimationFrame(()=>{we.current?.fitView({padding:.2,duration:300})})},[J,Q,X,Re]),b.useEffect(()=>{const ue=setTimeout(()=>{we.current?.fitView({padding:.2,duration:300})},50);return()=>clearTimeout(ue)},[h]);const Pe=b.useCallback(ue=>{ue&&(O.current=!0)},[]),Ae=b.useCallback((ue,fe)=>{if(!M&&ee.has(fe.id)&&(O.current=!1,_(fe.id)),fe.id.startsWith("req-")){const Me=W.get(fe.id.slice(4));Me&&l&&l(Me)}else{const Me=Y.get(fe.id);Me&&i&&i(Me)}},[Y,W,i,l,ee,M]),Xe=b.useCallback(async ue=>{const{source:fe,target:Me}=ue;if(!fe||!Me||fe===Me)return;const ne=Y.get(Me);if(!ne)return;if(ne.blockedBy?.includes(fe)){E(v("work:dag.toast.dependencyExists"),"error");return}if(kne(Y,fe,Me)){E(v("work:dag.toast.cycleError"),"error");return}const he=[...ne.blockedBy??[],fe];try{await le.tasks.update(Me,{blockedBy:he}),E(v("work:dag.toast.dependencyAdded")),u?.()}catch(Be){E(v("work:dag.toast.failed",{message:Be instanceof Error?Be.message:String(Be)}),"error")}},[Y,E,u,v]),Ze=b.useCallback((ue,fe)=>{j(fe)},[]),at=b.useCallback(async()=>{if(!N)return;const ue=Y.get(N.target);if(!ue){j(null);return}const fe=(ue.blockedBy??[]).filter(Me=>Me!==N.source);try{await le.tasks.update(N.target,{blockedBy:fe}),E(v("work:dag.toast.dependencyRemoved")),u?.()}catch(Me){E(v("work:dag.toast.failed",{message:Me instanceof Error?Me.message:String(Me)}),"error")}j(null)},[N,Y,E,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 pt=T.size===lf.size&&[...lf].every(ue=>T.has(ue))&&!L,Ct=N?Y.get(N.source):null,_e=N?Y.get(N.target):null;return n.jsxs("div",{className:"flex-1 min-h-0 relative",style:{height:"100%"},children:[n.jsxs(dte,{nodes:se,edges:je,onNodesChange:me,onEdgesChange:Ee,onNodeClick:Ae,onConnect:Xe,onEdgeClick:Ze,onMoveEnd:Pe,onInit:ue=>{we.current=ue},nodeTypes:gne,fitView:!0,minZoom:.3,maxZoom:2,proOptions:{hideAttribution:!0},connectionLineStyle:{stroke:"#818cf8",strokeWidth:2,strokeDasharray:"6 3"},children:[g&&n.jsx(xne,{nodeIds:se.map(ue=>ue.id),rfRef:we}),n.jsx(bte,{color:S?"#cbd5e1":"#374151",gap:20,size:1}),n.jsx(Ste,{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(zte,{nodeColor:ue=>{const fe=ue.data?.task,Me=fe?.status;return fe?.taskType==="scheduled"?"#06b6d4":Me==="completed"||Me==="accepted"?"#10b981":Me==="in_progress"?"#f59e0b":Me==="blocked"||Me==="failed"?"#ef4444":S?"#94a3b8":"#6b7280"},maskColor:S?"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:[I.map(ue=>{const fe=T.has(ue.id);return n.jsx("button",{onClick:()=>D(ue.id),className:`text-[10px] px-1.5 py-0.5 rounded border transition-colors ${fe?`${ue.color.bg} ${ue.color.border} ${ue.color.text}`:"bg-surface-elevated/50 border-border-default/50 text-fg-tertiary"}`,children:v(`work:dag.filter.${ue.id}`)},ue.id)}),K>0&&n.jsx("button",{onClick:()=>U(ue=>!ue),className:`text-[10px] px-1.5 py-0.5 rounded border transition-colors ${L?"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:K})}),!pt&&n.jsx("button",{onClick:()=>{R(new Set(lf)),U(!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:[M?n.jsx("button",{onClick:H,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:()=>j(null),children:n.jsxs("div",{className:"bg-surface-secondary border border-border-default rounded-xl p-5 shadow-2xl max-w-sm",onClick:ue=>ue.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:_e?.title??N.target.slice(-8),source:Ct?.title??N.source.slice(-8)})}),n.jsxs("div",{className:"flex justify-end gap-2",children:[n.jsx("button",{onClick:()=>j(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:at,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 Sne({orgId:e,onCreated:t,onClose:r}){const{t:s}=kt(["work","common"]),[a,i]=b.useState(""),[l,d]=b.useState(""),[u,m]=b.useState(""),[p,h]=b.useState("main"),[y,g]=b.useState([]),[v,S]=b.useState([]),[C,k]=b.useState(!1),[N,j]=b.useState(""),[T,R]=b.useState(!1),M=ks();b.useEffect(()=>{le.teams.list().then(z=>S(z.teams)).catch(()=>{})},[]);const _=b.useCallback(async z=>{if(z?.preventDefault(),R(!0),!(!a.trim()||C)){k(!0),j("");try{const L=u.trim()?[{url:u.trim(),defaultBranch:p.trim()||"main"}]:[],U=await le.projects.create({name:a.trim(),description:l.trim()||void 0,repositories:L.length>0?L:void 0,teamIds:y.length>0?y:void 0,orgId:e??"default"});t(U.project)}catch(L){j(L instanceof Error?L.message:s("project.failedToCreate"))}k(!1)}},[a,l,u,p,y,e,C,t,s]),F=T&&!a.trim();return sd.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 ${M?"w-full":"w-[520px]"}`,onClick:z=>z.stopPropagation(),onSubmit:_,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:z=>{i(z.target.value),j("")},onBlur:()=>R(!0),placeholder:s("project.projectNamePlaceholder"),className:`input ${F?"!border-red-500 focus:!ring-red-500/25":""}`,autoFocus:!M}),F&&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:z=>d(z.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(z=>{const L=y.includes(z.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:L,onChange:()=>g(U=>L?U.filter(K=>K!==z.id):[...U,z.id]),className:"accent-brand-500"}),n.jsx("span",{className:"truncate",children:z.name})]},z.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:z=>m(z.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:p,onChange:z=>h(z.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 N7(e,t){const[r,s]=b.useState(null);return b.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 ku({options:e,value:t,onChange:r,placeholder:s,noMatchesText:a,className:i}){const[l,d]=b.useState(!1),[u,m]=b.useState(""),p=b.useRef(null),h=b.useRef(null),y=b.useRef(null),g=b.useRef(null),v=N7(h,l);b.useEffect(()=>{const k=N=>{p.current&&!p.current.contains(N.target)&&g.current&&!g.current.contains(N.target)&&d(!1)};return document.addEventListener("mousedown",k),()=>document.removeEventListener("mousedown",k)},[]);const S=e.find(k=>k.value===t)?.label??"",C=u?e.filter(k=>k.label.toLowerCase().includes(u.toLowerCase())):e;return n.jsxs("div",{ref:p,className:i??"",children:[n.jsxs("div",{ref:h,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:k=>m(k.target.value),onClick:k=>k.stopPropagation(),className:"w-full bg-transparent outline-none text-fg-primary text-sm",placeholder:S||s,autoFocus:!0}):n.jsx("span",{className:S?"text-fg-primary":"text-fg-tertiary",children:S||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:g,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(k=>n.jsx("div",{onClick:()=>{r(k.value),d(!1),m("")},className:`px-3 py-2 text-sm cursor-pointer hover:bg-brand-500/10 ${k.value===t?"bg-brand-500/10 text-brand-500 font-medium":"text-fg-primary"}`,children:k.label},k.value))})]})}function Cne({options:e,selected:t,onAdd:r,placeholder:s,noMatchesText:a,className:i}){const[l,d]=b.useState(!1),[u,m]=b.useState(""),p=b.useRef(null),h=b.useRef(null),y=b.useRef(null),g=b.useRef(null),v=N7(h,l);b.useEffect(()=>{const k=N=>{p.current&&!p.current.contains(N.target)&&g.current&&!g.current.contains(N.target)&&d(!1)};return document.addEventListener("mousedown",k),()=>document.removeEventListener("mousedown",k)},[]);const S=e.filter(k=>!t.includes(k.value)),C=u?S.filter(k=>k.label.toLowerCase().includes(u.toLowerCase())):S;return n.jsxs("div",{ref:p,className:i??"",children:[n.jsxs("div",{ref:h,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:k=>m(k.target.value),onClick:k=>k.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:g,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(k=>n.jsx("div",{onClick:()=>{r(k.value),m("")},className:"px-3 py-2 text-sm cursor-pointer hover:bg-brand-500/10 text-fg-primary",children:k.label},k.value))})]})}function xd(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 nj({value:e,onSave:t,className:r,placeholder:s}){const{t:a}=kt(["work","common"]),[i,l]=b.useState(!1),[d,u]=b.useState(e),m=b.useRef(null);b.useEffect(()=>{u(e)},[e]),b.useEffect(()=>{i&&m.current?.focus()},[i]);const p=async()=>{l(!1);const h=d.trim();if(h&&h!==e)try{await t(h)}catch{u(e)}else u(e)};return i?n.jsx("input",{ref:m,value:d,onChange:h=>u(h.target.value),onBlur:()=>{p()},onKeyDown:h=>{h.key==="Enter"&&p(),h.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 Tne({value:e,onSave:t,className:r,placeholder:s}){const{t:a}=kt(["work","common"]),[i,l]=b.useState(!1),[d,u]=b.useState(e),m=b.useRef(null);b.useEffect(()=>{u(e)},[e]),b.useEffect(()=>{i&&m.current&&(m.current.focus(),m.current.style.height="auto",m.current.style.height=m.current.scrollHeight+"px")},[i]);const p=async()=>{l(!1);const h=d.trim();if(h!==e)try{await t(h)}catch{u(e)}else u(e)};return i?n.jsx("textarea",{ref:m,value:d,onChange:h=>{u(h.target.value),h.target.style.height="auto",h.target.style.height=h.target.scrollHeight+"px"},onBlur:()=>{p()},onKeyDown:h=>{h.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 Ane=/^\[([^\]]+?)(?:\s+by\s+([^\]]+))?\]\s*([\s\S]*)$/;function S7(e){const t=e.match(Ane);return t?{timestamp:t[1].trim(),author:t[2]?.trim()??"System",content:t[3].trim()}:{timestamp:"",author:"",content:e}}function Ene(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),p=s.getTime()-m.getTime();return p<6e4?t("work:relative.justNow"):p<36e5?t("work:relative.minutesAgo",{count:Math.floor(p/6e4)}):p<864e5?t("work:relative.hoursAgo",{count:Math.floor(p/36e5)}):p<6048e5?t("work:relative.daysAgo",{count:Math.floor(p/864e5)}):`${a}-${String(i+1).padStart(2,"0")}-${String(l).padStart(2,"0")}`}const rj=[{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 Mne(e){let t=0;for(let r=0;r<e.length;r++)t=(t<<5)-t+e.charCodeAt(r)|0;return rj[Math.abs(t)%rj.length]}function Dne({note:e,compact:t}){const{t:r}=kt(["work","common"]),s=S7(e),a=r("work:task.systemAuthor"),i=Mne(s.author||a),l=s.author?s.author.split(/[\s_-]+/).map(m=>m[0]).join("").slice(0,2).toUpperCase():"SY",d=Ene(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(Ur,{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(Ur,{content:s.content,className:"text-xs text-fg-secondary"})})]})})]})}const Rne=new Set(["rejected","cancelled","archived"]),fy=[{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"}],sj={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"},aj={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"},ij={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"},oj={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 C7(e){return Object.keys(aj).reduce((t,r)=>(t[r]={label:e(`work:status.task.${r}`),cls:aj[r]},t),{})}function T7(e){return Object.keys(sj).reduce((t,r)=>(t[r]={label:e(`work:status.sub.${r}`),cls:sj[r]},t),{})}function Lne(e){return Object.keys(ij).reduce((t,r)=>(t[r]={label:e(`work:priority.${r}`),cls:ij[r]},t),{})}function hy(e){return Object.keys(oj).reduce((t,r)=>(t[r]={label:e(`work:status.requirement.${r}`),cls:oj[r]},t),{})}const lj=["low","medium","high","urgent"],cj=["pending","in_progress","blocked","review","completed","failed","rejected","cancelled"],dj=["pending","in_progress","completed","rejected","cancelled"],uj={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([])},e1={pending:new Set(["in_progress","rejected","cancelled"]),in_progress:new Set(["completed","cancelled"]),completed:new Set([]),rejected:new Set([]),cancelled:new Set([])},l0={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"},mj={idle:"text-green-500",working:"text-blue-500",error:"text-red-500",paused:"text-amber-500",offline:"text-fg-muted"};function Ine({agent:e,anchorRect:t,onClose:r}){const{t:s}=kt(["work","common"]),a=b.useRef(null);b.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(),Nt.navigate(Se.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 $u({comment:e,agents:t,onReply:r}){const{t:s}=kt(["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]=b.useState(null),[p,h]=b.useState(!1),[y,g]=b.useState([]),[v,S]=b.useState(!1),C=b.useCallback((R,M)=>{const _=t.find(F=>F.name.toLowerCase()===R.toLowerCase());if(_){const F=M.target.getBoundingClientRect();m({agent:_,top:F.bottom,left:F.left})}},[t]),k=b.useMemo(()=>t.map(R=>R.name),[t]),N=b.useCallback(R=>{const M=t.find(_=>_.name.toLowerCase()===e.authorName.toLowerCase());if(M){const _=R.currentTarget.getBoundingClientRect();m({agent:M,top:_.bottom,left:_.left})}},[t,e.authorName]),j=b.useCallback(async()=>{if(p){h(!1);return}const R=e.activityId;if(R&&(h(!0),!(y.length>0))){S(!0);try{const{logs:M}=await le.agents.getActivityLogs(e.authorId,R),_=M.map(F=>Wj(F,R,e.authorId)).filter(F=>F!==null).map(F=>({...F,ts:new Date(F.createdAt).getTime()}));g(_)}catch{}S(!1)}},[p,y.length,e]),T=b.useMemo(()=>Gu(y.map(Yu).filter(R=>R!==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:j,className:"text-fg-tertiary hover:text-brand-400 text-[10px] opacity-0 group-hover:opacity-100 transition-opacity ml-1",children:s(p?"work:task.hideLog":"work:task.viewLog")})]}),e.replyTo&&e.replyToAuthor&&n.jsxs("button",{onClick:()=>{const R=document.getElementById(`comment-${e.replyTo}`);R&&(R.scrollIntoView({behavior:"smooth",block:"center"}),R.classList.add("bg-brand-500/10"),setTimeout(()=>R.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(Ur,{content:e.content,className:"text-xs text-fg-primary",onMentionClick:C,knownNames:k}),e.attachments?.map((R,M)=>R.type==="image"?n.jsx("img",{src:R.url,alt:R.name,className:"mt-1 max-w-[200px] rounded"},M):null),p&&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(Th,{entries:y,isActive:!1,onCollapse:()=>h(!1),embedded:!0})})]}),u&&n.jsx(Ine,{agent:u.agent,anchorRect:{top:u.top,left:u.left},onClose:()=>m(null)})]})}function Pne({task:e,agents:t,users:r,authUser:s}){const{t:a}=kt(["work","common"]),[i,l]=b.useState([]),[d,u]=b.useState([]),m=b.useRef(null),[p,h]=b.useState(new Map);b.useEffect(()=>{u([]),h(new Map),m.current&&(clearTimeout(m.current),m.current=null),le.tasks.getComments(e.id).then(k=>l(k.comments)).catch(()=>{})},[e.id]),b.useEffect(()=>gn.on("task:comment",N=>{if(N.payload?.taskId===e.id&&N.payload.comment){const j=N.payload.comment;l(T=>T.some(R=>R.id===j.id)?T:[...T,j]),(j.authorType==="agent"||j.authorId?.startsWith("agt_"))&&(u(T=>{const R=T.filter(M=>M.id!==j.authorId);return R.length===0&&m.current&&(clearTimeout(m.current),m.current=null),R}),h(T=>{const R=new Map(T);return R.delete(j.authorId),R}))}}),[e.id]),b.useEffect(()=>{if(d.length===0)return;const k=new Set(d.map(j=>j.id));return gn.on("agent:activity_log",j=>{const T=j.payload;if(!T)return;const R=T.agentId;if(!k.has(R))return;const M=T.type;if(M==="tool_start"||M==="tool_end"){const F={tool:T.content??T.metadata?.tool??"",phase:M==="tool_start"?"start":"end",success:M==="tool_end"?T.metadata?.success!==!1:void 0,ts:Date.now()};h(z=>{const L=new Map(z),U=[...L.get(R)??[],F];return L.set(R,U),L})}})},[d]);const y=b.useMemo(()=>{const k=[];for(const N of e.notes??[]){const j=S7(N);let T;if(j.timestamp){const R=j.timestamp.match(/^(\d{4})[/-](\d{2})[/-](\d{2})\s+(\d{2}):(\d{2})(?::(\d{2}))?/);T=R?new Date(+R[1],+R[2]-1,+R[3],+R[4],+R[5],+(R[6]??0)):new Date(0)}else T=new Date(0);k.push({type:"note",note:N,ts:T})}for(const N of i)k.push({type:"comment",comment:N,ts:new Date(N.createdAt)});return k.sort((N,j)=>N.ts.getTime()-j.ts.getTime()),k},[e.notes,i]),[g,v]=b.useState(null),S=async(k,N,j,T)=>{let R;j.length>0&&(R=(await le.uploads.upload(j.map(L=>({dataUrl:L.dataUrl,name:L.name})),"comments")).files.map(L=>({type:"image",url:L.url,name:L.name}))),await le.tasks.addComment(e.id,k,s?.name,R,s?.id,N.length>0?N:void 0,T);const M=[],_=new Set,F=z=>{if(_.has(z)||z===s?.id)return;_.add(z);const L=t.find(U=>U.id===z);L&&M.push({id:L.id,name:L.name,avatarUrl:L.avatarUrl})};for(const z of N){const L=t.find(U=>U.name.toLowerCase()===z.toLowerCase());L&&F(L.id)}e.assignedAgentId&&F(e.assignedAgentId),e.createdBy?.startsWith("agt_")&&e.status!=="in_progress"&&F(e.createdBy),M.length>0&&(m.current&&clearTimeout(m.current),u(M),m.current=setTimeout(()=>u([]),12e4))},C=b.useCallback(k=>{v({id:k.id,authorName:k.authorName,content:k.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((k,N)=>k.type==="note"?n.jsx(Dne,{note:k.note,compact:!0},`n-${N}`):n.jsx($u,{comment:k.comment,agents:t,onReply:C},`c-${k.comment.id}`)),d.length>0&&n.jsx("div",{className:"flex flex-col gap-1.5 pt-1",children:d.map(k=>{const N=p.get(k.id)??[];return n.jsxs("div",{className:"px-2 py-1.5 rounded-lg cursor-pointer hover:bg-surface-elevated/60 transition-colors",onClick:()=>Nt.navigate(Se.TEAM,{agentId:k.id,profileTab:"mind"}),children:[n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsxs("div",{className:"relative shrink-0",children:[n.jsx(gr,{name:k.name,avatarUrl:k.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:k.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(Ch,{activities:N,isActive:!0})})]},k.id)})})]}),n.jsx(wS,{agents:t,humans:r,onSubmit:S,replyTo:g,onCancelReply:()=>v(null),placeholder:a("work:task.commentPlaceholder")})]})}function One({task:e,isRunning:t,authUser:r,agents:s}){const a=e.id,{t:i}=kt(["work","common"]),[l,d]=b.useState([]),[u,m]=b.useState(new Map),[p,h]=b.useState(new Set),[y,g]=b.useState([]),[v,S]=b.useState(""),[C,k]=b.useState(t),[N,j]=b.useState(!0),[T,R]=b.useState(new Set),[M,_]=b.useState(""),[F,z]=b.useState(!1),[L,U]=b.useState([]),K=b.useRef(null),[q,I]=b.useState(new Map),[D,E]=b.useState([]),[$,Y]=b.useState([]),[W,O]=b.useState(!1),H=b.useRef(null),Z=b.useRef(null);b.useEffect(()=>{k(t)},[t]),b.useEffect(()=>{U([]),I(new Map),K.current&&(clearTimeout(K.current),K.current=null)},[a]),b.useEffect(()=>{j(!0),Promise.all([le.tasks.getLogsSummary(a).catch(()=>({rounds:[]})),le.tasks.getComments(a).catch(()=>({comments:[]}))]).then(([we,pe])=>{const Pe=we.rounds;if(d(Pe),g(pe.comments),Pe.length===0){j(!1);return}const Ae=Pe[Pe.length-1].round;R(new Set([Ae])),le.tasks.getLogs(a,Ae).catch(()=>({logs:[]})).then(Xe=>{m(new Map([[Ae,Xe.logs]])),j(!1)})})},[a]),b.useEffect(()=>{const we=e.assignedAgentId;we&&(O(!0),le.agents.getActivities(we,{taskId:a,limit:20}).then(pe=>Y(pe.activities)).catch(()=>Y([])).finally(()=>O(!1)))},[a,e.assignedAgentId]);const B=b.useCallback(we=>{u.has(we)||p.has(we)||(h(pe=>new Set(pe).add(we)),le.tasks.getLogs(a,we).catch(()=>({logs:[]})).then(pe=>{m(Pe=>new Map(Pe).set(we,pe.logs)),h(Pe=>{const Ae=new Set(Pe);return Ae.delete(we),Ae})}))},[a,u,p]),J=b.useCallback(we=>{R(pe=>{const Pe=new Set(pe);return Pe.has(we)?Pe.delete(we):(Pe.add(we),u.has(we)||B(we)),Pe})},[u,B]);b.useEffect(()=>{const we=gn.on("task:log",Ae=>{const Xe=Ae.payload;if(Xe.taskId!==a)return;const Ze={id:Xe.id,taskId:Xe.taskId,agentId:Xe.agentId,seq:Xe.seq,type:Xe.logType,content:Xe.content,metadata:Xe.metadata,executionRound:Xe.executionRound,createdAt:Xe.createdAt},at=Ze.executionRound??1;d(pt=>pt.find(_e=>_e.round===at)?pt:[...pt,{round:at,logCount:0,toolCount:0,firstAt:Ze.createdAt,lastAt:Ze.createdAt,status:"running"}]),R(pt=>pt.has(at)?pt:new Set(pt).add(at)),m(pt=>{const Ct=pt.get(at)??[];return Ze.id&&Ct.some(_e=>_e.id===Ze.id)?pt:new Map(pt).set(at,[...Ct,Ze])}),Ze.type==="text"&&S(""),Ze.type==="status"&&(Ze.content==="started"||Ze.content==="resumed"?k(!0):["completed","failed","cancelled","execution_finished"].includes(Ze.content)&&(k(!1),d(pt=>pt.map(Ct=>Ct.round===at?{...Ct,status:Ze.content}:Ct)))),Ze.type==="error"&&k(!1)}),pe=gn.on("task:log:delta",Ae=>{const Xe=Ae.payload;Xe.taskId===a&&S(Ze=>Ze+Xe.text)}),Pe=gn.on("task:comment",Ae=>{const Xe=Ae.payload;if(Xe.taskId!==a)return;const Ze=Xe.comment;g(at=>at.some(pt=>pt.id===Ze.id)?at:[...at,Ze]),(Ze.authorType==="agent"||Ze.authorId?.startsWith("agt_"))&&(U(at=>{const pt=at.filter(Ct=>Ct.id!==Ze.authorId);return pt.length===0&&K.current&&(clearTimeout(K.current),K.current=null),pt}),I(at=>{const pt=new Map(at);return pt.delete(Ze.authorId),pt}))});return()=>{we(),pe(),Pe()}},[a]),b.useEffect(()=>{if(L.length===0)return;const we=new Set(L.map(Pe=>Pe.id));return gn.on("agent:activity_log",Pe=>{const Ae=Pe.payload;if(!Ae)return;const Xe=Ae.agentId;if(!we.has(Xe))return;const Ze=Ae.type;if(Ze==="tool_start"||Ze==="tool_end"){const pt={tool:Ae.content??Ae.metadata?.tool??"",phase:Ze==="tool_start"?"start":"end",success:Ze==="tool_end"?Ae.metadata?.success!==!1:void 0,ts:Date.now()};I(Ct=>{const _e=new Map(Ct),ue=[..._e.get(Xe)??[],pt];return _e.set(Xe,ue),_e})}})},[L]);const Q=b.useMemo(()=>{const we=[];for(const[,pe]of u)we.push(...pe);return we.sort((pe,Pe)=>pe.seq-Pe.seq),we},[u]),ee=b.useMemo(()=>Q.map(we=>Zx(we)),[Q]),se=l.length>1,X=we=>{const pe=we.target.files;if(pe){for(const Pe of Array.from(pe)){if(!Pe.type.startsWith("image/"))continue;const Ae=new FileReader;Ae.onload=()=>{E(Xe=>[...Xe,{type:"image",url:Ae.result,name:Pe.name}])},Ae.readAsDataURL(Pe)}we.target.value=""}},me=async()=>{if(!(!M.trim()&&D.length===0)){z(!0);try{let we;D.length>0&&(we=(await le.uploads.upload(D.map(at=>({dataUrl:at.url,name:at.name})),"comments")).files.map(at=>({type:"image",url:at.url,name:at.name})));const pe=await le.tasks.addComment(a,M,r?.name,we,r?.id);pe.comment&&g(Ze=>Ze.some(at=>at.id===pe.comment.id)?Ze:[...Ze,pe.comment]),_(""),E([]);const Pe=[],Ae=new Set,Xe=Ze=>{if(Ae.has(Ze)||Ze===r?.id)return;Ae.add(Ze);const at=s.find(pt=>pt.id===Ze);at&&Pe.push({id:at.id,name:at.name,avatarUrl:at.avatarUrl})};e.assignedAgentId&&Xe(e.assignedAgentId),e.createdBy?.startsWith("agt_")&&e.status!=="in_progress"&&Xe(e.createdBy),Pe.length>0&&(K.current&&clearTimeout(K.current),U(Pe),K.current=setTimeout(()=>U([]),12e4))}catch{}z(!1)}},je=n.jsxs("div",{className:"border-t border-border-default px-4 py-3 sticky bottom-0 bg-surface-primary z-10",children:[D.length>0&&n.jsx("div",{className:"flex gap-2 mb-2 flex-wrap",children:D.map((we,pe)=>n.jsxs("div",{className:"relative group",children:[n.jsx("img",{src:we.url,alt:we.name,className:"w-16 h-16 object-cover rounded-lg border border-border-default"}),n.jsx("button",{onClick:()=>E(Pe=>Pe.filter((Ae,Xe)=>Xe!==pe)),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:"×"})]},pe))}),n.jsxs("div",{className:"flex gap-2",children:[n.jsx("input",{type:"text",value:M,onChange:we=>_(we.target.value),onKeyDown:we=>{we.key==="Enter"&&!we.shiftKey&&(we.preventDefault(),me())},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:H,accept:"image/*",multiple:!0,onChange:X,className:"hidden"}),n.jsx("button",{onClick:()=>H.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:()=>{me()},disabled:F||!M.trim()&&D.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 we=e.assignedAgentId?s.find(_e=>_e.id===e.assignedAgentId):void 0,pe=$.length>0,Pe=we&&we.currentTaskId&&we.currentTaskId!==e.id,Ae=e.status==="pending",Xe=e.status==="in_progress",Ze=!e.assignedAgentId;let at="📋",pt=i("work:task.emptyLogs.default"),Ct=i("work:task.emptyLogs.defaultHint");return Ze?(at="👤",pt=i("work:task.emptyLogs.noAgent"),Ct=i("work:task.emptyLogs.noAgentHint")):Ae?(at="⏳",pt=i("work:task.emptyLogs.pending"),Ct=i("work:task.emptyLogs.pendingHint")):Xe&&Pe?(at="🔄",pt=i("work:task.emptyLogs.agentBusy",{agent:we?.name??e.assignedAgentId}),Ct=i("work:task.emptyLogs.agentBusyHint")):Xe&&(at="⏳",pt=i("work:task.emptyLogs.starting"),Ct=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:W?n.jsx("div",{className:"flex items-center justify-center py-8 text-xs text-fg-tertiary",children:i("work:task.loadingLogs")}):pe?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:we?.name??i("work:task.agent"),count:$.length})]}),n.jsx("div",{className:"space-y-1.5",children:$.map(_e=>{const ue=!_e.endedAt,fe=_e.type==="task"?"🔧":_e.type==="chat"||_e.type==="respond_in_session"?"💬":_e.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:()=>Nt.navigate(Se.TEAM,{agentId:e.assignedAgentId}),children:[n.jsx("span",{className:"text-sm shrink-0",children:fe}),n.jsxs("div",{className:"flex-1 min-w-0",children:[n.jsx("div",{className:"text-xs text-fg-primary truncate",children:_e.label}),n.jsxs("div",{className:"text-[10px] text-fg-tertiary",children:[new Date(_e.startedAt).toLocaleString(),_e.endedAt?` — ${_e.totalTools} tools, ${_e.totalTokens.toLocaleString()} tokens`:""]})]}),ue&&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")]}),!ue&&n.jsx("span",{className:`shrink-0 text-[10px] ${_e.success?"text-fg-tertiary":"text-red-400"}`,children:_e.success?"✓":"✗"}),n.jsx("span",{className:"shrink-0 text-fg-tertiary text-[10px] opacity-0 group-hover:opacity-100 transition-opacity",children:"→"})]},_e.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:at}),n.jsxs("div",{className:"text-xs",children:[pt,n.jsx("br",{}),n.jsx("span",{className:"text-fg-muted",children:Ct})]})]})})}),je]})}if(!se){const we=ee.map(Ae=>Yu(Ae)).filter(Ae=>Ae!==null),pe=J4(Q,Gu(we)),Pe=[...pe.map(Ae=>({kind:"entry",entry:Ae,ts:Ae.timestamp?new Date(Ae.timestamp).getTime():0})),...y.map(Ae=>({kind:"comment",comment:Ae,ts:new Date(Ae.createdAt).getTime()}))];return Pe.sort((Ae,Xe)=>Ae.ts-Xe.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:[Pe.map((Ae,Xe)=>Ae.kind==="comment"?n.jsx($u,{comment:Ae.comment,agents:s},`c-${Ae.comment.id}`):n.jsx(Uf,{entry:Ae.entry,showTime:!0,isLast:Xe===Pe.length-1},`e-${Xe}`)),C&&v&&n.jsx(Mb,{content:v}),C&&!v&&pe.length>0&&n.jsx(Eb,{})]}),je]})}const Re=(we,pe)=>{const Pe=we.firstAt?new Date(we.firstAt).getTime():0,Ae=pe?.firstAt?new Date(pe.firstAt).getTime():1/0;return y.filter(Xe=>{const Ze=new Date(Xe.createdAt).getTime();return Ze>=Pe&&Ze<Ae})},Ee=l.length>0?y.filter(we=>new Date(we.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:[Ee.length>0&&n.jsx("div",{className:"space-y-0.5",children:Ee.map(we=>n.jsx($u,{comment:we,agents:s},we.id))}),l.map((we,pe)=>{const Pe=T.has(we.round),Ae=we.round===l[l.length-1].round,Xe=u.get(we.round),Ze=p.has(we.round),at=Re(we,l[pe+1]),pt=we.status==="completed"||we.status==="execution_finished"?"✅":we.status==="failed"?"❌":we.status==="cancelled"?"⏹":"🔄",Ct=we.lastAt&&we.firstAt?Math.max(0,new Date(we.lastAt).getTime()-new Date(we.firstAt).getTime()):0,_e=Ct>=6e4?`${Math.floor(Ct/6e4)}m ${Math.floor(Ct%6e4/1e3)}s`:Ct>=1e3?`${Math.floor(Ct/1e3)}s`:"";return n.jsxs("div",{className:"border border-border-default/50 rounded-lg overflow-hidden",children:[n.jsxs("button",{onClick:()=>J(we.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:pt}),n.jsx("span",{className:"text-xs text-fg-secondary font-medium",children:i("work:task.roundHeader",{n:we.round})}),at.length>0&&n.jsxs("span",{className:"text-[10px] text-blue-400",children:["💬 ",at.length]}),Ae&&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:we.toolCount})}),_e&&n.jsx("span",{className:"text-[10px] text-fg-tertiary tabular-nums",children:_e}),n.jsx("svg",{className:`w-3 h-3 text-fg-tertiary transition-transform ${Pe?"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"})})]})]}),Pe&&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:we.round})}),Xe&&(()=>{const fe=Xe.map(he=>Zx(he)).map(he=>Yu(he)).filter(he=>he!==null),ne=[...J4(Xe,Gu(fe)).map(he=>({kind:"entry",entry:he,ts:he.timestamp?new Date(he.timestamp).getTime():0})),...at.map(he=>({kind:"comment",comment:he,ts:new Date(he.createdAt).getTime()}))];return ne.sort((he,Be)=>he.ts-Be.ts),ne.map((he,Be)=>he.kind==="comment"?n.jsx($u,{comment:he.comment,agents:s},`c-${he.comment.id}`):n.jsx(Uf,{entry:he.entry,showTime:!0,isLast:Be===ne.length-1},`e-${Be}`))})(),Ae&&C&&v&&n.jsx(Mb,{content:v}),Ae&&C&&!v&&!Ze&&n.jsx(Eb,{})]})]},we.round)}),L.length>0&&n.jsx("div",{className:"flex flex-col gap-1.5 mt-2",children:L.map(we=>{const pe=q.get(we.id)??[];return n.jsxs("div",{className:"px-3 py-2 rounded-lg cursor-pointer hover:bg-surface-elevated/60 transition-colors",onClick:()=>Nt.navigate(Se.TEAM,{agentId:we.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(gr,{name:we.name,avatarUrl:we.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:we.name}),pe.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:"→"})]}),pe.length>0&&n.jsx("div",{className:"ml-9 mt-1",children:n.jsx(Ch,{activities:pe,isActive:!0})})]},we.id)})})]}),je]})}const fj=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 _ne(e){return e==null?"":e<1024?`${e} B`:e<1024*1024?`${(e/1024).toFixed(1)} KB`:`${(e/(1024*1024)).toFixed(1)} MB`}function zne({filePath:e,onClose:t}){const{t:r}=kt(["work","common"]),[s,a]=b.useState([e]),i=s[s.length-1],[l,d]=b.useState(null),[u,m]=b.useState(null),[p,h]=b.useState(!0);b.useEffect(()=>{h(!0),m(null),d(null),le.files.preview(i).then(T=>d(T)).catch(T=>m(String(T))).finally(()=>h(!1))},[i]);const y=T=>a(R=>[...R,T]),g=()=>a(T=>T.length>1?T.slice(0,-1):T),v=s.length>1,S=T=>{le.files.reveal(T).catch(()=>{})},C=T=>{T.isDirectory||fj.has(T.ext)?y(T.path):S(T.path)},k=i.split("/").pop()??i,N=l?.type==="directory",j=(T,R)=>{if(R)return"📁";const M=[".md",".markdown"],_=[".png",".jpg",".jpeg",".gif",".webp",".svg"];return M.includes(T)?"📝":_.includes(T)?"🖼":[".json",".yaml",".yml",".toml",".xml"].includes(T)?"⚙":[".js",".ts",".jsx",".tsx",".py",".sh"].includes(T)?"💻":"📄"};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:T=>T.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:[v&&n.jsx("button",{onClick:g,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:r("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"})})}),N?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:k}),N&&l.entries&&n.jsxs("span",{className:"text-[10px] text-fg-tertiary shrink-0",children:["(",l.entries.length,")"]})]}),n.jsxs("div",{className:"flex items-center gap-1 shrink-0 ml-3",children:[n.jsx("button",{onClick:()=>S(i),className:"text-fg-tertiary hover:text-fg-primary p-1.5 rounded hover:bg-surface-elevated/60 transition-colors",title:r("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:i})}),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:r("work:task.filePreviewLoading")}),u&&n.jsx("div",{className:"text-sm text-red-500 text-center py-8",children:u}),l?.type==="directory"&&l.entries&&n.jsxs("div",{className:"divide-y divide-border-default/50",children:[l.entries.length===0&&n.jsx("div",{className:"text-sm text-fg-tertiary text-center py-8",children:r("work:task.emptyDirectory")}),l.entries.map(T=>n.jsxs("button",{onClick:()=>C(T),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:j(T.ext,T.isDirectory)}),n.jsx("span",{className:"flex-1 min-w-0 truncate text-sm text-fg-primary group-hover:text-brand-400 transition-colors",children:T.name}),!T.isDirectory&&T.size!=null&&n.jsx("span",{className:"text-[10px] text-fg-tertiary shrink-0",children:_ne(T.size)}),T.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"})}),!T.isDirectory&&!fj.has(T.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"})]})]},T.path))]}),l&&l.type!=="directory"&&n.jsx("div",{className:"p-5",children:l.type==="image"?n.jsx("div",{className:"flex justify-center",children:n.jsx("img",{src:`data:${l.mimeType};base64,${l.content}`,alt:l.name,className:"max-w-full max-h-[60vh] rounded-lg"})}):n.jsx(G1,{content:l.content,format:l.type==="text"?"text":l.type,className:"text-sm text-fg-secondary leading-relaxed"})})]})]})})}function hj({task:e,agents:t,projects:r,requirements:s,allTasks:a,users:i,onClose:l,onRefresh:d,authUser:u,scrollToComments:m,onScrollToCommentsDone:p,onReqClick:h,onProjectClick:y}){const{t:g}=kt(["work","common"]),v=b.useMemo(()=>C7(g),[g]),[S,C]=b.useState([]),[k,N]=b.useState(""),[j,T]=b.useState(!1),[R,M]=b.useState(!1),[_,F]=b.useState(null),[z,L]=b.useState(null),[U,K]=b.useState(!1),[q,I]=b.useState(!1),[D,E]=b.useState(!1),[$,Y]=b.useState("every"),[W,O]=b.useState(""),[H,Z]=b.useState(""),[B,J]=b.useState(""),[Q,ee]=b.useState(!1),[se,X]=b.useState("details"),me=b.useRef(null),[je,Re]=b.useState("none"),Ee=b.useCallback(Ne=>{X(Ne),requestAnimationFrame(()=>{me.current?.scrollTo({top:0,behavior:"instant"})})},[]),we=b.useMemo(()=>[{id:"details"},{id:"logs"},{id:"deliverables"},{id:"history"}],[]),pe=hl(we,se,Ee);b.useEffect(()=>{const Ne=me.current;if(!Ne)return;const At=()=>{const{scrollTop:rn,scrollHeight:Jt,clientHeight:Ot}=Ne;if(!(Jt>Ot+50)){Re("none");return}const $n=rn<30,js=rn+Ot>=Jt-30;Re($n?"top":js?"bottom":"middle")};At(),Ne.addEventListener("scroll",At,{passive:!0});const Vt=new ResizeObserver(At);return Vt.observe(Ne),()=>{Ne.removeEventListener("scroll",At),Vt.disconnect()}},[se]),b.useEffect(()=>{if(!m)return;X("details");const Ne=setTimeout(()=>{const At=me.current;At&&At.scrollTo({top:At.scrollHeight,behavior:"smooth"}),p?.()},300);return()=>clearTimeout(Ne)},[m,p]);const[Pe,Ae]=b.useState(null),[Xe,Ze]=b.useState(!1),[at,pt]=b.useState(null),[Ct,_e]=b.useState(!1),[ue,fe]=b.useState(e.description),Me=b.useRef(null),ne=b.useRef(null),he=b.useRef(80);b.useEffect(()=>{if(Ct&&ne.current){const Ne=ne.current;Ne.style.height="auto",Ne.style.height=Math.max(Ne.scrollHeight,he.current)+"px",Ne.focus()}},[Ct]);const[Be,de]=b.useState(!1),[Ce,et]=b.useState(""),[it,Ve]=b.useState(1),[Ge,ut]=b.useState(!1),nt=ks(),ft=20,Rt=b.useCallback(async()=>{try{const Ne=await le.tasks.listSubtasks(e.id);C(Ne.subtasks)}catch{}},[e.id]);b.useEffect(()=>{Rt()},[Rt]);const lt=async Ne=>{if(!Q){ee(!0);try{await Ne(),d(),await Rt()}catch(At){Ae(String(At).replace("Error: ",""))}finally{ee(!1)}}},$e=Ne=>lt(()=>le.tasks.update(e.id,{priority:Ne})),ct=Ne=>lt(()=>le.tasks.assign(e.id,Ne||null)),Ut=Ne=>lt(()=>le.tasks.update(e.id,{projectId:Ne||null})),zt=async()=>{if(!Q){ee(!0);try{await le.tasks.pause(e.id),d()}finally{ee(!1)}}},cn=async()=>{if(!Q){ee(!0),Ae(null),Ee("logs");try{await le.tasks.resume(e.id),d()}catch(Ne){Ae(String(Ne).replace("Error: API error: 400","Server error").replace("Error: ",""))}finally{ee(!1)}}},Ln=async()=>{k.trim()&&(await le.tasks.createSubtask(e.id,k.trim()),N(""),T(!1),Rt(),d())},Xt=async Ne=>{Ne.status==="completed"?await le.tasks.cancelSubtask(e.id,Ne.id):await le.tasks.completeSubtask(e.id,Ne.id),Rt(),d()},kn=async Ne=>{await le.tasks.deleteSubtask(e.id,Ne.id),F(null),Rt(),d()},tr=async()=>{if(!Q){ee(!0);try{await le.tasks.updateStatus(e.id,"in_progress"),d()}finally{ee(!1)}}},ir=async()=>{if(!Q){ee(!0),Ae(null),Ee("logs");try{await le.tasks.retry(e.id),d()}catch(Ne){Ae(String(Ne).replace("Error: API error: 400","Server error").replace("Error: ",""))}finally{ee(!1)}}},gs=async()=>{if(!Q){ee(!0),Ae(null),Ee("logs");try{await le.tasks.runNow(e.id),d()}catch(Ne){Ae(String(Ne).replace("Error: API error: 400","Server error").replace("Error: ","")),d()}finally{ee(!1)}}},wr=b.useRef(d);wr.current=d,b.useEffect(()=>gn.on("task:update",At=>{At.payload.taskId===e.id&&(Rt(),wr.current())}),[e.id,Rt]);const or=S.filter(Ne=>Ne.status==="completed").length,Ue=e.status==="in_progress",Lt=e.status==="blocked",Zt=e.status==="completed",Ft=e.status==="failed",lr=e.status==="rejected",_n=e.status==="cancelled",dn=e.status==="archived",Sn=Zt||Ft||lr||_n||dn,Cn=e.taskType==="scheduled"&&!!e.scheduleConfig,$r=Cn&&!!e.scheduleConfig?.paused,Mr=(()=>{const Ne=r.find(At=>At.id===e.projectId);return Ne&&Ne.name!=="default"?Ne:void 0})(),hn=s.find(Ne=>Ne.id===e.requirementId);return t.find(Ne=>Ne.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:[nt&&n.jsx("button",{onClick:l,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 Ne=v[e.status];return Ne?n.jsx("span",{className:`text-[10px] px-2 py-0.5 rounded-full font-medium whitespace-nowrap align-middle ${Ne.cls}`,children:Ne.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," ")})})()]})]}),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:()=>Ee("details"),className:`px-3 py-1.5 text-xs rounded-t-md transition-colors ${se==="details"?"bg-surface-elevated text-fg-primary font-medium":"text-fg-tertiary hover:text-fg-secondary"}`,children:g("work:task.detailsTab")}),n.jsxs("button",{onClick:()=>Ee("logs"),className:`px-3 py-1.5 text-xs rounded-t-md transition-colors flex items-center gap-1.5 ${se==="logs"?"bg-surface-elevated text-fg-primary font-medium":"text-fg-tertiary hover:text-fg-secondary"}`,children:[g("work:task.executionLogTab"),Ue&&n.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-brand-400 animate-pulse"})]}),n.jsx("button",{onClick:()=>Ee("deliverables"),className:`px-3 py-1.5 text-xs rounded-t-md transition-colors flex items-center gap-1.5 ${se==="deliverables"?"bg-surface-elevated text-fg-primary font-medium":"text-fg-tertiary hover:text-fg-secondary"}`,children:(()=>{const Ne=(e.deliverables??[]).filter(At=>At.type!=="branch"&&typeof At.reference=="string"&&At.reference.length>0).length;return Ne>0?g("work:task.deliverablesCount",{count:Ne}):g("work:task.deliverables")})()}),n.jsx("button",{onClick:()=>Ee("history"),className:`px-3 py-1.5 text-xs rounded-t-md transition-colors ${se==="history"?"bg-surface-elevated text-fg-primary font-medium":"text-fg-tertiary hover:text-fg-secondary"}`,children:g("work:task.historyTab")})]}),n.jsxs("div",{className:"flex-1 min-h-0 relative",children:[n.jsxs("div",{ref:me,className:"h-full overflow-y-auto overflow-x-hidden",onTouchStart:pe.onTouchStart,onTouchEnd:pe.onTouchEnd,children:[n.jsxs("div",{className:se==="logs"?"min-w-0 min-h-full":"hidden",children:[Pe&&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:g("work:task.failedToStart")})," ",Pe]}),n.jsx(One,{task:e,isRunning:e.status==="in_progress",authUser:u,agents:t})]}),n.jsxs("div",{className:se==="details"?"":"hidden",children:[n.jsx("div",{className:"px-6 pt-4 pb-3 border-b border-border-default",children:Ct?n.jsx("textarea",{ref:ne,value:ue,onChange:Ne=>{fe(Ne.target.value);const At=Ne.target;At.style.height="auto",At.style.height=At.scrollHeight+"px"},onBlur:()=>{ue!==e.description&&lt(()=>le.tasks.update(e.id,{description:ue})),_e(!1)},onKeyDown:Ne=>{Ne.key==="Escape"&&(Ne.preventDefault(),fe(e.description),_e(!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:g("work:task.addDescription")}):n.jsx("div",{ref:Me,className:"group relative cursor-pointer rounded-lg -mx-2 px-2 -my-1 py-1 hover:bg-surface-elevated/50 transition-colors",onClick:()=>{he.current=Math.max(Me.current?.offsetHeight??80,60),fe(e.description),_e(!0)},role:"button",tabIndex:0,onKeyDown:Ne=>Ne.key==="Enter"&&(fe(e.description),_e(!0)),children:e.description?n.jsxs("div",{children:[n.jsx("div",{className:nt&&!Ge?"line-clamp-3":"",children:n.jsx(Ur,{content:e.description,className:"text-sm text-fg-secondary leading-relaxed"})}),nt&&e.description.length>150&&n.jsx("button",{onClick:Ne=>{Ne.stopPropagation(),ut(!Ge)},className:"text-[11px] text-brand-500 mt-1 font-medium",children:g(Ge?"work:task.collapse":"common:showMore")})]}):n.jsx("p",{className:"text-sm text-fg-tertiary italic",children:g("work:task.noDescription")})})}),(Mr||hn)&&n.jsxs("div",{className:"px-6 py-2.5 border-b border-border-default flex flex-wrap items-center gap-2",children:[Mr&&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(Mr.id):void 0,role:y?"button":void 0,tabIndex:y?0:void 0,onKeyDown:y?Ne=>Ne.key==="Enter"&&y(Mr.id):void 0,children:[n.jsx("span",{className:"text-[9px] text-brand-500/60",children:g("work:task.projectLabel")}),Mr.name]}),hn&&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 ${h?"cursor-pointer hover:bg-brand-500/20 transition-colors":""}`,onClick:h?()=>h(hn):void 0,role:h?"button":void 0,tabIndex:h?0:void 0,onKeyDown:h?Ne=>Ne.key==="Enter"&&h(hn):void 0,children:[n.jsx("span",{className:"text-[9px] text-brand-500/60",children:g("work:task.requirementLabel")}),hn.title.length>40?hn.title.slice(0,40)+"…":hn.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:g("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(Ne=>{const At=a.find(rn=>rn.id===Ne),Vt=At&&(At.status==="completed"||At.status==="cancelled");return n.jsxs("span",{className:`inline-flex items-center gap-1 text-[11px] px-2 py-1 rounded-full ${Vt?"bg-green-500/10 text-green-600":"bg-amber-500/10 text-amber-600"}`,children:[n.jsx("span",{className:"text-[9px]",children:Vt?"✓":"⏳"}),n.jsx("span",{className:`font-mono ${Vt?"line-through opacity-60":""}`,children:At?At.title.slice(0,30):Ne.slice(-8)}),!Sn&&n.jsx("button",{onClick:async()=>{const rn=(e.blockedBy??[]).filter(Jt=>Jt!==Ne);await le.tasks.update(e.id,{blockedBy:rn}),d()},className:"ml-0.5 text-current opacity-40 hover:opacity-100 transition-opacity",title:g("work:task.removeDependency"),children:"×"})]},Ne)})}):n.jsx("p",{className:"text-[11px] text-fg-tertiary mb-2",children:g("work:task.noDependencies")}),!Sn&&n.jsxs("select",{value:"",onChange:async Ne=>{const At=Ne.target.value;if(!At)return;const Vt=[...e.blockedBy??[],At];await le.tasks.update(e.id,{blockedBy:Vt}),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:g("work:task.addDependency")}),a.filter(Ne=>Ne.id!==e.id&&!(e.blockedBy??[]).includes(Ne.id)).map(Ne=>n.jsx("option",{value:Ne.id,children:Ne.title},Ne.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:g("work:task.projectLabel")}),n.jsxs("select",{value:e.projectId??"",onChange:Ne=>{Ut(Ne.target.value)},disabled:Q,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:g("work:task.noProject")}),r.map(Ne=>n.jsx("option",{value:Ne.id,children:Ne.name},Ne.id))]})]}),n.jsxs("div",{children:[n.jsx("label",{className:"block text-[10px] font-semibold text-fg-tertiary uppercase tracking-wider mb-1",children:g("work:task.requirementLabel")}),n.jsxs("select",{value:e.requirementId??"",onChange:Ne=>lt(()=>le.tasks.update(e.id,{requirementId:Ne.target.value||null})),disabled:Q,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:g("work:task.noRequirement")}),s.filter(Ne=>!e.projectId||Ne.projectId===e.projectId).map(Ne=>n.jsx("option",{value:Ne.id,children:Ne.title},Ne.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:g("work:task.assignee")}),n.jsxs("select",{value:e.assignedAgentId??"",onChange:Ne=>{ct(Ne.target.value)},disabled:Q,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:g("work:task.unassigned")}),t.map(Ne=>n.jsxs("option",{value:Ne.id,children:[Ne.name," (",Ne.status,")"]},Ne.id))]})]}),n.jsxs("div",{children:[n.jsx("label",{className:"block text-[10px] font-semibold text-fg-tertiary uppercase tracking-wider mb-1",children:g("work:task.reviewer")}),n.jsxs("select",{value:`${e.reviewerType??"agent"}:${e.reviewerId??""}`,onChange:Ne=>{const At=Ne.target.value;if(!At)return;const Vt=At.startsWith("human:"),rn=At.replace(/^(human|agent):/,"");(rn!==e.reviewerId||(Vt?"human":"agent")!==(e.reviewerType??"agent"))&&lt(()=>le.tasks.update(e.id,{reviewerId:rn,reviewerType:Vt?"human":"agent"}))},disabled:Q,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(Ne=>n.jsx("option",{value:`human:${Ne.id}`,children:Ne.name},`human:${Ne.id}`)),t.map(Ne=>n.jsx("option",{value:`agent:${Ne.id}`,children:Ne.name},`agent:${Ne.id}`))]})]}),n.jsxs("div",{children:[n.jsx("label",{className:"block text-[10px] font-semibold text-fg-tertiary uppercase tracking-wider mb-1",children:g("work:task.priority")}),n.jsxs("select",{value:e.priority,onChange:Ne=>{$e(Ne.target.value)},disabled:Q,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:g("work:priority.low")}),n.jsx("option",{value:"medium",children:g("work:priority.medium")}),n.jsx("option",{value:"high",children:g("work:priority.high")}),n.jsx("option",{value:"urgent",children:g("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:g("work:task.createdBy",{name:xd(e.createdBy,t,i)??e.createdBy})}),e.updatedBy&&n.jsx("span",{children:g("work:task.updatedBy",{name:xd(e.updatedBy,t,i)??e.updatedBy})}),e.createdAt&&n.jsx("span",{children:new Date(e.createdAt).toLocaleDateString()}),e.startedAt&&n.jsx("span",{children:g("work:task.started",{date:new Date(e.startedAt).toLocaleDateString()})}),e.updatedAt&&n.jsx("span",{children:g("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:g("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:[g("work:task.subtasks")," ",S.length>0&&n.jsx("span",{className:"ml-1.5 text-fg-tertiary font-normal normal-case",children:g("work:task.subtasksProgress",{done:or,total:S.length})})]}),n.jsxs("div",{className:"flex items-center gap-2",children:[or>0&&n.jsx("button",{onClick:()=>M(Ne=>!Ne),className:`text-[10px] px-2 py-0.5 rounded-full border transition-colors ${R?"bg-brand-500/15 text-brand-500 border-brand-500/30":"text-fg-tertiary border-border-default hover:text-fg-secondary"}`,children:R?g("work:task.hideCompleted"):g("work:task.showCompleted",{count:or})}),n.jsx("button",{onClick:()=>T(!0),className:"text-xs text-brand-500 hover:text-brand-500 transition-colors",children:g("work:task.addSubtask")})]})]}),(()=>{const Ne=R?S:S.filter(At=>At.status!=="completed");return Ne.length>0?n.jsx("div",{className:"space-y-1.5 mb-3",children:Ne.map(At=>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:()=>{Xt(At)},className:`shrink-0 w-4 h-4 rounded border flex items-center justify-center transition-colors ${At.status==="completed"?"bg-green-600 border-green-600 text-white":"border-gray-600 hover:border-brand-500"}`,children:At.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 ${At.status==="completed"?"line-through text-fg-tertiary":"text-fg-secondary"}`,children:At.title}),n.jsx("button",{onClick:()=>F(At),className:"shrink-0 opacity-0 group-hover:opacity-100 text-fg-tertiary hover:text-red-500 transition-all text-xs",children:"✕"})]},At.id))}):null})(),S.length===0&&!j&&n.jsx("div",{className:"text-xs text-fg-tertiary text-center py-4",children:g("work:task.noSubtasksYet")}),j&&n.jsxs("div",{className:"flex gap-2 mt-2",children:[n.jsx("input",{autoFocus:!0,value:k,onChange:Ne=>N(Ne.target.value),onKeyDown:Ne=>{Ne.key==="Enter"&&Ln(),Ne.key==="Escape"&&(T(!1),N(""))},placeholder:g("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:()=>{Ln()},className:"px-3 py-1.5 bg-brand-600 hover:bg-brand-500 text-white text-xs rounded-lg",children:g("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:g("common:cancel")})]}),(()=>{const Ne=(e.deliverables??[]).filter(rn=>rn.type!=="branch"&&typeof rn.reference=="string"&&rn.reference.length>0);if(Ne.length===0)return null;const At={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"},Vt=Ne.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:g("work:task.deliverablesCount",{count:Ne.length})}),Ne.length>3&&n.jsx("button",{onClick:()=>Ee("deliverables"),className:"text-[10px] text-brand-500 hover:text-brand-500",children:g("work:task.viewAll")})]}),n.jsx("div",{className:"space-y-1.5",children:Vt.map((rn,Jt)=>{const Ot=/^https?:\/\//i.test(rn.reference),Fn=Ot?rn.summary||rn.reference:rn.reference.split("/").pop()??rn.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 ${At[rn.type]??"bg-gray-500/15 text-fg-secondary"}`,children:rn.type}),n.jsxs("div",{className:"flex-1 min-w-0",children:[Ot?n.jsxs("a",{href:rn.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:rn.reference,children:[Fn," ",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:()=>pt(rn.reference),className:"text-sm text-brand-500 hover:text-brand-500 font-medium truncate block max-w-full text-left hover:underline",title:rn.reference,children:Fn}),rn.summary&&!Ot&&n.jsx("p",{className:"text-[11px] text-fg-secondary mt-0.5 line-clamp-2",children:rn.summary}),n.jsx("p",{className:"text-[10px] text-fg-tertiary font-mono truncate mt-0.5",children:rn.reference})]})]},Jt)})})]})})(),n.jsx(Pne,{task:e,agents:t,users:i,authUser:u})]})]}),n.jsx("div",{className:se==="history"?"":"hidden",children:n.jsx(M7,{entityType:"task",entityId:e.id})}),n.jsx("div",{className:se==="deliverables"?"px-6 py-4":"hidden",children:(()=>{const Ne=(e.deliverables??[]).filter(Jt=>Jt.type!=="branch"&&typeof Jt.reference=="string"&&Jt.reference.length>0);if(Ne.length===0)return n.jsx("div",{className:"flex items-center justify-center py-12 text-xs text-fg-tertiary",children:g("work:task.noDeliverablesYet")});const At={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"},Vt=Math.ceil(Ne.length/ft),rn=Ne.slice((it-1)*ft,it*ft);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:g("work:task.deliverablesCount",{count:Ne.length})}),Vt>1&&n.jsxs("div",{className:"flex items-center gap-1.5 text-[10px] text-fg-tertiary",children:[n.jsx("button",{disabled:it<=1,onClick:()=>Ve(Jt=>Jt-1),className:"px-1.5 py-0.5 rounded bg-surface-elevated hover:bg-surface-overlay disabled:opacity-30",children:"‹"}),n.jsxs("span",{children:[it,"/",Vt]}),n.jsx("button",{disabled:it>=Vt,onClick:()=>Ve(Jt=>Jt+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:rn.map((Jt,Ot)=>{const Fn=/^https?:\/\//i.test(Jt.reference),$n=Fn?Jt.summary||Jt.reference:Jt.reference.split("/").pop()??Jt.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 ${At[Jt.type]??"bg-gray-500/15 text-fg-secondary"}`,children:Jt.type}),n.jsxs("div",{className:"flex-1 min-w-0",children:[Fn?n.jsxs("a",{href:Jt.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:Jt.reference,children:[$n," ",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:()=>pt(Jt.reference),className:"text-sm text-brand-500 hover:text-brand-500 font-medium truncate block max-w-full text-left hover:underline",title:Jt.reference,children:$n}),Jt.summary&&!Fn&&n.jsx("p",{className:"text-[11px] text-fg-secondary mt-0.5 line-clamp-2",children:Jt.summary}),n.jsx("p",{className:"text-[10px] text-fg-tertiary font-mono truncate mt-0.5",children:Jt.reference})]})]},Ot)})})]})})()})]}),je!=="none"&&je!=="top"&&n.jsx("button",{onClick:()=>me.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:g("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"})})}),je!=="none"&&je!=="bottom"&&n.jsx("button",{onClick:()=>{const Ne=me.current;Ne&&Ne.scrollTo({top:Ne.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:g("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"})})})]}),Cn&&e.scheduleConfig&&n.jsxs("div",{className:`mx-6 mt-3 mb-0 px-4 py-2.5 rounded-lg border text-xs ${$r?"bg-amber-500/5 border-amber-500/20":"bg-brand-500/5 border-brand-500/20"} ${!Ue&&!D&&!e.scheduleConfig.runAt?"cursor-pointer hover:border-brand-500/40 transition-colors":""}`,onClick:()=>{Ue||D||e.scheduleConfig?.runAt||(Y(e.scheduleConfig?.cron?"cron":"every"),O(e.scheduleConfig?.every??"4h"),Z(e.scheduleConfig?.cron??""),J(e.scheduleConfig?.maxRuns&&e.scheduleConfig.maxRuns>0?String(e.scheduleConfig.maxRuns):""),E(!0))},children:[n.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[n.jsx("span",{className:$r?"text-amber-600":"text-brand-500",children:$r?g("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"})})," ",g("work:task.scheduled")]})}),n.jsx("span",{className:"text-fg-tertiary",children:"·"}),n.jsx("span",{className:"text-fg-secondary",children:e.scheduleConfig.every?g("work:task.scheduleEvery",{interval:e.scheduleConfig.every}):e.scheduleConfig.cron?g("work:task.scheduleCron",{expr:e.scheduleConfig.cron}):e.scheduleConfig.runAt?g("work:task.scheduleOneShot"):g("work:task.scheduleNA")}),!$r&&e.scheduleConfig.nextRunAt&&n.jsxs(n.Fragment,{children:[n.jsx("span",{className:"text-fg-tertiary",children:"·"}),n.jsx("span",{className:"text-fg-secondary",children:g("work:task.scheduleNext",{when:(()=>{const Ne=new Date(e.scheduleConfig.nextRunAt).getTime()-Date.now();if(Ne<=0)return g("work:task.scheduleDueNow");const At=Math.floor(Ne/6e4);if(At<60)return g("work:task.scheduleInMinutes",{count:At});const Vt=Math.floor(At/60);return Vt<24?g("work:task.scheduleInHoursMinutes",{h:Vt,m:At%60}):g("work:task.scheduleInDaysHours",{d:Math.floor(Vt/24),h:Vt%24})})()})})]}),!Ue&&!D&&!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"})]})]}),D?n.jsxs("div",{className:"mt-2 pt-2 border-t border-border-default/50 space-y-2",onClick:Ne=>Ne.stopPropagation(),children:[n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsxs("select",{value:$,onChange:Ne=>Y(Ne.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:g("work:task.scheduleEveryMode")}),n.jsx("option",{value:"cron",children:g("work:task.scheduleCronMode")})]}),$==="every"?n.jsxs("select",{value:W,onChange:Ne=>O(Ne.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:g("work:task.freq30m")}),n.jsx("option",{value:"1h",children:g("work:task.freq1h")}),n.jsx("option",{value:"2h",children:g("work:task.freq2h")}),n.jsx("option",{value:"4h",children:g("work:task.freq4h")}),n.jsx("option",{value:"8h",children:g("work:task.freq8h")}),n.jsx("option",{value:"12h",children:g("work:task.freq12h")}),n.jsx("option",{value:"1d",children:g("work:task.freq1d")}),n.jsx("option",{value:"1w",children:g("work:task.freq1w")})]}):n.jsx("input",{value:H,onChange:Ne=>Z(Ne.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:g("work:task.scheduleMaxRuns")}),n.jsx("input",{value:B,onChange:Ne=>J(Ne.target.value.replace(/\D/g,"")),placeholder:g("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 Ne={};$==="every"?Ne.every=W:Ne.cron=H.trim(),B&&(Ne.maxRuns=parseInt(B,10)),await lt(()=>le.tasks.updateSchedule(e.id,Ne)),E(!1)},disabled:Q,className:"px-3 py-1 text-xs bg-brand-600 hover:bg-brand-500 rounded-lg text-white disabled:opacity-50",children:g("common:save")}),n.jsx("button",{onClick:()=>E(!1),className:"px-3 py-1 text-xs text-fg-secondary hover:text-fg-primary",children:g("common:cancel")})]})]}):n.jsxs("div",{className:"flex items-center gap-2 mt-1 text-fg-tertiary",children:[n.jsx("span",{children:g("work:task.scheduleRuns",{current:e.scheduleConfig.currentRuns??0,max:e.scheduleConfig.maxRuns&&e.scheduleConfig.maxRuns>0?g("work:task.scheduleRunsMax",{max:e.scheduleConfig.maxRuns}):""})}),e.scheduleConfig.lastRunAt&&n.jsxs(n.Fragment,{children:[n.jsx("span",{children:"·"}),n.jsx("span",{children:g("work:task.scheduleLast",{when:(()=>{const Ne=Date.now()-new Date(e.scheduleConfig.lastRunAt).getTime(),At=Math.floor(Ne/6e4);if(At<1)return g("work:task.noteTimeJustNow");if(At<60)return g("work:task.noteTimeMinutes",{count:At});const Vt=Math.floor(At/60);return Vt<24?g("work:task.noteTimeHours",{count:Vt}):g("work:task.noteTimeDays",{count:Math.floor(Vt/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(Cn){Ze(!0);return}lt(()=>le.tasks.approve(e.id))},disabled:Q,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_")?g("work:task.startExecution"):g("work:task.approve")}),e.createdBy&&!e.createdBy.startsWith("agt_")?n.jsx("button",{onClick:()=>{lt(()=>le.tasks.cancel(e.id))},disabled:Q,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:g("work:task.cancelTask")}):n.jsx("button",{onClick:()=>K(!0),disabled:Q,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:g("work:task.reject")})]}),e.status==="review"&&n.jsxs(n.Fragment,{children:[n.jsx("button",{onClick:()=>{lt(()=>le.tasks.accept(e.id,u?.id))},disabled:Q,className:"px-3 py-1.5 text-xs bg-green-600 hover:bg-green-500 rounded-lg text-white disabled:opacity-50",children:g("work:task.approveCheck")}),Be?n.jsxs("div",{className:"flex items-center gap-1.5",children:[n.jsx("input",{type:"text",value:Ce,onChange:Ne=>et(Ne.target.value),onKeyDown:Ne=>{Ne.key==="Enter"&&Ce.trim()&&(lt(()=>le.tasks.revision(e.id,Ce.trim(),u?.id)),de(!1),et(""))},placeholder:g("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:()=>{lt(()=>le.tasks.revision(e.id,Ce.trim()||g("work:task.revisionsNeededDefault"),u?.id)),de(!1),et("")},disabled:Q,className:"px-2.5 py-1 text-xs bg-amber-600 hover:bg-amber-500 rounded-lg text-white disabled:opacity-50",children:g("common:send")}),n.jsx("button",{onClick:()=>{de(!1),et("")},className:"px-1.5 py-1 text-xs text-fg-secondary hover:text-fg-primary",children:"✕"})]}):n.jsx("button",{onClick:()=>de(!0),disabled:Q,className:"px-3 py-1.5 text-xs bg-amber-600 hover:bg-amber-500 rounded-lg text-white disabled:opacity-50",children:g("work:task.requestRevision")})]}),Ue&&n.jsxs(n.Fragment,{children:[n.jsxs("button",{onClick:()=>{zt()},disabled:Q,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"})]}),g("work:task.pause")]}),n.jsxs("button",{onClick:()=>{ir()},disabled:Q,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"})]}),g("work:task.retry")]})]}),Lt&&n.jsx("button",{onClick:()=>{cn()},disabled:Q,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:Q?n.jsx(n.Fragment,{children:g("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"})}),g("work:task.resume")]})}),Ft&&!Cn&&n.jsxs(n.Fragment,{children:[n.jsxs("button",{onClick:()=>{ir()},disabled:Q,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"})]}),g("work:task.retry")]}),n.jsxs("button",{onClick:()=>{tr()},disabled:Q,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"})}),g("work:task.continueTask")]})]}),Cn&&(Zt||Ft)&&!dn&&n.jsx("button",{onClick:()=>{gs()},disabled:Q,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:Q?n.jsx(n.Fragment,{children:g("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"})}),g("work:task.runNow")]})}),Cn&&!Ue&&!dn&&!lr&&($r?n.jsx("button",{onClick:()=>{lt(()=>le.tasks.resumeSchedule(e.id))},disabled:Q,className:"px-3 py-1.5 text-xs bg-green-600 hover:bg-green-500 rounded-lg text-white disabled:opacity-50",children:g("work:task.resumeSchedule")}):n.jsx("button",{onClick:()=>{lt(()=>le.tasks.pauseSchedule(e.id))},disabled:Q,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:g("work:task.pauseSchedule")})),(Zt||Ft||lr||_n)&&n.jsx("button",{onClick:()=>I(!0),disabled:Q,className:"px-3 py-1.5 text-xs bg-gray-600 hover:bg-gray-500 rounded-lg text-white disabled:opacity-50",children:g("work:task.archive")}),Zt&&!Cn&&n.jsx("button",{onClick:()=>{tr()},disabled:Q,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:g("work:task.reopen")}),!Sn&&e.status!=="pending"&&n.jsx("button",{onClick:async()=>{const{count:Ne}=await le.tasks.getDependentCount(e.id);L({dependentCount:Ne})},disabled:Q,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:g("work:task.cancelTask")})]})}),_&&n.jsx(Yc,{title:g("work:task.deleteSubtaskTitle",{title:_.title}),message:g("work:task.deleteSubtaskMessage"),confirmLabel:g("common:delete"),onConfirm:()=>{kn(_)},onCancel:()=>F(null)}),U&&n.jsx(Yc,{title:g("work:task.rejectConfirmTitle"),message:g("work:task.rejectConfirmMessage"),confirmLabel:g("work:task.reject"),onConfirm:()=>{K(!1),lt(()=>le.tasks.reject(e.id))},onCancel:()=>K(!1)}),q&&n.jsx(Yc,{title:g("work:task.archiveConfirmTitle"),message:g(Cn?"work:task.archiveScheduledConfirmMessage":"work:task.archiveConfirmMessage"),confirmLabel:g("work:task.archive"),onConfirm:()=>{I(!1),lt(()=>le.tasks.archive(e.id))},onCancel:()=>I(!1)}),z&&z.dependentCount>0?n.jsx("div",{className:"fixed inset-0 bg-black/60 flex items-center justify-center z-[60]",onClick:()=>L(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:Ne=>Ne.stopPropagation(),children:[n.jsx("h3",{className:"text-base font-semibold text-fg-primary mb-2",children:g("work:task.cancelTaskModalTitle")}),n.jsx("p",{className:"text-sm text-fg-secondary mb-4",children:g("work:task.cancelTaskDependent",{count:z.dependentCount})}),n.jsxs("div",{className:"flex flex-col gap-2",children:[n.jsxs("button",{onClick:()=>{L(null),lt(()=>le.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:g("work:task.cancelTaskOnly")}),n.jsx("span",{className:"block text-xs text-fg-tertiary mt-0.5",children:g("work:task.cancelTaskOnlyHint")})]}),n.jsxs("button",{onClick:()=>{L(null),lt(()=>le.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:g("work:task.cancelWithDependents")}),n.jsx("span",{className:"block text-xs text-red-500/70 mt-0.5",children:g("work:task.cancelWithDependentsHint",{count:z.dependentCount})})]}),n.jsx("button",{onClick:()=>L(null),className:"w-full px-4 py-2 text-sm text-fg-tertiary hover:text-fg-secondary",children:g("work:task.keepTaskRunning")})]})]})}):z&&n.jsx(Yc,{title:g("work:task.cancelTaskModalTitle"),message:g("work:task.cancelConfirmMessage"),confirmLabel:g("work:task.cancelTask"),onConfirm:()=>{L(null),lt(()=>le.tasks.cancel(e.id))},onCancel:()=>L(null)}),at&&n.jsx(zne,{filePath:at,onClose:()=>pt(null)}),Xe&&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:Ne=>Ne.stopPropagation(),children:[n.jsx("h3",{className:"font-semibold text-base mb-2",children:g("work:task.scheduleApproveTitle")}),n.jsx("p",{className:"text-sm text-fg-secondary mb-5 leading-relaxed",children:g("work:task.scheduleApproveDesc",{schedule:e.scheduleConfig.cron?`Cron: ${e.scheduleConfig.cron}`:e.scheduleConfig.every?g("work:task.scheduleEvery",{interval:e.scheduleConfig.every}):"",nextRun:e.scheduleConfig.nextRunAt?new Date(e.scheduleConfig.nextRunAt).toLocaleString():g("work:task.scheduleNA")})}),n.jsxs("div",{className:"flex flex-col gap-2",children:[n.jsx("button",{disabled:Q,onClick:()=>{Ze(!1),lt(()=>le.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:g("work:task.scheduleApproveRunNow")}),n.jsx("button",{disabled:Q,onClick:()=>{Ze(!1),lt(()=>le.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:g("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:g("common:cancel")})]})]})})]})}function $ne({project:e,tasks:t,requirements:r,agents:s,onDeleteProject:a,onUpdateProject:i,onRefresh:l}){const d=b.useMemo(()=>t.filter(z=>z.projectId===e.id),[t,e.id]),u=b.useMemo(()=>r.filter(z=>z.projectId===e.id),[r,e.id]),m=b.useMemo(()=>{const z={total:d.length,completed:0,inProgress:0,inReview:0,blocked:0,pending:0,failed:0,reqs:u.length,reqsDone:0};for(const L of d)L.status==="completed"||L.status==="accepted"?z.completed++:L.status==="in_progress"?z.inProgress++:L.status==="review"||L.status==="revision"?z.inReview++:L.status==="blocked"?z.blocked++:L.status==="failed"?z.failed++:z.pending++;for(const L of u)L.status==="completed"&&z.reqsDone++;return z},[d,u]),p=b.useMemo(()=>new Set(d.map(z=>z.assignedAgentId).filter(Boolean)),[d]),h=b.useMemo(()=>s.filter(z=>p.has(z.id)),[s,p]),[y,g]=b.useState(!1),[v,S]=b.useState(""),[C,k]=b.useState("main"),[N,j]=b.useState(!1),{t:T}=kt(["work","common"]),R=[{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")}],M=async z=>{if(z!==e.status){j(!0);try{await i({status:z}),l()}finally{j(!1)}}},_=async()=>{const z=v.trim();if(!z)return;const L=[...e.repositories??[],{url:"",localPath:z,defaultBranch:C||"main"}];await i({repositories:L}),S(""),k("main"),g(!1),l()},F=async z=>{const L=(e.repositories??[]).filter((U,K)=>K!==z);await i({repositories:L}),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(Tne,{value:e.description??"",onSave:async z=>{await i({description:z}),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:R.map(z=>n.jsxs("button",{disabled:N,onClick:()=>M(z.value),className:`flex-1 px-3 py-2 rounded-lg text-xs font-medium transition-all ${e.status===z.value?z.value==="active"?"bg-green-500/15 text-green-600 ring-1 ring-green-500/30":z.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:z.label}),n.jsx("div",{className:"text-[10px] opacity-70 mt-0.5",children:z.desc})]},z.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(fo,{label:T("work:project.statTotal"),value:m.total,color:"text-fg-primary"}),n.jsx(fo,{label:T("work:project.statCompleted"),value:m.completed,color:"text-green-600"}),n.jsx(fo,{label:T("work:project.statInProgress"),value:m.inProgress,color:"text-brand-500"}),n.jsx(fo,{label:T("work:project.statInReview"),value:m.inReview,color:"text-brand-500"}),n.jsx(fo,{label:T("work:project.statBlocked"),value:m.blocked,color:"text-amber-600"}),n.jsx(fo,{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(fo,{label:T("work:project.statTotal"),value:m.reqs,color:"text-fg-primary"}),n.jsx(fo,{label:T("work:project.statCompleted"),value:m.reqsDone,color:"text-green-600"}),n.jsx(fo,{label:T("work:project.statActive"),value:m.reqs-m.reqsDone,color:"text-brand-500"})]})]}),h.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:h.length})}),n.jsx("div",{className:"flex flex-wrap gap-2",children:h.map(z=>{const L=d.filter(K=>K.assignedAgentId===z.id),U=L.filter(K=>!["completed","failed","cancelled","archived"].includes(K.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 ${z.status==="working"?"bg-blue-500":z.status==="idle"?"bg-green-500":"bg-gray-500"}`}),n.jsx("span",{className:"text-xs text-fg-secondary",children:z.name}),n.jsx("span",{className:"text-[10px] text-fg-tertiary",children:T("work:project.agentTaskCounts",{active:U.length,total:L.length})})]},z.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:()=>g(!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((z,L)=>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:z.url||z.localPath}),n.jsx("span",{className:"text-[10px] text-fg-tertiary shrink-0",children:z.defaultBranch}),n.jsx("button",{onClick:()=>F(L),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"})]})})]},L)),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:z=>S(z.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:z=>k(z.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:_,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 fo({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 A7={pending:"todo",in_progress:"in_progress",completed:"done",rejected:"closed",cancelled:"closed",archived:"closed"},E7={failed:"rejected",todo:"pending",in_progress:"in_progress",review:"in_progress",done:"completed",closed:"cancelled"},Bne={urgent:0,high:1,medium:2,low:3},pj={failed:0,todo:1,in_progress:2,review:3,done:4,closed:5},gj={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"},Hne={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"},Fne=["pending","in_progress","completed","rejected","cancelled","archived"];function qne(e){for(const t of fy)if(t.statuses.includes(e))return t.id;return"closed"}function xj(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]=b.useState(!1),l=b.useRef(null),d=b.useRef(null),u=t.find(m=>m.value===e);return b.useEffect(()=>{if(!a)return;const m=p=>{d.current&&!d.current.contains(p.target)&&l.current&&!l.current.contains(p.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 p=m.value===e,h=p||!s||s.has(m.value);return n.jsxs("button",{disabled:!h,onClick:()=>{!p&&h&&r(m.value),i(!1)},className:`w-full text-left px-3 py-1.5 text-[11px] flex items-center gap-2 transition-colors ${p?"bg-surface-elevated":h?"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 ${h?m.cls.split(" ")[0]:"bg-gray-600"}`}),n.jsx("span",{className:`font-medium ${p?"text-fg-primary":h?"text-fg-secondary":"text-fg-muted"}`,children:m.label}),p&&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 bj({row:e,idx:t,dragIdx:r,agentMap:s,projMap:a,onTaskClick:i,onReqClick:l,onRowDragStart:d,onRowDragEnd:u,handleStatusChange:m,handlePriorityChange:p,selected:h,isMobile:y}){const{t:g}=kt(["work","common"]),v=b.useMemo(()=>C7(g),[g]),S=b.useMemo(()=>hy(g),[g]),C=b.useMemo(()=>Lne(g),[g]),k=e.data.status,N=e.data.priority,j=e.kind==="task"?s.get(e.data.assignedAgentId??""):void 0,T=(()=>{const M=a.get((e.kind==="task",e.data.projectId??""));return M&&M.name!=="default"?M: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:g("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:g("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:g("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 ${gj[e.group]??"border-l-gray-700"} ${h?"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,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:M=>M.stopPropagation(),children:n.jsx(cf,{value:k,options:e.kind==="task"?cj.map(M=>({value:M,label:v[M]?.label??M,cls:v[M]?.cls??"bg-gray-500/15 text-fg-tertiary"})):dj.map(M=>({value:M,label:S[M]?.label??M,cls:S[M]?.cls??"bg-gray-500/15 text-fg-tertiary"})),allowedValues:e.kind==="task"?uj[k]:e1[k],onSelect:M=>{m(e,M)}})}),n.jsx("div",{onClick:M=>M.stopPropagation(),children:n.jsx(cf,{value:N,options:lj.map(M=>({value:M,label:C[M]?.label??M,cls:C[M]?.cls??"bg-gray-500/15 text-fg-tertiary"})),onSelect:M=>{p(e,M)}})}),j&&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 ${l0[j.status]??"bg-gray-500"}`}),n.jsx("span",{className:`${mj[j.status]??"text-fg-secondary"}`,children:j.name})]}),T?.name&&n.jsx("span",{className:"text-[10px] text-brand-400/70 truncate max-w-[80px]",children:T.name}),n.jsx("span",{className:"text-[9px] text-fg-muted ml-auto",children:xj(e.data.updatedAt??"",g)})]})]}):n.jsxs("div",{draggable:!0,onDragStart:M=>d(M,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 ${gj[e.group]??"border-l-gray-700"} ${r===t?"opacity-40":""} ${h?"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.jsx("div",{className:"flex-1 min-w-[200px] text-sm text-fg-primary truncate",children:e.data.title}),n.jsx("div",{className:"w-[130px] shrink-0",onClick:M=>M.stopPropagation(),children:n.jsx(cf,{value:k,options:e.kind==="task"?cj.map(M=>({value:M,label:v[M]?.label??M,cls:v[M]?.cls??"bg-gray-500/15 text-fg-tertiary"})):dj.map(M=>({value:M,label:S[M]?.label??M,cls:S[M]?.cls??"bg-gray-500/15 text-fg-tertiary"})),allowedValues:e.kind==="task"?uj[k]:e1[k],onSelect:M=>{m(e,M)}})}),n.jsx("div",{className:"w-[100px] shrink-0",onClick:M=>M.stopPropagation(),children:n.jsx(cf,{value:N,options:lj.map(M=>({value:M,label:C[M]?.label??M,cls:C[M]?.cls??"bg-gray-500/15 text-fg-tertiary"})),onSelect:M=>{p(e,M)}})}),n.jsx("div",{className:"w-[120px] shrink-0 text-[11px] truncate",children:j?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 ${l0[j.status]??"bg-gray-500"}`}),n.jsx("span",{className:`font-medium ${mj[j.status]??"text-fg-secondary"}`,children:j.name})]}):n.jsx("span",{className:"text-fg-muted",children:"—"})}),n.jsx("div",{className:"w-[120px] shrink-0 text-[11px] truncate",children:T?.name?n.jsx("span",{className:"text-brand-400/70",children:T.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:xj(e.data.updatedAt??"",g)})]})}function Une({tasks:e,requirements:t,agents:r,projects:s,onTaskClick:a,onReqClick:i,onRefresh:l,selectedTaskId:d,selectedReqId:u}){const{t:m}=kt(["work","common"]),p=ks(),[h,y]=b.useState("status"),[g,v]=b.useState(null),[S,C]=b.useState(null),k=b.useMemo(()=>{const D=[];for(const E of e){const $=qne(E.status);D.push({kind:"task",data:E,group:$,groupOrder:pj[$]??5})}for(const E of t){const $=A7[E.status]??"todo";D.push({kind:"req",data:E,group:$,groupOrder:pj[$]??5})}if(h==="status")D.sort((E,$)=>{if(E.groupOrder!==$.groupOrder)return E.groupOrder-$.groupOrder;const Y=new Date(E.data.updatedAt??0).getTime();return new Date($.data.updatedAt??0).getTime()-Y});else{const E=$=>Bne[$.data.priority]??2;D.sort(($,Y)=>{const W=E($),O=E(Y);return W!==O?W-O:new Date(Y.data.updatedAt??0).getTime()-new Date($.data.updatedAt??0).getTime()})}return D},[e,t,h]),N=async(D,E)=>{try{D.kind==="task"?await le.tasks.updateStatus(D.data.id,E):await le.requirements.updateStatus(D.data.id,E),l()}catch{}},j=async(D,E)=>{try{D.kind==="task"?await le.tasks.update(D.data.id,{priority:E}):await le.requirements.update(D.data.id,{priority:E}),l()}catch{}},T=(D,E)=>{v(E),D.dataTransfer.effectAllowed="move",D.dataTransfer.setData("text/plain",String(E)),D.currentTarget.style.opacity="0.4"},R=D=>{D.currentTarget.style.opacity="1",v(null),C(null)},M=(D,E)=>{D.preventDefault(),D.dataTransfer.dropEffect="move",S!==E&&C(E)},_=async(D,E)=>{if(D.preventDefault(),C(null),g==null)return;const $=k[g];if(!$||$.group===E)return;const Y=fy.find(W=>W.id===E);if(Y){try{if($.kind==="task"){if($.data.status==="pending")return;await le.tasks.updateStatus($.data.id,Y.dropStatus)}else{const W=E7[E];W&&await le.requirements.updateStatus($.data.id,W)}l()}catch{}v(null)}},F=b.useMemo(()=>new Map(r.map(D=>[D.id,D])),[r]),z=b.useMemo(()=>new Map(s.map(D=>[D.id,D])),[s]),L=["todo","in_progress","review","done"],U=b.useMemo(()=>{const D={};for(const E of k)D[E.group]=(D[E.group]??0)+1;return D},[k]),{rowsByGroup:K,rowIndexMap:q}=b.useMemo(()=>{const D=new Map,E=new Map;for(let $=0;$<k.length;$++){const Y=k[$];E.set(Y,$);const W=D.get(Y.group)??[];W.push(Y),D.set(Y.group,W)}return{rowsByGroup:D,rowIndexMap:E}},[k]),I=b.useMemo(()=>{if(h!=="status")return null;const D=new Set(k.map(Y=>Y.group)),E=[],$=new Set;D.has("failed")&&(E.push("failed"),$.add("failed"));for(const Y of L)E.push(Y),$.add(Y);for(const Y of k)$.has(Y.group)||(E.push(Y.group),$.add(Y.group));return E},[k,h]);return n.jsx("div",{className:`flex-1 min-h-0 overflow-auto bg-surface-primary ${p?"overflow-x-hidden w-full":""}`,children:n.jsxs("div",{className:p?"w-full":"w-fit min-w-full",children:[!p&&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:k.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 ${h==="status"?"text-brand-500":"hover:text-fg-secondary"}`,children:[m("work:filters.status")," ",h==="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 ${h==="priority"?"text-brand-500":"hover:text-fg-secondary"}`,children:[m("work:filters.priority")," ",h==="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:[h==="status"&&I?I.map(D=>{const E=K.get(D)??[];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 ${Hne[D]??""} ${S===D?"ring-1 ring-brand-500/40":""}`,onDragOver:$=>M($,D),onDragLeave:()=>C(null),onDrop:$=>{_($,D)},children:[n.jsx("span",{className:"text-[11px] font-semibold uppercase tracking-wider",children:m(`work:boardColumn.${D}`)}),n.jsx("span",{className:"text-[10px] text-fg-tertiary",children:U[D]??0})]}),E.map($=>n.jsx(bj,{row:$,idx:q.get($)??0,dragIdx:g,agentMap:F,projMap:z,onTaskClick:a,onReqClick:i,onRowDragStart:T,onRowDragEnd:R,handleStatusChange:N,handlePriorityChange:j,selected:$.kind==="task"?$.data.id===d:$.data.id===u,isMobile:p},`${$.kind}-${$.data.id}`))]},D)}):k.map((D,E)=>n.jsx(bj,{row:D,idx:E,dragIdx:g,agentMap:F,projMap:z,onTaskClick:a,onReqClick:i,onRowDragStart:T,onRowDragEnd:R,handleStatusChange:N,handlePriorityChange:j,selected:D.kind==="task"?D.data.id===d:D.data.id===u,isMobile:p},`${D.kind}-${D.data.id}`)),k.length===0&&n.jsx("div",{className:"flex items-center justify-center py-16 text-sm text-fg-tertiary",children:m("work:task.noItems")})]})]})})}function yj({authUser:e,previewMode:t,previewData:r}={}){const{t:s}=kt(["work","common"]),a=bd(Se.WORK),i=b.useMemo(()=>fy.map(ae=>({...ae,label:s(`work:boardColumn.${ae.id}`)})),[s]),l=b.useMemo(()=>T7(s),[s]),d=b.useMemo(()=>hy(s),[s]),u=ks(),m=b.useRef(null),[p,h]=b.useState(0);b.useEffect(()=>{const ae=m.current;if(!ae)return;const Ye=new ResizeObserver(([dt])=>h(dt.contentRect.width));return Ye.observe(ae),h(ae.clientWidth),()=>Ye.disconnect()},[]);const y=p||window.innerWidth,g=b.useRef(!1),v=Zu({side:"right",defaultWidth:Math.round(y/2),minWidth:380,maxWidth:Math.round(y*.8),storageKey:"markus_projects_detail_v4"});b.useEffect(()=>{p>0&&!g.current&&(g.current=!0,v.setWidth(Math.round(p/2)))},[p]);const[S,C]=b.useState(!1),k=b.useRef(S);k.current=S;const[N,j]=b.useState(r?.projects??[]),[T,R]=b.useState("all"),[M,_]=b.useState(null),[F,z]=b.useState(r?.board??{}),[L,U]=b.useState(r?.agents??[]),[K,q]=b.useState(r?.users??[]),[I,D]=b.useState(r?.allRequirements??[]),[E,$]=b.useState(!r),[Y,W]=b.useState(""),[O,H]=b.useState(!1),[Z,B]=b.useState(null),J=b.useCallback(()=>{Jt(M??""),Cn(!0)},[M]),[Q,ee]=b.useState(!1),[se,X]=b.useState(!1),[me,je]=b.useState(""),[Re,Ee]=b.useState(""),[we,pe]=b.useState("medium"),[Pe,Ae]=b.useState(""),[Xe,Ze]=b.useState(""),[at,pt]=b.useState(""),[Ct,_e]=b.useState(""),[ue,fe]=b.useState([]),[Me,ne]=b.useState("standard"),[he,Be]=b.useState("4h"),[de,Ce]=b.useState(""),[et,it]=b.useState(null),[Ve,Ge]=b.useState(()=>r?.initialSelectedReqId&&r.allRequirements?r.allRequirements.find(ae=>ae.id===r.initialSelectedReqId)??null:null),[ut,nt]=b.useState(new Set),[ft,Rt]=b.useState(!1),[lt,$e]=b.useState(new Set),ct=b.useRef(new Set),Ut=b.useRef(new Set),[zt,cn]=b.useState(null),[Ln,Xt]=b.useState(r?.initialBoardType??"backlog"),kn=b.useMemo(()=>[{id:"backlog"},{id:"kanban"},{id:"dag"}],[]),tr=hl(kn,Ln,Xt),ir=b.useRef(null),gs=b.useMemo(()=>({scrollContainerRef:ir}),[]),wr=hl(kn,Ln,Xt,gs),[or,Ue]=b.useState(!1),[Lt,Zt]=b.useState(null),[Ft,lr]=b.useState(!1),_n=b.useRef(null),dn=b.useRef(null),[Sn,Cn]=b.useState(!1),[$r,Mr]=b.useState(""),[hn,Ne]=b.useState(""),[At,Vt]=b.useState("medium"),[rn,Jt]=b.useState(""),[Ot,Fn]=b.useState(null),[$n,js]=b.useState(""),[kr,xe]=b.useState(""),[Qe,xt]=b.useState(""),[Kt,on]=b.useState(null),en=ae=>{W(ae),setTimeout(()=>W(""),3e3)},un=N.find(ae=>ae.id===M)??null,jn=un??N.find(ae=>ae.id===Z)??null,Bn=b.useCallback(()=>{H(!1),B(null)},[]),rr=b.useCallback(ae=>{if(O&&(M===ae||Z===ae)){Bn();return}M||B(ae),H(!0)},[O,M,Z,Bn]);b.useEffect(()=>{Ut.current=lt},[lt]);const Dr=b.useCallback(async()=>{try{const{projects:ae}=await le.projects.list();j(ae)}catch{}},[]),Bt=b.useCallback(async()=>{const ae={};T==="project"&&M&&(ae.projectId=M);try{const{board:Ye}=await le.tasks.board(ae);z(Ye)}catch{}},[T,M]),nr=b.useCallback(async()=>{try{const{agents:ae}=await le.agents.list();U(ae)}catch{}},[]),Ir=b.useCallback(async()=>{try{const{users:ae}=await le.users.list(e?.orgId);q(ae)}catch{}},[e?.orgId]),cr=b.useCallback(async()=>{try{const{requirements:ae}=await le.requirements.list({});D(ae)}catch{}},[]),Va=b.useCallback(async()=>{await Promise.all([Dr(),Bt(),nr(),Ir(),cr()]),$(!1)},[Dr,Bt,nr,Ir,cr]);b.useEffect(()=>{t||Va()},[t,Va]),b.useEffect(()=>{!t||!r||(j(r.projects??[]),z(r.board??{}),U(r.agents??[]),q(r.users??[]),D(r.allRequirements??[]))},[t,r]);const Gr=b.useCallback(ae=>{it(Ye=>Ye?.id===ae.id?(u&&k.current&&C(!1),null):(u&&(C(!0),history.pushState({mobileDetail:Se.WORK},"",window.location.hash)),ae)),Ge(null)},[u]),$s=b.useCallback(ae=>{Ge(Ye=>Ye?.id===ae.id?(u&&k.current&&C(!1),null):(u&&(C(!0),history.pushState({mobileDetail:Se.WORK},"",window.location.hash)),ae)),it(null)},[u]),Bs=b.useCallback(()=>{it(null),Ge(null),u&&k.current&&C(!1)},[u]),sa=b.useCallback(()=>{it(null),!Wa.current&&u&&k.current&&C(!1)},[u]);b.useEffect(()=>{if(!u)return;const ae=()=>{k.current&&(C(!1),it(null),Ge(null))};return window.addEventListener("popstate",ae),()=>window.removeEventListener("popstate",ae)},[u]);const Pr=b.useRef(et);Pr.current=et;const Wa=b.useRef(Ve);Wa.current=Ve,b.useEffect(()=>{const ae=Ye=>{if(Ye.key!=="Escape")return;const dt=Ye.target?.tagName;if(!(dt==="INPUT"||dt==="TEXTAREA"||dt==="SELECT")){if(Pr.current){it(null);return}if(Wa.current){Ge(null);return}}};return window.addEventListener("keydown",ae),()=>window.removeEventListener("keydown",ae)},[]),b.useEffect(()=>{if(t||!a)return;const ae=Pr.current?12e4:45e3,Ye=setInterval(()=>{Bt(),nr(),cr()},ae);let dt=null;const Et=()=>{dt||(dt=setTimeout(()=>{dt=null,Bt()},800))};let sn=null;const pr=()=>{sn||(sn=setTimeout(()=>{sn=null,cr()},800))},En=gn.on("task:update",Fr=>{Et();const ie=Fr?.payload;ie?.taskId&&it(Oe=>{if(!Oe||Oe.id!==ie.taskId)return Oe;const Je={};return typeof ie.status=="string"&&(Je.status=ie.status),Array.isArray(ie.deliverables)&&(Je.deliverables=ie.deliverables),Array.isArray(ie.notes)&&(Je.notes=ie.notes),ie.result!==void 0&&(Je.result=ie.result),{...Oe,...Je}})}),Dt=gn.on("task:create",()=>{Et()}),Ls=["requirement:created","requirement:approved","requirement:rejected","requirement:updated","requirement:completed","requirement:cancelled","requirement:resubmitted"].map(Fr=>gn.on(Fr,()=>{pr()})),Fs=()=>{rl("/taskboard"),Bt(),cr()};return window.addEventListener("markus:data-changed",Fs),()=>{clearInterval(Ye),En(),Dt(),Ls.forEach(Fr=>Fr()),window.removeEventListener("markus:data-changed",Fs),dt&&clearTimeout(dt),sn&&clearTimeout(sn)}},[t,a,Bt,nr,cr]);const Vi=b.useRef(F);Vi.current=F;const Ks=b.useRef(I);Ks.current=I;const Es=b.useCallback(ae=>{if(!ae)return;const Ye=Ut.current;Ye.size>0&&!Ye.has(ae)&&$e(dt=>new Set([...dt,ae]))},[]),[dr,va]=b.useState(!1),Hs=b.useCallback((ae,Ye)=>{it(ae),Ge(null),Ye?.scrollToComments&&va(!0),u&&(C(!0),history.pushState({mobileDetail:Se.WORK},"",window.location.hash))},[u]),xs=b.useCallback((ae,Ye)=>{Ge(ae),it(null),Ye?.scrollToComments&&va(!0),u&&(C(!0),history.pushState({mobileDetail:Se.WORK},"",window.location.hash))},[u]);b.useEffect(()=>{const ae=localStorage.getItem("markus_nav_openTask");if(!ae)return;const dt=Object.values(F).flat().find(Et=>Et.id===ae);dt&&(Es(dt.projectId),Hs(dt),localStorage.removeItem("markus_nav_openTask"))},[F,Hs,Es]),b.useEffect(()=>{const ae=localStorage.getItem("markus_nav_openRequirement");if(!ae)return;const Ye=I.find(dt=>dt.id===ae);Ye&&(Es(Ye.projectId),xs(Ye),localStorage.removeItem("markus_nav_openRequirement"))},[I,xs,Es]),b.useEffect(()=>{const ae=window.location.hash.slice(1).split("/");if(il(ae[0])===Se.WORK&&ae[1])yn(ae[1]);else{const Ye=localStorage.getItem("markus_nav_projectId");Ye&&(localStorage.removeItem("markus_nav_projectId"),yn(Ye))}},[]);const li=b.useRef(il(window.location.hash.slice(1).split("/")[0]));b.useEffect(()=>{if(t)return;const ae=()=>{const dt=window.location.hash.slice(1).split("/"),Et=il(dt[0]),sn=li.current===Se.WORK;li.current=Et,Et===Se.WORK&&(Et===Se.WORK&&dt[1]?yn(dt[1]):sn&&xr())},Ye=async dt=>{const Et=dt.detail;if(il(Et.page)===Se.WORK){if(Et.params?.openTask){const sn=Et.params.openTask,pr=Et.params.scrollToComments==="true";localStorage.removeItem("markus_nav_openTask");let En=Object.values(Vi.current).flat().find(Dt=>Dt.id===sn);if(!En)try{En=(await le.tasks.get(sn)).task}catch{}En&&(Es(En.projectId),Hs(En,{scrollToComments:pr}))}if(Et.params?.openRequirement){const sn=Et.params.openRequirement,pr=Et.params.scrollToComments==="true";let En=Ks.current.find(Dt=>Dt.id===sn);if(!En)try{En=(await le.requirements.get(sn)).requirement}catch{}En&&(Es(En.projectId),xs(En,{scrollToComments:pr}))}if(Et.params?.projectId&&yn(Et.params.projectId),Et.params?.statusFilter){const sn=Et.params.statusFilter;localStorage.removeItem("markus_nav_statusFilter"),Rne.has(sn)&&Ue(!0),Zt(sn)}}};return window.addEventListener("markus:navigate",Ye),window.addEventListener("hashchange",ae),()=>{window.removeEventListener("markus:navigate",Ye),window.removeEventListener("hashchange",ae)}},[t]);const yn=ae=>{Ut.current.size>0&&(ct.current=new Set(Ut.current)),$e(new Set),_(ae),R("project"),B(null),H(!1),history.replaceState(null,"",nw(Se.WORK,ae))},xr=()=>{$e(ct.current),_(null),R("all"),B(null),H(!1),history.replaceState(null,"",nw(Se.WORK))},ci=()=>{ee(!1),en(s("work:task.projectCreated")),Dr()},wa=async ae=>{if(confirm("Delete this project and unlink all its tasks?"))try{await le.projects.delete(ae),M===ae&&xr(),en("Project deleted"),Dr(),Bt()}catch(Ye){en(`Error: ${Ye}`)}},Ms=async()=>{if(!me||!Pe||!Xe)return;Ce("");const ae=Xe.startsWith("human:"),Ye=Xe.replace(/^(human|agent):/,"");if(Pe===Ye&&!ae){en(s("work:task.assignedReviewerDifferent"));return}const dt=at||void 0,Et=Ct||void 0;try{const{task:sn}=await le.tasks.create(me,Re,Pe,Ye,we,dt,ue.length>0?ue:void 0,Et,Me!=="standard"?Me:void 0,Me==="scheduled"?{every:he}:void 0,ae?"human":"agent");je(""),Ee(""),fe([]),_e(""),ne("standard"),Be("4h"),X(!1),Bt(),sn&&Hs(sn)}catch(sn){const En=`work:task.errorCode_${(sn instanceof Vj?sn.code:void 0)||"unknown"}`,Dt=s(En,{defaultValue:""});Ce(Dt||s("work:task.errorCreatingTask",{message:sn instanceof Error?sn.message:String(sn)}))}},Rr=ae=>{window.dispatchEvent(new CustomEvent("markus:mark-read-by-ref",{detail:ae}))},ji=()=>{Bt(),et&&(Rr({taskId:et.id}),setTimeout(()=>{const ae={};T==="project"&&M&&(ae.projectId=M),le.tasks.board(ae).then(Ye=>{const Et=Object.values(Ye.board).flat().find(sn=>sn.id===et.id);it(Et||null)}).catch(()=>{})},150))},vn=()=>{cr(),Ve&&setTimeout(()=>{le.requirements.list({}).then(({requirements:ae})=>{const Ye=ae.find(dt=>dt.id===Ve.id);Ge(Ye||null)}).catch(()=>{})},150)},Kn=async()=>{if(!$r.trim()){xe(s("work:task.pleaseReqTitle"));return}if(!hn.trim()){xe(s("work:task.pleaseReqDesc"));return}if(!rn){xe(s("work:task.pleaseReqProject"));return}xe("");try{const{requirement:ae}=await le.requirements.create({title:$r.trim(),description:hn.trim(),priority:At,projectId:rn});en(s("work:task.requirementCreated")),Mr(""),Ne(""),Cn(!1),cr(),ae&&xs(ae)}catch(ae){xe(ae instanceof Error?ae.message:String(ae))}},Yr=async ae=>{try{await le.requirements.approve(ae),en("Requirement approved"),Rr({requirementId:ae}),vn(),Bt()}catch(Ye){en(`Error: ${Ye}`)}},Ds=async()=>{if(Ot){xt("");try{await le.requirements.reject(Ot,$n),en("Requirement rejected"),Rr({requirementId:Ot}),Fn(null),js(""),xt(""),vn()}catch(ae){xt(ae instanceof Error?ae.message:String(ae))}}},ka=async ae=>{try{await le.requirements.cancel(ae),en("Requirement cancelled"),Rr({requirementId:ae}),vn()}catch(Ye){en(`Error: ${Ye}`)}},ja=(ae,Ye)=>{_n.current=Ye,dn.current=null,ae.dataTransfer.effectAllowed="move",ae.dataTransfer.setData("text/plain",`task:${Ye.id}`),ae.currentTarget.style.opacity="0.4"},Ns=(ae,Ye)=>{dn.current=Ye,_n.current=null,ae.dataTransfer.effectAllowed="move",ae.dataTransfer.setData("text/plain",`req:${Ye.id}`),ae.currentTarget.style.opacity="0.4"},Gs=ae=>{ae.currentTarget.style.opacity="1",_n.current=null,dn.current=null,cn(null)},Na=(ae,Ye)=>{ae.preventDefault(),ae.dataTransfer.dropEffect="move",zt!==Ye&&cn(Ye)},di=(ae,Ye)=>{const dt=ae.currentTarget.getBoundingClientRect(),{clientX:Et,clientY:sn}=ae;(Et<dt.left||Et>dt.right||sn<dt.top||sn>dt.bottom)&&zt===Ye&&cn(null)},Ka=async(ae,Ye)=>{ae.preventDefault(),cn(null);const dt=_n.current,Et=dn.current;if(dt){const sn=i.find(En=>En.id===Ye);if(!sn)return;const pr=sn.dropStatus;if(dt.status===pr||dt.status==="pending")return;try{await le.tasks.updateStatus(dt.id,pr),Bt()}catch{}}else if(Et){const sn=E7[Ye];if(!sn||Et.status===sn)return;try{await le.requirements.updateStatus(Et.id,sn),cr()}catch{}}},Xr=ae=>{nt(Ye=>{const dt=new Set(Ye);return dt.has(ae)?dt.delete(ae):dt.add(ae),dt})},Cr=ae=>{T==="project"?M===ae?xr():yn(ae):$e(Ye=>{const dt=new Set(Ye);return dt.has(ae)?dt.delete(ae):dt.add(ae),dt})},Br=new Set(["rejected","cancelled","archived"]),Ss=ae=>Br.has(ae.status),An=(ae,Ye=!1)=>{let dt=ae.filter(Et=>or||!Ss(Et));return Lt&&(dt=dt.filter(Et=>Et.status===Lt)),T==="project"&&M&&(dt=dt.filter(Et=>Et.projectId===M)),lt.size>0&&(dt=dt.filter(Et=>Et.projectId&&lt.has(Et.projectId))),ut.size>0&&(dt=dt.filter(Et=>Et.assignedAgentId&&ut.has(Et.assignedAgentId))),ft&&e?.id&&(dt=dt.filter(Et=>Et.createdBy===e.id)),dt},Hr=b.useMemo(()=>new Set(L.map(ae=>ae.id)),[L]),Sa=ae=>ae.statuses.flatMap(Ye=>An(F[Ye]??[])),Cs=b.useMemo(()=>{let ae=I;if(or||(ae=ae.filter(Ye=>!Ss(Ye))),T==="project"&&M&&(ae=ae.filter(Ye=>Ye.projectId===M)),lt.size>0&&(ae=ae.filter(Ye=>Ye.projectId&&lt.has(Ye.projectId))),ut.size>0){const Ye=e?.id;ae=ae.filter(dt=>ut.has(dt.createdBy)||Ye!=null&&dt.createdBy===Ye||!Hr.has(dt.createdBy))}return ft&&e?.id&&(ae=ae.filter(Ye=>Ye.createdBy===e.id)),ae},[I,or,T,M,lt,ut,ft,e?.id,Hr]),aa=b.useCallback(ae=>Cs.filter(Ye=>A7[Ye.status]===ae.id),[Cs]),Ca=i.filter(ae=>{if(ae.id==="failed"||ae.id==="closed"){const Ye=Sa(ae),dt=aa(ae);return Ye.length+dt.length>0}return!0}),Ys=Object.values(F).flat().filter(ae=>Ss(ae)).length+I.filter(ae=>Ss(ae)).length,Ga=b.useMemo(()=>{const ae=new Set(["completed","failed","cancelled","archived"]),Ye=Object.values(F).flat(),dt=new Set;for(const Et of Ye)Et.assignedAgentId&&!ae.has(Et.status)&&(!M||Et.projectId===M)&&dt.add(Et.assignedAgentId);return[...L].sort((Et,sn)=>{const pr=dt.has(Et.id)?0:1,En=dt.has(sn.id)?0:1;return pr-En})},[L,F,M]),To=b.useMemo(()=>{const ae=new Set(["completed","failed","cancelled","archived"]),Ye=Object.values(F).flat(),dt=new Set;for(const Et of Ye)Et.projectId&&!ae.has(Et.status)&&dt.add(Et.projectId);return[...N].sort((Et,sn)=>{const pr=Et.status==="archived"?1:0,En=sn.status==="archived"?1:0;if(pr!==En)return pr-En;const Dt=dt.has(Et.id)?0:1,Rs=dt.has(sn.id)?0:1;return Dt!==Rs?Dt-Rs:Et.name.localeCompare(sn.name)})},[N,F]),ui=b.useMemo(()=>{const ae={};for(const Ye of Object.values(F))for(const dt of Ye){const Et=dt.projectId??"__none__";ae[Et]=(ae[Et]??0)+1}return ae},[F]),Wi=Object.values(ui).reduce((ae,Ye)=>ae+Ye,0);if(E)return n.jsx("div",{className:"flex-1 flex items-center justify-center text-fg-tertiary",children:s("work:task.loadingPage")});const Ta=!!(et||Ve),Ni=!u&&!!(et&&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":Ta?"shrink-0 min-w-0":"flex-1"} overflow-hidden flex flex-col bg-surface-primary`,style:u?S?{display:"none"}:void 0:Ni?{width:0}:Ta?{width:`calc(100% - ${v.width}px - 4px)`}:void 0,children:[Y&&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:Y}),u?n.jsxs("div",{className:"shrink-0",children:[n.jsxs("div",{className:"flex items-center gap-2 px-3 h-11",children:[n.jsx(sc,{}),un?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:un.name}),n.jsx("button",{onClick:()=>rr(un.id),className:`w-6 h-6 flex items-center justify-center rounded-md transition-colors shrink-0 ${O?"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:()=>{pt(M??""),X(!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(ae=>n.jsx("button",{onClick:()=>Xt(ae),className:`px-2 py-0.5 text-[10px] font-medium transition-colors ${Ln===ae?"bg-brand-600/25 text-brand-500":"text-fg-tertiary"}`,children:s(ae==="backlog"?"work:task.backlog":ae==="kanban"?"work:task.kanban":"work:task.dag")},ae))}),Ys>0&&n.jsx("button",{onClick:()=>Ue(ae=>!ae),className:`text-[10px] shrink-0 px-2 py-0.5 rounded-md transition-colors ${or?"bg-surface-overlay text-fg-secondary":"text-fg-tertiary"}`,children:or?s("work:task.hideArchived"):s("work:task.archivedCount",{count:Ys})}),n.jsx("div",{className:"flex-1"}),Lt&&n.jsxs("button",{onClick:()=>Zt(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.${Lt==="in_progress"?"inProgress":Lt}`),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"})]})]}),(lt.size>0||ut.size>0||ft||N.length>1||L.length>0)&&n.jsxs("button",{onClick:()=>lr(!0),className:`px-2 py-1 text-[11px] rounded-md font-medium transition-colors flex items-center gap-1 ${lt.size>0||ut.size>0||ft?"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"})}),lt.size+ut.size+(ft?1:0)>0?s("work:task.filterWithCount",{count:lt.size+ut.size+(ft?1:0)}):s("work:task.filter")]})]})]}):n.jsxs("div",{className:"flex items-center gap-3 px-6 h-14 shrink-0",children:[un?n.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[n.jsx(nj,{value:un.name,onSave:async ae=>{await le.projects.update(un.id,{name:ae}),Dr()},className:"text-sm font-semibold text-fg-primary"}),n.jsx("button",{onClick:()=>rr(un.id),className:`w-6 h-6 flex items-center justify-center rounded-md transition-colors ${O?"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})}),Ys>0&&n.jsx("button",{onClick:()=>Ue(ae=>!ae),className:`text-[10px] shrink-0 px-2 py-0.5 rounded-md transition-colors ${or?"bg-surface-overlay text-fg-secondary":"text-fg-tertiary hover:text-fg-secondary"}`,children:or?s("work:task.hideArchivedWithCount",{count:Ys}):s("work:task.archivedCount",{count:Ys})}),n.jsx("div",{className:"flex items-center border border-border-default/60 rounded-md overflow-hidden shrink-0",children:["backlog","kanban","dag"].map(ae=>n.jsx("button",{onClick:()=>Xt(ae),className:`px-2.5 py-1 text-[10px] font-medium transition-colors ${Ln===ae?"bg-brand-600/25 text-brand-500":"text-fg-tertiary hover:text-fg-secondary hover:bg-surface-elevated"}`,children:s(ae==="backlog"?"work:task.backlog":ae==="kanban"?"work:task.kanban":"work:task.dag")},ae))}),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:()=>{pt(M??""),X(!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&&!M&&!O&&(Wi>0||I.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:()=>$e(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 ${lt.size>0?"visible opacity-100":"invisible opacity-0"}`,children:s("work:task.clear")}),To.map(ae=>{const Ye=lt.has(ae.id),dt=ui[ae.id]??0,Et=O&&Z===ae.id;return n.jsxs("div",{className:`flex items-center shrink-0 rounded-md overflow-hidden transition-all ${Ye?"bg-brand-500/15 ring-1 ring-brand-500/30":""}`,children:[n.jsxs("button",{onClick:()=>Cr(ae.id),className:`flex items-center gap-1.5 px-2.5 py-1 text-[11px] shrink-0 transition-all ${Ye?"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 ${Ye?"bg-brand-600 text-white":"bg-surface-overlay text-fg-secondary"}`,children:ae.name[0]?.toUpperCase()}),ae.name,dt>0&&n.jsx("span",{className:"text-[9px] text-fg-tertiary ml-0.5",children:dt})]}),Ye&&n.jsx("button",{onClick:()=>rr(ae.id),className:`px-1.5 py-1 self-stretch flex items-center border-l border-brand-500/20 transition-colors ${Et?"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"})]})})]},ae.id)})]}),!u&&(L.length>0||e?.id)&&!O&&(Wi>0||I.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:()=>{nt(new Set),Rt(!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 ${ut.size>0||ft?"visible opacity-100":"invisible opacity-0"}`,children:s("work:task.clear")}),e?.id&&n.jsx("button",{type:"button",onClick:()=>Rt(ae=>!ae),className:`flex items-center gap-1.5 px-2.5 py-1 rounded-md text-[11px] shrink-0 transition-all ${ft?"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")}),Ga.map(ae=>{const Ye=ut.has(ae.id);return n.jsxs("button",{onClick:()=>Xr(ae.id),className:`flex items-center gap-1.5 px-2.5 py-1 rounded-md text-[11px] shrink-0 transition-all ${Ye?"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 ${Ye?"bg-brand-600 text-white":"bg-surface-overlay text-fg-secondary"}`,children:ae.name[0]?.toUpperCase()}),ae.name]},ae.id)})]}),O&&jn?n.jsxs("div",{className:"flex-1 overflow-y-auto",children:[!un&&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:Bn,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(nj,{value:jn.name,onSave:async ae=>{await le.projects.update(jn.id,{name:ae}),Dr()},className:"text-sm font-semibold text-fg-primary truncate min-w-0"})]}),n.jsx($ne,{project:jn,tasks:Object.values(F).flat(),requirements:I,agents:L,onDeleteProject:()=>wa(jn.id),onUpdateProject:async ae=>{await le.projects.update(jn.id,ae)},onRefresh:()=>{Dr()}})]}):Wi===0&&Cs.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")})]})}):Ln==="backlog"?n.jsx("div",{className:"flex-1 min-h-0 flex flex-col",onTouchStart:u?tr.onTouchStart:void 0,onTouchEnd:u?tr.onTouchEnd:void 0,children:n.jsx(Une,{tasks:An(Object.values(F).flat()),requirements:Cs,agents:L,projects:N,onTaskClick:ae=>Gr(ae),onReqClick:ae=>$s(ae),onRefresh:()=>{Bt(),cr()},selectedTaskId:et?.id,selectedReqId:Ve?.id})}):Ln==="dag"?n.jsxs("div",{className:"flex-1 min-h-0 flex flex-col relative",onTouchStart:u?tr.onTouchStart:void 0,onTouchEnd:u?tr.onTouchEnd:void 0,children:[n.jsx(Nne,{tasks:(()=>{const ae=An(Object.values(F).flat(),!0);if(t&&Ve){const Ye=new Set(Ve.taskIds??[]);return ae.filter(dt=>Ye.has(dt.id))}return ae})(),requirements:t&&Ve?[Ve]:Cs,agents:L,showArchived:or,onShowArchivedChange:Ue,onTaskClick:ae=>Gr(ae),onReqClick:ae=>$s(ae),onCollapseDAG:()=>{it(null),Ge(null)},onDependencyChange:Bt,selectedTaskId:et?.id,selectedReqId:Ve?.id,hasDetailPanel:Ta,defaultExpandedNodeId:t&&Ve?`req-${Ve.id}`:void 0,previewMode:t}),u&&n.jsx("button",{onClick:()=>Xt("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:ir,className:"flex-1 min-h-0 overflow-x-auto overflow-y-hidden px-4 py-5",onTouchStart:u?wr.onTouchStart:void 0,onTouchEnd:u?wr.onTouchEnd:void 0,children:n.jsx("div",{className:"flex gap-3 h-full",children:Ca.map(ae=>{const Ye=Sa(ae),dt=aa(ae),Et=Ye.length+dt.length,sn=zt===ae.id;return n.jsxs("div",{className:`w-[280px] shrink-0 rounded-xl flex flex-col h-full transition-colors ${sn?"bg-surface-elevated/60 ring-1 ring-brand-500/30":"bg-surface-secondary/50"}`,onDragOver:pr=>Na(pr,ae.id),onDragLeave:pr=>di(pr,ae.id),onDrop:pr=>{Ka(pr,ae.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 ${ae.accent.replace("border-t-","bg-")}`}),n.jsx("span",{className:"text-xs font-semibold text-fg-secondary uppercase tracking-wider",children:ae.label})]}),n.jsx("span",{className:"text-[11px] text-fg-tertiary font-medium tabular-nums",children:Et})]}),n.jsx("div",{className:"space-y-2 flex-1 min-h-0 overflow-y-auto scrollbar-thin px-2 py-2",children:(()=>{const pr=[...dt.map(En=>({kind:"req",data:En,time:new Date(En.updatedAt??En.createdAt).getTime()})),...Ye.map(En=>({kind:"task",data:En,time:new Date(En.updatedAt??En.createdAt??0).getTime()}))];return pr.sort((En,Dt)=>Dt.time-En.time),pr.map(En=>{if(En.kind==="req"){const Dt=En.data,Rs=d[Dt.status]??{label:Dt.status,cls:"bg-gray-500/15 text-fg-secondary"},Fs=Dt.source==="agent"&&Dt.status==="pending",Fr=T==="all"&&Dt.projectId?N.find(Je=>Je.id===Dt.projectId):null,ie=xd(Dt.createdBy,L,K)??Dt.createdBy.slice(0,10),Oe=Ve?.id===Dt.id;return n.jsxs("div",{role:"button",tabIndex:0,draggable:!0,onDragStart:Je=>Ns(Je,Dt),onDragEnd:Gs,onClick:()=>$s(Dt),onKeyDown:Je=>Je.key==="Enter"&&$s(Dt),className:`group rounded-lg p-2.5 border border-transparent transition-all cursor-grab active:cursor-grabbing
705
705
  ${Fs?"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"}
706
- ${Oe?"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 ${Rs.cls}`,children:Rs.label})]}),n.jsx("div",{className:"text-[13px] font-medium leading-snug text-fg-primary line-clamp-2 mb-1",children:Dt.title}),Dt.description&&n.jsx("div",{className:"text-[11px] text-fg-tertiary line-clamp-1 mb-1.5",children:Dt.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:[Fr&&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:Fr.name,children:Fr.name}),n.jsx("span",{className:"text-[10px] text-fg-tertiary",children:Dt.priority}),n.jsxs("span",{className:"text-[10px] text-fg-quaternary",children:["by ",ie]})]}),n.jsx("div",{className:"flex items-center gap-1",children:Dt.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:["📋 ",Dt.taskIds.length]})})]}),Fs&&n.jsxs("div",{className:"flex items-center gap-2 mt-2 pt-2 border-t border-amber-500/15",children:[n.jsx("button",{onClick:Je=>{Je.stopPropagation(),Yr(Dt.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:Je=>{Je.stopPropagation(),Fn(Dt.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-${Dt.id}`)}else{const Dt=En.data,Rs=Dt.subtasks?.length??0,Ls=l[Dt.status],Fs=Dt.status==="pending",Fr=Dt.taskType==="scheduled"&&!!Dt.scheduleConfig,ie=Fr?Dt.scheduleConfig.every?s("work:task.everyInterval",{interval:Dt.scheduleConfig.every}):Dt.scheduleConfig.cron?s("work:task.cronLabel"):s("work:task.scheduledShort"):null,Oe=T==="all"&&Dt.projectId?(()=>{const rs=N.find(Cd=>Cd.id===Dt.projectId)?.name;return rs&&rs!=="default"?rs:null})():null,Je=Dt.requirementId?I.find(rs=>rs.id===Dt.requirementId)?.title:null,Mn=Dt.createdBy?xd(Dt.createdBy,L,K)??Dt.createdBy:null,ia=et?.id===Dt.id,Aa={urgent:"bg-red-500",high:"bg-amber-500",medium:"bg-blue-500",low:"bg-gray-400"};return n.jsxs("div",{role:"button",tabIndex:0,"aria-label":Dt.title,draggable:!Fs,onDragStart:rs=>!Fs&&ja(rs,Dt),onDragEnd:Gs,onClick:()=>Gr(Dt),onKeyDown:rs=>rs.key==="Enter"&&Gr(Dt),className:`group rounded-lg p-2.5 border border-transparent transition-all ${Fs?"bg-amber-500/[0.06] border-amber-500/30 ring-1 ring-amber-500/15 cursor-pointer":Fr?"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"} ${ia?"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 ${Aa[Dt.priority]??"bg-gray-400"}`,title:Dt.priority}),Fr&&n.jsx("span",{className:"text-blue-500 shrink-0",title:ie??"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"})})}),Fr&&ie&&n.jsx("span",{className:"text-[9px] px-1.5 py-0.5 rounded-md bg-blue-500/10 text-blue-500 whitespace-nowrap",children:ie}),Ls&&n.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded-md ml-auto shrink-0 ${Ls.cls}`,children:Ls.label})]}),n.jsx("div",{className:"text-[13px] font-medium leading-snug text-fg-primary line-clamp-2 mb-1",children:Dt.title}),Dt.description&&n.jsx("div",{className:"text-[11px] text-fg-tertiary line-clamp-1 mb-1.5",children:Dt.description}),(Oe||Je||Dt.blockedBy&&Dt.blockedBy.length>0)&&n.jsxs("div",{className:"flex flex-wrap gap-1 mb-1.5",children:[Oe&&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:Oe,children:Oe}),Je&&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:Je,children:["# ",Je]}),Dt.blockedBy&&Dt.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:["⏳ ",Dt.blockedBy.length," dep",Dt.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:Mn&&n.jsxs("span",{className:"text-[10px] text-fg-quaternary",title:`by ${Mn}`,children:["by ",Mn]})}),n.jsxs("div",{className:"flex items-center gap-1.5",children:[Rs>0&&n.jsxs("span",{className:"text-[10px] text-fg-tertiary",children:["⋮ ",Rs]}),Dt.notes&&Dt.notes.length>0&&n.jsxs("span",{className:"text-[10px] text-fg-tertiary",children:["📝 ",Dt.notes.length]}),Dt.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 ${l0[L.find(rs=>rs.id===Dt.assignedAgentId)?.status??""]??"bg-gray-500"}`}),L.find(rs=>rs.id===Dt.assignedAgentId)?.name??Dt.assignedAgentId.slice(0,8)]})]})]})]},Dt.id)}})})()}),sn&&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")})})]},ae.id)})})})]}),!u&&Ta&&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||S)&&Ta&&n.jsx("div",{className:`${u||Ni?"flex-1":"shrink-0"} overflow-hidden min-w-0 flex`,style:u||Ni?void 0:{width:v.width},children:Ni?n.jsxs(n.Fragment,{children:[n.jsx("div",{className:"flex-1 min-w-0 overflow-hidden",children:n.jsx(vj,{req:Ve,agents:L,projects:N,allTasks:Object.values(F).flat(),users:K,onClose:()=>{Ge(null)},onApprove:ae=>{Yr(ae)},onReject:ae=>{Fn(ae)},onCancel:ae=>{ka(ae),Ge(null)},onStatusChange:async(ae,Ye)=>{try{await le.requirements.updateStatus(ae,Ye),en(`Requirement status → ${Ye}`),Rr({requirementId:ae}),vn(),Bt()}catch(dt){en(`Error: ${dt}`)}},onRefresh:vn,authUser:e,onTaskClick:ae=>{it(ae)},onCreateTask:(ae,Ye)=>{_e(ae),Ye&&pt(Ye),X(!0)},onProjectClick:Cr,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(hj,{task:et,agents:L,projects:N,requirements:I,allTasks:Object.values(F).flat(),users:K,onClose:sa,onRefresh:ji,authUser:e,scrollToComments:dr,onScrollToCommentsDone:()=>va(!1),onReqClick:ae=>{Ge(Ye=>Ye?.id===ae.id?null:ae)},onProjectClick:Cr})})]}):et?n.jsx(hj,{task:et,agents:L,projects:N,requirements:I,allTasks:Object.values(F).flat(),users:K,onClose:Bs,onRefresh:ji,authUser:e,scrollToComments:dr,onScrollToCommentsDone:()=>va(!1),onReqClick:ae=>{Ge(Ye=>Ye?.id===ae.id?null:ae)},onProjectClick:Cr}):Ve?n.jsx(vj,{req:Ve,agents:L,projects:N,allTasks:Object.values(F).flat(),users:K,onClose:Bs,onApprove:ae=>{Yr(ae)},onReject:ae=>{Fn(ae)},onCancel:ae=>{ka(ae),Bs()},onStatusChange:async(ae,Ye)=>{try{await le.requirements.updateStatus(ae,Ye),en(`Requirement status → ${Ye}`),Rr({requirementId:ae}),vn(),Bt()}catch(dt){en(`Error: ${dt}`)}},scrollToComments:dr,onScrollToCommentsDone:()=>va(!1),onRefresh:vn,authUser:e,onTaskClick:ae=>{it(ae),u&&(C(!0),history.pushState({mobileDetail:Se.WORK},"",window.location.hash))},onCreateTask:(ae,Ye)=>{_e(ae),Ye&&pt(Ye),X(!0)},onProjectClick:Cr,previewMode:t}):null}),Q&&n.jsx(Sne,{orgId:e?.orgId,onCreated:ci,onClose:()=>ee(!1)}),se&&n.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 p-3",onClick:()=>{X(!1),Ce("")},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:ae=>ae.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:me,onChange:ae=>je(ae.target.value),onKeyDown:ae=>{ae.key==="Enter"&&Ms()},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:Re,onChange:ae=>Ee(ae.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(ku,{options:[{value:"",label:s("work:task.noProject")},...N.map(ae=>({value:ae.id,label:ae.name}))],value:at,onChange:ae=>{pt(ae),_e("")},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(ku,{options:[{value:"",label:s("work:task.selectRequirement")},...I.filter(ae=>ae.status==="in_progress"&&(!at||ae.projectId===at)).map(ae=>({value:ae.id,label:ae.title}))],value:Ct,onChange:_e,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(ku,{options:L.map(ae=>({value:ae.id,label:`${ae.name} (${ae.status})`})),value:Pe,onChange:Ae,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(ku,{options:[...K.map(ae=>({value:`human:${ae.id}`,label:ae.name})),...L.filter(ae=>ae.id!==Pe).map(ae=>({value:`agent:${ae.id}`,label:`${ae.name} (${ae.status})`}))],value:Xe,onChange:Ze,placeholder:s("work:task.selectReviewer"),noMatchesText:s("work:task.noMatches")})]})]}),n.jsxs("div",{className:`grid gap-4 ${Me==="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:we,onChange:ae=>pe(ae.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:Me,onChange:ae=>ne(ae.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")})]})]}),Me==="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:he,onChange:ae=>Be(ae.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(Cne,{options:Object.values(F).flat().filter(ae=>ae.status!=="completed"&&ae.status!=="cancelled").map(ae=>({value:ae.id,label:ae.title})),selected:ue,onAdd:ae=>fe([...ue,ae]),placeholder:s("work:task.selectDependency"),noMatchesText:s("work:task.noMatches")}),ue.length>0&&n.jsx("div",{className:"mt-2 flex flex-wrap gap-1.5",children:ue.map(ae=>{const Ye=Object.values(F).flat().find(dt=>dt.id===ae);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:[Ye?Ye.title.slice(0,30):ae.slice(-8),n.jsx("button",{onClick:()=>fe(ue.filter(dt=>dt!==ae)),className:"ml-0.5 text-amber-600/60 hover:text-amber-600",children:"×"})]},ae)})})]}),de&&n.jsx("div",{className:"px-3 py-2 bg-red-500/15 text-red-500 text-xs rounded-lg",children:de}),n.jsxs("div",{className:"flex justify-end gap-3 pt-1",children:[n.jsx("button",{onClick:()=>{X(!1),Ce("")},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:()=>{Ms()},disabled:!me.trim()||!Pe||!Xe,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")})]})]})}),Sn&&n.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 p-3",onClick:()=>{Cn(!1),Mr(""),Ne(""),xe("")},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:ae=>ae.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(ku,{options:N.map(ae=>({value:ae.id,label:ae.name})),value:rn,onChange:Jt,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:$r,onChange:ae=>Mr(ae.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:ae=>{ae.key==="Enter"&&$r.trim()&&Kn()}})]}),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:hn,onChange:ae=>Ne(ae.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:At,onChange:ae=>Vt(ae.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")})]})]}),kr&&n.jsx("div",{className:"px-3 py-2 bg-red-500/15 text-red-500 text-xs rounded-lg",children:kr}),n.jsxs("div",{className:"flex justify-end gap-3 pt-1",children:[n.jsx("button",{onClick:()=>{Cn(!1),Mr(""),Ne(""),xe("")},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:()=>{Kn()},disabled:!$r.trim()||!hn.trim()||!rn,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")})]})]})}),Ot&&n.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 p-3",onClick:()=>{Fn(null),xt("")},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:ae=>ae.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:$n,onChange:ae=>js(ae.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})]}),Qe&&n.jsx("div",{className:"px-3 py-2 bg-red-500/15 text-red-500 text-xs rounded-lg",children:Qe}),n.jsxs("div",{className:"flex justify-end gap-3",children:[n.jsx("button",{onClick:()=>{Fn(null),xt("")},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:()=>{Ds()},className:"px-4 py-2 text-sm bg-red-600 hover:bg-red-500 rounded-lg text-white",children:s("work:task.reject")})]})]})}),Ft&&n.jsxs("div",{className:"fixed inset-0 z-[60] flex flex-col justify-end",onClick:()=>lr(!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:ae=>ae.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:[(lt.size>0||ut.size>0||ft)&&n.jsx("button",{onClick:()=>{$e(new Set),nt(new Set),Rt(!1)},className:"text-[11px] text-brand-500 font-medium",children:s("work:task.clearAll")}),n.jsx("button",{onClick:()=>lr(!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:To.map(ae=>{const Ye=lt.has(ae.id),dt=ui[ae.id]??0;return n.jsxs("div",{className:`flex items-center rounded-lg overflow-hidden transition-all ${Ye?"bg-brand-500/15 ring-1 ring-brand-500/30":""}`,children:[n.jsxs("button",{onClick:()=>Cr(ae.id),className:`flex items-center gap-1.5 px-2.5 py-1.5 text-[11px] transition-all ${Ye?"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 ${Ye?"bg-brand-600 text-white":"bg-surface-overlay text-fg-tertiary"}`,children:ae.name[0]?.toUpperCase()}),ae.name,dt>0&&n.jsx("span",{className:"text-[9px] text-fg-tertiary",children:dt})]}),Ye&&n.jsx("button",{onClick:()=>{lr(!1),rr(ae.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"})]})})]},ae.id)})})]}),e?.id&&n.jsx("div",{className:"px-4 py-3 border-t border-border-default/40",children:n.jsx("button",{type:"button",onClick:()=>Rt(ae=>!ae),className:`w-full text-left px-2.5 py-1.5 rounded-lg text-[11px] transition-all ${ft?"bg-green-600/20 text-green-500 ring-1 ring-green-500/40":"bg-surface-elevated text-fg-secondary"}`,children:s("work:task.myTasks")})}),L.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:Ga.map(ae=>{const Ye=ut.has(ae.id);return n.jsxs("button",{onClick:()=>Xr(ae.id),className:`flex items-center gap-1.5 px-2.5 py-1.5 rounded-lg text-[11px] transition-all ${Ye?"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 ${Ye?"bg-brand-600 text-white":"bg-surface-overlay text-fg-tertiary"}`,children:ae.name[0]?.toUpperCase()}),ae.name]},ae.id)})})]}),n.jsx("div",{className:"h-[env(safe-area-inset-bottom,0px)]"})]})]})]})}function Vne({requirementId:e,createdBy:t,agents:r,users:s,authUser:a}){const{t:i}=kt(["work","common"]),[l,d]=b.useState([]),[u,m]=b.useState([]),p=b.useRef(null),[h,y]=b.useState(new Map);b.useEffect(()=>{m([]),y(new Map),p.current&&(clearTimeout(p.current),p.current=null),le.requirements.getComments(e).then(k=>d(k.comments)).catch(()=>{})},[e]),b.useEffect(()=>gn.on("requirement:comment",N=>{if(N.payload?.requirementId===e&&N.payload.comment){const j=N.payload.comment;d(T=>T.some(R=>R.id===j.id)?T:[...T,j]),(j.authorType==="agent"||j.authorId?.startsWith("agt_"))&&(m(T=>{const R=T.filter(M=>M.id!==j.authorId);return R.length===0&&p.current&&(clearTimeout(p.current),p.current=null),R}),y(T=>{const R=new Map(T);return R.delete(j.authorId),R}))}}),[e]),b.useEffect(()=>{if(u.length===0)return;const k=new Set(u.map(j=>j.id));return gn.on("agent:activity_log",j=>{const T=j.payload;if(!T)return;const R=T.agentId;if(!k.has(R))return;const M=T.type;if(M==="tool_start"||M==="tool_end"){const F={tool:T.content??T.metadata?.tool??"",phase:M==="tool_start"?"start":"end",success:M==="tool_end"?T.metadata?.success!==!1:void 0,ts:Date.now()};y(z=>{const L=new Map(z),U=[...L.get(R)??[],F];return L.set(R,U),L})}})},[u]);const[g,v]=b.useState(null),S=async(k,N,j,T)=>{let R;j.length>0&&(R=(await le.uploads.upload(j.map(L=>({dataUrl:L.dataUrl,name:L.name})),"comments")).files.map(L=>({type:"image",url:L.url,name:L.name}))),await le.requirements.addComment(e,k,a?.name,R,a?.id,N.length>0?N:void 0,T);const M=[],_=new Set,F=z=>{if(_.has(z)||z===a?.id)return;_.add(z);const L=r.find(U=>U.id===z);L&&M.push({id:L.id,name:L.name,avatarUrl:L.avatarUrl})};for(const z of N){const L=r.find(U=>U.name.toLowerCase()===z.toLowerCase());L&&F(L.id)}t?.startsWith("agt_")&&F(t),M.length>0&&(p.current&&clearTimeout(p.current),m(M),p.current=setTimeout(()=>m([]),12e4))},C=b.useCallback(k=>{v({id:k.id,authorName:k.authorName,content:k.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(k=>n.jsx($u,{comment:k,agents:r,onReply:C},k.id)),u.length>0&&n.jsx("div",{className:"flex flex-col gap-1.5 pt-1",children:u.map(k=>{const N=h.get(k.id)??[];return n.jsxs("div",{className:"px-2 py-1.5 rounded-lg cursor-pointer hover:bg-surface-elevated/60 transition-colors",onClick:()=>Nt.navigate(Se.TEAM,{agentId:k.id,profileTab:"mind"}),children:[n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsxs("div",{className:"relative shrink-0",children:[n.jsx(gr,{name:k.name,avatarUrl:k.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:k.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(Ch,{activities:N,isActive:!0})})]},k.id)})})]}),n.jsx(wS,{agents:r,humans:s,onSubmit:S,replyTo:g,onCancelReply:()=>v(null)})]})}function vj({req:e,agents:t,projects:r,allTasks:s,users:a,onClose:i,onApprove:l,onReject:d,onCancel:u,onStatusChange:m,onRefresh:p,authUser:h,scrollToComments:y,onScrollToCommentsDone:g,onTaskClick:v,onCreateTask:S,onProjectClick:C,previewMode:k}){const{t:N}=kt(["work","common"]),j=b.useMemo(()=>hy(N),[N]),T=b.useMemo(()=>T7(N),[N]),R=ks(),[M,_]=b.useState(!1),[F,z]=b.useState(e.description),[L,U]=b.useState(!1),[K,q]=b.useState(!1),I=b.useRef(null),[D,E]=b.useState("none"),$=b.useRef(null),Y=b.useRef(null),W=b.useRef(80);b.useEffect(()=>{const X=I.current;if(!X)return;const me=()=>{const{scrollTop:Re,scrollHeight:Ee,clientHeight:we}=X;if(!(Ee>we+50)){E("none");return}const Pe=Re<30,Ae=Re+we>=Ee-30;E(Pe?"top":Ae?"bottom":"middle")};me(),X.addEventListener("scroll",me,{passive:!0});const je=new ResizeObserver(me);return je.observe(X),()=>{X.removeEventListener("scroll",me),je.disconnect()}},[]),b.useEffect(()=>{if(M&&Y.current){const X=Y.current;X.style.height="auto",X.style.height=Math.max(X.scrollHeight,W.current)+"px",X.focus()}},[M]),b.useEffect(()=>{if(!y)return;const X=setTimeout(()=>{const me=I.current;me&&me.scrollTo({top:me.scrollHeight,behavior:"smooth"}),g?.()},300);return()=>clearTimeout(X)},[y,g]);const O=j[e.status]??{label:e.status,cls:"bg-gray-500/15 text-fg-secondary"},H=e.source==="agent",Z=H&&e.status==="pending",B=e.status==="pending"||e.status==="in_progress",J=e.status==="completed"||e.status==="rejected"||e.status==="cancelled"||e.status==="archived",Q=e.projectId?r.find(X=>X.id===e.projectId):null,ee=xd(e.createdBy,t,a)??e.createdBy.slice(0,12),se=s.filter(X=>e.taskIds.includes(X.id));return b.useEffect(()=>{z(e.description),_(!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:[R&&n.jsx("button",{onClick:i,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 ${O.cls}`,children:O.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:I,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")}),M?n.jsx("textarea",{ref:Y,value:F,onChange:X=>{z(X.target.value);const me=X.target;me.style.height="auto",me.style.height=me.scrollHeight+"px"},onBlur:async()=>{if(F!==e.description){U(!0);try{await le.requirements.update(e.id,{description:F}),p?.()}catch{}finally{U(!1)}}_(!1)},onKeyDown:X=>{X.key==="Escape"&&(X.preventDefault(),z(e.description),_(!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:()=>{W.current=Math.max($.current?.offsetHeight??80,60),z(e.description),_(!0)},role:J?void 0:"button",tabIndex:J?void 0:0,onKeyDown:J?void 0:X=>X.key==="Enter"&&(z(e.description),_(!0)),children:e.description?n.jsx(Ur,{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}),H&&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()})]}),Q&&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(Q.id):void 0,role:C?"button":void 0,tabIndex:C?0:void 0,onKeyDown:C?X=>X.key==="Enter"&&C(Q.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:Q.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:xd(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(X=>n.jsxs("span",{className:"text-[10px] bg-surface-elevated text-fg-secondary px-2 py-0.5 rounded-full",children:["#",X]},X))}),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:se.length})}),!J&&S&&n.jsxs("button",{onClick:()=>S(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")]})]}),se.length>0?(()=>{const X=new Map(se.map(pe=>[pe.id,pe]));if(!se.some(pe=>pe.blockedBy?.some(Pe=>X.has(Pe))))return n.jsx("div",{className:"space-y-1.5",children:se.map(pe=>{const Pe=T[pe.status];return n.jsxs("div",{onClick:()=>v?.(pe),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 ${l0[pe.status]??"bg-gray-500"}`}),n.jsx("span",{className:"text-xs text-fg-secondary flex-1 truncate",children:pe.title}),Pe&&n.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded shrink-0 ${Pe.cls}`,children:Pe.label})]},pe.id)})});const je=new Map,Re=new Set;for(const pe of se)for(const Pe of pe.blockedBy??[])if(X.has(Pe)){Re.add(pe.id);const Ae=je.get(Pe)??[];Ae.push(pe.id),je.set(Pe,Ae)}const Ee=se.filter(pe=>!Re.has(pe.id)),we=(pe,Pe)=>{const Ae=T[pe.status],Xe=(je.get(pe.id)??[]).map(Ze=>X.get(Ze)).filter(Boolean);return n.jsxs("div",{children:[n.jsxs("div",{onClick:()=>v?.(pe),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:Pe>0?{marginLeft:Pe*20}:void 0,children:[Pe>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 ${l0[pe.status]??"bg-gray-500"}`}),n.jsx("span",{className:"text-xs text-fg-secondary flex-1 truncate",children:pe.title}),Ae&&n.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded shrink-0 ${Ae.cls}`,children:Ae.label})]}),Xe.map(Ze=>we(Ze,Pe+1))]},pe.id)};return n.jsx("div",{className:"space-y-1.5",children:Ee.map(pe=>we(pe,0))})})():n.jsx("div",{className:"text-xs text-fg-tertiary italic py-2",children:N("work:requirement.noLinkedTasks")})]}),!k&&n.jsx(Vne,{requirementId:e.id,createdBy:e.createdBy,agents:t,users:a,authUser:h}),!k&&n.jsx(M7,{entityType:"requirement",entityId:e.id})]}),D!=="none"&&D!=="top"&&n.jsx("button",{onClick:()=>I.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"})})}),D!=="none"&&D!=="bottom"&&n.jsx("button",{onClick:()=>{const X=I.current;X&&X.scrollTo({top:X.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:X=>{X.target.value!==e.status&&m(e.id,X.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:Fne.map(X=>{const me=j[X],je=X===e.status||(e1[e.status]?.has(X)??!1);return n.jsx("option",{value:X,disabled:!je,children:me?.label??X},X)})}),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"}),B&&!Z&&n.jsx("button",{onClick:()=>q(!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")})]}),K&&n.jsx(Yc,{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:()=>{q(!1),u(e.id)},onCancel:()=>q(!1)})]})}function M7({entityType:e,entityId:t}){const{t:r}=kt(["work"]),[s,a]=b.useState([]),[i,l]=b.useState(!0),[d,u]=b.useState(!1);if(b.useEffect(()=>{l(!0),(e==="task"?le.tasks.getHistory:le.requirements.getHistory)(t).then(g=>a(g.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),p=s.length>5&&!d,h=y=>{const g=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:g})};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")}),p&&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:[h(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 Di(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 Wne(e){return e.files&&typeof e.files=="object"&&!Array.isArray(e.files)?e.files:null}function Hl({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 Fc({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 Ux({files:e}){const{t}=kt(["builder","common"]),[r,s]=b.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 Kne({artifact:e,mode:t}){const{t:r}=kt(["builder","common"]),s=Wne(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,p=a?.llmProvider,h=a?.llmModel,y=Di(l?.env),g=Di(l?.skills);return n.jsxs("div",{className:"space-y-3 text-sm",children:[n.jsx(Hl,{label:r("builder:artifact.name"),value:d}),n.jsx(Hl,{label:r("builder:artifact.description"),value:e.description}),n.jsxs("div",{className:"flex flex-wrap gap-2",children:[u&&n.jsx(Fc,{label:r("builder:artifact.baseTemplate"),value:u,color:"indigo"}),n.jsx(Fc,{label:r("builder:artifact.agentRole"),value:m,color:m==="manager"?"purple":"cyan"})]}),Di(e.tags).length>0&&n.jsx("div",{className:"flex flex-wrap gap-1",children:Di(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))}),(p||h)&&n.jsxs("div",{className:"flex gap-2",children:[p&&n.jsx(Fc,{label:r("builder:artifact.llmProvider"),value:p,color:"gray"}),h&&n.jsx(Fc,{label:r("builder:artifact.llmModel"),value:h,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))})]}),g.length>0&&n.jsx(Hl,{label:r("builder:artifact.skills"),value:g.join(", ")}),s&&n.jsx(Ux,{files:s})]})}if(t==="team"){const m=i?.members??[];return n.jsxs("div",{className:"space-y-3 text-sm",children:[n.jsx(Hl,{label:r("builder:artifact.name"),value:d}),n.jsx(Hl,{label:r("builder:artifact.description"),value:e.description}),n.jsx("div",{className:"flex flex-wrap gap-2",children:n.jsx(Fc,{label:r("builder:artifact.category"),value:e.category,color:"indigo"})}),Di(e.tags).length>0&&n.jsx("div",{className:"flex flex-wrap gap-1",children:Di(e.tags).map(p=>n.jsx("span",{className:"px-1.5 py-0.5 text-[10px] bg-surface-elevated text-fg-tertiary rounded",children:p},p))}),s&&n.jsx(Ux,{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((p,h)=>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 ${p.role==="manager"?"bg-brand-500/20 text-brand-500":"bg-blue-500/20 text-blue-600"}`,children:p.role==="manager"?"★":h+1}),n.jsx("span",{className:"text-xs text-fg-secondary flex-1 truncate",children:p.name}),typeof p.roleName=="string"&&p.roleName&&n.jsx("span",{className:"text-[10px] text-brand-500/70 font-mono",children:p.roleName}),n.jsxs("span",{className:"text-[10px] text-fg-tertiary",children:["x",String(p.count??1)]})]}),Di(p.skills).length>0&&n.jsx("div",{className:"mt-1 ml-7 flex flex-wrap gap-1",children:Di(p.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))})]},h))})]})]})}return n.jsxs("div",{className:"space-y-3 text-sm",children:[n.jsx(Hl,{label:r("builder:artifact.name"),value:d}),n.jsx(Hl,{label:r("builder:artifact.description"),value:e.description}),n.jsx("div",{className:"flex gap-2",children:n.jsx(Fc,{label:r("builder:artifact.category"),value:e.category,color:"indigo"})}),s&&n.jsx(Ux,{files:s}),Di(e.tags).length>0&&n.jsx("div",{className:"flex flex-wrap gap-1",children:Di(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 ju={file:{icon:"📄",color:"bg-green-500/10 text-green-600"},directory:{icon:"📁",color:"bg-blue-500/10 text-blue-600"}},Gne={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"}},Yne=["file","directory"];function df(e){return/^https?:\/\//i.test(e)}const Fl={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 wj({authUser:e,previewMode:t,previewData:r}={}){const{t:s}=kt(["deliverables","common"]),a=ks(),i=bd(Se.DELIVERABLES),l=Zu({side:"left",defaultWidth:384,minWidth:280,maxWidth:600,storageKey:"markus_deliverables_list"}),[d,u]=b.useState(!1),m=b.useRef(d);m.current=d,b.useEffect(()=>{if(!a)return;const Ue=()=>{m.current&&u(!1)};return window.addEventListener("popstate",Ue),()=>window.removeEventListener("popstate",Ue)},[a]);const p=100,[h,y]=b.useState(r?.items??[]),[g,v]=b.useState(r?.items?.length??0),[S,C]=b.useState(!1),[k,N]=b.useState(r?.projects??[]),[j,T]=b.useState(r?.agents??[]),[R,M]=b.useState(!r),[_,F]=b.useState(""),[z,L]=b.useState(""),[U,K]=b.useState(""),[q,I]=b.useState(""),[D,E]=b.useState(""),[$,Y]=b.useState(""),[W,O]=b.useState(""),[H,Z]=b.useState("date"),[B,J]=b.useState(()=>r?.initialSelectedId&&r.items?r.items.find(Ue=>Ue.id===r.initialSelectedId)??r.items[0]??null:r?.items?.[0]??null),[Q,ee]=b.useState(null),[se,X]=b.useState(""),[me,je]=b.useState(new Set),Re=b.useMemo(()=>[{id:"date"},{id:"project"},{id:"agent"},{id:"type"}],[]),Ee=b.useCallback(Ue=>{Z(Ue),je(new Set)},[]),we=hl(Re,H,Ee),pe=b.useRef(null),[Pe,Ae]=b.useState(null),[Xe,Ze]=b.useState("markdown"),[at,pt]=b.useState(null),[Ct,_e]=b.useState(!1),[ue,fe]=b.useState(!1),[Me,ne]=b.useState(!1),[he,Be]=b.useState(null),[de,Ce]=b.useState(""),[et,it]=b.useState(new Set),Ve=b.useRef(void 0),Ge=(Ue,Lt)=>{ee({type:Ue,text:Lt}),setTimeout(()=>ee(null),3e3)},ut=async Ue=>{await H1(Ue)?(ne(!0),setTimeout(()=>ne(!1),1500)):Ge("error",s("detail.copyFailed"))},nt=b.useMemo(()=>new Map(j.map(Ue=>[Ue.id,Ue])),[j]),ft=b.useMemo(()=>new Map(k.map(Ue=>[Ue.id,Ue])),[k]),Rt=b.useCallback(Ue=>{if(!Ue||Ue==="default")return null;const Lt=ft.get(Ue)?.name;return!Lt||Lt==="default"?null:Lt},[ft]);b.useEffect(()=>{t||(le.projects.list().then(Ue=>N(Ue.projects)).catch(()=>{}),le.agents.list().then(Ue=>T(Ue.agents??[])).catch(()=>{}),le.system.storage().then(Ue=>Ce(Ue.dataDir+"/shared")).catch(()=>{}),le.deliverables.checkHealth().then(Ue=>it(new Set(Ue.missingFiles))).catch(()=>{}))},[t]),b.useEffect(()=>(Ve.current=setTimeout(()=>L(_),300),()=>clearTimeout(Ve.current)),[_]);const lt=b.useMemo(()=>({q:z||void 0,projectId:q||void 0,agentId:D||void 0,type:U||void 0,status:$||void 0,artifactType:W||void 0}),[z,q,D,U,$,W]),$e=b.useCallback(async()=>{M(!0);try{const{results:Ue,total:Lt}=await le.deliverables.search({...lt,offset:0,limit:p});y(Ue),v(Lt)}catch{y([]),v(0)}M(!1)},[lt]),ct=b.useCallback(async()=>{if(!(S||h.length>=g)){C(!0);try{const{results:Ue,total:Lt}=await le.deliverables.search({...lt,offset:h.length,limit:p});y(Zt=>[...Zt,...Ue]),v(Lt)}catch{}C(!1)}},[lt,h.length,g,S]);b.useEffect(()=>{t||$e()},[$e,t]),b.useEffect(()=>{!t||!r||(y(r.items??[]),v(r.items?.length??0),N(r.projects??[]),T(r.agents??[]),r.initialSelectedId&&J(r.items?.find(Ue=>Ue.id===r.initialSelectedId)??r.items?.[0]??null))},[t,r]),b.useEffect(()=>{if(t||!i)return;const Ue=gn.on("deliverable:created",()=>$e()),Lt=gn.on("deliverable:updated",()=>$e()),Zt=gn.on("deliverable:removed",()=>$e());return()=>{Ue(),Lt(),Zt()}},[$e,i,t]);const Ut=b.useRef(null),zt=b.useRef(h);zt.current=h;const cn=b.useCallback(Ue=>{const Lt=Ft=>{J(Ft),a&&(u(!0),history.pushState({mobileDetail:Se.DELIVERABLES},"",window.location.hash))},Zt=zt.current.find(Ft=>Ft.id===Ue);if(Zt){Lt(Zt);return}le.deliverables.get(Ue).then(Ft=>{Ft.deliverable&&Lt(Ft.deliverable)}).catch(()=>{})},[a]);b.useEffect(()=>{if(t)return;const Ue=localStorage.getItem("markus_nav_openDeliverable");Ue&&(localStorage.removeItem("markus_nav_openDeliverable"),zt.current.length>0?cn(Ue):Ut.current=Ue);const Lt=Zt=>{const Ft=Zt.detail;Ft?.params?.openDeliverable&&(localStorage.removeItem("markus_nav_openDeliverable"),cn(Ft.params.openDeliverable))};return window.addEventListener("markus:navigate",Lt),()=>window.removeEventListener("markus:navigate",Lt)},[cn,t]),b.useEffect(()=>{const Ue=Ut.current;!Ue||h.length===0||(Ut.current=null,cn(Ue))},[h,cn]);const Ln=b.useCallback(()=>{const Ue=pe.current;!Ue||R||S||h.length>=g||Ue.scrollHeight<=Ue.clientHeight+100&&ct()},[R,S,h.length,g,ct]);b.useEffect(()=>{const Ue=pe.current;if(!Ue)return;const Lt=()=>{Ue.scrollTop+Ue.clientHeight>=Ue.scrollHeight-100&&ct()};return Ue.addEventListener("scroll",Lt,{passive:!0}),()=>Ue.removeEventListener("scroll",Lt)},[ct]),b.useEffect(()=>{Ln()},[Ln,me]);const Xt=b.useMemo(()=>{const Ue=new Map;for(const Zt of h){let Ft,lr;if(H==="project"){const _n=Rt(Zt.projectId);Ft=_n?Zt.projectId??"_none":"_none",lr=_n??s("noProject")}else if(H==="agent")Ft=Zt.agentId??"_none",lr=Zt.agentId?nt.get(Zt.agentId)?.name??Zt.agentId:s("common:unknown");else if(H==="type")Ft=Zt.type,lr=Zt.type.charAt(0).toUpperCase()+Zt.type.slice(1);else{const _n=new Date(Zt.updatedAt);Ft=`${_n.getFullYear()}-${String(_n.getMonth()+1).padStart(2,"0")}-${String(_n.getDate()).padStart(2,"0")}`,lr=Ft}Ue.has(Ft)||Ue.set(Ft,{label:lr,items:[]}),Ue.get(Ft).items.push(Zt)}const Lt=[...Ue.entries()];return H==="date"?Lt.sort((Zt,Ft)=>Ft[0].localeCompare(Zt[0])):Lt.sort((Zt,Ft)=>Zt[1].label.localeCompare(Ft[1].label)),Lt},[h,H,ft,nt,s]),kn=async Ue=>{X("remove");try{await le.deliverables.remove(Ue.id),Ge("success",s("removed")),J(null),$e()}catch(Lt){Ge("error",s("common:error",{message:String(Lt)}))}X("")},tr=()=>{Nt.navigate(Se.BUILDER)},ir=async Ue=>{if(Ue.reference&&!df(Ue.reference)){if(Ue.type==="directory"){fe(!0);return}_e(!0);try{const Lt=await le.files.preview(Ue.reference);Lt.type==="image"&&Lt.mimeType?pt({src:`data:${Lt.mimeType};base64,${Lt.content}`,name:Lt.name}):(Ae(Lt.content),Ze(OS({format:Ue.format,reference:Ue.reference,content:Lt.content})))}catch{Ae(null),Ue.type==="file"&&fe(!0)}_e(!1)}};b.useEffect(()=>{t||(Ae(null),Ze("markdown"),pt(null),fe(!1),B&&ir(B))},[B?.id,t]);const gs=b.useCallback(Ue=>{je(Lt=>{const Zt=new Set(Lt);return Zt.has(Ue)?Zt.delete(Ue):Zt.add(Ue),Zt})},[]),wr=b.useCallback(()=>{me.size===Xt.length?je(new Set):je(new Set(Xt.map(([Ue])=>Ue)))},[me.size,Xt]),or=Ue=>{J(Ue),a&&(u(!0),history.pushState({mobileDetail:Se.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(sc,{}),n.jsxs("h2",{className:"text-sm font-semibold text-fg-secondary truncate",children:[s("title"),g>0&&n.jsxs("span",{className:"ml-1.5 text-fg-tertiary font-normal",children:["(",g,")"]})]})]})}),n.jsx("input",{value:_,onChange:Ue=>F(Ue.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"}),de&&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:de}),n.jsx("button",{onClick:()=>{le.system.openPath(de)},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(Nu,{label:s("filters.allTypes"),value:"",current:U||W||"",onClick:()=>{K(""),O("")}}),Yne.map(Ue=>n.jsx(Nu,{label:`${ju[Ue]?.icon??""} ${Ue}`,value:Ue,current:U,onClick:Lt=>{K(Lt),O("")}},Ue)),["agent","team","skill"].map(Ue=>n.jsx(Nu,{label:`${Fl[Ue].icon} ${s(`artifactTypes.${Ue}`)}`,value:Ue,current:W,onClick:Lt=>{O(Lt),K("")}},Ue))]}),k.length>0&&n.jsxs("div",{className:"flex gap-1 overflow-x-auto scrollbar-hide",children:[n.jsx(Nu,{label:s("filters.allProjects"),value:"",current:q,onClick:I}),k.map(Ue=>n.jsx(Nu,{label:Ue.name,value:Ue.id,current:q,onClick:I},Ue.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(Ue=>n.jsx("button",{onClick:()=>{Z(Ue),je(new Set)},className:`px-2 py-1 rounded text-xs transition-colors ${H===Ue?"bg-brand-600 text-white":"bg-surface-elevated text-fg-secondary hover:bg-surface-overlay"}`,children:s(`groupBy.${Ue}`)},Ue)),Xt.length>1&&n.jsx("button",{onClick:wr,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:me.size===Xt.length?s("expandAllTooltip"):s("collapseAllTooltip"),children:me.size===Xt.length?s("expandAll"):s("collapseAll")})]})]}),Q&&n.jsx("div",{className:`mx-4 mt-2 px-3 py-1.5 text-xs rounded-lg ${Q.type==="success"?"bg-green-500/15 text-green-600":"bg-red-500/15 text-red-500"}`,children:Q.text}),n.jsxs("div",{ref:pe,className:"flex-1 overflow-y-auto p-2 space-y-1",onTouchStart:a?we.onTouchStart:void 0,onTouchEnd:a?we.onTouchEnd:void 0,children:[R?n.jsx("div",{className:"p-4 space-y-3",children:[1,2,3].map(Ue=>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"})]},Ue))}):h.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:()=>Nt.navigate(Se.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")})]}):Xt.map(([Ue,Lt])=>{const Zt=me.has(Ue);return n.jsxs("div",{children:[n.jsxs("button",{onClick:()=>gs(Ue),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 ${Zt?"":"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:Lt.label}),n.jsxs("span",{className:"text-[10px] text-fg-tertiary shrink-0",children:["(",Lt.items.length,")"]})]}),!Zt&&Lt.items.map(Ft=>n.jsx("button",{onClick:()=>or(Ft),className:`w-full text-left px-3 py-2 rounded-lg transition-colors ${B?.id===Ft.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:[Ft.artifactType&&Fl[Ft.artifactType]?n.jsx("span",{className:`text-[10px] px-1 py-0.5 rounded font-medium shrink-0 ${Fl[Ft.artifactType].color}`,children:Fl[Ft.artifactType].icon}):n.jsx("span",{className:`text-[10px] px-1 py-0.5 rounded font-medium uppercase shrink-0 ${ju[Ft.type]?.color??"bg-surface-overlay text-fg-secondary"}`,children:ju[Ft.type]?.icon??Ft.type.charAt(0)}),n.jsx("span",{className:"text-sm font-medium text-fg-primary truncate",children:Ft.title}),et.has(Ft.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 ${Gne[Ft.status]?.color??"bg-surface-elevated text-fg-tertiary"}`,children:s(`common:status.${Ft.status}`,{defaultValue:Ft.status})})]})},Ft.id))]},Ue)}),S&&n.jsxs("div",{className:"flex items-center justify-center gap-2 py-3 text-fg-tertiary",children:[n.jsx(kj,{})," ",n.jsx("span",{className:"text-[10px]",children:s("common:loadingMore")})]}),!R&&h.length>0&&n.jsx("div",{className:"text-center text-[10px] text-fg-tertiary py-2",children:h.length<g?s("count.partial",{loaded:h.length,total:g}):s("count.total",{total:g})})]})]}),!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:B?.title??s("detail.details")})]}),B?n.jsxs("div",{className:"p-6 space-y-4",children:[!t&&et.has(B.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:B.title}),!t&&n.jsx("button",{onClick:()=>Be(B),disabled:!!se,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 ${ju[B.type]?.color??"bg-surface-overlay text-fg-secondary"}`,children:[ju[B.type]?.icon??""," ",B.type]}),B.artifactType&&Fl[B.artifactType]&&n.jsxs("span",{className:`px-2 py-0.5 rounded text-xs font-medium ${Fl[B.artifactType].color}`,children:[Fl[B.artifactType].icon," ",s("detail.builderWithType",{type:s(`artifactTypes.${B.artifactType}`)})]}),B.tags.length>0&&B.tags.map(Ue=>n.jsx("span",{className:"px-2 py-0.5 text-xs bg-surface-elevated text-fg-secondary rounded",children:Ue},Ue))]}),(B.taskId||B.agentId||Rt(B.projectId))&&n.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[B.taskId&&n.jsx("button",{onClick:()=>Nt.navigate(Se.WORK,{openTask:B.taskId}),className:"text-xs text-brand-500 hover:underline bg-brand-500/10 px-2 py-0.5 rounded",children:s("links.task",{id:`${B.taskId.slice(0,12)}...`})}),B.agentId&&n.jsx("button",{onClick:()=>Nt.navigate(Se.TEAM,{selectAgent:B.agentId}),className:"text-xs text-blue-600 hover:underline bg-blue-500/10 px-2 py-0.5 rounded",children:s("links.agent",{name:nt.get(B.agentId)?.name??B.agentId.slice(0,12)})}),Rt(B.projectId)&&n.jsx("button",{onClick:()=>Nt.navigate(Se.WORK,{projectId:B.projectId}),className:"text-xs text-blue-600 hover:underline bg-blue-500/10 px-2 py-0.5 rounded",children:s("links.project",{name:Rt(B.projectId)})})]}),(B.diffStats||B.testResults)&&n.jsxs("div",{className:"flex gap-3 flex-wrap",children:[B.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:B.diffStats.filesChanged})}),n.jsxs("span",{className:"text-green-600",children:["+",B.diffStats.additions]}),n.jsxs("span",{className:"text-red-500",children:["-",B.diffStats.deletions]})]}),B.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:B.testResults.passed})}),n.jsx("span",{className:"text-red-500",children:s("testResults.failed",{count:B.testResults.failed})}),n.jsx("span",{className:"text-fg-secondary",children:s("testResults.skipped",{count:B.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(B.createdAt).toLocaleDateString()]}),n.jsxs("span",{children:[s("metadata.updated")," ",new Date(B.updatedAt).toLocaleDateString()]}),n.jsx("span",{className:"text-fg-muted select-all",children:B.id.slice(0,12)})]}),B.reference&&!df(B.reference)&&B.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:()=>{le.files.reveal(B.reference).catch(()=>Ge("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:B.reference}),n.jsx("button",{onClick:()=>{le.files.reveal(B.reference).catch(()=>Ge("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:()=>ut(B.reference),className:`px-2 py-1 text-[10px] rounded transition-colors shrink-0 ${Me?"bg-green-500/20 text-green-600":"bg-surface-overlay/50 text-fg-secondary hover:bg-surface-overlay"}`,title:s("detail.copyPath"),children:s(Me?"common:copied":"common:copy")})]}),B.reference&&!df(B.reference)&&B.type!=="file"&&B.type!=="directory"&&n.jsx("span",{className:"text-xs text-fg-tertiary font-mono break-all",children:B.reference})]}),B.artifactType&&B.artifactData?n.jsxs("div",{className:"space-y-4",children:[n.jsx("div",{className:"bg-surface-elevated rounded-xl p-5",children:n.jsx(Kne,{artifact:B.artifactData,mode:B.artifactType})}),B.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:B.reference})]}),n.jsx("div",{className:"flex gap-2",children:n.jsx("button",{onClick:tr,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")})}),B.summary&&n.jsx("div",{className:"bg-surface-elevated rounded-xl p-5",children:n.jsx(Ur,{content:B.summary,className:"text-fg-secondary text-sm"})})]}):B.reference&&df(B.reference)?n.jsxs("div",{className:"space-y-4",children:[B.summary&&n.jsx("div",{className:"bg-surface-elevated rounded-xl p-5",children:n.jsx(Ur,{content:B.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:B.reference}),n.jsx("button",{onClick:()=>window.open(B.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")})]})]}):B.type==="directory"&&B.reference?n.jsxs("div",{className:"space-y-4",children:[B.summary&&n.jsx("div",{className:"bg-surface-elevated rounded-xl p-5",children:n.jsx(Ur,{content:B.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:B.reference}),n.jsx("button",{onClick:()=>{le.files.reveal(B.reference).catch(()=>Ge("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:Ct?n.jsxs("div",{className:"flex items-center gap-2 text-fg-tertiary text-sm",children:[n.jsx(kj,{})," ",s("detail.loadingPreview")]}):at?n.jsxs("div",{className:"flex flex-col items-center gap-2",children:[n.jsx("img",{src:at.src,alt:at.name,className:"max-w-full max-h-[60vh] rounded-lg object-contain"}),n.jsx("span",{className:"text-xs text-fg-tertiary",children:at.name})]}):Pe?n.jsx(G1,{content:Pe,format:Xe,className:"text-fg-secondary text-sm"}):ue?n.jsxs("div",{className:"space-y-3",children:[n.jsx("p",{className:"text-sm text-fg-secondary",children:s("detail.cannotPreview",{type:B.type})}),n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx("button",{onClick:()=>{le.files.reveal(B.reference).catch(()=>Ge("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:B.reference}),n.jsx("button",{onClick:()=>{le.files.reveal(B.reference).catch(()=>Ge("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:()=>ut(B.reference),className:`px-3 py-2 text-xs rounded-lg transition-colors shrink-0 ${Me?"bg-green-500/20 text-green-600":"bg-surface-overlay/50 text-fg-secondary hover:bg-surface-overlay"}`,children:s(Me?"common:copied":"common:copy")})]})]}):B.summary?n.jsx(Ur,{content:B.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")})]})})]}),he&&n.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60",onClick:()=>Be(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:Ue=>Ue.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:he.title})})]})]}),n.jsxs("div",{className:"flex justify-end gap-2",children:[n.jsx("button",{onClick:()=>Be(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 Ue=he;Be(null),kn(Ue)},disabled:!!se,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 Nu({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 kj(){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 ho(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}K`:e.toLocaleString()}function Kc(e){return e<.01?`$${e.toFixed(4)}`:`$${e.toFixed(2)}`}function Xne(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 jj({authUser:e}){const{t}=kt(["reports","common"]),r=ks(),s=bd(Se.REPORTS),[a,i]=b.useState("weekly"),[l,d]=b.useState(null),[u,m]=b.useState(!0),[p,h]=b.useState(""),[y,g]=b.useState(null),[v,S]=b.useState([]),[C,k]=b.useState("totalTokens"),[N,j]=b.useState(!0),[T,R]=b.useState("generate"),[M,_]=b.useState([]),[F,z]=b.useState(null),[L,U]=b.useState([]),[K,q]=b.useState(""),[I,D]=b.useState(""),E=X=>{D(X),setTimeout(()=>D(""),3e3)},$=b.useCallback(async X=>{m(!0),h("");try{const{report:me}=await le.reports.generate({period:X,scope:"org",orgId:"default"});d(me)}catch(me){h(String(me)),d(null)}m(!1)},[]),Y=b.useCallback(()=>{le.usage.summary().then(X=>g(X.usage)).catch(()=>{}),le.usage.agents().then(X=>S(X.agents)).catch(()=>{})},[]),W=b.useCallback(async()=>{try{const{reports:X}=await le.reports.list();_(X)}catch{}},[]),O=b.useCallback(async X=>{z(X);try{const{feedback:me}=await le.reports.getFeedback(X.id);U(me)}catch{U([])}},[]);b.useEffect(()=>{$(a)},[a,$]),b.useEffect(()=>{if(!s)return;Y();const X=setInterval(Y,3e4);return()=>clearInterval(X)},[Y,s]),b.useEffect(()=>{T==="history"&&W()},[T,W]);const H=b.useMemo(()=>[...v].sort((X,me)=>{const je=X[C],Re=me[C];return N?Re-je:je-Re}),[v,C,N]),Z=v.reduce((X,me)=>X+me.estimatedCost,0),B=v.reduce((X,me)=>X+me.tokensUsedToday,0),J=v.reduce((X,me)=>X+(me.costToday??0),0),Q=Math.max(1,...v.map(X=>X.totalTokens)),ee=X=>{C===X?j(!N):(k(X),j(!0))},se=b.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(sc,{}),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:()=>R("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:()=>R("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"),M.length>0?` (${M.length})`:""]})]})]}),n.jsxs("div",{className:"flex items-center gap-3 flex-wrap",children:[I&&n.jsx("span",{className:"px-2.5 py-1 bg-green-500/10 text-green-600 text-xs rounded-lg",children:I}),T==="generate"&&n.jsx("div",{className:"flex gap-1 bg-surface-elevated rounded-lg p-0.5",children:["daily","weekly","monthly"].map(X=>n.jsx("button",{onClick:()=>i(X),className:`px-3 py-1.5 text-xs rounded-md transition-colors ${a===X?"bg-surface-overlay text-fg-primary shadow-sm":"text-fg-tertiary hover:text-fg-secondary"}`,children:t(`period.${X}`)},X))})]})]}),T==="history"&&!F&&n.jsx("section",{className:"bg-surface-elevated rounded-xl overflow-hidden",children:M.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:M.map(X=>n.jsxs("button",{onClick:()=>O(X),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:X.type})}),n.jsxs("div",{className:"text-xs text-fg-tertiary mt-0.5",children:[new Date(X.periodStart).toLocaleDateString()," — ",new Date(X.periodEnd).toLocaleDateString()]})]}),X.plan&&n.jsx("span",{className:`px-2 py-0.5 rounded-full text-[10px] font-medium shrink-0 ${X.plan.status==="approved"?"bg-green-500/10 text-green-600":X.plan.status==="rejected"?"bg-red-500/10 text-red-500":"bg-amber-500/10 text-amber-600"}`,children:X.plan.status==="pending"?t("upcomingPlan.planPending"):t("upcomingPlan.planStatus",{status:X.plan.status})}),n.jsx("span",{className:"text-[10px] text-fg-tertiary shrink-0",children:new Date(X.generatedAt).toLocaleDateString()})]},X.id))})}),T==="history"&&F&&n.jsxs(n.Fragment,{children:[n.jsxs("div",{className:"flex items-center gap-3",children:[n.jsx("button",{onClick:()=>{z(null),U([])},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:F.type})}),n.jsxs("span",{className:"text-xs text-fg-tertiary",children:[new Date(F.periodStart).toLocaleDateString()," — ",new Date(F.periodEnd).toLocaleDateString()]})]}),F.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(Ri,{label:t("taskMetrics.completed"),value:F.metrics.tasksCompleted,color:"text-green-600"}),n.jsx(Ri,{label:t("taskMetrics.inProgress"),value:F.metrics.tasksInProgress,color:"text-brand-500"}),n.jsx(Ri,{label:t("taskMetrics.created"),value:F.metrics.tasksCreated,color:"text-blue-600"}),n.jsx(Ri,{label:t("taskMetrics.blocked"),value:F.metrics.tasksBlocked,color:"text-amber-600"}),n.jsx(Ri,{label:t("taskMetrics.failed"),value:F.metrics.tasksFailed,color:"text-red-500"})]})]}),F.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:F.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:Kc(F.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 ${F.costSummary.trend==="decreasing"?"text-green-600":F.costSummary.trend==="increasing"?"text-red-500":"text-fg-primary"}`,children:[F.costSummary.trend==="decreasing"?"↓":F.costSummary.trend==="increasing"?"↑":"→"," ",F.costSummary.trend]}),n.jsx("div",{className:"text-xs text-fg-tertiary",children:t("costOverview.trend")})]})]}),F.costSummary.byAgent&&F.costSummary.byAgent.length>0&&n.jsx("div",{className:"mt-4 pt-3 border-t border-border-default/50 space-y-1.5",children:F.costSummary.byAgent.map((X,me)=>n.jsxs("div",{className:"flex items-center justify-between text-xs",children:[n.jsx("span",{className:"text-fg-secondary",children:X.agentId}),n.jsx("span",{className:"text-fg-tertiary tabular-nums",children:t("costOverview.byAgentRow",{tokens:ho(X.tokens),cost:Kc(X.cost)})})]},me))})]}),F.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:[F.taskSummary.completed.length>0&&n.jsx(qc,{title:t("taskSummary.completedCount",{count:F.taskSummary.completed.length}),color:"emerald",items:F.taskSummary.completed.map(X=>({id:X.id,label:X.title,sub:X.agent}))}),F.taskSummary.inProgress.length>0&&n.jsx(qc,{title:t("taskSummary.inProgressCount",{count:F.taskSummary.inProgress.length}),color:"indigo",items:F.taskSummary.inProgress.map(X=>({id:X.id,label:X.title,sub:X.agent}))}),F.taskSummary.blocked.length>0&&n.jsx(qc,{title:t("taskSummary.blockedCount",{count:F.taskSummary.blocked.length}),color:"amber",items:F.taskSummary.blocked.map(X=>({id:X.id,label:X.title,sub:X.reason||X.agent}))}),F.taskSummary.completed.length===0&&F.taskSummary.inProgress.length===0&&F.taskSummary.blocked.length===0&&n.jsx("p",{className:"text-sm text-fg-tertiary",children:t("taskSummary.noTasksInPeriod")})]})]}),F.highlights&&F.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:F.highlights.map((X,me)=>n.jsx("li",{children:X},me))})]}),F.blockers&&F.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:F.blockers.map((X,me)=>n.jsx("li",{children:X},me))})]}),F.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 ${F.plan.status==="approved"?"bg-green-500/10 text-green-600":F.plan.status==="rejected"?"bg-red-500/10 text-red-500":"bg-amber-500/10 text-amber-600"}`,children:t(`common:status.${F.plan.status}`,{defaultValue:F.plan.status})})]}),F.plan.status==="pending"&&n.jsxs("div",{className:"flex gap-2",children:[n.jsx("button",{onClick:async()=>{try{const{report:X}=await le.reports.approvePlan(F.id,{approvedBy:e?.id??"unknown"});z(X),E(t("upcomingPlan.planApproved")),W()}catch(X){E(t("common:error",{message:String(X)}))}},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 X=prompt(t("upcomingPlan.rejectionReason"));if(X)try{const{report:me}=await le.reports.rejectPlan(F.id,{rejectedBy:e?.id??"unknown",reason:X});z(me),E(t("upcomingPlan.planRejected")),W()}catch(me){E(t("common:error",{message:String(me)}))}},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")})]})]}),F.plan.items&&F.plan.items.length>0&&n.jsx("div",{className:"space-y-1.5",children:F.plan.items.map((X,me)=>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 ${X.priority==="high"?"bg-red-500/10 text-red-500":X.priority==="medium"?"bg-amber-500/10 text-amber-600":"bg-gray-500/10 text-fg-tertiary"}`,children:X.priority}),n.jsx("span",{children:X.title}),X.assignee&&n.jsx("span",{className:"text-[10px] text-fg-tertiary ml-auto",children:X.assignee})]},me))})]}),!F.metrics&&!F.taskSummary&&!F.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:L.length})}),L.length>0&&n.jsx("div",{className:"space-y-2 mb-4",children:L.map(X=>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:X.authorName}),n.jsx("span",{children:X.type}),n.jsx("span",{children:new Date(X.createdAt).toLocaleDateString()})]}),n.jsx("p",{className:"text-xs text-fg-secondary",children:X.content})]},X.id))}),n.jsxs("div",{className:"flex gap-2",children:[n.jsx("input",{value:K,onChange:X=>q(X.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:X=>{X.key==="Enter"&&K.trim()&&le.reports.addFeedback(F.id,{author:e?.id??"unknown",type:"comment",content:K.trim()}).then(({feedback:me})=>{U(je=>[...je,me]),q(""),E(t("feedback.added"))}).catch(me=>E(t("common:error",{message:String(me)})))}}),n.jsx("button",{onClick:()=>{K.trim()&&le.reports.addFeedback(F.id,{author:e?.id??"unknown",type:"comment",content:K.trim()}).then(({feedback:X})=>{U(me=>[...me,X]),q(""),E(t("feedback.added"))}).catch(X=>E(t("common:error",{message:String(X)})))},disabled:!K.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(uf,{label:t("usage.llmTokens"),value:ho(y.llmTokens),color:"text-brand-500"}),n.jsx(uf,{label:t("usage.toolCalls"),value:ho(y.toolCalls),color:"text-blue-600"}),n.jsx(uf,{label:t("usage.messages"),value:ho(y.messages),color:"text-green-600"}),y.storageBytes>0&&n.jsx(uf,{label:t("usage.storage"),value:Xne(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")}):p?n.jsx("div",{className:"flex items-center justify-center h-32 text-red-500 text-sm",children:p}):l?n.jsxs(n.Fragment,{children:[n.jsxs("div",{className:"text-xs text-fg-tertiary",children:[se[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(Ri,{label:t("taskMetrics.completed"),value:l.metrics.tasksCompleted,color:"text-green-600"}),n.jsx(Ri,{label:t("taskMetrics.inProgress"),value:l.metrics.tasksInProgress,color:"text-brand-500"}),n.jsx(Ri,{label:t("taskMetrics.created"),value:l.metrics.tasksCreated,color:"text-blue-600"}),n.jsx(Ri,{label:t("taskMetrics.blocked"),value:l.metrics.tasksBlocked,color:"text-amber-600"}),n.jsx(Ri,{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:Kc(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:ho(B)}),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:Kc(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(qc,{title:t("taskSummary.completedCount",{count:l.taskSummary.completed.length}),color:"emerald",items:l.taskSummary.completed.map(X=>({id:X.id,label:X.title,sub:X.agent}))}),l.taskSummary.inProgress.length>0&&n.jsx(qc,{title:t("taskSummary.inProgressCount",{count:l.taskSummary.inProgress.length}),color:"indigo",items:l.taskSummary.inProgress.map(X=>({id:X.id,label:X.title,sub:X.agent}))}),l.taskSummary.blocked.length>0&&n.jsx(qc,{title:t("taskSummary.blockedCount",{count:l.taskSummary.blocked.length}),color:"amber",items:l.taskSummary.blocked.map(X=>({id:X.id,label:X.title,sub:X.reason||X.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(Su,{label:t("perAgentUsage.totalTokens"),col:"totalTokens",current:C,desc:N,onSort:ee}),n.jsx(Su,{label:t("perAgentUsage.today"),col:"tokensUsedToday",current:C,desc:N,onSort:ee}),n.jsx(Su,{label:t("perAgentUsage.requests"),col:"requestCount",current:C,desc:N,onSort:ee}),n.jsx(Su,{label:t("perAgentUsage.toolCalls"),col:"toolCalls",current:C,desc:N,onSort:ee}),n.jsx(Su,{label:t("perAgentUsage.estCost"),col:"estimatedCost",current:C,desc:N,onSort:ee,align:"right"})]})}),n.jsx("tbody",{children:H.map(X=>n.jsx(Qne,{agent:X,maxTokens:Q},X.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:ho(v.reduce((X,me)=>X+me.totalTokens,0))}),n.jsx("td",{className:"px-4 py-3 text-sm font-medium text-fg-secondary tabular-nums",children:ho(B)}),n.jsx("td",{className:"px-4 py-3 text-sm font-medium text-fg-secondary tabular-nums",children:v.reduce((X,me)=>X+me.requestCount,0)}),n.jsx("td",{className:"px-4 py-3 text-sm font-medium text-fg-secondary tabular-nums",children:v.reduce((X,me)=>X+me.toolCalls,0)}),n.jsx("td",{className:"px-4 py-3 text-sm font-medium text-right text-fg-secondary tabular-nums",children:Kc(Z)})]})})]})})]})]})})}function Ri({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 qc({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?()=>Nt.navigate(Se.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 uf({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 Su({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 Qne({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:()=>Nt.navigate(Se.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:ho(e.totalTokens)})]})}),n.jsx("td",{className:"px-4 py-3 text-sm text-fg-secondary tabular-nums",children:ho(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:Kc(e.estimatedCost)})]})}const mf={urgent:"bg-red-500",high:"bg-amber-500",normal:"bg-blue-500",low:"bg-gray-400"},Uc={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"},Nj={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 Vc(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 ff(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 Zne(){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 D7({collapsed:e,userId:t,embeddedMode:r,onClose:s,sidebarMode:a,isActive:i,label:l,iconPath:d}){const{t:u}=kt(["team","common"]),[m,p]=b.useState(!1),[h,y]=b.useState("approvals"),[g,v]=b.useState([]),[S,C]=b.useState([]),[k,N]=b.useState(null),[j,T]=b.useState(null),[R,M]=b.useState({}),[_,F]=b.useState(0),z=b.useRef(null),L=b.useRef(null),[U,K]=b.useState({top:0,left:0,width:448,maxHeight:576}),q=b.useRef(null),I=b.useRef(!1),[D,E]=b.useState(!0),[$,Y]=b.useState(!1),W=b.useRef(null),O=b.useRef("approvals"),H=30,Z=b.useCallback(async()=>{try{const[ne,he]=await Promise.all([le.notifications.list(t,!1,{limit:H,offset:0}),le.approvals.list()]);if(v(ne.notifications),F(ne.unreadCount??ne.notifications.filter(Be=>!Be.read).length),E(ne.totalCount!=null?ne.notifications.length<ne.totalCount:ne.notifications.length>=H),C(he.approvals),!I.current){const Be=he.approvals.filter(de=>de.status==="pending").length;q.current=Be,I.current=!0}}catch{}},[t]),B=b.useCallback(async()=>{if(!($||!D)){Y(!0);try{const ne=await le.notifications.list(t,!1,{limit:H,offset:g.length});ne.notifications.length>0&&v(he=>[...he,...ne.notifications.filter(Be=>!he.some(de=>de.id===Be.id))]),E(ne.totalCount!=null?g.length+ne.notifications.length<ne.totalCount:ne.notifications.length>=H)}catch{}Y(!1)}},[t,g.length,$,D]),J=b.useCallback(ne=>{const he=ne.detail;if(!he)return;const{taskId:Be,requirementId:de}=he;!Be&&!de||v(Ce=>{const et=Ce.filter(it=>!it.read&&(Be&&it.metadata?.taskId===Be||de&&it.metadata?.requirementId===de));if(et.length===0)return Ce;for(const it of et)le.notifications.markRead(it.id).catch(()=>{});return F(it=>Math.max(0,it-et.length)),Ce.map(it=>et.some(Ve=>Ve.id===it.id)?{...it,read:!0}:it)})},[]);b.useEffect(()=>{Z();const ne=setInterval(Z,6e4),he=()=>Z(),Be=()=>{p(!0),Z()};window.addEventListener("markus:notifications-changed",he),window.addEventListener("markus:mark-read-by-ref",J),window.addEventListener("markus:open-notifications",Be);const de=gn.on("notification:created",()=>Z()),Ce=gn.on("approval:created",()=>Z());return()=>{clearInterval(ne),window.removeEventListener("markus:notifications-changed",he),window.removeEventListener("markus:mark-read-by-ref",J),window.removeEventListener("markus:open-notifications",Be),de(),Ce()}},[Z,J]);const Q=b.useCallback(()=>{if(!z.current)return;const ne=z.current.getBoundingClientRect(),he=window.innerWidth,Be=window.innerHeight,de=Math.min(448,he-16),Ce=Math.min(576,Be-16);let et=ne.right+8,it=ne.top;et+de>he-8&&(et=Math.max(8,he-de-8)),it+Ce>Be-8&&(it=Math.max(8,Be-Ce-8)),K({top:it,left:et,width:de,maxHeight:Ce})},[]);b.useLayoutEffect(()=>{m&&Q()},[m,Q]),b.useEffect(()=>{if(m)return window.addEventListener("resize",Q),()=>window.removeEventListener("resize",Q)},[m,Q]),b.useEffect(()=>{if(!m)return;const ne=he=>{z.current?.contains(he.target)||L.current?.contains(he.target)||p(!1)};return document.addEventListener("mousedown",ne),()=>document.removeEventListener("mousedown",ne)},[m]),b.useEffect(()=>{if(!m)return;const ne=S.some(Be=>Be.status==="pending"),he=g.some(Be=>!Be.read);y(ne&&!he?"approvals":!ne&&he?"notifications":O.current)},[m]);const ee=new Set(S.filter(ne=>ne.status==="pending").map(ne=>ne.id)),se=new Set(S.map(ne=>ne.id)),X=g.filter(ne=>!(ne.type==="approval_request"&&ne.metadata?.approvalId&&se.has(ne.metadata.approvalId))),me=g.filter(ne=>ne.type==="approval_request"&&!ne.read&&ne.metadata?.approvalId&&ee.has(ne.metadata.approvalId)).length,je=Math.max(0,_-me),Re=ee.size,Ee=je+Re;b.useEffect(()=>{q.current!==null&&Re>q.current&&Zne(),q.current=Re},[Re]);const we=async ne=>{await le.notifications.markRead(ne),v(he=>he.map(Be=>Be.id===ne?{...Be,read:!0}:Be)),F(he=>Math.max(0,he-1))},pe=ne=>{const he=ne.metadata??{},Be=ne.actionType,de=ne.actionTarget;if(Be==="open_chat"&&de)try{const Ce=typeof de=="string"?JSON.parse(de):de;if(Ce.agentId){const et={agentId:Ce.agentId};Ce.sessionId&&(et.sessionId=Ce.sessionId),Nt.navigate(Se.TEAM,et);return}}catch{}if(Be==="navigate"&&de)try{const Ce=typeof de=="string"?JSON.parse(de):de;if(Ce.path){if(Ce.path.startsWith("/team")){const et={},it=new URLSearchParams(Ce.path.split("?")[1]||"");for(const[Ve,Ge]of it.entries())et[Ve]=Ge;Nt.navigate(Se.TEAM,et);return}if(Ce.path.startsWith("/work")){const et={},it=new URLSearchParams(Ce.path.split("?")[1]||"");for(const[Ve,Ge]of it.entries())et[Ve]=Ge;Nt.navigate(Se.WORK,et);return}}}catch{}switch(ne.type){case"approval_request":{const Ce=he.approvalId,et=Ce?S.find(ut=>ut.id===Ce):void 0,it=et?.details?.taskId??he.taskId,Ve=et?.details?.requirementId??he.requirementId,Ge=et?.details?.agentId??et?.agentId;it?Nt.navigate(Se.WORK,{openTask:it}):Ve?Nt.navigate(Se.WORK,{openRequirement:Ve}):Ge?Nt.navigate(Se.TEAM,{agentId:Ge}):Nt.navigate(Se.WORK);break}case"task_completed":case"task_created":case"task_review":case"task_failed":he.taskId?Nt.navigate(Se.WORK,{openTask:he.taskId}):Nt.navigate(Se.WORK);break;case"requirement_created":case"requirement_decision":he.requirementId?Nt.navigate(Se.WORK,{openRequirement:he.requirementId}):Nt.navigate(Se.WORK);break;case"agent_report":case"system":{if(he.agentId){const Ce={agentId:he.agentId};he.sessionId&&(Ce.sessionId=he.sessionId),Nt.navigate(Se.TEAM,Ce)}else Nt.navigate(Se.TEAM);break}case"direct_message":{const Ce=he.senderId;Ce?Nt.navigate(Se.TEAM,{dm:Ce}):Nt.navigate(Se.TEAM);break}case"group_message":{const Ce=he.channel;Ce?Nt.navigate(Se.TEAM,{channel:Ce}):Nt.navigate(Se.TEAM);break}default:he.taskId?Nt.navigate(Se.WORK,{openTask:he.taskId}):he.requirementId?Nt.navigate(Se.WORK,{openRequirement:he.requirementId}):he.projectId?Nt.navigate(Se.WORK,{projectId:he.projectId}):he.agentId&&Nt.navigate(Se.TEAM,{agentId:he.agentId});break}},Pe=async ne=>{ne.read||we(ne.id);const he=ne.metadata??{},Be=he.taskId,de=he.requirementId;if(Be||de){const Ce=g.filter(et=>et.id!==ne.id&&!et.read&&(Be&&et.metadata?.taskId===Be||de&&et.metadata?.requirementId===de));for(const et of Ce)we(et.id)}pe(ne)},Ae=async(ne,he,Be,de)=>{N(ne);try{const{approval:Ce}=await le.approvals.respond(ne,he,t,Be,de);C(Ge=>Ge.map(ut=>ut.id===ne?Ce:ut)),T(null),M(Ge=>{const ut={...Ge};return delete ut[ne],ut});const et=Ce.details?.taskId,it=Ce.details?.requirementId,Ve=g.filter(Ge=>!Ge.read&&(Ge.type==="approval_request"&&Ge.metadata?.approvalId===ne||et&&Ge.metadata?.taskId===et||it&&Ge.metadata?.requirementId===it));if(Ve.length>0){for(const ut of Ve)le.notifications.markRead(ut.id).catch(()=>{});const Ge=new Set(Ve.map(ut=>ut.id));v(ut=>ut.map(nt=>Ge.has(nt.id)?{...nt,read:!0}:nt)),F(ut=>Math.max(0,ut-Ve.length))}rl("/approvals"),rl("/notifications"),rl("/tasks"),rl("/taskboard"),rl("/requirements"),window.dispatchEvent(new CustomEvent("markus:data-changed")),window.dispatchEvent(new CustomEvent("markus:notifications-changed")),setTimeout(()=>Z(),800)}catch{}N(null)},Xe=async()=>{try{if(!t)return;await le.notifications.markAllRead(t),v(ne=>ne.map(he=>({...he,read:!0}))),F(0),rl("/notifications")}catch{const ne=X.filter(he=>!he.read);await Promise.all(ne.map(he=>le.notifications.markRead(he.id))),v(he=>he.map(Be=>({...Be,read:!0}))),F(0),rl("/notifications")}},Ze=ne=>{const he=ne.details?.subType;return he==="requirement_resubmit"?u("team:notifications.approvalType.requirementResubmit"):he==="requirement"||ne.details?.requirementId?u("team:notifications.approvalType.requirement"):he==="task_review"?u("team:notifications.approvalType.taskReview"):he==="task"||ne.details?.taskId?u("team:notifications.approvalType.task"):ne.details?.toolName?u("team:notifications.approvalType.toolExecution"):null},at=ne=>{const he=[];he.push(ne.agentName);const Be=ne.details?.taskTitle,de=ne.details?.taskId;Be?he.push(Be):de&&he.push(`Task ${de.slice(0,8)}`);const Ce=ne.details?.requirementId;return Ce&&!de&&he.push(`Req ${Ce.slice(0,8)}`),he.join(" · ")},pt=[...S].sort((ne,he)=>new Date(he.requestedAt).getTime()-new Date(ne.requestedAt).getTime()),Ct=pt.filter(ne=>ne.status==="pending"),_e=pt.filter(ne=>ne.status!=="pending"),ue=ne=>{const he=ne.details?.taskId,Be=ne.details?.requirementId,de=ne.details?.agentId??ne.agentId;he?Nt.navigate(Se.WORK,{openTask:he}):Be?Nt.navigate(Se.WORK,{openRequirement:Be}):de?Nt.navigate(Se.TEAM,{agentId:de}):Nt.navigate(Se.WORK)},fe=()=>{p(!1),s?.()},Me=n.jsxs(n.Fragment,{children:[n.jsxs("div",{className:"flex border-b border-border-default shrink-0",children:[n.jsxs("button",{onClick:()=>{y("approvals"),O.current="approvals"},className:`flex-1 px-3 py-2.5 text-xs font-medium transition-colors ${h==="approvals"?"text-fg-primary border-b-2 border-brand-500":"text-fg-tertiary hover:text-fg-secondary"}`,children:[u("team:notifications.approvals"),Re>0?` (${Re})`:""]}),n.jsxs("button",{onClick:()=>{y("notifications"),O.current="notifications"},className:`flex-1 px-3 py-2.5 text-xs font-medium transition-colors ${h==="notifications"?"text-fg-primary border-b-2 border-brand-500":"text-fg-tertiary hover:text-fg-secondary"}`,children:[u("team:notifications.notifications"),je>0?` (${je})`:""]}),n.jsx("button",{onClick:fe,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"})]})})]}),h==="notifications"&&_>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:Xe,className:"text-[10px] text-brand-500 hover:text-brand-400 transition-colors",children:u("team:notifications.markAllRead")})}),n.jsxs("div",{ref:W,className:"flex-1 overflow-y-auto",onScroll:ne=>{if(h!=="notifications"||!D||$)return;const he=ne.currentTarget;he.scrollTop+he.clientHeight>=he.scrollHeight-80&&B()},children:[h==="approvals"&&(S.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:[Ct.map(ne=>{const he=ne.details?.command,Be=he?ne.description.replace(/\s*Command:.*$/,""):ne.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:()=>ue(ne),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:Uc.approval_request})}),n.jsxs("div",{className:"flex-1 min-w-0",children:[n.jsxs("div",{className:"flex items-center gap-2",children:[Ze(ne)&&n.jsx("span",{className:"text-[10px] text-amber-500 font-medium shrink-0",children:Ze(ne)}),n.jsx("span",{className:"text-xs text-fg-primary font-medium truncate",children:ne.title}),n.jsx("span",{className:"text-[10px] text-fg-tertiary shrink-0",children:Vc(ne.requestedAt,u)})]}),n.jsx("div",{className:"text-[11px] text-fg-tertiary mt-0.5",children:ne.agentName})]})]}),n.jsx("div",{className:"mt-2.5 text-[11px] text-fg-secondary leading-relaxed",children:n.jsx(Ur,{content:Be,className:"text-[11px] [&_h1]:text-xs [&_h2]:text-[11px] [&_h3]:text-[11px] [&_p]:text-[11px] [&_li]:text-[11px]"})}),he&&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:he})]}),(()=>{const de=ne.details?.subType,Ce=de==="task"||de==="requirement"||de==="requirement_resubmit",et=ne.options&&ne.options.length>0,it=(R[ne.id]??"").trim();return et?n.jsxs("div",{className:"space-y-1.5",children:[ne.options.map((Ve,Ge)=>n.jsxs("button",{disabled:k===ne.id,onClick:()=>Ae(ne.id,Ve.id!=="reject",it||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+Ge)}),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:R[ne.id]??"",onChange:Ve=>M(Ge=>({...Ge,[ne.id]:Ve.target.value})),onKeyDown:Ve=>{Ve.key==="Enter"&&(R[ne.id]??"").trim()&&Ae(ne.id,!0,(R[ne.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:k===ne.id||!(R[ne.id]??"").trim(),onClick:()=>Ae(ne.id,!0,(R[ne.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")})]})]}):Ce?n.jsxs("div",{className:"space-y-1.5",children:[n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsxs("button",{disabled:k===ne.id,onClick:()=>Ae(ne.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:k===ne.id,onClick:()=>Ae(ne.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")]}),j!==ne.id&&n.jsxs("button",{disabled:k===ne.id,onClick:()=>T(ne.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")]})]}),j===ne.id&&n.jsxs("div",{className:"space-y-1.5",children:[n.jsx("input",{type:"text",autoFocus:!0,placeholder:u("team:notifications.adjustmentPlaceholder"),value:R[ne.id]??"",onChange:Ve=>M(Ge=>({...Ge,[ne.id]:Ve.target.value})),onKeyDown:Ve=>{Ve.key==="Enter"&&(R[ne.id]??"").trim()&&Ae(ne.id,!1,(R[ne.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:k===ne.id||!(R[ne.id]??"").trim(),onClick:()=>Ae(ne.id,!1,(R[ne.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:R[ne.id]??"",onChange:Ve=>M(Ge=>({...Ge,[ne.id]:Ve.target.value})),onKeyDown:Ve=>{Ve.key==="Enter"&&Ae(ne.id,!0,it||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:k===ne.id,onClick:()=>Ae(ne.id,!0,it||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:k===ne.id,onClick:()=>Ae(ne.id,!1,it||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")})]})]})})()]},ne.id)}),_e.length>0&&n.jsxs(n.Fragment,{children:[Ct.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")}),_e.slice(0,50).map(ne=>n.jsxs("button",{onClick:()=>ue(ne),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 ${ne.status==="approved"?"bg-green-500":ne.status==="cancelled"||ne.status==="expired"?"bg-gray-400":"bg-red-500"}`}),Ze(ne)&&n.jsx("span",{className:"text-[10px] text-fg-tertiary font-medium shrink-0",children:Ze(ne)}),n.jsx("span",{className:"text-xs text-fg-secondary truncate flex-1 group-hover:text-fg-primary",children:ne.title}),n.jsx("span",{className:`text-[10px] font-medium shrink-0 ${ne.status==="approved"?"text-green-500":ne.status==="cancelled"||ne.status==="expired"?"text-fg-muted":"text-red-500"}`,children:u(`common:status.${ne.status}`,{defaultValue:ne.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:at(ne)}),n.jsx("span",{className:"text-[10px] text-fg-muted shrink-0",children:"·"}),n.jsx("span",{className:"text-[10px] text-fg-muted shrink-0",children:Vc(ne.respondedAt??ne.requestedAt,u)})]}),ne.responseComment&&n.jsxs("p",{className:"text-[10px] text-fg-muted mt-0.5 pl-3.5 truncate",children:["“",ne.responseComment,"”"]})]},ne.id))]})]})),h==="notifications"&&(X.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:[X.map(ne=>{const he=Nj[ne.type]??"text-fg-tertiary";return n.jsxs("div",{role:"button",tabIndex:0,onClick:()=>Pe(ne),onKeyDown:Be=>{(Be.key==="Enter"||Be.key===" ")&&(Be.preventDefault(),Pe(ne))},className:`w-full text-left px-3 py-2.5 flex gap-2.5 transition-colors cursor-pointer ${ne.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:he,children:n.jsx("path",{d:Uc[ne.type]??Uc.system})})}),n.jsxs("div",{className:"flex-1 min-w-0",children:[n.jsxs("div",{className:"flex items-center gap-1.5",children:[!ne.read&&n.jsx("span",{className:`w-1.5 h-1.5 rounded-full shrink-0 ${mf[ne.priority]??mf.normal}`}),n.jsx("span",{className:"text-xs text-fg-primary font-medium truncate",children:ne.title})]}),n.jsx("div",{className:"text-[11px] text-fg-tertiary mt-0.5 ",children:n.jsx(Ur,{content:ne.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:Vc(ne.createdAt,u)}),ff(ne,u)&&n.jsx("span",{className:`text-[10px] font-medium ${he}`,children:ff(ne,u)})]})]})]},ne.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 ne=["approvals","notifications"],he=ne.indexOf(h),Be=(()=>{let de=0,Ce=0;return{onTouchStart:et=>{de=et.touches[0].clientX,Ce=et.touches[0].clientY},onTouchEnd:et=>{const it=et.changedTouches[0].clientX-de,Ve=et.changedTouches[0].clientY-Ce;Math.abs(it)>60&&Math.abs(it)>Math.abs(Ve)*1.5&&(it<0&&he<ne.length-1&&y(ne[he+1]),it>0&&he>0&&y(ne[he-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:ne.map(de=>n.jsx("button",{onClick:()=>y(de),className:`flex-1 px-3 py-3 text-sm font-medium transition-colors ${h===de?"text-fg-primary border-b-2 border-brand-500":"text-fg-tertiary"}`,children:de==="approvals"?n.jsxs(n.Fragment,{children:[u("team:notifications.approvals"),Re>0?` (${Re})`:""]}):n.jsxs(n.Fragment,{children:[u("team:notifications.notifications"),je>0?` (${je})`:""]})},de))}),h==="notifications"&&_>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:Xe,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",...Be,children:n.jsxs("div",{className:"flex h-full transition-transform duration-300 ease-out",style:{transform:`translateX(-${he*100}%)`},children:[n.jsx("div",{className:"w-full shrink-0 h-full overflow-y-auto scrollbar-thin",children:S.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:[Ct.map(de=>{const Ce=de.details?.command,et=Ce?de.description.replace(/\s*Command:.*$/,""):de.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:()=>ue(de),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:Uc.approval_request})}),n.jsxs("div",{className:"flex-1 min-w-0",children:[n.jsxs("div",{className:"flex items-center gap-2",children:[Ze(de)&&n.jsx("span",{className:"text-[10px] text-amber-500 font-medium shrink-0",children:Ze(de)}),n.jsx("span",{className:"text-xs text-fg-primary font-medium truncate",children:de.title}),n.jsx("span",{className:"text-[10px] text-fg-tertiary shrink-0",children:Vc(de.requestedAt,u)})]}),n.jsx("div",{className:"text-[11px] text-fg-tertiary mt-0.5",children:de.agentName})]})]}),n.jsx("div",{className:"mt-2.5 text-[11px] text-fg-secondary leading-relaxed",children:n.jsx(Ur,{content:et,className:"text-[11px] [&_h1]:text-xs [&_h2]:text-[11px] [&_h3]:text-[11px] [&_p]:text-[11px] [&_li]:text-[11px]"})}),Ce&&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:Ce})]}),(()=>{const it=de.details?.subType,Ve=it==="task"||it==="requirement"||it==="requirement_resubmit",Ge=de.options&&de.options.length>0,ut=(R[de.id]??"").trim();return Ge?n.jsxs("div",{className:"space-y-1.5",children:[de.options.map((nt,ft)=>n.jsxs("button",{disabled:k===de.id,onClick:()=>Ae(de.id,nt.id!=="reject",ut||void 0,nt.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 ${nt.id==="reject"||nt.id==="request_changes"?"border border-border-default text-fg-secondary hover:bg-surface-overlay":"bg-brand-600 text-white hover:bg-brand-700"}`,title:nt.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+ft)}),nt.label]},nt.id)),n.jsxs("div",{className:"flex gap-1.5 mt-1",children:[n.jsx("input",{type:"text",placeholder:u("team:notifications.freeformPlaceholder"),value:R[de.id]??"",onChange:nt=>M(ft=>({...ft,[de.id]:nt.target.value})),onKeyDown:nt=>{nt.key==="Enter"&&(R[de.id]??"").trim()&&Ae(de.id,!0,(R[de.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:k===de.id||!(R[de.id]??"").trim(),onClick:()=>Ae(de.id,!0,(R[de.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:k===de.id,onClick:()=>Ae(de.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:k===de.id,onClick:()=>Ae(de.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")]}),j!==de.id&&n.jsxs("button",{disabled:k===de.id,onClick:()=>T(de.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")]})]}),j===de.id&&n.jsxs("div",{className:"space-y-1.5",children:[n.jsx("input",{type:"text",autoFocus:!0,placeholder:u("team:notifications.adjustmentPlaceholder"),value:R[de.id]??"",onChange:nt=>M(ft=>({...ft,[de.id]:nt.target.value})),onKeyDown:nt=>{nt.key==="Enter"&&(R[de.id]??"").trim()&&Ae(de.id,!1,(R[de.id]??"").trim(),"needs_adjustment"),nt.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:k===de.id||!(R[de.id]??"").trim(),onClick:()=>Ae(de.id,!1,(R[de.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:R[de.id]??"",onChange:nt=>M(ft=>({...ft,[de.id]:nt.target.value})),onKeyDown:nt=>{nt.key==="Enter"&&Ae(de.id,!0,ut||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:k===de.id,onClick:()=>Ae(de.id,!0,ut||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:k===de.id,onClick:()=>Ae(de.id,!1,ut||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")})]})]})})()]},de.id)}),_e.length>0&&n.jsxs(n.Fragment,{children:[Ct.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")}),_e.slice(0,50).map(de=>n.jsxs("button",{onClick:()=>ue(de),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 ${de.status==="approved"?"bg-green-500":de.status==="cancelled"||de.status==="expired"?"bg-gray-400":"bg-red-500"}`}),n.jsx("span",{className:"text-xs text-fg-secondary truncate flex-1",children:de.title}),n.jsx("span",{className:`text-[10px] font-medium shrink-0 ${de.status==="approved"?"text-green-500":de.status==="cancelled"||de.status==="expired"?"text-fg-muted":"text-red-500"}`,children:u(`common:status.${de.status}`,{defaultValue:de.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:at(de)}),n.jsx("span",{className:"text-[10px] text-fg-muted shrink-0",children:"·"}),n.jsx("span",{className:"text-[10px] text-fg-muted shrink-0",children:Vc(de.respondedAt??de.requestedAt,u)})]})]},de.id))]})]})}),n.jsx("div",{className:"w-full shrink-0 h-full overflow-y-auto scrollbar-thin",children:X.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:X.slice(0,50).map(de=>{const Ce=Nj[de.type]??"text-fg-tertiary";return n.jsxs("button",{onClick:()=>Pe(de),className:`w-full text-left px-3 py-2.5 flex gap-2.5 transition-colors ${de.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:Ce,children:n.jsx("path",{d:Uc[de.type]??Uc.system})})}),n.jsxs("div",{className:"flex-1 min-w-0",children:[n.jsxs("div",{className:"flex items-center gap-1.5",children:[!de.read&&n.jsx("span",{className:`w-1.5 h-1.5 rounded-full shrink-0 ${mf[de.priority]??mf.normal}`}),n.jsx("span",{className:"text-xs text-fg-primary font-medium truncate",children:de.title})]}),n.jsx("div",{className:"text-[11px] text-fg-tertiary mt-0.5 ",children:n.jsx(Ur,{content:de.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:Vc(de.createdAt,u)}),ff(de,u)&&n.jsx("span",{className:`text-[10px] font-medium ${Ce}`,children:ff(de,u)})]})]})]},de.id)})})})]})})]})}if(a){const ne=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:z,onClick:()=>{p(!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:ne})}),e?n.jsx("span",{className:"text-[9px] leading-tight truncate w-full text-center",children:l}):n.jsx("span",{className:"truncate",children:l}),Ee>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:Ee>99?u("common:badgeOverLimit"):Ee})]}),m&&sd.createPortal(n.jsx("div",{ref:L,className:"fixed bg-surface-secondary border border-border-default rounded-xl shadow-2xl z-[9999] flex flex-col overflow-hidden",style:{top:U.top,left:U.left,width:U.width,maxHeight:U.maxHeight},children:Me}),document.body)]})}return n.jsxs(n.Fragment,{children:[n.jsxs("button",{ref:z,onClick:()=>{p(!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"})]}),Ee>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:Ee>99?u("common:badgeOverLimit"):Ee})]}),m&&sd.createPortal(n.jsx("div",{ref:L,className:"fixed bg-surface-secondary border border-border-default rounded-xl shadow-2xl z-[9999] flex flex-col overflow-hidden",style:{top:U.top,left:U.left,width:U.width,maxHeight:U.maxHeight},children:Me}),document.body)]})}function Jne({authUser:e}){const{t}=kt("nav"),r=ks();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(sc,{}),n.jsx("h2",{className:"text-base font-bold",children:t("notifications")})]}),n.jsx("div",{className:"flex-1 overflow-hidden",children:n.jsx(D7,{collapsed:!1,userId:e?.id,embeddedMode:!0})})]})}function ere(){const{t:e}=kt(["common","home","work"]),[t,r]=b.useState(""),[s,a]=b.useState("all"),[i,l]=b.useState({agents:[],tasks:[],requirements:[],projects:[],deliverables:[]}),[d,u]=b.useState(!1),[m,p]=b.useState(!1),h=b.useRef(null),y=b.useRef(void 0);b.useEffect(()=>{setTimeout(()=>h.current?.focus(),100)},[]);const g=b.useCallback(async k=>{if(!k.trim()){l({agents:[],tasks:[],requirements:[],projects:[],deliverables:[]}),p(!1);return}u(!0),p(!0);const N=k.toLowerCase();try{const[j,T,R,M,_]=await Promise.allSettled([le.agents.list(),le.tasks.list({search:k,pageSize:20}),le.requirements.list(),le.projects.list(),le.deliverables.search({q:k,limit:20})]),F=j.status==="fulfilled"?j.value.agents.filter(q=>q.name?.toLowerCase().includes(N)||q.role?.toLowerCase().includes(N)):[],z=T.status==="fulfilled"?T.value.tasks:[],L=R.status==="fulfilled"?R.value.requirements.filter(q=>q.title?.toLowerCase().includes(N)||q.description?.toLowerCase().includes(N)):[],U=M.status==="fulfilled"?M.value.projects.filter(q=>q.name?.toLowerCase().includes(N)||q.description?.toLowerCase().includes(N)):[],K=_.status==="fulfilled"?_.value.results:[];l({agents:F,tasks:z,requirements:L,projects:U,deliverables:K})}catch{l({agents:[],tasks:[],requirements:[],projects:[],deliverables:[]})}finally{u(!1)}},[]),v=k=>{r(k),y.current&&clearTimeout(y.current),y.current=setTimeout(()=>g(k),400)},S=[{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:()=>Nt.navigate(Se.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:h,value:t,onChange:k=>v(k.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:[]}),p(!1),h.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:S.map(k=>n.jsx("button",{onClick:()=>a(k.id),className:`px-3 py-1.5 text-xs rounded-lg whitespace-nowrap transition-colors ${s===k.id?"bg-brand-600 text-white":"bg-surface-elevated text-fg-secondary hover:text-fg-primary"}`,children:k.label},k.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(k=>n.jsxs("button",{onClick:()=>Nt.navigate(Se.TEAM,{agentId:k.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(gr,{name:k.name||"Agent",avatarUrl:k.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:k.name}),n.jsx("div",{className:"text-xs text-fg-tertiary truncate",children:k.role||k.status})]}),n.jsx(tre,{status:k.status})]},k.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(k=>n.jsxs("button",{onClick:()=>Nt.navigate(Se.WORK,{openTask:k.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(nre,{status:k.status}),n.jsxs("div",{className:"flex-1 min-w-0",children:[n.jsx("div",{className:"text-sm text-fg-primary truncate",children:k.title}),n.jsxs("div",{className:"text-xs text-fg-tertiary truncate",children:[k.status," · ",k.priority||""]})]})]},k.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(k=>n.jsxs("button",{onClick:()=>Nt.navigate(Se.WORK,{openRequirement:k.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 ${k.status==="approved"?"text-green-500 bg-green-500/15":k.status==="pending"?"text-amber-500 bg-amber-500/15":k.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:k.title}),n.jsxs("div",{className:"text-xs text-fg-tertiary truncate",children:[k.status," · ",k.priority||""]})]})]},k.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(k=>n.jsxs("button",{onClick:()=>Nt.navigate(Se.WORK,{projectId:k.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:k.name}),k.description&&n.jsx("div",{className:"text-xs text-fg-tertiary truncate",children:k.description})]})]},k.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(k=>n.jsxs("button",{onClick:()=>Nt.navigate(Se.DELIVERABLES,{openDeliverable:k.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:k.title}),n.jsxs("div",{className:"text-xs text-fg-tertiary truncate",children:[k.type," · ",k.status]})]})]},k.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 tre({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 nre({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 rre({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 sre({currentPage:e,onNavigate:t,authUser:r,collapsed:s,onToggleCollapse:a}){const{t:i}=kt(["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:e_.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"}),t_.filter(m=>m.section===l.key).map(m=>{if(m.id===Se.NOTIFICATIONS)return n.jsx(D7,{sidebarMode:!0,collapsed:s,userId:r?.id,label:i(m.id),iconPath:Qx[m.id],isActive:e===m.id},m.id);const p=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 ${p?"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(rre,{d:Qx[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.7.5"]})]})}function are({currentPage:e,onNavigate:t,userId:r}){const{t:s}=kt("nav"),[a,i]=b.useState(0),[l,d]=b.useState(0),u=b.useCallback(async()=>{try{const m=await le.notifications.list(r,!1);i(m.unreadCount??m.notifications.filter(p=>!p.read).length)}catch{}},[r]);return b.useEffect(()=>{u();const m=setInterval(u,15e3),p=()=>u();window.addEventListener("markus:notifications-changed",p);const h=y=>{const g=y.detail?.count??0;d(g)};return window.addEventListener("markus:team-unread-changed",h),()=>{clearInterval(m),window.removeEventListener("markus:notifications-changed",p),window.removeEventListener("markus:team-unread-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:n_.map(m=>{const p=m.group.includes(e),h=m.id===Se.NOTIFICATIONS,y=m.id===Se.TEAM;return n.jsxs("button",{onClick:()=>t(m.id),className:`flex-1 flex flex-col items-center justify-center gap-0.5 transition-colors ${p?"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:p?2:1.75,strokeLinecap:"round",strokeLinejoin:"round",className:"shrink-0",children:n.jsx("path",{d:Qx[m.id]})}),h&&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&&l>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:l>99?"99+":l})]}),n.jsx("span",{className:`text-[10px] leading-tight ${p?"font-semibold":""}`,children:s(m.id)})]},m.id)})})}const R7=["builder","agents","teams","skills"];function ire(){const e=localStorage.getItem("markus_nav_storeTab");return e&&(localStorage.removeItem("markus_nav_storeTab"),R7.includes(e))?e:"builder"}function ore({authUser:e}){const{t}=kt(["nav","common"]),r=b.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]=b.useState(ire),i=hl(r,s,a);return b.useEffect(()=>{const l=d=>{const u=d.detail;u.params?.storeTab&&R7.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(sc,{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(CS,{}),s==="agents"&&n.jsx(ES,{authUser:e}),s==="teams"&&n.jsx(RS,{}),s==="skills"&&n.jsx(LS,{})]})]})}const Vx="profile",Sj="llm",Cj="search";function lre({onComplete:e,theme:t,onThemeChange:r,skipProfile:s}){const{t:a}=kt(["onboarding","common"]),[i,l]=b.useState(0),[d,u]=b.useState(""),[m,p]=b.useState(""),[h,y]=b.useState(""),[g,v]=b.useState(""),[S,C]=b.useState(!1),[k,N]=b.useState(""),[j,T]=b.useState(!1),[R,M]=b.useState(null);b.useEffect(()=>{le.auth.me().then(({user:$e})=>{$e.name&&u($e.name),$e.email&&p($e.email),$e.avatarUrl&&M($e.avatarUrl)}).catch(()=>{})},[]);const[_,F]=b.useState(null),[z,L]=b.useState(!1),[U,K]=b.useState({}),[q,I]=b.useState(!1),[D,E]=b.useState(null),[$,Y]=b.useState(!1),[W,O]=b.useState(!1),[H,Z]=b.useState([]),[B,J]=b.useState(null),[Q,ee]=b.useState(!0),[se,X]=b.useState(""),me=b.useRef(!1),[je,Re]=b.useState(null),[Ee,we]=b.useState({serperApiKey:"",tavilyApiKey:"",bingApiKey:"",googleSearchApiKey:"",googleSearchCx:"",serpApiKey:"",braveApiKey:"",exaApiKey:"",bochaApiKey:""}),[pe,Pe]=b.useState(!1),[Ae,Xe]=b.useState(!1),[Ze,at]=b.useState(null),pt=b.useRef(!1),Ct=()=>({"Content-Type":"application/json",Authorization:`Bearer ${localStorage.getItem("markus_token")??""}`});b.useEffect(()=>{fetch("/api/settings/llm").then($e=>$e.ok?$e.json():null).then($e=>{if($e?.providers){const ct=Object.entries($e.providers).filter(([,Ut])=>Ut.configured).map(([Ut,zt])=>({name:Ut,displayName:zt.displayName??Ut,model:zt.model??"",apiKeyPreview:zt.apiKeyPreview}));ct.length>0&&(O(!0),Z(ct))}$e?.defaultProvider&&X($e.defaultProvider),typeof $e?.autoFallback=="boolean"&&ee($e.autoFallback)}).catch(()=>{})},[]);const _e=s?2:3;b.useEffect(()=>{i===_e&&!me.current&&!W&&(me.current=!0,fe())},[i,W,_e]);const ue=s?3:4;b.useEffect(()=>{i===ue&&!pt.current&&(pt.current=!0,de())},[i,ue]);const fe=async()=>{L(!0);try{const $e=await fetch("/api/settings/env-models",{headers:Ct()});if($e.ok){const ct=await $e.json();if(F(ct),ct.detected.length>0){const Ut={};for(const zt of ct.detected)Ut[zt.provider]=!0;K(Ut)}}}catch{}finally{L(!1)}},Me=async()=>{if(!_)return;const $e=_.detected.filter(ct=>U[ct.provider]);if($e.length!==0){I(!0),J(null);try{const ct=await fetch("/api/settings/env-models",{method:"POST",headers:Ct(),body:JSON.stringify({providers:$e.map(Ut=>({provider:Ut.provider,model:Ut.model,baseUrl:Ut.baseUrl,enabled:!0}))})});if(ct.ok){const Ut=await ct.json();if(Ut.settings?.providers){const cn=Object.entries(Ut.settings.providers).filter(([,Ln])=>Ln.configured).map(([Ln,Xt])=>({name:Ln,displayName:Xt.displayName??Ln,model:Xt.model??"",apiKeyPreview:Xt.apiKeyPreview}));Z(cn)}else Z($e.map(cn=>({name:cn.provider,displayName:cn.displayName,model:cn.model,apiKeyPreview:cn.apiKeyPreview})));const zt=Ut.settings?.defaultProvider||Ut.applied[0]||$e[0]?.provider||"";X(zt),zt&&fetch("/api/settings/llm",{method:"POST",headers:Ct(),body:JSON.stringify({defaultProvider:zt})}).catch(()=>{}),J({type:"ok",text:Ut.message}),O(!0)}else J({type:"err",text:a("llm.failedToApply")})}catch{J({type:"err",text:a("common:networkError")})}finally{I(!1)}}},ne=async()=>{Y(!0);try{const ct=await(await fetch("/api/settings/import/openclaw",{method:"POST",headers:Ct(),body:JSON.stringify({preview:!0})})).json();"error"in ct||E(ct)}catch{}finally{Y(!1)}},he=async()=>{try{const $e=await fetch("/api/settings/llm");if(!$e.ok)return;const ct=await $e.json();if(ct.providers){const Ut=Object.entries(ct.providers).filter(([,zt])=>zt.configured).map(([zt,cn])=>({name:zt,displayName:cn.displayName??zt,model:cn.model??"",apiKeyPreview:cn.apiKeyPreview}));Ut.length>0&&Z(Ut)}ct.defaultProvider&&X(ct.defaultProvider),typeof ct.autoFallback=="boolean"&&ee(ct.autoFallback)}catch{}},Be=async()=>{Y(!0),J(null);try{const ct=await(await fetch("/api/settings/import/openclaw",{method:"POST",headers:Ct(),body:JSON.stringify({preview:!1})})).json();"error"in ct?J({type:"err",text:ct.error}):(J({type:"ok",text:a("llm.importedModels",{count:ct.appliedModels})}),O(!0),await he())}catch{J({type:"err",text:a("llm.importFailed")})}finally{Y(!1)}},de=async()=>{try{const $e=await fetch("/api/settings/search",{headers:Ct()});if($e.ok){const ct=await $e.json();Re(ct),ct&&(ct.serper.configured||ct.tavily.configured||ct.bing.configured||ct.google.configured||ct.serpapi.configured||ct.brave.configured||ct.exa.configured||ct.bocha.configured)&&Xe(!0)}}catch{}},Ce=async()=>{if(Ee.serperApiKey||Ee.tavilyApiKey||Ee.bingApiKey||Ee.googleSearchApiKey||Ee.googleSearchCx||Ee.serpApiKey||Ee.braveApiKey||Ee.exaApiKey||Ee.bochaApiKey){Pe(!0),at(null);try{const ct={};Ee.serperApiKey&&(ct.serperApiKey=Ee.serperApiKey),Ee.tavilyApiKey&&(ct.tavilyApiKey=Ee.tavilyApiKey),Ee.bingApiKey&&(ct.bingApiKey=Ee.bingApiKey),Ee.googleSearchApiKey&&(ct.googleSearchApiKey=Ee.googleSearchApiKey),Ee.googleSearchCx&&(ct.googleSearchCx=Ee.googleSearchCx),Ee.serpApiKey&&(ct.serpApiKey=Ee.serpApiKey),Ee.braveApiKey&&(ct.braveApiKey=Ee.braveApiKey),Ee.exaApiKey&&(ct.exaApiKey=Ee.exaApiKey),Ee.bochaApiKey&&(ct.bochaApiKey=Ee.bochaApiKey);const Ut=await fetch("/api/settings/search",{method:"POST",headers:Ct(),body:JSON.stringify(ct)});if(Ut.ok){const zt=await Ut.json();Re(zt),Xe(!0),we({serperApiKey:"",tavilyApiKey:"",bingApiKey:"",googleSearchApiKey:"",googleSearchCx:"",serpApiKey:"",braveApiKey:"",exaApiKey:"",bochaApiKey:""}),at({type:"ok",text:a("search.saved")})}else at({type:"err",text:a("search.failedToSave")})}catch{at({type:"err",text:a("common:networkError")})}finally{Pe(!1)}}},et=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(h&&h.length<6){N(a("profile.errors.passwordTooShort"));return}if(h&&h!==g){N(a("profile.errors.passwordMismatch"));return}C(!0);try{await le.auth.updateProfile(d.trim(),m.trim()),h&&await le.auth.changePassword("",h),T(!0)}catch{N(a("profile.errors.saveFailed"))}finally{C(!1)}},it=[{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")}],Ve=[{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(Fu,{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(([$e,ct])=>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:$e}),n.jsx("div",{className:"text-fg-secondary text-xs mt-1",children:ct})]},$e))})]})},{id:Vx,title:a("profile.title"),subtitle:a("profile.subtitle"),content:j?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(Qj,{currentUrl:R,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:$e=>u($e.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:$e=>p($e.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:h,onChange:$e=>y($e.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"})]}),h&&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:g,onChange:$e=>v($e.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"})]}),k&&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:k}),n.jsx("button",{onClick:()=>{et()},disabled:S||!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(S?"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:it.map($e=>n.jsxs("button",{onClick:()=>r($e.value),className:`flex flex-col items-center gap-2 rounded-xl border-2 p-5 transition-all ${t===$e.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:$e.icon}),n.jsx("span",{className:"text-sm font-medium text-fg-primary",children:$e.label}),n.jsx("span",{className:"text-[11px] text-fg-tertiary leading-tight text-center",children:$e.desc})]},$e.value))})},{id:Sj,title:a("llm.title"),subtitle:a("llm.subtitle"),content:W?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")})]}),H.length>1&&n.jsx("div",{className:"text-xs text-fg-secondary mb-1",children:a("llm.selectDefault")}),H.map($e=>{const ct=se===$e.name;return n.jsxs("button",{onClick:async()=>{const Ut=se;X($e.name);try{await fetch("/api/settings/llm",{method:"POST",headers:Ct(),body:JSON.stringify({defaultProvider:$e.name})})}catch{X(Ut)}},className:`w-full flex items-center justify-between rounded-lg px-4 py-2.5 text-left transition-colors ${ct?"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 ${ct?"border-brand-500":"border-fg-tertiary"}`,children:ct&&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:$e.displayName}),$e.model&&n.jsx("span",{className:"text-xs text-fg-tertiary",children:$e.model}),ct&&n.jsx("span",{className:"text-[10px] text-brand-500 font-medium",children:a("llm.default")})]}),$e.apiKeyPreview&&n.jsx("code",{className:"text-[10px] text-fg-tertiary",children:$e.apiKeyPreview})]},$e.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 $e=!Q;ee($e);try{await fetch("/api/settings/llm",{method:"POST",headers:Ct(),body:JSON.stringify({autoFallback:$e})})}catch{ee(!$e)}},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:[n.jsxs("div",{className:"space-y-2",children:[n.jsx("div",{className:"text-xs text-fg-secondary uppercase tracking-wider",children:a("llm.fromEnv")}),z&&n.jsx("div",{className:"text-xs text-fg-tertiary animate-pulse",children:a("llm.detectingKeys")}),_&&_.detected.length>0&&n.jsxs("div",{className:"space-y-2",children:[_.detected.map($e=>n.jsxs("label",{className:"flex items-center gap-3 bg-surface-elevated/40 rounded-lg px-3 py-2.5 cursor-pointer hover:bg-surface-elevated/60 transition-colors",children:[n.jsx("input",{type:"checkbox",checked:U[$e.provider]??!1,onChange:ct=>K({...U,[$e.provider]:ct.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:$e.displayName}),n.jsx("span",{className:"text-xs text-fg-tertiary ml-2",children:$e.model})]}),n.jsx("code",{className:"text-[10px] text-fg-tertiary",children:$e.apiKeyPreview})]},$e.provider)),n.jsx("button",{onClick:()=>{Me()},disabled:q||Object.values(U).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:q?a("common:applying"):a("llm.applyProviders",{count:Object.values(U).filter(Boolean).length})})]}),_&&_.detected.length===0&&!z&&n.jsx("div",{className:"text-xs text-fg-tertiary bg-surface-elevated/30 rounded-lg p-3",children:n.jsx(Fu,{i18nKey:"llm.noKeysFound",ns:"onboarding",components:{code:n.jsx("code",{className:"text-fg-secondary"})}})})]}),n.jsxs("div",{className:"flex items-center gap-3",children:[n.jsx("div",{className:"flex-1 h-px bg-border-default"}),n.jsx("span",{className:"text-xs text-fg-tertiary",children:a("llm.or")}),n.jsx("div",{className:"flex-1 h-px bg-border-default"})]}),n.jsxs("div",{className:"space-y-2",children:[n.jsx("div",{className:"text-xs text-fg-secondary uppercase tracking-wider",children:a("llm.fromOpenClaw")}),D?D.found?n.jsxs("div",{className:"space-y-2",children:[n.jsxs("div",{className:"text-xs text-green-600",children:[a("llm.openClawFoundLabel")," ",n.jsx("code",{className:"text-fg-secondary",children:D.summary.configPath}),D.summary.models&&n.jsx("span",{className:"text-fg-tertiary ml-1",children:a("llm.openClawProviders",{count:D.summary.models.providerCount})})]}),n.jsx("button",{onClick:()=>{Be()},disabled:$,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:a($?"common:importing":"llm.importModelConfigs")})]}):n.jsx("div",{className:"text-xs text-fg-tertiary bg-surface-elevated/30 rounded-lg p-3",children:a("llm.noOpenClawFound")}):n.jsx("button",{onClick:()=>{ne()},disabled:$,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 w-full",children:a($?"common:detecting":"llm.detectOpenClaw")})]}),B&&n.jsx("div",{className:`text-xs px-3 py-2 rounded-lg ${B.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:B.text})]})},{id:Cj,title:a("search.title"),subtitle:a("search.subtitle"),content:Ae?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($e=>je[$e.id]?.configured).map($e=>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:$e.label})]}),n.jsx("code",{className:"text-[10px] text-fg-tertiary",children:je[$e.id].preview})]},$e.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($e=>je[$e.id]?.configured).map($e=>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:$e.label})]}),n.jsx("code",{className:"text-[10px] text-fg-tertiary",children:je[$e.id].preview})]},$e.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($e=>n.jsxs("div",{className:"space-y-1",children:[n.jsx("label",{className:"text-xs text-fg-tertiary font-medium",children:$e.label}),n.jsx("input",{type:"password",value:Ee[$e.field],onChange:ct=>we({...Ee,[$e.field]:ct.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"})]},$e.field))}),n.jsx("button",{onClick:()=>{Ce()},disabled:pe||!Ee.serperApiKey&&!Ee.tavilyApiKey&&!Ee.bingApiKey&&!Ee.googleSearchApiKey&&!Ee.serpApiKey&&!Ee.braveApiKey&&!Ee.exaApiKey&&!Ee.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(pe?"search.saving":"search.save")}),Ze&&n.jsx("div",{className:`text-xs px-3 py-2 rounded-lg ${Ze.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:Ze.text})]})},{id:"done",title:a("done.title"),subtitle:a("done.subtitle"),content:n.jsx("div",{className:"space-y-2 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(([$e,ct])=>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:$e}),n.jsx("div",{className:"text-fg-secondary text-xs",children:ct})]})]},$e))})}],Ge=s?Ve.filter($e=>$e.id!==Vx):Ve,ut=Ge.findIndex($e=>$e.id===Vx),nt=Ge.findIndex($e=>$e.id===Sj),ft=Ge.findIndex($e=>$e.id===Cj),Rt=()=>{i===ut&&ut>=0&&!j||(i<Ge.length-1?l(i+1):e())},lt=Ge[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:Ge.map(($e,ct)=>n.jsx("div",{className:`h-1 flex-1 rounded-full transition-colors ${ct<=i?"bg-brand-500":"bg-surface-elevated"}`},ct))}),n.jsx("h2",{className:"text-2xl font-bold text-fg-primary",children:lt.title}),n.jsx("p",{className:"text-sm text-fg-secondary mt-1 mb-6",children:lt.subtitle}),lt.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:[ut>=0&&i===ut&&!j&&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")}),nt>=0&&i===nt&&!W&&n.jsx("button",{onClick:Rt,className:"px-4 py-2 text-sm text-fg-tertiary hover:text-fg-secondary transition-colors",children:a("llm.skipForNow")}),ft>=0&&i===ft&&!Ae&&n.jsx("button",{onClick:Rt,className:"px-4 py-2 text-sm text-fg-tertiary hover:text-fg-secondary transition-colors",children:a("search.skipForNow")}),n.jsx("button",{onClick:Rt,disabled:ut>=0&&i===ut&&!j,className:`px-6 py-2.5 text-white text-sm rounded-xl transition-colors ${ut>=0&&i===ut&&!j?"bg-brand-600/40 cursor-not-allowed":"bg-brand-600 hover:bg-brand-500"}`,children:i===Ge.length-1?a("getStarted"):a("common:next")})]})]})]})})})}function cre({onSetup:e}){const{t}=kt("auth"),[r,s]=b.useState(""),[a,i]=b.useState(""),[l,d]=b.useState(""),[u,m]=b.useState(""),[p,h]=b.useState(null),[y,g]=b.useState(""),[v,S]=b.useState(!1),C=b.useRef(null),k=b.useCallback(j=>{if(!j.type.startsWith("image/")||j.size>2*1024*1024)return;const T=new FileReader;T.onload=()=>h(T.result),T.readAsDataURL(j)},[]),N=async j=>{if(j.preventDefault(),g(""),l.length<6){g(t("setup.passwordMinLength"));return}if(l!==u){g(t("setup.passwordsDoNotMatch"));return}S(!0);try{const{user:T,needsOnboarding:R}=await le.auth.init(r.trim(),a.trim(),l);if(p)try{await le.auth.uploadAvatar(p,"user")}catch{}e(T,R??!0)}catch{g(t("setup.error"))}finally{S(!1)}};return r.trim()&&r.trim()[0].toUpperCase(),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:t("setup.subtitle")})]}),n.jsxs("form",{onSubmit:N,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.jsx("h2",{className:"text-lg font-semibold text-fg-primary text-center",children:t("setup.title")}),n.jsxs("div",{className:"flex flex-col items-center gap-2",children:[n.jsxs("div",{className:"relative group cursor-pointer",onClick:()=>C.current?.click(),children:[p?n.jsx("img",{src:p,alt:"",className:"w-16 h-16 rounded-full object-cover ring-2 ring-border-default group-hover:ring-brand-500 transition-all"}):n.jsx("div",{className:"w-16 h-16 rounded-full bg-surface-elevated border-2 border-dashed border-border-default group-hover:border-brand-500 flex items-center justify-center transition-all",children:n.jsxs("svg",{className:"w-6 h-6 text-fg-tertiary group-hover:text-brand-500 transition-colors",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:[n.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5,d:"M3 9a2 2 0 012-2h.93a2 2 0 001.664-.89l.812-1.22A2 2 0 0110.07 4h3.86a2 2 0 011.664.89l.812 1.22A2 2 0 0018.07 7H19a2 2 0 012 2v9a2 2 0 01-2 2H5a2 2 0 01-2-2V9z"}),n.jsx("circle",{cx:"12",cy:"13",r:"3"})]})}),n.jsx("div",{className:"absolute -bottom-0.5 -right-0.5 w-5 h-5 rounded-full bg-brand-600 flex items-center justify-center ring-2 ring-surface-secondary",children:n.jsx("svg",{className:"w-3 h-3 text-white",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:n.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 4v16m8-8H4"})})}),n.jsx("input",{ref:C,type:"file",accept:"image/png,image/jpeg,image/webp,image/gif",className:"hidden",onChange:j=>{const T=j.target.files?.[0];T&&k(T)}})]}),n.jsx("span",{className:"text-xs text-fg-tertiary",children:t("setup.uploadAvatar")})]}),n.jsxs("div",{className:"space-y-1",children:[n.jsx("label",{className:"text-xs text-fg-tertiary font-medium",children:t("setup.name")}),n.jsx("input",{type:"text",value:r,onChange:j=>s(j.target.value),autoComplete:"name",autoFocus:!0,placeholder:"Admin",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.jsxs("div",{className:"space-y-1",children:[n.jsx("label",{className:"text-xs text-fg-tertiary font-medium",children:t("setup.email")}),n.jsx("input",{type:"email",value:a,onChange:j=>i(j.target.value),autoComplete:"email",placeholder:"your@email.com",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.jsxs("div",{className:"space-y-1",children:[n.jsx("label",{className:"text-xs text-fg-tertiary font-medium",children:t("setup.password")}),n.jsx("input",{type:"password",value:l,onChange:j=>d(j.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})]}),n.jsxs("div",{className:"space-y-1",children:[n.jsx("label",{className:"text-xs text-fg-tertiary font-medium",children:t("setup.confirmPassword")}),n.jsx("input",{type:"password",value:u,onChange:j=>m(j.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})]}),y&&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:y}),n.jsx("button",{type:"submit",disabled:v||!r||!a||!l||!u,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:t(v?"setup.creating":"setup.createAccount")})]})]})]})}function dre({onLogin:e}){const{t}=kt("auth"),[r,s]=b.useState(""),[a,i]=b.useState(""),[l,d]=b.useState(""),[u,m]=b.useState(!1),p=async h=>{if(h.preventDefault(),!(!r.trim()||!a)){d(""),m(!0);try{const{user:y,needsOnboarding:g}=await le.auth.login(r.trim(),a);e(y,g??!1)}catch{d(t("login.invalidCredentials"))}finally{m(!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:t("login.subtitle")})]}),n.jsxs("form",{onSubmit:p,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.jsx("h2",{className:"text-lg font-semibold text-fg-primary text-center",children:t("login.signIn")}),n.jsxs("div",{className:"space-y-1",children:[n.jsx("label",{className:"text-xs text-fg-tertiary font-medium",children:t("login.email")}),n.jsx("input",{type:"email",value:r,onChange:h=>s(h.target.value),autoComplete:"email",placeholder:"your@email.com",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.jsxs("div",{className:"space-y-1",children:[n.jsx("label",{className:"text-xs text-fg-tertiary font-medium",children:t("login.password")}),n.jsx("input",{type:"password",value:a,onChange:h=>i(h.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",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}),n.jsx("button",{type:"submit",disabled:u||!r||!a,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:t(u?"login.signingIn":"login.signIn")}),n.jsx("p",{className:"text-center text-xs text-fg-tertiary",children:t("login.defaultCredentials")})]})]})]})}function ure({token:e,onComplete:t}){const{t:r}=kt("auth"),[s,a]=b.useState(null),[i,l]=b.useState(""),[d,u]=b.useState(""),[m,p]=b.useState(""),[h,y]=b.useState(!1),[g,v]=b.useState(!1),[S,C]=b.useState(!1);b.useEffect(()=>{le.auth.inviteInfo(e).then(N=>a(N)).catch(()=>C(!0))},[e]);const k=async N=>{if(N.preventDefault(),p(""),i.length<6){p(r("invite.passwordMinLength"));return}if(i!==d){p(r("invite.passwordsDoNotMatch"));return}y(!0);try{await le.auth.setup(e,i),v(!0),setTimeout(()=>{window.location.hash="",t()},2e3)}catch{p(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:S?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")})]}):g?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:k,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:h||!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(h?"invite.settingUp":"invite.setupAccount")})]}):n.jsx("div",{className:"text-center text-fg-tertiary text-sm animate-pulse py-4",children:"Loading…"})})]})]})}function mre({onComplete:e,isFirstTime:t}){const{t:r}=kt("auth"),[s,a]=b.useState(""),[i,l]=b.useState(""),[d,u]=b.useState(""),[m,p]=b.useState(""),[h,y]=b.useState(!1),g=async v=>{if(v.preventDefault(),p(""),i.length<6){p(r("changePassword.passwordMinLength"));return}if(i!==d){p(r("changePassword.passwordsDoNotMatch"));return}y(!0);try{await le.auth.changePassword(s,i),e()}catch{p(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:g,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:h||!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(h?"changePassword.saving":t?"changePassword.setPasswordAndContinue":"changePassword.changePassword")})]})]})]})}const Ef={agents:[],tasks:[],requirements:[],projects:[],deliverables:[]},fre={team:["agents","tasks","requirements","projects","deliverables"],work:["projects","requirements","tasks","agents","deliverables"],deliverables:["deliverables","agents","tasks","requirements","projects"]},hre=["agents","tasks","requirements","projects","deliverables"];let Tj="",Aj="all",Ej=Ef,Mj=!1;function pre({onClose:e,currentPage:t}){const{t:r}=kt(["common","home","work"]),[s,a]=b.useState(Tj),[i,l]=b.useState(Aj),[d,u]=b.useState(Ej),[m,p]=b.useState(!1),[h,y]=b.useState(Mj),[g,v]=b.useState(-1);b.useEffect(()=>{Tj=s},[s]),b.useEffect(()=>{Aj=i},[i]),b.useEffect(()=>{Ej=d},[d]),b.useEffect(()=>{Mj=h},[h]);const S=b.useRef(null),C=b.useRef(void 0),k=b.useRef(null),N=b.useRef(null);b.useEffect(()=>{setTimeout(()=>{S.current?.focus(),S.current?.select()},100)},[]);const j=b.useCallback(async q=>{if(!q.trim()){u(Ef),y(!1),v(-1);return}p(!0),y(!0),v(-1);const I=q.toLowerCase();try{const[D,E,$,Y,W]=await Promise.allSettled([le.agents.list(),le.tasks.list({search:q,pageSize:20}),le.requirements.list(),le.projects.list(),le.deliverables.search({q,limit:20})]),O=D.status==="fulfilled"?D.value.agents.filter(Q=>Q.name?.toLowerCase().includes(I)||Q.role?.toLowerCase().includes(I)):[],H=E.status==="fulfilled"?E.value.tasks:[],Z=$.status==="fulfilled"?$.value.requirements.filter(Q=>Q.title?.toLowerCase().includes(I)||Q.description?.toLowerCase().includes(I)):[],B=Y.status==="fulfilled"?Y.value.projects.filter(Q=>Q.name?.toLowerCase().includes(I)||Q.description?.toLowerCase().includes(I)):[],J=W.status==="fulfilled"?W.value.results:[];u({agents:O,tasks:H,requirements:Z,projects:B,deliverables:J})}catch{u(Ef)}finally{p(!1)}},[]),T=q=>{a(q),C.current&&clearTimeout(C.current),C.current=setTimeout(()=>j(q),400)},R=b.useCallback((q,I)=>{e(),Nt.navigate(q,I)},[e]),M=[{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:"交付物"})}],_=b.useMemo(()=>fre[t||""]||hre,[t]),F=b.useMemo(()=>{const q=[],I=i==="all"?8:void 0,D=E=>{if(i!=="all"&&i!==E)return;const $=d[E==="agents"?"agents":E==="tasks"?"tasks":E==="requirements"?"requirements":E==="projects"?"projects":"deliverables"],Y=I?$.slice(0,I):$;for(const W of Y)switch(E){case"agents":q.push({id:W.id,type:"agent",page:Se.TEAM,params:{agentId:W.id}});break;case"tasks":q.push({id:W.id,type:"task",page:Se.WORK,params:{openTask:W.id}});break;case"requirements":q.push({id:W.id,type:"requirement",page:Se.WORK,params:{openRequirement:W.id}});break;case"projects":q.push({id:W.id,type:"project",page:Se.WORK,params:{projectId:W.id}});break;case"deliverables":q.push({id:W.id,type:"deliverable",page:Se.DELIVERABLES,params:{openDeliverable:W.id}});break}I&&$.length>I&&q.push({id:`more_${E}`,type:"showMore",page:"",expandCategory:E,totalCount:$.length})};for(const E of _)D(E);return q},[d,i,_]),z=b.useCallback(q=>{if(q.type==="showMore"&&q.expandCategory){l(q.expandCategory),v(-1);return}R(q.page,q.params)},[R]);b.useEffect(()=>{const q=N.current;if(!q||g<0)return;const I=q.querySelector(`[data-idx="${g}"]`);I&&I.scrollIntoView({block:"nearest"})},[g]);const L=b.useCallback(q=>{if(q.key==="Escape"){e();return}if(q.key==="Tab"){q.preventDefault();const E=M.map(W=>W.id),$=E.indexOf(i),Y=q.shiftKey?$<=0?E.length-1:$-1:$>=E.length-1?0:$+1;l(E[Y]),v(-1);return}const I=q.ctrlKey&&q.key==="n"||q.key==="ArrowDown",D=q.ctrlKey&&q.key==="p"||q.key==="ArrowUp";if(I||D){q.preventDefault(),v(E=>{const $=F.length-1;return $<0?-1:I?E>=$?0:E+1:E<=0?$:E-1});return}q.key==="Enter"&&(q.preventDefault(),g>=0&&g<F.length&&z(F[g]))},[e,F,g,z,M,i]);b.useEffect(()=>(document.addEventListener("keydown",L),()=>document.removeEventListener("keydown",L)),[L]);const U=F.length>0;let K=0;return n.jsx("div",{ref:k,className:"fixed inset-0 bg-black/50 flex items-start justify-center z-50 pt-[8vh]",onClick:q=>{q.target===k.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:S,value:s,onChange:q=>T(q.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(Ef),y(!1),v(-1),S.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:M.map(q=>n.jsx("button",{onClick:()=>{l(q.id),v(-1)},className:`px-3 py-1.5 text-xs rounded-lg whitespace-nowrap transition-colors ${i===q.id?"bg-brand-600 text-white":"bg-surface-elevated text-fg-secondary hover:text-fg-primary"}`,children:q.label},q.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&&h&&!U&&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&&U&&n.jsx("div",{className:"space-y-4",children:_.map(q=>{if(i!=="all"&&i!==q)return null;const I=i==="all"?8:void 0,D=E=>{const $=K++,Y=E==="agents"?d.agents.length:E==="tasks"?d.tasks.length:E==="requirements"?d.requirements.length:E==="projects"?d.projects.length:d.deliverables.length;return n.jsxs("button",{"data-idx":$,onClick:()=>{l(E),v(-1)},className:`mt-1 w-full text-xs py-1.5 rounded-lg transition-colors ${$===g?"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:"查看全部"})," (",Y,")"]})};return q==="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:(I?d.agents.slice(0,I):d.agents).map(E=>{const $=K++;return n.jsxs("button",{"data-idx":$,onClick:()=>R(Se.TEAM,{agentId:E.id}),className:`w-full flex items-center gap-3 px-3 py-2 rounded-xl transition-colors text-left ${$===g?"bg-brand-600/15 ring-1 ring-brand-500/40":"hover:bg-surface-overlay"}`,children:[n.jsx(gr,{name:E.name||"Agent",avatarUrl:E.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:E.name}),n.jsx("div",{className:"text-xs text-fg-tertiary truncate",children:E.role||E.status})]}),n.jsx(gre,{status:E.status})]},E.id)})}),I&&d.agents.length>I&&D("agents")]},"agents"):q==="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:(I?d.tasks.slice(0,I):d.tasks).map(E=>{const $=K++;return n.jsxs("button",{"data-idx":$,onClick:()=>R(Se.WORK,{openTask:E.id}),className:`w-full flex items-center gap-3 px-3 py-2 rounded-xl transition-colors text-left ${$===g?"bg-brand-600/15 ring-1 ring-brand-500/40":"hover:bg-surface-overlay"}`,children:[n.jsx(xre,{status:E.status}),n.jsxs("div",{className:"flex-1 min-w-0",children:[n.jsx("div",{className:"text-sm text-fg-primary truncate",children:E.title}),n.jsxs("div",{className:"text-xs text-fg-tertiary truncate",children:[E.status," · ",E.priority||""]})]})]},E.id)})}),I&&d.tasks.length>I&&D("tasks")]},"tasks"):q==="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:(I?d.requirements.slice(0,I):d.requirements).map(E=>{const $=K++;return n.jsxs("button",{"data-idx":$,onClick:()=>R(Se.WORK,{openRequirement:E.id}),className:`w-full flex items-center gap-3 px-3 py-2 rounded-xl transition-colors text-left ${$===g?"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 ${E.status==="approved"?"text-green-500 bg-green-500/15":E.status==="pending"?"text-amber-500 bg-amber-500/15":E.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:E.title}),n.jsxs("div",{className:"text-xs text-fg-tertiary truncate",children:[E.status," · ",E.priority||""]})]})]},E.id)})}),I&&d.requirements.length>I&&D("requirements")]},"requirements"):q==="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:(I?d.projects.slice(0,I):d.projects).map(E=>{const $=K++;return n.jsxs("button",{"data-idx":$,onClick:()=>R(Se.WORK,{projectId:E.id}),className:`w-full flex items-center gap-3 px-3 py-2 rounded-xl transition-colors text-left ${$===g?"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:E.name}),E.description&&n.jsx("div",{className:"text-xs text-fg-tertiary truncate",children:E.description})]})]},E.id)})}),I&&d.projects.length>I&&D("projects")]},"projects"):q==="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:(I?d.deliverables.slice(0,I):d.deliverables).map(E=>{const $=K++;return n.jsxs("button",{"data-idx":$,onClick:()=>R(Se.DELIVERABLES,{openDeliverable:E.id}),className:`w-full flex items-center gap-3 px-3 py-2 rounded-xl transition-colors text-left ${$===g?"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:E.title}),n.jsxs("div",{className:"text-xs text-fg-tertiary truncate",children:[E.type," · ",E.status]})]})]},E.id)})}),I&&d.deliverables.length>I&&D("deliverables")]},"deliverables"):null})}),!m&&!h&&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 gre({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 xre({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 bre=b.memo(function({id:t,activePage:r,children:s}){return n.jsx("div",{className:"flex-1 overflow-hidden flex flex-col",style:{display:t===r?"flex":"none"},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}),Wx={};function yre(){const{t:e}=kt("common"),[t,r]=b.useState(Ul),[s,a]=b.useState(()=>!localStorage.getItem("markus_onboarded")),[i,l]=b.useState(!0),d=ks(),u=JK(),m=Zu({side:"left",defaultWidth:160,minWidth:140,maxWidth:400,collapsedWidth:64,storageKey:"markus_sidebar"}),[p,h]=b.useState(()=>new Set([Ul()])),[y,g]=b.useState("loading"),[v,S]=b.useState(null),[C,k]=b.useState(!1),[N,j]=b.useState(!1),[T,R]=b.useState(null),[M,_]=b.useState(!1),[F,z]=b.useState(null),[L,U]=b.useState(()=>{const O=localStorage.getItem("markus_update_dismissed");return O||null}),[K,q]=b.useState(!1);b.useEffect(()=>{if(d)return;const O=navigator.platform.toUpperCase().includes("MAC"),H=B=>{O&&B.metaKey&&!B.ctrlKey&&B.key==="p"?(B.preventDefault(),q(J=>!J)):!O&&B.ctrlKey&&!B.metaKey&&B.key==="p"&&(B.preventDefault(),q(J=>!J))},Z=()=>q(!0);return document.addEventListener("keydown",H),window.addEventListener("markus:open-search",Z),()=>{document.removeEventListener("keydown",H),window.removeEventListener("markus:open-search",Z)}},[d]);const I=b.useCallback(O=>{let H=il(O);d?H=JO[H]??H:H===Se.NOTIFICATIONS&&(H=Se.HOME);const Z=Ul(),B=window.location.hash.slice(1);B!==Z?Wx[Z]=B:delete Wx[Z];const J=H!==Se.WORK?Wx[H]:void 0;J&&J!==H?(history.pushState(null,"","#"+H),history.pushState(null,"","#"+J)):history.pushState(null,"","#"+H),window.dispatchEvent(new HashChangeEvent("hashchange")),r(H),h(Q=>Q.has(H)?Q:new Set([...Q,H]))},[d]);b.useEffect(()=>{Nt.setHandler(O=>I(O))},[I]);const D=b.useCallback(()=>{fetch("/api/settings/llm").then(O=>O.ok?O.json():null).then(O=>{if(O?.providers){const H=Object.values(O.providers).some(Z=>Z.configured);R(H)}}).catch(()=>{})},[]);b.useEffect(()=>{const O=new URLSearchParams(window.location.search),H=O.get("install");if(H&&Ul()!==Se.STORE){const J=O.get("type"),ee=J&&{agent:"agents",team:"teams",skill:"skills"}[J]||"agents";localStorage.setItem("markus_nav_installItem",H),localStorage.setItem("markus_nav_storeTab",ee),O.delete("install"),O.delete("type");const se=O.toString();window.history.replaceState(null,"",window.location.pathname+(se?`?${se}`:"")+"#store"),setTimeout(()=>Nt.navigate(Se.STORE,{storeTab:ee,installItem:H}),300)}le.auth.me().then(({user:J})=>{g(J),S(!0),gn.connect(J.id),D(),le.health().then(ee=>{ee.updateAvailable&&ee.latestVersion&&z({latestVersion:ee.latestVersion,currentVersion:ee.version})}).catch(()=>{});const Q=()=>{Bl(ga.builderArtifacts,()=>le.builder.artifacts.list()),Bl(ga.builderAgents,()=>le.agents.list()),Bl(ga.builderHubMyItems,()=>zn.myItems()),Bl(ga.builderInstalled,()=>le.builder.artifacts.installed()),Bl(ga.hubAgents,()=>zn.search({type:"agent",limit:50})),Bl(ga.hubTeams,()=>zn.search({type:"team",limit:50})),Bl(ga.hubSkills,()=>zn.search({type:"skill",limit:50}))};typeof requestIdleCallback=="function"?requestIdleCallback(Q,{timeout:5e3}):setTimeout(Q,3e3)}).catch(()=>{g(null),le.auth.status().then(({initialized:J})=>S(J)).catch(()=>S(!0))}),gn.connect();const Z=gn.on("notification",()=>{window.dispatchEvent(new CustomEvent("markus:notifications-changed"))}),B=()=>{const J=Ul();r(J),h(Q=>Q.has(J)?Q:new Set([...Q,J]))};return window.addEventListener("hashchange",B),()=>{Z(),gn.disconnect(),window.removeEventListener("hashchange",B)}},[]);const E=y!=="loading"&&y!==null?y:void 0,$=b.useMemo(()=>d?{[Se.HOME]:n.jsx(aw,{authUser:E}),[Se.TEAM]:n.jsx(Ek,{authUser:E}),[Se.BUILDER]:n.jsx(ore,{authUser:E}),[Se.SETTINGS]:n.jsx(Lk,{theme:u.mode,onThemeChange:u.setMode,authUser:E,onLogout:()=>g(null),onUserUpdated:O=>g(O)}),[Se.WORK]:n.jsx(yj,{authUser:E}),[Se.DELIVERABLES]:n.jsx(wj,{authUser:E}),[Se.NOTIFICATIONS]:n.jsx(Jne,{authUser:E}),[Se.REPORTS]:n.jsx(jj,{authUser:E}),[Se.SEARCH]:n.jsx(ere,{})}:{[Se.HOME]:n.jsx(aw,{authUser:E}),[Se.TEAM]:n.jsx(Ek,{authUser:E}),[Se.SETTINGS]:n.jsx(Lk,{theme:u.mode,onThemeChange:u.setMode,authUser:E,onLogout:()=>g(null),onUserUpdated:O=>g(O)}),[Se.STORE]:n.jsx(DG,{authUser:E}),[Se.BUILDER]:n.jsx(CS,{authUser:E}),[Se.WORK]:n.jsx(yj,{authUser:E}),[Se.DELIVERABLES]:n.jsx(wj,{authUser:E}),[Se.REPORTS]:n.jsx(jj,{authUser:E})},[E?.id,E?.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 W=(typeof window<"u"?window.location.hash:"").match(/^#invite\?token=([a-f0-9]+)/);return W?n.jsx(ure,{token:W[1],onComplete:()=>{window.location.hash="",localStorage.removeItem("markus_onboarded"),a(!0),k(!0),g("loading"),le.auth.me().then(O=>g(O.user)).catch(()=>g(null))}}):y===null?v===!1?n.jsx(cre,{onSetup:(O,H)=>{g(O),S(!0),k(!0),H&&(localStorage.removeItem("markus_onboarded"),a(!0))}}):n.jsx(dre,{onLogin:(O,H)=>{g(O),H?(localStorage.removeItem("markus_onboarded"),a(!0)):localStorage.getItem("markus_onboarded")||(localStorage.setItem("markus_onboarded","1"),a(!1))}}):N?n.jsx(mre,{onComplete:()=>j(!1),isFirstTime:!0}):s?n.jsx(lre,{theme:u.mode,onThemeChange:u.setMode,skipProfile:C,onComplete:()=>{localStorage.setItem("markus_onboarded","1"),a(!1),k(!1),D(),I(Se.HOME)}}):n.jsxs("div",{className:`flex h-dvh bg-surface-primary text-fg-primary overflow-x-hidden ${d?"flex-col":""}`,children:[!d&&t!==Se.SETTINGS&&n.jsxs(n.Fragment,{children:[n.jsx("div",{className:"relative z-40 shrink-0",style:{width:m.width},children:n.jsx(sre,{currentPage:t,onNavigate:O=>{I(O),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!==Se.SETTINGS&&t!==Se.SEARCH?"pb-14":""}`,children:[T===!1&&!M&&t!==Se.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:()=>{I(Se.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:()=>_(!0),className:"text-amber-500 hover:text-amber-600 text-xs",children:e("dismiss")})]})]}),F&&L!==F.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.jsxs("span",{className:d?"text-xs":"",children:["New version available: ",n.jsxs("strong",{children:["v",F.latestVersion]})," (current: v",F.currentVersion,")",!d&&n.jsxs("span",{className:"text-fg-tertiary ml-2",children:["— run ",n.jsx("code",{className:"bg-surface-overlay px-1.5 py-0.5 rounded text-xs font-mono",children:"npm i -g @markus-global/cli"})," to upgrade"]})]}),n.jsx("button",{onClick:()=>{U(F.latestVersion),localStorage.setItem("markus_update_dismissed",F.latestVersion)},className:"text-brand-400 hover:text-brand-300 text-xs shrink-0",children:e("dismiss")})]}),n.jsx("main",{className:"flex-1 overflow-hidden flex flex-col",children:Object.keys($).map(O=>p.has(O)?n.jsx(bre,{id:O,activePage:t,children:$[O]},O):null)})]}),d&&t!==Se.SETTINGS&&t!==Se.SEARCH&&n.jsx(are,{currentPage:t,onNavigate:I,userId:E?.id}),d&&n.jsx(o_,{authUser:E,onNavigate:I}),!d&&K&&n.jsx(pre,{onClose:()=>q(!1),currentPage:t})]})}l9.createRoot(document.getElementById("root")).render(n.jsx(b.StrictMode,{children:n.jsx(yre,{})}));export{c0 as g};
706
+ ${Oe?"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 ${Rs.cls}`,children:Rs.label})]}),n.jsx("div",{className:"text-[13px] font-medium leading-snug text-fg-primary line-clamp-2 mb-1",children:Dt.title}),Dt.description&&n.jsx("div",{className:"text-[11px] text-fg-tertiary line-clamp-1 mb-1.5",children:Dt.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:[Fr&&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:Fr.name,children:Fr.name}),n.jsx("span",{className:"text-[10px] text-fg-tertiary",children:Dt.priority}),n.jsxs("span",{className:"text-[10px] text-fg-quaternary",children:["by ",ie]})]}),n.jsx("div",{className:"flex items-center gap-1",children:Dt.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:["📋 ",Dt.taskIds.length]})})]}),Fs&&n.jsxs("div",{className:"flex items-center gap-2 mt-2 pt-2 border-t border-amber-500/15",children:[n.jsx("button",{onClick:Je=>{Je.stopPropagation(),Yr(Dt.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:Je=>{Je.stopPropagation(),Fn(Dt.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-${Dt.id}`)}else{const Dt=En.data,Rs=Dt.subtasks?.length??0,Ls=l[Dt.status],Fs=Dt.status==="pending",Fr=Dt.taskType==="scheduled"&&!!Dt.scheduleConfig,ie=Fr?Dt.scheduleConfig.every?s("work:task.everyInterval",{interval:Dt.scheduleConfig.every}):Dt.scheduleConfig.cron?s("work:task.cronLabel"):s("work:task.scheduledShort"):null,Oe=T==="all"&&Dt.projectId?(()=>{const rs=N.find(Cd=>Cd.id===Dt.projectId)?.name;return rs&&rs!=="default"?rs:null})():null,Je=Dt.requirementId?I.find(rs=>rs.id===Dt.requirementId)?.title:null,Mn=Dt.createdBy?xd(Dt.createdBy,L,K)??Dt.createdBy:null,ia=et?.id===Dt.id,Aa={urgent:"bg-red-500",high:"bg-amber-500",medium:"bg-blue-500",low:"bg-gray-400"};return n.jsxs("div",{role:"button",tabIndex:0,"aria-label":Dt.title,draggable:!Fs,onDragStart:rs=>!Fs&&ja(rs,Dt),onDragEnd:Gs,onClick:()=>Gr(Dt),onKeyDown:rs=>rs.key==="Enter"&&Gr(Dt),className:`group rounded-lg p-2.5 border border-transparent transition-all ${Fs?"bg-amber-500/[0.06] border-amber-500/30 ring-1 ring-amber-500/15 cursor-pointer":Fr?"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"} ${ia?"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 ${Aa[Dt.priority]??"bg-gray-400"}`,title:Dt.priority}),Fr&&n.jsx("span",{className:"text-blue-500 shrink-0",title:ie??"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"})})}),Fr&&ie&&n.jsx("span",{className:"text-[9px] px-1.5 py-0.5 rounded-md bg-blue-500/10 text-blue-500 whitespace-nowrap",children:ie}),Ls&&n.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded-md ml-auto shrink-0 ${Ls.cls}`,children:Ls.label})]}),n.jsx("div",{className:"text-[13px] font-medium leading-snug text-fg-primary line-clamp-2 mb-1",children:Dt.title}),Dt.description&&n.jsx("div",{className:"text-[11px] text-fg-tertiary line-clamp-1 mb-1.5",children:Dt.description}),(Oe||Je||Dt.blockedBy&&Dt.blockedBy.length>0)&&n.jsxs("div",{className:"flex flex-wrap gap-1 mb-1.5",children:[Oe&&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:Oe,children:Oe}),Je&&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:Je,children:["# ",Je]}),Dt.blockedBy&&Dt.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:["⏳ ",Dt.blockedBy.length," dep",Dt.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:Mn&&n.jsxs("span",{className:"text-[10px] text-fg-quaternary",title:`by ${Mn}`,children:["by ",Mn]})}),n.jsxs("div",{className:"flex items-center gap-1.5",children:[Rs>0&&n.jsxs("span",{className:"text-[10px] text-fg-tertiary",children:["⋮ ",Rs]}),Dt.notes&&Dt.notes.length>0&&n.jsxs("span",{className:"text-[10px] text-fg-tertiary",children:["📝 ",Dt.notes.length]}),Dt.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 ${l0[L.find(rs=>rs.id===Dt.assignedAgentId)?.status??""]??"bg-gray-500"}`}),L.find(rs=>rs.id===Dt.assignedAgentId)?.name??Dt.assignedAgentId.slice(0,8)]})]})]})]},Dt.id)}})})()}),sn&&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")})})]},ae.id)})})})]}),!u&&Ta&&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||S)&&Ta&&n.jsx("div",{className:`${u||Ni?"flex-1":"shrink-0"} overflow-hidden min-w-0 flex`,style:u||Ni?void 0:{width:v.width},children:Ni?n.jsxs(n.Fragment,{children:[n.jsx("div",{className:"flex-1 min-w-0 overflow-hidden",children:n.jsx(vj,{req:Ve,agents:L,projects:N,allTasks:Object.values(F).flat(),users:K,onClose:()=>{Ge(null)},onApprove:ae=>{Yr(ae)},onReject:ae=>{Fn(ae)},onCancel:ae=>{ka(ae),Ge(null)},onStatusChange:async(ae,Ye)=>{try{await le.requirements.updateStatus(ae,Ye),en(`Requirement status → ${Ye}`),Rr({requirementId:ae}),vn(),Bt()}catch(dt){en(`Error: ${dt}`)}},onRefresh:vn,authUser:e,onTaskClick:ae=>{it(ae)},onCreateTask:(ae,Ye)=>{_e(ae),Ye&&pt(Ye),X(!0)},onProjectClick:Cr,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(hj,{task:et,agents:L,projects:N,requirements:I,allTasks:Object.values(F).flat(),users:K,onClose:sa,onRefresh:ji,authUser:e,scrollToComments:dr,onScrollToCommentsDone:()=>va(!1),onReqClick:ae=>{Ge(Ye=>Ye?.id===ae.id?null:ae)},onProjectClick:Cr})})]}):et?n.jsx(hj,{task:et,agents:L,projects:N,requirements:I,allTasks:Object.values(F).flat(),users:K,onClose:Bs,onRefresh:ji,authUser:e,scrollToComments:dr,onScrollToCommentsDone:()=>va(!1),onReqClick:ae=>{Ge(Ye=>Ye?.id===ae.id?null:ae)},onProjectClick:Cr}):Ve?n.jsx(vj,{req:Ve,agents:L,projects:N,allTasks:Object.values(F).flat(),users:K,onClose:Bs,onApprove:ae=>{Yr(ae)},onReject:ae=>{Fn(ae)},onCancel:ae=>{ka(ae),Bs()},onStatusChange:async(ae,Ye)=>{try{await le.requirements.updateStatus(ae,Ye),en(`Requirement status → ${Ye}`),Rr({requirementId:ae}),vn(),Bt()}catch(dt){en(`Error: ${dt}`)}},scrollToComments:dr,onScrollToCommentsDone:()=>va(!1),onRefresh:vn,authUser:e,onTaskClick:ae=>{it(ae),u&&(C(!0),history.pushState({mobileDetail:Se.WORK},"",window.location.hash))},onCreateTask:(ae,Ye)=>{_e(ae),Ye&&pt(Ye),X(!0)},onProjectClick:Cr,previewMode:t}):null}),Q&&n.jsx(Sne,{orgId:e?.orgId,onCreated:ci,onClose:()=>ee(!1)}),se&&n.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 p-3",onClick:()=>{X(!1),Ce("")},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:ae=>ae.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:me,onChange:ae=>je(ae.target.value),onKeyDown:ae=>{ae.key==="Enter"&&Ms()},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:Re,onChange:ae=>Ee(ae.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(ku,{options:[{value:"",label:s("work:task.noProject")},...N.map(ae=>({value:ae.id,label:ae.name}))],value:at,onChange:ae=>{pt(ae),_e("")},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(ku,{options:[{value:"",label:s("work:task.selectRequirement")},...I.filter(ae=>ae.status==="in_progress"&&(!at||ae.projectId===at)).map(ae=>({value:ae.id,label:ae.title}))],value:Ct,onChange:_e,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(ku,{options:L.map(ae=>({value:ae.id,label:`${ae.name} (${ae.status})`})),value:Pe,onChange:Ae,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(ku,{options:[...K.map(ae=>({value:`human:${ae.id}`,label:ae.name})),...L.filter(ae=>ae.id!==Pe).map(ae=>({value:`agent:${ae.id}`,label:`${ae.name} (${ae.status})`}))],value:Xe,onChange:Ze,placeholder:s("work:task.selectReviewer"),noMatchesText:s("work:task.noMatches")})]})]}),n.jsxs("div",{className:`grid gap-4 ${Me==="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:we,onChange:ae=>pe(ae.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:Me,onChange:ae=>ne(ae.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")})]})]}),Me==="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:he,onChange:ae=>Be(ae.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(Cne,{options:Object.values(F).flat().filter(ae=>ae.status!=="completed"&&ae.status!=="cancelled").map(ae=>({value:ae.id,label:ae.title})),selected:ue,onAdd:ae=>fe([...ue,ae]),placeholder:s("work:task.selectDependency"),noMatchesText:s("work:task.noMatches")}),ue.length>0&&n.jsx("div",{className:"mt-2 flex flex-wrap gap-1.5",children:ue.map(ae=>{const Ye=Object.values(F).flat().find(dt=>dt.id===ae);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:[Ye?Ye.title.slice(0,30):ae.slice(-8),n.jsx("button",{onClick:()=>fe(ue.filter(dt=>dt!==ae)),className:"ml-0.5 text-amber-600/60 hover:text-amber-600",children:"×"})]},ae)})})]}),de&&n.jsx("div",{className:"px-3 py-2 bg-red-500/15 text-red-500 text-xs rounded-lg",children:de}),n.jsxs("div",{className:"flex justify-end gap-3 pt-1",children:[n.jsx("button",{onClick:()=>{X(!1),Ce("")},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:()=>{Ms()},disabled:!me.trim()||!Pe||!Xe,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")})]})]})}),Sn&&n.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 p-3",onClick:()=>{Cn(!1),Mr(""),Ne(""),xe("")},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:ae=>ae.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(ku,{options:N.map(ae=>({value:ae.id,label:ae.name})),value:rn,onChange:Jt,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:$r,onChange:ae=>Mr(ae.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:ae=>{ae.key==="Enter"&&$r.trim()&&Kn()}})]}),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:hn,onChange:ae=>Ne(ae.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:At,onChange:ae=>Vt(ae.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")})]})]}),kr&&n.jsx("div",{className:"px-3 py-2 bg-red-500/15 text-red-500 text-xs rounded-lg",children:kr}),n.jsxs("div",{className:"flex justify-end gap-3 pt-1",children:[n.jsx("button",{onClick:()=>{Cn(!1),Mr(""),Ne(""),xe("")},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:()=>{Kn()},disabled:!$r.trim()||!hn.trim()||!rn,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")})]})]})}),Ot&&n.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 p-3",onClick:()=>{Fn(null),xt("")},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:ae=>ae.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:$n,onChange:ae=>js(ae.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})]}),Qe&&n.jsx("div",{className:"px-3 py-2 bg-red-500/15 text-red-500 text-xs rounded-lg",children:Qe}),n.jsxs("div",{className:"flex justify-end gap-3",children:[n.jsx("button",{onClick:()=>{Fn(null),xt("")},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:()=>{Ds()},className:"px-4 py-2 text-sm bg-red-600 hover:bg-red-500 rounded-lg text-white",children:s("work:task.reject")})]})]})}),Ft&&n.jsxs("div",{className:"fixed inset-0 z-[60] flex flex-col justify-end",onClick:()=>lr(!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:ae=>ae.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:[(lt.size>0||ut.size>0||ft)&&n.jsx("button",{onClick:()=>{$e(new Set),nt(new Set),Rt(!1)},className:"text-[11px] text-brand-500 font-medium",children:s("work:task.clearAll")}),n.jsx("button",{onClick:()=>lr(!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:To.map(ae=>{const Ye=lt.has(ae.id),dt=ui[ae.id]??0;return n.jsxs("div",{className:`flex items-center rounded-lg overflow-hidden transition-all ${Ye?"bg-brand-500/15 ring-1 ring-brand-500/30":""}`,children:[n.jsxs("button",{onClick:()=>Cr(ae.id),className:`flex items-center gap-1.5 px-2.5 py-1.5 text-[11px] transition-all ${Ye?"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 ${Ye?"bg-brand-600 text-white":"bg-surface-overlay text-fg-tertiary"}`,children:ae.name[0]?.toUpperCase()}),ae.name,dt>0&&n.jsx("span",{className:"text-[9px] text-fg-tertiary",children:dt})]}),Ye&&n.jsx("button",{onClick:()=>{lr(!1),rr(ae.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"})]})})]},ae.id)})})]}),e?.id&&n.jsx("div",{className:"px-4 py-3 border-t border-border-default/40",children:n.jsx("button",{type:"button",onClick:()=>Rt(ae=>!ae),className:`w-full text-left px-2.5 py-1.5 rounded-lg text-[11px] transition-all ${ft?"bg-green-600/20 text-green-500 ring-1 ring-green-500/40":"bg-surface-elevated text-fg-secondary"}`,children:s("work:task.myTasks")})}),L.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:Ga.map(ae=>{const Ye=ut.has(ae.id);return n.jsxs("button",{onClick:()=>Xr(ae.id),className:`flex items-center gap-1.5 px-2.5 py-1.5 rounded-lg text-[11px] transition-all ${Ye?"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 ${Ye?"bg-brand-600 text-white":"bg-surface-overlay text-fg-tertiary"}`,children:ae.name[0]?.toUpperCase()}),ae.name]},ae.id)})})]}),n.jsx("div",{className:"h-[env(safe-area-inset-bottom,0px)]"})]})]})]})}function Vne({requirementId:e,createdBy:t,agents:r,users:s,authUser:a}){const{t:i}=kt(["work","common"]),[l,d]=b.useState([]),[u,m]=b.useState([]),p=b.useRef(null),[h,y]=b.useState(new Map);b.useEffect(()=>{m([]),y(new Map),p.current&&(clearTimeout(p.current),p.current=null),le.requirements.getComments(e).then(k=>d(k.comments)).catch(()=>{})},[e]),b.useEffect(()=>gn.on("requirement:comment",N=>{if(N.payload?.requirementId===e&&N.payload.comment){const j=N.payload.comment;d(T=>T.some(R=>R.id===j.id)?T:[...T,j]),(j.authorType==="agent"||j.authorId?.startsWith("agt_"))&&(m(T=>{const R=T.filter(M=>M.id!==j.authorId);return R.length===0&&p.current&&(clearTimeout(p.current),p.current=null),R}),y(T=>{const R=new Map(T);return R.delete(j.authorId),R}))}}),[e]),b.useEffect(()=>{if(u.length===0)return;const k=new Set(u.map(j=>j.id));return gn.on("agent:activity_log",j=>{const T=j.payload;if(!T)return;const R=T.agentId;if(!k.has(R))return;const M=T.type;if(M==="tool_start"||M==="tool_end"){const F={tool:T.content??T.metadata?.tool??"",phase:M==="tool_start"?"start":"end",success:M==="tool_end"?T.metadata?.success!==!1:void 0,ts:Date.now()};y(z=>{const L=new Map(z),U=[...L.get(R)??[],F];return L.set(R,U),L})}})},[u]);const[g,v]=b.useState(null),S=async(k,N,j,T)=>{let R;j.length>0&&(R=(await le.uploads.upload(j.map(L=>({dataUrl:L.dataUrl,name:L.name})),"comments")).files.map(L=>({type:"image",url:L.url,name:L.name}))),await le.requirements.addComment(e,k,a?.name,R,a?.id,N.length>0?N:void 0,T);const M=[],_=new Set,F=z=>{if(_.has(z)||z===a?.id)return;_.add(z);const L=r.find(U=>U.id===z);L&&M.push({id:L.id,name:L.name,avatarUrl:L.avatarUrl})};for(const z of N){const L=r.find(U=>U.name.toLowerCase()===z.toLowerCase());L&&F(L.id)}t?.startsWith("agt_")&&F(t),M.length>0&&(p.current&&clearTimeout(p.current),m(M),p.current=setTimeout(()=>m([]),12e4))},C=b.useCallback(k=>{v({id:k.id,authorName:k.authorName,content:k.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(k=>n.jsx($u,{comment:k,agents:r,onReply:C},k.id)),u.length>0&&n.jsx("div",{className:"flex flex-col gap-1.5 pt-1",children:u.map(k=>{const N=h.get(k.id)??[];return n.jsxs("div",{className:"px-2 py-1.5 rounded-lg cursor-pointer hover:bg-surface-elevated/60 transition-colors",onClick:()=>Nt.navigate(Se.TEAM,{agentId:k.id,profileTab:"mind"}),children:[n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsxs("div",{className:"relative shrink-0",children:[n.jsx(gr,{name:k.name,avatarUrl:k.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:k.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(Ch,{activities:N,isActive:!0})})]},k.id)})})]}),n.jsx(wS,{agents:r,humans:s,onSubmit:S,replyTo:g,onCancelReply:()=>v(null)})]})}function vj({req:e,agents:t,projects:r,allTasks:s,users:a,onClose:i,onApprove:l,onReject:d,onCancel:u,onStatusChange:m,onRefresh:p,authUser:h,scrollToComments:y,onScrollToCommentsDone:g,onTaskClick:v,onCreateTask:S,onProjectClick:C,previewMode:k}){const{t:N}=kt(["work","common"]),j=b.useMemo(()=>hy(N),[N]),T=b.useMemo(()=>T7(N),[N]),R=ks(),[M,_]=b.useState(!1),[F,z]=b.useState(e.description),[L,U]=b.useState(!1),[K,q]=b.useState(!1),I=b.useRef(null),[D,E]=b.useState("none"),$=b.useRef(null),Y=b.useRef(null),W=b.useRef(80);b.useEffect(()=>{const X=I.current;if(!X)return;const me=()=>{const{scrollTop:Re,scrollHeight:Ee,clientHeight:we}=X;if(!(Ee>we+50)){E("none");return}const Pe=Re<30,Ae=Re+we>=Ee-30;E(Pe?"top":Ae?"bottom":"middle")};me(),X.addEventListener("scroll",me,{passive:!0});const je=new ResizeObserver(me);return je.observe(X),()=>{X.removeEventListener("scroll",me),je.disconnect()}},[]),b.useEffect(()=>{if(M&&Y.current){const X=Y.current;X.style.height="auto",X.style.height=Math.max(X.scrollHeight,W.current)+"px",X.focus()}},[M]),b.useEffect(()=>{if(!y)return;const X=setTimeout(()=>{const me=I.current;me&&me.scrollTo({top:me.scrollHeight,behavior:"smooth"}),g?.()},300);return()=>clearTimeout(X)},[y,g]);const O=j[e.status]??{label:e.status,cls:"bg-gray-500/15 text-fg-secondary"},H=e.source==="agent",Z=H&&e.status==="pending",B=e.status==="pending"||e.status==="in_progress",J=e.status==="completed"||e.status==="rejected"||e.status==="cancelled"||e.status==="archived",Q=e.projectId?r.find(X=>X.id===e.projectId):null,ee=xd(e.createdBy,t,a)??e.createdBy.slice(0,12),se=s.filter(X=>e.taskIds.includes(X.id));return b.useEffect(()=>{z(e.description),_(!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:[R&&n.jsx("button",{onClick:i,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 ${O.cls}`,children:O.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:I,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")}),M?n.jsx("textarea",{ref:Y,value:F,onChange:X=>{z(X.target.value);const me=X.target;me.style.height="auto",me.style.height=me.scrollHeight+"px"},onBlur:async()=>{if(F!==e.description){U(!0);try{await le.requirements.update(e.id,{description:F}),p?.()}catch{}finally{U(!1)}}_(!1)},onKeyDown:X=>{X.key==="Escape"&&(X.preventDefault(),z(e.description),_(!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:()=>{W.current=Math.max($.current?.offsetHeight??80,60),z(e.description),_(!0)},role:J?void 0:"button",tabIndex:J?void 0:0,onKeyDown:J?void 0:X=>X.key==="Enter"&&(z(e.description),_(!0)),children:e.description?n.jsx(Ur,{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}),H&&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()})]}),Q&&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(Q.id):void 0,role:C?"button":void 0,tabIndex:C?0:void 0,onKeyDown:C?X=>X.key==="Enter"&&C(Q.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:Q.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:xd(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(X=>n.jsxs("span",{className:"text-[10px] bg-surface-elevated text-fg-secondary px-2 py-0.5 rounded-full",children:["#",X]},X))}),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:se.length})}),!J&&S&&n.jsxs("button",{onClick:()=>S(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")]})]}),se.length>0?(()=>{const X=new Map(se.map(pe=>[pe.id,pe]));if(!se.some(pe=>pe.blockedBy?.some(Pe=>X.has(Pe))))return n.jsx("div",{className:"space-y-1.5",children:se.map(pe=>{const Pe=T[pe.status];return n.jsxs("div",{onClick:()=>v?.(pe),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 ${l0[pe.status]??"bg-gray-500"}`}),n.jsx("span",{className:"text-xs text-fg-secondary flex-1 truncate",children:pe.title}),Pe&&n.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded shrink-0 ${Pe.cls}`,children:Pe.label})]},pe.id)})});const je=new Map,Re=new Set;for(const pe of se)for(const Pe of pe.blockedBy??[])if(X.has(Pe)){Re.add(pe.id);const Ae=je.get(Pe)??[];Ae.push(pe.id),je.set(Pe,Ae)}const Ee=se.filter(pe=>!Re.has(pe.id)),we=(pe,Pe)=>{const Ae=T[pe.status],Xe=(je.get(pe.id)??[]).map(Ze=>X.get(Ze)).filter(Boolean);return n.jsxs("div",{children:[n.jsxs("div",{onClick:()=>v?.(pe),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:Pe>0?{marginLeft:Pe*20}:void 0,children:[Pe>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 ${l0[pe.status]??"bg-gray-500"}`}),n.jsx("span",{className:"text-xs text-fg-secondary flex-1 truncate",children:pe.title}),Ae&&n.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded shrink-0 ${Ae.cls}`,children:Ae.label})]}),Xe.map(Ze=>we(Ze,Pe+1))]},pe.id)};return n.jsx("div",{className:"space-y-1.5",children:Ee.map(pe=>we(pe,0))})})():n.jsx("div",{className:"text-xs text-fg-tertiary italic py-2",children:N("work:requirement.noLinkedTasks")})]}),!k&&n.jsx(Vne,{requirementId:e.id,createdBy:e.createdBy,agents:t,users:a,authUser:h}),!k&&n.jsx(M7,{entityType:"requirement",entityId:e.id})]}),D!=="none"&&D!=="top"&&n.jsx("button",{onClick:()=>I.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"})})}),D!=="none"&&D!=="bottom"&&n.jsx("button",{onClick:()=>{const X=I.current;X&&X.scrollTo({top:X.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:X=>{X.target.value!==e.status&&m(e.id,X.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:Fne.map(X=>{const me=j[X],je=X===e.status||(e1[e.status]?.has(X)??!1);return n.jsx("option",{value:X,disabled:!je,children:me?.label??X},X)})}),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"}),B&&!Z&&n.jsx("button",{onClick:()=>q(!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")})]}),K&&n.jsx(Yc,{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:()=>{q(!1),u(e.id)},onCancel:()=>q(!1)})]})}function M7({entityType:e,entityId:t}){const{t:r}=kt(["work"]),[s,a]=b.useState([]),[i,l]=b.useState(!0),[d,u]=b.useState(!1);if(b.useEffect(()=>{l(!0),(e==="task"?le.tasks.getHistory:le.requirements.getHistory)(t).then(g=>a(g.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),p=s.length>5&&!d,h=y=>{const g=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:g})};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")}),p&&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:[h(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 Di(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 Wne(e){return e.files&&typeof e.files=="object"&&!Array.isArray(e.files)?e.files:null}function Hl({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 Fc({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 Ux({files:e}){const{t}=kt(["builder","common"]),[r,s]=b.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 Kne({artifact:e,mode:t}){const{t:r}=kt(["builder","common"]),s=Wne(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,p=a?.llmProvider,h=a?.llmModel,y=Di(l?.env),g=Di(l?.skills);return n.jsxs("div",{className:"space-y-3 text-sm",children:[n.jsx(Hl,{label:r("builder:artifact.name"),value:d}),n.jsx(Hl,{label:r("builder:artifact.description"),value:e.description}),n.jsxs("div",{className:"flex flex-wrap gap-2",children:[u&&n.jsx(Fc,{label:r("builder:artifact.baseTemplate"),value:u,color:"indigo"}),n.jsx(Fc,{label:r("builder:artifact.agentRole"),value:m,color:m==="manager"?"purple":"cyan"})]}),Di(e.tags).length>0&&n.jsx("div",{className:"flex flex-wrap gap-1",children:Di(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))}),(p||h)&&n.jsxs("div",{className:"flex gap-2",children:[p&&n.jsx(Fc,{label:r("builder:artifact.llmProvider"),value:p,color:"gray"}),h&&n.jsx(Fc,{label:r("builder:artifact.llmModel"),value:h,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))})]}),g.length>0&&n.jsx(Hl,{label:r("builder:artifact.skills"),value:g.join(", ")}),s&&n.jsx(Ux,{files:s})]})}if(t==="team"){const m=i?.members??[];return n.jsxs("div",{className:"space-y-3 text-sm",children:[n.jsx(Hl,{label:r("builder:artifact.name"),value:d}),n.jsx(Hl,{label:r("builder:artifact.description"),value:e.description}),n.jsx("div",{className:"flex flex-wrap gap-2",children:n.jsx(Fc,{label:r("builder:artifact.category"),value:e.category,color:"indigo"})}),Di(e.tags).length>0&&n.jsx("div",{className:"flex flex-wrap gap-1",children:Di(e.tags).map(p=>n.jsx("span",{className:"px-1.5 py-0.5 text-[10px] bg-surface-elevated text-fg-tertiary rounded",children:p},p))}),s&&n.jsx(Ux,{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((p,h)=>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 ${p.role==="manager"?"bg-brand-500/20 text-brand-500":"bg-blue-500/20 text-blue-600"}`,children:p.role==="manager"?"★":h+1}),n.jsx("span",{className:"text-xs text-fg-secondary flex-1 truncate",children:p.name}),typeof p.roleName=="string"&&p.roleName&&n.jsx("span",{className:"text-[10px] text-brand-500/70 font-mono",children:p.roleName}),n.jsxs("span",{className:"text-[10px] text-fg-tertiary",children:["x",String(p.count??1)]})]}),Di(p.skills).length>0&&n.jsx("div",{className:"mt-1 ml-7 flex flex-wrap gap-1",children:Di(p.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))})]},h))})]})]})}return n.jsxs("div",{className:"space-y-3 text-sm",children:[n.jsx(Hl,{label:r("builder:artifact.name"),value:d}),n.jsx(Hl,{label:r("builder:artifact.description"),value:e.description}),n.jsx("div",{className:"flex gap-2",children:n.jsx(Fc,{label:r("builder:artifact.category"),value:e.category,color:"indigo"})}),s&&n.jsx(Ux,{files:s}),Di(e.tags).length>0&&n.jsx("div",{className:"flex flex-wrap gap-1",children:Di(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 ju={file:{icon:"📄",color:"bg-green-500/10 text-green-600"},directory:{icon:"📁",color:"bg-blue-500/10 text-blue-600"}},Gne={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"}},Yne=["file","directory"];function df(e){return/^https?:\/\//i.test(e)}const Fl={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 wj({authUser:e,previewMode:t,previewData:r}={}){const{t:s}=kt(["deliverables","common"]),a=ks(),i=bd(Se.DELIVERABLES),l=Zu({side:"left",defaultWidth:384,minWidth:280,maxWidth:600,storageKey:"markus_deliverables_list"}),[d,u]=b.useState(!1),m=b.useRef(d);m.current=d,b.useEffect(()=>{if(!a)return;const Ue=()=>{m.current&&u(!1)};return window.addEventListener("popstate",Ue),()=>window.removeEventListener("popstate",Ue)},[a]);const p=100,[h,y]=b.useState(r?.items??[]),[g,v]=b.useState(r?.items?.length??0),[S,C]=b.useState(!1),[k,N]=b.useState(r?.projects??[]),[j,T]=b.useState(r?.agents??[]),[R,M]=b.useState(!r),[_,F]=b.useState(""),[z,L]=b.useState(""),[U,K]=b.useState(""),[q,I]=b.useState(""),[D,E]=b.useState(""),[$,Y]=b.useState(""),[W,O]=b.useState(""),[H,Z]=b.useState("date"),[B,J]=b.useState(()=>r?.initialSelectedId&&r.items?r.items.find(Ue=>Ue.id===r.initialSelectedId)??r.items[0]??null:r?.items?.[0]??null),[Q,ee]=b.useState(null),[se,X]=b.useState(""),[me,je]=b.useState(new Set),Re=b.useMemo(()=>[{id:"date"},{id:"project"},{id:"agent"},{id:"type"}],[]),Ee=b.useCallback(Ue=>{Z(Ue),je(new Set)},[]),we=hl(Re,H,Ee),pe=b.useRef(null),[Pe,Ae]=b.useState(null),[Xe,Ze]=b.useState("markdown"),[at,pt]=b.useState(null),[Ct,_e]=b.useState(!1),[ue,fe]=b.useState(!1),[Me,ne]=b.useState(!1),[he,Be]=b.useState(null),[de,Ce]=b.useState(""),[et,it]=b.useState(new Set),Ve=b.useRef(void 0),Ge=(Ue,Lt)=>{ee({type:Ue,text:Lt}),setTimeout(()=>ee(null),3e3)},ut=async Ue=>{await H1(Ue)?(ne(!0),setTimeout(()=>ne(!1),1500)):Ge("error",s("detail.copyFailed"))},nt=b.useMemo(()=>new Map(j.map(Ue=>[Ue.id,Ue])),[j]),ft=b.useMemo(()=>new Map(k.map(Ue=>[Ue.id,Ue])),[k]),Rt=b.useCallback(Ue=>{if(!Ue||Ue==="default")return null;const Lt=ft.get(Ue)?.name;return!Lt||Lt==="default"?null:Lt},[ft]);b.useEffect(()=>{t||(le.projects.list().then(Ue=>N(Ue.projects)).catch(()=>{}),le.agents.list().then(Ue=>T(Ue.agents??[])).catch(()=>{}),le.system.storage().then(Ue=>Ce(Ue.dataDir+"/shared")).catch(()=>{}),le.deliverables.checkHealth().then(Ue=>it(new Set(Ue.missingFiles))).catch(()=>{}))},[t]),b.useEffect(()=>(Ve.current=setTimeout(()=>L(_),300),()=>clearTimeout(Ve.current)),[_]);const lt=b.useMemo(()=>({q:z||void 0,projectId:q||void 0,agentId:D||void 0,type:U||void 0,status:$||void 0,artifactType:W||void 0}),[z,q,D,U,$,W]),$e=b.useCallback(async()=>{M(!0);try{const{results:Ue,total:Lt}=await le.deliverables.search({...lt,offset:0,limit:p});y(Ue),v(Lt)}catch{y([]),v(0)}M(!1)},[lt]),ct=b.useCallback(async()=>{if(!(S||h.length>=g)){C(!0);try{const{results:Ue,total:Lt}=await le.deliverables.search({...lt,offset:h.length,limit:p});y(Zt=>[...Zt,...Ue]),v(Lt)}catch{}C(!1)}},[lt,h.length,g,S]);b.useEffect(()=>{t||$e()},[$e,t]),b.useEffect(()=>{!t||!r||(y(r.items??[]),v(r.items?.length??0),N(r.projects??[]),T(r.agents??[]),r.initialSelectedId&&J(r.items?.find(Ue=>Ue.id===r.initialSelectedId)??r.items?.[0]??null))},[t,r]),b.useEffect(()=>{if(t||!i)return;const Ue=gn.on("deliverable:created",()=>$e()),Lt=gn.on("deliverable:updated",()=>$e()),Zt=gn.on("deliverable:removed",()=>$e());return()=>{Ue(),Lt(),Zt()}},[$e,i,t]);const Ut=b.useRef(null),zt=b.useRef(h);zt.current=h;const cn=b.useCallback(Ue=>{const Lt=Ft=>{J(Ft),a&&(u(!0),history.pushState({mobileDetail:Se.DELIVERABLES},"",window.location.hash))},Zt=zt.current.find(Ft=>Ft.id===Ue);if(Zt){Lt(Zt);return}le.deliverables.get(Ue).then(Ft=>{Ft.deliverable&&Lt(Ft.deliverable)}).catch(()=>{})},[a]);b.useEffect(()=>{if(t)return;const Ue=localStorage.getItem("markus_nav_openDeliverable");Ue&&(localStorage.removeItem("markus_nav_openDeliverable"),zt.current.length>0?cn(Ue):Ut.current=Ue);const Lt=Zt=>{const Ft=Zt.detail;Ft?.params?.openDeliverable&&(localStorage.removeItem("markus_nav_openDeliverable"),cn(Ft.params.openDeliverable))};return window.addEventListener("markus:navigate",Lt),()=>window.removeEventListener("markus:navigate",Lt)},[cn,t]),b.useEffect(()=>{const Ue=Ut.current;!Ue||h.length===0||(Ut.current=null,cn(Ue))},[h,cn]);const Ln=b.useCallback(()=>{const Ue=pe.current;!Ue||R||S||h.length>=g||Ue.scrollHeight<=Ue.clientHeight+100&&ct()},[R,S,h.length,g,ct]);b.useEffect(()=>{const Ue=pe.current;if(!Ue)return;const Lt=()=>{Ue.scrollTop+Ue.clientHeight>=Ue.scrollHeight-100&&ct()};return Ue.addEventListener("scroll",Lt,{passive:!0}),()=>Ue.removeEventListener("scroll",Lt)},[ct]),b.useEffect(()=>{Ln()},[Ln,me]);const Xt=b.useMemo(()=>{const Ue=new Map;for(const Zt of h){let Ft,lr;if(H==="project"){const _n=Rt(Zt.projectId);Ft=_n?Zt.projectId??"_none":"_none",lr=_n??s("noProject")}else if(H==="agent")Ft=Zt.agentId??"_none",lr=Zt.agentId?nt.get(Zt.agentId)?.name??Zt.agentId:s("common:unknown");else if(H==="type")Ft=Zt.type,lr=Zt.type.charAt(0).toUpperCase()+Zt.type.slice(1);else{const _n=new Date(Zt.updatedAt);Ft=`${_n.getFullYear()}-${String(_n.getMonth()+1).padStart(2,"0")}-${String(_n.getDate()).padStart(2,"0")}`,lr=Ft}Ue.has(Ft)||Ue.set(Ft,{label:lr,items:[]}),Ue.get(Ft).items.push(Zt)}const Lt=[...Ue.entries()];return H==="date"?Lt.sort((Zt,Ft)=>Ft[0].localeCompare(Zt[0])):Lt.sort((Zt,Ft)=>Zt[1].label.localeCompare(Ft[1].label)),Lt},[h,H,ft,nt,s]),kn=async Ue=>{X("remove");try{await le.deliverables.remove(Ue.id),Ge("success",s("removed")),J(null),$e()}catch(Lt){Ge("error",s("common:error",{message:String(Lt)}))}X("")},tr=()=>{Nt.navigate(Se.BUILDER)},ir=async Ue=>{if(Ue.reference&&!df(Ue.reference)){if(Ue.type==="directory"){fe(!0);return}_e(!0);try{const Lt=await le.files.preview(Ue.reference);Lt.type==="image"&&Lt.mimeType?pt({src:`data:${Lt.mimeType};base64,${Lt.content}`,name:Lt.name}):(Ae(Lt.content),Ze(OS({format:Ue.format,reference:Ue.reference,content:Lt.content})))}catch{Ae(null),Ue.type==="file"&&fe(!0)}_e(!1)}};b.useEffect(()=>{t||(Ae(null),Ze("markdown"),pt(null),fe(!1),B&&ir(B))},[B?.id,t]);const gs=b.useCallback(Ue=>{je(Lt=>{const Zt=new Set(Lt);return Zt.has(Ue)?Zt.delete(Ue):Zt.add(Ue),Zt})},[]),wr=b.useCallback(()=>{me.size===Xt.length?je(new Set):je(new Set(Xt.map(([Ue])=>Ue)))},[me.size,Xt]),or=Ue=>{J(Ue),a&&(u(!0),history.pushState({mobileDetail:Se.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(sc,{}),n.jsxs("h2",{className:"text-sm font-semibold text-fg-secondary truncate",children:[s("title"),g>0&&n.jsxs("span",{className:"ml-1.5 text-fg-tertiary font-normal",children:["(",g,")"]})]})]})}),n.jsx("input",{value:_,onChange:Ue=>F(Ue.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"}),de&&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:de}),n.jsx("button",{onClick:()=>{le.system.openPath(de)},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(Nu,{label:s("filters.allTypes"),value:"",current:U||W||"",onClick:()=>{K(""),O("")}}),Yne.map(Ue=>n.jsx(Nu,{label:`${ju[Ue]?.icon??""} ${Ue}`,value:Ue,current:U,onClick:Lt=>{K(Lt),O("")}},Ue)),["agent","team","skill"].map(Ue=>n.jsx(Nu,{label:`${Fl[Ue].icon} ${s(`artifactTypes.${Ue}`)}`,value:Ue,current:W,onClick:Lt=>{O(Lt),K("")}},Ue))]}),k.length>0&&n.jsxs("div",{className:"flex gap-1 overflow-x-auto scrollbar-hide",children:[n.jsx(Nu,{label:s("filters.allProjects"),value:"",current:q,onClick:I}),k.map(Ue=>n.jsx(Nu,{label:Ue.name,value:Ue.id,current:q,onClick:I},Ue.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(Ue=>n.jsx("button",{onClick:()=>{Z(Ue),je(new Set)},className:`px-2 py-1 rounded text-xs transition-colors ${H===Ue?"bg-brand-600 text-white":"bg-surface-elevated text-fg-secondary hover:bg-surface-overlay"}`,children:s(`groupBy.${Ue}`)},Ue)),Xt.length>1&&n.jsx("button",{onClick:wr,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:me.size===Xt.length?s("expandAllTooltip"):s("collapseAllTooltip"),children:me.size===Xt.length?s("expandAll"):s("collapseAll")})]})]}),Q&&n.jsx("div",{className:`mx-4 mt-2 px-3 py-1.5 text-xs rounded-lg ${Q.type==="success"?"bg-green-500/15 text-green-600":"bg-red-500/15 text-red-500"}`,children:Q.text}),n.jsxs("div",{ref:pe,className:"flex-1 overflow-y-auto p-2 space-y-1",onTouchStart:a?we.onTouchStart:void 0,onTouchEnd:a?we.onTouchEnd:void 0,children:[R?n.jsx("div",{className:"p-4 space-y-3",children:[1,2,3].map(Ue=>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"})]},Ue))}):h.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:()=>Nt.navigate(Se.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")})]}):Xt.map(([Ue,Lt])=>{const Zt=me.has(Ue);return n.jsxs("div",{children:[n.jsxs("button",{onClick:()=>gs(Ue),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 ${Zt?"":"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:Lt.label}),n.jsxs("span",{className:"text-[10px] text-fg-tertiary shrink-0",children:["(",Lt.items.length,")"]})]}),!Zt&&Lt.items.map(Ft=>n.jsx("button",{onClick:()=>or(Ft),className:`w-full text-left px-3 py-2 rounded-lg transition-colors ${B?.id===Ft.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:[Ft.artifactType&&Fl[Ft.artifactType]?n.jsx("span",{className:`text-[10px] px-1 py-0.5 rounded font-medium shrink-0 ${Fl[Ft.artifactType].color}`,children:Fl[Ft.artifactType].icon}):n.jsx("span",{className:`text-[10px] px-1 py-0.5 rounded font-medium uppercase shrink-0 ${ju[Ft.type]?.color??"bg-surface-overlay text-fg-secondary"}`,children:ju[Ft.type]?.icon??Ft.type.charAt(0)}),n.jsx("span",{className:"text-sm font-medium text-fg-primary truncate",children:Ft.title}),et.has(Ft.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 ${Gne[Ft.status]?.color??"bg-surface-elevated text-fg-tertiary"}`,children:s(`common:status.${Ft.status}`,{defaultValue:Ft.status})})]})},Ft.id))]},Ue)}),S&&n.jsxs("div",{className:"flex items-center justify-center gap-2 py-3 text-fg-tertiary",children:[n.jsx(kj,{})," ",n.jsx("span",{className:"text-[10px]",children:s("common:loadingMore")})]}),!R&&h.length>0&&n.jsx("div",{className:"text-center text-[10px] text-fg-tertiary py-2",children:h.length<g?s("count.partial",{loaded:h.length,total:g}):s("count.total",{total:g})})]})]}),!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:B?.title??s("detail.details")})]}),B?n.jsxs("div",{className:"p-6 space-y-4",children:[!t&&et.has(B.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:B.title}),!t&&n.jsx("button",{onClick:()=>Be(B),disabled:!!se,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 ${ju[B.type]?.color??"bg-surface-overlay text-fg-secondary"}`,children:[ju[B.type]?.icon??""," ",B.type]}),B.artifactType&&Fl[B.artifactType]&&n.jsxs("span",{className:`px-2 py-0.5 rounded text-xs font-medium ${Fl[B.artifactType].color}`,children:[Fl[B.artifactType].icon," ",s("detail.builderWithType",{type:s(`artifactTypes.${B.artifactType}`)})]}),B.tags.length>0&&B.tags.map(Ue=>n.jsx("span",{className:"px-2 py-0.5 text-xs bg-surface-elevated text-fg-secondary rounded",children:Ue},Ue))]}),(B.taskId||B.agentId||Rt(B.projectId))&&n.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[B.taskId&&n.jsx("button",{onClick:()=>Nt.navigate(Se.WORK,{openTask:B.taskId}),className:"text-xs text-brand-500 hover:underline bg-brand-500/10 px-2 py-0.5 rounded",children:s("links.task",{id:`${B.taskId.slice(0,12)}...`})}),B.agentId&&n.jsx("button",{onClick:()=>Nt.navigate(Se.TEAM,{selectAgent:B.agentId}),className:"text-xs text-blue-600 hover:underline bg-blue-500/10 px-2 py-0.5 rounded",children:s("links.agent",{name:nt.get(B.agentId)?.name??B.agentId.slice(0,12)})}),Rt(B.projectId)&&n.jsx("button",{onClick:()=>Nt.navigate(Se.WORK,{projectId:B.projectId}),className:"text-xs text-blue-600 hover:underline bg-blue-500/10 px-2 py-0.5 rounded",children:s("links.project",{name:Rt(B.projectId)})})]}),(B.diffStats||B.testResults)&&n.jsxs("div",{className:"flex gap-3 flex-wrap",children:[B.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:B.diffStats.filesChanged})}),n.jsxs("span",{className:"text-green-600",children:["+",B.diffStats.additions]}),n.jsxs("span",{className:"text-red-500",children:["-",B.diffStats.deletions]})]}),B.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:B.testResults.passed})}),n.jsx("span",{className:"text-red-500",children:s("testResults.failed",{count:B.testResults.failed})}),n.jsx("span",{className:"text-fg-secondary",children:s("testResults.skipped",{count:B.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(B.createdAt).toLocaleDateString()]}),n.jsxs("span",{children:[s("metadata.updated")," ",new Date(B.updatedAt).toLocaleDateString()]}),n.jsx("span",{className:"text-fg-muted select-all",children:B.id.slice(0,12)})]}),B.reference&&!df(B.reference)&&B.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:()=>{le.files.reveal(B.reference).catch(()=>Ge("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:B.reference}),n.jsx("button",{onClick:()=>{le.files.reveal(B.reference).catch(()=>Ge("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:()=>ut(B.reference),className:`px-2 py-1 text-[10px] rounded transition-colors shrink-0 ${Me?"bg-green-500/20 text-green-600":"bg-surface-overlay/50 text-fg-secondary hover:bg-surface-overlay"}`,title:s("detail.copyPath"),children:s(Me?"common:copied":"common:copy")})]}),B.reference&&!df(B.reference)&&B.type!=="file"&&B.type!=="directory"&&n.jsx("span",{className:"text-xs text-fg-tertiary font-mono break-all",children:B.reference})]}),B.artifactType&&B.artifactData?n.jsxs("div",{className:"space-y-4",children:[n.jsx("div",{className:"bg-surface-elevated rounded-xl p-5",children:n.jsx(Kne,{artifact:B.artifactData,mode:B.artifactType})}),B.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:B.reference})]}),n.jsx("div",{className:"flex gap-2",children:n.jsx("button",{onClick:tr,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")})}),B.summary&&n.jsx("div",{className:"bg-surface-elevated rounded-xl p-5",children:n.jsx(Ur,{content:B.summary,className:"text-fg-secondary text-sm"})})]}):B.reference&&df(B.reference)?n.jsxs("div",{className:"space-y-4",children:[B.summary&&n.jsx("div",{className:"bg-surface-elevated rounded-xl p-5",children:n.jsx(Ur,{content:B.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:B.reference}),n.jsx("button",{onClick:()=>window.open(B.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")})]})]}):B.type==="directory"&&B.reference?n.jsxs("div",{className:"space-y-4",children:[B.summary&&n.jsx("div",{className:"bg-surface-elevated rounded-xl p-5",children:n.jsx(Ur,{content:B.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:B.reference}),n.jsx("button",{onClick:()=>{le.files.reveal(B.reference).catch(()=>Ge("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:Ct?n.jsxs("div",{className:"flex items-center gap-2 text-fg-tertiary text-sm",children:[n.jsx(kj,{})," ",s("detail.loadingPreview")]}):at?n.jsxs("div",{className:"flex flex-col items-center gap-2",children:[n.jsx("img",{src:at.src,alt:at.name,className:"max-w-full max-h-[60vh] rounded-lg object-contain"}),n.jsx("span",{className:"text-xs text-fg-tertiary",children:at.name})]}):Pe?n.jsx(G1,{content:Pe,format:Xe,className:"text-fg-secondary text-sm"}):ue?n.jsxs("div",{className:"space-y-3",children:[n.jsx("p",{className:"text-sm text-fg-secondary",children:s("detail.cannotPreview",{type:B.type})}),n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx("button",{onClick:()=>{le.files.reveal(B.reference).catch(()=>Ge("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:B.reference}),n.jsx("button",{onClick:()=>{le.files.reveal(B.reference).catch(()=>Ge("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:()=>ut(B.reference),className:`px-3 py-2 text-xs rounded-lg transition-colors shrink-0 ${Me?"bg-green-500/20 text-green-600":"bg-surface-overlay/50 text-fg-secondary hover:bg-surface-overlay"}`,children:s(Me?"common:copied":"common:copy")})]})]}):B.summary?n.jsx(Ur,{content:B.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")})]})})]}),he&&n.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60",onClick:()=>Be(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:Ue=>Ue.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:he.title})})]})]}),n.jsxs("div",{className:"flex justify-end gap-2",children:[n.jsx("button",{onClick:()=>Be(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 Ue=he;Be(null),kn(Ue)},disabled:!!se,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 Nu({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 kj(){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 ho(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}K`:e.toLocaleString()}function Kc(e){return e<.01?`$${e.toFixed(4)}`:`$${e.toFixed(2)}`}function Xne(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 jj({authUser:e}){const{t}=kt(["reports","common"]),r=ks(),s=bd(Se.REPORTS),[a,i]=b.useState("weekly"),[l,d]=b.useState(null),[u,m]=b.useState(!0),[p,h]=b.useState(""),[y,g]=b.useState(null),[v,S]=b.useState([]),[C,k]=b.useState("totalTokens"),[N,j]=b.useState(!0),[T,R]=b.useState("generate"),[M,_]=b.useState([]),[F,z]=b.useState(null),[L,U]=b.useState([]),[K,q]=b.useState(""),[I,D]=b.useState(""),E=X=>{D(X),setTimeout(()=>D(""),3e3)},$=b.useCallback(async X=>{m(!0),h("");try{const{report:me}=await le.reports.generate({period:X,scope:"org",orgId:"default"});d(me)}catch(me){h(String(me)),d(null)}m(!1)},[]),Y=b.useCallback(()=>{le.usage.summary().then(X=>g(X.usage)).catch(()=>{}),le.usage.agents().then(X=>S(X.agents)).catch(()=>{})},[]),W=b.useCallback(async()=>{try{const{reports:X}=await le.reports.list();_(X)}catch{}},[]),O=b.useCallback(async X=>{z(X);try{const{feedback:me}=await le.reports.getFeedback(X.id);U(me)}catch{U([])}},[]);b.useEffect(()=>{$(a)},[a,$]),b.useEffect(()=>{if(!s)return;Y();const X=setInterval(Y,3e4);return()=>clearInterval(X)},[Y,s]),b.useEffect(()=>{T==="history"&&W()},[T,W]);const H=b.useMemo(()=>[...v].sort((X,me)=>{const je=X[C],Re=me[C];return N?Re-je:je-Re}),[v,C,N]),Z=v.reduce((X,me)=>X+me.estimatedCost,0),B=v.reduce((X,me)=>X+me.tokensUsedToday,0),J=v.reduce((X,me)=>X+(me.costToday??0),0),Q=Math.max(1,...v.map(X=>X.totalTokens)),ee=X=>{C===X?j(!N):(k(X),j(!0))},se=b.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(sc,{}),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:()=>R("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:()=>R("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"),M.length>0?` (${M.length})`:""]})]})]}),n.jsxs("div",{className:"flex items-center gap-3 flex-wrap",children:[I&&n.jsx("span",{className:"px-2.5 py-1 bg-green-500/10 text-green-600 text-xs rounded-lg",children:I}),T==="generate"&&n.jsx("div",{className:"flex gap-1 bg-surface-elevated rounded-lg p-0.5",children:["daily","weekly","monthly"].map(X=>n.jsx("button",{onClick:()=>i(X),className:`px-3 py-1.5 text-xs rounded-md transition-colors ${a===X?"bg-surface-overlay text-fg-primary shadow-sm":"text-fg-tertiary hover:text-fg-secondary"}`,children:t(`period.${X}`)},X))})]})]}),T==="history"&&!F&&n.jsx("section",{className:"bg-surface-elevated rounded-xl overflow-hidden",children:M.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:M.map(X=>n.jsxs("button",{onClick:()=>O(X),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:X.type})}),n.jsxs("div",{className:"text-xs text-fg-tertiary mt-0.5",children:[new Date(X.periodStart).toLocaleDateString()," — ",new Date(X.periodEnd).toLocaleDateString()]})]}),X.plan&&n.jsx("span",{className:`px-2 py-0.5 rounded-full text-[10px] font-medium shrink-0 ${X.plan.status==="approved"?"bg-green-500/10 text-green-600":X.plan.status==="rejected"?"bg-red-500/10 text-red-500":"bg-amber-500/10 text-amber-600"}`,children:X.plan.status==="pending"?t("upcomingPlan.planPending"):t("upcomingPlan.planStatus",{status:X.plan.status})}),n.jsx("span",{className:"text-[10px] text-fg-tertiary shrink-0",children:new Date(X.generatedAt).toLocaleDateString()})]},X.id))})}),T==="history"&&F&&n.jsxs(n.Fragment,{children:[n.jsxs("div",{className:"flex items-center gap-3",children:[n.jsx("button",{onClick:()=>{z(null),U([])},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:F.type})}),n.jsxs("span",{className:"text-xs text-fg-tertiary",children:[new Date(F.periodStart).toLocaleDateString()," — ",new Date(F.periodEnd).toLocaleDateString()]})]}),F.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(Ri,{label:t("taskMetrics.completed"),value:F.metrics.tasksCompleted,color:"text-green-600"}),n.jsx(Ri,{label:t("taskMetrics.inProgress"),value:F.metrics.tasksInProgress,color:"text-brand-500"}),n.jsx(Ri,{label:t("taskMetrics.created"),value:F.metrics.tasksCreated,color:"text-blue-600"}),n.jsx(Ri,{label:t("taskMetrics.blocked"),value:F.metrics.tasksBlocked,color:"text-amber-600"}),n.jsx(Ri,{label:t("taskMetrics.failed"),value:F.metrics.tasksFailed,color:"text-red-500"})]})]}),F.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:F.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:Kc(F.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 ${F.costSummary.trend==="decreasing"?"text-green-600":F.costSummary.trend==="increasing"?"text-red-500":"text-fg-primary"}`,children:[F.costSummary.trend==="decreasing"?"↓":F.costSummary.trend==="increasing"?"↑":"→"," ",F.costSummary.trend]}),n.jsx("div",{className:"text-xs text-fg-tertiary",children:t("costOverview.trend")})]})]}),F.costSummary.byAgent&&F.costSummary.byAgent.length>0&&n.jsx("div",{className:"mt-4 pt-3 border-t border-border-default/50 space-y-1.5",children:F.costSummary.byAgent.map((X,me)=>n.jsxs("div",{className:"flex items-center justify-between text-xs",children:[n.jsx("span",{className:"text-fg-secondary",children:X.agentId}),n.jsx("span",{className:"text-fg-tertiary tabular-nums",children:t("costOverview.byAgentRow",{tokens:ho(X.tokens),cost:Kc(X.cost)})})]},me))})]}),F.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:[F.taskSummary.completed.length>0&&n.jsx(qc,{title:t("taskSummary.completedCount",{count:F.taskSummary.completed.length}),color:"emerald",items:F.taskSummary.completed.map(X=>({id:X.id,label:X.title,sub:X.agent}))}),F.taskSummary.inProgress.length>0&&n.jsx(qc,{title:t("taskSummary.inProgressCount",{count:F.taskSummary.inProgress.length}),color:"indigo",items:F.taskSummary.inProgress.map(X=>({id:X.id,label:X.title,sub:X.agent}))}),F.taskSummary.blocked.length>0&&n.jsx(qc,{title:t("taskSummary.blockedCount",{count:F.taskSummary.blocked.length}),color:"amber",items:F.taskSummary.blocked.map(X=>({id:X.id,label:X.title,sub:X.reason||X.agent}))}),F.taskSummary.completed.length===0&&F.taskSummary.inProgress.length===0&&F.taskSummary.blocked.length===0&&n.jsx("p",{className:"text-sm text-fg-tertiary",children:t("taskSummary.noTasksInPeriod")})]})]}),F.highlights&&F.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:F.highlights.map((X,me)=>n.jsx("li",{children:X},me))})]}),F.blockers&&F.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:F.blockers.map((X,me)=>n.jsx("li",{children:X},me))})]}),F.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 ${F.plan.status==="approved"?"bg-green-500/10 text-green-600":F.plan.status==="rejected"?"bg-red-500/10 text-red-500":"bg-amber-500/10 text-amber-600"}`,children:t(`common:status.${F.plan.status}`,{defaultValue:F.plan.status})})]}),F.plan.status==="pending"&&n.jsxs("div",{className:"flex gap-2",children:[n.jsx("button",{onClick:async()=>{try{const{report:X}=await le.reports.approvePlan(F.id,{approvedBy:e?.id??"unknown"});z(X),E(t("upcomingPlan.planApproved")),W()}catch(X){E(t("common:error",{message:String(X)}))}},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 X=prompt(t("upcomingPlan.rejectionReason"));if(X)try{const{report:me}=await le.reports.rejectPlan(F.id,{rejectedBy:e?.id??"unknown",reason:X});z(me),E(t("upcomingPlan.planRejected")),W()}catch(me){E(t("common:error",{message:String(me)}))}},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")})]})]}),F.plan.items&&F.plan.items.length>0&&n.jsx("div",{className:"space-y-1.5",children:F.plan.items.map((X,me)=>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 ${X.priority==="high"?"bg-red-500/10 text-red-500":X.priority==="medium"?"bg-amber-500/10 text-amber-600":"bg-gray-500/10 text-fg-tertiary"}`,children:X.priority}),n.jsx("span",{children:X.title}),X.assignee&&n.jsx("span",{className:"text-[10px] text-fg-tertiary ml-auto",children:X.assignee})]},me))})]}),!F.metrics&&!F.taskSummary&&!F.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:L.length})}),L.length>0&&n.jsx("div",{className:"space-y-2 mb-4",children:L.map(X=>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:X.authorName}),n.jsx("span",{children:X.type}),n.jsx("span",{children:new Date(X.createdAt).toLocaleDateString()})]}),n.jsx("p",{className:"text-xs text-fg-secondary",children:X.content})]},X.id))}),n.jsxs("div",{className:"flex gap-2",children:[n.jsx("input",{value:K,onChange:X=>q(X.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:X=>{X.key==="Enter"&&K.trim()&&le.reports.addFeedback(F.id,{author:e?.id??"unknown",type:"comment",content:K.trim()}).then(({feedback:me})=>{U(je=>[...je,me]),q(""),E(t("feedback.added"))}).catch(me=>E(t("common:error",{message:String(me)})))}}),n.jsx("button",{onClick:()=>{K.trim()&&le.reports.addFeedback(F.id,{author:e?.id??"unknown",type:"comment",content:K.trim()}).then(({feedback:X})=>{U(me=>[...me,X]),q(""),E(t("feedback.added"))}).catch(X=>E(t("common:error",{message:String(X)})))},disabled:!K.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(uf,{label:t("usage.llmTokens"),value:ho(y.llmTokens),color:"text-brand-500"}),n.jsx(uf,{label:t("usage.toolCalls"),value:ho(y.toolCalls),color:"text-blue-600"}),n.jsx(uf,{label:t("usage.messages"),value:ho(y.messages),color:"text-green-600"}),y.storageBytes>0&&n.jsx(uf,{label:t("usage.storage"),value:Xne(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")}):p?n.jsx("div",{className:"flex items-center justify-center h-32 text-red-500 text-sm",children:p}):l?n.jsxs(n.Fragment,{children:[n.jsxs("div",{className:"text-xs text-fg-tertiary",children:[se[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(Ri,{label:t("taskMetrics.completed"),value:l.metrics.tasksCompleted,color:"text-green-600"}),n.jsx(Ri,{label:t("taskMetrics.inProgress"),value:l.metrics.tasksInProgress,color:"text-brand-500"}),n.jsx(Ri,{label:t("taskMetrics.created"),value:l.metrics.tasksCreated,color:"text-blue-600"}),n.jsx(Ri,{label:t("taskMetrics.blocked"),value:l.metrics.tasksBlocked,color:"text-amber-600"}),n.jsx(Ri,{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:Kc(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:ho(B)}),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:Kc(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(qc,{title:t("taskSummary.completedCount",{count:l.taskSummary.completed.length}),color:"emerald",items:l.taskSummary.completed.map(X=>({id:X.id,label:X.title,sub:X.agent}))}),l.taskSummary.inProgress.length>0&&n.jsx(qc,{title:t("taskSummary.inProgressCount",{count:l.taskSummary.inProgress.length}),color:"indigo",items:l.taskSummary.inProgress.map(X=>({id:X.id,label:X.title,sub:X.agent}))}),l.taskSummary.blocked.length>0&&n.jsx(qc,{title:t("taskSummary.blockedCount",{count:l.taskSummary.blocked.length}),color:"amber",items:l.taskSummary.blocked.map(X=>({id:X.id,label:X.title,sub:X.reason||X.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(Su,{label:t("perAgentUsage.totalTokens"),col:"totalTokens",current:C,desc:N,onSort:ee}),n.jsx(Su,{label:t("perAgentUsage.today"),col:"tokensUsedToday",current:C,desc:N,onSort:ee}),n.jsx(Su,{label:t("perAgentUsage.requests"),col:"requestCount",current:C,desc:N,onSort:ee}),n.jsx(Su,{label:t("perAgentUsage.toolCalls"),col:"toolCalls",current:C,desc:N,onSort:ee}),n.jsx(Su,{label:t("perAgentUsage.estCost"),col:"estimatedCost",current:C,desc:N,onSort:ee,align:"right"})]})}),n.jsx("tbody",{children:H.map(X=>n.jsx(Qne,{agent:X,maxTokens:Q},X.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:ho(v.reduce((X,me)=>X+me.totalTokens,0))}),n.jsx("td",{className:"px-4 py-3 text-sm font-medium text-fg-secondary tabular-nums",children:ho(B)}),n.jsx("td",{className:"px-4 py-3 text-sm font-medium text-fg-secondary tabular-nums",children:v.reduce((X,me)=>X+me.requestCount,0)}),n.jsx("td",{className:"px-4 py-3 text-sm font-medium text-fg-secondary tabular-nums",children:v.reduce((X,me)=>X+me.toolCalls,0)}),n.jsx("td",{className:"px-4 py-3 text-sm font-medium text-right text-fg-secondary tabular-nums",children:Kc(Z)})]})})]})})]})]})})}function Ri({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 qc({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?()=>Nt.navigate(Se.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 uf({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 Su({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 Qne({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:()=>Nt.navigate(Se.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:ho(e.totalTokens)})]})}),n.jsx("td",{className:"px-4 py-3 text-sm text-fg-secondary tabular-nums",children:ho(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:Kc(e.estimatedCost)})]})}const mf={urgent:"bg-red-500",high:"bg-amber-500",normal:"bg-blue-500",low:"bg-gray-400"},Uc={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"},Nj={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 Vc(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 ff(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 Zne(){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 D7({collapsed:e,userId:t,embeddedMode:r,onClose:s,sidebarMode:a,isActive:i,label:l,iconPath:d}){const{t:u}=kt(["team","common"]),[m,p]=b.useState(!1),[h,y]=b.useState("approvals"),[g,v]=b.useState([]),[S,C]=b.useState([]),[k,N]=b.useState(null),[j,T]=b.useState(null),[R,M]=b.useState({}),[_,F]=b.useState(0),z=b.useRef(null),L=b.useRef(null),[U,K]=b.useState({top:0,left:0,width:448,maxHeight:576}),q=b.useRef(null),I=b.useRef(!1),[D,E]=b.useState(!0),[$,Y]=b.useState(!1),W=b.useRef(null),O=b.useRef("approvals"),H=30,Z=b.useCallback(async()=>{try{const[ne,he]=await Promise.all([le.notifications.list(t,!1,{limit:H,offset:0}),le.approvals.list()]);if(v(ne.notifications),F(ne.unreadCount??ne.notifications.filter(Be=>!Be.read).length),E(ne.totalCount!=null?ne.notifications.length<ne.totalCount:ne.notifications.length>=H),C(he.approvals),!I.current){const Be=he.approvals.filter(de=>de.status==="pending").length;q.current=Be,I.current=!0}}catch{}},[t]),B=b.useCallback(async()=>{if(!($||!D)){Y(!0);try{const ne=await le.notifications.list(t,!1,{limit:H,offset:g.length});ne.notifications.length>0&&v(he=>[...he,...ne.notifications.filter(Be=>!he.some(de=>de.id===Be.id))]),E(ne.totalCount!=null?g.length+ne.notifications.length<ne.totalCount:ne.notifications.length>=H)}catch{}Y(!1)}},[t,g.length,$,D]),J=b.useCallback(ne=>{const he=ne.detail;if(!he)return;const{taskId:Be,requirementId:de}=he;!Be&&!de||v(Ce=>{const et=Ce.filter(it=>!it.read&&(Be&&it.metadata?.taskId===Be||de&&it.metadata?.requirementId===de));if(et.length===0)return Ce;for(const it of et)le.notifications.markRead(it.id).catch(()=>{});return F(it=>Math.max(0,it-et.length)),Ce.map(it=>et.some(Ve=>Ve.id===it.id)?{...it,read:!0}:it)})},[]);b.useEffect(()=>{Z();const ne=setInterval(Z,6e4),he=()=>Z(),Be=()=>{p(!0),Z()};window.addEventListener("markus:notifications-changed",he),window.addEventListener("markus:mark-read-by-ref",J),window.addEventListener("markus:open-notifications",Be);const de=gn.on("notification:created",()=>Z()),Ce=gn.on("approval:created",()=>Z());return()=>{clearInterval(ne),window.removeEventListener("markus:notifications-changed",he),window.removeEventListener("markus:mark-read-by-ref",J),window.removeEventListener("markus:open-notifications",Be),de(),Ce()}},[Z,J]);const Q=b.useCallback(()=>{if(!z.current)return;const ne=z.current.getBoundingClientRect(),he=window.innerWidth,Be=window.innerHeight,de=Math.min(448,he-16),Ce=Math.min(576,Be-16);let et=ne.right+8,it=ne.top;et+de>he-8&&(et=Math.max(8,he-de-8)),it+Ce>Be-8&&(it=Math.max(8,Be-Ce-8)),K({top:it,left:et,width:de,maxHeight:Ce})},[]);b.useLayoutEffect(()=>{m&&Q()},[m,Q]),b.useEffect(()=>{if(m)return window.addEventListener("resize",Q),()=>window.removeEventListener("resize",Q)},[m,Q]),b.useEffect(()=>{if(!m)return;const ne=he=>{z.current?.contains(he.target)||L.current?.contains(he.target)||p(!1)};return document.addEventListener("mousedown",ne),()=>document.removeEventListener("mousedown",ne)},[m]),b.useEffect(()=>{if(!m)return;const ne=S.some(Be=>Be.status==="pending"),he=g.some(Be=>!Be.read);y(ne&&!he?"approvals":!ne&&he?"notifications":O.current)},[m]);const ee=new Set(S.filter(ne=>ne.status==="pending").map(ne=>ne.id)),se=new Set(S.map(ne=>ne.id)),X=g.filter(ne=>!(ne.type==="approval_request"&&ne.metadata?.approvalId&&se.has(ne.metadata.approvalId))),me=g.filter(ne=>ne.type==="approval_request"&&!ne.read&&ne.metadata?.approvalId&&ee.has(ne.metadata.approvalId)).length,je=Math.max(0,_-me),Re=ee.size,Ee=je+Re;b.useEffect(()=>{q.current!==null&&Re>q.current&&Zne(),q.current=Re},[Re]);const we=async ne=>{await le.notifications.markRead(ne),v(he=>he.map(Be=>Be.id===ne?{...Be,read:!0}:Be)),F(he=>Math.max(0,he-1))},pe=ne=>{const he=ne.metadata??{},Be=ne.actionType,de=ne.actionTarget;if(Be==="open_chat"&&de)try{const Ce=typeof de=="string"?JSON.parse(de):de;if(Ce.agentId){const et={agentId:Ce.agentId};Ce.sessionId&&(et.sessionId=Ce.sessionId),Nt.navigate(Se.TEAM,et);return}}catch{}if(Be==="navigate"&&de)try{const Ce=typeof de=="string"?JSON.parse(de):de;if(Ce.path){if(Ce.path.startsWith("/team")){const et={},it=new URLSearchParams(Ce.path.split("?")[1]||"");for(const[Ve,Ge]of it.entries())et[Ve]=Ge;Nt.navigate(Se.TEAM,et);return}if(Ce.path.startsWith("/work")){const et={},it=new URLSearchParams(Ce.path.split("?")[1]||"");for(const[Ve,Ge]of it.entries())et[Ve]=Ge;Nt.navigate(Se.WORK,et);return}}}catch{}switch(ne.type){case"approval_request":{const Ce=he.approvalId,et=Ce?S.find(ut=>ut.id===Ce):void 0,it=et?.details?.taskId??he.taskId,Ve=et?.details?.requirementId??he.requirementId,Ge=et?.details?.agentId??et?.agentId;it?Nt.navigate(Se.WORK,{openTask:it}):Ve?Nt.navigate(Se.WORK,{openRequirement:Ve}):Ge?Nt.navigate(Se.TEAM,{agentId:Ge}):Nt.navigate(Se.WORK);break}case"task_completed":case"task_created":case"task_review":case"task_failed":he.taskId?Nt.navigate(Se.WORK,{openTask:he.taskId}):Nt.navigate(Se.WORK);break;case"requirement_created":case"requirement_decision":he.requirementId?Nt.navigate(Se.WORK,{openRequirement:he.requirementId}):Nt.navigate(Se.WORK);break;case"agent_report":case"system":{if(he.agentId){const Ce={agentId:he.agentId};he.sessionId&&(Ce.sessionId=he.sessionId),Nt.navigate(Se.TEAM,Ce)}else Nt.navigate(Se.TEAM);break}case"direct_message":{const Ce=he.senderId;Ce?Nt.navigate(Se.TEAM,{dm:Ce}):Nt.navigate(Se.TEAM);break}case"group_message":{const Ce=he.channel;Ce?Nt.navigate(Se.TEAM,{channel:Ce}):Nt.navigate(Se.TEAM);break}default:he.taskId?Nt.navigate(Se.WORK,{openTask:he.taskId}):he.requirementId?Nt.navigate(Se.WORK,{openRequirement:he.requirementId}):he.projectId?Nt.navigate(Se.WORK,{projectId:he.projectId}):he.agentId&&Nt.navigate(Se.TEAM,{agentId:he.agentId});break}},Pe=async ne=>{ne.read||we(ne.id);const he=ne.metadata??{},Be=he.taskId,de=he.requirementId;if(Be||de){const Ce=g.filter(et=>et.id!==ne.id&&!et.read&&(Be&&et.metadata?.taskId===Be||de&&et.metadata?.requirementId===de));for(const et of Ce)we(et.id)}pe(ne)},Ae=async(ne,he,Be,de)=>{N(ne);try{const{approval:Ce}=await le.approvals.respond(ne,he,t,Be,de);C(Ge=>Ge.map(ut=>ut.id===ne?Ce:ut)),T(null),M(Ge=>{const ut={...Ge};return delete ut[ne],ut});const et=Ce.details?.taskId,it=Ce.details?.requirementId,Ve=g.filter(Ge=>!Ge.read&&(Ge.type==="approval_request"&&Ge.metadata?.approvalId===ne||et&&Ge.metadata?.taskId===et||it&&Ge.metadata?.requirementId===it));if(Ve.length>0){for(const ut of Ve)le.notifications.markRead(ut.id).catch(()=>{});const Ge=new Set(Ve.map(ut=>ut.id));v(ut=>ut.map(nt=>Ge.has(nt.id)?{...nt,read:!0}:nt)),F(ut=>Math.max(0,ut-Ve.length))}rl("/approvals"),rl("/notifications"),rl("/tasks"),rl("/taskboard"),rl("/requirements"),window.dispatchEvent(new CustomEvent("markus:data-changed")),window.dispatchEvent(new CustomEvent("markus:notifications-changed")),setTimeout(()=>Z(),800)}catch{}N(null)},Xe=async()=>{try{if(!t)return;await le.notifications.markAllRead(t),v(ne=>ne.map(he=>({...he,read:!0}))),F(0),rl("/notifications")}catch{const ne=X.filter(he=>!he.read);await Promise.all(ne.map(he=>le.notifications.markRead(he.id))),v(he=>he.map(Be=>({...Be,read:!0}))),F(0),rl("/notifications")}},Ze=ne=>{const he=ne.details?.subType;return he==="requirement_resubmit"?u("team:notifications.approvalType.requirementResubmit"):he==="requirement"||ne.details?.requirementId?u("team:notifications.approvalType.requirement"):he==="task_review"?u("team:notifications.approvalType.taskReview"):he==="task"||ne.details?.taskId?u("team:notifications.approvalType.task"):ne.details?.toolName?u("team:notifications.approvalType.toolExecution"):null},at=ne=>{const he=[];he.push(ne.agentName);const Be=ne.details?.taskTitle,de=ne.details?.taskId;Be?he.push(Be):de&&he.push(`Task ${de.slice(0,8)}`);const Ce=ne.details?.requirementId;return Ce&&!de&&he.push(`Req ${Ce.slice(0,8)}`),he.join(" · ")},pt=[...S].sort((ne,he)=>new Date(he.requestedAt).getTime()-new Date(ne.requestedAt).getTime()),Ct=pt.filter(ne=>ne.status==="pending"),_e=pt.filter(ne=>ne.status!=="pending"),ue=ne=>{const he=ne.details?.taskId,Be=ne.details?.requirementId,de=ne.details?.agentId??ne.agentId;he?Nt.navigate(Se.WORK,{openTask:he}):Be?Nt.navigate(Se.WORK,{openRequirement:Be}):de?Nt.navigate(Se.TEAM,{agentId:de}):Nt.navigate(Se.WORK)},fe=()=>{p(!1),s?.()},Me=n.jsxs(n.Fragment,{children:[n.jsxs("div",{className:"flex border-b border-border-default shrink-0",children:[n.jsxs("button",{onClick:()=>{y("approvals"),O.current="approvals"},className:`flex-1 px-3 py-2.5 text-xs font-medium transition-colors ${h==="approvals"?"text-fg-primary border-b-2 border-brand-500":"text-fg-tertiary hover:text-fg-secondary"}`,children:[u("team:notifications.approvals"),Re>0?` (${Re})`:""]}),n.jsxs("button",{onClick:()=>{y("notifications"),O.current="notifications"},className:`flex-1 px-3 py-2.5 text-xs font-medium transition-colors ${h==="notifications"?"text-fg-primary border-b-2 border-brand-500":"text-fg-tertiary hover:text-fg-secondary"}`,children:[u("team:notifications.notifications"),je>0?` (${je})`:""]}),n.jsx("button",{onClick:fe,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"})]})})]}),h==="notifications"&&_>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:Xe,className:"text-[10px] text-brand-500 hover:text-brand-400 transition-colors",children:u("team:notifications.markAllRead")})}),n.jsxs("div",{ref:W,className:"flex-1 overflow-y-auto",onScroll:ne=>{if(h!=="notifications"||!D||$)return;const he=ne.currentTarget;he.scrollTop+he.clientHeight>=he.scrollHeight-80&&B()},children:[h==="approvals"&&(S.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:[Ct.map(ne=>{const he=ne.details?.command,Be=he?ne.description.replace(/\s*Command:.*$/,""):ne.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:()=>ue(ne),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:Uc.approval_request})}),n.jsxs("div",{className:"flex-1 min-w-0",children:[n.jsxs("div",{className:"flex items-center gap-2",children:[Ze(ne)&&n.jsx("span",{className:"text-[10px] text-amber-500 font-medium shrink-0",children:Ze(ne)}),n.jsx("span",{className:"text-xs text-fg-primary font-medium truncate",children:ne.title}),n.jsx("span",{className:"text-[10px] text-fg-tertiary shrink-0",children:Vc(ne.requestedAt,u)})]}),n.jsx("div",{className:"text-[11px] text-fg-tertiary mt-0.5",children:ne.agentName})]})]}),n.jsx("div",{className:"mt-2.5 text-[11px] text-fg-secondary leading-relaxed",children:n.jsx(Ur,{content:Be,className:"text-[11px] [&_h1]:text-xs [&_h2]:text-[11px] [&_h3]:text-[11px] [&_p]:text-[11px] [&_li]:text-[11px]"})}),he&&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:he})]}),(()=>{const de=ne.details?.subType,Ce=de==="task"||de==="requirement"||de==="requirement_resubmit",et=ne.options&&ne.options.length>0,it=(R[ne.id]??"").trim();return et?n.jsxs("div",{className:"space-y-1.5",children:[ne.options.map((Ve,Ge)=>n.jsxs("button",{disabled:k===ne.id,onClick:()=>Ae(ne.id,Ve.id!=="reject",it||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+Ge)}),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:R[ne.id]??"",onChange:Ve=>M(Ge=>({...Ge,[ne.id]:Ve.target.value})),onKeyDown:Ve=>{Ve.key==="Enter"&&(R[ne.id]??"").trim()&&Ae(ne.id,!0,(R[ne.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:k===ne.id||!(R[ne.id]??"").trim(),onClick:()=>Ae(ne.id,!0,(R[ne.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")})]})]}):Ce?n.jsxs("div",{className:"space-y-1.5",children:[n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsxs("button",{disabled:k===ne.id,onClick:()=>Ae(ne.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:k===ne.id,onClick:()=>Ae(ne.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")]}),j!==ne.id&&n.jsxs("button",{disabled:k===ne.id,onClick:()=>T(ne.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")]})]}),j===ne.id&&n.jsxs("div",{className:"space-y-1.5",children:[n.jsx("input",{type:"text",autoFocus:!0,placeholder:u("team:notifications.adjustmentPlaceholder"),value:R[ne.id]??"",onChange:Ve=>M(Ge=>({...Ge,[ne.id]:Ve.target.value})),onKeyDown:Ve=>{Ve.key==="Enter"&&(R[ne.id]??"").trim()&&Ae(ne.id,!1,(R[ne.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:k===ne.id||!(R[ne.id]??"").trim(),onClick:()=>Ae(ne.id,!1,(R[ne.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:R[ne.id]??"",onChange:Ve=>M(Ge=>({...Ge,[ne.id]:Ve.target.value})),onKeyDown:Ve=>{Ve.key==="Enter"&&Ae(ne.id,!0,it||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:k===ne.id,onClick:()=>Ae(ne.id,!0,it||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:k===ne.id,onClick:()=>Ae(ne.id,!1,it||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")})]})]})})()]},ne.id)}),_e.length>0&&n.jsxs(n.Fragment,{children:[Ct.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")}),_e.slice(0,50).map(ne=>n.jsxs("button",{onClick:()=>ue(ne),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 ${ne.status==="approved"?"bg-green-500":ne.status==="cancelled"||ne.status==="expired"?"bg-gray-400":"bg-red-500"}`}),Ze(ne)&&n.jsx("span",{className:"text-[10px] text-fg-tertiary font-medium shrink-0",children:Ze(ne)}),n.jsx("span",{className:"text-xs text-fg-secondary truncate flex-1 group-hover:text-fg-primary",children:ne.title}),n.jsx("span",{className:`text-[10px] font-medium shrink-0 ${ne.status==="approved"?"text-green-500":ne.status==="cancelled"||ne.status==="expired"?"text-fg-muted":"text-red-500"}`,children:u(`common:status.${ne.status}`,{defaultValue:ne.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:at(ne)}),n.jsx("span",{className:"text-[10px] text-fg-muted shrink-0",children:"·"}),n.jsx("span",{className:"text-[10px] text-fg-muted shrink-0",children:Vc(ne.respondedAt??ne.requestedAt,u)})]}),ne.responseComment&&n.jsxs("p",{className:"text-[10px] text-fg-muted mt-0.5 pl-3.5 truncate",children:["“",ne.responseComment,"”"]})]},ne.id))]})]})),h==="notifications"&&(X.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:[X.map(ne=>{const he=Nj[ne.type]??"text-fg-tertiary";return n.jsxs("div",{role:"button",tabIndex:0,onClick:()=>Pe(ne),onKeyDown:Be=>{(Be.key==="Enter"||Be.key===" ")&&(Be.preventDefault(),Pe(ne))},className:`w-full text-left px-3 py-2.5 flex gap-2.5 transition-colors cursor-pointer ${ne.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:he,children:n.jsx("path",{d:Uc[ne.type]??Uc.system})})}),n.jsxs("div",{className:"flex-1 min-w-0",children:[n.jsxs("div",{className:"flex items-center gap-1.5",children:[!ne.read&&n.jsx("span",{className:`w-1.5 h-1.5 rounded-full shrink-0 ${mf[ne.priority]??mf.normal}`}),n.jsx("span",{className:"text-xs text-fg-primary font-medium truncate",children:ne.title})]}),n.jsx("div",{className:"text-[11px] text-fg-tertiary mt-0.5 ",children:n.jsx(Ur,{content:ne.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:Vc(ne.createdAt,u)}),ff(ne,u)&&n.jsx("span",{className:`text-[10px] font-medium ${he}`,children:ff(ne,u)})]})]})]},ne.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 ne=["approvals","notifications"],he=ne.indexOf(h),Be=(()=>{let de=0,Ce=0;return{onTouchStart:et=>{de=et.touches[0].clientX,Ce=et.touches[0].clientY},onTouchEnd:et=>{const it=et.changedTouches[0].clientX-de,Ve=et.changedTouches[0].clientY-Ce;Math.abs(it)>60&&Math.abs(it)>Math.abs(Ve)*1.5&&(it<0&&he<ne.length-1&&y(ne[he+1]),it>0&&he>0&&y(ne[he-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:ne.map(de=>n.jsx("button",{onClick:()=>y(de),className:`flex-1 px-3 py-3 text-sm font-medium transition-colors ${h===de?"text-fg-primary border-b-2 border-brand-500":"text-fg-tertiary"}`,children:de==="approvals"?n.jsxs(n.Fragment,{children:[u("team:notifications.approvals"),Re>0?` (${Re})`:""]}):n.jsxs(n.Fragment,{children:[u("team:notifications.notifications"),je>0?` (${je})`:""]})},de))}),h==="notifications"&&_>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:Xe,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",...Be,children:n.jsxs("div",{className:"flex h-full transition-transform duration-300 ease-out",style:{transform:`translateX(-${he*100}%)`},children:[n.jsx("div",{className:"w-full shrink-0 h-full overflow-y-auto scrollbar-thin",children:S.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:[Ct.map(de=>{const Ce=de.details?.command,et=Ce?de.description.replace(/\s*Command:.*$/,""):de.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:()=>ue(de),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:Uc.approval_request})}),n.jsxs("div",{className:"flex-1 min-w-0",children:[n.jsxs("div",{className:"flex items-center gap-2",children:[Ze(de)&&n.jsx("span",{className:"text-[10px] text-amber-500 font-medium shrink-0",children:Ze(de)}),n.jsx("span",{className:"text-xs text-fg-primary font-medium truncate",children:de.title}),n.jsx("span",{className:"text-[10px] text-fg-tertiary shrink-0",children:Vc(de.requestedAt,u)})]}),n.jsx("div",{className:"text-[11px] text-fg-tertiary mt-0.5",children:de.agentName})]})]}),n.jsx("div",{className:"mt-2.5 text-[11px] text-fg-secondary leading-relaxed",children:n.jsx(Ur,{content:et,className:"text-[11px] [&_h1]:text-xs [&_h2]:text-[11px] [&_h3]:text-[11px] [&_p]:text-[11px] [&_li]:text-[11px]"})}),Ce&&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:Ce})]}),(()=>{const it=de.details?.subType,Ve=it==="task"||it==="requirement"||it==="requirement_resubmit",Ge=de.options&&de.options.length>0,ut=(R[de.id]??"").trim();return Ge?n.jsxs("div",{className:"space-y-1.5",children:[de.options.map((nt,ft)=>n.jsxs("button",{disabled:k===de.id,onClick:()=>Ae(de.id,nt.id!=="reject",ut||void 0,nt.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 ${nt.id==="reject"||nt.id==="request_changes"?"border border-border-default text-fg-secondary hover:bg-surface-overlay":"bg-brand-600 text-white hover:bg-brand-700"}`,title:nt.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+ft)}),nt.label]},nt.id)),n.jsxs("div",{className:"flex gap-1.5 mt-1",children:[n.jsx("input",{type:"text",placeholder:u("team:notifications.freeformPlaceholder"),value:R[de.id]??"",onChange:nt=>M(ft=>({...ft,[de.id]:nt.target.value})),onKeyDown:nt=>{nt.key==="Enter"&&(R[de.id]??"").trim()&&Ae(de.id,!0,(R[de.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:k===de.id||!(R[de.id]??"").trim(),onClick:()=>Ae(de.id,!0,(R[de.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:k===de.id,onClick:()=>Ae(de.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:k===de.id,onClick:()=>Ae(de.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")]}),j!==de.id&&n.jsxs("button",{disabled:k===de.id,onClick:()=>T(de.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")]})]}),j===de.id&&n.jsxs("div",{className:"space-y-1.5",children:[n.jsx("input",{type:"text",autoFocus:!0,placeholder:u("team:notifications.adjustmentPlaceholder"),value:R[de.id]??"",onChange:nt=>M(ft=>({...ft,[de.id]:nt.target.value})),onKeyDown:nt=>{nt.key==="Enter"&&(R[de.id]??"").trim()&&Ae(de.id,!1,(R[de.id]??"").trim(),"needs_adjustment"),nt.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:k===de.id||!(R[de.id]??"").trim(),onClick:()=>Ae(de.id,!1,(R[de.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:R[de.id]??"",onChange:nt=>M(ft=>({...ft,[de.id]:nt.target.value})),onKeyDown:nt=>{nt.key==="Enter"&&Ae(de.id,!0,ut||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:k===de.id,onClick:()=>Ae(de.id,!0,ut||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:k===de.id,onClick:()=>Ae(de.id,!1,ut||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")})]})]})})()]},de.id)}),_e.length>0&&n.jsxs(n.Fragment,{children:[Ct.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")}),_e.slice(0,50).map(de=>n.jsxs("button",{onClick:()=>ue(de),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 ${de.status==="approved"?"bg-green-500":de.status==="cancelled"||de.status==="expired"?"bg-gray-400":"bg-red-500"}`}),n.jsx("span",{className:"text-xs text-fg-secondary truncate flex-1",children:de.title}),n.jsx("span",{className:`text-[10px] font-medium shrink-0 ${de.status==="approved"?"text-green-500":de.status==="cancelled"||de.status==="expired"?"text-fg-muted":"text-red-500"}`,children:u(`common:status.${de.status}`,{defaultValue:de.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:at(de)}),n.jsx("span",{className:"text-[10px] text-fg-muted shrink-0",children:"·"}),n.jsx("span",{className:"text-[10px] text-fg-muted shrink-0",children:Vc(de.respondedAt??de.requestedAt,u)})]})]},de.id))]})]})}),n.jsx("div",{className:"w-full shrink-0 h-full overflow-y-auto scrollbar-thin",children:X.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:X.slice(0,50).map(de=>{const Ce=Nj[de.type]??"text-fg-tertiary";return n.jsxs("button",{onClick:()=>Pe(de),className:`w-full text-left px-3 py-2.5 flex gap-2.5 transition-colors ${de.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:Ce,children:n.jsx("path",{d:Uc[de.type]??Uc.system})})}),n.jsxs("div",{className:"flex-1 min-w-0",children:[n.jsxs("div",{className:"flex items-center gap-1.5",children:[!de.read&&n.jsx("span",{className:`w-1.5 h-1.5 rounded-full shrink-0 ${mf[de.priority]??mf.normal}`}),n.jsx("span",{className:"text-xs text-fg-primary font-medium truncate",children:de.title})]}),n.jsx("div",{className:"text-[11px] text-fg-tertiary mt-0.5 ",children:n.jsx(Ur,{content:de.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:Vc(de.createdAt,u)}),ff(de,u)&&n.jsx("span",{className:`text-[10px] font-medium ${Ce}`,children:ff(de,u)})]})]})]},de.id)})})})]})})]})}if(a){const ne=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:z,onClick:()=>{p(!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:ne})}),e?n.jsx("span",{className:"text-[9px] leading-tight truncate w-full text-center",children:l}):n.jsx("span",{className:"truncate",children:l}),Ee>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:Ee>99?u("common:badgeOverLimit"):Ee})]}),m&&sd.createPortal(n.jsx("div",{ref:L,className:"fixed bg-surface-secondary border border-border-default rounded-xl shadow-2xl z-[9999] flex flex-col overflow-hidden",style:{top:U.top,left:U.left,width:U.width,maxHeight:U.maxHeight},children:Me}),document.body)]})}return n.jsxs(n.Fragment,{children:[n.jsxs("button",{ref:z,onClick:()=>{p(!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"})]}),Ee>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:Ee>99?u("common:badgeOverLimit"):Ee})]}),m&&sd.createPortal(n.jsx("div",{ref:L,className:"fixed bg-surface-secondary border border-border-default rounded-xl shadow-2xl z-[9999] flex flex-col overflow-hidden",style:{top:U.top,left:U.left,width:U.width,maxHeight:U.maxHeight},children:Me}),document.body)]})}function Jne({authUser:e}){const{t}=kt("nav"),r=ks();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(sc,{}),n.jsx("h2",{className:"text-base font-bold",children:t("notifications")})]}),n.jsx("div",{className:"flex-1 overflow-hidden",children:n.jsx(D7,{collapsed:!1,userId:e?.id,embeddedMode:!0})})]})}function ere(){const{t:e}=kt(["common","home","work"]),[t,r]=b.useState(""),[s,a]=b.useState("all"),[i,l]=b.useState({agents:[],tasks:[],requirements:[],projects:[],deliverables:[]}),[d,u]=b.useState(!1),[m,p]=b.useState(!1),h=b.useRef(null),y=b.useRef(void 0);b.useEffect(()=>{setTimeout(()=>h.current?.focus(),100)},[]);const g=b.useCallback(async k=>{if(!k.trim()){l({agents:[],tasks:[],requirements:[],projects:[],deliverables:[]}),p(!1);return}u(!0),p(!0);const N=k.toLowerCase();try{const[j,T,R,M,_]=await Promise.allSettled([le.agents.list(),le.tasks.list({search:k,pageSize:20}),le.requirements.list(),le.projects.list(),le.deliverables.search({q:k,limit:20})]),F=j.status==="fulfilled"?j.value.agents.filter(q=>q.name?.toLowerCase().includes(N)||q.role?.toLowerCase().includes(N)):[],z=T.status==="fulfilled"?T.value.tasks:[],L=R.status==="fulfilled"?R.value.requirements.filter(q=>q.title?.toLowerCase().includes(N)||q.description?.toLowerCase().includes(N)):[],U=M.status==="fulfilled"?M.value.projects.filter(q=>q.name?.toLowerCase().includes(N)||q.description?.toLowerCase().includes(N)):[],K=_.status==="fulfilled"?_.value.results:[];l({agents:F,tasks:z,requirements:L,projects:U,deliverables:K})}catch{l({agents:[],tasks:[],requirements:[],projects:[],deliverables:[]})}finally{u(!1)}},[]),v=k=>{r(k),y.current&&clearTimeout(y.current),y.current=setTimeout(()=>g(k),400)},S=[{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:()=>Nt.navigate(Se.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:h,value:t,onChange:k=>v(k.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:[]}),p(!1),h.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:S.map(k=>n.jsx("button",{onClick:()=>a(k.id),className:`px-3 py-1.5 text-xs rounded-lg whitespace-nowrap transition-colors ${s===k.id?"bg-brand-600 text-white":"bg-surface-elevated text-fg-secondary hover:text-fg-primary"}`,children:k.label},k.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(k=>n.jsxs("button",{onClick:()=>Nt.navigate(Se.TEAM,{agentId:k.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(gr,{name:k.name||"Agent",avatarUrl:k.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:k.name}),n.jsx("div",{className:"text-xs text-fg-tertiary truncate",children:k.role||k.status})]}),n.jsx(tre,{status:k.status})]},k.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(k=>n.jsxs("button",{onClick:()=>Nt.navigate(Se.WORK,{openTask:k.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(nre,{status:k.status}),n.jsxs("div",{className:"flex-1 min-w-0",children:[n.jsx("div",{className:"text-sm text-fg-primary truncate",children:k.title}),n.jsxs("div",{className:"text-xs text-fg-tertiary truncate",children:[k.status," · ",k.priority||""]})]})]},k.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(k=>n.jsxs("button",{onClick:()=>Nt.navigate(Se.WORK,{openRequirement:k.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 ${k.status==="approved"?"text-green-500 bg-green-500/15":k.status==="pending"?"text-amber-500 bg-amber-500/15":k.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:k.title}),n.jsxs("div",{className:"text-xs text-fg-tertiary truncate",children:[k.status," · ",k.priority||""]})]})]},k.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(k=>n.jsxs("button",{onClick:()=>Nt.navigate(Se.WORK,{projectId:k.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:k.name}),k.description&&n.jsx("div",{className:"text-xs text-fg-tertiary truncate",children:k.description})]})]},k.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(k=>n.jsxs("button",{onClick:()=>Nt.navigate(Se.DELIVERABLES,{openDeliverable:k.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:k.title}),n.jsxs("div",{className:"text-xs text-fg-tertiary truncate",children:[k.type," · ",k.status]})]})]},k.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 tre({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 nre({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 rre({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 sre({currentPage:e,onNavigate:t,authUser:r,collapsed:s,onToggleCollapse:a}){const{t:i}=kt(["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:e_.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"}),t_.filter(m=>m.section===l.key).map(m=>{if(m.id===Se.NOTIFICATIONS)return n.jsx(D7,{sidebarMode:!0,collapsed:s,userId:r?.id,label:i(m.id),iconPath:Qx[m.id],isActive:e===m.id},m.id);const p=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 ${p?"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(rre,{d:Qx[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.7.6"]})]})}function are({currentPage:e,onNavigate:t,userId:r}){const{t:s}=kt("nav"),[a,i]=b.useState(0),[l,d]=b.useState(0),u=b.useCallback(async()=>{try{const m=await le.notifications.list(r,!1);i(m.unreadCount??m.notifications.filter(p=>!p.read).length)}catch{}},[r]);return b.useEffect(()=>{u();const m=setInterval(u,15e3),p=()=>u();window.addEventListener("markus:notifications-changed",p);const h=y=>{const g=y.detail?.count??0;d(g)};return window.addEventListener("markus:team-unread-changed",h),()=>{clearInterval(m),window.removeEventListener("markus:notifications-changed",p),window.removeEventListener("markus:team-unread-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:n_.map(m=>{const p=m.group.includes(e),h=m.id===Se.NOTIFICATIONS,y=m.id===Se.TEAM;return n.jsxs("button",{onClick:()=>t(m.id),className:`flex-1 flex flex-col items-center justify-center gap-0.5 transition-colors ${p?"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:p?2:1.75,strokeLinecap:"round",strokeLinejoin:"round",className:"shrink-0",children:n.jsx("path",{d:Qx[m.id]})}),h&&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&&l>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:l>99?"99+":l})]}),n.jsx("span",{className:`text-[10px] leading-tight ${p?"font-semibold":""}`,children:s(m.id)})]},m.id)})})}const R7=["builder","agents","teams","skills"];function ire(){const e=localStorage.getItem("markus_nav_storeTab");return e&&(localStorage.removeItem("markus_nav_storeTab"),R7.includes(e))?e:"builder"}function ore({authUser:e}){const{t}=kt(["nav","common"]),r=b.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]=b.useState(ire),i=hl(r,s,a);return b.useEffect(()=>{const l=d=>{const u=d.detail;u.params?.storeTab&&R7.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(sc,{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(CS,{}),s==="agents"&&n.jsx(ES,{authUser:e}),s==="teams"&&n.jsx(RS,{}),s==="skills"&&n.jsx(LS,{})]})]})}const Vx="profile",Sj="llm",Cj="search";function lre({onComplete:e,theme:t,onThemeChange:r,skipProfile:s}){const{t:a}=kt(["onboarding","common"]),[i,l]=b.useState(0),[d,u]=b.useState(""),[m,p]=b.useState(""),[h,y]=b.useState(""),[g,v]=b.useState(""),[S,C]=b.useState(!1),[k,N]=b.useState(""),[j,T]=b.useState(!1),[R,M]=b.useState(null);b.useEffect(()=>{le.auth.me().then(({user:$e})=>{$e.name&&u($e.name),$e.email&&p($e.email),$e.avatarUrl&&M($e.avatarUrl)}).catch(()=>{})},[]);const[_,F]=b.useState(null),[z,L]=b.useState(!1),[U,K]=b.useState({}),[q,I]=b.useState(!1),[D,E]=b.useState(null),[$,Y]=b.useState(!1),[W,O]=b.useState(!1),[H,Z]=b.useState([]),[B,J]=b.useState(null),[Q,ee]=b.useState(!0),[se,X]=b.useState(""),me=b.useRef(!1),[je,Re]=b.useState(null),[Ee,we]=b.useState({serperApiKey:"",tavilyApiKey:"",bingApiKey:"",googleSearchApiKey:"",googleSearchCx:"",serpApiKey:"",braveApiKey:"",exaApiKey:"",bochaApiKey:""}),[pe,Pe]=b.useState(!1),[Ae,Xe]=b.useState(!1),[Ze,at]=b.useState(null),pt=b.useRef(!1),Ct=()=>({"Content-Type":"application/json",Authorization:`Bearer ${localStorage.getItem("markus_token")??""}`});b.useEffect(()=>{fetch("/api/settings/llm").then($e=>$e.ok?$e.json():null).then($e=>{if($e?.providers){const ct=Object.entries($e.providers).filter(([,Ut])=>Ut.configured).map(([Ut,zt])=>({name:Ut,displayName:zt.displayName??Ut,model:zt.model??"",apiKeyPreview:zt.apiKeyPreview}));ct.length>0&&(O(!0),Z(ct))}$e?.defaultProvider&&X($e.defaultProvider),typeof $e?.autoFallback=="boolean"&&ee($e.autoFallback)}).catch(()=>{})},[]);const _e=s?2:3;b.useEffect(()=>{i===_e&&!me.current&&!W&&(me.current=!0,fe())},[i,W,_e]);const ue=s?3:4;b.useEffect(()=>{i===ue&&!pt.current&&(pt.current=!0,de())},[i,ue]);const fe=async()=>{L(!0);try{const $e=await fetch("/api/settings/env-models",{headers:Ct()});if($e.ok){const ct=await $e.json();if(F(ct),ct.detected.length>0){const Ut={};for(const zt of ct.detected)Ut[zt.provider]=!0;K(Ut)}}}catch{}finally{L(!1)}},Me=async()=>{if(!_)return;const $e=_.detected.filter(ct=>U[ct.provider]);if($e.length!==0){I(!0),J(null);try{const ct=await fetch("/api/settings/env-models",{method:"POST",headers:Ct(),body:JSON.stringify({providers:$e.map(Ut=>({provider:Ut.provider,model:Ut.model,baseUrl:Ut.baseUrl,enabled:!0}))})});if(ct.ok){const Ut=await ct.json();if(Ut.settings?.providers){const cn=Object.entries(Ut.settings.providers).filter(([,Ln])=>Ln.configured).map(([Ln,Xt])=>({name:Ln,displayName:Xt.displayName??Ln,model:Xt.model??"",apiKeyPreview:Xt.apiKeyPreview}));Z(cn)}else Z($e.map(cn=>({name:cn.provider,displayName:cn.displayName,model:cn.model,apiKeyPreview:cn.apiKeyPreview})));const zt=Ut.settings?.defaultProvider||Ut.applied[0]||$e[0]?.provider||"";X(zt),zt&&fetch("/api/settings/llm",{method:"POST",headers:Ct(),body:JSON.stringify({defaultProvider:zt})}).catch(()=>{}),J({type:"ok",text:Ut.message}),O(!0)}else J({type:"err",text:a("llm.failedToApply")})}catch{J({type:"err",text:a("common:networkError")})}finally{I(!1)}}},ne=async()=>{Y(!0);try{const ct=await(await fetch("/api/settings/import/openclaw",{method:"POST",headers:Ct(),body:JSON.stringify({preview:!0})})).json();"error"in ct||E(ct)}catch{}finally{Y(!1)}},he=async()=>{try{const $e=await fetch("/api/settings/llm");if(!$e.ok)return;const ct=await $e.json();if(ct.providers){const Ut=Object.entries(ct.providers).filter(([,zt])=>zt.configured).map(([zt,cn])=>({name:zt,displayName:cn.displayName??zt,model:cn.model??"",apiKeyPreview:cn.apiKeyPreview}));Ut.length>0&&Z(Ut)}ct.defaultProvider&&X(ct.defaultProvider),typeof ct.autoFallback=="boolean"&&ee(ct.autoFallback)}catch{}},Be=async()=>{Y(!0),J(null);try{const ct=await(await fetch("/api/settings/import/openclaw",{method:"POST",headers:Ct(),body:JSON.stringify({preview:!1})})).json();"error"in ct?J({type:"err",text:ct.error}):(J({type:"ok",text:a("llm.importedModels",{count:ct.appliedModels})}),O(!0),await he())}catch{J({type:"err",text:a("llm.importFailed")})}finally{Y(!1)}},de=async()=>{try{const $e=await fetch("/api/settings/search",{headers:Ct()});if($e.ok){const ct=await $e.json();Re(ct),ct&&(ct.serper.configured||ct.tavily.configured||ct.bing.configured||ct.google.configured||ct.serpapi.configured||ct.brave.configured||ct.exa.configured||ct.bocha.configured)&&Xe(!0)}}catch{}},Ce=async()=>{if(Ee.serperApiKey||Ee.tavilyApiKey||Ee.bingApiKey||Ee.googleSearchApiKey||Ee.googleSearchCx||Ee.serpApiKey||Ee.braveApiKey||Ee.exaApiKey||Ee.bochaApiKey){Pe(!0),at(null);try{const ct={};Ee.serperApiKey&&(ct.serperApiKey=Ee.serperApiKey),Ee.tavilyApiKey&&(ct.tavilyApiKey=Ee.tavilyApiKey),Ee.bingApiKey&&(ct.bingApiKey=Ee.bingApiKey),Ee.googleSearchApiKey&&(ct.googleSearchApiKey=Ee.googleSearchApiKey),Ee.googleSearchCx&&(ct.googleSearchCx=Ee.googleSearchCx),Ee.serpApiKey&&(ct.serpApiKey=Ee.serpApiKey),Ee.braveApiKey&&(ct.braveApiKey=Ee.braveApiKey),Ee.exaApiKey&&(ct.exaApiKey=Ee.exaApiKey),Ee.bochaApiKey&&(ct.bochaApiKey=Ee.bochaApiKey);const Ut=await fetch("/api/settings/search",{method:"POST",headers:Ct(),body:JSON.stringify(ct)});if(Ut.ok){const zt=await Ut.json();Re(zt),Xe(!0),we({serperApiKey:"",tavilyApiKey:"",bingApiKey:"",googleSearchApiKey:"",googleSearchCx:"",serpApiKey:"",braveApiKey:"",exaApiKey:"",bochaApiKey:""}),at({type:"ok",text:a("search.saved")})}else at({type:"err",text:a("search.failedToSave")})}catch{at({type:"err",text:a("common:networkError")})}finally{Pe(!1)}}},et=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(h&&h.length<6){N(a("profile.errors.passwordTooShort"));return}if(h&&h!==g){N(a("profile.errors.passwordMismatch"));return}C(!0);try{await le.auth.updateProfile(d.trim(),m.trim()),h&&await le.auth.changePassword("",h),T(!0)}catch{N(a("profile.errors.saveFailed"))}finally{C(!1)}},it=[{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")}],Ve=[{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(Fu,{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(([$e,ct])=>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:$e}),n.jsx("div",{className:"text-fg-secondary text-xs mt-1",children:ct})]},$e))})]})},{id:Vx,title:a("profile.title"),subtitle:a("profile.subtitle"),content:j?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(Qj,{currentUrl:R,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:$e=>u($e.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:$e=>p($e.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:h,onChange:$e=>y($e.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"})]}),h&&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:g,onChange:$e=>v($e.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"})]}),k&&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:k}),n.jsx("button",{onClick:()=>{et()},disabled:S||!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(S?"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:it.map($e=>n.jsxs("button",{onClick:()=>r($e.value),className:`flex flex-col items-center gap-2 rounded-xl border-2 p-5 transition-all ${t===$e.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:$e.icon}),n.jsx("span",{className:"text-sm font-medium text-fg-primary",children:$e.label}),n.jsx("span",{className:"text-[11px] text-fg-tertiary leading-tight text-center",children:$e.desc})]},$e.value))})},{id:Sj,title:a("llm.title"),subtitle:a("llm.subtitle"),content:W?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")})]}),H.length>1&&n.jsx("div",{className:"text-xs text-fg-secondary mb-1",children:a("llm.selectDefault")}),H.map($e=>{const ct=se===$e.name;return n.jsxs("button",{onClick:async()=>{const Ut=se;X($e.name);try{await fetch("/api/settings/llm",{method:"POST",headers:Ct(),body:JSON.stringify({defaultProvider:$e.name})})}catch{X(Ut)}},className:`w-full flex items-center justify-between rounded-lg px-4 py-2.5 text-left transition-colors ${ct?"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 ${ct?"border-brand-500":"border-fg-tertiary"}`,children:ct&&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:$e.displayName}),$e.model&&n.jsx("span",{className:"text-xs text-fg-tertiary",children:$e.model}),ct&&n.jsx("span",{className:"text-[10px] text-brand-500 font-medium",children:a("llm.default")})]}),$e.apiKeyPreview&&n.jsx("code",{className:"text-[10px] text-fg-tertiary",children:$e.apiKeyPreview})]},$e.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 $e=!Q;ee($e);try{await fetch("/api/settings/llm",{method:"POST",headers:Ct(),body:JSON.stringify({autoFallback:$e})})}catch{ee(!$e)}},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:[n.jsxs("div",{className:"space-y-2",children:[n.jsx("div",{className:"text-xs text-fg-secondary uppercase tracking-wider",children:a("llm.fromEnv")}),z&&n.jsx("div",{className:"text-xs text-fg-tertiary animate-pulse",children:a("llm.detectingKeys")}),_&&_.detected.length>0&&n.jsxs("div",{className:"space-y-2",children:[_.detected.map($e=>n.jsxs("label",{className:"flex items-center gap-3 bg-surface-elevated/40 rounded-lg px-3 py-2.5 cursor-pointer hover:bg-surface-elevated/60 transition-colors",children:[n.jsx("input",{type:"checkbox",checked:U[$e.provider]??!1,onChange:ct=>K({...U,[$e.provider]:ct.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:$e.displayName}),n.jsx("span",{className:"text-xs text-fg-tertiary ml-2",children:$e.model})]}),n.jsx("code",{className:"text-[10px] text-fg-tertiary",children:$e.apiKeyPreview})]},$e.provider)),n.jsx("button",{onClick:()=>{Me()},disabled:q||Object.values(U).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:q?a("common:applying"):a("llm.applyProviders",{count:Object.values(U).filter(Boolean).length})})]}),_&&_.detected.length===0&&!z&&n.jsx("div",{className:"text-xs text-fg-tertiary bg-surface-elevated/30 rounded-lg p-3",children:n.jsx(Fu,{i18nKey:"llm.noKeysFound",ns:"onboarding",components:{code:n.jsx("code",{className:"text-fg-secondary"})}})})]}),n.jsxs("div",{className:"flex items-center gap-3",children:[n.jsx("div",{className:"flex-1 h-px bg-border-default"}),n.jsx("span",{className:"text-xs text-fg-tertiary",children:a("llm.or")}),n.jsx("div",{className:"flex-1 h-px bg-border-default"})]}),n.jsxs("div",{className:"space-y-2",children:[n.jsx("div",{className:"text-xs text-fg-secondary uppercase tracking-wider",children:a("llm.fromOpenClaw")}),D?D.found?n.jsxs("div",{className:"space-y-2",children:[n.jsxs("div",{className:"text-xs text-green-600",children:[a("llm.openClawFoundLabel")," ",n.jsx("code",{className:"text-fg-secondary",children:D.summary.configPath}),D.summary.models&&n.jsx("span",{className:"text-fg-tertiary ml-1",children:a("llm.openClawProviders",{count:D.summary.models.providerCount})})]}),n.jsx("button",{onClick:()=>{Be()},disabled:$,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:a($?"common:importing":"llm.importModelConfigs")})]}):n.jsx("div",{className:"text-xs text-fg-tertiary bg-surface-elevated/30 rounded-lg p-3",children:a("llm.noOpenClawFound")}):n.jsx("button",{onClick:()=>{ne()},disabled:$,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 w-full",children:a($?"common:detecting":"llm.detectOpenClaw")})]}),B&&n.jsx("div",{className:`text-xs px-3 py-2 rounded-lg ${B.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:B.text})]})},{id:Cj,title:a("search.title"),subtitle:a("search.subtitle"),content:Ae?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($e=>je[$e.id]?.configured).map($e=>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:$e.label})]}),n.jsx("code",{className:"text-[10px] text-fg-tertiary",children:je[$e.id].preview})]},$e.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($e=>je[$e.id]?.configured).map($e=>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:$e.label})]}),n.jsx("code",{className:"text-[10px] text-fg-tertiary",children:je[$e.id].preview})]},$e.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($e=>n.jsxs("div",{className:"space-y-1",children:[n.jsx("label",{className:"text-xs text-fg-tertiary font-medium",children:$e.label}),n.jsx("input",{type:"password",value:Ee[$e.field],onChange:ct=>we({...Ee,[$e.field]:ct.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"})]},$e.field))}),n.jsx("button",{onClick:()=>{Ce()},disabled:pe||!Ee.serperApiKey&&!Ee.tavilyApiKey&&!Ee.bingApiKey&&!Ee.googleSearchApiKey&&!Ee.serpApiKey&&!Ee.braveApiKey&&!Ee.exaApiKey&&!Ee.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(pe?"search.saving":"search.save")}),Ze&&n.jsx("div",{className:`text-xs px-3 py-2 rounded-lg ${Ze.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:Ze.text})]})},{id:"done",title:a("done.title"),subtitle:a("done.subtitle"),content:n.jsx("div",{className:"space-y-2 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(([$e,ct])=>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:$e}),n.jsx("div",{className:"text-fg-secondary text-xs",children:ct})]})]},$e))})}],Ge=s?Ve.filter($e=>$e.id!==Vx):Ve,ut=Ge.findIndex($e=>$e.id===Vx),nt=Ge.findIndex($e=>$e.id===Sj),ft=Ge.findIndex($e=>$e.id===Cj),Rt=()=>{i===ut&&ut>=0&&!j||(i<Ge.length-1?l(i+1):e())},lt=Ge[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:Ge.map(($e,ct)=>n.jsx("div",{className:`h-1 flex-1 rounded-full transition-colors ${ct<=i?"bg-brand-500":"bg-surface-elevated"}`},ct))}),n.jsx("h2",{className:"text-2xl font-bold text-fg-primary",children:lt.title}),n.jsx("p",{className:"text-sm text-fg-secondary mt-1 mb-6",children:lt.subtitle}),lt.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:[ut>=0&&i===ut&&!j&&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")}),nt>=0&&i===nt&&!W&&n.jsx("button",{onClick:Rt,className:"px-4 py-2 text-sm text-fg-tertiary hover:text-fg-secondary transition-colors",children:a("llm.skipForNow")}),ft>=0&&i===ft&&!Ae&&n.jsx("button",{onClick:Rt,className:"px-4 py-2 text-sm text-fg-tertiary hover:text-fg-secondary transition-colors",children:a("search.skipForNow")}),n.jsx("button",{onClick:Rt,disabled:ut>=0&&i===ut&&!j,className:`px-6 py-2.5 text-white text-sm rounded-xl transition-colors ${ut>=0&&i===ut&&!j?"bg-brand-600/40 cursor-not-allowed":"bg-brand-600 hover:bg-brand-500"}`,children:i===Ge.length-1?a("getStarted"):a("common:next")})]})]})]})})})}function cre({onSetup:e}){const{t}=kt("auth"),[r,s]=b.useState(""),[a,i]=b.useState(""),[l,d]=b.useState(""),[u,m]=b.useState(""),[p,h]=b.useState(null),[y,g]=b.useState(""),[v,S]=b.useState(!1),C=b.useRef(null),k=b.useCallback(j=>{if(!j.type.startsWith("image/")||j.size>2*1024*1024)return;const T=new FileReader;T.onload=()=>h(T.result),T.readAsDataURL(j)},[]),N=async j=>{if(j.preventDefault(),g(""),l.length<6){g(t("setup.passwordMinLength"));return}if(l!==u){g(t("setup.passwordsDoNotMatch"));return}S(!0);try{const{user:T,needsOnboarding:R}=await le.auth.init(r.trim(),a.trim(),l);if(p)try{await le.auth.uploadAvatar(p,"user")}catch{}e(T,R??!0)}catch{g(t("setup.error"))}finally{S(!1)}};return r.trim()&&r.trim()[0].toUpperCase(),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:t("setup.subtitle")})]}),n.jsxs("form",{onSubmit:N,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.jsx("h2",{className:"text-lg font-semibold text-fg-primary text-center",children:t("setup.title")}),n.jsxs("div",{className:"flex flex-col items-center gap-2",children:[n.jsxs("div",{className:"relative group cursor-pointer",onClick:()=>C.current?.click(),children:[p?n.jsx("img",{src:p,alt:"",className:"w-16 h-16 rounded-full object-cover ring-2 ring-border-default group-hover:ring-brand-500 transition-all"}):n.jsx("div",{className:"w-16 h-16 rounded-full bg-surface-elevated border-2 border-dashed border-border-default group-hover:border-brand-500 flex items-center justify-center transition-all",children:n.jsxs("svg",{className:"w-6 h-6 text-fg-tertiary group-hover:text-brand-500 transition-colors",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:[n.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5,d:"M3 9a2 2 0 012-2h.93a2 2 0 001.664-.89l.812-1.22A2 2 0 0110.07 4h3.86a2 2 0 011.664.89l.812 1.22A2 2 0 0018.07 7H19a2 2 0 012 2v9a2 2 0 01-2 2H5a2 2 0 01-2-2V9z"}),n.jsx("circle",{cx:"12",cy:"13",r:"3"})]})}),n.jsx("div",{className:"absolute -bottom-0.5 -right-0.5 w-5 h-5 rounded-full bg-brand-600 flex items-center justify-center ring-2 ring-surface-secondary",children:n.jsx("svg",{className:"w-3 h-3 text-white",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:n.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 4v16m8-8H4"})})}),n.jsx("input",{ref:C,type:"file",accept:"image/png,image/jpeg,image/webp,image/gif",className:"hidden",onChange:j=>{const T=j.target.files?.[0];T&&k(T)}})]}),n.jsx("span",{className:"text-xs text-fg-tertiary",children:t("setup.uploadAvatar")})]}),n.jsxs("div",{className:"space-y-1",children:[n.jsx("label",{className:"text-xs text-fg-tertiary font-medium",children:t("setup.name")}),n.jsx("input",{type:"text",value:r,onChange:j=>s(j.target.value),autoComplete:"name",autoFocus:!0,placeholder:"Admin",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.jsxs("div",{className:"space-y-1",children:[n.jsx("label",{className:"text-xs text-fg-tertiary font-medium",children:t("setup.email")}),n.jsx("input",{type:"email",value:a,onChange:j=>i(j.target.value),autoComplete:"email",placeholder:"your@email.com",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.jsxs("div",{className:"space-y-1",children:[n.jsx("label",{className:"text-xs text-fg-tertiary font-medium",children:t("setup.password")}),n.jsx("input",{type:"password",value:l,onChange:j=>d(j.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})]}),n.jsxs("div",{className:"space-y-1",children:[n.jsx("label",{className:"text-xs text-fg-tertiary font-medium",children:t("setup.confirmPassword")}),n.jsx("input",{type:"password",value:u,onChange:j=>m(j.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})]}),y&&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:y}),n.jsx("button",{type:"submit",disabled:v||!r||!a||!l||!u,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:t(v?"setup.creating":"setup.createAccount")})]})]})]})}function dre({onLogin:e}){const{t}=kt("auth"),[r,s]=b.useState(""),[a,i]=b.useState(""),[l,d]=b.useState(""),[u,m]=b.useState(!1),p=async h=>{if(h.preventDefault(),!(!r.trim()||!a)){d(""),m(!0);try{const{user:y,needsOnboarding:g}=await le.auth.login(r.trim(),a);e(y,g??!1)}catch{d(t("login.invalidCredentials"))}finally{m(!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:t("login.subtitle")})]}),n.jsxs("form",{onSubmit:p,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.jsx("h2",{className:"text-lg font-semibold text-fg-primary text-center",children:t("login.signIn")}),n.jsxs("div",{className:"space-y-1",children:[n.jsx("label",{className:"text-xs text-fg-tertiary font-medium",children:t("login.email")}),n.jsx("input",{type:"email",value:r,onChange:h=>s(h.target.value),autoComplete:"email",placeholder:"your@email.com",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.jsxs("div",{className:"space-y-1",children:[n.jsx("label",{className:"text-xs text-fg-tertiary font-medium",children:t("login.password")}),n.jsx("input",{type:"password",value:a,onChange:h=>i(h.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",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}),n.jsx("button",{type:"submit",disabled:u||!r||!a,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:t(u?"login.signingIn":"login.signIn")}),n.jsx("p",{className:"text-center text-xs text-fg-tertiary",children:t("login.defaultCredentials")})]})]})]})}function ure({token:e,onComplete:t}){const{t:r}=kt("auth"),[s,a]=b.useState(null),[i,l]=b.useState(""),[d,u]=b.useState(""),[m,p]=b.useState(""),[h,y]=b.useState(!1),[g,v]=b.useState(!1),[S,C]=b.useState(!1);b.useEffect(()=>{le.auth.inviteInfo(e).then(N=>a(N)).catch(()=>C(!0))},[e]);const k=async N=>{if(N.preventDefault(),p(""),i.length<6){p(r("invite.passwordMinLength"));return}if(i!==d){p(r("invite.passwordsDoNotMatch"));return}y(!0);try{await le.auth.setup(e,i),v(!0),setTimeout(()=>{window.location.hash="",t()},2e3)}catch{p(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:S?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")})]}):g?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:k,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:h||!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(h?"invite.settingUp":"invite.setupAccount")})]}):n.jsx("div",{className:"text-center text-fg-tertiary text-sm animate-pulse py-4",children:"Loading…"})})]})]})}function mre({onComplete:e,isFirstTime:t}){const{t:r}=kt("auth"),[s,a]=b.useState(""),[i,l]=b.useState(""),[d,u]=b.useState(""),[m,p]=b.useState(""),[h,y]=b.useState(!1),g=async v=>{if(v.preventDefault(),p(""),i.length<6){p(r("changePassword.passwordMinLength"));return}if(i!==d){p(r("changePassword.passwordsDoNotMatch"));return}y(!0);try{await le.auth.changePassword(s,i),e()}catch{p(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:g,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:h||!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(h?"changePassword.saving":t?"changePassword.setPasswordAndContinue":"changePassword.changePassword")})]})]})]})}const Ef={agents:[],tasks:[],requirements:[],projects:[],deliverables:[]},fre={team:["agents","tasks","requirements","projects","deliverables"],work:["projects","requirements","tasks","agents","deliverables"],deliverables:["deliverables","agents","tasks","requirements","projects"]},hre=["agents","tasks","requirements","projects","deliverables"];let Tj="",Aj="all",Ej=Ef,Mj=!1;function pre({onClose:e,currentPage:t}){const{t:r}=kt(["common","home","work"]),[s,a]=b.useState(Tj),[i,l]=b.useState(Aj),[d,u]=b.useState(Ej),[m,p]=b.useState(!1),[h,y]=b.useState(Mj),[g,v]=b.useState(-1);b.useEffect(()=>{Tj=s},[s]),b.useEffect(()=>{Aj=i},[i]),b.useEffect(()=>{Ej=d},[d]),b.useEffect(()=>{Mj=h},[h]);const S=b.useRef(null),C=b.useRef(void 0),k=b.useRef(null),N=b.useRef(null);b.useEffect(()=>{setTimeout(()=>{S.current?.focus(),S.current?.select()},100)},[]);const j=b.useCallback(async q=>{if(!q.trim()){u(Ef),y(!1),v(-1);return}p(!0),y(!0),v(-1);const I=q.toLowerCase();try{const[D,E,$,Y,W]=await Promise.allSettled([le.agents.list(),le.tasks.list({search:q,pageSize:20}),le.requirements.list(),le.projects.list(),le.deliverables.search({q,limit:20})]),O=D.status==="fulfilled"?D.value.agents.filter(Q=>Q.name?.toLowerCase().includes(I)||Q.role?.toLowerCase().includes(I)):[],H=E.status==="fulfilled"?E.value.tasks:[],Z=$.status==="fulfilled"?$.value.requirements.filter(Q=>Q.title?.toLowerCase().includes(I)||Q.description?.toLowerCase().includes(I)):[],B=Y.status==="fulfilled"?Y.value.projects.filter(Q=>Q.name?.toLowerCase().includes(I)||Q.description?.toLowerCase().includes(I)):[],J=W.status==="fulfilled"?W.value.results:[];u({agents:O,tasks:H,requirements:Z,projects:B,deliverables:J})}catch{u(Ef)}finally{p(!1)}},[]),T=q=>{a(q),C.current&&clearTimeout(C.current),C.current=setTimeout(()=>j(q),400)},R=b.useCallback((q,I)=>{e(),Nt.navigate(q,I)},[e]),M=[{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:"交付物"})}],_=b.useMemo(()=>fre[t||""]||hre,[t]),F=b.useMemo(()=>{const q=[],I=i==="all"?8:void 0,D=E=>{if(i!=="all"&&i!==E)return;const $=d[E==="agents"?"agents":E==="tasks"?"tasks":E==="requirements"?"requirements":E==="projects"?"projects":"deliverables"],Y=I?$.slice(0,I):$;for(const W of Y)switch(E){case"agents":q.push({id:W.id,type:"agent",page:Se.TEAM,params:{agentId:W.id}});break;case"tasks":q.push({id:W.id,type:"task",page:Se.WORK,params:{openTask:W.id}});break;case"requirements":q.push({id:W.id,type:"requirement",page:Se.WORK,params:{openRequirement:W.id}});break;case"projects":q.push({id:W.id,type:"project",page:Se.WORK,params:{projectId:W.id}});break;case"deliverables":q.push({id:W.id,type:"deliverable",page:Se.DELIVERABLES,params:{openDeliverable:W.id}});break}I&&$.length>I&&q.push({id:`more_${E}`,type:"showMore",page:"",expandCategory:E,totalCount:$.length})};for(const E of _)D(E);return q},[d,i,_]),z=b.useCallback(q=>{if(q.type==="showMore"&&q.expandCategory){l(q.expandCategory),v(-1);return}R(q.page,q.params)},[R]);b.useEffect(()=>{const q=N.current;if(!q||g<0)return;const I=q.querySelector(`[data-idx="${g}"]`);I&&I.scrollIntoView({block:"nearest"})},[g]);const L=b.useCallback(q=>{if(q.key==="Escape"){e();return}if(q.key==="Tab"){q.preventDefault();const E=M.map(W=>W.id),$=E.indexOf(i),Y=q.shiftKey?$<=0?E.length-1:$-1:$>=E.length-1?0:$+1;l(E[Y]),v(-1);return}const I=q.ctrlKey&&q.key==="n"||q.key==="ArrowDown",D=q.ctrlKey&&q.key==="p"||q.key==="ArrowUp";if(I||D){q.preventDefault(),v(E=>{const $=F.length-1;return $<0?-1:I?E>=$?0:E+1:E<=0?$:E-1});return}q.key==="Enter"&&(q.preventDefault(),g>=0&&g<F.length&&z(F[g]))},[e,F,g,z,M,i]);b.useEffect(()=>(document.addEventListener("keydown",L),()=>document.removeEventListener("keydown",L)),[L]);const U=F.length>0;let K=0;return n.jsx("div",{ref:k,className:"fixed inset-0 bg-black/50 flex items-start justify-center z-50 pt-[8vh]",onClick:q=>{q.target===k.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:S,value:s,onChange:q=>T(q.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(Ef),y(!1),v(-1),S.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:M.map(q=>n.jsx("button",{onClick:()=>{l(q.id),v(-1)},className:`px-3 py-1.5 text-xs rounded-lg whitespace-nowrap transition-colors ${i===q.id?"bg-brand-600 text-white":"bg-surface-elevated text-fg-secondary hover:text-fg-primary"}`,children:q.label},q.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&&h&&!U&&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&&U&&n.jsx("div",{className:"space-y-4",children:_.map(q=>{if(i!=="all"&&i!==q)return null;const I=i==="all"?8:void 0,D=E=>{const $=K++,Y=E==="agents"?d.agents.length:E==="tasks"?d.tasks.length:E==="requirements"?d.requirements.length:E==="projects"?d.projects.length:d.deliverables.length;return n.jsxs("button",{"data-idx":$,onClick:()=>{l(E),v(-1)},className:`mt-1 w-full text-xs py-1.5 rounded-lg transition-colors ${$===g?"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:"查看全部"})," (",Y,")"]})};return q==="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:(I?d.agents.slice(0,I):d.agents).map(E=>{const $=K++;return n.jsxs("button",{"data-idx":$,onClick:()=>R(Se.TEAM,{agentId:E.id}),className:`w-full flex items-center gap-3 px-3 py-2 rounded-xl transition-colors text-left ${$===g?"bg-brand-600/15 ring-1 ring-brand-500/40":"hover:bg-surface-overlay"}`,children:[n.jsx(gr,{name:E.name||"Agent",avatarUrl:E.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:E.name}),n.jsx("div",{className:"text-xs text-fg-tertiary truncate",children:E.role||E.status})]}),n.jsx(gre,{status:E.status})]},E.id)})}),I&&d.agents.length>I&&D("agents")]},"agents"):q==="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:(I?d.tasks.slice(0,I):d.tasks).map(E=>{const $=K++;return n.jsxs("button",{"data-idx":$,onClick:()=>R(Se.WORK,{openTask:E.id}),className:`w-full flex items-center gap-3 px-3 py-2 rounded-xl transition-colors text-left ${$===g?"bg-brand-600/15 ring-1 ring-brand-500/40":"hover:bg-surface-overlay"}`,children:[n.jsx(xre,{status:E.status}),n.jsxs("div",{className:"flex-1 min-w-0",children:[n.jsx("div",{className:"text-sm text-fg-primary truncate",children:E.title}),n.jsxs("div",{className:"text-xs text-fg-tertiary truncate",children:[E.status," · ",E.priority||""]})]})]},E.id)})}),I&&d.tasks.length>I&&D("tasks")]},"tasks"):q==="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:(I?d.requirements.slice(0,I):d.requirements).map(E=>{const $=K++;return n.jsxs("button",{"data-idx":$,onClick:()=>R(Se.WORK,{openRequirement:E.id}),className:`w-full flex items-center gap-3 px-3 py-2 rounded-xl transition-colors text-left ${$===g?"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 ${E.status==="approved"?"text-green-500 bg-green-500/15":E.status==="pending"?"text-amber-500 bg-amber-500/15":E.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:E.title}),n.jsxs("div",{className:"text-xs text-fg-tertiary truncate",children:[E.status," · ",E.priority||""]})]})]},E.id)})}),I&&d.requirements.length>I&&D("requirements")]},"requirements"):q==="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:(I?d.projects.slice(0,I):d.projects).map(E=>{const $=K++;return n.jsxs("button",{"data-idx":$,onClick:()=>R(Se.WORK,{projectId:E.id}),className:`w-full flex items-center gap-3 px-3 py-2 rounded-xl transition-colors text-left ${$===g?"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:E.name}),E.description&&n.jsx("div",{className:"text-xs text-fg-tertiary truncate",children:E.description})]})]},E.id)})}),I&&d.projects.length>I&&D("projects")]},"projects"):q==="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:(I?d.deliverables.slice(0,I):d.deliverables).map(E=>{const $=K++;return n.jsxs("button",{"data-idx":$,onClick:()=>R(Se.DELIVERABLES,{openDeliverable:E.id}),className:`w-full flex items-center gap-3 px-3 py-2 rounded-xl transition-colors text-left ${$===g?"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:E.title}),n.jsxs("div",{className:"text-xs text-fg-tertiary truncate",children:[E.type," · ",E.status]})]})]},E.id)})}),I&&d.deliverables.length>I&&D("deliverables")]},"deliverables"):null})}),!m&&!h&&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 gre({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 xre({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 bre=b.memo(function({id:t,activePage:r,children:s}){return n.jsx("div",{className:"flex-1 overflow-hidden flex flex-col",style:{display:t===r?"flex":"none"},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}),Wx={};function yre(){const{t:e}=kt("common"),[t,r]=b.useState(Ul),[s,a]=b.useState(()=>!localStorage.getItem("markus_onboarded")),[i,l]=b.useState(!0),d=ks(),u=JK(),m=Zu({side:"left",defaultWidth:160,minWidth:140,maxWidth:400,collapsedWidth:64,storageKey:"markus_sidebar"}),[p,h]=b.useState(()=>new Set([Ul()])),[y,g]=b.useState("loading"),[v,S]=b.useState(null),[C,k]=b.useState(!1),[N,j]=b.useState(!1),[T,R]=b.useState(null),[M,_]=b.useState(!1),[F,z]=b.useState(null),[L,U]=b.useState(()=>{const O=localStorage.getItem("markus_update_dismissed");return O||null}),[K,q]=b.useState(!1);b.useEffect(()=>{if(d)return;const O=navigator.platform.toUpperCase().includes("MAC"),H=B=>{O&&B.metaKey&&!B.ctrlKey&&B.key==="p"?(B.preventDefault(),q(J=>!J)):!O&&B.ctrlKey&&!B.metaKey&&B.key==="p"&&(B.preventDefault(),q(J=>!J))},Z=()=>q(!0);return document.addEventListener("keydown",H),window.addEventListener("markus:open-search",Z),()=>{document.removeEventListener("keydown",H),window.removeEventListener("markus:open-search",Z)}},[d]);const I=b.useCallback(O=>{let H=il(O);d?H=JO[H]??H:H===Se.NOTIFICATIONS&&(H=Se.HOME);const Z=Ul(),B=window.location.hash.slice(1);B!==Z?Wx[Z]=B:delete Wx[Z];const J=H!==Se.WORK?Wx[H]:void 0;J&&J!==H?(history.pushState(null,"","#"+H),history.pushState(null,"","#"+J)):history.pushState(null,"","#"+H),window.dispatchEvent(new HashChangeEvent("hashchange")),r(H),h(Q=>Q.has(H)?Q:new Set([...Q,H]))},[d]);b.useEffect(()=>{Nt.setHandler(O=>I(O))},[I]);const D=b.useCallback(()=>{fetch("/api/settings/llm").then(O=>O.ok?O.json():null).then(O=>{if(O?.providers){const H=Object.values(O.providers).some(Z=>Z.configured);R(H)}}).catch(()=>{})},[]);b.useEffect(()=>{const O=new URLSearchParams(window.location.search),H=O.get("install");if(H&&Ul()!==Se.STORE){const J=O.get("type"),ee=J&&{agent:"agents",team:"teams",skill:"skills"}[J]||"agents";localStorage.setItem("markus_nav_installItem",H),localStorage.setItem("markus_nav_storeTab",ee),O.delete("install"),O.delete("type");const se=O.toString();window.history.replaceState(null,"",window.location.pathname+(se?`?${se}`:"")+"#store"),setTimeout(()=>Nt.navigate(Se.STORE,{storeTab:ee,installItem:H}),300)}le.auth.me().then(({user:J})=>{g(J),S(!0),gn.connect(J.id),D(),le.health().then(ee=>{ee.updateAvailable&&ee.latestVersion&&z({latestVersion:ee.latestVersion,currentVersion:ee.version})}).catch(()=>{});const Q=()=>{Bl(ga.builderArtifacts,()=>le.builder.artifacts.list()),Bl(ga.builderAgents,()=>le.agents.list()),Bl(ga.builderHubMyItems,()=>zn.myItems()),Bl(ga.builderInstalled,()=>le.builder.artifacts.installed()),Bl(ga.hubAgents,()=>zn.search({type:"agent",limit:50})),Bl(ga.hubTeams,()=>zn.search({type:"team",limit:50})),Bl(ga.hubSkills,()=>zn.search({type:"skill",limit:50}))};typeof requestIdleCallback=="function"?requestIdleCallback(Q,{timeout:5e3}):setTimeout(Q,3e3)}).catch(()=>{g(null),le.auth.status().then(({initialized:J})=>S(J)).catch(()=>S(!0))}),gn.connect();const Z=gn.on("notification",()=>{window.dispatchEvent(new CustomEvent("markus:notifications-changed"))}),B=()=>{const J=Ul();r(J),h(Q=>Q.has(J)?Q:new Set([...Q,J]))};return window.addEventListener("hashchange",B),()=>{Z(),gn.disconnect(),window.removeEventListener("hashchange",B)}},[]);const E=y!=="loading"&&y!==null?y:void 0,$=b.useMemo(()=>d?{[Se.HOME]:n.jsx(aw,{authUser:E}),[Se.TEAM]:n.jsx(Ek,{authUser:E}),[Se.BUILDER]:n.jsx(ore,{authUser:E}),[Se.SETTINGS]:n.jsx(Lk,{theme:u.mode,onThemeChange:u.setMode,authUser:E,onLogout:()=>g(null),onUserUpdated:O=>g(O)}),[Se.WORK]:n.jsx(yj,{authUser:E}),[Se.DELIVERABLES]:n.jsx(wj,{authUser:E}),[Se.NOTIFICATIONS]:n.jsx(Jne,{authUser:E}),[Se.REPORTS]:n.jsx(jj,{authUser:E}),[Se.SEARCH]:n.jsx(ere,{})}:{[Se.HOME]:n.jsx(aw,{authUser:E}),[Se.TEAM]:n.jsx(Ek,{authUser:E}),[Se.SETTINGS]:n.jsx(Lk,{theme:u.mode,onThemeChange:u.setMode,authUser:E,onLogout:()=>g(null),onUserUpdated:O=>g(O)}),[Se.STORE]:n.jsx(DG,{authUser:E}),[Se.BUILDER]:n.jsx(CS,{authUser:E}),[Se.WORK]:n.jsx(yj,{authUser:E}),[Se.DELIVERABLES]:n.jsx(wj,{authUser:E}),[Se.REPORTS]:n.jsx(jj,{authUser:E})},[E?.id,E?.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 W=(typeof window<"u"?window.location.hash:"").match(/^#invite\?token=([a-f0-9]+)/);return W?n.jsx(ure,{token:W[1],onComplete:()=>{window.location.hash="",localStorage.removeItem("markus_onboarded"),a(!0),k(!0),g("loading"),le.auth.me().then(O=>g(O.user)).catch(()=>g(null))}}):y===null?v===!1?n.jsx(cre,{onSetup:(O,H)=>{g(O),S(!0),k(!0),H&&(localStorage.removeItem("markus_onboarded"),a(!0))}}):n.jsx(dre,{onLogin:(O,H)=>{g(O),H?(localStorage.removeItem("markus_onboarded"),a(!0)):localStorage.getItem("markus_onboarded")||(localStorage.setItem("markus_onboarded","1"),a(!1))}}):N?n.jsx(mre,{onComplete:()=>j(!1),isFirstTime:!0}):s?n.jsx(lre,{theme:u.mode,onThemeChange:u.setMode,skipProfile:C,onComplete:()=>{localStorage.setItem("markus_onboarded","1"),a(!1),k(!1),D(),I(Se.HOME)}}):n.jsxs("div",{className:`flex h-dvh bg-surface-primary text-fg-primary overflow-x-hidden ${d?"flex-col":""}`,children:[!d&&t!==Se.SETTINGS&&n.jsxs(n.Fragment,{children:[n.jsx("div",{className:"relative z-40 shrink-0",style:{width:m.width},children:n.jsx(sre,{currentPage:t,onNavigate:O=>{I(O),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!==Se.SETTINGS&&t!==Se.SEARCH?"pb-14":""}`,children:[T===!1&&!M&&t!==Se.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:()=>{I(Se.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:()=>_(!0),className:"text-amber-500 hover:text-amber-600 text-xs",children:e("dismiss")})]})]}),F&&L!==F.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.jsxs("span",{className:d?"text-xs":"",children:["New version available: ",n.jsxs("strong",{children:["v",F.latestVersion]})," (current: v",F.currentVersion,")",!d&&n.jsxs("span",{className:"text-fg-tertiary ml-2",children:["— run ",n.jsx("code",{className:"bg-surface-overlay px-1.5 py-0.5 rounded text-xs font-mono",children:"npm i -g @markus-global/cli"})," to upgrade"]})]}),n.jsx("button",{onClick:()=>{U(F.latestVersion),localStorage.setItem("markus_update_dismissed",F.latestVersion)},className:"text-brand-400 hover:text-brand-300 text-xs shrink-0",children:e("dismiss")})]}),n.jsx("main",{className:"flex-1 overflow-hidden flex flex-col",children:Object.keys($).map(O=>p.has(O)?n.jsx(bre,{id:O,activePage:t,children:$[O]},O):null)})]}),d&&t!==Se.SETTINGS&&t!==Se.SEARCH&&n.jsx(are,{currentPage:t,onNavigate:I,userId:E?.id}),d&&n.jsx(o_,{authUser:E,onNavigate:I}),!d&&K&&n.jsx(pre,{onClose:()=>q(!1),currentPage:t})]})}l9.createRoot(document.getElementById("root")).render(n.jsx(b.StrictMode,{children:n.jsx(yre,{})}));export{c0 as g};