@useorgx/openclaw-plugin 0.4.4 → 0.4.5
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/README.md +64 -2
- package/dashboard/dist/assets/B68j2crt.js +1 -0
- package/dashboard/dist/assets/BZZ-fiJx.js +32 -0
- package/dashboard/dist/assets/{4hvaB0UC.js → BoXlCHKa.js} +1 -1
- package/dashboard/dist/assets/Bq9x_Xyh.css +1 -0
- package/dashboard/dist/assets/DBhrRVdp.js +1 -0
- package/dashboard/dist/assets/DD1jv1Hd.js +8 -0
- package/dashboard/dist/assets/DNjbmawF.js +214 -0
- package/dashboard/dist/index.html +5 -5
- package/dist/http-handler.js +14 -5
- package/dist/index.js +111 -26
- package/dist/mcp-client-setup.d.ts +30 -0
- package/dist/mcp-client-setup.js +215 -0
- package/dist/mcp-http-handler.d.ts +38 -0
- package/dist/mcp-http-handler.js +254 -0
- package/package.json +1 -1
- package/dashboard/dist/assets/B3ziCA02.js +0 -8
- package/dashboard/dist/assets/BgsfM2lz.js +0 -1
- package/dashboard/dist/assets/DCBlK4MX.js +0 -212
- package/dashboard/dist/assets/DEuY_RBN.js +0 -1
- package/dashboard/dist/assets/jyFhCND-.css +0 -1
- package/dashboard/dist/assets/sAhvFnpk.js +0 -4
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{r as n,u as ms,b as fs,c as Ze,j as e}from"./DD1jv1Hd.js";import{q as wt,b as yt,p as Is,c as $s,a as O,A as Ut,d as _s,E as Pe,u as Nt,P as Ts,M as Ls,e as Ps,f as Rs,g as es,o as zs,U as Os,N as ts}from"./DNjbmawF.js";import{A as Le,m as le,L as Us}from"./BoXlCHKa.js";import"./C-KIc3Wc.js";import"./BZZ-fiJx.js";function qs({activities:t,agents:s,initiatives:i}){return n.useMemo(()=>{const x=new Map,o=(h,r,j,w)=>{const F=x.get(h)??[];F.some(d=>d.id===r)||(F.push({id:r,name:j,confidence:w}),x.set(h,F))};return t.forEach(h=>{const r="metadata"in h&&h.metadata&&typeof h.metadata=="object"?h.metadata:null,j=r&&typeof r=="object"?r:{},w=("initiativeId"in h&&typeof h.initiativeId=="string"?h.initiativeId:void 0)??j.initiativeId??void 0,F=h.agentId??void 0,d=("agentName"in h&&typeof h.agentName=="string"?h.agentName:"agent"in h&&typeof h.agent=="string"?h.agent:void 0)??F??"Unknown";w&&F&&o(w,F,d,"high")}),i.forEach(h=>{var r;(r=h.avatars)!=null&&r.length&&h.avatars.forEach(j=>{const w=s.find(F=>F.name.toLowerCase()===j.toLowerCase());w?o(h.id,w.id,w.name,"medium"):o(h.id,`avatar:${j}`,j,"medium")})}),s.forEach(h=>{if(!h.task)return;const r=h.task.toLowerCase();i.forEach(j=>{j.name.toLowerCase().split(/\s+/).filter(M=>M.length>3).some(M=>r.includes(M))&&o(j.id,h.id,h.name,"low")})}),x},[t,s,i])}function Ws({initiativeId:t=null,authToken:s=null,embedMode:i=!1,enabled:x=!0}){var _,m,l;const o=ms(),h=n.useMemo(()=>wt.autoContinueStatus({initiativeId:t??"__global__",authToken:s,embedMode:i}),[t,s,i]),r=fs({queryKey:h,enabled:x&&(!!t||t===null),queryFn:async()=>{const g=new URLSearchParams;t&&g.set("initiative_id",t);const b=await fetch(`/orgx/api/mission-control/auto-continue/status?${g.toString()}`,{headers:yt({authToken:s,embedMode:i})}),p=await b.json().catch(()=>null);if(!b.ok){const C=typeof(p==null?void 0:p.error)=="string"&&p.error||typeof(p==null?void 0:p.message)=="string"&&p.message||`Failed to load auto-continue status (${b.status})`;return{ok:!1,initiativeId:t,run:null,defaults:{tokenBudget:0,tickMs:0},error:C}}return p},refetchInterval:g=>{var v,B;const b=g.state.data;if((b==null?void 0:b.ok)===!1)return!1;const p=((v=b==null?void 0:b.error)==null?void 0:v.toLowerCase())??"";if(p.includes("404")||p.includes("400")||p.includes("not found")||p.includes("bad request"))return!1;const u=((B=b==null?void 0:b.run)==null?void 0:B.status)??null;return u==="running"||u==="stopping"?2500:12e3}}),j=async()=>{await o.invalidateQueries({queryKey:h}),await o.invalidateQueries({queryKey:wt.missionControlGraph({initiativeId:t,authToken:s,embedMode:i})}),await o.invalidateQueries({queryKey:wt.liveData({authToken:s,embedMode:i})})},w=Ze({mutationFn:async g=>{const b={};t&&(b.initiativeId=t),g&&typeof g=="object"&&(typeof g.tokenBudgetTokens=="number"&&(b.tokenBudgetTokens=g.tokenBudgetTokens),typeof g.agentId=="string"&&g.agentId.trim().length>0&&(b.agentId=g.agentId.trim()));const p=await fetch("/orgx/api/mission-control/auto-continue/start",{method:"POST",headers:yt({authToken:s,embedMode:i,contentTypeJson:!0}),body:JSON.stringify(b)}),C=await p.json().catch(()=>null);if(!p.ok){const u=Is(C);if(u)throw u;const v=typeof(C==null?void 0:C.error)=="string"&&C.error||typeof(C==null?void 0:C.message)=="string"&&C.message||`Failed to start auto-continue (${p.status})`;throw new Error(v)}if(C&&typeof C=="object"&&"run"in C){const u=r.data??null;return{ok:!0,initiativeId:t,run:C.run??null,defaults:(u==null?void 0:u.defaults)??{tokenBudget:0,tickMs:0}}}return C},onSuccess:()=>{j()}}),F=Ze({mutationFn:async()=>{const g={};t&&(g.initiativeId=t);const b=await fetch("/orgx/api/mission-control/auto-continue/stop",{method:"POST",headers:yt({authToken:s,embedMode:i,contentTypeJson:!0}),body:JSON.stringify(g)}),p=await b.json().catch(()=>null);if(!b.ok){const C=typeof(p==null?void 0:p.error)=="string"&&p.error||typeof(p==null?void 0:p.message)=="string"&&p.message||`Failed to stop auto-continue (${b.status})`;throw new Error(C)}if(p&&typeof p=="object"&&"run"in p){const C=r.data??null;return{ok:!0,initiativeId:t,run:p.run??null,defaults:(C==null?void 0:C.defaults)??{tokenBudget:0,tickMs:0}}}return p},onSuccess:()=>{j()}}),d=((_=r.data)==null?void 0:_.run)??null,M=(d==null?void 0:d.status)==="running"||(d==null?void 0:d.status)==="stopping";return{status:r.data??null,run:d,isRunning:M,isLoading:r.isLoading,error:((m=r.data)==null?void 0:m.error)??((l=r.error)==null?void 0:l.message)??null,start:w.mutateAsync,stop:F.mutateAsync,isStarting:w.isPending,isStopping:F.isPending,refetch:r.refetch}}function gs({value:t,onChange:s,placeholder:i}){return e.jsxs("label",{className:"relative block",children:[e.jsx("span",{className:"sr-only",children:i}),e.jsxs("svg",{className:"pointer-events-none absolute left-3 top-1/2 -translate-y-1/2 text-white/35",width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("circle",{cx:"11",cy:"11",r:"8"}),e.jsx("path",{d:"m21 21-4.3-4.3"})]}),e.jsx("input",{type:"text",value:t,onChange:x=>s(x.target.value),placeholder:i,className:"w-full rounded-xl border border-white/[0.08] bg-white/[0.03] py-2.5 pl-10 pr-8 text-[13px] text-white placeholder:text-white/35 transition-all focus:border-[#BFFF00]/30 focus:bg-white/[0.05] focus:outline-none"}),t.length>0&&e.jsx("button",{type:"button",onClick:()=>s(""),className:"absolute right-2.5 top-1/2 -translate-y-1/2 rounded-full p-0.5 text-white/40 transition-colors hover:text-white/70","aria-label":"Clear search",children:e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:e.jsx("path",{d:"M18 6 6 18M6 6l12 12"})})})]})}function ht({className:t=""}){return e.jsx("div",{className:$s("shimmer-skeleton",t),"aria-hidden":"true"})}async function Xe(t){if(!t.ok){const s=await t.json().catch(()=>null),i=typeof(s==null?void 0:s.error)=="string"&&s.error||typeof(s==null?void 0:s.message)=="string"&&s.message||`Request failed (${t.status})`;throw new Error(i)}return t}function Hs(t){const s=t.trim().toLowerCase();return s==="completed"||s==="done"?"completed":s==="blocked"||s==="at_risk"?"blocked":s==="paused"||s==="hold"?"paused":s==="deleted"||s==="archived"||s==="cancelled"?"completed":"active"}function Tt(t){const s=t.trim().toLowerCase();return s==="deleted"||s==="archived"||s==="cancelled"}function Vs(t){const s=t.trim().toLowerCase();return s==="blocked"||s==="at_risk"?"blocked":s==="paused"||s==="hold"?"paused":s==="completed"||s==="done"?"completed":"running"}function Gs(t){const s=ms(),i=yt({authToken:t.authToken,embedMode:t.embedMode,contentTypeJson:!0}),x=()=>{s.invalidateQueries({queryKey:["live-data"]}),s.invalidateQueries({queryKey:["live-initiatives"]}),s.invalidateQueries({queryKey:["initiative-details"]}),s.invalidateQueries({queryKey:["entities"]}),s.invalidateQueries({queryKey:["mission-control-graph"]}),s.invalidateQueries({queryKey:["mission-control-next-up"]})},o=(m,l)=>{s.setQueryData(["initiative-tombstones"],g=>{const b=Array.isArray(g)?g.filter(C=>typeof C=="string"):[],p=b.includes(m);return l?p?b:[...b,m]:p?b.filter(C=>C!==m):b})},h=(m,l)=>{const g=Hs(l),b=new Date().toISOString(),p=Tt(l);o(m,p);const C=u=>{if(!Array.isArray(u))return u;if(p){const W=u.filter(X=>{if(!X||typeof X!="object")return!0;const K=X;return!(typeof K.id=="string"&&K.id===m)});return W.length===u.length?u:W}let v=!1;const B=u.map(W=>{if(!W||typeof W!="object")return W;const X=W;return typeof X.id!="string"||X.id!==m?W:(v=!0,{...X,status:g,rawStatus:l,updatedAt:b})});return v?B:u};s.setQueriesData({queryKey:["entities"]},C),s.setQueriesData({queryKey:["live-initiatives"]},C)},r=(m,l,g="status")=>{const b=Vs(l);s.setQueriesData({queryKey:["live-data"]},p=>{if(!p||typeof p!="object")return p;const C=p,u=C.sessions;if(!u||typeof u!="object")return p;const v=u,B=v.nodes;if(!Array.isArray(B))return p;let W=!1;const X=g==="delete"?B.filter(k=>{if(!k||typeof k!="object")return!0;const z=k,ne=(typeof z.initiativeId=="string"?z.initiativeId:null)===m;return ne&&(W=!0),!ne}):B.map(k=>{if(!k||typeof k!="object")return k;const z=k;return(typeof z.initiativeId=="string"?z.initiativeId:null)!==m||z.status===b?k:(W=!0,{...z,status:b})});if(!W)return p;const K=new Set,U=new Set;for(const k of X){if(!k||typeof k!="object")continue;const z=k;typeof z.id=="string"&&K.add(z.id),typeof z.groupId=="string"&&U.add(z.groupId)}const T=Array.isArray(v.edges)?v.edges.filter(k=>{if(!k||typeof k!="object")return!1;const z=k,q=typeof z.parentId=="string"?z.parentId:null,ne=typeof z.childId=="string"?z.childId:null;return q!==null&&ne!==null&&K.has(q)&&K.has(ne)}):v.edges,Q=Array.isArray(v.groups)?v.groups.filter(k=>{if(!k||typeof k!="object")return!1;const z=k;return typeof z.id=="string"&&U.has(z.id)}):v.groups;return{...C,sessions:{...v,nodes:X,edges:T,groups:Q}}})},j={start:"in_progress",complete:"done",block:"blocked",unblock:"in_progress",pause:"paused",resume:"active"},w=Ze({mutationFn:async m=>{const{type:l,...g}=m,b=await fetch("/orgx/api/entities",{method:"POST",headers:i,body:JSON.stringify({type:l,...g})});return await Xe(b),b.json()},onSuccess:x}),F=Ze({mutationFn:async m=>{const{type:l,id:g,...b}=m,p=await fetch("/orgx/api/entities",{method:"PATCH",headers:i,body:JSON.stringify({type:l,id:g,...b})});return await Xe(p),p.json()},onSuccess:(m,l)=>{l.type.trim().toLowerCase()==="initiative"&&typeof l.status=="string"&&l.status.trim().length>0&&(h(l.id,l.status),r(l.id,l.status,Tt(l.status)?"delete":"status")),x()}}),d=Ze({mutationFn:async m=>{const l=await fetch(`/orgx/api/entities/${encodeURIComponent(m.type)}/${encodeURIComponent(m.id)}/delete`,{method:"POST",headers:i,body:"{}"});return await Xe(l),l.json()},onSuccess:(m,l)=>{l.type.trim().toLowerCase()==="initiative"&&(h(l.id,"archived"),r(l.id,"archived","delete")),x()}}),M=Ze({mutationFn:async m=>{const l=await fetch(`/orgx/api/entities/${encodeURIComponent(m.type)}/${encodeURIComponent(m.id)}/${encodeURIComponent(m.action)}`,{method:"POST",headers:i,body:JSON.stringify({force:m.force??!1})});return await Xe(l),l.json()},onSuccess:(m,l)=>{if(l.type.trim().toLowerCase()==="initiative"){const g=j[l.action.trim().toLowerCase()];g&&(h(l.id,g),r(l.id,g,"status"))}x()}}),_=Ze({mutationFn:async m=>{const l=Array.from(new Map((m.items??[]).filter(v=>typeof(v==null?void 0:v.type)=="string"&&v.type.trim().length>0&&typeof(v==null?void 0:v.id)=="string"&&v.id.trim().length>0).map(v=>[`${v.type}:${v.id}`,v])).values());if(l.length===0)return{updated:0,failed:0,errors:[]};if(m.mode==="action"&&!m.action)throw new Error("bulk action requires an action name");const g=async v=>{try{if(m.mode==="delete"){const W=await fetch(`/orgx/api/entities/${encodeURIComponent(v.type)}/${encodeURIComponent(v.id)}/delete`,{method:"POST",headers:i,body:"{}"});return await Xe(W),{ok:!0}}if(m.mode==="update"){const W=await fetch("/orgx/api/entities",{method:"PATCH",headers:i,body:JSON.stringify({type:v.type,id:v.id,...m.updates??{}})});return await Xe(W),{ok:!0}}const B=await fetch(`/orgx/api/entities/${encodeURIComponent(v.type)}/${encodeURIComponent(v.id)}/${encodeURIComponent(m.action)}`,{method:"POST",headers:i,body:JSON.stringify({force:m.force??!1})});return await Xe(B),{ok:!0}}catch(B){return{ok:!1,error:B instanceof Error?B.message:"Unknown bulk mutation failure"}}},b=await Promise.all(l.map(v=>g(v)));let p=0,C=0;const u=[];for(const v of b)v.ok?p+=1:(C+=1,u.push(v.error));return{updated:p,failed:C,errors:u}},onSuccess:(m,l)=>{var b;const g=(l.items??[]).filter(p=>p.type.trim().toLowerCase()==="initiative");if(g.length>0){if(l.mode==="update"&&typeof((b=l.updates)==null?void 0:b.status)=="string"&&l.updates.status.trim().length>0)for(const p of g)h(p.id,l.updates.status),r(p.id,l.updates.status,Tt(l.updates.status)?"delete":"status");else if(l.mode==="delete")for(const p of g)h(p.id,"archived"),r(p.id,"archived","delete");else if(l.mode==="action"&&l.action){const p=j[l.action.trim().toLowerCase()];if(p)for(const C of g)h(C.id,p),r(C.id,p,"status")}}x()}});return{createEntity:w,updateEntity:F,deleteEntity:d,entityAction:M,bulkEntityMutation:_}}const bs=n.createContext(null);function tt(){const t=n.useContext(bs);if(!t)throw new Error("useMissionControl must be used within MissionControlProvider");return t}function Ks({children:t,agentEntityMap:s,authToken:i,embedMode:x}){const[o,h]=n.useState(new Set),[r,j]=n.useState(null),[w,F]=n.useState(""),[d,M]=n.useState([]),[_,m]=n.useState("target"),[l,g]=n.useState("any"),[b,p]=n.useState(""),[C,u]=n.useState(""),[v,B]=n.useState("status"),[W,X]=n.useState("default"),K=Gs({authToken:i,embedMode:x}),U=n.useCallback(Z=>{h(A=>{const se=new Set(A);return se.has(Z)?se.delete(Z):se.add(Z),se})},[]),T=n.useCallback(Z=>{h(A=>{if(A.has(Z))return A;const se=new Set(A);return se.add(Z),se})},[]),Q=n.useCallback(Z=>{h(new Set(Z))},[]),k=n.useCallback(()=>{h(new Set)},[]),z=n.useCallback(Z=>{j(Z)},[]),q=n.useCallback(()=>{j(null)},[]),ne=n.useCallback(Z=>{const A=Array.from(new Set((Z??[]).map(se=>se.trim().toLowerCase()).filter(Boolean)));M(A)},[]),L=n.useCallback(Z=>{M(A=>{const se=Z.trim().toLowerCase();return se?A.includes(se)?A.filter(ge=>ge!==se):[...A,se]:A})},[]),Y=n.useCallback(()=>{F(""),M([]),m("target"),g("any"),p(""),u("")},[]),oe=b.trim().length>0||C.trim().length>0,c=l!=="any"&&(l!=="custom_range"||oe),te=d.length+(c?1:0),J=w.trim().length>0||te>0,G=n.useMemo(()=>({agentEntityMap:s,expandedInitiatives:o,modalTarget:r,searchQuery:w,statusFilters:d,dateField:_,datePreset:l,dateStart:b,dateEnd:C,activeFilterCount:te,hasActiveFilters:J,groupBy:v,sortBy:W,authToken:i,embedMode:x,mutations:K,toggleExpanded:U,expandInitiative:T,expandAll:Q,collapseAll:k,openModal:z,closeModal:q,setSearchQuery:F,setStatusFilters:ne,toggleStatusFilter:L,setDateField:m,setDatePreset:g,setDateStart:p,setDateEnd:u,setGroupBy:B,setSortBy:X,clearFilters:Y}),[s,o,r,w,d,_,l,b,C,te,J,v,W,i,x,K,U,T,Q,k,z,q,ne,L,m,g,p,u,B,X,Y]);return e.jsx(bs.Provider,{value:G,children:t})}const jt={active:"text-[#BFFF00] bg-[#BFFF00]/10 border-[#BFFF00]/20",paused:"text-[#F5B700] bg-[#F5B700]/10 border-[#F5B700]/20",blocked:"text-[#FF6B88] bg-[#FF6B88]/10 border-[#FF6B88]/20",completed:"text-[#14B8A6] bg-[#14B8A6]/10 border-[#14B8A6]/20"},Qs={done:"text-[#14B8A6] bg-[#14B8A6]/10 border-[#14B8A6]/20",completed:"text-[#14B8A6] bg-[#14B8A6]/10 border-[#14B8A6]/20",in_progress:"text-[#BFFF00] bg-[#BFFF00]/10 border-[#BFFF00]/20",active:"text-[#BFFF00] bg-[#BFFF00]/10 border-[#BFFF00]/20",blocked:"text-[#FF6B88] bg-[#FF6B88]/10 border-[#FF6B88]/20",todo:"text-white/60 bg-white/5 border-white/10"},qt=t=>Qs[t.toLowerCase()]??"text-white/60 bg-white/5 border-white/10",ws=t=>{const s=t.toLowerCase();return s==="active"||s==="in_progress"?"text-[#BFFF00] bg-[#BFFF00]/10 border-[#BFFF00]/20":s==="blocked"?"text-[#FF6B88] bg-[#FF6B88]/10 border-[#FF6B88]/20":s==="completed"||s==="done"?"text-[#14B8A6] bg-[#14B8A6]/10 border-[#14B8A6]/20":"text-white/60 bg-white/5 border-white/10"},ys=t=>{const s=t.toLowerCase();return s==="done"||s==="completed"?"text-[#14B8A6] bg-[#14B8A6]/10 border-[#14B8A6]/20":s==="active"||s==="in_progress"?"text-[#BFFF00] bg-[#BFFF00]/10 border-[#BFFF00]/20":"text-white/60 bg-white/5 border-white/10"},Ne=t=>t.replace(/[_-]+/g," ").replace(/\s+/g," ").trim().replace(/\b\w/g,s=>s.toUpperCase()),vt=t=>{const s=t.toLowerCase();return s==="blocked"?0:s==="in_progress"||s==="active"?1:s==="todo"||s==="planned"?2:s==="done"||s==="completed"?3:4},ss=t=>{const s=t.toLowerCase();return s==="blocked"?O.red:s==="active"||s==="in_progress"?O.lime:s==="done"||s==="completed"?O.teal:s==="paused"?O.amber:"rgba(255,255,255,0.35)"};function Ct({agents:t,max:s=4}){if(!t.length)return null;const i=t.slice(0,s),x=t.length-s;return e.jsxs("div",{className:"inline-flex min-w-0 items-center justify-end -space-x-1.5 pl-1",children:[i.map(o=>e.jsx("div",{className:"relative flex-shrink-0",title:`${o.name} (${o.confidence} confidence)`,style:{borderRadius:"9999px",border:o.confidence==="high"?"1.5px solid rgba(255,255,255,0.25)":o.confidence==="medium"?"1.5px dashed rgba(255,255,255,0.15)":"1.5px dotted rgba(255,255,255,0.10)"},children:e.jsx(Ut,{name:o.name,size:"xs"})},o.id)),x>0&&e.jsxs("span",{className:"ml-1 flex-shrink-0 text-[9px] text-white/40",children:["+",x]})]})}function Lt(t){return{initiative:{id:t,title:"Initiative",status:"active",summary:null,assignedAgents:[]},nodes:[],edges:[],recentTodos:[]}}function Js({initiativeId:t,authToken:s=null,embedMode:i=!1,enabled:x=!0}){var w,F;const o=_s(t),h=n.useMemo(()=>wt.missionControlGraph({initiativeId:t,authToken:s,embedMode:i}),[t,s,i]),r=fs({queryKey:h,enabled:x&&!!t&&o,queryFn:async()=>{if(!t)throw new Error("initiativeId is required");if(!o)return Lt(t);const d=new URLSearchParams({initiative_id:t}),M={};i&&(M["X-Orgx-Embed"]="true"),s&&(M.Authorization=`Bearer ${s}`);const _=Object.keys(M).length>0?M:void 0,m=await fetch(`/orgx/api/mission-control/graph?${d.toString()}`,{headers:_});if(!m.ok){const l=await m.json().catch(()=>null),g=typeof(l==null?void 0:l.error)=="string"&&l.error||typeof(l==null?void 0:l.message)=="string"&&l.message||`Failed to fetch Mission Control graph (${m.status})`;return{...Lt(t),degraded:[g]}}return await m.json()}});return{graph:r.data??(t?Lt(t):null),isLoading:o?r.isLoading:!1,error:o?((w=r.error)==null?void 0:w.message)??null:null,degraded:o?((F=r.data)==null?void 0:F.degraded)??[]:[],refetch:r.refetch}}function kt({type:t,className:s=""}){return e.jsx(Pe,{type:t,className:s,size:14})}function Ys(t){return t==="initiative"?"Initiatives":t==="workstream"?"Workstreams":t==="milestone"?"Milestones":"Tasks"}function Xs({nodes:t,edges:s,selectedNodeId:i,focusedWorkstreamId:x,onSelectNode:o}){const h=n.useMemo(()=>new Map(t.map(u=>[u.id,u])),[t]),[r,j]=n.useState(""),[w,F]=n.useState(!1),d=r.trim().toLowerCase(),M=n.useMemo(()=>{if(!x)return new Set(t.map(B=>B.id));const u=new Set;for(const B of t)(B.type==="initiative"||B.id===x||B.workstreamId===x)&&u.add(B.id);let v=!0;for(;v;){v=!1;for(const B of s)(u.has(B.from)||u.has(B.to))&&(!u.has(B.from)||!u.has(B.to))&&(u.add(B.from),u.add(B.to),v=!0)}return u},[x,t,s]),_=t.filter(u=>M.has(u.id)),m=s.filter(u=>M.has(u.from)&&M.has(u.to)),l=n.useMemo(()=>{if(!i)return new Set;const u=new Set([i]);for(const v of m)v.from===i&&u.add(v.to),v.to===i&&u.add(v.from);return u},[i,m]),g=n.useMemo(()=>{let u=new Set(Array.from(M));return w&&i&&(u=new Set(Array.from(u).filter(v=>l.has(v)))),d.length>0&&(u=new Set(Array.from(u).filter(v=>{const B=h.get(v);return B?B.title.toLowerCase().includes(d):!1}))),u},[h,d,l,w,i,M]),b=t.filter(u=>g.has(u.id)),p=s.filter(u=>g.has(u.from)&&g.has(u.to)),C={initiative:b.filter(u=>u.type==="initiative"),workstream:b.filter(u=>u.type==="workstream"),milestone:b.filter(u=>u.type==="milestone"),task:b.filter(u=>u.type==="task")};return _.length===0?null:e.jsxs("section",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("span",{className:"text-[10px] uppercase tracking-[0.08em] text-white/42",children:[b.length," nodes · ",p.length," links"]}),x&&e.jsx("span",{className:"status-pill","data-tone":"active",children:"Focused workstream"})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("input",{value:r,onChange:u=>j(u.target.value),placeholder:"Filter nodes...",className:"h-9 flex-1 min-w-[200px] rounded-lg border border-white/[0.12] bg-black/30 px-3 text-[11px] text-white/80 placeholder:text-white/25 transition-colors focus:border-[#BFFF00]/35 focus:outline-none"}),i&&e.jsx("button",{type:"button",onClick:()=>F(u=>!u),"aria-pressed":w,"data-state":w?"active":"idle",className:"control-pill px-3 text-[11px] font-semibold",title:"Show only the selected node and its direct neighbors",children:"Related only"}),(r.trim().length>0||w)&&e.jsx("button",{type:"button",onClick:()=>{j(""),F(!1)},className:"control-pill px-3 text-[11px]",children:"Reset"})]}),b.length===0?e.jsx("div",{className:"rounded-xl border border-white/[0.07] bg-black/[0.14] px-3 py-3 text-[11px] text-white/48",children:"No nodes match this view. Clear filters or select a different node to see connected work."}):e.jsx("div",{className:`grid gap-2 ${Object.values(C).filter(u=>u.length>0).length<=2?"grid-cols-1 sm:grid-cols-2":"md:grid-cols-2 xl:grid-cols-4"}`,children:Object.keys(C).filter(u=>C[u].length>0).map(u=>e.jsxs("div",{className:"rounded-xl border border-white/[0.07] bg-black/[0.14] p-2.5",children:[e.jsxs("div",{className:"mb-1.5 text-[10px] uppercase tracking-[0.09em] text-white/45",children:[Ys(u)," (",C[u].length,")"]}),e.jsxs("div",{className:"space-y-1",children:[C[u].slice(0,10).map(v=>{const B=i===v.id,W=!B&&l.has(v.id);return e.jsxs("button",{type:"button",onClick:()=>o(v.id),title:v.title,className:`flex w-full items-center gap-1.5 rounded-md border px-2 py-1 text-left transition-colors ${B?"border-[#BFFF00]/35 bg-[#BFFF00]/12":W?"border-[#14B8A6]/35 bg-[#14B8A6]/12":"border-white/[0.12] bg-white/[0.03] hover:bg-white/[0.08]"}`,children:[e.jsx(kt,{type:v.type}),e.jsx("span",{className:"truncate text-[11px] text-white/80",children:v.title})]},v.id)}),C[u].length>10&&e.jsxs("div",{className:"px-1 text-[10px] text-white/35",children:["+",C[u].length-10," more"]})]})]},u))}),p.length>0&&e.jsxs("div",{className:"rounded-xl border border-white/[0.07] bg-black/[0.14] px-2.5 py-2",children:[e.jsx("div",{className:"mb-1 text-[10px] uppercase tracking-[0.08em] text-white/35",children:"Dependency links"}),e.jsx("div",{className:"max-h-[110px] space-y-1 overflow-auto pr-1",children:p.slice(0,36).map(u=>{const v=h.get(u.from),B=h.get(u.to);if(!v||!B)return null;const W=i===v.id||i===B.id;return e.jsxs("button",{type:"button",onClick:()=>o(B.id),className:"flex w-full items-center gap-1 rounded-md px-1.5 py-1 text-left hover:bg-white/[0.06]",children:[e.jsx("span",{className:"h-1.5 w-1.5 rounded-full",style:{backgroundColor:W?O.lime:"rgba(255,255,255,0.35)"}}),e.jsx("span",{className:"truncate text-[10px] text-white/70",children:v.title}),e.jsx("span",{className:"text-[10px] text-white/30",children:"→"}),e.jsx("span",{className:"truncate text-[10px] text-white/70",children:B.title})]},`${u.from}-${u.to}`)})})]})]})}function Zs(t){return t.trim().toLowerCase().replace(/[\s-]+/g,"_")}const en=new Set(["done","completed","complete","cancelled","canceled","archived","deleted"]);function Ae(t){return en.has(Zs(t))}function St(t){return Number.isFinite(t)?Math.max(0,Math.min(100,Math.round(t))):0}function et(t,s){return s<=0?0:St(t/s*100)}function tn({dependencies:t,allNodes:s,disabled:i=!1,onSave:x}){const[o,h]=n.useState(!1),[r,j]=n.useState(""),[w,F]=n.useState(t),d=n.useMemo(()=>new Map(s.map(l=>[l.id,l])),[s]),M=n.useMemo(()=>{const l=r.trim().toLowerCase(),g=[...s].sort((b,p)=>b.title.localeCompare(p.title));return l?g.filter(b=>b.title.toLowerCase().includes(l)||b.id.toLowerCase().includes(l)).slice(0,16):g.slice(0,16)},[s,r]),_=()=>{x(Array.from(new Set(w))),h(!1)},m=l=>{F(g=>g.includes(l)?g.filter(b=>b!==l):[...g,l])};return e.jsxs("div",{className:"relative",children:[e.jsx("button",{type:"button",disabled:i,onClick:()=>{j(""),F(t),h(l=>!l)},className:"rounded-md border border-white/[0.12] bg-white/[0.04] px-2 py-1 text-[10px] text-white/70 transition-colors hover:bg-white/[0.08] disabled:opacity-40",children:t.length>0?`${t.length} linked`:"Set links"}),o&&e.jsxs("div",{className:"surface-tier-2 absolute right-0 z-20 mt-1.5 w-[320px] rounded-xl p-2.5 shadow-[0_20px_40px_rgba(0,0,0,0.45)]",children:[e.jsx("label",{className:"text-[10px] uppercase tracking-[0.08em] text-white/45",children:"Link dependencies"}),e.jsx("input",{value:r,onChange:l=>j(l.target.value),placeholder:"Search by title or id...",className:"mt-1.5 h-9 w-full rounded-md border border-white/[0.12] bg-black/25 px-2.5 text-[11px] text-white/85 outline-none transition-colors placeholder:text-white/35 focus:border-[#BFFF00]/35"}),e.jsx("div",{className:"mt-2 flex max-h-[84px] flex-wrap gap-1.5 overflow-y-auto rounded-md border border-white/[0.08] bg-black/20 p-1.5",children:w.length===0?e.jsx("span",{className:"text-[10px] text-white/40",children:"No links selected"}):w.map(l=>{var b;const g=((b=d.get(l))==null?void 0:b.title)??l;return e.jsxs("button",{type:"button",onClick:()=>m(l),className:"inline-flex items-center gap-1 rounded-full border border-white/[0.16] bg-white/[0.05] px-2 py-0.5 text-[10px] text-white/70 transition-colors hover:bg-white/[0.1]",title:g,children:[e.jsx("span",{className:"max-w-[180px] truncate",children:g}),e.jsx("span",{className:"text-white/45",children:"×"})]},l)})}),e.jsx("div",{className:"mt-2 max-h-[150px] space-y-1 overflow-y-auto rounded-md border border-white/[0.08] bg-black/20 p-1.5",children:M.length===0?e.jsx("div",{className:"px-1 text-[10px] text-white/40",children:"No matching nodes"}):M.map(l=>{const g=w.includes(l.id);return e.jsxs("button",{type:"button",onClick:()=>m(l.id),className:`flex w-full items-center justify-between rounded-md border px-2 py-1 text-left text-[10px] transition-colors ${g?"border-[#BFFF00]/32 bg-[#BFFF00]/12 text-[#D8FFA1]":"border-white/[0.1] bg-white/[0.03] text-white/70 hover:bg-white/[0.08]"}`,children:[e.jsxs("span",{className:"min-w-0 pr-2",children:[e.jsx("span",{className:"block truncate",children:l.title}),e.jsxs("span",{className:"block truncate text-white/40",children:[l.id.slice(0,8),"…"]})]}),e.jsx("span",{className:"font-semibold",children:g?"Linked":"Link"})]},l.id)})}),e.jsxs("div",{className:"mt-2 flex items-center justify-end gap-1.5",children:[e.jsx("button",{type:"button",onClick:()=>h(!1),className:"rounded-md border border-white/[0.12] px-2 py-1 text-[10px] text-white/60 transition-colors hover:bg-white/[0.08]",children:"Cancel"}),e.jsx("button",{type:"button",onClick:_,className:"rounded-md border border-[#BFFF00]/30 bg-[#BFFF00]/15 px-2 py-1 text-[10px] text-[#D8FFA1] transition-colors hover:bg-[#BFFF00]/22",children:"Save links"})]})]})]})}function sn(t){if(!t)return"";const s=new Date(t);if(Number.isNaN(s.getTime()))return"";const i=s.getFullYear(),x=String(s.getMonth()+1).padStart(2,"0"),o=String(s.getDate()).padStart(2,"0"),h=String(s.getHours()).padStart(2,"0"),r=String(s.getMinutes()).padStart(2,"0");return`${i}-${x}-${o}T${h}:${r}`}const ns=["not_started","planned","todo","in_progress","active","blocked","done"];function nn(t){const s=t.trim().toLowerCase();return s==="blocked"?"blocked":s==="done"||s==="completed"?"done":s==="in_progress"||s==="active"||s==="running"||s==="queued"?"active":"planned"}function mt(t){const s=t.trim().toLowerCase();return s==="completed"?"done":s==="running"||s==="queued"?"active":s==="pending"||s==="backlog"?"todo":s}function an(t,s){return s==="all"?!0:s==="blocked"?t==="blocked":s==="done"?t==="done":t!=="blocked"&&t!=="done"}function rn(t,s){const i=new Map(s.map(h=>[h.id,h])),x=new Set,o=[t];for(;o.length>0;){const h=o.shift(),r=i.get(h);r&&(r.parentId&&!x.has(r.parentId)&&(x.add(r.parentId),o.push(r.parentId)),r.workstreamId&&!x.has(r.workstreamId)&&(x.add(r.workstreamId),o.push(r.workstreamId)),r.milestoneId&&!x.has(r.milestoneId)&&(x.add(r.milestoneId),o.push(r.milestoneId)))}return x}function ln(t,s,i,x){let o=0;if(i==="title")o=t.title.localeCompare(s.title);else if(i==="status")o=vt(t.status)-vt(s.status);else if(i==="priority")o=t.priorityNum-s.priorityNum;else if(i==="eta"){const h=t.etaEndAt?Date.parse(t.etaEndAt):1/0,r=s.etaEndAt?Date.parse(s.etaEndAt):1/0;o=h-r}return x==="desc"?-o:o}function on({nodes:t,edges:s,selectedNodeId:i,highlightedNodeIds:x,editMode:o,onToggleEditMode:h,onSelectNode:r,onFocusWorkstream:j,onOpenNode:w,onUpdateNode:F,mutations:d}){const[M,_]=n.useState(""),[m,l]=n.useState(new Set),[g,b]=n.useState("all"),[p,C]=n.useState(!1),[u,v]=n.useState(null),[B,W]=n.useState("asc"),[X,K]=n.useState(new Set),[U,T]=n.useState(!1),[Q,k]=n.useState(null),z=n.useRef(null),q=n.useRef(null),ne=n.useMemo(()=>new Map(t.map(a=>[a.id,a])),[t]),L=n.useMemo(()=>t.map(a=>({id:a.id,title:a.title})),[t]),Y=n.useMemo(()=>{const a=new Map;for(const N of t){const S=mt(N.status);a.set(S,(a.get(S)??0)+1)}return a},[t]),oe=n.useMemo(()=>{let a=0,N=0,S=0;for(const $ of t){const ee=mt($.status);ee==="blocked"?N+=1:ee==="done"?S+=1:a+=1}return{all:t.length,open:a,blocked:N,done:S}},[t]),c=n.useMemo(()=>{const a=M.trim().toLowerCase(),N=a.length>0,S=m.size>0;if(!N&&!S&&!(g!=="all"))return null;const ee=new Set;for(const xe of t){const Fe=mt(xe.status),he=!N||xe.title.toLowerCase().includes(a)||xe.assignedAgents.some(I=>I.name.toLowerCase().includes(a)),D=!S||m.has(Fe),P=an(Fe,g);he&&D&&P&&ee.add(xe.id)}const je=new Set(ee);for(const xe of ee)for(const Fe of rn(xe,t))je.add(Fe);return je},[m,t,M,g]),te=n.useMemo(()=>t.filter(a=>a.type==="workstream").sort((a,N)=>a.priorityNum-N.priorityNum||a.title.localeCompare(N.title)),[t]),J=n.useMemo(()=>{const a=new Map;for(const N of t.filter(S=>S.type==="milestone")){const S=N.workstreamId??"unscoped",$=a.get(S)??[];$.push(N),a.set(S,$)}for(const N of a.values())N.sort((S,$)=>S.priorityNum-$.priorityNum||S.title.localeCompare($.title));return a},[t]),G=n.useMemo(()=>{const a=new Map;for(const N of t.filter(S=>S.type==="task"&&S.milestoneId)){const S=N.milestoneId??"unscoped",$=a.get(S)??[];$.push(N),a.set(S,$)}for(const N of a.values())N.sort((S,$)=>S.priorityNum-$.priorityNum||S.title.localeCompare($.title));return a},[t]),Z=n.useMemo(()=>{const a=new Map;for(const N of t.filter(S=>S.type==="task"&&!S.milestoneId)){const S=N.workstreamId??"unscoped",$=a.get(S)??[];$.push(N),a.set(S,$)}for(const N of a.values())N.sort((S,$)=>S.priorityNum-$.priorityNum||S.title.localeCompare($.title));return a},[t]),A=n.useMemo(()=>{const a=new Set;for(const N of te)a.add(N.id);for(const N of t.filter(S=>S.type==="milestone"))a.add(N.id);return a},[t,te]),[se,ge]=n.useState(A);n.useEffect(()=>{ge(A)},[A]);const ye=a=>u?[...a].sort((N,S)=>ln(N,S,u,B)):a,ue=n.useMemo(()=>{const a=[],N=ee=>c===null||c.has(ee);for(const ee of ye(te)){if(!N(ee.id))continue;const je=ye(J.get(ee.id)??[]),xe=ye(Z.get(ee.id)??[]),Fe=je.length>0||xe.length>0;if(a.push({node:ee,depth:0,canCollapse:Fe}),!!se.has(ee.id)){for(const he of je){if(!N(he.id))continue;const D=ye(G.get(he.id)??[]);if(a.push({node:he,depth:1,canCollapse:D.length>0}),se.has(he.id))for(const P of D)N(P.id)&&a.push({node:P,depth:2,canCollapse:!1})}for(const he of xe)N(he.id)&&a.push({node:he,depth:1,canCollapse:!1})}}const S=ye(J.get("unscoped")??[]),$=ye(Z.get("unscoped")??[]);for(const ee of S)if(N(ee.id)&&(a.push({node:ee,depth:0,canCollapse:(G.get(ee.id)??[]).length>0}),se.has(ee.id)))for(const je of ye(G.get(ee.id)??[]))N(je.id)&&a.push({node:je,depth:1,canCollapse:!1});for(const ee of $)N(ee.id)&&a.push({node:ee,depth:0,canCollapse:!1});return a},[Z,se,c,J,u,B,G,te]),Be=n.useMemo(()=>ue.map(({node:a})=>a.id),[ue]),Ye=n.useMemo(()=>new Set(Be),[Be]),Me=n.useMemo(()=>ue.filter(({node:a})=>X.has(a.id)),[ue,X]),Re=(g!=="all"?1:0)+m.size,st=M.trim().length>0||g!=="all"||m.size>0,me=Me.length,be=ue.length>0&&me===ue.length,pe=(d==null?void 0:d.bulkEntityMutation.isPending)??!1;n.useEffect(()=>{K(a=>{if(a.size===0)return a;const N=new Set(Array.from(a).filter(S=>Ye.has(S)));return N.size===a.size?a:N})},[Ye]),n.useEffect(()=>{z.current&&(z.current.indeterminate=me>0&&!be)},[be,me]),n.useEffect(()=>{me===0&&U&&T(!1)},[U,me]),n.useEffect(()=>{if(!p)return;const a=S=>{var ee;const $=S.target;$&&((ee=q.current)!=null&&ee.contains($)||C(!1))},N=S=>{S.key==="Escape"&&C(!1)};return document.addEventListener("mousedown",a),document.addEventListener("touchstart",a),document.addEventListener("keydown",N),()=>{document.removeEventListener("mousedown",a),document.removeEventListener("touchstart",a),document.removeEventListener("keydown",N)}},[p]);const ze=a=>a.dependencyIds.length,Oe=n.useMemo(()=>{const a=new Map,N=(S,$)=>{if(S.length>0){const ee=S.filter(je=>Ae(je.status)).length;return et(ee,S.length)}return Ae($)?100:0};for(const S of t.filter($=>$.type==="milestone")){const $=G.get(S.id)??[];a.set(S.id,N($,S.status))}for(const S of te){const ee=(J.get(S.id)??[]).flatMap(xe=>G.get(xe.id)??[]),je=Z.get(S.id)??[];a.set(S.id,N([...je,...ee],S.status))}return a},[Z,J,t,G,te]),Ie=a=>{u===a?W(N=>N==="asc"?"desc":"asc"):(v(a),W("asc"))},Ee=a=>{l(N=>{const S=new Set(N);return S.has(a)?S.delete(a):S.add(a),S})},Ge=()=>{_(""),b("all"),l(new Set)},we=(a,N)=>{k(null),T(!1),K(S=>{const $=new Set(S);return N?$.add(a):$.delete(a),$})},Ke=()=>{k(null),T(!1),K(()=>ue.length===0||be?new Set:new Set(Be))},ie=()=>{T(!1),K(new Set)},$e=async a=>{if(!(!d||Me.length===0)){T(!1),k(null);try{const N=await d.bulkEntityMutation.mutateAsync({items:Me.map(({node:S})=>({type:S.type,id:S.id})),mode:"update",updates:{status:a}});N.failed>0?k({tone:"error",message:`Updated ${N.updated}, failed ${N.failed}.`}):k({tone:"success",message:`Updated ${N.updated} item${N.updated===1?"":"s"} to ${Ne(a)}.`})}catch(N){k({tone:"error",message:N instanceof Error?N.message:"Bulk status update failed."})}}},_e=async()=>{if(!(!d||Me.length===0)){k(null);try{const a=await d.bulkEntityMutation.mutateAsync({items:Me.map(({node:N})=>({type:N.type,id:N.id})),mode:"delete"});a.failed>0?k({tone:"error",message:`Deleted ${a.updated}, failed ${a.failed}.`}):(k({tone:"success",message:`Deleted ${a.updated} item${a.updated===1?"":"s"}.`}),K(new Set),T(!1))}catch(a){k({tone:"error",message:a instanceof Error?a.message:"Bulk delete failed."})}}},Se=({field:a})=>u!==a?e.jsx("span",{className:"text-white/20 ml-0.5",children:"↕"}):e.jsx("span",{className:"text-[#BFFF00] ml-0.5",children:B==="asc"?"↑":"↓"});return e.jsxs("section",{className:"space-y-2.5",children:[e.jsxs("div",{className:"mb-3.5 flex flex-col gap-3 xl:flex-row xl:items-center xl:justify-between",children:[e.jsx("div",{className:"w-full xl:max-w-[380px]",children:e.jsx(gs,{value:M,onChange:_,placeholder:"Search items or agents..."})}),e.jsxs("div",{className:"flex min-h-[40px] min-w-0 flex-wrap items-center gap-2.5",children:[h&&e.jsxs("button",{type:"button",onClick:h,"data-state":o?"active":"idle",className:`control-pill inline-flex h-8 items-center gap-1.5 px-3.5 text-[11px] font-semibold ${o?"text-[#D8FFA1]":"text-white/65 hover:text-white/85"}`,children:[e.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:e.jsx("path",{d:"M17 3a2.828 2.828 0 1 1 4 4L7.5 20.5 2 22l1.5-5.5L17 3z"})}),o?"Editing":"Edit"]}),e.jsxs("div",{ref:q,className:"relative",children:[e.jsxs("button",{type:"button",onClick:()=>C(a=>!a),"data-state":p||Re>0?"active":"idle",className:"control-pill flex items-center gap-1.5 px-3.5 text-[11px] font-semibold",children:[e.jsx("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:e.jsx("path",{d:"M22 3H2l8 9.46V19l4 2v-8.54L22 3z"})}),e.jsx("span",{children:"Filters"}),Re>0&&e.jsx("span",{className:"inline-flex min-w-[16px] items-center justify-center rounded-full border border-current/30 bg-black/25 px-1 text-[10px] leading-4",children:Re})]}),e.jsx(Le,{children:p&&e.jsxs(le.div,{initial:{opacity:0,y:-4,scale:.97},animate:{opacity:1,y:0,scale:1},exit:{opacity:0,y:-4,scale:.97},transition:{duration:.16,ease:[.22,1,.36,1]},className:"surface-tier-2 absolute left-0 top-10 z-30 w-[360px] max-w-[86vw] rounded-xl p-3 shadow-[0_16px_40px_rgba(0,0,0,0.45)] backdrop-blur-xl",children:[e.jsxs("div",{className:"mb-2",children:[e.jsx("div",{className:"text-[10px] font-semibold uppercase tracking-[0.08em] text-white/38",children:"Scope"}),e.jsx("div",{className:"mt-1.5 flex flex-wrap gap-1.5",children:[{id:"all",label:"All",count:oe.all},{id:"open",label:"Open",count:oe.open},{id:"blocked",label:"Blocked",count:oe.blocked},{id:"done",label:"Done",count:oe.done}].map(a=>{const N=g===a.id;return e.jsxs("button",{type:"button",onClick:()=>b(a.id),className:`inline-flex h-7 items-center gap-1.5 rounded-full border px-2.5 text-[10px] font-semibold transition-colors ${N?"border-[#BFFF00]/30 bg-[#BFFF00]/10 text-[#D8FFA1]":"border-white/[0.12] bg-white/[0.03] text-white/60 hover:bg-white/[0.07] hover:text-white/82"}`,children:[e.jsx("span",{children:a.label}),e.jsx("span",{className:"text-[9px] text-current/80",children:a.count})]},a.id)})})]}),e.jsxs("div",{className:"mb-2 border-t border-white/[0.08] pt-2",children:[e.jsx("div",{className:"text-[10px] font-semibold uppercase tracking-[0.08em] text-white/38",children:"Status"}),e.jsx("div",{className:"mt-1.5 flex flex-wrap gap-1.5",children:ns.map(a=>{const N=m.has(a),S=Y.get(a)??0;return e.jsxs("button",{type:"button",onClick:()=>Ee(a),className:`inline-flex h-7 items-center gap-1 rounded-full border px-2.5 text-[10px] transition-colors ${N?"border-[#14B8A6]/35 bg-[#14B8A6]/12 text-[#8FF7EC]":"border-white/[0.12] bg-white/[0.03] text-white/58 hover:bg-white/[0.07] hover:text-white/85"}`,children:[e.jsx("span",{children:Ne(a)}),e.jsx("span",{className:"text-[9px] text-current/75",children:S})]},a)})})]}),(g!=="all"||m.size>0)&&e.jsx("button",{type:"button",onClick:()=>{b("all"),l(new Set)},className:"text-[10px] text-white/45 transition-colors hover:text-white/75",children:"Reset filters"})]})})]}),e.jsx(Le,{initial:!1,children:st&&e.jsx(le.button,{type:"button",onClick:Ge,initial:{opacity:0,x:-4},animate:{opacity:1,x:0},exit:{opacity:0,x:-4},transition:{duration:.16,ease:[.22,1,.36,1]},className:"control-pill inline-flex h-8 items-center px-2.5 text-[11px] font-medium text-white/70 hover:text-white/88",children:"Clear"},"hierarchy-clear-filters")}),e.jsx("button",{type:"button",onClick:Ke,"data-state":be?"active":"idle",className:"control-pill inline-flex h-8 items-center gap-1.5 px-3.5 text-[11px] font-semibold",children:be?"Clear visible":"Select visible"})]})]}),e.jsx("div",{className:`rounded-xl border px-3 ${me>0?"border-[#BFFF00]/24 bg-[#BFFF00]/[0.08]":"border-white/[0.08] bg-white/[0.02]"}`,children:e.jsxs("div",{className:"flex h-[48px] min-w-max flex-nowrap items-center gap-2 overflow-x-auto py-1 whitespace-nowrap",children:[e.jsxs("label",{className:"inline-flex flex-shrink-0 items-center gap-2 text-[11px] text-white/75",children:[e.jsx("input",{ref:z,type:"checkbox",checked:be,onChange:Ke,className:"h-3.5 w-3.5 rounded border-white/20 bg-black/40 text-[#BFFF00] focus:ring-[#BFFF00]/35"}),"Select all visible"]}),e.jsx("span",{className:"flex-shrink-0 text-[11px] text-white/58",children:me>0?`${me} selected`:`${ue.length} visible`}),me>0&&e.jsxs("div",{className:"flex flex-shrink-0 items-center gap-2 whitespace-nowrap",children:[e.jsx("button",{type:"button",onClick:()=>{$e("planned")},disabled:pe,className:"control-pill h-8 flex-shrink-0 px-3 text-[11px] font-semibold disabled:opacity-45",children:"Plan"}),e.jsx("button",{type:"button",onClick:()=>{$e("in_progress")},disabled:pe,className:"control-pill h-8 flex-shrink-0 px-3 text-[11px] font-semibold disabled:opacity-45","data-state":"active",children:"Start"}),e.jsx("button",{type:"button",onClick:()=>{$e("blocked")},disabled:pe,className:"control-pill h-8 flex-shrink-0 px-3 text-[11px] font-semibold disabled:opacity-45",children:"Block"}),e.jsx("button",{type:"button",onClick:()=>{$e("done")},disabled:pe,className:"control-pill h-8 flex-shrink-0 px-3 text-[11px] font-semibold disabled:opacity-45",children:"Complete"}),U?e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-[10px] text-white/58",children:"Delete selected?"}),e.jsx("button",{type:"button",onClick:()=>{_e()},disabled:pe,className:"control-pill h-8 flex-shrink-0 border-red-400/35 bg-red-500/14 px-3 text-[11px] font-semibold text-red-100 disabled:opacity-45",children:"Delete"}),e.jsx("button",{type:"button",onClick:()=>T(!1),disabled:pe,className:"control-pill h-8 flex-shrink-0 px-2.5 text-[11px] disabled:opacity-45",children:"Keep"})]}):e.jsx("button",{type:"button",onClick:()=>T(!0),disabled:pe,className:"control-pill h-8 flex-shrink-0 border-red-400/24 bg-red-500/[0.08] px-3 text-[11px] font-semibold text-red-100/85 disabled:opacity-45",children:"Delete"}),e.jsx("button",{type:"button",onClick:ie,disabled:pe,className:"text-[11px] text-white/55 transition-colors hover:text-white/80 disabled:opacity-45",children:"Clear"})]})]})}),Q&&e.jsx("div",{className:`rounded-lg border px-3 py-2 text-[11px] ${Q.tone==="success"?"border-emerald-400/24 bg-emerald-500/[0.1] text-emerald-100":"border-amber-400/24 bg-amber-500/[0.1] text-amber-100"}`,children:Q.message}),o&&e.jsx("div",{className:"mb-2 text-[10px] text-white/45",children:"Edit mode: select a row to edit its fields inline."}),e.jsx("div",{className:"overflow-x-auto rounded-xl border border-white/[0.07] bg-black/[0.14] p-2",children:e.jsxs("table",{className:"w-full min-w-[1180px] border-separate border-spacing-y-1.5",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"text-left text-[10px] uppercase tracking-[0.08em] text-white/42",children:[e.jsx("th",{className:"w-10 px-2 py-1.5",children:e.jsx("span",{className:"sr-only",children:"Select rows"})}),e.jsxs("th",{className:"px-2 py-1.5 cursor-pointer select-none",onClick:()=>Ie("title"),children:["Item ",e.jsx(Se,{field:"title"})]}),e.jsx("th",{className:"w-[188px] px-2 py-1.5",children:"Assigned"}),e.jsxs("th",{className:"px-2 py-1.5 cursor-pointer select-none",onClick:()=>Ie("status"),children:["Status ",e.jsx(Se,{field:"status"})]}),e.jsx("th",{className:"px-2 py-1.5",children:"Progress"}),e.jsxs("th",{className:"px-2 py-1.5 cursor-pointer select-none",onClick:()=>Ie("priority"),children:["Priority ",e.jsx(Se,{field:"priority"})]}),e.jsxs("th",{className:"px-2 py-1.5 cursor-pointer select-none",onClick:()=>Ie("eta"),children:["ETA ",e.jsx(Se,{field:"eta"})]}),e.jsx("th",{className:"px-2 py-1.5",children:"Duration (h)"}),e.jsx("th",{className:"px-2 py-1.5",children:"Budget ($)"}),e.jsx("th",{className:"px-2 py-1.5",children:"Dependencies"})]})}),e.jsx("tbody",{children:ue.map(({node:a,depth:N,canCollapse:S})=>{var P;const $=i===a.id,ee=x.has(a.id),je=X.has(a.id),xe=a.assignedAgents.map(I=>I.name).join(", "),Fe=a.dependencyIds.map(I=>{var de;return((de=ne.get(I))==null?void 0:de.title)??I}).slice(0,3).join(", "),he=Oe.get(a.id),D=o&&$;return e.jsxs("tr",{onClick:()=>{r(a.id),a.type==="workstream"&&j(a.id)},className:`group/row cursor-pointer rounded-lg border transition-colors ${$?"border-[#BFFF00]/[0.22] bg-[#BFFF00]/[0.08]":ee?"border-[#14B8A6]/[0.2] bg-[#14B8A6]/[0.08]":"border-white/[0.06] bg-white/[0.02] hover:border-white/[0.14] hover:bg-white/[0.05]"}`,children:[e.jsx("td",{className:"rounded-l-lg px-2 py-1.5",children:e.jsx("input",{type:"checkbox",checked:je,onChange:I=>{I.stopPropagation(),we(a.id,I.currentTarget.checked)},onClick:I=>I.stopPropagation(),"aria-label":`Select ${a.type}: ${a.title}`,className:"h-3.5 w-3.5 rounded border-white/20 bg-black/40 text-[#BFFF00] focus:ring-[#BFFF00]/35"})}),e.jsx("td",{className:"px-2 py-1.5",children:e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("div",{style:{width:N*14}}),S?e.jsx("button",{type:"button",onClick:I=>{I.stopPropagation(),ge(de=>{const y=new Set(de);return y.has(a.id)?y.delete(a.id):y.add(a.id),y})},"aria-label":`${se.has(a.id)?"Collapse":"Expand"} ${a.type}: ${a.title}`,className:"rounded text-white/50 focus:outline-none focus-visible:ring-2 focus-visible:ring-[#BFFF00]/35 focus-visible:ring-offset-2 focus-visible:ring-offset-[#02040A]",children:se.has(a.id)?"▾":"▸"}):e.jsx("span",{className:"w-2.5"}),e.jsx(kt,{type:a.type}),e.jsx("button",{type:"button",onClick:I=>{I.stopPropagation(),w(a)},"aria-label":`Open ${a.type} details: ${a.title}`,className:"max-w-[320px] truncate rounded text-[12px] text-white/88 hover:text-white focus:outline-none focus-visible:ring-2 focus-visible:ring-[#BFFF00]/35 focus-visible:ring-offset-2 focus-visible:ring-offset-[#02040A]",children:a.title}),a.type==="task"&&d&&!o&&e.jsx("div",{className:"flex items-center gap-0.5 opacity-0 group-hover/row:opacity-100 transition-opacity ml-1",children:["not_started","todo","planned","pending","backlog"].includes(a.status.toLowerCase())?e.jsx("button",{type:"button",title:"Start",onClick:I=>{I.stopPropagation(),F(a,{status:"in_progress"})},"aria-label":`Start task: ${a.title}`,className:"flex items-center justify-center w-5 h-5 rounded text-white/40 transition-colors hover:text-[#BFFF00] hover:bg-white/[0.06] focus:outline-none focus-visible:ring-2 focus-visible:ring-[#BFFF00]/35 focus-visible:ring-offset-2 focus-visible:ring-offset-[#02040A]",children:e.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"currentColor",children:e.jsx("path",{d:"M8 5v14l11-7z"})})}):["in_progress","active"].includes(a.status.toLowerCase())?e.jsx("button",{type:"button",title:"Mark done",onClick:I=>{I.stopPropagation(),F(a,{status:"done"})},"aria-label":`Mark task done: ${a.title}`,className:"flex items-center justify-center w-5 h-5 rounded text-white/40 transition-colors hover:text-emerald-400 hover:bg-white/[0.06] focus:outline-none focus-visible:ring-2 focus-visible:ring-[#BFFF00]/35 focus-visible:ring-offset-2 focus-visible:ring-offset-[#02040A]",children:e.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"3",children:e.jsx("path",{d:"M20 6 9 17l-5-5"})})}):null})]})}),e.jsx("td",{className:"px-2 py-1.5 text-[11px] text-white/75 whitespace-nowrap",children:D?e.jsx("input",{type:"text",defaultValue:xe,placeholder:"Agent A, Agent B",onClick:I=>I.stopPropagation(),onBlur:I=>{const de=I.currentTarget.value.split(",").map(y=>y.trim()).filter(Boolean);F(a,{assigned_agent_names:de,assigned_agent_ids:de.map(y=>`name:${y}`),assignment_source:"manual"})},className:"w-[190px] rounded border border-white/[0.16] bg-white/[0.06] px-2 py-1 text-[10px] text-white/82"}):e.jsx("div",{className:"flex items-center gap-2",children:a.assignedAgents.length>0?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"flex items-center -space-x-1.5",children:a.assignedAgents.slice(0,3).map(I=>e.jsx("div",{title:I.name,className:"rounded-full ring-1 ring-[#02040A]",children:e.jsx(Ut,{name:I.name,hint:`${I.id} ${a.title}`,size:"xs"})},`${a.id}:${I.id}`))}),e.jsxs("span",{className:"max-w-[110px] truncate text-[10px] text-white/62",title:xe,children:[(P=a.assignedAgents[0])==null?void 0:P.name,a.assignedAgents.length>1?` +${a.assignedAgents.length-1}`:""]})]}):e.jsx("span",{className:"text-white/35",children:"Unassigned"})})}),e.jsx("td",{className:"px-2 py-1.5 text-[11px] text-white/75",children:D?e.jsx("select",{defaultValue:mt(a.status),onClick:I=>I.stopPropagation(),onChange:I=>{F(a,{status:I.target.value})},className:"rounded border border-white/[0.16] bg-white/[0.06] px-2 py-1 text-[10px] text-white/82",children:ns.map(I=>e.jsx("option",{value:I,children:Ne(I)},I))}):e.jsx("span",{className:"status-pill whitespace-nowrap","data-tone":nn(a.status),children:Ne(a.status)})}),e.jsx("td",{className:"px-2 py-1.5 text-[11px] text-white/75",children:he!==void 0&&(a.type==="workstream"||a.type==="milestone")?e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"h-1 w-[72px] rounded-full bg-white/[0.06] overflow-hidden",children:e.jsx("div",{className:"h-full rounded-full transition-all",style:{width:`${he}%`,backgroundColor:a.type==="milestone"?O.teal:O.lime}})}),e.jsxs("span",{className:"text-[10px] text-white/60",style:{fontVariantNumeric:"tabular-nums"},children:[he,"%"]})]}):e.jsx("span",{className:"text-white/35",children:"—"})}),e.jsx("td",{className:"px-2 py-1.5 text-[11px] text-white/75",children:D?e.jsx("input",{type:"number",min:1,max:100,defaultValue:a.priorityNum,onClick:I=>I.stopPropagation(),onBlur:I=>{const de=Number(I.currentTarget.value);Number.isFinite(de)&&F(a,{priority_num:de})},className:"w-[72px] rounded border border-white/[0.16] bg-white/[0.06] px-2 py-1 text-[10px] text-white/82"}):e.jsxs("span",{children:["P",a.priorityNum]})}),e.jsx("td",{className:"px-2 py-1.5 text-[11px] text-white/75",children:D?e.jsx("input",{type:"datetime-local",defaultValue:sn(a.etaEndAt),onClick:I=>I.stopPropagation(),onBlur:I=>{const de=I.currentTarget.value;F(a,{eta_end_at:de?new Date(de).toISOString():null})},className:"w-[176px] rounded border border-white/[0.16] bg-white/[0.06] px-2 py-1 text-[10px] text-white/82"}):e.jsx("span",{children:a.etaEndAt?new Date(a.etaEndAt).toLocaleString():"—"})}),e.jsx("td",{className:"px-2 py-1.5 text-[11px] text-white/75",children:D&&a.type!=="task"?e.jsx("input",{type:"number",min:0,step:.5,defaultValue:a.expectedDurationHours,onClick:I=>I.stopPropagation(),onBlur:I=>{const de=Number(I.currentTarget.value);Number.isFinite(de)&&F(a,{expected_duration_hours:de})},className:"w-[82px] rounded border border-white/[0.16] bg-white/[0.06] px-2 py-1 text-[10px] text-white/82"}):e.jsx("span",{children:a.expectedDurationHours})}),e.jsx("td",{className:"px-2 py-1.5 text-[11px] text-white/75",children:D&&a.type!=="task"?e.jsx("input",{type:"number",min:0,step:1,defaultValue:a.expectedBudgetUsd,onClick:I=>I.stopPropagation(),onBlur:I=>{const de=Number(I.currentTarget.value);Number.isFinite(de)&&F(a,{expected_budget_usd:de})},className:"w-[92px] rounded border border-white/[0.16] bg-white/[0.06] px-2 py-1 text-[10px] text-white/82"}):e.jsxs("span",{children:["$",a.expectedBudgetUsd.toLocaleString(),D&&a.type==="task"?" (from task spec)":""]})}),e.jsx("td",{className:"rounded-r-lg px-2 py-1.5 text-[11px] text-white/75",children:D?e.jsx("div",{onClick:I=>I.stopPropagation(),children:e.jsx(tn,{dependencies:a.dependencyIds,allNodes:L,onSave:I=>void F(a,{depends_on:I})})}):e.jsx("div",{className:"max-w-[250px] truncate",children:ze(a)>0?`${ze(a)} · ${Fe}`:"—"})})]},a.id)})})]})}),ue.length===0&&e.jsxs("div",{className:"flex flex-col items-center py-10",children:[e.jsxs("svg",{width:"32",height:"32",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",className:"text-white/20",children:[e.jsx("path",{d:"M9 5H7a2 2 0 0 0-2 2v12a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V7a2 2 0 0 0-2-2h-2"}),e.jsx("rect",{x:"9",y:"3",width:"6",height:"4",rx:"1"}),e.jsx("path",{d:"M9 14h6M9 18h4"})]}),e.jsx("div",{className:"mt-3 text-[13px] font-medium text-white/50",children:M||m.size>0||g!=="all"?"No items match the current filters":"No work items yet"}),e.jsx("div",{className:"mt-1 text-[11px] text-white/30",children:M||m.size>0||g!=="all"?"Try adjusting your search or filter criteria.":"Workstreams, milestones, and tasks will appear here."})]})]})}function as(t){if(!t)return"No target date";const s=new Date(t);return Number.isNaN(s.getTime())?"No target date":`Due ${s.toLocaleDateString()}`}function cn({recentTodoIds:t,nodesById:s,selectedNodeId:i,onSelectNode:x}){const o=t.map(j=>s.get(j)).filter(j=>!!j).sort((j,w)=>{if(j.priorityNum!==w.priorityNum)return j.priorityNum-w.priorityNum;const F=j.dueDate?Date.parse(j.dueDate):Number.POSITIVE_INFINITY,d=w.dueDate?Date.parse(w.dueDate):Number.POSITIVE_INFINITY;return F-d}).slice(0,14);if(o.length===0)return null;const h=o[0],r=o.slice(1,7);return e.jsxs("section",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("span",{className:"text-[10px] uppercase tracking-[0.08em] text-white/42",children:"Queue overview"}),e.jsxs("span",{className:"rounded-full border border-white/15 bg-black/20 px-2 py-0.5 text-[10px] text-white/65",children:[o.length," in queue"]})]}),e.jsx("button",{type:"button",onClick:()=>x(h.id),className:`surface-hero group w-full rounded-xl border px-3.5 py-3 text-left transition-colors ${i===h.id?"border-[#BFFF00]/35 bg-[#BFFF00]/14":"border-white/15 bg-black/25 hover:border-white/30 hover:bg-white/[0.08]"}`,children:e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"inline-flex items-center gap-1.5 text-[10px] uppercase tracking-[0.1em] text-white/50",children:[e.jsx(kt,{type:h.type}),e.jsx("span",{children:"Priority task"})]}),e.jsx("p",{className:"mt-1 line-clamp-2 text-[13px] font-semibold leading-snug text-white",children:h.title}),e.jsx("p",{className:"mt-1 text-[11px] text-white/60",children:as(h.dueDate)})]}),e.jsxs("span",{className:"inline-flex flex-shrink-0 rounded-full border px-2 py-0.5 text-[10px] font-semibold",style:{borderColor:`${O.amber}44`,backgroundColor:`${O.amber}22`,color:O.amber},children:["P",h.priorityNum]})]})}),r.length>0&&e.jsx("div",{className:"space-y-1.5",children:r.map(j=>e.jsxs("button",{type:"button",onClick:()=>x(j.id),className:`flex min-h-[62px] min-w-0 items-start justify-between gap-2 rounded-lg border px-2.5 py-2 text-left transition-colors ${i===j.id?"border-[#BFFF00]/30 bg-[#BFFF00]/12":"border-white/[0.14] bg-black/20 hover:bg-white/[0.08]"}`,children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"inline-flex items-center gap-1.5 text-[9px] uppercase tracking-[0.08em] text-white/45",children:[e.jsx(kt,{type:j.type}),e.jsx("span",{children:"Queued"})]}),e.jsx("p",{className:"mt-1 line-clamp-1 break-words text-[11px] leading-snug text-white/85",title:j.title,children:j.title}),e.jsx("p",{className:"mt-1 text-[10px] text-white/50",children:as(j.dueDate)})]}),e.jsxs("span",{className:"inline-flex flex-shrink-0 rounded-full px-1.5 py-0.5 text-[9px]",style:{backgroundColor:`${O.amber}22`,color:`${O.amber}`},children:["P",j.priorityNum]})]},j.id))})]})}function dn(t,s){try{const i=localStorage.getItem(`orgx.section.${t}`);if(i==="0")return!1;if(i==="1")return!0}catch{}return s}function un(t,s){try{localStorage.setItem(`orgx.section.${t}`,s?"1":"0")}catch{}}function ft({title:t,defaultOpen:s=!0,storageKey:i,sticky:x=!1,stickyOffsetClass:o="top-0",stickyTop:h,children:r}){const[j,w]=n.useState(()=>i?dn(i,s):s),F=n.useRef(null),[d,M]=n.useState(40),_=()=>{const m=!j;w(m),i&&un(i,m)};return n.useEffect(()=>{if(!x)return;const m=F.current;if(!m)return;const l=()=>{const b=Math.max(34,m.offsetHeight);M(p=>p===b?p:b)};if(l(),typeof ResizeObserver>"u")return;const g=new ResizeObserver(()=>l());return g.observe(m),()=>g.disconnect()},[x,h,t]),e.jsxs("div",{style:x?{"--mc-collapsible-header-offset":`${d}px`}:void 0,children:[e.jsxs("button",{ref:x?F:void 0,type:"button","data-mc-section-header":t,onClick:_,className:`flex w-full items-center gap-2 rounded-lg border px-2 py-2 text-left transition-colors ${x?`sticky ${o} z-20 border-white/[0.08] bg-[#090B11]/92 shadow-[0_8px_18px_rgba(0,0,0,0.24)] backdrop-blur-xl`:"border-transparent hover:border-white/[0.06] hover:bg-white/[0.03]"}`,style:x&&h?{top:h}:void 0,children:[e.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",className:`text-white/30 transition-transform duration-200 ${j?"rotate-180":""}`,children:e.jsx("path",{d:"m6 9 6 6 6-6"})}),e.jsx("span",{className:"text-[11px] font-semibold tracking-[0.02em] text-white/68",children:t})]}),e.jsx(Le,{initial:!1,children:j&&e.jsx(le.div,{initial:{height:0,opacity:0},animate:{height:"auto",opacity:1},exit:{height:0,opacity:0},transition:{type:"spring",stiffness:400,damping:35},className:"overflow-hidden",children:r})})]})}function pn(t){if(!t)return{priorityNum:60,priorityLabel:null};const s=t.trim().toLowerCase();if(s==="urgent"||s==="p0")return{priorityNum:10,priorityLabel:"urgent"};if(s==="high"||s==="p1")return{priorityNum:25,priorityLabel:"high"};if(s==="medium"||s==="p2")return{priorityNum:50,priorityLabel:"medium"};if(s==="low"||s==="p3"||s==="p4")return{priorityNum:75,priorityLabel:"low"};const i=Number(s.replace(/^p/,""));return Number.isFinite(i)?{priorityNum:Math.max(1,Math.min(100,Math.round(i))),priorityLabel:null}:{priorityNum:60,priorityLabel:null}}function xn(t){const s=t.toLowerCase();return["todo","not_started","planned","pending","backlog"].includes(s)}function hn(t){const s=t.toLowerCase();return["in_progress","active","running","queued"].includes(s)}function mn(t,s){const i={id:t.id,type:"initiative",title:t.name,status:t.rawStatus??t.status,parentId:null,initiativeId:t.id,workstreamId:null,milestoneId:null,priorityNum:60,priorityLabel:null,dependencyIds:[],dueDate:t.targetDate??null,etaEndAt:t.targetDate??null,expectedDurationHours:40,expectedBudgetUsd:1500,assignedAgents:[],updatedAt:t.updatedAt??t.createdAt??null},o=(s.workstreams.length>0?s.workstreams:(t.workstreams??[]).map(d=>({id:d.id,name:d.name,summary:null,status:d.status,progress:null,initiativeId:t.id,createdAt:null}))).map(d=>({id:d.id,type:"workstream",title:d.name,status:d.status,parentId:t.id,initiativeId:t.id,workstreamId:d.id,milestoneId:null,priorityNum:50,priorityLabel:"medium",dependencyIds:[],dueDate:null,etaEndAt:null,expectedDurationHours:16,expectedBudgetUsd:300,assignedAgents:[],updatedAt:d.createdAt})),h=new Set(o.map(d=>d.id)),r=s.milestones.map(d=>({id:d.id,type:"milestone",title:d.title,status:d.status,parentId:d.workstreamId&&h.has(d.workstreamId)?d.workstreamId:t.id,initiativeId:t.id,workstreamId:d.workstreamId&&h.has(d.workstreamId)?d.workstreamId:null,milestoneId:d.id,priorityNum:50,priorityLabel:"medium",dependencyIds:[],dueDate:d.dueDate,etaEndAt:d.dueDate,expectedDurationHours:6,expectedBudgetUsd:120,assignedAgents:[],updatedAt:d.createdAt})),j=new Set(r.map(d=>d.id)),w=s.tasks.map(d=>{const M=pn(d.priority),_=d.milestoneId&&j.has(d.milestoneId),m=d.workstreamId&&h.has(d.workstreamId);return{id:d.id,type:"task",title:d.title,status:d.status,parentId:_?d.milestoneId:m?d.workstreamId:t.id,initiativeId:t.id,workstreamId:m?d.workstreamId:null,milestoneId:_?d.milestoneId:null,priorityNum:M.priorityNum,priorityLabel:M.priorityLabel,dependencyIds:[],dueDate:d.dueDate,etaEndAt:d.dueDate,expectedDurationHours:2,expectedBudgetUsd:40,assignedAgents:[],updatedAt:d.createdAt}}),F=w.filter(d=>["todo","not_started","planned","pending","backlog"].includes(d.status.toLowerCase())).sort((d,M)=>{const _=d.priorityNum-M.priorityNum;if(_!==0)return _;const m=d.etaEndAt?Date.parse(d.etaEndAt):1/0,l=M.etaEndAt?Date.parse(M.etaEndAt):1/0;if(m!==l)return m-l;const g=d.updatedAt?Date.parse(d.updatedAt):0;return(M.updatedAt?Date.parse(M.updatedAt):0)-g}).map(d=>d.id);return{nodes:[i,...o,...r,...w],edges:[],recentTodos:F}}function fn(t,s){if(!t)return new Set;const i=new Map(s.map(r=>[r.id,r])),x=new Map;for(const r of s)for(const j of r.dependencyIds){const w=x.get(j)??[];w.push(r.id),x.set(j,w)}const o=new Set,h=[t];for(;h.length>0;){const r=h.shift();if(o.has(r))continue;o.add(r);const j=i.get(r);if(j){for(const w of j.dependencyIds)o.has(w)||h.push(w);for(const w of x.get(r)??[])o.has(w)||h.push(w)}}return o}function gn(t,s){return{id:t.id,name:t.title,summary:null,status:t.status,progress:null,initiativeId:s.id,createdAt:t.updatedAt}}function bn(t,s){return{id:t.id,title:t.title,description:null,status:t.status,dueDate:t.dueDate,initiativeId:s.id,workstreamId:t.workstreamId,createdAt:t.updatedAt}}function wn(t,s){return{id:t.id,title:t.title,description:null,status:t.status,priority:t.priorityLabel??`p${t.priorityNum}`,dueDate:t.dueDate,initiativeId:s.id,milestoneId:t.milestoneId,workstreamId:t.workstreamId,createdAt:t.updatedAt}}function yn(t){return/unknown api endpoint/i.test(t)?"Graph API unavailable — showing session-derived data":/401|unauthorized/i.test(t)?"Auth expired — reconnect to load full data":/failed to list initiative/i.test(t)?"Initiative data unavailable":/failed to list workstream/i.test(t)?"Workstream data unavailable":/failed to list milestone/i.test(t)?"Milestone data unavailable":/failed to list task/i.test(t)?"Task data unavailable":/500 internal server/i.test(t)?"Server error — some data may be incomplete":/entity data partially unavailable/i.test(t)?"Entity data partially unavailable":t.length>80?t.slice(0,72).replace(/[^a-zA-Z0-9]$/,"")+"...":t}const pt={hidden:{opacity:0},show:{opacity:1}};function gt({label:t,value:s}){return e.jsxs("div",{className:"rounded-lg border border-white/[0.08] bg-white/[0.03] px-2.5 py-2",children:[e.jsx("div",{className:"text-[10px] text-white/45",children:t}),e.jsx("div",{className:"mt-0.5 text-[12px] font-semibold text-white/85",children:s})]})}function jn({initiative:t,selected:s=!1,onSelectionChange:i,runtimeActivity:x=null}){var de;const{expandedInitiatives:o,toggleExpanded:h,openModal:r,agentEntityMap:j,authToken:w,embedMode:F,mutations:d}=tt(),[M,_]=n.useState(!1),[m,l]=n.useState(null),[g,b]=n.useState(null),[p,C]=n.useState(!1),[u,v]=n.useState(!1),B=n.useRef(null),[W,X]=n.useState(52),[K,U]=n.useState(0),T=o.has(t.id),{graph:Q,isLoading:k,degraded:z,error:q}=Js({initiativeId:t.id,authToken:w,embedMode:F,enabled:T}),{details:ne,isLoading:L,error:Y}=Nt({initiativeId:t.id,authToken:w,embedMode:F,enabled:T}),oe=n.useMemo(()=>mn(t,ne),[t,ne]),c=!!(Q&&Q.nodes.length>0),te=oe.nodes.length>0,J=!c&&te,G=J?oe.nodes:c?(Q==null?void 0:Q.nodes)??[]:oe.nodes,Z=J?oe.edges:c?(Q==null?void 0:Q.edges)??[]:oe.edges,A=J?oe.recentTodos:c?(Q==null?void 0:Q.recentTodos)??[]:oe.recentTodos,se=z.some(y=>/401|unauthorized/i.test(y))||!!(q&&/401|unauthorized/i.test(q))||!!(Y&&/401|unauthorized/i.test(Y)),ge=q&&/unknown api endpoint/i.test(q)?"Graph API unavailable. Showing session-derived data.":q,ye=Y,ue=[...z,...ge?[ge]:[],...ye?[`Entity data partially unavailable: ${ye}`]:[],...se?["OrgX auth is missing or expired in this local plugin instance. Reconnect in onboarding to load full workstreams/milestones/tasks."]:[]],Be=n.useMemo(()=>new Map(G.map(y=>[y.id,y])),[G]),Ye=n.useMemo(()=>fn(m,G),[m,G]),Me=n.useMemo(()=>A.some(y=>Be.has(y)),[Be,A]);n.useEffect(()=>{const y=B.current;if(!y||!T)return;const re=()=>{const qe=Math.max(48,y.offsetHeight);X(He=>He===qe?He:qe)};if(re(),typeof ResizeObserver>"u")return;const Ue=new ResizeObserver(()=>re());return Ue.observe(y),()=>Ue.disconnect()},[T,t.status,t.targetDate,t.name]),n.useEffect(()=>{const y=B.current;if(!y||!T){U(0);return}const re=y.closest('[data-mc-scroll-host="true"]')??y.closest(".h-full.overflow-y-auto.overflow-x-hidden"),Ue=re??window;let qe=0;const He=()=>{qe=0;const Ce=Number.parseFloat(getComputedStyle(y).top||"0"),Ve=y.getBoundingClientRect(),Qe=(re==null?void 0:re.getBoundingClientRect().top)??0,ut=1-(Ve.top-Qe-Ce)/56,at=Math.pow(Math.max(0,Math.min(1,ut)),1.2);U(De=>Math.abs(De-at)<.015?De:at)},nt=()=>{qe||(qe=window.requestAnimationFrame(He))};return He(),Ue.addEventListener("scroll",nt,{passive:!0}),window.addEventListener("resize",nt),()=>{qe&&window.cancelAnimationFrame(qe),Ue.removeEventListener("scroll",nt),window.removeEventListener("resize",nt)}},[T,t.id]),n.useEffect(()=>{var y;T&&!m&&G.length>0&&l(((y=G[0])==null?void 0:y.id)??null)},[T,G,m]);const Re=((Q==null?void 0:Q.initiative.assignedAgents)??[]).map(y=>({id:y.id,name:y.name,confidence:"high"})),st=j.get(t.id)??[],me=Re.length>0?Re:st,be=G.filter(y=>y.type==="task"),pe=be.filter(y=>hn(y.status)).length,ze=be.filter(y=>xn(y.status)).length,Oe=be.filter(y=>Ae(y.status)).length,Ie=(x==null?void 0:x.activeCount)??0,Ee=(x==null?void 0:x.totalCount)??0,Ge=pe>0||Ie>0,we=t.status==="active"&&Ge?"in_progress":t.status,Ke=we==="in_progress"?jt.active:jt[we],ie=we==="in_progress"?"In Progress":Ne(we),$e=be.length>0?be:G.some(y=>y.type==="milestone")?G.filter(y=>y.type==="milestone"):G.filter(y=>y.type==="workstream"),_e=Math.round($e.reduce((y,re)=>y+(re.expectedDurationHours||0),0)*10)/10,Se=Math.round($e.reduce((y,re)=>y+(re.expectedBudgetUsd||0),0)*100)/100,a=G.filter(y=>y.type==="milestone"),N=G.filter(y=>y.type==="workstream"),S=T&&(c||ne.workstreams.length>0||ne.milestones.length>0||ne.tasks.length>0),$=be.length>0?et(Oe,be.length):a.length>0?et(a.filter(y=>Ae(y.status)).length,a.length):S&&N.length>0?et(N.filter(y=>Ae(y.status)).length,N.length):null,ee=St($===null?t.health:$),je=ee===0?2:ee,xe=Math.pow(K,.82),Fe=Math.max(0,Number((16*(1-xe)).toFixed(2))),he=`0 10px 26px rgba(0,0,0,${(.18+xe*.24).toFixed(3)}), 0 1px 0 rgba(191,255,0,${(xe*.09).toFixed(3)})`,D=y=>{if(y.type==="initiative"){r({type:"initiative",entity:t});return}if(y.type==="workstream"){r({type:"workstream",entity:gn(y,t),initiative:t});return}if(y.type==="milestone"){r({type:"milestone",entity:bn(y,t),initiative:t});return}r({type:"task",entity:wn(y,t),initiative:t})},P=async(y,re)=>{await d.updateEntity.mutateAsync({type:y.type,id:y.id,...re})},I=y=>re=>{re.stopPropagation(),d.entityAction.mutate({type:"initiative",id:t.id,action:y})};return e.jsxs("div",{id:`initiative-${t.id}`,className:`surface-tier-1 overflow-visible rounded-2xl transition-[background-color,border-color,box-shadow] duration-200 ${T?"bg-[--orgx-surface-elevated]":"bg-[--orgx-surface]"} ${s?"ring-1 ring-[#BFFF00]/30 shadow-[0_0_0_1px_rgba(191,255,0,0.12)]":""}`,style:{"--mc-initiative-header-offset":`${W}px`},children:[e.jsxs("div",{ref:B,role:"button",tabIndex:0,"aria-expanded":T,onClick:()=>h(t.id),onKeyDown:y=>{(y.key==="Enter"||y.key===" ")&&(y.preventDefault(),h(t.id))},className:`group flex min-h-[66px] w-full min-w-0 items-center gap-2.5 overflow-hidden px-3 py-3 text-left transition-[background-color,border-radius,box-shadow] duration-300 hover:bg-white/[0.035] sm:gap-3 sm:px-4 ${T?"sticky z-30 border-b border-white/[0.06] bg-[#0C0E14]/95 shadow-[0_8px_20px_rgba(0,0,0,0.3)] backdrop-blur-xl":""}`,style:T?{top:"var(--mc-toolbar-offset, 88px)",borderTopLeftRadius:`${Fe}px`,borderTopRightRadius:`${Fe}px`,boxShadow:he}:void 0,children:[e.jsx(le.div,{animate:{rotate:T?90:0},transition:{type:"spring",stiffness:400,damping:25},className:"flex-shrink-0 flex items-center justify-center w-6 h-6 rounded-md transition-colors group-hover:bg-white/[0.06]",children:e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",className:"text-white/40",children:e.jsx("path",{d:"m9 18 6-6-6-6"})})}),i&&e.jsx("div",{className:"flex h-6 w-6 flex-shrink-0 items-center justify-center",children:e.jsx("input",{type:"checkbox",checked:s,onChange:y=>i(t.id,y.currentTarget.checked),onClick:y=>y.stopPropagation(),"aria-label":`Select initiative ${t.name}`,className:"h-3.5 w-3.5 rounded border-white/20 bg-black/40 text-[#BFFF00] focus:ring-[#BFFF00]/35"})}),e.jsx("span",{className:`w-2 h-2 rounded-full flex-shrink-0 ${Ge?"status-breathe":""}`,style:{backgroundColor:ss(we)}}),e.jsx("div",{className:"min-w-0 flex-[1_1_auto] overflow-hidden pr-2 sm:pr-3",children:e.jsx("button",{type:"button",onClick:y=>{y.stopPropagation(),r({type:"initiative",entity:t})},className:"block w-full max-w-full overflow-hidden text-ellipsis whitespace-nowrap text-left text-[13px] font-semibold text-white transition-colors hover:text-white/80 sm:text-[14px]",title:t.name,children:t.name})}),e.jsx("div",{className:"ml-1 flex w-[90px] min-w-[90px] flex-shrink-0 justify-start sm:w-[102px] sm:min-w-[102px]",children:e.jsx("span",{className:`w-full truncate text-center text-[10px] px-2 py-0.5 rounded-full border uppercase tracking-[0.08em] leading-none whitespace-nowrap ${Ke}`,children:ie})}),e.jsxs("div",{className:"ml-1.5 flex w-[148px] min-w-[148px] flex-shrink-0 items-center justify-end gap-2.5 pr-0.5 sm:w-[182px] sm:min-w-[182px] sm:pr-1 md:w-[206px] md:min-w-[206px]",children:[e.jsx("div",{className:"min-w-[88px] flex-1 sm:min-w-[112px] md:min-w-[140px]",children:e.jsx("div",{className:"h-[2px] w-full overflow-hidden rounded-full bg-white/[0.06]",children:e.jsx(le.div,{className:"h-full rounded-full transition-all",initial:!1,animate:{width:`${je}%`,opacity:ee===0?.45:1},transition:{type:"spring",stiffness:260,damping:34,mass:.75},style:{backgroundColor:ss(we)}})})}),e.jsxs("span",{className:"w-[42px] text-right text-[10px] text-white/40 sm:w-[48px] sm:text-[11px]",style:{fontVariantNumeric:"tabular-nums"},children:[ee,"%"]})]}),e.jsx("div",{className:"ml-2 flex w-[104px] min-w-[104px] flex-shrink-0 items-center justify-end border-l border-white/[0.05] pl-2 sm:w-[116px] sm:min-w-[116px] sm:pl-2.5 md:w-[132px] md:min-w-[132px]",children:Ie>0?e.jsxs("span",{className:"inline-flex items-center gap-1 rounded-full border border-[#BFFF00]/30 bg-[#BFFF00]/14 px-2 py-0.5 text-[10px] font-semibold text-[#D8FFA1]",children:[e.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-[#BFFF00] status-breathe"}),Ie," live"]}):me.length>0?e.jsx(Ct,{agents:me,max:3}):Ee>0?e.jsxs("span",{className:"w-full text-right text-[10px] text-white/35",children:[Ee," idle"]}):e.jsx("span",{className:"w-full text-right text-[10px] text-white/28",children:"—"})}),e.jsxs("div",{className:"hidden w-[46px] flex-shrink-0 translate-x-1 items-center justify-end gap-1 opacity-0 transition-all duration-200 group-hover:translate-x-0 group-hover:opacity-100 group-focus-within:translate-x-0 group-focus-within:opacity-100 2xl:flex",children:[t.status==="active"&&e.jsx("button",{type:"button",onClick:I("pause"),title:"Pause",className:"flex items-center justify-center w-6 h-6 rounded-lg text-white/50 hover:text-white hover:bg-white/[0.08] transition-colors",children:e.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"currentColor",children:[e.jsx("rect",{x:"6",y:"4",width:"4",height:"16",rx:"1"}),e.jsx("rect",{x:"14",y:"4",width:"4",height:"16",rx:"1"})]})}),t.status==="paused"&&e.jsx("button",{type:"button",onClick:I("resume"),title:"Resume",className:"flex items-center justify-center w-6 h-6 rounded-lg text-white/50 hover:text-white hover:bg-white/[0.08] transition-colors",children:e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"currentColor",children:e.jsx("path",{d:"M8 5v14l11-7z"})})}),e.jsx("button",{type:"button",onClick:y=>{y.stopPropagation(),r({type:"initiative",entity:t})},title:"Details",className:"flex items-center justify-center w-6 h-6 rounded-lg text-white/50 hover:text-white hover:bg-white/[0.08] transition-colors",children:e.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[e.jsx("circle",{cx:"12",cy:"12",r:"10"}),e.jsx("path",{d:"M12 16v-4M12 8h.01"})]})})]})]}),e.jsx(Le,{children:T&&e.jsx(le.div,{initial:{height:0,opacity:0},animate:{height:"auto",opacity:1},exit:{height:0,opacity:0},transition:{duration:.2,ease:[.22,1,.36,1]},onAnimationStart:()=>v(!0),onAnimationComplete:()=>v(!1),className:u?"overflow-hidden":"overflow-visible",children:e.jsxs("div",{className:"space-y-2.5 px-4 pb-4 pt-2.5",children:[e.jsx("div",{className:"section-divider"}),k||!c&&L?e.jsx("div",{className:"space-y-2",children:Array.from({length:3}).map((y,re)=>e.jsx(ht,{className:"h-24 w-full rounded-xl"},`mc-loading-${re}`))}):e.jsxs(le.div,{initial:"hidden",animate:"show",variants:{hidden:{},show:{transition:{staggerChildren:.08}}},className:"space-y-3.5",children:[ue.length>0&&e.jsxs(le.div,{variants:pt,className:"overflow-hidden rounded-lg border border-amber-300/15 bg-amber-500/[0.06]",children:[e.jsxs("button",{type:"button",onClick:()=>C(y=>!y),className:"flex w-full items-center justify-between px-3 py-2 text-left transition-colors hover:bg-white/[0.03]",children:[e.jsxs("span",{className:"text-[11px] text-amber-100/85",children:[ue.length," data source",ue.length>1?"s":""," unavailable"]}),e.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",className:`text-amber-100/55 transition-transform ${p?"rotate-180":""}`,children:e.jsx("path",{d:"m6 9 6 6 6-6"})})]}),e.jsx(Le,{children:p&&e.jsx(le.div,{initial:{height:0,opacity:0},animate:{height:"auto",opacity:1},exit:{height:0,opacity:0},transition:{duration:.15},className:"overflow-hidden",children:e.jsx("div",{className:"px-3 pb-2 space-y-1",children:ue.map((y,re)=>e.jsx("div",{className:"text-[10px] text-amber-100/72",children:yn(y)},re))})})})]}),(ze>0||pe>0||_e>0||Se>0)&&e.jsx(le.div,{variants:pt,children:e.jsx(ft,{title:"Stats",storageKey:`stats.${t.id}`,defaultOpen:!0,children:e.jsxs("div",{className:"grid gap-2 py-0.5 sm:grid-cols-2 lg:grid-cols-4",children:[e.jsx(gt,{label:"Queue",value:`${ze} todo · ${pe} active`}),e.jsx(gt,{label:"Completed",value:`${Oe}/${be.length||0}`}),e.jsx(gt,{label:"Duration",value:`${_e}h`}),e.jsx(gt,{label:"Budget",value:`$${Se.toLocaleString()}`})]})})}),g&&e.jsxs("div",{className:"subsection-shell flex items-center justify-between rounded-lg px-3 py-2 text-[11px] text-[#D8FFA1]",children:[e.jsxs("span",{children:["Focused on workstream ",((de=Be.get(g))==null?void 0:de.title)??g]}),e.jsx("button",{type:"button",onClick:()=>b(null),className:"text-[10px] underline underline-offset-2",children:"Clear focus"})]}),e.jsx(le.div,{variants:pt,children:e.jsx(ft,{title:"Dependency Map",storageKey:`depmap.${t.id}`,defaultOpen:!0,children:e.jsx(Xs,{nodes:G,edges:Z,selectedNodeId:m,focusedWorkstreamId:g,onSelectNode:y=>{l(y);const re=Be.get(y);(re==null?void 0:re.type)==="workstream"&&b(re.id)}})})}),Me&&e.jsx(le.div,{variants:pt,children:e.jsx(ft,{title:"Next Up",storageKey:`nextup.${t.id}`,defaultOpen:!0,children:e.jsx(cn,{recentTodoIds:A,nodesById:Be,selectedNodeId:m,onSelectNode:y=>{l(y);const re=Be.get(y);(re==null?void 0:re.type)==="workstream"&&b(re.id)}})})}),e.jsx(le.div,{variants:pt,children:e.jsx(ft,{title:"Hierarchy",storageKey:`hierarchy.${t.id}`,defaultOpen:!0,sticky:!u,stickyTop:"calc(var(--mc-toolbar-offset, 88px) + var(--mc-initiative-header-offset, 52px))",children:e.jsx(on,{nodes:G,edges:Z,selectedNodeId:m,highlightedNodeIds:Ye,editMode:M,onSelectNode:l,onFocusWorkstream:b,onOpenNode:D,onUpdateNode:P,onToggleEditMode:()=>_(y=>!y),mutations:d})})})]}),e.jsxs("button",{type:"button",onClick:()=>h(t.id),className:"flex w-full items-center justify-center gap-1.5 py-1.5 text-[10px] text-white/35 transition-colors hover:text-white/65",children:[e.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:e.jsx("path",{d:"m18 15-6-6-6 6"})}),"Collapse"]})]})})})]})}const vn={hidden:{opacity:0},show:{opacity:1,transition:{staggerChildren:.045,delayChildren:.02}}},kn={hidden:{opacity:0,y:10,scale:.995},show:{opacity:1,y:0,scale:1,transition:{type:"spring",stiffness:320,damping:28,mass:.7}}};function rs({initiatives:t,selectedInitiativeIds:s,onToggleInitiativeSelection:i,runtimeActivityByInitiativeId:x}){return e.jsx(le.div,{variants:vn,initial:"hidden",animate:"show",className:"space-y-2",children:t.map(o=>e.jsx(le.div,{variants:kn,layout:!0,transition:{type:"spring",stiffness:280,damping:32,mass:.75},children:e.jsx(jn,{initiative:o,selected:(s==null?void 0:s.has(o.id))??!1,onSelectionChange:i,runtimeActivity:(x==null?void 0:x.get(o.id))??null})},o.id))})}function Nn(){return e.jsx("div",{className:"flex-1 flex items-center justify-center p-12",children:e.jsx(Ts,{className:"max-w-sm p-8",children:e.jsxs("div",{className:"flex flex-col items-center text-center gap-4",children:[e.jsx("div",{className:"relative flex items-center justify-center h-16 w-16 rounded-2xl",style:{backgroundColor:`${O.iris}1a`,border:`1px solid ${O.iris}33`},children:e.jsxs("svg",{width:"28",height:"28",viewBox:"0 0 24 24",fill:"none",stroke:O.iris,strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("circle",{cx:"12",cy:"12",r:"10"}),e.jsx("path",{d:"M12 6v6l4 2"})]})}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("h3",{className:"text-[14px] font-semibold text-white",children:"No initiatives yet"}),e.jsx("p",{className:"text-[12px] text-white/50 leading-relaxed",children:"Create initiatives in OrgX to see them here. Mission Control shows your full initiative hierarchy with workstreams, milestones, and tasks."})]})]})})})}function V({label:t,icon:s,color:i="#BFFF00",variant:x="secondary",size:o="md",className:h="",type:r="button",...j}){const w=o==="sm"?"px-2.5 py-1 text-[10px]":"px-3 py-1.5 text-[11px]",F=x==="primary"?{backgroundColor:i,color:"#05060A",borderColor:`${i}CC`}:x==="destructive"?{backgroundColor:`${i}18`,color:i,borderColor:`${i}45`}:x==="ghost"?{backgroundColor:"rgba(255,255,255,0.03)",color:"rgba(255,255,255,0.75)",borderColor:"rgba(255,255,255,0.12)"}:{backgroundColor:`${i}20`,color:i,borderColor:`${i}30`};return e.jsxs("button",{type:r,className:`inline-flex items-center gap-1.5 rounded-lg border transition-colors disabled:cursor-not-allowed disabled:opacity-50 ${w} ${h}`,style:F,...j,children:[s,t&&e.jsx("span",{children:t})]})}function Cn({initiative:t}){const{agentEntityMap:s,openModal:i,closeModal:x,authToken:o,embedMode:h,mutations:r}=tt(),j=s.get(t.id)??[],[w,F]=n.useState(!1),[d,M]=n.useState(""),[_,m]=n.useState(!1),[l,g]=n.useState(!1),[b,p]=n.useState(null),[C,u]=n.useState(t.name),[v,B]=n.useState(t.description??""),[W,X]=n.useState(xt(t.priority)),[K,U]=n.useState(Pt(t.targetDate)),[T,Q]=n.useState(null),{details:k,isLoading:z}=Nt({initiativeId:t.id,authToken:o,embedMode:h}),q=k.tasks.filter(A=>["active","in_progress"].includes(A.status.toLowerCase())).length,ne=k.tasks.filter(A=>A.status.toLowerCase()==="blocked").length,L=k.tasks.filter(A=>Ae(A.status)).length,Y=T??t.status,oe=Sn(T??t.rawStatus??t.status),c=["active","in_progress","running","queued"].includes(oe),te=["paused","draft","planned","todo","backlog","pending","not_started"].includes(oe),J=r.entityAction.isPending||r.createEntity.isPending||r.updateEntity.isPending||r.deleteEntity.isPending;n.useEffect(()=>{_||(u(t.name),B(t.description??""),U(Pt(t.targetDate)),X(xt(t.priority)))},[_,t.description,t.name,t.priority,t.targetDate]),n.useEffect(()=>{Q(null),g(!1)},[t.id,t.status,t.rawStatus]);const G=(A,se,ge)=>{p(null),r.entityAction.mutate({type:"initiative",id:t.id,action:A},{onSuccess:()=>{Q(se),p(ge)},onError:ye=>{p(ye instanceof Error?ye.message:`Failed to ${A} initiative.`)}})},Z=()=>{const A=C.trim();if(!A){p("Initiative title is required.");return}p(null),r.updateEntity.mutate({type:"initiative",id:t.id,title:A,summary:v.trim()||null,priority:W,target_date:K||null},{onSuccess:()=>{m(!1),p("Initiative updated.")},onError:se=>{p(se instanceof Error?se.message:"Failed to update initiative.")}})};return e.jsxs("div",{className:"flex h-full w-full min-h-0 flex-col",children:[e.jsxs("div",{className:"min-h-0 flex-1 space-y-5 overflow-y-auto p-6",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(Pe,{type:"initiative",size:16}),e.jsx("h2",{className:"text-[16px] font-semibold text-white",children:t.name}),e.jsx("span",{className:`text-[10px] px-2.5 py-0.5 rounded-full border uppercase tracking-[0.08em] ${jt[Y]??jt.active}`,children:Ne(Y)}),e.jsx("span",{className:"rounded-full border border-white/[0.14] bg-white/[0.04] px-2 py-0.5 text-[10px] uppercase tracking-[0.08em] text-white/68",children:Fn(t.priority)})]}),_?e.jsxs("div",{className:"space-y-2 rounded-xl border border-white/[0.08] bg-white/[0.02] p-3",children:[e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-[10px] uppercase tracking-[0.08em] text-white/35",children:"Title"}),e.jsx("input",{type:"text",value:C,onChange:A=>u(A.target.value),className:"mt-1 w-full rounded-lg border border-white/15 bg-white/[0.06] px-3 py-2 text-[12px] text-white/90 outline-none focus:border-white/30"})]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-[10px] uppercase tracking-[0.08em] text-white/35",children:"Summary"}),e.jsx("textarea",{value:v,onChange:A=>B(A.target.value),rows:3,className:"mt-1 w-full resize-y rounded-lg border border-white/15 bg-white/[0.06] px-3 py-2 text-[12px] text-white/90 outline-none focus:border-white/30"})]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-[10px] uppercase tracking-[0.08em] text-white/35",children:"Target date"}),e.jsx("input",{type:"date",value:K,onChange:A=>U(A.target.value),className:"mt-1 w-full rounded-lg border border-white/15 bg-white/[0.06] px-3 py-2 text-[12px] text-white/90 outline-none focus:border-white/30"})]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-[10px] uppercase tracking-[0.08em] text-white/35",children:"Priority"}),e.jsxs("select",{value:W,onChange:A=>X(xt(A.target.value)),className:"mt-1 w-full rounded-lg border border-white/15 bg-white/[0.06] px-3 py-2 text-[12px] text-white/90 outline-none focus:border-white/30",children:[e.jsx("option",{value:"critical",children:"Critical (P0)"}),e.jsx("option",{value:"high",children:"High (P1)"}),e.jsx("option",{value:"medium",children:"Medium (P2)"}),e.jsx("option",{value:"low",children:"Low (P3)"})]})]})]}):t.description?e.jsx("p",{className:"text-[13px] text-white/50 leading-relaxed",children:t.description}):e.jsx("p",{className:"text-[12px] text-white/35",children:"No summary yet."}),j.length>0&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-[10px] text-white/30 uppercase tracking-wider",children:"Agents"}),e.jsx(Ct,{agents:j,max:6})]}),b&&e.jsx("div",{className:"text-[11px] text-white/55",children:b})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3 sm:grid-cols-4",children:[e.jsx(bt,{label:"Workstreams",value:`${k.workstreams.length}`}),e.jsx(bt,{label:"Milestones",value:`${k.milestones.length}`}),e.jsx(bt,{label:"Active Tasks",value:`${q}`,accent:q>0?O.lime:void 0}),e.jsx(bt,{label:"Blocked",value:`${ne}`,accent:ne>0?O.red:void 0})]}),z?e.jsx("div",{className:"space-y-2",children:Array.from({length:3}).map((A,se)=>e.jsx(ht,{className:"h-14 w-full rounded-lg"},`init-detail-${se}`))}):e.jsxs(e.Fragment,{children:[k.workstreams.length>0&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(is,{title:"Workstreams",count:k.workstreams.length}),k.workstreams.map(A=>{const se=k.tasks.filter(ue=>ue.workstreamId===A.id),ge=se.filter(ue=>Ae(ue.status)).length,ye=se.length>0?et(ge,se.length):typeof A.progress=="number"?St(A.progress<=1?A.progress*100:A.progress):Ae(A.status)?100:null;return e.jsxs("button",{onClick:()=>i({type:"workstream",entity:A,initiative:t}),className:"w-full text-left rounded-xl border border-white/[0.08] bg-white/[0.03] p-3.5 transition-colors hover:bg-white/[0.06]",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("span",{className:"text-[12px] text-white/90 break-words",children:A.name}),e.jsx("span",{className:`text-[9px] px-1.5 py-0.5 rounded-full border uppercase tracking-[0.08em] ${ws(A.status)}`,children:Ne(A.status)})]}),e.jsxs("div",{className:"mt-1.5 flex items-center gap-3 text-[10px] text-white/35 uppercase tracking-[0.08em]",children:[e.jsxs("span",{children:[se.length," tasks"]}),ye!==null&&e.jsxs("span",{children:[ye,"%"]})]})]},A.id)})]}),k.milestones.length>0&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(is,{title:"Milestones",count:k.milestones.length}),k.milestones.map(A=>e.jsxs("button",{onClick:()=>i({type:"milestone",entity:A,initiative:t}),className:"w-full text-left rounded-xl border border-white/[0.08] bg-white/[0.03] p-3 transition-colors hover:bg-white/[0.06]",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-[12px] text-white/90 break-words",children:A.title}),e.jsx("span",{className:"text-[10px] text-white/40 uppercase tracking-[0.08em]",children:Ne(A.status)})]}),A.dueDate&&e.jsxs("span",{className:"text-[10px] text-white/30 mt-0.5 block",children:["Due: ",new Date(A.dueDate).toLocaleDateString()]})]},A.id))]}),e.jsxs("div",{className:"text-[10px] uppercase tracking-[0.08em] text-white/30 pt-2 border-t border-white/[0.06]",children:[k.tasks.length," total tasks · ",L," done"]})]})]}),e.jsx("div",{className:"border-t border-white/[0.06] bg-[#070b12]/85 px-6 py-3 backdrop-blur",children:e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[c&&e.jsx(V,{label:"Pause",color:O.amber,onClick:()=>G("pause","paused","Initiative paused."),disabled:J}),te&&e.jsx(V,{label:oe==="paused"?"Resume":"Start",color:O.lime,variant:"primary",onClick:()=>G("resume","active",oe==="paused"?"Initiative resumed.":"Initiative started."),disabled:J}),_?e.jsxs(e.Fragment,{children:[e.jsx(V,{label:"Save",color:O.teal,variant:"primary",onClick:Z,disabled:J||!C.trim()}),e.jsx(V,{label:"Cancel",variant:"ghost",onClick:()=>{m(!1),u(t.name),B(t.description??""),X(xt(t.priority)),U(Pt(t.targetDate)),p(null)},disabled:J})]}):e.jsx(V,{label:"Edit",variant:"ghost",onClick:()=>{m(!0),p(null)},disabled:J}),e.jsx("div",{className:"flex-1"}),l?e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-[11px] text-white/60",children:"Delete initiative?"}),e.jsx(V,{label:"Delete",color:O.red,variant:"destructive",onClick:()=>r.deleteEntity.mutate({type:"initiative",id:t.id},{onSuccess:()=>x(),onError:A=>p(A instanceof Error?A.message:"Failed to delete initiative.")}),disabled:J}),e.jsx(V,{label:"Keep",variant:"ghost",onClick:()=>g(!1),disabled:J})]}):e.jsx(V,{label:"Delete",color:O.red,variant:"destructive",onClick:()=>g(!0),disabled:J}),w?e.jsxs("form",{className:"flex flex-wrap items-center gap-2",onSubmit:A=>{A.preventDefault(),d.trim()&&r.createEntity.mutate({type:"workstream",title:d.trim(),initiative_id:t.id,status:"not_started"},{onSuccess:()=>{M(""),F(!1)}})},children:[e.jsx("input",{type:"text",value:d,onChange:A=>M(A.target.value),placeholder:"Workstream name...",autoFocus:!0,className:"text-[12px] bg-white/5 border border-white/10 rounded-lg px-2.5 py-1.5 text-white/80 placeholder-white/30 w-[180px] outline-none focus:border-white/25"}),e.jsx(V,{type:"submit",label:"Add",color:O.lime,disabled:!d.trim()||r.createEntity.isPending,size:"sm"}),e.jsx(V,{label:"Cancel",variant:"ghost",onClick:()=>{F(!1),M("")},size:"sm"})]}):e.jsx(V,{label:"+ Workstream",variant:"ghost",onClick:()=>F(!0),disabled:J})]})})]})}function Pt(t){if(!t)return"";const s=Date.parse(t);return Number.isFinite(s)?new Date(s).toISOString().slice(0,10):""}function Sn(t){return(t??"").trim().toLowerCase().replace(/[\s-]+/g,"_")}function xt(t){const s=(t??"").trim().toLowerCase();return s==="critical"||s==="p0"||s==="urgent"?"critical":s==="high"||s==="p1"?"high":s==="medium"||s==="normal"||s==="p2"?"medium":s==="low"||s==="p3"?"low":"medium"}function Fn(t){const s=xt(t);return s==="critical"?"Priority: Critical":s==="high"?"Priority: High":s==="low"?"Priority: Low":"Priority: Medium"}function bt({label:t,value:s,accent:i}){return e.jsxs("div",{className:"rounded-xl border border-white/[0.08] bg-white/[0.03] px-3 py-2.5",style:i?{borderTopColor:`${i}50`,borderTopWidth:2}:void 0,children:[e.jsx("div",{className:"text-[10px] uppercase tracking-[0.08em] text-white/35",children:t}),e.jsx("div",{className:"text-[15px] font-medium mt-0.5",style:{color:i??"rgba(255,255,255,0.8)"},children:s})]})}function is({title:t,count:s}){return e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-[11px] uppercase tracking-[0.08em] text-white/35",children:t}),e.jsx("span",{className:"text-[10px] text-white/30",children:s})]})}function Dn({workstream:t,initiative:s}){const{agentEntityMap:i,openModal:x,closeModal:o,authToken:h,embedMode:r,mutations:j}=tt(),w=i.get(t.id)??i.get(s.id)??[],[F,d]=n.useState(!1),[M,_]=n.useState(""),[m,l]=n.useState(!1),[g,b]=n.useState(!1),[p,C]=n.useState(null),[u,v]=n.useState(t.name),[B,W]=n.useState(t.summary??""),[X,K]=n.useState(t.status),{details:U,isLoading:T}=Nt({initiativeId:s.id,authToken:h,embedMode:r}),Q=n.useMemo(()=>U.milestones.filter(c=>c.workstreamId===t.id),[U.milestones,t.id]),k=n.useMemo(()=>new Set(Q.map(c=>c.id)),[Q]),z=n.useMemo(()=>U.tasks.filter(c=>c.workstreamId===t.id||c.milestoneId!==null&&k.has(c.milestoneId)).sort((c,te)=>{const J=vt(c.status)-vt(te.status);if(J!==0)return J;const G=c.createdAt?Date.parse(c.createdAt):0;return(te.createdAt?Date.parse(te.createdAt):0)-G}),[U.tasks,k,t.id]),q=z.filter(c=>Ae(c.status)).length,ne=z.length>0?et(q,z.length):typeof t.progress=="number"?St(t.progress<=1?t.progress*100:t.progress):Ae(t.status)?100:null,L=t.status.toLowerCase(),Y=j.entityAction.isPending||j.createEntity.isPending||j.updateEntity.isPending||j.deleteEntity.isPending,oe=()=>{const c=u.trim();if(!c){C("Workstream name is required.");return}C(null),j.updateEntity.mutate({type:"workstream",id:t.id,title:c,summary:B.trim()||null,status:X},{onSuccess:()=>{l(!1),C("Workstream updated.")},onError:te=>{C(te instanceof Error?te.message:"Failed to update workstream.")}})};return e.jsxs("div",{className:"flex h-full w-full min-h-0 flex-col",children:[e.jsxs("div",{className:"min-h-0 flex-1 space-y-5 overflow-y-auto p-6",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-[11px]",children:[e.jsx(Pe,{type:"initiative",size:12,className:"flex-shrink-0 opacity-80"}),e.jsx("button",{onClick:()=>x({type:"initiative",entity:s}),className:"break-words text-white/45 transition-colors hover:text-white",children:s.name}),e.jsx("svg",{width:"8",height:"8",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:"text-white/20",children:e.jsx("path",{d:"m9 18 6-6-6-6"})}),e.jsx(Pe,{type:"workstream",size:12,className:"flex-shrink-0 opacity-95"}),e.jsx("span",{className:"break-words font-medium text-white/70",children:t.name})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(Pe,{type:"workstream",size:16}),e.jsx("h2",{className:"text-[16px] font-semibold text-white",children:t.name}),e.jsx("span",{className:`text-[10px] px-2.5 py-0.5 rounded-full border uppercase tracking-[0.08em] ${ws(t.status)}`,children:Ne(t.status)})]}),m?e.jsxs("div",{className:"space-y-2 rounded-xl border border-white/[0.08] bg-white/[0.02] p-3",children:[e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-[10px] uppercase tracking-[0.08em] text-white/35",children:"Name"}),e.jsx("input",{type:"text",value:u,onChange:c=>v(c.target.value),className:"mt-1 w-full rounded-lg border border-white/15 bg-white/[0.06] px-3 py-2 text-[12px] text-white/90 outline-none focus:border-white/30"})]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-[10px] uppercase tracking-[0.08em] text-white/35",children:"Summary"}),e.jsx("textarea",{value:B,onChange:c=>W(c.target.value),rows:3,className:"mt-1 w-full resize-y rounded-lg border border-white/15 bg-white/[0.06] px-3 py-2 text-[12px] text-white/90 outline-none focus:border-white/30"})]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-[10px] uppercase tracking-[0.08em] text-white/35",children:"Status"}),e.jsx("select",{value:X,onChange:c=>K(c.target.value),className:"mt-1 w-full rounded-lg border border-white/15 bg-white/[0.06] px-3 py-2 text-[12px] text-white/90 outline-none focus:border-white/30",children:["not_started","planned","active","in_progress","paused","blocked","done"].map(c=>e.jsx("option",{value:c,children:Ne(c)},c))})]})]}):t.summary?e.jsx("p",{className:"text-[13px] text-white/50 leading-relaxed",children:t.summary}):e.jsx("p",{className:"text-[12px] text-white/35",children:"No summary yet."}),w.length>0&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-[10px] text-white/30 uppercase tracking-wider",children:"Agents"}),e.jsx(Ct,{agents:w,max:6})]}),p&&e.jsx("div",{className:"text-[11px] text-white/55",children:p})]}),ne!==null&&e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-1",children:[e.jsx("span",{className:"text-[10px] text-white/30 uppercase tracking-wider",children:"Progress"}),e.jsxs("span",{className:"text-[12px] text-white/60",children:[ne,"%"]})]}),e.jsx("div",{className:"h-1.5 w-full rounded-full bg-white/[0.06] overflow-hidden",children:e.jsx("div",{className:"h-full rounded-full transition-all",style:{width:`${ne}%`,backgroundColor:O.lime}})})]}),e.jsxs("div",{className:"grid grid-cols-1 gap-3 sm:grid-cols-3",children:[e.jsxs("div",{className:"rounded-xl border border-white/[0.08] bg-white/[0.03] px-3 py-2.5",children:[e.jsx("div",{className:"text-[10px] uppercase tracking-[0.08em] text-white/35",children:"Tasks"}),e.jsx("div",{className:"text-[15px] font-medium text-white/80 mt-0.5",children:z.length})]}),e.jsxs("div",{className:"rounded-xl border border-white/[0.08] bg-white/[0.03] px-3 py-2.5",children:[e.jsx("div",{className:"text-[10px] uppercase tracking-[0.08em] text-white/35",children:"Milestones"}),e.jsx("div",{className:"text-[15px] font-medium text-white/80 mt-0.5",children:Q.length})]}),e.jsxs("div",{className:"rounded-xl border border-white/[0.08] bg-white/[0.03] px-3 py-2.5",children:[e.jsx("div",{className:"text-[10px] uppercase tracking-[0.08em] text-white/35",children:"Progress"}),e.jsx("div",{className:"text-[15px] font-medium text-white/80 mt-0.5",children:ne!==null?`${ne}%`:"-"})]})]}),T?e.jsx("div",{className:"space-y-2",children:Array.from({length:3}).map((c,te)=>e.jsx(ht,{className:"h-12 w-full rounded-lg"},`ws-detail-${te}`))}):e.jsxs(e.Fragment,{children:[Q.length>0&&e.jsxs("div",{className:"space-y-2",children:[e.jsx("span",{className:"text-[11px] uppercase tracking-[0.08em] text-white/35",children:"Milestones"}),Q.map(c=>e.jsx("button",{onClick:()=>x({type:"milestone",entity:c,initiative:s}),className:"w-full text-left rounded-xl border border-white/[0.08] bg-white/[0.03] p-3 transition-colors hover:bg-white/[0.06]",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-[12px] text-white/90",children:c.title}),e.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded-full border uppercase tracking-[0.08em] ${ys(c.status)}`,children:Ne(c.status)})]})},c.id))]}),z.length>0&&e.jsxs("div",{className:"space-y-2",children:[e.jsxs("span",{className:"text-[11px] uppercase tracking-[0.08em] text-white/35",children:["Tasks (",z.length,")"]}),z.map(c=>e.jsxs("button",{onClick:()=>x({type:"task",entity:c,initiative:s}),className:"w-full text-left rounded-xl border border-white/[0.08] bg-white/[0.03] p-3 transition-colors hover:bg-white/[0.06]",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("span",{className:"text-[12px] text-white/90",children:c.title}),e.jsx("span",{className:`text-[9px] px-1.5 py-0.5 rounded-full border uppercase tracking-[0.08em] flex-shrink-0 ${qt(c.status)}`,children:Ne(c.status)})]}),c.priority&&e.jsxs("span",{className:"text-[10px] text-white/30 mt-0.5 block uppercase tracking-wider",children:["Priority: ",c.priority]})]},c.id))]})]})]}),e.jsx("div",{className:"border-t border-white/[0.06] bg-[#070b12]/85 px-6 py-3 backdrop-blur",children:e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[["not_started","planned","todo"].includes(L)&&e.jsx(V,{label:"Start",color:O.lime,variant:"primary",onClick:()=>j.entityAction.mutate({type:"workstream",id:t.id,action:"start"}),disabled:Y}),["active","in_progress"].includes(L)&&e.jsxs(e.Fragment,{children:[e.jsx(V,{label:"Complete",color:O.teal,variant:"primary",onClick:()=>j.entityAction.mutate({type:"workstream",id:t.id,action:"complete"}),disabled:Y}),e.jsx(V,{label:"Pause",color:O.amber,onClick:()=>j.entityAction.mutate({type:"workstream",id:t.id,action:"pause"}),disabled:Y}),e.jsx(V,{label:"Block",color:O.red,variant:"destructive",onClick:()=>j.entityAction.mutate({type:"workstream",id:t.id,action:"block"}),disabled:Y})]}),["paused","blocked"].includes(L)&&e.jsx(V,{label:"Resume",color:O.lime,variant:"primary",onClick:()=>j.entityAction.mutate({type:"workstream",id:t.id,action:"resume"}),disabled:Y}),m?e.jsxs(e.Fragment,{children:[e.jsx(V,{label:"Save",color:O.teal,variant:"primary",onClick:oe,disabled:Y||!u.trim()}),e.jsx(V,{label:"Cancel",variant:"ghost",onClick:()=>{l(!1),v(t.name),W(t.summary??""),K(t.status),C(null)},disabled:Y})]}):e.jsx(V,{label:"Edit",variant:"ghost",onClick:()=>{l(!0),C(null)},disabled:Y}),e.jsx("div",{className:"flex-1"}),g?e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-[11px] text-white/60",children:"Delete workstream?"}),e.jsx(V,{label:"Delete",color:O.red,variant:"destructive",onClick:()=>j.deleteEntity.mutate({type:"workstream",id:t.id},{onSuccess:()=>o(),onError:c=>C(c instanceof Error?c.message:"Failed to delete workstream.")}),disabled:Y}),e.jsx(V,{label:"Keep",variant:"ghost",onClick:()=>b(!1),disabled:Y})]}):e.jsx(V,{label:"Delete",color:O.red,variant:"destructive",onClick:()=>b(!0),disabled:Y}),F?e.jsxs("form",{className:"flex flex-wrap items-center gap-2",onSubmit:c=>{c.preventDefault(),M.trim()&&j.createEntity.mutate({type:"task",title:M.trim(),workstream_id:t.id,initiative_id:s.id,status:"todo"},{onSuccess:()=>{_(""),d(!1)},onError:te=>{C(te instanceof Error?te.message:"Failed to create task.")}})},children:[e.jsx("input",{type:"text",value:M,onChange:c=>_(c.target.value),placeholder:"Task title...",autoFocus:!0,className:"text-[12px] bg-white/5 border border-white/10 rounded-lg px-2.5 py-1.5 text-white/80 placeholder-white/30 w-[160px] outline-none focus:border-white/25"}),e.jsx(V,{label:"Add",color:O.lime,type:"submit",size:"sm",disabled:!M.trim()||j.createEntity.isPending}),e.jsx(V,{label:"Cancel",variant:"ghost",size:"sm",onClick:()=>{d(!1),_("")}})]}):e.jsx(V,{label:"+ Task",variant:"ghost",onClick:()=>d(!0),disabled:Y})]})})]})}function En({milestone:t,initiative:s}){const{openModal:i,closeModal:x,authToken:o,embedMode:h,mutations:r}=tt(),[j,w]=n.useState(!1),[F,d]=n.useState(!1),[M,_]=n.useState(!1),[m,l]=n.useState(""),[g,b]=n.useState(null),[p,C]=n.useState(t.title),[u,v]=n.useState(t.description??""),[B,W]=n.useState(ls(t.dueDate)),[X,K]=n.useState(t.status),{details:U}=Nt({initiativeId:s.id,authToken:o,embedMode:h}),T=U.tasks.filter(L=>L.milestoneId===t.id),Q=t.status.toLowerCase()==="done"||t.status.toLowerCase()==="completed",k=T.filter(L=>Ae(L.status)).length,z=T.length>0?et(k,T.length):Q?100:0,q=r.entityAction.isPending||r.createEntity.isPending||r.updateEntity.isPending||r.deleteEntity.isPending,ne=()=>{const L=p.trim();if(!L){b("Milestone title is required.");return}b(null),r.updateEntity.mutate({type:"milestone",id:t.id,title:L,description:u.trim()||null,due_date:B||null,status:X},{onSuccess:()=>{w(!1),b("Milestone updated.")},onError:Y=>{b(Y instanceof Error?Y.message:"Failed to update milestone.")}})};return e.jsxs("div",{className:"flex h-full w-full min-h-0 flex-col",children:[e.jsxs("div",{className:"min-h-0 flex-1 space-y-5 overflow-y-auto p-6",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-[11px]",children:[e.jsx(Pe,{type:"initiative",size:12,className:"flex-shrink-0 opacity-80"}),e.jsx("button",{onClick:()=>i({type:"initiative",entity:s}),className:"break-words text-white/45 transition-colors hover:text-white",children:s.name}),e.jsx("svg",{width:"8",height:"8",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:"text-white/20",children:e.jsx("path",{d:"m9 18 6-6-6-6"})}),e.jsx(Pe,{type:"milestone",size:12,className:"flex-shrink-0 opacity-95"}),e.jsx("span",{className:"break-words font-medium text-white/70",children:t.title})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(Pe,{type:"milestone",size:16}),e.jsx("h2",{className:"text-[16px] font-semibold text-white",children:t.title}),e.jsx("span",{className:`text-[10px] px-2.5 py-0.5 rounded-full border uppercase tracking-[0.08em] ${ys(t.status)}`,children:Ne(t.status)})]}),j?e.jsxs("div",{className:"space-y-2 rounded-xl border border-white/[0.08] bg-white/[0.02] p-3",children:[e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-[10px] uppercase tracking-[0.08em] text-white/35",children:"Title"}),e.jsx("input",{type:"text",value:p,onChange:L=>C(L.target.value),className:"mt-1 w-full rounded-lg border border-white/15 bg-white/[0.06] px-3 py-2 text-[12px] text-white/90 outline-none focus:border-white/30"})]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-[10px] uppercase tracking-[0.08em] text-white/35",children:"Description"}),e.jsx("textarea",{value:u,onChange:L=>v(L.target.value),rows:3,className:"mt-1 w-full resize-y rounded-lg border border-white/15 bg-white/[0.06] px-3 py-2 text-[12px] text-white/90 outline-none focus:border-white/30"})]}),e.jsxs("div",{className:"grid gap-2 sm:grid-cols-2",children:[e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-[10px] uppercase tracking-[0.08em] text-white/35",children:"Due date"}),e.jsx("input",{type:"date",value:B,onChange:L=>W(L.target.value),className:"mt-1 w-full rounded-lg border border-white/15 bg-white/[0.06] px-3 py-2 text-[12px] text-white/90 outline-none focus:border-white/30"})]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-[10px] uppercase tracking-[0.08em] text-white/35",children:"Status"}),e.jsx("select",{value:X,onChange:L=>K(L.target.value),className:"mt-1 w-full rounded-lg border border-white/15 bg-white/[0.06] px-3 py-2 text-[12px] text-white/90 outline-none focus:border-white/30",children:["planned","active","in_progress","at_risk","blocked","done"].map(L=>e.jsx("option",{value:L,children:Ne(L)},L))})]})]})]}):t.description?e.jsx("p",{className:"text-[13px] text-white/50 leading-relaxed",children:t.description}):e.jsx("p",{className:"text-[12px] text-white/35",children:"No description yet."}),g&&e.jsx("div",{className:"text-[11px] text-white/55",children:g})]}),e.jsxs("div",{className:"grid grid-cols-1 gap-3 sm:grid-cols-3",children:[t.dueDate&&e.jsxs("div",{className:"rounded-xl border border-white/[0.08] bg-white/[0.03] px-3 py-2.5",children:[e.jsx("div",{className:"text-[10px] uppercase tracking-[0.08em] text-white/35",children:"Due Date"}),e.jsx("div",{className:"text-[13px] text-white/80 mt-0.5",children:new Date(t.dueDate).toLocaleDateString()})]}),e.jsxs("div",{className:"rounded-xl border border-white/[0.08] bg-white/[0.03] px-3 py-2.5",children:[e.jsx("div",{className:"text-[10px] uppercase tracking-[0.08em] text-white/35",children:"Associated Tasks"}),e.jsx("div",{className:"text-[15px] font-medium text-white/80 mt-0.5",children:T.length})]}),e.jsxs("div",{className:"rounded-xl border border-white/[0.08] bg-white/[0.03] px-3 py-2.5",children:[e.jsx("div",{className:"text-[10px] uppercase tracking-[0.08em] text-white/35",children:"Completion"}),e.jsxs("div",{className:"mt-1 flex items-center gap-2",children:[e.jsx("div",{className:"h-1.5 flex-1 rounded-full bg-white/[0.06] overflow-hidden",children:e.jsx("div",{className:"h-full rounded-full transition-all",style:{width:`${z}%`,backgroundColor:O.teal}})}),e.jsxs("div",{className:"text-[12px] text-white/75",style:{fontVariantNumeric:"tabular-nums"},children:[z,"%"]})]}),e.jsxs("div",{className:"mt-1 text-[10px] text-white/35",children:[k,"/",T.length," done"]})]})]}),T.length>0&&e.jsxs("div",{className:"space-y-2",children:[e.jsx("span",{className:"text-[11px] uppercase tracking-[0.08em] text-white/35",children:"Tasks"}),T.map(L=>e.jsx("button",{onClick:()=>i({type:"task",entity:L,initiative:s}),className:"w-full text-left rounded-xl border border-white/[0.08] bg-white/[0.03] p-3 transition-colors hover:bg-white/[0.06]",children:e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("span",{className:"text-[12px] text-white/90",children:L.title}),e.jsx("span",{className:`text-[9px] px-1.5 py-0.5 rounded-full border uppercase tracking-[0.08em] flex-shrink-0 ${qt(L.status)}`,children:Ne(L.status)})]})},L.id))]})]}),e.jsx("div",{className:"border-t border-white/[0.06] bg-[#070b12]/85 px-6 py-3 backdrop-blur",children:e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[!Q&&t.status.toLowerCase()==="planned"&&e.jsx(V,{label:"Start",color:O.lime,variant:"primary",onClick:()=>r.entityAction.mutate({type:"milestone",id:t.id,action:"start"}),disabled:q}),!Q&&(t.status.toLowerCase()==="in_progress"||t.status.toLowerCase()==="at_risk")&&e.jsx(V,{label:T.length>0&&!T.every(L=>Ae(L.status))?"Complete (force)":"Complete",color:O.teal,variant:"primary",onClick:()=>{const L=T.length===0||T.every(Y=>Ae(Y.status));r.entityAction.mutate({type:"milestone",id:t.id,action:"complete",force:!L})},disabled:q}),j?e.jsxs(e.Fragment,{children:[e.jsx(V,{label:"Save",color:O.teal,variant:"primary",onClick:ne,disabled:q||!p.trim()}),e.jsx(V,{label:"Cancel",variant:"ghost",onClick:()=>{w(!1),C(t.title),v(t.description??""),W(ls(t.dueDate)),K(t.status),b(null)},disabled:q})]}):e.jsx(V,{label:"Edit",variant:"ghost",onClick:()=>{w(!0),b(null)},disabled:q}),e.jsx("div",{className:"flex-1"}),F?e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-[11px] text-white/60",children:"Delete milestone?"}),e.jsx(V,{label:"Delete",color:O.red,variant:"destructive",onClick:()=>r.deleteEntity.mutate({type:"milestone",id:t.id},{onSuccess:()=>x(),onError:L=>b(L instanceof Error?L.message:"Failed to delete milestone.")}),disabled:q}),e.jsx(V,{label:"Keep",variant:"ghost",onClick:()=>d(!1),disabled:q})]}):e.jsx(V,{label:"Delete",color:O.red,variant:"destructive",onClick:()=>d(!0),disabled:q}),M?e.jsxs("form",{className:"flex flex-wrap items-center gap-2",onSubmit:L=>{L.preventDefault(),m.trim()&&r.createEntity.mutate({type:"task",title:m.trim(),milestone_id:t.id,workstream_id:t.workstreamId??void 0,initiative_id:s.id,status:"todo"},{onSuccess:()=>{l(""),_(!1)},onError:Y=>{b(Y instanceof Error?Y.message:"Failed to create task.")}})},children:[e.jsx("input",{type:"text",value:m,onChange:L=>l(L.target.value),placeholder:"Task title...",autoFocus:!0,className:"text-[12px] bg-white/5 border border-white/10 rounded-lg px-2.5 py-1.5 text-white/80 placeholder-white/30 w-[160px] outline-none focus:border-white/25"}),e.jsx(V,{label:"Add",color:O.lime,type:"submit",size:"sm",disabled:!m.trim()||r.createEntity.isPending}),e.jsx(V,{label:"Cancel",variant:"ghost",size:"sm",onClick:()=>{_(!1),l("")}})]}):e.jsx(V,{label:"+ Task",variant:"ghost",onClick:()=>_(!0),disabled:q})]})})]})}function ls(t){if(!t)return"";const s=Date.parse(t);return Number.isFinite(s)?new Date(s).toISOString().slice(0,10):""}function An({task:t,initiative:s}){const{agentEntityMap:i,openModal:x,mutations:o,closeModal:h}=tt(),r=i.get(t.id)??i.get(s.id)??[],[j,w]=n.useState(!1),[F,d]=n.useState(!1),[M,_]=n.useState(null),[m,l]=n.useState(t.title),[g,b]=n.useState(t.description??""),[p,C]=n.useState(t.priority??""),[u,v]=n.useState(os(t.dueDate)),[B,W]=n.useState(t.status),X=t.status.toLowerCase(),K=o.entityAction.isPending||o.updateEntity.isPending||o.deleteEntity.isPending,U=k=>{_(null),o.entityAction.mutate({type:"task",id:t.id,action:k},{onError:z=>{_(z instanceof Error?z.message:"Task action failed.")}})},T=()=>{const k=m.trim();if(!k){_("Task title is required.");return}_(null),o.updateEntity.mutate({type:"task",id:t.id,title:k,description:g.trim()||null,priority:p.trim()||null,due_date:u||null,status:B},{onSuccess:()=>{d(!1),_("Task updated.")},onError:z=>{_(z instanceof Error?z.message:"Failed to update task.")}})},Q=()=>{_(null),o.deleteEntity.mutate({type:"task",id:t.id},{onSuccess:()=>h(),onError:k=>{_(k instanceof Error?k.message:"Failed to delete task.")}})};return e.jsxs("div",{className:"flex h-full w-full min-h-0 flex-col",children:[e.jsxs("div",{className:"min-h-0 flex-1 space-y-5 overflow-y-auto p-6",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-[11px]",children:[e.jsx(Pe,{type:"initiative",size:12,className:"flex-shrink-0 opacity-80"}),e.jsx("button",{onClick:()=>x({type:"initiative",entity:s}),className:"break-words text-white/45 transition-colors hover:text-white",children:s.name}),e.jsx("svg",{width:"8",height:"8",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:"text-white/20",children:e.jsx("path",{d:"m9 18 6-6-6-6"})}),e.jsx(Pe,{type:"task",size:12,className:"flex-shrink-0 opacity-95"}),e.jsx("span",{className:"break-words font-medium text-white/70",children:t.title})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[e.jsx(Pe,{type:"task",size:16}),e.jsx("h2",{className:"break-words text-[16px] font-semibold text-white",children:t.title}),e.jsx("span",{className:`text-[10px] px-2.5 py-0.5 rounded-full border uppercase tracking-[0.08em] ${qt(t.status)}`,children:Ne(t.status)})]}),F?e.jsxs("div",{className:"space-y-2 rounded-xl border border-white/[0.08] bg-white/[0.02] p-3",children:[e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-[10px] uppercase tracking-[0.08em] text-white/35",children:"Title"}),e.jsx("input",{type:"text",value:m,onChange:k=>l(k.target.value),className:"mt-1 w-full rounded-lg border border-white/15 bg-white/[0.06] px-3 py-2 text-[12px] text-white/90 outline-none focus:border-white/30"})]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-[10px] uppercase tracking-[0.08em] text-white/35",children:"Description"}),e.jsx("textarea",{value:g,onChange:k=>b(k.target.value),rows:3,className:"mt-1 w-full resize-y rounded-lg border border-white/15 bg-white/[0.06] px-3 py-2 text-[12px] text-white/90 outline-none focus:border-white/30"})]}),e.jsxs("div",{className:"grid gap-2 sm:grid-cols-3",children:[e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-[10px] uppercase tracking-[0.08em] text-white/35",children:"Priority"}),e.jsx("input",{type:"text",value:p,onChange:k=>C(k.target.value),placeholder:"p1, high, p50",className:"mt-1 w-full rounded-lg border border-white/15 bg-white/[0.06] px-3 py-2 text-[12px] text-white/90 outline-none focus:border-white/30"})]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-[10px] uppercase tracking-[0.08em] text-white/35",children:"Due date"}),e.jsx("input",{type:"date",value:u,onChange:k=>v(k.target.value),className:"mt-1 w-full rounded-lg border border-white/15 bg-white/[0.06] px-3 py-2 text-[12px] text-white/90 outline-none focus:border-white/30"})]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-[10px] uppercase tracking-[0.08em] text-white/35",children:"Status"}),e.jsx("select",{value:B,onChange:k=>W(k.target.value),className:"mt-1 w-full rounded-lg border border-white/15 bg-white/[0.06] px-3 py-2 text-[12px] text-white/90 outline-none focus:border-white/30",children:["not_started","planned","todo","in_progress","active","blocked","done"].map(k=>e.jsx("option",{value:k,children:Ne(k)},k))})]})]})]}):t.description?e.jsx(Ls,{text:t.description,mode:"block",className:"text-[13px] text-white/50 leading-relaxed"}):e.jsx("p",{className:"text-[12px] text-white/35",children:"No description yet."}),r.length>0&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-[10px] text-white/30 uppercase tracking-wider",children:"Agents"}),e.jsx(Ct,{agents:r,max:4})]})]}),e.jsxs("div",{className:"grid grid-cols-1 gap-3 sm:grid-cols-3",children:[e.jsxs("div",{className:"rounded-xl border border-white/[0.08] bg-white/[0.03] px-3 py-2.5",children:[e.jsx("div",{className:"text-[10px] uppercase tracking-[0.08em] text-white/35",children:"Status"}),e.jsx("div",{className:"text-[13px] text-white/80 mt-0.5",children:Ne(t.status)})]}),e.jsxs("div",{className:"rounded-xl border border-white/[0.08] bg-white/[0.03] px-3 py-2.5",children:[e.jsx("div",{className:"text-[10px] uppercase tracking-[0.08em] text-white/35",children:"Priority"}),e.jsx("div",{className:"text-[13px] text-white/80 mt-0.5",children:t.priority??"-"})]}),e.jsxs("div",{className:"rounded-xl border border-white/[0.08] bg-white/[0.03] px-3 py-2.5",children:[e.jsx("div",{className:"text-[10px] uppercase tracking-[0.08em] text-white/35",children:"Due Date"}),e.jsx("div",{className:"text-[13px] text-white/80 mt-0.5",children:t.dueDate?new Date(t.dueDate).toLocaleDateString():"-"})]})]}),M&&e.jsx("div",{className:"text-[11px] px-1",style:{color:`${O.red}b3`},children:M})]}),e.jsx("div",{className:"border-t border-white/[0.06] bg-[#070b12]/85 px-6 py-3 backdrop-blur",children:e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[X==="todo"&&e.jsx(V,{label:"Start",color:O.lime,variant:"primary",onClick:()=>U("start"),disabled:K}),(X==="in_progress"||X==="active")&&e.jsx(V,{label:"Complete",color:O.teal,variant:"primary",onClick:()=>U("complete"),disabled:K}),(X==="todo"||X==="in_progress"||X==="active")&&e.jsx(V,{label:"Block",color:O.red,variant:"destructive",onClick:()=>U("block"),disabled:K}),X==="blocked"&&e.jsx(V,{label:"Unblock",color:O.amber,onClick:()=>U("unblock"),disabled:K}),F?e.jsxs(e.Fragment,{children:[e.jsx(V,{label:"Save",color:O.teal,variant:"primary",onClick:T,disabled:K||!m.trim()}),e.jsx(V,{label:"Cancel",variant:"ghost",onClick:()=>{d(!1),_(null),l(t.title),b(t.description??""),C(t.priority??""),v(os(t.dueDate)),W(t.status)},disabled:K})]}):e.jsx(V,{label:"Edit",variant:"ghost",onClick:()=>{d(!0),_(null)},disabled:K}),e.jsx("div",{className:"flex-1"}),j?e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-[11px]",style:{color:`${O.red}b3`},children:"Delete?"}),e.jsx(V,{label:"Delete",color:O.red,variant:"destructive",onClick:Q,disabled:K}),e.jsx(V,{label:"Keep",variant:"ghost",onClick:()=>w(!1),disabled:K})]}):e.jsx(V,{label:"Delete",color:O.red,variant:"destructive",onClick:()=>w(!0),disabled:K})]})})]})}function os(t){if(!t)return"";const s=Date.parse(t);return Number.isFinite(s)?new Date(s).toISOString().slice(0,10):""}function Bn(t){const s=[];return t.type!=="initiative"&&t.initiative&&s.push(t.initiative.name),t.type==="initiative"||t.type==="workstream"?s.push(t.entity.name):(t.type==="milestone"||t.type==="task")&&s.push(t.entity.title),s}function Mn({target:t,onClose:s}){return e.jsx(Ps,{open:t!==null,onClose:s,maxWidth:"max-w-5xl",children:t&&e.jsxs("div",{className:"flex h-full w-full min-h-0 flex-col",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 border-b border-white/[0.06] px-5 py-3 sm:px-6",children:[e.jsxs("div",{className:"flex items-center gap-1.5 min-w-0 text-[12px] text-white/50",children:[Bn(t).map((i,x,o)=>e.jsxs("span",{className:"flex items-center gap-1.5 min-w-0",children:[x>0&&e.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",className:"flex-shrink-0 text-white/25",children:e.jsx("path",{d:"m9 18 6-6-6-6"})}),e.jsx("span",{className:`truncate ${x===o.length-1?"text-white/80 font-medium":""}`,children:i})]},x)),e.jsxs("span",{className:"ml-1 inline-flex items-center gap-1 rounded-full border border-white/[0.1] bg-white/[0.04] px-2 py-0.5 text-[10px] uppercase tracking-[0.06em] text-white/52",children:[e.jsx(Pe,{type:t.type,size:11,className:"opacity-90"}),t.type]})]}),e.jsx("button",{type:"button",onClick:s,"aria-label":"Close detail",className:"inline-flex h-9 w-9 flex-shrink-0 items-center justify-center rounded-full border border-white/[0.12] bg-white/[0.03] text-white/70 transition-colors hover:bg-white/[0.08] hover:text-white",children:e.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M18 6L6 18"}),e.jsx("path",{d:"M6 6l12 12"})]})})]}),e.jsxs("div",{className:"flex-1 min-h-0 overflow-y-auto",children:[t.type==="initiative"&&e.jsx(Cn,{initiative:t.entity}),t.type==="workstream"&&e.jsx(Dn,{workstream:t.entity,initiative:t.initiative}),t.type==="milestone"&&e.jsx(En,{milestone:t.entity,initiative:t.initiative}),t.type==="task"&&e.jsx(An,{task:t.entity,initiative:t.initiative})]})]})})}function cs(t){return(t??"").trim().toLowerCase().replace(/[\s-]+/g,"_")}function In(t){return t.split("_").map(s=>s.slice(0,1).toUpperCase()+s.slice(1)).join(" ")}const Rt=["active","in_progress","not_started","planned","blocked","at_risk","paused","completed","done","backlog","todo","pending","draft"],$n=[{value:"target",label:"Target date"},{value:"created",label:"Created at"},{value:"updated",label:"Updated at"}],_n=[{value:"any",label:"Any time"},{value:"missing",label:"No target date"},{value:"overdue",label:"Overdue"},{value:"today",label:"Today"},{value:"next_7_days",label:"Next 7 days"},{value:"next_30_days",label:"Next 30 days"},{value:"custom_range",label:"Custom range"}],Tn=[{value:"any",label:"Any time"},{value:"missing",label:"No timestamp"},{value:"today",label:"Today"},{value:"past_7_days",label:"Past 7 days"},{value:"past_30_days",label:"Past 30 days"},{value:"custom_range",label:"Custom range"}];function Ln({initiatives:t,visibleCount:s}){const{statusFilters:i,dateField:x,datePreset:o,dateStart:h,dateEnd:r,activeFilterCount:j,groupBy:w,setGroupBy:F,sortBy:d,setSortBy:M,setStatusFilters:_,toggleStatusFilter:m,setDateField:l,setDatePreset:g,setDateStart:b,setDateEnd:p,clearFilters:C}=tt(),[u,v]=n.useState(!1),[B,W]=n.useState(!1),X=n.useRef(null);n.useEffect(()=>{if(!u)return;const c=J=>{var Z;const G=J.target;G&&((Z=X.current)!=null&&Z.contains(G)||v(!1))},te=J=>{J.key==="Escape"&&v(!1)};return document.addEventListener("mousedown",c),document.addEventListener("keydown",te),()=>{document.removeEventListener("mousedown",c),document.removeEventListener("keydown",te)}},[u]);const K=n.useMemo(()=>{const c=new Map;for(const J of t){const G=new Set([cs(J.status),cs(J.rawStatus)]);for(const Z of G)Z&&c.set(Z,(c.get(Z)??0)+1)}for(const J of Rt)c.has(J)||c.set(J,0);return Array.from(c.entries()).sort((J,G)=>{const Z=Rt.indexOf(J[0]),A=Rt.indexOf(G[0]);return Z>=0&&A>=0?Z-A:Z>=0?-1:A>=0?1:J[0].localeCompare(G[0])}).map(([J,G])=>({key:J,count:G}))},[t]),U=i.length,T=n.useMemo(()=>K.filter(c=>B||c.count>0||i.includes(c.key)),[B,i,K]),Q=K.length-T.length,k=n.useMemo(()=>x==="target"?_n:Tn,[x]);n.useEffect(()=>{k.some(c=>c.value===o)||g("any")},[o,k,g]);const z=[{value:"none",label:"None"},{value:"status",label:"Status"},{value:"date",label:"Date"},{value:"category",label:"Category"}],q=[{value:"default",label:"Default"},{value:"date_asc",label:"Date (earliest)"},{value:"date_desc",label:"Date (latest)"},{value:"priority_high",label:"Priority (high first)"},{value:"priority_low",label:"Priority (low first)"}],ne=w!=="status"||d!=="default",L=j>0,Y=j,oe=L||ne;return e.jsxs("div",{ref:X,className:"relative flex items-center gap-2",children:[e.jsxs("button",{type:"button",onClick:()=>{v(c=>{const te=!c;return te||W(!1),te})},"data-state":u||Y>0?"active":"idle",className:"control-pill flex items-center gap-1.5 px-3 text-[11px] font-semibold",children:[e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:e.jsx("path",{d:"M22 3H2l8 9.46V19l4 2v-8.54L22 3z"})}),e.jsx("span",{children:"Filters"}),Y>0&&e.jsx("span",{className:"inline-flex min-w-[16px] items-center justify-center rounded-full border border-current/30 bg-black/25 px-1 text-[10px] leading-4",children:Y})]}),s<t.length&&e.jsxs("span",{className:"text-[10px] text-white/35 whitespace-nowrap",children:[s,"/",t.length]}),e.jsx(Le,{initial:!1,children:L&&e.jsx(le.button,{type:"button",onClick:C,initial:{opacity:0,x:-4},animate:{opacity:1,x:0},exit:{opacity:0,x:-4},transition:{duration:.15,ease:[.22,1,.36,1]},className:"text-[10px] text-white/40 transition-colors whitespace-nowrap hover:text-white/70",children:"Clear"})}),e.jsx(Le,{children:u&&e.jsxs(le.div,{initial:{opacity:0,y:-4,scale:.97},animate:{opacity:1,y:0,scale:1},exit:{opacity:0,y:-4,scale:.97},transition:{duration:.16,ease:[.22,1,.36,1]},className:"surface-tier-2 absolute right-0 top-12 z-30 w-[360px] max-w-[94vw] rounded-xl p-3.5 shadow-[0_16px_40px_rgba(0,0,0,0.45)] backdrop-blur-xl",children:[e.jsxs("div",{className:"mb-3 flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx("div",{className:"text-[11px] font-semibold tracking-[0.01em] text-white/85",children:"Filters"}),e.jsx("div",{className:"text-[10px] text-white/45",children:"Scope the Mission Control list view"})]}),L?e.jsxs("span",{className:"rounded-full border border-white/[0.12] bg-white/[0.04] px-2 py-0.5 text-[10px] text-white/70",children:[Y," active"]}):ne?e.jsx("span",{className:"rounded-full border border-white/[0.12] bg-white/[0.04] px-2 py-0.5 text-[10px] text-white/60",children:"view modified"}):null]}),e.jsxs("div",{className:"subsection-shell p-2.5",children:[e.jsx("div",{className:"section-kicker mb-2",children:"Layout"}),e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsxs("label",{className:"flex flex-col gap-1",children:[e.jsx("span",{className:"text-[10px] uppercase tracking-[0.08em] text-white/35",children:"Group"}),e.jsx("select",{value:w,onChange:c=>F(c.target.value),className:"h-9 rounded-lg border border-white/[0.08] bg-black/30 px-2 text-[11px] text-white/80 focus:border-[#BFFF00]/40 focus:outline-none",children:z.map(c=>e.jsx("option",{value:c.value,children:c.label},c.value))})]}),e.jsxs("label",{className:"flex flex-col gap-1",children:[e.jsx("span",{className:"text-[10px] uppercase tracking-[0.08em] text-white/35",children:"Sort"}),e.jsx("select",{value:d,onChange:c=>M(c.target.value),className:"h-9 rounded-lg border border-white/[0.08] bg-black/30 px-2 text-[11px] text-white/80 focus:border-[#BFFF00]/40 focus:outline-none",children:q.map(c=>e.jsx("option",{value:c.value,children:c.label},c.value))})]})]})]}),e.jsxs("div",{className:"mt-2.5 subsection-shell p-2.5",children:[e.jsxs("div",{className:"mb-2 flex items-center justify-between",children:[e.jsx("div",{className:"section-kicker",children:"Status"}),Q>0&&e.jsx("button",{type:"button",onClick:()=>W(c=>!c),className:"text-[10px] text-white/42 transition-colors hover:text-white/72",children:B?"Hide empty":`Show empty (${Q})`})]}),e.jsx("div",{className:"max-h-40 space-y-1 overflow-auto pr-1",children:T.map(c=>{const te=i.includes(c.key);return e.jsxs("label",{className:`flex cursor-pointer items-center justify-between rounded-md border px-2.5 py-1.5 text-[11px] transition-colors ${te?"border-[#BFFF00]/30 bg-[#BFFF00]/10 text-white/88":"border-white/[0.08] bg-white/[0.02] text-white/78 hover:border-white/[0.15]"}`,children:[e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"checkbox",checked:te,onChange:()=>m(c.key),className:"h-3.5 w-3.5 accent-[#BFFF00]"}),e.jsx("span",{children:In(c.key)})]}),e.jsx("span",{className:"text-[10px] text-white/48",children:c.count})]},c.key)})}),e.jsxs("div",{className:"mt-2 flex items-center justify-between",children:[e.jsx("button",{type:"button",onClick:()=>_([]),className:`text-[10px] uppercase tracking-[0.08em] ${U>0?"text-white/70 hover:text-white":"text-white/35"}`,disabled:U===0,children:"Clear status"}),e.jsxs("div",{className:"text-[10px] text-white/45",children:[U," selected"]})]})]}),e.jsxs("div",{className:"mt-2.5 subsection-shell p-2.5",children:[e.jsx("div",{className:"section-kicker mb-2",children:"Date"}),e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsxs("label",{className:"flex flex-col gap-1",children:[e.jsx("span",{className:"text-[10px] uppercase tracking-[0.08em] text-white/45",children:"Field"}),e.jsx("select",{value:x,onChange:c=>l(c.target.value),className:"h-9 rounded-lg border border-white/[0.12] bg-black/30 px-2 text-[11px] text-white focus:border-[#BFFF00]/40 focus:outline-none",children:$n.map(c=>e.jsx("option",{value:c.value,children:c.label},c.value))})]}),e.jsxs("label",{className:"flex flex-col gap-1",children:[e.jsx("span",{className:"text-[10px] uppercase tracking-[0.08em] text-white/45",children:"Condition"}),e.jsx("select",{value:o,onChange:c=>g(c.target.value),className:"h-9 rounded-lg border border-white/[0.12] bg-black/30 px-2 text-[11px] text-white focus:border-[#BFFF00]/40 focus:outline-none",children:k.map(c=>e.jsx("option",{value:c.value,children:c.label},c.value))})]})]}),o==="custom_range"&&e.jsxs("div",{className:"mt-2 grid grid-cols-2 gap-2",children:[e.jsxs("label",{className:"flex flex-col gap-1",children:[e.jsx("span",{className:"text-[10px] uppercase tracking-[0.08em] text-white/45",children:"Start"}),e.jsx("input",{type:"date",value:h,onChange:c=>b(c.target.value),className:"h-9 rounded-lg border border-white/[0.12] bg-black/30 px-2 text-[11px] text-white focus:border-[#BFFF00]/40 focus:outline-none"})]}),e.jsxs("label",{className:"flex flex-col gap-1",children:[e.jsx("span",{className:"text-[10px] uppercase tracking-[0.08em] text-white/45",children:"End"}),e.jsx("input",{type:"date",value:r,onChange:c=>p(c.target.value),className:"h-9 rounded-lg border border-white/[0.12] bg-black/30 px-2 text-[11px] text-white focus:border-[#BFFF00]/40 focus:outline-none"})]})]})]}),oe&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"mt-2 section-divider"}),e.jsxs("div",{className:"mt-2 flex flex-wrap justify-end gap-2",children:[ne&&e.jsx("button",{type:"button",onClick:()=>{F("status"),M("default")},className:"text-[10px] uppercase tracking-[0.09em] text-white/55 transition-colors hover:text-white/85",children:"Reset layout"}),L&&e.jsx("button",{type:"button",onClick:C,className:"text-[10px] uppercase tracking-[0.09em] text-white/55 transition-colors hover:text-white/85",children:"Clear filters"})]})]})]})})]})}function zt(t){return(t??"").trim().toLowerCase().replace(/[\s-]+/g,"_")}function Ot(t){return new Date(t.getFullYear(),t.getMonth(),t.getDate()).getTime()}function ds(t){if(!t)return null;const s=Date.parse(`${t}T00:00:00`);return Number.isFinite(s)?s:null}function Pn(t,s){return s==="target"?t.targetDate??null:s==="created"?t.createdAt??null:t.updatedAt??t.createdAt??null}function us(t){const s=(t??"").trim().toLowerCase();return s?s==="critical"||s==="p0"||s==="urgent"?0:s==="high"||s==="p1"?1:s==="medium"||s==="normal"||s==="p2"?2:s==="low"||s==="p3"?3:4:4}function ps(t){return t==="active"?0:t==="blocked"?1:t==="paused"?2:3}function xs(t,s){if(s==="status"){const i=new Map,x=["active","blocked","paused","completed"];for(const o of t){const h=o.status??"active",r=i.get(h)??[];r.push(o),i.set(h,r)}return x.filter(o=>i.has(o)).concat(Array.from(i.keys()).filter(o=>!x.includes(o))).map(o=>{var h;return{key:o,label:o.charAt(0).toUpperCase()+o.slice(1),count:((h=i.get(o))==null?void 0:h.length)??0,initiatives:i.get(o)??[]}})}if(s==="category"){const i=new Map;for(const x of t){const o=x.category??"Uncategorized",h=i.get(o)??[];h.push(x),i.set(o,h)}return Array.from(i.entries()).sort((x,o)=>x[0].localeCompare(o[0])).map(([x,o])=>({key:x,label:x,count:o.length,initiatives:o}))}if(s==="date"){const x=Ot(new Date),o=x+7*864e5,h=x+30*864e5,r={overdue:[],this_week:[],this_month:[],later:[],no_date:[]};for(const w of t){const F=w.targetDate?Date.parse(w.targetDate):null;F===null||!Number.isFinite(F)?r.no_date.push(w):F<x?r.overdue.push(w):F<o?r.this_week.push(w):F<h?r.this_month.push(w):r.later.push(w)}const j={overdue:"Overdue",this_week:"This Week",this_month:"This Month",later:"Later",no_date:"No Date"};return["overdue","this_week","this_month","later","no_date"].filter(w=>r[w].length>0).map(w=>({key:w,label:j[w],count:r[w].length,initiatives:r[w]}))}return[]}function ct(t,s){return`${t}:${s}`}function Rn(t){return`mc-group-${t}`.toLowerCase().replace(/[^a-z0-9_-]+/g,"-")}function hs(t,s){if(t.size!==s.size)return!1;for(const i of t)if(!s.has(i))return!1;return!0}function zn(t){return t==="running"?"Running":t==="blocked"?"Blocked":t==="queued"?"Queued":t==="startable"?"Startable":t==="completed"?"Complete":t==="active_no_queue"?"Idle":"No target"}function On(t){return t==="running"?"border-teal-300/35 bg-teal-400/[0.12] text-teal-100":t==="blocked"?"border-red-400/35 bg-red-500/[0.12] text-red-100":t==="queued"||t==="startable"?"border-[#BFFF00]/30 bg-[#BFFF00]/12 text-[#E1FFB2]":t==="completed"?"border-white/[0.16] bg-white/[0.05] text-white/60":"border-white/[0.16] bg-white/[0.05] text-white/68"}function Qn({initiatives:t,activities:s,agents:i,runtimeInstances:x=[],isLoading:o,authToken:h,embedMode:r,initialInitiativeId:j,connection:w,lastSnapshotAt:F,error:d,hasApiKey:M,onOpenSettings:_,onRefresh:m,onFollowWorkstream:l}){const g=qs({activities:s,agents:i,initiatives:t});return e.jsx(Ks,{agentEntityMap:g,authToken:h,embedMode:r,children:e.jsx(qn,{initiatives:t,runtimeInstances:x,isLoading:o,initialInitiativeId:j,connection:w,lastSnapshotAt:F,error:d,hasApiKey:M,onOpenSettings:_,onRefresh:m,onFollowWorkstream:l})})}function Un(t){if(!t)return"unknown";const s=Date.parse(t);if(!Number.isFinite(s))return"unknown";try{return new Date(s).toLocaleString()}catch{return"unknown"}}function qn({initiatives:t,runtimeInstances:s,isLoading:i,initialInitiativeId:x,connection:o,lastSnapshotAt:h,error:r,hasApiKey:j,onOpenSettings:w,onRefresh:F,onFollowWorkstream:d}){var Xt;const{searchQuery:M,setSearchQuery:_,statusFilters:m,setStatusFilters:l,dateField:g,setDateField:b,datePreset:p,setDatePreset:C,dateStart:u,setDateStart:v,dateEnd:B,setDateEnd:W,clearFilters:X,hasActiveFilters:K,groupBy:U,sortBy:T,expandedInitiatives:Q,expandAll:k,collapseAll:z,modalTarget:q,closeModal:ne,expandInitiative:L,authToken:Y,embedMode:oe,mutations:c}=tt(),te=n.useRef(!1),J=n.useRef(null),G=n.useRef(0),[Z,A]=n.useState(0),[se,ge]=n.useState(new Set),[ye,ue]=n.useState(!1),[Be,Ye]=n.useState(!1),[Me,Re]=n.useState(!1),[st,me]=n.useState(!1),[be,pe]=n.useState(null),[ze,Oe]=n.useState(new Set),[Ie,Ee]=n.useState(!1),[Ge,we]=n.useState(null),Ke=n.useMemo(()=>{const E=Ot(new Date),R=M.toLowerCase().trim().split(/\s+/).filter(Boolean);return t.filter(H=>{if(m.length>0&&![zt(H.status),zt(H.rawStatus)].filter(Boolean).some(Te=>m.includes(Te)))return!1;const ce=Pn(H,g),fe=ce?Date.parse(ce):Number.NaN,ke=Number.isFinite(fe)?Ot(new Date(fe)):null,ae=ke===null?null:Math.round((ke-E)/864e5);if(p==="missing"&&ke!==null||p==="overdue"&&!(ae!==null&&ae<0)||p==="today"&&ae!==0||p==="next_7_days"&&!(ae!==null&&ae>=0&&ae<=7)||p==="next_30_days"&&!(ae!==null&&ae>=0&&ae<=30)||p==="past_7_days"&&!(ae!==null&&ae<=0&&ae>=-7)||p==="past_30_days"&&!(ae!==null&&ae<=0&&ae>=-30))return!1;if(p==="custom_range"){const We=ds(u),Te=ds(B);if(ke===null||We!==null&&ke<We||Te!==null&&ke>Te)return!1}if(R.length===0)return!0;const lt=[H.name,H.description??"",H.status,H.rawStatus??"",H.category??""].join(" ").toLowerCase();return R.every(We=>lt.includes(We))})},[t,M,m,g,p,u,B]),ie=n.useMemo(()=>{const f=(E,R,H)=>{const ce=E.targetDate?Date.parse(E.targetDate):Number.NaN,fe=R.targetDate?Date.parse(R.targetDate):Number.NaN,ke=Number.isFinite(ce),ae=Number.isFinite(fe);return!ke&&!ae?0:ke?ae?H==="asc"?ce-fe:fe-ce:-1:1};return[...Ke].sort((E,R)=>{if(T==="date_asc")return f(E,R,"asc");if(T==="date_desc")return f(E,R,"desc");const H=us(E.priority),ce=us(R.priority);if(T==="priority_high"&&H!==ce)return H-ce;if(T==="priority_low"&&H!==ce)return ce-H;if(T==="default"){const ae=ps(E.status)-ps(R.status);if(ae!==0)return ae;if(H!==ce)return H-ce}const fe=E.updatedAt?Date.parse(E.updatedAt):0,ke=R.updatedAt?Date.parse(R.updatedAt):0;return fe!==ke?ke-fe:E.name.localeCompare(R.name)})},[Ke,T]),$e=n.useMemo(()=>new Set(ie.map(f=>f.id)),[ie]),_e=n.useMemo(()=>ie.filter(f=>ze.has(f.id)),[ze,ie]),Se=_e.length,a=ie.length>0&&Se===ie.length,N=c.bulkEntityMutation.isPending,S=n.useMemo(()=>{var R;const f=new Map;for(const H of s){const ce=(R=H.initiativeId)==null?void 0:R.trim();if(!ce)continue;const fe=f.get(ce)??{activeCount:0,totalCount:0,lastHeartbeatAt:null,lastHeartbeatMs:0};fe.totalCount+=1,H.state==="active"&&(fe.activeCount+=1);const ke=H.lastHeartbeatAt??H.lastEventAt??null,ae=ke?Date.parse(ke):Number.NaN;Number.isFinite(ae)&&ae>fe.lastHeartbeatMs&&(fe.lastHeartbeatMs=ae,fe.lastHeartbeatAt=new Date(ae).toISOString()),f.set(ce,fe)}const E=new Map;for(const[H,ce]of f.entries())E.set(H,{activeCount:ce.activeCount,totalCount:ce.totalCount,lastHeartbeatAt:ce.lastHeartbeatAt});return E},[s]),$=n.useMemo(()=>U!=="none"?xs(ie,U):null,[ie,U]),ee=n.useMemo(()=>($==null?void 0:$.map(f=>ct(U,f.key)))??[],[U,$]),je=n.useCallback(f=>{ge(E=>{const R=new Set(E);return R.has(f)?R.delete(f):R.add(f),R})},[]);n.useEffect(()=>{if(!$||$.length===0){ge(E=>E.size===0?E:new Set);return}const f=new Set($.map(E=>ct(U,E.key)));ge(E=>{const R=new Set(Array.from(E).filter(H=>f.has(H)));return R.size===0&&R.add(ct(U,$[0].key)),hs(R,E)?E:R})},[U,$]),n.useEffect(()=>{Oe(f=>{if(f.size===0)return f;const E=new Set(Array.from(f).filter(R=>$e.has(R)));return hs(E,f)?f:E})},[$e]),n.useEffect(()=>{if(x&&!te.current&&!i&&t.length>0){if(L(x),$){const f=$.find(E=>E.initiatives.some(R=>R.id===x));if(f){const E=ct(U,f.key);ge(R=>{if(R.has(E))return R;const H=new Set(R);return H.add(E),H})}}te.current=!0,requestAnimationFrame(()=>{const f=document.getElementById(`initiative-${x}`);f==null||f.scrollIntoView({behavior:"smooth",block:"start"})})}},[x,i,t.length,L,U,$]),n.useEffect(()=>{Se===0&&Ie&&Ee(!1)},[Ie,Se]);const xe=ie.length>0&&Q.size>=ie.length,Fe=n.useMemo(()=>ie.find(f=>f.status!=="completed")??ie[0]??null,[ie]),he=Rs({initiativeId:null,authToken:Y,embedMode:oe,enabled:t.length>0}),D=he.items[0]??null,P=n.useMemo(()=>D?t.find(f=>f.id===D.initiativeId)??Fe:Fe,[Fe,t,D]),I=(P==null?void 0:P.id)??null,de=n.useCallback((f,E)=>{we(null),Ee(!1),Oe(R=>{const H=new Set(R);return E?H.add(f):H.delete(f),H})},[]),y=n.useCallback(()=>{we(null),Ee(!1),Oe(f=>ie.length===0?f:a?new Set:new Set(ie.map(E=>E.id)))},[a,ie]),re=n.useCallback(()=>{Ee(!1),Oe(new Set)},[]),Ue=n.useCallback(async f=>{if(_e.length!==0){Ee(!1),we(null);try{const E=await c.bulkEntityMutation.mutateAsync({items:_e.map(R=>({type:"initiative",id:R.id})),mode:"update",updates:{status:f}});E.failed>0?we({tone:"error",message:`Updated ${E.updated}, failed ${E.failed}.`}):we({tone:"success",message:`Updated ${E.updated} initiative${E.updated===1?"":"s"} to ${f}.`})}catch(E){we({tone:"error",message:E instanceof Error?E.message:"Bulk initiative update failed."})}}},[c.bulkEntityMutation,_e]),qe=n.useCallback(async()=>{if(_e.length!==0){we(null);try{const f=await c.bulkEntityMutation.mutateAsync({items:_e.map(E=>({type:"initiative",id:E.id})),mode:"delete"});f.failed>0?we({tone:"error",message:`Deleted ${f.updated}, failed ${f.failed}.`}):(we({tone:"success",message:`Deleted ${f.updated} initiative${f.updated===1?"":"s"}.`}),Oe(new Set),Ee(!1))}catch(f){we({tone:"error",message:f instanceof Error?f.message:"Bulk initiative delete failed."})}}},[c.bulkEntityMutation,_e]),He=n.useCallback(()=>{G.current+=1,ue(!1)},[]),nt=n.useCallback(f=>{if(f.length===0){He();return}const E=1,R=G.current+1;G.current=R,ue(!0);const H=ce=>{if(G.current===R){if(k(f.slice(0,ce)),ce>=f.length){ue(!1);return}requestAnimationFrame(()=>H(Math.min(f.length,ce+E)))}};H(Math.min(E,f.length))},[He,k]),Ce=Ws({initiativeId:I,authToken:Y,embedMode:oe,enabled:!!I}),[Ve,Qe]=n.useState(null),dt=Ce.run,ut=((Xt=Ce.error)==null?void 0:Xt.toLowerCase())??"",at=!I||ut.includes("404")||ut.includes("400")||ut.includes("not found"),De=I?S.get(I)??null:null,Ft=((De==null?void 0:De.activeCount)??0)>0,js=((De==null?void 0:De.totalCount)??0)>0,Wt=Ve?`Upgrade required · ${es(Ve.currentPlan)} → ${es(Ve.requiredPlan)}`:I?Ce.isRunning?Ft?`Running · ${(De==null?void 0:De.activeCount)??0} live`:js?`Enabled · ${(De==null?void 0:De.totalCount)??0} idle`:"Enabled · waiting":dt!=null&&dt.stopReason?`Idle · ${dt.stopReason.replace(/_/g," ")}`:"Idle":"No target",rt=!!Ve&&!Ce.isRunning,vs=rt?"amber":"teal";n.useEffect(()=>{Qe(null)},[I]),n.useEffect(()=>{const f=J.current;if(!f)return;const E=()=>{A(Math.max(64,f.offsetHeight))};if(E(),typeof ResizeObserver>"u")return;const R=new ResizeObserver(()=>E());return R.observe(f),()=>R.disconnect()},[Wt,o,r,i,ie.length]);const Dt=!!(!i&&j&&(o==="disconnected"||r)),Ht=!!(o==="disconnected"||r);n.useEffect(()=>{if(!Dt){Ye(!1);return}Ht&&Ye(!0)},[Dt,Ht]);const Vt=o==="disconnected"||r?"critical":"info",ks=Vt==="critical"?"border-red-400/30 bg-red-500/14 text-red-100":"border-white/[0.14] bg-white/[0.08] text-white/75",Ns=o==="disconnected"?"Offline":r?"Live degraded":"Connected",Gt=r||(o==="disconnected"?"Data may be stale":`Last snapshot ${Un(h)}`),Je=n.useCallback((f,E)=>{if(!t.find(ae=>ae.id===f))return pe({tone:"error",message:E?`${E} is unavailable in the current initiative list.`:"Initiative is unavailable in the current initiative list."}),!1;pe(null);const H=$e.has(f),ce=!H;if(ce&&(_(""),l([]),b("target"),C("any"),v(""),W("")),L(f),U!=="none"){const We=xs(H?ie:t,U).find(Te=>Te.initiatives.some(ot=>ot.id===f));if(We){const Te=ct(U,We.key);ge(ot=>{if(ot.has(Te))return ot;const Zt=new Set(ot);return Zt.add(Te),Zt})}}const fe=(ae=0)=>{const lt=document.getElementById(`initiative-${f}`);if(lt){lt.scrollIntoView({behavior:ae===0?"smooth":"auto",block:"start"});const We=Math.max(72,Z)+8,Te=lt.getBoundingClientRect();!(Te.top>=We&&Te.top<=window.innerHeight-72)&&ae<18&&window.setTimeout(()=>fe(ae+1),90);return}ae>=60||requestAnimationFrame(()=>fe(ae+1))},ke=()=>requestAnimationFrame(()=>fe());return ce?window.setTimeout(ke,90):ke(),!0},[t,$e,pe,_,l,b,C,v,W,L,U,ie,Z]),Et=n.useCallback(f=>{d==null||d(f),me(!1)},[d]),Cs=n.useCallback(()=>{P&&(pe(null),c.updateEntity.mutateAsync({type:"initiative",id:P.id,status:"active"}).then(()=>{pe({tone:"success",message:`Started ${P.name}.`}),Je(P.id,P.name)}).catch(f=>{pe({tone:"error",message:f instanceof Error?f.message:"Failed to start initiative."})}))},[c.updateEntity,P,Je]),Kt=n.useCallback(()=>{if(!D){P&&Je(P.id,P.name);return}pe(null),he.playWorkstream({initiativeId:D.initiativeId,workstreamId:D.workstreamId,agentId:D.runnerAgentId}).then(()=>{pe({tone:"success",message:`Dispatched ${D.workstreamTitle}.`})}).catch(f=>{pe({tone:"error",message:f instanceof Error?f.message:"Failed to dispatch next workstream."})})},[he,D,P,Je]),Ss=n.useCallback(()=>{P&&(Je(P.id,P.name),typeof window<"u"&&window.innerWidth>=1280&&Re(!0))},[P,Je]),At=n.useCallback(()=>{if(typeof window<"u"&&window.innerWidth>=1280){me(!1),Re(f=>!f);return}me(!0)},[]),it=zt((P==null?void 0:P.rawStatus)??(P==null?void 0:P.status)??null),Qt=n.useMemo(()=>new Set(["paused","draft","planned","todo","backlog","queued"]),[]),ve=n.useMemo(()=>{var f;return P?(D==null?void 0:D.queueState)==="running"||((f=D==null?void 0:D.autoContinue)==null?void 0:f.status)==="running"?"running":(D==null?void 0:D.queueState)==="blocked"||P.status==="blocked"?"blocked":D?"queued":Qt.has(it)?"startable":it==="completed"||it==="done"?"completed":"active_no_queue":"none"},[P,D,Qt,it]),Bt=n.useMemo(()=>P?ve==="running"&&D?{headline:`${D.workstreamTitle} is running`,detail:`Runner: ${D.runnerAgentName}. Follow live updates in Activity.`}:ve==="queued"&&D?{headline:D.workstreamTitle,detail:`Ready to dispatch${D.nextTaskTitle?` · ${D.nextTaskTitle}`:""}.`}:ve==="startable"?{headline:it==="paused"?`${P.name} is paused`:`${P.name} is ready to start`,detail:"Start initiative to queue and dispatch the next workstream."}:ve==="blocked"?{headline:(D==null?void 0:D.queueState)==="blocked"?`${D.workstreamTitle} is blocked`:`${P.name} is blocked`,detail:(D==null?void 0:D.blockReason)??"Resolve blockers or approvals before dispatching more work."}:ve==="completed"?{headline:`${P.name} is complete`,detail:"Choose another active initiative or queue new workstreams."}:{headline:P.name,detail:"No queued workstream detected yet. Use Next Up to choose what runs next."}:{headline:"No initiative selected",detail:"Create or select an initiative to queue work."},[P,ve,D,it]),Mt=he.isPlaying||he.isStartingAutoContinue||he.isStoppingAutoContinue||c.updateEntity.isPending,Fs=n.useMemo(()=>ve==="blocked"?"Review blockers":ve==="active_no_queue"?"Open and queue work":ve==="completed"?"Review initiative":"Open initiative",[ve]),Jt=D?D.workstreamTitle:"No queued workstream",Ds=(D==null?void 0:D.initiativeTitle)??(P==null?void 0:P.name)??"No initiative selected",It=(D==null?void 0:D.nextTaskTitle)??Bt.detail,Es=zn(ve),As=On(ve),$t="next-up-surface",_t=n.useMemo(()=>({type:"spring",stiffness:340,damping:38,mass:.72}),[]),Bs=n.useMemo(()=>({backgroundColor:"rgba(18, 26, 39, 0.9)",borderColor:"rgba(191, 255, 0, 0.24)"}),[]),Yt=n.useMemo(()=>({backgroundColor:"rgba(10, 14, 21, 0.95)",borderColor:"rgba(255, 255, 255, 0.11)"}),[]),Ms=n.useMemo(()=>{if(!q)return null;const f=R=>t.find(H=>H.id===R)??null;if(q.type==="initiative"){const R=f(q.entity.id);return R?{...q,entity:R}:q}const E=f(q.initiative.id);return E?{...q,initiative:E}:q},[t,q]);return n.useEffect(()=>{pe(null)},[P==null?void 0:P.id,D==null?void 0:D.initiativeId,D==null?void 0:D.workstreamId]),n.useEffect(()=>{if(!q)return;const f=q.type==="initiative"?q.entity.id:q.initiative.id;t.some(R=>R.id===f)||ne()},[ne,t,q]),n.useEffect(()=>{if(typeof window>"u")return;const f=()=>{window.innerWidth>=1280?me(!1):Re(!1)};return f(),window.addEventListener("resize",f),()=>window.removeEventListener("resize",f)},[]),e.jsxs("div",{className:"flex-1 min-h-0 flex flex-col overflow-hidden",children:[e.jsxs("div",{className:"relative flex-1 min-h-0",children:[e.jsx("div",{className:"pointer-events-none absolute top-0 left-0 right-0 h-6 bg-gradient-to-b from-[#02040A] to-transparent z-10"}),e.jsx("div",{className:"pointer-events-none absolute bottom-0 left-0 right-0 h-12 bg-gradient-to-t from-[#02040A] to-transparent z-10"}),e.jsx("div",{"data-mc-scroll-host":"true",className:"h-full overflow-y-auto overflow-x-hidden",children:e.jsxs("div",{className:"mx-auto max-w-6xl px-4 sm:px-6",style:{"--mc-toolbar-offset":`${Z}px`},children:[e.jsxs(Us,{id:"next-up-morph",children:[e.jsxs("div",{ref:J,className:"sticky top-0 z-40 relative -mx-4 border-b border-white/[0.05] bg-[#02040A]/78 px-4 pb-2.5 pt-3.5 backdrop-blur-xl sm:-mx-6 sm:px-6",children:[e.jsx(Le,{initial:!1,children:Be&&Dt&&e.jsx(le.div,{initial:{opacity:0,y:-6,scale:.98},animate:{opacity:1,y:0,scale:1},exit:{opacity:0,y:-6,scale:.98},transition:{duration:.18,ease:[.22,1,.36,1]},className:"pointer-events-none absolute right-4 top-2.5 z-50 sm:right-6",children:e.jsxs("div",{className:`pointer-events-auto inline-flex max-w-[540px] items-center gap-2 rounded-full border px-2.5 py-1.5 shadow-[0_10px_24px_rgba(0,0,0,0.35)] ${ks}`,children:[e.jsx("span",{className:`h-1.5 w-1.5 rounded-full ${Vt==="critical"?"bg-red-300":"bg-white/70"}`}),e.jsx("span",{className:"text-[10px] font-semibold uppercase tracking-[0.08em]",children:Ns}),e.jsx("span",{className:"max-w-[280px] truncate text-[11px] opacity-85",title:Gt,children:Gt}),e.jsxs("div",{className:"flex items-center gap-1",children:[F&&e.jsx("button",{type:"button",onClick:F,className:"h-6 rounded-full border border-white/[0.16] bg-white/[0.08] px-2 text-[10px] font-semibold text-current transition-colors hover:bg-white/[0.15]",children:"Refresh"}),w&&e.jsx("button",{type:"button",onClick:w,className:"h-6 rounded-full border border-white/[0.16] bg-white/[0.08] px-2 text-[10px] font-semibold text-current transition-colors hover:bg-white/[0.15]",children:"Settings"})]})]})})}),e.jsxs("div",{className:"toolbar-shell flex flex-col gap-2.5 md:flex-row md:items-center",children:[e.jsx("div",{className:"min-w-0 flex-1",children:e.jsx(gs,{value:M,onChange:_,placeholder:"Search initiatives..."})}),e.jsxs("div",{className:"flex min-w-0 flex-wrap items-center gap-2.5 md:ml-auto md:flex-nowrap",children:[e.jsx(Ln,{initiatives:t,visibleCount:Ke.length}),e.jsxs("div",{className:"hidden min-w-[220px] max-w-[320px] items-center gap-2 rounded-lg border border-white/[0.12] bg-white/[0.03] px-2.5 py-1.5 xl:flex",title:(P==null?void 0:P.name)??void 0,children:[e.jsx("span",{className:"text-[10px] font-semibold uppercase tracking-[0.08em] text-white/44",children:"Autopilot"}),e.jsxs("div",{className:"min-w-0 flex-1 text-right",children:[e.jsx("div",{className:"truncate text-[10px] text-white/72",children:Wt}),P&&e.jsx("div",{className:"truncate text-[10px] text-white/44",children:P.name})]})]}),e.jsxs("button",{type:"button",onClick:()=>{if(at||!I)return;if(rt&&Ve){zs({actions:Ve.actions,requiredPlan:Ve.requiredPlan}).catch(E=>{});return}(Ce.isRunning?Ce.stop:Ce.start)().then(()=>Qe(null)).catch(E=>{E instanceof Os?Qe(E):Qe(null)})},disabled:at||Ce.isStarting||Ce.isStopping,title:at?"Select an initiative to run Autopilot":rt?"Upgrade to enable auto-continue for BYOK agents":Ce.isRunning?"Stop Autopilot":`Start Autopilot${P?` for ${P.name}`:""}`,"data-state":Ce.isRunning||rt?"active":"idle","data-tone":vs,className:"control-pill flex items-center gap-1.5 px-3 text-[11px] font-semibold disabled:opacity-40",children:[rt?e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M12 5v14"}),e.jsx("path",{d:"M18 11l-6-6-6 6"})]}):Ce.isRunning?Ft?e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"currentColor",className:"status-breathe",children:e.jsx("rect",{x:"7",y:"7",width:"10",height:"10",rx:"2"})}):e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[e.jsx("circle",{cx:"12",cy:"12",r:"8"}),e.jsx("path",{d:"M12 8v4l3 2"})]}):e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"currentColor",children:e.jsx("path",{d:"M8 5v14l11-7z"})}),e.jsx("span",{children:rt?"Upgrade Autopilot":`${Ce.isRunning?"Stop":"Start"} Autopilot`}),Ce.isRunning&&Ft&&e.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-[#0AD4C4] status-breathe"})]}),ie.length>0&&e.jsx("button",{type:"button",onClick:()=>{xe?(He(),z(),$&&ee.length>0&&ge(new Set)):(nt(ie.map(f=>f.id)),$&&ee.length>0&&ge(new Set(ee)))},title:xe?"Collapse all":"Expand all","aria-busy":ye&&!xe,className:"control-pill flex h-8 w-8 flex-shrink-0 items-center justify-center text-white/55",children:e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:xe?e.jsxs(e.Fragment,{children:[e.jsx("path",{d:"M4 14h16"}),e.jsx("path",{d:"M4 10h16"})]}):e.jsxs(e.Fragment,{children:[e.jsx("path",{d:"M4 12h16"}),e.jsx("path",{d:"M12 4v16"})]})})})]})]}),ie.length>0&&e.jsxs("div",{"data-mc-selection-bar":"true",className:`mt-2.5 flex min-h-12 flex-nowrap items-center gap-2 overflow-x-auto rounded-xl border px-3 py-1 whitespace-nowrap ${Se>0?"border-[#BFFF00]/24 bg-[#BFFF00]/[0.08]":"border-white/[0.08] bg-white/[0.02]"}`,children:[e.jsxs("label",{className:"inline-flex flex-shrink-0 items-center gap-2 text-[11px] text-white/75",children:[e.jsx("input",{type:"checkbox",checked:a,onChange:y,className:"h-3.5 w-3.5 rounded border-white/20 bg-black/40 text-[#BFFF00] focus:ring-[#BFFF00]/35"}),"Select visible"]}),e.jsx("span",{className:"flex-shrink-0 text-[11px] text-white/58",children:Se>0?`${Se} selected`:`${ie.length} visible`}),Se>0&&e.jsxs("div",{className:"flex flex-shrink-0 items-center gap-2",children:[e.jsx("button",{type:"button",onClick:()=>{Ue("active")},disabled:N,className:"control-pill h-8 flex-shrink-0 px-3 text-[11px] font-semibold disabled:opacity-45","data-state":"active",children:"Mark active"}),e.jsx("button",{type:"button",onClick:()=>{Ue("paused")},disabled:N,className:"control-pill h-8 flex-shrink-0 px-3 text-[11px] font-semibold disabled:opacity-45",children:"Pause"}),e.jsx("button",{type:"button",onClick:()=>{Ue("blocked")},disabled:N,className:"control-pill h-8 flex-shrink-0 px-3 text-[11px] font-semibold disabled:opacity-45",children:"Block"}),e.jsx("button",{type:"button",onClick:()=>{Ue("completed")},disabled:N,className:"control-pill h-8 flex-shrink-0 px-3 text-[11px] font-semibold disabled:opacity-45",children:"Complete"}),Ie?e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-[10px] text-white/58",children:"Delete selected?"}),e.jsx("button",{type:"button",onClick:()=>{qe()},disabled:N,className:"control-pill h-8 flex-shrink-0 border-red-400/35 bg-red-500/14 px-3 text-[11px] font-semibold text-red-100 disabled:opacity-45",children:"Delete"}),e.jsx("button",{type:"button",onClick:()=>Ee(!1),disabled:N,className:"control-pill h-8 flex-shrink-0 px-2.5 text-[11px] disabled:opacity-45",children:"Keep"})]}):e.jsx("button",{type:"button",onClick:()=>Ee(!0),disabled:N,className:"control-pill h-8 flex-shrink-0 border-red-400/24 bg-red-500/[0.08] px-3 text-[11px] font-semibold text-red-100/85 disabled:opacity-45",children:"Delete"}),e.jsx("button",{type:"button",onClick:re,disabled:N,className:"text-[11px] text-white/55 transition-colors hover:text-white/80 disabled:opacity-45",children:"Clear"})]}),e.jsx(Le,{initial:!1,mode:"popLayout",children:!Me&&!st&&e.jsxs(le.div,{layout:"position",layoutId:$t,initial:{opacity:0,y:4},animate:{opacity:1,y:0,...Bs},exit:{opacity:0,y:-4},transition:{layout:_t,duration:.2,ease:[.22,1,.36,1]},className:"ml-auto flex min-w-[320px] max-w-[640px] flex-shrink-0 items-center gap-3 overflow-hidden rounded-xl border px-2.5 py-2 shadow-[0_14px_30px_rgba(0,0,0,0.32)] backdrop-blur-[10px]",children:[e.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-2.5",children:[D?e.jsx(Ut,{name:D.runnerAgentName,hint:`${D.runnerAgentId} ${D.runnerSource}`,size:"xs"}):e.jsx("div",{className:"h-6 w-6 rounded-full border border-white/[0.16] bg-white/[0.05]"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"text-[10px] font-semibold uppercase tracking-[0.08em] text-white/76",children:"Next Up"}),e.jsx("span",{className:`rounded-full border px-1.5 py-[1px] text-[9px] uppercase tracking-[0.07em] ${As}`,children:Es})]}),e.jsx("p",{className:"truncate text-[11px] font-semibold text-white/92",title:Jt,children:Jt}),e.jsxs("p",{className:"truncate text-[9px] text-white/56",title:It,children:[Ds,It?` · ${It}`:""]})]})]}),e.jsxs("div",{className:"ml-auto flex items-center gap-1.5",children:[e.jsx("button",{type:"button",onClick:Kt,disabled:!D||Mt,className:"control-pill h-7 flex-shrink-0 px-2 text-[10px] font-semibold disabled:opacity-45",title:D?`Dispatch ${D.workstreamTitle}`:"No queued workstream to dispatch",children:"▶ Play"}),e.jsx("button",{type:"button",onClick:At,className:"control-pill h-7 flex-shrink-0 px-2 text-[10px] font-semibold",title:"Expand Next Up rail",children:"Open"})]})]},"next-up-inline-card")})]}),Ge&&e.jsx("div",{className:`mt-2 rounded-lg border px-3 py-2 text-[11px] ${Ge.tone==="success"?"border-emerald-400/24 bg-emerald-500/[0.1] text-emerald-100":"border-amber-400/24 bg-amber-500/[0.1] text-amber-100"}`,children:Ge.message})]}),e.jsxs(le.div,{layout:!0,transition:{type:"spring",stiffness:260,damping:30},className:`grid gap-4 pb-8 ${Me?"xl:grid-cols-[minmax(0,1fr)_320px]":"grid-cols-1"}`,children:[e.jsxs(le.div,{layout:!0,className:"min-w-0",children:[!i&&P&&e.jsx(le.div,{initial:{opacity:0,y:6,scale:.995},animate:{opacity:1,y:0,scale:1},transition:{type:"spring",stiffness:280,damping:30},className:"surface-hero mb-3.5 rounded-2xl p-3.5",children:e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-[240px]",children:[e.jsx("p",{className:"section-kicker",children:"Next action"}),e.jsx("p",{className:"mt-1 text-[14px] font-semibold text-white",children:Bt.headline}),e.jsx("p",{className:"mt-1 text-[12px] text-white/65",children:Bt.detail}),be&&e.jsx("div",{className:`mt-2 inline-flex max-w-[520px] items-center gap-1 rounded-full border px-2.5 py-1 text-[10px] ${be.tone==="success"?"border-emerald-400/24 bg-emerald-500/[0.1] text-emerald-100":"border-amber-400/24 bg-amber-500/[0.1] text-amber-100"}`,children:be.message})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[(ve==="queued"||ve==="running")&&D?e.jsx("button",{type:"button",onClick:ve==="running"?()=>Et(D):Kt,disabled:Mt,className:"control-pill px-3 text-[11px] font-semibold disabled:opacity-45","data-state":"active",children:ve==="running"?"Follow workstream":"Play next workstream"}):ve==="startable"?e.jsx("button",{type:"button",onClick:Cs,disabled:Mt,className:"control-pill px-3 text-[11px] font-semibold disabled:opacity-45","data-state":"active",children:"Start initiative"}):e.jsx("button",{type:"button",onClick:Ss,className:"control-pill px-3 text-[11px] font-semibold","data-state":ve==="blocked"?"active":"idle",children:Fs}),e.jsx("button",{type:"button",onClick:At,className:"control-pill px-3 text-[11px] font-semibold",children:Me?"Hide Next Up":"Open Next Up"})]})]})}),i?e.jsx("div",{className:"space-y-3 pb-8",children:Array.from({length:4}).map((f,E)=>e.jsxs("div",{className:"bg-[--orgx-surface] border border-[--orgx-border] soft-shadow rounded-2xl p-4",children:[e.jsx(ht,{className:"h-4 w-2/5 rounded"}),e.jsx(ht,{className:"h-1 w-full rounded mt-3"})]},`mc-skeleton-${E}`))}):t.length===0?j?e.jsx("div",{className:"pb-8",children:e.jsx(Nn,{})}):e.jsx("div",{className:"pb-8",children:e.jsxs("div",{className:"rounded-2xl border border-white/[0.08] bg-white/[0.02] px-6 py-8 text-center",children:[e.jsx("div",{className:"text-[14px] font-semibold text-white/85",children:"Connect OrgX to get started"}),e.jsx("div",{className:"mt-1 text-[12px] text-white/55",children:"Mission Control shows your initiative hierarchy once a user-scoped API key is configured."}),w&&e.jsx("div",{className:"mt-4 flex items-center justify-center",children:e.jsx("button",{type:"button",onClick:w,className:"h-10 rounded-full border border-[#BFFF00]/30 bg-[#BFFF00]/15 px-4 text-[12px] font-semibold text-[#D8FFA1] transition-colors hover:bg-[#BFFF00]/20",children:"Open settings"})})]})}):ie.length===0?e.jsxs("div",{className:"rounded-2xl border border-white/[0.08] bg-white/[0.02] px-4 py-8 text-center pb-8",children:[e.jsx("div",{className:"text-[13px] font-medium text-white/85",children:"No initiatives match the current filters"}),e.jsx("div",{className:"mt-1 text-[12px] text-white/50",children:K?"Try adjusting status/date filters or clear them.":"Try a broader search phrase."})]}):$?e.jsx("div",{className:"space-y-4 pb-8",children:$.map(f=>{const E=ct(U,f.key),R=Rn(E),H=se.has(E);return e.jsxs(le.div,{layout:!0,transition:{type:"spring",stiffness:260,damping:30},children:[e.jsxs("button",{type:"button","aria-expanded":H,"aria-controls":R,onClick:()=>je(E),className:"mb-2 flex w-full items-center gap-2 rounded-xl border border-white/[0.075] bg-white/[0.016] px-3 py-2.5 text-left transition-colors hover:border-white/[0.16] hover:bg-white/[0.04]",children:[e.jsx("span",{"aria-hidden":!0,className:`inline-flex h-5 w-5 items-center justify-center rounded-md border border-white/[0.12] bg-white/[0.04] text-[11px] text-white/55 transition-transform ${H?"rotate-90":""}`,children:"▶"}),e.jsx("span",{className:"text-[12px] font-semibold text-white/80",children:f.label}),e.jsx("span",{className:"rounded-full border border-white/[0.1] bg-white/[0.04] px-2 py-0.5 text-[10px] text-white/55",children:f.count}),e.jsx("span",{className:"ml-auto text-[10px] uppercase tracking-[0.08em] text-white/45",children:H?"Hide":"Show"})]}),e.jsx(Le,{initial:!1,children:H&&e.jsx(le.div,{id:R,initial:{opacity:0,y:-4},animate:{opacity:1,y:0},exit:{opacity:0,y:-4},transition:{duration:.2,ease:[.22,1,.36,1]},children:e.jsx("div",{className:"pt-0.5",children:e.jsx(rs,{initiatives:f.initiatives,selectedInitiativeIds:ze,onToggleInitiativeSelection:de,runtimeActivityByInitiativeId:S})})})})]},f.key)})}):e.jsx("div",{className:"pb-8",children:e.jsx(rs,{initiatives:ie,selectedInitiativeIds:ze,onToggleInitiativeSelection:de,runtimeActivityByInitiativeId:S})})]}),e.jsx(Le,{initial:!1,children:Me&&e.jsx(le.aside,{layout:!0,initial:{opacity:0,x:14},animate:{opacity:1,x:0},exit:{opacity:0,x:14},transition:{duration:.2,ease:[.22,1,.36,1]},className:"hidden xl:block",children:e.jsx("div",{className:"sticky",style:{top:"calc(var(--mc-toolbar-offset) + 12px)"},children:e.jsx(le.div,{layout:"position",layoutId:$t,initial:{borderRadius:12},animate:{borderRadius:16,...Yt},transition:{layout:_t,type:"spring",stiffness:340,damping:38,mass:.72},className:"origin-top-right overflow-hidden rounded-2xl border shadow-[0_18px_40px_rgba(0,0,0,0.42)] backdrop-blur-[12px]",children:e.jsxs("div",{className:"relative",children:[e.jsx("button",{type:"button",onClick:At,className:"control-pill absolute right-3 top-3 z-20 h-7 px-2 text-[10px] font-semibold",title:"Collapse Next Up rail",children:"Hide"}),e.jsx(ts,{title:"Next Up",compact:!0,className:"!bg-transparent !shadow-none !border-transparent",disableEnterAnimation:!0,authToken:Y,embedMode:oe,onFollowWorkstream:Et,onOpenInitiative:Je,onOpenSettings:w,onUpgradeGate:Qe})]})})})})})]})]}),e.jsx(Le,{children:st&&e.jsxs(e.Fragment,{children:[e.jsx(le.button,{type:"button","aria-label":"Close next up panel",onClick:()=>me(!1),initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:"fixed bottom-0 left-0 right-0 top-[64px] z-[220] hidden bg-black/45 lg:block xl:hidden"},"next-up-backdrop"),e.jsx(le.aside,{initial:{x:"100%",opacity:.85},animate:{x:0,opacity:1},exit:{x:"100%",opacity:.9},transition:{type:"spring",stiffness:320,damping:34},className:"fixed bottom-0 right-0 top-[64px] z-[230] hidden w-[360px] max-w-[94vw] p-3 lg:block xl:hidden",children:e.jsxs("div",{className:"relative flex h-full flex-col",children:[e.jsx("button",{type:"button",onClick:()=>me(!1),className:"absolute right-2 top-16 z-20 inline-flex h-8 w-8 items-center justify-center rounded-full border border-white/[0.14] bg-[#080d14]/85 text-white/72 transition-colors hover:text-white","aria-label":"Close next up drawer",children:"✕"}),e.jsx(le.div,{layout:"position",layoutId:$t,initial:{borderRadius:12},animate:{borderRadius:16,...Yt},transition:{layout:_t,type:"spring",stiffness:340,damping:38,mass:.72},className:"h-full overflow-hidden rounded-2xl border shadow-[0_18px_40px_rgba(0,0,0,0.42)] backdrop-blur-[12px]",children:e.jsx(ts,{title:"Next Up",className:"!bg-transparent !shadow-none !border-transparent",disableEnterAnimation:!0,authToken:Y,embedMode:oe,onFollowWorkstream:Et,onOpenInitiative:(f,E)=>{Je(f,E),me(!1)},onOpenSettings:w,onUpgradeGate:Qe})})]})},"next-up-drawer")]})})]})})]}),e.jsx(Mn,{target:Ms,onClose:ne})]})}export{Qn as MissionControlView};
|