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