import{d as g,r as c,k as u,a as s,u as r}from"../index.js";const P=g("pipeline",()=>{const i=c([]),l=c(!1),p=u(()=>i.value.find(e=>e.is_default)||i.value[0]||null),d=u(()=>e=>{for(const t of i.value){const a=(t.stages||[]).find(n=>n.id===e);if(a)return a}return null});async function f(){l.value=!0;try{const e=await s("pipelines");i.value=Array.isArray(e)?e:e.items||[]}catch(e){r().error(e.message)}finally{l.value=!1}}async function y(e){try{const t=await s("pipelines",{method:"POST",body:e});return i.value.push(t),t}catch(t){throw r().error(t.message),t}}async function h(e,t){try{const a=await s(`pipelines/${e}`,{method:"PATCH",body:t}),n=i.value.findIndex(o=>o.id===e);return n>-1&&i.value.splice(n,1,a),a}catch(a){throw r().error(a.message),a}}async function m(e){try{await s(`pipelines/${e}`,{method:"DELETE"}),i.value=i.value.filter(t=>t.id!==e)}catch(t){throw r().error(t.message),t}}async function v(e,t){try{const a=await s(`pipelines/${e}/stages`,{method:"PUT",body:{stages:t}}),n=i.value.findIndex(o=>o.id===e);return n>-1&&i.value.splice(n,1,a),a}catch(a){throw r().error(a.message),a}}return{pipelines:i,loading:l,defaultPipeline:p,stageById:d,fetchAll:f,createPipeline:y,updatePipeline:h,deletePipeline:m,reorderStages:v}});export{P as u};
