1import{f as s,n as r,g as h}from"./index-DVu_w4ho.js";const y=e=>({...e,"Cache-Control":"no-store",Pragma:"no-cache",Expires:"0"}),l=e=>{const t=e.includes("?")?"&":"?";return`${e}${t}_ts=${Date.now()}`},b=e=>e?Array.isArray(e)?e:Array.isArray(e.data)?e.data:e.data?[e.data]:[]:[],c=e=>e?e.attributes?{id:e.id,...e.attributes}:e:null,d=e=>e&&typeof e=="object"&&"data"in e?e:{data:e};async function n(e,t={}){var i;const o=await fetch(e,{...t,headers:y(h())});if(!o.ok){const a=await o.json().catch(()=>({}));throw new Error(((i=a==null?void 0:a.error)==null?void 0:i.message)||`Error ${o.status}`)}return o.json()}const I=[{value:"ESTANTERIA",label:"EstanterÃa"},{value:"PASILLO",label:"Pasillo"},{value:"BODEGA_PISO",label:"Bodega Piso"},{value:"REFRIGERACION",label:"Refrigeración"},{value:"CONGELADOR",label:"Congelador"},{value:"VITRINA",label:"Vitrina"},{value:"BACKROOM",label:"Backroom"},{value:"OTRO",label:"Otro"}],A={async getAll(e){const t="shop-ubicacion-fisicas?populate=*&sort=codigo:asc",o=e?`${t}&${e}`:t,i=await n(l(s(o)));return b(i).map(c)},async getBySucursal(e){return this.getAll(`filters[activa][$eq]=true&filters[sucursal][documentId][$eq]=${e}`)},async getByBodega(e){return this.getAll(`filters[activa][$eq]=true&filters[bodega][documentId][$eq]=${e}`)},async getById(e){const t=await n(l(s(`shop-ubicacion-fisicas/${e}?populate=*`)));return c(t.data||t)},async create(e){const t=await n(s("shop-ubicacion-fisicas"),{method:"POST",body:JSON.stringify(d(e))}),o=c(t.data||t);return o&&r({moduleName:"Ubicación",action:"created",record:o,recordId:o.documentId||o.id,route:"/shop/locations",payload:e}),o},async update(e,t){const o=await n(s(`shop-ubicacion-fisicas/${e}`),{method:"PUT",body:JSON.stringify(d(t))}),i=c(o.data||o);return i&&r({moduleName:"Ubicación",action:"updated",record:i,recordId:i.documentId||i.id,route:"/shop/locations",payload:t}),i},async delete(e){await n(s(`shop-ubicacion-fisicas/${e}`),{method:"DELETE"}),r({moduleName:"Ubicación",action:"deleted",record:{documentId:e},recordId:e,payload:{eliminado:!0}})}},p="populate[ubicacion][fields][0]=codigo&populate[ubicacion][fields][1]=nombre&populate[ubicacion][fields][2]=tipo_ubicacion&populate[ubicacion][fields][3]=zona&populate[ubicacion][fields][4]=pasillo&populate[ubicacion][fields][5]=estanteria&populate[ubicacion][fields][6]=fila&populate[ubicacion][fields][7]=columna&populate[ubicacion][fields][8]=nivel&populate[ubicacion][fields][9]=posicion&populate[producto][fields][0]=nombre&populate[producto][fields][1]=sku&populate[variante][fields][0]=nombre&populate[variante][fields][1]=sku&populate[insumo][fields][0]=nombre&populate[insumo][fields][1]=sku&populate[sucursal][fields][0]=nombre&populate[bodega][fields][0]=nombre",O={async getAll(e){const t=`shop-stock-ubicaciones?${p}&sort=createdAt:desc`,o=e?`${t}&${e}`:t,i=await n(l(s(o)));return b(i).map(c)},async getByProducto(e){return this.getAll(`filters[producto][documentId][$eq]=${e}`)},async getByVariante(e){return this.getAll(`filters[variante][documentId][$eq]=${e}`)},async getByInsumo(e){return this.getAll(`filters[insumo][documentId][$eq]=${e}`)},async getByUbicacion(e){return this.getAll(`filters[ubicacion][documentId][$eq]=${e}`)},async findExisting(e,t,o){const i=`filters[ubicacion][documentId][$eq]=${e}&filters[${t}][documentId][$eq]=${o}`,a=await this.getAll(i);return a.length>0?a[0]:null},async getById(e){const t=await n(l(s(`shop-stock-ubicaciones/${e}?${p}`)));return c(t.data||t)},async create(e){const t=await n(s("shop-stock-ubicaciones"),{method:"POST",body:JSON.stringify(d(e))}),o=c(t.data||t);return o&&r({moduleName:"Ubicación",action:"created",record:o,recordId:o.documentId||o.id,route:"/shop/locations",payload:e}),o},async update(e,t){const o=await n(s(`shop-stock-ubicaciones/${e}`),{method:"PUT",body:JSON.stringify(d(t))}),i=c(o.data||o);return i&&r({moduleName:"Ubicación",action:"updated",record:i,recordId:i.documentId||i.id,route:"/shop/locations",payload:t}),i},async delete(e){await n(s(`shop-stock-ubicaciones/${e}`),{method:"DELETE"}),r({moduleName:"Ubicación",action:"deleted",record:{documentId:e},recordId:e,payload:{eliminado:!0}})},async upsertStock(e,t,o,i,a){const u=await this.findExisting(e,t,o);
1if(u){const m=Number(u.cantidad||0)+i,g=Number(u.cantidad_disponible||0)+i;return this.update(u.documentId||u.id,{cantidad:m,cantidad_disponible:g,ultimo_movimiento:new Date().toISOString()})}const f={producto:"PRODUCTO",variante:"VARIANTE",insumo:"INSUMO"};return this.create({tipo_item:f[t],[t]:o,ubicacion:e,cantidad:i,cantidad_reservada:0,cantidad_disponible:i,ultimo_movimiento:new Date().toISOString(),activo:!0,...a!=null&&a.sucursal?{sucursal:a.sucursal}:{},...a!=null&&a.bodega?{bodega:a.bodega}:{}})}};export{I as T,O as s,A as u};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.