@markus-global/cli 0.11.0-rc.0 → 0.11.0-rc.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. package/dist/web-ui/assets/{CommentInput-qC6sIdWc.js → CommentInput-D4udF3ci.js} +1 -1
  2. package/dist/web-ui/assets/{ContentRenderer-Dg2NkAAp.js → ContentRenderer-CY0moVGG.js} +2 -2
  3. package/dist/web-ui/assets/{DeliverableShareModal-bJZIzEcd.js → DeliverableShareModal-Kw_PwtaD.js} +1 -1
  4. package/dist/web-ui/assets/{Deliverables-1lbmiGAG.js → Deliverables-B6Fo0RuB.js} +1 -1
  5. package/dist/web-ui/assets/{Notifications-CNIT_3nV.js → Notifications-DsP8Z0a3.js} +1 -1
  6. package/dist/web-ui/assets/{Search-z4hSEFJB.js → Search-CLSRxUnd.js} +1 -1
  7. package/dist/web-ui/assets/{Settings-CiDdRf4c.js → Settings-_kkGsvr2.js} +1 -1
  8. package/dist/web-ui/assets/{Store-Dow-P_iy.js → Store-BOV3Thkl.js} +1 -1
  9. package/dist/web-ui/assets/{Team-B-hEPIUd.js → Team-mz_JWJwM.js} +36 -36
  10. package/dist/web-ui/assets/{Work-C1398-Y_.js → Work-DaY25Zvg.js} +1 -1
  11. package/dist/web-ui/assets/{arc-DmEkpFyx.js → arc-DppCSfqA.js} +1 -1
  12. package/dist/web-ui/assets/{architectureDiagram-3BPJPVTR-BAvpMlqX.js → architectureDiagram-3BPJPVTR-Cqxc4BLx.js} +1 -1
  13. package/dist/web-ui/assets/{blockDiagram-GPEHLZMM-BG_TT3-3.js → blockDiagram-GPEHLZMM-Bnoj-Has.js} +1 -1
  14. package/dist/web-ui/assets/{c4Diagram-AAUBKEIU-CMyvSuYL.js → c4Diagram-AAUBKEIU-BwigdMy_.js} +1 -1
  15. package/dist/web-ui/assets/channel-CDQp_KCp.js +1 -0
  16. package/dist/web-ui/assets/{chunk-2J33WTMH-j3hhcNXY.js → chunk-2J33WTMH-BY8hN7e1.js} +1 -1
  17. package/dist/web-ui/assets/{chunk-4BX2VUAB-X4xnI9BZ.js → chunk-4BX2VUAB-BeLkwvuM.js} +1 -1
  18. package/dist/web-ui/assets/{chunk-55IACEB6-DyUtXnN3.js → chunk-55IACEB6-C1IrH2YD.js} +1 -1
  19. package/dist/web-ui/assets/{chunk-727SXJPM-BrdruDab.js → chunk-727SXJPM-jJXbcC5A.js} +1 -1
  20. package/dist/web-ui/assets/{chunk-AQP2D5EJ-MBJ1Y6YH.js → chunk-AQP2D5EJ-6QZflhse.js} +1 -1
  21. package/dist/web-ui/assets/{chunk-FMBD7UC4-BxP2G3lY.js → chunk-FMBD7UC4-CE8BtseF.js} +1 -1
  22. package/dist/web-ui/assets/{chunk-ND2GUHAM-BJaE5HMp.js → chunk-ND2GUHAM-JYpnGzBS.js} +1 -1
  23. package/dist/web-ui/assets/{chunk-QZHKN3VN-urDgA5Vs.js → chunk-QZHKN3VN-ChBjEb5B.js} +1 -1
  24. package/dist/web-ui/assets/classDiagram-4FO5ZUOK-BvMC7FQO.js +1 -0
  25. package/dist/web-ui/assets/classDiagram-v2-Q7XG4LA2-BvMC7FQO.js +1 -0
  26. package/dist/web-ui/assets/{cose-bilkent-S5V4N54A-ycciI64h.js → cose-bilkent-S5V4N54A-DC3PvBlT.js} +1 -1
  27. package/dist/web-ui/assets/{dagre-BM42HDAG-BumurzyM.js → dagre-BM42HDAG-CHs1tyq2.js} +1 -1
  28. package/dist/web-ui/assets/{diagram-2AECGRRQ-SFaF84fx.js → diagram-2AECGRRQ-CKFu3DHI.js} +1 -1
  29. package/dist/web-ui/assets/{diagram-5GNKFQAL-ClibNqdZ.js → diagram-5GNKFQAL-B83ktWF9.js} +1 -1
  30. package/dist/web-ui/assets/{diagram-KO2AKTUF-Dq4sObCM.js → diagram-KO2AKTUF-Cd_0fmGt.js} +1 -1
  31. package/dist/web-ui/assets/{diagram-LMA3HP47-CzQflDnT.js → diagram-LMA3HP47-CF4idZdP.js} +1 -1
  32. package/dist/web-ui/assets/{diagram-OG6HWLK6-DWca0pGk.js → diagram-OG6HWLK6-D1_l8wLK.js} +1 -1
  33. package/dist/web-ui/assets/{docx-preview-BDequ2bp.js → docx-preview-BLbI_SCu.js} +1 -1
  34. package/dist/web-ui/assets/{erDiagram-TEJ5UH35-CMS23LUK.js → erDiagram-TEJ5UH35-D8rK_F87.js} +1 -1
  35. package/dist/web-ui/assets/{flowDiagram-I6XJVG4X-DtAEypSz.js → flowDiagram-I6XJVG4X-ZoPp1kJi.js} +1 -1
  36. package/dist/web-ui/assets/{ganttDiagram-6RSMTGT7-A1EmvSHz.js → ganttDiagram-6RSMTGT7-uligSftG.js} +1 -1
  37. package/dist/web-ui/assets/{gitGraphDiagram-PVQCEYII-C0enVP1d.js → gitGraphDiagram-PVQCEYII-DY0gAjmH.js} +1 -1
  38. package/dist/web-ui/assets/index-DxPx73Ja.css +1 -0
  39. package/dist/web-ui/assets/{index-CbHCYKaC.js → index-gob1iLha.js} +9 -9
  40. package/dist/web-ui/assets/{infoDiagram-5YYISTIA-DikBMq11.js → infoDiagram-5YYISTIA-Bj9ByigZ.js} +1 -1
  41. package/dist/web-ui/assets/{ishikawaDiagram-YF4QCWOH-BPsIvWKE.js → ishikawaDiagram-YF4QCWOH-CP7f_i4P.js} +1 -1
  42. package/dist/web-ui/assets/{journeyDiagram-JHISSGLW-C3h9ewdq.js → journeyDiagram-JHISSGLW-Br7sCfe4.js} +1 -1
  43. package/dist/web-ui/assets/{kanban-definition-UN3LZRKU-Cnc97p2Y.js → kanban-definition-UN3LZRKU-MroLrnqj.js} +1 -1
  44. package/dist/web-ui/assets/{mermaid.core-DkHPUH0x.js → mermaid.core-DbFRJGs8.js} +5 -5
  45. package/dist/web-ui/assets/{mindmap-definition-RKZ34NQL-B6zj2wNQ.js → mindmap-definition-RKZ34NQL-Bus39q04.js} +1 -1
  46. package/dist/web-ui/assets/{pieDiagram-4H26LBE5-D1gAGU0u.js → pieDiagram-4H26LBE5-SO5RJs--.js} +1 -1
  47. package/dist/web-ui/assets/{quadrantDiagram-W4KKPZXB-CU2nw0oG.js → quadrantDiagram-W4KKPZXB-xBzLY7eN.js} +1 -1
  48. package/dist/web-ui/assets/{requirementDiagram-4Y6WPE33-Br7HOsVo.js → requirementDiagram-4Y6WPE33-CDYrNQvD.js} +1 -1
  49. package/dist/web-ui/assets/{sankeyDiagram-5OEKKPKP-D5nDUIGI.js → sankeyDiagram-5OEKKPKP-D6MRbXJQ.js} +1 -1
  50. package/dist/web-ui/assets/{sequenceDiagram-3UESZ5HK-CjeWx2PY.js → sequenceDiagram-3UESZ5HK-1EcHUnVa.js} +1 -1
  51. package/dist/web-ui/assets/{stateDiagram-AJRCARHV-S7nP0eey.js → stateDiagram-AJRCARHV-Bxr9KAun.js} +1 -1
  52. package/dist/web-ui/assets/stateDiagram-v2-BHNVJYJU-CYQuSdFg.js +1 -0
  53. package/dist/web-ui/assets/{timeline-definition-PNZ67QCA-BqPnxUEG.js → timeline-definition-PNZ67QCA-BJ82e_G9.js} +1 -1
  54. package/dist/web-ui/assets/{vennDiagram-CIIHVFJN-C7QGFyJh.js → vennDiagram-CIIHVFJN-DlbfUUC7.js} +1 -1
  55. package/dist/web-ui/assets/{wardley-L42UT6IY-DN09KkEl.js → wardley-L42UT6IY-DIyuDPl5.js} +1 -1
  56. package/dist/web-ui/assets/{wardleyDiagram-YWT4CUSO-DPTSSDRg.js → wardleyDiagram-YWT4CUSO-J-XhaGPJ.js} +1 -1
  57. package/dist/web-ui/assets/{xychartDiagram-2RQKCTM6-CMjgal_M.js → xychartDiagram-2RQKCTM6-BJv3cUEO.js} +1 -1
  58. package/dist/web-ui/index.html +2 -2
  59. package/package.json +1 -1
  60. package/dist/web-ui/assets/channel-BTYEBkz-.js +0 -1
  61. package/dist/web-ui/assets/classDiagram-4FO5ZUOK-1-yypxub.js +0 -1
  62. package/dist/web-ui/assets/classDiagram-v2-Q7XG4LA2-1-yypxub.js +0 -1
  63. package/dist/web-ui/assets/index-1DxMQarj.css +0 -1
  64. package/dist/web-ui/assets/stateDiagram-v2-BHNVJYJU-C4e2ZIU1.js +0 -1
@@ -1,4 +1,4 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/mermaid.core-DkHPUH0x.js","assets/transform-CpIVI4vC.js","assets/Team-B-hEPIUd.js","assets/CommentInput-qC6sIdWc.js","assets/ContentRenderer-Dg2NkAAp.js","assets/DeliverableShareModal-bJZIzEcd.js","assets/modelCapabilities-DDtCBZ6o.js","assets/Team-DFuMZ0ql.css","assets/Settings-CiDdRf4c.js","assets/Work-C1398-Y_.js","assets/value-DIujSiJ7.js","assets/Work-BZV40eAE.css","assets/Deliverables-1lbmiGAG.js"])))=>i.map(i=>d[i]);
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/mermaid.core-DbFRJGs8.js","assets/transform-CpIVI4vC.js","assets/Team-mz_JWJwM.js","assets/CommentInput-D4udF3ci.js","assets/ContentRenderer-CY0moVGG.js","assets/DeliverableShareModal-Kw_PwtaD.js","assets/modelCapabilities-DDtCBZ6o.js","assets/Team-DFuMZ0ql.css","assets/Settings-_kkGsvr2.js","assets/Work-DaY25Zvg.js","assets/value-DIujSiJ7.js","assets/Work-BZV40eAE.css","assets/Deliverables-B6Fo0RuB.js"])))=>i.map(i=>d[i]);
2
2
  (function(){const t=document.createElement("link").relList;if(t&&t.supports&&t.supports("modulepreload"))return;for(const s of document.querySelectorAll('link[rel="modulepreload"]'))a(s);new MutationObserver(s=>{for(const l of s)if(l.type==="childList")for(const c of l.addedNodes)c.tagName==="LINK"&&c.rel==="modulepreload"&&a(c)}).observe(document,{childList:!0,subtree:!0});function n(s){const l={};return s.integrity&&(l.integrity=s.integrity),s.referrerPolicy&&(l.referrerPolicy=s.referrerPolicy),s.crossOrigin==="use-credentials"?l.credentials="include":s.crossOrigin==="anonymous"?l.credentials="omit":l.credentials="same-origin",l}function a(s){if(s.ep)return;s.ep=!0;const l=n(s);fetch(s.href,l)}})();var Vie=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function Ic(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var cf={exports:{}},Xl={};var Xx;function pA(){if(Xx)return Xl;Xx=1;var e=Symbol.for("react.transitional.element"),t=Symbol.for("react.fragment");function n(a,s,l){var c=null;if(l!==void 0&&(c=""+l),s.key!==void 0&&(c=""+s.key),"key"in s){l={};for(var d in s)d!=="key"&&(l[d]=s[d])}else l=s;return s=l.ref,{$$typeof:e,type:a,key:c,ref:s!==void 0?s:null,props:l}}return Xl.Fragment=t,Xl.jsx=n,Xl.jsxs=n,Xl}var Jx;function fA(){return Jx||(Jx=1,cf.exports=pA()),cf.exports}var i=fA(),uf={exports:{}},$t={};var Zx;function hA(){if(Zx)return $t;Zx=1;var e=Symbol.for("react.transitional.element"),t=Symbol.for("react.portal"),n=Symbol.for("react.fragment"),a=Symbol.for("react.strict_mode"),s=Symbol.for("react.profiler"),l=Symbol.for("react.consumer"),c=Symbol.for("react.context"),d=Symbol.for("react.forward_ref"),m=Symbol.for("react.suspense"),p=Symbol.for("react.memo"),h=Symbol.for("react.lazy"),g=Symbol.for("react.activity"),x=Symbol.iterator;function y(V){return V===null||typeof V!="object"?null:(V=x&&V[x]||V["@@iterator"],typeof V=="function"?V:null)}var w={isMounted:function(){return!1},enqueueForceUpdate:function(){},enqueueReplaceState:function(){},enqueueSetState:function(){}},T=Object.assign,C={};function S(V,fe,z){this.props=V,this.context=fe,this.refs=C,this.updater=z||w}S.prototype.isReactComponent={},S.prototype.setState=function(V,fe){if(typeof V!="object"&&typeof V!="function"&&V!=null)throw Error("takes an object of state variables to update or a function which returns an object of state variables.");this.updater.enqueueSetState(this,V,fe,"setState")},S.prototype.forceUpdate=function(V){this.updater.enqueueForceUpdate(this,V,"forceUpdate")};function E(){}E.prototype=S.prototype;function _(V,fe,z){this.props=V,this.context=fe,this.refs=C,this.updater=z||w}var L=_.prototype=new E;L.constructor=_,T(L,S.prototype),L.isPureReactComponent=!0;var D=Array.isArray;function M(){}var O={H:null,A:null,T:null,S:null},G=Object.prototype.hasOwnProperty;function Q(V,fe,z){var je=z.ref;return{$$typeof:e,type:V,key:fe,ref:je!==void 0?je:null,props:z}}function $(V,fe){return Q(V.type,fe,V.props)}function Y(V){return typeof V=="object"&&V!==null&&V.$$typeof===e}function K(V){var fe={"=":"=0",":":"=2"};return"$"+V.replace(/[=:]/g,function(z){return fe[z]})}var ee=/\/+/g;function U(V,fe){return typeof V=="object"&&V!==null&&V.key!=null?K(""+V.key):fe.toString(36)}function te(V){switch(V.status){case"fulfilled":return V.value;case"rejected":throw V.reason;default:switch(typeof V.status=="string"?V.then(M,M):(V.status="pending",V.then(function(fe){V.status==="pending"&&(V.status="fulfilled",V.value=fe)},function(fe){V.status==="pending"&&(V.status="rejected",V.reason=fe)})),V.status){case"fulfilled":return V.value;case"rejected":throw V.reason}}throw V}function I(V,fe,z,je,Ue){var qe=typeof V;(qe==="undefined"||qe==="boolean")&&(V=null);var He=!1;if(V===null)He=!0;else switch(qe){case"bigint":case"string":case"number":He=!0;break;case"object":switch(V.$$typeof){case e:case t:He=!0;break;case h:return He=V._init,I(He(V._payload),fe,z,je,Ue)}}if(He)return Ue=Ue(V),He=je===""?"."+U(V,0):je,D(Ue)?(z="",He!=null&&(z=He.replace(ee,"$&/")+"/"),I(Ue,fe,z,"",function(Nt){return Nt})):Ue!=null&&(Y(Ue)&&(Ue=$(Ue,z+(Ue.key==null||V&&V.key===Ue.key?"":(""+Ue.key).replace(ee,"$&/")+"/")+He)),fe.push(Ue)),1;He=0;var ut=je===""?".":je+":";if(D(V))for(var dt=0;dt<V.length;dt++)je=V[dt],qe=ut+U(je,dt),He+=I(je,fe,z,qe,Ue);else if(dt=y(V),typeof dt=="function")for(V=dt.call(V),dt=0;!(je=V.next()).done;)je=je.value,qe=ut+U(je,dt++),He+=I(je,fe,z,qe,Ue);else if(qe==="object"){if(typeof V.then=="function")return I(te(V),fe,z,je,Ue);throw fe=String(V),Error("Objects are not valid as a React child (found: "+(fe==="[object Object]"?"object with keys {"+Object.keys(V).join(", ")+"}":fe)+"). If you meant to render a collection of children, use an array instead.")}return He}function J(V,fe,z){if(V==null)return V;var je=[],Ue=0;return I(V,je,"","",function(qe){return fe.call(z,qe,Ue++)}),je}function me(V){if(V._status===-1){var fe=V._result;fe=fe(),fe.then(function(z){(V._status===0||V._status===-1)&&(V._status=1,V._result=z)},function(z){(V._status===0||V._status===-1)&&(V._status=2,V._result=z)}),V._status===-1&&(V._status=0,V._result=fe)}if(V._status===1)return V._result.default;throw V._result}var Ce=typeof reportError=="function"?reportError:function(V){if(typeof window=="object"&&typeof window.ErrorEvent=="function"){var fe=new window.ErrorEvent("error",{bubbles:!0,cancelable:!0,message:typeof V=="object"&&V!==null&&typeof V.message=="string"?String(V.message):String(V),error:V});if(!window.dispatchEvent(fe))return}else if(typeof process=="object"&&typeof process.emit=="function"){process.emit("uncaughtException",V);return}console.error(V)},H={map:J,forEach:function(V,fe,z){J(V,function(){fe.apply(this,arguments)},z)},count:function(V){var fe=0;return J(V,function(){fe++}),fe},toArray:function(V){return J(V,function(fe){return fe})||[]},only:function(V){if(!Y(V))throw Error("React.Children.only expected to receive a single React element child.");return V}};return $t.Activity=g,$t.Children=H,$t.Component=S,$t.Fragment=n,$t.Profiler=s,$t.PureComponent=_,$t.StrictMode=a,$t.Suspense=m,$t.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE=O,$t.__COMPILER_RUNTIME={__proto__:null,c:function(V){return O.H.useMemoCache(V)}},$t.cache=function(V){return function(){return V.apply(null,arguments)}},$t.cacheSignal=function(){return null},$t.cloneElement=function(V,fe,z){if(V==null)throw Error("The argument must be a React element, but you passed "+V+".");var je=T({},V.props),Ue=V.key;if(fe!=null)for(qe in fe.key!==void 0&&(Ue=""+fe.key),fe)!G.call(fe,qe)||qe==="key"||qe==="__self"||qe==="__source"||qe==="ref"&&fe.ref===void 0||(je[qe]=fe[qe]);var qe=arguments.length-2;if(qe===1)je.children=z;else if(1<qe){for(var He=Array(qe),ut=0;ut<qe;ut++)He[ut]=arguments[ut+2];je.children=He}return Q(V.type,Ue,je)},$t.createContext=function(V){return V={$$typeof:c,_currentValue:V,_currentValue2:V,_threadCount:0,Provider:null,Consumer:null},V.Provider=V,V.Consumer={$$typeof:l,_context:V},V},$t.createElement=function(V,fe,z){var je,Ue={},qe=null;if(fe!=null)for(je in fe.key!==void 0&&(qe=""+fe.key),fe)G.call(fe,je)&&je!=="key"&&je!=="__self"&&je!=="__source"&&(Ue[je]=fe[je]);var He=arguments.length-2;if(He===1)Ue.children=z;else if(1<He){for(var ut=Array(He),dt=0;dt<He;dt++)ut[dt]=arguments[dt+2];Ue.children=ut}if(V&&V.defaultProps)for(je in He=V.defaultProps,He)Ue[je]===void 0&&(Ue[je]=He[je]);return Q(V,qe,Ue)},$t.createRef=function(){return{current:null}},$t.forwardRef=function(V){return{$$typeof:d,render:V}},$t.isValidElement=Y,$t.lazy=function(V){return{$$typeof:h,_payload:{_status:-1,_result:V},_init:me}},$t.memo=function(V,fe){return{$$typeof:p,type:V,compare:fe===void 0?null:fe}},$t.startTransition=function(V){var fe=O.T,z={};O.T=z;try{var je=V(),Ue=O.S;Ue!==null&&Ue(z,je),typeof je=="object"&&je!==null&&typeof je.then=="function"&&je.then(M,Ce)}catch(qe){Ce(qe)}finally{fe!==null&&z.types!==null&&(fe.types=z.types),O.T=fe}},$t.unstable_useCacheRefresh=function(){return O.H.useCacheRefresh()},$t.use=function(V){return O.H.use(V)},$t.useActionState=function(V,fe,z){return O.H.useActionState(V,fe,z)},$t.useCallback=function(V,fe){return O.H.useCallback(V,fe)},$t.useContext=function(V){return O.H.useContext(V)},$t.useDebugValue=function(){},$t.useDeferredValue=function(V,fe){return O.H.useDeferredValue(V,fe)},$t.useEffect=function(V,fe){return O.H.useEffect(V,fe)},$t.useEffectEvent=function(V){return O.H.useEffectEvent(V)},$t.useId=function(){return O.H.useId()},$t.useImperativeHandle=function(V,fe,z){return O.H.useImperativeHandle(V,fe,z)},$t.useInsertionEffect=function(V,fe){return O.H.useInsertionEffect(V,fe)},$t.useLayoutEffect=function(V,fe){return O.H.useLayoutEffect(V,fe)},$t.useMemo=function(V,fe){return O.H.useMemo(V,fe)},$t.useOptimistic=function(V,fe){return O.H.useOptimistic(V,fe)},$t.useReducer=function(V,fe,z){return O.H.useReducer(V,fe,z)},$t.useRef=function(V){return O.H.useRef(V)},$t.useState=function(V){return O.H.useState(V)},$t.useSyncExternalStore=function(V,fe,z){return O.H.useSyncExternalStore(V,fe,z)},$t.useTransition=function(){return O.H.useTransition()},$t.version="19.2.4",$t}var ev;function zm(){return ev||(ev=1,uf.exports=hA()),uf.exports}var k=zm();const Wie=Ic(k);var df={exports:{}},Jl={},mf={exports:{}},pf={};var tv;function gA(){return tv||(tv=1,(function(e){function t(I,J){var me=I.length;I.push(J);e:for(;0<me;){var Ce=me-1>>>1,H=I[Ce];if(0<s(H,J))I[Ce]=J,I[me]=H,me=Ce;else break e}}function n(I){return I.length===0?null:I[0]}function a(I){if(I.length===0)return null;var J=I[0],me=I.pop();if(me!==J){I[0]=me;e:for(var Ce=0,H=I.length,V=H>>>1;Ce<V;){var fe=2*(Ce+1)-1,z=I[fe],je=fe+1,Ue=I[je];if(0>s(z,me))je<H&&0>s(Ue,z)?(I[Ce]=Ue,I[je]=me,Ce=je):(I[Ce]=z,I[fe]=me,Ce=fe);else if(je<H&&0>s(Ue,me))I[Ce]=Ue,I[je]=me,Ce=je;else break e}}return J}function s(I,J){var me=I.sortIndex-J.sortIndex;return me!==0?me:I.id-J.id}if(e.unstable_now=void 0,typeof performance=="object"&&typeof performance.now=="function"){var l=performance;e.unstable_now=function(){return l.now()}}else{var c=Date,d=c.now();e.unstable_now=function(){return c.now()-d}}var m=[],p=[],h=1,g=null,x=3,y=!1,w=!1,T=!1,C=!1,S=typeof setTimeout=="function"?setTimeout:null,E=typeof clearTimeout=="function"?clearTimeout:null,_=typeof setImmediate<"u"?setImmediate:null;function L(I){for(var J=n(p);J!==null;){if(J.callback===null)a(p);else if(J.startTime<=I)a(p),J.sortIndex=J.expirationTime,t(m,J);else break;J=n(p)}}function D(I){if(T=!1,L(I),!w)if(n(m)!==null)w=!0,M||(M=!0,K());else{var J=n(p);J!==null&&te(D,J.startTime-I)}}var M=!1,O=-1,G=5,Q=-1;function $(){return C?!0:!(e.unstable_now()-Q<G)}function Y(){if(C=!1,M){var I=e.unstable_now();Q=I;var J=!0;try{e:{w=!1,T&&(T=!1,E(O),O=-1),y=!0;var me=x;try{t:{for(L(I),g=n(m);g!==null&&!(g.expirationTime>I&&$());){var Ce=g.callback;if(typeof Ce=="function"){g.callback=null,x=g.priorityLevel;var H=Ce(g.expirationTime<=I);if(I=e.unstable_now(),typeof H=="function"){g.callback=H,L(I),J=!0;break t}g===n(m)&&a(m),L(I)}else a(m);g=n(m)}if(g!==null)J=!0;else{var V=n(p);V!==null&&te(D,V.startTime-I),J=!1}}break e}finally{g=null,x=me,y=!1}J=void 0}}finally{J?K():M=!1}}}var K;if(typeof _=="function")K=function(){_(Y)};else if(typeof MessageChannel<"u"){var ee=new MessageChannel,U=ee.port2;ee.port1.onmessage=Y,K=function(){U.postMessage(null)}}else K=function(){S(Y,0)};function te(I,J){O=S(function(){I(e.unstable_now())},J)}e.unstable_IdlePriority=5,e.unstable_ImmediatePriority=1,e.unstable_LowPriority=4,e.unstable_NormalPriority=3,e.unstable_Profiling=null,e.unstable_UserBlockingPriority=2,e.unstable_cancelCallback=function(I){I.callback=null},e.unstable_forceFrameRate=function(I){0>I||125<I?console.error("forceFrameRate takes a positive int between 0 and 125, forcing frame rates higher than 125 fps is not supported"):G=0<I?Math.floor(1e3/I):5},e.unstable_getCurrentPriorityLevel=function(){return x},e.unstable_next=function(I){switch(x){case 1:case 2:case 3:var J=3;break;default:J=x}var me=x;x=J;try{return I()}finally{x=me}},e.unstable_requestPaint=function(){C=!0},e.unstable_runWithPriority=function(I,J){switch(I){case 1:case 2:case 3:case 4:case 5:break;default:I=3}var me=x;x=I;try{return J()}finally{x=me}},e.unstable_scheduleCallback=function(I,J,me){var Ce=e.unstable_now();switch(typeof me=="object"&&me!==null?(me=me.delay,me=typeof me=="number"&&0<me?Ce+me:Ce):me=Ce,I){case 1:var H=-1;break;case 2:H=250;break;case 5:H=1073741823;break;case 4:H=1e4;break;default:H=5e3}return H=me+H,I={id:h++,callback:J,priorityLevel:I,startTime:me,expirationTime:H,sortIndex:-1},me>Ce?(I.sortIndex=me,t(p,I),n(m)===null&&I===n(p)&&(T?(E(O),O=-1):T=!0,te(D,me-Ce))):(I.sortIndex=H,t(m,I),w||y||(w=!0,M||(M=!0,K()))),I},e.unstable_shouldYield=$,e.unstable_wrapCallback=function(I){var J=x;return function(){var me=x;x=J;try{return I.apply(this,arguments)}finally{x=me}}}})(pf)),pf}var nv;function bA(){return nv||(nv=1,mf.exports=gA()),mf.exports}var ff={exports:{}},ga={};var av;function yA(){if(av)return ga;av=1;var e=zm();function t(m){var p="https://react.dev/errors/"+m;if(1<arguments.length){p+="?args[]="+encodeURIComponent(arguments[1]);for(var h=2;h<arguments.length;h++)p+="&args[]="+encodeURIComponent(arguments[h])}return"Minified React error #"+m+"; visit "+p+" for the full message or use the non-minified dev environment for full errors and additional helpful warnings."}function n(){}var a={d:{f:n,r:function(){throw Error(t(522))},D:n,C:n,L:n,m:n,X:n,S:n,M:n},p:0,findDOMNode:null},s=Symbol.for("react.portal");function l(m,p,h){var g=3<arguments.length&&arguments[3]!==void 0?arguments[3]:null;return{$$typeof:s,key:g==null?null:""+g,children:m,containerInfo:p,implementation:h}}var c=e.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE;function d(m,p){if(m==="font")return"";if(typeof p=="string")return p==="use-credentials"?p:""}return ga.__DOM_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE=a,ga.createPortal=function(m,p){var h=2<arguments.length&&arguments[2]!==void 0?arguments[2]:null;if(!p||p.nodeType!==1&&p.nodeType!==9&&p.nodeType!==11)throw Error(t(299));return l(m,p,null,h)},ga.flushSync=function(m){var p=c.T,h=a.p;try{if(c.T=null,a.p=2,m)return m()}finally{c.T=p,a.p=h,a.d.f()}},ga.preconnect=function(m,p){typeof m=="string"&&(p?(p=p.crossOrigin,p=typeof p=="string"?p==="use-credentials"?p:"":void 0):p=null,a.d.C(m,p))},ga.prefetchDNS=function(m){typeof m=="string"&&a.d.D(m)},ga.preinit=function(m,p){if(typeof m=="string"&&p&&typeof p.as=="string"){var h=p.as,g=d(h,p.crossOrigin),x=typeof p.integrity=="string"?p.integrity:void 0,y=typeof p.fetchPriority=="string"?p.fetchPriority:void 0;h==="style"?a.d.S(m,typeof p.precedence=="string"?p.precedence:void 0,{crossOrigin:g,integrity:x,fetchPriority:y}):h==="script"&&a.d.X(m,{crossOrigin:g,integrity:x,fetchPriority:y,nonce:typeof p.nonce=="string"?p.nonce:void 0})}},ga.preinitModule=function(m,p){if(typeof m=="string")if(typeof p=="object"&&p!==null){if(p.as==null||p.as==="script"){var h=d(p.as,p.crossOrigin);a.d.M(m,{crossOrigin:h,integrity:typeof p.integrity=="string"?p.integrity:void 0,nonce:typeof p.nonce=="string"?p.nonce:void 0})}}else p==null&&a.d.M(m)},ga.preload=function(m,p){if(typeof m=="string"&&typeof p=="object"&&p!==null&&typeof p.as=="string"){var h=p.as,g=d(h,p.crossOrigin);a.d.L(m,h,{crossOrigin:g,integrity:typeof p.integrity=="string"?p.integrity:void 0,nonce:typeof p.nonce=="string"?p.nonce:void 0,type:typeof p.type=="string"?p.type:void 0,fetchPriority:typeof p.fetchPriority=="string"?p.fetchPriority:void 0,referrerPolicy:typeof p.referrerPolicy=="string"?p.referrerPolicy:void 0,imageSrcSet:typeof p.imageSrcSet=="string"?p.imageSrcSet:void 0,imageSizes:typeof p.imageSizes=="string"?p.imageSizes:void 0,media:typeof p.media=="string"?p.media:void 0})}},ga.preloadModule=function(m,p){if(typeof m=="string")if(p){var h=d(p.as,p.crossOrigin);a.d.m(m,{as:typeof p.as=="string"&&p.as!=="script"?p.as:void 0,crossOrigin:h,integrity:typeof p.integrity=="string"?p.integrity:void 0})}else a.d.m(m)},ga.requestFormReset=function(m){a.d.r(m)},ga.unstable_batchedUpdates=function(m,p){return m(p)},ga.useFormState=function(m,p,h){return c.H.useFormState(m,p,h)},ga.useFormStatus=function(){return c.H.useHostTransitionStatus()},ga.version="19.2.4",ga}var rv;function Fk(){if(rv)return ff.exports;rv=1;function e(){if(!(typeof __REACT_DEVTOOLS_GLOBAL_HOOK__>"u"||typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE!="function"))try{__REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE(e)}catch(t){console.error(t)}}return e(),ff.exports=yA(),ff.exports}var iv;function xA(){if(iv)return Jl;iv=1;var e=bA(),t=zm(),n=Fk();function a(r){var o="https://react.dev/errors/"+r;if(1<arguments.length){o+="?args[]="+encodeURIComponent(arguments[1]);for(var u=2;u<arguments.length;u++)o+="&args[]="+encodeURIComponent(arguments[u])}return"Minified React error #"+r+"; visit "+o+" for the full message or use the non-minified dev environment for full errors and additional helpful warnings."}function s(r){return!(!r||r.nodeType!==1&&r.nodeType!==9&&r.nodeType!==11)}function l(r){var o=r,u=r;if(r.alternate)for(;o.return;)o=o.return;else{r=o;do o=r,(o.flags&4098)!==0&&(u=o.return),r=o.return;while(r)}return o.tag===3?u:null}function c(r){if(r.tag===13){var o=r.memoizedState;if(o===null&&(r=r.alternate,r!==null&&(o=r.memoizedState)),o!==null)return o.dehydrated}return null}function d(r){if(r.tag===31){var o=r.memoizedState;if(o===null&&(r=r.alternate,r!==null&&(o=r.memoizedState)),o!==null)return o.dehydrated}return null}function m(r){if(l(r)!==r)throw Error(a(188))}function p(r){var o=r.alternate;if(!o){if(o=l(r),o===null)throw Error(a(188));return o!==r?null:r}for(var u=r,f=o;;){var b=u.return;if(b===null)break;var v=b.alternate;if(v===null){if(f=b.return,f!==null){u=f;continue}break}if(b.child===v.child){for(v=b.child;v;){if(v===u)return m(b),r;if(v===f)return m(b),o;v=v.sibling}throw Error(a(188))}if(u.return!==f.return)u=b,f=v;else{for(var j=!1,P=b.child;P;){if(P===u){j=!0,u=b,f=v;break}if(P===f){j=!0,f=b,u=v;break}P=P.sibling}if(!j){for(P=v.child;P;){if(P===u){j=!0,u=v,f=b;break}if(P===f){j=!0,f=v,u=b;break}P=P.sibling}if(!j)throw Error(a(189))}}if(u.alternate!==f)throw Error(a(190))}if(u.tag!==3)throw Error(a(188));return u.stateNode.current===u?r:o}function h(r){var o=r.tag;if(o===5||o===26||o===27||o===6)return r;for(r=r.child;r!==null;){if(o=h(r),o!==null)return o;r=r.sibling}return null}var g=Object.assign,x=Symbol.for("react.element"),y=Symbol.for("react.transitional.element"),w=Symbol.for("react.portal"),T=Symbol.for("react.fragment"),C=Symbol.for("react.strict_mode"),S=Symbol.for("react.profiler"),E=Symbol.for("react.consumer"),_=Symbol.for("react.context"),L=Symbol.for("react.forward_ref"),D=Symbol.for("react.suspense"),M=Symbol.for("react.suspense_list"),O=Symbol.for("react.memo"),G=Symbol.for("react.lazy"),Q=Symbol.for("react.activity"),$=Symbol.for("react.memo_cache_sentinel"),Y=Symbol.iterator;function K(r){return r===null||typeof r!="object"?null:(r=Y&&r[Y]||r["@@iterator"],typeof r=="function"?r:null)}var ee=Symbol.for("react.client.reference");function U(r){if(r==null)return null;if(typeof r=="function")return r.$$typeof===ee?null:r.displayName||r.name||null;if(typeof r=="string")return r;switch(r){case T:return"Fragment";case S:return"Profiler";case C:return"StrictMode";case D:return"Suspense";case M:return"SuspenseList";case Q:return"Activity"}if(typeof r=="object")switch(r.$$typeof){case w:return"Portal";case _:return r.displayName||"Context";case E:return(r._context.displayName||"Context")+".Consumer";case L:var o=r.render;return r=r.displayName,r||(r=o.displayName||o.name||"",r=r!==""?"ForwardRef("+r+")":"ForwardRef"),r;case O:return o=r.displayName||null,o!==null?o:U(r.type)||"Memo";case G:o=r._payload,r=r._init;try{return U(r(o))}catch{}}return null}var te=Array.isArray,I=t.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,J=n.__DOM_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,me={pending:!1,data:null,method:null,action:null},Ce=[],H=-1;function V(r){return{current:r}}function fe(r){0>H||(r.current=Ce[H],Ce[H]=null,H--)}function z(r,o){H++,Ce[H]=r.current,r.current=o}var je=V(null),Ue=V(null),qe=V(null),He=V(null);function ut(r,o){switch(z(qe,o),z(Ue,r),z(je,null),o.nodeType){case 9:case 11:r=(r=o.documentElement)&&(r=r.namespaceURI)?vx(r):0;break;default:if(r=o.tagName,o=o.namespaceURI)o=vx(o),r=wx(o,r);else switch(r){case"svg":r=1;break;case"math":r=2;break;default:r=0}}fe(je),z(je,r)}function dt(){fe(je),fe(Ue),fe(qe)}function Nt(r){r.memoizedState!==null&&z(He,r);var o=je.current,u=wx(o,r.type);o!==u&&(z(Ue,r),z(je,u))}function wt(r){Ue.current===r&&(fe(je),fe(Ue)),He.current===r&&(fe(He),Vl._currentValue=me)}var Zt,Wt;function rt(r){if(Zt===void 0)try{throw Error()}catch(u){var o=u.stack.trim().match(/\n( *(at )?)/);Zt=o&&o[1]||"",Wt=-1<u.stack.indexOf(`
3
3
  at`)?" (<anonymous>)":-1<u.stack.indexOf("@")?"@unknown:0:0":""}return`
4
4
  `+Zt+r+Wt}var $e=!1;function mt(r,o){if(!r||$e)return"";$e=!0;var u=Error.prepareStackTrace;Error.prepareStackTrace=void 0;try{var f={DetermineComponentFrameRoot:function(){try{if(o){var Oe=function(){throw Error()};if(Object.defineProperty(Oe.prototype,"props",{set:function(){throw Error()}}),typeof Reflect=="object"&&Reflect.construct){try{Reflect.construct(Oe,[])}catch(Te){var ke=Te}Reflect.construct(r,[],Oe)}else{try{Oe.call()}catch(Te){ke=Te}r.call(Oe.prototype)}}else{try{throw Error()}catch(Te){ke=Te}(Oe=r())&&typeof Oe.catch=="function"&&Oe.catch(function(){})}}catch(Te){if(Te&&ke&&typeof Te.stack=="string")return[Te.stack,ke.stack]}return[null,null]}};f.DetermineComponentFrameRoot.displayName="DetermineComponentFrameRoot";var b=Object.getOwnPropertyDescriptor(f.DetermineComponentFrameRoot,"name");b&&b.configurable&&Object.defineProperty(f.DetermineComponentFrameRoot,"name",{value:"DetermineComponentFrameRoot"});var v=f.DetermineComponentFrameRoot(),j=v[0],P=v[1];if(j&&P){var oe=j.split(`
@@ -844,29 +844,29 @@ if (ip && typeof ip.join !== 'function') {
844
844
  };
845
845
  }
846
846
  await import("${new URL("/assets/pdf.worker.min-CHFwMXne.mjs",import.meta.url).toString()}");
847
- `;ch=URL.createObjectURL(new Blob([t],{type:"text/javascript"}))}return ch}async function Ane(e,t,n){const a=await va(()=>import("./pdf-DMRcuM1e.js"),[]);a.GlobalWorkerOptions.workerSrc=Cne();const s=await a.getDocument({url:e}).promise,l=[];for(let c=1;c<=s.numPages;c++){const d=await s.getPage(c),m=d.getViewport({scale:1.5*n.zoom}),p=document.createElement("canvas");p.width=Math.floor(m.width),p.height=Math.floor(m.height),p.style.width=`${Math.floor(m.width)}px`,p.style.height=`${Math.floor(m.height)}px`,p.style.marginBottom="8px",p.style.boxShadow="0 1px 4px rgba(0,0,0,0.15)",p.style.borderRadius="2px";const h=p.getContext("2d");if(!h)throw new Error("canvas 2d context unavailable");await d.render({canvas:p,canvasContext:h,viewport:m}).promise,p.dataset.page=String(c),t.appendChild(p),l.push(p)}return n.onReady(s.numPages),()=>{for(const c of l)c.remove();s.cleanup()}}async function Tne(e,t){const{renderAsync:n}=await va(async()=>{const{renderAsync:s}=await import("./docx-preview-BDequ2bp.js");return{renderAsync:s}},[]),a=await fetch(e).then(s=>{if(!s.ok)throw new Error(`HTTP ${s.status}`);return s.blob()});if(a.size===0)throw new Error("empty docx");return await n(a,t,void 0,{inWrapper:!0,ignoreWidth:!0,ignoreHeight:!1,breakPages:!0,className:"office-docx"}),()=>{t.innerHTML=""}}async function Nne(e,t){const n=await va(()=>import("./xlsx-CNerDvZX.js"),[]),a=await fetch(e).then(d=>{if(!d.ok)throw new Error(`HTTP ${d.status}`);return d.arrayBuffer()});if(a.byteLength===0)throw new Error("empty xlsx");const s=n.read(a,{type:"array"});if(!s.SheetNames||s.SheetNames.length===0)throw new Error("no sheets");const l=n.utils.sheet_to_html(s.Sheets[s.SheetNames[0]],{id:"office-xlsx-sheet",editable:!1});t.innerHTML=l;const c=document.createElement("style");return c.textContent=`
847
+ `;ch=URL.createObjectURL(new Blob([t],{type:"text/javascript"}))}return ch}async function Ane(e,t,n){const a=await va(()=>import("./pdf-DMRcuM1e.js"),[]);a.GlobalWorkerOptions.workerSrc=Cne();const s=await a.getDocument({url:e}).promise,l=[];for(let c=1;c<=s.numPages;c++){const d=await s.getPage(c),m=d.getViewport({scale:1.5*n.zoom}),p=document.createElement("canvas");p.width=Math.floor(m.width),p.height=Math.floor(m.height),p.style.width=`${Math.floor(m.width)}px`,p.style.height=`${Math.floor(m.height)}px`,p.style.marginBottom="8px",p.style.boxShadow="0 1px 4px rgba(0,0,0,0.15)",p.style.borderRadius="2px";const h=p.getContext("2d");if(!h)throw new Error("canvas 2d context unavailable");await d.render({canvas:p,canvasContext:h,viewport:m}).promise,p.dataset.page=String(c),t.appendChild(p),l.push(p)}return n.onReady(s.numPages),()=>{for(const c of l)c.remove();s.cleanup()}}async function Tne(e,t){const{renderAsync:n}=await va(async()=>{const{renderAsync:s}=await import("./docx-preview-BLbI_SCu.js");return{renderAsync:s}},[]),a=await fetch(e).then(s=>{if(!s.ok)throw new Error(`HTTP ${s.status}`);return s.blob()});if(a.size===0)throw new Error("empty docx");return await n(a,t,void 0,{inWrapper:!0,ignoreWidth:!0,ignoreHeight:!1,breakPages:!0,className:"office-docx"}),()=>{t.innerHTML=""}}async function Nne(e,t){const n=await va(()=>import("./xlsx-CNerDvZX.js"),[]),a=await fetch(e).then(d=>{if(!d.ok)throw new Error(`HTTP ${d.status}`);return d.arrayBuffer()});if(a.byteLength===0)throw new Error("empty xlsx");const s=n.read(a,{type:"array"});if(!s.SheetNames||s.SheetNames.length===0)throw new Error("no sheets");const l=n.utils.sheet_to_html(s.Sheets[s.SheetNames[0]],{id:"office-xlsx-sheet",editable:!1});t.innerHTML=l;const c=document.createElement("style");return c.textContent=`
848
848
  #office-xlsx-sheet { border-collapse: collapse; font-size: 12px; color: var(--fg-primary, #333); }
849
849
  #office-xlsx-sheet td, #office-xlsx-sheet th {
850
850
  border: 1px solid var(--border-default, #ddd); padding: 4px 8px; white-space: nowrap;
851
851
  background: var(--surface-primary, #fff);
852
852
  }
853
853
  #office-xlsx-sheet th { background: var(--surface-elevated, #f3f4f6); font-weight: 600; }
854
- `,t.prepend(c),()=>{t.innerHTML=""}}k.lazy(()=>va(()=>Promise.resolve().then(()=>PS),void 0).then(e=>({default:e.MarkdownMessage})));const Ene=k.lazy(()=>va(()=>import("./ContentRenderer-Dg2NkAAp.js"),[]).then(e=>({default:e.ContentRenderer})));let Do=[],Pw=60;function jne(e){const t=k.useRef(e);t.current=e;const[n]=k.useState(()=>++Pw);return k.useEffect(()=>{const a=()=>t.current();Do.push(a);const s=l=>{l.key==="Escape"&&Do[Do.length-1]===a&&(l.preventDefault(),a())};return window.addEventListener("keydown",s,!0),()=>{window.removeEventListener("keydown",s,!0),Do=Do.filter(l=>l!==a),Do.length===0&&(Pw=60)}},[]),n}const zw=500,Ji=new Map,jm=new Set,Zd=new Map;let em=null;function Mne(){if(Ji.size<=zw)return;const e=Ji.size-zw,t=Ji.keys();for(let n=0;n<e;n++){const{value:a,done:s}=t.next();if(s)break;Ji.delete(a)}}function Bw(e,t){Ji.delete(e),Ji.set(e,t),Mne()}function Hw(e){const t=Zd.get(e);if(t)for(const n of t)n()}function _ne(){em=null;const e=[...jm];jm.clear(),e.length!==0&&Ae.files.check(e).then(({results:t})=>{for(const[n,a]of Object.entries(t))Bw(n,a),Hw(n)}).catch(()=>{for(const t of e)Bw(t,{exists:!1,isFile:!1,type:"unknown"}),Hw(t)})}function Rne(e){Ji.has(e)||jm.has(e)||(jm.add(e),em&&clearTimeout(em),em=setTimeout(_ne,30))}function Dne(e,t){let n=Zd.get(e);return n||(n=new Set,Zd.set(e,n)),n.add(t),()=>{n.delete(t),n.size===0&&Zd.delete(e)}}function Lne(e){const t=k.useCallback(s=>Dne(e,s),[e]),n=k.useCallback(()=>Ji.get(e),[e]),a=k.useSyncExternalStore(t,n,n);return k.useEffect(()=>{Rne(e)},[e]),a}function Ine(e){const t=e.includes("\\")?"\\":"/",n=e.lastIndexOf(t);return n<=0?t==="/"?"/":e.slice(0,2):e.slice(0,n)}function One({filePath:e,onClose:t}){const n=jne(t),[a,s]=k.useState(e),[l,c]=k.useState(!0),[d,m]=k.useState(null),[p,h]=k.useState(""),[g,x]=k.useState(""),[y,w]=k.useState(""),[T,C]=k.useState(""),[S,E]=k.useState(""),[_,L]=k.useState(null),[D,M]=k.useState(!1);k.useEffect(()=>{c(!0),m(null),h(""),L(null),Ae.files.preview(a).then(Y=>{if(Y.type==="directory"&&Array.isArray(Y.entries)){x("directory"),w(Y.name),L(Y.entries);return}x(Y.type),w(Y.name),C(Y.mimeType||""),h(typeof Y.content=="string"?Y.content:""),E(Y.streamUrl||(Y.path?Ae.files.streamUrl(Y.path):"")||(Y.type==="audio"||Y.type==="video"?Ae.files.streamUrl(a):""))}).catch(Y=>{m(String(Y?.message||Y))}).finally(()=>{c(!1)})},[a]);const O=y||a.split(/[/\\]/).pop()||a,G=g==="directory"||a!==e,Q=()=>s(Y=>Ine(Y)),$=()=>{navigator.clipboard?.writeText(a).then(()=>{M(!0),setTimeout(()=>M(!1),1500)}).catch(()=>{})};return zr.createPortal(i.jsx("div",{className:"fixed inset-0 bg-black/40 flex items-center justify-center",style:{zIndex:n},onClick:t,children:i.jsxs("div",{className:"bg-surface-secondary border border-border-default rounded-xl shadow-2xl w-[90vw] max-w-3xl max-h-[85vh] flex flex-col overflow-hidden",onClick:Y=>Y.stopPropagation(),children:[i.jsxs("div",{className:"flex items-center justify-between px-4 py-3 border-b border-border-default bg-surface-elevated/50 shrink-0",children:[i.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[g==="directory"&&i.jsx("svg",{className:"w-4 h-4 shrink-0 text-blue-400",viewBox:"0 0 20 20",fill:"currentColor",children:i.jsx("path",{d:"M3.5 3A1.5 1.5 0 002 4.5v11A1.5 1.5 0 003.5 17h13a1.5 1.5 0 001.5-1.5v-8A1.5 1.5 0 0016.5 6h-6.53a.5.5 0 01-.354-.146L8.706 4.854A1.5 1.5 0 007.586 4H3.5z"})}),g!=="directory"&&i.jsx("svg",{className:"w-4 h-4 shrink-0 text-fg-secondary",viewBox:"0 0 20 20",fill:"currentColor",children:i.jsx("path",{fillRule:"evenodd",d:"M4 4a2 2 0 012-2h4.586A2 2 0 0112 2.586L15.414 6A2 2 0 0116 7.414V16a2 2 0 01-2 2H6a2 2 0 01-2-2V4z",clipRule:"evenodd"})}),i.jsx("span",{className:"text-sm font-medium text-fg-primary truncate",children:O}),i.jsx("span",{className:"text-xs text-fg-tertiary truncate hidden sm:inline",children:a})]}),i.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[G&&i.jsx("button",{className:"text-xs text-fg-secondary hover:text-fg-primary px-2 py-1 rounded hover:bg-surface-elevated transition-colors",onClick:Q,title:"返回上级目录",children:"← 上级"}),i.jsx("button",{className:"text-xs text-fg-secondary hover:text-fg-primary px-2 py-1 rounded hover:bg-surface-elevated transition-colors",onClick:$,title:"复制路径",children:D?"✓ 已复制":"复制路径"}),i.jsx("button",{className:"text-xs text-fg-secondary hover:text-fg-primary px-2 py-1 rounded hover:bg-surface-elevated transition-colors",onClick:()=>Ae.files.reveal(a),title:"Reveal in file explorer",children:i.jsx("svg",{className:"w-4 h-4",viewBox:"0 0 20 20",fill:"currentColor",children:i.jsx("path",{d:"M4.5 17a2.5 2.5 0 01-2.5-2.5v-9A2.5 2.5 0 014.5 3h3.672a1.5 1.5 0 011.06.44L10.56 4.77a.5.5 0 00.354.147H15.5A2.5 2.5 0 0118 7.417v7.083A2.5 2.5 0 0115.5 17h-11z"})})}),i.jsx("button",{className:"text-fg-secondary hover:text-fg-primary p-1 rounded hover:bg-surface-elevated transition-colors",onClick:t,children:i.jsx("svg",{className:"w-4 h-4",viewBox:"0 0 20 20",fill:"currentColor",children:i.jsx("path",{fillRule:"evenodd",d:"M4.293 4.293a1 1 0 011.414 0L10 8.586l4.293-4.293a1 1 0 111.414 1.414L11.414 10l4.293 4.293a1 1 0 01-1.414 1.414L10 11.414l-4.293 4.293a1 1 0 01-1.414-1.414L8.586 10 4.293 5.707a1 1 0 010-1.414z",clipRule:"evenodd"})})})]})]}),i.jsxs("div",{className:"flex-1 overflow-y-auto p-5",children:[l&&i.jsx("div",{className:"flex items-center justify-center py-12",children:i.jsx("div",{className:"w-5 h-5 border-2 border-brand-500/30 border-t-brand-500 rounded-full animate-spin"})}),d&&i.jsxs("div",{className:"text-center py-12 text-fg-secondary text-sm",children:[i.jsx("p",{className:"text-red-400 mb-1",children:"Failed to load file"}),i.jsx("p",{className:"text-xs text-fg-tertiary",children:d})]}),!l&&!d&&g==="directory"&&_&&i.jsx(yne,{path:a,entries:_,onNavigate:Y=>s(Y),onOpenFile:Y=>s(Y),onReveal:Y=>Ae.files.reveal(Y),onCopyPath:Y=>{navigator.clipboard?.writeText(Y).then(()=>{M(!0),setTimeout(()=>M(!1),1500)}).catch(()=>{})}}),!l&&!d&&g==="office"&&S&&i.jsx(vne,{data:{format:(a.split(".").pop()||"pdf").toLowerCase(),streamUrl:S,name:O},reference:a,onFallback:()=>{Ae.files.reveal(a)}}),!l&&!d&&g==="image"&&p&&i.jsx("div",{className:"flex justify-center",children:i.jsx("img",{src:`data:${T||"image/png"};base64,${p}`,alt:O,className:"max-w-full rounded"})}),!l&&!d&&g==="audio"&&S&&i.jsx("audio",{controls:!0,preload:"metadata",src:S,className:"w-full"}),!l&&!d&&g==="video"&&S&&i.jsx("video",{controls:!0,preload:"metadata",src:S,className:"w-full max-h-[60vh] rounded-lg bg-black"}),!l&&!d&&(g==="binary"||!p&&g!=="image"&&g!=="audio"&&g!=="video"&&g!=="directory")&&i.jsxs("div",{className:"text-center py-8 space-y-3",children:[i.jsx("p",{className:"text-sm text-fg-secondary",children:"This file type cannot be previewed."}),i.jsx("button",{className:"px-3 py-2 text-xs rounded-lg bg-brand-600/20 text-brand-500 hover:bg-brand-600/30 transition-colors",onClick:()=>{Ae.files.reveal(a)},children:"Reveal in file explorer"})]}),!l&&!d&&p&&g!=="image"&&g!=="audio"&&g!=="video"&&g!=="binary"&&g!=="directory"&&i.jsx(k.Suspense,{fallback:i.jsx("div",{className:"text-xs text-fg-tertiary",children:"Loading…"}),children:i.jsx(Ene,{content:p,format:g==="text"?"text":g,className:"text-sm"})})]})]})}),document.body)}function Pne({path:e}){const t=Lne(e),[n,a]=k.useState(null),s=qc(),l=t?.exists??!1,c=t?.type==="markdown"||t?.type==="html"||t?.type==="json"||t?.type==="text"||t?.type==="image"||t?.type==="audio"||t?.type==="video"||t?.type==="office"||t?.type==="directory",d=k.useCallback(h=>{if(h.preventDefault(),h.stopPropagation(),!!l)if(c){if(s?.hostAvailable){s.openRightPanel({kind:"file",path:e});return}a(e)}else Ae.files.reveal(e)},[l,c,e,s]),m="inline w-3 h-3 align-[-0.125em]",p=c?i.jsx("svg",{className:m,viewBox:"0 0 20 20",fill:"currentColor",children:i.jsx("path",{fillRule:"evenodd",d:"M4 4a2 2 0 012-2h4.586A2 2 0 0112 2.586L15.414 6A2 2 0 0116 7.414V16a2 2 0 01-2 2H6a2 2 0 01-2-2V4zm2 6a1 1 0 011-1h6a1 1 0 110 2H7a1 1 0 01-1-1zm1 3a1 1 0 100 2h6a1 1 0 100-2H7z",clipRule:"evenodd"})}):i.jsx("svg",{className:m,viewBox:"0 0 20 20",fill:"currentColor",children:i.jsx("path",{fillRule:"evenodd",d:"M4 4a2 2 0 012-2h4.586A2 2 0 0112 2.586L15.414 6A2 2 0 0116 7.414V16a2 2 0 01-2 2H6a2 2 0 01-2-2V4z",clipRule:"evenodd"})});return t?l?i.jsxs(i.Fragment,{children:[i.jsxs("code",{"data-file-path-link":"ready",className:"bg-brand-500/10 px-1.5 py-0.5 rounded text-xs font-mono text-brand-500 cursor-pointer hover:bg-brand-500/20 transition-colors border border-brand-500/20 hover:border-brand-500/40 break-all",onClick:d,title:c?"Click to preview":"Click to reveal in file explorer",role:"button",tabIndex:0,children:[i.jsxs("span",{className:"whitespace-nowrap",children:[p,e.charAt(0)]}),e.slice(1)]}),n&&i.jsx(One,{filePath:n,onClose:()=>a(null)})]}):i.jsx("code",{"data-file-path-link":"missing",className:"bg-surface-secondary/50 px-1.5 py-0.5 rounded text-xs font-mono text-fg-tertiary border border-border-default/30 line-through decoration-fg-tertiary/30 break-all",title:"File not found",children:e}):i.jsx("code",{"data-file-path-link":"loading",className:"bg-surface-secondary px-1.5 py-0.5 rounded text-xs font-mono text-fg-secondary break-all",children:e})}let uh=null;function zne(){return uh||(uh=va(()=>import("./mermaid.core-DkHPUH0x.js").then(e=>e.b9),__vite__mapDeps([0,1])).then(e=>(e.default.initialize({startOnLoad:!1,securityLevel:"loose",fontFamily:"inherit"}),e))),uh}function Bne(){const e=document.documentElement;return e.classList.contains("light")?!1:e.classList.contains("dark")||e.classList.contains("cyberpunk")||e.classList.contains("mono")?!0:!window.matchMedia("(prefers-color-scheme: light)").matches}function Hne(e){const t=window.matchMedia("(prefers-color-scheme: dark)");t.addEventListener("change",e);const n=new MutationObserver(e);return n.observe(document.documentElement,{attributes:!0,attributeFilter:["class"]}),()=>{t.removeEventListener("change",e),n.disconnect()}}function $ne(){return Bne()}function qne(){return k.useSyncExternalStore(Hne,$ne)}function RS({code:e}){const{t}=ot("common"),n=k.useRef(null),[a,s]=k.useState(null),[l,c]=k.useState(!0),d=k.useId(),m=k.useRef(0),p=k.useRef(null),h=qne();return k.useEffect(()=>{if(!e.trim()||p.current&&p.current.code===e&&p.current.dark===h)return;let g=!1;return c(!0),s(null),m.current+=1,(async()=>{try{const x=await zne();if(g)return;x.default.initialize({startOnLoad:!1,theme:h?"dark":"default",securityLevel:"loose",fontFamily:"inherit"});const y=`mermaid-${d.replace(/:/g,"")}-${m.current}`,{svg:w}=await x.default.render(y,e.trim());if(g)return;n.current&&(n.current.innerHTML=w,p.current={code:e,dark:h})}catch(x){g||s(x instanceof Error?x.message:String(x))}finally{g||c(!1)}})(),()=>{g=!0}},[e,d,h]),a?i.jsxs("div",{className:"my-2 rounded-lg overflow-hidden border border-red-500/30",children:[i.jsxs("div",{className:"flex items-center gap-1.5 px-3 py-1.5 bg-red-500/10 border-b border-red-500/20",children:[i.jsx("svg",{className:"w-3.5 h-3.5 text-red-400",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:i.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-2.5L13.732 4c-.77-.833-1.964-.833-2.732 0L4.082 16.5c-.77.833.192 2.5 1.732 2.5z"})}),i.jsx("span",{className:"text-[10px] font-medium text-red-400",children:t("markdown.mermaidRenderError")})]}),a&&i.jsx("div",{className:"px-3 py-2 bg-surface-secondary/60 text-[11px] font-mono text-red-300/90 whitespace-pre-wrap break-words border-b border-red-500/10 max-h-40 overflow-y-auto",children:a}),i.jsx("pre",{className:"p-3 bg-surface-secondary text-xs text-fg-secondary overflow-x-auto font-mono",children:e})]}):i.jsxs("div",{className:"not-prose my-2 rounded-lg bg-surface-secondary border border-border-subtle p-4 overflow-x-auto",children:[l&&i.jsxs("div",{className:"flex items-center gap-2 text-xs text-fg-tertiary",children:[i.jsx("div",{className:"w-4 h-4 border-2 border-fg-tertiary/30 border-t-fg-tertiary rounded-full animate-spin"}),t("markdown.renderingDiagram")]}),i.jsx("div",{ref:n,className:`flex justify-center [&>svg]:max-w-full${l?" hidden":""}`})]})}const Fne="/assets/viz-global-C_AyN6D9.js";let Rd=!1,dh=null;function Une(){return Rd?Promise.resolve():new Promise((e,t)=>{const n=document.querySelector("script[data-plantuml-viz]");if(n){globalThis.Viz?(Rd=!0,e()):(n.addEventListener("load",()=>{Rd=!0,e()}),n.addEventListener("error",()=>t(new Error("Failed to load viz-global.js"))));return}const a=document.createElement("script");a.setAttribute("data-plantuml-viz",""),a.src=Fne,a.onload=()=>{Rd=!0,e()},a.onerror=()=>t(new Error("Failed to load viz-global.js")),document.head.appendChild(a)})}function Gne(){return dh||(dh=Une().then(()=>va(()=>import("./plantuml-DezRDxd4.js"),[]))),dh}let $w=Promise.resolve();function Kne(e,t){const n=$w.then(()=>new Promise((a,s)=>{Gne().then(({renderToString:l})=>{const c=e.split(/\r\n|\r|\n/);l(c,a,s,{dark:t})}).catch(s)}));return $w=n.then(()=>{},()=>{}),n}function Vne(){const e=document.documentElement;return e.classList.contains("light")?!1:e.classList.contains("dark")||e.classList.contains("cyberpunk")||e.classList.contains("mono")?!0:!window.matchMedia("(prefers-color-scheme: light)").matches}function Wne(e){const t=window.matchMedia("(prefers-color-scheme: dark)");t.addEventListener("change",e);const n=new MutationObserver(e);return n.observe(document.documentElement,{attributes:!0,attributeFilter:["class"]}),()=>{t.removeEventListener("change",e),n.disconnect()}}function Yne(){return k.useSyncExternalStore(Wne,()=>Vne())}function DS({code:e}){const{t}=ot("common"),[n,a]=k.useState(null),[s,l]=k.useState(null),[c,d]=k.useState(!0),m=k.useRef(null),p=Yne();return k.useEffect(()=>{if(!e.trim()||m.current&&m.current.code===e&&m.current.dark===p)return;let h=!1;return d(!0),l(null),Kne(e.trim(),p).then(g=>{h||(a(g),m.current={code:e,dark:p})}).catch(g=>{h||l(g instanceof Error?g.message:String(g))}).finally(()=>{h||d(!1)}),()=>{h=!0}},[e,p]),s?i.jsxs("div",{className:"my-2 rounded-lg overflow-hidden border border-red-500/30",children:[i.jsxs("div",{className:"flex items-center gap-1.5 px-3 py-1.5 bg-red-500/10 border-b border-red-500/20",children:[i.jsx("svg",{className:"w-3.5 h-3.5 text-red-400",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:i.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-2.5L13.732 4c-.77-.833-1.964-.833-2.732 0L4.082 16.5c-.77.833.192 2.5 1.732 2.5z"})}),i.jsx("span",{className:"text-[10px] font-medium text-red-400",children:t("markdown.plantumlRenderError")})]}),s&&i.jsx("div",{className:"px-3 py-2 bg-surface-secondary/60 text-[11px] font-mono text-red-300/90 whitespace-pre-wrap break-words border-b border-red-500/10 max-h-40 overflow-y-auto",children:s}),i.jsx("pre",{className:"p-3 bg-surface-secondary text-xs text-fg-secondary overflow-x-auto font-mono",children:e})]}):i.jsxs("div",{className:"not-prose my-2 rounded-lg bg-surface-secondary border border-border-subtle p-4 overflow-x-auto",children:[c&&i.jsxs("div",{className:"flex items-center gap-2 text-xs text-fg-tertiary",children:[i.jsx("div",{className:"w-4 h-4 border-2 border-fg-tertiary/30 border-t-fg-tertiary rounded-full animate-spin"}),t("markdown.renderingDiagram")]}),n&&i.jsx("div",{className:`flex justify-center [&>svg]:max-w-full${c?" hidden":""}`,dangerouslySetInnerHTML:{__html:n}})]})}function dg({code:e,language:t,children:n}){const{t:a}=ot("common"),[s,l]=k.useState("rendered"),[c,d]=k.useState(!1),m=k.useCallback(async()=>{await hb(e)&&(d(!0),setTimeout(()=>d(!1),1800))},[e]);return i.jsxs("div",{className:"not-prose my-2 rounded-lg overflow-hidden border border-border-subtle",children:[i.jsxs("div",{className:"flex items-center justify-between px-3 py-1.5 border-b border-border-subtle bg-surface-secondary",children:[i.jsx("span",{className:"text-[10px] font-medium text-fg-tertiary uppercase tracking-wider select-none",children:t}),i.jsxs("div",{className:"flex items-center gap-1",children:[i.jsx("button",{onClick:()=>l("rendered"),className:`px-2 py-0.5 rounded text-[10px] font-medium transition-colors ${s==="rendered"?"bg-brand-600/20 text-brand-500":"text-fg-tertiary hover:text-fg-secondary"}`,children:i.jsxs("span",{className:"flex items-center gap-1",children:[i.jsxs("svg",{className:"w-3 h-3",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:[i.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M15 12a3 3 0 11-6 0 3 3 0 016 0z"}),i.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M2.458 12C3.732 7.943 7.523 5 12 5c4.478 0 8.268 2.943 9.542 7-1.274 4.057-5.064 7-9.542 7-4.477 0-8.268-2.943-9.542-7z"})]}),a("markdown.viewRendered")]})}),i.jsx("button",{onClick:()=>l("source"),className:`px-2 py-0.5 rounded text-[10px] font-medium transition-colors ${s==="source"?"bg-brand-600/20 text-brand-500":"text-fg-tertiary hover:text-fg-secondary"}`,children:i.jsxs("span",{className:"flex items-center gap-1",children:[i.jsx("svg",{className:"w-3 h-3",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:i.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M10 20l4-16m4 4l4 4-4 4M6 16l-4-4 4-4"})}),a("markdown.viewSource")]})})]})]}),s==="rendered"?i.jsx("div",{children:n}):i.jsxs("div",{className:"relative group/source",children:[i.jsx("pre",{className:"p-3 overflow-x-auto text-xs font-mono text-fg-secondary bg-surface-secondary leading-relaxed whitespace-pre-wrap break-words",children:e}),i.jsx("button",{onClick:m,className:"absolute top-2 right-2 p-1.5 rounded-md bg-surface-elevated/80 hover:bg-surface-overlay text-fg-tertiary hover:text-fg-primary backdrop-blur-sm border border-border-default/50 transition-all opacity-0 group-hover/source:opacity-100",title:a("markdown.copyContent"),children:c?i.jsx("svg",{className:"w-3.5 h-3.5 text-green-400",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:i.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M5 13l4 4L19 7"})}):i.jsx("svg",{className:"w-3.5 h-3.5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:i.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"})})})]})]})}const Qne=[RS,DS];function Xne(e){for(const t of k.Children.toArray(e))if(k.isValidElement(t)&&typeof t.props?.className=="string"){const n=t.props.className;return Kte(n)}return null}function bc(e){if(typeof e=="string")return e;if(typeof e=="number")return String(e);if(!e)return"";if(Array.isArray(e))return e.map(bc).join("");if(k.isValidElement(e)){const t=e.props;return bc(t.children)}return""}function Jne({children:e}){const{t}=ot("common"),n=Xne(e),a=k.useRef(null),[s,l]=k.useState(!1),[c,d]=k.useState("rendered"),m=k.useCallback(async()=>{let h;c==="source"?h=bc(e):h=a.current?.querySelector("code")?.textContent??"";try{await navigator.clipboard.writeText(h),l(!0),setTimeout(()=>l(!1),1800)}catch{}},[c,e]);if(k.Children.toArray(e).some(h=>k.isValidElement(h)&&Qne.includes(h.type))){const h=bc(e),g=n==="mermaid"||n==="plantuml"?n:"diagram";return i.jsx(dg,{code:h,language:g,children:e})}return n==="mermaid"||n==="plantuml"?i.jsx(i.Fragment,{children:e}):i.jsxs("div",{className:"not-prose relative group/code my-2 rounded-lg overflow-hidden bg-surface-secondary border border-border-subtle",children:[n&&i.jsxs("div",{className:"flex items-center justify-between px-3 py-1.5 border-b border-border-subtle",children:[i.jsx("span",{className:"text-[10px] font-medium text-fg-tertiary uppercase tracking-wider select-none",children:Gte(n)}),i.jsxs("div",{className:"flex items-center gap-1",children:[i.jsx("button",{onClick:()=>d("rendered"),className:`px-1.5 py-0.5 rounded text-[10px] font-medium transition-colors ${c==="rendered"?"bg-brand-600/20 text-brand-500":"text-fg-tertiary hover:text-fg-secondary"}`,children:t("markdown.viewRendered")}),i.jsx("button",{onClick:()=>d("source"),className:`px-1.5 py-0.5 rounded text-[10px] font-medium transition-colors ${c==="source"?"bg-brand-600/20 text-brand-500":"text-fg-tertiary hover:text-fg-secondary"}`,children:t("markdown.viewSource")})]})]}),i.jsxs("div",{className:"relative",children:[c==="rendered"?i.jsx("pre",{ref:a,className:"p-3 overflow-x-auto text-xs [&>code]:p-0 [&>code]:rounded-none [&>code]:text-fg-secondary",children:k.Children.map(e,h=>k.isValidElement(h)?k.cloneElement(h,{style:{background:"transparent",padding:0}}):h)}):i.jsx("pre",{className:"p-3 overflow-x-auto text-xs font-mono text-fg-secondary whitespace-pre-wrap break-words",children:bc(e)}),i.jsx("button",{onClick:m,className:"absolute top-2 right-2 p-1.5 rounded-md bg-surface-elevated/80 hover:bg-surface-overlay text-fg-tertiary hover:text-fg-primary backdrop-blur-sm border border-border-default/50 transition-all opacity-0 group-hover/code:opacity-100",title:t("markdown.copyContent"),children:s?i.jsx("svg",{className:"w-3.5 h-3.5 text-green-400",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:i.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M5 13l4 4L19 7"})}):i.jsx("svg",{className:"w-3.5 h-3.5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:i.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"})})})]})]})}const qw="#mention:",Mm="#entity:",Zne=/^\[([^\]]+)\]\(#entity:((tsk|req|proj|dlv|agt|team)_[a-f0-9]{6,})\)$/i,LS=/^(workflow|task|requirement|project|deliverable|agent|team):(.+)$/,mg="text-brand-500 hover:text-brand-500 underline break-all cursor-pointer";function pg(e){return e.type==="text"?e.value??"":(e.children??[]).map(pg).join("")}function eae(e){return e.type==="text"&&(e.value??"").trim()===""}function tae(e){if(!e?.children)return null;const t=e.children.filter(a=>!eae(a));if(t.length!==1)return null;const n=t[0];if(n.type==="element"&&n.tagName==="a"){const a=n.properties?.href;if(!a)return null;const s=pg(n);if(a.startsWith(Mm))return{id:a.slice(Mm.length)};const l=a.match(LS);return l&&l[1]!=="workflow"?{id:l[2],type:TS(l[1]),label:s}:null}if(n.type==="element"&&n.tagName==="code"){const a=pg(n).trim();if(Em(a))return{id:a}}if(n.type==="text"){const a=(n.value??"").trim();if(Em(a))return{id:a}}return null}const nae={p:({children:e})=>i.jsx("p",{className:"mb-2 last:mb-0 leading-relaxed text-fg-secondary",children:e}),h1:({children:e})=>i.jsx("h1",{className:"text-base font-bold mb-2 mt-3 first:mt-0 text-fg-primary",children:e}),h2:({children:e})=>i.jsx("h2",{className:"text-sm font-bold mb-2 mt-3 first:mt-0 text-fg-primary",children:e}),h3:({children:e})=>i.jsx("h3",{className:"text-sm font-semibold mb-1 mt-2 first:mt-0 text-fg-primary",children:e}),h4:({children:e})=>i.jsx("h4",{className:"text-sm font-semibold mb-1 mt-2 first:mt-0 text-fg-primary",children:e}),h5:({children:e})=>i.jsx("h5",{className:"text-xs font-semibold mb-1 mt-2 first:mt-0 text-fg-primary",children:e}),h6:({children:e})=>i.jsx("h6",{className:"text-xs font-medium mb-1 mt-2 first:mt-0 text-fg-primary",children:e}),ul:({children:e})=>i.jsx("ul",{className:"list-disc pl-4 mb-2 space-y-0.5",children:e}),ol:({children:e,start:t})=>i.jsx("ol",{start:t,className:"list-decimal pl-7 mb-2 space-y-0.5",children:e}),li:({children:e,value:t})=>i.jsx("li",{value:t,className:"leading-relaxed text-fg-secondary marker:text-fg-secondary",children:e}),code:({children:e,className:t})=>{const n=typeof e=="string"?e:String(e??""),a=n.trim();if(t?.includes("language-plantuml")||Fte(a))return i.jsx(dg,{code:a,language:"plantuml",children:i.jsx(DS,{code:a})});if(t?.includes("language-mermaid"))return i.jsx(dg,{code:a,language:"mermaid",children:i.jsx(RS,{code:a})});if(t?.includes("language-"))return i.jsx("code",{className:`${t} text-fg-secondary font-mono text-xs`,children:e});if(Em(n))return i.jsx(gc,{id:n.trim()});const s=n.match(Zne);return s?i.jsx(gc,{id:s[2],label:s[1]}):Xte(n)?i.jsx(Pne,{path:n}):i.jsx("code",{className:"bg-surface-secondary px-1.5 py-0.5 rounded text-xs font-mono text-brand-500 break-all",children:e})},pre:({children:e})=>i.jsx(Jne,{children:e}),strong:({children:e})=>i.jsx("strong",{className:"font-bold text-fg-primary",children:e}),em:({children:e})=>i.jsx("em",{className:"italic text-fg-secondary",children:e}),del:({children:e})=>i.jsx("del",{className:"line-through text-fg-tertiary",children:e}),blockquote:({children:e})=>i.jsx("blockquote",{className:"border-l-2 border-brand-500 pl-3 my-2 text-fg-secondary italic",children:e}),a:({href:e,children:t})=>i.jsx("a",{href:e,className:mg,children:t}),hr:()=>i.jsx("hr",{className:"border-border-default my-3"}),table:({children:e})=>i.jsx("div",{className:"overflow-x-auto my-2",children:i.jsx("table",{className:"min-w-full text-sm border-collapse border border-border-default",children:e})}),thead:({children:e})=>i.jsx("thead",{className:"bg-surface-secondary",children:e}),tbody:({children:e})=>i.jsx("tbody",{className:"divide-y divide-border-default",children:e}),tr:({children:e})=>i.jsx("tr",{className:"hover:bg-surface-elevated/50 transition-colors",children:e}),th:({children:e})=>i.jsx("th",{className:"px-3 py-2 text-left text-sm font-semibold text-fg-primary border border-border-default",children:e}),td:({children:e})=>i.jsx("td",{className:"px-3 py-2 text-sm text-fg-primary border border-border-default",children:e})},aae=/\.(png|jpe?g|gif|webp|svg|bmp|ico)$/i;function rae(e){const t=fb(e);return vS(e)&&aae.test(t.split("?")[0]??t)}function iae(e,t){const n=fb(e);if(n.startsWith("/")||n.startsWith("~/")||/^[A-Za-z]:\//.test(n)||n.startsWith("//"))return n;if((n.startsWith("./")||n.startsWith("../"))&&t){const s=((t.replace(/\\/g,"/").endsWith("/")?t.replace(/\\/g,"/"):`${t.replace(/\\/g,"/")}/`)+n).split("/"),l=[];for(const c of s)c===".."?l.pop():c!=="."&&c!==""&&l.push(c);return"/"+l.join("/")}return n}function sae(e){return`/api/files/image?path=${encodeURIComponent(e)}`}function oae(e,t){return rae(e)?sae(iae(e,t)):null}const Lo=new Map,sc=new Map,lae=k.memo(function({src:t,alt:n,onPreview:a,basePath:s}){const l=k.useMemo(()=>oae(t,s)??t,[t,s]),c=l.startsWith("/api/files/image?"),d=Lo.get(l),m=sc.get(l),[p,h]=k.useState(d??(c?null:l)),[g,x]=k.useState(!!d),[y,w]=k.useState(!!m),[T,C]=k.useState(m??null),[S,E]=k.useState(0),_=k.useRef(0),L=k.useCallback(M=>{sc.set(l,M),C(M),w(!0),x(!1)},[l]),D=k.useCallback(()=>{Lo.delete(l),sc.delete(l),w(!1),C(null),x(!1),h(c?null:`${l}${l.includes("?")?"&":"?"}retry=${Date.now()}`),E(M=>M+1)},[l,c]);return k.useEffect(()=>{if(!c)return;const M=Lo.get(l);if(M){h(M),x(!0),w(!1),C(null);return}const O=sc.get(l);if(O!==void 0){w(!0),C(O),x(!1);return}const G=++_.current;w(!1),C(null),x(!1),h(null),(async()=>{try{const Q=await fetch(l,{credentials:"same-origin"});if(G!==_.current)return;if(!Q.ok){let K=`HTTP ${Q.status}`;try{const ee=await Q.json();ee.error&&(K=ee.error)}catch{}throw new Error(K)}const $=await Q.blob();if(G!==_.current)return;if($.size===0)throw new Error("Empty image response");if($.type&&!$.type.startsWith("image/")&&!$.type.includes("octet-stream"))throw new Error(`Unexpected content-type: ${$.type}`);const Y=URL.createObjectURL($);Lo.set(l,Y),h(Y),x(!0),w(!1),C(null)}catch(Q){if(G!==_.current)return;const $=Q instanceof Error?Q.message:String(Q);console.warn("[MarkdownImage] failed to load local image",l,Q),L($)}})()},[c,l,S]),k.useEffect(()=>{if(c)return;const M=sc.get(l);if(M!==void 0){w(!0),C(M),x(!1);return}h(l),x(!!Lo.get(l)),w(!1),C(null)},[l,c,S]),y?i.jsxs("button",{type:"button",onClick:D,title:T??"Click to retry",className:"inline-flex items-center gap-1.5 px-3 py-2 text-xs text-fg-tertiary bg-surface-elevated rounded-lg border border-border-default hover:bg-surface-overlay hover:text-fg-secondary cursor-pointer transition-colors max-w-full",children:[i.jsxs("svg",{className:"w-4 h-4 shrink-0",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:1.5,children:[i.jsx("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2",ry:"2"}),i.jsx("circle",{cx:"8.5",cy:"8.5",r:"1.5"}),i.jsx("polyline",{points:"21 15 16 10 5 21"})]}),i.jsxs("span",{className:"truncate",children:["Failed to load image — click to retry",T?` (${T})`:""]})]}):i.jsxs("span",{className:"inline-block align-middle max-w-full",children:[!g&&i.jsx("span",{className:"block w-full min-h-[80px] max-w-[400px] bg-surface-elevated rounded-lg animate-pulse"}),p?i.jsx("img",{src:p,alt:n??"",onLoad:()=>{c||Lo.set(l,l),x(!0)},onError:()=>{L("Image decode failed")},onClick:()=>a?.(p),className:`max-w-full h-auto rounded-lg cursor-pointer hover:opacity-90 transition-opacity my-1${g?"":" absolute opacity-0 pointer-events-none"}`,style:{maxHeight:"400px",objectFit:"contain"}}):null]})});async function Fw(e){const t=await fetch(e);if(!t.ok)throw new Error(`Failed to fetch image (${t.status})`);return t.blob()}async function cae(e){if(e.type==="image/png")return e;const t=await createImageBitmap(e),n=document.createElement("canvas");n.width=t.width,n.height=t.height;const a=n.getContext("2d");if(!a)throw new Error("Canvas unavailable");return a.drawImage(t,0,0),t.close(),new Promise((s,l)=>{n.toBlob(c=>c?s(c):l(new Error("PNG encode failed")),"image/png")})}function uae(e,t){try{const s=(e.startsWith("data:")?"":new URL(e,window.location.href).pathname).split("/").pop()||"";if(s&&/\.(png|jpe?g|gif|webp|svg|bmp)$/i.test(s))return decodeURIComponent(s)}catch{}return`image.${(t.type.split("/")[1]||"png").replace("jpeg","jpg")}`}function IS({src:e,onClose:t}){const{t:n}=ot("common"),[a,s]=k.useState(null),[l,c]=k.useState(null);Qo(!0),k.useEffect(()=>{const g=x=>{x.key==="Escape"&&t()};return document.addEventListener("keydown",g),()=>document.removeEventListener("keydown",g)},[t]);const d=k.useCallback(g=>{s(g),window.setTimeout(()=>s(null),1600)},[]),m=k.useCallback(async g=>{if(g.stopPropagation(),!l){c("copy");try{const x=await Fw(e),y=await cae(x);await navigator.clipboard.write([new ClipboardItem({"image/png":y})]),d(n("imageCopied"))}catch{d(n("imageCopyFailed"))}finally{c(null)}}},[l,d,e,n]),p=k.useCallback(async g=>{if(g.stopPropagation(),!l){c("download");try{const x=await Fw(e),y=URL.createObjectURL(x),w=document.createElement("a");w.href=y,w.download=uae(e,x),document.body.appendChild(w),w.click(),w.remove(),URL.revokeObjectURL(y),d(n("imageDownloaded"))}catch{d(n("imageDownloadFailed"))}finally{c(null)}}},[l,d,e,n]),h="inline-flex items-center gap-1.5 px-3 py-1.5 rounded-lg bg-white/10 hover:bg-white/20 text-white text-sm transition-colors disabled:opacity-50";return zr.createPortal(i.jsxs("div",{className:"fixed inset-0 z-[9999] bg-black/80 flex items-center justify-center p-4",onClick:t,children:[i.jsxs("div",{className:"absolute top-4 right-4 z-10 flex items-center gap-2",onClick:g=>g.stopPropagation(),children:[i.jsxs("button",{type:"button",className:h,onClick:m,disabled:!!l,title:n("copyImage"),children:[i.jsxs("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[i.jsx("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2"}),i.jsx("path",{d:"M5 15H4a2 2 0 01-2-2V4a2 2 0 012-2h9a2 2 0 012 2v1"})]}),n("copy")]}),i.jsxs("button",{type:"button",className:h,onClick:p,disabled:!!l,title:n("downloadImage"),children:[i.jsxs("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[i.jsx("path",{d:"M21 15v4a2 2 0 01-2 2H5a2 2 0 01-2-2v-4"}),i.jsx("polyline",{points:"7 10 12 15 17 10"}),i.jsx("line",{x1:"12",y1:"15",x2:"12",y2:"3"})]}),n("downloadImage")]}),i.jsx("button",{type:"button",onClick:t,className:"w-10 h-10 rounded-full bg-white/10 hover:bg-white/20 flex items-center justify-center transition-colors",title:n("close"),children:i.jsxs("svg",{className:"w-6 h-6 text-white",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,children:[i.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),i.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]}),a&&i.jsx("div",{className:"absolute top-16 left-1/2 -translate-x-1/2 z-10 px-3 py-1.5 rounded-lg bg-black/70 text-white text-xs",children:a}),i.jsx("img",{src:e,alt:"Preview",className:"max-w-full max-h-[90vh] object-contain rounded-lg",onClick:g=>g.stopPropagation()})]}),document.body)}function OS(e={}){const{onMentionClick:t,basePath:n,onImagePreview:a,contentRef:s,hostAvailable:l,openRightPanel:c}=e,d=k.useCallback((m,p)=>{const h=Rw(p,n);if(h.kind!=="passthrough"){if(m.preventDefault(),m.stopPropagation(),h.kind==="fragment"){Jte(s?.current??null,h.id);return}if(h.kind==="file"){l&&c?c({kind:"file",path:h.path,title:h.path.split(/[/\\]/).pop()}):Ae.files.reveal(h.path).catch(()=>{});return}if(h.kind==="external"){if(l&&c&&/^https?:\/\//i.test(h.url)){c({kind:"url",url:h.url,title:h.url});return}fi(h.url)}}},[n,s,l,c]);return k.useMemo(()=>({...nae,img:({src:m,alt:p})=>i.jsx(lae,{src:m??"",alt:p,onPreview:a,basePath:n},m??""),p:({children:m,node:p})=>{const h=tae(p);return h?i.jsx(pne,{id:h.id,type:h.type,label:h.label}):i.jsx("p",{className:"mb-2 last:mb-0 leading-relaxed text-fg-secondary",children:m})},a:({href:m,children:p})=>{if(m?.startsWith(qw)){const g=decodeURIComponent(m.slice(qw.length));return i.jsx("span",{className:`text-brand-500 font-medium${t?" cursor-pointer hover:underline":""}`,onClick:t?x=>{x.preventDefault(),x.stopPropagation(),t(g,x)}:void 0,title:g,children:p})}if(m?.startsWith(Mm))return i.jsx(gc,{id:m.slice(Mm.length)});{const g=m?.match(LS);if(g){const[,x,y]=g;if(x==="workflow")return i.jsxs("span",{className:"inline-flex items-center gap-0.5 px-1 py-0.5 rounded bg-brand-500/10 text-brand-500 text-xs font-medium cursor-pointer hover:bg-brand-500/20 transition-colors",onClick:T=>{T.preventDefault(),T.stopPropagation(),at.navigate(de.WORK,{boardType:"workflows"})},title:`workflow: ${y}`,children:[i.jsx("span",{className:"text-[10px]",children:"⚙️"}),i.jsx("span",{children:p})]});const w=TS(x);if(w)return i.jsx(gc,{id:y,type:w,label:p})}}if(m&&Em(m))return i.jsx(gc,{id:m.trim(),label:p});const h=Rw(m,n);return h.kind==="fragment"||h.kind==="file"||h.kind==="external"?i.jsx("a",{href:m,className:mg,onClick:g=>d(g,m),title:h.kind==="fragment"?`#${h.id}`:h.kind==="file"?h.path:h.url,children:p}):i.jsx("a",{href:m,className:mg,onClick:g=>{Go()&&m&&!/^[a-zA-Z][a-zA-Z0-9+.-]*:/.test(m)&&g.preventDefault()},children:p})}}),[t,n,a,d])}const Uw=[D5,I3,O3],Gw=[SS,[G3,{strict:"ignore"}],[cS,{detect:!0,ignoreMissing:!0}]];function fg(e){if(/^(deliverable|task|requirement|project|agent|team|workflow):/i.test(e))return e;const n=pb(e);return vS(n)?n:o5(e)}const dae=/(?:<thinking>| thinking)([\s\S]*?)<\/thinking>/g;function mae(e){const t=[];let n=e.replace(dae,(a,s)=>{const l=s.trim();return l&&t.push(l),""});return n=n.replace(/<thinking>/gi,"").replace(/<\/thinking>/gi,""),{thinking:t,rest:n.trim()}}function pae(e=640){const[t,n]=k.useState(()=>window.innerWidth<e);return k.useEffect(()=>{const a=window.matchMedia(`(max-width: ${e-1}px)`),s=l=>n(l.matches);return a.addEventListener("change",s),n(a.matches),()=>a.removeEventListener("change",s)},[e]),t}function fae({content:e,contentRef:t}){const{t:n}=ot("common"),[a,s]=k.useState(!1),[l,c]=k.useState(!1),[d,m]=k.useState(!1),[p,h]=k.useState(null),g=k.useRef(null),x=pae();k.useEffect(()=>{if(!a)return;const C=S=>{g.current&&!g.current.contains(S.target)&&(s(!1),c(!1),m(!1))};return document.addEventListener("mousedown",C),()=>document.removeEventListener("mousedown",C)},[a]);const y=k.useCallback(C=>{h(C),setTimeout(()=>h(null),1500)},[]),w=async()=>{const C=await hb(e);y(n(C?"markdown.copied":"markdown.failed")),s(!1)},T=async C=>{const S=t.current?.firstElementChild;if(!S)return;const E=AS(),_=nne(E),L=await ene(S,C,e,{fontFamily:_.fontFamily,fontSize:_.fontSize,headingScales:_.headingScales}),D=n(C==="light"?"markdown.themeLight":"markdown.themeDark");y(L.ok?L.method==="html"?n("markdown.htmlCopied",{theme:D}):n("markdown.textCopied"):n("markdown.failed")),s(!1)};return i.jsxs("div",{className:"absolute top-1 right-1 z-10 opacity-0 group-hover/md:opacity-100 transition-opacity",ref:g,children:[p&&i.jsx("div",{className:"absolute right-0 top-full mt-1 z-20 px-2 py-0.5 rounded bg-surface-elevated border border-border-default text-[10px] text-fg-secondary whitespace-nowrap shadow-lg",children:p}),i.jsx("button",{onClick:()=>s(C=>!C),className:"p-1.5 rounded-lg bg-surface-elevated/80 hover:bg-surface-overlay text-fg-secondary hover:text-fg-primary backdrop-blur-sm border border-border-default/50 transition-all",title:n("markdown.copyContent"),children:i.jsx("svg",{className:"w-3.5 h-3.5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:i.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"})})}),a&&i.jsx("div",{className:"absolute right-0 top-full mt-1 bg-surface-elevated border border-border-default rounded-lg shadow-xl py-1 min-w-[180px]",children:d?i.jsx(ane,{onClose:()=>m(!1)}):l?i.jsxs("div",{className:"px-3 py-2 text-[11px] text-fg-secondary space-y-2 max-w-[260px]",children:[i.jsxs("div",{className:"flex items-center justify-between mb-1",children:[i.jsx("span",{className:"font-medium text-fg-primary text-xs",children:n("markdown.infoTitle")}),i.jsx("button",{onClick:()=>c(!1),className:"text-fg-tertiary hover:text-fg-primary p-0.5",children:i.jsx("svg",{className:"w-3 h-3",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:i.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M6 18L18 6M6 6l12 12"})})})]}),i.jsxs("div",{children:[i.jsx("span",{className:"font-medium text-fg-primary",children:n("markdown.mdAbbrev")})," — ",n("markdown.infoMdDesc")]}),i.jsxs("div",{children:[i.jsx("span",{className:"font-medium text-fg-primary",children:"☀️"})," — ",n("markdown.infoHtmlLightDesc")]}),i.jsxs("div",{children:[i.jsx("span",{className:"font-medium text-fg-primary",children:"🌙"})," — ",n("markdown.infoHtmlDarkDesc")]})]}):i.jsxs(i.Fragment,{children:[i.jsxs("div",{className:"flex items-center justify-between px-3 py-1 border-b border-border-subtle mb-1",children:[i.jsx("span",{className:"text-[10px] text-fg-tertiary font-medium",children:n("markdown.copyContent")}),i.jsxs("div",{className:"flex items-center gap-1",children:[i.jsx("button",{onClick:()=>m(!0),className:"p-0.5 rounded text-fg-tertiary hover:text-fg-primary transition-colors",title:n("markdown.typographySettings"),children:i.jsxs("svg",{className:"w-3.5 h-3.5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:[i.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M10.325 4.317c.426-1.756 2.924-1.756 3.35 0a1.724 1.724 0 002.573 1.066c1.543-.94 3.31.826 2.37 2.37a1.724 1.724 0 001.066 2.573c1.756.426 1.756 2.924 0 3.35a1.724 1.724 0 00-1.066 2.573c.94 1.543-.826 3.31-2.37 2.37a1.724 1.724 0 00-2.573 1.066c-.426 1.756-2.924 1.756-3.35 0a1.724 1.724 0 00-2.573-1.066c-1.543.94-3.31-.826-2.37-2.37a1.724 1.724 0 00-1.066-2.573c-1.756-.426-1.756-2.924 0-3.35a1.724 1.724 0 001.066-2.573c-.94-1.543.826-3.31 2.37-2.37.996.608 2.296.07 2.572-1.065z"}),i.jsx("circle",{cx:"12",cy:"12",r:"3"})]})}),i.jsx("button",{onClick:()=>c(!0),className:"p-0.5 rounded text-fg-tertiary hover:text-fg-primary transition-colors",title:n("markdown.infoTitle"),children:i.jsxs("svg",{className:"w-3.5 h-3.5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:[i.jsx("circle",{cx:"12",cy:"12",r:"10"}),i.jsx("path",{strokeLinecap:"round",d:"M12 16v-4m0-4h.01"})]})})]})]}),i.jsxs("button",{onClick:w,className:"w-full px-3 py-2 text-left text-xs text-fg-secondary hover:bg-surface-overlay hover:text-fg-primary transition-colors flex items-center gap-2",children:[i.jsx("span",{className:"w-4 text-center text-fg-tertiary shrink-0 font-mono text-[10px]",children:n("markdown.mdAbbrev")}),n(x?"markdown.copyMdSourceShort":"markdown.copyMdSource")]}),i.jsxs("button",{onClick:()=>T("light"),className:"w-full px-3 py-2 text-left text-xs text-fg-secondary hover:bg-surface-overlay hover:text-fg-primary transition-colors flex items-center gap-2",children:[i.jsx("span",{className:"w-4 text-center shrink-0 text-[10px]",children:"☀️"}),n(x?"markdown.copyHtmlLightShort":"markdown.copyHtmlLight")]}),i.jsxs("button",{onClick:()=>T("dark"),className:"w-full px-3 py-2 text-left text-xs text-fg-secondary hover:bg-surface-overlay hover:text-fg-primary transition-colors flex items-center gap-2",children:[i.jsx("span",{className:"w-4 text-center shrink-0 text-[10px]",children:"🌙"}),n(x?"markdown.copyHtmlDarkShort":"markdown.copyHtmlDark")]})]})})]})}const Ea=k.memo(function({content:t,className:n="",onMentionClick:a,knownNames:s,basePath:l}){const{thinking:c,rest:d}=mae(t),m=k.useRef(null),[p,h]=k.useState(null),g=qc(),x=k.useCallback(T=>{let C=ui(T,mS);return C=ui(C,Ite),C=ui(C,Yte),C=ui(C,Bte),C=ui(C,Hte),C=ui(C,S=>Ote(S,s)),C=ui(C,hS),C},[s]),y=k.useMemo(()=>x(d),[d,x]),w=OS({onMentionClick:a,basePath:l,onImagePreview:h,contentRef:m,hostAvailable:g?.hostAvailable,openRightPanel:g?.openRightPanel});return i.jsxs("div",{className:"relative group/md",children:[i.jsx(fae,{content:t,contentRef:m}),i.jsx("div",{ref:m,children:i.jsx(rne,{resetKeys:[y],fallback:i.jsx("div",{className:`prose prose-sm max-w-none break-words whitespace-pre-wrap pr-8 text-fg-secondary ${n}`,children:d}),children:i.jsxs("div",{className:`prose prose-sm max-w-none break-words pr-8 text-fg-secondary ${n}`,children:[c.length>0&&(()=>{const T=c.join(`
854
+ `,t.prepend(c),()=>{t.innerHTML=""}}k.lazy(()=>va(()=>Promise.resolve().then(()=>PS),void 0).then(e=>({default:e.MarkdownMessage})));const Ene=k.lazy(()=>va(()=>import("./ContentRenderer-CY0moVGG.js"),[]).then(e=>({default:e.ContentRenderer})));let Do=[],Pw=60;function jne(e){const t=k.useRef(e);t.current=e;const[n]=k.useState(()=>++Pw);return k.useEffect(()=>{const a=()=>t.current();Do.push(a);const s=l=>{l.key==="Escape"&&Do[Do.length-1]===a&&(l.preventDefault(),a())};return window.addEventListener("keydown",s,!0),()=>{window.removeEventListener("keydown",s,!0),Do=Do.filter(l=>l!==a),Do.length===0&&(Pw=60)}},[]),n}const zw=500,Ji=new Map,jm=new Set,Zd=new Map;let em=null;function Mne(){if(Ji.size<=zw)return;const e=Ji.size-zw,t=Ji.keys();for(let n=0;n<e;n++){const{value:a,done:s}=t.next();if(s)break;Ji.delete(a)}}function Bw(e,t){Ji.delete(e),Ji.set(e,t),Mne()}function Hw(e){const t=Zd.get(e);if(t)for(const n of t)n()}function _ne(){em=null;const e=[...jm];jm.clear(),e.length!==0&&Ae.files.check(e).then(({results:t})=>{for(const[n,a]of Object.entries(t))Bw(n,a),Hw(n)}).catch(()=>{for(const t of e)Bw(t,{exists:!1,isFile:!1,type:"unknown"}),Hw(t)})}function Rne(e){Ji.has(e)||jm.has(e)||(jm.add(e),em&&clearTimeout(em),em=setTimeout(_ne,30))}function Dne(e,t){let n=Zd.get(e);return n||(n=new Set,Zd.set(e,n)),n.add(t),()=>{n.delete(t),n.size===0&&Zd.delete(e)}}function Lne(e){const t=k.useCallback(s=>Dne(e,s),[e]),n=k.useCallback(()=>Ji.get(e),[e]),a=k.useSyncExternalStore(t,n,n);return k.useEffect(()=>{Rne(e)},[e]),a}function Ine(e){const t=e.includes("\\")?"\\":"/",n=e.lastIndexOf(t);return n<=0?t==="/"?"/":e.slice(0,2):e.slice(0,n)}function One({filePath:e,onClose:t}){const n=jne(t),[a,s]=k.useState(e),[l,c]=k.useState(!0),[d,m]=k.useState(null),[p,h]=k.useState(""),[g,x]=k.useState(""),[y,w]=k.useState(""),[T,C]=k.useState(""),[S,E]=k.useState(""),[_,L]=k.useState(null),[D,M]=k.useState(!1);k.useEffect(()=>{c(!0),m(null),h(""),L(null),Ae.files.preview(a).then(Y=>{if(Y.type==="directory"&&Array.isArray(Y.entries)){x("directory"),w(Y.name),L(Y.entries);return}x(Y.type),w(Y.name),C(Y.mimeType||""),h(typeof Y.content=="string"?Y.content:""),E(Y.streamUrl||(Y.path?Ae.files.streamUrl(Y.path):"")||(Y.type==="audio"||Y.type==="video"?Ae.files.streamUrl(a):""))}).catch(Y=>{m(String(Y?.message||Y))}).finally(()=>{c(!1)})},[a]);const O=y||a.split(/[/\\]/).pop()||a,G=g==="directory"||a!==e,Q=()=>s(Y=>Ine(Y)),$=()=>{navigator.clipboard?.writeText(a).then(()=>{M(!0),setTimeout(()=>M(!1),1500)}).catch(()=>{})};return zr.createPortal(i.jsx("div",{className:"fixed inset-0 bg-black/40 flex items-center justify-center",style:{zIndex:n},onClick:t,children:i.jsxs("div",{className:"bg-surface-secondary border border-border-default rounded-xl shadow-2xl w-[90vw] max-w-3xl max-h-[85vh] flex flex-col overflow-hidden",onClick:Y=>Y.stopPropagation(),children:[i.jsxs("div",{className:"flex items-center justify-between px-4 py-3 border-b border-border-default bg-surface-elevated/50 shrink-0",children:[i.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[g==="directory"&&i.jsx("svg",{className:"w-4 h-4 shrink-0 text-blue-400",viewBox:"0 0 20 20",fill:"currentColor",children:i.jsx("path",{d:"M3.5 3A1.5 1.5 0 002 4.5v11A1.5 1.5 0 003.5 17h13a1.5 1.5 0 001.5-1.5v-8A1.5 1.5 0 0016.5 6h-6.53a.5.5 0 01-.354-.146L8.706 4.854A1.5 1.5 0 007.586 4H3.5z"})}),g!=="directory"&&i.jsx("svg",{className:"w-4 h-4 shrink-0 text-fg-secondary",viewBox:"0 0 20 20",fill:"currentColor",children:i.jsx("path",{fillRule:"evenodd",d:"M4 4a2 2 0 012-2h4.586A2 2 0 0112 2.586L15.414 6A2 2 0 0116 7.414V16a2 2 0 01-2 2H6a2 2 0 01-2-2V4z",clipRule:"evenodd"})}),i.jsx("span",{className:"text-sm font-medium text-fg-primary truncate",children:O}),i.jsx("span",{className:"text-xs text-fg-tertiary truncate hidden sm:inline",children:a})]}),i.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[G&&i.jsx("button",{className:"text-xs text-fg-secondary hover:text-fg-primary px-2 py-1 rounded hover:bg-surface-elevated transition-colors",onClick:Q,title:"返回上级目录",children:"← 上级"}),i.jsx("button",{className:"text-xs text-fg-secondary hover:text-fg-primary px-2 py-1 rounded hover:bg-surface-elevated transition-colors",onClick:$,title:"复制路径",children:D?"✓ 已复制":"复制路径"}),i.jsx("button",{className:"text-xs text-fg-secondary hover:text-fg-primary px-2 py-1 rounded hover:bg-surface-elevated transition-colors",onClick:()=>Ae.files.reveal(a),title:"Reveal in file explorer",children:i.jsx("svg",{className:"w-4 h-4",viewBox:"0 0 20 20",fill:"currentColor",children:i.jsx("path",{d:"M4.5 17a2.5 2.5 0 01-2.5-2.5v-9A2.5 2.5 0 014.5 3h3.672a1.5 1.5 0 011.06.44L10.56 4.77a.5.5 0 00.354.147H15.5A2.5 2.5 0 0118 7.417v7.083A2.5 2.5 0 0115.5 17h-11z"})})}),i.jsx("button",{className:"text-fg-secondary hover:text-fg-primary p-1 rounded hover:bg-surface-elevated transition-colors",onClick:t,children:i.jsx("svg",{className:"w-4 h-4",viewBox:"0 0 20 20",fill:"currentColor",children:i.jsx("path",{fillRule:"evenodd",d:"M4.293 4.293a1 1 0 011.414 0L10 8.586l4.293-4.293a1 1 0 111.414 1.414L11.414 10l4.293 4.293a1 1 0 01-1.414 1.414L10 11.414l-4.293 4.293a1 1 0 01-1.414-1.414L8.586 10 4.293 5.707a1 1 0 010-1.414z",clipRule:"evenodd"})})})]})]}),i.jsxs("div",{className:"flex-1 overflow-y-auto p-5",children:[l&&i.jsx("div",{className:"flex items-center justify-center py-12",children:i.jsx("div",{className:"w-5 h-5 border-2 border-brand-500/30 border-t-brand-500 rounded-full animate-spin"})}),d&&i.jsxs("div",{className:"text-center py-12 text-fg-secondary text-sm",children:[i.jsx("p",{className:"text-red-400 mb-1",children:"Failed to load file"}),i.jsx("p",{className:"text-xs text-fg-tertiary",children:d})]}),!l&&!d&&g==="directory"&&_&&i.jsx(yne,{path:a,entries:_,onNavigate:Y=>s(Y),onOpenFile:Y=>s(Y),onReveal:Y=>Ae.files.reveal(Y),onCopyPath:Y=>{navigator.clipboard?.writeText(Y).then(()=>{M(!0),setTimeout(()=>M(!1),1500)}).catch(()=>{})}}),!l&&!d&&g==="office"&&S&&i.jsx(vne,{data:{format:(a.split(".").pop()||"pdf").toLowerCase(),streamUrl:S,name:O},reference:a,onFallback:()=>{Ae.files.reveal(a)}}),!l&&!d&&g==="image"&&p&&i.jsx("div",{className:"flex justify-center",children:i.jsx("img",{src:`data:${T||"image/png"};base64,${p}`,alt:O,className:"max-w-full rounded"})}),!l&&!d&&g==="audio"&&S&&i.jsx("audio",{controls:!0,preload:"metadata",src:S,className:"w-full"}),!l&&!d&&g==="video"&&S&&i.jsx("video",{controls:!0,preload:"metadata",src:S,className:"w-full max-h-[60vh] rounded-lg bg-black"}),!l&&!d&&(g==="binary"||!p&&g!=="image"&&g!=="audio"&&g!=="video"&&g!=="directory")&&i.jsxs("div",{className:"text-center py-8 space-y-3",children:[i.jsx("p",{className:"text-sm text-fg-secondary",children:"This file type cannot be previewed."}),i.jsx("button",{className:"px-3 py-2 text-xs rounded-lg bg-brand-600/20 text-brand-500 hover:bg-brand-600/30 transition-colors",onClick:()=>{Ae.files.reveal(a)},children:"Reveal in file explorer"})]}),!l&&!d&&p&&g!=="image"&&g!=="audio"&&g!=="video"&&g!=="binary"&&g!=="directory"&&i.jsx(k.Suspense,{fallback:i.jsx("div",{className:"text-xs text-fg-tertiary",children:"Loading…"}),children:i.jsx(Ene,{content:p,format:g==="text"?"text":g,className:"text-sm"})})]})]})}),document.body)}function Pne({path:e}){const t=Lne(e),[n,a]=k.useState(null),s=qc(),l=t?.exists??!1,c=t?.type==="markdown"||t?.type==="html"||t?.type==="json"||t?.type==="text"||t?.type==="image"||t?.type==="audio"||t?.type==="video"||t?.type==="office"||t?.type==="directory",d=k.useCallback(h=>{if(h.preventDefault(),h.stopPropagation(),!!l)if(c){if(s?.hostAvailable){s.openRightPanel({kind:"file",path:e});return}a(e)}else Ae.files.reveal(e)},[l,c,e,s]),m="inline w-3 h-3 align-[-0.125em]",p=c?i.jsx("svg",{className:m,viewBox:"0 0 20 20",fill:"currentColor",children:i.jsx("path",{fillRule:"evenodd",d:"M4 4a2 2 0 012-2h4.586A2 2 0 0112 2.586L15.414 6A2 2 0 0116 7.414V16a2 2 0 01-2 2H6a2 2 0 01-2-2V4zm2 6a1 1 0 011-1h6a1 1 0 110 2H7a1 1 0 01-1-1zm1 3a1 1 0 100 2h6a1 1 0 100-2H7z",clipRule:"evenodd"})}):i.jsx("svg",{className:m,viewBox:"0 0 20 20",fill:"currentColor",children:i.jsx("path",{fillRule:"evenodd",d:"M4 4a2 2 0 012-2h4.586A2 2 0 0112 2.586L15.414 6A2 2 0 0116 7.414V16a2 2 0 01-2 2H6a2 2 0 01-2-2V4z",clipRule:"evenodd"})});return t?l?i.jsxs(i.Fragment,{children:[i.jsxs("code",{"data-file-path-link":"ready",className:"bg-brand-500/10 px-1.5 py-0.5 rounded text-xs font-mono text-brand-500 cursor-pointer hover:bg-brand-500/20 transition-colors border border-brand-500/20 hover:border-brand-500/40 break-all",onClick:d,title:c?"Click to preview":"Click to reveal in file explorer",role:"button",tabIndex:0,children:[i.jsxs("span",{className:"whitespace-nowrap",children:[p,e.charAt(0)]}),e.slice(1)]}),n&&i.jsx(One,{filePath:n,onClose:()=>a(null)})]}):i.jsx("code",{"data-file-path-link":"missing",className:"bg-surface-secondary/50 px-1.5 py-0.5 rounded text-xs font-mono text-fg-tertiary border border-border-default/30 line-through decoration-fg-tertiary/30 break-all",title:"File not found",children:e}):i.jsx("code",{"data-file-path-link":"loading",className:"bg-surface-secondary px-1.5 py-0.5 rounded text-xs font-mono text-fg-secondary break-all",children:e})}let uh=null;function zne(){return uh||(uh=va(()=>import("./mermaid.core-DbFRJGs8.js").then(e=>e.b9),__vite__mapDeps([0,1])).then(e=>(e.default.initialize({startOnLoad:!1,securityLevel:"loose",fontFamily:"inherit"}),e))),uh}function Bne(){const e=document.documentElement;return e.classList.contains("light")?!1:e.classList.contains("dark")||e.classList.contains("cyberpunk")||e.classList.contains("mono")?!0:!window.matchMedia("(prefers-color-scheme: light)").matches}function Hne(e){const t=window.matchMedia("(prefers-color-scheme: dark)");t.addEventListener("change",e);const n=new MutationObserver(e);return n.observe(document.documentElement,{attributes:!0,attributeFilter:["class"]}),()=>{t.removeEventListener("change",e),n.disconnect()}}function $ne(){return Bne()}function qne(){return k.useSyncExternalStore(Hne,$ne)}function RS({code:e}){const{t}=ot("common"),n=k.useRef(null),[a,s]=k.useState(null),[l,c]=k.useState(!0),d=k.useId(),m=k.useRef(0),p=k.useRef(null),h=qne();return k.useEffect(()=>{if(!e.trim()||p.current&&p.current.code===e&&p.current.dark===h)return;let g=!1;return c(!0),s(null),m.current+=1,(async()=>{try{const x=await zne();if(g)return;x.default.initialize({startOnLoad:!1,theme:h?"dark":"default",securityLevel:"loose",fontFamily:"inherit"});const y=`mermaid-${d.replace(/:/g,"")}-${m.current}`,{svg:w}=await x.default.render(y,e.trim());if(g)return;n.current&&(n.current.innerHTML=w,p.current={code:e,dark:h})}catch(x){g||s(x instanceof Error?x.message:String(x))}finally{g||c(!1)}})(),()=>{g=!0}},[e,d,h]),a?i.jsxs("div",{className:"my-2 rounded-lg overflow-hidden border border-red-500/30",children:[i.jsxs("div",{className:"flex items-center gap-1.5 px-3 py-1.5 bg-red-500/10 border-b border-red-500/20",children:[i.jsx("svg",{className:"w-3.5 h-3.5 text-red-400",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:i.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-2.5L13.732 4c-.77-.833-1.964-.833-2.732 0L4.082 16.5c-.77.833.192 2.5 1.732 2.5z"})}),i.jsx("span",{className:"text-[10px] font-medium text-red-400",children:t("markdown.mermaidRenderError")})]}),a&&i.jsx("div",{className:"px-3 py-2 bg-surface-secondary/60 text-[11px] font-mono text-red-300/90 whitespace-pre-wrap break-words border-b border-red-500/10 max-h-40 overflow-y-auto",children:a}),i.jsx("pre",{className:"p-3 bg-surface-secondary text-xs text-fg-secondary overflow-x-auto font-mono",children:e})]}):i.jsxs("div",{className:"not-prose my-2 rounded-lg bg-surface-secondary border border-border-subtle p-4 overflow-x-auto",children:[l&&i.jsxs("div",{className:"flex items-center gap-2 text-xs text-fg-tertiary",children:[i.jsx("div",{className:"w-4 h-4 border-2 border-fg-tertiary/30 border-t-fg-tertiary rounded-full animate-spin"}),t("markdown.renderingDiagram")]}),i.jsx("div",{ref:n,className:`flex justify-center [&>svg]:max-w-full${l?" hidden":""}`})]})}const Fne="/assets/viz-global-C_AyN6D9.js";let Rd=!1,dh=null;function Une(){return Rd?Promise.resolve():new Promise((e,t)=>{const n=document.querySelector("script[data-plantuml-viz]");if(n){globalThis.Viz?(Rd=!0,e()):(n.addEventListener("load",()=>{Rd=!0,e()}),n.addEventListener("error",()=>t(new Error("Failed to load viz-global.js"))));return}const a=document.createElement("script");a.setAttribute("data-plantuml-viz",""),a.src=Fne,a.onload=()=>{Rd=!0,e()},a.onerror=()=>t(new Error("Failed to load viz-global.js")),document.head.appendChild(a)})}function Gne(){return dh||(dh=Une().then(()=>va(()=>import("./plantuml-DezRDxd4.js"),[]))),dh}let $w=Promise.resolve();function Kne(e,t){const n=$w.then(()=>new Promise((a,s)=>{Gne().then(({renderToString:l})=>{const c=e.split(/\r\n|\r|\n/);l(c,a,s,{dark:t})}).catch(s)}));return $w=n.then(()=>{},()=>{}),n}function Vne(){const e=document.documentElement;return e.classList.contains("light")?!1:e.classList.contains("dark")||e.classList.contains("cyberpunk")||e.classList.contains("mono")?!0:!window.matchMedia("(prefers-color-scheme: light)").matches}function Wne(e){const t=window.matchMedia("(prefers-color-scheme: dark)");t.addEventListener("change",e);const n=new MutationObserver(e);return n.observe(document.documentElement,{attributes:!0,attributeFilter:["class"]}),()=>{t.removeEventListener("change",e),n.disconnect()}}function Yne(){return k.useSyncExternalStore(Wne,()=>Vne())}function DS({code:e}){const{t}=ot("common"),[n,a]=k.useState(null),[s,l]=k.useState(null),[c,d]=k.useState(!0),m=k.useRef(null),p=Yne();return k.useEffect(()=>{if(!e.trim()||m.current&&m.current.code===e&&m.current.dark===p)return;let h=!1;return d(!0),l(null),Kne(e.trim(),p).then(g=>{h||(a(g),m.current={code:e,dark:p})}).catch(g=>{h||l(g instanceof Error?g.message:String(g))}).finally(()=>{h||d(!1)}),()=>{h=!0}},[e,p]),s?i.jsxs("div",{className:"my-2 rounded-lg overflow-hidden border border-red-500/30",children:[i.jsxs("div",{className:"flex items-center gap-1.5 px-3 py-1.5 bg-red-500/10 border-b border-red-500/20",children:[i.jsx("svg",{className:"w-3.5 h-3.5 text-red-400",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:i.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-2.5L13.732 4c-.77-.833-1.964-.833-2.732 0L4.082 16.5c-.77.833.192 2.5 1.732 2.5z"})}),i.jsx("span",{className:"text-[10px] font-medium text-red-400",children:t("markdown.plantumlRenderError")})]}),s&&i.jsx("div",{className:"px-3 py-2 bg-surface-secondary/60 text-[11px] font-mono text-red-300/90 whitespace-pre-wrap break-words border-b border-red-500/10 max-h-40 overflow-y-auto",children:s}),i.jsx("pre",{className:"p-3 bg-surface-secondary text-xs text-fg-secondary overflow-x-auto font-mono",children:e})]}):i.jsxs("div",{className:"not-prose my-2 rounded-lg bg-surface-secondary border border-border-subtle p-4 overflow-x-auto",children:[c&&i.jsxs("div",{className:"flex items-center gap-2 text-xs text-fg-tertiary",children:[i.jsx("div",{className:"w-4 h-4 border-2 border-fg-tertiary/30 border-t-fg-tertiary rounded-full animate-spin"}),t("markdown.renderingDiagram")]}),n&&i.jsx("div",{className:`flex justify-center [&>svg]:max-w-full${c?" hidden":""}`,dangerouslySetInnerHTML:{__html:n}})]})}function dg({code:e,language:t,children:n}){const{t:a}=ot("common"),[s,l]=k.useState("rendered"),[c,d]=k.useState(!1),m=k.useCallback(async()=>{await hb(e)&&(d(!0),setTimeout(()=>d(!1),1800))},[e]);return i.jsxs("div",{className:"not-prose my-2 rounded-lg overflow-hidden border border-border-subtle",children:[i.jsxs("div",{className:"flex items-center justify-between px-3 py-1.5 border-b border-border-subtle bg-surface-secondary",children:[i.jsx("span",{className:"text-[10px] font-medium text-fg-tertiary uppercase tracking-wider select-none",children:t}),i.jsxs("div",{className:"flex items-center gap-1",children:[i.jsx("button",{onClick:()=>l("rendered"),className:`px-2 py-0.5 rounded text-[10px] font-medium transition-colors ${s==="rendered"?"bg-brand-600/20 text-brand-500":"text-fg-tertiary hover:text-fg-secondary"}`,children:i.jsxs("span",{className:"flex items-center gap-1",children:[i.jsxs("svg",{className:"w-3 h-3",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:[i.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M15 12a3 3 0 11-6 0 3 3 0 016 0z"}),i.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M2.458 12C3.732 7.943 7.523 5 12 5c4.478 0 8.268 2.943 9.542 7-1.274 4.057-5.064 7-9.542 7-4.477 0-8.268-2.943-9.542-7z"})]}),a("markdown.viewRendered")]})}),i.jsx("button",{onClick:()=>l("source"),className:`px-2 py-0.5 rounded text-[10px] font-medium transition-colors ${s==="source"?"bg-brand-600/20 text-brand-500":"text-fg-tertiary hover:text-fg-secondary"}`,children:i.jsxs("span",{className:"flex items-center gap-1",children:[i.jsx("svg",{className:"w-3 h-3",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:i.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M10 20l4-16m4 4l4 4-4 4M6 16l-4-4 4-4"})}),a("markdown.viewSource")]})})]})]}),s==="rendered"?i.jsx("div",{children:n}):i.jsxs("div",{className:"relative group/source",children:[i.jsx("pre",{className:"p-3 overflow-x-auto text-xs font-mono text-fg-secondary bg-surface-secondary leading-relaxed whitespace-pre-wrap break-words",children:e}),i.jsx("button",{onClick:m,className:"absolute top-2 right-2 p-1.5 rounded-md bg-surface-elevated/80 hover:bg-surface-overlay text-fg-tertiary hover:text-fg-primary backdrop-blur-sm border border-border-default/50 transition-all opacity-0 group-hover/source:opacity-100",title:a("markdown.copyContent"),children:c?i.jsx("svg",{className:"w-3.5 h-3.5 text-green-400",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:i.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M5 13l4 4L19 7"})}):i.jsx("svg",{className:"w-3.5 h-3.5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:i.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"})})})]})]})}const Qne=[RS,DS];function Xne(e){for(const t of k.Children.toArray(e))if(k.isValidElement(t)&&typeof t.props?.className=="string"){const n=t.props.className;return Kte(n)}return null}function bc(e){if(typeof e=="string")return e;if(typeof e=="number")return String(e);if(!e)return"";if(Array.isArray(e))return e.map(bc).join("");if(k.isValidElement(e)){const t=e.props;return bc(t.children)}return""}function Jne({children:e}){const{t}=ot("common"),n=Xne(e),a=k.useRef(null),[s,l]=k.useState(!1),[c,d]=k.useState("rendered"),m=k.useCallback(async()=>{let h;c==="source"?h=bc(e):h=a.current?.querySelector("code")?.textContent??"";try{await navigator.clipboard.writeText(h),l(!0),setTimeout(()=>l(!1),1800)}catch{}},[c,e]);if(k.Children.toArray(e).some(h=>k.isValidElement(h)&&Qne.includes(h.type))){const h=bc(e),g=n==="mermaid"||n==="plantuml"?n:"diagram";return i.jsx(dg,{code:h,language:g,children:e})}return n==="mermaid"||n==="plantuml"?i.jsx(i.Fragment,{children:e}):i.jsxs("div",{className:"not-prose relative group/code my-2 rounded-lg overflow-hidden bg-surface-secondary border border-border-subtle",children:[n&&i.jsxs("div",{className:"flex items-center justify-between px-3 py-1.5 border-b border-border-subtle",children:[i.jsx("span",{className:"text-[10px] font-medium text-fg-tertiary uppercase tracking-wider select-none",children:Gte(n)}),i.jsxs("div",{className:"flex items-center gap-1",children:[i.jsx("button",{onClick:()=>d("rendered"),className:`px-1.5 py-0.5 rounded text-[10px] font-medium transition-colors ${c==="rendered"?"bg-brand-600/20 text-brand-500":"text-fg-tertiary hover:text-fg-secondary"}`,children:t("markdown.viewRendered")}),i.jsx("button",{onClick:()=>d("source"),className:`px-1.5 py-0.5 rounded text-[10px] font-medium transition-colors ${c==="source"?"bg-brand-600/20 text-brand-500":"text-fg-tertiary hover:text-fg-secondary"}`,children:t("markdown.viewSource")})]})]}),i.jsxs("div",{className:"relative",children:[c==="rendered"?i.jsx("pre",{ref:a,className:"p-3 overflow-x-auto text-xs [&>code]:p-0 [&>code]:rounded-none [&>code]:text-fg-secondary",children:k.Children.map(e,h=>k.isValidElement(h)?k.cloneElement(h,{style:{background:"transparent",padding:0}}):h)}):i.jsx("pre",{className:"p-3 overflow-x-auto text-xs font-mono text-fg-secondary whitespace-pre-wrap break-words",children:bc(e)}),i.jsx("button",{onClick:m,className:"absolute top-2 right-2 p-1.5 rounded-md bg-surface-elevated/80 hover:bg-surface-overlay text-fg-tertiary hover:text-fg-primary backdrop-blur-sm border border-border-default/50 transition-all opacity-0 group-hover/code:opacity-100",title:t("markdown.copyContent"),children:s?i.jsx("svg",{className:"w-3.5 h-3.5 text-green-400",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:i.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M5 13l4 4L19 7"})}):i.jsx("svg",{className:"w-3.5 h-3.5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:i.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"})})})]})]})}const qw="#mention:",Mm="#entity:",Zne=/^\[([^\]]+)\]\(#entity:((tsk|req|proj|dlv|agt|team)_[a-f0-9]{6,})\)$/i,LS=/^(workflow|task|requirement|project|deliverable|agent|team):(.+)$/,mg="text-brand-500 hover:text-brand-500 underline break-all cursor-pointer";function pg(e){return e.type==="text"?e.value??"":(e.children??[]).map(pg).join("")}function eae(e){return e.type==="text"&&(e.value??"").trim()===""}function tae(e){if(!e?.children)return null;const t=e.children.filter(a=>!eae(a));if(t.length!==1)return null;const n=t[0];if(n.type==="element"&&n.tagName==="a"){const a=n.properties?.href;if(!a)return null;const s=pg(n);if(a.startsWith(Mm))return{id:a.slice(Mm.length)};const l=a.match(LS);return l&&l[1]!=="workflow"?{id:l[2],type:TS(l[1]),label:s}:null}if(n.type==="element"&&n.tagName==="code"){const a=pg(n).trim();if(Em(a))return{id:a}}if(n.type==="text"){const a=(n.value??"").trim();if(Em(a))return{id:a}}return null}const nae={p:({children:e})=>i.jsx("p",{className:"mb-2 last:mb-0 leading-relaxed text-fg-secondary",children:e}),h1:({children:e})=>i.jsx("h1",{className:"text-base font-bold mb-2 mt-3 first:mt-0 text-fg-primary",children:e}),h2:({children:e})=>i.jsx("h2",{className:"text-sm font-bold mb-2 mt-3 first:mt-0 text-fg-primary",children:e}),h3:({children:e})=>i.jsx("h3",{className:"text-sm font-semibold mb-1 mt-2 first:mt-0 text-fg-primary",children:e}),h4:({children:e})=>i.jsx("h4",{className:"text-sm font-semibold mb-1 mt-2 first:mt-0 text-fg-primary",children:e}),h5:({children:e})=>i.jsx("h5",{className:"text-xs font-semibold mb-1 mt-2 first:mt-0 text-fg-primary",children:e}),h6:({children:e})=>i.jsx("h6",{className:"text-xs font-medium mb-1 mt-2 first:mt-0 text-fg-primary",children:e}),ul:({children:e})=>i.jsx("ul",{className:"list-disc pl-4 mb-2 space-y-0.5",children:e}),ol:({children:e,start:t})=>i.jsx("ol",{start:t,className:"list-decimal pl-7 mb-2 space-y-0.5",children:e}),li:({children:e,value:t})=>i.jsx("li",{value:t,className:"leading-relaxed text-fg-secondary marker:text-fg-secondary",children:e}),code:({children:e,className:t})=>{const n=typeof e=="string"?e:String(e??""),a=n.trim();if(t?.includes("language-plantuml")||Fte(a))return i.jsx(dg,{code:a,language:"plantuml",children:i.jsx(DS,{code:a})});if(t?.includes("language-mermaid"))return i.jsx(dg,{code:a,language:"mermaid",children:i.jsx(RS,{code:a})});if(t?.includes("language-"))return i.jsx("code",{className:`${t} text-fg-secondary font-mono text-xs`,children:e});if(Em(n))return i.jsx(gc,{id:n.trim()});const s=n.match(Zne);return s?i.jsx(gc,{id:s[2],label:s[1]}):Xte(n)?i.jsx(Pne,{path:n}):i.jsx("code",{className:"bg-surface-secondary px-1.5 py-0.5 rounded text-xs font-mono text-brand-500 break-all",children:e})},pre:({children:e})=>i.jsx(Jne,{children:e}),strong:({children:e})=>i.jsx("strong",{className:"font-bold text-fg-primary",children:e}),em:({children:e})=>i.jsx("em",{className:"italic text-fg-secondary",children:e}),del:({children:e})=>i.jsx("del",{className:"line-through text-fg-tertiary",children:e}),blockquote:({children:e})=>i.jsx("blockquote",{className:"border-l-2 border-brand-500 pl-3 my-2 text-fg-secondary italic",children:e}),a:({href:e,children:t})=>i.jsx("a",{href:e,className:mg,children:t}),hr:()=>i.jsx("hr",{className:"border-border-default my-3"}),table:({children:e})=>i.jsx("div",{className:"overflow-x-auto my-2",children:i.jsx("table",{className:"min-w-full text-sm border-collapse border border-border-default",children:e})}),thead:({children:e})=>i.jsx("thead",{className:"bg-surface-secondary",children:e}),tbody:({children:e})=>i.jsx("tbody",{className:"divide-y divide-border-default",children:e}),tr:({children:e})=>i.jsx("tr",{className:"hover:bg-surface-elevated/50 transition-colors",children:e}),th:({children:e})=>i.jsx("th",{className:"px-3 py-2 text-left text-sm font-semibold text-fg-primary border border-border-default",children:e}),td:({children:e})=>i.jsx("td",{className:"px-3 py-2 text-sm text-fg-primary border border-border-default",children:e})},aae=/\.(png|jpe?g|gif|webp|svg|bmp|ico)$/i;function rae(e){const t=fb(e);return vS(e)&&aae.test(t.split("?")[0]??t)}function iae(e,t){const n=fb(e);if(n.startsWith("/")||n.startsWith("~/")||/^[A-Za-z]:\//.test(n)||n.startsWith("//"))return n;if((n.startsWith("./")||n.startsWith("../"))&&t){const s=((t.replace(/\\/g,"/").endsWith("/")?t.replace(/\\/g,"/"):`${t.replace(/\\/g,"/")}/`)+n).split("/"),l=[];for(const c of s)c===".."?l.pop():c!=="."&&c!==""&&l.push(c);return"/"+l.join("/")}return n}function sae(e){return`/api/files/image?path=${encodeURIComponent(e)}`}function oae(e,t){return rae(e)?sae(iae(e,t)):null}const Lo=new Map,sc=new Map,lae=k.memo(function({src:t,alt:n,onPreview:a,basePath:s}){const l=k.useMemo(()=>oae(t,s)??t,[t,s]),c=l.startsWith("/api/files/image?"),d=Lo.get(l),m=sc.get(l),[p,h]=k.useState(d??(c?null:l)),[g,x]=k.useState(!!d),[y,w]=k.useState(!!m),[T,C]=k.useState(m??null),[S,E]=k.useState(0),_=k.useRef(0),L=k.useCallback(M=>{sc.set(l,M),C(M),w(!0),x(!1)},[l]),D=k.useCallback(()=>{Lo.delete(l),sc.delete(l),w(!1),C(null),x(!1),h(c?null:`${l}${l.includes("?")?"&":"?"}retry=${Date.now()}`),E(M=>M+1)},[l,c]);return k.useEffect(()=>{if(!c)return;const M=Lo.get(l);if(M){h(M),x(!0),w(!1),C(null);return}const O=sc.get(l);if(O!==void 0){w(!0),C(O),x(!1);return}const G=++_.current;w(!1),C(null),x(!1),h(null),(async()=>{try{const Q=await fetch(l,{credentials:"same-origin"});if(G!==_.current)return;if(!Q.ok){let K=`HTTP ${Q.status}`;try{const ee=await Q.json();ee.error&&(K=ee.error)}catch{}throw new Error(K)}const $=await Q.blob();if(G!==_.current)return;if($.size===0)throw new Error("Empty image response");if($.type&&!$.type.startsWith("image/")&&!$.type.includes("octet-stream"))throw new Error(`Unexpected content-type: ${$.type}`);const Y=URL.createObjectURL($);Lo.set(l,Y),h(Y),x(!0),w(!1),C(null)}catch(Q){if(G!==_.current)return;const $=Q instanceof Error?Q.message:String(Q);console.warn("[MarkdownImage] failed to load local image",l,Q),L($)}})()},[c,l,S]),k.useEffect(()=>{if(c)return;const M=sc.get(l);if(M!==void 0){w(!0),C(M),x(!1);return}h(l),x(!!Lo.get(l)),w(!1),C(null)},[l,c,S]),y?i.jsxs("button",{type:"button",onClick:D,title:T??"Click to retry",className:"inline-flex items-center gap-1.5 px-3 py-2 text-xs text-fg-tertiary bg-surface-elevated rounded-lg border border-border-default hover:bg-surface-overlay hover:text-fg-secondary cursor-pointer transition-colors max-w-full",children:[i.jsxs("svg",{className:"w-4 h-4 shrink-0",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:1.5,children:[i.jsx("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2",ry:"2"}),i.jsx("circle",{cx:"8.5",cy:"8.5",r:"1.5"}),i.jsx("polyline",{points:"21 15 16 10 5 21"})]}),i.jsxs("span",{className:"truncate",children:["Failed to load image — click to retry",T?` (${T})`:""]})]}):i.jsxs("span",{className:"inline-block align-middle max-w-full",children:[!g&&i.jsx("span",{className:"block w-full min-h-[80px] max-w-[400px] bg-surface-elevated rounded-lg animate-pulse"}),p?i.jsx("img",{src:p,alt:n??"",onLoad:()=>{c||Lo.set(l,l),x(!0)},onError:()=>{L("Image decode failed")},onClick:()=>a?.(p),className:`max-w-full h-auto rounded-lg cursor-pointer hover:opacity-90 transition-opacity my-1${g?"":" absolute opacity-0 pointer-events-none"}`,style:{maxHeight:"400px",objectFit:"contain"}}):null]})});async function Fw(e){const t=await fetch(e);if(!t.ok)throw new Error(`Failed to fetch image (${t.status})`);return t.blob()}async function cae(e){if(e.type==="image/png")return e;const t=await createImageBitmap(e),n=document.createElement("canvas");n.width=t.width,n.height=t.height;const a=n.getContext("2d");if(!a)throw new Error("Canvas unavailable");return a.drawImage(t,0,0),t.close(),new Promise((s,l)=>{n.toBlob(c=>c?s(c):l(new Error("PNG encode failed")),"image/png")})}function uae(e,t){try{const s=(e.startsWith("data:")?"":new URL(e,window.location.href).pathname).split("/").pop()||"";if(s&&/\.(png|jpe?g|gif|webp|svg|bmp)$/i.test(s))return decodeURIComponent(s)}catch{}return`image.${(t.type.split("/")[1]||"png").replace("jpeg","jpg")}`}function IS({src:e,onClose:t}){const{t:n}=ot("common"),[a,s]=k.useState(null),[l,c]=k.useState(null);Qo(!0),k.useEffect(()=>{const g=x=>{x.key==="Escape"&&t()};return document.addEventListener("keydown",g),()=>document.removeEventListener("keydown",g)},[t]);const d=k.useCallback(g=>{s(g),window.setTimeout(()=>s(null),1600)},[]),m=k.useCallback(async g=>{if(g.stopPropagation(),!l){c("copy");try{const x=await Fw(e),y=await cae(x);await navigator.clipboard.write([new ClipboardItem({"image/png":y})]),d(n("imageCopied"))}catch{d(n("imageCopyFailed"))}finally{c(null)}}},[l,d,e,n]),p=k.useCallback(async g=>{if(g.stopPropagation(),!l){c("download");try{const x=await Fw(e),y=URL.createObjectURL(x),w=document.createElement("a");w.href=y,w.download=uae(e,x),document.body.appendChild(w),w.click(),w.remove(),URL.revokeObjectURL(y),d(n("imageDownloaded"))}catch{d(n("imageDownloadFailed"))}finally{c(null)}}},[l,d,e,n]),h="inline-flex items-center gap-1.5 px-3 py-1.5 rounded-lg bg-white/10 hover:bg-white/20 text-white text-sm transition-colors disabled:opacity-50";return zr.createPortal(i.jsxs("div",{className:"fixed inset-0 z-[9999] bg-black/80 flex items-center justify-center p-4",onClick:t,children:[i.jsxs("div",{className:"absolute top-4 right-4 z-10 flex items-center gap-2",onClick:g=>g.stopPropagation(),children:[i.jsxs("button",{type:"button",className:h,onClick:m,disabled:!!l,title:n("copyImage"),children:[i.jsxs("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[i.jsx("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2"}),i.jsx("path",{d:"M5 15H4a2 2 0 01-2-2V4a2 2 0 012-2h9a2 2 0 012 2v1"})]}),n("copy")]}),i.jsxs("button",{type:"button",className:h,onClick:p,disabled:!!l,title:n("downloadImage"),children:[i.jsxs("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[i.jsx("path",{d:"M21 15v4a2 2 0 01-2 2H5a2 2 0 01-2-2v-4"}),i.jsx("polyline",{points:"7 10 12 15 17 10"}),i.jsx("line",{x1:"12",y1:"15",x2:"12",y2:"3"})]}),n("downloadImage")]}),i.jsx("button",{type:"button",onClick:t,className:"w-10 h-10 rounded-full bg-white/10 hover:bg-white/20 flex items-center justify-center transition-colors",title:n("close"),children:i.jsxs("svg",{className:"w-6 h-6 text-white",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,children:[i.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),i.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]}),a&&i.jsx("div",{className:"absolute top-16 left-1/2 -translate-x-1/2 z-10 px-3 py-1.5 rounded-lg bg-black/70 text-white text-xs",children:a}),i.jsx("img",{src:e,alt:"Preview",className:"max-w-full max-h-[90vh] object-contain rounded-lg",onClick:g=>g.stopPropagation()})]}),document.body)}function OS(e={}){const{onMentionClick:t,basePath:n,onImagePreview:a,contentRef:s,hostAvailable:l,openRightPanel:c}=e,d=k.useCallback((m,p)=>{const h=Rw(p,n);if(h.kind!=="passthrough"){if(m.preventDefault(),m.stopPropagation(),h.kind==="fragment"){Jte(s?.current??null,h.id);return}if(h.kind==="file"){l&&c?c({kind:"file",path:h.path,title:h.path.split(/[/\\]/).pop()}):Ae.files.reveal(h.path).catch(()=>{});return}if(h.kind==="external"){if(l&&c&&/^https?:\/\//i.test(h.url)){c({kind:"url",url:h.url,title:h.url});return}fi(h.url)}}},[n,s,l,c]);return k.useMemo(()=>({...nae,img:({src:m,alt:p})=>i.jsx(lae,{src:m??"",alt:p,onPreview:a,basePath:n},m??""),p:({children:m,node:p})=>{const h=tae(p);return h?i.jsx(pne,{id:h.id,type:h.type,label:h.label}):i.jsx("p",{className:"mb-2 last:mb-0 leading-relaxed text-fg-secondary",children:m})},a:({href:m,children:p})=>{if(m?.startsWith(qw)){const g=decodeURIComponent(m.slice(qw.length));return i.jsx("span",{className:`text-brand-500 font-medium${t?" cursor-pointer hover:underline":""}`,onClick:t?x=>{x.preventDefault(),x.stopPropagation(),t(g,x)}:void 0,title:g,children:p})}if(m?.startsWith(Mm))return i.jsx(gc,{id:m.slice(Mm.length)});{const g=m?.match(LS);if(g){const[,x,y]=g;if(x==="workflow")return i.jsxs("span",{className:"inline-flex items-center gap-0.5 px-1 py-0.5 rounded bg-brand-500/10 text-brand-500 text-xs font-medium cursor-pointer hover:bg-brand-500/20 transition-colors",onClick:T=>{T.preventDefault(),T.stopPropagation(),at.navigate(de.WORK,{boardType:"workflows"})},title:`workflow: ${y}`,children:[i.jsx("span",{className:"text-[10px]",children:"⚙️"}),i.jsx("span",{children:p})]});const w=TS(x);if(w)return i.jsx(gc,{id:y,type:w,label:p})}}if(m&&Em(m))return i.jsx(gc,{id:m.trim(),label:p});const h=Rw(m,n);return h.kind==="fragment"||h.kind==="file"||h.kind==="external"?i.jsx("a",{href:m,className:mg,onClick:g=>d(g,m),title:h.kind==="fragment"?`#${h.id}`:h.kind==="file"?h.path:h.url,children:p}):i.jsx("a",{href:m,className:mg,onClick:g=>{Go()&&m&&!/^[a-zA-Z][a-zA-Z0-9+.-]*:/.test(m)&&g.preventDefault()},children:p})}}),[t,n,a,d])}const Uw=[D5,I3,O3],Gw=[SS,[G3,{strict:"ignore"}],[cS,{detect:!0,ignoreMissing:!0}]];function fg(e){if(/^(deliverable|task|requirement|project|agent|team|workflow):/i.test(e))return e;const n=pb(e);return vS(n)?n:o5(e)}const dae=/(?:<thinking>| thinking)([\s\S]*?)<\/thinking>/g;function mae(e){const t=[];let n=e.replace(dae,(a,s)=>{const l=s.trim();return l&&t.push(l),""});return n=n.replace(/<thinking>/gi,"").replace(/<\/thinking>/gi,""),{thinking:t,rest:n.trim()}}function pae(e=640){const[t,n]=k.useState(()=>window.innerWidth<e);return k.useEffect(()=>{const a=window.matchMedia(`(max-width: ${e-1}px)`),s=l=>n(l.matches);return a.addEventListener("change",s),n(a.matches),()=>a.removeEventListener("change",s)},[e]),t}function fae({content:e,contentRef:t}){const{t:n}=ot("common"),[a,s]=k.useState(!1),[l,c]=k.useState(!1),[d,m]=k.useState(!1),[p,h]=k.useState(null),g=k.useRef(null),x=pae();k.useEffect(()=>{if(!a)return;const C=S=>{g.current&&!g.current.contains(S.target)&&(s(!1),c(!1),m(!1))};return document.addEventListener("mousedown",C),()=>document.removeEventListener("mousedown",C)},[a]);const y=k.useCallback(C=>{h(C),setTimeout(()=>h(null),1500)},[]),w=async()=>{const C=await hb(e);y(n(C?"markdown.copied":"markdown.failed")),s(!1)},T=async C=>{const S=t.current?.firstElementChild;if(!S)return;const E=AS(),_=nne(E),L=await ene(S,C,e,{fontFamily:_.fontFamily,fontSize:_.fontSize,headingScales:_.headingScales}),D=n(C==="light"?"markdown.themeLight":"markdown.themeDark");y(L.ok?L.method==="html"?n("markdown.htmlCopied",{theme:D}):n("markdown.textCopied"):n("markdown.failed")),s(!1)};return i.jsxs("div",{className:"absolute top-1 right-1 z-10 opacity-0 group-hover/md:opacity-100 transition-opacity",ref:g,children:[p&&i.jsx("div",{className:"absolute right-0 top-full mt-1 z-20 px-2 py-0.5 rounded bg-surface-elevated border border-border-default text-[10px] text-fg-secondary whitespace-nowrap shadow-lg",children:p}),i.jsx("button",{onClick:()=>s(C=>!C),className:"p-1.5 rounded-lg bg-surface-elevated/80 hover:bg-surface-overlay text-fg-secondary hover:text-fg-primary backdrop-blur-sm border border-border-default/50 transition-all",title:n("markdown.copyContent"),children:i.jsx("svg",{className:"w-3.5 h-3.5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:i.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"})})}),a&&i.jsx("div",{className:"absolute right-0 top-full mt-1 bg-surface-elevated border border-border-default rounded-lg shadow-xl py-1 min-w-[180px]",children:d?i.jsx(ane,{onClose:()=>m(!1)}):l?i.jsxs("div",{className:"px-3 py-2 text-[11px] text-fg-secondary space-y-2 max-w-[260px]",children:[i.jsxs("div",{className:"flex items-center justify-between mb-1",children:[i.jsx("span",{className:"font-medium text-fg-primary text-xs",children:n("markdown.infoTitle")}),i.jsx("button",{onClick:()=>c(!1),className:"text-fg-tertiary hover:text-fg-primary p-0.5",children:i.jsx("svg",{className:"w-3 h-3",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:i.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M6 18L18 6M6 6l12 12"})})})]}),i.jsxs("div",{children:[i.jsx("span",{className:"font-medium text-fg-primary",children:n("markdown.mdAbbrev")})," — ",n("markdown.infoMdDesc")]}),i.jsxs("div",{children:[i.jsx("span",{className:"font-medium text-fg-primary",children:"☀️"})," — ",n("markdown.infoHtmlLightDesc")]}),i.jsxs("div",{children:[i.jsx("span",{className:"font-medium text-fg-primary",children:"🌙"})," — ",n("markdown.infoHtmlDarkDesc")]})]}):i.jsxs(i.Fragment,{children:[i.jsxs("div",{className:"flex items-center justify-between px-3 py-1 border-b border-border-subtle mb-1",children:[i.jsx("span",{className:"text-[10px] text-fg-tertiary font-medium",children:n("markdown.copyContent")}),i.jsxs("div",{className:"flex items-center gap-1",children:[i.jsx("button",{onClick:()=>m(!0),className:"p-0.5 rounded text-fg-tertiary hover:text-fg-primary transition-colors",title:n("markdown.typographySettings"),children:i.jsxs("svg",{className:"w-3.5 h-3.5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:[i.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M10.325 4.317c.426-1.756 2.924-1.756 3.35 0a1.724 1.724 0 002.573 1.066c1.543-.94 3.31.826 2.37 2.37a1.724 1.724 0 001.066 2.573c1.756.426 1.756 2.924 0 3.35a1.724 1.724 0 00-1.066 2.573c.94 1.543-.826 3.31-2.37 2.37a1.724 1.724 0 00-2.573 1.066c-.426 1.756-2.924 1.756-3.35 0a1.724 1.724 0 00-2.573-1.066c-1.543.94-3.31-.826-2.37-2.37a1.724 1.724 0 00-1.066-2.573c-1.756-.426-1.756-2.924 0-3.35a1.724 1.724 0 001.066-2.573c-.94-1.543.826-3.31 2.37-2.37.996.608 2.296.07 2.572-1.065z"}),i.jsx("circle",{cx:"12",cy:"12",r:"3"})]})}),i.jsx("button",{onClick:()=>c(!0),className:"p-0.5 rounded text-fg-tertiary hover:text-fg-primary transition-colors",title:n("markdown.infoTitle"),children:i.jsxs("svg",{className:"w-3.5 h-3.5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:[i.jsx("circle",{cx:"12",cy:"12",r:"10"}),i.jsx("path",{strokeLinecap:"round",d:"M12 16v-4m0-4h.01"})]})})]})]}),i.jsxs("button",{onClick:w,className:"w-full px-3 py-2 text-left text-xs text-fg-secondary hover:bg-surface-overlay hover:text-fg-primary transition-colors flex items-center gap-2",children:[i.jsx("span",{className:"w-4 text-center text-fg-tertiary shrink-0 font-mono text-[10px]",children:n("markdown.mdAbbrev")}),n(x?"markdown.copyMdSourceShort":"markdown.copyMdSource")]}),i.jsxs("button",{onClick:()=>T("light"),className:"w-full px-3 py-2 text-left text-xs text-fg-secondary hover:bg-surface-overlay hover:text-fg-primary transition-colors flex items-center gap-2",children:[i.jsx("span",{className:"w-4 text-center shrink-0 text-[10px]",children:"☀️"}),n(x?"markdown.copyHtmlLightShort":"markdown.copyHtmlLight")]}),i.jsxs("button",{onClick:()=>T("dark"),className:"w-full px-3 py-2 text-left text-xs text-fg-secondary hover:bg-surface-overlay hover:text-fg-primary transition-colors flex items-center gap-2",children:[i.jsx("span",{className:"w-4 text-center shrink-0 text-[10px]",children:"🌙"}),n(x?"markdown.copyHtmlDarkShort":"markdown.copyHtmlDark")]})]})})]})}const Ea=k.memo(function({content:t,className:n="",onMentionClick:a,knownNames:s,basePath:l}){const{thinking:c,rest:d}=mae(t),m=k.useRef(null),[p,h]=k.useState(null),g=qc(),x=k.useCallback(T=>{let C=ui(T,mS);return C=ui(C,Ite),C=ui(C,Yte),C=ui(C,Bte),C=ui(C,Hte),C=ui(C,S=>Ote(S,s)),C=ui(C,hS),C},[s]),y=k.useMemo(()=>x(d),[d,x]),w=OS({onMentionClick:a,basePath:l,onImagePreview:h,contentRef:m,hostAvailable:g?.hostAvailable,openRightPanel:g?.openRightPanel});return i.jsxs("div",{className:"relative group/md",children:[i.jsx(fae,{content:t,contentRef:m}),i.jsx("div",{ref:m,children:i.jsx(rne,{resetKeys:[y],fallback:i.jsx("div",{className:`prose prose-sm max-w-none break-words whitespace-pre-wrap pr-8 text-fg-secondary ${n}`,children:d}),children:i.jsxs("div",{className:`prose prose-sm max-w-none break-words pr-8 text-fg-secondary ${n}`,children:[c.length>0&&(()=>{const T=c.join(`
855
855
 
856
856
  `),C=T.split(`
857
- `)[0]??"",S=C.length>80?C.slice(0,80)+"…":C;return i.jsxs("details",{className:"mb-3 rounded-lg bg-surface-elevated/60 border border-border-default/50 overflow-hidden group/think",children:[i.jsxs("summary",{className:"cursor-pointer select-none px-3 py-2 text-xs text-fg-secondary hover:text-fg-secondary transition-colors flex items-center gap-1.5 min-w-0",children:[i.jsx("svg",{className:"w-3 h-3 shrink-0 transition-transform group-open/think:rotate-90",viewBox:"0 0 20 20",fill:"currentColor",children:i.jsx("path",{fillRule:"evenodd",d:"M7.21 14.77a.75.75 0 01.02-1.06L11.168 10 7.23 6.29a.75.75 0 111.04-1.08l4.5 4.25a.75.75 0 010 1.08l-4.5 4.25a.75.75 0 01-1.06-.02z",clipRule:"evenodd"})}),i.jsx("span",{className:"shrink-0",children:"Thinking"}),i.jsx("span",{className:"truncate text-fg-tertiary ml-1 group-open/think:hidden",children:S})]}),i.jsx("div",{className:"px-3 pb-3 border-t border-border-default/50",children:i.jsx("div",{className:"mt-2 pl-3 border-l-2 border-brand-500/40 text-xs text-fg-secondary leading-relaxed",children:i.jsx(qh,{remarkPlugins:Uw,rehypePlugins:Gw,components:w,urlTransform:fg,children:x(T)})})})]})})(),i.jsx(qh,{remarkPlugins:Uw,rehypePlugins:Gw,components:w,urlTransform:fg,children:y})]})})}),p&&i.jsx(IS,{src:p,onClose:()=>h(null)})]})},(e,t)=>e.content===t.content&&e.className===t.className&&e.basePath===t.basePath&&e.onMentionClick===t.onMentionClick&&hae(e.knownNames,t.knownNames));function hae(e,t){if(e===t)return!0;if(!e||!t||e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(e[n]!==t[n])return!1;return!0}const PS=Object.freeze(Object.defineProperty({__proto__:null,ImagePreviewModal:IS,MarkdownMessage:Ea,chatUrlTransform:fg},Symbol.toStringTag,{value:"Module"})),hg={suppressAdjustUntil:0};function Dc(e=2500){const t=typeof performance<"u"?performance.now():Date.now();hg.suppressAdjustUntil=Math.max(hg.suppressAdjustUntil,t+e)}function ase(){return(typeof performance<"u"?performance.now():Date.now())<hg.suppressAdjustUntil}const Kw={shell_execute:{label:"Running command",icon:"⌨"},list_terminals:{label:"Listing terminals",icon:"⌨"},new_terminal:{label:"Opening terminal",icon:"⌨"},select_terminal:{label:"Selecting terminal",icon:"⌨"},close_terminal:{label:"Closing terminal",icon:"⌨"},read_terminal:{label:"Reading terminal",icon:"⌨"},write_terminal:{label:"Writing terminal",icon:"⌨"},exec_terminal:{label:"Running in terminal",icon:"⌨"},file_read:{label:"Reading file",icon:"📄"},file_write:{label:"Writing file",icon:"✏"},file_edit:{label:"Editing file",icon:"✏"},apply_patch:{label:"Applying patch",icon:"🔀"},list_directory:{label:"Listing directory",icon:"📂"},glob_find:{label:"Finding files",icon:"🔍"},grep_search:{label:"Searching code",icon:"🔍"},web_fetch:{label:"Fetching page",icon:"🌐"},web_search:{label:"Searching web",icon:"🔍"},web_extract:{label:"Extracting content",icon:"📑"},create_task:{label:"Creating task",icon:"📌"},task_create:{label:"Creating task",icon:"📌"},create_subtask:{label:"Adding subtask",icon:"📌"},update_task:{label:"Updating task",icon:"✅"},task_update:{label:"Updating task",icon:"✅"},add_task_note:{label:"Adding note",icon:"📝"},task_add_note:{label:"Adding note",icon:"📝"},task_list:{label:"Listing tasks",icon:"📋"},task_get:{label:"Getting task",icon:"📋"},task_note:{label:"Adding note",icon:"📝"},task_assign:{label:"Assigning task",icon:"👥"},task_submit_review:{label:"Submitting for review",icon:"✅"},task_comment:{label:"Commenting task",icon:"💬"},subtask_create:{label:"Adding subtask",icon:"📌"},subtask_complete:{label:"Completing subtask",icon:"✅"},subtask_cancel:{label:"Cancelling subtask",icon:"🚫"},subtask_list:{label:"Listing subtasks",icon:"📋"},requirement_propose:{label:"Proposing requirement",icon:"📋"},requirement_list:{label:"Listing requirements",icon:"📋"},requirement_get:{label:"Getting requirement",icon:"📋"},requirement_update:{label:"Updating requirement",icon:"📋"},requirement_update_status:{label:"Updating req status",icon:"✅"},requirement_resubmit:{label:"Resubmitting requirement",icon:"📋"},requirement_comment:{label:"Commenting requirement",icon:"💬"},list_projects:{label:"Listing projects",icon:"🗂"},get_project:{label:"Getting project",icon:"🗂"},create_project:{label:"Creating project",icon:"🗂"},update_project:{label:"Updating project",icon:"🗂"},deliverable_create:{label:"Creating deliverable",icon:"📦"},deliverable_search:{label:"Searching deliverables",icon:"🔍"},deliverable_list:{label:"Listing deliverables",icon:"📦"},deliverable_update:{label:"Updating deliverable",icon:"📦"},git_status:{label:"Git status",icon:"🔀"},git_diff:{label:"Git diff",icon:"🔀"},git_log:{label:"Git log",icon:"📜"},git_branch:{label:"Git branch",icon:"🌿"},git_add:{label:"Git add",icon:"➕"},git_commit:{label:"Git commit",icon:"💾"},project_structure:{label:"Project structure",icon:"🗂"},code_stats:{label:"Code stats",icon:"📊"},navigate_page:{label:"Opening page",icon:"🌐"},new_page:{label:"Opening new tab",icon:"🌐"},close_page:{label:"Closing tab",icon:"🌐"},select_page:{label:"Switching tab",icon:"🌐"},list_pages:{label:"Listing tabs",icon:"🌐"},click:{label:"Clicking element",icon:"👆"},hover:{label:"Hovering element",icon:"👆"},fill:{label:"Filling field",icon:"⌨"},fill_form:{label:"Filling form",icon:"⌨"},type_text:{label:"Typing text",icon:"⌨"},press_key:{label:"Pressing key",icon:"⌨"},take_screenshot:{label:"Screenshot",icon:"📸"},take_snapshot:{label:"Page snapshot",icon:"📋"},evaluate_script:{label:"Running script",icon:"⚙"},wait_for:{label:"Waiting",icon:"⏳"},list_console_messages:{label:"Console logs",icon:"🔍"},list_network_requests:{label:"Network requests",icon:"🔍"},lighthouse_audit:{label:"Running audit",icon:"📊"},agent_send_message:{label:"Messaging colleague",icon:"💬"},agent_list_colleagues:{label:"Checking team",icon:"👥"},memory_save:{label:"Saving memory",icon:"💾"},memory_search:{label:"Searching memory",icon:"🔍"},memory_list:{label:"Listing memory",icon:"💾"},memory_update:{label:"Updating memory",icon:"💾"},recall_activity:{label:"Recalling activity",icon:"📜"},notebook_upsert:{label:"Updating notebook",icon:"📝"},kb_search:{label:"Searching knowledge base",icon:"📚"},kb_list:{label:"Listing knowledge base",icon:"📚"},kb_read:{label:"Reading knowledge base",icon:"📚"},notify_user:{label:"Notifying user",icon:"🔔"},request_user_input:{label:"Requesting input",icon:"❓"},request_user_approval:{label:"Requesting approval",icon:"❓"},schedule_wakeup:{label:"Scheduling wakeup",icon:"⏰"},cancel_wakeup:{label:"Cancelling wakeup",icon:"⏰"},set_heartbeat_interval:{label:"Setting heartbeat",icon:"⏱"},discover_tools:{label:"Discovering tools",icon:"🧰"},check_mailbox:{label:"Checking mailbox",icon:"📥"},goal_create:{label:"Creating goal",icon:"🎯"},goal_update:{label:"Updating goal",icon:"🎯"},goal_status:{label:"Goal status",icon:"🎯"},background_exec:{label:"Background command",icon:"⌨"},process:{label:"Managing process",icon:"⚙"},feishu_send_message:{label:"Sending Feishu msg",icon:"✉"},feishu_search_docs:{label:"Searching Feishu",icon:"🔍"},spawn_subagent:{label:"Spawn Subagent",icon:"◎"},spawn_subagents:{label:"Spawn Subagents",icon:"◎"},invoke_coding_tool:{label:"Invoke Coding Tool",icon:"🛠"},coding_tool_apply:{label:"Apply Coding Result",icon:"🔀"},generate_image:{label:"Generating image",icon:"🖼"},text_to_speech:{label:"Generating speech",icon:"🔊"},speech_to_text:{label:"Transcribing audio",icon:"🎙"},generate_video:{label:"Generating video",icon:"🎬"},llm_list_providers:{label:"Listing providers",icon:"⚙"},llm_switch_model:{label:"Switching model",icon:"⚙"},llm_switch_default_provider:{label:"Switching provider",icon:"⚙"},llm_add_provider:{label:"Adding provider",icon:"⚙"},llm_edit_provider:{label:"Editing provider",icon:"⚙"},llm_add_model:{label:"Adding model",icon:"⚙"},llm_get_capability_routing:{label:"Checking capability routing",icon:"⚙"},llm_set_capability_routing:{label:"Setting capability routing",icon:"⚙"},team_list:{label:"Listing teams",icon:"👥"},team_status:{label:"Team status",icon:"👥"},team_start:{label:"Starting team",icon:"👥"},team_stop:{label:"Stopping team",icon:"👥"},team_update:{label:"Updating team",icon:"👥"},agent_start:{label:"Starting agent",icon:"◎"},agent_stop:{label:"Stopping agent",icon:"◎"},agent_update:{label:"Updating agent",icon:"◎"},agent_delegate_task:{label:"Delegating task",icon:"📌"},agent_broadcast_status:{label:"Broadcasting status",icon:"📣"},agent_create_group_chat:{label:"Creating group chat",icon:"💬"},agent_list_group_chats:{label:"Listing group chats",icon:"💬"},agent_send_group_message:{label:"Sending group message",icon:"💬"},delete_project:{label:"Deleting project",icon:"🗂"},project_stats:{label:"Project stats",icon:"📊"},hub_search:{label:"Searching Hub",icon:"🔍"},hub_install:{label:"Installing from Hub",icon:"📦"},package_list:{label:"Listing packages",icon:"📦"},package_install:{label:"Installing package",icon:"📦"},memory_delete:{label:"Deleting memory",icon:"💾"},memory_update_longterm:{label:"Updating long-term memory",icon:"💾"},notebook_clear:{label:"Clearing notebook",icon:"📝"},notebook_read:{label:"Reading notebook",icon:"📝"},recall_context:{label:"Recalling context",icon:"📜"},defer_mailbox_item:{label:"Deferring mailbox item",icon:"📥"},drop_mailbox_item:{label:"Dropping mailbox item",icon:"📥"},prioritize_mailbox_item:{label:"Prioritizing mailbox",icon:"📥"},delegate_message:{label:"Delegating message",icon:"💬"},task_board_health:{label:"Checking task board",icon:"📋"},task_check_duplicates:{label:"Checking duplicates",icon:"📋"},task_cleanup_duplicates:{label:"Cleaning duplicates",icon:"📋"},workflow_list:{label:"Listing workflows",icon:"🔄"},workflow_create:{label:"Creating workflow",icon:"🔄"},workflow_update:{label:"Updating workflow",icon:"🔄"},workflow_delete:{label:"Deleting workflow",icon:"🔄"},workflow_run:{label:"Running workflow",icon:"🔄"},workflow_status:{label:"Workflow status",icon:"🔄"},workflow_cancel:{label:"Cancelling workflow",icon:"🔄"},open_page:{label:"Opening page",icon:"🌐"},resize_page:{label:"Resizing page",icon:"🌐"},drag:{label:"Dragging element",icon:"👆"},upload_file:{label:"Uploading file",icon:"📎"},emulate:{label:"Emulating device",icon:"📱"},handle_dialog:{label:"Handling dialog",icon:"💬"},get_console_message:{label:"Console message",icon:"🔍"},get_network_request:{label:"Network request",icon:"🔍"}},Vw={shell_execute:"square-terminal",background_exec:"square-terminal",process:"settings",list_terminals:"square-terminal",new_terminal:"square-terminal",select_terminal:"square-terminal",close_terminal:"square-terminal",read_terminal:"square-terminal",write_terminal:"square-terminal",exec_terminal:"square-terminal",file_read:"file-text",file_write:"edit",file_edit:"edit",apply_patch:"git-branch",list_directory:"folder",glob_find:"search",grep_search:"search",web_fetch:"globe",web_search:"search",web_extract:"file-text",create_task:"clipboard",task_create:"clipboard",create_subtask:"clipboard",update_task:"check-circle",task_update:"check-circle",add_task_note:"edit",task_add_note:"edit",task_note:"edit",task_list:"clipboard",task_get:"clipboard",task_assign:"users",task_submit_review:"check-circle",task_comment:"message-square",subtask_create:"clipboard",subtask_complete:"check-circle",subtask_cancel:"alert-circle",subtask_list:"clipboard",requirement_propose:"clipboard",requirement_list:"clipboard",requirement_get:"clipboard",requirement_update:"clipboard",requirement_update_status:"check-circle",requirement_resubmit:"clipboard",requirement_comment:"message-square",list_projects:"layers",get_project:"layers",create_project:"layers",update_project:"layers",deliverable_create:"package",deliverable_search:"search",deliverable_list:"package",deliverable_update:"edit",git_status:"git-branch",git_diff:"git-branch",git_log:"book-open",git_branch:"git-branch",git_add:"git-branch",git_commit:"save",project_structure:"layers",code_stats:"bar-chart",navigate_page:"globe",new_page:"globe",close_page:"globe",select_page:"globe",list_pages:"globe",click:"target",hover:"target",fill:"terminal",fill_form:"terminal",type_text:"terminal",press_key:"terminal",take_screenshot:"camera",take_snapshot:"camera",evaluate_script:"code",wait_for:"clock",list_console_messages:"terminal",list_network_requests:"globe",lighthouse_audit:"bar-chart",agent_send_message:"message-square",agent_list_colleagues:"users",memory_save:"database",memory_search:"search",memory_list:"database",memory_update:"database",recall_activity:"book-open",notebook_upsert:"edit",kb_search:"book-open",kb_list:"book-open",kb_read:"book-open",notify_user:"megaphone",request_user_input:"message-square",request_user_approval:"check-circle",schedule_wakeup:"clock",cancel_wakeup:"clock",set_heartbeat_interval:"clock",discover_tools:"wrench",check_mailbox:"message-square",goal_create:"target",goal_update:"target",goal_status:"target",feishu_send_message:"message-square",feishu_search_docs:"search",spawn_subagent:"bot",spawn_subagents:"bot",invoke_coding_tool:"wrench",coding_tool_apply:"git-branch",generate_image:"camera",text_to_speech:"headphones",speech_to_text:"headphones",generate_video:"camera",llm_list_providers:"settings",llm_switch_model:"settings",llm_switch_default_provider:"settings",llm_add_provider:"settings",llm_edit_provider:"settings",llm_add_model:"settings",llm_get_capability_routing:"settings",llm_set_capability_routing:"settings",team_list:"users",team_status:"users",team_start:"users",team_stop:"users",team_update:"users",agent_start:"bot",agent_stop:"bot",agent_update:"bot",agent_delegate_task:"clipboard",agent_broadcast_status:"megaphone",agent_create_group_chat:"message-square",agent_list_group_chats:"message-square",agent_send_group_message:"message-square",delete_project:"layers",project_stats:"bar-chart",hub_search:"search",hub_install:"package",package_list:"package",package_install:"package",memory_delete:"database",memory_update_longterm:"database",notebook_clear:"edit",notebook_read:"edit",recall_context:"book-open",defer_mailbox_item:"message-square",drop_mailbox_item:"message-square",prioritize_mailbox_item:"message-square",delegate_message:"message-square",task_board_health:"clipboard",task_check_duplicates:"clipboard",task_cleanup_duplicates:"clipboard",workflow_list:"git-branch",workflow_create:"git-branch",workflow_update:"git-branch",workflow_delete:"git-branch",workflow_run:"git-branch",workflow_status:"git-branch",workflow_cancel:"git-branch",open_page:"globe",resize_page:"globe",drag:"target",upload_file:"file-text",emulate:"settings",handle_dialog:"message-square",get_console_message:"terminal",get_network_request:"globe"};function zs(e){const t=e.includes("__")?e.split("__").pop():e,n=Kw[t]??Kw[e],a=Vw[t]??Vw[e]??"settings";return n?{...n,iconName:a,key:t}:{label:t.replace(/_/g," ").replace(/\b\w/g,s=>s.toUpperCase()),icon:"⚙",iconName:a,key:t}}function $s(e){return e==null?"":e<1e3?`${e}ms`:`${(e/1e3).toFixed(1)}s`}function gae(e){const t=new Date(e);if(isNaN(t.getTime()))return e;const n=String(t.getMonth()+1).padStart(2,"0"),a=String(t.getDate()).padStart(2,"0"),s=String(t.getHours()).padStart(2,"0"),l=String(t.getMinutes()).padStart(2,"0"),c=String(t.getSeconds()).padStart(2,"0");return`${n}-${a} ${s}:${l}:${c}`}function gg(e,t){return e.length<=t?e:e.slice(0,t)+"…"}function Ww(e){try{const t=JSON.parse(e);return JSON.stringify(t,null,2)}catch{return e}}function zS(e){return!e||typeof e!="object"?[]:Object.entries(e).filter(([,n])=>n!=null).map(([n,a])=>({key:n,value:typeof a=="string"?a:JSON.stringify(a,null,2)}))}function bae(e){if(e.tool!=="shell_execute"||!e.args||typeof e.args!="object")return null;const t=e.args.command;return typeof t=="string"?t:null}function rse(e,t){const n=new Map;let a=null;for(const s of e)if(s.type==="tool_start"&&(s.content==="spawn_subagent"||s.content==="spawn_subagents"))a=s.seq,n.set(s.seq,[]);else if(s.type==="tool_end"&&(s.content==="spawn_subagent"||s.content==="spawn_subagents")){if(a!==null){const l=n.get(a);l&&n.set(s.seq,l)}a=null}else if(a!==null&&s.type.startsWith("subagent_")){const l=s.type.replace("subagent_",""),c=s.metadata;n.get(a)?.push({eventType:l,content:s.content,metadata:c})}return t.map(s=>{if(s.type!=="tool")return s;const l=s.key;if(!l)return s;const c=l.replace(/^(?:t[se]_|e[se]_)/,""),d=parseInt(c,10);if(isNaN(d))return s;const m=n.get(d);return!m||m.length===0?s:{...s,info:{...s.info,subagentLogs:m}}})}function bg(e){const t=new Set;for(let n=0;n<e.length;n++){const a=e[n];if(a.type==="tool"&&(a.info.status==="done"||a.info.status==="error"))for(let s=n-1;s>=0;s--){const l=e[s];if(l.type==="tool"&&l.info.status==="running"&&l.info.tool===a.info.tool&&!t.has(s)){t.add(s);break}}}return e.filter((n,a)=>!t.has(a))}function gb(e){const t=gae(e.createdAt),n=e.createdAt,a=e.metadata;switch(e.type){case"text":return a?.isThinking?{type:"thinking",content:e.content,time:t,timestamp:n}:{type:"text",content:e.content,time:t,timestamp:n};case"status":{const s=a?.action;return s&&["chat","chat_stream","task_execution","respond_in_session"].includes(s)?null:{type:"status",content:e.content,time:t,timestamp:n}}case"error":return{type:"error",content:e.content,time:t,timestamp:n};case"tool_start":return{type:"tool",time:t,timestamp:n,key:`es_${e.seq}`,info:{tool:e.content,status:"running",args:a?.arguments,subagentLogs:a?.subagentLogs}};case"tool_end":return{type:"tool",time:t,timestamp:n,key:`ee_${e.seq}`,info:{tool:e.content,status:a?.success===!1?"error":"done",args:a?.arguments,result:a?.result,error:a?.error,durationMs:a?.durationMs,subagentLogs:a?.subagentLogs}};default:return null}}function BS(e,t){if(e!=="task_create"&&e!=="create_task"||!t)return null;try{const n=JSON.parse(t);if(!n.task)return null;const a=n.task;return{taskId:a.id,title:a.title,description:a.description,assignedAgentId:a.assignedAgentId,priority:a.priority}}catch{return null}}function HS(e,t){if(e!=="requirement_propose"||!t)return null;try{const n=JSON.parse(t);if(n.status!=="success"||!n.requirement)return null;const a=n.requirement;return a.status!=="pending"?null:{requirementId:a.id,title:a.title,description:a.description,priority:a.priority}}catch{return null}}const $S={code:i.jsxs(i.Fragment,{children:[i.jsx("polyline",{points:"16 18 22 12 16 6"}),i.jsx("polyline",{points:"8 6 2 12 8 18"})]}),search:i.jsxs(i.Fragment,{children:[i.jsx("circle",{cx:"11",cy:"11",r:"8"}),i.jsx("path",{d:"m21 21-4.3-4.3"})]}),clipboard:i.jsxs(i.Fragment,{children:[i.jsx("rect",{width:"8",height:"4",x:"8",y:"2",rx:"1",ry:"1"}),i.jsx("path",{d:"M16 4h2a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2h2"})]}),"check-circle":i.jsxs(i.Fragment,{children:[i.jsx("circle",{cx:"12",cy:"12",r:"10"}),i.jsx("path",{d:"m9 12 2 2 4-4"})]}),server:i.jsxs(i.Fragment,{children:[i.jsx("rect",{width:"20",height:"8",x:"2",y:"2",rx:"2",ry:"2"}),i.jsx("rect",{width:"20",height:"8",x:"2",y:"14",rx:"2",ry:"2"}),i.jsx("line",{x1:"6",x2:"6.01",y1:"6",y2:"6"}),i.jsx("line",{x1:"6",x2:"6.01",y1:"18",y2:"18"})]}),"file-text":i.jsxs(i.Fragment,{children:[i.jsx("path",{d:"M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z"}),i.jsx("path",{d:"M14 2v4a2 2 0 0 0 2 2h4"}),i.jsx("path",{d:"M10 9H8"}),i.jsx("path",{d:"M16 13H8"}),i.jsx("path",{d:"M16 17H8"})]}),"book-open":i.jsxs(i.Fragment,{children:[i.jsx("path",{d:"M12 7v14"}),i.jsx("path",{d:"M3 18a1 1 0 0 1-1-1V4a1 1 0 0 1 1-1h5a4 4 0 0 1 4 4 4 4 0 0 1 4-4h5a1 1 0 0 1 1 1v13a1 1 0 0 1-1 1h-6a3 3 0 0 0-3 3 3 3 0 0 0-3-3z"})]}),users:i.jsxs(i.Fragment,{children:[i.jsx("path",{d:"M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2"}),i.jsx("circle",{cx:"9",cy:"7",r:"4"}),i.jsx("path",{d:"M22 21v-2a4 4 0 0 0-3-3.87"}),i.jsx("path",{d:"M16 3.13a4 4 0 0 1 0 7.75"})]}),"dollar-sign":i.jsxs(i.Fragment,{children:[i.jsx("line",{x1:"12",x2:"12",y1:"2",y2:"22"}),i.jsx("path",{d:"M17 5H9.5a3.5 3.5 0 0 0 0 7h5a3.5 3.5 0 0 1 0 7H6"})]}),megaphone:i.jsxs(i.Fragment,{children:[i.jsx("path",{d:"m3 11 18-5v12L3 14v-3z"}),i.jsx("path",{d:"M11.6 16.8a3 3 0 1 1-5.8-1.6"})]}),edit:i.jsxs(i.Fragment,{children:[i.jsx("path",{d:"M12 20h9"}),i.jsx("path",{d:"M16.5 3.5a2.121 2.121 0 0 1 3 3L7 19l-4 1 1-4Z"})]}),headphones:i.jsx(i.Fragment,{children:i.jsx("path",{d:"M3 14h3a2 2 0 0 1 2 2v3a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-5a9 9 0 0 1 18 0v5a2 2 0 0 1-2 2h-1a2 2 0 0 1-2-2v-3a2 2 0 0 1 2-2h3"})}),settings:i.jsxs(i.Fragment,{children:[i.jsx("path",{d:"M12.22 2h-.44a2 2 0 0 0-2 2v.18a2 2 0 0 1-1 1.73l-.43.25a2 2 0 0 1-2 0l-.15-.08a2 2 0 0 0-2.73.73l-.22.38a2 2 0 0 0 .73 2.73l.15.1a2 2 0 0 1 1 1.72v.51a2 2 0 0 1-1 1.74l-.15.09a2 2 0 0 0-.73 2.73l.22.38a2 2 0 0 0 2.73.73l.15-.08a2 2 0 0 1 2 0l.43.25a2 2 0 0 1 1 1.73V20a2 2 0 0 0 2 2h.44a2 2 0 0 0 2-2v-.18a2 2 0 0 1 1-1.73l.43-.25a2 2 0 0 1 2 0l.15.08a2 2 0 0 0 2.73-.73l.22-.39a2 2 0 0 0-.73-2.73l-.15-.08a2 2 0 0 1-1-1.74v-.5a2 2 0 0 1 1-1.74l.15-.09a2 2 0 0 0 .73-2.73l-.22-.38a2 2 0 0 0-2.73-.73l-.15.08a2 2 0 0 1-2 0l-.43-.25a2 2 0 0 1-1-1.73V4a2 2 0 0 0-2-2z"}),i.jsx("circle",{cx:"12",cy:"12",r:"3"})]}),target:i.jsxs(i.Fragment,{children:[i.jsx("circle",{cx:"12",cy:"12",r:"10"}),i.jsx("circle",{cx:"12",cy:"12",r:"6"}),i.jsx("circle",{cx:"12",cy:"12",r:"2"})]}),zap:i.jsx(i.Fragment,{children:i.jsx("polygon",{points:"13 2 3 14 12 14 11 22 21 10 12 10 13 2"})}),terminal:i.jsxs(i.Fragment,{children:[i.jsx("polyline",{points:"4 17 10 11 4 5"}),i.jsx("line",{x1:"12",x2:"20",y1:"19",y2:"19"})]}),sparkles:i.jsxs(i.Fragment,{children:[i.jsx("path",{d:"M9.937 15.5A2 2 0 0 0 8.5 14.063l-6.135-1.582a.5.5 0 0 1 0-.962L8.5 9.936A2 2 0 0 0 9.937 8.5l1.582-6.135a.5.5 0 0 1 .962 0L14.063 8.5A2 2 0 0 0 15.5 9.937l6.135 1.581a.5.5 0 0 1 0 .964L15.5 14.063a2 2 0 0 0-1.437 1.437l-1.582 6.135a.5.5 0 0 1-.962 0z"}),i.jsx("path",{d:"M20 3v4"}),i.jsx("path",{d:"M22 5h-4"})]}),wrench:i.jsx(i.Fragment,{children:i.jsx("path",{d:"M14.7 6.3a1 1 0 0 0 0 1.4l1.6 1.6a1 1 0 0 0 1.4 0l3.77-3.77a6 6 0 0 1-7.94 7.94l-6.91 6.91a2.12 2.12 0 0 1-3-3l6.91-6.91a6 6 0 0 1 7.94-7.94l-3.76 3.76z"})}),globe:i.jsxs(i.Fragment,{children:[i.jsx("circle",{cx:"12",cy:"12",r:"10"}),i.jsx("path",{d:"M12 2a14.5 14.5 0 0 0 0 20 14.5 14.5 0 0 0 0-20"}),i.jsx("path",{d:"M2 12h20"})]}),link:i.jsxs(i.Fragment,{children:[i.jsx("path",{d:"M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"}),i.jsx("path",{d:"M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"})]}),bot:i.jsxs(i.Fragment,{children:[i.jsx("path",{d:"M12 8V4H8"}),i.jsx("rect",{width:"16",height:"12",x:"4",y:"8",rx:"2"}),i.jsx("path",{d:"M2 14h2"}),i.jsx("path",{d:"M20 14h2"}),i.jsx("path",{d:"M15 13v2"}),i.jsx("path",{d:"M9 13v2"})]}),"message-square":i.jsx(i.Fragment,{children:i.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"})}),newspaper:i.jsxs(i.Fragment,{children:[i.jsx("path",{d:"M4 22h16a2 2 0 0 0 2-2V4a2 2 0 0 0-2-2H8a2 2 0 0 0-2 2v16a2 2 0 0 1-2 2Zm0 0a2 2 0 0 1-2-2v-9c0-1.1.9-2 2-2h2"}),i.jsx("path",{d:"M18 14h-8"}),i.jsx("path",{d:"M15 18h-5"}),i.jsx("path",{d:"M10 6h8v4h-8V6Z"})]}),layers:i.jsxs(i.Fragment,{children:[i.jsx("path",{d:"m12.83 2.18a2 2 0 0 0-1.66 0L2.6 6.08a1 1 0 0 0 0 1.83l8.58 3.91a2 2 0 0 0 1.66 0l8.58-3.9a1 1 0 0 0 0-1.83Z"}),i.jsx("path",{d:"m22 17.65-9.17 4.16a2 2 0 0 1-1.66 0L2 17.65"}),i.jsx("path",{d:"m22 12.65-9.17 4.16a2 2 0 0 1-1.66 0L2 12.65"})]}),"bar-chart":i.jsxs(i.Fragment,{children:[i.jsx("line",{x1:"12",x2:"12",y1:"20",y2:"10"}),i.jsx("line",{x1:"18",x2:"18",y1:"20",y2:"4"}),i.jsx("line",{x1:"6",x2:"6",y1:"20",y2:"16"})]}),folder:i.jsx(i.Fragment,{children:i.jsx("path",{d:"M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z"})}),"git-branch":i.jsxs(i.Fragment,{children:[i.jsx("line",{x1:"6",x2:"6",y1:"3",y2:"15"}),i.jsx("circle",{cx:"18",cy:"6",r:"3"}),i.jsx("circle",{cx:"6",cy:"18",r:"3"}),i.jsx("path",{d:"M18 9a9 9 0 0 1-9 9"})]}),save:i.jsxs(i.Fragment,{children:[i.jsx("path",{d:"M15.2 3a2 2 0 0 1 1.4.6l3.8 3.8a2 2 0 0 1 .6 1.4V19a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2z"}),i.jsx("path",{d:"M17 21v-7a1 1 0 0 0-1-1H8a1 1 0 0 0-1 1v7"}),i.jsx("path",{d:"M7 3v4a1 1 0 0 0 1 1h7"})]}),camera:i.jsxs(i.Fragment,{children:[i.jsx("path",{d:"M14.5 4h-5L7 7H4a2 2 0 0 0-2 2v9a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2V9a2 2 0 0 0-2-2h-3l-2.5-3z"}),i.jsx("circle",{cx:"12",cy:"13",r:"3"})]}),clock:i.jsxs(i.Fragment,{children:[i.jsx("circle",{cx:"12",cy:"12",r:"10"}),i.jsx("polyline",{points:"12 6 12 12 16 14"})]}),database:i.jsxs(i.Fragment,{children:[i.jsx("ellipse",{cx:"12",cy:"5",rx:"9",ry:"3"}),i.jsx("path",{d:"M3 5v14a9 3 0 0 0 18 0V5"}),i.jsx("path",{d:"M3 12a9 3 0 0 0 18 0"})]}),lightbulb:i.jsxs(i.Fragment,{children:[i.jsx("path",{d:"M15 14c.2-1 .7-1.7 1.5-2.5 1-.9 1.5-2.2 1.5-3.5A6 6 0 0 0 6 8c0 1 .2 2.2 1.5 3.5.7.7 1.3 1.5 1.5 2.5"}),i.jsx("path",{d:"M9 18h6"}),i.jsx("path",{d:"M10 22h4"})]}),"alert-circle":i.jsxs(i.Fragment,{children:[i.jsx("circle",{cx:"12",cy:"12",r:"10"}),i.jsx("line",{x1:"12",x2:"12",y1:"8",y2:"12"}),i.jsx("line",{x1:"12",x2:"12.01",y1:"16",y2:"16"})]}),"square-terminal":i.jsxs(i.Fragment,{children:[i.jsx("path",{d:"m7 11 2-2-2-2"}),i.jsx("path",{d:"M11 13h4"}),i.jsx("rect",{width:"18",height:"18",x:"3",y:"3",rx:"2"})]}),package:i.jsxs(i.Fragment,{children:[i.jsx("path",{d:"m7.5 4.27 9 5.15"}),i.jsx("path",{d:"M21 8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16Z"}),i.jsx("path",{d:"m3.3 7 8.7 5 8.7-5"}),i.jsx("path",{d:"M12 22V12"})]})};function yae(e){return!!e&&e in $S}function rl({name:e,size:t=24,className:n=""}){const a=$S[e];return a?i.jsx("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",className:n,"aria-hidden":!0,children:a}):null}const Yw={"coding-tools":"terminal",markitdown:"file-text","markus-admin-cli":"terminal",codex:"code","team-building":"users","claude-code":"code","skill-building":"wrench","workflow-building":"layers","chrome-devtools":"globe","markus-hub-connector":"link","cursor-agent":"bot","agent-building":"bot","feishu-interaction":"message-square","content-publishing":"edit","research-report":"book-open","daily-digest":"newspaper"},Qw={development:"code",开发工具:"code",devops:"server",data:"bar-chart",数据分析:"bar-chart",productivity:"zap",效率提升:"zap",communication:"message-square",通讯协作:"message-square",browser:"globe",内容创作:"edit","AI 智能":"sparkles"};function tm(e,t){const n=(e||"").toLowerCase();return Yw[n]?Yw[n]:t&&Qw[t]?Qw[t]:"layers"}function xae(e){const t=[];for(const n of e)if(n.phase!=="output"){if(n.phase==="start"){const a=`${n.tool}_${n.ts}`;t.push({key:a,tool:n.tool,status:"running"})}else for(let a=t.length-1;a>=0;a--)if(t[a].tool===n.tool&&t[a].status==="running"){t[a]={...t[a],status:n.success===!1?"error":"done"};break}}return t}function qS(){return i.jsxs("svg",{className:"w-3 h-3 animate-spin text-brand-500 shrink-0",viewBox:"0 0 24 24",fill:"none",children:[i.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),i.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"})]})}function vae(){return i.jsx("span",{className:"flex items-center gap-0.5",children:[0,150,300].map(e=>i.jsx("span",{className:"w-1 h-1 rounded-full bg-brand-400 animate-bounce",style:{animationDelay:`${e}ms`,animationDuration:"1s"}},e))})}function Xw({item:e}){const{t}=ot("common"),n=zs(e.tool);return i.jsxs("div",{className:"flex items-center gap-1.5 py-0.5",children:[i.jsx(rl,{name:n.iconName,size:15,className:`shrink-0 ${e.status==="running"?"text-brand-500":e.status==="error"?"text-red-500":"text-green-500"}`}),i.jsxs("span",{className:`text-xs ${e.status==="running"?"activity-text-shimmer":e.status==="error"?"text-fg-tertiary":"text-fg-secondary"}`,children:[t(`execution.tools.${n.key}`,{defaultValue:n.label}),e.status==="running"?"…":""]}),e.status==="running"&&i.jsx(qS,{})]})}function Jw({activities:e,isActive:t,persistent:n}){const{t:a}=ot("common"),s=xae(e),[l,c]=k.useState(!1),d=s.length>0,m=d&&s.every(w=>w.status!=="running");if(n&&m){const w=s.filter(C=>C.status==="error").length,T=s.filter(C=>C.status==="done").length;return i.jsxs("div",{className:"mb-3 border-b border-border-default/50 pb-2",children:[i.jsxs("button",{onClick:()=>c(C=>!C),className:"flex items-center gap-1.5 text-xs text-fg-tertiary hover:text-fg-secondary transition-colors select-none",children:[i.jsx("span",{className:`transition-transform duration-150 ${l?"rotate-90":""}`,children:"▶"}),i.jsx("span",{className:"font-medium",children:a("activity.step",{count:T})}),w>0&&i.jsxs("span",{className:"text-red-500 ml-0.5",children:["· ",a("activity.failed",{count:w})]}),!l&&i.jsxs("span",{className:"ml-1 flex items-center gap-1",children:[s.slice(0,5).map(C=>{const S=zs(C.tool);return i.jsx(rl,{name:S.iconName,size:13,className:`shrink-0 ${C.status==="error"?"text-red-500":"text-green-500"}`},C.key)}),s.length>5&&i.jsxs("span",{className:"text-[10px] text-fg-tertiary",children:["+",s.length-5]})]})]}),l&&i.jsx("div",{className:"mt-2 space-y-0.5",children:s.map((C,S)=>i.jsx(Xw,{item:C,idx:S,total:s.length},C.key))})]})}if(!d)return i.jsxs("div",{className:"flex items-center gap-1.5 text-xs py-0.5",children:[i.jsx("span",{className:"mr-0.5 activity-text-shimmer",children:a("activity.thinking")}),i.jsx(vae,{})]});const p=s.filter(w=>w.status==="error").length;let h=null;for(let w=s.length-1;w>=0;w--)if(s[w].status==="running"){h=s[w];break}const g=s[s.length-1];let x;if(h){const w=zs(h.tool);x=`${a(`execution.tools.${w.key}`,{defaultValue:w.label})}…`}else if(t&&m)x=a("activity.writingResponse");else{const w=zs(g.tool);x=a(`execution.tools.${w.key}`,{defaultValue:w.label})}const y=!!h||t&&m;return i.jsxs("div",{className:"mb-1",children:[i.jsxs("button",{onClick:w=>{w.stopPropagation(),c(T=>!T)},className:"flex items-center gap-1.5 text-xs w-full min-w-0 select-none text-fg-tertiary hover:text-fg-secondary transition-colors",children:[i.jsx("span",{className:`shrink-0 transition-transform duration-150 ${l?"rotate-90":""}`,children:"▶"}),i.jsx("span",{className:`truncate font-medium ${y?"activity-text-shimmer":"text-fg-secondary"}`,children:x}),i.jsxs("span",{className:"shrink-0",children:["· ",a("activity.step",{count:s.length})]}),p>0&&i.jsxs("span",{className:"text-red-500 shrink-0",children:["· ",a("activity.failed",{count:p})]}),y&&i.jsx(qS,{})]}),l&&i.jsx("div",{className:"mt-1 space-y-0.5",children:s.map((w,T)=>i.jsx(Xw,{item:w,idx:T,total:s.length},w.key))})]})}const wae={"claude-code":{label:"Claude Code",icon:"🤖",badgeClass:"bg-orange-500/15 text-orange-500"},codex:{label:"Codex",icon:"⬡",badgeClass:"bg-emerald-500/15 text-emerald-500"},"cursor-agent":{label:"Cursor",icon:"▶",badgeClass:"bg-blue-500/15 text-blue-500"}},Uo=["created","context_injected","running"],kae=new Set(["completed","failed","cancelled","timeout"]),Zw={created:"Created",context_injected:"Context injected",running:"Running",completed:"Completed",failed:"Failed",cancelled:"Cancelled",timeout:"Timed out"};function Sae(e){return wae[e]??{label:e.replace(/-/g," ").replace(/\b\w/g,t=>t.toUpperCase()),icon:"⚙",badgeClass:"bg-surface-elevated text-fg-tertiary"}}function Cae(e,t){if(e.cost?.durationMs!=null)return e.cost.durationMs;const n=e.startedAt??e.createdAt,a=new Date(n).getTime();if(!Number.isNaN(a)){if(e.completedAt){const s=new Date(e.completedAt).getTime();return Number.isNaN(s)?void 0:Math.max(0,s-a)}if(e.status==="running"||e.status==="context_injected")return Math.max(0,t-a)}}function Aae(e){if(e==="completed"||kae.has(e))return Uo.length;const t=Uo.indexOf(e);return t>=0?t:0}function Tae({session:e,className:t}){const n=Sae(e.tool),[a,s]=k.useState(!1),[l,c]=k.useState(()=>Date.now()),d=e.status==="running"||e.status==="context_injected"||e.status==="created",m=e.status==="failed"||e.status==="timeout"||e.result?.success===!1,p=e.status==="completed"||e.result?.success===!0;k.useEffect(()=>{if(!d)return;const w=setInterval(()=>c(Date.now()),1e3);return()=>clearInterval(w)},[d]);const h=k.useMemo(()=>Cae(e,l),[e,l]),g=Aae(e.status),x=e.result?.rawOutput??(p||m?e.result?.summary:void 0),y=d?"border-brand-500/40 bg-brand-500/5":m?"border-red-500/30 bg-red-500/5":p?"border-green-500/30 bg-green-500/5":"border-border-default bg-surface-secondary/30";return i.jsxs("div",{className:`my-2 rounded-lg border ${y} p-3 max-w-2xl transition-colors ${t??""}`,children:[i.jsxs("div",{className:"flex items-start gap-2",children:[i.jsx("span",{className:"text-sm mt-0.5",children:n.icon}),i.jsxs("div",{className:"flex-1 min-w-0",children:[i.jsxs("div",{className:"flex items-center gap-1.5 flex-wrap",children:[i.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded font-medium ${n.badgeClass}`,children:n.label}),i.jsx("span",{className:`text-[10px] font-medium ${d?"text-brand-500":m?"text-red-500":p?"text-green-500":"text-fg-tertiary"}`,children:Zw[e.status]??e.status}),h!=null&&i.jsx("span",{className:"text-[10px] text-fg-tertiary tabular-nums",children:$s(h)}),e.cost?.estimatedCostUsd!=null&&i.jsxs("span",{className:"text-[10px] text-fg-tertiary tabular-nums",children:["$",e.cost.estimatedCostUsd.toFixed(4)]})]}),i.jsx("div",{className:"text-xs text-fg-secondary mt-1 line-clamp-2",children:e.prompt})]}),d&&i.jsxs("svg",{className:"w-3.5 h-3.5 animate-spin text-brand-500 shrink-0 mt-0.5",viewBox:"0 0 24 24",fill:"none",children:[i.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),i.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"})]})]}),i.jsxs("div",{className:"flex items-center gap-1 mt-3 ml-6",children:[Uo.map((w,T)=>{const C=g>T||g===T&&!d&&p,S=g===T&&d,E=m&&T===Uo.length-1&&e.status!=="completed";return i.jsxs("div",{className:"flex items-center gap-1 flex-1 min-w-0",children:[i.jsx("div",{className:`w-2 h-2 rounded-full shrink-0 ${E?"bg-red-500":C?"bg-green-500":S?"bg-brand-500 animate-pulse":"bg-gray-600"}`,title:Zw[w]}),T<Uo.length-1&&i.jsx("div",{className:`h-px flex-1 ${C?"bg-green-500/50":"bg-border-default/60"}`})]},w)}),i.jsx("div",{className:`w-2 h-2 rounded-full shrink-0 ${m?"bg-red-500":p?"bg-green-500":"bg-gray-600"}`,title:m?"Failed":"Done"})]}),(e.progressMessage||e.progressPercent!=null)&&d&&i.jsxs("div",{className:"mt-2 ml-6 space-y-1",children:[e.progressPercent!=null&&i.jsx("div",{className:"h-1 bg-surface-elevated rounded-full overflow-hidden",children:i.jsx("div",{className:"h-full bg-brand-500 transition-all duration-300",style:{width:`${Math.min(100,Math.max(0,e.progressPercent))}%`}})}),e.progressMessage&&i.jsx("div",{className:"text-[11px] text-fg-tertiary font-mono truncate",children:e.progressMessage})]}),e.result&&!d&&i.jsxs("div",{className:"mt-2 ml-6 space-y-1.5",children:[e.result.summary&&i.jsx("div",{className:"text-xs text-fg-secondary",children:e.result.summary}),e.result.diffStats&&i.jsxs("div",{className:"flex items-center gap-3 text-[10px] font-mono",children:[i.jsxs("span",{className:"text-fg-tertiary",children:[e.result.diffStats.filesChanged," files"]}),i.jsxs("span",{className:"text-green-500",children:["+",e.result.diffStats.additions]}),i.jsxs("span",{className:"text-red-500",children:["−",e.result.diffStats.deletions]})]}),e.cost&&(e.cost.inputTokens!=null||e.cost.outputTokens!=null)&&i.jsxs("div",{className:"text-[10px] text-fg-tertiary",children:[e.cost.inputTokens!=null&&i.jsxs("span",{children:[e.cost.inputTokens.toLocaleString()," in"]}),e.cost.inputTokens!=null&&e.cost.outputTokens!=null&&i.jsx("span",{className:"mx-1",children:"·"}),e.cost.outputTokens!=null&&i.jsxs("span",{children:[e.cost.outputTokens.toLocaleString()," out"]})]})]}),x&&i.jsxs("div",{className:"mt-2 ml-6 border-t border-border-default/30 pt-2",children:[i.jsxs("button",{type:"button",onClick:()=>s(!a),className:"flex items-center gap-1.5 text-[10px] text-fg-tertiary hover:text-fg-secondary transition-colors",children:[i.jsx("svg",{className:`w-3 h-3 transition-transform ${a?"rotate-90":""}`,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:i.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M9 5l7 7-7 7"})}),i.jsx("span",{className:"font-medium uppercase tracking-wider",children:"Raw output"})]}),a&&i.jsx("pre",{className:"mt-2 text-[11px] text-fg-tertiary bg-surface-elevated/70 rounded-lg px-3 py-2 overflow-x-auto max-h-48 overflow-y-auto whitespace-pre-wrap break-all font-mono",children:x})]})]})}function Nae({label:e}){const{t}=ot("common");return i.jsxs("div",{className:"flex items-center gap-1.5 text-xs py-0.5",children:[i.jsx("span",{className:"activity-text-shimmer",children:e??t("execution.thinking")}),i.jsx("span",{className:"flex gap-0.5",children:[0,150,300].map(n=>i.jsx("span",{className:"w-1 h-1 rounded-full bg-brand-400 animate-bounce",style:{animationDelay:`${n}ms`,animationDuration:"1s"}},n))})]})}const ek=150;function Eae({content:e,className:t}){const[n,a]=k.useState(e),s=k.useRef(0),l=k.useRef(null);k.useEffect(()=>{const d=Date.now(),m=d-s.current;return m>=ek?(s.current=d,a(e)):l.current||(l.current=setTimeout(()=>{s.current=Date.now(),l.current=null,a(e)},ek-m)),()=>{l.current&&(clearTimeout(l.current),l.current=null)}},[e]);const c=k.useMemo(()=>n,[n]);return i.jsxs("div",{className:"bg-surface-elevated/50 rounded-lg px-3 py-2.5 my-1 min-w-0 overflow-hidden",children:[i.jsx(Ea,{content:c,className:t??"text-sm text-fg-secondary break-words"}),i.jsx("span",{className:"inline-block w-0.5 h-4 bg-brand-400 animate-pulse ml-0.5 align-middle"})]})}const _m=8e3,Dd=120;function mh({text:e,className:t}){const{t:n}=ot("common"),[a,s]=k.useState(!1),l=e.length>_m,c=!l||a?e:`${e.slice(0,_m)}
858
- …`;return i.jsxs("div",{children:[i.jsx("pre",{className:t,children:c}),l&&i.jsx("button",{type:"button",className:"mt-1 text-[11px] text-brand-500 hover:underline",onClick:d=>{d.stopPropagation(),s(m=>!m)},children:n(a?"showLess":"showMore")})]})}function jae({info:e,time:t}){const{t:n}=ot("common"),a=zS(e.args),s=e.status==="running",l=e.status!=="error",c=a.length>0||!s&&(!!e.result||!!e.error)||!!e.subagentLogs&&e.subagentLogs.length>0,d=k.useRef(null),m=e.subagentLogs?.length??0,p=e.subagentLogs&&e.subagentLogs.length>Dd?e.subagentLogs.slice(e.subagentLogs.length-Dd):e.subagentLogs;return k.useEffect(()=>{!s||!d.current||(d.current.scrollTop=d.current.scrollHeight)},[m,s]),i.jsxs("div",{className:"space-y-3 py-1",children:[i.jsxs("div",{className:"flex items-center gap-2 text-[10px]",children:[i.jsx("span",{className:`px-1.5 py-0.5 rounded ${s?"bg-brand-500/15 text-brand-500":l?"bg-green-500/15 text-green-600":"bg-surface-overlay text-fg-tertiary"}`,children:n(s?"execution.toolRunning":l?"execution.toolSuccess":"execution.toolFailed")}),t&&i.jsx("span",{className:"text-fg-tertiary tabular-nums",children:t}),e.durationMs!=null&&i.jsx("span",{className:"text-fg-tertiary",children:$s(e.durationMs)})]}),a.length>0&&i.jsxs("div",{children:[i.jsx("h4",{className:"text-[10px] font-semibold text-fg-tertiary uppercase tracking-wider mb-1",children:n("execution.arguments")}),i.jsx("div",{className:"space-y-2",children:a.map(({key:h,value:g})=>i.jsxs("div",{children:[i.jsx("div",{className:"text-[11px] text-brand-500 font-medium mb-0.5",children:h}),i.jsx(mh,{text:g,className:"text-xs text-fg-secondary bg-surface-elevated/70 rounded-lg px-3 py-2 overflow-x-auto whitespace-pre-wrap break-all font-mono"})]},h))})]}),p&&p.length>0&&i.jsxs("div",{children:[i.jsx("h4",{className:"text-[10px] font-semibold text-fg-tertiary uppercase tracking-wider mb-1",children:n("execution.subagentExecution")}),i.jsxs("div",{ref:d,className:"bg-surface-elevated/50 rounded-lg px-3 py-2 space-y-1 max-h-64 overflow-y-auto",children:[m>Dd&&i.jsxs("div",{className:"text-[10px] text-fg-tertiary pb-1",children:["… ",m-Dd," earlier steps omitted"]}),p.map((h,g)=>{const x=h.eventType==="started"?"▶":h.eventType==="completed"?"✓":h.eventType==="error"?"✗":h.eventType==="tool_start"?"◎":h.eventType==="tool_end"?"●":h.eventType==="thinking"?"·":"→",y=h.eventType==="error"?"text-fg-tertiary":h.eventType==="completed"?"text-green-500":h.eventType==="started"||h.eventType==="tool_start"?"text-brand-500":"text-fg-tertiary";return i.jsxs("div",{className:"flex items-start gap-1.5 text-xs",children:[i.jsx("span",{className:`shrink-0 ${y}`,children:x}),i.jsx("span",{className:`font-mono break-all ${y}`,children:gg(h.content,500)})]},g)}),s&&i.jsxs("div",{className:"flex items-center gap-1.5 text-[11px] text-brand-500 pt-0.5",children:[i.jsxs("svg",{className:"w-3 h-3 animate-spin shrink-0",viewBox:"0 0 24 24",fill:"none",children:[i.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),i.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"})]}),i.jsx("span",{children:n("execution.toolRunning")})]})]})]}),!s&&e.result&&i.jsxs("div",{children:[i.jsx("h4",{className:"text-[10px] font-semibold text-fg-tertiary uppercase tracking-wider mb-1",children:n("execution.result")}),i.jsx(mh,{text:Ww(e.result),className:"text-xs text-fg-secondary bg-surface-elevated/70 rounded-lg px-3 py-2 overflow-x-auto whitespace-pre-wrap break-all font-mono"})]}),!s&&e.error&&i.jsxs("div",{children:[i.jsx("h4",{className:"text-[10px] font-semibold text-fg-tertiary uppercase tracking-wider mb-1",children:n("execution.error")}),i.jsx(mh,{text:Ww(String(e.error)),className:"text-xs text-fg-secondary bg-surface-elevated/50 border border-border-default rounded-lg px-3 py-2 overflow-x-auto whitespace-pre-wrap break-all font-mono"})]}),!c&&i.jsx("div",{className:"text-xs text-fg-tertiary italic py-2 text-center",children:n("execution.noToolDetail")})]})}const FS={urgent:"text-red-500",high:"text-amber-500",medium:"text-blue-500",low:"text-fg-tertiary"},tk={pending:"pending",in_progress:"in_progress",completed:"completed",review:"review",blocked:"blocked",failed:"failed",cancelled:"cancelled",archived:"archived"},nk={pending:{icon:"⏳",labelKey:"execution.card.pendingApproval",borderClass:"border-amber-500/40",bgClass:"bg-amber-500/5",badgeClass:"bg-amber-500/15 text-amber-600",textClass:""},approving:{icon:"⏳",labelKey:"execution.card.approving",borderClass:"border-amber-500/40",bgClass:"bg-amber-500/5",badgeClass:"bg-amber-500/15 text-amber-600",textClass:""},rejecting:{icon:"⏳",labelKey:"execution.card.rejecting",borderClass:"border-amber-500/40",bgClass:"bg-amber-500/5",badgeClass:"bg-amber-500/15 text-amber-600",textClass:""},in_progress:{icon:"▶",labelKey:"execution.card.inProgress",borderClass:"border-blue-500/40",bgClass:"bg-blue-500/5",badgeClass:"bg-blue-500/15 text-blue-500",textClass:"text-blue-500"},completed:{icon:"✅",labelKey:"execution.card.completed",borderClass:"border-green-500/30",bgClass:"bg-green-500/5",badgeClass:"bg-green-500/15 text-green-500",textClass:"text-green-500"},review:{icon:"👀",labelKey:"execution.card.inReview",borderClass:"border-purple-500/40",bgClass:"bg-purple-500/5",badgeClass:"bg-purple-500/15 text-purple-500",textClass:"text-purple-500"},blocked:{icon:"🚫",labelKey:"execution.card.blocked",borderClass:"border-orange-500/40",bgClass:"bg-orange-500/5",badgeClass:"bg-orange-500/15 text-orange-500",textClass:"text-orange-500"},failed:{icon:"❌",labelKey:"execution.card.failed",borderClass:"border-red-500/30",bgClass:"bg-red-500/5",badgeClass:"bg-red-500/15 text-red-500",textClass:"text-red-500"},cancelled:{icon:"⊘",labelKey:"execution.card.cancelled",borderClass:"border-border-default/40",bgClass:"bg-surface-secondary/30",badgeClass:"bg-surface-elevated text-fg-tertiary",textClass:"text-fg-tertiary"},archived:{icon:"📦",labelKey:"execution.card.archived",borderClass:"border-border-default/40",bgClass:"bg-surface-secondary/30",badgeClass:"bg-surface-elevated text-fg-tertiary",textClass:"text-fg-tertiary"},loading:{icon:"⏳",labelKey:"execution.card.loading",borderClass:"border-border-default/40",bgClass:"bg-surface-secondary/30",badgeClass:"bg-surface-elevated text-fg-tertiary",textClass:""}};function US({info:e}){const{t}=ot("common"),[n,a]=k.useState("loading"),[s,l]=k.useState(null);k.useEffect(()=>{let x=!1;return Ae.tasks.get(e.taskId).then(({task:y})=>{x||a(tk[y.status]??"pending")}).catch(()=>{x||a("pending")}),()=>{x=!0}},[e.taskId]),k.useEffect(()=>Ir.on("task:update",x=>{const y=x.payload;y.taskId===e.taskId&&y.status&&a(tk[y.status]??"pending")}),[e.taskId]);const c=()=>{window.dispatchEvent(new CustomEvent("markus:mark-read-by-ref",{detail:{taskId:e.taskId}}))},d=async()=>{l(null),a("approving");try{await Ae.tasks.approve(e.taskId),a("in_progress"),c()}catch{a("pending")}},m=async()=>{l(null),a("rejecting");try{await Ae.tasks.reject(e.taskId),a("cancelled"),c()}catch{a("pending")}},p=n==="pending"||n==="approving"||n==="rejecting",h=nk[n]??nk.loading,g=()=>at.navigate(de.WORK,{openTask:e.taskId});return i.jsxs("div",{className:`my-2 rounded-lg border ${h.borderClass} ${h.bgClass} p-3 max-w-md transition-colors`,children:[i.jsxs("div",{className:"flex items-start gap-2 mb-1 cursor-pointer group",role:"button",tabIndex:0,onClick:g,onKeyDown:x=>x.key==="Enter"&&g(),children:[i.jsx("span",{className:"text-sm mt-0.5",children:h.icon}),i.jsxs("div",{className:"flex-1 min-w-0",children:[i.jsxs("div",{className:"flex items-center gap-1.5",children:[i.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded font-medium ${h.badgeClass}`,children:t("execution.taskBadge")}),!p&&n!=="loading"&&i.jsx("span",{className:`text-[10px] font-medium ${h.textClass}`,children:t(h.labelKey)})]}),i.jsx("div",{className:`text-sm font-medium truncate mt-1 group-hover:underline ${!p&&n!=="loading"?"text-fg-secondary":"text-fg-primary"}`,children:e.title}),e.description&&i.jsx("div",{className:"text-xs text-fg-secondary mt-0.5 line-clamp-2",children:e.description}),i.jsxs("div",{className:"flex items-center gap-2 mt-1.5 text-[11px] text-fg-tertiary",children:[e.priority&&i.jsx("span",{className:FS[e.priority]??"text-fg-tertiary",children:t(`priority.${e.priority}`,{defaultValue:e.priority})}),i.jsx("span",{className:"opacity-50",children:t("execution.idPrefix",{id:e.taskId.slice(0,8)})})]})]})]}),p&&i.jsxs("div",{className:"flex items-center gap-2 mt-2 pt-2 border-t border-border-default/30",children:[i.jsx("button",{onClick:()=>l("approve"),disabled:n!=="pending",className:"flex-1 px-3 py-1.5 text-xs font-medium rounded-md bg-green-600 hover:bg-green-500 text-white transition-colors disabled:opacity-50 disabled:cursor-not-allowed",children:t(n==="approving"?"execution.card.approving":"approve")}),i.jsx("button",{onClick:()=>l("reject"),disabled:n!=="pending",className:"flex-1 px-3 py-1.5 text-xs font-medium rounded-md bg-surface-elevated hover:bg-surface-overlay text-fg-secondary border border-border-default transition-colors disabled:opacity-50 disabled:cursor-not-allowed",children:t(n==="rejecting"?"execution.card.rejecting":"reject")})]}),s==="approve"&&i.jsx(ba,{variant:"primary",title:t("execution.card.confirmApproveTaskTitle"),message:t("execution.card.confirmApproveTaskMessage",{title:e.title}),confirmLabel:t("approve"),onConfirm:()=>{d()},onCancel:()=>l(null)}),s==="reject"&&i.jsx(ba,{variant:"danger",title:t("execution.card.confirmRejectTaskTitle"),message:t("execution.card.confirmRejectTaskMessage",{title:e.title}),confirmLabel:t("reject"),onConfirm:()=>{m()},onCancel:()=>l(null)})]})}const ak={pending:"pending",in_progress:"in_progress",completed:"completed",rejected:"rejected",cancelled:"cancelled",archived:"archived"},rk={pending:{icon:"📋",labelKey:"execution.card.pendingApproval",borderClass:"border-amber-500/40",bgClass:"bg-amber-500/5",badgeClass:"bg-amber-500/15 text-amber-600",textClass:""},approving:{icon:"⏳",labelKey:"execution.card.approving",borderClass:"border-amber-500/40",bgClass:"bg-amber-500/5",badgeClass:"bg-amber-500/15 text-amber-600",textClass:""},rejecting:{icon:"⏳",labelKey:"execution.card.rejecting",borderClass:"border-amber-500/40",bgClass:"bg-amber-500/5",badgeClass:"bg-amber-500/15 text-amber-600",textClass:""},in_progress:{icon:"▶",labelKey:"execution.card.inProgress",borderClass:"border-blue-500/40",bgClass:"bg-blue-500/5",badgeClass:"bg-blue-500/15 text-blue-500",textClass:"text-blue-500"},completed:{icon:"✅",labelKey:"execution.card.completed",borderClass:"border-green-500/30",bgClass:"bg-green-500/5",badgeClass:"bg-green-500/15 text-green-500",textClass:"text-green-500"},rejected:{icon:"❌",labelKey:"execution.card.rejected",borderClass:"border-red-500/30",bgClass:"bg-red-500/5",badgeClass:"bg-red-500/15 text-red-500",textClass:"text-red-500"},cancelled:{icon:"⊘",labelKey:"execution.card.cancelled",borderClass:"border-border-default/40",bgClass:"bg-surface-secondary/30",badgeClass:"bg-surface-elevated text-fg-tertiary",textClass:"text-fg-tertiary"},archived:{icon:"📦",labelKey:"execution.card.archived",borderClass:"border-border-default/40",bgClass:"bg-surface-secondary/30",badgeClass:"bg-surface-elevated text-fg-tertiary",textClass:"text-fg-tertiary"},loading:{icon:"⏳",labelKey:"execution.card.loading",borderClass:"border-border-default/40",bgClass:"bg-surface-secondary/30",badgeClass:"bg-surface-elevated text-fg-tertiary",textClass:""}},Mae=["requirement:approved","requirement:rejected","requirement:updated","requirement:completed","requirement:cancelled","requirement:resubmitted"];function GS({info:e}){const{t}=ot("common"),[n,a]=k.useState("loading"),[s,l]=k.useState(""),[c,d]=k.useState(!1),[m,p]=k.useState(null);k.useEffect(()=>{let S=!1;return Ae.requirements.get(e.requirementId).then(({requirement:E})=>{S||a(ak[E.status]??"pending")}).catch(()=>{S||a("pending")}),()=>{S=!0}},[e.requirementId]),k.useEffect(()=>{const S=Mae.map(E=>Ir.on(E,_=>{const L=_.payload;L.id===e.requirementId&&L.status&&a(ak[L.status]??"pending")}));return()=>S.forEach(E=>E())},[e.requirementId]);const h=()=>{window.dispatchEvent(new CustomEvent("markus:mark-read-by-ref",{detail:{requirementId:e.requirementId}}))},g=async()=>{p(null),a("approving");try{await Ae.requirements.approve(e.requirementId),a("in_progress"),h()}catch{a("pending")}},x=async()=>{if(s.trim()){p(null),a("rejecting");try{await Ae.requirements.reject(e.requirementId,s.trim()),a("rejected"),h()}catch{a("pending")}}},y=()=>{if(!c){d(!0);return}s.trim()&&p("reject")},w=n==="pending"||n==="approving"||n==="rejecting",T=rk[n]??rk.loading,C=()=>at.navigate(de.WORK,{openRequirement:e.requirementId});return i.jsxs("div",{className:`my-2 rounded-lg border ${T.borderClass} ${T.bgClass} p-3 max-w-md transition-colors`,children:[i.jsxs("div",{className:"flex items-start gap-2 mb-1 cursor-pointer group",role:"button",tabIndex:0,onClick:C,onKeyDown:S=>S.key==="Enter"&&C(),children:[i.jsx("span",{className:"text-sm mt-0.5",children:T.icon}),i.jsxs("div",{className:"flex-1 min-w-0",children:[i.jsxs("div",{className:"flex items-center gap-1.5",children:[i.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded font-medium ${T.badgeClass}`,children:t("execution.reqBadge")}),!w&&n!=="loading"&&i.jsx("span",{className:`text-[10px] font-medium ${T.textClass}`,children:t(T.labelKey)})]}),i.jsx("div",{className:`text-sm font-medium truncate mt-1 group-hover:underline ${!w&&n!=="loading"?"text-fg-secondary":"text-fg-primary"}`,children:e.title}),e.description&&i.jsx("div",{className:"text-xs text-fg-secondary mt-0.5 line-clamp-3",children:e.description}),i.jsxs("div",{className:"flex items-center gap-2 mt-1.5 text-[11px] text-fg-tertiary",children:[e.priority&&i.jsx("span",{className:FS[e.priority]??"text-fg-tertiary",children:t(`priority.${e.priority}`,{defaultValue:e.priority})}),i.jsx("span",{className:"opacity-50",children:t("execution.idPrefix",{id:e.requirementId.slice(0,8)})})]})]})]}),w&&i.jsxs("div",{className:"mt-2 pt-2 border-t border-border-default/30 space-y-2",children:[c&&i.jsx("input",{type:"text",value:s,onChange:S=>l(S.target.value),placeholder:t("execution.rejectionReasonPlaceholder"),className:"w-full px-2 py-1.5 text-xs rounded-md bg-surface-secondary border border-border-default text-fg-primary placeholder:text-fg-tertiary focus:outline-none focus:border-brand-500",onKeyDown:S=>S.key==="Enter"&&y(),autoFocus:!0}),i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("button",{onClick:()=>p("approve"),disabled:n!=="pending",className:"flex-1 px-3 py-1.5 text-xs font-medium rounded-md bg-green-600 hover:bg-green-500 text-white transition-colors disabled:opacity-50 disabled:cursor-not-allowed",children:t(n==="approving"?"execution.card.approving":"approve")}),i.jsx("button",{onClick:y,disabled:n!=="pending"||c&&!s.trim(),className:"flex-1 px-3 py-1.5 text-xs font-medium rounded-md bg-surface-elevated hover:bg-surface-overlay text-fg-secondary border border-border-default transition-colors disabled:opacity-50 disabled:cursor-not-allowed",children:t(n==="rejecting"?"execution.card.rejecting":"reject")})]})]}),m==="approve"&&i.jsx(ba,{variant:"primary",title:t("execution.card.confirmApproveReqTitle"),message:t("execution.card.confirmApproveReqMessage",{title:e.title}),confirmLabel:t("approve"),onConfirm:()=>{g()},onCancel:()=>p(null)}),m==="reject"&&i.jsx(ba,{variant:"danger",title:t("execution.card.confirmRejectReqTitle"),message:t("execution.card.confirmRejectReqMessage",{title:e.title}),confirmLabel:t("reject"),onConfirm:()=>{x()},onCancel:()=>p(null)})]})}const _ae={"claude-code":{label:"Claude Code",badgeClass:"bg-orange-500/15 text-orange-500"},codex:{label:"Codex",badgeClass:"bg-emerald-500/15 text-emerald-500"},"cursor-agent":{label:"Cursor",badgeClass:"bg-blue-500/15 text-blue-500"}};function Rae({session:e,info:t,onClose:n}){const a=t.args&&typeof t.args=="object"&&!Array.isArray(t.args)?t.args:{},s=e.status==="running"||e.status==="created"||e.status==="context_injected",l=e.status==="failed"||e.status==="timeout",c=e.status==="completed",d=_ae[e.tool]??{label:e.tool,badgeClass:"bg-surface-elevated text-fg-tertiary"},[m,p]=k.useState(!1);k.useEffect(()=>{const y=w=>{w.key==="Escape"&&n()};return document.addEventListener("keydown",y),()=>document.removeEventListener("keydown",y)},[n]);const h=e.cost?.durationMs??t.durationMs,g=typeof a.model=="string"?a.model:void 0,x=typeof a.mode=="string"?a.mode:void 0;return i.jsxs("div",{className:"fixed inset-0 z-[60] flex items-center justify-center",onClick:n,children:[i.jsx("div",{className:"absolute inset-0 bg-black/60"}),i.jsxs("div",{className:"relative bg-surface-secondary border border-border-default rounded-xl shadow-2xl w-[640px] max-w-[92vw] max-h-[80vh] overflow-hidden flex flex-col",onClick:y=>y.stopPropagation(),children:[i.jsxs("div",{className:"px-5 py-3 border-b border-border-default flex items-center justify-between shrink-0",children:[i.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[i.jsx("span",{className:`text-xs px-2 py-0.5 rounded font-medium ${d.badgeClass}`,children:d.label}),i.jsx("span",{className:`text-xs px-1.5 py-0.5 rounded ${s?"bg-brand-500/15 text-brand-500":c?"bg-green-500/15 text-green-600":"bg-surface-overlay text-fg-tertiary"}`,children:s?"Running":c?"Completed":l?"Failed":e.status}),h!=null&&i.jsx("span",{className:"text-xs text-fg-tertiary tabular-nums",children:$s(h)}),g&&i.jsx("span",{className:"text-[10px] bg-surface-elevated px-1.5 py-0.5 rounded text-fg-tertiary font-mono",children:g}),x&&i.jsx("span",{className:"text-[10px] bg-surface-elevated px-1.5 py-0.5 rounded text-fg-tertiary",children:x})]}),i.jsx("button",{onClick:n,className:"text-fg-tertiary hover:text-fg-secondary text-lg leading-none ml-2",children:"×"})]}),i.jsxs("div",{className:"flex-1 overflow-y-auto px-5 py-4 space-y-4",children:[i.jsxs("div",{children:[i.jsx("h4",{className:"text-[10px] font-semibold text-fg-tertiary uppercase tracking-wider mb-2",children:"Prompt"}),i.jsx("pre",{className:"text-xs text-fg-secondary bg-surface-elevated/70 rounded-lg px-3 py-2 overflow-x-auto max-h-40 overflow-y-auto whitespace-pre-wrap break-all font-mono",children:e.prompt})]}),Object.keys(a).length>0&&i.jsxs("div",{children:[i.jsx("h4",{className:"text-[10px] font-semibold text-fg-tertiary uppercase tracking-wider mb-2",children:"Input Arguments"}),i.jsx("div",{className:"space-y-1.5",children:Object.entries(a).filter(([y])=>y!=="prompt").map(([y,w])=>i.jsxs("div",{className:"flex items-start gap-2 text-xs",children:[i.jsxs("span",{className:"text-brand-500 font-medium shrink-0 font-mono",children:[y,":"]}),i.jsx("span",{className:"text-fg-secondary font-mono break-all",children:typeof w=="string"?w:JSON.stringify(w)})]},y))})]}),e.result&&!s&&i.jsxs("div",{children:[i.jsx("h4",{className:"text-[10px] font-semibold text-fg-tertiary uppercase tracking-wider mb-2",children:"Result"}),i.jsxs("div",{className:"space-y-2",children:[e.result.summary&&i.jsx("div",{className:"text-xs text-fg-secondary",children:e.result.summary}),e.result.diffStats&&i.jsxs("div",{className:"flex items-center gap-3 text-xs font-mono",children:[i.jsxs("span",{className:"text-fg-tertiary",children:[e.result.diffStats.filesChanged," files changed"]}),i.jsxs("span",{className:"text-green-500",children:["+",e.result.diffStats.additions]}),i.jsxs("span",{className:"text-red-500",children:["-",e.result.diffStats.deletions]})]}),e.result.modifiedFiles&&e.result.modifiedFiles.length>0&&i.jsxs("div",{children:[i.jsx("div",{className:"text-[10px] text-fg-tertiary mb-1",children:"Modified files:"}),i.jsx("div",{className:"bg-surface-elevated/70 rounded-lg px-3 py-2 max-h-32 overflow-y-auto",children:e.result.modifiedFiles.map((y,w)=>i.jsx("div",{className:"text-[11px] text-fg-secondary font-mono truncate",children:y},w))})]}),e.result.error&&i.jsx("pre",{className:"text-xs text-fg-secondary bg-surface-elevated/50 border border-border-default rounded-lg px-3 py-2 overflow-x-auto max-h-60 overflow-y-auto whitespace-pre-wrap break-all font-mono",children:e.result.error})]})]}),e.cost&&(e.cost.inputTokens!=null||e.cost.outputTokens!=null||e.cost.estimatedCostUsd!=null)&&i.jsxs("div",{children:[i.jsx("h4",{className:"text-[10px] font-semibold text-fg-tertiary uppercase tracking-wider mb-2",children:"Cost"}),i.jsxs("div",{className:"flex items-center gap-4 text-xs text-fg-secondary",children:[e.cost.inputTokens!=null&&i.jsxs("span",{children:[e.cost.inputTokens.toLocaleString()," input tokens"]}),e.cost.outputTokens!=null&&i.jsxs("span",{children:[e.cost.outputTokens.toLocaleString()," output tokens"]}),e.cost.estimatedCostUsd!=null&&i.jsxs("span",{className:"font-medium",children:["$",e.cost.estimatedCostUsd.toFixed(4)]}),h!=null&&i.jsx("span",{className:"text-fg-tertiary",children:$s(h)})]})]}),e.result?.rawOutput&&i.jsxs("div",{children:[i.jsxs("button",{type:"button",onClick:()=>p(!m),className:"flex items-center gap-1.5 text-[10px] text-fg-tertiary hover:text-fg-secondary transition-colors",children:[i.jsx("svg",{className:`w-3 h-3 transition-transform ${m?"rotate-90":""}`,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:i.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M9 5l7 7-7 7"})}),i.jsx("span",{className:"font-semibold uppercase tracking-wider",children:"Raw Output"})]}),m&&i.jsx("pre",{className:"mt-2 text-[11px] text-fg-tertiary bg-surface-elevated/70 rounded-lg px-3 py-2 overflow-x-auto max-h-[50vh] overflow-y-auto whitespace-pre-wrap break-all font-mono",children:e.result.rawOutput})]})]})]})]})}function Dae(e){if(e.tool!=="invoke_coding_tool")return null;const t=e.args&&typeof e.args=="object"&&!Array.isArray(e.args)?e.args:{},n=typeof t.tool=="string"?t.tool:"unknown",a=typeof t.prompt=="string"?t.prompt:"",l={running:"running",done:"completed",error:"failed",stopped:"cancelled"}[e.status]??e.status;let c,d;if(e.result)try{const p=JSON.parse(e.result);if(p&&typeof p=="object"){const h=p.result&&typeof p.result=="object"?p.result:p;c={success:h.success??p.success??e.status==="done",summary:h.summary??h.message??p.summary??p.message??"Completed",diffStats:h.diffStats??p.diffStats,modifiedFiles:h.modifiedFiles??p.modifiedFiles,exitCode:h.exitCode??p.exitCode,rawOutput:h.rawOutput??h.output??p.rawOutput??p.output,error:h.error??p.error},h.cost?d=h.cost:p.cost&&(d=p.cost)}}catch{c={success:e.status==="done",summary:e.result.slice(0,500),rawOutput:e.result}}e.durationMs!=null&&(d={...d,durationMs:e.durationMs});let m;if(e.liveOutput&&e.status==="running"){const p=e.liveOutput.trim().split(`
857
+ `)[0]??"",S=C.length>80?C.slice(0,80)+"…":C;return i.jsxs("details",{className:"mb-3 rounded-lg bg-surface-elevated/60 border border-border-default/50 overflow-hidden group/think",children:[i.jsxs("summary",{className:"cursor-pointer select-none px-3 py-2 text-xs text-fg-secondary hover:text-fg-secondary transition-colors flex items-center gap-1.5 min-w-0",children:[i.jsx("svg",{className:"w-3 h-3 shrink-0 transition-transform group-open/think:rotate-90",viewBox:"0 0 20 20",fill:"currentColor",children:i.jsx("path",{fillRule:"evenodd",d:"M7.21 14.77a.75.75 0 01.02-1.06L11.168 10 7.23 6.29a.75.75 0 111.04-1.08l4.5 4.25a.75.75 0 010 1.08l-4.5 4.25a.75.75 0 01-1.06-.02z",clipRule:"evenodd"})}),i.jsx("span",{className:"shrink-0",children:"Thinking"}),i.jsx("span",{className:"truncate text-fg-tertiary ml-1 group-open/think:hidden",children:S})]}),i.jsx("div",{className:"px-3 pb-3 border-t border-border-default/50",children:i.jsx("div",{className:"mt-2 pl-3 border-l-2 border-brand-500/40 text-xs text-fg-secondary leading-relaxed",children:i.jsx(qh,{remarkPlugins:Uw,rehypePlugins:Gw,components:w,urlTransform:fg,children:x(T)})})})]})})(),i.jsx(qh,{remarkPlugins:Uw,rehypePlugins:Gw,components:w,urlTransform:fg,children:y})]})})}),p&&i.jsx(IS,{src:p,onClose:()=>h(null)})]})},(e,t)=>e.content===t.content&&e.className===t.className&&e.basePath===t.basePath&&e.onMentionClick===t.onMentionClick&&hae(e.knownNames,t.knownNames));function hae(e,t){if(e===t)return!0;if(!e||!t||e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(e[n]!==t[n])return!1;return!0}const PS=Object.freeze(Object.defineProperty({__proto__:null,ImagePreviewModal:IS,MarkdownMessage:Ea,chatUrlTransform:fg},Symbol.toStringTag,{value:"Module"})),hg={suppressAdjustUntil:0};function Dc(e=2500){const t=typeof performance<"u"?performance.now():Date.now();hg.suppressAdjustUntil=Math.max(hg.suppressAdjustUntil,t+e)}function ase(){return(typeof performance<"u"?performance.now():Date.now())<hg.suppressAdjustUntil}const Kw={shell_execute:{label:"Running command",icon:"⌨"},list_terminals:{label:"Listing terminals",icon:"⌨"},new_terminal:{label:"Opening terminal",icon:"⌨"},select_terminal:{label:"Selecting terminal",icon:"⌨"},close_terminal:{label:"Closing terminal",icon:"⌨"},read_terminal:{label:"Reading terminal",icon:"⌨"},write_terminal:{label:"Writing terminal",icon:"⌨"},exec_terminal:{label:"Running in terminal",icon:"⌨"},file_read:{label:"Reading file",icon:"📄"},file_write:{label:"Writing file",icon:"✏"},file_edit:{label:"Editing file",icon:"✏"},apply_patch:{label:"Applying patch",icon:"🔀"},list_directory:{label:"Listing directory",icon:"📂"},glob_find:{label:"Finding files",icon:"🔍"},grep_search:{label:"Searching code",icon:"🔍"},web_fetch:{label:"Fetching page",icon:"🌐"},web_search:{label:"Searching web",icon:"🔍"},web_extract:{label:"Extracting content",icon:"📑"},create_task:{label:"Creating task",icon:"📌"},task_create:{label:"Creating task",icon:"📌"},create_subtask:{label:"Adding subtask",icon:"📌"},update_task:{label:"Updating task",icon:"✅"},task_update:{label:"Updating task",icon:"✅"},add_task_note:{label:"Adding note",icon:"📝"},task_add_note:{label:"Adding note",icon:"📝"},task_list:{label:"Listing tasks",icon:"📋"},task_get:{label:"Getting task",icon:"📋"},task_note:{label:"Adding note",icon:"📝"},task_assign:{label:"Assigning task",icon:"👥"},task_submit_review:{label:"Submitting for review",icon:"✅"},task_comment:{label:"Commenting task",icon:"💬"},subtask_create:{label:"Adding subtask",icon:"📌"},subtask_complete:{label:"Completing subtask",icon:"✅"},subtask_cancel:{label:"Cancelling subtask",icon:"🚫"},subtask_list:{label:"Listing subtasks",icon:"📋"},requirement_propose:{label:"Proposing requirement",icon:"📋"},requirement_list:{label:"Listing requirements",icon:"📋"},requirement_get:{label:"Getting requirement",icon:"📋"},requirement_update:{label:"Updating requirement",icon:"📋"},requirement_update_status:{label:"Updating req status",icon:"✅"},requirement_resubmit:{label:"Resubmitting requirement",icon:"📋"},requirement_comment:{label:"Commenting requirement",icon:"💬"},list_projects:{label:"Listing projects",icon:"🗂"},get_project:{label:"Getting project",icon:"🗂"},create_project:{label:"Creating project",icon:"🗂"},update_project:{label:"Updating project",icon:"🗂"},deliverable_create:{label:"Creating deliverable",icon:"📦"},deliverable_search:{label:"Searching deliverables",icon:"🔍"},deliverable_list:{label:"Listing deliverables",icon:"📦"},deliverable_update:{label:"Updating deliverable",icon:"📦"},git_status:{label:"Git status",icon:"🔀"},git_diff:{label:"Git diff",icon:"🔀"},git_log:{label:"Git log",icon:"📜"},git_branch:{label:"Git branch",icon:"🌿"},git_add:{label:"Git add",icon:"➕"},git_commit:{label:"Git commit",icon:"💾"},project_structure:{label:"Project structure",icon:"🗂"},code_stats:{label:"Code stats",icon:"📊"},navigate_page:{label:"Opening page",icon:"🌐"},new_page:{label:"Opening new tab",icon:"🌐"},close_page:{label:"Closing tab",icon:"🌐"},select_page:{label:"Switching tab",icon:"🌐"},list_pages:{label:"Listing tabs",icon:"🌐"},click:{label:"Clicking element",icon:"👆"},hover:{label:"Hovering element",icon:"👆"},fill:{label:"Filling field",icon:"⌨"},fill_form:{label:"Filling form",icon:"⌨"},type_text:{label:"Typing text",icon:"⌨"},press_key:{label:"Pressing key",icon:"⌨"},take_screenshot:{label:"Screenshot",icon:"📸"},take_snapshot:{label:"Page snapshot",icon:"📋"},evaluate_script:{label:"Running script",icon:"⚙"},wait_for:{label:"Waiting",icon:"⏳"},list_console_messages:{label:"Console logs",icon:"🔍"},list_network_requests:{label:"Network requests",icon:"🔍"},lighthouse_audit:{label:"Running audit",icon:"📊"},agent_send_message:{label:"Messaging colleague",icon:"💬"},agent_list_colleagues:{label:"Checking team",icon:"👥"},memory_save:{label:"Saving memory",icon:"💾"},memory_search:{label:"Searching memory",icon:"🔍"},memory_list:{label:"Listing memory",icon:"💾"},memory_update:{label:"Updating memory",icon:"💾"},recall_activity:{label:"Recalling activity",icon:"📜"},notebook_upsert:{label:"Updating notebook",icon:"📝"},kb_search:{label:"Searching knowledge base",icon:"📚"},kb_list:{label:"Listing knowledge base",icon:"📚"},kb_read:{label:"Reading knowledge base",icon:"📚"},notify_user:{label:"Notifying user",icon:"🔔"},request_user_input:{label:"Requesting input",icon:"❓"},request_user_approval:{label:"Requesting approval",icon:"❓"},schedule_wakeup:{label:"Scheduling wakeup",icon:"⏰"},cancel_wakeup:{label:"Cancelling wakeup",icon:"⏰"},set_heartbeat_interval:{label:"Setting heartbeat",icon:"⏱"},discover_tools:{label:"Discovering tools",icon:"🧰"},check_mailbox:{label:"Checking mailbox",icon:"📥"},goal_create:{label:"Creating goal",icon:"🎯"},goal_update:{label:"Updating goal",icon:"🎯"},goal_status:{label:"Goal status",icon:"🎯"},background_exec:{label:"Background command",icon:"⌨"},process:{label:"Managing process",icon:"⚙"},feishu_send_message:{label:"Sending Feishu msg",icon:"✉"},feishu_search_docs:{label:"Searching Feishu",icon:"🔍"},spawn_subagent:{label:"Spawn Subagent",icon:"◎"},spawn_subagents:{label:"Spawn Subagents",icon:"◎"},invoke_coding_tool:{label:"Invoke Coding Tool",icon:"🛠"},coding_tool_apply:{label:"Apply Coding Result",icon:"🔀"},generate_image:{label:"Generating image",icon:"🖼"},text_to_speech:{label:"Generating speech",icon:"🔊"},speech_to_text:{label:"Transcribing audio",icon:"🎙"},generate_video:{label:"Generating video",icon:"🎬"},llm_list_providers:{label:"Listing providers",icon:"⚙"},llm_switch_model:{label:"Switching model",icon:"⚙"},llm_switch_default_provider:{label:"Switching provider",icon:"⚙"},llm_add_provider:{label:"Adding provider",icon:"⚙"},llm_edit_provider:{label:"Editing provider",icon:"⚙"},llm_add_model:{label:"Adding model",icon:"⚙"},llm_get_capability_routing:{label:"Checking capability routing",icon:"⚙"},llm_set_capability_routing:{label:"Setting capability routing",icon:"⚙"},team_list:{label:"Listing teams",icon:"👥"},team_status:{label:"Team status",icon:"👥"},team_start:{label:"Starting team",icon:"👥"},team_stop:{label:"Stopping team",icon:"👥"},team_update:{label:"Updating team",icon:"👥"},agent_start:{label:"Starting agent",icon:"◎"},agent_stop:{label:"Stopping agent",icon:"◎"},agent_update:{label:"Updating agent",icon:"◎"},agent_delegate_task:{label:"Delegating task",icon:"📌"},agent_broadcast_status:{label:"Broadcasting status",icon:"📣"},agent_create_group_chat:{label:"Creating group chat",icon:"💬"},agent_list_group_chats:{label:"Listing group chats",icon:"💬"},agent_send_group_message:{label:"Sending group message",icon:"💬"},delete_project:{label:"Deleting project",icon:"🗂"},project_stats:{label:"Project stats",icon:"📊"},hub_search:{label:"Searching Hub",icon:"🔍"},hub_install:{label:"Installing from Hub",icon:"📦"},package_list:{label:"Listing packages",icon:"📦"},package_install:{label:"Installing package",icon:"📦"},memory_delete:{label:"Deleting memory",icon:"💾"},memory_update_longterm:{label:"Updating long-term memory",icon:"💾"},notebook_clear:{label:"Clearing notebook",icon:"📝"},notebook_read:{label:"Reading notebook",icon:"📝"},recall_context:{label:"Recalling context",icon:"📜"},defer_mailbox_item:{label:"Deferring mailbox item",icon:"📥"},drop_mailbox_item:{label:"Dropping mailbox item",icon:"📥"},prioritize_mailbox_item:{label:"Prioritizing mailbox",icon:"📥"},delegate_message:{label:"Delegating message",icon:"💬"},task_board_health:{label:"Checking task board",icon:"📋"},task_check_duplicates:{label:"Checking duplicates",icon:"📋"},task_cleanup_duplicates:{label:"Cleaning duplicates",icon:"📋"},workflow_list:{label:"Listing workflows",icon:"🔄"},workflow_create:{label:"Creating workflow",icon:"🔄"},workflow_update:{label:"Updating workflow",icon:"🔄"},workflow_delete:{label:"Deleting workflow",icon:"🔄"},workflow_run:{label:"Running workflow",icon:"🔄"},workflow_status:{label:"Workflow status",icon:"🔄"},workflow_cancel:{label:"Cancelling workflow",icon:"🔄"},open_page:{label:"Opening page",icon:"🌐"},resize_page:{label:"Resizing page",icon:"🌐"},drag:{label:"Dragging element",icon:"👆"},upload_file:{label:"Uploading file",icon:"📎"},emulate:{label:"Emulating device",icon:"📱"},handle_dialog:{label:"Handling dialog",icon:"💬"},get_console_message:{label:"Console message",icon:"🔍"},get_network_request:{label:"Network request",icon:"🔍"}},Vw={shell_execute:"square-terminal",background_exec:"square-terminal",process:"settings",list_terminals:"square-terminal",new_terminal:"square-terminal",select_terminal:"square-terminal",close_terminal:"square-terminal",read_terminal:"square-terminal",write_terminal:"square-terminal",exec_terminal:"square-terminal",file_read:"file-text",file_write:"edit",file_edit:"edit",apply_patch:"git-branch",list_directory:"folder",glob_find:"search",grep_search:"search",web_fetch:"globe",web_search:"search",web_extract:"file-text",create_task:"clipboard",task_create:"clipboard",create_subtask:"clipboard",update_task:"check-circle",task_update:"check-circle",add_task_note:"edit",task_add_note:"edit",task_note:"edit",task_list:"clipboard",task_get:"clipboard",task_assign:"users",task_submit_review:"check-circle",task_comment:"message-square",subtask_create:"clipboard",subtask_complete:"check-circle",subtask_cancel:"alert-circle",subtask_list:"clipboard",requirement_propose:"clipboard",requirement_list:"clipboard",requirement_get:"clipboard",requirement_update:"clipboard",requirement_update_status:"check-circle",requirement_resubmit:"clipboard",requirement_comment:"message-square",list_projects:"layers",get_project:"layers",create_project:"layers",update_project:"layers",deliverable_create:"package",deliverable_search:"search",deliverable_list:"package",deliverable_update:"edit",git_status:"git-branch",git_diff:"git-branch",git_log:"book-open",git_branch:"git-branch",git_add:"git-branch",git_commit:"save",project_structure:"layers",code_stats:"bar-chart",navigate_page:"globe",new_page:"globe",close_page:"globe",select_page:"globe",list_pages:"globe",click:"target",hover:"target",fill:"terminal",fill_form:"terminal",type_text:"terminal",press_key:"terminal",take_screenshot:"camera",take_snapshot:"camera",evaluate_script:"code",wait_for:"clock",list_console_messages:"terminal",list_network_requests:"globe",lighthouse_audit:"bar-chart",agent_send_message:"message-square",agent_list_colleagues:"users",memory_save:"database",memory_search:"search",memory_list:"database",memory_update:"database",recall_activity:"book-open",notebook_upsert:"edit",kb_search:"book-open",kb_list:"book-open",kb_read:"book-open",notify_user:"megaphone",request_user_input:"message-square",request_user_approval:"check-circle",schedule_wakeup:"clock",cancel_wakeup:"clock",set_heartbeat_interval:"clock",discover_tools:"wrench",check_mailbox:"message-square",goal_create:"target",goal_update:"target",goal_status:"target",feishu_send_message:"message-square",feishu_search_docs:"search",spawn_subagent:"bot",spawn_subagents:"bot",invoke_coding_tool:"wrench",coding_tool_apply:"git-branch",generate_image:"camera",text_to_speech:"headphones",speech_to_text:"headphones",generate_video:"camera",llm_list_providers:"settings",llm_switch_model:"settings",llm_switch_default_provider:"settings",llm_add_provider:"settings",llm_edit_provider:"settings",llm_add_model:"settings",llm_get_capability_routing:"settings",llm_set_capability_routing:"settings",team_list:"users",team_status:"users",team_start:"users",team_stop:"users",team_update:"users",agent_start:"bot",agent_stop:"bot",agent_update:"bot",agent_delegate_task:"clipboard",agent_broadcast_status:"megaphone",agent_create_group_chat:"message-square",agent_list_group_chats:"message-square",agent_send_group_message:"message-square",delete_project:"layers",project_stats:"bar-chart",hub_search:"search",hub_install:"package",package_list:"package",package_install:"package",memory_delete:"database",memory_update_longterm:"database",notebook_clear:"edit",notebook_read:"edit",recall_context:"book-open",defer_mailbox_item:"message-square",drop_mailbox_item:"message-square",prioritize_mailbox_item:"message-square",delegate_message:"message-square",task_board_health:"clipboard",task_check_duplicates:"clipboard",task_cleanup_duplicates:"clipboard",workflow_list:"git-branch",workflow_create:"git-branch",workflow_update:"git-branch",workflow_delete:"git-branch",workflow_run:"git-branch",workflow_status:"git-branch",workflow_cancel:"git-branch",open_page:"globe",resize_page:"globe",drag:"target",upload_file:"file-text",emulate:"settings",handle_dialog:"message-square",get_console_message:"terminal",get_network_request:"globe"};function zs(e){const t=e.includes("__")?e.split("__").pop():e,n=Kw[t]??Kw[e],a=Vw[t]??Vw[e]??"settings";return n?{...n,iconName:a,key:t}:{label:t.replace(/_/g," ").replace(/\b\w/g,s=>s.toUpperCase()),icon:"⚙",iconName:a,key:t}}function $s(e){return e==null?"":e<1e3?`${e}ms`:`${(e/1e3).toFixed(1)}s`}function gae(e){const t=new Date(e);if(isNaN(t.getTime()))return e;const n=String(t.getMonth()+1).padStart(2,"0"),a=String(t.getDate()).padStart(2,"0"),s=String(t.getHours()).padStart(2,"0"),l=String(t.getMinutes()).padStart(2,"0"),c=String(t.getSeconds()).padStart(2,"0");return`${n}-${a} ${s}:${l}:${c}`}function gg(e,t){return e.length<=t?e:e.slice(0,t)+"…"}function Ww(e){try{const t=JSON.parse(e);return JSON.stringify(t,null,2)}catch{return e}}function zS(e){return!e||typeof e!="object"?[]:Object.entries(e).filter(([,n])=>n!=null).map(([n,a])=>({key:n,value:typeof a=="string"?a:JSON.stringify(a,null,2)}))}function bae(e){if(e.tool!=="shell_execute"||!e.args||typeof e.args!="object")return null;const t=e.args.command;return typeof t=="string"?t:null}function rse(e,t){const n=new Map;let a=null;for(const s of e)if(s.type==="tool_start"&&(s.content==="spawn_subagent"||s.content==="spawn_subagents"))a=s.seq,n.set(s.seq,[]);else if(s.type==="tool_end"&&(s.content==="spawn_subagent"||s.content==="spawn_subagents")){if(a!==null){const l=n.get(a);l&&n.set(s.seq,l)}a=null}else if(a!==null&&s.type.startsWith("subagent_")){const l=s.type.replace("subagent_",""),c=s.metadata;n.get(a)?.push({eventType:l,content:s.content,metadata:c})}return t.map(s=>{if(s.type!=="tool")return s;const l=s.key;if(!l)return s;const c=l.replace(/^(?:t[se]_|e[se]_)/,""),d=parseInt(c,10);if(isNaN(d))return s;const m=n.get(d);return!m||m.length===0?s:{...s,info:{...s.info,subagentLogs:m}}})}function bg(e){const t=new Set;for(let n=0;n<e.length;n++){const a=e[n];if(a.type==="tool"&&(a.info.status==="done"||a.info.status==="error"))for(let s=n-1;s>=0;s--){const l=e[s];if(l.type==="tool"&&l.info.status==="running"&&l.info.tool===a.info.tool&&!t.has(s)){t.add(s);break}}}return e.filter((n,a)=>!t.has(a))}function gb(e){const t=gae(e.createdAt),n=e.createdAt,a=e.metadata;switch(e.type){case"text":return a?.isThinking?{type:"thinking",content:e.content,time:t,timestamp:n}:{type:"text",content:e.content,time:t,timestamp:n};case"status":{const s=a?.action;return s&&["chat","chat_stream","task_execution","respond_in_session"].includes(s)?null:{type:"status",content:e.content,time:t,timestamp:n}}case"error":return{type:"error",content:e.content,time:t,timestamp:n};case"tool_start":return{type:"tool",time:t,timestamp:n,key:`es_${e.seq}`,info:{tool:e.content,status:"running",args:a?.arguments,subagentLogs:a?.subagentLogs}};case"tool_end":return{type:"tool",time:t,timestamp:n,key:`ee_${e.seq}`,info:{tool:e.content,status:a?.success===!1?"error":"done",args:a?.arguments,result:a?.result,error:a?.error,durationMs:a?.durationMs,subagentLogs:a?.subagentLogs}};default:return null}}function BS(e,t){if(e!=="task_create"&&e!=="create_task"||!t)return null;try{const n=JSON.parse(t);if(!n.task)return null;const a=n.task;return{taskId:a.id,title:a.title,description:a.description,assignedAgentId:a.assignedAgentId,priority:a.priority}}catch{return null}}function HS(e,t){if(e!=="requirement_propose"||!t)return null;try{const n=JSON.parse(t);if(n.status!=="success"||!n.requirement)return null;const a=n.requirement;return a.status!=="pending"?null:{requirementId:a.id,title:a.title,description:a.description,priority:a.priority}}catch{return null}}const $S={code:i.jsxs(i.Fragment,{children:[i.jsx("polyline",{points:"16 18 22 12 16 6"}),i.jsx("polyline",{points:"8 6 2 12 8 18"})]}),search:i.jsxs(i.Fragment,{children:[i.jsx("circle",{cx:"11",cy:"11",r:"8"}),i.jsx("path",{d:"m21 21-4.3-4.3"})]}),clipboard:i.jsxs(i.Fragment,{children:[i.jsx("rect",{width:"8",height:"4",x:"8",y:"2",rx:"1",ry:"1"}),i.jsx("path",{d:"M16 4h2a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2h2"})]}),"check-circle":i.jsxs(i.Fragment,{children:[i.jsx("circle",{cx:"12",cy:"12",r:"10"}),i.jsx("path",{d:"m9 12 2 2 4-4"})]}),server:i.jsxs(i.Fragment,{children:[i.jsx("rect",{width:"20",height:"8",x:"2",y:"2",rx:"2",ry:"2"}),i.jsx("rect",{width:"20",height:"8",x:"2",y:"14",rx:"2",ry:"2"}),i.jsx("line",{x1:"6",x2:"6.01",y1:"6",y2:"6"}),i.jsx("line",{x1:"6",x2:"6.01",y1:"18",y2:"18"})]}),"file-text":i.jsxs(i.Fragment,{children:[i.jsx("path",{d:"M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z"}),i.jsx("path",{d:"M14 2v4a2 2 0 0 0 2 2h4"}),i.jsx("path",{d:"M10 9H8"}),i.jsx("path",{d:"M16 13H8"}),i.jsx("path",{d:"M16 17H8"})]}),"book-open":i.jsxs(i.Fragment,{children:[i.jsx("path",{d:"M12 7v14"}),i.jsx("path",{d:"M3 18a1 1 0 0 1-1-1V4a1 1 0 0 1 1-1h5a4 4 0 0 1 4 4 4 4 0 0 1 4-4h5a1 1 0 0 1 1 1v13a1 1 0 0 1-1 1h-6a3 3 0 0 0-3 3 3 3 0 0 0-3-3z"})]}),users:i.jsxs(i.Fragment,{children:[i.jsx("path",{d:"M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2"}),i.jsx("circle",{cx:"9",cy:"7",r:"4"}),i.jsx("path",{d:"M22 21v-2a4 4 0 0 0-3-3.87"}),i.jsx("path",{d:"M16 3.13a4 4 0 0 1 0 7.75"})]}),"dollar-sign":i.jsxs(i.Fragment,{children:[i.jsx("line",{x1:"12",x2:"12",y1:"2",y2:"22"}),i.jsx("path",{d:"M17 5H9.5a3.5 3.5 0 0 0 0 7h5a3.5 3.5 0 0 1 0 7H6"})]}),megaphone:i.jsxs(i.Fragment,{children:[i.jsx("path",{d:"m3 11 18-5v12L3 14v-3z"}),i.jsx("path",{d:"M11.6 16.8a3 3 0 1 1-5.8-1.6"})]}),edit:i.jsxs(i.Fragment,{children:[i.jsx("path",{d:"M12 20h9"}),i.jsx("path",{d:"M16.5 3.5a2.121 2.121 0 0 1 3 3L7 19l-4 1 1-4Z"})]}),headphones:i.jsx(i.Fragment,{children:i.jsx("path",{d:"M3 14h3a2 2 0 0 1 2 2v3a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-5a9 9 0 0 1 18 0v5a2 2 0 0 1-2 2h-1a2 2 0 0 1-2-2v-3a2 2 0 0 1 2-2h3"})}),settings:i.jsxs(i.Fragment,{children:[i.jsx("path",{d:"M12.22 2h-.44a2 2 0 0 0-2 2v.18a2 2 0 0 1-1 1.73l-.43.25a2 2 0 0 1-2 0l-.15-.08a2 2 0 0 0-2.73.73l-.22.38a2 2 0 0 0 .73 2.73l.15.1a2 2 0 0 1 1 1.72v.51a2 2 0 0 1-1 1.74l-.15.09a2 2 0 0 0-.73 2.73l.22.38a2 2 0 0 0 2.73.73l.15-.08a2 2 0 0 1 2 0l.43.25a2 2 0 0 1 1 1.73V20a2 2 0 0 0 2 2h.44a2 2 0 0 0 2-2v-.18a2 2 0 0 1 1-1.73l.43-.25a2 2 0 0 1 2 0l.15.08a2 2 0 0 0 2.73-.73l.22-.39a2 2 0 0 0-.73-2.73l-.15-.08a2 2 0 0 1-1-1.74v-.5a2 2 0 0 1 1-1.74l.15-.09a2 2 0 0 0 .73-2.73l-.22-.38a2 2 0 0 0-2.73-.73l-.15.08a2 2 0 0 1-2 0l-.43-.25a2 2 0 0 1-1-1.73V4a2 2 0 0 0-2-2z"}),i.jsx("circle",{cx:"12",cy:"12",r:"3"})]}),target:i.jsxs(i.Fragment,{children:[i.jsx("circle",{cx:"12",cy:"12",r:"10"}),i.jsx("circle",{cx:"12",cy:"12",r:"6"}),i.jsx("circle",{cx:"12",cy:"12",r:"2"})]}),zap:i.jsx(i.Fragment,{children:i.jsx("polygon",{points:"13 2 3 14 12 14 11 22 21 10 12 10 13 2"})}),terminal:i.jsxs(i.Fragment,{children:[i.jsx("polyline",{points:"4 17 10 11 4 5"}),i.jsx("line",{x1:"12",x2:"20",y1:"19",y2:"19"})]}),sparkles:i.jsxs(i.Fragment,{children:[i.jsx("path",{d:"M9.937 15.5A2 2 0 0 0 8.5 14.063l-6.135-1.582a.5.5 0 0 1 0-.962L8.5 9.936A2 2 0 0 0 9.937 8.5l1.582-6.135a.5.5 0 0 1 .962 0L14.063 8.5A2 2 0 0 0 15.5 9.937l6.135 1.581a.5.5 0 0 1 0 .964L15.5 14.063a2 2 0 0 0-1.437 1.437l-1.582 6.135a.5.5 0 0 1-.962 0z"}),i.jsx("path",{d:"M20 3v4"}),i.jsx("path",{d:"M22 5h-4"})]}),wrench:i.jsx(i.Fragment,{children:i.jsx("path",{d:"M14.7 6.3a1 1 0 0 0 0 1.4l1.6 1.6a1 1 0 0 0 1.4 0l3.77-3.77a6 6 0 0 1-7.94 7.94l-6.91 6.91a2.12 2.12 0 0 1-3-3l6.91-6.91a6 6 0 0 1 7.94-7.94l-3.76 3.76z"})}),globe:i.jsxs(i.Fragment,{children:[i.jsx("circle",{cx:"12",cy:"12",r:"10"}),i.jsx("path",{d:"M12 2a14.5 14.5 0 0 0 0 20 14.5 14.5 0 0 0 0-20"}),i.jsx("path",{d:"M2 12h20"})]}),link:i.jsxs(i.Fragment,{children:[i.jsx("path",{d:"M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"}),i.jsx("path",{d:"M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"})]}),bot:i.jsxs(i.Fragment,{children:[i.jsx("path",{d:"M12 8V4H8"}),i.jsx("rect",{width:"16",height:"12",x:"4",y:"8",rx:"2"}),i.jsx("path",{d:"M2 14h2"}),i.jsx("path",{d:"M20 14h2"}),i.jsx("path",{d:"M15 13v2"}),i.jsx("path",{d:"M9 13v2"})]}),"message-square":i.jsx(i.Fragment,{children:i.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"})}),newspaper:i.jsxs(i.Fragment,{children:[i.jsx("path",{d:"M4 22h16a2 2 0 0 0 2-2V4a2 2 0 0 0-2-2H8a2 2 0 0 0-2 2v16a2 2 0 0 1-2 2Zm0 0a2 2 0 0 1-2-2v-9c0-1.1.9-2 2-2h2"}),i.jsx("path",{d:"M18 14h-8"}),i.jsx("path",{d:"M15 18h-5"}),i.jsx("path",{d:"M10 6h8v4h-8V6Z"})]}),layers:i.jsxs(i.Fragment,{children:[i.jsx("path",{d:"m12.83 2.18a2 2 0 0 0-1.66 0L2.6 6.08a1 1 0 0 0 0 1.83l8.58 3.91a2 2 0 0 0 1.66 0l8.58-3.9a1 1 0 0 0 0-1.83Z"}),i.jsx("path",{d:"m22 17.65-9.17 4.16a2 2 0 0 1-1.66 0L2 17.65"}),i.jsx("path",{d:"m22 12.65-9.17 4.16a2 2 0 0 1-1.66 0L2 12.65"})]}),"bar-chart":i.jsxs(i.Fragment,{children:[i.jsx("line",{x1:"12",x2:"12",y1:"20",y2:"10"}),i.jsx("line",{x1:"18",x2:"18",y1:"20",y2:"4"}),i.jsx("line",{x1:"6",x2:"6",y1:"20",y2:"16"})]}),folder:i.jsx(i.Fragment,{children:i.jsx("path",{d:"M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z"})}),"git-branch":i.jsxs(i.Fragment,{children:[i.jsx("line",{x1:"6",x2:"6",y1:"3",y2:"15"}),i.jsx("circle",{cx:"18",cy:"6",r:"3"}),i.jsx("circle",{cx:"6",cy:"18",r:"3"}),i.jsx("path",{d:"M18 9a9 9 0 0 1-9 9"})]}),save:i.jsxs(i.Fragment,{children:[i.jsx("path",{d:"M15.2 3a2 2 0 0 1 1.4.6l3.8 3.8a2 2 0 0 1 .6 1.4V19a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2z"}),i.jsx("path",{d:"M17 21v-7a1 1 0 0 0-1-1H8a1 1 0 0 0-1 1v7"}),i.jsx("path",{d:"M7 3v4a1 1 0 0 0 1 1h7"})]}),camera:i.jsxs(i.Fragment,{children:[i.jsx("path",{d:"M14.5 4h-5L7 7H4a2 2 0 0 0-2 2v9a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2V9a2 2 0 0 0-2-2h-3l-2.5-3z"}),i.jsx("circle",{cx:"12",cy:"13",r:"3"})]}),clock:i.jsxs(i.Fragment,{children:[i.jsx("circle",{cx:"12",cy:"12",r:"10"}),i.jsx("polyline",{points:"12 6 12 12 16 14"})]}),database:i.jsxs(i.Fragment,{children:[i.jsx("ellipse",{cx:"12",cy:"5",rx:"9",ry:"3"}),i.jsx("path",{d:"M3 5v14a9 3 0 0 0 18 0V5"}),i.jsx("path",{d:"M3 12a9 3 0 0 0 18 0"})]}),lightbulb:i.jsxs(i.Fragment,{children:[i.jsx("path",{d:"M15 14c.2-1 .7-1.7 1.5-2.5 1-.9 1.5-2.2 1.5-3.5A6 6 0 0 0 6 8c0 1 .2 2.2 1.5 3.5.7.7 1.3 1.5 1.5 2.5"}),i.jsx("path",{d:"M9 18h6"}),i.jsx("path",{d:"M10 22h4"})]}),"alert-circle":i.jsxs(i.Fragment,{children:[i.jsx("circle",{cx:"12",cy:"12",r:"10"}),i.jsx("line",{x1:"12",x2:"12",y1:"8",y2:"12"}),i.jsx("line",{x1:"12",x2:"12.01",y1:"16",y2:"16"})]}),"square-terminal":i.jsxs(i.Fragment,{children:[i.jsx("path",{d:"m7 11 2-2-2-2"}),i.jsx("path",{d:"M11 13h4"}),i.jsx("rect",{width:"18",height:"18",x:"3",y:"3",rx:"2"})]}),package:i.jsxs(i.Fragment,{children:[i.jsx("path",{d:"m7.5 4.27 9 5.15"}),i.jsx("path",{d:"M21 8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16Z"}),i.jsx("path",{d:"m3.3 7 8.7 5 8.7-5"}),i.jsx("path",{d:"M12 22V12"})]})};function yae(e){return!!e&&e in $S}function rl({name:e,size:t=24,className:n=""}){const a=$S[e];return a?i.jsx("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",className:n,"aria-hidden":!0,children:a}):null}const Yw={"coding-tools":"terminal",markitdown:"file-text","markus-admin-cli":"terminal",codex:"code","team-building":"users","claude-code":"code","skill-building":"wrench","workflow-building":"layers","chrome-devtools":"globe","markus-hub-connector":"link","cursor-agent":"bot","agent-building":"bot","feishu-interaction":"message-square","content-publishing":"edit","research-report":"book-open","daily-digest":"newspaper"},Qw={development:"code",开发工具:"code",devops:"server",data:"bar-chart",数据分析:"bar-chart",productivity:"zap",效率提升:"zap",communication:"message-square",通讯协作:"message-square",browser:"globe",内容创作:"edit","AI 智能":"sparkles"};function tm(e,t){const n=(e||"").toLowerCase();return Yw[n]?Yw[n]:t&&Qw[t]?Qw[t]:"layers"}function xae(e){const t=[];for(const n of e)if(n.phase!=="output"){if(n.phase==="start"){const a=`${n.tool}_${n.ts}`;t.push({key:a,tool:n.tool,status:"running"})}else for(let a=t.length-1;a>=0;a--)if(t[a].tool===n.tool&&t[a].status==="running"){t[a]={...t[a],status:n.success===!1?"error":"done"};break}}return t}function qS(){return i.jsxs("svg",{className:"w-3 h-3 animate-spin text-brand-500 shrink-0",viewBox:"0 0 24 24",fill:"none",children:[i.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),i.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"})]})}function vae(){return i.jsx("span",{className:"flex items-center gap-0.5",children:[0,150,300].map(e=>i.jsx("span",{className:"w-1 h-1 rounded-full bg-brand-400 animate-bounce",style:{animationDelay:`${e}ms`,animationDuration:"1s"}},e))})}function Xw({item:e}){const{t}=ot("common"),n=zs(e.tool);return i.jsxs("div",{className:"flex items-center gap-1.5 py-0.5",children:[i.jsx(rl,{name:n.iconName,size:15,className:`shrink-0 ${e.status==="running"?"text-brand-500":e.status==="error"?"text-red-500":"text-green-500"}`}),i.jsxs("span",{className:`text-xs ${e.status==="running"?"activity-text-shimmer":e.status==="error"?"text-fg-tertiary":"text-fg-secondary"}`,children:[t(`execution.tools.${n.key}`,{defaultValue:n.label}),e.status==="running"?"…":""]}),e.status==="running"&&i.jsx(qS,{})]})}function Jw({activities:e,isActive:t,persistent:n}){const{t:a}=ot("common"),s=xae(e),[l,c]=k.useState(!1),d=s.length>0,m=d&&s.every(w=>w.status!=="running");if(n&&m){const w=s.filter(C=>C.status==="error").length,T=s.filter(C=>C.status==="done").length;return i.jsxs("div",{className:"mb-3 border-b border-border-default/50 pb-2",children:[i.jsxs("button",{onClick:()=>c(C=>!C),className:"flex items-center gap-1.5 text-xs text-fg-tertiary hover:text-fg-secondary transition-colors select-none",children:[i.jsx("span",{className:`transition-transform duration-150 ${l?"rotate-90":""}`,children:"▶"}),i.jsx("span",{className:"font-medium",children:a("activity.step",{count:T})}),w>0&&i.jsxs("span",{className:"text-red-500 ml-0.5",children:["· ",a("activity.failed",{count:w})]}),!l&&i.jsxs("span",{className:"ml-1 flex items-center gap-1",children:[s.slice(0,5).map(C=>{const S=zs(C.tool);return i.jsx(rl,{name:S.iconName,size:13,className:`shrink-0 ${C.status==="error"?"text-red-500":"text-green-500"}`},C.key)}),s.length>5&&i.jsxs("span",{className:"text-[10px] text-fg-tertiary",children:["+",s.length-5]})]})]}),l&&i.jsx("div",{className:"mt-2 space-y-0.5",children:s.map((C,S)=>i.jsx(Xw,{item:C,idx:S,total:s.length},C.key))})]})}if(!d)return i.jsxs("div",{className:"flex items-center gap-1.5 text-xs py-0.5",children:[i.jsx("span",{className:"mr-0.5 activity-text-shimmer",children:a("activity.thinking")}),i.jsx(vae,{})]});const p=s.filter(w=>w.status==="error").length;let h=null;for(let w=s.length-1;w>=0;w--)if(s[w].status==="running"){h=s[w];break}const g=s[s.length-1];let x;if(h){const w=zs(h.tool);x=`${a(`execution.tools.${w.key}`,{defaultValue:w.label})}…`}else if(t&&m)x=a("activity.writingResponse");else{const w=zs(g.tool);x=a(`execution.tools.${w.key}`,{defaultValue:w.label})}const y=!!h||t&&m;return i.jsxs("div",{className:"mb-1",children:[i.jsxs("button",{onClick:w=>{w.stopPropagation(),c(T=>!T)},className:"flex items-center gap-1.5 text-xs w-full min-w-0 select-none text-fg-tertiary hover:text-fg-secondary transition-colors",children:[i.jsx("span",{className:`shrink-0 transition-transform duration-150 ${l?"rotate-90":""}`,children:"▶"}),i.jsx("span",{className:`truncate font-medium ${y?"activity-text-shimmer":"text-fg-secondary"}`,children:x}),i.jsxs("span",{className:"shrink-0",children:["· ",a("activity.step",{count:s.length})]}),p>0&&i.jsxs("span",{className:"text-red-500 shrink-0",children:["· ",a("activity.failed",{count:p})]}),y&&i.jsx(qS,{})]}),l&&i.jsx("div",{className:"mt-1 space-y-0.5",children:s.map((w,T)=>i.jsx(Xw,{item:w,idx:T,total:s.length},w.key))})]})}const wae={"claude-code":{label:"Claude Code",icon:"🤖",badgeClass:"bg-orange-500/15 text-orange-500"},codex:{label:"Codex",icon:"⬡",badgeClass:"bg-emerald-500/15 text-emerald-500"},"cursor-agent":{label:"Cursor",icon:"▶",badgeClass:"bg-blue-500/15 text-blue-500"}},Uo=["created","context_injected","running"],kae=new Set(["completed","failed","cancelled","timeout"]),Zw={created:"Created",context_injected:"Context injected",running:"Running",completed:"Completed",failed:"Failed",cancelled:"Cancelled",timeout:"Timed out"};function Sae(e){return wae[e]??{label:e.replace(/-/g," ").replace(/\b\w/g,t=>t.toUpperCase()),icon:"⚙",badgeClass:"bg-surface-elevated text-fg-tertiary"}}function Cae(e,t){if(e.cost?.durationMs!=null)return e.cost.durationMs;const n=e.startedAt??e.createdAt,a=new Date(n).getTime();if(!Number.isNaN(a)){if(e.completedAt){const s=new Date(e.completedAt).getTime();return Number.isNaN(s)?void 0:Math.max(0,s-a)}if(e.status==="running"||e.status==="context_injected")return Math.max(0,t-a)}}function Aae(e){if(e==="completed"||kae.has(e))return Uo.length;const t=Uo.indexOf(e);return t>=0?t:0}function Tae({session:e,className:t}){const n=Sae(e.tool),[a,s]=k.useState(!1),[l,c]=k.useState(()=>Date.now()),d=e.status==="running"||e.status==="context_injected"||e.status==="created",m=e.status==="failed"||e.status==="timeout"||e.result?.success===!1,p=e.status==="completed"||e.result?.success===!0;k.useEffect(()=>{if(!d)return;const w=setInterval(()=>c(Date.now()),1e3);return()=>clearInterval(w)},[d]);const h=k.useMemo(()=>Cae(e,l),[e,l]),g=Aae(e.status),x=e.result?.rawOutput??(p||m?e.result?.summary:void 0),y=d?"border-brand-500/40 bg-brand-500/5":m?"border-red-500/30 bg-red-500/5":p?"border-green-500/30 bg-green-500/5":"border-border-default bg-surface-secondary/30";return i.jsxs("div",{className:`my-2 rounded-lg border ${y} p-3 max-w-2xl transition-colors ${t??""}`,children:[i.jsxs("div",{className:"flex items-start gap-2",children:[i.jsx("span",{className:"text-sm mt-0.5",children:n.icon}),i.jsxs("div",{className:"flex-1 min-w-0",children:[i.jsxs("div",{className:"flex items-center gap-1.5 flex-wrap",children:[i.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded font-medium ${n.badgeClass}`,children:n.label}),i.jsx("span",{className:`text-[10px] font-medium ${d?"text-brand-500":m?"text-red-500":p?"text-green-500":"text-fg-tertiary"}`,children:Zw[e.status]??e.status}),h!=null&&i.jsx("span",{className:"text-[10px] text-fg-tertiary tabular-nums",children:$s(h)}),e.cost?.estimatedCostUsd!=null&&i.jsxs("span",{className:"text-[10px] text-fg-tertiary tabular-nums",children:["$",e.cost.estimatedCostUsd.toFixed(4)]})]}),i.jsx("div",{className:"text-xs text-fg-secondary mt-1 line-clamp-2",children:e.prompt})]}),d&&i.jsxs("svg",{className:"w-3.5 h-3.5 animate-spin text-brand-500 shrink-0 mt-0.5",viewBox:"0 0 24 24",fill:"none",children:[i.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),i.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"})]})]}),i.jsxs("div",{className:"flex items-center gap-1 mt-3 ml-6",children:[Uo.map((w,T)=>{const C=g>T||g===T&&!d&&p,S=g===T&&d,E=m&&T===Uo.length-1&&e.status!=="completed";return i.jsxs("div",{className:"flex items-center gap-1 flex-1 min-w-0",children:[i.jsx("div",{className:`w-2 h-2 rounded-full shrink-0 ${E?"bg-red-500":C?"bg-green-500":S?"bg-brand-500 animate-pulse":"bg-gray-600"}`,title:Zw[w]}),T<Uo.length-1&&i.jsx("div",{className:`h-px flex-1 ${C?"bg-green-500/50":"bg-border-default/60"}`})]},w)}),i.jsx("div",{className:`w-2 h-2 rounded-full shrink-0 ${m?"bg-red-500":p?"bg-green-500":"bg-gray-600"}`,title:m?"Failed":"Done"})]}),(e.progressMessage||e.progressPercent!=null)&&d&&i.jsxs("div",{className:"mt-2 ml-6 space-y-1",children:[e.progressPercent!=null&&i.jsx("div",{className:"h-1 bg-surface-elevated rounded-full overflow-hidden",children:i.jsx("div",{className:"h-full bg-brand-500 transition-all duration-300",style:{width:`${Math.min(100,Math.max(0,e.progressPercent))}%`}})}),e.progressMessage&&i.jsx("div",{className:"text-[11px] text-fg-tertiary font-mono truncate",children:e.progressMessage})]}),e.result&&!d&&i.jsxs("div",{className:"mt-2 ml-6 space-y-1.5",children:[e.result.summary&&i.jsx("div",{className:"text-xs text-fg-secondary",children:e.result.summary}),e.result.diffStats&&i.jsxs("div",{className:"flex items-center gap-3 text-[10px] font-mono",children:[i.jsxs("span",{className:"text-fg-tertiary",children:[e.result.diffStats.filesChanged," files"]}),i.jsxs("span",{className:"text-green-500",children:["+",e.result.diffStats.additions]}),i.jsxs("span",{className:"text-red-500",children:["−",e.result.diffStats.deletions]})]}),e.cost&&(e.cost.inputTokens!=null||e.cost.outputTokens!=null)&&i.jsxs("div",{className:"text-[10px] text-fg-tertiary",children:[e.cost.inputTokens!=null&&i.jsxs("span",{children:[e.cost.inputTokens.toLocaleString()," in"]}),e.cost.inputTokens!=null&&e.cost.outputTokens!=null&&i.jsx("span",{className:"mx-1",children:"·"}),e.cost.outputTokens!=null&&i.jsxs("span",{children:[e.cost.outputTokens.toLocaleString()," out"]})]})]}),x&&i.jsxs("div",{className:"mt-2 ml-6 border-t border-border-default/30 pt-2",children:[i.jsxs("button",{type:"button",onClick:()=>s(!a),className:"flex items-center gap-1.5 text-[10px] text-fg-tertiary hover:text-fg-secondary transition-colors",children:[i.jsx("svg",{className:`w-3 h-3 transition-transform ${a?"rotate-90":""}`,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:i.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M9 5l7 7-7 7"})}),i.jsx("span",{className:"font-medium uppercase tracking-wider",children:"Raw output"})]}),a&&i.jsx("pre",{className:"mt-2 text-[11px] text-fg-tertiary bg-surface-elevated/70 rounded-lg px-3 py-2 overflow-x-auto whitespace-pre-wrap break-all font-mono",children:x})]})]})}function Nae({label:e}){const{t}=ot("common");return i.jsxs("div",{className:"flex items-center gap-1.5 text-xs py-0.5",children:[i.jsx("span",{className:"activity-text-shimmer",children:e??t("execution.thinking")}),i.jsx("span",{className:"flex gap-0.5",children:[0,150,300].map(n=>i.jsx("span",{className:"w-1 h-1 rounded-full bg-brand-400 animate-bounce",style:{animationDelay:`${n}ms`,animationDuration:"1s"}},n))})]})}const ek=150;function Eae({content:e,className:t}){const[n,a]=k.useState(e),s=k.useRef(0),l=k.useRef(null);k.useEffect(()=>{const d=Date.now(),m=d-s.current;return m>=ek?(s.current=d,a(e)):l.current||(l.current=setTimeout(()=>{s.current=Date.now(),l.current=null,a(e)},ek-m)),()=>{l.current&&(clearTimeout(l.current),l.current=null)}},[e]);const c=k.useMemo(()=>n,[n]);return i.jsxs("div",{className:"bg-surface-elevated/50 rounded-lg px-3 py-2.5 my-1 min-w-0 overflow-hidden",children:[i.jsx(Ea,{content:c,className:t??"text-sm text-fg-secondary break-words"}),i.jsx("span",{className:"inline-block w-0.5 h-4 bg-brand-400 animate-pulse ml-0.5 align-middle"})]})}const _m=8e3,Dd=120;function mh({text:e,className:t}){const{t:n}=ot("common"),[a,s]=k.useState(!1),l=e.length>_m,c=!l||a?e:`${e.slice(0,_m)}
858
+ …`;return i.jsxs("div",{children:[i.jsx("pre",{className:t,children:c}),l&&i.jsx("button",{type:"button",className:"mt-1 text-[11px] text-brand-500 hover:underline",onClick:d=>{d.stopPropagation(),s(m=>!m)},children:n(a?"showLess":"showMore")})]})}function jae({info:e,time:t}){const{t:n}=ot("common"),a=zS(e.args),s=e.status==="running",l=e.status!=="error",c=a.length>0||!s&&(!!e.result||!!e.error)||!!e.subagentLogs&&e.subagentLogs.length>0,d=k.useRef(null),m=e.subagentLogs?.length??0,p=e.subagentLogs&&e.subagentLogs.length>Dd?e.subagentLogs.slice(e.subagentLogs.length-Dd):e.subagentLogs;return k.useEffect(()=>{!s||!d.current||(d.current.scrollTop=d.current.scrollHeight)},[m,s]),i.jsxs("div",{className:"space-y-3 py-1",children:[i.jsxs("div",{className:"flex items-center gap-2 text-[10px]",children:[i.jsx("span",{className:`px-1.5 py-0.5 rounded ${s?"bg-brand-500/15 text-brand-500":l?"bg-green-500/15 text-green-600":"bg-surface-overlay text-fg-tertiary"}`,children:n(s?"execution.toolRunning":l?"execution.toolSuccess":"execution.toolFailed")}),t&&i.jsx("span",{className:"text-fg-tertiary tabular-nums",children:t}),e.durationMs!=null&&i.jsx("span",{className:"text-fg-tertiary",children:$s(e.durationMs)})]}),a.length>0&&i.jsxs("div",{children:[i.jsx("h4",{className:"text-[10px] font-semibold text-fg-tertiary uppercase tracking-wider mb-1",children:n("execution.arguments")}),i.jsx("div",{className:"space-y-2",children:a.map(({key:h,value:g})=>i.jsxs("div",{children:[i.jsx("div",{className:"text-[11px] text-brand-500 font-medium mb-0.5",children:h}),i.jsx(mh,{text:g,className:"text-xs text-fg-secondary bg-surface-elevated/70 rounded-lg px-3 py-2 overflow-x-auto whitespace-pre-wrap break-all font-mono"})]},h))})]}),p&&p.length>0&&i.jsxs("div",{children:[i.jsx("h4",{className:"text-[10px] font-semibold text-fg-tertiary uppercase tracking-wider mb-1",children:n("execution.subagentExecution")}),i.jsxs("div",{ref:d,className:"bg-surface-elevated/50 rounded-lg px-3 py-2 space-y-1",children:[m>Dd&&i.jsxs("div",{className:"text-[10px] text-fg-tertiary pb-1",children:["… ",m-Dd," earlier steps omitted"]}),p.map((h,g)=>{const x=h.eventType==="started"?"▶":h.eventType==="completed"?"✓":h.eventType==="error"?"✗":h.eventType==="tool_start"?"◎":h.eventType==="tool_end"?"●":h.eventType==="thinking"?"·":"→",y=h.eventType==="error"?"text-fg-tertiary":h.eventType==="completed"?"text-green-500":h.eventType==="started"||h.eventType==="tool_start"?"text-brand-500":"text-fg-tertiary";return i.jsxs("div",{className:"flex items-start gap-1.5 text-xs",children:[i.jsx("span",{className:`shrink-0 ${y}`,children:x}),i.jsx("span",{className:`font-mono break-all ${y}`,children:gg(h.content,500)})]},g)}),s&&i.jsxs("div",{className:"flex items-center gap-1.5 text-[11px] text-brand-500 pt-0.5",children:[i.jsxs("svg",{className:"w-3 h-3 animate-spin shrink-0",viewBox:"0 0 24 24",fill:"none",children:[i.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),i.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"})]}),i.jsx("span",{children:n("execution.toolRunning")})]})]})]}),!s&&e.result&&i.jsxs("div",{children:[i.jsx("h4",{className:"text-[10px] font-semibold text-fg-tertiary uppercase tracking-wider mb-1",children:n("execution.result")}),i.jsx(mh,{text:Ww(e.result),className:"text-xs text-fg-secondary bg-surface-elevated/70 rounded-lg px-3 py-2 overflow-x-auto whitespace-pre-wrap break-all font-mono"})]}),!s&&e.error&&i.jsxs("div",{children:[i.jsx("h4",{className:"text-[10px] font-semibold text-fg-tertiary uppercase tracking-wider mb-1",children:n("execution.error")}),i.jsx(mh,{text:Ww(String(e.error)),className:"text-xs text-fg-secondary bg-surface-elevated/50 border border-border-default rounded-lg px-3 py-2 overflow-x-auto whitespace-pre-wrap break-all font-mono"})]}),!c&&i.jsx("div",{className:"text-xs text-fg-tertiary italic py-2 text-center",children:n("execution.noToolDetail")})]})}const FS={urgent:"text-red-500",high:"text-amber-500",medium:"text-blue-500",low:"text-fg-tertiary"},tk={pending:"pending",in_progress:"in_progress",completed:"completed",review:"review",blocked:"blocked",failed:"failed",cancelled:"cancelled",archived:"archived"},nk={pending:{icon:"⏳",labelKey:"execution.card.pendingApproval",borderClass:"border-amber-500/40",bgClass:"bg-amber-500/5",badgeClass:"bg-amber-500/15 text-amber-600",textClass:""},approving:{icon:"⏳",labelKey:"execution.card.approving",borderClass:"border-amber-500/40",bgClass:"bg-amber-500/5",badgeClass:"bg-amber-500/15 text-amber-600",textClass:""},rejecting:{icon:"⏳",labelKey:"execution.card.rejecting",borderClass:"border-amber-500/40",bgClass:"bg-amber-500/5",badgeClass:"bg-amber-500/15 text-amber-600",textClass:""},in_progress:{icon:"▶",labelKey:"execution.card.inProgress",borderClass:"border-blue-500/40",bgClass:"bg-blue-500/5",badgeClass:"bg-blue-500/15 text-blue-500",textClass:"text-blue-500"},completed:{icon:"✅",labelKey:"execution.card.completed",borderClass:"border-green-500/30",bgClass:"bg-green-500/5",badgeClass:"bg-green-500/15 text-green-500",textClass:"text-green-500"},review:{icon:"👀",labelKey:"execution.card.inReview",borderClass:"border-purple-500/40",bgClass:"bg-purple-500/5",badgeClass:"bg-purple-500/15 text-purple-500",textClass:"text-purple-500"},blocked:{icon:"🚫",labelKey:"execution.card.blocked",borderClass:"border-orange-500/40",bgClass:"bg-orange-500/5",badgeClass:"bg-orange-500/15 text-orange-500",textClass:"text-orange-500"},failed:{icon:"❌",labelKey:"execution.card.failed",borderClass:"border-red-500/30",bgClass:"bg-red-500/5",badgeClass:"bg-red-500/15 text-red-500",textClass:"text-red-500"},cancelled:{icon:"⊘",labelKey:"execution.card.cancelled",borderClass:"border-border-default/40",bgClass:"bg-surface-secondary/30",badgeClass:"bg-surface-elevated text-fg-tertiary",textClass:"text-fg-tertiary"},archived:{icon:"📦",labelKey:"execution.card.archived",borderClass:"border-border-default/40",bgClass:"bg-surface-secondary/30",badgeClass:"bg-surface-elevated text-fg-tertiary",textClass:"text-fg-tertiary"},loading:{icon:"⏳",labelKey:"execution.card.loading",borderClass:"border-border-default/40",bgClass:"bg-surface-secondary/30",badgeClass:"bg-surface-elevated text-fg-tertiary",textClass:""}};function US({info:e}){const{t}=ot("common"),[n,a]=k.useState("loading"),[s,l]=k.useState(null);k.useEffect(()=>{let x=!1;return Ae.tasks.get(e.taskId).then(({task:y})=>{x||a(tk[y.status]??"pending")}).catch(()=>{x||a("pending")}),()=>{x=!0}},[e.taskId]),k.useEffect(()=>Ir.on("task:update",x=>{const y=x.payload;y.taskId===e.taskId&&y.status&&a(tk[y.status]??"pending")}),[e.taskId]);const c=()=>{window.dispatchEvent(new CustomEvent("markus:mark-read-by-ref",{detail:{taskId:e.taskId}}))},d=async()=>{l(null),a("approving");try{await Ae.tasks.approve(e.taskId),a("in_progress"),c()}catch{a("pending")}},m=async()=>{l(null),a("rejecting");try{await Ae.tasks.reject(e.taskId),a("cancelled"),c()}catch{a("pending")}},p=n==="pending"||n==="approving"||n==="rejecting",h=nk[n]??nk.loading,g=()=>at.navigate(de.WORK,{openTask:e.taskId});return i.jsxs("div",{className:`my-2 rounded-lg border ${h.borderClass} ${h.bgClass} p-3 max-w-md transition-colors`,children:[i.jsxs("div",{className:"flex items-start gap-2 mb-1 cursor-pointer group",role:"button",tabIndex:0,onClick:g,onKeyDown:x=>x.key==="Enter"&&g(),children:[i.jsx("span",{className:"text-sm mt-0.5",children:h.icon}),i.jsxs("div",{className:"flex-1 min-w-0",children:[i.jsxs("div",{className:"flex items-center gap-1.5",children:[i.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded font-medium ${h.badgeClass}`,children:t("execution.taskBadge")}),!p&&n!=="loading"&&i.jsx("span",{className:`text-[10px] font-medium ${h.textClass}`,children:t(h.labelKey)})]}),i.jsx("div",{className:`text-sm font-medium truncate mt-1 group-hover:underline ${!p&&n!=="loading"?"text-fg-secondary":"text-fg-primary"}`,children:e.title}),e.description&&i.jsx("div",{className:"text-xs text-fg-secondary mt-0.5 line-clamp-2",children:e.description}),i.jsxs("div",{className:"flex items-center gap-2 mt-1.5 text-[11px] text-fg-tertiary",children:[e.priority&&i.jsx("span",{className:FS[e.priority]??"text-fg-tertiary",children:t(`priority.${e.priority}`,{defaultValue:e.priority})}),i.jsx("span",{className:"opacity-50",children:t("execution.idPrefix",{id:e.taskId.slice(0,8)})})]})]})]}),p&&i.jsxs("div",{className:"flex items-center gap-2 mt-2 pt-2 border-t border-border-default/30",children:[i.jsx("button",{onClick:()=>l("approve"),disabled:n!=="pending",className:"flex-1 px-3 py-1.5 text-xs font-medium rounded-md bg-green-600 hover:bg-green-500 text-white transition-colors disabled:opacity-50 disabled:cursor-not-allowed",children:t(n==="approving"?"execution.card.approving":"approve")}),i.jsx("button",{onClick:()=>l("reject"),disabled:n!=="pending",className:"flex-1 px-3 py-1.5 text-xs font-medium rounded-md bg-surface-elevated hover:bg-surface-overlay text-fg-secondary border border-border-default transition-colors disabled:opacity-50 disabled:cursor-not-allowed",children:t(n==="rejecting"?"execution.card.rejecting":"reject")})]}),s==="approve"&&i.jsx(ba,{variant:"primary",title:t("execution.card.confirmApproveTaskTitle"),message:t("execution.card.confirmApproveTaskMessage",{title:e.title}),confirmLabel:t("approve"),onConfirm:()=>{d()},onCancel:()=>l(null)}),s==="reject"&&i.jsx(ba,{variant:"danger",title:t("execution.card.confirmRejectTaskTitle"),message:t("execution.card.confirmRejectTaskMessage",{title:e.title}),confirmLabel:t("reject"),onConfirm:()=>{m()},onCancel:()=>l(null)})]})}const ak={pending:"pending",in_progress:"in_progress",completed:"completed",rejected:"rejected",cancelled:"cancelled",archived:"archived"},rk={pending:{icon:"📋",labelKey:"execution.card.pendingApproval",borderClass:"border-amber-500/40",bgClass:"bg-amber-500/5",badgeClass:"bg-amber-500/15 text-amber-600",textClass:""},approving:{icon:"⏳",labelKey:"execution.card.approving",borderClass:"border-amber-500/40",bgClass:"bg-amber-500/5",badgeClass:"bg-amber-500/15 text-amber-600",textClass:""},rejecting:{icon:"⏳",labelKey:"execution.card.rejecting",borderClass:"border-amber-500/40",bgClass:"bg-amber-500/5",badgeClass:"bg-amber-500/15 text-amber-600",textClass:""},in_progress:{icon:"▶",labelKey:"execution.card.inProgress",borderClass:"border-blue-500/40",bgClass:"bg-blue-500/5",badgeClass:"bg-blue-500/15 text-blue-500",textClass:"text-blue-500"},completed:{icon:"✅",labelKey:"execution.card.completed",borderClass:"border-green-500/30",bgClass:"bg-green-500/5",badgeClass:"bg-green-500/15 text-green-500",textClass:"text-green-500"},rejected:{icon:"❌",labelKey:"execution.card.rejected",borderClass:"border-red-500/30",bgClass:"bg-red-500/5",badgeClass:"bg-red-500/15 text-red-500",textClass:"text-red-500"},cancelled:{icon:"⊘",labelKey:"execution.card.cancelled",borderClass:"border-border-default/40",bgClass:"bg-surface-secondary/30",badgeClass:"bg-surface-elevated text-fg-tertiary",textClass:"text-fg-tertiary"},archived:{icon:"📦",labelKey:"execution.card.archived",borderClass:"border-border-default/40",bgClass:"bg-surface-secondary/30",badgeClass:"bg-surface-elevated text-fg-tertiary",textClass:"text-fg-tertiary"},loading:{icon:"⏳",labelKey:"execution.card.loading",borderClass:"border-border-default/40",bgClass:"bg-surface-secondary/30",badgeClass:"bg-surface-elevated text-fg-tertiary",textClass:""}},Mae=["requirement:approved","requirement:rejected","requirement:updated","requirement:completed","requirement:cancelled","requirement:resubmitted"];function GS({info:e}){const{t}=ot("common"),[n,a]=k.useState("loading"),[s,l]=k.useState(""),[c,d]=k.useState(!1),[m,p]=k.useState(null);k.useEffect(()=>{let S=!1;return Ae.requirements.get(e.requirementId).then(({requirement:E})=>{S||a(ak[E.status]??"pending")}).catch(()=>{S||a("pending")}),()=>{S=!0}},[e.requirementId]),k.useEffect(()=>{const S=Mae.map(E=>Ir.on(E,_=>{const L=_.payload;L.id===e.requirementId&&L.status&&a(ak[L.status]??"pending")}));return()=>S.forEach(E=>E())},[e.requirementId]);const h=()=>{window.dispatchEvent(new CustomEvent("markus:mark-read-by-ref",{detail:{requirementId:e.requirementId}}))},g=async()=>{p(null),a("approving");try{await Ae.requirements.approve(e.requirementId),a("in_progress"),h()}catch{a("pending")}},x=async()=>{if(s.trim()){p(null),a("rejecting");try{await Ae.requirements.reject(e.requirementId,s.trim()),a("rejected"),h()}catch{a("pending")}}},y=()=>{if(!c){d(!0);return}s.trim()&&p("reject")},w=n==="pending"||n==="approving"||n==="rejecting",T=rk[n]??rk.loading,C=()=>at.navigate(de.WORK,{openRequirement:e.requirementId});return i.jsxs("div",{className:`my-2 rounded-lg border ${T.borderClass} ${T.bgClass} p-3 max-w-md transition-colors`,children:[i.jsxs("div",{className:"flex items-start gap-2 mb-1 cursor-pointer group",role:"button",tabIndex:0,onClick:C,onKeyDown:S=>S.key==="Enter"&&C(),children:[i.jsx("span",{className:"text-sm mt-0.5",children:T.icon}),i.jsxs("div",{className:"flex-1 min-w-0",children:[i.jsxs("div",{className:"flex items-center gap-1.5",children:[i.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded font-medium ${T.badgeClass}`,children:t("execution.reqBadge")}),!w&&n!=="loading"&&i.jsx("span",{className:`text-[10px] font-medium ${T.textClass}`,children:t(T.labelKey)})]}),i.jsx("div",{className:`text-sm font-medium truncate mt-1 group-hover:underline ${!w&&n!=="loading"?"text-fg-secondary":"text-fg-primary"}`,children:e.title}),e.description&&i.jsx("div",{className:"text-xs text-fg-secondary mt-0.5 line-clamp-3",children:e.description}),i.jsxs("div",{className:"flex items-center gap-2 mt-1.5 text-[11px] text-fg-tertiary",children:[e.priority&&i.jsx("span",{className:FS[e.priority]??"text-fg-tertiary",children:t(`priority.${e.priority}`,{defaultValue:e.priority})}),i.jsx("span",{className:"opacity-50",children:t("execution.idPrefix",{id:e.requirementId.slice(0,8)})})]})]})]}),w&&i.jsxs("div",{className:"mt-2 pt-2 border-t border-border-default/30 space-y-2",children:[c&&i.jsx("input",{type:"text",value:s,onChange:S=>l(S.target.value),placeholder:t("execution.rejectionReasonPlaceholder"),className:"w-full px-2 py-1.5 text-xs rounded-md bg-surface-secondary border border-border-default text-fg-primary placeholder:text-fg-tertiary focus:outline-none focus:border-brand-500",onKeyDown:S=>S.key==="Enter"&&y(),autoFocus:!0}),i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("button",{onClick:()=>p("approve"),disabled:n!=="pending",className:"flex-1 px-3 py-1.5 text-xs font-medium rounded-md bg-green-600 hover:bg-green-500 text-white transition-colors disabled:opacity-50 disabled:cursor-not-allowed",children:t(n==="approving"?"execution.card.approving":"approve")}),i.jsx("button",{onClick:y,disabled:n!=="pending"||c&&!s.trim(),className:"flex-1 px-3 py-1.5 text-xs font-medium rounded-md bg-surface-elevated hover:bg-surface-overlay text-fg-secondary border border-border-default transition-colors disabled:opacity-50 disabled:cursor-not-allowed",children:t(n==="rejecting"?"execution.card.rejecting":"reject")})]})]}),m==="approve"&&i.jsx(ba,{variant:"primary",title:t("execution.card.confirmApproveReqTitle"),message:t("execution.card.confirmApproveReqMessage",{title:e.title}),confirmLabel:t("approve"),onConfirm:()=>{g()},onCancel:()=>p(null)}),m==="reject"&&i.jsx(ba,{variant:"danger",title:t("execution.card.confirmRejectReqTitle"),message:t("execution.card.confirmRejectReqMessage",{title:e.title}),confirmLabel:t("reject"),onConfirm:()=>{x()},onCancel:()=>p(null)})]})}const _ae={"claude-code":{label:"Claude Code",badgeClass:"bg-orange-500/15 text-orange-500"},codex:{label:"Codex",badgeClass:"bg-emerald-500/15 text-emerald-500"},"cursor-agent":{label:"Cursor",badgeClass:"bg-blue-500/15 text-blue-500"}};function Rae({session:e,info:t,onClose:n}){const a=t.args&&typeof t.args=="object"&&!Array.isArray(t.args)?t.args:{},s=e.status==="running"||e.status==="created"||e.status==="context_injected",l=e.status==="failed"||e.status==="timeout",c=e.status==="completed",d=_ae[e.tool]??{label:e.tool,badgeClass:"bg-surface-elevated text-fg-tertiary"},[m,p]=k.useState(!1);k.useEffect(()=>{const y=w=>{w.key==="Escape"&&n()};return document.addEventListener("keydown",y),()=>document.removeEventListener("keydown",y)},[n]);const h=e.cost?.durationMs??t.durationMs,g=typeof a.model=="string"?a.model:void 0,x=typeof a.mode=="string"?a.mode:void 0;return i.jsxs("div",{className:"fixed inset-0 z-[60] flex items-center justify-center",onClick:n,children:[i.jsx("div",{className:"absolute inset-0 bg-black/60"}),i.jsxs("div",{className:"relative bg-surface-secondary border border-border-default rounded-xl shadow-2xl w-[640px] max-w-[92vw] max-h-[80vh] overflow-hidden flex flex-col",onClick:y=>y.stopPropagation(),children:[i.jsxs("div",{className:"px-5 py-3 border-b border-border-default flex items-center justify-between shrink-0",children:[i.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[i.jsx("span",{className:`text-xs px-2 py-0.5 rounded font-medium ${d.badgeClass}`,children:d.label}),i.jsx("span",{className:`text-xs px-1.5 py-0.5 rounded ${s?"bg-brand-500/15 text-brand-500":c?"bg-green-500/15 text-green-600":"bg-surface-overlay text-fg-tertiary"}`,children:s?"Running":c?"Completed":l?"Failed":e.status}),h!=null&&i.jsx("span",{className:"text-xs text-fg-tertiary tabular-nums",children:$s(h)}),g&&i.jsx("span",{className:"text-[10px] bg-surface-elevated px-1.5 py-0.5 rounded text-fg-tertiary font-mono",children:g}),x&&i.jsx("span",{className:"text-[10px] bg-surface-elevated px-1.5 py-0.5 rounded text-fg-tertiary",children:x})]}),i.jsx("button",{onClick:n,className:"text-fg-tertiary hover:text-fg-secondary text-lg leading-none ml-2",children:"×"})]}),i.jsxs("div",{className:"flex-1 overflow-y-auto px-5 py-4 space-y-4",children:[i.jsxs("div",{children:[i.jsx("h4",{className:"text-[10px] font-semibold text-fg-tertiary uppercase tracking-wider mb-2",children:"Prompt"}),i.jsx("pre",{className:"text-xs text-fg-secondary bg-surface-elevated/70 rounded-lg px-3 py-2 overflow-x-auto max-h-40 overflow-y-auto whitespace-pre-wrap break-all font-mono",children:e.prompt})]}),Object.keys(a).length>0&&i.jsxs("div",{children:[i.jsx("h4",{className:"text-[10px] font-semibold text-fg-tertiary uppercase tracking-wider mb-2",children:"Input Arguments"}),i.jsx("div",{className:"space-y-1.5",children:Object.entries(a).filter(([y])=>y!=="prompt").map(([y,w])=>i.jsxs("div",{className:"flex items-start gap-2 text-xs",children:[i.jsxs("span",{className:"text-brand-500 font-medium shrink-0 font-mono",children:[y,":"]}),i.jsx("span",{className:"text-fg-secondary font-mono break-all",children:typeof w=="string"?w:JSON.stringify(w)})]},y))})]}),e.result&&!s&&i.jsxs("div",{children:[i.jsx("h4",{className:"text-[10px] font-semibold text-fg-tertiary uppercase tracking-wider mb-2",children:"Result"}),i.jsxs("div",{className:"space-y-2",children:[e.result.summary&&i.jsx("div",{className:"text-xs text-fg-secondary",children:e.result.summary}),e.result.diffStats&&i.jsxs("div",{className:"flex items-center gap-3 text-xs font-mono",children:[i.jsxs("span",{className:"text-fg-tertiary",children:[e.result.diffStats.filesChanged," files changed"]}),i.jsxs("span",{className:"text-green-500",children:["+",e.result.diffStats.additions]}),i.jsxs("span",{className:"text-red-500",children:["-",e.result.diffStats.deletions]})]}),e.result.modifiedFiles&&e.result.modifiedFiles.length>0&&i.jsxs("div",{children:[i.jsx("div",{className:"text-[10px] text-fg-tertiary mb-1",children:"Modified files:"}),i.jsx("div",{className:"bg-surface-elevated/70 rounded-lg px-3 py-2 max-h-32 overflow-y-auto",children:e.result.modifiedFiles.map((y,w)=>i.jsx("div",{className:"text-[11px] text-fg-secondary font-mono truncate",children:y},w))})]}),e.result.error&&i.jsx("pre",{className:"text-xs text-fg-secondary bg-surface-elevated/50 border border-border-default rounded-lg px-3 py-2 overflow-x-auto max-h-60 overflow-y-auto whitespace-pre-wrap break-all font-mono",children:e.result.error})]})]}),e.cost&&(e.cost.inputTokens!=null||e.cost.outputTokens!=null||e.cost.estimatedCostUsd!=null)&&i.jsxs("div",{children:[i.jsx("h4",{className:"text-[10px] font-semibold text-fg-tertiary uppercase tracking-wider mb-2",children:"Cost"}),i.jsxs("div",{className:"flex items-center gap-4 text-xs text-fg-secondary",children:[e.cost.inputTokens!=null&&i.jsxs("span",{children:[e.cost.inputTokens.toLocaleString()," input tokens"]}),e.cost.outputTokens!=null&&i.jsxs("span",{children:[e.cost.outputTokens.toLocaleString()," output tokens"]}),e.cost.estimatedCostUsd!=null&&i.jsxs("span",{className:"font-medium",children:["$",e.cost.estimatedCostUsd.toFixed(4)]}),h!=null&&i.jsx("span",{className:"text-fg-tertiary",children:$s(h)})]})]}),e.result?.rawOutput&&i.jsxs("div",{children:[i.jsxs("button",{type:"button",onClick:()=>p(!m),className:"flex items-center gap-1.5 text-[10px] text-fg-tertiary hover:text-fg-secondary transition-colors",children:[i.jsx("svg",{className:`w-3 h-3 transition-transform ${m?"rotate-90":""}`,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:i.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M9 5l7 7-7 7"})}),i.jsx("span",{className:"font-semibold uppercase tracking-wider",children:"Raw Output"})]}),m&&i.jsx("pre",{className:"mt-2 text-[11px] text-fg-tertiary bg-surface-elevated/70 rounded-lg px-3 py-2 overflow-x-auto max-h-[50vh] overflow-y-auto whitespace-pre-wrap break-all font-mono",children:e.result.rawOutput})]})]})]})]})}function Dae(e){if(e.tool!=="invoke_coding_tool")return null;const t=e.args&&typeof e.args=="object"&&!Array.isArray(e.args)?e.args:{},n=typeof t.tool=="string"?t.tool:"unknown",a=typeof t.prompt=="string"?t.prompt:"",l={running:"running",done:"completed",error:"failed",stopped:"cancelled"}[e.status]??e.status;let c,d;if(e.result)try{const p=JSON.parse(e.result);if(p&&typeof p=="object"){const h=p.result&&typeof p.result=="object"?p.result:p;c={success:h.success??p.success??e.status==="done",summary:h.summary??h.message??p.summary??p.message??"Completed",diffStats:h.diffStats??p.diffStats,modifiedFiles:h.modifiedFiles??p.modifiedFiles,exitCode:h.exitCode??p.exitCode,rawOutput:h.rawOutput??h.output??p.rawOutput??p.output,error:h.error??p.error},h.cost?d=h.cost:p.cost&&(d=p.cost)}}catch{c={success:e.status==="done",summary:e.result.slice(0,500),rawOutput:e.result}}e.durationMs!=null&&(d={...d,durationMs:e.durationMs});let m;if(e.liveOutput&&e.status==="running"){const p=e.liveOutput.trim().split(`
859
859
  `);m=p[p.length-1]?.slice(0,200)}return{id:`tc-${n}-${Date.now()}`,tool:n,status:l,prompt:a,progressMessage:m,result:c,cost:d,createdAt:new Date().toISOString()}}function Lae({info:e,time:t,hideApprovalCards:n}){const{t:a}=ot("common"),s=zs(e.tool),l=e.status!=="running",c=e.status==="stopped",d=e.tool==="spawn_subagent"||e.tool==="spawn_subagents",m=!!(d&&e.subagentLogs&&e.subagentLogs.length>0),[p,h]=k.useState(()=>d&&e.status==="running"),g=k.useRef(!1),x=k.useMemo(()=>Dae(e),[e]),[y,w]=k.useState(!1),T=bae(e),C=k.useRef(null),S=m?e.subagentLogs[e.subagentLogs.length-1].content:"",E=k.useMemo(()=>zS(e.args).length>0||!!e.result||!!e.error||!!e.subagentLogs&&e.subagentLogs.length>0,[e.args,e.result,e.error,e.subagentLogs]);return k.useEffect(()=>{C.current&&(C.current.scrollTop=C.current.scrollHeight)},[e.liveOutput]),k.useEffect(()=>{d&&e.status==="running"&&m&&!g.current&&h(!0)},[d,e.status,m,e.subagentLogs?.length]),x?i.jsxs(i.Fragment,{children:[i.jsx("div",{className:"cursor-pointer",onClick:()=>w(!0),children:i.jsx(Tae,{session:x})}),y&&zr.createPortal(i.jsx(Rae,{session:x,info:e,onClose:()=>w(!1)}),document.body)]}):i.jsxs(i.Fragment,{children:[i.jsxs("div",{className:"relative py-0.5 min-w-0",children:[i.jsxs("div",{className:`flex items-center gap-2 min-w-0 rounded ${E?"cursor-pointer hover:bg-surface-elevated/30 transition-colors":""}`,onClick:()=>{E&&(Dc(),h(_=>{const L=!_;return d&&e.status==="running"&&(g.current=!L),L}))},children:[i.jsx(rl,{name:s.iconName,size:15,className:`shrink-0 ${e.status==="running"?"text-brand-500":e.status==="error"||c?"text-fg-tertiary":"text-green-500"}`}),i.jsxs("span",{className:`text-xs leading-snug shrink-0 ${e.status==="running"?"activity-text-shimmer":e.status==="error"||c?"text-fg-tertiary opacity-70":"text-fg-secondary"}`,children:[a(`execution.tools.${s.key}`,{defaultValue:s.label}),e.status==="running"?"…":""]}),E&&i.jsx("svg",{className:`w-3 h-3 shrink-0 text-fg-tertiary transition-transform ${p?"rotate-90":""}`,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:i.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M9 5l7 7-7 7"})}),e.status==="running"&&i.jsxs("svg",{className:"w-3 h-3 animate-spin shrink-0",viewBox:"0 0 24 24",fill:"none",children:[i.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),i.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"})]}),e.durationMs!=null&&e.status!=="running"&&i.jsx("span",{className:"text-[10px] text-fg-tertiary shrink-0",children:$s(e.durationMs)}),T&&i.jsxs("span",{className:"font-mono text-[11px] text-fg-tertiary truncate min-w-0",title:T,children:[i.jsx("span",{className:"select-none opacity-70",children:"$ "}),T.split(`
860
- `)[0]]}),m&&i.jsx("span",{className:"text-[10px] text-fg-tertiary shrink-0 opacity-60",children:a("execution.toolSteps",{count:e.subagentLogs.filter(_=>_.eventType==="tool_end").length})})]}),e.liveOutput&&e.status==="running"&&i.jsx("pre",{ref:C,className:"mt-1 font-mono text-[11px] text-fg-tertiary bg-surface-secondary/60 rounded px-2 py-1.5 max-h-32 overflow-y-auto overflow-x-hidden whitespace-pre-wrap break-all",children:e.liveOutput.length>_m?e.liveOutput.slice(e.liveOutput.length-_m):e.liveOutput}),!p&&d&&e.status==="running"&&S&&i.jsx("div",{className:"mt-1 ml-[23px] font-mono text-[11px] text-fg-tertiary truncate",title:S,children:S}),p&&E&&i.jsx("div",{className:"mt-1 ml-[23px] border-l-2 border-border-default/60 pl-3 max-h-80 overflow-y-auto overflow-x-hidden",children:i.jsx(jae,{info:e,time:t})})]}),l&&!n&&(()=>{const _=BS(e.tool,e.result);if(_)return i.jsx(US,{info:_});const L=HS(e.tool,e.result);return L?i.jsx(GS,{info:L}):null})()]})}function Iae({content:e,time:t,defaultExpanded:n}){const{t:a}=ot("common"),[s,l]=k.useState(n??!1);return k.useEffect(()=>{n&&l(!0)},[n]),i.jsxs("div",{className:"min-w-0 py-0.5 overflow-hidden",children:[i.jsxs("button",{onClick:()=>{Dc(),l(c=>!c)},className:"flex items-center gap-2 text-xs w-full min-w-0",children:[i.jsx(rl,{name:"sparkles",size:15,className:"shrink-0 text-violet-400"}),i.jsx("span",{className:`shrink-0 ${n?"activity-text-shimmer":"text-fg-secondary"}`,children:a("execution.thinking")}),i.jsx("svg",{className:`w-3 h-3 shrink-0 text-fg-tertiary transition-transform ${s?"rotate-90":""}`,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:i.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M9 5l7 7-7 7"})}),s&&t&&i.jsx("span",{className:"ml-auto shrink-0 text-[10px] text-fg-tertiary tabular-nums",children:t})]}),s&&i.jsx("div",{className:"mt-1.5 ml-[23px] border-l-2 border-border-default/60 pl-3 overflow-hidden",children:i.jsx(Ea,{content:e,className:"text-xs text-fg-tertiary break-words"})})]})}const yg=k.memo(Oae);function Oae({entry:e,showTime:t,isLast:n,defaultThinkingExpanded:a,hideApprovalCards:s}){const{t:l}=ot("common");if(e.type==="tool")return i.jsx(Lae,{info:e.info,showTime:t,time:e.time,isLast:n,hideApprovalCards:s},e.key);if(e.type==="thinking")return i.jsx(Iae,{content:e.content,time:e.time,showTime:t,defaultExpanded:a});if(e.type==="text")return e.content.startsWith("⚠")?i.jsx("div",{className:"min-w-0 pl-[23px] pr-1 overflow-hidden",children:i.jsx("p",{className:"text-[13px] text-fg-tertiary leading-relaxed whitespace-pre-wrap break-words",children:e.content.replace(/^⚠\s*/,"")})}):i.jsx("div",{className:"min-w-0 pl-[23px] pr-1 overflow-hidden",children:i.jsx(Ea,{content:e.content,className:"text-sm text-fg-secondary break-words"})});if(e.type==="status"){const c=e.content==="completed"||e.content==="execution_finished",d=e.content==="started",m=e.content==="resumed",p=c?"text-green-600":d?"text-blue-600":m?"text-amber-600":"text-fg-tertiary",h=c?"bg-green-400":d?"bg-blue-400":m?"bg-amber-400":"bg-gray-500";return i.jsxs("div",{className:"flex items-center gap-2 py-0.5 min-w-0",children:[i.jsx("span",{className:"w-[15px] flex justify-center shrink-0",children:i.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${h}`})}),i.jsx("span",{className:`text-xs capitalize ${p}`,children:l(`execution.statusKnown.${e.content}`,{defaultValue:e.content})})]})}return e.type==="error"?i.jsxs("div",{className:"flex items-start gap-2 py-0.5 min-w-0",children:[i.jsx(rl,{name:"alert-circle",size:15,className:"shrink-0 mt-0.5 text-fg-tertiary"}),i.jsxs("span",{className:"text-xs text-fg-tertiary leading-relaxed break-words min-w-0",children:[i.jsx("span",{className:"font-medium",children:l("execution.errorPrefix")})," ",e.content.replace(/^⚠\s*/,"")]})]}):null}function ise({entries:e,streamingText:t,isActive:n,onExpand:a,showRounds:s,embedded:l}){const{t:c}=ot("common"),d=e.length>0?e[e.length-1]:null,m=e.filter(L=>L.type==="tool_end").length,p=e.filter(L=>L.type==="error").length,h=e.length>0?new Date(e[0].createdAt).getTime():Date.now(),g=d?new Date(d.createdAt).getTime():Date.now(),x=n?Date.now()-h:g-h,y=new Set(e.filter(L=>L.executionRound!=null).map(L=>L.executionRound)),w=y.size>0?Math.max(...y):void 0,T=s&&y.size>1;let C,S,E=null;if(n)if(t)C="✍",S=c("execution.compact.writingResponse"),E=gg(t.split(`
860
+ `)[0]]}),m&&i.jsx("span",{className:"text-[10px] text-fg-tertiary shrink-0 opacity-60",children:a("execution.toolSteps",{count:e.subagentLogs.filter(_=>_.eventType==="tool_end").length})})]}),e.liveOutput&&e.status==="running"&&i.jsx("pre",{ref:C,className:"mt-1 font-mono text-[11px] text-fg-tertiary bg-surface-secondary/60 rounded px-2 py-1.5 overflow-x-hidden whitespace-pre-wrap break-all",children:e.liveOutput.length>_m?e.liveOutput.slice(e.liveOutput.length-_m):e.liveOutput}),!p&&d&&e.status==="running"&&S&&i.jsx("div",{className:"mt-1 ml-[23px] font-mono text-[11px] text-fg-tertiary truncate",title:S,children:S}),p&&E&&i.jsx("div",{className:"mt-1 ml-[23px] border-l-2 border-border-default/60 pl-3 overflow-x-hidden",children:i.jsx(jae,{info:e,time:t})})]}),l&&!n&&(()=>{const _=BS(e.tool,e.result);if(_)return i.jsx(US,{info:_});const L=HS(e.tool,e.result);return L?i.jsx(GS,{info:L}):null})()]})}function Iae({content:e,time:t,defaultExpanded:n}){const{t:a}=ot("common"),[s,l]=k.useState(n??!1);return k.useEffect(()=>{n&&l(!0)},[n]),i.jsxs("div",{className:"min-w-0 py-0.5 overflow-hidden",children:[i.jsxs("button",{onClick:()=>{Dc(),l(c=>!c)},className:"flex items-center gap-2 text-xs w-full min-w-0",children:[i.jsx(rl,{name:"sparkles",size:15,className:"shrink-0 text-violet-400"}),i.jsx("span",{className:`shrink-0 ${n?"activity-text-shimmer":"text-fg-secondary"}`,children:a("execution.thinking")}),i.jsx("svg",{className:`w-3 h-3 shrink-0 text-fg-tertiary transition-transform ${s?"rotate-90":""}`,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:i.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M9 5l7 7-7 7"})}),s&&t&&i.jsx("span",{className:"ml-auto shrink-0 text-[10px] text-fg-tertiary tabular-nums",children:t})]}),s&&i.jsx("div",{className:"mt-1.5 ml-[23px] border-l-2 border-border-default/60 pl-3 overflow-hidden",children:i.jsx(Ea,{content:e,className:"text-xs text-fg-tertiary break-words"})})]})}const yg=k.memo(Oae);function Oae({entry:e,showTime:t,isLast:n,defaultThinkingExpanded:a,hideApprovalCards:s}){const{t:l}=ot("common");if(e.type==="tool")return i.jsx(Lae,{info:e.info,showTime:t,time:e.time,isLast:n,hideApprovalCards:s},e.key);if(e.type==="thinking")return i.jsx(Iae,{content:e.content,time:e.time,showTime:t,defaultExpanded:a});if(e.type==="text")return e.content.startsWith("⚠")?i.jsx("div",{className:"min-w-0 pl-[23px] pr-1 overflow-hidden",children:i.jsx("p",{className:"text-[13px] text-fg-tertiary leading-relaxed whitespace-pre-wrap break-words",children:e.content.replace(/^⚠\s*/,"")})}):i.jsx("div",{className:"min-w-0 pl-[23px] pr-1 overflow-hidden",children:i.jsx(Ea,{content:e.content,className:"text-sm text-fg-secondary break-words"})});if(e.type==="status"){const c=e.content==="completed"||e.content==="execution_finished",d=e.content==="started",m=e.content==="resumed",p=c?"text-green-600":d?"text-blue-600":m?"text-amber-600":"text-fg-tertiary",h=c?"bg-green-400":d?"bg-blue-400":m?"bg-amber-400":"bg-gray-500";return i.jsxs("div",{className:"flex items-center gap-2 py-0.5 min-w-0",children:[i.jsx("span",{className:"w-[15px] flex justify-center shrink-0",children:i.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${h}`})}),i.jsx("span",{className:`text-xs capitalize ${p}`,children:l(`execution.statusKnown.${e.content}`,{defaultValue:e.content})})]})}return e.type==="error"?i.jsxs("div",{className:"flex items-start gap-2 py-0.5 min-w-0",children:[i.jsx(rl,{name:"alert-circle",size:15,className:"shrink-0 mt-0.5 text-fg-tertiary"}),i.jsxs("span",{className:"text-xs text-fg-tertiary leading-relaxed break-words min-w-0",children:[i.jsx("span",{className:"font-medium",children:l("execution.errorPrefix")})," ",e.content.replace(/^⚠\s*/,"")]})]}):null}function ise({entries:e,streamingText:t,isActive:n,onExpand:a,showRounds:s,embedded:l}){const{t:c}=ot("common"),d=e.length>0?e[e.length-1]:null,m=e.filter(L=>L.type==="tool_end").length,p=e.filter(L=>L.type==="error").length,h=e.length>0?new Date(e[0].createdAt).getTime():Date.now(),g=d?new Date(d.createdAt).getTime():Date.now(),x=n?Date.now()-h:g-h,y=new Set(e.filter(L=>L.executionRound!=null).map(L=>L.executionRound)),w=y.size>0?Math.max(...y):void 0,T=s&&y.size>1;let C,S,E=null;if(n)if(t)C="✍",S=c("execution.compact.writingResponse"),E=gg(t.split(`
861
861
  `).pop()??"",80);else if(d?.type==="tool_start"){const L=zs(d.content);C=L.icon,S=`${c(`execution.tools.${L.key}`,{defaultValue:L.label})}...`;const D=d.metadata?.arguments&&typeof d.metadata.arguments=="object"?d.metadata.arguments.command:void 0;D&&(E=`$ ${gg(D.split(`
862
- `)[0]??"",80)}`)}else if(d?.type==="tool_end"){const L=zs(d.content);C=L.icon,S=c(`execution.tools.${L.key}`,{defaultValue:L.label})}else C="💭",S=c("execution.compact.thinking");else if(p>0&&d?.type==="error")C="❌",S=c("execution.compact.failed");else{const D=[...e].reverse().find(M=>M.type==="status")?.content??"";D==="completed"||D==="execution_finished"?(C="✅",S=c("execution.compact.completed")):(C="●",S=c("execution.compact.toolsExecuted",{count:m}))}const _=$s(x);return i.jsx("div",{onClick:()=>{Dc(),a()},className:`overflow-hidden transition-all cursor-pointer min-w-0 ${l?"hover:bg-surface-elevated/20":`rounded-lg border hover:brightness-110 ${n?"border-2 exec-card-active":"border border-border-default bg-surface-elevated/30 hover:border-brand-500/40"}`}`,children:i.jsxs("div",{className:l?"py-2":"px-3 py-2.5 bg-surface-primary/80",children:[i.jsxs("div",{className:"flex items-center justify-between gap-2",children:[i.jsxs("div",{className:"flex items-center gap-2 min-w-0 flex-1",children:[n?i.jsxs("svg",{className:"w-3.5 h-3.5 animate-spin text-brand-500 shrink-0",viewBox:"0 0 24 24",fill:"none",children:[i.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),i.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"})]}):i.jsx("span",{className:"text-sm shrink-0",children:C}),i.jsx("span",{className:`text-xs font-medium truncate ${n?"text-fg-primary":"text-fg-secondary"}`,children:S})]}),_&&i.jsx("span",{className:"text-[10px] text-fg-tertiary tabular-nums shrink-0",children:_})]}),t?i.jsx("div",{className:`mt-1.5 ml-5.5 text-xs text-fg-secondary whitespace-pre-wrap break-words leading-relaxed ${l&&n?"":"max-h-32 overflow-y-auto"}`,children:i.jsx(Ea,{content:t,className:"text-xs"})}):E?i.jsx("div",{className:"mt-1 ml-5.5 text-[11px] font-mono text-fg-tertiary truncate",children:E}):null,i.jsxs("div",{className:"flex items-center justify-between mt-2",children:[i.jsxs("div",{className:"flex items-center gap-2 text-[10px] text-fg-tertiary",children:[m>0&&i.jsxs("span",{children:["🔧 ",c("execution.compact.toolsLine",{count:m})]}),e.some(L=>L.type==="text"&&!L.metadata?.isThinking)&&i.jsxs("span",{children:["💬 ",c("execution.compact.text")]}),e.some(L=>L.type==="text"&&L.metadata?.isThinking)&&i.jsxs("span",{className:"text-purple-400",children:["💭 ",c("execution.compact.thinkingTag")]}),T&&w!=null&&i.jsxs(i.Fragment,{children:[i.jsx("span",{className:"opacity-30",children:"·"}),i.jsx("span",{children:c("execution.compact.round",{n:w})}),i.jsx("span",{className:"opacity-30",children:"·"}),i.jsx("span",{children:c("execution.compact.rounds",{count:y.size})})]})]}),i.jsxs("span",{className:"text-[10px] text-brand-500 flex items-center gap-0.5",children:[c("execution.compact.showFullLog"),i.jsx("svg",{className:"w-3 h-3",viewBox:"0 0 20 20",fill:"currentColor",children:i.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"})})]})]})]})})}function Pae(e){const t=new Map;for(const n of e){const a=n.executionRound??1;t.has(a)||t.set(a,[]);const s=gb(n);s&&t.get(a).push(s)}return Array.from(t.entries()).sort(([n],[a])=>n-a).map(([n,a])=>({round:n,entries:a}))}function sse({entries:e,streamingText:t,isActive:n,onCollapse:a,showRounds:s,embedded:l,expandThinking:c,hideApprovalCards:d}){const{t:m}=ot("common"),p=k.useRef(null),[h,g]=k.useState(new Set),x=Pae(e),y=s&&x.length>1;k.useEffect(()=>{x.length>0&&g(S=>{const E=new Set(S);return E.add(x[x.length-1].round),E})},[x.length]),k.useEffect(()=>{l||!p.current||!n||(p.current.scrollTop=p.current.scrollHeight)},[e.length,t,n,l]);const w=S=>{Dc(),g(E=>{const _=new Set(E);return _.has(S)?_.delete(S):_.add(S),_})},T=y?null:e.map(gb).filter(S=>S!==null),C=T?bg(T):null;return i.jsxs("div",{className:`min-w-0 overflow-hidden ${l?"":"rounded-lg border border-border-default bg-surface-primary/50"}`,children:[a&&i.jsxs("div",{onClick:()=>{Dc(),a()},className:`flex items-center cursor-pointer hover:bg-surface-elevated/40 transition-colors ${l?"justify-end py-0.5":"justify-between px-3 py-1.5 border-b border-border-default"}`,children:[!l&&i.jsx("span",{className:"text-[10px] text-fg-tertiary font-medium uppercase tracking-wider",children:m("execution.fullLog.title")}),i.jsxs("span",{className:"text-[10px] text-brand-500 flex items-center gap-0.5",children:[m("execution.fullLog.collapse"),i.jsx("svg",{className:"w-3 h-3 rotate-180",viewBox:"0 0 20 20",fill:"currentColor",children:i.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"})})]})]}),i.jsxs("div",{ref:l?void 0:p,className:`space-y-2.5 min-w-0 overflow-x-hidden ${l?"py-1":"px-3 py-2 max-h-[60vh] overflow-y-auto scrollbar-thin"}`,children:[y?x.map(S=>{const E=h.has(S.round),_=bg(S.entries),L=S.entries.filter(D=>D.type==="tool"&&D.info?.status!=="running").length;return i.jsxs("div",{className:"border border-border-default/50 rounded-lg mb-2 overflow-hidden",children:[i.jsxs("button",{onClick:()=>w(S.round),className:"w-full flex items-center justify-between px-3 py-1.5 bg-surface-elevated/30 hover:bg-surface-elevated/50 transition-colors",children:[i.jsx("span",{className:"text-xs text-fg-secondary font-medium",children:m("execution.compact.round",{n:S.round})}),i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("span",{className:"text-[10px] text-fg-tertiary",children:m("execution.compact.toolsLine",{count:L})}),i.jsx("svg",{className:`w-3 h-3 text-fg-tertiary transition-transform ${E?"rotate-180":""}`,viewBox:"0 0 20 20",fill:"currentColor",children:i.jsx("path",{fillRule:"evenodd",d:"M5.23 7.21a.75.75 0 011.06.02L10 11.168l3.71-3.938a.75.75 0 111.08 1.04l-4.25 4.5a.75.75 0 01-1.08 0l-4.25-4.5a.75.75 0 01.02-1.06z",clipRule:"evenodd"})})]})]}),E&&i.jsx("div",{className:"px-3 py-1.5 space-y-2.5",children:_.map((D,M)=>i.jsx(yg,{entry:D,showTime:!1,isLast:M===_.length-1,defaultThinkingExpanded:!!c,hideApprovalCards:d},M))})]},S.round)}):C&&C.map((S,E)=>i.jsx(yg,{entry:S,showTime:!1,isLast:E===C.length-1,defaultThinkingExpanded:!!c,hideApprovalCards:d},E)),n&&t&&i.jsx(Eae,{content:t}),n&&!t&&i.jsx(Nae,{})]})]})}function zae(e,t){return!!e&&t==="agent"}const Bae=24e3,Hae=200;function ose(e,t,n=Bae){const a=(e??"")+t;return a.length<=n?a:a.slice(a.length-n)}function lse(e,t,n=Hae){const a=[...e??[],t];return a.length<=n?a:a.slice(a.length-n)}function $ae(e){return!!e.text?.trim()||(e.segments??[]).some(t=>t.type==="text"&&(t.content||t.thinking)||t.type==="tool")}function cse(e,t=8){for(let n=e.length-1;n>=Math.max(0,e.length-t);n--){const a=e[n];if(a.isStreaming&&!a.isStopped)return!0}return!1}function KS(e){if(!e||e.length===0)return e;let t=!1;const n=e.map(a=>a.type==="tool"&&a.status==="running"?(t=!0,{...a,status:"stopped"}):a);return t?n:e}function VS(e,t){if(!$ae(e)&&t!=="done")return null;const a={...e,isStreaming:!1,segments:KS(e.segments)};switch(t){case"done":return{...a,isStopped:!1,isError:!1};case"stopped":return{...a,isStopped:!0,isError:!1};case"error":return{...a,isStopped:!0,isError:!0}}}function use(e){const t=[...e];for(let n=t.length-1;n>=0;n--)if(t[n].sender==="agent"&&!t[n].isStopped&&!t[n].isError){const a=VS(t[n],"stopped");a===null?t.splice(n,1):t[n]=a;break}return t}function dse(e,t){const n=e.findIndex(c=>c.id===t);if(n<0)return e;const a=e[n],s=KS(a.segments);if(!a.isStreaming&&s===a.segments)return e;const l=[...e];return l[n]={...a,isStreaming:!1,segments:s},l}function mse(e,t="stopped"){for(let n=e.length-1;n>=0;n--){const a=e[n];if(a.sender==="agent"&&a.isStreaming&&!a.isStopped){const s=VS(a,t);if(s===null)return e.filter((c,d)=>d!==n);const l=[...e];return l[n]=s,l}}return e}function pse(e,t){if(e.some(l=>l.id===t.id))return e;const n=t.rawCreatedAt?Date.parse(t.rawCreatedAt):NaN;if(!Number.isFinite(n)||e.length===0)return[...e,t];let a=e.length;for(;a>0;){const l=e[a-1],c=l.rawCreatedAt?Date.parse(l.rawCreatedAt):NaN;if(!Number.isFinite(c)||c<=n)break;a--}if(a===e.length)return[...e,t];const s=e.slice();return s.splice(a,0,t),s}function fse(e,t){if(!t)return e;const n=e[e.length-1];return n?.type==="text"?[...e.slice(0,-1),{...n,thinking:(n.thinking??"")+t}]:[...e,{type:"text",content:"",thinking:t,createdAt:new Date().toISOString()}]}function hse(e,t){if(!t)return e;const n=e[e.length-1];return n?.type==="text"?[...e.slice(0,-1),{...n,content:n.content+t}]:[...e,{type:"text",content:t,createdAt:new Date().toISOString()}]}const qae=/\n*<!--\s*notify_context:\s*([\s\S]*?)-->/g;function bb(e){if(!e.includes("notify_context"))return{cleaned:e};let t;const n=e.match(/<!--\s*notify_context:\s*([\s\S]*?)-->/);if(n?.[1]){const a=n[1].match(/priority\s*=\s*(\w+)/i);a&&(t=a[1])}return{cleaned:e.replace(qae,"").trimEnd(),priority:t}}const Fae=/(?:<thinking>| thinking)[\s\S]*?<\/thinking>/g,Uae=/(?:<thinking>| thinking| thinking| think)[\s\S]*?<\/think>/g;function gse(e){return e.replace(Fae,"").replace(Uae,"")}function Gae(e,t,n){if(e.type!=="tool"){const{cleaned:d}=bb(e.content??"");return{type:"text",content:d,thinking:e.thinking,createdAt:e.createdAt}}const a=n?.type==="tool"&&n.tool===e.tool?n:void 0,s=e.subagentLogs?.length??0,l=a?.subagentLogs?.length??0,c=s>=l?e.subagentLogs:a?.subagentLogs;return{type:"tool",key:`${e.tool}_${t}`,tool:e.tool,status:e.status,args:e.arguments,result:e.result,error:e.error,durationMs:e.durationMs,createdAt:e.createdAt,...c?.length?{subagentLogs:c}:{}}}function Kae(e,t){const n=(t??[]).filter(s=>s.type==="tool");let a=0;return e.map((s,l)=>{const c=s.type==="tool"?n[a++]:void 0;return Gae(s,l,c)})}const Ld=new Map,Vae=2e3;function WS(e){if(!e)return"";const t=Ld.get(e);if(t!==void 0)return t;const n=new Date(e),a=isNaN(n.getTime())?"":n.toLocaleTimeString();return Ld.size>=Vae&&Ld.clear(),Ld.set(e,a),a}function bse(e){const t={id:e.id,sender:e.role==="user"?"user":"agent",text:e.content,time:WS(e.createdAt),rawCreatedAt:e.createdAt,agentId:e.role!=="user"?e.agentId:void 0};if(e.role!=="user"&&e.metadata?.segments&&e.metadata.segments.length>0&&(t.segments=Kae(e.metadata.segments)),e.role==="assistant"&&(e.content==="[cancelled]"||e.content==="[Stream cancelled]")&&(t.text=""),(e.metadata?.isError||e.role==="assistant"&&e.content.startsWith("⚠"))&&(t.isError=!0),(e.metadata?.emptyReply||e.role==="assistant"&&!e.content&&!e.metadata?.segments?.length&&(e.metadata?.isError||e.metadata?.isStopped))&&(t.emptyReply=!0,t.isStopped||(t.isError=!0)),e.metadata?.isStreaming&&(t.isStreaming=!0),e.metadata?.isStopped&&!e.metadata?.isStreaming&&(t.isStopped=!0),e.metadata?.images?.length&&(t.images=e.metadata.images),e.metadata?.notifyUser&&(t.isNotification=!0,t.notifyPriority=e.metadata.priority,e.metadata.taskId&&(t.taskId=e.metadata.taskId),e.metadata.requirementId&&(t.requirementId=e.metadata.requirementId)),t.text.includes("<!-- notify_context:")){const{cleaned:n,priority:a}=bb(t.text);t.text=n,a&&!t.notifyPriority&&(t.notifyPriority=a),t.isNotification=!0}if(e.metadata?.activityLog&&(t.isActivityLog=!0,t.activityType=e.metadata.activityType,t.outcome=e.metadata.outcome,t.mailboxItemId=e.metadata.mailboxItemId,t.taskId=e.metadata.taskId,t.requirementId=e.metadata.requirementId,!t.outcome&&t.text.startsWith("[ACTIVITY:"))){const n=t.text.lastIndexOf(" → ");n!==-1&&(t.outcome=t.text.slice(n+3)),t.text=t.text.replace(/^\[ACTIVITY:\s*\w+\]\s*/,"")}return e.metadata?.replyToId&&(t.replyToId=e.metadata.replyToId,t.replyToSender=e.metadata.replyToSender,t.replyToText=e.metadata.replyToText,t.text=YS(t.text,t.replyToSender,t.replyToText)),t}function YS(e,t,n){if(!e||!t||!n)return e;const a=`> **${t}**: ${n}
862
+ `)[0]??"",80)}`)}else if(d?.type==="tool_end"){const L=zs(d.content);C=L.icon,S=c(`execution.tools.${L.key}`,{defaultValue:L.label})}else C="💭",S=c("execution.compact.thinking");else if(p>0&&d?.type==="error")C="❌",S=c("execution.compact.failed");else{const D=[...e].reverse().find(M=>M.type==="status")?.content??"";D==="completed"||D==="execution_finished"?(C="✅",S=c("execution.compact.completed")):(C="●",S=c("execution.compact.toolsExecuted",{count:m}))}const _=$s(x);return i.jsx("div",{onClick:()=>{Dc(),a()},className:`overflow-hidden transition-all cursor-pointer min-w-0 ${l?"hover:bg-surface-elevated/20":`rounded-lg border hover:brightness-110 ${n?"border-2 exec-card-active":"border border-border-default bg-surface-elevated/30 hover:border-brand-500/40"}`}`,children:i.jsxs("div",{className:l?"py-2":"px-3 py-2.5 bg-surface-primary/80",children:[i.jsxs("div",{className:"flex items-center justify-between gap-2",children:[i.jsxs("div",{className:"flex items-center gap-2 min-w-0 flex-1",children:[n?i.jsxs("svg",{className:"w-3.5 h-3.5 animate-spin text-brand-500 shrink-0",viewBox:"0 0 24 24",fill:"none",children:[i.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),i.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"})]}):i.jsx("span",{className:"text-sm shrink-0",children:C}),i.jsx("span",{className:`text-xs font-medium truncate ${n?"text-fg-primary":"text-fg-secondary"}`,children:S})]}),_&&i.jsx("span",{className:"text-[10px] text-fg-tertiary tabular-nums shrink-0",children:_})]}),t?i.jsx("div",{className:`mt-1.5 ml-5.5 text-xs text-fg-secondary whitespace-pre-wrap break-words leading-relaxed ${l?"":"max-h-32 overflow-y-auto"}`,children:i.jsx(Ea,{content:t,className:"text-xs"})}):E?i.jsx("div",{className:"mt-1 ml-5.5 text-[11px] font-mono text-fg-tertiary truncate",children:E}):null,i.jsxs("div",{className:"flex items-center justify-between mt-2",children:[i.jsxs("div",{className:"flex items-center gap-2 text-[10px] text-fg-tertiary",children:[m>0&&i.jsxs("span",{children:["🔧 ",c("execution.compact.toolsLine",{count:m})]}),e.some(L=>L.type==="text"&&!L.metadata?.isThinking)&&i.jsxs("span",{children:["💬 ",c("execution.compact.text")]}),e.some(L=>L.type==="text"&&L.metadata?.isThinking)&&i.jsxs("span",{className:"text-purple-400",children:["💭 ",c("execution.compact.thinkingTag")]}),T&&w!=null&&i.jsxs(i.Fragment,{children:[i.jsx("span",{className:"opacity-30",children:"·"}),i.jsx("span",{children:c("execution.compact.round",{n:w})}),i.jsx("span",{className:"opacity-30",children:"·"}),i.jsx("span",{children:c("execution.compact.rounds",{count:y.size})})]})]}),i.jsxs("span",{className:"text-[10px] text-brand-500 flex items-center gap-0.5",children:[c("execution.compact.showFullLog"),i.jsx("svg",{className:"w-3 h-3",viewBox:"0 0 20 20",fill:"currentColor",children:i.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"})})]})]})]})})}function Pae(e){const t=new Map;for(const n of e){const a=n.executionRound??1;t.has(a)||t.set(a,[]);const s=gb(n);s&&t.get(a).push(s)}return Array.from(t.entries()).sort(([n],[a])=>n-a).map(([n,a])=>({round:n,entries:a}))}function sse({entries:e,streamingText:t,isActive:n,onCollapse:a,showRounds:s,embedded:l,expandThinking:c,hideApprovalCards:d}){const{t:m}=ot("common"),p=k.useRef(null),[h,g]=k.useState(new Set),x=Pae(e),y=s&&x.length>1;k.useEffect(()=>{x.length>0&&g(S=>{const E=new Set(S);return E.add(x[x.length-1].round),E})},[x.length]),k.useEffect(()=>{l||!p.current||!n||(p.current.scrollTop=p.current.scrollHeight)},[e.length,t,n,l]);const w=S=>{Dc(),g(E=>{const _=new Set(E);return _.has(S)?_.delete(S):_.add(S),_})},T=y?null:e.map(gb).filter(S=>S!==null),C=T?bg(T):null;return i.jsxs("div",{className:`min-w-0 overflow-hidden ${l?"":"rounded-lg border border-border-default bg-surface-primary/50"}`,children:[a&&i.jsxs("div",{onClick:()=>{Dc(),a()},className:`flex items-center cursor-pointer hover:bg-surface-elevated/40 transition-colors ${l?"justify-end py-0.5":"justify-between px-3 py-1.5 border-b border-border-default"}`,children:[!l&&i.jsx("span",{className:"text-[10px] text-fg-tertiary font-medium uppercase tracking-wider",children:m("execution.fullLog.title")}),i.jsxs("span",{className:"text-[10px] text-brand-500 flex items-center gap-0.5",children:[m("execution.fullLog.collapse"),i.jsx("svg",{className:"w-3 h-3 rotate-180",viewBox:"0 0 20 20",fill:"currentColor",children:i.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"})})]})]}),i.jsxs("div",{ref:l?void 0:p,className:`space-y-2.5 min-w-0 overflow-x-hidden ${l?"py-1":"px-3 py-2 max-h-[60vh] overflow-y-auto scrollbar-thin"}`,children:[y?x.map(S=>{const E=h.has(S.round),_=bg(S.entries),L=S.entries.filter(D=>D.type==="tool"&&D.info?.status!=="running").length;return i.jsxs("div",{className:"border border-border-default/50 rounded-lg mb-2 overflow-hidden",children:[i.jsxs("button",{onClick:()=>w(S.round),className:"w-full flex items-center justify-between px-3 py-1.5 bg-surface-elevated/30 hover:bg-surface-elevated/50 transition-colors",children:[i.jsx("span",{className:"text-xs text-fg-secondary font-medium",children:m("execution.compact.round",{n:S.round})}),i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("span",{className:"text-[10px] text-fg-tertiary",children:m("execution.compact.toolsLine",{count:L})}),i.jsx("svg",{className:`w-3 h-3 text-fg-tertiary transition-transform ${E?"rotate-180":""}`,viewBox:"0 0 20 20",fill:"currentColor",children:i.jsx("path",{fillRule:"evenodd",d:"M5.23 7.21a.75.75 0 011.06.02L10 11.168l3.71-3.938a.75.75 0 111.08 1.04l-4.25 4.5a.75.75 0 01-1.08 0l-4.25-4.5a.75.75 0 01.02-1.06z",clipRule:"evenodd"})})]})]}),E&&i.jsx("div",{className:"px-3 py-1.5 space-y-2.5",children:_.map((D,M)=>i.jsx(yg,{entry:D,showTime:!1,isLast:M===_.length-1,defaultThinkingExpanded:!!c,hideApprovalCards:d},M))})]},S.round)}):C&&C.map((S,E)=>i.jsx(yg,{entry:S,showTime:!1,isLast:E===C.length-1,defaultThinkingExpanded:!!c,hideApprovalCards:d},E)),n&&t&&i.jsx(Eae,{content:t}),n&&!t&&i.jsx(Nae,{})]})]})}function zae(e,t){return!!e&&t==="agent"}const Bae=24e3,Hae=200;function ose(e,t,n=Bae){const a=(e??"")+t;return a.length<=n?a:a.slice(a.length-n)}function lse(e,t,n=Hae){const a=[...e??[],t];return a.length<=n?a:a.slice(a.length-n)}function $ae(e){return!!e.text?.trim()||(e.segments??[]).some(t=>t.type==="text"&&(t.content||t.thinking)||t.type==="tool")}function cse(e,t=8){for(let n=e.length-1;n>=Math.max(0,e.length-t);n--){const a=e[n];if(a.isStreaming&&!a.isStopped)return!0}return!1}function KS(e){if(!e||e.length===0)return e;let t=!1;const n=e.map(a=>a.type==="tool"&&a.status==="running"?(t=!0,{...a,status:"stopped"}):a);return t?n:e}function VS(e,t){if(!$ae(e)&&t!=="done")return null;const a={...e,isStreaming:!1,segments:KS(e.segments)};switch(t){case"done":return{...a,isStopped:!1,isError:!1};case"stopped":return{...a,isStopped:!0,isError:!1};case"error":return{...a,isStopped:!0,isError:!0}}}function use(e){const t=[...e];for(let n=t.length-1;n>=0;n--)if(t[n].sender==="agent"&&!t[n].isStopped&&!t[n].isError){const a=VS(t[n],"stopped");a===null?t.splice(n,1):t[n]=a;break}return t}function dse(e,t){const n=e.findIndex(c=>c.id===t);if(n<0)return e;const a=e[n],s=KS(a.segments);if(!a.isStreaming&&s===a.segments)return e;const l=[...e];return l[n]={...a,isStreaming:!1,segments:s},l}function mse(e,t="stopped"){for(let n=e.length-1;n>=0;n--){const a=e[n];if(a.sender==="agent"&&a.isStreaming&&!a.isStopped){const s=VS(a,t);if(s===null)return e.filter((c,d)=>d!==n);const l=[...e];return l[n]=s,l}}return e}function pse(e,t){if(e.some(l=>l.id===t.id))return e;const n=t.rawCreatedAt?Date.parse(t.rawCreatedAt):NaN;if(!Number.isFinite(n)||e.length===0)return[...e,t];let a=e.length;for(;a>0;){const l=e[a-1],c=l.rawCreatedAt?Date.parse(l.rawCreatedAt):NaN;if(!Number.isFinite(c)||c<=n)break;a--}if(a===e.length)return[...e,t];const s=e.slice();return s.splice(a,0,t),s}function fse(e,t){if(!t)return e;const n=e[e.length-1];return n?.type==="text"?[...e.slice(0,-1),{...n,thinking:(n.thinking??"")+t}]:[...e,{type:"text",content:"",thinking:t,createdAt:new Date().toISOString()}]}function hse(e,t){if(!t)return e;const n=e[e.length-1];return n?.type==="text"?[...e.slice(0,-1),{...n,content:n.content+t}]:[...e,{type:"text",content:t,createdAt:new Date().toISOString()}]}const qae=/\n*<!--\s*notify_context:\s*([\s\S]*?)-->/g;function bb(e){if(!e.includes("notify_context"))return{cleaned:e};let t;const n=e.match(/<!--\s*notify_context:\s*([\s\S]*?)-->/);if(n?.[1]){const a=n[1].match(/priority\s*=\s*(\w+)/i);a&&(t=a[1])}return{cleaned:e.replace(qae,"").trimEnd(),priority:t}}const Fae=/(?:<thinking>| thinking)[\s\S]*?<\/thinking>/g,Uae=/(?:<thinking>| thinking| thinking| think)[\s\S]*?<\/think>/g;function gse(e){return e.replace(Fae,"").replace(Uae,"")}function Gae(e,t,n){if(e.type!=="tool"){const{cleaned:d}=bb(e.content??"");return{type:"text",content:d,thinking:e.thinking,createdAt:e.createdAt}}const a=n?.type==="tool"&&n.tool===e.tool?n:void 0,s=e.subagentLogs?.length??0,l=a?.subagentLogs?.length??0,c=s>=l?e.subagentLogs:a?.subagentLogs;return{type:"tool",key:`${e.tool}_${t}`,tool:e.tool,status:e.status,args:e.arguments,result:e.result,error:e.error,durationMs:e.durationMs,createdAt:e.createdAt,...c?.length?{subagentLogs:c}:{}}}function Kae(e,t){const n=(t??[]).filter(s=>s.type==="tool");let a=0;return e.map((s,l)=>{const c=s.type==="tool"?n[a++]:void 0;return Gae(s,l,c)})}const Ld=new Map,Vae=2e3;function WS(e){if(!e)return"";const t=Ld.get(e);if(t!==void 0)return t;const n=new Date(e),a=isNaN(n.getTime())?"":n.toLocaleTimeString();return Ld.size>=Vae&&Ld.clear(),Ld.set(e,a),a}function bse(e){const t={id:e.id,sender:e.role==="user"?"user":"agent",text:e.content,time:WS(e.createdAt),rawCreatedAt:e.createdAt,agentId:e.role!=="user"?e.agentId:void 0};if(e.role!=="user"&&e.metadata?.segments&&e.metadata.segments.length>0&&(t.segments=Kae(e.metadata.segments)),e.role==="assistant"&&(e.content==="[cancelled]"||e.content==="[Stream cancelled]")&&(t.text=""),(e.metadata?.isError||e.role==="assistant"&&e.content.startsWith("⚠"))&&(t.isError=!0),(e.metadata?.emptyReply||e.role==="assistant"&&!e.content&&!e.metadata?.segments?.length&&(e.metadata?.isError||e.metadata?.isStopped))&&(t.emptyReply=!0,t.isStopped||(t.isError=!0)),e.metadata?.isStreaming&&(t.isStreaming=!0),e.metadata?.isStopped&&!e.metadata?.isStreaming&&(t.isStopped=!0),e.metadata?.images?.length&&(t.images=e.metadata.images),e.metadata?.notifyUser&&(t.isNotification=!0,t.notifyPriority=e.metadata.priority,e.metadata.taskId&&(t.taskId=e.metadata.taskId),e.metadata.requirementId&&(t.requirementId=e.metadata.requirementId)),t.text.includes("<!-- notify_context:")){const{cleaned:n,priority:a}=bb(t.text);t.text=n,a&&!t.notifyPriority&&(t.notifyPriority=a),t.isNotification=!0}if(e.metadata?.activityLog&&(t.isActivityLog=!0,t.activityType=e.metadata.activityType,t.outcome=e.metadata.outcome,t.mailboxItemId=e.metadata.mailboxItemId,t.taskId=e.metadata.taskId,t.requirementId=e.metadata.requirementId,!t.outcome&&t.text.startsWith("[ACTIVITY:"))){const n=t.text.lastIndexOf(" → ");n!==-1&&(t.outcome=t.text.slice(n+3)),t.text=t.text.replace(/^\[ACTIVITY:\s*\w+\]\s*/,"")}return e.metadata?.replyToId&&(t.replyToId=e.metadata.replyToId,t.replyToSender=e.metadata.replyToSender,t.replyToText=e.metadata.replyToText,t.text=YS(t.text,t.replyToSender,t.replyToText)),t}function YS(e,t,n){if(!e||!t||!n)return e;const a=`> **${t}**: ${n}
863
863
 
864
864
  `;return e.startsWith(a)?e.slice(a.length):e}function yse(e,t={}){if(t.expectedMessageId)for(let a=e.length-1;a>=0;a--){const s=e[a];if(s.id===t.expectedMessageId&&s.sender==="agent"&&!s.isError)return s}let n=-1;for(let a=e.length-1;a>=0;a--)if(e[a].sender==="user"){n=a;break}for(let a=e.length-1;a>=0;a--){const s=e[a];if(s.sender!=="agent")continue;return s.isStreaming?s:s.isError?void 0:!(s.text?.trim()||(s.segments??[]).some(c=>c.type==="text"&&((c.content??"").trim()||c.thinking)||c.type==="tool"))||t.allowCurrentTurnPartial&&n>=0&&a>n?s:void 0}}function xse(e,t=12e4){if(e.length<2)return e;const n=[];for(const a of e){const s=n[n.length-1];if(a.sender==="user"&&s?.sender==="user"&&s.text===a.text&&s.text.length>0&&s.text.length<=500){const l=s.rawCreatedAt?Date.parse(s.rawCreatedAt):NaN,c=a.rawCreatedAt?Date.parse(a.rawCreatedAt):NaN;if(!Number.isFinite(l)||!Number.isFinite(c)||Math.abs(c-l)<=t)continue}n.push(a)}return n}function vse(e,t){const n=e.senderType==="system"||e.senderType==="agent"&&e.text.startsWith("⚠"),a=e.senderType==="human"&&(!t||e.senderId===t);let s=e.text;a&&e.replyToId&&e.replyToSender&&e.replyToText&&(s=YS(s,e.replyToSender,e.replyToText));const l={id:e.id,sender:a?"user":"agent",text:s,time:WS(e.createdAt),rawCreatedAt:e.createdAt,agentName:a?void 0:e.senderName,agentId:a?void 0:e.senderId,isError:n,replyToId:e.replyToId,replyToSender:e.replyToSender,replyToText:e.replyToText},c=e.metadata;if(c?.images?.length&&(l.images=c.images),c&&e.senderType==="agent"){const d=[];if(c.thinking?.length&&d.push({type:"text",content:"",thinking:c.thinking.join(`
865
865
 
866
866
  `)}),c.toolCalls?.length)for(let m=0;m<c.toolCalls.length;m++){const p=c.toolCalls[m];d.push({type:"tool",key:`${p.tool}_${m}`,tool:p.tool,status:p.status==="error"?"error":"done",args:p.arguments,result:p.result,durationMs:p.durationMs})}d.length>0&&(d.push({type:"text",content:e.text}),l.segments=d)}return l}const Id=new Map,Wae=2e3;function wse(e,t,n){const a=new Date,s=new Date(a.getFullYear(),a.getMonth(),a.getDate()).getTime(),l=t?`${t}|${s}|${e}|${n?.yesterday??""}`:null;if(l){const h=Id.get(l);if(h!==void 0)return h}const c=t?new Date(t):a;if(isNaN(c.getTime()))return e;const d=c.getTime(),m=c.toLocaleTimeString(void 0,{hour:"2-digit",minute:"2-digit",second:"2-digit",hour12:!1});let p;return d>=s?p=m:d>=s-864e5?p=`${n?.yesterday??"Yesterday"} ${m}`:p=c.toLocaleDateString(void 0,{month:"short",day:"numeric"})+" "+m,l&&(Id.size>=Wae&&Id.clear(),Id.set(l,p)),p}function kse(e){if(!e)return"";const t=new Date(e);return isNaN(t.getTime())?"":`${t.getFullYear()}-${t.getMonth()+1}-${t.getDate()}`}function Sse(e,t){const n=new Date(e);if(isNaN(n.getTime()))return"";const a=new Date,s=new Date(a.getFullYear(),a.getMonth(),a.getDate()).getTime(),l=n.getTime();return l>=s?t?.today??"Today":l>=s-864e5?t?.yesterday??"Yesterday":n.toLocaleDateString(void 0,{weekday:"long",year:"numeric",month:"long",day:"numeric"})}function Cse(e,t){return(t?e.metaKey&&!e.ctrlKey:e.ctrlKey&&!e.metaKey)&&!e.altKey&&!e.shiftKey&&e.key.toLowerCase()==="n"?"new-conversation":e.ctrlKey&&!e.metaKey&&!e.altKey&&e.key==="Tab"?e.shiftKey?"cycle-session-prev":"cycle-session-next":null}function Ase(e,t,n){if(e.length<=1)return null;const a=t===null?-1:e.indexOf(t),l=((a>=0?a:n===1?-1:0)+n+e.length)%e.length;return e[l]??null}function Tse(e,t){let n=0,a=null;return((...s)=>{const l=Date.now(),c=t-(l-n);if(c<=0)return a&&(clearTimeout(a),a=null),n=l,e(...s);a||(a=setTimeout(()=>{n=Date.now(),a=null,e(...s)},c))})}const Yae=10,Qae=23,ik={expanded:24,compact:12};function Nse(e){const t=e?ik.compact:ik.expanded;return Yae*Qae+t}function Ese(e,t){return e||t}function jse(e){return e?"justify-end":""}function Mse(e,t,n){return e?t.includes(e)?"detail":n?"missing":"loading":"missing"}function _se({priority:e}){const{t}=ot(["common","team"]),n=e==="high"||e==="critical",a=e&&e!=="normal"?` · ${t(`common:priority.${e}`,{defaultValue:e})}`:"";return i.jsxs("div",{className:`inline-flex items-center gap-1 mt-1.5 px-2 py-0.5 rounded-full text-[10px] font-medium ${n?"bg-amber-500/10 text-amber-500 border border-amber-500/20":"bg-brand-500/10 text-brand-400 border border-brand-500/20"}`,children:[i.jsxs("svg",{className:"w-3 h-3",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[i.jsx("path",{d:"M18 8A6 6 0 0 0 6 8c0 7-3 9-3 9h18s-3-2-3-9"}),i.jsx("path",{d:"M13.73 21a2 2 0 0 1-3.46 0"})]}),i.jsxs("span",{children:[t("team:notifications.badgeLabel"),a]})]})}function Rse({name:e,agentId:t,agents:n,onViewProfile:a}){const{t:s}=ot(["team","common"]),[l,c]=k.useState(!1),d=k.useRef(null),m=t?n.find(p=>p.id===t):n.find(p=>p.name===e);return k.useEffect(()=>{if(!l)return;const p=h=>{d.current&&!d.current.contains(h.target)&&c(!1)};return document.addEventListener("mousedown",p),()=>document.removeEventListener("mousedown",p)},[l]),m?i.jsxs("span",{ref:d,className:"relative inline-block",children:[i.jsx("button",{onClick:()=>c(!l),className:"text-fg-tertiary hover:text-brand-500 cursor-pointer transition-colors",children:e}),l&&i.jsxs("div",{className:"absolute left-0 top-full mt-1.5 bg-surface-secondary border border-border-default rounded-xl shadow-2xl z-40 w-56 p-3 space-y-2",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(Zi,{name:m.name,avatarUrl:m.avatarUrl,size:28,bgClass:"bg-brand-500/15 text-brand-600"}),i.jsxs("div",{className:"flex-1 min-w-0",children:[i.jsx("div",{className:"text-xs text-fg-primary font-medium truncate",children:m.name}),i.jsxs("div",{className:"text-[10px] text-fg-tertiary",children:[m.role," · ",m.agentRole??s("page.workerRole")]})]}),i.jsx("span",{className:`w-2 h-2 rounded-full shrink-0 ${m.status==="working"?"bg-blue-400 animate-pulse":m.status==="error"?"bg-red-400":"bg-green-400"}`})]}),i.jsx("button",{onClick:()=>{c(!1),a?.(m.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("page.viewProfileArrow")})]})]}):i.jsx("span",{children:e})}function Dse({agent:e,anchorRect:t,onClose:n,onViewProfile:a}){const{t:s}=ot(["common","team"]),l=k.useRef(null);k.useEffect(()=>{const p=h=>{l.current&&!l.current.contains(h.target)&&n()};return document.addEventListener("mousedown",p),()=>document.removeEventListener("mousedown",p)},[n]);const c=e.status==="idle"?"bg-green-400":e.status==="working"?"bg-blue-400 animate-pulse":e.status==="error"?"bg-red-400":"bg-gray-500",d=e.status==="idle"?s("common:status.online"):e.status==="working"?s("common:status.working"):e.status==="error"?s("common:status.error"):s("common:status.offline"),m=k.useCallback(p=>{if(!p)return;l.current=p;const h=p.getBoundingClientRect(),g=window.innerWidth,x=window.innerHeight,y=8;h.right>g-y&&(p.style.left=`${Math.max(y,g-h.width-y)}px`),h.left<y&&(p.style.left=`${y}px`),h.bottom>x-y&&(p.style.top=`${Math.max(y,x-h.height-y)}px`)},[]);return i.jsxs("div",{ref:m,className:"fixed z-50 w-64 max-w-[calc(100vw-1rem)] bg-surface-secondary border border-border-default rounded-xl shadow-2xl p-4 space-y-3",style:{top:t.top+40,left:t.left},children:[i.jsxs("div",{className:"flex items-center gap-3",children:[i.jsx(Zi,{name:e.name,avatarUrl:e.avatarUrl,size:40,bgClass:"bg-brand-500/15 text-brand-600"}),i.jsxs("div",{className:"flex-1 min-w-0",children:[i.jsx("div",{className:"text-sm text-fg-primary font-medium truncate",children:e.name}),i.jsx("div",{className:"text-[11px] text-fg-tertiary",children:e.role}),i.jsxs("div",{className:"flex items-center gap-1.5 mt-0.5",children:[i.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${c}`}),i.jsx("span",{className:"text-[10px] text-fg-secondary",children:d}),e.agentRole&&i.jsxs("span",{className:"text-[10px] text-fg-tertiary",children:["· ",e.agentRole]})]})]})]}),i.jsx("button",{onClick:()=>{n(),a(e.id)},className:"w-full py-1.5 text-xs text-brand-500 hover:text-brand-500 border border-border-default hover:border-gray-600 rounded-lg transition-colors text-center",children:s("team:page.viewProfileArrow")})]})}function Xae(e){const t=String(e);return t.includes("MARKUS_UPSTREAM_ERROR")?!1:t.includes("CU_EXCEEDED")||t.includes("CU_MONTHLY_EXCEEDED")}const QS="markus:credit-notif-muted";let sk=0;function Lse(){try{if(localStorage.getItem(QS))return}catch{}const e=Date.now();e-sk<5*6e4||(sk=e,window.dispatchEvent(new CustomEvent("markus:credit-exhausted")))}function Jae(){try{localStorage.setItem(QS,"1")}catch{}}function Ise(e,t){const n=String(e);if(n.includes("AbortError")||n.includes("abort"))return"";let a="";const s=n.match(/\{[\s\S]*\}/);if(s)try{const d=JSON.parse(s[0]);a=d.error?.message??d.message??""}catch{}if(!a){const d=n.lastIndexOf(": ");d>=0&&(a=n.slice(d+2).trim())}const l=(d,m)=>t(`team:errors.${d}`,m);if(n.includes("MARKUS_UPSTREAM_ERROR"))return l("aiUpstreamBillingMismatch",{detail:a||l("defaultUpstreamBillingMismatch")});if(Xae(n)||n.includes("CU_EXCEEDED"))return l("markusCuExceeded");if(n.includes("CU_WINDOW_EXCEEDED"))return l("markusWindowExceeded");if(n.includes("MARKUS_RATE_LIMITED"))return l("markusRateLimited");if(/not available in your region/i.test(n))return l("aiRegionBlocked",{model:(n.match(/\[(?:markus|openrouter):([^\]]+)\]/i)?.[1]||"").trim()||"—"});if(n.includes("401")||/unauthorized|invalid.?api.?key/i.test(n))return l("ai401",{detail:a||l("defaultInvalidApiKey")});if(n.includes("429")||/rate.?limit/i.test(n))return l("ai429",{detail:a||l("defaultTooManyRequests")});if(/\b409\b/.test(n)||/conflict/i.test(n))return l("ai409",{detail:a||l("defaultConflict")});if(n.includes("502")||/bad.?gateway/i.test(n))return l("ai502",{detail:a||l("defaultUpstreamDown")});if(n.includes("503")||/service.?unavailable/i.test(n))return l("ai503",{detail:a||l("defaultServiceDown")});const c=(a||n).replace(/https?:\/\/[^\s]*openrouter\.ai[^\s]*/gi,"").trim();return l("aiGeneric",{detail:(c||n).slice(0,120)})}function Ose({msg:e,onCopy:t,onRetry:n,onResume:a,onReply:s,onRemember:l,isCopied:c,isLastAgentMsg:d,showRemember:m}){const{t:p}=ot(["team","common"]),h=e.isError||e.sender==="agent"&&e.text.startsWith("⚠"),g=e.isStopped,x=!!e.emptyReply||e.sender==="agent"&&!e.text?.trim()&&!e.segments?.some(T=>T.type==="text"&&(T.content||T.thinking)||T.type==="tool"),y=d!==!1,w=zae(m,e.sender)&&!!l;return i.jsxs("div",{className:"flex items-center flex-wrap gap-0.5 mt-1",children:[i.jsxs("button",{onClick:()=>t(e),className:"flex items-center gap-1 px-2 py-0.5 rounded text-[11px] text-fg-tertiary hover:text-fg-primary hover:bg-surface-overlay/60 transition-colors",title:p("common:copy"),children:[c?i.jsx("svg",{className:"w-3.5 h-3.5",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:i.jsx("polyline",{points:"20 6 9 17 4 12"})}):i.jsxs("svg",{className:"w-3.5 h-3.5",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[i.jsx("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2"}),i.jsx("path",{d:"M5 15H4a2 2 0 01-2-2V4a2 2 0 012-2h9a2 2 0 012 2v1"})]}),p(c?"common:copied":"common:copy")]}),y&&a&&i.jsxs("button",{onClick:()=>a(e),className:"flex items-center gap-1 px-2 py-0.5 rounded text-[11px] text-green-500 hover:text-green-400 hover:bg-green-500/10 transition-colors",title:p("page.messageActions.resumeTitle"),children:[i.jsx("svg",{className:"w-3.5 h-3.5",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:i.jsx("polygon",{points:"5 3 19 12 5 21 5 3"})}),p("page.messageActions.resumeTitle")]}),y&&g&&n&&i.jsxs("button",{onClick:()=>n(e),className:"flex items-center gap-1 px-2 py-0.5 rounded text-[11px] text-brand-500 hover:text-brand-500 hover:bg-brand-500/10 transition-colors",title:p("page.messageActions.reaskTitle"),children:[i.jsxs("svg",{className:"w-3.5 h-3.5",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[i.jsx("polyline",{points:"23 4 23 10 17 10"}),i.jsx("path",{d:"M20.49 15a9 9 0 11-2.12-9.36L23 10"})]}),p("page.messageActions.reaskTitle")]}),y&&(h||x)&&!g&&n&&i.jsxs("button",{onClick:()=>n(e),className:"flex items-center gap-1 px-2 py-0.5 rounded text-[11px] text-amber-600 hover:text-amber-600 hover:bg-amber-500/10 transition-colors",title:p("page.messageActions.retryTitle"),children:[i.jsxs("svg",{className:"w-3.5 h-3.5",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[i.jsx("polyline",{points:"23 4 23 10 17 10"}),i.jsx("path",{d:"M20.49 15a9 9 0 11-2.12-9.36L23 10"})]}),p("page.messageActions.retryTitle")]}),y&&!h&&!x&&!g&&e.sender==="agent"&&n&&i.jsxs("button",{onClick:()=>n(e),className:"flex items-center gap-1 px-2 py-0.5 rounded text-[11px] text-fg-tertiary hover:text-fg-primary hover:bg-surface-overlay/60 transition-colors",title:p("page.messageActions.retryTitle"),children:[i.jsxs("svg",{className:"w-3.5 h-3.5",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[i.jsx("polyline",{points:"23 4 23 10 17 10"}),i.jsx("path",{d:"M20.49 15a9 9 0 11-2.12-9.36L23 10"})]}),p("page.messageActions.retryTitle")]}),s&&i.jsxs("button",{onClick:()=>s(e),className:"flex items-center gap-1 px-2 py-0.5 rounded text-[11px] text-fg-tertiary hover:text-fg-primary hover:bg-surface-overlay/60 transition-colors",title:p("page.messageActions.replyTitle"),children:[i.jsxs("svg",{className:"w-3.5 h-3.5",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[i.jsx("polyline",{points:"9 17 4 12 9 7"}),i.jsx("path",{d:"M20 18v-2a4 4 0 00-4-4H4"})]}),p("page.messageActions.replyTitle")]}),w&&i.jsxs("button",{type:"button",onClick:()=>l(e),className:"flex items-center gap-1 px-2 py-0.5 rounded text-[11px] text-fg-tertiary hover:text-fg-primary hover:bg-surface-overlay/60 transition-colors",title:p("page.messageActions.rememberTitle"),children:[i.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:[i.jsx("path",{d:"M12 2a7 7 0 00-4 12.7V19a1 1 0 001 1h6a1 1 0 001-1v-4.3A7 7 0 0012 2z"}),i.jsx("path",{d:"M9 22h6"})]}),p("page.messageActions.rememberTitle")]}),e.sender==="agent"&&i.jsx("span",{className:"ml-1 px-1 text-[10px] leading-none text-fg-tertiary/70 select-none whitespace-nowrap",children:p("page.messageActions.aiGeneratedDisclaimer")})]})}function Pse({busy:e,onConfirm:t,onCancel:n}){const{t:a}=ot(["team","common"]),[s,l]=k.useState("");return zr.createPortal(i.jsx("div",{className:"fixed inset-0 bg-black/60 flex items-center justify-center z-[10050] p-4",onClick:n,children:i.jsxs("div",{className:"bg-surface-secondary border border-border-default rounded-xl p-6 w-[400px] max-w-[calc(100vw-2rem)] shadow-2xl",onClick:c=>c.stopPropagation(),children:[i.jsx("h3",{className:"font-semibold text-base text-fg-primary",children:a("page.messageActions.rememberModalTitle")}),i.jsx("p",{className:"text-sm text-fg-secondary mt-1.5 leading-relaxed",children:a("page.messageActions.rememberModalHint")}),i.jsx("textarea",{value:s,onChange:c=>l(c.target.value),placeholder:a("page.messageActions.rememberModalPlaceholder"),rows:3,disabled:e,className:"mt-3 w-full px-3 py-2 text-sm bg-surface-primary border border-border-default rounded-lg outline-none focus:border-brand-500/50 resize-y min-h-[72px]"}),i.jsxs("div",{className:"flex justify-end gap-2 mt-4",children:[i.jsx("button",{type:"button",onClick:n,disabled:e,className:"px-4 py-1.5 text-sm text-fg-secondary hover:text-fg-primary rounded-lg transition-colors",children:a("page.messageActions.rememberCancel")}),i.jsx("button",{type:"button",onClick:()=>t(s),disabled:e,className:"px-4 py-1.5 text-sm bg-brand-600 hover:bg-brand-500 disabled:opacity-60 text-white rounded-lg transition-colors",children:e?a("common:loading",{defaultValue:"…"}):a("page.messageActions.rememberConfirm")})]})]})}),document.body)}const Zae=/[.!?。!?…::]\s*$|["'”’)\]}】》]\s*$|\n\s*$/,ere=/^(?:\n|#{1,6}[ \t]|[-*+][ \t]|\d+[.)][ \t]|>|\||```|~~~|---)/;function tre(e,t){return!(!e.replace(/\s+$/,"")||Zae.test(e)||!t.trim()||ere.test(t))}function nre(e,t,n){return/\s$/.test(e)||/^\s/.test(t)?e+t:n?.spaceNeeded?`${e} ${t}`:e+t}function are(e){const t=l=>l.type!=="text"||l.metadata?.isThinking===!0,n=[];let a=[],s=-1;for(const l of e){if(t(l)){a.push(l);continue}const c=s>=0?n[s]:void 0;if(c&&a.length>0&&l.metadata?.paragraphBreak!==!0&&c.metadata?.paragraphAfter!==!0&&tre(c.content,l.content)){c.content=nre(c.content,l.content,{spaceNeeded:c.metadata?.trailingSpace===!0||l.metadata?.leadingSpace===!0}),n.push(...a),a=[];continue}a.length>0&&(n.push(...a),a=[]),n.push(l),s=n.length-1}return a.length>0&&n.push(...a),n}function rre(e){return e.type!=="text"||e.metadata?.isThinking===!0}function XS(e){const t=Date.parse(e[0]?.createdAt??""),n=Date.parse(e[e.length-1]?.createdAt??"");return Number.isFinite(t)&&Number.isFinite(n)&&n>t?n-t:0}function ire(e){let t=0,n=0,a=0,s=null,l=0;for(const d of e){if(d.type==="text"&&d.metadata?.isThinking===!0){t++;continue}if(d.type==="tool_start"){n++,s=d.content;continue}if(d.type==="tool_end"){d.metadata?.success===!1&&l++,s=null;continue}d.type==="subagent_start"&&a++,d.type==="error"&&l++}const c=XS(e);return{thinkingCount:t,toolCount:n,subagentCount:a,running:s!==null,...s?{runningTool:s}:{},tailIsThinking:e[e.length-1]?.type==="text"&&e[e.length-1]?.metadata?.isThinking===!0,elapsedMs:c,errorCount:l}}function sre(e){const t=[];let n=[],a=0;const s=()=>{n.length!==0&&(t.push({kind:"process",key:`proc_${a}`,entries:n,summary:ire(n)}),n=[])};return e.forEach((l,c)=>{if(rre(l)){n.length===0&&(a=c),n.push(l);return}s(),t.push({kind:"text",key:`text_${c}`,entry:l})}),s(),t}function ore(e){for(let t=e.length-1;t>=0;t--)if(e[t].kind==="text")return t;return-1}function lre(e,t){if(t)return 0;const n=ore(e);return n>0?n:0}function cre(e,t){const n=Math.max(0,Math.round(e/1e3));return n<60?t("common:execution.workedForSeconds",{seconds:n}):t("common:execution.workedForMinutes",{minutes:Math.floor(n/60),seconds:n%60})}function JS({state:e}){return e==="running"?i.jsx("span",{className:"animate-spin inline-flex",children:i.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round","aria-hidden":"true",children:i.jsx("path",{d:"M12 3a9 9 0 1 0 9 9"})})}):i.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:i.jsx("path",{d:"M20 6.5 9.5 17 4 11.5"})})}function ure({entries:e,summary:t,isStreaming:n,isLastBlock:a,hideApprovalCards:s,reconnecting:l}){const{t:c}=ot("common"),[d,m]=k.useState(!1),p=k.useMemo(()=>bg(e.map(gb).filter(C=>C!==null)),[e]),h=!!(n&&(a||t.running))||!!l,g=h?"running":"done",x=l?c("execution.reconnecting"):h&&t.runningTool?c("execution.processRun.runningTool",{tool:c(`execution.tools.${t.runningTool}`,{defaultValue:t.runningTool})}):null,y=[];t.thinkingCount>0&&y.push(c("execution.processRun.thinking")),t.toolCount>0&&y.push(c("execution.processRun.tools",{count:t.toolCount})),t.subagentCount>0&&y.push(c("execution.processRun.subagents",{count:t.subagentCount})),t.errorCount>0&&y.push(c("execution.processRun.errors",{count:t.errorCount})),t.elapsedMs>=1e3&&y.push($s(t.elapsedMs));const w=h?x??c("execution.thinkingEllipsis"):y.join(" · ")||c("execution.processRun.label"),T=c(`execution.processRun.state.${g}`);return i.jsxs("div",{className:"min-w-0",children:[i.jsxs("button",{type:"button",onClick:()=>m(C=>!C),"aria-expanded":d,"data-process-state":g,title:w,className:"group relative w-full flex items-center gap-2 px-2 py-1 rounded-lg text-left text-[11px] leading-tight text-fg-tertiary bg-surface-elevated/25 hover:bg-surface-elevated/45 border border-border-default/40 hover:border-border-default/70 overflow-hidden transition-colors cursor-pointer select-none",children:[h&&i.jsx("span",{className:"process-run-sweep","aria-hidden":"true"}),i.jsx("span",{className:`relative shrink-0 flex items-center justify-center w-3 h-3 ${g==="running"?"text-brand-400":""}`,children:i.jsx(JS,{state:g})}),i.jsx("span",{className:"sr-only",children:T}),i.jsx("span",{className:`relative min-w-0 truncate ${h&&!x?"activity-text-shimmer":""}`,children:h||y.length===0?w:y.map((C,S)=>i.jsxs("span",{children:[S>0?" · ":"",C]},C+S))}),i.jsx("svg",{className:`relative ml-auto w-3 h-3 shrink-0 transition-transform ${d?"rotate-180":""}`,viewBox:"0 0 20 20",fill:"currentColor","aria-hidden":"true",children:i.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"})})]}),d&&i.jsx("div",{className:"mt-1 ml-[7px] pl-3 border-l-2 border-border-default/50 space-y-2 min-w-0 overflow-hidden",children:p.length>0?p.map((C,S)=>i.jsx(yg,{entry:C,showTime:!1,hideApprovalCards:s},S)):i.jsx("div",{className:"py-1 text-[11px] text-fg-tertiary",children:c("execution.noToolDetail")})})]})}function ok(e,t,n){if(!e)return[];const a=[];let s=0;const l=t??"";let d=n?new Date(n).getTime():Date.now();const m=e.some(E=>E.createdAt),p=E=>{if(E.createdAt)return E.createdAt;if(m)return new Date(d).toISOString();const _=new Date(d).toISOString();return E.type==="tool"&&E.durationMs?d+=E.durationMs:d+=1e3,_};let h="",g="",x="";const y=()=>{const E=h.trim();if(E){const _=a[a.length-1];_&&_.type==="text"&&_.metadata?.isThinking?_.content+=(_.content?`
867
867
 
868
868
  `:"")+E:a.push({id:`cseg_${s}`,sourceType:"chat",sourceId:"",agentId:l,seq:s++,type:"text",content:E,createdAt:x,metadata:{isThinking:!0}})}h=""},w=()=>{const E=g,_=E.trim();if(_){const L={};/^\s*\n/.test(E)&&(L.paragraphBreak=!0),/\n\s*\n\s*$/.test(E)&&(L.paragraphAfter=!0),/\s$/.test(E)&&(L.trailingSpace=!0),/^\s/.test(E)&&(L.leadingSpace=!0),a.push({id:`cseg_${s}`,sourceType:"chat",sourceId:"",agentId:l,seq:s++,type:"text",content:_,createdAt:x,...Object.keys(L).length>0?{metadata:L}:{}})}g=""},T="<think>",C="</think>",S=E=>{let _=0,L=!1;for(;_<E.length;)if(L){const D=E.indexOf(C,_);D===-1?_=E.length:(L=!1,_=D+C.length)}else{const D=E.indexOf(T,_);D===-1?(g+=E.slice(_),_=E.length):(g+=E.slice(_,D),L=!0,_=D+T.length)}};for(const E of e)if(x=p(E),E.type==="tool"){w();const _=E.createdAt&&E.durationMs?new Date(new Date(E.createdAt).getTime()-E.durationMs).toISOString():x;a.push({id:`cseg_${s}`,sourceType:"chat",sourceId:"",agentId:l,seq:s++,type:"tool_start",content:E.tool,metadata:{arguments:E.args,...E.status==="running"&&E.subagentLogs?.length?{subagentLogs:E.subagentLogs}:{}},createdAt:_}),E.status!=="running"&&a.push({id:`cseg_${s}`,sourceType:"chat",sourceId:"",agentId:l,seq:s++,type:"tool_end",content:E.tool,metadata:{arguments:E.args,result:E.result,error:E.error,durationMs:E.durationMs,success:E.status!=="error",...E.subagentLogs?.length?{subagentLogs:E.subagentLogs}:{}},createdAt:x})}else E.thinking&&(w(),h+=E.thinking,y()),S(bb(E.content).cleaned);return w(),are(a)}const zse=k.memo(function({msg:t,isStreaming:n,liveActivities:a,onMentionClick:s,knownNames:l}){const{t:c}=ot(["team","common"]),d=t.segments,m=t.isStopped,[p,h]=k.useState(!1),g=D=>D.type==="text"?D.content.length+(D.thinking?.length??0):(D.result?.length??0)+(D.subagentLogs?.length??0)*1e3+(D.liveOutput?.length??0),x=d?d.length+":"+(d.length>0?g(d[d.length-1]):0):"",y=d?d.reduce((D,M)=>D+(M.type==="tool"?M.subagentLogs?.length??0:0),0):0,w=k.useMemo(()=>d&&d.length>0?ok(d,t.agentId,t.rawCreatedAt):[],[x,y,t.agentId,t.rawCreatedAt]),T=t.committedSegments,C=T?T.length+":"+(T.length>0?g(T[T.length-1]):0):"",S=T?T.reduce((D,M)=>D+(M.type==="tool"?M.subagentLogs?.length??0:0),0):0,E=k.useMemo(()=>n?w:T&&T.length>0?ok(T,t.agentId,t.rawCreatedAt):w,[n,C,S,t.agentId,t.rawCreatedAt,w]);if(d!==void 0&&d.length>0){const M=d.filter(I=>I.type==="text").map(I=>I.content).join(""),O=I=>I.replace(/\n*<!--\s*notify_context:\s*[\s\S]*?-->/g,"").replace(/<think>[\s\S]*?(<\/think>|$)/g,"").replace(/<(invoke|function_calls|antml:\w+)\b[\s\S]*?(<\/\1>|$)/g,"").replace(/<\/?(invoke|function_calls|antml:\w+)[^>]*>/g,"").trim()||null,Q=(M?O(M):null)||(t.text?O(t.text):null),$=sre(E),Y=$.some(I=>I.kind==="text"),K=lre($,n),ee=K>0&&!p?K:0,U=cre(XS(E),c),te=[];for(const I of d){if(I.type!=="tool")continue;const J=BS(I.tool,I.result);if(J){te.push({key:`task-${J.taskId}`,kind:"task",info:J});continue}const me=HS(I.tool,I.result);me&&te.push({key:`req-${me.requirementId}`,kind:"req",info:me})}return i.jsxs("div",{className:"space-y-2 min-h-[1em] min-w-0 overflow-x-hidden",children:[K>0&&i.jsxs("button",{type:"button",onClick:()=>h(I=>!I),"aria-expanded":p,"data-worked-summary":"true",title:U,className:"group relative w-full flex items-center gap-2 px-2 py-1 rounded-lg text-left text-[11px] leading-tight text-fg-tertiary bg-surface-elevated/25 hover:bg-surface-elevated/45 border border-border-default/40 hover:border-border-default/70 overflow-hidden transition-colors cursor-pointer select-none",children:[i.jsx("span",{className:"relative shrink-0 flex items-center justify-center w-3 h-3",children:i.jsx(JS,{state:"done"})}),i.jsx("span",{className:"relative min-w-0 truncate",children:U}),i.jsx("svg",{className:`relative ml-auto w-3 h-3 shrink-0 transition-transform ${p?"rotate-180":""}`,viewBox:"0 0 20 20",fill:"currentColor","aria-hidden":"true",children:i.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"})})]}),$.slice(ee).map((I,J)=>{const me=J+ee;return I.kind==="text"?i.jsx(Ea,{content:I.entry.content,onMentionClick:s,knownNames:l},I.key):i.jsx(ure,{entries:I.entries,summary:I.summary,isStreaming:n,isLastBlock:me===$.length-1,hideApprovalCards:!0,reconnecting:!!t.reconnecting},I.key)}),$.length===0&&n&&i.jsx(Jw,{activities:a,isActive:!0}),!Y&&Q&&i.jsx(Ea,{content:Q,onMentionClick:s,knownNames:l}),te.map(I=>I.kind==="task"?i.jsx(US,{info:I.info},I.key):i.jsx(GS,{info:I.info},I.key)),!n&&!Q&&$.length===0&&te.length===0&&!m&&(t.emptyReply||!t.isError)&&i.jsx("div",{className:"flex items-start gap-1.5 text-[13px] text-fg-tertiary leading-relaxed",children:i.jsx("span",{children:c("page.emptyReply")})}),!n&&(t.isError||t.text.startsWith("⚠"))&&t.text&&!d?.some(I=>I.type==="text"&&I.content&&(I.content===t.text||I.content.startsWith("⚠")))&&i.jsx("p",{className:"mt-1.5 text-[13px] text-fg-tertiary leading-relaxed whitespace-pre-wrap",children:t.text.replace(/^⚠\s*/,"")}),m&&i.jsxs("div",{className:"flex items-center gap-1.5 mt-1.5 text-[11px] text-fg-tertiary",children:[i.jsx("svg",{className:"w-3 h-3 shrink-0",viewBox:"0 0 24 24",fill:"currentColor",children:i.jsx("rect",{x:"4",y:"4",width:"16",height:"16",rx:"2"})}),i.jsx("span",{children:c("page.stopped")})]})]})}const _=(t.activities?.length??0)>0,L=t.text?t.text.replace(/<think>[\s\S]*?(<\/think>|$)/g,"").replace(/<(invoke|function_calls|antml:\w+)\b[\s\S]*?(<\/\1>|$)/g,"").replace(/<\/?(invoke|function_calls|antml:\w+)[^>]*>/g,"").trim():"";return i.jsxs(i.Fragment,{children:[(n||_)&&i.jsx(Jw,{activities:n?a:t.activities??[],isActive:n,persistent:!n&&_}),L?t.isError||L.startsWith("⚠")?i.jsx("p",{className:"text-[13px] text-fg-tertiary leading-relaxed whitespace-pre-wrap",children:L.replace(/^⚠\s*/,"")}):i.jsx(Ea,{content:L,onMentionClick:s,knownNames:l}):null,!n&&!L&&!_&&!m&&t.sender==="agent"&&(t.emptyReply||!t.isError)&&i.jsx("div",{className:"flex items-start gap-1.5 text-[13px] text-fg-tertiary leading-relaxed",children:i.jsx("span",{children:c("page.emptyReply")})}),m&&i.jsxs("div",{className:"flex items-center gap-1.5 mt-1.5 text-[11px] text-fg-tertiary",children:[i.jsx("svg",{className:"w-3 h-3 shrink-0",viewBox:"0 0 24 24",fill:"currentColor",children:i.jsx("rect",{x:"4",y:"4",width:"16",height:"16",rx:"2"})}),i.jsx("span",{children:c("page.stopped")})]})]})});function dre(e){return e.questions&&e.questions.length>0?e.questions:e.options&&e.options.length>0?[{id:"q1",prompt:e.description||e.title,inputType:"choice",options:e.options,allowMultiple:!1,allowFreeform:e.allowFreeform}]:[{id:"q1",prompt:e.description||e.title,inputType:"text",allowFreeform:!0}]}function mre({approval:e,submitting:t,readOnly:n,onClose:a,onSubmit:s}){const{t:l}=ot(["team","common"]);Qo(!0);const c=k.useMemo(()=>dre(e),[e]),[d,m]=k.useState(0),[p,h]=k.useState(()=>{if(n&&e.answers&&e.answers.length>0){const D={};for(const M of e.answers)D[M.questionId]={selectedOptionIds:M.selectedOptionIds??[],text:M.text??""};return D}return{}}),g=c[d],x=d===c.length-1,y=c.length>1,w=D=>p[D]??{selectedOptionIds:[],text:""},T=(D,M)=>{h(O=>({...O,[D]:{...w(D),...M}}))},C=(D,M)=>{const O=w(D.id);if(D.allowMultiple){const G=O.selectedOptionIds.includes(M);T(D.id,{selectedOptionIds:G?O.selectedOptionIds.filter(Q=>Q!==M):[...O.selectedOptionIds,M],text:G?O.text:""})}else{const G=O.selectedOptionIds.includes(M);T(D.id,{selectedOptionIds:G?[]:[M],text:G?O.text:""})}},S=D=>{const M=w(D.id);return D.inputType==="choice"?M.selectedOptionIds.length>0?!0:!!(D.allowFreeform&&M.text.trim()):M.text.trim().length>0},E=c.every(S),_=()=>c.map(D=>{const M=w(D.id),O={questionId:D.id};return M.selectedOptionIds.length>0&&(O.selectedOptionIds=M.selectedOptionIds),M.text.trim()&&(O.text=M.text.trim()),O}),L=()=>{const D=_();let M=!0,O;if(!e.questions?.length&&e.options?.length){const Q=D[0];O=Q?.selectedOptionIds?.[0]??(Q?.text?"custom":void 0),M=O!=="reject"&&O!=="request_changes"}const G=D.map(Q=>Q.text).filter(Boolean).join(`
869
- `)||void 0;s({approved:M,comment:G,selectedOption:O,answers:D})};return zr.createPortal(i.jsx("div",{className:"fixed inset-0 z-[10000] flex items-center justify-center p-4 bg-black/50 backdrop-blur-sm",onMouseDown:D=>{D.target===D.currentTarget&&a()},children:i.jsxs("div",{className:"w-full max-w-2xl max-h-[85vh] flex flex-col bg-surface-secondary border border-border-default rounded-2xl shadow-2xl overflow-hidden",children:[i.jsxs("div",{className:"flex items-start gap-3 px-6 py-4 border-b border-border-default shrink-0",children:[i.jsx("div",{className:"w-9 h-9 rounded-lg bg-amber-500/15 text-amber-500 flex items-center justify-center shrink-0",children:i.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[i.jsx("path",{d:"M12 2a10 10 0 1 0 0 20 10 10 0 0 0 0-20z"}),i.jsx("path",{d:"M12 8v4"}),i.jsx("path",{d:"M12 16h.01"})]})}),i.jsxs("div",{className:"flex-1 min-w-0",children:[i.jsx("h2",{className:"text-base font-semibold text-fg-primary leading-snug",children:e.title}),i.jsxs("div",{className:"flex items-center gap-2 mt-0.5",children:[i.jsx("p",{className:"text-xs text-fg-tertiary",children:e.agentName}),n&&i.jsxs("span",{className:"inline-flex items-center gap-1 px-1.5 py-0.5 rounded text-[10px] font-medium bg-green-500/15 text-green-600",children:[i.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"3",strokeLinecap:"round",strokeLinejoin:"round",children:i.jsx("path",{d:"M20 6L9 17l-5-5"})}),l("team:userInput.submitted",{defaultValue:"Submitted"})]})]})]}),i.jsx("button",{onClick:a,className:"p-1.5 text-fg-tertiary hover:text-fg-primary rounded-md hover:bg-surface-overlay transition-colors shrink-0",title:l("common:close"),children:i.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[i.jsx("path",{d:"M18 6L6 18"}),i.jsx("path",{d:"M6 6l12 12"})]})})]}),i.jsxs("div",{className:"flex-1 overflow-y-auto px-6 py-5 space-y-4",children:[y&&i.jsx("div",{className:"flex items-center gap-2",children:c.map((D,M)=>i.jsx("button",{onClick:()=>m(M),className:`h-1.5 flex-1 rounded-full transition-colors ${M===d?"bg-brand-500":S(D)?"bg-green-500/60":"bg-border-default"}`,title:`${M+1}. ${D.prompt.slice(0,40)}`},D.id))}),y&&i.jsx("div",{className:"text-[11px] font-medium text-fg-tertiary",children:l("team:userInput.questionProgress",{current:d+1,total:c.length,defaultValue:`Question ${d+1} of ${c.length}`})}),i.jsx("div",{className:"text-sm text-fg-primary leading-relaxed",children:i.jsx(Ea,{content:g.prompt})}),g.inputType==="choice"&&g.options&&i.jsx("div",{className:"space-y-2",children:g.options.map((D,M)=>{const O=w(g.id).selectedOptionIds.includes(D.id);return i.jsxs("button",{onClick:n?void 0:()=>C(g,D.id),disabled:n,className:`w-full px-4 py-3 text-left rounded-xl border transition-colors flex items-start gap-3 ${O?"border-brand-500 bg-brand-500/10":`border-border-default ${n?"":"hover:bg-surface-overlay"}`} ${n?"cursor-default":""} ${n&&!O?"opacity-50":""}`,children:[i.jsx("span",{className:`w-6 h-6 rounded-full flex items-center justify-center text-[11px] font-bold shrink-0 mt-0.5 ${O?"bg-brand-600 text-white":"bg-surface-overlay text-fg-tertiary"}`,children:O?i.jsx("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"3",strokeLinecap:"round",strokeLinejoin:"round",children:i.jsx("path",{d:"M20 6L9 17l-5-5"})}):String.fromCharCode(65+M)}),i.jsxs("span",{className:"flex-1 min-w-0 text-sm text-fg-primary [&_p]:my-0 [&_p]:text-sm",children:[i.jsx(Ea,{content:D.label}),D.description&&i.jsx("span",{className:"block text-xs text-fg-tertiary mt-1 [&_p]:my-0 [&_p]:text-xs",children:i.jsx(Ea,{content:D.description})})]})]},D.id)})}),(g.inputType==="text"||g.allowFreeform)&&(!n||w(g.id).text)&&i.jsx("textarea",{rows:g.inputType==="text"?4:2,readOnly:n,placeholder:g.inputType==="text"?l("team:userInput.textPlaceholder",{defaultValue:"Type your answer…"}):l("team:userInput.freeformPlaceholder",{defaultValue:"Or write your own answer…"}),value:w(g.id).text,onChange:D=>{const M=D.target.value;T(g.id,{text:M,selectedOptionIds:M.trim()&&g.inputType==="choice"?[]:w(g.id).selectedOptionIds})},className:`w-full px-3.5 py-2.5 text-sm bg-surface-overlay border border-border-default rounded-xl text-fg-primary placeholder:text-fg-tertiary focus:outline-none resize-y ${n?"cursor-default opacity-80":"focus:ring-1 focus:ring-brand-500/50"}`})]}),i.jsxs("div",{className:"flex items-center justify-between gap-2 px-6 py-4 border-t border-border-default shrink-0",children:[i.jsx("div",{children:y&&d>0&&i.jsx("button",{onClick:()=>m(D=>Math.max(0,D-1)),className:"px-4 py-2 text-sm font-medium text-fg-secondary border border-border-default rounded-lg hover:bg-surface-overlay transition-colors",children:l("team:userInput.previous",{defaultValue:"Previous"})})}),i.jsx("div",{className:"flex items-center gap-2",children:y&&!x?i.jsx("button",{disabled:!n&&!S(g),onClick:()=>m(D=>Math.min(c.length-1,D+1)),className:"px-5 py-2 text-sm font-medium bg-brand-600 text-white rounded-lg hover:bg-brand-700 disabled:opacity-50 transition-colors",children:l("team:userInput.next",{defaultValue:"Next"})}):n?i.jsx("button",{onClick:a,className:"px-5 py-2 text-sm font-medium text-fg-secondary border border-border-default rounded-lg hover:bg-surface-overlay transition-colors",children:l("common:close",{defaultValue:"Close"})}):i.jsxs("button",{disabled:t||!E,onClick:L,className:"px-5 py-2 text-sm font-medium bg-brand-600 text-white rounded-lg hover:bg-brand-700 disabled:opacity-50 transition-colors inline-flex items-center gap-2",children:[t&&i.jsxs("svg",{className:"animate-spin h-4 w-4",viewBox:"0 0 24 24",fill:"none",children:[i.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),i.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"})]}),l("team:userInput.submit",{defaultValue:"Submit"})]})})]})]})}),document.body)}function Od(e){return Array.isArray(e.questions)&&e.questions.length>0}const Pd={urgent:"bg-red-500",high:"bg-amber-500",normal:"bg-blue-500",low:"bg-gray-400"},Io={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"},lk={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 Oo(e,t){const n=Date.now()-new Date(e).getTime(),a=Math.floor(n/6e4);if(a<1)return t("common:time.now");if(a<60)return t("common:time.minutesAgo",{count:a});const s=Math.floor(a/60);return s<24?t("common:time.hoursAgo",{count:s}):t("common:time.daysAgo",{count:Math.floor(s/24)})}const ck="markus:template-updates-ack";let ph=!1,zd=null;function pre(e){return e.map(t=>`${t.name}@${t.availableVersion}`).sort().join(",")}function uk(e,t){if(e.type!=="system"||!e.metadata?.templateUpdates)return!1;if(!t)return!0;const n=e.metadata.templateUpdatesFingerprint;return!n||n===t}function Bd(e,t){const n=e.actionType;if(n==="open_chat")return t("team:notifications.actionHints.openChat");if(n==="navigate")return t("team:notifications.actionHints.viewDetails");const a=e.metadata??{};switch(e.type){case"task_completed":case"task_created":case"task_review":case"task_failed":return a.taskId?t("team:notifications.actionHints.viewTask"):null;case"requirement_created":case"requirement_decision":return a.requirementId?t("team:notifications.actionHints.viewRequirement"):null;case"agent_report":return a.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");case"system":return a.templateUpdates?t("common:templateUpdates.actionHint"):null;default:return a.taskId?t("team:notifications.actionHints.viewTask"):a.requirementId?t("team:notifications.actionHints.viewRequirement"):a.agentId?t("team:notifications.actionHints.viewAgent"):null}}function ZS(e){const t=e.metadata;if(!(!t||typeof t.i18n!="object"||!t.i18n))return t.i18n}function dk(e,t){const n=ZS(e);if(!n?.titleKey)return e.title;const a={...n.titleParams??{}};return t(`team:${n.titleKey}`,{...a,defaultValue:e.title})}function mk(e,t){const n=ZS(e);if(!n?.bodyKey)return e.body;const a={};for(const[s,l]of Object.entries(n.bodyParams??{}))a[s]=s==="status"||s==="statusKey"?t(`common:status.${l}`,{defaultValue:l}):l;return t(`team:${n.bodyKey}`,{...a,defaultValue:e.body})}function fh(){try{const e=new AudioContext,t=e.currentTime,n=e.createGain();n.connect(e.destination),n.gain.setValueAtTime(.15,t),n.gain.exponentialRampToValueAtTime(.01,t+.6);const a=e.createOscillator();a.type="sine",a.frequency.setValueAtTime(880,t),a.frequency.setValueAtTime(1174.66,t+.15),a.connect(n),a.start(t),a.stop(t+.6),a.onended=()=>e.close()}catch{}}function fre({collapsed:e,userId:t,embeddedMode:n,onClose:a,sidebarMode:s,isActive:l,label:c,iconPath:d}){const{t:m}=ot(["team","common"]),[p,h]=k.useState(!1),[g,x]=k.useState("approvals"),[y,w]=k.useState([]),[T,C]=k.useState([]),[S,E]=k.useState(null),[_,L]=k.useState(null),[D,M]=k.useState(null),[O,G]=k.useState({}),[Q,$]=k.useState(0),[Y,K]=k.useState([]),ee=k.useRef(null),U=k.useRef(null),[te,I]=k.useState({top:0,left:0,width:448,maxHeight:576}),J=k.useRef(null),me=k.useRef(!1),[Ce,H]=k.useState(!0),[V,fe]=k.useState(!1),z=k.useRef(null),je=k.useRef("approvals"),[Ue,qe]=k.useState(!1),[He,ut]=k.useState("unread"),dt=30,Nt=100,wt=k.useCallback(async()=>{try{li("/approvals"),li("/notifications");const[F,ge,Xe]=await Promise.all([Ae.notifications.list(t,!1,{limit:dt,offset:0}),Ae.approvals.list(),Ae.notifications.list(t,!0,{limit:Nt,offset:0})]);w(F.notifications),K(Xe.notifications);const ye=F.unreadCount??F.notifications.filter(tt=>!tt.read).length;if($(ye),H(F.totalCount!=null?F.notifications.length<F.totalCount:F.notifications.length>=dt),C(ge.approvals),!me.current){const tt=ge.approvals.filter(ft=>ft.status==="pending").length;J.current=tt,me.current=!0}}catch{}},[t]),Zt=k.useCallback(async()=>{if(!(V||!Ce)){fe(!0);try{const F=await Ae.notifications.list(t,!1,{limit:dt,offset:y.length});F.notifications.length>0&&w(ge=>[...ge,...F.notifications.filter(Xe=>!ge.some(ye=>ye.id===Xe.id))]),H(F.totalCount!=null?y.length+F.notifications.length<F.totalCount:F.notifications.length>=dt)}catch{}fe(!1)}},[t,y.length,V,Ce]),Wt=k.useCallback(F=>{const ge=F.detail;if(!ge)return;const{taskId:Xe,requirementId:ye}=ge;!Xe&&!ye||w(tt=>{const ft=tt.filter(bt=>!bt.read&&(Xe&&bt.metadata?.taskId===Xe||ye&&bt.metadata?.requirementId===ye));if(ft.length===0)return tt;for(const bt of ft)Ae.notifications.markRead(bt.id).catch(()=>{});$(bt=>Math.max(0,bt-ft.length));const Ht=new Set(ft.map(bt=>bt.id));return K(bt=>bt.filter(le=>!Ht.has(le.id))),tt.map(bt=>ft.some(le=>le.id===bt.id)?{...bt,read:!0}:bt)})},[]),rt=k.useRef(y);rt.current=y;const $e=k.useCallback(async()=>{if(!rt.current.some(ge=>!ge.read&&ge.type==="system"&&ge.metadata?.creditExhausted))try{await Ae.notifications.create({title:m("credits.notificationTitle",{ns:"common"}),body:m("credits.notificationBody",{ns:"common"}),type:"system",priority:"urgent",metadata:{creditExhausted:!0}}),wt(),fh()}catch{}},[wt,m]),mt=k.useCallback(async()=>{if(!ph){ph=!0;try{const{updates:F}=await Ae.skills.updates();if(!F.length)return;const ge=pre(F);try{if(localStorage.getItem(ck)===ge)return}catch{}if(zd===ge||rt.current.some(ye=>!ye.read&&uk(ye,ge)))return;try{const tt=(await Ae.notifications.list(t,!0,{limit:50,type:"system"})).notifications.filter(ft=>uk(ft,ge)).sort((ft,Ht)=>new Date(Ht.createdAt).getTime()-new Date(ft.createdAt).getTime());if(tt.length>0){for(const ft of tt.slice(1))Ae.notifications.markRead(ft.id).catch(()=>{});tt.length>1&&wt(),zd=ge;return}}catch{}zd=ge,await Ae.notifications.create({title:m("templateUpdates.notificationTitle",{ns:"common"}),body:m("templateUpdates.notificationBody",{ns:"common",count:F.length}),type:"system",priority:"high",metadata:{templateUpdates:!0,templateUpdatesFingerprint:ge,count:F.length,skills:F.map(ye=>ye.name)}}),wt(),fh()}catch{zd=null}finally{ph=!1}}},[wt,m,t]);k.useEffect(()=>{wt();const F=setInterval(wt,6e4);let ge=null;const Xe=()=>{ge||(ge=setTimeout(()=>{ge=null,wt()},400))},ye=()=>Xe(),tt=()=>{h(!0),wt()};window.addEventListener("markus:notifications-changed",ye),window.addEventListener("markus:mark-read-by-ref",Wt),window.addEventListener("markus:open-notifications",tt),window.addEventListener("markus:credit-exhausted",$e);const ft=Ir.on("notification",Xe),Ht=Ir.on("approval:requested",Xe);return()=>{clearInterval(F),ge&&clearTimeout(ge),window.removeEventListener("markus:notifications-changed",ye),window.removeEventListener("markus:mark-read-by-ref",Wt),window.removeEventListener("markus:open-notifications",tt),window.removeEventListener("markus:credit-exhausted",$e),ft(),Ht()}},[wt,Wt,$e]),k.useEffect(()=>{mt();const F=setInterval(()=>{mt()},5*6e4),ge=()=>{mt()};return window.addEventListener("markus:data-changed",ge),()=>{clearInterval(F),window.removeEventListener("markus:data-changed",ge)}},[t]);const At=k.useCallback(()=>{if(!ee.current)return;const F=ee.current.getBoundingClientRect(),ge=window.innerWidth,Xe=window.innerHeight,ye=Math.min(448,ge-16),tt=Math.min(576,Xe-16);let ft=F.right+8,Ht=F.top;ft+ye>ge-8&&(ft=Math.max(8,ge-ye-8)),Ht+tt>Xe-8&&(Ht=Math.max(8,Xe-tt-8)),I({top:Ht,left:ft,width:ye,maxHeight:tt})},[]);k.useLayoutEffect(()=>{p&&At()},[p,At]),k.useEffect(()=>{if(p)return window.addEventListener("resize",At),()=>window.removeEventListener("resize",At)},[p,At]),k.useEffect(()=>{if(!p)return;const F=ge=>{ee.current?.contains(ge.target)||U.current?.contains(ge.target)||h(!1)};return document.addEventListener("mousedown",F),()=>document.removeEventListener("mousedown",F)},[p]),k.useEffect(()=>{if(!p)return;ut("unread");const F=T.some(Xe=>Xe.status==="pending"),ge=y.some(Xe=>!Xe.read);x(F&&!ge?"approvals":!F&&ge?"notifications":je.current)},[p]);const Dt=new Set(T.filter(F=>F.status==="pending").map(F=>F.id)),ln=new Set(T.map(F=>F.id)),ce=F=>F.type==="approval_request"&&!!F.metadata?.approvalId&&ln.has(F.metadata.approvalId),et=F=>[...F].sort((ge,Xe)=>new Date(Xe.createdAt).getTime()-new Date(ge.createdAt).getTime()),nt=y.filter(F=>!ce(F)),we=Y.filter(F=>!ce(F)),Me=et(nt),Ne=et(we),se=He==="all"?Me:Ne,q=m(He==="unread"?"team:notifications.noUnread":"team:notifications.noNotifications"),ae=Ne.length,Se=Dt.size,De=ae+Se;k.useEffect(()=>{J.current!==null&&Se>J.current&&fh(),J.current=Se},[Se]);const Pe=async F=>{await Ae.notifications.markRead(F),w(ge=>ge.map(Xe=>Xe.id===F?{...Xe,read:!0}:Xe)),K(ge=>ge.filter(Xe=>Xe.id!==F)),$(ge=>Math.max(0,ge-1)),window.dispatchEvent(new CustomEvent("markus:notifications-changed"))},X=F=>{const ge=F.metadata??{},Xe=F.actionType,ye=F.actionTarget;if(Xe==="open_chat"&&ye)try{const tt=typeof ye=="string"?JSON.parse(ye):ye;if(tt.agentId){const ft={agentId:tt.agentId};tt.sessionId&&(ft.sessionId=tt.sessionId),at.navigate(de.TEAM,ft);return}}catch{}if(Xe==="navigate"&&ye)try{const tt=typeof ye=="string"?JSON.parse(ye):ye;if(tt.path){if(tt.path.startsWith("/team")){const ft={},Ht=new URLSearchParams(tt.path.split("?")[1]||"");for(const[bt,le]of Ht.entries())ft[bt]=le;at.navigate(de.TEAM,ft);return}if(tt.path.startsWith("/work")){const ft={},Ht=new URLSearchParams(tt.path.split("?")[1]||"");for(const[bt,le]of Ht.entries())ft[bt]=le;at.navigate(de.WORK,ft);return}}}catch{}switch(F.type){case"approval_request":{const tt=ge.approvalId,ft=tt?T.find(_e=>_e.id===tt):void 0;if(ft&&Od(ft)){L(ft);break}const Ht=ft?.details?.taskId??ge.taskId,bt=ft?.details?.requirementId??ge.requirementId,le=ft?.details?.agentId??ft?.agentId;Ht?at.navigate(de.WORK,{openTask:Ht}):bt?at.navigate(de.WORK,{openRequirement:bt}):le?at.navigate(de.TEAM,{agentId:le}):at.navigate(de.WORK);break}case"task_completed":case"task_created":case"task_review":case"task_failed":ge.taskId?at.navigate(de.WORK,{openTask:ge.taskId}):at.navigate(de.WORK);break;case"requirement_created":case"requirement_decision":ge.requirementId?at.navigate(de.WORK,{openRequirement:ge.requirementId}):at.navigate(de.WORK);break;case"agent_report":case"system":{if(ge.creditExhausted){qe(!0);return}if(ge.templateUpdates){const tt=ge.templateUpdatesFingerprint;if(tt)try{localStorage.setItem(ck,tt)}catch{}localStorage.setItem("markus_nav_storeTab","installed"),at.navigate(de.STORE);return}if(ge.agentId){const tt={agentId:ge.agentId};ge.sessionId&&(tt.sessionId=ge.sessionId),at.navigate(de.TEAM,tt)}else at.navigate(de.TEAM);break}case"direct_message":{const tt=ge.senderId;tt?at.navigate(de.TEAM,{dm:tt}):at.navigate(de.TEAM);break}case"group_message":{const tt=ge.channel;tt?at.navigate(de.TEAM,{channel:tt}):at.navigate(de.TEAM);break}default:ge.taskId?at.navigate(de.WORK,{openTask:ge.taskId}):ge.requirementId?at.navigate(de.WORK,{openRequirement:ge.requirementId}):ge.projectId?at.navigate(de.WORK,{projectId:ge.projectId}):ge.agentId&&at.navigate(de.TEAM,{agentId:ge.agentId});break}},Z=async F=>{const ge=F.metadata??{},Xe=F.actionType,ye=F.type==="agent_report"&&!ge.creditExhausted&&!ge.templateUpdates&&(Xe==="open_chat"||!!ge.agentId&&Xe!=="navigate");!F.read&&!ye&&Pe(F.id);const tt=ge.taskId,ft=ge.requirementId;if(!ye&&(tt||ft)){const Ht=y.filter(bt=>bt.id!==F.id&&!bt.read&&(tt&&bt.metadata?.taskId===tt||ft&&bt.metadata?.requirementId===ft));for(const bt of Ht)Pe(bt.id)}X(F)},ue=async(F,ge,Xe,ye,tt)=>{E(F);try{const{approval:ft}=await Ae.approvals.respond(F,ge,t,Xe,ye,tt);C(_e=>_e.map(ht=>ht.id===F?ft:ht)),L(null),M(null),G(_e=>{const ht={..._e};return delete ht[F],ht});const Ht=ft.details?.taskId,bt=ft.details?.requirementId,le=y.filter(_e=>!_e.read&&(_e.type==="approval_request"&&_e.metadata?.approvalId===F||Ht&&_e.metadata?.taskId===Ht||bt&&_e.metadata?.requirementId===bt));if(le.length>0){for(const ht of le)Ae.notifications.markRead(ht.id).catch(()=>{});const _e=new Set(le.map(ht=>ht.id));w(ht=>ht.map(Tt=>_e.has(Tt.id)?{...Tt,read:!0}:Tt)),$(ht=>Math.max(0,ht-le.length))}li("/approvals"),li("/notifications"),li("/tasks"),li("/taskboard"),li("/requirements"),window.dispatchEvent(new CustomEvent("markus:data-changed")),window.dispatchEvent(new CustomEvent("markus:notifications-changed")),setTimeout(()=>wt(),800)}catch{}E(null)},Be=async()=>{try{if(!t)return;await Ae.notifications.markAllRead(t),w(F=>F.map(ge=>({...ge,read:!0}))),K([]),$(0),li("/notifications"),window.dispatchEvent(new CustomEvent("markus:notifications-changed"))}catch{const F=nt.filter(ge=>!ge.read);await Promise.all(F.map(ge=>Ae.notifications.markRead(ge.id))),w(ge=>ge.map(Xe=>({...Xe,read:!0}))),K([]),$(0),li("/notifications"),window.dispatchEvent(new CustomEvent("markus:notifications-changed"))}},Ie=F=>{const ge=F.details?.subType;return ge==="requirement_resubmit"?m("team:notifications.approvalType.requirementResubmit"):ge==="requirement"||F.details?.requirementId?m("team:notifications.approvalType.requirement"):ge==="task_review"?m("team:notifications.approvalType.taskReview"):ge==="task"||F.details?.taskId?m("team:notifications.approvalType.task"):F.details?.toolName?m("team:notifications.approvalType.toolExecution"):null},Ge=F=>{const ge=F.details??{},Xe=ge.subType,ye=ge.priority,tt=ye?m(`common:priority.${ye}`,{defaultValue:ye}):"";if(Xe==="requirement")return m("team:notifications.approvalDesc.requirementProposed",{agentName:F.agentName,title:F.title,priority:tt,defaultValue:F.description});if(Xe==="requirement_resubmit")return m("team:notifications.approvalDesc.requirementResubmitted",{agentName:F.agentName,title:F.title,priority:tt,defaultValue:F.description});if(Xe==="task")return m("team:notifications.approvalDesc.taskCreate",{agentName:F.agentName,title:F.title,priority:tt,defaultValue:F.description});if(Xe==="task_review"){const ft=`Task "${F.title}" has been submitted for your review.`;if(F.description.startsWith(ft))return m("team:notifications.approvalDesc.taskReview",{title:F.title})+F.description.slice(ft.length)}return F.description},kt=F=>{const ge=[];ge.push(F.agentName);const Xe=F.details?.taskTitle,ye=F.details?.taskId;Xe?ge.push(Xe):ye&&ge.push(`${m("team:notifications.approvalType.task")} ${ye.slice(0,8)}`);const tt=F.details?.requirementId;return tt&&!ye&&ge.push(`${m("team:notifications.approvalType.requirement")} ${tt.slice(0,8)}`),ge.join(" · ")},Rt=[...T].sort((F,ge)=>new Date(ge.requestedAt).getTime()-new Date(F.requestedAt).getTime()),Mt=Rt.filter(F=>F.status==="pending"),Ot=Rt.filter(F=>F.status!=="pending"),Un=F=>{const ge=F.details?.taskId,Xe=F.details?.requirementId,ye=F.details?.agentId??F.agentId;ge?at.navigate(de.WORK,{openTask:ge}):Xe?at.navigate(de.WORK,{openRequirement:Xe}):ye?at.navigate(de.TEAM,{agentId:ye}):at.navigate(de.WORK)},hn=()=>{h(!1),a?.()},ie=F=>i.jsxs("button",{disabled:S===F.id,onClick:()=>L(F),className:"w-full px-3 py-2 text-[11px] font-medium bg-brand-600 text-white rounded-md hover:bg-brand-700 disabled:opacity-50 transition-colors inline-flex items-center justify-center gap-1.5",children:[i.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:i.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"})}),m("team:userInput.respond",{defaultValue:"Respond"}),F.questions&&F.questions.length>1?` (${F.questions.length})`:""]}),Ee=_?i.jsx(mre,{approval:_,submitting:S===_.id,readOnly:_.status!=="pending",onClose:()=>L(null),onSubmit:F=>ue(_.id,F.approved,F.comment,F.selectedOption,F.answers)}):null,We=i.jsxs("div",{className:"flex items-center justify-between gap-2 px-3 py-1.5 border-b border-border-default/50 shrink-0",children:[i.jsx("div",{className:"flex items-center gap-0.5 rounded-md bg-surface-overlay/60 p-0.5",children:["unread","all"].map(F=>i.jsx("button",{onClick:()=>ut(F),"aria-pressed":He===F,title:F==="unread"?m("team:notifications.noUnread"):void 0,className:`px-2 py-0.5 rounded text-[10px] font-medium transition-colors ${He===F?"bg-surface-base text-fg-primary shadow-sm":"text-fg-tertiary hover:text-fg-secondary"}`,children:F==="unread"?m("team:notifications.filterUnread")+(ae>0?` (${ae})`:""):m("team:notifications.filterAll")},F))}),Q>0&&i.jsx("button",{onClick:Be,className:"text-[10px] text-brand-500 hover:text-brand-400 transition-colors shrink-0",children:m("team:notifications.markAllRead")})]}),pt=i.jsxs(i.Fragment,{children:[i.jsxs("div",{className:"flex border-b border-border-default shrink-0",children:[i.jsxs("button",{onClick:()=>{x("approvals"),je.current="approvals"},className:`flex-1 px-3 py-2.5 text-xs font-medium transition-colors ${g==="approvals"?"text-fg-primary border-b-2 border-brand-500":"text-fg-tertiary hover:text-fg-secondary"}`,children:[m("team:notifications.approvals"),Se>0?` (${Se})`:""]}),i.jsxs("button",{onClick:()=>{x("notifications"),je.current="notifications"},className:`flex-1 px-3 py-2.5 text-xs font-medium transition-colors ${g==="notifications"?"text-fg-primary border-b-2 border-brand-500":"text-fg-tertiary hover:text-fg-secondary"}`,children:[m("team:notifications.notifications"),ae>0?` (${ae})`:""]}),i.jsx("button",{onClick:hn,className:"px-2 py-2 text-fg-tertiary hover:text-fg-primary transition-colors shrink-0",title:m("common:close"),children:i.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[i.jsx("path",{d:"M18 6L6 18"}),i.jsx("path",{d:"M6 6l12 12"})]})})]}),g==="notifications"&&We,i.jsxs("div",{ref:z,className:"flex-1 overflow-y-auto",onScroll:F=>{if(g!=="notifications"||!Ce||V)return;const ge=F.currentTarget;ge.scrollTop+ge.clientHeight>=ge.scrollHeight-80&&Zt()},children:[g==="approvals"&&(T.length===0?i.jsx("div",{className:"p-6 text-center text-xs text-fg-tertiary",children:m("team:notifications.noApprovals")}):i.jsxs("div",{className:"divide-y divide-border-default/50",children:[Mt.map(F=>{const ge=F.details?.command,Xe=ge?Ge(F).replace(/\s*Command:.*$/,""):Ge(F);return i.jsxs("div",{className:"px-3 py-3 space-y-2.5",children:[i.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:()=>Un(F),children:[i.jsxs("div",{className:"flex items-start gap-2",children:[i.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:i.jsx("path",{d:Io.approval_request})}),i.jsxs("div",{className:"flex-1 min-w-0",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[Ie(F)&&i.jsx("span",{className:"text-[10px] text-amber-500 font-medium shrink-0",children:Ie(F)}),i.jsx("span",{className:"text-xs text-fg-primary font-medium truncate",children:F.title}),i.jsx("span",{className:"text-[10px] text-fg-tertiary shrink-0",children:Oo(F.requestedAt,m)})]}),i.jsx("div",{className:"text-[11px] text-fg-tertiary mt-0.5",children:F.agentName})]})]}),i.jsx("div",{className:"mt-2.5 text-[11px] text-fg-secondary leading-relaxed",children:i.jsx(Ea,{content:Xe,className:"text-[11px] [&_h1]:text-xs [&_h2]:text-[11px] [&_h3]:text-[11px] [&_p]:text-[11px] [&_li]:text-[11px]"})}),ge&&i.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:ge})]}),(()=>{if(Od(F))return ie(F);const ye=F.details?.subType,tt=ye==="task"||ye==="requirement"||ye==="requirement_resubmit",ft=F.options&&F.options.length>0,Ht=(O[F.id]??"").trim();if(ft){const bt=le=>le.id==="approve"?m("common:approve",{defaultValue:le.label}):le.id==="reject"||le.id==="request_changes"?m("team:notifications.optionLabels.requestChanges",{defaultValue:le.label}):le.label;return i.jsxs("div",{className:"space-y-1.5",children:[F.options.map((le,_e)=>i.jsxs("button",{disabled:S===F.id,onClick:()=>ue(F.id,le.id!=="reject",Ht||void 0,le.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 ${le.id==="reject"||le.id==="request_changes"?"border border-border-default text-fg-secondary hover:bg-surface-overlay":"bg-brand-600 text-white hover:bg-brand-700"}`,title:le.description,children:[i.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+_e)}),bt(le)]},le.id)),i.jsxs("div",{className:"flex gap-1.5 mt-1",children:[i.jsx("input",{type:"text",placeholder:m("team:notifications.freeformPlaceholder"),value:O[F.id]??"",onChange:le=>G(_e=>({..._e,[F.id]:le.target.value})),onKeyDown:le=>{le.key==="Enter"&&(O[F.id]??"").trim()&&ue(F.id,!0,(O[F.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"}),i.jsx("button",{disabled:S===F.id||!(O[F.id]??"").trim(),onClick:()=>ue(F.id,!0,(O[F.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:m("common:send")})]})]})}return tt?i.jsxs("div",{className:"space-y-1.5",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsxs("button",{disabled:S===F.id,onClick:()=>ue(F.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:[i.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:i.jsx("path",{d:"M20 6L9 17l-5-5"})}),m("common:approve")]}),i.jsxs("button",{disabled:S===F.id,onClick:()=>ue(F.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:[i.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:[i.jsx("path",{d:"M18 6L6 18"}),i.jsx("path",{d:"M6 6l12 12"})]}),m("common:reject")]}),D!==F.id&&i.jsxs("button",{disabled:S===F.id,onClick:()=>M(F.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:[i.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[i.jsx("path",{d:"M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"}),i.jsx("path",{d:"M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z"})]}),m("team:notifications.needsAdjustment")]})]}),D===F.id&&i.jsxs("div",{className:"space-y-1.5",children:[i.jsx("input",{type:"text",autoFocus:!0,placeholder:m("team:notifications.adjustmentPlaceholder"),value:O[F.id]??"",onChange:bt=>G(le=>({...le,[F.id]:bt.target.value})),onKeyDown:bt=>{bt.key==="Enter"&&(O[F.id]??"").trim()&&ue(F.id,!1,(O[F.id]??"").trim(),"needs_adjustment"),bt.key==="Escape"&&M(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"}),i.jsxs("div",{className:"flex gap-2",children:[i.jsx("button",{disabled:S===F.id||!(O[F.id]??"").trim(),onClick:()=>ue(F.id,!1,(O[F.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:m("team:notifications.confirmAdjustment")}),i.jsx("button",{onClick:()=>M(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:m("common:cancel")})]})]})]}):i.jsxs("div",{className:"space-y-1.5",children:[i.jsx("input",{type:"text",placeholder:m("team:notifications.commentPlaceholder"),value:O[F.id]??"",onChange:bt=>G(le=>({...le,[F.id]:bt.target.value})),onKeyDown:bt=>{bt.key==="Enter"&&ue(F.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"}),i.jsxs("div",{className:"flex gap-2",children:[i.jsx("button",{disabled:S===F.id,onClick:()=>ue(F.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:m("common:approve")}),i.jsx("button",{disabled:S===F.id,onClick:()=>ue(F.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:m("common:reject")})]})]})})()]},F.id)}),Ot.length>0&&i.jsxs(i.Fragment,{children:[Mt.length>0&&i.jsx("div",{className:"px-3 py-1.5 text-[10px] font-medium text-fg-tertiary uppercase tracking-wider bg-surface-overlay/30",children:m("team:notifications.approvalHistory")}),Ot.slice(0,50).map(F=>i.jsxs("button",{onClick:()=>Od(F)?L(F):Un(F),className:"w-full text-left px-3 py-2.5 hover:bg-surface-overlay/50 transition-colors group",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("span",{className:`w-1.5 h-1.5 rounded-full shrink-0 ${F.status==="approved"?"bg-green-500":F.status==="cancelled"||F.status==="expired"?"bg-gray-400":"bg-red-500"}`}),Ie(F)&&i.jsx("span",{className:"text-[10px] text-fg-tertiary font-medium shrink-0",children:Ie(F)}),i.jsx("span",{className:"text-xs text-fg-secondary truncate flex-1 group-hover:text-fg-primary",children:F.title}),i.jsx("span",{className:`text-[10px] font-medium shrink-0 ${F.status==="approved"?"text-green-500":F.status==="cancelled"||F.status==="expired"?"text-fg-muted":"text-red-500"}`,children:m(`common:status.${F.status}`,{defaultValue:F.status})})]}),i.jsxs("div",{className:"flex items-center gap-1.5 mt-0.5 pl-3.5",children:[i.jsx("span",{className:"text-[10px] text-fg-muted truncate",children:kt(F)}),i.jsx("span",{className:"text-[10px] text-fg-muted shrink-0",children:"·"}),i.jsx("span",{className:"text-[10px] text-fg-muted shrink-0",children:Oo(F.respondedAt??F.requestedAt,m)})]}),F.responseComment&&i.jsxs("p",{className:"text-[10px] text-fg-muted mt-0.5 pl-3.5 truncate",children:["“",F.responseComment,"”"]})]},F.id))]})]})),g==="notifications"&&(se.length===0?i.jsx("div",{className:"p-6 text-center text-xs text-fg-tertiary",children:q}):i.jsxs("div",{className:"divide-y divide-border-default/50",children:[se.map(F=>{const ge=lk[F.type]??"text-fg-tertiary";return i.jsxs("div",{role:"button",tabIndex:0,onClick:()=>Z(F),onKeyDown:Xe=>{(Xe.key==="Enter"||Xe.key===" ")&&(Xe.preventDefault(),Z(F))},className:`w-full text-left px-3 py-2.5 flex gap-2.5 transition-colors cursor-pointer ${F.read?"opacity-50 hover:opacity-70":"hover:bg-surface-overlay"}`,children:[i.jsx("div",{className:"shrink-0 mt-0.5",children:i.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:ge,children:i.jsx("path",{d:Io[F.type]??Io.system})})}),i.jsxs("div",{className:"flex-1 min-w-0",children:[i.jsxs("div",{className:"flex items-center gap-1.5",children:[!F.read&&i.jsx("span",{className:`w-1.5 h-1.5 rounded-full shrink-0 ${Pd[F.priority]??Pd.normal}`}),i.jsx("span",{className:"text-xs text-fg-primary font-medium truncate",children:dk(F,m)})]}),i.jsx("div",{className:"text-[11px] text-fg-tertiary mt-0.5 ",children:i.jsx(Ea,{content:mk(F,m),className:"text-[11px] [&_h1]:text-xs [&_h2]:text-[11px] [&_h3]:text-[11px] [&_p]:text-[11px] [&_li]:text-[11px] [&_p]:text-fg-tertiary"})}),i.jsxs("div",{className:"flex items-center gap-2 mt-0.5",children:[i.jsx("span",{className:"text-[10px] text-fg-muted",children:Oo(F.createdAt,m)}),Bd(F,m)&&i.jsx("span",{className:`text-[10px] font-medium ${ge}`,children:Bd(F,m)})]})]})]},F.id)}),V&&i.jsx("div",{className:"py-3 text-center",children:i.jsxs("svg",{className:"animate-spin h-4 w-4 text-fg-tertiary mx-auto",viewBox:"0 0 24 24",fill:"none",children:[i.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),i.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"})]})})]}))]})]}),Bt=k.useCallback(F=>{F?.mute&&Jae()},[]),Pt=k.useCallback(F=>{Bt(F),qe(!1)},[Bt]),it=Ue?i.jsx(ba,{title:m("credits.dialogTitle",{ns:"common"}),message:m("credits.dialogDesc",{ns:"common"}),variant:"primary",cancelLabel:m("credits.configureModels",{ns:"common"}),confirmLabel:m("credits.topUp",{ns:"common"}),checkboxes:[{id:"mute",label:m("credits.dontRemind",{ns:"common"})}],onCancel:()=>qe(!1),onCancelClick:F=>{Pt(F),at.navigate(de.SETTINGS),setTimeout(()=>{window.location.hash="settings/providers"},50)},onConfirm:F=>{const ge=`${st.getUrl().replace(/\/$/,"")}/settings?tab=billing`;Pt(F),fi(ge)}}):null;if(n){const F=["approvals","notifications"],ge=F.indexOf(g),Xe=(()=>{let ye=0,tt=0;return{onTouchStart:ft=>{ye=ft.touches[0].clientX,tt=ft.touches[0].clientY},onTouchEnd:ft=>{const Ht=ft.changedTouches[0].clientX-ye,bt=ft.changedTouches[0].clientY-tt;Math.abs(Ht)>60&&Math.abs(Ht)>Math.abs(bt)*1.5&&(Ht<0&&ge<F.length-1&&x(F[ge+1]),Ht>0&&ge>0&&x(F[ge-1]))}}})();return i.jsxs(i.Fragment,{children:[it,i.jsxs("div",{className:"flex flex-col h-full overflow-hidden",children:[Ee,i.jsx("div",{className:"flex border-b border-border-default shrink-0",children:F.map(ye=>i.jsx("button",{onClick:()=>x(ye),className:`flex-1 px-3 py-3 text-sm font-medium transition-colors ${g===ye?"text-fg-primary border-b-2 border-brand-500":"text-fg-tertiary"}`,children:ye==="approvals"?i.jsxs(i.Fragment,{children:[m("team:notifications.approvals"),Se>0?` (${Se})`:""]}):i.jsxs(i.Fragment,{children:[m("team:notifications.notifications"),ae>0?` (${ae})`:""]})},ye))}),g==="notifications"&&We,i.jsx("div",{className:"flex-1 overflow-hidden relative",...Xe,children:i.jsxs("div",{className:"flex h-full transition-transform duration-300 ease-out",style:{transform:`translateX(-${ge*100}%)`},children:[i.jsx("div",{className:"w-full shrink-0 h-full overflow-y-auto scrollbar-thin",children:T.length===0?i.jsx("div",{className:"p-6 text-center text-xs text-fg-tertiary",children:m("team:notifications.noApprovals")}):i.jsxs("div",{className:"divide-y divide-border-default/50",children:[Mt.map(ye=>{const tt=ye.details?.command,ft=tt?Ge(ye).replace(/\s*Command:.*$/,""):Ge(ye);return i.jsxs("div",{className:"px-3 py-3 space-y-2.5",children:[i.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:()=>Un(ye),children:[i.jsxs("div",{className:"flex items-start gap-2",children:[i.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:i.jsx("path",{d:Io.approval_request})}),i.jsxs("div",{className:"flex-1 min-w-0",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[Ie(ye)&&i.jsx("span",{className:"text-[10px] text-amber-500 font-medium shrink-0",children:Ie(ye)}),i.jsx("span",{className:"text-xs text-fg-primary font-medium truncate",children:ye.title}),i.jsx("span",{className:"text-[10px] text-fg-tertiary shrink-0",children:Oo(ye.requestedAt,m)})]}),i.jsx("div",{className:"text-[11px] text-fg-tertiary mt-0.5",children:ye.agentName})]})]}),i.jsx("div",{className:"mt-2.5 text-[11px] text-fg-secondary leading-relaxed",children:i.jsx(Ea,{content:ft,className:"text-[11px] [&_h1]:text-xs [&_h2]:text-[11px] [&_h3]:text-[11px] [&_p]:text-[11px] [&_li]:text-[11px]"})}),tt&&i.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:tt})]}),(()=>{if(Od(ye))return ie(ye);const Ht=ye.details?.subType,bt=Ht==="task"||Ht==="requirement"||Ht==="requirement_resubmit",le=ye.options&&ye.options.length>0,_e=(O[ye.id]??"").trim();if(le){const ht=Tt=>Tt.id==="approve"?m("common:approve",{defaultValue:Tt.label}):Tt.id==="reject"||Tt.id==="request_changes"?m("team:notifications.optionLabels.requestChanges",{defaultValue:Tt.label}):Tt.label;return i.jsxs("div",{className:"space-y-1.5",children:[ye.options.map((Tt,Pn)=>i.jsxs("button",{disabled:S===ye.id,onClick:()=>ue(ye.id,Tt.id!=="reject",_e||void 0,Tt.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 ${Tt.id==="reject"||Tt.id==="request_changes"?"border border-border-default text-fg-secondary hover:bg-surface-overlay":"bg-brand-600 text-white hover:bg-brand-700"}`,title:Tt.description,children:[i.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+Pn)}),ht(Tt)]},Tt.id)),i.jsxs("div",{className:"flex gap-1.5 mt-1",children:[i.jsx("input",{type:"text",placeholder:m("team:notifications.freeformPlaceholder"),value:O[ye.id]??"",onChange:Tt=>G(Pn=>({...Pn,[ye.id]:Tt.target.value})),onKeyDown:Tt=>{Tt.key==="Enter"&&(O[ye.id]??"").trim()&&ue(ye.id,!0,(O[ye.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"}),i.jsx("button",{disabled:S===ye.id||!(O[ye.id]??"").trim(),onClick:()=>ue(ye.id,!0,(O[ye.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:m("common:send")})]})]})}return bt?i.jsxs("div",{className:"space-y-1.5",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsxs("button",{disabled:S===ye.id,onClick:()=>ue(ye.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:[i.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:i.jsx("path",{d:"M20 6L9 17l-5-5"})}),m("common:approve")]}),i.jsxs("button",{disabled:S===ye.id,onClick:()=>ue(ye.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:[i.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:[i.jsx("path",{d:"M18 6L6 18"}),i.jsx("path",{d:"M6 6l12 12"})]}),m("common:reject")]}),D!==ye.id&&i.jsxs("button",{disabled:S===ye.id,onClick:()=>M(ye.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:[i.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[i.jsx("path",{d:"M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"}),i.jsx("path",{d:"M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z"})]}),m("team:notifications.needsAdjustment")]})]}),D===ye.id&&i.jsxs("div",{className:"space-y-1.5",children:[i.jsx("input",{type:"text",autoFocus:!0,placeholder:m("team:notifications.adjustmentPlaceholder"),value:O[ye.id]??"",onChange:ht=>G(Tt=>({...Tt,[ye.id]:ht.target.value})),onKeyDown:ht=>{ht.key==="Enter"&&(O[ye.id]??"").trim()&&ue(ye.id,!1,(O[ye.id]??"").trim(),"needs_adjustment"),ht.key==="Escape"&&M(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"}),i.jsxs("div",{className:"flex gap-2",children:[i.jsx("button",{disabled:S===ye.id||!(O[ye.id]??"").trim(),onClick:()=>ue(ye.id,!1,(O[ye.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:m("team:notifications.confirmAdjustment")}),i.jsx("button",{onClick:()=>M(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:m("common:cancel")})]})]})]}):i.jsxs("div",{className:"space-y-1.5",children:[i.jsx("input",{type:"text",placeholder:m("team:notifications.commentPlaceholder"),value:O[ye.id]??"",onChange:ht=>G(Tt=>({...Tt,[ye.id]:ht.target.value})),onKeyDown:ht=>{ht.key==="Enter"&&ue(ye.id,!0,_e||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"}),i.jsxs("div",{className:"flex gap-2",children:[i.jsx("button",{disabled:S===ye.id,onClick:()=>ue(ye.id,!0,_e||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:m("common:approve")}),i.jsx("button",{disabled:S===ye.id,onClick:()=>ue(ye.id,!1,_e||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:m("common:reject")})]})]})})()]},ye.id)}),Ot.length>0&&i.jsxs(i.Fragment,{children:[Mt.length>0&&i.jsx("div",{className:"px-3 py-1.5 text-[10px] font-medium text-fg-tertiary uppercase tracking-wider bg-surface-overlay/30",children:m("team:notifications.approvalHistory")}),Ot.slice(0,50).map(ye=>i.jsxs("button",{onClick:()=>Un(ye),className:"w-full text-left px-3 py-2.5 hover:bg-surface-overlay/50 transition-colors",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("span",{className:`w-1.5 h-1.5 rounded-full shrink-0 ${ye.status==="approved"?"bg-green-500":ye.status==="cancelled"||ye.status==="expired"?"bg-gray-400":"bg-red-500"}`}),i.jsx("span",{className:"text-xs text-fg-secondary truncate flex-1",children:ye.title}),i.jsx("span",{className:`text-[10px] font-medium shrink-0 ${ye.status==="approved"?"text-green-500":ye.status==="cancelled"||ye.status==="expired"?"text-fg-muted":"text-red-500"}`,children:m(`common:status.${ye.status}`,{defaultValue:ye.status})})]}),i.jsxs("div",{className:"flex items-center gap-1.5 mt-0.5 pl-3.5",children:[i.jsx("span",{className:"text-[10px] text-fg-muted truncate",children:kt(ye)}),i.jsx("span",{className:"text-[10px] text-fg-muted shrink-0",children:"·"}),i.jsx("span",{className:"text-[10px] text-fg-muted shrink-0",children:Oo(ye.respondedAt??ye.requestedAt,m)})]})]},ye.id))]})]})}),i.jsx("div",{className:"w-full shrink-0 h-full overflow-y-auto scrollbar-thin",children:se.length===0?i.jsx("div",{className:"p-6 text-center text-xs text-fg-tertiary",children:q}):i.jsx("div",{className:"divide-y divide-border-default/50",children:se.slice(0,He==="unread"?Nt:50).map(ye=>{const tt=lk[ye.type]??"text-fg-tertiary";return i.jsxs("button",{onClick:()=>Z(ye),className:`w-full text-left px-3 py-2.5 flex gap-2.5 transition-colors ${ye.read?"opacity-50 hover:opacity-70":"hover:bg-surface-overlay"}`,children:[i.jsx("div",{className:"shrink-0 mt-0.5",children:i.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:tt,children:i.jsx("path",{d:Io[ye.type]??Io.system})})}),i.jsxs("div",{className:"flex-1 min-w-0",children:[i.jsxs("div",{className:"flex items-center gap-1.5",children:[!ye.read&&i.jsx("span",{className:`w-1.5 h-1.5 rounded-full shrink-0 ${Pd[ye.priority]??Pd.normal}`}),i.jsx("span",{className:"text-xs text-fg-primary font-medium truncate",children:dk(ye,m)})]}),i.jsx("div",{className:"text-[11px] text-fg-tertiary mt-0.5 ",children:i.jsx(Ea,{content:mk(ye,m),className:"text-[11px] [&_h1]:text-xs [&_h2]:text-[11px] [&_h3]:text-[11px] [&_p]:text-[11px] [&_li]:text-[11px] [&_p]:text-fg-tertiary"})}),i.jsxs("div",{className:"flex items-center gap-2 mt-0.5",children:[i.jsx("span",{className:"text-[10px] text-fg-muted",children:Oo(ye.createdAt,m)}),Bd(ye,m)&&i.jsx("span",{className:`text-[10px] font-medium ${tt}`,children:Bd(ye,m)})]})]})]},ye.id)})})})]})})]})]})}if(s){const F=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 i.jsxs(i.Fragment,{children:[Ee,i.jsxs("button",{ref:ee,onClick:()=>{h(!p),p||wt()},title:e?c||m("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-lg text-[13px] font-medium mb-0.5 transition-colors relative text-fg-primary ${p||l?"bg-surface-overlay":"hover:bg-surface-overlay/60"}`,children:[i.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:i.jsx("path",{d:F})}),e?i.jsx("span",{className:"text-[9px] leading-tight truncate w-full text-center",children:c}):i.jsx("span",{className:"truncate",children:c}),De>0&&i.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:De>99?m("common:badgeOverLimit"):De})]}),p&&zr.createPortal(i.jsx("div",{ref:U,className:"fixed bg-surface-secondary border border-border-default rounded-xl shadow-2xl z-[9999] flex flex-col overflow-hidden",style:{top:te.top,left:te.left,width:te.width,maxHeight:te.maxHeight},children:pt}),document.body),it]})}return i.jsxs(i.Fragment,{children:[Ee,i.jsxs("button",{ref:ee,onClick:()=>{h(!p),p||wt()},className:`relative flex items-center justify-center rounded-md transition-colors ${e?"w-8 h-8":"w-7 h-7"} ${p?"bg-surface-overlay text-fg-primary":"text-fg-tertiary hover:text-fg-secondary hover:bg-surface-overlay"}`,title:m("team:notifications.bellTitle"),children:[i.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[i.jsx("path",{d:"M18 8A6 6 0 0 0 6 8c0 7-3 9-3 9h18s-3-2-3-9"}),i.jsx("path",{d:"M13.73 21a2 2 0 0 1-3.46 0"})]}),De>0&&i.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:De>99?m("common:badgeOverLimit"):De})]}),p&&zr.createPortal(i.jsx("div",{ref:U,className:"fixed bg-surface-secondary border border-border-default rounded-xl shadow-2xl z-[9999] flex flex-col overflow-hidden",style:{top:te.top,left:te.left,width:te.width,maxHeight:te.maxHeight},children:pt}),document.body),it]})}function Hd({d:e,size:t=14}){return i.jsx("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"shrink-0",children:i.jsx("path",{d:e})})}const hh=200;function hre({authUser:e,onLogout:t,onEditProfile:n,showSettingsLink:a=!1,collapsed:s=!1,showVersion:l=!1}){const{t:c}=ot(["nav","common"]),[d,m]=k.useState(!1),[p,h]=k.useState(!1),[g,x]=k.useState({top:0,left:0}),y=k.useRef(null),w=k.useRef(null),{connected:T,user:C,credits:S,refresh:E}=h4(d),_=k.useCallback(()=>{if(!y.current)return;const K=y.current.getBoundingClientRect(),ee=window.innerWidth,U=window.innerHeight,te=w.current?.offsetHeight??220;let I=K.right+8;I+hh>ee-8&&(I=Math.max(8,K.left-hh-8));let J=K.top-te-8;J<8&&(J=Math.min(K.bottom+8,U-te-8)),x({top:Math.max(8,J),left:I})},[]);k.useLayoutEffect(()=>{if(!d)return;_();const K=requestAnimationFrame(()=>_());return()=>cancelAnimationFrame(K)},[d,_,s]),k.useEffect(()=>{if(!d)return;const K=U=>{const te=U.target;y.current?.contains(te)||w.current?.contains(te)||m(!1)},ee=()=>_();return document.addEventListener("mousedown",K),window.addEventListener("resize",ee),window.addEventListener("scroll",ee,!0),()=>{document.removeEventListener("mousedown",K),window.removeEventListener("resize",ee),window.removeEventListener("scroll",ee,!0)}},[d,_]);const L=e?.name||C?.displayName||C?.username||c("common:userPlaceholder"),D=e?.email||C?.email||"",M=m4(e?.avatarUrl,C?.avatarUrl),O=T?"bg-emerald-500":"bg-fg-muted",G=T?C?.username?c("sidebar.hubConnectedAs",{username:C.username}):c("sidebar.hubConnected"):c("sidebar.hubDisconnected"),Q=!!(T&&C?.username&&e?.name&&C.username.toLowerCase()!==e.name.toLowerCase()&&C.email?.toLowerCase()!==e.email?.toLowerCase()),$=()=>{m(!1),E({validate:!0}),at.navigate(de.SETTINGS,{tab:"account"})},Y=d&&zr.createPortal(i.jsxs("div",{ref:w,className:"fixed bg-surface-elevated border border-border-default rounded-xl shadow-xl z-[9999] overflow-hidden",style:{top:g.top,left:g.left,width:hh},children:[i.jsxs("div",{className:"px-3.5 py-3 border-b border-border-default flex items-start gap-2",children:[i.jsxs("div",{className:"min-w-0 flex-1",children:[i.jsx("div",{className:"text-sm font-medium text-fg-primary truncate",children:L}),D&&i.jsx("div",{className:"text-xs text-fg-tertiary mt-0.5 truncate",children:D}),S!==null&&i.jsxs("div",{className:"text-xs text-fg-secondary mt-0.5 flex items-center gap-1",children:[i.jsx("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"shrink-0",children:i.jsx("polyline",{points:"13 2 3 14 12 14 18 22 6 22 12 17"})}),i.jsxs("span",{className:"truncate",children:[c("common:creditBalance"),": ",S.remaining.toLocaleString()]})]})]}),n&&i.jsx("button",{type:"button",onClick:()=>{m(!1),n()},title:c("common:profile.editProfile"),className:"shrink-0 mt-0.5 p-1.5 rounded-md text-fg-tertiary hover:text-fg-secondary hover:bg-surface-overlay transition-colors",children:i.jsx(Hd,{d:"M12 20h9M16.5 3.5a2.12 2.12 0 0 1 3 3L7 19l-4 1 1-4Z",size:14})})]}),i.jsxs("button",{type:"button",onClick:$,className:"w-full px-3.5 py-2.5 border-b border-border-default flex items-center gap-2 hover:bg-surface-overlay transition-colors text-left",children:[i.jsx("span",{className:`w-2 h-2 rounded-full shrink-0 ${O}`}),i.jsxs("span",{className:"min-w-0 flex-1",children:[i.jsx("span",{className:"text-xs text-fg-secondary block truncate",children:G}),Q&&C?.username&&i.jsx("span",{className:"text-[10px] text-amber-500/90 block truncate mt-0.5",children:c("sidebar.hubAccountMismatch",{username:C.username})})]}),i.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"text-fg-muted shrink-0",children:i.jsx("path",{d:"m9 18 6-6-6-6"})})]}),i.jsxs("div",{className:"py-1",children:[a&&i.jsxs("button",{type:"button",onClick:()=>{m(!1),at.navigate(de.SETTINGS)},className:"w-full flex items-center gap-2.5 px-3.5 py-2 text-sm text-fg-secondary hover:bg-surface-overlay transition-colors",children:[i.jsx(Hd,{d:Cc[de.SETTINGS]}),c("settings")]}),window.markusDesktop&&i.jsxs("button",{type:"button",onClick:()=>{m(!1),window.markusDesktop?.openInBrowser()},className:"w-full flex items-center gap-2.5 px-3.5 py-2 text-sm text-fg-secondary hover:bg-surface-overlay transition-colors",children:[i.jsx(Hd,{d:"M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6M15 3h6v6M10 14 21 3"}),c("common:openInBrowser")]}),t&&i.jsxs("button",{type:"button",onClick:()=>{m(!1),h(!0)},className:"w-full flex items-center gap-2.5 px-3.5 py-2 text-sm text-fg-secondary hover:bg-surface-overlay transition-colors",children:[i.jsx(Hd,{d:"M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4M16 17l5-5-5-5M21 12H9"}),c("common:signOut")]})]})]}),document.body);return i.jsxs("div",{className:`relative ${s?"flex justify-center":"flex items-center justify-between gap-2 w-full"}`,children:[i.jsxs("button",{ref:y,type:"button",onClick:()=>m(K=>!K),title:L,className:`relative inline-flex items-center justify-center rounded-full transition-opacity hover:opacity-90 ${s?"p-0.5":""}`,children:[i.jsx(Zi,{name:L,avatarUrl:M,size:s?28:32,fallback:"icon"}),i.jsx("span",{className:`absolute bottom-0 right-0 w-2.5 h-2.5 rounded-full border-2 border-surface-secondary ${O}`,title:G})]}),l&&!s&&i.jsxs("span",{className:"text-[10px] text-fg-muted select-none shrink-0",children:["v","0.11.0-rc.0"]}),Y,p&&t&&i.jsx(ba,{title:c("common:signOutConfirmTitle"),message:c("common:signOutConfirmMessage"),confirmLabel:c("common:signOut"),variant:"primary",onConfirm:()=>{h(!1),t()},onCancel:()=>h(!1)})]})}function gre({d:e,size:t=18}){return i.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:i.jsx("path",{d:e})})}function bre({currentPage:e,onNavigate:t,authUser:n,collapsed:a,onToggleCollapse:s,onLogout:l,keyboardFocusPageId:c,keyboardPaneActive:d}){const{t:m}=ot(["nav","common"]);return i.jsxs("aside",{"data-keyboard-pane":"l0",className:"markus-app-sidebar h-dvh bg-surface-secondary flex flex-col shrink-0 overflow-hidden",children:[i.jsx("div",{"data-electron-drag":!0,className:`electron-mac-sidebar-header flex items-center ${a?"px-2 py-3.5 justify-center":"px-4 h-14 justify-between"}`,children:i.jsxs("button",{"data-no-drag":!0,onClick:s,title:m(a?"sidebar.expandSidebar":"sidebar.collapseSidebar"),className:"flex items-center gap-2.5 min-w-0 group",children:[i.jsx("img",{src:"/logo.png",alt:"Markus",className:"w-8 h-8 rounded-lg shrink-0"}),!a&&i.jsx("span",{className:"text-[15px] font-bold tracking-tight text-fg-primary whitespace-nowrap",children:"Markus"})]})}),i.jsx("nav",{className:`${a?"p-1":"px-3 py-2"} flex-1 overflow-y-auto scrollbar-thin`,children:aU.map((p,h)=>{const g=r4.filter(y=>y.section===p.key);if(g.length===0)return null;const x=m(`sections.${p.key}`);return i.jsx("div",{children:i.jsxs("div",{className:h>0?"mt-3":"",children:[!a&&x&&i.jsx("div",{className:"px-3 py-1.5 mb-1 text-[10px] font-semibold text-fg-muted uppercase tracking-[0.1em]",children:x}),a&&h>0&&i.jsx("div",{className:"my-3"}),g.map(y=>{if(y.id===de.NOTIFICATIONS)return i.jsx(fre,{sidebarMode:!0,collapsed:a,userId:n?.id,label:m(y.id),iconPath:Cc[y.id],isActive:e===y.id},y.id);const w=e===y.id,T=d&&c===y.id;return i.jsxs("button",{"data-l0-page-id":y.id,onClick:()=>t(y.id),title:a?m(y.id):void 0,className:`w-full flex items-center ${a?"flex-col justify-center px-1 py-1.5 gap-0.5":"gap-3 px-3 py-[7px]"} rounded-lg text-[13px] font-medium mb-0.5 transition-colors text-fg-primary ${T?"bg-brand-500/25 ring-1 ring-inset ring-brand-500/40":w?"bg-surface-overlay":"hover:bg-surface-overlay/60"}`,children:[i.jsx(gre,{d:Cc[y.id]??"",size:a?16:18}),a?i.jsx("span",{className:"text-[9px] leading-tight truncate w-full text-center",children:m(y.id)}):i.jsx("span",{className:"truncate",children:m(y.id)})]},y.id)})]})},p.key)})}),i.jsx("div",{className:`shrink-0 border-t border-border-subtle ${a?"p-1.5 flex justify-center":"px-3 py-2.5"}`,children:i.jsx(hre,{authUser:n,onLogout:l,onEditProfile:()=>{window.dispatchEvent(new Event("markus:open-edit-profile"))},showSettingsLink:!1,collapsed:a,showVersion:!a})})]})}const yre=6e4,xre=2e3;let Ar={},Yi={};const xg=new Set,Rm=new Set;let e6=0;const vg=new Map;let yc=null,$d=0,nm=null;function Lc(){for(const e of xg)e()}function pk(e,t){const n=Object.keys(e);if(n.length!==Object.keys(t).length)return!1;for(const a of n)if(e[a]!==t[a])return!1;return!0}function vre(e,t){const n={},a=[];for(const[s,l]of Object.entries(e)){if(t.has(s)){l>0&&a.push(s);continue}n[s]=l}return{counts:n,staleActiveKeys:a}}function yb(e,t){const n=Date.now(),a=vg.get(e)??0;!t?.force&&n-a<xre||(vg.set(e,n),e in Ar&&(delete Ar[e],Lc()),Ae.unread.markRead(e,new Date().toISOString()).catch(()=>{}))}async function wg(){try{const e=await Ae.unread.getCounts(),{counts:t,staleActiveKeys:n}=vre(e.counts??{},Rm);Ar=t,Yi=e.sessionAgentMap??{},Lc();for(const a of n)yb(a)}catch{}}function wre(){yc||(wg(),yc=setInterval(wg,yre),nm=Ir.on("chat:unread_update",e=>{const t=e.payload?.conversationKey;if(t){if(Rm.has(t)){yb(t);return}Date.now()>e6&&(Ar[t]=(Ar[t]??0)+1,Lc())}}))}function kre(){yc&&(clearInterval(yc),yc=null),nm&&(nm(),nm=null)}function Sre(e){const t=e?.enabled??!0,[n,a]=k.useState(Ar),[s,l]=k.useState(Yi),c=k.useCallback(async()=>{await wg()},[]),d=k.useCallback(async w=>{const T=new Date().toISOString();delete Ar[w],Lc();try{await Ae.unread.markRead(w,T)}catch{}},[]),m=k.useCallback(async()=>{Ar={},Lc();try{await Ae.unread.markAllRead()}catch{}},[]),p=k.useCallback(w=>{Rm.add(w)},[]),h=k.useCallback(w=>{Rm.delete(w),e6=Date.now()+150,vg.delete(w),yb(w,{force:!0})},[]);k.useEffect(()=>{if(!t)return;$d++,wre();let w=Yi;const T=()=>{a(C=>pk(C,Ar)?C:{...Ar}),w!==Yi&&(w=Yi,l(C=>pk(C,Yi)?C:{...Yi}))};return xg.add(T),a({...Ar}),l({...Yi}),()=>{xg.delete(T),$d--,$d<=0&&($d=0,kre())}},[t]);const g=k.useMemo(()=>Object.values(n).reduce((w,T)=>w+T,0),[n]),x=k.useCallback(w=>n[`session:${w}`]??0,[n]),y=k.useCallback(w=>n[`channel:${w}`]??0,[n]);return{counts:n,totalUnread:g,sessionAgentMap:s,getSessionUnread:x,getChannelUnread:y,markRead:d,markAllRead:m,refresh:c,setActiveKey:p,clearActiveKey:h}}function Bse(e,t){return k.useMemo(()=>{const n=new Map;for(const[a,s]of Object.entries(t))if(a.startsWith("session:")){const l=a.slice(8),c=e[l];c&&n.set(c,(n.get(c)??0)+s)}return n},[e,t])}function Cre(e){return e.startsWith("channel:dm:a2a:")}function Are(e,t){let n=0;for(const[a,s]of Object.entries(e))if(a.startsWith("session:")){const l=a.slice(8);t[l]&&(n+=s)}else if(a.startsWith("channel:")){if(Cre(a))continue;n+=s}return n}function Tre({currentPage:e,onNavigate:t,userId:n}){const{t:a}=ot("nav"),[s,l]=k.useState(0),{counts:c,sessionAgentMap:d}=Sre({enabled:!0}),m=k.useMemo(()=>Are(c,d),[c,d]),p=k.useCallback(async()=>{try{const h=await Ae.notifications.list(n,!1);l(h.unreadCount??h.notifications.filter(g=>!g.read).length)}catch{}},[n]);return k.useEffect(()=>{p();const h=setInterval(()=>{document.visibilityState==="visible"&&p()},3e4),g=()=>p();return window.addEventListener("markus:notifications-changed",g),()=>{clearInterval(h),window.removeEventListener("markus:notifications-changed",g)}},[p]),i.jsx("nav",{className:"fixed bottom-0 left-0 right-0 z-50 bg-surface-secondary flex items-stretch h-14 safe-area-bottom",children:iU.map(h=>{const g=h.group.includes(e),x=h.id===de.NOTIFICATIONS,y=h.id===de.TEAM;return i.jsxs("button",{onClick:()=>t(h.id),className:`flex-1 flex flex-col items-center justify-center gap-0.5 transition-colors ${g?"text-fg-primary":"text-fg-tertiary active:text-fg-secondary"}`,children:[i.jsxs("div",{className:"relative",children:[i.jsx("svg",{width:20,height:20,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:g?2:1.75,strokeLinecap:"round",strokeLinejoin:"round",className:"shrink-0",children:i.jsx("path",{d:Cc[h.id]})}),x&&s>0&&i.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:s>99?"99+":s}),y&&m>0&&i.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:m>99?"99+":m})]}),i.jsx("span",{className:`text-[10px] leading-tight ${g?"font-semibold":""}`,children:a(h.id)})]},h.id)})})}const Dm=new Map;function Ns(e,t){Dm.has(e)||Dm.set(e,t().catch(()=>{}))}function Ls(e){const t=Dm.get(e);return Dm.delete(e),t}const qa={builderArtifacts:"builder.artifacts",builderAgents:"builder.agents",builderHubMyItems:"builder.hubMyItems",builderInstalled:"builder.installed",hubAgents:"hub.agents",hubTeams:"hub.teams",hubSkills:"hub.skills"},Bs={agent:{label:"Agent",labelZh:"智能体",gradient:"from-violet-500 to-indigo-600",accent:"#8b5cf6",covers:[["#7c3aed","#4f46e5"],["#8b5cf6","#6366f1"],["#a855f7","#4338ca"],["#6d28d9","#2563eb"]]},team:{label:"Team",labelZh:"AI 小队",gradient:"from-cyan-500 to-blue-600",accent:"#06b6d4",covers:[["#0891b2","#2563eb"],["#06b6d4","#3b82f6"],["#0e7490","#1d4ed8"],["#22d3ee","#4f46e5"]]},skill:{label:"Skill",labelZh:"技能",gradient:"from-amber-500 to-orange-600",accent:"#f59e0b",covers:[["#f59e0b","#ea580c"],["#d97706","#dc2626"],["#fbbf24","#f97316"],["#f59e0b","#b45309"]]},connector:{label:"Connector",labelZh:"连接器",gradient:"from-emerald-500 to-teal-600",accent:"#10b981",covers:[["#10b981","#0d9488"],["#059669","#0891b2"],["#34d399","#14b8a6"],["#16a34a","#0f766e"]]}};function il(e){const t=(e||"").toLowerCase();return t==="team"?"team":t==="skill"?"skill":t==="connector"||t==="mcp"?"connector":"agent"}function t6(e){let t=2166136261;for(let n=0;n<e.length;n++)t^=e.charCodeAt(n),t=Math.imul(t,16777619);return t>>>0}const Nre={agent:258,team:205,skill:32,connector:162};function xb(e,t){const n=Nre[e],a=t6(t),s=((n+(a%68-34))%360+360)%360,l=(s+22+(a>>>8)%24)%360;return`linear-gradient(${120+a%44}deg, hsl(${s} 72% 56%), hsl(${l} 66% 43%))`}const fk=["M12 2l2.4 6.9L21 9l-5.4 4 2 7-5.6-4.1L6.4 20l2-7L3 9l6.6-.1z","M12 2a10 10 0 100 20 10 10 0 000-20zm0 4a6 6 0 110 12 6 6 0 010-12z","M4 4h7v7H4zM13 4h7v7h-7zM4 13h7v7H4zM13 13h7v7h-7z","M12 2l9 5v10l-9 5-9-5V7z","M3 12a9 9 0 019-9v9h9a9 9 0 11-18 0z","M6 3h12l3 6-9 12L3 9z","M12 3l3 6 6 .9-4.5 4.3 1 6.3L12 18l-5.5 2.5 1-6.3L3 9.9 9 9z","M4 12a8 8 0 018-8v4a4 4 0 00-4 4zm8 8a8 8 0 01-8-8h4a4 4 0 004 4z","M12 2l7 4v12l-7 4-7-4V6z M12 6l-3 1.7v3.4L12 13l3-1.9V7.7z","M3 6h18M3 12h18M3 18h18","M12 2a10 10 0 100 20A6 6 0 0112 8a6 6 0 010 12","M12 2l4 8h-8zM4 12h16l-8 10z"];function n6(e){return fk[t6(e+"g")%fk.length]}function a6(e){return e?e.startsWith("http://")||e.startsWith("https://")||e.startsWith("/")||e.startsWith("data:")||/\.(png|jpe?g|gif|webp|svg)$/i.test(e):!1}function Ere(e){return!e||a6(e)?!1:[...e].length<=4&&new RegExp("\\p{Extended_Pictographic}","u").test(e)}function jre(e,t="user"){const n=t==="org"?"shapes":"thumbs",a=encodeURIComponent(e);return`https://api.dicebear.com/9.x/${n}/svg?seed=${a}&radius=50&backgroundType=gradientLinear`}function $o(e){const t=e??0;return t<1e3?String(t):t<1e6?`${(t/1e3).toFixed(t<1e4?1:0)}k`.replace(".0k","k"):`${(t/1e6).toFixed(1)}M`.replace(".0M","M")}function hk(e,t="usd"){return!e||e<=0?"Free":`${t.toLowerCase()==="usd"?"$":""}${(e/100).toFixed(e%100===0?0:2)}`}const gk={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"}},Mre=["development","devops","management","productivity","browser","custom","general"],_re=[{label:"Tech",emojis:["✦","◈","⬡","⚡","🤖","🧠","💡","🎯","🔧","📦","🚀","💻","🛠️","⭐","🔥","💎","⚙️","🧩","🔌","💾","🖥️","📡","🔬","🧪","🏗️","📱","🎮","🕹️","📟","💽","🖨️","⌨️"]},{label:"People",emojis:["👤","👥","🧑‍💻","👨‍💼","👩‍🔬","🧙","🦸","🤝","💪","🎓","👷","🕵️","🧑‍🎨","🧑‍🏫","👨‍🚀","🥷","🧑‍🏭","🧑‍⚕️","🧑‍🔧","🧑‍🍳","👨‍🎤","🦹","🧝","🧞","🧑‍✈️","💂","🤴","👸","🧛","🧟","🧜","🧚"]},{label:"Objects",emojis:["📝","📊","🗂️","📁","🔍","🔑","🌐","💬","🔒","🎨","📐","🗃️","📋","✏️","🖊️","📌","📎","🧲","🪝","🧰","🪜","🧬","🔭","💊","🩺","📕","📗","📘","📙","📓","🗒️","📰"]},{label:"Symbols",emojis:["❤️","🧡","💛","💚","💙","💜","🖤","🤍","♠️","♥️","♦️","♣️","🎵","🎶","💯","✅","❌","⭕","🔴","🟠","🟡","🟢","🔵","🟣","⚫","⚪","🟤","🔶","🔷","▶️","⏸️","⏹️"]},{label:"Nature",emojis:["🌟","🌈","🌊","🌿","🍀","🔮","💫","✨","🌙","☀️","🦋","🐉","🦊","🐺","🦅","🐙","🦁","🐯","🦄","🐲","🌸","🌺","🍄","🌵","🎄","🌴","🍁","🌻","🐝","🦎","🐍","🦈"]},{label:"Activity",emojis:["🎯","🏆","🥇","🎖️","🏅","🎪","🎭","🎬","🎤","🎧","🎼","🎹","🥁","🎸","🎺","🎻","⚽","🏀","🎾","🏐","🎲","🧸","🪁","🎰","🎳","🏹","🥊","🤺","⛷️","🏄","🚴","🧗"]}],Rre={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-brand-500/15 text-brand-400 border-brand-500/30"}};function gh({value:e,onChange:t,renderAs:n="span",className:a,editClassName:s,placeholder:l,multiline:c,readOnly:d}){const[m,p]=k.useState(!1),[h,g]=k.useState(e),x=k.useRef(null);if(k.useEffect(()=>{g(e)},[e]),k.useEffect(()=>{m&&x.current?.focus()},[m]),d){const _=e||l,D=`${a??""} ${!e?"text-fg-muted italic":""}`;return n==="h1"?i.jsx("h1",{className:D,children:_}):n==="p"?i.jsx("p",{className:D,children:_}):i.jsx("span",{className:D,children:_})}const y=()=>{p(!1),h!==e&&t(h)},w=()=>{g(e),p(!1)},T=_=>{_.key==="Escape"&&w(),_.key==="Enter"&&!c&&y()};if(m){const _=`bg-transparent outline-none w-full ${s??a??""} ring-1 ring-brand-500/50 rounded px-1 -mx-1`;return c?i.jsx("textarea",{ref:x,value:h,onChange:L=>g(L.target.value),onBlur:y,onKeyDown:T,className:`${_} resize-y min-h-[60px]`,placeholder:l}):i.jsx("input",{ref:x,value:h,onChange:L=>g(L.target.value),onBlur:y,onKeyDown:T,className:_,placeholder:l})}const C=e||l,S=!e,E="cursor-text hover:ring-1 hover:ring-border-default rounded px-1 -mx-1 transition-all";return n==="h1"?i.jsx("h1",{onClick:()=>p(!0),className:`${a??""} ${E} ${S?"text-fg-muted italic":""}`,children:C}):n==="p"?i.jsx("p",{onClick:()=>p(!0),className:`${a??""} ${E} ${S?"text-fg-muted italic":""}`,children:C}):n==="badge"?i.jsx("span",{onClick:()=>p(!0),className:`${a??""} ${E} ${S?"text-fg-muted italic":""}`,children:C}):i.jsx("span",{onClick:()=>p(!0),className:`${a??""} ${E} ${S?"text-fg-muted italic":""}`,children:C})}function Dre({value:e,options:t,onChange:n,className:a,readOnly:s}){const[l,c]=k.useState(!1),[d,m]=k.useState(e),p=k.useRef(null),h=k.useRef(null);if(k.useEffect(()=>{l&&(m(e),setTimeout(()=>p.current?.focus(),0))},[l,e]),s)return i.jsx("span",{className:a,children:e});const g=t.filter(y=>y.toLowerCase().includes(d.toLowerCase())),x=y=>{const w=y.trim();w&&w!==e&&n(w),c(!1)};return l?i.jsxs("div",{ref:h,className:"relative inline-block",children:[i.jsx("input",{ref:p,value:d,onChange:y=>m(y.target.value),onKeyDown:y=>{y.key==="Enter"?(y.preventDefault(),x(d)):y.key==="Escape"&&c(!1)},onBlur:y=>{h.current?.contains(y.relatedTarget)||x(d)},className:`${a??""} bg-transparent outline-none ring-1 ring-brand-500/50 rounded w-28`}),g.length>0&&i.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:g.map(y=>i.jsx("button",{onMouseDown:w=>{w.preventDefault(),x(y)},className:`block w-full text-left px-3 py-1.5 text-xs hover:bg-surface-secondary/80 transition-colors ${y===e?"text-brand-400 font-medium":"text-fg-secondary"}`,children:y},y))})]}):i.jsx("span",{onClick:()=>c(!0),className:`${a??""} cursor-pointer hover:ring-1 hover:ring-border-default rounded px-1 -mx-1 transition-all`,children:e})}function Lre({tags:e,onChange:t,readOnly:n}){const{t:a}=ot(["builder"]),[s,l]=k.useState(!1),[c,d]=k.useState(""),m=k.useRef(null);if(k.useEffect(()=>{s&&m.current?.focus()},[s]),n)return i.jsx("div",{className:"flex flex-wrap items-center gap-1.5 min-h-[24px]",children:e.map(h=>i.jsx("span",{className:"text-[10px] px-2 py-0.5 bg-surface-elevated text-fg-muted rounded-full border border-border-default",children:h},h))});const p=h=>{if((h.key==="Enter"||h.key===",")&&c.trim()){h.preventDefault();const g=c.trim().toLowerCase();e.includes(g)||t([...e,g]),d("")}else h.key==="Backspace"&&!c&&e.length>0?t(e.slice(0,-1)):h.key==="Escape"&&(l(!1),d(""))};return s?i.jsxs("div",{className:"flex flex-wrap items-center gap-1.5 ring-1 ring-brand-500/50 rounded px-2 py-1 -mx-1 min-h-[32px]",children:[e.map(h=>i.jsxs("span",{className:"inline-flex items-center gap-1 text-[10px] bg-surface-elevated text-fg-secondary rounded-full px-2 py-0.5 border border-border-default",children:[h,i.jsx("button",{onClick:()=>t(e.filter(g=>g!==h)),className:"text-fg-muted hover:text-red-500",children:"×"})]},h)),i.jsx("input",{ref:m,value:c,onChange:h=>d(h.target.value),onKeyDown:p,onBlur:()=>{c||l(!1)},className:"flex-1 min-w-[80px] bg-transparent text-xs text-fg-primary placeholder:text-fg-muted focus:outline-none",placeholder:a("detail.typeTagAndEnter")})]}):i.jsx("div",{onClick:()=>l(!0),className:"flex flex-wrap items-center gap-1.5 cursor-text hover:ring-1 hover:ring-border-default rounded px-1 -mx-1 py-0.5 transition-all min-h-[24px]",children:e.length>0?e.map(h=>i.jsx("span",{className:"text-[10px] px-2 py-0.5 bg-surface-elevated text-fg-muted rounded-full border border-border-default",children:h},h)):i.jsx("span",{className:"text-[10px] text-fg-muted italic",children:a("detail.typeTagAndEnter")})})}function kg({content:e}){const t=[D5,I3,O3],n=[SS,[G3,{strict:"ignore"}],[cS,{detect:!0,ignoreMissing:!0}]],a=OS({}),s=k.useMemo(()=>{let l=ui(e,mS);return l=ui(l,hS),l},[e]);return i.jsx("div",{className:`prose prose-invert prose-sm max-w-none
869
+ `)||void 0;s({approved:M,comment:G,selectedOption:O,answers:D})};return zr.createPortal(i.jsx("div",{className:"fixed inset-0 z-[10000] flex items-center justify-center p-4 bg-black/50 backdrop-blur-sm",onMouseDown:D=>{D.target===D.currentTarget&&a()},children:i.jsxs("div",{className:"w-full max-w-2xl max-h-[85vh] flex flex-col bg-surface-secondary border border-border-default rounded-2xl shadow-2xl overflow-hidden",children:[i.jsxs("div",{className:"flex items-start gap-3 px-6 py-4 border-b border-border-default shrink-0",children:[i.jsx("div",{className:"w-9 h-9 rounded-lg bg-amber-500/15 text-amber-500 flex items-center justify-center shrink-0",children:i.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[i.jsx("path",{d:"M12 2a10 10 0 1 0 0 20 10 10 0 0 0 0-20z"}),i.jsx("path",{d:"M12 8v4"}),i.jsx("path",{d:"M12 16h.01"})]})}),i.jsxs("div",{className:"flex-1 min-w-0",children:[i.jsx("h2",{className:"text-base font-semibold text-fg-primary leading-snug",children:e.title}),i.jsxs("div",{className:"flex items-center gap-2 mt-0.5",children:[i.jsx("p",{className:"text-xs text-fg-tertiary",children:e.agentName}),n&&i.jsxs("span",{className:"inline-flex items-center gap-1 px-1.5 py-0.5 rounded text-[10px] font-medium bg-green-500/15 text-green-600",children:[i.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"3",strokeLinecap:"round",strokeLinejoin:"round",children:i.jsx("path",{d:"M20 6L9 17l-5-5"})}),l("team:userInput.submitted",{defaultValue:"Submitted"})]})]})]}),i.jsx("button",{onClick:a,className:"p-1.5 text-fg-tertiary hover:text-fg-primary rounded-md hover:bg-surface-overlay transition-colors shrink-0",title:l("common:close"),children:i.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[i.jsx("path",{d:"M18 6L6 18"}),i.jsx("path",{d:"M6 6l12 12"})]})})]}),i.jsxs("div",{className:"flex-1 overflow-y-auto px-6 py-5 space-y-4",children:[y&&i.jsx("div",{className:"flex items-center gap-2",children:c.map((D,M)=>i.jsx("button",{onClick:()=>m(M),className:`h-1.5 flex-1 rounded-full transition-colors ${M===d?"bg-brand-500":S(D)?"bg-green-500/60":"bg-border-default"}`,title:`${M+1}. ${D.prompt.slice(0,40)}`},D.id))}),y&&i.jsx("div",{className:"text-[11px] font-medium text-fg-tertiary",children:l("team:userInput.questionProgress",{current:d+1,total:c.length,defaultValue:`Question ${d+1} of ${c.length}`})}),i.jsx("div",{className:"text-sm text-fg-primary leading-relaxed",children:i.jsx(Ea,{content:g.prompt})}),g.inputType==="choice"&&g.options&&i.jsx("div",{className:"space-y-2",children:g.options.map((D,M)=>{const O=w(g.id).selectedOptionIds.includes(D.id);return i.jsxs("button",{onClick:n?void 0:()=>C(g,D.id),disabled:n,className:`w-full px-4 py-3 text-left rounded-xl border transition-colors flex items-start gap-3 ${O?"border-brand-500 bg-brand-500/10":`border-border-default ${n?"":"hover:bg-surface-overlay"}`} ${n?"cursor-default":""} ${n&&!O?"opacity-50":""}`,children:[i.jsx("span",{className:`w-6 h-6 rounded-full flex items-center justify-center text-[11px] font-bold shrink-0 mt-0.5 ${O?"bg-brand-600 text-white":"bg-surface-overlay text-fg-tertiary"}`,children:O?i.jsx("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"3",strokeLinecap:"round",strokeLinejoin:"round",children:i.jsx("path",{d:"M20 6L9 17l-5-5"})}):String.fromCharCode(65+M)}),i.jsxs("span",{className:"flex-1 min-w-0 text-sm text-fg-primary [&_p]:my-0 [&_p]:text-sm",children:[i.jsx(Ea,{content:D.label}),D.description&&i.jsx("span",{className:"block text-xs text-fg-tertiary mt-1 [&_p]:my-0 [&_p]:text-xs",children:i.jsx(Ea,{content:D.description})})]})]},D.id)})}),(g.inputType==="text"||g.allowFreeform)&&(!n||w(g.id).text)&&i.jsx("textarea",{rows:g.inputType==="text"?4:2,readOnly:n,placeholder:g.inputType==="text"?l("team:userInput.textPlaceholder",{defaultValue:"Type your answer…"}):l("team:userInput.freeformPlaceholder",{defaultValue:"Or write your own answer…"}),value:w(g.id).text,onChange:D=>{const M=D.target.value;T(g.id,{text:M,selectedOptionIds:M.trim()&&g.inputType==="choice"?[]:w(g.id).selectedOptionIds})},className:`w-full px-3.5 py-2.5 text-sm bg-surface-overlay border border-border-default rounded-xl text-fg-primary placeholder:text-fg-tertiary focus:outline-none resize-y ${n?"cursor-default opacity-80":"focus:ring-1 focus:ring-brand-500/50"}`})]}),i.jsxs("div",{className:"flex items-center justify-between gap-2 px-6 py-4 border-t border-border-default shrink-0",children:[i.jsx("div",{children:y&&d>0&&i.jsx("button",{onClick:()=>m(D=>Math.max(0,D-1)),className:"px-4 py-2 text-sm font-medium text-fg-secondary border border-border-default rounded-lg hover:bg-surface-overlay transition-colors",children:l("team:userInput.previous",{defaultValue:"Previous"})})}),i.jsx("div",{className:"flex items-center gap-2",children:y&&!x?i.jsx("button",{disabled:!n&&!S(g),onClick:()=>m(D=>Math.min(c.length-1,D+1)),className:"px-5 py-2 text-sm font-medium bg-brand-600 text-white rounded-lg hover:bg-brand-700 disabled:opacity-50 transition-colors",children:l("team:userInput.next",{defaultValue:"Next"})}):n?i.jsx("button",{onClick:a,className:"px-5 py-2 text-sm font-medium text-fg-secondary border border-border-default rounded-lg hover:bg-surface-overlay transition-colors",children:l("common:close",{defaultValue:"Close"})}):i.jsxs("button",{disabled:t||!E,onClick:L,className:"px-5 py-2 text-sm font-medium bg-brand-600 text-white rounded-lg hover:bg-brand-700 disabled:opacity-50 transition-colors inline-flex items-center gap-2",children:[t&&i.jsxs("svg",{className:"animate-spin h-4 w-4",viewBox:"0 0 24 24",fill:"none",children:[i.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),i.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"})]}),l("team:userInput.submit",{defaultValue:"Submit"})]})})]})]})}),document.body)}function Od(e){return Array.isArray(e.questions)&&e.questions.length>0}const Pd={urgent:"bg-red-500",high:"bg-amber-500",normal:"bg-blue-500",low:"bg-gray-400"},Io={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"},lk={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 Oo(e,t){const n=Date.now()-new Date(e).getTime(),a=Math.floor(n/6e4);if(a<1)return t("common:time.now");if(a<60)return t("common:time.minutesAgo",{count:a});const s=Math.floor(a/60);return s<24?t("common:time.hoursAgo",{count:s}):t("common:time.daysAgo",{count:Math.floor(s/24)})}const ck="markus:template-updates-ack";let ph=!1,zd=null;function pre(e){return e.map(t=>`${t.name}@${t.availableVersion}`).sort().join(",")}function uk(e,t){if(e.type!=="system"||!e.metadata?.templateUpdates)return!1;if(!t)return!0;const n=e.metadata.templateUpdatesFingerprint;return!n||n===t}function Bd(e,t){const n=e.actionType;if(n==="open_chat")return t("team:notifications.actionHints.openChat");if(n==="navigate")return t("team:notifications.actionHints.viewDetails");const a=e.metadata??{};switch(e.type){case"task_completed":case"task_created":case"task_review":case"task_failed":return a.taskId?t("team:notifications.actionHints.viewTask"):null;case"requirement_created":case"requirement_decision":return a.requirementId?t("team:notifications.actionHints.viewRequirement"):null;case"agent_report":return a.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");case"system":return a.templateUpdates?t("common:templateUpdates.actionHint"):null;default:return a.taskId?t("team:notifications.actionHints.viewTask"):a.requirementId?t("team:notifications.actionHints.viewRequirement"):a.agentId?t("team:notifications.actionHints.viewAgent"):null}}function ZS(e){const t=e.metadata;if(!(!t||typeof t.i18n!="object"||!t.i18n))return t.i18n}function dk(e,t){const n=ZS(e);if(!n?.titleKey)return e.title;const a={...n.titleParams??{}};return t(`team:${n.titleKey}`,{...a,defaultValue:e.title})}function mk(e,t){const n=ZS(e);if(!n?.bodyKey)return e.body;const a={};for(const[s,l]of Object.entries(n.bodyParams??{}))a[s]=s==="status"||s==="statusKey"?t(`common:status.${l}`,{defaultValue:l}):l;return t(`team:${n.bodyKey}`,{...a,defaultValue:e.body})}function fh(){try{const e=new AudioContext,t=e.currentTime,n=e.createGain();n.connect(e.destination),n.gain.setValueAtTime(.15,t),n.gain.exponentialRampToValueAtTime(.01,t+.6);const a=e.createOscillator();a.type="sine",a.frequency.setValueAtTime(880,t),a.frequency.setValueAtTime(1174.66,t+.15),a.connect(n),a.start(t),a.stop(t+.6),a.onended=()=>e.close()}catch{}}function fre({collapsed:e,userId:t,embeddedMode:n,onClose:a,sidebarMode:s,isActive:l,label:c,iconPath:d}){const{t:m}=ot(["team","common"]),[p,h]=k.useState(!1),[g,x]=k.useState("approvals"),[y,w]=k.useState([]),[T,C]=k.useState([]),[S,E]=k.useState(null),[_,L]=k.useState(null),[D,M]=k.useState(null),[O,G]=k.useState({}),[Q,$]=k.useState(0),[Y,K]=k.useState([]),ee=k.useRef(null),U=k.useRef(null),[te,I]=k.useState({top:0,left:0,width:448,maxHeight:576}),J=k.useRef(null),me=k.useRef(!1),[Ce,H]=k.useState(!0),[V,fe]=k.useState(!1),z=k.useRef(null),je=k.useRef("approvals"),[Ue,qe]=k.useState(!1),[He,ut]=k.useState("unread"),dt=30,Nt=100,wt=k.useCallback(async()=>{try{li("/approvals"),li("/notifications");const[F,ge,Xe]=await Promise.all([Ae.notifications.list(t,!1,{limit:dt,offset:0}),Ae.approvals.list(),Ae.notifications.list(t,!0,{limit:Nt,offset:0})]);w(F.notifications),K(Xe.notifications);const ye=F.unreadCount??F.notifications.filter(tt=>!tt.read).length;if($(ye),H(F.totalCount!=null?F.notifications.length<F.totalCount:F.notifications.length>=dt),C(ge.approvals),!me.current){const tt=ge.approvals.filter(ft=>ft.status==="pending").length;J.current=tt,me.current=!0}}catch{}},[t]),Zt=k.useCallback(async()=>{if(!(V||!Ce)){fe(!0);try{const F=await Ae.notifications.list(t,!1,{limit:dt,offset:y.length});F.notifications.length>0&&w(ge=>[...ge,...F.notifications.filter(Xe=>!ge.some(ye=>ye.id===Xe.id))]),H(F.totalCount!=null?y.length+F.notifications.length<F.totalCount:F.notifications.length>=dt)}catch{}fe(!1)}},[t,y.length,V,Ce]),Wt=k.useCallback(F=>{const ge=F.detail;if(!ge)return;const{taskId:Xe,requirementId:ye}=ge;!Xe&&!ye||w(tt=>{const ft=tt.filter(bt=>!bt.read&&(Xe&&bt.metadata?.taskId===Xe||ye&&bt.metadata?.requirementId===ye));if(ft.length===0)return tt;for(const bt of ft)Ae.notifications.markRead(bt.id).catch(()=>{});$(bt=>Math.max(0,bt-ft.length));const Ht=new Set(ft.map(bt=>bt.id));return K(bt=>bt.filter(le=>!Ht.has(le.id))),tt.map(bt=>ft.some(le=>le.id===bt.id)?{...bt,read:!0}:bt)})},[]),rt=k.useRef(y);rt.current=y;const $e=k.useCallback(async()=>{if(!rt.current.some(ge=>!ge.read&&ge.type==="system"&&ge.metadata?.creditExhausted))try{await Ae.notifications.create({title:m("credits.notificationTitle",{ns:"common"}),body:m("credits.notificationBody",{ns:"common"}),type:"system",priority:"urgent",metadata:{creditExhausted:!0}}),wt(),fh()}catch{}},[wt,m]),mt=k.useCallback(async()=>{if(!ph){ph=!0;try{const{updates:F}=await Ae.skills.updates();if(!F.length)return;const ge=pre(F);try{if(localStorage.getItem(ck)===ge)return}catch{}if(zd===ge||rt.current.some(ye=>!ye.read&&uk(ye,ge)))return;try{const tt=(await Ae.notifications.list(t,!0,{limit:50,type:"system"})).notifications.filter(ft=>uk(ft,ge)).sort((ft,Ht)=>new Date(Ht.createdAt).getTime()-new Date(ft.createdAt).getTime());if(tt.length>0){for(const ft of tt.slice(1))Ae.notifications.markRead(ft.id).catch(()=>{});tt.length>1&&wt(),zd=ge;return}}catch{}zd=ge,await Ae.notifications.create({title:m("templateUpdates.notificationTitle",{ns:"common"}),body:m("templateUpdates.notificationBody",{ns:"common",count:F.length}),type:"system",priority:"high",metadata:{templateUpdates:!0,templateUpdatesFingerprint:ge,count:F.length,skills:F.map(ye=>ye.name)}}),wt(),fh()}catch{zd=null}finally{ph=!1}}},[wt,m,t]);k.useEffect(()=>{wt();const F=setInterval(wt,6e4);let ge=null;const Xe=()=>{ge||(ge=setTimeout(()=>{ge=null,wt()},400))},ye=()=>Xe(),tt=()=>{h(!0),wt()};window.addEventListener("markus:notifications-changed",ye),window.addEventListener("markus:mark-read-by-ref",Wt),window.addEventListener("markus:open-notifications",tt),window.addEventListener("markus:credit-exhausted",$e);const ft=Ir.on("notification",Xe),Ht=Ir.on("approval:requested",Xe);return()=>{clearInterval(F),ge&&clearTimeout(ge),window.removeEventListener("markus:notifications-changed",ye),window.removeEventListener("markus:mark-read-by-ref",Wt),window.removeEventListener("markus:open-notifications",tt),window.removeEventListener("markus:credit-exhausted",$e),ft(),Ht()}},[wt,Wt,$e]),k.useEffect(()=>{mt();const F=setInterval(()=>{mt()},5*6e4),ge=()=>{mt()};return window.addEventListener("markus:data-changed",ge),()=>{clearInterval(F),window.removeEventListener("markus:data-changed",ge)}},[t]);const At=k.useCallback(()=>{if(!ee.current)return;const F=ee.current.getBoundingClientRect(),ge=window.innerWidth,Xe=window.innerHeight,ye=Math.min(448,ge-16),tt=Math.min(576,Xe-16);let ft=F.right+8,Ht=F.top;ft+ye>ge-8&&(ft=Math.max(8,ge-ye-8)),Ht+tt>Xe-8&&(Ht=Math.max(8,Xe-tt-8)),I({top:Ht,left:ft,width:ye,maxHeight:tt})},[]);k.useLayoutEffect(()=>{p&&At()},[p,At]),k.useEffect(()=>{if(p)return window.addEventListener("resize",At),()=>window.removeEventListener("resize",At)},[p,At]),k.useEffect(()=>{if(!p)return;const F=ge=>{ee.current?.contains(ge.target)||U.current?.contains(ge.target)||h(!1)};return document.addEventListener("mousedown",F),()=>document.removeEventListener("mousedown",F)},[p]),k.useEffect(()=>{if(!p)return;ut("unread");const F=T.some(Xe=>Xe.status==="pending"),ge=y.some(Xe=>!Xe.read);x(F&&!ge?"approvals":!F&&ge?"notifications":je.current)},[p]);const Dt=new Set(T.filter(F=>F.status==="pending").map(F=>F.id)),ln=new Set(T.map(F=>F.id)),ce=F=>F.type==="approval_request"&&!!F.metadata?.approvalId&&ln.has(F.metadata.approvalId),et=F=>[...F].sort((ge,Xe)=>new Date(Xe.createdAt).getTime()-new Date(ge.createdAt).getTime()),nt=y.filter(F=>!ce(F)),we=Y.filter(F=>!ce(F)),Me=et(nt),Ne=et(we),se=He==="all"?Me:Ne,q=m(He==="unread"?"team:notifications.noUnread":"team:notifications.noNotifications"),ae=Ne.length,Se=Dt.size,De=ae+Se;k.useEffect(()=>{J.current!==null&&Se>J.current&&fh(),J.current=Se},[Se]);const Pe=async F=>{await Ae.notifications.markRead(F),w(ge=>ge.map(Xe=>Xe.id===F?{...Xe,read:!0}:Xe)),K(ge=>ge.filter(Xe=>Xe.id!==F)),$(ge=>Math.max(0,ge-1)),window.dispatchEvent(new CustomEvent("markus:notifications-changed"))},X=F=>{const ge=F.metadata??{},Xe=F.actionType,ye=F.actionTarget;if(Xe==="open_chat"&&ye)try{const tt=typeof ye=="string"?JSON.parse(ye):ye;if(tt.agentId){const ft={agentId:tt.agentId};tt.sessionId&&(ft.sessionId=tt.sessionId),at.navigate(de.TEAM,ft);return}}catch{}if(Xe==="navigate"&&ye)try{const tt=typeof ye=="string"?JSON.parse(ye):ye;if(tt.path){if(tt.path.startsWith("/team")){const ft={},Ht=new URLSearchParams(tt.path.split("?")[1]||"");for(const[bt,le]of Ht.entries())ft[bt]=le;at.navigate(de.TEAM,ft);return}if(tt.path.startsWith("/work")){const ft={},Ht=new URLSearchParams(tt.path.split("?")[1]||"");for(const[bt,le]of Ht.entries())ft[bt]=le;at.navigate(de.WORK,ft);return}}}catch{}switch(F.type){case"approval_request":{const tt=ge.approvalId,ft=tt?T.find(_e=>_e.id===tt):void 0;if(ft&&Od(ft)){L(ft);break}const Ht=ft?.details?.taskId??ge.taskId,bt=ft?.details?.requirementId??ge.requirementId,le=ft?.details?.agentId??ft?.agentId;Ht?at.navigate(de.WORK,{openTask:Ht}):bt?at.navigate(de.WORK,{openRequirement:bt}):le?at.navigate(de.TEAM,{agentId:le}):at.navigate(de.WORK);break}case"task_completed":case"task_created":case"task_review":case"task_failed":ge.taskId?at.navigate(de.WORK,{openTask:ge.taskId}):at.navigate(de.WORK);break;case"requirement_created":case"requirement_decision":ge.requirementId?at.navigate(de.WORK,{openRequirement:ge.requirementId}):at.navigate(de.WORK);break;case"agent_report":case"system":{if(ge.creditExhausted){qe(!0);return}if(ge.templateUpdates){const tt=ge.templateUpdatesFingerprint;if(tt)try{localStorage.setItem(ck,tt)}catch{}localStorage.setItem("markus_nav_storeTab","installed"),at.navigate(de.STORE);return}if(ge.agentId){const tt={agentId:ge.agentId};ge.sessionId&&(tt.sessionId=ge.sessionId),at.navigate(de.TEAM,tt)}else at.navigate(de.TEAM);break}case"direct_message":{const tt=ge.senderId;tt?at.navigate(de.TEAM,{dm:tt}):at.navigate(de.TEAM);break}case"group_message":{const tt=ge.channel;tt?at.navigate(de.TEAM,{channel:tt}):at.navigate(de.TEAM);break}default:ge.taskId?at.navigate(de.WORK,{openTask:ge.taskId}):ge.requirementId?at.navigate(de.WORK,{openRequirement:ge.requirementId}):ge.projectId?at.navigate(de.WORK,{projectId:ge.projectId}):ge.agentId&&at.navigate(de.TEAM,{agentId:ge.agentId});break}},Z=async F=>{const ge=F.metadata??{},Xe=F.actionType,ye=F.type==="agent_report"&&!ge.creditExhausted&&!ge.templateUpdates&&(Xe==="open_chat"||!!ge.agentId&&Xe!=="navigate");!F.read&&!ye&&Pe(F.id);const tt=ge.taskId,ft=ge.requirementId;if(!ye&&(tt||ft)){const Ht=y.filter(bt=>bt.id!==F.id&&!bt.read&&(tt&&bt.metadata?.taskId===tt||ft&&bt.metadata?.requirementId===ft));for(const bt of Ht)Pe(bt.id)}X(F)},ue=async(F,ge,Xe,ye,tt)=>{E(F);try{const{approval:ft}=await Ae.approvals.respond(F,ge,t,Xe,ye,tt);C(_e=>_e.map(ht=>ht.id===F?ft:ht)),L(null),M(null),G(_e=>{const ht={..._e};return delete ht[F],ht});const Ht=ft.details?.taskId,bt=ft.details?.requirementId,le=y.filter(_e=>!_e.read&&(_e.type==="approval_request"&&_e.metadata?.approvalId===F||Ht&&_e.metadata?.taskId===Ht||bt&&_e.metadata?.requirementId===bt));if(le.length>0){for(const ht of le)Ae.notifications.markRead(ht.id).catch(()=>{});const _e=new Set(le.map(ht=>ht.id));w(ht=>ht.map(Tt=>_e.has(Tt.id)?{...Tt,read:!0}:Tt)),$(ht=>Math.max(0,ht-le.length))}li("/approvals"),li("/notifications"),li("/tasks"),li("/taskboard"),li("/requirements"),window.dispatchEvent(new CustomEvent("markus:data-changed")),window.dispatchEvent(new CustomEvent("markus:notifications-changed")),setTimeout(()=>wt(),800)}catch{}E(null)},Be=async()=>{try{if(!t)return;await Ae.notifications.markAllRead(t),w(F=>F.map(ge=>({...ge,read:!0}))),K([]),$(0),li("/notifications"),window.dispatchEvent(new CustomEvent("markus:notifications-changed"))}catch{const F=nt.filter(ge=>!ge.read);await Promise.all(F.map(ge=>Ae.notifications.markRead(ge.id))),w(ge=>ge.map(Xe=>({...Xe,read:!0}))),K([]),$(0),li("/notifications"),window.dispatchEvent(new CustomEvent("markus:notifications-changed"))}},Ie=F=>{const ge=F.details?.subType;return ge==="requirement_resubmit"?m("team:notifications.approvalType.requirementResubmit"):ge==="requirement"||F.details?.requirementId?m("team:notifications.approvalType.requirement"):ge==="task_review"?m("team:notifications.approvalType.taskReview"):ge==="task"||F.details?.taskId?m("team:notifications.approvalType.task"):F.details?.toolName?m("team:notifications.approvalType.toolExecution"):null},Ge=F=>{const ge=F.details??{},Xe=ge.subType,ye=ge.priority,tt=ye?m(`common:priority.${ye}`,{defaultValue:ye}):"";if(Xe==="requirement")return m("team:notifications.approvalDesc.requirementProposed",{agentName:F.agentName,title:F.title,priority:tt,defaultValue:F.description});if(Xe==="requirement_resubmit")return m("team:notifications.approvalDesc.requirementResubmitted",{agentName:F.agentName,title:F.title,priority:tt,defaultValue:F.description});if(Xe==="task")return m("team:notifications.approvalDesc.taskCreate",{agentName:F.agentName,title:F.title,priority:tt,defaultValue:F.description});if(Xe==="task_review"){const ft=`Task "${F.title}" has been submitted for your review.`;if(F.description.startsWith(ft))return m("team:notifications.approvalDesc.taskReview",{title:F.title})+F.description.slice(ft.length)}return F.description},kt=F=>{const ge=[];ge.push(F.agentName);const Xe=F.details?.taskTitle,ye=F.details?.taskId;Xe?ge.push(Xe):ye&&ge.push(`${m("team:notifications.approvalType.task")} ${ye.slice(0,8)}`);const tt=F.details?.requirementId;return tt&&!ye&&ge.push(`${m("team:notifications.approvalType.requirement")} ${tt.slice(0,8)}`),ge.join(" · ")},Rt=[...T].sort((F,ge)=>new Date(ge.requestedAt).getTime()-new Date(F.requestedAt).getTime()),Mt=Rt.filter(F=>F.status==="pending"),Ot=Rt.filter(F=>F.status!=="pending"),Un=F=>{const ge=F.details?.taskId,Xe=F.details?.requirementId,ye=F.details?.agentId??F.agentId;ge?at.navigate(de.WORK,{openTask:ge}):Xe?at.navigate(de.WORK,{openRequirement:Xe}):ye?at.navigate(de.TEAM,{agentId:ye}):at.navigate(de.WORK)},hn=()=>{h(!1),a?.()},ie=F=>i.jsxs("button",{disabled:S===F.id,onClick:()=>L(F),className:"w-full px-3 py-2 text-[11px] font-medium bg-brand-600 text-white rounded-md hover:bg-brand-700 disabled:opacity-50 transition-colors inline-flex items-center justify-center gap-1.5",children:[i.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:i.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"})}),m("team:userInput.respond",{defaultValue:"Respond"}),F.questions&&F.questions.length>1?` (${F.questions.length})`:""]}),Ee=_?i.jsx(mre,{approval:_,submitting:S===_.id,readOnly:_.status!=="pending",onClose:()=>L(null),onSubmit:F=>ue(_.id,F.approved,F.comment,F.selectedOption,F.answers)}):null,We=i.jsxs("div",{className:"flex items-center justify-between gap-2 px-3 py-1.5 border-b border-border-default/50 shrink-0",children:[i.jsx("div",{className:"flex items-center gap-0.5 rounded-md bg-surface-overlay/60 p-0.5",children:["unread","all"].map(F=>i.jsx("button",{onClick:()=>ut(F),"aria-pressed":He===F,title:F==="unread"?m("team:notifications.noUnread"):void 0,className:`px-2 py-0.5 rounded text-[10px] font-medium transition-colors ${He===F?"bg-surface-base text-fg-primary shadow-sm":"text-fg-tertiary hover:text-fg-secondary"}`,children:F==="unread"?m("team:notifications.filterUnread")+(ae>0?` (${ae})`:""):m("team:notifications.filterAll")},F))}),Q>0&&i.jsx("button",{onClick:Be,className:"text-[10px] text-brand-500 hover:text-brand-400 transition-colors shrink-0",children:m("team:notifications.markAllRead")})]}),pt=i.jsxs(i.Fragment,{children:[i.jsxs("div",{className:"flex border-b border-border-default shrink-0",children:[i.jsxs("button",{onClick:()=>{x("approvals"),je.current="approvals"},className:`flex-1 px-3 py-2.5 text-xs font-medium transition-colors ${g==="approvals"?"text-fg-primary border-b-2 border-brand-500":"text-fg-tertiary hover:text-fg-secondary"}`,children:[m("team:notifications.approvals"),Se>0?` (${Se})`:""]}),i.jsxs("button",{onClick:()=>{x("notifications"),je.current="notifications"},className:`flex-1 px-3 py-2.5 text-xs font-medium transition-colors ${g==="notifications"?"text-fg-primary border-b-2 border-brand-500":"text-fg-tertiary hover:text-fg-secondary"}`,children:[m("team:notifications.notifications"),ae>0?` (${ae})`:""]}),i.jsx("button",{onClick:hn,className:"px-2 py-2 text-fg-tertiary hover:text-fg-primary transition-colors shrink-0",title:m("common:close"),children:i.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[i.jsx("path",{d:"M18 6L6 18"}),i.jsx("path",{d:"M6 6l12 12"})]})})]}),g==="notifications"&&We,i.jsxs("div",{ref:z,className:"flex-1 overflow-y-auto",onScroll:F=>{if(g!=="notifications"||!Ce||V)return;const ge=F.currentTarget;ge.scrollTop+ge.clientHeight>=ge.scrollHeight-80&&Zt()},children:[g==="approvals"&&(T.length===0?i.jsx("div",{className:"p-6 text-center text-xs text-fg-tertiary",children:m("team:notifications.noApprovals")}):i.jsxs("div",{className:"divide-y divide-border-default/50",children:[Mt.map(F=>{const ge=F.details?.command,Xe=ge?Ge(F).replace(/\s*Command:.*$/,""):Ge(F);return i.jsxs("div",{className:"px-3 py-3 space-y-2.5",children:[i.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:()=>Un(F),children:[i.jsxs("div",{className:"flex items-start gap-2",children:[i.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:i.jsx("path",{d:Io.approval_request})}),i.jsxs("div",{className:"flex-1 min-w-0",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[Ie(F)&&i.jsx("span",{className:"text-[10px] text-amber-500 font-medium shrink-0",children:Ie(F)}),i.jsx("span",{className:"text-xs text-fg-primary font-medium truncate",children:F.title}),i.jsx("span",{className:"text-[10px] text-fg-tertiary shrink-0",children:Oo(F.requestedAt,m)})]}),i.jsx("div",{className:"text-[11px] text-fg-tertiary mt-0.5",children:F.agentName})]})]}),i.jsx("div",{className:"mt-2.5 text-[11px] text-fg-secondary leading-relaxed",children:i.jsx(Ea,{content:Xe,className:"text-[11px] [&_h1]:text-xs [&_h2]:text-[11px] [&_h3]:text-[11px] [&_p]:text-[11px] [&_li]:text-[11px]"})}),ge&&i.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:ge})]}),(()=>{if(Od(F))return ie(F);const ye=F.details?.subType,tt=ye==="task"||ye==="requirement"||ye==="requirement_resubmit",ft=F.options&&F.options.length>0,Ht=(O[F.id]??"").trim();if(ft){const bt=le=>le.id==="approve"?m("common:approve",{defaultValue:le.label}):le.id==="reject"||le.id==="request_changes"?m("team:notifications.optionLabels.requestChanges",{defaultValue:le.label}):le.label;return i.jsxs("div",{className:"space-y-1.5",children:[F.options.map((le,_e)=>i.jsxs("button",{disabled:S===F.id,onClick:()=>ue(F.id,le.id!=="reject",Ht||void 0,le.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 ${le.id==="reject"||le.id==="request_changes"?"border border-border-default text-fg-secondary hover:bg-surface-overlay":"bg-brand-600 text-white hover:bg-brand-700"}`,title:le.description,children:[i.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+_e)}),bt(le)]},le.id)),i.jsxs("div",{className:"flex gap-1.5 mt-1",children:[i.jsx("input",{type:"text",placeholder:m("team:notifications.freeformPlaceholder"),value:O[F.id]??"",onChange:le=>G(_e=>({..._e,[F.id]:le.target.value})),onKeyDown:le=>{le.key==="Enter"&&(O[F.id]??"").trim()&&ue(F.id,!0,(O[F.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"}),i.jsx("button",{disabled:S===F.id||!(O[F.id]??"").trim(),onClick:()=>ue(F.id,!0,(O[F.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:m("common:send")})]})]})}return tt?i.jsxs("div",{className:"space-y-1.5",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsxs("button",{disabled:S===F.id,onClick:()=>ue(F.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:[i.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:i.jsx("path",{d:"M20 6L9 17l-5-5"})}),m("common:approve")]}),i.jsxs("button",{disabled:S===F.id,onClick:()=>ue(F.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:[i.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:[i.jsx("path",{d:"M18 6L6 18"}),i.jsx("path",{d:"M6 6l12 12"})]}),m("common:reject")]}),D!==F.id&&i.jsxs("button",{disabled:S===F.id,onClick:()=>M(F.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:[i.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[i.jsx("path",{d:"M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"}),i.jsx("path",{d:"M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z"})]}),m("team:notifications.needsAdjustment")]})]}),D===F.id&&i.jsxs("div",{className:"space-y-1.5",children:[i.jsx("input",{type:"text",autoFocus:!0,placeholder:m("team:notifications.adjustmentPlaceholder"),value:O[F.id]??"",onChange:bt=>G(le=>({...le,[F.id]:bt.target.value})),onKeyDown:bt=>{bt.key==="Enter"&&(O[F.id]??"").trim()&&ue(F.id,!1,(O[F.id]??"").trim(),"needs_adjustment"),bt.key==="Escape"&&M(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"}),i.jsxs("div",{className:"flex gap-2",children:[i.jsx("button",{disabled:S===F.id||!(O[F.id]??"").trim(),onClick:()=>ue(F.id,!1,(O[F.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:m("team:notifications.confirmAdjustment")}),i.jsx("button",{onClick:()=>M(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:m("common:cancel")})]})]})]}):i.jsxs("div",{className:"space-y-1.5",children:[i.jsx("input",{type:"text",placeholder:m("team:notifications.commentPlaceholder"),value:O[F.id]??"",onChange:bt=>G(le=>({...le,[F.id]:bt.target.value})),onKeyDown:bt=>{bt.key==="Enter"&&ue(F.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"}),i.jsxs("div",{className:"flex gap-2",children:[i.jsx("button",{disabled:S===F.id,onClick:()=>ue(F.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:m("common:approve")}),i.jsx("button",{disabled:S===F.id,onClick:()=>ue(F.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:m("common:reject")})]})]})})()]},F.id)}),Ot.length>0&&i.jsxs(i.Fragment,{children:[Mt.length>0&&i.jsx("div",{className:"px-3 py-1.5 text-[10px] font-medium text-fg-tertiary uppercase tracking-wider bg-surface-overlay/30",children:m("team:notifications.approvalHistory")}),Ot.slice(0,50).map(F=>i.jsxs("button",{onClick:()=>Od(F)?L(F):Un(F),className:"w-full text-left px-3 py-2.5 hover:bg-surface-overlay/50 transition-colors group",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("span",{className:`w-1.5 h-1.5 rounded-full shrink-0 ${F.status==="approved"?"bg-green-500":F.status==="cancelled"||F.status==="expired"?"bg-gray-400":"bg-red-500"}`}),Ie(F)&&i.jsx("span",{className:"text-[10px] text-fg-tertiary font-medium shrink-0",children:Ie(F)}),i.jsx("span",{className:"text-xs text-fg-secondary truncate flex-1 group-hover:text-fg-primary",children:F.title}),i.jsx("span",{className:`text-[10px] font-medium shrink-0 ${F.status==="approved"?"text-green-500":F.status==="cancelled"||F.status==="expired"?"text-fg-muted":"text-red-500"}`,children:m(`common:status.${F.status}`,{defaultValue:F.status})})]}),i.jsxs("div",{className:"flex items-center gap-1.5 mt-0.5 pl-3.5",children:[i.jsx("span",{className:"text-[10px] text-fg-muted truncate",children:kt(F)}),i.jsx("span",{className:"text-[10px] text-fg-muted shrink-0",children:"·"}),i.jsx("span",{className:"text-[10px] text-fg-muted shrink-0",children:Oo(F.respondedAt??F.requestedAt,m)})]}),F.responseComment&&i.jsxs("p",{className:"text-[10px] text-fg-muted mt-0.5 pl-3.5 truncate",children:["“",F.responseComment,"”"]})]},F.id))]})]})),g==="notifications"&&(se.length===0?i.jsx("div",{className:"p-6 text-center text-xs text-fg-tertiary",children:q}):i.jsxs("div",{className:"divide-y divide-border-default/50",children:[se.map(F=>{const ge=lk[F.type]??"text-fg-tertiary";return i.jsxs("div",{role:"button",tabIndex:0,onClick:()=>Z(F),onKeyDown:Xe=>{(Xe.key==="Enter"||Xe.key===" ")&&(Xe.preventDefault(),Z(F))},className:`w-full text-left px-3 py-2.5 flex gap-2.5 transition-colors cursor-pointer ${F.read?"opacity-50 hover:opacity-70":"hover:bg-surface-overlay"}`,children:[i.jsx("div",{className:"shrink-0 mt-0.5",children:i.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:ge,children:i.jsx("path",{d:Io[F.type]??Io.system})})}),i.jsxs("div",{className:"flex-1 min-w-0",children:[i.jsxs("div",{className:"flex items-center gap-1.5",children:[!F.read&&i.jsx("span",{className:`w-1.5 h-1.5 rounded-full shrink-0 ${Pd[F.priority]??Pd.normal}`}),i.jsx("span",{className:"text-xs text-fg-primary font-medium truncate",children:dk(F,m)})]}),i.jsx("div",{className:"text-[11px] text-fg-tertiary mt-0.5 ",children:i.jsx(Ea,{content:mk(F,m),className:"text-[11px] [&_h1]:text-xs [&_h2]:text-[11px] [&_h3]:text-[11px] [&_p]:text-[11px] [&_li]:text-[11px] [&_p]:text-fg-tertiary"})}),i.jsxs("div",{className:"flex items-center gap-2 mt-0.5",children:[i.jsx("span",{className:"text-[10px] text-fg-muted",children:Oo(F.createdAt,m)}),Bd(F,m)&&i.jsx("span",{className:`text-[10px] font-medium ${ge}`,children:Bd(F,m)})]})]})]},F.id)}),V&&i.jsx("div",{className:"py-3 text-center",children:i.jsxs("svg",{className:"animate-spin h-4 w-4 text-fg-tertiary mx-auto",viewBox:"0 0 24 24",fill:"none",children:[i.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),i.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"})]})})]}))]})]}),Bt=k.useCallback(F=>{F?.mute&&Jae()},[]),Pt=k.useCallback(F=>{Bt(F),qe(!1)},[Bt]),it=Ue?i.jsx(ba,{title:m("credits.dialogTitle",{ns:"common"}),message:m("credits.dialogDesc",{ns:"common"}),variant:"primary",cancelLabel:m("credits.configureModels",{ns:"common"}),confirmLabel:m("credits.topUp",{ns:"common"}),checkboxes:[{id:"mute",label:m("credits.dontRemind",{ns:"common"})}],onCancel:()=>qe(!1),onCancelClick:F=>{Pt(F),at.navigate(de.SETTINGS),setTimeout(()=>{window.location.hash="settings/providers"},50)},onConfirm:F=>{const ge=`${st.getUrl().replace(/\/$/,"")}/settings?tab=billing`;Pt(F),fi(ge)}}):null;if(n){const F=["approvals","notifications"],ge=F.indexOf(g),Xe=(()=>{let ye=0,tt=0;return{onTouchStart:ft=>{ye=ft.touches[0].clientX,tt=ft.touches[0].clientY},onTouchEnd:ft=>{const Ht=ft.changedTouches[0].clientX-ye,bt=ft.changedTouches[0].clientY-tt;Math.abs(Ht)>60&&Math.abs(Ht)>Math.abs(bt)*1.5&&(Ht<0&&ge<F.length-1&&x(F[ge+1]),Ht>0&&ge>0&&x(F[ge-1]))}}})();return i.jsxs(i.Fragment,{children:[it,i.jsxs("div",{className:"flex flex-col h-full overflow-hidden",children:[Ee,i.jsx("div",{className:"flex border-b border-border-default shrink-0",children:F.map(ye=>i.jsx("button",{onClick:()=>x(ye),className:`flex-1 px-3 py-3 text-sm font-medium transition-colors ${g===ye?"text-fg-primary border-b-2 border-brand-500":"text-fg-tertiary"}`,children:ye==="approvals"?i.jsxs(i.Fragment,{children:[m("team:notifications.approvals"),Se>0?` (${Se})`:""]}):i.jsxs(i.Fragment,{children:[m("team:notifications.notifications"),ae>0?` (${ae})`:""]})},ye))}),g==="notifications"&&We,i.jsx("div",{className:"flex-1 overflow-hidden relative",...Xe,children:i.jsxs("div",{className:"flex h-full transition-transform duration-300 ease-out",style:{transform:`translateX(-${ge*100}%)`},children:[i.jsx("div",{className:"w-full shrink-0 h-full overflow-y-auto scrollbar-thin",children:T.length===0?i.jsx("div",{className:"p-6 text-center text-xs text-fg-tertiary",children:m("team:notifications.noApprovals")}):i.jsxs("div",{className:"divide-y divide-border-default/50",children:[Mt.map(ye=>{const tt=ye.details?.command,ft=tt?Ge(ye).replace(/\s*Command:.*$/,""):Ge(ye);return i.jsxs("div",{className:"px-3 py-3 space-y-2.5",children:[i.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:()=>Un(ye),children:[i.jsxs("div",{className:"flex items-start gap-2",children:[i.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:i.jsx("path",{d:Io.approval_request})}),i.jsxs("div",{className:"flex-1 min-w-0",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[Ie(ye)&&i.jsx("span",{className:"text-[10px] text-amber-500 font-medium shrink-0",children:Ie(ye)}),i.jsx("span",{className:"text-xs text-fg-primary font-medium truncate",children:ye.title}),i.jsx("span",{className:"text-[10px] text-fg-tertiary shrink-0",children:Oo(ye.requestedAt,m)})]}),i.jsx("div",{className:"text-[11px] text-fg-tertiary mt-0.5",children:ye.agentName})]})]}),i.jsx("div",{className:"mt-2.5 text-[11px] text-fg-secondary leading-relaxed",children:i.jsx(Ea,{content:ft,className:"text-[11px] [&_h1]:text-xs [&_h2]:text-[11px] [&_h3]:text-[11px] [&_p]:text-[11px] [&_li]:text-[11px]"})}),tt&&i.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:tt})]}),(()=>{if(Od(ye))return ie(ye);const Ht=ye.details?.subType,bt=Ht==="task"||Ht==="requirement"||Ht==="requirement_resubmit",le=ye.options&&ye.options.length>0,_e=(O[ye.id]??"").trim();if(le){const ht=Tt=>Tt.id==="approve"?m("common:approve",{defaultValue:Tt.label}):Tt.id==="reject"||Tt.id==="request_changes"?m("team:notifications.optionLabels.requestChanges",{defaultValue:Tt.label}):Tt.label;return i.jsxs("div",{className:"space-y-1.5",children:[ye.options.map((Tt,Pn)=>i.jsxs("button",{disabled:S===ye.id,onClick:()=>ue(ye.id,Tt.id!=="reject",_e||void 0,Tt.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 ${Tt.id==="reject"||Tt.id==="request_changes"?"border border-border-default text-fg-secondary hover:bg-surface-overlay":"bg-brand-600 text-white hover:bg-brand-700"}`,title:Tt.description,children:[i.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+Pn)}),ht(Tt)]},Tt.id)),i.jsxs("div",{className:"flex gap-1.5 mt-1",children:[i.jsx("input",{type:"text",placeholder:m("team:notifications.freeformPlaceholder"),value:O[ye.id]??"",onChange:Tt=>G(Pn=>({...Pn,[ye.id]:Tt.target.value})),onKeyDown:Tt=>{Tt.key==="Enter"&&(O[ye.id]??"").trim()&&ue(ye.id,!0,(O[ye.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"}),i.jsx("button",{disabled:S===ye.id||!(O[ye.id]??"").trim(),onClick:()=>ue(ye.id,!0,(O[ye.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:m("common:send")})]})]})}return bt?i.jsxs("div",{className:"space-y-1.5",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsxs("button",{disabled:S===ye.id,onClick:()=>ue(ye.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:[i.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:i.jsx("path",{d:"M20 6L9 17l-5-5"})}),m("common:approve")]}),i.jsxs("button",{disabled:S===ye.id,onClick:()=>ue(ye.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:[i.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:[i.jsx("path",{d:"M18 6L6 18"}),i.jsx("path",{d:"M6 6l12 12"})]}),m("common:reject")]}),D!==ye.id&&i.jsxs("button",{disabled:S===ye.id,onClick:()=>M(ye.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:[i.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[i.jsx("path",{d:"M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"}),i.jsx("path",{d:"M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z"})]}),m("team:notifications.needsAdjustment")]})]}),D===ye.id&&i.jsxs("div",{className:"space-y-1.5",children:[i.jsx("input",{type:"text",autoFocus:!0,placeholder:m("team:notifications.adjustmentPlaceholder"),value:O[ye.id]??"",onChange:ht=>G(Tt=>({...Tt,[ye.id]:ht.target.value})),onKeyDown:ht=>{ht.key==="Enter"&&(O[ye.id]??"").trim()&&ue(ye.id,!1,(O[ye.id]??"").trim(),"needs_adjustment"),ht.key==="Escape"&&M(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"}),i.jsxs("div",{className:"flex gap-2",children:[i.jsx("button",{disabled:S===ye.id||!(O[ye.id]??"").trim(),onClick:()=>ue(ye.id,!1,(O[ye.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:m("team:notifications.confirmAdjustment")}),i.jsx("button",{onClick:()=>M(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:m("common:cancel")})]})]})]}):i.jsxs("div",{className:"space-y-1.5",children:[i.jsx("input",{type:"text",placeholder:m("team:notifications.commentPlaceholder"),value:O[ye.id]??"",onChange:ht=>G(Tt=>({...Tt,[ye.id]:ht.target.value})),onKeyDown:ht=>{ht.key==="Enter"&&ue(ye.id,!0,_e||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"}),i.jsxs("div",{className:"flex gap-2",children:[i.jsx("button",{disabled:S===ye.id,onClick:()=>ue(ye.id,!0,_e||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:m("common:approve")}),i.jsx("button",{disabled:S===ye.id,onClick:()=>ue(ye.id,!1,_e||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:m("common:reject")})]})]})})()]},ye.id)}),Ot.length>0&&i.jsxs(i.Fragment,{children:[Mt.length>0&&i.jsx("div",{className:"px-3 py-1.5 text-[10px] font-medium text-fg-tertiary uppercase tracking-wider bg-surface-overlay/30",children:m("team:notifications.approvalHistory")}),Ot.slice(0,50).map(ye=>i.jsxs("button",{onClick:()=>Un(ye),className:"w-full text-left px-3 py-2.5 hover:bg-surface-overlay/50 transition-colors",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("span",{className:`w-1.5 h-1.5 rounded-full shrink-0 ${ye.status==="approved"?"bg-green-500":ye.status==="cancelled"||ye.status==="expired"?"bg-gray-400":"bg-red-500"}`}),i.jsx("span",{className:"text-xs text-fg-secondary truncate flex-1",children:ye.title}),i.jsx("span",{className:`text-[10px] font-medium shrink-0 ${ye.status==="approved"?"text-green-500":ye.status==="cancelled"||ye.status==="expired"?"text-fg-muted":"text-red-500"}`,children:m(`common:status.${ye.status}`,{defaultValue:ye.status})})]}),i.jsxs("div",{className:"flex items-center gap-1.5 mt-0.5 pl-3.5",children:[i.jsx("span",{className:"text-[10px] text-fg-muted truncate",children:kt(ye)}),i.jsx("span",{className:"text-[10px] text-fg-muted shrink-0",children:"·"}),i.jsx("span",{className:"text-[10px] text-fg-muted shrink-0",children:Oo(ye.respondedAt??ye.requestedAt,m)})]})]},ye.id))]})]})}),i.jsx("div",{className:"w-full shrink-0 h-full overflow-y-auto scrollbar-thin",children:se.length===0?i.jsx("div",{className:"p-6 text-center text-xs text-fg-tertiary",children:q}):i.jsx("div",{className:"divide-y divide-border-default/50",children:se.slice(0,He==="unread"?Nt:50).map(ye=>{const tt=lk[ye.type]??"text-fg-tertiary";return i.jsxs("button",{onClick:()=>Z(ye),className:`w-full text-left px-3 py-2.5 flex gap-2.5 transition-colors ${ye.read?"opacity-50 hover:opacity-70":"hover:bg-surface-overlay"}`,children:[i.jsx("div",{className:"shrink-0 mt-0.5",children:i.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:tt,children:i.jsx("path",{d:Io[ye.type]??Io.system})})}),i.jsxs("div",{className:"flex-1 min-w-0",children:[i.jsxs("div",{className:"flex items-center gap-1.5",children:[!ye.read&&i.jsx("span",{className:`w-1.5 h-1.5 rounded-full shrink-0 ${Pd[ye.priority]??Pd.normal}`}),i.jsx("span",{className:"text-xs text-fg-primary font-medium truncate",children:dk(ye,m)})]}),i.jsx("div",{className:"text-[11px] text-fg-tertiary mt-0.5 ",children:i.jsx(Ea,{content:mk(ye,m),className:"text-[11px] [&_h1]:text-xs [&_h2]:text-[11px] [&_h3]:text-[11px] [&_p]:text-[11px] [&_li]:text-[11px] [&_p]:text-fg-tertiary"})}),i.jsxs("div",{className:"flex items-center gap-2 mt-0.5",children:[i.jsx("span",{className:"text-[10px] text-fg-muted",children:Oo(ye.createdAt,m)}),Bd(ye,m)&&i.jsx("span",{className:`text-[10px] font-medium ${tt}`,children:Bd(ye,m)})]})]})]},ye.id)})})})]})})]})]})}if(s){const F=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 i.jsxs(i.Fragment,{children:[Ee,i.jsxs("button",{ref:ee,onClick:()=>{h(!p),p||wt()},title:e?c||m("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-lg text-[13px] font-medium mb-0.5 transition-colors relative text-fg-primary ${p||l?"bg-surface-overlay":"hover:bg-surface-overlay/60"}`,children:[i.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:i.jsx("path",{d:F})}),e?i.jsx("span",{className:"text-[9px] leading-tight truncate w-full text-center",children:c}):i.jsx("span",{className:"truncate",children:c}),De>0&&i.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:De>99?m("common:badgeOverLimit"):De})]}),p&&zr.createPortal(i.jsx("div",{ref:U,className:"fixed bg-surface-secondary border border-border-default rounded-xl shadow-2xl z-[9999] flex flex-col overflow-hidden",style:{top:te.top,left:te.left,width:te.width,maxHeight:te.maxHeight},children:pt}),document.body),it]})}return i.jsxs(i.Fragment,{children:[Ee,i.jsxs("button",{ref:ee,onClick:()=>{h(!p),p||wt()},className:`relative flex items-center justify-center rounded-md transition-colors ${e?"w-8 h-8":"w-7 h-7"} ${p?"bg-surface-overlay text-fg-primary":"text-fg-tertiary hover:text-fg-secondary hover:bg-surface-overlay"}`,title:m("team:notifications.bellTitle"),children:[i.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[i.jsx("path",{d:"M18 8A6 6 0 0 0 6 8c0 7-3 9-3 9h18s-3-2-3-9"}),i.jsx("path",{d:"M13.73 21a2 2 0 0 1-3.46 0"})]}),De>0&&i.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:De>99?m("common:badgeOverLimit"):De})]}),p&&zr.createPortal(i.jsx("div",{ref:U,className:"fixed bg-surface-secondary border border-border-default rounded-xl shadow-2xl z-[9999] flex flex-col overflow-hidden",style:{top:te.top,left:te.left,width:te.width,maxHeight:te.maxHeight},children:pt}),document.body),it]})}function Hd({d:e,size:t=14}){return i.jsx("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"shrink-0",children:i.jsx("path",{d:e})})}const hh=200;function hre({authUser:e,onLogout:t,onEditProfile:n,showSettingsLink:a=!1,collapsed:s=!1,showVersion:l=!1}){const{t:c}=ot(["nav","common"]),[d,m]=k.useState(!1),[p,h]=k.useState(!1),[g,x]=k.useState({top:0,left:0}),y=k.useRef(null),w=k.useRef(null),{connected:T,user:C,credits:S,refresh:E}=h4(d),_=k.useCallback(()=>{if(!y.current)return;const K=y.current.getBoundingClientRect(),ee=window.innerWidth,U=window.innerHeight,te=w.current?.offsetHeight??220;let I=K.right+8;I+hh>ee-8&&(I=Math.max(8,K.left-hh-8));let J=K.top-te-8;J<8&&(J=Math.min(K.bottom+8,U-te-8)),x({top:Math.max(8,J),left:I})},[]);k.useLayoutEffect(()=>{if(!d)return;_();const K=requestAnimationFrame(()=>_());return()=>cancelAnimationFrame(K)},[d,_,s]),k.useEffect(()=>{if(!d)return;const K=U=>{const te=U.target;y.current?.contains(te)||w.current?.contains(te)||m(!1)},ee=()=>_();return document.addEventListener("mousedown",K),window.addEventListener("resize",ee),window.addEventListener("scroll",ee,!0),()=>{document.removeEventListener("mousedown",K),window.removeEventListener("resize",ee),window.removeEventListener("scroll",ee,!0)}},[d,_]);const L=e?.name||C?.displayName||C?.username||c("common:userPlaceholder"),D=e?.email||C?.email||"",M=m4(e?.avatarUrl,C?.avatarUrl),O=T?"bg-emerald-500":"bg-fg-muted",G=T?C?.username?c("sidebar.hubConnectedAs",{username:C.username}):c("sidebar.hubConnected"):c("sidebar.hubDisconnected"),Q=!!(T&&C?.username&&e?.name&&C.username.toLowerCase()!==e.name.toLowerCase()&&C.email?.toLowerCase()!==e.email?.toLowerCase()),$=()=>{m(!1),E({validate:!0}),at.navigate(de.SETTINGS,{tab:"account"})},Y=d&&zr.createPortal(i.jsxs("div",{ref:w,className:"fixed bg-surface-elevated border border-border-default rounded-xl shadow-xl z-[9999] overflow-hidden",style:{top:g.top,left:g.left,width:hh},children:[i.jsxs("div",{className:"px-3.5 py-3 border-b border-border-default flex items-start gap-2",children:[i.jsxs("div",{className:"min-w-0 flex-1",children:[i.jsx("div",{className:"text-sm font-medium text-fg-primary truncate",children:L}),D&&i.jsx("div",{className:"text-xs text-fg-tertiary mt-0.5 truncate",children:D}),S!==null&&i.jsxs("div",{className:"text-xs text-fg-secondary mt-0.5 flex items-center gap-1",children:[i.jsx("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"shrink-0",children:i.jsx("polyline",{points:"13 2 3 14 12 14 18 22 6 22 12 17"})}),i.jsxs("span",{className:"truncate",children:[c("common:creditBalance"),": ",S.remaining.toLocaleString()]})]})]}),n&&i.jsx("button",{type:"button",onClick:()=>{m(!1),n()},title:c("common:profile.editProfile"),className:"shrink-0 mt-0.5 p-1.5 rounded-md text-fg-tertiary hover:text-fg-secondary hover:bg-surface-overlay transition-colors",children:i.jsx(Hd,{d:"M12 20h9M16.5 3.5a2.12 2.12 0 0 1 3 3L7 19l-4 1 1-4Z",size:14})})]}),i.jsxs("button",{type:"button",onClick:$,className:"w-full px-3.5 py-2.5 border-b border-border-default flex items-center gap-2 hover:bg-surface-overlay transition-colors text-left",children:[i.jsx("span",{className:`w-2 h-2 rounded-full shrink-0 ${O}`}),i.jsxs("span",{className:"min-w-0 flex-1",children:[i.jsx("span",{className:"text-xs text-fg-secondary block truncate",children:G}),Q&&C?.username&&i.jsx("span",{className:"text-[10px] text-amber-500/90 block truncate mt-0.5",children:c("sidebar.hubAccountMismatch",{username:C.username})})]}),i.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"text-fg-muted shrink-0",children:i.jsx("path",{d:"m9 18 6-6-6-6"})})]}),i.jsxs("div",{className:"py-1",children:[a&&i.jsxs("button",{type:"button",onClick:()=>{m(!1),at.navigate(de.SETTINGS)},className:"w-full flex items-center gap-2.5 px-3.5 py-2 text-sm text-fg-secondary hover:bg-surface-overlay transition-colors",children:[i.jsx(Hd,{d:Cc[de.SETTINGS]}),c("settings")]}),window.markusDesktop&&i.jsxs("button",{type:"button",onClick:()=>{m(!1),window.markusDesktop?.openInBrowser()},className:"w-full flex items-center gap-2.5 px-3.5 py-2 text-sm text-fg-secondary hover:bg-surface-overlay transition-colors",children:[i.jsx(Hd,{d:"M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6M15 3h6v6M10 14 21 3"}),c("common:openInBrowser")]}),t&&i.jsxs("button",{type:"button",onClick:()=>{m(!1),h(!0)},className:"w-full flex items-center gap-2.5 px-3.5 py-2 text-sm text-fg-secondary hover:bg-surface-overlay transition-colors",children:[i.jsx(Hd,{d:"M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4M16 17l5-5-5-5M21 12H9"}),c("common:signOut")]})]})]}),document.body);return i.jsxs("div",{className:`relative ${s?"flex justify-center":"flex items-center justify-between gap-2 w-full"}`,children:[i.jsxs("button",{ref:y,type:"button",onClick:()=>m(K=>!K),title:L,className:`relative inline-flex items-center justify-center rounded-full transition-opacity hover:opacity-90 ${s?"p-0.5":""}`,children:[i.jsx(Zi,{name:L,avatarUrl:M,size:s?28:32,fallback:"icon"}),i.jsx("span",{className:`absolute bottom-0 right-0 w-2.5 h-2.5 rounded-full border-2 border-surface-secondary ${O}`,title:G})]}),l&&!s&&i.jsxs("span",{className:"text-[10px] text-fg-muted select-none shrink-0",children:["v","0.11.0-rc.1"]}),Y,p&&t&&i.jsx(ba,{title:c("common:signOutConfirmTitle"),message:c("common:signOutConfirmMessage"),confirmLabel:c("common:signOut"),variant:"primary",onConfirm:()=>{h(!1),t()},onCancel:()=>h(!1)})]})}function gre({d:e,size:t=18}){return i.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:i.jsx("path",{d:e})})}function bre({currentPage:e,onNavigate:t,authUser:n,collapsed:a,onToggleCollapse:s,onLogout:l,keyboardFocusPageId:c,keyboardPaneActive:d}){const{t:m}=ot(["nav","common"]);return i.jsxs("aside",{"data-keyboard-pane":"l0",className:"markus-app-sidebar h-dvh bg-surface-secondary flex flex-col shrink-0 overflow-hidden",children:[i.jsx("div",{"data-electron-drag":!0,className:`electron-mac-sidebar-header flex items-center ${a?"px-2 py-3.5 justify-center":"px-4 h-14 justify-between"}`,children:i.jsxs("button",{"data-no-drag":!0,onClick:s,title:m(a?"sidebar.expandSidebar":"sidebar.collapseSidebar"),className:"flex items-center gap-2.5 min-w-0 group",children:[i.jsx("img",{src:"/logo.png",alt:"Markus",className:"w-8 h-8 rounded-lg shrink-0"}),!a&&i.jsx("span",{className:"text-[15px] font-bold tracking-tight text-fg-primary whitespace-nowrap",children:"Markus"})]})}),i.jsx("nav",{className:`${a?"p-1":"px-3 py-2"} flex-1 overflow-y-auto scrollbar-thin`,children:aU.map((p,h)=>{const g=r4.filter(y=>y.section===p.key);if(g.length===0)return null;const x=m(`sections.${p.key}`);return i.jsx("div",{children:i.jsxs("div",{className:h>0?"mt-3":"",children:[!a&&x&&i.jsx("div",{className:"px-3 py-1.5 mb-1 text-[10px] font-semibold text-fg-muted uppercase tracking-[0.1em]",children:x}),a&&h>0&&i.jsx("div",{className:"my-3"}),g.map(y=>{if(y.id===de.NOTIFICATIONS)return i.jsx(fre,{sidebarMode:!0,collapsed:a,userId:n?.id,label:m(y.id),iconPath:Cc[y.id],isActive:e===y.id},y.id);const w=e===y.id,T=d&&c===y.id;return i.jsxs("button",{"data-l0-page-id":y.id,onClick:()=>t(y.id),title:a?m(y.id):void 0,className:`w-full flex items-center ${a?"flex-col justify-center px-1 py-1.5 gap-0.5":"gap-3 px-3 py-[7px]"} rounded-lg text-[13px] font-medium mb-0.5 transition-colors text-fg-primary ${T?"bg-brand-500/25 ring-1 ring-inset ring-brand-500/40":w?"bg-surface-overlay":"hover:bg-surface-overlay/60"}`,children:[i.jsx(gre,{d:Cc[y.id]??"",size:a?16:18}),a?i.jsx("span",{className:"text-[9px] leading-tight truncate w-full text-center",children:m(y.id)}):i.jsx("span",{className:"truncate",children:m(y.id)})]},y.id)})]})},p.key)})}),i.jsx("div",{className:`shrink-0 border-t border-border-subtle ${a?"p-1.5 flex justify-center":"px-3 py-2.5"}`,children:i.jsx(hre,{authUser:n,onLogout:l,onEditProfile:()=>{window.dispatchEvent(new Event("markus:open-edit-profile"))},showSettingsLink:!1,collapsed:a,showVersion:!a})})]})}const yre=6e4,xre=2e3;let Ar={},Yi={};const xg=new Set,Rm=new Set;let e6=0;const vg=new Map;let yc=null,$d=0,nm=null;function Lc(){for(const e of xg)e()}function pk(e,t){const n=Object.keys(e);if(n.length!==Object.keys(t).length)return!1;for(const a of n)if(e[a]!==t[a])return!1;return!0}function vre(e,t){const n={},a=[];for(const[s,l]of Object.entries(e)){if(t.has(s)){l>0&&a.push(s);continue}n[s]=l}return{counts:n,staleActiveKeys:a}}function yb(e,t){const n=Date.now(),a=vg.get(e)??0;!t?.force&&n-a<xre||(vg.set(e,n),e in Ar&&(delete Ar[e],Lc()),Ae.unread.markRead(e,new Date().toISOString()).catch(()=>{}))}async function wg(){try{const e=await Ae.unread.getCounts(),{counts:t,staleActiveKeys:n}=vre(e.counts??{},Rm);Ar=t,Yi=e.sessionAgentMap??{},Lc();for(const a of n)yb(a)}catch{}}function wre(){yc||(wg(),yc=setInterval(wg,yre),nm=Ir.on("chat:unread_update",e=>{const t=e.payload?.conversationKey;if(t){if(Rm.has(t)){yb(t);return}Date.now()>e6&&(Ar[t]=(Ar[t]??0)+1,Lc())}}))}function kre(){yc&&(clearInterval(yc),yc=null),nm&&(nm(),nm=null)}function Sre(e){const t=e?.enabled??!0,[n,a]=k.useState(Ar),[s,l]=k.useState(Yi),c=k.useCallback(async()=>{await wg()},[]),d=k.useCallback(async w=>{const T=new Date().toISOString();delete Ar[w],Lc();try{await Ae.unread.markRead(w,T)}catch{}},[]),m=k.useCallback(async()=>{Ar={},Lc();try{await Ae.unread.markAllRead()}catch{}},[]),p=k.useCallback(w=>{Rm.add(w)},[]),h=k.useCallback(w=>{Rm.delete(w),e6=Date.now()+150,vg.delete(w),yb(w,{force:!0})},[]);k.useEffect(()=>{if(!t)return;$d++,wre();let w=Yi;const T=()=>{a(C=>pk(C,Ar)?C:{...Ar}),w!==Yi&&(w=Yi,l(C=>pk(C,Yi)?C:{...Yi}))};return xg.add(T),a({...Ar}),l({...Yi}),()=>{xg.delete(T),$d--,$d<=0&&($d=0,kre())}},[t]);const g=k.useMemo(()=>Object.values(n).reduce((w,T)=>w+T,0),[n]),x=k.useCallback(w=>n[`session:${w}`]??0,[n]),y=k.useCallback(w=>n[`channel:${w}`]??0,[n]);return{counts:n,totalUnread:g,sessionAgentMap:s,getSessionUnread:x,getChannelUnread:y,markRead:d,markAllRead:m,refresh:c,setActiveKey:p,clearActiveKey:h}}function Bse(e,t){return k.useMemo(()=>{const n=new Map;for(const[a,s]of Object.entries(t))if(a.startsWith("session:")){const l=a.slice(8),c=e[l];c&&n.set(c,(n.get(c)??0)+s)}return n},[e,t])}function Cre(e){return e.startsWith("channel:dm:a2a:")}function Are(e,t){let n=0;for(const[a,s]of Object.entries(e))if(a.startsWith("session:")){const l=a.slice(8);t[l]&&(n+=s)}else if(a.startsWith("channel:")){if(Cre(a))continue;n+=s}return n}function Tre({currentPage:e,onNavigate:t,userId:n}){const{t:a}=ot("nav"),[s,l]=k.useState(0),{counts:c,sessionAgentMap:d}=Sre({enabled:!0}),m=k.useMemo(()=>Are(c,d),[c,d]),p=k.useCallback(async()=>{try{const h=await Ae.notifications.list(n,!1);l(h.unreadCount??h.notifications.filter(g=>!g.read).length)}catch{}},[n]);return k.useEffect(()=>{p();const h=setInterval(()=>{document.visibilityState==="visible"&&p()},3e4),g=()=>p();return window.addEventListener("markus:notifications-changed",g),()=>{clearInterval(h),window.removeEventListener("markus:notifications-changed",g)}},[p]),i.jsx("nav",{className:"fixed bottom-0 left-0 right-0 z-50 bg-surface-secondary flex items-stretch h-14 safe-area-bottom",children:iU.map(h=>{const g=h.group.includes(e),x=h.id===de.NOTIFICATIONS,y=h.id===de.TEAM;return i.jsxs("button",{onClick:()=>t(h.id),className:`flex-1 flex flex-col items-center justify-center gap-0.5 transition-colors ${g?"text-fg-primary":"text-fg-tertiary active:text-fg-secondary"}`,children:[i.jsxs("div",{className:"relative",children:[i.jsx("svg",{width:20,height:20,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:g?2:1.75,strokeLinecap:"round",strokeLinejoin:"round",className:"shrink-0",children:i.jsx("path",{d:Cc[h.id]})}),x&&s>0&&i.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:s>99?"99+":s}),y&&m>0&&i.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:m>99?"99+":m})]}),i.jsx("span",{className:`text-[10px] leading-tight ${g?"font-semibold":""}`,children:a(h.id)})]},h.id)})})}const Dm=new Map;function Ns(e,t){Dm.has(e)||Dm.set(e,t().catch(()=>{}))}function Ls(e){const t=Dm.get(e);return Dm.delete(e),t}const qa={builderArtifacts:"builder.artifacts",builderAgents:"builder.agents",builderHubMyItems:"builder.hubMyItems",builderInstalled:"builder.installed",hubAgents:"hub.agents",hubTeams:"hub.teams",hubSkills:"hub.skills"},Bs={agent:{label:"Agent",labelZh:"智能体",gradient:"from-violet-500 to-indigo-600",accent:"#8b5cf6",covers:[["#7c3aed","#4f46e5"],["#8b5cf6","#6366f1"],["#a855f7","#4338ca"],["#6d28d9","#2563eb"]]},team:{label:"Team",labelZh:"AI 小队",gradient:"from-cyan-500 to-blue-600",accent:"#06b6d4",covers:[["#0891b2","#2563eb"],["#06b6d4","#3b82f6"],["#0e7490","#1d4ed8"],["#22d3ee","#4f46e5"]]},skill:{label:"Skill",labelZh:"技能",gradient:"from-amber-500 to-orange-600",accent:"#f59e0b",covers:[["#f59e0b","#ea580c"],["#d97706","#dc2626"],["#fbbf24","#f97316"],["#f59e0b","#b45309"]]},connector:{label:"Connector",labelZh:"连接器",gradient:"from-emerald-500 to-teal-600",accent:"#10b981",covers:[["#10b981","#0d9488"],["#059669","#0891b2"],["#34d399","#14b8a6"],["#16a34a","#0f766e"]]}};function il(e){const t=(e||"").toLowerCase();return t==="team"?"team":t==="skill"?"skill":t==="connector"||t==="mcp"?"connector":"agent"}function t6(e){let t=2166136261;for(let n=0;n<e.length;n++)t^=e.charCodeAt(n),t=Math.imul(t,16777619);return t>>>0}const Nre={agent:258,team:205,skill:32,connector:162};function xb(e,t){const n=Nre[e],a=t6(t),s=((n+(a%68-34))%360+360)%360,l=(s+22+(a>>>8)%24)%360;return`linear-gradient(${120+a%44}deg, hsl(${s} 72% 56%), hsl(${l} 66% 43%))`}const fk=["M12 2l2.4 6.9L21 9l-5.4 4 2 7-5.6-4.1L6.4 20l2-7L3 9l6.6-.1z","M12 2a10 10 0 100 20 10 10 0 000-20zm0 4a6 6 0 110 12 6 6 0 010-12z","M4 4h7v7H4zM13 4h7v7h-7zM4 13h7v7H4zM13 13h7v7h-7z","M12 2l9 5v10l-9 5-9-5V7z","M3 12a9 9 0 019-9v9h9a9 9 0 11-18 0z","M6 3h12l3 6-9 12L3 9z","M12 3l3 6 6 .9-4.5 4.3 1 6.3L12 18l-5.5 2.5 1-6.3L3 9.9 9 9z","M4 12a8 8 0 018-8v4a4 4 0 00-4 4zm8 8a8 8 0 01-8-8h4a4 4 0 004 4z","M12 2l7 4v12l-7 4-7-4V6z M12 6l-3 1.7v3.4L12 13l3-1.9V7.7z","M3 6h18M3 12h18M3 18h18","M12 2a10 10 0 100 20A6 6 0 0112 8a6 6 0 010 12","M12 2l4 8h-8zM4 12h16l-8 10z"];function n6(e){return fk[t6(e+"g")%fk.length]}function a6(e){return e?e.startsWith("http://")||e.startsWith("https://")||e.startsWith("/")||e.startsWith("data:")||/\.(png|jpe?g|gif|webp|svg)$/i.test(e):!1}function Ere(e){return!e||a6(e)?!1:[...e].length<=4&&new RegExp("\\p{Extended_Pictographic}","u").test(e)}function jre(e,t="user"){const n=t==="org"?"shapes":"thumbs",a=encodeURIComponent(e);return`https://api.dicebear.com/9.x/${n}/svg?seed=${a}&radius=50&backgroundType=gradientLinear`}function $o(e){const t=e??0;return t<1e3?String(t):t<1e6?`${(t/1e3).toFixed(t<1e4?1:0)}k`.replace(".0k","k"):`${(t/1e6).toFixed(1)}M`.replace(".0M","M")}function hk(e,t="usd"){return!e||e<=0?"Free":`${t.toLowerCase()==="usd"?"$":""}${(e/100).toFixed(e%100===0?0:2)}`}const gk={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"}},Mre=["development","devops","management","productivity","browser","custom","general"],_re=[{label:"Tech",emojis:["✦","◈","⬡","⚡","🤖","🧠","💡","🎯","🔧","📦","🚀","💻","🛠️","⭐","🔥","💎","⚙️","🧩","🔌","💾","🖥️","📡","🔬","🧪","🏗️","📱","🎮","🕹️","📟","💽","🖨️","⌨️"]},{label:"People",emojis:["👤","👥","🧑‍💻","👨‍💼","👩‍🔬","🧙","🦸","🤝","💪","🎓","👷","🕵️","🧑‍🎨","🧑‍🏫","👨‍🚀","🥷","🧑‍🏭","🧑‍⚕️","🧑‍🔧","🧑‍🍳","👨‍🎤","🦹","🧝","🧞","🧑‍✈️","💂","🤴","👸","🧛","🧟","🧜","🧚"]},{label:"Objects",emojis:["📝","📊","🗂️","📁","🔍","🔑","🌐","💬","🔒","🎨","📐","🗃️","📋","✏️","🖊️","📌","📎","🧲","🪝","🧰","🪜","🧬","🔭","💊","🩺","📕","📗","📘","📙","📓","🗒️","📰"]},{label:"Symbols",emojis:["❤️","🧡","💛","💚","💙","💜","🖤","🤍","♠️","♥️","♦️","♣️","🎵","🎶","💯","✅","❌","⭕","🔴","🟠","🟡","🟢","🔵","🟣","⚫","⚪","🟤","🔶","🔷","▶️","⏸️","⏹️"]},{label:"Nature",emojis:["🌟","🌈","🌊","🌿","🍀","🔮","💫","✨","🌙","☀️","🦋","🐉","🦊","🐺","🦅","🐙","🦁","🐯","🦄","🐲","🌸","🌺","🍄","🌵","🎄","🌴","🍁","🌻","🐝","🦎","🐍","🦈"]},{label:"Activity",emojis:["🎯","🏆","🥇","🎖️","🏅","🎪","🎭","🎬","🎤","🎧","🎼","🎹","🥁","🎸","🎺","🎻","⚽","🏀","🎾","🏐","🎲","🧸","🪁","🎰","🎳","🏹","🥊","🤺","⛷️","🏄","🚴","🧗"]}],Rre={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-brand-500/15 text-brand-400 border-brand-500/30"}};function gh({value:e,onChange:t,renderAs:n="span",className:a,editClassName:s,placeholder:l,multiline:c,readOnly:d}){const[m,p]=k.useState(!1),[h,g]=k.useState(e),x=k.useRef(null);if(k.useEffect(()=>{g(e)},[e]),k.useEffect(()=>{m&&x.current?.focus()},[m]),d){const _=e||l,D=`${a??""} ${!e?"text-fg-muted italic":""}`;return n==="h1"?i.jsx("h1",{className:D,children:_}):n==="p"?i.jsx("p",{className:D,children:_}):i.jsx("span",{className:D,children:_})}const y=()=>{p(!1),h!==e&&t(h)},w=()=>{g(e),p(!1)},T=_=>{_.key==="Escape"&&w(),_.key==="Enter"&&!c&&y()};if(m){const _=`bg-transparent outline-none w-full ${s??a??""} ring-1 ring-brand-500/50 rounded px-1 -mx-1`;return c?i.jsx("textarea",{ref:x,value:h,onChange:L=>g(L.target.value),onBlur:y,onKeyDown:T,className:`${_} resize-y min-h-[60px]`,placeholder:l}):i.jsx("input",{ref:x,value:h,onChange:L=>g(L.target.value),onBlur:y,onKeyDown:T,className:_,placeholder:l})}const C=e||l,S=!e,E="cursor-text hover:ring-1 hover:ring-border-default rounded px-1 -mx-1 transition-all";return n==="h1"?i.jsx("h1",{onClick:()=>p(!0),className:`${a??""} ${E} ${S?"text-fg-muted italic":""}`,children:C}):n==="p"?i.jsx("p",{onClick:()=>p(!0),className:`${a??""} ${E} ${S?"text-fg-muted italic":""}`,children:C}):n==="badge"?i.jsx("span",{onClick:()=>p(!0),className:`${a??""} ${E} ${S?"text-fg-muted italic":""}`,children:C}):i.jsx("span",{onClick:()=>p(!0),className:`${a??""} ${E} ${S?"text-fg-muted italic":""}`,children:C})}function Dre({value:e,options:t,onChange:n,className:a,readOnly:s}){const[l,c]=k.useState(!1),[d,m]=k.useState(e),p=k.useRef(null),h=k.useRef(null);if(k.useEffect(()=>{l&&(m(e),setTimeout(()=>p.current?.focus(),0))},[l,e]),s)return i.jsx("span",{className:a,children:e});const g=t.filter(y=>y.toLowerCase().includes(d.toLowerCase())),x=y=>{const w=y.trim();w&&w!==e&&n(w),c(!1)};return l?i.jsxs("div",{ref:h,className:"relative inline-block",children:[i.jsx("input",{ref:p,value:d,onChange:y=>m(y.target.value),onKeyDown:y=>{y.key==="Enter"?(y.preventDefault(),x(d)):y.key==="Escape"&&c(!1)},onBlur:y=>{h.current?.contains(y.relatedTarget)||x(d)},className:`${a??""} bg-transparent outline-none ring-1 ring-brand-500/50 rounded w-28`}),g.length>0&&i.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:g.map(y=>i.jsx("button",{onMouseDown:w=>{w.preventDefault(),x(y)},className:`block w-full text-left px-3 py-1.5 text-xs hover:bg-surface-secondary/80 transition-colors ${y===e?"text-brand-400 font-medium":"text-fg-secondary"}`,children:y},y))})]}):i.jsx("span",{onClick:()=>c(!0),className:`${a??""} cursor-pointer hover:ring-1 hover:ring-border-default rounded px-1 -mx-1 transition-all`,children:e})}function Lre({tags:e,onChange:t,readOnly:n}){const{t:a}=ot(["builder"]),[s,l]=k.useState(!1),[c,d]=k.useState(""),m=k.useRef(null);if(k.useEffect(()=>{s&&m.current?.focus()},[s]),n)return i.jsx("div",{className:"flex flex-wrap items-center gap-1.5 min-h-[24px]",children:e.map(h=>i.jsx("span",{className:"text-[10px] px-2 py-0.5 bg-surface-elevated text-fg-muted rounded-full border border-border-default",children:h},h))});const p=h=>{if((h.key==="Enter"||h.key===",")&&c.trim()){h.preventDefault();const g=c.trim().toLowerCase();e.includes(g)||t([...e,g]),d("")}else h.key==="Backspace"&&!c&&e.length>0?t(e.slice(0,-1)):h.key==="Escape"&&(l(!1),d(""))};return s?i.jsxs("div",{className:"flex flex-wrap items-center gap-1.5 ring-1 ring-brand-500/50 rounded px-2 py-1 -mx-1 min-h-[32px]",children:[e.map(h=>i.jsxs("span",{className:"inline-flex items-center gap-1 text-[10px] bg-surface-elevated text-fg-secondary rounded-full px-2 py-0.5 border border-border-default",children:[h,i.jsx("button",{onClick:()=>t(e.filter(g=>g!==h)),className:"text-fg-muted hover:text-red-500",children:"×"})]},h)),i.jsx("input",{ref:m,value:c,onChange:h=>d(h.target.value),onKeyDown:p,onBlur:()=>{c||l(!1)},className:"flex-1 min-w-[80px] bg-transparent text-xs text-fg-primary placeholder:text-fg-muted focus:outline-none",placeholder:a("detail.typeTagAndEnter")})]}):i.jsx("div",{onClick:()=>l(!0),className:"flex flex-wrap items-center gap-1.5 cursor-text hover:ring-1 hover:ring-border-default rounded px-1 -mx-1 py-0.5 transition-all min-h-[24px]",children:e.length>0?e.map(h=>i.jsx("span",{className:"text-[10px] px-2 py-0.5 bg-surface-elevated text-fg-muted rounded-full border border-border-default",children:h},h)):i.jsx("span",{className:"text-[10px] text-fg-muted italic",children:a("detail.typeTagAndEnter")})})}function kg({content:e}){const t=[D5,I3,O3],n=[SS,[G3,{strict:"ignore"}],[cS,{detect:!0,ignoreMissing:!0}]],a=OS({}),s=k.useMemo(()=>{let l=ui(e,mS);return l=ui(l,hS),l},[e]);return i.jsx("div",{className:`prose prose-invert prose-sm max-w-none
870
870
  prose-headings:text-fg-primary prose-headings:font-semibold
871
871
  prose-p:text-fg-secondary prose-p:leading-relaxed
872
872
  prose-a:text-brand-400 prose-a:no-underline hover:prose-a:underline
@@ -879,4 +879,4 @@ await import("${new URL("/assets/pdf.worker.min-CHFwMXne.mjs",import.meta.url).t
879
879
 
880
880
  ${m("share.rejectedEncourage")}`})},className:"text-xs px-2 py-1.5 rounded-lg border border-red-500/30 text-red-400 hover:bg-red-500/10 transition-colors inline-flex items-center gap-1 cursor-pointer",title:m("share.rejectedTip"),children:[i.jsxs("svg",{className:"w-3 h-3",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[i.jsx("circle",{cx:"12",cy:"12",r:"10"}),i.jsx("line",{x1:"15",y1:"9",x2:"9",y2:"15"}),i.jsx("line",{x1:"9",y1:"9",x2:"15",y2:"15"})]}),m("share.rejected")]}),i.jsxs("button",{onClick:()=>{we({visibility:M.visibility})},disabled:G,className:"text-xs px-3 py-1.5 rounded-lg border border-brand-500/40 text-brand-400 hover:bg-brand-500/10 hover:border-brand-500/60 transition-colors disabled:opacity-50 inline-flex items-center gap-1",children:[i.jsxs("svg",{className:"w-3 h-3",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[i.jsx("polyline",{points:"23 4 23 10 17 10"}),i.jsx("polyline",{points:"1 20 1 14 7 14"}),i.jsx("path",{d:"M3.51 9a9 9 0 0 1 14.85-3.36L23 10M1 14l4.64 4.36A9 9 0 0 0 20.49 15"})]}),m(G?"share.updating":"share.resubmit")]})]}),!M.moderationStatus&&M.pendingReview&&i.jsxs("span",{className:"text-xs px-2 py-1.5 rounded-lg border border-amber-500/30 text-amber-400 inline-flex items-center gap-1",title:m("share.updateUnderReviewTip"),children:[i.jsxs("svg",{className:"w-3 h-3",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[i.jsx("circle",{cx:"12",cy:"12",r:"10"}),i.jsx("polyline",{points:"12 6 12 12 16 14"})]}),m("share.updateUnderReview")]}),Z&&i.jsxs("a",{href:Z,target:"_blank",rel:"noopener noreferrer",onClick:Ie=>{Go()&&(Ie.preventDefault(),fi(Z))},className:`text-xs px-3 py-1.5 rounded-lg border transition-colors inline-flex items-center gap-1.5 ${M.visibility==="org"?"border-blue-500/30 text-blue-500 hover:text-blue-400 hover:border-blue-400/50":M.visibility==="unlisted"?"border-gray-500/30 text-fg-tertiary hover:text-fg-secondary hover:border-gray-400/50":"border-green-600/30 text-green-600 hover:text-green-500 hover:border-green-500/50"}`,children:[M.visibility==="org"?i.jsxs("svg",{className:"w-3 h-3",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[i.jsx("path",{d:"M3 21h18"}),i.jsx("path",{d:"M9 8h1"}),i.jsx("path",{d:"M9 12h1"}),i.jsx("path",{d:"M9 16h1"}),i.jsx("path",{d:"M14 8h1"}),i.jsx("path",{d:"M14 12h1"}),i.jsx("path",{d:"M14 16h1"}),i.jsx("path",{d:"M5 21V5a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2v16"})]}):M.visibility==="unlisted"?i.jsxs("svg",{className:"w-3 h-3",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[i.jsx("path",{d:"M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"}),i.jsx("path",{d:"M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"})]}):i.jsxs("svg",{className:"w-3 h-3",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[i.jsx("path",{d:"M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"}),i.jsx("polyline",{points:"15 3 21 3 21 9"}),i.jsx("line",{x1:"10",y1:"14",x2:"21",y2:"3"})]}),M.visibility==="org"?m("visibility.sharedOrg"):M.visibility==="unlisted"?m("visibility.sharedUnlisted"):m("share.viewOnHub")]}),Be&&i.jsx("button",{onClick:()=>{we({visibility:M.visibility})},disabled:G,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:G?m("share.updating"):m("share.updateVersion",{version:ue})})]})})(),!s&&!M.shared&&i.jsx("button",{onClick:()=>J(!0),disabled:G,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:m(G?"share.sharing":"share.toHub")})]})]}),!s&&$&&!K&&i.jsxs("div",{className:"mb-4 px-4 py-2.5 rounded-lg bg-amber-50 dark:bg-amber-500/10 border border-amber-300 dark:border-amber-500/20 flex items-center justify-between",children:[i.jsx("span",{className:"text-xs text-amber-800 dark:text-amber-300",children:m("versionBump.contentModified")}),i.jsx("button",{onClick:()=>ee(!0),className:"text-xs px-3 py-1 rounded bg-amber-200 dark:bg-amber-500/20 text-amber-800 dark:text-amber-300 hover:bg-amber-300 dark:hover:bg-amber-500/30 transition-colors",children:m("versionBump.bumpVersion")})]}),!s&&K&&i.jsxs("div",{className:"mb-4 px-4 py-3 rounded-lg bg-amber-50 dark:bg-amber-500/10 border border-amber-300 dark:border-amber-500/20",children:[i.jsxs("div",{className:"flex items-center gap-3",children:[i.jsx("span",{className:"text-xs text-amber-800 dark:text-amber-300",children:m("versionBump.newVersion")}),i.jsx("input",{type:"text",defaultValue:(()=>{const X=(ut||"1.0.0").split(".");return X[2]=String(Number(X[2]??0)+1),X.join(".")})(),className:"text-xs px-2 py-1 rounded bg-surface-elevated border border-border-default text-fg-primary w-24 font-mono",onKeyDown:X=>{X.key==="Enter"&&et("version",X.target.value)}}),i.jsx("button",{onClick:X=>{const Z=X.target.parentElement?.querySelector("input");Z&&et("version",Z.value)},className:"text-xs px-3 py-1 rounded bg-amber-200 dark:bg-amber-500/20 text-amber-800 dark:text-amber-300 hover:bg-amber-300 dark:hover:bg-amber-500/30 transition-colors",children:m("common:confirm")}),i.jsx("button",{onClick:()=>ee(!1),className:"text-xs text-fg-tertiary hover:text-fg-secondary",children:m("common:cancel")})]}),M.shared&&i.jsx("p",{className:"text-[10px] text-fg-tertiary mt-2",children:"After bumping the version, you can share the new version to Hub."})]}),i.jsxs("div",{className:`flex gap-8 ${p?"flex-col":""}`,children:[i.jsxs("div",{className:`${p?"w-full":"flex-1 min-w-0"}`,children:[i.jsxs("div",{className:"flex items-start gap-4 mb-6",children:[i.jsxs("div",{className:"relative",children:[i.jsx("div",{onClick:()=>!s&&Ce(!me),className:`w-16 h-16 rounded-xl ${se.bg} flex items-center justify-center text-3xl shrink-0 ${s?"":"cursor-pointer hover:ring-2"} ${se.ring} transition-all overflow-hidden`,children:rt&&rt.startsWith("images/")?i.jsx("img",{src:`/api/builder/artifacts/${e}s/${encodeURIComponent(x)}/images/${encodeURIComponent(rt.replace("images/",""))}?v=${fe}`,alt:"",className:"w-full h-full object-cover"}):rt&&(rt.startsWith("http")||rt.startsWith("/"))?i.jsx("img",{src:rt,alt:"",className:"w-full h-full object-cover"}):(()=>{const X=rt||"";if(X&&[...X].length<=2&&new RegExp("\\p{Emoji}","u").test(X))return X;const ue=Bs[il(e)].accent;return i.jsx("svg",{width:"36",height:"36",viewBox:"0 0 24 24",fill:"none","aria-hidden":!0,children:i.jsx("path",{d:n6(je||t||e),fill:ue})})})()}),!s&&me&&i.jsxs(i.Fragment,{children:[i.jsx("div",{className:"fixed inset-0 z-40",onClick:()=>Ce(!1)}),i.jsxs("div",{className:"absolute top-full left-0 mt-2 z-50 bg-surface-secondary border border-border-default rounded-xl p-3 shadow-xl w-80",children:[i.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[i.jsx("input",{type:"text",placeholder:m("detail.pasteEmojiOrUrl"),className:"flex-1 text-sm px-2 py-1.5 rounded-lg bg-surface-elevated border border-border-default text-fg-primary placeholder:text-fg-muted",defaultValue:rt,onKeyDown:X=>{X.key==="Enter"&&(et("icon",X.target.value),Ce(!1))}}),i.jsxs("label",{className:"text-[10px] text-brand-400 hover:text-brand-300 cursor-pointer px-1.5 py-1 border border-brand-500/30 rounded-lg",children:[m("detail.upload"),i.jsx("input",{type:"file",accept:"image/*",className:"hidden",onChange:async X=>{const Z=X.target.files?.[0];if(!Z)return;const ue=new FormData;ue.append("image",Z);try{const Be=await fetch(`/api/builder/artifacts/${e}s/${encodeURIComponent(x)}/images`,{method:"POST",body:ue,credentials:"include"});if(Be.ok){const Ge=(await Be.json()).path;if($e(Ge),Ce(!1),C){const kt={...C,icon:Ge};S(kt),await Ae.builder.artifacts.save(e,kt)}Y(!0)}}catch{}}})]}),rt&&i.jsx("button",{onClick:()=>{et("icon",""),Ce(!1)},className:"text-[10px] text-fg-tertiary hover:text-red-400 px-1",children:"✕"})]}),i.jsx("div",{className:"max-h-64 overflow-y-auto",children:_re.map(X=>i.jsxs("div",{className:"mb-2.5",children:[i.jsx("div",{className:"text-[10px] text-fg-tertiary mb-1 sticky top-0 bg-surface-secondary py-0.5",children:X.label}),i.jsx("div",{className:"flex flex-wrap gap-0.5",children:X.emojis.map(Z=>i.jsx("button",{onClick:()=>{et("icon",Z),Ce(!1)},className:`w-7 h-7 rounded flex items-center justify-center text-base hover:bg-surface-elevated transition-colors ${rt===Z?"ring-1.5 ring-brand-500 bg-brand-500/10":""}`,children:Z},Z))})]},X.label))})]})]})]}),i.jsxs("div",{className:"flex-1 min-w-0",children:[i.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[i.jsx(gh,{value:je,onChange:X=>et("displayName",X),renderAs:"h1",className:"text-xl font-bold text-fg-primary",placeholder:m("detail.untitled"),readOnly:s}),i.jsx("span",{className:`text-[10px] font-medium uppercase tracking-wider px-2 py-0.5 rounded-full ${se.bg} ${se.color}`,children:se.label}),i.jsx(gh,{value:ut,onChange:X=>et("version",X),renderAs:"badge",className:"text-[10px] px-2 py-0.5 rounded-full bg-surface-elevated text-fg-tertiary border border-border-default font-mono",placeholder:"1.0.0",readOnly:s})]}),i.jsx(gh,{value:qe,onChange:X=>et("description",X),renderAs:"p",className:"text-sm text-fg-secondary mt-1.5 leading-relaxed",placeholder:m("detail.addDescription"),multiline:!0,readOnly:s}),i.jsxs("div",{className:"flex items-center gap-2 mt-2 flex-wrap",children:[i.jsx(Dre,{value:Nt,options:Mre,onChange:X=>et("category",X),className:"text-xs px-2 py-0.5 rounded bg-surface-elevated text-fg-tertiary",readOnly:s}),i.jsx(Lre,{tags:Zt,onChange:X=>et("tags",X),readOnly:s})]})]})]}),i.jsx("div",{className:"mb-8",children:i.jsx(Ore,{images:q,artifactType:e,artifactName:t,onUpload:Me,onRemove:Ne,readOnly:s,cacheBust:fe})}),d&&i.jsx("div",{className:"mb-8",children:d}),e==="team"&&C.team&&i.jsx("div",{className:"mb-8",children:i.jsx(Pre,{members:C.team.members,teamTopFiles:De,files:w,artifactName:x,onFileSave:nt,readOnly:s})}),e==="agent"&&Se.length>0&&i.jsxs("div",{className:"mb-8",children:[i.jsx("h2",{className:"text-sm font-semibold text-fg-primary mb-4 uppercase tracking-wider",children:"About This Agent"}),i.jsx(Lm,{noHeader:!0,files:Se,onSave:nt,readOnly:s})]}),e==="skill"&&i.jsxs("div",{className:"mb-8",children:[C.skill?.requiredPermissions&&C.skill.requiredPermissions.length>0&&i.jsxs("div",{className:"mb-6",children:[i.jsx("h2",{className:"text-sm font-semibold text-fg-primary mb-3 uppercase tracking-wider",children:m("sidebar.permissions")}),i.jsx("div",{className:"flex flex-wrap gap-2",children:C.skill.requiredPermissions.map(X=>{const Z=Rre[X];return i.jsxs("span",{className:`inline-flex items-center gap-1.5 text-xs px-3 py-1.5 rounded-lg border font-medium ${Z?.color??"bg-surface-elevated text-fg-secondary border-border-default"}`,children:[i.jsx("span",{className:"font-mono text-[10px]",children:Z?.icon??"?"})," ",X]},X)})})]}),C.skill?.mcpServers&&Object.keys(C.skill.mcpServers).length>0&&i.jsxs("div",{className:"mb-6",children:[i.jsx("h2",{className:"text-sm font-semibold text-fg-primary mb-3 uppercase tracking-wider",children:"Integrations"}),i.jsx("div",{className:"grid gap-2",children:Object.entries(C.skill.mcpServers).map(([X,Z])=>i.jsxs("div",{className:"rounded-lg border border-border-default bg-surface-secondary/40 px-4 py-3 flex items-center gap-3",children:[i.jsx("span",{className:"w-8 h-8 rounded-lg bg-purple-500/15 flex items-center justify-center text-purple-400 text-sm shrink-0",children:"◎"}),i.jsxs("div",{children:[i.jsx("div",{className:"text-xs font-medium text-fg-primary",children:X}),i.jsx("div",{className:"text-[10px] text-fg-muted font-mono truncate",children:typeof Z=="object"?JSON.stringify(Z).slice(0,80):String(Z)})]})]},X))})]}),ae&&i.jsxs("div",{children:[i.jsx("h2",{className:"text-sm font-semibold text-fg-primary mb-3 uppercase tracking-wider",children:"Instructions"}),i.jsx("div",{className:"rounded-xl border border-border-default bg-surface-secondary/40 p-5",children:i.jsx(kg,{content:ae})})]})]}),Pe.length>0&&i.jsx(Lm,{files:Pe,onSave:nt,readOnly:s})]}),i.jsx("div",{className:`${p?"w-full":"w-72 shrink-0"}`,children:i.jsxs("div",{className:`${p?"":"sticky top-6"} space-y-4`,children:[i.jsxs("div",{className:"rounded-xl border border-border-default bg-surface-secondary/60 p-4 space-y-3",children:[i.jsx("div",{className:"text-xs font-medium text-fg-tertiary uppercase tracking-wider",children:m("sidebar.info")}),i.jsxs("div",{className:"space-y-2 text-xs",children:[i.jsxs("div",{className:"flex justify-between",children:[i.jsx("span",{className:"text-fg-muted",children:m("sidebar.type")}),i.jsx("span",{className:`font-medium ${se.color}`,children:se.label})]}),i.jsxs("div",{className:"flex justify-between",children:[i.jsx("span",{className:"text-fg-muted",children:m("sidebar.category")}),i.jsx("span",{className:"text-fg-secondary",children:Nt})]}),i.jsxs("div",{className:"flex justify-between",children:[i.jsx("span",{className:"text-fg-muted",children:m("sidebar.version")}),i.jsx("span",{className:"text-fg-secondary font-mono",children:ut})]}),C.author&&i.jsxs("div",{className:"flex justify-between",children:[i.jsx("span",{className:"text-fg-muted",children:m("sidebar.author")}),i.jsx("span",{className:"text-fg-secondary",children:typeof C.author=="string"?C.author:C.author?.name??""})]})]})]}),e==="agent"&&C.agent&&i.jsxs("div",{className:"rounded-xl border border-border-default bg-surface-secondary/60 p-4 space-y-3",children:[i.jsx("div",{className:"text-xs font-medium text-fg-tertiary uppercase tracking-wider",children:m("sidebar.agentSpecs")}),i.jsxs("div",{className:"space-y-2 text-xs",children:[C.agent.roleName&&i.jsxs("div",{className:"flex justify-between",children:[i.jsx("span",{className:"text-fg-muted",children:m("sidebar.role")}),i.jsx("span",{className:"text-fg-secondary",children:C.agent.roleName})]}),C.agent.llmProvider&&i.jsxs("div",{className:"flex justify-between",children:[i.jsx("span",{className:"text-fg-muted",children:m("sidebar.provider")}),i.jsx("span",{className:"text-fg-secondary",children:C.agent.llmProvider})]}),C.agent.llmModel&&i.jsxs("div",{className:"flex justify-between",children:[i.jsx("span",{className:"text-fg-muted",children:m("sidebar.model")}),i.jsx("span",{className:"text-fg-secondary font-mono",children:C.agent.llmModel})]}),C.agent.temperature!==void 0&&i.jsxs("div",{className:"flex justify-between",children:[i.jsx("span",{className:"text-fg-muted",children:m("sidebar.temperature")}),i.jsx("span",{className:"text-fg-secondary",children:C.agent.temperature})]})]})]}),e==="team"&&C.team&&i.jsxs("div",{className:"rounded-xl border border-border-default bg-surface-secondary/60 p-4 space-y-3",children:[i.jsx("div",{className:"text-xs font-medium text-fg-tertiary uppercase tracking-wider",children:m("sidebar.composition")}),i.jsxs("div",{className:"space-y-2 text-xs",children:[i.jsxs("div",{className:"flex justify-between",children:[i.jsx("span",{className:"text-fg-muted",children:m("sidebar.totalMembers")}),i.jsx("span",{className:"text-fg-secondary",children:C.team.members.reduce((X,Z)=>X+Z.count,0)})]}),i.jsxs("div",{className:"flex justify-between",children:[i.jsx("span",{className:"text-fg-muted",children:m("sidebar.managers")}),i.jsx("span",{className:"text-amber-400",children:C.team.members.filter(X=>X.role==="manager").reduce((X,Z)=>X+Z.count,0)})]}),i.jsxs("div",{className:"flex justify-between",children:[i.jsx("span",{className:"text-fg-muted",children:m("sidebar.workers")}),i.jsx("span",{className:"text-blue-400",children:C.team.members.filter(X=>X.role!=="manager").reduce((X,Z)=>X+Z.count,0)})]})]})]}),e==="skill"&&C.skill&&i.jsxs("div",{className:"rounded-xl border border-border-default bg-surface-secondary/60 p-4 space-y-3",children:[i.jsx("div",{className:"text-xs font-medium text-fg-tertiary uppercase tracking-wider",children:m("sidebar.skillInfo")}),i.jsxs("div",{className:"space-y-2 text-xs",children:[C.skill.alwaysOn!==void 0&&i.jsxs("div",{className:"flex justify-between",children:[i.jsx("span",{className:"text-fg-muted",children:m("sidebar.alwaysOn")}),i.jsx("span",{className:C.skill.alwaysOn?"text-green-400":"text-fg-secondary",children:C.skill.alwaysOn?m("sidebar.yes"):m("sidebar.no")})]}),i.jsxs("div",{className:"flex justify-between",children:[i.jsx("span",{className:"text-fg-muted",children:m("sidebar.skillFile")}),i.jsx("span",{className:"text-fg-secondary font-mono truncate ml-2",children:C.skill.skillFile})]}),C.skill.requiredPermissions&&C.skill.requiredPermissions.length>0&&i.jsxs("div",{children:[i.jsx("span",{className:"text-fg-muted",children:m("sidebar.permissions")}),i.jsx("div",{className:"flex flex-wrap gap-1 mt-1",children:C.skill.requiredPermissions.map(X=>i.jsx("span",{className:"text-[10px] px-1.5 py-0.5 bg-surface-elevated text-fg-muted rounded border border-border-default",children:X},X))})]})]})]}),C.dependencies&&(C.dependencies.skills?.length||C.dependencies.env?.length)?i.jsxs("div",{className:"rounded-xl border border-border-default bg-surface-secondary/60 p-4 space-y-3",children:[i.jsx("div",{className:"text-xs font-medium text-fg-tertiary uppercase tracking-wider",children:m("sidebar.dependencies")}),C.dependencies.skills?.length?i.jsxs("div",{children:[i.jsx("div",{className:"text-[10px] text-fg-muted mb-1",children:m("sidebar.skills")}),i.jsx("div",{className:"flex flex-wrap gap-1",children:C.dependencies.skills.map(X=>i.jsx("span",{className:"text-[10px] px-2 py-0.5 bg-surface-elevated text-fg-secondary rounded border border-border-default",children:X},X))})]}):null,C.dependencies.env?.length?i.jsxs("div",{children:[i.jsx("div",{className:"text-[10px] text-fg-muted mb-1",children:m("sidebar.environment")}),i.jsx("div",{className:"flex flex-wrap gap-1",children:C.dependencies.env.map(X=>i.jsx("span",{className:"text-[10px] px-2 py-0.5 bg-surface-elevated text-fg-secondary rounded font-mono border border-border-default",children:X},X))})]}):null]}):null,!s&&E&&i.jsxs("button",{onClick:()=>Ae.system.openPath(E).catch(()=>{}),className:"w-full text-left rounded-xl border border-border-default bg-surface-secondary/60 px-4 py-3 text-[10px] text-fg-muted hover:text-fg-secondary hover:border-gray-600 transition-colors truncate",title:E,children:[i.jsx("span",{className:"text-fg-tertiary block mb-0.5",children:m("sidebar.openInFinder")}),E.replace(/.*\.markus\//,"~/.markus/")]})]})})]})]}),!s&&U&&i.jsx(Bre,{onClose:()=>te(!1),onConfirm:(X,Z)=>{te(!1),we({donationsEnabled:!1,priceCents:X==="paid"?Z:void 0})},isUpdate:M.shared}),!s&&I&&i.jsx(zre,{onClose:()=>J(!1),onConfirm:(X,Z,ue,Be)=>{J(!1),we({visibility:X,orgId:Z,priceCents:ue,donationsEnabled:Be})}}),H&&i.jsx(ba,{alertOnly:!0,variant:H.variant??"primary",title:H.title,message:H.message,onConfirm:()=>V(null),onCancel:()=>V(null)})]}):i.jsx("div",{className:"flex-1 overflow-y-auto",children:i.jsxs("div",{className:"px-6 py-8",children:[i.jsxs("button",{onClick:n,className:"text-xs text-brand-400 hover:text-brand-300 mb-4 inline-flex items-center gap-1",children:[i.jsx("svg",{className:"w-3.5 h-3.5",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:i.jsx("polyline",{points:"15 18 9 12 15 6"})}),m("detail.backToBuilder")]}),i.jsx("div",{className:"text-fg-tertiary text-sm py-20 text-center",children:m("detail.notFound")})]})})}function zre({onClose:e,onConfirm:t}){const{t:n}=ot(["builder","common"]),[a,s]=k.useState("public"),[l,c]=k.useState([]),[d,m]=k.useState(""),[p,h]=k.useState(!1),[g,x]=k.useState(0),[y,w]=k.useState(!1);k.useEffect(()=>{a==="org"&&l.length===0&&(h(!0),st.myOrgs().then(S=>{c(S.memberships),S.memberships.length>0&&m(S.memberships[0].id)}).catch(()=>{}).finally(()=>h(!1)))},[a,l.length]);const T=a==="public"||a==="unlisted",C=[{value:"public",icon:i.jsxs("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[i.jsx("circle",{cx:"12",cy:"12",r:"10"}),i.jsx("line",{x1:"2",y1:"12",x2:"22",y2:"12"}),i.jsx("path",{d:"M12 2a15.3 15.3 0 0 1 4 10 15.3 15.3 0 0 1-4 10 15.3 15.3 0 0 1-4-10 15.3 15.3 0 0 1 4-10z"})]}),label:n("visibility.public"),desc:n("visibility.publicDesc")},{value:"org",icon:i.jsxs("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[i.jsx("path",{d:"M3 21h18"}),i.jsx("path",{d:"M9 8h1"}),i.jsx("path",{d:"M9 12h1"}),i.jsx("path",{d:"M9 16h1"}),i.jsx("path",{d:"M14 8h1"}),i.jsx("path",{d:"M14 12h1"}),i.jsx("path",{d:"M14 16h1"}),i.jsx("path",{d:"M5 21V5a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2v16"})]}),label:n("visibility.org"),desc:n("visibility.orgDesc")},{value:"unlisted",icon:i.jsxs("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[i.jsx("path",{d:"M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"}),i.jsx("path",{d:"M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"})]}),label:n("visibility.unlisted"),desc:n("visibility.unlistedDesc")}];return i.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm",onClick:e,children:i.jsxs("div",{className:"bg-surface-secondary border border-border-default rounded-xl max-w-sm w-full mx-4 p-6 shadow-2xl",onClick:S=>S.stopPropagation(),children:[i.jsx("h3",{className:"text-base font-semibold text-fg-primary mb-1",children:n("visibility.label")}),i.jsx("p",{className:"text-[11px] text-fg-tertiary mb-4 leading-relaxed",children:n("visibility.subtitle")}),i.jsxs("div",{className:"text-[10px] uppercase tracking-wider text-fg-tertiary font-semibold mb-2",children:["1 · ",n("visibility.public")," / ",n("visibility.org")]}),i.jsx("div",{className:"space-y-2 mb-5",children:C.map(S=>i.jsxs("label",{className:`flex items-center gap-3 p-3 rounded-lg border cursor-pointer transition-colors ${a===S.value?"border-brand-500 bg-brand-500/10":"border-border-default hover:border-gray-600"}`,children:[i.jsx("input",{type:"radio",name:"visibility",checked:a===S.value,onChange:()=>s(S.value),className:"accent-brand-500"}),i.jsx("div",{className:"flex items-center gap-2 text-fg-secondary",children:S.icon}),i.jsxs("div",{children:[i.jsx("div",{className:"text-sm font-medium text-fg-primary",children:S.label}),i.jsx("div",{className:"text-[11px] text-fg-tertiary",children:S.desc})]})]},S.value))}),a==="org"&&i.jsxs("div",{className:"mb-5",children:[i.jsx("label",{className:"text-xs text-fg-secondary block mb-1.5",children:n("visibility.orgSelect")}),p?i.jsx("div",{className:"text-xs text-fg-tertiary py-2",children:"Loading..."}):l.length===0?i.jsx("div",{className:"text-xs text-fg-tertiary py-2",children:n("visibility.orgNone")}):i.jsx("select",{value:d,onChange:S=>m(S.target.value),className:"w-full text-sm px-3 py-2 rounded-lg bg-surface-elevated border border-border-default text-fg-primary",children:l.map(S=>i.jsx("option",{value:S.id,children:S.name},S.id))})]}),T&&i.jsxs("div",{className:"mb-5",children:[i.jsxs("div",{className:"text-[10px] uppercase tracking-wider text-fg-tertiary font-semibold mb-2",children:["2 · ",n("pricing.label")]}),i.jsx("label",{className:"text-xs text-fg-secondary block mb-1.5",children:n("pricing.label")}),i.jsx("div",{className:"grid grid-cols-4 gap-2 mb-3",children:r6.map(S=>i.jsx("button",{type:"button",onClick:()=>x(S.cents),className:`text-sm px-2 py-2 rounded-lg border transition-colors ${g===S.cents?"border-brand-500 bg-brand-500/10 text-fg-primary":"border-border-default text-fg-secondary hover:border-gray-600"}`,children:S.label},S.cents))}),i.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[i.jsx("input",{type:"checkbox",checked:y,onChange:S=>w(S.target.checked),className:"accent-brand-500"}),i.jsx("span",{className:"text-xs text-fg-secondary",children:n("pricing.enableTips")})]})]}),T&&i.jsx("div",{className:"mb-4 text-[11px] text-fg-tertiary rounded-lg border border-border-default px-3 py-2",children:n("pricing.reviewNote")}),i.jsxs("div",{className:"flex gap-3",children:[i.jsx("button",{onClick:e,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:n("common:cancel")}),i.jsx("button",{onClick:()=>t(a,a==="org"?d:void 0,T&&g>0?g:void 0,T?y:void 0),disabled:a==="org"&&!d,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:n("shareMode.share")})]})]})})}const r6=[{cents:0,label:"Free"},{cents:100,label:"$1"},{cents:500,label:"$5"},{cents:1e3,label:"$10"}];function Bre({onClose:e,onConfirm:t,isUpdate:n}){const{t:a}=ot(["builder","common"]),[s,l]=k.useState(0);return i.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm",onClick:e,children:i.jsxs("div",{className:"bg-surface-secondary border border-border-default rounded-xl max-w-sm w-full mx-4 p-6 shadow-2xl",onClick:c=>c.stopPropagation(),children:[i.jsx("h3",{className:"text-base font-semibold text-fg-primary mb-4",children:a(n?"shareMode.titleUpdate":"share.toHub")}),i.jsx("div",{className:"space-y-2 mb-5",children:r6.map(c=>i.jsxs("label",{className:`flex items-center gap-3 p-3 rounded-lg border cursor-pointer transition-colors ${s===c.cents?"border-brand-500 bg-brand-500/10":"border-border-default hover:border-gray-600"}`,children:[i.jsx("input",{type:"radio",name:"sharePrice",checked:s===c.cents,onChange:()=>l(c.cents),className:"accent-brand-500"}),i.jsxs("div",{children:[i.jsx("div",{className:"text-sm font-medium text-fg-primary",children:c.label}),i.jsx("div",{className:"text-[11px] text-fg-tertiary",children:c.cents===0?a("shareMode.freeDesc"):a("shareMode.paidDesc")})]})]},c.cents))}),i.jsxs("div",{className:"flex gap-3",children:[i.jsx("button",{onClick:e,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:a("common:cancel")}),i.jsx("button",{onClick:()=>t(s>0?"paid":"free",s),className:"flex-1 text-sm px-4 py-2 rounded-lg bg-brand-600 hover:bg-brand-500 text-white transition-colors",children:a(n?"shareMode.update":"shareMode.share")})]})]})})}function Im(e,t){return!e||!a6(e)?null:e.startsWith("http")||e.startsWith("data:")?e:e.startsWith("/")&&t?`${t}${e}`:e}function Hre({type:e,seed:t,icon:n,hubBase:a,size:s=44,className:l="",rounded:c="rounded-xl"}){const d=il(e),m=Im(n,a),p=k.useMemo(()=>xb(d,t),[d,t]),h=k.useMemo(()=>n6(t),[t]),[g,x]=k.useState(!1);return m&&!g?i.jsx("img",{src:m,alt:"",onError:()=>x(!0),style:{width:s,height:s},className:`${c} object-cover shrink-0 ${l}`}):Ere(n)?i.jsx("div",{style:{width:s,height:s,background:p,fontSize:s*.5},className:`${c} shrink-0 flex items-center justify-center shadow-inner ${l}`,children:i.jsx("span",{className:"drop-shadow-sm",children:n})}):n&&yae(n)?i.jsx("div",{style:{width:s,height:s,background:p},className:`${c} shrink-0 flex items-center justify-center text-white shadow-inner ${l}`,children:i.jsx(rl,{name:n,size:s*.52,className:"drop-shadow-sm"})}):i.jsx("div",{style:{width:s,height:s,background:p},className:`${c} shrink-0 flex items-center justify-center shadow-inner ${l}`,children:i.jsx("svg",{width:s*.55,height:s*.55,viewBox:"0 0 24 24",fill:"none","aria-hidden":!0,children:i.jsx("path",{d:h,fill:"rgba(255,255,255,0.92)"})})})}function Om({name:e,username:t,avatarUrl:n,hubBase:a,size:s=24,className:l="",verified:c}){const d=t||e||"markus",m=Im(n,a),[p,h]=k.useState(!1),g=m&&!p?m:jre(d);return i.jsxs("span",{className:`relative inline-flex shrink-0 ${l}`,style:{width:s,height:s},children:[i.jsx("img",{src:g,alt:e||t||"",onError:()=>h(!0),className:"w-full h-full rounded-full object-cover ring-1 ring-white/10 bg-surface-elevated"}),c&&i.jsx("span",{className:"absolute -right-0.5 -bottom-0.5 flex items-center justify-center rounded-full bg-brand-500 ring-2 ring-surface-primary",style:{width:s*.42,height:s*.42},children:i.jsx("svg",{viewBox:"0 0 24 24",width:"60%",height:"60%",fill:"white","aria-hidden":!0,children:i.jsx("path",{d:"M9 16.2l-3.5-3.5 1.4-1.4L9 13.4l7.1-7.1 1.4 1.4z"})})})]})}function $re({type:e,className:t=""}){const n=il(e),a=Bs[n];return i.jsx("span",{className:`inline-flex items-center gap-1 rounded-full px-2 py-0.5 text-[10px] font-semibold tracking-wide text-white bg-gradient-to-r ${a.gradient} ${t}`,children:a.label})}function yk({rating:e=0}){const t=Math.round(e);return i.jsx("span",{className:"inline-flex items-center","aria-label":`${e} out of 5`,children:[0,1,2,3,4].map(n=>i.jsx("svg",{viewBox:"0 0 24 24",width:"12",height:"12",className:n<t?"text-amber-400":"text-fg-muted/40",fill:"currentColor","aria-hidden":!0,children:i.jsx("path",{d:"M12 2l2.4 6.9L21 9l-5.4 4 2 7-5.6-4.1L6.4 20l2-7L3 9l6.6-.1z"})},n))})}function vr(e){const{type:t,name:n,description:a,seed:s,icon:l,cover:c,hubBase:d,author:m,authorLabel:p,version:h,category:g,tags:x,rating:y=0,ratingCount:w=0,downloadCount:T=0,priceCents:C,currency:S="usd",installed:E,glowing:_,selected:L,showTypeBadge:D=!0,hideStats:M=!1,cornerLabel:O,actions:G,footerLeft:Q,headerAction:$,onClick:Y,className:K=""}=e,ee=il(t),U=Bs[ee],te=s||n,I=(C??0)>0,J=!!Im(c||void 0,d),me=xb(ee,te),Ce=p??m?.displayName??m?.username??"",[H,V]=k.useState(null),fe=E?i.jsx("span",{className:"inline-flex items-center gap-1 rounded-full bg-emerald-500/12 text-emerald-400 border border-emerald-500/25 px-2 py-0.5 text-[10px] font-semibold",children:i.jsx("svg",{className:"w-2.5 h-2.5",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"3.5",children:i.jsx("polyline",{points:"20 6 9 17 4 12"})})}):O?i.jsx("span",{className:"chip",children:O}):I?i.jsx("span",{className:"badge-paid",children:hk(C,S)}):null;if(J){const z=Im(c||void 0,d);return i.jsxs("div",{onClick:Y,style:{aspectRatio:H??void 0},className:`group asset-card card-shine relative flex flex-col overflow-hidden min-h-[180px] ${Y?"cursor-pointer":""} ${L?"ring-1 ring-brand-500/60":""} ${_?"ring-2 ring-brand-500 shadow-lg shadow-brand-500/20":""} ${K}`,children:[i.jsx("img",{src:z,alt:"",onLoad:je=>{const Ue=je.currentTarget;Ue.naturalWidth&&Ue.naturalHeight&&V(Math.min(1.9,Math.max(1,Ue.naturalWidth/Ue.naturalHeight)))},className:"absolute inset-0 w-full h-full object-cover transition-transform duration-[600ms] group-hover:scale-[1.05]"}),i.jsx("div",{className:"absolute inset-0 bg-gradient-to-t from-black/90 via-black/50 to-black/5"}),i.jsx("div",{className:"absolute inset-x-0 top-0 h-20 bg-gradient-to-b from-black/50 to-transparent"}),i.jsxs("div",{className:"relative flex items-start justify-between gap-2 p-3",children:[i.jsx("span",{children:D&&i.jsx($re,{type:ee})}),i.jsxs("span",{className:"flex items-center gap-1.5",onClick:je=>je.stopPropagation(),children:[E?i.jsx("span",{className:"inline-flex items-center gap-1 rounded-full bg-emerald-500/25 text-emerald-50 border border-emerald-300/40 px-2 py-0.5 text-[10px] font-semibold backdrop-blur-md",children:i.jsx("svg",{className:"w-3 h-3",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"3",children:i.jsx("polyline",{points:"20 6 9 17 4 12"})})}):O?i.jsx("span",{className:"inline-flex items-center rounded-full bg-white/15 text-white border border-white/25 px-2 py-0.5 text-[10px] font-medium backdrop-blur-md",children:O}):$?null:i.jsx("span",{className:I?"badge-paid":"badge-free",children:hk(C,S)}),$]})]}),i.jsxs("div",{className:"relative mt-auto p-4 pt-10 flex flex-col gap-2 text-white",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("h3",{className:"text-[15px] font-semibold truncate drop-shadow-md",children:n}),h&&i.jsxs("span",{className:"shrink-0 rounded-full bg-white/15 border border-white/25 px-1.5 py-0.5 text-[10px] font-medium backdrop-blur-md",children:["v",h]})]}),Ce&&i.jsxs("div",{className:"flex items-center gap-1.5 text-[11px] text-white/85",children:[m&&i.jsx(Om,{name:m.displayName,username:m.username,avatarUrl:m.avatarUrl,hubBase:d,size:15}),i.jsx("span",{className:"truncate",children:Ce})]}),a&&i.jsx("p",{className:"text-[12.5px] text-white/80 truncate leading-snug drop-shadow-sm",children:a}),(g||x&&x.length>0)&&i.jsxs("div",{className:"flex flex-nowrap gap-1.5 overflow-hidden",children:[g&&i.jsx("span",{className:"shrink-0 rounded-full bg-white/15 border border-white/20 text-white/95 px-2 py-0.5 text-[10px] font-semibold capitalize backdrop-blur-md",children:g}),x?.slice(0,3).map(je=>i.jsx("span",{className:"shrink-0 rounded-full bg-white/10 border border-white/15 text-white/85 px-2 py-0.5 text-[10px] backdrop-blur-md",children:je},je))]}),(!M||G)&&i.jsxs("div",{className:"flex items-center justify-between gap-2 pt-1 shrink-0",children:[M?i.jsx("span",{}):i.jsxs("div",{className:"flex items-center gap-3 text-[11px] text-white/80",children:[i.jsxs("span",{className:"inline-flex items-center gap-1",children:[i.jsx(yk,{rating:y}),w>0&&i.jsxs("span",{className:"text-white/60",children:["(",$o(w),")"]})]}),i.jsxs("span",{className:"inline-flex items-center gap-1",children:[i.jsx("svg",{viewBox:"0 0 24 24",width:"12",height:"12",fill:"none",stroke:"currentColor",strokeWidth:"2","aria-hidden":!0,children:i.jsx("path",{d:"M12 3v12m0 0l-4-4m4 4l4-4M5 21h14"})}),$o(T)]})]}),G&&i.jsx("div",{className:"flex items-center gap-2",onClick:je=>je.stopPropagation(),children:G})]})]})]})}return i.jsxs("div",{onClick:Y,className:`group asset-card card-shine relative flex flex-col ${Y?"cursor-pointer":""} ${L?"ring-1 ring-brand-500/60":""} ${_?"ring-2 ring-brand-500 shadow-lg shadow-brand-500/20":""} ${K}`,children:[i.jsx("div",{className:"pointer-events-none absolute inset-x-0 top-0 h-[2px] opacity-0 group-hover:opacity-100 transition-opacity duration-300",style:{background:`linear-gradient(90deg, transparent, ${U.accent}, transparent)`}}),i.jsx("div",{className:"pointer-events-none absolute -top-10 -left-10 w-36 h-36 rounded-full blur-2xl opacity-[0.12] group-hover:opacity-20 transition-opacity duration-300",style:{background:me}}),$&&i.jsx("div",{className:"absolute top-2.5 right-2.5 z-10",onClick:z=>z.stopPropagation(),children:$}),i.jsxs("div",{className:"relative p-4 flex flex-col flex-1 gap-2.5",children:[i.jsxs("div",{className:"flex items-start gap-3",children:[i.jsx(Hre,{type:ee,seed:te,icon:l,hubBase:d,size:46,rounded:"rounded-2xl",className:"ring-1 ring-white/10 shadow-sm shadow-black/20"}),i.jsxs("div",{className:`min-w-0 flex-1 ${$?"pr-7":""}`,children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("h3",{className:"text-sm font-semibold text-fg-primary truncate group-hover:text-brand-300 transition-colors",children:n}),h&&i.jsxs("span",{className:"chip shrink-0",children:["v",h]}),fe&&i.jsx("span",{className:"ml-auto shrink-0",children:fe})]}),(Ce||D)&&i.jsxs("div",{className:"mt-1 flex items-center gap-1.5 text-[11px] text-fg-tertiary min-w-0",children:[m&&i.jsx(Om,{name:m.displayName,username:m.username,avatarUrl:m.avatarUrl,hubBase:d,size:15}),Ce&&i.jsx("span",{className:"truncate",children:Ce}),D&&i.jsxs(i.Fragment,{children:[Ce&&i.jsx("span",{className:"text-fg-muted",children:"·"}),i.jsx("span",{className:"font-semibold shrink-0",style:{color:U.accent},children:U.label})]})]})]})]}),a&&i.jsx("p",{className:"text-[13px] text-fg-secondary truncate leading-snug",children:a}),(g||x&&x.length>0)&&i.jsxs("div",{className:"flex flex-wrap gap-1.5",children:[g&&i.jsx("span",{className:"chip-accent capitalize",children:g}),x?.slice(0,3).map(z=>i.jsx("span",{className:"chip",children:z},z)),(x?.length??0)>3&&i.jsxs("span",{className:"text-[10px] text-fg-muted self-center",children:["+",(x?.length??0)-3]})]}),(()=>{const z=Q??(M?null:i.jsxs("span",{className:"flex items-center gap-3 text-[11px] text-fg-tertiary",children:[i.jsxs("span",{className:"inline-flex items-center gap-1",children:[i.jsx(yk,{rating:y}),i.jsx("span",{className:"text-fg-muted",children:w>0?`(${$o(w)})`:""})]}),i.jsxs("span",{className:"inline-flex items-center gap-1",children:[i.jsx("svg",{viewBox:"0 0 24 24",width:"12",height:"12",fill:"none",stroke:"currentColor",strokeWidth:"2","aria-hidden":!0,children:i.jsx("path",{d:"M12 3v12m0 0l-4-4m4 4l4-4M5 21h14"})}),$o(T)]})]}));return!z&&!G?null:i.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2 pt-2 mt-auto border-t border-border-subtle/60",onClick:je=>je.stopPropagation(),children:[z&&i.jsx("div",{className:"min-w-0 flex items-center gap-2",children:z}),G&&i.jsx("div",{className:"flex flex-wrap items-center gap-2 justify-end",children:G})]})})()]})]})}function Fa({children:e,maxCardWidth:t=400,gap:n="1rem",className:a=""}){const s=k.useRef(null),[l,c]=k.useState(0);k.useEffect(()=>{const h=s.current;if(!h)return;c(h.clientWidth);const g=new ResizeObserver(x=>{for(const y of x)c(y.contentRect.width)});return g.observe(h),()=>g.disconnect()},[]);const d=Math.max(1,Math.ceil((l||t)/t)),m=k.Children.toArray(e),p=Array.from({length:d},()=>[]);return m.forEach((h,g)=>{p[g%d].push(h)}),i.jsx("div",{ref:s,className:`flex items-start ${a}`,style:{gap:n},children:p.map((h,g)=>i.jsx("div",{className:"flex flex-col flex-1 min-w-0",style:{gap:n,maxWidth:t},children:h},g))})}function qre(e){const t=e.indexOf(".markus/builder-artifacts/");return t>=0?"~/"+e.slice(t):e}const Fre=[{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"}];function Ure(){const[e,t]=k.useState(()=>{const a=window.location.hash.slice(1).split("/");return kc(a[0])===de.BUILDER&&a[1]&&a[2]?{type:a[1],name:decodeURIComponent(a[2])}:null});return k.useEffect(()=>{const n=()=>{const s=window.location.hash.slice(1).split("/");kc(s[0])===de.BUILDER&&s[1]&&s[2]?t({type:s[1],name:decodeURIComponent(s[2])}):t(null)};return window.addEventListener("hashchange",n),()=>window.removeEventListener("hashchange",n)},[]),e}const i6="markus_builder_shared_map";function Gre(){try{const e=localStorage.getItem(i6);if(!e)return new Map;const t=JSON.parse(e);return new Map(Object.entries(t))}catch{return new Map}}function qd(e){try{localStorage.setItem(i6,JSON.stringify(Object.fromEntries(e)))}catch{}}function s6({authUser:e}={}){const{t}=ot(["builder","common"]),n=Xo(),a=Ure(),[s,l]=k.useState([]),[c,d]=k.useState([]),[m,p]=k.useState(!1),[h,g]=k.useState("all"),[x,y]=k.useState(null),[w,T]=k.useState(new Map),[C,S]=k.useState(null),[E,_]=k.useState(null),[L,D]=k.useState(null),[M,O]=k.useState(Gre),[G,Q]=k.useState(null),[$,Y]=k.useState(null),[K,ee]=k.useState(null),[U,te]=k.useState(null),[I,J]=k.useState(null),[me,Ce]=k.useState("creations"),[H,V]=k.useState([]),[fe,z]=k.useState(""),[je,Ue]=k.useState([]),[qe,He]=k.useState(!1),[ut,dt]=k.useState("all"),Nt=k.useCallback(()=>{p(!0),Promise.all([(Ls(qa.builderArtifacts)??Ae.builder.artifacts.list()).then(ce=>ce?.artifacts??[]).catch(()=>[]),(Ls(qa.builderAgents)??Ae.agents.list()).then(ce=>ce?.agents??[]).catch(()=>[]),(Ls(qa.builderHubMyItems)??st.myItems()).then(ce=>ce?.items??[]).catch(()=>[]),(Ls(qa.builderInstalled)??Ae.builder.artifacts.installed()).then(ce=>ce?.installed??{}).catch(()=>({}))]).then(([ce,et,nt,we])=>{if(d(ce),l(et),nt.length>0){const Ne=new Map;for(const se of nt){const q=se.itemType==="agent"?"agent":se.itemType==="team"?"team":"skill";for(const ae of ce)ae.type===q&&(se.slug===ae.name||se.name===(ae.meta.displayName||ae.meta.name||ae.name))&&Ne.set(`${ae.type}/${ae.name}`,{id:se.id,name:se.name,slug:se.slug||ae.name,version:se.version||"1.0.0",visibility:se.visibility??"public",moderationStatus:se.moderationStatus,moderationNote:se.moderationNote,pendingReview:se.pendingReview})}Ne.size>0&&O(se=>{const q=new Map(se);for(const[ae,Se]of Ne)q.set(ae,Se);return qd(q),q})}const Me=new Map;for(const Ne of ce){const se=`${Ne.type}/${Ne.name}`,q=we[se];q&&Me.set(se,{agentId:q.agentId,agentIds:q.agentIds,teamId:q.teamId})}T(Me)}).finally(()=>p(!1))},[]);k.useEffect(()=>{Nt();const ce=et=>{et.detail?.page===de.BUILDER&&Nt()};return window.addEventListener("markus:navigate",ce),()=>window.removeEventListener("markus:navigate",ce)},[Nt]);const wt=ce=>{const et=s.find(nt=>nt.role==="Secretary"||nt.name==="Secretary");et?at.navigate(de.TEAM,{agentId:et.id,prefillMessage:ce}):at.navigate(de.TEAM,{prefillMessage:ce})},Zt=async ce=>{const et=`${ce.type}/${ce.name}`;if(!w.has(et)){y({key:et,action:"install"});try{const nt=await Ae.builder.artifacts.install(ce.type,ce.name),we={};nt.agent&&typeof nt.agent=="object"&&(we.agentId=nt.agent.id),nt.team&&typeof nt.team=="object"&&(we.teamId=nt.team.id),Array.isArray(nt.agents)&&(we.agentIds=nt.agents.map(Me=>Me.id)),T(Me=>new Map(Me).set(et,we)),window.dispatchEvent(new CustomEvent("markus:data-changed"))}catch(nt){console.error("Install failed:",nt),Y({title:t("common:install"),message:t("installFailed",{error:String(nt)}),variant:"danger"})}finally{y(null)}}},Wt=async ce=>{const et=`${ce.type}/${ce.name}`;if(w.has(et)){y({key:et,action:"uninstall"});try{await Ae.builder.artifacts.uninstall(ce.type,ce.name),T(nt=>{const we=new Map(nt);return we.delete(et),we}),window.dispatchEvent(new CustomEvent("markus:data-changed"))}catch(nt){console.error("Uninstall failed:",nt),Y({title:t("common:uninstall"),message:t("uninstallFailed",{error:String(nt)}),variant:"danger"})}finally{y(null)}}},rt=async(ce,et)=>{const nt=`${ce.type}/${ce.name}`;y({key:nt,action:"share"});try{const we=await Ae.builder.artifacts.ensureSlugSafe(ce.type,ce.name,ce.meta.displayName||ce.meta.name||ce.name),Me=we.name,Ne=we.slug||Nc(Me);if(!Ne)throw new Error("Invalid package slug: use English kebab-case for the artifact name (e.g. qwen-multimodal). Chinese-only names cannot be shared — rename the package slug and put the Chinese title in displayName.");const se=`${ce.type}/${Me}`;we.converted&&(d(Rt=>Rt.map(Mt=>Mt.type===ce.type&&Mt.name===ce.name?{...Mt,name:Me,path:we.path,meta:{...Mt.meta,name:Me,displayName:we.displayName??Mt.meta.displayName??ce.name}}:Mt)),O(Rt=>{const Mt=new Map(Rt),Ot=Mt.get(nt);return Ot&&(Mt.delete(nt),Mt.set(se,{...Ot,slug:Ne,name:we.displayName??Ot.name})),qd(Mt),Mt}),T(Rt=>{const Mt=new Map(Rt),Ot=Mt.get(nt);return Ot&&(Mt.delete(nt),Mt.set(se,Ot)),Mt}));const q=await Ae.builder.artifacts.get(ce.type,Me);let ae={...ce.meta,name:Me,displayName:we.displayName??ce.meta.displayName??ce.name};try{const Rt=q.files?.[`${ce.type}.json`]??q.files?.["agent.json"]??q.files?.["team.json"]??q.files?.["skill.json"];Rt&&(ae={...JSON.parse(Rt),...ae,name:Me,displayName:ae.displayName})}catch{}const Se=ae.displayName||ae.name||Me,De=ae.description||"",Pe=ae.category||"general",X=Array.isArray(ae.tags)?ae.tags:[];let Z=ae.icon||void 0;const ue=ae.version||"1.0.0";if(Z&&!Z.startsWith("http")&&/\.(png|jpe?g|gif|webp|svg)$/i.test(Z)){const Rt=Z.split("/").pop()??Z;try{const Mt=await fetch(`/api/builder/artifacts/${ce.type}s/${encodeURIComponent(Me)}/images/${encodeURIComponent(Rt)}`);if(Mt.ok){const Ot=await Mt.blob(),Un=new File([Ot],Rt,{type:Ot.type}),hn=await st.uploadImage(Un);hn?.url&&(Z=hn.url)}}catch{}}let Be;const Ie=[],Ge=Array.isArray(ae.screenshots)?ae.screenshots:[];for(let Rt=0;Rt<Ge.length;Rt++){const Mt=Ge[Rt],Ot=Mt.split("/").pop()??Mt;try{const Un=await fetch(`/api/builder/artifacts/${ce.type}s/${encodeURIComponent(Me)}/images/${encodeURIComponent(Ot)}`);if(Un.ok){const hn=await Un.blob(),ie=new File([hn],Ot,{type:hn.type}),Ee=await st.uploadImage(ie);Ee?.url&&(Ie.push({url:Ee.url,alt:Ot,order:Rt}),(Rt===0||ae.thumbnail===Mt)&&(Be=Ee.url))}}catch{}}const kt=await st.publishViaProxy({itemType:ce.type==="team"?"team":ce.type==="skill"?"skill":"agent",name:Se,slug:Ne,description:De,category:Pe,tags:X,icon:Z,version:ue,config:{...ae,name:Me,displayName:Se},files:q.files&&Object.keys(q.files).length>0?q.files:void 0,thumbnailUrl:Be,images:Ie.length>0?Ie:void 0,priceCents:et?.priceCents,donationsEnabled:et?.donationsEnabled,visibility:et?.visibility,orgId:et?.orgId});kt.id&&(O(Mt=>{const Ot=new Map(Mt);return Ot.set(se,{id:kt.id,name:Se,slug:kt.slug??Ne,version:ue,visibility:kt.visibility??et?.visibility??"public",moderationStatus:kt.moderationStatus,pendingReview:kt.pendingReview}),qd(Ot),Ot}),(kt.visibility??et?.visibility??"public")!=="org"?Y({title:t("common:share"),message:we.converted?t("share.convertedAndSubmitted",{previous:ce.name,slug:Ne}):kt.updated?t("share.updateSubmitted"):t("share.submittedForReview"),variant:"primary"}):we.converted&&Y({title:t("common:share"),message:t("share.convertedSlug",{previous:ce.name,slug:Ne}),variant:"primary"}))}catch(we){console.error("Share failed:",we),Y({title:t("common:share"),message:t("shareFailed",{error:we instanceof Error?we.message:String(we)}),variant:"danger"})}finally{y(null)}},$e=async()=>{if(!G)return;const{key:ce}=G,et=M.get(ce);if(Q(null),!et)return;const nt=et.id;y({key:ce,action:"hubDelete"});try{await st.deleteItem(nt),O(we=>{const Me=new Map(we);return Me.delete(ce),qd(Me),Me})}catch(we){console.error("Hub delete failed:",we),Y({title:t("unshare"),message:t("hubDeleteFailed",{error:String(we)}),variant:"danger"})}finally{y(null)}},mt=async()=>{if(!C)return;const ce=C,et=`${ce.type}/${ce.name}`;S(null),y({key:et,action:"delete"});try{await Ae.builder.artifacts.delete(ce.type,ce.name),d(nt=>nt.filter(we=>!(we.type===ce.type&&we.name===ce.name))),T(nt=>{const we=new Map(nt);return we.delete(et),we}),window.dispatchEvent(new CustomEvent("markus:data-changed"))}catch(nt){console.error("Delete failed:",nt)}finally{y(null)}},At=h==="all"?c:c.filter(ce=>ce.type===h);k.useEffect(()=>{me!=="orgAssets"||H.length>0||st.myOrgs().then(ce=>{V(ce.memberships),ce.memberships.length>0&&!fe&&z(ce.memberships[0].id)}).catch(()=>{})},[me,H.length,fe]),k.useEffect(()=>{me!=="orgAssets"||!fe||(He(!0),st.browseItems({orgId:fe,limit:100}).then(ce=>Ue(ce.items??[])).catch(()=>Ue([])).finally(()=>He(!1)))},[me,fe]);const Dt=ut==="all"?je:je.filter(ce=>ce.itemType===ut),ln=ce=>{history.pushState(null,"",Ps(de.BUILDER,`${ce.type}/${encodeURIComponent(ce.name)}`)),window.dispatchEvent(new HashChangeEvent("hashchange"))};return a?i.jsx(qs,{type:a.type,name:a.name,authUser:e,onBack:()=>{history.pushState(null,"",Ps(de.BUILDER)),window.dispatchEvent(new HashChangeEvent("hashchange"))}}):i.jsx("div",{className:"flex-1 overflow-y-auto",children:i.jsxs("div",{className:`max-w-5xl mx-auto w-full ${n?"px-4 py-5":"px-6 py-6"}`,children:[i.jsxs("div",{className:"mb-6",children:[i.jsxs("div",{className:"flex items-center justify-between mb-4",children:[i.jsxs("div",{children:[i.jsx("h1",{className:"text-xl font-bold text-fg-primary",children:t("title")}),i.jsx("p",{className:"text-xs text-fg-tertiary mt-1",children:t("subtitle")})]}),i.jsx("button",{onClick:Nt,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")})]}),i.jsx("div",{className:`grid ${n?"grid-cols-1 gap-2":"grid-cols-3 gap-3"}`,children:Fre.map(ce=>{const et=t(`prompts.${ce.id}Prompt`),nt=t(`prompts.${ce.id}Examples`,{returnObjects:!0}),we=Array.isArray(nt)?nt:[];return i.jsx("button",{onClick:()=>wt(et),className:`group text-left w-full rounded-xl border ${ce.borderColor} bg-surface-secondary/60 p-4 transition-all hover:bg-surface-secondary/80 hover:shadow-lg`,children:i.jsxs("div",{className:"flex items-start gap-3",children:[i.jsx("div",{className:`w-10 h-10 text-xl rounded-lg ${ce.bgColor} flex items-center justify-center shrink-0`,children:ce.icon}),i.jsxs("div",{className:"flex-1 min-w-0",children:[i.jsx("h3",{className:`text-sm font-semibold bg-gradient-to-r ${ce.color} bg-clip-text text-transparent`,children:t(`prompts.${ce.id}`)}),i.jsx("p",{className:"text-[11px] text-fg-tertiary mt-1 leading-relaxed",children:t(`prompts.${ce.id}Desc`)}),we.length>0&&i.jsx("div",{className:"mt-2 flex flex-wrap gap-1.5",children:we.slice(0,2).map((Me,Ne)=>i.jsxs("span",{className:"text-[10px] text-fg-muted bg-surface-elevated/60 rounded-full px-2 py-0.5 border border-border-default",onClick:se=>{se.stopPropagation(),wt(et+Me)},children:["“",Me,"”"]},Ne))})]})]})},ce.id)})})]}),i.jsx("div",{className:"mb-3",children:i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{className:"flex items-center gap-3",children:[i.jsx("button",{onClick:()=>Ce("creations"),className:`text-sm font-semibold transition-colors ${me==="creations"?"text-fg-primary":"text-fg-tertiary hover:text-fg-secondary"}`,children:t("myCreations.title")}),i.jsx("button",{onClick:()=>Ce("orgAssets"),className:`text-sm font-semibold transition-colors ${me==="orgAssets"?"text-fg-primary":"text-fg-tertiary hover:text-fg-secondary"}`,children:t("orgAssets.title")})]}),me==="creations"&&i.jsx("div",{className:"flex gap-1.5",children:["all","agent","team","skill"].map(ce=>i.jsx("button",{onClick:()=>g(ce),className:`text-xs px-2.5 py-1 rounded-lg transition-colors ${h===ce?"bg-brand-600 text-white":"text-fg-tertiary hover:text-fg-secondary hover:bg-surface-elevated"}`,children:t(ce==="all"?"myCreations.filterAll":ce==="agent"?"myCreations.filterAgents":ce==="team"?"myCreations.filterTeams":"myCreations.filterSkills")},ce))}),me==="orgAssets"&&i.jsx("div",{className:"flex gap-1.5",children:["all","agent","team","skill"].map(ce=>i.jsx("button",{onClick:()=>dt(ce),className:`text-xs px-2.5 py-1 rounded-lg transition-colors ${ut===ce?"bg-brand-600 text-white":"text-fg-tertiary hover:text-fg-secondary hover:bg-surface-elevated"}`,children:t(ce==="all"?"myCreations.filterAll":ce==="agent"?"myCreations.filterAgents":ce==="team"?"myCreations.filterTeams":"myCreations.filterSkills")},ce))})]})}),me==="orgAssets"&&H.length>0&&i.jsx("div",{className:"flex gap-2 mb-3 overflow-x-auto pb-1",children:H.map(ce=>i.jsx("button",{onClick:()=>z(ce.id),className:`text-xs px-3 py-1.5 rounded-full whitespace-nowrap border transition-colors ${fe===ce.id?"bg-blue-500/15 border-blue-500/40 text-blue-400":"border-border-default text-fg-tertiary hover:text-fg-secondary hover:border-gray-600"}`,children:ce.name},ce.id))}),me==="orgAssets"&&(H.length===0&&!qe?i.jsx("div",{className:"text-center py-12",children:i.jsx("div",{className:"text-fg-tertiary text-sm",children:t("orgAssets.noOrgs")})}):qe?i.jsx("div",{className:"text-center text-fg-tertiary py-12 text-sm",children:t("orgAssets.loading")}):Dt.length===0?i.jsx("div",{className:"text-center py-12",children:i.jsx("div",{className:"text-fg-tertiary text-sm",children:t("orgAssets.noItems")})}):i.jsx(Fa,{children:Dt.map(ce=>{const et=ce.author?.username&&ce.slug?`${st.getUrl()}/@${encodeURIComponent(ce.author.username)}/${encodeURIComponent(ce.slug)}`:null;return i.jsx(vr,{type:ce.itemType,name:ce.name,description:ce.description,seed:ce.slug||ce.id||ce.name,icon:ce.icon,cover:ce.thumbnailUrl,hubBase:st.getUrl(),author:ce.author,version:ce.version,rating:parseFloat(ce.avgRating)||0,ratingCount:ce.ratingCount,downloadCount:ce.downloadCount,actions:et?i.jsxs("a",{href:et,target:"_blank",rel:"noopener noreferrer",onClick:nt=>{nt.stopPropagation(),Go()&&(nt.preventDefault(),fi(et))},className:"text-xs px-3 py-1.5 rounded-lg border border-border-default text-fg-secondary hover:text-fg-primary hover:border-gray-600 transition-colors inline-flex items-center gap-1",children:[i.jsxs("svg",{className:"w-3 h-3",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[i.jsx("path",{d:"M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"}),i.jsx("polyline",{points:"15 3 21 3 21 9"}),i.jsx("line",{x1:"10",y1:"14",x2:"21",y2:"3"})]}),"Hub"]}):void 0},ce.id)})})),me==="creations"&&(m&&c.length===0?i.jsx("div",{className:"text-center text-fg-tertiary py-12 text-sm",children:t("myCreations.loadingArtifacts")}):At.length===0?i.jsxs("div",{className:"text-center py-12",children:[i.jsx("div",{className:"text-fg-tertiary text-sm",children:t("myCreations.noArtifacts")}),i.jsx("div",{className:"text-fg-muted text-xs mt-1",children:t("myCreations.noArtifactsHint")})]}):i.jsx(Fa,{children:At.map(ce=>{const et=ce.meta.displayName||ce.meta.name||ce.name,nt=ce.meta.description||"",we=`${ce.type}/${ce.name}`,Me=x?.key===we?x.action:null,Ne=M.get(we),se=ce.meta.version||"1.0.0",q=!!Ne,ae=q&&Ne.version!==se,Se=()=>{const Ie=st.getUser();return!Ne||!Ie?null:`${st.getUrl()}/@${encodeURIComponent(Ie.username)}/${encodeURIComponent(Ne.slug)}`},De=q&&Ne?.moderationStatus==="rejected",Pe=i.jsxs("div",{className:"flex items-center gap-1.5 justify-end",onClick:Ie=>Ie.stopPropagation(),children:[w.has(we)?i.jsxs("button",{onClick:()=>D(ce),disabled:!!Me,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 inline-flex items-center gap-1",children:[i.jsxs("svg",{className:"w-3 h-3",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[i.jsx("path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"}),i.jsx("polyline",{points:"17 8 12 3 7 8"}),i.jsx("line",{x1:"12",y1:"3",x2:"12",y2:"15"})]}),t(Me==="uninstall"?"common:uninstalling":"common:uninstall")]}):i.jsxs("button",{onClick:()=>_(ce),disabled:!!Me,className:"text-xs px-3 py-1.5 rounded-lg bg-brand-600 hover:bg-brand-500 text-white transition-colors disabled:opacity-50 inline-flex items-center gap-1",children:[i.jsxs("svg",{className:"w-3 h-3",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[i.jsx("path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"}),i.jsx("polyline",{points:"7 10 12 15 17 10"}),i.jsx("line",{x1:"12",y1:"15",x2:"12",y2:"3"})]}),t(Me==="install"?"common:installing":"common:install")]}),q&&De?i.jsxs(i.Fragment,{children:[i.jsxs("button",{onClick:()=>{Y({title:t("share.rejectedDetailTitle"),variant:"danger",message:`${t("share.rejectedReasonLabel")}${Ne?.moderationNote?Ne.moderationNote:t("share.rejectedNoReason")}
881
881
 
882
- ${t("share.rejectedEncourage")}`})},className:"text-xs px-2 py-1.5 rounded-lg border border-red-500/30 text-red-400 hover:bg-red-500/10 transition-colors inline-flex items-center gap-1 cursor-pointer",title:t("share.rejectedTip"),children:[i.jsxs("svg",{className:"w-3 h-3",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[i.jsx("circle",{cx:"12",cy:"12",r:"10"}),i.jsx("line",{x1:"15",y1:"9",x2:"9",y2:"15"}),i.jsx("line",{x1:"9",y1:"9",x2:"15",y2:"15"})]}),t("share.rejected")]}),i.jsxs("button",{onClick:()=>{rt(ce,{visibility:Ne?.visibility??"public"})},disabled:!!Me,className:"text-xs px-3 py-1.5 rounded-lg border border-brand-500/40 text-brand-400 hover:bg-brand-500/10 hover:border-brand-500/60 transition-colors disabled:opacity-50 inline-flex items-center gap-1",title:t("share.rejectedTip"),children:[i.jsxs("svg",{className:"w-3 h-3",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[i.jsx("polyline",{points:"23 4 23 10 17 10"}),i.jsx("polyline",{points:"1 20 1 14 7 14"}),i.jsx("path",{d:"M3.51 9a9 9 0 0 1 14.85-3.36L23 10M1 14l4.64 4.36A9 9 0 0 0 20.49 15"})]}),t(Me==="share"?"common:sharing":"share.resubmit")]})]}):q?i.jsxs(i.Fragment,{children:[ae&&i.jsxs("button",{onClick:()=>{const Ie=Ne?.visibility??"public";rt(ce,{visibility:Ie})},disabled:!!Me,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 inline-flex items-center gap-1",children:[i.jsxs("svg",{className:"w-3 h-3",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[i.jsx("polyline",{points:"23 4 23 10 17 10"}),i.jsx("polyline",{points:"1 20 1 14 7 14"}),i.jsx("path",{d:"M3.51 9a9 9 0 0 1 14.85-3.36L23 10M1 14l4.64 4.36A9 9 0 0 0 20.49 15"})]}),Me==="share"?t("common:sharing"):t("share.updateVersion",{version:se})]}),i.jsxs("a",{href:Se()??"#",target:"_blank",rel:"noopener noreferrer",onClick:Ie=>{const Ge=Se();Go()&&Ge&&(Ie.preventDefault(),fi(Ge))},className:`text-xs px-3 py-1.5 rounded-lg border transition-colors inline-flex items-center gap-1 ${Ne?.visibility==="org"?"border-blue-500/30 text-blue-500 hover:text-blue-400 hover:border-blue-400/40":Ne?.visibility==="unlisted"?"border-gray-500/30 text-fg-tertiary hover:text-fg-secondary hover:border-gray-400/40":"border-green-600/30 text-green-600 hover:text-green-500 hover:border-green-500/40"}`,children:[Ne?.visibility==="org"?i.jsxs("svg",{className:"w-3 h-3",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[i.jsx("path",{d:"M3 21h18"}),i.jsx("path",{d:"M9 8h1"}),i.jsx("path",{d:"M9 12h1"}),i.jsx("path",{d:"M9 16h1"}),i.jsx("path",{d:"M14 8h1"}),i.jsx("path",{d:"M14 12h1"}),i.jsx("path",{d:"M14 16h1"}),i.jsx("path",{d:"M5 21V5a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2v16"})]}):Ne?.visibility==="unlisted"?i.jsxs("svg",{className:"w-3 h-3",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[i.jsx("path",{d:"M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"}),i.jsx("path",{d:"M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"})]}):i.jsxs("svg",{className:"w-3 h-3",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[i.jsx("path",{d:"M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"}),i.jsx("polyline",{points:"15 3 21 3 21 9"}),i.jsx("line",{x1:"10",y1:"14",x2:"21",y2:"3"})]}),Ne?.visibility==="org"?t("visibility.sharedOrg"):Ne?.visibility==="unlisted"?t("visibility.sharedUnlisted"):t("visibility.shared")]}),i.jsxs("button",{onClick:()=>Q({key:we,name:et}),disabled:!!Me,className:"text-xs px-2.5 py-1.5 rounded-lg border border-border-default text-fg-secondary hover:text-amber-500 hover:border-amber-500/40 hover:bg-amber-500/10 transition-colors disabled:opacity-50 inline-flex items-center gap-1",title:t("removeFromHubTooltip"),children:[i.jsxs("svg",{className:"w-3 h-3",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[i.jsx("path",{d:"M18.84 12.25l1.72-1.71a5 5 0 0 0-7.07-7.07l-1.72 1.71"}),i.jsx("path",{d:"M5.17 11.75l-1.71 1.71a5 5 0 0 0 7.07 7.07l1.71-1.71"}),i.jsx("line",{x1:"2",y1:"2",x2:"22",y2:"22"})]}),t("unshare")]})]}):i.jsxs("button",{onClick:async()=>{await st.ensureAuth(),Array.isArray(ce.meta.screenshots)&&ce.meta.screenshots.length>0?J(ce):ee(ce)},disabled:!!Me,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 inline-flex items-center gap-1",children:[i.jsxs("svg",{className:"w-3 h-3",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[i.jsx("circle",{cx:"18",cy:"5",r:"3"}),i.jsx("circle",{cx:"6",cy:"12",r:"3"}),i.jsx("circle",{cx:"18",cy:"19",r:"3"}),i.jsx("line",{x1:"8.59",y1:"13.51",x2:"15.42",y2:"17.49"}),i.jsx("line",{x1:"15.41",y1:"6.51",x2:"8.59",y2:"10.49"})]}),t(Me==="share"?"common:sharing":"common:share")]})]}),X=i.jsx("button",{onClick:()=>S(ce),disabled:!!Me,className:"w-7 h-7 rounded-lg text-fg-muted hover:text-red-500 hover:bg-red-500/10 transition-colors disabled:opacity-50 inline-flex items-center justify-center",title:t("deleteLocalTooltip"),children:i.jsxs("svg",{className:"w-3.5 h-3.5",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[i.jsx("polyline",{points:"3 6 5 6 21 6"}),i.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"})]})}),Z=ce.meta.icon,Be=!!Z&&/\.(png|jpe?g|gif|webp|svg)$/i.test(Z)?Z.startsWith("http")||Z.startsWith("/")?Z:`/api/builder/artifacts/${ce.type}s/${encodeURIComponent(ce.name)}/images/${encodeURIComponent(Z.split("/").pop()??"")}?v=${ce.updatedAt??""}`:Z;return i.jsx(vr,{type:ce.type,name:et,description:nt,seed:we,icon:Be,version:se,footerLeft:i.jsxs("span",{className:"flex items-center gap-2 text-[10px] text-fg-tertiary min-w-0",children:[i.jsx("button",{onClick:Ie=>{Ie.stopPropagation(),Ae.system.openPath(ce.path).catch(()=>{})},className:"hover:text-fg-secondary transition-colors truncate min-w-0",title:ce.path,children:qre(ce.path)}),i.jsx("span",{className:"shrink-0",children:"·"}),i.jsx("span",{className:"shrink-0",children:new Date(ce.updatedAt).toLocaleDateString()})]}),headerAction:X,actions:Pe,onClick:()=>ln(ce)},we)})})),E&&i.jsx(ba,{variant:"primary",title:t("confirmInstall"),message:t("confirmInstallMsg",{name:E.meta.displayName||E.meta.name||E.name}),confirmLabel:t("common:install"),onConfirm:()=>{const ce=E;_(null),Zt(ce)},onCancel:()=>_(null)}),L&&i.jsx(ba,{variant:"primary",title:t("confirmUninstall"),message:t("confirmUninstallMsg",{name:L.meta.displayName||L.meta.name||L.name}),confirmLabel:t("common:uninstall"),onConfirm:()=>{const ce=L;D(null),Wt(ce)},onCancel:()=>D(null)}),C&&i.jsx(ba,{title:t("confirmDeleteLocal"),message:t("deleteCannotUndo",{name:C.meta.displayName||C.meta.name||C.name}),confirmLabel:t("common:delete"),onConfirm:mt,onCancel:()=>S(null)}),G&&i.jsx(ba,{title:t("confirmUnshare"),message:t("removeFromHub",{name:G.name}),confirmLabel:t("unshare"),onConfirm:()=>{$e()},onCancel:()=>Q(null)}),$&&i.jsx(ba,{alertOnly:!0,variant:$.variant??"primary",title:$.title,message:$.message,onConfirm:()=>Y(null),onCancel:()=>Y(null)}),K&&i.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm",onClick:()=>ee(null),children:i.jsxs("div",{className:"bg-surface-secondary border border-border-default rounded-xl max-w-sm w-full mx-4 p-6 shadow-2xl",onClick:ce=>ce.stopPropagation(),children:[i.jsx("h3",{className:"text-base font-semibold text-fg-primary mb-2",children:t("common:share")}),i.jsx("p",{className:"text-sm text-fg-secondary mb-5",children:t("share.imagePrompt")}),i.jsxs("div",{className:"flex gap-3",children:[i.jsx("button",{onClick:()=>{const ce=K;ee(null),J(ce)},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")}),i.jsx("button",{onClick:()=>{const ce=K;ee(null),ln(ce)},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")})]})]})}),U&&i.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm",onClick:()=>te(null),children:i.jsx("div",{className:"bg-surface-secondary border border-border-default rounded-xl max-w-sm w-full mx-4 p-6 shadow-2xl",onClick:ce=>ce.stopPropagation(),children:i.jsx(Vre,{isUpdate:M.has(`${U.type}/${U.name}`),onCancel:()=>te(null),onConfirm:(ce,et)=>{const nt=U;te(null),rt(nt,{priceCents:et>0?et:void 0})}})})}),I&&i.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm",onClick:()=>J(null),children:i.jsx("div",{className:"bg-surface-secondary border border-border-default rounded-xl max-w-sm w-full mx-4 p-6 shadow-2xl",onClick:ce=>ce.stopPropagation(),children:i.jsx(Kre,{onCancel:()=>J(null),onConfirm:(ce,et,nt,we)=>{const Me=I;J(null),rt(Me,{visibility:ce,orgId:et,priceCents:nt,donationsEnabled:we})}})})})]})})}function Kre({onCancel:e,onConfirm:t}){const{t:n}=ot(["builder","common"]),[a,s]=k.useState("public"),[l,c]=k.useState([]),[d,m]=k.useState(""),[p,h]=k.useState(!1),[g,x]=k.useState(0),[y,w]=k.useState(!1);k.useEffect(()=>{a==="org"&&l.length===0&&(h(!0),st.myOrgs().then(S=>{c(S.memberships),S.memberships.length>0&&m(S.memberships[0].id)}).catch(()=>{}).finally(()=>h(!1)))},[a,l.length]);const T=a==="public"||a==="unlisted",C=[{value:"public",icon:i.jsxs("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[i.jsx("circle",{cx:"12",cy:"12",r:"10"}),i.jsx("line",{x1:"2",y1:"12",x2:"22",y2:"12"}),i.jsx("path",{d:"M12 2a15.3 15.3 0 0 1 4 10 15.3 15.3 0 0 1-4 10 15.3 15.3 0 0 1-4-10 15.3 15.3 0 0 1 4-10z"})]}),label:n("visibility.public"),desc:n("visibility.publicDesc")},{value:"org",icon:i.jsxs("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[i.jsx("path",{d:"M3 21h18"}),i.jsx("path",{d:"M9 8h1"}),i.jsx("path",{d:"M9 12h1"}),i.jsx("path",{d:"M9 16h1"}),i.jsx("path",{d:"M14 8h1"}),i.jsx("path",{d:"M14 12h1"}),i.jsx("path",{d:"M14 16h1"}),i.jsx("path",{d:"M5 21V5a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2v16"})]}),label:n("visibility.org"),desc:n("visibility.orgDesc")},{value:"unlisted",icon:i.jsxs("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[i.jsx("path",{d:"M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"}),i.jsx("path",{d:"M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"})]}),label:n("visibility.unlisted"),desc:n("visibility.unlistedDesc")}];return i.jsxs(i.Fragment,{children:[i.jsx("h3",{className:"text-base font-semibold text-fg-primary mb-4",children:n("visibility.label")}),i.jsx("div",{className:"space-y-2 mb-5",children:C.map(S=>i.jsxs("label",{className:`flex items-center gap-3 p-3 rounded-lg border cursor-pointer transition-colors ${a===S.value?"border-brand-500 bg-brand-500/10":"border-border-default hover:border-gray-600"}`,children:[i.jsx("input",{type:"radio",name:"visibility",checked:a===S.value,onChange:()=>s(S.value),className:"accent-brand-500"}),i.jsx("div",{className:"flex items-center gap-2 text-fg-secondary",children:S.icon}),i.jsxs("div",{children:[i.jsx("div",{className:"text-sm font-medium text-fg-primary",children:S.label}),i.jsx("div",{className:"text-[11px] text-fg-tertiary",children:S.desc})]})]},S.value))}),a==="org"&&i.jsxs("div",{className:"mb-5",children:[i.jsx("label",{className:"text-xs text-fg-secondary block mb-1.5",children:n("visibility.orgSelect")}),p?i.jsx("div",{className:"text-xs text-fg-tertiary py-2",children:"Loading..."}):l.length===0?i.jsx("div",{className:"text-xs text-fg-tertiary py-2",children:n("visibility.orgNone")}):i.jsx("select",{value:d,onChange:S=>m(S.target.value),className:"w-full text-sm px-3 py-2 rounded-lg bg-surface-elevated border border-border-default text-fg-primary",children:l.map(S=>i.jsx("option",{value:S.id,children:S.name},S.id))})]}),T&&i.jsxs("div",{className:"mb-5",children:[i.jsx("label",{className:"text-xs text-fg-secondary block mb-1.5",children:n("pricing.label")}),i.jsx("div",{className:"grid grid-cols-4 gap-2 mb-3",children:o6.map(S=>i.jsx("button",{type:"button",onClick:()=>x(S.cents),className:`text-sm px-2 py-2 rounded-lg border transition-colors ${g===S.cents?"border-brand-500 bg-brand-500/10 text-fg-primary":"border-border-default text-fg-secondary hover:border-gray-600"}`,children:S.label},S.cents))}),i.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[i.jsx("input",{type:"checkbox",checked:y,onChange:S=>w(S.target.checked),className:"accent-brand-500"}),i.jsx("span",{className:"text-xs text-fg-secondary",children:n("pricing.enableTips")})]})]}),T&&i.jsx("div",{className:"mb-4 text-[11px] text-fg-tertiary rounded-lg border border-border-default px-3 py-2",children:n("pricing.reviewNote")}),i.jsxs("div",{className:"flex gap-3",children:[i.jsx("button",{onClick:e,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:n("common:cancel")}),i.jsx("button",{onClick:()=>t(a,a==="org"?d:void 0,T&&g>0?g:void 0,T?y:void 0),disabled:a==="org"&&!d,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:n("shareMode.share")})]})]})}const o6=[{cents:0,label:"Free"},{cents:100,label:"$1"},{cents:500,label:"$5"},{cents:1e3,label:"$10"}];function Vre({isUpdate:e,onCancel:t,onConfirm:n}){const{t:a}=ot(["builder","common"]),[s,l]=k.useState(0);return i.jsxs(i.Fragment,{children:[i.jsx("h3",{className:"text-base font-semibold text-fg-primary mb-4",children:a(e?"shareMode.titleUpdate":"shareMode.title")}),i.jsx("div",{className:"space-y-2 mb-5",children:o6.map(c=>i.jsxs("label",{className:`flex items-center gap-3 p-3 rounded-lg border cursor-pointer transition-colors ${s===c.cents?"border-brand-500 bg-brand-500/10":"border-border-default hover:border-gray-600"}`,children:[i.jsx("input",{type:"radio",name:"sharePrice",checked:s===c.cents,onChange:()=>l(c.cents),className:"accent-brand-500"}),i.jsxs("div",{children:[i.jsx("div",{className:"text-sm font-medium text-fg-primary",children:c.label}),i.jsx("div",{className:"text-[11px] text-fg-tertiary",children:c.cents===0?a("shareMode.freeDesc"):a("shareMode.paidDesc")})]})]},c.cents))}),i.jsxs("div",{className:"flex gap-3",children:[i.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:a("common:cancel")}),i.jsx("button",{onClick:()=>n(s>0?"paid":"free",s),className:"flex-1 text-sm px-4 py-2 rounded-lg bg-brand-600 hover:bg-brand-500 text-white transition-colors",children:a(e?"shareMode.update":"shareMode.share")})]})]})}const Wre=Object.freeze(Object.defineProperty({__proto__:null,AgentBuilder:s6},Symbol.toStringTag,{value:"Module"}));async function l6(e,t){if(!t)return{items:e,highlighted:null,missing:!1};const n=e.find(a=>a.id===t);if(n)return{items:[n,...e.filter(a=>a.id!==t)],highlighted:n,missing:!1};try{const{item:a}=await st.getItem(t);return a?{items:[a,...e],highlighted:a,missing:!1}:{items:e,highlighted:null,missing:!0}}catch{return{items:e,highlighted:null,missing:!0}}}function Yre(e,t){const n=e.split(".").map(Number),a=t.split(".").map(Number);for(let s=0;s<Math.max(n.length,a.length);s++){const l=n[s]??0,c=a[s]??0;if(l>c)return!0;if(l<c)return!1}return!1}function Pm(e,t){const n=e.i18n?.[t];return n?.displayName||n?.name||e.name}function xk(e,t){return e.i18n?.[t]?.description||e.description}const Qre={manager:"bg-brand-500/15 text-brand-500",worker:"bg-blue-500/15 text-blue-600"};function Xre({authUser:e,highlightItemId:t,onHighlightDone:n}={}){const{t:a,i18n:s}=ot(["store","common"]),l=s.language,[c,d]=k.useState(""),[m,p]=k.useState([]),[h,g]=k.useState([]),[x,y]=k.useState(null),[w,T]=k.useState({}),[C,S]=k.useState(!1),[E,_]=k.useState(!0),[L,D]=k.useState(new Map),[M,O]=k.useState(new Set),[G,Q]=k.useState(null),[$,Y]=k.useState(null),K=k.useCallback(async()=>{try{const[te,I]=await Promise.all([Ae.builder.artifacts.list().catch(()=>({artifacts:[]})),Ae.builder.artifacts.installed().catch(()=>({installed:{}}))]),J=new Map;for(const me of te.artifacts){if(me.type!=="agent")continue;const Ce=!!I.installed[`agent/${me.name}`];J.set(me.name,{installed:Ce,localVersion:me.meta.version||void 0,localUpdatedAt:me.updatedAt})}D(J)}catch{}},[]),ee=k.useCallback(async()=>{_(!0);try{const te=c?st.search({type:"agent",q:c,limit:50}):Ls(qa.hubAgents)??st.search({type:"agent",limit:50}),I=new URLSearchParams;c&&I.set("q",c);const J=fetch("/api/templates?"+I.toString()).then(V=>V.json()).catch(()=>({templates:[]})),[me,Ce]=await Promise.all([te.catch(()=>({items:[],total:0})),J,K(),st.isAuthenticated()?st.purchases.mine().then(V=>O(new Set(V.purchases.map(fe=>fe.itemId)))).catch(()=>{}):Promise.resolve()]),H=await l6(me?.items??[],t);g(H.items),p(Array.isArray(Ce.templates)?Ce.templates:[]),H.missing&&n?.()}catch{p([]),g([])}finally{_(!1)}},[c,K,t,n]);k.useEffect(()=>{ee()},[ee]),k.useEffect(()=>{if(!x){T({});return}fetch(`/api/templates/${encodeURIComponent(x.id)}/files`,{credentials:"include"}).then(te=>te.json()).then(te=>T(te.files??{})).catch(()=>T({}))},[x]);const U=async(te,I,J)=>{try{const me=await fetch("/api/templates/instantiate",{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({templateId:te,name:I,orgId:"default",teamId:J})});if(!me.ok)throw new Error(`Failed: ${me.status}`);S(!1),y(null)}catch(me){Y({title:a("common:create",{defaultValue:"Create"}),message:`Failed to create agent: ${me}`,variant:"danger"})}};if(G)return i.jsx(qs,{type:G.type,name:G.name,onBack:()=>Q(null)});if(x){const te={type:"agent",name:x.id,displayName:Pm(x,l),version:x.version,description:xk(x,l),author:x.author,category:x.category,tags:x.tags,icon:x.icon,files:w,agent:{roleName:x.roleId,agentRole:x.agentRole==="manager"?"manager":"worker"},dependencies:{skills:x.skills}},I=i.jsxs("div",{className:"space-y-6",children:[i.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[i.jsxs("div",{className:"rounded-xl border border-border-default bg-surface-secondary/40 p-5",children:[i.jsx("h3",{className:"text-xs text-fg-tertiary uppercase tracking-wider mb-3",children:a("agentStore.roleConfig")}),i.jsxs("div",{className:"space-y-2.5 text-sm",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("span",{className:"text-fg-tertiary w-20",children:a("agentStore.role")}),i.jsx("span",{className:"text-fg-secondary font-mono text-xs bg-surface-elevated px-2 py-0.5 rounded",children:x.roleId})]}),i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("span",{className:"text-fg-tertiary w-20",children:a("agentStore.position")}),i.jsx("span",{className:`px-2 py-0.5 rounded text-xs capitalize ${Qre[x.agentRole]??""}`,children:x.agentRole})]})]})]}),i.jsxs("div",{className:"rounded-xl border border-border-default bg-surface-secondary/40 p-5",children:[i.jsx("h3",{className:"text-xs text-fg-tertiary uppercase tracking-wider mb-3",children:a("agentStore.skills")}),i.jsxs("div",{className:"flex flex-wrap gap-1.5",children:[x.skills.map(J=>i.jsx("span",{className:"px-2.5 py-1 text-xs bg-brand-500/10 text-brand-500 rounded-lg border border-brand-500/20",children:J},J)),x.skills.length===0&&i.jsx("span",{className:"text-xs text-fg-tertiary italic",children:a("agentStore.noSkills")})]})]})]}),x.starterTasks&&x.starterTasks.length>0&&i.jsxs("div",{className:"rounded-xl border border-border-default bg-surface-secondary/40 p-5",children:[i.jsx("h3",{className:"text-xs text-fg-tertiary uppercase tracking-wider mb-3",children:a("agentStore.starterTasks")}),i.jsx("div",{className:"space-y-2",children:x.starterTasks.map((J,me)=>i.jsxs("div",{className:"flex items-start gap-3 bg-surface-elevated/50 rounded-lg p-3",children:[i.jsx("span",{className:`inline-block w-2 h-2 rounded-full shrink-0 mt-1 ${J.priority==="high"?"bg-red-400":J.priority==="medium"?"bg-amber-400":"bg-green-400"}`}),i.jsxs("div",{children:[i.jsx("div",{className:"text-sm text-fg-primary",children:J.title}),J.description&&i.jsx("div",{className:"text-xs text-fg-tertiary mt-0.5",children:J.description})]})]},me))})]})]});return i.jsxs(i.Fragment,{children:[i.jsx(qs,{type:"agent",name:x.id,onBack:()=>y(null),readOnly:!0,initialManifest:te,actionSlot:i.jsx("button",{onClick:()=>S(!0),className:"px-4 py-1.5 text-xs bg-brand-600 hover:bg-brand-500 text-white rounded-lg transition-colors font-medium",children:a("agentStore.hireAgent")}),contentSlot:I}),C&&i.jsx(vk,{template:x,lang:l,onClose:()=>S(!1),onHire:U}),$&&i.jsx(ba,{alertOnly:!0,variant:$.variant??"danger",title:$.title,message:$.message,onConfirm:()=>Y(null),onCancel:()=>Y(null)})]})}return i.jsxs("div",{className:"flex-1 overflow-hidden flex flex-col",children:[i.jsxs("div",{"data-electron-drag":!0,className:"px-6 h-14 flex items-center justify-between shrink-0 gap-3",children:[i.jsx("h2",{className:"text-lg font-semibold",children:a("agentStore.title")}),i.jsx("input",{type:"text",placeholder:a("agentStore.searchPlaceholder"),value:c,onChange:te=>d(te.target.value),className:"px-3 py-1.5 bg-surface-elevated border border-border-default rounded-lg text-sm max-w-xs w-full focus:border-brand-500 focus:outline-none"})]}),i.jsx("div",{className:"flex-1 overflow-y-auto p-7 space-y-8",children:E?i.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4",children:Array.from({length:6}).map((te,I)=>i.jsx("div",{className:"h-56 rounded-2xl skeleton"},I))}):m.length===0&&h.length===0?i.jsxs("div",{className:"text-center py-20",children:[i.jsx("div",{className:"text-4xl mb-4 opacity-30",children:"⧉"}),i.jsx("div",{className:"text-fg-secondary font-medium mb-1",children:c?a("agentStore.noResults",{search:c}):a("agentStore.noAgents")}),i.jsx("div",{className:"text-fg-tertiary text-sm",children:a(c?"agentStore.noResultsHint":"agentStore.noAgentsHint")})]}):i.jsxs(i.Fragment,{children:[m.length>0&&i.jsxs("section",{children:[i.jsxs("div",{className:"flex items-baseline gap-2 mb-3",children:[i.jsx("h3",{className:"section-title",children:a("agentStore.builtin")}),i.jsx("span",{className:"text-xs text-fg-tertiary",children:a("agentStore.available",{count:m.length})})]}),i.jsx(Fa,{columns:3,children:m.map(te=>i.jsx(vr,{type:"agent",name:Pm(te,l),description:xk(te,l),seed:te.id,icon:te.icon,version:te.version,category:te.category,tags:te.tags,authorLabel:te.author,hideStats:!0,showTypeBadge:!1,cornerLabel:a("agentStore.builtin"),onClick:()=>y(te)},te.id))})]}),h.length>0&&i.jsxs("section",{children:[i.jsx("h3",{className:"section-title mb-3",children:a("agentStore.markusHub")}),i.jsx(Fa,{columns:3,children:h.map(te=>i.jsx(Jre,{item:te,localInfo:L.get(Fc(te)),purchased:cm(te,M),onStatusChange:K,highlight:te.id===t,onHighlightDone:n,onViewDetail:I=>Q({type:"agent",name:I})},te.id))})]})]})}),C&&x&&i.jsx(vk,{template:x,lang:l,onClose:()=>S(!1),onHire:U}),$&&i.jsx(ba,{alertOnly:!0,variant:$.variant??"danger",title:$.title,message:$.message,onConfirm:()=>Y(null),onCancel:()=>Y(null)})]})}function Fc(e,t){if(e.slug&&e.slug.trim())return e.slug.trim();const n=t&&typeof t.name=="string"?t.name.trim():"";return mm(n||e.name,"hub-pkg")}function Is(e){return(async()=>{const t=await st.download(e.id),n=t.name||e.name,a=t.config??{},s=Fc(e,a),l=t.itemType==="team"?"team":t.itemType==="skill"?"skill":"agent",c={type:"hub",hubItemId:e.id},d=(t.version||e.version||(typeof a.version=="string"?a.version:"")||"").trim()||void 0;if(t.files&&Object.keys(t.files).length>0)await Ae.builder.artifacts.import(l,s,t.files,c,d);else{const m={...a,...d?{version:d}:{},name:s,displayName:a.displayName||n,description:e.description,source:c};await Ae.builder.artifacts.save(l,m)}return await Ae.builder.artifacts.install(l,s),window.dispatchEvent(new CustomEvent("markus:data-changed")),n})()}async function vb(e,t){t("checking"),await st.ensureAuth();const n=await st.purchases.checkout(e.id);if(n.alreadyOwned)return t("installing"),await Is(e),"installed";try{if((await st.creator.getBalance()).availableBalance>=(e.priceCents??0)){const c=await st.purchases.payWithEarnings(e.id);if(c.ok||c.alreadyOwned)return t("installing"),await Is(e),"installed"}}catch{}if(!n.checkoutUrl)throw new Error("No checkout URL");t("checkout_opened");const a=Go();let s=null;return a?fi(n.checkoutUrl):s=window.open(n.checkoutUrl,"_blank","noopener"),new Promise((l,c)=>{const d=Date.now(),m=300*1e3,p=setInterval(async()=>{if(Date.now()-d>m){clearInterval(p),l("cancelled");return}const g=!a&&s?s.closed:!1;try{if((await st.purchases.checkout(e.id)).alreadyOwned){clearInterval(p),t("installing");try{await Is(e),l("installed")}catch(y){c(y)}return}}catch{}if(g){clearInterval(p);try{if((await st.purchases.checkout(e.id)).alreadyOwned){t("installing"),await Is(e),l("installed");return}}catch{}l("cancelled")}},2e3)})}function Jre({item:e,localInfo:t,purchased:n,onStatusChange:a,highlight:s,onHighlightDone:l,onViewDetail:c}){const{t:d}=ot(["store"]),[m,p]=k.useState(!1),[h,g]=k.useState(""),x=k.useRef(null),[y,w]=k.useState(!1);k.useEffect(()=>{if(s&&x.current){x.current.scrollIntoView({behavior:"smooth",block:"center"}),w(!0);const G=setTimeout(()=>{w(!1)},4e3);return()=>clearTimeout(G)}},[s,l]);const T=t?.installed??!1,C=T&&e.version&&t?.localVersion&&Yre(e.version,t.localVersion),S=(e.priceCents??0)>0,E=async G=>{if(G.stopPropagation(),!m){p(!0),g("");try{await Is(e),g(C?d("card.upgraded"):d("card.installed")+"!"),a()}catch(Q){const $=Q instanceof Error?Q.message:"";$.includes("402")||$.includes("Purchase required")?g(d("card.purchaseRequired")):g(d("card.failed"))}finally{p(!1)}}},_=async G=>{if(G.stopPropagation(),!m){p(!0),g("");try{await vb(e,$=>{$==="checkout_opened"?g(d("card.waitingPurchase","Waiting for purchase...")):$==="installing"&&g(d("card.installing"))})==="installed"?(g(d("card.installed")+"!"),a()):g("")}catch(Q){g(Q instanceof Error?Q.message:d("card.failed"))}finally{p(!1)}}},L=S?`$${((e.priceCents??0)/100).toFixed(2)}`:null,D=e.slug&&e.author?.username?`${st.getUrl()}/@${encodeURIComponent(e.author.username)}/${encodeURIComponent(e.slug)}`:null,M=()=>{T&&c?c(Fc(e)):D&&window.open(D,"_blank","noopener,noreferrer")},O=i.jsxs(i.Fragment,{children:[C?i.jsx("button",{onClick:G=>{E(G)},disabled:m,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:m?d("card.upgrading"):d("card.upgrade",{version:e.version})}):T?i.jsxs("button",{onClick:G=>{E(G)},disabled:m,className:"px-3 py-1.5 text-xs bg-surface-elevated hover:bg-surface-overlay text-fg-secondary border border-border-default rounded-lg transition-colors disabled:opacity-50",children:[d("card.installed"),t?.localVersion?` v${t.localVersion}`:""]}):S&&!n?i.jsx("button",{onClick:G=>{_(G)},disabled:m,className:"px-3 py-1.5 text-xs bg-amber-600 hover:bg-amber-500 text-white rounded-lg transition-colors disabled:opacity-50 inline-flex items-center gap-1",children:m?h||d("card.installing"):i.jsxs(i.Fragment,{children:[d("card.buy","Buy")," ",L]})}):i.jsx("button",{onClick:G=>{E(G)},disabled:m,className:"px-3 py-1.5 text-xs bg-brand-600 hover:bg-brand-500 text-white rounded-lg transition-colors disabled:opacity-50",children:d(m?"card.installing":"card.install")}),h&&!(S&&!n)&&i.jsx("span",{className:`text-[10px] ${h===d("card.failed")||h===d("card.purchaseRequired")?"text-red-500":"text-green-600"}`,children:h})]});return i.jsx("div",{ref:x,className:y?"animate-pulse":"",children:i.jsx(vr,{type:"agent",showTypeBadge:!1,name:e.name,description:e.description,seed:e.slug||e.name,icon:e.icon||"bot",cover:e.thumbnailUrl,hubBase:st.getUrl(),author:e.author,version:e.version,category:e.category,tags:e.tags,rating:parseFloat(e.avgRating)||0,ratingCount:e.ratingCount,downloadCount:e.downloadCount,priceCents:e.priceCents,currency:e.currency,installed:T,glowing:y,onClick:M,actions:O})})}function vk({template:e,lang:t,onClose:n,onHire:a}){const{t:s}=ot(["store"]),[l,c]=k.useState(`${Pm(e,t)} Agent`),[d,m]=k.useState(""),[p,h]=k.useState([]),[g,x]=k.useState(!1);k.useEffect(()=>{fetch("/api/teams",{credentials:"include"}).then(w=>w.json()).then(w=>h(w.teams??[])).catch(()=>{})},[]);const y=async()=>{if(l.trim()){x(!0);try{await a(e.id,l.trim(),d||void 0)}finally{x(!1)}}};return i.jsx("div",{className:"fixed inset-0 bg-black/60 flex items-center justify-center z-50",onClick:n,children:i.jsxs("div",{className:"bg-surface-secondary border border-border-default rounded-xl p-6 w-[440px] shadow-2xl",onClick:w=>w.stopPropagation(),children:[i.jsx("div",{className:"flex items-center gap-3 mb-5",children:i.jsxs("div",{children:[i.jsx("h3",{className:"text-base font-semibold",children:s("hireModal.title")}),i.jsx("p",{className:"text-xs text-fg-tertiary",children:s("hireModal.creating",{name:Pm(e,t)})})]})}),i.jsxs("div",{className:"space-y-4",children:[i.jsxs("div",{children:[i.jsx("label",{className:"block text-xs text-fg-tertiary mb-1.5",children:s("hireModal.agentName")}),i.jsx("input",{type:"text",value:l,onChange:w=>c(w.target.value),className:"input-field",autoFocus:!0})]}),p.length>0&&i.jsxs("div",{children:[i.jsx("label",{className:"block text-xs text-fg-tertiary mb-1.5",children:s("hireModal.assignTeam")}),i.jsxs("select",{value:d,onChange:w=>m(w.target.value),className:"input-field",children:[i.jsx("option",{value:"",children:s("hireModal.noTeam")}),p.map(w=>i.jsx("option",{value:w.id,children:w.name},w.id))]})]}),i.jsxs("div",{className:"bg-surface-elevated/50 rounded-lg p-3",children:[i.jsx("div",{className:"text-xs text-fg-tertiary mb-2 font-medium",children:s("hireModal.agentConfig")}),i.jsxs("div",{className:"grid grid-cols-2 gap-y-1.5 gap-x-4 text-xs",children:[i.jsx("div",{className:"text-fg-tertiary",children:s("hireModal.role")}),i.jsx("div",{className:"text-fg-secondary font-mono",children:e.roleId}),i.jsx("div",{className:"text-fg-tertiary",children:s("hireModal.position")}),i.jsx("div",{className:"text-fg-secondary capitalize",children:e.agentRole}),i.jsx("div",{className:"text-fg-tertiary",children:s("hireModal.skills")}),i.jsx("div",{className:"text-fg-secondary",children:e.skills.join(", ")||s("hireModal.none")})]})]})]}),i.jsxs("div",{className:"flex justify-end gap-3 mt-6",children:[i.jsx("button",{onClick:n,className:"btn-secondary",children:s("hireModal.cancel")}),i.jsx("button",{onClick:y,disabled:!l.trim()||g,className:"btn-primary",children:s(g?"hireModal.creating_progress":"hireModal.create")})]})]})})}function yh(e,t){const n=e.i18n?.[t];return n?.displayName||n?.name||e.name}function wk(e,t){return e.i18n?.[t]?.description||e.description}function kk(e,t,n){return e.i18n?.[n]?.members?.[t]||t}function Zre(e,t){const n=e.split(".").map(Number),a=t.split(".").map(Number);for(let s=0;s<Math.max(n.length,a.length);s++){const l=n[s]??0,c=a[s]??0;if(l>c)return!0;if(l<c)return!1}return!1}function eie({highlightItemId:e,onHighlightDone:t}={}){const{t:n,i18n:a}=ot(["store","common"]),s=a.language,[l,c]=k.useState(""),[d,m]=k.useState([]),[p,h]=k.useState([]),[g,x]=k.useState(null),[y,w]=k.useState({}),[T,C]=k.useState(!0),[S,E]=k.useState(!1),[_,L]=k.useState(null),[D,M]=k.useState(new Map),[O,G]=k.useState(new Set),[Q,$]=k.useState(null),Y=k.useCallback(async()=>{try{const[U,te]=await Promise.all([Ae.builder.artifacts.list().catch(()=>({artifacts:[]})),Ae.builder.artifacts.installed().catch(()=>({installed:{}}))]),I=new Map;for(const J of U.artifacts){if(J.type!=="team")continue;const me=!!te.installed[`team/${J.name}`];I.set(J.name,{installed:me,localVersion:J.meta.version||void 0,localUpdatedAt:J.updatedAt})}M(I)}catch{}},[]),K=k.useCallback(async()=>{C(!0);try{const U=l?st.search({type:"team",q:l,limit:50}):Ls(qa.hubTeams)??st.search({type:"team",limit:50}),[te,I]=await Promise.all([U.catch(()=>({items:[],total:0})),Ae.teamTemplates.list(l||void 0).catch(()=>({templates:[]})),Y(),st.isAuthenticated()?st.purchases.mine().then(me=>G(new Set(me.purchases.map(Ce=>Ce.itemId)))).catch(()=>{}):Promise.resolve()]),J=await l6(te?.items??[],e);h(J.items),m(I?.templates??[]),J.missing&&t?.()}catch{m([]),h([])}finally{C(!1)}},[l,Y,e,t]);k.useEffect(()=>{K()},[K]),k.useEffect(()=>{if(!g){w({});return}fetch(`/api/team-templates/${encodeURIComponent(g.id)}/files`,{credentials:"include"}).then(U=>U.json()).then(U=>w(U.files??{})).catch(()=>w({}))},[g]);const ee=async U=>{E(!0),L(null);try{const I=(await Ae.teams.create(U.name,U.description)).team.id;let J,me=0;const Ce=[];for(const V of U.members){const fe=V.count??1;for(let z=0;z<fe;z++){const je=V.name??`${U.name} Agent ${z+1}`,Ue=fe>1?`${je} ${z+1}`:je,qe=V.roleName??V.templateId;try{const He=await fetch("/api/agents",{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({name:Ue,...qe?{roleName:qe}:{},orgId:"default",teamId:I,agentRole:V.role??"worker",skills:V.skills??[]})});if(He.ok){me++;const ut=await He.json();V.role==="manager"&&!J&&(J=ut.agent?.id)}else{const ut=await He.json().catch(()=>({error:`HTTP ${He.status}`}));Ce.push(`${Ue}: ${ut.error??He.statusText}`)}}catch(He){Ce.push(`${Ue}: ${String(He)}`)}}}J&&await Ae.teams.update(I,{managerId:J,managerType:"agent"}).catch(()=>{});const H=Ce.length>0?` (${Ce.length} failed: ${Ce[0]})`:"";L({ok:me>0,message:`Team "${yh(U,s)}" deployed with ${me} agent(s)${H}`})}catch(te){L({ok:!1,message:`Failed: ${te}`})}finally{E(!1)}};if(Q)return i.jsx(qs,{type:Q.type,name:Q.name,onBack:()=>$(null)});if(g){const U={...y};g.announcements&&(U["ANNOUNCEMENT.md"]=g.announcements),g.norms&&(U["NORMS.md"]=g.norms);const te={type:"team",name:g.id,displayName:yh(g,s),version:g.version,description:wk(g,s),author:g.author,category:g.category??"general",tags:g.tags??[],files:U,team:{members:g.members.map(J=>({name:kk(g,J.name??J.roleName??J.templateId??"Agent",s),role:J.role??"worker",roleName:J.roleName??J.templateId,count:J.count??1,skills:J.skills??[]}))}},I=i.jsxs("div",{className:"rounded-xl border border-border-default bg-surface-secondary/40 overflow-hidden",children:[i.jsx("div",{className:"px-5 py-3 border-b border-border-default bg-surface-elevated/30",children:i.jsx("h3",{className:"text-xs text-fg-tertiary uppercase tracking-wider",children:n("teamStore.teamComposition")})}),i.jsx("div",{className:"p-5 space-y-2",children:g.members.map((J,me)=>{const Ce=kk(g,J.name??J.roleName??J.templateId??"Agent",s);return i.jsxs("div",{className:"flex items-center gap-3 bg-surface-elevated/50 rounded-lg p-3",children:[i.jsx("div",{className:`w-9 h-9 rounded-lg flex items-center justify-center text-sm font-bold shrink-0 ${J.role==="manager"?"bg-amber-500/15 text-amber-400 ring-1 ring-amber-500/30":"bg-blue-500/15 text-blue-400 ring-1 ring-blue-500/30"}`,children:(Ce[0]??"?").toUpperCase()}),i.jsxs("div",{className:"min-w-0 flex-1",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("span",{className:"text-sm text-fg-primary font-medium",children:Ce}),i.jsx("span",{className:`px-1.5 py-0.5 rounded text-[10px] capitalize font-medium ${J.role==="manager"?"bg-amber-500/15 text-amber-400":"bg-blue-500/15 text-blue-400"}`,children:J.role??"worker"}),(J.count??1)>1&&i.jsxs("span",{className:"text-[10px] text-fg-muted",children:["×",J.count]})]}),(J.roleName||J.templateId)&&i.jsx("div",{className:"text-[10px] text-fg-tertiary font-mono mt-0.5",children:J.roleName??J.templateId})]}),J.skills&&J.skills.length>0&&i.jsxs("div",{className:"flex flex-wrap gap-1 shrink-0",children:[J.skills.slice(0,3).map(H=>i.jsx("span",{className:"px-1.5 py-0.5 text-[9px] bg-surface-elevated text-fg-muted rounded border border-border-default",children:H},H)),J.skills.length>3&&i.jsxs("span",{className:"text-[9px] text-fg-muted",children:["+",J.skills.length-3]})]})]},me)})})]});return i.jsx(i.Fragment,{children:i.jsx(qs,{type:"team",name:g.id,onBack:()=>{x(null),L(null)},readOnly:!0,initialManifest:te,contentSlot:I,actionSlot:i.jsxs(i.Fragment,{children:[_&&i.jsx("span",{className:`text-xs ${_.ok?"text-green-500":"text-red-500"}`,children:_.message}),i.jsx("button",{onClick:()=>{ee(g)},disabled:S,className:"px-4 py-1.5 text-xs bg-brand-600 hover:bg-brand-500 text-white rounded-lg transition-colors font-medium disabled:opacity-50",children:n(S?"teamStore.deploying":"teamStore.deployTeam")})]})})})}return i.jsxs("div",{className:"flex-1 overflow-hidden flex flex-col",children:[i.jsxs("div",{"data-electron-drag":!0,className:"px-6 h-14 flex items-center justify-between shrink-0 gap-3",children:[i.jsx("h2",{className:"text-lg font-semibold",children:n("teamStore.title")}),i.jsx("input",{type:"text",placeholder:n("teamStore.searchPlaceholder"),value:l,onChange:U=>c(U.target.value),className:"px-3 py-1.5 bg-surface-elevated border border-border-default rounded-lg text-sm max-w-xs w-full focus:border-brand-500 focus:outline-none"})]}),i.jsx("div",{className:"flex-1 overflow-y-auto p-7 space-y-8",children:T?i.jsx("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-4",children:Array.from({length:4}).map((U,te)=>i.jsx("div",{className:"h-56 rounded-2xl skeleton"},te))}):d.length===0&&p.length===0?i.jsxs("div",{className:"text-center py-20",children:[i.jsx("div",{className:"text-4xl mb-4 opacity-30",children:"◉"}),i.jsx("div",{className:"text-fg-secondary font-medium mb-1",children:l?n("teamStore.noResults",{search:l}):n("teamStore.noTeams")}),i.jsx("div",{className:"text-fg-tertiary text-sm",children:n(l?"teamStore.noResultsHint":"teamStore.noTeamsHint")})]}):i.jsxs(i.Fragment,{children:[d.length>0&&i.jsxs("section",{children:[i.jsxs("div",{className:"flex items-baseline gap-2 mb-3",children:[i.jsx("h3",{className:"section-title",children:n("teamStore.builtin")}),i.jsx("span",{className:"text-xs text-fg-tertiary",children:n("teamStore.available",{count:d.length})})]}),i.jsx(Fa,{columns:2,children:d.map(U=>i.jsx(vr,{type:"team",name:yh(U,s),description:wk(U,s),seed:U.id,icon:U.icon||"users",version:U.version,category:U.category,tags:U.tags,authorLabel:U.author,hideStats:!0,showTypeBadge:!1,cornerLabel:n("teamStore.builtin"),onClick:()=>x(U)},U.id))})]}),p.length>0&&i.jsxs("section",{children:[i.jsx("h3",{className:"section-title mb-3",children:n("teamStore.markusHub")}),i.jsx(Fa,{columns:2,children:p.map(U=>i.jsx(tie,{item:U,localInfo:D.get(Fc(U)),purchased:cm(U,O),onStatusChange:Y,highlight:U.id===e,onHighlightDone:t,onViewDetail:te=>$({type:"team",name:te})},U.id))})]})]})})]})}function tie({item:e,localInfo:t,purchased:n,onStatusChange:a,highlight:s,onHighlightDone:l,onViewDetail:c}){const{t:d}=ot(["store"]),[m,p]=k.useState(!1),[h,g]=k.useState(""),x=k.useRef(null),[y,w]=k.useState(!1);k.useEffect(()=>{if(s&&x.current){x.current.scrollIntoView({behavior:"smooth",block:"center"}),w(!0);const G=setTimeout(()=>{w(!1)},4e3);return()=>clearTimeout(G)}},[s,l]);const T=t?.installed??!1,C=T&&e.version&&t?.localVersion&&Zre(e.version,t.localVersion),S=(e.priceCents??0)>0,E=S?`$${((e.priceCents??0)/100).toFixed(2)}`:null,_=async G=>{if(G.stopPropagation(),!m){p(!0),g("");try{await Is(e),g(C?d("card.upgraded"):d("card.installed")+"!"),a()}catch(Q){const $=Q instanceof Error?Q.message:"";$.includes("402")||$.includes("Purchase required")?g(d("card.purchaseRequired")):g(d("card.failed"))}finally{p(!1)}}},L=async G=>{if(G.stopPropagation(),!m){p(!0),g("");try{await vb(e,$=>{$==="checkout_opened"?g(d("card.waitingPurchase","Waiting for purchase...")):$==="installing"&&g(d("card.installing"))})==="installed"?(g(d("card.installed")+"!"),a()):g("")}catch(Q){g(Q instanceof Error?Q.message:d("card.failed"))}finally{p(!1)}}},D=e.slug&&e.author?.username?`${st.getUrl()}/@${encodeURIComponent(e.author.username)}/${encodeURIComponent(e.slug)}`:null,M=()=>{T&&c?c(Fc(e)):D&&window.open(D,"_blank","noopener,noreferrer")},O=i.jsxs(i.Fragment,{children:[C?i.jsx("button",{onClick:G=>{_(G)},disabled:m,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:m?d("card.upgrading"):d("card.upgrade",{version:e.version})}):T?i.jsxs("button",{onClick:G=>{_(G)},disabled:m,className:"px-3 py-1.5 text-xs bg-surface-elevated hover:bg-surface-overlay text-fg-secondary border border-border-default rounded-lg transition-colors disabled:opacity-50",children:[d("card.installed"),t?.localVersion?` v${t.localVersion}`:""]}):S&&!n?i.jsx("button",{onClick:G=>{L(G)},disabled:m,className:"px-3 py-1.5 text-xs bg-amber-600 hover:bg-amber-500 text-white rounded-lg transition-colors disabled:opacity-50 inline-flex items-center gap-1",children:m?h||d("card.installing"):i.jsxs(i.Fragment,{children:[d("card.buy","Buy")," ",E]})}):i.jsx("button",{onClick:G=>{_(G)},disabled:m,className:"px-3 py-1.5 text-xs bg-brand-600 hover:bg-brand-500 text-white rounded-lg transition-colors disabled:opacity-50",children:d(m?"card.installing":"card.install")}),h&&i.jsx("span",{className:`text-[10px] ${h===d("card.failed")||h===d("card.purchaseRequired")?"text-red-500":"text-green-600"}`,children:h})]});return i.jsx("div",{ref:x,className:y?"animate-pulse":"",children:i.jsx(vr,{type:"team",showTypeBadge:!1,name:e.name,description:e.description,seed:e.slug||e.name,icon:e.icon||"users",cover:e.thumbnailUrl,hubBase:st.getUrl(),author:e.author,version:e.version,category:e.category,tags:e.tags,rating:parseFloat(e.avgRating)||0,ratingCount:e.ratingCount,downloadCount:e.downloadCount,priceCents:e.priceCents,currency:e.currency,installed:T,glowing:y,onClick:M,actions:O})})}function xh(e,t){return e.i18n?.[t]?.displayName||e.name}function vh(e,t){return e.i18n?.[t]?.description||e.description||""}function c6(e,t){const n=e.split(".").map(Number),a=t.split(".").map(Number);for(let s=0;s<Math.max(n.length,a.length);s++){const l=n[s]??0,c=a[s]??0;if(l>c)return!0;if(l<c)return!1}return!1}const nie={development:"bg-blue-500/15 text-blue-600",devops:"bg-amber-500/15 text-amber-600",productivity:"bg-green-500/15 text-green-600",custom:"bg-gray-500/15 text-fg-secondary",browser:"bg-brand-500/15 text-brand-500",communication:"bg-green-500/15 text-green-600",data:"bg-brand-500/15 text-brand-500",platform:"bg-blue-500/15 text-blue-600","AI 智能":"bg-brand-500/15 text-brand-500",开发工具:"bg-blue-500/15 text-blue-600",效率提升:"bg-green-500/15 text-green-600",数据分析:"bg-brand-500/15 text-brand-500",内容创作:"bg-brand-500/15 text-brand-500",安全合规:"bg-red-500/15 text-red-500",通讯协作:"bg-green-500/15 text-green-600"};function aie({item:e,installedSkills:t,purchased:n,onMsg:a,onRefresh:s}){const{t:l}=ot(["store"]),[c,d]=k.useState(!1),m=e.name.toLowerCase().trim().replace(/\s+/g,"-").replace(/[\/\\:*?"<>|]+/g,"").replace(/-{2,}/g,"-").replace(/^-|-$/g,"")||"unnamed",p=t.find(S=>S.name===e.name||S.name===m||!!e.slug&&S.name===e.slug),h=!!p,g=h&&e.version&&p?.version&&c6(e.version,p.version),x=(e.priceCents??0)>0,[y,w]=k.useState(""),T=async()=>{if(!c){d(!0),w("");try{await Is(e),a(g?`Upgraded ${e.name}`:`Installed ${e.name}`,"success"),s()}catch(S){const E=S instanceof Error?S.message:"";E.includes("402")||E.includes("Purchase required")?a(l("card.purchaseRequired"),"error"):a(l("card.failed"),"error")}finally{d(!1)}}},C=async()=>{if(!c){d(!0),w("");try{await vb(e,E=>{E==="checkout_opened"?w(l("card.waitingPurchase","Waiting for purchase...")):E==="installing"&&w(l("card.installing"))})==="installed"&&(a(`Purchased & installed ${e.name}`,"success"),s()),w("")}catch(S){a(S instanceof Error?S.message:l("card.failed"),"error"),w("")}finally{d(!1)}}};if(g)return i.jsx("button",{onClick:()=>{T()},disabled:c,className:"px-2.5 py-1 text-[10px] bg-amber-600 hover:bg-amber-500 text-white rounded-lg disabled:opacity-50",children:c?l("card.upgrading"):l("card.upgrade",{version:e.version})});if(h)return i.jsxs("span",{className:"px-2.5 py-1 text-[10px] bg-surface-overlay text-fg-secondary rounded-lg",children:[l("card.installed"),p?.version?` (v${p.version})`:""]});if(x&&!n){const S=`$${((e.priceCents??0)/100).toFixed(2)}`;return i.jsx("span",{className:"inline-flex items-center gap-1.5",children:i.jsx("button",{onClick:()=>{C()},disabled:c,className:"px-2.5 py-1 text-[10px] bg-amber-600 hover:bg-amber-500 text-white rounded-lg disabled:opacity-50 inline-flex items-center gap-1",children:c?y||l("card.installing"):i.jsxs(i.Fragment,{children:[l("card.buy","Buy")," ",S]})})})}return i.jsx("button",{onClick:()=>{T()},disabled:c,className:"px-2.5 py-1 text-[10px] bg-brand-600 hover:bg-brand-500 text-white rounded-lg disabled:opacity-50",children:l(c?"card.installing":"card.install")})}function Sk({item:e,installedSkills:t,purchased:n,onMsg:a,onRefresh:s,highlight:l,onHighlightDone:c,type:d="skill"}){const m=k.useRef(null),[p,h]=k.useState(!1);k.useEffect(()=>{if(l&&m.current){m.current.scrollIntoView({behavior:"smooth",block:"center"}),h(!0);const y=setTimeout(()=>{h(!1)},4e3);return()=>clearTimeout(y)}},[l,c]);const g=e.slug&&e.author?.username?`${st.getUrl()}/@${encodeURIComponent(e.author.username)}/${encodeURIComponent(e.slug)}`:null,x=()=>{g&&window.open(g,"_blank","noopener,noreferrer")};return i.jsx("div",{ref:m,className:p?"animate-pulse":"",children:i.jsx(vr,{type:d,showTypeBadge:d!=="skill",name:e.name,description:e.description,seed:e.slug||e.name,icon:e.icon||tm(e.slug||e.name,e.category),cover:e.thumbnailUrl,hubBase:st.getUrl(),author:e.author,version:e.version,category:e.category,tags:e.tags,rating:parseFloat(e.avgRating)||0,ratingCount:e.ratingCount,downloadCount:e.downloadCount,priceCents:e.priceCents,currency:e.currency,onClick:x,actions:i.jsx(aie,{item:e,installedSkills:t,purchased:n,onMsg:a,onRefresh:s})})})}function rie({highlightItemId:e,onHighlightDone:t}={}){const{t:n,i18n:a}=ot(["store","common"]),s=a.language,l=Xo(),[c,d]=k.useState("skills"),[m,p]=k.useState(null),[h,g]=k.useState(new Set),[x,y]=k.useState([]),[w,T]=k.useState(null),[C,S]=k.useState([]),[E,_]=k.useState(0),[L,D]=k.useState(1),[M,O]=k.useState([]),[G,Q]=k.useState(""),[$,Y]=k.useState("score"),[K,ee]=k.useState(""),[U,te]=k.useState(!1),[I,J]=k.useState([]),[me,Ce]=k.useState(!1),[H,V]=k.useState([]),[fe,z]=k.useState(""),[je,Ue]=k.useState(!1),[qe,He]=k.useState([]),[ut,dt]=k.useState([]),[Nt,wt]=k.useState(new Set),[Zt,Wt]=k.useState(!1),[rt,$e]=k.useState(""),mt=[{id:"skills",labelKey:"skillStore.tabs.all"},{id:"skillhub",labelKey:"skillStore.tabs.skillhub"},{id:"skillssh",labelKey:"skillStore.tabs.skillssh"}],At=(q,ae="success")=>{p({text:q,type:ae}),setTimeout(()=>p(null),ae==="error"?1e4:4e3)},Dt=k.useCallback(async()=>{try{const q=await Ae.skills.list();y(q.skills)}catch{}},[]),ln=k.useCallback(async()=>{Ce(!0);try{const q=await Ae.skills.builtin();J(q.skills)}catch{}Ce(!1)},[]),ce=k.useCallback(async q=>{te(!0);try{const ae=await Ae.skills.registrySkillhub({q:q?.q,category:q?.category,page:q?.page??1,limit:24,sort:q?.sort??$});S(ae.skills),_(ae.total),ae.categories?.length&&O(ae.categories)}catch{}te(!1)},[$]),et=k.useCallback(async q=>{Ue(!0);try{const ae=await Ae.skills.registrySkillssh(q);V(ae.skills)}catch{}Ue(!1)},[]),nt=k.useCallback(async q=>{Wt(!0);try{const ae=q?st.search({type:"skill",q,limit:50}):Ls(qa.hubSkills)??st.search({type:"skill",limit:50}),Se=st.search({subtype:"connector",q:q||void 0,limit:50}).catch(()=>({items:[]})),[De,Pe]=await Promise.all([ae,Se,st.isAuthenticated()?st.purchases.mine().then(ue=>wt(new Set(ue.purchases.map(Be=>Be.itemId)))).catch(()=>{}):Promise.resolve()]);let X=De?.items??[],Z=Pe?.items??[];if(e){const ue=X.some(Ie=>Ie.id===e),Be=Z.some(Ie=>Ie.id===e);if(!ue&&!Be)try{const{item:Ie}=await st.getItem(e);Ie?.subtype==="connector"?Z=[Ie,...Z]:Ie?X=[Ie,...X]:t?.()}catch{t?.()}else ue&&(X=[X.find(Ge=>Ge.id===e),...X.filter(Ge=>Ge.id!==e)]),Be&&(Z=[Z.find(Ge=>Ge.id===e),...Z.filter(Ge=>Ge.id!==e)])}He(X),dt(Z)}catch{}Wt(!1)},[e,t]);k.useEffect(()=>{Dt(),ln(),ce(),et()},[]),k.useEffect(()=>{c==="skills"&&nt(rt)},[c,rt,nt]);const we=async q=>{g(ae=>new Set(ae).add(q.name));try{const ae=await Ae.skills.install({name:q.name,source:"skillhub",slug:q.slug,sourceUrl:q.homepage,description:q.description_zh??q.description,category:"custom",version:q.version});await Dt(),At(`"${q.name}" installed (${ae.method}) → ${ae.path}`),window.dispatchEvent(new CustomEvent("markus:data-changed"))}catch{At(`Download failed for "${q.name}". You can try manually from: ${q.homepage}`,"error")}g(ae=>{const Se=new Set(ae);return Se.delete(q.name),Se})},Me=async q=>{g(ae=>new Set(ae).add(q.name));try{const ae=await Ae.skills.install({name:q.name,source:"skillssh",sourceUrl:q.url,githubRepo:`${q.author}/${q.repo}`,githubSkillPath:q.name});await Dt(),At(`"${q.name}" installed (${ae.method}) → ${ae.path}`),window.dispatchEvent(new CustomEvent("markus:data-changed"))}catch{At(`Download failed for "${q.name}". You can try manually from: ${q.url}`,"error")}g(ae=>{const Se=new Set(ae);return Se.delete(q.name),Se})},Ne=async q=>{g(ae=>new Set(ae).add(q.name));try{const ae=await Ae.skills.install({name:q.name,source:"builtin"});await Dt(),await ln(),At(`"${q.name}" installed (${ae.method}) → ${ae.path}`),window.dispatchEvent(new CustomEvent("markus:data-changed"))}catch(ae){At(`Install failed for "${q.name}": ${ae}`,"error")}g(ae=>{const Se=new Set(ae);return Se.delete(q.name),Se})},se=H.filter(q=>{if(!fe)return!0;const ae=fe.toLowerCase();return q.name.toLowerCase().includes(ae)||q.repo.toLowerCase().includes(ae)});if(w){const q=w,ae={};q.instructions&&(ae["SKILL.md"]=q.instructions);const Se={type:"skill",name:q.name,displayName:xh(q,s),version:q.version,description:vh(q,s),author:q.author??"",category:q.category??"general",tags:q.tags,files:ae,skill:{skillFile:q.instructions?"SKILL.md":"",requiredPermissions:q.requiredPermissions,mcpServers:void 0,alwaysOn:!1}},De=q.installed&&q.installedVersion&&c6(q.version,q.installedVersion)?i.jsx("button",{onClick:()=>{Ne(q)},disabled:h.has(q.name),className:"px-4 py-1.5 text-xs bg-amber-600 hover:bg-amber-500 text-white rounded-lg disabled:opacity-50 transition-colors",children:h.has(q.name)?n("card.upgrading"):n("card.upgrade",{version:q.version})}):q.installed?i.jsxs("span",{className:"px-4 py-1.5 text-xs bg-green-500/10 text-green-500 rounded-lg border border-green-500/20 inline-flex items-center gap-1",children:[i.jsx("svg",{className:"w-3 h-3",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:i.jsx("polyline",{points:"20 6 9 17 4 12"})}),n("card.installed"),q.installedVersion?` v${q.installedVersion}`:""]}):i.jsx("button",{onClick:()=>{Ne(q)},disabled:h.has(q.name),className:"px-4 py-1.5 text-xs bg-green-600 hover:bg-green-500 text-white rounded-lg disabled:opacity-50 transition-colors",children:h.has(q.name)?n("card.installing"):n("card.install")}),Pe=i.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[i.jsxs("div",{className:"rounded-xl border border-border-default bg-surface-secondary/40 p-5",children:[i.jsx("h3",{className:"text-xs text-fg-tertiary uppercase tracking-wider mb-3",children:n("skillStore.details")}),i.jsxs("div",{className:"space-y-2.5 text-sm",children:[q.category&&i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("span",{className:"text-fg-tertiary w-24",children:n("skillStore.category")}),i.jsx("span",{className:`px-2 py-0.5 rounded-full text-[10px] font-medium capitalize ${nie[q.category]??"bg-gray-500/15 text-fg-secondary"}`,children:q.category})]}),i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("span",{className:"text-fg-tertiary w-24",children:n("skillStore.version")}),i.jsx("span",{className:"text-fg-secondary font-mono text-xs",children:q.version})]}),q.hasMcpServers&&i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("span",{className:"text-fg-tertiary w-24",children:n("skillStore.integration")}),i.jsx("span",{className:"px-2 py-0.5 rounded text-[10px] bg-purple-500/15 text-purple-400",children:"MCP"})]}),q.hasInstructions&&i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("span",{className:"text-fg-tertiary w-24",children:n("skillStore.instructions")}),i.jsx("span",{className:"text-green-500 text-xs",children:"✓"})]})]})]}),(q.requiredPermissions.length>0||q.tags.length>0)&&i.jsxs("div",{className:"space-y-4",children:[q.requiredPermissions.length>0&&i.jsxs("div",{className:"rounded-xl border border-border-default bg-surface-secondary/40 p-5",children:[i.jsx("h3",{className:"text-xs text-fg-tertiary uppercase tracking-wider mb-3",children:n("skillStore.permissions")}),i.jsx("div",{className:"flex flex-wrap gap-1.5",children:q.requiredPermissions.map(X=>i.jsx("span",{className:"px-2.5 py-1 text-xs bg-amber-500/10 text-amber-500 rounded-lg border border-amber-500/20",children:X},X))})]}),q.tags.length>0&&i.jsxs("div",{className:"rounded-xl border border-border-default bg-surface-secondary/40 p-5",children:[i.jsx("h3",{className:"text-xs text-fg-tertiary uppercase tracking-wider mb-3",children:n("skillStore.tags")}),i.jsx("div",{className:"flex flex-wrap gap-1.5",children:q.tags.map(X=>i.jsx("span",{className:"px-2.5 py-1 text-xs bg-surface-elevated text-fg-secondary rounded-lg border border-border-default/50",children:X},X))})]})]})]});return i.jsxs(i.Fragment,{children:[i.jsx(qs,{type:"skill",name:q.name,onBack:()=>T(null),readOnly:!0,initialManifest:Se,actionSlot:De,contentSlot:Pe}),m&&i.jsx("div",{className:`mx-7 mb-2 px-3 py-1.5 text-xs rounded-lg shrink-0 ${m.type==="error"?"bg-red-500/10 text-red-500":"bg-green-500/10 text-green-600"}`,children:m.text})]})}return i.jsxs("div",{className:"flex-1 overflow-hidden flex flex-col",children:[i.jsxs("div",{className:`${l?"px-4":"px-6"} shrink-0`,children:[i.jsx("div",{"data-electron-drag":!0,className:"flex items-center h-14",children:i.jsx("h2",{className:"text-lg font-semibold",children:n("skillStore.title")})}),i.jsx("div",{className:`flex ${l?"flex-wrap":""} gap-1 pb-2 overflow-x-auto scrollbar-hide`,children:mt.map(q=>i.jsx("button",{onClick:()=>d(q.id),className:`px-3 py-1.5 text-xs rounded-lg transition-colors shrink-0 ${c===q.id?"bg-brand-600 text-white":"text-fg-secondary hover:text-fg-primary hover:bg-surface-elevated"}`,children:n(q.labelKey)},q.id))})]}),m&&i.jsx("div",{className:`mx-7 mt-2 px-3 py-1.5 text-xs rounded-lg shrink-0 ${m.type==="error"?"bg-red-500/10 text-red-500":"bg-green-500/10 text-green-600"}`,children:m.text}),c==="skills"&&(()=>{const q=rt.trim().toLowerCase(),ae=q?I.filter(Pe=>xh(Pe,s).toLowerCase().includes(q)||vh(Pe,s).toLowerCase().includes(q)):I,Se=me&&Zt,De=ae.length===0&&qe.length===0&&ut.length===0;return i.jsxs("div",{className:`flex-1 overflow-y-auto ${l?"p-4":"p-6"} space-y-8`,children:[i.jsx("div",{className:"flex items-center gap-2",children:i.jsx("input",{value:rt,onChange:Pe=>$e(Pe.target.value),placeholder:n("skillStore.searchMarkusHub"),className:`px-3 py-1.5 bg-surface-elevated border border-border-default rounded-lg text-sm text-fg-primary focus:border-brand-500 outline-none ${l?"flex-1 min-w-0":"w-72"}`})}),Se&&De?i.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4",children:Array.from({length:6}).map((Pe,X)=>i.jsx("div",{className:"h-56 rounded-2xl skeleton"},X))}):De?i.jsxs("div",{className:"text-center text-fg-tertiary py-20",children:[i.jsx("div",{className:"text-4xl mb-3 opacity-30",children:"◇"}),i.jsx("div",{children:n("skillStore.noBuiltin")}),i.jsx("div",{className:"text-xs mt-1",children:n("skillStore.noBuiltinHint")})]}):i.jsxs(i.Fragment,{children:[ae.length>0&&i.jsxs("section",{children:[i.jsxs("div",{className:"flex items-baseline gap-2 mb-3",children:[i.jsx("h3",{className:"section-title",children:n("skillStore.tabs.builtin")}),i.jsx("span",{className:"text-xs text-fg-tertiary",children:n("skillStore.builtinCount",{count:ae.length})})]}),i.jsx(Fa,{columns:3,children:ae.map(Pe=>i.jsx(vr,{type:"skill",name:xh(Pe,s),description:vh(Pe,s),seed:Pe.name,icon:tm(Pe.name,Pe.category),version:Pe.version,category:Pe.category,tags:Pe.tags,authorLabel:Pe.author||void 0,installed:Pe.installed,hideStats:!0,showTypeBadge:!1,cornerLabel:Pe.installed?void 0:n("skillStore.tabs.builtin"),onClick:()=>T(Pe)},Pe.name))})]}),qe.length>0&&i.jsxs("section",{children:[i.jsx("h3",{className:"section-title mb-3",children:n("skillStore.tabs.markusHub")}),i.jsx(Fa,{columns:3,children:qe.map(Pe=>i.jsx(Sk,{item:Pe,installedSkills:x,purchased:cm(Pe,Nt),onMsg:At,onRefresh:()=>{Dt(),nt(rt)},highlight:Pe.id===e,onHighlightDone:t},Pe.id))})]}),ut.length>0&&i.jsxs("section",{children:[i.jsxs("div",{className:"mb-3",children:[i.jsx("h3",{className:"section-title",children:n("tabs.connectors")}),i.jsx("p",{className:"text-xs text-fg-tertiary mt-0.5",children:n("connectorStore.emptyHint","连接器让智能体接入外部工具与服务 (MCP)")})]}),i.jsx(Fa,{columns:3,children:ut.map(Pe=>i.jsx(Sk,{item:Pe,type:"connector",installedSkills:x,purchased:cm(Pe,Nt),onMsg:At,onRefresh:()=>{Dt(),nt(rt)},highlight:Pe.id===e,onHighlightDone:t},Pe.id))})]})]})]})})(),c==="skillhub"&&i.jsxs("div",{className:`flex-1 overflow-y-auto ${l?"p-4":"p-6"}`,children:[i.jsxs("div",{className:"flex items-center gap-2 mb-3 flex-wrap",children:[i.jsxs("select",{value:G,onChange:q=>{Q(q.target.value),D(1),ce({q:K||void 0,category:q.target.value||void 0,page:1})},className:"px-2 py-1.5 bg-surface-elevated border border-border-default rounded-lg text-xs text-fg-secondary outline-none",children:[i.jsx("option",{value:"",children:n("skillStore.allCategories")}),M.map(q=>i.jsx("option",{value:q,children:q},q))]}),i.jsxs("select",{value:$,onChange:q=>{Y(q.target.value),D(1),ce({q:K||void 0,category:G||void 0,page:1,sort:q.target.value})},className:"px-2 py-1.5 bg-surface-elevated border border-border-default rounded-lg text-xs text-fg-secondary outline-none",children:[i.jsx("option",{value:"score",children:n("skillStore.sortScore")}),i.jsx("option",{value:"downloads",children:n("skillStore.sortDownloads")}),i.jsx("option",{value:"stars",children:n("skillStore.sortStars")}),i.jsx("option",{value:"installs",children:n("skillStore.sortInstalls")})]}),!l&&i.jsx("span",{className:"text-xs text-fg-tertiary ml-auto",children:i.jsx("a",{href:"https://skillhub.tencent.com",target:"_blank",rel:"noopener noreferrer",className:"text-brand-500 hover:text-brand-500",children:n("skillStore.visitSite")})})]}),i.jsxs("div",{className:"flex items-center gap-2 mb-5",children:[i.jsx("input",{value:K,onChange:q=>ee(q.target.value),onKeyDown:q=>{q.key==="Enter"&&(D(1),ce({q:K||void 0,category:G||void 0,page:1}))},placeholder:n("skillStore.searchSkillhub"),className:"px-3 py-1.5 bg-surface-elevated border border-border-default rounded-lg text-sm text-fg-primary focus:border-brand-500 outline-none flex-1 min-w-0"}),i.jsx("button",{onClick:()=>{D(1),ce({q:K||void 0,category:G||void 0,page:1})},className:"px-3 py-1.5 bg-brand-600 hover:bg-brand-500 text-white text-xs rounded-lg shrink-0",children:"Search"})]}),U?i.jsx("div",{className:"text-center text-fg-tertiary py-20",children:i.jsx("div",{className:"animate-pulse",children:n("skillStore.loadingSkillhub")})}):C.length===0?i.jsxs("div",{className:"text-center text-fg-tertiary py-20",children:[i.jsx("div",{className:"text-4xl mb-3 opacity-30",children:"◎"}),i.jsx("div",{children:n("skillStore.noSkillhub")})]}):i.jsxs(i.Fragment,{children:[i.jsx("div",{className:"text-xs text-fg-tertiary mb-3",children:n("skillStore.skillhubTotal",{count:E.toLocaleString()})}),i.jsx(Fa,{columns:3,children:C.map(q=>{const ae=x.some(Se=>Se.name===q.name||Se.name===q.slug);return i.jsx(vr,{type:"skill",name:q.name,description:q.description_zh??q.description??"",seed:q.slug,icon:tm(q.slug||q.name,q.tags?.[0]),version:q.version,authorLabel:"SkillHub",showTypeBadge:!1,tags:q.tags,installed:ae,hideStats:!0,onClick:()=>window.open(q.homepage,"_blank","noopener,noreferrer"),footerLeft:i.jsxs("span",{className:"flex items-center gap-2 text-[10px] text-fg-tertiary",children:[q.stars>0&&i.jsxs("span",{className:"text-amber-600",children:["★ ",q.stars.toLocaleString()]}),q.downloads>0&&i.jsxs("span",{children:[q.downloads>=1e4?`${(q.downloads/1e4).toFixed(1)}万`:q.downloads.toLocaleString()," ",n("skillStore.downloads")]})]}),actions:ae?void 0:i.jsx("button",{onClick:()=>{we(q)},disabled:h.has(q.name),className:"px-2.5 py-1 text-[10px] bg-brand-600 hover:bg-brand-500 text-white rounded-lg disabled:opacity-50",children:h.has(q.name)?"...":n("card.install")})},q.slug)})}),E>24&&i.jsxs("div",{className:"flex items-center justify-center gap-2 mt-6",children:[i.jsx("button",{disabled:L<=1,onClick:()=>{const q=L-1;D(q),ce({q:K||void 0,category:G||void 0,page:q})},className:"px-3 py-1.5 text-xs bg-surface-elevated text-fg-secondary rounded-lg hover:bg-surface-overlay disabled:opacity-30",children:n("skillStore.prevPage")}),i.jsx("span",{className:"text-xs text-fg-tertiary",children:n("skillStore.pageInfo",{current:L,total:Math.ceil(E/24)})}),i.jsx("button",{disabled:L>=Math.ceil(E/24),onClick:()=>{const q=L+1;D(q),ce({q:K||void 0,category:G||void 0,page:q})},className:"px-3 py-1.5 text-xs bg-surface-elevated text-fg-secondary rounded-lg hover:bg-surface-overlay disabled:opacity-30",children:n("skillStore.nextPage")})]})]})]}),c==="skillssh"&&i.jsxs("div",{className:`flex-1 overflow-y-auto ${l?"p-4":"p-6"}`,children:[i.jsxs("div",{className:`flex ${l?"flex-wrap":""} items-center gap-2 mb-5`,children:[i.jsx("input",{value:fe,onChange:q=>z(q.target.value),onKeyDown:q=>{q.key==="Enter"&&fe.trim()&&et(fe)},placeholder:n("skillStore.searchSkillssh"),className:`px-3 py-1.5 bg-surface-elevated border border-border-default rounded-lg text-sm text-fg-primary focus:border-brand-500 outline-none ${l?"flex-1 min-w-0":"w-72"}`}),i.jsx("button",{onClick:()=>{fe.trim()&&et(fe)},className:"px-3 py-1.5 bg-brand-600 hover:bg-brand-500 text-white text-xs rounded-lg shrink-0",children:"Search"}),!l&&i.jsx("span",{className:"text-xs text-fg-tertiary ml-auto",children:i.jsx("a",{href:"https://skills.sh",target:"_blank",rel:"noopener noreferrer",className:"text-brand-500 hover:text-brand-500",children:n("skillStore.visitSite")})})]}),je?i.jsx("div",{className:"text-center text-fg-tertiary py-20",children:i.jsx("div",{className:"animate-pulse",children:n("skillStore.loadingSkillssh")})}):se.length===0?i.jsxs("div",{className:"text-center text-fg-tertiary py-20",children:[i.jsx("div",{className:"text-4xl mb-3 opacity-30",children:"⬡"}),i.jsx("div",{children:n("skillStore.browseSkillssh")}),i.jsx("div",{className:"text-xs mt-1",children:n("skillStore.browseSkillsshHint")})]}):i.jsx(Fa,{columns:3,children:se.map(q=>{const ae=x.some(Se=>Se.name===q.name);return i.jsx(vr,{type:"skill",name:q.name,description:q.description||"",seed:`${q.author}-${q.name}`,icon:tm(q.name),authorLabel:`${q.author}/${q.repo}`,showTypeBadge:!1,installed:ae,hideStats:!0,cornerLabel:ae?void 0:"skills.sh",onClick:()=>window.open(q.url,"_blank","noopener,noreferrer"),footerLeft:q.installs?i.jsxs("span",{className:"text-[10px] text-fg-tertiary",children:[q.installs," installs"]}):void 0,actions:ae?void 0:i.jsx("button",{onClick:()=>{Me(q)},disabled:h.has(q.name),className:"px-2.5 py-1 text-[10px] bg-brand-600 hover:bg-brand-500 text-white rounded-lg disabled:opacity-50",children:h.has(q.name)?"...":n("card.install")})},`${q.author}-${q.name}`)})})]})]})}const iie=["agent","team","skill","connector"];function wh({title:e,subtitle:t,onMore:n,moreLabel:a}){return i.jsxs("div",{className:"flex items-end justify-between mb-3",children:[i.jsxs("div",{children:[i.jsx("h3",{className:"section-title",children:e}),t&&i.jsx("p",{className:"section-subtitle",children:t})]}),n&&i.jsxs("button",{className:"section-link",onClick:n,children:[a??"View all"," →"]})]})}function sie({item:e,onOpen:t}){const n=il(e.subtype==="connector"?"connector":e.itemType),a=xb(n,e.slug||e.name),s=Bs[n];return i.jsxs("button",{onClick:t,className:"group relative w-full overflow-hidden rounded-2xl text-left h-44 md:h-52",style:{background:a},children:[i.jsx("div",{className:"absolute inset-0 bg-gradient-to-r from-black/55 via-black/20 to-transparent"}),i.jsx("svg",{className:"absolute -right-8 -bottom-10 opacity-20",width:"220",height:"220",viewBox:"0 0 24 24",fill:"none","aria-hidden":!0,children:i.jsx("path",{d:"M12 2l2.4 6.9L21 9l-5.4 4 2 7-5.6-4.1L6.4 20l2-7L3 9l6.6-.1z",fill:"white"})}),i.jsxs("div",{className:"relative h-full flex flex-col justify-end p-5 md:p-6",children:[i.jsxs("span",{className:"inline-flex w-fit items-center gap-1 rounded-full bg-white/20 backdrop-blur px-2.5 py-0.5 text-[11px] font-semibold text-white mb-2",children:["★ Featured · ",s.label]}),i.jsx("h2",{className:"text-xl md:text-2xl font-bold text-white drop-shadow-sm",children:e.name}),i.jsx("p",{className:"text-sm text-white/85 truncate max-w-lg mt-1",children:e.description}),i.jsxs("div",{className:"flex items-center gap-3 mt-3 text-white/80 text-xs",children:[i.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[i.jsx(Om,{name:e.author?.displayName,username:e.author?.username,avatarUrl:e.author?.avatarUrl,hubBase:st.getUrl(),size:18}),e.author?.displayName||e.author?.username]}),i.jsxs("span",{children:["↓ ",$o(e.downloadCount)]}),(e.priceCents??0)>0?i.jsxs("span",{className:"badge-paid",children:["$",((e.priceCents??0)/100).toFixed(0)]}):i.jsx("span",{className:"badge-free",children:"Free"})]})]})]})}function Ck({items:e,onOpen:t}){return i.jsx(Fa,{columns:3,children:e.map(n=>i.jsx(vr,{type:n.subtype==="connector"?"connector":n.itemType,name:n.name,description:n.description,seed:n.slug||n.name,icon:n.icon,cover:n.thumbnailUrl,hubBase:st.getUrl(),author:n.author,category:n.category,tags:n.tags,rating:parseFloat(n.avgRating)||0,ratingCount:n.ratingCount,downloadCount:n.downloadCount,priceCents:n.priceCents,currency:n.currency,onClick:()=>t(n)},n.id))})}function Ak(){return i.jsx(Fa,{columns:3,children:Array.from({length:6}).map((e,t)=>i.jsx("div",{className:"h-64 rounded-2xl skeleton"},t))})}function oie({onOpenType:e}){const{t}=ot(["store","common"]),[n,a]=k.useState([]),[s,l]=k.useState(!0);k.useEffect(()=>{let g=!1;return(async()=>{l(!0);try{const x=await st.search({limit:60,sort:"popular"});g||a(x.items??[])}catch{g||a([])}finally{g||l(!1)}})(),()=>{g=!0}},[]);const c=k.useMemo(()=>{const g=n.filter(y=>y.featured);return(g.length>0?g:n).slice(0,3)},[n]),d=k.useMemo(()=>[...n].sort((g,x)=>(x.trendingScore??x.downloadCount)-(g.trendingScore??g.downloadCount)).slice(0,10),[n]),m=k.useMemo(()=>[...n].sort((g,x)=>(x.createdAt||"").localeCompare(g.createdAt||"")).slice(0,10),[n]),p=k.useMemo(()=>{const g=new Map;for(const x of n){const y=x.author?.username||x.author?.id;if(!y)continue;const w=g.get(y)??{author:x.author,downloads:0,count:0};w.downloads+=x.downloadCount||0,w.count+=1,g.set(y,w)}return[...g.values()].sort((x,y)=>y.downloads-x.downloads).slice(0,6)},[n]),h=g=>e(il(g.subtype==="connector"?"connector":g.itemType),g.id);return i.jsxs("div",{className:"flex-1 overflow-y-auto px-5 md:px-7 py-5 space-y-8",children:[i.jsxs("div",{className:"hero-glow rounded-2xl border border-border-subtle bg-surface-secondary p-5 md:p-6",children:[i.jsx("h1",{className:"text-2xl font-bold text-gradient tracking-tight",children:t("discover.title","Markus 广场")}),i.jsx("p",{className:"text-sm text-fg-tertiary mt-1 max-w-2xl",children:t("discover.subtitle","发现社区共享的智能体、AI 小队、技能与连接器 — 由创作者共建的开放生态。")}),i.jsx("div",{className:"flex flex-wrap gap-2 mt-4",children:iie.map(g=>i.jsxs("button",{onClick:()=>e(g),className:`inline-flex items-center gap-1.5 rounded-full px-3 py-1.5 text-xs font-medium text-white bg-gradient-to-r ${Bs[g].gradient} hover:opacity-90 transition-opacity`,children:[Bs[g].labelZh,i.jsx("span",{className:"opacity-70",children:Bs[g].label})]},g))})]}),s?i.jsx("div",{className:"h-52 rounded-2xl skeleton"}):c.length>0?i.jsx("div",{className:"grid grid-cols-1 lg:grid-cols-3 gap-4",children:c.map(g=>i.jsx(sie,{item:g,onOpen:()=>h(g)},g.id))}):null,i.jsxs("section",{children:[i.jsx(wh,{title:t("discover.trending","热门趋势"),subtitle:t("discover.trendingSub","社区中下载与评分增长最快的资产")}),s?i.jsx(Ak,{}):d.length>0?i.jsx(Ck,{items:d,onOpen:h}):i.jsx(lie,{})]}),i.jsxs("section",{children:[i.jsx(wh,{title:t("discover.fresh","新鲜上架"),subtitle:t("discover.freshSub","来自创作者的最新作品")}),s?i.jsx(Ak,{}):m.length>0?i.jsx(Ck,{items:m,onOpen:h}):null]}),p.length>0&&i.jsxs("section",{children:[i.jsx(wh,{title:t("discover.topCreators","顶尖创作者"),subtitle:t("discover.topCreatorsSub","生态贡献榜")}),i.jsx("div",{className:"grid grid-cols-2 md:grid-cols-3 lg:grid-cols-6 gap-3",children:p.map((g,x)=>i.jsxs("div",{className:"asset-card p-4 flex flex-col items-center text-center",children:[i.jsxs("div",{className:"relative",children:[i.jsx(Om,{name:g.author?.displayName,username:g.author?.username,avatarUrl:g.author?.avatarUrl,hubBase:st.getUrl(),size:48,verified:x<3}),x<3&&i.jsx("span",{className:"absolute -top-1 -left-1 w-5 h-5 rounded-full bg-amber-400 text-black text-[10px] font-bold flex items-center justify-center ring-2 ring-surface-secondary",children:x+1})]}),i.jsx("div",{className:"text-sm font-semibold text-fg-primary truncate w-full mt-2",children:g.author?.displayName||g.author?.username}),i.jsxs("div",{className:"text-[11px] text-fg-tertiary mt-0.5",children:[g.count," 作品 · ↓ ",$o(g.downloads)]})]},g.author?.username||x))})]})]})}function lie(){const{t:e}=ot(["store"]);return i.jsxs("div",{className:"text-center py-12 rounded-2xl border border-dashed border-border-default",children:[i.jsx("div",{className:"text-3xl mb-2 opacity-40",children:"✦"}),i.jsx("div",{className:"text-fg-secondary font-medium",children:e("discover.empty","生态正在成长中")}),i.jsx("div",{className:"text-fg-tertiary text-sm mt-1",children:e("discover.emptyHint","成为首批创作者,分享你的第一个资产")})]})}function Fd(e,t,n){return e.i18n?.[n]?.[t]}function cie(){const{t:e,i18n:t}=ot(["store","common"]),n=Xo(),a=t.language,[s,l]=k.useState([]),[c,d]=k.useState({}),[m,p]=k.useState(new Set),[h,g]=k.useState(null),[x,y]=k.useState(!0),[w,T]=k.useState(""),[C,S]=k.useState("all"),[E,_]=k.useState(null),L=k.useCallback(async()=>{y(!0);try{const[O,G,Q,$]=await Promise.all([Ae.builder.artifacts.list().catch(()=>({artifacts:[]})),Ae.builder.artifacts.installed().catch(()=>({installed:{}})),Ae.skills.updates().catch(()=>({updates:[],count:0})),Ae.skills.builtin().catch(()=>({skills:[]}))]),Y={};for(const U of Q.updates)Y[U.name]={availableVersion:U.availableVersion,installedVersion:U.installedVersion,displayName:U.displayName,description:U.description};d(Y);const K=O.artifacts.filter(U=>{const te=`${U.type}/${U.name}`;return!!G.installed[te]}),ee=new Set(K.filter(U=>U.type==="skill").map(U=>U.name));for(const U of $.skills)!U.installed||ee.has(U.name)||!(G.installed[`skill/${U.name}`]||Y[U.name])&&!U.updateAvailable||!G.installed[`skill/${U.name}`]&&!Y[U.name]||(K.push({type:"skill",name:U.name,meta:{displayName:U.i18n?.[a]?.displayName||U.name,description:U.i18n?.[a]?.description||U.description||"",version:U.installedVersion||U.version,author:U.author,category:U.category,tags:U.tags,i18n:U.i18n},path:"",updatedAt:""}),ee.add(U.name));for(const[U,te]of Object.entries(Y))ee.has(U)||(K.push({type:"skill",name:U,meta:{displayName:te.displayName||U,description:te.description||"",version:te.installedVersion},path:"",updatedAt:""}),ee.add(U));l(K)}catch{}y(!1)},[a]);k.useEffect(()=>{L()},[L]),k.useEffect(()=>{const O=()=>{L()};return window.addEventListener("markus:data-changed",O),()=>window.removeEventListener("markus:data-changed",O)},[L]),k.useEffect(()=>{if(!h)return;const O=setTimeout(()=>g(null),3e3);return()=>clearTimeout(O)},[h]);const D=async(O,G)=>{if(!m.has(O)){p(Q=>new Set(Q).add(O));try{await Ae.skills.install({name:O,source:"builtin"});try{localStorage.removeItem("markus:template-updates-ack")}catch{}g({text:e("installedTab.updateSuccess",{name:O,version:G}),type:"success"}),window.dispatchEvent(new CustomEvent("markus:data-changed")),await L()}catch{g({text:e("installedTab.updateFailed",{name:O}),type:"error"})}p(Q=>{const $=new Set(Q);return $.delete(O),$})}},M=s.filter(O=>{if(C!=="all"&&O.type!==C)return!1;if(!w)return!0;const G=w.toLowerCase(),Q=(Fd(O.meta,"displayName",a)||O.meta.displayName||O.name).toLowerCase(),$=(Fd(O.meta,"description",a)||O.meta.description||"").toLowerCase();return Q.includes(G)||$.includes(G)}).sort((O,G)=>{const Q=O.type==="skill"&&c[O.name]?1:0;return(G.type==="skill"&&c[G.name]?1:0)-Q});return E?i.jsx(qs,{type:E.type,name:E.name,onBack:()=>_(null)}):i.jsxs("div",{className:"flex-1 overflow-hidden flex flex-col",children:[i.jsxs("div",{"data-electron-drag":!0,className:`${n?"px-4":"px-6"} h-14 flex items-center shrink-0 gap-3`,children:[i.jsx("h2",{className:"text-lg font-semibold",children:e("installedTab.title")}),Object.keys(c).length>0&&i.jsxs("span",{className:"px-2 py-0.5 text-[11px] font-medium rounded-md bg-amber-500/15 text-amber-600 border border-amber-500/25",children:[e("installedTab.updateAvailable")," · ",Object.keys(c).length]})]}),i.jsxs("div",{className:`flex flex-wrap items-center gap-2 ${n?"px-4":"px-6"} py-2 shrink-0`,children:[i.jsx("div",{className:"flex gap-1",children:["all","agent","team","skill"].map(O=>i.jsx("button",{onClick:()=>S(O),className:`px-3 py-1 text-xs rounded-md transition-colors ${C===O?"bg-brand-600 text-white":"text-fg-secondary hover:text-fg-primary hover:bg-surface-elevated"}`,children:e(`installedTab.filter${O==="all"?"All":O==="agent"?"Agents":O==="team"?"Teams":"Skills"}`)},O))}),i.jsx("div",{className:"flex-1 min-w-[120px]",children:i.jsx("input",{type:"text",placeholder:e("installedTab.searchPlaceholder"),value:w,onChange:O=>T(O.target.value),className:"px-3 py-1.5 bg-surface-elevated border border-border-default rounded-lg text-sm w-full focus:border-brand-500 focus:outline-none"})})]}),i.jsx("div",{className:`flex-1 overflow-y-auto ${n?"p-4":"p-7"}`,children:x?i.jsx("div",{className:"text-center text-fg-tertiary py-20 animate-pulse",children:e("installedTab.loading")}):M.length===0?i.jsxs("div",{className:"text-center py-20",children:[i.jsx("div",{className:"text-4xl mb-4 opacity-30",children:"⧉"}),i.jsx("div",{className:"text-fg-secondary font-medium mb-1",children:e("installedTab.noItems")}),i.jsx("div",{className:"text-fg-tertiary text-sm",children:e("installedTab.noItemsHint")})]}):i.jsx(Fa,{columns:3,children:M.map(O=>{const G=Fd(O.meta,"displayName",a)||O.meta.displayName||O.name,Q=Fd(O.meta,"description",a)||O.meta.description||"",$=O.meta.version||"",Y=O.meta.author||"",K=O.meta.tags??[],ee=O.meta.category||"",U=O.meta.icon,te=U&&/\.(png|jpe?g|gif|webp|svg)$/i.test(U)&&!U.startsWith("http")&&!U.startsWith("data:")&&!U.startsWith("/")?`/api/builder/artifacts/${O.type}s/${encodeURIComponent(O.name)}/${U}`:U,I=O.type==="skill"?c[O.name]:void 0;return i.jsx(vr,{type:O.type,name:G,description:Q,seed:O.name,icon:te,author:null,authorLabel:Y||void 0,version:I?I.installedVersion:$,category:ee,tags:K,installed:!I,hideStats:!0,cornerLabel:I?e("installedTab.updateAvailable"):void 0,onClick:()=>{O.path&&_({type:O.type,name:O.name})},actions:I?i.jsx("button",{type:"button",disabled:m.has(O.name),onClick:()=>{D(O.name,I.availableVersion)},className:"px-3 py-1.5 text-xs font-medium bg-amber-600 hover:bg-amber-500 text-white rounded-lg disabled:opacity-50 transition-colors",children:m.has(O.name)?e("installedTab.updating"):e("installedTab.updateTo",{version:I.availableVersion})}):void 0},`${O.type}/${O.name}`)})})}),h&&i.jsx("div",{className:`fixed bottom-6 left-1/2 -translate-x-1/2 z-50 px-4 py-2 rounded-lg text-sm shadow-lg ${h.type==="success"?"bg-emerald-600 text-white":"bg-red-600 text-white"}`,children:h.text})]})}const uie=50,die=30;function mie(e,t,n,a){const s=k.useRef(0),l=k.useRef(0),c=k.useCallback(m=>{s.current=m.touches[0].clientX,l.current=m.touches[0].clientY},[]),d=k.useCallback(m=>{const p=m.changedTouches[0].clientX-s.current,h=m.changedTouches[0].clientY-l.current,g=Math.abs(p),x=Math.abs(h);if(g<uie||Math.atan2(x,g)*(180/Math.PI)>die)return;if(a?.scrollContainerRef?.current){const T=a.scrollContainerRef.current,C=T.scrollLeft<=1,S=T.scrollLeft+T.clientWidth>=T.scrollWidth-1;if(p>0&&!C||p<0&&!S)return}const w=e.findIndex(T=>T.id===t);p<0&&w<e.length-1?n(e[w+1].id):p>0&&w>0?n(e[w-1].id):p>0&&w===0&&a?.onSwipeOutLeft?a.onSwipeOutLeft():p<0&&w===e.length-1&&a?.onSwipeOutRight&&a.onSwipeOutRight()},[e,t,n,a]);return{onTouchStart:c,onTouchEnd:d}}const pie=["builder","discover","agents","teams","skills","installed"],fie={agent:"agents",team:"teams",skill:"skills",connector:"skills"};function Sg(e){return!!e&&pie.includes(e)}function Tk(){const e=localStorage.getItem("markus_nav_installItem"),t=localStorage.getItem("markus_nav_storeTab");return{tab:Sg(t)?t:"builder",installId:e}}function hie({authUser:e}){const{t}=ot(["nav","store","common"]),n=k.useMemo(()=>[{id:"builder",label:t("nav:tabs.create")},{id:"discover",label:t("nav:tabs.discover")},{id:"agents",label:t("nav:tabs.agents")},{id:"teams",label:t("nav:tabs.teams")},{id:"skills",label:t("nav:tabs.skills")},{id:"installed",label:t("nav:tabs.installed")}],[t]),[a]=k.useState(Tk),[s,l]=k.useState(a.tab),[c,d]=k.useState(a.installId),m=mie(n,s,l);k.useEffect(()=>{const h=Tk();h.installId&&(d(h.installId),Sg(h.tab)&&l(h.tab),localStorage.removeItem("markus_nav_installItem"),localStorage.removeItem("markus_nav_storeTab"))},[]),k.useEffect(()=>{const h=g=>{const x=g.detail,y=x.params?.storeTab??localStorage.getItem("markus_nav_storeTab");Sg(y)&&l(y);const w=x.params?.installItem??localStorage.getItem("markus_nav_installItem");w&&d(w),localStorage.removeItem("markus_nav_storeTab"),localStorage.removeItem("markus_nav_installItem")};return window.addEventListener("markus:navigate",h),()=>window.removeEventListener("markus:navigate",h)},[]);const p=(h,g)=>{g&&d(g),l(fie[h]??"agents")};return i.jsxs("div",{className:"flex-1 overflow-hidden flex flex-col",onTouchStart:m.onTouchStart,onTouchEnd:m.onTouchEnd,children:[i.jsxs("div",{className:"flex items-center shrink-0 overflow-x-auto scrollbar-hide",children:[i.jsx(g4,{className:"ml-2"}),n.map(h=>i.jsx("button",{onClick:()=>l(h.id),className:`flex-1 min-w-fit px-3 py-2.5 text-xs font-medium text-center whitespace-nowrap transition-colors border-b-2 ${s===h.id?"border-brand-500 text-brand-500":"border-transparent text-fg-tertiary"}`,children:h.label},h.id))]}),i.jsxs("div",{className:"flex-1 overflow-hidden flex flex-col",children:[s==="builder"&&i.jsx(s6,{authUser:e}),s==="discover"&&i.jsx(oie,{onOpenType:p}),s==="agents"&&i.jsx(Xre,{authUser:e,highlightItemId:c,onHighlightDone:()=>d(null)}),s==="teams"&&i.jsx(eie,{highlightItemId:c,onHighlightDone:()=>d(null)}),s==="skills"&&i.jsx(rie,{highlightItemId:c,onHighlightDone:()=>d(null)}),s==="installed"&&i.jsx(cie,{})]})]})}const Nk="usageType",kh="profile";function gie({onComplete:e,theme:t,onThemeChange:n,skipProfile:a,onProfileUpdated:s}){const{t:l}=ot(["onboarding","common"]),[c,d]=k.useState(0),[m,p]=k.useState(""),[h,g]=k.useState(""),[x,y]=k.useState(""),[w,T]=k.useState(""),[C,S]=k.useState(!1),[E,_]=k.useState(""),[L,D]=k.useState(!1),[M,O]=k.useState(null);k.useEffect(()=>{Ae.auth.me().then(({user:$e})=>{$e.name&&p($e.name),$e.email&&g($e.email),$e.avatarUrl&&O($e.avatarUrl);const mt=$e.name||$e.email?.split("@")[0]||"";mt&&Y(At=>At||l("usageType.defaultOrgName",{name:mt}))}).catch(()=>{}),Ae.settings.getOrg().then(({org:$e})=>{$e?.name&&$e.name!=="My Organization"&&Y($e.name)}).catch(()=>{}),jn()&&Ae.hubOrgs.invitations().then($e=>{$e.invitations?.length>0&&Ce($e.invitations)}).catch(()=>{})},[]);const[G,Q]=k.useState(null),[$,Y]=k.useState(""),[K,ee]=k.useState(!1),[U,te]=k.useState(!1),[I,J]=k.useState(""),[me,Ce]=k.useState([]),[H,V]=k.useState(null),[fe,z]=k.useState(null),je=async()=>{const $e=$.trim();if($e){ee(!0),J("");try{if(await Ae.settings.updateOrg($e),jn()){const mt=await Ae.hubOrgs.mine(),At=mt.orgs?.find(Dt=>Dt.role==="owner")??mt.orgs?.[0];At?.id?await Ae.hubOrgs.update(At.id,{name:$e}):await Ae.hubOrgs.create($e)}te(!0)}catch{J(l("usageType.orgNameSaveFailed"))}finally{ee(!1)}}},[Ue,qe]=k.useState(!0),He=async()=>{if(_(""),!m.trim()){_(l("profile.errors.nameRequired"));return}if(!h.trim()){_(l("profile.errors.emailRequired"));return}if(!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(h.trim())){_(l("profile.errors.emailInvalid"));return}if(x&&x.length<6){_(l("profile.errors.passwordTooShort"));return}if(x&&x!==w){_(l("profile.errors.passwordMismatch"));return}S(!0);try{const{user:$e}=await Ae.auth.updateProfile(m.trim(),h.trim());x&&await Ae.auth.changePassword("",x),s?.($e),D(!0)}catch{_(l("profile.errors.saveFailed"))}finally{S(!1)}},ut=[{value:"system",label:l("theme.system"),icon:"💻",desc:l("theme.systemDesc")},{value:"light",label:l("theme.light"),icon:"☀️",desc:l("theme.lightDesc")},{value:"dark",label:l("theme.dark"),icon:"🌊",desc:l("theme.darkDesc")},{value:"cyberpunk",label:l("theme.cyberpunk"),icon:"🔮",desc:l("theme.cyberpunkDesc")},{value:"mono",label:l("theme.mono"),icon:"⬛",desc:l("theme.monoDesc")}],dt=[{id:"welcome",title:l("welcome.title"),subtitle:l("welcome.subtitle"),content:i.jsx("p",{className:"text-fg-secondary text-sm leading-relaxed",children:i.jsx(pT,{i18nKey:"welcome.description",ns:"onboarding",components:{strong:i.jsx("strong",{className:"text-fg-primary"})}})})},{id:Nk,title:l("usageType.title",{defaultValue:"How will you use Markus?"}),subtitle:l("usageType.subtitle",{defaultValue:"This helps us tailor your experience."}),content:i.jsxs("div",{className:"space-y-4",children:[i.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[i.jsxs("button",{onClick:()=>{Q("personal"),te(!0)},className:`flex flex-col items-center gap-3 rounded-xl border-2 p-5 transition-all text-left ${G==="personal"?"border-brand-500 bg-brand-500/10":"border-border-default hover:border-fg-tertiary bg-surface-elevated/30"}`,children:[i.jsx("span",{className:"text-2xl",children:"👤"}),i.jsxs("div",{children:[i.jsx("div",{className:"font-medium text-fg-primary text-sm text-center",children:l("usageType.personal",{defaultValue:"Personal"})}),i.jsx("div",{className:"text-[11px] text-fg-tertiary mt-1 text-center",children:l("usageType.personalDesc",{defaultValue:"Individual use with your own AI agents."})})]})]}),i.jsxs("button",{onClick:()=>{Q("organization"),te(!1)},className:`flex flex-col items-center gap-3 rounded-xl border-2 p-5 transition-all text-left ${G==="organization"?"border-brand-500 bg-brand-500/10":"border-border-default hover:border-fg-tertiary bg-surface-elevated/30"}`,children:[i.jsx("span",{className:"text-2xl",children:"🏢"}),i.jsxs("div",{children:[i.jsx("div",{className:"font-medium text-fg-primary text-sm text-center",children:l("usageType.organization",{defaultValue:"Team & Enterprise"})}),i.jsx("div",{className:"text-[11px] text-fg-tertiary mt-1 text-center",children:l("usageType.organizationDesc",{defaultValue:"For teams sharing licenses and collaborating."})})]})]})]}),G==="organization"&&i.jsxs("div",{className:"space-y-4 mt-4",children:[me.length>0&&i.jsxs("div",{className:"space-y-2",children:[i.jsx("div",{className:"text-xs text-fg-tertiary font-medium",children:l("usageType.pendingInvitations")}),me.map($e=>i.jsxs("div",{className:"flex items-center justify-between px-4 py-3 rounded-xl border border-amber-500/20 bg-amber-500/5",children:[i.jsxs("div",{children:[i.jsx("div",{className:"text-sm font-medium text-fg-primary",children:$e.orgName}),i.jsx("div",{className:"text-[11px] text-fg-tertiary",children:l("usageType.invitedBy",{name:$e.invitedBy})})]}),i.jsx("button",{onClick:async()=>{V($e.orgId);try{await Ae.hubOrgs.acceptInvitation($e.orgId),z($e.orgId),te(!0)}catch{}finally{V(null)}},disabled:H===$e.orgId||fe===$e.orgId,className:"px-3 py-1.5 text-xs rounded-lg bg-brand-600 hover:bg-brand-500 disabled:opacity-40 text-white transition-colors",children:fe===$e.orgId?l("usageType.accepted"):H===$e.orgId?l("usageType.accepting"):l("usageType.acceptAndJoin")})]},$e.orgId)),i.jsx("div",{className:"text-[11px] text-fg-tertiary text-center pt-1",children:l("usageType.orCreateNew")})]}),i.jsxs("div",{className:"space-y-1",children:[i.jsx("label",{className:"text-xs text-fg-tertiary font-medium",children:l("usageType.orgNameLabel")}),i.jsx("input",{type:"text",value:$,onChange:$e=>{Y($e.target.value),te(!1),J("")},placeholder:l("usageType.orgNamePlaceholder"),className:"w-full px-4 py-2.5 bg-surface-elevated border border-border-default rounded-xl text-sm text-fg-primary focus:border-brand-500 outline-none transition-colors"})]}),I&&i.jsx("p",{className:"text-xs text-red-500",children:I}),i.jsx("button",{onClick:()=>{je()},disabled:K||!$.trim()||U,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:l(K?"common:saving":U?"usageType.orgNameSaved":"usageType.setOrgName")})]})]})},{id:kh,title:l("profile.title"),subtitle:l("profile.subtitle"),content:L?i.jsxs("div",{className:"flex items-center gap-3 bg-green-500/10 border border-green-500/30 rounded-xl p-4",children:[i.jsx("span",{className:"text-green-600 text-lg",children:"✓"}),i.jsxs("div",{children:[i.jsx("div",{className:"text-sm font-medium text-green-600",children:l("profile.saved")}),i.jsxs("div",{className:"text-xs text-fg-secondary mt-0.5",children:[m," · ",h]})]})]}):i.jsxs("div",{className:"space-y-4",children:[i.jsx("div",{className:"flex justify-center",children:i.jsx(f4,{currentUrl:M,name:m,size:64,targetType:"user"})}),i.jsxs("div",{className:"space-y-1",children:[i.jsxs("label",{className:"text-xs text-fg-tertiary font-medium",children:[l("profile.nameLabel")," ",i.jsx("span",{className:"text-red-500",children:"*"})]}),i.jsx("input",{type:"text",value:m,onChange:$e=>p($e.target.value),placeholder:l("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})]}),i.jsxs("div",{className:"space-y-1",children:[i.jsxs("label",{className:"text-xs text-fg-tertiary font-medium",children:[l("profile.emailLabel")," ",i.jsx("span",{className:"text-red-500",children:"*"})]}),i.jsx("input",{type:"email",value:h,onChange:$e=>g($e.target.value),placeholder:l("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"})]}),i.jsxs("div",{className:"space-y-1",children:[i.jsx("label",{className:"text-xs text-fg-tertiary font-medium",children:l("profile.newPasswordLabel")}),i.jsx("input",{type:"password",value:x,onChange:$e=>y($e.target.value),placeholder:l("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"})]}),x&&i.jsxs("div",{className:"space-y-1",children:[i.jsx("label",{className:"text-xs text-fg-tertiary font-medium",children:l("profile.confirmPasswordLabel")}),i.jsx("input",{type:"password",value:w,onChange:$e=>T($e.target.value),placeholder:l("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"})]}),E&&i.jsx("div",{className:"px-3 py-2 bg-red-500/10 border border-red-500/30 rounded-lg text-xs text-red-500",children:E}),i.jsx("button",{onClick:()=>{He()},disabled:C||!m.trim()||!h.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:l(C?"common:saving":"profile.saveProfile")})]})},{id:"theme",title:l("theme.title"),subtitle:l("theme.subtitle"),content:i.jsxs("div",{className:"space-y-4",children:[i.jsx("div",{className:"grid grid-cols-3 gap-3",children:ut.map($e=>i.jsxs("button",{onClick:()=>n($e.value),className:`flex flex-col items-center gap-2 rounded-xl border-2 p-5 transition-all ${t===$e.value?"border-brand-500 bg-brand-500/10":"border-border-default hover:border-fg-tertiary bg-surface-elevated/30"}`,children:[i.jsx("span",{className:"text-2xl",children:$e.icon}),i.jsx("span",{className:"text-sm font-medium text-fg-primary",children:$e.label}),i.jsx("span",{className:"text-[11px] text-fg-tertiary leading-tight text-center",children:$e.desc})]},$e.value))}),i.jsxs("label",{className:"flex items-center gap-2.5 p-3 bg-surface-elevated/30 rounded-lg cursor-pointer group",children:[i.jsx("input",{type:"checkbox",checked:Ue,onChange:$e=>qe($e.target.checked),className:"accent-brand-500 shrink-0"}),i.jsx("span",{className:"text-[11px] text-fg-tertiary",children:l("done.telemetry")})]})]})}],Nt=a?dt.filter($e=>$e.id!==kh):dt,wt=Nt.findIndex($e=>$e.id===Nk),Zt=Nt.findIndex($e=>$e.id===kh),Wt=()=>{c===wt&&wt>=0&&!G||c===wt&&G==="organization"&&!U||c===Zt&&Zt>=0&&!L||(c<Nt.length-1?d(c+1):(fetch("/api/settings/telemetry",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({enabled:Ue})}).catch(()=>{}),e()))},rt=Nt[c];return i.jsx("div",{className:"min-h-dvh bg-surface-primary flex items-center justify-center p-4",children:i.jsx("div",{className:"w-full max-w-lg",children:i.jsxs("div",{className:"bg-surface-elevated rounded-2xl p-8",children:[i.jsx("div",{className:"flex gap-1.5 mb-8",children:Nt.map(($e,mt)=>i.jsx("div",{className:`h-1 flex-1 rounded-full transition-colors ${mt<=c?"bg-brand-500":"bg-surface-elevated"}`},mt))}),i.jsx("h2",{className:"text-2xl font-bold text-fg-primary",children:rt.title}),i.jsx("p",{className:"text-sm text-fg-secondary mt-1 mb-6",children:rt.subtitle}),rt.content,i.jsxs("div",{className:"flex justify-between mt-8",children:[c>0?i.jsx("button",{onClick:()=>d(c-1),className:"px-4 py-2 text-sm text-fg-secondary hover:text-fg-primary transition-colors",children:l("common:back")}):i.jsx("span",{}),i.jsx("button",{onClick:Wt,disabled:Zt>=0&&c===Zt&&!L||wt>=0&&c===wt&&(!G||G==="organization"&&!U),className:`px-6 py-2.5 text-white text-sm rounded-xl transition-colors ${Zt>=0&&c===Zt&&!L||wt>=0&&c===wt&&(!G||G==="organization"&&!U)?"bg-brand-600/40 cursor-not-allowed":"bg-brand-600 hover:bg-brand-500"}`,children:c===Nt.length-1?l("getStarted"):l("common:next")})]})]})})})}const Ek="markus:legal-consent",bie="https://markus.global";function yie({onLogin:e,hasOwner:t}){const{t:n,i18n:a}=ot("auth"),[s,l]=k.useState(null),[c,d]=k.useState(""),[m,p]=k.useState(!1),[h,g]=k.useState(""),[x,y]=k.useState(""),[w,T]=k.useState(!1),[C,S]=k.useState(!1),E=Y=>{const K=(a.language||"").toLowerCase().startsWith("zh")?"?lang=zh":"";return`${bie}${Y}${K}`},_=()=>{try{localStorage.setItem(Ek,JSON.stringify({acceptedAt:new Date().toISOString(),terms:!0,privacy:!0}))}catch{}},L=()=>C?(_(),!0):(T(!1),requestAnimationFrame(()=>T(!0)),!1),D=async()=>{const Y=jn(),K=xr();if(!Y||!K){d(n("login.hubUnavailable"));return}const ee=await Ae.auth.hubLogin(Y,K);if(window.markusDesktop?.clearPendingDeepLinkAuth?.(),ee.cloudAiReady===!1)try{sessionStorage.setItem("markus:cloud-ai-warning",ee.cloudAiError?n("login.cloudAiNotReady",{error:ee.cloudAiError}):n("login.cloudAiNotReadyGeneric"))}catch{}e(ee.user,ee.needsOnboarding??!1,{fromHub:!0})},M=async(Y,K=!1)=>{if(!(!K&&!L())){d(""),l(Y??"hub");try{if(K&&jn()&&xr()){await D();return}await Ha({method:Y,force:!0}),await D()}catch(ee){const U=ee instanceof Error?ee.message:"";if(!U.includes("cancelled")){if(!K&&jn())return M(Y,!0);d(U||n("login.hubUnavailable"))}}finally{l(null)}}},O=()=>{hU(),l(null),d("")};k.useEffect(()=>{const Y=window.markusDesktop;if(!Y?.peekPendingDeepLinkAuth&&!Y?.consumePendingDeepLinkAuth)return;let K=!1;return(async()=>{const ee=Y.peekPendingDeepLinkAuth?await Y.peekPendingDeepLinkAuth():null;if(K||!ee)return;let U=!1;try{U=!!localStorage.getItem(Ek)}catch{}if(!C&&!U){d(n("login.consentRequired"));return}U&&!C&&S(!0),_();const te=Y.consumePendingDeepLinkAuth?await Y.consumePendingDeepLinkAuth():ee;if(!(K||!te)){d(""),l("hub");try{if(!await fU(te)||!jn()||!xr()){d(n("login.hubUnavailable"));return}await D()}catch{d(n("login.hubUnavailable"))}finally{K||l(null)}}})().catch(()=>{}),()=>{K=!0}},[C]);const G=async Y=>{if(Y.preventDefault(),!(!h.trim()||!x)&&L()){d(""),l("local");try{const{user:K,needsOnboarding:ee}=await Ae.auth.login(h.trim(),x);e(K,ee??!1)}catch{d(n("login.invalidCredentials"))}finally{l(null)}}},Q=n(t?"login.welcomeBack":"login.getStarted"),$="w-full flex items-center justify-center gap-3 h-11 px-4 bg-surface-elevated border border-border-default rounded-xl text-sm text-fg-primary font-medium transition-all hover:border-brand-400/60 hover:shadow-sm active:scale-[0.99] disabled:opacity-50 disabled:pointer-events-none";return i.jsxs("div",{className:"min-h-dvh bg-surface-primary flex flex-col items-center justify-center p-4 relative overflow-hidden",children:[i.jsxs("div",{className:"pointer-events-none absolute inset-0 overflow-hidden",children:[i.jsx("div",{className:"absolute -top-48 left-1/2 -translate-x-1/2 h-[42rem] w-[42rem] rounded-full bg-brand-500/20 blur-[120px]"}),i.jsx("div",{className:"absolute top-1/4 -left-40 h-[26rem] w-[26rem] rounded-full bg-brand-400/10 blur-[100px]"}),i.jsx("div",{className:"absolute -bottom-40 -right-32 h-[34rem] w-[34rem] rounded-full bg-brand-600/10 blur-[110px]"})]}),i.jsxs("div",{className:"w-full max-w-[26rem] relative z-10 flex-1 flex flex-col justify-center",children:[i.jsxs("div",{className:"text-center mb-8",children:[i.jsx("img",{src:"/logo.png",alt:"Markus",className:"w-16 h-16 mx-auto mb-4 rounded-2xl shadow-xl shadow-brand-900/20 ring-1 ring-border-default/40"}),i.jsx("div",{className:"text-[1.75rem] leading-none font-extrabold tracking-tight text-fg-primary mb-2",children:"Markus"}),i.jsx("div",{className:"text-sm text-fg-tertiary",children:Q})]}),i.jsx("div",{className:"bg-surface-secondary/70 backdrop-blur-xl border border-border-default/80 rounded-3xl p-7 sm:p-8 shadow-2xl shadow-black/10",children:m?i.jsxs("div",{className:"space-y-4",children:[i.jsxs("div",{children:[i.jsx("div",{className:"text-base font-semibold text-fg-primary",children:n("login.localTitle")}),i.jsx("div",{className:"text-xs text-fg-tertiary mt-0.5",children:n("login.localAccountHint")})]}),i.jsxs("form",{onSubmit:G,className:"space-y-3",children:[i.jsx("input",{type:"email",value:h,onChange:Y=>g(Y.target.value),autoComplete:"email",autoFocus:!0,placeholder:n("login.email"),className:"w-full px-4 h-11 bg-surface-elevated border border-border-default rounded-xl text-sm text-fg-primary focus:border-brand-500 focus:ring-2 focus:ring-brand-500/20 outline-none transition-all placeholder:text-fg-tertiary",required:!0}),i.jsx("input",{type:"password",value:x,onChange:Y=>y(Y.target.value),autoComplete:"current-password",placeholder:n("login.password"),className:"w-full px-4 h-11 bg-surface-elevated border border-border-default rounded-xl text-sm text-fg-primary focus:border-brand-500 focus:ring-2 focus:ring-brand-500/20 outline-none transition-all placeholder:text-fg-tertiary",required:!0}),c&&i.jsx("div",{className:"px-3 py-2 bg-red-500/10 border border-red-500/30 rounded-lg text-xs text-red-500",children:c}),!t&&i.jsx("p",{className:"text-[11px] text-fg-tertiary",children:n("login.defaultCredentials")}),i.jsx("button",{type:"submit",disabled:s==="local"||!h||!x,className:"w-full h-11 bg-brand-600 hover:bg-brand-500 disabled:opacity-50 text-white text-sm font-semibold rounded-xl transition-all shadow-md shadow-brand-900/30 hover:shadow-lg active:scale-[0.99]",children:n(s==="local"?"login.signingIn":"login.signIn")})]}),i.jsx("div",{className:"text-center",children:i.jsx("button",{onClick:()=>{p(!1),d("")},className:"text-xs text-fg-tertiary hover:text-fg-secondary transition-colors",children:n("login.backToHub")})})]}):i.jsxs("div",{className:"space-y-3",children:[i.jsxs("button",{onClick:()=>M("google"),disabled:!!s,className:$,children:[i.jsxs("svg",{className:"w-5 h-5",viewBox:"0 0 24 24",children:[i.jsx("path",{fill:"#4285F4",d:"M22.56 12.25c0-.78-.07-1.53-.2-2.25H12v4.26h5.92a5.06 5.06 0 01-2.2 3.32v2.77h3.57c2.08-1.92 3.28-4.74 3.28-8.1z"}),i.jsx("path",{fill:"#34A853",d:"M12 23c2.97 0 5.46-.98 7.28-2.66l-3.57-2.77c-.98.66-2.23 1.06-3.71 1.06-2.86 0-5.29-1.93-6.16-4.53H2.18v2.84C3.99 20.53 7.7 23 12 23z"}),i.jsx("path",{fill:"#FBBC05",d:"M5.84 14.09c-.22-.66-.35-1.36-.35-2.09s.13-1.43.35-2.09V7.07H2.18C1.43 8.55 1 10.22 1 12s.43 3.45 1.18 4.93l2.85-2.22.81-.62z"}),i.jsx("path",{fill:"#EA4335",d:"M12 5.38c1.62 0 3.06.56 4.21 1.64l3.15-3.15C17.45 2.09 14.97 1 12 1 7.7 1 3.99 3.47 2.18 7.07l3.66 2.84c.87-2.6 3.3-4.53 6.16-4.53z"})]}),n(s==="google"?"login.connectingHub":"login.withGoogle")]}),i.jsxs("button",{onClick:()=>M("github"),disabled:!!s,className:$,children:[i.jsx("svg",{className:"w-5 h-5",viewBox:"0 0 24 24",fill:"currentColor",children:i.jsx("path",{d:"M12 0C5.37 0 0 5.37 0 12c0 5.31 3.435 9.795 8.205 11.385.6.105.825-.255.825-.57 0-.285-.015-1.23-.015-2.235-3.015.555-3.795-.735-4.035-1.41-.135-.345-.72-1.41-1.23-1.695-.42-.225-1.02-.78-.015-.795.945-.015 1.62.87 1.845 1.23 1.08 1.815 2.805 1.305 3.495.99.105-.78.42-1.305.765-1.605-2.67-.3-5.46-1.335-5.46-5.925 0-1.305.465-2.385 1.23-3.225-.12-.3-.54-1.53.12-3.18 0 0 1.005-.315 3.3 1.23.96-.27 1.98-.405 3-.405s2.04.135 3 .405c2.295-1.56 3.3-1.23 3.3-1.23.66 1.65.24 2.88.12 3.18.765.84 1.23 1.905 1.23 3.225 0 4.605-2.805 5.625-5.475 5.925.435.375.81 1.095.81 2.22 0 1.605-.015 2.895-.015 3.3 0 .315.225.69.825.57A12.02 12.02 0 0024 12c0-6.63-5.37-12-12-12z"})}),n(s==="github"?"login.connectingHub":"login.withGithub")]}),i.jsxs("button",{onClick:()=>M("email"),disabled:!!s,className:$,children:[i.jsx("svg",{className:"w-5 h-5",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:1.5,children:i.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M21.75 6.75v10.5a2.25 2.25 0 01-2.25 2.25h-15a2.25 2.25 0 01-2.25-2.25V6.75m19.5 0A2.25 2.25 0 0019.5 4.5h-15a2.25 2.25 0 00-2.25 2.25m19.5 0v.243a2.25 2.25 0 01-1.07 1.916l-7.5 4.615a2.25 2.25 0 01-2.36 0L3.32 8.91a2.25 2.25 0 01-1.07-1.916V6.75"})}),n(s==="email"?"login.connectingHub":"login.withEmail")]}),s&&(s==="google"||s==="github"||s==="email"||s==="hub")&&i.jsxs("div",{className:"px-3 py-2.5 bg-brand-500/10 border border-brand-500/30 rounded-lg text-xs text-fg-secondary space-y-2",children:[i.jsx("p",{children:n("login.browserOpened")}),i.jsx("button",{type:"button",onClick:O,className:"text-brand-500 hover:text-brand-400 underline font-medium",children:n("login.cancelWaiting")})]}),c&&i.jsx("div",{className:"px-3 py-2 bg-red-500/10 border border-red-500/30 rounded-lg text-xs text-red-500",children:c}),i.jsxs("div",{className:"flex items-center gap-3 py-1 text-[11px] text-fg-tertiary",children:[i.jsx("span",{className:"h-px flex-1 bg-border-default"}),n("login.or"),i.jsx("span",{className:"h-px flex-1 bg-border-default"})]}),i.jsx("button",{onClick:()=>{p(!0),d("")},disabled:!!s,className:"w-full h-11 px-4 rounded-xl text-sm text-fg-secondary font-medium transition-all hover:bg-surface-elevated/70 disabled:opacity-50",children:n("login.useLocalAccount")})]})}),i.jsxs("label",{onAnimationEnd:()=>T(!1),className:`mt-5 flex items-start justify-center gap-2 text-[11px] leading-relaxed cursor-pointer select-none px-2 transition-colors ${w?"animate-shake text-fg-primary font-medium":"text-fg-tertiary"}`,children:[i.jsx("input",{type:"checkbox",checked:C,onChange:Y=>{S(Y.target.checked),Y.target.checked&&T(!1)},className:"mt-0.5 h-3.5 w-3.5 shrink-0 accent-brand-600 cursor-pointer"}),i.jsxs("span",{className:"text-center",children:[n("login.consentPrefix")," ",i.jsx("a",{href:E("/terms"),target:"_blank",rel:"noopener noreferrer",className:"text-brand-500 hover:text-brand-400 underline",children:n("login.termsLink")})," ",n("login.consentAnd")," ",i.jsx("a",{href:E("/privacy"),target:"_blank",rel:"noopener noreferrer",className:"text-brand-500 hover:text-brand-400 underline",children:n("login.privacyLink")})]})]})]}),i.jsxs("div",{className:"relative z-10 flex flex-wrap items-center justify-center gap-x-5 gap-y-1 py-6 text-[11px] text-fg-tertiary",children:[i.jsx("a",{href:"https://markus.global",target:"_blank",rel:"noopener noreferrer",className:"hover:text-fg-secondary transition-colors",children:"markus.global"}),i.jsx("a",{href:"mailto:business@markus.global",className:"hover:text-fg-secondary transition-colors",children:n("login.contactSales")})]})]})}function xie({token:e,onComplete:t}){const{t:n}=ot("auth"),[a,s]=k.useState(null),[l,c]=k.useState(""),[d,m]=k.useState(""),[p,h]=k.useState(""),[g,x]=k.useState(!1),[y,w]=k.useState(!1),[T,C]=k.useState(!1);k.useEffect(()=>{Ae.auth.inviteInfo(e).then(E=>s(E)).catch(()=>C(!0))},[e]);const S=async E=>{if(E.preventDefault(),h(""),l.length<6){h(n("invite.passwordMinLength"));return}if(l!==d){h(n("invite.passwordsDoNotMatch"));return}x(!0);try{await Ae.auth.setup(e,l),w(!0),setTimeout(()=>{window.location.hash="",t()},2e3)}catch{h(n("invite.error"))}finally{x(!1)}};return i.jsxs("div",{className:"min-h-dvh bg-surface-primary flex items-center justify-center p-4 relative overflow-hidden",children:[i.jsx("div",{className:"absolute inset-0 bg-[radial-gradient(ellipse_at_top,_var(--tw-gradient-stops))] from-brand-950/50 via-transparent to-transparent"}),i.jsxs("div",{className:"w-full max-w-sm relative z-10",children:[i.jsxs("div",{className:"text-center mb-8",children:[i.jsx("img",{src:"/logo.png",alt:"Markus",className:"w-14 h-14 mx-auto mb-3 rounded-xl shadow-lg shadow-black/40"}),i.jsx("div",{className:"text-2xl font-extrabold tracking-tight text-fg-primary mb-1",children:"Markus"}),i.jsx("div",{className:"text-sm text-fg-tertiary",children:n("invite.subtitle")})]}),i.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:T?i.jsxs("div",{className:"text-center space-y-3",children:[i.jsx("div",{className:"text-red-500 text-3xl",children:"⚠"}),i.jsx("p",{className:"text-sm text-fg-secondary",children:n("invite.invalidLink")}),i.jsx("button",{onClick:()=>{window.location.hash="",t()},className:"text-sm text-brand-500 hover:text-brand-400",children:n("login.signIn")})]}):y?i.jsxs("div",{className:"text-center space-y-3",children:[i.jsx("div",{className:"text-green-500 text-3xl",children:"✓"}),i.jsx("p",{className:"text-sm text-fg-secondary",children:n("invite.setupComplete")})]}):a?i.jsxs("form",{onSubmit:S,className:"space-y-5",children:[i.jsx("h2",{className:"text-lg font-semibold text-fg-primary text-center",children:n("invite.greeting",{name:a.name})}),i.jsx("p",{className:"text-xs text-fg-tertiary text-center",children:a.email}),i.jsxs("div",{className:"space-y-1",children:[i.jsx("label",{className:"text-xs text-fg-tertiary font-medium",children:n("invite.setPassword")}),i.jsx("input",{type:"password",value:l,onChange:E=>c(E.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})]}),i.jsxs("div",{className:"space-y-1",children:[i.jsx("label",{className:"text-xs text-fg-tertiary font-medium",children:n("invite.confirmPassword")}),i.jsx("input",{type:"password",value:d,onChange:E=>m(E.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})]}),p&&i.jsx("div",{className:"px-3 py-2 bg-red-500/10 border border-red-500/30 rounded-lg text-xs text-red-500",children:p}),i.jsx("button",{type:"submit",disabled:g||!l||!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:n(g?"invite.settingUp":"invite.setupAccount")})]}):i.jsx("div",{className:"text-center text-fg-tertiary text-sm animate-pulse py-4",children:"Loading…"})})]})]})}function vie({onComplete:e,isFirstTime:t}){const{t:n}=ot("auth"),[a,s]=k.useState(""),[l,c]=k.useState(""),[d,m]=k.useState(""),[p,h]=k.useState(""),[g,x]=k.useState(!1),y=async w=>{if(w.preventDefault(),h(""),l.length<6){h(n("changePassword.passwordMinLength"));return}if(l!==d){h(n("changePassword.passwordsDoNotMatch"));return}x(!0);try{await Ae.auth.changePassword(a,l),e()}catch{h(n("changePassword.failedToChange"))}finally{x(!1)}};return i.jsxs("div",{className:"min-h-dvh bg-surface-primary flex items-center justify-center p-4 relative overflow-hidden",children:[i.jsx("div",{className:"absolute inset-0 bg-[radial-gradient(ellipse_at_top,_var(--tw-gradient-stops))] from-brand-950/50 via-transparent to-transparent"}),i.jsxs("div",{className:"w-full max-w-sm relative z-10",children:[i.jsxs("div",{className:"text-center mb-8",children:[i.jsx("img",{src:"/logo.png",alt:"Markus",className:"w-14 h-14 mx-auto mb-3 rounded-xl shadow-lg shadow-black/40"}),i.jsx("div",{className:"text-2xl font-extrabold tracking-tight text-fg-primary mb-1",children:"Markus"}),i.jsx("div",{className:"text-sm text-fg-tertiary",children:n("login.subtitle")})]}),i.jsxs("form",{onSubmit:y,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:[i.jsxs("div",{children:[i.jsx("h2",{className:"text-lg font-semibold text-fg-primary text-center",children:n(t?"changePassword.setYourPassword":"changePassword.changePassword")}),t&&i.jsx("p",{className:"text-xs text-amber-600/80 text-center mt-2",children:n("changePassword.defaultPasswordWarning")})]}),!t&&i.jsxs("div",{className:"space-y-1",children:[i.jsx("label",{className:"text-xs text-fg-tertiary font-medium",children:n("changePassword.currentPassword")}),i.jsx("input",{type:"password",value:a,onChange:w=>s(w.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"})]}),i.jsxs("div",{className:"space-y-1",children:[i.jsx("label",{className:"text-xs text-fg-tertiary font-medium",children:n("changePassword.newPassword")}),i.jsx("input",{type:"password",value:l,onChange:w=>c(w.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})]}),i.jsxs("div",{className:"space-y-1",children:[i.jsx("label",{className:"text-xs text-fg-tertiary font-medium",children:n("changePassword.confirmNewPassword")}),i.jsx("input",{type:"password",value:d,onChange:w=>m(w.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})]}),p&&i.jsx("div",{className:"px-3 py-2 bg-red-500/10 border border-red-500/30 rounded-lg text-xs text-red-500",children:p}),i.jsx("button",{type:"submit",disabled:g||!l||!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:n(g?"changePassword.saving":t?"changePassword.setPasswordAndContinue":"changePassword.changePassword")})]})]})]})}function wie({side:e,defaultWidth:t,minWidth:n,maxWidth:a,collapsedWidth:s=0,storageKey:l}){const[c,d]=k.useState(()=>{try{const T=localStorage.getItem(`${l}_w`);if(T)return Math.max(n,Math.min(a,parseInt(T,10)))}catch{}return t}),[m,p]=k.useState(()=>{try{return localStorage.getItem(`${l}_c`)==="1"}catch{return!1}}),h=k.useRef(!1),g=k.useRef(n),x=k.useRef(a);g.current=n,x.current=a,k.useEffect(()=>{try{localStorage.setItem(`${l}_w`,String(c))}catch{}},[c,l]),k.useEffect(()=>{try{localStorage.setItem(`${l}_c`,m?"1":"0")}catch{}},[m,l]),k.useEffect(()=>{d(T=>Math.max(n,Math.min(a,T)))},[n,a]);const y=k.useCallback(T=>{T.preventDefault(),h.current=!0;const C=T.clientX,S=c,E=L=>{if(!h.current)return;const D=L.clientX-C;d(Math.max(g.current,Math.min(x.current,S+D)))},_=()=>{h.current=!1,document.removeEventListener("mousemove",E),document.removeEventListener("mouseup",_),document.body.style.cursor="",document.body.style.userSelect=""};document.addEventListener("mousemove",E),document.addEventListener("mouseup",_),document.body.style.cursor="col-resize",document.body.style.userSelect="none"},[c,e]),w=k.useCallback(()=>p(T=>!T),[]);return{width:m?s:c,rawWidth:c,collapsed:m,toggle:w,setCollapsed:p,setWidth:d,onResizeStart:y}}const Hse=[{value:"system",label:"System"},{value:"light",label:"Light"},{value:"dark",label:"Dark"},{value:"cyberpunk",label:"Cyberpunk"},{value:"mono",label:"Mono"}],Cg="markus-theme";function jk(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 kie(){try{const e=localStorage.getItem(Cg);if(e==="midnight")return localStorage.setItem(Cg,"dark"),"dark";if(e==="light"||e==="dark"||e==="system"||e==="cyberpunk"||e==="mono")return e}catch{}return"system"}function Sie(){const[e,t]=k.useState(kie),n=k.useCallback(a=>{t(a);try{localStorage.setItem(Cg,a)}catch{}jk(a)},[]);return k.useEffect(()=>{jk(e)},[e]),{mode:e,setMode:n}}const am={agents:[],tasks:[],requirements:[],projects:[],deliverables:[],workflows:[]},Cie={team:["agents","workflows","tasks","requirements","projects","deliverables"],work:["workflows","projects","requirements","tasks","agents","deliverables"],deliverables:["deliverables","agents","tasks","requirements","projects","workflows"]},Aie=["agents","tasks","requirements","projects","deliverables","workflows"];let Mk="",_k="all",Rk=am,Dk=!1;function Tie({onClose:e,currentPage:t}){const{t:n}=ot(["common","home","work"]);Qo(!0);const[a,s]=k.useState(Mk),[l,c]=k.useState(_k),[d,m]=k.useState(Rk),[p,h]=k.useState(!1),[g,x]=k.useState(Dk),[y,w]=k.useState(-1);k.useEffect(()=>{Mk=a},[a]),k.useEffect(()=>{_k=l},[l]),k.useEffect(()=>{Rk=d},[d]),k.useEffect(()=>{Dk=g},[g]);const T=k.useRef(null),C=k.useRef(void 0),S=k.useRef(null),E=k.useRef(null);k.useEffect(()=>{setTimeout(()=>{T.current?.focus(),T.current?.select()},100)},[]);const _=k.useCallback(async ee=>{if(!ee.trim()){m(am),x(!1),w(-1);return}h(!0),x(!0),w(-1);const U=ee.toLowerCase();try{const[te,I,J,me,Ce,H]=await Promise.allSettled([Ae.agents.list(),Ae.tasks.list({search:ee,pageSize:20}),Ae.requirements.list(),Ae.projects.list(),Ae.deliverables.search({q:ee,limit:20}),Ae.teams.list()]),V=te.status==="fulfilled"?te.value.agents.filter(He=>He.name?.toLowerCase().includes(U)||He.role?.toLowerCase().includes(U)):[],fe=I.status==="fulfilled"?I.value.tasks:[],z=J.status==="fulfilled"?J.value.requirements.filter(He=>He.title?.toLowerCase().includes(U)||He.description?.toLowerCase().includes(U)):[],je=me.status==="fulfilled"?me.value.projects.filter(He=>He.name?.toLowerCase().includes(U)||He.description?.toLowerCase().includes(U)):[],Ue=Ce.status==="fulfilled"?Ce.value.results:[],qe=[];if(H.status==="fulfilled"){const He=await Promise.allSettled(H.value.teams.map(ut=>Ae.workflows.list(ut.id)));for(const ut of He)if(ut.status==="fulfilled")for(const dt of ut.value.workflows)(dt.name.toLowerCase().includes(U)||(dt.displayName||"").toLowerCase().includes(U)||dt.description?.toLowerCase().includes(U))&&qe.push(dt)}m({agents:V,tasks:fe,requirements:z,projects:je,deliverables:Ue,workflows:qe})}catch{m(am)}finally{h(!1)}},[]),L=ee=>{s(ee),C.current&&clearTimeout(C.current),C.current=setTimeout(()=>_(ee),400)},D=k.useCallback((ee,U)=>{e(),at.navigate(ee,U)},[e]),M=[{id:"all",label:n("common:all",{defaultValue:"全部"})},{id:"agents",label:n("common:agents",{defaultValue:"智能体"})},{id:"tasks",label:n("common:tasks",{defaultValue:"任务"})},{id:"requirements",label:n("common:requirements",{defaultValue:"需求"})},{id:"projects",label:n("common:projects",{defaultValue:"项目"})},{id:"deliverables",label:n("common:deliverables",{defaultValue:"交付物"})},{id:"workflows",label:n("common:workflows",{defaultValue:"工作流"})}],O=k.useMemo(()=>Cie[t||""]||Aie,[t]),G=k.useMemo(()=>{const ee=[],U=l==="all"?8:void 0,te=I=>{if(l!=="all"&&l!==I)return;const J=d[I].length;if(I==="workflows"){const me=U?d.workflows.slice(0,U):d.workflows;for(const Ce of me)ee.push({id:Ce.name,type:"workflow",page:de.WORK,params:{boardType:"workflows"}})}else{const me=d[I],Ce=U?me.slice(0,U):me;for(const H of Ce)switch(I){case"agents":ee.push({id:H.id,type:"agent",page:de.TEAM,params:{agentId:H.id}});break;case"tasks":ee.push({id:H.id,type:"task",page:de.WORK,params:{openTask:H.id}});break;case"requirements":ee.push({id:H.id,type:"requirement",page:de.WORK,params:{openRequirement:H.id}});break;case"projects":ee.push({id:H.id,type:"project",page:de.WORK,params:{projectId:H.id}});break;case"deliverables":ee.push({id:H.id,type:"deliverable",page:de.DELIVERABLES,params:{openDeliverable:H.id}});break}}U&&J>U&&ee.push({id:`more_${I}`,type:"showMore",page:"",expandCategory:I,totalCount:J})};for(const I of O)te(I);return ee},[d,l,O]),Q=k.useCallback(ee=>{if(ee.type==="showMore"&&ee.expandCategory){c(ee.expandCategory),w(-1);return}D(ee.page,ee.params)},[D]);k.useEffect(()=>{const ee=E.current;if(!ee||y<0)return;const U=ee.querySelector(`[data-idx="${y}"]`);U&&U.scrollIntoView({block:"nearest"})},[y]);const $=k.useCallback(ee=>{if(ee.key==="Escape"){e();return}if(ee.key==="Tab"){ee.preventDefault();const I=M.map(Ce=>Ce.id),J=I.indexOf(l),me=ee.shiftKey?J<=0?I.length-1:J-1:J>=I.length-1?0:J+1;c(I[me]),w(-1);return}const U=ee.ctrlKey&&ee.key==="n"||ee.key==="ArrowDown",te=ee.ctrlKey&&ee.key==="p"||ee.key==="ArrowUp";if(U||te){ee.preventDefault(),w(I=>{const J=G.length-1;return J<0?-1:U?I>=J?0:I+1:I<=0?J:I-1});return}ee.key==="Enter"&&(ee.preventDefault(),y>=0&&y<G.length&&Q(G[y]))},[e,G,y,Q,M,l]);k.useEffect(()=>(document.addEventListener("keydown",$),()=>document.removeEventListener("keydown",$)),[$]);const Y=G.length>0;let K=0;return i.jsx("div",{ref:S,className:"fixed inset-0 bg-black/50 flex items-start justify-center z-50 pt-[8vh]",onClick:ee=>{ee.target===S.current&&e()},children:i.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:[i.jsxs("div",{className:"shrink-0 px-5 pt-4 pb-3 border-b border-border-default space-y-3",children:[i.jsxs("div",{className:"relative",children:[i.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:[i.jsx("circle",{cx:"11",cy:"11",r:"8"}),i.jsx("line",{x1:"21",y1:"21",x2:"16.65",y2:"16.65"})]}),i.jsx("input",{ref:T,value:a,onChange:ee=>L(ee.target.value),placeholder:n("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"}),a&&i.jsx("button",{onClick:()=>{s(""),m(am),x(!1),w(-1),T.current?.focus()},className:"absolute right-3 top-1/2 -translate-y-1/2 text-fg-tertiary hover:text-fg-secondary",children:i.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[i.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),i.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]}),i.jsx("div",{className:"flex gap-1 overflow-x-auto scrollbar-hide",children:M.map(ee=>i.jsx("button",{onClick:()=>{c(ee.id),w(-1)},className:`px-3 py-1.5 text-xs rounded-lg whitespace-nowrap transition-colors ${l===ee.id?"bg-brand-600 text-white":"bg-surface-elevated text-fg-secondary hover:text-fg-primary"}`,children:ee.label},ee.id))})]}),i.jsxs("div",{ref:E,className:"flex-1 overflow-y-auto px-5 py-3",children:[p&&i.jsx("div",{className:"flex items-center justify-center py-8",children:i.jsx("div",{className:"text-fg-tertiary text-sm animate-pulse",children:n("common:loading")})}),!p&&g&&!Y&&i.jsxs("div",{className:"flex flex-col items-center justify-center py-8 text-center",children:[i.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:[i.jsx("circle",{cx:"11",cy:"11",r:"8"}),i.jsx("line",{x1:"21",y1:"21",x2:"16.65",y2:"16.65"})]}),i.jsx("p",{className:"text-sm text-fg-tertiary",children:n("common:noResults",{defaultValue:"没有找到相关结果"})})]}),!p&&Y&&i.jsx("div",{className:"space-y-4",children:O.map(ee=>{if(l!=="all"&&l!==ee)return null;const U=l==="all"?8:void 0,te=I=>{const J=K++,me=I==="agents"?d.agents.length:I==="tasks"?d.tasks.length:I==="requirements"?d.requirements.length:I==="projects"?d.projects.length:I==="workflows"?d.workflows.length:d.deliverables.length;return i.jsxs("button",{"data-idx":J,onClick:()=>{c(I),w(-1)},className:`mt-1 w-full text-xs py-1.5 rounded-lg transition-colors ${J===y?"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:[n("common:showAll",{defaultValue:"查看全部"})," (",me,")"]})};return ee==="agents"&&d.agents.length>0?i.jsxs("section",{children:[i.jsx("h3",{className:"text-xs font-medium text-fg-tertiary uppercase mb-2",children:n("common:agents",{defaultValue:"智能体"})}),i.jsx("div",{className:"space-y-0.5",children:(U?d.agents.slice(0,U):d.agents).map(I=>{const J=K++;return i.jsxs("button",{"data-idx":J,onClick:()=>D(de.TEAM,{agentId:I.id}),className:`w-full flex items-center gap-3 px-3 py-2 rounded-xl transition-colors text-left ${J===y?"bg-brand-600/15 ring-1 ring-brand-500/40":"hover:bg-surface-overlay"}`,children:[i.jsx(Zi,{name:I.name||"Agent",avatarUrl:I.avatarUrl,size:28}),i.jsxs("div",{className:"flex-1 min-w-0",children:[i.jsx("div",{className:"text-sm font-medium text-fg-primary truncate",children:I.name}),i.jsx("div",{className:"text-xs text-fg-tertiary truncate",children:I.role||I.status})]}),i.jsx(Nie,{status:I.status})]},I.id)})}),U&&d.agents.length>U&&te("agents")]},"agents"):ee==="tasks"&&d.tasks.length>0?i.jsxs("section",{children:[i.jsx("h3",{className:"text-xs font-medium text-fg-tertiary uppercase mb-2",children:n("common:tasks",{defaultValue:"任务"})}),i.jsx("div",{className:"space-y-0.5",children:(U?d.tasks.slice(0,U):d.tasks).map(I=>{const J=K++;return i.jsxs("button",{"data-idx":J,onClick:()=>D(de.WORK,{openTask:I.id}),className:`w-full flex items-center gap-3 px-3 py-2 rounded-xl transition-colors text-left ${J===y?"bg-brand-600/15 ring-1 ring-brand-500/40":"hover:bg-surface-overlay"}`,children:[i.jsx(Eie,{status:I.status}),i.jsxs("div",{className:"flex-1 min-w-0",children:[i.jsx("div",{className:"text-sm text-fg-primary truncate",children:I.title}),i.jsxs("div",{className:"text-xs text-fg-tertiary truncate",children:[I.status," · ",I.priority||""]})]})]},I.id)})}),U&&d.tasks.length>U&&te("tasks")]},"tasks"):ee==="requirements"&&d.requirements.length>0?i.jsxs("section",{children:[i.jsx("h3",{className:"text-xs font-medium text-fg-tertiary uppercase mb-2",children:n("common:requirements",{defaultValue:"需求"})}),i.jsx("div",{className:"space-y-0.5",children:(U?d.requirements.slice(0,U):d.requirements).map(I=>{const J=K++;return i.jsxs("button",{"data-idx":J,onClick:()=>D(de.WORK,{openRequirement:I.id}),className:`w-full flex items-center gap-3 px-3 py-2 rounded-xl transition-colors text-left ${J===y?"bg-brand-600/15 ring-1 ring-brand-500/40":"hover:bg-surface-overlay"}`,children:[i.jsx("div",{className:`w-7 h-7 rounded-lg flex items-center justify-center shrink-0 ${I.status==="approved"?"text-green-500 bg-green-500/15":I.status==="pending"?"text-amber-500 bg-amber-500/15":I.status==="rejected"?"text-red-500 bg-red-500/15":"text-fg-tertiary bg-surface-elevated"}`,children:i.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[i.jsx("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),i.jsx("polyline",{points:"14 2 14 8 20 8"}),i.jsx("line",{x1:"16",y1:"13",x2:"8",y2:"13"}),i.jsx("line",{x1:"16",y1:"17",x2:"8",y2:"17"})]})}),i.jsxs("div",{className:"flex-1 min-w-0",children:[i.jsx("div",{className:"text-sm text-fg-primary truncate",children:I.title}),i.jsxs("div",{className:"text-xs text-fg-tertiary truncate",children:[I.status," · ",I.priority||""]})]})]},I.id)})}),U&&d.requirements.length>U&&te("requirements")]},"requirements"):ee==="projects"&&d.projects.length>0?i.jsxs("section",{children:[i.jsx("h3",{className:"text-xs font-medium text-fg-tertiary uppercase mb-2",children:n("common:projects",{defaultValue:"项目"})}),i.jsx("div",{className:"space-y-0.5",children:(U?d.projects.slice(0,U):d.projects).map(I=>{const J=K++;return i.jsxs("button",{"data-idx":J,onClick:()=>D(de.WORK,{projectId:I.id}),className:`w-full flex items-center gap-3 px-3 py-2 rounded-xl transition-colors text-left ${J===y?"bg-brand-600/15 ring-1 ring-brand-500/40":"hover:bg-surface-overlay"}`,children:[i.jsx("div",{className:"w-7 h-7 rounded-lg bg-brand-500/15 flex items-center justify-center shrink-0",children:i.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:"text-brand-500",children:i.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"})})}),i.jsxs("div",{className:"flex-1 min-w-0",children:[i.jsx("div",{className:"text-sm text-fg-primary truncate",children:I.name}),I.description&&i.jsx("div",{className:"text-xs text-fg-tertiary truncate",children:I.description})]})]},I.id)})}),U&&d.projects.length>U&&te("projects")]},"projects"):ee==="deliverables"&&d.deliverables.length>0?i.jsxs("section",{children:[i.jsx("h3",{className:"text-xs font-medium text-fg-tertiary uppercase mb-2",children:n("common:deliverables",{defaultValue:"交付物"})}),i.jsx("div",{className:"space-y-0.5",children:(U?d.deliverables.slice(0,U):d.deliverables).map(I=>{const J=K++;return i.jsxs("button",{"data-idx":J,onClick:()=>D(de.DELIVERABLES,{openDeliverable:I.id}),className:`w-full flex items-center gap-3 px-3 py-2 rounded-xl transition-colors text-left ${J===y?"bg-brand-600/15 ring-1 ring-brand-500/40":"hover:bg-surface-overlay"}`,children:[i.jsx("div",{className:"w-7 h-7 rounded-lg bg-purple-500/15 flex items-center justify-center shrink-0",children:i.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:"text-purple-500",children:[i.jsx("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),i.jsx("polyline",{points:"14 2 14 8 20 8"})]})}),i.jsxs("div",{className:"flex-1 min-w-0",children:[i.jsx("div",{className:"text-sm text-fg-primary truncate",children:I.title}),i.jsxs("div",{className:"text-xs text-fg-tertiary truncate",children:[I.type," · ",I.status]})]})]},I.id)})}),U&&d.deliverables.length>U&&te("deliverables")]},"deliverables"):ee==="workflows"&&d.workflows.length>0?i.jsxs("section",{children:[i.jsx("h3",{className:"text-xs font-medium text-fg-tertiary uppercase mb-2",children:n("common:workflows",{defaultValue:"工作流"})}),i.jsx("div",{className:"space-y-0.5",children:(U?d.workflows.slice(0,U):d.workflows).map(I=>{const J=K++;return i.jsxs("button",{"data-idx":J,onClick:()=>D(de.WORK,{boardType:"workflows"}),className:`w-full flex items-center gap-3 px-3 py-2 rounded-xl transition-colors text-left ${J===y?"bg-brand-600/15 ring-1 ring-brand-500/40":"hover:bg-surface-overlay"}`,children:[i.jsx("div",{className:"w-7 h-7 rounded-lg bg-teal-500/15 flex items-center justify-center shrink-0",children:i.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:"text-teal-500",children:[i.jsx("circle",{cx:"12",cy:"12",r:"3"}),i.jsx("path",{d:"M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 0 1 0 2.83 2 2 0 0 1-2.83 0l-.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-2 2 2 2 0 0 1-2-2v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 0 1-2.83 0 2 2 0 0 1 0-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-2-2 2 2 0 0 1 2-2h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 0 1 0-2.83 2 2 0 0 1 2.83 0l.06.06A1.65 1.65 0 0 0 9 4.68a1.65 1.65 0 0 0 1-1.51V3a2 2 0 0 1 2-2 2 2 0 0 1 2 2v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 0 1 2.83 0 2 2 0 0 1 0 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 2 2 2 2 0 0 1-2 2h-.09a1.65 1.65 0 0 0-1.51 1z"})]})}),i.jsxs("div",{className:"flex-1 min-w-0",children:[i.jsx("div",{className:"text-sm text-fg-primary truncate",children:I.displayName||I.name}),i.jsxs("div",{className:"text-xs text-fg-tertiary truncate",children:[I.stepCount," steps · v",I.version]})]})]},I.name)})}),U&&d.workflows.length>U&&te("workflows")]},"workflows"):null})}),!p&&!g&&i.jsxs("div",{className:"flex flex-col items-center justify-center py-8 text-center",children:[i.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:[i.jsx("circle",{cx:"11",cy:"11",r:"8"}),i.jsx("line",{x1:"21",y1:"21",x2:"16.65",y2:"16.65"})]}),i.jsx("p",{className:"text-sm text-fg-tertiary",children:n("common:searchHint",{defaultValue:"输入关键词搜索"})})]})]}),i.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:[i.jsxs("span",{children:[i.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"})," ",n("common:toggle",{defaultValue:"唤起/关闭"})]}),i.jsxs("span",{children:[i.jsx("kbd",{className:"px-1.5 py-0.5 rounded bg-surface-elevated border border-border-default text-[11px] font-medium",children:"Tab"})," ",n("common:switchTab",{defaultValue:"切换分类"})]}),i.jsxs("span",{children:[i.jsx("kbd",{className:"px-1.5 py-0.5 rounded bg-surface-elevated border border-border-default text-[11px] font-medium",children:"↑↓"})," ",n("common:navigate",{defaultValue:"导航"})]}),i.jsxs("span",{children:[i.jsx("kbd",{className:"px-1.5 py-0.5 rounded bg-surface-elevated border border-border-default text-[11px] font-medium",children:"Enter"})," ",n("common:open",{defaultValue:"打开"})]}),i.jsxs("span",{children:[i.jsx("kbd",{className:"px-1.5 py-0.5 rounded bg-surface-elevated border border-border-default text-[11px] font-medium",children:"Esc"})," ",n("common:close",{defaultValue:"关闭"})]})]})]})})}function Nie({status:e}){const t=e==="active"||e==="idle"?"bg-green-500":e==="working"||e==="busy"?"bg-blue-500":"bg-gray-400";return i.jsx("span",{className:`w-2 h-2 rounded-full shrink-0 ${t}`})}function Eie({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 i.jsx("div",{className:`w-7 h-7 rounded-lg flex items-center justify-center shrink-0 ${t}`,children:i.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[i.jsx("path",{d:"M9 11l3 3L22 4"}),i.jsx("path",{d:"M21 12v7a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h11"})]})})}const jie=["layout","navigation","tasks","team","search","rightPanel","terminal","help"];function Mie(e){return e===de.TEAM?"team":e===de.WORK?"work":e===de.DELIVERABLES?"deliverables":e===de.STORE?"store":"any"}function _ie({open:e,onClose:t,page:n}){const{t:a}=ot("common"),s=typeof navigator<"u"&&navigator.platform.toUpperCase().includes("MAC"),l=Mie(n);return k.useEffect(()=>{if(!e)return;const c=d=>{d.key==="Escape"&&(d.preventDefault(),d.stopPropagation(),t())};return window.addEventListener("keydown",c,!0),()=>window.removeEventListener("keydown",c,!0)},[e,t]),e?i.jsx("div",{className:"fixed inset-0 z-[100] flex items-center justify-center bg-black/45 backdrop-blur-[1px] p-4",onMouseDown:c=>{c.target===c.currentTarget&&t()},role:"dialog","aria-modal":"true","aria-label":a("shortcuts.title"),children:i.jsxs("div",{className:"w-full max-w-lg max-h-[80vh] overflow-auto rounded-xl border border-border-default bg-surface-primary shadow-2xl",children:[i.jsxs("div",{className:"sticky top-0 z-10 flex items-center justify-between gap-3 px-4 py-3 border-b border-border-default bg-surface-primary",children:[i.jsx("h2",{className:"text-sm font-semibold text-fg-primary",children:a("shortcuts.title")}),i.jsx("button",{type:"button",onClick:t,className:"w-7 h-7 flex items-center justify-center rounded-md text-fg-tertiary hover:text-fg-secondary hover:bg-surface-elevated","aria-label":a("shortcuts.close"),children:i.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[i.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),i.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]}),i.jsx("div",{className:"px-4 py-3 space-y-4",children:jie.map(c=>{const d=_U.filter(m=>{if(m.group!==c)return!1;const p=m.page??"any";return p==="any"?!0:p===l});return d.length===0?null:i.jsxs("section",{children:[i.jsx("h3",{className:"text-[11px] font-semibold uppercase tracking-wide text-fg-tertiary mb-2",children:a(`shortcuts.groups.${c}`)}),i.jsx("ul",{className:"space-y-1.5",children:d.map(m=>i.jsxs("li",{className:"flex items-center justify-between gap-3 text-sm",children:[i.jsx("span",{className:"text-fg-secondary min-w-0",children:a(m.labelKey??m.label,{defaultValue:m.label})}),i.jsx("kbd",{className:"shrink-0 px-2 py-1 rounded bg-surface-elevated border border-border-default text-[13px] font-medium leading-none text-fg-primary font-mono",children:x4(m.keys,s,m.bare)})]},m.id))})]},c)})})]})}):null}function Rie({authUser:e,onClose:t,onSaved:n,onUserUpdated:a}){const{t:s}=ot("common");Qo(!0);const[l,c]=k.useState(e.name||""),[d,m]=k.useState(e.email||""),[p,h]=k.useState(!1),[g,x]=k.useState(""),[y,w]=k.useState(()=>m4(e.avatarUrl,xr()?.avatarUrl)),T=async C=>{if(C.preventDefault(),!l.trim()){x(s("profile.nameRequired"));return}if(d&&!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(d.trim())){x(s("profile.invalidEmail"));return}h(!0),x("");try{const{user:S}=await Ae.auth.updateProfile(l.trim(),d.trim());n({...S,avatarUrl:y??S.avatarUrl})}catch{x(s("profile.failedToSave"))}finally{h(!1)}};return i.jsx("div",{className:"fixed inset-0 bg-black/60 flex items-center justify-center z-[10000]",onClick:t,children:i.jsxs("form",{onSubmit:T,className:"bg-surface-secondary border border-border-default rounded-xl p-6 w-[400px] max-w-[calc(100vw-2rem)] shadow-2xl",onClick:C=>C.stopPropagation(),children:[i.jsx("h3",{className:"text-base font-semibold mb-5",children:s("profile.editProfile")}),i.jsx("div",{className:"flex justify-center mb-5",children:i.jsx(f4,{currentUrl:y,name:l,size:72,targetType:"user",targetId:e.id,onUploaded:C=>{w(C),a?.({...e,avatarUrl:C})}})}),i.jsxs("div",{className:"space-y-3",children:[i.jsxs("div",{children:[i.jsx("label",{className:"block text-xs text-fg-tertiary font-medium mb-1",children:s("profile.name")}),i.jsx("input",{value:l,onChange:C=>c(C.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"})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-xs text-fg-tertiary font-medium mb-1",children:s("profile.email")}),i.jsx("input",{value:d,onChange:C=>m(C.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"})]}),g&&i.jsx("div",{className:"text-xs text-red-500 bg-red-500/10 border border-red-500/30 rounded-lg px-3 py-2",children:g})]}),i.jsxs("div",{className:"flex justify-end gap-3 mt-5",children:[i.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")}),i.jsx("button",{type:"submit",disabled:p,className:"px-4 py-2 text-sm bg-brand-600 hover:bg-brand-500 disabled:opacity-50 text-white rounded-lg",children:s(p?"saving":"save")})]})]})})}const Lk=k.lazy(()=>va(()=>import("./Team-B-hEPIUd.js"),__vite__mapDeps([2,3,4,5,6,7])).then(e=>({default:e.TeamPage}))),Ik=k.lazy(()=>va(()=>import("./Settings-CiDdRf4c.js"),__vite__mapDeps([8,6])).then(e=>({default:e.Settings}))),Die=k.lazy(()=>va(()=>import("./Store-Dow-P_iy.js"),[]).then(e=>({default:e.StorePage}))),Lie=k.lazy(()=>va(()=>Promise.resolve().then(()=>Wre),void 0).then(e=>({default:e.AgentBuilder}))),Ok=k.lazy(()=>va(()=>import("./Work-C1398-Y_.js"),__vite__mapDeps([9,4,1,10,3,11])).then(e=>({default:e.WorkPage}))),Pk=k.lazy(()=>va(()=>import("./Deliverables-1lbmiGAG.js"),__vite__mapDeps([12,4,5])).then(e=>({default:e.DeliverablesPage}))),Iie=k.lazy(()=>va(()=>import("./Notifications-CNIT_3nV.js"),[]).then(e=>({default:e.NotificationsPage}))),Oie=k.lazy(()=>va(()=>import("./Search-z4hSEFJB.js"),[]).then(e=>({default:e.SearchPage}))),Pie={visibility:"hidden",position:"absolute",inset:0,pointerEvents:"none",zIndex:-1};function zie(e){try{const t=navigator.language,n=Intl.DateTimeFormat().resolvedOptions().timeZone,a=e.preferences??{};if(a.locale===t&&a.timezone===n)return;Ae.auth.updatePreferences({locale:t,timezone:n}).catch(()=>{})}catch{}}function Bie(){return i.jsx("div",{className:"flex-1 flex items-center justify-center text-fg-tertiary text-sm animate-pulse",children:"Loading..."})}const Hie=k.memo(function({id:t,activePage:n,children:a}){const s=t===n;return i.jsx("div",{className:"flex-1 overflow-hidden flex flex-col",style:s?void 0:Pie,children:i.jsx(k.Suspense,{fallback:i.jsx(Bie,{}),children:a})})},(e,t)=>{const n=e.id===e.activePage,a=t.id===t.activePage;return n!==a?!1:a?e.children===t.children:!0}),Ud={};function u6(e){return typeof window<"u"&&window.matchMedia("(max-width: 767px)").matches?a4[e]??e:e}function zk(){return u6(Sc())}function $ie(){const{t:e}=ot("common"),[t,n]=k.useState(zk),[a,s]=k.useState(!1),[l,c]=k.useState(!0),d=Xo(),m=Sie(),p=wie({side:"left",defaultWidth:160,minWidth:140,maxWidth:400,collapsedWidth:64,storageKey:"markus_sidebar"}),[h,g]=k.useState(()=>new Set([zk()])),[x,y]=k.useState("loading"),[w,T]=k.useState(!1),[C,S]=k.useState(null),[E,_]=k.useState({hasOwner:!1,hasMultipleUsers:!1}),[L,D]=k.useState(!1),[M,O]=k.useState(!1),[G,Q]=k.useState(null),[$,Y]=k.useState(!1),[K,ee]=k.useState(null),[U,te]=k.useState(()=>{const X=localStorage.getItem("markus_update_dismissed");return X||null}),[I,J]=k.useState(!1),[me,Ce]=k.useState(!1),H=qc(),V=H?.leftCollapsed??!1,fe=H?.toggleLeftCollapsed,z=H?.setLeftCollapsed,je=H?.keyboardPane??"l0",Ue=H?.setKeyboardPane,qe=H?.l0FocusPageId??null,He=H?.setL0FocusPageId,ut=k.useRef(t);ut.current=t;const dt=k.useRef(de.HOME),Nt=H?.toggleRightPanel,wt=H?.toggleTerminalPanel,Zt=H?.cycleRightPanelTab,Wt=H?.activateRightPanelTabAt,rt=H?.openNewRightPanelTab,$e=H?.rightPanelOpen??!1,mt=H?.activeRightPanelTabId??null,At=H?.openRightPanel,Dt=H?.closeRightPanelTab,ln=H?.updateRightPanelBrowserTab,ce=H?.updateRightPanelTerminalTab,et=k.useRef(H?.rightPanelTabs);et.current=H?.rightPanelTabs,k.useEffect(()=>{const X=window.markusDesktop?.browser?.onPageEvent;if(!(!X||!At))return X(Z=>{if(Z.type==="closed"){const ue=et.current?.find(Be=>Be.payload.kind==="url"&&Be.payload.browserId===Z.browserId);ue&&Dt&&Dt(ue.id);return}if(Z.type==="navigated"){if(Z.url&&Ac(Z.url))return;Z.browserId&&ln&&ln(Z.browserId,{url:Z.url,title:Z.title||Z.url});return}if(Z.type==="opened"||Z.type==="selected"){if(!Z.url&&!Z.browserId||Z.browserId.startsWith("eb_")||Ete(Z.browserId)||Z.url&&Ac(Z.url))return;At({kind:"url",url:Z.url||"about:blank",title:Z.title||Z.url||"Browser",browserId:Z.browserId,pageId:Z.pageId})}})},[At,Dt,ln]),k.useEffect(()=>{const X=window.markusDesktop?.terminal?.onEvent;if(!(!X||!At))return X(Z=>{if(Z.type==="closed"){const ue=et.current?.find(Be=>Be.payload.kind==="terminal"&&Be.payload.terminalId===Z.id);ue&&Dt&&Dt(ue.id);return}if(Z.type==="cwd"){Z.cwd&&ce?.(Z.id,{cwd:Z.cwd});return}if(Z.type==="selected"){(Z.title||Z.cwd)&&ce?.(Z.id,{title:Z.title,cwd:Z.cwd});return}if(Z.type==="opened"){if(mb.has(Z.id)){(Z.title||Z.cwd)&&ce?.(Z.id,{title:Z.title,cwd:Z.cwd});return}_s(Z.id),At({kind:"terminal",terminalId:Z.id,title:Z.title||"Terminal",cwd:Z.cwd})}})},[At,Dt,ce]);const nt=H?.handleTerminalExit;k.useEffect(()=>{const X=window.markusDesktop?.terminal?.onExit;if(!(!X||!nt))return X(Z=>{nt(Z.id)})},[nt]),k.useLayoutEffect(()=>{const X=t===de.TEAM&&$e&&H?.rightPanelMode==="browser";wf(X)},[t,$e,H?.rightPanelMode]),k.useEffect(()=>{window.markusDesktop?.browser?.hideAll?.()},[]);const we=k.useRef(!1);k.useEffect(()=>{if(!we.current){we.current=!0;return}p.setCollapsed(V)},[V,p.setCollapsed]),k.useEffect(()=>{if(d)return;const X=navigator.platform.toUpperCase().includes("MAC"),Z=Be=>{X&&Be.metaKey&&!Be.ctrlKey&&Be.key==="p"?(Be.preventDefault(),J(Ie=>!Ie)):!X&&Be.ctrlKey&&!Be.metaKey&&Be.key==="p"&&(Be.preventDefault(),J(Ie=>!Ie))},ue=()=>J(!0);return document.addEventListener("keydown",Z),window.addEventListener("markus:open-search",ue),()=>{document.removeEventListener("keydown",Z),window.removeEventListener("markus:open-search",ue)}},[d]);const Me=k.useCallback(()=>!$e||!mt||!Dt?!1:(Dt(mt),!0),[$e,mt,Dt]);k.useEffect(()=>{const X=window.markusDesktop?.onAppShortcut?.(Z=>{if(Z.type==="close-tab"){Me();return}Z.type==="new-tab"&&rt?.()});return()=>{X?.()}},[Me,rt]),k.useEffect(()=>{if(d||!fe||!Nt)return;const X=navigator.platform.toUpperCase().includes("MAC"),Z=ue=>{if(!(X?ue.metaKey&&!ue.ctrlKey:ue.ctrlKey&&!ue.metaKey)||ue.altKey)return;if(!ue.shiftKey&&(ue.key==="/"||ue.code==="Slash")){ue.preventDefault(),Ce(Ge=>!Ge);return}if(ue.shiftKey&&(ue.key==="?"||ue.key==="/")){ue.preventDefault(),Ce(Ge=>!Ge);return}if(ue.shiftKey&&$e&&Zt){if(ue.key==="]"||ue.code==="BracketRight"){ue.preventDefault(),Zt(1);return}if(ue.key==="["||ue.code==="BracketLeft"){ue.preventDefault(),Zt(-1);return}}if(!ue.shiftKey&&$e&&Wt){const Ge=ue.key>="1"&&ue.key<="9"?Number(ue.key):0;if(Ge>=1){ue.preventDefault(),Wt(Ge-1);return}}if(ue.shiftKey)return;const Ie=ue.key.toLowerCase();if(Ie==="w"){ue.preventDefault(),ue.stopPropagation(),Me();return}if(Ie==="t"){ue.preventDefault(),rt?.();return}if(Ie==="b"){if(t===de.DELIVERABLES)return;ue.preventDefault(),fe()}else if(t===de.TEAM&&Ie==="l"){if(!X&&Pv(ue.target)||X&&Pv(ue.target)&&ue.ctrlKey)return;ue.preventDefault(),Nt()}else t===de.TEAM&&Ie==="j"&&wt&&(ue.preventDefault(),wt())};return document.addEventListener("keydown",Z,!0),()=>document.removeEventListener("keydown",Z,!0)},[d,t,fe,Nt,wt,Zt,Wt,$e,Me,rt]);const Ne=k.useCallback((X,Z)=>{let ue=kc(X);d?ue=a4[ue]??ue:ue===de.NOTIFICATIONS&&(ue=de.HOME),ue!==de.TEAM&&wf(!1);const Be=Sc(),Ie=window.location.hash.slice(1);Ie!==Nh(Be)?Ud[Be]=Ie:delete Ud[Be];const Ge=ut.current;if(ue===de.SETTINGS&&Ge!==de.SETTINGS&&(dt.current=Ge,at.setSettingsReturnPage(Ge),Ue?.("l1"),He?.(de.SETTINGS)),Ge===de.SETTINGS&&ue!==de.SETTINGS&&(Ue?.("l0"),He?.(ue)),ue===de.SETTINGS&&Z?.tab){const Rt=`settings/${Z.tab}`;Ud[ue]=Rt,history.pushState(null,"","#"+Rt),window.dispatchEvent(new HashChangeEvent("hashchange")),n(ue),g(Mt=>Mt.has(ue)?Mt:new Set([...Mt,ue]));return}const kt=ue!==de.WORK?Ud[ue]:void 0;kt&&kt!==Nh(ue)?(history.pushState(null,"",Ps(ue)),history.pushState(null,"","#"+kt)):history.pushState(null,"",Ps(ue)),window.dispatchEvent(new HashChangeEvent("hashchange")),n(ue),g(Rt=>Rt.has(ue)?Rt:new Set([...Rt,ue]))},[d,Ue,He]);k.useEffect(()=>{at.setHandler((X,Z)=>Ne(X,Z))},[Ne]),k.useEffect(()=>{je==="l0"&&t!==de.SETTINGS&&He?.(t)},[je,t,He]),k.useEffect(()=>{if(d||!Ue||!He)return;const X=Z=>{if(Z.metaKey||Z.ctrlKey||Z.altKey||Ov(Z.target))return;const ue=Z.key.length===1?Z.key.toLowerCase():Z.key;if(t===de.SETTINGS&&(ue==="h"||ue==="ArrowLeft")){Z.preventDefault(),Z.stopImmediatePropagation(),at.leaveSettings();return}if(je!=="l0"||t===de.SETTINGS)return;const Be=qe&&Eo.includes(qe)?qe:t,Ie=Math.max(0,Eo.indexOf(Be));if(ue==="j"||ue==="ArrowDown"){Z.preventDefault(),Z.stopImmediatePropagation();const Ge=Eo[Math.min(Eo.length-1,Ie+1)];He(Ge),Ge!==t&&Ne(Ge),requestAnimationFrame(()=>{document.querySelector(`[data-l0-page-id="${Ge}"]`)?.scrollIntoView({block:"nearest"})});return}if(ue==="k"||ue==="ArrowUp"){Z.preventDefault(),Z.stopImmediatePropagation();const Ge=Eo[Math.max(0,Ie-1)];He(Ge),Ge!==t&&Ne(Ge),requestAnimationFrame(()=>{document.querySelector(`[data-l0-page-id="${Ge}"]`)?.scrollIntoView({block:"nearest"})});return}if(ue==="l"||ue==="ArrowRight"||ue==="Enter"){const Ge=qe&&Eo.includes(qe)?qe:t;if(!rU.has(Ge)){Z.preventDefault(),Z.stopImmediatePropagation();return}Z.preventDefault(),Z.stopImmediatePropagation(),Ge!==t&&Ne(Ge),z?.(!1),Ue("l1");return}(ue==="h"||ue==="ArrowLeft")&&(Z.preventDefault(),Z.stopImmediatePropagation())};return document.addEventListener("keydown",X,!0),()=>document.removeEventListener("keydown",X,!0)},[d,je,qe,t,Ne,Ue,He,z]),k.useEffect(()=>{const X=()=>T(!0);return window.addEventListener("markus:open-edit-profile",X),()=>window.removeEventListener("markus:open-edit-profile",X)},[]),k.useEffect(()=>{if(!window.markusDesktop)return;!d&&t!==de.SETTINGS&&!p.collapsed?window.markusDesktop.setTrafficLightPosition(16,16):window.markusDesktop.setTrafficLightPosition(6,16)},[p.collapsed,t,d]),k.useEffect(()=>{window.markusDesktop&&window.markusDesktop.onNotificationClick(X=>{if(X.openNotifications&&window.dispatchEvent(new CustomEvent("markus:open-notifications")),X.page){const Z=kc(X.page);X.params&&Object.entries(X.params).forEach(([ue,Be])=>localStorage.setItem(`markus_nav_${ue}`,Be)),Ne(Z),window.dispatchEvent(new CustomEvent("markus:navigate",{detail:{page:Z,params:X.params}}))}})},[Ne]);const se=k.useCallback(()=>{fetch("/api/settings/llm").then(X=>X.ok?X.json():null).then(X=>{if(X?.providers){const Z=Object.values(X.providers).some(ue=>ue.configured);Q(Z)}}).catch(()=>{})},[]),q=k.useCallback((X,Z)=>{if(!X)return;const Be=Z&&{agent:"agents",team:"teams",skill:"skills"}[Z]||"agents";localStorage.setItem("markus_nav_installItem",X),localStorage.setItem("markus_nav_storeTab",Be);const Ie=new URLSearchParams(window.location.search);Ie.get("install")||(Ie.set("install",X),Z&&Ie.set("type",Z));const Ge=Ie.toString();window.history.replaceState(null,"",`${window.location.pathname}?${Ge}${Ps(de.STORE)}`);const kt=()=>at.navigate(de.STORE,{storeTab:Be,installItem:X});kt(),setTimeout(kt,500),setTimeout(kt,1500)},[]);k.useEffect(()=>{const X=new URLSearchParams(window.location.search),Z=X.get("install");Z&&q(Z,X.get("type"));const ue=window.markusDesktop;ue?.onDeepLinkInstall?.(({id:Ge,type:kt})=>q(Ge,kt)),ue?.consumePendingDeepLinkInstall?.().then(Ge=>{Ge?.id&&q(Ge.id,Ge.type)}),Ae.auth.me().then(({user:Ge})=>{y(Ge),S(!0),s(!1),Ge.preferences?.guideHidden===!0&&!_h(Ge.id)&&Rh(Ge.id),zie(Ge),Ir.connect(Ge.id),se(),Ae.health().then(Rt=>{Rt.updateAvailable&&Rt.latestVersion&&ee({latestVersion:Rt.latestVersion,currentVersion:Rt.version})}).catch(()=>{});const kt=()=>{Ns(qa.builderArtifacts,()=>Ae.builder.artifacts.list()),Ns(qa.builderAgents,()=>Ae.agents.list()),Ns(qa.builderHubMyItems,()=>st.myItems()),Ns(qa.builderInstalled,()=>Ae.builder.artifacts.installed()),Ns(qa.hubAgents,()=>st.search({type:"agent",limit:50})),Ns(qa.hubTeams,()=>st.search({type:"team",limit:50})),Ns(qa.hubSkills,()=>st.search({type:"skill",limit:50}))};typeof requestIdleCallback=="function"?requestIdleCallback(kt,{timeout:5e3}):setTimeout(kt,3e3)}).catch(()=>{y(null),Ae.auth.status().then(({initialized:Ge,hasOwner:kt,hasMultipleUsers:Rt})=>{S(Ge),_({hasOwner:kt,hasMultipleUsers:Rt})}).catch(()=>S(!0))}),Ir.connect();const Be=Ir.on("notification",()=>{window.dispatchEvent(new CustomEvent("markus:notifications-changed"))}),Ie=()=>{const Ge=u6(Sc());Ge!==de.TEAM&&wf(!1),n(Ge),g(kt=>kt.has(Ge)?kt:new Set([...kt,Ge]))};return window.addEventListener("hashchange",Ie),window.addEventListener("popstate",Ie),()=>{Be(),Ir.disconnect(),window.removeEventListener("hashchange",Ie),window.removeEventListener("popstate",Ie)}},[]),k.useEffect(()=>{const X=x!=="loading"&&x!==null?x.id:void 0;if(!X)return;const Z=navigator.platform.toUpperCase().includes("MAC"),ue=Be=>{if(Ov(Be.target))return;const Ie={key:Be.key,code:Be.code,metaKey:Be.metaKey,ctrlKey:Be.ctrlKey,altKey:Be.altKey,shiftKey:Be.shiftKey};jU(Ie,X,Z)&&window.dispatchEvent(new CustomEvent("markus:shortcut-lesson-complete"))};return window.addEventListener("keydown",ue,!0),()=>window.removeEventListener("keydown",ue,!0)},[x]);const ae=x!=="loading"&&x!==null?x:void 0,Se=k.useMemo(()=>d?{[de.HOME]:i.jsx($v,{authUser:ae}),[de.TEAM]:i.jsx(Lk,{authUser:ae}),[de.BUILDER]:i.jsx(hie,{authUser:ae}),[de.SETTINGS]:i.jsx(Ik,{theme:m.mode,onThemeChange:m.setMode,authUser:ae,onLogout:()=>{Ae.auth.logout().catch(()=>{}),Ds(),y(null)},onUserUpdated:X=>y(X)}),[de.WORK]:i.jsx(Ok,{authUser:ae}),[de.DELIVERABLES]:i.jsx(Pk,{authUser:ae}),[de.NOTIFICATIONS]:i.jsx(Iie,{authUser:ae}),[de.SEARCH]:i.jsx(Oie,{})}:{[de.HOME]:i.jsx($v,{authUser:ae}),[de.TEAM]:i.jsx(Lk,{authUser:ae}),[de.SETTINGS]:i.jsx(Ik,{theme:m.mode,onThemeChange:m.setMode,authUser:ae,onLogout:()=>{Ae.auth.logout().catch(()=>{}),Ds(),y(null)},onUserUpdated:X=>y(X)}),[de.STORE]:i.jsx(Die,{authUser:ae}),[de.BUILDER]:i.jsx(Lie,{authUser:ae}),[de.WORK]:i.jsx(Ok,{authUser:ae}),[de.DELIVERABLES]:i.jsx(Pk,{authUser:ae})},[ae?.id,ae?.role,m.mode,d]);if(x==="loading"||x===null&&C===null)return i.jsx("div",{className:"min-h-dvh bg-surface-primary flex items-center justify-center",children:i.jsx("div",{className:"text-fg-tertiary text-sm animate-pulse",children:e("loading")})});const Pe=(typeof window<"u"?window.location.hash:"").match(/^#invite\?token=([a-f0-9]+)/);return Pe?i.jsx(xie,{token:Pe[1],onComplete:()=>{window.location.hash="",localStorage.removeItem("markus_onboarded"),s(!0),D(!0),y("loading"),Ae.auth.me().then(X=>{zv(X.user.id),y(X.user)}).catch(()=>y(null))}}):x===null?i.jsx(yie,{hasOwner:E.hasOwner,hasMultipleUsers:E.hasMultipleUsers,onLogin:(X,Z,ue)=>{y(X),Ir.connect(X.id),Z?(zv(X.id),s(!0),ue?.fromHub&&D(!0)):(s(!1),_h(X.id)?(Rh(X.id),Ae.auth.updatePreferences({guideHidden:!0}).catch(()=>{}),y({...X,preferences:{...X.preferences,guideHidden:!0}})):y(X))}}):M?i.jsx(vie,{onComplete:()=>O(!1),isFirstTime:!0}):a?i.jsx(gie,{theme:m.mode,onThemeChange:m.setMode,skipProfile:L,onProfileUpdated:X=>{const Z={id:X.id,name:X.name,email:X.email,role:X.role,orgId:X.orgId??"default",avatarUrl:X.avatarUrl};y(Z)},onComplete:()=>{localStorage.removeItem("markus_onboarded"),s(!1),D(!1),Ae.auth.me().then(X=>y(X.user)).catch(()=>{}),se(),Ne(de.HOME)}}):i.jsxs("div",{className:`flex h-dvh bg-surface-primary text-fg-primary overflow-x-hidden ${d?"flex-col":""}`,children:[!d&&t!==de.SETTINGS&&i.jsxs(i.Fragment,{children:[i.jsx("div",{className:"relative z-40 shrink-0",style:{width:p.width},children:i.jsx(bre,{currentPage:t,onNavigate:X=>{Ne(X),c(!1),Ue?.("l0"),He?.(X)},authUser:x,collapsed:p.collapsed,onToggleCollapse:p.toggle,onLogout:()=>{Ae.auth.logout().catch(()=>{}),Ds(),y(null)},keyboardFocusPageId:qe,keyboardPaneActive:je==="l0"})}),i.jsx("div",{className:`${p.collapsed?"w-0":"w-1.5 cursor-col-resize"} shrink-0 group relative z-10 flex items-center justify-center`,onMouseDown:p.collapsed?void 0:p.onResizeStart,children:!p.collapsed&&i.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"})})]}),i.jsxs("div",{className:`flex-1 overflow-hidden flex flex-col min-w-0 ${d&&t!==de.SETTINGS&&t!==de.SEARCH?"pb-14":""}`,children:[G===!1&&!$&&t!==de.SETTINGS&&i.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:[i.jsx("span",{className:d?"text-xs":"",children:e("llmBanner.message")}),i.jsxs("div",{className:"flex items-center gap-3",children:[i.jsx("button",{onClick:()=>{window.location.hash="#settings/providers"},className:"px-3 py-1 bg-amber-700/50 hover:bg-amber-700/70 text-white text-xs rounded-lg transition-colors",children:e("llmBanner.goToSettings")}),i.jsx("button",{onClick:()=>Y(!0),className:"text-amber-500 hover:text-amber-600 text-xs",children:e("dismiss")})]})]}),K&&U!==K.latestVersion&&i.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:[i.jsx("span",{className:d?"text-xs":"",children:e("update.available",{latest:K.latestVersion,current:K.currentVersion})}),i.jsxs("span",{className:"flex items-center gap-3 shrink-0",children:[i.jsx("a",{href:"https://markus.global/#download",target:"_blank",rel:"noopener noreferrer",className:"text-xs font-medium text-brand-400 hover:text-brand-300 transition-colors",children:e("update.download")}),i.jsx("button",{onClick:()=>{te(K.latestVersion),localStorage.setItem("markus_update_dismissed",K.latestVersion)},className:"text-fg-tertiary hover:text-fg-secondary text-xs shrink-0",children:e("dismiss")})]})]}),i.jsx("main",{className:"flex-1 overflow-hidden flex flex-col relative",children:Object.keys(Se).map(X=>h.has(X)?i.jsx(Hie,{id:X,activePage:t,children:Se[X]},X):null)})]}),d&&t!==de.SETTINGS&&t!==de.SEARCH&&i.jsx(Tre,{currentPage:t,onNavigate:Ne,userId:ae?.id}),d&&i.jsx(TU,{authUser:ae,onNavigate:Ne,onLogout:()=>{Ae.auth.logout().catch(()=>{}),Ds(),y(null)}}),!d&&I&&i.jsx(Tie,{onClose:()=>J(!1),currentPage:t}),!d&&i.jsx(_ie,{open:me,onClose:()=>Ce(!1),page:t}),w&&ae&&i.jsx(Rie,{authUser:ae,onClose:()=>T(!1),onUserUpdated:X=>y(X),onSaved:X=>{T(!1),y(X)}})]})}const Bk="data-anim-paused",Hk="data-anim-tick",$k=8,qie=250;function Fie(){return document.visibilityState!=="visible"||document.hidden?!0:!document.hasFocus()}let xc=null,Po=0;function Uie(){xc===null&&(Po=Po%$k,document.documentElement.setAttribute(Hk,String(Po)),xc=window.setInterval(()=>{Po=(Po+1)%$k,document.documentElement.setAttribute(Hk,String(Po))},qie))}function Gie(){xc!==null&&(window.clearInterval(xc),xc=null)}function oc(){const e=document.documentElement;Fie()?(e.setAttribute(Bk,"true"),Gie()):(e.removeAttribute(Bk),Uie())}let qk=!1;function Kie(){qk||typeof document>"u"||(qk=!0,oc(),document.addEventListener("visibilitychange",oc,{passive:!0}),window.addEventListener("focus",oc,{passive:!0}),window.addEventListener("blur",oc,{passive:!0}),window.addEventListener("pageshow",oc,{passive:!0}))}Kie();wA.createRoot(document.getElementById("root")).render(i.jsx(k.StrictMode,{children:i.jsx(Lte,{children:i.jsx($ie,{})})}));export{Hse as $,Zi as A,Qo as B,li as C,yne as D,Ps as E,ba as F,lU as G,Zie as H,cie as I,gb as J,rse as K,bg as L,g4 as M,fre as N,vne as O,de as P,yg as Q,Wie as R,oie as S,Xre as T,Eae as U,Nae as V,ese as W,sse as X,ise as Y,Go as Z,va as _,Xo as a,Ase as a$,Yie as a0,xr as a1,pT as a2,gse as a3,sU as a4,Qie as a5,Xie as a6,_s as a7,Md as a8,fi as a9,Bse as aA,Tse as aB,Mse as aC,ase as aD,pse as aE,bb as aF,x4 as aG,f4 as aH,wse as aI,kse as aJ,Sse as aK,Rse as aL,Jw as aM,rne as aN,zse as aO,_se as aP,Ose as aQ,Dse as aR,dk as aS,mk as aT,mre as aU,Pse as aV,Nse as aW,jse as aX,IS as aY,Pv as aZ,Cse as a_,mm as aa,Ise as ab,one as ac,Lw as ad,Oae as ae,zs as af,rl as ag,xse as ah,bse as ai,mse as aj,yse as ak,hse as al,fse as am,lse as an,Kae as ao,use as ap,vse as aq,Xae as ar,Lse as as,VS as at,dse as au,$ae as av,ose as aw,Jie as ax,cse as ay,Sre as az,vU as b,Ese as b0,nse as b1,PS as b2,qc as c,mie as d,eie as e,rie as f,Is as g,st as h,Ov as i,i as j,zr as k,Ae as l,wie as m,at as n,jn as o,kc as p,Ea as q,k as r,hb as s,Ha as t,ot as u,Vie as v,Ir as w,Ic as x,zm as y,hT as z};
882
+ ${t("share.rejectedEncourage")}`})},className:"text-xs px-2 py-1.5 rounded-lg border border-red-500/30 text-red-400 hover:bg-red-500/10 transition-colors inline-flex items-center gap-1 cursor-pointer",title:t("share.rejectedTip"),children:[i.jsxs("svg",{className:"w-3 h-3",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[i.jsx("circle",{cx:"12",cy:"12",r:"10"}),i.jsx("line",{x1:"15",y1:"9",x2:"9",y2:"15"}),i.jsx("line",{x1:"9",y1:"9",x2:"15",y2:"15"})]}),t("share.rejected")]}),i.jsxs("button",{onClick:()=>{rt(ce,{visibility:Ne?.visibility??"public"})},disabled:!!Me,className:"text-xs px-3 py-1.5 rounded-lg border border-brand-500/40 text-brand-400 hover:bg-brand-500/10 hover:border-brand-500/60 transition-colors disabled:opacity-50 inline-flex items-center gap-1",title:t("share.rejectedTip"),children:[i.jsxs("svg",{className:"w-3 h-3",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[i.jsx("polyline",{points:"23 4 23 10 17 10"}),i.jsx("polyline",{points:"1 20 1 14 7 14"}),i.jsx("path",{d:"M3.51 9a9 9 0 0 1 14.85-3.36L23 10M1 14l4.64 4.36A9 9 0 0 0 20.49 15"})]}),t(Me==="share"?"common:sharing":"share.resubmit")]})]}):q?i.jsxs(i.Fragment,{children:[ae&&i.jsxs("button",{onClick:()=>{const Ie=Ne?.visibility??"public";rt(ce,{visibility:Ie})},disabled:!!Me,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 inline-flex items-center gap-1",children:[i.jsxs("svg",{className:"w-3 h-3",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[i.jsx("polyline",{points:"23 4 23 10 17 10"}),i.jsx("polyline",{points:"1 20 1 14 7 14"}),i.jsx("path",{d:"M3.51 9a9 9 0 0 1 14.85-3.36L23 10M1 14l4.64 4.36A9 9 0 0 0 20.49 15"})]}),Me==="share"?t("common:sharing"):t("share.updateVersion",{version:se})]}),i.jsxs("a",{href:Se()??"#",target:"_blank",rel:"noopener noreferrer",onClick:Ie=>{const Ge=Se();Go()&&Ge&&(Ie.preventDefault(),fi(Ge))},className:`text-xs px-3 py-1.5 rounded-lg border transition-colors inline-flex items-center gap-1 ${Ne?.visibility==="org"?"border-blue-500/30 text-blue-500 hover:text-blue-400 hover:border-blue-400/40":Ne?.visibility==="unlisted"?"border-gray-500/30 text-fg-tertiary hover:text-fg-secondary hover:border-gray-400/40":"border-green-600/30 text-green-600 hover:text-green-500 hover:border-green-500/40"}`,children:[Ne?.visibility==="org"?i.jsxs("svg",{className:"w-3 h-3",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[i.jsx("path",{d:"M3 21h18"}),i.jsx("path",{d:"M9 8h1"}),i.jsx("path",{d:"M9 12h1"}),i.jsx("path",{d:"M9 16h1"}),i.jsx("path",{d:"M14 8h1"}),i.jsx("path",{d:"M14 12h1"}),i.jsx("path",{d:"M14 16h1"}),i.jsx("path",{d:"M5 21V5a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2v16"})]}):Ne?.visibility==="unlisted"?i.jsxs("svg",{className:"w-3 h-3",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[i.jsx("path",{d:"M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"}),i.jsx("path",{d:"M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"})]}):i.jsxs("svg",{className:"w-3 h-3",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[i.jsx("path",{d:"M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"}),i.jsx("polyline",{points:"15 3 21 3 21 9"}),i.jsx("line",{x1:"10",y1:"14",x2:"21",y2:"3"})]}),Ne?.visibility==="org"?t("visibility.sharedOrg"):Ne?.visibility==="unlisted"?t("visibility.sharedUnlisted"):t("visibility.shared")]}),i.jsxs("button",{onClick:()=>Q({key:we,name:et}),disabled:!!Me,className:"text-xs px-2.5 py-1.5 rounded-lg border border-border-default text-fg-secondary hover:text-amber-500 hover:border-amber-500/40 hover:bg-amber-500/10 transition-colors disabled:opacity-50 inline-flex items-center gap-1",title:t("removeFromHubTooltip"),children:[i.jsxs("svg",{className:"w-3 h-3",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[i.jsx("path",{d:"M18.84 12.25l1.72-1.71a5 5 0 0 0-7.07-7.07l-1.72 1.71"}),i.jsx("path",{d:"M5.17 11.75l-1.71 1.71a5 5 0 0 0 7.07 7.07l1.71-1.71"}),i.jsx("line",{x1:"2",y1:"2",x2:"22",y2:"22"})]}),t("unshare")]})]}):i.jsxs("button",{onClick:async()=>{await st.ensureAuth(),Array.isArray(ce.meta.screenshots)&&ce.meta.screenshots.length>0?J(ce):ee(ce)},disabled:!!Me,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 inline-flex items-center gap-1",children:[i.jsxs("svg",{className:"w-3 h-3",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[i.jsx("circle",{cx:"18",cy:"5",r:"3"}),i.jsx("circle",{cx:"6",cy:"12",r:"3"}),i.jsx("circle",{cx:"18",cy:"19",r:"3"}),i.jsx("line",{x1:"8.59",y1:"13.51",x2:"15.42",y2:"17.49"}),i.jsx("line",{x1:"15.41",y1:"6.51",x2:"8.59",y2:"10.49"})]}),t(Me==="share"?"common:sharing":"common:share")]})]}),X=i.jsx("button",{onClick:()=>S(ce),disabled:!!Me,className:"w-7 h-7 rounded-lg text-fg-muted hover:text-red-500 hover:bg-red-500/10 transition-colors disabled:opacity-50 inline-flex items-center justify-center",title:t("deleteLocalTooltip"),children:i.jsxs("svg",{className:"w-3.5 h-3.5",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[i.jsx("polyline",{points:"3 6 5 6 21 6"}),i.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"})]})}),Z=ce.meta.icon,Be=!!Z&&/\.(png|jpe?g|gif|webp|svg)$/i.test(Z)?Z.startsWith("http")||Z.startsWith("/")?Z:`/api/builder/artifacts/${ce.type}s/${encodeURIComponent(ce.name)}/images/${encodeURIComponent(Z.split("/").pop()??"")}?v=${ce.updatedAt??""}`:Z;return i.jsx(vr,{type:ce.type,name:et,description:nt,seed:we,icon:Be,version:se,footerLeft:i.jsxs("span",{className:"flex items-center gap-2 text-[10px] text-fg-tertiary min-w-0",children:[i.jsx("button",{onClick:Ie=>{Ie.stopPropagation(),Ae.system.openPath(ce.path).catch(()=>{})},className:"hover:text-fg-secondary transition-colors truncate min-w-0",title:ce.path,children:qre(ce.path)}),i.jsx("span",{className:"shrink-0",children:"·"}),i.jsx("span",{className:"shrink-0",children:new Date(ce.updatedAt).toLocaleDateString()})]}),headerAction:X,actions:Pe,onClick:()=>ln(ce)},we)})})),E&&i.jsx(ba,{variant:"primary",title:t("confirmInstall"),message:t("confirmInstallMsg",{name:E.meta.displayName||E.meta.name||E.name}),confirmLabel:t("common:install"),onConfirm:()=>{const ce=E;_(null),Zt(ce)},onCancel:()=>_(null)}),L&&i.jsx(ba,{variant:"primary",title:t("confirmUninstall"),message:t("confirmUninstallMsg",{name:L.meta.displayName||L.meta.name||L.name}),confirmLabel:t("common:uninstall"),onConfirm:()=>{const ce=L;D(null),Wt(ce)},onCancel:()=>D(null)}),C&&i.jsx(ba,{title:t("confirmDeleteLocal"),message:t("deleteCannotUndo",{name:C.meta.displayName||C.meta.name||C.name}),confirmLabel:t("common:delete"),onConfirm:mt,onCancel:()=>S(null)}),G&&i.jsx(ba,{title:t("confirmUnshare"),message:t("removeFromHub",{name:G.name}),confirmLabel:t("unshare"),onConfirm:()=>{$e()},onCancel:()=>Q(null)}),$&&i.jsx(ba,{alertOnly:!0,variant:$.variant??"primary",title:$.title,message:$.message,onConfirm:()=>Y(null),onCancel:()=>Y(null)}),K&&i.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm",onClick:()=>ee(null),children:i.jsxs("div",{className:"bg-surface-secondary border border-border-default rounded-xl max-w-sm w-full mx-4 p-6 shadow-2xl",onClick:ce=>ce.stopPropagation(),children:[i.jsx("h3",{className:"text-base font-semibold text-fg-primary mb-2",children:t("common:share")}),i.jsx("p",{className:"text-sm text-fg-secondary mb-5",children:t("share.imagePrompt")}),i.jsxs("div",{className:"flex gap-3",children:[i.jsx("button",{onClick:()=>{const ce=K;ee(null),J(ce)},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")}),i.jsx("button",{onClick:()=>{const ce=K;ee(null),ln(ce)},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")})]})]})}),U&&i.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm",onClick:()=>te(null),children:i.jsx("div",{className:"bg-surface-secondary border border-border-default rounded-xl max-w-sm w-full mx-4 p-6 shadow-2xl",onClick:ce=>ce.stopPropagation(),children:i.jsx(Vre,{isUpdate:M.has(`${U.type}/${U.name}`),onCancel:()=>te(null),onConfirm:(ce,et)=>{const nt=U;te(null),rt(nt,{priceCents:et>0?et:void 0})}})})}),I&&i.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm",onClick:()=>J(null),children:i.jsx("div",{className:"bg-surface-secondary border border-border-default rounded-xl max-w-sm w-full mx-4 p-6 shadow-2xl",onClick:ce=>ce.stopPropagation(),children:i.jsx(Kre,{onCancel:()=>J(null),onConfirm:(ce,et,nt,we)=>{const Me=I;J(null),rt(Me,{visibility:ce,orgId:et,priceCents:nt,donationsEnabled:we})}})})})]})})}function Kre({onCancel:e,onConfirm:t}){const{t:n}=ot(["builder","common"]),[a,s]=k.useState("public"),[l,c]=k.useState([]),[d,m]=k.useState(""),[p,h]=k.useState(!1),[g,x]=k.useState(0),[y,w]=k.useState(!1);k.useEffect(()=>{a==="org"&&l.length===0&&(h(!0),st.myOrgs().then(S=>{c(S.memberships),S.memberships.length>0&&m(S.memberships[0].id)}).catch(()=>{}).finally(()=>h(!1)))},[a,l.length]);const T=a==="public"||a==="unlisted",C=[{value:"public",icon:i.jsxs("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[i.jsx("circle",{cx:"12",cy:"12",r:"10"}),i.jsx("line",{x1:"2",y1:"12",x2:"22",y2:"12"}),i.jsx("path",{d:"M12 2a15.3 15.3 0 0 1 4 10 15.3 15.3 0 0 1-4 10 15.3 15.3 0 0 1-4-10 15.3 15.3 0 0 1 4-10z"})]}),label:n("visibility.public"),desc:n("visibility.publicDesc")},{value:"org",icon:i.jsxs("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[i.jsx("path",{d:"M3 21h18"}),i.jsx("path",{d:"M9 8h1"}),i.jsx("path",{d:"M9 12h1"}),i.jsx("path",{d:"M9 16h1"}),i.jsx("path",{d:"M14 8h1"}),i.jsx("path",{d:"M14 12h1"}),i.jsx("path",{d:"M14 16h1"}),i.jsx("path",{d:"M5 21V5a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2v16"})]}),label:n("visibility.org"),desc:n("visibility.orgDesc")},{value:"unlisted",icon:i.jsxs("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[i.jsx("path",{d:"M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"}),i.jsx("path",{d:"M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"})]}),label:n("visibility.unlisted"),desc:n("visibility.unlistedDesc")}];return i.jsxs(i.Fragment,{children:[i.jsx("h3",{className:"text-base font-semibold text-fg-primary mb-4",children:n("visibility.label")}),i.jsx("div",{className:"space-y-2 mb-5",children:C.map(S=>i.jsxs("label",{className:`flex items-center gap-3 p-3 rounded-lg border cursor-pointer transition-colors ${a===S.value?"border-brand-500 bg-brand-500/10":"border-border-default hover:border-gray-600"}`,children:[i.jsx("input",{type:"radio",name:"visibility",checked:a===S.value,onChange:()=>s(S.value),className:"accent-brand-500"}),i.jsx("div",{className:"flex items-center gap-2 text-fg-secondary",children:S.icon}),i.jsxs("div",{children:[i.jsx("div",{className:"text-sm font-medium text-fg-primary",children:S.label}),i.jsx("div",{className:"text-[11px] text-fg-tertiary",children:S.desc})]})]},S.value))}),a==="org"&&i.jsxs("div",{className:"mb-5",children:[i.jsx("label",{className:"text-xs text-fg-secondary block mb-1.5",children:n("visibility.orgSelect")}),p?i.jsx("div",{className:"text-xs text-fg-tertiary py-2",children:"Loading..."}):l.length===0?i.jsx("div",{className:"text-xs text-fg-tertiary py-2",children:n("visibility.orgNone")}):i.jsx("select",{value:d,onChange:S=>m(S.target.value),className:"w-full text-sm px-3 py-2 rounded-lg bg-surface-elevated border border-border-default text-fg-primary",children:l.map(S=>i.jsx("option",{value:S.id,children:S.name},S.id))})]}),T&&i.jsxs("div",{className:"mb-5",children:[i.jsx("label",{className:"text-xs text-fg-secondary block mb-1.5",children:n("pricing.label")}),i.jsx("div",{className:"grid grid-cols-4 gap-2 mb-3",children:o6.map(S=>i.jsx("button",{type:"button",onClick:()=>x(S.cents),className:`text-sm px-2 py-2 rounded-lg border transition-colors ${g===S.cents?"border-brand-500 bg-brand-500/10 text-fg-primary":"border-border-default text-fg-secondary hover:border-gray-600"}`,children:S.label},S.cents))}),i.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[i.jsx("input",{type:"checkbox",checked:y,onChange:S=>w(S.target.checked),className:"accent-brand-500"}),i.jsx("span",{className:"text-xs text-fg-secondary",children:n("pricing.enableTips")})]})]}),T&&i.jsx("div",{className:"mb-4 text-[11px] text-fg-tertiary rounded-lg border border-border-default px-3 py-2",children:n("pricing.reviewNote")}),i.jsxs("div",{className:"flex gap-3",children:[i.jsx("button",{onClick:e,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:n("common:cancel")}),i.jsx("button",{onClick:()=>t(a,a==="org"?d:void 0,T&&g>0?g:void 0,T?y:void 0),disabled:a==="org"&&!d,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:n("shareMode.share")})]})]})}const o6=[{cents:0,label:"Free"},{cents:100,label:"$1"},{cents:500,label:"$5"},{cents:1e3,label:"$10"}];function Vre({isUpdate:e,onCancel:t,onConfirm:n}){const{t:a}=ot(["builder","common"]),[s,l]=k.useState(0);return i.jsxs(i.Fragment,{children:[i.jsx("h3",{className:"text-base font-semibold text-fg-primary mb-4",children:a(e?"shareMode.titleUpdate":"shareMode.title")}),i.jsx("div",{className:"space-y-2 mb-5",children:o6.map(c=>i.jsxs("label",{className:`flex items-center gap-3 p-3 rounded-lg border cursor-pointer transition-colors ${s===c.cents?"border-brand-500 bg-brand-500/10":"border-border-default hover:border-gray-600"}`,children:[i.jsx("input",{type:"radio",name:"sharePrice",checked:s===c.cents,onChange:()=>l(c.cents),className:"accent-brand-500"}),i.jsxs("div",{children:[i.jsx("div",{className:"text-sm font-medium text-fg-primary",children:c.label}),i.jsx("div",{className:"text-[11px] text-fg-tertiary",children:c.cents===0?a("shareMode.freeDesc"):a("shareMode.paidDesc")})]})]},c.cents))}),i.jsxs("div",{className:"flex gap-3",children:[i.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:a("common:cancel")}),i.jsx("button",{onClick:()=>n(s>0?"paid":"free",s),className:"flex-1 text-sm px-4 py-2 rounded-lg bg-brand-600 hover:bg-brand-500 text-white transition-colors",children:a(e?"shareMode.update":"shareMode.share")})]})]})}const Wre=Object.freeze(Object.defineProperty({__proto__:null,AgentBuilder:s6},Symbol.toStringTag,{value:"Module"}));async function l6(e,t){if(!t)return{items:e,highlighted:null,missing:!1};const n=e.find(a=>a.id===t);if(n)return{items:[n,...e.filter(a=>a.id!==t)],highlighted:n,missing:!1};try{const{item:a}=await st.getItem(t);return a?{items:[a,...e],highlighted:a,missing:!1}:{items:e,highlighted:null,missing:!0}}catch{return{items:e,highlighted:null,missing:!0}}}function Yre(e,t){const n=e.split(".").map(Number),a=t.split(".").map(Number);for(let s=0;s<Math.max(n.length,a.length);s++){const l=n[s]??0,c=a[s]??0;if(l>c)return!0;if(l<c)return!1}return!1}function Pm(e,t){const n=e.i18n?.[t];return n?.displayName||n?.name||e.name}function xk(e,t){return e.i18n?.[t]?.description||e.description}const Qre={manager:"bg-brand-500/15 text-brand-500",worker:"bg-blue-500/15 text-blue-600"};function Xre({authUser:e,highlightItemId:t,onHighlightDone:n}={}){const{t:a,i18n:s}=ot(["store","common"]),l=s.language,[c,d]=k.useState(""),[m,p]=k.useState([]),[h,g]=k.useState([]),[x,y]=k.useState(null),[w,T]=k.useState({}),[C,S]=k.useState(!1),[E,_]=k.useState(!0),[L,D]=k.useState(new Map),[M,O]=k.useState(new Set),[G,Q]=k.useState(null),[$,Y]=k.useState(null),K=k.useCallback(async()=>{try{const[te,I]=await Promise.all([Ae.builder.artifacts.list().catch(()=>({artifacts:[]})),Ae.builder.artifacts.installed().catch(()=>({installed:{}}))]),J=new Map;for(const me of te.artifacts){if(me.type!=="agent")continue;const Ce=!!I.installed[`agent/${me.name}`];J.set(me.name,{installed:Ce,localVersion:me.meta.version||void 0,localUpdatedAt:me.updatedAt})}D(J)}catch{}},[]),ee=k.useCallback(async()=>{_(!0);try{const te=c?st.search({type:"agent",q:c,limit:50}):Ls(qa.hubAgents)??st.search({type:"agent",limit:50}),I=new URLSearchParams;c&&I.set("q",c);const J=fetch("/api/templates?"+I.toString()).then(V=>V.json()).catch(()=>({templates:[]})),[me,Ce]=await Promise.all([te.catch(()=>({items:[],total:0})),J,K(),st.isAuthenticated()?st.purchases.mine().then(V=>O(new Set(V.purchases.map(fe=>fe.itemId)))).catch(()=>{}):Promise.resolve()]),H=await l6(me?.items??[],t);g(H.items),p(Array.isArray(Ce.templates)?Ce.templates:[]),H.missing&&n?.()}catch{p([]),g([])}finally{_(!1)}},[c,K,t,n]);k.useEffect(()=>{ee()},[ee]),k.useEffect(()=>{if(!x){T({});return}fetch(`/api/templates/${encodeURIComponent(x.id)}/files`,{credentials:"include"}).then(te=>te.json()).then(te=>T(te.files??{})).catch(()=>T({}))},[x]);const U=async(te,I,J)=>{try{const me=await fetch("/api/templates/instantiate",{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({templateId:te,name:I,orgId:"default",teamId:J})});if(!me.ok)throw new Error(`Failed: ${me.status}`);S(!1),y(null)}catch(me){Y({title:a("common:create",{defaultValue:"Create"}),message:`Failed to create agent: ${me}`,variant:"danger"})}};if(G)return i.jsx(qs,{type:G.type,name:G.name,onBack:()=>Q(null)});if(x){const te={type:"agent",name:x.id,displayName:Pm(x,l),version:x.version,description:xk(x,l),author:x.author,category:x.category,tags:x.tags,icon:x.icon,files:w,agent:{roleName:x.roleId,agentRole:x.agentRole==="manager"?"manager":"worker"},dependencies:{skills:x.skills}},I=i.jsxs("div",{className:"space-y-6",children:[i.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[i.jsxs("div",{className:"rounded-xl border border-border-default bg-surface-secondary/40 p-5",children:[i.jsx("h3",{className:"text-xs text-fg-tertiary uppercase tracking-wider mb-3",children:a("agentStore.roleConfig")}),i.jsxs("div",{className:"space-y-2.5 text-sm",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("span",{className:"text-fg-tertiary w-20",children:a("agentStore.role")}),i.jsx("span",{className:"text-fg-secondary font-mono text-xs bg-surface-elevated px-2 py-0.5 rounded",children:x.roleId})]}),i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("span",{className:"text-fg-tertiary w-20",children:a("agentStore.position")}),i.jsx("span",{className:`px-2 py-0.5 rounded text-xs capitalize ${Qre[x.agentRole]??""}`,children:x.agentRole})]})]})]}),i.jsxs("div",{className:"rounded-xl border border-border-default bg-surface-secondary/40 p-5",children:[i.jsx("h3",{className:"text-xs text-fg-tertiary uppercase tracking-wider mb-3",children:a("agentStore.skills")}),i.jsxs("div",{className:"flex flex-wrap gap-1.5",children:[x.skills.map(J=>i.jsx("span",{className:"px-2.5 py-1 text-xs bg-brand-500/10 text-brand-500 rounded-lg border border-brand-500/20",children:J},J)),x.skills.length===0&&i.jsx("span",{className:"text-xs text-fg-tertiary italic",children:a("agentStore.noSkills")})]})]})]}),x.starterTasks&&x.starterTasks.length>0&&i.jsxs("div",{className:"rounded-xl border border-border-default bg-surface-secondary/40 p-5",children:[i.jsx("h3",{className:"text-xs text-fg-tertiary uppercase tracking-wider mb-3",children:a("agentStore.starterTasks")}),i.jsx("div",{className:"space-y-2",children:x.starterTasks.map((J,me)=>i.jsxs("div",{className:"flex items-start gap-3 bg-surface-elevated/50 rounded-lg p-3",children:[i.jsx("span",{className:`inline-block w-2 h-2 rounded-full shrink-0 mt-1 ${J.priority==="high"?"bg-red-400":J.priority==="medium"?"bg-amber-400":"bg-green-400"}`}),i.jsxs("div",{children:[i.jsx("div",{className:"text-sm text-fg-primary",children:J.title}),J.description&&i.jsx("div",{className:"text-xs text-fg-tertiary mt-0.5",children:J.description})]})]},me))})]})]});return i.jsxs(i.Fragment,{children:[i.jsx(qs,{type:"agent",name:x.id,onBack:()=>y(null),readOnly:!0,initialManifest:te,actionSlot:i.jsx("button",{onClick:()=>S(!0),className:"px-4 py-1.5 text-xs bg-brand-600 hover:bg-brand-500 text-white rounded-lg transition-colors font-medium",children:a("agentStore.hireAgent")}),contentSlot:I}),C&&i.jsx(vk,{template:x,lang:l,onClose:()=>S(!1),onHire:U}),$&&i.jsx(ba,{alertOnly:!0,variant:$.variant??"danger",title:$.title,message:$.message,onConfirm:()=>Y(null),onCancel:()=>Y(null)})]})}return i.jsxs("div",{className:"flex-1 overflow-hidden flex flex-col",children:[i.jsxs("div",{"data-electron-drag":!0,className:"px-6 h-14 flex items-center justify-between shrink-0 gap-3",children:[i.jsx("h2",{className:"text-lg font-semibold",children:a("agentStore.title")}),i.jsx("input",{type:"text",placeholder:a("agentStore.searchPlaceholder"),value:c,onChange:te=>d(te.target.value),className:"px-3 py-1.5 bg-surface-elevated border border-border-default rounded-lg text-sm max-w-xs w-full focus:border-brand-500 focus:outline-none"})]}),i.jsx("div",{className:"flex-1 overflow-y-auto p-7 space-y-8",children:E?i.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4",children:Array.from({length:6}).map((te,I)=>i.jsx("div",{className:"h-56 rounded-2xl skeleton"},I))}):m.length===0&&h.length===0?i.jsxs("div",{className:"text-center py-20",children:[i.jsx("div",{className:"text-4xl mb-4 opacity-30",children:"⧉"}),i.jsx("div",{className:"text-fg-secondary font-medium mb-1",children:c?a("agentStore.noResults",{search:c}):a("agentStore.noAgents")}),i.jsx("div",{className:"text-fg-tertiary text-sm",children:a(c?"agentStore.noResultsHint":"agentStore.noAgentsHint")})]}):i.jsxs(i.Fragment,{children:[m.length>0&&i.jsxs("section",{children:[i.jsxs("div",{className:"flex items-baseline gap-2 mb-3",children:[i.jsx("h3",{className:"section-title",children:a("agentStore.builtin")}),i.jsx("span",{className:"text-xs text-fg-tertiary",children:a("agentStore.available",{count:m.length})})]}),i.jsx(Fa,{columns:3,children:m.map(te=>i.jsx(vr,{type:"agent",name:Pm(te,l),description:xk(te,l),seed:te.id,icon:te.icon,version:te.version,category:te.category,tags:te.tags,authorLabel:te.author,hideStats:!0,showTypeBadge:!1,cornerLabel:a("agentStore.builtin"),onClick:()=>y(te)},te.id))})]}),h.length>0&&i.jsxs("section",{children:[i.jsx("h3",{className:"section-title mb-3",children:a("agentStore.markusHub")}),i.jsx(Fa,{columns:3,children:h.map(te=>i.jsx(Jre,{item:te,localInfo:L.get(Fc(te)),purchased:cm(te,M),onStatusChange:K,highlight:te.id===t,onHighlightDone:n,onViewDetail:I=>Q({type:"agent",name:I})},te.id))})]})]})}),C&&x&&i.jsx(vk,{template:x,lang:l,onClose:()=>S(!1),onHire:U}),$&&i.jsx(ba,{alertOnly:!0,variant:$.variant??"danger",title:$.title,message:$.message,onConfirm:()=>Y(null),onCancel:()=>Y(null)})]})}function Fc(e,t){if(e.slug&&e.slug.trim())return e.slug.trim();const n=t&&typeof t.name=="string"?t.name.trim():"";return mm(n||e.name,"hub-pkg")}function Is(e){return(async()=>{const t=await st.download(e.id),n=t.name||e.name,a=t.config??{},s=Fc(e,a),l=t.itemType==="team"?"team":t.itemType==="skill"?"skill":"agent",c={type:"hub",hubItemId:e.id},d=(t.version||e.version||(typeof a.version=="string"?a.version:"")||"").trim()||void 0;if(t.files&&Object.keys(t.files).length>0)await Ae.builder.artifacts.import(l,s,t.files,c,d);else{const m={...a,...d?{version:d}:{},name:s,displayName:a.displayName||n,description:e.description,source:c};await Ae.builder.artifacts.save(l,m)}return await Ae.builder.artifacts.install(l,s),window.dispatchEvent(new CustomEvent("markus:data-changed")),n})()}async function vb(e,t){t("checking"),await st.ensureAuth();const n=await st.purchases.checkout(e.id);if(n.alreadyOwned)return t("installing"),await Is(e),"installed";try{if((await st.creator.getBalance()).availableBalance>=(e.priceCents??0)){const c=await st.purchases.payWithEarnings(e.id);if(c.ok||c.alreadyOwned)return t("installing"),await Is(e),"installed"}}catch{}if(!n.checkoutUrl)throw new Error("No checkout URL");t("checkout_opened");const a=Go();let s=null;return a?fi(n.checkoutUrl):s=window.open(n.checkoutUrl,"_blank","noopener"),new Promise((l,c)=>{const d=Date.now(),m=300*1e3,p=setInterval(async()=>{if(Date.now()-d>m){clearInterval(p),l("cancelled");return}const g=!a&&s?s.closed:!1;try{if((await st.purchases.checkout(e.id)).alreadyOwned){clearInterval(p),t("installing");try{await Is(e),l("installed")}catch(y){c(y)}return}}catch{}if(g){clearInterval(p);try{if((await st.purchases.checkout(e.id)).alreadyOwned){t("installing"),await Is(e),l("installed");return}}catch{}l("cancelled")}},2e3)})}function Jre({item:e,localInfo:t,purchased:n,onStatusChange:a,highlight:s,onHighlightDone:l,onViewDetail:c}){const{t:d}=ot(["store"]),[m,p]=k.useState(!1),[h,g]=k.useState(""),x=k.useRef(null),[y,w]=k.useState(!1);k.useEffect(()=>{if(s&&x.current){x.current.scrollIntoView({behavior:"smooth",block:"center"}),w(!0);const G=setTimeout(()=>{w(!1)},4e3);return()=>clearTimeout(G)}},[s,l]);const T=t?.installed??!1,C=T&&e.version&&t?.localVersion&&Yre(e.version,t.localVersion),S=(e.priceCents??0)>0,E=async G=>{if(G.stopPropagation(),!m){p(!0),g("");try{await Is(e),g(C?d("card.upgraded"):d("card.installed")+"!"),a()}catch(Q){const $=Q instanceof Error?Q.message:"";$.includes("402")||$.includes("Purchase required")?g(d("card.purchaseRequired")):g(d("card.failed"))}finally{p(!1)}}},_=async G=>{if(G.stopPropagation(),!m){p(!0),g("");try{await vb(e,$=>{$==="checkout_opened"?g(d("card.waitingPurchase","Waiting for purchase...")):$==="installing"&&g(d("card.installing"))})==="installed"?(g(d("card.installed")+"!"),a()):g("")}catch(Q){g(Q instanceof Error?Q.message:d("card.failed"))}finally{p(!1)}}},L=S?`$${((e.priceCents??0)/100).toFixed(2)}`:null,D=e.slug&&e.author?.username?`${st.getUrl()}/@${encodeURIComponent(e.author.username)}/${encodeURIComponent(e.slug)}`:null,M=()=>{T&&c?c(Fc(e)):D&&window.open(D,"_blank","noopener,noreferrer")},O=i.jsxs(i.Fragment,{children:[C?i.jsx("button",{onClick:G=>{E(G)},disabled:m,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:m?d("card.upgrading"):d("card.upgrade",{version:e.version})}):T?i.jsxs("button",{onClick:G=>{E(G)},disabled:m,className:"px-3 py-1.5 text-xs bg-surface-elevated hover:bg-surface-overlay text-fg-secondary border border-border-default rounded-lg transition-colors disabled:opacity-50",children:[d("card.installed"),t?.localVersion?` v${t.localVersion}`:""]}):S&&!n?i.jsx("button",{onClick:G=>{_(G)},disabled:m,className:"px-3 py-1.5 text-xs bg-amber-600 hover:bg-amber-500 text-white rounded-lg transition-colors disabled:opacity-50 inline-flex items-center gap-1",children:m?h||d("card.installing"):i.jsxs(i.Fragment,{children:[d("card.buy","Buy")," ",L]})}):i.jsx("button",{onClick:G=>{E(G)},disabled:m,className:"px-3 py-1.5 text-xs bg-brand-600 hover:bg-brand-500 text-white rounded-lg transition-colors disabled:opacity-50",children:d(m?"card.installing":"card.install")}),h&&!(S&&!n)&&i.jsx("span",{className:`text-[10px] ${h===d("card.failed")||h===d("card.purchaseRequired")?"text-red-500":"text-green-600"}`,children:h})]});return i.jsx("div",{ref:x,className:y?"animate-pulse":"",children:i.jsx(vr,{type:"agent",showTypeBadge:!1,name:e.name,description:e.description,seed:e.slug||e.name,icon:e.icon||"bot",cover:e.thumbnailUrl,hubBase:st.getUrl(),author:e.author,version:e.version,category:e.category,tags:e.tags,rating:parseFloat(e.avgRating)||0,ratingCount:e.ratingCount,downloadCount:e.downloadCount,priceCents:e.priceCents,currency:e.currency,installed:T,glowing:y,onClick:M,actions:O})})}function vk({template:e,lang:t,onClose:n,onHire:a}){const{t:s}=ot(["store"]),[l,c]=k.useState(`${Pm(e,t)} Agent`),[d,m]=k.useState(""),[p,h]=k.useState([]),[g,x]=k.useState(!1);k.useEffect(()=>{fetch("/api/teams",{credentials:"include"}).then(w=>w.json()).then(w=>h(w.teams??[])).catch(()=>{})},[]);const y=async()=>{if(l.trim()){x(!0);try{await a(e.id,l.trim(),d||void 0)}finally{x(!1)}}};return i.jsx("div",{className:"fixed inset-0 bg-black/60 flex items-center justify-center z-50",onClick:n,children:i.jsxs("div",{className:"bg-surface-secondary border border-border-default rounded-xl p-6 w-[440px] shadow-2xl",onClick:w=>w.stopPropagation(),children:[i.jsx("div",{className:"flex items-center gap-3 mb-5",children:i.jsxs("div",{children:[i.jsx("h3",{className:"text-base font-semibold",children:s("hireModal.title")}),i.jsx("p",{className:"text-xs text-fg-tertiary",children:s("hireModal.creating",{name:Pm(e,t)})})]})}),i.jsxs("div",{className:"space-y-4",children:[i.jsxs("div",{children:[i.jsx("label",{className:"block text-xs text-fg-tertiary mb-1.5",children:s("hireModal.agentName")}),i.jsx("input",{type:"text",value:l,onChange:w=>c(w.target.value),className:"input-field",autoFocus:!0})]}),p.length>0&&i.jsxs("div",{children:[i.jsx("label",{className:"block text-xs text-fg-tertiary mb-1.5",children:s("hireModal.assignTeam")}),i.jsxs("select",{value:d,onChange:w=>m(w.target.value),className:"input-field",children:[i.jsx("option",{value:"",children:s("hireModal.noTeam")}),p.map(w=>i.jsx("option",{value:w.id,children:w.name},w.id))]})]}),i.jsxs("div",{className:"bg-surface-elevated/50 rounded-lg p-3",children:[i.jsx("div",{className:"text-xs text-fg-tertiary mb-2 font-medium",children:s("hireModal.agentConfig")}),i.jsxs("div",{className:"grid grid-cols-2 gap-y-1.5 gap-x-4 text-xs",children:[i.jsx("div",{className:"text-fg-tertiary",children:s("hireModal.role")}),i.jsx("div",{className:"text-fg-secondary font-mono",children:e.roleId}),i.jsx("div",{className:"text-fg-tertiary",children:s("hireModal.position")}),i.jsx("div",{className:"text-fg-secondary capitalize",children:e.agentRole}),i.jsx("div",{className:"text-fg-tertiary",children:s("hireModal.skills")}),i.jsx("div",{className:"text-fg-secondary",children:e.skills.join(", ")||s("hireModal.none")})]})]})]}),i.jsxs("div",{className:"flex justify-end gap-3 mt-6",children:[i.jsx("button",{onClick:n,className:"btn-secondary",children:s("hireModal.cancel")}),i.jsx("button",{onClick:y,disabled:!l.trim()||g,className:"btn-primary",children:s(g?"hireModal.creating_progress":"hireModal.create")})]})]})})}function yh(e,t){const n=e.i18n?.[t];return n?.displayName||n?.name||e.name}function wk(e,t){return e.i18n?.[t]?.description||e.description}function kk(e,t,n){return e.i18n?.[n]?.members?.[t]||t}function Zre(e,t){const n=e.split(".").map(Number),a=t.split(".").map(Number);for(let s=0;s<Math.max(n.length,a.length);s++){const l=n[s]??0,c=a[s]??0;if(l>c)return!0;if(l<c)return!1}return!1}function eie({highlightItemId:e,onHighlightDone:t}={}){const{t:n,i18n:a}=ot(["store","common"]),s=a.language,[l,c]=k.useState(""),[d,m]=k.useState([]),[p,h]=k.useState([]),[g,x]=k.useState(null),[y,w]=k.useState({}),[T,C]=k.useState(!0),[S,E]=k.useState(!1),[_,L]=k.useState(null),[D,M]=k.useState(new Map),[O,G]=k.useState(new Set),[Q,$]=k.useState(null),Y=k.useCallback(async()=>{try{const[U,te]=await Promise.all([Ae.builder.artifacts.list().catch(()=>({artifacts:[]})),Ae.builder.artifacts.installed().catch(()=>({installed:{}}))]),I=new Map;for(const J of U.artifacts){if(J.type!=="team")continue;const me=!!te.installed[`team/${J.name}`];I.set(J.name,{installed:me,localVersion:J.meta.version||void 0,localUpdatedAt:J.updatedAt})}M(I)}catch{}},[]),K=k.useCallback(async()=>{C(!0);try{const U=l?st.search({type:"team",q:l,limit:50}):Ls(qa.hubTeams)??st.search({type:"team",limit:50}),[te,I]=await Promise.all([U.catch(()=>({items:[],total:0})),Ae.teamTemplates.list(l||void 0).catch(()=>({templates:[]})),Y(),st.isAuthenticated()?st.purchases.mine().then(me=>G(new Set(me.purchases.map(Ce=>Ce.itemId)))).catch(()=>{}):Promise.resolve()]),J=await l6(te?.items??[],e);h(J.items),m(I?.templates??[]),J.missing&&t?.()}catch{m([]),h([])}finally{C(!1)}},[l,Y,e,t]);k.useEffect(()=>{K()},[K]),k.useEffect(()=>{if(!g){w({});return}fetch(`/api/team-templates/${encodeURIComponent(g.id)}/files`,{credentials:"include"}).then(U=>U.json()).then(U=>w(U.files??{})).catch(()=>w({}))},[g]);const ee=async U=>{E(!0),L(null);try{const I=(await Ae.teams.create(U.name,U.description)).team.id;let J,me=0;const Ce=[];for(const V of U.members){const fe=V.count??1;for(let z=0;z<fe;z++){const je=V.name??`${U.name} Agent ${z+1}`,Ue=fe>1?`${je} ${z+1}`:je,qe=V.roleName??V.templateId;try{const He=await fetch("/api/agents",{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({name:Ue,...qe?{roleName:qe}:{},orgId:"default",teamId:I,agentRole:V.role??"worker",skills:V.skills??[]})});if(He.ok){me++;const ut=await He.json();V.role==="manager"&&!J&&(J=ut.agent?.id)}else{const ut=await He.json().catch(()=>({error:`HTTP ${He.status}`}));Ce.push(`${Ue}: ${ut.error??He.statusText}`)}}catch(He){Ce.push(`${Ue}: ${String(He)}`)}}}J&&await Ae.teams.update(I,{managerId:J,managerType:"agent"}).catch(()=>{});const H=Ce.length>0?` (${Ce.length} failed: ${Ce[0]})`:"";L({ok:me>0,message:`Team "${yh(U,s)}" deployed with ${me} agent(s)${H}`})}catch(te){L({ok:!1,message:`Failed: ${te}`})}finally{E(!1)}};if(Q)return i.jsx(qs,{type:Q.type,name:Q.name,onBack:()=>$(null)});if(g){const U={...y};g.announcements&&(U["ANNOUNCEMENT.md"]=g.announcements),g.norms&&(U["NORMS.md"]=g.norms);const te={type:"team",name:g.id,displayName:yh(g,s),version:g.version,description:wk(g,s),author:g.author,category:g.category??"general",tags:g.tags??[],files:U,team:{members:g.members.map(J=>({name:kk(g,J.name??J.roleName??J.templateId??"Agent",s),role:J.role??"worker",roleName:J.roleName??J.templateId,count:J.count??1,skills:J.skills??[]}))}},I=i.jsxs("div",{className:"rounded-xl border border-border-default bg-surface-secondary/40 overflow-hidden",children:[i.jsx("div",{className:"px-5 py-3 border-b border-border-default bg-surface-elevated/30",children:i.jsx("h3",{className:"text-xs text-fg-tertiary uppercase tracking-wider",children:n("teamStore.teamComposition")})}),i.jsx("div",{className:"p-5 space-y-2",children:g.members.map((J,me)=>{const Ce=kk(g,J.name??J.roleName??J.templateId??"Agent",s);return i.jsxs("div",{className:"flex items-center gap-3 bg-surface-elevated/50 rounded-lg p-3",children:[i.jsx("div",{className:`w-9 h-9 rounded-lg flex items-center justify-center text-sm font-bold shrink-0 ${J.role==="manager"?"bg-amber-500/15 text-amber-400 ring-1 ring-amber-500/30":"bg-blue-500/15 text-blue-400 ring-1 ring-blue-500/30"}`,children:(Ce[0]??"?").toUpperCase()}),i.jsxs("div",{className:"min-w-0 flex-1",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("span",{className:"text-sm text-fg-primary font-medium",children:Ce}),i.jsx("span",{className:`px-1.5 py-0.5 rounded text-[10px] capitalize font-medium ${J.role==="manager"?"bg-amber-500/15 text-amber-400":"bg-blue-500/15 text-blue-400"}`,children:J.role??"worker"}),(J.count??1)>1&&i.jsxs("span",{className:"text-[10px] text-fg-muted",children:["×",J.count]})]}),(J.roleName||J.templateId)&&i.jsx("div",{className:"text-[10px] text-fg-tertiary font-mono mt-0.5",children:J.roleName??J.templateId})]}),J.skills&&J.skills.length>0&&i.jsxs("div",{className:"flex flex-wrap gap-1 shrink-0",children:[J.skills.slice(0,3).map(H=>i.jsx("span",{className:"px-1.5 py-0.5 text-[9px] bg-surface-elevated text-fg-muted rounded border border-border-default",children:H},H)),J.skills.length>3&&i.jsxs("span",{className:"text-[9px] text-fg-muted",children:["+",J.skills.length-3]})]})]},me)})})]});return i.jsx(i.Fragment,{children:i.jsx(qs,{type:"team",name:g.id,onBack:()=>{x(null),L(null)},readOnly:!0,initialManifest:te,contentSlot:I,actionSlot:i.jsxs(i.Fragment,{children:[_&&i.jsx("span",{className:`text-xs ${_.ok?"text-green-500":"text-red-500"}`,children:_.message}),i.jsx("button",{onClick:()=>{ee(g)},disabled:S,className:"px-4 py-1.5 text-xs bg-brand-600 hover:bg-brand-500 text-white rounded-lg transition-colors font-medium disabled:opacity-50",children:n(S?"teamStore.deploying":"teamStore.deployTeam")})]})})})}return i.jsxs("div",{className:"flex-1 overflow-hidden flex flex-col",children:[i.jsxs("div",{"data-electron-drag":!0,className:"px-6 h-14 flex items-center justify-between shrink-0 gap-3",children:[i.jsx("h2",{className:"text-lg font-semibold",children:n("teamStore.title")}),i.jsx("input",{type:"text",placeholder:n("teamStore.searchPlaceholder"),value:l,onChange:U=>c(U.target.value),className:"px-3 py-1.5 bg-surface-elevated border border-border-default rounded-lg text-sm max-w-xs w-full focus:border-brand-500 focus:outline-none"})]}),i.jsx("div",{className:"flex-1 overflow-y-auto p-7 space-y-8",children:T?i.jsx("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-4",children:Array.from({length:4}).map((U,te)=>i.jsx("div",{className:"h-56 rounded-2xl skeleton"},te))}):d.length===0&&p.length===0?i.jsxs("div",{className:"text-center py-20",children:[i.jsx("div",{className:"text-4xl mb-4 opacity-30",children:"◉"}),i.jsx("div",{className:"text-fg-secondary font-medium mb-1",children:l?n("teamStore.noResults",{search:l}):n("teamStore.noTeams")}),i.jsx("div",{className:"text-fg-tertiary text-sm",children:n(l?"teamStore.noResultsHint":"teamStore.noTeamsHint")})]}):i.jsxs(i.Fragment,{children:[d.length>0&&i.jsxs("section",{children:[i.jsxs("div",{className:"flex items-baseline gap-2 mb-3",children:[i.jsx("h3",{className:"section-title",children:n("teamStore.builtin")}),i.jsx("span",{className:"text-xs text-fg-tertiary",children:n("teamStore.available",{count:d.length})})]}),i.jsx(Fa,{columns:2,children:d.map(U=>i.jsx(vr,{type:"team",name:yh(U,s),description:wk(U,s),seed:U.id,icon:U.icon||"users",version:U.version,category:U.category,tags:U.tags,authorLabel:U.author,hideStats:!0,showTypeBadge:!1,cornerLabel:n("teamStore.builtin"),onClick:()=>x(U)},U.id))})]}),p.length>0&&i.jsxs("section",{children:[i.jsx("h3",{className:"section-title mb-3",children:n("teamStore.markusHub")}),i.jsx(Fa,{columns:2,children:p.map(U=>i.jsx(tie,{item:U,localInfo:D.get(Fc(U)),purchased:cm(U,O),onStatusChange:Y,highlight:U.id===e,onHighlightDone:t,onViewDetail:te=>$({type:"team",name:te})},U.id))})]})]})})]})}function tie({item:e,localInfo:t,purchased:n,onStatusChange:a,highlight:s,onHighlightDone:l,onViewDetail:c}){const{t:d}=ot(["store"]),[m,p]=k.useState(!1),[h,g]=k.useState(""),x=k.useRef(null),[y,w]=k.useState(!1);k.useEffect(()=>{if(s&&x.current){x.current.scrollIntoView({behavior:"smooth",block:"center"}),w(!0);const G=setTimeout(()=>{w(!1)},4e3);return()=>clearTimeout(G)}},[s,l]);const T=t?.installed??!1,C=T&&e.version&&t?.localVersion&&Zre(e.version,t.localVersion),S=(e.priceCents??0)>0,E=S?`$${((e.priceCents??0)/100).toFixed(2)}`:null,_=async G=>{if(G.stopPropagation(),!m){p(!0),g("");try{await Is(e),g(C?d("card.upgraded"):d("card.installed")+"!"),a()}catch(Q){const $=Q instanceof Error?Q.message:"";$.includes("402")||$.includes("Purchase required")?g(d("card.purchaseRequired")):g(d("card.failed"))}finally{p(!1)}}},L=async G=>{if(G.stopPropagation(),!m){p(!0),g("");try{await vb(e,$=>{$==="checkout_opened"?g(d("card.waitingPurchase","Waiting for purchase...")):$==="installing"&&g(d("card.installing"))})==="installed"?(g(d("card.installed")+"!"),a()):g("")}catch(Q){g(Q instanceof Error?Q.message:d("card.failed"))}finally{p(!1)}}},D=e.slug&&e.author?.username?`${st.getUrl()}/@${encodeURIComponent(e.author.username)}/${encodeURIComponent(e.slug)}`:null,M=()=>{T&&c?c(Fc(e)):D&&window.open(D,"_blank","noopener,noreferrer")},O=i.jsxs(i.Fragment,{children:[C?i.jsx("button",{onClick:G=>{_(G)},disabled:m,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:m?d("card.upgrading"):d("card.upgrade",{version:e.version})}):T?i.jsxs("button",{onClick:G=>{_(G)},disabled:m,className:"px-3 py-1.5 text-xs bg-surface-elevated hover:bg-surface-overlay text-fg-secondary border border-border-default rounded-lg transition-colors disabled:opacity-50",children:[d("card.installed"),t?.localVersion?` v${t.localVersion}`:""]}):S&&!n?i.jsx("button",{onClick:G=>{L(G)},disabled:m,className:"px-3 py-1.5 text-xs bg-amber-600 hover:bg-amber-500 text-white rounded-lg transition-colors disabled:opacity-50 inline-flex items-center gap-1",children:m?h||d("card.installing"):i.jsxs(i.Fragment,{children:[d("card.buy","Buy")," ",E]})}):i.jsx("button",{onClick:G=>{_(G)},disabled:m,className:"px-3 py-1.5 text-xs bg-brand-600 hover:bg-brand-500 text-white rounded-lg transition-colors disabled:opacity-50",children:d(m?"card.installing":"card.install")}),h&&i.jsx("span",{className:`text-[10px] ${h===d("card.failed")||h===d("card.purchaseRequired")?"text-red-500":"text-green-600"}`,children:h})]});return i.jsx("div",{ref:x,className:y?"animate-pulse":"",children:i.jsx(vr,{type:"team",showTypeBadge:!1,name:e.name,description:e.description,seed:e.slug||e.name,icon:e.icon||"users",cover:e.thumbnailUrl,hubBase:st.getUrl(),author:e.author,version:e.version,category:e.category,tags:e.tags,rating:parseFloat(e.avgRating)||0,ratingCount:e.ratingCount,downloadCount:e.downloadCount,priceCents:e.priceCents,currency:e.currency,installed:T,glowing:y,onClick:M,actions:O})})}function xh(e,t){return e.i18n?.[t]?.displayName||e.name}function vh(e,t){return e.i18n?.[t]?.description||e.description||""}function c6(e,t){const n=e.split(".").map(Number),a=t.split(".").map(Number);for(let s=0;s<Math.max(n.length,a.length);s++){const l=n[s]??0,c=a[s]??0;if(l>c)return!0;if(l<c)return!1}return!1}const nie={development:"bg-blue-500/15 text-blue-600",devops:"bg-amber-500/15 text-amber-600",productivity:"bg-green-500/15 text-green-600",custom:"bg-gray-500/15 text-fg-secondary",browser:"bg-brand-500/15 text-brand-500",communication:"bg-green-500/15 text-green-600",data:"bg-brand-500/15 text-brand-500",platform:"bg-blue-500/15 text-blue-600","AI 智能":"bg-brand-500/15 text-brand-500",开发工具:"bg-blue-500/15 text-blue-600",效率提升:"bg-green-500/15 text-green-600",数据分析:"bg-brand-500/15 text-brand-500",内容创作:"bg-brand-500/15 text-brand-500",安全合规:"bg-red-500/15 text-red-500",通讯协作:"bg-green-500/15 text-green-600"};function aie({item:e,installedSkills:t,purchased:n,onMsg:a,onRefresh:s}){const{t:l}=ot(["store"]),[c,d]=k.useState(!1),m=e.name.toLowerCase().trim().replace(/\s+/g,"-").replace(/[\/\\:*?"<>|]+/g,"").replace(/-{2,}/g,"-").replace(/^-|-$/g,"")||"unnamed",p=t.find(S=>S.name===e.name||S.name===m||!!e.slug&&S.name===e.slug),h=!!p,g=h&&e.version&&p?.version&&c6(e.version,p.version),x=(e.priceCents??0)>0,[y,w]=k.useState(""),T=async()=>{if(!c){d(!0),w("");try{await Is(e),a(g?`Upgraded ${e.name}`:`Installed ${e.name}`,"success"),s()}catch(S){const E=S instanceof Error?S.message:"";E.includes("402")||E.includes("Purchase required")?a(l("card.purchaseRequired"),"error"):a(l("card.failed"),"error")}finally{d(!1)}}},C=async()=>{if(!c){d(!0),w("");try{await vb(e,E=>{E==="checkout_opened"?w(l("card.waitingPurchase","Waiting for purchase...")):E==="installing"&&w(l("card.installing"))})==="installed"&&(a(`Purchased & installed ${e.name}`,"success"),s()),w("")}catch(S){a(S instanceof Error?S.message:l("card.failed"),"error"),w("")}finally{d(!1)}}};if(g)return i.jsx("button",{onClick:()=>{T()},disabled:c,className:"px-2.5 py-1 text-[10px] bg-amber-600 hover:bg-amber-500 text-white rounded-lg disabled:opacity-50",children:c?l("card.upgrading"):l("card.upgrade",{version:e.version})});if(h)return i.jsxs("span",{className:"px-2.5 py-1 text-[10px] bg-surface-overlay text-fg-secondary rounded-lg",children:[l("card.installed"),p?.version?` (v${p.version})`:""]});if(x&&!n){const S=`$${((e.priceCents??0)/100).toFixed(2)}`;return i.jsx("span",{className:"inline-flex items-center gap-1.5",children:i.jsx("button",{onClick:()=>{C()},disabled:c,className:"px-2.5 py-1 text-[10px] bg-amber-600 hover:bg-amber-500 text-white rounded-lg disabled:opacity-50 inline-flex items-center gap-1",children:c?y||l("card.installing"):i.jsxs(i.Fragment,{children:[l("card.buy","Buy")," ",S]})})})}return i.jsx("button",{onClick:()=>{T()},disabled:c,className:"px-2.5 py-1 text-[10px] bg-brand-600 hover:bg-brand-500 text-white rounded-lg disabled:opacity-50",children:l(c?"card.installing":"card.install")})}function Sk({item:e,installedSkills:t,purchased:n,onMsg:a,onRefresh:s,highlight:l,onHighlightDone:c,type:d="skill"}){const m=k.useRef(null),[p,h]=k.useState(!1);k.useEffect(()=>{if(l&&m.current){m.current.scrollIntoView({behavior:"smooth",block:"center"}),h(!0);const y=setTimeout(()=>{h(!1)},4e3);return()=>clearTimeout(y)}},[l,c]);const g=e.slug&&e.author?.username?`${st.getUrl()}/@${encodeURIComponent(e.author.username)}/${encodeURIComponent(e.slug)}`:null,x=()=>{g&&window.open(g,"_blank","noopener,noreferrer")};return i.jsx("div",{ref:m,className:p?"animate-pulse":"",children:i.jsx(vr,{type:d,showTypeBadge:d!=="skill",name:e.name,description:e.description,seed:e.slug||e.name,icon:e.icon||tm(e.slug||e.name,e.category),cover:e.thumbnailUrl,hubBase:st.getUrl(),author:e.author,version:e.version,category:e.category,tags:e.tags,rating:parseFloat(e.avgRating)||0,ratingCount:e.ratingCount,downloadCount:e.downloadCount,priceCents:e.priceCents,currency:e.currency,onClick:x,actions:i.jsx(aie,{item:e,installedSkills:t,purchased:n,onMsg:a,onRefresh:s})})})}function rie({highlightItemId:e,onHighlightDone:t}={}){const{t:n,i18n:a}=ot(["store","common"]),s=a.language,l=Xo(),[c,d]=k.useState("skills"),[m,p]=k.useState(null),[h,g]=k.useState(new Set),[x,y]=k.useState([]),[w,T]=k.useState(null),[C,S]=k.useState([]),[E,_]=k.useState(0),[L,D]=k.useState(1),[M,O]=k.useState([]),[G,Q]=k.useState(""),[$,Y]=k.useState("score"),[K,ee]=k.useState(""),[U,te]=k.useState(!1),[I,J]=k.useState([]),[me,Ce]=k.useState(!1),[H,V]=k.useState([]),[fe,z]=k.useState(""),[je,Ue]=k.useState(!1),[qe,He]=k.useState([]),[ut,dt]=k.useState([]),[Nt,wt]=k.useState(new Set),[Zt,Wt]=k.useState(!1),[rt,$e]=k.useState(""),mt=[{id:"skills",labelKey:"skillStore.tabs.all"},{id:"skillhub",labelKey:"skillStore.tabs.skillhub"},{id:"skillssh",labelKey:"skillStore.tabs.skillssh"}],At=(q,ae="success")=>{p({text:q,type:ae}),setTimeout(()=>p(null),ae==="error"?1e4:4e3)},Dt=k.useCallback(async()=>{try{const q=await Ae.skills.list();y(q.skills)}catch{}},[]),ln=k.useCallback(async()=>{Ce(!0);try{const q=await Ae.skills.builtin();J(q.skills)}catch{}Ce(!1)},[]),ce=k.useCallback(async q=>{te(!0);try{const ae=await Ae.skills.registrySkillhub({q:q?.q,category:q?.category,page:q?.page??1,limit:24,sort:q?.sort??$});S(ae.skills),_(ae.total),ae.categories?.length&&O(ae.categories)}catch{}te(!1)},[$]),et=k.useCallback(async q=>{Ue(!0);try{const ae=await Ae.skills.registrySkillssh(q);V(ae.skills)}catch{}Ue(!1)},[]),nt=k.useCallback(async q=>{Wt(!0);try{const ae=q?st.search({type:"skill",q,limit:50}):Ls(qa.hubSkills)??st.search({type:"skill",limit:50}),Se=st.search({subtype:"connector",q:q||void 0,limit:50}).catch(()=>({items:[]})),[De,Pe]=await Promise.all([ae,Se,st.isAuthenticated()?st.purchases.mine().then(ue=>wt(new Set(ue.purchases.map(Be=>Be.itemId)))).catch(()=>{}):Promise.resolve()]);let X=De?.items??[],Z=Pe?.items??[];if(e){const ue=X.some(Ie=>Ie.id===e),Be=Z.some(Ie=>Ie.id===e);if(!ue&&!Be)try{const{item:Ie}=await st.getItem(e);Ie?.subtype==="connector"?Z=[Ie,...Z]:Ie?X=[Ie,...X]:t?.()}catch{t?.()}else ue&&(X=[X.find(Ge=>Ge.id===e),...X.filter(Ge=>Ge.id!==e)]),Be&&(Z=[Z.find(Ge=>Ge.id===e),...Z.filter(Ge=>Ge.id!==e)])}He(X),dt(Z)}catch{}Wt(!1)},[e,t]);k.useEffect(()=>{Dt(),ln(),ce(),et()},[]),k.useEffect(()=>{c==="skills"&&nt(rt)},[c,rt,nt]);const we=async q=>{g(ae=>new Set(ae).add(q.name));try{const ae=await Ae.skills.install({name:q.name,source:"skillhub",slug:q.slug,sourceUrl:q.homepage,description:q.description_zh??q.description,category:"custom",version:q.version});await Dt(),At(`"${q.name}" installed (${ae.method}) → ${ae.path}`),window.dispatchEvent(new CustomEvent("markus:data-changed"))}catch{At(`Download failed for "${q.name}". You can try manually from: ${q.homepage}`,"error")}g(ae=>{const Se=new Set(ae);return Se.delete(q.name),Se})},Me=async q=>{g(ae=>new Set(ae).add(q.name));try{const ae=await Ae.skills.install({name:q.name,source:"skillssh",sourceUrl:q.url,githubRepo:`${q.author}/${q.repo}`,githubSkillPath:q.name});await Dt(),At(`"${q.name}" installed (${ae.method}) → ${ae.path}`),window.dispatchEvent(new CustomEvent("markus:data-changed"))}catch{At(`Download failed for "${q.name}". You can try manually from: ${q.url}`,"error")}g(ae=>{const Se=new Set(ae);return Se.delete(q.name),Se})},Ne=async q=>{g(ae=>new Set(ae).add(q.name));try{const ae=await Ae.skills.install({name:q.name,source:"builtin"});await Dt(),await ln(),At(`"${q.name}" installed (${ae.method}) → ${ae.path}`),window.dispatchEvent(new CustomEvent("markus:data-changed"))}catch(ae){At(`Install failed for "${q.name}": ${ae}`,"error")}g(ae=>{const Se=new Set(ae);return Se.delete(q.name),Se})},se=H.filter(q=>{if(!fe)return!0;const ae=fe.toLowerCase();return q.name.toLowerCase().includes(ae)||q.repo.toLowerCase().includes(ae)});if(w){const q=w,ae={};q.instructions&&(ae["SKILL.md"]=q.instructions);const Se={type:"skill",name:q.name,displayName:xh(q,s),version:q.version,description:vh(q,s),author:q.author??"",category:q.category??"general",tags:q.tags,files:ae,skill:{skillFile:q.instructions?"SKILL.md":"",requiredPermissions:q.requiredPermissions,mcpServers:void 0,alwaysOn:!1}},De=q.installed&&q.installedVersion&&c6(q.version,q.installedVersion)?i.jsx("button",{onClick:()=>{Ne(q)},disabled:h.has(q.name),className:"px-4 py-1.5 text-xs bg-amber-600 hover:bg-amber-500 text-white rounded-lg disabled:opacity-50 transition-colors",children:h.has(q.name)?n("card.upgrading"):n("card.upgrade",{version:q.version})}):q.installed?i.jsxs("span",{className:"px-4 py-1.5 text-xs bg-green-500/10 text-green-500 rounded-lg border border-green-500/20 inline-flex items-center gap-1",children:[i.jsx("svg",{className:"w-3 h-3",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:i.jsx("polyline",{points:"20 6 9 17 4 12"})}),n("card.installed"),q.installedVersion?` v${q.installedVersion}`:""]}):i.jsx("button",{onClick:()=>{Ne(q)},disabled:h.has(q.name),className:"px-4 py-1.5 text-xs bg-green-600 hover:bg-green-500 text-white rounded-lg disabled:opacity-50 transition-colors",children:h.has(q.name)?n("card.installing"):n("card.install")}),Pe=i.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[i.jsxs("div",{className:"rounded-xl border border-border-default bg-surface-secondary/40 p-5",children:[i.jsx("h3",{className:"text-xs text-fg-tertiary uppercase tracking-wider mb-3",children:n("skillStore.details")}),i.jsxs("div",{className:"space-y-2.5 text-sm",children:[q.category&&i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("span",{className:"text-fg-tertiary w-24",children:n("skillStore.category")}),i.jsx("span",{className:`px-2 py-0.5 rounded-full text-[10px] font-medium capitalize ${nie[q.category]??"bg-gray-500/15 text-fg-secondary"}`,children:q.category})]}),i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("span",{className:"text-fg-tertiary w-24",children:n("skillStore.version")}),i.jsx("span",{className:"text-fg-secondary font-mono text-xs",children:q.version})]}),q.hasMcpServers&&i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("span",{className:"text-fg-tertiary w-24",children:n("skillStore.integration")}),i.jsx("span",{className:"px-2 py-0.5 rounded text-[10px] bg-purple-500/15 text-purple-400",children:"MCP"})]}),q.hasInstructions&&i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("span",{className:"text-fg-tertiary w-24",children:n("skillStore.instructions")}),i.jsx("span",{className:"text-green-500 text-xs",children:"✓"})]})]})]}),(q.requiredPermissions.length>0||q.tags.length>0)&&i.jsxs("div",{className:"space-y-4",children:[q.requiredPermissions.length>0&&i.jsxs("div",{className:"rounded-xl border border-border-default bg-surface-secondary/40 p-5",children:[i.jsx("h3",{className:"text-xs text-fg-tertiary uppercase tracking-wider mb-3",children:n("skillStore.permissions")}),i.jsx("div",{className:"flex flex-wrap gap-1.5",children:q.requiredPermissions.map(X=>i.jsx("span",{className:"px-2.5 py-1 text-xs bg-amber-500/10 text-amber-500 rounded-lg border border-amber-500/20",children:X},X))})]}),q.tags.length>0&&i.jsxs("div",{className:"rounded-xl border border-border-default bg-surface-secondary/40 p-5",children:[i.jsx("h3",{className:"text-xs text-fg-tertiary uppercase tracking-wider mb-3",children:n("skillStore.tags")}),i.jsx("div",{className:"flex flex-wrap gap-1.5",children:q.tags.map(X=>i.jsx("span",{className:"px-2.5 py-1 text-xs bg-surface-elevated text-fg-secondary rounded-lg border border-border-default/50",children:X},X))})]})]})]});return i.jsxs(i.Fragment,{children:[i.jsx(qs,{type:"skill",name:q.name,onBack:()=>T(null),readOnly:!0,initialManifest:Se,actionSlot:De,contentSlot:Pe}),m&&i.jsx("div",{className:`mx-7 mb-2 px-3 py-1.5 text-xs rounded-lg shrink-0 ${m.type==="error"?"bg-red-500/10 text-red-500":"bg-green-500/10 text-green-600"}`,children:m.text})]})}return i.jsxs("div",{className:"flex-1 overflow-hidden flex flex-col",children:[i.jsxs("div",{className:`${l?"px-4":"px-6"} shrink-0`,children:[i.jsx("div",{"data-electron-drag":!0,className:"flex items-center h-14",children:i.jsx("h2",{className:"text-lg font-semibold",children:n("skillStore.title")})}),i.jsx("div",{className:`flex ${l?"flex-wrap":""} gap-1 pb-2 overflow-x-auto scrollbar-hide`,children:mt.map(q=>i.jsx("button",{onClick:()=>d(q.id),className:`px-3 py-1.5 text-xs rounded-lg transition-colors shrink-0 ${c===q.id?"bg-brand-600 text-white":"text-fg-secondary hover:text-fg-primary hover:bg-surface-elevated"}`,children:n(q.labelKey)},q.id))})]}),m&&i.jsx("div",{className:`mx-7 mt-2 px-3 py-1.5 text-xs rounded-lg shrink-0 ${m.type==="error"?"bg-red-500/10 text-red-500":"bg-green-500/10 text-green-600"}`,children:m.text}),c==="skills"&&(()=>{const q=rt.trim().toLowerCase(),ae=q?I.filter(Pe=>xh(Pe,s).toLowerCase().includes(q)||vh(Pe,s).toLowerCase().includes(q)):I,Se=me&&Zt,De=ae.length===0&&qe.length===0&&ut.length===0;return i.jsxs("div",{className:`flex-1 overflow-y-auto ${l?"p-4":"p-6"} space-y-8`,children:[i.jsx("div",{className:"flex items-center gap-2",children:i.jsx("input",{value:rt,onChange:Pe=>$e(Pe.target.value),placeholder:n("skillStore.searchMarkusHub"),className:`px-3 py-1.5 bg-surface-elevated border border-border-default rounded-lg text-sm text-fg-primary focus:border-brand-500 outline-none ${l?"flex-1 min-w-0":"w-72"}`})}),Se&&De?i.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4",children:Array.from({length:6}).map((Pe,X)=>i.jsx("div",{className:"h-56 rounded-2xl skeleton"},X))}):De?i.jsxs("div",{className:"text-center text-fg-tertiary py-20",children:[i.jsx("div",{className:"text-4xl mb-3 opacity-30",children:"◇"}),i.jsx("div",{children:n("skillStore.noBuiltin")}),i.jsx("div",{className:"text-xs mt-1",children:n("skillStore.noBuiltinHint")})]}):i.jsxs(i.Fragment,{children:[ae.length>0&&i.jsxs("section",{children:[i.jsxs("div",{className:"flex items-baseline gap-2 mb-3",children:[i.jsx("h3",{className:"section-title",children:n("skillStore.tabs.builtin")}),i.jsx("span",{className:"text-xs text-fg-tertiary",children:n("skillStore.builtinCount",{count:ae.length})})]}),i.jsx(Fa,{columns:3,children:ae.map(Pe=>i.jsx(vr,{type:"skill",name:xh(Pe,s),description:vh(Pe,s),seed:Pe.name,icon:tm(Pe.name,Pe.category),version:Pe.version,category:Pe.category,tags:Pe.tags,authorLabel:Pe.author||void 0,installed:Pe.installed,hideStats:!0,showTypeBadge:!1,cornerLabel:Pe.installed?void 0:n("skillStore.tabs.builtin"),onClick:()=>T(Pe)},Pe.name))})]}),qe.length>0&&i.jsxs("section",{children:[i.jsx("h3",{className:"section-title mb-3",children:n("skillStore.tabs.markusHub")}),i.jsx(Fa,{columns:3,children:qe.map(Pe=>i.jsx(Sk,{item:Pe,installedSkills:x,purchased:cm(Pe,Nt),onMsg:At,onRefresh:()=>{Dt(),nt(rt)},highlight:Pe.id===e,onHighlightDone:t},Pe.id))})]}),ut.length>0&&i.jsxs("section",{children:[i.jsxs("div",{className:"mb-3",children:[i.jsx("h3",{className:"section-title",children:n("tabs.connectors")}),i.jsx("p",{className:"text-xs text-fg-tertiary mt-0.5",children:n("connectorStore.emptyHint","连接器让智能体接入外部工具与服务 (MCP)")})]}),i.jsx(Fa,{columns:3,children:ut.map(Pe=>i.jsx(Sk,{item:Pe,type:"connector",installedSkills:x,purchased:cm(Pe,Nt),onMsg:At,onRefresh:()=>{Dt(),nt(rt)},highlight:Pe.id===e,onHighlightDone:t},Pe.id))})]})]})]})})(),c==="skillhub"&&i.jsxs("div",{className:`flex-1 overflow-y-auto ${l?"p-4":"p-6"}`,children:[i.jsxs("div",{className:"flex items-center gap-2 mb-3 flex-wrap",children:[i.jsxs("select",{value:G,onChange:q=>{Q(q.target.value),D(1),ce({q:K||void 0,category:q.target.value||void 0,page:1})},className:"px-2 py-1.5 bg-surface-elevated border border-border-default rounded-lg text-xs text-fg-secondary outline-none",children:[i.jsx("option",{value:"",children:n("skillStore.allCategories")}),M.map(q=>i.jsx("option",{value:q,children:q},q))]}),i.jsxs("select",{value:$,onChange:q=>{Y(q.target.value),D(1),ce({q:K||void 0,category:G||void 0,page:1,sort:q.target.value})},className:"px-2 py-1.5 bg-surface-elevated border border-border-default rounded-lg text-xs text-fg-secondary outline-none",children:[i.jsx("option",{value:"score",children:n("skillStore.sortScore")}),i.jsx("option",{value:"downloads",children:n("skillStore.sortDownloads")}),i.jsx("option",{value:"stars",children:n("skillStore.sortStars")}),i.jsx("option",{value:"installs",children:n("skillStore.sortInstalls")})]}),!l&&i.jsx("span",{className:"text-xs text-fg-tertiary ml-auto",children:i.jsx("a",{href:"https://skillhub.tencent.com",target:"_blank",rel:"noopener noreferrer",className:"text-brand-500 hover:text-brand-500",children:n("skillStore.visitSite")})})]}),i.jsxs("div",{className:"flex items-center gap-2 mb-5",children:[i.jsx("input",{value:K,onChange:q=>ee(q.target.value),onKeyDown:q=>{q.key==="Enter"&&(D(1),ce({q:K||void 0,category:G||void 0,page:1}))},placeholder:n("skillStore.searchSkillhub"),className:"px-3 py-1.5 bg-surface-elevated border border-border-default rounded-lg text-sm text-fg-primary focus:border-brand-500 outline-none flex-1 min-w-0"}),i.jsx("button",{onClick:()=>{D(1),ce({q:K||void 0,category:G||void 0,page:1})},className:"px-3 py-1.5 bg-brand-600 hover:bg-brand-500 text-white text-xs rounded-lg shrink-0",children:"Search"})]}),U?i.jsx("div",{className:"text-center text-fg-tertiary py-20",children:i.jsx("div",{className:"animate-pulse",children:n("skillStore.loadingSkillhub")})}):C.length===0?i.jsxs("div",{className:"text-center text-fg-tertiary py-20",children:[i.jsx("div",{className:"text-4xl mb-3 opacity-30",children:"◎"}),i.jsx("div",{children:n("skillStore.noSkillhub")})]}):i.jsxs(i.Fragment,{children:[i.jsx("div",{className:"text-xs text-fg-tertiary mb-3",children:n("skillStore.skillhubTotal",{count:E.toLocaleString()})}),i.jsx(Fa,{columns:3,children:C.map(q=>{const ae=x.some(Se=>Se.name===q.name||Se.name===q.slug);return i.jsx(vr,{type:"skill",name:q.name,description:q.description_zh??q.description??"",seed:q.slug,icon:tm(q.slug||q.name,q.tags?.[0]),version:q.version,authorLabel:"SkillHub",showTypeBadge:!1,tags:q.tags,installed:ae,hideStats:!0,onClick:()=>window.open(q.homepage,"_blank","noopener,noreferrer"),footerLeft:i.jsxs("span",{className:"flex items-center gap-2 text-[10px] text-fg-tertiary",children:[q.stars>0&&i.jsxs("span",{className:"text-amber-600",children:["★ ",q.stars.toLocaleString()]}),q.downloads>0&&i.jsxs("span",{children:[q.downloads>=1e4?`${(q.downloads/1e4).toFixed(1)}万`:q.downloads.toLocaleString()," ",n("skillStore.downloads")]})]}),actions:ae?void 0:i.jsx("button",{onClick:()=>{we(q)},disabled:h.has(q.name),className:"px-2.5 py-1 text-[10px] bg-brand-600 hover:bg-brand-500 text-white rounded-lg disabled:opacity-50",children:h.has(q.name)?"...":n("card.install")})},q.slug)})}),E>24&&i.jsxs("div",{className:"flex items-center justify-center gap-2 mt-6",children:[i.jsx("button",{disabled:L<=1,onClick:()=>{const q=L-1;D(q),ce({q:K||void 0,category:G||void 0,page:q})},className:"px-3 py-1.5 text-xs bg-surface-elevated text-fg-secondary rounded-lg hover:bg-surface-overlay disabled:opacity-30",children:n("skillStore.prevPage")}),i.jsx("span",{className:"text-xs text-fg-tertiary",children:n("skillStore.pageInfo",{current:L,total:Math.ceil(E/24)})}),i.jsx("button",{disabled:L>=Math.ceil(E/24),onClick:()=>{const q=L+1;D(q),ce({q:K||void 0,category:G||void 0,page:q})},className:"px-3 py-1.5 text-xs bg-surface-elevated text-fg-secondary rounded-lg hover:bg-surface-overlay disabled:opacity-30",children:n("skillStore.nextPage")})]})]})]}),c==="skillssh"&&i.jsxs("div",{className:`flex-1 overflow-y-auto ${l?"p-4":"p-6"}`,children:[i.jsxs("div",{className:`flex ${l?"flex-wrap":""} items-center gap-2 mb-5`,children:[i.jsx("input",{value:fe,onChange:q=>z(q.target.value),onKeyDown:q=>{q.key==="Enter"&&fe.trim()&&et(fe)},placeholder:n("skillStore.searchSkillssh"),className:`px-3 py-1.5 bg-surface-elevated border border-border-default rounded-lg text-sm text-fg-primary focus:border-brand-500 outline-none ${l?"flex-1 min-w-0":"w-72"}`}),i.jsx("button",{onClick:()=>{fe.trim()&&et(fe)},className:"px-3 py-1.5 bg-brand-600 hover:bg-brand-500 text-white text-xs rounded-lg shrink-0",children:"Search"}),!l&&i.jsx("span",{className:"text-xs text-fg-tertiary ml-auto",children:i.jsx("a",{href:"https://skills.sh",target:"_blank",rel:"noopener noreferrer",className:"text-brand-500 hover:text-brand-500",children:n("skillStore.visitSite")})})]}),je?i.jsx("div",{className:"text-center text-fg-tertiary py-20",children:i.jsx("div",{className:"animate-pulse",children:n("skillStore.loadingSkillssh")})}):se.length===0?i.jsxs("div",{className:"text-center text-fg-tertiary py-20",children:[i.jsx("div",{className:"text-4xl mb-3 opacity-30",children:"⬡"}),i.jsx("div",{children:n("skillStore.browseSkillssh")}),i.jsx("div",{className:"text-xs mt-1",children:n("skillStore.browseSkillsshHint")})]}):i.jsx(Fa,{columns:3,children:se.map(q=>{const ae=x.some(Se=>Se.name===q.name);return i.jsx(vr,{type:"skill",name:q.name,description:q.description||"",seed:`${q.author}-${q.name}`,icon:tm(q.name),authorLabel:`${q.author}/${q.repo}`,showTypeBadge:!1,installed:ae,hideStats:!0,cornerLabel:ae?void 0:"skills.sh",onClick:()=>window.open(q.url,"_blank","noopener,noreferrer"),footerLeft:q.installs?i.jsxs("span",{className:"text-[10px] text-fg-tertiary",children:[q.installs," installs"]}):void 0,actions:ae?void 0:i.jsx("button",{onClick:()=>{Me(q)},disabled:h.has(q.name),className:"px-2.5 py-1 text-[10px] bg-brand-600 hover:bg-brand-500 text-white rounded-lg disabled:opacity-50",children:h.has(q.name)?"...":n("card.install")})},`${q.author}-${q.name}`)})})]})]})}const iie=["agent","team","skill","connector"];function wh({title:e,subtitle:t,onMore:n,moreLabel:a}){return i.jsxs("div",{className:"flex items-end justify-between mb-3",children:[i.jsxs("div",{children:[i.jsx("h3",{className:"section-title",children:e}),t&&i.jsx("p",{className:"section-subtitle",children:t})]}),n&&i.jsxs("button",{className:"section-link",onClick:n,children:[a??"View all"," →"]})]})}function sie({item:e,onOpen:t}){const n=il(e.subtype==="connector"?"connector":e.itemType),a=xb(n,e.slug||e.name),s=Bs[n];return i.jsxs("button",{onClick:t,className:"group relative w-full overflow-hidden rounded-2xl text-left h-44 md:h-52",style:{background:a},children:[i.jsx("div",{className:"absolute inset-0 bg-gradient-to-r from-black/55 via-black/20 to-transparent"}),i.jsx("svg",{className:"absolute -right-8 -bottom-10 opacity-20",width:"220",height:"220",viewBox:"0 0 24 24",fill:"none","aria-hidden":!0,children:i.jsx("path",{d:"M12 2l2.4 6.9L21 9l-5.4 4 2 7-5.6-4.1L6.4 20l2-7L3 9l6.6-.1z",fill:"white"})}),i.jsxs("div",{className:"relative h-full flex flex-col justify-end p-5 md:p-6",children:[i.jsxs("span",{className:"inline-flex w-fit items-center gap-1 rounded-full bg-white/20 backdrop-blur px-2.5 py-0.5 text-[11px] font-semibold text-white mb-2",children:["★ Featured · ",s.label]}),i.jsx("h2",{className:"text-xl md:text-2xl font-bold text-white drop-shadow-sm",children:e.name}),i.jsx("p",{className:"text-sm text-white/85 truncate max-w-lg mt-1",children:e.description}),i.jsxs("div",{className:"flex items-center gap-3 mt-3 text-white/80 text-xs",children:[i.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[i.jsx(Om,{name:e.author?.displayName,username:e.author?.username,avatarUrl:e.author?.avatarUrl,hubBase:st.getUrl(),size:18}),e.author?.displayName||e.author?.username]}),i.jsxs("span",{children:["↓ ",$o(e.downloadCount)]}),(e.priceCents??0)>0?i.jsxs("span",{className:"badge-paid",children:["$",((e.priceCents??0)/100).toFixed(0)]}):i.jsx("span",{className:"badge-free",children:"Free"})]})]})]})}function Ck({items:e,onOpen:t}){return i.jsx(Fa,{columns:3,children:e.map(n=>i.jsx(vr,{type:n.subtype==="connector"?"connector":n.itemType,name:n.name,description:n.description,seed:n.slug||n.name,icon:n.icon,cover:n.thumbnailUrl,hubBase:st.getUrl(),author:n.author,category:n.category,tags:n.tags,rating:parseFloat(n.avgRating)||0,ratingCount:n.ratingCount,downloadCount:n.downloadCount,priceCents:n.priceCents,currency:n.currency,onClick:()=>t(n)},n.id))})}function Ak(){return i.jsx(Fa,{columns:3,children:Array.from({length:6}).map((e,t)=>i.jsx("div",{className:"h-64 rounded-2xl skeleton"},t))})}function oie({onOpenType:e}){const{t}=ot(["store","common"]),[n,a]=k.useState([]),[s,l]=k.useState(!0);k.useEffect(()=>{let g=!1;return(async()=>{l(!0);try{const x=await st.search({limit:60,sort:"popular"});g||a(x.items??[])}catch{g||a([])}finally{g||l(!1)}})(),()=>{g=!0}},[]);const c=k.useMemo(()=>{const g=n.filter(y=>y.featured);return(g.length>0?g:n).slice(0,3)},[n]),d=k.useMemo(()=>[...n].sort((g,x)=>(x.trendingScore??x.downloadCount)-(g.trendingScore??g.downloadCount)).slice(0,10),[n]),m=k.useMemo(()=>[...n].sort((g,x)=>(x.createdAt||"").localeCompare(g.createdAt||"")).slice(0,10),[n]),p=k.useMemo(()=>{const g=new Map;for(const x of n){const y=x.author?.username||x.author?.id;if(!y)continue;const w=g.get(y)??{author:x.author,downloads:0,count:0};w.downloads+=x.downloadCount||0,w.count+=1,g.set(y,w)}return[...g.values()].sort((x,y)=>y.downloads-x.downloads).slice(0,6)},[n]),h=g=>e(il(g.subtype==="connector"?"connector":g.itemType),g.id);return i.jsxs("div",{className:"flex-1 overflow-y-auto px-5 md:px-7 py-5 space-y-8",children:[i.jsxs("div",{className:"hero-glow rounded-2xl border border-border-subtle bg-surface-secondary p-5 md:p-6",children:[i.jsx("h1",{className:"text-2xl font-bold text-gradient tracking-tight",children:t("discover.title","Markus 广场")}),i.jsx("p",{className:"text-sm text-fg-tertiary mt-1 max-w-2xl",children:t("discover.subtitle","发现社区共享的智能体、AI 小队、技能与连接器 — 由创作者共建的开放生态。")}),i.jsx("div",{className:"flex flex-wrap gap-2 mt-4",children:iie.map(g=>i.jsxs("button",{onClick:()=>e(g),className:`inline-flex items-center gap-1.5 rounded-full px-3 py-1.5 text-xs font-medium text-white bg-gradient-to-r ${Bs[g].gradient} hover:opacity-90 transition-opacity`,children:[Bs[g].labelZh,i.jsx("span",{className:"opacity-70",children:Bs[g].label})]},g))})]}),s?i.jsx("div",{className:"h-52 rounded-2xl skeleton"}):c.length>0?i.jsx("div",{className:"grid grid-cols-1 lg:grid-cols-3 gap-4",children:c.map(g=>i.jsx(sie,{item:g,onOpen:()=>h(g)},g.id))}):null,i.jsxs("section",{children:[i.jsx(wh,{title:t("discover.trending","热门趋势"),subtitle:t("discover.trendingSub","社区中下载与评分增长最快的资产")}),s?i.jsx(Ak,{}):d.length>0?i.jsx(Ck,{items:d,onOpen:h}):i.jsx(lie,{})]}),i.jsxs("section",{children:[i.jsx(wh,{title:t("discover.fresh","新鲜上架"),subtitle:t("discover.freshSub","来自创作者的最新作品")}),s?i.jsx(Ak,{}):m.length>0?i.jsx(Ck,{items:m,onOpen:h}):null]}),p.length>0&&i.jsxs("section",{children:[i.jsx(wh,{title:t("discover.topCreators","顶尖创作者"),subtitle:t("discover.topCreatorsSub","生态贡献榜")}),i.jsx("div",{className:"grid grid-cols-2 md:grid-cols-3 lg:grid-cols-6 gap-3",children:p.map((g,x)=>i.jsxs("div",{className:"asset-card p-4 flex flex-col items-center text-center",children:[i.jsxs("div",{className:"relative",children:[i.jsx(Om,{name:g.author?.displayName,username:g.author?.username,avatarUrl:g.author?.avatarUrl,hubBase:st.getUrl(),size:48,verified:x<3}),x<3&&i.jsx("span",{className:"absolute -top-1 -left-1 w-5 h-5 rounded-full bg-amber-400 text-black text-[10px] font-bold flex items-center justify-center ring-2 ring-surface-secondary",children:x+1})]}),i.jsx("div",{className:"text-sm font-semibold text-fg-primary truncate w-full mt-2",children:g.author?.displayName||g.author?.username}),i.jsxs("div",{className:"text-[11px] text-fg-tertiary mt-0.5",children:[g.count," 作品 · ↓ ",$o(g.downloads)]})]},g.author?.username||x))})]})]})}function lie(){const{t:e}=ot(["store"]);return i.jsxs("div",{className:"text-center py-12 rounded-2xl border border-dashed border-border-default",children:[i.jsx("div",{className:"text-3xl mb-2 opacity-40",children:"✦"}),i.jsx("div",{className:"text-fg-secondary font-medium",children:e("discover.empty","生态正在成长中")}),i.jsx("div",{className:"text-fg-tertiary text-sm mt-1",children:e("discover.emptyHint","成为首批创作者,分享你的第一个资产")})]})}function Fd(e,t,n){return e.i18n?.[n]?.[t]}function cie(){const{t:e,i18n:t}=ot(["store","common"]),n=Xo(),a=t.language,[s,l]=k.useState([]),[c,d]=k.useState({}),[m,p]=k.useState(new Set),[h,g]=k.useState(null),[x,y]=k.useState(!0),[w,T]=k.useState(""),[C,S]=k.useState("all"),[E,_]=k.useState(null),L=k.useCallback(async()=>{y(!0);try{const[O,G,Q,$]=await Promise.all([Ae.builder.artifacts.list().catch(()=>({artifacts:[]})),Ae.builder.artifacts.installed().catch(()=>({installed:{}})),Ae.skills.updates().catch(()=>({updates:[],count:0})),Ae.skills.builtin().catch(()=>({skills:[]}))]),Y={};for(const U of Q.updates)Y[U.name]={availableVersion:U.availableVersion,installedVersion:U.installedVersion,displayName:U.displayName,description:U.description};d(Y);const K=O.artifacts.filter(U=>{const te=`${U.type}/${U.name}`;return!!G.installed[te]}),ee=new Set(K.filter(U=>U.type==="skill").map(U=>U.name));for(const U of $.skills)!U.installed||ee.has(U.name)||!(G.installed[`skill/${U.name}`]||Y[U.name])&&!U.updateAvailable||!G.installed[`skill/${U.name}`]&&!Y[U.name]||(K.push({type:"skill",name:U.name,meta:{displayName:U.i18n?.[a]?.displayName||U.name,description:U.i18n?.[a]?.description||U.description||"",version:U.installedVersion||U.version,author:U.author,category:U.category,tags:U.tags,i18n:U.i18n},path:"",updatedAt:""}),ee.add(U.name));for(const[U,te]of Object.entries(Y))ee.has(U)||(K.push({type:"skill",name:U,meta:{displayName:te.displayName||U,description:te.description||"",version:te.installedVersion},path:"",updatedAt:""}),ee.add(U));l(K)}catch{}y(!1)},[a]);k.useEffect(()=>{L()},[L]),k.useEffect(()=>{const O=()=>{L()};return window.addEventListener("markus:data-changed",O),()=>window.removeEventListener("markus:data-changed",O)},[L]),k.useEffect(()=>{if(!h)return;const O=setTimeout(()=>g(null),3e3);return()=>clearTimeout(O)},[h]);const D=async(O,G)=>{if(!m.has(O)){p(Q=>new Set(Q).add(O));try{await Ae.skills.install({name:O,source:"builtin"});try{localStorage.removeItem("markus:template-updates-ack")}catch{}g({text:e("installedTab.updateSuccess",{name:O,version:G}),type:"success"}),window.dispatchEvent(new CustomEvent("markus:data-changed")),await L()}catch{g({text:e("installedTab.updateFailed",{name:O}),type:"error"})}p(Q=>{const $=new Set(Q);return $.delete(O),$})}},M=s.filter(O=>{if(C!=="all"&&O.type!==C)return!1;if(!w)return!0;const G=w.toLowerCase(),Q=(Fd(O.meta,"displayName",a)||O.meta.displayName||O.name).toLowerCase(),$=(Fd(O.meta,"description",a)||O.meta.description||"").toLowerCase();return Q.includes(G)||$.includes(G)}).sort((O,G)=>{const Q=O.type==="skill"&&c[O.name]?1:0;return(G.type==="skill"&&c[G.name]?1:0)-Q});return E?i.jsx(qs,{type:E.type,name:E.name,onBack:()=>_(null)}):i.jsxs("div",{className:"flex-1 overflow-hidden flex flex-col",children:[i.jsxs("div",{"data-electron-drag":!0,className:`${n?"px-4":"px-6"} h-14 flex items-center shrink-0 gap-3`,children:[i.jsx("h2",{className:"text-lg font-semibold",children:e("installedTab.title")}),Object.keys(c).length>0&&i.jsxs("span",{className:"px-2 py-0.5 text-[11px] font-medium rounded-md bg-amber-500/15 text-amber-600 border border-amber-500/25",children:[e("installedTab.updateAvailable")," · ",Object.keys(c).length]})]}),i.jsxs("div",{className:`flex flex-wrap items-center gap-2 ${n?"px-4":"px-6"} py-2 shrink-0`,children:[i.jsx("div",{className:"flex gap-1",children:["all","agent","team","skill"].map(O=>i.jsx("button",{onClick:()=>S(O),className:`px-3 py-1 text-xs rounded-md transition-colors ${C===O?"bg-brand-600 text-white":"text-fg-secondary hover:text-fg-primary hover:bg-surface-elevated"}`,children:e(`installedTab.filter${O==="all"?"All":O==="agent"?"Agents":O==="team"?"Teams":"Skills"}`)},O))}),i.jsx("div",{className:"flex-1 min-w-[120px]",children:i.jsx("input",{type:"text",placeholder:e("installedTab.searchPlaceholder"),value:w,onChange:O=>T(O.target.value),className:"px-3 py-1.5 bg-surface-elevated border border-border-default rounded-lg text-sm w-full focus:border-brand-500 focus:outline-none"})})]}),i.jsx("div",{className:`flex-1 overflow-y-auto ${n?"p-4":"p-7"}`,children:x?i.jsx("div",{className:"text-center text-fg-tertiary py-20 animate-pulse",children:e("installedTab.loading")}):M.length===0?i.jsxs("div",{className:"text-center py-20",children:[i.jsx("div",{className:"text-4xl mb-4 opacity-30",children:"⧉"}),i.jsx("div",{className:"text-fg-secondary font-medium mb-1",children:e("installedTab.noItems")}),i.jsx("div",{className:"text-fg-tertiary text-sm",children:e("installedTab.noItemsHint")})]}):i.jsx(Fa,{columns:3,children:M.map(O=>{const G=Fd(O.meta,"displayName",a)||O.meta.displayName||O.name,Q=Fd(O.meta,"description",a)||O.meta.description||"",$=O.meta.version||"",Y=O.meta.author||"",K=O.meta.tags??[],ee=O.meta.category||"",U=O.meta.icon,te=U&&/\.(png|jpe?g|gif|webp|svg)$/i.test(U)&&!U.startsWith("http")&&!U.startsWith("data:")&&!U.startsWith("/")?`/api/builder/artifacts/${O.type}s/${encodeURIComponent(O.name)}/${U}`:U,I=O.type==="skill"?c[O.name]:void 0;return i.jsx(vr,{type:O.type,name:G,description:Q,seed:O.name,icon:te,author:null,authorLabel:Y||void 0,version:I?I.installedVersion:$,category:ee,tags:K,installed:!I,hideStats:!0,cornerLabel:I?e("installedTab.updateAvailable"):void 0,onClick:()=>{O.path&&_({type:O.type,name:O.name})},actions:I?i.jsx("button",{type:"button",disabled:m.has(O.name),onClick:()=>{D(O.name,I.availableVersion)},className:"px-3 py-1.5 text-xs font-medium bg-amber-600 hover:bg-amber-500 text-white rounded-lg disabled:opacity-50 transition-colors",children:m.has(O.name)?e("installedTab.updating"):e("installedTab.updateTo",{version:I.availableVersion})}):void 0},`${O.type}/${O.name}`)})})}),h&&i.jsx("div",{className:`fixed bottom-6 left-1/2 -translate-x-1/2 z-50 px-4 py-2 rounded-lg text-sm shadow-lg ${h.type==="success"?"bg-emerald-600 text-white":"bg-red-600 text-white"}`,children:h.text})]})}const uie=50,die=30;function mie(e,t,n,a){const s=k.useRef(0),l=k.useRef(0),c=k.useCallback(m=>{s.current=m.touches[0].clientX,l.current=m.touches[0].clientY},[]),d=k.useCallback(m=>{const p=m.changedTouches[0].clientX-s.current,h=m.changedTouches[0].clientY-l.current,g=Math.abs(p),x=Math.abs(h);if(g<uie||Math.atan2(x,g)*(180/Math.PI)>die)return;if(a?.scrollContainerRef?.current){const T=a.scrollContainerRef.current,C=T.scrollLeft<=1,S=T.scrollLeft+T.clientWidth>=T.scrollWidth-1;if(p>0&&!C||p<0&&!S)return}const w=e.findIndex(T=>T.id===t);p<0&&w<e.length-1?n(e[w+1].id):p>0&&w>0?n(e[w-1].id):p>0&&w===0&&a?.onSwipeOutLeft?a.onSwipeOutLeft():p<0&&w===e.length-1&&a?.onSwipeOutRight&&a.onSwipeOutRight()},[e,t,n,a]);return{onTouchStart:c,onTouchEnd:d}}const pie=["builder","discover","agents","teams","skills","installed"],fie={agent:"agents",team:"teams",skill:"skills",connector:"skills"};function Sg(e){return!!e&&pie.includes(e)}function Tk(){const e=localStorage.getItem("markus_nav_installItem"),t=localStorage.getItem("markus_nav_storeTab");return{tab:Sg(t)?t:"builder",installId:e}}function hie({authUser:e}){const{t}=ot(["nav","store","common"]),n=k.useMemo(()=>[{id:"builder",label:t("nav:tabs.create")},{id:"discover",label:t("nav:tabs.discover")},{id:"agents",label:t("nav:tabs.agents")},{id:"teams",label:t("nav:tabs.teams")},{id:"skills",label:t("nav:tabs.skills")},{id:"installed",label:t("nav:tabs.installed")}],[t]),[a]=k.useState(Tk),[s,l]=k.useState(a.tab),[c,d]=k.useState(a.installId),m=mie(n,s,l);k.useEffect(()=>{const h=Tk();h.installId&&(d(h.installId),Sg(h.tab)&&l(h.tab),localStorage.removeItem("markus_nav_installItem"),localStorage.removeItem("markus_nav_storeTab"))},[]),k.useEffect(()=>{const h=g=>{const x=g.detail,y=x.params?.storeTab??localStorage.getItem("markus_nav_storeTab");Sg(y)&&l(y);const w=x.params?.installItem??localStorage.getItem("markus_nav_installItem");w&&d(w),localStorage.removeItem("markus_nav_storeTab"),localStorage.removeItem("markus_nav_installItem")};return window.addEventListener("markus:navigate",h),()=>window.removeEventListener("markus:navigate",h)},[]);const p=(h,g)=>{g&&d(g),l(fie[h]??"agents")};return i.jsxs("div",{className:"flex-1 overflow-hidden flex flex-col",onTouchStart:m.onTouchStart,onTouchEnd:m.onTouchEnd,children:[i.jsxs("div",{className:"flex items-center shrink-0 overflow-x-auto scrollbar-hide",children:[i.jsx(g4,{className:"ml-2"}),n.map(h=>i.jsx("button",{onClick:()=>l(h.id),className:`flex-1 min-w-fit px-3 py-2.5 text-xs font-medium text-center whitespace-nowrap transition-colors border-b-2 ${s===h.id?"border-brand-500 text-brand-500":"border-transparent text-fg-tertiary"}`,children:h.label},h.id))]}),i.jsxs("div",{className:"flex-1 overflow-hidden flex flex-col",children:[s==="builder"&&i.jsx(s6,{authUser:e}),s==="discover"&&i.jsx(oie,{onOpenType:p}),s==="agents"&&i.jsx(Xre,{authUser:e,highlightItemId:c,onHighlightDone:()=>d(null)}),s==="teams"&&i.jsx(eie,{highlightItemId:c,onHighlightDone:()=>d(null)}),s==="skills"&&i.jsx(rie,{highlightItemId:c,onHighlightDone:()=>d(null)}),s==="installed"&&i.jsx(cie,{})]})]})}const Nk="usageType",kh="profile";function gie({onComplete:e,theme:t,onThemeChange:n,skipProfile:a,onProfileUpdated:s}){const{t:l}=ot(["onboarding","common"]),[c,d]=k.useState(0),[m,p]=k.useState(""),[h,g]=k.useState(""),[x,y]=k.useState(""),[w,T]=k.useState(""),[C,S]=k.useState(!1),[E,_]=k.useState(""),[L,D]=k.useState(!1),[M,O]=k.useState(null);k.useEffect(()=>{Ae.auth.me().then(({user:$e})=>{$e.name&&p($e.name),$e.email&&g($e.email),$e.avatarUrl&&O($e.avatarUrl);const mt=$e.name||$e.email?.split("@")[0]||"";mt&&Y(At=>At||l("usageType.defaultOrgName",{name:mt}))}).catch(()=>{}),Ae.settings.getOrg().then(({org:$e})=>{$e?.name&&$e.name!=="My Organization"&&Y($e.name)}).catch(()=>{}),jn()&&Ae.hubOrgs.invitations().then($e=>{$e.invitations?.length>0&&Ce($e.invitations)}).catch(()=>{})},[]);const[G,Q]=k.useState(null),[$,Y]=k.useState(""),[K,ee]=k.useState(!1),[U,te]=k.useState(!1),[I,J]=k.useState(""),[me,Ce]=k.useState([]),[H,V]=k.useState(null),[fe,z]=k.useState(null),je=async()=>{const $e=$.trim();if($e){ee(!0),J("");try{if(await Ae.settings.updateOrg($e),jn()){const mt=await Ae.hubOrgs.mine(),At=mt.orgs?.find(Dt=>Dt.role==="owner")??mt.orgs?.[0];At?.id?await Ae.hubOrgs.update(At.id,{name:$e}):await Ae.hubOrgs.create($e)}te(!0)}catch{J(l("usageType.orgNameSaveFailed"))}finally{ee(!1)}}},[Ue,qe]=k.useState(!0),He=async()=>{if(_(""),!m.trim()){_(l("profile.errors.nameRequired"));return}if(!h.trim()){_(l("profile.errors.emailRequired"));return}if(!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(h.trim())){_(l("profile.errors.emailInvalid"));return}if(x&&x.length<6){_(l("profile.errors.passwordTooShort"));return}if(x&&x!==w){_(l("profile.errors.passwordMismatch"));return}S(!0);try{const{user:$e}=await Ae.auth.updateProfile(m.trim(),h.trim());x&&await Ae.auth.changePassword("",x),s?.($e),D(!0)}catch{_(l("profile.errors.saveFailed"))}finally{S(!1)}},ut=[{value:"system",label:l("theme.system"),icon:"💻",desc:l("theme.systemDesc")},{value:"light",label:l("theme.light"),icon:"☀️",desc:l("theme.lightDesc")},{value:"dark",label:l("theme.dark"),icon:"🌊",desc:l("theme.darkDesc")},{value:"cyberpunk",label:l("theme.cyberpunk"),icon:"🔮",desc:l("theme.cyberpunkDesc")},{value:"mono",label:l("theme.mono"),icon:"⬛",desc:l("theme.monoDesc")}],dt=[{id:"welcome",title:l("welcome.title"),subtitle:l("welcome.subtitle"),content:i.jsx("p",{className:"text-fg-secondary text-sm leading-relaxed",children:i.jsx(pT,{i18nKey:"welcome.description",ns:"onboarding",components:{strong:i.jsx("strong",{className:"text-fg-primary"})}})})},{id:Nk,title:l("usageType.title",{defaultValue:"How will you use Markus?"}),subtitle:l("usageType.subtitle",{defaultValue:"This helps us tailor your experience."}),content:i.jsxs("div",{className:"space-y-4",children:[i.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[i.jsxs("button",{onClick:()=>{Q("personal"),te(!0)},className:`flex flex-col items-center gap-3 rounded-xl border-2 p-5 transition-all text-left ${G==="personal"?"border-brand-500 bg-brand-500/10":"border-border-default hover:border-fg-tertiary bg-surface-elevated/30"}`,children:[i.jsx("span",{className:"text-2xl",children:"👤"}),i.jsxs("div",{children:[i.jsx("div",{className:"font-medium text-fg-primary text-sm text-center",children:l("usageType.personal",{defaultValue:"Personal"})}),i.jsx("div",{className:"text-[11px] text-fg-tertiary mt-1 text-center",children:l("usageType.personalDesc",{defaultValue:"Individual use with your own AI agents."})})]})]}),i.jsxs("button",{onClick:()=>{Q("organization"),te(!1)},className:`flex flex-col items-center gap-3 rounded-xl border-2 p-5 transition-all text-left ${G==="organization"?"border-brand-500 bg-brand-500/10":"border-border-default hover:border-fg-tertiary bg-surface-elevated/30"}`,children:[i.jsx("span",{className:"text-2xl",children:"🏢"}),i.jsxs("div",{children:[i.jsx("div",{className:"font-medium text-fg-primary text-sm text-center",children:l("usageType.organization",{defaultValue:"Team & Enterprise"})}),i.jsx("div",{className:"text-[11px] text-fg-tertiary mt-1 text-center",children:l("usageType.organizationDesc",{defaultValue:"For teams sharing licenses and collaborating."})})]})]})]}),G==="organization"&&i.jsxs("div",{className:"space-y-4 mt-4",children:[me.length>0&&i.jsxs("div",{className:"space-y-2",children:[i.jsx("div",{className:"text-xs text-fg-tertiary font-medium",children:l("usageType.pendingInvitations")}),me.map($e=>i.jsxs("div",{className:"flex items-center justify-between px-4 py-3 rounded-xl border border-amber-500/20 bg-amber-500/5",children:[i.jsxs("div",{children:[i.jsx("div",{className:"text-sm font-medium text-fg-primary",children:$e.orgName}),i.jsx("div",{className:"text-[11px] text-fg-tertiary",children:l("usageType.invitedBy",{name:$e.invitedBy})})]}),i.jsx("button",{onClick:async()=>{V($e.orgId);try{await Ae.hubOrgs.acceptInvitation($e.orgId),z($e.orgId),te(!0)}catch{}finally{V(null)}},disabled:H===$e.orgId||fe===$e.orgId,className:"px-3 py-1.5 text-xs rounded-lg bg-brand-600 hover:bg-brand-500 disabled:opacity-40 text-white transition-colors",children:fe===$e.orgId?l("usageType.accepted"):H===$e.orgId?l("usageType.accepting"):l("usageType.acceptAndJoin")})]},$e.orgId)),i.jsx("div",{className:"text-[11px] text-fg-tertiary text-center pt-1",children:l("usageType.orCreateNew")})]}),i.jsxs("div",{className:"space-y-1",children:[i.jsx("label",{className:"text-xs text-fg-tertiary font-medium",children:l("usageType.orgNameLabel")}),i.jsx("input",{type:"text",value:$,onChange:$e=>{Y($e.target.value),te(!1),J("")},placeholder:l("usageType.orgNamePlaceholder"),className:"w-full px-4 py-2.5 bg-surface-elevated border border-border-default rounded-xl text-sm text-fg-primary focus:border-brand-500 outline-none transition-colors"})]}),I&&i.jsx("p",{className:"text-xs text-red-500",children:I}),i.jsx("button",{onClick:()=>{je()},disabled:K||!$.trim()||U,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:l(K?"common:saving":U?"usageType.orgNameSaved":"usageType.setOrgName")})]})]})},{id:kh,title:l("profile.title"),subtitle:l("profile.subtitle"),content:L?i.jsxs("div",{className:"flex items-center gap-3 bg-green-500/10 border border-green-500/30 rounded-xl p-4",children:[i.jsx("span",{className:"text-green-600 text-lg",children:"✓"}),i.jsxs("div",{children:[i.jsx("div",{className:"text-sm font-medium text-green-600",children:l("profile.saved")}),i.jsxs("div",{className:"text-xs text-fg-secondary mt-0.5",children:[m," · ",h]})]})]}):i.jsxs("div",{className:"space-y-4",children:[i.jsx("div",{className:"flex justify-center",children:i.jsx(f4,{currentUrl:M,name:m,size:64,targetType:"user"})}),i.jsxs("div",{className:"space-y-1",children:[i.jsxs("label",{className:"text-xs text-fg-tertiary font-medium",children:[l("profile.nameLabel")," ",i.jsx("span",{className:"text-red-500",children:"*"})]}),i.jsx("input",{type:"text",value:m,onChange:$e=>p($e.target.value),placeholder:l("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})]}),i.jsxs("div",{className:"space-y-1",children:[i.jsxs("label",{className:"text-xs text-fg-tertiary font-medium",children:[l("profile.emailLabel")," ",i.jsx("span",{className:"text-red-500",children:"*"})]}),i.jsx("input",{type:"email",value:h,onChange:$e=>g($e.target.value),placeholder:l("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"})]}),i.jsxs("div",{className:"space-y-1",children:[i.jsx("label",{className:"text-xs text-fg-tertiary font-medium",children:l("profile.newPasswordLabel")}),i.jsx("input",{type:"password",value:x,onChange:$e=>y($e.target.value),placeholder:l("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"})]}),x&&i.jsxs("div",{className:"space-y-1",children:[i.jsx("label",{className:"text-xs text-fg-tertiary font-medium",children:l("profile.confirmPasswordLabel")}),i.jsx("input",{type:"password",value:w,onChange:$e=>T($e.target.value),placeholder:l("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"})]}),E&&i.jsx("div",{className:"px-3 py-2 bg-red-500/10 border border-red-500/30 rounded-lg text-xs text-red-500",children:E}),i.jsx("button",{onClick:()=>{He()},disabled:C||!m.trim()||!h.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:l(C?"common:saving":"profile.saveProfile")})]})},{id:"theme",title:l("theme.title"),subtitle:l("theme.subtitle"),content:i.jsxs("div",{className:"space-y-4",children:[i.jsx("div",{className:"grid grid-cols-3 gap-3",children:ut.map($e=>i.jsxs("button",{onClick:()=>n($e.value),className:`flex flex-col items-center gap-2 rounded-xl border-2 p-5 transition-all ${t===$e.value?"border-brand-500 bg-brand-500/10":"border-border-default hover:border-fg-tertiary bg-surface-elevated/30"}`,children:[i.jsx("span",{className:"text-2xl",children:$e.icon}),i.jsx("span",{className:"text-sm font-medium text-fg-primary",children:$e.label}),i.jsx("span",{className:"text-[11px] text-fg-tertiary leading-tight text-center",children:$e.desc})]},$e.value))}),i.jsxs("label",{className:"flex items-center gap-2.5 p-3 bg-surface-elevated/30 rounded-lg cursor-pointer group",children:[i.jsx("input",{type:"checkbox",checked:Ue,onChange:$e=>qe($e.target.checked),className:"accent-brand-500 shrink-0"}),i.jsx("span",{className:"text-[11px] text-fg-tertiary",children:l("done.telemetry")})]})]})}],Nt=a?dt.filter($e=>$e.id!==kh):dt,wt=Nt.findIndex($e=>$e.id===Nk),Zt=Nt.findIndex($e=>$e.id===kh),Wt=()=>{c===wt&&wt>=0&&!G||c===wt&&G==="organization"&&!U||c===Zt&&Zt>=0&&!L||(c<Nt.length-1?d(c+1):(fetch("/api/settings/telemetry",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({enabled:Ue})}).catch(()=>{}),e()))},rt=Nt[c];return i.jsx("div",{className:"min-h-dvh bg-surface-primary flex items-center justify-center p-4",children:i.jsx("div",{className:"w-full max-w-lg",children:i.jsxs("div",{className:"bg-surface-elevated rounded-2xl p-8",children:[i.jsx("div",{className:"flex gap-1.5 mb-8",children:Nt.map(($e,mt)=>i.jsx("div",{className:`h-1 flex-1 rounded-full transition-colors ${mt<=c?"bg-brand-500":"bg-surface-elevated"}`},mt))}),i.jsx("h2",{className:"text-2xl font-bold text-fg-primary",children:rt.title}),i.jsx("p",{className:"text-sm text-fg-secondary mt-1 mb-6",children:rt.subtitle}),rt.content,i.jsxs("div",{className:"flex justify-between mt-8",children:[c>0?i.jsx("button",{onClick:()=>d(c-1),className:"px-4 py-2 text-sm text-fg-secondary hover:text-fg-primary transition-colors",children:l("common:back")}):i.jsx("span",{}),i.jsx("button",{onClick:Wt,disabled:Zt>=0&&c===Zt&&!L||wt>=0&&c===wt&&(!G||G==="organization"&&!U),className:`px-6 py-2.5 text-white text-sm rounded-xl transition-colors ${Zt>=0&&c===Zt&&!L||wt>=0&&c===wt&&(!G||G==="organization"&&!U)?"bg-brand-600/40 cursor-not-allowed":"bg-brand-600 hover:bg-brand-500"}`,children:c===Nt.length-1?l("getStarted"):l("common:next")})]})]})})})}const Ek="markus:legal-consent",bie="https://markus.global";function yie({onLogin:e,hasOwner:t}){const{t:n,i18n:a}=ot("auth"),[s,l]=k.useState(null),[c,d]=k.useState(""),[m,p]=k.useState(!1),[h,g]=k.useState(""),[x,y]=k.useState(""),[w,T]=k.useState(!1),[C,S]=k.useState(!1),E=Y=>{const K=(a.language||"").toLowerCase().startsWith("zh")?"?lang=zh":"";return`${bie}${Y}${K}`},_=()=>{try{localStorage.setItem(Ek,JSON.stringify({acceptedAt:new Date().toISOString(),terms:!0,privacy:!0}))}catch{}},L=()=>C?(_(),!0):(T(!1),requestAnimationFrame(()=>T(!0)),!1),D=async()=>{const Y=jn(),K=xr();if(!Y||!K){d(n("login.hubUnavailable"));return}const ee=await Ae.auth.hubLogin(Y,K);if(window.markusDesktop?.clearPendingDeepLinkAuth?.(),ee.cloudAiReady===!1)try{sessionStorage.setItem("markus:cloud-ai-warning",ee.cloudAiError?n("login.cloudAiNotReady",{error:ee.cloudAiError}):n("login.cloudAiNotReadyGeneric"))}catch{}e(ee.user,ee.needsOnboarding??!1,{fromHub:!0})},M=async(Y,K=!1)=>{if(!(!K&&!L())){d(""),l(Y??"hub");try{if(K&&jn()&&xr()){await D();return}await Ha({method:Y,force:!0}),await D()}catch(ee){const U=ee instanceof Error?ee.message:"";if(!U.includes("cancelled")){if(!K&&jn())return M(Y,!0);d(U||n("login.hubUnavailable"))}}finally{l(null)}}},O=()=>{hU(),l(null),d("")};k.useEffect(()=>{const Y=window.markusDesktop;if(!Y?.peekPendingDeepLinkAuth&&!Y?.consumePendingDeepLinkAuth)return;let K=!1;return(async()=>{const ee=Y.peekPendingDeepLinkAuth?await Y.peekPendingDeepLinkAuth():null;if(K||!ee)return;let U=!1;try{U=!!localStorage.getItem(Ek)}catch{}if(!C&&!U){d(n("login.consentRequired"));return}U&&!C&&S(!0),_();const te=Y.consumePendingDeepLinkAuth?await Y.consumePendingDeepLinkAuth():ee;if(!(K||!te)){d(""),l("hub");try{if(!await fU(te)||!jn()||!xr()){d(n("login.hubUnavailable"));return}await D()}catch{d(n("login.hubUnavailable"))}finally{K||l(null)}}})().catch(()=>{}),()=>{K=!0}},[C]);const G=async Y=>{if(Y.preventDefault(),!(!h.trim()||!x)&&L()){d(""),l("local");try{const{user:K,needsOnboarding:ee}=await Ae.auth.login(h.trim(),x);e(K,ee??!1)}catch{d(n("login.invalidCredentials"))}finally{l(null)}}},Q=n(t?"login.welcomeBack":"login.getStarted"),$="w-full flex items-center justify-center gap-3 h-11 px-4 bg-surface-elevated border border-border-default rounded-xl text-sm text-fg-primary font-medium transition-all hover:border-brand-400/60 hover:shadow-sm active:scale-[0.99] disabled:opacity-50 disabled:pointer-events-none";return i.jsxs("div",{className:"min-h-dvh bg-surface-primary flex flex-col items-center justify-center p-4 relative overflow-hidden",children:[i.jsxs("div",{className:"pointer-events-none absolute inset-0 overflow-hidden",children:[i.jsx("div",{className:"absolute -top-48 left-1/2 -translate-x-1/2 h-[42rem] w-[42rem] rounded-full bg-brand-500/20 blur-[120px]"}),i.jsx("div",{className:"absolute top-1/4 -left-40 h-[26rem] w-[26rem] rounded-full bg-brand-400/10 blur-[100px]"}),i.jsx("div",{className:"absolute -bottom-40 -right-32 h-[34rem] w-[34rem] rounded-full bg-brand-600/10 blur-[110px]"})]}),i.jsxs("div",{className:"w-full max-w-[26rem] relative z-10 flex-1 flex flex-col justify-center",children:[i.jsxs("div",{className:"text-center mb-8",children:[i.jsx("img",{src:"/logo.png",alt:"Markus",className:"w-16 h-16 mx-auto mb-4 rounded-2xl shadow-xl shadow-brand-900/20 ring-1 ring-border-default/40"}),i.jsx("div",{className:"text-[1.75rem] leading-none font-extrabold tracking-tight text-fg-primary mb-2",children:"Markus"}),i.jsx("div",{className:"text-sm text-fg-tertiary",children:Q})]}),i.jsx("div",{className:"bg-surface-secondary/70 backdrop-blur-xl border border-border-default/80 rounded-3xl p-7 sm:p-8 shadow-2xl shadow-black/10",children:m?i.jsxs("div",{className:"space-y-4",children:[i.jsxs("div",{children:[i.jsx("div",{className:"text-base font-semibold text-fg-primary",children:n("login.localTitle")}),i.jsx("div",{className:"text-xs text-fg-tertiary mt-0.5",children:n("login.localAccountHint")})]}),i.jsxs("form",{onSubmit:G,className:"space-y-3",children:[i.jsx("input",{type:"email",value:h,onChange:Y=>g(Y.target.value),autoComplete:"email",autoFocus:!0,placeholder:n("login.email"),className:"w-full px-4 h-11 bg-surface-elevated border border-border-default rounded-xl text-sm text-fg-primary focus:border-brand-500 focus:ring-2 focus:ring-brand-500/20 outline-none transition-all placeholder:text-fg-tertiary",required:!0}),i.jsx("input",{type:"password",value:x,onChange:Y=>y(Y.target.value),autoComplete:"current-password",placeholder:n("login.password"),className:"w-full px-4 h-11 bg-surface-elevated border border-border-default rounded-xl text-sm text-fg-primary focus:border-brand-500 focus:ring-2 focus:ring-brand-500/20 outline-none transition-all placeholder:text-fg-tertiary",required:!0}),c&&i.jsx("div",{className:"px-3 py-2 bg-red-500/10 border border-red-500/30 rounded-lg text-xs text-red-500",children:c}),!t&&i.jsx("p",{className:"text-[11px] text-fg-tertiary",children:n("login.defaultCredentials")}),i.jsx("button",{type:"submit",disabled:s==="local"||!h||!x,className:"w-full h-11 bg-brand-600 hover:bg-brand-500 disabled:opacity-50 text-white text-sm font-semibold rounded-xl transition-all shadow-md shadow-brand-900/30 hover:shadow-lg active:scale-[0.99]",children:n(s==="local"?"login.signingIn":"login.signIn")})]}),i.jsx("div",{className:"text-center",children:i.jsx("button",{onClick:()=>{p(!1),d("")},className:"text-xs text-fg-tertiary hover:text-fg-secondary transition-colors",children:n("login.backToHub")})})]}):i.jsxs("div",{className:"space-y-3",children:[i.jsxs("button",{onClick:()=>M("google"),disabled:!!s,className:$,children:[i.jsxs("svg",{className:"w-5 h-5",viewBox:"0 0 24 24",children:[i.jsx("path",{fill:"#4285F4",d:"M22.56 12.25c0-.78-.07-1.53-.2-2.25H12v4.26h5.92a5.06 5.06 0 01-2.2 3.32v2.77h3.57c2.08-1.92 3.28-4.74 3.28-8.1z"}),i.jsx("path",{fill:"#34A853",d:"M12 23c2.97 0 5.46-.98 7.28-2.66l-3.57-2.77c-.98.66-2.23 1.06-3.71 1.06-2.86 0-5.29-1.93-6.16-4.53H2.18v2.84C3.99 20.53 7.7 23 12 23z"}),i.jsx("path",{fill:"#FBBC05",d:"M5.84 14.09c-.22-.66-.35-1.36-.35-2.09s.13-1.43.35-2.09V7.07H2.18C1.43 8.55 1 10.22 1 12s.43 3.45 1.18 4.93l2.85-2.22.81-.62z"}),i.jsx("path",{fill:"#EA4335",d:"M12 5.38c1.62 0 3.06.56 4.21 1.64l3.15-3.15C17.45 2.09 14.97 1 12 1 7.7 1 3.99 3.47 2.18 7.07l3.66 2.84c.87-2.6 3.3-4.53 6.16-4.53z"})]}),n(s==="google"?"login.connectingHub":"login.withGoogle")]}),i.jsxs("button",{onClick:()=>M("github"),disabled:!!s,className:$,children:[i.jsx("svg",{className:"w-5 h-5",viewBox:"0 0 24 24",fill:"currentColor",children:i.jsx("path",{d:"M12 0C5.37 0 0 5.37 0 12c0 5.31 3.435 9.795 8.205 11.385.6.105.825-.255.825-.57 0-.285-.015-1.23-.015-2.235-3.015.555-3.795-.735-4.035-1.41-.135-.345-.72-1.41-1.23-1.695-.42-.225-1.02-.78-.015-.795.945-.015 1.62.87 1.845 1.23 1.08 1.815 2.805 1.305 3.495.99.105-.78.42-1.305.765-1.605-2.67-.3-5.46-1.335-5.46-5.925 0-1.305.465-2.385 1.23-3.225-.12-.3-.54-1.53.12-3.18 0 0 1.005-.315 3.3 1.23.96-.27 1.98-.405 3-.405s2.04.135 3 .405c2.295-1.56 3.3-1.23 3.3-1.23.66 1.65.24 2.88.12 3.18.765.84 1.23 1.905 1.23 3.225 0 4.605-2.805 5.625-5.475 5.925.435.375.81 1.095.81 2.22 0 1.605-.015 2.895-.015 3.3 0 .315.225.69.825.57A12.02 12.02 0 0024 12c0-6.63-5.37-12-12-12z"})}),n(s==="github"?"login.connectingHub":"login.withGithub")]}),i.jsxs("button",{onClick:()=>M("email"),disabled:!!s,className:$,children:[i.jsx("svg",{className:"w-5 h-5",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:1.5,children:i.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M21.75 6.75v10.5a2.25 2.25 0 01-2.25 2.25h-15a2.25 2.25 0 01-2.25-2.25V6.75m19.5 0A2.25 2.25 0 0019.5 4.5h-15a2.25 2.25 0 00-2.25 2.25m19.5 0v.243a2.25 2.25 0 01-1.07 1.916l-7.5 4.615a2.25 2.25 0 01-2.36 0L3.32 8.91a2.25 2.25 0 01-1.07-1.916V6.75"})}),n(s==="email"?"login.connectingHub":"login.withEmail")]}),s&&(s==="google"||s==="github"||s==="email"||s==="hub")&&i.jsxs("div",{className:"px-3 py-2.5 bg-brand-500/10 border border-brand-500/30 rounded-lg text-xs text-fg-secondary space-y-2",children:[i.jsx("p",{children:n("login.browserOpened")}),i.jsx("button",{type:"button",onClick:O,className:"text-brand-500 hover:text-brand-400 underline font-medium",children:n("login.cancelWaiting")})]}),c&&i.jsx("div",{className:"px-3 py-2 bg-red-500/10 border border-red-500/30 rounded-lg text-xs text-red-500",children:c}),i.jsxs("div",{className:"flex items-center gap-3 py-1 text-[11px] text-fg-tertiary",children:[i.jsx("span",{className:"h-px flex-1 bg-border-default"}),n("login.or"),i.jsx("span",{className:"h-px flex-1 bg-border-default"})]}),i.jsx("button",{onClick:()=>{p(!0),d("")},disabled:!!s,className:"w-full h-11 px-4 rounded-xl text-sm text-fg-secondary font-medium transition-all hover:bg-surface-elevated/70 disabled:opacity-50",children:n("login.useLocalAccount")})]})}),i.jsxs("label",{onAnimationEnd:()=>T(!1),className:`mt-5 flex items-start justify-center gap-2 text-[11px] leading-relaxed cursor-pointer select-none px-2 transition-colors ${w?"animate-shake text-fg-primary font-medium":"text-fg-tertiary"}`,children:[i.jsx("input",{type:"checkbox",checked:C,onChange:Y=>{S(Y.target.checked),Y.target.checked&&T(!1)},className:"mt-0.5 h-3.5 w-3.5 shrink-0 accent-brand-600 cursor-pointer"}),i.jsxs("span",{className:"text-center",children:[n("login.consentPrefix")," ",i.jsx("a",{href:E("/terms"),target:"_blank",rel:"noopener noreferrer",className:"text-brand-500 hover:text-brand-400 underline",children:n("login.termsLink")})," ",n("login.consentAnd")," ",i.jsx("a",{href:E("/privacy"),target:"_blank",rel:"noopener noreferrer",className:"text-brand-500 hover:text-brand-400 underline",children:n("login.privacyLink")})]})]})]}),i.jsxs("div",{className:"relative z-10 flex flex-wrap items-center justify-center gap-x-5 gap-y-1 py-6 text-[11px] text-fg-tertiary",children:[i.jsx("a",{href:"https://markus.global",target:"_blank",rel:"noopener noreferrer",className:"hover:text-fg-secondary transition-colors",children:"markus.global"}),i.jsx("a",{href:"mailto:business@markus.global",className:"hover:text-fg-secondary transition-colors",children:n("login.contactSales")})]})]})}function xie({token:e,onComplete:t}){const{t:n}=ot("auth"),[a,s]=k.useState(null),[l,c]=k.useState(""),[d,m]=k.useState(""),[p,h]=k.useState(""),[g,x]=k.useState(!1),[y,w]=k.useState(!1),[T,C]=k.useState(!1);k.useEffect(()=>{Ae.auth.inviteInfo(e).then(E=>s(E)).catch(()=>C(!0))},[e]);const S=async E=>{if(E.preventDefault(),h(""),l.length<6){h(n("invite.passwordMinLength"));return}if(l!==d){h(n("invite.passwordsDoNotMatch"));return}x(!0);try{await Ae.auth.setup(e,l),w(!0),setTimeout(()=>{window.location.hash="",t()},2e3)}catch{h(n("invite.error"))}finally{x(!1)}};return i.jsxs("div",{className:"min-h-dvh bg-surface-primary flex items-center justify-center p-4 relative overflow-hidden",children:[i.jsx("div",{className:"absolute inset-0 bg-[radial-gradient(ellipse_at_top,_var(--tw-gradient-stops))] from-brand-950/50 via-transparent to-transparent"}),i.jsxs("div",{className:"w-full max-w-sm relative z-10",children:[i.jsxs("div",{className:"text-center mb-8",children:[i.jsx("img",{src:"/logo.png",alt:"Markus",className:"w-14 h-14 mx-auto mb-3 rounded-xl shadow-lg shadow-black/40"}),i.jsx("div",{className:"text-2xl font-extrabold tracking-tight text-fg-primary mb-1",children:"Markus"}),i.jsx("div",{className:"text-sm text-fg-tertiary",children:n("invite.subtitle")})]}),i.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:T?i.jsxs("div",{className:"text-center space-y-3",children:[i.jsx("div",{className:"text-red-500 text-3xl",children:"⚠"}),i.jsx("p",{className:"text-sm text-fg-secondary",children:n("invite.invalidLink")}),i.jsx("button",{onClick:()=>{window.location.hash="",t()},className:"text-sm text-brand-500 hover:text-brand-400",children:n("login.signIn")})]}):y?i.jsxs("div",{className:"text-center space-y-3",children:[i.jsx("div",{className:"text-green-500 text-3xl",children:"✓"}),i.jsx("p",{className:"text-sm text-fg-secondary",children:n("invite.setupComplete")})]}):a?i.jsxs("form",{onSubmit:S,className:"space-y-5",children:[i.jsx("h2",{className:"text-lg font-semibold text-fg-primary text-center",children:n("invite.greeting",{name:a.name})}),i.jsx("p",{className:"text-xs text-fg-tertiary text-center",children:a.email}),i.jsxs("div",{className:"space-y-1",children:[i.jsx("label",{className:"text-xs text-fg-tertiary font-medium",children:n("invite.setPassword")}),i.jsx("input",{type:"password",value:l,onChange:E=>c(E.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})]}),i.jsxs("div",{className:"space-y-1",children:[i.jsx("label",{className:"text-xs text-fg-tertiary font-medium",children:n("invite.confirmPassword")}),i.jsx("input",{type:"password",value:d,onChange:E=>m(E.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})]}),p&&i.jsx("div",{className:"px-3 py-2 bg-red-500/10 border border-red-500/30 rounded-lg text-xs text-red-500",children:p}),i.jsx("button",{type:"submit",disabled:g||!l||!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:n(g?"invite.settingUp":"invite.setupAccount")})]}):i.jsx("div",{className:"text-center text-fg-tertiary text-sm animate-pulse py-4",children:"Loading…"})})]})]})}function vie({onComplete:e,isFirstTime:t}){const{t:n}=ot("auth"),[a,s]=k.useState(""),[l,c]=k.useState(""),[d,m]=k.useState(""),[p,h]=k.useState(""),[g,x]=k.useState(!1),y=async w=>{if(w.preventDefault(),h(""),l.length<6){h(n("changePassword.passwordMinLength"));return}if(l!==d){h(n("changePassword.passwordsDoNotMatch"));return}x(!0);try{await Ae.auth.changePassword(a,l),e()}catch{h(n("changePassword.failedToChange"))}finally{x(!1)}};return i.jsxs("div",{className:"min-h-dvh bg-surface-primary flex items-center justify-center p-4 relative overflow-hidden",children:[i.jsx("div",{className:"absolute inset-0 bg-[radial-gradient(ellipse_at_top,_var(--tw-gradient-stops))] from-brand-950/50 via-transparent to-transparent"}),i.jsxs("div",{className:"w-full max-w-sm relative z-10",children:[i.jsxs("div",{className:"text-center mb-8",children:[i.jsx("img",{src:"/logo.png",alt:"Markus",className:"w-14 h-14 mx-auto mb-3 rounded-xl shadow-lg shadow-black/40"}),i.jsx("div",{className:"text-2xl font-extrabold tracking-tight text-fg-primary mb-1",children:"Markus"}),i.jsx("div",{className:"text-sm text-fg-tertiary",children:n("login.subtitle")})]}),i.jsxs("form",{onSubmit:y,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:[i.jsxs("div",{children:[i.jsx("h2",{className:"text-lg font-semibold text-fg-primary text-center",children:n(t?"changePassword.setYourPassword":"changePassword.changePassword")}),t&&i.jsx("p",{className:"text-xs text-amber-600/80 text-center mt-2",children:n("changePassword.defaultPasswordWarning")})]}),!t&&i.jsxs("div",{className:"space-y-1",children:[i.jsx("label",{className:"text-xs text-fg-tertiary font-medium",children:n("changePassword.currentPassword")}),i.jsx("input",{type:"password",value:a,onChange:w=>s(w.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"})]}),i.jsxs("div",{className:"space-y-1",children:[i.jsx("label",{className:"text-xs text-fg-tertiary font-medium",children:n("changePassword.newPassword")}),i.jsx("input",{type:"password",value:l,onChange:w=>c(w.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})]}),i.jsxs("div",{className:"space-y-1",children:[i.jsx("label",{className:"text-xs text-fg-tertiary font-medium",children:n("changePassword.confirmNewPassword")}),i.jsx("input",{type:"password",value:d,onChange:w=>m(w.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})]}),p&&i.jsx("div",{className:"px-3 py-2 bg-red-500/10 border border-red-500/30 rounded-lg text-xs text-red-500",children:p}),i.jsx("button",{type:"submit",disabled:g||!l||!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:n(g?"changePassword.saving":t?"changePassword.setPasswordAndContinue":"changePassword.changePassword")})]})]})]})}function wie({side:e,defaultWidth:t,minWidth:n,maxWidth:a,collapsedWidth:s=0,storageKey:l}){const[c,d]=k.useState(()=>{try{const T=localStorage.getItem(`${l}_w`);if(T)return Math.max(n,Math.min(a,parseInt(T,10)))}catch{}return t}),[m,p]=k.useState(()=>{try{return localStorage.getItem(`${l}_c`)==="1"}catch{return!1}}),h=k.useRef(!1),g=k.useRef(n),x=k.useRef(a);g.current=n,x.current=a,k.useEffect(()=>{try{localStorage.setItem(`${l}_w`,String(c))}catch{}},[c,l]),k.useEffect(()=>{try{localStorage.setItem(`${l}_c`,m?"1":"0")}catch{}},[m,l]),k.useEffect(()=>{d(T=>Math.max(n,Math.min(a,T)))},[n,a]);const y=k.useCallback(T=>{T.preventDefault(),h.current=!0;const C=T.clientX,S=c,E=L=>{if(!h.current)return;const D=L.clientX-C;d(Math.max(g.current,Math.min(x.current,S+D)))},_=()=>{h.current=!1,document.removeEventListener("mousemove",E),document.removeEventListener("mouseup",_),document.body.style.cursor="",document.body.style.userSelect=""};document.addEventListener("mousemove",E),document.addEventListener("mouseup",_),document.body.style.cursor="col-resize",document.body.style.userSelect="none"},[c,e]),w=k.useCallback(()=>p(T=>!T),[]);return{width:m?s:c,rawWidth:c,collapsed:m,toggle:w,setCollapsed:p,setWidth:d,onResizeStart:y}}const Hse=[{value:"system",label:"System"},{value:"light",label:"Light"},{value:"dark",label:"Dark"},{value:"cyberpunk",label:"Cyberpunk"},{value:"mono",label:"Mono"}],Cg="markus-theme";function jk(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 kie(){try{const e=localStorage.getItem(Cg);if(e==="midnight")return localStorage.setItem(Cg,"dark"),"dark";if(e==="light"||e==="dark"||e==="system"||e==="cyberpunk"||e==="mono")return e}catch{}return"system"}function Sie(){const[e,t]=k.useState(kie),n=k.useCallback(a=>{t(a);try{localStorage.setItem(Cg,a)}catch{}jk(a)},[]);return k.useEffect(()=>{jk(e)},[e]),{mode:e,setMode:n}}const am={agents:[],tasks:[],requirements:[],projects:[],deliverables:[],workflows:[]},Cie={team:["agents","workflows","tasks","requirements","projects","deliverables"],work:["workflows","projects","requirements","tasks","agents","deliverables"],deliverables:["deliverables","agents","tasks","requirements","projects","workflows"]},Aie=["agents","tasks","requirements","projects","deliverables","workflows"];let Mk="",_k="all",Rk=am,Dk=!1;function Tie({onClose:e,currentPage:t}){const{t:n}=ot(["common","home","work"]);Qo(!0);const[a,s]=k.useState(Mk),[l,c]=k.useState(_k),[d,m]=k.useState(Rk),[p,h]=k.useState(!1),[g,x]=k.useState(Dk),[y,w]=k.useState(-1);k.useEffect(()=>{Mk=a},[a]),k.useEffect(()=>{_k=l},[l]),k.useEffect(()=>{Rk=d},[d]),k.useEffect(()=>{Dk=g},[g]);const T=k.useRef(null),C=k.useRef(void 0),S=k.useRef(null),E=k.useRef(null);k.useEffect(()=>{setTimeout(()=>{T.current?.focus(),T.current?.select()},100)},[]);const _=k.useCallback(async ee=>{if(!ee.trim()){m(am),x(!1),w(-1);return}h(!0),x(!0),w(-1);const U=ee.toLowerCase();try{const[te,I,J,me,Ce,H]=await Promise.allSettled([Ae.agents.list(),Ae.tasks.list({search:ee,pageSize:20}),Ae.requirements.list(),Ae.projects.list(),Ae.deliverables.search({q:ee,limit:20}),Ae.teams.list()]),V=te.status==="fulfilled"?te.value.agents.filter(He=>He.name?.toLowerCase().includes(U)||He.role?.toLowerCase().includes(U)):[],fe=I.status==="fulfilled"?I.value.tasks:[],z=J.status==="fulfilled"?J.value.requirements.filter(He=>He.title?.toLowerCase().includes(U)||He.description?.toLowerCase().includes(U)):[],je=me.status==="fulfilled"?me.value.projects.filter(He=>He.name?.toLowerCase().includes(U)||He.description?.toLowerCase().includes(U)):[],Ue=Ce.status==="fulfilled"?Ce.value.results:[],qe=[];if(H.status==="fulfilled"){const He=await Promise.allSettled(H.value.teams.map(ut=>Ae.workflows.list(ut.id)));for(const ut of He)if(ut.status==="fulfilled")for(const dt of ut.value.workflows)(dt.name.toLowerCase().includes(U)||(dt.displayName||"").toLowerCase().includes(U)||dt.description?.toLowerCase().includes(U))&&qe.push(dt)}m({agents:V,tasks:fe,requirements:z,projects:je,deliverables:Ue,workflows:qe})}catch{m(am)}finally{h(!1)}},[]),L=ee=>{s(ee),C.current&&clearTimeout(C.current),C.current=setTimeout(()=>_(ee),400)},D=k.useCallback((ee,U)=>{e(),at.navigate(ee,U)},[e]),M=[{id:"all",label:n("common:all",{defaultValue:"全部"})},{id:"agents",label:n("common:agents",{defaultValue:"智能体"})},{id:"tasks",label:n("common:tasks",{defaultValue:"任务"})},{id:"requirements",label:n("common:requirements",{defaultValue:"需求"})},{id:"projects",label:n("common:projects",{defaultValue:"项目"})},{id:"deliverables",label:n("common:deliverables",{defaultValue:"交付物"})},{id:"workflows",label:n("common:workflows",{defaultValue:"工作流"})}],O=k.useMemo(()=>Cie[t||""]||Aie,[t]),G=k.useMemo(()=>{const ee=[],U=l==="all"?8:void 0,te=I=>{if(l!=="all"&&l!==I)return;const J=d[I].length;if(I==="workflows"){const me=U?d.workflows.slice(0,U):d.workflows;for(const Ce of me)ee.push({id:Ce.name,type:"workflow",page:de.WORK,params:{boardType:"workflows"}})}else{const me=d[I],Ce=U?me.slice(0,U):me;for(const H of Ce)switch(I){case"agents":ee.push({id:H.id,type:"agent",page:de.TEAM,params:{agentId:H.id}});break;case"tasks":ee.push({id:H.id,type:"task",page:de.WORK,params:{openTask:H.id}});break;case"requirements":ee.push({id:H.id,type:"requirement",page:de.WORK,params:{openRequirement:H.id}});break;case"projects":ee.push({id:H.id,type:"project",page:de.WORK,params:{projectId:H.id}});break;case"deliverables":ee.push({id:H.id,type:"deliverable",page:de.DELIVERABLES,params:{openDeliverable:H.id}});break}}U&&J>U&&ee.push({id:`more_${I}`,type:"showMore",page:"",expandCategory:I,totalCount:J})};for(const I of O)te(I);return ee},[d,l,O]),Q=k.useCallback(ee=>{if(ee.type==="showMore"&&ee.expandCategory){c(ee.expandCategory),w(-1);return}D(ee.page,ee.params)},[D]);k.useEffect(()=>{const ee=E.current;if(!ee||y<0)return;const U=ee.querySelector(`[data-idx="${y}"]`);U&&U.scrollIntoView({block:"nearest"})},[y]);const $=k.useCallback(ee=>{if(ee.key==="Escape"){e();return}if(ee.key==="Tab"){ee.preventDefault();const I=M.map(Ce=>Ce.id),J=I.indexOf(l),me=ee.shiftKey?J<=0?I.length-1:J-1:J>=I.length-1?0:J+1;c(I[me]),w(-1);return}const U=ee.ctrlKey&&ee.key==="n"||ee.key==="ArrowDown",te=ee.ctrlKey&&ee.key==="p"||ee.key==="ArrowUp";if(U||te){ee.preventDefault(),w(I=>{const J=G.length-1;return J<0?-1:U?I>=J?0:I+1:I<=0?J:I-1});return}ee.key==="Enter"&&(ee.preventDefault(),y>=0&&y<G.length&&Q(G[y]))},[e,G,y,Q,M,l]);k.useEffect(()=>(document.addEventListener("keydown",$),()=>document.removeEventListener("keydown",$)),[$]);const Y=G.length>0;let K=0;return i.jsx("div",{ref:S,className:"fixed inset-0 bg-black/50 flex items-start justify-center z-50 pt-[8vh]",onClick:ee=>{ee.target===S.current&&e()},children:i.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:[i.jsxs("div",{className:"shrink-0 px-5 pt-4 pb-3 border-b border-border-default space-y-3",children:[i.jsxs("div",{className:"relative",children:[i.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:[i.jsx("circle",{cx:"11",cy:"11",r:"8"}),i.jsx("line",{x1:"21",y1:"21",x2:"16.65",y2:"16.65"})]}),i.jsx("input",{ref:T,value:a,onChange:ee=>L(ee.target.value),placeholder:n("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"}),a&&i.jsx("button",{onClick:()=>{s(""),m(am),x(!1),w(-1),T.current?.focus()},className:"absolute right-3 top-1/2 -translate-y-1/2 text-fg-tertiary hover:text-fg-secondary",children:i.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[i.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),i.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]}),i.jsx("div",{className:"flex gap-1 overflow-x-auto scrollbar-hide",children:M.map(ee=>i.jsx("button",{onClick:()=>{c(ee.id),w(-1)},className:`px-3 py-1.5 text-xs rounded-lg whitespace-nowrap transition-colors ${l===ee.id?"bg-brand-600 text-white":"bg-surface-elevated text-fg-secondary hover:text-fg-primary"}`,children:ee.label},ee.id))})]}),i.jsxs("div",{ref:E,className:"flex-1 overflow-y-auto px-5 py-3",children:[p&&i.jsx("div",{className:"flex items-center justify-center py-8",children:i.jsx("div",{className:"text-fg-tertiary text-sm animate-pulse",children:n("common:loading")})}),!p&&g&&!Y&&i.jsxs("div",{className:"flex flex-col items-center justify-center py-8 text-center",children:[i.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:[i.jsx("circle",{cx:"11",cy:"11",r:"8"}),i.jsx("line",{x1:"21",y1:"21",x2:"16.65",y2:"16.65"})]}),i.jsx("p",{className:"text-sm text-fg-tertiary",children:n("common:noResults",{defaultValue:"没有找到相关结果"})})]}),!p&&Y&&i.jsx("div",{className:"space-y-4",children:O.map(ee=>{if(l!=="all"&&l!==ee)return null;const U=l==="all"?8:void 0,te=I=>{const J=K++,me=I==="agents"?d.agents.length:I==="tasks"?d.tasks.length:I==="requirements"?d.requirements.length:I==="projects"?d.projects.length:I==="workflows"?d.workflows.length:d.deliverables.length;return i.jsxs("button",{"data-idx":J,onClick:()=>{c(I),w(-1)},className:`mt-1 w-full text-xs py-1.5 rounded-lg transition-colors ${J===y?"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:[n("common:showAll",{defaultValue:"查看全部"})," (",me,")"]})};return ee==="agents"&&d.agents.length>0?i.jsxs("section",{children:[i.jsx("h3",{className:"text-xs font-medium text-fg-tertiary uppercase mb-2",children:n("common:agents",{defaultValue:"智能体"})}),i.jsx("div",{className:"space-y-0.5",children:(U?d.agents.slice(0,U):d.agents).map(I=>{const J=K++;return i.jsxs("button",{"data-idx":J,onClick:()=>D(de.TEAM,{agentId:I.id}),className:`w-full flex items-center gap-3 px-3 py-2 rounded-xl transition-colors text-left ${J===y?"bg-brand-600/15 ring-1 ring-brand-500/40":"hover:bg-surface-overlay"}`,children:[i.jsx(Zi,{name:I.name||"Agent",avatarUrl:I.avatarUrl,size:28}),i.jsxs("div",{className:"flex-1 min-w-0",children:[i.jsx("div",{className:"text-sm font-medium text-fg-primary truncate",children:I.name}),i.jsx("div",{className:"text-xs text-fg-tertiary truncate",children:I.role||I.status})]}),i.jsx(Nie,{status:I.status})]},I.id)})}),U&&d.agents.length>U&&te("agents")]},"agents"):ee==="tasks"&&d.tasks.length>0?i.jsxs("section",{children:[i.jsx("h3",{className:"text-xs font-medium text-fg-tertiary uppercase mb-2",children:n("common:tasks",{defaultValue:"任务"})}),i.jsx("div",{className:"space-y-0.5",children:(U?d.tasks.slice(0,U):d.tasks).map(I=>{const J=K++;return i.jsxs("button",{"data-idx":J,onClick:()=>D(de.WORK,{openTask:I.id}),className:`w-full flex items-center gap-3 px-3 py-2 rounded-xl transition-colors text-left ${J===y?"bg-brand-600/15 ring-1 ring-brand-500/40":"hover:bg-surface-overlay"}`,children:[i.jsx(Eie,{status:I.status}),i.jsxs("div",{className:"flex-1 min-w-0",children:[i.jsx("div",{className:"text-sm text-fg-primary truncate",children:I.title}),i.jsxs("div",{className:"text-xs text-fg-tertiary truncate",children:[I.status," · ",I.priority||""]})]})]},I.id)})}),U&&d.tasks.length>U&&te("tasks")]},"tasks"):ee==="requirements"&&d.requirements.length>0?i.jsxs("section",{children:[i.jsx("h3",{className:"text-xs font-medium text-fg-tertiary uppercase mb-2",children:n("common:requirements",{defaultValue:"需求"})}),i.jsx("div",{className:"space-y-0.5",children:(U?d.requirements.slice(0,U):d.requirements).map(I=>{const J=K++;return i.jsxs("button",{"data-idx":J,onClick:()=>D(de.WORK,{openRequirement:I.id}),className:`w-full flex items-center gap-3 px-3 py-2 rounded-xl transition-colors text-left ${J===y?"bg-brand-600/15 ring-1 ring-brand-500/40":"hover:bg-surface-overlay"}`,children:[i.jsx("div",{className:`w-7 h-7 rounded-lg flex items-center justify-center shrink-0 ${I.status==="approved"?"text-green-500 bg-green-500/15":I.status==="pending"?"text-amber-500 bg-amber-500/15":I.status==="rejected"?"text-red-500 bg-red-500/15":"text-fg-tertiary bg-surface-elevated"}`,children:i.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[i.jsx("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),i.jsx("polyline",{points:"14 2 14 8 20 8"}),i.jsx("line",{x1:"16",y1:"13",x2:"8",y2:"13"}),i.jsx("line",{x1:"16",y1:"17",x2:"8",y2:"17"})]})}),i.jsxs("div",{className:"flex-1 min-w-0",children:[i.jsx("div",{className:"text-sm text-fg-primary truncate",children:I.title}),i.jsxs("div",{className:"text-xs text-fg-tertiary truncate",children:[I.status," · ",I.priority||""]})]})]},I.id)})}),U&&d.requirements.length>U&&te("requirements")]},"requirements"):ee==="projects"&&d.projects.length>0?i.jsxs("section",{children:[i.jsx("h3",{className:"text-xs font-medium text-fg-tertiary uppercase mb-2",children:n("common:projects",{defaultValue:"项目"})}),i.jsx("div",{className:"space-y-0.5",children:(U?d.projects.slice(0,U):d.projects).map(I=>{const J=K++;return i.jsxs("button",{"data-idx":J,onClick:()=>D(de.WORK,{projectId:I.id}),className:`w-full flex items-center gap-3 px-3 py-2 rounded-xl transition-colors text-left ${J===y?"bg-brand-600/15 ring-1 ring-brand-500/40":"hover:bg-surface-overlay"}`,children:[i.jsx("div",{className:"w-7 h-7 rounded-lg bg-brand-500/15 flex items-center justify-center shrink-0",children:i.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:"text-brand-500",children:i.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"})})}),i.jsxs("div",{className:"flex-1 min-w-0",children:[i.jsx("div",{className:"text-sm text-fg-primary truncate",children:I.name}),I.description&&i.jsx("div",{className:"text-xs text-fg-tertiary truncate",children:I.description})]})]},I.id)})}),U&&d.projects.length>U&&te("projects")]},"projects"):ee==="deliverables"&&d.deliverables.length>0?i.jsxs("section",{children:[i.jsx("h3",{className:"text-xs font-medium text-fg-tertiary uppercase mb-2",children:n("common:deliverables",{defaultValue:"交付物"})}),i.jsx("div",{className:"space-y-0.5",children:(U?d.deliverables.slice(0,U):d.deliverables).map(I=>{const J=K++;return i.jsxs("button",{"data-idx":J,onClick:()=>D(de.DELIVERABLES,{openDeliverable:I.id}),className:`w-full flex items-center gap-3 px-3 py-2 rounded-xl transition-colors text-left ${J===y?"bg-brand-600/15 ring-1 ring-brand-500/40":"hover:bg-surface-overlay"}`,children:[i.jsx("div",{className:"w-7 h-7 rounded-lg bg-purple-500/15 flex items-center justify-center shrink-0",children:i.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:"text-purple-500",children:[i.jsx("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),i.jsx("polyline",{points:"14 2 14 8 20 8"})]})}),i.jsxs("div",{className:"flex-1 min-w-0",children:[i.jsx("div",{className:"text-sm text-fg-primary truncate",children:I.title}),i.jsxs("div",{className:"text-xs text-fg-tertiary truncate",children:[I.type," · ",I.status]})]})]},I.id)})}),U&&d.deliverables.length>U&&te("deliverables")]},"deliverables"):ee==="workflows"&&d.workflows.length>0?i.jsxs("section",{children:[i.jsx("h3",{className:"text-xs font-medium text-fg-tertiary uppercase mb-2",children:n("common:workflows",{defaultValue:"工作流"})}),i.jsx("div",{className:"space-y-0.5",children:(U?d.workflows.slice(0,U):d.workflows).map(I=>{const J=K++;return i.jsxs("button",{"data-idx":J,onClick:()=>D(de.WORK,{boardType:"workflows"}),className:`w-full flex items-center gap-3 px-3 py-2 rounded-xl transition-colors text-left ${J===y?"bg-brand-600/15 ring-1 ring-brand-500/40":"hover:bg-surface-overlay"}`,children:[i.jsx("div",{className:"w-7 h-7 rounded-lg bg-teal-500/15 flex items-center justify-center shrink-0",children:i.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:"text-teal-500",children:[i.jsx("circle",{cx:"12",cy:"12",r:"3"}),i.jsx("path",{d:"M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 0 1 0 2.83 2 2 0 0 1-2.83 0l-.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-2 2 2 2 0 0 1-2-2v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 0 1-2.83 0 2 2 0 0 1 0-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-2-2 2 2 0 0 1 2-2h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 0 1 0-2.83 2 2 0 0 1 2.83 0l.06.06A1.65 1.65 0 0 0 9 4.68a1.65 1.65 0 0 0 1-1.51V3a2 2 0 0 1 2-2 2 2 0 0 1 2 2v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 0 1 2.83 0 2 2 0 0 1 0 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 2 2 2 2 0 0 1-2 2h-.09a1.65 1.65 0 0 0-1.51 1z"})]})}),i.jsxs("div",{className:"flex-1 min-w-0",children:[i.jsx("div",{className:"text-sm text-fg-primary truncate",children:I.displayName||I.name}),i.jsxs("div",{className:"text-xs text-fg-tertiary truncate",children:[I.stepCount," steps · v",I.version]})]})]},I.name)})}),U&&d.workflows.length>U&&te("workflows")]},"workflows"):null})}),!p&&!g&&i.jsxs("div",{className:"flex flex-col items-center justify-center py-8 text-center",children:[i.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:[i.jsx("circle",{cx:"11",cy:"11",r:"8"}),i.jsx("line",{x1:"21",y1:"21",x2:"16.65",y2:"16.65"})]}),i.jsx("p",{className:"text-sm text-fg-tertiary",children:n("common:searchHint",{defaultValue:"输入关键词搜索"})})]})]}),i.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:[i.jsxs("span",{children:[i.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"})," ",n("common:toggle",{defaultValue:"唤起/关闭"})]}),i.jsxs("span",{children:[i.jsx("kbd",{className:"px-1.5 py-0.5 rounded bg-surface-elevated border border-border-default text-[11px] font-medium",children:"Tab"})," ",n("common:switchTab",{defaultValue:"切换分类"})]}),i.jsxs("span",{children:[i.jsx("kbd",{className:"px-1.5 py-0.5 rounded bg-surface-elevated border border-border-default text-[11px] font-medium",children:"↑↓"})," ",n("common:navigate",{defaultValue:"导航"})]}),i.jsxs("span",{children:[i.jsx("kbd",{className:"px-1.5 py-0.5 rounded bg-surface-elevated border border-border-default text-[11px] font-medium",children:"Enter"})," ",n("common:open",{defaultValue:"打开"})]}),i.jsxs("span",{children:[i.jsx("kbd",{className:"px-1.5 py-0.5 rounded bg-surface-elevated border border-border-default text-[11px] font-medium",children:"Esc"})," ",n("common:close",{defaultValue:"关闭"})]})]})]})})}function Nie({status:e}){const t=e==="active"||e==="idle"?"bg-green-500":e==="working"||e==="busy"?"bg-blue-500":"bg-gray-400";return i.jsx("span",{className:`w-2 h-2 rounded-full shrink-0 ${t}`})}function Eie({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 i.jsx("div",{className:`w-7 h-7 rounded-lg flex items-center justify-center shrink-0 ${t}`,children:i.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[i.jsx("path",{d:"M9 11l3 3L22 4"}),i.jsx("path",{d:"M21 12v7a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h11"})]})})}const jie=["layout","navigation","tasks","team","search","rightPanel","terminal","help"];function Mie(e){return e===de.TEAM?"team":e===de.WORK?"work":e===de.DELIVERABLES?"deliverables":e===de.STORE?"store":"any"}function _ie({open:e,onClose:t,page:n}){const{t:a}=ot("common"),s=typeof navigator<"u"&&navigator.platform.toUpperCase().includes("MAC"),l=Mie(n);return k.useEffect(()=>{if(!e)return;const c=d=>{d.key==="Escape"&&(d.preventDefault(),d.stopPropagation(),t())};return window.addEventListener("keydown",c,!0),()=>window.removeEventListener("keydown",c,!0)},[e,t]),e?i.jsx("div",{className:"fixed inset-0 z-[100] flex items-center justify-center bg-black/45 backdrop-blur-[1px] p-4",onMouseDown:c=>{c.target===c.currentTarget&&t()},role:"dialog","aria-modal":"true","aria-label":a("shortcuts.title"),children:i.jsxs("div",{className:"w-full max-w-lg max-h-[80vh] overflow-auto rounded-xl border border-border-default bg-surface-primary shadow-2xl",children:[i.jsxs("div",{className:"sticky top-0 z-10 flex items-center justify-between gap-3 px-4 py-3 border-b border-border-default bg-surface-primary",children:[i.jsx("h2",{className:"text-sm font-semibold text-fg-primary",children:a("shortcuts.title")}),i.jsx("button",{type:"button",onClick:t,className:"w-7 h-7 flex items-center justify-center rounded-md text-fg-tertiary hover:text-fg-secondary hover:bg-surface-elevated","aria-label":a("shortcuts.close"),children:i.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[i.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),i.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]}),i.jsx("div",{className:"px-4 py-3 space-y-4",children:jie.map(c=>{const d=_U.filter(m=>{if(m.group!==c)return!1;const p=m.page??"any";return p==="any"?!0:p===l});return d.length===0?null:i.jsxs("section",{children:[i.jsx("h3",{className:"text-[11px] font-semibold uppercase tracking-wide text-fg-tertiary mb-2",children:a(`shortcuts.groups.${c}`)}),i.jsx("ul",{className:"space-y-1.5",children:d.map(m=>i.jsxs("li",{className:"flex items-center justify-between gap-3 text-sm",children:[i.jsx("span",{className:"text-fg-secondary min-w-0",children:a(m.labelKey??m.label,{defaultValue:m.label})}),i.jsx("kbd",{className:"shrink-0 px-2 py-1 rounded bg-surface-elevated border border-border-default text-[13px] font-medium leading-none text-fg-primary font-mono",children:x4(m.keys,s,m.bare)})]},m.id))})]},c)})})]})}):null}function Rie({authUser:e,onClose:t,onSaved:n,onUserUpdated:a}){const{t:s}=ot("common");Qo(!0);const[l,c]=k.useState(e.name||""),[d,m]=k.useState(e.email||""),[p,h]=k.useState(!1),[g,x]=k.useState(""),[y,w]=k.useState(()=>m4(e.avatarUrl,xr()?.avatarUrl)),T=async C=>{if(C.preventDefault(),!l.trim()){x(s("profile.nameRequired"));return}if(d&&!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(d.trim())){x(s("profile.invalidEmail"));return}h(!0),x("");try{const{user:S}=await Ae.auth.updateProfile(l.trim(),d.trim());n({...S,avatarUrl:y??S.avatarUrl})}catch{x(s("profile.failedToSave"))}finally{h(!1)}};return i.jsx("div",{className:"fixed inset-0 bg-black/60 flex items-center justify-center z-[10000]",onClick:t,children:i.jsxs("form",{onSubmit:T,className:"bg-surface-secondary border border-border-default rounded-xl p-6 w-[400px] max-w-[calc(100vw-2rem)] shadow-2xl",onClick:C=>C.stopPropagation(),children:[i.jsx("h3",{className:"text-base font-semibold mb-5",children:s("profile.editProfile")}),i.jsx("div",{className:"flex justify-center mb-5",children:i.jsx(f4,{currentUrl:y,name:l,size:72,targetType:"user",targetId:e.id,onUploaded:C=>{w(C),a?.({...e,avatarUrl:C})}})}),i.jsxs("div",{className:"space-y-3",children:[i.jsxs("div",{children:[i.jsx("label",{className:"block text-xs text-fg-tertiary font-medium mb-1",children:s("profile.name")}),i.jsx("input",{value:l,onChange:C=>c(C.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"})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-xs text-fg-tertiary font-medium mb-1",children:s("profile.email")}),i.jsx("input",{value:d,onChange:C=>m(C.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"})]}),g&&i.jsx("div",{className:"text-xs text-red-500 bg-red-500/10 border border-red-500/30 rounded-lg px-3 py-2",children:g})]}),i.jsxs("div",{className:"flex justify-end gap-3 mt-5",children:[i.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")}),i.jsx("button",{type:"submit",disabled:p,className:"px-4 py-2 text-sm bg-brand-600 hover:bg-brand-500 disabled:opacity-50 text-white rounded-lg",children:s(p?"saving":"save")})]})]})})}const Lk=k.lazy(()=>va(()=>import("./Team-mz_JWJwM.js"),__vite__mapDeps([2,3,4,5,6,7])).then(e=>({default:e.TeamPage}))),Ik=k.lazy(()=>va(()=>import("./Settings-_kkGsvr2.js"),__vite__mapDeps([8,6])).then(e=>({default:e.Settings}))),Die=k.lazy(()=>va(()=>import("./Store-BOV3Thkl.js"),[]).then(e=>({default:e.StorePage}))),Lie=k.lazy(()=>va(()=>Promise.resolve().then(()=>Wre),void 0).then(e=>({default:e.AgentBuilder}))),Ok=k.lazy(()=>va(()=>import("./Work-DaY25Zvg.js"),__vite__mapDeps([9,4,1,10,3,11])).then(e=>({default:e.WorkPage}))),Pk=k.lazy(()=>va(()=>import("./Deliverables-B6Fo0RuB.js"),__vite__mapDeps([12,4,5])).then(e=>({default:e.DeliverablesPage}))),Iie=k.lazy(()=>va(()=>import("./Notifications-DsP8Z0a3.js"),[]).then(e=>({default:e.NotificationsPage}))),Oie=k.lazy(()=>va(()=>import("./Search-CLSRxUnd.js"),[]).then(e=>({default:e.SearchPage}))),Pie={visibility:"hidden",position:"absolute",inset:0,pointerEvents:"none",zIndex:-1};function zie(e){try{const t=navigator.language,n=Intl.DateTimeFormat().resolvedOptions().timeZone,a=e.preferences??{};if(a.locale===t&&a.timezone===n)return;Ae.auth.updatePreferences({locale:t,timezone:n}).catch(()=>{})}catch{}}function Bie(){return i.jsx("div",{className:"flex-1 flex items-center justify-center text-fg-tertiary text-sm animate-pulse",children:"Loading..."})}const Hie=k.memo(function({id:t,activePage:n,children:a}){const s=t===n;return i.jsx("div",{className:"flex-1 overflow-hidden flex flex-col",style:s?void 0:Pie,children:i.jsx(k.Suspense,{fallback:i.jsx(Bie,{}),children:a})})},(e,t)=>{const n=e.id===e.activePage,a=t.id===t.activePage;return n!==a?!1:a?e.children===t.children:!0}),Ud={};function u6(e){return typeof window<"u"&&window.matchMedia("(max-width: 767px)").matches?a4[e]??e:e}function zk(){return u6(Sc())}function $ie(){const{t:e}=ot("common"),[t,n]=k.useState(zk),[a,s]=k.useState(!1),[l,c]=k.useState(!0),d=Xo(),m=Sie(),p=wie({side:"left",defaultWidth:160,minWidth:140,maxWidth:400,collapsedWidth:64,storageKey:"markus_sidebar"}),[h,g]=k.useState(()=>new Set([zk()])),[x,y]=k.useState("loading"),[w,T]=k.useState(!1),[C,S]=k.useState(null),[E,_]=k.useState({hasOwner:!1,hasMultipleUsers:!1}),[L,D]=k.useState(!1),[M,O]=k.useState(!1),[G,Q]=k.useState(null),[$,Y]=k.useState(!1),[K,ee]=k.useState(null),[U,te]=k.useState(()=>{const X=localStorage.getItem("markus_update_dismissed");return X||null}),[I,J]=k.useState(!1),[me,Ce]=k.useState(!1),H=qc(),V=H?.leftCollapsed??!1,fe=H?.toggleLeftCollapsed,z=H?.setLeftCollapsed,je=H?.keyboardPane??"l0",Ue=H?.setKeyboardPane,qe=H?.l0FocusPageId??null,He=H?.setL0FocusPageId,ut=k.useRef(t);ut.current=t;const dt=k.useRef(de.HOME),Nt=H?.toggleRightPanel,wt=H?.toggleTerminalPanel,Zt=H?.cycleRightPanelTab,Wt=H?.activateRightPanelTabAt,rt=H?.openNewRightPanelTab,$e=H?.rightPanelOpen??!1,mt=H?.activeRightPanelTabId??null,At=H?.openRightPanel,Dt=H?.closeRightPanelTab,ln=H?.updateRightPanelBrowserTab,ce=H?.updateRightPanelTerminalTab,et=k.useRef(H?.rightPanelTabs);et.current=H?.rightPanelTabs,k.useEffect(()=>{const X=window.markusDesktop?.browser?.onPageEvent;if(!(!X||!At))return X(Z=>{if(Z.type==="closed"){const ue=et.current?.find(Be=>Be.payload.kind==="url"&&Be.payload.browserId===Z.browserId);ue&&Dt&&Dt(ue.id);return}if(Z.type==="navigated"){if(Z.url&&Ac(Z.url))return;Z.browserId&&ln&&ln(Z.browserId,{url:Z.url,title:Z.title||Z.url});return}if(Z.type==="opened"||Z.type==="selected"){if(!Z.url&&!Z.browserId||Z.browserId.startsWith("eb_")||Ete(Z.browserId)||Z.url&&Ac(Z.url))return;At({kind:"url",url:Z.url||"about:blank",title:Z.title||Z.url||"Browser",browserId:Z.browserId,pageId:Z.pageId})}})},[At,Dt,ln]),k.useEffect(()=>{const X=window.markusDesktop?.terminal?.onEvent;if(!(!X||!At))return X(Z=>{if(Z.type==="closed"){const ue=et.current?.find(Be=>Be.payload.kind==="terminal"&&Be.payload.terminalId===Z.id);ue&&Dt&&Dt(ue.id);return}if(Z.type==="cwd"){Z.cwd&&ce?.(Z.id,{cwd:Z.cwd});return}if(Z.type==="selected"){(Z.title||Z.cwd)&&ce?.(Z.id,{title:Z.title,cwd:Z.cwd});return}if(Z.type==="opened"){if(mb.has(Z.id)){(Z.title||Z.cwd)&&ce?.(Z.id,{title:Z.title,cwd:Z.cwd});return}_s(Z.id),At({kind:"terminal",terminalId:Z.id,title:Z.title||"Terminal",cwd:Z.cwd})}})},[At,Dt,ce]);const nt=H?.handleTerminalExit;k.useEffect(()=>{const X=window.markusDesktop?.terminal?.onExit;if(!(!X||!nt))return X(Z=>{nt(Z.id)})},[nt]),k.useLayoutEffect(()=>{const X=t===de.TEAM&&$e&&H?.rightPanelMode==="browser";wf(X)},[t,$e,H?.rightPanelMode]),k.useEffect(()=>{window.markusDesktop?.browser?.hideAll?.()},[]);const we=k.useRef(!1);k.useEffect(()=>{if(!we.current){we.current=!0;return}p.setCollapsed(V)},[V,p.setCollapsed]),k.useEffect(()=>{if(d)return;const X=navigator.platform.toUpperCase().includes("MAC"),Z=Be=>{X&&Be.metaKey&&!Be.ctrlKey&&Be.key==="p"?(Be.preventDefault(),J(Ie=>!Ie)):!X&&Be.ctrlKey&&!Be.metaKey&&Be.key==="p"&&(Be.preventDefault(),J(Ie=>!Ie))},ue=()=>J(!0);return document.addEventListener("keydown",Z),window.addEventListener("markus:open-search",ue),()=>{document.removeEventListener("keydown",Z),window.removeEventListener("markus:open-search",ue)}},[d]);const Me=k.useCallback(()=>!$e||!mt||!Dt?!1:(Dt(mt),!0),[$e,mt,Dt]);k.useEffect(()=>{const X=window.markusDesktop?.onAppShortcut?.(Z=>{if(Z.type==="close-tab"){Me();return}Z.type==="new-tab"&&rt?.()});return()=>{X?.()}},[Me,rt]),k.useEffect(()=>{if(d||!fe||!Nt)return;const X=navigator.platform.toUpperCase().includes("MAC"),Z=ue=>{if(!(X?ue.metaKey&&!ue.ctrlKey:ue.ctrlKey&&!ue.metaKey)||ue.altKey)return;if(!ue.shiftKey&&(ue.key==="/"||ue.code==="Slash")){ue.preventDefault(),Ce(Ge=>!Ge);return}if(ue.shiftKey&&(ue.key==="?"||ue.key==="/")){ue.preventDefault(),Ce(Ge=>!Ge);return}if(ue.shiftKey&&$e&&Zt){if(ue.key==="]"||ue.code==="BracketRight"){ue.preventDefault(),Zt(1);return}if(ue.key==="["||ue.code==="BracketLeft"){ue.preventDefault(),Zt(-1);return}}if(!ue.shiftKey&&$e&&Wt){const Ge=ue.key>="1"&&ue.key<="9"?Number(ue.key):0;if(Ge>=1){ue.preventDefault(),Wt(Ge-1);return}}if(ue.shiftKey)return;const Ie=ue.key.toLowerCase();if(Ie==="w"){ue.preventDefault(),ue.stopPropagation(),Me();return}if(Ie==="t"){ue.preventDefault(),rt?.();return}if(Ie==="b"){if(t===de.DELIVERABLES)return;ue.preventDefault(),fe()}else if(t===de.TEAM&&Ie==="l"){if(!X&&Pv(ue.target)||X&&Pv(ue.target)&&ue.ctrlKey)return;ue.preventDefault(),Nt()}else t===de.TEAM&&Ie==="j"&&wt&&(ue.preventDefault(),wt())};return document.addEventListener("keydown",Z,!0),()=>document.removeEventListener("keydown",Z,!0)},[d,t,fe,Nt,wt,Zt,Wt,$e,Me,rt]);const Ne=k.useCallback((X,Z)=>{let ue=kc(X);d?ue=a4[ue]??ue:ue===de.NOTIFICATIONS&&(ue=de.HOME),ue!==de.TEAM&&wf(!1);const Be=Sc(),Ie=window.location.hash.slice(1);Ie!==Nh(Be)?Ud[Be]=Ie:delete Ud[Be];const Ge=ut.current;if(ue===de.SETTINGS&&Ge!==de.SETTINGS&&(dt.current=Ge,at.setSettingsReturnPage(Ge),Ue?.("l1"),He?.(de.SETTINGS)),Ge===de.SETTINGS&&ue!==de.SETTINGS&&(Ue?.("l0"),He?.(ue)),ue===de.SETTINGS&&Z?.tab){const Rt=`settings/${Z.tab}`;Ud[ue]=Rt,history.pushState(null,"","#"+Rt),window.dispatchEvent(new HashChangeEvent("hashchange")),n(ue),g(Mt=>Mt.has(ue)?Mt:new Set([...Mt,ue]));return}const kt=ue!==de.WORK?Ud[ue]:void 0;kt&&kt!==Nh(ue)?(history.pushState(null,"",Ps(ue)),history.pushState(null,"","#"+kt)):history.pushState(null,"",Ps(ue)),window.dispatchEvent(new HashChangeEvent("hashchange")),n(ue),g(Rt=>Rt.has(ue)?Rt:new Set([...Rt,ue]))},[d,Ue,He]);k.useEffect(()=>{at.setHandler((X,Z)=>Ne(X,Z))},[Ne]),k.useEffect(()=>{je==="l0"&&t!==de.SETTINGS&&He?.(t)},[je,t,He]),k.useEffect(()=>{if(d||!Ue||!He)return;const X=Z=>{if(Z.metaKey||Z.ctrlKey||Z.altKey||Ov(Z.target))return;const ue=Z.key.length===1?Z.key.toLowerCase():Z.key;if(t===de.SETTINGS&&(ue==="h"||ue==="ArrowLeft")){Z.preventDefault(),Z.stopImmediatePropagation(),at.leaveSettings();return}if(je!=="l0"||t===de.SETTINGS)return;const Be=qe&&Eo.includes(qe)?qe:t,Ie=Math.max(0,Eo.indexOf(Be));if(ue==="j"||ue==="ArrowDown"){Z.preventDefault(),Z.stopImmediatePropagation();const Ge=Eo[Math.min(Eo.length-1,Ie+1)];He(Ge),Ge!==t&&Ne(Ge),requestAnimationFrame(()=>{document.querySelector(`[data-l0-page-id="${Ge}"]`)?.scrollIntoView({block:"nearest"})});return}if(ue==="k"||ue==="ArrowUp"){Z.preventDefault(),Z.stopImmediatePropagation();const Ge=Eo[Math.max(0,Ie-1)];He(Ge),Ge!==t&&Ne(Ge),requestAnimationFrame(()=>{document.querySelector(`[data-l0-page-id="${Ge}"]`)?.scrollIntoView({block:"nearest"})});return}if(ue==="l"||ue==="ArrowRight"||ue==="Enter"){const Ge=qe&&Eo.includes(qe)?qe:t;if(!rU.has(Ge)){Z.preventDefault(),Z.stopImmediatePropagation();return}Z.preventDefault(),Z.stopImmediatePropagation(),Ge!==t&&Ne(Ge),z?.(!1),Ue("l1");return}(ue==="h"||ue==="ArrowLeft")&&(Z.preventDefault(),Z.stopImmediatePropagation())};return document.addEventListener("keydown",X,!0),()=>document.removeEventListener("keydown",X,!0)},[d,je,qe,t,Ne,Ue,He,z]),k.useEffect(()=>{const X=()=>T(!0);return window.addEventListener("markus:open-edit-profile",X),()=>window.removeEventListener("markus:open-edit-profile",X)},[]),k.useEffect(()=>{if(!window.markusDesktop)return;!d&&t!==de.SETTINGS&&!p.collapsed?window.markusDesktop.setTrafficLightPosition(16,16):window.markusDesktop.setTrafficLightPosition(6,16)},[p.collapsed,t,d]),k.useEffect(()=>{window.markusDesktop&&window.markusDesktop.onNotificationClick(X=>{if(X.openNotifications&&window.dispatchEvent(new CustomEvent("markus:open-notifications")),X.page){const Z=kc(X.page);X.params&&Object.entries(X.params).forEach(([ue,Be])=>localStorage.setItem(`markus_nav_${ue}`,Be)),Ne(Z),window.dispatchEvent(new CustomEvent("markus:navigate",{detail:{page:Z,params:X.params}}))}})},[Ne]);const se=k.useCallback(()=>{fetch("/api/settings/llm").then(X=>X.ok?X.json():null).then(X=>{if(X?.providers){const Z=Object.values(X.providers).some(ue=>ue.configured);Q(Z)}}).catch(()=>{})},[]),q=k.useCallback((X,Z)=>{if(!X)return;const Be=Z&&{agent:"agents",team:"teams",skill:"skills"}[Z]||"agents";localStorage.setItem("markus_nav_installItem",X),localStorage.setItem("markus_nav_storeTab",Be);const Ie=new URLSearchParams(window.location.search);Ie.get("install")||(Ie.set("install",X),Z&&Ie.set("type",Z));const Ge=Ie.toString();window.history.replaceState(null,"",`${window.location.pathname}?${Ge}${Ps(de.STORE)}`);const kt=()=>at.navigate(de.STORE,{storeTab:Be,installItem:X});kt(),setTimeout(kt,500),setTimeout(kt,1500)},[]);k.useEffect(()=>{const X=new URLSearchParams(window.location.search),Z=X.get("install");Z&&q(Z,X.get("type"));const ue=window.markusDesktop;ue?.onDeepLinkInstall?.(({id:Ge,type:kt})=>q(Ge,kt)),ue?.consumePendingDeepLinkInstall?.().then(Ge=>{Ge?.id&&q(Ge.id,Ge.type)}),Ae.auth.me().then(({user:Ge})=>{y(Ge),S(!0),s(!1),Ge.preferences?.guideHidden===!0&&!_h(Ge.id)&&Rh(Ge.id),zie(Ge),Ir.connect(Ge.id),se(),Ae.health().then(Rt=>{Rt.updateAvailable&&Rt.latestVersion&&ee({latestVersion:Rt.latestVersion,currentVersion:Rt.version})}).catch(()=>{});const kt=()=>{Ns(qa.builderArtifacts,()=>Ae.builder.artifacts.list()),Ns(qa.builderAgents,()=>Ae.agents.list()),Ns(qa.builderHubMyItems,()=>st.myItems()),Ns(qa.builderInstalled,()=>Ae.builder.artifacts.installed()),Ns(qa.hubAgents,()=>st.search({type:"agent",limit:50})),Ns(qa.hubTeams,()=>st.search({type:"team",limit:50})),Ns(qa.hubSkills,()=>st.search({type:"skill",limit:50}))};typeof requestIdleCallback=="function"?requestIdleCallback(kt,{timeout:5e3}):setTimeout(kt,3e3)}).catch(()=>{y(null),Ae.auth.status().then(({initialized:Ge,hasOwner:kt,hasMultipleUsers:Rt})=>{S(Ge),_({hasOwner:kt,hasMultipleUsers:Rt})}).catch(()=>S(!0))}),Ir.connect();const Be=Ir.on("notification",()=>{window.dispatchEvent(new CustomEvent("markus:notifications-changed"))}),Ie=()=>{const Ge=u6(Sc());Ge!==de.TEAM&&wf(!1),n(Ge),g(kt=>kt.has(Ge)?kt:new Set([...kt,Ge]))};return window.addEventListener("hashchange",Ie),window.addEventListener("popstate",Ie),()=>{Be(),Ir.disconnect(),window.removeEventListener("hashchange",Ie),window.removeEventListener("popstate",Ie)}},[]),k.useEffect(()=>{const X=x!=="loading"&&x!==null?x.id:void 0;if(!X)return;const Z=navigator.platform.toUpperCase().includes("MAC"),ue=Be=>{if(Ov(Be.target))return;const Ie={key:Be.key,code:Be.code,metaKey:Be.metaKey,ctrlKey:Be.ctrlKey,altKey:Be.altKey,shiftKey:Be.shiftKey};jU(Ie,X,Z)&&window.dispatchEvent(new CustomEvent("markus:shortcut-lesson-complete"))};return window.addEventListener("keydown",ue,!0),()=>window.removeEventListener("keydown",ue,!0)},[x]);const ae=x!=="loading"&&x!==null?x:void 0,Se=k.useMemo(()=>d?{[de.HOME]:i.jsx($v,{authUser:ae}),[de.TEAM]:i.jsx(Lk,{authUser:ae}),[de.BUILDER]:i.jsx(hie,{authUser:ae}),[de.SETTINGS]:i.jsx(Ik,{theme:m.mode,onThemeChange:m.setMode,authUser:ae,onLogout:()=>{Ae.auth.logout().catch(()=>{}),Ds(),y(null)},onUserUpdated:X=>y(X)}),[de.WORK]:i.jsx(Ok,{authUser:ae}),[de.DELIVERABLES]:i.jsx(Pk,{authUser:ae}),[de.NOTIFICATIONS]:i.jsx(Iie,{authUser:ae}),[de.SEARCH]:i.jsx(Oie,{})}:{[de.HOME]:i.jsx($v,{authUser:ae}),[de.TEAM]:i.jsx(Lk,{authUser:ae}),[de.SETTINGS]:i.jsx(Ik,{theme:m.mode,onThemeChange:m.setMode,authUser:ae,onLogout:()=>{Ae.auth.logout().catch(()=>{}),Ds(),y(null)},onUserUpdated:X=>y(X)}),[de.STORE]:i.jsx(Die,{authUser:ae}),[de.BUILDER]:i.jsx(Lie,{authUser:ae}),[de.WORK]:i.jsx(Ok,{authUser:ae}),[de.DELIVERABLES]:i.jsx(Pk,{authUser:ae})},[ae?.id,ae?.role,m.mode,d]);if(x==="loading"||x===null&&C===null)return i.jsx("div",{className:"min-h-dvh bg-surface-primary flex items-center justify-center",children:i.jsx("div",{className:"text-fg-tertiary text-sm animate-pulse",children:e("loading")})});const Pe=(typeof window<"u"?window.location.hash:"").match(/^#invite\?token=([a-f0-9]+)/);return Pe?i.jsx(xie,{token:Pe[1],onComplete:()=>{window.location.hash="",localStorage.removeItem("markus_onboarded"),s(!0),D(!0),y("loading"),Ae.auth.me().then(X=>{zv(X.user.id),y(X.user)}).catch(()=>y(null))}}):x===null?i.jsx(yie,{hasOwner:E.hasOwner,hasMultipleUsers:E.hasMultipleUsers,onLogin:(X,Z,ue)=>{y(X),Ir.connect(X.id),Z?(zv(X.id),s(!0),ue?.fromHub&&D(!0)):(s(!1),_h(X.id)?(Rh(X.id),Ae.auth.updatePreferences({guideHidden:!0}).catch(()=>{}),y({...X,preferences:{...X.preferences,guideHidden:!0}})):y(X))}}):M?i.jsx(vie,{onComplete:()=>O(!1),isFirstTime:!0}):a?i.jsx(gie,{theme:m.mode,onThemeChange:m.setMode,skipProfile:L,onProfileUpdated:X=>{const Z={id:X.id,name:X.name,email:X.email,role:X.role,orgId:X.orgId??"default",avatarUrl:X.avatarUrl};y(Z)},onComplete:()=>{localStorage.removeItem("markus_onboarded"),s(!1),D(!1),Ae.auth.me().then(X=>y(X.user)).catch(()=>{}),se(),Ne(de.HOME)}}):i.jsxs("div",{className:`flex h-dvh bg-surface-primary text-fg-primary overflow-x-hidden ${d?"flex-col":""}`,children:[!d&&t!==de.SETTINGS&&i.jsxs(i.Fragment,{children:[i.jsx("div",{className:"relative z-40 shrink-0",style:{width:p.width},children:i.jsx(bre,{currentPage:t,onNavigate:X=>{Ne(X),c(!1),Ue?.("l0"),He?.(X)},authUser:x,collapsed:p.collapsed,onToggleCollapse:p.toggle,onLogout:()=>{Ae.auth.logout().catch(()=>{}),Ds(),y(null)},keyboardFocusPageId:qe,keyboardPaneActive:je==="l0"})}),i.jsx("div",{className:`${p.collapsed?"w-0":"w-1.5 cursor-col-resize"} shrink-0 group relative z-10 flex items-center justify-center`,onMouseDown:p.collapsed?void 0:p.onResizeStart,children:!p.collapsed&&i.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"})})]}),i.jsxs("div",{className:`flex-1 overflow-hidden flex flex-col min-w-0 ${d&&t!==de.SETTINGS&&t!==de.SEARCH?"pb-14":""}`,children:[G===!1&&!$&&t!==de.SETTINGS&&i.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:[i.jsx("span",{className:d?"text-xs":"",children:e("llmBanner.message")}),i.jsxs("div",{className:"flex items-center gap-3",children:[i.jsx("button",{onClick:()=>{window.location.hash="#settings/providers"},className:"px-3 py-1 bg-amber-700/50 hover:bg-amber-700/70 text-white text-xs rounded-lg transition-colors",children:e("llmBanner.goToSettings")}),i.jsx("button",{onClick:()=>Y(!0),className:"text-amber-500 hover:text-amber-600 text-xs",children:e("dismiss")})]})]}),K&&U!==K.latestVersion&&i.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:[i.jsx("span",{className:d?"text-xs":"",children:e("update.available",{latest:K.latestVersion,current:K.currentVersion})}),i.jsxs("span",{className:"flex items-center gap-3 shrink-0",children:[i.jsx("a",{href:"https://markus.global/#download",target:"_blank",rel:"noopener noreferrer",className:"text-xs font-medium text-brand-400 hover:text-brand-300 transition-colors",children:e("update.download")}),i.jsx("button",{onClick:()=>{te(K.latestVersion),localStorage.setItem("markus_update_dismissed",K.latestVersion)},className:"text-fg-tertiary hover:text-fg-secondary text-xs shrink-0",children:e("dismiss")})]})]}),i.jsx("main",{className:"flex-1 overflow-hidden flex flex-col relative",children:Object.keys(Se).map(X=>h.has(X)?i.jsx(Hie,{id:X,activePage:t,children:Se[X]},X):null)})]}),d&&t!==de.SETTINGS&&t!==de.SEARCH&&i.jsx(Tre,{currentPage:t,onNavigate:Ne,userId:ae?.id}),d&&i.jsx(TU,{authUser:ae,onNavigate:Ne,onLogout:()=>{Ae.auth.logout().catch(()=>{}),Ds(),y(null)}}),!d&&I&&i.jsx(Tie,{onClose:()=>J(!1),currentPage:t}),!d&&i.jsx(_ie,{open:me,onClose:()=>Ce(!1),page:t}),w&&ae&&i.jsx(Rie,{authUser:ae,onClose:()=>T(!1),onUserUpdated:X=>y(X),onSaved:X=>{T(!1),y(X)}})]})}const Bk="data-anim-paused",Hk="data-anim-tick",$k=8,qie=250;function Fie(){return document.visibilityState!=="visible"||document.hidden?!0:!document.hasFocus()}let xc=null,Po=0;function Uie(){xc===null&&(Po=Po%$k,document.documentElement.setAttribute(Hk,String(Po)),xc=window.setInterval(()=>{Po=(Po+1)%$k,document.documentElement.setAttribute(Hk,String(Po))},qie))}function Gie(){xc!==null&&(window.clearInterval(xc),xc=null)}function oc(){const e=document.documentElement;Fie()?(e.setAttribute(Bk,"true"),Gie()):(e.removeAttribute(Bk),Uie())}let qk=!1;function Kie(){qk||typeof document>"u"||(qk=!0,oc(),document.addEventListener("visibilitychange",oc,{passive:!0}),window.addEventListener("focus",oc,{passive:!0}),window.addEventListener("blur",oc,{passive:!0}),window.addEventListener("pageshow",oc,{passive:!0}))}Kie();wA.createRoot(document.getElementById("root")).render(i.jsx(k.StrictMode,{children:i.jsx(Lte,{children:i.jsx($ie,{})})}));export{Hse as $,Zi as A,Qo as B,li as C,yne as D,Ps as E,ba as F,lU as G,Zie as H,cie as I,gb as J,rse as K,bg as L,g4 as M,fre as N,vne as O,de as P,yg as Q,Wie as R,oie as S,Xre as T,Eae as U,Nae as V,ese as W,sse as X,ise as Y,Go as Z,va as _,Xo as a,Ase as a$,Yie as a0,xr as a1,pT as a2,gse as a3,sU as a4,Qie as a5,Xie as a6,_s as a7,Md as a8,fi as a9,Bse as aA,Tse as aB,Mse as aC,ase as aD,pse as aE,bb as aF,x4 as aG,f4 as aH,wse as aI,kse as aJ,Sse as aK,Rse as aL,Jw as aM,rne as aN,zse as aO,_se as aP,Ose as aQ,Dse as aR,dk as aS,mk as aT,mre as aU,Pse as aV,Nse as aW,jse as aX,IS as aY,Pv as aZ,Cse as a_,mm as aa,Ise as ab,one as ac,Lw as ad,Oae as ae,zs as af,rl as ag,xse as ah,bse as ai,mse as aj,yse as ak,hse as al,fse as am,lse as an,Kae as ao,use as ap,vse as aq,Xae as ar,Lse as as,VS as at,dse as au,$ae as av,ose as aw,Jie as ax,cse as ay,Sre as az,vU as b,Ese as b0,nse as b1,PS as b2,qc as c,mie as d,eie as e,rie as f,Is as g,st as h,Ov as i,i as j,zr as k,Ae as l,wie as m,at as n,jn as o,kc as p,Ea as q,k as r,hb as s,Ha as t,ot as u,Vie as v,Ir as w,Ic as x,zm as y,hT as z};