import{l as h,r as o}from"./tpFEFzWU.js";const v={BACKLOG:"backlog",DONE:"done"};function S(u){const t=u.replace(/^\d+_/,"");return t===v.BACKLOG||t===v.DONE}function L(u){return u.replace(/^\d+_/,"")===v.BACKLOG}function $(u){return u.replace(/^\d+_/,"")===v.DONE}const c=o(""),e=o(null),f=o(!1),p=o(!1),d=o(!1),w=()=>{const u=async l=>{if(l){p.value=!0;try{const n=await $fetch(`/api/pipelines/${l}`);e.value=n,f.value=!1}finally{p.value=!1}}},t=async()=>{if(!(!e.value||!c.value)){d.value=!0;try{return await $fetch(`/api/pipelines/${c.value}`,{method:"PUT",body:{version:e.value.version,description:e.value.description,definition:e.value.definition,action:e.value.action,finish:e.value.finish}}),f.value=!1,!0}finally{d.value=!1}}},s=()=>{f.value=!0},g=l=>l.toLowerCase().normalize("NFD").replace(/[\u0300-\u036f]/g,"").replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,""),m=h(()=>e.value?[...e.value.definition,...e.value.action,...e.value.finish]:[]),y=h(()=>e.value?e.value.definition.length>0&&e.value.action.length>0&&e.value.finish.length>0:!1),P=(l,n)=>{if(!e.value||!n.trim())return!1;const i=g(n);return m.value.map(r=>r.slug.replace(/^\d+_/,"")).includes(i)?!1:(e.value[l].push({name:n,slug:i}),s(),!0)},_=(l,n)=>{if(!e.value||S(n.slug))return!1;const i=e.value[l].findIndex(a=>a.slug===n.slug);return i>-1?(e.value[l].splice(i,1),s(),!0):!1},C=l=>{if(!e.value)return{inPipeline:!1};const n=l.replace(/^\d+_/,"");for(const i of["definition","action","finish"]){const a=e.value[i].find(r=>r.slug.replace(/^\d+_/,"")===n);if(a)return{inPipeline:!0,segment:i,column:a}}return{inPipeline:!1}};return{selectedPipeline:c,pipelineConfig:e,isDirty:f,loading:p,saving:d,loadPipeline:u,savePipeline:t,markDirty:s,generateSlug:g,allColumns:m,isValid:y,addColumn:P,removeColumn:_,isColumnInPipeline:C,addColumnBySlug:(l,n,i)=>{if(!e.value)return!1;const a=l.replace(/^\d+_/,"");return C(a).inPipeline?!1:(e.value[i].push({name:n,slug:a}),s(),!0)},removeColumnBySlug:l=>{if(!e.value)return!1;const n=l.replace(/^\d+_/,"");if(S(n))return!1;for(const i of["definition","action","finish"]){const a=e.value[i].findIndex(r=>r.slug.replace(/^\d+_/,"")===n);if(a>-1)return e.value[i].splice(a,1),s(),!0}return!1},loadActivePipeline:async()=>{if(!e.value)try{const n=(await $fetch("/api/pipelines")).find(i=>i.active);n&&(c.value=n.name,await u(n.name))}catch{}}}};export{L as a,$ as b,S as i,w as u};
