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