Files

2 lines
729 B
JavaScript

import{q as g,U as f,K as s,V as p,h as v,i as y,v as h}from"./index-CBgSEtCI.js";const S=g("catalog",()=>{const o=f(),n=o.peek(s.catalog),t=p(n??[]),c=v(n!==void 0),r=y(()=>{const e=new Map;for(const a of t.value)a.category&&!e.has(a.category.id)&&e.set(a.category.id,{id:a.category.id,title:a.category.title});return[...e.values()]});async function i(e=!1){const a=await o.fetch(s.catalog,async()=>(await h.listProductsPaged({page:1,limit:100,sort:"newest"})).rows,{force:e});return t.value=a,c.value=!0,a}function l(e){t.value=e,c.value=!0}function u(e){return t.value.find(a=>a.id===e)??null}function d(){o.invalidate(s.catalog)}return{products:t,loaded:c,categories:r,load:i,replace:l,byId:u,invalidate:d}});export{S as u};