crewx 0.8.2-rc.6 → 0.8.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/{MarketPage-Dm-3QavD.js → MarketPage-CyYkZIcw.js} +1 -1
- package/dist/assets/{PromptTab-sX4AsLbK.js → PromptTab-CBlt-krG.js} +1 -1
- package/dist/assets/{_baseUniq-x431tTgR.js → _baseUniq-DkYSH7iR.js} +1 -1
- package/dist/assets/{arc-Bdw_HjPg.js → arc-DGZk1vOk.js} +1 -1
- package/dist/assets/{architectureDiagram-Q4EWVU46-CKOyiOm8.js → architectureDiagram-Q4EWVU46-CifAWdeJ.js} +1 -1
- package/dist/assets/{blockDiagram-DXYQGD6D-CBEUu9y9.js → blockDiagram-DXYQGD6D-Cf47SU_V.js} +1 -1
- package/dist/assets/{c4Diagram-AHTNJAMY-BL4Rtyhe.js → c4Diagram-AHTNJAMY-DnNIhb62.js} +1 -1
- package/dist/assets/channel-cvw8MhuL.js +1 -0
- package/dist/assets/{chunk-4BX2VUAB-BiIGin3q.js → chunk-4BX2VUAB-PoQywvRB.js} +1 -1
- package/dist/assets/{chunk-4TB4RGXK-GpuMIrpW.js → chunk-4TB4RGXK-sXJUDs7c.js} +1 -1
- package/dist/assets/{chunk-55IACEB6-D3f63-DT.js → chunk-55IACEB6-BcnA0vyQ.js} +1 -1
- package/dist/assets/{chunk-EDXVE4YY-fdIQ56GC.js → chunk-EDXVE4YY-D5vM3Sk1.js} +1 -1
- package/dist/assets/{chunk-FMBD7UC4-Bq8zfDUH.js → chunk-FMBD7UC4-CvNWDiTK.js} +1 -1
- package/dist/assets/{chunk-OYMX7WX6-B-ICq3-a.js → chunk-OYMX7WX6-C9X-9n06.js} +1 -1
- package/dist/assets/{chunk-QZHKN3VN-DbfEU1M-.js → chunk-QZHKN3VN-6SCVKu7R.js} +1 -1
- package/dist/assets/{chunk-YZCP3GAM-RcrMb8NF.js → chunk-YZCP3GAM-PnW259Hh.js} +1 -1
- package/dist/assets/classDiagram-6PBFFD2Q-BDSg69Gf.js +1 -0
- package/dist/assets/classDiagram-v2-HSJHXN6E-BDSg69Gf.js +1 -0
- package/dist/assets/clone-vO15YbuB.js +1 -0
- package/dist/assets/{cose-bilkent-S5V4N54A-Dz2Nu8IR.js → cose-bilkent-S5V4N54A-Dp34VlDR.js} +1 -1
- package/dist/assets/{dagre-KV5264BT-B2IJS2kr.js → dagre-KV5264BT-fy9Jy7D-.js} +1 -1
- package/dist/assets/{diagram-5BDNPKRD-8z7YbL3v.js → diagram-5BDNPKRD-CifPGnA5.js} +1 -1
- package/dist/assets/{diagram-G4DWMVQ6-DUZmwTh5.js → diagram-G4DWMVQ6-CO324vbS.js} +1 -1
- package/dist/assets/{diagram-MMDJMWI5-CnB1sGp0.js → diagram-MMDJMWI5-DQKHCVNg.js} +1 -1
- package/dist/assets/{diagram-TYMM5635-BbOA-kUr.js → diagram-TYMM5635-XBBjlYIc.js} +1 -1
- package/dist/assets/{erDiagram-SMLLAGMA-DOKYAfb3.js → erDiagram-SMLLAGMA-U_b9j-iW.js} +1 -1
- package/dist/assets/{flowDiagram-DWJPFMVM-DHyg5Orb.js → flowDiagram-DWJPFMVM-DaMvV0c8.js} +1 -1
- package/dist/assets/{ganttDiagram-T4ZO3ILL--jR28tKt.js → ganttDiagram-T4ZO3ILL-DxcjNxAW.js} +1 -1
- package/dist/assets/{gitGraphDiagram-UUTBAWPF-Bv2jMUpq.js → gitGraphDiagram-UUTBAWPF-B5Go_w_e.js} +1 -1
- package/dist/assets/{graph-HnXnCSDL.js → graph-CQGeuC8m.js} +1 -1
- package/dist/assets/{infoDiagram-42DDH7IO-DrEh4i5q.js → infoDiagram-42DDH7IO-B9uc-Zdc.js} +1 -1
- package/dist/assets/{ishikawaDiagram-UXIWVN3A-BTS9mMjE.js → ishikawaDiagram-UXIWVN3A-DPI8hbB4.js} +1 -1
- package/dist/assets/{journeyDiagram-VCZTEJTY-CKgvMQgR.js → journeyDiagram-VCZTEJTY-JZjg2VSV.js} +1 -1
- package/dist/assets/{kanban-definition-6JOO6SKY-BYvGqAia.js → kanban-definition-6JOO6SKY-C8GcL5aF.js} +1 -1
- package/dist/assets/{layout-BzNPaPW3.js → layout-CHr5cB81.js} +1 -1
- package/dist/assets/{linear-BUnFM2ae.js → linear-T3wDZ56h.js} +1 -1
- package/dist/assets/{main-BUNk9K7r.js → main-BMOLBRpY.js} +5 -5
- package/dist/assets/{min-8mnPXDtt.js → min-_F_K3roO.js} +1 -1
- package/dist/assets/{mindmap-definition-QFDTVHPH-B0rH-dAY.js → mindmap-definition-QFDTVHPH-BUSgUnqS.js} +1 -1
- package/dist/assets/{pieDiagram-DEJITSTG-bjiSm1h0.js → pieDiagram-DEJITSTG-BTBjF7Bv.js} +1 -1
- package/dist/assets/{quadrantDiagram-34T5L4WZ-B6SKXcvr.js → quadrantDiagram-34T5L4WZ-Z3Buxsxe.js} +1 -1
- package/dist/assets/{requirementDiagram-MS252O5E-l_nMizfW.js → requirementDiagram-MS252O5E-CnfFthlg.js} +1 -1
- package/dist/assets/{sankeyDiagram-XADWPNL6-CesXBREd.js → sankeyDiagram-XADWPNL6-BIeDgqXh.js} +1 -1
- package/dist/assets/{sequenceDiagram-FGHM5R23-DkYd7G1G.js → sequenceDiagram-FGHM5R23-BICX7EKt.js} +1 -1
- package/dist/assets/{stateDiagram-FHFEXIEX-DXHYUjiy.js → stateDiagram-FHFEXIEX-cW0_yGa2.js} +1 -1
- package/dist/assets/stateDiagram-v2-QKLJ7IA2-BXRvCfMx.js +1 -0
- package/dist/assets/{timeline-definition-GMOUNBTQ-CCHtb46U.js → timeline-definition-GMOUNBTQ-BFHBbQkD.js} +1 -1
- package/dist/assets/{vennDiagram-DHZGUBPP-B8uHLM-H.js → vennDiagram-DHZGUBPP-Ck_7LdKT.js} +1 -1
- package/dist/assets/wardley-RL74JXVD-B_IIjPGw.js +162 -0
- package/dist/assets/{wardleyDiagram-NUSXRM2D-CEFJviBh.js → wardleyDiagram-NUSXRM2D-BRdXdErY.js} +1 -1
- package/dist/assets/{xychartDiagram-5P7HB3ND-Dfqj8elB.js → xychartDiagram-5P7HB3ND-za19jTKs.js} +1 -1
- package/dist/index.html +1 -1
- package/package.json +8 -8
- package/packages/cli/package.json +1 -1
- package/dist/assets/channel-BFWwPNdX.js +0 -1
- package/dist/assets/classDiagram-6PBFFD2Q-CNkE6SD4.js +0 -1
- package/dist/assets/classDiagram-v2-HSJHXN6E-CNkE6SD4.js +0 -1
- package/dist/assets/clone-DCwYYXrf.js +0 -1
- package/dist/assets/stateDiagram-v2-QKLJ7IA2-CkNAZmh8.js +0 -1
- package/dist/assets/wardley-RL74JXVD-A9hKdyZ9.js +0 -162
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./dagre-KV5264BT-
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./dagre-KV5264BT-fy9Jy7D-.js","./graph-CQGeuC8m.js","./_baseUniq-DkYSH7iR.js","./layout-CHr5cB81.js","./min-_F_K3roO.js","./clone-vO15YbuB.js","./cose-bilkent-S5V4N54A-Dp34VlDR.js","./cytoscape.esm-BiciSPf8.js","./c4Diagram-AHTNJAMY-DnNIhb62.js","./chunk-YZCP3GAM-PnW259Hh.js","./flowDiagram-DWJPFMVM-DaMvV0c8.js","./chunk-FMBD7UC4-CvNWDiTK.js","./chunk-55IACEB6-BcnA0vyQ.js","./chunk-EDXVE4YY-D5vM3Sk1.js","./channel-cvw8MhuL.js","./erDiagram-SMLLAGMA-U_b9j-iW.js","./gitGraphDiagram-UUTBAWPF-B5Go_w_e.js","./chunk-4BX2VUAB-PoQywvRB.js","./chunk-QZHKN3VN-6SCVKu7R.js","./wardley-RL74JXVD-B_IIjPGw.js","./ganttDiagram-T4ZO3ILL-DxcjNxAW.js","./linear-T3wDZ56h.js","./init-Gi6I4Gst.js","./defaultLocale-DX6XiGOO.js","./infoDiagram-42DDH7IO-B9uc-Zdc.js","./pieDiagram-DEJITSTG-BTBjF7Bv.js","./arc-DGZk1vOk.js","./ordinal-Cboi1Yqb.js","./quadrantDiagram-34T5L4WZ-Z3Buxsxe.js","./xychartDiagram-5P7HB3ND-za19jTKs.js","./requirementDiagram-MS252O5E-CnfFthlg.js","./sequenceDiagram-FGHM5R23-BICX7EKt.js","./classDiagram-6PBFFD2Q-BDSg69Gf.js","./chunk-4TB4RGXK-sXJUDs7c.js","./classDiagram-v2-HSJHXN6E-BDSg69Gf.js","./stateDiagram-FHFEXIEX-cW0_yGa2.js","./chunk-OYMX7WX6-C9X-9n06.js","./stateDiagram-v2-QKLJ7IA2-BXRvCfMx.js","./journeyDiagram-VCZTEJTY-JZjg2VSV.js","./timeline-definition-GMOUNBTQ-BFHBbQkD.js","./mindmap-definition-QFDTVHPH-BUSgUnqS.js","./kanban-definition-6JOO6SKY-C8GcL5aF.js","./sankeyDiagram-XADWPNL6-BIeDgqXh.js","./diagram-TYMM5635-XBBjlYIc.js","./diagram-MMDJMWI5-DQKHCVNg.js","./blockDiagram-DXYQGD6D-Cf47SU_V.js","./diagram-5BDNPKRD-CifPGnA5.js","./architectureDiagram-Q4EWVU46-CifAWdeJ.js","./diagram-G4DWMVQ6-CO324vbS.js","./wardleyDiagram-NUSXRM2D-BRdXdErY.js"])))=>i.map(i=>d[i]);
|
|
2
2
|
var hK=Object.defineProperty;var dK=(t,e,n)=>e in t?hK(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n;var pe=(t,e,n)=>dK(t,typeof e!="symbol"?e+"":e,n);(function(){const e=document.createElement("link").relList;if(e&&e.supports&&e.supports("modulepreload"))return;for(const i of document.querySelectorAll('link[rel="modulepreload"]'))r(i);new MutationObserver(i=>{for(const s of i)if(s.type==="childList")for(const o of s.addedNodes)o.tagName==="LINK"&&o.rel==="modulepreload"&&r(o)}).observe(document,{childList:!0,subtree:!0});function n(i){const s={};return i.integrity&&(s.integrity=i.integrity),i.referrerPolicy&&(s.referrerPolicy=i.referrerPolicy),i.crossOrigin==="use-credentials"?s.credentials="include":i.crossOrigin==="anonymous"?s.credentials="omit":s.credentials="same-origin",s}function r(i){if(i.ep)return;i.ep=!0;const s=n(i);fetch(i.href,s)}})();var ip=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function ol(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}function OHe(t){if(t.__esModule)return t;var e=t.default;if(typeof e=="function"){var n=function r(){return this instanceof r?Reflect.construct(e,arguments,this.constructor):e.apply(this,arguments)};n.prototype=e.prototype}else n={};return Object.defineProperty(n,"__esModule",{value:!0}),Object.keys(t).forEach(function(r){var i=Object.getOwnPropertyDescriptor(t,r);Object.defineProperty(n,r,i.get?i:{enumerable:!0,get:function(){return t[r]}})}),n}var wB={exports:{}},Fb={},vB={exports:{}},Je={};/**
|
|
3
3
|
* @license React
|
|
4
4
|
* react.production.min.js
|
|
@@ -898,8 +898,8 @@ Please report this to https://github.com/markedjs/marked.`,e){let i="<p>An error
|
|
|
898
898
|
L0,20`)},"requirement_arrow"),MAe=_((t,e,n)=>{const r=Gt(),{themeVariables:i}=r,{strokeWidth:s}=i;t.append("defs").append("marker").attr("id",n+"_"+e+"-requirement_arrowEnd").attr("refX",20).attr("refY",10).attr("markerWidth",20).attr("markerHeight",20).attr("orient","auto").attr("markerUnits","userSpaceOnUse").attr("stroke-width",`${s}`).attr("viewBox","0 0 25 20").append("path").attr("d",`M0,0
|
|
899
899
|
L20,10
|
|
900
900
|
M20,10
|
|
901
|
-
L0,20`).attr("stroke-linejoin","miter")},"requirement_arrow_neo"),LAe=_((t,e,n)=>{const r=t.append("defs").append("marker").attr("id",n+"_"+e+"-requirement_containsStart").attr("refX",0).attr("refY",10).attr("markerWidth",20).attr("markerHeight",20).attr("orient","auto").append("g");r.append("circle").attr("cx",10).attr("cy",10).attr("r",9).attr("fill","none"),r.append("line").attr("x1",1).attr("x2",19).attr("y1",10).attr("y2",10),r.append("line").attr("y1",1).attr("y2",19).attr("x1",10).attr("x2",10)},"requirement_contains"),DAe=_((t,e,n)=>{const r=Gt(),{themeVariables:i}=r,{strokeWidth:s}=i,o=t.append("defs").append("marker").attr("id",n+"_"+e+"-requirement_containsStart").attr("refX",0).attr("refY",10).attr("markerWidth",20).attr("markerHeight",20).attr("orient","auto").attr("markerUnits","userSpaceOnUse").append("g");o.append("circle").attr("cx",10).attr("cy",10).attr("r",9).attr("fill","none"),o.append("line").attr("x1",1).attr("x2",19).attr("y1",10).attr("y2",10),o.append("line").attr("y1",1).attr("y2",19).attr("x1",10).attr("x2",10),o.selectAll("*").attr("stroke-width",`${s}`)},"requirement_contains_neo"),OAe={extension:hAe,composition:dAe,aggregation:fAe,dependency:pAe,lollipop:gAe,point:mAe,circle:yAe,cross:xAe,barb:bAe,barbNeo:kAe,only_one:wAe,zero_or_one:vAe,one_or_more:CAe,zero_or_more:SAe,only_one_neo:_Ae,zero_or_one_neo:TAe,one_or_more_neo:EAe,zero_or_more_neo:AAe,requirement_arrow:NAe,requirement_contains:LAe,requirement_arrow_neo:MAe,requirement_contains_neo:DAe},RAe=uAe,IAe={common:_g,getConfig:Gt,insertCluster:DEe,insertEdge:cAe,insertEdgeLabel:rAe,insertMarkers:RAe,insertNode:GU,interpolateToCurve:oA,labelHelper:Ie,log:J,positionEdgeLabel:iAe},qp={},ZU=_(t=>{for(const e of t)qp[e.name]=e},"registerLayoutLoaders"),BAe=_(()=>{ZU([{name:"dagre",loader:_(async()=>await et(()=>import("./dagre-KV5264BT-B2IJS2kr.js"),__vite__mapDeps([0,1,2,3,4,5]),import.meta.url),"loader")},{name:"cose-bilkent",loader:_(async()=>await et(()=>import("./cose-bilkent-S5V4N54A-Dz2Nu8IR.js"),__vite__mapDeps([6,7]),import.meta.url),"loader")}])},"registerDefaultLayoutLoaders");BAe();var dUe=_(async(t,e)=>{if(!(t.layoutAlgorithm in qp))throw new Error(`Unknown layout algorithm: ${t.layoutAlgorithm}`);if(t.diagramId)for(const u of t.nodes){const h=u.domId||u.id;u.domId=`${t.diagramId}-${h}`}const n=qp[t.layoutAlgorithm],r=await n.loader(),{theme:i,themeVariables:s}=t.config,{useGradient:o,gradientStart:a,gradientStop:l}=s,c=e.attr("id");if(e.append("defs").append("filter").attr("id",`${c}-drop-shadow`).attr("height","130%").attr("width","130%").append("feDropShadow").attr("dx","4").attr("dy","4").attr("stdDeviation",0).attr("flood-opacity","0.06").attr("flood-color",`${i!=null&&i.includes("dark")?"#FFFFFF":"#000000"}`),e.append("defs").append("filter").attr("id",`${c}-drop-shadow-small`).attr("height","150%").attr("width","150%").append("feDropShadow").attr("dx","2").attr("dy","2").attr("stdDeviation",0).attr("flood-opacity","0.06").attr("flood-color",`${i!=null&&i.includes("dark")?"#FFFFFF":"#000000"}`),o){const u=e.append("linearGradient").attr("id",e.attr("id")+"-gradient").attr("gradientUnits","objectBoundingBox").attr("x1","0%").attr("y1","0%").attr("x2","100%").attr("y2","0%");u.append("svg:stop").attr("offset","0%").attr("stop-color",a).attr("stop-opacity",1),u.append("svg:stop").attr("offset","100%").attr("stop-color",l).attr("stop-opacity",1)}return r.render(t,e,IAe,{algorithm:n.algorithm})},"render"),fUe=_((t="",{fallback:e="dagre"}={})=>{if(t in qp)return t;if(e in qp)return J.warn(`Layout algorithm ${t} is not registered. Using ${e} as fallback.`),e;throw new Error(`Both layout algorithms ${t} and ${e} are not registered.`)},"getRegisteredLayoutAlgorithm"),QU="comm",JU="rule",eW="decl",PAe="@import",FAe="@namespace",$Ae="@keyframes",jAe="@layer",zAe=Math.abs,qf=String.fromCharCode;function tW(t){return t.trim()}function xS(t,e,n){return t.replace(e,n)}function Yu(t,e){return t.charCodeAt(e)|0}function Dh(t,e,n){return t.slice(e,n)}function Rs(t){return t.length}function HAe(t){return t.length}function Vm(t,e){return e.push(t),t}var H1=1,Oh=1,nW=0,ji=0,un=0,sd="";function EA(t,e,n,r,i,s,o,a){return{value:t,root:e,parent:n,type:r,props:i,children:s,line:H1,column:Oh,length:o,return:"",siblings:a}}function UAe(){return un}function WAe(){return un=ji>0?Yu(sd,--ji):0,Oh--,un===10&&(Oh=1,H1--),un}function cs(){return un=ji<nW?Yu(sd,ji++):0,Oh++,un===10&&(Oh=1,H1++),un}function Sa(){return Yu(sd,ji)}function Q0(){return ji}function U1(t,e){return Dh(sd,t,e)}function Vp(t){switch(t){case 0:case 9:case 10:case 13:case 32:return 5;case 33:case 43:case 44:case 47:case 62:case 64:case 126:case 59:case 123:case 125:return 4;case 58:return 3;case 34:case 39:case 40:case 91:return 2;case 41:case 93:return 1}return 0}function qAe(t){return H1=Oh=1,nW=Rs(sd=t),ji=0,[]}function VAe(t){return sd="",t}function nv(t){return tW(U1(ji-1,bS(t===91?t+2:t===40?t+1:t)))}function GAe(t){for(;(un=Sa())&&un<33;)cs();return Vp(t)>2||Vp(un)>3?"":" "}function YAe(t,e){for(;--e&&cs()&&!(un<48||un>102||un>57&&un<65||un>70&&un<97););return U1(t,Q0()+(e<6&&Sa()==32&&cs()==32))}function bS(t){for(;cs();)switch(un){case t:return ji;case 34:case 39:t!==34&&t!==39&&bS(un);break;case 40:t===41&&bS(t);break;case 92:cs();break}return ji}function KAe(t,e){for(;cs()&&t+un!==57;)if(t+un===84&&Sa()===47)break;return"/*"+U1(e,ji-1)+"*"+qf(t===47?t:cs())}function XAe(t){for(;!Vp(Sa());)cs();return U1(t,ji)}function ZAe(t){return VAe(J0("",null,null,null,[""],t=qAe(t),0,[0],t))}function J0(t,e,n,r,i,s,o,a,l){for(var c=0,u=0,h=o,f=0,d=0,p=0,m=1,y=1,x=1,b=0,k=0,w="",v=i,C=s,S=r,E=w;y;)switch(p=k,k=cs()){case 40:p!=108&&Yu(E,h-1)==58?(b++,E+="("):E+=nv(k);break;case 41:b--,E+=")";break;case 34:case 39:case 91:E+=nv(k);break;case 9:case 10:case 13:case 32:if(b>0){E+=qf(k);break}E+=GAe(p);break;case 92:E+=YAe(Q0()-1,7);continue;case 47:switch(Sa()){case 42:case 47:Vm(QAe(KAe(cs(),Q0()),e,n,l),l),(Vp(p||1)==5||Vp(Sa()||1)==5)&&Rs(E)&&Dh(E,-1,void 0)!==" "&&(E+=" ");break;default:E+="/"}break;case 123*m:a[c++]=Rs(E)*x;case 125*m:case 59:case 0:if(b>0&&k){E+=qf(k);break}switch(k){case 0:case 125:y=0;case 59+u:x==-1&&(E=xS(E,/\f/g,"")),d>0&&(Rs(E)-h||m===0)&&Vm(d>32?iR(E+";",r,n,h-1,l):iR(xS(E," ","")+";",r,n,h-2,l),l);break;case 59:E+=";";default:if(Vm(S=rR(E,e,n,c,u,i,a,w,v=[],C=[],h,s),s),k===123)if(u===0)J0(E,e,S,S,v,s,h,a,C);else{switch(f){case 99:if(Yu(E,3)===110)break;case 108:if(Yu(E,2)===97)break;default:u=0;case 100:case 109:case 115:}u?J0(t,S,S,r&&Vm(rR(t,S,S,0,0,i,a,w,i,v=[],h,C),C),i,C,h,a,r?v:C):J0(E,S,S,S,[""],C,0,a,C)}}c=u=d=0,m=x=1,w=E="",h=o;break;case 58:h=1+Rs(E),d=p;default:if(m<1){if(k==123)--m;else if(k==125&&m++==0&&WAe()==125)continue}switch(E+=qf(k),k*m){case 38:x=u>0?1:(E+="\f",-1);break;case 44:if(b>0)break;a[c++]=(Rs(E)-1)*x,x=1;break;case 64:Sa()===45&&(E+=nv(cs())),f=Sa(),u=h=Rs(w=E+=XAe(Q0())),k++;break;case 45:p===45&&Rs(E)==2&&(m=0)}}return s}function rR(t,e,n,r,i,s,o,a,l,c,u,h){for(var f=i-1,d=i===0?s:[""],p=HAe(d),m=0,y=0,x=0;m<r;++m)for(var b=0,k=Dh(t,f+1,f=zAe(y=o[m])),w=t;b<p;++b)(w=tW(y>0?d[b]+" "+k:xS(k,/&\f/g,d[b])))&&(l[x++]=w);return EA(t,e,n,i===0?JU:a,l,c,u,h)}function QAe(t,e,n,r){return EA(t,e,n,QU,qf(UAe()),Dh(t,2,-2),0,r)}function iR(t,e,n,r,i){return EA(t,e,n,eW,Dh(t,0,r),Dh(t,r+1,-1),r,i)}function kS(t,e){for(var n="",r=0;r<t.length;r++)n+=e(t[r],r,t,e)||"";return n}function JAe(t,e,n,r){switch(t.type){case jAe:if(t.children.length)break;case PAe:case FAe:case eW:return t.return=t.return||t.value;case QU:return"";case $Ae:return t.return=t.value+"{"+kS(t.children,r)+"}";case JU:if(!Rs(t.value=t.props.join(",")))return""}return Rs(n=kS(t.children,r))?t.return=t.value+"{"+n+"}":""}var eNe=T7(Object.keys,Object),tNe=Object.prototype,nNe=tNe.hasOwnProperty;function rNe(t){if(!O1(t))return eNe(t);var e=[];for(var n in Object(t))nNe.call(t,n)&&n!="constructor"&&e.push(n);return e}var wS=zc(Qs,"DataView"),vS=zc(Qs,"Promise"),CS=zc(Qs,"Set"),SS=zc(Qs,"WeakMap"),sR="[object Map]",iNe="[object Object]",oR="[object Promise]",aR="[object Set]",lR="[object WeakMap]",cR="[object DataView]",sNe=jc(wS),oNe=jc(Up),aNe=jc(vS),lNe=jc(CS),cNe=jc(SS),Dl=td;(wS&&Dl(new wS(new ArrayBuffer(1)))!=cR||Up&&Dl(new Up)!=sR||vS&&Dl(vS.resolve())!=oR||CS&&Dl(new CS)!=aR||SS&&Dl(new SS)!=lR)&&(Dl=function(t){var e=td(t),n=e==iNe?t.constructor:void 0,r=n?jc(n):"";if(r)switch(r){case sNe:return cR;case oNe:return sR;case aNe:return oR;case lNe:return aR;case cNe:return lR}return e});var uNe="[object Map]",hNe="[object Set]",dNe=Object.prototype,fNe=dNe.hasOwnProperty;function uR(t){if(t==null)return!0;if(R1(t)&&(Mx(t)||typeof t=="string"||typeof t.splice=="function"||iA(t)||sA(t)||Nx(t)))return!t.length;var e=Dl(t);if(e==uNe||e==hNe)return!t.size;if(O1(t))return!rNe(t).length;for(var n in t)if(fNe.call(t,n))return!1;return!0}var rW="c4",pNe=_(t=>/^\s*C4Context|C4Container|C4Component|C4Dynamic|C4Deployment/.test(t),"detector"),gNe=_(async()=>{const{diagram:t}=await et(async()=>{const{diagram:e}=await import("./c4Diagram-AHTNJAMY-BL4Rtyhe.js");return{diagram:e}},__vite__mapDeps([8,9]),import.meta.url);return{id:rW,diagram:t}},"loader"),mNe={id:rW,detector:pNe,loader:gNe},yNe=mNe,iW="flowchart",xNe=_((t,e)=>{var n,r;return((n=e==null?void 0:e.flowchart)==null?void 0:n.defaultRenderer)==="dagre-wrapper"||((r=e==null?void 0:e.flowchart)==null?void 0:r.defaultRenderer)==="elk"?!1:/^\s*graph/.test(t)},"detector"),bNe=_(async()=>{const{diagram:t}=await et(async()=>{const{diagram:e}=await import("./flowDiagram-DWJPFMVM-DHyg5Orb.js");return{diagram:e}},__vite__mapDeps([10,11,9,12,13,14]),import.meta.url);return{id:iW,diagram:t}},"loader"),kNe={id:iW,detector:xNe,loader:bNe},wNe=kNe,sW="flowchart-v2",vNe=_((t,e)=>{var n,r,i;return((n=e==null?void 0:e.flowchart)==null?void 0:n.defaultRenderer)==="dagre-d3"?!1:(((r=e==null?void 0:e.flowchart)==null?void 0:r.defaultRenderer)==="elk"&&(e.layout="elk"),/^\s*graph/.test(t)&&((i=e==null?void 0:e.flowchart)==null?void 0:i.defaultRenderer)==="dagre-wrapper"?!0:/^\s*flowchart/.test(t))},"detector"),CNe=_(async()=>{const{diagram:t}=await et(async()=>{const{diagram:e}=await import("./flowDiagram-DWJPFMVM-DHyg5Orb.js");return{diagram:e}},__vite__mapDeps([10,11,9,12,13,14]),import.meta.url);return{id:sW,diagram:t}},"loader"),SNe={id:sW,detector:vNe,loader:CNe},_Ne=SNe,oW="er",TNe=_(t=>/^\s*erDiagram/.test(t),"detector"),ENe=_(async()=>{const{diagram:t}=await et(async()=>{const{diagram:e}=await import("./erDiagram-SMLLAGMA-DOKYAfb3.js");return{diagram:e}},__vite__mapDeps([15,12,13,14]),import.meta.url);return{id:oW,diagram:t}},"loader"),ANe={id:oW,detector:TNe,loader:ENe},NNe=ANe,aW="gitGraph",MNe=_(t=>/^\s*gitGraph/.test(t),"detector"),LNe=_(async()=>{const{diagram:t}=await et(async()=>{const{diagram:e}=await import("./gitGraphDiagram-UUTBAWPF-Bv2jMUpq.js");return{diagram:e}},__vite__mapDeps([16,17,18,19,4,2]),import.meta.url);return{id:aW,diagram:t}},"loader"),DNe={id:aW,detector:MNe,loader:LNe},ONe=DNe,lW="gantt",RNe=_(t=>/^\s*gantt/.test(t),"detector"),INe=_(async()=>{const{diagram:t}=await et(async()=>{const{diagram:e}=await import("./ganttDiagram-T4ZO3ILL--jR28tKt.js");return{diagram:e}},__vite__mapDeps([20,21,22,23]),import.meta.url);return{id:lW,diagram:t}},"loader"),BNe={id:lW,detector:RNe,loader:INe},PNe=BNe,cW="info",FNe=_(t=>/^\s*info/.test(t),"detector"),$Ne=_(async()=>{const{diagram:t}=await et(async()=>{const{diagram:e}=await import("./infoDiagram-42DDH7IO-DrEh4i5q.js");return{diagram:e}},__vite__mapDeps([24,19,4,2]),import.meta.url);return{id:cW,diagram:t}},"loader"),jNe={id:cW,detector:FNe,loader:$Ne},uW="pie",zNe=_(t=>/^\s*pie/.test(t),"detector"),HNe=_(async()=>{const{diagram:t}=await et(async()=>{const{diagram:e}=await import("./pieDiagram-DEJITSTG-bjiSm1h0.js");return{diagram:e}},__vite__mapDeps([25,17,19,4,2,26,27,22]),import.meta.url);return{id:uW,diagram:t}},"loader"),UNe={id:uW,detector:zNe,loader:HNe},hW="quadrantChart",WNe=_(t=>/^\s*quadrantChart/.test(t),"detector"),qNe=_(async()=>{const{diagram:t}=await et(async()=>{const{diagram:e}=await import("./quadrantDiagram-34T5L4WZ-B6SKXcvr.js");return{diagram:e}},__vite__mapDeps([28,21,22,23]),import.meta.url);return{id:hW,diagram:t}},"loader"),VNe={id:hW,detector:WNe,loader:qNe},GNe=VNe,dW="xychart",YNe=_(t=>/^\s*xychart(-beta)?/.test(t),"detector"),KNe=_(async()=>{const{diagram:t}=await et(async()=>{const{diagram:e}=await import("./xychartDiagram-5P7HB3ND-Dfqj8elB.js");return{diagram:e}},__vite__mapDeps([29,22,27,21,23]),import.meta.url);return{id:dW,diagram:t}},"loader"),XNe={id:dW,detector:YNe,loader:KNe},ZNe=XNe,fW="requirement",QNe=_(t=>/^\s*requirement(Diagram)?/.test(t),"detector"),JNe=_(async()=>{const{diagram:t}=await et(async()=>{const{diagram:e}=await import("./requirementDiagram-MS252O5E-l_nMizfW.js");return{diagram:e}},__vite__mapDeps([30,12,13]),import.meta.url);return{id:fW,diagram:t}},"loader"),eMe={id:fW,detector:QNe,loader:JNe},tMe=eMe,pW="sequence",nMe=_(t=>/^\s*sequenceDiagram/.test(t),"detector"),rMe=_(async()=>{const{diagram:t}=await et(async()=>{const{diagram:e}=await import("./sequenceDiagram-FGHM5R23-DkYd7G1G.js");return{diagram:e}},__vite__mapDeps([31,9,18]),import.meta.url);return{id:pW,diagram:t}},"loader"),iMe={id:pW,detector:nMe,loader:rMe},sMe=iMe,gW="class",oMe=_((t,e)=>{var n;return((n=e==null?void 0:e.class)==null?void 0:n.defaultRenderer)==="dagre-wrapper"?!1:/^\s*classDiagram/.test(t)},"detector"),aMe=_(async()=>{const{diagram:t}=await et(async()=>{const{diagram:e}=await import("./classDiagram-6PBFFD2Q-CNkE6SD4.js");return{diagram:e}},__vite__mapDeps([32,33,11,9,12,13]),import.meta.url);return{id:gW,diagram:t}},"loader"),lMe={id:gW,detector:oMe,loader:aMe},cMe=lMe,mW="classDiagram",uMe=_((t,e)=>{var n;return/^\s*classDiagram/.test(t)&&((n=e==null?void 0:e.class)==null?void 0:n.defaultRenderer)==="dagre-wrapper"?!0:/^\s*classDiagram-v2/.test(t)},"detector"),hMe=_(async()=>{const{diagram:t}=await et(async()=>{const{diagram:e}=await import("./classDiagram-v2-HSJHXN6E-CNkE6SD4.js");return{diagram:e}},__vite__mapDeps([34,33,11,9,12,13]),import.meta.url);return{id:mW,diagram:t}},"loader"),dMe={id:mW,detector:uMe,loader:hMe},fMe=dMe,yW="state",pMe=_((t,e)=>{var n;return((n=e==null?void 0:e.state)==null?void 0:n.defaultRenderer)==="dagre-wrapper"?!1:/^\s*stateDiagram/.test(t)},"detector"),gMe=_(async()=>{const{diagram:t}=await et(async()=>{const{diagram:e}=await import("./stateDiagram-FHFEXIEX-DXHYUjiy.js");return{diagram:e}},__vite__mapDeps([35,36,12,13,1,2,3,4]),import.meta.url);return{id:yW,diagram:t}},"loader"),mMe={id:yW,detector:pMe,loader:gMe},yMe=mMe,xW="stateDiagram",xMe=_((t,e)=>{var n;return!!(/^\s*stateDiagram-v2/.test(t)||/^\s*stateDiagram/.test(t)&&((n=e==null?void 0:e.state)==null?void 0:n.defaultRenderer)==="dagre-wrapper")},"detector"),bMe=_(async()=>{const{diagram:t}=await et(async()=>{const{diagram:e}=await import("./stateDiagram-v2-QKLJ7IA2-CkNAZmh8.js");return{diagram:e}},__vite__mapDeps([37,36,12,13]),import.meta.url);return{id:xW,diagram:t}},"loader"),kMe={id:xW,detector:xMe,loader:bMe},wMe=kMe,bW="journey",vMe=_(t=>/^\s*journey/.test(t),"detector"),CMe=_(async()=>{const{diagram:t}=await et(async()=>{const{diagram:e}=await import("./journeyDiagram-VCZTEJTY-CKgvMQgR.js");return{diagram:e}},__vite__mapDeps([38,11,9,26]),import.meta.url);return{id:bW,diagram:t}},"loader"),SMe={id:bW,detector:vMe,loader:CMe},_Me=SMe,TMe=_((t,e,n)=>{J.debug(`rendering svg for syntax error
|
|
902
|
-
`);const r=Gve(e),i=r.append("g");r.attr("viewBox","0 0 2412 512"),W8(r,100,512,!0),i.append("path").attr("class","error-icon").attr("d","m411.313,123.313c6.25-6.25 6.25-16.375 0-22.625s-16.375-6.25-22.625,0l-32,32-9.375,9.375-20.688-20.688c-12.484-12.5-32.766-12.5-45.25,0l-16,16c-1.261,1.261-2.304,2.648-3.31,4.051-21.739-8.561-45.324-13.426-70.065-13.426-105.867,0-192,86.133-192,192s86.133,192 192,192 192-86.133 192-192c0-24.741-4.864-48.327-13.426-70.065 1.402-1.007 2.79-2.049 4.051-3.31l16-16c12.5-12.492 12.5-32.758 0-45.25l-20.688-20.688 9.375-9.375 32.001-31.999zm-219.313,100.687c-52.938,0-96,43.063-96,96 0,8.836-7.164,16-16,16s-16-7.164-16-16c0-70.578 57.422-128 128-128 8.836,0 16,7.164 16,16s-7.164,16-16,16z"),i.append("path").attr("class","error-icon").attr("d","m459.02,148.98c-6.25-6.25-16.375-6.25-22.625,0s-6.25,16.375 0,22.625l16,16c3.125,3.125 7.219,4.688 11.313,4.688 4.094,0 8.188-1.563 11.313-4.688 6.25-6.25 6.25-16.375 0-22.625l-16.001-16z"),i.append("path").attr("class","error-icon").attr("d","m340.395,75.605c3.125,3.125 7.219,4.688 11.313,4.688 4.094,0 8.188-1.563 11.313-4.688 6.25-6.25 6.25-16.375 0-22.625l-16-16c-6.25-6.25-16.375-6.25-22.625,0s-6.25,16.375 0,22.625l15.999,16z"),i.append("path").attr("class","error-icon").attr("d","m400,64c8.844,0 16-7.164 16-16v-32c0-8.836-7.156-16-16-16-8.844,0-16,7.164-16,16v32c0,8.836 7.156,16 16,16z"),i.append("path").attr("class","error-icon").attr("d","m496,96.586h-32c-8.844,0-16,7.164-16,16 0,8.836 7.156,16 16,16h32c8.844,0 16-7.164 16-16 0-8.836-7.156-16-16-16z"),i.append("path").attr("class","error-icon").attr("d","m436.98,75.605c3.125,3.125 7.219,4.688 11.313,4.688 4.094,0 8.188-1.563 11.313-4.688l32-32c6.25-6.25 6.25-16.375 0-22.625s-16.375-6.25-22.625,0l-32,32c-6.251,6.25-6.251,16.375-0.001,22.625z"),i.append("text").attr("class","error-text").attr("x",1440).attr("y",250).attr("font-size","150px").style("text-anchor","middle").text("Syntax error in text"),i.append("text").attr("class","error-text").attr("x",1250).attr("y",400).attr("font-size","100px").style("text-anchor","middle").text(`mermaid version ${n}`)},"draw"),kW={draw:TMe},EMe=kW,AMe={db:{},renderer:kW,parser:{parse:_(()=>{},"parse")}},NMe=AMe,wW="flowchart-elk",MMe=_((t,e={})=>{var n;return/^\s*flowchart-elk/.test(t)||/^\s*(flowchart|graph)/.test(t)&&((n=e==null?void 0:e.flowchart)==null?void 0:n.defaultRenderer)==="elk"?(e.layout="elk",!0):!1},"detector"),LMe=_(async()=>{const{diagram:t}=await et(async()=>{const{diagram:e}=await import("./flowDiagram-DWJPFMVM-
|
|
901
|
+
L0,20`).attr("stroke-linejoin","miter")},"requirement_arrow_neo"),LAe=_((t,e,n)=>{const r=t.append("defs").append("marker").attr("id",n+"_"+e+"-requirement_containsStart").attr("refX",0).attr("refY",10).attr("markerWidth",20).attr("markerHeight",20).attr("orient","auto").append("g");r.append("circle").attr("cx",10).attr("cy",10).attr("r",9).attr("fill","none"),r.append("line").attr("x1",1).attr("x2",19).attr("y1",10).attr("y2",10),r.append("line").attr("y1",1).attr("y2",19).attr("x1",10).attr("x2",10)},"requirement_contains"),DAe=_((t,e,n)=>{const r=Gt(),{themeVariables:i}=r,{strokeWidth:s}=i,o=t.append("defs").append("marker").attr("id",n+"_"+e+"-requirement_containsStart").attr("refX",0).attr("refY",10).attr("markerWidth",20).attr("markerHeight",20).attr("orient","auto").attr("markerUnits","userSpaceOnUse").append("g");o.append("circle").attr("cx",10).attr("cy",10).attr("r",9).attr("fill","none"),o.append("line").attr("x1",1).attr("x2",19).attr("y1",10).attr("y2",10),o.append("line").attr("y1",1).attr("y2",19).attr("x1",10).attr("x2",10),o.selectAll("*").attr("stroke-width",`${s}`)},"requirement_contains_neo"),OAe={extension:hAe,composition:dAe,aggregation:fAe,dependency:pAe,lollipop:gAe,point:mAe,circle:yAe,cross:xAe,barb:bAe,barbNeo:kAe,only_one:wAe,zero_or_one:vAe,one_or_more:CAe,zero_or_more:SAe,only_one_neo:_Ae,zero_or_one_neo:TAe,one_or_more_neo:EAe,zero_or_more_neo:AAe,requirement_arrow:NAe,requirement_contains:LAe,requirement_arrow_neo:MAe,requirement_contains_neo:DAe},RAe=uAe,IAe={common:_g,getConfig:Gt,insertCluster:DEe,insertEdge:cAe,insertEdgeLabel:rAe,insertMarkers:RAe,insertNode:GU,interpolateToCurve:oA,labelHelper:Ie,log:J,positionEdgeLabel:iAe},qp={},ZU=_(t=>{for(const e of t)qp[e.name]=e},"registerLayoutLoaders"),BAe=_(()=>{ZU([{name:"dagre",loader:_(async()=>await et(()=>import("./dagre-KV5264BT-fy9Jy7D-.js"),__vite__mapDeps([0,1,2,3,4,5]),import.meta.url),"loader")},{name:"cose-bilkent",loader:_(async()=>await et(()=>import("./cose-bilkent-S5V4N54A-Dp34VlDR.js"),__vite__mapDeps([6,7]),import.meta.url),"loader")}])},"registerDefaultLayoutLoaders");BAe();var dUe=_(async(t,e)=>{if(!(t.layoutAlgorithm in qp))throw new Error(`Unknown layout algorithm: ${t.layoutAlgorithm}`);if(t.diagramId)for(const u of t.nodes){const h=u.domId||u.id;u.domId=`${t.diagramId}-${h}`}const n=qp[t.layoutAlgorithm],r=await n.loader(),{theme:i,themeVariables:s}=t.config,{useGradient:o,gradientStart:a,gradientStop:l}=s,c=e.attr("id");if(e.append("defs").append("filter").attr("id",`${c}-drop-shadow`).attr("height","130%").attr("width","130%").append("feDropShadow").attr("dx","4").attr("dy","4").attr("stdDeviation",0).attr("flood-opacity","0.06").attr("flood-color",`${i!=null&&i.includes("dark")?"#FFFFFF":"#000000"}`),e.append("defs").append("filter").attr("id",`${c}-drop-shadow-small`).attr("height","150%").attr("width","150%").append("feDropShadow").attr("dx","2").attr("dy","2").attr("stdDeviation",0).attr("flood-opacity","0.06").attr("flood-color",`${i!=null&&i.includes("dark")?"#FFFFFF":"#000000"}`),o){const u=e.append("linearGradient").attr("id",e.attr("id")+"-gradient").attr("gradientUnits","objectBoundingBox").attr("x1","0%").attr("y1","0%").attr("x2","100%").attr("y2","0%");u.append("svg:stop").attr("offset","0%").attr("stop-color",a).attr("stop-opacity",1),u.append("svg:stop").attr("offset","100%").attr("stop-color",l).attr("stop-opacity",1)}return r.render(t,e,IAe,{algorithm:n.algorithm})},"render"),fUe=_((t="",{fallback:e="dagre"}={})=>{if(t in qp)return t;if(e in qp)return J.warn(`Layout algorithm ${t} is not registered. Using ${e} as fallback.`),e;throw new Error(`Both layout algorithms ${t} and ${e} are not registered.`)},"getRegisteredLayoutAlgorithm"),QU="comm",JU="rule",eW="decl",PAe="@import",FAe="@namespace",$Ae="@keyframes",jAe="@layer",zAe=Math.abs,qf=String.fromCharCode;function tW(t){return t.trim()}function xS(t,e,n){return t.replace(e,n)}function Yu(t,e){return t.charCodeAt(e)|0}function Dh(t,e,n){return t.slice(e,n)}function Rs(t){return t.length}function HAe(t){return t.length}function Vm(t,e){return e.push(t),t}var H1=1,Oh=1,nW=0,ji=0,un=0,sd="";function EA(t,e,n,r,i,s,o,a){return{value:t,root:e,parent:n,type:r,props:i,children:s,line:H1,column:Oh,length:o,return:"",siblings:a}}function UAe(){return un}function WAe(){return un=ji>0?Yu(sd,--ji):0,Oh--,un===10&&(Oh=1,H1--),un}function cs(){return un=ji<nW?Yu(sd,ji++):0,Oh++,un===10&&(Oh=1,H1++),un}function Sa(){return Yu(sd,ji)}function Q0(){return ji}function U1(t,e){return Dh(sd,t,e)}function Vp(t){switch(t){case 0:case 9:case 10:case 13:case 32:return 5;case 33:case 43:case 44:case 47:case 62:case 64:case 126:case 59:case 123:case 125:return 4;case 58:return 3;case 34:case 39:case 40:case 91:return 2;case 41:case 93:return 1}return 0}function qAe(t){return H1=Oh=1,nW=Rs(sd=t),ji=0,[]}function VAe(t){return sd="",t}function nv(t){return tW(U1(ji-1,bS(t===91?t+2:t===40?t+1:t)))}function GAe(t){for(;(un=Sa())&&un<33;)cs();return Vp(t)>2||Vp(un)>3?"":" "}function YAe(t,e){for(;--e&&cs()&&!(un<48||un>102||un>57&&un<65||un>70&&un<97););return U1(t,Q0()+(e<6&&Sa()==32&&cs()==32))}function bS(t){for(;cs();)switch(un){case t:return ji;case 34:case 39:t!==34&&t!==39&&bS(un);break;case 40:t===41&&bS(t);break;case 92:cs();break}return ji}function KAe(t,e){for(;cs()&&t+un!==57;)if(t+un===84&&Sa()===47)break;return"/*"+U1(e,ji-1)+"*"+qf(t===47?t:cs())}function XAe(t){for(;!Vp(Sa());)cs();return U1(t,ji)}function ZAe(t){return VAe(J0("",null,null,null,[""],t=qAe(t),0,[0],t))}function J0(t,e,n,r,i,s,o,a,l){for(var c=0,u=0,h=o,f=0,d=0,p=0,m=1,y=1,x=1,b=0,k=0,w="",v=i,C=s,S=r,E=w;y;)switch(p=k,k=cs()){case 40:p!=108&&Yu(E,h-1)==58?(b++,E+="("):E+=nv(k);break;case 41:b--,E+=")";break;case 34:case 39:case 91:E+=nv(k);break;case 9:case 10:case 13:case 32:if(b>0){E+=qf(k);break}E+=GAe(p);break;case 92:E+=YAe(Q0()-1,7);continue;case 47:switch(Sa()){case 42:case 47:Vm(QAe(KAe(cs(),Q0()),e,n,l),l),(Vp(p||1)==5||Vp(Sa()||1)==5)&&Rs(E)&&Dh(E,-1,void 0)!==" "&&(E+=" ");break;default:E+="/"}break;case 123*m:a[c++]=Rs(E)*x;case 125*m:case 59:case 0:if(b>0&&k){E+=qf(k);break}switch(k){case 0:case 125:y=0;case 59+u:x==-1&&(E=xS(E,/\f/g,"")),d>0&&(Rs(E)-h||m===0)&&Vm(d>32?iR(E+";",r,n,h-1,l):iR(xS(E," ","")+";",r,n,h-2,l),l);break;case 59:E+=";";default:if(Vm(S=rR(E,e,n,c,u,i,a,w,v=[],C=[],h,s),s),k===123)if(u===0)J0(E,e,S,S,v,s,h,a,C);else{switch(f){case 99:if(Yu(E,3)===110)break;case 108:if(Yu(E,2)===97)break;default:u=0;case 100:case 109:case 115:}u?J0(t,S,S,r&&Vm(rR(t,S,S,0,0,i,a,w,i,v=[],h,C),C),i,C,h,a,r?v:C):J0(E,S,S,S,[""],C,0,a,C)}}c=u=d=0,m=x=1,w=E="",h=o;break;case 58:h=1+Rs(E),d=p;default:if(m<1){if(k==123)--m;else if(k==125&&m++==0&&WAe()==125)continue}switch(E+=qf(k),k*m){case 38:x=u>0?1:(E+="\f",-1);break;case 44:if(b>0)break;a[c++]=(Rs(E)-1)*x,x=1;break;case 64:Sa()===45&&(E+=nv(cs())),f=Sa(),u=h=Rs(w=E+=XAe(Q0())),k++;break;case 45:p===45&&Rs(E)==2&&(m=0)}}return s}function rR(t,e,n,r,i,s,o,a,l,c,u,h){for(var f=i-1,d=i===0?s:[""],p=HAe(d),m=0,y=0,x=0;m<r;++m)for(var b=0,k=Dh(t,f+1,f=zAe(y=o[m])),w=t;b<p;++b)(w=tW(y>0?d[b]+" "+k:xS(k,/&\f/g,d[b])))&&(l[x++]=w);return EA(t,e,n,i===0?JU:a,l,c,u,h)}function QAe(t,e,n,r){return EA(t,e,n,QU,qf(UAe()),Dh(t,2,-2),0,r)}function iR(t,e,n,r,i){return EA(t,e,n,eW,Dh(t,0,r),Dh(t,r+1,-1),r,i)}function kS(t,e){for(var n="",r=0;r<t.length;r++)n+=e(t[r],r,t,e)||"";return n}function JAe(t,e,n,r){switch(t.type){case jAe:if(t.children.length)break;case PAe:case FAe:case eW:return t.return=t.return||t.value;case QU:return"";case $Ae:return t.return=t.value+"{"+kS(t.children,r)+"}";case JU:if(!Rs(t.value=t.props.join(",")))return""}return Rs(n=kS(t.children,r))?t.return=t.value+"{"+n+"}":""}var eNe=T7(Object.keys,Object),tNe=Object.prototype,nNe=tNe.hasOwnProperty;function rNe(t){if(!O1(t))return eNe(t);var e=[];for(var n in Object(t))nNe.call(t,n)&&n!="constructor"&&e.push(n);return e}var wS=zc(Qs,"DataView"),vS=zc(Qs,"Promise"),CS=zc(Qs,"Set"),SS=zc(Qs,"WeakMap"),sR="[object Map]",iNe="[object Object]",oR="[object Promise]",aR="[object Set]",lR="[object WeakMap]",cR="[object DataView]",sNe=jc(wS),oNe=jc(Up),aNe=jc(vS),lNe=jc(CS),cNe=jc(SS),Dl=td;(wS&&Dl(new wS(new ArrayBuffer(1)))!=cR||Up&&Dl(new Up)!=sR||vS&&Dl(vS.resolve())!=oR||CS&&Dl(new CS)!=aR||SS&&Dl(new SS)!=lR)&&(Dl=function(t){var e=td(t),n=e==iNe?t.constructor:void 0,r=n?jc(n):"";if(r)switch(r){case sNe:return cR;case oNe:return sR;case aNe:return oR;case lNe:return aR;case cNe:return lR}return e});var uNe="[object Map]",hNe="[object Set]",dNe=Object.prototype,fNe=dNe.hasOwnProperty;function uR(t){if(t==null)return!0;if(R1(t)&&(Mx(t)||typeof t=="string"||typeof t.splice=="function"||iA(t)||sA(t)||Nx(t)))return!t.length;var e=Dl(t);if(e==uNe||e==hNe)return!t.size;if(O1(t))return!rNe(t).length;for(var n in t)if(fNe.call(t,n))return!1;return!0}var rW="c4",pNe=_(t=>/^\s*C4Context|C4Container|C4Component|C4Dynamic|C4Deployment/.test(t),"detector"),gNe=_(async()=>{const{diagram:t}=await et(async()=>{const{diagram:e}=await import("./c4Diagram-AHTNJAMY-DnNIhb62.js");return{diagram:e}},__vite__mapDeps([8,9]),import.meta.url);return{id:rW,diagram:t}},"loader"),mNe={id:rW,detector:pNe,loader:gNe},yNe=mNe,iW="flowchart",xNe=_((t,e)=>{var n,r;return((n=e==null?void 0:e.flowchart)==null?void 0:n.defaultRenderer)==="dagre-wrapper"||((r=e==null?void 0:e.flowchart)==null?void 0:r.defaultRenderer)==="elk"?!1:/^\s*graph/.test(t)},"detector"),bNe=_(async()=>{const{diagram:t}=await et(async()=>{const{diagram:e}=await import("./flowDiagram-DWJPFMVM-DaMvV0c8.js");return{diagram:e}},__vite__mapDeps([10,11,9,12,13,14]),import.meta.url);return{id:iW,diagram:t}},"loader"),kNe={id:iW,detector:xNe,loader:bNe},wNe=kNe,sW="flowchart-v2",vNe=_((t,e)=>{var n,r,i;return((n=e==null?void 0:e.flowchart)==null?void 0:n.defaultRenderer)==="dagre-d3"?!1:(((r=e==null?void 0:e.flowchart)==null?void 0:r.defaultRenderer)==="elk"&&(e.layout="elk"),/^\s*graph/.test(t)&&((i=e==null?void 0:e.flowchart)==null?void 0:i.defaultRenderer)==="dagre-wrapper"?!0:/^\s*flowchart/.test(t))},"detector"),CNe=_(async()=>{const{diagram:t}=await et(async()=>{const{diagram:e}=await import("./flowDiagram-DWJPFMVM-DaMvV0c8.js");return{diagram:e}},__vite__mapDeps([10,11,9,12,13,14]),import.meta.url);return{id:sW,diagram:t}},"loader"),SNe={id:sW,detector:vNe,loader:CNe},_Ne=SNe,oW="er",TNe=_(t=>/^\s*erDiagram/.test(t),"detector"),ENe=_(async()=>{const{diagram:t}=await et(async()=>{const{diagram:e}=await import("./erDiagram-SMLLAGMA-U_b9j-iW.js");return{diagram:e}},__vite__mapDeps([15,12,13,14]),import.meta.url);return{id:oW,diagram:t}},"loader"),ANe={id:oW,detector:TNe,loader:ENe},NNe=ANe,aW="gitGraph",MNe=_(t=>/^\s*gitGraph/.test(t),"detector"),LNe=_(async()=>{const{diagram:t}=await et(async()=>{const{diagram:e}=await import("./gitGraphDiagram-UUTBAWPF-B5Go_w_e.js");return{diagram:e}},__vite__mapDeps([16,17,18,19,4,2]),import.meta.url);return{id:aW,diagram:t}},"loader"),DNe={id:aW,detector:MNe,loader:LNe},ONe=DNe,lW="gantt",RNe=_(t=>/^\s*gantt/.test(t),"detector"),INe=_(async()=>{const{diagram:t}=await et(async()=>{const{diagram:e}=await import("./ganttDiagram-T4ZO3ILL-DxcjNxAW.js");return{diagram:e}},__vite__mapDeps([20,21,22,23]),import.meta.url);return{id:lW,diagram:t}},"loader"),BNe={id:lW,detector:RNe,loader:INe},PNe=BNe,cW="info",FNe=_(t=>/^\s*info/.test(t),"detector"),$Ne=_(async()=>{const{diagram:t}=await et(async()=>{const{diagram:e}=await import("./infoDiagram-42DDH7IO-B9uc-Zdc.js");return{diagram:e}},__vite__mapDeps([24,19,4,2]),import.meta.url);return{id:cW,diagram:t}},"loader"),jNe={id:cW,detector:FNe,loader:$Ne},uW="pie",zNe=_(t=>/^\s*pie/.test(t),"detector"),HNe=_(async()=>{const{diagram:t}=await et(async()=>{const{diagram:e}=await import("./pieDiagram-DEJITSTG-BTBjF7Bv.js");return{diagram:e}},__vite__mapDeps([25,17,19,4,2,26,27,22]),import.meta.url);return{id:uW,diagram:t}},"loader"),UNe={id:uW,detector:zNe,loader:HNe},hW="quadrantChart",WNe=_(t=>/^\s*quadrantChart/.test(t),"detector"),qNe=_(async()=>{const{diagram:t}=await et(async()=>{const{diagram:e}=await import("./quadrantDiagram-34T5L4WZ-Z3Buxsxe.js");return{diagram:e}},__vite__mapDeps([28,21,22,23]),import.meta.url);return{id:hW,diagram:t}},"loader"),VNe={id:hW,detector:WNe,loader:qNe},GNe=VNe,dW="xychart",YNe=_(t=>/^\s*xychart(-beta)?/.test(t),"detector"),KNe=_(async()=>{const{diagram:t}=await et(async()=>{const{diagram:e}=await import("./xychartDiagram-5P7HB3ND-za19jTKs.js");return{diagram:e}},__vite__mapDeps([29,22,27,21,23]),import.meta.url);return{id:dW,diagram:t}},"loader"),XNe={id:dW,detector:YNe,loader:KNe},ZNe=XNe,fW="requirement",QNe=_(t=>/^\s*requirement(Diagram)?/.test(t),"detector"),JNe=_(async()=>{const{diagram:t}=await et(async()=>{const{diagram:e}=await import("./requirementDiagram-MS252O5E-CnfFthlg.js");return{diagram:e}},__vite__mapDeps([30,12,13]),import.meta.url);return{id:fW,diagram:t}},"loader"),eMe={id:fW,detector:QNe,loader:JNe},tMe=eMe,pW="sequence",nMe=_(t=>/^\s*sequenceDiagram/.test(t),"detector"),rMe=_(async()=>{const{diagram:t}=await et(async()=>{const{diagram:e}=await import("./sequenceDiagram-FGHM5R23-BICX7EKt.js");return{diagram:e}},__vite__mapDeps([31,9,18]),import.meta.url);return{id:pW,diagram:t}},"loader"),iMe={id:pW,detector:nMe,loader:rMe},sMe=iMe,gW="class",oMe=_((t,e)=>{var n;return((n=e==null?void 0:e.class)==null?void 0:n.defaultRenderer)==="dagre-wrapper"?!1:/^\s*classDiagram/.test(t)},"detector"),aMe=_(async()=>{const{diagram:t}=await et(async()=>{const{diagram:e}=await import("./classDiagram-6PBFFD2Q-BDSg69Gf.js");return{diagram:e}},__vite__mapDeps([32,33,11,9,12,13]),import.meta.url);return{id:gW,diagram:t}},"loader"),lMe={id:gW,detector:oMe,loader:aMe},cMe=lMe,mW="classDiagram",uMe=_((t,e)=>{var n;return/^\s*classDiagram/.test(t)&&((n=e==null?void 0:e.class)==null?void 0:n.defaultRenderer)==="dagre-wrapper"?!0:/^\s*classDiagram-v2/.test(t)},"detector"),hMe=_(async()=>{const{diagram:t}=await et(async()=>{const{diagram:e}=await import("./classDiagram-v2-HSJHXN6E-BDSg69Gf.js");return{diagram:e}},__vite__mapDeps([34,33,11,9,12,13]),import.meta.url);return{id:mW,diagram:t}},"loader"),dMe={id:mW,detector:uMe,loader:hMe},fMe=dMe,yW="state",pMe=_((t,e)=>{var n;return((n=e==null?void 0:e.state)==null?void 0:n.defaultRenderer)==="dagre-wrapper"?!1:/^\s*stateDiagram/.test(t)},"detector"),gMe=_(async()=>{const{diagram:t}=await et(async()=>{const{diagram:e}=await import("./stateDiagram-FHFEXIEX-cW0_yGa2.js");return{diagram:e}},__vite__mapDeps([35,36,12,13,1,2,3,4]),import.meta.url);return{id:yW,diagram:t}},"loader"),mMe={id:yW,detector:pMe,loader:gMe},yMe=mMe,xW="stateDiagram",xMe=_((t,e)=>{var n;return!!(/^\s*stateDiagram-v2/.test(t)||/^\s*stateDiagram/.test(t)&&((n=e==null?void 0:e.state)==null?void 0:n.defaultRenderer)==="dagre-wrapper")},"detector"),bMe=_(async()=>{const{diagram:t}=await et(async()=>{const{diagram:e}=await import("./stateDiagram-v2-QKLJ7IA2-BXRvCfMx.js");return{diagram:e}},__vite__mapDeps([37,36,12,13]),import.meta.url);return{id:xW,diagram:t}},"loader"),kMe={id:xW,detector:xMe,loader:bMe},wMe=kMe,bW="journey",vMe=_(t=>/^\s*journey/.test(t),"detector"),CMe=_(async()=>{const{diagram:t}=await et(async()=>{const{diagram:e}=await import("./journeyDiagram-VCZTEJTY-JZjg2VSV.js");return{diagram:e}},__vite__mapDeps([38,11,9,26]),import.meta.url);return{id:bW,diagram:t}},"loader"),SMe={id:bW,detector:vMe,loader:CMe},_Me=SMe,TMe=_((t,e,n)=>{J.debug(`rendering svg for syntax error
|
|
902
|
+
`);const r=Gve(e),i=r.append("g");r.attr("viewBox","0 0 2412 512"),W8(r,100,512,!0),i.append("path").attr("class","error-icon").attr("d","m411.313,123.313c6.25-6.25 6.25-16.375 0-22.625s-16.375-6.25-22.625,0l-32,32-9.375,9.375-20.688-20.688c-12.484-12.5-32.766-12.5-45.25,0l-16,16c-1.261,1.261-2.304,2.648-3.31,4.051-21.739-8.561-45.324-13.426-70.065-13.426-105.867,0-192,86.133-192,192s86.133,192 192,192 192-86.133 192-192c0-24.741-4.864-48.327-13.426-70.065 1.402-1.007 2.79-2.049 4.051-3.31l16-16c12.5-12.492 12.5-32.758 0-45.25l-20.688-20.688 9.375-9.375 32.001-31.999zm-219.313,100.687c-52.938,0-96,43.063-96,96 0,8.836-7.164,16-16,16s-16-7.164-16-16c0-70.578 57.422-128 128-128 8.836,0 16,7.164 16,16s-7.164,16-16,16z"),i.append("path").attr("class","error-icon").attr("d","m459.02,148.98c-6.25-6.25-16.375-6.25-22.625,0s-6.25,16.375 0,22.625l16,16c3.125,3.125 7.219,4.688 11.313,4.688 4.094,0 8.188-1.563 11.313-4.688 6.25-6.25 6.25-16.375 0-22.625l-16.001-16z"),i.append("path").attr("class","error-icon").attr("d","m340.395,75.605c3.125,3.125 7.219,4.688 11.313,4.688 4.094,0 8.188-1.563 11.313-4.688 6.25-6.25 6.25-16.375 0-22.625l-16-16c-6.25-6.25-16.375-6.25-22.625,0s-6.25,16.375 0,22.625l15.999,16z"),i.append("path").attr("class","error-icon").attr("d","m400,64c8.844,0 16-7.164 16-16v-32c0-8.836-7.156-16-16-16-8.844,0-16,7.164-16,16v32c0,8.836 7.156,16 16,16z"),i.append("path").attr("class","error-icon").attr("d","m496,96.586h-32c-8.844,0-16,7.164-16,16 0,8.836 7.156,16 16,16h32c8.844,0 16-7.164 16-16 0-8.836-7.156-16-16-16z"),i.append("path").attr("class","error-icon").attr("d","m436.98,75.605c3.125,3.125 7.219,4.688 11.313,4.688 4.094,0 8.188-1.563 11.313-4.688l32-32c6.25-6.25 6.25-16.375 0-22.625s-16.375-6.25-22.625,0l-32,32c-6.251,6.25-6.251,16.375-0.001,22.625z"),i.append("text").attr("class","error-text").attr("x",1440).attr("y",250).attr("font-size","150px").style("text-anchor","middle").text("Syntax error in text"),i.append("text").attr("class","error-text").attr("x",1250).attr("y",400).attr("font-size","100px").style("text-anchor","middle").text(`mermaid version ${n}`)},"draw"),kW={draw:TMe},EMe=kW,AMe={db:{},renderer:kW,parser:{parse:_(()=>{},"parse")}},NMe=AMe,wW="flowchart-elk",MMe=_((t,e={})=>{var n;return/^\s*flowchart-elk/.test(t)||/^\s*(flowchart|graph)/.test(t)&&((n=e==null?void 0:e.flowchart)==null?void 0:n.defaultRenderer)==="elk"?(e.layout="elk",!0):!1},"detector"),LMe=_(async()=>{const{diagram:t}=await et(async()=>{const{diagram:e}=await import("./flowDiagram-DWJPFMVM-DaMvV0c8.js");return{diagram:e}},__vite__mapDeps([10,11,9,12,13,14]),import.meta.url);return{id:wW,diagram:t}},"loader"),DMe={id:wW,detector:MMe,loader:LMe},OMe=DMe,vW="timeline",RMe=_(t=>/^\s*timeline/.test(t),"detector"),IMe=_(async()=>{const{diagram:t}=await et(async()=>{const{diagram:e}=await import("./timeline-definition-GMOUNBTQ-BFHBbQkD.js");return{diagram:e}},__vite__mapDeps([39,26]),import.meta.url);return{id:vW,diagram:t}},"loader"),BMe={id:vW,detector:RMe,loader:IMe},PMe=BMe,CW="mindmap",FMe=_(t=>/^\s*mindmap/.test(t),"detector"),$Me=_(async()=>{const{diagram:t}=await et(async()=>{const{diagram:e}=await import("./mindmap-definition-QFDTVHPH-BUSgUnqS.js");return{diagram:e}},__vite__mapDeps([40,12,13]),import.meta.url);return{id:CW,diagram:t}},"loader"),jMe={id:CW,detector:FMe,loader:$Me},zMe=jMe,SW="kanban",HMe=_(t=>/^\s*kanban/.test(t),"detector"),UMe=_(async()=>{const{diagram:t}=await et(async()=>{const{diagram:e}=await import("./kanban-definition-6JOO6SKY-C8GcL5aF.js");return{diagram:e}},__vite__mapDeps([41,11]),import.meta.url);return{id:SW,diagram:t}},"loader"),WMe={id:SW,detector:HMe,loader:UMe},qMe=WMe,_W="sankey",VMe=_(t=>/^\s*sankey(-beta)?/.test(t),"detector"),GMe=_(async()=>{const{diagram:t}=await et(async()=>{const{diagram:e}=await import("./sankeyDiagram-XADWPNL6-BIeDgqXh.js");return{diagram:e}},__vite__mapDeps([42,27,22]),import.meta.url);return{id:_W,diagram:t}},"loader"),YMe={id:_W,detector:VMe,loader:GMe},KMe=YMe,TW="packet",XMe=_(t=>/^\s*packet(-beta)?/.test(t),"detector"),ZMe=_(async()=>{const{diagram:t}=await et(async()=>{const{diagram:e}=await import("./diagram-TYMM5635-XBBjlYIc.js");return{diagram:e}},__vite__mapDeps([43,17,19,4,2]),import.meta.url);return{id:TW,diagram:t}},"loader"),QMe={id:TW,detector:XMe,loader:ZMe},EW="radar",JMe=_(t=>/^\s*radar-beta/.test(t),"detector"),e3e=_(async()=>{const{diagram:t}=await et(async()=>{const{diagram:e}=await import("./diagram-MMDJMWI5-DQKHCVNg.js");return{diagram:e}},__vite__mapDeps([44,17,19,4,2]),import.meta.url);return{id:EW,diagram:t}},"loader"),t3e={id:EW,detector:JMe,loader:e3e},AW="block",n3e=_(t=>/^\s*block(-beta)?/.test(t),"detector"),r3e=_(async()=>{const{diagram:t}=await et(async()=>{const{diagram:e}=await import("./blockDiagram-DXYQGD6D-Cf47SU_V.js");return{diagram:e}},__vite__mapDeps([45,11,5,1,2,14]),import.meta.url);return{id:AW,diagram:t}},"loader"),i3e={id:AW,detector:n3e,loader:r3e},s3e=i3e,NW="treeView",o3e=_(t=>/^\s*treeView-beta/.test(t),"detector"),a3e=_(async()=>{const{diagram:t}=await et(async()=>{const{diagram:e}=await import("./diagram-5BDNPKRD-CifPGnA5.js");return{diagram:e}},__vite__mapDeps([46,17,18,19,4,2]),import.meta.url);return{id:NW,diagram:t}},"loader"),l3e={id:NW,detector:o3e,loader:a3e},c3e=l3e,MW="architecture",u3e=_(t=>/^\s*architecture/.test(t),"detector"),h3e=_(async()=>{const{diagram:t}=await et(async()=>{const{diagram:e}=await import("./architectureDiagram-Q4EWVU46-CifAWdeJ.js");return{diagram:e}},__vite__mapDeps([47,17,19,4,2,7]),import.meta.url);return{id:MW,diagram:t}},"loader"),d3e={id:MW,detector:u3e,loader:h3e},f3e=d3e,LW="ishikawa",p3e=_(t=>/^\s*ishikawa(-beta)?\b/i.test(t),"detector"),g3e=_(async()=>{const{diagram:t}=await et(async()=>{const{diagram:e}=await import("./ishikawaDiagram-UXIWVN3A-DPI8hbB4.js");return{diagram:e}},[],import.meta.url);return{id:LW,diagram:t}},"loader"),m3e={id:LW,detector:p3e,loader:g3e},DW="venn",y3e=_(t=>/^\s*venn-beta/.test(t),"detector"),x3e=_(async()=>{const{diagram:t}=await et(async()=>{const{diagram:e}=await import("./vennDiagram-DHZGUBPP-Ck_7LdKT.js");return{diagram:e}},[],import.meta.url);return{id:DW,diagram:t}},"loader"),b3e={id:DW,detector:y3e,loader:x3e},k3e=b3e,OW="treemap",w3e=_(t=>/^\s*treemap/.test(t),"detector"),v3e=_(async()=>{const{diagram:t}=await et(async()=>{const{diagram:e}=await import("./diagram-G4DWMVQ6-CO324vbS.js");return{diagram:e}},__vite__mapDeps([48,13,17,19,4,2,23,27,22]),import.meta.url);return{id:OW,diagram:t}},"loader"),C3e={id:OW,detector:w3e,loader:v3e},RW="wardley-beta",S3e=_(t=>/^\s*wardley-beta/i.test(t),"detector"),_3e=_(async()=>{const{diagram:t}=await et(async()=>{const{diagram:e}=await import("./wardleyDiagram-NUSXRM2D-BRdXdErY.js");return{diagram:e}},__vite__mapDeps([49,17,19,4,2]),import.meta.url);return{id:RW,diagram:t}},"loader"),T3e={id:RW,detector:S3e,loader:_3e},E3e=T3e,hR=!1,W1=_(()=>{hR||(hR=!0,hx("error",NMe,t=>t.toLowerCase().trim()==="error"),hx("---",{db:{clear:_(()=>{},"clear")},styles:{},renderer:{draw:_(()=>{},"draw")},parser:{parse:_(()=>{throw new Error("Diagrams beginning with --- are not valid. If you were trying to use a YAML front-matter, please ensure that you've correctly opened and closed the YAML front-matter with un-indented `---` blocks")},"parse")},init:_(()=>null,"init")},t=>t.toLowerCase().trimStart().startsWith("---")),E2(OMe,zMe,f3e),E2(yNe,qMe,fMe,cMe,NNe,PNe,jNe,UNe,tMe,sMe,_Ne,wNe,PMe,ONe,wMe,yMe,_Me,GNe,KMe,QMe,ZNe,s3e,c3e,t3e,m3e,C3e,k3e,E3e))},"addDiagrams"),A3e=_(async()=>{J.debug("Loading registered diagrams");const e=(await Promise.allSettled(Object.entries(bc).map(async([n,{detector:r,loader:i}])=>{if(i)try{L2(n)}catch{try{const{diagram:s,id:o}=await i();hx(o,s,r)}catch(s){throw J.error(`Failed to load external diagram with key ${n}. Removing from detectors.`),delete bc[n],s}}}))).filter(n=>n.status==="rejected");if(e.length>0){J.error(`Failed to load ${e.length} external diagrams`);for(const n of e)J.error(n);throw new Error(`Failed to load ${e.length} external diagrams`)}},"loadRegisteredDiagrams"),N3e="graphics-document document";function IW(t,e){t.attr("role",N3e),e!==""&&t.attr("aria-roledescription",e)}_(IW,"setA11yDiagramInfo");function BW(t,e,n,r){if(t.insert!==void 0){if(n){const i=`chart-desc-${r}`;t.attr("aria-describedby",i),t.insert("desc",":first-child").attr("id",i).text(n)}if(e){const i=`chart-title-${r}`;t.attr("aria-labelledby",i),t.insert("title",":first-child").attr("id",i).text(e)}}}_(BW,"addSVGa11yTitleDescription");var lc,_S=(lc=class{constructor(e,n,r,i,s){this.type=e,this.text=n,this.db=r,this.parser=i,this.renderer=s}static async fromText(e,n={}){var c,u;const r=Gt(),i=ME(e,r);e=Q_e(e)+`
|
|
903
903
|
`;try{L2(i)}catch{const h=dbe(i);if(!h)throw new M8(`Diagram ${i} not found.`);const{id:f,diagram:d}=await h();hx(f,d)}const{db:s,parser:o,renderer:a,init:l}=L2(i);return o.parser&&(o.parser.yy=s),(c=s.clear)==null||c.call(s),l==null||l(r),n.title&&((u=s.setDiagramTitle)==null||u.call(s,n.title)),await o.parse(e),new lc(i,e,s,o,a)}async render(e,n){await this.renderer.draw(this.text,e,n,this)}getParser(){return this.parser}getType(){return this.type}},_(lc,"Diagram"),lc),dR=[],M3e=_(()=>{dR.forEach(t=>{t()}),dR=[]},"attachFunctions"),L3e=_(t=>t.replace(/^\s*%%(?!{)[^\n]+\n?/gm,"").trimStart(),"cleanupComments");function PW(t){const e=t.match(N8);if(!e)return{text:t,metadata:{}};let n=e2e(e[1],{schema:JCe})??{};n=typeof n=="object"&&!Array.isArray(n)?n:{};const r={};return n.displayMode&&(r.displayMode=n.displayMode.toString()),n.title&&(r.title=n.title.toString()),n.config&&(r.config=n.config),{text:t.slice(e[0].length),metadata:r}}_(PW,"extractFrontMatter");var D3e=_(t=>t.replace(/\r\n?/g,`
|
|
904
904
|
`).replace(/<(\w+)([^>]*)>/g,(e,n,r)=>"<"+n+r.replace(/="([^"]*)"/g,"='$1'")+">"),"cleanupText"),O3e=_(t=>{const{text:e,metadata:n}=PW(t),{displayMode:r,title:i,config:s={}}=n;return r&&(s.gantt||(s.gantt={}),s.gantt.displayMode=r),{title:i,config:s,text:e}},"processFrontmatter"),R3e=_(t=>{const e=Qi.detectInit(t)??{},n=Qi.detectDirective(t,"wrap");return Array.isArray(n)?e.wrap=n.some(({type:r})=>r==="wrap"):(n==null?void 0:n.type)==="wrap"&&(e.wrap=!0),{text:$_e(t),directive:e}},"processDirectives");function AA(t){const e=D3e(t),n=O3e(e),r=R3e(n.text),i=hA(n.config,r.directive);return t=L3e(r.text),{code:t,title:n.title,config:i}}_(AA,"preprocessDiagram");function FW(t){const e=new TextEncoder().encode(t),n=Array.from(e,r=>String.fromCodePoint(r)).join("");return btoa(n)}_(FW,"toBase64");var I3e=5e4,B3e="graph TB;a[Maximum text size in diagram exceeded];style a fill:#faa",P3e="sandbox",F3e="loose",$3e="http://www.w3.org/2000/svg",j3e="http://www.w3.org/1999/xlink",z3e="http://www.w3.org/1999/xhtml",H3e="100%",U3e="100%",W3e="border:0;margin:0;",q3e="margin:0",V3e="allow-top-navigation-by-user-activation allow-popups",G3e='The "iframe" tag is not supported by your browser.',Y3e=["foreignobject"],K3e=["dominant-baseline"];function NA(t){const e=AA(t);return cx(),jbe(e.config??{}),e}_(NA,"processAndSetConfigs");async function $W(t,e){W1();try{const{code:n,config:r}=NA(t);return{diagramType:(await zW(n)).type,config:r}}catch(n){if(e!=null&&e.suppressErrors)return!1;throw n}}_($W,"parse");var fR=_((t,e,n=[])=>`
|
|
905
905
|
.${t} ${e} { ${n.join(" !important; ")} !important; }`,"cssImportantStyles"),X3e=_((t,e=new Map)=>{let n="";if(t.themeCSS!==void 0&&(n+=`
|
|
@@ -1112,7 +1112,7 @@ ${n}
|
|
|
1112
1112
|
`):"",markdownTokenizer:{name:"taskList",level:"block",start(t){var e;const n=(e=t.match(/^\s*[-+*]\s+\[([ xX])\]\s+/))==null?void 0:e.index;return n!==void 0?n:-1},tokenize(t,e,n){const r=s=>{const o=e_(s,{itemPattern:/^(\s*)([-+*])\s+\[([ xX])\]\s+(.*)$/,extractItemData:a=>({indentLevel:a[1].length,mainContent:a[4],checked:a[3].toLowerCase()==="x"}),createToken:(a,l)=>({type:"taskItem",raw:"",mainContent:a.mainContent,indentLevel:a.indentLevel,checked:a.checked,text:a.mainContent,tokens:n.inlineTokens(a.mainContent),nestedTokens:l}),customNestedParser:r},n);return o?[{type:"taskList",raw:o.raw,items:o.items}]:n.blockTokens(s)},i=e_(t,{itemPattern:/^(\s*)([-+*])\s+\[([ xX])\]\s+(.*)$/,extractItemData:s=>({indentLevel:s[1].length,mainContent:s[4],checked:s[3].toLowerCase()==="x"}),createToken:(s,o)=>({type:"taskItem",raw:"",mainContent:s.mainContent,indentLevel:s.indentLevel,checked:s.checked,text:s.mainContent,tokens:n.inlineTokens(s.mainContent),nestedTokens:o}),customNestedParser:r},n);if(i)return{type:"taskList",raw:i.raw,items:i.items}}},markdownOptions:{indentsContent:!0},addCommands(){return{toggleTaskList:()=>({commands:t})=>t.toggleList(this.name,this.options.itemTypeName)}},addKeyboardShortcuts(){return{"Mod-Shift-9":()=>this.editor.commands.toggleTaskList()}}});Pt.create({name:"listKit",addExtensions(){const t=[];return this.options.bulletList!==!1&&t.push(WG.configure(this.options.bulletList)),this.options.listItem!==!1&&t.push(qG.configure(this.options.listItem)),this.options.listKeymap!==!1&&t.push(ZG.configure(this.options.listKeymap)),this.options.orderedList!==!1&&t.push(JG.configure(this.options.orderedList)),this.options.taskItem!==!1&&t.push(O6e.configure(this.options.taskItem)),this.options.taskList!==!1&&t.push(R6e.configure(this.options.taskList)),t}});var l0=" ",Rv=" ",I6e=ot.create({name:"paragraph",priority:1e3,addOptions(){return{HTMLAttributes:{}}},group:"block",content:"inline*",parseHTML(){return[{tag:"p"}]},renderHTML({HTMLAttributes:t}){return["p",xt(this.options.HTMLAttributes,t),0]},parseMarkdown:(t,e)=>{const n=t.tokens||[];if(n.length===1&&n[0].type==="image")return e.parseChildren([n[0]]);const r=e.parseInline(n);return n.length===1&&n[0].type==="text"&&(n[0].raw===l0||n[0].text===l0||n[0].raw===Rv||n[0].text===Rv)&&r.length===1&&r[0].type==="text"&&(r[0].text===l0||r[0].text===Rv)?e.createNode("paragraph",void 0,[]):e.createNode("paragraph",void 0,r)},renderMarkdown:(t,e,n)=>{var r,i;if(!t)return"";const s=Array.isArray(t.content)?t.content:[];if(s.length===0){const o=Array.isArray((r=n==null?void 0:n.previousNode)==null?void 0:r.content)?n.previousNode.content:[];return((i=n==null?void 0:n.previousNode)==null?void 0:i.type)==="paragraph"&&o.length===0?l0:""}return e.renderChildren(s)},addCommands(){return{setParagraph:()=>({commands:t})=>t.setNode(this.name)}},addKeyboardShortcuts(){return{"Mod-Alt-0":()=>this.editor.commands.setParagraph()}}}),B6e=/(?:^|\s)(~~(?!\s+~~)((?:[^~]+))~~(?!\s+~~))$/,P6e=/(?:^|\s)(~~(?!\s+~~)((?:[^~]+))~~(?!\s+~~))/g,F6e=bi.create({name:"strike",addOptions(){return{HTMLAttributes:{}}},parseHTML(){return[{tag:"s"},{tag:"del"},{tag:"strike"},{style:"text-decoration",consuming:!1,getAttrs:t=>t.includes("line-through")?{}:!1}]},renderHTML({HTMLAttributes:t}){return["s",xt(this.options.HTMLAttributes,t),0]},markdownTokenName:"del",parseMarkdown:(t,e)=>e.applyMark("strike",e.parseInline(t.tokens||[])),renderMarkdown:(t,e)=>`~~${e.renderChildren(t)}~~`,addCommands(){return{setStrike:()=>({commands:t})=>t.setMark(this.name),toggleStrike:()=>({commands:t})=>t.toggleMark(this.name),unsetStrike:()=>({commands:t})=>t.unsetMark(this.name)}},addKeyboardShortcuts(){return{"Mod-Shift-s":()=>this.editor.commands.toggleStrike()}},addInputRules(){return[jh({find:B6e,type:this.type})]},addPasteRules(){return[Lc({find:P6e,type:this.type})]}}),$6e=ot.create({name:"text",group:"inline",parseMarkdown:t=>({type:"text",text:t.text||""}),renderMarkdown:t=>t.text||""}),j6e=bi.create({name:"underline",addOptions(){return{HTMLAttributes:{}}},parseHTML(){return[{tag:"u"},{style:"text-decoration",consuming:!1,getAttrs:t=>t.includes("underline")?{}:!1}]},renderHTML({HTMLAttributes:t}){return["u",xt(this.options.HTMLAttributes,t),0]},parseMarkdown(t,e){return e.applyMark(this.name||"underline",e.parseInline(t.tokens||[]))},renderMarkdown(t,e){return`++${e.renderChildren(t)}++`},markdownTokenizer:{name:"underline",level:"inline",start(t){return t.indexOf("++")},tokenize(t,e,n){const i=/^(\+\+)([\s\S]+?)(\+\+)/.exec(t);if(!i)return;const s=i[2].trim();return{type:"underline",raw:i[0],text:s,tokens:n.inlineTokens(s)}}},addCommands(){return{setUnderline:()=>({commands:t})=>t.setMark(this.name),toggleUnderline:()=>({commands:t})=>t.toggleMark(this.name),unsetUnderline:()=>({commands:t})=>t.unsetMark(this.name)}},addKeyboardShortcuts(){return{"Mod-u":()=>this.editor.commands.toggleUnderline(),"Mod-U":()=>this.editor.commands.toggleUnderline()}}}),z6e=Pt.create({name:"starterKit",addExtensions(){var t,e,n,r;const i=[];return this.options.bold!==!1&&i.push(IPe.configure(this.options.bold)),this.options.blockquote!==!1&&i.push(MPe.configure(this.options.blockquote)),this.options.bulletList!==!1&&i.push(WG.configure(this.options.bulletList)),this.options.code!==!1&&i.push(FPe.configure(this.options.code)),this.options.codeBlock!==!1&&i.push(zPe.configure(this.options.codeBlock)),this.options.document!==!1&&i.push(HPe.configure(this.options.document)),this.options.dropcursor!==!1&&i.push(kBe.configure(this.options.dropcursor)),this.options.gapcursor!==!1&&i.push(wBe.configure(this.options.gapcursor)),this.options.hardBreak!==!1&&i.push(UPe.configure(this.options.hardBreak)),this.options.heading!==!1&&i.push(WPe.configure(this.options.heading)),this.options.undoRedo!==!1&&i.push(TBe.configure(this.options.undoRedo)),this.options.horizontalRule!==!1&&i.push(qPe.configure(this.options.horizontalRule)),this.options.italic!==!1&&i.push(XPe.configure(this.options.italic)),this.options.listItem!==!1&&i.push(qG.configure(this.options.listItem)),this.options.listKeymap!==!1&&i.push(ZG.configure((t=this.options)==null?void 0:t.listKeymap)),this.options.link!==!1&&i.push(UG.configure((e=this.options)==null?void 0:e.link)),this.options.orderedList!==!1&&i.push(JG.configure(this.options.orderedList)),this.options.paragraph!==!1&&i.push(I6e.configure(this.options.paragraph)),this.options.strike!==!1&&i.push(F6e.configure(this.options.strike)),this.options.text!==!1&&i.push($6e.configure(this.options.text)),this.options.underline!==!1&&i.push(j6e.configure((n=this.options)==null?void 0:n.underline)),this.options.trailingNode!==!1&&i.push(_Be.configure((r=this.options)==null?void 0:r.trailingNode)),i}}),eY=z6e;const H6e="@[__display__](__id__)",U6e="[[wf:__id__|__display__]]",W6e=/\[\[wf:([^|\]]+)\|([^\]]*)\]\]/g,q6e=/@\[((?:[^\]]|\\])*)\]\(([^)]*)\)|\[\[wf:([^|\]]+)\|([^\]]*)\]\]|\n/g,V6e=new Ct("mention-input-agent-suggestion"),G6e=new Ct("mention-input-workflow-suggestion");function c0(t){return t.trim().toLowerCase().replace(/\s+/g," ")}function Y6e(t,e){let n=0;for(const r of e)if(r===t[n]&&(n+=1,n===t.length))return!0;return t.length===0}function K6e(t,e){const n=c0(e);if(!n)return 1;const r=c0(t.id),i=c0(t.name),s=c0(t.description),o=[r,i,s].filter(Boolean);return r===n?100:i===n?95:r.startsWith(n)?90:i.startsWith(n)?85:o.some(a=>a.includes(n))?70:o.some(a=>Y6e(n,a.replace(/\s+/g,"")))?40:0}function Lb(t,e,n){return{type:"agentWorkflowMention",attrs:{id:e,label:n,kind:t,mentionSuggestionChar:t==="agent"?"@":"/"}}}function o4(t,e){if(!e)return;const n=t[t.length-1];if((n==null?void 0:n.type)==="text"){n.text=`${n.text??""}${e}`;return}t.push({type:"text",text:e})}function a4(t){const e=[];let n=0;return t.replace(q6e,(r,i,s,o,a,l)=>(o4(e,t.slice(n,l)),r===`
|
|
1113
1113
|
`?e.push({type:"hardBreak"}):s?e.push(Lb("agent",s,i)):o&&e.push(Lb("workflow",o,a||o)),n=l+r.length,r)),o4(e,t.slice(n)),{type:"doc",content:[{type:"paragraph",content:e.length>0?e:void 0}]}}function X6e(t){const e=t.attrs??{},n=String(e.id??""),r=String(e.label??n);return(e.kind==="workflow"?"workflow":"agent")==="workflow"?`[[wf:${n}|${r}]]`:`@[${r}](${n})`}function tY(t){if(!t)return"";switch(t.type){case"text":return t.text??"";case"hardBreak":return`
|
|
1114
1114
|
`;case"agentWorkflowMention":return X6e(t);default:return(t.content??[]).map(e=>tY(e)).join("")}}function l4(t){return(t.content??[]).map(e=>tY(e)).join(`
|
|
1115
|
-
`)}function sy(t){return t.replace(/@\[([^\]]*)\]\(([^)]*)\)/g,"@$2").replace(W6e,"/wf $1")}function Z6e(t){return H6e.replace("__display__",t.name).replace("__id__",t.id)+" "}function Q6e(t){return U6e.replace("__id__",t.id).replace("__display__",t.name)+" "}function J6e(t){const e=t.match(/\[\[wf:([^|\]]+)\|[^\]]*\]\]/);if(e!=null&&e[1])return e[1];const n=sy(t).match(/(?:^|\s)\/wf\s+([^\s]+)/);return(n==null?void 0:n[1])??null}function eFe({$position:t}){var l;const e=(l=t.nodeBefore)!=null&&l.isText?t.nodeBefore.text??"":"";if(!e)return null;const n=t.pos-e.length,r=/(?:^|\s)(\/wf(?:\s+([^\n]*))?)$/.exec(e);if(!r||r.index===void 0)return null;const i=r[1]??"",s=r[2]??"",o=n+r.index+r[0].length-i.length,a=o+i.length;return o<t.pos&&a>=t.pos?{range:{from:o,to:a},query:s,text:i}:null}function tFe(t,e){const n=document.createElement("button");if(n.type="button",n.setAttribute("role","option"),n.setAttribute("aria-selected",e?"true":"false"),n.className="flex w-full cursor-pointer items-start gap-3 px-3 py-2 text-left transition-colors "+(e?"bg-blue-50":"bg-transparent hover:bg-gray-50"),t.kind==="workflow"){const s=document.createElement("span");s.className="mt-0.5 inline-flex h-5 min-w-5 items-center justify-center rounded-full bg-blue-600 px-1.5 text-[10px] font-semibold uppercase tracking-wide text-white",s.textContent="wf",n.append(s)}const r=document.createElement("span");r.className="min-w-0 flex-1";const i=document.createElement("span");if(i.className="block truncate text-sm font-medium "+(e?"text-blue-700":"text-gray-900"),i.textContent=t.kind==="workflow"?t.label:`@${t.label}`,r.append(i),t.description||t.secondary){const s=document.createElement("span");s.className="mt-0.5 block truncate text-xs text-gray-500",s.textContent=t.secondary&&t.description?`${t.secondary} · ${t.description}`:t.secondary||t.description||"",r.append(s)}return n.append(r),n}function c4(t){return()=>{let e=null,n=null,r=null,i=0,s=null;const o=()=>{s==null||s(),s=null,e==null||e.remove(),e=null,n=null,r=null,i=0,t.onVisibilityChange(!1)},a=()=>{if(!e||!(r!=null&&r.clientRect))return;const h=r.clientRect();if(!h)return;const f=e.offsetWidth||320,d=e.offsetHeight||0,p=Math.min(Math.max(12,h.left),Math.max(12,window.innerWidth-f-12)),m=h.bottom+8,y=Math.min(m,Math.max(12,window.innerHeight-d-12));e.style.left=`${p}px`,e.style.top=`${y}px`},l=h=>{if(!r)return;const f=r.items[h];f&&r.command(f)},c=()=>{if(!(!n||!r)){if(n.replaceChildren(),n.setAttribute("aria-label",t.label()),r.items.length===0){const h=document.createElement("div");h.className="px-3 py-2 text-sm text-gray-400",h.textContent=t.emptyLabel(),n.append(h),requestAnimationFrame(a);return}r.items.forEach((h,f)=>{const d=tFe(h,f===i);d.addEventListener("mousedown",p=>{p.preventDefault(),l(f)}),n==null||n.append(d)}),requestAnimationFrame(a)}},u=h=>{!r||r.items.length===0||(i=(i+h+r.items.length)%r.items.length,c())};return{onStart(h){r=h,i=0,e=document.createElement("div"),e.className="fixed z-[100] min-w-[320px] max-w-[360px] overflow-hidden rounded-xl border border-gray-200 bg-white shadow-lg",n=document.createElement("div"),n.setAttribute("role","listbox"),n.className="max-h-72 overflow-y-auto py-1",e.append(n),document.body.append(e);const f=d=>{const p=d.target;if(!(p instanceof Node)||e!=null&&e.contains(p))return;const m=r==null?void 0:r.editor.view.dom;m!=null&&m.contains(p)||o()};document.addEventListener("pointerdown",f,!0),s=()=>{document.removeEventListener("pointerdown",f,!0)},t.onVisibilityChange(!0),c()},onUpdate(h){r=h,i>=h.items.length&&(i=0),c()},onExit(){o()},onKeyDown({event:h}){return r?h.key==="ArrowDown"?(h.preventDefault(),u(1),!0):h.key==="ArrowUp"?(h.preventDefault(),u(-1),!0):h.key==="Enter"?r.items.length===0?!1:(h.preventDefault(),l(i),!0):h.key==="Escape"?(h.preventDefault(),o(),!0):!1:!1}}}}const nFe=tBe.extend({name:"agentWorkflowMention",addAttributes(){var t;return{...(t=this.parent)==null?void 0:t.call(this),kind:{default:"agent",parseHTML:e=>e.getAttribute("data-kind")??"agent",renderHTML:e=>({"data-kind":String(e.kind??"agent")})}}},renderText({node:t}){const e=t.attrs.kind==="workflow"?"workflow":"agent",n=String(t.attrs.id??""),r=String(t.attrs.label??n);return e==="workflow"?`/wf ${n}`:`@${r}`},renderHTML({node:t,HTMLAttributes:e}){const n=t.attrs.kind==="workflow"?"workflow":"agent",r=String(t.attrs.id??""),i=String(t.attrs.label??r);return["span",{...e,class:n==="workflow"?"inline-flex items-center rounded-full bg-blue-50 px-2 py-0.5 text-xs font-medium text-blue-700":"inline-flex items-center rounded-full bg-blue-100 px-2 py-0.5 text-xs font-semibold text-blue-700","data-testid":n==="workflow"?"workflow-chip":"mention-chip"},n==="workflow"?`/wf ${r}`:`@${i}`]}});function u4({value:t,onChange:e,onSend:n,agents:r,workflows:i=[],placeholder:s,disabled:o=!1,multiline:a=!1,className:l="",inputRef:c}){const{t:u}=me(),h=T.useRef(null),f=T.useRef(e),d=T.useRef(n),p=T.useRef(r),m=T.useRef(i),y=T.useRef(u("workflow.mentionLabel")),x=T.useRef(u("workflow.noSuggestions")),b=T.useRef(!1);f.current=e,d.current=n,p.current=r,m.current=i,y.current=u("workflow.mentionLabel"),x.current=u("workflow.noSuggestions");const k=T.useCallback(S=>{b.current=S},[]),w=T.useMemo(()=>[eY.configure({heading:!1,blockquote:!1,bulletList:!1,orderedList:!1,listItem:!1,code:!1,codeBlock:!1,horizontalRule:!1}),_G.configure({placeholder:s??""}),nFe.configure({suggestions:[{char:"@",pluginKey:V6e,items:({query:S})=>{const E=S.trim().toLowerCase();return p.current.filter(M=>E?M.id.toLowerCase().includes(E)||M.name.toLowerCase().includes(E):!0).map(M=>({id:M.id,label:M.name,kind:"agent",description:[M.role,M.team].filter(Boolean).join(" · ")}))},render:c4({label:()=>y.current,emptyLabel:()=>x.current,onVisibilityChange:k}),command:({editor:S,range:E,props:M})=>{S.chain().focus().insertContentAt(E,[Lb("agent",M.id,M.label),{type:"text",text:" "}]).run()}},{char:"/",pluginKey:G6e,findSuggestionMatch:eFe,items:({query:S})=>m.current.map(E=>({workflow:E,score:K6e(E,S)})).filter(E=>E.score>0).sort((E,M)=>M.score-E.score||E.workflow.name.localeCompare(M.workflow.name)).slice(0,8).map(E=>({id:E.workflow.id,label:`/wf ${E.workflow.id}`,kind:"workflow",description:E.workflow.description,secondary:E.workflow.name})),render:c4({label:()=>y.current,emptyLabel:()=>x.current,onVisibilityChange:k}),command:({editor:S,range:E,props:M})=>{const A=m.current.find(B=>B.id===M.id);S.chain().focus().insertContentAt(E,[Lb("workflow",M.id,(A==null?void 0:A.name)??M.id),{type:"text",text:" "}]).run()}}]})],[k,s]),v=NG({immediatelyRender:!1,extensions:w,content:a4(t),editable:!o,editorProps:{attributes:{class:["focus:outline-none","text-sm","text-gray-900","break-words","[&_.is-editor-empty:first-child::before]:pointer-events-none","[&_.is-editor-empty:first-child::before]:float-left","[&_.is-editor-empty:first-child::before]:h-0","[&_.is-editor-empty:first-child::before]:text-gray-400","[&_.is-editor-empty:first-child::before]:content-[attr(data-placeholder)]",a?"min-h-[56px] max-h-[168px] overflow-y-auto px-4 py-3 whitespace-pre-wrap":"h-10 overflow-x-auto whitespace-nowrap px-4 py-[9px]"].join(" "),"data-testid":"mention-input-editor","aria-label":s||u("workflow.mentionLabel"),"aria-multiline":a?"true":"false",role:"textbox",placeholder:s??""},handleKeyDown:(S,E)=>{var M;return E.key==="Enter"&&!E.shiftKey?b.current?!1:(E.preventDefault(),(M=d.current)==null||M.call(d),!0):!a&&E.key==="Enter"?(E.preventDefault(),!0):!1}},onUpdate({editor:S}){const E=l4(S.getJSON());h.current=E,f.current(E)}},[w,o,a]);T.useEffect(()=>{v&&v.setEditable(!o)},[o,v]),T.useEffect(()=>{if(!v)return;const S=l4(v.getJSON());t===S||t===h.current||(v.commands.setContent(a4(t),{emitUpdate:!1}),h.current=t)},[v,t]);const C=["relative w-full border border-gray-200 bg-white transition-shadow",a?"rounded-xl":"rounded-md","focus-within:border-transparent focus-within:ring-2 focus-within:ring-blue-500",o?"pointer-events-none opacity-50":"",l].filter(Boolean).join(" ");return g.jsxs("div",{className:C,children:[c?g.jsx("textarea",{ref:c,tabIndex:-1,"aria-hidden":"true",className:"sr-only",onFocus:()=>{v==null||v.chain().focus("end").run()},readOnly:!0}):null,g.jsx(dN,{editor:v})]})}function rFe(){var t;return typeof window<"u"&&typeof((t=window.electronAPI)==null?void 0:t.captureScreen)=="function"}function SN({onSend:t,onCapture:e,disabled:n,activeAgent:r,value:i,onChange:s,agents:o,workflows:a,placeholder:l,sendLabel:c,multiline:u=!1,inputRef:h,variant:f="docked",className:d="",storageKey:p}){var Ve;const{t:m}=me(),[y,x]=T.useState(""),[b,k]=T.useState("query"),[w,v]=T.useState([]),[C,S]=T.useState(!1),[E,M]=T.useState(!1),A=T.useRef(null),B=nr(te=>te.workflows),F=nr(te=>te.fetchWorkflows),z=Pa(te=>{var $e;return p?(($e=te.chat.threads[p])==null?void 0:$e.mode)??"query":"query"}),D=Pa(te=>te.set),O=rFe(),N=i??y,$=o??w,I=a??B,P=p?z:b,L=T.useCallback(te=>{if(s){s(te);return}x(te)},[s]);T.useEffect(()=>{o||fe.getAgents().then(te=>v(te.agents)).catch(()=>v([]))},[o]),T.useEffect(()=>{a||F().catch(()=>{})},[F,a]),T.useEffect(()=>{if(!E)return;const te=ee=>{var ge;(ge=A.current)!=null&&ge.contains(ee.target)||M(!1)},$e=ee=>{ee.key==="Escape"&&(ee.preventDefault(),M(!1))};return window.addEventListener("mousedown",te),window.addEventListener("keydown",$e),()=>{window.removeEventListener("mousedown",te),window.removeEventListener("keydown",$e)}},[E]),T.useEffect(()=>{n&&M(!1)},[n]);const W=T.useMemo(()=>{const te=J6e(N);return I.find($e=>$e.id===te)??null},[N,I]),G=T.useMemo(()=>[{value:"query",label:m("taskDetail.inputModeQuery")},{value:"execute",label:m("taskDetail.inputModeExecute")}],[m]),j=((Ve=G.find(te=>te.value===P))==null?void 0:Ve.label)??G[0].label,V=u?"!border-0 !shadow-none !bg-transparent focus-within:!border-transparent focus-within:!ring-0 !rounded-none":"flex-1 shadow-sm",Z=T.useCallback(async()=>{const te=N.trim();if(!te||n)return;const $e=sy(te),ee=$e.match(/^@(\S+)\s+([\s\S]+)/),ge=(ee==null?void 0:ee[1])||r||"",ze=(ee==null?void 0:ee[2])??$e;await t(ze,ge,P)!==!1&&L("")},[r,n,N,P,t,L]),re=T.useCallback(async()=>{var te,$e;if(!C){S(!0);try{const ee=await(($e=(te=window.electronAPI)==null?void 0:te.captureScreen)==null?void 0:$e.call(te));ee!=null&&ee.success&&e&&e(ee)}finally{S(!1)}}},[C,e]),ve=T.useCallback(te=>{if(!p){k(te);return}const $e=Pa.getState().chat.threads,{[p]:ee,...ge}=$e;let ze={...ge,[p]:{mode:te}};const ce=Object.keys(ze);ce.length>Hy&&(ze=Object.fromEntries(ce.slice(ce.length-Hy).map(Ut=>[Ut,ze[Ut]]))),D("chat",{threads:ze})},[D,p]),Ee=[f==="standalone"?"w-full":"shrink-0 border-t border-gray-200 bg-gray-50 px-5 py-3",d].filter(Boolean).join(" "),qe=u?["w-full rounded-2xl border border-gray-200 bg-white shadow-sm transition-shadow","focus-within:border-blue-400 focus-within:ring-2 focus-within:ring-blue-500/20",n?"opacity-60":""].filter(Boolean).join(" "):"flex items-center gap-2";if(!u)return g.jsx("div",{className:Ee,children:g.jsx("div",{className:qe,children:g.jsx(be,{})})});return g.jsx("div",{className:Ee,children:g.jsxs("div",{className:qe,children:[g.jsxs("div",{className:"relative min-w-0",children:[W&&g.jsxs("div",{className:"pointer-events-none absolute bottom-full left-0 mb-2 flex items-center gap-2 rounded-lg bg-gray-900 px-3 py-2 text-xs text-white shadow-lg",children:[g.jsx(wh,{size:13,className:"text-blue-300"}),g.jsx("span",{className:"max-w-[420px] truncate",children:W.description||m("workflow.selectedLabel",{id:W.id})})]}),g.jsx(u4,{value:N,onChange:L,onSend:Z,agents:$,workflows:I,placeholder:l??(r?m("taskDetail.inputPlaceholderActive",{agent:r}):m("taskDetail.inputPlaceholder")),disabled:n,multiline:!0,inputRef:h,className:V})]}),g.jsxs("div",{className:"flex items-center gap-2 rounded-b-2xl border-t border-gray-100 bg-gray-50/50 px-3 py-2",children:[g.jsx(he,{}),O&&g.jsx("button",{onClick:re,disabled:n||C,className:"inline-flex h-8 w-8 items-center justify-center rounded-md text-gray-400 transition-colors hover:bg-gray-100 hover:text-gray-600 disabled:cursor-not-allowed disabled:opacity-40",title:m("taskDetail.captureScreen"),"aria-label":m("taskDetail.captureScreen"),children:g.jsx(R3,{size:16})}),g.jsx("div",{className:"flex-1"}),g.jsx("button",{onClick:Z,disabled:n||!sy(N).trim(),className:"inline-flex h-8 shrink-0 items-center justify-center rounded-md bg-blue-600 px-4 text-sm font-medium text-white shadow-sm transition-colors hover:bg-blue-500 disabled:cursor-not-allowed disabled:opacity-40",children:c??m("taskDetail.send")})]})]})});function he(){return g.jsxs("div",{ref:A,className:"relative shrink-0",children:[g.jsxs("button",{type:"button",onMouseDown:te=>te.preventDefault(),onClick:()=>{n||M(te=>!te)},disabled:n,"aria-expanded":E,"aria-haspopup":"listbox",className:["inline-flex h-8 items-center justify-between gap-1 rounded-md border px-2.5 text-xs font-medium transition-all duration-150",P==="execute"?"border-red-200 bg-red-50 text-red-700 hover:border-red-300 hover:bg-red-100":"border-gray-200 bg-white text-gray-700 hover:border-gray-300 hover:bg-gray-50",n?"cursor-not-allowed opacity-40":""].filter(Boolean).join(" "),children:[g.jsx("span",{className:"truncate",children:j}),g.jsx(Yr,{size:12,className:`shrink-0 transition-transform duration-150 ${E?"rotate-180":""}`})]}),g.jsx("div",{role:"listbox","aria-hidden":!E,className:["absolute bottom-full left-0 z-20 mb-2 w-32 origin-bottom-left rounded-lg border bg-white p-1 shadow-lg transition-all duration-150",E?"pointer-events-auto translate-y-0 scale-100 opacity-100":"pointer-events-none translate-y-1 scale-95 opacity-0",P==="execute"?"border-red-200":"border-gray-200"].filter(Boolean).join(" "),children:G.map(te=>{const $e=te.value===P;return g.jsx("button",{type:"button",role:"option","aria-selected":$e,onMouseDown:ee=>ee.preventDefault(),onClick:()=>{ve(te.value),M(!1)},className:["flex w-full items-center rounded-md px-3 py-2 text-left text-xs font-medium transition-colors duration-150",$e?te.value==="execute"?"bg-red-50 text-red-700":"bg-gray-100 text-gray-900":te.value==="execute"?"text-gray-700 hover:bg-red-50 hover:text-red-700":"text-gray-700 hover:bg-gray-50 hover:text-gray-900"].join(" "),children:te.label},te.value)})})]})}function be(){return g.jsxs(g.Fragment,{children:[g.jsxs("div",{ref:A,className:"relative shrink-0",children:[g.jsxs("button",{type:"button",onMouseDown:te=>te.preventDefault(),onClick:()=>{n||M(te=>!te)},disabled:n,"aria-expanded":E,"aria-haspopup":"listbox",className:["inline-flex h-10 w-24 items-center justify-between gap-1.5 rounded-md border px-3 text-sm font-medium shadow-sm transition-all duration-150",P==="execute"?"border-red-200 bg-red-50 text-red-700 hover:border-red-300 hover:bg-red-100":"border-gray-200 bg-white text-gray-700 hover:border-gray-300 hover:bg-gray-50",E?"shadow-sm":"",n?"cursor-not-allowed opacity-40":""].filter(Boolean).join(" "),children:[g.jsx("span",{className:"truncate",children:j}),g.jsx(Yr,{size:14,className:`shrink-0 transition-transform duration-150 ${E?"rotate-180":""}`})]}),g.jsx("div",{role:"listbox","aria-hidden":!E,className:["absolute bottom-full left-0 z-20 mb-2 w-32 origin-bottom-left rounded-lg border bg-white p-1 shadow-lg transition-all duration-150",E?"pointer-events-auto translate-y-0 scale-100 opacity-100":"pointer-events-none translate-y-1 scale-95 opacity-0",P==="execute"?"border-red-200":"border-gray-200"].filter(Boolean).join(" "),children:G.map(te=>{const $e=te.value===P;return g.jsx("button",{type:"button",role:"option","aria-selected":$e,onMouseDown:ee=>ee.preventDefault(),onClick:()=>{ve(te.value),M(!1)},className:["flex w-full items-center rounded-md px-3 py-2 text-left text-xs font-medium transition-colors duration-150",$e?te.value==="execute"?"bg-red-50 text-red-700":"bg-gray-100 text-gray-900":te.value==="execute"?"text-gray-700 hover:bg-red-50 hover:text-red-700":"text-gray-700 hover:bg-gray-50 hover:text-gray-900"].join(" "),children:te.label},te.value)})})]}),g.jsx("div",{className:"min-w-0 flex-1",children:g.jsxs("div",{className:"relative flex min-w-0 items-center",children:[W&&g.jsxs("div",{className:"pointer-events-none absolute bottom-full left-0 mb-2 flex items-center gap-2 rounded-lg bg-gray-900 px-3 py-2 text-xs text-white shadow-lg",children:[g.jsx(wh,{size:13,className:"text-blue-300"}),g.jsx("span",{className:"max-w-[420px] truncate",children:W.description||m("workflow.selectedLabel",{id:W.id})})]}),g.jsx(u4,{value:N,onChange:L,onSend:Z,agents:$,workflows:I,placeholder:l??(r?m("taskDetail.inputPlaceholderActive",{agent:r}):m("taskDetail.inputPlaceholder")),disabled:n,multiline:u,inputRef:h,className:V})]})}),O&&g.jsx("button",{onClick:re,disabled:n||C,className:"inline-flex h-10 w-10 items-center justify-center rounded-md border border-gray-200 bg-white text-gray-400 shadow-sm transition-colors hover:border-gray-300 hover:bg-gray-50 hover:text-gray-600 disabled:cursor-not-allowed disabled:opacity-40",title:m("taskDetail.captureScreen"),"aria-label":m("taskDetail.captureScreen"),children:g.jsx(R3,{size:18})}),g.jsx("button",{onClick:Z,disabled:n||!sy(N).trim(),className:"inline-flex h-10 shrink-0 items-center justify-center rounded-md bg-blue-600 px-5 text-sm font-medium text-white shadow-sm transition-colors hover:bg-blue-500 disabled:cursor-not-allowed disabled:opacity-40",children:c??m("taskDetail.send")})]})}}function iFe(){const{t}=me(),{taskId:e}=Kh(),n=T.useRef(null),{setPageHeader:r}=ur(),{messages:i,loading:s,error:o,taskStatus:a,logs:l,childTasks:c,sending:u,fetchDetail:h,sendMessage:f,addLocalMessage:d,stopPolling:p,reset:m}=LF();if(T.useEffect(()=>{r({title:"",actions:null})},[r]),T.useEffect(()=>(e&&h(e),()=>{p(),m()}),[e]),T.useEffect(()=>{n.current&&(n.current.scrollTop=n.current.scrollHeight)},[i.length,l.length]),!e)return null;const y=(w,v)=>{f(w,v)},x=w=>{d({id:`capture-${w.timestamp}`,userId:"user",text:"",timestamp:new Date(w.timestamp).toISOString(),isAssistant:!1,imageDataUrl:w.imageDataUrl})},b=i.reduceRight((w,v,C)=>w===-1&&v.isAssistant?C:w,-1),k=(()=>{var C;const w=new Map;let v=null;for(let S=0;S<i.length;S++)if(i[S].isAssistant){const E=((C=i[S].metadata)==null?void 0:C.agent_id)??"assistant";E!==v&&(w.set(S,E),v=E)}return w})();return g.jsxs("div",{className:"flex flex-col h-[calc(100vh-3rem)] -m-6 bg-gray-50",children:[g.jsxs("div",{ref:n,className:"flex-1 overflow-y-auto px-8 py-6 space-y-5",children:[s&&g.jsx("div",{className:"flex items-center justify-center py-16",children:g.jsx(ut,{size:24,className:"animate-spin text-gray-500"})}),o&&!s&&g.jsxs("div",{className:"flex items-center gap-3 bg-red-50 text-red-600 text-sm rounded-lg px-4 py-3 border border-red-200",children:[g.jsx(Rn,{size:16,className:"shrink-0"}),g.jsx("span",{children:o})]}),!s&&i.map((w,v)=>{const C=v===b,S=k.get(v);return g.jsxs(T.Fragment,{children:[S&&g.jsxs("div",{className:"flex items-center gap-3 py-1",children:[g.jsx("div",{className:"flex-1 h-px bg-gray-200"}),g.jsx("span",{className:"text-xs text-gray-400 shrink-0 select-none",children:t("taskDetail.agentJoined",{agent:S})}),g.jsx("div",{className:"flex-1 h-px bg-gray-200"})]}),g.jsx(OS,{message:w,logs:w.logs,childTasks:C?c:void 0,taskStatus:C?a:void 0})]},w.id)}),!s&&!o&&g.jsx("div",{className:"mt-2",children:g.jsx(RA,{logs:l,childTasks:c,status:a})}),!s&&!o&&i.length===0&&g.jsxs("div",{className:"flex flex-col items-center justify-center py-16 text-gray-500",children:[g.jsx("p",{className:"text-sm",children:t("taskDetail.noMessages")}),g.jsx("p",{className:"text-xs mt-1 text-gray-600",children:t("taskDetail.noMessagesHint")})]})]}),g.jsx(SN,{onSend:y,onCapture:x,disabled:u,multiline:!0})]})}function rp(t,e,n){return Math.min(Math.max(t,e),n)}function sFe(t,e,n,r){const i=rp(t,e,n);if(!r||typeof window>"u")return i;const s=Number(window.localStorage.getItem(r));return Number.isFinite(s)?rp(s,e,n):i}function _N({children:t,defaultWidth:e,minWidth:n=160,maxWidth:r=480,side:i,storageKey:s}){const[o,a]=T.useState(()=>sFe(e,n,r,s)),[l,c]=T.useState(!1),u=T.useRef(null),h=T.useCallback(()=>{a(rp(e,n,r))},[e,r,n]),f=T.useCallback(d=>{d.preventDefault(),u.current={startX:d.clientX,startWidth:o},c(!0)},[o]);return T.useEffect(()=>{a(d=>rp(d,n,r))},[r,n]),T.useEffect(()=>{!s||typeof window>"u"||window.localStorage.setItem(s,String(o))},[s,o]),T.useEffect(()=>{if(!l)return;const d=document.body.style.cursor,p=document.body.style.userSelect;document.body.style.cursor="col-resize",document.body.style.userSelect="none";const m=x=>{const b=u.current;if(!b)return;const k=x.clientX-b.startX,w=i==="right"?b.startWidth+k:b.startWidth-k;a(rp(w,n,r))},y=()=>{u.current=null,c(!1)};return window.addEventListener("mousemove",m),window.addEventListener("mouseup",y),()=>{document.body.style.cursor=d,document.body.style.userSelect=p,window.removeEventListener("mousemove",m),window.removeEventListener("mouseup",y)}},[l,r,n,i]),g.jsxs("div",{className:"relative h-full shrink-0",style:{width:o},children:[g.jsx("div",{className:"h-full overflow-hidden",children:t}),g.jsx("div",{role:"separator","aria-orientation":"vertical",onMouseDown:f,onDoubleClick:h,className:["absolute inset-y-0 z-10 w-1 cursor-col-resize rounded-full transition-colors",i==="left"?"left-0 -translate-x-1/2":"right-0 translate-x-1/2",l?"bg-blue-400/80":"bg-transparent hover:bg-blue-400/60"].join(" ")})]})}const oFe=5e3,aFe=1e3;function TN(t,e){const n=T.useRef(t);T.useEffect(()=>{n.current=t},[t]);const{interval:r,idleOnly:i=!1,idleTimeout:s=oFe,enabled:o=!0}=e;T.useEffect(()=>{if(!o)return;const a=()=>{n.current()};if(!i){const y=window.setInterval(a,r);return()=>{window.clearInterval(y)}}let l=null,c=null,u=Number.NEGATIVE_INFINITY;const h=()=>{l!==null&&(window.clearTimeout(l),l=null)},f=()=>{c!==null&&(window.clearInterval(c),c=null)},d=()=>{c===null&&(c=window.setInterval(a,r))},p=()=>{h(),l=window.setTimeout(()=>{d()},s)},m=()=>{const y=Date.now();y-u<aFe||(u=y,f(),p())};return p(),document.addEventListener("mousemove",m,{passive:!0}),document.addEventListener("keydown",m,{passive:!0}),()=>{f(),h(),document.removeEventListener("mousemove",m),document.removeEventListener("keydown",m)}},[o,i,s,r])}const lFe={bash:"#a855f7",read:"#22c55e",grep:"#22c55e",edit:"#f97316",write:"#f97316"};function cFe(t){return lFe[t.trim().toLowerCase()]??"#6b7280"}function uFe(t){switch(t.trim().toLowerCase()){case"bash":return a1;case"read":return Uo;case"grep":return Ya;case"edit":case"write":return PT;default:return xF}}function hFe({stats:t,open:e,onToggle:n}){const{t:r}=me(),i=T.useMemo(()=>t.reduce((o,a)=>o+a.count,0),[t]),s=T.useMemo(()=>t.map(o=>{const a=i>0?o.count/i*100:0;return{...o,color:cFe(o.tool),percentage:a,displayPercentage:Math.round(a)}}),[t,i]);return t.length===0||i===0?null:g.jsxs("section",{className:"rounded-lg border border-gray-200 bg-white shadow-sm",children:[g.jsx("div",{className:"border-b border-gray-200 px-4 py-3",children:g.jsxs("button",{type:"button",onClick:n,"aria-expanded":e,className:"flex w-full items-center justify-between gap-4 text-left",children:[g.jsxs("span",{className:"flex min-w-0 items-center gap-2",children:[e?g.jsx(Yr,{size:16,className:"shrink-0 text-gray-400"}):g.jsx(hs,{size:16,className:"shrink-0 text-gray-400"}),g.jsx("span",{className:"truncate text-sm font-semibold text-gray-900",children:r("tasks.panel.toolUsage")})]}),g.jsx("span",{className:"flex h-2.5 w-28 shrink-0 overflow-hidden rounded-full bg-gray-100","aria-hidden":"true",children:s.map(o=>g.jsx("span",{className:"h-full",style:{width:`${o.percentage}%`,backgroundColor:o.color},title:r("tasks.panel.toolUsageTooltip",{tool:o.tool,count:o.count,pct:o.displayPercentage})},o.tool))})]})}),e&&g.jsx("div",{className:"px-4 py-3",children:g.jsxs("table",{className:"w-full table-fixed text-sm",children:[g.jsx("thead",{children:g.jsxs("tr",{className:"text-left text-xs uppercase tracking-wide text-gray-500",children:[g.jsx("th",{className:"pb-2 font-medium",children:r("tasks.panel.tool")}),g.jsx("th",{className:"pb-2 text-right font-medium",children:r("tasks.panel.calls")}),g.jsx("th",{className:"pb-2 pl-4 font-medium",children:r("tasks.panel.ratio")})]})}),g.jsx("tbody",{className:"divide-y divide-gray-100",children:s.map(o=>{const a=uFe(o.tool);return g.jsxs("tr",{children:[g.jsx("td",{className:"py-3 pr-3",children:g.jsxs("div",{className:"flex items-center gap-2 text-gray-800",children:[g.jsx("span",{className:"inline-flex h-5 w-5 items-center justify-center rounded-full",style:{backgroundColor:`${o.color}1a`,color:o.color},children:g.jsx(a,{size:12})}),g.jsx("span",{className:"h-2 w-2 rounded-full",style:{backgroundColor:o.color},"aria-hidden":"true"}),g.jsx("span",{className:"truncate font-medium",children:o.tool})]})}),g.jsx("td",{className:"py-3 text-right font-mono text-xs text-gray-600",children:o.count}),g.jsx("td",{className:"py-3 pl-4",children:g.jsxs("div",{className:"flex items-center gap-3",children:[g.jsxs("span",{className:"w-10 shrink-0 text-xs font-medium text-gray-600",children:[o.displayPercentage,"%"]}),g.jsx("div",{className:"h-2 flex-1 overflow-hidden rounded-full bg-gray-100",children:g.jsx("div",{className:"h-full rounded-full",style:{width:`${o.percentage}%`,backgroundColor:o.color},title:r("tasks.panel.toolUsageTooltip",{tool:o.tool,count:o.count,pct:o.displayPercentage})})})]})})]},o.tool)})})]})})]})}function Iv(t){switch(t){case"success":return{prompt:!1,result:!0,toolUsage:!1,metadata:!1};case"failed":return{prompt:!0,result:!1,toolUsage:!1,metadata:!1};case"running":return{prompt:!1,result:!1,toolUsage:!1,metadata:!1};case"pending":default:return{prompt:!0,result:!1,toolUsage:!1,metadata:!1}}}function dFe(t){return t?t>=1e6?`${(t/1e6).toFixed(1)}M`:t>=1e3?`${(t/1e3).toFixed(1)}K`:`${t}`:"0"}function fFe(t,e){const n=(t??0)+(e??0);return n===0?"-":`${dFe(n)} tok`}function pFe(t){return t?t<.01?`$${t.toFixed(4)}`:`$${t.toFixed(2)}`:"-"}function gFe(t,e){return e==="running"||t==null?"—":`${(t/1e3).toFixed(1).replace(/\.0$/,"")}s`}function h4(t){return t?new Intl.DateTimeFormat(void 0,{hour:"2-digit",minute:"2-digit"}).format(new Date(t)):"—"}function mFe(t,e,n){return(e==null?void 0:e.agentId)??(n==null?void 0:n.agent)??t}function d_({status:t}){const{t:e}=me(),n={success:"bg-green-100 text-green-800",failed:"bg-red-100 text-red-800",running:"bg-yellow-100 text-yellow-800",pending:"bg-gray-100 text-gray-800"};return g.jsx("span",{className:`inline-flex items-center rounded-full px-2.5 py-1 text-xs font-medium ${n[t]}`,children:e(`tasks.status.${t}`)})}function d4({title:t,content:e,open:n,onToggle:r,onCopy:i,clampLines:s}){const{t:o}=me(),[a,l]=T.useState(!1);T.useEffect(()=>{l(!1)},[e]);const c=!!s&&e.trim().length>240,u=s&&!a?`overflow-hidden [display:-webkit-box] [-webkit-box-orient:vertical] [-webkit-line-clamp:${s}]`:"";return g.jsxs("section",{className:"rounded-lg border border-gray-200 bg-white shadow-sm",children:[g.jsxs("div",{className:"flex items-start justify-between gap-3 border-b border-gray-200 px-4 py-3",children:[g.jsxs("button",{type:"button",onClick:r,"aria-expanded":n,className:"flex min-w-0 flex-1 items-center gap-2 text-left",children:[n?g.jsx(Yr,{size:16,className:"shrink-0 text-gray-400"}):g.jsx(hs,{size:16,className:"shrink-0 text-gray-400"}),g.jsx("span",{className:"truncate text-sm font-semibold text-gray-900",children:t})]}),g.jsxs("button",{type:"button",onClick:i,className:"inline-flex items-center gap-1 rounded-md border border-gray-200 px-2.5 py-1.5 text-xs font-medium text-gray-600 transition-colors hover:bg-gray-50",children:[g.jsx(yg,{size:13}),g.jsx("span",{children:o("tasks.panel.copy")})]})]}),n&&g.jsxs("div",{className:"px-4 py-3",children:[g.jsx("div",{className:`text-sm leading-6 text-gray-700 ${u}`,children:g.jsx(Pg,{content:e})}),c&&g.jsx("button",{type:"button",onClick:()=>l(h=>!h),className:"mt-2 text-xs font-medium text-blue-600 transition-colors hover:text-blue-700",children:o(a?"tasks.panel.showLess":"tasks.panel.showMore")})]})]})}function yFe({childTasks:t,onSelectTask:e}){const{t:n}=me();return g.jsxs("section",{className:"rounded-lg border border-gray-200 bg-white shadow-sm",children:[g.jsx("div",{className:"border-b border-gray-200 px-4 py-3",children:g.jsx("h3",{className:"text-sm font-semibold text-gray-900",children:n("tasks.panel.childTasks")})}),g.jsx("div",{className:"divide-y divide-gray-200",children:t.map(r=>{if(e){const i=e;return g.jsxs("button",{type:"button",onClick:()=>i(r.taskId),className:"flex w-full cursor-pointer items-center justify-between gap-3 px-4 py-3 text-left transition-colors hover:bg-gray-50",children:[g.jsxs("div",{className:"min-w-0",children:[g.jsx("p",{className:"truncate text-sm font-medium text-gray-900",children:r.agentId}),g.jsx("p",{className:"truncate font-mono text-xs text-blue-500",children:r.taskId})]}),g.jsx(d_,{status:r.status})]},r.taskId)}return g.jsxs("div",{className:"flex items-center justify-between gap-3 px-4 py-3",children:[g.jsxs("div",{className:"min-w-0",children:[g.jsx("p",{className:"truncate text-sm font-medium text-gray-900",children:r.agentId}),g.jsx("p",{className:"truncate font-mono text-xs text-gray-400",children:r.taskId})]}),g.jsx(d_,{status:r.status})]},r.taskId)})})]})}function xFe({taskId:t,task:e,onClose:n,onRefresh:r,onSelectTask:i}){const{t:s}=me(),o=Nt(),a=ul(V=>V.addToast),[l,c]=T.useState(null),[u,h]=T.useState(!0),[f,d]=T.useState(null),[p,m]=T.useState("idle"),[y,x]=T.useState(Iv((e==null?void 0:e.status)??"pending")),b=(l==null?void 0:l.status)??(e==null?void 0:e.status)??"pending",k=(l==null?void 0:l.prompt)??(e==null?void 0:e.prompt)??"",w=(l==null?void 0:l.result)??"",v=(l==null?void 0:l.startedAt)??(e==null?void 0:e.startedAt),C=(l==null?void 0:l.completedAt)??(e==null?void 0:e.completedAt),S=(l==null?void 0:l.durationMs)??(e==null?void 0:e.durationMs),E=(l==null?void 0:l.model)??(e==null?void 0:e.model)??null,M=(l==null?void 0:l.threadId)??(e==null?void 0:e.threadId)??null,A=(l==null?void 0:l.inputTokens)??(e==null?void 0:e.inputTokens),B=(l==null?void 0:l.outputTokens)??(e==null?void 0:e.outputTokens),F=(l==null?void 0:l.costUsd)??(e==null?void 0:e.costUsd),z=(l==null?void 0:l.error)??null,D=(l==null?void 0:l.logs)??[],O=(l==null?void 0:l.childTasks)??[],N=(l==null?void 0:l.parentTaskId)??null,$=(l==null?void 0:l.metadata)??null,I=mFe(t,e,l),P=T.useMemo(()=>{const V=(l==null?void 0:l.toolUsage)??{};return Object.entries(V).map(([Z,re])=>({tool:Z,count:re})).sort((Z,re)=>re.count-Z.count)},[l==null?void 0:l.toolUsage]),L=T.useMemo(()=>[E??"-",fFe(A,B),pFe(F)].join(" · "),[F,A,E,B]),W=T.useCallback(async(V=!0)=>{V&&h(!0);try{const Z=await fe.getTaskStatus(t,{include:"logs,children",skipRequestLog:!0});c(Z),d(null)}catch(Z){d(Z instanceof Error?Z.message:"Failed to load task details")}finally{V&&h(!1)}},[t]);T.useEffect(()=>{c(null),h(!0),d(null),m("idle"),x(Iv((e==null?void 0:e.status)??"pending")),W(!0)},[W,e==null?void 0:e.status,t]),T.useEffect(()=>{!e&&l&&x(Iv(l.status))},[l,e]),T.useEffect(()=>{if(p!=="confirming")return;const V=window.setTimeout(()=>{m("idle")},3e3);return()=>window.clearTimeout(V)},[p]),TN(()=>W(!1),{interval:5e3,enabled:b==="running"});const G=T.useCallback(async(V,Z)=>{var re;try{if(!((re=navigator.clipboard)!=null&&re.writeText))throw new Error("Clipboard unavailable");await navigator.clipboard.writeText(V),a({type:"success",message:s(Z)})}catch(ve){console.error("[TaskDetailPanel] Failed to copy text.",ve),a({type:"error",message:s("tasks.panel.copyFailed")})}},[a,s]),j=T.useCallback(async()=>{if(p!=="stopping"){if(p==="idle"){m("confirming");return}m("stopping");try{await fe.stopTask(t),await Promise.all([Promise.resolve(r==null?void 0:r()),W(!1)]),m("idle")}catch(V){console.error("[TaskDetailPanel] Failed to stop task.",V),a({type:"error",message:s("tasks.panel.stopFailed")}),m("idle")}}},[a,W,r,p,s,t]);return g.jsx(g.Fragment,{children:g.jsxs("aside",{role:"dialog","aria-label":s("tasks.panel.title"),className:"flex h-full w-full min-w-0 flex-col border-l border-gray-200 bg-white shadow-lg",children:[g.jsx("div",{className:"sticky top-0 z-10 border-b border-gray-200 bg-white p-4",children:g.jsxs("div",{className:"flex items-start gap-3",children:[g.jsx("div",{className:"flex h-11 w-11 shrink-0 items-center justify-center rounded-full bg-blue-50 text-blue-600",children:g.jsx(hF,{size:18})}),g.jsxs("div",{className:"min-w-0 flex-1",children:[g.jsxs("div",{className:"flex items-start justify-between gap-3",children:[g.jsxs("div",{className:"min-w-0",children:[g.jsx("p",{className:"truncate text-lg font-semibold text-gray-900",children:I}),g.jsx("p",{className:"truncate font-mono text-xs text-gray-400",children:t})]}),g.jsx("button",{type:"button",onClick:n,className:"rounded-md p-1.5 text-gray-400 transition-colors hover:bg-gray-100 hover:text-gray-600","aria-label":s("tasks.panel.close"),children:g.jsx(Xa,{size:16})})]}),g.jsxs("div",{className:"mt-3 flex flex-wrap items-center gap-2",children:[g.jsx(d_,{status:b}),g.jsx("span",{className:"text-sm font-medium text-gray-600",children:gFe(S,b)}),b==="running"&&g.jsx("button",{type:"button",onClick:()=>void j(),disabled:p==="stopping",className:"inline-flex min-w-[108px] items-center justify-center gap-1.5 rounded-md border border-red-200 bg-red-50 px-3 py-1.5 text-xs font-semibold text-red-700 transition-colors hover:bg-red-100 disabled:cursor-not-allowed disabled:opacity-70",children:p==="stopping"?g.jsxs(g.Fragment,{children:[g.jsx(ut,{size:12,className:"animate-spin"}),g.jsx("span",{children:s("tasks.panel.stopping")})]}):p==="confirming"?g.jsx("span",{children:s("tasks.panel.stopConfirm")}):g.jsxs(g.Fragment,{children:[g.jsx(uie,{size:12}),g.jsx("span",{children:s("tasks.panel.stop")})]})})]}),g.jsx("p",{className:"mt-3 text-sm text-gray-600",children:L}),g.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-x-3 gap-y-1 text-xs text-gray-500",children:[g.jsx("span",{children:`${h4(v)} → ${h4(C)}`}),M?g.jsxs("button",{type:"button",onClick:()=>o(`/threads/${M}`),className:"inline-flex items-center gap-1 font-medium text-blue-600 transition-colors hover:text-blue-700",children:[g.jsx(Tre,{size:13}),g.jsx("span",{children:s("tasks.panel.viewThread")})]}):g.jsx("span",{className:"text-gray-400",children:s("tasks.panel.noThread")})]}),N&&i&&g.jsxs("div",{className:"mt-2 flex items-center gap-1.5 text-xs text-gray-500",children:[g.jsx(Pne,{size:14}),g.jsx("span",{children:s("tasks.panel.parentLabel")}),g.jsxs("button",{type:"button",onClick:()=>i(N),className:"font-medium text-blue-500 transition-colors hover:underline",children:["#",N]})]})]})]})}),g.jsxs("div",{className:"flex-1 space-y-3 overflow-y-auto p-4",children:[b==="failed"&&z&&g.jsxs("div",{className:"flex items-start gap-3 rounded-lg border border-red-200 bg-red-50 px-4 py-3 text-sm text-red-700",children:[g.jsx(Rn,{size:16,className:"mt-0.5 shrink-0"}),g.jsx("span",{children:z})]}),f&&g.jsxs("div",{className:"rounded-lg border border-red-200 bg-white p-4 shadow-sm",children:[g.jsxs("div",{className:"flex items-start gap-3 text-sm text-red-700",children:[g.jsx(Rn,{size:16,className:"mt-0.5 shrink-0"}),g.jsxs("div",{className:"min-w-0 flex-1",children:[g.jsx("p",{className:"font-medium",children:s("tasks.panel.detailLoadError")}),g.jsx("p",{className:"mt-1 break-words text-xs text-red-600",children:f})]})]}),g.jsx("button",{type:"button",onClick:()=>void W(!0),className:"mt-3 rounded-md bg-red-100 px-3 py-1.5 text-xs font-medium text-red-700 transition-colors hover:bg-red-200",children:s("tasks.panel.retryDetail")})]}),k&&g.jsx(d4,{title:s("tasks.panel.request"),content:k,open:y.prompt,onToggle:()=>x(V=>({...V,prompt:!V.prompt})),onCopy:()=>void G(k,"tasks.panel.copyRequestSuccess")}),u&&!l&&g.jsxs("div",{className:"space-y-3 rounded-lg border border-gray-200 bg-white p-4 shadow-sm",children:[g.jsx("div",{className:"h-4 w-32 animate-pulse rounded bg-gray-200"}),g.jsx("div",{className:"h-4 w-full animate-pulse rounded bg-gray-100"}),g.jsx("div",{className:"h-4 w-4/5 animate-pulse rounded bg-gray-100"})]}),w&&g.jsx(d4,{title:s("tasks.panel.result"),content:w,open:y.result,onToggle:()=>x(V=>({...V,result:!V.result})),onCopy:()=>void G(w,"tasks.panel.copyResultSuccess"),clampLines:5}),!u&&b==="pending"&&!w&&g.jsxs("section",{className:"rounded-lg border border-gray-200 bg-white p-4 shadow-sm",children:[g.jsx("h3",{className:"text-sm font-semibold text-gray-900",children:s("tasks.panel.pendingTitle")}),g.jsx("p",{className:"mt-2 text-sm text-gray-500",children:s("tasks.panel.pendingDescription")})]}),P.length>0&&g.jsx(hFe,{stats:P,open:y.toolUsage,onToggle:()=>x(V=>({...V,toolUsage:!V.toolUsage}))}),(D.length>0||b==="running"||b==="failed")&&g.jsx(RA,{logs:D,childTasks:O,status:b}),O.length>0&&g.jsx(yFe,{childTasks:O,onSelectTask:i}),$&&g.jsxs("section",{className:"rounded-lg border border-gray-200 bg-white shadow-sm",children:[g.jsx("div",{className:"flex items-start justify-between gap-3 border-b border-gray-200 px-4 py-3",children:g.jsxs("button",{type:"button",onClick:()=>x(V=>({...V,metadata:!V.metadata})),"aria-expanded":y.metadata,className:"flex min-w-0 flex-1 items-center gap-2 text-left",children:[y.metadata?g.jsx(Yr,{size:16,className:"shrink-0 text-gray-400"}):g.jsx(hs,{size:16,className:"shrink-0 text-gray-400"}),g.jsx("span",{className:"truncate text-sm font-semibold text-gray-900",children:"Metadata"})]})}),y.metadata&&g.jsx("div",{className:"px-4 py-3",children:g.jsx("pre",{className:"max-h-60 overflow-auto rounded bg-muted p-3 text-xs",children:JSON.stringify($,null,2)})})]})]})]})})}const bFe=["pending","running","success","failed"];function kFe(t,e){const n=(t??0)+(e??0);return n===0?"-":n>=1e6?`${(n/1e6).toFixed(1)}M`:n>=1e3?`${(n/1e3).toFixed(1)}k`:String(n)}function wFe(t,e){if(e==="running"||t==null)return"—";const n=t/1e3;return`${(n>=10,n.toFixed(1)).replace(/\.0$/,"")}s`}function vFe(t,e){const n=new Date(t),r=Date.now()-n.getTime(),i=Math.floor(r/6e4);if(i<1)return e("tasks.relative.justNow");if(i<60)return e("tasks.relative.minutesAgo",{count:i});const s=Math.floor(i/60);return s<24?e("tasks.relative.hoursAgo",{count:s}):new Intl.DateTimeFormat(void 0,{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"}).format(n)}function CFe({status:t}){const{t:e}=me(),n={success:"bg-green-100 text-green-800",failed:"bg-red-100 text-red-800",running:"bg-yellow-100 text-yellow-800",pending:"bg-gray-100 text-gray-800"};return g.jsx("span",{className:`inline-flex items-center rounded-full px-2.5 py-1 text-xs font-medium ${n[t]}`,children:e(`tasks.status.${t}`)})}function f4({label:t,options:e,selectedValues:n,allLabel:r,getOptionLabel:i,onChange:s}){const o=n.length===0?r:n.length===1?i(n[0]):`${t} (${n.length})`;return g.jsxs("details",{className:"relative min-w-[160px]",children:[g.jsxs("summary",{className:"flex h-10 cursor-pointer list-none items-center justify-between gap-2 rounded-lg border border-gray-200 bg-white px-3 text-sm text-gray-700 shadow-sm transition-colors hover:border-gray-300",children:[g.jsx("span",{className:"truncate",children:o}),g.jsx(Yr,{size:16,className:"shrink-0 text-gray-400"})]}),g.jsx("div",{className:"absolute right-0 z-20 mt-2 w-full min-w-[180px] rounded-lg border border-gray-200 bg-white p-2 shadow-lg",children:g.jsx("div",{className:"max-h-60 overflow-y-auto",children:e.map(a=>{const l=n.includes(a);return g.jsxs("label",{className:"flex cursor-pointer items-center justify-between gap-3 rounded-md px-2 py-2 text-sm text-gray-700 transition-colors hover:bg-gray-50",children:[g.jsxs("div",{className:"flex items-center gap-2",children:[g.jsx("input",{type:"checkbox",className:"h-4 w-4 rounded border-gray-300 text-blue-500 focus:ring-blue-500",checked:l,onChange:()=>{s(l?n.filter(c=>c!==a):[...n,a])}}),g.jsx("span",{children:i(a)})]}),l&&g.jsx(Us,{size:14,className:"text-blue-500"})]},a)})})})]})}function SFe(t){return t?"hidden":""}function _Fe(t,e){return e?t.find(n=>n.taskId===e)??null:null}function TFe(){const{t}=me(),{setPageHeader:e}=ur(),[n,r]=mg(),{tasks:i,total:s,page:o,limit:a,loading:l,error:c,searchQuery:u,agentFilter:h,statusFilter:f,availableAgents:d,fetchTasks:p,setPage:m,setSearchQuery:y,setAgentFilter:x,setStatusFilter:b,refresh:k}=OF(),[w,v]=T.useState(u),C=n.get("selected"),S=T.useMemo(()=>_Fe(i,C),[C,i]),E=SFe(C),M=C?5:7,A=Math.max(1,Math.ceil(s/a)),B=T.useMemo(()=>{const D=Math.max(1,o-2),O=Math.min(A,D+4),N=Math.max(1,O-4);return Array.from({length:O-N+1},($,I)=>N+I)},[o,A]),F=T.useCallback(D=>{r(O=>{const N=new URLSearchParams(O);return D?N.set("selected",D):N.delete("selected"),N})},[r]),z=T.useCallback(()=>{k()},[k]);return TN(z,{interval:3e4,idleOnly:!0,idleTimeout:5e3}),T.useEffect(()=>{e({title:t("tasks.title"),actions:g.jsx("button",{onClick:z,className:"rounded-lg p-2 text-gray-500 transition-colors hover:bg-gray-100 hover:text-gray-700",title:t("common.refresh"),children:g.jsx(Vr,{size:16,className:l?"animate-spin":""})})})},[z,l,e,t]),T.useEffect(()=>{const D=window.setTimeout(()=>{w!==u&&y(w)},300);return()=>window.clearTimeout(D)},[w,u,y]),T.useEffect(()=>{p()},[h,p,o,u,f]),T.useEffect(()=>{if(!C)return;const D=O=>{O.key==="Escape"&&F(null)};return window.addEventListener("keydown",D),()=>window.removeEventListener("keydown",D)},[C,F]),g.jsxs("div",{className:"space-y-5",children:[g.jsx("section",{className:"rounded-lg border border-gray-200 bg-white p-4 shadow-sm",children:g.jsxs("div",{className:"flex flex-col gap-3 lg:flex-row lg:items-center",children:[g.jsxs("label",{className:"relative block w-full max-w-[280px]",children:[g.jsx(Ya,{size:16,className:"pointer-events-none absolute left-3 top-1/2 -translate-y-1/2 text-gray-400"}),g.jsx("input",{type:"search",value:w,onChange:D=>v(D.target.value),placeholder:t("tasks.filters.searchPlaceholder"),className:"h-10 w-full rounded-lg border border-gray-200 bg-white pl-9 pr-3 text-sm text-gray-900 placeholder:text-gray-400 focus:border-blue-500 focus:outline-none focus:ring-2 focus:ring-blue-100"})]}),g.jsxs("div",{className:"flex flex-col gap-3 sm:flex-row",children:[g.jsx(f4,{label:t("tasks.filters.agent"),options:d,selectedValues:h,allLabel:t("tasks.filters.allAgents"),getOptionLabel:D=>D,onChange:x}),g.jsx(f4,{label:t("tasks.filters.status"),options:bFe,selectedValues:f,allLabel:t("tasks.filters.allStatuses"),getOptionLabel:D=>t(`tasks.status.${D}`),onChange:b})]})]})}),c&&g.jsxs("div",{className:"flex items-center gap-3 rounded-lg border border-red-200 bg-red-50 px-4 py-3 text-sm text-red-700",children:[g.jsx(Rn,{size:16,className:"shrink-0"}),g.jsx("span",{className:"flex-1",children:c}),g.jsx("button",{onClick:z,className:"rounded-md bg-red-100 px-3 py-1 text-xs font-medium text-red-700 transition-colors hover:bg-red-200",children:t("tasks.retry")})]}),g.jsxs("div",{className:"relative flex min-h-0 flex-col gap-5",children:[g.jsxs("section",{className:"min-w-0 flex-1 overflow-hidden rounded-lg border border-gray-200 bg-white shadow-sm",children:[g.jsx("div",{className:"overflow-x-auto",children:g.jsxs("table",{className:"min-w-full divide-y divide-gray-200",children:[g.jsx("thead",{className:"bg-gray-50",children:g.jsxs("tr",{children:[g.jsx("th",{className:"w-[160px] px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-gray-500",children:t("tasks.columns.time")}),g.jsx("th",{className:`${E} w-[200px] px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-gray-500`,children:t("tasks.columns.taskId")}),g.jsx("th",{className:"w-[140px] px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-gray-500",children:t("tasks.columns.agent")}),g.jsx("th",{className:"w-[80px] px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-gray-500",children:t("tasks.columns.status")}),g.jsx("th",{className:"w-[80px] px-4 py-3 text-right text-xs font-semibold uppercase tracking-wide text-gray-500",children:t("tasks.columns.duration")}),g.jsx("th",{className:`${E} w-[160px] px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-gray-500`,children:t("tasks.columns.model")}),g.jsx("th",{className:"w-[90px] px-4 py-3 text-right text-xs font-semibold uppercase tracking-wide text-gray-500",children:t("tasks.columns.tokens")})]})}),g.jsx("tbody",{className:"divide-y divide-gray-200 bg-white",children:l?g.jsx("tr",{children:g.jsx("td",{colSpan:M,className:"px-4 py-12 text-center text-sm text-gray-500",children:g.jsxs("div",{className:"inline-flex items-center gap-2",children:[g.jsx(Vr,{size:16,className:"animate-spin text-gray-400"}),g.jsx("span",{children:t("tasks.loading")})]})})}):i.length===0?g.jsx("tr",{children:g.jsx("td",{colSpan:M,className:"px-4 py-14",children:g.jsxs("div",{className:"flex flex-col items-center justify-center text-center text-gray-400",children:[g.jsx(OT,{size:36,className:"mb-3"}),g.jsx("p",{className:"text-sm font-medium text-gray-500",children:t("tasks.empty")}),g.jsx("p",{className:"mt-1 text-xs text-gray-400",children:t("tasks.emptyHint")})]})})}):i.map(D=>{const O=C===D.taskId;return g.jsxs("tr",{"aria-selected":O,onClick:()=>F(D.taskId),className:`cursor-pointer transition-colors hover:bg-gray-50 ${O?"bg-blue-50":""}`,children:[g.jsx("td",{className:`px-4 py-3 text-sm text-gray-500 ${O?"border-l-2 border-l-blue-500 bg-blue-50":""}`,children:vFe(D.startedAt,t)}),g.jsx("td",{className:`${E} px-4 py-3 text-sm font-medium text-gray-900`,children:g.jsx("span",{className:"font-mono",title:D.taskId,children:D.taskId})}),g.jsx("td",{className:"px-4 py-3 text-sm font-medium text-gray-900",children:D.agentId}),g.jsx("td",{className:"px-4 py-3 text-sm text-gray-700",children:g.jsx(CFe,{status:D.status})}),g.jsx("td",{className:"px-4 py-3 text-right text-sm text-gray-700",children:wFe(D.durationMs,D.status)}),g.jsx("td",{className:`${E} px-4 py-3 text-sm text-gray-700`,children:D.model??"-"}),g.jsx("td",{className:"px-4 py-3 text-right text-sm text-gray-500 tabular-nums",children:kFe(D.inputTokens,D.outputTokens)})]},D.taskId)})})]})}),g.jsxs("div",{className:"flex flex-col gap-3 border-t border-gray-200 px-4 py-4 sm:flex-row sm:items-center sm:justify-between",children:[g.jsx("p",{className:"text-sm text-gray-500",children:t("tasks.totalCount",{count:s})}),g.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[g.jsx("button",{onClick:()=>m(Math.max(1,o-1)),disabled:o<=1,className:"rounded-lg border border-gray-200 px-3 py-1.5 text-sm text-gray-600 transition-colors hover:bg-gray-50 disabled:cursor-not-allowed disabled:opacity-50",children:t("tasks.pagination.previous")}),B.map(D=>g.jsx("button",{onClick:()=>m(D),className:`rounded-lg px-3 py-1.5 text-sm transition-colors ${D===o?"bg-blue-500 text-white":"border border-gray-200 text-gray-600 hover:bg-gray-50"}`,children:D},D)),g.jsx("button",{onClick:()=>m(Math.min(A,o+1)),disabled:o>=A,className:"rounded-lg border border-gray-200 px-3 py-1.5 text-sm text-gray-600 transition-colors hover:bg-gray-50 disabled:cursor-not-allowed disabled:opacity-50",children:t("tasks.pagination.next")})]})]})]}),C&&g.jsx("div",{className:"fixed inset-y-0 right-0 z-40",children:g.jsx(_N,{defaultWidth:400,minWidth:300,maxWidth:600,side:"left",storageKey:"task-detail-width",children:g.jsx(xFe,{taskId:C,task:S,onClose:()=>F(null),onRefresh:k,onSelectTask:F})})})]})]})}function f_({resource:t,current:e,limit:n}){const{t:r}=me();return g.jsx("div",{"data-testid":`limit-banner-${t}`,className:"rounded-xl border border-amber-200 bg-amber-50 px-4 py-3 text-sm text-amber-800",children:g.jsxs("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-start",children:[g.jsxs("div",{className:"flex-1",children:[g.jsx("div",{className:"font-medium",children:r(`limits.banner.${t}.title`,{current:e,limit:n})}),g.jsx("div",{className:"mt-1 text-amber-700",children:r(`limits.banner.${t}.description`)}),g.jsx("div",{className:"mt-2 text-amber-700",children:r("limits.banner.grandfatherPromise")})]}),g.jsxs("a",{href:_p,target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center justify-center gap-1 rounded-lg bg-amber-600 px-3 py-2 text-xs font-medium text-white transition-colors hover:bg-amber-700",children:[r("upgrade.waitlistCta"),g.jsx(o1,{size:12})]})]})})}const p4={경영진:$ne,개발팀:fF,default:Ka};function EFe({teamName:t,memberCount:e,isCollapsible:n=!1,isExpanded:r=!0,onToggle:i,className:s}){const{t:o}=me(),a=p4[t]??p4.default,l=r?Yr:hs,c=g.jsxs(g.Fragment,{children:[g.jsxs("div",{className:"flex items-center gap-3",children:[g.jsx("div",{className:"flex h-9 w-9 items-center justify-center rounded-lg bg-gray-100 text-gray-600",children:g.jsx(a,{size:18})}),g.jsxs("div",{className:"flex items-center gap-2",children:[g.jsx("span",{className:"text-sm font-semibold text-gray-900",children:t}),g.jsx("span",{className:"rounded-full bg-gray-100 px-2.5 py-1 text-xs font-medium text-gray-500",children:o("agent.team.memberCount",{count:e})})]})]}),n&&g.jsx(l,{size:16,className:"shrink-0 text-gray-400"})]});return n?g.jsx("button",{type:"button",onClick:i,"aria-expanded":r,"aria-label":o(r?"agent.team.collapse":"agent.team.expand",{team:t}),className:`flex w-full items-center justify-between gap-3 rounded-xl border border-gray-200 bg-white px-4 py-3 text-left transition-colors hover:border-gray-300 hover:bg-gray-50 ${s??""}`.trim(),children:c}):g.jsx("div",{role:"button","aria-expanded":!0,className:`flex w-full items-center justify-between gap-3 rounded-xl border border-gray-200 bg-white px-4 py-3 ${s??""}`.trim(),children:c})}const Gd="__unassigned__";function AFe(t){var i,s;const e=new Map,n=[];for(const o of t){const a=((i=o.team)==null?void 0:i.trim())||Gd;e.has(a)||(e.set(a,[]),n.push(a)),(s=e.get(a))==null||s.push(o)}const r=n.filter(o=>o!==Gd);return e.has(Gd)&&r.push(Gd),r.map(o=>({teamKey:o,agents:e.get(o)??[],isUnassigned:o===Gd}))}const au={id:"",name:"",role:"",team:"",description:"",provider:"",model:"",prompt:""},NFe={include:[]},Yd=["cli/claude","cli/codex","cli/gemini","cli/copilot"],MFe={"cli/claude":"agent.guide.providerClaude","cli/codex":"agent.guide.providerCodex","cli/gemini":"agent.guide.providerGemini","cli/copilot":"agent.guide.providerCopilot"},LFe={"cli/claude":"agent.engine.claude","cli/codex":"agent.engine.codex","cli/gemini":"agent.engine.gemini","cli/copilot":"agent.engine.copilot"},DFe={"cli/claude":["claude-opus-4-6","claude-sonnet-4-6","claude-haiku-4-5","claude-opus-4-5","claude-sonnet-4-5","claude-sonnet-4","claude-opus-4-6-fast"],"cli/codex":["gpt-5.3-codex","gpt-5.2-codex","gpt-5.1-codex-mini","o4-mini"],"cli/gemini":["gemini-3-pro-preview","gemini-3-flash-preview","gemini-2.5-pro","gemini-2.5-flash"],"cli/copilot":["claude-sonnet-4-6","claude-sonnet-4-5","claude-haiku-4-5","claude-opus-4-6","claude-opus-4-6-fast","claude-opus-4-5","claude-sonnet-4","gpt-5.4","gpt-5.3-codex","gpt-5.2-codex","gpt-5.2","gpt-5.1","gpt-5.4-mini","gpt-5-mini","gpt-4.1"]},nY={"cli/claude":"claude-sonnet-4-6","cli/gemini":"gemini-3-flash-preview","cli/copilot":"claude-sonnet-4-6"},OFe={"claude-sonnet-4-6":"1x","claude-sonnet-4-5":"1x","claude-haiku-4-5":"0.33x","claude-opus-4-6":"3x","claude-opus-4-6-fast":"30x","claude-opus-4-5":"3x","claude-sonnet-4":"1x","gpt-5.4":"1x","gpt-5.3-codex":"1x","gpt-5.2-codex":"1x","gpt-5.2":"1x","gpt-5.1":"1x","gpt-5.4-mini":"0.33x","gpt-5-mini":"0x","gpt-4.1":"0x"},rY=[{id:"coding-assistant",icon:"📝",titleKey:"agent.template.codingAssistant",descriptionKey:"agent.template.codingAssistantDesc",form:{name:"Coding Assistant",role:"Software Engineer",description:"General coding, implementation, debugging, and refactoring support",provider:"cli/claude",model:"claude-sonnet-4-6"}},{id:"research",icon:"🔍",titleKey:"agent.template.research",descriptionKey:"agent.template.researchDesc",form:{name:"Research Assistant",role:"Researcher",description:"Technical research, comparisons, and source-backed investigation",provider:"cli/gemini",model:"gemini-3-flash-preview"}},{id:"data-analysis",icon:"📊",titleKey:"agent.template.dataAnalysis",descriptionKey:"agent.template.dataAnalysisDesc",form:{name:"Data Analyst",role:"Data Analyst",description:"Data exploration, analysis, and reporting support",provider:"cli/copilot",model:"gpt-5.4"}},{id:"writing",icon:"✍️",titleKey:"agent.template.writing",descriptionKey:"agent.template.writingDesc",form:{name:"Writing Assistant",role:"Technical Writer",description:"Documentation drafting, editing, and structured content writing",provider:"cli/claude",model:"claude-sonnet-4-6"}},{id:"design-review",icon:"🎨",titleKey:"agent.template.designReview",descriptionKey:"agent.template.designReviewDesc",form:{name:"Design Reviewer",role:"Design Reviewer",description:"UI/UX review, multimodal inspection, and feedback support",provider:"cli/gemini",model:"gemini-3-pro-preview"}}];function lu(t){return{include:[...(t==null?void 0:t.include)??NFe.include]}}function RFe(t){return t&&t.charAt(0).toUpperCase()+t.slice(1)}function wf(t,e){if(!t)return"";const n=LFe[t];return n&&e?e(n):t.startsWith("cli/")?RFe(t.slice(4)):t}function oy(t,e){if(!t)return"";if(!e)return t;const n=`agent.model.${t}.label`,r=e(n);return r===n?t:r}function IFe(t){if(!t)return[];const e=DFe[t]??[],n=nY[t];return!n||!e.includes(n)?e:[n,...e.filter(r=>r!==n)]}const BFe=In(t=>({activeTab:"basic",selectedTemplateId:null,form:au,skills:lu(),setActiveTab:e=>t({activeTab:e}),setField:(e,n)=>{t(r=>({form:{...r.form,[e]:n}}))},setProvider:e=>{t(n=>({form:{...n.form,provider:e,model:""}}))},setSkillsInclude:e=>{t(n=>({skills:{...n.skills,include:[...e]}}))},initializeBlank:()=>{t({activeTab:"basic",selectedTemplateId:null,form:au,skills:lu()})},initializeFromAgent:(e,n)=>{const r=(n==null?void 0:n.clearIdentity)??!1;t({activeTab:"basic",selectedTemplateId:null,form:{...au,id:r?"":e.id??"",name:r?"":e.name??"",role:e.role??"",team:e.team??"",description:e.description??"",provider:e.provider??"",model:e.model??"",prompt:e.prompt??""},skills:lu(n==null?void 0:n.skills)})},applyTemplate:e=>{if(!e){t({activeTab:"basic",selectedTemplateId:null,form:au,skills:lu()});return}const n=rY.find(r=>r.id===e);n&&t({activeTab:"basic",selectedTemplateId:n.id,form:{...au,...n.form,id:""},skills:lu()})},reset:()=>{t({activeTab:"basic",selectedTemplateId:null,form:au,skills:lu()})}}));function PFe(t){const e=t.trim().split(/\s+/);return e.length>=2?(e[0][0]+e[1][0]).toUpperCase():t.slice(0,2).toUpperCase()}const g4=[{bg:"bg-blue-100",text:"text-blue-700"},{bg:"bg-purple-100",text:"text-purple-700"},{bg:"bg-green-100",text:"text-green-700"},{bg:"bg-amber-100",text:"text-amber-700"},{bg:"bg-rose-100",text:"text-rose-700"},{bg:"bg-cyan-100",text:"text-cyan-700"},{bg:"bg-indigo-100",text:"text-indigo-700"},{bg:"bg-teal-100",text:"text-teal-700"}];function FFe(t){const e=t.split("").reduce((n,r)=>n+r.charCodeAt(0),0)%g4.length;return g4[e]}const Bv="crewx-agent-accordion-state";function $Fe(t){const e=t.length<=5;return Object.fromEntries(t.map(n=>[n.teamKey,e]))}function jFe({agent:t,onClose:e,onConfirm:n,deleting:r,t:i}){return g.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/40",children:g.jsxs("div",{className:"mx-4 w-full max-w-sm rounded-xl bg-white shadow-xl",children:[g.jsxs("div",{className:"px-6 py-5",children:[g.jsx("h3",{className:"mb-2 text-base font-semibold text-gray-900",children:i("agent.deleteConfirmTitle")}),g.jsx("p",{className:"text-sm text-gray-600",children:i("agent.deleteConfirmMsg",{id:t.id,name:t.name})}),g.jsx("p",{className:"mt-2 text-xs text-red-500",children:i("agent.deleteWarning")})]}),g.jsxs("div",{className:"flex justify-end gap-2 px-6 pb-5",children:[g.jsx("button",{onClick:e,className:"rounded-lg bg-gray-100 px-4 py-2 text-sm font-medium text-gray-700 transition-colors hover:bg-gray-200",children:i("agent.cancel")}),g.jsxs("button",{onClick:n,disabled:r,className:"flex items-center gap-2 rounded-lg bg-red-500 px-4 py-2 text-sm font-medium text-white transition-colors hover:bg-red-600 disabled:cursor-not-allowed disabled:opacity-40",children:[r?g.jsx(ut,{size:14,className:"animate-spin"}):g.jsx($y,{size:14}),i("agent.delete")]})]})]})})}function zFe(){const{setPageHeader:t}=ur(),e=Nt(),{t:n}=me(),r=yn(F=>F.limits),i=yn(F=>F.limitsLoading),s=yn(F=>F.fetchLimits),[o,a]=T.useState([]),[l,c]=T.useState(!0),[u,h]=T.useState(null),[f,d]=T.useState({}),[p,m]=T.useState(!1),[y,x]=T.useState(null),[b,k]=T.useState(!1),w=T.useMemo(()=>AFe(o),[o]),v=r==null?void 0:r.agentsPerWorkspace,C=v!==void 0&&v!==-1&&o.length>=v,S=i||!r||C,E=C&&r?n("limits.banner.agent.title",{current:o.length,limit:r.agentsPerWorkspace}):void 0,M=T.useCallback(async()=>{c(!0),h(null);try{const F=await fe.getAgents();a(F.agents)}catch(F){h(F instanceof Error?F.message:n("agent.listError"))}finally{c(!1)}},[n]);T.useEffect(()=>{t({title:n("agent.management")}),M()},[]),T.useEffect(()=>{s().catch(()=>{})},[s]),T.useEffect(()=>{if(l||u)return;const F=$Fe(w);if(typeof window>"u"){d(F),m(!0);return}let z=F;const D=window.localStorage.getItem(Bv);if(D)try{const O=JSON.parse(D);z=w.reduce((N,$)=>(N[$.teamKey]=typeof O[$.teamKey]=="boolean"?O[$.teamKey]:F[$.teamKey],N),{})}catch{window.localStorage.removeItem(Bv),z=F}d(z),m(!0)},[u,w,l]),T.useEffect(()=>{!p||typeof window>"u"||window.localStorage.setItem(Bv,JSON.stringify(f))},[p,f]);const A=T.useCallback(async()=>{if(y){k(!0);try{await fe.deleteAgent(y.id),x(null),await M()}catch(F){alert(F instanceof Error?F.message:n("agent.deleteError"))}finally{k(!1)}}},[y,M,n]),B=T.useCallback(F=>{d(z=>({...z,[F]:!z[F]}))},[]);return g.jsxs("div",{className:"mx-auto max-w-4xl",children:[g.jsxs("div",{className:"mb-6 flex items-center justify-between",children:[g.jsxs("div",{className:"flex items-center gap-2",children:[g.jsx(Ka,{size:20,className:"text-gray-500"}),g.jsx("h2",{className:"text-lg font-semibold text-gray-900",children:n("agent.management")}),!l&&g.jsx("span",{className:"text-sm text-gray-400",children:n("agent.count",{count:o.length})})]}),g.jsxs("button",{type:"button",disabled:S,title:E,onClick:()=>e("/agents/new"),className:`flex items-center gap-2 rounded-lg px-4 py-2 text-sm font-medium transition-colors ${S?"bg-gray-100 text-gray-400":"bg-blue-500 text-white hover:bg-blue-600"}`,children:[g.jsx(Kr,{size:16}),n("agent.add")]})]}),!l&&!u&&C&&r?g.jsx("div",{className:"mb-6",children:g.jsx(f_,{resource:"agent",current:o.length,limit:r.agentsPerWorkspace})}):null,l&&g.jsx("div",{className:"flex items-center justify-center py-16",children:g.jsx(ut,{size:24,className:"animate-spin text-gray-400"})}),!l&&u&&g.jsxs("div",{className:"flex items-center gap-3 rounded-xl border border-red-200 bg-red-50 p-4 text-red-600",children:[g.jsx(Rn,{size:18,className:"shrink-0"}),g.jsxs("div",{children:[g.jsx("p",{className:"text-sm font-medium",children:n("agent.loadFailTitle")}),g.jsx("p",{className:"mt-0.5 text-xs",children:u})]}),g.jsx("button",{onClick:M,className:"ml-auto text-xs text-red-500 underline hover:text-red-700",children:n("agent.retry")})]}),!l&&!u&&o.length===0&&g.jsxs("div",{className:"flex flex-col items-center justify-center py-16 text-gray-400",children:[g.jsx(Ka,{size:40,className:"mb-3 opacity-30"}),g.jsx("p",{className:"text-sm font-medium",children:n("agent.emptyTitle")}),g.jsx("p",{className:"mt-1 text-xs",children:n("agent.emptyDesc")}),g.jsxs("button",{type:"button",disabled:S,title:E,onClick:()=>e("/agents/new"),className:`mt-4 flex items-center gap-1.5 rounded-lg px-4 py-2 text-sm font-medium transition-colors ${S?"bg-gray-100 text-gray-400":"bg-blue-500 text-white hover:bg-blue-600"}`,children:[g.jsx(Kr,{size:16}),n("agent.emptyAction")]})]}),!l&&!u&&o.length>0&&g.jsx("div",{className:"space-y-4",children:w.map(F=>{const z=f[F.teamKey]??w.length<=5;return g.jsx("section",{children:g.jsxs("div",{className:"overflow-hidden rounded-xl border border-gray-200 bg-white shadow-sm",children:[g.jsx(EFe,{teamName:F.isUnassigned?n("agent.team.unassigned"):F.teamKey,memberCount:F.agents.length,isCollapsible:!0,isExpanded:z,onToggle:()=>B(F.teamKey),className:"rounded-none border-0 border-b border-gray-100 bg-transparent px-5 py-4 shadow-none hover:border-gray-100 hover:bg-gray-50"}),g.jsx("div",{className:"grid transition-[grid-template-rows,opacity] duration-300 ease-out",style:{gridTemplateRows:z?"1fr":"0fr",opacity:z?1:.7},children:g.jsx("div",{className:"min-h-0 overflow-hidden",children:g.jsx("div",{className:"divide-y divide-gray-100",children:F.agents.map(D=>{var I,P,L;const{bg:O,text:N}=FFe(D.id),$=[D.role,wf(D.provider,n),oy(D.model,n)].filter(Boolean).join(" · ");return g.jsxs("div",{className:"group flex items-center gap-4 px-5 py-4 transition-colors hover:bg-gray-50",children:[g.jsxs("div",{className:"relative shrink-0",children:[g.jsx("div",{className:`flex h-10 w-10 items-center justify-center rounded-full text-sm font-bold ${O} ${N}`,children:PFe(D.name)}),((I=D.provider)==null?void 0:I.startsWith("remote/"))&&g.jsx("div",{className:`absolute -bottom-1 -right-1 flex h-5 w-5 items-center justify-center rounded-full border border-white ${(P=D.providerLocation)!=null&&P.startsWith("file://")?"bg-gray-600":"bg-gray-700"}`,children:(L=D.providerLocation)!=null&&L.startsWith("file://")?g.jsx(gre,{size:11,className:"text-gray-300"}):g.jsx(Lne,{size:11,className:"text-blue-300"})})]}),g.jsxs("div",{className:"min-w-0 flex-1",children:[g.jsxs("div",{className:"flex items-center gap-2",children:[g.jsx("span",{className:"truncate text-sm font-semibold text-gray-900",children:D.name}),g.jsxs("span",{className:"truncate text-xs text-gray-400",children:["@",D.id]})]}),$&&g.jsx("p",{className:"mt-0.5 truncate text-xs text-gray-500",children:$}),D.description&&g.jsx("p",{className:"mt-0.5 truncate text-xs text-gray-400",children:D.description})]}),g.jsxs("div",{className:"flex shrink-0 items-center gap-1 opacity-0 transition-opacity group-hover:opacity-100",children:[g.jsxs("button",{onClick:()=>e(`/agents/new?from=${encodeURIComponent(D.id)}`),className:"flex items-center gap-1.5 rounded-lg bg-blue-50 px-3 py-1.5 text-xs font-medium text-blue-700 transition-colors hover:bg-blue-100",children:[g.jsx(yg,{size:13}),n("agent.duplicate")]}),g.jsxs("button",{onClick:()=>e(`/agents/${D.id}/edit`),className:"flex items-center gap-1.5 rounded-lg bg-gray-100 px-3 py-1.5 text-xs font-medium text-gray-600 transition-colors hover:bg-gray-200",children:[g.jsx(lie,{size:13}),n("agent.edit")]}),g.jsxs("button",{onClick:()=>x(D),className:"flex items-center gap-1.5 rounded-lg bg-red-50 px-3 py-1.5 text-xs font-medium text-red-600 transition-colors hover:bg-red-100",children:[g.jsx($y,{size:13}),n("agent.delete")]})]})]},D.id)})})})})]})},F.teamKey)})}),y&&g.jsx(jFe,{agent:y,onClose:()=>x(null),onConfirm:A,deleting:b,t:n})]})}const HFe=T.lazy(()=>et(()=>import("./PromptTab-sX4AsLbK.js"),[],import.meta.url));function UFe(t){return t.trim()?t:""}function iY(t){return{include:[...t]}}function WFe(t,e){return{id:t.id.trim(),name:t.name.trim(),role:t.role.trim(),team:t.team.trim(),description:t.description.trim(),provider:t.provider||void 0,model:t.model||void 0,prompt:UFe(t.prompt),skills:iY(e)}}function m4(t){return typeof t=="object"&&t!==null}function qFe(t){if(!(t instanceof Ql))return"UNKNOWN";if(m4(t.body)){if(typeof t.body.code=="string")return t.body.code;if(m4(t.body.error)&&typeof t.body.error.code=="string")return t.body.error.code}return"UNKNOWN"}function y4(){var ct;const t=Nt(),{agentId:e}=Kh(),[n]=mg(),{setPageHeader:r}=ur(),{t:i}=me(),s=ul(ne=>ne.addToast),o=((ct=n.get("from"))==null?void 0:ct.trim())||null,a=!!e,l=!a&&!!o,c=!a&&!l,u=e??o,{form:h,skills:f,activeTab:d,selectedTemplateId:p,setActiveTab:m,setField:y,setProvider:x,setSkillsInclude:b,initializeBlank:k,initializeFromAgent:w,applyTemplate:v,reset:C}=BFe(),[S,E]=T.useState(!!u),[M,A]=T.useState(!1),[B,F]=T.useState(null),[z,D]=T.useState(null),[O,N]=T.useState([]),[$,I]=T.useState(!0),[P,L]=T.useState(null),[W,G]=T.useState(0),j=h.provider.startsWith("remote/"),V=a&&j,Z=T.useMemo(()=>!h.provider||Yd.includes(h.provider)?[...Yd]:h.provider.startsWith("cli/")?[h.provider,...Yd]:[...Yd],[h.provider]),re=T.useMemo(()=>IFe(h.provider),[h.provider]),ve=h.provider?nY[h.provider]:void 0,Ee=!!h.model&&!re.includes(h.model),qe=wf(h.provider,i),he=T.useMemo(()=>O.filter(ne=>ne.source!=="builtin"),[O]);T.useEffect(()=>{r({title:i(a?"agent.edit":"agent.add")})},[a,r]),T.useEffect(()=>()=>C(),[C]);const be=T.useCallback(ne=>{w(ne,{clearIdentity:l,skills:ne.skills})},[w,l]);T.useEffect(()=>{let ne=!1;return(async()=>{if(F(null),!u){k(),E(!1);return}E(!0);try{const je=await fe.getAgents();if(ne)return;const Kt=je.agents.find(gn=>gn.id===u);if(!Kt){F(i("agent.notFound"));return}be(Kt)}catch(je){if(ne)return;F(je instanceof Error?je.message:i(l?"agent.duplicateError":"agent.loadError"))}finally{ne||E(!1)}})(),()=>{ne=!0}},[be,k,l,u]),T.useEffect(()=>{let ne=!1;return(async()=>{I(!0),L(null);try{const je=await fe.getInstalledSkills();if(ne)return;N(je.skills)}catch(je){if(ne)return;L(je instanceof Error?je.message:i("agent.skills.loadError"))}finally{ne||I(!1)}})(),()=>{ne=!0}},[W]);const Ve=T.useCallback(ne=>{const Ge=f.include.includes(ne)?f.include.filter(je=>je!==ne):[...f.include,ne];b(Ge)},[b,f.include]),te=ne=>Ge=>{if(ne==="provider"){x(Ge.target.value);return}y(ne,Ge.target.value)},$e=ne=>{v(ne)},ee=async ne=>{ne.preventDefault(),A(!0),D(null);try{const Ge=WFe(h,f.include);if(a&&e){const je={name:Ge.name,role:Ge.role,team:Ge.team,description:Ge.description,provider:Ge.provider,model:Ge.model,prompt:Ge.prompt,skills:iY(f.include)};await fe.updateAgent(e,je)}else await fe.createAgent(Ge);t("/agents")}catch(Ge){const je=qFe(Ge);if(!a&&je==="AGENT_LIMIT_EXCEEDED"){D(je),s({type:"error",duration:1e4,message:g.jsxs("div",{className:"space-y-2",children:[g.jsx("div",{children:i("agent.createError.AGENT_LIMIT_EXCEEDED")}),g.jsx("a",{href:_p,target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center text-sm font-medium text-red-700 underline underline-offset-2 transition-colors hover:text-red-800",children:i("upgrade.waitlistCta")})]})});return}alert(Ge instanceof Error?Ge.message:i("agent.saveError"))}finally{A(!1)}},ge="w-full rounded-lg border border-gray-300 bg-white px-3 py-2.5 text-sm text-gray-900 placeholder-gray-400 shadow-sm transition focus:border-blue-500 focus:outline-none focus:ring-2 focus:ring-blue-500/20",ze="bg-gray-100 text-gray-500 cursor-not-allowed",ce="mb-1.5 block text-sm font-medium text-gray-700",Ut="rounded-xl border border-gray-200 bg-white p-6 shadow-sm";return S?g.jsx("div",{className:"flex items-center justify-center py-24",children:g.jsx(ut,{size:28,className:"animate-spin text-gray-400"})}):B?g.jsxs("div",{className:"mx-auto max-w-3xl px-4 py-8",children:[g.jsx("p",{className:"text-sm text-red-500",children:B}),g.jsx("button",{onClick:()=>t("/agents"),className:"mt-4 text-sm text-gray-500 underline transition hover:text-gray-900",children:i("agent.backToList")})]}):g.jsxs("div",{className:`mx-auto px-4 py-6 text-gray-900 ${d==="prompt"?"max-w-6xl":"max-w-3xl"}`,children:[g.jsxs("div",{className:"mb-6 flex items-center gap-3",children:[g.jsx("button",{onClick:()=>t("/agents"),className:"flex h-9 w-9 items-center justify-center rounded-lg border border-gray-200 bg-white text-gray-500 shadow-sm transition hover:bg-gray-50 hover:text-gray-900","aria-label":i("agent.back"),children:g.jsx(LT,{size:18})}),g.jsxs("div",{children:[g.jsx("h1",{className:"text-xl font-semibold text-gray-900",children:i(a?"agent.edit":"agent.add")}),l&&o&&g.jsxs("p",{className:"mt-1 text-sm text-gray-500",children:["@",o]})]})]}),c&&g.jsxs("section",{className:`${Ut} mb-5`,children:[g.jsxs("div",{className:"mb-4",children:[g.jsx("h2",{className:"text-sm font-semibold text-gray-900",children:i("agent.template.title")}),g.jsx("p",{className:"mt-1 text-sm text-gray-500",children:i("agent.template.subtitle")})]}),g.jsxs("div",{className:"flex flex-wrap gap-2.5",children:[rY.map(ne=>{const Ge=p===ne.id;return g.jsxs("button",{type:"button",onClick:()=>$e(ne.id),className:`inline-flex items-center gap-2 rounded-full border px-3.5 py-2 text-sm font-medium transition ${Ge?"border-blue-500 bg-blue-50 text-blue-700":"border-gray-200 bg-white text-gray-700 hover:border-gray-300 hover:bg-gray-50"}`,children:[g.jsx("span",{"aria-hidden":"true",children:ne.icon}),g.jsx("span",{children:i(ne.titleKey)})]},ne.id)}),g.jsx("button",{type:"button",onClick:()=>$e(null),className:`inline-flex items-center gap-2 rounded-full border px-3.5 py-2 text-sm font-medium transition ${p===null?"border-blue-500 bg-blue-50 text-blue-700":"border-dashed border-gray-300 bg-white text-gray-600 hover:border-gray-400 hover:bg-gray-50"}`,children:g.jsx("span",{children:i("agent.template.direct")})})]})]}),z==="AGENT_LIMIT_EXCEEDED"?g.jsxs("div",{className:"mb-5 rounded-xl border border-red-200 bg-red-50 px-4 py-4 text-sm text-red-700",children:[g.jsx("p",{children:i("agent.createError.AGENT_LIMIT_EXCEEDED")}),g.jsx("a",{href:_p,target:"_blank",rel:"noopener noreferrer",className:"mt-3 inline-flex items-center gap-1 text-sm font-medium text-red-700 transition-colors hover:text-red-800 hover:underline",children:i("upgrade.waitlistCta")})]}):null,g.jsxs("form",{onSubmit:ee,className:"space-y-5",children:[g.jsxs("div",{className:"overflow-hidden rounded-xl border border-gray-200 bg-white shadow-sm",children:[g.jsxs("div",{className:"flex border-b border-gray-200",children:[g.jsx("button",{type:"button",onClick:()=>m("basic"),className:`px-5 py-3 text-sm font-medium transition ${d==="basic"?"border-b-2 border-blue-500 text-blue-600":"text-gray-500 hover:text-gray-900"}`,children:i("agent.tab.basic")}),g.jsx("button",{type:"button",onClick:()=>m("skills"),className:`px-5 py-3 text-sm font-medium transition ${d==="skills"?"border-b-2 border-blue-500 text-blue-600":"text-gray-500 hover:text-gray-900"}`,children:i("agent.tab.skills")}),g.jsx("button",{type:"button",onClick:()=>m("prompt"),className:`px-5 py-3 text-sm font-medium transition ${d==="prompt"?"border-b-2 border-blue-500 text-blue-600":"text-gray-500 hover:text-gray-900"}`,children:i("agent.tab.prompt")})]}),g.jsx("div",{className:"p-6",children:d==="basic"?g.jsxs("div",{className:"space-y-5",children:[g.jsxs("div",{children:[g.jsx("h2",{className:"text-base font-semibold text-gray-900",children:i("agent.section.basicTitle")}),g.jsx("p",{className:"mt-1 text-sm text-gray-500",children:i("agent.section.basicDescription")})]}),g.jsxs("div",{children:[g.jsxs("label",{className:ce,children:[i("agent.field.id")," ",!a&&g.jsx("span",{className:"text-red-500",children:"*"})]}),g.jsx("input",{type:"text",value:h.id,onChange:te("id"),placeholder:i("agent.field.idPlaceholder"),required:!a,disabled:a,className:`${ge} ${a?ze:""}`}),!a&&g.jsx("p",{className:"mt-1.5 text-xs text-gray-500",children:i("agent.field.idHint")})]}),g.jsxs("div",{children:[g.jsxs("label",{className:ce,children:[i("agent.field.name")," ",g.jsx("span",{className:"text-red-500",children:"*"})]}),g.jsx("input",{type:"text",value:h.name,onChange:te("name"),placeholder:i("agent.field.namePlaceholder"),required:!0,className:ge})]}),g.jsxs("div",{children:[g.jsx("label",{className:ce,children:i("agent.field.role")}),g.jsx("input",{type:"text",value:h.role,onChange:te("role"),placeholder:i("agent.field.rolePlaceholder"),className:ge})]}),g.jsxs("div",{children:[g.jsx("label",{className:ce,children:i("agent.field.team")}),g.jsx("input",{type:"text",value:h.team,onChange:te("team"),placeholder:i("agent.field.teamPlaceholder"),className:ge})]}),g.jsxs("div",{children:[g.jsxs("div",{className:"mb-1.5 flex items-center gap-1.5",children:[g.jsx("span",{className:"text-sm font-medium text-gray-700",children:i("agent.field.provider")}),g.jsxs("div",{className:"group/provider relative",children:[g.jsx(JC,{size:14,className:"cursor-help text-gray-400 transition hover:text-gray-600"}),g.jsxs("div",{className:"pointer-events-none absolute left-0 top-full z-50 mt-2 hidden min-w-[280px] rounded-lg border border-gray-200 bg-white p-4 text-xs text-gray-700 shadow-lg group-hover/provider:block",children:[g.jsx("p",{className:"mb-2 font-semibold text-gray-900",children:i("agent.guide.providerTitle")}),Yd.map(ne=>g.jsxs("div",{className:"mb-1.5 last:mb-0",children:[g.jsx("span",{className:"font-semibold text-gray-900",children:wf(ne,i)}),g.jsxs("span",{className:"text-gray-500",children:[" — ",i(MFe[ne])]})]},ne))]})]})]}),V?g.jsx("input",{type:"text",value:wf(h.provider,i),disabled:!0,className:`${ge} ${ze}`}):g.jsxs("select",{value:h.provider,onChange:te("provider"),className:ge,children:[g.jsx("option",{value:"",children:i("agent.field.selectProvider")}),Z.map(ne=>g.jsx("option",{value:ne,children:wf(ne,i)},ne))]})]}),g.jsxs("div",{children:[g.jsxs("div",{className:"mb-1.5 flex items-center gap-1.5",children:[g.jsx("span",{className:"text-sm font-medium text-gray-700",children:i("agent.field.model")}),g.jsxs("div",{className:"group/model relative",children:[g.jsx(JC,{size:14,className:"cursor-help text-gray-400 transition hover:text-gray-600"}),g.jsx("div",{className:"pointer-events-none absolute left-0 top-full z-50 mt-2 hidden min-w-[320px] rounded-lg border border-gray-200 bg-white p-4 text-xs text-gray-700 shadow-lg group-hover/model:block",children:h.provider&&re.length>0?g.jsxs(g.Fragment,{children:[g.jsx("p",{className:"mb-2 font-semibold text-gray-900",children:i("agent.guide.modelTitle",{provider:qe})}),re.map(ne=>{const Ge=ve===ne;return g.jsxs("div",{className:"mb-1.5 last:mb-0",children:[g.jsxs("span",{className:"font-semibold text-gray-900",children:[Ge?"⭐ ":"",oy(ne,i),Ge?` (${i("agent.field.recommended")})`:""]}),g.jsxs("span",{className:"text-gray-500",children:[" ","— ",i(`agent.model.${ne}.cost`)," · ",i(`agent.model.${ne}.desc`)]})]},ne)})]}):g.jsx("p",{className:"text-gray-500",children:i("agent.field.selectProviderFirst")})})]})]}),V?g.jsx("input",{type:"text",value:oy(h.model,i)||h.model,disabled:!0,className:`${ge} ${ze}`}):g.jsxs("select",{value:h.model,onChange:te("model"),disabled:!h.provider,className:`${ge} ${h.provider?"":ze}`,children:[g.jsx("option",{value:"",children:h.provider?i("agent.field.selectModel"):i("agent.field.selectProviderFirst")}),Ee&&g.jsxs("option",{value:h.model,children:[h.model," (",i("agent.field.custom"),")"]}),re.map(ne=>{const Ge=ve===ne,je=oy(ne,i);let Kt="";if(h.provider==="cli/copilot"){const gn=OFe[ne];gn&&(Kt=` — ${gn}`)}else{const gn=`agent.model.${ne}.cost`,U=i(gn);Kt=U!==gn?` — ${U}`:""}return g.jsx("option",{value:ne,children:Ge?`⭐ ${je} (${i("agent.field.recommended")})${Kt}`:`${je}${Kt}`},ne)})]})]}),g.jsxs("div",{children:[g.jsx("label",{className:ce,children:i("agent.field.description")}),g.jsx("textarea",{value:h.description,onChange:te("description"),placeholder:i("agent.field.descPlaceholder"),rows:5,className:`${ge} resize-none`})]})]}):d==="skills"?g.jsxs("div",{className:"space-y-4",children:[g.jsxs("div",{children:[g.jsx("h2",{className:"text-base font-semibold text-gray-900",children:i("agent.section.skillsTitle")}),g.jsx("p",{className:"mt-1 text-sm text-gray-500",children:i("agent.section.skillsDescription")})]}),$?g.jsx("div",{className:"flex items-center justify-center py-20",children:g.jsx(ut,{size:24,className:"animate-spin text-gray-400"})}):P?g.jsxs("div",{className:"rounded-xl border border-red-200 bg-red-50 px-4 py-4 text-sm text-red-700",children:[g.jsx("p",{children:P}),g.jsx("button",{type:"button",onClick:()=>G(ne=>ne+1),className:"mt-3 font-medium underline underline-offset-2 transition hover:text-red-800",children:i("agent.retry")})]}):he.length===0?g.jsx("div",{className:"rounded-xl border border-gray-200 bg-white px-6 py-16",children:g.jsxs("div",{className:"mx-auto flex max-w-xl flex-col items-center text-center",children:[g.jsx("div",{className:"mb-5 rounded-full bg-gray-100 p-4 text-gray-500",children:g.jsx(gF,{size:40,strokeWidth:1.8})}),g.jsx("h3",{className:"text-3xl font-semibold tracking-tight text-gray-900",children:i("agent.skills.emptyTitle")}),g.jsx("p",{className:"mt-4 text-lg leading-8 text-gray-500",children:i("agent.skills.emptyDescription")}),g.jsxs("button",{type:"button",onClick:()=>t("/market"),className:"mt-8 inline-flex items-center gap-2 rounded-2xl border border-gray-200 bg-white px-6 py-3 text-base font-semibold text-gray-900 shadow-sm transition hover:bg-gray-50",children:[g.jsx(o1,{size:18}),i("agent.skills.openMarket")]})]})}):g.jsx("div",{className:"overflow-hidden rounded-xl border border-gray-200 bg-white",children:g.jsx("div",{className:"max-h-[420px] overflow-y-auto",children:he.map((ne,Ge)=>{const je=f.include.includes(ne.name);return g.jsxs("label",{className:`flex cursor-pointer items-start gap-4 px-4 py-4 transition hover:bg-gray-50 ${Ge>0?"border-t border-gray-200":""}`,children:[g.jsx("input",{type:"checkbox",checked:je,onChange:()=>Ve(ne.name),"aria-label":ne.name,className:"mt-0.5 h-5 w-5 rounded border-gray-300 text-gray-900 focus:ring-gray-900"}),g.jsxs("div",{className:"min-w-0",children:[g.jsx("div",{className:"text-base font-semibold text-gray-900",children:ne.name}),ne.description?g.jsx("p",{className:"mt-1 text-sm text-gray-500",children:ne.description}):null]})]},ne.name)})})})]}):g.jsx(T.Suspense,{fallback:g.jsx("div",{className:"flex items-center justify-center py-24",children:g.jsx(ut,{size:28,className:"animate-spin text-gray-400"})}),children:g.jsx(HFe,{previewAgentId:u})})})]}),g.jsxs("div",{className:"flex items-center justify-end gap-3 border-t border-gray-200 pt-4",children:[g.jsx("button",{type:"button",onClick:()=>t("/agents"),className:"rounded-lg border border-gray-200 bg-white px-5 py-2.5 text-sm font-medium text-gray-700 shadow-sm transition hover:bg-gray-50 hover:text-gray-900",children:i("agent.cancel")}),g.jsxs("button",{type:"submit",disabled:M||!a&&!h.id.trim()||!h.name.trim(),className:"inline-flex items-center gap-2 rounded-lg bg-blue-500 px-5 py-2.5 text-sm font-medium text-white transition hover:bg-blue-600 disabled:cursor-not-allowed disabled:opacity-40",children:[M?g.jsx(ut,{size:15,className:"animate-spin"}):g.jsx(mF,{size:15}),i(a?"agent.save":"agent.add")]})]})]})]})}function sY({node:t,depth:e=0,expandedFolders:n,onToggle:r,onSelect:i,selectedPath:s,isFileDisabled:o,renderFileSuffix:a}){var p;const l=n.has(t.path),c=s===t.path,u=t.type==="dir",h=u&&(t.hasCrewxYaml!==void 0||t.isRegistered!==void 0),f=(!u||h)&&((o==null?void 0:o(t))??!1),d=()=>{if(u){f||r(t.path);return}f||i(t.path)};return g.jsxs("div",{children:[g.jsxs("button",{type:"button",onClick:d,disabled:f,style:{paddingLeft:`${8+e*16}px`},className:`flex w-full items-center gap-1.5 py-1 pr-2 text-left text-sm transition-colors ${c?"bg-blue-50 font-medium text-blue-700":"text-gray-700 hover:bg-gray-100"} ${f?"cursor-not-allowed opacity-50 hover:bg-transparent":""}`,children:[u?g.jsxs(g.Fragment,{children:[l?g.jsx(Yr,{className:"h-3.5 w-3.5 shrink-0 text-gray-400"}):g.jsx(hs,{className:"h-3.5 w-3.5 shrink-0 text-gray-400"}),l?g.jsx(is,{className:"h-4 w-4 shrink-0 text-amber-500"}):g.jsx(Zne,{className:"h-4 w-4 shrink-0 text-amber-500"})]}):g.jsxs(g.Fragment,{children:[g.jsx("span",{className:"w-3.5 shrink-0"}),g.jsx(Uo,{className:"h-4 w-4 shrink-0 text-gray-400"})]}),g.jsx("span",{className:"min-w-0 flex-1 truncate",children:t.name}),!u||h?a==null?void 0:a(t):null]}),u&&l&&((p=t.children)!=null&&p.length)?g.jsx("div",{children:t.children.map(m=>g.jsx(sY,{node:m,depth:e+1,expandedFolders:n,onToggle:r,onSelect:i,selectedPath:s,isFileDisabled:o,renderFileSuffix:a},m.path))}):null]})}function oY({nodes:t,expandedFolders:e,onToggle:n,onSelect:r,selectedPath:i,isFileDisabled:s,renderFileSuffix:o}){return g.jsx("div",{children:t.map(a=>g.jsx(sY,{node:a,expandedFolders:e,onToggle:n,onSelect:r,selectedPath:i,isFileDisabled:s,renderFileSuffix:o},a.path))})}let p_,g_;if(typeof WeakMap<"u"){let t=new WeakMap;p_=e=>t.get(e),g_=(e,n)=>(t.set(e,n),n)}else{const t=[];let n=0;p_=r=>{for(let i=0;i<t.length;i+=2)if(t[i]==r)return t[i+1]},g_=(r,i)=>(n==10&&(n=0),t[n++]=r,t[n++]=i)}var en=class{constructor(t,e,n,r){this.width=t,this.height=e,this.map=n,this.problems=r}findCell(t){for(let e=0;e<this.map.length;e++){const n=this.map[e];if(n!=t)continue;const r=e%this.width,i=e/this.width|0;let s=r+1,o=i+1;for(let a=1;s<this.width&&this.map[e+a]==n;a++)s++;for(let a=1;o<this.height&&this.map[e+this.width*a]==n;a++)o++;return{left:r,top:i,right:s,bottom:o}}throw new RangeError(`No cell with offset ${t} found`)}colCount(t){for(let e=0;e<this.map.length;e++)if(this.map[e]==t)return e%this.width;throw new RangeError(`No cell with offset ${t} found`)}nextCell(t,e,n){const{left:r,right:i,top:s,bottom:o}=this.findCell(t);return e=="horiz"?(n<0?r==0:i==this.width)?null:this.map[s*this.width+(n<0?r-1:i)]:(n<0?s==0:o==this.height)?null:this.map[r+this.width*(n<0?s-1:o)]}rectBetween(t,e){const{left:n,right:r,top:i,bottom:s}=this.findCell(t),{left:o,right:a,top:l,bottom:c}=this.findCell(e);return{left:Math.min(n,o),top:Math.min(i,l),right:Math.max(r,a),bottom:Math.max(s,c)}}cellsInRect(t){const e=[],n={};for(let r=t.top;r<t.bottom;r++)for(let i=t.left;i<t.right;i++){const s=r*this.width+i,o=this.map[s];n[o]||(n[o]=!0,!(i==t.left&&i&&this.map[s-1]==o||r==t.top&&r&&this.map[s-this.width]==o)&&e.push(o))}return e}positionAt(t,e,n){for(let r=0,i=0;;r++){const s=i+n.child(r).nodeSize;if(r==t){let o=e+t*this.width;const a=(t+1)*this.width;for(;o<a&&this.map[o]<i;)o++;return o==a?s-1:this.map[o]}i=s}}static get(t){return p_(t)||g_(t,VFe(t))}};function VFe(t){if(t.type.spec.tableRole!="table")throw new RangeError("Not a table node: "+t.type.name);const e=GFe(t),n=t.childCount,r=[];let i=0,s=null;const o=[];for(let c=0,u=e*n;c<u;c++)r[c]=0;for(let c=0,u=0;c<n;c++){const h=t.child(c);u++;for(let p=0;;p++){for(;i<r.length&&r[i]!=0;)i++;if(p==h.childCount)break;const m=h.child(p),{colspan:y,rowspan:x,colwidth:b}=m.attrs;for(let k=0;k<x;k++){if(k+c>=n){(s||(s=[])).push({type:"overlong_rowspan",pos:u,n:x-k});break}const w=i+k*e;for(let v=0;v<y;v++){r[w+v]==0?r[w+v]=u:(s||(s=[])).push({type:"collision",row:c,pos:u,n:y-v});const C=b&&b[v];if(C){const S=(w+v)%e*2,E=o[S];E==null||E!=C&&o[S+1]==1?(o[S]=C,o[S+1]=1):E==C&&o[S+1]++}}}i+=y,u+=m.nodeSize}const f=(c+1)*e;let d=0;for(;i<f;)r[i++]==0&&d++;d&&(s||(s=[])).push({type:"missing",row:c,n:d}),u++}(e===0||n===0)&&(s||(s=[])).push({type:"zero_sized"});const a=new en(e,n,r,s);let l=!1;for(let c=0;!l&&c<o.length;c+=2)o[c]!=null&&o[c+1]<n&&(l=!0);return l&&YFe(a,o,t),a}function GFe(t){let e=-1,n=!1;for(let r=0;r<t.childCount;r++){const i=t.child(r);let s=0;if(n)for(let o=0;o<r;o++){const a=t.child(o);for(let l=0;l<a.childCount;l++){const c=a.child(l);o+c.attrs.rowspan>r&&(s+=c.attrs.colspan)}}for(let o=0;o<i.childCount;o++){const a=i.child(o);s+=a.attrs.colspan,a.attrs.rowspan>1&&(n=!0)}e==-1?e=s:e!=s&&(e=Math.max(e,s))}return e}function YFe(t,e,n){t.problems||(t.problems=[]);const r={};for(let i=0;i<t.map.length;i++){const s=t.map[i];if(r[s])continue;r[s]=!0;const o=n.nodeAt(s);if(!o)throw new RangeError(`No cell with offset ${s} found`);let a=null;const l=o.attrs;for(let c=0;c<l.colspan;c++){const u=e[(i+c)%t.width*2];u!=null&&(!l.colwidth||l.colwidth[c]!=u)&&((a||(a=KFe(l)))[c]=u)}a&&t.problems.unshift({type:"colwidth mismatch",pos:s,colwidth:a})}}function KFe(t){if(t.colwidth)return t.colwidth.slice();const e=[];for(let n=0;n<t.colspan;n++)e.push(0);return e}function lr(t){let e=t.cached.tableNodeTypes;if(!e){e=t.cached.tableNodeTypes={};for(const n in t.nodes){const r=t.nodes[n],i=r.spec.tableRole;i&&(e[i]=r)}}return e}const pa=new Ct("selectingCells");function Dc(t){for(let e=t.depth-1;e>0;e--)if(t.node(e).type.spec.tableRole=="row")return t.node(0).resolve(t.before(e+1));return null}function XFe(t){for(let e=t.depth;e>0;e--){const n=t.node(e).type.spec.tableRole;if(n==="cell"||n==="header_cell")return t.node(e)}return null}function ms(t){const e=t.selection.$head;for(let n=e.depth;n>0;n--)if(e.node(n).type.spec.tableRole=="row")return!0;return!1}function lk(t){const e=t.selection;if("$anchorCell"in e&&e.$anchorCell)return e.$anchorCell.pos>e.$headCell.pos?e.$anchorCell:e.$headCell;if("node"in e&&e.node&&e.node.type.spec.tableRole=="cell")return e.$anchor;const n=Dc(e.$head)||ZFe(e.$head);if(n)return n;throw new RangeError(`No cell found around position ${e.head}`)}function ZFe(t){for(let e=t.nodeAfter,n=t.pos;e;e=e.firstChild,n++){const r=e.type.spec.tableRole;if(r=="cell"||r=="header_cell")return t.doc.resolve(n)}for(let e=t.nodeBefore,n=t.pos;e;e=e.lastChild,n--){const r=e.type.spec.tableRole;if(r=="cell"||r=="header_cell")return t.doc.resolve(n-e.nodeSize)}}function m_(t){return t.parent.type.spec.tableRole=="row"&&!!t.nodeAfter}function QFe(t){return t.node(0).resolve(t.pos+t.nodeAfter.nodeSize)}function EN(t,e){return t.depth==e.depth&&t.pos>=e.start(-1)&&t.pos<=e.end(-1)}function aY(t,e,n){const r=t.node(-1),i=en.get(r),s=t.start(-1),o=i.nextCell(t.pos-s,e,n);return o==null?null:t.node(0).resolve(s+o)}function Oc(t,e,n=1){const r={...t,colspan:t.colspan-n};return r.colwidth&&(r.colwidth=r.colwidth.slice(),r.colwidth.splice(e,n),r.colwidth.some(i=>i>0)||(r.colwidth=null)),r}function lY(t,e,n=1){const r={...t,colspan:t.colspan+n};if(r.colwidth){r.colwidth=r.colwidth.slice();for(let i=0;i<n;i++)r.colwidth.splice(e,0,0)}return r}function JFe(t,e,n){const r=lr(e.type.schema).header_cell;for(let i=0;i<t.height;i++)if(e.nodeAt(t.map[n+i*t.width]).type!=r)return!1;return!0}var At=class mo extends Pe{constructor(e,n=e){const r=e.node(-1),i=en.get(r),s=e.start(-1),o=i.rectBetween(e.pos-s,n.pos-s),a=e.node(0),l=i.cellsInRect(o).filter(u=>u!=n.pos-s);l.unshift(n.pos-s);const c=l.map(u=>{const h=r.nodeAt(u);if(!h)throw new RangeError(`No cell with offset ${u} found`);const f=s+u+1;return new zq(a.resolve(f),a.resolve(f+h.content.size))});super(c[0].$from,c[0].$to,c),this.$anchorCell=e,this.$headCell=n}map(e,n){const r=e.resolve(n.map(this.$anchorCell.pos)),i=e.resolve(n.map(this.$headCell.pos));if(m_(r)&&m_(i)&&EN(r,i)){const s=this.$anchorCell.node(-1)!=r.node(-1);return s&&this.isRowSelection()?mo.rowSelection(r,i):s&&this.isColSelection()?mo.colSelection(r,i):new mo(r,i)}return Le.between(r,i)}content(){const e=this.$anchorCell.node(-1),n=en.get(e),r=this.$anchorCell.start(-1),i=n.rectBetween(this.$anchorCell.pos-r,this.$headCell.pos-r),s={},o=[];for(let l=i.top;l<i.bottom;l++){const c=[];for(let u=l*n.width+i.left,h=i.left;h<i.right;h++,u++){const f=n.map[u];if(s[f])continue;s[f]=!0;const d=n.findCell(f);let p=e.nodeAt(f);if(!p)throw new RangeError(`No cell with offset ${f} found`);const m=i.left-d.left,y=d.right-i.right;if(m>0||y>0){let x=p.attrs;if(m>0&&(x=Oc(x,0,m)),y>0&&(x=Oc(x,x.colspan-y,y)),d.left<i.left){if(p=p.type.createAndFill(x),!p)throw new RangeError(`Could not create cell with attrs ${JSON.stringify(x)}`)}else p=p.type.create(x,p.content)}if(d.top<i.top||d.bottom>i.bottom){const x={...p.attrs,rowspan:Math.min(d.bottom,i.bottom)-Math.max(d.top,i.top)};d.top<i.top?p=p.type.createAndFill(x):p=p.type.create(x,p.content)}c.push(p)}o.push(e.child(l).copy(Q.from(c)))}const a=this.isColSelection()&&this.isRowSelection()?e:o;return new de(Q.from(a),1,1)}replace(e,n=de.empty){const r=e.steps.length,i=this.ranges;for(let o=0;o<i.length;o++){const{$from:a,$to:l}=i[o],c=e.mapping.slice(r);e.replace(c.map(a.pos),c.map(l.pos),o?de.empty:n)}const s=Pe.findFrom(e.doc.resolve(e.mapping.slice(r).map(this.to)),-1);s&&e.setSelection(s)}replaceWith(e,n){this.replace(e,new de(Q.from(n),0,0))}forEachCell(e){const n=this.$anchorCell.node(-1),r=en.get(n),i=this.$anchorCell.start(-1),s=r.cellsInRect(r.rectBetween(this.$anchorCell.pos-i,this.$headCell.pos-i));for(let o=0;o<s.length;o++)e(n.nodeAt(s[o]),i+s[o])}isColSelection(){const e=this.$anchorCell.index(-1),n=this.$headCell.index(-1);if(Math.min(e,n)>0)return!1;const r=e+this.$anchorCell.nodeAfter.attrs.rowspan,i=n+this.$headCell.nodeAfter.attrs.rowspan;return Math.max(r,i)==this.$headCell.node(-1).childCount}static colSelection(e,n=e){const r=e.node(-1),i=en.get(r),s=e.start(-1),o=i.findCell(e.pos-s),a=i.findCell(n.pos-s),l=e.node(0);return o.top<=a.top?(o.top>0&&(e=l.resolve(s+i.map[o.left])),a.bottom<i.height&&(n=l.resolve(s+i.map[i.width*(i.height-1)+a.right-1]))):(a.top>0&&(n=l.resolve(s+i.map[a.left])),o.bottom<i.height&&(e=l.resolve(s+i.map[i.width*(i.height-1)+o.right-1]))),new mo(e,n)}isRowSelection(){const e=this.$anchorCell.node(-1),n=en.get(e),r=this.$anchorCell.start(-1),i=n.colCount(this.$anchorCell.pos-r),s=n.colCount(this.$headCell.pos-r);if(Math.min(i,s)>0)return!1;const o=i+this.$anchorCell.nodeAfter.attrs.colspan,a=s+this.$headCell.nodeAfter.attrs.colspan;return Math.max(o,a)==n.width}eq(e){return e instanceof mo&&e.$anchorCell.pos==this.$anchorCell.pos&&e.$headCell.pos==this.$headCell.pos}static rowSelection(e,n=e){const r=e.node(-1),i=en.get(r),s=e.start(-1),o=i.findCell(e.pos-s),a=i.findCell(n.pos-s),l=e.node(0);return o.left<=a.left?(o.left>0&&(e=l.resolve(s+i.map[o.top*i.width])),a.right<i.width&&(n=l.resolve(s+i.map[i.width*(a.top+1)-1]))):(a.left>0&&(n=l.resolve(s+i.map[a.top*i.width])),o.right<i.width&&(e=l.resolve(s+i.map[i.width*(o.top+1)-1]))),new mo(e,n)}toJSON(){return{type:"cell",anchor:this.$anchorCell.pos,head:this.$headCell.pos}}static fromJSON(e,n){return new mo(e.resolve(n.anchor),e.resolve(n.head))}static create(e,n,r=n){return new mo(e.resolve(n),e.resolve(r))}getBookmark(){return new e$e(this.$anchorCell.pos,this.$headCell.pos)}};At.prototype.visible=!1;Pe.jsonID("cell",At);var e$e=class cY{constructor(e,n){this.anchor=e,this.head=n}map(e){return new cY(e.map(this.anchor),e.map(this.head))}resolve(e){const n=e.resolve(this.anchor),r=e.resolve(this.head);return n.parent.type.spec.tableRole=="row"&&r.parent.type.spec.tableRole=="row"&&n.index()<n.parent.childCount&&r.index()<r.parent.childCount&&EN(n,r)?new At(n,r):Pe.near(r,1)}};function t$e(t){if(!(t.selection instanceof At))return null;const e=[];return t.selection.forEachCell((n,r)=>{e.push(Cn.node(r,r+n.nodeSize,{class:"selectedCell"}))}),bt.create(t.doc,e)}function n$e({$from:t,$to:e}){if(t.pos==e.pos||t.pos<e.pos-6)return!1;let n=t.pos,r=e.pos,i=t.depth;for(;i>=0&&!(t.after(i+1)<t.end(i));i--,n++);for(let s=e.depth;s>=0&&!(e.before(s+1)>e.start(s));s--,r--);return n==r&&/row|table/.test(t.node(i).type.spec.tableRole)}function r$e({$from:t,$to:e}){let n,r;for(let i=t.depth;i>0;i--){const s=t.node(i);if(s.type.spec.tableRole==="cell"||s.type.spec.tableRole==="header_cell"){n=s;break}}for(let i=e.depth;i>0;i--){const s=e.node(i);if(s.type.spec.tableRole==="cell"||s.type.spec.tableRole==="header_cell"){r=s;break}}return n!==r&&e.parentOffset===0}function i$e(t,e,n){const r=(e||t).selection,i=(e||t).doc;let s,o;if(r instanceof Me&&(o=r.node.type.spec.tableRole)){if(o=="cell"||o=="header_cell")s=At.create(i,r.from);else if(o=="row"){const a=i.resolve(r.from+1);s=At.rowSelection(a,a)}else if(!n){const a=en.get(r.node),l=r.from+1,c=l+a.map[a.width*a.height-1];s=At.create(i,l+1,c)}}else r instanceof Le&&n$e(r)?s=Le.create(i,r.from):r instanceof Le&&r$e(r)&&(s=Le.create(i,r.$from.start(),r.$from.end()));return s&&(e||(e=t.tr)).setSelection(s),e}const s$e=new Ct("fix-tables");function uY(t,e,n,r){const i=t.childCount,s=e.childCount;e:for(let o=0,a=0;o<s;o++){const l=e.child(o);for(let c=a,u=Math.min(i,o+3);c<u;c++)if(t.child(c)==l){a=c+1,n+=l.nodeSize;continue e}r(l,n),a<i&&t.child(a).sameMarkup(l)?uY(t.child(a),l,n+1,r):l.nodesBetween(0,l.content.size,r,n+1),n+=l.nodeSize}}function hY(t,e){let n;const r=(i,s)=>{i.type.spec.tableRole=="table"&&(n=o$e(t,i,s,n))};return e?e.doc!=t.doc&&uY(e.doc,t.doc,0,r):t.doc.descendants(r),n}function o$e(t,e,n,r){const i=en.get(e);if(!i.problems)return r;r||(r=t.tr);const s=[];for(let l=0;l<i.height;l++)s.push(0);for(let l=0;l<i.problems.length;l++){const c=i.problems[l];if(c.type=="collision"){const u=e.nodeAt(c.pos);if(!u)continue;const h=u.attrs;for(let f=0;f<h.rowspan;f++)s[c.row+f]+=c.n;r.setNodeMarkup(r.mapping.map(n+1+c.pos),null,Oc(h,h.colspan-c.n,c.n))}else if(c.type=="missing")s[c.row]+=c.n;else if(c.type=="overlong_rowspan"){const u=e.nodeAt(c.pos);if(!u)continue;r.setNodeMarkup(r.mapping.map(n+1+c.pos),null,{...u.attrs,rowspan:u.attrs.rowspan-c.n})}else if(c.type=="colwidth mismatch"){const u=e.nodeAt(c.pos);if(!u)continue;r.setNodeMarkup(r.mapping.map(n+1+c.pos),null,{...u.attrs,colwidth:c.colwidth})}else if(c.type=="zero_sized"){const u=r.mapping.map(n);r.delete(u,u+e.nodeSize)}}let o,a;for(let l=0;l<s.length;l++)s[l]&&(o==null&&(o=l),a=l);for(let l=0,c=n+1;l<i.height;l++){const u=e.child(l),h=c+u.nodeSize,f=s[l];if(f>0){let d="cell";u.firstChild&&(d=u.firstChild.type.spec.tableRole);const p=[];for(let y=0;y<f;y++){const x=lr(t.schema)[d].createAndFill();x&&p.push(x)}const m=(l==0||o==l-1)&&a==l?c+1:h-1;r.insert(r.mapping.map(m),p)}c=h}return r.setMeta(s$e,{fixTables:!0})}function Js(t){const e=t.selection,n=lk(t),r=n.node(-1),i=n.start(-1),s=en.get(r);return{...e instanceof At?s.rectBetween(e.$anchorCell.pos-i,e.$headCell.pos-i):s.findCell(n.pos-i),tableStart:i,map:s,table:r}}function dY(t,{map:e,tableStart:n,table:r},i){let s=i>0?-1:0;JFe(e,r,i+s)&&(s=i==0||i==e.width?null:0);for(let o=0;o<e.height;o++){const a=o*e.width+i;if(i>0&&i<e.width&&e.map[a-1]==e.map[a]){const l=e.map[a],c=r.nodeAt(l);t.setNodeMarkup(t.mapping.map(n+l),null,lY(c.attrs,i-e.colCount(l))),o+=c.attrs.rowspan-1}else{const l=s==null?lr(r.type.schema).cell:r.nodeAt(e.map[a+s]).type,c=e.positionAt(o,i,r);t.insert(t.mapping.map(n+c),l.createAndFill())}}return t}function a$e(t,e){if(!ms(t))return!1;if(e){const n=Js(t);e(dY(t.tr,n,n.left))}return!0}function l$e(t,e){if(!ms(t))return!1;if(e){const n=Js(t);e(dY(t.tr,n,n.right))}return!0}function c$e(t,{map:e,table:n,tableStart:r},i){const s=t.mapping.maps.length;for(let o=0;o<e.height;){const a=o*e.width+i,l=e.map[a],c=n.nodeAt(l),u=c.attrs;if(i>0&&e.map[a-1]==l||i<e.width-1&&e.map[a+1]==l)t.setNodeMarkup(t.mapping.slice(s).map(r+l),null,Oc(u,i-e.colCount(l)));else{const h=t.mapping.slice(s).map(r+l);t.delete(h,h+c.nodeSize)}o+=u.rowspan}}function u$e(t,e){if(!ms(t))return!1;if(e){const n=Js(t),r=t.tr;if(n.left==0&&n.right==n.map.width)return!1;for(let i=n.right-1;c$e(r,n,i),i!=n.left;i--){const s=n.tableStart?r.doc.nodeAt(n.tableStart-1):r.doc;if(!s)throw new RangeError("No table found");n.table=s,n.map=en.get(s)}e(r)}return!0}function h$e(t,e,n){var r;const i=lr(e.type.schema).header_cell;for(let s=0;s<t.width;s++)if(((r=e.nodeAt(t.map[s+n*t.width]))===null||r===void 0?void 0:r.type)!=i)return!1;return!0}function fY(t,{map:e,tableStart:n,table:r},i){let s=n;for(let c=0;c<i;c++)s+=r.child(c).nodeSize;const o=[];let a=i>0?-1:0;h$e(e,r,i+a)&&(a=i==0||i==e.height?null:0);for(let c=0,u=e.width*i;c<e.width;c++,u++)if(i>0&&i<e.height&&e.map[u]==e.map[u-e.width]){const h=e.map[u],f=r.nodeAt(h).attrs;t.setNodeMarkup(n+h,null,{...f,rowspan:f.rowspan+1}),c+=f.colspan-1}else{var l;const h=a==null?lr(r.type.schema).cell:(l=r.nodeAt(e.map[u+a*e.width]))===null||l===void 0?void 0:l.type,f=h==null?void 0:h.createAndFill();f&&o.push(f)}return t.insert(s,lr(r.type.schema).row.create(null,o)),t}function d$e(t,e){if(!ms(t))return!1;if(e){const n=Js(t);e(fY(t.tr,n,n.top))}return!0}function f$e(t,e){if(!ms(t))return!1;if(e){const n=Js(t);e(fY(t.tr,n,n.bottom))}return!0}function p$e(t,{map:e,table:n,tableStart:r},i){let s=0;for(let c=0;c<i;c++)s+=n.child(c).nodeSize;const o=s+n.child(i).nodeSize,a=t.mapping.maps.length;t.delete(s+r,o+r);const l=new Set;for(let c=0,u=i*e.width;c<e.width;c++,u++){const h=e.map[u];if(!l.has(h)){if(l.add(h),i>0&&h==e.map[u-e.width]){const f=n.nodeAt(h).attrs;t.setNodeMarkup(t.mapping.slice(a).map(h+r),null,{...f,rowspan:f.rowspan-1}),c+=f.colspan-1}else if(i<e.height&&h==e.map[u+e.width]){const f=n.nodeAt(h),d=f.attrs,p=f.type.create({...d,rowspan:f.attrs.rowspan-1},f.content),m=e.positionAt(i+1,c,n);t.insert(t.mapping.slice(a).map(r+m),p),c+=d.colspan-1}}}}function g$e(t,e){if(!ms(t))return!1;if(e){const n=Js(t),r=t.tr;if(n.top==0&&n.bottom==n.map.height)return!1;for(let i=n.bottom-1;p$e(r,n,i),i!=n.top;i--){const s=n.tableStart?r.doc.nodeAt(n.tableStart-1):r.doc;if(!s)throw new RangeError("No table found");n.table=s,n.map=en.get(n.table)}e(r)}return!0}function x4(t){const e=t.content;return e.childCount==1&&e.child(0).isTextblock&&e.child(0).childCount==0}function m$e({width:t,height:e,map:n},r){let i=r.top*t+r.left,s=i,o=(r.bottom-1)*t+r.left,a=i+(r.right-r.left-1);for(let l=r.top;l<r.bottom;l++){if(r.left>0&&n[s]==n[s-1]||r.right<t&&n[a]==n[a+1])return!0;s+=t,a+=t}for(let l=r.left;l<r.right;l++){if(r.top>0&&n[i]==n[i-t]||r.bottom<e&&n[o]==n[o+t])return!0;i++,o++}return!1}function b4(t,e){const n=t.selection;if(!(n instanceof At)||n.$anchorCell.pos==n.$headCell.pos)return!1;const r=Js(t),{map:i}=r;if(m$e(i,r))return!1;if(e){const s=t.tr,o={};let a=Q.empty,l,c;for(let u=r.top;u<r.bottom;u++)for(let h=r.left;h<r.right;h++){const f=i.map[u*i.width+h],d=r.table.nodeAt(f);if(!(o[f]||!d))if(o[f]=!0,l==null)l=f,c=d;else{x4(d)||(a=a.append(d.content));const p=s.mapping.map(f+r.tableStart);s.delete(p,p+d.nodeSize)}}if(l==null||c==null)return!0;if(s.setNodeMarkup(l+r.tableStart,null,{...lY(c.attrs,c.attrs.colspan,r.right-r.left-c.attrs.colspan),rowspan:r.bottom-r.top}),a.size>0){const u=l+1+c.content.size,h=x4(c)?l+1:u;s.replaceWith(h+r.tableStart,u+r.tableStart,a)}s.setSelection(new At(s.doc.resolve(l+r.tableStart))),e(s)}return!0}function k4(t,e){const n=lr(t.schema);return y$e(({node:r})=>n[r.type.spec.tableRole])(t,e)}function y$e(t){return(e,n)=>{const r=e.selection;let i,s;if(r instanceof At){if(r.$anchorCell.pos!=r.$headCell.pos)return!1;i=r.$anchorCell.nodeAfter,s=r.$anchorCell.pos}else{var o;if(i=XFe(r.$from),!i)return!1;s=(o=Dc(r.$from))===null||o===void 0?void 0:o.pos}if(i==null||s==null||i.attrs.colspan==1&&i.attrs.rowspan==1)return!1;if(n){let a=i.attrs;const l=[],c=a.colwidth;a.rowspan>1&&(a={...a,rowspan:1}),a.colspan>1&&(a={...a,colspan:1});const u=Js(e),h=e.tr;for(let d=0;d<u.right-u.left;d++)l.push(c?{...a,colwidth:c&&c[d]?[c[d]]:null}:a);let f;for(let d=u.top;d<u.bottom;d++){let p=u.map.positionAt(d,u.left,u.table);d==u.top&&(p+=i.nodeSize);for(let m=u.left,y=0;m<u.right;m++,y++)m==u.left&&d==u.top||h.insert(f=h.mapping.map(p+u.tableStart,1),t({node:i,row:d,col:m}).createAndFill(l[y]))}h.setNodeMarkup(s,t({node:i,row:u.top,col:u.left}),l[0]),r instanceof At&&h.setSelection(new At(h.doc.resolve(r.$anchorCell.pos),f?h.doc.resolve(f):void 0)),n(h)}return!0}}function x$e(t,e){return function(n,r){if(!ms(n))return!1;const i=lk(n);if(i.nodeAfter.attrs[t]===e)return!1;if(r){const s=n.tr;n.selection instanceof At?n.selection.forEachCell((o,a)=>{o.attrs[t]!==e&&s.setNodeMarkup(a,null,{...o.attrs,[t]:e})}):s.setNodeMarkup(i.pos,null,{...i.nodeAfter.attrs,[t]:e}),r(s)}return!0}}function b$e(t){return function(e,n){if(!ms(e))return!1;if(n){const r=lr(e.schema),i=Js(e),s=e.tr,o=i.map.cellsInRect(t=="column"?{left:i.left,top:0,right:i.right,bottom:i.map.height}:t=="row"?{left:0,top:i.top,right:i.map.width,bottom:i.bottom}:i),a=o.map(l=>i.table.nodeAt(l));for(let l=0;l<o.length;l++)a[l].type==r.header_cell&&s.setNodeMarkup(i.tableStart+o[l],r.cell,a[l].attrs);if(s.steps.length===0)for(let l=0;l<o.length;l++)s.setNodeMarkup(i.tableStart+o[l],r.header_cell,a[l].attrs);n(s)}return!0}}function w4(t,e,n){const r=e.map.cellsInRect({left:0,top:0,right:t=="row"?e.map.width:1,bottom:t=="column"?e.map.height:1});for(let i=0;i<r.length;i++){const s=e.table.nodeAt(r[i]);if(s&&s.type!==n.header_cell)return!1}return!0}function ig(t,e){return e=e||{useDeprecatedLogic:!1},e.useDeprecatedLogic?b$e(t):function(n,r){if(!ms(n))return!1;if(r){const i=lr(n.schema),s=Js(n),o=n.tr,a=w4("row",s,i),l=w4("column",s,i),c=(t==="column"?a:t==="row"&&l)?1:0,u=t=="column"?{left:0,top:c,right:1,bottom:s.map.height}:t=="row"?{left:c,top:0,right:s.map.width,bottom:1}:s,h=t=="column"?l?i.cell:i.header_cell:t=="row"?a?i.cell:i.header_cell:i.cell;s.map.cellsInRect(u).forEach(f=>{const d=f+s.tableStart,p=o.doc.nodeAt(d);p&&o.setNodeMarkup(d,h,p.attrs)}),r(o)}return!0}}ig("row",{useDeprecatedLogic:!0});ig("column",{useDeprecatedLogic:!0});const k$e=ig("cell",{useDeprecatedLogic:!0});function w$e(t,e){if(e<0){const n=t.nodeBefore;if(n)return t.pos-n.nodeSize;for(let r=t.index(-1)-1,i=t.before();r>=0;r--){const s=t.node(-1).child(r),o=s.lastChild;if(o)return i-1-o.nodeSize;i-=s.nodeSize}}else{if(t.index()<t.parent.childCount-1)return t.pos+t.nodeAfter.nodeSize;const n=t.node(-1);for(let r=t.indexAfter(-1),i=t.after();r<n.childCount;r++){const s=n.child(r);if(s.childCount)return i+1;i+=s.nodeSize}}return null}function v4(t){return function(e,n){if(!ms(e))return!1;const r=w$e(lk(e),t);if(r==null)return!1;if(n){const i=e.doc.resolve(r);n(e.tr.setSelection(Le.between(i,QFe(i))).scrollIntoView())}return!0}}function v$e(t,e){const n=t.selection.$anchor;for(let r=n.depth;r>0;r--)if(n.node(r).type.spec.tableRole=="table")return e&&e(t.tr.delete(n.before(r),n.after(r)).scrollIntoView()),!0;return!1}function u0(t,e){const n=t.selection;if(!(n instanceof At))return!1;if(e){const r=t.tr,i=lr(t.schema).cell.createAndFill().content;n.forEachCell((s,o)=>{s.content.eq(i)||r.replace(r.mapping.map(o+1),r.mapping.map(o+s.nodeSize-1),new de(i,0,0))}),r.docChanged&&e(r)}return!0}function C$e(t){if(t.size===0)return null;let{content:e,openStart:n,openEnd:r}=t;for(;e.childCount==1&&(n>0&&r>0||e.child(0).type.spec.tableRole=="table");)n--,r--,e=e.child(0).content;const i=e.child(0),s=i.type.spec.tableRole,o=i.type.schema,a=[];if(s=="row")for(let l=0;l<e.childCount;l++){let c=e.child(l).content;const u=l?0:Math.max(0,n-1),h=l<e.childCount-1?0:Math.max(0,r-1);(u||h)&&(c=y_(lr(o).row,new de(c,u,h)).content),a.push(c)}else if(s=="cell"||s=="header_cell")a.push(n||r?y_(lr(o).row,new de(e,n,r)).content:e);else return null;return S$e(o,a)}function S$e(t,e){const n=[];for(let i=0;i<e.length;i++){const s=e[i];for(let o=s.childCount-1;o>=0;o--){const{rowspan:a,colspan:l}=s.child(o).attrs;for(let c=i;c<i+a;c++)n[c]=(n[c]||0)+l}}let r=0;for(let i=0;i<n.length;i++)r=Math.max(r,n[i]);for(let i=0;i<n.length;i++)if(i>=e.length&&e.push(Q.empty),n[i]<r){const s=lr(t).cell.createAndFill(),o=[];for(let a=n[i];a<r;a++)o.push(s);e[i]=e[i].append(Q.from(o))}return{height:e.length,width:r,rows:e}}function y_(t,e){const n=t.createAndFill();return new $A(n).replace(0,n.content.size,e).doc}function _$e({width:t,height:e,rows:n},r,i){if(t!=r){const s=[],o=[];for(let a=0;a<n.length;a++){const l=n[a],c=[];for(let u=s[a]||0,h=0;u<r;h++){let f=l.child(h%l.childCount);u+f.attrs.colspan>r&&(f=f.type.createChecked(Oc(f.attrs,f.attrs.colspan,u+f.attrs.colspan-r),f.content)),c.push(f),u+=f.attrs.colspan;for(let d=1;d<f.attrs.rowspan;d++)s[a+d]=(s[a+d]||0)+f.attrs.colspan}o.push(Q.from(c))}n=o,t=r}if(e!=i){const s=[];for(let o=0,a=0;o<i;o++,a++){const l=[],c=n[a%e];for(let u=0;u<c.childCount;u++){let h=c.child(u);o+h.attrs.rowspan>i&&(h=h.type.create({...h.attrs,rowspan:Math.max(1,i-h.attrs.rowspan)},h.content)),l.push(h)}s.push(Q.from(l))}n=s,e=i}return{width:t,height:e,rows:n}}function T$e(t,e,n,r,i,s,o){const a=t.doc.type.schema,l=lr(a);let c,u;if(i>e.width)for(let h=0,f=0;h<e.height;h++){const d=n.child(h);f+=d.nodeSize;const p=[];let m;d.lastChild==null||d.lastChild.type==l.cell?m=c||(c=l.cell.createAndFill()):m=u||(u=l.header_cell.createAndFill());for(let y=e.width;y<i;y++)p.push(m);t.insert(t.mapping.slice(o).map(f-1+r),p)}if(s>e.height){const h=[];for(let p=0,m=(e.height-1)*e.width;p<Math.max(e.width,i);p++){const y=p>=e.width?!1:n.nodeAt(e.map[m+p]).type==l.header_cell;h.push(y?u||(u=l.header_cell.createAndFill()):c||(c=l.cell.createAndFill()))}const f=l.row.create(null,Q.from(h)),d=[];for(let p=e.height;p<s;p++)d.push(f);t.insert(t.mapping.slice(o).map(r+n.nodeSize-2),d)}return!!(c||u)}function C4(t,e,n,r,i,s,o,a){if(o==0||o==e.height)return!1;let l=!1;for(let c=i;c<s;c++){const u=o*e.width+c,h=e.map[u];if(e.map[u-e.width]==h){l=!0;const f=n.nodeAt(h),{top:d,left:p}=e.findCell(h);t.setNodeMarkup(t.mapping.slice(a).map(h+r),null,{...f.attrs,rowspan:o-d}),t.insert(t.mapping.slice(a).map(e.positionAt(o,p,n)),f.type.createAndFill({...f.attrs,rowspan:d+f.attrs.rowspan-o})),c+=f.attrs.colspan-1}}return l}function S4(t,e,n,r,i,s,o,a){if(o==0||o==e.width)return!1;let l=!1;for(let c=i;c<s;c++){const u=c*e.width+o,h=e.map[u];if(e.map[u-1]==h){l=!0;const f=n.nodeAt(h),d=e.colCount(h),p=t.mapping.slice(a).map(h+r);t.setNodeMarkup(p,null,Oc(f.attrs,o-d,f.attrs.colspan-(o-d))),t.insert(p+f.nodeSize,f.type.createAndFill(Oc(f.attrs,0,o-d))),c+=f.attrs.rowspan-1}}return l}function _4(t,e,n,r,i){let s=n?t.doc.nodeAt(n-1):t.doc;if(!s)throw new Error("No table found");let o=en.get(s);const{top:a,left:l}=r,c=l+i.width,u=a+i.height,h=t.tr;let f=0;function d(){if(s=n?h.doc.nodeAt(n-1):h.doc,!s)throw new Error("No table found");o=en.get(s),f=h.mapping.maps.length}T$e(h,o,s,n,c,u,f)&&d(),C4(h,o,s,n,l,c,a,f)&&d(),C4(h,o,s,n,l,c,u,f)&&d(),S4(h,o,s,n,a,u,l,f)&&d(),S4(h,o,s,n,a,u,c,f)&&d();for(let p=a;p<u;p++){const m=o.positionAt(p,l,s),y=o.positionAt(p,c,s);h.replace(h.mapping.slice(f).map(m+n),h.mapping.slice(f).map(y+n),new de(i.rows[p-a],0,0))}d(),h.setSelection(new At(h.doc.resolve(n+o.positionAt(a,l,s)),h.doc.resolve(n+o.positionAt(u-1,c-1,s)))),e(h)}const E$e=tN({ArrowLeft:h0("horiz",-1),ArrowRight:h0("horiz",1),ArrowUp:h0("vert",-1),ArrowDown:h0("vert",1),"Shift-ArrowLeft":d0("horiz",-1),"Shift-ArrowRight":d0("horiz",1),"Shift-ArrowUp":d0("vert",-1),"Shift-ArrowDown":d0("vert",1),Backspace:u0,"Mod-Backspace":u0,Delete:u0,"Mod-Delete":u0});function ay(t,e,n){return n.eq(t.selection)?!1:(e&&e(t.tr.setSelection(n).scrollIntoView()),!0)}function h0(t,e){return(n,r,i)=>{if(!i)return!1;const s=n.selection;if(s instanceof At)return ay(n,r,Pe.near(s.$headCell,e));if(t!="horiz"&&!s.empty)return!1;const o=pY(i,t,e);if(o==null)return!1;if(t=="horiz")return ay(n,r,Pe.near(n.doc.resolve(s.head+e),e));{const a=n.doc.resolve(o),l=aY(a,t,e);let c;return l?c=Pe.near(l,1):e<0?c=Pe.near(n.doc.resolve(a.before(-1)),-1):c=Pe.near(n.doc.resolve(a.after(-1)),1),ay(n,r,c)}}}function d0(t,e){return(n,r,i)=>{if(!i)return!1;const s=n.selection;let o;if(s instanceof At)o=s;else{const l=pY(i,t,e);if(l==null)return!1;o=new At(n.doc.resolve(l))}const a=aY(o.$headCell,t,e);return a?ay(n,r,new At(o.$anchorCell,a)):!1}}function A$e(t,e){const n=t.state.doc,r=Dc(n.resolve(e));return r?(t.dispatch(t.state.tr.setSelection(new At(r))),!0):!1}function N$e(t,e,n){if(!ms(t.state))return!1;let r=C$e(n);const i=t.state.selection;if(i instanceof At){r||(r={width:1,height:1,rows:[Q.from(y_(lr(t.state.schema).cell,n))]});const s=i.$anchorCell.node(-1),o=i.$anchorCell.start(-1),a=en.get(s).rectBetween(i.$anchorCell.pos-o,i.$headCell.pos-o);return r=_$e(r,a.right-a.left,a.bottom-a.top),_4(t.state,t.dispatch,o,a,r),!0}else if(r){const s=lk(t.state),o=s.start(-1);return _4(t.state,t.dispatch,o,en.get(s.node(-1)).findCell(s.pos-o),r),!0}else return!1}function M$e(t,e){var n;if(e.button!=0||e.ctrlKey||e.metaKey)return;const r=T4(t,e.target);let i;if(e.shiftKey&&t.state.selection instanceof At)s(t.state.selection.$anchorCell,e),e.preventDefault();else if(e.shiftKey&&r&&(i=Dc(t.state.selection.$anchor))!=null&&((n=Pv(t,e))===null||n===void 0?void 0:n.pos)!=i.pos)s(i,e),e.preventDefault();else if(!r)return;function s(l,c){let u=Pv(t,c);const h=pa.getState(t.state)==null;if(!u||!EN(l,u))if(h)u=l;else return;const f=new At(l,u);if(h||!t.state.selection.eq(f)){const d=t.state.tr.setSelection(f);h&&d.setMeta(pa,l.pos),t.dispatch(d)}}function o(){t.root.removeEventListener("mouseup",o),t.root.removeEventListener("dragstart",o),t.root.removeEventListener("mousemove",a),pa.getState(t.state)!=null&&t.dispatch(t.state.tr.setMeta(pa,-1))}function a(l){const c=l,u=pa.getState(t.state);let h;if(u!=null)h=t.state.doc.resolve(u);else if(T4(t,c.target)!=r&&(h=Pv(t,e),!h))return o();h&&s(h,c)}t.root.addEventListener("mouseup",o),t.root.addEventListener("dragstart",o),t.root.addEventListener("mousemove",a)}function pY(t,e,n){if(!(t.state.selection instanceof Le))return null;const{$head:r}=t.state.selection;for(let i=r.depth-1;i>=0;i--){const s=r.node(i);if((n<0?r.index(i):r.indexAfter(i))!=(n<0?0:s.childCount))return null;if(s.type.spec.tableRole=="cell"||s.type.spec.tableRole=="header_cell"){const o=r.before(i),a=e=="vert"?n>0?"down":"up":n>0?"right":"left";return t.endOfTextblock(a)?o:null}}return null}function T4(t,e){for(;e&&e!=t.dom;e=e.parentNode)if(e.nodeName=="TD"||e.nodeName=="TH")return e;return null}function Pv(t,e){const n=t.posAtCoords({left:e.clientX,top:e.clientY});if(!n)return null;let{inside:r,pos:i}=n;return r>=0&&Dc(t.state.doc.resolve(r))||Dc(t.state.doc.resolve(i))}var L$e=class{constructor(e,n){this.node=e,this.defaultCellMinWidth=n,this.dom=document.createElement("div"),this.dom.className="tableWrapper",this.table=this.dom.appendChild(document.createElement("table")),this.table.style.setProperty("--default-cell-min-width",`${n}px`),this.colgroup=this.table.appendChild(document.createElement("colgroup")),x_(e,this.colgroup,this.table,n),this.contentDOM=this.table.appendChild(document.createElement("tbody"))}update(e){return e.type!=this.node.type?!1:(this.node=e,x_(e,this.colgroup,this.table,this.defaultCellMinWidth),!0)}ignoreMutation(e){return e.type=="attributes"&&(e.target==this.table||this.colgroup.contains(e.target))}};function x_(t,e,n,r,i,s){let o=0,a=!0,l=e.firstChild;const c=t.firstChild;if(c){for(let h=0,f=0;h<c.childCount;h++){const{colspan:d,colwidth:p}=c.child(h).attrs;for(let m=0;m<d;m++,f++){const y=i==f?s:p&&p[m],x=y?y+"px":"";if(o+=y||r,y||(a=!1),l)l.style.width!=x&&(l.style.width=x),l=l.nextSibling;else{const b=document.createElement("col");b.style.width=x,e.appendChild(b)}}}for(;l;){var u;const h=l.nextSibling;(u=l.parentNode)===null||u===void 0||u.removeChild(l),l=h}a?(n.style.width=o+"px",n.style.minWidth=""):(n.style.width="",n.style.minWidth=o+"px")}}const ai=new Ct("tableColumnResizing");function D$e({handleWidth:t=5,cellMinWidth:e=25,defaultCellMinWidth:n=100,View:r=L$e,lastColumnResizable:i=!0}={}){const s=new vt({key:ai,state:{init(o,a){var l;const c=(l=s.spec)===null||l===void 0||(l=l.props)===null||l===void 0?void 0:l.nodeViews,u=lr(a.schema).table.name;return r&&c&&(c[u]=(h,f)=>new r(h,n,f)),new O$e(-1,!1)},apply(o,a){return a.apply(o)}},props:{attributes:o=>{const a=ai.getState(o);return a&&a.activeHandle>-1?{class:"resize-cursor"}:{}},handleDOMEvents:{mousemove:(o,a)=>{R$e(o,a,t,i)},mouseleave:o=>{I$e(o)},mousedown:(o,a)=>{B$e(o,a,e,n)}},decorations:o=>{const a=ai.getState(o);if(a&&a.activeHandle>-1)return z$e(o,a.activeHandle)},nodeViews:{}}});return s}var O$e=class ly{constructor(e,n){this.activeHandle=e,this.dragging=n}apply(e){const n=this,r=e.getMeta(ai);if(r&&r.setHandle!=null)return new ly(r.setHandle,!1);if(r&&r.setDragging!==void 0)return new ly(n.activeHandle,r.setDragging);if(n.activeHandle>-1&&e.docChanged){let i=e.mapping.map(n.activeHandle,-1);return m_(e.doc.resolve(i))||(i=-1),new ly(i,n.dragging)}return n}};function R$e(t,e,n,r){if(!t.editable)return;const i=ai.getState(t.state);if(i&&!i.dragging){const s=F$e(e.target);let o=-1;if(s){const{left:a,right:l}=s.getBoundingClientRect();e.clientX-a<=n?o=E4(t,e,"left",n):l-e.clientX<=n&&(o=E4(t,e,"right",n))}if(o!=i.activeHandle){if(!r&&o!==-1){const a=t.state.doc.resolve(o),l=a.node(-1),c=en.get(l),u=a.start(-1);if(c.colCount(a.pos-u)+a.nodeAfter.attrs.colspan-1==c.width-1)return}gY(t,o)}}}function I$e(t){if(!t.editable)return;const e=ai.getState(t.state);e&&e.activeHandle>-1&&!e.dragging&&gY(t,-1)}function B$e(t,e,n,r){var i;if(!t.editable)return!1;const s=(i=t.dom.ownerDocument.defaultView)!==null&&i!==void 0?i:window,o=ai.getState(t.state);if(!o||o.activeHandle==-1||o.dragging)return!1;const a=t.state.doc.nodeAt(o.activeHandle),l=P$e(t,o.activeHandle,a.attrs);t.dispatch(t.state.tr.setMeta(ai,{setDragging:{startX:e.clientX,startWidth:l}}));function c(h){s.removeEventListener("mouseup",c),s.removeEventListener("mousemove",u);const f=ai.getState(t.state);f!=null&&f.dragging&&($$e(t,f.activeHandle,A4(f.dragging,h,n)),t.dispatch(t.state.tr.setMeta(ai,{setDragging:null})))}function u(h){if(!h.which)return c(h);const f=ai.getState(t.state);if(f&&f.dragging){const d=A4(f.dragging,h,n);N4(t,f.activeHandle,d,r)}}return N4(t,o.activeHandle,l,r),s.addEventListener("mouseup",c),s.addEventListener("mousemove",u),e.preventDefault(),!0}function P$e(t,e,{colspan:n,colwidth:r}){const i=r&&r[r.length-1];if(i)return i;const s=t.domAtPos(e);let o=s.node.childNodes[s.offset].offsetWidth,a=n;if(r)for(let l=0;l<n;l++)r[l]&&(o-=r[l],a--);return o/a}function F$e(t){for(;t&&t.nodeName!="TD"&&t.nodeName!="TH";)t=t.classList&&t.classList.contains("ProseMirror")?null:t.parentNode;return t}function E4(t,e,n,r){const i=n=="right"?-r:r,s=t.posAtCoords({left:e.clientX+i,top:e.clientY});if(!s)return-1;const{pos:o}=s,a=Dc(t.state.doc.resolve(o));if(!a)return-1;if(n=="right")return a.pos;const l=en.get(a.node(-1)),c=a.start(-1),u=l.map.indexOf(a.pos-c);return u%l.width==0?-1:c+l.map[u-1]}function A4(t,e,n){const r=e.clientX-t.startX;return Math.max(n,t.startWidth+r)}function gY(t,e){t.dispatch(t.state.tr.setMeta(ai,{setHandle:e}))}function $$e(t,e,n){const r=t.state.doc.resolve(e),i=r.node(-1),s=en.get(i),o=r.start(-1),a=s.colCount(r.pos-o)+r.nodeAfter.attrs.colspan-1,l=t.state.tr;for(let c=0;c<s.height;c++){const u=c*s.width+a;if(c&&s.map[u]==s.map[u-s.width])continue;const h=s.map[u],f=i.nodeAt(h).attrs,d=f.colspan==1?0:a-s.colCount(h);if(f.colwidth&&f.colwidth[d]==n)continue;const p=f.colwidth?f.colwidth.slice():j$e(f.colspan);p[d]=n,l.setNodeMarkup(o+h,null,{...f,colwidth:p})}l.docChanged&&t.dispatch(l)}function N4(t,e,n,r){const i=t.state.doc.resolve(e),s=i.node(-1),o=i.start(-1),a=en.get(s).colCount(i.pos-o)+i.nodeAfter.attrs.colspan-1;let l=t.domAtPos(i.start(-1)).node;for(;l&&l.nodeName!="TABLE";)l=l.parentNode;l&&x_(s,l.firstChild,l,r,a,n)}function j$e(t){return Array(t).fill(0)}function z$e(t,e){const n=[],r=t.doc.resolve(e),i=r.node(-1);if(!i)return bt.empty;const s=en.get(i),o=r.start(-1),a=s.colCount(r.pos-o)+r.nodeAfter.attrs.colspan-1;for(let c=0;c<s.height;c++){const u=a+c*s.width;if((a==s.width-1||s.map[u]!=s.map[u+1])&&(c==0||s.map[u]!=s.map[u-s.width])){var l;const h=s.map[u],f=o+h+i.nodeAt(h).nodeSize-1,d=document.createElement("div");d.className="column-resize-handle",!((l=ai.getState(t))===null||l===void 0)&&l.dragging&&n.push(Cn.node(o+h,o+h+i.nodeAt(h).nodeSize,{class:"column-resize-dragging"})),n.push(Cn.widget(f,d))}}return bt.create(t.doc,n)}function H$e({allowTableNodeSelection:t=!1}={}){return new vt({key:pa,state:{init(){return null},apply(e,n){const r=e.getMeta(pa);if(r!=null)return r==-1?null:r;if(n==null||!e.docChanged)return n;const{deleted:i,pos:s}=e.mapping.mapResult(n);return i?null:s}},props:{decorations:t$e,handleDOMEvents:{mousedown:M$e},createSelectionBetween(e){return pa.getState(e.state)!=null?e.state.selection:null},handleTripleClick:A$e,handleKeyDown:E$e,handlePaste:N$e},appendTransaction(e,n,r){return i$e(r,hY(r,n),t)}})}function Db(t){return t==="left"||t==="right"||t==="center"?t:null}function U$e(t){const e=(t.style.textAlign||"").trim().toLowerCase(),n=(t.getAttribute("align")||"").trim().toLowerCase();return Db(e||n)}function W$e(t){return Db(t==null?void 0:t.align)}function mY(){return{default:null,parseHTML:t=>U$e(t),renderHTML:t=>t.align?{style:`text-align: ${t.align}`}:{}}}var yY=ot.create({name:"tableCell",addOptions(){return{HTMLAttributes:{}}},content:"block+",addAttributes(){return{colspan:{default:1},rowspan:{default:1},colwidth:{default:null,parseHTML:t=>{var e,n;const r=t.getAttribute("colwidth"),i=r?r.split(",").map(s=>parseInt(s,10)):null;if(!i){const s=(e=t.closest("table"))==null?void 0:e.querySelectorAll("colgroup > col"),o=Array.from(((n=t.parentElement)==null?void 0:n.children)||[]).indexOf(t);if(o&&o>-1&&s&&s[o]){const a=s[o].getAttribute("width");return a?[parseInt(a,10)]:null}}return i}},align:mY()}},tableRole:"cell",isolating:!0,parseHTML(){return[{tag:"td"}]},renderHTML({HTMLAttributes:t}){return["td",xt(this.options.HTMLAttributes,t),0]}}),xY=ot.create({name:"tableHeader",addOptions(){return{HTMLAttributes:{}}},content:"block+",addAttributes(){return{colspan:{default:1},rowspan:{default:1},colwidth:{default:null,parseHTML:t=>{const e=t.getAttribute("colwidth");return e?e.split(",").map(r=>parseInt(r,10)):null}},align:mY()}},tableRole:"header_cell",isolating:!0,parseHTML(){return[{tag:"th"}]},renderHTML({HTMLAttributes:t}){return["th",xt(this.options.HTMLAttributes,t),0]}}),bY=ot.create({name:"tableRow",addOptions(){return{HTMLAttributes:{}}},content:"(tableCell | tableHeader)*",tableRole:"row",parseHTML(){return[{tag:"tr"}]},renderHTML({HTMLAttributes:t}){return["tr",xt(this.options.HTMLAttributes,t),0]}});function b_(t,e){return e?["width",`${Math.max(e,t)}px`]:["min-width",`${t}px`]}function M4(t,e,n,r,i,s){var o;let a=0,l=!0,c=e.firstChild;const u=t.firstChild;if(u!==null)for(let f=0,d=0;f<u.childCount;f+=1){const{colspan:p,colwidth:m}=u.child(f).attrs;for(let y=0;y<p;y+=1,d+=1){const x=i===d?s:m&&m[y],b=x?`${x}px`:"";if(a+=x||r,x||(l=!1),c){if(c.style.width!==b){const[k,w]=b_(r,x);c.style.setProperty(k,w)}c=c.nextSibling}else{const k=document.createElement("col"),[w,v]=b_(r,x);k.style.setProperty(w,v),e.appendChild(k)}}}for(;c;){const f=c.nextSibling;(o=c.parentNode)==null||o.removeChild(c),c=f}const h=t.attrs.style&&typeof t.attrs.style=="string"&&/\bwidth\s*:/i.test(t.attrs.style);l&&!h?(n.style.width=`${a}px`,n.style.minWidth=""):(n.style.width="",n.style.minWidth=`${a}px`)}var q$e=class{constructor(t,e){this.node=t,this.cellMinWidth=e,this.dom=document.createElement("div"),this.dom.className="tableWrapper",this.table=this.dom.appendChild(document.createElement("table")),t.attrs.style&&(this.table.style.cssText=t.attrs.style),this.colgroup=this.table.appendChild(document.createElement("colgroup")),M4(t,this.colgroup,this.table,e),this.contentDOM=this.table.appendChild(document.createElement("tbody"))}update(t){return t.type!==this.node.type?!1:(this.node=t,M4(t,this.colgroup,this.table,this.cellMinWidth),!0)}ignoreMutation(t){const e=t.target,n=this.dom.contains(e),r=this.contentDOM.contains(e);return!!(n&&!r&&(t.type==="attributes"||t.type==="childList"||t.type==="characterData"))}};function V$e(t,e,n,r){let i=0,s=!0;const o=[],a=t.firstChild;if(!a)return{};for(let h=0,f=0;h<a.childCount;h+=1){const{colspan:d,colwidth:p}=a.child(h).attrs;for(let m=0;m<d;m+=1,f+=1){const y=n===f?r:p&&p[m];i+=y||e,y||(s=!1);const[x,b]=b_(e,y);o.push(["col",{style:`${x}: ${b}`}])}}const l=s?`${i}px`:"",c=s?"":`${i}px`;return{colgroup:["colgroup",{},...o],tableWidth:l,tableMinWidth:c}}function L4(t,e){return t.createAndFill()}function G$e(t){if(t.cached.tableNodeTypes)return t.cached.tableNodeTypes;const e={};return Object.keys(t.nodes).forEach(n=>{const r=t.nodes[n];r.spec.tableRole&&(e[r.spec.tableRole]=r)}),t.cached.tableNodeTypes=e,e}function Y$e(t,e,n,r,i){const s=G$e(t),o=[],a=[];for(let c=0;c<n;c+=1){const u=L4(s.cell);if(u&&a.push(u),r){const h=L4(s.header_cell);h&&o.push(h)}}const l=[];for(let c=0;c<e;c+=1)l.push(s.row.createChecked(null,r&&c===0?o:a));return s.table.createChecked(null,l)}function K$e(t){return t instanceof At}var f0=({editor:t})=>{const{selection:e}=t.state;if(!K$e(e))return!1;let n=0;const r=qV(e.ranges[0].$from,s=>s.type.name==="table");return r==null||r.node.descendants(s=>{if(s.type.name==="table")return!1;["tableCell","tableHeader"].includes(s.type.name)&&(n+=1)}),n===e.ranges.length?(t.commands.deleteTable(),!0):!1},X$e="";function Z$e(t){return(t||"").replace(/\s+/g," ").trim()}function Q$e(t,e,n={}){var r;const i=(r=n.cellLineSeparator)!=null?r:X$e;if(!t||!t.content||t.content.length===0)return"";const s=[];t.content.forEach(m=>{const y=[];m.content&&m.content.forEach(x=>{let b="";x.content&&Array.isArray(x.content)&&x.content.length>1?b=x.content.map(S=>e.renderChildren(S)).join(i):b=x.content?e.renderChildren(x.content):"";const k=Z$e(b),w=x.type==="tableHeader",v=W$e(x.attrs);y.push({text:k,isHeader:w,align:v})}),s.push(y)});const o=s.reduce((m,y)=>Math.max(m,y.length),0);if(o===0)return"";const a=new Array(o).fill(0);s.forEach(m=>{var y;for(let x=0;x<o;x+=1){const k=(((y=m[x])==null?void 0:y.text)||"").length;k>a[x]&&(a[x]=k),a[x]<3&&(a[x]=3)}});const l=(m,y)=>m+" ".repeat(Math.max(0,y-m.length)),c=s[0],u=c.some(m=>m.isHeader),h=new Array(o).fill(null);s.forEach(m=>{var y;for(let x=0;x<o;x+=1)!h[x]&&((y=m[x])!=null&&y.align)&&(h[x]=m[x].align)});let f=`
|
|
1115
|
+
`)}function sy(t){return t.replace(/@\[([^\]]*)\]\(([^)]*)\)/g,"@$2").replace(W6e,"/wf $1")}function Z6e(t){return H6e.replace("__display__",t.name).replace("__id__",t.id)+" "}function Q6e(t){return U6e.replace("__id__",t.id).replace("__display__",t.name)+" "}function J6e(t){const e=t.match(/\[\[wf:([^|\]]+)\|[^\]]*\]\]/);if(e!=null&&e[1])return e[1];const n=sy(t).match(/(?:^|\s)\/wf\s+([^\s]+)/);return(n==null?void 0:n[1])??null}function eFe({$position:t}){var l;const e=(l=t.nodeBefore)!=null&&l.isText?t.nodeBefore.text??"":"";if(!e)return null;const n=t.pos-e.length,r=/(?:^|\s)(\/wf(?:\s+([^\n]*))?)$/.exec(e);if(!r||r.index===void 0)return null;const i=r[1]??"",s=r[2]??"",o=n+r.index+r[0].length-i.length,a=o+i.length;return o<t.pos&&a>=t.pos?{range:{from:o,to:a},query:s,text:i}:null}function tFe(t,e){const n=document.createElement("button");if(n.type="button",n.setAttribute("role","option"),n.setAttribute("aria-selected",e?"true":"false"),n.className="flex w-full cursor-pointer items-start gap-3 px-3 py-2 text-left transition-colors "+(e?"bg-blue-50":"bg-transparent hover:bg-gray-50"),t.kind==="workflow"){const s=document.createElement("span");s.className="mt-0.5 inline-flex h-5 min-w-5 items-center justify-center rounded-full bg-blue-600 px-1.5 text-[10px] font-semibold uppercase tracking-wide text-white",s.textContent="wf",n.append(s)}const r=document.createElement("span");r.className="min-w-0 flex-1";const i=document.createElement("span");if(i.className="block truncate text-sm font-medium "+(e?"text-blue-700":"text-gray-900"),i.textContent=t.kind==="workflow"?t.label:`@${t.label}`,r.append(i),t.description||t.secondary){const s=document.createElement("span");s.className="mt-0.5 block truncate text-xs text-gray-500",s.textContent=t.secondary&&t.description?`${t.secondary} · ${t.description}`:t.secondary||t.description||"",r.append(s)}return n.append(r),n}function c4(t){return()=>{let e=null,n=null,r=null,i=0,s=null;const o=()=>{s==null||s(),s=null,e==null||e.remove(),e=null,n=null,r=null,i=0,t.onVisibilityChange(!1)},a=()=>{if(!e||!(r!=null&&r.clientRect))return;const h=r.clientRect();if(!h)return;const f=e.offsetWidth||320,d=e.offsetHeight||0,p=Math.min(Math.max(12,h.left),Math.max(12,window.innerWidth-f-12)),m=h.bottom+8,y=Math.min(m,Math.max(12,window.innerHeight-d-12));e.style.left=`${p}px`,e.style.top=`${y}px`},l=h=>{if(!r)return;const f=r.items[h];f&&r.command(f)},c=()=>{if(!(!n||!r)){if(n.replaceChildren(),n.setAttribute("aria-label",t.label()),r.items.length===0){const h=document.createElement("div");h.className="px-3 py-2 text-sm text-gray-400",h.textContent=t.emptyLabel(),n.append(h),requestAnimationFrame(a);return}r.items.forEach((h,f)=>{const d=tFe(h,f===i);d.addEventListener("mousedown",p=>{p.preventDefault(),l(f)}),n==null||n.append(d)}),requestAnimationFrame(a)}},u=h=>{!r||r.items.length===0||(i=(i+h+r.items.length)%r.items.length,c())};return{onStart(h){r=h,i=0,e=document.createElement("div"),e.className="fixed z-[100] min-w-[320px] max-w-[360px] overflow-hidden rounded-xl border border-gray-200 bg-white shadow-lg",n=document.createElement("div"),n.setAttribute("role","listbox"),n.className="max-h-72 overflow-y-auto py-1",e.append(n),document.body.append(e);const f=d=>{const p=d.target;if(!(p instanceof Node)||e!=null&&e.contains(p))return;const m=r==null?void 0:r.editor.view.dom;m!=null&&m.contains(p)||o()};document.addEventListener("pointerdown",f,!0),s=()=>{document.removeEventListener("pointerdown",f,!0)},t.onVisibilityChange(!0),c()},onUpdate(h){r=h,i>=h.items.length&&(i=0),c()},onExit(){o()},onKeyDown({event:h}){return r?h.key==="ArrowDown"?(h.preventDefault(),u(1),!0):h.key==="ArrowUp"?(h.preventDefault(),u(-1),!0):h.key==="Enter"?r.items.length===0?!1:(h.preventDefault(),l(i),!0):h.key==="Escape"?(h.preventDefault(),o(),!0):!1:!1}}}}const nFe=tBe.extend({name:"agentWorkflowMention",addAttributes(){var t;return{...(t=this.parent)==null?void 0:t.call(this),kind:{default:"agent",parseHTML:e=>e.getAttribute("data-kind")??"agent",renderHTML:e=>({"data-kind":String(e.kind??"agent")})}}},renderText({node:t}){const e=t.attrs.kind==="workflow"?"workflow":"agent",n=String(t.attrs.id??""),r=String(t.attrs.label??n);return e==="workflow"?`/wf ${n}`:`@${r}`},renderHTML({node:t,HTMLAttributes:e}){const n=t.attrs.kind==="workflow"?"workflow":"agent",r=String(t.attrs.id??""),i=String(t.attrs.label??r);return["span",{...e,class:n==="workflow"?"inline-flex items-center rounded-full bg-blue-50 px-2 py-0.5 text-xs font-medium text-blue-700":"inline-flex items-center rounded-full bg-blue-100 px-2 py-0.5 text-xs font-semibold text-blue-700","data-testid":n==="workflow"?"workflow-chip":"mention-chip"},n==="workflow"?`/wf ${r}`:`@${i}`]}});function u4({value:t,onChange:e,onSend:n,agents:r,workflows:i=[],placeholder:s,disabled:o=!1,multiline:a=!1,className:l="",inputRef:c}){const{t:u}=me(),h=T.useRef(null),f=T.useRef(e),d=T.useRef(n),p=T.useRef(r),m=T.useRef(i),y=T.useRef(u("workflow.mentionLabel")),x=T.useRef(u("workflow.noSuggestions")),b=T.useRef(!1);f.current=e,d.current=n,p.current=r,m.current=i,y.current=u("workflow.mentionLabel"),x.current=u("workflow.noSuggestions");const k=T.useCallback(S=>{b.current=S},[]),w=T.useMemo(()=>[eY.configure({heading:!1,blockquote:!1,bulletList:!1,orderedList:!1,listItem:!1,code:!1,codeBlock:!1,horizontalRule:!1}),_G.configure({placeholder:s??""}),nFe.configure({suggestions:[{char:"@",pluginKey:V6e,items:({query:S})=>{const E=S.trim().toLowerCase();return p.current.filter(M=>E?M.id.toLowerCase().includes(E)||M.name.toLowerCase().includes(E):!0).map(M=>({id:M.id,label:M.name,kind:"agent",description:[M.role,M.team].filter(Boolean).join(" · ")}))},render:c4({label:()=>y.current,emptyLabel:()=>x.current,onVisibilityChange:k}),command:({editor:S,range:E,props:M})=>{S.chain().focus().insertContentAt(E,[Lb("agent",M.id,M.label),{type:"text",text:" "}]).run()}},{char:"/",pluginKey:G6e,findSuggestionMatch:eFe,items:({query:S})=>m.current.map(E=>({workflow:E,score:K6e(E,S)})).filter(E=>E.score>0).sort((E,M)=>M.score-E.score||E.workflow.name.localeCompare(M.workflow.name)).slice(0,8).map(E=>({id:E.workflow.id,label:`/wf ${E.workflow.id}`,kind:"workflow",description:E.workflow.description,secondary:E.workflow.name})),render:c4({label:()=>y.current,emptyLabel:()=>x.current,onVisibilityChange:k}),command:({editor:S,range:E,props:M})=>{const A=m.current.find(B=>B.id===M.id);S.chain().focus().insertContentAt(E,[Lb("workflow",M.id,(A==null?void 0:A.name)??M.id),{type:"text",text:" "}]).run()}}]})],[k,s]),v=NG({immediatelyRender:!1,extensions:w,content:a4(t),editable:!o,editorProps:{attributes:{class:["focus:outline-none","text-sm","text-gray-900","break-words","[&_.is-editor-empty:first-child::before]:pointer-events-none","[&_.is-editor-empty:first-child::before]:float-left","[&_.is-editor-empty:first-child::before]:h-0","[&_.is-editor-empty:first-child::before]:text-gray-400","[&_.is-editor-empty:first-child::before]:content-[attr(data-placeholder)]",a?"min-h-[56px] max-h-[168px] overflow-y-auto px-4 py-3 whitespace-pre-wrap":"h-10 overflow-x-auto whitespace-nowrap px-4 py-[9px]"].join(" "),"data-testid":"mention-input-editor","aria-label":s||u("workflow.mentionLabel"),"aria-multiline":a?"true":"false",role:"textbox",placeholder:s??""},handleKeyDown:(S,E)=>{var M;return E.key==="Enter"&&!E.shiftKey?b.current?!1:(E.preventDefault(),(M=d.current)==null||M.call(d),!0):!a&&E.key==="Enter"?(E.preventDefault(),!0):!1}},onUpdate({editor:S}){const E=l4(S.getJSON());h.current=E,f.current(E)}},[w,o,a]);T.useEffect(()=>{v&&v.setEditable(!o)},[o,v]),T.useEffect(()=>{if(!v)return;const S=l4(v.getJSON());t===S||t===h.current||(v.commands.setContent(a4(t),{emitUpdate:!1}),h.current=t)},[v,t]);const C=["relative w-full border border-gray-200 bg-white transition-shadow",a?"rounded-xl":"rounded-md","focus-within:border-transparent focus-within:ring-2 focus-within:ring-blue-500",o?"pointer-events-none opacity-50":"",l].filter(Boolean).join(" ");return g.jsxs("div",{className:C,children:[c?g.jsx("textarea",{ref:c,tabIndex:-1,"aria-hidden":"true",className:"sr-only",onFocus:()=>{v==null||v.chain().focus("end").run()},readOnly:!0}):null,g.jsx(dN,{editor:v})]})}function rFe(){var t;return typeof window<"u"&&typeof((t=window.electronAPI)==null?void 0:t.captureScreen)=="function"}function SN({onSend:t,onCapture:e,disabled:n,activeAgent:r,value:i,onChange:s,agents:o,workflows:a,placeholder:l,sendLabel:c,multiline:u=!1,inputRef:h,variant:f="docked",className:d="",storageKey:p}){var Ve;const{t:m}=me(),[y,x]=T.useState(""),[b,k]=T.useState("query"),[w,v]=T.useState([]),[C,S]=T.useState(!1),[E,M]=T.useState(!1),A=T.useRef(null),B=nr(te=>te.workflows),F=nr(te=>te.fetchWorkflows),z=Pa(te=>{var $e;return p?(($e=te.chat.threads[p])==null?void 0:$e.mode)??"query":"query"}),D=Pa(te=>te.set),O=rFe(),N=i??y,$=o??w,I=a??B,P=p?z:b,L=T.useCallback(te=>{if(s){s(te);return}x(te)},[s]);T.useEffect(()=>{o||fe.getAgents().then(te=>v(te.agents)).catch(()=>v([]))},[o]),T.useEffect(()=>{a||F().catch(()=>{})},[F,a]),T.useEffect(()=>{if(!E)return;const te=ee=>{var ge;(ge=A.current)!=null&&ge.contains(ee.target)||M(!1)},$e=ee=>{ee.key==="Escape"&&(ee.preventDefault(),M(!1))};return window.addEventListener("mousedown",te),window.addEventListener("keydown",$e),()=>{window.removeEventListener("mousedown",te),window.removeEventListener("keydown",$e)}},[E]),T.useEffect(()=>{n&&M(!1)},[n]);const W=T.useMemo(()=>{const te=J6e(N);return I.find($e=>$e.id===te)??null},[N,I]),G=T.useMemo(()=>[{value:"query",label:m("taskDetail.inputModeQuery")},{value:"execute",label:m("taskDetail.inputModeExecute")}],[m]),j=((Ve=G.find(te=>te.value===P))==null?void 0:Ve.label)??G[0].label,V=u?"!border-0 !shadow-none !bg-transparent focus-within:!border-transparent focus-within:!ring-0 !rounded-none":"flex-1 shadow-sm",Z=T.useCallback(async()=>{const te=N.trim();if(!te||n)return;const $e=sy(te),ee=$e.match(/^@(\S+)\s+([\s\S]+)/),ge=(ee==null?void 0:ee[1])||r||"",ze=(ee==null?void 0:ee[2])??$e;await t(ze,ge,P)!==!1&&L("")},[r,n,N,P,t,L]),re=T.useCallback(async()=>{var te,$e;if(!C){S(!0);try{const ee=await(($e=(te=window.electronAPI)==null?void 0:te.captureScreen)==null?void 0:$e.call(te));ee!=null&&ee.success&&e&&e(ee)}finally{S(!1)}}},[C,e]),ve=T.useCallback(te=>{if(!p){k(te);return}const $e=Pa.getState().chat.threads,{[p]:ee,...ge}=$e;let ze={...ge,[p]:{mode:te}};const ce=Object.keys(ze);ce.length>Hy&&(ze=Object.fromEntries(ce.slice(ce.length-Hy).map(Ut=>[Ut,ze[Ut]]))),D("chat",{threads:ze})},[D,p]),Ee=[f==="standalone"?"w-full":"shrink-0 border-t border-gray-200 bg-gray-50 px-5 py-3",d].filter(Boolean).join(" "),qe=u?["w-full rounded-2xl border border-gray-200 bg-white shadow-sm transition-shadow","focus-within:border-blue-400 focus-within:ring-2 focus-within:ring-blue-500/20",n?"opacity-60":""].filter(Boolean).join(" "):"flex items-center gap-2";if(!u)return g.jsx("div",{className:Ee,children:g.jsx("div",{className:qe,children:g.jsx(be,{})})});return g.jsx("div",{className:Ee,children:g.jsxs("div",{className:qe,children:[g.jsxs("div",{className:"relative min-w-0",children:[W&&g.jsxs("div",{className:"pointer-events-none absolute bottom-full left-0 mb-2 flex items-center gap-2 rounded-lg bg-gray-900 px-3 py-2 text-xs text-white shadow-lg",children:[g.jsx(wh,{size:13,className:"text-blue-300"}),g.jsx("span",{className:"max-w-[420px] truncate",children:W.description||m("workflow.selectedLabel",{id:W.id})})]}),g.jsx(u4,{value:N,onChange:L,onSend:Z,agents:$,workflows:I,placeholder:l??(r?m("taskDetail.inputPlaceholderActive",{agent:r}):m("taskDetail.inputPlaceholder")),disabled:n,multiline:!0,inputRef:h,className:V})]}),g.jsxs("div",{className:"flex items-center gap-2 rounded-b-2xl border-t border-gray-100 bg-gray-50/50 px-3 py-2",children:[g.jsx(he,{}),O&&g.jsx("button",{onClick:re,disabled:n||C,className:"inline-flex h-8 w-8 items-center justify-center rounded-md text-gray-400 transition-colors hover:bg-gray-100 hover:text-gray-600 disabled:cursor-not-allowed disabled:opacity-40",title:m("taskDetail.captureScreen"),"aria-label":m("taskDetail.captureScreen"),children:g.jsx(R3,{size:16})}),g.jsx("div",{className:"flex-1"}),g.jsx("button",{onClick:Z,disabled:n||!sy(N).trim(),className:"inline-flex h-8 shrink-0 items-center justify-center rounded-md bg-blue-600 px-4 text-sm font-medium text-white shadow-sm transition-colors hover:bg-blue-500 disabled:cursor-not-allowed disabled:opacity-40",children:c??m("taskDetail.send")})]})]})});function he(){return g.jsxs("div",{ref:A,className:"relative shrink-0",children:[g.jsxs("button",{type:"button",onMouseDown:te=>te.preventDefault(),onClick:()=>{n||M(te=>!te)},disabled:n,"aria-expanded":E,"aria-haspopup":"listbox",className:["inline-flex h-8 items-center justify-between gap-1 rounded-md border px-2.5 text-xs font-medium transition-all duration-150",P==="execute"?"border-red-200 bg-red-50 text-red-700 hover:border-red-300 hover:bg-red-100":"border-gray-200 bg-white text-gray-700 hover:border-gray-300 hover:bg-gray-50",n?"cursor-not-allowed opacity-40":""].filter(Boolean).join(" "),children:[g.jsx("span",{className:"truncate",children:j}),g.jsx(Yr,{size:12,className:`shrink-0 transition-transform duration-150 ${E?"rotate-180":""}`})]}),g.jsx("div",{role:"listbox","aria-hidden":!E,className:["absolute bottom-full left-0 z-20 mb-2 w-32 origin-bottom-left rounded-lg border bg-white p-1 shadow-lg transition-all duration-150",E?"pointer-events-auto translate-y-0 scale-100 opacity-100":"pointer-events-none translate-y-1 scale-95 opacity-0",P==="execute"?"border-red-200":"border-gray-200"].filter(Boolean).join(" "),children:G.map(te=>{const $e=te.value===P;return g.jsx("button",{type:"button",role:"option","aria-selected":$e,onMouseDown:ee=>ee.preventDefault(),onClick:()=>{ve(te.value),M(!1)},className:["flex w-full items-center rounded-md px-3 py-2 text-left text-xs font-medium transition-colors duration-150",$e?te.value==="execute"?"bg-red-50 text-red-700":"bg-gray-100 text-gray-900":te.value==="execute"?"text-gray-700 hover:bg-red-50 hover:text-red-700":"text-gray-700 hover:bg-gray-50 hover:text-gray-900"].join(" "),children:te.label},te.value)})})]})}function be(){return g.jsxs(g.Fragment,{children:[g.jsxs("div",{ref:A,className:"relative shrink-0",children:[g.jsxs("button",{type:"button",onMouseDown:te=>te.preventDefault(),onClick:()=>{n||M(te=>!te)},disabled:n,"aria-expanded":E,"aria-haspopup":"listbox",className:["inline-flex h-10 w-24 items-center justify-between gap-1.5 rounded-md border px-3 text-sm font-medium shadow-sm transition-all duration-150",P==="execute"?"border-red-200 bg-red-50 text-red-700 hover:border-red-300 hover:bg-red-100":"border-gray-200 bg-white text-gray-700 hover:border-gray-300 hover:bg-gray-50",E?"shadow-sm":"",n?"cursor-not-allowed opacity-40":""].filter(Boolean).join(" "),children:[g.jsx("span",{className:"truncate",children:j}),g.jsx(Yr,{size:14,className:`shrink-0 transition-transform duration-150 ${E?"rotate-180":""}`})]}),g.jsx("div",{role:"listbox","aria-hidden":!E,className:["absolute bottom-full left-0 z-20 mb-2 w-32 origin-bottom-left rounded-lg border bg-white p-1 shadow-lg transition-all duration-150",E?"pointer-events-auto translate-y-0 scale-100 opacity-100":"pointer-events-none translate-y-1 scale-95 opacity-0",P==="execute"?"border-red-200":"border-gray-200"].filter(Boolean).join(" "),children:G.map(te=>{const $e=te.value===P;return g.jsx("button",{type:"button",role:"option","aria-selected":$e,onMouseDown:ee=>ee.preventDefault(),onClick:()=>{ve(te.value),M(!1)},className:["flex w-full items-center rounded-md px-3 py-2 text-left text-xs font-medium transition-colors duration-150",$e?te.value==="execute"?"bg-red-50 text-red-700":"bg-gray-100 text-gray-900":te.value==="execute"?"text-gray-700 hover:bg-red-50 hover:text-red-700":"text-gray-700 hover:bg-gray-50 hover:text-gray-900"].join(" "),children:te.label},te.value)})})]}),g.jsx("div",{className:"min-w-0 flex-1",children:g.jsxs("div",{className:"relative flex min-w-0 items-center",children:[W&&g.jsxs("div",{className:"pointer-events-none absolute bottom-full left-0 mb-2 flex items-center gap-2 rounded-lg bg-gray-900 px-3 py-2 text-xs text-white shadow-lg",children:[g.jsx(wh,{size:13,className:"text-blue-300"}),g.jsx("span",{className:"max-w-[420px] truncate",children:W.description||m("workflow.selectedLabel",{id:W.id})})]}),g.jsx(u4,{value:N,onChange:L,onSend:Z,agents:$,workflows:I,placeholder:l??(r?m("taskDetail.inputPlaceholderActive",{agent:r}):m("taskDetail.inputPlaceholder")),disabled:n,multiline:u,inputRef:h,className:V})]})}),O&&g.jsx("button",{onClick:re,disabled:n||C,className:"inline-flex h-10 w-10 items-center justify-center rounded-md border border-gray-200 bg-white text-gray-400 shadow-sm transition-colors hover:border-gray-300 hover:bg-gray-50 hover:text-gray-600 disabled:cursor-not-allowed disabled:opacity-40",title:m("taskDetail.captureScreen"),"aria-label":m("taskDetail.captureScreen"),children:g.jsx(R3,{size:18})}),g.jsx("button",{onClick:Z,disabled:n||!sy(N).trim(),className:"inline-flex h-10 shrink-0 items-center justify-center rounded-md bg-blue-600 px-5 text-sm font-medium text-white shadow-sm transition-colors hover:bg-blue-500 disabled:cursor-not-allowed disabled:opacity-40",children:c??m("taskDetail.send")})]})}}function iFe(){const{t}=me(),{taskId:e}=Kh(),n=T.useRef(null),{setPageHeader:r}=ur(),{messages:i,loading:s,error:o,taskStatus:a,logs:l,childTasks:c,sending:u,fetchDetail:h,sendMessage:f,addLocalMessage:d,stopPolling:p,reset:m}=LF();if(T.useEffect(()=>{r({title:"",actions:null})},[r]),T.useEffect(()=>(e&&h(e),()=>{p(),m()}),[e]),T.useEffect(()=>{n.current&&(n.current.scrollTop=n.current.scrollHeight)},[i.length,l.length]),!e)return null;const y=(w,v)=>{f(w,v)},x=w=>{d({id:`capture-${w.timestamp}`,userId:"user",text:"",timestamp:new Date(w.timestamp).toISOString(),isAssistant:!1,imageDataUrl:w.imageDataUrl})},b=i.reduceRight((w,v,C)=>w===-1&&v.isAssistant?C:w,-1),k=(()=>{var C;const w=new Map;let v=null;for(let S=0;S<i.length;S++)if(i[S].isAssistant){const E=((C=i[S].metadata)==null?void 0:C.agent_id)??"assistant";E!==v&&(w.set(S,E),v=E)}return w})();return g.jsxs("div",{className:"flex flex-col h-[calc(100vh-3rem)] -m-6 bg-gray-50",children:[g.jsxs("div",{ref:n,className:"flex-1 overflow-y-auto px-8 py-6 space-y-5",children:[s&&g.jsx("div",{className:"flex items-center justify-center py-16",children:g.jsx(ut,{size:24,className:"animate-spin text-gray-500"})}),o&&!s&&g.jsxs("div",{className:"flex items-center gap-3 bg-red-50 text-red-600 text-sm rounded-lg px-4 py-3 border border-red-200",children:[g.jsx(Rn,{size:16,className:"shrink-0"}),g.jsx("span",{children:o})]}),!s&&i.map((w,v)=>{const C=v===b,S=k.get(v);return g.jsxs(T.Fragment,{children:[S&&g.jsxs("div",{className:"flex items-center gap-3 py-1",children:[g.jsx("div",{className:"flex-1 h-px bg-gray-200"}),g.jsx("span",{className:"text-xs text-gray-400 shrink-0 select-none",children:t("taskDetail.agentJoined",{agent:S})}),g.jsx("div",{className:"flex-1 h-px bg-gray-200"})]}),g.jsx(OS,{message:w,logs:w.logs,childTasks:C?c:void 0,taskStatus:C?a:void 0})]},w.id)}),!s&&!o&&g.jsx("div",{className:"mt-2",children:g.jsx(RA,{logs:l,childTasks:c,status:a})}),!s&&!o&&i.length===0&&g.jsxs("div",{className:"flex flex-col items-center justify-center py-16 text-gray-500",children:[g.jsx("p",{className:"text-sm",children:t("taskDetail.noMessages")}),g.jsx("p",{className:"text-xs mt-1 text-gray-600",children:t("taskDetail.noMessagesHint")})]})]}),g.jsx(SN,{onSend:y,onCapture:x,disabled:u,multiline:!0})]})}function rp(t,e,n){return Math.min(Math.max(t,e),n)}function sFe(t,e,n,r){const i=rp(t,e,n);if(!r||typeof window>"u")return i;const s=Number(window.localStorage.getItem(r));return Number.isFinite(s)?rp(s,e,n):i}function _N({children:t,defaultWidth:e,minWidth:n=160,maxWidth:r=480,side:i,storageKey:s}){const[o,a]=T.useState(()=>sFe(e,n,r,s)),[l,c]=T.useState(!1),u=T.useRef(null),h=T.useCallback(()=>{a(rp(e,n,r))},[e,r,n]),f=T.useCallback(d=>{d.preventDefault(),u.current={startX:d.clientX,startWidth:o},c(!0)},[o]);return T.useEffect(()=>{a(d=>rp(d,n,r))},[r,n]),T.useEffect(()=>{!s||typeof window>"u"||window.localStorage.setItem(s,String(o))},[s,o]),T.useEffect(()=>{if(!l)return;const d=document.body.style.cursor,p=document.body.style.userSelect;document.body.style.cursor="col-resize",document.body.style.userSelect="none";const m=x=>{const b=u.current;if(!b)return;const k=x.clientX-b.startX,w=i==="right"?b.startWidth+k:b.startWidth-k;a(rp(w,n,r))},y=()=>{u.current=null,c(!1)};return window.addEventListener("mousemove",m),window.addEventListener("mouseup",y),()=>{document.body.style.cursor=d,document.body.style.userSelect=p,window.removeEventListener("mousemove",m),window.removeEventListener("mouseup",y)}},[l,r,n,i]),g.jsxs("div",{className:"relative h-full shrink-0",style:{width:o},children:[g.jsx("div",{className:"h-full overflow-hidden",children:t}),g.jsx("div",{role:"separator","aria-orientation":"vertical",onMouseDown:f,onDoubleClick:h,className:["absolute inset-y-0 z-10 w-1 cursor-col-resize rounded-full transition-colors",i==="left"?"left-0 -translate-x-1/2":"right-0 translate-x-1/2",l?"bg-blue-400/80":"bg-transparent hover:bg-blue-400/60"].join(" ")})]})}const oFe=5e3,aFe=1e3;function TN(t,e){const n=T.useRef(t);T.useEffect(()=>{n.current=t},[t]);const{interval:r,idleOnly:i=!1,idleTimeout:s=oFe,enabled:o=!0}=e;T.useEffect(()=>{if(!o)return;const a=()=>{n.current()};if(!i){const y=window.setInterval(a,r);return()=>{window.clearInterval(y)}}let l=null,c=null,u=Number.NEGATIVE_INFINITY;const h=()=>{l!==null&&(window.clearTimeout(l),l=null)},f=()=>{c!==null&&(window.clearInterval(c),c=null)},d=()=>{c===null&&(c=window.setInterval(a,r))},p=()=>{h(),l=window.setTimeout(()=>{d()},s)},m=()=>{const y=Date.now();y-u<aFe||(u=y,f(),p())};return p(),document.addEventListener("mousemove",m,{passive:!0}),document.addEventListener("keydown",m,{passive:!0}),()=>{f(),h(),document.removeEventListener("mousemove",m),document.removeEventListener("keydown",m)}},[o,i,s,r])}const lFe={bash:"#a855f7",read:"#22c55e",grep:"#22c55e",edit:"#f97316",write:"#f97316"};function cFe(t){return lFe[t.trim().toLowerCase()]??"#6b7280"}function uFe(t){switch(t.trim().toLowerCase()){case"bash":return a1;case"read":return Uo;case"grep":return Ya;case"edit":case"write":return PT;default:return xF}}function hFe({stats:t,open:e,onToggle:n}){const{t:r}=me(),i=T.useMemo(()=>t.reduce((o,a)=>o+a.count,0),[t]),s=T.useMemo(()=>t.map(o=>{const a=i>0?o.count/i*100:0;return{...o,color:cFe(o.tool),percentage:a,displayPercentage:Math.round(a)}}),[t,i]);return t.length===0||i===0?null:g.jsxs("section",{className:"rounded-lg border border-gray-200 bg-white shadow-sm",children:[g.jsx("div",{className:"border-b border-gray-200 px-4 py-3",children:g.jsxs("button",{type:"button",onClick:n,"aria-expanded":e,className:"flex w-full items-center justify-between gap-4 text-left",children:[g.jsxs("span",{className:"flex min-w-0 items-center gap-2",children:[e?g.jsx(Yr,{size:16,className:"shrink-0 text-gray-400"}):g.jsx(hs,{size:16,className:"shrink-0 text-gray-400"}),g.jsx("span",{className:"truncate text-sm font-semibold text-gray-900",children:r("tasks.panel.toolUsage")})]}),g.jsx("span",{className:"flex h-2.5 w-28 shrink-0 overflow-hidden rounded-full bg-gray-100","aria-hidden":"true",children:s.map(o=>g.jsx("span",{className:"h-full",style:{width:`${o.percentage}%`,backgroundColor:o.color},title:r("tasks.panel.toolUsageTooltip",{tool:o.tool,count:o.count,pct:o.displayPercentage})},o.tool))})]})}),e&&g.jsx("div",{className:"px-4 py-3",children:g.jsxs("table",{className:"w-full table-fixed text-sm",children:[g.jsx("thead",{children:g.jsxs("tr",{className:"text-left text-xs uppercase tracking-wide text-gray-500",children:[g.jsx("th",{className:"pb-2 font-medium",children:r("tasks.panel.tool")}),g.jsx("th",{className:"pb-2 text-right font-medium",children:r("tasks.panel.calls")}),g.jsx("th",{className:"pb-2 pl-4 font-medium",children:r("tasks.panel.ratio")})]})}),g.jsx("tbody",{className:"divide-y divide-gray-100",children:s.map(o=>{const a=uFe(o.tool);return g.jsxs("tr",{children:[g.jsx("td",{className:"py-3 pr-3",children:g.jsxs("div",{className:"flex items-center gap-2 text-gray-800",children:[g.jsx("span",{className:"inline-flex h-5 w-5 items-center justify-center rounded-full",style:{backgroundColor:`${o.color}1a`,color:o.color},children:g.jsx(a,{size:12})}),g.jsx("span",{className:"h-2 w-2 rounded-full",style:{backgroundColor:o.color},"aria-hidden":"true"}),g.jsx("span",{className:"truncate font-medium",children:o.tool})]})}),g.jsx("td",{className:"py-3 text-right font-mono text-xs text-gray-600",children:o.count}),g.jsx("td",{className:"py-3 pl-4",children:g.jsxs("div",{className:"flex items-center gap-3",children:[g.jsxs("span",{className:"w-10 shrink-0 text-xs font-medium text-gray-600",children:[o.displayPercentage,"%"]}),g.jsx("div",{className:"h-2 flex-1 overflow-hidden rounded-full bg-gray-100",children:g.jsx("div",{className:"h-full rounded-full",style:{width:`${o.percentage}%`,backgroundColor:o.color},title:r("tasks.panel.toolUsageTooltip",{tool:o.tool,count:o.count,pct:o.displayPercentage})})})]})})]},o.tool)})})]})})]})}function Iv(t){switch(t){case"success":return{prompt:!1,result:!0,toolUsage:!1,metadata:!1};case"failed":return{prompt:!0,result:!1,toolUsage:!1,metadata:!1};case"running":return{prompt:!1,result:!1,toolUsage:!1,metadata:!1};case"pending":default:return{prompt:!0,result:!1,toolUsage:!1,metadata:!1}}}function dFe(t){return t?t>=1e6?`${(t/1e6).toFixed(1)}M`:t>=1e3?`${(t/1e3).toFixed(1)}K`:`${t}`:"0"}function fFe(t,e){const n=(t??0)+(e??0);return n===0?"-":`${dFe(n)} tok`}function pFe(t){return t?t<.01?`$${t.toFixed(4)}`:`$${t.toFixed(2)}`:"-"}function gFe(t,e){return e==="running"||t==null?"—":`${(t/1e3).toFixed(1).replace(/\.0$/,"")}s`}function h4(t){return t?new Intl.DateTimeFormat(void 0,{hour:"2-digit",minute:"2-digit"}).format(new Date(t)):"—"}function mFe(t,e,n){return(e==null?void 0:e.agentId)??(n==null?void 0:n.agent)??t}function d_({status:t}){const{t:e}=me(),n={success:"bg-green-100 text-green-800",failed:"bg-red-100 text-red-800",running:"bg-yellow-100 text-yellow-800",pending:"bg-gray-100 text-gray-800"};return g.jsx("span",{className:`inline-flex items-center rounded-full px-2.5 py-1 text-xs font-medium ${n[t]}`,children:e(`tasks.status.${t}`)})}function d4({title:t,content:e,open:n,onToggle:r,onCopy:i,clampLines:s}){const{t:o}=me(),[a,l]=T.useState(!1);T.useEffect(()=>{l(!1)},[e]);const c=!!s&&e.trim().length>240,u=s&&!a?`overflow-hidden [display:-webkit-box] [-webkit-box-orient:vertical] [-webkit-line-clamp:${s}]`:"";return g.jsxs("section",{className:"rounded-lg border border-gray-200 bg-white shadow-sm",children:[g.jsxs("div",{className:"flex items-start justify-between gap-3 border-b border-gray-200 px-4 py-3",children:[g.jsxs("button",{type:"button",onClick:r,"aria-expanded":n,className:"flex min-w-0 flex-1 items-center gap-2 text-left",children:[n?g.jsx(Yr,{size:16,className:"shrink-0 text-gray-400"}):g.jsx(hs,{size:16,className:"shrink-0 text-gray-400"}),g.jsx("span",{className:"truncate text-sm font-semibold text-gray-900",children:t})]}),g.jsxs("button",{type:"button",onClick:i,className:"inline-flex items-center gap-1 rounded-md border border-gray-200 px-2.5 py-1.5 text-xs font-medium text-gray-600 transition-colors hover:bg-gray-50",children:[g.jsx(yg,{size:13}),g.jsx("span",{children:o("tasks.panel.copy")})]})]}),n&&g.jsxs("div",{className:"px-4 py-3",children:[g.jsx("div",{className:`text-sm leading-6 text-gray-700 ${u}`,children:g.jsx(Pg,{content:e})}),c&&g.jsx("button",{type:"button",onClick:()=>l(h=>!h),className:"mt-2 text-xs font-medium text-blue-600 transition-colors hover:text-blue-700",children:o(a?"tasks.panel.showLess":"tasks.panel.showMore")})]})]})}function yFe({childTasks:t,onSelectTask:e}){const{t:n}=me();return g.jsxs("section",{className:"rounded-lg border border-gray-200 bg-white shadow-sm",children:[g.jsx("div",{className:"border-b border-gray-200 px-4 py-3",children:g.jsx("h3",{className:"text-sm font-semibold text-gray-900",children:n("tasks.panel.childTasks")})}),g.jsx("div",{className:"divide-y divide-gray-200",children:t.map(r=>{if(e){const i=e;return g.jsxs("button",{type:"button",onClick:()=>i(r.taskId),className:"flex w-full cursor-pointer items-center justify-between gap-3 px-4 py-3 text-left transition-colors hover:bg-gray-50",children:[g.jsxs("div",{className:"min-w-0",children:[g.jsx("p",{className:"truncate text-sm font-medium text-gray-900",children:r.agentId}),g.jsx("p",{className:"truncate font-mono text-xs text-blue-500",children:r.taskId})]}),g.jsx(d_,{status:r.status})]},r.taskId)}return g.jsxs("div",{className:"flex items-center justify-between gap-3 px-4 py-3",children:[g.jsxs("div",{className:"min-w-0",children:[g.jsx("p",{className:"truncate text-sm font-medium text-gray-900",children:r.agentId}),g.jsx("p",{className:"truncate font-mono text-xs text-gray-400",children:r.taskId})]}),g.jsx(d_,{status:r.status})]},r.taskId)})})]})}function xFe({taskId:t,task:e,onClose:n,onRefresh:r,onSelectTask:i}){const{t:s}=me(),o=Nt(),a=ul(V=>V.addToast),[l,c]=T.useState(null),[u,h]=T.useState(!0),[f,d]=T.useState(null),[p,m]=T.useState("idle"),[y,x]=T.useState(Iv((e==null?void 0:e.status)??"pending")),b=(l==null?void 0:l.status)??(e==null?void 0:e.status)??"pending",k=(l==null?void 0:l.prompt)??(e==null?void 0:e.prompt)??"",w=(l==null?void 0:l.result)??"",v=(l==null?void 0:l.startedAt)??(e==null?void 0:e.startedAt),C=(l==null?void 0:l.completedAt)??(e==null?void 0:e.completedAt),S=(l==null?void 0:l.durationMs)??(e==null?void 0:e.durationMs),E=(l==null?void 0:l.model)??(e==null?void 0:e.model)??null,M=(l==null?void 0:l.threadId)??(e==null?void 0:e.threadId)??null,A=(l==null?void 0:l.inputTokens)??(e==null?void 0:e.inputTokens),B=(l==null?void 0:l.outputTokens)??(e==null?void 0:e.outputTokens),F=(l==null?void 0:l.costUsd)??(e==null?void 0:e.costUsd),z=(l==null?void 0:l.error)??null,D=(l==null?void 0:l.logs)??[],O=(l==null?void 0:l.childTasks)??[],N=(l==null?void 0:l.parentTaskId)??null,$=(l==null?void 0:l.metadata)??null,I=mFe(t,e,l),P=T.useMemo(()=>{const V=(l==null?void 0:l.toolUsage)??{};return Object.entries(V).map(([Z,re])=>({tool:Z,count:re})).sort((Z,re)=>re.count-Z.count)},[l==null?void 0:l.toolUsage]),L=T.useMemo(()=>[E??"-",fFe(A,B),pFe(F)].join(" · "),[F,A,E,B]),W=T.useCallback(async(V=!0)=>{V&&h(!0);try{const Z=await fe.getTaskStatus(t,{include:"logs,children",skipRequestLog:!0});c(Z),d(null)}catch(Z){d(Z instanceof Error?Z.message:"Failed to load task details")}finally{V&&h(!1)}},[t]);T.useEffect(()=>{c(null),h(!0),d(null),m("idle"),x(Iv((e==null?void 0:e.status)??"pending")),W(!0)},[W,e==null?void 0:e.status,t]),T.useEffect(()=>{!e&&l&&x(Iv(l.status))},[l,e]),T.useEffect(()=>{if(p!=="confirming")return;const V=window.setTimeout(()=>{m("idle")},3e3);return()=>window.clearTimeout(V)},[p]),TN(()=>W(!1),{interval:5e3,enabled:b==="running"});const G=T.useCallback(async(V,Z)=>{var re;try{if(!((re=navigator.clipboard)!=null&&re.writeText))throw new Error("Clipboard unavailable");await navigator.clipboard.writeText(V),a({type:"success",message:s(Z)})}catch(ve){console.error("[TaskDetailPanel] Failed to copy text.",ve),a({type:"error",message:s("tasks.panel.copyFailed")})}},[a,s]),j=T.useCallback(async()=>{if(p!=="stopping"){if(p==="idle"){m("confirming");return}m("stopping");try{await fe.stopTask(t),await Promise.all([Promise.resolve(r==null?void 0:r()),W(!1)]),m("idle")}catch(V){console.error("[TaskDetailPanel] Failed to stop task.",V),a({type:"error",message:s("tasks.panel.stopFailed")}),m("idle")}}},[a,W,r,p,s,t]);return g.jsx(g.Fragment,{children:g.jsxs("aside",{role:"dialog","aria-label":s("tasks.panel.title"),className:"flex h-full w-full min-w-0 flex-col border-l border-gray-200 bg-white shadow-lg",children:[g.jsx("div",{className:"sticky top-0 z-10 border-b border-gray-200 bg-white p-4",children:g.jsxs("div",{className:"flex items-start gap-3",children:[g.jsx("div",{className:"flex h-11 w-11 shrink-0 items-center justify-center rounded-full bg-blue-50 text-blue-600",children:g.jsx(hF,{size:18})}),g.jsxs("div",{className:"min-w-0 flex-1",children:[g.jsxs("div",{className:"flex items-start justify-between gap-3",children:[g.jsxs("div",{className:"min-w-0",children:[g.jsx("p",{className:"truncate text-lg font-semibold text-gray-900",children:I}),g.jsx("p",{className:"truncate font-mono text-xs text-gray-400",children:t})]}),g.jsx("button",{type:"button",onClick:n,className:"rounded-md p-1.5 text-gray-400 transition-colors hover:bg-gray-100 hover:text-gray-600","aria-label":s("tasks.panel.close"),children:g.jsx(Xa,{size:16})})]}),g.jsxs("div",{className:"mt-3 flex flex-wrap items-center gap-2",children:[g.jsx(d_,{status:b}),g.jsx("span",{className:"text-sm font-medium text-gray-600",children:gFe(S,b)}),b==="running"&&g.jsx("button",{type:"button",onClick:()=>void j(),disabled:p==="stopping",className:"inline-flex min-w-[108px] items-center justify-center gap-1.5 rounded-md border border-red-200 bg-red-50 px-3 py-1.5 text-xs font-semibold text-red-700 transition-colors hover:bg-red-100 disabled:cursor-not-allowed disabled:opacity-70",children:p==="stopping"?g.jsxs(g.Fragment,{children:[g.jsx(ut,{size:12,className:"animate-spin"}),g.jsx("span",{children:s("tasks.panel.stopping")})]}):p==="confirming"?g.jsx("span",{children:s("tasks.panel.stopConfirm")}):g.jsxs(g.Fragment,{children:[g.jsx(uie,{size:12}),g.jsx("span",{children:s("tasks.panel.stop")})]})})]}),g.jsx("p",{className:"mt-3 text-sm text-gray-600",children:L}),g.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-x-3 gap-y-1 text-xs text-gray-500",children:[g.jsx("span",{children:`${h4(v)} → ${h4(C)}`}),M?g.jsxs("button",{type:"button",onClick:()=>o(`/threads/${M}`),className:"inline-flex items-center gap-1 font-medium text-blue-600 transition-colors hover:text-blue-700",children:[g.jsx(Tre,{size:13}),g.jsx("span",{children:s("tasks.panel.viewThread")})]}):g.jsx("span",{className:"text-gray-400",children:s("tasks.panel.noThread")})]}),N&&i&&g.jsxs("div",{className:"mt-2 flex items-center gap-1.5 text-xs text-gray-500",children:[g.jsx(Pne,{size:14}),g.jsx("span",{children:s("tasks.panel.parentLabel")}),g.jsxs("button",{type:"button",onClick:()=>i(N),className:"font-medium text-blue-500 transition-colors hover:underline",children:["#",N]})]})]})]})}),g.jsxs("div",{className:"flex-1 space-y-3 overflow-y-auto p-4",children:[b==="failed"&&z&&g.jsxs("div",{className:"flex items-start gap-3 rounded-lg border border-red-200 bg-red-50 px-4 py-3 text-sm text-red-700",children:[g.jsx(Rn,{size:16,className:"mt-0.5 shrink-0"}),g.jsx("span",{children:z})]}),f&&g.jsxs("div",{className:"rounded-lg border border-red-200 bg-white p-4 shadow-sm",children:[g.jsxs("div",{className:"flex items-start gap-3 text-sm text-red-700",children:[g.jsx(Rn,{size:16,className:"mt-0.5 shrink-0"}),g.jsxs("div",{className:"min-w-0 flex-1",children:[g.jsx("p",{className:"font-medium",children:s("tasks.panel.detailLoadError")}),g.jsx("p",{className:"mt-1 break-words text-xs text-red-600",children:f})]})]}),g.jsx("button",{type:"button",onClick:()=>void W(!0),className:"mt-3 rounded-md bg-red-100 px-3 py-1.5 text-xs font-medium text-red-700 transition-colors hover:bg-red-200",children:s("tasks.panel.retryDetail")})]}),k&&g.jsx(d4,{title:s("tasks.panel.request"),content:k,open:y.prompt,onToggle:()=>x(V=>({...V,prompt:!V.prompt})),onCopy:()=>void G(k,"tasks.panel.copyRequestSuccess")}),u&&!l&&g.jsxs("div",{className:"space-y-3 rounded-lg border border-gray-200 bg-white p-4 shadow-sm",children:[g.jsx("div",{className:"h-4 w-32 animate-pulse rounded bg-gray-200"}),g.jsx("div",{className:"h-4 w-full animate-pulse rounded bg-gray-100"}),g.jsx("div",{className:"h-4 w-4/5 animate-pulse rounded bg-gray-100"})]}),w&&g.jsx(d4,{title:s("tasks.panel.result"),content:w,open:y.result,onToggle:()=>x(V=>({...V,result:!V.result})),onCopy:()=>void G(w,"tasks.panel.copyResultSuccess"),clampLines:5}),!u&&b==="pending"&&!w&&g.jsxs("section",{className:"rounded-lg border border-gray-200 bg-white p-4 shadow-sm",children:[g.jsx("h3",{className:"text-sm font-semibold text-gray-900",children:s("tasks.panel.pendingTitle")}),g.jsx("p",{className:"mt-2 text-sm text-gray-500",children:s("tasks.panel.pendingDescription")})]}),P.length>0&&g.jsx(hFe,{stats:P,open:y.toolUsage,onToggle:()=>x(V=>({...V,toolUsage:!V.toolUsage}))}),(D.length>0||b==="running"||b==="failed")&&g.jsx(RA,{logs:D,childTasks:O,status:b}),O.length>0&&g.jsx(yFe,{childTasks:O,onSelectTask:i}),$&&g.jsxs("section",{className:"rounded-lg border border-gray-200 bg-white shadow-sm",children:[g.jsx("div",{className:"flex items-start justify-between gap-3 border-b border-gray-200 px-4 py-3",children:g.jsxs("button",{type:"button",onClick:()=>x(V=>({...V,metadata:!V.metadata})),"aria-expanded":y.metadata,className:"flex min-w-0 flex-1 items-center gap-2 text-left",children:[y.metadata?g.jsx(Yr,{size:16,className:"shrink-0 text-gray-400"}):g.jsx(hs,{size:16,className:"shrink-0 text-gray-400"}),g.jsx("span",{className:"truncate text-sm font-semibold text-gray-900",children:"Metadata"})]})}),y.metadata&&g.jsx("div",{className:"px-4 py-3",children:g.jsx("pre",{className:"max-h-60 overflow-auto rounded bg-muted p-3 text-xs",children:JSON.stringify($,null,2)})})]})]})]})})}const bFe=["pending","running","success","failed"];function kFe(t,e){const n=(t??0)+(e??0);return n===0?"-":n>=1e6?`${(n/1e6).toFixed(1)}M`:n>=1e3?`${(n/1e3).toFixed(1)}k`:String(n)}function wFe(t,e){if(e==="running"||t==null)return"—";const n=t/1e3;return`${(n>=10,n.toFixed(1)).replace(/\.0$/,"")}s`}function vFe(t,e){const n=new Date(t),r=Date.now()-n.getTime(),i=Math.floor(r/6e4);if(i<1)return e("tasks.relative.justNow");if(i<60)return e("tasks.relative.minutesAgo",{count:i});const s=Math.floor(i/60);return s<24?e("tasks.relative.hoursAgo",{count:s}):new Intl.DateTimeFormat(void 0,{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"}).format(n)}function CFe({status:t}){const{t:e}=me(),n={success:"bg-green-100 text-green-800",failed:"bg-red-100 text-red-800",running:"bg-yellow-100 text-yellow-800",pending:"bg-gray-100 text-gray-800"};return g.jsx("span",{className:`inline-flex items-center rounded-full px-2.5 py-1 text-xs font-medium ${n[t]}`,children:e(`tasks.status.${t}`)})}function f4({label:t,options:e,selectedValues:n,allLabel:r,getOptionLabel:i,onChange:s}){const o=n.length===0?r:n.length===1?i(n[0]):`${t} (${n.length})`;return g.jsxs("details",{className:"relative min-w-[160px]",children:[g.jsxs("summary",{className:"flex h-10 cursor-pointer list-none items-center justify-between gap-2 rounded-lg border border-gray-200 bg-white px-3 text-sm text-gray-700 shadow-sm transition-colors hover:border-gray-300",children:[g.jsx("span",{className:"truncate",children:o}),g.jsx(Yr,{size:16,className:"shrink-0 text-gray-400"})]}),g.jsx("div",{className:"absolute right-0 z-20 mt-2 w-full min-w-[180px] rounded-lg border border-gray-200 bg-white p-2 shadow-lg",children:g.jsx("div",{className:"max-h-60 overflow-y-auto",children:e.map(a=>{const l=n.includes(a);return g.jsxs("label",{className:"flex cursor-pointer items-center justify-between gap-3 rounded-md px-2 py-2 text-sm text-gray-700 transition-colors hover:bg-gray-50",children:[g.jsxs("div",{className:"flex items-center gap-2",children:[g.jsx("input",{type:"checkbox",className:"h-4 w-4 rounded border-gray-300 text-blue-500 focus:ring-blue-500",checked:l,onChange:()=>{s(l?n.filter(c=>c!==a):[...n,a])}}),g.jsx("span",{children:i(a)})]}),l&&g.jsx(Us,{size:14,className:"text-blue-500"})]},a)})})})]})}function SFe(t){return t?"hidden":""}function _Fe(t,e){return e?t.find(n=>n.taskId===e)??null:null}function TFe(){const{t}=me(),{setPageHeader:e}=ur(),[n,r]=mg(),{tasks:i,total:s,page:o,limit:a,loading:l,error:c,searchQuery:u,agentFilter:h,statusFilter:f,availableAgents:d,fetchTasks:p,setPage:m,setSearchQuery:y,setAgentFilter:x,setStatusFilter:b,refresh:k}=OF(),[w,v]=T.useState(u),C=n.get("selected"),S=T.useMemo(()=>_Fe(i,C),[C,i]),E=SFe(C),M=C?5:7,A=Math.max(1,Math.ceil(s/a)),B=T.useMemo(()=>{const D=Math.max(1,o-2),O=Math.min(A,D+4),N=Math.max(1,O-4);return Array.from({length:O-N+1},($,I)=>N+I)},[o,A]),F=T.useCallback(D=>{r(O=>{const N=new URLSearchParams(O);return D?N.set("selected",D):N.delete("selected"),N})},[r]),z=T.useCallback(()=>{k()},[k]);return TN(z,{interval:3e4,idleOnly:!0,idleTimeout:5e3}),T.useEffect(()=>{e({title:t("tasks.title"),actions:g.jsx("button",{onClick:z,className:"rounded-lg p-2 text-gray-500 transition-colors hover:bg-gray-100 hover:text-gray-700",title:t("common.refresh"),children:g.jsx(Vr,{size:16,className:l?"animate-spin":""})})})},[z,l,e,t]),T.useEffect(()=>{const D=window.setTimeout(()=>{w!==u&&y(w)},300);return()=>window.clearTimeout(D)},[w,u,y]),T.useEffect(()=>{p()},[h,p,o,u,f]),T.useEffect(()=>{if(!C)return;const D=O=>{O.key==="Escape"&&F(null)};return window.addEventListener("keydown",D),()=>window.removeEventListener("keydown",D)},[C,F]),g.jsxs("div",{className:"space-y-5",children:[g.jsx("section",{className:"rounded-lg border border-gray-200 bg-white p-4 shadow-sm",children:g.jsxs("div",{className:"flex flex-col gap-3 lg:flex-row lg:items-center",children:[g.jsxs("label",{className:"relative block w-full max-w-[280px]",children:[g.jsx(Ya,{size:16,className:"pointer-events-none absolute left-3 top-1/2 -translate-y-1/2 text-gray-400"}),g.jsx("input",{type:"search",value:w,onChange:D=>v(D.target.value),placeholder:t("tasks.filters.searchPlaceholder"),className:"h-10 w-full rounded-lg border border-gray-200 bg-white pl-9 pr-3 text-sm text-gray-900 placeholder:text-gray-400 focus:border-blue-500 focus:outline-none focus:ring-2 focus:ring-blue-100"})]}),g.jsxs("div",{className:"flex flex-col gap-3 sm:flex-row",children:[g.jsx(f4,{label:t("tasks.filters.agent"),options:d,selectedValues:h,allLabel:t("tasks.filters.allAgents"),getOptionLabel:D=>D,onChange:x}),g.jsx(f4,{label:t("tasks.filters.status"),options:bFe,selectedValues:f,allLabel:t("tasks.filters.allStatuses"),getOptionLabel:D=>t(`tasks.status.${D}`),onChange:b})]})]})}),c&&g.jsxs("div",{className:"flex items-center gap-3 rounded-lg border border-red-200 bg-red-50 px-4 py-3 text-sm text-red-700",children:[g.jsx(Rn,{size:16,className:"shrink-0"}),g.jsx("span",{className:"flex-1",children:c}),g.jsx("button",{onClick:z,className:"rounded-md bg-red-100 px-3 py-1 text-xs font-medium text-red-700 transition-colors hover:bg-red-200",children:t("tasks.retry")})]}),g.jsxs("div",{className:"relative flex min-h-0 flex-col gap-5",children:[g.jsxs("section",{className:"min-w-0 flex-1 overflow-hidden rounded-lg border border-gray-200 bg-white shadow-sm",children:[g.jsx("div",{className:"overflow-x-auto",children:g.jsxs("table",{className:"min-w-full divide-y divide-gray-200",children:[g.jsx("thead",{className:"bg-gray-50",children:g.jsxs("tr",{children:[g.jsx("th",{className:"w-[160px] px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-gray-500",children:t("tasks.columns.time")}),g.jsx("th",{className:`${E} w-[200px] px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-gray-500`,children:t("tasks.columns.taskId")}),g.jsx("th",{className:"w-[140px] px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-gray-500",children:t("tasks.columns.agent")}),g.jsx("th",{className:"w-[80px] px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-gray-500",children:t("tasks.columns.status")}),g.jsx("th",{className:"w-[80px] px-4 py-3 text-right text-xs font-semibold uppercase tracking-wide text-gray-500",children:t("tasks.columns.duration")}),g.jsx("th",{className:`${E} w-[160px] px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-gray-500`,children:t("tasks.columns.model")}),g.jsx("th",{className:"w-[90px] px-4 py-3 text-right text-xs font-semibold uppercase tracking-wide text-gray-500",children:t("tasks.columns.tokens")})]})}),g.jsx("tbody",{className:"divide-y divide-gray-200 bg-white",children:l?g.jsx("tr",{children:g.jsx("td",{colSpan:M,className:"px-4 py-12 text-center text-sm text-gray-500",children:g.jsxs("div",{className:"inline-flex items-center gap-2",children:[g.jsx(Vr,{size:16,className:"animate-spin text-gray-400"}),g.jsx("span",{children:t("tasks.loading")})]})})}):i.length===0?g.jsx("tr",{children:g.jsx("td",{colSpan:M,className:"px-4 py-14",children:g.jsxs("div",{className:"flex flex-col items-center justify-center text-center text-gray-400",children:[g.jsx(OT,{size:36,className:"mb-3"}),g.jsx("p",{className:"text-sm font-medium text-gray-500",children:t("tasks.empty")}),g.jsx("p",{className:"mt-1 text-xs text-gray-400",children:t("tasks.emptyHint")})]})})}):i.map(D=>{const O=C===D.taskId;return g.jsxs("tr",{"aria-selected":O,onClick:()=>F(D.taskId),className:`cursor-pointer transition-colors hover:bg-gray-50 ${O?"bg-blue-50":""}`,children:[g.jsx("td",{className:`px-4 py-3 text-sm text-gray-500 ${O?"border-l-2 border-l-blue-500 bg-blue-50":""}`,children:vFe(D.startedAt,t)}),g.jsx("td",{className:`${E} px-4 py-3 text-sm font-medium text-gray-900`,children:g.jsx("span",{className:"font-mono",title:D.taskId,children:D.taskId})}),g.jsx("td",{className:"px-4 py-3 text-sm font-medium text-gray-900",children:D.agentId}),g.jsx("td",{className:"px-4 py-3 text-sm text-gray-700",children:g.jsx(CFe,{status:D.status})}),g.jsx("td",{className:"px-4 py-3 text-right text-sm text-gray-700",children:wFe(D.durationMs,D.status)}),g.jsx("td",{className:`${E} px-4 py-3 text-sm text-gray-700`,children:D.model??"-"}),g.jsx("td",{className:"px-4 py-3 text-right text-sm text-gray-500 tabular-nums",children:kFe(D.inputTokens,D.outputTokens)})]},D.taskId)})})]})}),g.jsxs("div",{className:"flex flex-col gap-3 border-t border-gray-200 px-4 py-4 sm:flex-row sm:items-center sm:justify-between",children:[g.jsx("p",{className:"text-sm text-gray-500",children:t("tasks.totalCount",{count:s})}),g.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[g.jsx("button",{onClick:()=>m(Math.max(1,o-1)),disabled:o<=1,className:"rounded-lg border border-gray-200 px-3 py-1.5 text-sm text-gray-600 transition-colors hover:bg-gray-50 disabled:cursor-not-allowed disabled:opacity-50",children:t("tasks.pagination.previous")}),B.map(D=>g.jsx("button",{onClick:()=>m(D),className:`rounded-lg px-3 py-1.5 text-sm transition-colors ${D===o?"bg-blue-500 text-white":"border border-gray-200 text-gray-600 hover:bg-gray-50"}`,children:D},D)),g.jsx("button",{onClick:()=>m(Math.min(A,o+1)),disabled:o>=A,className:"rounded-lg border border-gray-200 px-3 py-1.5 text-sm text-gray-600 transition-colors hover:bg-gray-50 disabled:cursor-not-allowed disabled:opacity-50",children:t("tasks.pagination.next")})]})]})]}),C&&g.jsx("div",{className:"fixed inset-y-0 right-0 z-40",children:g.jsx(_N,{defaultWidth:400,minWidth:300,maxWidth:600,side:"left",storageKey:"task-detail-width",children:g.jsx(xFe,{taskId:C,task:S,onClose:()=>F(null),onRefresh:k,onSelectTask:F})})})]})]})}function f_({resource:t,current:e,limit:n}){const{t:r}=me();return g.jsx("div",{"data-testid":`limit-banner-${t}`,className:"rounded-xl border border-amber-200 bg-amber-50 px-4 py-3 text-sm text-amber-800",children:g.jsxs("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-start",children:[g.jsxs("div",{className:"flex-1",children:[g.jsx("div",{className:"font-medium",children:r(`limits.banner.${t}.title`,{current:e,limit:n})}),g.jsx("div",{className:"mt-1 text-amber-700",children:r(`limits.banner.${t}.description`)}),g.jsx("div",{className:"mt-2 text-amber-700",children:r("limits.banner.grandfatherPromise")})]}),g.jsxs("a",{href:_p,target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center justify-center gap-1 rounded-lg bg-amber-600 px-3 py-2 text-xs font-medium text-white transition-colors hover:bg-amber-700",children:[r("upgrade.waitlistCta"),g.jsx(o1,{size:12})]})]})})}const p4={경영진:$ne,개발팀:fF,default:Ka};function EFe({teamName:t,memberCount:e,isCollapsible:n=!1,isExpanded:r=!0,onToggle:i,className:s}){const{t:o}=me(),a=p4[t]??p4.default,l=r?Yr:hs,c=g.jsxs(g.Fragment,{children:[g.jsxs("div",{className:"flex items-center gap-3",children:[g.jsx("div",{className:"flex h-9 w-9 items-center justify-center rounded-lg bg-gray-100 text-gray-600",children:g.jsx(a,{size:18})}),g.jsxs("div",{className:"flex items-center gap-2",children:[g.jsx("span",{className:"text-sm font-semibold text-gray-900",children:t}),g.jsx("span",{className:"rounded-full bg-gray-100 px-2.5 py-1 text-xs font-medium text-gray-500",children:o("agent.team.memberCount",{count:e})})]})]}),n&&g.jsx(l,{size:16,className:"shrink-0 text-gray-400"})]});return n?g.jsx("button",{type:"button",onClick:i,"aria-expanded":r,"aria-label":o(r?"agent.team.collapse":"agent.team.expand",{team:t}),className:`flex w-full items-center justify-between gap-3 rounded-xl border border-gray-200 bg-white px-4 py-3 text-left transition-colors hover:border-gray-300 hover:bg-gray-50 ${s??""}`.trim(),children:c}):g.jsx("div",{role:"button","aria-expanded":!0,className:`flex w-full items-center justify-between gap-3 rounded-xl border border-gray-200 bg-white px-4 py-3 ${s??""}`.trim(),children:c})}const Gd="__unassigned__";function AFe(t){var i,s;const e=new Map,n=[];for(const o of t){const a=((i=o.team)==null?void 0:i.trim())||Gd;e.has(a)||(e.set(a,[]),n.push(a)),(s=e.get(a))==null||s.push(o)}const r=n.filter(o=>o!==Gd);return e.has(Gd)&&r.push(Gd),r.map(o=>({teamKey:o,agents:e.get(o)??[],isUnassigned:o===Gd}))}const au={id:"",name:"",role:"",team:"",description:"",provider:"",model:"",prompt:""},NFe={include:[]},Yd=["cli/claude","cli/codex","cli/gemini","cli/copilot"],MFe={"cli/claude":"agent.guide.providerClaude","cli/codex":"agent.guide.providerCodex","cli/gemini":"agent.guide.providerGemini","cli/copilot":"agent.guide.providerCopilot"},LFe={"cli/claude":"agent.engine.claude","cli/codex":"agent.engine.codex","cli/gemini":"agent.engine.gemini","cli/copilot":"agent.engine.copilot"},DFe={"cli/claude":["claude-opus-4-6","claude-sonnet-4-6","claude-haiku-4-5","claude-opus-4-5","claude-sonnet-4-5","claude-sonnet-4","claude-opus-4-6-fast"],"cli/codex":["gpt-5.3-codex","gpt-5.2-codex","gpt-5.1-codex-mini","o4-mini"],"cli/gemini":["gemini-3-pro-preview","gemini-3-flash-preview","gemini-2.5-pro","gemini-2.5-flash"],"cli/copilot":["claude-sonnet-4-6","claude-sonnet-4-5","claude-haiku-4-5","claude-opus-4-6","claude-opus-4-6-fast","claude-opus-4-5","claude-sonnet-4","gpt-5.4","gpt-5.3-codex","gpt-5.2-codex","gpt-5.2","gpt-5.1","gpt-5.4-mini","gpt-5-mini","gpt-4.1"]},nY={"cli/claude":"claude-sonnet-4-6","cli/gemini":"gemini-3-flash-preview","cli/copilot":"claude-sonnet-4-6"},OFe={"claude-sonnet-4-6":"1x","claude-sonnet-4-5":"1x","claude-haiku-4-5":"0.33x","claude-opus-4-6":"3x","claude-opus-4-6-fast":"30x","claude-opus-4-5":"3x","claude-sonnet-4":"1x","gpt-5.4":"1x","gpt-5.3-codex":"1x","gpt-5.2-codex":"1x","gpt-5.2":"1x","gpt-5.1":"1x","gpt-5.4-mini":"0.33x","gpt-5-mini":"0x","gpt-4.1":"0x"},rY=[{id:"coding-assistant",icon:"📝",titleKey:"agent.template.codingAssistant",descriptionKey:"agent.template.codingAssistantDesc",form:{name:"Coding Assistant",role:"Software Engineer",description:"General coding, implementation, debugging, and refactoring support",provider:"cli/claude",model:"claude-sonnet-4-6"}},{id:"research",icon:"🔍",titleKey:"agent.template.research",descriptionKey:"agent.template.researchDesc",form:{name:"Research Assistant",role:"Researcher",description:"Technical research, comparisons, and source-backed investigation",provider:"cli/gemini",model:"gemini-3-flash-preview"}},{id:"data-analysis",icon:"📊",titleKey:"agent.template.dataAnalysis",descriptionKey:"agent.template.dataAnalysisDesc",form:{name:"Data Analyst",role:"Data Analyst",description:"Data exploration, analysis, and reporting support",provider:"cli/copilot",model:"gpt-5.4"}},{id:"writing",icon:"✍️",titleKey:"agent.template.writing",descriptionKey:"agent.template.writingDesc",form:{name:"Writing Assistant",role:"Technical Writer",description:"Documentation drafting, editing, and structured content writing",provider:"cli/claude",model:"claude-sonnet-4-6"}},{id:"design-review",icon:"🎨",titleKey:"agent.template.designReview",descriptionKey:"agent.template.designReviewDesc",form:{name:"Design Reviewer",role:"Design Reviewer",description:"UI/UX review, multimodal inspection, and feedback support",provider:"cli/gemini",model:"gemini-3-pro-preview"}}];function lu(t){return{include:[...(t==null?void 0:t.include)??NFe.include]}}function RFe(t){return t&&t.charAt(0).toUpperCase()+t.slice(1)}function wf(t,e){if(!t)return"";const n=LFe[t];return n&&e?e(n):t.startsWith("cli/")?RFe(t.slice(4)):t}function oy(t,e){if(!t)return"";if(!e)return t;const n=`agent.model.${t}.label`,r=e(n);return r===n?t:r}function IFe(t){if(!t)return[];const e=DFe[t]??[],n=nY[t];return!n||!e.includes(n)?e:[n,...e.filter(r=>r!==n)]}const BFe=In(t=>({activeTab:"basic",selectedTemplateId:null,form:au,skills:lu(),setActiveTab:e=>t({activeTab:e}),setField:(e,n)=>{t(r=>({form:{...r.form,[e]:n}}))},setProvider:e=>{t(n=>({form:{...n.form,provider:e,model:""}}))},setSkillsInclude:e=>{t(n=>({skills:{...n.skills,include:[...e]}}))},initializeBlank:()=>{t({activeTab:"basic",selectedTemplateId:null,form:au,skills:lu()})},initializeFromAgent:(e,n)=>{const r=(n==null?void 0:n.clearIdentity)??!1;t({activeTab:"basic",selectedTemplateId:null,form:{...au,id:r?"":e.id??"",name:r?"":e.name??"",role:e.role??"",team:e.team??"",description:e.description??"",provider:e.provider??"",model:e.model??"",prompt:e.prompt??""},skills:lu(n==null?void 0:n.skills)})},applyTemplate:e=>{if(!e){t({activeTab:"basic",selectedTemplateId:null,form:au,skills:lu()});return}const n=rY.find(r=>r.id===e);n&&t({activeTab:"basic",selectedTemplateId:n.id,form:{...au,...n.form,id:""},skills:lu()})},reset:()=>{t({activeTab:"basic",selectedTemplateId:null,form:au,skills:lu()})}}));function PFe(t){const e=t.trim().split(/\s+/);return e.length>=2?(e[0][0]+e[1][0]).toUpperCase():t.slice(0,2).toUpperCase()}const g4=[{bg:"bg-blue-100",text:"text-blue-700"},{bg:"bg-purple-100",text:"text-purple-700"},{bg:"bg-green-100",text:"text-green-700"},{bg:"bg-amber-100",text:"text-amber-700"},{bg:"bg-rose-100",text:"text-rose-700"},{bg:"bg-cyan-100",text:"text-cyan-700"},{bg:"bg-indigo-100",text:"text-indigo-700"},{bg:"bg-teal-100",text:"text-teal-700"}];function FFe(t){const e=t.split("").reduce((n,r)=>n+r.charCodeAt(0),0)%g4.length;return g4[e]}const Bv="crewx-agent-accordion-state";function $Fe(t){const e=t.length<=5;return Object.fromEntries(t.map(n=>[n.teamKey,e]))}function jFe({agent:t,onClose:e,onConfirm:n,deleting:r,t:i}){return g.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/40",children:g.jsxs("div",{className:"mx-4 w-full max-w-sm rounded-xl bg-white shadow-xl",children:[g.jsxs("div",{className:"px-6 py-5",children:[g.jsx("h3",{className:"mb-2 text-base font-semibold text-gray-900",children:i("agent.deleteConfirmTitle")}),g.jsx("p",{className:"text-sm text-gray-600",children:i("agent.deleteConfirmMsg",{id:t.id,name:t.name})}),g.jsx("p",{className:"mt-2 text-xs text-red-500",children:i("agent.deleteWarning")})]}),g.jsxs("div",{className:"flex justify-end gap-2 px-6 pb-5",children:[g.jsx("button",{onClick:e,className:"rounded-lg bg-gray-100 px-4 py-2 text-sm font-medium text-gray-700 transition-colors hover:bg-gray-200",children:i("agent.cancel")}),g.jsxs("button",{onClick:n,disabled:r,className:"flex items-center gap-2 rounded-lg bg-red-500 px-4 py-2 text-sm font-medium text-white transition-colors hover:bg-red-600 disabled:cursor-not-allowed disabled:opacity-40",children:[r?g.jsx(ut,{size:14,className:"animate-spin"}):g.jsx($y,{size:14}),i("agent.delete")]})]})]})})}function zFe(){const{setPageHeader:t}=ur(),e=Nt(),{t:n}=me(),r=yn(F=>F.limits),i=yn(F=>F.limitsLoading),s=yn(F=>F.fetchLimits),[o,a]=T.useState([]),[l,c]=T.useState(!0),[u,h]=T.useState(null),[f,d]=T.useState({}),[p,m]=T.useState(!1),[y,x]=T.useState(null),[b,k]=T.useState(!1),w=T.useMemo(()=>AFe(o),[o]),v=r==null?void 0:r.agentsPerWorkspace,C=v!==void 0&&v!==-1&&o.length>=v,S=i||!r||C,E=C&&r?n("limits.banner.agent.title",{current:o.length,limit:r.agentsPerWorkspace}):void 0,M=T.useCallback(async()=>{c(!0),h(null);try{const F=await fe.getAgents();a(F.agents)}catch(F){h(F instanceof Error?F.message:n("agent.listError"))}finally{c(!1)}},[n]);T.useEffect(()=>{t({title:n("agent.management")}),M()},[]),T.useEffect(()=>{s().catch(()=>{})},[s]),T.useEffect(()=>{if(l||u)return;const F=$Fe(w);if(typeof window>"u"){d(F),m(!0);return}let z=F;const D=window.localStorage.getItem(Bv);if(D)try{const O=JSON.parse(D);z=w.reduce((N,$)=>(N[$.teamKey]=typeof O[$.teamKey]=="boolean"?O[$.teamKey]:F[$.teamKey],N),{})}catch{window.localStorage.removeItem(Bv),z=F}d(z),m(!0)},[u,w,l]),T.useEffect(()=>{!p||typeof window>"u"||window.localStorage.setItem(Bv,JSON.stringify(f))},[p,f]);const A=T.useCallback(async()=>{if(y){k(!0);try{await fe.deleteAgent(y.id),x(null),await M()}catch(F){alert(F instanceof Error?F.message:n("agent.deleteError"))}finally{k(!1)}}},[y,M,n]),B=T.useCallback(F=>{d(z=>({...z,[F]:!z[F]}))},[]);return g.jsxs("div",{className:"mx-auto max-w-4xl",children:[g.jsxs("div",{className:"mb-6 flex items-center justify-between",children:[g.jsxs("div",{className:"flex items-center gap-2",children:[g.jsx(Ka,{size:20,className:"text-gray-500"}),g.jsx("h2",{className:"text-lg font-semibold text-gray-900",children:n("agent.management")}),!l&&g.jsx("span",{className:"text-sm text-gray-400",children:n("agent.count",{count:o.length})})]}),g.jsxs("button",{type:"button",disabled:S,title:E,onClick:()=>e("/agents/new"),className:`flex items-center gap-2 rounded-lg px-4 py-2 text-sm font-medium transition-colors ${S?"bg-gray-100 text-gray-400":"bg-blue-500 text-white hover:bg-blue-600"}`,children:[g.jsx(Kr,{size:16}),n("agent.add")]})]}),!l&&!u&&C&&r?g.jsx("div",{className:"mb-6",children:g.jsx(f_,{resource:"agent",current:o.length,limit:r.agentsPerWorkspace})}):null,l&&g.jsx("div",{className:"flex items-center justify-center py-16",children:g.jsx(ut,{size:24,className:"animate-spin text-gray-400"})}),!l&&u&&g.jsxs("div",{className:"flex items-center gap-3 rounded-xl border border-red-200 bg-red-50 p-4 text-red-600",children:[g.jsx(Rn,{size:18,className:"shrink-0"}),g.jsxs("div",{children:[g.jsx("p",{className:"text-sm font-medium",children:n("agent.loadFailTitle")}),g.jsx("p",{className:"mt-0.5 text-xs",children:u})]}),g.jsx("button",{onClick:M,className:"ml-auto text-xs text-red-500 underline hover:text-red-700",children:n("agent.retry")})]}),!l&&!u&&o.length===0&&g.jsxs("div",{className:"flex flex-col items-center justify-center py-16 text-gray-400",children:[g.jsx(Ka,{size:40,className:"mb-3 opacity-30"}),g.jsx("p",{className:"text-sm font-medium",children:n("agent.emptyTitle")}),g.jsx("p",{className:"mt-1 text-xs",children:n("agent.emptyDesc")}),g.jsxs("button",{type:"button",disabled:S,title:E,onClick:()=>e("/agents/new"),className:`mt-4 flex items-center gap-1.5 rounded-lg px-4 py-2 text-sm font-medium transition-colors ${S?"bg-gray-100 text-gray-400":"bg-blue-500 text-white hover:bg-blue-600"}`,children:[g.jsx(Kr,{size:16}),n("agent.emptyAction")]})]}),!l&&!u&&o.length>0&&g.jsx("div",{className:"space-y-4",children:w.map(F=>{const z=f[F.teamKey]??w.length<=5;return g.jsx("section",{children:g.jsxs("div",{className:"overflow-hidden rounded-xl border border-gray-200 bg-white shadow-sm",children:[g.jsx(EFe,{teamName:F.isUnassigned?n("agent.team.unassigned"):F.teamKey,memberCount:F.agents.length,isCollapsible:!0,isExpanded:z,onToggle:()=>B(F.teamKey),className:"rounded-none border-0 border-b border-gray-100 bg-transparent px-5 py-4 shadow-none hover:border-gray-100 hover:bg-gray-50"}),g.jsx("div",{className:"grid transition-[grid-template-rows,opacity] duration-300 ease-out",style:{gridTemplateRows:z?"1fr":"0fr",opacity:z?1:.7},children:g.jsx("div",{className:"min-h-0 overflow-hidden",children:g.jsx("div",{className:"divide-y divide-gray-100",children:F.agents.map(D=>{var I,P,L;const{bg:O,text:N}=FFe(D.id),$=[D.role,wf(D.provider,n),oy(D.model,n)].filter(Boolean).join(" · ");return g.jsxs("div",{className:"group flex items-center gap-4 px-5 py-4 transition-colors hover:bg-gray-50",children:[g.jsxs("div",{className:"relative shrink-0",children:[g.jsx("div",{className:`flex h-10 w-10 items-center justify-center rounded-full text-sm font-bold ${O} ${N}`,children:PFe(D.name)}),((I=D.provider)==null?void 0:I.startsWith("remote/"))&&g.jsx("div",{className:`absolute -bottom-1 -right-1 flex h-5 w-5 items-center justify-center rounded-full border border-white ${(P=D.providerLocation)!=null&&P.startsWith("file://")?"bg-gray-600":"bg-gray-700"}`,children:(L=D.providerLocation)!=null&&L.startsWith("file://")?g.jsx(gre,{size:11,className:"text-gray-300"}):g.jsx(Lne,{size:11,className:"text-blue-300"})})]}),g.jsxs("div",{className:"min-w-0 flex-1",children:[g.jsxs("div",{className:"flex items-center gap-2",children:[g.jsx("span",{className:"truncate text-sm font-semibold text-gray-900",children:D.name}),g.jsxs("span",{className:"truncate text-xs text-gray-400",children:["@",D.id]})]}),$&&g.jsx("p",{className:"mt-0.5 truncate text-xs text-gray-500",children:$}),D.description&&g.jsx("p",{className:"mt-0.5 truncate text-xs text-gray-400",children:D.description})]}),g.jsxs("div",{className:"flex shrink-0 items-center gap-1 opacity-0 transition-opacity group-hover:opacity-100",children:[g.jsxs("button",{onClick:()=>e(`/agents/new?from=${encodeURIComponent(D.id)}`),className:"flex items-center gap-1.5 rounded-lg bg-blue-50 px-3 py-1.5 text-xs font-medium text-blue-700 transition-colors hover:bg-blue-100",children:[g.jsx(yg,{size:13}),n("agent.duplicate")]}),g.jsxs("button",{onClick:()=>e(`/agents/${D.id}/edit`),className:"flex items-center gap-1.5 rounded-lg bg-gray-100 px-3 py-1.5 text-xs font-medium text-gray-600 transition-colors hover:bg-gray-200",children:[g.jsx(lie,{size:13}),n("agent.edit")]}),g.jsxs("button",{onClick:()=>x(D),className:"flex items-center gap-1.5 rounded-lg bg-red-50 px-3 py-1.5 text-xs font-medium text-red-600 transition-colors hover:bg-red-100",children:[g.jsx($y,{size:13}),n("agent.delete")]})]})]},D.id)})})})})]})},F.teamKey)})}),y&&g.jsx(jFe,{agent:y,onClose:()=>x(null),onConfirm:A,deleting:b,t:n})]})}const HFe=T.lazy(()=>et(()=>import("./PromptTab-CBlt-krG.js"),[],import.meta.url));function UFe(t){return t.trim()?t:""}function iY(t){return{include:[...t]}}function WFe(t,e){return{id:t.id.trim(),name:t.name.trim(),role:t.role.trim(),team:t.team.trim(),description:t.description.trim(),provider:t.provider||void 0,model:t.model||void 0,prompt:UFe(t.prompt),skills:iY(e)}}function m4(t){return typeof t=="object"&&t!==null}function qFe(t){if(!(t instanceof Ql))return"UNKNOWN";if(m4(t.body)){if(typeof t.body.code=="string")return t.body.code;if(m4(t.body.error)&&typeof t.body.error.code=="string")return t.body.error.code}return"UNKNOWN"}function y4(){var ct;const t=Nt(),{agentId:e}=Kh(),[n]=mg(),{setPageHeader:r}=ur(),{t:i}=me(),s=ul(ne=>ne.addToast),o=((ct=n.get("from"))==null?void 0:ct.trim())||null,a=!!e,l=!a&&!!o,c=!a&&!l,u=e??o,{form:h,skills:f,activeTab:d,selectedTemplateId:p,setActiveTab:m,setField:y,setProvider:x,setSkillsInclude:b,initializeBlank:k,initializeFromAgent:w,applyTemplate:v,reset:C}=BFe(),[S,E]=T.useState(!!u),[M,A]=T.useState(!1),[B,F]=T.useState(null),[z,D]=T.useState(null),[O,N]=T.useState([]),[$,I]=T.useState(!0),[P,L]=T.useState(null),[W,G]=T.useState(0),j=h.provider.startsWith("remote/"),V=a&&j,Z=T.useMemo(()=>!h.provider||Yd.includes(h.provider)?[...Yd]:h.provider.startsWith("cli/")?[h.provider,...Yd]:[...Yd],[h.provider]),re=T.useMemo(()=>IFe(h.provider),[h.provider]),ve=h.provider?nY[h.provider]:void 0,Ee=!!h.model&&!re.includes(h.model),qe=wf(h.provider,i),he=T.useMemo(()=>O.filter(ne=>ne.source!=="builtin"),[O]);T.useEffect(()=>{r({title:i(a?"agent.edit":"agent.add")})},[a,r]),T.useEffect(()=>()=>C(),[C]);const be=T.useCallback(ne=>{w(ne,{clearIdentity:l,skills:ne.skills})},[w,l]);T.useEffect(()=>{let ne=!1;return(async()=>{if(F(null),!u){k(),E(!1);return}E(!0);try{const je=await fe.getAgents();if(ne)return;const Kt=je.agents.find(gn=>gn.id===u);if(!Kt){F(i("agent.notFound"));return}be(Kt)}catch(je){if(ne)return;F(je instanceof Error?je.message:i(l?"agent.duplicateError":"agent.loadError"))}finally{ne||E(!1)}})(),()=>{ne=!0}},[be,k,l,u]),T.useEffect(()=>{let ne=!1;return(async()=>{I(!0),L(null);try{const je=await fe.getInstalledSkills();if(ne)return;N(je.skills)}catch(je){if(ne)return;L(je instanceof Error?je.message:i("agent.skills.loadError"))}finally{ne||I(!1)}})(),()=>{ne=!0}},[W]);const Ve=T.useCallback(ne=>{const Ge=f.include.includes(ne)?f.include.filter(je=>je!==ne):[...f.include,ne];b(Ge)},[b,f.include]),te=ne=>Ge=>{if(ne==="provider"){x(Ge.target.value);return}y(ne,Ge.target.value)},$e=ne=>{v(ne)},ee=async ne=>{ne.preventDefault(),A(!0),D(null);try{const Ge=WFe(h,f.include);if(a&&e){const je={name:Ge.name,role:Ge.role,team:Ge.team,description:Ge.description,provider:Ge.provider,model:Ge.model,prompt:Ge.prompt,skills:iY(f.include)};await fe.updateAgent(e,je)}else await fe.createAgent(Ge);t("/agents")}catch(Ge){const je=qFe(Ge);if(!a&&je==="AGENT_LIMIT_EXCEEDED"){D(je),s({type:"error",duration:1e4,message:g.jsxs("div",{className:"space-y-2",children:[g.jsx("div",{children:i("agent.createError.AGENT_LIMIT_EXCEEDED")}),g.jsx("a",{href:_p,target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center text-sm font-medium text-red-700 underline underline-offset-2 transition-colors hover:text-red-800",children:i("upgrade.waitlistCta")})]})});return}alert(Ge instanceof Error?Ge.message:i("agent.saveError"))}finally{A(!1)}},ge="w-full rounded-lg border border-gray-300 bg-white px-3 py-2.5 text-sm text-gray-900 placeholder-gray-400 shadow-sm transition focus:border-blue-500 focus:outline-none focus:ring-2 focus:ring-blue-500/20",ze="bg-gray-100 text-gray-500 cursor-not-allowed",ce="mb-1.5 block text-sm font-medium text-gray-700",Ut="rounded-xl border border-gray-200 bg-white p-6 shadow-sm";return S?g.jsx("div",{className:"flex items-center justify-center py-24",children:g.jsx(ut,{size:28,className:"animate-spin text-gray-400"})}):B?g.jsxs("div",{className:"mx-auto max-w-3xl px-4 py-8",children:[g.jsx("p",{className:"text-sm text-red-500",children:B}),g.jsx("button",{onClick:()=>t("/agents"),className:"mt-4 text-sm text-gray-500 underline transition hover:text-gray-900",children:i("agent.backToList")})]}):g.jsxs("div",{className:`mx-auto px-4 py-6 text-gray-900 ${d==="prompt"?"max-w-6xl":"max-w-3xl"}`,children:[g.jsxs("div",{className:"mb-6 flex items-center gap-3",children:[g.jsx("button",{onClick:()=>t("/agents"),className:"flex h-9 w-9 items-center justify-center rounded-lg border border-gray-200 bg-white text-gray-500 shadow-sm transition hover:bg-gray-50 hover:text-gray-900","aria-label":i("agent.back"),children:g.jsx(LT,{size:18})}),g.jsxs("div",{children:[g.jsx("h1",{className:"text-xl font-semibold text-gray-900",children:i(a?"agent.edit":"agent.add")}),l&&o&&g.jsxs("p",{className:"mt-1 text-sm text-gray-500",children:["@",o]})]})]}),c&&g.jsxs("section",{className:`${Ut} mb-5`,children:[g.jsxs("div",{className:"mb-4",children:[g.jsx("h2",{className:"text-sm font-semibold text-gray-900",children:i("agent.template.title")}),g.jsx("p",{className:"mt-1 text-sm text-gray-500",children:i("agent.template.subtitle")})]}),g.jsxs("div",{className:"flex flex-wrap gap-2.5",children:[rY.map(ne=>{const Ge=p===ne.id;return g.jsxs("button",{type:"button",onClick:()=>$e(ne.id),className:`inline-flex items-center gap-2 rounded-full border px-3.5 py-2 text-sm font-medium transition ${Ge?"border-blue-500 bg-blue-50 text-blue-700":"border-gray-200 bg-white text-gray-700 hover:border-gray-300 hover:bg-gray-50"}`,children:[g.jsx("span",{"aria-hidden":"true",children:ne.icon}),g.jsx("span",{children:i(ne.titleKey)})]},ne.id)}),g.jsx("button",{type:"button",onClick:()=>$e(null),className:`inline-flex items-center gap-2 rounded-full border px-3.5 py-2 text-sm font-medium transition ${p===null?"border-blue-500 bg-blue-50 text-blue-700":"border-dashed border-gray-300 bg-white text-gray-600 hover:border-gray-400 hover:bg-gray-50"}`,children:g.jsx("span",{children:i("agent.template.direct")})})]})]}),z==="AGENT_LIMIT_EXCEEDED"?g.jsxs("div",{className:"mb-5 rounded-xl border border-red-200 bg-red-50 px-4 py-4 text-sm text-red-700",children:[g.jsx("p",{children:i("agent.createError.AGENT_LIMIT_EXCEEDED")}),g.jsx("a",{href:_p,target:"_blank",rel:"noopener noreferrer",className:"mt-3 inline-flex items-center gap-1 text-sm font-medium text-red-700 transition-colors hover:text-red-800 hover:underline",children:i("upgrade.waitlistCta")})]}):null,g.jsxs("form",{onSubmit:ee,className:"space-y-5",children:[g.jsxs("div",{className:"overflow-hidden rounded-xl border border-gray-200 bg-white shadow-sm",children:[g.jsxs("div",{className:"flex border-b border-gray-200",children:[g.jsx("button",{type:"button",onClick:()=>m("basic"),className:`px-5 py-3 text-sm font-medium transition ${d==="basic"?"border-b-2 border-blue-500 text-blue-600":"text-gray-500 hover:text-gray-900"}`,children:i("agent.tab.basic")}),g.jsx("button",{type:"button",onClick:()=>m("skills"),className:`px-5 py-3 text-sm font-medium transition ${d==="skills"?"border-b-2 border-blue-500 text-blue-600":"text-gray-500 hover:text-gray-900"}`,children:i("agent.tab.skills")}),g.jsx("button",{type:"button",onClick:()=>m("prompt"),className:`px-5 py-3 text-sm font-medium transition ${d==="prompt"?"border-b-2 border-blue-500 text-blue-600":"text-gray-500 hover:text-gray-900"}`,children:i("agent.tab.prompt")})]}),g.jsx("div",{className:"p-6",children:d==="basic"?g.jsxs("div",{className:"space-y-5",children:[g.jsxs("div",{children:[g.jsx("h2",{className:"text-base font-semibold text-gray-900",children:i("agent.section.basicTitle")}),g.jsx("p",{className:"mt-1 text-sm text-gray-500",children:i("agent.section.basicDescription")})]}),g.jsxs("div",{children:[g.jsxs("label",{className:ce,children:[i("agent.field.id")," ",!a&&g.jsx("span",{className:"text-red-500",children:"*"})]}),g.jsx("input",{type:"text",value:h.id,onChange:te("id"),placeholder:i("agent.field.idPlaceholder"),required:!a,disabled:a,className:`${ge} ${a?ze:""}`}),!a&&g.jsx("p",{className:"mt-1.5 text-xs text-gray-500",children:i("agent.field.idHint")})]}),g.jsxs("div",{children:[g.jsxs("label",{className:ce,children:[i("agent.field.name")," ",g.jsx("span",{className:"text-red-500",children:"*"})]}),g.jsx("input",{type:"text",value:h.name,onChange:te("name"),placeholder:i("agent.field.namePlaceholder"),required:!0,className:ge})]}),g.jsxs("div",{children:[g.jsx("label",{className:ce,children:i("agent.field.role")}),g.jsx("input",{type:"text",value:h.role,onChange:te("role"),placeholder:i("agent.field.rolePlaceholder"),className:ge})]}),g.jsxs("div",{children:[g.jsx("label",{className:ce,children:i("agent.field.team")}),g.jsx("input",{type:"text",value:h.team,onChange:te("team"),placeholder:i("agent.field.teamPlaceholder"),className:ge})]}),g.jsxs("div",{children:[g.jsxs("div",{className:"mb-1.5 flex items-center gap-1.5",children:[g.jsx("span",{className:"text-sm font-medium text-gray-700",children:i("agent.field.provider")}),g.jsxs("div",{className:"group/provider relative",children:[g.jsx(JC,{size:14,className:"cursor-help text-gray-400 transition hover:text-gray-600"}),g.jsxs("div",{className:"pointer-events-none absolute left-0 top-full z-50 mt-2 hidden min-w-[280px] rounded-lg border border-gray-200 bg-white p-4 text-xs text-gray-700 shadow-lg group-hover/provider:block",children:[g.jsx("p",{className:"mb-2 font-semibold text-gray-900",children:i("agent.guide.providerTitle")}),Yd.map(ne=>g.jsxs("div",{className:"mb-1.5 last:mb-0",children:[g.jsx("span",{className:"font-semibold text-gray-900",children:wf(ne,i)}),g.jsxs("span",{className:"text-gray-500",children:[" — ",i(MFe[ne])]})]},ne))]})]})]}),V?g.jsx("input",{type:"text",value:wf(h.provider,i),disabled:!0,className:`${ge} ${ze}`}):g.jsxs("select",{value:h.provider,onChange:te("provider"),className:ge,children:[g.jsx("option",{value:"",children:i("agent.field.selectProvider")}),Z.map(ne=>g.jsx("option",{value:ne,children:wf(ne,i)},ne))]})]}),g.jsxs("div",{children:[g.jsxs("div",{className:"mb-1.5 flex items-center gap-1.5",children:[g.jsx("span",{className:"text-sm font-medium text-gray-700",children:i("agent.field.model")}),g.jsxs("div",{className:"group/model relative",children:[g.jsx(JC,{size:14,className:"cursor-help text-gray-400 transition hover:text-gray-600"}),g.jsx("div",{className:"pointer-events-none absolute left-0 top-full z-50 mt-2 hidden min-w-[320px] rounded-lg border border-gray-200 bg-white p-4 text-xs text-gray-700 shadow-lg group-hover/model:block",children:h.provider&&re.length>0?g.jsxs(g.Fragment,{children:[g.jsx("p",{className:"mb-2 font-semibold text-gray-900",children:i("agent.guide.modelTitle",{provider:qe})}),re.map(ne=>{const Ge=ve===ne;return g.jsxs("div",{className:"mb-1.5 last:mb-0",children:[g.jsxs("span",{className:"font-semibold text-gray-900",children:[Ge?"⭐ ":"",oy(ne,i),Ge?` (${i("agent.field.recommended")})`:""]}),g.jsxs("span",{className:"text-gray-500",children:[" ","— ",i(`agent.model.${ne}.cost`)," · ",i(`agent.model.${ne}.desc`)]})]},ne)})]}):g.jsx("p",{className:"text-gray-500",children:i("agent.field.selectProviderFirst")})})]})]}),V?g.jsx("input",{type:"text",value:oy(h.model,i)||h.model,disabled:!0,className:`${ge} ${ze}`}):g.jsxs("select",{value:h.model,onChange:te("model"),disabled:!h.provider,className:`${ge} ${h.provider?"":ze}`,children:[g.jsx("option",{value:"",children:h.provider?i("agent.field.selectModel"):i("agent.field.selectProviderFirst")}),Ee&&g.jsxs("option",{value:h.model,children:[h.model," (",i("agent.field.custom"),")"]}),re.map(ne=>{const Ge=ve===ne,je=oy(ne,i);let Kt="";if(h.provider==="cli/copilot"){const gn=OFe[ne];gn&&(Kt=` — ${gn}`)}else{const gn=`agent.model.${ne}.cost`,U=i(gn);Kt=U!==gn?` — ${U}`:""}return g.jsx("option",{value:ne,children:Ge?`⭐ ${je} (${i("agent.field.recommended")})${Kt}`:`${je}${Kt}`},ne)})]})]}),g.jsxs("div",{children:[g.jsx("label",{className:ce,children:i("agent.field.description")}),g.jsx("textarea",{value:h.description,onChange:te("description"),placeholder:i("agent.field.descPlaceholder"),rows:5,className:`${ge} resize-none`})]})]}):d==="skills"?g.jsxs("div",{className:"space-y-4",children:[g.jsxs("div",{children:[g.jsx("h2",{className:"text-base font-semibold text-gray-900",children:i("agent.section.skillsTitle")}),g.jsx("p",{className:"mt-1 text-sm text-gray-500",children:i("agent.section.skillsDescription")})]}),$?g.jsx("div",{className:"flex items-center justify-center py-20",children:g.jsx(ut,{size:24,className:"animate-spin text-gray-400"})}):P?g.jsxs("div",{className:"rounded-xl border border-red-200 bg-red-50 px-4 py-4 text-sm text-red-700",children:[g.jsx("p",{children:P}),g.jsx("button",{type:"button",onClick:()=>G(ne=>ne+1),className:"mt-3 font-medium underline underline-offset-2 transition hover:text-red-800",children:i("agent.retry")})]}):he.length===0?g.jsx("div",{className:"rounded-xl border border-gray-200 bg-white px-6 py-16",children:g.jsxs("div",{className:"mx-auto flex max-w-xl flex-col items-center text-center",children:[g.jsx("div",{className:"mb-5 rounded-full bg-gray-100 p-4 text-gray-500",children:g.jsx(gF,{size:40,strokeWidth:1.8})}),g.jsx("h3",{className:"text-3xl font-semibold tracking-tight text-gray-900",children:i("agent.skills.emptyTitle")}),g.jsx("p",{className:"mt-4 text-lg leading-8 text-gray-500",children:i("agent.skills.emptyDescription")}),g.jsxs("button",{type:"button",onClick:()=>t("/market"),className:"mt-8 inline-flex items-center gap-2 rounded-2xl border border-gray-200 bg-white px-6 py-3 text-base font-semibold text-gray-900 shadow-sm transition hover:bg-gray-50",children:[g.jsx(o1,{size:18}),i("agent.skills.openMarket")]})]})}):g.jsx("div",{className:"overflow-hidden rounded-xl border border-gray-200 bg-white",children:g.jsx("div",{className:"max-h-[420px] overflow-y-auto",children:he.map((ne,Ge)=>{const je=f.include.includes(ne.name);return g.jsxs("label",{className:`flex cursor-pointer items-start gap-4 px-4 py-4 transition hover:bg-gray-50 ${Ge>0?"border-t border-gray-200":""}`,children:[g.jsx("input",{type:"checkbox",checked:je,onChange:()=>Ve(ne.name),"aria-label":ne.name,className:"mt-0.5 h-5 w-5 rounded border-gray-300 text-gray-900 focus:ring-gray-900"}),g.jsxs("div",{className:"min-w-0",children:[g.jsx("div",{className:"text-base font-semibold text-gray-900",children:ne.name}),ne.description?g.jsx("p",{className:"mt-1 text-sm text-gray-500",children:ne.description}):null]})]},ne.name)})})})]}):g.jsx(T.Suspense,{fallback:g.jsx("div",{className:"flex items-center justify-center py-24",children:g.jsx(ut,{size:28,className:"animate-spin text-gray-400"})}),children:g.jsx(HFe,{previewAgentId:u})})})]}),g.jsxs("div",{className:"flex items-center justify-end gap-3 border-t border-gray-200 pt-4",children:[g.jsx("button",{type:"button",onClick:()=>t("/agents"),className:"rounded-lg border border-gray-200 bg-white px-5 py-2.5 text-sm font-medium text-gray-700 shadow-sm transition hover:bg-gray-50 hover:text-gray-900",children:i("agent.cancel")}),g.jsxs("button",{type:"submit",disabled:M||!a&&!h.id.trim()||!h.name.trim(),className:"inline-flex items-center gap-2 rounded-lg bg-blue-500 px-5 py-2.5 text-sm font-medium text-white transition hover:bg-blue-600 disabled:cursor-not-allowed disabled:opacity-40",children:[M?g.jsx(ut,{size:15,className:"animate-spin"}):g.jsx(mF,{size:15}),i(a?"agent.save":"agent.add")]})]})]})]})}function sY({node:t,depth:e=0,expandedFolders:n,onToggle:r,onSelect:i,selectedPath:s,isFileDisabled:o,renderFileSuffix:a}){var p;const l=n.has(t.path),c=s===t.path,u=t.type==="dir",h=u&&(t.hasCrewxYaml!==void 0||t.isRegistered!==void 0),f=(!u||h)&&((o==null?void 0:o(t))??!1),d=()=>{if(u){f||r(t.path);return}f||i(t.path)};return g.jsxs("div",{children:[g.jsxs("button",{type:"button",onClick:d,disabled:f,style:{paddingLeft:`${8+e*16}px`},className:`flex w-full items-center gap-1.5 py-1 pr-2 text-left text-sm transition-colors ${c?"bg-blue-50 font-medium text-blue-700":"text-gray-700 hover:bg-gray-100"} ${f?"cursor-not-allowed opacity-50 hover:bg-transparent":""}`,children:[u?g.jsxs(g.Fragment,{children:[l?g.jsx(Yr,{className:"h-3.5 w-3.5 shrink-0 text-gray-400"}):g.jsx(hs,{className:"h-3.5 w-3.5 shrink-0 text-gray-400"}),l?g.jsx(is,{className:"h-4 w-4 shrink-0 text-amber-500"}):g.jsx(Zne,{className:"h-4 w-4 shrink-0 text-amber-500"})]}):g.jsxs(g.Fragment,{children:[g.jsx("span",{className:"w-3.5 shrink-0"}),g.jsx(Uo,{className:"h-4 w-4 shrink-0 text-gray-400"})]}),g.jsx("span",{className:"min-w-0 flex-1 truncate",children:t.name}),!u||h?a==null?void 0:a(t):null]}),u&&l&&((p=t.children)!=null&&p.length)?g.jsx("div",{children:t.children.map(m=>g.jsx(sY,{node:m,depth:e+1,expandedFolders:n,onToggle:r,onSelect:i,selectedPath:s,isFileDisabled:o,renderFileSuffix:a},m.path))}):null]})}function oY({nodes:t,expandedFolders:e,onToggle:n,onSelect:r,selectedPath:i,isFileDisabled:s,renderFileSuffix:o}){return g.jsx("div",{children:t.map(a=>g.jsx(sY,{node:a,expandedFolders:e,onToggle:n,onSelect:r,selectedPath:i,isFileDisabled:s,renderFileSuffix:o},a.path))})}let p_,g_;if(typeof WeakMap<"u"){let t=new WeakMap;p_=e=>t.get(e),g_=(e,n)=>(t.set(e,n),n)}else{const t=[];let n=0;p_=r=>{for(let i=0;i<t.length;i+=2)if(t[i]==r)return t[i+1]},g_=(r,i)=>(n==10&&(n=0),t[n++]=r,t[n++]=i)}var en=class{constructor(t,e,n,r){this.width=t,this.height=e,this.map=n,this.problems=r}findCell(t){for(let e=0;e<this.map.length;e++){const n=this.map[e];if(n!=t)continue;const r=e%this.width,i=e/this.width|0;let s=r+1,o=i+1;for(let a=1;s<this.width&&this.map[e+a]==n;a++)s++;for(let a=1;o<this.height&&this.map[e+this.width*a]==n;a++)o++;return{left:r,top:i,right:s,bottom:o}}throw new RangeError(`No cell with offset ${t} found`)}colCount(t){for(let e=0;e<this.map.length;e++)if(this.map[e]==t)return e%this.width;throw new RangeError(`No cell with offset ${t} found`)}nextCell(t,e,n){const{left:r,right:i,top:s,bottom:o}=this.findCell(t);return e=="horiz"?(n<0?r==0:i==this.width)?null:this.map[s*this.width+(n<0?r-1:i)]:(n<0?s==0:o==this.height)?null:this.map[r+this.width*(n<0?s-1:o)]}rectBetween(t,e){const{left:n,right:r,top:i,bottom:s}=this.findCell(t),{left:o,right:a,top:l,bottom:c}=this.findCell(e);return{left:Math.min(n,o),top:Math.min(i,l),right:Math.max(r,a),bottom:Math.max(s,c)}}cellsInRect(t){const e=[],n={};for(let r=t.top;r<t.bottom;r++)for(let i=t.left;i<t.right;i++){const s=r*this.width+i,o=this.map[s];n[o]||(n[o]=!0,!(i==t.left&&i&&this.map[s-1]==o||r==t.top&&r&&this.map[s-this.width]==o)&&e.push(o))}return e}positionAt(t,e,n){for(let r=0,i=0;;r++){const s=i+n.child(r).nodeSize;if(r==t){let o=e+t*this.width;const a=(t+1)*this.width;for(;o<a&&this.map[o]<i;)o++;return o==a?s-1:this.map[o]}i=s}}static get(t){return p_(t)||g_(t,VFe(t))}};function VFe(t){if(t.type.spec.tableRole!="table")throw new RangeError("Not a table node: "+t.type.name);const e=GFe(t),n=t.childCount,r=[];let i=0,s=null;const o=[];for(let c=0,u=e*n;c<u;c++)r[c]=0;for(let c=0,u=0;c<n;c++){const h=t.child(c);u++;for(let p=0;;p++){for(;i<r.length&&r[i]!=0;)i++;if(p==h.childCount)break;const m=h.child(p),{colspan:y,rowspan:x,colwidth:b}=m.attrs;for(let k=0;k<x;k++){if(k+c>=n){(s||(s=[])).push({type:"overlong_rowspan",pos:u,n:x-k});break}const w=i+k*e;for(let v=0;v<y;v++){r[w+v]==0?r[w+v]=u:(s||(s=[])).push({type:"collision",row:c,pos:u,n:y-v});const C=b&&b[v];if(C){const S=(w+v)%e*2,E=o[S];E==null||E!=C&&o[S+1]==1?(o[S]=C,o[S+1]=1):E==C&&o[S+1]++}}}i+=y,u+=m.nodeSize}const f=(c+1)*e;let d=0;for(;i<f;)r[i++]==0&&d++;d&&(s||(s=[])).push({type:"missing",row:c,n:d}),u++}(e===0||n===0)&&(s||(s=[])).push({type:"zero_sized"});const a=new en(e,n,r,s);let l=!1;for(let c=0;!l&&c<o.length;c+=2)o[c]!=null&&o[c+1]<n&&(l=!0);return l&&YFe(a,o,t),a}function GFe(t){let e=-1,n=!1;for(let r=0;r<t.childCount;r++){const i=t.child(r);let s=0;if(n)for(let o=0;o<r;o++){const a=t.child(o);for(let l=0;l<a.childCount;l++){const c=a.child(l);o+c.attrs.rowspan>r&&(s+=c.attrs.colspan)}}for(let o=0;o<i.childCount;o++){const a=i.child(o);s+=a.attrs.colspan,a.attrs.rowspan>1&&(n=!0)}e==-1?e=s:e!=s&&(e=Math.max(e,s))}return e}function YFe(t,e,n){t.problems||(t.problems=[]);const r={};for(let i=0;i<t.map.length;i++){const s=t.map[i];if(r[s])continue;r[s]=!0;const o=n.nodeAt(s);if(!o)throw new RangeError(`No cell with offset ${s} found`);let a=null;const l=o.attrs;for(let c=0;c<l.colspan;c++){const u=e[(i+c)%t.width*2];u!=null&&(!l.colwidth||l.colwidth[c]!=u)&&((a||(a=KFe(l)))[c]=u)}a&&t.problems.unshift({type:"colwidth mismatch",pos:s,colwidth:a})}}function KFe(t){if(t.colwidth)return t.colwidth.slice();const e=[];for(let n=0;n<t.colspan;n++)e.push(0);return e}function lr(t){let e=t.cached.tableNodeTypes;if(!e){e=t.cached.tableNodeTypes={};for(const n in t.nodes){const r=t.nodes[n],i=r.spec.tableRole;i&&(e[i]=r)}}return e}const pa=new Ct("selectingCells");function Dc(t){for(let e=t.depth-1;e>0;e--)if(t.node(e).type.spec.tableRole=="row")return t.node(0).resolve(t.before(e+1));return null}function XFe(t){for(let e=t.depth;e>0;e--){const n=t.node(e).type.spec.tableRole;if(n==="cell"||n==="header_cell")return t.node(e)}return null}function ms(t){const e=t.selection.$head;for(let n=e.depth;n>0;n--)if(e.node(n).type.spec.tableRole=="row")return!0;return!1}function lk(t){const e=t.selection;if("$anchorCell"in e&&e.$anchorCell)return e.$anchorCell.pos>e.$headCell.pos?e.$anchorCell:e.$headCell;if("node"in e&&e.node&&e.node.type.spec.tableRole=="cell")return e.$anchor;const n=Dc(e.$head)||ZFe(e.$head);if(n)return n;throw new RangeError(`No cell found around position ${e.head}`)}function ZFe(t){for(let e=t.nodeAfter,n=t.pos;e;e=e.firstChild,n++){const r=e.type.spec.tableRole;if(r=="cell"||r=="header_cell")return t.doc.resolve(n)}for(let e=t.nodeBefore,n=t.pos;e;e=e.lastChild,n--){const r=e.type.spec.tableRole;if(r=="cell"||r=="header_cell")return t.doc.resolve(n-e.nodeSize)}}function m_(t){return t.parent.type.spec.tableRole=="row"&&!!t.nodeAfter}function QFe(t){return t.node(0).resolve(t.pos+t.nodeAfter.nodeSize)}function EN(t,e){return t.depth==e.depth&&t.pos>=e.start(-1)&&t.pos<=e.end(-1)}function aY(t,e,n){const r=t.node(-1),i=en.get(r),s=t.start(-1),o=i.nextCell(t.pos-s,e,n);return o==null?null:t.node(0).resolve(s+o)}function Oc(t,e,n=1){const r={...t,colspan:t.colspan-n};return r.colwidth&&(r.colwidth=r.colwidth.slice(),r.colwidth.splice(e,n),r.colwidth.some(i=>i>0)||(r.colwidth=null)),r}function lY(t,e,n=1){const r={...t,colspan:t.colspan+n};if(r.colwidth){r.colwidth=r.colwidth.slice();for(let i=0;i<n;i++)r.colwidth.splice(e,0,0)}return r}function JFe(t,e,n){const r=lr(e.type.schema).header_cell;for(let i=0;i<t.height;i++)if(e.nodeAt(t.map[n+i*t.width]).type!=r)return!1;return!0}var At=class mo extends Pe{constructor(e,n=e){const r=e.node(-1),i=en.get(r),s=e.start(-1),o=i.rectBetween(e.pos-s,n.pos-s),a=e.node(0),l=i.cellsInRect(o).filter(u=>u!=n.pos-s);l.unshift(n.pos-s);const c=l.map(u=>{const h=r.nodeAt(u);if(!h)throw new RangeError(`No cell with offset ${u} found`);const f=s+u+1;return new zq(a.resolve(f),a.resolve(f+h.content.size))});super(c[0].$from,c[0].$to,c),this.$anchorCell=e,this.$headCell=n}map(e,n){const r=e.resolve(n.map(this.$anchorCell.pos)),i=e.resolve(n.map(this.$headCell.pos));if(m_(r)&&m_(i)&&EN(r,i)){const s=this.$anchorCell.node(-1)!=r.node(-1);return s&&this.isRowSelection()?mo.rowSelection(r,i):s&&this.isColSelection()?mo.colSelection(r,i):new mo(r,i)}return Le.between(r,i)}content(){const e=this.$anchorCell.node(-1),n=en.get(e),r=this.$anchorCell.start(-1),i=n.rectBetween(this.$anchorCell.pos-r,this.$headCell.pos-r),s={},o=[];for(let l=i.top;l<i.bottom;l++){const c=[];for(let u=l*n.width+i.left,h=i.left;h<i.right;h++,u++){const f=n.map[u];if(s[f])continue;s[f]=!0;const d=n.findCell(f);let p=e.nodeAt(f);if(!p)throw new RangeError(`No cell with offset ${f} found`);const m=i.left-d.left,y=d.right-i.right;if(m>0||y>0){let x=p.attrs;if(m>0&&(x=Oc(x,0,m)),y>0&&(x=Oc(x,x.colspan-y,y)),d.left<i.left){if(p=p.type.createAndFill(x),!p)throw new RangeError(`Could not create cell with attrs ${JSON.stringify(x)}`)}else p=p.type.create(x,p.content)}if(d.top<i.top||d.bottom>i.bottom){const x={...p.attrs,rowspan:Math.min(d.bottom,i.bottom)-Math.max(d.top,i.top)};d.top<i.top?p=p.type.createAndFill(x):p=p.type.create(x,p.content)}c.push(p)}o.push(e.child(l).copy(Q.from(c)))}const a=this.isColSelection()&&this.isRowSelection()?e:o;return new de(Q.from(a),1,1)}replace(e,n=de.empty){const r=e.steps.length,i=this.ranges;for(let o=0;o<i.length;o++){const{$from:a,$to:l}=i[o],c=e.mapping.slice(r);e.replace(c.map(a.pos),c.map(l.pos),o?de.empty:n)}const s=Pe.findFrom(e.doc.resolve(e.mapping.slice(r).map(this.to)),-1);s&&e.setSelection(s)}replaceWith(e,n){this.replace(e,new de(Q.from(n),0,0))}forEachCell(e){const n=this.$anchorCell.node(-1),r=en.get(n),i=this.$anchorCell.start(-1),s=r.cellsInRect(r.rectBetween(this.$anchorCell.pos-i,this.$headCell.pos-i));for(let o=0;o<s.length;o++)e(n.nodeAt(s[o]),i+s[o])}isColSelection(){const e=this.$anchorCell.index(-1),n=this.$headCell.index(-1);if(Math.min(e,n)>0)return!1;const r=e+this.$anchorCell.nodeAfter.attrs.rowspan,i=n+this.$headCell.nodeAfter.attrs.rowspan;return Math.max(r,i)==this.$headCell.node(-1).childCount}static colSelection(e,n=e){const r=e.node(-1),i=en.get(r),s=e.start(-1),o=i.findCell(e.pos-s),a=i.findCell(n.pos-s),l=e.node(0);return o.top<=a.top?(o.top>0&&(e=l.resolve(s+i.map[o.left])),a.bottom<i.height&&(n=l.resolve(s+i.map[i.width*(i.height-1)+a.right-1]))):(a.top>0&&(n=l.resolve(s+i.map[a.left])),o.bottom<i.height&&(e=l.resolve(s+i.map[i.width*(i.height-1)+o.right-1]))),new mo(e,n)}isRowSelection(){const e=this.$anchorCell.node(-1),n=en.get(e),r=this.$anchorCell.start(-1),i=n.colCount(this.$anchorCell.pos-r),s=n.colCount(this.$headCell.pos-r);if(Math.min(i,s)>0)return!1;const o=i+this.$anchorCell.nodeAfter.attrs.colspan,a=s+this.$headCell.nodeAfter.attrs.colspan;return Math.max(o,a)==n.width}eq(e){return e instanceof mo&&e.$anchorCell.pos==this.$anchorCell.pos&&e.$headCell.pos==this.$headCell.pos}static rowSelection(e,n=e){const r=e.node(-1),i=en.get(r),s=e.start(-1),o=i.findCell(e.pos-s),a=i.findCell(n.pos-s),l=e.node(0);return o.left<=a.left?(o.left>0&&(e=l.resolve(s+i.map[o.top*i.width])),a.right<i.width&&(n=l.resolve(s+i.map[i.width*(a.top+1)-1]))):(a.left>0&&(n=l.resolve(s+i.map[a.top*i.width])),o.right<i.width&&(e=l.resolve(s+i.map[i.width*(o.top+1)-1]))),new mo(e,n)}toJSON(){return{type:"cell",anchor:this.$anchorCell.pos,head:this.$headCell.pos}}static fromJSON(e,n){return new mo(e.resolve(n.anchor),e.resolve(n.head))}static create(e,n,r=n){return new mo(e.resolve(n),e.resolve(r))}getBookmark(){return new e$e(this.$anchorCell.pos,this.$headCell.pos)}};At.prototype.visible=!1;Pe.jsonID("cell",At);var e$e=class cY{constructor(e,n){this.anchor=e,this.head=n}map(e){return new cY(e.map(this.anchor),e.map(this.head))}resolve(e){const n=e.resolve(this.anchor),r=e.resolve(this.head);return n.parent.type.spec.tableRole=="row"&&r.parent.type.spec.tableRole=="row"&&n.index()<n.parent.childCount&&r.index()<r.parent.childCount&&EN(n,r)?new At(n,r):Pe.near(r,1)}};function t$e(t){if(!(t.selection instanceof At))return null;const e=[];return t.selection.forEachCell((n,r)=>{e.push(Cn.node(r,r+n.nodeSize,{class:"selectedCell"}))}),bt.create(t.doc,e)}function n$e({$from:t,$to:e}){if(t.pos==e.pos||t.pos<e.pos-6)return!1;let n=t.pos,r=e.pos,i=t.depth;for(;i>=0&&!(t.after(i+1)<t.end(i));i--,n++);for(let s=e.depth;s>=0&&!(e.before(s+1)>e.start(s));s--,r--);return n==r&&/row|table/.test(t.node(i).type.spec.tableRole)}function r$e({$from:t,$to:e}){let n,r;for(let i=t.depth;i>0;i--){const s=t.node(i);if(s.type.spec.tableRole==="cell"||s.type.spec.tableRole==="header_cell"){n=s;break}}for(let i=e.depth;i>0;i--){const s=e.node(i);if(s.type.spec.tableRole==="cell"||s.type.spec.tableRole==="header_cell"){r=s;break}}return n!==r&&e.parentOffset===0}function i$e(t,e,n){const r=(e||t).selection,i=(e||t).doc;let s,o;if(r instanceof Me&&(o=r.node.type.spec.tableRole)){if(o=="cell"||o=="header_cell")s=At.create(i,r.from);else if(o=="row"){const a=i.resolve(r.from+1);s=At.rowSelection(a,a)}else if(!n){const a=en.get(r.node),l=r.from+1,c=l+a.map[a.width*a.height-1];s=At.create(i,l+1,c)}}else r instanceof Le&&n$e(r)?s=Le.create(i,r.from):r instanceof Le&&r$e(r)&&(s=Le.create(i,r.$from.start(),r.$from.end()));return s&&(e||(e=t.tr)).setSelection(s),e}const s$e=new Ct("fix-tables");function uY(t,e,n,r){const i=t.childCount,s=e.childCount;e:for(let o=0,a=0;o<s;o++){const l=e.child(o);for(let c=a,u=Math.min(i,o+3);c<u;c++)if(t.child(c)==l){a=c+1,n+=l.nodeSize;continue e}r(l,n),a<i&&t.child(a).sameMarkup(l)?uY(t.child(a),l,n+1,r):l.nodesBetween(0,l.content.size,r,n+1),n+=l.nodeSize}}function hY(t,e){let n;const r=(i,s)=>{i.type.spec.tableRole=="table"&&(n=o$e(t,i,s,n))};return e?e.doc!=t.doc&&uY(e.doc,t.doc,0,r):t.doc.descendants(r),n}function o$e(t,e,n,r){const i=en.get(e);if(!i.problems)return r;r||(r=t.tr);const s=[];for(let l=0;l<i.height;l++)s.push(0);for(let l=0;l<i.problems.length;l++){const c=i.problems[l];if(c.type=="collision"){const u=e.nodeAt(c.pos);if(!u)continue;const h=u.attrs;for(let f=0;f<h.rowspan;f++)s[c.row+f]+=c.n;r.setNodeMarkup(r.mapping.map(n+1+c.pos),null,Oc(h,h.colspan-c.n,c.n))}else if(c.type=="missing")s[c.row]+=c.n;else if(c.type=="overlong_rowspan"){const u=e.nodeAt(c.pos);if(!u)continue;r.setNodeMarkup(r.mapping.map(n+1+c.pos),null,{...u.attrs,rowspan:u.attrs.rowspan-c.n})}else if(c.type=="colwidth mismatch"){const u=e.nodeAt(c.pos);if(!u)continue;r.setNodeMarkup(r.mapping.map(n+1+c.pos),null,{...u.attrs,colwidth:c.colwidth})}else if(c.type=="zero_sized"){const u=r.mapping.map(n);r.delete(u,u+e.nodeSize)}}let o,a;for(let l=0;l<s.length;l++)s[l]&&(o==null&&(o=l),a=l);for(let l=0,c=n+1;l<i.height;l++){const u=e.child(l),h=c+u.nodeSize,f=s[l];if(f>0){let d="cell";u.firstChild&&(d=u.firstChild.type.spec.tableRole);const p=[];for(let y=0;y<f;y++){const x=lr(t.schema)[d].createAndFill();x&&p.push(x)}const m=(l==0||o==l-1)&&a==l?c+1:h-1;r.insert(r.mapping.map(m),p)}c=h}return r.setMeta(s$e,{fixTables:!0})}function Js(t){const e=t.selection,n=lk(t),r=n.node(-1),i=n.start(-1),s=en.get(r);return{...e instanceof At?s.rectBetween(e.$anchorCell.pos-i,e.$headCell.pos-i):s.findCell(n.pos-i),tableStart:i,map:s,table:r}}function dY(t,{map:e,tableStart:n,table:r},i){let s=i>0?-1:0;JFe(e,r,i+s)&&(s=i==0||i==e.width?null:0);for(let o=0;o<e.height;o++){const a=o*e.width+i;if(i>0&&i<e.width&&e.map[a-1]==e.map[a]){const l=e.map[a],c=r.nodeAt(l);t.setNodeMarkup(t.mapping.map(n+l),null,lY(c.attrs,i-e.colCount(l))),o+=c.attrs.rowspan-1}else{const l=s==null?lr(r.type.schema).cell:r.nodeAt(e.map[a+s]).type,c=e.positionAt(o,i,r);t.insert(t.mapping.map(n+c),l.createAndFill())}}return t}function a$e(t,e){if(!ms(t))return!1;if(e){const n=Js(t);e(dY(t.tr,n,n.left))}return!0}function l$e(t,e){if(!ms(t))return!1;if(e){const n=Js(t);e(dY(t.tr,n,n.right))}return!0}function c$e(t,{map:e,table:n,tableStart:r},i){const s=t.mapping.maps.length;for(let o=0;o<e.height;){const a=o*e.width+i,l=e.map[a],c=n.nodeAt(l),u=c.attrs;if(i>0&&e.map[a-1]==l||i<e.width-1&&e.map[a+1]==l)t.setNodeMarkup(t.mapping.slice(s).map(r+l),null,Oc(u,i-e.colCount(l)));else{const h=t.mapping.slice(s).map(r+l);t.delete(h,h+c.nodeSize)}o+=u.rowspan}}function u$e(t,e){if(!ms(t))return!1;if(e){const n=Js(t),r=t.tr;if(n.left==0&&n.right==n.map.width)return!1;for(let i=n.right-1;c$e(r,n,i),i!=n.left;i--){const s=n.tableStart?r.doc.nodeAt(n.tableStart-1):r.doc;if(!s)throw new RangeError("No table found");n.table=s,n.map=en.get(s)}e(r)}return!0}function h$e(t,e,n){var r;const i=lr(e.type.schema).header_cell;for(let s=0;s<t.width;s++)if(((r=e.nodeAt(t.map[s+n*t.width]))===null||r===void 0?void 0:r.type)!=i)return!1;return!0}function fY(t,{map:e,tableStart:n,table:r},i){let s=n;for(let c=0;c<i;c++)s+=r.child(c).nodeSize;const o=[];let a=i>0?-1:0;h$e(e,r,i+a)&&(a=i==0||i==e.height?null:0);for(let c=0,u=e.width*i;c<e.width;c++,u++)if(i>0&&i<e.height&&e.map[u]==e.map[u-e.width]){const h=e.map[u],f=r.nodeAt(h).attrs;t.setNodeMarkup(n+h,null,{...f,rowspan:f.rowspan+1}),c+=f.colspan-1}else{var l;const h=a==null?lr(r.type.schema).cell:(l=r.nodeAt(e.map[u+a*e.width]))===null||l===void 0?void 0:l.type,f=h==null?void 0:h.createAndFill();f&&o.push(f)}return t.insert(s,lr(r.type.schema).row.create(null,o)),t}function d$e(t,e){if(!ms(t))return!1;if(e){const n=Js(t);e(fY(t.tr,n,n.top))}return!0}function f$e(t,e){if(!ms(t))return!1;if(e){const n=Js(t);e(fY(t.tr,n,n.bottom))}return!0}function p$e(t,{map:e,table:n,tableStart:r},i){let s=0;for(let c=0;c<i;c++)s+=n.child(c).nodeSize;const o=s+n.child(i).nodeSize,a=t.mapping.maps.length;t.delete(s+r,o+r);const l=new Set;for(let c=0,u=i*e.width;c<e.width;c++,u++){const h=e.map[u];if(!l.has(h)){if(l.add(h),i>0&&h==e.map[u-e.width]){const f=n.nodeAt(h).attrs;t.setNodeMarkup(t.mapping.slice(a).map(h+r),null,{...f,rowspan:f.rowspan-1}),c+=f.colspan-1}else if(i<e.height&&h==e.map[u+e.width]){const f=n.nodeAt(h),d=f.attrs,p=f.type.create({...d,rowspan:f.attrs.rowspan-1},f.content),m=e.positionAt(i+1,c,n);t.insert(t.mapping.slice(a).map(r+m),p),c+=d.colspan-1}}}}function g$e(t,e){if(!ms(t))return!1;if(e){const n=Js(t),r=t.tr;if(n.top==0&&n.bottom==n.map.height)return!1;for(let i=n.bottom-1;p$e(r,n,i),i!=n.top;i--){const s=n.tableStart?r.doc.nodeAt(n.tableStart-1):r.doc;if(!s)throw new RangeError("No table found");n.table=s,n.map=en.get(n.table)}e(r)}return!0}function x4(t){const e=t.content;return e.childCount==1&&e.child(0).isTextblock&&e.child(0).childCount==0}function m$e({width:t,height:e,map:n},r){let i=r.top*t+r.left,s=i,o=(r.bottom-1)*t+r.left,a=i+(r.right-r.left-1);for(let l=r.top;l<r.bottom;l++){if(r.left>0&&n[s]==n[s-1]||r.right<t&&n[a]==n[a+1])return!0;s+=t,a+=t}for(let l=r.left;l<r.right;l++){if(r.top>0&&n[i]==n[i-t]||r.bottom<e&&n[o]==n[o+t])return!0;i++,o++}return!1}function b4(t,e){const n=t.selection;if(!(n instanceof At)||n.$anchorCell.pos==n.$headCell.pos)return!1;const r=Js(t),{map:i}=r;if(m$e(i,r))return!1;if(e){const s=t.tr,o={};let a=Q.empty,l,c;for(let u=r.top;u<r.bottom;u++)for(let h=r.left;h<r.right;h++){const f=i.map[u*i.width+h],d=r.table.nodeAt(f);if(!(o[f]||!d))if(o[f]=!0,l==null)l=f,c=d;else{x4(d)||(a=a.append(d.content));const p=s.mapping.map(f+r.tableStart);s.delete(p,p+d.nodeSize)}}if(l==null||c==null)return!0;if(s.setNodeMarkup(l+r.tableStart,null,{...lY(c.attrs,c.attrs.colspan,r.right-r.left-c.attrs.colspan),rowspan:r.bottom-r.top}),a.size>0){const u=l+1+c.content.size,h=x4(c)?l+1:u;s.replaceWith(h+r.tableStart,u+r.tableStart,a)}s.setSelection(new At(s.doc.resolve(l+r.tableStart))),e(s)}return!0}function k4(t,e){const n=lr(t.schema);return y$e(({node:r})=>n[r.type.spec.tableRole])(t,e)}function y$e(t){return(e,n)=>{const r=e.selection;let i,s;if(r instanceof At){if(r.$anchorCell.pos!=r.$headCell.pos)return!1;i=r.$anchorCell.nodeAfter,s=r.$anchorCell.pos}else{var o;if(i=XFe(r.$from),!i)return!1;s=(o=Dc(r.$from))===null||o===void 0?void 0:o.pos}if(i==null||s==null||i.attrs.colspan==1&&i.attrs.rowspan==1)return!1;if(n){let a=i.attrs;const l=[],c=a.colwidth;a.rowspan>1&&(a={...a,rowspan:1}),a.colspan>1&&(a={...a,colspan:1});const u=Js(e),h=e.tr;for(let d=0;d<u.right-u.left;d++)l.push(c?{...a,colwidth:c&&c[d]?[c[d]]:null}:a);let f;for(let d=u.top;d<u.bottom;d++){let p=u.map.positionAt(d,u.left,u.table);d==u.top&&(p+=i.nodeSize);for(let m=u.left,y=0;m<u.right;m++,y++)m==u.left&&d==u.top||h.insert(f=h.mapping.map(p+u.tableStart,1),t({node:i,row:d,col:m}).createAndFill(l[y]))}h.setNodeMarkup(s,t({node:i,row:u.top,col:u.left}),l[0]),r instanceof At&&h.setSelection(new At(h.doc.resolve(r.$anchorCell.pos),f?h.doc.resolve(f):void 0)),n(h)}return!0}}function x$e(t,e){return function(n,r){if(!ms(n))return!1;const i=lk(n);if(i.nodeAfter.attrs[t]===e)return!1;if(r){const s=n.tr;n.selection instanceof At?n.selection.forEachCell((o,a)=>{o.attrs[t]!==e&&s.setNodeMarkup(a,null,{...o.attrs,[t]:e})}):s.setNodeMarkup(i.pos,null,{...i.nodeAfter.attrs,[t]:e}),r(s)}return!0}}function b$e(t){return function(e,n){if(!ms(e))return!1;if(n){const r=lr(e.schema),i=Js(e),s=e.tr,o=i.map.cellsInRect(t=="column"?{left:i.left,top:0,right:i.right,bottom:i.map.height}:t=="row"?{left:0,top:i.top,right:i.map.width,bottom:i.bottom}:i),a=o.map(l=>i.table.nodeAt(l));for(let l=0;l<o.length;l++)a[l].type==r.header_cell&&s.setNodeMarkup(i.tableStart+o[l],r.cell,a[l].attrs);if(s.steps.length===0)for(let l=0;l<o.length;l++)s.setNodeMarkup(i.tableStart+o[l],r.header_cell,a[l].attrs);n(s)}return!0}}function w4(t,e,n){const r=e.map.cellsInRect({left:0,top:0,right:t=="row"?e.map.width:1,bottom:t=="column"?e.map.height:1});for(let i=0;i<r.length;i++){const s=e.table.nodeAt(r[i]);if(s&&s.type!==n.header_cell)return!1}return!0}function ig(t,e){return e=e||{useDeprecatedLogic:!1},e.useDeprecatedLogic?b$e(t):function(n,r){if(!ms(n))return!1;if(r){const i=lr(n.schema),s=Js(n),o=n.tr,a=w4("row",s,i),l=w4("column",s,i),c=(t==="column"?a:t==="row"&&l)?1:0,u=t=="column"?{left:0,top:c,right:1,bottom:s.map.height}:t=="row"?{left:c,top:0,right:s.map.width,bottom:1}:s,h=t=="column"?l?i.cell:i.header_cell:t=="row"?a?i.cell:i.header_cell:i.cell;s.map.cellsInRect(u).forEach(f=>{const d=f+s.tableStart,p=o.doc.nodeAt(d);p&&o.setNodeMarkup(d,h,p.attrs)}),r(o)}return!0}}ig("row",{useDeprecatedLogic:!0});ig("column",{useDeprecatedLogic:!0});const k$e=ig("cell",{useDeprecatedLogic:!0});function w$e(t,e){if(e<0){const n=t.nodeBefore;if(n)return t.pos-n.nodeSize;for(let r=t.index(-1)-1,i=t.before();r>=0;r--){const s=t.node(-1).child(r),o=s.lastChild;if(o)return i-1-o.nodeSize;i-=s.nodeSize}}else{if(t.index()<t.parent.childCount-1)return t.pos+t.nodeAfter.nodeSize;const n=t.node(-1);for(let r=t.indexAfter(-1),i=t.after();r<n.childCount;r++){const s=n.child(r);if(s.childCount)return i+1;i+=s.nodeSize}}return null}function v4(t){return function(e,n){if(!ms(e))return!1;const r=w$e(lk(e),t);if(r==null)return!1;if(n){const i=e.doc.resolve(r);n(e.tr.setSelection(Le.between(i,QFe(i))).scrollIntoView())}return!0}}function v$e(t,e){const n=t.selection.$anchor;for(let r=n.depth;r>0;r--)if(n.node(r).type.spec.tableRole=="table")return e&&e(t.tr.delete(n.before(r),n.after(r)).scrollIntoView()),!0;return!1}function u0(t,e){const n=t.selection;if(!(n instanceof At))return!1;if(e){const r=t.tr,i=lr(t.schema).cell.createAndFill().content;n.forEachCell((s,o)=>{s.content.eq(i)||r.replace(r.mapping.map(o+1),r.mapping.map(o+s.nodeSize-1),new de(i,0,0))}),r.docChanged&&e(r)}return!0}function C$e(t){if(t.size===0)return null;let{content:e,openStart:n,openEnd:r}=t;for(;e.childCount==1&&(n>0&&r>0||e.child(0).type.spec.tableRole=="table");)n--,r--,e=e.child(0).content;const i=e.child(0),s=i.type.spec.tableRole,o=i.type.schema,a=[];if(s=="row")for(let l=0;l<e.childCount;l++){let c=e.child(l).content;const u=l?0:Math.max(0,n-1),h=l<e.childCount-1?0:Math.max(0,r-1);(u||h)&&(c=y_(lr(o).row,new de(c,u,h)).content),a.push(c)}else if(s=="cell"||s=="header_cell")a.push(n||r?y_(lr(o).row,new de(e,n,r)).content:e);else return null;return S$e(o,a)}function S$e(t,e){const n=[];for(let i=0;i<e.length;i++){const s=e[i];for(let o=s.childCount-1;o>=0;o--){const{rowspan:a,colspan:l}=s.child(o).attrs;for(let c=i;c<i+a;c++)n[c]=(n[c]||0)+l}}let r=0;for(let i=0;i<n.length;i++)r=Math.max(r,n[i]);for(let i=0;i<n.length;i++)if(i>=e.length&&e.push(Q.empty),n[i]<r){const s=lr(t).cell.createAndFill(),o=[];for(let a=n[i];a<r;a++)o.push(s);e[i]=e[i].append(Q.from(o))}return{height:e.length,width:r,rows:e}}function y_(t,e){const n=t.createAndFill();return new $A(n).replace(0,n.content.size,e).doc}function _$e({width:t,height:e,rows:n},r,i){if(t!=r){const s=[],o=[];for(let a=0;a<n.length;a++){const l=n[a],c=[];for(let u=s[a]||0,h=0;u<r;h++){let f=l.child(h%l.childCount);u+f.attrs.colspan>r&&(f=f.type.createChecked(Oc(f.attrs,f.attrs.colspan,u+f.attrs.colspan-r),f.content)),c.push(f),u+=f.attrs.colspan;for(let d=1;d<f.attrs.rowspan;d++)s[a+d]=(s[a+d]||0)+f.attrs.colspan}o.push(Q.from(c))}n=o,t=r}if(e!=i){const s=[];for(let o=0,a=0;o<i;o++,a++){const l=[],c=n[a%e];for(let u=0;u<c.childCount;u++){let h=c.child(u);o+h.attrs.rowspan>i&&(h=h.type.create({...h.attrs,rowspan:Math.max(1,i-h.attrs.rowspan)},h.content)),l.push(h)}s.push(Q.from(l))}n=s,e=i}return{width:t,height:e,rows:n}}function T$e(t,e,n,r,i,s,o){const a=t.doc.type.schema,l=lr(a);let c,u;if(i>e.width)for(let h=0,f=0;h<e.height;h++){const d=n.child(h);f+=d.nodeSize;const p=[];let m;d.lastChild==null||d.lastChild.type==l.cell?m=c||(c=l.cell.createAndFill()):m=u||(u=l.header_cell.createAndFill());for(let y=e.width;y<i;y++)p.push(m);t.insert(t.mapping.slice(o).map(f-1+r),p)}if(s>e.height){const h=[];for(let p=0,m=(e.height-1)*e.width;p<Math.max(e.width,i);p++){const y=p>=e.width?!1:n.nodeAt(e.map[m+p]).type==l.header_cell;h.push(y?u||(u=l.header_cell.createAndFill()):c||(c=l.cell.createAndFill()))}const f=l.row.create(null,Q.from(h)),d=[];for(let p=e.height;p<s;p++)d.push(f);t.insert(t.mapping.slice(o).map(r+n.nodeSize-2),d)}return!!(c||u)}function C4(t,e,n,r,i,s,o,a){if(o==0||o==e.height)return!1;let l=!1;for(let c=i;c<s;c++){const u=o*e.width+c,h=e.map[u];if(e.map[u-e.width]==h){l=!0;const f=n.nodeAt(h),{top:d,left:p}=e.findCell(h);t.setNodeMarkup(t.mapping.slice(a).map(h+r),null,{...f.attrs,rowspan:o-d}),t.insert(t.mapping.slice(a).map(e.positionAt(o,p,n)),f.type.createAndFill({...f.attrs,rowspan:d+f.attrs.rowspan-o})),c+=f.attrs.colspan-1}}return l}function S4(t,e,n,r,i,s,o,a){if(o==0||o==e.width)return!1;let l=!1;for(let c=i;c<s;c++){const u=c*e.width+o,h=e.map[u];if(e.map[u-1]==h){l=!0;const f=n.nodeAt(h),d=e.colCount(h),p=t.mapping.slice(a).map(h+r);t.setNodeMarkup(p,null,Oc(f.attrs,o-d,f.attrs.colspan-(o-d))),t.insert(p+f.nodeSize,f.type.createAndFill(Oc(f.attrs,0,o-d))),c+=f.attrs.rowspan-1}}return l}function _4(t,e,n,r,i){let s=n?t.doc.nodeAt(n-1):t.doc;if(!s)throw new Error("No table found");let o=en.get(s);const{top:a,left:l}=r,c=l+i.width,u=a+i.height,h=t.tr;let f=0;function d(){if(s=n?h.doc.nodeAt(n-1):h.doc,!s)throw new Error("No table found");o=en.get(s),f=h.mapping.maps.length}T$e(h,o,s,n,c,u,f)&&d(),C4(h,o,s,n,l,c,a,f)&&d(),C4(h,o,s,n,l,c,u,f)&&d(),S4(h,o,s,n,a,u,l,f)&&d(),S4(h,o,s,n,a,u,c,f)&&d();for(let p=a;p<u;p++){const m=o.positionAt(p,l,s),y=o.positionAt(p,c,s);h.replace(h.mapping.slice(f).map(m+n),h.mapping.slice(f).map(y+n),new de(i.rows[p-a],0,0))}d(),h.setSelection(new At(h.doc.resolve(n+o.positionAt(a,l,s)),h.doc.resolve(n+o.positionAt(u-1,c-1,s)))),e(h)}const E$e=tN({ArrowLeft:h0("horiz",-1),ArrowRight:h0("horiz",1),ArrowUp:h0("vert",-1),ArrowDown:h0("vert",1),"Shift-ArrowLeft":d0("horiz",-1),"Shift-ArrowRight":d0("horiz",1),"Shift-ArrowUp":d0("vert",-1),"Shift-ArrowDown":d0("vert",1),Backspace:u0,"Mod-Backspace":u0,Delete:u0,"Mod-Delete":u0});function ay(t,e,n){return n.eq(t.selection)?!1:(e&&e(t.tr.setSelection(n).scrollIntoView()),!0)}function h0(t,e){return(n,r,i)=>{if(!i)return!1;const s=n.selection;if(s instanceof At)return ay(n,r,Pe.near(s.$headCell,e));if(t!="horiz"&&!s.empty)return!1;const o=pY(i,t,e);if(o==null)return!1;if(t=="horiz")return ay(n,r,Pe.near(n.doc.resolve(s.head+e),e));{const a=n.doc.resolve(o),l=aY(a,t,e);let c;return l?c=Pe.near(l,1):e<0?c=Pe.near(n.doc.resolve(a.before(-1)),-1):c=Pe.near(n.doc.resolve(a.after(-1)),1),ay(n,r,c)}}}function d0(t,e){return(n,r,i)=>{if(!i)return!1;const s=n.selection;let o;if(s instanceof At)o=s;else{const l=pY(i,t,e);if(l==null)return!1;o=new At(n.doc.resolve(l))}const a=aY(o.$headCell,t,e);return a?ay(n,r,new At(o.$anchorCell,a)):!1}}function A$e(t,e){const n=t.state.doc,r=Dc(n.resolve(e));return r?(t.dispatch(t.state.tr.setSelection(new At(r))),!0):!1}function N$e(t,e,n){if(!ms(t.state))return!1;let r=C$e(n);const i=t.state.selection;if(i instanceof At){r||(r={width:1,height:1,rows:[Q.from(y_(lr(t.state.schema).cell,n))]});const s=i.$anchorCell.node(-1),o=i.$anchorCell.start(-1),a=en.get(s).rectBetween(i.$anchorCell.pos-o,i.$headCell.pos-o);return r=_$e(r,a.right-a.left,a.bottom-a.top),_4(t.state,t.dispatch,o,a,r),!0}else if(r){const s=lk(t.state),o=s.start(-1);return _4(t.state,t.dispatch,o,en.get(s.node(-1)).findCell(s.pos-o),r),!0}else return!1}function M$e(t,e){var n;if(e.button!=0||e.ctrlKey||e.metaKey)return;const r=T4(t,e.target);let i;if(e.shiftKey&&t.state.selection instanceof At)s(t.state.selection.$anchorCell,e),e.preventDefault();else if(e.shiftKey&&r&&(i=Dc(t.state.selection.$anchor))!=null&&((n=Pv(t,e))===null||n===void 0?void 0:n.pos)!=i.pos)s(i,e),e.preventDefault();else if(!r)return;function s(l,c){let u=Pv(t,c);const h=pa.getState(t.state)==null;if(!u||!EN(l,u))if(h)u=l;else return;const f=new At(l,u);if(h||!t.state.selection.eq(f)){const d=t.state.tr.setSelection(f);h&&d.setMeta(pa,l.pos),t.dispatch(d)}}function o(){t.root.removeEventListener("mouseup",o),t.root.removeEventListener("dragstart",o),t.root.removeEventListener("mousemove",a),pa.getState(t.state)!=null&&t.dispatch(t.state.tr.setMeta(pa,-1))}function a(l){const c=l,u=pa.getState(t.state);let h;if(u!=null)h=t.state.doc.resolve(u);else if(T4(t,c.target)!=r&&(h=Pv(t,e),!h))return o();h&&s(h,c)}t.root.addEventListener("mouseup",o),t.root.addEventListener("dragstart",o),t.root.addEventListener("mousemove",a)}function pY(t,e,n){if(!(t.state.selection instanceof Le))return null;const{$head:r}=t.state.selection;for(let i=r.depth-1;i>=0;i--){const s=r.node(i);if((n<0?r.index(i):r.indexAfter(i))!=(n<0?0:s.childCount))return null;if(s.type.spec.tableRole=="cell"||s.type.spec.tableRole=="header_cell"){const o=r.before(i),a=e=="vert"?n>0?"down":"up":n>0?"right":"left";return t.endOfTextblock(a)?o:null}}return null}function T4(t,e){for(;e&&e!=t.dom;e=e.parentNode)if(e.nodeName=="TD"||e.nodeName=="TH")return e;return null}function Pv(t,e){const n=t.posAtCoords({left:e.clientX,top:e.clientY});if(!n)return null;let{inside:r,pos:i}=n;return r>=0&&Dc(t.state.doc.resolve(r))||Dc(t.state.doc.resolve(i))}var L$e=class{constructor(e,n){this.node=e,this.defaultCellMinWidth=n,this.dom=document.createElement("div"),this.dom.className="tableWrapper",this.table=this.dom.appendChild(document.createElement("table")),this.table.style.setProperty("--default-cell-min-width",`${n}px`),this.colgroup=this.table.appendChild(document.createElement("colgroup")),x_(e,this.colgroup,this.table,n),this.contentDOM=this.table.appendChild(document.createElement("tbody"))}update(e){return e.type!=this.node.type?!1:(this.node=e,x_(e,this.colgroup,this.table,this.defaultCellMinWidth),!0)}ignoreMutation(e){return e.type=="attributes"&&(e.target==this.table||this.colgroup.contains(e.target))}};function x_(t,e,n,r,i,s){let o=0,a=!0,l=e.firstChild;const c=t.firstChild;if(c){for(let h=0,f=0;h<c.childCount;h++){const{colspan:d,colwidth:p}=c.child(h).attrs;for(let m=0;m<d;m++,f++){const y=i==f?s:p&&p[m],x=y?y+"px":"";if(o+=y||r,y||(a=!1),l)l.style.width!=x&&(l.style.width=x),l=l.nextSibling;else{const b=document.createElement("col");b.style.width=x,e.appendChild(b)}}}for(;l;){var u;const h=l.nextSibling;(u=l.parentNode)===null||u===void 0||u.removeChild(l),l=h}a?(n.style.width=o+"px",n.style.minWidth=""):(n.style.width="",n.style.minWidth=o+"px")}}const ai=new Ct("tableColumnResizing");function D$e({handleWidth:t=5,cellMinWidth:e=25,defaultCellMinWidth:n=100,View:r=L$e,lastColumnResizable:i=!0}={}){const s=new vt({key:ai,state:{init(o,a){var l;const c=(l=s.spec)===null||l===void 0||(l=l.props)===null||l===void 0?void 0:l.nodeViews,u=lr(a.schema).table.name;return r&&c&&(c[u]=(h,f)=>new r(h,n,f)),new O$e(-1,!1)},apply(o,a){return a.apply(o)}},props:{attributes:o=>{const a=ai.getState(o);return a&&a.activeHandle>-1?{class:"resize-cursor"}:{}},handleDOMEvents:{mousemove:(o,a)=>{R$e(o,a,t,i)},mouseleave:o=>{I$e(o)},mousedown:(o,a)=>{B$e(o,a,e,n)}},decorations:o=>{const a=ai.getState(o);if(a&&a.activeHandle>-1)return z$e(o,a.activeHandle)},nodeViews:{}}});return s}var O$e=class ly{constructor(e,n){this.activeHandle=e,this.dragging=n}apply(e){const n=this,r=e.getMeta(ai);if(r&&r.setHandle!=null)return new ly(r.setHandle,!1);if(r&&r.setDragging!==void 0)return new ly(n.activeHandle,r.setDragging);if(n.activeHandle>-1&&e.docChanged){let i=e.mapping.map(n.activeHandle,-1);return m_(e.doc.resolve(i))||(i=-1),new ly(i,n.dragging)}return n}};function R$e(t,e,n,r){if(!t.editable)return;const i=ai.getState(t.state);if(i&&!i.dragging){const s=F$e(e.target);let o=-1;if(s){const{left:a,right:l}=s.getBoundingClientRect();e.clientX-a<=n?o=E4(t,e,"left",n):l-e.clientX<=n&&(o=E4(t,e,"right",n))}if(o!=i.activeHandle){if(!r&&o!==-1){const a=t.state.doc.resolve(o),l=a.node(-1),c=en.get(l),u=a.start(-1);if(c.colCount(a.pos-u)+a.nodeAfter.attrs.colspan-1==c.width-1)return}gY(t,o)}}}function I$e(t){if(!t.editable)return;const e=ai.getState(t.state);e&&e.activeHandle>-1&&!e.dragging&&gY(t,-1)}function B$e(t,e,n,r){var i;if(!t.editable)return!1;const s=(i=t.dom.ownerDocument.defaultView)!==null&&i!==void 0?i:window,o=ai.getState(t.state);if(!o||o.activeHandle==-1||o.dragging)return!1;const a=t.state.doc.nodeAt(o.activeHandle),l=P$e(t,o.activeHandle,a.attrs);t.dispatch(t.state.tr.setMeta(ai,{setDragging:{startX:e.clientX,startWidth:l}}));function c(h){s.removeEventListener("mouseup",c),s.removeEventListener("mousemove",u);const f=ai.getState(t.state);f!=null&&f.dragging&&($$e(t,f.activeHandle,A4(f.dragging,h,n)),t.dispatch(t.state.tr.setMeta(ai,{setDragging:null})))}function u(h){if(!h.which)return c(h);const f=ai.getState(t.state);if(f&&f.dragging){const d=A4(f.dragging,h,n);N4(t,f.activeHandle,d,r)}}return N4(t,o.activeHandle,l,r),s.addEventListener("mouseup",c),s.addEventListener("mousemove",u),e.preventDefault(),!0}function P$e(t,e,{colspan:n,colwidth:r}){const i=r&&r[r.length-1];if(i)return i;const s=t.domAtPos(e);let o=s.node.childNodes[s.offset].offsetWidth,a=n;if(r)for(let l=0;l<n;l++)r[l]&&(o-=r[l],a--);return o/a}function F$e(t){for(;t&&t.nodeName!="TD"&&t.nodeName!="TH";)t=t.classList&&t.classList.contains("ProseMirror")?null:t.parentNode;return t}function E4(t,e,n,r){const i=n=="right"?-r:r,s=t.posAtCoords({left:e.clientX+i,top:e.clientY});if(!s)return-1;const{pos:o}=s,a=Dc(t.state.doc.resolve(o));if(!a)return-1;if(n=="right")return a.pos;const l=en.get(a.node(-1)),c=a.start(-1),u=l.map.indexOf(a.pos-c);return u%l.width==0?-1:c+l.map[u-1]}function A4(t,e,n){const r=e.clientX-t.startX;return Math.max(n,t.startWidth+r)}function gY(t,e){t.dispatch(t.state.tr.setMeta(ai,{setHandle:e}))}function $$e(t,e,n){const r=t.state.doc.resolve(e),i=r.node(-1),s=en.get(i),o=r.start(-1),a=s.colCount(r.pos-o)+r.nodeAfter.attrs.colspan-1,l=t.state.tr;for(let c=0;c<s.height;c++){const u=c*s.width+a;if(c&&s.map[u]==s.map[u-s.width])continue;const h=s.map[u],f=i.nodeAt(h).attrs,d=f.colspan==1?0:a-s.colCount(h);if(f.colwidth&&f.colwidth[d]==n)continue;const p=f.colwidth?f.colwidth.slice():j$e(f.colspan);p[d]=n,l.setNodeMarkup(o+h,null,{...f,colwidth:p})}l.docChanged&&t.dispatch(l)}function N4(t,e,n,r){const i=t.state.doc.resolve(e),s=i.node(-1),o=i.start(-1),a=en.get(s).colCount(i.pos-o)+i.nodeAfter.attrs.colspan-1;let l=t.domAtPos(i.start(-1)).node;for(;l&&l.nodeName!="TABLE";)l=l.parentNode;l&&x_(s,l.firstChild,l,r,a,n)}function j$e(t){return Array(t).fill(0)}function z$e(t,e){const n=[],r=t.doc.resolve(e),i=r.node(-1);if(!i)return bt.empty;const s=en.get(i),o=r.start(-1),a=s.colCount(r.pos-o)+r.nodeAfter.attrs.colspan-1;for(let c=0;c<s.height;c++){const u=a+c*s.width;if((a==s.width-1||s.map[u]!=s.map[u+1])&&(c==0||s.map[u]!=s.map[u-s.width])){var l;const h=s.map[u],f=o+h+i.nodeAt(h).nodeSize-1,d=document.createElement("div");d.className="column-resize-handle",!((l=ai.getState(t))===null||l===void 0)&&l.dragging&&n.push(Cn.node(o+h,o+h+i.nodeAt(h).nodeSize,{class:"column-resize-dragging"})),n.push(Cn.widget(f,d))}}return bt.create(t.doc,n)}function H$e({allowTableNodeSelection:t=!1}={}){return new vt({key:pa,state:{init(){return null},apply(e,n){const r=e.getMeta(pa);if(r!=null)return r==-1?null:r;if(n==null||!e.docChanged)return n;const{deleted:i,pos:s}=e.mapping.mapResult(n);return i?null:s}},props:{decorations:t$e,handleDOMEvents:{mousedown:M$e},createSelectionBetween(e){return pa.getState(e.state)!=null?e.state.selection:null},handleTripleClick:A$e,handleKeyDown:E$e,handlePaste:N$e},appendTransaction(e,n,r){return i$e(r,hY(r,n),t)}})}function Db(t){return t==="left"||t==="right"||t==="center"?t:null}function U$e(t){const e=(t.style.textAlign||"").trim().toLowerCase(),n=(t.getAttribute("align")||"").trim().toLowerCase();return Db(e||n)}function W$e(t){return Db(t==null?void 0:t.align)}function mY(){return{default:null,parseHTML:t=>U$e(t),renderHTML:t=>t.align?{style:`text-align: ${t.align}`}:{}}}var yY=ot.create({name:"tableCell",addOptions(){return{HTMLAttributes:{}}},content:"block+",addAttributes(){return{colspan:{default:1},rowspan:{default:1},colwidth:{default:null,parseHTML:t=>{var e,n;const r=t.getAttribute("colwidth"),i=r?r.split(",").map(s=>parseInt(s,10)):null;if(!i){const s=(e=t.closest("table"))==null?void 0:e.querySelectorAll("colgroup > col"),o=Array.from(((n=t.parentElement)==null?void 0:n.children)||[]).indexOf(t);if(o&&o>-1&&s&&s[o]){const a=s[o].getAttribute("width");return a?[parseInt(a,10)]:null}}return i}},align:mY()}},tableRole:"cell",isolating:!0,parseHTML(){return[{tag:"td"}]},renderHTML({HTMLAttributes:t}){return["td",xt(this.options.HTMLAttributes,t),0]}}),xY=ot.create({name:"tableHeader",addOptions(){return{HTMLAttributes:{}}},content:"block+",addAttributes(){return{colspan:{default:1},rowspan:{default:1},colwidth:{default:null,parseHTML:t=>{const e=t.getAttribute("colwidth");return e?e.split(",").map(r=>parseInt(r,10)):null}},align:mY()}},tableRole:"header_cell",isolating:!0,parseHTML(){return[{tag:"th"}]},renderHTML({HTMLAttributes:t}){return["th",xt(this.options.HTMLAttributes,t),0]}}),bY=ot.create({name:"tableRow",addOptions(){return{HTMLAttributes:{}}},content:"(tableCell | tableHeader)*",tableRole:"row",parseHTML(){return[{tag:"tr"}]},renderHTML({HTMLAttributes:t}){return["tr",xt(this.options.HTMLAttributes,t),0]}});function b_(t,e){return e?["width",`${Math.max(e,t)}px`]:["min-width",`${t}px`]}function M4(t,e,n,r,i,s){var o;let a=0,l=!0,c=e.firstChild;const u=t.firstChild;if(u!==null)for(let f=0,d=0;f<u.childCount;f+=1){const{colspan:p,colwidth:m}=u.child(f).attrs;for(let y=0;y<p;y+=1,d+=1){const x=i===d?s:m&&m[y],b=x?`${x}px`:"";if(a+=x||r,x||(l=!1),c){if(c.style.width!==b){const[k,w]=b_(r,x);c.style.setProperty(k,w)}c=c.nextSibling}else{const k=document.createElement("col"),[w,v]=b_(r,x);k.style.setProperty(w,v),e.appendChild(k)}}}for(;c;){const f=c.nextSibling;(o=c.parentNode)==null||o.removeChild(c),c=f}const h=t.attrs.style&&typeof t.attrs.style=="string"&&/\bwidth\s*:/i.test(t.attrs.style);l&&!h?(n.style.width=`${a}px`,n.style.minWidth=""):(n.style.width="",n.style.minWidth=`${a}px`)}var q$e=class{constructor(t,e){this.node=t,this.cellMinWidth=e,this.dom=document.createElement("div"),this.dom.className="tableWrapper",this.table=this.dom.appendChild(document.createElement("table")),t.attrs.style&&(this.table.style.cssText=t.attrs.style),this.colgroup=this.table.appendChild(document.createElement("colgroup")),M4(t,this.colgroup,this.table,e),this.contentDOM=this.table.appendChild(document.createElement("tbody"))}update(t){return t.type!==this.node.type?!1:(this.node=t,M4(t,this.colgroup,this.table,this.cellMinWidth),!0)}ignoreMutation(t){const e=t.target,n=this.dom.contains(e),r=this.contentDOM.contains(e);return!!(n&&!r&&(t.type==="attributes"||t.type==="childList"||t.type==="characterData"))}};function V$e(t,e,n,r){let i=0,s=!0;const o=[],a=t.firstChild;if(!a)return{};for(let h=0,f=0;h<a.childCount;h+=1){const{colspan:d,colwidth:p}=a.child(h).attrs;for(let m=0;m<d;m+=1,f+=1){const y=n===f?r:p&&p[m];i+=y||e,y||(s=!1);const[x,b]=b_(e,y);o.push(["col",{style:`${x}: ${b}`}])}}const l=s?`${i}px`:"",c=s?"":`${i}px`;return{colgroup:["colgroup",{},...o],tableWidth:l,tableMinWidth:c}}function L4(t,e){return t.createAndFill()}function G$e(t){if(t.cached.tableNodeTypes)return t.cached.tableNodeTypes;const e={};return Object.keys(t.nodes).forEach(n=>{const r=t.nodes[n];r.spec.tableRole&&(e[r.spec.tableRole]=r)}),t.cached.tableNodeTypes=e,e}function Y$e(t,e,n,r,i){const s=G$e(t),o=[],a=[];for(let c=0;c<n;c+=1){const u=L4(s.cell);if(u&&a.push(u),r){const h=L4(s.header_cell);h&&o.push(h)}}const l=[];for(let c=0;c<e;c+=1)l.push(s.row.createChecked(null,r&&c===0?o:a));return s.table.createChecked(null,l)}function K$e(t){return t instanceof At}var f0=({editor:t})=>{const{selection:e}=t.state;if(!K$e(e))return!1;let n=0;const r=qV(e.ranges[0].$from,s=>s.type.name==="table");return r==null||r.node.descendants(s=>{if(s.type.name==="table")return!1;["tableCell","tableHeader"].includes(s.type.name)&&(n+=1)}),n===e.ranges.length?(t.commands.deleteTable(),!0):!1},X$e="";function Z$e(t){return(t||"").replace(/\s+/g," ").trim()}function Q$e(t,e,n={}){var r;const i=(r=n.cellLineSeparator)!=null?r:X$e;if(!t||!t.content||t.content.length===0)return"";const s=[];t.content.forEach(m=>{const y=[];m.content&&m.content.forEach(x=>{let b="";x.content&&Array.isArray(x.content)&&x.content.length>1?b=x.content.map(S=>e.renderChildren(S)).join(i):b=x.content?e.renderChildren(x.content):"";const k=Z$e(b),w=x.type==="tableHeader",v=W$e(x.attrs);y.push({text:k,isHeader:w,align:v})}),s.push(y)});const o=s.reduce((m,y)=>Math.max(m,y.length),0);if(o===0)return"";const a=new Array(o).fill(0);s.forEach(m=>{var y;for(let x=0;x<o;x+=1){const k=(((y=m[x])==null?void 0:y.text)||"").length;k>a[x]&&(a[x]=k),a[x]<3&&(a[x]=3)}});const l=(m,y)=>m+" ".repeat(Math.max(0,y-m.length)),c=s[0],u=c.some(m=>m.isHeader),h=new Array(o).fill(null);s.forEach(m=>{var y;for(let x=0;x<o;x+=1)!h[x]&&((y=m[x])!=null&&y.align)&&(h[x]=m[x].align)});let f=`
|
|
1116
1116
|
`;const d=new Array(o).fill(0).map((m,y)=>u&&c[y]&&c[y].text||"");return f+=`| ${d.map((m,y)=>l(m,a[y])).join(" | ")} |
|
|
1117
1117
|
`,f+=`| ${a.map((m,y)=>{const x=Math.max(3,m),b=h[y];return b==="left"?`:${"-".repeat(x)}`:b==="right"?`${"-".repeat(x)}:`:b==="center"?`:${"-".repeat(x)}:`:"-".repeat(x)}).join(" | ")} |
|
|
1118
1118
|
`,(u?s.slice(1):s).forEach(m=>{f+=`| ${new Array(o).fill(0).map((y,x)=>l(m[x]&&m[x].text||"",a[x])).join(" | ")} |
|
|
@@ -1147,4 +1147,4 @@ ${n.innerHTML}
|
|
|
1147
1147
|
`),t.text(e.textContent,!1),t.ensureNewLine(),t.write("```"),t.closeBlock(e)},parse:{setup(t){var e;t.set({langPrefix:(e=this.options.languageClassPrefix)!==null&&e!==void 0?e:"language-"})},updateDOM(t){t.innerHTML=t.innerHTML.replace(/\n<\/code><\/pre>/g,"</code></pre>")}}}}}}),C9e=ot.create({name:"hardBreak"}),JY=C9e.extend({addStorage(){return{markdown:{serialize(t,e,n,r){for(let i=r+1;i<n.childCount;i++)if(n.child(i).type!=e.type){t.write(t.inTable?fk.storage.markdown.serialize.call(this,t,e,n):`\\
|
|
1148
1148
|
`);return}},parse:{}}}}}),S9e=ot.create({name:"heading"}),_9e=S9e.extend({addStorage(){return{markdown:{serialize:no.nodes.heading,parse:{}}}}}),T9e=ot.create({name:"horizontalRule"}),E9e=T9e.extend({addStorage(){return{markdown:{serialize:no.nodes.horizontal_rule,parse:{}}}}}),A9e=ot.create({name:"image"}),N9e=A9e.extend({addStorage(){return{markdown:{serialize:no.nodes.image,parse:{}}}}}),M9e=ot.create({name:"listItem"}),L9e=M9e.extend({addStorage(){return{markdown:{serialize:no.nodes.list_item,parse:{}}}}}),D9e=ot.create({name:"orderedList"});function O9e(t,e,n){let r=0;for(;n-r>0&&e.child(n-r-1).type.name===t.type.name;r++);return r}const R9e=D9e.extend({addStorage(){return{markdown:{serialize(t,e,n,r){const i=e.attrs.start||1,s=String(i+e.childCount-1).length,o=t.repeat(" ",s+2),l=O9e(e,n,r)%2?") ":". ";t.renderList(e,o,c=>{const u=String(i+c);return t.repeat(" ",s-u.length)+u+l})},parse:{}}}}}),I9e=ot.create({name:"paragraph"}),B9e=I9e.extend({addStorage(){return{markdown:{serialize:no.nodes.paragraph,parse:{}}}}});function Gv(t){var e,n;return(e=t==null||(n=t.content)===null||n===void 0?void 0:n.content)!==null&&e!==void 0?e:[]}const P9e=ot.create({name:"table"}),F9e=P9e.extend({addStorage(){return{markdown:{serialize(t,e,n){if(!$9e(e)){fk.storage.markdown.serialize.call(this,t,e,n);return}t.inTable=!0,e.forEach((r,i,s)=>{if(t.write("| "),r.forEach((o,a,l)=>{l&&t.write(" | ");const c=o.firstChild;c.textContent.trim()&&t.renderInline(c)}),t.write(" |"),t.ensureNewLine(),!s){const o=Array.from({length:r.childCount}).map(()=>"---").join(" | ");t.write(`| ${o} |`),t.ensureNewLine()}}),t.closeBlock(e),t.inTable=!1},parse:{}}}}});function nB(t){return t.attrs.colspan>1||t.attrs.rowspan>1}function $9e(t){const e=Gv(t),n=e[0],r=e.slice(1);return!(Gv(n).some(i=>i.type.name!=="tableHeader"||nB(i)||i.childCount>1)||r.some(i=>Gv(i).some(s=>s.type.name==="tableHeader"||nB(s)||s.childCount>1)))}const j9e=ot.create({name:"taskItem"}),z9e=j9e.extend({addStorage(){return{markdown:{serialize(t,e){const n=e.attrs.checked?"[x]":"[ ]";t.write(`${n} `),t.renderContent(e)},parse:{updateDOM(t){[...t.querySelectorAll(".task-list-item")].forEach(e=>{const n=e.querySelector("input");e.setAttribute("data-type","taskItem"),n&&(e.setAttribute("data-checked",n.checked),n.remove())})}}}}}}),H9e=ot.create({name:"taskList"}),U9e=H9e.extend({addStorage(){return{markdown:{serialize:QY.storage.markdown.serialize,parse:{setup(t){t.use(s9e)},updateDOM(t){[...t.querySelectorAll(".contains-task-list")].forEach(e=>{e.setAttribute("data-type","taskList")})}}}}}}),W9e=ot.create({name:"text"}),q9e=W9e.extend({addStorage(){return{markdown:{serialize(t,e){t.text(f9e(e.text))},parse:{}}}}}),V9e=bi.create({name:"bold"}),G9e=V9e.extend({addStorage(){return{markdown:{serialize:no.marks.strong,parse:{}}}}}),Y9e=bi.create({name:"code"}),K9e=Y9e.extend({addStorage(){return{markdown:{serialize:no.marks.code,parse:{}}}}}),X9e=bi.create({name:"italic"}),Z9e=X9e.extend({addStorage(){return{markdown:{serialize:no.marks.em,parse:{}}}}}),Q9e=bi.create({name:"link"}),J9e=Q9e.extend({addStorage(){return{markdown:{serialize:no.marks.link,parse:{}}}}}),e7e=bi.create({name:"strike"}),t7e=e7e.extend({addStorage(){return{markdown:{serialize:{open:"~~",close:"~~",expelEnclosingWhitespace:!0},parse:{}}}}}),n7e=[b9e,QY,v9e,JY,_9e,E9e,fk,N9e,L9e,R9e,B9e,F9e,z9e,U9e,q9e,G9e,K9e,ZY,Z9e,J9e,t7e];function Pb(t){var e,n;const r=(e=t.storage)===null||e===void 0?void 0:e.markdown,i=(n=n7e.find(s=>s.name===t.name))===null||n===void 0?void 0:n.storage.markdown;return r||i?{...i,...r}:null}class r7e{constructor(e){Bb(this,"editor",null),this.editor=e}serialize(e){const n=new d9e(this.nodes,this.marks,{hardBreakNodeName:JY.name});return n.renderContent(e),n.out}get nodes(){var e;return{...Object.fromEntries(Object.keys(this.editor.schema.nodes).map(n=>[n,this.serializeNode(fk)])),...Object.fromEntries((e=this.editor.extensionManager.extensions.filter(n=>n.type==="node"&&this.serializeNode(n)).map(n=>[n.name,this.serializeNode(n)]))!==null&&e!==void 0?e:[])}}get marks(){var e;return{...Object.fromEntries(Object.keys(this.editor.schema.marks).map(n=>[n,this.serializeMark(ZY)])),...Object.fromEntries((e=this.editor.extensionManager.extensions.filter(n=>n.type==="mark"&&this.serializeMark(n)).map(n=>[n.name,this.serializeMark(n)]))!==null&&e!==void 0?e:[])}}serializeNode(e){var n;return(n=Pb(e))===null||n===void 0||(n=n.serialize)===null||n===void 0?void 0:n.bind({editor:this.editor,options:e.options})}serializeMark(e){var n;const r=(n=Pb(e))===null||n===void 0?void 0:n.serialize;return r?{...r,open:typeof r.open=="function"?r.open.bind({editor:this.editor,options:e.options}):r.open,close:typeof r.close=="function"?r.close.bind({editor:this.editor,options:e.options}):r.close}:null}}class i7e{constructor(e,n){Bb(this,"editor",null),Bb(this,"md",null);let{html:r,linkify:i,breaks:s}=n;this.editor=e,this.md=this.withPatchedRenderer(Zr({html:r,linkify:i,breaks:s}))}parse(e){let{inline:n}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};if(typeof e=="string"){this.editor.extensionManager.extensions.forEach(s=>{var o;return(o=Pb(s))===null||o===void 0||(o=o.parse)===null||o===void 0||(o=o.setup)===null||o===void 0?void 0:o.call({editor:this.editor,options:s.options},this.md)});const r=this.md.render(e),i=BN(r);return this.editor.extensionManager.extensions.forEach(s=>{var o;return(o=Pb(s))===null||o===void 0||(o=o.parse)===null||o===void 0||(o=o.updateDOM)===null||o===void 0?void 0:o.call({editor:this.editor,options:s.options},i)}),this.normalizeDOM(i,{inline:n,content:e}),i.innerHTML}return e}normalizeDOM(e,n){let{inline:r,content:i}=n;return this.normalizeBlocks(e),e.querySelectorAll("*").forEach(s=>{var o;((o=s.nextSibling)===null||o===void 0?void 0:o.nodeType)===Node.TEXT_NODE&&!s.closest("pre")&&(s.nextSibling.textContent=s.nextSibling.textContent.replace(/^\n/,""))}),r&&this.normalizeInline(e,i),e}normalizeBlocks(e){const r=Object.values(this.editor.schema.nodes).filter(i=>i.isBlock).map(i=>{var s;return(s=i.spec.parseDOM)===null||s===void 0?void 0:s.map(o=>o.tag)}).flat().filter(Boolean).join(",");r&&[...e.querySelectorAll(r)].forEach(i=>{i.parentElement.matches("p")&&p9e(i)})}normalizeInline(e,n){var r;if((r=e.firstElementChild)!==null&&r!==void 0&&r.matches("p")){var i,s,o,a;const l=e.firstElementChild,{nextElementSibling:c}=l,u=(i=(s=n.match(/^\s+/))===null||s===void 0?void 0:s[0])!==null&&i!==void 0?i:"",h=c?"":(o=(a=n.match(/\s+$/))===null||a===void 0?void 0:a[0])!==null&&o!==void 0?o:"";if(n.match(/^\n\n/)){l.innerHTML=`${l.innerHTML}${h}`;return}g9e(l),e.innerHTML=`${u}${e.innerHTML}${h}`}}withPatchedRenderer(e){const n=r=>function(){const i=r(...arguments);return i===`
|
|
1149
1149
|
`?i:i[i.length-1]===`
|
|
1150
|
-
`?i.slice(0,-1):i};return e.renderer.rules.hardbreak=n(e.renderer.rules.hardbreak),e.renderer.rules.softbreak=n(e.renderer.rules.softbreak),e.renderer.rules.fence=n(e.renderer.rules.fence),e.renderer.rules.code_block=n(e.renderer.rules.code_block),e.renderer.renderToken=n(e.renderer.renderToken.bind(e.renderer)),e}}const s7e=Pt.create({name:"markdownClipboard",addOptions(){return{transformPastedText:!1,transformCopiedText:!1}},addProseMirrorPlugins(){return[new vt({key:new Ct("markdownClipboard"),props:{clipboardTextParser:(t,e,n)=>{if(n||!this.options.transformPastedText)return null;const r=this.editor.storage.markdown.parser.parse(t,{inline:!0});return Do.fromSchema(this.editor.schema).parseSlice(BN(r),{preserveWhitespace:!0,context:e})},clipboardTextSerializer:t=>this.options.transformCopiedText?this.editor.storage.markdown.serializer.serialize(t.content):null}})]}}),o7e=Pt.create({name:"markdown",priority:50,addOptions(){return{html:!0,tightLists:!0,tightListClass:"tight",bulletListMarker:"-",linkify:!1,breaks:!1,transformPastedText:!1,transformCopiedText:!1}},addCommands(){const t=iG.Commands.config.addCommands();return{setContent:(e,n)=>r=>t.setContent(r.editor.storage.markdown.parser.parse(e),n)(r),insertContentAt:(e,n,r)=>i=>t.insertContentAt(e,i.editor.storage.markdown.parser.parse(n,{inline:!0}),r)(i)}},onBeforeCreate(){this.editor.storage.markdown={options:{...this.options},parser:new i7e(this.editor,this.options),serializer:new r7e(this.editor),getMarkdown:()=>this.editor.storage.markdown.serializer.serialize(this.editor.state.doc)},this.editor.options.initialContent=this.editor.options.content,this.editor.options.content=this.editor.storage.markdown.parser.parse(this.editor.options.content)},onCreate(){this.editor.options.content=this.editor.options.initialContent,delete this.editor.options.initialContent},addStorage(){return{}},addExtensions(){return[l9e.configure({tight:this.options.tightLists,tightClass:this.options.tightListClass}),s7e.configure({transformPastedText:this.options.transformPastedText,transformCopiedText:this.options.transformCopiedText})]}});function a7e({editor:t,readOnly:e=!1,toolbarExtras:n}){const{t:r}=me(),i=T.useMemo(()=>[{key:"headings",buttons:[{key:"h1",label:r("markdownEditor.toolbar.h1"),icon:ire,shortcut:"Cmd+Alt+1",action:o=>{o.chain().focus().toggleHeading({level:1}).run()},isActive:o=>o.isActive("heading",{level:1})},{key:"h2",label:r("markdownEditor.toolbar.h2"),icon:ore,shortcut:"Cmd+Alt+2",action:o=>{o.chain().focus().toggleHeading({level:2}).run()},isActive:o=>o.isActive("heading",{level:2})},{key:"h3",label:r("markdownEditor.toolbar.h3"),icon:lre,shortcut:"Cmd+Alt+3",action:o=>{o.chain().focus().toggleHeading({level:3}).run()},isActive:o=>o.isActive("heading",{level:3})}]},{key:"text",buttons:[{key:"bold",label:r("markdownEditor.toolbar.bold"),icon:cne,shortcut:"Cmd+B",action:o=>{o.chain().focus().toggleBold().run()},isActive:o=>o.isActive("bold")},{key:"italic",label:r("markdownEditor.toolbar.italic"),icon:hre,shortcut:"Cmd+I",action:o=>{o.chain().focus().toggleItalic().run()},isActive:o=>o.isActive("italic")},{key:"strike",label:r("markdownEditor.toolbar.strike"),icon:die,shortcut:"Cmd+Shift+S",action:o=>{o.chain().focus().toggleStrike().run()},isActive:o=>o.isActive("strike")}]},{key:"lists",buttons:[{key:"bulletList",label:r("markdownEditor.toolbar.bulletList"),icon:wre,shortcut:"Cmd+Shift+8",action:o=>{o.chain().focus().toggleBulletList().run()},isActive:o=>o.isActive("bulletList")},{key:"orderedList",label:r("markdownEditor.toolbar.orderedList"),icon:bre,shortcut:"Cmd+Shift+7",action:o=>{o.chain().focus().toggleOrderedList().run()},isActive:o=>o.isActive("orderedList")},{key:"blockquote",label:r("markdownEditor.toolbar.blockquote"),icon:Wre,shortcut:"Cmd+Shift+B",action:o=>{o.chain().focus().toggleBlockquote().run()},isActive:o=>o.isActive("blockquote")}]},{key:"code",buttons:[{key:"code",label:r("markdownEditor.toolbar.code"),icon:Rne,shortcut:"Cmd+E",action:o=>{o.chain().focus().toggleCode().run()},isActive:o=>o.isActive("code")},{key:"codeBlock",label:r("markdownEditor.toolbar.codeBlock"),icon:fF,shortcut:"Cmd+Alt+C",action:o=>{o.chain().focus().toggleCodeBlock().run()},isActive:o=>o.isActive("codeBlock")},{key:"horizontalRule",label:r("markdownEditor.toolbar.horizontalRule"),icon:xg,shortcut:"Cmd+Alt+-",action:o=>{o.chain().focus().setHorizontalRule().run()}}]},{key:"history",buttons:[{key:"undo",label:r("markdownEditor.toolbar.undo"),icon:bie,shortcut:"Cmd+Z",action:o=>{o.chain().focus().undo().run()},isDisabled:o=>!o.can().chain().focus().undo().run()},{key:"redo",label:r("markdownEditor.toolbar.redo"),icon:Vre,shortcut:"Cmd+Shift+Z",action:o=>{o.chain().focus().redo().run()},isDisabled:o=>!o.can().chain().focus().redo().run()}]}],[r]),s=EG({editor:t,selector:({editor:o})=>o?{active:{h1:o.isActive("heading",{level:1}),h2:o.isActive("heading",{level:2}),h3:o.isActive("heading",{level:3}),bold:o.isActive("bold"),italic:o.isActive("italic"),strike:o.isActive("strike"),bulletList:o.isActive("bulletList"),orderedList:o.isActive("orderedList"),blockquote:o.isActive("blockquote"),code:o.isActive("code"),codeBlock:o.isActive("codeBlock")},disabled:{undo:!o.can().chain().focus().undo().run(),redo:!o.can().chain().focus().redo().run()}}:{active:{},disabled:{}}});return g.jsxs("div",{className:"mb-4 flex flex-wrap items-center gap-2 rounded-xl border border-gray-200 bg-white p-2 shadow-sm",children:[i.map((o,a)=>g.jsxs("div",{className:"flex items-center gap-1",children:[a>0?g.jsx("div",{className:"mx-1 h-6 border-l border-gray-300","aria-hidden":"true"}):null,o.buttons.map(l=>{var d;const c=(s==null?void 0:s.active[l.key])??!1,u=!t||e||(((d=l.isDisabled)==null?void 0:d.call(l,t))??!1)||((s==null?void 0:s.disabled[l.key])??!1),h=l.icon,f=`${l.label} (${l.shortcut})`;return g.jsx("button",{type:"button",title:f,"aria-label":f,"data-testid":`markdown-toolbar-${l.key}`,disabled:u,onClick:()=>{t&&!u&&l.action(t)},className:`flex h-8 w-8 items-center justify-center rounded-md transition-colors ${c?"bg-gray-200 text-gray-900":"text-gray-600 hover:bg-gray-100 hover:text-gray-900"} ${u?"cursor-not-allowed opacity-40":""}`,children:g.jsx(h,{className:"h-4 w-4"})},l.key)})]},o.key)),g.jsx("div",{className:"ml-auto flex flex-wrap items-center gap-2",children:n?g.jsxs(g.Fragment,{children:[g.jsx("div",{className:"mx-1 h-6 border-l border-gray-300","aria-hidden":"true"}),n]}):null})]})}const l7e=["[&_h1]:mt-0","[&_h1]:mb-3","[&_h1]:text-2xl","[&_h1]:font-bold","[&_h2]:mt-0","[&_h2]:mb-2","[&_h2]:text-xl","[&_h2]:font-semibold","[&_h3]:mt-0","[&_h3]:mb-2","[&_h3]:text-lg","[&_h3]:font-semibold","[&_p]:my-2","[&_p]:leading-7","[&_ul]:my-2","[&_ol]:my-2","[&_ul]:list-disc","[&_ol]:list-decimal","[&_ul]:pl-6","[&_ol]:pl-6","[&_li]:my-1","[&_blockquote]:my-3","[&_blockquote]:border-l-4","[&_blockquote]:border-gray-300","[&_blockquote]:pl-4","[&_blockquote]:text-gray-600","[&_blockquote]:italic","[&_blockquote_p]:my-0","[&_a]:text-blue-600","[&_a]:underline","[&_hr]:my-4","[&_hr]:border-gray-300","[&_code]:rounded","[&_code]:bg-gray-100","[&_code]:px-1.5","[&_code]:py-0.5","[&_code]:font-mono","[&_code]:text-[13px]","[&_pre]:my-3","[&_pre]:overflow-x-auto","[&_pre]:rounded-lg","[&_pre]:bg-gray-900","[&_pre]:p-4","[&_pre]:text-sm","[&_pre]:text-gray-100","[&_pre_code]:bg-transparent","[&_pre_code]:p-0","[&_pre_code]:text-inherit"].join(" "),c7e=["min-h-[420px]","rounded-xl","border","border-gray-200","bg-white","px-4","py-3","text-sm","text-gray-900","shadow-sm","focus:outline-none","prose","prose-sm","max-w-none",l7e,"[&_.is-editor-empty:first-child::before]:pointer-events-none","[&_.is-editor-empty:first-child::before]:float-left","[&_.is-editor-empty:first-child::before]:h-0","[&_.is-editor-empty:first-child::before]:text-gray-400","[&_.is-editor-empty:first-child::before]:content-[attr(data-placeholder)]"].join(" ");function m0(t){return t.storage.markdown.getMarkdown()}const u7e=T.forwardRef(function({value:e,onChange:n,placeholder:r,readOnly:i=!1,className:s,extensions:o,toolbarExtras:a,editorProps:l},c){const{t:u}=me(),h=T.useRef(null),f=T.useRef(n),d=T.useRef(e);T.useEffect(()=>{f.current=n},[n]),T.useEffect(()=>{d.current=e},[e]);const p=r??u("markdownEditor.placeholder"),m=T.useMemo(()=>[eY.configure({heading:{levels:[1,2,3]}}),_G.configure({placeholder:p}),UG.configure({openOnClick:!1,autolink:!0}),kY.configure({resizable:!1}),bY,xY,yY,o7e.configure({html:!1,linkify:!0,transformPastedText:!0,transformCopiedText:!0}),...o??[]],[o,p]),y=T.useMemo(()=>{const b=(l==null?void 0:l.attributes)??{},k=b.class??"";return{...b,class:[c7e,k].filter(Boolean).join(" "),"data-testid":b["data-testid"]??"markdown-editor-content","aria-label":b["aria-label"]??p,role:b.role??"textbox"}},[l==null?void 0:l.attributes,p]),x=NG({immediatelyRender:!1,editable:!i,extensions:m,content:e,editorProps:{attributes:y},onCreate({editor:b}){const k=m0(b);d.current=k,h.current=k},onUpdate({editor:b}){const k=m0(b);if(k===d.current){h.current=k;return}h.current=k,f.current(k)}},[m]);return T.useEffect(()=>{x&&(x.setEditable(!i),x.setOptions({editorProps:{attributes:y}}))},[x,y,i]),T.useEffect(()=>{!x||m0(x)===e||e===h.current||(x.commands.setContent(e),h.current=e)},[x,e]),T.useImperativeHandle(c,()=>({focus(){x==null||x.chain().focus().run()},selectAll(){x==null||x.chain().focus().selectAll().run()},getMarkdown(){return x?m0(x):""}}),[x]),g.jsxs("section",{className:["flex min-h-0 flex-col rounded-xl border border-gray-200 bg-gray-50 p-4 shadow-sm",s].filter(Boolean).join(" "),children:[g.jsx(a7e,{editor:x,readOnly:i,toolbarExtras:a}),g.jsx("div",{"data-testid":"markdown-editor",className:"min-h-0 flex-1 overflow-auto",children:g.jsx(dN,{editor:x})})]})}),h7e=T.forwardRef(function({path:e,initialContent:n,initialMtime:r,onCancel:i,onSaved:s,onDirtyChange:o},a){const{t:l}=me(),c=T.useRef(null),u=ss(B=>B.saveContent),h=ss(B=>B.selectPath),f=ul(B=>B.addToast),[d,p]=T.useState(n),[m,y]=T.useState(n),[x,b]=T.useState(r),[k,w]=T.useState(!1),[v,C]=T.useState(null),S=d!==m;T.useEffect(()=>{p(n),y(n),b(r),C(null)},[n,r,e]),T.useEffect(()=>{o==null||o(S)},[S,o]),T.useEffect(()=>{var B;(B=c.current)==null||B.focus()},[]);const E=T.useCallback(()=>k||S&&!window.confirm(l("docs.edit.discardConfirm"))?!1:(i(),!0),[S,i,k,l]),M=T.useCallback(async B=>{if(k)return!1;w(!0);try{const F=await u(e,d,B??x);return"error"in F?(C({currentMtime:F.currentMtime}),!1):(y(d),b(F.mtime),C(null),f({type:"success",message:l("docs.edit.savedToast")}),s(),!0)}catch(F){const z=F instanceof Error?F.message:String(F);return f({type:"error",message:l("docs.edit.saveFailed",{message:z})}),!1}finally{w(!1)}},[f,x,d,s,e,u,k,l]),A=T.useCallback(async()=>{w(!0);try{await h(e),C(null)}finally{w(!1)}},[e,h]);return T.useImperativeHandle(a,()=>({save:()=>M(),cancel:E}),[E,M]),T.useEffect(()=>{const B=F=>{(F.metaKey||F.ctrlKey)&&F.key.toLowerCase()==="s"&&(F.preventDefault(),M()),F.key==="Escape"&&(F.preventDefault(),E())};return window.addEventListener("keydown",B),()=>window.removeEventListener("keydown",B)},[E,M]),T.useEffect(()=>{if(!S)return;const B=F=>{F.preventDefault(),F.returnValue=""};return window.addEventListener("beforeunload",B),()=>window.removeEventListener("beforeunload",B)},[S]),g.jsxs(g.Fragment,{children:[g.jsx("div",{className:"flex h-full flex-col overflow-hidden bg-white",children:g.jsx("div",{className:"min-h-0 flex-1 overflow-hidden px-6 py-4",children:g.jsx(u7e,{ref:c,value:d,onChange:p,className:"h-full"})})}),v&&g.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/40 p-4",children:g.jsxs("div",{role:"dialog","aria-modal":"true",className:"w-full max-w-md rounded-2xl border border-gray-200 bg-white shadow-xl",children:[g.jsx("div",{className:"border-b border-gray-200 px-6 py-5",children:g.jsxs("div",{className:"flex items-start gap-3",children:[g.jsx("div",{className:"flex h-10 w-10 shrink-0 items-center justify-center rounded-full bg-amber-100 text-amber-600",children:g.jsx(Rn,{size:18})}),g.jsxs("div",{children:[g.jsx("h2",{className:"text-base font-semibold text-gray-900",children:l("docs.edit.conflict.title")}),g.jsx("p",{className:"mt-1 text-sm text-gray-500",children:l("docs.edit.conflict.message")})]})]})}),g.jsxs("div",{className:"flex items-center justify-end gap-2 px-6 py-4",children:[g.jsx("button",{type:"button",onClick:()=>C(null),disabled:k,className:"rounded-lg bg-gray-100 px-4 py-2 text-sm font-medium text-gray-700 transition-colors hover:bg-gray-200 disabled:cursor-not-allowed disabled:opacity-50",children:l("docs.edit.conflict.dismiss")}),g.jsxs("button",{type:"button",onClick:()=>void A(),disabled:k,className:"rounded-lg bg-blue-100 px-4 py-2 text-sm font-medium text-blue-700 transition-colors hover:bg-blue-200 disabled:cursor-not-allowed disabled:opacity-50",children:[k?g.jsx(Vr,{size:14,className:"mr-1 inline animate-spin"}):null,l("docs.edit.conflict.reload")]}),g.jsxs("button",{type:"button",onClick:()=>void M(v.currentMtime),disabled:k,className:"rounded-lg bg-amber-500 px-4 py-2 text-sm font-medium text-white transition-colors hover:bg-amber-600 disabled:cursor-not-allowed disabled:opacity-50",children:[k?g.jsx(Vr,{size:14,className:"mr-1 inline animate-spin"}):null,l("docs.edit.conflict.overwrite")]})]})]})})]})});function d7e(t){const e=t.split("/").filter(Boolean);return e.slice(0,-1).map((n,r)=>e.slice(0,r+1).join("/"))}function f7e(t){return t.split("/").filter(Boolean).slice(0,-1).join("/")}const p7e=["docs/","skills/"],g7e=new Set(["AGENTS.md","README.md","CLAUDE.md"]),rB="docs-tree-visible";function m7e(t){return/^[a-z][a-z\d+.-]*:/i.test(t)}function Yv(t){const e=[];for(const n of t.split("/"))if(!(!n||n===".")){if(n===".."){e.pop();continue}e.push(n)}return e.join("/")}function iB(t){const e=t.indexOf("#");if(e===-1)return null;const n=t.slice(e+1).trim();return n?decodeURIComponent(n):null}function y7e(t){return g7e.has(t)||p7e.some(e=>t.startsWith(e))}function x7e(t,e){const[n]=e.split("#"),[r]=n.split("?");if(!r)return t;const i=decodeURIComponent(r);if(i.startsWith("/"))return Yv(i.replace(/^\/+/,""));const s=Yv(i);return y7e(s)?s:Yv([f7e(t),i].filter(Boolean).join("/"))}function b7e(t){return t.toLowerCase().replace(/[^\w\s가-힣-]/gu,"").replace(/\s+/g,"-").replace(/^-+|-+$/g,"")}function S_(t){return typeof t=="string"||typeof t=="number"?String(t):Array.isArray(t)?t.map(e=>S_(e)).join(""):T.isValidElement(t)?S_(t.props.children):""}function __(t,e="smooth"){const n=document.getElementById(t);return n?(n.scrollIntoView({behavior:e,block:"start"}),!0):!1}function Qu(t,e,n=!1){return{pathname:"/docs",search:`?path=${encodeURIComponent(t)}`,hash:e?`#${n?encodeURIComponent(e):e}`:""}}function uu(t){return function({children:n,...r}){const i=S_(n).replace(/[✅🔲🗑️🗑⚠️]/gu,"").trim(),s=b7e(i);return T.createElement(t,{id:s,...r},n)}}function k7e({onToggle:t,onSelectPath:e}){const{t:n}=me(),{tree:r,treeLoading:i,treeError:s,fetchTree:o}=ss(),{selectedPath:a,expandedFolders:l,toggleFolder:c}=ss();return T.useEffect(()=>{o()},[o]),g.jsxs("div",{className:"flex h-full w-full min-w-0 flex-col border-r border-gray-200 bg-white",children:[g.jsxs("div",{className:"flex shrink-0 items-center justify-between border-b border-gray-200 px-4 py-3",children:[g.jsx("h2",{className:"text-xs font-semibold uppercase tracking-wide text-gray-400",children:n("docs.fileTree")}),g.jsx("button",{type:"button",onClick:t,"aria-label":n("docs.toggleTree.hide"),className:"rounded-md p-1 text-gray-500 transition-colors hover:bg-gray-100 hover:text-gray-700",children:g.jsx(Bre,{className:"h-4 w-4"})})]}),g.jsx("div",{className:"flex-1 overflow-y-auto py-1",children:i?g.jsx("div",{className:"flex h-32 items-center justify-center",children:g.jsx(ut,{className:"h-5 w-5 animate-spin text-gray-400"})}):s?g.jsx("div",{className:"px-4 py-4 text-sm text-red-500",children:s}):r.length===0?g.jsx("div",{className:"px-4 py-4 text-sm text-gray-400",children:n("docs.noFiles")}):g.jsx(oY,{nodes:r,expandedFolders:l,onToggle:c,onSelect:u=>{e(u)},selectedPath:a})})]})}function w7e({onToggle:t}){const{t:e}=me();return g.jsx("div",{className:"flex h-full w-10 shrink-0 items-start justify-center border-r border-gray-200 bg-white pt-3",children:g.jsx("button",{type:"button",onClick:t,"aria-label":e("docs.toggleTree.show"),className:"rounded-md p-1 text-gray-500 transition-colors hover:bg-gray-100 hover:text-gray-700",children:g.jsx(Fre,{className:"h-4 w-4"})})})}function v7e({path:t,dirty:e=!1}){const{t:n}=me();if(!t)return null;const r=t.split("/").filter(Boolean);return g.jsxs("nav",{className:"flex items-center gap-2 text-sm text-gray-500",children:[r.map((i,s)=>g.jsxs("span",{className:"flex items-center gap-1",children:[s>0&&g.jsx(hs,{className:"h-3.5 w-3.5 text-gray-300"}),g.jsx("span",{className:s===r.length-1?"font-medium text-gray-800":"",children:i})]},s)),e?g.jsx("span",{className:"text-sm font-semibold leading-none text-amber-500","aria-label":n("docs.edit.dirtyMarker"),children:n("docs.edit.dirtyMarker")}):null]})}function C7e(){const t=Nt(),{toc:e,tocLoading:n,selectedPath:r}=ss();return n?g.jsx("div",{className:"flex h-full w-full items-start justify-center border-l border-gray-200 pt-6",children:g.jsx(ut,{className:"h-4 w-4 animate-spin text-gray-400"})}):e.length===0?null:g.jsxs("nav",{className:"h-full w-full overflow-y-auto border-l border-gray-200 py-4 pl-4 pr-2",children:[g.jsx("p",{className:"mb-2 text-xs font-semibold uppercase tracking-wide text-gray-400",children:"Contents"}),g.jsx("ul",{className:"space-y-0.5",children:e.map((i,s)=>g.jsx("li",{children:g.jsx("a",{href:`#${i.anchor}`,onClick:o=>{o.preventDefault(),r&&t(Qu(r,i.anchor),{replace:!0}),__(i.anchor)},style:{paddingLeft:`${(i.level-1)*12}px`},className:"flex items-center gap-1 truncate text-xs text-gray-600 hover:text-blue-600 py-0.5",children:g.jsx("span",{className:"truncate",children:i.text})})},`${i.anchor}-${s}`))})]})}function S7e(){const{t}=me(),e=Nt(),n=cr(),{content:r,contentLoading:i,contentError:s,selectedPath:o,selectPath:a,toc:l}=ss();return T.useEffect(()=>{const c=n.hash?decodeURIComponent(n.hash.slice(1)):null;if(!c||i)return;const u=window.requestAnimationFrame(()=>{__(c)});return()=>window.cancelAnimationFrame(u)},[r,i,n.hash,l]),o?i?g.jsx("div",{className:"flex h-full items-center justify-center",children:g.jsx(ut,{className:"h-6 w-6 animate-spin text-gray-400"})}):s?g.jsx("div",{className:"flex h-full items-center justify-center px-4",children:g.jsx("p",{className:"text-sm text-red-500",children:s})}):g.jsx("div",{className:"prose prose-sm prose-gray max-w-none overflow-y-auto px-6 py-4 h-full",children:g.jsx(mj,{remarkPlugins:[zj],components:{h1:uu("h1"),h2:uu("h2"),h3:uu("h3"),h4:uu("h4"),h5:uu("h5"),h6:uu("h6"),a:({href:c,className:u,onClick:h,...f})=>{if(!c)return g.jsx("a",{className:u,onClick:h,...f});if(/^https?:\/\//i.test(c))return g.jsx("a",{href:c,target:"_blank",rel:"noopener noreferrer",className:u,onClick:h,...f});if(c.startsWith("#")){const y=iB(c),x=b=>{h==null||h(b),!(b.defaultPrevented||!y)&&(b.preventDefault(),e(Qu(o,y),{replace:!0}),__(y))};return g.jsx("a",{href:c,className:u,onClick:x,...f})}if(m7e(c))return g.jsx("a",{href:c,className:u,onClick:h,...f});const d=x7e(o,c),p=iB(c),m=y=>{if(h==null||h(y),y.defaultPrevented||!d)return;y.preventDefault(),a(d);const x=d===o;e(Qu(d,p,!0),{replace:x})};return g.jsx("a",{href:c,className:["cursor-pointer",u].filter(Boolean).join(" "),onClick:m,...f})}},children:r})}):g.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-2 text-gray-400",children:[g.jsx(Uo,{className:"h-10 w-10"}),g.jsx("p",{className:"text-sm",children:t("docs.selectFile")})]})}function _7e({mode:t,dirty:e,canEdit:n,contentForEditing:r,mtime:i,onEdit:s,onSave:o,onCancel:a,onCancelRequest:l,onDirtyChange:c,onSaved:u,editorRef:h}){const{t:f}=me(),{selectedPath:d,toc:p,tocLoading:m}=ss(),y=t==="view"&&(m||p.length>0);return g.jsxs("div",{className:"flex min-w-0 flex-1 flex-col overflow-hidden",children:[g.jsxs("div",{className:"flex shrink-0 items-center justify-between gap-4 border-b border-gray-200 bg-white px-6 py-3",children:[g.jsx(v7e,{path:d,dirty:t==="edit"&&e}),g.jsx("div",{className:"flex items-center gap-2",children:t==="edit"?g.jsxs(g.Fragment,{children:[g.jsxs("button",{type:"button",onClick:o,className:"inline-flex items-center gap-2 rounded-lg bg-blue-500 px-4 py-2 text-sm font-medium text-white transition-colors hover:bg-blue-600",children:[g.jsx(mF,{className:"h-4 w-4"}),f("docs.edit.save")]}),g.jsxs("button",{type:"button",onClick:l,className:"inline-flex items-center gap-2 rounded-lg bg-gray-100 px-4 py-2 text-sm font-medium text-gray-700 transition-colors hover:bg-gray-200",children:[g.jsx(Xa,{className:"h-4 w-4"}),f("docs.edit.cancel")]})]}):g.jsxs("button",{type:"button",onClick:s,disabled:!n,className:"inline-flex items-center gap-2 rounded-lg bg-gray-100 px-4 py-2 text-sm font-medium text-gray-700 transition-colors hover:bg-gray-200 disabled:cursor-not-allowed disabled:opacity-50",children:[g.jsx(PT,{className:"h-4 w-4"}),f("docs.edit.button")]})})]}),g.jsxs("div",{className:"flex min-h-0 flex-1 overflow-hidden",children:[g.jsx("div",{className:"min-w-0 flex-1 overflow-hidden",children:t==="edit"&&d&&i!==null?g.jsx(h7e,{ref:h,path:d,initialContent:r,initialMtime:i,onCancel:a,onSaved:u,onDirtyChange:c}):g.jsx(S7e,{})}),y&&g.jsx(_N,{defaultWidth:208,minWidth:160,maxWidth:320,side:"left",storageKey:"docs-toc-width",children:g.jsx(C7e,{})})]})]})}function T7e(){const{t}=me(),e=Nt(),[n]=mg(),r=n.get("path"),i=T.useRef(null),s=T.useRef(null),[o,a]=T.useState(()=>typeof window>"u"?!0:window.localStorage.getItem(rB)!=="false"),[l,c]=T.useState("view"),[u,h]=T.useState(!1),{tree:f,selectedPath:d,rawContent:p,expandedFolders:m,contentLoading:y,contentError:x,mtime:b,toggleFolder:k,selectPath:w,fetchTree:v}=ss(),C=!!(d&&!y&&!x&&b!==null),S=T.useCallback(()=>{c("view"),h(!1)},[]),E=T.useCallback(A=>{s.current=A},[]),M=T.useCallback(async(A,B=!0)=>{if(!A||A===d){A&&e(Qu(A),{replace:B});return}if(l==="edit"){if(u&&!window.confirm(t("docs.edit.discardConfirm"))){d&&e(Qu(d),{replace:!0});return}S()}await w(A),e(Qu(A),{replace:B})},[u,S,l,e,w,d,t]);return T.useEffect(()=>{v()},[v]),T.useEffect(()=>{typeof window>"u"||window.localStorage.setItem(rB,String(o))},[o]),T.useEffect(()=>{if(!r||f.length===0||i.current===r)return;const A=typeof ss.getState=="function"?ss.getState():{expandedFolders:m,toggleFolder:k},{expandedFolders:B,toggleFolder:F}=A;for(const z of d7e(r))B.has(z)||F(z);i.current=r,d!==r&&M(r,!0)},[m,M,r,d,k,f.length]),g.jsxs("div",{className:"flex h-full flex-col overflow-hidden bg-white",children:[g.jsx("header",{className:"flex h-14 shrink-0 items-center border-b border-gray-200 px-6",children:g.jsx("h1",{className:"text-lg font-semibold text-gray-900",children:t("docs.title")})}),g.jsxs("div",{className:"flex min-h-0 flex-1 overflow-hidden",children:[o?g.jsx(_N,{defaultWidth:260,minWidth:180,maxWidth:400,side:"right",storageKey:"docs-tree-width",children:g.jsx(k7e,{onToggle:()=>a(!1),onSelectPath:A=>M(A,!0)})}):g.jsx(w7e,{onToggle:()=>a(!0)}),g.jsx(_7e,{mode:l,dirty:u,canEdit:C,contentForEditing:p,mtime:b,onEdit:()=>c("edit"),onSave:()=>{var A;(A=s.current)==null||A.save()},onCancel:S,onCancelRequest:()=>{var A;(A=s.current)==null||A.cancel()},onDirtyChange:h,onSaved:S,editorRef:E})]})]})}const E7e=[{key:"all",icon:g.jsx(fre,{size:14}),labelKey:"search.tabAll"},{key:"memory",icon:g.jsx(OT,{size:14}),labelKey:"search.tabMemory"},{key:"docs",icon:g.jsx(Uo,{size:14}),labelKey:"search.tabDocs"}],sB={memory:g.jsx(OT,{size:14,className:"text-purple-500"}),docs:g.jsx(Uo,{size:14,className:"text-blue-500"})};function oB(t){return t.path?t.path:t.filePath?t.filePath:t.source==="docs"&&t.id.startsWith("doc:")?`docs/${t.id.slice(4)}.md`:t.source==="memory"&&t.agent&&t.id?`memory/${t.agent}/entries/${t.id}.md`:null}function A7e(){const{t}=me(),e=Nt(),[n,r]=mg(),i=n.get("q")??"",[s,o]=T.useState(i),[a,l]=T.useState("all"),[c,u]=T.useState([]),[h,f]=T.useState(!1),[d,p]=T.useState(null),[m,y]=T.useState(!1),x=T.useRef(null),b=T.useCallback(async C=>{const S=C.trim();if(S){r({q:S},{replace:!0}),f(!0),p(null),y(!0);try{const E=await fe.searchKnowledge(S);u(E.data)}catch(E){p(E instanceof Error?E.message:"Unknown error"),u([])}finally{f(!1)}}},[r]);T.useEffect(()=>{i&&!m&&b(i)},[]);const k=C=>{C.key==="Enter"&&b(s)},w=T.useCallback(C=>{const S=oB(C);S&&e(`/docs?path=${S}`)},[e]),v=a==="all"?c:c.filter(C=>C.source===a);return g.jsxs("div",{className:"flex flex-col items-center min-h-full py-12 px-4",children:[g.jsx("h1",{className:"text-2xl font-bold text-gray-900 mb-6",children:t("search.title")}),g.jsx("div",{className:"w-full max-w-[720px] relative mb-6",children:g.jsxs("div",{className:"flex items-center gap-2 bg-white border border-gray-300 rounded-xl shadow-sm px-4 py-3 focus-within:border-blue-400 focus-within:ring-2 focus-within:ring-blue-100 transition-all",children:[g.jsx(Ya,{size:18,className:"text-gray-400 shrink-0"}),g.jsx("input",{ref:x,type:"text",value:s,onChange:C=>o(C.target.value),onKeyDown:k,placeholder:t("search.placeholder"),className:"flex-1 text-sm text-gray-900 placeholder-gray-400 outline-none bg-transparent",autoFocus:!0}),g.jsx("button",{onClick:()=>b(s),disabled:h||!s.trim(),className:"px-4 py-1.5 bg-blue-500 text-white text-sm font-medium rounded-lg hover:bg-blue-600 disabled:opacity-50 disabled:cursor-not-allowed transition-colors",children:h?g.jsx(ut,{size:14,className:"animate-spin"}):t("search.searchBtn")})]})}),m&&g.jsx("div",{className:"w-full max-w-[720px] mb-4",children:g.jsx("div",{className:"flex gap-1 border-b border-gray-200",children:E7e.map(C=>g.jsxs("button",{type:"button",onClick:()=>{C.disabled||l(C.key)},disabled:C.disabled,className:`flex items-center gap-1.5 border-b-2 px-4 py-2 text-sm font-medium transition-colors ${C.disabled?"cursor-not-allowed border-transparent text-gray-400 opacity-60":""} ${a===C.key?"border-blue-500 text-blue-600":"border-transparent text-gray-500 hover:text-gray-700"}`,children:[C.icon,t(C.labelKey),C.key!=="all"&&!C.disabled&&g.jsxs("span",{className:"text-xs text-gray-400",children:["(",c.filter(S=>S.source===C.key).length,")"]}),C.key==="all"&&g.jsxs("span",{className:"text-xs text-gray-400",children:["(",c.length,")"]})]},C.key))})}),g.jsxs("div",{className:"w-full max-w-[720px]",children:[d&&g.jsxs("div",{className:"flex items-center gap-2 px-4 py-3 bg-red-50 border border-red-200 rounded-lg text-sm text-red-600",children:[g.jsx(Rn,{size:16}),g.jsx("span",{children:d})]}),h&&g.jsx("div",{className:"flex justify-center py-12",children:g.jsx(ut,{size:24,className:"animate-spin text-gray-400"})}),!h&&m&&!d&&v.length===0&&g.jsx("div",{className:"text-center py-12 text-gray-400 text-sm",children:t("search.noResults")}),!h&&v.length>0&&g.jsx("ul",{className:"space-y-3",children:v.map(C=>{const S=C.source==="docs",E=oB(C),M=!!E;return g.jsx("li",{onClick:M?()=>w(C):void 0,className:`bg-white border border-gray-200 rounded-lg p-4 shadow-sm hover:border-blue-300 transition-colors ${M?"cursor-pointer":""}`,children:g.jsxs("div",{className:"flex items-start gap-3",children:[g.jsx("div",{className:"shrink-0 mt-0.5",children:sB[C.source??"memory"]??sB.memory}),g.jsxs("div",{className:"flex-1 min-w-0",children:[g.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[g.jsx("span",{className:"text-sm font-medium text-gray-900 truncate",children:C.title}),g.jsx("span",{className:"shrink-0 text-xs px-1.5 py-0.5 bg-gray-100 text-gray-500 rounded",children:S?t("search.tabDocs"):C.category})]}),E&&g.jsx("p",{className:"mb-1 text-xs text-gray-400 truncate",children:E}),g.jsx("p",{className:"text-xs text-gray-500 line-clamp-2",children:C.snippet}),g.jsxs("div",{className:"flex items-center gap-2 mt-1.5",children:[!S&&C.agent&&g.jsxs("span",{className:"text-xs text-gray-400",children:["@",C.agent]}),g.jsxs("span",{className:"text-xs text-gray-300",children:["score: ",C.score.toFixed(2)]})]})]})]})},C.id)})}),!m&&g.jsx("div",{className:"text-center py-12 text-gray-400 text-sm",children:t("search.hint")})]})]})}function N7e(){const e=new Date().toISOString().slice(0,10),n=Math.random().toString(36).slice(2,8);return`${e}-${n}`}function aB(){var S;const{t}=me(),e=Nt(),[n]=mg(),{setPageHeader:r}=ur(),i=n.get("workflow"),s=t("threadNew.addAgent").replace(/^\s*\+\s*/,""),o=[{agent:"cto",label:t("threadNew.recommended.codeReview")},{agent:"devlead",label:t("threadNew.recommended.sprintSummary")},{agent:"cpo",label:t("threadNew.recommended.roadmapReview")}],[a,l]=T.useState(""),[c,u]=T.useState(!1),[h,f]=T.useState([]),[d,p]=T.useState(!0),[m,y]=T.useState(!1),x=T.useRef(null),b=T.useRef(!1),k=nr(E=>E.workflows),w=nr(E=>E.loading),v=nr(E=>E.fetchWorkflows);T.useEffect(()=>{r({title:""}),fe.getAgents().then(E=>{f(E.agents),y(!1)}).catch(()=>{f([]),y(!0)}).finally(()=>p(!1))},[r]),T.useEffect(()=>{v().catch(()=>{})},[v]),T.useEffect(()=>{if(!i||w||b.current)return;const E=k.find(M=>M.id===i);if(E){l(M=>`${Q6e(E)}${M}`.trimEnd()+" "),b.current=!0,setTimeout(()=>{var M;return(M=x.current)==null?void 0:M.focus()},0);return}w||(l(M=>M.trim()?`/wf ${i} ${M}`:`/wf ${i} `),b.current=!0,setTimeout(()=>{var M;return(M=x.current)==null?void 0:M.focus()},0))},[i,w,k]);const C=T.useCallback(async(E,M,A="query")=>{var z;const B=E.trim();if(!B||c)return!1;const F=M.trim().replace(/^@+/,"")||((z=h[0])==null?void 0:z.id)||"ui_devlead";u(!0);try{const D=N7e();return await fe.sendMessage(D,B,F,A),zs("thread_create",e2(F)),i&&zs("workflow_run",{workflow_id:i}),e(`/threads/${encodeURIComponent(D)}`),!0}catch{return u(!1),!1}},[h,e,c,i]);return g.jsx("div",{className:"flex h-full min-h-[60vh] flex-col items-center justify-center px-4 py-12 sm:px-8 lg:px-16",children:g.jsxs("div",{className:"w-full max-w-[760px] space-y-8",children:[g.jsxs("div",{className:"flex flex-col gap-4 text-center sm:flex-row sm:items-start sm:justify-between sm:text-left",children:[g.jsxs("div",{className:"flex flex-1 flex-col items-center gap-2 sm:items-start",children:[g.jsx(Ka,{size:32,className:"text-gray-400"}),g.jsx("h2",{className:"text-2xl font-semibold text-gray-900",children:t("threadNew.heading")}),g.jsx("p",{className:"text-sm text-gray-500",children:t("threadNew.subheading")})]}),g.jsxs("button",{onClick:()=>e("/agents/new"),className:"inline-flex items-center gap-2 self-center rounded-lg border border-gray-200 bg-white px-3 py-2 text-sm font-medium text-gray-600 shadow-sm transition-colors hover:border-blue-300 hover:bg-blue-50 hover:text-blue-600 sm:self-start",children:[g.jsx(Kr,{size:16}),g.jsx("span",{children:s})]})]}),m&&!d?g.jsx("div",{className:"text-center text-sm text-red-500",children:t("threadNew.agentsError")}):null,g.jsxs("div",{className:"flex flex-col items-center gap-3",children:[g.jsx("span",{className:"text-sm font-medium text-gray-500",children:t("threadNew.recommendedTitle")}),g.jsx("div",{className:"flex flex-wrap justify-center gap-3",children:o.map(E=>g.jsxs("button",{onClick:()=>{const M=h.find(B=>B.id===E.agent),A=M?`${Z6e(M)}${E.label}`:`@${E.agent} ${E.label}`;l(A),setTimeout(()=>{var B;return(B=x.current)==null?void 0:B.focus()},0)},className:"w-[200px] rounded-lg border border-gray-200 bg-white px-4 py-3 text-left transition-colors hover:border-blue-300 hover:bg-blue-50",children:[g.jsxs("span",{className:"mb-1 block text-xs font-medium text-blue-600",children:["@",E.agent]}),g.jsx("span",{className:"block text-sm font-medium text-gray-900",children:E.label})]},E.agent+E.label))})]}),d?g.jsx("div",{className:"flex h-12 items-center justify-center",children:g.jsx(ut,{size:20,className:"animate-spin text-gray-400"})}):g.jsx(SN,{onSend:C,value:a,onChange:E=>l(E),agents:h,workflows:k,placeholder:t("threadNew.inputPlaceholder"),sendLabel:t("threadNew.send"),multiline:!0,inputRef:x,disabled:c,activeAgent:((S=h[0])==null?void 0:S.id)||"ui_devlead",variant:"standalone"}),h.length===0&&!d?g.jsx("div",{className:"flex justify-center",children:g.jsxs("button",{onClick:()=>e("/agents/new"),className:"inline-flex items-center gap-2 rounded-lg border border-dashed border-gray-300 bg-white px-3 py-2 text-sm font-medium text-gray-500 transition-colors hover:border-blue-300 hover:bg-blue-50 hover:text-blue-600",children:[g.jsx(Kr,{size:16}),g.jsx("span",{children:s})]})}):null]})})}const M7e={cli:"bg-violet-100 text-violet-700",slack:"bg-green-100 text-green-700",react:"bg-cyan-100 text-cyan-700",i18n:"bg-orange-100 text-orange-700"},L7e="bg-gray-100 text-gray-600";function D7e(t){return M7e[t.toLowerCase()]??L7e}function O7e(t){if(!t)return"";const e=new Date(t);if(isNaN(e.getTime()))return t;const n=e.getFullYear(),r=String(e.getMonth()+1).padStart(2,"0"),i=String(e.getDate()).padStart(2,"0");return`${n}-${r}-${i}`}function R7e({thread:t,onUpdateTitle:e}){const n=Nt(),{t:r}=me(),i=ul(D=>D.addToast),s=T.useRef(null),o=T.useRef(!1),[a,l]=T.useState(!1),[c,u]=T.useState(t.title||""),[h,f]=T.useState(!1),{threadId:d,platform:p,messageCount:m,title:y,createdAt:x,tasks:b}=t,k=y||r("threads.emptyPrompt"),w=c.length,v=b.filter(D=>D.status==="running").length,C=Array.from(new Set(b.map(D=>D.agentId).filter(Boolean)));T.useEffect(()=>{a||u(t.title||"")},[a,t.title]),T.useEffect(()=>{if(!a)return;const D=globalThis.requestAnimationFrame(()=>{var O,N;(O=s.current)==null||O.focus(),(N=s.current)==null||N.select()});return()=>globalThis.cancelAnimationFrame(D)},[a]);const S=T.useCallback(()=>{o.current=!0,globalThis.setTimeout(()=>{o.current=!1},0)},[]),E=()=>{a||o.current||n(`/threads/${encodeURIComponent(d)}`)},M=T.useCallback(()=>{u(t.title||""),f(!1),l(!1)},[t.title]),A=T.useCallback(async()=>{S();const D=Sp(c),O=Sp(t.title);if(D===O){M();return}if(!D){i({type:"error",message:r("threads.editEmptyError")}),M();return}try{await e(d,D),f(!1),l(!1)}catch(N){u(t.title||""),f(!1),l(!1),i({type:"error",message:r("threads.editSaveFailed",{message:N instanceof Error?N.message:String(N)})})}},[i,M,e,S,r,t.title,d,c]),B=T.useCallback(D=>{if(D.key==="Escape"){D.preventDefault(),M();return}D.key==="Enter"&&(D.nativeEvent.isComposing||h||(D.preventDefault(),A()))},[M,A,h]),F=T.useCallback(()=>{S(),u(t.title||""),l(!0)},[S,t.title]),z=D=>{D.target!==D.currentTarget||a||(D.key==="Enter"||D.key===" ")&&(D.preventDefault(),E())};return g.jsxs("div",{role:"button",tabIndex:0,onClick:E,onKeyDown:z,className:"w-full text-left bg-white border border-gray-200 rounded-lg shadow-sm hover:border-blue-300 hover:shadow-md transition-all cursor-pointer overflow-hidden",children:[g.jsxs("div",{className:"flex items-start justify-between gap-4 px-4 pt-3 pb-2",children:[g.jsx("div",{className:"min-w-0 flex-1",onClick:D=>D.stopPropagation(),onDoubleClick:D=>{D.stopPropagation(),F()},children:a?g.jsxs("div",{className:"space-y-1",children:[g.jsx("input",{ref:s,value:c,maxLength:zy,onChange:D=>u(D.target.value),onBlur:()=>{A()},onKeyDown:B,onCompositionStart:()=>f(!0),onCompositionEnd:()=>f(!1),"aria-label":r("threads.editAriaLabel"),placeholder:r("threads.editPlaceholder"),className:"w-full rounded-md border border-blue-200 bg-white px-2 py-1 text-sm font-semibold text-gray-900 outline-none transition focus:border-blue-500 focus:ring-2 focus:ring-blue-500/20"}),g.jsxs("div",{className:`text-[11px] ${w>IF?"text-red-500":"text-gray-400"}`,children:[w,"/",zy]})]}):g.jsx("p",{className:"line-clamp-2 cursor-text text-sm font-semibold leading-5 text-gray-900 transition-colors hover:text-blue-600",title:k,children:k})}),v>0&&g.jsxs("span",{className:"inline-flex items-center gap-1.5 px-2 py-0.5 rounded-full text-xs font-medium shrink-0 bg-green-50 text-green-700",children:[g.jsxs("span",{className:"relative flex h-2 w-2",children:[g.jsx("span",{className:"animate-ping absolute inline-flex h-full w-full rounded-full bg-green-400 opacity-75"}),g.jsx("span",{className:"relative inline-flex rounded-full h-2 w-2 bg-green-500"})]}),v>1?r("status.runningWithCount",{count:v}):r("status.running")]})]}),g.jsxs("div",{className:"flex items-center gap-3 px-4 pb-3 flex-wrap",children:[g.jsx("span",{className:"text-xs text-gray-400 shrink-0",children:O7e(x)}),g.jsx("span",{className:`inline-flex items-center px-2 py-0.5 rounded text-xs font-medium shrink-0 ${D7e(p)}`,children:p}),g.jsxs("span",{className:"text-xs text-gray-400 flex items-center gap-1 shrink-0",children:[g.jsx(vh,{size:11}),r("threads.msgCount",{count:m})]}),C.length>0&&g.jsx("span",{className:"text-xs text-gray-400 truncate",children:C.join(", ")})]})]})}function lB({label:t,value:e,options:n,onChange:r}){return g.jsxs("div",{className:"relative",children:[g.jsx("select",{value:e,onChange:i=>r(i.target.value),className:"h-8 pl-3 pr-8 text-xs border border-gray-200 rounded-md bg-white text-gray-700 appearance-none cursor-pointer hover:border-gray-300 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent transition-colors",children:n.map(i=>g.jsx("option",{value:i.value,children:i.value==="all"?t:i.label},i.value))}),g.jsx("span",{className:"pointer-events-none absolute right-2 top-1/2 -translate-y-1/2 text-gray-400 text-xs",children:"▼"})]})}function I7e(){const{t}=me(),{setPageHeader:e}=ur(),n=Nt(),{threads:r,total:i,filters:s,loading:o,error:a,setFilters:l,fetchThreads:c,clearSearch:u,searchThreads:h,searching:f,updateTitle:d}=jT(),p=T.useRef(1),[m,y]=T.useState([]),[x,b]=T.useState(""),k=T.useRef(null),w=m.length<i;T.useEffect(()=>{p.current===1&&y(r)},[r]);const v=T.useCallback(()=>{p.current=1,b(""),u(),c()},[u,c]),C=T.useCallback(F=>{if(b(F),k.current&&clearTimeout(k.current),!F.trim()){u(),c();return}k.current=setTimeout(()=>{h(F.trim())},300)},[u,c,h]);T.useEffect(()=>{e({title:t("threads.title"),actions:g.jsxs("div",{className:"flex items-center gap-2",children:[g.jsxs("div",{className:"relative",children:[g.jsx(Ya,{size:14,className:"absolute left-2.5 top-1/2 -translate-y-1/2 text-gray-400 pointer-events-none"}),g.jsx("input",{type:"text",value:x,onChange:F=>C(F.target.value),placeholder:t("threads.searchPlaceholder"),className:"h-8 pl-8 pr-3 text-xs border border-gray-200 rounded-md bg-white text-gray-700 placeholder-gray-400 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent transition-colors w-48"})]}),g.jsx("button",{onClick:v,className:"p-2 text-gray-500 hover:text-gray-700 hover:bg-gray-100 rounded-lg transition-colors",title:t("threads.refresh"),children:g.jsx(Vr,{size:16,className:f?"animate-spin":""})})]})})},[e,v,C,x,f,t]),T.useEffect(()=>{p.current=1,c()},[c,s]);const S=T.useCallback(async()=>{const F=p.current+1;p.current=F,await c(),y(z=>[...z,...r])},[c,r]),E=[{value:"all",label:t("threads.filterAll")}],M=[{value:"updatedAt_desc",label:t("threads.sortNewest")},{value:"updatedAt_asc",label:t("threads.sortOldest")}],A=F=>{const[z,D]=F.split("_");l({sort:z,order:D})},B=`${s.sort}_${s.order}`;return g.jsxs("div",{className:"flex flex-col gap-5 max-w-4xl",children:[g.jsxs("div",{className:"flex items-center gap-3 flex-wrap",children:[g.jsx(lB,{label:`${t("threads.filterPlatform")} ▼`,value:s.platform,options:E,onChange:F=>l({platform:F})}),g.jsx(lB,{label:`${t("threads.sortNewest")}`,value:B,options:M,onChange:A})]}),a&&g.jsxs("div",{className:"flex items-center gap-3 bg-red-50 text-red-700 text-sm rounded-lg px-4 py-3 border border-red-200",children:[g.jsx(Rn,{size:16,className:"shrink-0"}),g.jsx("span",{className:"flex-1",children:a}),g.jsx("button",{onClick:v,className:"shrink-0 px-3 py-1 text-xs bg-red-100 text-red-700 rounded-md hover:bg-red-200 transition-colors",children:t("threads.retry")})]}),o&&m.length===0&&g.jsx("div",{className:"flex items-center justify-center py-12",children:g.jsx(Vr,{size:20,className:"animate-spin text-gray-400"})}),!o||m.length>0?g.jsxs(g.Fragment,{children:[g.jsx("div",{className:"flex flex-col gap-3",children:m.length===0?g.jsxs("div",{className:"flex flex-col items-center justify-center py-16 text-gray-400",children:[g.jsx(Nre,{size:40,className:"mb-3"}),g.jsx("p",{className:"text-sm",children:t("threads.empty")}),g.jsx("p",{className:"text-xs mt-1 text-gray-300",children:t("threads.emptyHint")}),g.jsxs("button",{type:"button",onClick:()=>n("/"),className:"mt-4 flex items-center gap-1.5 rounded-lg bg-blue-500 px-4 py-2 text-sm font-medium text-white transition-colors hover:bg-blue-600",children:[g.jsx(Kr,{size:16}),t("threads.emptyAction")]})]}):m.map(F=>g.jsx(R7e,{thread:F,onUpdateTitle:d},F.threadId))}),w&&!o&&g.jsx("div",{className:"flex justify-center",children:g.jsx("button",{onClick:S,className:"px-6 py-2 text-sm text-gray-600 bg-white border border-gray-200 rounded-lg hover:border-gray-300 hover:bg-gray-50 transition-colors",children:t("threads.loadMore")})}),o&&m.length>0&&g.jsx("div",{className:"flex justify-center py-4",children:g.jsx(Vr,{size:16,className:"animate-spin text-gray-400"})})]}):null]})}function B7e({agentId:t,agentColor:e}){const{t:n}=me();return g.jsxs("div",{className:"flex gap-2.5",children:[g.jsx("div",{className:`w-8 h-8 rounded-full ${e} flex items-center justify-center text-[10px] text-white font-bold shrink-0 mt-1`,title:t,children:t.substring(0,3).toUpperCase()}),g.jsxs("div",{className:"bg-white border border-gray-200 rounded-2xl rounded-tl-sm px-4 py-3 shadow-sm inline-block",children:[g.jsxs("div",{className:"flex items-center gap-1.5 mb-1",children:[g.jsx("span",{className:"w-2 h-2 rounded-full bg-gray-400 animate-dot-bounce"}),g.jsx("span",{className:"w-2 h-2 rounded-full bg-gray-400 animate-dot-bounce [animation-delay:150ms]"}),g.jsx("span",{className:"w-2 h-2 rounded-full bg-gray-400 animate-dot-bounce [animation-delay:300ms]"})]}),g.jsx("span",{className:"text-xs text-gray-400",children:n("taskDetail.thinking")})]})]})}function P7e({box:t}){const{t:e}=me();return g.jsxs("div",{className:"bg-gray-50 border border-gray-200 rounded-lg px-4 py-3 max-w-[85%]",children:[g.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[g.jsx(gF,{size:14,className:"text-gray-400 shrink-0"}),g.jsx("span",{className:"text-xs font-medium text-gray-500",children:e("threadDetail.boxLabel",{count:t.taskCount,tokens:Math.round(t.sourceTokens/1e3)})})]}),g.jsxs("div",{className:"space-y-1 text-sm text-gray-600",children:[t.previewFirst&&g.jsx("p",{className:"truncate",children:t.previewFirst}),t.previewMid&&g.jsx("p",{className:"truncate text-gray-400",children:t.previewMid}),t.previewLast&&g.jsx("p",{className:"truncate",children:t.previewLast})]})]})}function cB(t){const e=["bg-blue-500","bg-green-500","bg-purple-500","bg-orange-500","bg-pink-500","bg-cyan-500"];let n=0;for(let r=0;r<t.length;r++)n=t.charCodeAt(r)+((n<<5)-n);return e[Math.abs(n)%e.length]}function uB(t){return t>=1e3?`${(t/1e3).toFixed(1)}K`:String(t)}function F7e(t){return{id:t.taskId,userId:void 0,text:t.content,timestamp:t.startedAt,isAssistant:!0,metadata:{agent_id:t.agentId},logs:void 0}}function $7e(t){return{id:`${t.taskId}-prompt`,userId:"user",text:t.prompt,timestamp:t.startedAt,isAssistant:!1,metadata:void 0,logs:void 0}}function j7e(){var $e;const{t}=me(),{threadId:e}=Kh(),n=Nt(),r=T.useRef(null),i=T.useRef(null),{setPageHeader:s}=ur(),o=jT(ee=>ee.updateTitle),a=ul(ee=>ee.addToast),[l,c]=T.useState(!1),[u,h]=T.useState(""),[f,d]=T.useState(!1),{title:p,messages:m,meta:y,platform:x,loading:b,error:k,sending:w,polling:v,taskLogs:C,fetchDetail:S,fetchTaskLogs:E,sendMessage:M,stopPolling:A,setOptimisticTitle:B,rollbackTitle:F,reset:z}=RF();T.useEffect(()=>{s({title:"",actions:null})},[s]),T.useEffect(()=>(e&&S(e),()=>{A(),z()}),[e]),T.useEffect(()=>{r.current&&(r.current.scrollTop=r.current.scrollHeight)},[m.length]);const{agents:D,latestStatus:O,latestAgentId:N,runningCount:$,oldestRunningStartedAt:I,totalCost:P,totalInput:L,totalOutput:W}=T.useMemo(()=>{const ee=m.filter(je=>je.type==="task"),ge=ee[ee.length-1],ze=ee.filter(je=>je.status==="running"),ce=ze.length,Ut=ze.reduce((je,Kt)=>Kt.startedAt?je?Kt.startedAt<je?Kt.startedAt:je:Kt.startedAt:je,null);if(y)return{agents:y.agents,latestStatus:(ge==null?void 0:ge.status)??null,latestAgentId:(ge==null?void 0:ge.agentId)??"",runningCount:ce,oldestRunningStartedAt:Ut,totalCost:y.totals.costUsd,totalInput:y.totals.inputTokens,totalOutput:y.totals.outputTokens};const ct=new Set;let ne=null,Ge="";for(const je of m)je.type==="task"&&(je.agentId&&ct.add(je.agentId),ne=je.status,Ge=je.agentId||Ge);return{agents:Array.from(ct),latestStatus:ne,latestAgentId:Ge,runningCount:ce,oldestRunningStartedAt:Ut,totalCost:0,totalInput:0,totalOutput:0}},[m,y]);if(!e)return null;const G=(ee,ge,ze="query")=>{M(ee,ge,ze)},j=($e=m.find(ee=>ee.type==="task"))==null?void 0:$e.prompt,V=p||(j?j.slice(0,30):null)||e.replace(/^\d{4}-\d{2}-\d{2}-/,""),Z=u.length,re=Z>IF?"text-red-500":"text-gray-400";T.useEffect(()=>{l||h(V)},[V,l]),T.useEffect(()=>{if(!l)return;const ee=globalThis.requestAnimationFrame(()=>{var ge,ze;(ge=i.current)==null||ge.focus(),(ze=i.current)==null||ze.select()});return()=>globalThis.cancelAnimationFrame(ee)},[l]);const ve=T.useCallback(()=>{h(V),d(!1),c(!1)},[V]),Ee=T.useCallback(async()=>{if(!e)return;const ee=Sp(u),ge=Sp(V);if(ee===ge){ve();return}if(!ee){a({type:"error",message:t("threads.editEmptyError")}),ve();return}const ze=p;B(ee);try{await o(e,ee),d(!1),c(!1)}catch(ce){F(ze),h(ze||V),d(!1),c(!1),a({type:"error",message:t("threads.editSaveFailed",{message:ce instanceof Error?ce.message:String(ce)})})}},[a,V,ve,F,B,t,e,p,u,o]),qe=T.useCallback(ee=>{if(ee.key==="Escape"){ee.preventDefault(),ve();return}ee.key==="Enter"&&(ee.nativeEvent.isComposing||f||(ee.preventDefault(),Ee()))},[ve,Ee,f]),he=(()=>{const ee=new Map;let ge=null;for(let ze=0;ze<m.length;ze++){const ce=m[ze];ce.type==="task"&&ce.agentId!==ge&&(ee.set(ze,ce.agentId),ge=ce.agentId)}return ee})(),be=D.slice(0,4),Ve=D.length-be.length,te=P>0;return g.jsxs("div",{className:"flex flex-col h-[calc(100vh-3rem)] -m-6 bg-gray-50",children:[g.jsxs("div",{className:"flex items-center px-6 py-3 bg-white border-b border-gray-200 shrink-0",children:[g.jsxs("div",{className:"flex items-center gap-3 min-w-0 flex-1",children:[g.jsxs("button",{onClick:()=>n("/threads"),className:"flex items-center gap-1.5 text-sm text-gray-600 hover:text-gray-900 transition-colors shrink-0",children:[g.jsx(LT,{size:16}),g.jsx("span",{children:t("threadDetail.back")})]}),g.jsx("div",{className:"w-px h-4 bg-gray-200 shrink-0"}),g.jsxs("div",{className:"min-w-0",children:[l?g.jsxs("div",{className:"space-y-1",children:[g.jsx("input",{ref:i,value:u,maxLength:zy,onChange:ee=>h(ee.target.value),onBlur:()=>{Ee()},onKeyDown:qe,onCompositionStart:()=>d(!0),onCompositionEnd:()=>d(!1),"aria-label":t("threads.editAriaLabel"),placeholder:t("threads.editPlaceholder"),className:"w-full rounded-md border border-blue-200 bg-white px-2 py-1 text-base font-semibold text-gray-900 outline-none transition focus:border-blue-500 focus:ring-2 focus:ring-blue-500/20"}),g.jsxs("div",{className:`text-[11px] ${re}`,children:[Z,"/",zy]})]}):g.jsx("h1",{className:"cursor-text text-base font-semibold text-gray-900 transition-colors hover:text-blue-600",onDoubleClick:()=>c(!0),title:V,children:V}),g.jsx("p",{className:"text-[11px] text-gray-500 truncate",children:x??"cli"})]})]}),be.length>0&&g.jsxs("div",{className:"flex items-center -space-x-2 mx-4",children:[be.map(ee=>g.jsx("div",{className:`w-7 h-7 rounded-full ${cB(ee)} flex items-center justify-center text-[9px] text-white font-bold border-2 border-white`,title:ee,children:ee.substring(0,3).toUpperCase()},ee)),Ve>0&&g.jsxs("div",{className:"w-7 h-7 rounded-full bg-gray-200 flex items-center justify-center text-[9px] text-gray-600 font-bold border-2 border-white",children:["+",Ve]})]}),g.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[te&&g.jsxs("div",{className:"flex items-center gap-1.5 text-xs text-gray-500",children:[g.jsx("span",{children:t("taskDetail.costLabel",{cost:P.toFixed(2)})}),g.jsx("span",{className:"text-gray-300",children:"·"}),g.jsx("span",{children:t("taskDetail.tokenUsage",{input:uB(L),output:uB(W)})})]}),$>0&&g.jsx(uq,{status:"running",startedAt:I,runningCount:$})]})]}),g.jsxs("div",{ref:r,className:"flex-1 overflow-y-auto px-8 py-6 space-y-5",children:[b&&g.jsx("div",{className:"flex items-center justify-center py-16",children:g.jsx(ut,{size:24,className:"animate-spin text-gray-500"})}),k&&!b&&g.jsxs("div",{className:"flex items-center gap-3 bg-red-50 text-red-600 text-sm rounded-lg px-4 py-3 border border-red-200",children:[g.jsx(Rn,{size:16,className:"shrink-0"}),g.jsx("span",{children:k})]}),!b&&m.map((ee,ge)=>{var ce,Ut;if(ee.type==="box")return g.jsx(P7e,{box:ee},ee.boxId);const ze=he.get(ge);return g.jsxs(T.Fragment,{children:[ze&&g.jsxs("div",{className:"flex items-center gap-3 py-1",children:[g.jsx("div",{className:"flex-1 h-px bg-gray-200"}),g.jsx("span",{className:"text-xs text-gray-400 shrink-0 select-none",children:t("taskDetail.agentJoined",{agent:ze})}),g.jsx("div",{className:"flex-1 h-px bg-gray-200"})]}),ee.prompt&&g.jsx(OS,{message:$7e(ee),taskStatus:null}),g.jsx(OS,{message:F7e(ee),logs:(ce=C[ee.taskId])==null?void 0:ce.logs,childTasks:(Ut=C[ee.taskId])==null?void 0:Ut.childTasks,taskStatus:ee.status,onRequestLogs:()=>E(ee.taskId)})]},ee.taskId)}),!b&&!k&&!m.some(ee=>ee.type==="task"&&(ee.status==="running"||ee.status==="pending"))&&(O==="running"||O==="pending")&&g.jsx(B7e,{agentId:N||"assistant",agentColor:cB(N||"assistant")}),!b&&!k&&m.length===0&&v&&g.jsxs("div",{className:"flex flex-col items-center justify-center py-16 text-gray-500",children:[g.jsx(ut,{size:24,className:"animate-spin text-blue-400 mb-3"}),g.jsx("p",{className:"text-sm font-medium",children:t("taskDetail.pendingAgent","에이전트 실행 대기 중...")}),g.jsx("p",{className:"text-xs mt-1 text-gray-400",children:t("taskDetail.pendingAgentHint","잠시만 기다려 주세요.")})]}),!b&&!k&&m.length===0&&!v&&g.jsxs("div",{className:"flex flex-col items-center justify-center py-16 text-gray-500",children:[g.jsx("p",{className:"text-sm",children:t("threadDetail.noMessages")}),g.jsx("p",{className:"text-xs mt-1 text-gray-600",children:t("threadDetail.noMessagesHint")})]})]}),g.jsx(SN,{onSend:G,disabled:w,activeAgent:N||void 0,storageKey:e,multiline:!0})]})}function eK(t){return t.trim().replace(/^@+/,"")}function z7e(t){return`@${eK(t)}`}function H7e(t,e){if(!t)return"";const n=Date.now()-new Date(t).getTime(),r=Math.floor(n/6e4);if(r<1)return e("projects.justNow");if(r<60)return e("projects.minutesAgo",{count:r});const i=Math.floor(r/60);if(i<24)return e("projects.hoursAgo",{count:i});const s=Math.floor(i/24);if(s<7)return e("projects.daysAgo",{count:s});const o=Math.floor(s/7);return e("projects.weeksAgo",{count:o})}function U7e({agentId:t}){const e=eK(t),n=e.slice(0,2).toUpperCase(),r=["bg-blue-500","bg-emerald-500","bg-violet-500","bg-amber-500","bg-rose-500","bg-cyan-500"],i=e.split("").reduce((s,o)=>s+o.charCodeAt(0),0)%r.length;return g.jsx("span",{className:`inline-flex items-center justify-center w-6 h-6 rounded-full text-[10px] font-semibold text-white ${r[i]}`,title:e,children:n})}const hB=[{bg:"bg-blue-100",text:"text-blue-600"},{bg:"bg-orange-100",text:"text-orange-500"},{bg:"bg-green-100",text:"text-green-600"},{bg:"bg-purple-100",text:"text-purple-600"},{bg:"bg-pink-100",text:"text-pink-500"},{bg:"bg-cyan-100",text:"text-cyan-600"},{bg:"bg-amber-100",text:"text-amber-600"}];function W7e({project:t,index:e,onDeleted:n}){const r=Nt(),{t:i}=me(),[s,o]=T.useState(!1),a=T.useRef(null),l=hB[e%hB.length];T.useEffect(()=>{if(!s)return;const u=h=>{a.current&&!a.current.contains(h.target)&&o(!1)};return document.addEventListener("mousedown",u),()=>document.removeEventListener("mousedown",u)},[s]);const c=async u=>{if(u.stopPropagation(),o(!1),!!confirm(i("projects.deleteConfirm",{name:t.name})))try{await fe.deleteProject(t.id),n(t.id)}catch{}};return g.jsxs("div",{className:"bg-white border border-gray-200 rounded-lg shadow-sm p-4 cursor-pointer hover:border-blue-300 hover:shadow-md transition-all",onClick:()=>r(`/projects/${t.id}`),children:[g.jsxs("div",{className:"flex items-start gap-3 mb-2",children:[g.jsx("div",{className:`flex-shrink-0 w-9 h-9 ${l.bg} rounded-lg flex items-center justify-center`,children:g.jsx(is,{size:18,className:l.text})}),g.jsxs("div",{className:"flex-1 min-w-0",children:[g.jsx("h3",{className:"text-sm font-semibold text-gray-900 truncate",children:t.name}),t.description&&g.jsx("p",{className:"text-xs text-gray-500 mt-0.5 line-clamp-2",children:t.description})]}),g.jsxs("div",{className:"relative flex-shrink-0",ref:a,children:[g.jsx("button",{type:"button",onClick:u=>{u.stopPropagation(),o(h=>!h)},className:"p-1 rounded-md text-gray-400 hover:text-gray-600 hover:bg-gray-100 transition-colors","aria-label":i("projects.menuAriaLabel"),children:g.jsx(Wne,{size:16})}),s&&g.jsxs("div",{className:"absolute right-0 top-7 z-20 w-28 bg-white border border-gray-200 rounded-lg shadow-lg py-1",children:[g.jsx("button",{type:"button",onClick:u=>{u.stopPropagation(),o(!1),r(`/projects/${t.id}/edit`)},className:"w-full text-left px-3 py-1.5 text-sm text-gray-700 hover:bg-gray-50 transition-colors",children:i("projects.edit")}),g.jsx("button",{type:"button",onClick:c,className:"w-full text-left px-3 py-1.5 text-sm text-red-600 hover:bg-red-50 transition-colors",children:i("projects.delete")})]})]})]}),t.agents.length>0&&g.jsxs("div",{className:"flex items-center gap-1.5 mb-3 flex-wrap",children:[g.jsx("div",{className:"flex -space-x-1",children:t.agents.slice(0,4).map(u=>g.jsx(U7e,{agentId:u.agentId},u.agentId))}),g.jsxs("span",{className:"text-xs text-gray-500",children:[t.agents.slice(0,3).map(u=>z7e(u.agentId)).join(", "),t.agents.length>3&&` +${t.agents.length-3}`]})]}),g.jsxs("div",{className:"flex items-center justify-between text-xs text-gray-400",children:[g.jsxs("div",{className:"flex items-center gap-3",children:[g.jsxs("span",{className:"flex items-center gap-1",children:[g.jsx(vh,{size:12}),i("projects.threadCount",{count:t.threadCount})]}),g.jsxs("span",{className:"flex items-center gap-1",children:[g.jsx(Uo,{size:12}),i("projects.docCount",{count:t.docCount})]})]}),t.lastActivityAt&&g.jsx("span",{children:H7e(t.lastActivityAt,i)})]})]})}function q7e(){const{t}=me(),e=Nt(),{setPageHeader:n}=ur(),[r,i]=T.useState([]),[s,o]=T.useState(!0),[a,l]=T.useState(null),c=T.useCallback(async()=>{o(!0),l(null);try{const h=await fe.getProjects();i(h.data??[])}catch(h){l(h instanceof Error?h.message:t("projects.loadError"))}finally{o(!1)}},[t]),u=T.useCallback(h=>{i(f=>f.filter(d=>d.id!==h))},[]);return T.useEffect(()=>{const h=!s&&!a&&r.length>0?t("projects.totalCount",{count:r.length}):void 0;n({title:t("projects.title"),subtitle:h,actions:g.jsxs("button",{onClick:()=>e("/projects/new"),className:"flex items-center gap-1.5 px-3 py-1.5 text-sm bg-blue-500 text-white hover:bg-blue-600 rounded-lg transition-colors",children:[g.jsx(Kr,{size:16}),t("projects.newProject")]})})},[n,e,t,r.length,s,a]),T.useEffect(()=>{c()},[c]),g.jsxs("div",{className:"h-full flex flex-col",children:[a&&g.jsxs("div",{className:"flex items-center gap-3 bg-red-50 text-red-700 text-sm rounded-lg px-4 py-3 border border-red-200 mb-4",children:[g.jsx(Rn,{size:16,className:"shrink-0"}),g.jsx("span",{className:"flex-1",children:a}),g.jsx("button",{onClick:c,className:"shrink-0 px-3 py-1 text-xs bg-red-100 text-red-700 rounded-md hover:bg-red-200 transition-colors",children:t("projects.retry")})]}),s&&g.jsx("div",{className:"flex items-center justify-center py-16",children:g.jsx(Vr,{size:20,className:"animate-spin text-gray-400"})}),!s&&!a&&r.length===0&&g.jsxs("div",{className:"flex flex-col items-center justify-center py-20 text-gray-400",children:[g.jsx(is,{size:48,className:"mb-4 text-gray-300"}),g.jsx("p",{className:"text-sm font-medium text-gray-500 mb-1",children:t("projects.emptyTitle")}),g.jsx("p",{className:"text-xs text-gray-400 mb-4",children:t("projects.emptyDesc")}),g.jsxs("button",{onClick:()=>e("/projects/new"),className:"flex items-center gap-1.5 px-4 py-2 text-sm bg-blue-500 text-white hover:bg-blue-600 rounded-lg transition-colors",children:[g.jsx(Kr,{size:16}),t("projects.newProject")]})]}),!s&&!a&&r.length>0&&g.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:r.map((h,f)=>g.jsx(W7e,{project:h,index:f,onDeleted:u},h.id))})]})}function V7e({agent:t,onRemove:e}){const n=["bg-blue-100 text-blue-700","bg-emerald-100 text-emerald-700","bg-violet-100 text-violet-700","bg-amber-100 text-amber-700","bg-rose-100 text-rose-700","bg-cyan-100 text-cyan-700"],r=t.id.split("").reduce((i,s)=>i+s.charCodeAt(0),0)%n.length;return g.jsxs("span",{className:`inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-xs font-medium ${n[r]}`,children:["@",t.id,g.jsx("button",{type:"button",onClick:i=>{i.stopPropagation(),e()},className:"hover:opacity-70 transition-opacity","aria-label":`Remove ${t.id}`,children:g.jsx(Xa,{size:10})})]})}function G7e({value:t,onChange:e}){const{t:n}=me(),[r,i]=T.useState([]),[s,o]=T.useState(!0),[a,l]=T.useState(null),[c,u]=T.useState(!1),h=T.useRef(null);T.useEffect(()=>{fe.getAgents().then(m=>i(m.agents??[])).catch(()=>l(n("project.agentsError"))).finally(()=>o(!1))},[n]),T.useEffect(()=>{function m(y){h.current&&!h.current.contains(y.target)&&u(!1)}return document.addEventListener("mousedown",m),()=>document.removeEventListener("mousedown",m)},[]);const f=r.filter(m=>t.includes(m.id)),d=r.filter(m=>!t.includes(m.id));function p(m){t.includes(m)?e(t.filter(y=>y!==m)):e([...t,m])}return g.jsxs("div",{ref:h,className:"relative",children:[g.jsxs("div",{role:"combobox","aria-expanded":c,"aria-haspopup":"listbox",onClick:()=>!s&&!a&&u(m=>!m),className:`min-h-[38px] w-full flex items-center flex-wrap gap-1.5 px-3 py-2 rounded-lg border border-gray-200 bg-white text-sm cursor-pointer select-none transition-colors hover:border-gray-300 focus-within:border-blue-400 ${s||a?"opacity-60 cursor-not-allowed":""}`,children:[a?g.jsxs("span",{className:"flex items-center gap-1.5 text-red-500 text-xs",children:[g.jsx(Rn,{size:14}),a]}):s?g.jsx("span",{className:"text-gray-400",children:n("common.loading","Loading...")}):f.length===0?g.jsx("span",{className:"text-gray-400",children:n("project.fieldAgentPlaceholder")}):f.map(m=>g.jsx(V7e,{agent:m,onRemove:()=>p(m.id)},m.id)),g.jsx(Yr,{size:16,className:`ml-auto shrink-0 text-gray-400 transition-transform ${c?"rotate-180":""}`})]}),c&&!s&&!a&&g.jsx("div",{className:"absolute z-50 mt-1 w-full rounded-lg border border-gray-200 bg-white shadow-lg max-h-56 overflow-y-auto",children:r.length===0?g.jsx("div",{className:"px-4 py-3 text-sm text-gray-400 text-center",children:n("project.noAgentsAvailable")}):g.jsxs(g.Fragment,{children:[d.length===0&&t.length>0&&g.jsx("div",{className:"px-4 py-2 text-xs text-gray-400",children:n("project.allAgentsSelected")}),r.map(m=>{const y=t.includes(m.id);return g.jsxs("button",{type:"button",role:"option","aria-selected":y,onClick:()=>p(m.id),className:"w-full flex items-center gap-3 px-4 py-2.5 text-sm text-left hover:bg-gray-50 transition-colors",children:[g.jsxs("div",{className:"flex-1 min-w-0",children:[g.jsxs("div",{className:"font-medium text-gray-900 truncate",children:["@",m.id]}),m.role&&g.jsx("div",{className:"text-xs text-gray-500 truncate",children:m.role})]}),y&&g.jsx(Us,{size:16,className:"shrink-0 text-blue-500"})]},m.id)})]})})]})}function Y7e(){const t=Nt(),{id:e}=Kh(),{t:n}=me(),r=!!e,[i,s]=T.useState(""),[o,a]=T.useState(""),[l,c]=T.useState([]),[u,h]=T.useState(""),[f,d]=T.useState(!1),[p,m]=T.useState(""),[y,x]=T.useState(!1),b=T.useCallback(async()=>{if(e){x(!0),m("");try{const w=await fe.getProject(e);s(w.name??""),a(w.description??"")}catch(w){m(w instanceof Error?w.message:n("project.loadError"))}finally{x(!1)}}},[e,n]);T.useEffect(()=>{b()},[b]);const k=async()=>{if(!i.trim()){h(n("project.nameRequired"));return}h(""),m(""),d(!0);try{const w=r&&e?await fe.updateProject(e,{name:i.trim(),description:o.trim()||void 0}):await fe.createProject({name:i.trim(),description:o.trim()||void 0,agentIds:l.length>0?l:void 0});w.id?t(`/projects/${w.id}`):m(n(r?"project.updateError":"project.createError"))}catch{m(n(r?"project.updateError":"project.createError"))}finally{d(!1)}};return g.jsxs("div",{className:"flex flex-col h-full bg-gray-50",children:[g.jsxs("div",{className:"flex items-center justify-between bg-white border-b border-gray-200",style:{padding:"20px 32px"},children:[g.jsxs("div",{className:"flex flex-col gap-0.5",children:[g.jsx("h1",{className:"text-xl font-semibold text-gray-900",children:n(r?"project.editTitle":"project.newTitle")}),g.jsx("p",{className:"text-sm text-gray-500",children:n(r?"project.editSubtitle":"project.newSubtitle")})]}),g.jsxs("div",{className:"flex items-center gap-2",children:[g.jsx("button",{type:"button",onClick:()=>t("/projects"),disabled:f,className:"px-4 py-2 rounded-lg text-sm font-medium text-gray-700 bg-transparent border border-gray-300 hover:bg-gray-50 disabled:opacity-50",children:n("project.cancel")}),g.jsxs("button",{type:"button",onClick:k,disabled:f,className:"px-4 py-2 rounded-lg text-sm font-medium text-white bg-blue-500 hover:bg-blue-600 disabled:opacity-50 flex items-center gap-2",children:[f&&g.jsxs("svg",{className:"animate-spin h-4 w-4",viewBox:"0 0 24 24",fill:"none",children:[g.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),g.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8v8H4z"})]}),n(r?"project.save":"project.create")]})]})]}),g.jsx("div",{className:"flex-1 flex justify-center overflow-y-auto",style:{padding:"48px 0"},children:g.jsxs("div",{className:"flex flex-col gap-8",style:{width:720},children:[y&&g.jsx("div",{className:"rounded-lg bg-gray-50 border border-gray-200 px-4 py-3 text-sm text-gray-600",children:n("project.loading")}),p&&g.jsx("div",{className:"rounded-lg bg-red-50 border border-red-200 px-4 py-3 text-sm text-red-700",children:p}),g.jsxs("div",{className:"flex flex-col gap-5",children:[g.jsx("h2",{className:"text-base font-semibold text-gray-900",children:n("project.sectionBasic")}),g.jsxs("div",{className:"flex flex-col gap-1.5",children:[g.jsxs("label",{className:"text-sm font-medium text-gray-700",children:[n("project.fieldName"),g.jsx("span",{className:"text-red-500 ml-0.5",children:"*"})]}),g.jsx("input",{type:"text",value:i,onChange:w=>{s(w.target.value),w.target.value.trim()&&h("")},placeholder:n("project.fieldNamePlaceholder"),className:`w-full px-3 py-2 rounded-lg border text-sm outline-none transition-colors ${u?"border-red-400 focus:border-red-500 bg-red-50":"border-gray-200 focus:border-blue-400 bg-white"}`}),u&&g.jsx("p",{className:"text-xs text-red-500",children:u})]}),g.jsxs("div",{className:"flex flex-col gap-1.5",children:[g.jsx("label",{className:"text-sm font-medium text-gray-700",children:n("project.fieldDescription")}),g.jsx("textarea",{value:o,onChange:w=>a(w.target.value),placeholder:n("project.fieldDescriptionPlaceholder"),rows:5,className:"w-full px-3 py-2 rounded-lg border border-gray-200 focus:border-blue-400 text-sm outline-none resize-none bg-white transition-colors"})]})]}),g.jsxs("div",{className:"flex flex-col gap-5",children:[g.jsx("h2",{className:"text-base font-semibold text-gray-900",children:n("project.sectionTeam")}),g.jsx("p",{className:"text-sm text-gray-500 -mt-3",children:n("project.sectionTeamDesc")}),g.jsxs("div",{className:"flex flex-col gap-1.5",children:[g.jsx("label",{className:"text-sm font-medium text-gray-700",children:n("project.fieldAgent")}),g.jsx(G7e,{value:l,onChange:c})]})]})]})})]})}function pk(t){return t.trim().replace(/^@+/,"")}function dB(t){return`@${pk(t)}`}function K7e(t,e){const n=Date.now(),r=new Date(t).getTime(),i=n-r,s=Math.floor(i/6e4),o=Math.floor(s/60),a=Math.floor(o/24);return s<1?e("projects.justNow"):s<60?e("projects.minutesAgo",{count:s}):o<24?e("projects.hoursAgo",{count:o}):a===1?e("projectDetail.yesterday"):e("projects.daysAgo",{count:a})}function X7e(t){const e=pk(t),n=["bg-blue-500","bg-purple-500","bg-green-500","bg-orange-500","bg-pink-500","bg-teal-500","bg-indigo-500","bg-rose-500"];let r=0;for(let i=0;i<e.length;i++)r=r*31+e.charCodeAt(i)&4294967295;return n[Math.abs(r)%n.length]}function Z7e(t){const e=pk(t),n=e.split(/[_\-\s]+/).filter(Boolean);return n.length===0?e.slice(0,2).toUpperCase():n.slice(0,2).map(r=>r[0]).join("").toUpperCase()}const Q7e={pending:"bg-gray-100 text-gray-600",running:"bg-blue-100 text-blue-700",success:"bg-green-100 text-green-700",failed:"bg-red-100 text-red-700"};function J7e(){const{id:t}=Kh(),e=Nt(),{t:n}=me(),{setPageHeader:r}=ur(),[i,s]=T.useState(null),[o,a]=T.useState([]),[l,c]=T.useState([]),[u,h]=T.useState(!0),[f,d]=T.useState(null),[p,m]=T.useState(""),[y,x]=T.useState(!1),[b,k]=T.useState(!1),w=T.useCallback(async()=>{if(t){h(!0),d(null);try{const[M,A,B]=await Promise.all([fe.getProject(t),fe.getProjectThreads(t),fe.getProjectDocs(t)]);s(M),a(A.threads),c(B.docs)}catch(M){d(M instanceof Error?M.message:n("projectDetail.loadError"))}finally{h(!1)}}},[t,n]);T.useEffect(()=>{w()},[w]),T.useEffect(()=>{r({title:(i==null?void 0:i.name)??n("projects.title"),subtitle:(i==null?void 0:i.description)||void 0})},[r,i,n]);const v=T.useCallback(()=>{p.trim()&&e(`/?workspace=${encodeURIComponent(t??"")}&prompt=${encodeURIComponent(p.trim())}`)},[p,t,e]),C=T.useCallback(M=>{M.key==="Enter"&&!M.shiftKey&&(M.preventDefault(),v())},[v]),S=T.useCallback(async()=>{if(t){k(!0);try{await fe.deleteProject(t),e("/projects")}catch(M){d(M instanceof Error?M.message:n("projectDetail.deleteError")),x(!1)}finally{k(!1)}}},[t,e,n]);if(u)return g.jsx("div",{className:"flex items-center justify-center h-full py-20",children:g.jsx(Vr,{size:20,className:"animate-spin text-gray-400"})});if(f)return g.jsxs("div",{className:"flex flex-col items-center justify-center py-20 gap-4",children:[g.jsxs("div",{className:"flex items-center gap-3 bg-red-50 text-red-700 text-sm rounded-lg px-4 py-3 border border-red-200",children:[g.jsx(Rn,{size:16,className:"shrink-0"}),g.jsx("span",{children:f})]}),g.jsx("button",{onClick:w,className:"px-4 py-2 text-sm bg-gray-100 text-gray-700 rounded-lg hover:bg-gray-200 transition-colors",children:n("common.refresh")})]});if(!i)return g.jsxs("div",{className:"flex flex-col items-center justify-center py-20 gap-2 text-gray-400",children:[g.jsx(is,{size:40}),g.jsx("p",{className:"text-sm",children:n("projectDetail.notFound")})]});const E=n(`projectDetail.projectStatus.${i.status}`,{defaultValue:i.status});return g.jsxs("div",{className:"flex flex-col h-full min-h-0",children:[y&&g.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/40",children:g.jsxs("div",{className:"bg-white rounded-xl shadow-xl p-6 w-80 flex flex-col gap-4",children:[g.jsxs("div",{className:"flex items-center gap-3",children:[g.jsx("div",{className:"flex items-center justify-center w-10 h-10 rounded-full bg-red-100",children:g.jsx($y,{size:18,className:"text-red-600"})}),g.jsxs("div",{children:[g.jsx("p",{className:"text-sm font-semibold text-gray-900",children:n("projectDetail.deleteTitle")}),g.jsx("p",{className:"text-xs text-gray-500 mt-0.5",children:n("projectDetail.deleteWarning")})]})]}),g.jsx("p",{className:"text-sm text-gray-700",children:n("projectDetail.deleteConfirmMsg",{name:i.name})}),g.jsxs("div",{className:"flex gap-2 justify-end",children:[g.jsx("button",{onClick:()=>x(!1),disabled:b,className:"px-4 py-2 text-sm text-gray-700 bg-gray-100 hover:bg-gray-200 rounded-lg transition-colors disabled:opacity-50",children:n("projectDetail.cancel")}),g.jsxs("button",{onClick:S,disabled:b,className:"flex items-center gap-1.5 px-4 py-2 text-sm text-white bg-red-500 hover:bg-red-600 rounded-lg transition-colors disabled:opacity-50",children:[b&&g.jsx(Vr,{size:12,className:"animate-spin"}),n("projectDetail.delete")]})]})]})}),g.jsxs("div",{className:"flex items-center justify-between px-8 py-5 border-b border-gray-200 bg-white shrink-0",style:{borderBottomWidth:1},children:[g.jsxs("div",{className:"flex items-center gap-3",children:[g.jsx("button",{onClick:()=>e("/projects"),className:"p-1 text-gray-400 hover:text-gray-700 rounded-lg hover:bg-gray-100 transition-colors","aria-label":n("projectDetail.back"),children:g.jsx(bne,{size:20})}),g.jsxs("div",{className:"flex flex-col gap-1",children:[g.jsx("h1",{className:"text-xl font-semibold text-gray-900 leading-tight",children:i.name}),g.jsx("p",{className:"text-sm text-gray-500 leading-tight",children:i.description||E})]})]}),g.jsxs("div",{className:"flex items-center gap-2",children:[g.jsxs("button",{onClick:()=>x(!0),className:"flex items-center gap-1.5 px-3 py-1.5 text-sm text-red-600 bg-red-50 hover:bg-red-100 rounded-lg transition-colors",children:[g.jsx($y,{size:14}),n("projectDetail.delete")]}),g.jsxs("button",{onClick:()=>e(`/projects/${t}/edit`),className:"flex items-center gap-1.5 px-3 py-1.5 text-sm text-gray-600 bg-gray-100 hover:bg-gray-200 rounded-lg transition-colors",children:[g.jsx(jre,{size:14}),n("projectDetail.edit")]}),g.jsxs("button",{onClick:()=>e(`/?workspace=${encodeURIComponent(t??"")}`),className:"flex items-center gap-1.5 px-3 py-1.5 text-sm text-white bg-blue-500 hover:bg-blue-600 rounded-lg transition-colors",children:[g.jsx(Kr,{size:14}),n("projectDetail.newChat")]})]})]}),g.jsxs("div",{className:"flex flex-1 min-h-0 overflow-hidden",children:[g.jsxs("div",{className:"flex flex-col flex-1 gap-6 p-8 overflow-y-auto border-r border-gray-200",children:[g.jsxs("div",{className:"flex flex-col gap-4",children:[g.jsx("p",{className:"text-base font-semibold text-gray-900",children:n("projectDetail.chatPrompt",{name:i.name})}),g.jsxs("div",{className:"flex items-center gap-3 px-4 py-3 bg-white border border-gray-200 rounded-lg",children:[g.jsx(ane,{size:18,className:"text-gray-400 shrink-0"}),g.jsx("input",{type:"text",value:p,onChange:M=>m(M.target.value),onKeyDown:C,placeholder:n("projectDetail.chatPlaceholder"),className:"flex-1 text-sm text-gray-900 placeholder-gray-400 bg-transparent outline-none"}),g.jsxs("button",{onClick:v,disabled:!p.trim(),className:"flex items-center gap-1.5 px-3 py-1.5 text-sm text-white bg-blue-500 hover:bg-blue-600 disabled:opacity-40 disabled:cursor-not-allowed rounded-lg transition-colors",children:[g.jsx(tie,{size:14}),n("projectDetail.send")]})]}),g.jsxs("div",{className:"flex items-center gap-3",children:[g.jsx("p",{className:"text-xs font-medium text-gray-500 uppercase tracking-wide shrink-0",children:n("projectDetail.assignedAgents")}),i.agents&&i.agents.length>0?g.jsx("div",{className:"flex flex-wrap gap-2",children:i.agents.map(M=>g.jsxs("button",{onClick:()=>e(`/agents/${encodeURIComponent(pk(M))}/edit`),className:"flex items-center gap-2 px-3 py-1.5 bg-white border border-gray-200 rounded-lg hover:bg-gray-50 transition-colors",children:[g.jsx("div",{className:`flex items-center justify-center w-6 h-6 rounded-full text-white text-[10px] font-bold shrink-0 ${X7e(M)}`,children:Z7e(M)}),g.jsx("span",{className:"text-xs font-medium text-gray-700",children:dB(M)})]},M))}):g.jsxs("div",{className:"flex items-center gap-2 text-gray-400",children:[g.jsx(Ka,{size:14}),g.jsx("span",{className:"text-sm",children:n("projectDetail.noAgents")})]})]})]}),g.jsxs("div",{className:"flex flex-col gap-3 flex-1",children:[g.jsx("p",{className:"text-xs font-medium text-gray-500 uppercase tracking-wide",children:n("projectDetail.relatedThreads")}),o.length===0?g.jsxs("div",{className:"flex flex-col items-center justify-center py-10 text-gray-400",children:[g.jsx(vh,{size:32,className:"mb-2"}),g.jsx("p",{className:"text-sm",children:n("projectDetail.noThreads")})]}):g.jsx("div",{className:"flex flex-col gap-2",children:o.map(M=>g.jsxs("button",{onClick:()=>e(`/threads/${encodeURIComponent(M.taskId)}`),className:"flex items-center gap-3 px-4 py-3 bg-white border border-gray-200 rounded-lg hover:bg-gray-50 transition-colors text-left",children:[g.jsx(vh,{size:16,className:"text-gray-400 shrink-0"}),g.jsxs("div",{className:"flex flex-col gap-0.5 flex-1 min-w-0",children:[g.jsx("p",{className:"text-sm font-medium text-gray-900 truncate",children:M.title||n("threads.emptyPrompt")}),g.jsxs("p",{className:"text-xs text-gray-500",children:[M.agentId?dB(M.agentId):n("projectDetail.unknownAgent")," · ",K7e(M.updatedAt,n)]})]}),g.jsx("span",{className:`shrink-0 px-2 py-0.5 text-xs rounded-full font-medium ${Q7e[M.status]??"bg-gray-100 text-gray-600"}`,children:n(`status.${M.status}`,{defaultValue:M.status})})]},M.taskId))})]})]}),g.jsxs("div",{className:"w-80 shrink-0 flex flex-col gap-6 p-6 overflow-y-auto",children:[g.jsxs("div",{className:"flex flex-col gap-2 p-4 bg-white border border-gray-200 rounded-lg",children:[g.jsx("p",{className:"text-xs font-medium text-gray-500 uppercase tracking-wide",children:n("projectDetail.description")}),g.jsx("p",{className:"text-sm text-gray-700 leading-relaxed",children:i.description||n("projectDetail.noDescription")})]}),g.jsxs("div",{className:"flex flex-col gap-2",children:[g.jsx("p",{className:"text-xs font-medium text-gray-500 uppercase tracking-wide",children:n("projectDetail.relatedDocs")}),l.length===0?g.jsx("p",{className:"text-sm text-gray-400",children:n("projectDetail.noDocs")}):g.jsx("div",{className:"flex flex-col gap-2",children:l.map(M=>g.jsxs("button",{onClick:()=>e(`/docs?path=${encodeURIComponent(M.path)}`),className:"flex items-center gap-2 px-3 py-2 bg-white border border-gray-200 rounded-lg",children:[g.jsx(Uo,{size:14,className:"text-gray-400 shrink-0"}),g.jsx("span",{className:"text-sm text-gray-700 truncate",children:M.name})]},M.path))})]})]})]})]})}class tK extends T.Component{constructor(){super(...arguments);pe(this,"state",{hasError:!1})}static getDerivedStateFromError(){return{hasError:!0}}componentDidCatch(n,r){console.error("PageErrorBoundary caught an error",n,r)}render(){return this.state.hasError?this.props.fallback:this.props.children}}const fB="crewx-wfl-banner-dismissed";function eHe(){return g.jsxs("div",{className:"rounded-xl border border-gray-200 bg-white p-5 shadow-sm",children:[g.jsxs("div",{className:"mb-4 flex items-start justify-between gap-3",children:[g.jsxs("div",{className:"flex items-start gap-3",children:[g.jsx("div",{className:"h-10 w-10 animate-pulse rounded-xl bg-gray-100"}),g.jsxs("div",{className:"space-y-2",children:[g.jsx("div",{className:"h-4 w-32 animate-pulse rounded bg-gray-100"}),g.jsx("div",{className:"h-3 w-20 animate-pulse rounded bg-gray-100"})]})]}),g.jsx("div",{className:"h-8 w-24 animate-pulse rounded-md bg-gray-100"})]}),g.jsx("div",{className:"mb-4 h-4 w-full animate-pulse rounded bg-gray-100"}),g.jsxs("div",{className:"mb-4 flex gap-2",children:[g.jsx("div",{className:"h-6 w-20 animate-pulse rounded-full bg-gray-100"}),g.jsx("div",{className:"h-6 w-20 animate-pulse rounded-full bg-gray-100"})]}),g.jsx("div",{className:"h-3 w-40 animate-pulse rounded bg-gray-100"})]})}function tHe({workflow:t,onOpen:e,onStart:n,startLabel:r,startTooltip:i}){const s=t.agents.slice(0,4),o=t.agents.length-s.length;return g.jsxs("div",{role:"button",tabIndex:0,onClick:e,onKeyDown:a=>{(a.key==="Enter"||a.key===" ")&&(a.preventDefault(),e())},className:"flex h-full flex-col rounded-xl border border-gray-200 bg-white p-5 text-left shadow-sm transition-all hover:-translate-y-0.5 hover:border-blue-200 hover:shadow-md",children:[g.jsxs("div",{className:"mb-4 flex items-start justify-between gap-3",children:[g.jsxs("div",{className:"flex min-w-0 items-start gap-3",children:[g.jsx("div",{className:"flex h-10 w-10 shrink-0 items-center justify-center rounded-xl bg-blue-50 text-blue-600",children:g.jsx(wh,{size:18})}),g.jsxs("div",{className:"min-w-0",children:[g.jsx("h3",{className:"truncate text-base font-semibold text-gray-900",children:t.name}),g.jsx("p",{className:"mt-1 text-xs text-gray-500",children:t.id})]})]}),g.jsxs("button",{type:"button",onClick:a=>{a.stopPropagation(),n()},title:i,"aria-label":i,className:"inline-flex shrink-0 items-center gap-1.5 rounded-md bg-blue-500 px-3 py-2 text-xs font-medium text-white transition-colors hover:bg-blue-600",children:[g.jsx(BT,{size:14}),g.jsx("span",{children:r})]})]}),g.jsx("p",{className:"mb-4 truncate text-[13px] text-gray-500",children:t.description||"—"}),g.jsxs("div",{className:"mb-4 flex flex-wrap gap-2",children:[g.jsxs("span",{className:"rounded-full bg-gray-100 px-2.5 py-1 text-xs font-medium text-gray-600",children:["노드 ",t.nodeCount,"개"]}),g.jsxs("span",{className:"rounded-full bg-gray-100 px-2.5 py-1 text-xs font-medium text-gray-600",children:["분기 ",t.branchCount,"개"]})]}),g.jsxs("div",{className:"mt-auto text-xs text-gray-500",children:[s.map(a=>`@${a}`).join(" → "),o>0?` +${o}`:""]})]})}function nHe(){const{t}=me(),e=Nt(),{setPageHeader:n}=ur(),r=nr(k=>k.workflows),i=nr(k=>k.listErrors),s=nr(k=>k.loading),o=nr(k=>k.error),a=nr(k=>k.fetchWorkflows),[l,c]=T.useState(()=>typeof window<"u"&&window.localStorage.getItem(fB)==="true"),[u,h]=T.useState(!1),[f,d]=T.useState("");T.useEffect(()=>{n({title:""}),a().catch(()=>{})},[a,n]);const p=T.useMemo(()=>{const k=f.trim().toLowerCase();return k?r.filter(w=>[w.id,w.name,w.description,...w.agents].filter(v=>!!v).some(v=>v.toLowerCase().includes(k))):r},[f,r]),m=T.useMemo(()=>t("workflow.totalCount",{count:p.length}),[p.length,t]),y=()=>{c(!0),window.localStorage.setItem(fB,"true")},x=async()=>{try{await navigator.clipboard.writeText("workflows/"),h(!0),window.setTimeout(()=>h(!1),1500)}catch{h(!1)}},b=k=>{e(`/threads/new?workflow=${encodeURIComponent(k)}`)};return g.jsx(tK,{fallback:g.jsx("div",{className:"rounded-xl border border-red-200 bg-red-50 px-4 py-3 text-sm text-red-600",children:t("workflow.pageError")}),children:g.jsxs("div",{className:"mx-auto flex max-w-7xl flex-col gap-6",children:[g.jsxs("div",{className:"flex flex-col gap-1",children:[g.jsx("h1",{className:"text-2xl font-semibold text-gray-900",children:t("workflow.title")}),g.jsx("p",{className:"text-sm text-gray-500",children:m})]}),g.jsx("div",{className:"rounded-2xl border border-gray-200 bg-white p-4 shadow-sm",children:g.jsxs("div",{className:"relative",children:[g.jsx(Ya,{size:16,className:"pointer-events-none absolute left-3 top-1/2 -translate-y-1/2 text-gray-400"}),g.jsx("input",{type:"search",value:f,onChange:k=>d(k.target.value),placeholder:t("workflow.searchPlaceholder"),className:`w-full rounded-xl border border-gray-300 py-2.5 pl-10 text-sm text-gray-900 placeholder:text-gray-400 focus:border-blue-500 focus:outline-none focus:ring-2 focus:ring-blue-500 ${f?"pr-10":"pr-4"}`}),f&&g.jsx("button",{type:"button",onClick:()=>d(""),className:"absolute right-3 top-1/2 -translate-y-1/2 rounded-md p-1 text-gray-400 transition-colors hover:bg-gray-100 hover:text-gray-600","aria-label":t("workflow.clearSearch"),children:g.jsx(Xa,{size:16})})]})}),!l&&g.jsxs("div",{className:"flex items-start justify-between gap-4 rounded-xl border border-blue-200 bg-blue-50 px-4 py-4 text-blue-900",children:[g.jsxs("div",{children:[g.jsx("p",{className:"text-sm font-medium",children:t("workflow.bannerTitle")}),g.jsx("p",{className:"mt-1 text-sm text-blue-700",children:t("workflow.bannerBody")})]}),g.jsx("button",{type:"button",onClick:y,className:"rounded-md p-1 text-blue-500 transition-colors hover:bg-blue-100 hover:text-blue-700","aria-label":t("common.close"),children:g.jsx(Xa,{size:16})})]}),i.length>0&&g.jsxs("div",{className:"rounded-xl border border-amber-200 bg-amber-50 px-4 py-4 text-amber-900",children:[g.jsxs("div",{className:"flex items-center gap-2 text-sm font-medium",children:[g.jsx(FT,{size:16}),g.jsx("span",{children:t("workflow.errorsTitle",{count:i.length})})]}),g.jsx("ul",{className:"mt-2 space-y-1 text-sm text-amber-800",children:i.map(k=>g.jsx("li",{children:t("workflow.errorItem",{file:k.file,reason:k.reason})},`${k.file}-${k.reason}`))})]}),o&&!s&&g.jsxs("div",{className:"flex items-center justify-between gap-4 rounded-xl border border-red-200 bg-red-50 px-4 py-4 text-sm text-red-700",children:[g.jsx("span",{children:o}),g.jsx("button",{type:"button",onClick:()=>a(!0).catch(()=>{}),className:"rounded-md bg-white px-3 py-2 font-medium text-red-700 transition-colors hover:bg-red-100",children:t("workflow.retry")})]}),s&&r.length===0?g.jsx("div",{className:"grid grid-cols-1 gap-4 sm:grid-cols-2 xl:grid-cols-3 2xl:grid-cols-4",children:Array.from({length:8},(k,w)=>g.jsx(eHe,{},w))}):r.length===0?g.jsxs("div",{className:"rounded-2xl border border-gray-200 bg-white px-6 py-14 text-center shadow-sm",children:[g.jsx("div",{className:"mx-auto mb-4 flex h-16 w-16 items-center justify-center rounded-full bg-blue-50 text-blue-600",children:g.jsx(wh,{size:28})}),g.jsx("h2",{className:"text-xl font-semibold text-gray-900",children:t("workflow.emptyTitle")}),g.jsx("p",{className:"mt-2 text-sm text-gray-500",children:t("workflow.emptyDescription")}),g.jsx("p",{className:"mt-1 text-sm text-gray-500",children:t("workflow.emptyAction")}),g.jsxs("details",{className:"mx-auto mt-8 max-w-md rounded-xl border border-gray-200 bg-gray-50 px-4 py-3 text-left",children:[g.jsx("summary",{className:"cursor-pointer list-none text-sm font-medium text-gray-700",children:t("workflow.developerTitle")}),g.jsxs("div",{className:"mt-3 flex items-center justify-between gap-3 text-sm text-gray-600",children:[g.jsx("span",{children:t("workflow.developerPathHint")}),g.jsxs("button",{type:"button",onClick:x,className:"inline-flex items-center gap-1 rounded-md border border-gray-200 bg-white px-3 py-1.5 text-xs font-medium text-gray-700 transition-colors hover:bg-gray-100",children:[u?g.jsx(Us,{size:12}):g.jsx(yg,{size:12}),g.jsx("span",{children:t(u?"common.copied":"common.copy")})]})]})]})]}):p.length===0?g.jsxs("div",{className:"rounded-xl border border-dashed border-gray-300 bg-white px-4 py-12 text-center shadow-sm",children:[g.jsx("div",{className:"mx-auto flex h-10 w-10 items-center justify-center rounded-full bg-gray-100 text-gray-400",children:g.jsx(Ya,{size:18})}),g.jsx("h2",{className:"mt-3 text-sm font-semibold text-gray-900",children:t("workflow.emptyFilteredTitle")}),g.jsx("p",{className:"mt-2 text-xs leading-5 text-gray-500",children:t("workflow.emptyFilteredDescription")})]}):g.jsx("div",{className:"grid grid-cols-1 gap-4 sm:grid-cols-2 xl:grid-cols-3 2xl:grid-cols-4",children:p.map(k=>g.jsx(tHe,{workflow:k,onOpen:()=>e(`/workflows/${encodeURIComponent(k.id)}`),onStart:()=>b(k.id),startLabel:t("workflow.startChat"),startTooltip:t("workflow.startChatTooltip",{id:k.id})},k.id))})]})})}function y0({icon:t,label:e,value:n}){return g.jsxs("div",{className:"rounded-xl border border-gray-200 bg-white p-4 shadow-sm",children:[g.jsx("div",{className:"mb-3 flex h-10 w-10 items-center justify-center rounded-xl bg-blue-50 text-blue-600",children:g.jsx(t,{size:18})}),g.jsx("p",{className:"text-xs font-medium uppercase tracking-wide text-gray-400",children:e}),g.jsx("p",{className:"mt-1 text-lg font-semibold text-gray-900",children:n})]})}function rHe({title:t,variables:e}){return g.jsxs("aside",{className:"w-full rounded-2xl border border-gray-200 bg-white p-4 shadow-sm lg:w-[280px] lg:shrink-0",children:[g.jsxs("div",{className:"flex items-center gap-2 text-[13px] font-semibold text-gray-900",children:[g.jsx(zne,{size:14,className:"text-gray-500"}),g.jsx("h2",{children:t})]}),g.jsx("div",{className:"mt-3 border-t border-gray-200 pt-3",children:g.jsx("ul",{className:"space-y-2",children:e.map(n=>g.jsxs("li",{className:"flex items-center gap-2",children:[g.jsx("span",{"aria-hidden":"true",className:"h-1.5 w-1.5 rounded-full bg-gray-300"}),g.jsx("span",{className:"font-mono text-[11px] text-gray-500",children:n})]},n))})})]})}function iHe(){const{t}=me(),e=Nt(),{id:n}=Kh(),{setPageHeader:r}=ur(),i=nr(C=>C.fetchWorkflowDetail),s=nr(C=>C.clearSelectedWorkflow),o=nr(C=>C.selectedWorkflow),a=nr(C=>C.detailLoading),l=nr(C=>C.detailError),[c,u]=T.useState(!1),[h,f]=T.useState(!1),[d,p]=T.useState({svg:null,error:null,isRendering:!1});T.useEffect(()=>{r({title:""})},[r]),T.useEffect(()=>{if(n)return i(n).catch(()=>{}),()=>s()},[s,i,n]);const m=T.useMemo(()=>o!=null&&o.timeout?t("workflow.timeoutMinutes",{count:Math.max(1,Math.round(o.timeout/60))}):t("workflow.noLimit"),[t,o==null?void 0:o.timeout]),y=T.useMemo(()=>o!=null&&o.maxIterations?t("workflow.iterationCount",{count:o.maxIterations}):t("workflow.noLimit"),[t,o==null?void 0:o.maxIterations]),x=T.useMemo(()=>Object.keys((o==null?void 0:o.state)??{}).sort((C,S)=>C.localeCompare(S)),[o==null?void 0:o.state]),b=o?x.length>0?"WFLUI003":"WFLUI002":null,k=x.length>0?"워크플로 상세 State":"워크플로 상세";CF(b,k);const w=()=>{o&&e(`/threads/new?workflow=${encodeURIComponent(o.id)}`)},v=async()=>{if(o)try{await navigator.clipboard.writeText(`workflows/${o.sourceFile}`),f(!0),window.setTimeout(()=>f(!1),1500)}catch{f(!1)}};return g.jsx(tK,{fallback:g.jsx("div",{className:"rounded-xl border border-red-200 bg-red-50 px-4 py-3 text-sm text-red-600",children:t("workflow.pageError")}),children:g.jsxs("div",{className:"mx-auto flex max-w-6xl flex-col gap-6",children:[g.jsxs("button",{type:"button",onClick:()=>e("/workflows"),className:"inline-flex items-center gap-2 self-start text-sm font-medium text-gray-600 transition-colors hover:text-gray-900",children:[g.jsx(LT,{size:16}),g.jsx("span",{children:t("workflow.backToList")})]}),a&&!o?g.jsx("div",{className:"flex min-h-[360px] items-center justify-center rounded-2xl border border-gray-200 bg-white shadow-sm",children:g.jsx(ut,{size:24,className:"animate-spin text-gray-400"})}):l?g.jsxs("div",{className:"flex items-center justify-between gap-4 rounded-xl border border-red-200 bg-red-50 px-4 py-4 text-sm text-red-700",children:[g.jsx("span",{children:l}),n&&g.jsx("button",{type:"button",onClick:()=>i(n,!0).catch(()=>{}),className:"rounded-md bg-white px-3 py-2 font-medium text-red-700 transition-colors hover:bg-red-100",children:t("workflow.retry")})]}):o?g.jsxs(g.Fragment,{children:[g.jsxs("div",{className:"flex flex-col gap-4 rounded-2xl border border-gray-200 bg-white p-6 shadow-sm lg:flex-row lg:items-center lg:justify-between",children:[g.jsx("div",{className:"min-w-0",children:g.jsxs("div",{className:"flex items-center gap-3",children:[g.jsx("div",{className:"flex h-12 w-12 items-center justify-center rounded-xl bg-blue-50 text-blue-600",children:g.jsx(wh,{size:20})}),g.jsxs("div",{className:"min-w-0",children:[g.jsx("h1",{className:"truncate text-2xl font-semibold text-gray-900",children:o.name}),g.jsx("p",{className:"mt-1 text-sm text-gray-500",children:o.id})]})]})}),g.jsxs("button",{type:"button",onClick:w,title:t("workflow.startChatTooltip",{id:o.id}),className:"inline-flex items-center justify-center gap-2 rounded-lg bg-blue-500 px-4 py-3 text-sm font-medium text-white transition-colors hover:bg-blue-600",children:[g.jsx(BT,{size:16}),g.jsx("span",{children:t("workflow.startChat")})]})]}),g.jsxs("div",{className:"flex flex-col gap-4 lg:flex-row lg:items-start",children:[g.jsxs("div",{className:"min-w-0 flex-1 overflow-hidden rounded-2xl border border-gray-200 bg-white shadow-sm",children:[g.jsxs("div",{className:"flex items-center justify-between border-b border-gray-200 px-4 py-3",children:[g.jsx("span",{className:"text-sm font-medium text-gray-500",children:t("workflow.developerPathHint")}),g.jsxs("button",{type:"button",onClick:()=>u(!0),disabled:!d.svg,className:"inline-flex items-center gap-2 rounded-md border border-gray-200 px-3 py-2 text-sm font-medium text-gray-700 transition-colors hover:bg-gray-50 disabled:cursor-not-allowed disabled:opacity-50",children:[g.jsx(Vne,{size:14}),g.jsx("span",{children:t("mermaidFullscreen.expand")})]})]}),g.jsx("div",{className:"min-h-[360px] bg-gray-50 p-6",children:g.jsx(cq,{code:o.mermaid,containerClassName:"relative overflow-auto rounded-xl border border-gray-200 bg-white p-4",diagramClassName:"min-w-[700px] [&_svg]:mx-auto [&_svg]:h-auto [&_svg]:max-w-none [&_svg]:w-full",loadingContent:g.jsxs("div",{className:"flex h-[320px] items-center justify-center text-sm text-gray-500",children:[g.jsx(ut,{size:18,className:"mr-2 animate-spin"}),t("workflow.diagramLoading")]}),errorRenderer:C=>g.jsx("div",{className:"rounded-xl border border-red-200 bg-red-50 px-4 py-3 text-sm text-red-700",children:C||t("workflow.diagramError")}),showExpandButton:!1,fullscreen:c,onFullscreenChange:u,onRenderStateChange:p})})]}),x.length>0?g.jsx(rHe,{title:t("workflow.stateVariablesTitle"),variables:x}):null]}),g.jsxs("div",{className:"rounded-xl border border-gray-200 bg-white px-4 py-4 text-sm text-gray-700 shadow-sm",children:[g.jsx("p",{className:"font-medium text-gray-900",children:t("workflow.developerTitle")}),g.jsx("p",{className:"mt-1 text-gray-500",children:t("workflow.developerPathHint")}),g.jsxs("details",{className:"mt-4 rounded-lg border border-gray-200 bg-gray-50 px-3 py-2 text-gray-900",children:[g.jsx("summary",{className:"cursor-pointer list-none text-sm font-medium",children:t("workflow.developerTitle")}),g.jsxs("div",{className:"mt-3 flex items-center justify-between gap-3 text-sm text-gray-700",children:[g.jsx("span",{children:t("workflow.sourcePath",{path:`workflows/${o.sourceFile}`})}),g.jsxs("button",{type:"button",onClick:v,className:"inline-flex items-center gap-1 rounded-md border border-gray-200 bg-white px-3 py-1.5 text-xs font-medium text-gray-700 transition-colors hover:bg-gray-100",children:[h?g.jsx(Us,{size:12}):g.jsx(yg,{size:12}),g.jsx("span",{children:t(h?"common.copied":"common.copy")})]})]})]})]}),g.jsxs("div",{className:"grid grid-cols-1 gap-4 sm:grid-cols-2 xl:grid-cols-4",children:[g.jsx(y0,{icon:Ka,label:t("workflow.metadataAgents"),value:String(o.agents.length)}),g.jsx(y0,{icon:wh,label:t("workflow.metadataNodes"),value:String(o.nodeCount)}),g.jsx(y0,{icon:gie,label:t("workflow.metadataTimeout"),value:m}),g.jsx(y0,{icon:Kre,label:t("workflow.metadataMaxIterations"),value:y})]})]}):null]})})}function nK(t){return t.map(e=>({name:e.name,path:e.path,type:e.isDirectory??e.type==="dir"?"dir":"file",isDirectory:e.isDirectory??e.type==="dir",children:e.children?nK(e.children):[],hasCrewxYaml:e.hasCrewxYaml,isRegistered:e.isRegistered}))}async function sHe(t,e=3){const n=await fe.getFsTree(t,e);return nK(n)}function oHe(t){for(const e of t){if(!e)continue;const n=/^\/Users\/[^/]+/.exec(e);if(n)return n[0];const r=/^\/home\/[^/]+/.exec(e);if(r)return r[0]}return null}function pB(t,e){return e?t===e?"~":t.startsWith(`${e}/`)?`~${t.slice(e.length)}`:t:t}function aHe(t){const e=t??"/";return[{key:"home",path:e},{key:"git",path:`${e.replace(/\/$/,"")}/git`},{key:"projects",path:`${e.replace(/\/$/,"")}/projects`},{key:"desktop",path:`${e.replace(/\/$/,"")}/Desktop`}]}function T_(t,e){var n;for(const r of t){if(r.path===e)return r;if((n=r.children)!=null&&n.length){const i=T_(r.children,e);if(i)return i}}return null}function lHe(t){if(!(t instanceof Ql)||typeof t.body!="object"||t.body===null)return"UNKNOWN";const e=t.body;if(typeof e.code=="string")return e.code;if(typeof e.error=="object"&&e.error!==null){const n=e.error;if(typeof n.code=="string")return n.code}return"UNKNOWN"}function cHe({open:t,onClose:e,onSelect:n,initialPath:r}){const{t:i}=me(),s=yn(S=>S.currentWorkspace),o=yn(S=>S.workspaces),a=T.useMemo(()=>oHe([r,s==null?void 0:s.workspace_path,...o.map(S=>S.workspace_path)]),[s==null?void 0:s.workspace_path,r,o]),l=T.useMemo(()=>aHe(a),[a]),c=T.useMemo(()=>{var S,E;if(r&&r.startsWith("/")){const M=[...l].sort((A,B)=>B.path.length-A.path.length).find(A=>r===A.path||r.startsWith(`${A.path}/`));return(M==null?void 0:M.path)??r}return((S=l[1])==null?void 0:S.path)??((E=l[0])==null?void 0:E.path)??"/"},[r,l]),[u,h]=T.useState(c),[f,d]=T.useState([]),[p,m]=T.useState(new Set),[y,x]=T.useState(r??null),[b,k]=T.useState(!1),[w,v]=T.useState(null),C=T.useMemo(()=>y?T_(f,y):null,[y,f]);return T.useEffect(()=>{t&&(h(c),x(r??null),m(new Set),v(null))},[c,r,t]),T.useEffect(()=>{if(!t)return;const S=E=>{E.key==="Escape"&&(E.preventDefault(),E.stopPropagation(),e())};return window.addEventListener("keydown",S),()=>window.removeEventListener("keydown",S)},[e,t]),T.useEffect(()=>{if(!t)return;let S=!0;return k(!0),v(null),sHe(u,3).then(E=>{S&&d(E)}).catch(E=>{S&&(d([]),x(null),m(new Set),v(lHe(E)))}).finally(()=>{S&&k(!1)}),()=>{S=!1}},[t,u]),t?g.jsx("div",{"data-testid":"directory-picker-backdrop",className:"fixed inset-0 z-[60] flex items-center justify-center bg-black/40 p-4",onClick:e,children:g.jsxs("div",{role:"dialog","aria-modal":"true","aria-labelledby":"directory-picker-title","data-testid":"directory-picker-dialog",className:"flex h-[70vh] w-full max-w-5xl flex-col overflow-hidden rounded-2xl border border-gray-200 bg-white shadow-xl",onClick:S=>S.stopPropagation(),children:[g.jsxs("div",{className:"flex items-start justify-between gap-4 border-b border-gray-200 px-6 py-5",children:[g.jsxs("div",{children:[g.jsx("h2",{id:"directory-picker-title",className:"text-lg font-semibold text-gray-900",children:i("dirPicker.title")}),g.jsx("p",{className:"mt-1 text-sm text-gray-500",children:i("dirPicker.description")})]}),g.jsx("button",{type:"button",onClick:e,className:"rounded-lg bg-gray-100 px-3 py-2 text-sm font-medium text-gray-700 transition-colors hover:bg-gray-200",children:i("common.close")})]}),g.jsxs("div",{className:"min-h-0 flex flex-1",children:[g.jsxs("aside",{className:"w-48 border-r border-gray-200 bg-gray-50 px-4 py-4",children:[g.jsx("p",{className:"mb-3 text-xs font-semibold uppercase tracking-wide text-gray-500",children:i("dirPicker.quickAccess.title")}),g.jsx("div",{className:"space-y-2",children:l.map(S=>{const E=u===S.path;return g.jsxs("button",{type:"button",onClick:()=>{h(S.path),x(null),m(new Set)},className:`flex w-full items-center justify-between rounded-lg px-3 py-2 text-left text-sm transition-colors ${E?"bg-blue-100 text-blue-700":"text-gray-700 hover:bg-white"}`,children:[g.jsx("span",{children:i(`dirPicker.quickAccess.${S.key}`)}),E?g.jsx(Us,{className:"h-4 w-4"}):null]},S.key)})})]}),g.jsxs("div",{className:"flex min-h-0 flex-1 flex-col px-6 py-5",children:[g.jsxs("div",{className:"mb-4 flex items-center gap-2 rounded-lg border border-gray-200 bg-gray-50 px-3 py-2 text-sm text-gray-600",children:[g.jsx(is,{className:"h-4 w-4 text-gray-400"}),g.jsx("span",{className:"truncate",children:pB(u,a)})]}),g.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto rounded-xl border border-gray-200 bg-white px-3 py-3",children:b?g.jsxs("div",{className:"flex items-center gap-2 px-2 py-2 text-sm text-gray-500",children:[g.jsx(ut,{className:"h-4 w-4 animate-spin"}),g.jsx("span",{children:i("dirPicker.loading")})]}):w?g.jsxs("div",{className:"flex items-start gap-2 rounded-lg border border-red-200 bg-red-50 px-3 py-3 text-sm text-red-700",role:"alert",children:[g.jsx(Rn,{className:"mt-0.5 h-4 w-4 shrink-0"}),g.jsx("span",{children:i(`dirPicker.error.${w}`,{defaultValue:i("dirPicker.error.UNKNOWN")})})]}):f.length===0?g.jsx("div",{className:"px-2 py-2 text-sm text-gray-500",children:i("dirPicker.empty")}):g.jsx(oY,{nodes:f,expandedFolders:p,selectedPath:y,onToggle:S=>{const E=T_(f,S);!E||E.isRegistered||(x(S),m(M=>{const A=new Set(M);return A.has(S)?A.delete(S):A.add(S),A}))},onSelect:S=>x(S),isFileDisabled:S=>S.isRegistered===!0,renderFileSuffix:S=>g.jsxs("span",{className:"ml-2 flex items-center gap-1",children:[S.hasCrewxYaml?g.jsx("span",{className:"rounded bg-blue-100 px-1.5 py-0.5 text-[10px] font-medium text-blue-700",children:i("dirPicker.badge.crewxYaml")}):null,S.isRegistered?g.jsx("span",{className:"rounded bg-gray-200 px-1.5 py-0.5 text-[10px] font-medium text-gray-600",title:i("dirPicker.disabledTooltip"),children:i("dirPicker.alreadyRegistered")}):null]})})}),g.jsxs("div",{className:"mt-4 rounded-lg border border-gray-200 bg-gray-50 px-3 py-3 text-sm text-gray-600",children:[g.jsx("p",{className:"text-xs font-medium uppercase tracking-wide text-gray-400",children:i("dirPicker.selected")}),g.jsx("p",{className:"mt-1 truncate text-sm font-medium text-gray-900",children:y?pB(y,a):i("dirPicker.noneSelected")})]})]})]}),g.jsxs("div",{className:"flex items-center justify-end gap-2 border-t border-gray-200 px-6 py-4",children:[g.jsx("button",{type:"button",onClick:e,className:"rounded-lg bg-gray-100 px-4 py-2 text-sm font-medium text-gray-700 transition-colors hover:bg-gray-200",children:i("dirPicker.cancel")}),g.jsx("button",{type:"button",onClick:()=>{y&&C&&!C.isRegistered&&(n(y),e())},disabled:!y||!C||C.isRegistered===!0,className:"rounded-lg bg-blue-600 px-4 py-2 text-sm font-medium text-white transition-colors hover:bg-blue-700 disabled:cursor-not-allowed disabled:bg-blue-300",children:i("dirPicker.select")})]})]})}):null}const gB=150;function mB(t){return new Promise(e=>{window.setTimeout(e,t)})}function yB(t){return typeof t=="object"&&t!==null}function xB(t){if(!(t instanceof Ql))return"UNKNOWN";if(yB(t.body)){if(typeof t.body.code=="string")return t.body.code;if(yB(t.body.error)&&typeof t.body.error.code=="string")return t.body.error.code}return"UNKNOWN"}function Kv(t,e,n){return e===0?"pending":t<e?"done":t===e?n?"current":"done":"pending"}function Xv({label:t,status:e}){return g.jsxs("div",{className:"flex items-center gap-3 rounded-lg border border-gray-200 bg-white px-4 py-3",children:[e==="done"?g.jsx(dF,{size:18,className:"shrink-0 text-green-600"}):e==="current"?g.jsx(ut,{size:18,className:"shrink-0 animate-spin text-blue-600"}):g.jsx(Nne,{size:18,className:"shrink-0 text-gray-300"}),g.jsx("span",{className:e==="pending"?"text-sm text-gray-400":e==="current"?"text-sm font-medium text-blue-700":"text-sm font-medium text-gray-900",children:t})]})}function bB({open:t,onClose:e}){const{t:n}=me();CF(t?"WKSUI001-NEW":null,"워크스페이스 생성");const r=ul(D=>D.addToast),i=yn(D=>D.createWorkspace),[s,o]=T.useState(""),[a,l]=T.useState(""),[c,u]=T.useState("form"),[h,f]=T.useState(!1),[d,p]=T.useState(null),[m,y]=T.useState(null),[x,b]=T.useState(0),[k,w]=T.useState(null),[v,C]=T.useState(!1);T.useEffect(()=>{t||(o(""),l(""),u("form"),f(!1),p(null),y(null),b(0),w(null),C(!1))},[t]),T.useEffect(()=>{if(!t)return;const D=O=>{O.key!=="Escape"||h||v||(O.preventDefault(),e())};return window.addEventListener("keydown",D),()=>window.removeEventListener("keydown",D)},[e,t,v,h]);const S=T.useMemo(()=>d?n(`workspace.createModal.error.${d}`,{defaultValue:n("workspace.createModal.error.UNKNOWN")}):null,[d,n]),E=h||v,M=[n("workspace.createModal.confirmInit.files.config"),n("workspace.createModal.confirmInit.files.automation"),n("workspace.createModal.confirmInit.files.registration")];if(!t)return null;const A=async()=>{const D=s.trim(),O=a.trim();if(!(!D||h)){f(!0),p(null);try{await i({workspace_path:D,slug:O||void 0,initIfMissing:!1}),r({type:"success",message:n("workspace.createModal.success")}),e()}catch(N){const $=xB(N);if($==="NOT_A_CREWX_WORKSPACE"){y(D),u("confirm-init");return}p($)}finally{f(!1)}}},B=()=>{u("form"),p(null),w(null),b(0)},F=async()=>{var N;const D=m??s.trim(),O=a.trim();if(!(!D||h)){u("initializing"),f(!0),p(null),w(null),b(1);try{const $=await i({workspace_path:D,slug:O||void 0,initIfMissing:!0});b(2),await mB(gB),b(3),f(!1);const I=((N=$.initResult)==null?void 0:N.errors.some(P=>P.startsWith("HOOK_INSTALL_FAILED")))??!1;if(r({type:"success",message:n("workspace.createModal.success")}),I){w(n("workspace.createModal.error.HOOK_INSTALL_FAILED"));return}await mB(gB),e()}catch($){f(!1),u("confirm-init"),b(0),p(xB($))}}},z=()=>S?g.jsxs("div",{className:"rounded-lg border border-red-200 bg-red-50 px-3 py-3 text-sm text-red-700",children:[g.jsx("p",{children:S}),d==="WORKSPACE_LIMIT_EXCEEDED"?g.jsx("a",{href:_p,target:"_blank",rel:"noopener noreferrer",className:"mt-3 inline-flex items-center gap-1 text-sm font-medium text-red-700 transition-colors hover:text-red-800 hover:underline",children:n("upgrade.waitlistCta")}):null]}):null;return g.jsxs("div",{"data-testid":"create-workspace-modal-backdrop",className:"fixed inset-0 z-50 flex items-center justify-center bg-black/40 p-4",onClick:()=>{E||e()},children:[g.jsxs("div",{role:"dialog","aria-modal":"true","aria-labelledby":"create-workspace-modal-title",className:"w-full max-w-lg rounded-2xl border border-gray-200 bg-white shadow-xl",onClick:D=>D.stopPropagation(),children:[g.jsxs("div",{className:"flex items-start justify-between gap-4 border-b border-gray-200 px-6 py-5",children:[g.jsxs("div",{children:[g.jsx("h2",{id:"create-workspace-modal-title",className:"text-lg font-semibold text-gray-900",children:n("workspace.createModal.title")}),g.jsx("p",{className:"mt-1 text-sm text-gray-500",children:n("workspace.createModal.description")})]}),g.jsx("button",{type:"button",onClick:e,disabled:E,className:"rounded-lg bg-gray-100 p-2 text-gray-500 transition-colors hover:bg-gray-200 hover:text-gray-700 disabled:cursor-not-allowed disabled:opacity-50","aria-label":n("common.close"),children:g.jsx(Xa,{size:16})})]}),g.jsxs("div",{className:"space-y-4 px-6 py-5",children:[c==="form"?g.jsxs(g.Fragment,{children:[g.jsxs("div",{children:[g.jsx("label",{htmlFor:"workspace-path",className:"mb-1 block text-sm font-medium text-gray-700",children:n("workspace.createModal.pathLabel")}),g.jsxs("div",{className:"flex gap-2",children:[g.jsx("input",{id:"workspace-path",type:"text",value:s,onChange:D=>{o(D.target.value),p(null)},placeholder:n("workspace.createModal.pathPlaceholder"),className:"min-w-0 flex-1 rounded-lg border border-gray-200 px-3 py-2 text-sm text-gray-900 shadow-sm outline-none transition-colors placeholder:text-gray-400 focus:border-blue-500 focus:ring-2 focus:ring-blue-100"}),g.jsx("button",{type:"button",onClick:()=>C(!0),disabled:h,className:"shrink-0 rounded-lg bg-gray-100 px-4 py-2 text-sm font-medium text-gray-700 transition-colors hover:bg-gray-200 disabled:cursor-not-allowed disabled:opacity-50",children:n("workspace.createModal.browse")})]})]}),g.jsxs("div",{children:[g.jsx("label",{htmlFor:"workspace-slug",className:"mb-1 block text-sm font-medium text-gray-700",children:n("workspace.createModal.slugLabel")}),g.jsx("input",{id:"workspace-slug",type:"text",value:a,onChange:D=>l(D.target.value),placeholder:n("workspace.createModal.slugPlaceholder"),className:"w-full rounded-lg border border-gray-200 px-3 py-2 text-sm text-gray-900 shadow-sm outline-none transition-colors placeholder:text-gray-400 focus:border-blue-500 focus:ring-2 focus:ring-blue-100"})]}),z()]}):null,c==="confirm-init"?g.jsxs(g.Fragment,{children:[g.jsxs("div",{className:"space-y-2",children:[g.jsx("h3",{className:"text-base font-semibold text-gray-900",children:n("workspace.createModal.confirmInit.title")}),g.jsx("p",{className:"text-sm text-gray-600",children:n("workspace.createModal.confirmInit.description")})]}),g.jsxs("div",{className:"rounded-lg border border-gray-200 bg-gray-50 px-4 py-3",children:[g.jsx("p",{className:"text-xs font-medium uppercase tracking-wide text-gray-500",children:n("workspace.createModal.confirmInit.pathLabel")}),g.jsx("p",{className:"mt-1 break-all text-sm text-gray-900",children:m??s.trim()})]}),g.jsxs("div",{className:"rounded-lg border border-gray-200 bg-gray-50 px-4 py-3",children:[g.jsx("p",{className:"text-xs font-medium uppercase tracking-wide text-gray-500",children:n("workspace.createModal.confirmInit.filesLabel")}),g.jsx("ul",{className:"mt-2 space-y-2 text-sm text-gray-700",children:M.map(D=>g.jsx("li",{children:D},D))})]}),z()]}):null,c==="initializing"?g.jsxs(g.Fragment,{children:[g.jsxs("div",{className:"space-y-2",children:[g.jsx("h3",{className:"text-base font-semibold text-gray-900",children:n("workspace.createModal.initProgress.title")}),g.jsx("p",{className:"text-sm text-gray-600",children:n("workspace.createModal.initProgress.description")})]}),g.jsxs("div",{className:"space-y-3 rounded-xl bg-gray-50 p-4",children:[g.jsx(Xv,{label:n("workspace.createModal.initProgress.step1"),status:Kv(1,x,h)}),g.jsx(Xv,{label:n("workspace.createModal.initProgress.step2"),status:Kv(2,x,h)}),g.jsx(Xv,{label:n("workspace.createModal.initProgress.step3"),status:Kv(3,x,h)})]}),k?g.jsx("div",{className:"rounded-lg border border-amber-200 bg-amber-50 px-4 py-3 text-sm text-amber-900",children:g.jsxs("div",{className:"flex items-start gap-3",children:[g.jsx(FT,{size:18,className:"mt-0.5 shrink-0 text-amber-600"}),g.jsxs("div",{className:"space-y-3",children:[g.jsx("p",{children:k}),g.jsx("button",{type:"button",onClick:e,className:"font-medium text-amber-900 underline underline-offset-2",children:n("common.close")})]})]})}):null]}):null]}),c!=="initializing"?g.jsx("div",{className:"flex items-center justify-end gap-2 border-t border-gray-200 px-6 py-4",children:c==="form"?g.jsxs(g.Fragment,{children:[g.jsx("button",{type:"button",onClick:e,disabled:E,className:"rounded-lg bg-gray-100 px-4 py-2 text-sm font-medium text-gray-700 transition-colors hover:bg-gray-200 disabled:cursor-not-allowed disabled:opacity-50",children:n("workspace.createModal.cancel")}),g.jsxs("button",{type:"button",onClick:()=>{A()},disabled:!s.trim()||h,className:"inline-flex items-center gap-2 rounded-lg bg-blue-600 px-4 py-2 text-sm font-medium text-white transition-colors hover:bg-blue-700 disabled:cursor-not-allowed disabled:bg-blue-300",children:[h?g.jsx(ut,{size:14,className:"animate-spin"}):null,n("workspace.createModal.submit")]})]}):g.jsxs(g.Fragment,{children:[g.jsx("button",{type:"button",onClick:B,disabled:h,className:"rounded-lg bg-gray-100 px-4 py-2 text-sm font-medium text-gray-700 transition-colors hover:bg-gray-200 disabled:cursor-not-allowed disabled:opacity-50",children:n("workspace.createModal.confirmInit.back")}),g.jsxs("button",{type:"button",onClick:()=>{F()},disabled:!m||h,className:"inline-flex items-center gap-2 rounded-lg bg-blue-600 px-4 py-2 text-sm font-medium text-white transition-colors hover:bg-blue-700 disabled:cursor-not-allowed disabled:bg-blue-300",children:[h?g.jsx(ut,{size:14,className:"animate-spin"}):null,n("workspace.createModal.confirmInit.confirm")]})]})}):null]}),g.jsx(cHe,{open:v,initialPath:s.trim()||void 0,onClose:()=>C(!1),onSelect:D=>{o(D),p(null)}})]})}function uHe(t){if(!t)return"—";const n=/^\/Users\/([^/]+)(\/.*)?$/.exec(t);return n?`~${n[2]??""}`:t}function hHe(t,e){const n=new Date(t);return Number.isNaN(n.getTime())?t:new Intl.DateTimeFormat(e,{dateStyle:"medium",timeStyle:"short"}).format(n)}function dHe(){const{t,i18n:e}=me(),n=Nt(),{setPageHeader:r}=ur(),[i,s]=T.useState(!1),o=yn(v=>v.workspaces),a=yn(v=>v.currentWorkspace),l=yn(v=>v.loading),c=yn(v=>v.currentLoading),u=yn(v=>v.limitsLoading),h=yn(v=>v.error),f=yn(v=>v.limits),d=yn(v=>v.fetchLimits),p=yn(v=>v.initialize),m=f==null?void 0:f.workspaces,y=m!==void 0&&m!==-1&&o.length>=m,x=u||!f||y,b=y&&f?t("limits.banner.workspace.title",{current:o.length,limit:f.workspaces}):void 0;T.useEffect(()=>{r({title:t("workspace.title"),actions:g.jsxs("button",{type:"button",disabled:x,title:b,onClick:()=>s(!0),className:`inline-flex items-center gap-2 rounded-lg border px-4 py-2 text-sm font-medium transition-colors ${x?"border-gray-200 bg-white text-gray-400":"border-blue-600 bg-blue-600 text-white hover:bg-blue-700"}`,children:[g.jsx(Kr,{size:16}),g.jsx("span",{children:t("workspace.create")})]})})},[b,x,r,t]),T.useEffect(()=>{p().catch(()=>{})},[p]),T.useEffect(()=>{d().catch(()=>{})},[d]);const k=T.useMemo(()=>a,[a]),w=v=>{if(v.id===(k==null?void 0:k.id)){n("/");return}BF(v).then(()=>n("/")).catch(()=>{})};return(l||c)&&o.length===0?g.jsx("div",{className:"rounded-2xl border border-gray-200 bg-white px-6 py-16 text-center text-sm text-gray-500",children:t("workspace.loading")}):h&&o.length===0?g.jsx("div",{className:"rounded-xl border border-amber-200 bg-amber-50 px-4 py-4 text-sm text-amber-800",children:h}):o.length===0?g.jsxs(g.Fragment,{children:[y&&f?g.jsx(f_,{resource:"workspace",current:o.length,limit:f.workspaces}):null,g.jsxs("div",{className:"rounded-2xl border border-dashed border-gray-300 bg-white px-6 py-16 text-center shadow-sm",children:[g.jsx(is,{className:"mx-auto h-10 w-10 text-gray-300"}),g.jsx("h2",{className:"mt-4 text-xl font-semibold text-gray-900",children:t("workspace.emptyTitle")}),g.jsx("p",{className:"mt-2 text-sm text-gray-500",children:t("workspace.emptyDescription")}),g.jsxs("button",{type:"button",disabled:x,title:b,onClick:()=>s(!0),className:`mt-6 inline-flex items-center gap-2 rounded-lg border px-4 py-2 text-sm font-medium transition-colors ${x?"border-gray-200 bg-gray-50 text-gray-400":"border-blue-600 bg-blue-600 text-white hover:bg-blue-700"}`,children:[g.jsx(Kr,{size:16}),g.jsx("span",{children:t("workspace.create")})]})]}),g.jsx(bB,{open:i,onClose:()=>s(!1)})]}):g.jsxs(g.Fragment,{children:[g.jsxs("div",{className:"mx-auto flex max-w-6xl flex-col gap-6",children:[y&&f?g.jsx(f_,{resource:"workspace",current:o.length,limit:f.workspaces}):null,g.jsx("div",{className:"grid grid-cols-1 gap-4 xl:grid-cols-2",children:o.map(v=>{const C=(k==null?void 0:k.id)===v.id;return g.jsxs("button",{type:"button",onClick:()=>w(v),className:`rounded-2xl border px-5 py-5 text-left shadow-sm transition-colors ${C?"border-blue-200 bg-blue-50":"border-gray-200 bg-white hover:border-gray-300 hover:bg-gray-50"}`,children:[g.jsxs("div",{className:"flex items-start justify-between gap-3",children:[g.jsxs("div",{className:"min-w-0",children:[g.jsxs("div",{className:"flex items-center gap-2",children:[g.jsx(is,{size:18,className:C?"text-blue-600":"text-gray-400"}),g.jsx("h2",{className:"truncate text-lg font-semibold text-gray-900",children:v.name})]}),g.jsx("p",{className:"mt-2 truncate text-sm text-gray-500",children:uHe(v.workspace_path)})]}),v.is_current?g.jsx("span",{className:"rounded-full bg-white px-2.5 py-1 text-xs font-medium text-blue-700",children:t("workspace.currentBadge")}):null]}),g.jsxs("div",{className:"mt-5 grid grid-cols-2 gap-3 text-sm",children:[g.jsxs("div",{className:"rounded-xl bg-gray-50 px-3 py-3",children:[g.jsx("p",{className:"text-xs font-medium uppercase tracking-wide text-gray-400",children:t("workspace.slug")}),g.jsx("p",{className:"mt-1 truncate font-medium text-gray-800",children:v.slug})]}),g.jsxs("div",{className:"rounded-xl bg-gray-50 px-3 py-3",children:[g.jsx("p",{className:"text-xs font-medium uppercase tracking-wide text-gray-400",children:t("workspace.updatedAt")}),g.jsx("p",{className:"mt-1 truncate font-medium text-gray-800",children:hHe(v.updated_at,e.language)})]})]})]},v.id)})})]}),g.jsx(bB,{open:i,onClose:()=>s(!1)})]})}function fHe({cli:t,version:e,authenticated:n,selected:r,disabled:i,onToggle:s}){const{t:o}=me(),a=i?"border-gray-200 bg-gray-100":n===!0?"border-green-300 bg-green-50":n===!1?"border-amber-300 bg-amber-50":"border-blue-300 bg-blue-50",l=()=>{i||s(!r)};return g.jsxs("button",{type:"button",onClick:l,disabled:i,className:`w-full flex items-center gap-3 p-4 rounded-lg border-2 transition-colors text-left ${a} ${i?"opacity-60 cursor-not-allowed":"cursor-pointer hover:shadow-sm"}`,children:[g.jsxs("div",{className:"flex-1 min-w-0",children:[g.jsx("div",{className:"font-medium text-gray-900",children:t.displayName}),g.jsx("div",{className:"text-sm text-gray-600 mt-0.5",children:t.installed?g.jsxs(g.Fragment,{children:[g.jsx("span",{children:o("onboarding.s1.statusInstalled",{version:e})}),g.jsx("span",{className:"mx-1.5",children:"·"}),n===!0&&g.jsxs("span",{className:"text-green-600",children:[g.jsx(Us,{className:"inline w-3.5 h-3.5 mr-0.5"}),o("onboarding.s1.authLoggedIn")]}),n===!1&&g.jsxs("span",{className:"text-amber-600",children:[g.jsx(FT,{className:"inline w-3.5 h-3.5 mr-0.5"}),o("onboarding.s1.authRequired")]}),n===null&&g.jsxs("span",{className:"text-blue-600",children:[g.jsx(JC,{className:"inline w-3.5 h-3.5 mr-0.5"}),o("onboarding.s1.authUnknown")]})]}):g.jsx("span",{className:"text-gray-400",children:o("onboarding.s1.statusNotInstalled")})})]}),g.jsx("div",{className:"flex-shrink-0",children:g.jsx("div",{className:`w-5 h-5 rounded border-2 flex items-center justify-center ${r?"bg-blue-500 border-blue-500":"border-gray-300 bg-white"} ${i?"opacity-50":""}`,children:r&&g.jsx(Us,{className:"w-3.5 h-3.5 text-white"})})})]})}function pHe({onNext:t}){const{t:e}=me(),[n,r]=T.useState([]),[i,s]=T.useState(new Set),[o,a]=T.useState(!0),[l,c]=T.useState(!1),u=async()=>{a(!0),c(!1);try{const p=(await fe.getVersions()).filter(x=>x.name!=="crewx"),m=await Promise.all(p.map(async x=>{if(!x.installed)return{...x};try{const b=await fe.check(x.name);return{...x,checkResult:b}}catch{return{...x}}}));r(m);const y=new Set(m.filter(x=>x.installed).map(x=>x.name));s(y)}catch{c(!0)}finally{a(!1)}};T.useEffect(()=>{u()},[]);const h=(d,p)=>{s(m=>{const y=new Set(m);return p?y.add(d):y.delete(d),y})},f=()=>{const d=n.filter(p=>i.has(p.name));t(d)};return o?g.jsxs("div",{className:"flex flex-col items-center gap-3 py-12",children:[g.jsx(ut,{className:"w-8 h-8 animate-spin text-blue-500"}),g.jsx("p",{className:"text-gray-500",children:e("onboarding.s1.loadingCards")})]}):l?g.jsxs("div",{className:"flex flex-col items-center gap-3 py-12",children:[g.jsx("p",{className:"text-gray-900 font-medium",children:e("onboarding.s1.errorTitle")}),g.jsx("p",{className:"text-gray-500",children:e("onboarding.s1.errorDesc")}),g.jsx("button",{type:"button",onClick:u,className:"px-4 py-2 bg-blue-500 text-white rounded-lg hover:bg-blue-600",children:e("onboarding.common.retry")})]}):g.jsxs("div",{className:"space-y-4",children:[n.map(d=>{var p;return g.jsx(fHe,{cli:d,version:d.currentVersion??void 0,authenticated:((p=d.checkResult)==null?void 0:p.authenticated)??null,selected:i.has(d.name),disabled:!d.installed,onToggle:m=>h(d.name,m)},d.name)}),g.jsxs("div",{className:"pt-4",children:[g.jsx("button",{type:"button",onClick:f,disabled:i.size===0,className:"w-full px-6 py-3 bg-blue-500 text-white rounded-lg hover:bg-blue-600 disabled:opacity-50 disabled:cursor-not-allowed font-medium",children:e("onboarding.common.next")}),i.size===0&&g.jsx("p",{className:"text-sm text-amber-600 text-center mt-2",children:e("onboarding.s1.noToolsSelected")})]})]})}const kB=["onboarding.bubble.welcome","onboarding.bubble.tip1","onboarding.bubble.tip2","onboarding.bubble.tip3"];function gHe(){const{t}=me(),[e,n]=T.useState(0);return T.useEffect(()=>{const r=setInterval(()=>{n(i=>(i+1)%kB.length)},5e3);return()=>clearInterval(r)},[]),g.jsxs("div",{className:"fixed top-6 right-6 flex items-start gap-2 z-50",children:[g.jsx("div",{className:"bg-white border border-gray-200 rounded-xl shadow-lg px-4 py-3 max-w-[240px] text-sm text-gray-700",children:t(kB[e])}),g.jsx("div",{className:"w-10 h-10 bg-blue-500 rounded-full flex items-center justify-center flex-shrink-0 shadow-lg",children:g.jsx(BT,{className:"w-5 h-5 text-white"})})]})}function mHe({selectedCLIs:t,onNext:e,onPrev:n}){const{t:r}=me(),[i,s]=T.useState(new Map),[o,a]=T.useState(null),l=t.filter(d=>{var p;return d.name!=="crewx"&&((p=d.checkResult)==null?void 0:p.authenticated)!==!0}),c=l.filter(d=>{var p;return((p=d.checkResult)==null?void 0:p.authenticated)!==null}),u=T.useCallback(async()=>{for(const d of c)if(i.get(d.name)!==!0)try{(await fe.check(d.name)).authenticated===!0&&s(m=>new Map(m).set(d.name,!0))}catch{}},[i,c]);TN(u,{interval:5e3,enabled:c.length>0}),T.useEffect(()=>{l.length===0&&e()},[l.length,e]);const h=c.every(d=>i.get(d.name)===!0),f=async(d,p)=>{await navigator.clipboard.writeText(d),a(p),setTimeout(()=>a(null),2e3)};return l.length===0?null:g.jsxs("div",{className:"space-y-6",children:[g.jsx(gHe,{}),l.map(d=>{var x,b;const p=i.get(d.name)===!0,m=((x=d.checkResult)==null?void 0:x.loginCommand)??"",y=((b=d.checkResult)==null?void 0:b.authenticated)===null||!m;return g.jsxs("div",{className:"bg-white border border-gray-200 rounded-lg p-4 space-y-3",children:[g.jsxs("div",{className:"flex items-center justify-between",children:[g.jsxs("div",{className:"font-medium text-gray-900",children:[d.displayName,g.jsx("span",{className:"ml-2 text-sm text-gray-500",children:r(p?"onboarding.s2.loginComplete":y?"onboarding.s2.manualCheck":"onboarding.s2.loginRequired")})]}),!p&&m&&g.jsx("button",{type:"button",onClick:()=>f(m,d.name),className:"px-3 py-1.5 bg-blue-500 text-white text-sm rounded-lg hover:bg-blue-600",children:r("onboarding.s2.loginButton")}),p&&g.jsxs("span",{className:"text-green-600 font-medium text-sm",children:[g.jsx(Us,{className:"inline w-4 h-4 mr-1"}),r("onboarding.s2.loginComplete")]})]}),!p&&m&&g.jsxs("div",{className:"bg-gray-900 rounded-lg p-3 font-mono text-sm text-gray-100 flex items-center justify-between",children:[g.jsxs("code",{children:["$ ",m]}),g.jsx("button",{type:"button",onClick:()=>f(m,d.name),className:"ml-2 text-gray-400 hover:text-white flex items-center gap-1 text-xs",children:o===d.name?g.jsxs(g.Fragment,{children:[g.jsx(Us,{className:"w-3.5 h-3.5"})," ",r("onboarding.s2.copied")]}):g.jsxs(g.Fragment,{children:[g.jsx(yg,{className:"w-3.5 h-3.5"})," ",r("onboarding.s2.copy")]})})]}),!p&&g.jsx("p",{className:"text-xs text-gray-500",children:r(y?"onboarding.s2.manualCheck":"onboarding.s2.terminalHint")})]},d.name)}),!h&&g.jsxs("div",{className:"flex items-center justify-center gap-2 text-sm text-gray-500",children:[g.jsx(ut,{className:"w-4 h-4 animate-spin"}),r("onboarding.s2.polling")]}),h&&g.jsx("p",{className:"text-center text-green-600 font-medium",children:r("onboarding.s2.allDone")}),g.jsxs("div",{className:"flex gap-3 pt-2",children:[g.jsx("button",{type:"button",onClick:n,className:"flex-1 px-6 py-3 bg-gray-100 text-gray-700 rounded-lg hover:bg-gray-200 font-medium",children:r("onboarding.common.prev")}),g.jsx("button",{type:"button",onClick:e,className:`flex-1 px-6 py-3 rounded-lg font-medium bg-blue-500 text-white hover:bg-blue-600 ${h?"animate-pulse shadow-lg shadow-blue-200":""}`,children:r("onboarding.common.next")})]})]})}function yHe({preset:t,onSelect:e,loading:n}){const{t:r}=me(),i=t.id==="custom";return g.jsxs("div",{className:`rounded-lg p-5 shadow-sm flex flex-col items-center text-center transition-shadow ${i?"bg-blue-50 border-2 border-dashed border-blue-300 hover:shadow-md":"bg-white border border-gray-200 hover:shadow-md"}`,children:[g.jsx("div",{className:`mb-2 flex h-12 w-12 items-center justify-center rounded-full ${i?"bg-white text-blue-500":""}`,children:i?g.jsx(Kr,{className:"h-7 w-7"}):g.jsx("span",{className:"text-3xl",children:t.icon})}),g.jsx("div",{className:"font-semibold text-gray-900 mb-1",children:t.name}),g.jsx("div",{className:"text-sm text-gray-500 mb-1",children:t.description}),g.jsx("div",{className:"text-xs text-gray-400 mb-3",children:r("onboarding.s3.agentCount",{count:t.agentCount})}),g.jsx("button",{type:"button",onClick:()=>e(t.id),disabled:n,className:`w-full px-4 py-2 rounded-lg disabled:opacity-50 disabled:cursor-not-allowed text-sm font-medium ${i?"bg-white text-blue-600 border border-blue-200 hover:bg-blue-100":"bg-blue-500 text-white hover:bg-blue-600"}`,children:n?g.jsxs("span",{className:"flex items-center justify-center gap-2",children:[g.jsx(ut,{className:"w-4 h-4 animate-spin"}),r("onboarding.s3.applying")]}):r(i?"onboarding.s3.customBuild":"onboarding.s3.selectPreset")})]})}function xHe({onPrev:t,onDismissAndExit:e}){const{t:n}=me(),r=Nt(),[i,s]=T.useState([]),[o,a]=T.useState(!0),[l,c]=T.useState(null),[u,h]=T.useState(null),[f,d]=T.useState(!1);T.useEffect(()=>{fe.getOnboardingPresets().then(y=>s(y.presets)).catch(()=>h(n("onboarding.s3.applyError"))).finally(()=>a(!1))},[n]);const p=async y=>{if(y==="custom"){c(y),h(null);try{await e()}catch{h(n("onboarding.common.dismissError"))}finally{c(null)}return}c(y),h(null);try{await fe.applyOnboardingPreset(y),zs("onboarding_step_complete",{step_id:"S3"}),r("/",{replace:!0})}catch(x){x instanceof Error&&x.message.includes("409")?(h(n("onboarding.s3.applyConflict",{count:0})),setTimeout(()=>r("/",{replace:!0}),2e3)):h(n("onboarding.s3.applyError"))}finally{c(null)}},m=async()=>{d(!0),h(null);try{await e(),zs("onboarding_step_complete",{step_id:"S3"})}catch{h(n("onboarding.common.dismissError"))}finally{d(!1)}};return o?g.jsx("div",{className:"flex items-center justify-center py-12",children:g.jsx(ut,{className:"w-8 h-8 animate-spin text-blue-500"})}):g.jsxs("div",{className:"space-y-6",children:[g.jsx("div",{className:"grid grid-cols-2 sm:grid-cols-3 gap-4",children:i.map(y=>g.jsx(yHe,{preset:y,onSelect:p,loading:l===y.id},y.id))}),u&&g.jsx("p",{className:"text-center text-red-500 text-sm",children:u}),g.jsxs("div",{className:"flex gap-3 pt-2",children:[g.jsx("button",{type:"button",onClick:t,className:"flex-1 px-6 py-3 bg-gray-100 text-gray-700 rounded-lg hover:bg-gray-200 font-medium",children:n("onboarding.common.prev")}),g.jsx("button",{type:"button",onClick:m,disabled:f,className:"flex-1 px-6 py-3 bg-blue-500 text-white rounded-lg hover:bg-blue-600 font-medium disabled:opacity-50 disabled:cursor-not-allowed",children:n("onboarding.common.start")})]})]})}const rK=["#step1","#step2","#step3"],bHe=3;function Zv(t){return rK.includes(t)?t:"#step1"}function kHe(t){return rK.indexOf(t)+1}function wHe(){const{t}=me(),e=Nt(),n=cr(),[r,i]=T.useState(()=>Zv(n.hash||"#step1")),[s,o]=T.useState([]),[a,l]=T.useState(!1),[c,u]=T.useState(null);T.useEffect(()=>{const x=Zv(n.hash);i(x),n.hash!==x&&(window.location.hash=x)},[n.hash]),T.useEffect(()=>{const x=()=>{i(Zv(window.location.hash))};return window.addEventListener("hashchange",x),()=>window.removeEventListener("hashchange",x)},[]),T.useEffect(()=>{window.location.hash||(window.location.hash="#step1")},[]);const h=T.useCallback(x=>{window.location.hash=x,i(x)},[]);T.useEffect(()=>{r!=="#step1"&&s.length===0&&h("#step1")},[r,s.length,h]);const f=T.useCallback(async()=>{u(null);try{await fe.dismissOnboarding(),e("/",{replace:!0})}catch{throw u(t("onboarding.common.dismissError")),new Error("dismiss-onboarding-failed")}},[e,t]),d=()=>{f().catch(()=>{})},p=x=>{o(x),zs("onboarding_step_complete",{step_id:"S1"});const b=x.every(k=>{var w;return((w=k.checkResult)==null?void 0:w.authenticated)===!0});l(b),h(b?"#step3":"#step2")},m=a?2:bHe,y=a&&r==="#step3"?2:kHe(r);return g.jsxs("div",{className:"min-h-screen bg-gray-50 flex flex-col",children:[g.jsxs("div",{className:"text-center pt-12 pb-6",children:[g.jsx("p",{className:"text-sm text-gray-500 mb-2",children:t("onboarding.common.stepOf",{current:y,total:m})}),g.jsxs("h1",{className:"text-2xl font-bold text-gray-900",children:[r==="#step1"&&t("onboarding.s1.title"),r==="#step2"&&t("onboarding.s2.title"),r==="#step3"&&t("onboarding.s3.title")]}),r==="#step1"&&g.jsx("p",{className:"text-gray-500 mt-2",children:t("onboarding.s1.subtitle")}),r==="#step3"&&g.jsx("p",{className:"text-gray-500 mt-2",children:t("onboarding.s3.subtitle")})]}),g.jsxs("div",{className:`flex-1 mx-auto w-full px-4 pb-8 ${r==="#step3"?"max-w-4xl":"max-w-lg"}`,children:[r==="#step1"&&g.jsx(pHe,{onNext:p}),r==="#step2"&&s.length>0&&g.jsx(mHe,{selectedCLIs:s,onNext:()=>{zs("onboarding_step_complete",{step_id:"S2"}),h("#step3")},onPrev:()=>h("#step1")}),r==="#step3"&&g.jsx(xHe,{onPrev:()=>h(a?"#step1":"#step2"),onDismissAndExit:f}),g.jsxs("div",{className:"text-center mt-6",children:[c&&g.jsx("p",{className:"mb-3 text-sm text-red-500",children:c}),g.jsx("button",{type:"button",onClick:d,className:"text-sm text-gray-400 hover:text-gray-600 underline",children:t("onboarding.common.skip")})]})]})]})}function vHe(){const[t,e]=T.useState("loading");return T.useEffect(()=>{fe.getOnboardingStatus().then(n=>{e(n.needsOnboarding?"needs":"done")}).catch(()=>{e("done")})},[]),t==="loading"?g.jsx("div",{"data-testid":"onboarding-guard-loading",className:"flex items-center justify-center h-screen bg-gray-50",children:g.jsx(ut,{className:"w-8 h-8 animate-spin text-blue-500"})}):t==="needs"?g.jsx(ef,{to:"/onboarding",replace:!0}):g.jsx(sF,{})}class CHe extends T.Component{constructor(){super(...arguments);pe(this,"state",{hasError:!1})}static getDerivedStateFromError(){return{hasError:!0}}componentDidCatch(n,r){Bie(Pie(n)),console.error("ErrorBoundary caught an error",n,r)}render(){return this.state.hasError?this.props.fallback:this.props.children}}function SHe({routes:t}){const{pathname:e}=cr();return T.useEffect(()=>{var i;const n=vT(t,{pathname:e}),r=(i=n==null?void 0:n.at(-1))==null?void 0:i.route.handle;r!=null&&r.screenId&&(r.manualTracking||vF(r.screenId,r.screenTitle))},[e,t]),null}const _He={success:{container:"border-emerald-200 bg-emerald-50 text-emerald-700",icon:g.jsx(dF,{size:18,className:"shrink-0"})},error:{container:"border-red-200 bg-red-50 text-red-700",icon:g.jsx(Rn,{size:18,className:"shrink-0"})},info:{container:"border-blue-200 bg-blue-50 text-blue-700",icon:g.jsx(IT,{size:18,className:"shrink-0"})}};function THe(){const t=ul(e=>e.toasts);return t.length===0?null:g.jsx("div",{className:"pointer-events-none fixed bottom-6 right-6 z-50 flex w-full max-w-sm flex-col gap-3 px-4 sm:w-auto sm:px-0",children:t.map(e=>{const n=_He[e.type];return g.jsxs("div",{role:e.type==="error"?"alert":"status","aria-live":e.type==="error"?"assertive":"polite",className:`pointer-events-auto flex items-start gap-3 rounded-lg border px-4 py-3 text-sm font-medium shadow-lg ${n.container}`,children:[n.icon,g.jsx("div",{className:"min-w-0 flex-1 leading-5",children:e.message})]},e.id)})})}function EHe(){const{t}=me(),e=$l(o=>o.phase),n=$l(o=>o.targetWorkspace),r=$l(o=>o.error),i=$l(o=>o.clear);if(e==="idle")return null;const s=e==="error";return g.jsx("div",{className:"fixed inset-0 z-[100] flex items-center justify-center bg-gray-950/45 px-4",children:g.jsxs("div",{className:"w-full max-w-md rounded-2xl border border-gray-200 bg-white p-6 shadow-xl",children:[g.jsx("div",{className:`flex h-12 w-12 items-center justify-center rounded-full ${s?"bg-red-50 text-red-500":"bg-blue-50 text-blue-500"}`,children:s?g.jsx(Rn,{size:22}):g.jsx(ut,{size:22,className:"animate-spin"})}),g.jsx("h2",{className:"mt-4 text-lg font-semibold text-gray-900",children:t(s?"workspace.switchErrorTitle":"workspace.switchingTitle")}),g.jsx("p",{className:"mt-2 text-sm text-gray-500",children:s?r||t("workspace.switchErrorDescription"):t("workspace.switchingDescription",{name:(n==null?void 0:n.name)??""})}),s?g.jsx("div",{className:"mt-5",children:g.jsx("button",{type:"button",onClick:i,className:"inline-flex items-center justify-center rounded-lg bg-gray-900 px-4 py-2 text-sm font-medium text-white transition-colors hover:bg-gray-800",children:t("common.close")})}):null]})})}const AHe=T.lazy(()=>et(()=>import("./MarketPage-Dm-3QavD.js"),[],import.meta.url));function $t(t,e,n){return{screenId:t,screenTitle:e,...n}}const iK=fte(g.jsxs(g.Fragment,{children:[g.jsx(pt,{path:"/onboarding",element:g.jsx(wHe,{}),handle:$t("ONBUI001","온보딩 위자드")}),g.jsx(pt,{element:g.jsx(vHe,{}),children:g.jsxs(pt,{element:g.jsx(Bse,{}),children:[g.jsx(pt,{path:"/",element:g.jsx(aB,{}),handle:$t("THDUI000","새 대화")}),g.jsx(pt,{path:"/tasks",element:g.jsx(TFe,{}),handle:$t("TSKUI001","태스크 목록")}),g.jsx(pt,{path:"/tasks/:taskId",element:g.jsx(iFe,{}),handle:$t("TSKUI002","태스크 상세")}),g.jsx(pt,{path:"/threads/new",element:g.jsx(aB,{}),handle:$t("THDUI000","새 대화")}),g.jsx(pt,{path:"/threads",element:g.jsx(I7e,{}),handle:$t("THDUI001","대화 목록")}),g.jsx(pt,{path:"/threads/:threadId",element:g.jsx(j7e,{}),handle:$t("THDUI002","대화창")}),g.jsx(pt,{path:"/workspaces",element:g.jsx(dHe,{}),handle:$t("WKSUI001","워크스페이스 관리")}),g.jsx(pt,{path:"/projects",element:g.jsx(q7e,{}),handle:$t("PJTUI000","프로젝트 목록")}),g.jsx(pt,{path:"/projects/new",element:g.jsx(Y7e,{}),handle:$t("PJTUI002","프로젝트 생성")}),g.jsx(pt,{path:"/projects/:id",element:g.jsx(J7e,{}),handle:$t("PJTUI001","프로젝트 상세")}),g.jsx(pt,{path:"/search",element:g.jsx(A7e,{}),handle:{screenId:"SRCHUI001",screenTitle:"통합 검색"}}),g.jsx(pt,{path:"/docs",element:g.jsx(T7e,{}),handle:$t("DOCUI001","문서 관리")}),g.jsx(pt,{path:"/workflows",element:g.jsx(nHe,{}),handle:$t("WFLUI001","워크플로 목록")}),g.jsx(pt,{path:"/workflows/:id",element:g.jsx(iHe,{}),handle:$t("WFLUI002","워크플로 상세",{manualTracking:!0})}),g.jsx(pt,{path:"/market",element:g.jsx(T.Suspense,{fallback:g.jsx("div",{className:"flex items-center justify-center py-16",children:g.jsx("div",{className:"h-6 w-6 animate-spin rounded-full border-2 border-gray-300 border-t-blue-500"})}),children:g.jsx(AHe,{})}),handle:$t("MKTUI001","마켓")}),g.jsx(pt,{path:"/agents",element:g.jsx(zFe,{}),handle:$t("AGTUI001","에이전트 관리")}),g.jsx(pt,{path:"/agents/new",element:g.jsx(y4,{}),handle:$t("AGTUI002","에이전트 추가/편집")}),g.jsx(pt,{path:"/agents/:agentId/edit",element:g.jsx(y4,{}),handle:$t("AGTUI002","에이전트 추가/편집")}),g.jsx(pt,{path:"/skills",element:g.jsx(ef,{to:"/market",replace:!0})}),g.jsx(pt,{path:"/cli",element:g.jsx(Qse,{}),handle:$t("CLIVUI001","CLI 버전 관리")}),g.jsx(pt,{path:"/usage",element:g.jsx(Zce,{}),handle:$t("USGUI002","Usage 사용량")}),g.jsx(pt,{path:"/memory",element:g.jsx(ef,{to:"/docs",replace:!0}),handle:$t("DOCUI001","문서 관리")}),g.jsx(pt,{path:"/graph",element:g.jsx(ef,{to:"/docs",replace:!0}),handle:$t("DOCUI001","문서 관리")}),g.jsx(pt,{path:"/wbs/*",element:g.jsx(ef,{to:"/",replace:!0}),handle:$t("THDUI000","새 대화")}),g.jsx(pt,{path:"/settings",element:g.jsx(aue,{}),handle:$t("STGUI001","환경 설정")})]})})]}));function NHe(){const{t}=me();return g.jsx("div",{className:"flex min-h-screen items-center justify-center bg-gray-50 px-4",children:g.jsxs("div",{className:"w-full max-w-md rounded-lg border border-red-200 bg-white p-6 text-center shadow-sm",children:[g.jsx("h1",{className:"text-lg font-semibold text-gray-900",children:t("common.somethingWentWrong")}),g.jsx("p",{className:"mt-2 text-sm text-gray-500",children:t("common.tryRefreshingPage")}),g.jsx("button",{type:"button",onClick:()=>window.location.reload(),className:"mt-5 inline-flex items-center justify-center rounded-lg bg-blue-500 px-4 py-2 text-sm font-medium text-white transition-colors hover:bg-blue-600",children:t("common.refresh")})]})})}function MHe(){return Jee(iK)}function LHe(){const t=Pa(e=>e.ui.theme);return T.useEffect(()=>{zse(t)},[t]),g.jsx(Fte,{children:g.jsx(CHe,{fallback:g.jsx(NHe,{}),children:g.jsxs(g.Fragment,{children:[g.jsx(SHe,{routes:iK}),g.jsx(MHe,{}),g.jsx(THe,{}),g.jsx(EHe,{})]})})})}Rie();Qv.createRoot(document.getElementById("root")).render(g.jsx(sr.StrictMode,{children:g.jsx(LHe,{})}));export{q8 as $,zHe as A,ja as B,Bxe as C,Gt as D,p1e as E,hA as F,R8 as G,W_e as H,Gve as I,JCe as J,xbe as K,Op as L,$He as M,I1 as N,Ybe as O,U8 as P,R5 as Q,Fve as R,z2 as S,U_e as T,Sg as U,ps as V,X as W,K as X,n1e as Y,I_e as Z,_,l1e as a,$y as a$,Rve as a0,eO as a1,J5 as a2,XHe as a3,qHe as a4,YHe as a5,GHe as a6,UHe as a7,UE as a8,KHe as a9,iAe as aA,rAe as aB,aEe as aC,S8 as aD,Ive as aE,FHe as aF,R1 as aG,Mx as aH,B7 as aI,ip as aJ,ol as aK,Dg as aL,sEe as aM,iEe as aN,le as aO,In as aP,fe as aQ,me as aR,ur as aS,T as aT,g as aU,Vr as aV,Rn as aW,Ya as aX,ut as aY,hF as aZ,iie as a_,WHe as aa,nu as ab,QHe as ac,ZHe as ad,VHe as ae,DEe as af,GU as ag,uUe as ah,t2e as ai,Sr as aj,Go as ak,Rd as al,dA as am,H7 as an,Sc as ao,V7 as ap,Ue as aq,Ws as ar,we as as,RAe as at,cUe as au,hUe as av,aUe as aw,Te as ax,lUe as ay,cAe as az,a1e as b,uR as b$,Kr as b0,Pg as b1,O3 as b2,gF as b3,xF as b4,o1 as b5,Xa as b6,yg as b7,Yr as b8,Uo as b9,BFe as bA,$E as bB,sa as bC,Bp as bD,G5 as bE,pwe as bF,c_e as bG,R7 as bH,E7 as bI,fSe as bJ,Ex as bK,pSe as bL,Mg as bM,Dl as bN,i_e as bO,bO as bP,$c as bQ,gSe as bR,iA as bS,dSe as bT,xSe as bU,nd as bV,l_e as bW,L_e as bX,CSe as bY,S_e as bZ,nA as b_,oY as ba,pUe as bb,Us as bc,ot as bd,gUe as be,xt as bf,tBe as bg,ire as bh,ore as bi,lre as bj,cne as bk,hre as bl,die as bm,wre as bn,bre as bo,Wre as bp,Rne as bq,fF as br,xg as bs,bie as bt,Vre as bu,NG as bv,eY as bw,_G as bx,EG as by,dN as bz,at as c,_e as c0,G7 as c1,Hr as c2,awe as c3,FE as c4,sz as c5,Eg as c6,lz as c7,HHe as c8,Ixe as c9,td as ca,g_e as cb,rNe as cc,Ng as cd,Nx as ce,dl as cf,M1 as cg,pO as ch,sA as ci,N7 as cj,O7 as ck,uSe as cl,CS as cm,M_e as cn,C_e as co,D_e as cp,rA as cq,R_e as cr,OHe as cs,et as ct,Xe as d,W8 as e,bn as f,u1e as g,zo as h,fs as i,n2e as j,_g as k,J as l,W7 as m,jHe as n,fUe as o,h1e as p,d1e as q,dUe as r,c1e as s,e2e as t,Qi as u,QEe as v,G_e as w,JHe as x,xc as y,o1e as z};
|
|
1150
|
+
`?i.slice(0,-1):i};return e.renderer.rules.hardbreak=n(e.renderer.rules.hardbreak),e.renderer.rules.softbreak=n(e.renderer.rules.softbreak),e.renderer.rules.fence=n(e.renderer.rules.fence),e.renderer.rules.code_block=n(e.renderer.rules.code_block),e.renderer.renderToken=n(e.renderer.renderToken.bind(e.renderer)),e}}const s7e=Pt.create({name:"markdownClipboard",addOptions(){return{transformPastedText:!1,transformCopiedText:!1}},addProseMirrorPlugins(){return[new vt({key:new Ct("markdownClipboard"),props:{clipboardTextParser:(t,e,n)=>{if(n||!this.options.transformPastedText)return null;const r=this.editor.storage.markdown.parser.parse(t,{inline:!0});return Do.fromSchema(this.editor.schema).parseSlice(BN(r),{preserveWhitespace:!0,context:e})},clipboardTextSerializer:t=>this.options.transformCopiedText?this.editor.storage.markdown.serializer.serialize(t.content):null}})]}}),o7e=Pt.create({name:"markdown",priority:50,addOptions(){return{html:!0,tightLists:!0,tightListClass:"tight",bulletListMarker:"-",linkify:!1,breaks:!1,transformPastedText:!1,transformCopiedText:!1}},addCommands(){const t=iG.Commands.config.addCommands();return{setContent:(e,n)=>r=>t.setContent(r.editor.storage.markdown.parser.parse(e),n)(r),insertContentAt:(e,n,r)=>i=>t.insertContentAt(e,i.editor.storage.markdown.parser.parse(n,{inline:!0}),r)(i)}},onBeforeCreate(){this.editor.storage.markdown={options:{...this.options},parser:new i7e(this.editor,this.options),serializer:new r7e(this.editor),getMarkdown:()=>this.editor.storage.markdown.serializer.serialize(this.editor.state.doc)},this.editor.options.initialContent=this.editor.options.content,this.editor.options.content=this.editor.storage.markdown.parser.parse(this.editor.options.content)},onCreate(){this.editor.options.content=this.editor.options.initialContent,delete this.editor.options.initialContent},addStorage(){return{}},addExtensions(){return[l9e.configure({tight:this.options.tightLists,tightClass:this.options.tightListClass}),s7e.configure({transformPastedText:this.options.transformPastedText,transformCopiedText:this.options.transformCopiedText})]}});function a7e({editor:t,readOnly:e=!1,toolbarExtras:n}){const{t:r}=me(),i=T.useMemo(()=>[{key:"headings",buttons:[{key:"h1",label:r("markdownEditor.toolbar.h1"),icon:ire,shortcut:"Cmd+Alt+1",action:o=>{o.chain().focus().toggleHeading({level:1}).run()},isActive:o=>o.isActive("heading",{level:1})},{key:"h2",label:r("markdownEditor.toolbar.h2"),icon:ore,shortcut:"Cmd+Alt+2",action:o=>{o.chain().focus().toggleHeading({level:2}).run()},isActive:o=>o.isActive("heading",{level:2})},{key:"h3",label:r("markdownEditor.toolbar.h3"),icon:lre,shortcut:"Cmd+Alt+3",action:o=>{o.chain().focus().toggleHeading({level:3}).run()},isActive:o=>o.isActive("heading",{level:3})}]},{key:"text",buttons:[{key:"bold",label:r("markdownEditor.toolbar.bold"),icon:cne,shortcut:"Cmd+B",action:o=>{o.chain().focus().toggleBold().run()},isActive:o=>o.isActive("bold")},{key:"italic",label:r("markdownEditor.toolbar.italic"),icon:hre,shortcut:"Cmd+I",action:o=>{o.chain().focus().toggleItalic().run()},isActive:o=>o.isActive("italic")},{key:"strike",label:r("markdownEditor.toolbar.strike"),icon:die,shortcut:"Cmd+Shift+S",action:o=>{o.chain().focus().toggleStrike().run()},isActive:o=>o.isActive("strike")}]},{key:"lists",buttons:[{key:"bulletList",label:r("markdownEditor.toolbar.bulletList"),icon:wre,shortcut:"Cmd+Shift+8",action:o=>{o.chain().focus().toggleBulletList().run()},isActive:o=>o.isActive("bulletList")},{key:"orderedList",label:r("markdownEditor.toolbar.orderedList"),icon:bre,shortcut:"Cmd+Shift+7",action:o=>{o.chain().focus().toggleOrderedList().run()},isActive:o=>o.isActive("orderedList")},{key:"blockquote",label:r("markdownEditor.toolbar.blockquote"),icon:Wre,shortcut:"Cmd+Shift+B",action:o=>{o.chain().focus().toggleBlockquote().run()},isActive:o=>o.isActive("blockquote")}]},{key:"code",buttons:[{key:"code",label:r("markdownEditor.toolbar.code"),icon:Rne,shortcut:"Cmd+E",action:o=>{o.chain().focus().toggleCode().run()},isActive:o=>o.isActive("code")},{key:"codeBlock",label:r("markdownEditor.toolbar.codeBlock"),icon:fF,shortcut:"Cmd+Alt+C",action:o=>{o.chain().focus().toggleCodeBlock().run()},isActive:o=>o.isActive("codeBlock")},{key:"horizontalRule",label:r("markdownEditor.toolbar.horizontalRule"),icon:xg,shortcut:"Cmd+Alt+-",action:o=>{o.chain().focus().setHorizontalRule().run()}}]},{key:"history",buttons:[{key:"undo",label:r("markdownEditor.toolbar.undo"),icon:bie,shortcut:"Cmd+Z",action:o=>{o.chain().focus().undo().run()},isDisabled:o=>!o.can().chain().focus().undo().run()},{key:"redo",label:r("markdownEditor.toolbar.redo"),icon:Vre,shortcut:"Cmd+Shift+Z",action:o=>{o.chain().focus().redo().run()},isDisabled:o=>!o.can().chain().focus().redo().run()}]}],[r]),s=EG({editor:t,selector:({editor:o})=>o?{active:{h1:o.isActive("heading",{level:1}),h2:o.isActive("heading",{level:2}),h3:o.isActive("heading",{level:3}),bold:o.isActive("bold"),italic:o.isActive("italic"),strike:o.isActive("strike"),bulletList:o.isActive("bulletList"),orderedList:o.isActive("orderedList"),blockquote:o.isActive("blockquote"),code:o.isActive("code"),codeBlock:o.isActive("codeBlock")},disabled:{undo:!o.can().chain().focus().undo().run(),redo:!o.can().chain().focus().redo().run()}}:{active:{},disabled:{}}});return g.jsxs("div",{className:"mb-4 flex flex-wrap items-center gap-2 rounded-xl border border-gray-200 bg-white p-2 shadow-sm",children:[i.map((o,a)=>g.jsxs("div",{className:"flex items-center gap-1",children:[a>0?g.jsx("div",{className:"mx-1 h-6 border-l border-gray-300","aria-hidden":"true"}):null,o.buttons.map(l=>{var d;const c=(s==null?void 0:s.active[l.key])??!1,u=!t||e||(((d=l.isDisabled)==null?void 0:d.call(l,t))??!1)||((s==null?void 0:s.disabled[l.key])??!1),h=l.icon,f=`${l.label} (${l.shortcut})`;return g.jsx("button",{type:"button",title:f,"aria-label":f,"data-testid":`markdown-toolbar-${l.key}`,disabled:u,onClick:()=>{t&&!u&&l.action(t)},className:`flex h-8 w-8 items-center justify-center rounded-md transition-colors ${c?"bg-gray-200 text-gray-900":"text-gray-600 hover:bg-gray-100 hover:text-gray-900"} ${u?"cursor-not-allowed opacity-40":""}`,children:g.jsx(h,{className:"h-4 w-4"})},l.key)})]},o.key)),g.jsx("div",{className:"ml-auto flex flex-wrap items-center gap-2",children:n?g.jsxs(g.Fragment,{children:[g.jsx("div",{className:"mx-1 h-6 border-l border-gray-300","aria-hidden":"true"}),n]}):null})]})}const l7e=["[&_h1]:mt-0","[&_h1]:mb-3","[&_h1]:text-2xl","[&_h1]:font-bold","[&_h2]:mt-0","[&_h2]:mb-2","[&_h2]:text-xl","[&_h2]:font-semibold","[&_h3]:mt-0","[&_h3]:mb-2","[&_h3]:text-lg","[&_h3]:font-semibold","[&_p]:my-2","[&_p]:leading-7","[&_ul]:my-2","[&_ol]:my-2","[&_ul]:list-disc","[&_ol]:list-decimal","[&_ul]:pl-6","[&_ol]:pl-6","[&_li]:my-1","[&_blockquote]:my-3","[&_blockquote]:border-l-4","[&_blockquote]:border-gray-300","[&_blockquote]:pl-4","[&_blockquote]:text-gray-600","[&_blockquote]:italic","[&_blockquote_p]:my-0","[&_a]:text-blue-600","[&_a]:underline","[&_hr]:my-4","[&_hr]:border-gray-300","[&_code]:rounded","[&_code]:bg-gray-100","[&_code]:px-1.5","[&_code]:py-0.5","[&_code]:font-mono","[&_code]:text-[13px]","[&_pre]:my-3","[&_pre]:overflow-x-auto","[&_pre]:rounded-lg","[&_pre]:bg-gray-900","[&_pre]:p-4","[&_pre]:text-sm","[&_pre]:text-gray-100","[&_pre_code]:bg-transparent","[&_pre_code]:p-0","[&_pre_code]:text-inherit"].join(" "),c7e=["min-h-[420px]","rounded-xl","border","border-gray-200","bg-white","px-4","py-3","text-sm","text-gray-900","shadow-sm","focus:outline-none","prose","prose-sm","max-w-none",l7e,"[&_.is-editor-empty:first-child::before]:pointer-events-none","[&_.is-editor-empty:first-child::before]:float-left","[&_.is-editor-empty:first-child::before]:h-0","[&_.is-editor-empty:first-child::before]:text-gray-400","[&_.is-editor-empty:first-child::before]:content-[attr(data-placeholder)]"].join(" ");function m0(t){return t.storage.markdown.getMarkdown()}const u7e=T.forwardRef(function({value:e,onChange:n,placeholder:r,readOnly:i=!1,className:s,extensions:o,toolbarExtras:a,editorProps:l},c){const{t:u}=me(),h=T.useRef(null),f=T.useRef(n),d=T.useRef(e);T.useEffect(()=>{f.current=n},[n]),T.useEffect(()=>{d.current=e},[e]);const p=r??u("markdownEditor.placeholder"),m=T.useMemo(()=>[eY.configure({heading:{levels:[1,2,3]}}),_G.configure({placeholder:p}),UG.configure({openOnClick:!1,autolink:!0}),kY.configure({resizable:!1}),bY,xY,yY,o7e.configure({html:!1,linkify:!0,transformPastedText:!0,transformCopiedText:!0}),...o??[]],[o,p]),y=T.useMemo(()=>{const b=(l==null?void 0:l.attributes)??{},k=b.class??"";return{...b,class:[c7e,k].filter(Boolean).join(" "),"data-testid":b["data-testid"]??"markdown-editor-content","aria-label":b["aria-label"]??p,role:b.role??"textbox"}},[l==null?void 0:l.attributes,p]),x=NG({immediatelyRender:!1,editable:!i,extensions:m,content:e,editorProps:{attributes:y},onCreate({editor:b}){const k=m0(b);d.current=k,h.current=k},onUpdate({editor:b}){const k=m0(b);if(k===d.current){h.current=k;return}h.current=k,f.current(k)}},[m]);return T.useEffect(()=>{x&&(x.setEditable(!i),x.setOptions({editorProps:{attributes:y}}))},[x,y,i]),T.useEffect(()=>{!x||m0(x)===e||e===h.current||(x.commands.setContent(e),h.current=e)},[x,e]),T.useImperativeHandle(c,()=>({focus(){x==null||x.chain().focus().run()},selectAll(){x==null||x.chain().focus().selectAll().run()},getMarkdown(){return x?m0(x):""}}),[x]),g.jsxs("section",{className:["flex min-h-0 flex-col rounded-xl border border-gray-200 bg-gray-50 p-4 shadow-sm",s].filter(Boolean).join(" "),children:[g.jsx(a7e,{editor:x,readOnly:i,toolbarExtras:a}),g.jsx("div",{"data-testid":"markdown-editor",className:"min-h-0 flex-1 overflow-auto",children:g.jsx(dN,{editor:x})})]})}),h7e=T.forwardRef(function({path:e,initialContent:n,initialMtime:r,onCancel:i,onSaved:s,onDirtyChange:o},a){const{t:l}=me(),c=T.useRef(null),u=ss(B=>B.saveContent),h=ss(B=>B.selectPath),f=ul(B=>B.addToast),[d,p]=T.useState(n),[m,y]=T.useState(n),[x,b]=T.useState(r),[k,w]=T.useState(!1),[v,C]=T.useState(null),S=d!==m;T.useEffect(()=>{p(n),y(n),b(r),C(null)},[n,r,e]),T.useEffect(()=>{o==null||o(S)},[S,o]),T.useEffect(()=>{var B;(B=c.current)==null||B.focus()},[]);const E=T.useCallback(()=>k||S&&!window.confirm(l("docs.edit.discardConfirm"))?!1:(i(),!0),[S,i,k,l]),M=T.useCallback(async B=>{if(k)return!1;w(!0);try{const F=await u(e,d,B??x);return"error"in F?(C({currentMtime:F.currentMtime}),!1):(y(d),b(F.mtime),C(null),f({type:"success",message:l("docs.edit.savedToast")}),s(),!0)}catch(F){const z=F instanceof Error?F.message:String(F);return f({type:"error",message:l("docs.edit.saveFailed",{message:z})}),!1}finally{w(!1)}},[f,x,d,s,e,u,k,l]),A=T.useCallback(async()=>{w(!0);try{await h(e),C(null)}finally{w(!1)}},[e,h]);return T.useImperativeHandle(a,()=>({save:()=>M(),cancel:E}),[E,M]),T.useEffect(()=>{const B=F=>{(F.metaKey||F.ctrlKey)&&F.key.toLowerCase()==="s"&&(F.preventDefault(),M()),F.key==="Escape"&&(F.preventDefault(),E())};return window.addEventListener("keydown",B),()=>window.removeEventListener("keydown",B)},[E,M]),T.useEffect(()=>{if(!S)return;const B=F=>{F.preventDefault(),F.returnValue=""};return window.addEventListener("beforeunload",B),()=>window.removeEventListener("beforeunload",B)},[S]),g.jsxs(g.Fragment,{children:[g.jsx("div",{className:"flex h-full flex-col overflow-hidden bg-white",children:g.jsx("div",{className:"min-h-0 flex-1 overflow-hidden px-6 py-4",children:g.jsx(u7e,{ref:c,value:d,onChange:p,className:"h-full"})})}),v&&g.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/40 p-4",children:g.jsxs("div",{role:"dialog","aria-modal":"true",className:"w-full max-w-md rounded-2xl border border-gray-200 bg-white shadow-xl",children:[g.jsx("div",{className:"border-b border-gray-200 px-6 py-5",children:g.jsxs("div",{className:"flex items-start gap-3",children:[g.jsx("div",{className:"flex h-10 w-10 shrink-0 items-center justify-center rounded-full bg-amber-100 text-amber-600",children:g.jsx(Rn,{size:18})}),g.jsxs("div",{children:[g.jsx("h2",{className:"text-base font-semibold text-gray-900",children:l("docs.edit.conflict.title")}),g.jsx("p",{className:"mt-1 text-sm text-gray-500",children:l("docs.edit.conflict.message")})]})]})}),g.jsxs("div",{className:"flex items-center justify-end gap-2 px-6 py-4",children:[g.jsx("button",{type:"button",onClick:()=>C(null),disabled:k,className:"rounded-lg bg-gray-100 px-4 py-2 text-sm font-medium text-gray-700 transition-colors hover:bg-gray-200 disabled:cursor-not-allowed disabled:opacity-50",children:l("docs.edit.conflict.dismiss")}),g.jsxs("button",{type:"button",onClick:()=>void A(),disabled:k,className:"rounded-lg bg-blue-100 px-4 py-2 text-sm font-medium text-blue-700 transition-colors hover:bg-blue-200 disabled:cursor-not-allowed disabled:opacity-50",children:[k?g.jsx(Vr,{size:14,className:"mr-1 inline animate-spin"}):null,l("docs.edit.conflict.reload")]}),g.jsxs("button",{type:"button",onClick:()=>void M(v.currentMtime),disabled:k,className:"rounded-lg bg-amber-500 px-4 py-2 text-sm font-medium text-white transition-colors hover:bg-amber-600 disabled:cursor-not-allowed disabled:opacity-50",children:[k?g.jsx(Vr,{size:14,className:"mr-1 inline animate-spin"}):null,l("docs.edit.conflict.overwrite")]})]})]})})]})});function d7e(t){const e=t.split("/").filter(Boolean);return e.slice(0,-1).map((n,r)=>e.slice(0,r+1).join("/"))}function f7e(t){return t.split("/").filter(Boolean).slice(0,-1).join("/")}const p7e=["docs/","skills/"],g7e=new Set(["AGENTS.md","README.md","CLAUDE.md"]),rB="docs-tree-visible";function m7e(t){return/^[a-z][a-z\d+.-]*:/i.test(t)}function Yv(t){const e=[];for(const n of t.split("/"))if(!(!n||n===".")){if(n===".."){e.pop();continue}e.push(n)}return e.join("/")}function iB(t){const e=t.indexOf("#");if(e===-1)return null;const n=t.slice(e+1).trim();return n?decodeURIComponent(n):null}function y7e(t){return g7e.has(t)||p7e.some(e=>t.startsWith(e))}function x7e(t,e){const[n]=e.split("#"),[r]=n.split("?");if(!r)return t;const i=decodeURIComponent(r);if(i.startsWith("/"))return Yv(i.replace(/^\/+/,""));const s=Yv(i);return y7e(s)?s:Yv([f7e(t),i].filter(Boolean).join("/"))}function b7e(t){return t.toLowerCase().replace(/[^\w\s가-힣-]/gu,"").replace(/\s+/g,"-").replace(/^-+|-+$/g,"")}function S_(t){return typeof t=="string"||typeof t=="number"?String(t):Array.isArray(t)?t.map(e=>S_(e)).join(""):T.isValidElement(t)?S_(t.props.children):""}function __(t,e="smooth"){const n=document.getElementById(t);return n?(n.scrollIntoView({behavior:e,block:"start"}),!0):!1}function Qu(t,e,n=!1){return{pathname:"/docs",search:`?path=${encodeURIComponent(t)}`,hash:e?`#${n?encodeURIComponent(e):e}`:""}}function uu(t){return function({children:n,...r}){const i=S_(n).replace(/[✅🔲🗑️🗑⚠️]/gu,"").trim(),s=b7e(i);return T.createElement(t,{id:s,...r},n)}}function k7e({onToggle:t,onSelectPath:e}){const{t:n}=me(),{tree:r,treeLoading:i,treeError:s,fetchTree:o}=ss(),{selectedPath:a,expandedFolders:l,toggleFolder:c}=ss();return T.useEffect(()=>{o()},[o]),g.jsxs("div",{className:"flex h-full w-full min-w-0 flex-col border-r border-gray-200 bg-white",children:[g.jsxs("div",{className:"flex shrink-0 items-center justify-between border-b border-gray-200 px-4 py-3",children:[g.jsx("h2",{className:"text-xs font-semibold uppercase tracking-wide text-gray-400",children:n("docs.fileTree")}),g.jsx("button",{type:"button",onClick:t,"aria-label":n("docs.toggleTree.hide"),className:"rounded-md p-1 text-gray-500 transition-colors hover:bg-gray-100 hover:text-gray-700",children:g.jsx(Bre,{className:"h-4 w-4"})})]}),g.jsx("div",{className:"flex-1 overflow-y-auto py-1",children:i?g.jsx("div",{className:"flex h-32 items-center justify-center",children:g.jsx(ut,{className:"h-5 w-5 animate-spin text-gray-400"})}):s?g.jsx("div",{className:"px-4 py-4 text-sm text-red-500",children:s}):r.length===0?g.jsx("div",{className:"px-4 py-4 text-sm text-gray-400",children:n("docs.noFiles")}):g.jsx(oY,{nodes:r,expandedFolders:l,onToggle:c,onSelect:u=>{e(u)},selectedPath:a})})]})}function w7e({onToggle:t}){const{t:e}=me();return g.jsx("div",{className:"flex h-full w-10 shrink-0 items-start justify-center border-r border-gray-200 bg-white pt-3",children:g.jsx("button",{type:"button",onClick:t,"aria-label":e("docs.toggleTree.show"),className:"rounded-md p-1 text-gray-500 transition-colors hover:bg-gray-100 hover:text-gray-700",children:g.jsx(Fre,{className:"h-4 w-4"})})})}function v7e({path:t,dirty:e=!1}){const{t:n}=me();if(!t)return null;const r=t.split("/").filter(Boolean);return g.jsxs("nav",{className:"flex items-center gap-2 text-sm text-gray-500",children:[r.map((i,s)=>g.jsxs("span",{className:"flex items-center gap-1",children:[s>0&&g.jsx(hs,{className:"h-3.5 w-3.5 text-gray-300"}),g.jsx("span",{className:s===r.length-1?"font-medium text-gray-800":"",children:i})]},s)),e?g.jsx("span",{className:"text-sm font-semibold leading-none text-amber-500","aria-label":n("docs.edit.dirtyMarker"),children:n("docs.edit.dirtyMarker")}):null]})}function C7e(){const t=Nt(),{toc:e,tocLoading:n,selectedPath:r}=ss();return n?g.jsx("div",{className:"flex h-full w-full items-start justify-center border-l border-gray-200 pt-6",children:g.jsx(ut,{className:"h-4 w-4 animate-spin text-gray-400"})}):e.length===0?null:g.jsxs("nav",{className:"h-full w-full overflow-y-auto border-l border-gray-200 py-4 pl-4 pr-2",children:[g.jsx("p",{className:"mb-2 text-xs font-semibold uppercase tracking-wide text-gray-400",children:"Contents"}),g.jsx("ul",{className:"space-y-0.5",children:e.map((i,s)=>g.jsx("li",{children:g.jsx("a",{href:`#${i.anchor}`,onClick:o=>{o.preventDefault(),r&&t(Qu(r,i.anchor),{replace:!0}),__(i.anchor)},style:{paddingLeft:`${(i.level-1)*12}px`},className:"flex items-center gap-1 truncate text-xs text-gray-600 hover:text-blue-600 py-0.5",children:g.jsx("span",{className:"truncate",children:i.text})})},`${i.anchor}-${s}`))})]})}function S7e(){const{t}=me(),e=Nt(),n=cr(),{content:r,contentLoading:i,contentError:s,selectedPath:o,selectPath:a,toc:l}=ss();return T.useEffect(()=>{const c=n.hash?decodeURIComponent(n.hash.slice(1)):null;if(!c||i)return;const u=window.requestAnimationFrame(()=>{__(c)});return()=>window.cancelAnimationFrame(u)},[r,i,n.hash,l]),o?i?g.jsx("div",{className:"flex h-full items-center justify-center",children:g.jsx(ut,{className:"h-6 w-6 animate-spin text-gray-400"})}):s?g.jsx("div",{className:"flex h-full items-center justify-center px-4",children:g.jsx("p",{className:"text-sm text-red-500",children:s})}):g.jsx("div",{className:"prose prose-sm prose-gray max-w-none overflow-y-auto px-6 py-4 h-full",children:g.jsx(mj,{remarkPlugins:[zj],components:{h1:uu("h1"),h2:uu("h2"),h3:uu("h3"),h4:uu("h4"),h5:uu("h5"),h6:uu("h6"),a:({href:c,className:u,onClick:h,...f})=>{if(!c)return g.jsx("a",{className:u,onClick:h,...f});if(/^https?:\/\//i.test(c))return g.jsx("a",{href:c,target:"_blank",rel:"noopener noreferrer",className:u,onClick:h,...f});if(c.startsWith("#")){const y=iB(c),x=b=>{h==null||h(b),!(b.defaultPrevented||!y)&&(b.preventDefault(),e(Qu(o,y),{replace:!0}),__(y))};return g.jsx("a",{href:c,className:u,onClick:x,...f})}if(m7e(c))return g.jsx("a",{href:c,className:u,onClick:h,...f});const d=x7e(o,c),p=iB(c),m=y=>{if(h==null||h(y),y.defaultPrevented||!d)return;y.preventDefault(),a(d);const x=d===o;e(Qu(d,p,!0),{replace:x})};return g.jsx("a",{href:c,className:["cursor-pointer",u].filter(Boolean).join(" "),onClick:m,...f})}},children:r})}):g.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-2 text-gray-400",children:[g.jsx(Uo,{className:"h-10 w-10"}),g.jsx("p",{className:"text-sm",children:t("docs.selectFile")})]})}function _7e({mode:t,dirty:e,canEdit:n,contentForEditing:r,mtime:i,onEdit:s,onSave:o,onCancel:a,onCancelRequest:l,onDirtyChange:c,onSaved:u,editorRef:h}){const{t:f}=me(),{selectedPath:d,toc:p,tocLoading:m}=ss(),y=t==="view"&&(m||p.length>0);return g.jsxs("div",{className:"flex min-w-0 flex-1 flex-col overflow-hidden",children:[g.jsxs("div",{className:"flex shrink-0 items-center justify-between gap-4 border-b border-gray-200 bg-white px-6 py-3",children:[g.jsx(v7e,{path:d,dirty:t==="edit"&&e}),g.jsx("div",{className:"flex items-center gap-2",children:t==="edit"?g.jsxs(g.Fragment,{children:[g.jsxs("button",{type:"button",onClick:o,className:"inline-flex items-center gap-2 rounded-lg bg-blue-500 px-4 py-2 text-sm font-medium text-white transition-colors hover:bg-blue-600",children:[g.jsx(mF,{className:"h-4 w-4"}),f("docs.edit.save")]}),g.jsxs("button",{type:"button",onClick:l,className:"inline-flex items-center gap-2 rounded-lg bg-gray-100 px-4 py-2 text-sm font-medium text-gray-700 transition-colors hover:bg-gray-200",children:[g.jsx(Xa,{className:"h-4 w-4"}),f("docs.edit.cancel")]})]}):g.jsxs("button",{type:"button",onClick:s,disabled:!n,className:"inline-flex items-center gap-2 rounded-lg bg-gray-100 px-4 py-2 text-sm font-medium text-gray-700 transition-colors hover:bg-gray-200 disabled:cursor-not-allowed disabled:opacity-50",children:[g.jsx(PT,{className:"h-4 w-4"}),f("docs.edit.button")]})})]}),g.jsxs("div",{className:"flex min-h-0 flex-1 overflow-hidden",children:[g.jsx("div",{className:"min-w-0 flex-1 overflow-hidden",children:t==="edit"&&d&&i!==null?g.jsx(h7e,{ref:h,path:d,initialContent:r,initialMtime:i,onCancel:a,onSaved:u,onDirtyChange:c}):g.jsx(S7e,{})}),y&&g.jsx(_N,{defaultWidth:208,minWidth:160,maxWidth:320,side:"left",storageKey:"docs-toc-width",children:g.jsx(C7e,{})})]})]})}function T7e(){const{t}=me(),e=Nt(),[n]=mg(),r=n.get("path"),i=T.useRef(null),s=T.useRef(null),[o,a]=T.useState(()=>typeof window>"u"?!0:window.localStorage.getItem(rB)!=="false"),[l,c]=T.useState("view"),[u,h]=T.useState(!1),{tree:f,selectedPath:d,rawContent:p,expandedFolders:m,contentLoading:y,contentError:x,mtime:b,toggleFolder:k,selectPath:w,fetchTree:v}=ss(),C=!!(d&&!y&&!x&&b!==null),S=T.useCallback(()=>{c("view"),h(!1)},[]),E=T.useCallback(A=>{s.current=A},[]),M=T.useCallback(async(A,B=!0)=>{if(!A||A===d){A&&e(Qu(A),{replace:B});return}if(l==="edit"){if(u&&!window.confirm(t("docs.edit.discardConfirm"))){d&&e(Qu(d),{replace:!0});return}S()}await w(A),e(Qu(A),{replace:B})},[u,S,l,e,w,d,t]);return T.useEffect(()=>{v()},[v]),T.useEffect(()=>{typeof window>"u"||window.localStorage.setItem(rB,String(o))},[o]),T.useEffect(()=>{if(!r||f.length===0||i.current===r)return;const A=typeof ss.getState=="function"?ss.getState():{expandedFolders:m,toggleFolder:k},{expandedFolders:B,toggleFolder:F}=A;for(const z of d7e(r))B.has(z)||F(z);i.current=r,d!==r&&M(r,!0)},[m,M,r,d,k,f.length]),g.jsxs("div",{className:"flex h-full flex-col overflow-hidden bg-white",children:[g.jsx("header",{className:"flex h-14 shrink-0 items-center border-b border-gray-200 px-6",children:g.jsx("h1",{className:"text-lg font-semibold text-gray-900",children:t("docs.title")})}),g.jsxs("div",{className:"flex min-h-0 flex-1 overflow-hidden",children:[o?g.jsx(_N,{defaultWidth:260,minWidth:180,maxWidth:400,side:"right",storageKey:"docs-tree-width",children:g.jsx(k7e,{onToggle:()=>a(!1),onSelectPath:A=>M(A,!0)})}):g.jsx(w7e,{onToggle:()=>a(!0)}),g.jsx(_7e,{mode:l,dirty:u,canEdit:C,contentForEditing:p,mtime:b,onEdit:()=>c("edit"),onSave:()=>{var A;(A=s.current)==null||A.save()},onCancel:S,onCancelRequest:()=>{var A;(A=s.current)==null||A.cancel()},onDirtyChange:h,onSaved:S,editorRef:E})]})]})}const E7e=[{key:"all",icon:g.jsx(fre,{size:14}),labelKey:"search.tabAll"},{key:"memory",icon:g.jsx(OT,{size:14}),labelKey:"search.tabMemory"},{key:"docs",icon:g.jsx(Uo,{size:14}),labelKey:"search.tabDocs"}],sB={memory:g.jsx(OT,{size:14,className:"text-purple-500"}),docs:g.jsx(Uo,{size:14,className:"text-blue-500"})};function oB(t){return t.path?t.path:t.filePath?t.filePath:t.source==="docs"&&t.id.startsWith("doc:")?`docs/${t.id.slice(4)}.md`:t.source==="memory"&&t.agent&&t.id?`memory/${t.agent}/entries/${t.id}.md`:null}function A7e(){const{t}=me(),e=Nt(),[n,r]=mg(),i=n.get("q")??"",[s,o]=T.useState(i),[a,l]=T.useState("all"),[c,u]=T.useState([]),[h,f]=T.useState(!1),[d,p]=T.useState(null),[m,y]=T.useState(!1),x=T.useRef(null),b=T.useCallback(async C=>{const S=C.trim();if(S){r({q:S},{replace:!0}),f(!0),p(null),y(!0);try{const E=await fe.searchKnowledge(S);u(E.data)}catch(E){p(E instanceof Error?E.message:"Unknown error"),u([])}finally{f(!1)}}},[r]);T.useEffect(()=>{i&&!m&&b(i)},[]);const k=C=>{C.key==="Enter"&&b(s)},w=T.useCallback(C=>{const S=oB(C);S&&e(`/docs?path=${S}`)},[e]),v=a==="all"?c:c.filter(C=>C.source===a);return g.jsxs("div",{className:"flex flex-col items-center min-h-full py-12 px-4",children:[g.jsx("h1",{className:"text-2xl font-bold text-gray-900 mb-6",children:t("search.title")}),g.jsx("div",{className:"w-full max-w-[720px] relative mb-6",children:g.jsxs("div",{className:"flex items-center gap-2 bg-white border border-gray-300 rounded-xl shadow-sm px-4 py-3 focus-within:border-blue-400 focus-within:ring-2 focus-within:ring-blue-100 transition-all",children:[g.jsx(Ya,{size:18,className:"text-gray-400 shrink-0"}),g.jsx("input",{ref:x,type:"text",value:s,onChange:C=>o(C.target.value),onKeyDown:k,placeholder:t("search.placeholder"),className:"flex-1 text-sm text-gray-900 placeholder-gray-400 outline-none bg-transparent",autoFocus:!0}),g.jsx("button",{onClick:()=>b(s),disabled:h||!s.trim(),className:"px-4 py-1.5 bg-blue-500 text-white text-sm font-medium rounded-lg hover:bg-blue-600 disabled:opacity-50 disabled:cursor-not-allowed transition-colors",children:h?g.jsx(ut,{size:14,className:"animate-spin"}):t("search.searchBtn")})]})}),m&&g.jsx("div",{className:"w-full max-w-[720px] mb-4",children:g.jsx("div",{className:"flex gap-1 border-b border-gray-200",children:E7e.map(C=>g.jsxs("button",{type:"button",onClick:()=>{C.disabled||l(C.key)},disabled:C.disabled,className:`flex items-center gap-1.5 border-b-2 px-4 py-2 text-sm font-medium transition-colors ${C.disabled?"cursor-not-allowed border-transparent text-gray-400 opacity-60":""} ${a===C.key?"border-blue-500 text-blue-600":"border-transparent text-gray-500 hover:text-gray-700"}`,children:[C.icon,t(C.labelKey),C.key!=="all"&&!C.disabled&&g.jsxs("span",{className:"text-xs text-gray-400",children:["(",c.filter(S=>S.source===C.key).length,")"]}),C.key==="all"&&g.jsxs("span",{className:"text-xs text-gray-400",children:["(",c.length,")"]})]},C.key))})}),g.jsxs("div",{className:"w-full max-w-[720px]",children:[d&&g.jsxs("div",{className:"flex items-center gap-2 px-4 py-3 bg-red-50 border border-red-200 rounded-lg text-sm text-red-600",children:[g.jsx(Rn,{size:16}),g.jsx("span",{children:d})]}),h&&g.jsx("div",{className:"flex justify-center py-12",children:g.jsx(ut,{size:24,className:"animate-spin text-gray-400"})}),!h&&m&&!d&&v.length===0&&g.jsx("div",{className:"text-center py-12 text-gray-400 text-sm",children:t("search.noResults")}),!h&&v.length>0&&g.jsx("ul",{className:"space-y-3",children:v.map(C=>{const S=C.source==="docs",E=oB(C),M=!!E;return g.jsx("li",{onClick:M?()=>w(C):void 0,className:`bg-white border border-gray-200 rounded-lg p-4 shadow-sm hover:border-blue-300 transition-colors ${M?"cursor-pointer":""}`,children:g.jsxs("div",{className:"flex items-start gap-3",children:[g.jsx("div",{className:"shrink-0 mt-0.5",children:sB[C.source??"memory"]??sB.memory}),g.jsxs("div",{className:"flex-1 min-w-0",children:[g.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[g.jsx("span",{className:"text-sm font-medium text-gray-900 truncate",children:C.title}),g.jsx("span",{className:"shrink-0 text-xs px-1.5 py-0.5 bg-gray-100 text-gray-500 rounded",children:S?t("search.tabDocs"):C.category})]}),E&&g.jsx("p",{className:"mb-1 text-xs text-gray-400 truncate",children:E}),g.jsx("p",{className:"text-xs text-gray-500 line-clamp-2",children:C.snippet}),g.jsxs("div",{className:"flex items-center gap-2 mt-1.5",children:[!S&&C.agent&&g.jsxs("span",{className:"text-xs text-gray-400",children:["@",C.agent]}),g.jsxs("span",{className:"text-xs text-gray-300",children:["score: ",C.score.toFixed(2)]})]})]})]})},C.id)})}),!m&&g.jsx("div",{className:"text-center py-12 text-gray-400 text-sm",children:t("search.hint")})]})]})}function N7e(){const e=new Date().toISOString().slice(0,10),n=Math.random().toString(36).slice(2,8);return`${e}-${n}`}function aB(){var S;const{t}=me(),e=Nt(),[n]=mg(),{setPageHeader:r}=ur(),i=n.get("workflow"),s=t("threadNew.addAgent").replace(/^\s*\+\s*/,""),o=[{agent:"cto",label:t("threadNew.recommended.codeReview")},{agent:"devlead",label:t("threadNew.recommended.sprintSummary")},{agent:"cpo",label:t("threadNew.recommended.roadmapReview")}],[a,l]=T.useState(""),[c,u]=T.useState(!1),[h,f]=T.useState([]),[d,p]=T.useState(!0),[m,y]=T.useState(!1),x=T.useRef(null),b=T.useRef(!1),k=nr(E=>E.workflows),w=nr(E=>E.loading),v=nr(E=>E.fetchWorkflows);T.useEffect(()=>{r({title:""}),fe.getAgents().then(E=>{f(E.agents),y(!1)}).catch(()=>{f([]),y(!0)}).finally(()=>p(!1))},[r]),T.useEffect(()=>{v().catch(()=>{})},[v]),T.useEffect(()=>{if(!i||w||b.current)return;const E=k.find(M=>M.id===i);if(E){l(M=>`${Q6e(E)}${M}`.trimEnd()+" "),b.current=!0,setTimeout(()=>{var M;return(M=x.current)==null?void 0:M.focus()},0);return}w||(l(M=>M.trim()?`/wf ${i} ${M}`:`/wf ${i} `),b.current=!0,setTimeout(()=>{var M;return(M=x.current)==null?void 0:M.focus()},0))},[i,w,k]);const C=T.useCallback(async(E,M,A="query")=>{var z;const B=E.trim();if(!B||c)return!1;const F=M.trim().replace(/^@+/,"")||((z=h[0])==null?void 0:z.id)||"ui_devlead";u(!0);try{const D=N7e();return await fe.sendMessage(D,B,F,A),zs("thread_create",e2(F)),i&&zs("workflow_run",{workflow_id:i}),e(`/threads/${encodeURIComponent(D)}`),!0}catch{return u(!1),!1}},[h,e,c,i]);return g.jsx("div",{className:"flex h-full min-h-[60vh] flex-col items-center justify-center px-4 py-12 sm:px-8 lg:px-16",children:g.jsxs("div",{className:"w-full max-w-[760px] space-y-8",children:[g.jsxs("div",{className:"flex flex-col gap-4 text-center sm:flex-row sm:items-start sm:justify-between sm:text-left",children:[g.jsxs("div",{className:"flex flex-1 flex-col items-center gap-2 sm:items-start",children:[g.jsx(Ka,{size:32,className:"text-gray-400"}),g.jsx("h2",{className:"text-2xl font-semibold text-gray-900",children:t("threadNew.heading")}),g.jsx("p",{className:"text-sm text-gray-500",children:t("threadNew.subheading")})]}),g.jsxs("button",{onClick:()=>e("/agents/new"),className:"inline-flex items-center gap-2 self-center rounded-lg border border-gray-200 bg-white px-3 py-2 text-sm font-medium text-gray-600 shadow-sm transition-colors hover:border-blue-300 hover:bg-blue-50 hover:text-blue-600 sm:self-start",children:[g.jsx(Kr,{size:16}),g.jsx("span",{children:s})]})]}),m&&!d?g.jsx("div",{className:"text-center text-sm text-red-500",children:t("threadNew.agentsError")}):null,g.jsxs("div",{className:"flex flex-col items-center gap-3",children:[g.jsx("span",{className:"text-sm font-medium text-gray-500",children:t("threadNew.recommendedTitle")}),g.jsx("div",{className:"flex flex-wrap justify-center gap-3",children:o.map(E=>g.jsxs("button",{onClick:()=>{const M=h.find(B=>B.id===E.agent),A=M?`${Z6e(M)}${E.label}`:`@${E.agent} ${E.label}`;l(A),setTimeout(()=>{var B;return(B=x.current)==null?void 0:B.focus()},0)},className:"w-[200px] rounded-lg border border-gray-200 bg-white px-4 py-3 text-left transition-colors hover:border-blue-300 hover:bg-blue-50",children:[g.jsxs("span",{className:"mb-1 block text-xs font-medium text-blue-600",children:["@",E.agent]}),g.jsx("span",{className:"block text-sm font-medium text-gray-900",children:E.label})]},E.agent+E.label))})]}),d?g.jsx("div",{className:"flex h-12 items-center justify-center",children:g.jsx(ut,{size:20,className:"animate-spin text-gray-400"})}):g.jsx(SN,{onSend:C,value:a,onChange:E=>l(E),agents:h,workflows:k,placeholder:t("threadNew.inputPlaceholder"),sendLabel:t("threadNew.send"),multiline:!0,inputRef:x,disabled:c,activeAgent:((S=h[0])==null?void 0:S.id)||"ui_devlead",variant:"standalone"}),h.length===0&&!d?g.jsx("div",{className:"flex justify-center",children:g.jsxs("button",{onClick:()=>e("/agents/new"),className:"inline-flex items-center gap-2 rounded-lg border border-dashed border-gray-300 bg-white px-3 py-2 text-sm font-medium text-gray-500 transition-colors hover:border-blue-300 hover:bg-blue-50 hover:text-blue-600",children:[g.jsx(Kr,{size:16}),g.jsx("span",{children:s})]})}):null]})})}const M7e={cli:"bg-violet-100 text-violet-700",slack:"bg-green-100 text-green-700",react:"bg-cyan-100 text-cyan-700",i18n:"bg-orange-100 text-orange-700"},L7e="bg-gray-100 text-gray-600";function D7e(t){return M7e[t.toLowerCase()]??L7e}function O7e(t){if(!t)return"";const e=new Date(t);if(isNaN(e.getTime()))return t;const n=e.getFullYear(),r=String(e.getMonth()+1).padStart(2,"0"),i=String(e.getDate()).padStart(2,"0");return`${n}-${r}-${i}`}function R7e({thread:t,onUpdateTitle:e}){const n=Nt(),{t:r}=me(),i=ul(D=>D.addToast),s=T.useRef(null),o=T.useRef(!1),[a,l]=T.useState(!1),[c,u]=T.useState(t.title||""),[h,f]=T.useState(!1),{threadId:d,platform:p,messageCount:m,title:y,createdAt:x,tasks:b}=t,k=y||r("threads.emptyPrompt"),w=c.length,v=b.filter(D=>D.status==="running").length,C=Array.from(new Set(b.map(D=>D.agentId).filter(Boolean)));T.useEffect(()=>{a||u(t.title||"")},[a,t.title]),T.useEffect(()=>{if(!a)return;const D=globalThis.requestAnimationFrame(()=>{var O,N;(O=s.current)==null||O.focus(),(N=s.current)==null||N.select()});return()=>globalThis.cancelAnimationFrame(D)},[a]);const S=T.useCallback(()=>{o.current=!0,globalThis.setTimeout(()=>{o.current=!1},0)},[]),E=()=>{a||o.current||n(`/threads/${encodeURIComponent(d)}`)},M=T.useCallback(()=>{u(t.title||""),f(!1),l(!1)},[t.title]),A=T.useCallback(async()=>{S();const D=Sp(c),O=Sp(t.title);if(D===O){M();return}if(!D){i({type:"error",message:r("threads.editEmptyError")}),M();return}try{await e(d,D),f(!1),l(!1)}catch(N){u(t.title||""),f(!1),l(!1),i({type:"error",message:r("threads.editSaveFailed",{message:N instanceof Error?N.message:String(N)})})}},[i,M,e,S,r,t.title,d,c]),B=T.useCallback(D=>{if(D.key==="Escape"){D.preventDefault(),M();return}D.key==="Enter"&&(D.nativeEvent.isComposing||h||(D.preventDefault(),A()))},[M,A,h]),F=T.useCallback(()=>{S(),u(t.title||""),l(!0)},[S,t.title]),z=D=>{D.target!==D.currentTarget||a||(D.key==="Enter"||D.key===" ")&&(D.preventDefault(),E())};return g.jsxs("div",{role:"button",tabIndex:0,onClick:E,onKeyDown:z,className:"w-full text-left bg-white border border-gray-200 rounded-lg shadow-sm hover:border-blue-300 hover:shadow-md transition-all cursor-pointer overflow-hidden",children:[g.jsxs("div",{className:"flex items-start justify-between gap-4 px-4 pt-3 pb-2",children:[g.jsx("div",{className:"min-w-0 flex-1",onClick:D=>D.stopPropagation(),onDoubleClick:D=>{D.stopPropagation(),F()},children:a?g.jsxs("div",{className:"space-y-1",children:[g.jsx("input",{ref:s,value:c,maxLength:zy,onChange:D=>u(D.target.value),onBlur:()=>{A()},onKeyDown:B,onCompositionStart:()=>f(!0),onCompositionEnd:()=>f(!1),"aria-label":r("threads.editAriaLabel"),placeholder:r("threads.editPlaceholder"),className:"w-full rounded-md border border-blue-200 bg-white px-2 py-1 text-sm font-semibold text-gray-900 outline-none transition focus:border-blue-500 focus:ring-2 focus:ring-blue-500/20"}),g.jsxs("div",{className:`text-[11px] ${w>IF?"text-red-500":"text-gray-400"}`,children:[w,"/",zy]})]}):g.jsx("p",{className:"line-clamp-2 cursor-text text-sm font-semibold leading-5 text-gray-900 transition-colors hover:text-blue-600",title:k,children:k})}),v>0&&g.jsxs("span",{className:"inline-flex items-center gap-1.5 px-2 py-0.5 rounded-full text-xs font-medium shrink-0 bg-green-50 text-green-700",children:[g.jsxs("span",{className:"relative flex h-2 w-2",children:[g.jsx("span",{className:"animate-ping absolute inline-flex h-full w-full rounded-full bg-green-400 opacity-75"}),g.jsx("span",{className:"relative inline-flex rounded-full h-2 w-2 bg-green-500"})]}),v>1?r("status.runningWithCount",{count:v}):r("status.running")]})]}),g.jsxs("div",{className:"flex items-center gap-3 px-4 pb-3 flex-wrap",children:[g.jsx("span",{className:"text-xs text-gray-400 shrink-0",children:O7e(x)}),g.jsx("span",{className:`inline-flex items-center px-2 py-0.5 rounded text-xs font-medium shrink-0 ${D7e(p)}`,children:p}),g.jsxs("span",{className:"text-xs text-gray-400 flex items-center gap-1 shrink-0",children:[g.jsx(vh,{size:11}),r("threads.msgCount",{count:m})]}),C.length>0&&g.jsx("span",{className:"text-xs text-gray-400 truncate",children:C.join(", ")})]})]})}function lB({label:t,value:e,options:n,onChange:r}){return g.jsxs("div",{className:"relative",children:[g.jsx("select",{value:e,onChange:i=>r(i.target.value),className:"h-8 pl-3 pr-8 text-xs border border-gray-200 rounded-md bg-white text-gray-700 appearance-none cursor-pointer hover:border-gray-300 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent transition-colors",children:n.map(i=>g.jsx("option",{value:i.value,children:i.value==="all"?t:i.label},i.value))}),g.jsx("span",{className:"pointer-events-none absolute right-2 top-1/2 -translate-y-1/2 text-gray-400 text-xs",children:"▼"})]})}function I7e(){const{t}=me(),{setPageHeader:e}=ur(),n=Nt(),{threads:r,total:i,filters:s,loading:o,error:a,setFilters:l,fetchThreads:c,clearSearch:u,searchThreads:h,searching:f,updateTitle:d}=jT(),p=T.useRef(1),[m,y]=T.useState([]),[x,b]=T.useState(""),k=T.useRef(null),w=m.length<i;T.useEffect(()=>{p.current===1&&y(r)},[r]);const v=T.useCallback(()=>{p.current=1,b(""),u(),c()},[u,c]),C=T.useCallback(F=>{if(b(F),k.current&&clearTimeout(k.current),!F.trim()){u(),c();return}k.current=setTimeout(()=>{h(F.trim())},300)},[u,c,h]);T.useEffect(()=>{e({title:t("threads.title"),actions:g.jsxs("div",{className:"flex items-center gap-2",children:[g.jsxs("div",{className:"relative",children:[g.jsx(Ya,{size:14,className:"absolute left-2.5 top-1/2 -translate-y-1/2 text-gray-400 pointer-events-none"}),g.jsx("input",{type:"text",value:x,onChange:F=>C(F.target.value),placeholder:t("threads.searchPlaceholder"),className:"h-8 pl-8 pr-3 text-xs border border-gray-200 rounded-md bg-white text-gray-700 placeholder-gray-400 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent transition-colors w-48"})]}),g.jsx("button",{onClick:v,className:"p-2 text-gray-500 hover:text-gray-700 hover:bg-gray-100 rounded-lg transition-colors",title:t("threads.refresh"),children:g.jsx(Vr,{size:16,className:f?"animate-spin":""})})]})})},[e,v,C,x,f,t]),T.useEffect(()=>{p.current=1,c()},[c,s]);const S=T.useCallback(async()=>{const F=p.current+1;p.current=F,await c(),y(z=>[...z,...r])},[c,r]),E=[{value:"all",label:t("threads.filterAll")}],M=[{value:"updatedAt_desc",label:t("threads.sortNewest")},{value:"updatedAt_asc",label:t("threads.sortOldest")}],A=F=>{const[z,D]=F.split("_");l({sort:z,order:D})},B=`${s.sort}_${s.order}`;return g.jsxs("div",{className:"flex flex-col gap-5 max-w-4xl",children:[g.jsxs("div",{className:"flex items-center gap-3 flex-wrap",children:[g.jsx(lB,{label:`${t("threads.filterPlatform")} ▼`,value:s.platform,options:E,onChange:F=>l({platform:F})}),g.jsx(lB,{label:`${t("threads.sortNewest")}`,value:B,options:M,onChange:A})]}),a&&g.jsxs("div",{className:"flex items-center gap-3 bg-red-50 text-red-700 text-sm rounded-lg px-4 py-3 border border-red-200",children:[g.jsx(Rn,{size:16,className:"shrink-0"}),g.jsx("span",{className:"flex-1",children:a}),g.jsx("button",{onClick:v,className:"shrink-0 px-3 py-1 text-xs bg-red-100 text-red-700 rounded-md hover:bg-red-200 transition-colors",children:t("threads.retry")})]}),o&&m.length===0&&g.jsx("div",{className:"flex items-center justify-center py-12",children:g.jsx(Vr,{size:20,className:"animate-spin text-gray-400"})}),!o||m.length>0?g.jsxs(g.Fragment,{children:[g.jsx("div",{className:"flex flex-col gap-3",children:m.length===0?g.jsxs("div",{className:"flex flex-col items-center justify-center py-16 text-gray-400",children:[g.jsx(Nre,{size:40,className:"mb-3"}),g.jsx("p",{className:"text-sm",children:t("threads.empty")}),g.jsx("p",{className:"text-xs mt-1 text-gray-300",children:t("threads.emptyHint")}),g.jsxs("button",{type:"button",onClick:()=>n("/"),className:"mt-4 flex items-center gap-1.5 rounded-lg bg-blue-500 px-4 py-2 text-sm font-medium text-white transition-colors hover:bg-blue-600",children:[g.jsx(Kr,{size:16}),t("threads.emptyAction")]})]}):m.map(F=>g.jsx(R7e,{thread:F,onUpdateTitle:d},F.threadId))}),w&&!o&&g.jsx("div",{className:"flex justify-center",children:g.jsx("button",{onClick:S,className:"px-6 py-2 text-sm text-gray-600 bg-white border border-gray-200 rounded-lg hover:border-gray-300 hover:bg-gray-50 transition-colors",children:t("threads.loadMore")})}),o&&m.length>0&&g.jsx("div",{className:"flex justify-center py-4",children:g.jsx(Vr,{size:16,className:"animate-spin text-gray-400"})})]}):null]})}function B7e({agentId:t,agentColor:e}){const{t:n}=me();return g.jsxs("div",{className:"flex gap-2.5",children:[g.jsx("div",{className:`w-8 h-8 rounded-full ${e} flex items-center justify-center text-[10px] text-white font-bold shrink-0 mt-1`,title:t,children:t.substring(0,3).toUpperCase()}),g.jsxs("div",{className:"bg-white border border-gray-200 rounded-2xl rounded-tl-sm px-4 py-3 shadow-sm inline-block",children:[g.jsxs("div",{className:"flex items-center gap-1.5 mb-1",children:[g.jsx("span",{className:"w-2 h-2 rounded-full bg-gray-400 animate-dot-bounce"}),g.jsx("span",{className:"w-2 h-2 rounded-full bg-gray-400 animate-dot-bounce [animation-delay:150ms]"}),g.jsx("span",{className:"w-2 h-2 rounded-full bg-gray-400 animate-dot-bounce [animation-delay:300ms]"})]}),g.jsx("span",{className:"text-xs text-gray-400",children:n("taskDetail.thinking")})]})]})}function P7e({box:t}){const{t:e}=me();return g.jsxs("div",{className:"bg-gray-50 border border-gray-200 rounded-lg px-4 py-3 max-w-[85%]",children:[g.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[g.jsx(gF,{size:14,className:"text-gray-400 shrink-0"}),g.jsx("span",{className:"text-xs font-medium text-gray-500",children:e("threadDetail.boxLabel",{count:t.taskCount,tokens:Math.round(t.sourceTokens/1e3)})})]}),g.jsxs("div",{className:"space-y-1 text-sm text-gray-600",children:[t.previewFirst&&g.jsx("p",{className:"truncate",children:t.previewFirst}),t.previewMid&&g.jsx("p",{className:"truncate text-gray-400",children:t.previewMid}),t.previewLast&&g.jsx("p",{className:"truncate",children:t.previewLast})]})]})}function cB(t){const e=["bg-blue-500","bg-green-500","bg-purple-500","bg-orange-500","bg-pink-500","bg-cyan-500"];let n=0;for(let r=0;r<t.length;r++)n=t.charCodeAt(r)+((n<<5)-n);return e[Math.abs(n)%e.length]}function uB(t){return t>=1e3?`${(t/1e3).toFixed(1)}K`:String(t)}function F7e(t){return{id:t.taskId,userId:void 0,text:t.content,timestamp:t.startedAt,isAssistant:!0,metadata:{agent_id:t.agentId},logs:void 0}}function $7e(t){return{id:`${t.taskId}-prompt`,userId:"user",text:t.prompt,timestamp:t.startedAt,isAssistant:!1,metadata:void 0,logs:void 0}}function j7e(){var $e;const{t}=me(),{threadId:e}=Kh(),n=Nt(),r=T.useRef(null),i=T.useRef(null),{setPageHeader:s}=ur(),o=jT(ee=>ee.updateTitle),a=ul(ee=>ee.addToast),[l,c]=T.useState(!1),[u,h]=T.useState(""),[f,d]=T.useState(!1),{title:p,messages:m,meta:y,platform:x,loading:b,error:k,sending:w,polling:v,taskLogs:C,fetchDetail:S,fetchTaskLogs:E,sendMessage:M,stopPolling:A,setOptimisticTitle:B,rollbackTitle:F,reset:z}=RF();T.useEffect(()=>{s({title:"",actions:null})},[s]),T.useEffect(()=>(e&&S(e),()=>{A(),z()}),[e]),T.useEffect(()=>{r.current&&(r.current.scrollTop=r.current.scrollHeight)},[m.length]);const{agents:D,latestStatus:O,latestAgentId:N,runningCount:$,oldestRunningStartedAt:I,totalCost:P,totalInput:L,totalOutput:W}=T.useMemo(()=>{const ee=m.filter(je=>je.type==="task"),ge=ee[ee.length-1],ze=ee.filter(je=>je.status==="running"),ce=ze.length,Ut=ze.reduce((je,Kt)=>Kt.startedAt?je?Kt.startedAt<je?Kt.startedAt:je:Kt.startedAt:je,null);if(y)return{agents:y.agents,latestStatus:(ge==null?void 0:ge.status)??null,latestAgentId:(ge==null?void 0:ge.agentId)??"",runningCount:ce,oldestRunningStartedAt:Ut,totalCost:y.totals.costUsd,totalInput:y.totals.inputTokens,totalOutput:y.totals.outputTokens};const ct=new Set;let ne=null,Ge="";for(const je of m)je.type==="task"&&(je.agentId&&ct.add(je.agentId),ne=je.status,Ge=je.agentId||Ge);return{agents:Array.from(ct),latestStatus:ne,latestAgentId:Ge,runningCount:ce,oldestRunningStartedAt:Ut,totalCost:0,totalInput:0,totalOutput:0}},[m,y]);if(!e)return null;const G=(ee,ge,ze="query")=>{M(ee,ge,ze)},j=($e=m.find(ee=>ee.type==="task"))==null?void 0:$e.prompt,V=p||(j?j.slice(0,30):null)||e.replace(/^\d{4}-\d{2}-\d{2}-/,""),Z=u.length,re=Z>IF?"text-red-500":"text-gray-400";T.useEffect(()=>{l||h(V)},[V,l]),T.useEffect(()=>{if(!l)return;const ee=globalThis.requestAnimationFrame(()=>{var ge,ze;(ge=i.current)==null||ge.focus(),(ze=i.current)==null||ze.select()});return()=>globalThis.cancelAnimationFrame(ee)},[l]);const ve=T.useCallback(()=>{h(V),d(!1),c(!1)},[V]),Ee=T.useCallback(async()=>{if(!e)return;const ee=Sp(u),ge=Sp(V);if(ee===ge){ve();return}if(!ee){a({type:"error",message:t("threads.editEmptyError")}),ve();return}const ze=p;B(ee);try{await o(e,ee),d(!1),c(!1)}catch(ce){F(ze),h(ze||V),d(!1),c(!1),a({type:"error",message:t("threads.editSaveFailed",{message:ce instanceof Error?ce.message:String(ce)})})}},[a,V,ve,F,B,t,e,p,u,o]),qe=T.useCallback(ee=>{if(ee.key==="Escape"){ee.preventDefault(),ve();return}ee.key==="Enter"&&(ee.nativeEvent.isComposing||f||(ee.preventDefault(),Ee()))},[ve,Ee,f]),he=(()=>{const ee=new Map;let ge=null;for(let ze=0;ze<m.length;ze++){const ce=m[ze];ce.type==="task"&&ce.agentId!==ge&&(ee.set(ze,ce.agentId),ge=ce.agentId)}return ee})(),be=D.slice(0,4),Ve=D.length-be.length,te=P>0;return g.jsxs("div",{className:"flex flex-col h-[calc(100vh-3rem)] -m-6 bg-gray-50",children:[g.jsxs("div",{className:"flex items-center px-6 py-3 bg-white border-b border-gray-200 shrink-0",children:[g.jsxs("div",{className:"flex items-center gap-3 min-w-0 flex-1",children:[g.jsxs("button",{onClick:()=>n("/threads"),className:"flex items-center gap-1.5 text-sm text-gray-600 hover:text-gray-900 transition-colors shrink-0",children:[g.jsx(LT,{size:16}),g.jsx("span",{children:t("threadDetail.back")})]}),g.jsx("div",{className:"w-px h-4 bg-gray-200 shrink-0"}),g.jsxs("div",{className:"min-w-0",children:[l?g.jsxs("div",{className:"space-y-1",children:[g.jsx("input",{ref:i,value:u,maxLength:zy,onChange:ee=>h(ee.target.value),onBlur:()=>{Ee()},onKeyDown:qe,onCompositionStart:()=>d(!0),onCompositionEnd:()=>d(!1),"aria-label":t("threads.editAriaLabel"),placeholder:t("threads.editPlaceholder"),className:"w-full rounded-md border border-blue-200 bg-white px-2 py-1 text-base font-semibold text-gray-900 outline-none transition focus:border-blue-500 focus:ring-2 focus:ring-blue-500/20"}),g.jsxs("div",{className:`text-[11px] ${re}`,children:[Z,"/",zy]})]}):g.jsx("h1",{className:"cursor-text text-base font-semibold text-gray-900 transition-colors hover:text-blue-600",onDoubleClick:()=>c(!0),title:V,children:V}),g.jsx("p",{className:"text-[11px] text-gray-500 truncate",children:x??"cli"})]})]}),be.length>0&&g.jsxs("div",{className:"flex items-center -space-x-2 mx-4",children:[be.map(ee=>g.jsx("div",{className:`w-7 h-7 rounded-full ${cB(ee)} flex items-center justify-center text-[9px] text-white font-bold border-2 border-white`,title:ee,children:ee.substring(0,3).toUpperCase()},ee)),Ve>0&&g.jsxs("div",{className:"w-7 h-7 rounded-full bg-gray-200 flex items-center justify-center text-[9px] text-gray-600 font-bold border-2 border-white",children:["+",Ve]})]}),g.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[te&&g.jsxs("div",{className:"flex items-center gap-1.5 text-xs text-gray-500",children:[g.jsx("span",{children:t("taskDetail.costLabel",{cost:P.toFixed(2)})}),g.jsx("span",{className:"text-gray-300",children:"·"}),g.jsx("span",{children:t("taskDetail.tokenUsage",{input:uB(L),output:uB(W)})})]}),$>0&&g.jsx(uq,{status:"running",startedAt:I,runningCount:$})]})]}),g.jsxs("div",{ref:r,className:"flex-1 overflow-y-auto px-8 py-6 space-y-5",children:[b&&g.jsx("div",{className:"flex items-center justify-center py-16",children:g.jsx(ut,{size:24,className:"animate-spin text-gray-500"})}),k&&!b&&g.jsxs("div",{className:"flex items-center gap-3 bg-red-50 text-red-600 text-sm rounded-lg px-4 py-3 border border-red-200",children:[g.jsx(Rn,{size:16,className:"shrink-0"}),g.jsx("span",{children:k})]}),!b&&m.map((ee,ge)=>{var ce,Ut;if(ee.type==="box")return g.jsx(P7e,{box:ee},ee.boxId);const ze=he.get(ge);return g.jsxs(T.Fragment,{children:[ze&&g.jsxs("div",{className:"flex items-center gap-3 py-1",children:[g.jsx("div",{className:"flex-1 h-px bg-gray-200"}),g.jsx("span",{className:"text-xs text-gray-400 shrink-0 select-none",children:t("taskDetail.agentJoined",{agent:ze})}),g.jsx("div",{className:"flex-1 h-px bg-gray-200"})]}),ee.prompt&&g.jsx(OS,{message:$7e(ee),taskStatus:null}),g.jsx(OS,{message:F7e(ee),logs:(ce=C[ee.taskId])==null?void 0:ce.logs,childTasks:(Ut=C[ee.taskId])==null?void 0:Ut.childTasks,taskStatus:ee.status,onRequestLogs:()=>E(ee.taskId)})]},ee.taskId)}),!b&&!k&&!m.some(ee=>ee.type==="task"&&(ee.status==="running"||ee.status==="pending"))&&(O==="running"||O==="pending")&&g.jsx(B7e,{agentId:N||"assistant",agentColor:cB(N||"assistant")}),!b&&!k&&m.length===0&&v&&g.jsxs("div",{className:"flex flex-col items-center justify-center py-16 text-gray-500",children:[g.jsx(ut,{size:24,className:"animate-spin text-blue-400 mb-3"}),g.jsx("p",{className:"text-sm font-medium",children:t("taskDetail.pendingAgent","에이전트 실행 대기 중...")}),g.jsx("p",{className:"text-xs mt-1 text-gray-400",children:t("taskDetail.pendingAgentHint","잠시만 기다려 주세요.")})]}),!b&&!k&&m.length===0&&!v&&g.jsxs("div",{className:"flex flex-col items-center justify-center py-16 text-gray-500",children:[g.jsx("p",{className:"text-sm",children:t("threadDetail.noMessages")}),g.jsx("p",{className:"text-xs mt-1 text-gray-600",children:t("threadDetail.noMessagesHint")})]})]}),g.jsx(SN,{onSend:G,disabled:w,activeAgent:N||void 0,storageKey:e,multiline:!0})]})}function eK(t){return t.trim().replace(/^@+/,"")}function z7e(t){return`@${eK(t)}`}function H7e(t,e){if(!t)return"";const n=Date.now()-new Date(t).getTime(),r=Math.floor(n/6e4);if(r<1)return e("projects.justNow");if(r<60)return e("projects.minutesAgo",{count:r});const i=Math.floor(r/60);if(i<24)return e("projects.hoursAgo",{count:i});const s=Math.floor(i/24);if(s<7)return e("projects.daysAgo",{count:s});const o=Math.floor(s/7);return e("projects.weeksAgo",{count:o})}function U7e({agentId:t}){const e=eK(t),n=e.slice(0,2).toUpperCase(),r=["bg-blue-500","bg-emerald-500","bg-violet-500","bg-amber-500","bg-rose-500","bg-cyan-500"],i=e.split("").reduce((s,o)=>s+o.charCodeAt(0),0)%r.length;return g.jsx("span",{className:`inline-flex items-center justify-center w-6 h-6 rounded-full text-[10px] font-semibold text-white ${r[i]}`,title:e,children:n})}const hB=[{bg:"bg-blue-100",text:"text-blue-600"},{bg:"bg-orange-100",text:"text-orange-500"},{bg:"bg-green-100",text:"text-green-600"},{bg:"bg-purple-100",text:"text-purple-600"},{bg:"bg-pink-100",text:"text-pink-500"},{bg:"bg-cyan-100",text:"text-cyan-600"},{bg:"bg-amber-100",text:"text-amber-600"}];function W7e({project:t,index:e,onDeleted:n}){const r=Nt(),{t:i}=me(),[s,o]=T.useState(!1),a=T.useRef(null),l=hB[e%hB.length];T.useEffect(()=>{if(!s)return;const u=h=>{a.current&&!a.current.contains(h.target)&&o(!1)};return document.addEventListener("mousedown",u),()=>document.removeEventListener("mousedown",u)},[s]);const c=async u=>{if(u.stopPropagation(),o(!1),!!confirm(i("projects.deleteConfirm",{name:t.name})))try{await fe.deleteProject(t.id),n(t.id)}catch{}};return g.jsxs("div",{className:"bg-white border border-gray-200 rounded-lg shadow-sm p-4 cursor-pointer hover:border-blue-300 hover:shadow-md transition-all",onClick:()=>r(`/projects/${t.id}`),children:[g.jsxs("div",{className:"flex items-start gap-3 mb-2",children:[g.jsx("div",{className:`flex-shrink-0 w-9 h-9 ${l.bg} rounded-lg flex items-center justify-center`,children:g.jsx(is,{size:18,className:l.text})}),g.jsxs("div",{className:"flex-1 min-w-0",children:[g.jsx("h3",{className:"text-sm font-semibold text-gray-900 truncate",children:t.name}),t.description&&g.jsx("p",{className:"text-xs text-gray-500 mt-0.5 line-clamp-2",children:t.description})]}),g.jsxs("div",{className:"relative flex-shrink-0",ref:a,children:[g.jsx("button",{type:"button",onClick:u=>{u.stopPropagation(),o(h=>!h)},className:"p-1 rounded-md text-gray-400 hover:text-gray-600 hover:bg-gray-100 transition-colors","aria-label":i("projects.menuAriaLabel"),children:g.jsx(Wne,{size:16})}),s&&g.jsxs("div",{className:"absolute right-0 top-7 z-20 w-28 bg-white border border-gray-200 rounded-lg shadow-lg py-1",children:[g.jsx("button",{type:"button",onClick:u=>{u.stopPropagation(),o(!1),r(`/projects/${t.id}/edit`)},className:"w-full text-left px-3 py-1.5 text-sm text-gray-700 hover:bg-gray-50 transition-colors",children:i("projects.edit")}),g.jsx("button",{type:"button",onClick:c,className:"w-full text-left px-3 py-1.5 text-sm text-red-600 hover:bg-red-50 transition-colors",children:i("projects.delete")})]})]})]}),t.agents.length>0&&g.jsxs("div",{className:"flex items-center gap-1.5 mb-3 flex-wrap",children:[g.jsx("div",{className:"flex -space-x-1",children:t.agents.slice(0,4).map(u=>g.jsx(U7e,{agentId:u.agentId},u.agentId))}),g.jsxs("span",{className:"text-xs text-gray-500",children:[t.agents.slice(0,3).map(u=>z7e(u.agentId)).join(", "),t.agents.length>3&&` +${t.agents.length-3}`]})]}),g.jsxs("div",{className:"flex items-center justify-between text-xs text-gray-400",children:[g.jsxs("div",{className:"flex items-center gap-3",children:[g.jsxs("span",{className:"flex items-center gap-1",children:[g.jsx(vh,{size:12}),i("projects.threadCount",{count:t.threadCount})]}),g.jsxs("span",{className:"flex items-center gap-1",children:[g.jsx(Uo,{size:12}),i("projects.docCount",{count:t.docCount})]})]}),t.lastActivityAt&&g.jsx("span",{children:H7e(t.lastActivityAt,i)})]})]})}function q7e(){const{t}=me(),e=Nt(),{setPageHeader:n}=ur(),[r,i]=T.useState([]),[s,o]=T.useState(!0),[a,l]=T.useState(null),c=T.useCallback(async()=>{o(!0),l(null);try{const h=await fe.getProjects();i(h.data??[])}catch(h){l(h instanceof Error?h.message:t("projects.loadError"))}finally{o(!1)}},[t]),u=T.useCallback(h=>{i(f=>f.filter(d=>d.id!==h))},[]);return T.useEffect(()=>{const h=!s&&!a&&r.length>0?t("projects.totalCount",{count:r.length}):void 0;n({title:t("projects.title"),subtitle:h,actions:g.jsxs("button",{onClick:()=>e("/projects/new"),className:"flex items-center gap-1.5 px-3 py-1.5 text-sm bg-blue-500 text-white hover:bg-blue-600 rounded-lg transition-colors",children:[g.jsx(Kr,{size:16}),t("projects.newProject")]})})},[n,e,t,r.length,s,a]),T.useEffect(()=>{c()},[c]),g.jsxs("div",{className:"h-full flex flex-col",children:[a&&g.jsxs("div",{className:"flex items-center gap-3 bg-red-50 text-red-700 text-sm rounded-lg px-4 py-3 border border-red-200 mb-4",children:[g.jsx(Rn,{size:16,className:"shrink-0"}),g.jsx("span",{className:"flex-1",children:a}),g.jsx("button",{onClick:c,className:"shrink-0 px-3 py-1 text-xs bg-red-100 text-red-700 rounded-md hover:bg-red-200 transition-colors",children:t("projects.retry")})]}),s&&g.jsx("div",{className:"flex items-center justify-center py-16",children:g.jsx(Vr,{size:20,className:"animate-spin text-gray-400"})}),!s&&!a&&r.length===0&&g.jsxs("div",{className:"flex flex-col items-center justify-center py-20 text-gray-400",children:[g.jsx(is,{size:48,className:"mb-4 text-gray-300"}),g.jsx("p",{className:"text-sm font-medium text-gray-500 mb-1",children:t("projects.emptyTitle")}),g.jsx("p",{className:"text-xs text-gray-400 mb-4",children:t("projects.emptyDesc")}),g.jsxs("button",{onClick:()=>e("/projects/new"),className:"flex items-center gap-1.5 px-4 py-2 text-sm bg-blue-500 text-white hover:bg-blue-600 rounded-lg transition-colors",children:[g.jsx(Kr,{size:16}),t("projects.newProject")]})]}),!s&&!a&&r.length>0&&g.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:r.map((h,f)=>g.jsx(W7e,{project:h,index:f,onDeleted:u},h.id))})]})}function V7e({agent:t,onRemove:e}){const n=["bg-blue-100 text-blue-700","bg-emerald-100 text-emerald-700","bg-violet-100 text-violet-700","bg-amber-100 text-amber-700","bg-rose-100 text-rose-700","bg-cyan-100 text-cyan-700"],r=t.id.split("").reduce((i,s)=>i+s.charCodeAt(0),0)%n.length;return g.jsxs("span",{className:`inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-xs font-medium ${n[r]}`,children:["@",t.id,g.jsx("button",{type:"button",onClick:i=>{i.stopPropagation(),e()},className:"hover:opacity-70 transition-opacity","aria-label":`Remove ${t.id}`,children:g.jsx(Xa,{size:10})})]})}function G7e({value:t,onChange:e}){const{t:n}=me(),[r,i]=T.useState([]),[s,o]=T.useState(!0),[a,l]=T.useState(null),[c,u]=T.useState(!1),h=T.useRef(null);T.useEffect(()=>{fe.getAgents().then(m=>i(m.agents??[])).catch(()=>l(n("project.agentsError"))).finally(()=>o(!1))},[n]),T.useEffect(()=>{function m(y){h.current&&!h.current.contains(y.target)&&u(!1)}return document.addEventListener("mousedown",m),()=>document.removeEventListener("mousedown",m)},[]);const f=r.filter(m=>t.includes(m.id)),d=r.filter(m=>!t.includes(m.id));function p(m){t.includes(m)?e(t.filter(y=>y!==m)):e([...t,m])}return g.jsxs("div",{ref:h,className:"relative",children:[g.jsxs("div",{role:"combobox","aria-expanded":c,"aria-haspopup":"listbox",onClick:()=>!s&&!a&&u(m=>!m),className:`min-h-[38px] w-full flex items-center flex-wrap gap-1.5 px-3 py-2 rounded-lg border border-gray-200 bg-white text-sm cursor-pointer select-none transition-colors hover:border-gray-300 focus-within:border-blue-400 ${s||a?"opacity-60 cursor-not-allowed":""}`,children:[a?g.jsxs("span",{className:"flex items-center gap-1.5 text-red-500 text-xs",children:[g.jsx(Rn,{size:14}),a]}):s?g.jsx("span",{className:"text-gray-400",children:n("common.loading","Loading...")}):f.length===0?g.jsx("span",{className:"text-gray-400",children:n("project.fieldAgentPlaceholder")}):f.map(m=>g.jsx(V7e,{agent:m,onRemove:()=>p(m.id)},m.id)),g.jsx(Yr,{size:16,className:`ml-auto shrink-0 text-gray-400 transition-transform ${c?"rotate-180":""}`})]}),c&&!s&&!a&&g.jsx("div",{className:"absolute z-50 mt-1 w-full rounded-lg border border-gray-200 bg-white shadow-lg max-h-56 overflow-y-auto",children:r.length===0?g.jsx("div",{className:"px-4 py-3 text-sm text-gray-400 text-center",children:n("project.noAgentsAvailable")}):g.jsxs(g.Fragment,{children:[d.length===0&&t.length>0&&g.jsx("div",{className:"px-4 py-2 text-xs text-gray-400",children:n("project.allAgentsSelected")}),r.map(m=>{const y=t.includes(m.id);return g.jsxs("button",{type:"button",role:"option","aria-selected":y,onClick:()=>p(m.id),className:"w-full flex items-center gap-3 px-4 py-2.5 text-sm text-left hover:bg-gray-50 transition-colors",children:[g.jsxs("div",{className:"flex-1 min-w-0",children:[g.jsxs("div",{className:"font-medium text-gray-900 truncate",children:["@",m.id]}),m.role&&g.jsx("div",{className:"text-xs text-gray-500 truncate",children:m.role})]}),y&&g.jsx(Us,{size:16,className:"shrink-0 text-blue-500"})]},m.id)})]})})]})}function Y7e(){const t=Nt(),{id:e}=Kh(),{t:n}=me(),r=!!e,[i,s]=T.useState(""),[o,a]=T.useState(""),[l,c]=T.useState([]),[u,h]=T.useState(""),[f,d]=T.useState(!1),[p,m]=T.useState(""),[y,x]=T.useState(!1),b=T.useCallback(async()=>{if(e){x(!0),m("");try{const w=await fe.getProject(e);s(w.name??""),a(w.description??"")}catch(w){m(w instanceof Error?w.message:n("project.loadError"))}finally{x(!1)}}},[e,n]);T.useEffect(()=>{b()},[b]);const k=async()=>{if(!i.trim()){h(n("project.nameRequired"));return}h(""),m(""),d(!0);try{const w=r&&e?await fe.updateProject(e,{name:i.trim(),description:o.trim()||void 0}):await fe.createProject({name:i.trim(),description:o.trim()||void 0,agentIds:l.length>0?l:void 0});w.id?t(`/projects/${w.id}`):m(n(r?"project.updateError":"project.createError"))}catch{m(n(r?"project.updateError":"project.createError"))}finally{d(!1)}};return g.jsxs("div",{className:"flex flex-col h-full bg-gray-50",children:[g.jsxs("div",{className:"flex items-center justify-between bg-white border-b border-gray-200",style:{padding:"20px 32px"},children:[g.jsxs("div",{className:"flex flex-col gap-0.5",children:[g.jsx("h1",{className:"text-xl font-semibold text-gray-900",children:n(r?"project.editTitle":"project.newTitle")}),g.jsx("p",{className:"text-sm text-gray-500",children:n(r?"project.editSubtitle":"project.newSubtitle")})]}),g.jsxs("div",{className:"flex items-center gap-2",children:[g.jsx("button",{type:"button",onClick:()=>t("/projects"),disabled:f,className:"px-4 py-2 rounded-lg text-sm font-medium text-gray-700 bg-transparent border border-gray-300 hover:bg-gray-50 disabled:opacity-50",children:n("project.cancel")}),g.jsxs("button",{type:"button",onClick:k,disabled:f,className:"px-4 py-2 rounded-lg text-sm font-medium text-white bg-blue-500 hover:bg-blue-600 disabled:opacity-50 flex items-center gap-2",children:[f&&g.jsxs("svg",{className:"animate-spin h-4 w-4",viewBox:"0 0 24 24",fill:"none",children:[g.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),g.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8v8H4z"})]}),n(r?"project.save":"project.create")]})]})]}),g.jsx("div",{className:"flex-1 flex justify-center overflow-y-auto",style:{padding:"48px 0"},children:g.jsxs("div",{className:"flex flex-col gap-8",style:{width:720},children:[y&&g.jsx("div",{className:"rounded-lg bg-gray-50 border border-gray-200 px-4 py-3 text-sm text-gray-600",children:n("project.loading")}),p&&g.jsx("div",{className:"rounded-lg bg-red-50 border border-red-200 px-4 py-3 text-sm text-red-700",children:p}),g.jsxs("div",{className:"flex flex-col gap-5",children:[g.jsx("h2",{className:"text-base font-semibold text-gray-900",children:n("project.sectionBasic")}),g.jsxs("div",{className:"flex flex-col gap-1.5",children:[g.jsxs("label",{className:"text-sm font-medium text-gray-700",children:[n("project.fieldName"),g.jsx("span",{className:"text-red-500 ml-0.5",children:"*"})]}),g.jsx("input",{type:"text",value:i,onChange:w=>{s(w.target.value),w.target.value.trim()&&h("")},placeholder:n("project.fieldNamePlaceholder"),className:`w-full px-3 py-2 rounded-lg border text-sm outline-none transition-colors ${u?"border-red-400 focus:border-red-500 bg-red-50":"border-gray-200 focus:border-blue-400 bg-white"}`}),u&&g.jsx("p",{className:"text-xs text-red-500",children:u})]}),g.jsxs("div",{className:"flex flex-col gap-1.5",children:[g.jsx("label",{className:"text-sm font-medium text-gray-700",children:n("project.fieldDescription")}),g.jsx("textarea",{value:o,onChange:w=>a(w.target.value),placeholder:n("project.fieldDescriptionPlaceholder"),rows:5,className:"w-full px-3 py-2 rounded-lg border border-gray-200 focus:border-blue-400 text-sm outline-none resize-none bg-white transition-colors"})]})]}),g.jsxs("div",{className:"flex flex-col gap-5",children:[g.jsx("h2",{className:"text-base font-semibold text-gray-900",children:n("project.sectionTeam")}),g.jsx("p",{className:"text-sm text-gray-500 -mt-3",children:n("project.sectionTeamDesc")}),g.jsxs("div",{className:"flex flex-col gap-1.5",children:[g.jsx("label",{className:"text-sm font-medium text-gray-700",children:n("project.fieldAgent")}),g.jsx(G7e,{value:l,onChange:c})]})]})]})})]})}function pk(t){return t.trim().replace(/^@+/,"")}function dB(t){return`@${pk(t)}`}function K7e(t,e){const n=Date.now(),r=new Date(t).getTime(),i=n-r,s=Math.floor(i/6e4),o=Math.floor(s/60),a=Math.floor(o/24);return s<1?e("projects.justNow"):s<60?e("projects.minutesAgo",{count:s}):o<24?e("projects.hoursAgo",{count:o}):a===1?e("projectDetail.yesterday"):e("projects.daysAgo",{count:a})}function X7e(t){const e=pk(t),n=["bg-blue-500","bg-purple-500","bg-green-500","bg-orange-500","bg-pink-500","bg-teal-500","bg-indigo-500","bg-rose-500"];let r=0;for(let i=0;i<e.length;i++)r=r*31+e.charCodeAt(i)&4294967295;return n[Math.abs(r)%n.length]}function Z7e(t){const e=pk(t),n=e.split(/[_\-\s]+/).filter(Boolean);return n.length===0?e.slice(0,2).toUpperCase():n.slice(0,2).map(r=>r[0]).join("").toUpperCase()}const Q7e={pending:"bg-gray-100 text-gray-600",running:"bg-blue-100 text-blue-700",success:"bg-green-100 text-green-700",failed:"bg-red-100 text-red-700"};function J7e(){const{id:t}=Kh(),e=Nt(),{t:n}=me(),{setPageHeader:r}=ur(),[i,s]=T.useState(null),[o,a]=T.useState([]),[l,c]=T.useState([]),[u,h]=T.useState(!0),[f,d]=T.useState(null),[p,m]=T.useState(""),[y,x]=T.useState(!1),[b,k]=T.useState(!1),w=T.useCallback(async()=>{if(t){h(!0),d(null);try{const[M,A,B]=await Promise.all([fe.getProject(t),fe.getProjectThreads(t),fe.getProjectDocs(t)]);s(M),a(A.threads),c(B.docs)}catch(M){d(M instanceof Error?M.message:n("projectDetail.loadError"))}finally{h(!1)}}},[t,n]);T.useEffect(()=>{w()},[w]),T.useEffect(()=>{r({title:(i==null?void 0:i.name)??n("projects.title"),subtitle:(i==null?void 0:i.description)||void 0})},[r,i,n]);const v=T.useCallback(()=>{p.trim()&&e(`/?workspace=${encodeURIComponent(t??"")}&prompt=${encodeURIComponent(p.trim())}`)},[p,t,e]),C=T.useCallback(M=>{M.key==="Enter"&&!M.shiftKey&&(M.preventDefault(),v())},[v]),S=T.useCallback(async()=>{if(t){k(!0);try{await fe.deleteProject(t),e("/projects")}catch(M){d(M instanceof Error?M.message:n("projectDetail.deleteError")),x(!1)}finally{k(!1)}}},[t,e,n]);if(u)return g.jsx("div",{className:"flex items-center justify-center h-full py-20",children:g.jsx(Vr,{size:20,className:"animate-spin text-gray-400"})});if(f)return g.jsxs("div",{className:"flex flex-col items-center justify-center py-20 gap-4",children:[g.jsxs("div",{className:"flex items-center gap-3 bg-red-50 text-red-700 text-sm rounded-lg px-4 py-3 border border-red-200",children:[g.jsx(Rn,{size:16,className:"shrink-0"}),g.jsx("span",{children:f})]}),g.jsx("button",{onClick:w,className:"px-4 py-2 text-sm bg-gray-100 text-gray-700 rounded-lg hover:bg-gray-200 transition-colors",children:n("common.refresh")})]});if(!i)return g.jsxs("div",{className:"flex flex-col items-center justify-center py-20 gap-2 text-gray-400",children:[g.jsx(is,{size:40}),g.jsx("p",{className:"text-sm",children:n("projectDetail.notFound")})]});const E=n(`projectDetail.projectStatus.${i.status}`,{defaultValue:i.status});return g.jsxs("div",{className:"flex flex-col h-full min-h-0",children:[y&&g.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/40",children:g.jsxs("div",{className:"bg-white rounded-xl shadow-xl p-6 w-80 flex flex-col gap-4",children:[g.jsxs("div",{className:"flex items-center gap-3",children:[g.jsx("div",{className:"flex items-center justify-center w-10 h-10 rounded-full bg-red-100",children:g.jsx($y,{size:18,className:"text-red-600"})}),g.jsxs("div",{children:[g.jsx("p",{className:"text-sm font-semibold text-gray-900",children:n("projectDetail.deleteTitle")}),g.jsx("p",{className:"text-xs text-gray-500 mt-0.5",children:n("projectDetail.deleteWarning")})]})]}),g.jsx("p",{className:"text-sm text-gray-700",children:n("projectDetail.deleteConfirmMsg",{name:i.name})}),g.jsxs("div",{className:"flex gap-2 justify-end",children:[g.jsx("button",{onClick:()=>x(!1),disabled:b,className:"px-4 py-2 text-sm text-gray-700 bg-gray-100 hover:bg-gray-200 rounded-lg transition-colors disabled:opacity-50",children:n("projectDetail.cancel")}),g.jsxs("button",{onClick:S,disabled:b,className:"flex items-center gap-1.5 px-4 py-2 text-sm text-white bg-red-500 hover:bg-red-600 rounded-lg transition-colors disabled:opacity-50",children:[b&&g.jsx(Vr,{size:12,className:"animate-spin"}),n("projectDetail.delete")]})]})]})}),g.jsxs("div",{className:"flex items-center justify-between px-8 py-5 border-b border-gray-200 bg-white shrink-0",style:{borderBottomWidth:1},children:[g.jsxs("div",{className:"flex items-center gap-3",children:[g.jsx("button",{onClick:()=>e("/projects"),className:"p-1 text-gray-400 hover:text-gray-700 rounded-lg hover:bg-gray-100 transition-colors","aria-label":n("projectDetail.back"),children:g.jsx(bne,{size:20})}),g.jsxs("div",{className:"flex flex-col gap-1",children:[g.jsx("h1",{className:"text-xl font-semibold text-gray-900 leading-tight",children:i.name}),g.jsx("p",{className:"text-sm text-gray-500 leading-tight",children:i.description||E})]})]}),g.jsxs("div",{className:"flex items-center gap-2",children:[g.jsxs("button",{onClick:()=>x(!0),className:"flex items-center gap-1.5 px-3 py-1.5 text-sm text-red-600 bg-red-50 hover:bg-red-100 rounded-lg transition-colors",children:[g.jsx($y,{size:14}),n("projectDetail.delete")]}),g.jsxs("button",{onClick:()=>e(`/projects/${t}/edit`),className:"flex items-center gap-1.5 px-3 py-1.5 text-sm text-gray-600 bg-gray-100 hover:bg-gray-200 rounded-lg transition-colors",children:[g.jsx(jre,{size:14}),n("projectDetail.edit")]}),g.jsxs("button",{onClick:()=>e(`/?workspace=${encodeURIComponent(t??"")}`),className:"flex items-center gap-1.5 px-3 py-1.5 text-sm text-white bg-blue-500 hover:bg-blue-600 rounded-lg transition-colors",children:[g.jsx(Kr,{size:14}),n("projectDetail.newChat")]})]})]}),g.jsxs("div",{className:"flex flex-1 min-h-0 overflow-hidden",children:[g.jsxs("div",{className:"flex flex-col flex-1 gap-6 p-8 overflow-y-auto border-r border-gray-200",children:[g.jsxs("div",{className:"flex flex-col gap-4",children:[g.jsx("p",{className:"text-base font-semibold text-gray-900",children:n("projectDetail.chatPrompt",{name:i.name})}),g.jsxs("div",{className:"flex items-center gap-3 px-4 py-3 bg-white border border-gray-200 rounded-lg",children:[g.jsx(ane,{size:18,className:"text-gray-400 shrink-0"}),g.jsx("input",{type:"text",value:p,onChange:M=>m(M.target.value),onKeyDown:C,placeholder:n("projectDetail.chatPlaceholder"),className:"flex-1 text-sm text-gray-900 placeholder-gray-400 bg-transparent outline-none"}),g.jsxs("button",{onClick:v,disabled:!p.trim(),className:"flex items-center gap-1.5 px-3 py-1.5 text-sm text-white bg-blue-500 hover:bg-blue-600 disabled:opacity-40 disabled:cursor-not-allowed rounded-lg transition-colors",children:[g.jsx(tie,{size:14}),n("projectDetail.send")]})]}),g.jsxs("div",{className:"flex items-center gap-3",children:[g.jsx("p",{className:"text-xs font-medium text-gray-500 uppercase tracking-wide shrink-0",children:n("projectDetail.assignedAgents")}),i.agents&&i.agents.length>0?g.jsx("div",{className:"flex flex-wrap gap-2",children:i.agents.map(M=>g.jsxs("button",{onClick:()=>e(`/agents/${encodeURIComponent(pk(M))}/edit`),className:"flex items-center gap-2 px-3 py-1.5 bg-white border border-gray-200 rounded-lg hover:bg-gray-50 transition-colors",children:[g.jsx("div",{className:`flex items-center justify-center w-6 h-6 rounded-full text-white text-[10px] font-bold shrink-0 ${X7e(M)}`,children:Z7e(M)}),g.jsx("span",{className:"text-xs font-medium text-gray-700",children:dB(M)})]},M))}):g.jsxs("div",{className:"flex items-center gap-2 text-gray-400",children:[g.jsx(Ka,{size:14}),g.jsx("span",{className:"text-sm",children:n("projectDetail.noAgents")})]})]})]}),g.jsxs("div",{className:"flex flex-col gap-3 flex-1",children:[g.jsx("p",{className:"text-xs font-medium text-gray-500 uppercase tracking-wide",children:n("projectDetail.relatedThreads")}),o.length===0?g.jsxs("div",{className:"flex flex-col items-center justify-center py-10 text-gray-400",children:[g.jsx(vh,{size:32,className:"mb-2"}),g.jsx("p",{className:"text-sm",children:n("projectDetail.noThreads")})]}):g.jsx("div",{className:"flex flex-col gap-2",children:o.map(M=>g.jsxs("button",{onClick:()=>e(`/threads/${encodeURIComponent(M.taskId)}`),className:"flex items-center gap-3 px-4 py-3 bg-white border border-gray-200 rounded-lg hover:bg-gray-50 transition-colors text-left",children:[g.jsx(vh,{size:16,className:"text-gray-400 shrink-0"}),g.jsxs("div",{className:"flex flex-col gap-0.5 flex-1 min-w-0",children:[g.jsx("p",{className:"text-sm font-medium text-gray-900 truncate",children:M.title||n("threads.emptyPrompt")}),g.jsxs("p",{className:"text-xs text-gray-500",children:[M.agentId?dB(M.agentId):n("projectDetail.unknownAgent")," · ",K7e(M.updatedAt,n)]})]}),g.jsx("span",{className:`shrink-0 px-2 py-0.5 text-xs rounded-full font-medium ${Q7e[M.status]??"bg-gray-100 text-gray-600"}`,children:n(`status.${M.status}`,{defaultValue:M.status})})]},M.taskId))})]})]}),g.jsxs("div",{className:"w-80 shrink-0 flex flex-col gap-6 p-6 overflow-y-auto",children:[g.jsxs("div",{className:"flex flex-col gap-2 p-4 bg-white border border-gray-200 rounded-lg",children:[g.jsx("p",{className:"text-xs font-medium text-gray-500 uppercase tracking-wide",children:n("projectDetail.description")}),g.jsx("p",{className:"text-sm text-gray-700 leading-relaxed",children:i.description||n("projectDetail.noDescription")})]}),g.jsxs("div",{className:"flex flex-col gap-2",children:[g.jsx("p",{className:"text-xs font-medium text-gray-500 uppercase tracking-wide",children:n("projectDetail.relatedDocs")}),l.length===0?g.jsx("p",{className:"text-sm text-gray-400",children:n("projectDetail.noDocs")}):g.jsx("div",{className:"flex flex-col gap-2",children:l.map(M=>g.jsxs("button",{onClick:()=>e(`/docs?path=${encodeURIComponent(M.path)}`),className:"flex items-center gap-2 px-3 py-2 bg-white border border-gray-200 rounded-lg",children:[g.jsx(Uo,{size:14,className:"text-gray-400 shrink-0"}),g.jsx("span",{className:"text-sm text-gray-700 truncate",children:M.name})]},M.path))})]})]})]})]})}class tK extends T.Component{constructor(){super(...arguments);pe(this,"state",{hasError:!1})}static getDerivedStateFromError(){return{hasError:!0}}componentDidCatch(n,r){console.error("PageErrorBoundary caught an error",n,r)}render(){return this.state.hasError?this.props.fallback:this.props.children}}const fB="crewx-wfl-banner-dismissed";function eHe(){return g.jsxs("div",{className:"rounded-xl border border-gray-200 bg-white p-5 shadow-sm",children:[g.jsxs("div",{className:"mb-4 flex items-start justify-between gap-3",children:[g.jsxs("div",{className:"flex items-start gap-3",children:[g.jsx("div",{className:"h-10 w-10 animate-pulse rounded-xl bg-gray-100"}),g.jsxs("div",{className:"space-y-2",children:[g.jsx("div",{className:"h-4 w-32 animate-pulse rounded bg-gray-100"}),g.jsx("div",{className:"h-3 w-20 animate-pulse rounded bg-gray-100"})]})]}),g.jsx("div",{className:"h-8 w-24 animate-pulse rounded-md bg-gray-100"})]}),g.jsx("div",{className:"mb-4 h-4 w-full animate-pulse rounded bg-gray-100"}),g.jsxs("div",{className:"mb-4 flex gap-2",children:[g.jsx("div",{className:"h-6 w-20 animate-pulse rounded-full bg-gray-100"}),g.jsx("div",{className:"h-6 w-20 animate-pulse rounded-full bg-gray-100"})]}),g.jsx("div",{className:"h-3 w-40 animate-pulse rounded bg-gray-100"})]})}function tHe({workflow:t,onOpen:e,onStart:n,startLabel:r,startTooltip:i}){const s=t.agents.slice(0,4),o=t.agents.length-s.length;return g.jsxs("div",{role:"button",tabIndex:0,onClick:e,onKeyDown:a=>{(a.key==="Enter"||a.key===" ")&&(a.preventDefault(),e())},className:"flex h-full flex-col rounded-xl border border-gray-200 bg-white p-5 text-left shadow-sm transition-all hover:-translate-y-0.5 hover:border-blue-200 hover:shadow-md",children:[g.jsxs("div",{className:"mb-4 flex items-start justify-between gap-3",children:[g.jsxs("div",{className:"flex min-w-0 items-start gap-3",children:[g.jsx("div",{className:"flex h-10 w-10 shrink-0 items-center justify-center rounded-xl bg-blue-50 text-blue-600",children:g.jsx(wh,{size:18})}),g.jsxs("div",{className:"min-w-0",children:[g.jsx("h3",{className:"truncate text-base font-semibold text-gray-900",children:t.name}),g.jsx("p",{className:"mt-1 text-xs text-gray-500",children:t.id})]})]}),g.jsxs("button",{type:"button",onClick:a=>{a.stopPropagation(),n()},title:i,"aria-label":i,className:"inline-flex shrink-0 items-center gap-1.5 rounded-md bg-blue-500 px-3 py-2 text-xs font-medium text-white transition-colors hover:bg-blue-600",children:[g.jsx(BT,{size:14}),g.jsx("span",{children:r})]})]}),g.jsx("p",{className:"mb-4 truncate text-[13px] text-gray-500",children:t.description||"—"}),g.jsxs("div",{className:"mb-4 flex flex-wrap gap-2",children:[g.jsxs("span",{className:"rounded-full bg-gray-100 px-2.5 py-1 text-xs font-medium text-gray-600",children:["노드 ",t.nodeCount,"개"]}),g.jsxs("span",{className:"rounded-full bg-gray-100 px-2.5 py-1 text-xs font-medium text-gray-600",children:["분기 ",t.branchCount,"개"]})]}),g.jsxs("div",{className:"mt-auto text-xs text-gray-500",children:[s.map(a=>`@${a}`).join(" → "),o>0?` +${o}`:""]})]})}function nHe(){const{t}=me(),e=Nt(),{setPageHeader:n}=ur(),r=nr(k=>k.workflows),i=nr(k=>k.listErrors),s=nr(k=>k.loading),o=nr(k=>k.error),a=nr(k=>k.fetchWorkflows),[l,c]=T.useState(()=>typeof window<"u"&&window.localStorage.getItem(fB)==="true"),[u,h]=T.useState(!1),[f,d]=T.useState("");T.useEffect(()=>{n({title:""}),a().catch(()=>{})},[a,n]);const p=T.useMemo(()=>{const k=f.trim().toLowerCase();return k?r.filter(w=>[w.id,w.name,w.description,...w.agents].filter(v=>!!v).some(v=>v.toLowerCase().includes(k))):r},[f,r]),m=T.useMemo(()=>t("workflow.totalCount",{count:p.length}),[p.length,t]),y=()=>{c(!0),window.localStorage.setItem(fB,"true")},x=async()=>{try{await navigator.clipboard.writeText("workflows/"),h(!0),window.setTimeout(()=>h(!1),1500)}catch{h(!1)}},b=k=>{e(`/threads/new?workflow=${encodeURIComponent(k)}`)};return g.jsx(tK,{fallback:g.jsx("div",{className:"rounded-xl border border-red-200 bg-red-50 px-4 py-3 text-sm text-red-600",children:t("workflow.pageError")}),children:g.jsxs("div",{className:"mx-auto flex max-w-7xl flex-col gap-6",children:[g.jsxs("div",{className:"flex flex-col gap-1",children:[g.jsx("h1",{className:"text-2xl font-semibold text-gray-900",children:t("workflow.title")}),g.jsx("p",{className:"text-sm text-gray-500",children:m})]}),g.jsx("div",{className:"rounded-2xl border border-gray-200 bg-white p-4 shadow-sm",children:g.jsxs("div",{className:"relative",children:[g.jsx(Ya,{size:16,className:"pointer-events-none absolute left-3 top-1/2 -translate-y-1/2 text-gray-400"}),g.jsx("input",{type:"search",value:f,onChange:k=>d(k.target.value),placeholder:t("workflow.searchPlaceholder"),className:`w-full rounded-xl border border-gray-300 py-2.5 pl-10 text-sm text-gray-900 placeholder:text-gray-400 focus:border-blue-500 focus:outline-none focus:ring-2 focus:ring-blue-500 ${f?"pr-10":"pr-4"}`}),f&&g.jsx("button",{type:"button",onClick:()=>d(""),className:"absolute right-3 top-1/2 -translate-y-1/2 rounded-md p-1 text-gray-400 transition-colors hover:bg-gray-100 hover:text-gray-600","aria-label":t("workflow.clearSearch"),children:g.jsx(Xa,{size:16})})]})}),!l&&g.jsxs("div",{className:"flex items-start justify-between gap-4 rounded-xl border border-blue-200 bg-blue-50 px-4 py-4 text-blue-900",children:[g.jsxs("div",{children:[g.jsx("p",{className:"text-sm font-medium",children:t("workflow.bannerTitle")}),g.jsx("p",{className:"mt-1 text-sm text-blue-700",children:t("workflow.bannerBody")})]}),g.jsx("button",{type:"button",onClick:y,className:"rounded-md p-1 text-blue-500 transition-colors hover:bg-blue-100 hover:text-blue-700","aria-label":t("common.close"),children:g.jsx(Xa,{size:16})})]}),i.length>0&&g.jsxs("div",{className:"rounded-xl border border-amber-200 bg-amber-50 px-4 py-4 text-amber-900",children:[g.jsxs("div",{className:"flex items-center gap-2 text-sm font-medium",children:[g.jsx(FT,{size:16}),g.jsx("span",{children:t("workflow.errorsTitle",{count:i.length})})]}),g.jsx("ul",{className:"mt-2 space-y-1 text-sm text-amber-800",children:i.map(k=>g.jsx("li",{children:t("workflow.errorItem",{file:k.file,reason:k.reason})},`${k.file}-${k.reason}`))})]}),o&&!s&&g.jsxs("div",{className:"flex items-center justify-between gap-4 rounded-xl border border-red-200 bg-red-50 px-4 py-4 text-sm text-red-700",children:[g.jsx("span",{children:o}),g.jsx("button",{type:"button",onClick:()=>a(!0).catch(()=>{}),className:"rounded-md bg-white px-3 py-2 font-medium text-red-700 transition-colors hover:bg-red-100",children:t("workflow.retry")})]}),s&&r.length===0?g.jsx("div",{className:"grid grid-cols-1 gap-4 sm:grid-cols-2 xl:grid-cols-3 2xl:grid-cols-4",children:Array.from({length:8},(k,w)=>g.jsx(eHe,{},w))}):r.length===0?g.jsxs("div",{className:"rounded-2xl border border-gray-200 bg-white px-6 py-14 text-center shadow-sm",children:[g.jsx("div",{className:"mx-auto mb-4 flex h-16 w-16 items-center justify-center rounded-full bg-blue-50 text-blue-600",children:g.jsx(wh,{size:28})}),g.jsx("h2",{className:"text-xl font-semibold text-gray-900",children:t("workflow.emptyTitle")}),g.jsx("p",{className:"mt-2 text-sm text-gray-500",children:t("workflow.emptyDescription")}),g.jsx("p",{className:"mt-1 text-sm text-gray-500",children:t("workflow.emptyAction")}),g.jsxs("details",{className:"mx-auto mt-8 max-w-md rounded-xl border border-gray-200 bg-gray-50 px-4 py-3 text-left",children:[g.jsx("summary",{className:"cursor-pointer list-none text-sm font-medium text-gray-700",children:t("workflow.developerTitle")}),g.jsxs("div",{className:"mt-3 flex items-center justify-between gap-3 text-sm text-gray-600",children:[g.jsx("span",{children:t("workflow.developerPathHint")}),g.jsxs("button",{type:"button",onClick:x,className:"inline-flex items-center gap-1 rounded-md border border-gray-200 bg-white px-3 py-1.5 text-xs font-medium text-gray-700 transition-colors hover:bg-gray-100",children:[u?g.jsx(Us,{size:12}):g.jsx(yg,{size:12}),g.jsx("span",{children:t(u?"common.copied":"common.copy")})]})]})]})]}):p.length===0?g.jsxs("div",{className:"rounded-xl border border-dashed border-gray-300 bg-white px-4 py-12 text-center shadow-sm",children:[g.jsx("div",{className:"mx-auto flex h-10 w-10 items-center justify-center rounded-full bg-gray-100 text-gray-400",children:g.jsx(Ya,{size:18})}),g.jsx("h2",{className:"mt-3 text-sm font-semibold text-gray-900",children:t("workflow.emptyFilteredTitle")}),g.jsx("p",{className:"mt-2 text-xs leading-5 text-gray-500",children:t("workflow.emptyFilteredDescription")})]}):g.jsx("div",{className:"grid grid-cols-1 gap-4 sm:grid-cols-2 xl:grid-cols-3 2xl:grid-cols-4",children:p.map(k=>g.jsx(tHe,{workflow:k,onOpen:()=>e(`/workflows/${encodeURIComponent(k.id)}`),onStart:()=>b(k.id),startLabel:t("workflow.startChat"),startTooltip:t("workflow.startChatTooltip",{id:k.id})},k.id))})]})})}function y0({icon:t,label:e,value:n}){return g.jsxs("div",{className:"rounded-xl border border-gray-200 bg-white p-4 shadow-sm",children:[g.jsx("div",{className:"mb-3 flex h-10 w-10 items-center justify-center rounded-xl bg-blue-50 text-blue-600",children:g.jsx(t,{size:18})}),g.jsx("p",{className:"text-xs font-medium uppercase tracking-wide text-gray-400",children:e}),g.jsx("p",{className:"mt-1 text-lg font-semibold text-gray-900",children:n})]})}function rHe({title:t,variables:e}){return g.jsxs("aside",{className:"w-full rounded-2xl border border-gray-200 bg-white p-4 shadow-sm lg:w-[280px] lg:shrink-0",children:[g.jsxs("div",{className:"flex items-center gap-2 text-[13px] font-semibold text-gray-900",children:[g.jsx(zne,{size:14,className:"text-gray-500"}),g.jsx("h2",{children:t})]}),g.jsx("div",{className:"mt-3 border-t border-gray-200 pt-3",children:g.jsx("ul",{className:"space-y-2",children:e.map(n=>g.jsxs("li",{className:"flex items-center gap-2",children:[g.jsx("span",{"aria-hidden":"true",className:"h-1.5 w-1.5 rounded-full bg-gray-300"}),g.jsx("span",{className:"font-mono text-[11px] text-gray-500",children:n})]},n))})})]})}function iHe(){const{t}=me(),e=Nt(),{id:n}=Kh(),{setPageHeader:r}=ur(),i=nr(C=>C.fetchWorkflowDetail),s=nr(C=>C.clearSelectedWorkflow),o=nr(C=>C.selectedWorkflow),a=nr(C=>C.detailLoading),l=nr(C=>C.detailError),[c,u]=T.useState(!1),[h,f]=T.useState(!1),[d,p]=T.useState({svg:null,error:null,isRendering:!1});T.useEffect(()=>{r({title:""})},[r]),T.useEffect(()=>{if(n)return i(n).catch(()=>{}),()=>s()},[s,i,n]);const m=T.useMemo(()=>o!=null&&o.timeout?t("workflow.timeoutMinutes",{count:Math.max(1,Math.round(o.timeout/60))}):t("workflow.noLimit"),[t,o==null?void 0:o.timeout]),y=T.useMemo(()=>o!=null&&o.maxIterations?t("workflow.iterationCount",{count:o.maxIterations}):t("workflow.noLimit"),[t,o==null?void 0:o.maxIterations]),x=T.useMemo(()=>Object.keys((o==null?void 0:o.state)??{}).sort((C,S)=>C.localeCompare(S)),[o==null?void 0:o.state]),b=o?x.length>0?"WFLUI003":"WFLUI002":null,k=x.length>0?"워크플로 상세 State":"워크플로 상세";CF(b,k);const w=()=>{o&&e(`/threads/new?workflow=${encodeURIComponent(o.id)}`)},v=async()=>{if(o)try{await navigator.clipboard.writeText(`workflows/${o.sourceFile}`),f(!0),window.setTimeout(()=>f(!1),1500)}catch{f(!1)}};return g.jsx(tK,{fallback:g.jsx("div",{className:"rounded-xl border border-red-200 bg-red-50 px-4 py-3 text-sm text-red-600",children:t("workflow.pageError")}),children:g.jsxs("div",{className:"mx-auto flex max-w-6xl flex-col gap-6",children:[g.jsxs("button",{type:"button",onClick:()=>e("/workflows"),className:"inline-flex items-center gap-2 self-start text-sm font-medium text-gray-600 transition-colors hover:text-gray-900",children:[g.jsx(LT,{size:16}),g.jsx("span",{children:t("workflow.backToList")})]}),a&&!o?g.jsx("div",{className:"flex min-h-[360px] items-center justify-center rounded-2xl border border-gray-200 bg-white shadow-sm",children:g.jsx(ut,{size:24,className:"animate-spin text-gray-400"})}):l?g.jsxs("div",{className:"flex items-center justify-between gap-4 rounded-xl border border-red-200 bg-red-50 px-4 py-4 text-sm text-red-700",children:[g.jsx("span",{children:l}),n&&g.jsx("button",{type:"button",onClick:()=>i(n,!0).catch(()=>{}),className:"rounded-md bg-white px-3 py-2 font-medium text-red-700 transition-colors hover:bg-red-100",children:t("workflow.retry")})]}):o?g.jsxs(g.Fragment,{children:[g.jsxs("div",{className:"flex flex-col gap-4 rounded-2xl border border-gray-200 bg-white p-6 shadow-sm lg:flex-row lg:items-center lg:justify-between",children:[g.jsx("div",{className:"min-w-0",children:g.jsxs("div",{className:"flex items-center gap-3",children:[g.jsx("div",{className:"flex h-12 w-12 items-center justify-center rounded-xl bg-blue-50 text-blue-600",children:g.jsx(wh,{size:20})}),g.jsxs("div",{className:"min-w-0",children:[g.jsx("h1",{className:"truncate text-2xl font-semibold text-gray-900",children:o.name}),g.jsx("p",{className:"mt-1 text-sm text-gray-500",children:o.id})]})]})}),g.jsxs("button",{type:"button",onClick:w,title:t("workflow.startChatTooltip",{id:o.id}),className:"inline-flex items-center justify-center gap-2 rounded-lg bg-blue-500 px-4 py-3 text-sm font-medium text-white transition-colors hover:bg-blue-600",children:[g.jsx(BT,{size:16}),g.jsx("span",{children:t("workflow.startChat")})]})]}),g.jsxs("div",{className:"flex flex-col gap-4 lg:flex-row lg:items-start",children:[g.jsxs("div",{className:"min-w-0 flex-1 overflow-hidden rounded-2xl border border-gray-200 bg-white shadow-sm",children:[g.jsxs("div",{className:"flex items-center justify-between border-b border-gray-200 px-4 py-3",children:[g.jsx("span",{className:"text-sm font-medium text-gray-500",children:t("workflow.developerPathHint")}),g.jsxs("button",{type:"button",onClick:()=>u(!0),disabled:!d.svg,className:"inline-flex items-center gap-2 rounded-md border border-gray-200 px-3 py-2 text-sm font-medium text-gray-700 transition-colors hover:bg-gray-50 disabled:cursor-not-allowed disabled:opacity-50",children:[g.jsx(Vne,{size:14}),g.jsx("span",{children:t("mermaidFullscreen.expand")})]})]}),g.jsx("div",{className:"min-h-[360px] bg-gray-50 p-6",children:g.jsx(cq,{code:o.mermaid,containerClassName:"relative overflow-auto rounded-xl border border-gray-200 bg-white p-4",diagramClassName:"min-w-[700px] [&_svg]:mx-auto [&_svg]:h-auto [&_svg]:max-w-none [&_svg]:w-full",loadingContent:g.jsxs("div",{className:"flex h-[320px] items-center justify-center text-sm text-gray-500",children:[g.jsx(ut,{size:18,className:"mr-2 animate-spin"}),t("workflow.diagramLoading")]}),errorRenderer:C=>g.jsx("div",{className:"rounded-xl border border-red-200 bg-red-50 px-4 py-3 text-sm text-red-700",children:C||t("workflow.diagramError")}),showExpandButton:!1,fullscreen:c,onFullscreenChange:u,onRenderStateChange:p})})]}),x.length>0?g.jsx(rHe,{title:t("workflow.stateVariablesTitle"),variables:x}):null]}),g.jsxs("div",{className:"rounded-xl border border-gray-200 bg-white px-4 py-4 text-sm text-gray-700 shadow-sm",children:[g.jsx("p",{className:"font-medium text-gray-900",children:t("workflow.developerTitle")}),g.jsx("p",{className:"mt-1 text-gray-500",children:t("workflow.developerPathHint")}),g.jsxs("details",{className:"mt-4 rounded-lg border border-gray-200 bg-gray-50 px-3 py-2 text-gray-900",children:[g.jsx("summary",{className:"cursor-pointer list-none text-sm font-medium",children:t("workflow.developerTitle")}),g.jsxs("div",{className:"mt-3 flex items-center justify-between gap-3 text-sm text-gray-700",children:[g.jsx("span",{children:t("workflow.sourcePath",{path:`workflows/${o.sourceFile}`})}),g.jsxs("button",{type:"button",onClick:v,className:"inline-flex items-center gap-1 rounded-md border border-gray-200 bg-white px-3 py-1.5 text-xs font-medium text-gray-700 transition-colors hover:bg-gray-100",children:[h?g.jsx(Us,{size:12}):g.jsx(yg,{size:12}),g.jsx("span",{children:t(h?"common.copied":"common.copy")})]})]})]})]}),g.jsxs("div",{className:"grid grid-cols-1 gap-4 sm:grid-cols-2 xl:grid-cols-4",children:[g.jsx(y0,{icon:Ka,label:t("workflow.metadataAgents"),value:String(o.agents.length)}),g.jsx(y0,{icon:wh,label:t("workflow.metadataNodes"),value:String(o.nodeCount)}),g.jsx(y0,{icon:gie,label:t("workflow.metadataTimeout"),value:m}),g.jsx(y0,{icon:Kre,label:t("workflow.metadataMaxIterations"),value:y})]})]}):null]})})}function nK(t){return t.map(e=>({name:e.name,path:e.path,type:e.isDirectory??e.type==="dir"?"dir":"file",isDirectory:e.isDirectory??e.type==="dir",children:e.children?nK(e.children):[],hasCrewxYaml:e.hasCrewxYaml,isRegistered:e.isRegistered}))}async function sHe(t,e=3){const n=await fe.getFsTree(t,e);return nK(n)}function oHe(t){for(const e of t){if(!e)continue;const n=/^\/Users\/[^/]+/.exec(e);if(n)return n[0];const r=/^\/home\/[^/]+/.exec(e);if(r)return r[0]}return null}function pB(t,e){return e?t===e?"~":t.startsWith(`${e}/`)?`~${t.slice(e.length)}`:t:t}function aHe(t){const e=t??"/";return[{key:"home",path:e},{key:"git",path:`${e.replace(/\/$/,"")}/git`},{key:"projects",path:`${e.replace(/\/$/,"")}/projects`},{key:"desktop",path:`${e.replace(/\/$/,"")}/Desktop`}]}function T_(t,e){var n;for(const r of t){if(r.path===e)return r;if((n=r.children)!=null&&n.length){const i=T_(r.children,e);if(i)return i}}return null}function lHe(t){if(!(t instanceof Ql)||typeof t.body!="object"||t.body===null)return"UNKNOWN";const e=t.body;if(typeof e.code=="string")return e.code;if(typeof e.error=="object"&&e.error!==null){const n=e.error;if(typeof n.code=="string")return n.code}return"UNKNOWN"}function cHe({open:t,onClose:e,onSelect:n,initialPath:r}){const{t:i}=me(),s=yn(S=>S.currentWorkspace),o=yn(S=>S.workspaces),a=T.useMemo(()=>oHe([r,s==null?void 0:s.workspace_path,...o.map(S=>S.workspace_path)]),[s==null?void 0:s.workspace_path,r,o]),l=T.useMemo(()=>aHe(a),[a]),c=T.useMemo(()=>{var S,E;if(r&&r.startsWith("/")){const M=[...l].sort((A,B)=>B.path.length-A.path.length).find(A=>r===A.path||r.startsWith(`${A.path}/`));return(M==null?void 0:M.path)??r}return((S=l[1])==null?void 0:S.path)??((E=l[0])==null?void 0:E.path)??"/"},[r,l]),[u,h]=T.useState(c),[f,d]=T.useState([]),[p,m]=T.useState(new Set),[y,x]=T.useState(r??null),[b,k]=T.useState(!1),[w,v]=T.useState(null),C=T.useMemo(()=>y?T_(f,y):null,[y,f]);return T.useEffect(()=>{t&&(h(c),x(r??null),m(new Set),v(null))},[c,r,t]),T.useEffect(()=>{if(!t)return;const S=E=>{E.key==="Escape"&&(E.preventDefault(),E.stopPropagation(),e())};return window.addEventListener("keydown",S),()=>window.removeEventListener("keydown",S)},[e,t]),T.useEffect(()=>{if(!t)return;let S=!0;return k(!0),v(null),sHe(u,3).then(E=>{S&&d(E)}).catch(E=>{S&&(d([]),x(null),m(new Set),v(lHe(E)))}).finally(()=>{S&&k(!1)}),()=>{S=!1}},[t,u]),t?g.jsx("div",{"data-testid":"directory-picker-backdrop",className:"fixed inset-0 z-[60] flex items-center justify-center bg-black/40 p-4",onClick:e,children:g.jsxs("div",{role:"dialog","aria-modal":"true","aria-labelledby":"directory-picker-title","data-testid":"directory-picker-dialog",className:"flex h-[70vh] w-full max-w-5xl flex-col overflow-hidden rounded-2xl border border-gray-200 bg-white shadow-xl",onClick:S=>S.stopPropagation(),children:[g.jsxs("div",{className:"flex items-start justify-between gap-4 border-b border-gray-200 px-6 py-5",children:[g.jsxs("div",{children:[g.jsx("h2",{id:"directory-picker-title",className:"text-lg font-semibold text-gray-900",children:i("dirPicker.title")}),g.jsx("p",{className:"mt-1 text-sm text-gray-500",children:i("dirPicker.description")})]}),g.jsx("button",{type:"button",onClick:e,className:"rounded-lg bg-gray-100 px-3 py-2 text-sm font-medium text-gray-700 transition-colors hover:bg-gray-200",children:i("common.close")})]}),g.jsxs("div",{className:"min-h-0 flex flex-1",children:[g.jsxs("aside",{className:"w-48 border-r border-gray-200 bg-gray-50 px-4 py-4",children:[g.jsx("p",{className:"mb-3 text-xs font-semibold uppercase tracking-wide text-gray-500",children:i("dirPicker.quickAccess.title")}),g.jsx("div",{className:"space-y-2",children:l.map(S=>{const E=u===S.path;return g.jsxs("button",{type:"button",onClick:()=>{h(S.path),x(null),m(new Set)},className:`flex w-full items-center justify-between rounded-lg px-3 py-2 text-left text-sm transition-colors ${E?"bg-blue-100 text-blue-700":"text-gray-700 hover:bg-white"}`,children:[g.jsx("span",{children:i(`dirPicker.quickAccess.${S.key}`)}),E?g.jsx(Us,{className:"h-4 w-4"}):null]},S.key)})})]}),g.jsxs("div",{className:"flex min-h-0 flex-1 flex-col px-6 py-5",children:[g.jsxs("div",{className:"mb-4 flex items-center gap-2 rounded-lg border border-gray-200 bg-gray-50 px-3 py-2 text-sm text-gray-600",children:[g.jsx(is,{className:"h-4 w-4 text-gray-400"}),g.jsx("span",{className:"truncate",children:pB(u,a)})]}),g.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto rounded-xl border border-gray-200 bg-white px-3 py-3",children:b?g.jsxs("div",{className:"flex items-center gap-2 px-2 py-2 text-sm text-gray-500",children:[g.jsx(ut,{className:"h-4 w-4 animate-spin"}),g.jsx("span",{children:i("dirPicker.loading")})]}):w?g.jsxs("div",{className:"flex items-start gap-2 rounded-lg border border-red-200 bg-red-50 px-3 py-3 text-sm text-red-700",role:"alert",children:[g.jsx(Rn,{className:"mt-0.5 h-4 w-4 shrink-0"}),g.jsx("span",{children:i(`dirPicker.error.${w}`,{defaultValue:i("dirPicker.error.UNKNOWN")})})]}):f.length===0?g.jsx("div",{className:"px-2 py-2 text-sm text-gray-500",children:i("dirPicker.empty")}):g.jsx(oY,{nodes:f,expandedFolders:p,selectedPath:y,onToggle:S=>{const E=T_(f,S);!E||E.isRegistered||(x(S),m(M=>{const A=new Set(M);return A.has(S)?A.delete(S):A.add(S),A}))},onSelect:S=>x(S),isFileDisabled:S=>S.isRegistered===!0,renderFileSuffix:S=>g.jsxs("span",{className:"ml-2 flex items-center gap-1",children:[S.hasCrewxYaml?g.jsx("span",{className:"rounded bg-blue-100 px-1.5 py-0.5 text-[10px] font-medium text-blue-700",children:i("dirPicker.badge.crewxYaml")}):null,S.isRegistered?g.jsx("span",{className:"rounded bg-gray-200 px-1.5 py-0.5 text-[10px] font-medium text-gray-600",title:i("dirPicker.disabledTooltip"),children:i("dirPicker.alreadyRegistered")}):null]})})}),g.jsxs("div",{className:"mt-4 rounded-lg border border-gray-200 bg-gray-50 px-3 py-3 text-sm text-gray-600",children:[g.jsx("p",{className:"text-xs font-medium uppercase tracking-wide text-gray-400",children:i("dirPicker.selected")}),g.jsx("p",{className:"mt-1 truncate text-sm font-medium text-gray-900",children:y?pB(y,a):i("dirPicker.noneSelected")})]})]})]}),g.jsxs("div",{className:"flex items-center justify-end gap-2 border-t border-gray-200 px-6 py-4",children:[g.jsx("button",{type:"button",onClick:e,className:"rounded-lg bg-gray-100 px-4 py-2 text-sm font-medium text-gray-700 transition-colors hover:bg-gray-200",children:i("dirPicker.cancel")}),g.jsx("button",{type:"button",onClick:()=>{y&&C&&!C.isRegistered&&(n(y),e())},disabled:!y||!C||C.isRegistered===!0,className:"rounded-lg bg-blue-600 px-4 py-2 text-sm font-medium text-white transition-colors hover:bg-blue-700 disabled:cursor-not-allowed disabled:bg-blue-300",children:i("dirPicker.select")})]})]})}):null}const gB=150;function mB(t){return new Promise(e=>{window.setTimeout(e,t)})}function yB(t){return typeof t=="object"&&t!==null}function xB(t){if(!(t instanceof Ql))return"UNKNOWN";if(yB(t.body)){if(typeof t.body.code=="string")return t.body.code;if(yB(t.body.error)&&typeof t.body.error.code=="string")return t.body.error.code}return"UNKNOWN"}function Kv(t,e,n){return e===0?"pending":t<e?"done":t===e?n?"current":"done":"pending"}function Xv({label:t,status:e}){return g.jsxs("div",{className:"flex items-center gap-3 rounded-lg border border-gray-200 bg-white px-4 py-3",children:[e==="done"?g.jsx(dF,{size:18,className:"shrink-0 text-green-600"}):e==="current"?g.jsx(ut,{size:18,className:"shrink-0 animate-spin text-blue-600"}):g.jsx(Nne,{size:18,className:"shrink-0 text-gray-300"}),g.jsx("span",{className:e==="pending"?"text-sm text-gray-400":e==="current"?"text-sm font-medium text-blue-700":"text-sm font-medium text-gray-900",children:t})]})}function bB({open:t,onClose:e}){const{t:n}=me();CF(t?"WKSUI001-NEW":null,"워크스페이스 생성");const r=ul(D=>D.addToast),i=yn(D=>D.createWorkspace),[s,o]=T.useState(""),[a,l]=T.useState(""),[c,u]=T.useState("form"),[h,f]=T.useState(!1),[d,p]=T.useState(null),[m,y]=T.useState(null),[x,b]=T.useState(0),[k,w]=T.useState(null),[v,C]=T.useState(!1);T.useEffect(()=>{t||(o(""),l(""),u("form"),f(!1),p(null),y(null),b(0),w(null),C(!1))},[t]),T.useEffect(()=>{if(!t)return;const D=O=>{O.key!=="Escape"||h||v||(O.preventDefault(),e())};return window.addEventListener("keydown",D),()=>window.removeEventListener("keydown",D)},[e,t,v,h]);const S=T.useMemo(()=>d?n(`workspace.createModal.error.${d}`,{defaultValue:n("workspace.createModal.error.UNKNOWN")}):null,[d,n]),E=h||v,M=[n("workspace.createModal.confirmInit.files.config"),n("workspace.createModal.confirmInit.files.automation"),n("workspace.createModal.confirmInit.files.registration")];if(!t)return null;const A=async()=>{const D=s.trim(),O=a.trim();if(!(!D||h)){f(!0),p(null);try{await i({workspace_path:D,slug:O||void 0,initIfMissing:!1}),r({type:"success",message:n("workspace.createModal.success")}),e()}catch(N){const $=xB(N);if($==="NOT_A_CREWX_WORKSPACE"){y(D),u("confirm-init");return}p($)}finally{f(!1)}}},B=()=>{u("form"),p(null),w(null),b(0)},F=async()=>{var N;const D=m??s.trim(),O=a.trim();if(!(!D||h)){u("initializing"),f(!0),p(null),w(null),b(1);try{const $=await i({workspace_path:D,slug:O||void 0,initIfMissing:!0});b(2),await mB(gB),b(3),f(!1);const I=((N=$.initResult)==null?void 0:N.errors.some(P=>P.startsWith("HOOK_INSTALL_FAILED")))??!1;if(r({type:"success",message:n("workspace.createModal.success")}),I){w(n("workspace.createModal.error.HOOK_INSTALL_FAILED"));return}await mB(gB),e()}catch($){f(!1),u("confirm-init"),b(0),p(xB($))}}},z=()=>S?g.jsxs("div",{className:"rounded-lg border border-red-200 bg-red-50 px-3 py-3 text-sm text-red-700",children:[g.jsx("p",{children:S}),d==="WORKSPACE_LIMIT_EXCEEDED"?g.jsx("a",{href:_p,target:"_blank",rel:"noopener noreferrer",className:"mt-3 inline-flex items-center gap-1 text-sm font-medium text-red-700 transition-colors hover:text-red-800 hover:underline",children:n("upgrade.waitlistCta")}):null]}):null;return g.jsxs("div",{"data-testid":"create-workspace-modal-backdrop",className:"fixed inset-0 z-50 flex items-center justify-center bg-black/40 p-4",onClick:()=>{E||e()},children:[g.jsxs("div",{role:"dialog","aria-modal":"true","aria-labelledby":"create-workspace-modal-title",className:"w-full max-w-lg rounded-2xl border border-gray-200 bg-white shadow-xl",onClick:D=>D.stopPropagation(),children:[g.jsxs("div",{className:"flex items-start justify-between gap-4 border-b border-gray-200 px-6 py-5",children:[g.jsxs("div",{children:[g.jsx("h2",{id:"create-workspace-modal-title",className:"text-lg font-semibold text-gray-900",children:n("workspace.createModal.title")}),g.jsx("p",{className:"mt-1 text-sm text-gray-500",children:n("workspace.createModal.description")})]}),g.jsx("button",{type:"button",onClick:e,disabled:E,className:"rounded-lg bg-gray-100 p-2 text-gray-500 transition-colors hover:bg-gray-200 hover:text-gray-700 disabled:cursor-not-allowed disabled:opacity-50","aria-label":n("common.close"),children:g.jsx(Xa,{size:16})})]}),g.jsxs("div",{className:"space-y-4 px-6 py-5",children:[c==="form"?g.jsxs(g.Fragment,{children:[g.jsxs("div",{children:[g.jsx("label",{htmlFor:"workspace-path",className:"mb-1 block text-sm font-medium text-gray-700",children:n("workspace.createModal.pathLabel")}),g.jsxs("div",{className:"flex gap-2",children:[g.jsx("input",{id:"workspace-path",type:"text",value:s,onChange:D=>{o(D.target.value),p(null)},placeholder:n("workspace.createModal.pathPlaceholder"),className:"min-w-0 flex-1 rounded-lg border border-gray-200 px-3 py-2 text-sm text-gray-900 shadow-sm outline-none transition-colors placeholder:text-gray-400 focus:border-blue-500 focus:ring-2 focus:ring-blue-100"}),g.jsx("button",{type:"button",onClick:()=>C(!0),disabled:h,className:"shrink-0 rounded-lg bg-gray-100 px-4 py-2 text-sm font-medium text-gray-700 transition-colors hover:bg-gray-200 disabled:cursor-not-allowed disabled:opacity-50",children:n("workspace.createModal.browse")})]})]}),g.jsxs("div",{children:[g.jsx("label",{htmlFor:"workspace-slug",className:"mb-1 block text-sm font-medium text-gray-700",children:n("workspace.createModal.slugLabel")}),g.jsx("input",{id:"workspace-slug",type:"text",value:a,onChange:D=>l(D.target.value),placeholder:n("workspace.createModal.slugPlaceholder"),className:"w-full rounded-lg border border-gray-200 px-3 py-2 text-sm text-gray-900 shadow-sm outline-none transition-colors placeholder:text-gray-400 focus:border-blue-500 focus:ring-2 focus:ring-blue-100"})]}),z()]}):null,c==="confirm-init"?g.jsxs(g.Fragment,{children:[g.jsxs("div",{className:"space-y-2",children:[g.jsx("h3",{className:"text-base font-semibold text-gray-900",children:n("workspace.createModal.confirmInit.title")}),g.jsx("p",{className:"text-sm text-gray-600",children:n("workspace.createModal.confirmInit.description")})]}),g.jsxs("div",{className:"rounded-lg border border-gray-200 bg-gray-50 px-4 py-3",children:[g.jsx("p",{className:"text-xs font-medium uppercase tracking-wide text-gray-500",children:n("workspace.createModal.confirmInit.pathLabel")}),g.jsx("p",{className:"mt-1 break-all text-sm text-gray-900",children:m??s.trim()})]}),g.jsxs("div",{className:"rounded-lg border border-gray-200 bg-gray-50 px-4 py-3",children:[g.jsx("p",{className:"text-xs font-medium uppercase tracking-wide text-gray-500",children:n("workspace.createModal.confirmInit.filesLabel")}),g.jsx("ul",{className:"mt-2 space-y-2 text-sm text-gray-700",children:M.map(D=>g.jsx("li",{children:D},D))})]}),z()]}):null,c==="initializing"?g.jsxs(g.Fragment,{children:[g.jsxs("div",{className:"space-y-2",children:[g.jsx("h3",{className:"text-base font-semibold text-gray-900",children:n("workspace.createModal.initProgress.title")}),g.jsx("p",{className:"text-sm text-gray-600",children:n("workspace.createModal.initProgress.description")})]}),g.jsxs("div",{className:"space-y-3 rounded-xl bg-gray-50 p-4",children:[g.jsx(Xv,{label:n("workspace.createModal.initProgress.step1"),status:Kv(1,x,h)}),g.jsx(Xv,{label:n("workspace.createModal.initProgress.step2"),status:Kv(2,x,h)}),g.jsx(Xv,{label:n("workspace.createModal.initProgress.step3"),status:Kv(3,x,h)})]}),k?g.jsx("div",{className:"rounded-lg border border-amber-200 bg-amber-50 px-4 py-3 text-sm text-amber-900",children:g.jsxs("div",{className:"flex items-start gap-3",children:[g.jsx(FT,{size:18,className:"mt-0.5 shrink-0 text-amber-600"}),g.jsxs("div",{className:"space-y-3",children:[g.jsx("p",{children:k}),g.jsx("button",{type:"button",onClick:e,className:"font-medium text-amber-900 underline underline-offset-2",children:n("common.close")})]})]})}):null]}):null]}),c!=="initializing"?g.jsx("div",{className:"flex items-center justify-end gap-2 border-t border-gray-200 px-6 py-4",children:c==="form"?g.jsxs(g.Fragment,{children:[g.jsx("button",{type:"button",onClick:e,disabled:E,className:"rounded-lg bg-gray-100 px-4 py-2 text-sm font-medium text-gray-700 transition-colors hover:bg-gray-200 disabled:cursor-not-allowed disabled:opacity-50",children:n("workspace.createModal.cancel")}),g.jsxs("button",{type:"button",onClick:()=>{A()},disabled:!s.trim()||h,className:"inline-flex items-center gap-2 rounded-lg bg-blue-600 px-4 py-2 text-sm font-medium text-white transition-colors hover:bg-blue-700 disabled:cursor-not-allowed disabled:bg-blue-300",children:[h?g.jsx(ut,{size:14,className:"animate-spin"}):null,n("workspace.createModal.submit")]})]}):g.jsxs(g.Fragment,{children:[g.jsx("button",{type:"button",onClick:B,disabled:h,className:"rounded-lg bg-gray-100 px-4 py-2 text-sm font-medium text-gray-700 transition-colors hover:bg-gray-200 disabled:cursor-not-allowed disabled:opacity-50",children:n("workspace.createModal.confirmInit.back")}),g.jsxs("button",{type:"button",onClick:()=>{F()},disabled:!m||h,className:"inline-flex items-center gap-2 rounded-lg bg-blue-600 px-4 py-2 text-sm font-medium text-white transition-colors hover:bg-blue-700 disabled:cursor-not-allowed disabled:bg-blue-300",children:[h?g.jsx(ut,{size:14,className:"animate-spin"}):null,n("workspace.createModal.confirmInit.confirm")]})]})}):null]}),g.jsx(cHe,{open:v,initialPath:s.trim()||void 0,onClose:()=>C(!1),onSelect:D=>{o(D),p(null)}})]})}function uHe(t){if(!t)return"—";const n=/^\/Users\/([^/]+)(\/.*)?$/.exec(t);return n?`~${n[2]??""}`:t}function hHe(t,e){const n=new Date(t);return Number.isNaN(n.getTime())?t:new Intl.DateTimeFormat(e,{dateStyle:"medium",timeStyle:"short"}).format(n)}function dHe(){const{t,i18n:e}=me(),n=Nt(),{setPageHeader:r}=ur(),[i,s]=T.useState(!1),o=yn(v=>v.workspaces),a=yn(v=>v.currentWorkspace),l=yn(v=>v.loading),c=yn(v=>v.currentLoading),u=yn(v=>v.limitsLoading),h=yn(v=>v.error),f=yn(v=>v.limits),d=yn(v=>v.fetchLimits),p=yn(v=>v.initialize),m=f==null?void 0:f.workspaces,y=m!==void 0&&m!==-1&&o.length>=m,x=u||!f||y,b=y&&f?t("limits.banner.workspace.title",{current:o.length,limit:f.workspaces}):void 0;T.useEffect(()=>{r({title:t("workspace.title"),actions:g.jsxs("button",{type:"button",disabled:x,title:b,onClick:()=>s(!0),className:`inline-flex items-center gap-2 rounded-lg border px-4 py-2 text-sm font-medium transition-colors ${x?"border-gray-200 bg-white text-gray-400":"border-blue-600 bg-blue-600 text-white hover:bg-blue-700"}`,children:[g.jsx(Kr,{size:16}),g.jsx("span",{children:t("workspace.create")})]})})},[b,x,r,t]),T.useEffect(()=>{p().catch(()=>{})},[p]),T.useEffect(()=>{d().catch(()=>{})},[d]);const k=T.useMemo(()=>a,[a]),w=v=>{if(v.id===(k==null?void 0:k.id)){n("/");return}BF(v).then(()=>n("/")).catch(()=>{})};return(l||c)&&o.length===0?g.jsx("div",{className:"rounded-2xl border border-gray-200 bg-white px-6 py-16 text-center text-sm text-gray-500",children:t("workspace.loading")}):h&&o.length===0?g.jsx("div",{className:"rounded-xl border border-amber-200 bg-amber-50 px-4 py-4 text-sm text-amber-800",children:h}):o.length===0?g.jsxs(g.Fragment,{children:[y&&f?g.jsx(f_,{resource:"workspace",current:o.length,limit:f.workspaces}):null,g.jsxs("div",{className:"rounded-2xl border border-dashed border-gray-300 bg-white px-6 py-16 text-center shadow-sm",children:[g.jsx(is,{className:"mx-auto h-10 w-10 text-gray-300"}),g.jsx("h2",{className:"mt-4 text-xl font-semibold text-gray-900",children:t("workspace.emptyTitle")}),g.jsx("p",{className:"mt-2 text-sm text-gray-500",children:t("workspace.emptyDescription")}),g.jsxs("button",{type:"button",disabled:x,title:b,onClick:()=>s(!0),className:`mt-6 inline-flex items-center gap-2 rounded-lg border px-4 py-2 text-sm font-medium transition-colors ${x?"border-gray-200 bg-gray-50 text-gray-400":"border-blue-600 bg-blue-600 text-white hover:bg-blue-700"}`,children:[g.jsx(Kr,{size:16}),g.jsx("span",{children:t("workspace.create")})]})]}),g.jsx(bB,{open:i,onClose:()=>s(!1)})]}):g.jsxs(g.Fragment,{children:[g.jsxs("div",{className:"mx-auto flex max-w-6xl flex-col gap-6",children:[y&&f?g.jsx(f_,{resource:"workspace",current:o.length,limit:f.workspaces}):null,g.jsx("div",{className:"grid grid-cols-1 gap-4 xl:grid-cols-2",children:o.map(v=>{const C=(k==null?void 0:k.id)===v.id;return g.jsxs("button",{type:"button",onClick:()=>w(v),className:`rounded-2xl border px-5 py-5 text-left shadow-sm transition-colors ${C?"border-blue-200 bg-blue-50":"border-gray-200 bg-white hover:border-gray-300 hover:bg-gray-50"}`,children:[g.jsxs("div",{className:"flex items-start justify-between gap-3",children:[g.jsxs("div",{className:"min-w-0",children:[g.jsxs("div",{className:"flex items-center gap-2",children:[g.jsx(is,{size:18,className:C?"text-blue-600":"text-gray-400"}),g.jsx("h2",{className:"truncate text-lg font-semibold text-gray-900",children:v.name})]}),g.jsx("p",{className:"mt-2 truncate text-sm text-gray-500",children:uHe(v.workspace_path)})]}),v.is_current?g.jsx("span",{className:"rounded-full bg-white px-2.5 py-1 text-xs font-medium text-blue-700",children:t("workspace.currentBadge")}):null]}),g.jsxs("div",{className:"mt-5 grid grid-cols-2 gap-3 text-sm",children:[g.jsxs("div",{className:"rounded-xl bg-gray-50 px-3 py-3",children:[g.jsx("p",{className:"text-xs font-medium uppercase tracking-wide text-gray-400",children:t("workspace.slug")}),g.jsx("p",{className:"mt-1 truncate font-medium text-gray-800",children:v.slug})]}),g.jsxs("div",{className:"rounded-xl bg-gray-50 px-3 py-3",children:[g.jsx("p",{className:"text-xs font-medium uppercase tracking-wide text-gray-400",children:t("workspace.updatedAt")}),g.jsx("p",{className:"mt-1 truncate font-medium text-gray-800",children:hHe(v.updated_at,e.language)})]})]})]},v.id)})})]}),g.jsx(bB,{open:i,onClose:()=>s(!1)})]})}function fHe({cli:t,version:e,authenticated:n,selected:r,disabled:i,onToggle:s}){const{t:o}=me(),a=i?"border-gray-200 bg-gray-100":n===!0?"border-green-300 bg-green-50":n===!1?"border-amber-300 bg-amber-50":"border-blue-300 bg-blue-50",l=()=>{i||s(!r)};return g.jsxs("button",{type:"button",onClick:l,disabled:i,className:`w-full flex items-center gap-3 p-4 rounded-lg border-2 transition-colors text-left ${a} ${i?"opacity-60 cursor-not-allowed":"cursor-pointer hover:shadow-sm"}`,children:[g.jsxs("div",{className:"flex-1 min-w-0",children:[g.jsx("div",{className:"font-medium text-gray-900",children:t.displayName}),g.jsx("div",{className:"text-sm text-gray-600 mt-0.5",children:t.installed?g.jsxs(g.Fragment,{children:[g.jsx("span",{children:o("onboarding.s1.statusInstalled",{version:e})}),g.jsx("span",{className:"mx-1.5",children:"·"}),n===!0&&g.jsxs("span",{className:"text-green-600",children:[g.jsx(Us,{className:"inline w-3.5 h-3.5 mr-0.5"}),o("onboarding.s1.authLoggedIn")]}),n===!1&&g.jsxs("span",{className:"text-amber-600",children:[g.jsx(FT,{className:"inline w-3.5 h-3.5 mr-0.5"}),o("onboarding.s1.authRequired")]}),n===null&&g.jsxs("span",{className:"text-blue-600",children:[g.jsx(JC,{className:"inline w-3.5 h-3.5 mr-0.5"}),o("onboarding.s1.authUnknown")]})]}):g.jsx("span",{className:"text-gray-400",children:o("onboarding.s1.statusNotInstalled")})})]}),g.jsx("div",{className:"flex-shrink-0",children:g.jsx("div",{className:`w-5 h-5 rounded border-2 flex items-center justify-center ${r?"bg-blue-500 border-blue-500":"border-gray-300 bg-white"} ${i?"opacity-50":""}`,children:r&&g.jsx(Us,{className:"w-3.5 h-3.5 text-white"})})})]})}function pHe({onNext:t}){const{t:e}=me(),[n,r]=T.useState([]),[i,s]=T.useState(new Set),[o,a]=T.useState(!0),[l,c]=T.useState(!1),u=async()=>{a(!0),c(!1);try{const p=(await fe.getVersions()).filter(x=>x.name!=="crewx"),m=await Promise.all(p.map(async x=>{if(!x.installed)return{...x};try{const b=await fe.check(x.name);return{...x,checkResult:b}}catch{return{...x}}}));r(m);const y=new Set(m.filter(x=>x.installed).map(x=>x.name));s(y)}catch{c(!0)}finally{a(!1)}};T.useEffect(()=>{u()},[]);const h=(d,p)=>{s(m=>{const y=new Set(m);return p?y.add(d):y.delete(d),y})},f=()=>{const d=n.filter(p=>i.has(p.name));t(d)};return o?g.jsxs("div",{className:"flex flex-col items-center gap-3 py-12",children:[g.jsx(ut,{className:"w-8 h-8 animate-spin text-blue-500"}),g.jsx("p",{className:"text-gray-500",children:e("onboarding.s1.loadingCards")})]}):l?g.jsxs("div",{className:"flex flex-col items-center gap-3 py-12",children:[g.jsx("p",{className:"text-gray-900 font-medium",children:e("onboarding.s1.errorTitle")}),g.jsx("p",{className:"text-gray-500",children:e("onboarding.s1.errorDesc")}),g.jsx("button",{type:"button",onClick:u,className:"px-4 py-2 bg-blue-500 text-white rounded-lg hover:bg-blue-600",children:e("onboarding.common.retry")})]}):g.jsxs("div",{className:"space-y-4",children:[n.map(d=>{var p;return g.jsx(fHe,{cli:d,version:d.currentVersion??void 0,authenticated:((p=d.checkResult)==null?void 0:p.authenticated)??null,selected:i.has(d.name),disabled:!d.installed,onToggle:m=>h(d.name,m)},d.name)}),g.jsxs("div",{className:"pt-4",children:[g.jsx("button",{type:"button",onClick:f,disabled:i.size===0,className:"w-full px-6 py-3 bg-blue-500 text-white rounded-lg hover:bg-blue-600 disabled:opacity-50 disabled:cursor-not-allowed font-medium",children:e("onboarding.common.next")}),i.size===0&&g.jsx("p",{className:"text-sm text-amber-600 text-center mt-2",children:e("onboarding.s1.noToolsSelected")})]})]})}const kB=["onboarding.bubble.welcome","onboarding.bubble.tip1","onboarding.bubble.tip2","onboarding.bubble.tip3"];function gHe(){const{t}=me(),[e,n]=T.useState(0);return T.useEffect(()=>{const r=setInterval(()=>{n(i=>(i+1)%kB.length)},5e3);return()=>clearInterval(r)},[]),g.jsxs("div",{className:"fixed top-6 right-6 flex items-start gap-2 z-50",children:[g.jsx("div",{className:"bg-white border border-gray-200 rounded-xl shadow-lg px-4 py-3 max-w-[240px] text-sm text-gray-700",children:t(kB[e])}),g.jsx("div",{className:"w-10 h-10 bg-blue-500 rounded-full flex items-center justify-center flex-shrink-0 shadow-lg",children:g.jsx(BT,{className:"w-5 h-5 text-white"})})]})}function mHe({selectedCLIs:t,onNext:e,onPrev:n}){const{t:r}=me(),[i,s]=T.useState(new Map),[o,a]=T.useState(null),l=t.filter(d=>{var p;return d.name!=="crewx"&&((p=d.checkResult)==null?void 0:p.authenticated)!==!0}),c=l.filter(d=>{var p;return((p=d.checkResult)==null?void 0:p.authenticated)!==null}),u=T.useCallback(async()=>{for(const d of c)if(i.get(d.name)!==!0)try{(await fe.check(d.name)).authenticated===!0&&s(m=>new Map(m).set(d.name,!0))}catch{}},[i,c]);TN(u,{interval:5e3,enabled:c.length>0}),T.useEffect(()=>{l.length===0&&e()},[l.length,e]);const h=c.every(d=>i.get(d.name)===!0),f=async(d,p)=>{await navigator.clipboard.writeText(d),a(p),setTimeout(()=>a(null),2e3)};return l.length===0?null:g.jsxs("div",{className:"space-y-6",children:[g.jsx(gHe,{}),l.map(d=>{var x,b;const p=i.get(d.name)===!0,m=((x=d.checkResult)==null?void 0:x.loginCommand)??"",y=((b=d.checkResult)==null?void 0:b.authenticated)===null||!m;return g.jsxs("div",{className:"bg-white border border-gray-200 rounded-lg p-4 space-y-3",children:[g.jsxs("div",{className:"flex items-center justify-between",children:[g.jsxs("div",{className:"font-medium text-gray-900",children:[d.displayName,g.jsx("span",{className:"ml-2 text-sm text-gray-500",children:r(p?"onboarding.s2.loginComplete":y?"onboarding.s2.manualCheck":"onboarding.s2.loginRequired")})]}),!p&&m&&g.jsx("button",{type:"button",onClick:()=>f(m,d.name),className:"px-3 py-1.5 bg-blue-500 text-white text-sm rounded-lg hover:bg-blue-600",children:r("onboarding.s2.loginButton")}),p&&g.jsxs("span",{className:"text-green-600 font-medium text-sm",children:[g.jsx(Us,{className:"inline w-4 h-4 mr-1"}),r("onboarding.s2.loginComplete")]})]}),!p&&m&&g.jsxs("div",{className:"bg-gray-900 rounded-lg p-3 font-mono text-sm text-gray-100 flex items-center justify-between",children:[g.jsxs("code",{children:["$ ",m]}),g.jsx("button",{type:"button",onClick:()=>f(m,d.name),className:"ml-2 text-gray-400 hover:text-white flex items-center gap-1 text-xs",children:o===d.name?g.jsxs(g.Fragment,{children:[g.jsx(Us,{className:"w-3.5 h-3.5"})," ",r("onboarding.s2.copied")]}):g.jsxs(g.Fragment,{children:[g.jsx(yg,{className:"w-3.5 h-3.5"})," ",r("onboarding.s2.copy")]})})]}),!p&&g.jsx("p",{className:"text-xs text-gray-500",children:r(y?"onboarding.s2.manualCheck":"onboarding.s2.terminalHint")})]},d.name)}),!h&&g.jsxs("div",{className:"flex items-center justify-center gap-2 text-sm text-gray-500",children:[g.jsx(ut,{className:"w-4 h-4 animate-spin"}),r("onboarding.s2.polling")]}),h&&g.jsx("p",{className:"text-center text-green-600 font-medium",children:r("onboarding.s2.allDone")}),g.jsxs("div",{className:"flex gap-3 pt-2",children:[g.jsx("button",{type:"button",onClick:n,className:"flex-1 px-6 py-3 bg-gray-100 text-gray-700 rounded-lg hover:bg-gray-200 font-medium",children:r("onboarding.common.prev")}),g.jsx("button",{type:"button",onClick:e,className:`flex-1 px-6 py-3 rounded-lg font-medium bg-blue-500 text-white hover:bg-blue-600 ${h?"animate-pulse shadow-lg shadow-blue-200":""}`,children:r("onboarding.common.next")})]})]})}function yHe({preset:t,onSelect:e,loading:n}){const{t:r}=me(),i=t.id==="custom";return g.jsxs("div",{className:`rounded-lg p-5 shadow-sm flex flex-col items-center text-center transition-shadow ${i?"bg-blue-50 border-2 border-dashed border-blue-300 hover:shadow-md":"bg-white border border-gray-200 hover:shadow-md"}`,children:[g.jsx("div",{className:`mb-2 flex h-12 w-12 items-center justify-center rounded-full ${i?"bg-white text-blue-500":""}`,children:i?g.jsx(Kr,{className:"h-7 w-7"}):g.jsx("span",{className:"text-3xl",children:t.icon})}),g.jsx("div",{className:"font-semibold text-gray-900 mb-1",children:t.name}),g.jsx("div",{className:"text-sm text-gray-500 mb-1",children:t.description}),g.jsx("div",{className:"text-xs text-gray-400 mb-3",children:r("onboarding.s3.agentCount",{count:t.agentCount})}),g.jsx("button",{type:"button",onClick:()=>e(t.id),disabled:n,className:`w-full px-4 py-2 rounded-lg disabled:opacity-50 disabled:cursor-not-allowed text-sm font-medium ${i?"bg-white text-blue-600 border border-blue-200 hover:bg-blue-100":"bg-blue-500 text-white hover:bg-blue-600"}`,children:n?g.jsxs("span",{className:"flex items-center justify-center gap-2",children:[g.jsx(ut,{className:"w-4 h-4 animate-spin"}),r("onboarding.s3.applying")]}):r(i?"onboarding.s3.customBuild":"onboarding.s3.selectPreset")})]})}function xHe({onPrev:t,onDismissAndExit:e}){const{t:n}=me(),r=Nt(),[i,s]=T.useState([]),[o,a]=T.useState(!0),[l,c]=T.useState(null),[u,h]=T.useState(null),[f,d]=T.useState(!1);T.useEffect(()=>{fe.getOnboardingPresets().then(y=>s(y.presets)).catch(()=>h(n("onboarding.s3.applyError"))).finally(()=>a(!1))},[n]);const p=async y=>{if(y==="custom"){c(y),h(null);try{await e()}catch{h(n("onboarding.common.dismissError"))}finally{c(null)}return}c(y),h(null);try{await fe.applyOnboardingPreset(y),zs("onboarding_step_complete",{step_id:"S3"}),r("/",{replace:!0})}catch(x){x instanceof Error&&x.message.includes("409")?(h(n("onboarding.s3.applyConflict",{count:0})),setTimeout(()=>r("/",{replace:!0}),2e3)):h(n("onboarding.s3.applyError"))}finally{c(null)}},m=async()=>{d(!0),h(null);try{await e(),zs("onboarding_step_complete",{step_id:"S3"})}catch{h(n("onboarding.common.dismissError"))}finally{d(!1)}};return o?g.jsx("div",{className:"flex items-center justify-center py-12",children:g.jsx(ut,{className:"w-8 h-8 animate-spin text-blue-500"})}):g.jsxs("div",{className:"space-y-6",children:[g.jsx("div",{className:"grid grid-cols-2 sm:grid-cols-3 gap-4",children:i.map(y=>g.jsx(yHe,{preset:y,onSelect:p,loading:l===y.id},y.id))}),u&&g.jsx("p",{className:"text-center text-red-500 text-sm",children:u}),g.jsxs("div",{className:"flex gap-3 pt-2",children:[g.jsx("button",{type:"button",onClick:t,className:"flex-1 px-6 py-3 bg-gray-100 text-gray-700 rounded-lg hover:bg-gray-200 font-medium",children:n("onboarding.common.prev")}),g.jsx("button",{type:"button",onClick:m,disabled:f,className:"flex-1 px-6 py-3 bg-blue-500 text-white rounded-lg hover:bg-blue-600 font-medium disabled:opacity-50 disabled:cursor-not-allowed",children:n("onboarding.common.start")})]})]})}const rK=["#step1","#step2","#step3"],bHe=3;function Zv(t){return rK.includes(t)?t:"#step1"}function kHe(t){return rK.indexOf(t)+1}function wHe(){const{t}=me(),e=Nt(),n=cr(),[r,i]=T.useState(()=>Zv(n.hash||"#step1")),[s,o]=T.useState([]),[a,l]=T.useState(!1),[c,u]=T.useState(null);T.useEffect(()=>{const x=Zv(n.hash);i(x),n.hash!==x&&(window.location.hash=x)},[n.hash]),T.useEffect(()=>{const x=()=>{i(Zv(window.location.hash))};return window.addEventListener("hashchange",x),()=>window.removeEventListener("hashchange",x)},[]),T.useEffect(()=>{window.location.hash||(window.location.hash="#step1")},[]);const h=T.useCallback(x=>{window.location.hash=x,i(x)},[]);T.useEffect(()=>{r!=="#step1"&&s.length===0&&h("#step1")},[r,s.length,h]);const f=T.useCallback(async()=>{u(null);try{await fe.dismissOnboarding(),e("/",{replace:!0})}catch{throw u(t("onboarding.common.dismissError")),new Error("dismiss-onboarding-failed")}},[e,t]),d=()=>{f().catch(()=>{})},p=x=>{o(x),zs("onboarding_step_complete",{step_id:"S1"});const b=x.every(k=>{var w;return((w=k.checkResult)==null?void 0:w.authenticated)===!0});l(b),h(b?"#step3":"#step2")},m=a?2:bHe,y=a&&r==="#step3"?2:kHe(r);return g.jsxs("div",{className:"min-h-screen bg-gray-50 flex flex-col",children:[g.jsxs("div",{className:"text-center pt-12 pb-6",children:[g.jsx("p",{className:"text-sm text-gray-500 mb-2",children:t("onboarding.common.stepOf",{current:y,total:m})}),g.jsxs("h1",{className:"text-2xl font-bold text-gray-900",children:[r==="#step1"&&t("onboarding.s1.title"),r==="#step2"&&t("onboarding.s2.title"),r==="#step3"&&t("onboarding.s3.title")]}),r==="#step1"&&g.jsx("p",{className:"text-gray-500 mt-2",children:t("onboarding.s1.subtitle")}),r==="#step3"&&g.jsx("p",{className:"text-gray-500 mt-2",children:t("onboarding.s3.subtitle")})]}),g.jsxs("div",{className:`flex-1 mx-auto w-full px-4 pb-8 ${r==="#step3"?"max-w-4xl":"max-w-lg"}`,children:[r==="#step1"&&g.jsx(pHe,{onNext:p}),r==="#step2"&&s.length>0&&g.jsx(mHe,{selectedCLIs:s,onNext:()=>{zs("onboarding_step_complete",{step_id:"S2"}),h("#step3")},onPrev:()=>h("#step1")}),r==="#step3"&&g.jsx(xHe,{onPrev:()=>h(a?"#step1":"#step2"),onDismissAndExit:f}),g.jsxs("div",{className:"text-center mt-6",children:[c&&g.jsx("p",{className:"mb-3 text-sm text-red-500",children:c}),g.jsx("button",{type:"button",onClick:d,className:"text-sm text-gray-400 hover:text-gray-600 underline",children:t("onboarding.common.skip")})]})]})]})}function vHe(){const[t,e]=T.useState("loading");return T.useEffect(()=>{fe.getOnboardingStatus().then(n=>{e(n.needsOnboarding?"needs":"done")}).catch(()=>{e("done")})},[]),t==="loading"?g.jsx("div",{"data-testid":"onboarding-guard-loading",className:"flex items-center justify-center h-screen bg-gray-50",children:g.jsx(ut,{className:"w-8 h-8 animate-spin text-blue-500"})}):t==="needs"?g.jsx(ef,{to:"/onboarding",replace:!0}):g.jsx(sF,{})}class CHe extends T.Component{constructor(){super(...arguments);pe(this,"state",{hasError:!1})}static getDerivedStateFromError(){return{hasError:!0}}componentDidCatch(n,r){Bie(Pie(n)),console.error("ErrorBoundary caught an error",n,r)}render(){return this.state.hasError?this.props.fallback:this.props.children}}function SHe({routes:t}){const{pathname:e}=cr();return T.useEffect(()=>{var i;const n=vT(t,{pathname:e}),r=(i=n==null?void 0:n.at(-1))==null?void 0:i.route.handle;r!=null&&r.screenId&&(r.manualTracking||vF(r.screenId,r.screenTitle))},[e,t]),null}const _He={success:{container:"border-emerald-200 bg-emerald-50 text-emerald-700",icon:g.jsx(dF,{size:18,className:"shrink-0"})},error:{container:"border-red-200 bg-red-50 text-red-700",icon:g.jsx(Rn,{size:18,className:"shrink-0"})},info:{container:"border-blue-200 bg-blue-50 text-blue-700",icon:g.jsx(IT,{size:18,className:"shrink-0"})}};function THe(){const t=ul(e=>e.toasts);return t.length===0?null:g.jsx("div",{className:"pointer-events-none fixed bottom-6 right-6 z-50 flex w-full max-w-sm flex-col gap-3 px-4 sm:w-auto sm:px-0",children:t.map(e=>{const n=_He[e.type];return g.jsxs("div",{role:e.type==="error"?"alert":"status","aria-live":e.type==="error"?"assertive":"polite",className:`pointer-events-auto flex items-start gap-3 rounded-lg border px-4 py-3 text-sm font-medium shadow-lg ${n.container}`,children:[n.icon,g.jsx("div",{className:"min-w-0 flex-1 leading-5",children:e.message})]},e.id)})})}function EHe(){const{t}=me(),e=$l(o=>o.phase),n=$l(o=>o.targetWorkspace),r=$l(o=>o.error),i=$l(o=>o.clear);if(e==="idle")return null;const s=e==="error";return g.jsx("div",{className:"fixed inset-0 z-[100] flex items-center justify-center bg-gray-950/45 px-4",children:g.jsxs("div",{className:"w-full max-w-md rounded-2xl border border-gray-200 bg-white p-6 shadow-xl",children:[g.jsx("div",{className:`flex h-12 w-12 items-center justify-center rounded-full ${s?"bg-red-50 text-red-500":"bg-blue-50 text-blue-500"}`,children:s?g.jsx(Rn,{size:22}):g.jsx(ut,{size:22,className:"animate-spin"})}),g.jsx("h2",{className:"mt-4 text-lg font-semibold text-gray-900",children:t(s?"workspace.switchErrorTitle":"workspace.switchingTitle")}),g.jsx("p",{className:"mt-2 text-sm text-gray-500",children:s?r||t("workspace.switchErrorDescription"):t("workspace.switchingDescription",{name:(n==null?void 0:n.name)??""})}),s?g.jsx("div",{className:"mt-5",children:g.jsx("button",{type:"button",onClick:i,className:"inline-flex items-center justify-center rounded-lg bg-gray-900 px-4 py-2 text-sm font-medium text-white transition-colors hover:bg-gray-800",children:t("common.close")})}):null]})})}const AHe=T.lazy(()=>et(()=>import("./MarketPage-CyYkZIcw.js"),[],import.meta.url));function $t(t,e,n){return{screenId:t,screenTitle:e,...n}}const iK=fte(g.jsxs(g.Fragment,{children:[g.jsx(pt,{path:"/onboarding",element:g.jsx(wHe,{}),handle:$t("ONBUI001","온보딩 위자드")}),g.jsx(pt,{element:g.jsx(vHe,{}),children:g.jsxs(pt,{element:g.jsx(Bse,{}),children:[g.jsx(pt,{path:"/",element:g.jsx(aB,{}),handle:$t("THDUI000","새 대화")}),g.jsx(pt,{path:"/tasks",element:g.jsx(TFe,{}),handle:$t("TSKUI001","태스크 목록")}),g.jsx(pt,{path:"/tasks/:taskId",element:g.jsx(iFe,{}),handle:$t("TSKUI002","태스크 상세")}),g.jsx(pt,{path:"/threads/new",element:g.jsx(aB,{}),handle:$t("THDUI000","새 대화")}),g.jsx(pt,{path:"/threads",element:g.jsx(I7e,{}),handle:$t("THDUI001","대화 목록")}),g.jsx(pt,{path:"/threads/:threadId",element:g.jsx(j7e,{}),handle:$t("THDUI002","대화창")}),g.jsx(pt,{path:"/workspaces",element:g.jsx(dHe,{}),handle:$t("WKSUI001","워크스페이스 관리")}),g.jsx(pt,{path:"/projects",element:g.jsx(q7e,{}),handle:$t("PJTUI000","프로젝트 목록")}),g.jsx(pt,{path:"/projects/new",element:g.jsx(Y7e,{}),handle:$t("PJTUI002","프로젝트 생성")}),g.jsx(pt,{path:"/projects/:id",element:g.jsx(J7e,{}),handle:$t("PJTUI001","프로젝트 상세")}),g.jsx(pt,{path:"/search",element:g.jsx(A7e,{}),handle:{screenId:"SRCHUI001",screenTitle:"통합 검색"}}),g.jsx(pt,{path:"/docs",element:g.jsx(T7e,{}),handle:$t("DOCUI001","문서 관리")}),g.jsx(pt,{path:"/workflows",element:g.jsx(nHe,{}),handle:$t("WFLUI001","워크플로 목록")}),g.jsx(pt,{path:"/workflows/:id",element:g.jsx(iHe,{}),handle:$t("WFLUI002","워크플로 상세",{manualTracking:!0})}),g.jsx(pt,{path:"/market",element:g.jsx(T.Suspense,{fallback:g.jsx("div",{className:"flex items-center justify-center py-16",children:g.jsx("div",{className:"h-6 w-6 animate-spin rounded-full border-2 border-gray-300 border-t-blue-500"})}),children:g.jsx(AHe,{})}),handle:$t("MKTUI001","마켓")}),g.jsx(pt,{path:"/agents",element:g.jsx(zFe,{}),handle:$t("AGTUI001","에이전트 관리")}),g.jsx(pt,{path:"/agents/new",element:g.jsx(y4,{}),handle:$t("AGTUI002","에이전트 추가/편집")}),g.jsx(pt,{path:"/agents/:agentId/edit",element:g.jsx(y4,{}),handle:$t("AGTUI002","에이전트 추가/편집")}),g.jsx(pt,{path:"/skills",element:g.jsx(ef,{to:"/market",replace:!0})}),g.jsx(pt,{path:"/cli",element:g.jsx(Qse,{}),handle:$t("CLIVUI001","CLI 버전 관리")}),g.jsx(pt,{path:"/usage",element:g.jsx(Zce,{}),handle:$t("USGUI002","Usage 사용량")}),g.jsx(pt,{path:"/memory",element:g.jsx(ef,{to:"/docs",replace:!0}),handle:$t("DOCUI001","문서 관리")}),g.jsx(pt,{path:"/graph",element:g.jsx(ef,{to:"/docs",replace:!0}),handle:$t("DOCUI001","문서 관리")}),g.jsx(pt,{path:"/wbs/*",element:g.jsx(ef,{to:"/",replace:!0}),handle:$t("THDUI000","새 대화")}),g.jsx(pt,{path:"/settings",element:g.jsx(aue,{}),handle:$t("STGUI001","환경 설정")})]})})]}));function NHe(){const{t}=me();return g.jsx("div",{className:"flex min-h-screen items-center justify-center bg-gray-50 px-4",children:g.jsxs("div",{className:"w-full max-w-md rounded-lg border border-red-200 bg-white p-6 text-center shadow-sm",children:[g.jsx("h1",{className:"text-lg font-semibold text-gray-900",children:t("common.somethingWentWrong")}),g.jsx("p",{className:"mt-2 text-sm text-gray-500",children:t("common.tryRefreshingPage")}),g.jsx("button",{type:"button",onClick:()=>window.location.reload(),className:"mt-5 inline-flex items-center justify-center rounded-lg bg-blue-500 px-4 py-2 text-sm font-medium text-white transition-colors hover:bg-blue-600",children:t("common.refresh")})]})})}function MHe(){return Jee(iK)}function LHe(){const t=Pa(e=>e.ui.theme);return T.useEffect(()=>{zse(t)},[t]),g.jsx(Fte,{children:g.jsx(CHe,{fallback:g.jsx(NHe,{}),children:g.jsxs(g.Fragment,{children:[g.jsx(SHe,{routes:iK}),g.jsx(MHe,{}),g.jsx(THe,{}),g.jsx(EHe,{})]})})})}Rie();Qv.createRoot(document.getElementById("root")).render(g.jsx(sr.StrictMode,{children:g.jsx(LHe,{})}));export{q8 as $,zHe as A,ja as B,Bxe as C,Gt as D,p1e as E,hA as F,R8 as G,W_e as H,Gve as I,JCe as J,xbe as K,Op as L,$He as M,I1 as N,Ybe as O,U8 as P,R5 as Q,Fve as R,z2 as S,U_e as T,Sg as U,ps as V,X as W,K as X,n1e as Y,I_e as Z,_,l1e as a,$y as a$,Rve as a0,eO as a1,J5 as a2,XHe as a3,qHe as a4,YHe as a5,GHe as a6,UHe as a7,UE as a8,KHe as a9,iAe as aA,rAe as aB,aEe as aC,S8 as aD,Ive as aE,FHe as aF,R1 as aG,Mx as aH,B7 as aI,ip as aJ,ol as aK,Dg as aL,sEe as aM,iEe as aN,le as aO,In as aP,fe as aQ,me as aR,ur as aS,T as aT,g as aU,Vr as aV,Rn as aW,Ya as aX,ut as aY,hF as aZ,iie as a_,WHe as aa,nu as ab,QHe as ac,ZHe as ad,VHe as ae,DEe as af,GU as ag,uUe as ah,t2e as ai,Sr as aj,Go as ak,Rd as al,dA as am,H7 as an,Sc as ao,V7 as ap,Ue as aq,Ws as ar,we as as,RAe as at,cUe as au,hUe as av,aUe as aw,Te as ax,lUe as ay,cAe as az,a1e as b,uR as b$,Kr as b0,Pg as b1,O3 as b2,gF as b3,xF as b4,o1 as b5,Xa as b6,yg as b7,Yr as b8,Uo as b9,BFe as bA,$E as bB,sa as bC,Bp as bD,G5 as bE,pwe as bF,c_e as bG,R7 as bH,E7 as bI,fSe as bJ,Ex as bK,pSe as bL,Mg as bM,Dl as bN,i_e as bO,bO as bP,$c as bQ,gSe as bR,iA as bS,dSe as bT,xSe as bU,nd as bV,l_e as bW,L_e as bX,CSe as bY,S_e as bZ,nA as b_,oY as ba,pUe as bb,Us as bc,ot as bd,gUe as be,xt as bf,tBe as bg,ire as bh,ore as bi,lre as bj,cne as bk,hre as bl,die as bm,wre as bn,bre as bo,Wre as bp,Rne as bq,fF as br,xg as bs,bie as bt,Vre as bu,NG as bv,eY as bw,_G as bx,EG as by,dN as bz,at as c,_e as c0,G7 as c1,Hr as c2,awe as c3,FE as c4,sz as c5,Eg as c6,lz as c7,HHe as c8,Ixe as c9,td as ca,g_e as cb,rNe as cc,Ng as cd,Nx as ce,dl as cf,M1 as cg,pO as ch,sA as ci,N7 as cj,O7 as ck,uSe as cl,CS as cm,M_e as cn,C_e as co,D_e as cp,rA as cq,R_e as cr,OHe as cs,et as ct,Xe as d,W8 as e,bn as f,u1e as g,zo as h,fs as i,n2e as j,_g as k,J as l,W7 as m,jHe as n,fUe as o,h1e as p,d1e as q,dUe as r,c1e as s,e2e as t,Qi as u,QEe as v,G_e as w,JHe as x,xc as y,o1e as z};
|