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