var n=(e,t,r)=>new Promise((o,d)=>{var f=i=>{try{s(r.next(i))}catch(l){d(l)}},u=i=>{try{s(r.throw(i))}catch(l){d(l)}},s=i=>i.done?o(i.value):Promise.resolve(i.value).then(f,u);s((r=r.apply(e,t)).next())});import{cb as g,bf as c}from"./bootstrap-Bqxdt4iG.js";const y=g("currencies",{state:()=>({version:0}),actions:{getList(e){return n(this,null,function*(){var l,a;let t=c.from("currencies").select("*",{count:"exact"}).eq("isDelete",!1);e!=null&&e.code&&(t=t.ilike("code",`%${e.code}%`)),t=e!=null&&e.sortBy?t.order(e.sortBy,{ascending:e.sortOrder!=="desc"}):t.order("code",{ascending:!0});const r=(l=e==null?void 0:e.page)!=null?l:1,o=(a=e==null?void 0:e.pageSize)!=null?a:10,d=(r-1)*o,f=d+o-1;t=t.range(d,f);const{data:u,error:s,count:i}=yield t;if(s)throw s;return{items:u!=null?u:[],total:i!=null?i:0,page:r,pageSize:o}})},getDetail(e){return n(this,null,function*(){const{data:t,error:r}=yield c.from("currencies").select("*").eq("id",e).eq("isDelete",!1).single();if(r)throw r;return t})},create(e){return n(this,null,function*(){const{data:t,error:r}=yield c.from("currencies").insert(e).select().single();if(r||!t)throw r!=null?r:new Error("Create failed");return this.version++,t})},update(e,t){return n(this,null,function*(){const{data:r,error:o}=yield c.from("currencies").update(t).eq("id",e).select().single();if(o)throw o;return this.version++,r})},remove(e){return n(this,null,function*(){const{error:t}=yield c.from("currencies").update({isDelete:!0}).eq("id",e);if(t)throw t;return this.version++,!0})},fetchOptions(){return n(this,null,function*(){const{data:e,error:t}=yield c.from("currencies").select("id, code, symbol").eq("isDelete",!1).order("code",{ascending:!0});if(t)throw t;return(e!=null?e:[]).map(r=>({label:`${r.code} (${r.symbol})`,value:r.id}))})},fetchOptionsWithRate(){return n(this,null,function*(){const{data:e,error:t}=yield c.from("currencies").select("id, code, symbol, exchangeRate").eq("isDelete",!1).order("code",{ascending:!0});if(t)throw t;return(e!=null?e:[]).map(r=>{var o;return{label:`${r.code} (${r.symbol})`,value:r.id,exchangeRate:(o=r.exchangeRate)!=null?o:1}})})},invalidate(){this.version++}}});export{y as u};
