import{M as T,r as s,p as w}from"./index-BzW1XhyH.js";const y="procler:recipe-last-run";function _(){try{const a=localStorage.getItem(y);return a?JSON.parse(a):{}}catch{return{}}}function L(a){try{localStorage.setItem(y,JSON.stringify(a))}catch{}}const j=T("recipes",()=>{const a=s([]),f=s(null),o=s(null),r=s(!1),t=s(null),i=s(null),c=s(_()),R=w(()=>a.value.length);async function d(){r.value=!0,t.value=null;try{const n=await(await fetch("/api/recipes")).json();n.success?a.value=n.data.recipes:t.value=n.error}catch(e){t.value=String(e)}finally{r.value=!1}}async function S(e){r.value=!0,t.value=null;try{const u=await(await fetch(`/api/recipes/${e}`)).json();u.success?f.value=u.data.recipe:t.value=u.error}catch(n){t.value=String(n)}finally{r.value=!1}}async function v(e,n=!1,u){i.value=e,t.value=null;try{const l=await(await fetch(`/api/recipes/${e}/run`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({dry_run:n,continue_on_error:u})})).json();return l.success?(o.value=l.data,n||(c.value={...c.value,[e]:Date.now()},L(c.value))):t.value=l.error,l}catch(p){return t.value=String(p),{success:!1,error:String(p)}}finally{i.value=null}}async function g(e){return v(e,!0)}function h(){o.value=null}function m(e){return c.value[e]??null}return{recipes:a,currentRecipe:f,lastRunResult:o,loading:r,error:t,runningRecipe:i,recipeCount:R,lastRunTimestamps:c,fetchRecipes:d,fetchRecipe:S,runRecipe:v,dryRunRecipe:g,clearLastResult:h,getLastRunTime:m}});export{j as u};
