1"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[2857],{18197:(e,o,t)=>{t.d(o,{J:()=>s,Z:()=>c});var a=t(5068),n=t(2660),r=t(1992),i=t(32895);let s=()=>(0,r.useQuery)(n.J.serviceProducts.key,async()=>(await a.A.request({baseURL:"/api/",url:"productos?categoria=catalogo",method:"post"})).data,{...n.J.serviceProducts,select:e=>{let o=(0,i.ld)(e),t=o?.catalogo.toSorted((e,o)=>e.codigo-o.codigo);return{...o,catalogo:t||[]}}}),c=(e=!1)=>(0,r.useQuery)(n.J.serviceCupones.key,async()=>(await a.A.request({baseURL:"/api/",url:"productos?categoria=cupon",method:"post"})).data??[],{...n.J.serviceCupones,select:e=>e??{},enabled:e})},32857:(e,o,t)=>{t.d(o,{t:()=>h});var a=t(37936),n=t(78427),r=t(27854),i=t(14232),s=t(32895),c=t(96721),l=t(33244),u=t(77216),d=t(17833),p=t(3814),m=t(71530),g=t(6616);let h=()=>{let{appData:e,setAppData:o,clearAppData:t}=(0,i.useContext)(a.B),{setOpenDetalle:h,setProductSeleted:b}=(0,i.useContext)(n.q),{handleError:f}=(0,g.M)(),{loading:S,fetchData:v}=(0,u.A)(),{ErrorMessageRedemption:y}=(0,m.o)(),{logout:P}=(0,l.A)(),{closeSession:C}=(0,d.h)(),{clearLocalData:D}=(0,p.M)();return{registerRedemption:async(o,a,n)=>{if(a.cantidad>0)try{let r={idMember:o,origenTransaccion:e?.fromMobile?"App":"Web",numeroDocumento:e.user.numDocumento,tipoDocumento:(0,c.Xx)(e.user.tipoDocumento),itemsCatalogo:[{idItem:a.producto.identificador,nombre:a.producto.nombre,cantidad:a.cantidad}]},i=await v({method:"POST",baseURL:"https://api.terpel.com",url:"/fidelidad-terpel/redencionSales/v2.0/otp/redenciones",headers:{"Content-Type":"application/json",...(0,s.gS)(e?.redemptionFlow?.otpCode)},body:JSON.stringify(r)});if(i?.responseMessage?.codeStatus==="200")return i;if(i?.codeSeverity!="409")return n(i?.redencion?.mensaje?.toLowerCase()?.includes("no se encuentra registrado o su estado no es activo")?{message:y(i?.redencion?.mensaje),title:"No fue posible completar tu transacci\xf3n",type:"error",open:!0,action:()=>{P("useRedemption"),C("useRedemption"),t(),D()}}:{message:y(i?.redencion?.mensaje),title:"No fue posible completar tu transacci\xf3n",type:"error",open:!0}),null;n({message:"Alcanzaste el l\xedmite de redenciones para este bono. Te invitamos a intentarlo m\xe1s adelante; la disponibilidad puede habilitarse en los pr\xf3ximos d\xedas.",title:"Alcanzaste tu l\xedmite de redenciones para este bono",type:"error",open:!0,textButton:"Ok, comprendo",action:()=>{h(!1),b(void 0)}})}catch(o){return f(o,{functionName:"registerRedemptions",component:"useRedemption",userPhone:e.user.celular}),null}},generatingVoucher:S,updateRedemptionData:async t=>{if(!t?.redencion)return;let{puntos:a,transactions:n}=e;n?.transactions?.unshift({nombre:t.redencion.nombre,fecha:t.redencion.fecha,hora:t.redencion.hora,pdv:t.redencion.tipoTransaccion,puntos:t.redencion.puntos,total:t.redencion.total,id:t.redencion.id,estado:"Aprobada",tipoTransaccion:t.redencion.tipoTransaccion}),a.balance=t.balance,o({...e,puntos:a,transactions:n},"UPDATE_PUNTOS")},getRedemmptions:async(o,t)=>{let a=o===r.k5?"CC":o==r.yn?"PPT":"CE",n=new Date().getTime();try{let e=await v({method:"POST",baseURL:"/api/",url:"/puntos?service=detalleredenciones",body:{tip:a,numDocumento:t,Authorization:localStorage.getItem("AccessToken")}});if(!e)return null;return e?.redenciones?.forEach(e=>{e.vouchers.forEach(e=>{e.estado=(0,s.VU)(e.estado,e.lineaNegocio,e.urlImagenDos)})}),e.redenciones=e?.redenciones?.map(e=>{let o=!e.nombre?.toLowerCase().includes("puntos latam")&&!e.nombre?.toLowerCase().includes("fisica"),t=e.vouchers.filter(e=>{let t=new Date(e?.fechaLimite).getTime(),a=e?.estado?.toLowerCase()?.includes("expirado");return o&&(!a||(a?(n-t)/864e5:0)<=30)});return{...e,vouchers:t}}
1)?.filter(e=>e.vouchers.length>0),e}catch(o){return f(o,{functionName:"getRedemptions",component:"useRedemption",userPhone:e.user.celular}),null}},habilitabono:async(e,o,t)=>{try{return await v({method:"POST",baseURL:"https://api.terpel.com",url:"/legacy/validacionvoucher/v1.0/habilitabono",headers:{"Content-Type":"application/json",Authorization:localStorage.getItem("AccessToken")},body:{voucher:e,idMember:o,canal:t?"ViveTerpel App":"ViveTerpel Web"}})}catch{return[]}}}}},78427:(e,o,t)=>{t.d(o,{A:()=>g,q:()=>m});var a=t(37876),n=t(6616),r=t(12047),i=t(18197),s=t(89099),c=t(14232),l=t(55225),u=t(32895),d=t(13663),p=t(37936);let m=(0,c.createContext)({productos0:[],productos1:[],productos2:[],subProductos:[],nameCategory:[],selectedFilter:"",isLoading:!1,lineasDeNegocio:[],cantidadBonos:0,comprarSoat:!1,valueFilter:"",openDetalle:!1,bonoSelected:!1,page:0,setPage:()=>{},setBonoSelected:()=>{},setProductSeleted:()=>{},handleClickProduct:()=>{},consultarProductos:()=>{},handleOpenModal:()=>{},handleCloseDetalle:()=>{},setCantidadBonos:()=>{},setComprarSoat:()=>{},handleChangeFilter:()=>{},setOpenDetalle:()=>{},setValueFilter:()=>{},consultarSubMenuProductos:()=>{}}),g=({children:e})=>{let{appData:o,msgAlert:t,puntosData:g,componentname:h,callbackAlerta:b}=(0,c.useContext)(p.B),[f,S]=(0,c.useState)(),[v,y]=(0,c.useState)([]),[P,C]=(0,c.useState)([]),[D,T]=(0,c.useState)([]),[N,w]=(0,c.useState)([]),[A,R]=(0,c.useState)(""),[_,k]=(0,c.useState)([]),[E,M]=(0,c.useState)([]),[L,I]=(0,c.useState)(!1),[x,O]=(0,c.useState)(0),[U,q]=(0,c.useState)(!1),[J,j]=(0,c.useState)(""),[B,F]=(0,c.useState)(!1),[V,z]=(0,c.useState)(0),{data:Q,isLoading:W}=(0,i.J)(),{handleTrack:X}=(0,n.M)(),{registerEventToAnalytics:Z}=(0,r.P)(),G=(0,s.useRouter)(),H=e=>{if(window.scrollTo({top:0,behavior:"smooth"}),!o.fromMobile&&window.gtag&&d.f0({action:"btn_redimir_producto",category:e?.lineaDeNegocio,label:"compra-iniciada",value:e?.identificador}),e?.subcategoria==="Soat"&&q(!0),O(1),S(e),L)return I(!1);X(o.fromMobile,"REDEEM_START"),g?.balance>=e?.puntos?I(!0):"invitado"!==h&&(I(!1),S(void 0),b({title:"Puntos insuficientes",message:"Contin\xfaa acumulando puntos ViveTerpel y disfruta de m\xe1s beneficios.",type:"warning",open:!0}))},K=async()=>{let e,o=[],a=Q?.catalogo??[];a.forEach(t=>{let a=o.find(e=>e.nombre===t.lineaDeNegocio);e!==t.lineaDeNegocio&&(!a&&t.lineaDeNegocio&&o.push({nombre:t.lineaDeNegocio}),e=t.lineaDeNegocio)}),k(o.toSorted((e,o)=>(0,u.id)(e.nombre,o.nombre)));let n=[...a].filter(e=>"L\xedquidos"===e.lineaDeNegocio||"Combustible"===e.lineaDeNegocio),r=[...a].filter(e=>"Tiendas"===e.lineaDeNegocio||"Altoque"===e.lineaDeNegocio);y(a),C(n),T(r),a&&(()=>{if(localStorage.getItem("prodId")){let e=localStorage.getItem("prodId");localStorage.removeItem("prodId");let o=v.find(o=>o.identificador===e);o?H(o):b({...t,message:"El producto no esta disponible",type:"warning",open:!0})}})()},Y=async e=>{let o,t=[],a=Q?.catalogo?.filter(o=>[e].includes(o.lineaDeNegocio));a?.forEach(e=>{let a=t.find(o=>o.categoriaProducto?.split("-")[1]==e.categoriaProducto?.split("-")[1]);o!==e.categoriaProducto&&(a||null===e.categoriaProducto||t.push({categoriaProducto:e.categoriaProducto,lineaDeNegocio:e.lineaDeNegocio}),o=e.categoriaProducto)}),t.sort((e,o)=>e.categoriaProducto?o.categoriaProducto?(0,u.id)(e.categoriaProducto,o.categoriaProducto):-1:1),M(t),w([...a].filter(e=>e.categoriaProducto?.split("-")[1]!==null))};(0,c.useEffect)(()=>{Q&&K()},[Q]),(0,c.useEffect)(()=>{try{let{identificador:e}=G.query,o=v.find(o=>o.identificador==e);v.length>0&&g.balance>0&&o&&!L&&(H(o),G.replace((0,l.o)(G,"identificador")))}catch{}},[v,g,G]);let $={productos0:v,productos1:P,productos2:D,subProductos:N,nameCategory:E,productSeleted:f,selectedFilter:A,isLoading:W,lineasDeNegocio:_,cantidadBonos:x,comprarSoat:U,valueFilter:J,openDetalle:L,bonoSelected:B,page:V,setPage:z,setBonoSelected:F,setProductSeleted:S,handleClickProduct:e=>{if("Menos puntos"===e){y([...v].sort((e,o)=>e.puntos-o.puntos)),C([...P].sort((e,o)=>e.puntos-o.puntos)),T([...D].sort((e,o)=>e.puntos-o.puntos)),w([...N].sort((e,o)=>e.puntos-o.puntos)),R(o=>o===e?"":e),Z("click_menos_puntos","app_terpel_catalogo");return}y([...v].sort((e,o)=>o.puntos-e.puntos)),C([...P].sort((e,o)=>o.puntos-e.puntos)),T([...D].sort((e,o)=>o.puntos-e.puntos)),w([...N].sort((e,o)=>o.puntos-e.puntos)),R(o=>o===e?"":e),Z("click_mas_puntos","app_terpel_catalogo")},consultarProductos:K,handleOpenModal:H,handleCloseDetalle:()=>{S(void 0),O(1),I(!1),F(!1)},setCantidadBonos:O,setComprarSoat:q,handleChangeFilter:e=>{j(e.target.value)},setOpenDetalle:I,setValueFilter:j,consultarSubMenuProductos:Y},ee=(0,c.useMemo)(()=>$,[$]);return(0,a.jsx)(m.Provider,{value:ee,children:e})}}}]);
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.