@markus-global/cli 0.7.3-rc.0 → 0.7.3-rc.2

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
  `)}),ot.toolCalls?.length)for(let Wn=0;Wn<ot.toolCalls.length;Wn++){const ar=ot.toolCalls[Wn];wn.push({type:"tool",key:`${ar.tool}_${Wn}`,tool:ar.tool,status:ar.status==="error"?"error":"done",args:ar.arguments,result:ar.result,durationMs:ar.durationMs})}wn.length>0&&(wn.push({type:"text",content:We}),an.segments=wn)}let On;if(Pe.startsWith("notes:"))On=`dm:${Pe.slice(6)}`;else if(Pe.startsWith("dm:")){const wn=Pe.slice(3).split(":");On=`dm:${wn.find(ar=>ar!==(t?.id??""))??wn[0]??""}`}else On=`ch:${Pe}`;yn(On,wn=>[...wn,an]),At==="agent"&&On===`ch:${ne}`&&mn(wn=>{const Wn=wn.filter(ar=>ar.id!==mt);return Wn.length===0&&Tn.current&&(clearTimeout(Tn.current),Tn.current=null),Wn})}),[r,yn,t?.id,ne]),b.useEffect(()=>r?void 0:fn.on("chat:agent_no_response",je=>{const Ie=je.payload,Pe=Ie.channel??"",At=Ie.agentId??"";Pe&&At&&`ch:${ne}`==`ch:${Pe}`&&mn(We=>{const mt=We.filter(pt=>pt.id!==At);return mt.length===0&&Tn.current&&(clearTimeout(Tn.current),Tn.current=null),mt})}),[r,ne]),b.useEffect(()=>r?void 0:fn.on("chat:proactive_message",je=>{const Ie=je.payload,Pe=Ie.targetUserId;if(Pe&&Pe!==t?.id)return;const At=Ie.agentId??"",We=Ie.agentName??a("page.fallbackAgent"),mt=Ie.message??"";Ie.sessionId;const pt=Ie.metadata??{};if(!At||!mt)return;const ot=!!pt.activityLog||mt.startsWith("[ACTIVITY:"),{cleaned:jt,priority:an}=CS(mt),On=!!pt.notifyUser||jt!==mt,wn={id:`proactive_${Date.now()}`,sender:"agent",text:jt,time:new Date().toLocaleTimeString(),agentName:We,agentId:At,...On?{isNotification:!0,notifyPriority:pt.priority??an}:{},...ot?{isActivityLog:!0,activityType:pt.activityType,outcome:pt.outcome,mailboxItemId:pt.mailboxItemId,taskId:pt.taskId,requirementId:pt.requirementId}:{},...!ot&&pt.taskId?{taskId:pt.taskId}:{},...!ot&&pt.requirementId?{requirementId:pt.requirementId}:{}},Wn=Ms("direct",At,"","");yn(Wn,ar=>[...ar,wn])}),[r,yn,a]),_t.find(te=>te.id===_r),b.useEffect(()=>{dr(null)},[ue]);const Ta=te=>hW(te),Ni=()=>{xs.current?.abort(),xs.current=null;const te=Je.current;ct.current.delete(te),at.current.delete(te),Nn(!1),xr([])},ae=async(te,je)=>{const Ie=(te??xt).trim();if(!Ie&&Zn.length===0||ze==="direct"&&!ue)return;if(yr.current=!0,Cs.current=!1,Vt){xs.current?.abort(),xs.current=null;const ot=Je.current;ct.current.delete(ot),at.current.delete(ot),yn(ot,jt=>{const an=[...jt];for(let On=an.length-1;On>=0;On--)if(an[On].sender==="agent"&&!an[On].isStopped&&!an[On].isError){const wn=an[On],Wn=(wn.segments??[]).map(ar=>ar.type==="tool"&&ar.status==="running"?{...ar,status:"stopped"}:ar);an[On]={...wn,isStopped:!0,segments:Wn};break}return an}),Nn(!1),xr([]),await new Promise(jt=>setTimeout(jt,50))}const Pe=Zn.length>0?Zn.map(ot=>ot.dataUrl):void 0,At=Zn.length>0?Zn.map(ot=>ot.name):void 0,We=Ms(ze,ue,ne,Be),mt=ut;te||Ve(""),br([]),zr(!1),it(null);const pt=ze==="dm";if(ct.current.add(We),at.current.set(We,[]),Je.current===We&&!pt&&(Nn(!0),xr([])),ze==="dm"){const ot=wa(t?.id??"",Be),jt=`opt_${Date.now()}`,an={id:jt,sender:"user",text:Ie,time:new Date().toLocaleTimeString()};mt&&(an.replyToId=mt.id,an.replyToSender=mt.sender,an.replyToText=mt.text),yn(We,On=>[...On,an]);try{const On=await de.channels.sendMessage(ot,{text:Ie,senderName:t?.name??a("page.fallbackYou"),senderId:t?.id,mentions:[],orgId:"default",humanOnly:!0});yn(We,wn=>{const Wn=wn.filter(Pr=>Pr.id!==jt),ar=[];return On.userMessage&&ar.push($l(On.userMessage,t?.id)),ar.length>0?[...Wn,...ar]:wn})}catch(On){yn(We,wn=>[...wn,{id:`err_${Date.now()}`,sender:"agent",text:a("page.errorWithMessage",{message:String(On)}),time:new Date().toLocaleTimeString(),agentName:a("page.systemName"),isError:!0}])}ct.current.delete(We),Je.current===We&&Nn(!1)}else if(ze==="channel"){const ot=`opt_${Date.now()}`,jt={id:ot,sender:"user",text:Ie,time:new Date().toLocaleTimeString()};mt&&(jt.replyToId=mt.id,jt.replyToSender=mt.sender,jt.replyToText=mt.text),yn(We,wn=>[...wn,jt]);const an=Ta(Ie),On=Xe.find(wn=>wn.channelKey===ne);if(ne.startsWith("group:")){const wn=[];if(On?.members){for(const Wn of On.members)if(Wn.type==="agent"){const ar=d.find(Pr=>Pr.id===Wn.id);ar&&wn.push({id:ar.id,name:ar.name,avatarUrl:ar.avatarUrl})}}wn.length>0&&(Tn.current&&clearTimeout(Tn.current),mn(wn),Tn.current=setTimeout(()=>mn([]),12e4))}try{const wn=await de.channels.sendMessage(ne,{text:Ie,senderName:t?.name??a("page.fallbackYou"),mentions:an,senderId:t?.id,orgId:"default",replyToId:mt?.id});yn(We,Wn=>{const ar=Wn.filter(Si=>Si.id!==ot),Pr=[];return wn.userMessage&&Pr.push($l(wn.userMessage,t?.id)),wn.agentMessage&&Pr.push($l(wn.agentMessage,t?.id)),Pr.length>0?[...ar,...Pr]:Wn})}catch(wn){const Wn=Tk(wn,a)||a("page.errorWithMessage",{message:String(wn)});yn(We,ar=>[...ar,{id:`err_${Date.now()}`,sender:"agent",text:Wn,time:new Date().toLocaleTimeString(),agentName:a("page.systemName"),isError:!0}]),Tn.current&&(clearTimeout(Tn.current),Tn.current=null),mn([])}ct.current.delete(We),Je.current===We&&Nn(!1)}else{const ot=`a_${Date.now()}`;if(je?.isResume){const Bt=new Date().toISOString();yn(We,Qt=>[...Qt,{id:ot,sender:"agent",text:"",time:new Date().toLocaleTimeString(),rawCreatedAt:Bt,segments:[]}])}else{const Bt=new Date().toISOString(),Qt={id:`u_${Date.now()}`,sender:"user",text:Ie,time:new Date().toLocaleTimeString()};Pe?.length&&(Qt.images=Pe),mt&&(Qt.replyToId=mt.id,Qt.replyToSender=mt.sender,Qt.replyToText=mt.text),yn(We,It=>[...It,Qt,{id:ot,sender:"agent",text:"",time:new Date().toLocaleTimeString(),rawCreatedAt:Bt,segments:[]}])}let jt=!1;const an=Bt=>{yn(We,Qt=>{const It=[...Qt],Mt=It.findIndex(Ea=>Ea.id===ot);if(Mt<0)return Qt;const Lt=It[Mt].segments??[],Ot=Lt[Lt.length-1],Yt=Ot?.type==="text"?Ot.thinking??"":"";let ln="",_n="",er=Bt;for(;er.length>0;)if(jt){const Ea=er.indexOf("</think>");Ea>=0?(ln+=er.slice(0,Ea),er=er.slice(Ea+8),jt=!1):(ln+=er,er="")}else{const Ea=er.indexOf("<think>");Ea>=0?(_n+=er.slice(0,Ea),er=er.slice(Ea+7),jt=!0):(_n+=er,er="")}const Is=Yt+ln||void 0,Ao=Ot?.type==="text"?[...Lt.slice(0,-1),{type:"text",content:Ot.content+_n,thinking:Is,createdAt:Ot.createdAt}]:[...Lt,{type:"text",content:_n,thinking:Is,createdAt:new Date().toISOString()}];return It[Mt]={...It[Mt],text:It[Mt].text+_n,segments:Ao},It})},On=Bt=>{if(Bt.type==="session_start"&&Bt.sessionId){Je.current===We&&(Ce(Bt.sessionId),qt(Qt=>Qt.map(It=>It.id===on?{...It,id:Bt.sessionId}:It)));return}yn(We,Qt=>{const It=[...Qt],Mt=It.findIndex(Ot=>Ot.id===ot);if(Mt<0)return Qt;const Lt=[...It[Mt].committedSegments??[]];return Bt.type==="thinking_commit"?Lt.push({type:"text",content:"",thinking:Bt.content,createdAt:Bt.createdAt}):Lt.push({type:"text",content:Bt.content,createdAt:Bt.createdAt}),It[Mt]={...It[Mt],committedSegments:Lt},It})},wn=Bt=>{(Bt.phase==="start"||Bt.phase==="end")&&Kn(We,{...Bt,phase:Bt.phase,ts:Date.now()}),Bt.phase==="start"?yn(We,Qt=>{const It=[...Qt],Mt=It.findIndex(er=>er.id===ot);if(Mt<0)return Qt;const Lt=[...It[Mt].segments??[]];let Ot=!1;if(Bt.arguments)for(let er=Lt.length-1;er>=0;er--){const Is=Lt[er];if(Is.type==="tool"&&Is.tool===Bt.tool&&Is.status==="running"){Lt[er]={...Is,args:Bt.arguments},Ot=!0;break}}const Yt=`${Bt.tool}_${Date.now()}`,ln=new Date().toISOString();Ot||Lt.push({type:"tool",key:Yt,tool:Bt.tool,status:"running",args:Bt.arguments,createdAt:ln});const _n=[...It[Mt].committedSegments??[]];return Bt.arguments!==void 0&&_n.push({type:"tool",key:Yt,tool:Bt.tool,status:"running",args:Bt.arguments,createdAt:ln}),It[Mt]={...It[Mt],segments:Lt,committedSegments:_n},It}):Bt.phase==="output"?yn(We,Qt=>{const It=[...Qt],Mt=It.findIndex(Ot=>Ot.id===ot);if(Mt<0)return Qt;const Lt=[...It[Mt].segments??[]];for(let Ot=Lt.length-1;Ot>=0;Ot--){const Yt=Lt[Ot];if(Yt.type==="tool"&&Yt.tool===Bt.tool&&Yt.status==="running"){Lt[Ot]={...Yt,liveOutput:(Yt.liveOutput??"")+(Bt.output??"")};break}}return It[Mt]={...It[Mt],segments:Lt},It}):Bt.phase==="subagent_progress"&&Bt.subagentEvent?yn(We,Qt=>{const It=[...Qt],Mt=It.findIndex(Ot=>Ot.id===ot);if(Mt<0)return Qt;const Lt=[...It[Mt].segments??[]];for(let Ot=Lt.length-1;Ot>=0;Ot--){const Yt=Lt[Ot];if(Yt.type==="tool"&&(Yt.tool==="spawn_subagent"||Yt.tool==="spawn_subagents")&&Yt.status==="running"){Lt[Ot]={...Yt,subagentLogs:[...Yt.subagentLogs??[],Bt.subagentEvent]};break}}return It[Mt]={...It[Mt],segments:Lt},It}):yn(We,Qt=>{const It=[...Qt],Mt=It.findIndex(ln=>ln.id===ot);if(Mt<0)return Qt;const Lt=new Date().toISOString(),Ot=[...It[Mt].segments??[]];for(let ln=Ot.length-1;ln>=0;ln--){const _n=Ot[ln];if(_n.type==="tool"&&_n.tool===Bt.tool&&_n.status==="running"){Ot[ln]={..._n,status:Bt.success===!1?"error":"done",args:Bt.arguments,result:Bt.result,error:Bt.error,durationMs:Bt.durationMs,liveOutput:void 0,createdAt:Lt};break}}const Yt=[...It[Mt].committedSegments??[]];for(let ln=Yt.length-1;ln>=0;ln--){const _n=Yt[ln];if(_n.type==="tool"&&_n.tool===Bt.tool&&_n.status==="running"){Yt[ln]={..._n,status:Bt.success===!1?"error":"done",args:Bt.arguments,result:Bt.result,error:Bt.error,durationMs:Bt.durationMs,liveOutput:void 0,createdAt:Lt};break}}return It[Mt]={...It[Mt],segments:Ot,committedSegments:Yt},It})},Wn=new AbortController;xs.current=Wn;try{const Bt=rn===on?null:rn,Qt=await de.agents.messageStream(ue,Ie,an,wn,Wn.signal,Pe,Bt,je?.isRetry,je?.isResume,On,At);Je.current===We&&(Qt.segments?.length&&yn(We,It=>{const Mt=[...It],Lt=Mt.findIndex(ln=>ln.id===ot);if(Lt<0)return It;const Ot=Qt.segments.map((ln,_n)=>ln.type==="tool"?{type:"tool",key:`${ln.tool}_${_n}`,tool:ln.tool,status:ln.status,args:ln.arguments,result:ln.result,error:ln.error,durationMs:ln.durationMs,createdAt:ln.createdAt}:{type:"text",content:ln.content,thinking:ln.thinking,createdAt:ln.createdAt});let Yt=Qt.content||Mt[Lt].text;return Yt||(Yt=Ot.filter(ln=>ln.type==="text").map(ln=>ln.content).join("")),Mt[Lt]={...Mt[Lt],text:Yt,segments:Ot,committedSegments:Ot},Mt}),Qt.segments?.length||yn(We,It=>{const Mt=[...It],Lt=Mt.findIndex(er=>er.id===ot);if(Lt<0)return It;const Ot=Mt[Lt],Yt=Ot.committedSegments??[],_n=Yt.filter(er=>er.type==="text"&&!!er.content).map(er=>er.content).join("")||Qt.content||Ot.text;return(Yt.length>0||_n)&&(Mt[Lt]={...Ot,text:_n,segments:Yt.length>0?Yt:Ot.segments}),Mt}),Qt.sessionId&&(Ce(Qt.sessionId),qt(It=>It.map(Mt=>Mt.id===on?{...Mt,id:Qt.sessionId}:Mt))),Ga(ue).then(It=>{if(Je.current===We&&(Nr(It),Qt.sessionId)){const Mt=It.find(Lt=>Lt.id===Qt.sessionId);Mt&&qt(Lt=>Lt.some(Yt=>Yt.id===Mt.id)?Lt.map(Yt=>Yt.id===Mt.id?Mt:Yt):[Mt,...Lt.filter(Yt=>Yt.id!==on)])}}))}catch(Bt){const Qt=Bt?.sessionId;Qt&&ze==="direct"&&Je.current===We&&(Ce(Qt),qt(Mt=>Mt.map(Lt=>Lt.id===on?{...Lt,id:Qt}:Lt)),Ga(ue).then(Mt=>{if(Je.current!==We)return;Nr(Mt);const Lt=Mt.find(Ot=>Ot.id===Qt);Lt&&qt(Ot=>Ot.some(ln=>ln.id===Lt.id)?Ot.map(ln=>ln.id===Lt.id?Lt:ln):[Lt,...Ot])}));const It=Tk(Bt,a);It?yn(We,Mt=>{const Lt=[...Mt],Ot=Lt.findIndex(Yt=>Yt.id===ot);if(Ot>=0){const Yt=Lt[Ot].segments??[];Lt[Ot]={...Lt[Ot],text:It,isError:!0,segments:[...Yt,{type:"text",content:It}]}}return Lt}):yn(We,Mt=>{const Lt=[...Mt],Ot=Lt.findIndex(Yt=>Yt.id===ot);if(Ot>=0){const Yt=Lt[Ot];if(!(Yt.text||Yt.segments&&Yt.segments.length>0&&Yt.segments.some(_n=>_n.type==="text"&&_n.content||_n.type==="tool")))return Mt.filter(_n=>_n.id!==ot);Lt[Ot]={...Yt,isStopped:!0}}return Lt})}yn(We,Bt=>{const Qt=[...Bt],It=Qt.findIndex(Mt=>Mt.id===ot);if(It>=0){const Mt=(Qt[It].segments??[]).map(Lt=>Lt.type==="tool"&&Lt.status==="running"?{...Lt,status:"stopped"}:Lt);Qt[It]={...Qt[It],segments:Mt}}return Qt}),Wn.signal.aborted&&yn(We,Bt=>{const Qt=[...Bt],It=Qt.findIndex(Mt=>Mt.id===ot);if(It>=0){const Mt=Qt[It];if(!(Mt.text||Mt.segments&&Mt.segments.length>0&&Mt.segments.some(Ot=>Ot.type==="text"&&Ot.content||Ot.type==="tool")))return Bt.filter(Ot=>Ot.id!==ot);Qt[It]={...Mt,isStopped:!0}}return Qt});const Pr=(Ke.current.get(We)??[]).find(Bt=>Bt.id===ot),Si=rn&&rn!==on?rn:null,S0=Pr?.text||Pr?.segments?.some(Bt=>Bt.type==="text"&&Bt.content||Bt.type==="tool");Pr&&!S0&&ze==="direct"&&Si&&!Wn.signal.aborted&&await(async(Qt,It)=>{for(let Mt=0;Mt<Qt;Mt++){await new Promise(Lt=>setTimeout(Lt,It));try{const Ot=(await de.sessions.getMessages(Si,2)).messages.find(Yt=>Yt.role==="assistant");if(Ot?.content){const Yt=Tx(Ot);yn(We,ln=>{const _n=[...ln],er=_n.findIndex(Is=>Is.id===ot);return er>=0&&(_n[er]={..._n[er],text:Yt.text,segments:Yt.segments}),_n});return}}catch{}}})(5,3e3),(xs.current===Wn||xs.current===null)&&(xs.current=null,ct.current.delete(We),at.current.delete(We),Je.current===We&&(Nn(!1),xr([])))}};li.current=ae;const[Ye,lt]=b.useState(null),[,Tt]=b.useState(new Set),en=b.useMemo(()=>{for(let te=rt.length-1;te>=0;te--)if(rt[te]?.sender==="agent"&&!rt[te]?.isActivityLog)return rt[te].id;return null},[rt]),pr=b.useCallback(te=>{const je=te.segments?te.segments.filter(Ie=>Ie.type==="text").map(Ie=>Ie.content).join(`
654
654
  `):te.text;navigator.clipboard.writeText(je),lt(te.id),setTimeout(()=>lt(Ie=>Ie===te.id?null:Ie),2e3)},[]),Cn=b.useCallback(te=>{const je=Je.current,Ie=Ke.current.get(je)??rt,Pe=Ie.findIndex(ot=>ot.id===te.id);if(Pe<0)return;let At=null;for(let ot=Pe-1;ot>=0;ot--)if(Ie[ot]?.sender==="user"){At=Ie[ot];break}const We=At?.text??"";if(!We)return;if(Pe<Ie.length-1){const ot=Ie.length-1-Pe;if(!window.confirm(ot===1?a("page.retryConfirmSingular"):a("page.retryConfirmPlural",{count:ot})))return}const pt=At&&Pe>0&&Ie[Pe-1]?.id===At.id;yn(je,ot=>{const jt=ot.findIndex(an=>an.id===(pt?At.id:te.id));return jt>=0?ot.slice(0,jt):ot}),ae(We,{isRetry:!0})},[rt,yn,a]),Et=b.useCallback(te=>{const je=Je.current;(Ke.current.get(je)??rt).findIndex(At=>At.id===te.id)<0||(yn(je,At=>{const We=[...At],mt=We.findIndex(jt=>jt.id===te.id);if(mt<0)return At;const pt=We[mt],ot=[...pt.segments??[]];for(;ot.length>0;){const jt=ot[ot.length-1];if(jt.type==="tool"&&(jt.status==="stopped"||jt.status==="running"))ot.pop();else if(jt.type==="text"&&!jt.content)ot.pop();else break}return We[mt]={...pt,segments:ot,isStopped:!1,isError:!1},We}),ae("[Continue from where you left off. Do not repeat content already generated.]",{isResume:!0}))},[rt,yn]),Ds=b.useCallback(te=>{const je=te.sender==="user"?t?.name??a("page.fallbackYou"):te.agentName??a("page.fallbackAgent");if(it({id:te.id,sender:je,text:te.text.slice(0,120)}),ze==="channel"&&te.sender==="agent"&&te.agentName){const Ie=`@${te.agentName} `;Ve(Pe=>Pe.startsWith(Ie)?Pe:Ie+Pe)}Xt.current?.focus()},[t?.name,ze,a]),Ls=async te=>{Ce(te.id),$t(!1),Ln(!1),Jn.current=null;const je=Je.current;Ke.current.delete(je),ht([]),qt(Ie=>Ie.some(Pe=>Pe.id===te.id)?Ie:[...Ie,te]),await Ys(te.id,je)},Fs=te=>{if(qt(je=>je.filter(Ie=>Ie.id!==te)),rn===te){const je=Wt.filter(Ie=>Ie.id!==te);je.length>0?Ls(je[je.length-1]):qr()}},qr=()=>{Ce(on);const te=Je.current;Ke.current.delete(te),ht([]),Ln(!1),Jn.current=null,$t(!1),qt(je=>{const Ie=je.filter(Pe=>Pe.id!==on);return[{id:on,agentId:ue??"",userId:null,title:a("page.newChat"),createdAt:new Date().toISOString(),lastMessageAt:new Date().toISOString()},...Ie]})},ie=te=>{if(Ve(te),ze!=="channel"){zr(!1);return}const je=Xt.current?.selectionStart??te.length,Ie=te.slice(0,je),Pe=Ie.lastIndexOf("@");if(Pe>=0){const At=Pe===0?"":Ie[Pe-1];if(Pe===0||/[\s\n,,。!?!?;;::、()()\[\]【】]/.test(At)){const mt=Ie.slice(Pe+1);if(!mt.includes(" ")&&!mt.includes(`
655
- `)){zr(!0),Vi(mt.toLowerCase()),Es(0);return}}}zr(!1)},_e=te=>{const je=Xt.current?.selectionStart??xt.length,Pe=xt.slice(0,je).lastIndexOf("@"),At=xt.slice(je),We=te.includes(" ")?`@[${te}]`:`@${te}`,mt=xt.slice(0,Pe)+We+" "+At;Ve(mt),zr(!1),Es(0);const pt=Pe+We.length+1;requestAnimationFrame(()=>{Xt.current?.setSelectionRange(pt,pt)})},Ze=10*1024*1024,An=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),[]),bs=te=>te.dataUrl.startsWith("data:image/"),$h=(te,je)=>{if(bs({dataUrl:je}))return null;const Ie=te.split(".").pop()?.toLowerCase()??"";return{pdf:"📄",docx:"📝",doc:"📝",xlsx:"📊",xls:"📊",pptx:"📎",csv:"📊",json:"🔧",xml:"🔧",html:"🌐",epub:"📚"}[Ie]??"📁"},bl=b.useCallback(te=>{const je=Array.from(te).filter(Aa);if(je.length!==0)for(const Ie of je){if(Ie.size>Ze)continue;const Pe=new FileReader;Pe.onload=()=>{const At=Pe.result;br(We=>We.length>=An||We.some(mt=>mt.dataUrl===At)?We:[...We,{id:`img_${Date.now()}_${Math.random().toString(36).slice(2,6)}`,dataUrl:At,name:Ie.name}])},Pe.readAsDataURL(Ie)}},[Aa]),Bh=b.useCallback(te=>{br(je=>je.filter(Ie=>Ie.id!==te))},[]),Hh=b.useCallback(te=>{const je=te.clipboardData?.files;if(je&&je.length>0){const Ie=Array.from(je).filter(Aa);Ie.length>0&&(te.preventDefault(),bl(Ie))}},[bl,Aa]),Td=b.useCallback(te=>{te.preventDefault();const je=te.dataTransfer?.files;je&&je.length>0&&bl(Array.from(je).filter(Aa))},[bl,Aa]),yl=b.useCallback(te=>{te.preventDefault()},[]),Jr=d.find(te=>te.id===ue),vl=t?.name??a("page.fallbackYou"),Ad=rt[rt.length-1],k0=Vt&&Ad?.sender==="agent",j0=$n&&Ad?.sender==="agent",Ed=b.useMemo(()=>{if(ze!=="channel")return null;if(ne.startsWith("group:custom:")){const je=Xe.find(Ie=>Ie.channelKey===ne);return je?.members?new Set(je.members.filter(Ie=>Ie.type==="agent").map(Ie=>Ie.id)):null}if(!ur)return null;const te=vn.find(je=>je.id===ur);return te?new Set(te.members.filter(je=>je.type==="agent").map(je=>je.id)):null},[ze,ne,ur,vn,Xe]),oa=d.filter(te=>Ed?Ed.has(te.id):!0).filter(te=>te.name.toLowerCase().includes(Ka)),Md=m.find(te=>te.id===Be),Rd=Be===t?.id||!Be,Xs=Xe.find(te=>te.channelKey===ne);b.useEffect(()=>{if(r||!ne.startsWith("group:custom:"))return;const te=Xe.find(je=>je.channelKey===ne);!te||te.members||de.groupChats.getById(te.id).then(je=>{je.chat.members&&bt(Ie=>Ie.map(Pe=>Pe.id===te.id?{...Pe,members:je.chat.members}:Pe))}).catch(()=>{})},[r,ne,Xe]);const Dd=ze==="channel"?Xs?.name??ne:ze==="direct"?Jr?.name??a("page.selectAgent"):ze==="dm"?Rd?a("chat.myNotes"):Md?.name??a("page.directMessage"):a("page.chatTitle"),N0=ze==="channel"?Xs?a("page.placeholder.channel",{name:Xs.name}):a("page.placeholder.channelWithMention",{name:ne}):ze==="dm"?Rd?a("page.placeholder.dmSelf"):a("page.placeholder.dmOther",{name:Md?.name??""}):a(ue?"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(vW,{authUser:t,agents:d,teams:vn,humans:m,tasks:_t,externalAgents:or,groupChats:Xe,chatMode:ze,selectedAgent:ue,activeChannel:ne,activeDmUserId:Be,previewMode:r,onSelectAgent:te=>{ce("direct"),Me(te),_("chat"),sn(!1),g&&T()},onSelectChannel:te=>{ce("channel"),he(te),_("chat"),sn(!1),g&&T()},onSelectDm:te=>{ce("dm"),Se(te),_("chat"),sn(!1),g&&T()},onSelectTeam:te=>{const je=Xe.find(Ie=>Ie.type==="team"&&Ie.teamId===te);g?D(te):je&&(ce("channel"),he(je.channelKey),_("chat"),sn(!1),!L&&!I&&U(!0))},selectedTeamId:ur??(ze==="direct"&&Jr?.teamId?Jr.teamId:null),onRefreshTeams:Ar,onRefreshAgents:Qr,onRefreshHumans:Sa,onRefreshGroupChats:Fr,onViewProfile:Qe,onManageGroupMembers:te=>{ce("channel"),he(te),_("chat"),sn(!0),g&&T()},unreadByAgent:Xr,unreadByChannel:Wa,width:g?void 0:z.width,onResizeStart:g?void 0:z.onResizeStart,hidden:g&&k!=="roster",initialLoading:h}),g&&k==="team"&&N&&(()=>{const te=vn.find(Pe=>Pe.id===N);if(!te)return null;const je=d.filter(Pe=>Pe.teamId===N),Ie=Xe.find(Pe=>Pe.type==="team"&&Pe.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=Te.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||je.length})})]})]})]}),n.jsxs("div",{className:"flex-1 overflow-y-auto px-3 py-3 space-y-1",children:[Ie&&(()=>{const Pe=Wa[Ie.channelKey]??0;return n.jsxs("button",{onClick:()=>{ce("channel"),he(Ie.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:Ie.name}),n.jsx("div",{className:"text-[10px] text-fg-tertiary",children:a("chat.groupChat")})]}),Pe>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:Pe}):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"})})]})})(),je.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")}),je.map(Pe=>{const At=Xr.get(Pe.id)??0;return n.jsxs("button",{onClick:()=>{ce("direct"),Me(Pe.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:Pe.name||"Agent",avatarUrl:Pe.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:Pe.name}),n.jsx("div",{className:"text-[10px] text-fg-tertiary truncate",children:Pe.role||Pe.status})]}),At>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:At}):n.jsx("span",{className:`w-2 h-2 rounded-full shrink-0 ${Pe.status==="active"||Pe.status==="idle"?"bg-green-500":Pe.status==="working"||Pe.status==="busy"?"bg-blue-500":Pe.status==="paused"?"bg-amber-500":"bg-gray-400"}`})]},Pe.id)})]})]})]})})(),L&&!I&&!g&&(()=>{const te=ur??(ze==="direct"?Jr?.teamId:void 0);if(!te)return null;const je=vn.find(Pe=>Pe.id===te);if(!je)return null;const Ie=Xe.find(Pe=>Pe.type==="team"&&Pe.teamId===te);return n.jsx(dk,{team:je,agents:d,humans:m,authUser:t,groupChat:Ie,chatMode:ze,selectedAgent:ue,activeChannel:ne,teams:vn,onSelectAgent:Pe=>{ce("direct"),Me(Pe),_("chat"),sn(!1)},onSelectChannel:Pe=>{ce("channel"),he(Pe),_("chat"),sn(!1)},onSelectDm:Pe=>{ce("dm"),Se(Pe),_("chat"),sn(!1)},onBack:()=>U(!1),onViewProfile:Qe,onRefreshAgents:Qr,onRefreshTeams:Ar,unreadByAgent:Xr,width:W.width,onResizeStart:W.onResizeStart})})(),E&&!g&&(()=>{const te=ur??(ze==="direct"?Jr?.teamId:void 0);if(!te)return null;const je=vn.find(Pe=>Pe.id===te);if(!je)return null;const Ie=Xe.find(Pe=>Pe.type==="team"&&Pe.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:W.width+8},children:n.jsx(dk,{team:je,agents:d,humans:m,authUser:t,groupChat:Ie,chatMode:ze,selectedAgent:ue,activeChannel:ne,teams:vn,onSelectAgent:Pe=>{ce("direct"),Me(Pe),_("chat"),sn(!1),$(!1)},onSelectChannel:Pe=>{ce("channel"),he(Pe),_("chat"),sn(!1),$(!1)},onSelectDm:Pe=>{ce("dm"),Se(Pe),_("chat"),sn(!1),$(!1)},onBack:()=>$(!1),onViewProfile:Pe=>{Qe(Pe),$(!1)},onRefreshAgents:Qr,onRefreshTeams:Ar,unreadByAgent:Xr,width:W.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:Dd}),ze==="direct"&&Jr&&n.jsx(Dk,{agent:Jr,tasks:_t,onViewProfile:Qe})]}),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)||Oe()},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(ze==="channel"?"page.teamTab":"page.profileTab")}),n.jsx("div",{className:"flex-1"}),ze==="channel"&&Xs?.type==="custom"&&n.jsxs("button",{onClick:()=>sn(!Gt),className:`text-[11px] px-2 py-1 rounded-md font-medium shrink-0 flex items-center gap-1 ${Gt?"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]}),ze==="direct"&&!uo(M)&&n.jsxs(n.Fragment,{children:[n.jsx("button",{onClick:qr,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:Dt,onClick:()=>$t(!Ct),className:`p-1 rounded-md transition-colors shrink-0 ${Ct?"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=ur?vn.find(jt=>jt.id===ur):void 0,je=ze==="direct"&&ue?VW:ze==="channel"&&ur?KW:["chat"],Ie=async()=>{const jt=se.trim();if(!jt){ee(!1);return}try{ze==="direct"&&ue?(await de.agents.updateConfig(ue,{name:jt}),Qr()):ze==="channel"&&ur&&(await de.teams.update(ur,{name:jt}),Ar())}catch{}ee(!1)},Pe=async()=>{try{ze==="direct"&&ue?(await de.agents.updateConfig(ue,{roleDescription:De}),Qr()):ze==="channel"&&ur&&(await de.teams.update(ur,{description:De}),Ar())}catch{}be(!1)},At=ze==="direct"?Jr?.name:ze==="channel"?te?.name??Xs?.name:Md?.name??"",We=ze==="direct"?Jr?.role||"":ze==="channel"&&te?.description||"",mt=ze==="direct"?Jr?.avatarUrl:void 0,pt=At||"U",ot=ze==="direct"&&ue||ze==="channel"&&ur;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)&&(ze==="channel"&&ur||ze==="direct"&&Jr?.teamId)&&n.jsx("button",{onClick:X,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"})]})}),ot&&(ze==="channel"&&ur?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:pt,avatarUrl:mt,size:36,className:"rounded-xl shrink-0"})),ot?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:ke,value:se,onChange:jt=>Y(jt.target.value),onBlur:Ie,onKeyDown:jt=>{jt.key==="Enter"&&Ie(),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:()=>{Y(At??""),ee(!0)},title:"Click to edit name",children:At}),ze==="direct"&&Jr&&n.jsx(Dk,{agent:Jr,tasks:_t,onViewProfile:Qe})]}),(ze==="direct"||ze==="channel"&&ur)&&(me?n.jsx("input",{ref:pe,value:De,onChange:jt=>He(jt.target.value),onBlur:Pe,onKeyDown:jt=>{jt.key==="Enter"&&Pe(),jt.key==="Escape"&&be(!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:()=>{He(We),be(!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:Dd}),ze==="dm"&&n.jsx("span",{className:"text-xs text-fg-tertiary",children:Rd?a("page.privateNotepad"):""})]}),n.jsxs("div",{className:"ml-auto flex items-center gap-2 shrink-0",children:[ze==="channel"&&Xs?.type==="custom"&&n.jsxs("button",{onClick:()=>sn(!Gt),className:`text-xs px-2.5 py-1 rounded-md border transition-colors flex items-center gap-1.5 ${Gt?"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]}),ze==="direct"&&Jr&&M==="chat"&&n.jsxs("div",{className:"flex items-center gap-1.5",children:[n.jsx("button",{onClick:qr,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:Dt,onClick:()=>$t(!Ct),className:`p-1.5 rounded-md transition-colors ${Ct?"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"})})})]})]})]}),je.length>1&&n.jsx("div",{className:"flex items-center gap-1 px-4 pb-1.5 overflow-x-auto scrollbar-hide",children:je.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:GW(jt)}),WW(jt,a)]},jt))})]})})(),ze==="direct"&&ue&&M==="chat"&&Wt.length>1&&n.jsx("div",{className:"flex items-center gap-0 px-3 overflow-x-auto scrollbar-hide",children:Wt.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===rn?"text-brand-500 bg-brand-500/10":"text-fg-tertiary hover:text-fg-secondary hover:bg-surface-elevated/50"}`,onClick:()=>{if(te.id===on){Ce(on);const je=Je.current;Ke.current.delete(je),ht([])}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===on?a("page.newChat"):te.isMain?a("page.sessionMain"):te.title||a("page.sessionConversation")}),!te.isMain&&n.jsx("button",{onClick:je=>{je.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))}),ze==="channel"&&Xs?.type==="custom"&&Gt&&(()=>{const te=Xs,je=te.members??[],Ie=[];for(const Pe of d)je.some(At=>At.id===Pe.id)||Ie.push({id:Pe.id,name:Pe.name,type:"agent",subtitle:Pe.role||"Agent"});for(const Pe of m)je.some(At=>At.id===Pe.id)||Ie.push({id:Pe.id,name:Pe.name,type:"human",subtitle:Pe.email||Pe.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")," (",je.length,")"]}),n.jsx("button",{onClick:()=>sn(!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:je.map(Pe=>n.jsxs("span",{className:`inline-flex items-center gap-1.5 px-2 py-1 rounded-full text-[11px] font-medium ${Pe.type==="agent"?"bg-brand-500/10 text-brand-500":"bg-green-500/10 text-green-600"}`,children:[n.jsx(gr,{name:Pe.name,size:16,bgClass:Pe.type==="agent"?"bg-brand-500/15 text-brand-500":"bg-green-500/15 text-green-600"}),Pe.name,Pe.id!==t?.id&&n.jsx("button",{onClick:async()=>{try{await de.groupChats.removeMember(te.id,Pe.id),bt(At=>At.map(We=>We.id===te.id?{...We,members:(We.members??[]).filter(mt=>mt.id!==Pe.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"})]})})]},Pe.id))}),Ie.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 Pe=>{const At=Pe.target.value;if(!At)return;const We=Ie.find(mt=>mt.id===At);if(We)try{await de.groupChats.addMember(te.id,We.id,We.type,We.name),bt(mt=>mt.map(pt=>pt.id===te.id?{...pt,members:[...pt.members??[],{id:We.id,name:We.name,type:We.type}],memberCount:(pt.memberCount??0)+1}:pt))}catch{}},children:[n.jsx("option",{value:"",children:a("page.addMemberPlaceholder")}),Ie.map(Pe=>n.jsxs("option",{value:Pe.id,children:["[",Pe.type==="agent"?"Agent":"Human","] ",Pe.name]},Pe.id))]})})]})})(),ze==="direct"&&ue&&Ct&&n.jsxs("div",{ref:Jt,className:"absolute right-4 top-full mt-1 w-72 max-h-[420px] bg-surface-secondary border border-border-default rounded-xl shadow-2xl shadow-black/40 z-50 flex flex-col overflow-hidden",children:[n.jsxs("div",{className:"px-4 py-3 border-b border-border-default flex items-center justify-between",children:[n.jsx("span",{className:"text-xs font-semibold text-fg-secondary uppercase tracking-wider",children:a("page.historyTitle")}),n.jsx("button",{onClick:()=>$t(!1),className:"text-fg-tertiary hover:text-fg-secondary text-xs",children:"✕"})]}),n.jsxs("div",{className:"flex-1 overflow-y-auto p-2",children:[Dr.length===0&&n.jsx("div",{className:"text-xs text-fg-tertiary text-center py-6",children:a("page.noConversationsYet")}),(()=>{const te=new Date,je=new Date(te.getFullYear(),te.getMonth(),te.getDate()).getTime(),Ie=je-864e5,Pe=je-7*864e5,At=[],We=[],mt=[],pt=[],ot=[];for(const jt of Dr){const an=new Date(jt.lastMessageAt).getTime();an>=je?We.push(jt):an>=Ie?mt.push(jt):an>=Pe?pt.push(jt):ot.push(jt)}return We.length>0&&At.push({label:a("page.dateToday"),items:We}),mt.length>0&&At.push({label:a("page.dateYesterday"),items:mt}),pt.length>0&&At.push({label:a("page.datePrevious7Days"),items:pt}),ot.length>0&&At.push({label:a("page.dateOlder"),items:ot}),At.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===rn?"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"&&ze==="direct"&&ue&&n.jsx("div",{className:"flex-1 overflow-y-auto",children:n.jsx(uk,{agentId:ue,onBack:()=>_("chat"),inline:!0,defaultTab:B,highlightMailboxId:H,onSwipeBack:()=>{uo(F.current)?history.back():_("chat")},authUser:t})}),g&&M==="profile"&&ze==="channel"&&ur&&n.jsx("div",{className:"flex-1 overflow-y-auto",onTouchStart:g?Le.onTouchStart:void 0,onTouchEnd:g?Le.onTouchEnd:void 0,children:n.jsx(Nk,{teamId:ur,onBack:()=>_("chat"),inline:!0,onSelectAgent:te=>{ce("direct"),Me(te),Oe()}})}),!g&&uo(M)&&ze==="direct"&&ue&&n.jsx("div",{className:"flex-1 overflow-y-auto",children:n.jsx(uk,{agentId:ue,onBack:()=>_("chat"),inline:!0,headless:!0,activeTab:M,highlightMailboxId:H,authUser:t})}),!g&&uo(M)&&ze==="channel"&&ur&&n.jsx("div",{className:"flex-1 flex flex-col min-h-0",children:n.jsx(Nk,{teamId:ur,onBack:()=>_("chat"),inline:!0,headless:!0,activeTab:M,onSelectAgent:te=>{ce("direct"),Me(te),_("overview"),!L&&!I&&U(!0)}})}),n.jsxs("div",{className:`flex-1 overflow-hidden flex flex-col relative ${M!=="chat"?"hidden":""}`,children:[Qn&&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:Ki,onTouchStart:g?Le.onTouchStart:void 0,onTouchEnd:g?Le.onTouchEnd:void 0,children:[rt.length===0&&!Vt&&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:ze==="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"})})}),ze==="channel"&&n.jsx("div",{children:a("page.emptyChannel",{name:Xs?.name??ne})}),ze==="direct"&&!ue&&n.jsx("div",{children:a("page.emptySelectAgent")}),ze==="direct"&&ue&&n.jsx("div",{children:a("page.emptyNewConversation",{name:Jr?.name??""})})]}),ze==="channel"?rt.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:je=>{if(te.sender==="agent"&&te.agentId){const Ie=je.currentTarget.getBoundingClientRect();P({agentId:te.agentId,top:Ie.top,left:Ie.right+8})}},children:n.jsx(gr,{name:te.sender==="user"?vl:te.agentName??a("page.fallbackAgent"),avatarUrl:te.sender==="user"?t?.avatarUrl:d.find(je=>je.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 je=document.getElementById(`msg-${te.replyToId}`);je&&(je.scrollIntoView({behavior:"smooth",block:"center"}),je.classList.add("bg-brand-500/10"),setTimeout(()=>je.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(Vr,{content:te.text,className:"text-sm text-fg-secondary",onMentionClick:nt,knownNames:gt}):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((je,Ie)=>n.jsx("img",{src:je,alt:"",className:"max-w-[200px] max-h-[150px] rounded-lg object-cover cursor-pointer hover:opacity-80 transition-opacity",onClick:()=>window.open(je,"_blank")},Ie))}),ck(te.text,d,(je,Ie)=>{const Pe=Ie.currentTarget.getBoundingClientRect();P({agentId:je.id,top:Pe.bottom,left:Pe.left})})]}),te.isNotification&&n.jsx(Ck,{priority:te.notifyPriority})]}),!r&&n.jsx("div",{className:`transition-opacity ${g?"opacity-100":"opacity-0 group-hover/msg:opacity-100"}`,children:n.jsx(Ak,{msg:te,onCopy:pr,onRetry:Cn,onResume:Et,onReply:Ds,isCopied:Ye===te.id,isLastAgentMsg:te.id===en})})]})]},te.id)):rt.map((te,je)=>{const Pe=k0&&je===rt.length-1&&Vt,At=j0&&je===rt.length-1||Pe,We=!Pe||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??(ze==="direct"?Jr?.name??a("page.fallbackAgent"):a("page.fallbackAgent")),avatarUrl:te.sender==="user"?t?.avatarUrl:d.find(mt=>mt.id===(te.agentId??(ze==="direct"?Jr?.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(FW,{name:te.agentName??(ze==="direct"?Jr?.name??a("page.fallbackAgent"):a("page.fallbackAgent")),agentId:te.agentId??(ze==="direct"?Jr?.id:void 0),agents:d,onViewProfile:Qe})}),n.jsx("span",{className:"text-xs text-fg-tertiary",children:te.time})]}),te.replyToId&&te.replyToSender&&n.jsxs("button",{onClick:()=>{const mt=document.getElementById(`msg-${te.replyToId}`);mt&&(mt.scrollIntoView({behavior:"smooth",block:"center"}),mt.classList.add("bg-brand-500/10"),setTimeout(()=>mt.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":""} ${At&&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((mt,pt)=>n.jsx("img",{src:mt,alt:"",className:"max-w-[200px] max-h-[150px] rounded-lg object-cover cursor-pointer hover:opacity-80 transition-opacity",onClick:()=>window.open(mt,"_blank")},pt))}),te.text&&n.jsx("span",{className:"leading-relaxed",children:ck(te.text,d,(mt,pt)=>{const ot=pt.currentTarget.getBoundingClientRect();P({agentId:mt.id,top:ot.bottom,left:ot.left})})})]}):n.jsx(UW,{msg:te,isStreaming:Pe,liveActivities:Pe?jr:[],onViewModeChange:mt=>Tt(pt=>{const ot=new Set(pt);return mt==="full"?ot.add(te.id):ot.delete(te.id),ot}),onMentionClick:nt,knownNames:gt}),te.isNotification&&n.jsx(Ck,{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(Ak,{msg:te,onCopy:pr,onRetry:Cn,onResume:Et,onReply:Ds,isCopied:Ye===te.id,isLastAgentMsg:te.id===en})})]})]},te.id)}),ze==="channel"&&Un.length>0&&n.jsx("div",{className:"flex flex-col gap-1.5 py-2",children:Un.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:()=>Qe(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})]})]}),K&&(()=>{const te=d.find(je=>je.id===K.agentId);return te?n.jsx(qW,{agent:te,anchorRect:{top:K.top,left:K.left},onClose:()=>P(null),onViewProfile:Qe}):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,je)=>n.jsxs("button",{ref:Ie=>{je===Ws&&Ie&&Ie.scrollIntoView({block:"nearest"})},onClick:()=>_e(te.name),onMouseEnter:()=>Es(je),className:`w-full text-left px-4 py-2 text-sm flex items-center gap-2 transition-colors ${je===Ws?"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))]}),Zn.length>0&&n.jsxs("div",{className:"flex items-center gap-2 mb-2 overflow-x-auto pb-1",children:[Zn.map(te=>n.jsxs("div",{className:"relative group/img shrink-0",children:[bs(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:$h(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)),Zn.length<An&&n.jsx("button",{onClick:()=>Bn.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"})})})]}),Zn.length>0&&Zn.some(te=>bs(te))&&Jr&&Jr.modelSupportsVision===!1&&n.jsxs("div",{className:"text-[10px] text-amber-500/80 mb-1.5 flex items-center gap-1",children:[n.jsx("svg",{className:"w-3 h-3 shrink-0",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:n.jsx("path",{d:"M12 9v4m0 4h.01M12 2L2 22h20L12 2z",strokeLinecap:"round",strokeLinejoin:"round"})}),a("page.visionWarning")]}),n.jsx("input",{ref:Bn,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=""}}),ut&&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:ut.sender}),n.jsx("p",{className:"text-[11px] text-fg-tertiary truncate",children:ut.text})]}),n.jsx("button",{onClick:()=>it(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:()=>Bn.current?.click(),disabled:ze==="direct"&&!ue,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:Xt,value:xt,onChange:te=>{ie(te.target.value),pn()},onKeyDown:te=>{if(sa&&oa.length>0){const je=te.key==="ArrowUp"||te.ctrlKey&&te.key==="p",Ie=te.key==="ArrowDown"||te.ctrlKey&&te.key==="n",Pe=te.key==="Enter"||te.key==="Tab",At=te.key==="Escape";if(je){te.preventDefault(),Es(We=>(We-1+oa.length)%oa.length);return}if(Ie){te.preventDefault(),Es(We=>(We+1)%oa.length);return}if(Pe){te.preventDefault();const We=oa[Ws];We&&_e(We.name);return}if(At){te.preventDefault(),zr(!1);return}}te.key==="Enter"&&!te.shiftKey&&(te.preventDefault(),ae())},onPaste:Hh,placeholder:N0,disabled:ze==="direct"&&!ue,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"}}),Vt&&ze!=="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:ze==="direct"&&!ue||!xt.trim()&&Zn.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 Dk({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(Te.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 QW=[{value:"system",label:"System"},{value:"light",label:"Light"},{value:"dark",label:"Dark"},{value:"cyberpunk",label:"Cyberpunk"},{value:"mono",label:"Mono"}],Pb="markus-theme";function Lk(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 ZW(){try{const e=localStorage.getItem(Pb);if(e==="midnight")return localStorage.setItem(Pb,"dark"),"dark";if(e==="light"||e==="dark"||e==="system"||e==="cyberpunk"||e==="mono")return e}catch{}return"system"}function JW(){const[e,t]=b.useState(ZW),r=b.useCallback(s=>{t(s);try{localStorage.setItem(Pb,s)}catch{}Lk(s)},[]);return b.useEffect(()=>{Lk(e)},[e]),{mode:e,setMode:r}}const TS=[{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 Ik(){const t=window.location.hash.slice(1).split("/");if(t[0]==="settings"&&t[1]){const r=t[1];if(TS.some(s=>s.id===r))return r}return null}function Pk({theme:e,onThemeChange:t,authUser:r,onLogout:s,onUserUpdated:a}={}){const{t:i,i18n:l}=kt(["settings","common"]),d=js(),[u,m]=b.useState(!1),[p,h]=b.useState(!1),y=b.useRef(null),[g,v]=b.useState(Ik);b.useEffect(()=>{const ie=()=>v(Ik());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=_e=>{y.current&&!y.current.contains(_e.target)&&m(!1)};return document.addEventListener("mousedown",ie),()=>document.removeEventListener("mousedown",ie)},[u]);const[N,j]=b.useState(null),[T,D]=b.useState(null),[M,_]=b.useState(""),[F,z]=b.useState(!1),[L,U]=b.useState(null),[W,q]=b.useState(null),[I,R]=b.useState(null),[E,$]=b.useState(null),[X,K]=b.useState(!1),[P,B]=b.useState(null),[Z,H]=b.useState(null),[J,Q]=b.useState(!1),[ee,se]=b.useState(null),[Y,me]=b.useState({}),[be,De]=b.useState(!1),[He,ke]=b.useState(null),[pe,Oe]=b.useState(!1),[Ee,fe]=b.useState(""),[Le,Qe]=b.useState(!1),[nt,gt]=b.useState(null),[ze,ce]=b.useState([]),[ue,Me]=b.useState([]),[ne,he]=b.useState(null),[Be,Se]=b.useState(null),[Ke,at]=b.useState(""),[ct,Je]=b.useState(null),rt=b.useRef(null),ht=b.useRef(!1),[xt,Ve]=b.useState(!1),[ut,it]=b.useState(200),[Vt,Nn]=b.useState(!1),[Un,mn]=b.useState(null),[Tn,$n]=b.useState(!1),[dn,bn]=b.useState(1),[nr,ir]=b.useState(!1),[jr,xr]=b.useState(null),[rr,Ln]=b.useState(!1),[Qn,Vn]=b.useState(0),[Zn,br]=b.useState(!0),[Bn,Xt]=b.useState(!1),[pn,on]=b.useState(!1),[Dr,Nr]=b.useState(9333),[rn,Ce]=b.useState(!1),[Ct,$t]=b.useState(null),[Wt,qt]=b.useState(null),[Ne,Rt]=b.useState({serperApiKey:"",tavilyApiKey:"",bingApiKey:"",googleSearchApiKey:"",googleSearchCx:"",serpApiKey:"",braveApiKey:"",exaApiKey:"",bochaApiKey:""}),[Dt,Jt]=b.useState(!1),[Jn,xe]=b.useState(null),[Xe,bt]=b.useState(null),[Ft,tn]=b.useState(!1),[Gt,sn]=b.useState(new Set),[vn,Pn]=b.useState(null),[or,Lr]=b.useState(!1),_t=()=>({"Content-Type":"application/json",Authorization:`Bearer ${localStorage.getItem("markus_token")??""}`}),sr=b.useCallback(()=>{de.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&&(D(ie),_(ie.defaultProvider))}).catch(()=>{})},[]),_r=b.useCallback(()=>{fetch("/api/settings/oauth/providers").then(ie=>ie.ok?ie.json():Promise.reject(ie.status)).then(ie=>ce(ie.providers??[])).catch(()=>{})},[]),dr=b.useCallback(()=>{fetch("/api/settings/oauth/profiles",{headers:_t()}).then(ie=>ie.ok?ie.json():Promise.reject(ie.status)).then(ie=>Me(ie.profiles??[])).catch(()=>{})},[]),Va=b.useCallback(()=>{de.settings.getAgent().then(ie=>{ie&&typeof ie.maxToolIterations=="number"&&it(ie.maxToolIterations),ie?.cognitive&&($n(ie.cognitive.enabled??!1),bn(ie.cognitive.maxDepth??1))}).catch(()=>{})},[]),Yr=b.useCallback(()=>{de.settings.getBrowser().then(ie=>{ie&&(Ln(ie.bringToFront??!1),Vn(ie.remoteDebuggingPort??0),br(ie.autoCloseTabs??!0),Xt(ie.autoClickAllowDialog??!1),on(ie.extensionConnected??!1),Nr(ie.extensionBridgePort??9333))}).catch(()=>{})},[]),$s=b.useCallback(()=>{de.settings.getSearch().then(ie=>{ie&&qt(ie)}).catch(()=>{})},[]),Bs=b.useCallback(()=>{tn(!0),de.system.storage().then(bt).catch(()=>{}).finally(()=>tn(!1)),de.system.orphans().then(Pn).catch(()=>{})},[]);b.useEffect(()=>{sr(),_r(),dr(),Va(),Yr(),$s(),Bs()},[sr,_r,dr,Va,Yr,$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),H(null),me({});try{const ie=await fetch("/api/settings/env-models",{headers:_t()});if(!ie.ok){se({type:"err",text:i("envConfig.detectionFailedHttp",{status:ie.status})});return}const _e=await ie.json();if(H(_e),_e.detected.length===0)se({type:"err",text:i("envConfig.noKeysFound")});else{const Ze={};for(const An of _e.detected)Ze[An.provider]=!0;me(Ze)}}catch{se({type:"err",text:i("envConfig.failedToDetect")})}finally{Q(!1)}},[i]),zr=b.useCallback(async()=>{Oe(!0),gt(null),ke(null);try{const ie=await fetch("/api/settings/detect-ollama",{headers:_t()});if(!ie.ok){gt({type:"err",text:i("ollama.detectFailed")});return}const _e=await ie.json();ke(_e),_e.found&&_e.models&&_e.models.length>0?fe(_e.models[0].name):_e.found||gt({type:"err",text:_e.error||i("ollama.notRunning")})}catch{gt({type:"err",text:i("ollama.detectFailed")})}finally{Oe(!1)}},[i]),Ka=T?Object.values(T.providers).some(ie=>ie.configured):!1;b.useEffect(()=>{T&&!Ka&&!ht.current&&(ht.current=!0,sa(),zr())},[T,Ka,sa,zr]);const Vi=async()=>{if(!(!M||M===T?.defaultProvider)){z(!0),U(null);try{const ie=await fetch("/api/settings/llm",{method:"POST",headers:_t(),body:JSON.stringify({defaultProvider:M})}),_e=await ie.json();ie.ok?(D(_e),U({type:"ok",text:i("defaultProvider.updated",{name:_e.defaultProvider})})):U({type:"err",text:_e.error??i("modelProviders.saveFailed")})}catch{U({type:"err",text:i("common:networkError")})}finally{z(!1)}}},Ws=async(ie,_e)=>{R(ie);try{const Ze=await fetch(`/api/settings/llm/providers/${ie}/toggle`,{method:"POST",headers:_t(),body:JSON.stringify({enabled:_e})});if(Ze.ok){const An=await Ze.json();D(An)}}catch{}finally{R(null)}},Es=async()=>{K(!0),B(null);try{const _e=await(await fetch("/api/settings/import/openclaw",{method:"POST",headers:_t(),body:JSON.stringify({preview:!0})})).json();"error"in _e?B({type:"err",text:_e.error}):$(_e)}catch{B({type:"err",text:i("openClaw.detectFailed")})}finally{K(!1)}},ur=async()=>{K(!0),B(null);try{const _e=await(await fetch("/api/settings/import/openclaw",{method:"POST",headers:_t(),body:JSON.stringify({preview:!1})})).json();"error"in _e?B({type:"err",text:_e.error}):(B({type:"ok",text:i("openClaw.importedFrom",{count:_e.appliedModels})}),sr())}catch{B({type:"err",text:i("openClaw.importFailed")})}finally{K(!1)}},va=async()=>{if(!Z)return;const ie=Z.detected.filter(_e=>Y[_e.provider]);if(ie.length===0){se({type:"err",text:i("envConfig.selectAtLeastOne")});return}De(!0),se(null);try{const _e=await fetch("/api/settings/env-models",{method:"POST",headers:_t(),body:JSON.stringify({providers:ie.map(An=>({provider:An.provider,model:An.model,baseUrl:An.baseUrl,enabled:!0}))})});if(!_e.ok){se({type:"err",text:i("envConfig.applyFailed",{status:_e.status})});return}const Ze=await _e.json();se({type:"ok",text:Ze.message}),H(null),me({}),sr()}catch{se({type:"err",text:i("envConfig.failedToApply")})}finally{De(!1)}},Hs=async()=>{if(!(!He?.found||!Ee)){Qe(!0),gt(null);try{const ie=await fetch("/api/settings/llm/providers",{method:"POST",headers:_t(),body:JSON.stringify({name:"ollama",model:Ee,baseUrl:He.baseUrl||"http://localhost:11434"})});if(ie.ok){const _e=await ie.json();D(_e),gt({type:"ok",text:i("ollama.configured",{model:Ee})}),ke(null)}else{const _e=await ie.json();gt({type:"err",text:_e.error||i("ollama.applyFailed")})}}catch{gt({type:"err",text:i("ollama.applyFailed")})}finally{Qe(!1)}}};b.useEffect(()=>()=>{rt.current&&clearInterval(rt.current)},[]),b.useEffect(()=>{if(k!=="browser"||pn)return;const ie=setInterval(async()=>{try{(await de.settings.getBrowser()).extensionConnected&&(on(!0),clearInterval(ie))}catch{}},5e3);return()=>clearInterval(ie)},[k,pn]);const[xs,li]=b.useState(!1),[gn,yr]=b.useState({name:"",apiKey:"",baseUrl:"",model:"",contextWindow:128e3,maxOutputTokens:16384,costInput:1,costOutput:5}),[ci,wa]=b.useState(!1),[Ms,Ir]=b.useState(null),[ji,yn]=b.useState(null),[Kn,Xr]=b.useState({apiKey:"",baseUrl:"",model:"",contextWindow:0,maxOutputTokens:0,costInput:0,costOutput:0}),[Rs,ka]=b.useState(!1),[ja,Ns]=b.useState(null),[Gs,Na]=b.useState(""),[di,Wa]=b.useState(!1),[Qr,Ar]=b.useState(null),[Fr,Ss]=b.useState(null),[Sn,Zr]=b.useState({id:"",name:"",contextWindow:128e3,maxOutputTokens:16384,costInput:1,costOutput:5,reasoning:!1,vision:!1}),[Sa,Cs]=b.useState(!1),aa=async()=>{if(!(!gn.name||!gn.model)){wa(!0),Ir(null);try{const ie=await fetch("/api/settings/llm/providers",{method:"POST",headers:_t(),body:JSON.stringify({name:gn.name,apiKey:gn.apiKey||void 0,baseUrl:gn.baseUrl||void 0,model:gn.model,contextWindow:gn.contextWindow||void 0,maxOutputTokens:gn.maxOutputTokens||void 0,cost:gn.costInput||gn.costOutput?{input:gn.costInput,output:gn.costOutput}:void 0})}),_e=await ie.json();ie.ok?(D(_e),li(!1),yr({name:"",apiKey:"",baseUrl:"",model:"",contextWindow:128e3,maxOutputTokens:16384,costInput:1,costOutput:5}),Ir({type:"ok",text:i("modelProviders.providerAdded",{name:gn.name})})):Ir({type:"err",text:_e.error??i("modelProviders.failedToAdd")})}catch{Ir({type:"err",text:i("common:networkError")})}finally{wa(!1)}}},Ca=async(ie,_e)=>{if(!Gs.trim())return;Wa(!0),Ar(null);const Ze=_e.models?.[0]?.id??ie;try{const An=await fetch("/api/settings/llm/providers",{method:"POST",headers:_t(),body:JSON.stringify({name:ie,apiKey:Gs.trim(),model:Ze})}),ia=await An.json();An.ok?(D(ia),Na(""),Ar({type:"ok",text:i("modelProviders.quickSetupSuccess",{name:_e.displayName??ie})})):Ar({type:"err",text:ia.error??i("modelProviders.failedToAdd")})}catch{Ar({type:"err",text:i("common:networkError")})}finally{Wa(!1)}},Ys=(ie,_e)=>{yn(ie),Xr({apiKey:"",baseUrl:_e.baseUrl??"",model:_e.model,contextWindow:_e.contextWindow??0,maxOutputTokens:_e.maxOutputTokens??0,costInput:_e.cost?.input??0,costOutput:_e.cost?.output??0})},Ga=async ie=>{ka(!0);try{const _e={};Kn.apiKey&&(_e.apiKey=Kn.apiKey),Kn.baseUrl!==void 0&&(_e.baseUrl=Kn.baseUrl),Kn.model&&(_e.model=Kn.model),Kn.contextWindow&&(_e.contextWindow=Kn.contextWindow),Kn.maxOutputTokens&&(_e.maxOutputTokens=Kn.maxOutputTokens),(Kn.costInput||Kn.costOutput)&&(_e.cost={input:Kn.costInput,output:Kn.costOutput});const Ze=await fetch(`/api/settings/llm/providers/${ie}`,{method:"PUT",headers:_t(),body:JSON.stringify(_e)});if(Ze.ok){const An=await Ze.json();D(An),yn(null)}}catch{}finally{ka(!1)}},To=async ie=>{Ns(ie);try{const _e=await fetch(`/api/settings/llm/providers/${ie}`,{method:"DELETE",headers:_t()});if(_e.ok){const Ze=await _e.json();D(Ze),_(Ze.defaultProvider)}}catch{}finally{Ns(null)}},ui=async ie=>{if(!(!Sn.id||!Sn.name)){Cs(!0);try{const _e=await fetch(`/api/settings/llm/providers/${ie}/models`,{method:"POST",headers:_t(),body:JSON.stringify({id:Sn.id,name:Sn.name,contextWindow:Sn.contextWindow,maxOutputTokens:Sn.maxOutputTokens,cost:{input:Sn.costInput,output:Sn.costOutput},reasoning:Sn.reasoning||void 0,inputTypes:Sn.vision?["text","image"]:["text"]})});if(_e.ok){const Ze=await _e.json();D(Ze),Ss(null),Zr({id:"",name:"",contextWindow:128e3,maxOutputTokens:16384,costInput:1,costOutput:5,reasoning:!1,vision:!1})}}catch{}finally{Cs(!1)}}},Ki=async(ie,_e)=>{try{const Ze=await fetch(`/api/settings/llm/providers/${ie}/models/${encodeURIComponent(_e)}`,{method:"DELETE",headers:_t()});if(Ze.ok){const An=await Ze.json();D(An)}}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,lt]=b.useState(null),[Tt,en]=b.useState({}),pr=async ie=>{lt(ie),en(_e=>{const Ze={..._e};return delete Ze[ie],Ze});try{const _e=await fetch(`/api/settings/llm/providers/${ie}/test`,{method:"POST",headers:_t()});if(!_e.ok){const An=await _e.json().catch(()=>({}));en(ia=>({...ia,[ie]:{ok:!1,error:An.error??`HTTP ${_e.status}`,errorCode:_e.status}}));return}const Ze=await _e.json();en(An=>({...An,[ie]:Ze}))}catch{en(_e=>({..._e,[ie]:{ok:!1,error:i("common:networkError")}}))}finally{lt(null)}},Cn=async(ie,_e)=>{ae(`${ie}:${_e}`);try{const Ze=await fetch(`/api/settings/llm/providers/${ie}/model`,{method:"POST",headers:_t(),body:JSON.stringify({model:_e})});if(Ze.ok){const An=await Ze.json();D(An)}}catch{}finally{ae(null)}},Et=async()=>{if(Ne.serperApiKey||Ne.tavilyApiKey||Ne.bingApiKey||Ne.googleSearchApiKey||Ne.googleSearchCx||Ne.serpApiKey||Ne.braveApiKey||Ne.exaApiKey||Ne.bochaApiKey){Jt(!0),xe(null);try{const _e={};Ne.serperApiKey&&(_e.serperApiKey=Ne.serperApiKey),Ne.tavilyApiKey&&(_e.tavilyApiKey=Ne.tavilyApiKey),Ne.bingApiKey&&(_e.bingApiKey=Ne.bingApiKey),Ne.googleSearchApiKey&&(_e.googleSearchApiKey=Ne.googleSearchApiKey),Ne.googleSearchCx&&(_e.googleSearchCx=Ne.googleSearchCx),Ne.serpApiKey&&(_e.serpApiKey=Ne.serpApiKey),Ne.braveApiKey&&(_e.braveApiKey=Ne.braveApiKey),Ne.exaApiKey&&(_e.exaApiKey=Ne.exaApiKey),Ne.bochaApiKey&&(_e.bochaApiKey=Ne.bochaApiKey);const Ze=await de.settings.updateSearch(_e);qt(Ze),Rt({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{Jt(!1)}}},Ds=T?.providers?Object.entries(T.providers).filter(([,ie])=>ie.configured&&ie.enabled).map(([ie])=>ie):[],Ls=T&&!Ka&&!xt,Fs=r?.role==="owner"||r?.role==="admin",qr=TS.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(Te.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:qr.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(Te.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:qr.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:${qr.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:QW.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:nw.map(({code:ie,label:_e})=>n.jsx("button",{onClick:()=>{l.changeLanguage(ie)},className:`px-3 py-1.5 text-xs rounded-md transition-colors ${l.language===ie||ie==="en"&&!nw.some(Ze=>Ze.code===l.language)?"bg-brand-600 text-white":"text-fg-secondary hover:text-fg-primary"}`,children:_e},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:()=>Ve(!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:Y[ie.provider]??!1,onChange:_e=>me({...Y,[ie.provider]:_e.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:be||Object.values(Y).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:be?i("common:applying"):i("setupGuide.applyProviders",{count:Object.values(Y).filter(Boolean).length})})]}),Z&&Z.detected.length===0&&n.jsx("div",{className:"text-xs text-fg-tertiary",children:n.jsx(Hu,{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:!!He?.found,children:[pe&&n.jsx("div",{className:"text-xs text-fg-tertiary",children:i("common:detecting")}),He?.found&&He.models&&He.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:He.models.length,url:He.baseUrl})}),n.jsx("select",{value:Ee,onChange:ie=>fe(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:He.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:Le||!Ee,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:Le?i("common:applying"):i("ollama.useModel",{model:Ee})})]}),!pe&&!He&&n.jsx("button",{onClick:()=>{zr()},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")}),He&&!He.found&&n.jsx("div",{className:"text-xs text-fg-tertiary",children:i("ollama.notRunning")}),nt&&n.jsx(Oa,{type:nt.type,text:nt.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,_e)=>ie+_e.modelCount,0)})}),n.jsx("button",{onClick:()=>{ur()},disabled:X,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(X?"common:importing":"openClaw.importConfigs")})]}):n.jsx("div",{className:"text-xs text-fg-tertiary",children:i("openClaw.notFound")}):n.jsx("button",{onClick:()=>{Es()},disabled:X,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(X?"common:detecting":"openClaw.detectShort")}),P&&n.jsx(Oa,{type:P.type,text:P.text})]}),n.jsx(yu,{step:i("setupGuide.manual.step"),title:i("setupGuide.manual.title"),description:n.jsx(Hu,{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:pn,children:pn?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:rn,onClick:async()=>{Ce(!0);try{await de.settings.downloadExtensionZip()}catch{}Ce(!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:rn,onClick:async()=>{try{await de.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:Ds.length>0?Ds.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 _e=await fetch("/api/settings/llm",{method:"POST",headers:_t(),body:JSON.stringify({autoFallback:ie})});if(_e.ok){const Ze=await _e.json();D(Ze)}}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,_e])=>n.jsxs("div",{className:`bg-surface-secondary border rounded-xl overflow-hidden transition-colors ${_e.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(W===ie?null:ie),Na(""),Ar(null)},children:[n.jsxs("div",{className:"flex items-center gap-3",children:[n.jsx("span",{className:`w-2 h-2 rounded-full ${_e.configured&&_e.enabled?"bg-green-400":_e.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:_e.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")}),_e.configured&&!_e.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")}),_e.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")}),Tt[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:Tt[ie].durationMs})}),Tt[ie]?.ok===!1&&n.jsx("span",{className:"text-[10px] bg-red-500/15 text-red-500 px-1.5 py-0.5 rounded",title:Tt[ie].error,children:Tt[ie].errorCode?i("modelProviders.testFailedCode",{code:Tt[ie].errorCode}):i("modelProviders.testFailed")})]}),n.jsx("div",{className:"text-xs text-fg-tertiary mt-0.5",children:_e.configured?n.jsxs(n.Fragment,{children:[_e.model,_e.apiKeyPreview&&n.jsxs(n.Fragment,{children:[" · ",n.jsx("code",{className:"text-fg-secondary",children:_e.apiKeyPreview})]})]}):i("modelProviders.notConfigured")})]})]}),n.jsxs("div",{className:"flex items-center gap-4",children:[_e.configured&&n.jsx("button",{onClick:Ze=>{Ze.stopPropagation(),Ws(ie,!_e.enabled)},disabled:I===ie,className:`relative inline-flex h-5 w-9 items-center rounded-full transition-colors ${_e.enabled?"bg-green-500":"bg-gray-600"} ${I===ie?"opacity-50":""}`,title:_e.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 ${_e.enabled?"translate-x-4":"translate-x-1"}`})}),_e.contextWindow&&n.jsx("span",{className:"text-[10px] text-fg-tertiary",children:i("modelProviders.ctxTokens",{size:(_e.contextWindow/1e3).toFixed(0)})}),_e.cost&&n.jsx("span",{className:"text-[10px] text-fg-tertiary",children:i("modelProviders.costPerMillion",{input:_e.cost.input,output:_e.cost.output})}),n.jsx("span",{className:"text-fg-tertiary text-xs",children:W===ie?"▲":"▼"})]})]}),W===ie&&n.jsxs("div",{className:"px-5 pb-4 border-t border-border-default pt-4 space-y-4",children:[_e.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:_e.model}),n.jsx(el,{label:i("modelProviders.contextWindow"),value:_e.contextWindow?i("modelProviders.kTokens",{k:(_e.contextWindow/1e3).toFixed(0)}):i("modelProviders.notApplicable")}),n.jsx(el,{label:i("modelProviders.maxOutput"),value:_e.maxOutputTokens?i("modelProviders.kTokens",{k:(_e.maxOutputTokens/1e3).toFixed(0)}):i("modelProviders.notApplicable")}),n.jsx(el,{label:i("modelProviders.baseUrlLabel"),value:_e.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:Ze=>Xr({...Kn,apiKey:Ze.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:Ze=>Xr({...Kn,baseUrl:Ze.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:Ze=>Xr({...Kn,model:Ze.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:Ze=>Xr({...Kn,contextWindow:Number(Ze.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:Ze=>Xr({...Kn,maxOutputTokens:Number(Ze.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:Ze=>Xr({...Kn,costInput:Number(Ze.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:Ze=>Xr({...Kn,costOutput:Number(Ze.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:Rs,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(Rs?"common:saving":"common:save")}),n.jsx("button",{onClick:()=>yn(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:Ze=>{Ze.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:Ze=>{Ze.stopPropagation(),Ys(ie,_e)},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:Ze=>{Ze.stopPropagation(),confirm(i("modelProviders.deleteConfirm",{name:_e.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")})]}),Tt[ie]&&n.jsx("div",{className:`text-xs px-3 py-2 rounded-lg ${Tt[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:Tt[ie].ok?i("modelProviders.testSuccess",{ms:Tt[ie].durationMs,reply:Tt[ie].reply}):Tt[ie].error})]}),_e.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:`$${_e.cost.input}`}),n.jsx(el,{label:i("modelProviders.output"),value:`$${_e.cost.output}`}),_e.cost.cacheRead!=null&&n.jsx(el,{label:i("modelProviders.cacheRead"),value:`$${_e.cost.cacheRead}`}),_e.cost.cacheWrite!=null&&n.jsx(el,{label:i("modelProviders.cacheWrite"),value:`$${_e.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")}),_e.configured&&Fr!==ie&&n.jsx("button",{onClick:()=>{Ss(ie),Zr({id:"",name:"",contextWindow:128e3,maxOutputTokens:16384,costInput:1,costOutput:5,reasoning:!1,vision:!1})},className:"text-[10px] text-brand-500 hover:text-brand-400 transition-colors",children:i("modelProviders.addModel")})]}),Fr===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:Sn.id,onChange:Ze=>Zr({...Sn,id:Ze.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:Sn.name,onChange:Ze=>Zr({...Sn,name:Ze.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:Sn.contextWindow,onChange:Ze=>Zr({...Sn,contextWindow:Number(Ze.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:Sn.maxOutputTokens,onChange:Ze=>Zr({...Sn,maxOutputTokens:Number(Ze.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:Sn.costInput,onChange:Ze=>Zr({...Sn,costInput:Number(Ze.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:Sn.costOutput,onChange:Ze=>Zr({...Sn,costOutput:Number(Ze.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:Sn.reasoning,onChange:Ze=>Zr({...Sn,reasoning:Ze.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:Sn.vision,onChange:Ze=>Zr({...Sn,vision:Ze.target.checked}),className:"rounded"}),i("modelProviders.vision")]}),n.jsx("div",{className:"flex-1"}),n.jsx("button",{onClick:()=>{ui(ie)},disabled:Sa||!Sn.id||!Sn.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")})]})]}),_e.models&&_e.models.length>0&&n.jsx("div",{className:"space-y-1.5",children:_e.models.map(Ze=>{const An=Ze.id===_e.model,ia=Ni===`${ie}:${Ze.id}`,Aa=!Ta.has(Ze.id);return n.jsxs("div",{className:`flex items-center justify-between px-3 py-2 rounded-lg text-xs transition-colors ${An?"bg-brand-500/15 border border-brand-500/30":_e.configured?"bg-surface-elevated/30 hover:bg-surface-elevated/60 cursor-pointer":"bg-surface-elevated/30"}`,onClick:()=>{!An&&_e.configured&&!ia&&Cn(ie,Ze.id)},children:[n.jsxs("div",{className:"flex items-center gap-2",children:[An&&n.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-brand-500 shrink-0"}),n.jsx("span",{className:An?"text-brand-500 font-medium":"text-fg-secondary",children:Ze.name}),Ze.reasoning&&n.jsx("span",{className:"text-[9px] bg-amber-500/15 text-amber-600 px-1 py-0.5 rounded",children:i("modelProviders.reasoning")}),Ze.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:(Ze.contextWindow/1e3).toFixed(0)})}),n.jsx("span",{children:i("modelProviders.costPair",{input:Ze.cost.input,output:Ze.cost.output})}),_e.configured&&!An&&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")}),An&&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&&!An&&n.jsx("button",{onClick:bs=>{bs.stopPropagation(),Ki(ie,Ze.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"})})})]})]},Ze.id)})})]}),!_e.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:W===ie?Gs:"",onChange:Ze=>Na(Ze.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:Ze=>{Ze.key==="Enter"&&Gs.trim()&&Ca(ie,_e)}}),n.jsx("button",{onClick:()=>{Ca(ie,_e)},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")})]}),Qr&&W===ie&&n.jsx(Oa,{type:Qr.type,text:Qr.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:gn.name,onChange:ie=>yr({...gn,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:gn.apiKey,onChange:ie=>yr({...gn,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:gn.baseUrl,onChange:ie=>yr({...gn,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:gn.model,onChange:ie=>yr({...gn,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:gn.contextWindow,onChange:ie=>yr({...gn,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:gn.maxOutputTokens,onChange:ie=>yr({...gn,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:gn.costInput,onChange:ie=>yr({...gn,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:gn.costOutput,onChange:ie=>yr({...gn,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||!gn.name||!gn.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),Ir(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:Y[ie.provider]??!1,onChange:_e=>me({...Y,[ie.provider]:_e.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(_e=>n.jsx("div",{children:n.jsx("code",{children:_e})},_e))})]},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:be||Object.values(Y).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:be?i("common:applying"):i("envConfig.applyToConfig",{count:Object.values(Y).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:()=>{zr()},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")]})]}),He?.found&&He.models&&He.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:He.models.length,url:He.baseUrl})}),n.jsx("div",{className:"space-y-1",children:He.models.map(ie=>n.jsx("label",{className:`flex items-center justify-between rounded-lg px-4 py-3 cursor-pointer transition-colors ${Ee===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:Ee===ie.name,onChange:()=>fe(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:Le||!Ee,className:"px-4 py-2 bg-brand-600 hover:bg-brand-500 disabled:opacity-40 text-white text-sm rounded-lg transition-colors",children:Le?i("common:applying"):i("ollama.useModel",{model:Ee})})]}),He&&!He.found&&n.jsx("div",{className:"text-xs text-fg-tertiary",children:He.error||i("ollama.notRunning")}),nt&&n.jsx(Oa,{type:nt.type,text:nt.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:X,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(X?"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:()=>{ur()},disabled:X,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(X?"common:importing":"openClaw.importConfigs")})]}),P&&n.jsx(Oa,{type:P.type,text:P.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:ut,onChange:ie=>{it(Number(ie.target.value)),mn(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:Vt,onClick:async()=>{Nn(!0),mn(null);try{const ie=await de.settings.updateAgent({maxToolIterations:ut});it(ie.maxToolIterations),mn({type:"ok",text:i("agentExecution.saved")})}catch{mn({type:"err",text:i("agentExecution.failedToSave")})}Nn(!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(Vt?"common:saving":"common:save")})]})]}),Un&&n.jsx(Oa,{type:Un.type,text:Un.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:()=>{$n(!Tn),xr(null)},className:`relative w-10 h-5 rounded-full transition-colors ${Tn?"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 ${Tn?"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:dn,onChange:ie=>{bn(Number(ie.target.value)),xr(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:nr,onClick:async()=>{ir(!0),xr(null);try{const ie=await de.settings.updateAgent({cognitive:{enabled:Tn,maxDepth:dn}});$n(ie.cognitive.enabled),bn(ie.cognitive.maxDepth??1),xr({type:"ok",text:i("cognitive.saved")})}catch{xr({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(nr?"common:saving":"common:save")})}),jr&&n.jsx(Oa,{type:jr.type,text:jr.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 ${pn?"bg-green-500/10 border border-green-500/20":Qn>0?"bg-blue-500/10 border border-blue-500/20":Bn?"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 ${pn?"bg-green-400":Qn>0?"bg-blue-400":Bn?"bg-amber-400":"bg-gray-400"}`}),n.jsxs("div",{className:"flex-1 min-w-0",children:[n.jsx("div",{className:`text-sm font-semibold ${pn?"text-green-400":Qn>0?"text-blue-400":Bn?"text-amber-400":"text-fg-secondary"}`,children:pn?i("browserAutomation.modeExtension"):Qn>0?i("browserAutomation.modeDebuggingPort",{port:Qn}):i(Bn?"browserAutomation.modeAutoClick":"browserAutomation.modeManual")}),n.jsx("div",{className:"text-xs text-fg-tertiary mt-0.5",children:pn?i("browserAutomation.modeExtensionDesc"):Qn>0?i("browserAutomation.modeDebuggingPortDesc"):i(Bn?"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=!rr;Ln(ie),Ce(!0),$t(null);try{const _e=await de.settings.updateBrowser({bringToFront:ie});Ln(_e.bringToFront),$t({type:"ok",text:i(ie?"browserAutomation.tabsForeground":"browserAutomation.tabsBackground")})}catch{$t({type:"err",text:i("agentExecution.failedToSave")}),Ln(!ie)}Ce(!1)},disabled:rn,className:`relative inline-flex h-5 w-9 items-center rounded-full transition-colors ${rr?"bg-green-500":"bg-gray-600"} ${rn?"opacity-50":""}`,children:n.jsx("span",{className:`inline-block h-3.5 w-3.5 rounded-full bg-white transition-transform ${rr?"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=!Zn;br(ie),Ce(!0),$t(null);try{const _e=await de.settings.updateBrowser({autoCloseTabs:ie});br(_e.autoCloseTabs),$t({type:"ok",text:i("agentExecution.saved")})}catch{$t({type:"err",text:i("agentExecution.failedToSave")}),br(!ie)}Ce(!1)},disabled:rn,className:`relative inline-flex h-5 w-9 items-center rounded-full transition-colors ${Zn?"bg-green-500":"bg-gray-600"} ${rn?"opacity-50":""}`,children:n.jsx("span",{className:`inline-block h-3.5 w-3.5 rounded-full bg-white transition-transform ${Zn?"translate-x-4":"translate-x-1"}`})})]})]}),n.jsxs("div",{className:`rounded-xl p-5 mb-4 transition-colors ${pn?"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 ${pn?"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 ${pn?"bg-green-400":"bg-gray-400"}`}),i(pn?"browserAutomation.extensionConnected":"browserAutomation.extensionDisconnected")]})]}),n.jsx("div",{className:"text-xs text-fg-tertiary",children:i("browserAutomation.extensionStatusDesc")}),pn?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:rn,onClick:async()=>{Ce(!0),$t(null);try{await de.settings.downloadExtensionZip()}catch{$t({type:"err",text:i("browserAutomation.extensionDownloadError")})}Ce(!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(rn?"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:rn,onClick:async()=>{Ce(!0),$t(null);try{await de.settings.openExtensionsPage()}catch{$t({type:"err",text:i("browserAutomation.extensionOpenError")})}Ce(!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")})]})]})]})]}),!pn&&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:rn,onClick:async()=>{Ce(!0),$t(null);try{const ie=await de.settings.testAutoClick(),_e={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"})}};$t(_e[ie.clickResult]??{type:"err",text:ie.clickResult})}catch{$t({type:"err",text:i("browserAutomation.autoClickTestError",{error:"request failed"})})}Ce(!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(rn?"browserAutomation.autoClickTesting":"browserAutomation.autoClickTest")}),n.jsx("button",{onClick:async()=>{const ie=!Bn;Xt(ie),Ce(!0),$t(null);try{const _e=await de.settings.updateBrowser({autoClickAllowDialog:ie});Xt(_e.autoClickAllowDialog),$t({type:"ok",text:i("agentExecution.saved")})}catch{$t({type:"err",text:i("agentExecution.failedToSave")}),Xt(!ie)}Ce(!1)},disabled:rn,className:`relative inline-flex h-5 w-9 items-center rounded-full transition-colors ${Bn?"bg-green-500":"bg-gray-600"} ${rn?"opacity-50":""}`,children:n.jsx("span",{className:`inline-block h-3.5 w-3.5 rounded-full bg-white transition-transform ${Bn?"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:Qn,onChange:ie=>{Vn(Number(ie.target.value)),$t(null)},className:"w-24 px-3 py-1.5 text-sm border border-border-default rounded-lg bg-surface-primary text-fg-primary text-right",placeholder:"0"}),n.jsx("button",{disabled:rn,onClick:async()=>{Ce(!0),$t(null);try{const ie=await de.settings.updateBrowser({remoteDebuggingPort:Qn});Vn(ie.remoteDebuggingPort),$t({type:"ok",text:ie.remoteDebuggingPort>0?i("browserAutomation.usingPort",{port:ie.remoteDebuggingPort}):i("browserAutomation.usingAutoConnect")})}catch{$t({type:"err",text:i("agentExecution.failedToSave")})}Ce(!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(rn?"common:saving":"common:save")})]})]})})]}),Ct&&n.jsx("div",{className:"mt-4",children:n.jsx(Oa,{type:Ct.type,text:Ct.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,_e)=>n.jsxs("div",{className:_e>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:[Wt?.[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:Wt[ie.id].preview})]}),Wt&&!Wt[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:Ne[ie.field],onChange:Ze=>Rt({...Ne,[ie.field]:Ze.target.value}),placeholder:Wt?.[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:Ne[ie.extraField],onChange:Ze=>Rt({...Ne,[ie.extraField]:Ze.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:[Jn&&n.jsx(Oa,{type:Jn.type,text:Jn.text}),!Jn&&n.jsx("div",{}),n.jsx("button",{disabled:Dt||!Ne.serperApiKey&&!Ne.tavilyApiKey&&!Ne.bingApiKey&&!Ne.googleSearchApiKey&&!Ne.googleSearchCx&&!Ne.serpApiKey&&!Ne.braveApiKey&&!Ne.exaApiKey&&!Ne.bochaApiKey,onClick:()=>{Et()},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(Dt?"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:[Ft&&!Xe&&n.jsx("div",{className:"text-sm text-fg-tertiary",children:i("dataStorage.scanning")}),Xe&&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(Xe.totalSize,i)}),n.jsx("div",{className:"text-xs text-fg-tertiary font-mono mt-0.5",children:Xe.dataDir})]}),n.jsxs("div",{className:"flex gap-2",children:[n.jsx("button",{onClick:()=>Bs(),disabled:Ft,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(Ft?"dataStorage.scanning":"common:refresh")}),n.jsx("button",{onClick:()=>{de.system.openPath(Xe.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:Xe.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))})]}),Xe.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:Xe.agents.length})}),n.jsx("div",{className:"space-y-1",children:Xe.agents.map(ie=>{const _e=Gt.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:()=>sn(Ze=>{const An=new Set(Ze);return An.has(ie.id)?An.delete(ie.id):An.add(ie.id),An}),children:[n.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[n.jsx("span",{className:"text-[10px] text-fg-tertiary",children:_e?"▼":"▶"}),n.jsx("button",{onClick:Ze=>{Ze.stopPropagation(),Nt.navigate(Te.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)})]}),_e&&n.jsxs("div",{className:"px-3 pb-2 pt-0.5 space-y-0.5",children:[ie.subItems.filter(Ze=>Ze.size>0).map(Ze=>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:Ze.name}),n.jsx("span",{className:"text-fg-secondary tabular-nums",children:Bc(Ze.size,i)})]},Ze.name)),n.jsx("div",{className:"pl-5 pt-1",children:n.jsx("button",{onClick:()=>{de.system.openPath(Xe.dataDir+"/agents/"+ie.id)},className:"text-[10px] text-fg-tertiary hover:text-fg-secondary underline",children:i("dataStorage.openFolder")})})]})]},ie.id)})})]}),vn&&(vn.orphanAgents.length>0||vn.orphanTeams.length>0)&&n.jsx(rG,{orphanInfo:vn,dataDir:Xe.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,D]=b.useState(null),M=b.useCallback(()=>{de.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??""),D(null)},F=async()=>{if(a)try{await de.users.update(a,{name:l,role:u,email:p||void 0}),i(null),D({type:"ok",text:t("settings:userManagement.updateSuccess")}),M()}catch(U){D({type:"err",text:`${t("settings:userManagement.error")}: ${String(U)}`})}},z=async()=>{if(!(!y||!v))try{await de.users.resetPassword(y,v),g(null),S(""),D({type:"ok",text:t("settings:userManagement.resetSuccess")})}catch(U){D({type:"err",text:`${t("settings:userManagement.error")}: ${String(U)}`})}},L=async U=>{if(U===e?.id){D({type:"err",text:t("settings:userManagement.cannotDeleteSelf")}),k(null);return}if(r.find(q=>q.id===U)?.role==="owner"){D({type:"err",text:t("settings:userManagement.cannotDeleteOwner")}),k(null);return}try{await de.users.remove(U),k(null),D({type:"ok",text:t("settings:userManagement.deleteSuccess")}),M()}catch(q){D({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),D({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 W=a===U.id,q=y===U.id,I=C===U.id,R=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:W?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}),R&&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:W?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:W?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:W?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(""),D(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 de.users.reinvite(U.id),X=`${window.location.origin}/#invite?token=${$}`;j(X),D({type:"ok",text:t("settings:userManagement.inviteLinkGenerated")})}catch($){D({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&&!R&&n.jsx("button",{onClick:()=>{k(U.id),D(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 de.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:()=>{de.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 de.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(Jj,{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=Yj(),y=b.useCallback(async()=>{try{const N=await de.settings.getRemote();r(N)}catch{r(null)}finally{a(!1)}},[]);b.useEffect(()=>{y()},[y]),b.useEffect(()=>fn.on("remote:status",N=>{const j=N.payload;j&&(r(j),l(!1))}),[]);const g=async()=>{l(!0),u(null);try{t?.enabled?(await de.settings.disableRemote(),await y(),l(!1)):(In.isAuthenticated()||await pi(),await de.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")}),In.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")})]}),In.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(Ok,{})]}),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(Ok,{})]})]}),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 Ok(){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),Cd(()=>import("./browser-hW8kkJnA.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 Vf=new Map;function Bl(e,t){Vf.has(e)||Vf.set(e,t().catch(()=>{}))}function Kl(e){const t=Vf.get(e);return Vf.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"}],_k={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 zk({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 AS({authUser:e}={}){const{t}=kt(["builder","common"]),r=js(),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,D]=b.useState(null),[M,_]=b.useState(null),[F,z]=b.useState(null),L=b.useCallback(()=>{m(!0),Promise.all([(Kl(ga.builderArtifacts)??de.builder.artifacts.list()).then(K=>K?.artifacts??[]).catch(()=>[]),(Kl(ga.builderAgents)??de.agents.list()).then(K=>K?.agents??[]).catch(()=>[]),(Kl(ga.builderHubMyItems)??In.myItems()).then(K=>K?.items??[]).catch(()=>[]),(Kl(ga.builderInstalled)??de.builder.artifacts.installed()).then(K=>K?.installed??{}).catch(()=>({}))]).then(([K,P,B,Z])=>{if(d(K),i(P),B.length>0){const J=new Map;for(const Q of B){const ee=Q.itemType==="agent"?"agent":Q.itemType==="team"?"team":"skill";for(const se of K)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,Y]of J)ee.set(se,Y);return ee})}const H=new Map;for(const J of K){const Q=`${J.type}/${J.name}`,ee=Z[Q];ee&&H.set(Q,{agentId:ee.agentId,agentIds:ee.agentIds,teamId:ee.teamId})}S(H)}).finally(()=>m(!1))},[]);b.useEffect(()=>{L();const K=P=>{P.detail?.page===Te.BUILDER&&L()};return window.addEventListener("markus:navigate",K),()=>window.removeEventListener("markus:navigate",K)},[L]);const U=K=>{const P=a.find(B=>B.role==="Secretary"||B.name==="Secretary");P?Nt.navigate(Te.TEAM,{agentId:P.id,prefillMessage:K}):Nt.navigate(Te.TEAM,{prefillMessage:K})},W=async K=>{const P=`${K.type}/${K.name}`;if(!v.has(P)){g({key:P,action:"install"});try{const B=await de.builder.artifacts.install(K.type,K.name),Z={};B.agent&&typeof B.agent=="object"&&(Z.agentId=B.agent.id),B.team&&typeof B.team=="object"&&(Z.teamId=B.team.id),Array.isArray(B.agents)&&(Z.agentIds=B.agents.map(H=>H.id)),S(H=>new Map(H).set(P,Z)),window.dispatchEvent(new CustomEvent("markus:data-changed"))}catch(B){console.error("Install failed:",B),alert(t("installFailed",{error:String(B)}))}finally{g(null)}}},q=async K=>{const P=`${K.type}/${K.name}`;if(v.has(P)){g({key:P,action:"uninstall"});try{await de.builder.artifacts.uninstall(K.type,K.name),S(B=>{const Z=new Map(B);return Z.delete(P),Z}),window.dispatchEvent(new CustomEvent("markus:data-changed"))}catch(B){console.error("Uninstall failed:",B),alert(t("uninstallFailed",{error:String(B)}))}finally{g(null)}}},I=async(K,P)=>{const B=`${K.type}/${K.name}`;g({key:B,action:"share"});try{const Z=await de.builder.artifacts.get(K.type,K.name),H=K.meta.displayName||K.meta.name||K.name,J=K.meta.description||"",Q=K.meta.category||"general",ee=Array.isArray(K.meta.tags)?K.meta.tags:[],se=K.name;let Y=K.meta.icon||void 0;const me=K.meta.version||"1.0.0";if(Y&&!Y.startsWith("http")&&/\.(png|jpe?g|gif|webp|svg)$/i.test(Y)){const pe=Y.split("/").pop()??Y;try{const Oe=await fetch(`/api/builder/artifacts/${K.type}s/${encodeURIComponent(K.name)}/images/${encodeURIComponent(pe)}`);if(Oe.ok){const Ee=await Oe.blob(),fe=new File([Ee],pe,{type:Ee.type}),Le=await In.uploadImage(fe);Le?.url&&(Y=Le.url)}}catch{}}let be;const De=[],He=Array.isArray(K.meta.screenshots)?K.meta.screenshots:[];for(let pe=0;pe<He.length;pe++){const Oe=He[pe],Ee=Oe.split("/").pop()??Oe;try{const fe=await fetch(`/api/builder/artifacts/${K.type}s/${encodeURIComponent(K.name)}/images/${encodeURIComponent(Ee)}`);if(fe.ok){const Le=await fe.blob(),Qe=new File([Le],Ee,{type:Le.type}),nt=await In.uploadImage(Qe);nt?.url&&(De.push({url:nt.url,alt:Ee,order:pe}),(pe===0||K.meta.thumbnail===Oe)&&(be=nt.url))}}catch{}}const ke=await In.publishViaProxy({itemType:K.type==="team"?"team":K.type==="skill"?"skill":"agent",name:H,slug:se,description:J,category:Q,tags:ee,icon:Y,version:me,config:K.meta,files:Z.files&&Object.keys(Z.files).length>0?Z.files:void 0,thumbnailUrl:be,images:De.length>0?De:void 0,priceCents:P?.priceCents,donationsEnabled:P?.donationsEnabled});ke.id&&j(pe=>{const Oe=new Map(pe);return Oe.set(B,{id:ke.id,name:H,slug:ke.slug??se,version:me}),Oe})}catch(Z){console.error("Share failed:",Z),alert(t("shareFailed",{error:String(Z)}))}finally{g(null)}},R=async()=>{if(!T)return;const{key:K}=T,P=N.get(K);if(D(null),!P)return;const B=P.id;g({key:K,action:"hubDelete"});try{await In.deleteItem(B),j(Z=>{const H=new Map(Z);return H.delete(K),H})}catch(Z){console.error("Hub delete failed:",Z),alert(t("hubDeleteFailed",{error:String(Z)}))}finally{g(null)}},E=async()=>{if(!C)return;const K=C,P=`${K.type}/${K.name}`;k(null),g({key:P,action:"delete"});try{await de.builder.artifacts.delete(K.type,K.name),d(B=>B.filter(Z=>!(Z.type===K.type&&Z.name===K.name))),S(B=>{const Z=new Map(B);return Z.delete(P),Z}),window.dispatchEvent(new CustomEvent("markus:data-changed"))}catch(B){console.error("Delete failed:",B)}finally{g(null)}},$=p==="all"?l:l.filter(K=>K.type===p),X=K=>{history.pushState(null,"",`#builder/${K.type}/${encodeURIComponent(K.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(K=>{const P=t(`prompts.${K.id}Prompt`),B=t(`prompts.${K.id}Examples`,{returnObjects:!0}),Z=Array.isArray(B)?B:[];return n.jsx("button",{onClick:()=>U(P),className:`group text-left w-full rounded-xl border ${K.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 ${K.bgColor} flex items-center justify-center shrink-0`,children:K.icon}),n.jsxs("div",{className:"flex-1 min-w-0",children:[n.jsx("h3",{className:`text-sm font-semibold bg-gradient-to-r ${K.color} bg-clip-text text-transparent`,children:t(`prompts.${K.id}`)}),n.jsx("p",{className:"text-[11px] text-fg-tertiary mt-1 leading-relaxed",children:t(`prompts.${K.id}Desc`)}),Z.length>0&&n.jsx("div",{className:"mt-2 flex flex-wrap gap-1.5",children:Z.slice(0,2).map((H,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(P+H)},children:["“",H,"”"]},J))})]})]})},K.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(K=>n.jsx("button",{onClick:()=>h(K),className:`text-xs px-2.5 py-1 rounded-lg transition-colors ${p===K?"bg-brand-600 text-white":"text-fg-tertiary hover:text-fg-secondary hover:bg-surface-elevated"}`,children:t(K==="all"?"myCreations.filterAll":K==="agent"?"myCreations.filterAgents":K==="team"?"myCreations.filterTeams":"myCreations.filterSkills")},K))})]})}),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(K=>{const P=_k[K.type]??_k.agent,B=K.meta.displayName||K.meta.name||K.name,Z=K.meta.description||"",H=`${K.type}/${K.name}`,J=y?.key===H?y.action:null,Q=N.get(H),ee=K.meta.version||"1.0.0",se=!!Q,Y=se&&Q.version!==ee,me=()=>{const De=In.getUser();return!Q||!De?null:`${In.getUrl()}/${encodeURIComponent(De.username)}/${encodeURIComponent(Q.slug)}`},be=n.jsxs("div",{className:`flex items-center gap-1.5 ${r?"flex-wrap":"shrink-0"}`,onClick:De=>De.stopPropagation(),children:[v.has(H)?n.jsx("button",{onClick:()=>q(K),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:()=>W(K),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&&Y?n.jsx("button",{onClick:()=>z(K),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:()=>D({key:H,name:B}),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 In.ensureAuth(),Array.isArray(K.meta.screenshots)&&K.meta.screenshots.length>0?I(K):_(K)},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(K),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:()=>X(K),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 De=K.meta.icon,ke=De&&(De.startsWith("http")||De.startsWith("/")||/\.(png|jpe?g|gif|webp|svg)$/i.test(De))?De.startsWith("http")||De.startsWith("/")?De:`/api/builder/artifacts/${K.type}s/${encodeURIComponent(K.name)}/images/${encodeURIComponent(De.split("/").pop()??"")}`:null;return n.jsx("div",{className:`w-9 h-9 rounded-lg ${P.bg} flex items-center justify-center text-lg shrink-0 overflow-hidden`,children:ke?n.jsx("img",{src:ke,alt:"",className:"w-full h-full object-cover"}):De?n.jsx("span",{children:De}):P.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:B}),n.jsx("span",{className:`text-[10px] font-medium uppercase tracking-wider ${P.color}`,children:K.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:De=>{De.stopPropagation(),de.system.openPath(K.path).catch(()=>{})},className:"hover:text-fg-secondary transition-colors truncate min-w-0",title:K.path,children:oG(K.path)}),n.jsx("span",{className:"shrink-0",children:new Date(K.updatedAt).toLocaleDateString()})]})]}),!r&&be]}),r&&n.jsx("div",{className:"mt-3 pt-3 border-t border-border-default/50",children:be})]},H)})}),C&&n.jsx(zk,{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(zk,{title:t("confirmDelete"),message:t("removeFromHub",{name:T.name}),cancelLabel:t("common:cancel"),confirmLabel:t("common:delete"),onConfirm:()=>{R()},onCancel:()=>D(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:K=>K.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 K=M;_(null),I(K)},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 K=M;_(null),X(K)},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:K=>K.stopPropagation(),children:n.jsx(dG,{isUpdate:N.has(`${F.type}/${F.name}`),onCancel:()=>z(null),onConfirm:(K,P)=>{const B=F;z(null),I(B,{donationsEnabled:K==="donation",priceCents:K==="paid"?P: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,D=`${s??""} ${!e?"text-fg-muted italic":""}`;return r==="h1"?n.jsx("h1",{className:D,children:j}):r==="p"?n.jsx("p",{className:D,children:j}):n.jsx("span",{className:D,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 Ob({content:e}){return n.jsx("div",{className:`prose prose-invert prose-sm max-w-none
655
+ `)){zr(!0),Vi(mt.toLowerCase()),Es(0);return}}}zr(!1)},_e=te=>{const je=Xt.current?.selectionStart??xt.length,Pe=xt.slice(0,je).lastIndexOf("@"),At=xt.slice(je),We=te.includes(" ")?`@[${te}]`:`@${te}`,mt=xt.slice(0,Pe)+We+" "+At;Ve(mt),zr(!1),Es(0);const pt=Pe+We.length+1;requestAnimationFrame(()=>{Xt.current?.setSelectionRange(pt,pt)})},Ze=10*1024*1024,An=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),[]),bs=te=>te.dataUrl.startsWith("data:image/"),$h=(te,je)=>{if(bs({dataUrl:je}))return null;const Ie=te.split(".").pop()?.toLowerCase()??"";return{pdf:"📄",docx:"📝",doc:"📝",xlsx:"📊",xls:"📊",pptx:"📎",csv:"📊",json:"🔧",xml:"🔧",html:"🌐",epub:"📚"}[Ie]??"📁"},bl=b.useCallback(te=>{const je=Array.from(te).filter(Aa);if(je.length!==0)for(const Ie of je){if(Ie.size>Ze)continue;const Pe=new FileReader;Pe.onload=()=>{const At=Pe.result;br(We=>We.length>=An||We.some(mt=>mt.dataUrl===At)?We:[...We,{id:`img_${Date.now()}_${Math.random().toString(36).slice(2,6)}`,dataUrl:At,name:Ie.name}])},Pe.readAsDataURL(Ie)}},[Aa]),Bh=b.useCallback(te=>{br(je=>je.filter(Ie=>Ie.id!==te))},[]),Hh=b.useCallback(te=>{const je=te.clipboardData?.files;if(je&&je.length>0){const Ie=Array.from(je).filter(Aa);Ie.length>0&&(te.preventDefault(),bl(Ie))}},[bl,Aa]),Td=b.useCallback(te=>{te.preventDefault();const je=te.dataTransfer?.files;je&&je.length>0&&bl(Array.from(je).filter(Aa))},[bl,Aa]),yl=b.useCallback(te=>{te.preventDefault()},[]),Jr=d.find(te=>te.id===ue),vl=t?.name??a("page.fallbackYou"),Ad=rt[rt.length-1],k0=Vt&&Ad?.sender==="agent",j0=$n&&Ad?.sender==="agent",Ed=b.useMemo(()=>{if(ze!=="channel")return null;if(ne.startsWith("group:custom:")){const je=Xe.find(Ie=>Ie.channelKey===ne);return je?.members?new Set(je.members.filter(Ie=>Ie.type==="agent").map(Ie=>Ie.id)):null}if(!ur)return null;const te=vn.find(je=>je.id===ur);return te?new Set(te.members.filter(je=>je.type==="agent").map(je=>je.id)):null},[ze,ne,ur,vn,Xe]),oa=d.filter(te=>Ed?Ed.has(te.id):!0).filter(te=>te.name.toLowerCase().includes(Ka)),Md=m.find(te=>te.id===Be),Rd=Be===t?.id||!Be,Xs=Xe.find(te=>te.channelKey===ne);b.useEffect(()=>{if(r||!ne.startsWith("group:custom:"))return;const te=Xe.find(je=>je.channelKey===ne);!te||te.members||de.groupChats.getById(te.id).then(je=>{je.chat.members&&bt(Ie=>Ie.map(Pe=>Pe.id===te.id?{...Pe,members:je.chat.members}:Pe))}).catch(()=>{})},[r,ne,Xe]);const Dd=ze==="channel"?Xs?.name??ne:ze==="direct"?Jr?.name??a("page.selectAgent"):ze==="dm"?Rd?a("chat.myNotes"):Md?.name??a("page.directMessage"):a("page.chatTitle"),N0=ze==="channel"?Xs?a("page.placeholder.channel",{name:Xs.name}):a("page.placeholder.channelWithMention",{name:ne}):ze==="dm"?Rd?a("page.placeholder.dmSelf"):a("page.placeholder.dmOther",{name:Md?.name??""}):a(ue?"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(vW,{authUser:t,agents:d,teams:vn,humans:m,tasks:_t,externalAgents:or,groupChats:Xe,chatMode:ze,selectedAgent:ue,activeChannel:ne,activeDmUserId:Be,previewMode:r,onSelectAgent:te=>{ce("direct"),Me(te),_("chat"),sn(!1),g&&T()},onSelectChannel:te=>{ce("channel"),he(te),_("chat"),sn(!1),g&&T()},onSelectDm:te=>{ce("dm"),Se(te),_("chat"),sn(!1),g&&T()},onSelectTeam:te=>{const je=Xe.find(Ie=>Ie.type==="team"&&Ie.teamId===te);g?D(te):je&&(ce("channel"),he(je.channelKey),_("chat"),sn(!1),!L&&!I&&U(!0))},selectedTeamId:ur??(ze==="direct"&&Jr?.teamId?Jr.teamId:null),onRefreshTeams:Ar,onRefreshAgents:Qr,onRefreshHumans:Sa,onRefreshGroupChats:Fr,onViewProfile:Qe,onManageGroupMembers:te=>{ce("channel"),he(te),_("chat"),sn(!0),g&&T()},unreadByAgent:Xr,unreadByChannel:Wa,width:g?void 0:z.width,onResizeStart:g?void 0:z.onResizeStart,hidden:g&&k!=="roster",initialLoading:h}),g&&k==="team"&&N&&(()=>{const te=vn.find(Pe=>Pe.id===N);if(!te)return null;const je=d.filter(Pe=>Pe.teamId===N),Ie=Xe.find(Pe=>Pe.type==="team"&&Pe.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=Te.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||je.length})})]})]})]}),n.jsxs("div",{className:"flex-1 overflow-y-auto px-3 py-3 space-y-1",children:[Ie&&(()=>{const Pe=Wa[Ie.channelKey]??0;return n.jsxs("button",{onClick:()=>{ce("channel"),he(Ie.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:Ie.name}),n.jsx("div",{className:"text-[10px] text-fg-tertiary",children:a("chat.groupChat")})]}),Pe>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:Pe}):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"})})]})})(),je.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")}),je.map(Pe=>{const At=Xr.get(Pe.id)??0;return n.jsxs("button",{onClick:()=>{ce("direct"),Me(Pe.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:Pe.name||"Agent",avatarUrl:Pe.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:Pe.name}),n.jsx("div",{className:"text-[10px] text-fg-tertiary truncate",children:Pe.role||Pe.status})]}),At>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:At}):n.jsx("span",{className:`w-2 h-2 rounded-full shrink-0 ${Pe.status==="active"||Pe.status==="idle"?"bg-green-500":Pe.status==="working"||Pe.status==="busy"?"bg-blue-500":Pe.status==="paused"?"bg-amber-500":"bg-gray-400"}`})]},Pe.id)})]})]})]})})(),L&&!I&&!g&&(()=>{const te=ur??(ze==="direct"?Jr?.teamId:void 0);if(!te)return null;const je=vn.find(Pe=>Pe.id===te);if(!je)return null;const Ie=Xe.find(Pe=>Pe.type==="team"&&Pe.teamId===te);return n.jsx(dk,{team:je,agents:d,humans:m,authUser:t,groupChat:Ie,chatMode:ze,selectedAgent:ue,activeChannel:ne,teams:vn,onSelectAgent:Pe=>{ce("direct"),Me(Pe),_("chat"),sn(!1)},onSelectChannel:Pe=>{ce("channel"),he(Pe),_("chat"),sn(!1)},onSelectDm:Pe=>{ce("dm"),Se(Pe),_("chat"),sn(!1)},onBack:()=>U(!1),onViewProfile:Qe,onRefreshAgents:Qr,onRefreshTeams:Ar,unreadByAgent:Xr,width:W.width,onResizeStart:W.onResizeStart})})(),E&&!g&&(()=>{const te=ur??(ze==="direct"?Jr?.teamId:void 0);if(!te)return null;const je=vn.find(Pe=>Pe.id===te);if(!je)return null;const Ie=Xe.find(Pe=>Pe.type==="team"&&Pe.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:W.width+8},children:n.jsx(dk,{team:je,agents:d,humans:m,authUser:t,groupChat:Ie,chatMode:ze,selectedAgent:ue,activeChannel:ne,teams:vn,onSelectAgent:Pe=>{ce("direct"),Me(Pe),_("chat"),sn(!1),$(!1)},onSelectChannel:Pe=>{ce("channel"),he(Pe),_("chat"),sn(!1),$(!1)},onSelectDm:Pe=>{ce("dm"),Se(Pe),_("chat"),sn(!1),$(!1)},onBack:()=>$(!1),onViewProfile:Pe=>{Qe(Pe),$(!1)},onRefreshAgents:Qr,onRefreshTeams:Ar,unreadByAgent:Xr,width:W.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:Dd}),ze==="direct"&&Jr&&n.jsx(Dk,{agent:Jr,tasks:_t,onViewProfile:Qe})]}),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)||Oe()},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(ze==="channel"?"page.teamTab":"page.profileTab")}),n.jsx("div",{className:"flex-1"}),ze==="channel"&&Xs?.type==="custom"&&n.jsxs("button",{onClick:()=>sn(!Gt),className:`text-[11px] px-2 py-1 rounded-md font-medium shrink-0 flex items-center gap-1 ${Gt?"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]}),ze==="direct"&&!uo(M)&&n.jsxs(n.Fragment,{children:[n.jsx("button",{onClick:qr,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:Dt,onClick:()=>$t(!Ct),className:`p-1 rounded-md transition-colors shrink-0 ${Ct?"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=ur?vn.find(jt=>jt.id===ur):void 0,je=ze==="direct"&&ue?VW:ze==="channel"&&ur?KW:["chat"],Ie=async()=>{const jt=se.trim();if(!jt){ee(!1);return}try{ze==="direct"&&ue?(await de.agents.updateConfig(ue,{name:jt}),Qr()):ze==="channel"&&ur&&(await de.teams.update(ur,{name:jt}),Ar())}catch{}ee(!1)},Pe=async()=>{try{ze==="direct"&&ue?(await de.agents.updateConfig(ue,{roleDescription:De}),Qr()):ze==="channel"&&ur&&(await de.teams.update(ur,{description:De}),Ar())}catch{}be(!1)},At=ze==="direct"?Jr?.name:ze==="channel"?te?.name??Xs?.name:Md?.name??"",We=ze==="direct"?Jr?.role||"":ze==="channel"&&te?.description||"",mt=ze==="direct"?Jr?.avatarUrl:void 0,pt=At||"U",ot=ze==="direct"&&ue||ze==="channel"&&ur;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)&&(ze==="channel"&&ur||ze==="direct"&&Jr?.teamId)&&n.jsx("button",{onClick:X,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"})]})}),ot&&(ze==="channel"&&ur?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:pt,avatarUrl:mt,size:36,className:"rounded-xl shrink-0"})),ot?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:ke,value:se,onChange:jt=>Y(jt.target.value),onBlur:Ie,onKeyDown:jt=>{jt.key==="Enter"&&Ie(),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:()=>{Y(At??""),ee(!0)},title:"Click to edit name",children:At}),ze==="direct"&&Jr&&n.jsx(Dk,{agent:Jr,tasks:_t,onViewProfile:Qe})]}),(ze==="direct"||ze==="channel"&&ur)&&(me?n.jsx("input",{ref:pe,value:De,onChange:jt=>He(jt.target.value),onBlur:Pe,onKeyDown:jt=>{jt.key==="Enter"&&Pe(),jt.key==="Escape"&&be(!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:()=>{He(We),be(!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:Dd}),ze==="dm"&&n.jsx("span",{className:"text-xs text-fg-tertiary",children:Rd?a("page.privateNotepad"):""})]}),n.jsxs("div",{className:"ml-auto flex items-center gap-2 shrink-0",children:[ze==="channel"&&Xs?.type==="custom"&&n.jsxs("button",{onClick:()=>sn(!Gt),className:`text-xs px-2.5 py-1 rounded-md border transition-colors flex items-center gap-1.5 ${Gt?"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]}),ze==="direct"&&Jr&&M==="chat"&&n.jsxs("div",{className:"flex items-center gap-1.5",children:[n.jsx("button",{onClick:qr,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:Dt,onClick:()=>$t(!Ct),className:`p-1.5 rounded-md transition-colors ${Ct?"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"})})})]})]})]}),je.length>1&&n.jsx("div",{className:"flex items-center gap-1 px-4 pb-1.5 overflow-x-auto scrollbar-hide",children:je.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:GW(jt)}),WW(jt,a)]},jt))})]})})(),ze==="direct"&&ue&&M==="chat"&&Wt.length>1&&n.jsx("div",{className:"flex items-center gap-0 px-3 overflow-x-auto scrollbar-hide",children:Wt.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===rn?"text-brand-500 bg-brand-500/10":"text-fg-tertiary hover:text-fg-secondary hover:bg-surface-elevated/50"}`,onClick:()=>{if(te.id===on){Ce(on);const je=Je.current;Ke.current.delete(je),ht([])}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===on?a("page.newChat"):te.isMain?a("page.sessionMain"):te.title||a("page.sessionConversation")}),!te.isMain&&n.jsx("button",{onClick:je=>{je.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))}),ze==="channel"&&Xs?.type==="custom"&&Gt&&(()=>{const te=Xs,je=te.members??[],Ie=[];for(const Pe of d)je.some(At=>At.id===Pe.id)||Ie.push({id:Pe.id,name:Pe.name,type:"agent",subtitle:Pe.role||"Agent"});for(const Pe of m)je.some(At=>At.id===Pe.id)||Ie.push({id:Pe.id,name:Pe.name,type:"human",subtitle:Pe.email||Pe.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")," (",je.length,")"]}),n.jsx("button",{onClick:()=>sn(!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:je.map(Pe=>n.jsxs("span",{className:`inline-flex items-center gap-1.5 px-2 py-1 rounded-full text-[11px] font-medium ${Pe.type==="agent"?"bg-brand-500/10 text-brand-500":"bg-green-500/10 text-green-600"}`,children:[n.jsx(gr,{name:Pe.name,size:16,bgClass:Pe.type==="agent"?"bg-brand-500/15 text-brand-500":"bg-green-500/15 text-green-600"}),Pe.name,Pe.id!==t?.id&&n.jsx("button",{onClick:async()=>{try{await de.groupChats.removeMember(te.id,Pe.id),bt(At=>At.map(We=>We.id===te.id?{...We,members:(We.members??[]).filter(mt=>mt.id!==Pe.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"})]})})]},Pe.id))}),Ie.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 Pe=>{const At=Pe.target.value;if(!At)return;const We=Ie.find(mt=>mt.id===At);if(We)try{await de.groupChats.addMember(te.id,We.id,We.type,We.name),bt(mt=>mt.map(pt=>pt.id===te.id?{...pt,members:[...pt.members??[],{id:We.id,name:We.name,type:We.type}],memberCount:(pt.memberCount??0)+1}:pt))}catch{}},children:[n.jsx("option",{value:"",children:a("page.addMemberPlaceholder")}),Ie.map(Pe=>n.jsxs("option",{value:Pe.id,children:["[",Pe.type==="agent"?"Agent":"Human","] ",Pe.name]},Pe.id))]})})]})})(),ze==="direct"&&ue&&Ct&&n.jsxs("div",{ref:Jt,className:"absolute right-4 top-full mt-1 w-72 max-h-[420px] bg-surface-secondary border border-border-default rounded-xl shadow-2xl shadow-black/40 z-50 flex flex-col overflow-hidden",children:[n.jsxs("div",{className:"px-4 py-3 border-b border-border-default flex items-center justify-between",children:[n.jsx("span",{className:"text-xs font-semibold text-fg-secondary uppercase tracking-wider",children:a("page.historyTitle")}),n.jsx("button",{onClick:()=>$t(!1),className:"text-fg-tertiary hover:text-fg-secondary text-xs",children:"✕"})]}),n.jsxs("div",{className:"flex-1 overflow-y-auto p-2",children:[Dr.length===0&&n.jsx("div",{className:"text-xs text-fg-tertiary text-center py-6",children:a("page.noConversationsYet")}),(()=>{const te=new Date,je=new Date(te.getFullYear(),te.getMonth(),te.getDate()).getTime(),Ie=je-864e5,Pe=je-7*864e5,At=[],We=[],mt=[],pt=[],ot=[];for(const jt of Dr){const an=new Date(jt.lastMessageAt).getTime();an>=je?We.push(jt):an>=Ie?mt.push(jt):an>=Pe?pt.push(jt):ot.push(jt)}return We.length>0&&At.push({label:a("page.dateToday"),items:We}),mt.length>0&&At.push({label:a("page.dateYesterday"),items:mt}),pt.length>0&&At.push({label:a("page.datePrevious7Days"),items:pt}),ot.length>0&&At.push({label:a("page.dateOlder"),items:ot}),At.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===rn?"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"&&ze==="direct"&&ue&&n.jsx("div",{className:"flex-1 overflow-y-auto",children:n.jsx(uk,{agentId:ue,onBack:()=>_("chat"),inline:!0,defaultTab:B,highlightMailboxId:H,onSwipeBack:()=>{uo(F.current)?history.back():_("chat")},authUser:t})}),g&&M==="profile"&&ze==="channel"&&ur&&n.jsx("div",{className:"flex-1 overflow-y-auto",onTouchStart:g?Le.onTouchStart:void 0,onTouchEnd:g?Le.onTouchEnd:void 0,children:n.jsx(Nk,{teamId:ur,onBack:()=>_("chat"),inline:!0,onSelectAgent:te=>{ce("direct"),Me(te),Oe()}})}),!g&&uo(M)&&ze==="direct"&&ue&&n.jsx("div",{className:"flex-1 overflow-y-auto",children:n.jsx(uk,{agentId:ue,onBack:()=>_("chat"),inline:!0,headless:!0,activeTab:M,highlightMailboxId:H,authUser:t})}),!g&&uo(M)&&ze==="channel"&&ur&&n.jsx("div",{className:"flex-1 flex flex-col min-h-0",children:n.jsx(Nk,{teamId:ur,onBack:()=>_("chat"),inline:!0,headless:!0,activeTab:M,onSelectAgent:te=>{ce("direct"),Me(te),_("overview"),!L&&!I&&U(!0)}})}),n.jsxs("div",{className:`flex-1 overflow-hidden flex flex-col relative ${M!=="chat"?"hidden":""}`,children:[Qn&&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:Ki,onTouchStart:g?Le.onTouchStart:void 0,onTouchEnd:g?Le.onTouchEnd:void 0,children:[rt.length===0&&!Vt&&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:ze==="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"})})}),ze==="channel"&&n.jsx("div",{children:a("page.emptyChannel",{name:Xs?.name??ne})}),ze==="direct"&&!ue&&n.jsx("div",{children:a("page.emptySelectAgent")}),ze==="direct"&&ue&&n.jsx("div",{children:a("page.emptyNewConversation",{name:Jr?.name??""})})]}),ze==="channel"?rt.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:je=>{if(te.sender==="agent"&&te.agentId){const Ie=je.currentTarget.getBoundingClientRect();P({agentId:te.agentId,top:Ie.top,left:Ie.right+8})}},children:n.jsx(gr,{name:te.sender==="user"?vl:te.agentName??a("page.fallbackAgent"),avatarUrl:te.sender==="user"?t?.avatarUrl:d.find(je=>je.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 je=document.getElementById(`msg-${te.replyToId}`);je&&(je.scrollIntoView({behavior:"smooth",block:"center"}),je.classList.add("bg-brand-500/10"),setTimeout(()=>je.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(Vr,{content:te.text,className:"text-sm text-fg-secondary",onMentionClick:nt,knownNames:gt}):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((je,Ie)=>n.jsx("img",{src:je,alt:"",className:"max-w-[200px] max-h-[150px] rounded-lg object-cover cursor-pointer hover:opacity-80 transition-opacity",onClick:()=>window.open(je,"_blank")},Ie))}),ck(te.text,d,(je,Ie)=>{const Pe=Ie.currentTarget.getBoundingClientRect();P({agentId:je.id,top:Pe.bottom,left:Pe.left})})]}),te.isNotification&&n.jsx(Ck,{priority:te.notifyPriority})]}),!r&&n.jsx("div",{className:`transition-opacity ${g?"opacity-100":"opacity-0 group-hover/msg:opacity-100"}`,children:n.jsx(Ak,{msg:te,onCopy:pr,onRetry:Cn,onResume:Et,onReply:Ds,isCopied:Ye===te.id,isLastAgentMsg:te.id===en})})]})]},te.id)):rt.map((te,je)=>{const Pe=k0&&je===rt.length-1&&Vt,At=j0&&je===rt.length-1||Pe,We=!Pe||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??(ze==="direct"?Jr?.name??a("page.fallbackAgent"):a("page.fallbackAgent")),avatarUrl:te.sender==="user"?t?.avatarUrl:d.find(mt=>mt.id===(te.agentId??(ze==="direct"?Jr?.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(FW,{name:te.agentName??(ze==="direct"?Jr?.name??a("page.fallbackAgent"):a("page.fallbackAgent")),agentId:te.agentId??(ze==="direct"?Jr?.id:void 0),agents:d,onViewProfile:Qe})}),n.jsx("span",{className:"text-xs text-fg-tertiary",children:te.time})]}),te.replyToId&&te.replyToSender&&n.jsxs("button",{onClick:()=>{const mt=document.getElementById(`msg-${te.replyToId}`);mt&&(mt.scrollIntoView({behavior:"smooth",block:"center"}),mt.classList.add("bg-brand-500/10"),setTimeout(()=>mt.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":""} ${At&&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((mt,pt)=>n.jsx("img",{src:mt,alt:"",className:"max-w-[200px] max-h-[150px] rounded-lg object-cover cursor-pointer hover:opacity-80 transition-opacity",onClick:()=>window.open(mt,"_blank")},pt))}),te.text&&n.jsx("span",{className:"leading-relaxed",children:ck(te.text,d,(mt,pt)=>{const ot=pt.currentTarget.getBoundingClientRect();P({agentId:mt.id,top:ot.bottom,left:ot.left})})})]}):n.jsx(UW,{msg:te,isStreaming:Pe,liveActivities:Pe?jr:[],onViewModeChange:mt=>Tt(pt=>{const ot=new Set(pt);return mt==="full"?ot.add(te.id):ot.delete(te.id),ot}),onMentionClick:nt,knownNames:gt}),te.isNotification&&n.jsx(Ck,{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(Ak,{msg:te,onCopy:pr,onRetry:Cn,onResume:Et,onReply:Ds,isCopied:Ye===te.id,isLastAgentMsg:te.id===en})})]})]},te.id)}),ze==="channel"&&Un.length>0&&n.jsx("div",{className:"flex flex-col gap-1.5 py-2",children:Un.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:()=>Qe(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})]})]}),K&&(()=>{const te=d.find(je=>je.id===K.agentId);return te?n.jsx(qW,{agent:te,anchorRect:{top:K.top,left:K.left},onClose:()=>P(null),onViewProfile:Qe}):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,je)=>n.jsxs("button",{ref:Ie=>{je===Ws&&Ie&&Ie.scrollIntoView({block:"nearest"})},onClick:()=>_e(te.name),onMouseEnter:()=>Es(je),className:`w-full text-left px-4 py-2 text-sm flex items-center gap-2 transition-colors ${je===Ws?"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))]}),Zn.length>0&&n.jsxs("div",{className:"flex items-center gap-2 mb-2 overflow-x-auto pb-1",children:[Zn.map(te=>n.jsxs("div",{className:"relative group/img shrink-0",children:[bs(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:$h(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)),Zn.length<An&&n.jsx("button",{onClick:()=>Bn.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"})})})]}),Zn.length>0&&Zn.some(te=>bs(te))&&Jr&&Jr.modelSupportsVision===!1&&n.jsxs("div",{className:"text-[10px] text-amber-500/80 mb-1.5 flex items-center gap-1",children:[n.jsx("svg",{className:"w-3 h-3 shrink-0",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:n.jsx("path",{d:"M12 9v4m0 4h.01M12 2L2 22h20L12 2z",strokeLinecap:"round",strokeLinejoin:"round"})}),a("page.visionWarning")]}),n.jsx("input",{ref:Bn,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=""}}),ut&&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:ut.sender}),n.jsx("p",{className:"text-[11px] text-fg-tertiary truncate",children:ut.text})]}),n.jsx("button",{onClick:()=>it(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:()=>Bn.current?.click(),disabled:ze==="direct"&&!ue,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:Xt,value:xt,onChange:te=>{ie(te.target.value),pn()},onKeyDown:te=>{if(sa&&oa.length>0){const je=te.key==="ArrowUp"||te.ctrlKey&&te.key==="p",Ie=te.key==="ArrowDown"||te.ctrlKey&&te.key==="n",Pe=te.key==="Enter"||te.key==="Tab",At=te.key==="Escape";if(je){te.preventDefault(),Es(We=>(We-1+oa.length)%oa.length);return}if(Ie){te.preventDefault(),Es(We=>(We+1)%oa.length);return}if(Pe){te.preventDefault();const We=oa[Ws];We&&_e(We.name);return}if(At){te.preventDefault(),zr(!1);return}}te.key==="Enter"&&!te.shiftKey&&(te.preventDefault(),ae())},onPaste:Hh,placeholder:N0,disabled:ze==="direct"&&!ue,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"}}),Vt&&ze!=="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:ze==="direct"&&!ue||!xt.trim()&&Zn.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 Dk({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(Te.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 QW=[{value:"system",label:"System"},{value:"light",label:"Light"},{value:"dark",label:"Dark"},{value:"cyberpunk",label:"Cyberpunk"},{value:"mono",label:"Mono"}],Pb="markus-theme";function Lk(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 ZW(){try{const e=localStorage.getItem(Pb);if(e==="midnight")return localStorage.setItem(Pb,"dark"),"dark";if(e==="light"||e==="dark"||e==="system"||e==="cyberpunk"||e==="mono")return e}catch{}return"system"}function JW(){const[e,t]=b.useState(ZW),r=b.useCallback(s=>{t(s);try{localStorage.setItem(Pb,s)}catch{}Lk(s)},[]);return b.useEffect(()=>{Lk(e)},[e]),{mode:e,setMode:r}}const TS=[{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 Ik(){const t=window.location.hash.slice(1).split("/");if(t[0]==="settings"&&t[1]){const r=t[1];if(TS.some(s=>s.id===r))return r}return null}function Pk({theme:e,onThemeChange:t,authUser:r,onLogout:s,onUserUpdated:a}={}){const{t:i,i18n:l}=kt(["settings","common"]),d=js(),[u,m]=b.useState(!1),[p,h]=b.useState(!1),y=b.useRef(null),[g,v]=b.useState(Ik);b.useEffect(()=>{const ie=()=>v(Ik());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=_e=>{y.current&&!y.current.contains(_e.target)&&m(!1)};return document.addEventListener("mousedown",ie),()=>document.removeEventListener("mousedown",ie)},[u]);const[N,j]=b.useState(null),[T,D]=b.useState(null),[M,_]=b.useState(""),[F,z]=b.useState(!1),[L,U]=b.useState(null),[W,q]=b.useState(null),[I,R]=b.useState(null),[E,$]=b.useState(null),[X,K]=b.useState(!1),[P,B]=b.useState(null),[Z,H]=b.useState(null),[J,Q]=b.useState(!1),[ee,se]=b.useState(null),[Y,me]=b.useState({}),[be,De]=b.useState(!1),[He,ke]=b.useState(null),[pe,Oe]=b.useState(!1),[Ee,fe]=b.useState(""),[Le,Qe]=b.useState(!1),[nt,gt]=b.useState(null),[ze,ce]=b.useState([]),[ue,Me]=b.useState([]),[ne,he]=b.useState(null),[Be,Se]=b.useState(null),[Ke,at]=b.useState(""),[ct,Je]=b.useState(null),rt=b.useRef(null),ht=b.useRef(!1),[xt,Ve]=b.useState(!1),[ut,it]=b.useState(200),[Vt,Nn]=b.useState(!1),[Un,mn]=b.useState(null),[Tn,$n]=b.useState(!1),[dn,bn]=b.useState(1),[nr,ir]=b.useState(!1),[jr,xr]=b.useState(null),[rr,Ln]=b.useState(!1),[Qn,Vn]=b.useState(0),[Zn,br]=b.useState(!0),[Bn,Xt]=b.useState(!1),[pn,on]=b.useState(!1),[Dr,Nr]=b.useState(9333),[rn,Ce]=b.useState(!1),[Ct,$t]=b.useState(null),[Wt,qt]=b.useState(null),[Ne,Rt]=b.useState({serperApiKey:"",tavilyApiKey:"",bingApiKey:"",googleSearchApiKey:"",googleSearchCx:"",serpApiKey:"",braveApiKey:"",exaApiKey:"",bochaApiKey:""}),[Dt,Jt]=b.useState(!1),[Jn,xe]=b.useState(null),[Xe,bt]=b.useState(null),[Ft,tn]=b.useState(!1),[Gt,sn]=b.useState(new Set),[vn,Pn]=b.useState(null),[or,Lr]=b.useState(!1),_t=()=>({"Content-Type":"application/json",Authorization:`Bearer ${localStorage.getItem("markus_token")??""}`}),sr=b.useCallback(()=>{de.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&&(D(ie),_(ie.defaultProvider))}).catch(()=>{})},[]),_r=b.useCallback(()=>{fetch("/api/settings/oauth/providers").then(ie=>ie.ok?ie.json():Promise.reject(ie.status)).then(ie=>ce(ie.providers??[])).catch(()=>{})},[]),dr=b.useCallback(()=>{fetch("/api/settings/oauth/profiles",{headers:_t()}).then(ie=>ie.ok?ie.json():Promise.reject(ie.status)).then(ie=>Me(ie.profiles??[])).catch(()=>{})},[]),Va=b.useCallback(()=>{de.settings.getAgent().then(ie=>{ie&&typeof ie.maxToolIterations=="number"&&it(ie.maxToolIterations),ie?.cognitive&&($n(ie.cognitive.enabled??!1),bn(ie.cognitive.maxDepth??1))}).catch(()=>{})},[]),Yr=b.useCallback(()=>{de.settings.getBrowser().then(ie=>{ie&&(Ln(ie.bringToFront??!1),Vn(ie.remoteDebuggingPort??0),br(ie.autoCloseTabs??!0),Xt(ie.autoClickAllowDialog??!1),on(ie.extensionConnected??!1),Nr(ie.extensionBridgePort??9333))}).catch(()=>{})},[]),$s=b.useCallback(()=>{de.settings.getSearch().then(ie=>{ie&&qt(ie)}).catch(()=>{})},[]),Bs=b.useCallback(()=>{tn(!0),de.system.storage().then(bt).catch(()=>{}).finally(()=>tn(!1)),de.system.orphans().then(Pn).catch(()=>{})},[]);b.useEffect(()=>{sr(),_r(),dr(),Va(),Yr(),$s(),Bs()},[sr,_r,dr,Va,Yr,$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),H(null),me({});try{const ie=await fetch("/api/settings/env-models",{headers:_t()});if(!ie.ok){se({type:"err",text:i("envConfig.detectionFailedHttp",{status:ie.status})});return}const _e=await ie.json();if(H(_e),_e.detected.length===0)se({type:"err",text:i("envConfig.noKeysFound")});else{const Ze={};for(const An of _e.detected)Ze[An.provider]=!0;me(Ze)}}catch{se({type:"err",text:i("envConfig.failedToDetect")})}finally{Q(!1)}},[i]),zr=b.useCallback(async()=>{Oe(!0),gt(null),ke(null);try{const ie=await fetch("/api/settings/detect-ollama",{headers:_t()});if(!ie.ok){gt({type:"err",text:i("ollama.detectFailed")});return}const _e=await ie.json();ke(_e),_e.found&&_e.models&&_e.models.length>0?fe(_e.models[0].name):_e.found||gt({type:"err",text:_e.error||i("ollama.notRunning")})}catch{gt({type:"err",text:i("ollama.detectFailed")})}finally{Oe(!1)}},[i]),Ka=T?Object.values(T.providers).some(ie=>ie.configured):!1;b.useEffect(()=>{T&&!Ka&&!ht.current&&(ht.current=!0,sa(),zr())},[T,Ka,sa,zr]);const Vi=async()=>{if(!(!M||M===T?.defaultProvider)){z(!0),U(null);try{const ie=await fetch("/api/settings/llm",{method:"POST",headers:_t(),body:JSON.stringify({defaultProvider:M})}),_e=await ie.json();ie.ok?(D(_e),U({type:"ok",text:i("defaultProvider.updated",{name:_e.defaultProvider})})):U({type:"err",text:_e.error??i("modelProviders.saveFailed")})}catch{U({type:"err",text:i("common:networkError")})}finally{z(!1)}}},Ws=async(ie,_e)=>{R(ie);try{const Ze=await fetch(`/api/settings/llm/providers/${ie}/toggle`,{method:"POST",headers:_t(),body:JSON.stringify({enabled:_e})});if(Ze.ok){const An=await Ze.json();D(An)}}catch{}finally{R(null)}},Es=async()=>{K(!0),B(null);try{const _e=await(await fetch("/api/settings/import/openclaw",{method:"POST",headers:_t(),body:JSON.stringify({preview:!0})})).json();"error"in _e?B({type:"err",text:_e.error}):$(_e)}catch{B({type:"err",text:i("openClaw.detectFailed")})}finally{K(!1)}},ur=async()=>{K(!0),B(null);try{const _e=await(await fetch("/api/settings/import/openclaw",{method:"POST",headers:_t(),body:JSON.stringify({preview:!1})})).json();"error"in _e?B({type:"err",text:_e.error}):(B({type:"ok",text:i("openClaw.importedFrom",{count:_e.appliedModels})}),sr())}catch{B({type:"err",text:i("openClaw.importFailed")})}finally{K(!1)}},va=async()=>{if(!Z)return;const ie=Z.detected.filter(_e=>Y[_e.provider]);if(ie.length===0){se({type:"err",text:i("envConfig.selectAtLeastOne")});return}De(!0),se(null);try{const _e=await fetch("/api/settings/env-models",{method:"POST",headers:_t(),body:JSON.stringify({providers:ie.map(An=>({provider:An.provider,model:An.model,baseUrl:An.baseUrl,enabled:!0}))})});if(!_e.ok){se({type:"err",text:i("envConfig.applyFailed",{status:_e.status})});return}const Ze=await _e.json();se({type:"ok",text:Ze.message}),H(null),me({}),sr()}catch{se({type:"err",text:i("envConfig.failedToApply")})}finally{De(!1)}},Hs=async()=>{if(!(!He?.found||!Ee)){Qe(!0),gt(null);try{const ie=await fetch("/api/settings/llm/providers",{method:"POST",headers:_t(),body:JSON.stringify({name:"ollama",model:Ee,baseUrl:He.baseUrl||"http://localhost:11434"})});if(ie.ok){const _e=await ie.json();D(_e),gt({type:"ok",text:i("ollama.configured",{model:Ee})}),ke(null)}else{const _e=await ie.json();gt({type:"err",text:_e.error||i("ollama.applyFailed")})}}catch{gt({type:"err",text:i("ollama.applyFailed")})}finally{Qe(!1)}}};b.useEffect(()=>()=>{rt.current&&clearInterval(rt.current)},[]),b.useEffect(()=>{if(k!=="browser"||pn)return;const ie=setInterval(async()=>{try{(await de.settings.getBrowser()).extensionConnected&&(on(!0),clearInterval(ie))}catch{}},5e3);return()=>clearInterval(ie)},[k,pn]);const[xs,li]=b.useState(!1),[gn,yr]=b.useState({name:"",apiKey:"",baseUrl:"",model:"",contextWindow:128e3,maxOutputTokens:16384,costInput:1,costOutput:5}),[ci,wa]=b.useState(!1),[Ms,Ir]=b.useState(null),[ji,yn]=b.useState(null),[Kn,Xr]=b.useState({apiKey:"",baseUrl:"",model:"",contextWindow:0,maxOutputTokens:0,costInput:0,costOutput:0}),[Rs,ka]=b.useState(!1),[ja,Ns]=b.useState(null),[Gs,Na]=b.useState(""),[di,Wa]=b.useState(!1),[Qr,Ar]=b.useState(null),[Fr,Ss]=b.useState(null),[Sn,Zr]=b.useState({id:"",name:"",contextWindow:128e3,maxOutputTokens:16384,costInput:1,costOutput:5,reasoning:!1,vision:!1}),[Sa,Cs]=b.useState(!1),aa=async()=>{if(!(!gn.name||!gn.model)){wa(!0),Ir(null);try{const ie=await fetch("/api/settings/llm/providers",{method:"POST",headers:_t(),body:JSON.stringify({name:gn.name,apiKey:gn.apiKey||void 0,baseUrl:gn.baseUrl||void 0,model:gn.model,contextWindow:gn.contextWindow||void 0,maxOutputTokens:gn.maxOutputTokens||void 0,cost:gn.costInput||gn.costOutput?{input:gn.costInput,output:gn.costOutput}:void 0})}),_e=await ie.json();ie.ok?(D(_e),li(!1),yr({name:"",apiKey:"",baseUrl:"",model:"",contextWindow:128e3,maxOutputTokens:16384,costInput:1,costOutput:5}),Ir({type:"ok",text:i("modelProviders.providerAdded",{name:gn.name})})):Ir({type:"err",text:_e.error??i("modelProviders.failedToAdd")})}catch{Ir({type:"err",text:i("common:networkError")})}finally{wa(!1)}}},Ca=async(ie,_e)=>{if(!Gs.trim())return;Wa(!0),Ar(null);const Ze=_e.models?.[0]?.id??ie;try{const An=await fetch("/api/settings/llm/providers",{method:"POST",headers:_t(),body:JSON.stringify({name:ie,apiKey:Gs.trim(),model:Ze})}),ia=await An.json();An.ok?(D(ia),Na(""),Ar({type:"ok",text:i("modelProviders.quickSetupSuccess",{name:_e.displayName??ie})})):Ar({type:"err",text:ia.error??i("modelProviders.failedToAdd")})}catch{Ar({type:"err",text:i("common:networkError")})}finally{Wa(!1)}},Ys=(ie,_e)=>{yn(ie),Xr({apiKey:"",baseUrl:_e.baseUrl??"",model:_e.model,contextWindow:_e.contextWindow??0,maxOutputTokens:_e.maxOutputTokens??0,costInput:_e.cost?.input??0,costOutput:_e.cost?.output??0})},Ga=async ie=>{ka(!0);try{const _e={};Kn.apiKey&&(_e.apiKey=Kn.apiKey),Kn.baseUrl!==void 0&&(_e.baseUrl=Kn.baseUrl),Kn.model&&(_e.model=Kn.model),Kn.contextWindow&&(_e.contextWindow=Kn.contextWindow),Kn.maxOutputTokens&&(_e.maxOutputTokens=Kn.maxOutputTokens),(Kn.costInput||Kn.costOutput)&&(_e.cost={input:Kn.costInput,output:Kn.costOutput});const Ze=await fetch(`/api/settings/llm/providers/${ie}`,{method:"PUT",headers:_t(),body:JSON.stringify(_e)});if(Ze.ok){const An=await Ze.json();D(An),yn(null)}}catch{}finally{ka(!1)}},To=async ie=>{Ns(ie);try{const _e=await fetch(`/api/settings/llm/providers/${ie}`,{method:"DELETE",headers:_t()});if(_e.ok){const Ze=await _e.json();D(Ze),_(Ze.defaultProvider)}}catch{}finally{Ns(null)}},ui=async ie=>{if(!(!Sn.id||!Sn.name)){Cs(!0);try{const _e=await fetch(`/api/settings/llm/providers/${ie}/models`,{method:"POST",headers:_t(),body:JSON.stringify({id:Sn.id,name:Sn.name,contextWindow:Sn.contextWindow,maxOutputTokens:Sn.maxOutputTokens,cost:{input:Sn.costInput,output:Sn.costOutput},reasoning:Sn.reasoning||void 0,inputTypes:Sn.vision?["text","image"]:["text"]})});if(_e.ok){const Ze=await _e.json();D(Ze),Ss(null),Zr({id:"",name:"",contextWindow:128e3,maxOutputTokens:16384,costInput:1,costOutput:5,reasoning:!1,vision:!1})}}catch{}finally{Cs(!1)}}},Ki=async(ie,_e)=>{try{const Ze=await fetch(`/api/settings/llm/providers/${ie}/models/${encodeURIComponent(_e)}`,{method:"DELETE",headers:_t()});if(Ze.ok){const An=await Ze.json();D(An)}}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,lt]=b.useState(null),[Tt,en]=b.useState({}),pr=async ie=>{lt(ie),en(_e=>{const Ze={..._e};return delete Ze[ie],Ze});try{const _e=await fetch(`/api/settings/llm/providers/${ie}/test`,{method:"POST",headers:_t()});if(!_e.ok){const An=await _e.json().catch(()=>({}));en(ia=>({...ia,[ie]:{ok:!1,error:An.error??`HTTP ${_e.status}`,errorCode:_e.status}}));return}const Ze=await _e.json();en(An=>({...An,[ie]:Ze}))}catch{en(_e=>({..._e,[ie]:{ok:!1,error:i("common:networkError")}}))}finally{lt(null)}},Cn=async(ie,_e)=>{ae(`${ie}:${_e}`);try{const Ze=await fetch(`/api/settings/llm/providers/${ie}/model`,{method:"POST",headers:_t(),body:JSON.stringify({model:_e})});if(Ze.ok){const An=await Ze.json();D(An)}}catch{}finally{ae(null)}},Et=async()=>{if(Ne.serperApiKey||Ne.tavilyApiKey||Ne.bingApiKey||Ne.googleSearchApiKey||Ne.googleSearchCx||Ne.serpApiKey||Ne.braveApiKey||Ne.exaApiKey||Ne.bochaApiKey){Jt(!0),xe(null);try{const _e={};Ne.serperApiKey&&(_e.serperApiKey=Ne.serperApiKey),Ne.tavilyApiKey&&(_e.tavilyApiKey=Ne.tavilyApiKey),Ne.bingApiKey&&(_e.bingApiKey=Ne.bingApiKey),Ne.googleSearchApiKey&&(_e.googleSearchApiKey=Ne.googleSearchApiKey),Ne.googleSearchCx&&(_e.googleSearchCx=Ne.googleSearchCx),Ne.serpApiKey&&(_e.serpApiKey=Ne.serpApiKey),Ne.braveApiKey&&(_e.braveApiKey=Ne.braveApiKey),Ne.exaApiKey&&(_e.exaApiKey=Ne.exaApiKey),Ne.bochaApiKey&&(_e.bochaApiKey=Ne.bochaApiKey);const Ze=await de.settings.updateSearch(_e);qt(Ze),Rt({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{Jt(!1)}}},Ds=T?.providers?Object.entries(T.providers).filter(([,ie])=>ie.configured&&ie.enabled).map(([ie])=>ie):[],Ls=T&&!Ka&&!xt,Fs=r?.role==="owner"||r?.role==="admin",qr=TS.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(Te.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:qr.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(Te.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:qr.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:${qr.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:QW.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:nw.map(({code:ie,label:_e})=>n.jsx("button",{onClick:()=>{l.changeLanguage(ie)},className:`px-3 py-1.5 text-xs rounded-md transition-colors ${l.language===ie||ie==="en"&&!nw.some(Ze=>Ze.code===l.language)?"bg-brand-600 text-white":"text-fg-secondary hover:text-fg-primary"}`,children:_e},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:()=>Ve(!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:Y[ie.provider]??!1,onChange:_e=>me({...Y,[ie.provider]:_e.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:be||Object.values(Y).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:be?i("common:applying"):i("setupGuide.applyProviders",{count:Object.values(Y).filter(Boolean).length})})]}),Z&&Z.detected.length===0&&n.jsx("div",{className:"text-xs text-fg-tertiary",children:n.jsx(Hu,{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:!!He?.found,children:[pe&&n.jsx("div",{className:"text-xs text-fg-tertiary",children:i("common:detecting")}),He?.found&&He.models&&He.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:He.models.length,url:He.baseUrl})}),n.jsx("select",{value:Ee,onChange:ie=>fe(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:He.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:Le||!Ee,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:Le?i("common:applying"):i("ollama.useModel",{model:Ee})})]}),!pe&&!He&&n.jsx("button",{onClick:()=>{zr()},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")}),He&&!He.found&&n.jsx("div",{className:"text-xs text-fg-tertiary",children:i("ollama.notRunning")}),nt&&n.jsx(Oa,{type:nt.type,text:nt.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,_e)=>ie+_e.modelCount,0)})}),n.jsx("button",{onClick:()=>{ur()},disabled:X,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(X?"common:importing":"openClaw.importConfigs")})]}):n.jsx("div",{className:"text-xs text-fg-tertiary",children:i("openClaw.notFound")}):n.jsx("button",{onClick:()=>{Es()},disabled:X,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(X?"common:detecting":"openClaw.detectShort")}),P&&n.jsx(Oa,{type:P.type,text:P.text})]}),n.jsx(yu,{step:i("setupGuide.manual.step"),title:i("setupGuide.manual.title"),description:n.jsx(Hu,{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:pn,children:pn?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:rn,onClick:async()=>{Ce(!0);try{await de.settings.downloadExtensionZip()}catch{}Ce(!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:rn,onClick:async()=>{try{await de.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:Ds.length>0?Ds.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 _e=await fetch("/api/settings/llm",{method:"POST",headers:_t(),body:JSON.stringify({autoFallback:ie})});if(_e.ok){const Ze=await _e.json();D(Ze)}}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,_e])=>n.jsxs("div",{className:`bg-surface-secondary border rounded-xl overflow-hidden transition-colors ${_e.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(W===ie?null:ie),Na(""),Ar(null)},children:[n.jsxs("div",{className:"flex items-center gap-3",children:[n.jsx("span",{className:`w-2 h-2 rounded-full ${_e.configured&&_e.enabled?"bg-green-400":_e.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:_e.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")}),_e.configured&&!_e.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")}),_e.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")}),Tt[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:Tt[ie].durationMs})}),Tt[ie]?.ok===!1&&n.jsx("span",{className:"text-[10px] bg-red-500/15 text-red-500 px-1.5 py-0.5 rounded",title:Tt[ie].error,children:Tt[ie].errorCode?i("modelProviders.testFailedCode",{code:Tt[ie].errorCode}):i("modelProviders.testFailed")})]}),n.jsx("div",{className:"text-xs text-fg-tertiary mt-0.5",children:_e.configured?n.jsxs(n.Fragment,{children:[_e.model,_e.apiKeyPreview&&n.jsxs(n.Fragment,{children:[" · ",n.jsx("code",{className:"text-fg-secondary",children:_e.apiKeyPreview})]})]}):i("modelProviders.notConfigured")})]})]}),n.jsxs("div",{className:"flex items-center gap-4",children:[_e.configured&&n.jsx("button",{onClick:Ze=>{Ze.stopPropagation(),Ws(ie,!_e.enabled)},disabled:I===ie,className:`relative inline-flex h-5 w-9 items-center rounded-full transition-colors ${_e.enabled?"bg-green-500":"bg-gray-600"} ${I===ie?"opacity-50":""}`,title:_e.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 ${_e.enabled?"translate-x-4":"translate-x-1"}`})}),_e.contextWindow&&n.jsx("span",{className:"text-[10px] text-fg-tertiary",children:i("modelProviders.ctxTokens",{size:(_e.contextWindow/1e3).toFixed(0)})}),_e.cost&&n.jsx("span",{className:"text-[10px] text-fg-tertiary",children:i("modelProviders.costPerMillion",{input:_e.cost.input,output:_e.cost.output})}),n.jsx("span",{className:"text-fg-tertiary text-xs",children:W===ie?"▲":"▼"})]})]}),W===ie&&n.jsxs("div",{className:"px-5 pb-4 border-t border-border-default pt-4 space-y-4",children:[_e.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:_e.model}),n.jsx(el,{label:i("modelProviders.contextWindow"),value:_e.contextWindow?i("modelProviders.kTokens",{k:(_e.contextWindow/1e3).toFixed(0)}):i("modelProviders.notApplicable")}),n.jsx(el,{label:i("modelProviders.maxOutput"),value:_e.maxOutputTokens?i("modelProviders.kTokens",{k:(_e.maxOutputTokens/1e3).toFixed(0)}):i("modelProviders.notApplicable")}),n.jsx(el,{label:i("modelProviders.baseUrlLabel"),value:_e.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:Ze=>Xr({...Kn,apiKey:Ze.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:Ze=>Xr({...Kn,baseUrl:Ze.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:Ze=>Xr({...Kn,model:Ze.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:Ze=>Xr({...Kn,contextWindow:Number(Ze.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:Ze=>Xr({...Kn,maxOutputTokens:Number(Ze.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:Ze=>Xr({...Kn,costInput:Number(Ze.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:Ze=>Xr({...Kn,costOutput:Number(Ze.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:Rs,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(Rs?"common:saving":"common:save")}),n.jsx("button",{onClick:()=>yn(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:Ze=>{Ze.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:Ze=>{Ze.stopPropagation(),Ys(ie,_e)},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:Ze=>{Ze.stopPropagation(),confirm(i("modelProviders.deleteConfirm",{name:_e.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")})]}),Tt[ie]&&n.jsx("div",{className:`text-xs px-3 py-2 rounded-lg ${Tt[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:Tt[ie].ok?i("modelProviders.testSuccess",{ms:Tt[ie].durationMs,reply:Tt[ie].reply}):Tt[ie].error})]}),_e.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:`$${_e.cost.input}`}),n.jsx(el,{label:i("modelProviders.output"),value:`$${_e.cost.output}`}),_e.cost.cacheRead!=null&&n.jsx(el,{label:i("modelProviders.cacheRead"),value:`$${_e.cost.cacheRead}`}),_e.cost.cacheWrite!=null&&n.jsx(el,{label:i("modelProviders.cacheWrite"),value:`$${_e.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")}),_e.configured&&Fr!==ie&&n.jsx("button",{onClick:()=>{Ss(ie),Zr({id:"",name:"",contextWindow:128e3,maxOutputTokens:16384,costInput:1,costOutput:5,reasoning:!1,vision:!1})},className:"text-[10px] text-brand-500 hover:text-brand-400 transition-colors",children:i("modelProviders.addModel")})]}),Fr===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:Sn.id,onChange:Ze=>Zr({...Sn,id:Ze.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:Sn.name,onChange:Ze=>Zr({...Sn,name:Ze.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:Sn.contextWindow,onChange:Ze=>Zr({...Sn,contextWindow:Number(Ze.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:Sn.maxOutputTokens,onChange:Ze=>Zr({...Sn,maxOutputTokens:Number(Ze.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:Sn.costInput,onChange:Ze=>Zr({...Sn,costInput:Number(Ze.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:Sn.costOutput,onChange:Ze=>Zr({...Sn,costOutput:Number(Ze.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:Sn.reasoning,onChange:Ze=>Zr({...Sn,reasoning:Ze.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:Sn.vision,onChange:Ze=>Zr({...Sn,vision:Ze.target.checked}),className:"rounded"}),i("modelProviders.vision")]}),n.jsx("div",{className:"flex-1"}),n.jsx("button",{onClick:()=>{ui(ie)},disabled:Sa||!Sn.id||!Sn.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")})]})]}),_e.models&&_e.models.length>0&&n.jsx("div",{className:"space-y-1.5",children:_e.models.map(Ze=>{const An=Ze.id===_e.model,ia=Ni===`${ie}:${Ze.id}`,Aa=!Ta.has(Ze.id);return n.jsxs("div",{className:`flex items-center justify-between px-3 py-2 rounded-lg text-xs transition-colors ${An?"bg-brand-500/15 border border-brand-500/30":_e.configured?"bg-surface-elevated/30 hover:bg-surface-elevated/60 cursor-pointer":"bg-surface-elevated/30"}`,onClick:()=>{!An&&_e.configured&&!ia&&Cn(ie,Ze.id)},children:[n.jsxs("div",{className:"flex items-center gap-2",children:[An&&n.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-brand-500 shrink-0"}),n.jsx("span",{className:An?"text-brand-500 font-medium":"text-fg-secondary",children:Ze.name}),Ze.reasoning&&n.jsx("span",{className:"text-[9px] bg-amber-500/15 text-amber-600 px-1 py-0.5 rounded",children:i("modelProviders.reasoning")}),Ze.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:(Ze.contextWindow/1e3).toFixed(0)})}),n.jsx("span",{children:i("modelProviders.costPair",{input:Ze.cost.input,output:Ze.cost.output})}),_e.configured&&!An&&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")}),An&&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&&!An&&n.jsx("button",{onClick:bs=>{bs.stopPropagation(),Ki(ie,Ze.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"})})})]})]},Ze.id)})})]}),!_e.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:W===ie?Gs:"",onChange:Ze=>Na(Ze.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:Ze=>{Ze.key==="Enter"&&Gs.trim()&&Ca(ie,_e)}}),n.jsx("button",{onClick:()=>{Ca(ie,_e)},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")})]}),Qr&&W===ie&&n.jsx(Oa,{type:Qr.type,text:Qr.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:gn.name,onChange:ie=>yr({...gn,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:gn.apiKey,onChange:ie=>yr({...gn,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:gn.baseUrl,onChange:ie=>yr({...gn,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:gn.model,onChange:ie=>yr({...gn,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:gn.contextWindow,onChange:ie=>yr({...gn,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:gn.maxOutputTokens,onChange:ie=>yr({...gn,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:gn.costInput,onChange:ie=>yr({...gn,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:gn.costOutput,onChange:ie=>yr({...gn,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||!gn.name||!gn.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),Ir(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:Y[ie.provider]??!1,onChange:_e=>me({...Y,[ie.provider]:_e.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(_e=>n.jsx("div",{children:n.jsx("code",{children:_e})},_e))})]},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:be||Object.values(Y).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:be?i("common:applying"):i("envConfig.applyToConfig",{count:Object.values(Y).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:()=>{zr()},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")]})]}),He?.found&&He.models&&He.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:He.models.length,url:He.baseUrl})}),n.jsx("div",{className:"space-y-1",children:He.models.map(ie=>n.jsx("label",{className:`flex items-center justify-between rounded-lg px-4 py-3 cursor-pointer transition-colors ${Ee===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:Ee===ie.name,onChange:()=>fe(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:Le||!Ee,className:"px-4 py-2 bg-brand-600 hover:bg-brand-500 disabled:opacity-40 text-white text-sm rounded-lg transition-colors",children:Le?i("common:applying"):i("ollama.useModel",{model:Ee})})]}),He&&!He.found&&n.jsx("div",{className:"text-xs text-fg-tertiary",children:He.error||i("ollama.notRunning")}),nt&&n.jsx(Oa,{type:nt.type,text:nt.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:X,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(X?"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:()=>{ur()},disabled:X,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(X?"common:importing":"openClaw.importConfigs")})]}),P&&n.jsx(Oa,{type:P.type,text:P.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:ut,onChange:ie=>{it(Number(ie.target.value)),mn(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:Vt,onClick:async()=>{Nn(!0),mn(null);try{const ie=await de.settings.updateAgent({maxToolIterations:ut});it(ie.maxToolIterations),mn({type:"ok",text:i("agentExecution.saved")})}catch{mn({type:"err",text:i("agentExecution.failedToSave")})}Nn(!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(Vt?"common:saving":"common:save")})]})]}),Un&&n.jsx(Oa,{type:Un.type,text:Un.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:()=>{$n(!Tn),xr(null)},className:`relative w-10 h-5 rounded-full transition-colors ${Tn?"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 ${Tn?"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:dn,onChange:ie=>{bn(Number(ie.target.value)),xr(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:nr,onClick:async()=>{ir(!0),xr(null);try{const ie=await de.settings.updateAgent({cognitive:{enabled:Tn,maxDepth:dn}});$n(ie.cognitive.enabled),bn(ie.cognitive.maxDepth??1),xr({type:"ok",text:i("cognitive.saved")})}catch{xr({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(nr?"common:saving":"common:save")})}),jr&&n.jsx(Oa,{type:jr.type,text:jr.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 ${pn?"bg-green-500/10 border border-green-500/20":Qn>0?"bg-blue-500/10 border border-blue-500/20":Bn?"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 ${pn?"bg-green-400":Qn>0?"bg-blue-400":Bn?"bg-amber-400":"bg-gray-400"}`}),n.jsxs("div",{className:"flex-1 min-w-0",children:[n.jsx("div",{className:`text-sm font-semibold ${pn?"text-green-400":Qn>0?"text-blue-400":Bn?"text-amber-400":"text-fg-secondary"}`,children:pn?i("browserAutomation.modeExtension"):Qn>0?i("browserAutomation.modeDebuggingPort",{port:Qn}):i(Bn?"browserAutomation.modeAutoClick":"browserAutomation.modeManual")}),n.jsx("div",{className:"text-xs text-fg-tertiary mt-0.5",children:pn?i("browserAutomation.modeExtensionDesc"):Qn>0?i("browserAutomation.modeDebuggingPortDesc"):i(Bn?"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=!rr;Ln(ie),Ce(!0),$t(null);try{const _e=await de.settings.updateBrowser({bringToFront:ie});Ln(_e.bringToFront),$t({type:"ok",text:i(ie?"browserAutomation.tabsForeground":"browserAutomation.tabsBackground")})}catch{$t({type:"err",text:i("agentExecution.failedToSave")}),Ln(!ie)}Ce(!1)},disabled:rn,className:`relative inline-flex h-5 w-9 items-center rounded-full transition-colors ${rr?"bg-green-500":"bg-gray-600"} ${rn?"opacity-50":""}`,children:n.jsx("span",{className:`inline-block h-3.5 w-3.5 rounded-full bg-white transition-transform ${rr?"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=!Zn;br(ie),Ce(!0),$t(null);try{const _e=await de.settings.updateBrowser({autoCloseTabs:ie});br(_e.autoCloseTabs),$t({type:"ok",text:i("agentExecution.saved")})}catch{$t({type:"err",text:i("agentExecution.failedToSave")}),br(!ie)}Ce(!1)},disabled:rn,className:`relative inline-flex h-5 w-9 items-center rounded-full transition-colors ${Zn?"bg-green-500":"bg-gray-600"} ${rn?"opacity-50":""}`,children:n.jsx("span",{className:`inline-block h-3.5 w-3.5 rounded-full bg-white transition-transform ${Zn?"translate-x-4":"translate-x-1"}`})})]})]}),n.jsxs("div",{className:`rounded-xl p-5 mb-4 transition-colors ${pn?"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 ${pn?"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 ${pn?"bg-green-400":"bg-gray-400"}`}),i(pn?"browserAutomation.extensionConnected":"browserAutomation.extensionDisconnected")]})]}),n.jsx("div",{className:"text-xs text-fg-tertiary",children:i("browserAutomation.extensionStatusDesc")}),pn?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:rn,onClick:async()=>{Ce(!0),$t(null);try{await de.settings.downloadExtensionZip()}catch{$t({type:"err",text:i("browserAutomation.extensionDownloadError")})}Ce(!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(rn?"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:rn,onClick:async()=>{Ce(!0),$t(null);try{await de.settings.openExtensionsPage()}catch{$t({type:"err",text:i("browserAutomation.extensionOpenError")})}Ce(!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")})]})]})]})]}),!pn&&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:rn,onClick:async()=>{Ce(!0),$t(null);try{const ie=await de.settings.testAutoClick(),_e={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"})}};$t(_e[ie.clickResult]??{type:"err",text:ie.clickResult})}catch{$t({type:"err",text:i("browserAutomation.autoClickTestError",{error:"request failed"})})}Ce(!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(rn?"browserAutomation.autoClickTesting":"browserAutomation.autoClickTest")}),n.jsx("button",{onClick:async()=>{const ie=!Bn;Xt(ie),Ce(!0),$t(null);try{const _e=await de.settings.updateBrowser({autoClickAllowDialog:ie});Xt(_e.autoClickAllowDialog),$t({type:"ok",text:i("agentExecution.saved")})}catch{$t({type:"err",text:i("agentExecution.failedToSave")}),Xt(!ie)}Ce(!1)},disabled:rn,className:`relative inline-flex h-5 w-9 items-center rounded-full transition-colors ${Bn?"bg-green-500":"bg-gray-600"} ${rn?"opacity-50":""}`,children:n.jsx("span",{className:`inline-block h-3.5 w-3.5 rounded-full bg-white transition-transform ${Bn?"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:Qn,onChange:ie=>{Vn(Number(ie.target.value)),$t(null)},className:"w-24 px-3 py-1.5 text-sm border border-border-default rounded-lg bg-surface-primary text-fg-primary text-right",placeholder:"0"}),n.jsx("button",{disabled:rn,onClick:async()=>{Ce(!0),$t(null);try{const ie=await de.settings.updateBrowser({remoteDebuggingPort:Qn});Vn(ie.remoteDebuggingPort),$t({type:"ok",text:ie.remoteDebuggingPort>0?i("browserAutomation.usingPort",{port:ie.remoteDebuggingPort}):i("browserAutomation.usingAutoConnect")})}catch{$t({type:"err",text:i("agentExecution.failedToSave")})}Ce(!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(rn?"common:saving":"common:save")})]})]})})]}),Ct&&n.jsx("div",{className:"mt-4",children:n.jsx(Oa,{type:Ct.type,text:Ct.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,_e)=>n.jsxs("div",{className:_e>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:[Wt?.[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:Wt[ie.id].preview})]}),Wt&&!Wt[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:Ne[ie.field],onChange:Ze=>Rt({...Ne,[ie.field]:Ze.target.value}),placeholder:Wt?.[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:Ne[ie.extraField],onChange:Ze=>Rt({...Ne,[ie.extraField]:Ze.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:[Jn&&n.jsx(Oa,{type:Jn.type,text:Jn.text}),!Jn&&n.jsx("div",{}),n.jsx("button",{disabled:Dt||!Ne.serperApiKey&&!Ne.tavilyApiKey&&!Ne.bingApiKey&&!Ne.googleSearchApiKey&&!Ne.googleSearchCx&&!Ne.serpApiKey&&!Ne.braveApiKey&&!Ne.exaApiKey&&!Ne.bochaApiKey,onClick:()=>{Et()},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(Dt?"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:[Ft&&!Xe&&n.jsx("div",{className:"text-sm text-fg-tertiary",children:i("dataStorage.scanning")}),Xe&&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(Xe.totalSize,i)}),n.jsx("div",{className:"text-xs text-fg-tertiary font-mono mt-0.5",children:Xe.dataDir})]}),n.jsxs("div",{className:"flex gap-2",children:[n.jsx("button",{onClick:()=>Bs(),disabled:Ft,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(Ft?"dataStorage.scanning":"common:refresh")}),n.jsx("button",{onClick:()=>{de.system.openPath(Xe.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:Xe.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))})]}),Xe.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:Xe.agents.length})}),n.jsx("div",{className:"space-y-1",children:Xe.agents.map(ie=>{const _e=Gt.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:()=>sn(Ze=>{const An=new Set(Ze);return An.has(ie.id)?An.delete(ie.id):An.add(ie.id),An}),children:[n.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[n.jsx("span",{className:"text-[10px] text-fg-tertiary",children:_e?"▼":"▶"}),n.jsx("button",{onClick:Ze=>{Ze.stopPropagation(),Nt.navigate(Te.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)})]}),_e&&n.jsxs("div",{className:"px-3 pb-2 pt-0.5 space-y-0.5",children:[ie.subItems.filter(Ze=>Ze.size>0).map(Ze=>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:Ze.name}),n.jsx("span",{className:"text-fg-secondary tabular-nums",children:Bc(Ze.size,i)})]},Ze.name)),n.jsx("div",{className:"pl-5 pt-1",children:n.jsx("button",{onClick:()=>{de.system.openPath(Xe.dataDir+"/agents/"+ie.id)},className:"text-[10px] text-fg-tertiary hover:text-fg-secondary underline",children:i("dataStorage.openFolder")})})]})]},ie.id)})})]}),vn&&(vn.orphanAgents.length>0||vn.orphanTeams.length>0)&&n.jsx(rG,{orphanInfo:vn,dataDir:Xe.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,D]=b.useState(null),M=b.useCallback(()=>{de.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??""),D(null)},F=async()=>{if(a)try{await de.users.update(a,{name:l,role:u,email:p||void 0}),i(null),D({type:"ok",text:t("settings:userManagement.updateSuccess")}),M()}catch(U){D({type:"err",text:`${t("settings:userManagement.error")}: ${String(U)}`})}},z=async()=>{if(!(!y||!v))try{await de.users.resetPassword(y,v),g(null),S(""),D({type:"ok",text:t("settings:userManagement.resetSuccess")})}catch(U){D({type:"err",text:`${t("settings:userManagement.error")}: ${String(U)}`})}},L=async U=>{if(U===e?.id){D({type:"err",text:t("settings:userManagement.cannotDeleteSelf")}),k(null);return}if(r.find(q=>q.id===U)?.role==="owner"){D({type:"err",text:t("settings:userManagement.cannotDeleteOwner")}),k(null);return}try{await de.users.remove(U),k(null),D({type:"ok",text:t("settings:userManagement.deleteSuccess")}),M()}catch(q){D({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),D({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 W=a===U.id,q=y===U.id,I=C===U.id,R=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:W?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}),R&&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:W?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:W?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:W?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(""),D(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 de.users.reinvite(U.id),X=`${window.location.origin}/#invite?token=${$}`;j(X),D({type:"ok",text:t("settings:userManagement.inviteLinkGenerated")})}catch($){D({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&&!R&&n.jsx("button",{onClick:()=>{k(U.id),D(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 de.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:()=>{de.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 de.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(Jj,{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=Yj(),y=b.useCallback(async()=>{try{const N=await de.settings.getRemote();r(N)}catch{r(null)}finally{a(!1)}},[]);b.useEffect(()=>{y()},[y]),b.useEffect(()=>fn.on("remote:status",N=>{const j=N.payload;j&&(r(j),l(!1))}),[]);const g=async()=>{l(!0),u(null);try{t?.enabled?(await de.settings.disableRemote(),await y(),l(!1)):(In.isAuthenticated()||await pi(),await de.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")}),In.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")})]}),In.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(Ok,{})]}),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(Ok,{})]})]}),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 Ok(){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),Cd(()=>import("./browser-CIXBeJ4H.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 Vf=new Map;function Bl(e,t){Vf.has(e)||Vf.set(e,t().catch(()=>{}))}function Kl(e){const t=Vf.get(e);return Vf.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"}],_k={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 zk({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 AS({authUser:e}={}){const{t}=kt(["builder","common"]),r=js(),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,D]=b.useState(null),[M,_]=b.useState(null),[F,z]=b.useState(null),L=b.useCallback(()=>{m(!0),Promise.all([(Kl(ga.builderArtifacts)??de.builder.artifacts.list()).then(K=>K?.artifacts??[]).catch(()=>[]),(Kl(ga.builderAgents)??de.agents.list()).then(K=>K?.agents??[]).catch(()=>[]),(Kl(ga.builderHubMyItems)??In.myItems()).then(K=>K?.items??[]).catch(()=>[]),(Kl(ga.builderInstalled)??de.builder.artifacts.installed()).then(K=>K?.installed??{}).catch(()=>({}))]).then(([K,P,B,Z])=>{if(d(K),i(P),B.length>0){const J=new Map;for(const Q of B){const ee=Q.itemType==="agent"?"agent":Q.itemType==="team"?"team":"skill";for(const se of K)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,Y]of J)ee.set(se,Y);return ee})}const H=new Map;for(const J of K){const Q=`${J.type}/${J.name}`,ee=Z[Q];ee&&H.set(Q,{agentId:ee.agentId,agentIds:ee.agentIds,teamId:ee.teamId})}S(H)}).finally(()=>m(!1))},[]);b.useEffect(()=>{L();const K=P=>{P.detail?.page===Te.BUILDER&&L()};return window.addEventListener("markus:navigate",K),()=>window.removeEventListener("markus:navigate",K)},[L]);const U=K=>{const P=a.find(B=>B.role==="Secretary"||B.name==="Secretary");P?Nt.navigate(Te.TEAM,{agentId:P.id,prefillMessage:K}):Nt.navigate(Te.TEAM,{prefillMessage:K})},W=async K=>{const P=`${K.type}/${K.name}`;if(!v.has(P)){g({key:P,action:"install"});try{const B=await de.builder.artifacts.install(K.type,K.name),Z={};B.agent&&typeof B.agent=="object"&&(Z.agentId=B.agent.id),B.team&&typeof B.team=="object"&&(Z.teamId=B.team.id),Array.isArray(B.agents)&&(Z.agentIds=B.agents.map(H=>H.id)),S(H=>new Map(H).set(P,Z)),window.dispatchEvent(new CustomEvent("markus:data-changed"))}catch(B){console.error("Install failed:",B),alert(t("installFailed",{error:String(B)}))}finally{g(null)}}},q=async K=>{const P=`${K.type}/${K.name}`;if(v.has(P)){g({key:P,action:"uninstall"});try{await de.builder.artifacts.uninstall(K.type,K.name),S(B=>{const Z=new Map(B);return Z.delete(P),Z}),window.dispatchEvent(new CustomEvent("markus:data-changed"))}catch(B){console.error("Uninstall failed:",B),alert(t("uninstallFailed",{error:String(B)}))}finally{g(null)}}},I=async(K,P)=>{const B=`${K.type}/${K.name}`;g({key:B,action:"share"});try{const Z=await de.builder.artifacts.get(K.type,K.name),H=K.meta.displayName||K.meta.name||K.name,J=K.meta.description||"",Q=K.meta.category||"general",ee=Array.isArray(K.meta.tags)?K.meta.tags:[],se=K.name;let Y=K.meta.icon||void 0;const me=K.meta.version||"1.0.0";if(Y&&!Y.startsWith("http")&&/\.(png|jpe?g|gif|webp|svg)$/i.test(Y)){const pe=Y.split("/").pop()??Y;try{const Oe=await fetch(`/api/builder/artifacts/${K.type}s/${encodeURIComponent(K.name)}/images/${encodeURIComponent(pe)}`);if(Oe.ok){const Ee=await Oe.blob(),fe=new File([Ee],pe,{type:Ee.type}),Le=await In.uploadImage(fe);Le?.url&&(Y=Le.url)}}catch{}}let be;const De=[],He=Array.isArray(K.meta.screenshots)?K.meta.screenshots:[];for(let pe=0;pe<He.length;pe++){const Oe=He[pe],Ee=Oe.split("/").pop()??Oe;try{const fe=await fetch(`/api/builder/artifacts/${K.type}s/${encodeURIComponent(K.name)}/images/${encodeURIComponent(Ee)}`);if(fe.ok){const Le=await fe.blob(),Qe=new File([Le],Ee,{type:Le.type}),nt=await In.uploadImage(Qe);nt?.url&&(De.push({url:nt.url,alt:Ee,order:pe}),(pe===0||K.meta.thumbnail===Oe)&&(be=nt.url))}}catch{}}const ke=await In.publishViaProxy({itemType:K.type==="team"?"team":K.type==="skill"?"skill":"agent",name:H,slug:se,description:J,category:Q,tags:ee,icon:Y,version:me,config:K.meta,files:Z.files&&Object.keys(Z.files).length>0?Z.files:void 0,thumbnailUrl:be,images:De.length>0?De:void 0,priceCents:P?.priceCents,donationsEnabled:P?.donationsEnabled});ke.id&&j(pe=>{const Oe=new Map(pe);return Oe.set(B,{id:ke.id,name:H,slug:ke.slug??se,version:me}),Oe})}catch(Z){console.error("Share failed:",Z),alert(t("shareFailed",{error:String(Z)}))}finally{g(null)}},R=async()=>{if(!T)return;const{key:K}=T,P=N.get(K);if(D(null),!P)return;const B=P.id;g({key:K,action:"hubDelete"});try{await In.deleteItem(B),j(Z=>{const H=new Map(Z);return H.delete(K),H})}catch(Z){console.error("Hub delete failed:",Z),alert(t("hubDeleteFailed",{error:String(Z)}))}finally{g(null)}},E=async()=>{if(!C)return;const K=C,P=`${K.type}/${K.name}`;k(null),g({key:P,action:"delete"});try{await de.builder.artifacts.delete(K.type,K.name),d(B=>B.filter(Z=>!(Z.type===K.type&&Z.name===K.name))),S(B=>{const Z=new Map(B);return Z.delete(P),Z}),window.dispatchEvent(new CustomEvent("markus:data-changed"))}catch(B){console.error("Delete failed:",B)}finally{g(null)}},$=p==="all"?l:l.filter(K=>K.type===p),X=K=>{history.pushState(null,"",`#builder/${K.type}/${encodeURIComponent(K.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(K=>{const P=t(`prompts.${K.id}Prompt`),B=t(`prompts.${K.id}Examples`,{returnObjects:!0}),Z=Array.isArray(B)?B:[];return n.jsx("button",{onClick:()=>U(P),className:`group text-left w-full rounded-xl border ${K.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 ${K.bgColor} flex items-center justify-center shrink-0`,children:K.icon}),n.jsxs("div",{className:"flex-1 min-w-0",children:[n.jsx("h3",{className:`text-sm font-semibold bg-gradient-to-r ${K.color} bg-clip-text text-transparent`,children:t(`prompts.${K.id}`)}),n.jsx("p",{className:"text-[11px] text-fg-tertiary mt-1 leading-relaxed",children:t(`prompts.${K.id}Desc`)}),Z.length>0&&n.jsx("div",{className:"mt-2 flex flex-wrap gap-1.5",children:Z.slice(0,2).map((H,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(P+H)},children:["“",H,"”"]},J))})]})]})},K.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(K=>n.jsx("button",{onClick:()=>h(K),className:`text-xs px-2.5 py-1 rounded-lg transition-colors ${p===K?"bg-brand-600 text-white":"text-fg-tertiary hover:text-fg-secondary hover:bg-surface-elevated"}`,children:t(K==="all"?"myCreations.filterAll":K==="agent"?"myCreations.filterAgents":K==="team"?"myCreations.filterTeams":"myCreations.filterSkills")},K))})]})}),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(K=>{const P=_k[K.type]??_k.agent,B=K.meta.displayName||K.meta.name||K.name,Z=K.meta.description||"",H=`${K.type}/${K.name}`,J=y?.key===H?y.action:null,Q=N.get(H),ee=K.meta.version||"1.0.0",se=!!Q,Y=se&&Q.version!==ee,me=()=>{const De=In.getUser();return!Q||!De?null:`${In.getUrl()}/${encodeURIComponent(De.username)}/${encodeURIComponent(Q.slug)}`},be=n.jsxs("div",{className:`flex items-center gap-1.5 ${r?"flex-wrap":"shrink-0"}`,onClick:De=>De.stopPropagation(),children:[v.has(H)?n.jsx("button",{onClick:()=>q(K),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:()=>W(K),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&&Y?n.jsx("button",{onClick:()=>z(K),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:()=>D({key:H,name:B}),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 In.ensureAuth(),Array.isArray(K.meta.screenshots)&&K.meta.screenshots.length>0?I(K):_(K)},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(K),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:()=>X(K),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 De=K.meta.icon,ke=De&&(De.startsWith("http")||De.startsWith("/")||/\.(png|jpe?g|gif|webp|svg)$/i.test(De))?De.startsWith("http")||De.startsWith("/")?De:`/api/builder/artifacts/${K.type}s/${encodeURIComponent(K.name)}/images/${encodeURIComponent(De.split("/").pop()??"")}`:null;return n.jsx("div",{className:`w-9 h-9 rounded-lg ${P.bg} flex items-center justify-center text-lg shrink-0 overflow-hidden`,children:ke?n.jsx("img",{src:ke,alt:"",className:"w-full h-full object-cover"}):De?n.jsx("span",{children:De}):P.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:B}),n.jsx("span",{className:`text-[10px] font-medium uppercase tracking-wider ${P.color}`,children:K.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:De=>{De.stopPropagation(),de.system.openPath(K.path).catch(()=>{})},className:"hover:text-fg-secondary transition-colors truncate min-w-0",title:K.path,children:oG(K.path)}),n.jsx("span",{className:"shrink-0",children:new Date(K.updatedAt).toLocaleDateString()})]})]}),!r&&be]}),r&&n.jsx("div",{className:"mt-3 pt-3 border-t border-border-default/50",children:be})]},H)})}),C&&n.jsx(zk,{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(zk,{title:t("confirmDelete"),message:t("removeFromHub",{name:T.name}),cancelLabel:t("common:cancel"),confirmLabel:t("common:delete"),onConfirm:()=>{R()},onCancel:()=>D(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:K=>K.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 K=M;_(null),I(K)},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 K=M;_(null),X(K)},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:K=>K.stopPropagation(),children:n.jsx(dG,{isUpdate:N.has(`${F.type}/${F.name}`),onCancel:()=>z(null),onConfirm:(K,P)=>{const B=F;z(null),I(B,{donationsEnabled:K==="donation",priceCents:K==="paid"?P: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,D=`${s??""} ${!e?"text-fg-muted italic":""}`;return r==="h1"?n.jsx("h1",{className:D,children:j}):r==="p"?n.jsx("p",{className:D,children:j}):n.jsx("span",{className:D,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 Ob({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??L3,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)&&T7(g))return!1;const S=P3(g.code,d);if(i.current.add(g[S]),I3(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=P3(g.code,d);I3(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 I3(e,t,r){return e.filter(s=>r||s.length===t.size).some(s=>s.every(a=>t.has(a)))}function P3(e,t){return t.includes(e)?"code":"key"}const FJ=()=>{const e=Hr();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=ay(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 w0(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=nh(t,r);return{x:l.x+a,y:l.y+i}}}),[])};function Y7(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 X7(e,t){return Y7(e,t)}function Q7(e,t){return Y7(e,t)}function ql(e,t){return{id:e,type:"select",selected:t}}function Zc(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 O3({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 _3(e){return{id:e.id,type:"remove"}}const z3=e=>pZ(e),UJ=e=>y7(e);function Z7(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(()=>KJ(()=>r(a=>a+BigInt(1))));return VJ(()=>{const a=s.get();a.length&&(e(a),s.reset())},[t]),s}function KJ(e){let t=[];return{get:()=>t,reset:()=>{t=[]},push:r=>{t.push(r),e()}}}const J7=b.createContext(null);function WJ({children:e}){const t=Hr(),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=O3({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(O3({items:g,lookup:y}))},[]),i=$3(a),l=b.useMemo(()=>({nodeQueue:s,edgeQueue:i}),[]);return n.jsx(J7.Provider,{value:l,children:e})}function GJ(){const e=b.useContext(J7);if(!e)throw new Error("useBatchContext must be used within a BatchProvider");return e}const YJ=e=>!!e.panZoom;function my(){const e=FJ(),t=Hr(),r=GJ(),s=tr(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=z3(h)?h:y.get(h.id),S=v.parentId?S7(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 pd(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&&z3(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:D,edges:M}=await vZ({nodesToRemove:h,edgesToRemove:y,nodes:g,edges:v,onBeforeDelete:T}),_=M.length>0,F=D.length>0;if(_){const z=M.map(_3);C?.(M),N(z)}if(F){const z=D.map(_3);S?.(D),k(z)}return(F||_)&&j?.({nodes:D,edges:M}),{deletedNodes:D,deletedEdges:M}},getIntersectingNodes:(h,y=!0,g)=>{const v=m3(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=pd(C?k:N),T=s0(j,S);return y&&T>0||T>=j.width*j.height||T>=S.width*S.height}):[]},isNodeIntersecting:(h,y,g=!0)=>{const S=m3(h)?h:u(h);if(!S)return!1;const C=s0(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 B3=e=>e.selected,XJ=typeof window<"u"?window:void 0;function QJ({deleteKeyCode:e,multiSelectionKeyCode:t}){const r=Hr(),{deleteElements:s}=my(),a=i0(e,{actInsideInputWithModifier:!1}),i=i0(t,{target:XJ});b.useEffect(()=>{if(a){const{edges:l,nodes:d}=r.getState();s({nodes:d.filter(B3),edges:l.filter(B3)}),r.setState({nodesSelectionActive:!1})}},[a]),b.useEffect(()=>{r.setState({multiSelectionActive:i})},[i])}function ZJ(e){const t=Hr();b.useEffect(()=>{const r=()=>{if(!e.current||!(e.current.checkVisibility?.()??!0))return!1;const s=iy(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 _h={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 D=Hr(),M=b.useRef(null),{userSelectionActive:_,lib:F,connectionInProgress:z}=tr(JJ,Wr),L=i0(y),U=b.useRef();ZJ(M);const W=b.useCallback(q=>{k?.({x:q[0],y:q[1],zoom:q[2]}),N||D.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=>D.setState($=>$.paneDragging===E?$:{paneDragging:E}),onPanZoomStart:(E,$)=>{const{onViewportChangeStart:X,onMoveStart:K}=D.getState();K?.(E,$),X?.($)},onPanZoom:(E,$)=>{const{onViewportChange:X,onMove:K}=D.getState();K?.(E,$),X?.($)},onPanZoomEnd:(E,$)=>{const{onViewportChangeEnd:X,onMoveEnd:K}=D.getState();K?.(E,$),X?.($)}});const{x:q,y:I,zoom:R}=U.current.getViewport();return D.setState({panZoom:U.current,transform:[q,I,R],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:W,connectionInProgress:z,selectionOnDrag:T,paneClickDistance:j})},[e,t,r,s,a,i,l,d,L,g,C,_,S,F,W,z,T,j]),n.jsx("div",{className:"react-flow__renderer",ref:M,style:_h,children:v})}const tee=e=>({userSelectionActive:e.userSelectionActive,userSelectionRect:e.userSelectionRect});function nee(){const{userSelectionActive:e,userSelectionRect:t}=tr(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=r0.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=Hr(),{userSelectionActive:C,elementsSelectable:k,dragging:N,connectionInProgress:j}=tr(ree,Wr),T=k&&(e||C),D=b.useRef(null),M=b.useRef(),_=b.useRef(new Set),F=b.useRef(new Set),z=b.useRef(!1),L=X=>{if(z.current||j){z.current=!1;return}u?.(X),S.getState().resetSelectedElements(),S.setState({nodesSelectionActive:!1})},U=X=>{if(Array.isArray(s)&&s?.includes(2)){X.preventDefault();return}m?.(X)},W=p?X=>p(X):void 0,q=X=>{z.current&&(X.stopPropagation(),z.current=!1)},I=X=>{const{domNode:K}=S.getState();if(M.current=K?.getBoundingClientRect(),!M.current)return;const P=X.target===D.current;if(!P&&!!X.target.closest(".nokey")||!e||!(i&&P||t)||X.button!==0||!X.isPrimary)return;X.target?.setPointerCapture?.(X.pointerId),z.current=!1;const{x:H,y:J}=yi(X.nativeEvent,M.current);S.setState({userSelectionRect:{width:0,height:0,startX:H,startY:J,x:H,y:J}}),P||(X.stopPropagation(),X.preventDefault())},R=X=>{const{userSelectionRect:K,transform:P,nodeLookup:B,edgeLookup:Z,connectionLookup:H,triggerNodeChanges:J,triggerEdgeChanges:Q,defaultEdgeOptions:ee,resetSelectedElements:se}=S.getState();if(!M.current||!K)return;const{x:Y,y:me}=yi(X.nativeEvent,M.current),{startX:be,startY:De}=K;if(!z.current){const Ee=t?0:a;if(Math.hypot(Y-be,me-De)<=Ee)return;se(),l?.(X)}z.current=!0;const He={startX:be,startY:De,x:Y<be?Y:be,y:me<De?me:De,width:Math.abs(Y-be),height:Math.abs(me-De)},ke=_.current,pe=F.current;_.current=new Set(sy(B,He,P,r===r0.Partial,!0).map(Ee=>Ee.id)),F.current=new Set;const Oe=ee?.selectable??!0;for(const Ee of _.current){const fe=H.get(Ee);if(fe)for(const{edgeId:Le}of fe.values()){const Qe=Z.get(Le);Qe&&(Qe.selectable??Oe)&&F.current.add(Le)}}if(!f3(ke,_.current)){const Ee=Zc(B,_.current,!0);J(Ee)}if(!f3(pe,F.current)){const Ee=Zc(Z,F.current);Q(Ee)}S.setState({userSelectionRect:He,userSelectionActive:!0,nodesSelectionActive:!1})},E=X=>{X.button===0&&(X.target?.releasePointerCapture?.(X.pointerId),!C&&X.target===D.current&&S.getState().userSelectionRect&&L?.(X),S.setState({userSelectionActive:!1,userSelectionRect:null}),z.current&&(d?.(X),S.setState({nodesSelectionActive:_.current.size>0})))},$=s===!0||Array.isArray(s)&&s.includes(0);return n.jsxs("div",{className:gs(["react-flow__pane",{draggable:$,dragging:N,selection:e}]),onClick:T?void 0:Fx(L,D),onContextMenu:Fx(U,D),onWheel:Fx(W,D),onPointerEnter:T?void 0:h,onPointerMove:T?R:y,onPointerUp:T?E:void 0,onPointerDownCapture:T?I:void 0,onClickCapture:T?q:void 0,onPointerLeave:g,ref:D,style:_h,children:[v,n.jsx(nee,{})]})}function e1({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 e8({nodeRef:e,disabled:t=!1,noDragClassName:r,handleSelector:s,nodeId:a,isSelectable:i,nodeClickDistance:l}){const d=Hr(),[u,m]=b.useState(!1),p=b.useRef();return b.useEffect(()=>{p.current=WZ({getStoreItems:()=>d.getState(),onNodeMouseDown:h=>{e1({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 t8(){const e=Hr();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=v0(N,i));const{position:j,positionAbsolute:T}=v7({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 fy=b.createContext(null),iee=fy.Provider;fy.Consumer;const n8=()=>b.useContext(fy),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===md.Strict?d?.type!==r:e!==d?.nodeId||t!==d?.id,connectionInProcess:!!d,clickConnectionInProcess:!!a,valid:p&&m}};function cee({type:e="source",position:t=Ut.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=Hr(),k=n8(),{connectOnClick:N,noPanClassName:j,rfId:T}=tr(oee,Wr),{connectingFrom:D,connectingTo:M,clickConnecting:_,isPossibleEndHandle:F,connectionInProcess:z,clickConnectionInProcess:L,valid:U}=tr(lee(k,v,e),Wr);k||C.getState().onError?.("010",$i.error010());const W=R=>{const{defaultEdgeOptions:E,onConnect:$,hasDefaultEdges:X}=C.getState(),K={...E,...R};if(X){const{edges:P,setEdges:B}=C.getState();B(RZ(K,P))}$?.(K),d?.(K)},q=R=>{if(!k)return;const E=A7(R.nativeEvent);if(a&&(E&&R.button===0||!E)){const $=C.getState();Jb.onPointerDown(R.nativeEvent,{handleDomNode:R.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:(...X)=>C.getState().onConnectEnd?.(...X),updateConnection:$.updateConnection,onConnect:W,isValidConnection:r||((...X)=>C.getState().isValidConnection?.(...X)??!0),getTransform:()=>C.getState().transform,getFromHandle:()=>C.getState().connection.fromHandle,autoPanSpeed:$.autoPanSpeed,dragThreshold:$.connectionDragThreshold})}E?p?.(R):h?.(R)},I=R=>{const{onClickConnectStart:E,onClickConnectEnd:$,connectionClickStartHandle:X,connectionMode:K,isValidConnection:P,lib:B,rfId:Z,nodeLookup:H,connection:J}=C.getState();if(!k||!X&&!a)return;if(!X){E?.(R.nativeEvent,{nodeId:k,handleId:v,handleType:e}),C.setState({connectionClickStartHandle:{nodeId:k,type:e,id:v}});return}const Q=C7(R.target),ee=r||P,{connection:se,isValid:Y}=Jb.isValid(R.nativeEvent,{handle:{nodeId:k,id:v,type:e},connectionMode:K,fromNodeId:X.nodeId,fromHandleId:X.id||null,fromType:X.type,isValidConnection:ee,flowId:Z,doc:Q,lib:B,nodeLookup:H});Y&&se&&W(se);const me=structuredClone(J);delete me.inProgress,me.toPosition=me.toHandle?me.toHandle.position:null,$?.(R,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:gs(["react-flow__handle",`react-flow__handle-${t}`,"nodrag",j,m,{source:!S,target:S,connectable:s,connectablestart:a,connectableend:i,clickconnecting:_,connectingfrom:D,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(Z7(cee));function dee({data:e,isConnectable:t,sourcePosition:r=Ut.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=Ut.Top,sourcePosition:s=Ut.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=Ut.Top}){return n.jsxs(n.Fragment,{children:[n.jsx(pl,{type:"target",position:r,isConnectable:t}),e?.label]})}const rh={ArrowUp:{x:0,y:-1},ArrowDown:{x:0,y:1},ArrowLeft:{x:-1,y:0},ArrowRight:{x:1,y:0}},H3={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}=y0(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=Hr(),{width:a,height:i,transformString:l,userSelectionActive:d}=tr(pee,Wr),u=t8(),m=b.useRef(null);b.useEffect(()=>{r||m.current?.focus({preventScroll:!0})},[r]);const p=!d&&a!==null&&i!==null;if(e8({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(rh,g.key)&&(g.preventDefault(),u({direction:rh[g.key],factor:g.shiftKey?4:1}))};return n.jsx("div",{className:gs(["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 F3=typeof window<"u"?window:void 0,xee=e=>({nodesSelectionActive:e.nodesSelectionActive,userSelectionActive:e.userSelectionActive});function r8({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:D,panOnScrollMode:M,zoomOnDoubleClick:_,panOnDrag:F,defaultViewport:z,translateExtent:L,minZoom:U,maxZoom:W,preventScrolling:q,onSelectionContextMenu:I,noWheelClassName:R,noPanClassName:E,disableKeyboardA11y:$,onViewportChange:X,isControlledViewport:K}){const{nodesSelectionActive:P,userSelectionActive:B}=tr(xee,Wr),Z=i0(m,{target:F3}),H=i0(S,{target:F3}),J=H||F,Q=H||T,ee=p&&J!==!0,se=Z||B||ee;return QJ({deleteKeyCode:u,multiSelectionKeyCode:v}),n.jsx(eee,{onPaneContextMenu:i,elementsSelectable:k,zoomOnScroll:N,zoomOnPinch:j,panOnScroll:Q,panOnScrollSpeed:D,panOnScrollMode:M,zoomOnDoubleClick:_,panOnDrag:!Z&&J,defaultViewport:z,translateExtent:L,minZoom:U,maxZoom:W,zoomActivationKeyCode:C,preventScrolling:q,noWheelClassName:R,noPanClassName:E,onViewportChange:X,isControlledViewport:K,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,P&&n.jsx(gee,{onSelectionContextMenu:I,noPanClassName:E,disableKeyboardA11y:$})]})})}r8.displayName="FlowRenderer";const bee=b.memo(r8),yee=e=>t=>e?sy(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 tr(b.useCallback(yee(e),[e]),Wr)}const wee=e=>e.updateNodeInternals;function kee(){const e=tr(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=Hr(),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:D}=tr(Y=>{const me=Y.nodeLookup.get(e),be=Y.parentLookup.has(e);return{node:me,internals:me.internals,isParent:be}},Wr);let M=j.type||"default",_=C?.[M]||H3[M];_===void 0&&(N?.("003",$i.error003(M)),M="default",_=C?.default||H3.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"),W=Hr(),q=N7(j),I=jee({node:j,nodeType:M,hasDimensions:q,resizeObserver:h}),R=e8({nodeRef:I,disabled:j.hidden||!F,noDragClassName:y,handleSelector:j.dragHandle,nodeId:e,isSelectable:z,nodeClickDistance:k}),E=t8();if(j.hidden)return null;const $=Co(j),X=hee(j),K=z||F||t||r||s||a,P=r?Y=>r(Y,{...T.userNode}):void 0,B=s?Y=>s(Y,{...T.userNode}):void 0,Z=a?Y=>a(Y,{...T.userNode}):void 0,H=i?Y=>i(Y,{...T.userNode}):void 0,J=l?Y=>l(Y,{...T.userNode}):void 0,Q=Y=>{const{selectNodesOnDrag:me,nodeDragThreshold:be}=W.getState();z&&(!me||!F||be>0)&&e1({id:e,store:W,nodeRef:I}),t&&t(Y,{...T.userNode})},ee=Y=>{if(!(T7(Y.nativeEvent)||v)){if(p7.includes(Y.key)&&z){const me=Y.key==="Escape";e1({id:e,store:W,unselect:me,nodeRef:I})}else if(F&&j.selected&&Object.prototype.hasOwnProperty.call(rh,Y.key)){Y.preventDefault();const{ariaLabelConfig:me}=W.getState();W.setState({ariaLiveMessage:me["node.a11yDescription.ariaLiveMessage"]({direction:Y.key.replace("Arrow","").toLowerCase(),x:~~T.positionAbsolute.x,y:~~T.positionAbsolute.y})}),E({direction:rh[Y.key],factor:Y.shiftKey?4:1})}}},se=()=>{if(v||!I.current?.matches(":focus-visible"))return;const{transform:Y,width:me,height:be,autoPanOnNodeFocus:De,setCenter:He}=W.getState();if(!De)return;sy(new Map([[e,j]]),{x:0,y:0,width:me,height:be},Y,!0).length>0||He(j.position.x+$.width/2,j.position.y+$.height/2,{zoom:Y[2]})};return n.jsx("div",{className:gs(["react-flow__node",`react-flow__node-${M}`,{[g]:F},j.className,{selected:j.selected,selectable:z,parent:D,draggable:F,dragging:R}]),ref:I,style:{zIndex:T.z,transform:`translate(${T.positionAbsolute.x}px,${T.positionAbsolute.y}px)`,pointerEvents:K?"all":"none",visibility:q?"visible":"hidden",...j.style,...X},"data-id":e,"data-testid":`rf__node-${e}`,onMouseEnter:P,onMouseMove:B,onMouseLeave:Z,onContextMenu:H,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:`${K7}-${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:R,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 s8(e){const{nodesDraggable:t,nodesConnectable:r,nodesFocusable:s,elementsSelectable:a,onError:i}=tr(Cee,Wr),l=vee(e.onlyRenderVisibleElements),d=kee();return n.jsx("div",{className:"react-flow__nodes",style:_h,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))})}s8.displayName="NodeRenderer";const Tee=b.memo(s8);function Aee(e){return tr(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"})},q3={[fd.Arrow]:Eee,[fd.ArrowClosed]:Mee};function Ree(e){const t=Hr();return b.useMemo(()=>Object.prototype.hasOwnProperty.call(q3,e)?q3[e]:(t.getState().onError?.("009",$i.error009(e)),null),[e])}const Dee=({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=Ree(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},a8=({defaultColor:e,rfId:t})=>{const r=tr(i=>i.edges),s=tr(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(Dee,{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};a8.displayName="MarkerDefinitions";var Lee=b.memo(a8);function i8({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=gs(["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}i8.displayName="EdgeText";const Iee=b.memo(i8);function zh({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:gs(["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 U3({pos:e,x1:t,y1:r,x2:s,y2:a}){return e===Ut.Left||e===Ut.Right?[.5*(t+s),r]:[t,.5*(r+a)]}function o8({sourceX:e,sourceY:t,sourcePosition:r=Ut.Bottom,targetX:s,targetY:a,targetPosition:i=Ut.Top}){const[l,d]=U3({pos:r,x1:e,y1:t,x2:s,y2:a}),[u,m]=U3({pos:i,x1:s,y1:a,x2:e,y2:t}),[p,h,y,g]=E7({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 l8(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]=o8({sourceX:r,sourceY:s,sourcePosition:l,targetX:a,targetY:i,targetPosition:d}),D=e.isInternal?void 0:t;return n.jsx(zh,{id:D,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=l8({isInternal:!1}),c8=l8({isInternal:!0});Pee.displayName="SimpleBezierEdge";c8.displayName="SimpleBezierEdgeInternal";function d8(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=Ut.Bottom,targetPosition:v=Ut.Top,markerEnd:S,markerStart:C,pathOptions:k,interactionWidth:N})=>{const[j,T,D]=Xb({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(zh,{id:M,path:j,labelX:T,labelY:D,label:l,labelStyle:d,labelShowBg:u,labelBgStyle:m,labelBgPadding:p,labelBgBorderRadius:h,style:y,markerEnd:S,markerStart:C,interactionWidth:N})})}const u8=d8({isInternal:!1}),m8=d8({isInternal:!0});u8.displayName="SmoothStepEdge";m8.displayName="SmoothStepEdgeInternal";function f8(e){return b.memo(({id:t,...r})=>{const s=e.isInternal?void 0:t;return n.jsx(u8,{...r,id:s,pathOptions:b.useMemo(()=>({borderRadius:0,offset:r.pathOptions?.offset}),[r.pathOptions?.offset])})})}const Oee=f8({isInternal:!1}),h8=f8({isInternal:!0});Oee.displayName="StepEdge";h8.displayName="StepEdgeInternal";function p8(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]=D7({sourceX:r,sourceY:s,targetX:a,targetY:i}),j=e.isInternal?void 0:t;return n.jsx(zh,{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=p8({isInternal:!1}),g8=p8({isInternal:!0});_ee.displayName="StraightEdge";g8.displayName="StraightEdgeInternal";function x8(e){return b.memo(({id:t,sourceX:r,sourceY:s,targetX:a,targetY:i,sourcePosition:l=Ut.Bottom,targetPosition:d=Ut.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,D]=M7({sourceX:r,sourceY:s,sourcePosition:l,targetX:a,targetY:i,targetPosition:d,curvature:k?.curvature}),M=e.isInternal?void 0:t;return n.jsx(zh,{id:M,path:j,labelX:T,labelY:D,label:u,labelStyle:m,labelShowBg:p,labelBgStyle:h,labelBgPadding:y,labelBgBorderRadius:g,style:v,markerEnd:S,markerStart:C,interactionWidth:N})})}const zee=x8({isInternal:!1}),b8=x8({isInternal:!0});zee.displayName="BezierEdge";b8.displayName="BezierEdgeInternal";const V3={default:b8,straight:g8,step:h8,smoothstep:m8,simplebezier:c8},K3={sourceX:null,sourceY:null,targetX:null,targetY:null,sourcePosition:null,targetPosition:null},$ee=(e,t,r)=>r===Ut.Left?e-t:r===Ut.Right?e+t:e,Bee=(e,t,r)=>r===Ut.Top?e-t:r===Ut.Bottom?e+t:e,W3="react-flow__edgeupdater";function G3({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:gs([W3,`${W3}-${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=Hr(),S=(T,D)=>{if(T.button!==0)return;const{autoPanOnConnect:M,domNode:_,connectionMode:F,connectionRadius:z,lib:L,onConnectStart:U,cancelConnection:W,nodeLookup:q,rfId:I,panBy:R,updateConnection:E}=v.getState(),$=D.type==="target",X=(B,Z)=>{y(!1),h?.(B,r,D.type,Z)},K=B=>m?.(r,B),P=(B,Z)=>{y(!0),p?.(T,r,D.type),U?.(B,Z)};Jb.onPointerDown(T.nativeEvent,{autoPanOnConnect:M,connectionMode:F,connectionRadius:z,domNode:_,handleId:D.id,nodeId:D.nodeId,nodeLookup:q,isTarget:$,edgeUpdaterType:D.type,lib:L,flowId:I,cancelConnection:W,panBy:R,isValidConnection:(...B)=>v.getState().isValidConnection?.(...B)??!0,onConnect:K,onConnectStart:P,onConnectEnd:(...B)=>v.getState().onConnectEnd?.(...B),onReconnectEnd:X,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(G3,{position:d,centerX:s,centerY:a,radius:t,onMouseDown:C,onMouseEnter:N,onMouseOut:j,type:"source"}),(e===!0||e==="target")&&n.jsx(G3,{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=tr(He=>He.edgeLookup.get(e));const T=tr(He=>He.defaultEdgeOptions);j=T?{...T,...j}:j;let D=j.type||"default",M=S?.[D]||V3[D];M===void 0&&(k?.("011",$i.error011(D)),D="default",M=S?.default||V3.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,W]=b.useState(!1),[q,I]=b.useState(!1),R=Hr(),{zIndex:E,sourceX:$,sourceY:X,targetX:K,targetY:P,sourcePosition:B,targetPosition:Z}=tr(b.useCallback(He=>{const ke=He.nodeLookup.get(j.source),pe=He.nodeLookup.get(j.target);if(!ke||!pe)return{zIndex:j.zIndex,...K3};const Oe=PZ({id:e,sourceNode:ke,targetNode:pe,sourceHandle:j.sourceHandle||null,targetHandle:j.targetHandle||null,connectionMode:He.connectionMode,onError:k});return{zIndex:TZ({selected:j.selected,zIndex:j.zIndex,sourceNode:ke,targetNode:pe,elevateOnSelect:He.elevateEdgesOnSelect,zIndexMode:He.zIndexMode}),...Oe||K3}},[j.source,j.target,j.sourceHandle,j.targetHandle,j.selected,j.zIndex]),Wr),H=b.useMemo(()=>j.markerStart?`url('#${Qb(j.markerStart,v)}')`:void 0,[j.markerStart,v]),J=b.useMemo(()=>j.markerEnd?`url('#${Qb(j.markerEnd,v)}')`:void 0,[j.markerEnd,v]);if(j.hidden||$===null||X===null||K===null||P===null)return null;const Q=He=>{const{addSelectedEdges:ke,unselectNodesAndEdges:pe,multiSelectionActive:Oe}=R.getState();z&&(R.setState({nodesSelectionActive:!1}),j.selected&&Oe?(pe({nodes:[],edges:[j]}),L.current?.blur()):ke([e])),a&&a(He,j)},ee=i?He=>{i(He,{...j})}:void 0,se=l?He=>{l(He,{...j})}:void 0,Y=d?He=>{d(He,{...j})}:void 0,me=u?He=>{u(He,{...j})}:void 0,be=m?He=>{m(He,{...j})}:void 0,De=He=>{if(!N&&p7.includes(He.key)&&z){const{unselectNodesAndEdges:ke,addSelectedEdges:pe}=R.getState();He.key==="Escape"?(L.current?.blur(),ke({edges:[j]})):pe([e])}};return n.jsx("svg",{style:{zIndex:E},children:n.jsxs("g",{className:gs(["react-flow__edge",`react-flow__edge-${D}`,j.className,C,{selected:j.selected,animated:j.animated,inactive:!z&&!a,updating:U,selectable:z}]),onClick:Q,onDoubleClick:ee,onContextMenu:se,onMouseEnter:Y,onMouseMove:me,onMouseLeave:be,onKeyDown:_?De: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":_?`${W7}-${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:X,targetX:K,targetY:P,sourcePosition:B,targetPosition:Z,data:j.data,style:j.style,sourceHandleId:j.sourceHandle,targetHandleId:j.targetHandle,markerStart:H,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:X,targetX:K,targetY:P,sourcePosition:B,targetPosition:Z,setUpdateHover:W,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 y8({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}=tr(Uee,Wr),T=Aee(t);return n.jsxs("div",{className:"react-flow__edges",children:[n.jsx(Lee,{defaultColor:e,rfId:r}),T.map(D=>n.jsx(qee,{id:D,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},D))]})}y8.displayName="EdgeRenderer";const Vee=b.memo(y8),Kee=e=>`translate(${e.transform[0]}px,${e.transform[1]}px) scale(${e.transform[2]})`;function Wee({children:e}){const t=tr(Kee);return n.jsx("div",{className:"react-flow__viewport xyflow__viewport react-flow__container",style:{transform:t},children:e})}function Gee(e){const t=my(),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=tr(Yee),r=Hr();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:w0(e.connection.to,e.transform)}:{...e.connection}}function Zee(e){return Qee}function Jee(e){const t=Zee();return tr(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}=tr(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:gs(["react-flow__connection",b7(d)]),children:n.jsx(v8,{style:t,type:r,CustomComponent:s,isValid:d})})})}const v8=({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:b7(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]=M7(S);break;case al.SimpleBezier:[v]=o8(S);break;case al.Step:[v]=Xb({...S,borderRadius:0});break;case al.SmoothStep:[v]=Xb(S);break;default:[v]=D7(S)}return n.jsx("path",{d:v,fill:"none",className:"react-flow__connection-path",style:e})};v8.displayName="ConnectionLine";const nte={};function Y3(e=nte){b.useRef(e),Hr(),b.useEffect(()=>{},[e])}function rte(){Hr(),b.useRef(!1),b.useEffect(()=>{},[])}function w8({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:D,panActivationKeyCode:M,zoomActivationKeyCode:_,deleteKeyCode:F,onlyRenderVisibleElements:z,elementsSelectable:L,defaultViewport:U,translateExtent:W,minZoom:q,maxZoom:I,preventScrolling:R,defaultMarkerColor:E,zoomOnScroll:$,zoomOnPinch:X,panOnScroll:K,panOnScrollSpeed:P,panOnScrollMode:B,zoomOnDoubleClick:Z,panOnDrag:H,onPaneClick:J,onPaneMouseEnter:Q,onPaneMouseMove:ee,onPaneMouseLeave:se,onPaneScroll:Y,onPaneContextMenu:me,paneClickDistance:be,nodeClickDistance:De,onEdgeContextMenu:He,onEdgeMouseEnter:ke,onEdgeMouseMove:pe,onEdgeMouseLeave:Oe,reconnectRadius:Ee,onReconnect:fe,onReconnectStart:Le,onReconnectEnd:Qe,noDragClassName:nt,noWheelClassName:gt,noPanClassName:ze,disableKeyboardA11y:ce,nodeExtent:ue,rfId:Me,viewport:ne,onViewportChange:he}){return Y3(e),Y3(t),rte(),Gee(r),Xee(ne),n.jsx(bee,{onPaneClick:J,onPaneMouseEnter:Q,onPaneMouseMove:ee,onPaneMouseLeave:se,onPaneContextMenu:me,onPaneScroll:Y,paneClickDistance:be,deleteKeyCode:F,selectionKeyCode:N,selectionOnDrag:j,selectionMode:T,onSelectionStart:y,onSelectionEnd:g,multiSelectionKeyCode:D,panActivationKeyCode:M,zoomActivationKeyCode:_,elementsSelectable:L,zoomOnScroll:$,zoomOnPinch:X,zoomOnDoubleClick:Z,panOnScroll:K,panOnScrollSpeed:P,panOnScrollMode:B,panOnDrag:H,defaultViewport:U,translateExtent:W,minZoom:q,maxZoom:I,onSelectionContextMenu:h,preventScrolling:R,noDragClassName:nt,noWheelClassName:gt,noPanClassName:ze,disableKeyboardA11y:ce,onViewportChange:he,isControlledViewport:!!ne,children:n.jsxs(Wee,{children:[n.jsx(Vee,{edgeTypes:t,onEdgeClick:a,onEdgeDoubleClick:l,onReconnect:fe,onReconnectStart:Le,onReconnectEnd:Qe,onlyRenderVisibleElements:z,onEdgeContextMenu:He,onEdgeMouseEnter:ke,onEdgeMouseMove:pe,onEdgeMouseLeave:Oe,reconnectRadius:Ee,defaultMarkerColor:E,noPanClassName:ze,disableKeyboardA11y:ce,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:De,onlyRenderVisibleElements:z,noPanClassName:ze,noDragClassName:nt,disableKeyboardA11y:ce,nodeExtent:ue,rfId:Me}),n.jsx("div",{className:"react-flow__viewport-portal"})]})})}w8.displayName="GraphView";const ste=b.memo(w8),X3=({nodes:e,edges:t,defaultNodes:r,defaultEdges:s,width:a,height:i,fitView:l,fitViewOptions:d,minZoom:u=.5,maxZoom:m=2,nodeOrigin: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??n0;P7(S,C,k);const D=Zb(N,g,v,{nodeOrigin:j,nodeExtent:T,zIndexMode:y});let M=[0,0,1];if(l&&a&&i){const _=y0(g,{filter:U=>!!((U.width||U.initialWidth)&&(U.height||U.initialHeight))}),{x:F,y:z,zoom:L}=ay(_,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:D,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:n0,nodeExtent:T,nodesSelectionActive:!1,userSelectionActive:!1,userSelectionRect:null,connectionMode:md.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:{...x7},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:g7,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:D,minZoom:M,maxZoom:_}=v();k&&(await yZ({nodes:C,width:T,height:D,panZoom:k,minZoom:M,maxZoom:_},N),j?.resolve(!0),g({fitViewResolver:null}))}return{...X3({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:D,zIndexMode:M}=v(),_=Zb(C,k,N,{nodeOrigin:j,nodeExtent:h,elevateNodesOnSelect:T,checkEquality:!0,zIndexMode:M});D&&_?(S(),g({nodes:C,nodesInitialized:_,fitViewQueued:!1,fitViewOptions:void 0})):g({nodes:C,nodesInitialized:_})},setEdges:C=>{const{connectionLookup:k,edgeLookup:N}=v();P7(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:D,nodeExtent:M,debug:_,fitViewQueued:F,zIndexMode:z}=v(),{changes:L,updatedInternals:U}=qZ(C,N,j,T,D,M,z);U&&($Z(N,j,{nodeOrigin:D,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:D,connection:M,updateConnection:_,onNodesChangeMiddlewareMap:F}=v();for(const[z,L]of C){const U=T.get(z),W=!!(U?.expandParent&&U?.parentId&&L?.position),q={id:z,type:"position",position:W?{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,Ut.Left,!0);_({...M,from:I})}W&&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=uy(N,T,z,L);j.push(...U)}for(const z of F.values())j=z(j);D(j)},triggerNodeChanges:C=>{const{onNodesChange:k,setNodes:N,nodes:j,hasDefaultNodes:T,debug:D}=v();if(C?.length){if(T){const M=X7(C,j);N(M)}D&&console.log("React Flow: trigger node changes",C),k?.(C)}},triggerEdgeChanges:C=>{const{onEdgesChange:k,setEdges:N,edges:j,hasDefaultEdges:T,debug:D}=v();if(C?.length){if(T){const M=Q7(C,j);N(M)}D&&console.log("React Flow: trigger edge changes",C),k?.(C)}},addSelectedNodes:C=>{const{multiSelectionActive:k,edgeLookup:N,nodeLookup:j,triggerNodeChanges:T,triggerEdgeChanges:D}=v();if(k){const M=C.map(_=>ql(_,!0));T(M);return}T(Zc(j,new Set([...C]),!0)),D(Zc(N))},addSelectedEdges:C=>{const{multiSelectionActive:k,edgeLookup:N,nodeLookup:j,triggerNodeChanges:T,triggerEdgeChanges:D}=v();if(k){const M=C.map(_=>ql(_,!0));D(M);return}D(Zc(N,new Set([...C]))),T(Zc(j,new Set,!0))},unselectNodesAndEdges:({nodes:C,edges:k}={})=>{const{edges:N,nodes:j,nodeLookup:T,triggerNodeChanges:D,triggerEdgeChanges:M}=v(),_=C||j,F=k||N,z=[];for(const U of _){if(!U.selected)continue;const W=T.get(U.id);W&&(W.selected=!1),z.push(ql(U.id,!1))}const L=[];for(const U of F)U.selected&&L.push(ql(U.id,!1));D(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 D=k.reduce((_,F)=>F.selected?[..._,ql(F.id,!1)]:_,[]),M=C.reduce((_,F)=>F.selected?[..._,ql(F.id,!1)]:_,[]);N(D),j(M)},setNodeExtent:C=>{const{nodes:k,nodeLookup:N,parentLookup:j,nodeOrigin:T,elevateNodesOnSelect:D,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]||(Zb(k,N,j,{nodeOrigin:T,nodeExtent:C,elevateNodesOnSelect:D,checkEquality:!1,zIndexMode:_}),g({nodeExtent:C}))},panBy:C=>{const{transform:k,width:N,height:j,panZoom:T,translateExtent:D}=v();return UZ({delta:C,panZoom:T,transform:k,translateExtent:D,width:N,height:j})},setCenter:async(C,k,N)=>{const{width:j,height:T,maxZoom:D,panZoom:M}=v();if(!M)return Promise.resolve(!1);const _=typeof N?.zoom<"u"?N.zoom:D;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:{...x7}})},updateConnection:C=>{g({connection:C})},reset:()=>g({...X3()})}},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(WJ,{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(Ph)?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:D,onNodeDoubleClick:M,onNodeDragStart:_,onNodeDrag:F,onNodeDragStop:z,onNodesDelete:L,onEdgesDelete:U,onDelete:W,onSelectionChange:q,onSelectionDragStart:I,onSelectionDrag:R,onSelectionDragStop:E,onSelectionContextMenu:$,onSelectionStart:X,onSelectionEnd:K,onBeforeDelete:P,connectionMode:B,connectionLineType:Z=al.Bezier,connectionLineStyle:H,connectionLineComponent:J,connectionLineContainerStyle:Q,deleteKeyCode:ee="Backspace",selectionKeyCode:se="Shift",selectionOnDrag:Y=!1,selectionMode:me=r0.Full,panActivationKeyCode:be="Space",multiSelectionKeyCode:De=a0()?"Meta":"Control",zoomActivationKeyCode:He=a0()?"Meta":"Control",snapToGrid:ke,snapGrid:pe,onlyRenderVisibleElements:Oe=!1,selectNodesOnDrag:Ee,nodesDraggable:fe,autoPanOnNodeFocus:Le,nodesConnectable:Qe,nodesFocusable:nt,nodeOrigin:gt=G7,edgesFocusable:ze,edgesReconnectable:ce,elementsSelectable:ue=!0,defaultViewport:Me=_J,minZoom:ne=.5,maxZoom:he=2,translateExtent:Be=n0,preventScrolling:Se=!0,nodeExtent:Ke,defaultMarkerColor:at="#b1b1b7",zoomOnScroll:ct=!0,zoomOnPinch:Je=!0,panOnScroll:rt=!1,panOnScrollSpeed:ht=.5,panOnScrollMode:xt=Xl.Free,zoomOnDoubleClick:Ve=!0,panOnDrag:ut=!0,onPaneClick:it,onPaneMouseEnter:Vt,onPaneMouseMove:Nn,onPaneMouseLeave:Un,onPaneScroll:mn,onPaneContextMenu:Tn,paneClickDistance:$n=1,nodeClickDistance:dn=0,children:bn,onReconnect:nr,onReconnectStart:ir,onReconnectEnd:jr,onEdgeContextMenu:xr,onEdgeDoubleClick:rr,onEdgeMouseEnter:Ln,onEdgeMouseMove:Qn,onEdgeMouseLeave:Vn,reconnectRadius:Zn=10,onNodesChange:br,onEdgesChange:Bn,noDragClassName:Xt="nodrag",noWheelClassName:pn="nowheel",noPanClassName:on="nopan",fitView:Dr,fitViewOptions:Nr,connectOnClick:rn,attributionPosition:Ce,proOptions:Ct,defaultEdgeOptions:$t,elevateNodesOnSelect:Wt=!0,elevateEdgesOnSelect:qt=!1,disableKeyboardA11y:Ne=!1,autoPanOnConnect:Rt,autoPanOnNodeDrag:Dt,autoPanSpeed:Jt,connectionRadius:Jn,isValidConnection:xe,onError:Xe,style:bt,id:Ft,nodeDragThreshold:tn,connectionDragThreshold:Gt,viewport:sn,onViewportChange:vn,width:Pn,height:or,colorMode:Lr="light",debug:_t,onScroll:sr,ariaLabelConfig:_r,zIndexMode:dr="basic",...Va},Yr){const $s=Ft||"1",Bs=HJ(Lr),sa=b.useCallback(zr=>{zr.currentTarget.scrollTo({top:0,left:0,behavior:"instant"}),sr?.(zr)},[sr]);return n.jsx("div",{"data-testid":"rf__wrapper",...Va,onScroll:sa,style:{...bt,...lte},ref:Yr,className:gs(["react-flow",a,Bs]),id:Ft,role:"application",children:n.jsxs(ote,{nodes:e,edges:t,width:Pn,height:or,fitView:Dr,fitViewOptions:Nr,minZoom:ne,maxZoom:he,nodeOrigin:gt,nodeExtent:Ke,zIndexMode:dr,children:[n.jsx(ste,{onInit:m,onNodeClick:d,onEdgeClick:u,onNodeMouseEnter:N,onNodeMouseMove:j,onNodeMouseLeave:T,onNodeContextMenu:D,onNodeDoubleClick:M,nodeTypes:i,edgeTypes:l,connectionLineType:Z,connectionLineStyle:H,connectionLineComponent:J,connectionLineContainerStyle:Q,selectionKeyCode:se,selectionOnDrag:Y,selectionMode:me,deleteKeyCode:ee,multiSelectionKeyCode:De,panActivationKeyCode:be,zoomActivationKeyCode:He,onlyRenderVisibleElements:Oe,defaultViewport:Me,translateExtent:Be,minZoom:ne,maxZoom:he,preventScrolling:Se,zoomOnScroll:ct,zoomOnPinch:Je,zoomOnDoubleClick:Ve,panOnScroll:rt,panOnScrollSpeed:ht,panOnScrollMode:xt,panOnDrag:ut,onPaneClick:it,onPaneMouseEnter:Vt,onPaneMouseMove:Nn,onPaneMouseLeave:Un,onPaneScroll:mn,onPaneContextMenu:Tn,paneClickDistance:$n,nodeClickDistance:dn,onSelectionContextMenu:$,onSelectionStart:X,onSelectionEnd:K,onReconnect:nr,onReconnectStart:ir,onReconnectEnd:jr,onEdgeContextMenu:xr,onEdgeDoubleClick:rr,onEdgeMouseEnter:Ln,onEdgeMouseMove:Qn,onEdgeMouseLeave:Vn,reconnectRadius:Zn,defaultMarkerColor:at,noDragClassName:Xt,noWheelClassName:pn,noPanClassName:on,rfId:$s,disableKeyboardA11y:Ne,nodeExtent:Ke,viewport:sn,onViewportChange:vn}),n.jsx(BJ,{nodes:e,edges:t,defaultNodes:r,defaultEdges:s,onConnect:g,onConnectStart:v,onConnectEnd:S,onClickConnectStart:C,onClickConnectEnd:k,nodesDraggable:fe,autoPanOnNodeFocus:Le,nodesConnectable:Qe,nodesFocusable:nt,edgesFocusable:ze,edgesReconnectable:ce,elementsSelectable:ue,elevateNodesOnSelect:Wt,elevateEdgesOnSelect:qt,minZoom:ne,maxZoom:he,nodeExtent:Ke,onNodesChange:br,onEdgesChange:Bn,snapToGrid:ke,snapGrid:pe,connectionMode:B,translateExtent:Be,connectOnClick:rn,defaultEdgeOptions:$t,fitView:Dr,fitViewOptions:Nr,onNodesDelete:L,onEdgesDelete:U,onDelete:W,onNodeDragStart:_,onNodeDrag:F,onNodeDragStop:z,onSelectionDrag:R,onSelectionDragStart:I,onSelectionDragStop:E,onMove:p,onMoveStart:h,onMoveEnd:y,noPanClassName:on,nodeOrigin:gt,rfId:$s,autoPanOnConnect:Rt,autoPanOnNodeDrag:Dt,autoPanSpeed:Jt,onError:Xe,connectionRadius:Jn,isValidConnection:xe,selectNodesOnDrag:Ee,nodeDragThreshold:tn,connectionDragThreshold:Gt,onBeforeDelete:P,debug:_t,ariaLabelConfig:_r,zIndexMode:dr}),n.jsx(OJ,{onSelectionChange:q}),bn,n.jsx(RJ,{proOptions:Ct,position:Ce}),n.jsx(MJ,{rfId:$s,disableKeyboardA11y:Ne})]})})}var dte=Z7(cte);function ute(){const e=Hr();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=>X7(a,i)),[]);return[t,r,s]}function fte(e){const[t,r]=b.useState(e),s=b.useCallback(a=>r(i=>Q7(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:gs(["react-flow__background-pattern",r,s])})}function pte({radius:e,className:t}){return n.jsx("circle",{cx:e,cy:e,r:e,className:gs(["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 k8({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}=tr(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],D=C?[j,j]:N,M=[T[0]*y[2]||1+D[0]/2,T[1]*y[2]||1+D[1]/2],_=`${g}${e||""}`;return n.jsxs("svg",{className:gs(["react-flow__background",m]),style:{...u,..._h,"--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:D,lineWidth:a,variant:t,className:p})}),n.jsx("rect",{x:"0",y:"0",width:"100%",height:"100%",fill:`url(#${_})`})]})}k8.displayName="Background";const bte=b.memo(k8);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 af({children:e,className:t,...r}){return n.jsx("button",{type:"button",className:gs(["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 j8({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=Hr(),{isInteractive:S,minZoomReached:C,maxZoomReached:k,ariaLabelConfig:N}=tr(Nte,Wr),{zoomIn:j,zoomOut:T,fitView:D}=my(),M=()=>{j(),i?.()},_=()=>{T(),l?.()},F=()=>{D(a),d?.()},z=()=>{v.setState({nodesDraggable:!S,nodesConnectable:!S,elementsSelectable:!S}),u?.(!S)},L=y==="horizontal"?"horizontal":"vertical";return n.jsxs(Oh,{className:gs(["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(af,{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(af,{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(af,{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(af,{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]})}j8.displayName="Controls";const Ste=b.memo(j8);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:gs(["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=tr(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(Rte,{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}=tr(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||!N7(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 Rte=b.memo(Mte);var Dte=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?j7(y0(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 N8({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 D=Hr(),M=b.useRef(null),{boundingRect:_,viewBB:F,rfId:z,panZoom:L,translateExtent:U,flowWidth:W,flowHeight:q,ariaLabelConfig:I}=tr(Ote,Wr),R=e?.width??Lte,E=e?.height??Ite,$=_.width/R,X=_.height/E,K=Math.max($,X),P=K*R,B=K*E,Z=T*K,H=_.x-(P-_.width)/2-Z,J=_.y-(B-_.height)/2-Z,Q=P+Z*2,ee=B+Z*2,se=`${_te}-${z}`,Y=b.useRef(0),me=b.useRef();Y.current=K,b.useEffect(()=>{if(M.current&&L)return me.current=JZ({domNode:M.current,panZoom:L,getTransform:()=>D.getState().transform,getViewScale:()=>Y.current}),()=>{me.current?.destroy()}},[L]),b.useEffect(()=>{me.current?.update({translateExtent:U,width:W,height:q,inversePan:N,pannable:S,zoomStep:j,zoomable:C})},[S,C,N,j,U,W,q]);const be=g?ke=>{const[pe,Oe]=me.current?.pointer(ke)||[0,0];g(ke,{x:pe,y:Oe})}:void 0,De=v?b.useCallback((ke,pe)=>{const Oe=D.getState().nodeLookup.get(pe).internals.userNode;v(ke,Oe)},[]):void 0,He=k??I["minimap.ariaLabel"];return n.jsx(Oh,{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*K: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:gs(["react-flow__minimap",t]),"data-testid":"rf__minimap",children:n.jsxs("svg",{width:R,height:E,viewBox:`${H} ${J} ${Q} ${ee}`,className:"react-flow__minimap-svg",role:"img","aria-labelledby":se,ref:M,onClick:be,children:[He&&n.jsx("title",{id:se,children:He}),n.jsx(Dte,{onClick:De,nodeColor:s,nodeStrokeColor:r,nodeBorderRadius:i,nodeClassName:a,nodeStrokeWidth:l,nodeComponent:d}),n.jsx("path",{className:"react-flow__minimap-mask",d:`M${H-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"})]})})}N8.displayName="MiniMap";const zte=b.memo(N8),$te=e=>t=>e?`${Math.max(1/t.transform[2],1)}`:void 0,Bte={[xd.Line]:"right",[xd.Handle]:"bottom-right"};function Hte({nodeId:e,position:t,variant:r=xd.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=n8(),j=typeof e=="string"?e:N,T=Hr(),D=b.useRef(null),M=r===xd.Handle,_=tr(b.useCallback($te(M&&g),[M,g]),Wr),F=b.useRef(null),z=t??Bte[r];b.useEffect(()=>{if(!(!D.current||!j))return F.current||(F.current=fJ({domNode:D.current,nodeId:j,getStoreItems:()=>{const{nodeLookup:U,transform:W,snapGrid:q,snapToGrid:I,nodeOrigin:R,domNode:E}=T.getState();return{nodeLookup:U,transform:W,snapGrid:q,snapToGrid:I,nodeOrigin:R,paneDomNode:E}},onChange:(U,W)=>{const{triggerNodeChanges:q,nodeLookup:I,parentLookup:R,nodeOrigin:E}=T.getState(),$=[],X={x:U.x,y:U.y},K=I.get(j);if(K&&K.expandParent&&K.parentId){const P=K.origin??E,B=U.width??K.measured.width??0,Z=U.height??K.measured.height??0,H={id:K.id,parentId:K.parentId,rect:{width:B,height:Z,...S7({x:U.x??K.position.x,y:U.y??K.position.y},{width:B,height:Z},K.parentId,I,P)}},J=uy([H],I,R,E);$.push(...J),X.x=U.x?Math.max(P[0]*B,U.x):void 0,X.y=U.y?Math.max(P[1]*Z,U.y):void 0}if(X.x!==void 0&&X.y!==void 0){const P={id:j,type:"position",position:{...X}};$.push(P)}if(U.width!==void 0&&U.height!==void 0){const B={id:j,type:"dimensions",resizing:!0,setAttributes:y?y==="horizontal"?"width":"height":!0,dimensions:{width:U.width,height:U.height}};$.push(B)}for(const P of W){const B={...P,type:"position"};$.push(B)}q($)},onEnd:({width:U,height:W})=>{const q={id:j,type:"dimensions",resizing:!1,dimensions:{width:U,height:W}};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:gs(["react-flow__resize-control","nodrag",...L,r,s]),ref:D,style:{...a,scale:_,...l&&{[M?"backgroundColor":"borderColor"]:l}},children:i})}b.memo(Hte);var kr=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),wi=kr((e,t)=>{var r=Object.defineProperty,s=(q,I,R)=>I in q?r(q,I,{enumerable:!0,configurable:!0,writable:!0,value:R}):q[I]=R,a=(q,I)=>()=>(I||q((I={exports:{}}).exports,I),I.exports),i=(q,I,R)=>s(q,typeof I!="symbol"?I+"":I,R),l=a((q,I)=>{var R="\0",E="\0",$="",X=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(Y){ee.length>1?se.setNode(Y,Q):se.setNode(Y)}),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,be]){J(me)&&Q.setNode(me,be)}),Object.values(this._edgeObjs).forEach(function(me){Q.hasNode(me.v)&&Q.hasNode(me.w)&&Q.setEdge(me,ee.edge(me))});var se={};function Y(me){var be=ee.parent(me);return be===void 0||Q.hasNode(be)?(se[me]=be,be):be in se?se[be]:Y(be)}return this._isCompound&&Q.nodes().forEach(me=>Q.setParent(me,Y(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(Y,me){return se.length>1?ee.setEdge(Y,me,Q):ee.setEdge(Y,me),me}),this}setEdge(){var J,Q,ee,se,Y=!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],Y=!0)):(J=me,Q=arguments[1],ee=arguments[3],arguments.length>2&&(se=arguments[2],Y=!0)),J=""+J,Q=""+Q,ee!==void 0&&(ee=""+ee);var be=B(this._isDirected,J,Q,ee);if(Object.hasOwn(this._edgeLabels,be))return Y&&(this._edgeLabels[be]=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[be]=Y?se:this._defaultEdgeLabelFn(J,Q,ee);var De=Z(this._isDirected,J,Q,ee);return J=De.v,Q=De.w,Object.freeze(De),this._edgeObjs[be]=De,K(this._preds[Q],J),K(this._sucs[J],Q),this._in[Q][be]=De,this._out[J][be]=De,this._edgeCount++,this}edge(J,Q,ee){var se=arguments.length===1?H(this._isDirected,arguments[0]):B(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?H(this._isDirected,arguments[0]):B(this._isDirected,J,Q,ee);return Object.hasOwn(this._edgeLabels,se)}removeEdge(J,Q,ee){var se=arguments.length===1?H(this._isDirected,arguments[0]):B(this._isDirected,J,Q,ee),Y=this._edgeObjs[se];return Y&&(J=Y.v,Q=Y.w,delete this._edgeLabels[se],delete this._edgeObjs[se],P(this._preds[Q],J),P(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(Y){return Y.v===Q&&Y.w===ee||Y.v===ee&&Y.w===Q}):se}}};function K(J,Q){J[Q]?J[Q]++:J[Q]=1}function P(J,Q){--J[Q]||delete J[Q]}function B(J,Q,ee,se){var Y=""+Q,me=""+ee;if(!J&&Y>me){var be=Y;Y=me,me=be}return Y+$+me+$+(se===void 0?R:se)}function Z(J,Q,ee,se){var Y=""+Q,me=""+ee;if(!J&&Y>me){var be=Y;Y=me,me=be}var De={v:Y,w:me};return se&&(De.name=se),De}function H(J,Q){return B(J,Q.v,Q.w,Q.name)}I.exports=X}),d=a((q,I)=>{I.exports="3.0.2"}),u=a((q,I)=>{I.exports={Graph:l(),version:d()}}),m=a((q,I)=>{var R=l();I.exports={write:E,read:K};function E(P){var B={options:{directed:P.isDirected(),multigraph:P.isMultigraph(),compound:P.isCompound()},nodes:$(P),edges:X(P)};return P.graph()!==void 0&&(B.value=structuredClone(P.graph())),B}function $(P){return P.nodes().map(function(B){var Z=P.node(B),H=P.parent(B),J={v:B};return Z!==void 0&&(J.value=Z),H!==void 0&&(J.parent=H),J})}function X(P){return P.edges().map(function(B){var Z=P.edge(B),H={v:B.v,w:B.w};return B.name!==void 0&&(H.name=B.name),Z!==void 0&&(H.value=Z),H})}function K(P){var B=new R(P.options).setGraph(P.value);return P.nodes.forEach(function(Z){B.setNode(Z.v,Z.value),Z.parent&&B.setParent(Z.v,Z.parent)}),P.edges.forEach(function(Z){B.setEdge({v:Z.v,w:Z.w,name:Z.name},Z.value)}),B}}),p=a((q,I)=>{I.exports=E;var R=()=>1;function E(X,K,P,B){return $(X,String(K),P||R,B||function(Z){return X.outEdges(Z)})}function $(X,K,P,B){var Z={},H=!0,J=0,Q=X.nodes(),ee=function(be){var De=P(be);Z[be.v].distance+De<Z[be.w].distance&&(Z[be.w]={distance:Z[be.v].distance+De,predecessor:be.v},H=!0)},se=function(){Q.forEach(function(be){B(be).forEach(function(De){var He=De.v===be?De.v:De.w,ke=He===De.v?De.w:De.v;ee({v:He,w:ke})})})};Q.forEach(function(be){var De=be===K?0:Number.POSITIVE_INFINITY;Z[be]={distance:De}});for(var Y=Q.length,me=1;me<Y&&(H=!1,J++,se(),!!H);me++);if(J===Y-1&&(H=!1,se(),H))throw new Error("The graph contains a negative weight cycle");return Z}}),h=a((q,I)=>{I.exports=R;function R(E){var $={},X=[],K;function P(B){Object.hasOwn($,B)||($[B]=!0,K.push(B),E.successors(B).forEach(P),E.predecessors(B).forEach(P))}return E.nodes().forEach(function(B){K=[],P(B),K.length&&X.push(K)}),X}}),y=a((q,I)=>{var R=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 X=this._keyIndices;if(E=String(E),!Object.hasOwn(X,E)){var K=this._arr,P=K.length;return X[E]=P,K.push({key:E,priority:$}),this._decrease(P),!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 X=this._keyIndices[E];if($>this._arr[X].priority)throw new Error("New priority is greater than current priority. Key: "+E+" Old: "+this._arr[X].priority+" New: "+$);this._arr[X].priority=$,this._decrease(X)}_heapify(E){var $=this._arr,X=2*E,K=X+1,P=E;X<$.length&&(P=$[X].priority<$[P].priority?X:P,K<$.length&&(P=$[K].priority<$[P].priority?K:P),P!==E&&(this._swap(E,P),this._heapify(P)))}_decrease(E){for(var $=this._arr,X=$[E].priority,K;E!==0&&(K=E>>1,!($[K].priority<X));)this._swap(E,K),E=K}_swap(E,$){var X=this._arr,K=this._keyIndices,P=X[E],B=X[$];X[E]=B,X[$]=P,K[B.key]=E,K[P.key]=$}};I.exports=R}),g=a((q,I)=>{var R=y();I.exports=$;var E=()=>1;function $(K,P,B,Z){var H=function(J){return K.outEdges(J)};return X(K,String(P),B||E,Z||H)}function X(K,P,B,Z){var H={},J=new R,Q,ee,se=function(Y){var me=Y.v!==Q?Y.v:Y.w,be=H[me],De=B(Y),He=ee.distance+De;if(De<0)throw new Error("dijkstra does not allow negative edge weights. Bad edge: "+Y+" Weight: "+De);He<be.distance&&(be.distance=He,be.predecessor=Q,J.decrease(me,He))};for(K.nodes().forEach(function(Y){var me=Y===P?0:Number.POSITIVE_INFINITY;H[Y]={distance:me},J.add(Y,me)});J.size()>0&&(Q=J.removeMin(),ee=H[Q],ee.distance!==Number.POSITIVE_INFINITY);)Z(Q).forEach(se);return H}}),v=a((q,I)=>{var R=g();I.exports=E;function E($,X,K){return $.nodes().reduce(function(P,B){return P[B]=R($,B,X,K),P},{})}}),S=a((q,I)=>{I.exports=R;function R($,X,K){if($[X].predecessor!==void 0)throw new Error("Invalid source vertex");if($[K].predecessor===void 0&&K!==X)throw new Error("Invalid destination vertex");return{weight:$[K].distance,path:E($,X,K)}}function E($,X,K){for(var P=[],B=K;B!==X;)P.push(B),B=$[B].predecessor;return P.push(X),P.reverse()}}),C=a((q,I)=>{I.exports=R;function R(E){var $=0,X=[],K={},P=[];function B(Z){var H=K[Z]={onStack:!0,lowlink:$,index:$++};if(X.push(Z),E.successors(Z).forEach(function(ee){Object.hasOwn(K,ee)?K[ee].onStack&&(H.lowlink=Math.min(H.lowlink,K[ee].index)):(B(ee),H.lowlink=Math.min(H.lowlink,K[ee].lowlink))}),H.lowlink===H.index){var J=[],Q;do Q=X.pop(),K[Q].onStack=!1,J.push(Q);while(Z!==Q);P.push(J)}}return E.nodes().forEach(function(Z){Object.hasOwn(K,Z)||B(Z)}),P}}),k=a((q,I)=>{var R=C();I.exports=E;function E($){return R($).filter(function(X){return X.length>1||X.length===1&&$.hasEdge(X[0],X[0])})}}),N=a((q,I)=>{I.exports=E;var R=()=>1;function E(X,K,P){return $(X,K||R,P||function(B){return X.outEdges(B)})}function $(X,K,P){var B={},Z=X.nodes();return Z.forEach(function(H){B[H]={},B[H][H]={distance:0},Z.forEach(function(J){H!==J&&(B[H][J]={distance:Number.POSITIVE_INFINITY})}),P(H).forEach(function(J){var Q=J.v===H?J.w:J.v,ee=K(J);B[H][Q]={distance:ee,predecessor:H}})}),Z.forEach(function(H){var J=B[H];Z.forEach(function(Q){var ee=B[Q];Z.forEach(function(se){var Y=ee[H],me=J[se],be=ee[se],De=Y.distance+me.distance;De<be.distance&&(be.distance=De,be.predecessor=me.predecessor)})})}),B}}),j=a((q,I)=>{function R($){var X={},K={},P=[];function B(Z){if(Object.hasOwn(K,Z))throw new E;Object.hasOwn(X,Z)||(K[Z]=!0,X[Z]=!0,$.predecessors(Z).forEach(B),delete K[Z],P.push(Z))}if($.sinks().forEach(B),Object.keys(X).length!==$.nodeCount())throw new E;return P}var E=class extends Error{constructor(){super(...arguments)}};I.exports=R,R.CycleException=E}),T=a((q,I)=>{var R=j();I.exports=E;function E($){try{R($)}catch(X){if(X instanceof R.CycleException)return!1;throw X}return!0}}),D=a((q,I)=>{I.exports=R;function R($,X,K,P,B){Array.isArray(X)||(X=[X]);var Z=($.isDirected()?$.successors:$.neighbors).bind($),H={};return X.forEach(function(J){if(!$.hasNode(J))throw new Error("Graph does not have node: "+J);B=E($,J,K==="post",H,Z,P,B)}),B}function E($,X,K,P,B,Z,H){return Object.hasOwn(P,X)||(P[X]=!0,K||(H=Z(H,X)),B(X).forEach(function(J){H=E($,J,K,P,B,Z,H)}),K&&(H=Z(H,X))),H}}),M=a((q,I)=>{var R=D();I.exports=E;function E($,X,K){return R($,X,K,function(P,B){return P.push(B),P},[])}}),_=a((q,I)=>{var R=M();I.exports=E;function E($,X){return R($,X,"post")}}),F=a((q,I)=>{var R=M();I.exports=E;function E($,X){return R($,X,"pre")}}),z=a((q,I)=>{var R=l(),E=y();I.exports=$;function $(X,K){var P=new R,B={},Z=new E,H;function J(ee){var se=ee.v===H?ee.w:ee.v,Y=Z.priority(se);if(Y!==void 0){var me=K(ee);me<Y&&(B[se]=H,Z.decrease(se,me))}}if(X.nodeCount()===0)return P;X.nodes().forEach(function(ee){Z.add(ee,Number.POSITIVE_INFINITY),P.setNode(ee)}),Z.decrease(X.nodes()[0],0);for(var Q=!1;Z.size()>0;){if(H=Z.removeMin(),Object.hasOwn(B,H))P.setEdge(H,B[H]);else{if(Q)throw new Error("Input graph is not connected: "+X);Q=!0}X.nodeEdges(H).forEach(J)}return P}}),L=a((q,I)=>{var R=g(),E=p();I.exports=$;function $(K,P,B,Z){return X(K,P,B,Z||function(H){return K.outEdges(H)})}function X(K,P,B,Z){if(B===void 0)return R(K,P,B,Z);for(var H=!1,J=K.nodes(),Q=0;Q<J.length;Q++){for(var ee=Z(J[Q]),se=0;se<ee.length;se++){var Y=ee[se],me=Y.v===J[Q]?Y.v:Y.w,be=me===Y.v?Y.w:Y.v;B({v:me,w:be})<0&&(H=!0)}if(H)return E(K,P,B,Z)}return R(K,P,B,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:D(),tarjan:C(),topsort:j()}}),W=u();t.exports={Graph:W.Graph,json:m(),alg:U(),version:W.version}}),Fte=kr((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=kr((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),D=j+T;g.setEdge(N.v,N.w,D),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}}),hs=kr((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:D,zipObject:z};function s(L,U,W,q){for(var I=q;L.hasNode(I);)I=D(q);return W.dummy=U,L.setNode(I,W),I}function a(L){let U=new r().setGraph(L.graph());return L.nodes().forEach(W=>U.setNode(W,L.node(W))),L.edges().forEach(W=>{let q=U.edge(W.v,W.w)||{weight:0,minlen:1},I=L.edge(W);U.setEdge(W.v,W.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(W=>{L.children(W).length||U.setNode(W,L.node(W))}),L.edges().forEach(W=>{U.setEdge(W,L.edge(W))}),U}function l(L){let U=L.nodes().map(W=>{let q={};return L.outEdges(W).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(W=>{let q={};return L.inEdges(W).forEach(I=>{q[I.v]=(q[I.v]||0)+L.edge(I).weight}),q});return z(L.nodes(),U)}function u(L,U){let W=L.x,q=L.y,I=U.x-W,R=U.y-q,E=L.width/2,$=L.height/2;if(!I&&!R)throw new Error("Not possible to find intersection inside of the rectangle");let X,K;return Math.abs(R)*E>Math.abs(I)*$?(R<0&&($=-$),X=$*I/R,K=$):(I<0&&(E=-E),X=E,K=E*R/I),{x:W+X,y:q+K}}function m(L){let U=M(C(L)+1).map(()=>[]);return L.nodes().forEach(W=>{let q=L.node(W),I=q.rank;I!==void 0&&(U[I][q.order]=W)}),U}function p(L){let U=L.nodes().map(q=>{let I=L.node(q).rank;return I===void 0?Number.MAX_VALUE:I}),W=S(Math.min,U);L.nodes().forEach(q=>{let I=L.node(q);Object.hasOwn(I,"rank")&&(I.rank-=W)})}function h(L){let U=L.nodes().map(E=>L.node(E).rank).filter(E=>E!==void 0),W=S(Math.min,U),q=[];L.nodes().forEach(E=>{let $=L.node(E).rank-W;q[$]||(q[$]=[]),q[$].push(E)});let I=0,R=L.graph().nodeRankFactor;Array.from(q).forEach((E,$)=>{E===void 0&&$%R!==0?--I:E!==void 0&&I&&E.forEach(X=>L.node(X).rank+=I)})}function y(L,U,W,q){let I={width:0,height:0};return arguments.length>=4&&(I.rank=W,I.order=q),s(L,"border",I,U)}function g(L,U=v){let W=[];for(let q=0;q<L.length;q+=U){let I=L.slice(q,q+U);W.push(I)}return W}var v=65535;function S(L,U){if(U.length>v){let W=g(U);return L.apply(null,W.map(q=>L.apply(null,q)))}else return L.apply(null,U)}function C(L){let U=L.nodes().map(W=>{let q=L.node(W).rank;return q===void 0?Number.MIN_VALUE:q});return S(Math.max,U)}function k(L,U){let W={lhs:[],rhs:[]};return L.forEach(q=>{U(q)?W.lhs.push(q):W.rhs.push(q)}),W}function N(L,U){let W=Date.now();try{return U()}finally{console.log(L+" time: "+(Date.now()-W)+"ms")}}function j(L,U){return U()}var T=0;function D(L){var U=++T;return L+(""+U)}function M(L,U,W=1){U==null&&(U=L,L=0);let q=R=>R<U;W<0&&(q=R=>U<R);let I=[];for(let R=L;q(R);R+=W)I.push(R);return I}function _(L,U){let W={};for(let q of U)L[q]!==void 0&&(W[q]=L[q]);return W}function F(L,U){let W=U;return typeof U=="string"&&(W=q=>q[U]),Object.entries(L).reduce((q,[I,R])=>(q[I]=W(R,I),q),{})}function z(L,U){return L.reduce((W,q,I)=>(W[q]=U[I],W),{})}}),Ute=kr((e,t)=>{var r=qte(),s=hs().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=kr((e,t)=>{var r=hs();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)})}}),sh=kr((e,t)=>{var{applyWithChunking:r}=hs();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}}),S8=kr((e,t)=>{var r=wi().Graph,s=sh().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)}}),Kte=kr((e,t)=>{var r=S8(),s=sh().slack,a=sh().longestPath,i=wi().alg.preorder,l=wi().alg.postorder,d=hs().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 D=r(T);y(D),m(D,T);for(var M,_;M=v(D);)_=S(D,T,M),C(D,T,M,_)}function m(T,D){var M=l(T,T.nodes());M=M.slice(0,M.length-1),M.forEach(_=>p(T,D,_))}function p(T,D,M){var _=T.node(M),F=_.parent;T.edge(M,F).cutvalue=h(T,D,M)}function h(T,D,M){var _=T.node(M),F=_.parent,z=!0,L=D.edge(M,F),U=0;return L||(z=!1,L=D.edge(F,M)),U=L.weight,D.nodeEdges(M).forEach(W=>{var q=W.v===M,I=q?W.w:W.v;if(I!==F){var R=q===z,E=D.edge(W).weight;if(U+=R?E:-E,N(T,M,I)){var $=T.edge(M,I).cutvalue;U+=R?-$:$}}}),U}function y(T,D){arguments.length<2&&(D=T.nodes()[0]),g(T,{},1,D)}function g(T,D,M,_,F){var z=M,L=T.node(_);return D[_]=!0,T.neighbors(_).forEach(U=>{Object.hasOwn(D,U)||(M=g(T,D,M,U,_))}),L.low=z,L.lim=M++,F?L.parent=F:delete L.parent,M}function v(T){return T.edges().find(D=>T.edge(D).cutvalue<0)}function S(T,D,M){var _=M.v,F=M.w;D.hasEdge(_,F)||(_=M.w,F=M.v);var z=T.node(_),L=T.node(F),U=z,W=!1;z.lim>L.lim&&(U=L,W=!0);var q=D.edges().filter(I=>W===j(T,T.node(I.v),U)&&W!==j(T,T.node(I.w),U));return q.reduce((I,R)=>s(D,R)<s(D,I)?R:I)}function C(T,D,M,_){var F=M.v,z=M.w;T.removeEdge(F,z),T.setEdge(_.v,_.w,{}),y(T),m(T,D),k(T,D)}function k(T,D){var M=T.nodes().find(F=>!D.node(F).parent),_=i(T,M);_=_.slice(1),_.forEach(F=>{var z=T.node(F).parent,L=D.edge(F,z),U=!1;L||(L=D.edge(z,F),U=!0),D.node(F).rank=D.node(z).rank+(U?L.minlen:-L.minlen)})}function N(T,D,M){return T.hasEdge(D,M)}function j(T,D,M){return M.low<=D.lim&&D.lim<=M.lim}}),Wte=kr((e,t)=>{var r=sh(),s=r.longestPath,a=S8(),i=Kte();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=kr((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=kr((e,t)=>{var r=hs();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),D=T.borderTop?T.borderTop:j,M=T.borderBottom?T.borderBottom:j,_=T.borderTop?h:2*h,F=D!==M?1:y-g[v]+1;u.setEdge(C,D,{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=kr((e,t)=>{var r=hs();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=kr((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=kr((e,t)=>{var r=hs();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=kr((e,t)=>{var r=hs().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=kr((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=kr((e,t)=>{var r=hs();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=kr((e,t)=>{var r=hs();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=kr((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 D=i(u,T.v,p,h);C[T.v]=D,Object.hasOwn(D,"barycenter")&&d(T,D)}});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]),D=u.node(u.predecessors(S)[0]);Object.hasOwn(j,"barycenter")||(j.barycenter=0,j.weight=0),j.barycenter=(j.barycenter*j.weight+T.order+D.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=kr((e,t)=>{var r=wi().Graph,s=hs();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=kr((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=kr((e,t)=>{var r=Zte(),s=Jte(),a=rne(),i=sne(),l=ane(),d=wi().Graph,u=hs();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,D=v.constraints||[];for(let M=0,_=0;_<4;++M,++_){h(M%2?C:k,M%4>=2,D),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,D)=>k.node(T).order=D),l(k,C,j.vs)})}function y(g,v){Object.values(v).forEach(S=>S.forEach((C,k)=>g.node(C).order=k))}}),one=kr((e,t)=>{var r=wi().Graph,s=hs();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 D(M,_){let F=0,z=0,L=M.length,U=_[_.length-1];return _.forEach((W,q)=>{let I=l(N,W),R=I?N.node(I).order:L;(I||W===U)&&(_.slice(z,q+1).forEach(E=>{N.predecessors(E).forEach($=>{let X=N.node($),K=X.order;(K<F||R<K)&&!(X.dummy&&N.node(E).dummy)&&d(T,$,E)})}),z=q+1,F=R)}),_}return j.length&&j.reduce(D),T}function i(N,j){let T={};function D(_,F,z,L,U){let W;s.range(F,z).forEach(q=>{W=_[q],N.node(W).dummy&&N.predecessors(W).forEach(I=>{let R=N.node(I);R.dummy&&(R.order<L||R.order>U)&&d(T,I,W)})})}function M(_,F){let z=-1,L,U=0;return F.forEach((W,q)=>{if(N.node(W).dummy==="border"){let I=N.predecessors(W);I.length&&(L=N.node(I[0]).order,D(F,U,q,z,L),U=q,z=L)}D(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 D=N[j];D||(N[j]=D={}),D[T]=!0}function u(N,j,T){if(j>T){let D=j;j=T,T=D}return!!N[j]&&Object.hasOwn(N[j],T)}function m(N,j,T,D){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 W=D(U);if(W.length){W=W.sort((I,R)=>F[I]-F[R]);let q=(W.length-1)/2;for(let I=Math.floor(q),R=Math.ceil(q);I<=R;++I){let E=W[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,D,M){let _={},F=h(N,j,T,M),z=M?"borderLeft":"borderRight";function L(q,I){let R=F.nodes().slice(),E={},$=R.pop();for(;$;){if(E[$])q($);else{E[$]=!0,R.push($);for(let X of I($))R.push(X)}$=R.pop()}}function U(q){_[q]=F.inEdges(q).reduce((I,R)=>Math.max(I,_[R.v]+F.edge(R)),0)}function W(q){let I=F.outEdges(q).reduce((E,$)=>Math.min(E,_[$.w]-F.edge($)),Number.POSITIVE_INFINITY),R=N.node(q);I!==Number.POSITIVE_INFINITY&&R.borderType!==z&&(_[q]=Math.max(_[q],I))}return L(U,F.predecessors.bind(F)),L(W,F.successors.bind(F)),Object.keys(D).forEach(q=>_[q]=_[T[q]]),_}function h(N,j,T,D){let M=new r,_=N.graph(),F=C(_.nodesep,_.edgesep,D);return j.forEach(z=>{let L;z.forEach(U=>{let W=T[U];if(M.setNode(W),L){var q=T[L],I=M.edge(q,W);M.setEdge(q,W,Math.max(F(N,U,L),I||0))}L=U})}),M}function y(N,j){return Object.values(j).reduce((T,D)=>{let M=Number.NEGATIVE_INFINITY,_=Number.POSITIVE_INFINITY;Object.entries(D).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,D]),T},[Number.POSITIVE_INFINITY,null])[1]}function g(N,j){let T=Object.values(j),D=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),W=D-s.applyWithChunking(Math.min,U);F!=="l"&&(W=M-s.applyWithChunking(Math.max,U)),W&&(N[z]=s.mapValues(L,q=>q+W))})})}function v(N,j){return s.mapValues(N.ul,(T,D)=>{if(j)return N[j.toLowerCase()][D];{let M=Object.values(N).map(_=>_[D]).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)),D={},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),W=p(N,M,U.root,U.align,z==="r");z==="r"&&(W=s.mapValues(W,q=>-q)),D[F+z]=W})});let _=y(N,D);return g(D,_),v(D,N.graph().align)}function C(N,j,T){return(D,M,_)=>{let F=D.node(M),z=D.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=kr((e,t)=>{var r=hs(),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=kr((e,t)=>{var r=Ute(),s=Vte(),a=Wte(),i=hs().normalizeRanks,l=Gte(),d=hs().removeEmptyRanks,u=Yte(),m=Xte(),p=Qte(),h=ine(),y=lne(),g=hs(),v=wi().Graph;t.exports=S;function S(Q,ee={}){let se=ee.debugTiming?g.time:g.notime;return se("layout",()=>{let Y=se(" buildLayoutGraph",()=>L(Q));return se(" runLayout",()=>C(Y,se,ee)),se(" updateInputGraph",()=>k(Q,Y)),Y})}function C(Q,ee,se){ee(" makeSpaceForEdgeLabels",()=>U(Q)),ee(" removeSelfEdges",()=>P(Q)),ee(" acyclic",()=>r.run(Q)),ee(" nestingGraph.run",()=>u.run(Q)),ee(" rank",()=>a(g.asNonCompoundGraph(Q))),ee(" injectEdgeLabelProxies",()=>W(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",()=>B(Q)),ee(" adjustCoordinateSystem",()=>p.adjust(Q)),ee(" position",()=>y(Q)),ee(" positionSelfEdges",()=>Z(Q)),ee(" removeBorderNodes",()=>K(Q)),ee(" normalize.undo",()=>s.undo(Q)),ee(" fixupEdgeLabelCoords",()=>$(Q)),ee(" undoCoordinateSystem",()=>p.undo(Q)),ee(" translateGraph",()=>R(Q)),ee(" assignNodeIntersects",()=>E(Q)),ee(" reversePoints",()=>X(Q)),ee(" acyclic.undo",()=>r.undo(Q))}function k(Q,ee){Q.nodes().forEach(se=>{let Y=Q.node(se),me=ee.node(se);Y&&(Y.x=me.x,Y.y=me.y,Y.order=me.order,Y.rank=me.rank,ee.children(se).length&&(Y.width=me.width,Y.height=me.height))}),Q.edges().forEach(se=>{let Y=Q.edge(se),me=ee.edge(se);Y.points=me.points,Object.hasOwn(me,"x")&&(Y.x=me.x,Y.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"],D=["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,H(se,N),g.pick(se,T))),Q.nodes().forEach(Y=>{let me=J(Q.node(Y)),be=H(me,D);Object.keys(M).forEach(De=>{be[De]===void 0&&(be[De]=M[De])}),ee.setNode(Y,be),ee.setParent(Y,Q.parent(Y))}),Q.edges().forEach(Y=>{let me=J(Q.edge(Y));ee.setEdge(Y,Object.assign({},F,H(me,_),g.pick(me,z)))}),ee}function U(Q){let ee=Q.graph();ee.ranksep/=2,Q.edges().forEach(se=>{let Y=Q.edge(se);Y.minlen*=2,Y.labelpos.toLowerCase()!=="c"&&(ee.rankdir==="TB"||ee.rankdir==="BT"?Y.width+=Y.labeloffset:Y.height+=Y.labeloffset)})}function W(Q){Q.edges().forEach(ee=>{let se=Q.edge(ee);if(se.width&&se.height){let Y=Q.node(ee.v),me={rank:(Q.node(ee.w).rank-Y.rank)/2+Y.rank,e:ee};g.addDummyNode(Q,"edge-proxy",me,"_ep")}})}function q(Q){let ee=0;Q.nodes().forEach(se=>{let Y=Q.node(se);Y.borderTop&&(Y.minRank=Q.node(Y.borderTop).rank,Y.maxRank=Q.node(Y.borderBottom).rank,ee=Math.max(ee,Y.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 R(Q){let ee=Number.POSITIVE_INFINITY,se=0,Y=Number.POSITIVE_INFINITY,me=0,be=Q.graph(),De=be.marginx||0,He=be.marginy||0;function ke(pe){let Oe=pe.x,Ee=pe.y,fe=pe.width,Le=pe.height;ee=Math.min(ee,Oe-fe/2),se=Math.max(se,Oe+fe/2),Y=Math.min(Y,Ee-Le/2),me=Math.max(me,Ee+Le/2)}Q.nodes().forEach(pe=>ke(Q.node(pe))),Q.edges().forEach(pe=>{let Oe=Q.edge(pe);Object.hasOwn(Oe,"x")&&ke(Oe)}),ee-=De,Y-=He,Q.nodes().forEach(pe=>{let Oe=Q.node(pe);Oe.x-=ee,Oe.y-=Y}),Q.edges().forEach(pe=>{let Oe=Q.edge(pe);Oe.points.forEach(Ee=>{Ee.x-=ee,Ee.y-=Y}),Object.hasOwn(Oe,"x")&&(Oe.x-=ee),Object.hasOwn(Oe,"y")&&(Oe.y-=Y)}),be.width=se-ee+De,be.height=me-Y+He}function E(Q){Q.edges().forEach(ee=>{let se=Q.edge(ee),Y=Q.node(ee.v),me=Q.node(ee.w),be,De;se.points?(be=se.points[0],De=se.points[se.points.length-1]):(se.points=[],be=me,De=Y),se.points.unshift(g.intersectRect(Y,be)),se.points.push(g.intersectRect(me,De))})}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 X(Q){Q.edges().forEach(ee=>{let se=Q.edge(ee);se.reversed&&se.points.reverse()})}function K(Q){Q.nodes().forEach(ee=>{if(Q.children(ee).length){let se=Q.node(ee),Y=Q.node(se.borderTop),me=Q.node(se.borderBottom),be=Q.node(se.borderLeft[se.borderLeft.length-1]),De=Q.node(se.borderRight[se.borderRight.length-1]);se.width=Math.abs(De.x-be.x),se.height=Math.abs(me.y-Y.y),se.x=be.x+se.width/2,se.y=Y.y+se.height/2}}),Q.nodes().forEach(ee=>{Q.node(ee).dummy==="border"&&Q.removeNode(ee)})}function P(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 B(Q){var ee=g.buildLayerMatrix(Q);ee.forEach(se=>{var Y=0;se.forEach((me,be)=>{var De=Q.node(me);De.order=be+Y,(De.selfEdges||[]).forEach(He=>{g.addDummyNode(Q,"selfedge",{width:He.label.width,height:He.label.height,rank:De.rank,order:be+ ++Y,e:He.e,label:He.label},"_se")}),delete De.selfEdges})})}function Z(Q){Q.nodes().forEach(ee=>{var se=Q.node(ee);if(se.dummy==="selfedge"){var Y=Q.node(se.e.v),me=Y.x+Y.width/2,be=Y.y,De=se.x-me,He=Y.height/2;Q.setEdge(se.e,se.label),Q.removeNode(ee),se.label.points=[{x:me+2*De/3,y:be-He},{x:me+5*De/6,y:be-He},{x:me+De,y:be},{x:me+5*De/6,y:be+He},{x:me+2*De/3,y:be+He}],se.label.x=se.x,se.label.y=se.y}})}function H(Q,ee){return g.mapValues(g.pick(Q,ee),Number)}function J(Q){var ee={};return Q&&Object.entries(Q).forEach(([se,Y])=>{typeof se=="string"&&(se=se.toLowerCase()),ee[se]=Y}),ee}}),dne=kr((e,t)=>{var r=hs(),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=kr((e,t)=>{t.exports="2.0.4"}),mne=kr((e,t)=>{t.exports={graphlib:wi(),layout:cne(),debug:dne(),util:{time:hs().time,notime:hs().notime},version:une()}});const Q3=mne();const Z3={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=Z3[r.status]??Z3.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"?Ut.Left:Ut.Top,y=i==="LR"?Ut.Right:Ut.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 J3={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"}},ej={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=J3[r.status]??J3.pending,u=a==="LR"?Ut.Left:Ut.Top,m=a==="LR"?Ut.Right:Ut.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 Cf=200,Tf=80;function tj(e,t,r="TB"){const s=i=>{const l=new Q3.graphlib.Graph;l.setDefaultEdgeLabel(()=>({})),l.setGraph({rankdir:i,nodesep:40,ranksep:60});for(const d of e)l.setNode(d.id,{width:Cf,height:Tf});for(const d of t)l.setEdge(d.source,d.target);return Q3.layout(l),e.map(d=>{const u=l.node(d.id);return{...d,position:{x:(u?.x??0)-Cf/2,y:(u?.y??0)-Tf/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+Cf),d=Math.min(d,y.position.y),u=Math.max(u,y.position.y+Tf);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 nj(e,t){if(e.length===0)return{nodes:[],direction:"TB"};const r=wne(e,t);if(r.length===1)return tj(e,t);let s="TB";const a=r.map(y=>{const{nodes:g,direction:v}=tj(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+Cf),k=Math.min(k,j.position.y),N=Math.max(N,j.position.y+Tf);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 Jc=[{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(Jc.map(e=>e.id));const of=new Set(Jc.filter(e=>e.id!=="done").map(e=>e.id)),rj=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,D]=b.useState(()=>new Set(of)),[M,_]=b.useState(y??null),[F,z]=b.useState(s??!1),L=s??F,U=b.useCallback(ce=>{const ue=typeof ce=="function"?ce(L):ce;z(ue),a?.(ue)},[L,a]);b.useEffect(()=>{s!==void 0&&z(s)},[s]),b.useEffect(()=>{y&&_(y)},[y]);const W=b.useMemo(()=>e.filter(ce=>rj(ce)).length,[e]),q=b.useMemo(()=>{const ce=new Set;for(const ue of Jc)if(T.has(ue.id))for(const Me of ue.statuses)ce.add(Me);return ce},[T]),I=b.useMemo(()=>{const ce=new Set;for(const ue of e)for(const Me of Jc)if(Me.statuses.has(ue.status)){ce.add(Me.id);break}for(const ue of t){const Me=ej[ue.status];Me&&ce.add(Me)}return Jc.filter(ue=>ce.has(ue.id))},[e,t]),R=b.useCallback(ce=>{D(ue=>{const Me=new Set(ue);return Me.has(ce)?Me.delete(ce):Me.add(ce),Me})},[]),E=b.useCallback((ce,ue="success")=>{k({msg:ce,type:ue}),setTimeout(()=>k(null),2500)},[]),$=b.useMemo(()=>{const ce=new Map;for(const ue of r)ce.set(ue.id,ue.name);return ce},[r]),X=b.useMemo(()=>{const ce=new Map;for(const ue of e)ce.set(ue.id,ue);return ce},[e]),K=b.useMemo(()=>{const ce=new Map;for(const ue of t)ce.set(ue.id,ue);return ce},[t]),P=b.useRef(!1),B=b.useCallback(()=>{P.current=!1,_(null),d?.()},[d]),Z=S?"#94a3b8":"#6b7280",H=b.useCallback((ce,ue,Me)=>({id:`${ce}->${ue}`,source:ce,target:ue,animated:Me==="blocked",markerEnd:{type:fd.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 ce=(it,Vt)=>{const Nn=new Set,Un=it.map(dn=>(Nn.add(dn.id),{id:dn.id,type:"task",data:{task:dn,agentName:dn.assignedAgentId?$.get(dn.assignedAgentId):void 0,selected:dn.id===m},position:{x:0,y:0}}));for(const dn of Vt){const bn=`req-${dn.id}`;Nn.add(bn),Un.push({id:bn,type:"requirement",data:{req:dn,selected:dn.id===p},position:{x:0,y:0}})}const mn=[];for(const dn of it)if(dn.blockedBy)for(const bn of dn.blockedBy)Nn.has(bn)&&mn.push(H(bn,dn.id,dn.status));const Tn=new Set,$n=(dn,bn)=>{const nr=`${dn}->${bn}`;Tn.has(nr)||(Tn.add(nr),mn.push({id:nr,source:dn,target:bn,markerEnd:{type:fd.ArrowClosed,width:14,height:14,color:"#8b5cf6"},style:{stroke:"#8b5cf6",strokeWidth:1.5,strokeDasharray:"4 2"}}))};for(const dn of Vt){const bn=`req-${dn.id}`;for(const nr of dn.taskIds)Nn.has(nr)&&$n(bn,nr)}for(const dn of it)if(dn.requirementId){const bn=`req-${dn.requirementId}`;Nn.has(bn)&&$n(bn,dn.id)}return{nodes:Un,edges:mn}},ue=e.filter(it=>q.has(it.status)&&(L||!rj(it))),Me=new Set;for(const it of Jc)T.has(it.id)&&Me.add(it.id);const ne=t.filter(it=>{const Vt=ej[it.status];return Vt&&Me.has(Vt)}),{nodes:he,edges:Be}=ce(ue,ne),Se=new Set;for(const it of Be)Se.add(it.target);const Ke=new Set(he.filter(it=>!Se.has(it.id)).map(it=>it.id));if(!M||!Ke.has(M)){const it=he.filter(mn=>Ke.has(mn.id)),{nodes:Vt,direction:Nn}=nj(it,[]);return{initialNodes:Vt.map(mn=>({...mn,data:{...mn.data,direction:Nn}})),initialEdges:[],topLevelIds:Ke}}const{nodes:at,edges:ct}=ce(e,t),Je=jne(M,X,K,e),rt=at.filter(it=>Je.has(it.id)).map(it=>it.id===M?{...it,data:{...it.data,isExpandedRoot:!0,onCollapse:B}}:it),ht=ct.filter(it=>Je.has(it.source)&&Je.has(it.target)),{nodes:xt,direction:Ve}=nj(rt,ht);return{initialNodes:xt.map(it=>({...it,data:{...it.data,direction:Ve}})),initialEdges:ht,topLevelIds:Ke}},[e,t,$,X,K,H,q,T,L,m,p,M,B]),[se,Y,me]=mte(J),[be,De,He]=fte(Q),ke=b.useRef(null),pe=b.useRef({groupFilter:T,showArchived:L});b.useEffect(()=>{const ce=pe.current;(ce.groupFilter!==T||ce.showArchived!==L)&&(P.current=!1,_(null),pe.current={groupFilter:T,showArchived:L})},[T,L]),b.useEffect(()=>{Y(J),De(Q),P.current||requestAnimationFrame(()=>{ke.current?.fitView({padding:.2,duration:300})})},[J,Q,Y,De]),b.useEffect(()=>{const ce=setTimeout(()=>{ke.current?.fitView({padding:.2,duration:300})},50);return()=>clearTimeout(ce)},[h]);const Oe=b.useCallback(ce=>{ce&&(P.current=!0)},[]),Ee=b.useCallback((ce,ue)=>{if(!M&&ee.has(ue.id)&&(P.current=!1,_(ue.id)),ue.id.startsWith("req-")){const Me=K.get(ue.id.slice(4));Me&&l&&l(Me)}else{const Me=X.get(ue.id);Me&&i&&i(Me)}},[X,K,i,l,ee,M]),fe=b.useCallback(async ce=>{const{source:ue,target:Me}=ce;if(!ue||!Me||ue===Me)return;const ne=X.get(Me);if(!ne)return;if(ne.blockedBy?.includes(ue)){E(v("work:dag.toast.dependencyExists"),"error");return}if(kne(X,ue,Me)){E(v("work:dag.toast.cycleError"),"error");return}const he=[...ne.blockedBy??[],ue];try{await de.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")}},[X,E,u,v]),Le=b.useCallback((ce,ue)=>{j(ue)},[]),Qe=b.useCallback(async()=>{if(!N)return;const ce=X.get(N.target);if(!ce){j(null);return}const ue=(ce.blockedBy??[]).filter(Me=>Me!==N.source);try{await de.tasks.update(N.target,{blockedBy:ue}),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,X,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 nt=T.size===of.size&&[...of].every(ce=>T.has(ce))&&!L,gt=N?X.get(N.source):null,ze=N?X.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:be,onNodesChange:me,onEdgesChange:He,onNodeClick:Ee,onConnect:fe,onEdgeClick:Le,onMoveEnd:Oe,onInit:ce=>{ke.current=ce},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(ce=>ce.id),rfRef:ke}),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:ce=>{const ue=ce.data?.task,Me=ue?.status;return ue?.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(ce=>{const ue=T.has(ce.id);return n.jsx("button",{onClick:()=>R(ce.id),className:`text-[10px] px-1.5 py-0.5 rounded border transition-colors ${ue?`${ce.color.bg} ${ce.color.border} ${ce.color.text}`:"bg-surface-elevated/50 border-border-default/50 text-fg-tertiary"}`,children:v(`work:dag.filter.${ce.id}`)},ce.id)}),W>0&&n.jsx("button",{onClick:()=>U(ce=>!ce),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:W})}),!nt&&n.jsx("button",{onClick:()=>{D(new Set(of)),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:B,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:ce=>ce.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:ze?.title??N.target.slice(-8),source:gt?.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:Qe,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,D]=b.useState(!1),M=js();b.useEffect(()=>{de.teams.list().then(z=>S(z.teams)).catch(()=>{})},[]);const _=b.useCallback(async z=>{if(z?.preventDefault(),D(!0),!(!a.trim()||C)){k(!0),j("");try{const L=u.trim()?[{url:u.trim(),defaultBranch:p.trim()||"main"}]:[],U=await de.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 ad.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:()=>D(!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(W=>W!==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 C8(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=C8(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=C8(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 bd(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 sj({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 T8(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 aj=[{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 aj[Math.abs(t)%aj.length]}function Rne({note:e,compact:t}){const{t:r}=kt(["work","common"]),s=T8(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(Vr,{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(Vr,{content:s.content,className:"text-xs text-fg-secondary"})})]})})]})}const Dne=new Set(["rejected","cancelled","archived"]),hy=[{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"}],ij={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"},oj={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"},lj={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"},cj={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 A8(e){return Object.keys(oj).reduce((t,r)=>(t[r]={label:e(`work:status.task.${r}`),cls:oj[r]},t),{})}function E8(e){return Object.keys(ij).reduce((t,r)=>(t[r]={label:e(`work:status.sub.${r}`),cls:ij[r]},t),{})}function Lne(e){return Object.keys(lj).reduce((t,r)=>(t[r]={label:e(`work:priority.${r}`),cls:lj[r]},t),{})}function py(e){return Object.keys(cj).reduce((t,r)=>(t[r]={label:e(`work:status.requirement.${r}`),cls:cj[r]},t),{})}const dj=["low","medium","high","urgent"],uj=["pending","in_progress","blocked","review","completed","failed","rejected","cancelled"],mj=["pending","in_progress","completed","rejected","cancelled"],fj={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([])},t1={pending:new Set(["in_progress","rejected","cancelled"]),in_progress:new Set(["completed","cancelled"]),completed:new Set([]),rejected:new Set([]),cancelled:new Set([])},o0={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"},hj={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(Te.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 zu({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((D,M)=>{const _=t.find(F=>F.name.toLowerCase()===D.toLowerCase());if(_){const F=M.target.getBoundingClientRect();m({agent:_,top:F.bottom,left:F.left})}},[t]),k=b.useMemo(()=>t.map(D=>D.name),[t]),N=b.useCallback(D=>{const M=t.find(_=>_.name.toLowerCase()===e.authorName.toLowerCase());if(M){const _=D.currentTarget.getBoundingClientRect();m({agent:M,top:_.bottom,left:_.left})}},[t,e.authorName]),j=b.useCallback(async()=>{if(p){h(!1);return}const D=e.activityId;if(D&&(h(!0),!(y.length>0))){S(!0);try{const{logs:M}=await de.agents.getActivityLogs(e.authorId,D),_=M.map(F=>Gj(F,D,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(()=>Wu(y.map(Gu).filter(D=>D!==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 D=document.getElementById(`comment-${e.replyTo}`);D&&(D.scrollIntoView({behavior:"smooth",block:"center"}),D.classList.add("bg-brand-500/10"),setTimeout(()=>D.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(Vr,{content:e.content,className:"text-xs text-fg-primary",onMentionClick:C,knownNames:k}),e.attachments?.map((D,M)=>D.type==="image"?n.jsx("img",{src:D.url,alt:D.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(Ch,{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),de.tasks.getComments(e.id).then(k=>l(k.comments)).catch(()=>{})},[e.id]),b.useEffect(()=>fn.on("task:comment",N=>{if(N.payload?.taskId===e.id&&N.payload.comment){const j=N.payload.comment;l(T=>T.some(D=>D.id===j.id)?T:[...T,j]),(j.authorType==="agent"||j.authorId?.startsWith("agt_"))&&(u(T=>{const D=T.filter(M=>M.id!==j.authorId);return D.length===0&&m.current&&(clearTimeout(m.current),m.current=null),D}),h(T=>{const D=new Map(T);return D.delete(j.authorId),D}))}}),[e.id]),b.useEffect(()=>{if(d.length===0)return;const k=new Set(d.map(j=>j.id));return fn.on("agent:activity_log",j=>{const T=j.payload;if(!T)return;const D=T.agentId;if(!k.has(D))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(D)??[],F];return L.set(D,U),L})}})},[d]);const y=b.useMemo(()=>{const k=[];for(const N of e.notes??[]){const j=T8(N);let T;if(j.timestamp){const D=j.timestamp.match(/^(\d{4})[/-](\d{2})[/-](\d{2})\s+(\d{2}):(\d{2})(?::(\d{2}))?/);T=D?new Date(+D[1],+D[2]-1,+D[3],+D[4],+D[5],+(D[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 D;j.length>0&&(D=(await de.uploads.upload(j.map(L=>({dataUrl:L.dataUrl,name:L.name})),"comments")).files.map(L=>({type:"image",url:L.url,name:L.name}))),await de.tasks.addComment(e.id,k,s?.name,D,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(Rne,{note:k.note,compact:!0},`n-${N}`):n.jsx(zu,{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(Te.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(Sh,{activities:N,isActive:!0})})]},k.id)})})]}),n.jsx(jS,{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,D]=b.useState(new Set),[M,_]=b.useState(""),[F,z]=b.useState(!1),[L,U]=b.useState([]),W=b.useRef(null),[q,I]=b.useState(new Map),[R,E]=b.useState([]),[$,X]=b.useState([]),[K,P]=b.useState(!1),B=b.useRef(null),Z=b.useRef(null);b.useEffect(()=>{k(t)},[t]),b.useEffect(()=>{U([]),I(new Map),W.current&&(clearTimeout(W.current),W.current=null)},[a]),b.useEffect(()=>{j(!0),Promise.all([de.tasks.getLogsSummary(a).catch(()=>({rounds:[]})),de.tasks.getComments(a).catch(()=>({comments:[]}))]).then(([ke,pe])=>{const Oe=ke.rounds;if(d(Oe),g(pe.comments),Oe.length===0){j(!1);return}const Ee=Oe[Oe.length-1].round;D(new Set([Ee])),de.tasks.getLogs(a,Ee).catch(()=>({logs:[]})).then(fe=>{m(new Map([[Ee,fe.logs]])),j(!1)})})},[a]),b.useEffect(()=>{const ke=e.assignedAgentId;ke&&(P(!0),de.agents.getActivities(ke,{taskId:a,limit:20}).then(pe=>X(pe.activities)).catch(()=>X([])).finally(()=>P(!1)))},[a,e.assignedAgentId]);const H=b.useCallback(ke=>{u.has(ke)||p.has(ke)||(h(pe=>new Set(pe).add(ke)),de.tasks.getLogs(a,ke).catch(()=>({logs:[]})).then(pe=>{m(Oe=>new Map(Oe).set(ke,pe.logs)),h(Oe=>{const Ee=new Set(Oe);return Ee.delete(ke),Ee})}))},[a,u,p]),J=b.useCallback(ke=>{D(pe=>{const Oe=new Set(pe);return Oe.has(ke)?Oe.delete(ke):(Oe.add(ke),u.has(ke)||H(ke)),Oe})},[u,H]);b.useEffect(()=>{const ke=fn.on("task:log",Ee=>{const fe=Ee.payload;if(fe.taskId!==a)return;const Le={id:fe.id,taskId:fe.taskId,agentId:fe.agentId,seq:fe.seq,type:fe.logType,content:fe.content,metadata:fe.metadata,executionRound:fe.executionRound,createdAt:fe.createdAt},Qe=Le.executionRound??1;d(nt=>nt.find(ze=>ze.round===Qe)?nt:[...nt,{round:Qe,logCount:0,toolCount:0,firstAt:Le.createdAt,lastAt:Le.createdAt,status:"running"}]),D(nt=>nt.has(Qe)?nt:new Set(nt).add(Qe)),m(nt=>{const gt=nt.get(Qe)??[];return Le.id&&gt.some(ze=>ze.id===Le.id)?nt:new Map(nt).set(Qe,[...gt,Le])}),Le.type==="text"&&S(""),Le.type==="status"&&(Le.content==="started"||Le.content==="resumed"?k(!0):["completed","failed","cancelled","execution_finished"].includes(Le.content)&&(k(!1),d(nt=>nt.map(gt=>gt.round===Qe?{...gt,status:Le.content}:gt)))),Le.type==="error"&&k(!1)}),pe=fn.on("task:log:delta",Ee=>{const fe=Ee.payload;fe.taskId===a&&S(Le=>Le+fe.text)}),Oe=fn.on("task:comment",Ee=>{const fe=Ee.payload;if(fe.taskId!==a)return;const Le=fe.comment;g(Qe=>Qe.some(nt=>nt.id===Le.id)?Qe:[...Qe,Le]),(Le.authorType==="agent"||Le.authorId?.startsWith("agt_"))&&(U(Qe=>{const nt=Qe.filter(gt=>gt.id!==Le.authorId);return nt.length===0&&W.current&&(clearTimeout(W.current),W.current=null),nt}),I(Qe=>{const nt=new Map(Qe);return nt.delete(Le.authorId),nt}))});return()=>{ke(),pe(),Oe()}},[a]),b.useEffect(()=>{if(L.length===0)return;const ke=new Set(L.map(Oe=>Oe.id));return fn.on("agent:activity_log",Oe=>{const Ee=Oe.payload;if(!Ee)return;const fe=Ee.agentId;if(!ke.has(fe))return;const Le=Ee.type;if(Le==="tool_start"||Le==="tool_end"){const nt={tool:Ee.content??Ee.metadata?.tool??"",phase:Le==="tool_start"?"start":"end",success:Le==="tool_end"?Ee.metadata?.success!==!1:void 0,ts:Date.now()};I(gt=>{const ze=new Map(gt),ce=[...ze.get(fe)??[],nt];return ze.set(fe,ce),ze})}})},[L]);const Q=b.useMemo(()=>{const ke=[];for(const[,pe]of u)ke.push(...pe);return ke.sort((pe,Oe)=>pe.seq-Oe.seq),ke},[u]),ee=b.useMemo(()=>Q.map(ke=>Jx(ke)),[Q]),se=l.length>1,Y=ke=>{const pe=ke.target.files;if(pe){for(const Oe of Array.from(pe)){if(!Oe.type.startsWith("image/"))continue;const Ee=new FileReader;Ee.onload=()=>{E(fe=>[...fe,{type:"image",url:Ee.result,name:Oe.name}])},Ee.readAsDataURL(Oe)}ke.target.value=""}},me=async()=>{if(!(!M.trim()&&R.length===0)){z(!0);try{let ke;R.length>0&&(ke=(await de.uploads.upload(R.map(Qe=>({dataUrl:Qe.url,name:Qe.name})),"comments")).files.map(Qe=>({type:"image",url:Qe.url,name:Qe.name})));const pe=await de.tasks.addComment(a,M,r?.name,ke,r?.id);pe.comment&&g(Le=>Le.some(Qe=>Qe.id===pe.comment.id)?Le:[...Le,pe.comment]),_(""),E([]);const Oe=[],Ee=new Set,fe=Le=>{if(Ee.has(Le)||Le===r?.id)return;Ee.add(Le);const Qe=s.find(nt=>nt.id===Le);Qe&&Oe.push({id:Qe.id,name:Qe.name,avatarUrl:Qe.avatarUrl})};e.assignedAgentId&&fe(e.assignedAgentId),e.createdBy?.startsWith("agt_")&&e.status!=="in_progress"&&fe(e.createdBy),Oe.length>0&&(W.current&&clearTimeout(W.current),U(Oe),W.current=setTimeout(()=>U([]),12e4))}catch{}z(!1)}},be=n.jsxs("div",{className:"border-t border-border-default px-4 py-3 sticky bottom-0 bg-surface-primary z-10",children:[R.length>0&&n.jsx("div",{className:"flex gap-2 mb-2 flex-wrap",children:R.map((ke,pe)=>n.jsxs("div",{className:"relative group",children:[n.jsx("img",{src:ke.url,alt:ke.name,className:"w-16 h-16 object-cover rounded-lg border border-border-default"}),n.jsx("button",{onClick:()=>E(Oe=>Oe.filter((Ee,fe)=>fe!==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:ke=>_(ke.target.value),onKeyDown:ke=>{ke.key==="Enter"&&!ke.shiftKey&&(ke.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:B,accept:"image/*",multiple:!0,onChange:Y,className:"hidden"}),n.jsx("button",{onClick:()=>B.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()&&R.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 ke=e.assignedAgentId?s.find(ze=>ze.id===e.assignedAgentId):void 0,pe=$.length>0,Oe=ke&&ke.currentTaskId&&ke.currentTaskId!==e.id,Ee=e.status==="pending",fe=e.status==="in_progress",Le=!e.assignedAgentId;let Qe="📋",nt=i("work:task.emptyLogs.default"),gt=i("work:task.emptyLogs.defaultHint");return Le?(Qe="👤",nt=i("work:task.emptyLogs.noAgent"),gt=i("work:task.emptyLogs.noAgentHint")):Ee?(Qe="⏳",nt=i("work:task.emptyLogs.pending"),gt=i("work:task.emptyLogs.pendingHint")):fe&&Oe?(Qe="🔄",nt=i("work:task.emptyLogs.agentBusy",{agent:ke?.name??e.assignedAgentId}),gt=i("work:task.emptyLogs.agentBusyHint")):fe&&(Qe="⏳",nt=i("work:task.emptyLogs.starting"),gt=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:K?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:ke?.name??i("work:task.agent"),count:$.length})]}),n.jsx("div",{className:"space-y-1.5",children:$.map(ze=>{const ce=!ze.endedAt,ue=ze.type==="task"?"🔧":ze.type==="chat"||ze.type==="respond_in_session"?"💬":ze.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(Te.TEAM,{agentId:e.assignedAgentId}),children:[n.jsx("span",{className:"text-sm shrink-0",children:ue}),n.jsxs("div",{className:"flex-1 min-w-0",children:[n.jsx("div",{className:"text-xs text-fg-primary truncate",children:ze.label}),n.jsxs("div",{className:"text-[10px] text-fg-tertiary",children:[new Date(ze.startedAt).toLocaleString(),ze.endedAt?` — ${ze.totalTools} tools, ${ze.totalTokens.toLocaleString()} tokens`:""]})]}),ce&&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")]}),!ce&&n.jsx("span",{className:`shrink-0 text-[10px] ${ze.success?"text-fg-tertiary":"text-red-400"}`,children:ze.success?"✓":"✗"}),n.jsx("span",{className:"shrink-0 text-fg-tertiary text-[10px] opacity-0 group-hover:opacity-100 transition-opacity",children:"→"})]},ze.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:Qe}),n.jsxs("div",{className:"text-xs",children:[nt,n.jsx("br",{}),n.jsx("span",{className:"text-fg-muted",children:gt})]})]})})}),be]})}if(!se){const ke=ee.map(Ee=>Gu(Ee)).filter(Ee=>Ee!==null),pe=ek(Q,Wu(ke)),Oe=[...pe.map(Ee=>({kind:"entry",entry:Ee,ts:Ee.timestamp?new Date(Ee.timestamp).getTime():0})),...y.map(Ee=>({kind:"comment",comment:Ee,ts:new Date(Ee.createdAt).getTime()}))];return Oe.sort((Ee,fe)=>Ee.ts-fe.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:[Oe.map((Ee,fe)=>Ee.kind==="comment"?n.jsx(zu,{comment:Ee.comment,agents:s},`c-${Ee.comment.id}`):n.jsx(qf,{entry:Ee.entry,showTime:!0,isLast:fe===Oe.length-1},`e-${fe}`)),C&&v&&n.jsx(Rb,{content:v}),C&&!v&&pe.length>0&&n.jsx(Mb,{})]}),be]})}const De=(ke,pe)=>{const Oe=ke.firstAt?new Date(ke.firstAt).getTime():0,Ee=pe?.firstAt?new Date(pe.firstAt).getTime():1/0;return y.filter(fe=>{const Le=new Date(fe.createdAt).getTime();return Le>=Oe&&Le<Ee})},He=l.length>0?y.filter(ke=>new Date(ke.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:[He.length>0&&n.jsx("div",{className:"space-y-0.5",children:He.map(ke=>n.jsx(zu,{comment:ke,agents:s},ke.id))}),l.map((ke,pe)=>{const Oe=T.has(ke.round),Ee=ke.round===l[l.length-1].round,fe=u.get(ke.round),Le=p.has(ke.round),Qe=De(ke,l[pe+1]),nt=ke.status==="completed"||ke.status==="execution_finished"?"✅":ke.status==="failed"?"❌":ke.status==="cancelled"?"⏹":"🔄",gt=ke.lastAt&&ke.firstAt?Math.max(0,new Date(ke.lastAt).getTime()-new Date(ke.firstAt).getTime()):0,ze=gt>=6e4?`${Math.floor(gt/6e4)}m ${Math.floor(gt%6e4/1e3)}s`:gt>=1e3?`${Math.floor(gt/1e3)}s`:"";return n.jsxs("div",{className:"border border-border-default/50 rounded-lg overflow-hidden",children:[n.jsxs("button",{onClick:()=>J(ke.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:nt}),n.jsx("span",{className:"text-xs text-fg-secondary font-medium",children:i("work:task.roundHeader",{n:ke.round})}),Qe.length>0&&n.jsxs("span",{className:"text-[10px] text-blue-400",children:["💬 ",Qe.length]}),Ee&&C&&n.jsxs("svg",{className:"w-3 h-3 animate-spin text-brand-500",viewBox:"0 0 24 24",fill:"none",children:[n.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),n.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"})]})]}),n.jsxs("div",{className:"flex items-center gap-3",children:[n.jsx("span",{className:"text-[10px] text-fg-tertiary",children:i("work:task.toolCount",{count:ke.toolCount})}),ze&&n.jsx("span",{className:"text-[10px] text-fg-tertiary tabular-nums",children:ze}),n.jsx("svg",{className:`w-3 h-3 text-fg-tertiary transition-transform ${Oe?"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"})})]})]}),Oe&&n.jsxs("div",{className:"px-3 py-1.5 space-y-0.5",children:[Le&&n.jsx("div",{className:"text-xs text-fg-tertiary py-2 text-center",children:i("work:task.loadingRound",{n:ke.round})}),fe&&(()=>{const ue=fe.map(he=>Jx(he)).map(he=>Gu(he)).filter(he=>he!==null),ne=[...ek(fe,Wu(ue)).map(he=>({kind:"entry",entry:he,ts:he.timestamp?new Date(he.timestamp).getTime():0})),...Qe.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(zu,{comment:he.comment,agents:s},`c-${he.comment.id}`):n.jsx(qf,{entry:he.entry,showTime:!0,isLast:Be===ne.length-1},`e-${Be}`))})(),Ee&&C&&v&&n.jsx(Rb,{content:v}),Ee&&C&&!v&&!Le&&n.jsx(Mb,{})]})]},ke.round)}),L.length>0&&n.jsx("div",{className:"flex flex-col gap-1.5 mt-2",children:L.map(ke=>{const pe=q.get(ke.id)??[];return n.jsxs("div",{className:"px-3 py-2 rounded-lg cursor-pointer hover:bg-surface-elevated/60 transition-colors",onClick:()=>Nt.navigate(Te.TEAM,{agentId:ke.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:ke.name,avatarUrl:ke.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:ke.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(Sh,{activities:pe,isActive:!0})})]},ke.id)})})]}),be]})}const pj=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),de.files.preview(i).then(T=>d(T)).catch(T=>m(String(T))).finally(()=>h(!1))},[i]);const y=T=>a(D=>[...D,T]),g=()=>a(T=>T.length>1?T.slice(0,-1):T),v=s.length>1,S=T=>{de.files.reveal(T).catch(()=>{})},C=T=>{T.isDirectory||pj.has(T.ext)?y(T.path):S(T.path)},k=i.split("/").pop()??i,N=l?.type==="directory",j=(T,D)=>{if(D)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&&!pj.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(Y1,{content:l.content,format:l.type==="text"?"text":l.type,className:"text-sm text-fg-secondary leading-relaxed"})})]})]})})}function gj({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(()=>A8(g),[g]),[S,C]=b.useState([]),[k,N]=b.useState(""),[j,T]=b.useState(!1),[D,M]=b.useState(!1),[_,F]=b.useState(null),[z,L]=b.useState(null),[U,W]=b.useState(!1),[q,I]=b.useState(!1),[R,E]=b.useState(!1),[$,X]=b.useState("every"),[K,P]=b.useState(""),[B,Z]=b.useState(""),[H,J]=b.useState(""),[Q,ee]=b.useState(!1),[se,Y]=b.useState("details"),me=b.useRef(null),[be,De]=b.useState("none"),He=b.useCallback(Ce=>{Y(Ce),requestAnimationFrame(()=>{me.current?.scrollTo({top:0,behavior:"instant"})})},[]),ke=b.useMemo(()=>[{id:"details"},{id:"logs"},{id:"deliverables"},{id:"history"}],[]),pe=hl(ke,se,He);b.useEffect(()=>{const Ce=me.current;if(!Ce)return;const Ct=()=>{const{scrollTop:Wt,scrollHeight:qt,clientHeight:Ne}=Ce;if(!(qt>Ne+50)){De("none");return}const Dt=Wt<30,Jt=Wt+Ne>=qt-30;De(Dt?"top":Jt?"bottom":"middle")};Ct(),Ce.addEventListener("scroll",Ct,{passive:!0});const $t=new ResizeObserver(Ct);return $t.observe(Ce),()=>{Ce.removeEventListener("scroll",Ct),$t.disconnect()}},[se]),b.useEffect(()=>{if(!m)return;Y("details");const Ce=setTimeout(()=>{const Ct=me.current;Ct&&Ct.scrollTo({top:Ct.scrollHeight,behavior:"smooth"}),p?.()},300);return()=>clearTimeout(Ce)},[m,p]);const[Oe,Ee]=b.useState(null),[fe,Le]=b.useState(!1),[Qe,nt]=b.useState(null),[gt,ze]=b.useState(!1),[ce,ue]=b.useState(e.description),Me=b.useRef(null),ne=b.useRef(null),he=b.useRef(80);b.useEffect(()=>{if(gt&&ne.current){const Ce=ne.current;Ce.style.height="auto",Ce.style.height=Math.max(Ce.scrollHeight,he.current)+"px",Ce.focus()}},[gt]);const[Be,Se]=b.useState(!1),[Ke,at]=b.useState(""),[ct,Je]=b.useState(1),[rt,ht]=b.useState(!1),xt=js(),Ve=20,ut=b.useCallback(async()=>{try{const Ce=await de.tasks.listSubtasks(e.id);C(Ce.subtasks)}catch{}},[e.id]);b.useEffect(()=>{ut()},[ut]);const it=async Ce=>{if(!Q){ee(!0);try{await Ce(),d(),await ut()}catch(Ct){Ee(String(Ct).replace("Error: ",""))}finally{ee(!1)}}},Vt=Ce=>it(()=>de.tasks.update(e.id,{priority:Ce})),Nn=Ce=>it(()=>de.tasks.assign(e.id,Ce||null)),Un=Ce=>it(()=>de.tasks.update(e.id,{projectId:Ce||null})),mn=async()=>{if(!Q){ee(!0);try{await de.tasks.pause(e.id),d()}finally{ee(!1)}}},Tn=async()=>{if(!Q){ee(!0),Ee(null),He("logs");try{await de.tasks.resume(e.id),d()}catch(Ce){Ee(String(Ce).replace("Error: API error: 400","Server error").replace("Error: ",""))}finally{ee(!1)}}},$n=async()=>{k.trim()&&(await de.tasks.createSubtask(e.id,k.trim()),N(""),T(!1),ut(),d())},dn=async Ce=>{Ce.status==="completed"?await de.tasks.cancelSubtask(e.id,Ce.id):await de.tasks.completeSubtask(e.id,Ce.id),ut(),d()},bn=async Ce=>{await de.tasks.deleteSubtask(e.id,Ce.id),F(null),ut(),d()},nr=async()=>{if(!Q){ee(!0);try{await de.tasks.updateStatus(e.id,"in_progress"),d()}finally{ee(!1)}}},ir=async()=>{if(!Q){ee(!0),Ee(null),He("logs");try{await de.tasks.retry(e.id),d()}catch(Ce){Ee(String(Ce).replace("Error: API error: 400","Server error").replace("Error: ",""))}finally{ee(!1)}}},jr=async()=>{if(!Q){ee(!0),Ee(null),He("logs");try{await de.tasks.runNow(e.id),d()}catch(Ce){Ee(String(Ce).replace("Error: API error: 400","Server error").replace("Error: ","")),d()}finally{ee(!1)}}},xr=b.useRef(d);xr.current=d,b.useEffect(()=>fn.on("task:update",Ct=>{Ct.payload.taskId===e.id&&(ut(),xr.current())}),[e.id,ut]);const rr=S.filter(Ce=>Ce.status==="completed").length,Ln=e.status==="in_progress",Qn=e.status==="blocked",Vn=e.status==="completed",Zn=e.status==="failed",br=e.status==="rejected",Bn=e.status==="cancelled",Xt=e.status==="archived",pn=Vn||Zn||br||Bn||Xt,on=e.taskType==="scheduled"&&!!e.scheduleConfig,Dr=on&&!!e.scheduleConfig?.paused,Nr=r.find(Ce=>Ce.id===e.projectId),rn=s.find(Ce=>Ce.id===e.requirementId);return t.find(Ce=>Ce.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:[xt&&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 Ce=v[e.status];return Ce?n.jsx("span",{className:`text-[10px] px-2 py-0.5 rounded-full font-medium whitespace-nowrap align-middle ${Ce.cls}`,children:Ce.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:()=>He("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:()=>He("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"),Ln&&n.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-brand-400 animate-pulse"})]}),n.jsx("button",{onClick:()=>He("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 Ce=(e.deliverables??[]).filter(Ct=>Ct.type!=="branch"&&typeof Ct.reference=="string"&&Ct.reference.length>0).length;return Ce>0?g("work:task.deliverablesCount",{count:Ce}):g("work:task.deliverables")})()}),n.jsx("button",{onClick:()=>He("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:[se==="logs"&&n.jsxs("div",{className:"min-w-0 min-h-full",children:[Oe&&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")})," ",Oe]}),n.jsx(One,{task:e,isRunning:e.status==="in_progress",authUser:u,agents:t})]}),se==="details"&&n.jsxs(n.Fragment,{children:[n.jsx("div",{className:"px-6 pt-4 pb-3 border-b border-border-default",children:gt?n.jsx("textarea",{ref:ne,value:ce,onChange:Ce=>{ue(Ce.target.value);const Ct=Ce.target;Ct.style.height="auto",Ct.style.height=Ct.scrollHeight+"px"},onBlur:()=>{ce!==e.description&&it(()=>de.tasks.update(e.id,{description:ce})),ze(!1)},onKeyDown:Ce=>{Ce.key==="Escape"&&(Ce.preventDefault(),ue(e.description),ze(!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),ue(e.description),ze(!0)},role:"button",tabIndex:0,onKeyDown:Ce=>Ce.key==="Enter"&&(ue(e.description),ze(!0)),children:e.description?n.jsxs("div",{children:[n.jsx("div",{className:xt&&!rt?"line-clamp-3":"",children:n.jsx(Vr,{content:e.description,className:"text-sm text-fg-secondary leading-relaxed"})}),xt&&e.description.length>150&&n.jsx("button",{onClick:Ce=>{Ce.stopPropagation(),ht(!rt)},className:"text-[11px] text-brand-500 mt-1 font-medium",children:g(rt?"work:task.collapse":"common:showMore")})]}):n.jsx("p",{className:"text-sm text-fg-tertiary italic",children:g("work:task.noDescription")})})}),(Nr||rn)&&n.jsxs("div",{className:"px-6 py-2.5 border-b border-border-default flex flex-wrap items-center gap-2",children:[Nr&&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(Nr.id):void 0,role:y?"button":void 0,tabIndex:y?0:void 0,onKeyDown:y?Ce=>Ce.key==="Enter"&&y(Nr.id):void 0,children:[n.jsx("span",{className:"text-[9px] text-brand-500/60",children:g("work:task.projectLabel")}),Nr.name]}),rn&&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(rn):void 0,role:h?"button":void 0,tabIndex:h?0:void 0,onKeyDown:h?Ce=>Ce.key==="Enter"&&h(rn):void 0,children:[n.jsx("span",{className:"text-[9px] text-brand-500/60",children:g("work:task.requirementLabel")}),rn.title.length>40?rn.title.slice(0,40)+"…":rn.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(Ce=>{const Ct=a.find(Wt=>Wt.id===Ce),$t=Ct&&(Ct.status==="completed"||Ct.status==="cancelled");return n.jsxs("span",{className:`inline-flex items-center gap-1 text-[11px] px-2 py-1 rounded-full ${$t?"bg-green-500/10 text-green-600":"bg-amber-500/10 text-amber-600"}`,children:[n.jsx("span",{className:"text-[9px]",children:$t?"✓":"⏳"}),n.jsx("span",{className:`font-mono ${$t?"line-through opacity-60":""}`,children:Ct?Ct.title.slice(0,30):Ce.slice(-8)}),!pn&&n.jsx("button",{onClick:async()=>{const Wt=(e.blockedBy??[]).filter(qt=>qt!==Ce);await de.tasks.update(e.id,{blockedBy:Wt}),d()},className:"ml-0.5 text-current opacity-40 hover:opacity-100 transition-opacity",title:g("work:task.removeDependency"),children:"×"})]},Ce)})}):n.jsx("p",{className:"text-[11px] text-fg-tertiary mb-2",children:g("work:task.noDependencies")}),!pn&&n.jsxs("select",{value:"",onChange:async Ce=>{const Ct=Ce.target.value;if(!Ct)return;const $t=[...e.blockedBy??[],Ct];await de.tasks.update(e.id,{blockedBy:$t}),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(Ce=>Ce.id!==e.id&&!(e.blockedBy??[]).includes(Ce.id)).map(Ce=>n.jsx("option",{value:Ce.id,children:Ce.title},Ce.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:Ce=>{Un(Ce.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(Ce=>n.jsx("option",{value:Ce.id,children:Ce.name},Ce.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:Ce=>it(()=>de.tasks.update(e.id,{requirementId:Ce.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(Ce=>!e.projectId||Ce.projectId===e.projectId).map(Ce=>n.jsx("option",{value:Ce.id,children:Ce.title},Ce.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:Ce=>{Nn(Ce.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(Ce=>n.jsxs("option",{value:Ce.id,children:[Ce.name," (",Ce.status,")"]},Ce.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:Ce=>{const Ct=Ce.target.value;if(!Ct)return;const $t=Ct.startsWith("human:"),Wt=Ct.replace(/^(human|agent):/,"");(Wt!==e.reviewerId||($t?"human":"agent")!==(e.reviewerType??"agent"))&&it(()=>de.tasks.update(e.id,{reviewerId:Wt,reviewerType:$t?"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(Ce=>n.jsx("option",{value:`human:${Ce.id}`,children:Ce.name},`human:${Ce.id}`)),t.map(Ce=>n.jsx("option",{value:`agent:${Ce.id}`,children:Ce.name},`agent:${Ce.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:Ce=>{Vt(Ce.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:bd(e.createdBy,t,i)??e.createdBy})}),e.updatedBy&&n.jsx("span",{children:g("work:task.updatedBy",{name:bd(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:rr,total:S.length})})]}),n.jsxs("div",{className:"flex items-center gap-2",children:[rr>0&&n.jsx("button",{onClick:()=>M(Ce=>!Ce),className:`text-[10px] px-2 py-0.5 rounded-full border transition-colors ${D?"bg-brand-500/15 text-brand-500 border-brand-500/30":"text-fg-tertiary border-border-default hover:text-fg-secondary"}`,children:D?g("work:task.hideCompleted"):g("work:task.showCompleted",{count:rr})}),n.jsx("button",{onClick:()=>T(!0),className:"text-xs text-brand-500 hover:text-brand-500 transition-colors",children:g("work:task.addSubtask")})]})]}),(()=>{const Ce=D?S:S.filter(Ct=>Ct.status!=="completed");return Ce.length>0?n.jsx("div",{className:"space-y-1.5 mb-3",children:Ce.map(Ct=>n.jsxs("div",{className:"group flex items-center gap-2.5 py-1.5 px-2 rounded-lg hover:bg-surface-elevated/50 transition-colors",children:[n.jsx("button",{onClick:()=>{dn(Ct)},className:`shrink-0 w-4 h-4 rounded border flex items-center justify-center transition-colors ${Ct.status==="completed"?"bg-green-600 border-green-600 text-white":"border-gray-600 hover:border-brand-500"}`,children:Ct.status==="completed"&&n.jsx("svg",{className:"w-2.5 h-2.5",viewBox:"0 0 12 12",fill:"none",children:n.jsx("path",{d:"M2 6l3 3 5-5",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})}),n.jsx("span",{className:`flex-1 text-sm ${Ct.status==="completed"?"line-through text-fg-tertiary":"text-fg-secondary"}`,children:Ct.title}),n.jsx("button",{onClick:()=>F(Ct),className:"shrink-0 opacity-0 group-hover:opacity-100 text-fg-tertiary hover:text-red-500 transition-all text-xs",children:"✕"})]},Ct.id))}):null})(),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:Ce=>N(Ce.target.value),onKeyDown:Ce=>{Ce.key==="Enter"&&$n(),Ce.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:()=>{$n()},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 Ce=(e.deliverables??[]).filter(Wt=>Wt.type!=="branch"&&typeof Wt.reference=="string"&&Wt.reference.length>0);if(Ce.length===0)return null;const Ct={file:"bg-blue-500/15 text-blue-600",document:"bg-blue-500/15 text-blue-600",report:"bg-brand-500/15 text-brand-500",directory:"bg-green-500/15 text-green-600",url:"bg-brand-500/15 text-brand-500",text:"bg-gray-500/15 text-fg-secondary"},$t=Ce.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:Ce.length})}),Ce.length>3&&n.jsx("button",{onClick:()=>He("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:$t.map((Wt,qt)=>{const Ne=/^https?:\/\//i.test(Wt.reference),Rt=Ne?Wt.summary||Wt.reference:Wt.reference.split("/").pop()??Wt.reference;return n.jsxs("div",{className:"flex items-start gap-2.5 bg-surface-elevated/60 rounded-lg px-3 py-2 group hover:bg-surface-elevated/80 transition-colors",children:[n.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded font-medium shrink-0 mt-0.5 ${Ct[Wt.type]??"bg-gray-500/15 text-fg-secondary"}`,children:Wt.type}),n.jsxs("div",{className:"flex-1 min-w-0",children:[Ne?n.jsxs("a",{href:Wt.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:Wt.reference,children:[Rt," ",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:()=>nt(Wt.reference),className:"text-sm text-brand-500 hover:text-brand-500 font-medium truncate block max-w-full text-left hover:underline",title:Wt.reference,children:Rt}),Wt.summary&&!Ne&&n.jsx("p",{className:"text-[11px] text-fg-secondary mt-0.5 line-clamp-2",children:Wt.summary}),n.jsx("p",{className:"text-[10px] text-fg-tertiary font-mono truncate mt-0.5",children:Wt.reference})]})]},qt)})})]})})(),n.jsx(Pne,{task:e,agents:t,users:i,authUser:u})]})]}),se==="history"&&n.jsx(D8,{entityType:"task",entityId:e.id}),se==="deliverables"&&n.jsx("div",{className:"px-6 py-4",children:(()=>{const Ce=(e.deliverables??[]).filter(qt=>qt.type!=="branch"&&typeof qt.reference=="string"&&qt.reference.length>0);if(Ce.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 Ct={file:"bg-blue-500/15 text-blue-600",document:"bg-blue-500/15 text-blue-600",report:"bg-brand-500/15 text-brand-500",directory:"bg-green-500/15 text-green-600",url:"bg-brand-500/15 text-brand-500",text:"bg-gray-500/15 text-fg-secondary"},$t=Math.ceil(Ce.length/Ve),Wt=Ce.slice((ct-1)*Ve,ct*Ve);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:Ce.length})}),$t>1&&n.jsxs("div",{className:"flex items-center gap-1.5 text-[10px] text-fg-tertiary",children:[n.jsx("button",{disabled:ct<=1,onClick:()=>Je(qt=>qt-1),className:"px-1.5 py-0.5 rounded bg-surface-elevated hover:bg-surface-overlay disabled:opacity-30",children:"‹"}),n.jsxs("span",{children:[ct,"/",$t]}),n.jsx("button",{disabled:ct>=$t,onClick:()=>Je(qt=>qt+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:Wt.map((qt,Ne)=>{const Rt=/^https?:\/\//i.test(qt.reference),Dt=Rt?qt.summary||qt.reference:qt.reference.split("/").pop()??qt.reference;return n.jsxs("div",{className:"flex items-start gap-2.5 bg-surface-elevated/60 rounded-lg px-3 py-2 group hover:bg-surface-elevated/80 transition-colors",children:[n.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded font-medium shrink-0 mt-0.5 ${Ct[qt.type]??"bg-gray-500/15 text-fg-secondary"}`,children:qt.type}),n.jsxs("div",{className:"flex-1 min-w-0",children:[Rt?n.jsxs("a",{href:qt.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:qt.reference,children:[Dt," ",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:()=>nt(qt.reference),className:"text-sm text-brand-500 hover:text-brand-500 font-medium truncate block max-w-full text-left hover:underline",title:qt.reference,children:Dt}),qt.summary&&!Rt&&n.jsx("p",{className:"text-[11px] text-fg-secondary mt-0.5 line-clamp-2",children:qt.summary}),n.jsx("p",{className:"text-[10px] text-fg-tertiary font-mono truncate mt-0.5",children:qt.reference})]})]},Ne)})})]})})()})]}),be!=="none"&&be!=="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"})})}),be!=="none"&&be!=="bottom"&&n.jsx("button",{onClick:()=>{const Ce=me.current;Ce&&Ce.scrollTo({top:Ce.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"})})})]}),on&&e.scheduleConfig&&n.jsxs("div",{className:`mx-6 mt-3 mb-0 px-4 py-2.5 rounded-lg border text-xs ${Dr?"bg-amber-500/5 border-amber-500/20":"bg-brand-500/5 border-brand-500/20"} ${!Ln&&!R&&!e.scheduleConfig.runAt?"cursor-pointer hover:border-brand-500/40 transition-colors":""}`,onClick:()=>{Ln||R||e.scheduleConfig?.runAt||(X(e.scheduleConfig?.cron?"cron":"every"),P(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:Dr?"text-amber-600":"text-brand-500",children:Dr?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")}),!Dr&&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 Ce=new Date(e.scheduleConfig.nextRunAt).getTime()-Date.now();if(Ce<=0)return g("work:task.scheduleDueNow");const Ct=Math.floor(Ce/6e4);if(Ct<60)return g("work:task.scheduleInMinutes",{count:Ct});const $t=Math.floor(Ct/60);return $t<24?g("work:task.scheduleInHoursMinutes",{h:$t,m:Ct%60}):g("work:task.scheduleInDaysHours",{d:Math.floor($t/24),h:$t%24})})()})})]}),!Ln&&!R&&!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"})]})]}),R?n.jsxs("div",{className:"mt-2 pt-2 border-t border-border-default/50 space-y-2",onClick:Ce=>Ce.stopPropagation(),children:[n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsxs("select",{value:$,onChange:Ce=>X(Ce.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:K,onChange:Ce=>P(Ce.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:B,onChange:Ce=>Z(Ce.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:H,onChange:Ce=>J(Ce.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 Ce={};$==="every"?Ce.every=K:Ce.cron=B.trim(),H&&(Ce.maxRuns=parseInt(H,10)),await it(()=>de.tasks.updateSchedule(e.id,Ce)),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 Ce=Date.now()-new Date(e.scheduleConfig.lastRunAt).getTime(),Ct=Math.floor(Ce/6e4);if(Ct<1)return g("work:task.noteTimeJustNow");if(Ct<60)return g("work:task.noteTimeMinutes",{count:Ct});const $t=Math.floor(Ct/60);return $t<24?g("work:task.noteTimeHours",{count:$t}):g("work:task.noteTimeDays",{count:Math.floor($t/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(on){Le(!0);return}it(()=>de.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:()=>{it(()=>de.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:()=>W(!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:()=>{it(()=>de.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:Ke,onChange:Ce=>at(Ce.target.value),onKeyDown:Ce=>{Ce.key==="Enter"&&Ke.trim()&&(it(()=>de.tasks.revision(e.id,Ke.trim(),u?.id)),Se(!1),at(""))},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:()=>{it(()=>de.tasks.revision(e.id,Ke.trim()||g("work:task.revisionsNeededDefault"),u?.id)),Se(!1),at("")},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:()=>{Se(!1),at("")},className:"px-1.5 py-1 text-xs text-fg-secondary hover:text-fg-primary",children:"✕"})]}):n.jsx("button",{onClick:()=>Se(!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")})]}),Ln&&n.jsxs(n.Fragment,{children:[n.jsxs("button",{onClick:()=>{mn()},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")]})]}),Qn&&n.jsx("button",{onClick:()=>{Tn()},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")]})}),Zn&&!on&&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:()=>{nr()},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")]})]}),on&&(Vn||Zn)&&!Xt&&n.jsx("button",{onClick:()=>{jr()},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")]})}),on&&!Ln&&!Xt&&!br&&(Dr?n.jsx("button",{onClick:()=>{it(()=>de.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:()=>{it(()=>de.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")})),(Vn||Zn||br||Bn)&&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")}),Vn&&!on&&n.jsx("button",{onClick:()=>{nr()},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")}),!pn&&e.status!=="pending"&&n.jsx("button",{onClick:async()=>{const{count:Ce}=await de.tasks.getDependentCount(e.id);L({dependentCount:Ce})},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(Xc,{title:g("work:task.deleteSubtaskTitle",{title:_.title}),message:g("work:task.deleteSubtaskMessage"),confirmLabel:g("common:delete"),onConfirm:()=>{bn(_)},onCancel:()=>F(null)}),U&&n.jsx(Xc,{title:g("work:task.rejectConfirmTitle"),message:g("work:task.rejectConfirmMessage"),confirmLabel:g("work:task.reject"),onConfirm:()=>{W(!1),it(()=>de.tasks.reject(e.id))},onCancel:()=>W(!1)}),q&&n.jsx(Xc,{title:g("work:task.archiveConfirmTitle"),message:g(on?"work:task.archiveScheduledConfirmMessage":"work:task.archiveConfirmMessage"),confirmLabel:g("work:task.archive"),onConfirm:()=>{I(!1),it(()=>de.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:Ce=>Ce.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),it(()=>de.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),it(()=>de.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(Xc,{title:g("work:task.cancelTaskModalTitle"),message:g("work:task.cancelConfirmMessage"),confirmLabel:g("work:task.cancelTask"),onConfirm:()=>{L(null),it(()=>de.tasks.cancel(e.id))},onCancel:()=>L(null)}),Qe&&n.jsx(zne,{filePath:Qe,onClose:()=>nt(null)}),fe&&e.scheduleConfig&&n.jsx("div",{className:"fixed inset-0 bg-black/60 flex items-center justify-center z-[60]",onClick:()=>Le(!1),children:n.jsxs("div",{className:"bg-surface-secondary border border-border-default rounded-xl p-6 w-[380px] shadow-2xl",onClick:Ce=>Ce.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:()=>{Le(!1),it(()=>de.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:()=>{Le(!1),it(()=>de.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:()=>Le(!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"]),D=[{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,W)=>W!==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:D.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(W=>W.assignedAgentId===z.id),U=L.filter(W=>!["completed","failed","cancelled","archived"].includes(W.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 M8={pending:"todo",in_progress:"in_progress",completed:"done",rejected:"closed",cancelled:"closed",archived:"closed"},R8={failed:"rejected",todo:"pending",in_progress:"in_progress",review:"in_progress",done:"completed",closed:"cancelled"},Bne={urgent:0,high:1,medium:2,low:3},xj={failed:0,todo:1,in_progress:2,review:3,done:4,closed:5},bj={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 hy)if(t.statuses.includes(e))return t.id;return"closed"}function yj(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 lf({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 vj({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(()=>A8(g),[g]),S=b.useMemo(()=>py(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=a.get((e.kind==="task",e.data.projectId??"")),D=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 ${bj[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:[D,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(lf,{value:k,options:e.kind==="task"?uj.map(M=>({value:M,label:v[M]?.label??M,cls:v[M]?.cls??"bg-gray-500/15 text-fg-tertiary"})):mj.map(M=>({value:M,label:S[M]?.label??M,cls:S[M]?.cls??"bg-gray-500/15 text-fg-tertiary"})),allowedValues:e.kind==="task"?fj[k]:t1[k],onSelect:M=>{m(e,M)}})}),n.jsx("div",{onClick:M=>M.stopPropagation(),children:n.jsx(lf,{value:N,options:dj.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 ${o0[j.status]??"bg-gray-500"}`}),n.jsx("span",{className:`${hj[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:yj(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 ${bj[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:D}),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(lf,{value:k,options:e.kind==="task"?uj.map(M=>({value:M,label:v[M]?.label??M,cls:v[M]?.cls??"bg-gray-500/15 text-fg-tertiary"})):mj.map(M=>({value:M,label:S[M]?.label??M,cls:S[M]?.cls??"bg-gray-500/15 text-fg-tertiary"})),allowedValues:e.kind==="task"?fj[k]:t1[k],onSelect:M=>{m(e,M)}})}),n.jsx("div",{className:"w-[100px] shrink-0",onClick:M=>M.stopPropagation(),children:n.jsx(lf,{value:N,options:dj.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 ${o0[j.status]??"bg-gray-500"}`}),n.jsx("span",{className:`font-medium ${hj[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:yj(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=js(),[h,y]=b.useState("status"),[g,v]=b.useState(null),[S,C]=b.useState(null),k=b.useMemo(()=>{const R=[];for(const E of e){const $=qne(E.status);R.push({kind:"task",data:E,group:$,groupOrder:xj[$]??5})}for(const E of t){const $=M8[E.status]??"todo";R.push({kind:"req",data:E,group:$,groupOrder:xj[$]??5})}if(h==="status")R.sort((E,$)=>{if(E.groupOrder!==$.groupOrder)return E.groupOrder-$.groupOrder;const X=new Date(E.data.updatedAt??0).getTime();return new Date($.data.updatedAt??0).getTime()-X});else{const E=$=>Bne[$.data.priority]??2;R.sort(($,X)=>{const K=E($),P=E(X);return K!==P?K-P:new Date(X.data.updatedAt??0).getTime()-new Date($.data.updatedAt??0).getTime()})}return R},[e,t,h]),N=async(R,E)=>{try{R.kind==="task"?await de.tasks.updateStatus(R.data.id,E):await de.requirements.updateStatus(R.data.id,E),l()}catch{}},j=async(R,E)=>{try{R.kind==="task"?await de.tasks.update(R.data.id,{priority:E}):await de.requirements.update(R.data.id,{priority:E}),l()}catch{}},T=(R,E)=>{v(E),R.dataTransfer.effectAllowed="move",R.dataTransfer.setData("text/plain",String(E)),R.currentTarget.style.opacity="0.4"},D=R=>{R.currentTarget.style.opacity="1",v(null),C(null)},M=(R,E)=>{R.preventDefault(),R.dataTransfer.dropEffect="move",S!==E&&C(E)},_=async(R,E)=>{if(R.preventDefault(),C(null),g==null)return;const $=k[g];if(!$||$.group===E)return;const X=hy.find(K=>K.id===E);if(X){try{if($.kind==="task"){if($.data.status==="pending")return;await de.tasks.updateStatus($.data.id,X.dropStatus)}else{const K=R8[E];K&&await de.requirements.updateStatus($.data.id,K)}l()}catch{}v(null)}},F=b.useMemo(()=>new Map(r.map(R=>[R.id,R])),[r]),z=b.useMemo(()=>new Map(s.map(R=>[R.id,R])),[s]),L=["todo","in_progress","review","done"],U=b.useMemo(()=>{const R={};for(const E of k)R[E.group]=(R[E.group]??0)+1;return R},[k]),{rowsByGroup:W,rowIndexMap:q}=b.useMemo(()=>{const R=new Map,E=new Map;for(let $=0;$<k.length;$++){const X=k[$];E.set(X,$);const K=R.get(X.group)??[];K.push(X),R.set(X.group,K)}return{rowsByGroup:R,rowIndexMap:E}},[k]),I=b.useMemo(()=>{if(h!=="status")return null;const R=new Set(k.map(X=>X.group)),E=[],$=new Set;R.has("failed")&&(E.push("failed"),$.add("failed"));for(const X of L)E.push(X),$.add(X);for(const X of k)$.has(X.group)||(E.push(X.group),$.add(X.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(R=>{const E=W.get(R)??[];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[R]??""} ${S===R?"ring-1 ring-brand-500/40":""}`,onDragOver:$=>M($,R),onDragLeave:()=>C(null),onDrop:$=>{_($,R)},children:[n.jsx("span",{className:"text-[11px] font-semibold uppercase tracking-wider",children:m(`work:boardColumn.${R}`)}),n.jsx("span",{className:"text-[10px] text-fg-tertiary",children:U[R]??0})]}),E.map($=>n.jsx(vj,{row:$,idx:q.get($)??0,dragIdx:g,agentMap:F,projMap:z,onTaskClick:a,onReqClick:i,onRowDragStart:T,onRowDragEnd:D,handleStatusChange:N,handlePriorityChange:j,selected:$.kind==="task"?$.data.id===d:$.data.id===u,isMobile:p},`${$.kind}-${$.data.id}`))]},R)}):k.map((R,E)=>n.jsx(vj,{row:R,idx:E,dragIdx:g,agentMap:F,projMap:z,onTaskClick:a,onReqClick:i,onRowDragStart:T,onRowDragEnd:D,handleStatusChange:N,handlePriorityChange:j,selected:R.kind==="task"?R.data.id===d:R.data.id===u,isMobile:p},`${R.kind}-${R.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 wj({authUser:e,previewMode:t,previewData:r}={}){const{t:s}=kt(["work","common"]),a=yd(Te.WORK),i=b.useMemo(()=>hy.map(ae=>({...ae,label:s(`work:boardColumn.${ae.id}`)})),[s]),l=b.useMemo(()=>E8(s),[s]),d=b.useMemo(()=>py(s),[s]),u=js(),m=b.useRef(null),[p,h]=b.useState(0);b.useEffect(()=>{const ae=m.current;if(!ae)return;const Ye=new ResizeObserver(([lt])=>h(lt.contentRect.width));return Ye.observe(ae),h(ae.clientWidth),()=>Ye.disconnect()},[]);const y=p||window.innerWidth,g=b.useRef(!1),v=Qu({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,D]=b.useState("all"),[M,_]=b.useState(null),[F,z]=b.useState(r?.board??{}),[L,U]=b.useState(r?.agents??[]),[W,q]=b.useState(r?.users??[]),[I,R]=b.useState(r?.allRequirements??[]),[E,$]=b.useState(!r),[X,K]=b.useState(""),[P,B]=b.useState(!1),[Z,H]=b.useState(null),J=b.useCallback(()=>{qt(M??""),on(!0)},[M]),[Q,ee]=b.useState(!1),[se,Y]=b.useState(!1),[me,be]=b.useState(""),[De,He]=b.useState(""),[ke,pe]=b.useState("medium"),[Oe,Ee]=b.useState(""),[fe,Le]=b.useState(""),[Qe,nt]=b.useState(""),[gt,ze]=b.useState(""),[ce,ue]=b.useState([]),[Me,ne]=b.useState("standard"),[he,Be]=b.useState("4h"),[Se,Ke]=b.useState(""),[at,ct]=b.useState(null),[Je,rt]=b.useState(()=>r?.initialSelectedReqId&&r.allRequirements?r.allRequirements.find(ae=>ae.id===r.initialSelectedReqId)??null:null),[ht,xt]=b.useState(new Set),[Ve,ut]=b.useState(!1),[it,Vt]=b.useState(new Set),Nn=b.useRef(new Set),Un=b.useRef(new Set),[mn,Tn]=b.useState(null),[$n,dn]=b.useState(r?.initialBoardType??"backlog"),bn=b.useMemo(()=>[{id:"backlog"},{id:"kanban"},{id:"dag"}],[]),nr=hl(bn,$n,dn),ir=b.useRef(null),jr=b.useMemo(()=>({scrollContainerRef:ir}),[]),xr=hl(bn,$n,dn,jr),[rr,Ln]=b.useState(!1),[Qn,Vn]=b.useState(null),[Zn,br]=b.useState(!1),Bn=b.useRef(null),Xt=b.useRef(null),[pn,on]=b.useState(!1),[Dr,Nr]=b.useState(""),[rn,Ce]=b.useState(""),[Ct,$t]=b.useState("medium"),[Wt,qt]=b.useState(""),[Ne,Rt]=b.useState(null),[Dt,Jt]=b.useState(""),[Jn,xe]=b.useState(""),[Xe,bt]=b.useState(""),[Ft,tn]=b.useState(null),Gt=ae=>{K(ae),setTimeout(()=>K(""),3e3)},sn=N.find(ae=>ae.id===M)??null,vn=sn??N.find(ae=>ae.id===Z)??null,Pn=b.useCallback(()=>{B(!1),H(null)},[]),or=b.useCallback(ae=>{if(P&&(M===ae||Z===ae)){Pn();return}M||H(ae),B(!0)},[P,M,Z,Pn]);b.useEffect(()=>{Un.current=it},[it]);const Lr=b.useCallback(async()=>{try{const{projects:ae}=await de.projects.list();j(ae)}catch{}},[]),_t=b.useCallback(async()=>{const ae={};T==="project"&&M&&(ae.projectId=M);try{const{board:Ye}=await de.tasks.board(ae);z(Ye)}catch{}},[T,M]),sr=b.useCallback(async()=>{try{const{agents:ae}=await de.agents.list();U(ae)}catch{}},[]),_r=b.useCallback(async()=>{try{const{users:ae}=await de.users.list(e?.orgId);q(ae)}catch{}},[e?.orgId]),dr=b.useCallback(async()=>{try{const{requirements:ae}=await de.requirements.list({});R(ae)}catch{}},[]),Va=b.useCallback(async()=>{await Promise.all([Lr(),_t(),sr(),_r(),dr()]),$(!1)},[Lr,_t,sr,_r,dr]);b.useEffect(()=>{t||Va()},[t,Va]),b.useEffect(()=>{!t||!r||(j(r.projects??[]),z(r.board??{}),U(r.agents??[]),q(r.users??[]),R(r.allRequirements??[]))},[t,r]);const Yr=b.useCallback(ae=>{ct(Ye=>Ye?.id===ae.id?(u&&k.current&&C(!1),null):(u&&(C(!0),history.pushState({mobileDetail:Te.WORK},"",window.location.hash)),ae)),rt(null)},[u]),$s=b.useCallback(ae=>{rt(Ye=>Ye?.id===ae.id?(u&&k.current&&C(!1),null):(u&&(C(!0),history.pushState({mobileDetail:Te.WORK},"",window.location.hash)),ae)),ct(null)},[u]),Bs=b.useCallback(()=>{ct(null),rt(null),u&&k.current&&C(!1)},[u]),sa=b.useCallback(()=>{ct(null),!Ka.current&&u&&k.current&&C(!1)},[u]);b.useEffect(()=>{if(!u)return;const ae=()=>{k.current&&(C(!1),ct(null),rt(null))};return window.addEventListener("popstate",ae),()=>window.removeEventListener("popstate",ae)},[u]);const zr=b.useRef(at);zr.current=at;const Ka=b.useRef(Je);Ka.current=Je,b.useEffect(()=>{const ae=Ye=>{if(Ye.key!=="Escape")return;const lt=Ye.target?.tagName;if(!(lt==="INPUT"||lt==="TEXTAREA"||lt==="SELECT")){if(zr.current){ct(null);return}if(Ka.current){rt(null);return}}};return window.addEventListener("keydown",ae),()=>window.removeEventListener("keydown",ae)},[]),b.useEffect(()=>{if(t||!a)return;const ae=zr.current?12e4:45e3,Ye=setInterval(()=>{_t(),sr(),dr()},ae);let lt=null;const Tt=()=>{lt||(lt=setTimeout(()=>{lt=null,_t()},800))};let en=null;const pr=()=>{en||(en=setTimeout(()=>{en=null,dr()},800))},Cn=fn.on("task:update",qr=>{Tt();const ie=qr?.payload;ie?.taskId&&ct(_e=>{if(!_e||_e.id!==ie.taskId)return _e;const Ze={};return typeof ie.status=="string"&&(Ze.status=ie.status),Array.isArray(ie.deliverables)&&(Ze.deliverables=ie.deliverables),Array.isArray(ie.notes)&&(Ze.notes=ie.notes),ie.result!==void 0&&(Ze.result=ie.result),{..._e,...Ze}})}),Et=fn.on("task:create",()=>{Tt()}),Ls=["requirement:created","requirement:approved","requirement:rejected","requirement:updated","requirement:completed","requirement:cancelled","requirement:resubmitted"].map(qr=>fn.on(qr,()=>{pr()})),Fs=()=>{rl("/taskboard"),_t(),dr()};return window.addEventListener("markus:data-changed",Fs),()=>{clearInterval(Ye),Cn(),Et(),Ls.forEach(qr=>qr()),window.removeEventListener("markus:data-changed",Fs),lt&&clearTimeout(lt),en&&clearTimeout(en)}},[t,a,_t,sr,dr]);const Vi=b.useRef(F);Vi.current=F;const Ws=b.useRef(I);Ws.current=I;const Es=b.useCallback(ae=>{if(!ae)return;const Ye=Un.current;Ye.size>0&&!Ye.has(ae)&&Vt(lt=>new Set([...lt,ae]))},[]),[ur,va]=b.useState(!1),Hs=b.useCallback((ae,Ye)=>{ct(ae),rt(null),Ye?.scrollToComments&&va(!0),u&&(C(!0),history.pushState({mobileDetail:Te.WORK},"",window.location.hash))},[u]),xs=b.useCallback((ae,Ye)=>{rt(ae),ct(null),Ye?.scrollToComments&&va(!0),u&&(C(!0),history.pushState({mobileDetail:Te.WORK},"",window.location.hash))},[u]);b.useEffect(()=>{const ae=localStorage.getItem("markus_nav_openTask");if(!ae)return;const lt=Object.values(F).flat().find(Tt=>Tt.id===ae);lt&&(Es(lt.projectId),Hs(lt),localStorage.removeItem("markus_nav_openTask"))},[F,Hs,Es]),b.useEffect(()=>{const ae=localStorage.getItem("markus_nav_openRequirement");if(!ae)return;const Ye=I.find(lt=>lt.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])===Te.WORK&&ae[1])gn(ae[1]);else{const Ye=localStorage.getItem("markus_nav_projectId");Ye&&(localStorage.removeItem("markus_nav_projectId"),gn(Ye))}},[]);const li=b.useRef(il(window.location.hash.slice(1).split("/")[0]));b.useEffect(()=>{if(t)return;const ae=()=>{const lt=window.location.hash.slice(1).split("/"),Tt=il(lt[0]),en=li.current===Te.WORK;li.current=Tt,Tt===Te.WORK&&(Tt===Te.WORK&&lt[1]?gn(lt[1]):en&&yr())},Ye=async lt=>{const Tt=lt.detail;if(il(Tt.page)===Te.WORK){if(Tt.params?.openTask){const en=Tt.params.openTask,pr=Tt.params.scrollToComments==="true";localStorage.removeItem("markus_nav_openTask");let Cn=Object.values(Vi.current).flat().find(Et=>Et.id===en);if(!Cn)try{Cn=(await de.tasks.get(en)).task}catch{}Cn&&(Es(Cn.projectId),Hs(Cn,{scrollToComments:pr}))}if(Tt.params?.openRequirement){const en=Tt.params.openRequirement,pr=Tt.params.scrollToComments==="true";let Cn=Ws.current.find(Et=>Et.id===en);if(!Cn)try{Cn=(await de.requirements.get(en)).requirement}catch{}Cn&&(Es(Cn.projectId),xs(Cn,{scrollToComments:pr}))}if(Tt.params?.projectId&&gn(Tt.params.projectId),Tt.params?.statusFilter){const en=Tt.params.statusFilter;localStorage.removeItem("markus_nav_statusFilter"),Dne.has(en)&&Ln(!0),Vn(en)}}};return window.addEventListener("markus:navigate",Ye),window.addEventListener("hashchange",ae),()=>{window.removeEventListener("markus:navigate",Ye),window.removeEventListener("hashchange",ae)}},[t]);const gn=ae=>{Un.current.size>0&&(Nn.current=new Set(Un.current)),Vt(new Set),_(ae),D("project"),H(null),B(!1),history.replaceState(null,"",rw(Te.WORK,ae))},yr=()=>{Vt(Nn.current),_(null),D("all"),H(null),B(!1),history.replaceState(null,"",rw(Te.WORK))},ci=()=>{ee(!1),Gt(s("work:task.projectCreated")),Lr()},wa=async ae=>{if(confirm("Delete this project and unlink all its tasks?"))try{await de.projects.delete(ae),M===ae&&yr(),Gt("Project deleted"),Lr(),_t()}catch(Ye){Gt(`Error: ${Ye}`)}},Ms=async()=>{if(!me||!Oe||!fe)return;Ke("");const ae=fe.startsWith("human:"),Ye=fe.replace(/^(human|agent):/,"");if(Oe===Ye&&!ae){Gt(s("work:task.assignedReviewerDifferent"));return}const lt=Qe||void 0,Tt=gt||void 0;try{const{task:en}=await de.tasks.create(me,De,Oe,Ye,ke,lt,ce.length>0?ce:void 0,Tt,Me!=="standard"?Me:void 0,Me==="scheduled"?{every:he}:void 0,ae?"human":"agent");be(""),He(""),ue([]),ze(""),ne("standard"),Be("4h"),Y(!1),_t(),en&&Hs(en)}catch(en){const Cn=`work:task.errorCode_${(en instanceof Wj?en.code:void 0)||"unknown"}`,Et=s(Cn,{defaultValue:""});Ke(Et||s("work:task.errorCreatingTask",{message:en instanceof Error?en.message:String(en)}))}},Ir=ae=>{window.dispatchEvent(new CustomEvent("markus:mark-read-by-ref",{detail:ae}))},ji=()=>{_t(),at&&(Ir({taskId:at.id}),setTimeout(()=>{const ae={};T==="project"&&M&&(ae.projectId=M),de.tasks.board(ae).then(Ye=>{const Tt=Object.values(Ye.board).flat().find(en=>en.id===at.id);ct(Tt||null)}).catch(()=>{})},150))},yn=()=>{dr(),Je&&setTimeout(()=>{de.requirements.list({}).then(({requirements:ae})=>{const Ye=ae.find(lt=>lt.id===Je.id);rt(Ye||null)}).catch(()=>{})},150)},Kn=async()=>{if(!Dr.trim()){xe(s("work:task.pleaseReqTitle"));return}if(!rn.trim()){xe(s("work:task.pleaseReqDesc"));return}if(!Wt){xe(s("work:task.pleaseReqProject"));return}xe("");try{const{requirement:ae}=await de.requirements.create({title:Dr.trim(),description:rn.trim(),priority:Ct,projectId:Wt});Gt(s("work:task.requirementCreated")),Nr(""),Ce(""),on(!1),dr(),ae&&xs(ae)}catch(ae){xe(ae instanceof Error?ae.message:String(ae))}},Xr=async ae=>{try{await de.requirements.approve(ae),Gt("Requirement approved"),Ir({requirementId:ae}),yn(),_t()}catch(Ye){Gt(`Error: ${Ye}`)}},Rs=async()=>{if(Ne){bt("");try{await de.requirements.reject(Ne,Dt),Gt("Requirement rejected"),Ir({requirementId:Ne}),Rt(null),Jt(""),bt(""),yn()}catch(ae){bt(ae instanceof Error?ae.message:String(ae))}}},ka=async ae=>{try{await de.requirements.cancel(ae),Gt("Requirement cancelled"),Ir({requirementId:ae}),yn()}catch(Ye){Gt(`Error: ${Ye}`)}},ja=(ae,Ye)=>{Bn.current=Ye,Xt.current=null,ae.dataTransfer.effectAllowed="move",ae.dataTransfer.setData("text/plain",`task:${Ye.id}`),ae.currentTarget.style.opacity="0.4"},Ns=(ae,Ye)=>{Xt.current=Ye,Bn.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",Bn.current=null,Xt.current=null,Tn(null)},Na=(ae,Ye)=>{ae.preventDefault(),ae.dataTransfer.dropEffect="move",mn!==Ye&&Tn(Ye)},di=(ae,Ye)=>{const lt=ae.currentTarget.getBoundingClientRect(),{clientX:Tt,clientY:en}=ae;(Tt<lt.left||Tt>lt.right||en<lt.top||en>lt.bottom)&&mn===Ye&&Tn(null)},Wa=async(ae,Ye)=>{ae.preventDefault(),Tn(null);const lt=Bn.current,Tt=Xt.current;if(lt){const en=i.find(Cn=>Cn.id===Ye);if(!en)return;const pr=en.dropStatus;if(lt.status===pr||lt.status==="pending")return;try{await de.tasks.updateStatus(lt.id,pr),_t()}catch{}}else if(Tt){const en=R8[Ye];if(!en||Tt.status===en)return;try{await de.requirements.updateStatus(Tt.id,en),dr()}catch{}}},Qr=ae=>{xt(Ye=>{const lt=new Set(Ye);return lt.has(ae)?lt.delete(ae):lt.add(ae),lt})},Ar=ae=>{T==="project"?M===ae?yr():gn(ae):Vt(Ye=>{const lt=new Set(Ye);return lt.has(ae)?lt.delete(ae):lt.add(ae),lt})},Fr=new Set(["rejected","cancelled","archived"]),Ss=ae=>Fr.has(ae.status),Sn=(ae,Ye=!1)=>{let lt=ae.filter(Tt=>rr||!Ss(Tt));return Qn&&(lt=lt.filter(Tt=>Tt.status===Qn)),T==="project"&&M&&(lt=lt.filter(Tt=>Tt.projectId===M)),it.size>0&&(lt=lt.filter(Tt=>Tt.projectId&&it.has(Tt.projectId))),ht.size>0&&(lt=lt.filter(Tt=>Tt.assignedAgentId&&ht.has(Tt.assignedAgentId))),Ve&&e?.id&&(lt=lt.filter(Tt=>Tt.createdBy===e.id)),lt},Zr=b.useMemo(()=>new Set(L.map(ae=>ae.id)),[L]),Sa=ae=>ae.statuses.flatMap(Ye=>Sn(F[Ye]??[])),Cs=b.useMemo(()=>{let ae=I;if(rr||(ae=ae.filter(Ye=>!Ss(Ye))),T==="project"&&M&&(ae=ae.filter(Ye=>Ye.projectId===M)),it.size>0&&(ae=ae.filter(Ye=>Ye.projectId&&it.has(Ye.projectId))),ht.size>0){const Ye=e?.id;ae=ae.filter(lt=>ht.has(lt.createdBy)||Ye!=null&&lt.createdBy===Ye||!Zr.has(lt.createdBy))}return Ve&&e?.id&&(ae=ae.filter(Ye=>Ye.createdBy===e.id)),ae},[I,rr,T,M,it,ht,Ve,e?.id,Zr]),aa=b.useCallback(ae=>Cs.filter(Ye=>M8[Ye.status]===ae.id),[Cs]),Ca=i.filter(ae=>{if(ae.id==="failed"||ae.id==="closed"){const Ye=Sa(ae),lt=aa(ae);return Ye.length+lt.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(),lt=new Set;for(const Tt of Ye)Tt.assignedAgentId&&!ae.has(Tt.status)&&(!M||Tt.projectId===M)&&lt.add(Tt.assignedAgentId);return[...L].sort((Tt,en)=>{const pr=lt.has(Tt.id)?0:1,Cn=lt.has(en.id)?0:1;return pr-Cn})},[L,F,M]),To=b.useMemo(()=>{const ae=new Set(["completed","failed","cancelled","archived"]),Ye=Object.values(F).flat(),lt=new Set;for(const Tt of Ye)Tt.projectId&&!ae.has(Tt.status)&&lt.add(Tt.projectId);return[...N].sort((Tt,en)=>{const pr=Tt.status==="archived"?1:0,Cn=en.status==="archived"?1:0;if(pr!==Cn)return pr-Cn;const Et=lt.has(Tt.id)?0:1,Ds=lt.has(en.id)?0:1;return Et!==Ds?Et-Ds:Tt.name.localeCompare(en.name)})},[N,F]),ui=b.useMemo(()=>{const ae={};for(const Ye of Object.values(F))for(const lt of Ye){const Tt=lt.projectId??"__none__";ae[Tt]=(ae[Tt]??0)+1}return ae},[F]),Ki=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=!!(at||Je),Ni=!u&&!!(at&&Je);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:[X&&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:X}),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,{}),sn?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:sn.name}),n.jsx("button",{onClick:()=>or(sn.id),className:`w-6 h-6 flex items-center justify-center rounded-md transition-colors shrink-0 ${P?"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:()=>{nt(M??""),Y(!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:()=>dn(ae),className:`px-2 py-0.5 text-[10px] font-medium transition-colors ${$n===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:()=>Ln(ae=>!ae),className:`text-[10px] shrink-0 px-2 py-0.5 rounded-md transition-colors ${rr?"bg-surface-overlay text-fg-secondary":"text-fg-tertiary"}`,children:rr?s("work:task.hideArchived"):s("work:task.archivedCount",{count:Ys})}),n.jsx("div",{className:"flex-1"}),Qn&&n.jsxs("button",{onClick:()=>Vn(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.${Qn==="in_progress"?"inProgress":Qn}`),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"})]})]}),(it.size>0||ht.size>0||Ve||N.length>1||L.length>0)&&n.jsxs("button",{onClick:()=>br(!0),className:`px-2 py-1 text-[11px] rounded-md font-medium transition-colors flex items-center gap-1 ${it.size>0||ht.size>0||Ve?"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"})}),it.size+ht.size+(Ve?1:0)>0?s("work:task.filterWithCount",{count:it.size+ht.size+(Ve?1:0)}):s("work:task.filter")]})]})]}):n.jsxs("div",{className:"flex items-center gap-3 px-6 h-14 shrink-0",children:[sn?n.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[n.jsx(sj,{value:sn.name,onSave:async ae=>{await de.projects.update(sn.id,{name:ae}),Lr()},className:"text-sm font-semibold text-fg-primary"}),n.jsx("button",{onClick:()=>or(sn.id),className:`w-6 h-6 flex items-center justify-center rounded-md transition-colors ${P?"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:()=>Ln(ae=>!ae),className:`text-[10px] shrink-0 px-2 py-0.5 rounded-md transition-colors ${rr?"bg-surface-overlay text-fg-secondary":"text-fg-tertiary hover:text-fg-secondary"}`,children:rr?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:()=>dn(ae),className:`px-2.5 py-1 text-[10px] font-medium transition-colors ${$n===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:()=>{nt(M??""),Y(!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&&!P&&(Ki>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:()=>Vt(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 ${it.size>0?"visible opacity-100":"invisible opacity-0"}`,children:s("work:task.clear")}),To.map(ae=>{const Ye=it.has(ae.id),lt=ui[ae.id]??0,Tt=P&&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:()=>Ar(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,lt>0&&n.jsx("span",{className:"text-[9px] text-fg-tertiary ml-0.5",children:lt})]}),Ye&&n.jsx("button",{onClick:()=>or(ae.id),className:`px-1.5 py-1 self-stretch flex items-center border-l border-brand-500/20 transition-colors ${Tt?"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)&&!P&&(Ki>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:()=>{xt(new Set),ut(!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 ${ht.size>0||Ve?"visible opacity-100":"invisible opacity-0"}`,children:s("work:task.clear")}),e?.id&&n.jsx("button",{type:"button",onClick:()=>ut(ae=>!ae),className:`flex items-center gap-1.5 px-2.5 py-1 rounded-md text-[11px] shrink-0 transition-all ${Ve?"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=ht.has(ae.id);return n.jsxs("button",{onClick:()=>Qr(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)})]}),P&&vn?n.jsxs("div",{className:"flex-1 overflow-y-auto",children:[!sn&&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:Pn,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(sj,{value:vn.name,onSave:async ae=>{await de.projects.update(vn.id,{name:ae}),Lr()},className:"text-sm font-semibold text-fg-primary truncate min-w-0"})]}),n.jsx($ne,{project:vn,tasks:Object.values(F).flat(),requirements:I,agents:L,onDeleteProject:()=>wa(vn.id),onUpdateProject:async ae=>{await de.projects.update(vn.id,ae)},onRefresh:()=>{Lr()}})]}):Ki===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")})]})}):$n==="backlog"?n.jsx("div",{className:"flex-1 min-h-0 flex flex-col",onTouchStart:u?nr.onTouchStart:void 0,onTouchEnd:u?nr.onTouchEnd:void 0,children:n.jsx(Une,{tasks:Sn(Object.values(F).flat()),requirements:Cs,agents:L,projects:N,onTaskClick:ae=>Yr(ae),onReqClick:ae=>$s(ae),onRefresh:()=>{_t(),dr()},selectedTaskId:at?.id,selectedReqId:Je?.id})}):$n==="dag"?n.jsxs("div",{className:"flex-1 min-h-0 flex flex-col relative",onTouchStart:u?nr.onTouchStart:void 0,onTouchEnd:u?nr.onTouchEnd:void 0,children:[n.jsx(Nne,{tasks:(()=>{const ae=Sn(Object.values(F).flat(),!0);if(t&&Je){const Ye=new Set(Je.taskIds??[]);return ae.filter(lt=>Ye.has(lt.id))}return ae})(),requirements:t&&Je?[Je]:Cs,agents:L,showArchived:rr,onShowArchivedChange:Ln,onTaskClick:ae=>Yr(ae),onReqClick:ae=>$s(ae),onCollapseDAG:()=>{ct(null),rt(null)},onDependencyChange:_t,selectedTaskId:at?.id,selectedReqId:Je?.id,hasDetailPanel:Ta,defaultExpandedNodeId:t&&Je?`req-${Je.id}`:void 0,previewMode:t}),u&&n.jsx("button",{onClick:()=>dn("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?xr.onTouchStart:void 0,onTouchEnd:u?xr.onTouchEnd:void 0,children:n.jsx("div",{className:"flex gap-3 h-full",children:Ca.map(ae=>{const Ye=Sa(ae),lt=aa(ae),Tt=Ye.length+lt.length,en=mn===ae.id;return n.jsxs("div",{className:`w-[280px] shrink-0 rounded-xl flex flex-col h-full transition-colors ${en?"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=>{Wa(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:Tt})]}),n.jsx("div",{className:"space-y-2 flex-1 min-h-0 overflow-y-auto scrollbar-thin px-2 py-2",children:(()=>{const pr=[...lt.map(Cn=>({kind:"req",data:Cn,time:new Date(Cn.updatedAt??Cn.createdAt).getTime()})),...Ye.map(Cn=>({kind:"task",data:Cn,time:new Date(Cn.updatedAt??Cn.createdAt??0).getTime()}))];return pr.sort((Cn,Et)=>Et.time-Cn.time),pr.map(Cn=>{if(Cn.kind==="req"){const Et=Cn.data,Ds=d[Et.status]??{label:Et.status,cls:"bg-gray-500/15 text-fg-secondary"},Fs=Et.source==="agent"&&Et.status==="pending",qr=T==="all"&&Et.projectId?N.find(Ze=>Ze.id===Et.projectId):null,ie=bd(Et.createdBy,L,W)??Et.createdBy.slice(0,10),_e=Je?.id===Et.id;return n.jsxs("div",{role:"button",tabIndex:0,draggable:!0,onDragStart:Ze=>Ns(Ze,Et),onDragEnd:Gs,onClick:()=>$s(Et),onKeyDown:Ze=>Ze.key==="Enter"&&$s(Et),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
- ${_e?"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 ${Ds.cls}`,children:Ds.label})]}),n.jsx("div",{className:"text-[13px] font-medium leading-snug text-fg-primary line-clamp-2 mb-1",children:Et.title}),Et.description&&n.jsx("div",{className:"text-[11px] text-fg-tertiary line-clamp-1 mb-1.5",children:Et.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:[qr&&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:qr.name,children:qr.name}),n.jsx("span",{className:"text-[10px] text-fg-tertiary",children:Et.priority}),n.jsxs("span",{className:"text-[10px] text-fg-quaternary",children:["by ",ie]})]}),n.jsx("div",{className:"flex items-center gap-1",children:Et.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:["📋 ",Et.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:Ze=>{Ze.stopPropagation(),Xr(Et.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:Ze=>{Ze.stopPropagation(),Rt(Et.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-${Et.id}`)}else{const Et=Cn.data,Ds=Et.subtasks?.length??0,Ls=l[Et.status],Fs=Et.status==="pending",qr=Et.taskType==="scheduled"&&!!Et.scheduleConfig,ie=qr?Et.scheduleConfig.every?s("work:task.everyInterval",{interval:Et.scheduleConfig.every}):Et.scheduleConfig.cron?s("work:task.cronLabel"):s("work:task.scheduledShort"):null,_e=T==="all"&&Et.projectId?N.find(bs=>bs.id===Et.projectId)?.name:null,Ze=Et.requirementId?I.find(bs=>bs.id===Et.requirementId)?.title:null,An=Et.createdBy?bd(Et.createdBy,L,W)??Et.createdBy:null,ia=at?.id===Et.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":Et.title,draggable:!Fs,onDragStart:bs=>!Fs&&ja(bs,Et),onDragEnd:Gs,onClick:()=>Yr(Et),onKeyDown:bs=>bs.key==="Enter"&&Yr(Et),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":qr?"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[Et.priority]??"bg-gray-400"}`,title:Et.priority}),qr&&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"})})}),qr&&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:Et.title}),Et.description&&n.jsx("div",{className:"text-[11px] text-fg-tertiary line-clamp-1 mb-1.5",children:Et.description}),(_e||Ze||Et.blockedBy&&Et.blockedBy.length>0)&&n.jsxs("div",{className:"flex flex-wrap gap-1 mb-1.5",children:[_e&&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:_e,children:_e}),Ze&&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:Ze,children:["# ",Ze]}),Et.blockedBy&&Et.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:["⏳ ",Et.blockedBy.length," dep",Et.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:An&&n.jsxs("span",{className:"text-[10px] text-fg-quaternary",title:`by ${An}`,children:["by ",An]})}),n.jsxs("div",{className:"flex items-center gap-1.5",children:[Ds>0&&n.jsxs("span",{className:"text-[10px] text-fg-tertiary",children:["⋮ ",Ds]}),Et.notes&&Et.notes.length>0&&n.jsxs("span",{className:"text-[10px] text-fg-tertiary",children:["📝 ",Et.notes.length]}),Et.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 ${o0[L.find(bs=>bs.id===Et.assignedAgentId)?.status??""]??"bg-gray-500"}`}),L.find(bs=>bs.id===Et.assignedAgentId)?.name??Et.assignedAgentId.slice(0,8)]})]})]})]},Et.id)}})})()}),en&&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(kj,{req:Je,agents:L,projects:N,allTasks:Object.values(F).flat(),users:W,onClose:()=>{rt(null)},onApprove:ae=>{Xr(ae)},onReject:ae=>{Rt(ae)},onCancel:ae=>{ka(ae),rt(null)},onStatusChange:async(ae,Ye)=>{try{await de.requirements.updateStatus(ae,Ye),Gt(`Requirement status → ${Ye}`),Ir({requirementId:ae}),yn(),_t()}catch(lt){Gt(`Error: ${lt}`)}},onRefresh:yn,authUser:e,onTaskClick:ae=>{ct(ae)},onCreateTask:(ae,Ye)=>{ze(ae),Ye&&nt(Ye),Y(!0)},onProjectClick:Ar,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(gj,{task:at,agents:L,projects:N,requirements:I,allTasks:Object.values(F).flat(),users:W,onClose:sa,onRefresh:ji,authUser:e,scrollToComments:ur,onScrollToCommentsDone:()=>va(!1),onReqClick:ae=>{rt(Ye=>Ye?.id===ae.id?null:ae)},onProjectClick:Ar})})]}):at?n.jsx(gj,{task:at,agents:L,projects:N,requirements:I,allTasks:Object.values(F).flat(),users:W,onClose:Bs,onRefresh:ji,authUser:e,scrollToComments:ur,onScrollToCommentsDone:()=>va(!1),onReqClick:ae=>{rt(Ye=>Ye?.id===ae.id?null:ae)},onProjectClick:Ar}):Je?n.jsx(kj,{req:Je,agents:L,projects:N,allTasks:Object.values(F).flat(),users:W,onClose:Bs,onApprove:ae=>{Xr(ae)},onReject:ae=>{Rt(ae)},onCancel:ae=>{ka(ae),Bs()},onStatusChange:async(ae,Ye)=>{try{await de.requirements.updateStatus(ae,Ye),Gt(`Requirement status → ${Ye}`),Ir({requirementId:ae}),yn(),_t()}catch(lt){Gt(`Error: ${lt}`)}},scrollToComments:ur,onScrollToCommentsDone:()=>va(!1),onRefresh:yn,authUser:e,onTaskClick:ae=>{ct(ae),u&&(C(!0),history.pushState({mobileDetail:Te.WORK},"",window.location.hash))},onCreateTask:(ae,Ye)=>{ze(ae),Ye&&nt(Ye),Y(!0)},onProjectClick:Ar,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:()=>{Y(!1),Ke("")},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=>be(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:De,onChange:ae=>He(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:Qe,onChange:ae=>{nt(ae),ze("")},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"&&(!Qe||ae.projectId===Qe)).map(ae=>({value:ae.id,label:ae.title}))],value:gt,onChange:ze,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:Oe,onChange:Ee,placeholder:s("work:task.selectAgent"),noMatchesText:s("work:task.noMatches")})]}),n.jsxs("div",{children:[n.jsxs("label",{className:"block text-sm text-fg-secondary mb-1.5",children:[s("work:task.reviewerRequired")," ",n.jsx("span",{className:"text-red-500",children:"*"})]}),n.jsx(ku,{options:[...W.map(ae=>({value:`human:${ae.id}`,label:ae.name})),...L.filter(ae=>ae.id!==Oe).map(ae=>({value:`agent:${ae.id}`,label:`${ae.name} (${ae.status})`}))],value:fe,onChange:Le,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:ke,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:ce,onAdd:ae=>ue([...ce,ae]),placeholder:s("work:task.selectDependency"),noMatchesText:s("work:task.noMatches")}),ce.length>0&&n.jsx("div",{className:"mt-2 flex flex-wrap gap-1.5",children:ce.map(ae=>{const Ye=Object.values(F).flat().find(lt=>lt.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:()=>ue(ce.filter(lt=>lt!==ae)),className:"ml-0.5 text-amber-600/60 hover:text-amber-600",children:"×"})]},ae)})})]}),Se&&n.jsx("div",{className:"px-3 py-2 bg-red-500/15 text-red-500 text-xs rounded-lg",children:Se}),n.jsxs("div",{className:"flex justify-end gap-3 pt-1",children:[n.jsx("button",{onClick:()=>{Y(!1),Ke("")},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()||!Oe||!fe,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")})]})]})}),pn&&n.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 p-3",onClick:()=>{on(!1),Nr(""),Ce(""),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:Wt,onChange:qt,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:Dr,onChange:ae=>Nr(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"&&Dr.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:rn,onChange:ae=>Ce(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:Ct,onChange:ae=>$t(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")})]})]}),Jn&&n.jsx("div",{className:"px-3 py-2 bg-red-500/15 text-red-500 text-xs rounded-lg",children:Jn}),n.jsxs("div",{className:"flex justify-end gap-3 pt-1",children:[n.jsx("button",{onClick:()=>{on(!1),Nr(""),Ce(""),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:!Dr.trim()||!rn.trim()||!Wt,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")})]})]})}),Ne&&n.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 p-3",onClick:()=>{Rt(null),bt("")},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:Dt,onChange:ae=>Jt(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})]}),Xe&&n.jsx("div",{className:"px-3 py-2 bg-red-500/15 text-red-500 text-xs rounded-lg",children:Xe}),n.jsxs("div",{className:"flex justify-end gap-3",children:[n.jsx("button",{onClick:()=>{Rt(null),bt("")},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:()=>{Rs()},className:"px-4 py-2 text-sm bg-red-600 hover:bg-red-500 rounded-lg text-white",children:s("work:task.reject")})]})]})}),Zn&&n.jsxs("div",{className:"fixed inset-0 z-[60] flex flex-col justify-end",onClick:()=>br(!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:[(it.size>0||ht.size>0||Ve)&&n.jsx("button",{onClick:()=>{Vt(new Set),xt(new Set),ut(!1)},className:"text-[11px] text-brand-500 font-medium",children:s("work:task.clearAll")}),n.jsx("button",{onClick:()=>br(!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=it.has(ae.id),lt=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:()=>Ar(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,lt>0&&n.jsx("span",{className:"text-[9px] text-fg-tertiary",children:lt})]}),Ye&&n.jsx("button",{onClick:()=>{br(!1),or(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:()=>ut(ae=>!ae),className:`w-full text-left px-2.5 py-1.5 rounded-lg text-[11px] transition-all ${Ve?"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=ht.has(ae.id);return n.jsxs("button",{onClick:()=>Qr(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),de.requirements.getComments(e).then(k=>d(k.comments)).catch(()=>{})},[e]),b.useEffect(()=>fn.on("requirement:comment",N=>{if(N.payload?.requirementId===e&&N.payload.comment){const j=N.payload.comment;d(T=>T.some(D=>D.id===j.id)?T:[...T,j]),(j.authorType==="agent"||j.authorId?.startsWith("agt_"))&&(m(T=>{const D=T.filter(M=>M.id!==j.authorId);return D.length===0&&p.current&&(clearTimeout(p.current),p.current=null),D}),y(T=>{const D=new Map(T);return D.delete(j.authorId),D}))}}),[e]),b.useEffect(()=>{if(u.length===0)return;const k=new Set(u.map(j=>j.id));return fn.on("agent:activity_log",j=>{const T=j.payload;if(!T)return;const D=T.agentId;if(!k.has(D))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(D)??[],F];return L.set(D,U),L})}})},[u]);const[g,v]=b.useState(null),S=async(k,N,j,T)=>{let D;j.length>0&&(D=(await de.uploads.upload(j.map(L=>({dataUrl:L.dataUrl,name:L.name})),"comments")).files.map(L=>({type:"image",url:L.url,name:L.name}))),await de.requirements.addComment(e,k,a?.name,D,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(zu,{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(Te.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(Sh,{activities:N,isActive:!0})})]},k.id)})})]}),n.jsx(jS,{agents:r,humans:s,onSubmit:S,replyTo:g,onCancelReply:()=>v(null)})]})}function kj({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(()=>py(N),[N]),T=b.useMemo(()=>E8(N),[N]),D=js(),[M,_]=b.useState(!1),[F,z]=b.useState(e.description),[L,U]=b.useState(!1),[W,q]=b.useState(!1),I=b.useRef(null),[R,E]=b.useState("none"),$=b.useRef(null),X=b.useRef(null),K=b.useRef(80);b.useEffect(()=>{const Y=I.current;if(!Y)return;const me=()=>{const{scrollTop:De,scrollHeight:He,clientHeight:ke}=Y;if(!(He>ke+50)){E("none");return}const Oe=De<30,Ee=De+ke>=He-30;E(Oe?"top":Ee?"bottom":"middle")};me(),Y.addEventListener("scroll",me,{passive:!0});const be=new ResizeObserver(me);return be.observe(Y),()=>{Y.removeEventListener("scroll",me),be.disconnect()}},[]),b.useEffect(()=>{if(M&&X.current){const Y=X.current;Y.style.height="auto",Y.style.height=Math.max(Y.scrollHeight,K.current)+"px",Y.focus()}},[M]),b.useEffect(()=>{if(!y)return;const Y=setTimeout(()=>{const me=I.current;me&&me.scrollTo({top:me.scrollHeight,behavior:"smooth"}),g?.()},300);return()=>clearTimeout(Y)},[y,g]);const P=j[e.status]??{label:e.status,cls:"bg-gray-500/15 text-fg-secondary"},B=e.source==="agent",Z=B&&e.status==="pending",H=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(Y=>Y.id===e.projectId):null,ee=bd(e.createdBy,t,a)??e.createdBy.slice(0,12),se=s.filter(Y=>e.taskIds.includes(Y.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:[D&&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 ${P.cls}`,children:P.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:X,value:F,onChange:Y=>{z(Y.target.value);const me=Y.target;me.style.height="auto",me.style.height=me.scrollHeight+"px"},onBlur:async()=>{if(F!==e.description){U(!0);try{await de.requirements.update(e.id,{description:F}),p?.()}catch{}finally{U(!1)}}_(!1)},onKeyDown:Y=>{Y.key==="Escape"&&(Y.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:()=>{K.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:Y=>Y.key==="Enter"&&(z(e.description),_(!0)),children:e.description?n.jsx(Vr,{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}),B&&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?Y=>Y.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:bd(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(Y=>n.jsxs("span",{className:"text-[10px] bg-surface-elevated text-fg-secondary px-2 py-0.5 rounded-full",children:["#",Y]},Y))}),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 Y=new Map(se.map(pe=>[pe.id,pe]));if(!se.some(pe=>pe.blockedBy?.some(Oe=>Y.has(Oe))))return n.jsx("div",{className:"space-y-1.5",children:se.map(pe=>{const Oe=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 ${o0[pe.status]??"bg-gray-500"}`}),n.jsx("span",{className:"text-xs text-fg-secondary flex-1 truncate",children:pe.title}),Oe&&n.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded shrink-0 ${Oe.cls}`,children:Oe.label})]},pe.id)})});const be=new Map,De=new Set;for(const pe of se)for(const Oe of pe.blockedBy??[])if(Y.has(Oe)){De.add(pe.id);const Ee=be.get(Oe)??[];Ee.push(pe.id),be.set(Oe,Ee)}const He=se.filter(pe=>!De.has(pe.id)),ke=(pe,Oe)=>{const Ee=T[pe.status],fe=(be.get(pe.id)??[]).map(Le=>Y.get(Le)).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:Oe>0?{marginLeft:Oe*20}:void 0,children:[Oe>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 ${o0[pe.status]??"bg-gray-500"}`}),n.jsx("span",{className:"text-xs text-fg-secondary flex-1 truncate",children:pe.title}),Ee&&n.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded shrink-0 ${Ee.cls}`,children:Ee.label})]}),fe.map(Le=>ke(Le,Oe+1))]},pe.id)};return n.jsx("div",{className:"space-y-1.5",children:He.map(pe=>ke(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(D8,{entityType:"requirement",entityId:e.id})]}),R!=="none"&&R!=="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"})})}),R!=="none"&&R!=="bottom"&&n.jsx("button",{onClick:()=>{const Y=I.current;Y&&Y.scrollTo({top:Y.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:Y=>{Y.target.value!==e.status&&m(e.id,Y.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(Y=>{const me=j[Y],be=Y===e.status||(t1[e.status]?.has(Y)??!1);return n.jsx("option",{value:Y,disabled:!be,children:me?.label??Y},Y)})}),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"}),H&&!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")})]}),W&&n.jsx(Xc,{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 D8({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"?de.tasks.getHistory:de.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 Ri(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 Kne(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 Wne({artifact:e,mode:t}){const{t:r}=kt(["builder","common"]),s=Kne(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=Ri(l?.env),g=Ri(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"})]}),Ri(e.tags).length>0&&n.jsx("div",{className:"flex flex-wrap gap-1",children:Ri(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"})}),Ri(e.tags).length>0&&n.jsx("div",{className:"flex flex-wrap gap-1",children:Ri(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)]})]}),Ri(p.skills).length>0&&n.jsx("div",{className:"mt-1 ml-7 flex flex-wrap gap-1",children:Ri(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}),Ri(e.tags).length>0&&n.jsx("div",{className:"flex flex-wrap gap-1",children:Ri(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 qc={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"}},jj=["file","directory"];function cf(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 Nj({authUser:e,previewMode:t,previewData:r}={}){const{t:s}=kt(["deliverables","common"]),a=js(),i=yd(Te.DELIVERABLES),l=Qu({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 Ne=()=>{m.current&&u(!1)};return window.addEventListener("popstate",Ne),()=>window.removeEventListener("popstate",Ne)},[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??[]),[D,M]=b.useState(!r),[_,F]=b.useState(""),[z,L]=b.useState(""),[U,W]=b.useState(""),[q,I]=b.useState(""),[R,E]=b.useState(""),[$,X]=b.useState(""),[K,P]=b.useState(""),[B,Z]=b.useState("date"),[H,J]=b.useState(()=>r?.initialSelectedId&&r.items?r.items.find(Ne=>Ne.id===r.initialSelectedId)??r.items[0]??null:r?.items?.[0]??null),[Q,ee]=b.useState(null),[se,Y]=b.useState(""),[me,be]=b.useState(!1),[De,He]=b.useState(!1),[ke,pe]=b.useState(new Set),Oe=b.useMemo(()=>[{id:"date"},{id:"project"},{id:"agent"},{id:"type"}],[]),Ee=b.useCallback(Ne=>{Z(Ne),pe(new Set)},[]),fe=hl(Oe,B,Ee),Le=b.useRef(null),[Qe,nt]=b.useState("file"),[gt,ze]=b.useState(""),[ce,ue]=b.useState(""),[Me,ne]=b.useState(""),[he,Be]=b.useState(""),[Se,Ke]=b.useState(""),[at,ct]=b.useState(null),[Je,rt]=b.useState("markdown"),[ht,xt]=b.useState(null),[Ve,ut]=b.useState(!1),[it,Vt]=b.useState(!1),[Nn,Un]=b.useState(!1),[mn,Tn]=b.useState(null),[$n,dn]=b.useState(""),[bn,nr]=b.useState(new Set),ir=b.useRef(void 0),jr=(Ne,Rt)=>{ee({type:Ne,text:Rt}),setTimeout(()=>ee(null),3e3)},xr=async Ne=>{await F1(Ne)?(Un(!0),setTimeout(()=>Un(!1),1500)):jr("error",s("detail.copyFailed"))},rr=b.useMemo(()=>new Map(j.map(Ne=>[Ne.id,Ne])),[j]),Ln=b.useMemo(()=>new Map(k.map(Ne=>[Ne.id,Ne])),[k]);b.useEffect(()=>{t||(de.projects.list().then(Ne=>N(Ne.projects)).catch(()=>{}),de.agents.list().then(Ne=>T(Ne.agents??[])).catch(()=>{}),de.system.storage().then(Ne=>dn(Ne.dataDir+"/shared")).catch(()=>{}),de.deliverables.checkHealth().then(Ne=>nr(new Set(Ne.missingFiles))).catch(()=>{}))},[t]),b.useEffect(()=>(ir.current=setTimeout(()=>L(_),300),()=>clearTimeout(ir.current)),[_]);const Qn=b.useMemo(()=>({q:z||void 0,projectId:q||void 0,agentId:R||void 0,type:U||void 0,status:$||void 0,artifactType:K||void 0}),[z,q,R,U,$,K]),Vn=b.useCallback(async()=>{M(!0);try{const{results:Ne,total:Rt}=await de.deliverables.search({...Qn,offset:0,limit:p});y(Ne),v(Rt)}catch{y([]),v(0)}M(!1)},[Qn]),Zn=b.useCallback(async()=>{if(!(S||h.length>=g)){C(!0);try{const{results:Ne,total:Rt}=await de.deliverables.search({...Qn,offset:h.length,limit:p});y(Dt=>[...Dt,...Ne]),v(Rt)}catch{}C(!1)}},[Qn,h.length,g,S]);b.useEffect(()=>{t||Vn()},[Vn,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(Ne=>Ne.id===r.initialSelectedId)??r.items?.[0]??null))},[t,r]),b.useEffect(()=>{if(t||!i)return;const Ne=fn.on("deliverable:created",()=>Vn()),Rt=fn.on("deliverable:updated",()=>Vn()),Dt=fn.on("deliverable:removed",()=>Vn());return()=>{Ne(),Rt(),Dt()}},[Vn,i,t]);const br=b.useRef(null),Bn=b.useRef(h);Bn.current=h;const Xt=b.useCallback(Ne=>{const Rt=Jt=>{J(Jt),a&&(u(!0),history.pushState({mobileDetail:Te.DELIVERABLES},"",window.location.hash))},Dt=Bn.current.find(Jt=>Jt.id===Ne);if(Dt){Rt(Dt);return}de.deliverables.get(Ne).then(Jt=>{Jt.deliverable&&Rt(Jt.deliverable)}).catch(()=>{})},[a]);b.useEffect(()=>{if(t)return;const Ne=localStorage.getItem("markus_nav_openDeliverable");Ne&&(localStorage.removeItem("markus_nav_openDeliverable"),Bn.current.length>0?Xt(Ne):br.current=Ne);const Rt=Dt=>{const Jt=Dt.detail;Jt?.params?.openDeliverable&&(localStorage.removeItem("markus_nav_openDeliverable"),Xt(Jt.params.openDeliverable))};return window.addEventListener("markus:navigate",Rt),()=>window.removeEventListener("markus:navigate",Rt)},[Xt,t]),b.useEffect(()=>{const Ne=br.current;!Ne||h.length===0||(br.current=null,Xt(Ne))},[h,Xt]);const pn=b.useCallback(()=>{const Ne=Le.current;!Ne||D||S||h.length>=g||Ne.scrollHeight<=Ne.clientHeight+100&&Zn()},[D,S,h.length,g,Zn]);b.useEffect(()=>{const Ne=Le.current;if(!Ne)return;const Rt=()=>{Ne.scrollTop+Ne.clientHeight>=Ne.scrollHeight-100&&Zn()};return Ne.addEventListener("scroll",Rt,{passive:!0}),()=>Ne.removeEventListener("scroll",Rt)},[Zn]),b.useEffect(()=>{pn()},[pn,ke]);const on=b.useMemo(()=>{const Ne=new Map;for(const Dt of h){let Jt,Jn;if(B==="project")Jt=Dt.projectId??"_none",Jn=Dt.projectId?Ln.get(Dt.projectId)?.name??Dt.projectId:s("noProject");else if(B==="agent")Jt=Dt.agentId??"_none",Jn=Dt.agentId?rr.get(Dt.agentId)?.name??Dt.agentId:s("common:unknown");else if(B==="type")Jt=Dt.type,Jn=Dt.type.charAt(0).toUpperCase()+Dt.type.slice(1);else{const xe=new Date(Dt.updatedAt);Jt=`${xe.getFullYear()}-${String(xe.getMonth()+1).padStart(2,"0")}-${String(xe.getDate()).padStart(2,"0")}`,Jn=Jt}Ne.has(Jt)||Ne.set(Jt,{label:Jn,items:[]}),Ne.get(Jt).items.push(Dt)}const Rt=[...Ne.entries()];return B==="date"?Rt.sort((Dt,Jt)=>Jt[0].localeCompare(Dt[0])):Rt.sort((Dt,Jt)=>Dt[1].label.localeCompare(Jt[1].label)),Rt},[h,B,Ln,rr,s]),Dr=async()=>{if(!(!gt.trim()||!ce.trim())){He(!0);try{await de.deliverables.create({type:Qe,title:gt,summary:ce,reference:Me,projectId:he||void 0,tags:Se.split(",").map(Ne=>Ne.trim()).filter(Boolean)}),be(!1),jr("success",s("createModal.created")),Vn()}catch(Ne){jr("error",s("common:error",{message:String(Ne)}))}He(!1)}},Nr=async Ne=>{Y("remove");try{await de.deliverables.remove(Ne.id),jr("success",s("removed")),J(null),Vn()}catch(Rt){jr("error",s("common:error",{message:String(Rt)}))}Y("")},rn=()=>{Nt.navigate(Te.BUILDER)},Ce=async Ne=>{if(Ne.reference&&!cf(Ne.reference)){if(Ne.type==="directory"){Vt(!0);return}ut(!0);try{const Rt=await de.files.preview(Ne.reference);Rt.type==="image"&&Rt.mimeType?xt({src:`data:${Rt.mimeType};base64,${Rt.content}`,name:Rt.name}):(ct(Rt.content),rt(zS({format:Ne.format,reference:Ne.reference,content:Rt.content})))}catch{ct(null),Ne.type==="file"&&Vt(!0)}ut(!1)}};b.useEffect(()=>{t||(ct(null),rt("markdown"),xt(null),Vt(!1),H&&Ce(H))},[H?.id,t]);const Ct=b.useCallback(Ne=>{pe(Rt=>{const Dt=new Set(Rt);return Dt.has(Ne)?Dt.delete(Ne):Dt.add(Ne),Dt})},[]),$t=b.useCallback(()=>{ke.size===on.length?pe(new Set):pe(new Set(on.map(([Ne])=>Ne)))},[ke.size,on]),Wt=()=>{ze(""),ue(""),ne(""),Ke(""),nt("file"),k.length>0&&Be(k[0].id),be(!0)},qt=Ne=>{J(Ne),a&&(u(!0),history.pushState({mobileDetail:Te.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.jsxs("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("button",{onClick:Wt,className:"text-xs px-2.5 py-1 rounded-lg bg-brand-600 hover:bg-brand-500 text-white transition-colors shrink-0",children:s("create")})]}),n.jsx("input",{value:_,onChange:Ne=>F(Ne.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"}),$n&&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:$n}),n.jsx("button",{onClick:()=>{de.system.openPath($n)},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(ju,{label:s("filters.allTypes"),value:"",current:U||K||"",onClick:()=>{W(""),P("")}}),jj.map(Ne=>n.jsx(ju,{label:`${qc[Ne]?.icon??""} ${Ne}`,value:Ne,current:U,onClick:Rt=>{W(Rt),P("")}},Ne)),["agent","team","skill"].map(Ne=>n.jsx(ju,{label:`${Fl[Ne].icon} ${s(`artifactTypes.${Ne}`)}`,value:Ne,current:K,onClick:Rt=>{P(Rt),W("")}},Ne))]}),k.length>0&&n.jsxs("div",{className:"flex gap-1 overflow-x-auto scrollbar-hide",children:[n.jsx(ju,{label:s("filters.allProjects"),value:"",current:q,onClick:I}),k.map(Ne=>n.jsx(ju,{label:Ne.name,value:Ne.id,current:q,onClick:I},Ne.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(Ne=>n.jsx("button",{onClick:()=>{Z(Ne),pe(new Set)},className:`px-2 py-1 rounded text-xs transition-colors ${B===Ne?"bg-brand-600 text-white":"bg-surface-elevated text-fg-secondary hover:bg-surface-overlay"}`,children:s(`groupBy.${Ne}`)},Ne)),on.length>1&&n.jsx("button",{onClick:$t,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:ke.size===on.length?s("expandAllTooltip"):s("collapseAllTooltip"),children:ke.size===on.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:Le,className:"flex-1 overflow-y-auto p-2 space-y-1",onTouchStart:a?fe.onTouchStart:void 0,onTouchEnd:a?fe.onTouchEnd:void 0,children:[D?n.jsx("div",{className:"p-4 space-y-3",children:[1,2,3].map(Ne=>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"})]},Ne))}):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:Wt,className:"text-xs px-3 py-1.5 rounded-lg bg-brand-600 hover:bg-brand-500 text-white transition-colors",children:s("empty.createFirst")})]}):on.map(([Ne,Rt])=>{const Dt=ke.has(Ne);return n.jsxs("div",{children:[n.jsxs("button",{onClick:()=>Ct(Ne),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 ${Dt?"":"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:Rt.label}),n.jsxs("span",{className:"text-[10px] text-fg-tertiary shrink-0",children:["(",Rt.items.length,")"]})]}),!Dt&&Rt.items.map(Jt=>n.jsx("button",{onClick:()=>qt(Jt),className:`w-full text-left px-3 py-2 rounded-lg transition-colors ${H?.id===Jt.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:[Jt.artifactType&&Fl[Jt.artifactType]?n.jsx("span",{className:`text-[10px] px-1 py-0.5 rounded font-medium shrink-0 ${Fl[Jt.artifactType].color}`,children:Fl[Jt.artifactType].icon}):n.jsx("span",{className:`text-[10px] px-1 py-0.5 rounded font-medium uppercase shrink-0 ${qc[Jt.type]?.color??"bg-surface-overlay text-fg-secondary"}`,children:qc[Jt.type]?.icon??Jt.type.charAt(0)}),n.jsx("span",{className:"text-sm font-medium text-fg-primary truncate",children:Jt.title}),bn.has(Jt.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[Jt.status]?.color??"bg-surface-elevated text-fg-tertiary"}`,children:s(`common:status.${Jt.status}`,{defaultValue:Jt.status})})]})},Jt.id))]},Ne)}),S&&n.jsxs("div",{className:"flex items-center justify-center gap-2 py-3 text-fg-tertiary",children:[n.jsx(Vx,{})," ",n.jsx("span",{className:"text-[10px]",children:s("common:loadingMore")})]}),!D&&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:H?.title??s("detail.details")})]}),H?n.jsxs("div",{className:"p-6 space-y-4",children:[!t&&bn.has(H.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:H.title}),!t&&n.jsx("button",{onClick:()=>Tn(H),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 ${qc[H.type]?.color??"bg-surface-overlay text-fg-secondary"}`,children:[qc[H.type]?.icon??""," ",H.type]}),H.artifactType&&Fl[H.artifactType]&&n.jsxs("span",{className:`px-2 py-0.5 rounded text-xs font-medium ${Fl[H.artifactType].color}`,children:[Fl[H.artifactType].icon," ",s("detail.builderWithType",{type:s(`artifactTypes.${H.artifactType}`)})]}),H.tags.length>0&&H.tags.map(Ne=>n.jsx("span",{className:"px-2 py-0.5 text-xs bg-surface-elevated text-fg-secondary rounded",children:Ne},Ne))]}),(H.taskId||H.agentId||H.projectId)&&n.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[H.taskId&&n.jsx("button",{onClick:()=>Nt.navigate(Te.WORK,{openTask:H.taskId}),className:"text-xs text-brand-500 hover:underline bg-brand-500/10 px-2 py-0.5 rounded",children:s("links.task",{id:`${H.taskId.slice(0,12)}...`})}),H.agentId&&n.jsx("button",{onClick:()=>Nt.navigate(Te.TEAM,{selectAgent:H.agentId}),className:"text-xs text-blue-600 hover:underline bg-blue-500/10 px-2 py-0.5 rounded",children:s("links.agent",{name:rr.get(H.agentId)?.name??H.agentId.slice(0,12)})}),H.projectId&&n.jsx("button",{onClick:()=>Nt.navigate(Te.WORK,{projectId:H.projectId}),className:"text-xs text-blue-600 hover:underline bg-blue-500/10 px-2 py-0.5 rounded",children:s("links.project",{name:Ln.get(H.projectId)?.name??H.projectId.slice(0,12)})})]}),(H.diffStats||H.testResults)&&n.jsxs("div",{className:"flex gap-3 flex-wrap",children:[H.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:H.diffStats.filesChanged})}),n.jsxs("span",{className:"text-green-600",children:["+",H.diffStats.additions]}),n.jsxs("span",{className:"text-red-500",children:["-",H.diffStats.deletions]})]}),H.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:H.testResults.passed})}),n.jsx("span",{className:"text-red-500",children:s("testResults.failed",{count:H.testResults.failed})}),n.jsx("span",{className:"text-fg-secondary",children:s("testResults.skipped",{count:H.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(H.createdAt).toLocaleDateString()]}),n.jsxs("span",{children:[s("metadata.updated")," ",new Date(H.updatedAt).toLocaleDateString()]}),n.jsx("span",{className:"text-fg-muted select-all",children:H.id.slice(0,12)})]}),H.reference&&!cf(H.reference)&&H.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:()=>{de.files.reveal(H.reference).catch(()=>jr("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:H.reference}),n.jsx("button",{onClick:()=>{de.files.reveal(H.reference).catch(()=>jr("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:()=>xr(H.reference),className:`px-2 py-1 text-[10px] rounded transition-colors shrink-0 ${Nn?"bg-green-500/20 text-green-600":"bg-surface-overlay/50 text-fg-secondary hover:bg-surface-overlay"}`,title:s("detail.copyPath"),children:s(Nn?"common:copied":"common:copy")})]}),H.reference&&!cf(H.reference)&&H.type!=="file"&&H.type!=="directory"&&n.jsx("span",{className:"text-xs text-fg-tertiary font-mono break-all",children:H.reference})]}),H.artifactType&&H.artifactData?n.jsxs("div",{className:"space-y-4",children:[n.jsx("div",{className:"bg-surface-elevated rounded-xl p-5",children:n.jsx(Wne,{artifact:H.artifactData,mode:H.artifactType})}),H.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:H.reference})]}),n.jsx("div",{className:"flex gap-2",children:n.jsx("button",{onClick:rn,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")})}),H.summary&&n.jsx("div",{className:"bg-surface-elevated rounded-xl p-5",children:n.jsx(Vr,{content:H.summary,className:"text-fg-secondary text-sm"})})]}):H.reference&&cf(H.reference)?n.jsxs("div",{className:"space-y-4",children:[H.summary&&n.jsx("div",{className:"bg-surface-elevated rounded-xl p-5",children:n.jsx(Vr,{content:H.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:H.reference}),n.jsx("button",{onClick:()=>window.open(H.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")})]})]}):H.type==="directory"&&H.reference?n.jsxs("div",{className:"space-y-4",children:[H.summary&&n.jsx("div",{className:"bg-surface-elevated rounded-xl p-5",children:n.jsx(Vr,{content:H.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:H.reference}),n.jsx("button",{onClick:()=>{de.files.reveal(H.reference).catch(()=>jr("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:Ve?n.jsxs("div",{className:"flex items-center gap-2 text-fg-tertiary text-sm",children:[n.jsx(Vx,{})," ",s("detail.loadingPreview")]}):ht?n.jsxs("div",{className:"flex flex-col items-center gap-2",children:[n.jsx("img",{src:ht.src,alt:ht.name,className:"max-w-full max-h-[60vh] rounded-lg object-contain"}),n.jsx("span",{className:"text-xs text-fg-tertiary",children:ht.name})]}):at?n.jsx(Y1,{content:at,format:Je,className:"text-fg-secondary text-sm"}):it?n.jsxs("div",{className:"space-y-3",children:[n.jsx("p",{className:"text-sm text-fg-secondary",children:s("detail.cannotPreview",{type:H.type})}),n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx("button",{onClick:()=>{de.files.reveal(H.reference).catch(()=>jr("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:H.reference}),n.jsx("button",{onClick:()=>{de.files.reveal(H.reference).catch(()=>jr("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:()=>xr(H.reference),className:`px-3 py-2 text-xs rounded-lg transition-colors shrink-0 ${Nn?"bg-green-500/20 text-green-600":"bg-surface-overlay/50 text-fg-secondary hover:bg-surface-overlay"}`,children:s(Nn?"common:copied":"common:copy")})]})]}):H.summary?n.jsx(Vr,{content:H.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")})]})})]}),mn&&n.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60",onClick:()=>Tn(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:Ne=>Ne.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:mn.title})})]})]}),n.jsxs("div",{className:"flex justify-end gap-2",children:[n.jsx("button",{onClick:()=>Tn(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 Ne=mn;Tn(null),Nr(Ne)},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")})]})]})}),me&&n.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60",onClick:()=>!De&&be(!1),children:n.jsxs("div",{className:"bg-surface-secondary border border-border-default rounded-xl p-6 w-[36rem] space-y-4",onClick:Ne=>Ne.stopPropagation(),children:[n.jsx("h3",{className:"text-base font-semibold text-fg-primary",children:s("createModal.title")}),n.jsxs("div",{children:[n.jsx("label",{className:"text-xs text-fg-tertiary block mb-1",children:s("createModal.type")}),n.jsx("select",{value:Qe,onChange:Ne=>nt(Ne.target.value),className:"w-full bg-surface-elevated border border-border-default rounded-lg px-3 py-2 text-sm text-fg-primary",children:jj.map(Ne=>n.jsxs("option",{value:Ne,children:[qc[Ne]?.icon??""," ",Ne]},Ne))})]}),n.jsxs("div",{children:[n.jsxs("label",{className:"text-xs text-fg-tertiary block mb-1",children:[s("createModal.titleField")," ",n.jsx("span",{className:"text-red-500",children:s("createModal.required")})]}),n.jsx("input",{value:gt,onChange:Ne=>ze(Ne.target.value),placeholder:s("createModal.titlePlaceholder"),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"})]}),n.jsxs("div",{children:[n.jsxs("label",{className:"text-xs text-fg-tertiary block mb-1",children:[s("createModal.reference")," ",n.jsxs("span",{className:"text-fg-tertiary",children:["(",s("createModal.referenceHint"),")"]})]}),n.jsx("input",{value:Me,onChange:Ne=>ne(Ne.target.value),placeholder:s("createModal.referencePlaceholder"),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 font-mono"})]}),n.jsxs("div",{children:[n.jsxs("label",{className:"text-xs text-fg-tertiary block mb-1",children:[s("createModal.summary")," ",n.jsx("span",{className:"text-red-500",children:s("createModal.required")})," ",n.jsxs("span",{className:"text-fg-tertiary",children:["(",s("createModal.summaryHint"),")"]})]}),n.jsx("textarea",{value:ce,onChange:Ne=>ue(Ne.target.value),placeholder:s("createModal.summaryPlaceholder"),className:"w-full bg-surface-elevated border border-border-default rounded-lg px-3 py-2 text-sm text-fg-primary h-36 resize-none focus:border-brand-500 focus:outline-none transition-colors font-mono"})]}),n.jsxs("div",{className:"flex gap-4",children:[n.jsxs("div",{className:"flex-1",children:[n.jsxs("label",{className:"text-xs text-fg-tertiary block mb-1",children:[s("createModal.tags")," ",n.jsxs("span",{className:"text-fg-tertiary",children:["(",s("createModal.tagsHint"),")"]})]}),n.jsx("input",{value:Se,onChange:Ne=>Ke(Ne.target.value),placeholder:s("createModal.tagsPlaceholder"),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"})]}),n.jsxs("div",{className:"flex-1",children:[n.jsx("label",{className:"text-xs text-fg-tertiary block mb-1",children:s("createModal.project")}),n.jsxs("select",{value:he,onChange:Ne=>Be(Ne.target.value),className:"w-full bg-surface-elevated border border-border-default rounded-lg px-3 py-2 text-sm text-fg-primary",children:[n.jsx("option",{value:"",children:s("common:none")}),k.map(Ne=>n.jsx("option",{value:Ne.id,children:Ne.name},Ne.id))]})]})]}),n.jsxs("div",{className:"flex justify-end gap-3 pt-1 border-t border-border-default",children:[n.jsx("button",{onClick:()=>be(!1),disabled:De,className:"text-sm text-fg-tertiary hover:text-fg-secondary disabled:opacity-50 transition-colors py-2",children:s("common:cancel")}),n.jsxs("button",{onClick:Dr,disabled:De||!gt.trim()||!ce.trim(),className:"bg-brand-600 hover:bg-brand-500 text-white text-sm px-4 py-2 rounded-lg disabled:opacity-50 flex items-center gap-2 transition-colors",children:[De&&n.jsx(Vx,{}),s(De?"common:creating":"common:create")]})]})]})})]})}function ju({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 Vx(){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 Gc(e){return e<.01?`$${e.toFixed(4)}`:`$${e.toFixed(2)}`}function Yne(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 Sj({authUser:e}){const{t}=kt(["reports","common"]),r=js(),s=yd(Te.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,D]=b.useState("generate"),[M,_]=b.useState([]),[F,z]=b.useState(null),[L,U]=b.useState([]),[W,q]=b.useState(""),[I,R]=b.useState(""),E=Y=>{R(Y),setTimeout(()=>R(""),3e3)},$=b.useCallback(async Y=>{m(!0),h("");try{const{report:me}=await de.reports.generate({period:Y,scope:"org",orgId:"default"});d(me)}catch(me){h(String(me)),d(null)}m(!1)},[]),X=b.useCallback(()=>{de.usage.summary().then(Y=>g(Y.usage)).catch(()=>{}),de.usage.agents().then(Y=>S(Y.agents)).catch(()=>{})},[]),K=b.useCallback(async()=>{try{const{reports:Y}=await de.reports.list();_(Y)}catch{}},[]),P=b.useCallback(async Y=>{z(Y);try{const{feedback:me}=await de.reports.getFeedback(Y.id);U(me)}catch{U([])}},[]);b.useEffect(()=>{$(a)},[a,$]),b.useEffect(()=>{if(!s)return;X();const Y=setInterval(X,3e4);return()=>clearInterval(Y)},[X,s]),b.useEffect(()=>{T==="history"&&K()},[T,K]);const B=b.useMemo(()=>[...v].sort((Y,me)=>{const be=Y[C],De=me[C];return N?De-be:be-De}),[v,C,N]),Z=v.reduce((Y,me)=>Y+me.estimatedCost,0),H=v.reduce((Y,me)=>Y+me.tokensUsedToday,0),J=v.reduce((Y,me)=>Y+(me.costToday??0),0),Q=Math.max(1,...v.map(Y=>Y.totalTokens)),ee=Y=>{C===Y?j(!N):(k(Y),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:()=>D("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:()=>D("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(Y=>n.jsx("button",{onClick:()=>i(Y),className:`px-3 py-1.5 text-xs rounded-md transition-colors ${a===Y?"bg-surface-overlay text-fg-primary shadow-sm":"text-fg-tertiary hover:text-fg-secondary"}`,children:t(`period.${Y}`)},Y))})]})]}),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(Y=>n.jsxs("button",{onClick:()=>P(Y),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:Y.type})}),n.jsxs("div",{className:"text-xs text-fg-tertiary mt-0.5",children:[new Date(Y.periodStart).toLocaleDateString()," — ",new Date(Y.periodEnd).toLocaleDateString()]})]}),Y.plan&&n.jsx("span",{className:`px-2 py-0.5 rounded-full text-[10px] font-medium shrink-0 ${Y.plan.status==="approved"?"bg-green-500/10 text-green-600":Y.plan.status==="rejected"?"bg-red-500/10 text-red-500":"bg-amber-500/10 text-amber-600"}`,children:Y.plan.status==="pending"?t("upcomingPlan.planPending"):t("upcomingPlan.planStatus",{status:Y.plan.status})}),n.jsx("span",{className:"text-[10px] text-fg-tertiary shrink-0",children:new Date(Y.generatedAt).toLocaleDateString()})]},Y.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(Di,{label:t("taskMetrics.completed"),value:F.metrics.tasksCompleted,color:"text-green-600"}),n.jsx(Di,{label:t("taskMetrics.inProgress"),value:F.metrics.tasksInProgress,color:"text-brand-500"}),n.jsx(Di,{label:t("taskMetrics.created"),value:F.metrics.tasksCreated,color:"text-blue-600"}),n.jsx(Di,{label:t("taskMetrics.blocked"),value:F.metrics.tasksBlocked,color:"text-amber-600"}),n.jsx(Di,{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:Gc(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((Y,me)=>n.jsxs("div",{className:"flex items-center justify-between text-xs",children:[n.jsx("span",{className:"text-fg-secondary",children:Y.agentId}),n.jsx("span",{className:"text-fg-tertiary tabular-nums",children:t("costOverview.byAgentRow",{tokens:ho(Y.tokens),cost:Gc(Y.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(Uc,{title:t("taskSummary.completedCount",{count:F.taskSummary.completed.length}),color:"emerald",items:F.taskSummary.completed.map(Y=>({id:Y.id,label:Y.title,sub:Y.agent}))}),F.taskSummary.inProgress.length>0&&n.jsx(Uc,{title:t("taskSummary.inProgressCount",{count:F.taskSummary.inProgress.length}),color:"indigo",items:F.taskSummary.inProgress.map(Y=>({id:Y.id,label:Y.title,sub:Y.agent}))}),F.taskSummary.blocked.length>0&&n.jsx(Uc,{title:t("taskSummary.blockedCount",{count:F.taskSummary.blocked.length}),color:"amber",items:F.taskSummary.blocked.map(Y=>({id:Y.id,label:Y.title,sub:Y.reason||Y.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((Y,me)=>n.jsx("li",{children:Y},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((Y,me)=>n.jsx("li",{children:Y},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:Y}=await de.reports.approvePlan(F.id,{approvedBy:e?.id??"unknown"});z(Y),E(t("upcomingPlan.planApproved")),K()}catch(Y){E(t("common:error",{message:String(Y)}))}},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 Y=prompt(t("upcomingPlan.rejectionReason"));if(Y)try{const{report:me}=await de.reports.rejectPlan(F.id,{rejectedBy:e?.id??"unknown",reason:Y});z(me),E(t("upcomingPlan.planRejected")),K()}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((Y,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 ${Y.priority==="high"?"bg-red-500/10 text-red-500":Y.priority==="medium"?"bg-amber-500/10 text-amber-600":"bg-gray-500/10 text-fg-tertiary"}`,children:Y.priority}),n.jsx("span",{children:Y.title}),Y.assignee&&n.jsx("span",{className:"text-[10px] text-fg-tertiary ml-auto",children:Y.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(Y=>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:Y.authorName}),n.jsx("span",{children:Y.type}),n.jsx("span",{children:new Date(Y.createdAt).toLocaleDateString()})]}),n.jsx("p",{className:"text-xs text-fg-secondary",children:Y.content})]},Y.id))}),n.jsxs("div",{className:"flex gap-2",children:[n.jsx("input",{value:W,onChange:Y=>q(Y.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:Y=>{Y.key==="Enter"&&W.trim()&&de.reports.addFeedback(F.id,{author:e?.id??"unknown",type:"comment",content:W.trim()}).then(({feedback:me})=>{U(be=>[...be,me]),q(""),E(t("feedback.added"))}).catch(me=>E(t("common:error",{message:String(me)})))}}),n.jsx("button",{onClick:()=>{W.trim()&&de.reports.addFeedback(F.id,{author:e?.id??"unknown",type:"comment",content:W.trim()}).then(({feedback:Y})=>{U(me=>[...me,Y]),q(""),E(t("feedback.added"))}).catch(Y=>E(t("common:error",{message:String(Y)})))},disabled:!W.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(df,{label:t("usage.llmTokens"),value:ho(y.llmTokens),color:"text-brand-500"}),n.jsx(df,{label:t("usage.toolCalls"),value:ho(y.toolCalls),color:"text-blue-600"}),n.jsx(df,{label:t("usage.messages"),value:ho(y.messages),color:"text-green-600"}),y.storageBytes>0&&n.jsx(df,{label:t("usage.storage"),value:Yne(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(Di,{label:t("taskMetrics.completed"),value:l.metrics.tasksCompleted,color:"text-green-600"}),n.jsx(Di,{label:t("taskMetrics.inProgress"),value:l.metrics.tasksInProgress,color:"text-brand-500"}),n.jsx(Di,{label:t("taskMetrics.created"),value:l.metrics.tasksCreated,color:"text-blue-600"}),n.jsx(Di,{label:t("taskMetrics.blocked"),value:l.metrics.tasksBlocked,color:"text-amber-600"}),n.jsx(Di,{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:Gc(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(H)}),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:Gc(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(Uc,{title:t("taskSummary.completedCount",{count:l.taskSummary.completed.length}),color:"emerald",items:l.taskSummary.completed.map(Y=>({id:Y.id,label:Y.title,sub:Y.agent}))}),l.taskSummary.inProgress.length>0&&n.jsx(Uc,{title:t("taskSummary.inProgressCount",{count:l.taskSummary.inProgress.length}),color:"indigo",items:l.taskSummary.inProgress.map(Y=>({id:Y.id,label:Y.title,sub:Y.agent}))}),l.taskSummary.blocked.length>0&&n.jsx(Uc,{title:t("taskSummary.blockedCount",{count:l.taskSummary.blocked.length}),color:"amber",items:l.taskSummary.blocked.map(Y=>({id:Y.id,label:Y.title,sub:Y.reason||Y.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(Nu,{label:t("perAgentUsage.totalTokens"),col:"totalTokens",current:C,desc:N,onSort:ee}),n.jsx(Nu,{label:t("perAgentUsage.today"),col:"tokensUsedToday",current:C,desc:N,onSort:ee}),n.jsx(Nu,{label:t("perAgentUsage.requests"),col:"requestCount",current:C,desc:N,onSort:ee}),n.jsx(Nu,{label:t("perAgentUsage.toolCalls"),col:"toolCalls",current:C,desc:N,onSort:ee}),n.jsx(Nu,{label:t("perAgentUsage.estCost"),col:"estimatedCost",current:C,desc:N,onSort:ee,align:"right"})]})}),n.jsx("tbody",{children:B.map(Y=>n.jsx(Xne,{agent:Y,maxTokens:Q},Y.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((Y,me)=>Y+me.totalTokens,0))}),n.jsx("td",{className:"px-4 py-3 text-sm font-medium text-fg-secondary tabular-nums",children:ho(H)}),n.jsx("td",{className:"px-4 py-3 text-sm font-medium text-fg-secondary tabular-nums",children:v.reduce((Y,me)=>Y+me.requestCount,0)}),n.jsx("td",{className:"px-4 py-3 text-sm font-medium text-fg-secondary tabular-nums",children:v.reduce((Y,me)=>Y+me.toolCalls,0)}),n.jsx("td",{className:"px-4 py-3 text-sm font-medium text-right text-fg-secondary tabular-nums",children:Gc(Z)})]})})]})})]})]})})}function Di({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 Uc({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(Te.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 df({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 Nu({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 Xne({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(Te.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:Gc(e.estimatedCost)})]})}const uf={urgent:"bg-red-500",high:"bg-amber-500",normal:"bg-blue-500",low:"bg-gray-400"},Vc={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"},Cj={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 Kc(e,t){const r=Date.now()-new Date(e).getTime(),s=Math.floor(r/6e4);if(s<1)return t("common:time.now");if(s<60)return t("common:time.minutesAgo",{count:s});const a=Math.floor(s/60);return a<24?t("common:time.hoursAgo",{count:a}):t("common:time.daysAgo",{count:Math.floor(a/24)})}function mf(e,t){const r=e.actionType;if(r==="open_chat")return t("team:notifications.actionHints.openChat");if(r==="navigate")return t("team:notifications.actionHints.viewDetails");const s=e.metadata??{};switch(e.type){case"task_completed":case"task_created":case"task_review":case"task_failed":return s.taskId?t("team:notifications.actionHints.viewTask"):null;case"requirement_created":case"requirement_decision":return s.requirementId?t("team:notifications.actionHints.viewRequirement"):null;case"agent_report":return s.agentId?t("team:notifications.actionHints.viewAgent"):null;case"direct_message":return t("team:notifications.actionHints.openChat");case"group_message":return t("team:notifications.actionHints.openChat");case"approval_request":return t("team:notifications.actionHints.viewApproval");default:return s.taskId?t("team:notifications.actionHints.viewTask"):s.requirementId?t("team:notifications.actionHints.viewRequirement"):s.agentId?t("team:notifications.actionHints.viewAgent"):null}}function Qne(){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 L8({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),[D,M]=b.useState({}),[_,F]=b.useState(0),z=b.useRef(null),L=b.useRef(null),[U,W]=b.useState({top:0,left:0,width:448,maxHeight:576}),q=b.useRef(null),I=b.useRef(!1),[R,E]=b.useState(!0),[$,X]=b.useState(!1),K=b.useRef(null),P=b.useRef("approvals"),B=30,Z=b.useCallback(async()=>{try{const[ne,he]=await Promise.all([de.notifications.list(t,!1,{limit:B,offset:0}),de.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>=B),C(he.approvals),!I.current){const Be=he.approvals.filter(Se=>Se.status==="pending").length;q.current=Be,I.current=!0}}catch{}},[t]),H=b.useCallback(async()=>{if(!($||!R)){X(!0);try{const ne=await de.notifications.list(t,!1,{limit:B,offset:g.length});ne.notifications.length>0&&v(he=>[...he,...ne.notifications.filter(Be=>!he.some(Se=>Se.id===Be.id))]),E(ne.totalCount!=null?g.length+ne.notifications.length<ne.totalCount:ne.notifications.length>=B)}catch{}X(!1)}},[t,g.length,$,R]),J=b.useCallback(ne=>{const he=ne.detail;if(!he)return;const{taskId:Be,requirementId:Se}=he;!Be&&!Se||v(Ke=>{const at=Ke.filter(ct=>!ct.read&&(Be&&ct.metadata?.taskId===Be||Se&&ct.metadata?.requirementId===Se));if(at.length===0)return Ke;for(const ct of at)de.notifications.markRead(ct.id).catch(()=>{});return F(ct=>Math.max(0,ct-at.length)),Ke.map(ct=>at.some(Je=>Je.id===ct.id)?{...ct,read:!0}:ct)})},[]);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 Se=fn.on("notification:created",()=>Z()),Ke=fn.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),Se(),Ke()}},[Z,J]);const Q=b.useCallback(()=>{if(!z.current)return;const ne=z.current.getBoundingClientRect(),he=window.innerWidth,Be=window.innerHeight,Se=Math.min(448,he-16),Ke=Math.min(576,Be-16);let at=ne.right+8,ct=ne.top;at+Se>he-8&&(at=Math.max(8,he-Se-8)),ct+Ke>Be-8&&(ct=Math.max(8,Be-Ke-8)),W({top:ct,left:at,width:Se,maxHeight:Ke})},[]);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":P.current)},[m]);const ee=new Set(S.filter(ne=>ne.status==="pending").map(ne=>ne.id)),se=new Set(S.map(ne=>ne.id)),Y=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,be=Math.max(0,_-me),De=ee.size,He=be+De;b.useEffect(()=>{q.current!==null&&De>q.current&&Qne(),q.current=De},[De]);const ke=async ne=>{await de.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,Se=ne.actionTarget;if(Be==="open_chat"&&Se)try{const Ke=typeof Se=="string"?JSON.parse(Se):Se;if(Ke.agentId){const at={agentId:Ke.agentId};Ke.sessionId&&(at.sessionId=Ke.sessionId),Nt.navigate(Te.TEAM,at);return}}catch{}if(Be==="navigate"&&Se)try{const Ke=typeof Se=="string"?JSON.parse(Se):Se;if(Ke.path){if(Ke.path.startsWith("/team")){const at={},ct=new URLSearchParams(Ke.path.split("?")[1]||"");for(const[Je,rt]of ct.entries())at[Je]=rt;Nt.navigate(Te.TEAM,at);return}if(Ke.path.startsWith("/work")){const at={},ct=new URLSearchParams(Ke.path.split("?")[1]||"");for(const[Je,rt]of ct.entries())at[Je]=rt;Nt.navigate(Te.WORK,at);return}}}catch{}switch(ne.type){case"approval_request":{const Ke=he.approvalId,at=Ke?S.find(ht=>ht.id===Ke):void 0,ct=at?.details?.taskId??he.taskId,Je=at?.details?.requirementId??he.requirementId,rt=at?.details?.agentId??at?.agentId;ct?Nt.navigate(Te.WORK,{openTask:ct}):Je?Nt.navigate(Te.WORK,{openRequirement:Je}):rt?Nt.navigate(Te.TEAM,{agentId:rt}):Nt.navigate(Te.WORK);break}case"task_completed":case"task_created":case"task_review":case"task_failed":he.taskId?Nt.navigate(Te.WORK,{openTask:he.taskId}):Nt.navigate(Te.WORK);break;case"requirement_created":case"requirement_decision":he.requirementId?Nt.navigate(Te.WORK,{openRequirement:he.requirementId}):Nt.navigate(Te.WORK);break;case"agent_report":case"system":{if(he.agentId){const Ke={agentId:he.agentId};he.sessionId&&(Ke.sessionId=he.sessionId),Nt.navigate(Te.TEAM,Ke)}else Nt.navigate(Te.TEAM);break}case"direct_message":{const Ke=he.senderId;Ke?Nt.navigate(Te.TEAM,{dm:Ke}):Nt.navigate(Te.TEAM);break}case"group_message":{const Ke=he.channel;Ke?Nt.navigate(Te.TEAM,{channel:Ke}):Nt.navigate(Te.TEAM);break}default:he.taskId?Nt.navigate(Te.WORK,{openTask:he.taskId}):he.requirementId?Nt.navigate(Te.WORK,{openRequirement:he.requirementId}):he.projectId?Nt.navigate(Te.WORK,{projectId:he.projectId}):he.agentId&&Nt.navigate(Te.TEAM,{agentId:he.agentId});break}},Oe=async ne=>{ne.read||ke(ne.id);const he=ne.metadata??{},Be=he.taskId,Se=he.requirementId;if(Be||Se){const Ke=g.filter(at=>at.id!==ne.id&&!at.read&&(Be&&at.metadata?.taskId===Be||Se&&at.metadata?.requirementId===Se));for(const at of Ke)ke(at.id)}pe(ne)},Ee=async(ne,he,Be,Se)=>{N(ne);try{const{approval:Ke}=await de.approvals.respond(ne,he,t,Be,Se);C(rt=>rt.map(ht=>ht.id===ne?Ke:ht)),T(null),M(rt=>{const ht={...rt};return delete ht[ne],ht});const at=Ke.details?.taskId,ct=Ke.details?.requirementId,Je=g.filter(rt=>!rt.read&&(rt.type==="approval_request"&&rt.metadata?.approvalId===ne||at&&rt.metadata?.taskId===at||ct&&rt.metadata?.requirementId===ct));if(Je.length>0){for(const ht of Je)de.notifications.markRead(ht.id).catch(()=>{});const rt=new Set(Je.map(ht=>ht.id));v(ht=>ht.map(xt=>rt.has(xt.id)?{...xt,read:!0}:xt)),F(ht=>Math.max(0,ht-Je.length))}rl("/approvals"),rl("/notifications"),rl("/tasks"),rl("/taskboard"),rl("/requirements"),window.dispatchEvent(new CustomEvent("markus:data-changed")),setTimeout(()=>Z(),800)}catch{}N(null)},fe=async()=>{try{if(!t)return;await de.notifications.markAllRead(t),v(ne=>ne.map(he=>({...he,read:!0}))),F(0),rl("/notifications")}catch{const ne=Y.filter(he=>!he.read);await Promise.all(ne.map(he=>de.notifications.markRead(he.id))),v(he=>he.map(Be=>({...Be,read:!0}))),F(0),rl("/notifications")}},Le=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},Qe=ne=>{const he=[];he.push(ne.agentName);const Be=ne.details?.taskTitle,Se=ne.details?.taskId;Be?he.push(Be):Se&&he.push(`Task ${Se.slice(0,8)}`);const Ke=ne.details?.requirementId;return Ke&&!Se&&he.push(`Req ${Ke.slice(0,8)}`),he.join(" · ")},nt=[...S].sort((ne,he)=>new Date(he.requestedAt).getTime()-new Date(ne.requestedAt).getTime()),gt=nt.filter(ne=>ne.status==="pending"),ze=nt.filter(ne=>ne.status!=="pending"),ce=ne=>{const he=ne.details?.taskId,Be=ne.details?.requirementId,Se=ne.details?.agentId??ne.agentId;he?Nt.navigate(Te.WORK,{openTask:he}):Be?Nt.navigate(Te.WORK,{openRequirement:Be}):Se?Nt.navigate(Te.TEAM,{agentId:Se}):Nt.navigate(Te.WORK)},ue=()=>{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"),P.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"),De>0?` (${De})`:""]}),n.jsxs("button",{onClick:()=>{y("notifications"),P.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"),be>0?` (${be})`:""]}),n.jsx("button",{onClick:ue,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:fe,className:"text-[10px] text-brand-500 hover:text-brand-400 transition-colors",children:u("team:notifications.markAllRead")})}),n.jsxs("div",{ref:K,className:"flex-1 overflow-y-auto",onScroll:ne=>{if(h!=="notifications"||!R||$)return;const he=ne.currentTarget;he.scrollTop+he.clientHeight>=he.scrollHeight-80&&H()},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:[gt.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:()=>ce(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:Vc.approval_request})}),n.jsxs("div",{className:"flex-1 min-w-0",children:[n.jsxs("div",{className:"flex items-center gap-2",children:[Le(ne)&&n.jsx("span",{className:"text-[10px] text-amber-500 font-medium shrink-0",children:Le(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:Kc(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(Vr,{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 Se=ne.details?.subType,Ke=Se==="task"||Se==="requirement"||Se==="requirement_resubmit",at=ne.options&&ne.options.length>0,ct=(D[ne.id]??"").trim();return at?n.jsxs("div",{className:"space-y-1.5",children:[ne.options.map((Je,rt)=>n.jsxs("button",{disabled:k===ne.id,onClick:()=>Ee(ne.id,Je.id!=="reject",ct||void 0,Je.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 ${Je.id==="reject"||Je.id==="request_changes"?"border border-border-default text-fg-secondary hover:bg-surface-overlay":"bg-brand-600 text-white hover:bg-brand-700"}`,title:Je.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+rt)}),Je.label]},Je.id)),n.jsxs("div",{className:"flex gap-1.5 mt-1",children:[n.jsx("input",{type:"text",placeholder:u("team:notifications.freeformPlaceholder"),value:D[ne.id]??"",onChange:Je=>M(rt=>({...rt,[ne.id]:Je.target.value})),onKeyDown:Je=>{Je.key==="Enter"&&(D[ne.id]??"").trim()&&Ee(ne.id,!0,(D[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||!(D[ne.id]??"").trim(),onClick:()=>Ee(ne.id,!0,(D[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")})]})]}):Ke?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:()=>Ee(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:()=>Ee(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:D[ne.id]??"",onChange:Je=>M(rt=>({...rt,[ne.id]:Je.target.value})),onKeyDown:Je=>{Je.key==="Enter"&&(D[ne.id]??"").trim()&&Ee(ne.id,!1,(D[ne.id]??"").trim(),"needs_adjustment"),Je.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||!(D[ne.id]??"").trim(),onClick:()=>Ee(ne.id,!1,(D[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:D[ne.id]??"",onChange:Je=>M(rt=>({...rt,[ne.id]:Je.target.value})),onKeyDown:Je=>{Je.key==="Enter"&&Ee(ne.id,!0,ct||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:()=>Ee(ne.id,!0,ct||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:()=>Ee(ne.id,!1,ct||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)}),ze.length>0&&n.jsxs(n.Fragment,{children:[gt.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")}),ze.slice(0,50).map(ne=>n.jsxs("button",{onClick:()=>ce(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"}`}),Le(ne)&&n.jsx("span",{className:"text-[10px] text-fg-tertiary font-medium shrink-0",children:Le(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:Qe(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:Kc(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"&&(Y.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:[Y.map(ne=>{const he=Cj[ne.type]??"text-fg-tertiary";return n.jsxs("div",{role:"button",tabIndex:0,onClick:()=>Oe(ne),onKeyDown:Be=>{(Be.key==="Enter"||Be.key===" ")&&(Be.preventDefault(),Oe(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:Vc[ne.type]??Vc.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 ${uf[ne.priority]??uf.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(Vr,{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:Kc(ne.createdAt,u)}),mf(ne,u)&&n.jsx("span",{className:`text-[10px] font-medium ${he}`,children:mf(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 Se=0,Ke=0;return{onTouchStart:at=>{Se=at.touches[0].clientX,Ke=at.touches[0].clientY},onTouchEnd:at=>{const ct=at.changedTouches[0].clientX-Se,Je=at.changedTouches[0].clientY-Ke;Math.abs(ct)>60&&Math.abs(ct)>Math.abs(Je)*1.5&&(ct<0&&he<ne.length-1&&y(ne[he+1]),ct>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(Se=>n.jsx("button",{onClick:()=>y(Se),className:`flex-1 px-3 py-3 text-sm font-medium transition-colors ${h===Se?"text-fg-primary border-b-2 border-brand-500":"text-fg-tertiary"}`,children:Se==="approvals"?n.jsxs(n.Fragment,{children:[u("team:notifications.approvals"),De>0?` (${De})`:""]}):n.jsxs(n.Fragment,{children:[u("team:notifications.notifications"),be>0?` (${be})`:""]})},Se))}),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:fe,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:[gt.map(Se=>{const Ke=Se.details?.command,at=Ke?Se.description.replace(/\s*Command:.*$/,""):Se.description;return n.jsxs("div",{className:"px-3 py-3 space-y-2.5",children:[n.jsxs("div",{className:"cursor-pointer hover:bg-surface-overlay/50 -mx-3 -mt-3 px-3 pt-3 pb-1 rounded-t-md transition-colors",onClick:()=>ce(Se),children:[n.jsxs("div",{className:"flex items-start gap-2",children:[n.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"text-amber-500 mt-0.5 shrink-0",children:n.jsx("path",{d:Vc.approval_request})}),n.jsxs("div",{className:"flex-1 min-w-0",children:[n.jsxs("div",{className:"flex items-center gap-2",children:[Le(Se)&&n.jsx("span",{className:"text-[10px] text-amber-500 font-medium shrink-0",children:Le(Se)}),n.jsx("span",{className:"text-xs text-fg-primary font-medium truncate",children:Se.title}),n.jsx("span",{className:"text-[10px] text-fg-tertiary shrink-0",children:Kc(Se.requestedAt,u)})]}),n.jsx("div",{className:"text-[11px] text-fg-tertiary mt-0.5",children:Se.agentName})]})]}),n.jsx("div",{className:"mt-2.5 text-[11px] text-fg-secondary leading-relaxed",children:n.jsx(Vr,{content:at,className:"text-[11px] [&_h1]:text-xs [&_h2]:text-[11px] [&_h3]:text-[11px] [&_p]:text-[11px] [&_li]:text-[11px]"})}),Ke&&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:Ke})]}),(()=>{const ct=Se.details?.subType,Je=ct==="task"||ct==="requirement"||ct==="requirement_resubmit",rt=Se.options&&Se.options.length>0,ht=(D[Se.id]??"").trim();return rt?n.jsxs("div",{className:"space-y-1.5",children:[Se.options.map((xt,Ve)=>n.jsxs("button",{disabled:k===Se.id,onClick:()=>Ee(Se.id,xt.id!=="reject",ht||void 0,xt.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 ${xt.id==="reject"||xt.id==="request_changes"?"border border-border-default text-fg-secondary hover:bg-surface-overlay":"bg-brand-600 text-white hover:bg-brand-700"}`,title:xt.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+Ve)}),xt.label]},xt.id)),n.jsxs("div",{className:"flex gap-1.5 mt-1",children:[n.jsx("input",{type:"text",placeholder:u("team:notifications.freeformPlaceholder"),value:D[Se.id]??"",onChange:xt=>M(Ve=>({...Ve,[Se.id]:xt.target.value})),onKeyDown:xt=>{xt.key==="Enter"&&(D[Se.id]??"").trim()&&Ee(Se.id,!0,(D[Se.id]??"").trim(),"custom")},className:"flex-1 px-2.5 py-1.5 text-[11px] bg-surface-overlay border border-border-default rounded-md text-fg-primary placeholder:text-fg-tertiary focus:outline-none focus:ring-1 focus:ring-brand-500/50"}),n.jsx("button",{disabled:k===Se.id||!(D[Se.id]??"").trim(),onClick:()=>Ee(Se.id,!0,(D[Se.id]??"").trim(),"custom"),className:"px-2.5 py-1.5 text-[11px] font-medium bg-brand-600 text-white rounded-md hover:bg-brand-700 disabled:opacity-50 transition-colors",children:u("common:send")})]})]}):Je?n.jsxs("div",{className:"space-y-1.5",children:[n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsxs("button",{disabled:k===Se.id,onClick:()=>Ee(Se.id,!0,void 0,"approve"),className:"px-3 py-1.5 text-[11px] font-medium bg-green-600 text-white rounded-md hover:bg-green-700 disabled:opacity-50 transition-colors inline-flex items-center gap-1.5",children:[n.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:n.jsx("path",{d:"M20 6L9 17l-5-5"})}),u("common:approve")]}),n.jsxs("button",{disabled:k===Se.id,onClick:()=>Ee(Se.id,!1,void 0,"reject"),className:"px-3 py-1.5 text-[11px] font-medium bg-red-600/80 text-white rounded-md hover:bg-red-700 disabled:opacity-50 transition-colors inline-flex items-center gap-1.5",children:[n.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("path",{d:"M18 6L6 18"}),n.jsx("path",{d:"M6 6l12 12"})]}),u("common:reject")]}),j!==Se.id&&n.jsxs("button",{disabled:k===Se.id,onClick:()=>T(Se.id),className:"px-3 py-1.5 text-[11px] font-medium border border-amber-500/50 text-amber-500 rounded-md hover:bg-amber-500/10 disabled:opacity-50 transition-colors inline-flex items-center gap-1.5",children:[n.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("path",{d:"M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"}),n.jsx("path",{d:"M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z"})]}),u("team:notifications.needsAdjustment")]})]}),j===Se.id&&n.jsxs("div",{className:"space-y-1.5",children:[n.jsx("input",{type:"text",autoFocus:!0,placeholder:u("team:notifications.adjustmentPlaceholder"),value:D[Se.id]??"",onChange:xt=>M(Ve=>({...Ve,[Se.id]:xt.target.value})),onKeyDown:xt=>{xt.key==="Enter"&&(D[Se.id]??"").trim()&&Ee(Se.id,!1,(D[Se.id]??"").trim(),"needs_adjustment"),xt.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===Se.id||!(D[Se.id]??"").trim(),onClick:()=>Ee(Se.id,!1,(D[Se.id]??"").trim(),"needs_adjustment"),className:"px-2.5 py-1.5 text-[11px] font-medium bg-amber-600 text-white rounded-md hover:bg-amber-700 disabled:opacity-50 transition-colors",children:u("team:notifications.confirmAdjustment")}),n.jsx("button",{onClick:()=>T(null),className:"px-2.5 py-1.5 text-[11px] font-medium border border-border-default text-fg-secondary rounded-md hover:bg-surface-overlay transition-colors",children:u("common:cancel")})]})]})]}):n.jsxs("div",{className:"space-y-1.5",children:[n.jsx("input",{type:"text",placeholder:u("team:notifications.commentPlaceholder"),value:D[Se.id]??"",onChange:xt=>M(Ve=>({...Ve,[Se.id]:xt.target.value})),onKeyDown:xt=>{xt.key==="Enter"&&Ee(Se.id,!0,ht||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===Se.id,onClick:()=>Ee(Se.id,!0,ht||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===Se.id,onClick:()=>Ee(Se.id,!1,ht||void 0,"reject"),className:"flex-1 px-2.5 py-1.5 text-[11px] font-medium border border-border-default text-fg-secondary rounded-md hover:bg-surface-overlay disabled:opacity-50 transition-colors",children:u("common:reject")})]})]})})()]},Se.id)}),ze.length>0&&n.jsxs(n.Fragment,{children:[gt.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")}),ze.slice(0,50).map(Se=>n.jsxs("button",{onClick:()=>ce(Se),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 ${Se.status==="approved"?"bg-green-500":Se.status==="cancelled"||Se.status==="expired"?"bg-gray-400":"bg-red-500"}`}),n.jsx("span",{className:"text-xs text-fg-secondary truncate flex-1",children:Se.title}),n.jsx("span",{className:`text-[10px] font-medium shrink-0 ${Se.status==="approved"?"text-green-500":Se.status==="cancelled"||Se.status==="expired"?"text-fg-muted":"text-red-500"}`,children:u(`common:status.${Se.status}`,{defaultValue:Se.status})})]}),n.jsxs("div",{className:"flex items-center gap-1.5 mt-0.5 pl-3.5",children:[n.jsx("span",{className:"text-[10px] text-fg-muted truncate",children:Qe(Se)}),n.jsx("span",{className:"text-[10px] text-fg-muted shrink-0",children:"·"}),n.jsx("span",{className:"text-[10px] text-fg-muted shrink-0",children:Kc(Se.respondedAt??Se.requestedAt,u)})]})]},Se.id))]})]})}),n.jsx("div",{className:"w-full shrink-0 h-full overflow-y-auto scrollbar-thin",children:Y.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:Y.slice(0,50).map(Se=>{const Ke=Cj[Se.type]??"text-fg-tertiary";return n.jsxs("button",{onClick:()=>Oe(Se),className:`w-full text-left px-3 py-2.5 flex gap-2.5 transition-colors ${Se.read?"opacity-50 hover:opacity-70":"hover:bg-surface-overlay"}`,children:[n.jsx("div",{className:"shrink-0 mt-0.5",children:n.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:Ke,children:n.jsx("path",{d:Vc[Se.type]??Vc.system})})}),n.jsxs("div",{className:"flex-1 min-w-0",children:[n.jsxs("div",{className:"flex items-center gap-1.5",children:[!Se.read&&n.jsx("span",{className:`w-1.5 h-1.5 rounded-full shrink-0 ${uf[Se.priority]??uf.normal}`}),n.jsx("span",{className:"text-xs text-fg-primary font-medium truncate",children:Se.title})]}),n.jsx("div",{className:"text-[11px] text-fg-tertiary mt-0.5 ",children:n.jsx(Vr,{content:Se.body,className:"text-[11px] [&_h1]:text-xs [&_h2]:text-[11px] [&_h3]:text-[11px] [&_p]:text-[11px] [&_li]:text-[11px] [&_p]:text-fg-tertiary"})}),n.jsxs("div",{className:"flex items-center gap-2 mt-0.5",children:[n.jsx("span",{className:"text-[10px] text-fg-muted",children:Kc(Se.createdAt,u)}),mf(Se,u)&&n.jsx("span",{className:`text-[10px] font-medium ${Ke}`,children:mf(Se,u)})]})]})]},Se.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}),He>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:He>99?u("common:badgeOverLimit"):He})]}),m&&ad.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"})]}),He>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:He>99?u("common:badgeOverLimit"):He})]}),m&&ad.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 Zne({authUser:e}){const{t}=kt("nav"),r=js();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(L8,{collapsed:!1,userId:e?.id,embeddedMode:!0})})]})}function Jne(){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,D,M,_]=await Promise.allSettled([de.agents.list(),de.tasks.list({search:k,pageSize:20}),de.requirements.list(),de.projects.list(),de.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=D.status==="fulfilled"?D.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)):[],W=_.status==="fulfilled"?_.value.results:[];l({agents:F,tasks:z,requirements:L,projects:U,deliverables:W})}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(Te.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(Te.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(ere,{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(Te.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(tre,{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(Te.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(Te.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(Te.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 ere({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 tre({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 nre({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 rre({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===Te.NOTIFICATIONS)return n.jsx(L8,{sidebarMode:!0,collapsed:s,userId:r?.id,label:i(m.id),iconPath:Zx[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(nre,{d:Zx[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.3-rc.0"]})]})}function sre({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 de.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===Te.NOTIFICATIONS,y=m.id===Te.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:Zx[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 I8=["builder","agents","teams","skills"];function are(){const e=localStorage.getItem("markus_nav_storeTab");return e&&(localStorage.removeItem("markus_nav_storeTab"),I8.includes(e))?e:"builder"}function ire({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(are),i=hl(r,s,a);return b.useEffect(()=>{const l=d=>{const u=d.detail;u.params?.storeTab&&I8.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(AS,{}),s==="agents"&&n.jsx(RS,{authUser:e}),s==="teams"&&n.jsx(IS,{}),s==="skills"&&n.jsx(PS,{})]})]})}const Kx="profile",Tj="llm",Aj="search";function ore({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),[D,M]=b.useState(null);b.useEffect(()=>{de.auth.me().then(({user:Ve})=>{Ve.name&&u(Ve.name),Ve.email&&p(Ve.email),Ve.avatarUrl&&M(Ve.avatarUrl)}).catch(()=>{})},[]);const[_,F]=b.useState(null),[z,L]=b.useState(!1),[U,W]=b.useState({}),[q,I]=b.useState(!1),[R,E]=b.useState(null),[$,X]=b.useState(!1),[K,P]=b.useState(!1),[B,Z]=b.useState([]),[H,J]=b.useState(null),[Q,ee]=b.useState(!0),se=b.useRef(!1),[Y,me]=b.useState(null),[be,De]=b.useState({serperApiKey:"",tavilyApiKey:"",bingApiKey:"",googleSearchApiKey:"",googleSearchCx:"",serpApiKey:"",braveApiKey:"",exaApiKey:"",bochaApiKey:""}),[He,ke]=b.useState(!1),[pe,Oe]=b.useState(!1),[Ee,fe]=b.useState(null),Le=b.useRef(!1),Qe=()=>({"Content-Type":"application/json",Authorization:`Bearer ${localStorage.getItem("markus_token")??""}`});b.useEffect(()=>{fetch("/api/settings/llm").then(Ve=>Ve.ok?Ve.json():null).then(Ve=>{if(Ve?.providers){const ut=Object.entries(Ve.providers).filter(([,it])=>it.configured).map(([it,Vt])=>({name:it,displayName:Vt.displayName??it,model:Vt.model??"",apiKeyPreview:Vt.apiKeyPreview}));ut.length>0&&(P(!0),Z(ut))}typeof Ve?.autoFallback=="boolean"&&ee(Ve.autoFallback)}).catch(()=>{})},[]);const nt=s?2:3;b.useEffect(()=>{i===nt&&!se.current&&!K&&(se.current=!0,ze())},[i,K,nt]);const gt=s?3:4;b.useEffect(()=>{i===gt&&!Le.current&&(Le.current=!0,ne())},[i,gt]);const ze=async()=>{L(!0);try{const Ve=await fetch("/api/settings/env-models",{headers:Qe()});if(Ve.ok){const ut=await Ve.json();if(F(ut),ut.detected.length>0){const it={};for(const Vt of ut.detected)it[Vt.provider]=!0;W(it)}}}catch{}finally{L(!1)}},ce=async()=>{if(!_)return;const Ve=_.detected.filter(ut=>U[ut.provider]);if(Ve.length!==0){I(!0),J(null);try{const ut=await fetch("/api/settings/env-models",{method:"POST",headers:Qe(),body:JSON.stringify({providers:Ve.map(it=>({provider:it.provider,model:it.model,baseUrl:it.baseUrl,enabled:!0}))})});if(ut.ok){const it=await ut.json();J({type:"ok",text:it.message}),P(!0)}else J({type:"err",text:a("llm.failedToApply")})}catch{J({type:"err",text:a("common:networkError")})}finally{I(!1)}}},ue=async()=>{X(!0);try{const ut=await(await fetch("/api/settings/import/openclaw",{method:"POST",headers:Qe(),body:JSON.stringify({preview:!0})})).json();"error"in ut||E(ut)}catch{}finally{X(!1)}},Me=async()=>{X(!0),J(null);try{const ut=await(await fetch("/api/settings/import/openclaw",{method:"POST",headers:Qe(),body:JSON.stringify({preview:!1})})).json();"error"in ut?J({type:"err",text:ut.error}):(J({type:"ok",text:a("llm.importedModels",{count:ut.appliedModels})}),P(!0))}catch{J({type:"err",text:a("llm.importFailed")})}finally{X(!1)}},ne=async()=>{try{const Ve=await fetch("/api/settings/search",{headers:Qe()});if(Ve.ok){const ut=await Ve.json();me(ut),ut&&(ut.serper.configured||ut.tavily.configured||ut.bing.configured||ut.google.configured||ut.serpapi.configured||ut.brave.configured||ut.exa.configured||ut.bocha.configured)&&Oe(!0)}}catch{}},he=async()=>{if(be.serperApiKey||be.tavilyApiKey||be.bingApiKey||be.googleSearchApiKey||be.googleSearchCx||be.serpApiKey||be.braveApiKey||be.exaApiKey||be.bochaApiKey){ke(!0),fe(null);try{const ut={};be.serperApiKey&&(ut.serperApiKey=be.serperApiKey),be.tavilyApiKey&&(ut.tavilyApiKey=be.tavilyApiKey),be.bingApiKey&&(ut.bingApiKey=be.bingApiKey),be.googleSearchApiKey&&(ut.googleSearchApiKey=be.googleSearchApiKey),be.googleSearchCx&&(ut.googleSearchCx=be.googleSearchCx),be.serpApiKey&&(ut.serpApiKey=be.serpApiKey),be.braveApiKey&&(ut.braveApiKey=be.braveApiKey),be.exaApiKey&&(ut.exaApiKey=be.exaApiKey),be.bochaApiKey&&(ut.bochaApiKey=be.bochaApiKey);const it=await fetch("/api/settings/search",{method:"POST",headers:Qe(),body:JSON.stringify(ut)});if(it.ok){const Vt=await it.json();me(Vt),Oe(!0),De({serperApiKey:"",tavilyApiKey:"",bingApiKey:"",googleSearchApiKey:"",googleSearchCx:"",serpApiKey:"",braveApiKey:"",exaApiKey:"",bochaApiKey:""}),fe({type:"ok",text:a("search.saved")})}else fe({type:"err",text:a("search.failedToSave")})}catch{fe({type:"err",text:a("common:networkError")})}finally{ke(!1)}}},Be=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 de.auth.updateProfile(d.trim(),m.trim()),h&&await de.auth.changePassword("",h),T(!0)}catch{N(a("profile.errors.saveFailed"))}finally{C(!1)}},Se=[{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")}],Ke=[{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(Hu,{i18nKey:"welcome.description",ns:"onboarding",components:{strong:n.jsx("strong",{className:"text-fg-primary"})}})}),n.jsx("div",{className:"grid grid-cols-2 gap-3 mt-6",children:[[a("welcome.features.operation"),a("welcome.features.operationDesc")],[a("welcome.features.collaboration"),a("welcome.features.collaborationDesc")],[a("welcome.features.memory"),a("welcome.features.memoryDesc")],[a("welcome.features.anyLlm"),a("welcome.features.anyLlmDesc")]].map(([Ve,ut])=>n.jsxs("div",{className:"bg-surface-elevated/50 rounded-lg p-3",children:[n.jsx("div",{className:"font-medium text-fg-primary text-xs",children:Ve}),n.jsx("div",{className:"text-fg-secondary text-xs mt-1",children:ut})]},Ve))})]})},{id:Kx,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(Jj,{currentUrl:D,name:d,size:64,targetType:"user"})}),n.jsxs("div",{className:"space-y-1",children:[n.jsxs("label",{className:"text-xs text-fg-tertiary font-medium",children:[a("profile.nameLabel")," ",n.jsx("span",{className:"text-red-500",children:"*"})]}),n.jsx("input",{type:"text",value:d,onChange:Ve=>u(Ve.target.value),placeholder:a("profile.namePlaceholder"),className:"w-full px-4 py-2.5 bg-surface-elevated border border-border-default rounded-xl text-sm text-fg-primary focus:border-brand-500 outline-none transition-colors",autoFocus:!0})]}),n.jsxs("div",{className:"space-y-1",children:[n.jsxs("label",{className:"text-xs text-fg-tertiary font-medium",children:[a("profile.emailLabel")," ",n.jsx("span",{className:"text-red-500",children:"*"})]}),n.jsx("input",{type:"email",value:m,onChange:Ve=>p(Ve.target.value),placeholder:a("profile.emailPlaceholder"),className:"w-full px-4 py-2.5 bg-surface-elevated border border-border-default rounded-xl text-sm text-fg-primary focus:border-brand-500 outline-none transition-colors"})]}),n.jsxs("div",{className:"space-y-1",children:[n.jsx("label",{className:"text-xs text-fg-tertiary font-medium",children:a("profile.newPasswordLabel")}),n.jsx("input",{type:"password",value:h,onChange:Ve=>y(Ve.target.value),placeholder:a("profile.newPasswordPlaceholder"),className:"w-full px-4 py-2.5 bg-surface-elevated border border-border-default rounded-xl text-sm text-fg-primary focus:border-brand-500 outline-none transition-colors"})]}),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:Ve=>v(Ve.target.value),placeholder:a("profile.confirmPasswordPlaceholder"),className:"w-full px-4 py-2.5 bg-surface-elevated border border-border-default rounded-xl text-sm text-fg-primary focus:border-brand-500 outline-none transition-colors"})]}),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:()=>{Be()},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:Se.map(Ve=>n.jsxs("button",{onClick:()=>r(Ve.value),className:`flex flex-col items-center gap-2 rounded-xl border-2 p-5 transition-all ${t===Ve.value?"border-brand-500 bg-brand-500/10":"border-border-default hover:border-fg-tertiary bg-surface-elevated/30"}`,children:[n.jsx("span",{className:"text-2xl",children:Ve.icon}),n.jsx("span",{className:"text-sm font-medium text-fg-primary",children:Ve.label}),n.jsx("span",{className:"text-[11px] text-fg-tertiary leading-tight text-center",children:Ve.desc})]},Ve.value))})},{id:Tj,title:a("llm.title"),subtitle:a("llm.subtitle"),content:K?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")})]}),B.map(Ve=>n.jsxs("div",{className:"flex items-center justify-between bg-green-500/10 border border-green-500/30 rounded-lg px-4 py-2.5",children:[n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx("span",{className:"w-2 h-2 rounded-full bg-green-400"}),n.jsx("span",{className:"text-sm text-fg-primary font-medium",children:Ve.displayName}),Ve.model&&n.jsx("span",{className:"text-xs text-fg-tertiary",children:Ve.model})]}),Ve.apiKeyPreview&&n.jsx("code",{className:"text-[10px] text-fg-tertiary",children:Ve.apiKeyPreview})]},Ve.name)),n.jsx("div",{className:"text-xs text-fg-secondary mt-1",children:a("llm.configuredHint")}),n.jsxs("div",{className:"flex items-center justify-between bg-surface-elevated/40 rounded-lg px-4 py-3 mt-3",children:[n.jsxs("div",{children:[n.jsx("div",{className:"text-xs font-medium text-fg-primary",children:a("llm.autoFallback")}),n.jsx("div",{className:"text-[11px] text-fg-tertiary mt-0.5",children:a("llm.autoFallbackDesc")})]}),n.jsx("button",{onClick:async()=>{const Ve=!Q;ee(Ve);try{await fetch("/api/settings/llm",{method:"POST",headers:Qe(),body:JSON.stringify({autoFallback:Ve})})}catch{ee(!Ve)}},className:`relative inline-flex h-5 w-9 items-center rounded-full transition-colors shrink-0 ${Q?"bg-green-500":"bg-gray-600"}`,children:n.jsx("span",{className:`inline-block h-3.5 w-3.5 rounded-full bg-white transition-transform ${Q?"translate-x-4":"translate-x-1"}`})})]})]}):n.jsxs("div",{className:"space-y-4",children:[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(Ve=>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[Ve.provider]??!1,onChange:ut=>W({...U,[Ve.provider]:ut.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:Ve.displayName}),n.jsx("span",{className:"text-xs text-fg-tertiary ml-2",children:Ve.model})]}),n.jsx("code",{className:"text-[10px] text-fg-tertiary",children:Ve.apiKeyPreview})]},Ve.provider)),n.jsx("button",{onClick:()=>{ce()},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(Hu,{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")}),R?R.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:R.summary.configPath}),R.summary.models&&n.jsx("span",{className:"text-fg-tertiary ml-1",children:a("llm.openClawProviders",{count:R.summary.models.providerCount})})]}),n.jsx("button",{onClick:()=>{Me()},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:()=>{ue()},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")})]}),H&&n.jsx("div",{className:`text-xs px-3 py-2 rounded-lg ${H.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:H.text})]})},{id:Aj,title:a("search.title"),subtitle:a("search.subtitle"),content:pe?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")})]}),Y&&[{id:"serper",label:a("search.serper")},{id:"tavily",label:a("search.tavily")},{id:"bing",label:a("search.bing")},{id:"google",label:a("search.google")},{id:"serpapi",label:a("search.serpapi")},{id:"brave",label:a("search.brave")},{id:"exa",label:a("search.exa")},{id:"bocha",label:a("search.bocha")}].filter(Ve=>Y[Ve.id]?.configured).map(Ve=>n.jsxs("div",{className:"flex items-center justify-between bg-green-500/10 border border-green-500/30 rounded-lg px-4 py-2.5",children:[n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx("span",{className:"w-2 h-2 rounded-full bg-green-400"}),n.jsx("span",{className:"text-sm text-fg-primary font-medium",children:Ve.label})]}),n.jsx("code",{className:"text-[10px] text-fg-tertiary",children:Y[Ve.id].preview})]},Ve.id)),n.jsx("div",{className:"text-xs text-fg-secondary mt-1",children:a("search.savedHint")})]}):n.jsxs("div",{className:"space-y-4",children:[n.jsx("div",{className:"text-xs text-fg-secondary",children:a("search.description")}),Y&&(Y.serper.configured||Y.tavily.configured||Y.bing.configured||Y.google.configured||Y.serpapi.configured||Y.brave.configured||Y.exa.configured||Y.bocha.configured)&&n.jsxs("div",{className:"space-y-2",children:[n.jsx("div",{className:"text-xs text-fg-secondary uppercase tracking-wider",children:a("search.detected")}),[{id:"serper",label:a("search.serper")},{id:"tavily",label:a("search.tavily")},{id:"bing",label:a("search.bing")},{id:"google",label:a("search.google")},{id:"serpapi",label:a("search.serpapi")},{id:"brave",label:a("search.brave")},{id:"exa",label:a("search.exa")},{id:"bocha",label:a("search.bocha")}].filter(Ve=>Y[Ve.id]?.configured).map(Ve=>n.jsxs("div",{className:"flex items-center justify-between bg-green-500/10 border border-green-500/30 rounded-lg px-3 py-2",children:[n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx("span",{className:"w-2 h-2 rounded-full bg-green-400"}),n.jsx("span",{className:"text-sm text-fg-primary",children:Ve.label})]}),n.jsx("code",{className:"text-[10px] text-fg-tertiary",children:Y[Ve.id].preview})]},Ve.id))]}),n.jsx("div",{className:"space-y-3",children:[{label:a("search.serper"),field:"serperApiKey"},{label:a("search.tavily"),field:"tavilyApiKey"},{label:a("search.bing"),field:"bingApiKey"},{label:a("search.google"),field:"googleSearchApiKey"},{label:a("search.serpapi"),field:"serpApiKey"},{label:a("search.brave"),field:"braveApiKey"},{label:a("search.exa"),field:"exaApiKey"},{label:a("search.bocha"),field:"bochaApiKey"}].map(Ve=>n.jsxs("div",{className:"space-y-1",children:[n.jsx("label",{className:"text-xs text-fg-tertiary font-medium",children:Ve.label}),n.jsx("input",{type:"password",value:be[Ve.field],onChange:ut=>De({...be,[Ve.field]:ut.target.value}),placeholder:a("search.apiKeyPlaceholder"),className:"w-full px-4 py-2 bg-surface-elevated border border-border-default rounded-xl text-sm text-fg-primary focus:border-brand-500 outline-none transition-colors"})]},Ve.field))}),n.jsx("button",{onClick:()=>{he()},disabled:He||!be.serperApiKey&&!be.tavilyApiKey&&!be.bingApiKey&&!be.googleSearchApiKey&&!be.serpApiKey&&!be.braveApiKey&&!be.exaApiKey&&!be.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(He?"search.saving":"search.save")}),Ee&&n.jsx("div",{className:`text-xs px-3 py-2 rounded-lg ${Ee.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:Ee.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(([Ve,ut])=>n.jsxs("div",{className:"flex gap-3 bg-surface-elevated/50 rounded-lg p-3",children:[n.jsx("div",{className:"text-brand-500 mt-0.5 shrink-0",children:"→"}),n.jsxs("div",{children:[n.jsx("div",{className:"font-medium text-fg-primary text-xs",children:Ve}),n.jsx("div",{className:"text-fg-secondary text-xs",children:ut})]})]},Ve))})}],at=s?Ke.filter(Ve=>Ve.id!==Kx):Ke,ct=at.findIndex(Ve=>Ve.id===Kx),Je=at.findIndex(Ve=>Ve.id===Tj),rt=at.findIndex(Ve=>Ve.id===Aj),ht=()=>{i===ct&&ct>=0&&!j||(i<at.length-1?l(i+1):e())},xt=at[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:at.map((Ve,ut)=>n.jsx("div",{className:`h-1 flex-1 rounded-full transition-colors ${ut<=i?"bg-brand-500":"bg-surface-elevated"}`},ut))}),n.jsx("h2",{className:"text-2xl font-bold text-fg-primary",children:xt.title}),n.jsx("p",{className:"text-sm text-fg-secondary mt-1 mb-6",children:xt.subtitle}),xt.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:[ct>=0&&i===ct&&!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")}),Je>=0&&i===Je&&!K&&n.jsx("button",{onClick:ht,className:"px-4 py-2 text-sm text-fg-tertiary hover:text-fg-secondary transition-colors",children:a("llm.skipForNow")}),rt>=0&&i===rt&&!pe&&n.jsx("button",{onClick:ht,className:"px-4 py-2 text-sm text-fg-tertiary hover:text-fg-secondary transition-colors",children:a("search.skipForNow")}),n.jsx("button",{onClick:ht,disabled:ct>=0&&i===ct&&!j,className:`px-6 py-2.5 text-white text-sm rounded-xl transition-colors ${ct>=0&&i===ct&&!j?"bg-brand-600/40 cursor-not-allowed":"bg-brand-600 hover:bg-brand-500"}`,children:i===at.length-1?a("getStarted"):a("common:next")})]})]})]})})})}function lre({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:D}=await de.auth.init(r.trim(),a.trim(),l);if(p)try{await de.auth.uploadAvatar(p,"user")}catch{}e(T,D??!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 cre({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 de.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 dre({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(()=>{de.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 de.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 ure({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 de.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 Af={agents:[],tasks:[],requirements:[],projects:[],deliverables:[]},mre={team:["agents","tasks","requirements","projects","deliverables"],work:["projects","requirements","tasks","agents","deliverables"],deliverables:["deliverables","agents","tasks","requirements","projects"]},fre=["agents","tasks","requirements","projects","deliverables"];let Ej="",Mj="all",Rj=Af,Dj=!1;function hre({onClose:e,currentPage:t}){const{t:r}=kt(["common","home","work"]),[s,a]=b.useState(Ej),[i,l]=b.useState(Mj),[d,u]=b.useState(Rj),[m,p]=b.useState(!1),[h,y]=b.useState(Dj),[g,v]=b.useState(-1);b.useEffect(()=>{Ej=s},[s]),b.useEffect(()=>{Mj=i},[i]),b.useEffect(()=>{Rj=d},[d]),b.useEffect(()=>{Dj=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(Af),y(!1),v(-1);return}p(!0),y(!0),v(-1);const I=q.toLowerCase();try{const[R,E,$,X,K]=await Promise.allSettled([de.agents.list(),de.tasks.list({search:q,pageSize:20}),de.requirements.list(),de.projects.list(),de.deliverables.search({q,limit:20})]),P=R.status==="fulfilled"?R.value.agents.filter(Q=>Q.name?.toLowerCase().includes(I)||Q.role?.toLowerCase().includes(I)):[],B=E.status==="fulfilled"?E.value.tasks:[],Z=$.status==="fulfilled"?$.value.requirements.filter(Q=>Q.title?.toLowerCase().includes(I)||Q.description?.toLowerCase().includes(I)):[],H=X.status==="fulfilled"?X.value.projects.filter(Q=>Q.name?.toLowerCase().includes(I)||Q.description?.toLowerCase().includes(I)):[],J=K.status==="fulfilled"?K.value.results:[];u({agents:P,tasks:B,requirements:Z,projects:H,deliverables:J})}catch{u(Af)}finally{p(!1)}},[]),T=q=>{a(q),C.current&&clearTimeout(C.current),C.current=setTimeout(()=>j(q),400)},D=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(()=>mre[t||""]||fre,[t]),F=b.useMemo(()=>{const q=[],I=i==="all"?8:void 0,R=E=>{if(i!=="all"&&i!==E)return;const $=d[E==="agents"?"agents":E==="tasks"?"tasks":E==="requirements"?"requirements":E==="projects"?"projects":"deliverables"],X=I?$.slice(0,I):$;for(const K of X)switch(E){case"agents":q.push({id:K.id,type:"agent",page:Te.TEAM,params:{agentId:K.id}});break;case"tasks":q.push({id:K.id,type:"task",page:Te.WORK,params:{openTask:K.id}});break;case"requirements":q.push({id:K.id,type:"requirement",page:Te.WORK,params:{openRequirement:K.id}});break;case"projects":q.push({id:K.id,type:"project",page:Te.WORK,params:{projectId:K.id}});break;case"deliverables":q.push({id:K.id,type:"deliverable",page:Te.DELIVERABLES,params:{openDeliverable:K.id}});break}I&&$.length>I&&q.push({id:`more_${E}`,type:"showMore",page:"",expandCategory:E,totalCount:$.length})};for(const E of _)R(E);return q},[d,i,_]),z=b.useCallback(q=>{if(q.type==="showMore"&&q.expandCategory){l(q.expandCategory),v(-1);return}D(q.page,q.params)},[D]);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(K=>K.id),$=E.indexOf(i),X=q.shiftKey?$<=0?E.length-1:$-1:$>=E.length-1?0:$+1;l(E[X]),v(-1);return}const I=q.ctrlKey&&q.key==="n"||q.key==="ArrowDown",R=q.ctrlKey&&q.key==="p"||q.key==="ArrowUp";if(I||R){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 W=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(Af),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,R=E=>{const $=W++,X=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:"查看全部"})," (",X,")"]})};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 $=W++;return n.jsxs("button",{"data-idx":$,onClick:()=>D(Te.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(pre,{status:E.status})]},E.id)})}),I&&d.agents.length>I&&R("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 $=W++;return n.jsxs("button",{"data-idx":$,onClick:()=>D(Te.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(gre,{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&&R("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 $=W++;return n.jsxs("button",{"data-idx":$,onClick:()=>D(Te.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&&R("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 $=W++;return n.jsxs("button",{"data-idx":$,onClick:()=>D(Te.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&&R("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 $=W++;return n.jsxs("button",{"data-idx":$,onClick:()=>D(Te.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&&R("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 pre({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 gre({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 xre=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 bre(){const{t:e}=kt("common"),[t,r]=b.useState(Ul),[s,a]=b.useState(()=>!localStorage.getItem("markus_onboarded")),[i,l]=b.useState(!0),d=js(),u=JW(),m=Qu({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,D]=b.useState(null),[M,_]=b.useState(!1),[F,z]=b.useState(null),[L,U]=b.useState(()=>{const P=localStorage.getItem("markus_update_dismissed");return P||null}),[W,q]=b.useState(!1);b.useEffect(()=>{if(d)return;const P=navigator.platform.toUpperCase().includes("MAC"),B=H=>{P&&H.metaKey&&!H.ctrlKey&&H.key==="p"?(H.preventDefault(),q(J=>!J)):!P&&H.ctrlKey&&!H.metaKey&&H.key==="p"&&(H.preventDefault(),q(J=>!J))},Z=()=>q(!0);return document.addEventListener("keydown",B),window.addEventListener("markus:open-search",Z),()=>{document.removeEventListener("keydown",B),window.removeEventListener("markus:open-search",Z)}},[d]);const I=b.useCallback(P=>{let B=il(P);d?B=JO[B]??B:B===Te.NOTIFICATIONS&&(B=Te.HOME);const Z=Ul(),H=window.location.hash.slice(1);H!==Z?Wx[Z]=H:delete Wx[Z];const J=B!==Te.WORK?Wx[B]:void 0;J&&J!==B?(history.pushState(null,"","#"+B),history.pushState(null,"","#"+J)):history.pushState(null,"","#"+B),window.dispatchEvent(new HashChangeEvent("hashchange")),r(B),h(Q=>Q.has(B)?Q:new Set([...Q,B]))},[d]);b.useEffect(()=>{Nt.setHandler(P=>I(P))},[I]);const R=b.useCallback(()=>{fetch("/api/settings/llm").then(P=>P.ok?P.json():null).then(P=>{if(P?.providers){const B=Object.values(P.providers).some(Z=>Z.configured);D(B)}}).catch(()=>{})},[]);b.useEffect(()=>{const P=new URLSearchParams(window.location.search),B=P.get("install");if(B&&Ul()!==Te.STORE){const J=P.get("type"),ee=J&&{agent:"agents",team:"teams",skill:"skills"}[J]||"agents";localStorage.setItem("markus_nav_installItem",B),localStorage.setItem("markus_nav_storeTab",ee),P.delete("install"),P.delete("type");const se=P.toString();window.history.replaceState(null,"",window.location.pathname+(se?`?${se}`:"")+"#store"),setTimeout(()=>Nt.navigate(Te.STORE,{storeTab:ee,installItem:B}),300)}de.auth.me().then(({user:J})=>{g(J),S(!0),fn.connect(J.id),R(),de.health().then(ee=>{ee.updateAvailable&&ee.latestVersion&&z({latestVersion:ee.latestVersion,currentVersion:ee.version})}).catch(()=>{});const Q=()=>{Bl(ga.builderArtifacts,()=>de.builder.artifacts.list()),Bl(ga.builderAgents,()=>de.agents.list()),Bl(ga.builderHubMyItems,()=>In.myItems()),Bl(ga.builderInstalled,()=>de.builder.artifacts.installed()),Bl(ga.hubAgents,()=>In.search({type:"agent",limit:50})),Bl(ga.hubTeams,()=>In.search({type:"team",limit:50})),Bl(ga.hubSkills,()=>In.search({type:"skill",limit:50}))};typeof requestIdleCallback=="function"?requestIdleCallback(Q,{timeout:5e3}):setTimeout(Q,3e3)}).catch(()=>{g(null),de.auth.status().then(({initialized:J})=>S(J)).catch(()=>S(!0))}),fn.connect();const Z=fn.on("notification",()=>{window.dispatchEvent(new CustomEvent("markus:notifications-changed"))}),H=()=>{const J=Ul();r(J),h(Q=>Q.has(J)?Q:new Set([...Q,J]))};return window.addEventListener("hashchange",H),()=>{Z(),fn.disconnect(),window.removeEventListener("hashchange",H)}},[]);const E=y!=="loading"&&y!==null?y:void 0,$=b.useMemo(()=>d?{[Te.HOME]:n.jsx(iw,{authUser:E}),[Te.TEAM]:n.jsx(Rk,{authUser:E}),[Te.BUILDER]:n.jsx(ire,{authUser:E}),[Te.SETTINGS]:n.jsx(Pk,{theme:u.mode,onThemeChange:u.setMode,authUser:E,onLogout:()=>g(null),onUserUpdated:P=>g(P)}),[Te.WORK]:n.jsx(wj,{authUser:E}),[Te.DELIVERABLES]:n.jsx(Nj,{authUser:E}),[Te.NOTIFICATIONS]:n.jsx(Zne,{authUser:E}),[Te.REPORTS]:n.jsx(Sj,{authUser:E}),[Te.SEARCH]:n.jsx(Jne,{})}:{[Te.HOME]:n.jsx(iw,{authUser:E}),[Te.TEAM]:n.jsx(Rk,{authUser:E}),[Te.SETTINGS]:n.jsx(Pk,{theme:u.mode,onThemeChange:u.setMode,authUser:E,onLogout:()=>g(null),onUserUpdated:P=>g(P)}),[Te.STORE]:n.jsx(RG,{authUser:E}),[Te.BUILDER]:n.jsx(AS,{authUser:E}),[Te.WORK]:n.jsx(wj,{authUser:E}),[Te.DELIVERABLES]:n.jsx(Nj,{authUser:E}),[Te.REPORTS]:n.jsx(Sj,{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 K=(typeof window<"u"?window.location.hash:"").match(/^#invite\?token=([a-f0-9]+)/);return K?n.jsx(dre,{token:K[1],onComplete:()=>{window.location.hash="",localStorage.removeItem("markus_onboarded"),a(!0),k(!0),g("loading"),de.auth.me().then(P=>g(P.user)).catch(()=>g(null))}}):y===null?v===!1?n.jsx(lre,{onSetup:(P,B)=>{g(P),S(!0),k(!0),B&&(localStorage.removeItem("markus_onboarded"),a(!0))}}):n.jsx(cre,{onLogin:(P,B)=>{g(P),B?(localStorage.removeItem("markus_onboarded"),a(!0)):localStorage.getItem("markus_onboarded")||(localStorage.setItem("markus_onboarded","1"),a(!1))}}):N?n.jsx(ure,{onComplete:()=>j(!1),isFirstTime:!0}):s?n.jsx(ore,{theme:u.mode,onThemeChange:u.setMode,skipProfile:C,onComplete:()=>{localStorage.setItem("markus_onboarded","1"),a(!1),k(!1),R(),I(Te.TEAM)}}):n.jsxs("div",{className:`flex h-dvh bg-surface-primary text-fg-primary overflow-x-hidden ${d?"flex-col":""}`,children:[!d&&t!==Te.SETTINGS&&n.jsxs(n.Fragment,{children:[n.jsx("div",{className:"relative z-40 shrink-0",style:{width:m.width},children:n.jsx(rre,{currentPage:t,onNavigate:P=>{I(P),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!==Te.SETTINGS&&t!==Te.SEARCH?"pb-14":""}`,children:[T===!1&&!M&&t!==Te.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(Te.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(P=>p.has(P)?n.jsx(xre,{id:P,activePage:t,children:$[P]},P):null)})]}),d&&t!==Te.SETTINGS&&t!==Te.SEARCH&&n.jsx(sre,{currentPage:t,onNavigate:I,userId:E?.id}),d&&n.jsx(o_,{authUser:E,onNavigate:I}),!d&&W&&n.jsx(hre,{onClose:()=>q(!1),currentPage:t})]})}d9.createRoot(document.getElementById("root")).render(n.jsx(b.StrictMode,{children:n.jsx(bre,{})}));export{l0 as g};
706
+ ${_e?"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 ${Ds.cls}`,children:Ds.label})]}),n.jsx("div",{className:"text-[13px] font-medium leading-snug text-fg-primary line-clamp-2 mb-1",children:Et.title}),Et.description&&n.jsx("div",{className:"text-[11px] text-fg-tertiary line-clamp-1 mb-1.5",children:Et.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:[qr&&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:qr.name,children:qr.name}),n.jsx("span",{className:"text-[10px] text-fg-tertiary",children:Et.priority}),n.jsxs("span",{className:"text-[10px] text-fg-quaternary",children:["by ",ie]})]}),n.jsx("div",{className:"flex items-center gap-1",children:Et.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:["📋 ",Et.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:Ze=>{Ze.stopPropagation(),Xr(Et.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:Ze=>{Ze.stopPropagation(),Rt(Et.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-${Et.id}`)}else{const Et=Cn.data,Ds=Et.subtasks?.length??0,Ls=l[Et.status],Fs=Et.status==="pending",qr=Et.taskType==="scheduled"&&!!Et.scheduleConfig,ie=qr?Et.scheduleConfig.every?s("work:task.everyInterval",{interval:Et.scheduleConfig.every}):Et.scheduleConfig.cron?s("work:task.cronLabel"):s("work:task.scheduledShort"):null,_e=T==="all"&&Et.projectId?N.find(bs=>bs.id===Et.projectId)?.name:null,Ze=Et.requirementId?I.find(bs=>bs.id===Et.requirementId)?.title:null,An=Et.createdBy?bd(Et.createdBy,L,W)??Et.createdBy:null,ia=at?.id===Et.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":Et.title,draggable:!Fs,onDragStart:bs=>!Fs&&ja(bs,Et),onDragEnd:Gs,onClick:()=>Yr(Et),onKeyDown:bs=>bs.key==="Enter"&&Yr(Et),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":qr?"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[Et.priority]??"bg-gray-400"}`,title:Et.priority}),qr&&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"})})}),qr&&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:Et.title}),Et.description&&n.jsx("div",{className:"text-[11px] text-fg-tertiary line-clamp-1 mb-1.5",children:Et.description}),(_e||Ze||Et.blockedBy&&Et.blockedBy.length>0)&&n.jsxs("div",{className:"flex flex-wrap gap-1 mb-1.5",children:[_e&&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:_e,children:_e}),Ze&&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:Ze,children:["# ",Ze]}),Et.blockedBy&&Et.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:["⏳ ",Et.blockedBy.length," dep",Et.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:An&&n.jsxs("span",{className:"text-[10px] text-fg-quaternary",title:`by ${An}`,children:["by ",An]})}),n.jsxs("div",{className:"flex items-center gap-1.5",children:[Ds>0&&n.jsxs("span",{className:"text-[10px] text-fg-tertiary",children:["⋮ ",Ds]}),Et.notes&&Et.notes.length>0&&n.jsxs("span",{className:"text-[10px] text-fg-tertiary",children:["📝 ",Et.notes.length]}),Et.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 ${o0[L.find(bs=>bs.id===Et.assignedAgentId)?.status??""]??"bg-gray-500"}`}),L.find(bs=>bs.id===Et.assignedAgentId)?.name??Et.assignedAgentId.slice(0,8)]})]})]})]},Et.id)}})})()}),en&&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(kj,{req:Je,agents:L,projects:N,allTasks:Object.values(F).flat(),users:W,onClose:()=>{rt(null)},onApprove:ae=>{Xr(ae)},onReject:ae=>{Rt(ae)},onCancel:ae=>{ka(ae),rt(null)},onStatusChange:async(ae,Ye)=>{try{await de.requirements.updateStatus(ae,Ye),Gt(`Requirement status → ${Ye}`),Ir({requirementId:ae}),yn(),_t()}catch(lt){Gt(`Error: ${lt}`)}},onRefresh:yn,authUser:e,onTaskClick:ae=>{ct(ae)},onCreateTask:(ae,Ye)=>{ze(ae),Ye&&nt(Ye),Y(!0)},onProjectClick:Ar,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(gj,{task:at,agents:L,projects:N,requirements:I,allTasks:Object.values(F).flat(),users:W,onClose:sa,onRefresh:ji,authUser:e,scrollToComments:ur,onScrollToCommentsDone:()=>va(!1),onReqClick:ae=>{rt(Ye=>Ye?.id===ae.id?null:ae)},onProjectClick:Ar})})]}):at?n.jsx(gj,{task:at,agents:L,projects:N,requirements:I,allTasks:Object.values(F).flat(),users:W,onClose:Bs,onRefresh:ji,authUser:e,scrollToComments:ur,onScrollToCommentsDone:()=>va(!1),onReqClick:ae=>{rt(Ye=>Ye?.id===ae.id?null:ae)},onProjectClick:Ar}):Je?n.jsx(kj,{req:Je,agents:L,projects:N,allTasks:Object.values(F).flat(),users:W,onClose:Bs,onApprove:ae=>{Xr(ae)},onReject:ae=>{Rt(ae)},onCancel:ae=>{ka(ae),Bs()},onStatusChange:async(ae,Ye)=>{try{await de.requirements.updateStatus(ae,Ye),Gt(`Requirement status → ${Ye}`),Ir({requirementId:ae}),yn(),_t()}catch(lt){Gt(`Error: ${lt}`)}},scrollToComments:ur,onScrollToCommentsDone:()=>va(!1),onRefresh:yn,authUser:e,onTaskClick:ae=>{ct(ae),u&&(C(!0),history.pushState({mobileDetail:Te.WORK},"",window.location.hash))},onCreateTask:(ae,Ye)=>{ze(ae),Ye&&nt(Ye),Y(!0)},onProjectClick:Ar,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:()=>{Y(!1),Ke("")},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=>be(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:De,onChange:ae=>He(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:Qe,onChange:ae=>{nt(ae),ze("")},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"&&(!Qe||ae.projectId===Qe)).map(ae=>({value:ae.id,label:ae.title}))],value:gt,onChange:ze,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:Oe,onChange:Ee,placeholder:s("work:task.selectAgent"),noMatchesText:s("work:task.noMatches")})]}),n.jsxs("div",{children:[n.jsxs("label",{className:"block text-sm text-fg-secondary mb-1.5",children:[s("work:task.reviewerRequired")," ",n.jsx("span",{className:"text-red-500",children:"*"})]}),n.jsx(ku,{options:[...W.map(ae=>({value:`human:${ae.id}`,label:ae.name})),...L.filter(ae=>ae.id!==Oe).map(ae=>({value:`agent:${ae.id}`,label:`${ae.name} (${ae.status})`}))],value:fe,onChange:Le,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:ke,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:ce,onAdd:ae=>ue([...ce,ae]),placeholder:s("work:task.selectDependency"),noMatchesText:s("work:task.noMatches")}),ce.length>0&&n.jsx("div",{className:"mt-2 flex flex-wrap gap-1.5",children:ce.map(ae=>{const Ye=Object.values(F).flat().find(lt=>lt.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:()=>ue(ce.filter(lt=>lt!==ae)),className:"ml-0.5 text-amber-600/60 hover:text-amber-600",children:"×"})]},ae)})})]}),Se&&n.jsx("div",{className:"px-3 py-2 bg-red-500/15 text-red-500 text-xs rounded-lg",children:Se}),n.jsxs("div",{className:"flex justify-end gap-3 pt-1",children:[n.jsx("button",{onClick:()=>{Y(!1),Ke("")},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()||!Oe||!fe,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")})]})]})}),pn&&n.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 p-3",onClick:()=>{on(!1),Nr(""),Ce(""),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:Wt,onChange:qt,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:Dr,onChange:ae=>Nr(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"&&Dr.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:rn,onChange:ae=>Ce(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:Ct,onChange:ae=>$t(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")})]})]}),Jn&&n.jsx("div",{className:"px-3 py-2 bg-red-500/15 text-red-500 text-xs rounded-lg",children:Jn}),n.jsxs("div",{className:"flex justify-end gap-3 pt-1",children:[n.jsx("button",{onClick:()=>{on(!1),Nr(""),Ce(""),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:!Dr.trim()||!rn.trim()||!Wt,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")})]})]})}),Ne&&n.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 p-3",onClick:()=>{Rt(null),bt("")},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:Dt,onChange:ae=>Jt(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})]}),Xe&&n.jsx("div",{className:"px-3 py-2 bg-red-500/15 text-red-500 text-xs rounded-lg",children:Xe}),n.jsxs("div",{className:"flex justify-end gap-3",children:[n.jsx("button",{onClick:()=>{Rt(null),bt("")},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:()=>{Rs()},className:"px-4 py-2 text-sm bg-red-600 hover:bg-red-500 rounded-lg text-white",children:s("work:task.reject")})]})]})}),Zn&&n.jsxs("div",{className:"fixed inset-0 z-[60] flex flex-col justify-end",onClick:()=>br(!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:[(it.size>0||ht.size>0||Ve)&&n.jsx("button",{onClick:()=>{Vt(new Set),xt(new Set),ut(!1)},className:"text-[11px] text-brand-500 font-medium",children:s("work:task.clearAll")}),n.jsx("button",{onClick:()=>br(!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=it.has(ae.id),lt=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:()=>Ar(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,lt>0&&n.jsx("span",{className:"text-[9px] text-fg-tertiary",children:lt})]}),Ye&&n.jsx("button",{onClick:()=>{br(!1),or(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:()=>ut(ae=>!ae),className:`w-full text-left px-2.5 py-1.5 rounded-lg text-[11px] transition-all ${Ve?"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=ht.has(ae.id);return n.jsxs("button",{onClick:()=>Qr(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),de.requirements.getComments(e).then(k=>d(k.comments)).catch(()=>{})},[e]),b.useEffect(()=>fn.on("requirement:comment",N=>{if(N.payload?.requirementId===e&&N.payload.comment){const j=N.payload.comment;d(T=>T.some(D=>D.id===j.id)?T:[...T,j]),(j.authorType==="agent"||j.authorId?.startsWith("agt_"))&&(m(T=>{const D=T.filter(M=>M.id!==j.authorId);return D.length===0&&p.current&&(clearTimeout(p.current),p.current=null),D}),y(T=>{const D=new Map(T);return D.delete(j.authorId),D}))}}),[e]),b.useEffect(()=>{if(u.length===0)return;const k=new Set(u.map(j=>j.id));return fn.on("agent:activity_log",j=>{const T=j.payload;if(!T)return;const D=T.agentId;if(!k.has(D))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(D)??[],F];return L.set(D,U),L})}})},[u]);const[g,v]=b.useState(null),S=async(k,N,j,T)=>{let D;j.length>0&&(D=(await de.uploads.upload(j.map(L=>({dataUrl:L.dataUrl,name:L.name})),"comments")).files.map(L=>({type:"image",url:L.url,name:L.name}))),await de.requirements.addComment(e,k,a?.name,D,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(zu,{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(Te.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(Sh,{activities:N,isActive:!0})})]},k.id)})})]}),n.jsx(jS,{agents:r,humans:s,onSubmit:S,replyTo:g,onCancelReply:()=>v(null)})]})}function kj({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(()=>py(N),[N]),T=b.useMemo(()=>E8(N),[N]),D=js(),[M,_]=b.useState(!1),[F,z]=b.useState(e.description),[L,U]=b.useState(!1),[W,q]=b.useState(!1),I=b.useRef(null),[R,E]=b.useState("none"),$=b.useRef(null),X=b.useRef(null),K=b.useRef(80);b.useEffect(()=>{const Y=I.current;if(!Y)return;const me=()=>{const{scrollTop:De,scrollHeight:He,clientHeight:ke}=Y;if(!(He>ke+50)){E("none");return}const Oe=De<30,Ee=De+ke>=He-30;E(Oe?"top":Ee?"bottom":"middle")};me(),Y.addEventListener("scroll",me,{passive:!0});const be=new ResizeObserver(me);return be.observe(Y),()=>{Y.removeEventListener("scroll",me),be.disconnect()}},[]),b.useEffect(()=>{if(M&&X.current){const Y=X.current;Y.style.height="auto",Y.style.height=Math.max(Y.scrollHeight,K.current)+"px",Y.focus()}},[M]),b.useEffect(()=>{if(!y)return;const Y=setTimeout(()=>{const me=I.current;me&&me.scrollTo({top:me.scrollHeight,behavior:"smooth"}),g?.()},300);return()=>clearTimeout(Y)},[y,g]);const P=j[e.status]??{label:e.status,cls:"bg-gray-500/15 text-fg-secondary"},B=e.source==="agent",Z=B&&e.status==="pending",H=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(Y=>Y.id===e.projectId):null,ee=bd(e.createdBy,t,a)??e.createdBy.slice(0,12),se=s.filter(Y=>e.taskIds.includes(Y.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:[D&&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 ${P.cls}`,children:P.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:X,value:F,onChange:Y=>{z(Y.target.value);const me=Y.target;me.style.height="auto",me.style.height=me.scrollHeight+"px"},onBlur:async()=>{if(F!==e.description){U(!0);try{await de.requirements.update(e.id,{description:F}),p?.()}catch{}finally{U(!1)}}_(!1)},onKeyDown:Y=>{Y.key==="Escape"&&(Y.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:()=>{K.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:Y=>Y.key==="Enter"&&(z(e.description),_(!0)),children:e.description?n.jsx(Vr,{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}),B&&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?Y=>Y.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:bd(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(Y=>n.jsxs("span",{className:"text-[10px] bg-surface-elevated text-fg-secondary px-2 py-0.5 rounded-full",children:["#",Y]},Y))}),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 Y=new Map(se.map(pe=>[pe.id,pe]));if(!se.some(pe=>pe.blockedBy?.some(Oe=>Y.has(Oe))))return n.jsx("div",{className:"space-y-1.5",children:se.map(pe=>{const Oe=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 ${o0[pe.status]??"bg-gray-500"}`}),n.jsx("span",{className:"text-xs text-fg-secondary flex-1 truncate",children:pe.title}),Oe&&n.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded shrink-0 ${Oe.cls}`,children:Oe.label})]},pe.id)})});const be=new Map,De=new Set;for(const pe of se)for(const Oe of pe.blockedBy??[])if(Y.has(Oe)){De.add(pe.id);const Ee=be.get(Oe)??[];Ee.push(pe.id),be.set(Oe,Ee)}const He=se.filter(pe=>!De.has(pe.id)),ke=(pe,Oe)=>{const Ee=T[pe.status],fe=(be.get(pe.id)??[]).map(Le=>Y.get(Le)).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:Oe>0?{marginLeft:Oe*20}:void 0,children:[Oe>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 ${o0[pe.status]??"bg-gray-500"}`}),n.jsx("span",{className:"text-xs text-fg-secondary flex-1 truncate",children:pe.title}),Ee&&n.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded shrink-0 ${Ee.cls}`,children:Ee.label})]}),fe.map(Le=>ke(Le,Oe+1))]},pe.id)};return n.jsx("div",{className:"space-y-1.5",children:He.map(pe=>ke(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(D8,{entityType:"requirement",entityId:e.id})]}),R!=="none"&&R!=="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"})})}),R!=="none"&&R!=="bottom"&&n.jsx("button",{onClick:()=>{const Y=I.current;Y&&Y.scrollTo({top:Y.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:Y=>{Y.target.value!==e.status&&m(e.id,Y.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(Y=>{const me=j[Y],be=Y===e.status||(t1[e.status]?.has(Y)??!1);return n.jsx("option",{value:Y,disabled:!be,children:me?.label??Y},Y)})}),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"}),H&&!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")})]}),W&&n.jsx(Xc,{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 D8({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"?de.tasks.getHistory:de.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 Ri(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 Kne(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 Wne({artifact:e,mode:t}){const{t:r}=kt(["builder","common"]),s=Kne(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=Ri(l?.env),g=Ri(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"})]}),Ri(e.tags).length>0&&n.jsx("div",{className:"flex flex-wrap gap-1",children:Ri(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"})}),Ri(e.tags).length>0&&n.jsx("div",{className:"flex flex-wrap gap-1",children:Ri(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)]})]}),Ri(p.skills).length>0&&n.jsx("div",{className:"mt-1 ml-7 flex flex-wrap gap-1",children:Ri(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}),Ri(e.tags).length>0&&n.jsx("div",{className:"flex flex-wrap gap-1",children:Ri(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 qc={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"}},jj=["file","directory"];function cf(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 Nj({authUser:e,previewMode:t,previewData:r}={}){const{t:s}=kt(["deliverables","common"]),a=js(),i=yd(Te.DELIVERABLES),l=Qu({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 Ne=()=>{m.current&&u(!1)};return window.addEventListener("popstate",Ne),()=>window.removeEventListener("popstate",Ne)},[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??[]),[D,M]=b.useState(!r),[_,F]=b.useState(""),[z,L]=b.useState(""),[U,W]=b.useState(""),[q,I]=b.useState(""),[R,E]=b.useState(""),[$,X]=b.useState(""),[K,P]=b.useState(""),[B,Z]=b.useState("date"),[H,J]=b.useState(()=>r?.initialSelectedId&&r.items?r.items.find(Ne=>Ne.id===r.initialSelectedId)??r.items[0]??null:r?.items?.[0]??null),[Q,ee]=b.useState(null),[se,Y]=b.useState(""),[me,be]=b.useState(!1),[De,He]=b.useState(!1),[ke,pe]=b.useState(new Set),Oe=b.useMemo(()=>[{id:"date"},{id:"project"},{id:"agent"},{id:"type"}],[]),Ee=b.useCallback(Ne=>{Z(Ne),pe(new Set)},[]),fe=hl(Oe,B,Ee),Le=b.useRef(null),[Qe,nt]=b.useState("file"),[gt,ze]=b.useState(""),[ce,ue]=b.useState(""),[Me,ne]=b.useState(""),[he,Be]=b.useState(""),[Se,Ke]=b.useState(""),[at,ct]=b.useState(null),[Je,rt]=b.useState("markdown"),[ht,xt]=b.useState(null),[Ve,ut]=b.useState(!1),[it,Vt]=b.useState(!1),[Nn,Un]=b.useState(!1),[mn,Tn]=b.useState(null),[$n,dn]=b.useState(""),[bn,nr]=b.useState(new Set),ir=b.useRef(void 0),jr=(Ne,Rt)=>{ee({type:Ne,text:Rt}),setTimeout(()=>ee(null),3e3)},xr=async Ne=>{await F1(Ne)?(Un(!0),setTimeout(()=>Un(!1),1500)):jr("error",s("detail.copyFailed"))},rr=b.useMemo(()=>new Map(j.map(Ne=>[Ne.id,Ne])),[j]),Ln=b.useMemo(()=>new Map(k.map(Ne=>[Ne.id,Ne])),[k]);b.useEffect(()=>{t||(de.projects.list().then(Ne=>N(Ne.projects)).catch(()=>{}),de.agents.list().then(Ne=>T(Ne.agents??[])).catch(()=>{}),de.system.storage().then(Ne=>dn(Ne.dataDir+"/shared")).catch(()=>{}),de.deliverables.checkHealth().then(Ne=>nr(new Set(Ne.missingFiles))).catch(()=>{}))},[t]),b.useEffect(()=>(ir.current=setTimeout(()=>L(_),300),()=>clearTimeout(ir.current)),[_]);const Qn=b.useMemo(()=>({q:z||void 0,projectId:q||void 0,agentId:R||void 0,type:U||void 0,status:$||void 0,artifactType:K||void 0}),[z,q,R,U,$,K]),Vn=b.useCallback(async()=>{M(!0);try{const{results:Ne,total:Rt}=await de.deliverables.search({...Qn,offset:0,limit:p});y(Ne),v(Rt)}catch{y([]),v(0)}M(!1)},[Qn]),Zn=b.useCallback(async()=>{if(!(S||h.length>=g)){C(!0);try{const{results:Ne,total:Rt}=await de.deliverables.search({...Qn,offset:h.length,limit:p});y(Dt=>[...Dt,...Ne]),v(Rt)}catch{}C(!1)}},[Qn,h.length,g,S]);b.useEffect(()=>{t||Vn()},[Vn,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(Ne=>Ne.id===r.initialSelectedId)??r.items?.[0]??null))},[t,r]),b.useEffect(()=>{if(t||!i)return;const Ne=fn.on("deliverable:created",()=>Vn()),Rt=fn.on("deliverable:updated",()=>Vn()),Dt=fn.on("deliverable:removed",()=>Vn());return()=>{Ne(),Rt(),Dt()}},[Vn,i,t]);const br=b.useRef(null),Bn=b.useRef(h);Bn.current=h;const Xt=b.useCallback(Ne=>{const Rt=Jt=>{J(Jt),a&&(u(!0),history.pushState({mobileDetail:Te.DELIVERABLES},"",window.location.hash))},Dt=Bn.current.find(Jt=>Jt.id===Ne);if(Dt){Rt(Dt);return}de.deliverables.get(Ne).then(Jt=>{Jt.deliverable&&Rt(Jt.deliverable)}).catch(()=>{})},[a]);b.useEffect(()=>{if(t)return;const Ne=localStorage.getItem("markus_nav_openDeliverable");Ne&&(localStorage.removeItem("markus_nav_openDeliverable"),Bn.current.length>0?Xt(Ne):br.current=Ne);const Rt=Dt=>{const Jt=Dt.detail;Jt?.params?.openDeliverable&&(localStorage.removeItem("markus_nav_openDeliverable"),Xt(Jt.params.openDeliverable))};return window.addEventListener("markus:navigate",Rt),()=>window.removeEventListener("markus:navigate",Rt)},[Xt,t]),b.useEffect(()=>{const Ne=br.current;!Ne||h.length===0||(br.current=null,Xt(Ne))},[h,Xt]);const pn=b.useCallback(()=>{const Ne=Le.current;!Ne||D||S||h.length>=g||Ne.scrollHeight<=Ne.clientHeight+100&&Zn()},[D,S,h.length,g,Zn]);b.useEffect(()=>{const Ne=Le.current;if(!Ne)return;const Rt=()=>{Ne.scrollTop+Ne.clientHeight>=Ne.scrollHeight-100&&Zn()};return Ne.addEventListener("scroll",Rt,{passive:!0}),()=>Ne.removeEventListener("scroll",Rt)},[Zn]),b.useEffect(()=>{pn()},[pn,ke]);const on=b.useMemo(()=>{const Ne=new Map;for(const Dt of h){let Jt,Jn;if(B==="project")Jt=Dt.projectId??"_none",Jn=Dt.projectId?Ln.get(Dt.projectId)?.name??Dt.projectId:s("noProject");else if(B==="agent")Jt=Dt.agentId??"_none",Jn=Dt.agentId?rr.get(Dt.agentId)?.name??Dt.agentId:s("common:unknown");else if(B==="type")Jt=Dt.type,Jn=Dt.type.charAt(0).toUpperCase()+Dt.type.slice(1);else{const xe=new Date(Dt.updatedAt);Jt=`${xe.getFullYear()}-${String(xe.getMonth()+1).padStart(2,"0")}-${String(xe.getDate()).padStart(2,"0")}`,Jn=Jt}Ne.has(Jt)||Ne.set(Jt,{label:Jn,items:[]}),Ne.get(Jt).items.push(Dt)}const Rt=[...Ne.entries()];return B==="date"?Rt.sort((Dt,Jt)=>Jt[0].localeCompare(Dt[0])):Rt.sort((Dt,Jt)=>Dt[1].label.localeCompare(Jt[1].label)),Rt},[h,B,Ln,rr,s]),Dr=async()=>{if(!(!gt.trim()||!ce.trim())){He(!0);try{await de.deliverables.create({type:Qe,title:gt,summary:ce,reference:Me,projectId:he||void 0,tags:Se.split(",").map(Ne=>Ne.trim()).filter(Boolean)}),be(!1),jr("success",s("createModal.created")),Vn()}catch(Ne){jr("error",s("common:error",{message:String(Ne)}))}He(!1)}},Nr=async Ne=>{Y("remove");try{await de.deliverables.remove(Ne.id),jr("success",s("removed")),J(null),Vn()}catch(Rt){jr("error",s("common:error",{message:String(Rt)}))}Y("")},rn=()=>{Nt.navigate(Te.BUILDER)},Ce=async Ne=>{if(Ne.reference&&!cf(Ne.reference)){if(Ne.type==="directory"){Vt(!0);return}ut(!0);try{const Rt=await de.files.preview(Ne.reference);Rt.type==="image"&&Rt.mimeType?xt({src:`data:${Rt.mimeType};base64,${Rt.content}`,name:Rt.name}):(ct(Rt.content),rt(zS({format:Ne.format,reference:Ne.reference,content:Rt.content})))}catch{ct(null),Ne.type==="file"&&Vt(!0)}ut(!1)}};b.useEffect(()=>{t||(ct(null),rt("markdown"),xt(null),Vt(!1),H&&Ce(H))},[H?.id,t]);const Ct=b.useCallback(Ne=>{pe(Rt=>{const Dt=new Set(Rt);return Dt.has(Ne)?Dt.delete(Ne):Dt.add(Ne),Dt})},[]),$t=b.useCallback(()=>{ke.size===on.length?pe(new Set):pe(new Set(on.map(([Ne])=>Ne)))},[ke.size,on]),Wt=()=>{ze(""),ue(""),ne(""),Ke(""),nt("file"),k.length>0&&Be(k[0].id),be(!0)},qt=Ne=>{J(Ne),a&&(u(!0),history.pushState({mobileDetail:Te.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.jsxs("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("button",{onClick:Wt,className:"text-xs px-2.5 py-1 rounded-lg bg-brand-600 hover:bg-brand-500 text-white transition-colors shrink-0",children:s("create")})]}),n.jsx("input",{value:_,onChange:Ne=>F(Ne.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"}),$n&&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:$n}),n.jsx("button",{onClick:()=>{de.system.openPath($n)},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(ju,{label:s("filters.allTypes"),value:"",current:U||K||"",onClick:()=>{W(""),P("")}}),jj.map(Ne=>n.jsx(ju,{label:`${qc[Ne]?.icon??""} ${Ne}`,value:Ne,current:U,onClick:Rt=>{W(Rt),P("")}},Ne)),["agent","team","skill"].map(Ne=>n.jsx(ju,{label:`${Fl[Ne].icon} ${s(`artifactTypes.${Ne}`)}`,value:Ne,current:K,onClick:Rt=>{P(Rt),W("")}},Ne))]}),k.length>0&&n.jsxs("div",{className:"flex gap-1 overflow-x-auto scrollbar-hide",children:[n.jsx(ju,{label:s("filters.allProjects"),value:"",current:q,onClick:I}),k.map(Ne=>n.jsx(ju,{label:Ne.name,value:Ne.id,current:q,onClick:I},Ne.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(Ne=>n.jsx("button",{onClick:()=>{Z(Ne),pe(new Set)},className:`px-2 py-1 rounded text-xs transition-colors ${B===Ne?"bg-brand-600 text-white":"bg-surface-elevated text-fg-secondary hover:bg-surface-overlay"}`,children:s(`groupBy.${Ne}`)},Ne)),on.length>1&&n.jsx("button",{onClick:$t,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:ke.size===on.length?s("expandAllTooltip"):s("collapseAllTooltip"),children:ke.size===on.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:Le,className:"flex-1 overflow-y-auto p-2 space-y-1",onTouchStart:a?fe.onTouchStart:void 0,onTouchEnd:a?fe.onTouchEnd:void 0,children:[D?n.jsx("div",{className:"p-4 space-y-3",children:[1,2,3].map(Ne=>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"})]},Ne))}):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:Wt,className:"text-xs px-3 py-1.5 rounded-lg bg-brand-600 hover:bg-brand-500 text-white transition-colors",children:s("empty.createFirst")})]}):on.map(([Ne,Rt])=>{const Dt=ke.has(Ne);return n.jsxs("div",{children:[n.jsxs("button",{onClick:()=>Ct(Ne),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 ${Dt?"":"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:Rt.label}),n.jsxs("span",{className:"text-[10px] text-fg-tertiary shrink-0",children:["(",Rt.items.length,")"]})]}),!Dt&&Rt.items.map(Jt=>n.jsx("button",{onClick:()=>qt(Jt),className:`w-full text-left px-3 py-2 rounded-lg transition-colors ${H?.id===Jt.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:[Jt.artifactType&&Fl[Jt.artifactType]?n.jsx("span",{className:`text-[10px] px-1 py-0.5 rounded font-medium shrink-0 ${Fl[Jt.artifactType].color}`,children:Fl[Jt.artifactType].icon}):n.jsx("span",{className:`text-[10px] px-1 py-0.5 rounded font-medium uppercase shrink-0 ${qc[Jt.type]?.color??"bg-surface-overlay text-fg-secondary"}`,children:qc[Jt.type]?.icon??Jt.type.charAt(0)}),n.jsx("span",{className:"text-sm font-medium text-fg-primary truncate",children:Jt.title}),bn.has(Jt.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[Jt.status]?.color??"bg-surface-elevated text-fg-tertiary"}`,children:s(`common:status.${Jt.status}`,{defaultValue:Jt.status})})]})},Jt.id))]},Ne)}),S&&n.jsxs("div",{className:"flex items-center justify-center gap-2 py-3 text-fg-tertiary",children:[n.jsx(Vx,{})," ",n.jsx("span",{className:"text-[10px]",children:s("common:loadingMore")})]}),!D&&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:H?.title??s("detail.details")})]}),H?n.jsxs("div",{className:"p-6 space-y-4",children:[!t&&bn.has(H.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:H.title}),!t&&n.jsx("button",{onClick:()=>Tn(H),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 ${qc[H.type]?.color??"bg-surface-overlay text-fg-secondary"}`,children:[qc[H.type]?.icon??""," ",H.type]}),H.artifactType&&Fl[H.artifactType]&&n.jsxs("span",{className:`px-2 py-0.5 rounded text-xs font-medium ${Fl[H.artifactType].color}`,children:[Fl[H.artifactType].icon," ",s("detail.builderWithType",{type:s(`artifactTypes.${H.artifactType}`)})]}),H.tags.length>0&&H.tags.map(Ne=>n.jsx("span",{className:"px-2 py-0.5 text-xs bg-surface-elevated text-fg-secondary rounded",children:Ne},Ne))]}),(H.taskId||H.agentId||H.projectId)&&n.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[H.taskId&&n.jsx("button",{onClick:()=>Nt.navigate(Te.WORK,{openTask:H.taskId}),className:"text-xs text-brand-500 hover:underline bg-brand-500/10 px-2 py-0.5 rounded",children:s("links.task",{id:`${H.taskId.slice(0,12)}...`})}),H.agentId&&n.jsx("button",{onClick:()=>Nt.navigate(Te.TEAM,{selectAgent:H.agentId}),className:"text-xs text-blue-600 hover:underline bg-blue-500/10 px-2 py-0.5 rounded",children:s("links.agent",{name:rr.get(H.agentId)?.name??H.agentId.slice(0,12)})}),H.projectId&&n.jsx("button",{onClick:()=>Nt.navigate(Te.WORK,{projectId:H.projectId}),className:"text-xs text-blue-600 hover:underline bg-blue-500/10 px-2 py-0.5 rounded",children:s("links.project",{name:Ln.get(H.projectId)?.name??H.projectId.slice(0,12)})})]}),(H.diffStats||H.testResults)&&n.jsxs("div",{className:"flex gap-3 flex-wrap",children:[H.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:H.diffStats.filesChanged})}),n.jsxs("span",{className:"text-green-600",children:["+",H.diffStats.additions]}),n.jsxs("span",{className:"text-red-500",children:["-",H.diffStats.deletions]})]}),H.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:H.testResults.passed})}),n.jsx("span",{className:"text-red-500",children:s("testResults.failed",{count:H.testResults.failed})}),n.jsx("span",{className:"text-fg-secondary",children:s("testResults.skipped",{count:H.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(H.createdAt).toLocaleDateString()]}),n.jsxs("span",{children:[s("metadata.updated")," ",new Date(H.updatedAt).toLocaleDateString()]}),n.jsx("span",{className:"text-fg-muted select-all",children:H.id.slice(0,12)})]}),H.reference&&!cf(H.reference)&&H.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:()=>{de.files.reveal(H.reference).catch(()=>jr("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:H.reference}),n.jsx("button",{onClick:()=>{de.files.reveal(H.reference).catch(()=>jr("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:()=>xr(H.reference),className:`px-2 py-1 text-[10px] rounded transition-colors shrink-0 ${Nn?"bg-green-500/20 text-green-600":"bg-surface-overlay/50 text-fg-secondary hover:bg-surface-overlay"}`,title:s("detail.copyPath"),children:s(Nn?"common:copied":"common:copy")})]}),H.reference&&!cf(H.reference)&&H.type!=="file"&&H.type!=="directory"&&n.jsx("span",{className:"text-xs text-fg-tertiary font-mono break-all",children:H.reference})]}),H.artifactType&&H.artifactData?n.jsxs("div",{className:"space-y-4",children:[n.jsx("div",{className:"bg-surface-elevated rounded-xl p-5",children:n.jsx(Wne,{artifact:H.artifactData,mode:H.artifactType})}),H.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:H.reference})]}),n.jsx("div",{className:"flex gap-2",children:n.jsx("button",{onClick:rn,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")})}),H.summary&&n.jsx("div",{className:"bg-surface-elevated rounded-xl p-5",children:n.jsx(Vr,{content:H.summary,className:"text-fg-secondary text-sm"})})]}):H.reference&&cf(H.reference)?n.jsxs("div",{className:"space-y-4",children:[H.summary&&n.jsx("div",{className:"bg-surface-elevated rounded-xl p-5",children:n.jsx(Vr,{content:H.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:H.reference}),n.jsx("button",{onClick:()=>window.open(H.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")})]})]}):H.type==="directory"&&H.reference?n.jsxs("div",{className:"space-y-4",children:[H.summary&&n.jsx("div",{className:"bg-surface-elevated rounded-xl p-5",children:n.jsx(Vr,{content:H.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:H.reference}),n.jsx("button",{onClick:()=>{de.files.reveal(H.reference).catch(()=>jr("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:Ve?n.jsxs("div",{className:"flex items-center gap-2 text-fg-tertiary text-sm",children:[n.jsx(Vx,{})," ",s("detail.loadingPreview")]}):ht?n.jsxs("div",{className:"flex flex-col items-center gap-2",children:[n.jsx("img",{src:ht.src,alt:ht.name,className:"max-w-full max-h-[60vh] rounded-lg object-contain"}),n.jsx("span",{className:"text-xs text-fg-tertiary",children:ht.name})]}):at?n.jsx(Y1,{content:at,format:Je,className:"text-fg-secondary text-sm"}):it?n.jsxs("div",{className:"space-y-3",children:[n.jsx("p",{className:"text-sm text-fg-secondary",children:s("detail.cannotPreview",{type:H.type})}),n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx("button",{onClick:()=>{de.files.reveal(H.reference).catch(()=>jr("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:H.reference}),n.jsx("button",{onClick:()=>{de.files.reveal(H.reference).catch(()=>jr("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:()=>xr(H.reference),className:`px-3 py-2 text-xs rounded-lg transition-colors shrink-0 ${Nn?"bg-green-500/20 text-green-600":"bg-surface-overlay/50 text-fg-secondary hover:bg-surface-overlay"}`,children:s(Nn?"common:copied":"common:copy")})]})]}):H.summary?n.jsx(Vr,{content:H.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")})]})})]}),mn&&n.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60",onClick:()=>Tn(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:Ne=>Ne.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:mn.title})})]})]}),n.jsxs("div",{className:"flex justify-end gap-2",children:[n.jsx("button",{onClick:()=>Tn(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 Ne=mn;Tn(null),Nr(Ne)},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")})]})]})}),me&&n.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60",onClick:()=>!De&&be(!1),children:n.jsxs("div",{className:"bg-surface-secondary border border-border-default rounded-xl p-6 w-[36rem] space-y-4",onClick:Ne=>Ne.stopPropagation(),children:[n.jsx("h3",{className:"text-base font-semibold text-fg-primary",children:s("createModal.title")}),n.jsxs("div",{children:[n.jsx("label",{className:"text-xs text-fg-tertiary block mb-1",children:s("createModal.type")}),n.jsx("select",{value:Qe,onChange:Ne=>nt(Ne.target.value),className:"w-full bg-surface-elevated border border-border-default rounded-lg px-3 py-2 text-sm text-fg-primary",children:jj.map(Ne=>n.jsxs("option",{value:Ne,children:[qc[Ne]?.icon??""," ",Ne]},Ne))})]}),n.jsxs("div",{children:[n.jsxs("label",{className:"text-xs text-fg-tertiary block mb-1",children:[s("createModal.titleField")," ",n.jsx("span",{className:"text-red-500",children:s("createModal.required")})]}),n.jsx("input",{value:gt,onChange:Ne=>ze(Ne.target.value),placeholder:s("createModal.titlePlaceholder"),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"})]}),n.jsxs("div",{children:[n.jsxs("label",{className:"text-xs text-fg-tertiary block mb-1",children:[s("createModal.reference")," ",n.jsxs("span",{className:"text-fg-tertiary",children:["(",s("createModal.referenceHint"),")"]})]}),n.jsx("input",{value:Me,onChange:Ne=>ne(Ne.target.value),placeholder:s("createModal.referencePlaceholder"),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 font-mono"})]}),n.jsxs("div",{children:[n.jsxs("label",{className:"text-xs text-fg-tertiary block mb-1",children:[s("createModal.summary")," ",n.jsx("span",{className:"text-red-500",children:s("createModal.required")})," ",n.jsxs("span",{className:"text-fg-tertiary",children:["(",s("createModal.summaryHint"),")"]})]}),n.jsx("textarea",{value:ce,onChange:Ne=>ue(Ne.target.value),placeholder:s("createModal.summaryPlaceholder"),className:"w-full bg-surface-elevated border border-border-default rounded-lg px-3 py-2 text-sm text-fg-primary h-36 resize-none focus:border-brand-500 focus:outline-none transition-colors font-mono"})]}),n.jsxs("div",{className:"flex gap-4",children:[n.jsxs("div",{className:"flex-1",children:[n.jsxs("label",{className:"text-xs text-fg-tertiary block mb-1",children:[s("createModal.tags")," ",n.jsxs("span",{className:"text-fg-tertiary",children:["(",s("createModal.tagsHint"),")"]})]}),n.jsx("input",{value:Se,onChange:Ne=>Ke(Ne.target.value),placeholder:s("createModal.tagsPlaceholder"),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"})]}),n.jsxs("div",{className:"flex-1",children:[n.jsx("label",{className:"text-xs text-fg-tertiary block mb-1",children:s("createModal.project")}),n.jsxs("select",{value:he,onChange:Ne=>Be(Ne.target.value),className:"w-full bg-surface-elevated border border-border-default rounded-lg px-3 py-2 text-sm text-fg-primary",children:[n.jsx("option",{value:"",children:s("common:none")}),k.map(Ne=>n.jsx("option",{value:Ne.id,children:Ne.name},Ne.id))]})]})]}),n.jsxs("div",{className:"flex justify-end gap-3 pt-1 border-t border-border-default",children:[n.jsx("button",{onClick:()=>be(!1),disabled:De,className:"text-sm text-fg-tertiary hover:text-fg-secondary disabled:opacity-50 transition-colors py-2",children:s("common:cancel")}),n.jsxs("button",{onClick:Dr,disabled:De||!gt.trim()||!ce.trim(),className:"bg-brand-600 hover:bg-brand-500 text-white text-sm px-4 py-2 rounded-lg disabled:opacity-50 flex items-center gap-2 transition-colors",children:[De&&n.jsx(Vx,{}),s(De?"common:creating":"common:create")]})]})]})})]})}function ju({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 Vx(){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 Gc(e){return e<.01?`$${e.toFixed(4)}`:`$${e.toFixed(2)}`}function Yne(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 Sj({authUser:e}){const{t}=kt(["reports","common"]),r=js(),s=yd(Te.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,D]=b.useState("generate"),[M,_]=b.useState([]),[F,z]=b.useState(null),[L,U]=b.useState([]),[W,q]=b.useState(""),[I,R]=b.useState(""),E=Y=>{R(Y),setTimeout(()=>R(""),3e3)},$=b.useCallback(async Y=>{m(!0),h("");try{const{report:me}=await de.reports.generate({period:Y,scope:"org",orgId:"default"});d(me)}catch(me){h(String(me)),d(null)}m(!1)},[]),X=b.useCallback(()=>{de.usage.summary().then(Y=>g(Y.usage)).catch(()=>{}),de.usage.agents().then(Y=>S(Y.agents)).catch(()=>{})},[]),K=b.useCallback(async()=>{try{const{reports:Y}=await de.reports.list();_(Y)}catch{}},[]),P=b.useCallback(async Y=>{z(Y);try{const{feedback:me}=await de.reports.getFeedback(Y.id);U(me)}catch{U([])}},[]);b.useEffect(()=>{$(a)},[a,$]),b.useEffect(()=>{if(!s)return;X();const Y=setInterval(X,3e4);return()=>clearInterval(Y)},[X,s]),b.useEffect(()=>{T==="history"&&K()},[T,K]);const B=b.useMemo(()=>[...v].sort((Y,me)=>{const be=Y[C],De=me[C];return N?De-be:be-De}),[v,C,N]),Z=v.reduce((Y,me)=>Y+me.estimatedCost,0),H=v.reduce((Y,me)=>Y+me.tokensUsedToday,0),J=v.reduce((Y,me)=>Y+(me.costToday??0),0),Q=Math.max(1,...v.map(Y=>Y.totalTokens)),ee=Y=>{C===Y?j(!N):(k(Y),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:()=>D("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:()=>D("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(Y=>n.jsx("button",{onClick:()=>i(Y),className:`px-3 py-1.5 text-xs rounded-md transition-colors ${a===Y?"bg-surface-overlay text-fg-primary shadow-sm":"text-fg-tertiary hover:text-fg-secondary"}`,children:t(`period.${Y}`)},Y))})]})]}),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(Y=>n.jsxs("button",{onClick:()=>P(Y),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:Y.type})}),n.jsxs("div",{className:"text-xs text-fg-tertiary mt-0.5",children:[new Date(Y.periodStart).toLocaleDateString()," — ",new Date(Y.periodEnd).toLocaleDateString()]})]}),Y.plan&&n.jsx("span",{className:`px-2 py-0.5 rounded-full text-[10px] font-medium shrink-0 ${Y.plan.status==="approved"?"bg-green-500/10 text-green-600":Y.plan.status==="rejected"?"bg-red-500/10 text-red-500":"bg-amber-500/10 text-amber-600"}`,children:Y.plan.status==="pending"?t("upcomingPlan.planPending"):t("upcomingPlan.planStatus",{status:Y.plan.status})}),n.jsx("span",{className:"text-[10px] text-fg-tertiary shrink-0",children:new Date(Y.generatedAt).toLocaleDateString()})]},Y.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(Di,{label:t("taskMetrics.completed"),value:F.metrics.tasksCompleted,color:"text-green-600"}),n.jsx(Di,{label:t("taskMetrics.inProgress"),value:F.metrics.tasksInProgress,color:"text-brand-500"}),n.jsx(Di,{label:t("taskMetrics.created"),value:F.metrics.tasksCreated,color:"text-blue-600"}),n.jsx(Di,{label:t("taskMetrics.blocked"),value:F.metrics.tasksBlocked,color:"text-amber-600"}),n.jsx(Di,{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:Gc(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((Y,me)=>n.jsxs("div",{className:"flex items-center justify-between text-xs",children:[n.jsx("span",{className:"text-fg-secondary",children:Y.agentId}),n.jsx("span",{className:"text-fg-tertiary tabular-nums",children:t("costOverview.byAgentRow",{tokens:ho(Y.tokens),cost:Gc(Y.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(Uc,{title:t("taskSummary.completedCount",{count:F.taskSummary.completed.length}),color:"emerald",items:F.taskSummary.completed.map(Y=>({id:Y.id,label:Y.title,sub:Y.agent}))}),F.taskSummary.inProgress.length>0&&n.jsx(Uc,{title:t("taskSummary.inProgressCount",{count:F.taskSummary.inProgress.length}),color:"indigo",items:F.taskSummary.inProgress.map(Y=>({id:Y.id,label:Y.title,sub:Y.agent}))}),F.taskSummary.blocked.length>0&&n.jsx(Uc,{title:t("taskSummary.blockedCount",{count:F.taskSummary.blocked.length}),color:"amber",items:F.taskSummary.blocked.map(Y=>({id:Y.id,label:Y.title,sub:Y.reason||Y.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((Y,me)=>n.jsx("li",{children:Y},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((Y,me)=>n.jsx("li",{children:Y},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:Y}=await de.reports.approvePlan(F.id,{approvedBy:e?.id??"unknown"});z(Y),E(t("upcomingPlan.planApproved")),K()}catch(Y){E(t("common:error",{message:String(Y)}))}},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 Y=prompt(t("upcomingPlan.rejectionReason"));if(Y)try{const{report:me}=await de.reports.rejectPlan(F.id,{rejectedBy:e?.id??"unknown",reason:Y});z(me),E(t("upcomingPlan.planRejected")),K()}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((Y,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 ${Y.priority==="high"?"bg-red-500/10 text-red-500":Y.priority==="medium"?"bg-amber-500/10 text-amber-600":"bg-gray-500/10 text-fg-tertiary"}`,children:Y.priority}),n.jsx("span",{children:Y.title}),Y.assignee&&n.jsx("span",{className:"text-[10px] text-fg-tertiary ml-auto",children:Y.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(Y=>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:Y.authorName}),n.jsx("span",{children:Y.type}),n.jsx("span",{children:new Date(Y.createdAt).toLocaleDateString()})]}),n.jsx("p",{className:"text-xs text-fg-secondary",children:Y.content})]},Y.id))}),n.jsxs("div",{className:"flex gap-2",children:[n.jsx("input",{value:W,onChange:Y=>q(Y.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:Y=>{Y.key==="Enter"&&W.trim()&&de.reports.addFeedback(F.id,{author:e?.id??"unknown",type:"comment",content:W.trim()}).then(({feedback:me})=>{U(be=>[...be,me]),q(""),E(t("feedback.added"))}).catch(me=>E(t("common:error",{message:String(me)})))}}),n.jsx("button",{onClick:()=>{W.trim()&&de.reports.addFeedback(F.id,{author:e?.id??"unknown",type:"comment",content:W.trim()}).then(({feedback:Y})=>{U(me=>[...me,Y]),q(""),E(t("feedback.added"))}).catch(Y=>E(t("common:error",{message:String(Y)})))},disabled:!W.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(df,{label:t("usage.llmTokens"),value:ho(y.llmTokens),color:"text-brand-500"}),n.jsx(df,{label:t("usage.toolCalls"),value:ho(y.toolCalls),color:"text-blue-600"}),n.jsx(df,{label:t("usage.messages"),value:ho(y.messages),color:"text-green-600"}),y.storageBytes>0&&n.jsx(df,{label:t("usage.storage"),value:Yne(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(Di,{label:t("taskMetrics.completed"),value:l.metrics.tasksCompleted,color:"text-green-600"}),n.jsx(Di,{label:t("taskMetrics.inProgress"),value:l.metrics.tasksInProgress,color:"text-brand-500"}),n.jsx(Di,{label:t("taskMetrics.created"),value:l.metrics.tasksCreated,color:"text-blue-600"}),n.jsx(Di,{label:t("taskMetrics.blocked"),value:l.metrics.tasksBlocked,color:"text-amber-600"}),n.jsx(Di,{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:Gc(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(H)}),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:Gc(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(Uc,{title:t("taskSummary.completedCount",{count:l.taskSummary.completed.length}),color:"emerald",items:l.taskSummary.completed.map(Y=>({id:Y.id,label:Y.title,sub:Y.agent}))}),l.taskSummary.inProgress.length>0&&n.jsx(Uc,{title:t("taskSummary.inProgressCount",{count:l.taskSummary.inProgress.length}),color:"indigo",items:l.taskSummary.inProgress.map(Y=>({id:Y.id,label:Y.title,sub:Y.agent}))}),l.taskSummary.blocked.length>0&&n.jsx(Uc,{title:t("taskSummary.blockedCount",{count:l.taskSummary.blocked.length}),color:"amber",items:l.taskSummary.blocked.map(Y=>({id:Y.id,label:Y.title,sub:Y.reason||Y.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(Nu,{label:t("perAgentUsage.totalTokens"),col:"totalTokens",current:C,desc:N,onSort:ee}),n.jsx(Nu,{label:t("perAgentUsage.today"),col:"tokensUsedToday",current:C,desc:N,onSort:ee}),n.jsx(Nu,{label:t("perAgentUsage.requests"),col:"requestCount",current:C,desc:N,onSort:ee}),n.jsx(Nu,{label:t("perAgentUsage.toolCalls"),col:"toolCalls",current:C,desc:N,onSort:ee}),n.jsx(Nu,{label:t("perAgentUsage.estCost"),col:"estimatedCost",current:C,desc:N,onSort:ee,align:"right"})]})}),n.jsx("tbody",{children:B.map(Y=>n.jsx(Xne,{agent:Y,maxTokens:Q},Y.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((Y,me)=>Y+me.totalTokens,0))}),n.jsx("td",{className:"px-4 py-3 text-sm font-medium text-fg-secondary tabular-nums",children:ho(H)}),n.jsx("td",{className:"px-4 py-3 text-sm font-medium text-fg-secondary tabular-nums",children:v.reduce((Y,me)=>Y+me.requestCount,0)}),n.jsx("td",{className:"px-4 py-3 text-sm font-medium text-fg-secondary tabular-nums",children:v.reduce((Y,me)=>Y+me.toolCalls,0)}),n.jsx("td",{className:"px-4 py-3 text-sm font-medium text-right text-fg-secondary tabular-nums",children:Gc(Z)})]})})]})})]})]})})}function Di({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 Uc({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(Te.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 df({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 Nu({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 Xne({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(Te.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:Gc(e.estimatedCost)})]})}const uf={urgent:"bg-red-500",high:"bg-amber-500",normal:"bg-blue-500",low:"bg-gray-400"},Vc={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"},Cj={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 Kc(e,t){const r=Date.now()-new Date(e).getTime(),s=Math.floor(r/6e4);if(s<1)return t("common:time.now");if(s<60)return t("common:time.minutesAgo",{count:s});const a=Math.floor(s/60);return a<24?t("common:time.hoursAgo",{count:a}):t("common:time.daysAgo",{count:Math.floor(a/24)})}function mf(e,t){const r=e.actionType;if(r==="open_chat")return t("team:notifications.actionHints.openChat");if(r==="navigate")return t("team:notifications.actionHints.viewDetails");const s=e.metadata??{};switch(e.type){case"task_completed":case"task_created":case"task_review":case"task_failed":return s.taskId?t("team:notifications.actionHints.viewTask"):null;case"requirement_created":case"requirement_decision":return s.requirementId?t("team:notifications.actionHints.viewRequirement"):null;case"agent_report":return s.agentId?t("team:notifications.actionHints.viewAgent"):null;case"direct_message":return t("team:notifications.actionHints.openChat");case"group_message":return t("team:notifications.actionHints.openChat");case"approval_request":return t("team:notifications.actionHints.viewApproval");default:return s.taskId?t("team:notifications.actionHints.viewTask"):s.requirementId?t("team:notifications.actionHints.viewRequirement"):s.agentId?t("team:notifications.actionHints.viewAgent"):null}}function Qne(){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 L8({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),[D,M]=b.useState({}),[_,F]=b.useState(0),z=b.useRef(null),L=b.useRef(null),[U,W]=b.useState({top:0,left:0,width:448,maxHeight:576}),q=b.useRef(null),I=b.useRef(!1),[R,E]=b.useState(!0),[$,X]=b.useState(!1),K=b.useRef(null),P=b.useRef("approvals"),B=30,Z=b.useCallback(async()=>{try{const[ne,he]=await Promise.all([de.notifications.list(t,!1,{limit:B,offset:0}),de.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>=B),C(he.approvals),!I.current){const Be=he.approvals.filter(Se=>Se.status==="pending").length;q.current=Be,I.current=!0}}catch{}},[t]),H=b.useCallback(async()=>{if(!($||!R)){X(!0);try{const ne=await de.notifications.list(t,!1,{limit:B,offset:g.length});ne.notifications.length>0&&v(he=>[...he,...ne.notifications.filter(Be=>!he.some(Se=>Se.id===Be.id))]),E(ne.totalCount!=null?g.length+ne.notifications.length<ne.totalCount:ne.notifications.length>=B)}catch{}X(!1)}},[t,g.length,$,R]),J=b.useCallback(ne=>{const he=ne.detail;if(!he)return;const{taskId:Be,requirementId:Se}=he;!Be&&!Se||v(Ke=>{const at=Ke.filter(ct=>!ct.read&&(Be&&ct.metadata?.taskId===Be||Se&&ct.metadata?.requirementId===Se));if(at.length===0)return Ke;for(const ct of at)de.notifications.markRead(ct.id).catch(()=>{});return F(ct=>Math.max(0,ct-at.length)),Ke.map(ct=>at.some(Je=>Je.id===ct.id)?{...ct,read:!0}:ct)})},[]);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 Se=fn.on("notification:created",()=>Z()),Ke=fn.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),Se(),Ke()}},[Z,J]);const Q=b.useCallback(()=>{if(!z.current)return;const ne=z.current.getBoundingClientRect(),he=window.innerWidth,Be=window.innerHeight,Se=Math.min(448,he-16),Ke=Math.min(576,Be-16);let at=ne.right+8,ct=ne.top;at+Se>he-8&&(at=Math.max(8,he-Se-8)),ct+Ke>Be-8&&(ct=Math.max(8,Be-Ke-8)),W({top:ct,left:at,width:Se,maxHeight:Ke})},[]);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":P.current)},[m]);const ee=new Set(S.filter(ne=>ne.status==="pending").map(ne=>ne.id)),se=new Set(S.map(ne=>ne.id)),Y=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,be=Math.max(0,_-me),De=ee.size,He=be+De;b.useEffect(()=>{q.current!==null&&De>q.current&&Qne(),q.current=De},[De]);const ke=async ne=>{await de.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,Se=ne.actionTarget;if(Be==="open_chat"&&Se)try{const Ke=typeof Se=="string"?JSON.parse(Se):Se;if(Ke.agentId){const at={agentId:Ke.agentId};Ke.sessionId&&(at.sessionId=Ke.sessionId),Nt.navigate(Te.TEAM,at);return}}catch{}if(Be==="navigate"&&Se)try{const Ke=typeof Se=="string"?JSON.parse(Se):Se;if(Ke.path){if(Ke.path.startsWith("/team")){const at={},ct=new URLSearchParams(Ke.path.split("?")[1]||"");for(const[Je,rt]of ct.entries())at[Je]=rt;Nt.navigate(Te.TEAM,at);return}if(Ke.path.startsWith("/work")){const at={},ct=new URLSearchParams(Ke.path.split("?")[1]||"");for(const[Je,rt]of ct.entries())at[Je]=rt;Nt.navigate(Te.WORK,at);return}}}catch{}switch(ne.type){case"approval_request":{const Ke=he.approvalId,at=Ke?S.find(ht=>ht.id===Ke):void 0,ct=at?.details?.taskId??he.taskId,Je=at?.details?.requirementId??he.requirementId,rt=at?.details?.agentId??at?.agentId;ct?Nt.navigate(Te.WORK,{openTask:ct}):Je?Nt.navigate(Te.WORK,{openRequirement:Je}):rt?Nt.navigate(Te.TEAM,{agentId:rt}):Nt.navigate(Te.WORK);break}case"task_completed":case"task_created":case"task_review":case"task_failed":he.taskId?Nt.navigate(Te.WORK,{openTask:he.taskId}):Nt.navigate(Te.WORK);break;case"requirement_created":case"requirement_decision":he.requirementId?Nt.navigate(Te.WORK,{openRequirement:he.requirementId}):Nt.navigate(Te.WORK);break;case"agent_report":case"system":{if(he.agentId){const Ke={agentId:he.agentId};he.sessionId&&(Ke.sessionId=he.sessionId),Nt.navigate(Te.TEAM,Ke)}else Nt.navigate(Te.TEAM);break}case"direct_message":{const Ke=he.senderId;Ke?Nt.navigate(Te.TEAM,{dm:Ke}):Nt.navigate(Te.TEAM);break}case"group_message":{const Ke=he.channel;Ke?Nt.navigate(Te.TEAM,{channel:Ke}):Nt.navigate(Te.TEAM);break}default:he.taskId?Nt.navigate(Te.WORK,{openTask:he.taskId}):he.requirementId?Nt.navigate(Te.WORK,{openRequirement:he.requirementId}):he.projectId?Nt.navigate(Te.WORK,{projectId:he.projectId}):he.agentId&&Nt.navigate(Te.TEAM,{agentId:he.agentId});break}},Oe=async ne=>{ne.read||ke(ne.id);const he=ne.metadata??{},Be=he.taskId,Se=he.requirementId;if(Be||Se){const Ke=g.filter(at=>at.id!==ne.id&&!at.read&&(Be&&at.metadata?.taskId===Be||Se&&at.metadata?.requirementId===Se));for(const at of Ke)ke(at.id)}pe(ne)},Ee=async(ne,he,Be,Se)=>{N(ne);try{const{approval:Ke}=await de.approvals.respond(ne,he,t,Be,Se);C(rt=>rt.map(ht=>ht.id===ne?Ke:ht)),T(null),M(rt=>{const ht={...rt};return delete ht[ne],ht});const at=Ke.details?.taskId,ct=Ke.details?.requirementId,Je=g.filter(rt=>!rt.read&&(rt.type==="approval_request"&&rt.metadata?.approvalId===ne||at&&rt.metadata?.taskId===at||ct&&rt.metadata?.requirementId===ct));if(Je.length>0){for(const ht of Je)de.notifications.markRead(ht.id).catch(()=>{});const rt=new Set(Je.map(ht=>ht.id));v(ht=>ht.map(xt=>rt.has(xt.id)?{...xt,read:!0}:xt)),F(ht=>Math.max(0,ht-Je.length))}rl("/approvals"),rl("/notifications"),rl("/tasks"),rl("/taskboard"),rl("/requirements"),window.dispatchEvent(new CustomEvent("markus:data-changed")),setTimeout(()=>Z(),800)}catch{}N(null)},fe=async()=>{try{if(!t)return;await de.notifications.markAllRead(t),v(ne=>ne.map(he=>({...he,read:!0}))),F(0),rl("/notifications")}catch{const ne=Y.filter(he=>!he.read);await Promise.all(ne.map(he=>de.notifications.markRead(he.id))),v(he=>he.map(Be=>({...Be,read:!0}))),F(0),rl("/notifications")}},Le=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},Qe=ne=>{const he=[];he.push(ne.agentName);const Be=ne.details?.taskTitle,Se=ne.details?.taskId;Be?he.push(Be):Se&&he.push(`Task ${Se.slice(0,8)}`);const Ke=ne.details?.requirementId;return Ke&&!Se&&he.push(`Req ${Ke.slice(0,8)}`),he.join(" · ")},nt=[...S].sort((ne,he)=>new Date(he.requestedAt).getTime()-new Date(ne.requestedAt).getTime()),gt=nt.filter(ne=>ne.status==="pending"),ze=nt.filter(ne=>ne.status!=="pending"),ce=ne=>{const he=ne.details?.taskId,Be=ne.details?.requirementId,Se=ne.details?.agentId??ne.agentId;he?Nt.navigate(Te.WORK,{openTask:he}):Be?Nt.navigate(Te.WORK,{openRequirement:Be}):Se?Nt.navigate(Te.TEAM,{agentId:Se}):Nt.navigate(Te.WORK)},ue=()=>{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"),P.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"),De>0?` (${De})`:""]}),n.jsxs("button",{onClick:()=>{y("notifications"),P.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"),be>0?` (${be})`:""]}),n.jsx("button",{onClick:ue,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:fe,className:"text-[10px] text-brand-500 hover:text-brand-400 transition-colors",children:u("team:notifications.markAllRead")})}),n.jsxs("div",{ref:K,className:"flex-1 overflow-y-auto",onScroll:ne=>{if(h!=="notifications"||!R||$)return;const he=ne.currentTarget;he.scrollTop+he.clientHeight>=he.scrollHeight-80&&H()},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:[gt.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:()=>ce(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:Vc.approval_request})}),n.jsxs("div",{className:"flex-1 min-w-0",children:[n.jsxs("div",{className:"flex items-center gap-2",children:[Le(ne)&&n.jsx("span",{className:"text-[10px] text-amber-500 font-medium shrink-0",children:Le(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:Kc(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(Vr,{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 Se=ne.details?.subType,Ke=Se==="task"||Se==="requirement"||Se==="requirement_resubmit",at=ne.options&&ne.options.length>0,ct=(D[ne.id]??"").trim();return at?n.jsxs("div",{className:"space-y-1.5",children:[ne.options.map((Je,rt)=>n.jsxs("button",{disabled:k===ne.id,onClick:()=>Ee(ne.id,Je.id!=="reject",ct||void 0,Je.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 ${Je.id==="reject"||Je.id==="request_changes"?"border border-border-default text-fg-secondary hover:bg-surface-overlay":"bg-brand-600 text-white hover:bg-brand-700"}`,title:Je.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+rt)}),Je.label]},Je.id)),n.jsxs("div",{className:"flex gap-1.5 mt-1",children:[n.jsx("input",{type:"text",placeholder:u("team:notifications.freeformPlaceholder"),value:D[ne.id]??"",onChange:Je=>M(rt=>({...rt,[ne.id]:Je.target.value})),onKeyDown:Je=>{Je.key==="Enter"&&(D[ne.id]??"").trim()&&Ee(ne.id,!0,(D[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||!(D[ne.id]??"").trim(),onClick:()=>Ee(ne.id,!0,(D[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")})]})]}):Ke?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:()=>Ee(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:()=>Ee(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:D[ne.id]??"",onChange:Je=>M(rt=>({...rt,[ne.id]:Je.target.value})),onKeyDown:Je=>{Je.key==="Enter"&&(D[ne.id]??"").trim()&&Ee(ne.id,!1,(D[ne.id]??"").trim(),"needs_adjustment"),Je.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||!(D[ne.id]??"").trim(),onClick:()=>Ee(ne.id,!1,(D[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:D[ne.id]??"",onChange:Je=>M(rt=>({...rt,[ne.id]:Je.target.value})),onKeyDown:Je=>{Je.key==="Enter"&&Ee(ne.id,!0,ct||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:()=>Ee(ne.id,!0,ct||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:()=>Ee(ne.id,!1,ct||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)}),ze.length>0&&n.jsxs(n.Fragment,{children:[gt.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")}),ze.slice(0,50).map(ne=>n.jsxs("button",{onClick:()=>ce(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"}`}),Le(ne)&&n.jsx("span",{className:"text-[10px] text-fg-tertiary font-medium shrink-0",children:Le(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:Qe(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:Kc(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"&&(Y.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:[Y.map(ne=>{const he=Cj[ne.type]??"text-fg-tertiary";return n.jsxs("div",{role:"button",tabIndex:0,onClick:()=>Oe(ne),onKeyDown:Be=>{(Be.key==="Enter"||Be.key===" ")&&(Be.preventDefault(),Oe(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:Vc[ne.type]??Vc.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 ${uf[ne.priority]??uf.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(Vr,{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:Kc(ne.createdAt,u)}),mf(ne,u)&&n.jsx("span",{className:`text-[10px] font-medium ${he}`,children:mf(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 Se=0,Ke=0;return{onTouchStart:at=>{Se=at.touches[0].clientX,Ke=at.touches[0].clientY},onTouchEnd:at=>{const ct=at.changedTouches[0].clientX-Se,Je=at.changedTouches[0].clientY-Ke;Math.abs(ct)>60&&Math.abs(ct)>Math.abs(Je)*1.5&&(ct<0&&he<ne.length-1&&y(ne[he+1]),ct>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(Se=>n.jsx("button",{onClick:()=>y(Se),className:`flex-1 px-3 py-3 text-sm font-medium transition-colors ${h===Se?"text-fg-primary border-b-2 border-brand-500":"text-fg-tertiary"}`,children:Se==="approvals"?n.jsxs(n.Fragment,{children:[u("team:notifications.approvals"),De>0?` (${De})`:""]}):n.jsxs(n.Fragment,{children:[u("team:notifications.notifications"),be>0?` (${be})`:""]})},Se))}),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:fe,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:[gt.map(Se=>{const Ke=Se.details?.command,at=Ke?Se.description.replace(/\s*Command:.*$/,""):Se.description;return n.jsxs("div",{className:"px-3 py-3 space-y-2.5",children:[n.jsxs("div",{className:"cursor-pointer hover:bg-surface-overlay/50 -mx-3 -mt-3 px-3 pt-3 pb-1 rounded-t-md transition-colors",onClick:()=>ce(Se),children:[n.jsxs("div",{className:"flex items-start gap-2",children:[n.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"text-amber-500 mt-0.5 shrink-0",children:n.jsx("path",{d:Vc.approval_request})}),n.jsxs("div",{className:"flex-1 min-w-0",children:[n.jsxs("div",{className:"flex items-center gap-2",children:[Le(Se)&&n.jsx("span",{className:"text-[10px] text-amber-500 font-medium shrink-0",children:Le(Se)}),n.jsx("span",{className:"text-xs text-fg-primary font-medium truncate",children:Se.title}),n.jsx("span",{className:"text-[10px] text-fg-tertiary shrink-0",children:Kc(Se.requestedAt,u)})]}),n.jsx("div",{className:"text-[11px] text-fg-tertiary mt-0.5",children:Se.agentName})]})]}),n.jsx("div",{className:"mt-2.5 text-[11px] text-fg-secondary leading-relaxed",children:n.jsx(Vr,{content:at,className:"text-[11px] [&_h1]:text-xs [&_h2]:text-[11px] [&_h3]:text-[11px] [&_p]:text-[11px] [&_li]:text-[11px]"})}),Ke&&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:Ke})]}),(()=>{const ct=Se.details?.subType,Je=ct==="task"||ct==="requirement"||ct==="requirement_resubmit",rt=Se.options&&Se.options.length>0,ht=(D[Se.id]??"").trim();return rt?n.jsxs("div",{className:"space-y-1.5",children:[Se.options.map((xt,Ve)=>n.jsxs("button",{disabled:k===Se.id,onClick:()=>Ee(Se.id,xt.id!=="reject",ht||void 0,xt.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 ${xt.id==="reject"||xt.id==="request_changes"?"border border-border-default text-fg-secondary hover:bg-surface-overlay":"bg-brand-600 text-white hover:bg-brand-700"}`,title:xt.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+Ve)}),xt.label]},xt.id)),n.jsxs("div",{className:"flex gap-1.5 mt-1",children:[n.jsx("input",{type:"text",placeholder:u("team:notifications.freeformPlaceholder"),value:D[Se.id]??"",onChange:xt=>M(Ve=>({...Ve,[Se.id]:xt.target.value})),onKeyDown:xt=>{xt.key==="Enter"&&(D[Se.id]??"").trim()&&Ee(Se.id,!0,(D[Se.id]??"").trim(),"custom")},className:"flex-1 px-2.5 py-1.5 text-[11px] bg-surface-overlay border border-border-default rounded-md text-fg-primary placeholder:text-fg-tertiary focus:outline-none focus:ring-1 focus:ring-brand-500/50"}),n.jsx("button",{disabled:k===Se.id||!(D[Se.id]??"").trim(),onClick:()=>Ee(Se.id,!0,(D[Se.id]??"").trim(),"custom"),className:"px-2.5 py-1.5 text-[11px] font-medium bg-brand-600 text-white rounded-md hover:bg-brand-700 disabled:opacity-50 transition-colors",children:u("common:send")})]})]}):Je?n.jsxs("div",{className:"space-y-1.5",children:[n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsxs("button",{disabled:k===Se.id,onClick:()=>Ee(Se.id,!0,void 0,"approve"),className:"px-3 py-1.5 text-[11px] font-medium bg-green-600 text-white rounded-md hover:bg-green-700 disabled:opacity-50 transition-colors inline-flex items-center gap-1.5",children:[n.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:n.jsx("path",{d:"M20 6L9 17l-5-5"})}),u("common:approve")]}),n.jsxs("button",{disabled:k===Se.id,onClick:()=>Ee(Se.id,!1,void 0,"reject"),className:"px-3 py-1.5 text-[11px] font-medium bg-red-600/80 text-white rounded-md hover:bg-red-700 disabled:opacity-50 transition-colors inline-flex items-center gap-1.5",children:[n.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("path",{d:"M18 6L6 18"}),n.jsx("path",{d:"M6 6l12 12"})]}),u("common:reject")]}),j!==Se.id&&n.jsxs("button",{disabled:k===Se.id,onClick:()=>T(Se.id),className:"px-3 py-1.5 text-[11px] font-medium border border-amber-500/50 text-amber-500 rounded-md hover:bg-amber-500/10 disabled:opacity-50 transition-colors inline-flex items-center gap-1.5",children:[n.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("path",{d:"M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"}),n.jsx("path",{d:"M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z"})]}),u("team:notifications.needsAdjustment")]})]}),j===Se.id&&n.jsxs("div",{className:"space-y-1.5",children:[n.jsx("input",{type:"text",autoFocus:!0,placeholder:u("team:notifications.adjustmentPlaceholder"),value:D[Se.id]??"",onChange:xt=>M(Ve=>({...Ve,[Se.id]:xt.target.value})),onKeyDown:xt=>{xt.key==="Enter"&&(D[Se.id]??"").trim()&&Ee(Se.id,!1,(D[Se.id]??"").trim(),"needs_adjustment"),xt.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===Se.id||!(D[Se.id]??"").trim(),onClick:()=>Ee(Se.id,!1,(D[Se.id]??"").trim(),"needs_adjustment"),className:"px-2.5 py-1.5 text-[11px] font-medium bg-amber-600 text-white rounded-md hover:bg-amber-700 disabled:opacity-50 transition-colors",children:u("team:notifications.confirmAdjustment")}),n.jsx("button",{onClick:()=>T(null),className:"px-2.5 py-1.5 text-[11px] font-medium border border-border-default text-fg-secondary rounded-md hover:bg-surface-overlay transition-colors",children:u("common:cancel")})]})]})]}):n.jsxs("div",{className:"space-y-1.5",children:[n.jsx("input",{type:"text",placeholder:u("team:notifications.commentPlaceholder"),value:D[Se.id]??"",onChange:xt=>M(Ve=>({...Ve,[Se.id]:xt.target.value})),onKeyDown:xt=>{xt.key==="Enter"&&Ee(Se.id,!0,ht||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===Se.id,onClick:()=>Ee(Se.id,!0,ht||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===Se.id,onClick:()=>Ee(Se.id,!1,ht||void 0,"reject"),className:"flex-1 px-2.5 py-1.5 text-[11px] font-medium border border-border-default text-fg-secondary rounded-md hover:bg-surface-overlay disabled:opacity-50 transition-colors",children:u("common:reject")})]})]})})()]},Se.id)}),ze.length>0&&n.jsxs(n.Fragment,{children:[gt.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")}),ze.slice(0,50).map(Se=>n.jsxs("button",{onClick:()=>ce(Se),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 ${Se.status==="approved"?"bg-green-500":Se.status==="cancelled"||Se.status==="expired"?"bg-gray-400":"bg-red-500"}`}),n.jsx("span",{className:"text-xs text-fg-secondary truncate flex-1",children:Se.title}),n.jsx("span",{className:`text-[10px] font-medium shrink-0 ${Se.status==="approved"?"text-green-500":Se.status==="cancelled"||Se.status==="expired"?"text-fg-muted":"text-red-500"}`,children:u(`common:status.${Se.status}`,{defaultValue:Se.status})})]}),n.jsxs("div",{className:"flex items-center gap-1.5 mt-0.5 pl-3.5",children:[n.jsx("span",{className:"text-[10px] text-fg-muted truncate",children:Qe(Se)}),n.jsx("span",{className:"text-[10px] text-fg-muted shrink-0",children:"·"}),n.jsx("span",{className:"text-[10px] text-fg-muted shrink-0",children:Kc(Se.respondedAt??Se.requestedAt,u)})]})]},Se.id))]})]})}),n.jsx("div",{className:"w-full shrink-0 h-full overflow-y-auto scrollbar-thin",children:Y.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:Y.slice(0,50).map(Se=>{const Ke=Cj[Se.type]??"text-fg-tertiary";return n.jsxs("button",{onClick:()=>Oe(Se),className:`w-full text-left px-3 py-2.5 flex gap-2.5 transition-colors ${Se.read?"opacity-50 hover:opacity-70":"hover:bg-surface-overlay"}`,children:[n.jsx("div",{className:"shrink-0 mt-0.5",children:n.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:Ke,children:n.jsx("path",{d:Vc[Se.type]??Vc.system})})}),n.jsxs("div",{className:"flex-1 min-w-0",children:[n.jsxs("div",{className:"flex items-center gap-1.5",children:[!Se.read&&n.jsx("span",{className:`w-1.5 h-1.5 rounded-full shrink-0 ${uf[Se.priority]??uf.normal}`}),n.jsx("span",{className:"text-xs text-fg-primary font-medium truncate",children:Se.title})]}),n.jsx("div",{className:"text-[11px] text-fg-tertiary mt-0.5 ",children:n.jsx(Vr,{content:Se.body,className:"text-[11px] [&_h1]:text-xs [&_h2]:text-[11px] [&_h3]:text-[11px] [&_p]:text-[11px] [&_li]:text-[11px] [&_p]:text-fg-tertiary"})}),n.jsxs("div",{className:"flex items-center gap-2 mt-0.5",children:[n.jsx("span",{className:"text-[10px] text-fg-muted",children:Kc(Se.createdAt,u)}),mf(Se,u)&&n.jsx("span",{className:`text-[10px] font-medium ${Ke}`,children:mf(Se,u)})]})]})]},Se.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}),He>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:He>99?u("common:badgeOverLimit"):He})]}),m&&ad.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"})]}),He>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:He>99?u("common:badgeOverLimit"):He})]}),m&&ad.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 Zne({authUser:e}){const{t}=kt("nav"),r=js();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(L8,{collapsed:!1,userId:e?.id,embeddedMode:!0})})]})}function Jne(){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,D,M,_]=await Promise.allSettled([de.agents.list(),de.tasks.list({search:k,pageSize:20}),de.requirements.list(),de.projects.list(),de.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=D.status==="fulfilled"?D.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)):[],W=_.status==="fulfilled"?_.value.results:[];l({agents:F,tasks:z,requirements:L,projects:U,deliverables:W})}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(Te.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(Te.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(ere,{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(Te.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(tre,{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(Te.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(Te.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(Te.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 ere({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 tre({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 nre({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 rre({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===Te.NOTIFICATIONS)return n.jsx(L8,{sidebarMode:!0,collapsed:s,userId:r?.id,label:i(m.id),iconPath:Zx[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(nre,{d:Zx[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.3-rc.2"]})]})}function sre({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 de.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===Te.NOTIFICATIONS,y=m.id===Te.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:Zx[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 I8=["builder","agents","teams","skills"];function are(){const e=localStorage.getItem("markus_nav_storeTab");return e&&(localStorage.removeItem("markus_nav_storeTab"),I8.includes(e))?e:"builder"}function ire({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(are),i=hl(r,s,a);return b.useEffect(()=>{const l=d=>{const u=d.detail;u.params?.storeTab&&I8.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(AS,{}),s==="agents"&&n.jsx(RS,{authUser:e}),s==="teams"&&n.jsx(IS,{}),s==="skills"&&n.jsx(PS,{})]})]})}const Kx="profile",Tj="llm",Aj="search";function ore({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),[D,M]=b.useState(null);b.useEffect(()=>{de.auth.me().then(({user:Ve})=>{Ve.name&&u(Ve.name),Ve.email&&p(Ve.email),Ve.avatarUrl&&M(Ve.avatarUrl)}).catch(()=>{})},[]);const[_,F]=b.useState(null),[z,L]=b.useState(!1),[U,W]=b.useState({}),[q,I]=b.useState(!1),[R,E]=b.useState(null),[$,X]=b.useState(!1),[K,P]=b.useState(!1),[B,Z]=b.useState([]),[H,J]=b.useState(null),[Q,ee]=b.useState(!0),se=b.useRef(!1),[Y,me]=b.useState(null),[be,De]=b.useState({serperApiKey:"",tavilyApiKey:"",bingApiKey:"",googleSearchApiKey:"",googleSearchCx:"",serpApiKey:"",braveApiKey:"",exaApiKey:"",bochaApiKey:""}),[He,ke]=b.useState(!1),[pe,Oe]=b.useState(!1),[Ee,fe]=b.useState(null),Le=b.useRef(!1),Qe=()=>({"Content-Type":"application/json",Authorization:`Bearer ${localStorage.getItem("markus_token")??""}`});b.useEffect(()=>{fetch("/api/settings/llm").then(Ve=>Ve.ok?Ve.json():null).then(Ve=>{if(Ve?.providers){const ut=Object.entries(Ve.providers).filter(([,it])=>it.configured).map(([it,Vt])=>({name:it,displayName:Vt.displayName??it,model:Vt.model??"",apiKeyPreview:Vt.apiKeyPreview}));ut.length>0&&(P(!0),Z(ut))}typeof Ve?.autoFallback=="boolean"&&ee(Ve.autoFallback)}).catch(()=>{})},[]);const nt=s?2:3;b.useEffect(()=>{i===nt&&!se.current&&!K&&(se.current=!0,ze())},[i,K,nt]);const gt=s?3:4;b.useEffect(()=>{i===gt&&!Le.current&&(Le.current=!0,ne())},[i,gt]);const ze=async()=>{L(!0);try{const Ve=await fetch("/api/settings/env-models",{headers:Qe()});if(Ve.ok){const ut=await Ve.json();if(F(ut),ut.detected.length>0){const it={};for(const Vt of ut.detected)it[Vt.provider]=!0;W(it)}}}catch{}finally{L(!1)}},ce=async()=>{if(!_)return;const Ve=_.detected.filter(ut=>U[ut.provider]);if(Ve.length!==0){I(!0),J(null);try{const ut=await fetch("/api/settings/env-models",{method:"POST",headers:Qe(),body:JSON.stringify({providers:Ve.map(it=>({provider:it.provider,model:it.model,baseUrl:it.baseUrl,enabled:!0}))})});if(ut.ok){const it=await ut.json();J({type:"ok",text:it.message}),P(!0)}else J({type:"err",text:a("llm.failedToApply")})}catch{J({type:"err",text:a("common:networkError")})}finally{I(!1)}}},ue=async()=>{X(!0);try{const ut=await(await fetch("/api/settings/import/openclaw",{method:"POST",headers:Qe(),body:JSON.stringify({preview:!0})})).json();"error"in ut||E(ut)}catch{}finally{X(!1)}},Me=async()=>{X(!0),J(null);try{const ut=await(await fetch("/api/settings/import/openclaw",{method:"POST",headers:Qe(),body:JSON.stringify({preview:!1})})).json();"error"in ut?J({type:"err",text:ut.error}):(J({type:"ok",text:a("llm.importedModels",{count:ut.appliedModels})}),P(!0))}catch{J({type:"err",text:a("llm.importFailed")})}finally{X(!1)}},ne=async()=>{try{const Ve=await fetch("/api/settings/search",{headers:Qe()});if(Ve.ok){const ut=await Ve.json();me(ut),ut&&(ut.serper.configured||ut.tavily.configured||ut.bing.configured||ut.google.configured||ut.serpapi.configured||ut.brave.configured||ut.exa.configured||ut.bocha.configured)&&Oe(!0)}}catch{}},he=async()=>{if(be.serperApiKey||be.tavilyApiKey||be.bingApiKey||be.googleSearchApiKey||be.googleSearchCx||be.serpApiKey||be.braveApiKey||be.exaApiKey||be.bochaApiKey){ke(!0),fe(null);try{const ut={};be.serperApiKey&&(ut.serperApiKey=be.serperApiKey),be.tavilyApiKey&&(ut.tavilyApiKey=be.tavilyApiKey),be.bingApiKey&&(ut.bingApiKey=be.bingApiKey),be.googleSearchApiKey&&(ut.googleSearchApiKey=be.googleSearchApiKey),be.googleSearchCx&&(ut.googleSearchCx=be.googleSearchCx),be.serpApiKey&&(ut.serpApiKey=be.serpApiKey),be.braveApiKey&&(ut.braveApiKey=be.braveApiKey),be.exaApiKey&&(ut.exaApiKey=be.exaApiKey),be.bochaApiKey&&(ut.bochaApiKey=be.bochaApiKey);const it=await fetch("/api/settings/search",{method:"POST",headers:Qe(),body:JSON.stringify(ut)});if(it.ok){const Vt=await it.json();me(Vt),Oe(!0),De({serperApiKey:"",tavilyApiKey:"",bingApiKey:"",googleSearchApiKey:"",googleSearchCx:"",serpApiKey:"",braveApiKey:"",exaApiKey:"",bochaApiKey:""}),fe({type:"ok",text:a("search.saved")})}else fe({type:"err",text:a("search.failedToSave")})}catch{fe({type:"err",text:a("common:networkError")})}finally{ke(!1)}}},Be=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 de.auth.updateProfile(d.trim(),m.trim()),h&&await de.auth.changePassword("",h),T(!0)}catch{N(a("profile.errors.saveFailed"))}finally{C(!1)}},Se=[{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")}],Ke=[{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(Hu,{i18nKey:"welcome.description",ns:"onboarding",components:{strong:n.jsx("strong",{className:"text-fg-primary"})}})}),n.jsx("div",{className:"grid grid-cols-2 gap-3 mt-6",children:[[a("welcome.features.operation"),a("welcome.features.operationDesc")],[a("welcome.features.collaboration"),a("welcome.features.collaborationDesc")],[a("welcome.features.memory"),a("welcome.features.memoryDesc")],[a("welcome.features.anyLlm"),a("welcome.features.anyLlmDesc")]].map(([Ve,ut])=>n.jsxs("div",{className:"bg-surface-elevated/50 rounded-lg p-3",children:[n.jsx("div",{className:"font-medium text-fg-primary text-xs",children:Ve}),n.jsx("div",{className:"text-fg-secondary text-xs mt-1",children:ut})]},Ve))})]})},{id:Kx,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(Jj,{currentUrl:D,name:d,size:64,targetType:"user"})}),n.jsxs("div",{className:"space-y-1",children:[n.jsxs("label",{className:"text-xs text-fg-tertiary font-medium",children:[a("profile.nameLabel")," ",n.jsx("span",{className:"text-red-500",children:"*"})]}),n.jsx("input",{type:"text",value:d,onChange:Ve=>u(Ve.target.value),placeholder:a("profile.namePlaceholder"),className:"w-full px-4 py-2.5 bg-surface-elevated border border-border-default rounded-xl text-sm text-fg-primary focus:border-brand-500 outline-none transition-colors",autoFocus:!0})]}),n.jsxs("div",{className:"space-y-1",children:[n.jsxs("label",{className:"text-xs text-fg-tertiary font-medium",children:[a("profile.emailLabel")," ",n.jsx("span",{className:"text-red-500",children:"*"})]}),n.jsx("input",{type:"email",value:m,onChange:Ve=>p(Ve.target.value),placeholder:a("profile.emailPlaceholder"),className:"w-full px-4 py-2.5 bg-surface-elevated border border-border-default rounded-xl text-sm text-fg-primary focus:border-brand-500 outline-none transition-colors"})]}),n.jsxs("div",{className:"space-y-1",children:[n.jsx("label",{className:"text-xs text-fg-tertiary font-medium",children:a("profile.newPasswordLabel")}),n.jsx("input",{type:"password",value:h,onChange:Ve=>y(Ve.target.value),placeholder:a("profile.newPasswordPlaceholder"),className:"w-full px-4 py-2.5 bg-surface-elevated border border-border-default rounded-xl text-sm text-fg-primary focus:border-brand-500 outline-none transition-colors"})]}),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:Ve=>v(Ve.target.value),placeholder:a("profile.confirmPasswordPlaceholder"),className:"w-full px-4 py-2.5 bg-surface-elevated border border-border-default rounded-xl text-sm text-fg-primary focus:border-brand-500 outline-none transition-colors"})]}),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:()=>{Be()},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:Se.map(Ve=>n.jsxs("button",{onClick:()=>r(Ve.value),className:`flex flex-col items-center gap-2 rounded-xl border-2 p-5 transition-all ${t===Ve.value?"border-brand-500 bg-brand-500/10":"border-border-default hover:border-fg-tertiary bg-surface-elevated/30"}`,children:[n.jsx("span",{className:"text-2xl",children:Ve.icon}),n.jsx("span",{className:"text-sm font-medium text-fg-primary",children:Ve.label}),n.jsx("span",{className:"text-[11px] text-fg-tertiary leading-tight text-center",children:Ve.desc})]},Ve.value))})},{id:Tj,title:a("llm.title"),subtitle:a("llm.subtitle"),content:K?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")})]}),B.map(Ve=>n.jsxs("div",{className:"flex items-center justify-between bg-green-500/10 border border-green-500/30 rounded-lg px-4 py-2.5",children:[n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx("span",{className:"w-2 h-2 rounded-full bg-green-400"}),n.jsx("span",{className:"text-sm text-fg-primary font-medium",children:Ve.displayName}),Ve.model&&n.jsx("span",{className:"text-xs text-fg-tertiary",children:Ve.model})]}),Ve.apiKeyPreview&&n.jsx("code",{className:"text-[10px] text-fg-tertiary",children:Ve.apiKeyPreview})]},Ve.name)),n.jsx("div",{className:"text-xs text-fg-secondary mt-1",children:a("llm.configuredHint")}),n.jsxs("div",{className:"flex items-center justify-between bg-surface-elevated/40 rounded-lg px-4 py-3 mt-3",children:[n.jsxs("div",{children:[n.jsx("div",{className:"text-xs font-medium text-fg-primary",children:a("llm.autoFallback")}),n.jsx("div",{className:"text-[11px] text-fg-tertiary mt-0.5",children:a("llm.autoFallbackDesc")})]}),n.jsx("button",{onClick:async()=>{const Ve=!Q;ee(Ve);try{await fetch("/api/settings/llm",{method:"POST",headers:Qe(),body:JSON.stringify({autoFallback:Ve})})}catch{ee(!Ve)}},className:`relative inline-flex h-5 w-9 items-center rounded-full transition-colors shrink-0 ${Q?"bg-green-500":"bg-gray-600"}`,children:n.jsx("span",{className:`inline-block h-3.5 w-3.5 rounded-full bg-white transition-transform ${Q?"translate-x-4":"translate-x-1"}`})})]})]}):n.jsxs("div",{className:"space-y-4",children:[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(Ve=>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[Ve.provider]??!1,onChange:ut=>W({...U,[Ve.provider]:ut.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:Ve.displayName}),n.jsx("span",{className:"text-xs text-fg-tertiary ml-2",children:Ve.model})]}),n.jsx("code",{className:"text-[10px] text-fg-tertiary",children:Ve.apiKeyPreview})]},Ve.provider)),n.jsx("button",{onClick:()=>{ce()},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(Hu,{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")}),R?R.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:R.summary.configPath}),R.summary.models&&n.jsx("span",{className:"text-fg-tertiary ml-1",children:a("llm.openClawProviders",{count:R.summary.models.providerCount})})]}),n.jsx("button",{onClick:()=>{Me()},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:()=>{ue()},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")})]}),H&&n.jsx("div",{className:`text-xs px-3 py-2 rounded-lg ${H.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:H.text})]})},{id:Aj,title:a("search.title"),subtitle:a("search.subtitle"),content:pe?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")})]}),Y&&[{id:"serper",label:a("search.serper")},{id:"tavily",label:a("search.tavily")},{id:"bing",label:a("search.bing")},{id:"google",label:a("search.google")},{id:"serpapi",label:a("search.serpapi")},{id:"brave",label:a("search.brave")},{id:"exa",label:a("search.exa")},{id:"bocha",label:a("search.bocha")}].filter(Ve=>Y[Ve.id]?.configured).map(Ve=>n.jsxs("div",{className:"flex items-center justify-between bg-green-500/10 border border-green-500/30 rounded-lg px-4 py-2.5",children:[n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx("span",{className:"w-2 h-2 rounded-full bg-green-400"}),n.jsx("span",{className:"text-sm text-fg-primary font-medium",children:Ve.label})]}),n.jsx("code",{className:"text-[10px] text-fg-tertiary",children:Y[Ve.id].preview})]},Ve.id)),n.jsx("div",{className:"text-xs text-fg-secondary mt-1",children:a("search.savedHint")})]}):n.jsxs("div",{className:"space-y-4",children:[n.jsx("div",{className:"text-xs text-fg-secondary",children:a("search.description")}),Y&&(Y.serper.configured||Y.tavily.configured||Y.bing.configured||Y.google.configured||Y.serpapi.configured||Y.brave.configured||Y.exa.configured||Y.bocha.configured)&&n.jsxs("div",{className:"space-y-2",children:[n.jsx("div",{className:"text-xs text-fg-secondary uppercase tracking-wider",children:a("search.detected")}),[{id:"serper",label:a("search.serper")},{id:"tavily",label:a("search.tavily")},{id:"bing",label:a("search.bing")},{id:"google",label:a("search.google")},{id:"serpapi",label:a("search.serpapi")},{id:"brave",label:a("search.brave")},{id:"exa",label:a("search.exa")},{id:"bocha",label:a("search.bocha")}].filter(Ve=>Y[Ve.id]?.configured).map(Ve=>n.jsxs("div",{className:"flex items-center justify-between bg-green-500/10 border border-green-500/30 rounded-lg px-3 py-2",children:[n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx("span",{className:"w-2 h-2 rounded-full bg-green-400"}),n.jsx("span",{className:"text-sm text-fg-primary",children:Ve.label})]}),n.jsx("code",{className:"text-[10px] text-fg-tertiary",children:Y[Ve.id].preview})]},Ve.id))]}),n.jsx("div",{className:"space-y-3",children:[{label:a("search.serper"),field:"serperApiKey"},{label:a("search.tavily"),field:"tavilyApiKey"},{label:a("search.bing"),field:"bingApiKey"},{label:a("search.google"),field:"googleSearchApiKey"},{label:a("search.serpapi"),field:"serpApiKey"},{label:a("search.brave"),field:"braveApiKey"},{label:a("search.exa"),field:"exaApiKey"},{label:a("search.bocha"),field:"bochaApiKey"}].map(Ve=>n.jsxs("div",{className:"space-y-1",children:[n.jsx("label",{className:"text-xs text-fg-tertiary font-medium",children:Ve.label}),n.jsx("input",{type:"password",value:be[Ve.field],onChange:ut=>De({...be,[Ve.field]:ut.target.value}),placeholder:a("search.apiKeyPlaceholder"),className:"w-full px-4 py-2 bg-surface-elevated border border-border-default rounded-xl text-sm text-fg-primary focus:border-brand-500 outline-none transition-colors"})]},Ve.field))}),n.jsx("button",{onClick:()=>{he()},disabled:He||!be.serperApiKey&&!be.tavilyApiKey&&!be.bingApiKey&&!be.googleSearchApiKey&&!be.serpApiKey&&!be.braveApiKey&&!be.exaApiKey&&!be.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(He?"search.saving":"search.save")}),Ee&&n.jsx("div",{className:`text-xs px-3 py-2 rounded-lg ${Ee.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:Ee.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(([Ve,ut])=>n.jsxs("div",{className:"flex gap-3 bg-surface-elevated/50 rounded-lg p-3",children:[n.jsx("div",{className:"text-brand-500 mt-0.5 shrink-0",children:"→"}),n.jsxs("div",{children:[n.jsx("div",{className:"font-medium text-fg-primary text-xs",children:Ve}),n.jsx("div",{className:"text-fg-secondary text-xs",children:ut})]})]},Ve))})}],at=s?Ke.filter(Ve=>Ve.id!==Kx):Ke,ct=at.findIndex(Ve=>Ve.id===Kx),Je=at.findIndex(Ve=>Ve.id===Tj),rt=at.findIndex(Ve=>Ve.id===Aj),ht=()=>{i===ct&&ct>=0&&!j||(i<at.length-1?l(i+1):e())},xt=at[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:at.map((Ve,ut)=>n.jsx("div",{className:`h-1 flex-1 rounded-full transition-colors ${ut<=i?"bg-brand-500":"bg-surface-elevated"}`},ut))}),n.jsx("h2",{className:"text-2xl font-bold text-fg-primary",children:xt.title}),n.jsx("p",{className:"text-sm text-fg-secondary mt-1 mb-6",children:xt.subtitle}),xt.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:[ct>=0&&i===ct&&!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")}),Je>=0&&i===Je&&!K&&n.jsx("button",{onClick:ht,className:"px-4 py-2 text-sm text-fg-tertiary hover:text-fg-secondary transition-colors",children:a("llm.skipForNow")}),rt>=0&&i===rt&&!pe&&n.jsx("button",{onClick:ht,className:"px-4 py-2 text-sm text-fg-tertiary hover:text-fg-secondary transition-colors",children:a("search.skipForNow")}),n.jsx("button",{onClick:ht,disabled:ct>=0&&i===ct&&!j,className:`px-6 py-2.5 text-white text-sm rounded-xl transition-colors ${ct>=0&&i===ct&&!j?"bg-brand-600/40 cursor-not-allowed":"bg-brand-600 hover:bg-brand-500"}`,children:i===at.length-1?a("getStarted"):a("common:next")})]})]})]})})})}function lre({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:D}=await de.auth.init(r.trim(),a.trim(),l);if(p)try{await de.auth.uploadAvatar(p,"user")}catch{}e(T,D??!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 cre({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 de.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 dre({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(()=>{de.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 de.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 ure({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 de.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 Af={agents:[],tasks:[],requirements:[],projects:[],deliverables:[]},mre={team:["agents","tasks","requirements","projects","deliverables"],work:["projects","requirements","tasks","agents","deliverables"],deliverables:["deliverables","agents","tasks","requirements","projects"]},fre=["agents","tasks","requirements","projects","deliverables"];let Ej="",Mj="all",Rj=Af,Dj=!1;function hre({onClose:e,currentPage:t}){const{t:r}=kt(["common","home","work"]),[s,a]=b.useState(Ej),[i,l]=b.useState(Mj),[d,u]=b.useState(Rj),[m,p]=b.useState(!1),[h,y]=b.useState(Dj),[g,v]=b.useState(-1);b.useEffect(()=>{Ej=s},[s]),b.useEffect(()=>{Mj=i},[i]),b.useEffect(()=>{Rj=d},[d]),b.useEffect(()=>{Dj=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(Af),y(!1),v(-1);return}p(!0),y(!0),v(-1);const I=q.toLowerCase();try{const[R,E,$,X,K]=await Promise.allSettled([de.agents.list(),de.tasks.list({search:q,pageSize:20}),de.requirements.list(),de.projects.list(),de.deliverables.search({q,limit:20})]),P=R.status==="fulfilled"?R.value.agents.filter(Q=>Q.name?.toLowerCase().includes(I)||Q.role?.toLowerCase().includes(I)):[],B=E.status==="fulfilled"?E.value.tasks:[],Z=$.status==="fulfilled"?$.value.requirements.filter(Q=>Q.title?.toLowerCase().includes(I)||Q.description?.toLowerCase().includes(I)):[],H=X.status==="fulfilled"?X.value.projects.filter(Q=>Q.name?.toLowerCase().includes(I)||Q.description?.toLowerCase().includes(I)):[],J=K.status==="fulfilled"?K.value.results:[];u({agents:P,tasks:B,requirements:Z,projects:H,deliverables:J})}catch{u(Af)}finally{p(!1)}},[]),T=q=>{a(q),C.current&&clearTimeout(C.current),C.current=setTimeout(()=>j(q),400)},D=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(()=>mre[t||""]||fre,[t]),F=b.useMemo(()=>{const q=[],I=i==="all"?8:void 0,R=E=>{if(i!=="all"&&i!==E)return;const $=d[E==="agents"?"agents":E==="tasks"?"tasks":E==="requirements"?"requirements":E==="projects"?"projects":"deliverables"],X=I?$.slice(0,I):$;for(const K of X)switch(E){case"agents":q.push({id:K.id,type:"agent",page:Te.TEAM,params:{agentId:K.id}});break;case"tasks":q.push({id:K.id,type:"task",page:Te.WORK,params:{openTask:K.id}});break;case"requirements":q.push({id:K.id,type:"requirement",page:Te.WORK,params:{openRequirement:K.id}});break;case"projects":q.push({id:K.id,type:"project",page:Te.WORK,params:{projectId:K.id}});break;case"deliverables":q.push({id:K.id,type:"deliverable",page:Te.DELIVERABLES,params:{openDeliverable:K.id}});break}I&&$.length>I&&q.push({id:`more_${E}`,type:"showMore",page:"",expandCategory:E,totalCount:$.length})};for(const E of _)R(E);return q},[d,i,_]),z=b.useCallback(q=>{if(q.type==="showMore"&&q.expandCategory){l(q.expandCategory),v(-1);return}D(q.page,q.params)},[D]);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(K=>K.id),$=E.indexOf(i),X=q.shiftKey?$<=0?E.length-1:$-1:$>=E.length-1?0:$+1;l(E[X]),v(-1);return}const I=q.ctrlKey&&q.key==="n"||q.key==="ArrowDown",R=q.ctrlKey&&q.key==="p"||q.key==="ArrowUp";if(I||R){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 W=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(Af),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,R=E=>{const $=W++,X=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:"查看全部"})," (",X,")"]})};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 $=W++;return n.jsxs("button",{"data-idx":$,onClick:()=>D(Te.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(pre,{status:E.status})]},E.id)})}),I&&d.agents.length>I&&R("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 $=W++;return n.jsxs("button",{"data-idx":$,onClick:()=>D(Te.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(gre,{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&&R("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 $=W++;return n.jsxs("button",{"data-idx":$,onClick:()=>D(Te.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&&R("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 $=W++;return n.jsxs("button",{"data-idx":$,onClick:()=>D(Te.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&&R("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 $=W++;return n.jsxs("button",{"data-idx":$,onClick:()=>D(Te.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&&R("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 pre({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 gre({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 xre=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 bre(){const{t:e}=kt("common"),[t,r]=b.useState(Ul),[s,a]=b.useState(()=>!localStorage.getItem("markus_onboarded")),[i,l]=b.useState(!0),d=js(),u=JW(),m=Qu({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,D]=b.useState(null),[M,_]=b.useState(!1),[F,z]=b.useState(null),[L,U]=b.useState(()=>{const P=localStorage.getItem("markus_update_dismissed");return P||null}),[W,q]=b.useState(!1);b.useEffect(()=>{if(d)return;const P=navigator.platform.toUpperCase().includes("MAC"),B=H=>{P&&H.metaKey&&!H.ctrlKey&&H.key==="p"?(H.preventDefault(),q(J=>!J)):!P&&H.ctrlKey&&!H.metaKey&&H.key==="p"&&(H.preventDefault(),q(J=>!J))},Z=()=>q(!0);return document.addEventListener("keydown",B),window.addEventListener("markus:open-search",Z),()=>{document.removeEventListener("keydown",B),window.removeEventListener("markus:open-search",Z)}},[d]);const I=b.useCallback(P=>{let B=il(P);d?B=JO[B]??B:B===Te.NOTIFICATIONS&&(B=Te.HOME);const Z=Ul(),H=window.location.hash.slice(1);H!==Z?Wx[Z]=H:delete Wx[Z];const J=B!==Te.WORK?Wx[B]:void 0;J&&J!==B?(history.pushState(null,"","#"+B),history.pushState(null,"","#"+J)):history.pushState(null,"","#"+B),window.dispatchEvent(new HashChangeEvent("hashchange")),r(B),h(Q=>Q.has(B)?Q:new Set([...Q,B]))},[d]);b.useEffect(()=>{Nt.setHandler(P=>I(P))},[I]);const R=b.useCallback(()=>{fetch("/api/settings/llm").then(P=>P.ok?P.json():null).then(P=>{if(P?.providers){const B=Object.values(P.providers).some(Z=>Z.configured);D(B)}}).catch(()=>{})},[]);b.useEffect(()=>{const P=new URLSearchParams(window.location.search),B=P.get("install");if(B&&Ul()!==Te.STORE){const J=P.get("type"),ee=J&&{agent:"agents",team:"teams",skill:"skills"}[J]||"agents";localStorage.setItem("markus_nav_installItem",B),localStorage.setItem("markus_nav_storeTab",ee),P.delete("install"),P.delete("type");const se=P.toString();window.history.replaceState(null,"",window.location.pathname+(se?`?${se}`:"")+"#store"),setTimeout(()=>Nt.navigate(Te.STORE,{storeTab:ee,installItem:B}),300)}de.auth.me().then(({user:J})=>{g(J),S(!0),fn.connect(J.id),R(),de.health().then(ee=>{ee.updateAvailable&&ee.latestVersion&&z({latestVersion:ee.latestVersion,currentVersion:ee.version})}).catch(()=>{});const Q=()=>{Bl(ga.builderArtifacts,()=>de.builder.artifacts.list()),Bl(ga.builderAgents,()=>de.agents.list()),Bl(ga.builderHubMyItems,()=>In.myItems()),Bl(ga.builderInstalled,()=>de.builder.artifacts.installed()),Bl(ga.hubAgents,()=>In.search({type:"agent",limit:50})),Bl(ga.hubTeams,()=>In.search({type:"team",limit:50})),Bl(ga.hubSkills,()=>In.search({type:"skill",limit:50}))};typeof requestIdleCallback=="function"?requestIdleCallback(Q,{timeout:5e3}):setTimeout(Q,3e3)}).catch(()=>{g(null),de.auth.status().then(({initialized:J})=>S(J)).catch(()=>S(!0))}),fn.connect();const Z=fn.on("notification",()=>{window.dispatchEvent(new CustomEvent("markus:notifications-changed"))}),H=()=>{const J=Ul();r(J),h(Q=>Q.has(J)?Q:new Set([...Q,J]))};return window.addEventListener("hashchange",H),()=>{Z(),fn.disconnect(),window.removeEventListener("hashchange",H)}},[]);const E=y!=="loading"&&y!==null?y:void 0,$=b.useMemo(()=>d?{[Te.HOME]:n.jsx(iw,{authUser:E}),[Te.TEAM]:n.jsx(Rk,{authUser:E}),[Te.BUILDER]:n.jsx(ire,{authUser:E}),[Te.SETTINGS]:n.jsx(Pk,{theme:u.mode,onThemeChange:u.setMode,authUser:E,onLogout:()=>g(null),onUserUpdated:P=>g(P)}),[Te.WORK]:n.jsx(wj,{authUser:E}),[Te.DELIVERABLES]:n.jsx(Nj,{authUser:E}),[Te.NOTIFICATIONS]:n.jsx(Zne,{authUser:E}),[Te.REPORTS]:n.jsx(Sj,{authUser:E}),[Te.SEARCH]:n.jsx(Jne,{})}:{[Te.HOME]:n.jsx(iw,{authUser:E}),[Te.TEAM]:n.jsx(Rk,{authUser:E}),[Te.SETTINGS]:n.jsx(Pk,{theme:u.mode,onThemeChange:u.setMode,authUser:E,onLogout:()=>g(null),onUserUpdated:P=>g(P)}),[Te.STORE]:n.jsx(RG,{authUser:E}),[Te.BUILDER]:n.jsx(AS,{authUser:E}),[Te.WORK]:n.jsx(wj,{authUser:E}),[Te.DELIVERABLES]:n.jsx(Nj,{authUser:E}),[Te.REPORTS]:n.jsx(Sj,{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 K=(typeof window<"u"?window.location.hash:"").match(/^#invite\?token=([a-f0-9]+)/);return K?n.jsx(dre,{token:K[1],onComplete:()=>{window.location.hash="",localStorage.removeItem("markus_onboarded"),a(!0),k(!0),g("loading"),de.auth.me().then(P=>g(P.user)).catch(()=>g(null))}}):y===null?v===!1?n.jsx(lre,{onSetup:(P,B)=>{g(P),S(!0),k(!0),B&&(localStorage.removeItem("markus_onboarded"),a(!0))}}):n.jsx(cre,{onLogin:(P,B)=>{g(P),B?(localStorage.removeItem("markus_onboarded"),a(!0)):localStorage.getItem("markus_onboarded")||(localStorage.setItem("markus_onboarded","1"),a(!1))}}):N?n.jsx(ure,{onComplete:()=>j(!1),isFirstTime:!0}):s?n.jsx(ore,{theme:u.mode,onThemeChange:u.setMode,skipProfile:C,onComplete:()=>{localStorage.setItem("markus_onboarded","1"),a(!1),k(!1),R(),I(Te.TEAM)}}):n.jsxs("div",{className:`flex h-dvh bg-surface-primary text-fg-primary overflow-x-hidden ${d?"flex-col":""}`,children:[!d&&t!==Te.SETTINGS&&n.jsxs(n.Fragment,{children:[n.jsx("div",{className:"relative z-40 shrink-0",style:{width:m.width},children:n.jsx(rre,{currentPage:t,onNavigate:P=>{I(P),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!==Te.SETTINGS&&t!==Te.SEARCH?"pb-14":""}`,children:[T===!1&&!M&&t!==Te.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(Te.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(P=>p.has(P)?n.jsx(xre,{id:P,activePage:t,children:$[P]},P):null)})]}),d&&t!==Te.SETTINGS&&t!==Te.SEARCH&&n.jsx(sre,{currentPage:t,onNavigate:I,userId:E?.id}),d&&n.jsx(o_,{authUser:E,onNavigate:I}),!d&&W&&n.jsx(hre,{onClose:()=>q(!1),currentPage:t})]})}d9.createRoot(document.getElementById("root")).render(n.jsx(b.StrictMode,{children:n.jsx(bre,{})}));export{l0 as g};