import{f as d,b as u}from"./index-Z_QI94Zg.js";import"./mermaid-C0IQv4mH.js";import"./markdown-9_JKOUHQ.js";const A=d((i,c)=>({automationsByProject:{},inbox:[],inboxCount:0,selectedAutomationRuns:[],loadAutomations:async t=>{(await u.listAutomations(t)).match(o=>{i(a=>({automationsByProject:{...a.automationsByProject,[t]:o}}))},o=>console.error("[automation-store] Failed to load automations:",o.message))},loadInbox:async t=>{(await u.getAutomationInbox(t)).match(o=>{const a=o.filter(e=>e.run.triageStatus==="pending").length;i({inbox:o,inboxCount:a})},o=>console.error("[automation-store] Failed to load inbox:",o.message))},loadRuns:async t=>{(await u.listAutomationRuns(t)).match(o=>i({selectedAutomationRuns:o}),o=>console.error("[automation-store] Failed to load runs:",o.message))},createAutomation:async t=>{const n=await u.createAutomation(t);if(n.isErr())return null;const o=n.value,a=t.projectId;return i(e=>({automationsByProject:{...e.automationsByProject,[a]:[o,...e.automationsByProject[a]||[]]}})),o},updateAutomation:async(t,n)=>{const o=await u.updateAutomation(t,n);if(o.isErr())return;const a=o.value;i(e=>{const s={...e.automationsByProject};for(const[r,m]of Object.entries(s))s[r]=m.map(l=>l.id===t?a:l);return{automationsByProject:s}})},deleteAutomation:async(t,n)=>{(await u.deleteAutomation(t)).isErr()||i(a=>({automationsByProject:{...a.automationsByProject,[n]:(a.automationsByProject[n]||[]).filter(e=>e.id!==t)}}))},triggerAutomation:async t=>{await u.triggerAutomation(t)},triageRun:async(t,n)=>{(await u.triageRun(t,n)).isErr()||i(a=>{const e=a.inbox.map(r=>r.run.id===t?{...r,run:{...r.run,triageStatus:n}}:r),s=e.filter(r=>r.run.triageStatus==="pending").length;return{inbox:e,inboxCount:s}})},handleRunStarted:t=>{c().loadInbox()},handleRunCompleted:t=>{c().loadInbox();const n=c().selectedAutomationRuns;n.length>0&&n[0].automationId===t.automationId&&c().loadRuns(t.automationId)}}));export{A as useAutomationStore};
