1import{r as c,j as e}from"./app-B0LAPjbu.js";import{c as F}from"./clientFlashStore-D5iliP8u.js";import{p as U,A as ue,e as me}from"./api-DkFJNxXY.js";import{c as G}from"./createLucideIcon-Cz66Tp46.js";import{B as pe}from"./Button-B8IzboFJ.js";import{B as xe}from"./BaseLayout-zj00W11N.js";import"./app-Ci0Z6NIf.js";import"./LoginController-B83tSgMb.js";import"./FloatingAlert-DwWSSqNs.js";import"./FlashAlert-EdNkUCwL.js";import"./Icons-Dzn32PKW.js";import"./Footer-B1Xovpr1.js";import"./paypal-js-c7UYulfR.js";import"./Navbar-CRBgTh9H.js";import"./ClientProfileController-B-i96EOg.js";import"./NavbarItems-BYgFGm9F.js";const he=[["path",{d:"m12 19-7-7 7-7",key:"1l729n"}],["path",{d:"M19 12H5",key:"x3x0zl"}]],fe=G("ArrowLeft",he);const be=[["path",{d:"M5 12h14",key:"1ays0h"}],["path",{d:"m12 5 7 7-7 7",key:"xquz4c"}]],ye=G("ArrowRight",be),O={day:1,week:2,month:3,year:4};function ge(t){const n=(t||"").toLowerCase().trim();return n.endsWith("s")?n.slice(0,-1):n}function ve(t,n){return t==="day"?n===1?"dÃa":"dÃas":t==="week"?n===1?"semana":"semanas":t==="month"?n===1?"mes":"meses":t==="year"?n===1?"año":"años":t}function Z(t,n){const o=Number(n==="renew"?t.expiration||0:t.validity||0),a=n==="renew"?t.expirationUnits:t.validityUnits,i=ge(a);return{value:o,unit:i}}function we(t,n){const{value:o,unit:a}=Z(t,n);return`${o}-${a}`}function K(t,n){const o=new Map;for(const a of t){const{value:i,unit:m}=Z(a,n);if(!i||!m)continue;const p=`${i}-${m}`;o.has(p)||o.set(p,{key:p,value:i,unit:m,label:`${i} ${ve(m,i)}`})}return Array.from(o.values()).sort((a,i)=>{const m=O[a.unit]??999,p=O[i.unit]??999;return m!==p?m-p:i.value-a.value})}function je(t,n){const o={};for(const a of t){const i=we(a,n);(o[i]??=[]).push(a)}return o}const z=t=>{const n=typeof t=="number"?t:Number(String(t).replace(/[^\d.]/g,""));return Number.isNaN(n)?String(t):n.toFixed(2)},Ne=({items:t,selectedKey:n,onSelect:o,page:a,onPageChange:i})=>{const p=c.useMemo(()=>Math.max(1,Math.ceil(t.length/4)),[t.length]),k=c.useMemo(()=>{const u=a*4;return t.slice(u,u+4)},[t,a]),b=t.length>4,x=a>0,v=a<p-1,w=Math.max(0,4-k.length);return e.jsx("div",{className:"h-full min-h-0",children:e.jsxs("div",{className:"flex items-center gap-2 sm:gap-3",children:[e.jsx("button",{type:"button",onClick:()=>x&&i(a-1),disabled:!x||!b,className:["shrink-0 grid place-items-center rounded-full transition","h-9 w-9 sm:h-10 sm:w-10","text-secondary",b?x?"hover:bg-slate-100":"opacity-30 cursor-not-allowed":"invisible"].join(" "),"aria-label":"Anterior",children:e.jsx(fe,{className:"h-5 w-5 sm:h-6 sm:w-6",strokeWidth:3})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:["grid grid-cols-2 gap-2 sm:gap-4","min-h-24 sm:min-h-35"].join(" "),children:[k.map(u=>{const l=`${u.id}-${u.supplementaryId??u.id}`,h=n===l;return e.jsxs("button",{type:"button",onClick:()=>o(l),className:["w-full rounded-full border-2 transition","overflow-hidden flex items-stretch bg-white","h-10 sm:h-11",h?"border-[#EA6682]":"border-neutral-700 hover:border-neutral-800"].join(" "),children:[e.jsxs("span",{className:["flex-1 flex items-center justify-center","px-2 sm:px-4","text-xs sm:text-sm font-semibold whitespace-nowrap",h?"text-[#EA6682]":"text-secondary","bg-white"].join(" "),children:[u.data," GB"]}),e.jsxs("span",{className:["flex items-center justify-center whitespace-nowrap","px-3 sm:px-5","text-xs sm:text-sm font-extrabold","rounded-full",h?"bg-[#EA6682] text-white border-primary":"bg-neutral-700 text-white border-neutral-700"].join(" "),children:["$",z(u.publicPrice)]})]},l)}),Array.from({length:w}).map((u,l)=>e.jsx("div",{className:"h-10 sm:h-11 opacity-0"},`empty-${l}`))]}),b&&e.jsx("div",{className:"mt-3 sm:mt-4 flex items-center justify-center gap-2",children:Array.from({length:p}).map((u,l)=>{const h=l===a;return e.jsx("button",{type:"button",onClick:()=>i(l),className:["h-2 rounded-full transition",h?"w-6 bg-[#EA6682]":"w-2 bg-slate-300 hover:bg-slate-400"].join(" "),"aria-label":`Ir a página ${l+1}`},l)})})]}),e.jsx("button",{type:"button",onClick:()=>v&&i(a+1),disabled:!v||!b,className:["shrink-0 grid place-items-center rounded-full transition","h-9 w-9 sm:h-10 sm:w-10","text-secondary",b?v?"hover:bg-slate-100":"opacity-30 curs
1or-not-allowed":"invisible"].join(" "),"aria-label":"Siguiente",children:e.jsx(ye,{className:"h-5 w-5 sm:h-6 sm:w-6",strokeWidth:3})})]})})};function ke({tabs:t,activeKey:n,onChange:o}){return e.jsx("div",{className:"flex flex-wrap items-center justify-center gap-2",children:t.map(a=>{const i=a.key===n;return e.jsx("button",{type:"button",onClick:()=>o(a.key),className:["rounded-full px-4 py-2 text-sm font-semibold transition",i?"bg-[#EA6682] text-white shadow":"bg-slate-100 text-slate-700 hover:bg-slate-200"].join(" "),children:a.label},a.key)})})}function Ae({tabs:t,activeTabKey:n,onTabChange:o,items:a,selectedOfferKey:i,onSelect:m,page:p,onPageChange:k,onCancel:b,onContinue:x,canContinue:v,msisdn:w,action:u}){const[l,h]=c.useState(!1),[f,A]=c.useState(!1),j=a.find(E=>`${E.id}-${E.supplementaryId??E.id}`===i),C=async()=>{if(!l){h(!0);return}if(!(f||!v))try{A(!0),await x()}catch(E){console.error("No se pudo completar la recarga o renovación:",E)}finally{A(!1)}},_=()=>{if(!f){if(l){h(!1);return}b()}},S=!v||f;return e.jsxs("div",{className:"relative z-10 flex h-full min-h-0 flex-col px-4 pb-4 pt-4 sm:px-8 sm:pb-5 sm:pt-5",children:[l?e.jsx("div",{className:"flex-1 flex flex-col justify-center items-center py-4",children:e.jsxs("div",{className:"w-full max-w-xs bg-white dark:bg-transparent p-4",children:[e.jsx("h2",{className:"text-center text-base font-bold text-black-100 mb-4",children:u==="renew"?"Confirma tu renovación":"Confirma tu recarga"}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex justify-between items-center border-b border-gray-100 dark:border-neutral-800/60 pb-2",children:[e.jsx("span",{className:"text-xs font-medium text-black-100",children:"Número"}),e.jsx("span",{className:"text-sm font-semibold text-black-100",children:w})]}),e.jsxs("div",{className:"flex justify-between items-center border-b border-gray-100 dark:border-neutral-800/60 pb-2",children:[e.jsx("span",{className:"text-xs font-medium text-black-100",children:"Oferta"}),e.jsx("span",{className:"text-sm font-semibold text-black-100",children:j?`${j.data} GB`:"Oferta seleccionada"})]}),e.jsxs("div",{className:"flex justify-between items-center pt-1",children:[e.jsx("span",{className:"text-xs font-medium text-black-100",children:"Total a pagar"}),e.jsxs("span",{className:"text-lg font-black text-black-100",children:["$",j?z(j.publicPrice):"0.00"]})]})]})]})}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"mt-3 shrink-0",children:e.jsx(ke,{tabs:t,activeKey:n,onChange:o})}),e.jsx("div",{className:"mt-4 flex-1 min-h-0",children:e.jsx(Ne,{items:a,selectedKey:i,onSelect:m,page:p,onPageChange:k})})]}),e.jsxs("div",{className:"mt-5 shrink-0 grid grid-cols-1 sm:grid-cols-2 gap-3 sm:gap-4",children:[e.jsx("button",{type:"button",onClick:_,disabled:f,className:["h-11 rounded-full border-2 px-4 text-sm font-semibold transition","border-[#EA6682] text-[#EA6682]","hover:bg-[#EA6682]/10 active:scale-[0.99]",f?"cursor-not-allowed opacity-50 hover:bg-transparent active:scale-100":""].join(" "),children:l?"Atrás":"Cancelar"}),e.jsxs("button",{type:"button",onClick:C,disabled:S,"aria-busy":f,className:["flex h-11 items-center justify-center gap-2 rounded-full px-4","text-sm font-semibold transition","bg-primary text-white hover:opacity-95 active:scale-[0.99]",S?"cursor-not-allowed opacity-50 hover:opacity-50 active:scale-100":""].join(" "),children:[f&&e.jsx("span",{className:"h-4 w-4 animate-spin rounded-full border-2 border-white/40 border-t-white","aria-hidden":"true"}),f?"Procesando...":l?"Confirmar y Pagar":"Continuar"]})]})]})}const _e=({action:t="topup"})=>{const[n,o]=c.useState(""),[a,i]=c.useState(""),[m,p]=c.useState(!1),[k,b]=c.useState(null),[x,v]=c.useState([]),[w,u]=c.useState("input"),l=c.useMemo(()=>K(x,t),[x,t]),[h,f]=c.useState(""),[A,j]=c.useState(null),[C,_]=c.useState({}),S=c.useMemo(()=>n.length>=10,[n]),T=c.useMemo(()=>je(x,t),[x,t])[h]??[],I=c.useMemo(()=>A?x.find(r=>`${r.id}-${r.supplementaryId??r.id}`===A)??null:null,[A,x]),M=r=>{const d=(r??"").replace(/\D/g,"").slice(0,10),y=d.slice(0,2),g=d.slice(2,6),s=d.slice(6,10);
1return[y,g,s].filter(Boolean).join(" ")},$=()=>{u("input"),b(null),v([]),j(null),f(""),_({})};c.useEffect(()=>{w==="select"&&n!==a&&$()},[n,w,a]);const D=(r,d)=>{let y=d;if(r instanceof ue){const g=me(r.body);g.length?y=g.join(` 2`):r.message&&(y=r.message)}else if(r&&typeof r=="object"&&"message"in r){const g=String(r.message??"");g.trim()&&(y=g),F.error(y)}else F.error(y);b(y)},W=async()=>{if(!(!S||m)){p(!0),b(null);try{const r=await U("/api/topup/supplementaries",{msisdn:n,action:t}),y=(Array.isArray(r?.data?.supplementaries)?r.data.supplementaries:[]).map(s=>{const N=s.validity&&typeof s.validity=="object"?s.validity:null,P=s.id??s.identity?.id,Y=s.supplementaryId??s.identity?.supplementaryId??s.identity?.supplementary_id,ee=s.publicName??s.names?.public,te=s.altanName??s.names?.provider,se=s.publicPrice??s.pricing?.public??0,ne=s.data??s.capacity?.data??0,ae=s.minutes??s.capacity?.minutes??null,re=s.sms??s.capacity?.sms??null,ie=s.serviceType??s.service_type,oe=s.status??s.availability?.enabled??!1,B=N?.duration??s.validity??s.duration??s.expiration??0,L=s.validityUnits??N?.unit??s.validity_unit??s.validity_units??"day",le=N?.expiration??s.expiration??B??0,ce=s.expirationUnits??N?.expirationUnit??N?.expiration_unit??s.expirationUnit??s.expiration_unit??s.expiration_units??L,de=s.allowsNewLineActivation??s.availability?.allowsNewLineActivation??s.availability?.allows_new_line_activation??!1;return{...s,id:P,supplementaryId:Y,publicName:ee,altanName:te,publicPrice:Number(se),data:Number(ne),minutes:ae,sms:re,validity:Number(B),validityUnits:L,expiration:Number(le),expirationUnits:ce,serviceType:ie,status:!!oe,allowsNewLineActivation:de}}),g=K(y,t);if(v(y),j(null),i(n),g.length>0){const s=g[0].key;f(s),_(g.reduce((N,P)=>(N[P.key]=0,N),{})),u("select")}else F.warning(t==="renew"?"No encontramos renovaciones disponibles para este número.":"No encontramos recargas disponibles para este número."),u("input")}catch(r){D(r,"Error al consultar ofertas"),$()}finally{p(!1)}}},V=()=>{$(),i("")},q=async()=>{if(I)try{const d=(await U("/api/checkout/complete/create-express",{msisdn:n,offer_id:I.id,action:t}))?.data?.id_order;if(!d)throw new Error("No se creó la orden");localStorage.setItem("checkout:id_order",String(d)),window.location.href=`/checkout/pay/${d}`}catch(r){console.error("Error creando orden express:",r)}},H=r=>{f(r),_(d=>({...d,[r]:d[r]??0}))},R=w==="select",J=x.length>0,Q=R&&J?"w-162.5 max-w-162.5":"w-130 max-w-130",X=t==="renew"?"Icon_renew.svg":"Icon_recharge.svg";return e.jsx("section",{id:"recharge",className:"py-8 sm:py-12",children:e.jsx("div",{className:"mx-auto px-4 sm:px-6",children:e.jsx("div",{className:"mx-auto flex justify-center",children:e.jsxs("div",{className:["relative overflow-hidden rounded-lg border border-slate-200/60 bg-white","shadow-[0_10px_30px_rgba(15,23,42,0.12)]","transition-all duration-300 ease-out","flex flex-col",Q,"h-auto max-h-none min-h-0","sm:max-h-110 sm:min-h-78",R?"scale-100":"scale-[0.98]"].join(" "),children:[e.jsxs("div",{className:"relative shrink-0 bg-[#FFF5F8] px-4 py-4 sm:px-8",children:[e.jsx("h2",{className:"text-center text-lg font-extrabold text-[#505050] sm:text-xl",children:w==="select"&&n?`${t==="renew"?"Renovar":"Recargar"} al ${M(n)}`:t==="renew"?"Renovar lÃnea":"Recargar lÃnea"}),e.jsx("img",{src:`/img/icons/${X}`,alt:t==="renew"?"Renovar lÃnea":"Recargar lÃnea",className:"absolute w-22 h-22 -ml-4 top-1 rounded-full"})]}),e.jsx("div",{className:"relative min-h-0 flex-1",children:w==="input"?e.jsxs("div",{className:"flex h-full min-h-0 flex-col",children:[e.jsx("div",{className:"min-h-0 flex-1 px-4 sm:px-8",children:e.jsxs("div",{className:"flex h-full flex-col items-center justify-center text-center",children:[e.jsxs("div",{className:"mt-8.5 w-full",children:[e.jsx("input",{id:"msisdn",name:"msisdn",inputMode:"numeric",value:M(n),onChange:r=>{const d=r.target.value.replace(/\D/g,"");o(d)},placeholder:"Ingresa el número de teléfono",className:["w-full rounded-lg bg-[#F2F2F2] ring-0 outline-none","px-4 py-3 sm:py-4","text-base font-medium text-slate-700 sm:text-lg","placeholder:text-slate-400"].join(" ")}),k?e.jsx("div",{className:"mt-2 text-sm font-medium text-red-600",children:k}):null]}),e.jsxs("p",{className:"mt-6 mb-5 max-w-md text-sm text-[#6B7280] sm:text-base",children:["Ingresa el número de tu lÃnea existente. Aquà no compraras una SIM nueva; al continuar veras las"," ",t==="renew"?"renovaciones":"recargas"," ","disponibles para ese número."]})]})}),e.jsx("div",{className:"mt-auto shrink-0 bg-[#FFF5F8] px-4 py-5 sm:px-8 sm:py-6",children:e.jsx(pe,{type:"button",onClick:W,disabled:!S||m,className:["h-12 w-full rounded-full font-extrabold transition","text-base",!S||m?"curs
2or-not-allowed opacity-50":"active:scale-[0.99]","disabled:hover:opacity-50 disabled:active:scale-100"].join(" "),children:m?"Cargando...":"Continuar"})})]}):e.jsx("div",{className:"h-full min-h-0 animate-[rechargePop_.25s_ease-out]",children:e.jsx(Ae,{tabs:l,activeTabKey:h,onTabChange:H,items:T,selectedOfferKey:A,onSelect:j,page:C[h]??0,onPageChange:r=>_(d=>({...d,[h]:r})),onCancel:V,onContinue:q,canContinue:!!I,msisdn:M(n),action:t})})}),e.jsx("style",{children:` 3 @keyframes rechargePop { 4 from { transform: scale(.98); opacity: 0; } 5 to { transform: scale(1); opacity: 1; } 6 } 7 `})]})})})})};function Ze({action:t="topup"}){return e.jsx(xe,{children:e.jsx(_e,{action:t})})}export{Ze as default};
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.