UNPKG

miniflare

Version:

Fun, full-featured, fully-local simulator for Cloudflare Workers

1 lines 26.7 kB
import{c as e,s as t,z as n}from"./useRouterState-DkU0JPAO.js";import{Bt as r,Vt as i,r as a,zt as o}from"./button-cdxnqcgzwko8ooha-DW4HgSd6.js";import{t as s}from"./ArrowClockwise.es-Cy5-iE5C.js";import{t as c}from"./CaretLeft.es-CNp61Qgm.js";import{c as l,d as u,f as d,i as f,l as p,p as m,s as h,t as g,u as _}from"./types-DtYWWlE_.js";import{t as v}from"./DotsThree.es-DeZ0Dokf.js";import{n as y,t as b}from"./async-BF-ZueHi.js";import{n as x,t as S}from"./Spinner.es-CSKgxcOR.js";import{n as ee,t as C}from"./dialog-oqh8l3l3zutpibxx-6QAIfPjB.js";import{t as w}from"./input-group-lxdd09p60cf27pe1-FmDFsFZv.js";import{t as T}from"./dropdown-ncwhcd912vmone8k-BMBcB-5m.js";import{t as E}from"./select-kva5ru5f673kah1m-DMJc8LO6.js";import{t as te}from"./Breadcrumbs-D11-yw8F.js";import{Ct as D,Dt as O,Et as k,Ft as A,Pt as j,Rt as M,St as N,at as ne,s as re,wt as ie,xt as P}from"./index-CkemaNd1.js";var F=n(t(),1),I=new Map([[`bold`,F.createElement(F.Fragment,null,F.createElement(`path`,{d:`M208.49,199.51a12,12,0,0,1-17,17l-80-80a12,12,0,0,1,0-17l80-80a12,12,0,0,1,17,17L137,128ZM57,128l71.52-71.51a12,12,0,0,0-17-17l-80,80a12,12,0,0,0,0,17l80,80a12,12,0,0,0,17-17Z`}))],[`duotone`,F.createElement(F.Fragment,null,F.createElement(`path`,{d:`M200,48V208l-80-80Z`,opacity:`0.2`}),F.createElement(`path`,{d:`M203.06,40.61a8,8,0,0,0-8.72,1.73l-80,80a8,8,0,0,0,0,11.32l80,80A8,8,0,0,0,208,208V48A8,8,0,0,0,203.06,40.61ZM192,188.69,131.31,128,192,67.31Zm-66.34,13.65a8,8,0,0,1-11.32,11.32l-80-80a8,8,0,0,1,0-11.32l80-80a8,8,0,0,1,11.32,11.32L51.31,128Z`}))],[`fill`,F.createElement(F.Fragment,null,F.createElement(`path`,{d:`M208,48V208a8,8,0,0,1-13.66,5.66L128,147.31V208a8,8,0,0,1-13.66,5.66l-80-80a8,8,0,0,1,0-11.32l80-80A8,8,0,0,1,128,48v60.69l66.34-66.35A8,8,0,0,1,208,48Z`}))],[`light`,F.createElement(F.Fragment,null,F.createElement(`path`,{d:`M204.24,203.76a6,6,0,1,1-8.48,8.48l-80-80a6,6,0,0,1,0-8.48l80-80a6,6,0,0,1,8.48,8.48L128.49,128ZM48.49,128l75.75-75.76a6,6,0,0,0-8.48-8.48l-80,80a6,6,0,0,0,0,8.48l80,80a6,6,0,1,0,8.48-8.48Z`}))],[`regular`,F.createElement(F.Fragment,null,F.createElement(`path`,{d:`M205.66,202.34a8,8,0,0,1-11.32,11.32l-80-80a8,8,0,0,1,0-11.32l80-80a8,8,0,0,1,11.32,11.32L131.31,128ZM51.31,128l74.35-74.34a8,8,0,0,0-11.32-11.32l-80,80a8,8,0,0,0,0,11.32l80,80a8,8,0,0,0,11.32-11.32Z`}))],[`thin`,F.createElement(F.Fragment,null,F.createElement(`path`,{d:`M202.83,205.17a4,4,0,0,1-5.66,5.66l-80-80a4,4,0,0,1,0-5.66l80-80a4,4,0,1,1,5.66,5.66L125.66,128ZM45.66,128l77.17-77.17a4,4,0,0,0-5.66-5.66l-80,80a4,4,0,0,0,0,5.66l80,80a4,4,0,1,0,5.66-5.66Z`}))]]),L=new Map([[`bold`,F.createElement(F.Fragment,null,F.createElement(`path`,{d:`M144.49,136.49l-80,80a12,12,0,0,1-17-17L119,128,47.51,56.49a12,12,0,0,1,17-17l80,80A12,12,0,0,1,144.49,136.49Zm80-17-80-80a12,12,0,1,0-17,17L199,128l-71.52,71.51a12,12,0,0,0,17,17l80-80A12,12,0,0,0,224.49,119.51Z`}))],[`duotone`,F.createElement(F.Fragment,null,F.createElement(`path`,{d:`M136,128,56,208V48Z`,opacity:`0.2`}),F.createElement(`path`,{d:`M141.66,122.34l-80-80A8,8,0,0,0,48,48V208a8,8,0,0,0,13.66,5.66l80-80A8,8,0,0,0,141.66,122.34ZM64,188.69V67.31L124.69,128Zm157.66-55-80,80a8,8,0,0,1-11.32-11.32L204.69,128,130.34,53.66a8,8,0,0,1,11.32-11.32l80,80A8,8,0,0,1,221.66,133.66Z`}))],[`fill`,F.createElement(F.Fragment,null,F.createElement(`path`,{d:`M221.66,133.66l-80,80A8,8,0,0,1,128,208V147.31L61.66,213.66A8,8,0,0,1,48,208V48a8,8,0,0,1,13.66-5.66L128,108.69V48a8,8,0,0,1,13.66-5.66l80,80A8,8,0,0,1,221.66,133.66Z`}))],[`light`,F.createElement(F.Fragment,null,F.createElement(`path`,{d:`M140.24,132.24l-80,80a6,6,0,0,1-8.48-8.48L127.51,128,51.76,52.24a6,6,0,0,1,8.48-8.48l80,80A6,6,0,0,1,140.24,132.24Zm80-8.48-80-80a6,6,0,0,0-8.48,8.48L207.51,128l-75.75,75.76a6,6,0,1,0,8.48,8.48l80-80A6,6,0,0,0,220.24,123.76Z`}))],[`regular`,F.createElement(F.Fragment,null,F.createElement(`path`,{d:`M141.66,133.66l-80,80a8,8,0,0,1-11.32-11.32L124.69,128,50.34,53.66A8,8,0,0,1,61.66,42.34l80,80A8,8,0,0,1,141.66,133.66Zm80-11.32-80-80a8,8,0,0,0-11.32,11.32L204.69,128l-74.35,74.34a8,8,0,0,0,11.32,11.32l80-80A8,8,0,0,0,221.66,122.34Z`}))],[`thin`,F.createElement(F.Fragment,null,F.createElement(`path`,{d:`M138.83,130.83l-80,80a4,4,0,0,1-5.66-5.66L130.34,128,53.17,50.83a4,4,0,0,1,5.66-5.66l80,80A4,4,0,0,1,138.83,130.83Zm80-5.66-80-80a4,4,0,0,0-5.66,5.66L210.34,128l-77.17,77.17a4,4,0,0,0,5.66,5.66l80-80A4,4,0,0,0,218.83,125.17Z`}))]]),R=new Map([[`bold`,F.createElement(F.Fragment,null,F.createElement(`path`,{d:`M208,28H48A20,20,0,0,0,28,48V208a20,20,0,0,0,20,20H208a20,20,0,0,0,20-20V48A20,20,0,0,0,208,28Zm-4,176H52V52H204Z`}))],[`duotone`,F.createElement(F.Fragment,null,F.createElement(`path`,{d:`M216,48V208a8,8,0,0,1-8,8H48a8,8,0,0,1-8-8V48a8,8,0,0,1,8-8H208A8,8,0,0,1,216,48Z`,opacity:`0.2`}),F.createElement(`path`,{d:`M208,32H48A16,16,0,0,0,32,48V208a16,16,0,0,0,16,16H208a16,16,0,0,0,16-16V48A16,16,0,0,0,208,32Zm0,176H48V48H208V208Z`}))],[`fill`,F.createElement(F.Fragment,null,F.createElement(`path`,{d:`M224,48V208a16,16,0,0,1-16,16H48a16,16,0,0,1-16-16V48A16,16,0,0,1,48,32H208A16,16,0,0,1,224,48Z`}))],[`light`,F.createElement(F.Fragment,null,F.createElement(`path`,{d:`M208,34H48A14,14,0,0,0,34,48V208a14,14,0,0,0,14,14H208a14,14,0,0,0,14-14V48A14,14,0,0,0,208,34Zm2,174a2,2,0,0,1-2,2H48a2,2,0,0,1-2-2V48a2,2,0,0,1,2-2H208a2,2,0,0,1,2,2Z`}))],[`regular`,F.createElement(F.Fragment,null,F.createElement(`path`,{d:`M208,32H48A16,16,0,0,0,32,48V208a16,16,0,0,0,16,16H208a16,16,0,0,0,16-16V48A16,16,0,0,0,208,32Zm0,176H48V48H208V208Z`}))],[`thin`,F.createElement(F.Fragment,null,F.createElement(`path`,{d:`M208,36H48A12,12,0,0,0,36,48V208a12,12,0,0,0,12,12H208a12,12,0,0,0,12-12V48A12,12,0,0,0,208,36Zm4,172a4,4,0,0,1-4,4H48a4,4,0,0,1-4-4V48a4,4,0,0,1,4-4H208a4,4,0,0,1,4,4Z`}))]]),z=F.forwardRef((e,t)=>F.createElement(r,{ref:t,...e,weights:I}));z.displayName=`CaretDoubleLeftIcon`;var B=F.forwardRef((e,t)=>F.createElement(r,{ref:t,...e,weights:L}));B.displayName=`CaretDoubleRightIcon`;var V=F.forwardRef((e,t)=>F.createElement(r,{ref:t,...e,weights:R}));V.displayName=`SquareIcon`;var H=e(),U=[25,50,100,250],W=(e,t,n)=>Math.min(Math.max(e,t),n),G={controls:`full`},K=(0,F.createContext)(null);function q(){let e=(0,F.useContext)(K);if(!e)throw Error(`Pagination compound components must be used within a Pagination component`);return e}function J({children:e,className:t}){let{page:n,perPage:r,totalCount:a,pageShowingRange:o}=q(),s=e?e({page:n,perPage:r,totalCount:a,pageShowingRange:o}):a&&a>0?(0,H.jsxs)(H.Fragment,{children:[`Showing `,(0,H.jsx)(`span`,{className:`tabular-nums`,children:o}),` of`,` `,(0,H.jsx)(`span`,{className:`tabular-nums`,children:a})]}):null;return(0,H.jsx)(`div`,{"data-slot":`pagination-info`,className:i(`text-sm text-kumo-strong`,t),children:s})}J.displayName=`Pagination.Info`;function Y({value:e,onChange:t,options:n=U,label:r=`Per page:`,className:a}){return(0,H.jsxs)(`div`,{"data-slot":`pagination-page-size`,className:i(`flex items-center gap-2`,a),children:[r&&(0,H.jsx)(`span`,{className:`text-sm text-kumo-strong`,children:r}),(0,H.jsx)(E,{"aria-label":`Page size`,value:e,onValueChange:e=>t(e),children:n.map(e=>(0,H.jsx)(E.Option,{value:e,children:e},e))})]})}Y.displayName=`Pagination.PageSize`;function X({controls:e=G.controls,pageSelector:t=`input`,className:n}){let{page:r,maxPage:a,setPage:o,editingPage:s,setEditingPage:l}=q();return(0,H.jsx)(`div`,{"data-slot":`pagination-controls`,className:i(`grow flex flex-col items-end`,n),children:(0,H.jsx)(`div`,{children:(0,H.jsxs)(w,{focusMode:`individual`,children:[e===`full`&&(0,H.jsx)(w.Button,{variant:`secondary`,"aria-label":`First page`,disabled:r<=1,onClick:()=>{o(1),l(1)},children:(0,H.jsx)(z,{size:16})}),(0,H.jsx)(w.Button,{variant:`secondary`,"aria-label":`Previous page`,disabled:r<=1,onClick:()=>{let e=Math.max(r-1,1);o(e),l(e)},children:(0,H.jsx)(c,{size:16})}),e===`full`&&(t===`dropdown`?(0,H.jsx)(E,{"aria-label":`Page number`,className:`rounded-none ring-kumo-line`,value:r,onValueChange:e=>{let t=e;o(t),l(t)},children:Array.from({length:a},(e,t)=>t+1).map(e=>(0,H.jsx)(E.Option,{value:e,children:e},e))}):(0,H.jsx)(w.Input,{style:{width:50},className:`text-center`,"aria-label":`Page number`,value:s,onValueChange:e=>{l(Number(e))},onBlur:()=>{let e=W(s,1,a);o(e),l(e)},onKeyDown:e=>{if(e.key===`Enter`){let e=W(s,1,a);o(e),l(e)}},autoComplete:`off`,"data-1p-ignore":!0,"data-lpignore":`true`,"data-form-type":`other`})),(0,H.jsx)(w.Button,{variant:`secondary`,"aria-label":`Next page`,disabled:r===a,onClick:()=>{let e=Math.min(r+1,a);o(e),l(e)},children:(0,H.jsx)(A,{size:16})}),e===`full`&&(0,H.jsx)(w.Button,{variant:`secondary`,"aria-label":`Last page`,disabled:r===a,onClick:()=>{o(a),l(a)},children:(0,H.jsx)(B,{size:16})})]})})})}X.displayName=`Pagination.Controls`;function Z({className:e}){return(0,H.jsx)(`div`,{"data-slot":`pagination-separator`,className:i(`mx-2 h-6 border-l border-kumo-line`,e)})}Z.displayName=`Pagination.Separator`;function Q(e){let{page:t=1,perPage:n,totalCount:r,setPage:a,children:o,className:s}=e,c=`text`in e?e.text:void 0,l=`controls`in e?e.controls??G.controls:G.controls,[u,d]=(0,F.useState)(1);(0,F.useEffect)(()=>{d(t)},[t]);let f=(0,F.useMemo)(()=>{let e=t*(n??1)-(n??0)+1,i=Math.min(t*(n??0),r??0);return Number.isNaN(e)&&(e=0),Number.isNaN(i)&&(i=0),`${e}-${i}`},[t,n,r]),p={page:t,perPage:n,totalCount:r,maxPage:(0,F.useMemo)(()=>Math.ceil((r??1)/(n??1)),[r,n]),pageShowingRange:f,setPage:a,editingPage:u,setEditingPage:d};return o?(0,H.jsx)(K.Provider,{value:p,children:(0,H.jsx)(`div`,{"data-slot":`pagination`,className:i(`flex items-center gap-2 w-full`,s),children:o})}):(0,H.jsx)(K.Provider,{value:p,children:(0,H.jsxs)(`div`,{"data-slot":`pagination`,className:i(`flex items-center gap-2 w-full`,s),children:[(0,H.jsx)(`div`,{"data-slot":`pagination-info`,className:`grow text-sm text-kumo-strong`,children:c?c({page:t,perPage:n,totalCount:r,pageShowingRange:f}):r&&r>0?(0,H.jsxs)(H.Fragment,{children:[`Showing `,(0,H.jsx)(`span`,{className:`tabular-nums`,children:f}),` of`,` `,(0,H.jsx)(`span`,{className:`tabular-nums`,children:r})]}):null}),(0,H.jsx)(X,{controls:l})]})})}Q.displayName=`Pagination`;var ae=Object.assign(Q,{Info:J,PageSize:Y,Controls:X,Separator:Z});function oe({onCreated:e,onOpenChange:t,open:n,workflowName:r}){let[i,o]=(0,F.useState)(!1),[s,c]=(0,F.useState)(null),[l,u]=(0,F.useState)(``),[d,f]=(0,F.useState)(``),[p,m]=(0,F.useState)(null),h=(0,F.useCallback)(()=>{u(``),f(``),c(null),m(null)},[]);function g(e){e||h(),t(e)}function _(){if(!d.trim())return m(null),{valid:!0,value:void 0};try{let e=JSON.parse(d);return m(null),{valid:!0,value:e}}catch{return m(`Invalid JSON`),{valid:!1}}}async function v(){let t=_();if(t.valid){o(!0),c(null);try{let n={};l.trim()&&(n.id=l.trim()),t.value!==void 0&&(n.params=t.value);let i=(await N({path:{workflow_name:r},body:n})).data?.result?.id;if(!i){c(`Instance was created but no ID was returned`);return}h(),e(i)}catch(e){c(e instanceof Error?e.message:`Failed to create instance`)}finally{o(!1)}}}return(0,H.jsx)(C.Root,{open:n,onOpenChange:g,children:(0,H.jsxs)(C,{size:`lg`,children:[(0,H.jsxs)(`div`,{className:`border-b border-kumo-fill px-6 pt-6 pb-4`,children:[(0,H.jsx)(C.Title,{className:`text-lg font-semibold text-kumo-default`,children:`Trigger this workflow?`}),(0,H.jsx)(`p`,{className:`mt-1 text-sm text-kumo-subtle`,children:`Manually trigger an instance of this Workflow using the payload below.`})]}),(0,H.jsxs)(`div`,{className:`px-6 py-6`,children:[s&&(0,H.jsx)(`div`,{className:`mb-5 rounded-lg border border-kumo-danger/20 bg-kumo-danger/8 p-3 text-sm text-kumo-danger`,children:s}),(0,H.jsxs)(`div`,{className:`mb-5`,children:[(0,H.jsxs)(`label`,{className:`mb-2 block text-sm font-medium text-kumo-default`,children:[`Instance ID`,` `,(0,H.jsx)(`span`,{className:`font-normal text-kumo-subtle`,children:`(optional)`})]}),(0,H.jsx)(`input`,{className:`focus-visible:ring-kumo-ring w-full rounded-lg border border-kumo-fill bg-kumo-base px-3 py-2.5 text-sm text-kumo-default placeholder:text-kumo-subtle focus:border-kumo-brand focus:outline-none focus-visible:ring-2`,onChange:e=>u(e.target.value),placeholder:`Auto-generated UUID if empty`,type:`text`,value:l})]}),(0,H.jsxs)(`div`,{children:[(0,H.jsx)(`label`,{className:`mb-2 block text-sm font-medium text-kumo-default`,children:`Params`}),(0,H.jsx)(`textarea`,{className:`focus-visible:ring-kumo-ring w-full resize-y rounded-lg border bg-kumo-base px-3 py-2.5 font-mono text-sm text-kumo-default placeholder:text-kumo-subtle focus:outline-none focus-visible:ring-2 ${p?`border-kumo-danger focus:border-kumo-danger`:`border-kumo-fill focus:border-kumo-brand`}`,onChange:e=>{f(e.target.value),p&&m(null)},placeholder:`{"key": "value"}`,rows:8,value:d}),p?(0,H.jsx)(`p`,{className:`mt-1 text-xs text-kumo-danger`,children:p}):(0,H.jsx)(`p`,{className:`mt-1 text-xs text-kumo-subtle`,children:`JSON payload passed to the workflow`})]})]}),(0,H.jsxs)(`div`,{className:`flex justify-end gap-2 border-t border-kumo-fill px-6 py-4`,children:[(0,H.jsx)(a,{variant:`secondary`,onClick:()=>g(!1),disabled:i,children:`Cancel`}),(0,H.jsx)(a,{variant:`primary`,disabled:i,loading:i,onClick:v,children:i?`Triggering...`:`Trigger Instance`})]})]})})}var $=[{key:`complete`,label:`Complete`,icon:m,color:`text-kumo-link`,weight:`fill`},{key:`errored`,label:`Errored`,icon:l,color:`text-kumo-danger`,weight:`fill`},{key:`queued`,label:`Queued`,icon:d,color:`text-kumo-subtle`,weight:`regular`},{key:`running`,label:`Running`,icon:x,color:`text-kumo-subtle`,weight:`fill`},{key:`paused`,label:`Paused`,icon:_,color:`text-kumo-subtle`,weight:`fill`},{key:`waiting`,label:`Waiting`,icon:S,color:`text-kumo-subtle`,weight:`regular`},{key:`terminated`,label:`Terminated`,icon:V,color:`text-kumo-subtle`,weight:`fill`}],se=(0,F.memo)(function({statusCounts:e}){return(0,H.jsx)(`div`,{className:`mb-4 flex divide-x divide-kumo-fill overflow-hidden rounded-lg border border-kumo-fill bg-kumo-base`,children:$.map(({key:t,label:n,icon:r,color:i,weight:a})=>(0,H.jsxs)(`div`,{className:`flex-1 space-y-1 px-4.5 pt-4 pb-3.5`,children:[(0,H.jsxs)(`div`,{className:`flex items-center gap-1.5 text-xs text-kumo-subtle`,children:[(0,H.jsx)(r,{className:i,size:12,weight:a}),n]}),(0,H.jsx)(`div`,{className:`mt-0.5 text-base text-kumo-default`,children:e[t]??0})]},t))})}),ce={pause:{icon:_,style:`border-kumo-fill bg-kumo-base text-kumo-default hover:bg-kumo-fill`,weight:`fill`},resume:{icon:x,style:`border-kumo-fill bg-kumo-base text-kumo-default hover:bg-kumo-fill`,weight:`fill`},restart:{icon:s,style:`border-kumo-fill bg-kumo-base text-kumo-default hover:bg-kumo-fill`,weight:`regular`},terminate:{icon:p,style:`border-kumo-fill bg-kumo-base text-kumo-danger hover:bg-kumo-badge-red/10`,weight:`fill`}},le=(0,F.memo)(function({instance:e,onActionComplete:t,workflowName:n}){let r=M(),[i,o]=(0,F.useState)(null),[s,c]=(0,F.useState)(!1),[l,d]=(0,F.useState)(!1),[p,m]=(0,F.useState)(``),[_,v]=(0,F.useState)(``),[y,b]=(0,F.useState)(!1),x=e.status??`unknown`,S=g(x);async function w(r,i){r.stopPropagation(),o(i);try{await P({path:{workflow_name:n,instance_id:e.id??``},body:{action:i}}),t()}catch{t()}finally{o(null)}}function T(e){e.stopPropagation(),c(!0)}async function E(){c(!1),o(`terminate`);try{await D({path:{workflow_name:n,instance_id:e.id??``}}),t()}catch{t()}finally{o(null)}}function te(e){e.stopPropagation(),d(!0)}async function k(){if(!p.trim())return;let r;if(_.trim())try{r=JSON.parse(_)}catch{return}b(!0);try{await O({path:{workflow_name:n,instance_id:e.id??``,event_type:p.trim()},body:r}),d(!1),m(``),v(``),t()}catch{d(!1),t()}finally{b(!1)}}function A(){r({to:`/workflows/$workflowName/$instanceId`,params:{instanceId:e.id??``,workflowName:n},search:e=>e})}return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`div`,{className:`border-b border-kumo-fill bg-kumo-base p-1 last:border-b-0`,children:(0,H.jsxs)(`div`,{className:`grid h-10 cursor-pointer grid-cols-[100px_60px_1fr_auto] items-center gap-3 rounded-lg px-2 transition-colors hover:bg-kumo-fill`,onClick:A,children:[(0,H.jsx)(`div`,{children:(0,H.jsx)(f,{status:x})}),(0,H.jsx)(`span`,{className:`text-sm text-kumo-subtle`,children:h(e.created_on)||`—`}),(0,H.jsx)(`span`,{className:`truncate font-mono text-xs text-kumo-default`,children:e.id}),(0,H.jsxs)(`div`,{className:`flex items-center gap-1`,children:[S.map(e=>{let t=ce[e],n=t.icon;return(0,H.jsx)(`button`,{className:`inline-flex size-7 cursor-pointer items-center justify-center rounded-md border transition-colors disabled:cursor-not-allowed disabled:opacity-40 ${t.style}`,disabled:i!==null,onClick:t=>void w(t,e),title:e.charAt(0).toUpperCase()+e.slice(1),children:(0,H.jsx)(n,{size:14,weight:t.weight,className:i===e?`animate-spin`:``})},e)}),x!==`complete`&&x!==`errored`&&x!==`terminated`&&(0,H.jsx)(`button`,{className:`ml-1 inline-flex size-7 cursor-pointer items-center justify-center rounded-md border border-kumo-fill bg-kumo-base text-kumo-default transition-colors hover:bg-kumo-fill disabled:cursor-not-allowed disabled:opacity-40`,disabled:i!==null,onClick:te,title:`Send Event`,children:(0,H.jsx)(u,{size:14})}),(0,H.jsx)(`button`,{className:`inline-flex size-7 cursor-pointer items-center justify-center rounded-md border border-kumo-fill bg-kumo-base text-kumo-danger transition-colors hover:bg-kumo-badge-red/10 disabled:cursor-not-allowed disabled:opacity-40`,disabled:i!==null,onClick:T,title:`Delete`,children:(0,H.jsx)(ee,{size:14})})]})]})}),(0,H.jsx)(C.Root,{open:s,onOpenChange:c,children:(0,H.jsxs)(C,{size:`lg`,children:[(0,H.jsxs)(`div`,{className:`border-b border-kumo-fill px-6 pt-6 pb-4`,children:[(0,H.jsx)(C.Title,{className:`text-lg font-semibold text-kumo-default`,children:`Delete this instance?`}),(0,H.jsx)(`p`,{className:`mt-1 text-sm text-kumo-subtle`,children:`This will permanently delete the instance and its persistence data. This action cannot be undone.`})]}),(0,H.jsx)(`div`,{className:`px-6 py-4`,children:(0,H.jsxs)(`div`,{className:`rounded-lg border border-kumo-fill bg-kumo-elevated px-4 py-3`,children:[(0,H.jsx)(`span`,{className:`text-xs text-kumo-subtle`,children:`Instance ID`}),(0,H.jsx)(`p`,{className:`mt-0.5 font-mono text-sm text-kumo-default`,children:e.id})]})}),(0,H.jsxs)(`div`,{className:`flex justify-end gap-2 border-t border-kumo-fill px-6 py-4`,children:[(0,H.jsx)(a,{variant:`secondary`,onClick:()=>c(!1),children:`Cancel`}),(0,H.jsx)(a,{variant:`destructive`,onClick:()=>void E(),children:`Delete Instance`})]})]})}),(0,H.jsx)(C.Root,{open:l,onOpenChange:e=>{d(e),e||(m(``),v(``))},children:(0,H.jsxs)(C,{size:`lg`,className:`w-lg`,children:[(0,H.jsx)(`div`,{className:`border-b border-kumo-fill px-6 py-4`,children:(0,H.jsx)(C.Title,{className:`text-lg font-semibold text-kumo-default`,children:`Send Event`})}),(0,H.jsxs)(`div`,{className:`space-y-4 px-6 py-5`,children:[(0,H.jsxs)(`div`,{children:[(0,H.jsx)(`label`,{className:`mb-2 block text-sm font-medium text-kumo-default`,children:`Event Type`}),(0,H.jsx)(`input`,{className:`focus-visible:ring-kumo-ring w-full rounded-lg border border-kumo-fill bg-kumo-base px-3 py-2.5 text-sm text-kumo-default placeholder:text-kumo-subtle focus:border-kumo-brand focus:outline-none focus-visible:ring-2`,onChange:e=>m(e.target.value),placeholder:`my-event`,type:`text`,value:p})]}),(0,H.jsxs)(`div`,{children:[(0,H.jsxs)(`label`,{className:`mb-2 block text-sm font-medium text-kumo-default`,children:[`Payload`,` `,(0,H.jsx)(`span`,{className:`font-normal text-kumo-subtle`,children:`(optional)`})]}),(0,H.jsx)(`textarea`,{className:`focus-visible:ring-kumo-ring w-full resize-y rounded-lg border border-kumo-fill bg-kumo-base px-3 py-2.5 font-mono text-sm text-kumo-default placeholder:text-kumo-subtle focus:border-kumo-brand focus:outline-none focus-visible:ring-2`,onChange:e=>v(e.target.value),placeholder:`{"key": "value"}`,rows:4,value:_})]})]}),(0,H.jsxs)(`div`,{className:`flex justify-end gap-2 border-t border-kumo-fill px-6 py-4`,children:[(0,H.jsx)(a,{variant:`secondary`,onClick:()=>d(!1),disabled:y,children:`Cancel`}),(0,H.jsx)(a,{variant:`primary`,disabled:!p.trim()||y,loading:y,onClick:()=>void k(),children:`Send`})]})]})})]})});function ue(){let e=re.useParams(),t=re.useLoaderData(),n=M(),[r,i]=(0,F.useState)(!1),[s,c]=(0,F.useState)(!1),[l,u]=(0,F.useState)(null),[d,f]=(0,F.useState)(!1),[p,m]=(0,F.useState)(null),[h,g]=(0,F.useState)(t.instances),[_,S]=(0,F.useState)(t.instances.length===0&&(t.resultInfo.total_count??0)===0),[w,E]=(0,F.useState)(!1),[D,O]=(0,F.useState)(!1),[A,N]=(0,F.useState)(t.resultInfo.page??1),[P,I]=(0,F.useState)(t.resultInfo.per_page??25),[L,R]=(0,F.useState)(t.resultInfo.status_counts??{}),[z,B]=(0,F.useState)(`all`),[V,U]=(0,F.useState)(t.resultInfo.total_count??0);(0,F.useEffect)(()=>{g(t.instances),U(t.resultInfo.total_count??0),R(t.resultInfo.status_counts??{}),m(null),S(!1),E(!1)},[t]);let W=(0,F.useCallback)(async(t,n,r,i)=>{try{r||E(!0),m(null);let a=t??A,o=n??P,s=i??z,c=await k({path:{workflow_name:e.workflowName},query:{page:a,per_page:o,...s===`all`?{}:{status:s}}});g(c.data?.result??[]),U(c.data?.result_info?.total_count??0),(!s||s===`all`)&&R(c.data?.result_info?.status_counts??{}),N(c.data?.result_info?.page??a),S(!1)}catch(e){m(e instanceof Error?e.message:`Failed to fetch instances`)}finally{E(!1)}},[e.workflowName,A,P,z]),G=(0,F.useCallback)(async()=>{O(!0);try{await b(W(void 0,void 0,!0))}finally{O(!1)}},[W]),K=(0,F.useRef)(null);(0,F.useEffect)(()=>(K.current=setInterval(()=>{W(void 0,void 0,!0)},1e4),()=>{K.current&&clearInterval(K.current)}),[W]);function q(e){N(e),W(e)}function J(e){I(e),N(1),W(1,e)}function Y(t){f(!1),n({to:`/workflows/$workflowName/$instanceId`,params:{workflowName:e.workflowName,instanceId:t}})}function X(e){B(e),N(1),W(1,void 0,!1,e)}function Z(e){i(e),e||u(null)}async function Q(){c(!0),u(null);try{await ie({path:{workflow_name:e.workflowName}}),Z(!1),W(1)}catch(e){u(e instanceof Error?e.message:`Failed to delete instances`)}finally{c(!1)}}return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(te,{icon:ne,items:[(0,H.jsx)(`span`,{className:`flex items-center gap-1.5`,children:e.workflowName},`workflow-name`)],title:`Workflows`}),(0,H.jsxs)(`div`,{className:`px-8 py-6`,children:[(0,H.jsx)(se,{statusCounts:L}),(0,H.jsx)(`hr`,{className:`-mx-8 my-4 border-kumo-fill`}),(0,H.jsxs)(`div`,{className:`mb-4 flex items-center justify-between`,children:[(0,H.jsxs)(T,{children:[(0,H.jsx)(T.Trigger,{render:(0,H.jsxs)(`button`,{className:`inline-flex h-9 min-w-36 cursor-pointer items-center justify-between rounded-lg border border-kumo-fill bg-kumo-base px-3 text-sm text-kumo-default transition-colors hover:bg-kumo-fill`,children:[(0,H.jsx)(`span`,{children:z===`all`?`All`:$.find(e=>e.key===z)?.label??z}),(0,H.jsx)(j,{size:14,className:`text-kumo-subtle`})]})}),(0,H.jsxs)(T.Content,{align:`start`,className:`w-36 bg-kumo-base`,side:`bottom`,children:[(0,H.jsx)(T.Item,{className:`cursor-pointer gap-2 rounded-md transition-colors hover:bg-kumo-fill`,icon:(0,H.jsx)(y,{}),onClick:()=>X(`all`),children:`All`}),$.map(({key:e,label:t,icon:n})=>(0,H.jsx)(T.Item,{className:`cursor-pointer gap-2 rounded-md transition-colors hover:bg-kumo-fill`,icon:(0,H.jsx)(n,{}),onClick:()=>X(e),children:t},e))]})]}),(0,H.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,H.jsxs)(a,{onClick:e=>{e.target.blur(),f(!0)},variant:`primary`,children:[(0,H.jsx)(x,{size:14,weight:`fill`}),`Trigger`]}),(0,H.jsx)(a,{"aria-label":`Refresh`,disabled:D,onClick:()=>void G(),shape:`square`,variant:`secondary`,children:(0,H.jsx)(o,{size:18,className:D?`animate-spin`:``})}),(0,H.jsxs)(T,{children:[(0,H.jsx)(T.Trigger,{render:(0,H.jsx)(a,{"aria-label":`More actions`,shape:`square`,children:(0,H.jsx)(v,{size:14,weight:`bold`})})}),(0,H.jsx)(T.Content,{align:`end`,sideOffset:4,children:(0,H.jsxs)(T.Item,{className:`flex cursor-pointer items-center gap-2 text-kumo-danger`,onClick:()=>Z(!0),children:[(0,H.jsx)(ee,{}),(0,H.jsx)(`span`,{children:`Delete all instances`})]})})]})]})]}),p&&(0,H.jsx)(`div`,{className:`mb-4 rounded-md border border-kumo-danger/20 bg-kumo-danger/8 p-4 text-kumo-danger`,children:p}),_?(0,H.jsx)(`div`,{className:`p-12 text-center text-kumo-subtle`,children:`Loading...`}):h.length===0&&!w?(0,H.jsx)(`div`,{className:`rounded-lg border border-kumo-fill bg-kumo-elevated px-5 py-8 text-center text-sm text-kumo-subtle`,children:`No instances found`}):h.length===0?(0,H.jsx)(`div`,{className:`rounded-lg border border-kumo-fill bg-kumo-elevated px-5 py-8 text-center text-sm text-kumo-subtle`,children:z===`all`?`No instances found`:(0,H.jsxs)(H.Fragment,{children:[`No instances found in state ‘`,z,`’`]})}):(0,H.jsxs)(`div`,{className:`transition-opacity duration-150 ${w?`opacity-60`:`opacity-100`}`,children:[(0,H.jsx)(`div`,{className:`overflow-hidden rounded-lg border border-kumo-fill bg-kumo-base`,children:h.map(t=>(0,H.jsx)(le,{instance:t,onActionComplete:G,workflowName:e.workflowName},t.id))}),V>0&&(0,H.jsxs)(`div`,{className:`flex items-center justify-between gap-2 pt-4`,children:[(0,H.jsxs)(T,{children:[(0,H.jsx)(T.Trigger,{render:(0,H.jsxs)(a,{children:[P,` `,(0,H.jsx)(j,{size:14})]})}),(0,H.jsx)(T.Content,{align:`start`,className:`bg-kumo-base`,side:`top`,children:[10,25,50,100].map(e=>(0,H.jsxs)(T.Item,{className:`cursor-pointer rounded-md transition-colors hover:bg-kumo-fill`,onClick:()=>J(e),children:[e,e===P&&(0,H.jsx)(`span`,{className:`ml-2 text-kumo-subtle`,children:`✓`})]},e))})]}),(0,H.jsx)(ae,{page:A,perPage:P,setPage:q,totalCount:V})]})]})]}),(0,H.jsx)(C.Root,{open:r,onOpenChange:Z,children:(0,H.jsxs)(C,{size:`lg`,className:`w-lg`,children:[(0,H.jsx)(`div`,{className:`border-b border-kumo-fill px-6 py-4`,children:(0,H.jsx)(C.Title,{className:`text-lg font-semibold text-kumo-default`,children:`Delete all instances`})}),(0,H.jsxs)(`div`,{className:`px-6 py-5`,children:[l&&(0,H.jsx)(`div`,{className:`mb-4 rounded-lg border border-kumo-danger/20 bg-kumo-danger/8 p-3 text-sm text-kumo-danger`,children:l}),(0,H.jsxs)(`p`,{className:`text-sm text-kumo-subtle`,children:[`This will permanently delete all instances of`,` `,(0,H.jsx)(`span`,{className:`font-semibold text-kumo-default`,children:e.workflowName}),`. All instance data and persistence files will be removed. This action cannot be undone.`]})]}),(0,H.jsxs)(`div`,{className:`flex justify-end gap-2 border-t border-kumo-fill px-6 py-4`,children:[(0,H.jsx)(a,{variant:`secondary`,onClick:()=>Z(!1),disabled:s,children:`Cancel`}),(0,H.jsx)(a,{variant:`destructive`,disabled:s,loading:s,onClick:()=>void Q(),children:`Delete`})]})]})}),(0,H.jsx)(oe,{onCreated:Y,onOpenChange:f,open:d,workflowName:e.workflowName})]})}export{ue as component};