"use strict";(self.webpackChunkapp_lapieza=self.webpackChunkapp_lapieza||[]).push([[443],{3443:(D,g,o)=>{o.d(g,{D:()=>f});var U=o(5312),p=o(8041),_=o(8810),d=o(6354),E=o(8141),l=o(9437),c=o(8457);let f=(()=>{class h{http;apiUrl=U.c.apiUrl;constructor(e){this.http=e}getUserUserInfo(){return this.http.get(`${this.apiUrl}customer/info`,{headers:this.getHeaders(!0)}).pipe((0,d.T)(t=>t.data))}getUserUserPurchaseInfo(e){return this.http.get(`${this.apiUrl}purchase-history?page=${e}`,{headers:this.getHeaders(!0)})}getUserUserDashboardInfo(){return this.http.get(`${this.apiUrl}profile/counters`,{headers:this.getHeaders(!0)}).pipe((0,E.M)(t=>{console.log("Respuesta de la API (profile/counters):",t)}),(0,l.W)(t=>(console.error("Error en getUserUserDashboardInfo:",t),(0,_.$)(()=>new Error("Error obteniendo datos del dashboard.")))))}getUserShippingAddress(){return this.http.get(`${this.apiUrl}user/shipping/address`,{headers:this.getHeaders(!0)}).pipe((0,d.T)(t=>t.data))}getUserGeneralDetails(e){return this.http.get(`${this.apiUrl}customer/${e}`,{headers:this.getHeaders(!0)}).pipe((0,d.T)(r=>r))}createUserShippingAddress(e,t,r,a,n,i){return this.http.post(`${this.apiUrl}user/shipping/create`,{address:e,city:t,state:r,postalCode:a,country:n,phone:i},{headers:this.getHeaders(!0)})}updateUserShippingAddress(e,t,r,a,n,i,s){return this.http.post(`${this.apiUrl}user/shipping/update`,{id:e,address:t,city:r,state:a,postalCode:n,country:i,phone:s},{headers:this.getHeaders(!0)})}updateUserLocationAddress(e,t,r){return this.http.post(`${this.apiUrl}user/shipping/update-location`,{id:e,latitude:t,longitude:r},{headers:this.getHeaders(!0)})}setDefaultUserShippingAddress(e){const t=`${this.apiUrl}user/shipping/make_default`,r=localStorage.getItem("authToken")||"",a=new p.b({"Content-Type":"application/json",Authorization:`Bearer ${r}`});return this.http.post(t,{id:e},{headers:a})}removeUserShippingAddress(e){return this.http.get(`${this.apiUrl}user/shipping/delete/${e}`,{headers:this.getHeaders(!0)})}getHeaders(e=!1){let t=new p.b({"Content-Type":"application/json"});if(e){const r=localStorage.getItem("authToken")||"";r||console.warn("No auth token found in localStorage!"),t=t.set("Authorization",`Bearer ${r}`)}return t}profileUploadImage(e){const t=`${this.apiUrl}profile/update-image`,r=e.slice(0,e.size,e.type),a=new File([r],e.name,{type:e.type}),n=new FormData;n.append("image",a),console.log("Enviando archivo:",{name:a.name,type:a.type,size:a.size,lastModified:a.lastModified});let i=this.getHeaders(!0);return i.has("Content-Type")&&(i=i.delete("Content-Type")),this.http.post(t,n,{headers:i,reportProgress:!0,observe:"events"}).pipe((0,d.T)(s=>{if(s.type===p.H.UploadProgress){const u=Math.round(100*s.loaded/s.total);console.log(`Progreso: ${u}%`)}return s.type===p.H.Response?s.body:s}),(0,l.W)(s=>{throw console.error("Error en la carga:",{error:s,status:s.status,statusText:s.statusText,message:s.message,body:s.error}),s}))}static \u0275fac=function(t){return new(t||h)(c.KVO(p.a))};static \u0275prov=c.jDH({token:h,factory:h.\u0275fac,providedIn:"root"})}return h})()}}]); |