import{r as n,C as xo,j as e,z as go,f as Lt,B as $e,A as ut,D as Ft,w as vo}from"./index-BmZS3y7B.js";import{R as wo,S as bo,a as M,u as Ht,W as Le,b as Oe,A as ft,C as ht,c as pt,d as mt,g as $t,e as De,D as Bt,f as Vt,E as Wt,h as zt,i as yo,j as Ut,r as jo,k as No,l as Kt,m as Gt,n as So,o as qt,p as Co,q as Yt,X as Zt,s as ko,t as Ro,P as Xt,v as St,w as Io,x as To,y as Eo,z as Po,B as Jt,F as _o,Z as Mo,G as Ao,H as Do,I as Oo,J as Lo,T as Fo,K as Ho,L as qe,M as Ye,N as Ze}from"./workflow-graph-viewer-B5c_xYyF.js";import{g as he,P as z,c as Se,h as $o,d as E,D as Bo,i as Vo,j as Wo,k as zo,T as ke,a as Re,B as oe,b as Ie,l as Qt,m as tt,n as J,o as es,p as ts,A as Uo,q as V,s as Te,v as ss,w as os,C as Ko,x as st,y as Go,V as qo,z as Yo,E as Zo,u as ns,t as me,L as Xe,F as Xo,G as Jo,H as xt,I as Qo,J as en}from"./mermaid-3ZIDBTTL-CCXSRVd3.js";var tn="Portal",gt=n.forwardRef((t,s)=>{var c;const{container:o,...r}=t,[l,a]=n.useState(!1);he(()=>a(!0),[]);const i=o||l&&((c=globalThis==null?void 0:globalThis.document)==null?void 0:c.body);return i?xo.createPortal(e.jsx(z.div,{...r,ref:s}),i):null});gt.displayName=tn;/**
 * @license lucide-react v0.575.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const sn=[["path",{d:"m3 16 4 4 4-4",key:"1co6wj"}],["path",{d:"M7 20V4",key:"1yoxec"}],["path",{d:"M20 8h-5",key:"1vsyxs"}],["path",{d:"M15 10V6.5a2.5 2.5 0 0 1 5 0V10",key:"ag13bf"}],["path",{d:"M15 14h5l-5 6h5",key:"ur5jdg"}]],on=Se("arrow-down-a-z",sn);/**
 * @license lucide-react v0.575.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const nn=[["path",{d:"m3 8 4-4 4 4",key:"11wl7u"}],["path",{d:"M7 4v16",key:"1glfcx"}],["path",{d:"M20 8h-5",key:"1vsyxs"}],["path",{d:"M15 10V6.5a2.5 2.5 0 0 1 5 0V10",key:"ag13bf"}],["path",{d:"M15 14h5l-5 6h5",key:"ur5jdg"}]],rn=Se("arrow-up-a-z",nn);/**
 * @license lucide-react v0.575.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const an=[["path",{d:"m15 18-6-6 6-6",key:"1wnfg3"}]],rs=Se("chevron-left",an);/**
 * @license lucide-react v0.575.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const ln=[["path",{d:"M15 6a9 9 0 0 0-9 9V3",key:"1cii5b"}],["circle",{cx:"18",cy:"6",r:"3",key:"1h7g24"}],["circle",{cx:"6",cy:"18",r:"3",key:"fqmcym"}]],Ct=Se("git-branch",ln);/**
 * @license lucide-react v0.575.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const cn=[["path",{d:"M5 12h14",key:"1ays0h"}]],dn=Se("minus",cn);/**
 * @license lucide-react v0.575.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const un=[["path",{d:"M3 12a9 9 0 0 1 9-9 9.75 9.75 0 0 1 6.74 2.74L21 8",key:"v9h5vc"}],["path",{d:"M21 3v5h-5",key:"1q7to0"}],["path",{d:"M21 12a9 9 0 0 1-9 9 9.75 9.75 0 0 1-6.74-2.74L3 16",key:"3uifl3"}],["path",{d:"M8 16H3v5",key:"1cv678"}]],as=Se("refresh-cw",un);/**
 * @license lucide-react v0.575.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const fn=[["rect",{width:"8",height:"8",x:"3",y:"3",rx:"2",key:"by2w9f"}],["path",{d:"M7 11v4a2 2 0 0 0 2 2h4",key:"xkn7yn"}],["rect",{width:"8",height:"8",x:"13",y:"13",rx:"2",key:"1cgmvn"}]],kt=Se("workflow",fn);function hn({onResolve:t,callbacks:s}){const o=$o(),[r,l]=n.useState(!1),[a,i]=n.useState(null),c=n.useCallback(g=>{i(g)},[]),d=n.useCallback(()=>{i(null)},[]),f=n.useCallback(async g=>{var u;if(!(r||!a))try{l(!0),await t(a,g),o.success("Hook resolved",{description:"The payload has been sent and the hook resolved."}),i(null),(u=s==null?void 0:s.onSuccess)==null||u.call(s)}catch(m){console.error("Failed to resolve hook:",m),o.error("Failed to resolve hook",{description:m instanceof Error?m.message:"An unknown error occurred"})}finally{l(!1)}},[t,a,r,s]);return{isResolving:r,selectedHook:a,openResolveModal:c,closeResolveModal:d,handleResolve:f}}function pn({hook:t,stopPropagation:s=!1,onResolveClick:o,DropdownMenuItem:r}){const l=a=>{s&&a.stopPropagation(),o(t)};return e.jsxs(r,{onClick:l,children:[e.jsx(bo,{className:"h-4 w-4 mr-2"}),"Resolve Hook"]})}function mn({hookActions:t}){const{selectedHook:s,closeResolveModal:o,handleResolve:r,isResolving:l}=t;return e.jsx(wo,{isOpen:s!==null,onClose:o,onSubmit:r,isSubmitting:l})}const Ee=n.forwardRef(({className:t,...s},o)=>e.jsx("div",{ref:o,className:E("rounded-lg border bg-card text-card-foreground shadow-sm",t),...s}));Ee.displayName="Card";const xn=n.forwardRef(({className:t,...s},o)=>e.jsx("div",{ref:o,className:E("flex flex-col space-y-1.5 p-6",t),...s}));xn.displayName="CardHeader";const gn=n.forwardRef(({className:t,...s},o)=>e.jsx("div",{ref:o,className:E("text-2xl font-semibold leading-none tracking-tight",t),...s}));gn.displayName="CardTitle";const vn=n.forwardRef(({className:t,...s},o)=>e.jsx("div",{ref:o,className:E("text-sm text-muted-foreground",t),...s}));vn.displayName="CardDescription";const Pe=n.forwardRef(({className:t,...s},o)=>e.jsx("div",{ref:o,className:E("p-6 pt-0",t),...s}));Pe.displayName="CardContent";const wn=n.forwardRef(({className:t,...s},o)=>e.jsx("div",{ref:o,className:E("flex items-center p-6 pt-0",t),...s}));wn.displayName="CardFooter";const ls=n.forwardRef(({className:t,href:s,children:o,...r},l)=>{const a=s.startsWith("http")?s:`https://useworkflow.dev/docs/${s.replace(/^\//,"")}`;return e.jsx(go,{href:a,className:E("font-medium underline underline-offset-4 transition-colors",t),style:{color:"var(--ds-blue-600)"},target:"_blank",rel:"noopener noreferrer",ref:l,...r,children:o})});ls.displayName="DocsLink";const Be=n.forwardRef(({className:t,...s},o)=>e.jsx("div",{className:"relative w-full overflow-auto",children:e.jsx("table",{ref:o,className:E("w-full caption-bottom text-sm",t),...s})}));Be.displayName="Table";const Ve=n.forwardRef(({className:t,...s},o)=>e.jsx("thead",{ref:o,className:E("[&_tr]:border-b",t),...s}));Ve.displayName="TableHeader";const We=n.forwardRef(({className:t,...s},o)=>e.jsx("tbody",{ref:o,className:E("[&_tr:last-child]:border-0",t),...s}));We.displayName="TableBody";const bn=n.forwardRef(({className:t,...s},o)=>e.jsx("tfoot",{ref:o,className:E("border-t bg-muted/50 font-medium [&>tr]:last:border-b-0",t),...s}));bn.displayName="TableFooter";const ie=n.forwardRef(({className:t,...s},o)=>e.jsx("tr",{ref:o,className:E("border-b transition-colors hover:bg-muted/50 data-[state=selected]:bg-muted",t),...s}));ie.displayName="TableRow";const G=n.forwardRef(({className:t,...s},o)=>e.jsx("th",{ref:o,className:E("h-12 px-4 text-left align-middle font-medium text-muted-foreground [&:has([role=checkbox])]:pr-0",t),...s}));G.displayName="TableHead";const W=n.forwardRef(({className:t,...s},o)=>e.jsx("td",{ref:o,className:E("p-4 align-middle [&:has([role=checkbox])]:pr-0",t),...s}));W.displayName="TableCell";const yn=n.forwardRef(({className:t,...s},o)=>e.jsx("caption",{ref:o,className:E("mt-4 text-sm text-muted-foreground",t),...s}));yn.displayName="TableCaption";function cs({rows:t=Bo,variant:s="runs"}){const o=l=>{switch(s){case"runs":return e.jsxs("div",{className:"grid grid-cols-[1fr_1.5fr_0.8fr_1fr_1fr_40px] items-center gap-4 py-3 px-4",children:[e.jsx(M,{className:"h-4 w-3/4"}),e.jsx(M,{className:"h-4 w-4/5"}),e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsx(M,{className:"h-3 w-14"}),e.jsx(M,{className:"h-2 w-8"})]}),e.jsx(M,{className:"h-3 w-3/4"}),e.jsx(M,{className:"h-3 w-3/4"}),e.jsx(M,{className:"h-6 w-6 rounded"})]},`skeleton-row-${l}`);case"hooks":return e.jsxs("div",{className:"grid grid-cols-[1.2fr_1.2fr_0.8fr_1fr_0.5fr_40px] items-center gap-4 py-3 px-4",children:[e.jsx(M,{className:"h-4 w-4/5"}),e.jsx(M,{className:"h-4 w-4/5"}),e.jsx(M,{className:"h-4 w-3/4"}),e.jsx(M,{className:"h-3 w-3/4"}),e.jsx(M,{className:"h-4 w-8"}),e.jsx(M,{className:"h-6 w-6 rounded"})]},`skeleton-row-${l}`);case"workflows":return e.jsxs("div",{className:"grid grid-cols-[1fr_1.5fr_0.5fr] items-center gap-4 py-3 px-4",children:[e.jsx(M,{className:"h-4 w-3/4"}),e.jsx(M,{className:"h-4 w-4/5"}),e.jsx(M,{className:"h-5 w-16 rounded-full mx-auto"})]},`skeleton-row-${l}`);default:return null}},r=()=>{switch(s){case"runs":return e.jsxs("div",{className:"grid grid-cols-[1fr_1.5fr_0.8fr_1fr_1fr_40px] items-center gap-4 py-3 px-4 border-b",children:[e.jsx(M,{className:"h-4 w-20"}),e.jsx(M,{className:"h-4 w-14"}),e.jsx(M,{className:"h-4 w-12"}),e.jsx(M,{className:"h-4 w-14"}),e.jsx(M,{className:"h-4 w-20"}),e.jsx("div",{className:"w-6"})]});case"hooks":return e.jsxs("div",{className:"grid grid-cols-[1.2fr_1.2fr_0.8fr_1fr_0.5fr_40px] items-center gap-4 py-3 px-4 border-b",children:[e.jsx(M,{className:"h-4 w-16"}),e.jsx(M,{className:"h-4 w-14"}),e.jsx(M,{className:"h-4 w-12"}),e.jsx(M,{className:"h-4 w-14"}),e.jsx(M,{className:"h-4 w-20"}),e.jsx("div",{className:"w-6"})]});case"workflows":return e.jsxs("div",{className:"grid grid-cols-[1fr_1.5fr_0.5fr] items-center gap-4 py-3 px-4 border-b",children:[e.jsx(M,{className:"h-4 w-20"}),e.jsx(M,{className:"h-4 w-10"}),e.jsx(M,{className:"h-4 w-12 mx-auto"})]});default:return null}};return e.jsx(Ee,{className:"overflow-hidden mt-4 bg-background",children:e.jsxs(Pe,{className:"p-0",children:[r(),Array.from({length:t},(l,a)=>o(a))]})})}function Rt(t,s,o){return o===1?t:s}function is(t){var O;const[s,o]=n.useState(void 0),[r,l]=n.useState(!1),[a,i]=n.useState(0),[c,d]=n.useState([void 0]),[f,g]=n.useState(1),[u,m]=n.useState(new Map([[0,{data:null,isLoading:!1,error:null}]])),p=n.useRef(new Map),x=n.useCallback(async(C,P,q=!1)=>{const _=P??"initial";if(m(k=>{var H;const L=new Map(k);return L.set(C,{data:((H=k.get(C))==null?void 0:H.data)??null,isLoading:!0,error:null}),L}),!q&&p.current.has(_)){const k=p.current.get(_);if(k){m(L=>{const H=new Map(L);return H.set(C,{data:k.data,isLoading:!1,error:null}),H}),o(k.cursor),l(k.hasMore);return}}try{const k=await t(P);p.current.set(_,{data:k.data,cursor:k.cursor,hasMore:k.hasMore}),m(L=>{const H=new Map(L);return H.set(C,{data:k.data,isLoading:!1,error:null}),H}),o(k.cursor),l(k.hasMore)}catch(k){const L=k instanceof Error?k:new Le(String(k),{layer:"client"});m(H=>{var de;const K=new Map(H);return K.set(C,{data:((de=H.get(C))==null?void 0:de.data)??null,isLoading:!1,error:L}),K})}},[t]);n.useEffect(()=>{x(0,void 0,!0)},[x]);const h=n.useCallback(()=>{if(r&&s){const C=a+1;d(P=>[...P,s]),i(C),g(P=>Math.max(P,C+1)),u.has(C)||m(P=>{const q=new Map(P);return q.set(C,{data:null,isLoading:!0,error:null}),q}),x(C,s)}},[r,s,x,a,u]),v=n.useCallback(()=>{if(a>0){const C=a-1,P=c[C];i(C),x(C,P)}},[a,c,x]),j=n.useCallback(()=>{p.current.clear(),m(new Map([[0,{data:null,isLoading:!0,error:null}]])),i(0),d([void 0]),g(1),x(0,void 0,!0)},[x]),w=n.useCallback(()=>{const C=c[a],P=C??"initial";p.current.delete(P),x(a,C,!0)},[x,a,c]),b=u.get(a)??{data:null,isLoading:!0,error:null},R=((O=Array.from(u.values()).find(C=>C.error))==null?void 0:O.error)??null,N=Array.from(u.values()).some(C=>C.isLoading),I=r?a+2:a+1,T=a+1,Z=zo(T,f,T===f&&r);return{data:b,allData:Array.from(u.values()),error:R,isLoading:N,currentPage:a,totalPages:I,nextPage:h,previousPage:v,hasNextPage:r,hasPreviousPage:a>0,reload:j,refresh:w,pageInfo:Z}}function jn(t,s){const{workflowName:o,status:r,limit:l=10,sortOrder:a="desc"}=s,i=n.useCallback(c=>Ht(Vo(t,{cursor:c,sortOrder:a,limit:l,workflowName:o,status:r})),[t,o,l,a,r]);return is(i)}function Nn(t,s){const{runId:o,limit:r=10,sortOrder:l="desc"}=s,a=n.useCallback(i=>Ht(Wo(t,{runId:o,cursor:i,sortOrder:l,limit:r})),[t,o,r,l]);return is(a)}function Sn({runId:t,onHookClick:s,selectedHookId:o}){const[r,l]=n.useState(()=>new Date),a=n.useMemo(()=>({}),[]),{data:i,error:c,nextPage:d,previousPage:f,hasNextPage:g,hasPreviousPage:u,refresh:m,pageInfo:p}=Nn(a,{runId:t,sortOrder:"desc"}),x=hn({onResolve:async(N,I)=>{await jo(a,N.token,I)},callbacks:{onSuccess:m}}),h=i.isLoading,v=i.data??[],j=()=>{l(()=>new Date),m()},[w,b]=n.useState(new Map);n.useEffect(()=>{if(!v.length||!t)return;(async()=>{const I=new Map;for(const T of v)I.set(T.hookId,{count:0,hasMore:!1,loading:!0});b(I);try{const T=await Qt(a,t,{sortOrder:"asc",limit:1e3});if(!T.success){b(O=>{const C=new Map(O);for(const P of v)C.set(P.hookId,{count:0,hasMore:!1,loading:!1});return C});return}const U=T.data.data,Y=new Set(v.map(O=>O.hookId)),Z=new Map;for(const O of U)O.eventType==="hook_received"&&O.correlationId&&Y.has(O.correlationId)&&Z.set(O.correlationId,(Z.get(O.correlationId)??0)+1);b(O=>{const C=new Map(O);for(const P of v)C.set(P.hookId,{count:Z.get(P.hookId)??0,hasMore:T.data.hasMore,loading:!1});return C})}catch{b(T=>{const U=new Map(T);for(const Y of v)U.set(Y.hookId,{count:0,hasMore:!1,loading:!1});return U})}})()},[v,a,t]);const R=N=>{const I=w.get(N.hookId);if(!I||I.loading)return e.jsx("span",{className:"text-muted-foreground text-xs",children:"..."});if(I.count instanceof Error)return e.jsx("span",{className:"text-muted-foreground",children:"Error"});if(I.count===0)return e.jsx("span",{className:"text-muted-foreground",children:"0"});const T=I.hasMore?`${I.count}+`:`${I.count}`;return I.hasMore?e.jsxs(ke,{children:[e.jsx(Re,{asChild:!0,children:e.jsx("span",{className:"font-semibold cursor-help",children:T})}),e.jsx(Ie,{className:"max-w-xs",children:e.jsx("div",{className:"text-xs",children:"Showing first 100 invocations. There may be more."})})]}):e.jsx("span",{className:"font-semibold",children:T})};return e.jsxs("div",{children:[e.jsx(mn,{hookActions:x}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-end gap-2",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Last refreshed"}),r&&e.jsx(Oe,{date:r,className:"text-sm text-muted-foreground",type:"distance"})]}),e.jsx("div",{className:"flex items-center gap-4",children:e.jsxs(ke,{children:[e.jsx(Re,{asChild:!0,children:e.jsxs(oe,{variant:"outline",size:"sm",onClick:j,disabled:h,children:[e.jsx(as,{className:h?"animate-spin":""}),"Refresh"]})}),e.jsx(Ie,{children:"Note that this resets pages"})]})})]}),c?e.jsxs(ft,{variant:"destructive",children:[e.jsx(ht,{className:"h-4 w-4"}),e.jsx(pt,{children:"Error loading hooks"}),e.jsx(mt,{children:$t(c)})]}):!h&&(!v||v.length===0)?e.jsxs("div",{className:"text-center py-8 text-muted-foreground",children:["No active hooks found. ",e.jsx("br",{}),e.jsx(ls,{href:"https://useworkflow.dev/docs/api-reference/workflow/create-hook",children:"Learn how to create a hook"})]}):h&&!(i!=null&&i.data)?e.jsx(cs,{variant:"hooks"}):e.jsxs(e.Fragment,{children:[e.jsx(Ee,{className:"overflow-hidden mt-4 bg-background",children:e.jsx(Pe,{className:"p-0 max-h-[calc(100vh-280px)] overflow-auto",children:e.jsxs(Be,{children:[e.jsx(Ve,{children:e.jsxs(ie,{children:[e.jsx(G,{className:"sticky top-0 bg-background z-10 border-b shadow-sm h-10",children:"Hook ID"}),e.jsx(G,{className:"sticky top-0 bg-background z-10 border-b shadow-sm h-10",children:"Run ID"}),e.jsx(G,{className:"sticky top-0 bg-background z-10 border-b shadow-sm h-10",children:"Token"}),e.jsx(G,{className:"sticky top-0 bg-background z-10 border-b shadow-sm h-10",children:"Created"}),e.jsx(G,{className:"sticky top-0 bg-background z-10 border-b shadow-sm h-10",children:"Invocations"}),e.jsx(G,{className:"sticky top-0 bg-background z-10 border-b shadow-sm h-10 w-10"})]})}),e.jsx(We,{children:v.map(N=>e.jsxs(ie,{className:"cursor-pointer group relative",onClick:()=>s(N.hookId,N.runId),"data-selected":N.hookId===o,children:[e.jsx(W,{className:"font-mono text-xs py-2",children:e.jsx(De,{text:N.hookId,overlay:!0,children:N.hookId})}),e.jsx(W,{className:"font-mono text-xs py-2",children:e.jsx(De,{text:N.runId,overlay:!0,children:N.runId})}),e.jsx(W,{className:"font-mono text-xs py-2",children:e.jsx(De,{text:N.token,overlay:!0,children:e.jsx("span",{className:"text-muted-foreground",children:"••••••••••••"})})}),e.jsx(W,{className:"py-2 text-muted-foreground text-xs",children:N.createdAt?e.jsx(Oe,{date:N.createdAt}):"-"}),e.jsx(W,{className:"py-2",children:R(N)}),e.jsx(W,{className:"py-2",children:e.jsxs(Bt,{children:[e.jsx(Vt,{asChild:!0,children:e.jsx(oe,{variant:"ghost",size:"icon",className:"h-8 w-8",onClick:I=>I.stopPropagation(),children:e.jsx(Wt,{className:"h-4 w-4"})})}),e.jsx(zt,{align:"end",children:e.jsx(pn,{hook:N,stopPropagation:!0,onResolveClick:x.openResolveModal,DropdownMenuItem:yo})})]})})]},N.hookId))})]})})}),e.jsxs("div",{className:"flex items-center justify-between mt-4",children:[e.jsx("div",{className:"text-sm text-muted-foreground",children:p}),e.jsxs("div",{className:"flex gap-2 items-center",children:[e.jsxs(oe,{variant:"outline",size:"sm",onClick:f,disabled:!u,children:[e.jsx(rs,{}),"Previous"]}),e.jsxs(oe,{variant:"outline",size:"sm",onClick:d,disabled:!g,children:["Next",e.jsx(Ut,{})]})]})]})]})]})}function It(t,[s,o]){return Math.min(o,Math.max(s,t))}var Je=0;function ds(){n.useEffect(()=>{const t=document.querySelectorAll("[data-radix-focus-guard]");return document.body.insertAdjacentElement("afterbegin",t[0]??Tt()),document.body.insertAdjacentElement("beforeend",t[1]??Tt()),Je++,()=>{Je===1&&document.querySelectorAll("[data-radix-focus-guard]").forEach(s=>s.remove()),Je--}},[])}function Tt(){const t=document.createElement("span");return t.setAttribute("data-radix-focus-guard",""),t.tabIndex=0,t.style.outline="none",t.style.opacity="0",t.style.position="fixed",t.style.pointerEvents="none",t}var Qe="focusScope.autoFocusOnMount",et="focusScope.autoFocusOnUnmount",Et={bubbles:!1,cancelable:!0},Cn="FocusScope",vt=n.forwardRef((t,s)=>{const{loop:o=!1,trapped:r=!1,onMountAutoFocus:l,onUnmountAutoFocus:a,...i}=t,[c,d]=n.useState(null),f=tt(l),g=tt(a),u=n.useRef(null),m=J(s,h=>d(h)),p=n.useRef({paused:!1,pause(){this.paused=!0},resume(){this.paused=!1}}).current;n.useEffect(()=>{if(r){let h=function(b){if(p.paused||!c)return;const R=b.target;c.contains(R)?u.current=R:ge(u.current,{select:!0})},v=function(b){if(p.paused||!c)return;const R=b.relatedTarget;R!==null&&(c.contains(R)||ge(u.current,{select:!0}))},j=function(b){if(document.activeElement===document.body)for(const N of b)N.removedNodes.length>0&&ge(c)};document.addEventListener("focusin",h),document.addEventListener("focusout",v);const w=new MutationObserver(j);return c&&w.observe(c,{childList:!0,subtree:!0}),()=>{document.removeEventListener("focusin",h),document.removeEventListener("focusout",v),w.disconnect()}}},[r,c,p.paused]),n.useEffect(()=>{if(c){_t.add(p);const h=document.activeElement;if(!c.contains(h)){const j=new CustomEvent(Qe,Et);c.addEventListener(Qe,f),c.dispatchEvent(j),j.defaultPrevented||(kn(Pn(us(c)),{select:!0}),document.activeElement===h&&ge(c))}return()=>{c.removeEventListener(Qe,f),setTimeout(()=>{const j=new CustomEvent(et,Et);c.addEventListener(et,g),c.dispatchEvent(j),j.defaultPrevented||ge(h??document.body,{select:!0}),c.removeEventListener(et,g),_t.remove(p)},0)}}},[c,f,g,p]);const x=n.useCallback(h=>{if(!o&&!r||p.paused)return;const v=h.key==="Tab"&&!h.altKey&&!h.ctrlKey&&!h.metaKey,j=document.activeElement;if(v&&j){const w=h.currentTarget,[b,R]=Rn(w);b&&R?!h.shiftKey&&j===R?(h.preventDefault(),o&&ge(b,{select:!0})):h.shiftKey&&j===b&&(h.preventDefault(),o&&ge(R,{select:!0})):j===w&&h.preventDefault()}},[o,r,p.paused]);return e.jsx(z.div,{tabIndex:-1,...i,ref:m,onKeyDown:x})});vt.displayName=Cn;function kn(t,{select:s=!1}={}){const o=document.activeElement;for(const r of t)if(ge(r,{select:s}),document.activeElement!==o)return}function Rn(t){const s=us(t),o=Pt(s,t),r=Pt(s.reverse(),t);return[o,r]}function us(t){const s=[],o=document.createTreeWalker(t,NodeFilter.SHOW_ELEMENT,{acceptNode:r=>{const l=r.tagName==="INPUT"&&r.type==="hidden";return r.disabled||r.hidden||l?NodeFilter.FILTER_SKIP:r.tabIndex>=0?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP}});for(;o.nextNode();)s.push(o.currentNode);return s}function Pt(t,s){for(const o of t)if(!In(o,{upTo:s}))return o}function In(t,{upTo:s}){if(getComputedStyle(t).visibility==="hidden")return!0;for(;t;){if(s!==void 0&&t===s)return!1;if(getComputedStyle(t).display==="none")return!0;t=t.parentElement}return!1}function Tn(t){return t instanceof HTMLInputElement&&"select"in t}function ge(t,{select:s=!1}={}){if(t&&t.focus){const o=document.activeElement;t.focus({preventScroll:!0}),t!==o&&Tn(t)&&s&&t.select()}}var _t=En();function En(){let t=[];return{add(s){const o=t[0];s!==o&&(o==null||o.pause()),t=Mt(t,s),t.unshift(s)},remove(s){var o;t=Mt(t,s),(o=t[0])==null||o.resume()}}}function Mt(t,s){const o=[...t],r=o.indexOf(s);return r!==-1&&o.splice(r,1),o}function Pn(t){return t.filter(s=>s.tagName!=="A")}function _n(t){const s=n.useRef({value:t,previous:t});return n.useMemo(()=>(s.current.value!==t&&(s.current.previous=s.current.value,s.current.value=t),s.current.previous),[t])}var Mn=[" ","Enter","ArrowUp","ArrowDown"],An=[" ","Enter"],ye="Select",[ze,Ue,Dn]=No(ye),[_e]=ts(ye,[Dn,es]),Ke=es(),[On,we]=_e(ye),[Ln,Fn]=_e(ye),fs=t=>{const{__scopeSelect:s,children:o,open:r,defaultOpen:l,onOpenChange:a,value:i,defaultValue:c,onValueChange:d,dir:f,name:g,autoComplete:u,disabled:m,required:p,form:x}=t,h=Ke(s),[v,j]=n.useState(null),[w,b]=n.useState(null),[R,N]=n.useState(!1),I=So(f),[T,U]=st({prop:r,defaultProp:l??!1,onChange:a,caller:ye}),[Y,Z]=st({prop:i,defaultProp:c,onChange:d,caller:ye}),O=n.useRef(null),C=v?x||!!v.closest("form"):!0,[P,q]=n.useState(new Set),_=Array.from(P).map(k=>k.props.value).join(";");return e.jsx(Go,{...h,children:e.jsxs(On,{required:p,scope:s,trigger:v,onTriggerChange:j,valueNode:w,onValueNodeChange:b,valueNodeHasChildren:R,onValueNodeHasChildrenChange:N,contentId:Te(),value:Y,onValueChange:Z,open:T,onOpenChange:U,dir:I,triggerPointerDownPosRef:O,disabled:m,children:[e.jsx(ze.Provider,{scope:s,children:e.jsx(Ln,{scope:t.__scopeSelect,onNativeOptionAdd:n.useCallback(k=>{q(L=>new Set(L).add(k))},[]),onNativeOptionRemove:n.useCallback(k=>{q(L=>{const H=new Set(L);return H.delete(k),H})},[]),children:o})}),C?e.jsxs(Os,{"aria-hidden":!0,required:p,tabIndex:-1,name:g,autoComplete:u,value:Y,onChange:k=>Z(k.target.value),disabled:m,form:x,children:[Y===void 0?e.jsx("option",{value:""}):null,Array.from(P)]},_):null]})})};fs.displayName=ye;var hs="SelectTrigger",ps=n.forwardRef((t,s)=>{const{__scopeSelect:o,disabled:r=!1,...l}=t,a=Ke(o),i=we(hs,o),c=i.disabled||r,d=J(s,i.onTriggerChange),f=Ue(o),g=n.useRef("touch"),[u,m,p]=Fs(h=>{const v=f().filter(b=>!b.disabled),j=v.find(b=>b.value===i.value),w=Hs(v,h,j);w!==void 0&&i.onValueChange(w.value)}),x=h=>{c||(i.onOpenChange(!0),p()),h&&(i.triggerPointerDownPosRef.current={x:Math.round(h.pageX),y:Math.round(h.pageY)})};return e.jsx(Uo,{asChild:!0,...a,children:e.jsx(z.button,{type:"button",role:"combobox","aria-controls":i.contentId,"aria-expanded":i.open,"aria-required":i.required,"aria-autocomplete":"none",dir:i.dir,"data-state":i.open?"open":"closed",disabled:c,"data-disabled":c?"":void 0,"data-placeholder":Ls(i.value)?"":void 0,...l,ref:d,onClick:V(l.onClick,h=>{h.currentTarget.focus(),g.current!=="mouse"&&x(h)}),onPointerDown:V(l.onPointerDown,h=>{g.current=h.pointerType;const v=h.target;v.hasPointerCapture(h.pointerId)&&v.releasePointerCapture(h.pointerId),h.button===0&&h.ctrlKey===!1&&h.pointerType==="mouse"&&(x(h),h.preventDefault())}),onKeyDown:V(l.onKeyDown,h=>{const v=u.current!=="";!(h.ctrlKey||h.altKey||h.metaKey)&&h.key.length===1&&m(h.key),!(v&&h.key===" ")&&Mn.includes(h.key)&&(x(),h.preventDefault())})})})});ps.displayName=hs;var ms="SelectValue",xs=n.forwardRef((t,s)=>{const{__scopeSelect:o,className:r,style:l,children:a,placeholder:i="",...c}=t,d=we(ms,o),{onValueNodeHasChildrenChange:f}=d,g=a!==void 0,u=J(s,d.onValueNodeChange);return he(()=>{f(g)},[f,g]),e.jsx(z.span,{...c,ref:u,style:{pointerEvents:"none"},children:Ls(d.value)?e.jsx(e.Fragment,{children:i}):a})});xs.displayName=ms;var Hn="SelectIcon",gs=n.forwardRef((t,s)=>{const{__scopeSelect:o,children:r,...l}=t;return e.jsx(z.span,{"aria-hidden":!0,...l,ref:s,children:r||"▼"})});gs.displayName=Hn;var $n="SelectPortal",vs=t=>e.jsx(gt,{asChild:!0,...t});vs.displayName=$n;var je="SelectContent",ws=n.forwardRef((t,s)=>{const o=we(je,t.__scopeSelect),[r,l]=n.useState();if(he(()=>{l(new DocumentFragment)},[]),!o.open){const a=r;return a?Lt.createPortal(e.jsx(bs,{scope:t.__scopeSelect,children:e.jsx(ze.Slot,{scope:t.__scopeSelect,children:e.jsx("div",{children:t.children})})}),a):null}return e.jsx(ys,{...t,ref:s})});ws.displayName=je;var re=10,[bs,be]=_e(je),Bn="SelectContentImpl",Vn=ss("SelectContent.RemoveScroll"),ys=n.forwardRef((t,s)=>{const{__scopeSelect:o,position:r="item-aligned",onCloseAutoFocus:l,onEscapeKeyDown:a,onPointerDownOutside:i,side:c,sideOffset:d,align:f,alignOffset:g,arrowPadding:u,collisionBoundary:m,collisionPadding:p,sticky:x,hideWhenDetached:h,avoidCollisions:v,...j}=t,w=we(je,o),[b,R]=n.useState(null),[N,I]=n.useState(null),T=J(s,S=>R(S)),[U,Y]=n.useState(null),[Z,O]=n.useState(null),C=Ue(o),[P,q]=n.useState(!1),_=n.useRef(!1);n.useEffect(()=>{if(b)return Kt(b)},[b]),ds();const k=n.useCallback(S=>{const[$,...X]=C().map(A=>A.ref.current),[F]=X.slice(-1),D=document.activeElement;for(const A of S)if(A===D||(A==null||A.scrollIntoView({block:"nearest"}),A===$&&N&&(N.scrollTop=0),A===F&&N&&(N.scrollTop=N.scrollHeight),A==null||A.focus(),document.activeElement!==D))return},[C,N]),L=n.useCallback(()=>k([U,b]),[k,U,b]);n.useEffect(()=>{P&&L()},[P,L]);const{onOpenChange:H,triggerPointerDownPosRef:K}=w;n.useEffect(()=>{if(b){let S={x:0,y:0};const $=F=>{var D,A;S={x:Math.abs(Math.round(F.pageX)-(((D=K.current)==null?void 0:D.x)??0)),y:Math.abs(Math.round(F.pageY)-(((A=K.current)==null?void 0:A.y)??0))}},X=F=>{S.x<=10&&S.y<=10?F.preventDefault():b.contains(F.target)||H(!1),document.removeEventListener("pointermove",$),K.current=null};return K.current!==null&&(document.addEventListener("pointermove",$),document.addEventListener("pointerup",X,{capture:!0,once:!0})),()=>{document.removeEventListener("pointermove",$),document.removeEventListener("pointerup",X,{capture:!0})}}},[b,H,K]),n.useEffect(()=>{const S=()=>H(!1);return window.addEventListener("blur",S),window.addEventListener("resize",S),()=>{window.removeEventListener("blur",S),window.removeEventListener("resize",S)}},[H]);const[de,ue]=Fs(S=>{const $=C().filter(D=>!D.disabled),X=$.find(D=>D.ref.current===document.activeElement),F=Hs($,S,X);F&&setTimeout(()=>F.ref.current.focus())}),pe=n.useCallback((S,$,X)=>{const F=!_.current&&!X;(w.value!==void 0&&w.value===$||F)&&(Y(S),F&&(_.current=!0))},[w.value]),ee=n.useCallback(()=>b==null?void 0:b.focus(),[b]),fe=n.useCallback((S,$,X)=>{const F=!_.current&&!X;(w.value!==void 0&&w.value===$||F)&&O(S)},[w.value]),ne=r==="popper"?ot:js,te=ne===ot?{side:c,sideOffset:d,align:f,alignOffset:g,arrowPadding:u,collisionBoundary:m,collisionPadding:p,sticky:x,hideWhenDetached:h,avoidCollisions:v}:{};return e.jsx(bs,{scope:o,content:b,viewport:N,onViewportChange:I,itemRefCallback:pe,selectedItem:U,onItemLeave:ee,itemTextRefCallback:fe,focusSelectedItem:L,selectedItemText:Z,position:r,isPositioned:P,searchRef:de,children:e.jsx(Gt,{as:Vn,allowPinchZoom:!0,children:e.jsx(vt,{asChild:!0,trapped:w.open,onMountAutoFocus:S=>{S.preventDefault()},onUnmountAutoFocus:V(l,S=>{var $;($=w.trigger)==null||$.focus({preventScroll:!0}),S.preventDefault()}),children:e.jsx(os,{asChild:!0,disableOutsidePointerEvents:!0,onEscapeKeyDown:a,onPointerDownOutside:i,onFocusOutside:S=>S.preventDefault(),onDismiss:()=>w.onOpenChange(!1),children:e.jsx(ne,{role:"listbox",id:w.contentId,"data-state":w.open?"open":"closed",dir:w.dir,onContextMenu:S=>S.preventDefault(),...j,...te,onPlaced:()=>q(!0),ref:T,style:{display:"flex",flexDirection:"column",outline:"none",...j.style},onKeyDown:V(j.onKeyDown,S=>{const $=S.ctrlKey||S.altKey||S.metaKey;if(S.key==="Tab"&&S.preventDefault(),!$&&S.key.length===1&&ue(S.key),["ArrowUp","ArrowDown","Home","End"].includes(S.key)){let F=C().filter(D=>!D.disabled).map(D=>D.ref.current);if(["ArrowUp","End"].includes(S.key)&&(F=F.slice().reverse()),["ArrowUp","ArrowDown"].includes(S.key)){const D=S.target,A=F.indexOf(D);F=F.slice(A+1)}setTimeout(()=>k(F)),S.preventDefault()}})})})})})})});ys.displayName=Bn;var Wn="SelectItemAlignedPosition",js=n.forwardRef((t,s)=>{const{__scopeSelect:o,onPlaced:r,...l}=t,a=we(je,o),i=be(je,o),[c,d]=n.useState(null),[f,g]=n.useState(null),u=J(s,T=>g(T)),m=Ue(o),p=n.useRef(!1),x=n.useRef(!0),{viewport:h,selectedItem:v,selectedItemText:j,focusSelectedItem:w}=i,b=n.useCallback(()=>{if(a.trigger&&a.valueNode&&c&&f&&h&&v&&j){const T=a.trigger.getBoundingClientRect(),U=f.getBoundingClientRect(),Y=a.valueNode.getBoundingClientRect(),Z=j.getBoundingClientRect();if(a.dir!=="rtl"){const D=Z.left-U.left,A=Y.left-D,le=T.left-A,ce=T.width+le,Ce=Math.max(ce,U.width),y=window.innerWidth-re,B=It(A,[re,Math.max(re,y-Ce)]);c.style.minWidth=ce+"px",c.style.left=B+"px"}else{const D=U.right-Z.right,A=window.innerWidth-Y.right-D,le=window.innerWidth-T.right-A,ce=T.width+le,Ce=Math.max(ce,U.width),y=window.innerWidth-re,B=It(A,[re,Math.max(re,y-Ce)]);c.style.minWidth=ce+"px",c.style.right=B+"px"}const O=m(),C=window.innerHeight-re*2,P=h.scrollHeight,q=window.getComputedStyle(f),_=parseInt(q.borderTopWidth,10),k=parseInt(q.paddingTop,10),L=parseInt(q.borderBottomWidth,10),H=parseInt(q.paddingBottom,10),K=_+k+P+H+L,de=Math.min(v.offsetHeight*5,K),ue=window.getComputedStyle(h),pe=parseInt(ue.paddingTop,10),ee=parseInt(ue.paddingBottom,10),fe=T.top+T.height/2-re,ne=C-fe,te=v.offsetHeight/2,S=v.offsetTop+te,$=_+k+S,X=K-$;if($<=fe){const D=O.length>0&&v===O[O.length-1].ref.current;c.style.bottom="0px";const A=f.clientHeight-h.offsetTop-h.offsetHeight,le=Math.max(ne,te+(D?ee:0)+A+L),ce=$+le;c.style.height=ce+"px"}else{const D=O.length>0&&v===O[0].ref.current;c.style.top="0px";const le=Math.max(fe,_+h.offsetTop+(D?pe:0)+te)+X;c.style.height=le+"px",h.scrollTop=$-fe+h.offsetTop}c.style.margin=`${re}px 0`,c.style.minHeight=de+"px",c.style.maxHeight=C+"px",r==null||r(),requestAnimationFrame(()=>p.current=!0)}},[m,a.trigger,a.valueNode,c,f,h,v,j,a.dir,r]);he(()=>b(),[b]);const[R,N]=n.useState();he(()=>{f&&N(window.getComputedStyle(f).zIndex)},[f]);const I=n.useCallback(T=>{T&&x.current===!0&&(b(),w==null||w(),x.current=!1)},[b,w]);return e.jsx(Un,{scope:o,contentWrapper:c,shouldExpandOnScrollRef:p,onScrollButtonChange:I,children:e.jsx("div",{ref:d,style:{display:"flex",flexDirection:"column",position:"fixed",zIndex:R},children:e.jsx(z.div,{...l,ref:u,style:{boxSizing:"border-box",maxHeight:"100%",...l.style}})})})});js.displayName=Wn;var zn="SelectPopperPosition",ot=n.forwardRef((t,s)=>{const{__scopeSelect:o,align:r="start",collisionPadding:l=re,...a}=t,i=Ke(o);return e.jsx(Ko,{...i,...a,ref:s,align:r,collisionPadding:l,style:{boxSizing:"border-box",...a.style,"--radix-select-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-select-content-available-width":"var(--radix-popper-available-width)","--radix-select-content-available-height":"var(--radix-popper-available-height)","--radix-select-trigger-width":"var(--radix-popper-anchor-width)","--radix-select-trigger-height":"var(--radix-popper-anchor-height)"}})});ot.displayName=zn;var[Un,wt]=_e(je,{}),nt="SelectViewport",Ns=n.forwardRef((t,s)=>{const{__scopeSelect:o,nonce:r,...l}=t,a=be(nt,o),i=wt(nt,o),c=J(s,a.onViewportChange),d=n.useRef(0);return e.jsxs(e.Fragment,{children:[e.jsx("style",{dangerouslySetInnerHTML:{__html:"[data-radix-select-viewport]{scrollbar-width:none;-ms-overflow-style:none;-webkit-overflow-scrolling:touch;}[data-radix-select-viewport]::-webkit-scrollbar{display:none}"},nonce:r}),e.jsx(ze.Slot,{scope:o,children:e.jsx(z.div,{"data-radix-select-viewport":"",role:"presentation",...l,ref:c,style:{position:"relative",flex:1,overflow:"hidden auto",...l.style},onScroll:V(l.onScroll,f=>{const g=f.currentTarget,{contentWrapper:u,shouldExpandOnScrollRef:m}=i;if(m!=null&&m.current&&u){const p=Math.abs(d.current-g.scrollTop);if(p>0){const x=window.innerHeight-re*2,h=parseFloat(u.style.minHeight),v=parseFloat(u.style.height),j=Math.max(h,v);if(j<x){const w=j+p,b=Math.min(x,w),R=w-b;u.style.height=b+"px",u.style.bottom==="0px"&&(g.scrollTop=R>0?R:0,u.style.justifyContent="flex-end")}}}d.current=g.scrollTop})})})]})});Ns.displayName=nt;var Ss="SelectGroup",[Kn,Gn]=_e(Ss),qn=n.forwardRef((t,s)=>{const{__scopeSelect:o,...r}=t,l=Te();return e.jsx(Kn,{scope:o,id:l,children:e.jsx(z.div,{role:"group","aria-labelledby":l,...r,ref:s})})});qn.displayName=Ss;var Cs="SelectLabel",ks=n.forwardRef((t,s)=>{const{__scopeSelect:o,...r}=t,l=Gn(Cs,o);return e.jsx(z.div,{id:l.id,...r,ref:s})});ks.displayName=Cs;var Fe="SelectItem",[Yn,Rs]=_e(Fe),Is=n.forwardRef((t,s)=>{const{__scopeSelect:o,value:r,disabled:l=!1,textValue:a,...i}=t,c=we(Fe,o),d=be(Fe,o),f=c.value===r,[g,u]=n.useState(a??""),[m,p]=n.useState(!1),x=J(s,w=>{var b;return(b=d.itemRefCallback)==null?void 0:b.call(d,w,r,l)}),h=Te(),v=n.useRef("touch"),j=()=>{l||(c.onValueChange(r),c.onOpenChange(!1))};if(r==="")throw new Error("A <Select.Item /> must have a value prop that is not an empty string. This is because the Select value can be set to an empty string to clear the selection and show the placeholder.");return e.jsx(Yn,{scope:o,value:r,disabled:l,textId:h,isSelected:f,onItemTextChange:n.useCallback(w=>{u(b=>b||((w==null?void 0:w.textContent)??"").trim())},[]),children:e.jsx(ze.ItemSlot,{scope:o,value:r,disabled:l,textValue:g,children:e.jsx(z.div,{role:"option","aria-labelledby":h,"data-highlighted":m?"":void 0,"aria-selected":f&&m,"data-state":f?"checked":"unchecked","aria-disabled":l||void 0,"data-disabled":l?"":void 0,tabIndex:l?void 0:-1,...i,ref:x,onFocus:V(i.onFocus,()=>p(!0)),onBlur:V(i.onBlur,()=>p(!1)),onClick:V(i.onClick,()=>{v.current!=="mouse"&&j()}),onPointerUp:V(i.onPointerUp,()=>{v.current==="mouse"&&j()}),onPointerDown:V(i.onPointerDown,w=>{v.current=w.pointerType}),onPointerMove:V(i.onPointerMove,w=>{var b;v.current=w.pointerType,l?(b=d.onItemLeave)==null||b.call(d):v.current==="mouse"&&w.currentTarget.focus({preventScroll:!0})}),onPointerLeave:V(i.onPointerLeave,w=>{var b;w.currentTarget===document.activeElement&&((b=d.onItemLeave)==null||b.call(d))}),onKeyDown:V(i.onKeyDown,w=>{var R;((R=d.searchRef)==null?void 0:R.current)!==""&&w.key===" "||(An.includes(w.key)&&j(),w.key===" "&&w.preventDefault())})})})})});Is.displayName=Fe;var Me="SelectItemText",Ts=n.forwardRef((t,s)=>{const{__scopeSelect:o,className:r,style:l,...a}=t,i=we(Me,o),c=be(Me,o),d=Rs(Me,o),f=Fn(Me,o),[g,u]=n.useState(null),m=J(s,j=>u(j),d.onItemTextChange,j=>{var w;return(w=c.itemTextRefCallback)==null?void 0:w.call(c,j,d.value,d.disabled)}),p=g==null?void 0:g.textContent,x=n.useMemo(()=>e.jsx("option",{value:d.value,disabled:d.disabled,children:p},d.value),[d.disabled,d.value,p]),{onNativeOptionAdd:h,onNativeOptionRemove:v}=f;return he(()=>(h(x),()=>v(x)),[h,v,x]),e.jsxs(e.Fragment,{children:[e.jsx(z.span,{id:d.textId,...a,ref:m}),d.isSelected&&i.valueNode&&!i.valueNodeHasChildren?Lt.createPortal(a.children,i.valueNode):null]})});Ts.displayName=Me;var Es="SelectItemIndicator",Ps=n.forwardRef((t,s)=>{const{__scopeSelect:o,...r}=t;return Rs(Es,o).isSelected?e.jsx(z.span,{"aria-hidden":!0,...r,ref:s}):null});Ps.displayName=Es;var rt="SelectScrollUpButton",_s=n.forwardRef((t,s)=>{const o=be(rt,t.__scopeSelect),r=wt(rt,t.__scopeSelect),[l,a]=n.useState(!1),i=J(s,r.onScrollButtonChange);return he(()=>{if(o.viewport&&o.isPositioned){let c=function(){const f=d.scrollTop>0;a(f)};const d=o.viewport;return c(),d.addEventListener("scroll",c),()=>d.removeEventListener("scroll",c)}},[o.viewport,o.isPositioned]),l?e.jsx(As,{...t,ref:i,onAutoScroll:()=>{const{viewport:c,selectedItem:d}=o;c&&d&&(c.scrollTop=c.scrollTop-d.offsetHeight)}}):null});_s.displayName=rt;var at="SelectScrollDownButton",Ms=n.forwardRef((t,s)=>{const o=be(at,t.__scopeSelect),r=wt(at,t.__scopeSelect),[l,a]=n.useState(!1),i=J(s,r.onScrollButtonChange);return he(()=>{if(o.viewport&&o.isPositioned){let c=function(){const f=d.scrollHeight-d.clientHeight,g=Math.ceil(d.scrollTop)<f;a(g)};const d=o.viewport;return c(),d.addEventListener("scroll",c),()=>d.removeEventListener("scroll",c)}},[o.viewport,o.isPositioned]),l?e.jsx(As,{...t,ref:i,onAutoScroll:()=>{const{viewport:c,selectedItem:d}=o;c&&d&&(c.scrollTop=c.scrollTop+d.offsetHeight)}}):null});Ms.displayName=at;var As=n.forwardRef((t,s)=>{const{__scopeSelect:o,onAutoScroll:r,...l}=t,a=be("SelectScrollButton",o),i=n.useRef(null),c=Ue(o),d=n.useCallback(()=>{i.current!==null&&(window.clearInterval(i.current),i.current=null)},[]);return n.useEffect(()=>()=>d(),[d]),he(()=>{var g;const f=c().find(u=>u.ref.current===document.activeElement);(g=f==null?void 0:f.ref.current)==null||g.scrollIntoView({block:"nearest"})},[c]),e.jsx(z.div,{"aria-hidden":!0,...l,ref:s,style:{flexShrink:0,...l.style},onPointerDown:V(l.onPointerDown,()=>{i.current===null&&(i.current=window.setInterval(r,50))}),onPointerMove:V(l.onPointerMove,()=>{var f;(f=a.onItemLeave)==null||f.call(a),i.current===null&&(i.current=window.setInterval(r,50))}),onPointerLeave:V(l.onPointerLeave,()=>{d()})})}),Zn="SelectSeparator",Ds=n.forwardRef((t,s)=>{const{__scopeSelect:o,...r}=t;return e.jsx(z.div,{"aria-hidden":!0,...r,ref:s})});Ds.displayName=Zn;var lt="SelectArrow",Xn=n.forwardRef((t,s)=>{const{__scopeSelect:o,...r}=t,l=Ke(o),a=we(lt,o),i=be(lt,o);return a.open&&i.position==="popper"?e.jsx(Yo,{...l,...r,ref:s}):null});Xn.displayName=lt;var Jn="SelectBubbleInput",Os=n.forwardRef(({__scopeSelect:t,value:s,...o},r)=>{const l=n.useRef(null),a=J(r,l),i=_n(s);return n.useEffect(()=>{const c=l.current;if(!c)return;const d=window.HTMLSelectElement.prototype,g=Object.getOwnPropertyDescriptor(d,"value").set;if(i!==s&&g){const u=new Event("change",{bubbles:!0});g.call(c,s),c.dispatchEvent(u)}},[i,s]),e.jsx(z.select,{...o,style:{...qo,...o.style},ref:a,defaultValue:s})});Os.displayName=Jn;function Ls(t){return t===""||t===void 0}function Fs(t){const s=tt(t),o=n.useRef(""),r=n.useRef(0),l=n.useCallback(i=>{const c=o.current+i;s(c),(function d(f){o.current=f,window.clearTimeout(r.current),f!==""&&(r.current=window.setTimeout(()=>d(""),1e3))})(c)},[s]),a=n.useCallback(()=>{o.current="",window.clearTimeout(r.current)},[]);return n.useEffect(()=>()=>window.clearTimeout(r.current),[]),[o,l,a]}function Hs(t,s,o){const l=s.length>1&&Array.from(s).every(f=>f===s[0])?s[0]:s,a=o?t.indexOf(o):-1;let i=Qn(t,Math.max(a,0));l.length===1&&(i=i.filter(f=>f!==o));const d=i.find(f=>f.textValue.toLowerCase().startsWith(l.toLowerCase()));return d!==o?d:void 0}function Qn(t,s){return t.map((o,r)=>t[(s+r)%t.length])}var er=fs,$s=ps,tr=xs,sr=gs,or=vs,Bs=ws,nr=Ns,Vs=ks,Ws=Is,rr=Ts,ar=Ps,zs=_s,Us=Ms,Ks=Ds;const At=er,Dt=tr,ct=n.forwardRef(({className:t,children:s,...o},r)=>e.jsxs($s,{ref:r,className:E("flex h-10 w-full items-center justify-between rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 [&>span]:line-clamp-1",t),...o,children:[s,e.jsx(sr,{asChild:!0,children:e.jsx(qt,{className:"h-4 w-4 opacity-50"})})]}));ct.displayName=$s.displayName;const Gs=n.forwardRef(({className:t,...s},o)=>e.jsx(zs,{ref:o,className:E("flex cursor-default items-center justify-center py-1",t),...s,children:e.jsx(Co,{className:"h-4 w-4"})}));Gs.displayName=zs.displayName;const qs=n.forwardRef(({className:t,...s},o)=>e.jsx(Us,{ref:o,className:E("flex cursor-default items-center justify-center py-1",t),...s,children:e.jsx(qt,{className:"h-4 w-4"})}));qs.displayName=Us.displayName;const it=n.forwardRef(({className:t,children:s,position:o="popper",...r},l)=>e.jsx(or,{children:e.jsxs(Bs,{ref:l,className:E("relative z-50 max-h-96 min-w-[8rem] overflow-hidden rounded-md border bg-popover text-popover-foreground shadow-md data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",o==="popper"&&"data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1",t),position:o,...r,children:[e.jsx(Gs,{}),e.jsx(nr,{className:E("p-1",o==="popper"&&"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]"),children:s}),e.jsx(qs,{})]})}));it.displayName=Bs.displayName;const lr=n.forwardRef(({className:t,...s},o)=>e.jsx(Vs,{ref:o,className:E("py-1.5 pl-8 pr-2 text-sm font-semibold",t),...s}));lr.displayName=Vs.displayName;const Ae=n.forwardRef(({className:t,children:s,...o},r)=>e.jsxs(Ws,{ref:r,className:E("relative flex w-full cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",t),...o,children:[e.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:e.jsx(ar,{children:e.jsx(Yt,{className:"h-4 w-4"})})}),e.jsx(rr,{children:s})]}));Ae.displayName=Ws.displayName;const cr=n.forwardRef(({className:t,...s},o)=>e.jsx(Ks,{ref:o,className:E("-mx-1 my-1 h-px bg-muted",t),...s}));cr.displayName=Ks.displayName;function ir({getItemId:t}){const[s,o]=n.useState(new Set),r=n.useCallback(p=>s.has(t(p)),[s,t]),l=n.useCallback(p=>{const x=t(p);o(h=>{const v=new Set(h);return v.has(x)?v.delete(x):v.add(x),v})},[t]),a=n.useCallback(p=>{o(new Set(p.map(t)))},[t]),i=n.useCallback(()=>{o(new Set)},[]),c=n.useCallback(p=>p.length===0?!1:p.every(x=>s.has(t(x))),[s,t]),d=n.useCallback(p=>{if(p.length===0)return!1;const x=p.some(v=>s.has(t(v))),h=p.every(v=>s.has(t(v)));return x&&!h},[s,t]),f=n.useCallback(p=>{c(p)?i():a(p)},[c,i,a]),g=n.useCallback(p=>{o(x=>{const h=new Set(x);return h.add(p),h})},[]),u=n.useCallback(p=>{o(x=>{const h=new Set(x);return h.delete(p),h})},[]),m=s.size;return n.useMemo(()=>({selectedIds:s,isSelected:r,toggleSelection:l,selectAll:a,clearSelection:i,toggleSelectAll:f,selectionCount:m,isAllSelected:c,isSomeSelected:d,selectById:g,deselectById:u}),[s,r,l,a,i,f,m,c,d,g,u])}function dr({selectionCount:t,onClearSelection:s,actions:o,itemLabel:r="items",className:l}){if(t===0)return null;const a=t===1?r.replace(/s$/,""):r;return e.jsxs("div",{className:E("fixed bottom-6 left-1/2 -translate-x-1/2 z-50","flex items-center gap-3 px-4 py-2.5 rounded-lg","bg-primary text-primary-foreground shadow-lg","animate-in fade-in slide-in-from-bottom-4 duration-200",l),children:[e.jsxs("span",{className:"text-sm font-medium",children:[t," ",a," selected"]}),o&&e.jsx("div",{className:"flex items-center gap-2 border-l border-primary-foreground/20 pl-3",children:o}),e.jsxs(oe,{variant:"ghost",size:"sm",className:"h-7 px-2 text-primary-foreground hover:bg-primary-foreground/10 hover:text-primary-foreground",onClick:s,children:[e.jsx(Zt,{className:"h-4 w-4"}),e.jsx("span",{className:"sr-only",children:"Clear selection"})]})]})}function ur(t){const s=n.useRef({value:t,previous:t});return n.useMemo(()=>(s.current.value!==t&&(s.current.previous=s.current.value,s.current.value=t),s.current.previous),[t])}var bt="Checkbox",[fr]=Ro(bt),[hr,pr]=fr(bt),Ys=n.forwardRef((t,s)=>{const{__scopeCheckbox:o,name:r,checked:l,defaultChecked:a,required:i,disabled:c,value:d="on",onCheckedChange:f,form:g,...u}=t,[m,p]=n.useState(null),x=Zo(s,R=>p(R)),h=n.useRef(!1),v=m?g||!!m.closest("form"):!0,[j=!1,w]=ko({prop:l,defaultProp:a,onChange:f}),b=n.useRef(j);return n.useEffect(()=>{const R=m==null?void 0:m.form;if(R){const N=()=>w(b.current);return R.addEventListener("reset",N),()=>R.removeEventListener("reset",N)}},[m,w]),e.jsxs(hr,{scope:o,state:j,disabled:c,children:[e.jsx(Xt.button,{type:"button",role:"checkbox","aria-checked":ve(j)?"mixed":j,"aria-required":i,"data-state":Js(j),"data-disabled":c?"":void 0,disabled:c,value:d,...u,ref:x,onKeyDown:St(t.onKeyDown,R=>{R.key==="Enter"&&R.preventDefault()}),onClick:St(t.onClick,R=>{w(N=>ve(N)?!0:!N),v&&(h.current=R.isPropagationStopped(),h.current||R.stopPropagation())})}),v&&e.jsx(mr,{control:m,bubbles:!h.current,name:r,value:d,checked:j,required:i,disabled:c,form:g,style:{transform:"translateX(-100%)"},defaultChecked:ve(a)?!1:a})]})});Ys.displayName=bt;var Zs="CheckboxIndicator",Xs=n.forwardRef((t,s)=>{const{__scopeCheckbox:o,forceMount:r,...l}=t,a=pr(Zs,o);return e.jsx(Io,{present:r||ve(a.state)||a.state===!0,children:e.jsx(Xt.span,{"data-state":Js(a.state),"data-disabled":a.disabled?"":void 0,...l,ref:s,style:{pointerEvents:"none",...t.style}})})});Xs.displayName=Zs;var mr=t=>{const{control:s,checked:o,bubbles:r=!0,defaultChecked:l,...a}=t,i=n.useRef(null),c=ur(o),d=To(s);n.useEffect(()=>{const g=i.current,u=window.HTMLInputElement.prototype,p=Object.getOwnPropertyDescriptor(u,"checked").set;if(c!==o&&p){const x=new Event("click",{bubbles:r});g.indeterminate=ve(o),p.call(g,ve(o)?!1:o),g.dispatchEvent(x)}},[c,o,r]);const f=n.useRef(ve(o)?!1:o);return e.jsx("input",{type:"checkbox","aria-hidden":!0,defaultChecked:l??f.current,...a,tabIndex:-1,ref:i,style:{...t.style,...d,position:"absolute",pointerEvents:"none",opacity:0,margin:0}})};function ve(t){return t==="indeterminate"}function Js(t){return ve(t)?"indeterminate":t?"checked":"unchecked"}var xr=Ys,gr=Xs;const dt=n.forwardRef(({className:t,checked:s,indeterminate:o,onCheckedChange:r,...l},a)=>{const i=n.useId(),c=l.id??i,d=o?"indeterminate":s??!1;return e.jsx("label",{htmlFor:c,className:"p-2 -m-2 inline-flex items-center justify-center cursor-pointer",onClick:f=>f.stopPropagation(),onKeyDown:f=>f.stopPropagation(),children:e.jsx(xr,{ref:a,id:c,checked:d,onCheckedChange:f=>{r==null||r(f===!0)},className:E("peer h-4 w-4 shrink-0 rounded-sm border border-primary shadow","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background","disabled:cursor-not-allowed disabled:opacity-50","data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground","data-[state=indeterminate]:bg-primary data-[state=indeterminate]:text-primary-foreground",t),...l,children:e.jsx(gr,{className:"flex items-center justify-center text-current",children:o?e.jsx(dn,{className:"h-3.5 w-3.5"}):e.jsx(Yt,{className:"h-3.5 w-3.5"})})})})});dt.displayName="Checkbox";function vr({env:t,runId:s,runStatus:o,onSuccess:r}){const[l,a]=n.useState(void 0),[i,c]=n.useState(!0),[d,f]=n.useState(void 0),g=(d==null?void 0:d.status)||o;return n.useEffect(()=>{c(!0),Promise.all([Xo(t,s,"none"),Qt(t,s,{limit:1e3,sortOrder:"desc"})]).then(([u,m])=>{u.success&&f(u.data),m.success&&a(m.data.data)}).catch(u=>{console.error("Failed to fetch run or events:",u)}).finally(()=>{c(!1)})},[t,s]),e.jsx(Do,{env:t,runId:s,runStatus:g,events:l,eventsLoading:i,stopPropagation:!0,callbacks:{onSuccess:r}})}function wr({env:t,runId:s,runStatus:o,onSuccess:r}){const[l,a]=n.useState(!1);return e.jsxs(Bt,{open:l,onOpenChange:a,children:[e.jsx(Vt,{asChild:!0,children:e.jsx(oe,{variant:"ghost",size:"icon",className:"h-8 w-8",onClick:i=>i.stopPropagation(),children:e.jsx(Wt,{className:"h-4 w-4"})})}),l&&e.jsx(zt,{align:"end",children:e.jsx(vr,{env:t,runId:s,runStatus:o,onSuccess:r})})]})}const Qs={pending:{label:"Pending",color:"bg-neutral-600 dark:bg-neutral-400"},running:{label:"Running",color:"bg-blue-600 dark:bg-blue-400"},completed:{label:"Completed",color:"bg-green-600 dark:bg-green-400"},failed:{label:"Failed",color:"bg-red-600 dark:bg-red-400"},cancelled:{label:"Cancelled",color:"bg-gray-600 dark:bg-gray-400"}};function br(){const t=ut(),{pathname:s}=Ft(),[o]=$e();return n.useCallback(r=>{const l=new URLSearchParams(o.toString());r==="all"?(l.delete("workflow"),l.delete("status")):l.set("workflow",r),t(`${s}?${l.toString()}`)},[t,s,o])}function yr(){const t=ut(),{pathname:s}=Ft(),[o]=$e();return n.useCallback(r=>{const l=new URLSearchParams(o.toString());r==="all"?l.delete("status"):l.set("status",r),t(`${s}?${l.toString()}`)},[t,s,o])}function jr({workflowNameFilter:t,status:s,seenWorkflowNames:o,sortOrder:r,loading:l,statusFilterRequiresWorkflowNameFilter:a,onWorkflowChange:i,onStatusChange:c,onSortToggle:d,onRefresh:f,lastRefreshTime:g}){return e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-end gap-2",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Last refreshed"}),g&&e.jsx(Oe,{date:g,className:"text-sm text-muted-foreground",type:"distance"})]}),e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsxs(At,{value:t??"all",onValueChange:i,disabled:l,children:[e.jsx(ct,{className:"w-[180px] h-9",children:e.jsx(Dt,{placeholder:"Filter by workflow"})}),e.jsxs(it,{children:[e.jsx(Ae,{value:"all",children:"All Workflows"}),Array.from(o).sort().map(u=>{var m;return e.jsx(Ae,{value:u,children:((m=Jt(u))==null?void 0:m.shortName)||u},u)})]})]}),e.jsxs(ke,{children:[e.jsx(Re,{asChild:!0,children:e.jsx("div",{children:e.jsxs(At,{value:s||"all",onValueChange:c,disabled:l||a&&!t,children:[e.jsx(ct,{className:"w-[140px] h-9",children:e.jsx(Dt,{placeholder:"Filter by status"})}),e.jsxs(it,{children:[e.jsx(Ae,{value:"all",children:"Any status"}),Object.entries(Qs).map(([u,{label:m,color:p}])=>e.jsx(Ae,{value:u,children:e.jsxs("div",{className:"flex items-center",children:[e.jsx("span",{className:`${p} size-1.5 rounded-full mr-2`}),m]})},u))]})]})})}),e.jsx(Ie,{children:a&&t==="all"?"Select a workflow first to filter by status":"Filter runs by status"})]}),e.jsxs(ke,{children:[e.jsx(Re,{asChild:!0,children:e.jsxs(oe,{variant:"outline",size:"sm",onClick:d,disabled:l,children:[r==="desc"?e.jsx(on,{className:"h-4 w-4"}):e.jsx(rn,{className:"h-4 w-4"}),r==="desc"?"Newest":"Oldest"]})}),e.jsx(Ie,{children:r==="desc"?"Showing newest first":"Showing oldest first"})]}),e.jsxs(ke,{children:[e.jsx(Re,{asChild:!0,children:e.jsxs(oe,{variant:"outline",size:"sm",onClick:f,disabled:l,children:[e.jsx(as,{className:l?"animate-spin":""}),"Refresh"]})}),e.jsx(Ie,{children:"Note that this resets pages"})]})]})]})}function Nr({onRunClick:t}){var A,le,ce,Ce;const[s]=$e(),o=br(),r=yr(),{serverConfig:l}=ns(),a=s.get("status"),i=Object.keys(Qs),c=a==="all"||a&&i.includes(a)?a:void 0,d=s.get("workflow"),[f,g]=n.useState("desc"),[u,m]=n.useState(()=>new Date),[p,x]=n.useState(!1),h=n.useMemo(()=>({}),[]),v=l.backendId==="local"||l.backendId==="@workflow/world-local",j=(A=l.displayInfo)==null?void 0:A["local.dataDirPath"],w=(le=l.displayInfo)==null?void 0:le["local.shortName"],b=((ce=l.backendId)==null?void 0:ce.includes("vercel"))||!1,[R,N]=n.useState(new Set),{data:I,error:T,nextPage:U,previousPage:Y,hasNextPage:Z,hasPreviousPage:O,reload:C,refresh:P,pageInfo:q}=jn(h,{sortOrder:f,workflowName:d==="all"?void 0:d,status:c==="all"?void 0:c}),_=ir({getItemId:y=>y.runId}),k=I.data??[],[L,H]=n.useState(!1),[K,de]=n.useState(!1),ue=v&&(!j||!((Ce=I==null?void 0:I.data)!=null&&Ce.length));n.useEffect(()=>{if(I.data&&I.data.length>0){const y=new Set(I.data.map(B=>B.workflowName));N(B=>{const se=new Set(B);for(const Q of y)se.add(Q);return se})}},[I.data]);const pe=I.isLoading;n.useEffect(()=>{!pe&&!p&&x(!0)},[pe,p]),n.useEffect(()=>{x(!1)},[d,c,f]);const ee=n.useCallback(()=>{m(()=>new Date),x(!1),C()},[C]),fe=n.useCallback(()=>{m(()=>new Date),P()},[P]),ne=n.useMemo(()=>k.filter(y=>_.selectedIds.has(y.runId)),[k,_.selectedIds]),te=n.useMemo(()=>ne.filter(y=>y.status==="pending"||y.status==="running"),[ne]),S=te.length>0,$=n.useCallback(async()=>{if(!(L||te.length===0)){H(!0);try{const y=await Promise.allSettled(te.map(Q=>Eo(h,Q.runId))),B=y.filter(Q=>Q.status==="fulfilled").length,se=y.filter(Q=>Q.status==="rejected").length;se===0?me.success(`Cancelled ${B} run${B!==1?"s":""}`):B===0?me.error(`Failed to cancel ${se} run${se!==1?"s":""}`):me.warning(`Cancelled ${B} run${B!==1?"s":""}, ${se} failed`),_.clearSelection(),ee()}catch(y){me.error("Failed to cancel runs",{description:y instanceof Error?y.message:"Unknown error"})}finally{H(!1)}}},[h,te,L,_,ee]),X=n.useCallback(async()=>{if(!(K||ne.length===0)){de(!0);try{const y=await Promise.allSettled(ne.map(Q=>Po(h,Q.runId))),B=y.filter(Q=>Q.status==="fulfilled").length,se=y.filter(Q=>Q.status==="rejected").length;se===0?me.success(`Re-enqueued ${B} run${B!==1?"s":""}`):B===0?me.error(`Failed to re-enqueue ${se} run${se!==1?"s":""}`):me.warning(`Re-enqueued ${B} run${B!==1?"s":""}, ${se} failed`),_.clearSelection(),ee()}catch(y){me.error("Failed to re-enqueue runs",{description:y instanceof Error?y.message:"Unknown error"})}finally{de(!1)}}},[h,ne,K,_,ee]),F=()=>{g(y=>y==="desc"?"asc":"desc")};n.useEffect(()=>{if(ue){const y=setInterval(()=>{fe()},5e3);return()=>clearInterval(y)}},[ue,fe]),n.useEffect(()=>{const y=()=>{document.visibilityState==="visible"&&u&&Date.now()-u.getTime()>=1e4&&ee()};return document.addEventListener("visibilitychange",y),()=>{document.removeEventListener("visibilitychange",y)}},[u,ee]);const D=e.jsx("code",{className:"font-mono",children:w||"current directory"});return e.jsxs("div",{children:[e.jsx(jr,{workflowNameFilter:d,status:c,seenWorkflowNames:R,sortOrder:f,loading:pe,statusFilterRequiresWorkflowNameFilter:b,onWorkflowChange:o,onStatusChange:r,onSortToggle:F,onRefresh:ee,lastRefreshTime:u}),e.jsx(Ee,{className:"overflow-hidden mt-4 bg-background",children:e.jsx(Pe,{className:"p-0 max-h-[calc(100vh-280px)] overflow-auto",children:e.jsxs(Be,{children:[e.jsx(Ve,{children:e.jsxs(ie,{children:[e.jsx(G,{className:"sticky top-0 bg-background z-10 border-b shadow-sm h-10 w-10",children:e.jsx(dt,{checked:_.isAllSelected(k),indeterminate:_.isSomeSelected(k),onCheckedChange:()=>_.toggleSelectAll(k),"aria-label":"Select all runs",disabled:!k.length})}),e.jsx(G,{className:"sticky top-0 bg-background z-10 border-b shadow-sm h-10",children:"Workflow"}),e.jsx(G,{className:"sticky top-0 bg-background z-10 border-b shadow-sm h-10",children:"Run ID"}),e.jsx(G,{className:"sticky top-0 bg-background z-10 border-b shadow-sm h-10",children:"Status"}),e.jsx(G,{className:"sticky top-0 bg-background z-10 border-b shadow-sm h-10",children:"Started"}),e.jsx(G,{className:"sticky top-0 bg-background z-10 border-b shadow-sm h-10",children:"Completed"}),e.jsx(G,{className:"sticky top-0 bg-background z-10 border-b shadow-sm h-10 w-10"})]})}),e.jsx(We,{children:T?e.jsx(ie,{children:e.jsx(W,{colSpan:7,className:"h-[400px]",children:e.jsx("div",{className:"flex items-center justify-center h-full",children:e.jsxs(ft,{variant:"destructive",className:"max-w-md",children:[e.jsx(ht,{className:"h-4 w-4"}),e.jsx(pt,{children:"Error loading runs"}),e.jsx(mt,{children:$t(T)})]})})})}):pe&&!p?e.jsx(ie,{children:e.jsx(W,{colSpan:7,className:"h-[400px]",children:e.jsx("div",{className:"flex items-center justify-center h-full",children:e.jsx(Xe,{className:"h-8 w-8 animate-spin text-muted-foreground"})})})}):!I.data||I.data.length===0?e.jsx(ie,{children:e.jsx(W,{colSpan:7,className:"h-[400px]",children:e.jsxs("div",{className:"text-sm text-center text-muted-foreground flex flex-col items-center justify-center gap-3 h-full",children:[e.jsxs("span",{className:"text-sm",children:["No workflow runs found",ue?e.jsxs(e.Fragment,{children:[" in ",D]}):"","."]}),ue&&e.jsx("span",{className:"text-sm flex items-center gap-2",children:"This view will update once you run a workflow."})]})})}):k.map(y=>{var B;return e.jsxs(ie,{className:"cursor-pointer group relative",onClick:()=>t(y.runId),"data-selected":_.isSelected(y),children:[e.jsx(W,{className:"py-2",children:e.jsx(dt,{checked:_.isSelected(y),onCheckedChange:()=>_.toggleSelection(y),"aria-label":`Select run ${y.runId}`})}),e.jsx(W,{className:"py-2",children:e.jsx(De,{text:y.workflowName,overlay:!0,children:((B=Jt(y.workflowName))==null?void 0:B.shortName)||"?"})}),e.jsx(W,{className:"font-mono text-xs py-2",children:e.jsx(De,{text:y.runId,overlay:!0,children:y.runId})}),e.jsx(W,{className:"py-2",children:e.jsx(_o,{status:y.status,context:y,durationMs:y.startedAt?(y.completedAt?new Date(y.completedAt).getTime():Date.now())-new Date(y.startedAt).getTime():void 0})}),e.jsx(W,{className:"py-2 text-muted-foreground text-xs",children:y.startedAt?e.jsx(Oe,{date:y.startedAt}):"-"}),e.jsx(W,{className:"py-2 text-muted-foreground text-xs",children:y.completedAt?e.jsx(Oe,{date:y.completedAt}):"-"}),e.jsx(W,{className:"py-2",children:e.jsx(wr,{env:h,runId:y.runId,runStatus:y.status,onSuccess:ee})})]},y.runId)})})]})})}),e.jsxs("div",{className:"flex items-center justify-between mt-4",children:[e.jsx("div",{className:"text-sm text-muted-foreground",children:q}),e.jsxs("div",{className:"flex gap-2 items-center",children:[e.jsxs(oe,{variant:"outline",size:"sm",onClick:Y,disabled:!O,children:[e.jsx(rs,{}),"Previous"]}),e.jsxs(oe,{variant:"outline",size:"sm",onClick:U,disabled:!Z,children:["Next",e.jsx(Ut,{})]})]})]}),e.jsx(dr,{selectionCount:_.selectionCount,onClearSelection:_.clearSelection,itemLabel:"runs",actions:e.jsxs(e.Fragment,{children:[e.jsxs(ke,{children:[e.jsx(Re,{asChild:!0,children:e.jsxs(oe,{variant:"ghost",size:"sm",className:"h-7 text-primary-foreground hover:bg-primary-foreground/10 hover:text-primary-foreground",onClick:X,disabled:K||ne.length===0,children:[K?e.jsx(Xe,{className:"h-4 w-4 mr-1 animate-spin"}):e.jsx(Mo,{className:"h-4 w-4 mr-1"}),K?"Re-enqueuing...":"Re-enqueue"]})}),e.jsx(Ie,{children:"Re-enqueue the workflow orchestration layer for selected runs. Useful if workflows appear stuck."})]}),S&&e.jsxs(oe,{variant:"ghost",size:"sm",className:"h-7 text-primary-foreground hover:bg-primary-foreground/10 hover:text-primary-foreground",onClick:$,disabled:L,children:[L?e.jsx(Xe,{className:"h-4 w-4 mr-1 animate-spin"}):e.jsx(Ao,{className:"h-4 w-4 mr-1"}),"Cancel"," ",te.length!==_.selectionCount?`${te.length} `:"",L?"cancelling...":""]})]})})]})}const Sr=Jo("inline-flex items-center rounded-md border px-2.5 py-0.5 text-xs font-semibold transition-colors focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2",{variants:{variant:{default:"border-transparent bg-primary text-primary-foreground shadow hover:bg-primary/80",secondary:"border-transparent bg-secondary text-secondary-foreground hover:bg-secondary/80",destructive:"border-transparent bg-destructive text-destructive-foreground shadow hover:bg-destructive/80",outline:"text-foreground"}},defaultVariants:{variant:"default"}});function Ot({className:t,variant:s,...o}){return e.jsx("div",{className:E(Sr({variant:s}),t),...o})}var Ge="Dialog",[eo]=ts(Ge),[Cr,ae]=eo(Ge),to=t=>{const{__scopeDialog:s,children:o,open:r,defaultOpen:l,onOpenChange:a,modal:i=!0}=t,c=n.useRef(null),d=n.useRef(null),[f,g]=st({prop:r,defaultProp:l??!1,onChange:a,caller:Ge});return e.jsx(Cr,{scope:s,triggerRef:c,contentRef:d,contentId:Te(),titleId:Te(),descriptionId:Te(),open:f,onOpenChange:g,onOpenToggle:n.useCallback(()=>g(u=>!u),[g]),modal:i,children:o})};to.displayName=Ge;var so="DialogTrigger",kr=n.forwardRef((t,s)=>{const{__scopeDialog:o,...r}=t,l=ae(so,o),a=J(s,l.triggerRef);return e.jsx(z.button,{type:"button","aria-haspopup":"dialog","aria-expanded":l.open,"aria-controls":l.contentId,"data-state":Nt(l.open),...r,ref:a,onClick:V(t.onClick,l.onOpenToggle)})});kr.displayName=so;var yt="DialogPortal",[Rr,oo]=eo(yt,{forceMount:void 0}),no=t=>{const{__scopeDialog:s,forceMount:o,children:r,container:l}=t,a=ae(yt,s);return e.jsx(Rr,{scope:s,forceMount:o,children:n.Children.map(r,i=>e.jsx(xt,{present:o||a.open,children:e.jsx(gt,{asChild:!0,container:l,children:i})}))})};no.displayName=yt;var He="DialogOverlay",ro=n.forwardRef((t,s)=>{const o=oo(He,t.__scopeDialog),{forceMount:r=o.forceMount,...l}=t,a=ae(He,t.__scopeDialog);return a.modal?e.jsx(xt,{present:r||a.open,children:e.jsx(Tr,{...l,ref:s})}):null});ro.displayName=He;var Ir=ss("DialogOverlay.RemoveScroll"),Tr=n.forwardRef((t,s)=>{const{__scopeDialog:o,...r}=t,l=ae(He,o);return e.jsx(Gt,{as:Ir,allowPinchZoom:!0,shards:[l.contentRef],children:e.jsx(z.div,{"data-state":Nt(l.open),...r,ref:s,style:{pointerEvents:"auto",...r.style}})})}),Ne="DialogContent",ao=n.forwardRef((t,s)=>{const o=oo(Ne,t.__scopeDialog),{forceMount:r=o.forceMount,...l}=t,a=ae(Ne,t.__scopeDialog);return e.jsx(xt,{present:r||a.open,children:a.modal?e.jsx(Er,{...l,ref:s}):e.jsx(Pr,{...l,ref:s})})});ao.displayName=Ne;var Er=n.forwardRef((t,s)=>{const o=ae(Ne,t.__scopeDialog),r=n.useRef(null),l=J(s,o.contentRef,r);return n.useEffect(()=>{const a=r.current;if(a)return Kt(a)},[]),e.jsx(lo,{...t,ref:l,trapFocus:o.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:V(t.onCloseAutoFocus,a=>{var i;a.preventDefault(),(i=o.triggerRef.current)==null||i.focus()}),onPointerDownOutside:V(t.onPointerDownOutside,a=>{const i=a.detail.originalEvent,c=i.button===0&&i.ctrlKey===!0;(i.button===2||c)&&a.preventDefault()}),onFocusOutside:V(t.onFocusOutside,a=>a.preventDefault())})}),Pr=n.forwardRef((t,s)=>{const o=ae(Ne,t.__scopeDialog),r=n.useRef(!1),l=n.useRef(!1);return e.jsx(lo,{...t,ref:s,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:a=>{var i,c;(i=t.onCloseAutoFocus)==null||i.call(t,a),a.defaultPrevented||(r.current||(c=o.triggerRef.current)==null||c.focus(),a.preventDefault()),r.current=!1,l.current=!1},onInteractOutside:a=>{var d,f;(d=t.onInteractOutside)==null||d.call(t,a),a.defaultPrevented||(r.current=!0,a.detail.originalEvent.type==="pointerdown"&&(l.current=!0));const i=a.target;((f=o.triggerRef.current)==null?void 0:f.contains(i))&&a.preventDefault(),a.detail.originalEvent.type==="focusin"&&l.current&&a.preventDefault()}})}),lo=n.forwardRef((t,s)=>{const{__scopeDialog:o,trapFocus:r,onOpenAutoFocus:l,onCloseAutoFocus:a,...i}=t,c=ae(Ne,o),d=n.useRef(null),f=J(s,d);return ds(),e.jsxs(e.Fragment,{children:[e.jsx(vt,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:l,onUnmountAutoFocus:a,children:e.jsx(os,{role:"dialog",id:c.contentId,"aria-describedby":c.descriptionId,"aria-labelledby":c.titleId,"data-state":Nt(c.open),...i,ref:f,onDismiss:()=>c.onOpenChange(!1)})}),e.jsxs(e.Fragment,{children:[e.jsx(_r,{titleId:c.titleId}),e.jsx(Ar,{contentRef:d,descriptionId:c.descriptionId})]})]})}),jt="DialogTitle",co=n.forwardRef((t,s)=>{const{__scopeDialog:o,...r}=t,l=ae(jt,o);return e.jsx(z.h2,{id:l.titleId,...r,ref:s})});co.displayName=jt;var io="DialogDescription",uo=n.forwardRef((t,s)=>{const{__scopeDialog:o,...r}=t,l=ae(io,o);return e.jsx(z.p,{id:l.descriptionId,...r,ref:s})});uo.displayName=io;var fo="DialogClose",ho=n.forwardRef((t,s)=>{const{__scopeDialog:o,...r}=t,l=ae(fo,o);return e.jsx(z.button,{type:"button",...r,ref:s,onClick:V(t.onClick,()=>l.onOpenChange(!1))})});ho.displayName=fo;function Nt(t){return t?"open":"closed"}var po="DialogTitleWarning",[sa,mo]=Qo(po,{contentName:Ne,titleName:jt,docsSlug:"dialog"}),_r=({titleId:t})=>{const s=mo(po),o=`\`${s.contentName}\` requires a \`${s.titleName}\` for the component to be accessible for screen reader users.

If you want to hide the \`${s.titleName}\`, you can wrap it with our VisuallyHidden component.

For more information, see https://radix-ui.com/primitives/docs/components/${s.docsSlug}`;return n.useEffect(()=>{t&&(document.getElementById(t)||console.error(o))},[o,t]),null},Mr="DialogDescriptionWarning",Ar=({contentRef:t,descriptionId:s})=>{const r=`Warning: Missing \`Description\` or \`aria-describedby={undefined}\` for {${mo(Mr).contentName}}.`;return n.useEffect(()=>{var a;const l=(a=t.current)==null?void 0:a.getAttribute("aria-describedby");s&&l&&(document.getElementById(s)||console.warn(r))},[r,t,s]),null},Dr=to,Or=no,Lr=ro,Fr=ao,Hr=co,$r=uo,Br=ho;function Vr({...t}){return e.jsx(Dr,{"data-slot":"sheet",...t})}function Wr({...t}){return e.jsx(Or,{"data-slot":"sheet-portal",...t})}function zr({className:t,...s}){return e.jsx(Lr,{"data-slot":"sheet-overlay",className:E("data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 fixed inset-0 z-50 bg-black/50",t),...s})}function Ur({className:t,children:s,side:o="right",...r}){return e.jsxs(Wr,{children:[e.jsx(zr,{}),e.jsxs(Fr,{"data-slot":"sheet-content",onSubmit:l=>l.preventDefault(),className:E("bg-background data-[state=open]:animate-in data-[state=closed]:animate-out fixed z-50 flex flex-col gap-4 shadow-lg transition ease-in-out data-[state=closed]:duration-300 data-[state=open]:duration-500",o==="right"&&"data-[state=closed]:slide-out-to-right data-[state=open]:slide-in-from-right inset-y-0 right-0 h-full w-3/4 border-l sm:max-w-sm",o==="left"&&"data-[state=closed]:slide-out-to-left data-[state=open]:slide-in-from-left inset-y-0 left-0 h-full w-3/4 border-r sm:max-w-sm",o==="top"&&"data-[state=closed]:slide-out-to-top data-[state=open]:slide-in-from-top inset-x-0 top-0 h-auto border-b",o==="bottom"&&"data-[state=closed]:slide-out-to-bottom data-[state=open]:slide-in-from-bottom inset-x-0 bottom-0 h-auto border-t",t),...r,children:[s,e.jsxs(Br,{className:"ring-offset-background focus:ring-ring data-[state=open]:bg-secondary absolute top-4 right-4 rounded-xs opacity-70 transition-opacity hover:opacity-100 focus:ring-2 focus:ring-offset-2 focus:outline-hidden disabled:pointer-events-none",children:[e.jsx(Zt,{className:"size-4"}),e.jsx("span",{className:"sr-only",children:"Close"})]})]})]})}function Kr({className:t,...s}){return e.jsx("div",{"data-slot":"sheet-header",className:E("flex flex-col gap-1.5 p-4",t),...s})}function Gr({className:t,...s}){return e.jsx(Hr,{"data-slot":"sheet-title",className:E("text-foreground font-semibold",t),...s})}function qr({className:t,...s}){return e.jsx($r,{"data-slot":"sheet-description",className:E("text-muted-foreground text-sm",t),...s})}const xe={HORIZONTAL_SPACING:280,VERTICAL_SPACING:320,START_X:250,START_Y:50};function Yr(t,s){if(t.length===0)return[];const o=new Map,r=new Map;for(const u of s){const m=o.get(u.source)||[];m.push(u.target),o.set(u.source,m);const p=r.get(u.target)||[];p.push(u.source),r.set(u.target,p)}const l=t.find(u=>u.data.nodeKind==="workflow_start");if(!l)return t.map((u,m)=>({id:u.id,type:u.type,data:{label:u.data.label,nodeKind:u.data.nodeKind,stepId:u.data.stepId},metadata:u.metadata,position:{x:xe.START_X,y:xe.START_Y+m*xe.VERTICAL_SPACING}}));const a=new Map,i=new Set,c=[l.id];for(a.set(l.id,0);c.length>0;){const u=c.shift();if(i.has(u))continue;i.add(u);const m=a.get(u),p=o.get(u)||[];for(const x of p)if(!(x===u||i.has(x)))if(!a.has(x))a.set(x,m+1),c.push(x);else{const h=a.get(x);m+1>h&&(a.set(x,m+1),c.includes(x)||c.push(x))}}let d=Math.max(...Array.from(a.values()),0);for(const u of t)a.has(u.id)||(d++,a.set(u.id,d));const f=new Map;for(const u of t){const m=a.get(u.id)??0,p=f.get(m)||[];p.push(u),f.set(m,p)}const g=[];for(const u of t){const m=a.get(u.id)??0,p=f.get(m)||[u],x=p.findIndex(w=>w.id===u.id),v=(p.length-1)*xe.HORIZONTAL_SPACING,j=xe.START_X-v/2;g.push({id:u.id,type:u.type,data:{label:u.data.label,nodeKind:u.data.nodeKind,stepId:u.data.stepId},metadata:u.metadata,position:{x:j+x*xe.HORIZONTAL_SPACING,y:xe.START_Y+m*xe.VERTICAL_SPACING}})}return g}function Zr(t){const s={};if(console.log("[adaptManifest] Raw manifest version:",t==null?void 0:t.version),console.log("[adaptManifest] Raw workflows keys:",Object.keys((t==null?void 0:t.workflows)||{})),!(t!=null&&t.workflows))return console.log("[adaptManifest] No workflows in manifest, returning empty"),{version:(t==null?void 0:t.version)||"1.0.0",workflows:{}};for(const[o,r]of Object.entries(t.workflows))for(const[l,a]of Object.entries(r)){const i=Yr(a.graph.nodes,a.graph.edges),c={workflowId:a.workflowId,workflowName:l,filePath:o,nodes:i,edges:a.graph.edges};s[a.workflowId]=c}return console.log("[adaptManifest] Adapted workflows count:",Object.keys(s).length),{version:t.version,workflows:s}}function Xr(){const[t,s]=n.useState(null),[o,r]=n.useState(!0),[l,a]=n.useState(null),i=n.useRef(!1),c=n.useMemo(()=>({}),[]),d=n.useCallback(async()=>{if(!i.current){i.current=!0,r(!0),a(null);try{console.log("[useWorkflowGraphManifest] Fetching with env:",c);const{result:f,error:g}=await Oo(en(c));if(g){a(g);return}console.log("[useWorkflowGraphManifest] Raw manifest after unwrap:",f),console.log("[useWorkflowGraphManifest] Workflows in raw:",Object.keys((f==null?void 0:f.workflows)||{}));const u=Zr(f);console.log("[useWorkflowGraphManifest] Adapted manifest workflows:",Object.keys(u.workflows)),s(u)}catch(f){const g=f instanceof Le?f:f instanceof Error?new Le(f.message,{cause:f,layer:"client"}):new Le(String(f),{layer:"client"});a(g),s(null)}finally{r(!1),i.current=!1}}},[c]);return n.useEffect(()=>{d()},[d]),{manifest:t,loading:o,error:l,refetch:d}}function Jr({onWorkflowSelect:t}){const[s,o]=n.useState(!1),[r,l]=n.useState(null),{manifest:a,loading:i,error:c}=Xr(),d=a?Object.values(a.workflows):[],f=n.useMemo(()=>[...d].sort((m,p)=>m.workflowName.localeCompare(p.workflowName)),[d]),g=n.useMemo(()=>(r==null?void 0:r.nodes.filter(m=>m.data.nodeKind==="step").length)??0,[r]),u=m=>{l(m),o(!0),t==null||t(m.workflowName)};return i?e.jsx(cs,{variant:"workflows",rows:6}):c?e.jsxs(ft,{variant:"destructive",children:[e.jsx(ht,{className:"h-4 w-4"}),e.jsx(pt,{children:"Error Loading Workflows"}),e.jsx(mt,{children:c.message})]}):d.length===0?e.jsx(Ee,{children:e.jsxs(Pe,{className:"p-12 text-center",children:[e.jsx(kt,{className:"mx-auto h-12 w-12 text-muted-foreground mb-4"}),e.jsx("h3",{className:"text-lg font-semibold mb-2",children:"No Workflows Found"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"No workflow definitions were found in the graph manifest."})]})}):e.jsxs(e.Fragment,{children:[e.jsx(Ee,{className:"overflow-hidden bg-background",children:e.jsx(Pe,{className:"p-0 max-h-[calc(100vh-200px)] overflow-auto",children:e.jsxs(Be,{children:[e.jsx(Ve,{children:e.jsxs(ie,{children:[e.jsx(G,{className:"sticky top-0 bg-background z-10 border-b shadow-sm h-10",children:"Workflow"}),e.jsx(G,{className:"sticky top-0 bg-background z-10 border-b shadow-sm h-10",children:"File"}),e.jsx(G,{className:"text-center sticky top-0 bg-background z-10 border-b shadow-sm h-10",children:"Steps"})]})}),e.jsx(We,{children:f.map(m=>{const p=m.nodes.filter(x=>x.data.nodeKind==="step").length;return e.jsxs(ie,{className:"cursor-pointer",onClick:()=>u(m),children:[e.jsx(W,{className:"py-2",children:e.jsx("span",{className:"font-medium",children:m.workflowName})}),e.jsx(W,{className:"py-2",children:e.jsx("code",{className:"text-xs text-muted-foreground",children:m.filePath})}),e.jsx(W,{className:"text-center py-2",children:e.jsxs(Ot,{variant:"secondary",className:"gap-1",children:[e.jsx(Ct,{className:"h-3 w-3"}),p," ",Rt("step","steps",p)]})})]},m.workflowId)})})]})})}),e.jsx(Vr,{open:s,onOpenChange:o,children:e.jsxs(Ur,{side:"right",className:"w-[75vw] max-w-[75vw] sm:max-w-[75vw]",children:[e.jsxs(Kr,{children:[e.jsxs(Gr,{className:"flex items-center gap-2",children:[e.jsx(kt,{className:"h-5 w-5"}),r==null?void 0:r.workflowName]}),r&&e.jsx(qr,{asChild:!0,children:e.jsxs("div",{className:"space-y-2",children:[e.jsx("code",{className:"text-xs",children:r.filePath}),e.jsx("div",{children:e.jsxs(Ot,{variant:"outline",className:"gap-1",children:[e.jsx(Ct,{className:"h-3 w-3"}),g," ",Rt("step","steps",g)]})})]})})]}),e.jsx("div",{className:"mt-6 h-[calc(100vh-180px)]",children:r&&e.jsx(Lo,{workflow:r})})]})})]})}const oa=vo(function(){const s=ut(),{serverConfig:o}=ns(),[r,l]=$e(),a=r.get("sidebar"),i=r.get("hookId"),c=r.get("tab")||"runs",d=p=>{l(x=>(x.set("tab",p),x),{replace:!0})},f=a==="hook"&&i?i:void 0,g=o.backendId==="local"||o.backendId==="@workflow/world-local",u=(p,x)=>{s(x?`/run/${p}/streams/${x}`:`/run/${p}`)},m=(p,x)=>{s(p?`/run/${x}?sidebar=hook&hookId=${p}`:`/run/${x}`)};return e.jsx("div",{className:"max-w-7xl mx-auto px-4",children:e.jsxs(Fo,{value:c,onValueChange:d,className:"w-full",children:[e.jsxs(Ho,{className:"mb-4",children:[e.jsx(qe,{value:"runs",children:"Runs"}),e.jsx(qe,{value:"hooks",children:"Hooks"}),g&&e.jsx(qe,{value:"workflows",children:"Workflows"})]}),e.jsx(Ye,{value:"runs",children:e.jsx(Ze,{title:"Failed to load workflow runs",children:e.jsx(Nr,{onRunClick:u})})}),e.jsx(Ye,{value:"hooks",children:e.jsx(Ze,{title:"Failed to load hooks",children:e.jsx(Sn,{onHookClick:m,selectedHookId:f})})}),g&&e.jsx(Ye,{value:"workflows",children:e.jsx(Ze,{title:"Failed to load workflow graph data",children:e.jsx(Jr,{})})})]})})});export{oa as default};
