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