var S=Object.defineProperty,E=Object.defineProperties;var I=Object.getOwnPropertyDescriptors;var k=Object.getOwnPropertySymbols;var h=Object.prototype.hasOwnProperty,g=Object.prototype.propertyIsEnumerable;var y=(e,t,r)=>t in e?S(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,q=(e,t)=>{for(var r in t||(t={}))h.call(t,r)&&y(e,r,t[r]);if(k)for(var r of k(t))g.call(t,r)&&y(e,r,t[r]);return e},T=(e,t)=>E(e,I(t));var a=(e,t)=>{var r={};for(var o in e)h.call(e,o)&&t.indexOf(o)<0&&(r[o]=e[o]);if(e!=null&&k)for(var o of k(e))t.indexOf(o)<0&&g.call(e,o)&&(r[o]=e[o]);return r};var s=(e,t,r)=>new Promise((o,n)=>{var d=i=>{try{c(r.next(i))}catch(f){n(f)}},u=i=>{try{c(r.throw(i))}catch(f){n(f)}},c=i=>i.done?o(i.value):Promise.resolve(i.value).then(d,u);c((r=r.apply(e,t)).next())});import{cb as L,bf as l}from"./bootstrap-Bqxdt4iG.js";import{t as D}from"./tms-trucks-U21Gru7Z.js";const N="*, vendor:vendors(code, name)";function b(e){var n,d,u,c;const o=e,{vendor:t}=o,r=a(o,["vendor"]);return T(q({},r),{vendorCode:(d=(n=t==null?void 0:t.code)!=null?n:r.vendorCode)!=null?d:"",vendorName:(c=(u=t==null?void 0:t.name)!=null?u:r.vendorName)!=null?c:""})}const B=L("tms-trucks",{state:()=>({version:0}),actions:{getTruckTypeLabel(e){var t,r;return(r=(t=D.find(o=>o.value===e))==null?void 0:t.label)!=null?r:e},getTruckTypeColor(e){var t,r;return(r=(t=D.find(o=>o.value===e))==null?void 0:t.color)!=null?r:"default"},getList(e){return s(this,null,function*(){var v,w;let t=l.from("trucks").select(N,{count:"exact"}).eq("isDelete",!1);e!=null&&e.vendorId&&(t=t.eq("vendorId",e.vendorId)),e!=null&&e.truckNo&&(t=t.ilike("truckNo",`%${e.truckNo}%`)),e!=null&&e.truckType&&(t=t.eq("truckType",e.truckType)),t=e!=null&&e.sortBy?t.order(e.sortBy,{ascending:e.sortOrder!=="desc"}):t.order("createdAt",{ascending:!1});const r=(v=e==null?void 0:e.page)!=null?v:1,o=(w=e==null?void 0:e.pageSize)!=null?w:10,n=(r-1)*o,d=n+o-1;t=t.range(n,d);const{data:u,error:c,count:i}=yield t;if(c)throw c;return{items:(u!=null?u:[]).map(C=>b(C)),total:i!=null?i:0,page:r,pageSize:o}})},getDetail(e){return s(this,null,function*(){const{data:t,error:r}=yield l.from("trucks").select(N).eq("id",e).eq("isDelete",!1).single();if(r)throw r;return t?b(t):null})},create(e){return s(this,null,function*(){const{data:t,error:r}=yield l.from("trucks").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("trucks").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("trucks").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 l.from("trucks").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 l.from("trucks").delete().eq("id",e);if(t)throw t;return this.version++,!0})},fetchOptions(e){return s(this,null,function*(){let t=l.from("trucks").select("*").eq("isDelete",!1).order("truckNo",{ascending:!0});e&&(t=t.eq("vendorId",e));const{data:r,error:o}=yield t;if(o)throw o;return(r!=null?r:[]).map(n=>({label:n.truckNo,value:n.id,truck:n}))})},invalidate(){this.version++}}});export{B as u};
