import{a as o,j as t}from"./vendor-query-B2UbickB.js";import{F as C,b as f}from"./FilterBar-Ck4K4rzu.js";import{f as $,C as T}from"./index-BZu5zewH.js";import{E as F}from"./SwimlaneTimeline-WQ6VMuqg.js";const D=new Set(["activity_task_scheduled","timer_started","child_workflow_execution_started","signal_wait_started"]),P=new Set(["activity_task_completed","activity_task_failed","timer_fired","child_workflow_execution_completed","child_workflow_execution_failed","workflow_execution_signaled"]);function O(l){const a=new Set;for(const i of l)P.has(i.event_type)&&i.attributes.timeline_key&&a.add(i.attributes.timeline_key);return a}function Y({events:l,childTasks:a}){const[i,_]=o.useState(""),[c,h]=o.useState(""),[x,y]=o.useState("asc"),[u,d]=o.useState(new Set),g=[...new Set(l.map(e=>e.category))].sort(),b=[...new Set(l.map(e=>e.event_type))].sort(),w=O(l),v=e=>{if(e.duration_ms!==null||!D.has(e.event_type))return!1;const s=e.attributes.timeline_key;return!(s&&w.has(s))};let n=l;i&&(n=n.filter(e=>e.category===i)),c&&(n=n.filter(e=>e.event_type===c)),n=[...n].sort((e,s)=>x==="asc"?e.event_id-s.event_id:s.event_id-e.event_id);const j=e=>{switch(e){case"activity":return"bg-blue-500";case"signal":return"bg-emerald-500";case"timer":return"bg-status-warning";case"child_workflow":return"bg-violet-500";default:return"bg-text-tertiary"}},k=e=>{const s=e.event_type;if(e.attributes.activity_type)return`${s} — ${e.attributes.activity_type}`;if(e.attributes.signal_name)return`${s} — ${e.attributes.signal_name}`;if(e.attributes.child_workflow_id){const r=e.attributes.child_workflow_id,S=r.length>24?`${r.slice(0,24)}...`:r;return`${s} — ${S}`}return s},N=e=>{if(!(a!=null&&a.length))return;const s=e.attributes.activity_type;if(s)return a.find(r=>r.workflow_type===s)},p=e=>{d(s=>{const r=new Set(s);return r.has(e)?r.delete(e):r.add(e),r})},m=n.length>0&&n.every(e=>u.has(e.event_id)),E=()=>{d(m?new Set:new Set(n.map(e=>e.event_id)))};return t.jsxs("div",{children:[t.jsxs("div",{className:"px-6 py-4 border-b border-surface-border flex items-center justify-between flex-wrap gap-3",children:[t.jsxs("div",{className:"flex items-center gap-4",children:[t.jsxs("p",{className:"text-[10px] font-semibold uppercase tracking-widest text-text-tertiary",children:["Events (",n.length,")"]}),n.length>0&&t.jsx("button",{onClick:E,className:"text-[10px] text-accent hover:underline",children:m?"Collapse all":"Expand all"})]}),t.jsxs(C,{children:[t.jsx(f,{label:"Category",value:i,onChange:_,options:g.map(e=>({value:e,label:e}))}),t.jsx(f,{label:"Type",value:c,onChange:h,options:b.map(e=>({value:e,label:e}))}),t.jsx("button",{onClick:()=>y(e=>e==="asc"?"desc":"asc"),className:"btn-ghost text-xs",children:x==="asc"?"Oldest first":"Newest first"})]})]}),t.jsx("div",{children:n.length===0?t.jsx("div",{className:"px-6 py-8 text-center",children:t.jsx("p",{className:"text-sm text-text-tertiary",children:"No events match the current filters"})}):n.map(e=>{const s=u.has(e.event_id),r=v(e);return t.jsxs("div",{className:"border-b border-surface-border last:border-b-0",children:[t.jsxs("div",{className:"px-6 py-3 flex items-center gap-4 cursor-pointer hover:bg-surface-hover transition-colors duration-200",onClick:()=>p(e.event_id),children:[t.jsx("span",{className:`text-[10px] text-text-tertiary transition-transform duration-300 ${s?"rotate-90":""}`,children:"▶"}),t.jsx("span",{className:"text-xs font-mono text-text-tertiary w-8 shrink-0",children:e.event_id}),t.jsx("span",{className:`w-2 h-2 rounded-full shrink-0 ${j(e.category)}`}),t.jsx("span",{className:"text-sm text-text-primary flex-1 truncate",children:k(e)}),t.jsx("span",{className:"text-xs font-mono text-text-tertiary shrink-0",children:r?t.jsxs("span",{className:"inline-flex items-center gap-1 text-status-warning",children:[t.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-status-warning animate-pulse"}),"Pending"]}):e.duration_ms!==null?$(e.duration_ms):"--"}),t.jsx("time",{className:"text-[10px] font-mono text-text-tertiary shrink-0",children:new Date(e.event_time).toLocaleTimeString()})]}),t.jsx(T,{open:s&&!!e.attributes,children:t.jsx("div",{className:"px-6 pb-4 pl-16",children:t.jsx(F,{event:e,childTask:N(e),pending:r,onClose:()=>p(e.event_id)})})})]},e.event_id)})})]})}export{Y as E};
//# sourceMappingURL=EventTable-D3IOLoxv.js.map
