1import{f as i,g as l,$ as y}from"./index-DVu_w4ho.js";const d=async(t,n)=>{try{return await t()}catch(e){if(!navigator.onLine||(e==null?void 0:e.code)==="ECONNABORTED"||(e==null?void 0:e.message)==="Network Error"||e instanceof TypeError||typeof(e==null?void 0:e.message)=="string"&&e.message.toLowerCase().includes("failed to fetch")){console.log("ð´ Sin red â encolando:",n.description);try{await y.addOperation({url:n.url,method:n.method,body:n.body,headers:l(),entityType:n.entityType,entityId:n.entityId,action:n.action,description:n.description,maxRetries:3})}catch(a){console.error("â Error guardando offline:",a)}return{success:!0,offline:!0,data:n.optimisticData??n.body??{},message:`${n.description} â Se sincronizará cuando vuelva la conexión`}}throw e}},m=t=>({...t,"Cache-Control":"no-store",Pragma:"no-cache",Expires:"0"}),c=t=>{const n=t.includes("?")?"&":"?";return`${t}${n}_ts=${Date.now()}`},u=t=>t?Array.isArray(t)?t:Array.isArray(t.data)?t.data:t.data?[t.data]:[]:[],r=t=>t?t.attributes?{id:t.id,...t.attributes}:t:null,p=t=>t&&typeof t=="object"&&"data"in t?t:{data:t};async function s(t,n={}){var o;const e=await fetch(t,{...n,headers:m(l())});if(!e.ok){const a=await e.json().catch(()=>({}));throw new Error(((o=a==null?void 0:a.error)==null?void 0:o.message)||`Error ${e.status}`)}return e.json()}const h={INGRESADO:"Ingresado",ASIGNADO:"Asignado",RECOGIDO:"Recogido en Tienda/Bodega",EN_RUTA:"En Ruta de Entrega",ENTREGADO:"Entregado",PROBLEMA:"Con Problema",CANCELADO:"Cancelado"},g={INGRESADO:{bg:"bg-slate-500/10",text:"text-slate-400",border:"border-slate-500/30"},ASIGNADO:{bg:"bg-indigo-500/10",text:"text-indigo-400",border:"border-indigo-500/30"},RECOGIDO:{bg:"bg-amber-500/10",text:"text-amber-400",border:"border-amber-500/30"},EN_RUTA:{bg:"bg-blue-500/10",text:"text-blue-400",border:"border-blue-500/30"},ENTREGADO:{bg:"bg-emerald-500/10",text:"text-emerald-400",border:"border-emerald-500/30"},PROBLEMA:{bg:"bg-rose-500/10",text:"text-rose-400",border:"border-rose-500/30"},CANCELADO:{bg:"bg-muted",text:"text-muted-foreground",border:"border-border"}},E={async getAll(t){const n="shipment-envios?populate=*&sort=createdAt:desc",e=t?`${n}&${t}`:n,o=await s(c(i(e)));return u(o).map(r)},async getPendingCommercialOrders(){const t=await s(c(i("shop-ordenes?populate=*&sort=createdAt:desc&pagination[limit]=100")));return u(t).map(r)},async getById(t){if(/^\d+$/.test(String(t))){const o=await s(c(i(`shipment-envios?filters[id][$eq]=${t}&populate=*`)));return u(o).map(r)[0]||null}const e=await s(c(i(`shipment-envios/${t}?populate=*`)));return r(e.data||e)},async create(t){const n=p(t),e=await d(async()=>{const o=await s(i("shipment-envios"),{method:"POST",body:JSON.stringify(n)});return r(o.data||o)},{url:i("shipment-envios"),method:"POST",body:n,entityType:"envio",action:"create",description:"Crear envÃo",optimisticData:t});return e&&typeof e=="object"&&"offline"in e?e.data:e},async update(t,n){const e=p(n),o=await d(async()=>{const a=await s(i(`shipment-envios/${t}`),{method:"PUT",body:JSON.stringify(e)});return r(a.data||a)},{url:i(`shipment-envios/${t}`),method:"PUT",body:e,entityType:"envio",entityId:t,action:"update",description:"Actualizar envÃo",optimisticData:n});return o&&typeof o=="object"&&"offline"in o?o.data:o},async delete(t){const n=await d(async()=>(await s(i(`shipment-envios/${t}`),{method:"DELETE"}),null),{url:i(`shipment-envios/${t}`),method:"DELETE",entityType:"envio",entityId:t,action:"delete",description:"Eliminar envÃo"});n&&typeof n=="object"&&"offline"in n},async assignPilot(t,n){const e=await s(i(`shop-engine/envios/${t}/asignar-piloto`),{method:"POST",body:JSON.stringify(p({piloto:n}))});return r(e.data||e)},async updateTracking(t,n){const e=await s(i(`shop-engine/envios/${t}/tracking`),{method:"POST",body:JSON.stringify(p(n))});return r(e.data||e)}},S={async getByShipment(t){const e=/^\d+$/.test(String(t))?"filters[envio][id][$eq]":"filters[envio][documentId][$eq]",o=await s(c(i(`shipment-tracking-rutas?${e}=${t}&populate=*&sort=timestamp:asc`)));return u(o).map(r)},async getAll(t){const n="shipment-tracking-rutas?populate=*&sort=timestamp:desc",e=t?`${n}&${t}`:n,o=await s(c(i(e)));return u(o).map(r)},async create(t){const n=p(t),e=await d(async()=>{const o=await s(i("shipment-tracking-rutas"),{method:"POST",body:JSON.stringify(n)});return r(o.data||o)},{url:i("shipment-tracking-rutas"),method:"POST",body:n,entityType:"envio",action:"create",description:"Crear ruta de tracking",optimisticData:t});return e&&typeof e=="object"&&"offline"in e?e.data:e}},T={async getAll(t){const n="shipment-pilotos?populate=*&sort=nombre:asc",e=t?`${n}&${t}`:n,o=await s(c(i(e)));return u(o).map(r)},async getById(t){if(/^\d+$/.test(String(t))){const o=await s(c(i(`shipment-pilotos?filters[id][$eq]=${t}&populate=*`)));return u(o).map(r)[0]||null}const e=await s(c(i(`shipment-pilotos/${t}?populate=*`)));return r(e.data||e)},async create(t){const n=p(t),e=await d(async()=>{const o=await s(i("shipment-pilotos"),{method:"POST",body:JSON.stringify(n)});return r(o.data||o)},{url:i("shipment-pilotos"),method:"POST",body:n,entityType:"piloto",action:"create",description:"Crear piloto",optimisticData:t});return e&&typeof e=="object"&&"offline"in e?e.data:e},async update(t,n){const e=p(n),o=await d(async()=>{const a=await s(i(`shipment-pilotos/${t}`),{method:"PUT",body:JSON.stringify(e)});return r(a.data||a)},{url:i(`shipment-pilotos/${t}`),method:"PUT",body:e,entityType:"piloto",entityId:t,action:"update",description:"Actualizar piloto",optimisticData:n});return o&&typeof o=="object"&&"offline"in o?o.data:o},async delete(t){return d(async()=>(await s(i(`shipment-pilotos/${t}`),{method:"DELETE"}),null),{url:i(`shipment-pilotos/${t}`),method:"DELETE",entityType:"piloto",entityId:t,action:"delete",description:"Eliminar piloto"})}};
1export{h as S,g as a,T as b,E as s,S as t};
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.