import{u as B,a as H,r as s,j as e,i as R,F as $,b as q,I as W,B as z,M as y,h as Q,v as X,s as Y,g as x,R as L,e as ee,P as se,S as te,T as ae,c as U,p as oe}from"./index-DJpKGdZI.js";const le="/assets/section-1-hero-md-D04mG7qK.png";function V(l){const{t:c}=B(),g=H(),{toggleModal:j,showModal:k}=l,[d,h]=s.useState(!1),[I,b]=s.useState(""),S=localStorage.getItem("planID"),f=localStorage.getItem("country"),a=localStorage.getItem("iso_code"),[E,u]=s.useState(!1),[m,v]=s.useState(!1),[w,A]=s.useState(""),_=async()=>{u(!0),localStorage.setItem("just-did-otp","true"),Q(`plan_id: ${S}`,"OTP","JabaaNumberVerification");try{l.signInBoolean?await X(l.mobile_number,I).then(async()=>{localStorage.getItem("do_password")!=="true"?(g({to:"/sign-in"}),l.closeAllModals&&l.closeAllModals()):g({to:`/onboarding?msisdn=${l.mobile_number}&profile=true`})}):await Y(I,parseInt(S||"")).then(async()=>{g({to:`/onboarding?msisdn=${l.mobile_number}&profile=true`})}).catch(n=>{n==="Invalid OTP."?(h(!0),u(!1)):(A(n),v(!0),u(!1))})}catch(n){h(!0),u(!1),console.warn(n)}},N=()=>{j(),h(!1)},T=async()=>{let n=localStorage.getItem("language")||"fr";await x(l.mobile_number,a||"",n).then(p=>{localStorage.removeItem("ENCELADUS"),localStorage.setItem("ENCELADUS",p.token),h(!1),u(!1)})},C=()=>{v(!1),g({to:"/"})};return e.jsxs(e.Fragment,{children:[k&&e.jsxs("div",{className:"package-select-modal",children:[e.jsx("div",{className:"dimmed-background",onClick:()=>N()}),e.jsx("div",{className:"otpmodal-content-container",children:e.jsxs("div",{className:"otpmodal-content",style:{background:"black",boxShadow:"0 3px 10px rgb(0 0 0 / 0.2)",borderRadius:"10px",backdropFilter:"blur(10px)"},children:[e.jsx("div",{className:"close-btn",onClick:()=>N(),children:e.jsx("img",{src:R})}),d?e.jsx("h1",{style:{color:"red",padding:"16px",fontSize:"30px"},children:"O.T.P Incorrect"}):e.jsx("h1",{style:{color:"red",padding:"16px",fontSize:"30px"},children:c("O.T.P Sent")}),e.jsxs("div",{className:"form-container",children:[d?e.jsx("h6",{children:"Please re-enter your O.T.P or resend to try again"}):e.jsxs("h6",{children:[c("An O.T.P has been Sent to")," ",l.mobile_number,"."]}),d?"":e.jsxs("h6",{children:[c("Please enter the code below")," :"]}),e.jsx($,{initialValues:{otp:""},onSubmit:_,children:e.jsxs(q,{children:[e.jsx(W,{type:"number",name:"otp",className:"medium",onChange:n=>{b(n.target.value)}}),e.jsx(z,{text:c("Confirm"),block:!0,type:"submit",isLoading:E})]})}),e.jsx("br",{}),e.jsx("div",{className:"join-text-link",onClick:T,children:e.jsx("span",{className:"underlined-text",children:c("Resend O.T.P")})})]})]})})]}),e.jsx(y,{showModal:m,toggleModal:()=>C(),showFooter:!0,showHeader:!1,closable:!1,size:"small",modalAnimation:"/lottie-animations/generic-error.json",bodyHeading:"Sign up Failed",bodyMessage:w,cta1Title:"Back"})]})}function re(l){const{toggleModal:c,showLinkToSignIn:g=!0}=l,[j,k]=s.useState([]),[d,h]=s.useState(!1),[I,b]=s.useState(!1),[S,f]=s.useState(!1),[a,E]=s.useState(""),[u,m]=s.useState(!1),[v,w]=s.useState(!1),[A,_]=s.useState(!1),N=H(),[T,C]=s.useState(!1),[n,p]=L.useState(!1),[D,K]=L.useState(""),[O,G]=L.useState(!1),{t:r}=B(),[J,M]=s.useState(!1),Z=async()=>{let o=localStorage.getItem("language")||"fr";m(!0),await oe(a).then(async t=>{t.profile_exists===!0?(localStorage.setItem("ENCELADUS",t.token),t.has_subscription?(G(!0),t.password_set?f(!0):(localStorage.setItem("do_password","true"),x(a,localStorage.getItem("iso_code")||"",o).then(i=>{localStorage.removeItem("ENCELADUS"),localStorage.setItem("ENCELADUS",i.token),M(!0),m(!1)}))):t.password_set?x(a,localStorage.getItem("iso_code")||"",o).then(i=>{localStorage.removeItem("ENCELADUS"),localStorage.setItem("ENCELADUS",i.token),C(!0),m(!1)}):x(a,localStorage.getItem("iso_code")||"",o).then(i=>{localStorage.removeItem("ENCELADUS"),localStorage.setItem("ENCELADUS",i.token),M(!0),m(!1),localStorage.setItem("do_password","true")})):x(a,localStorage.getItem("iso_code")||"",o).then(i=>{localStorage.removeItem("ENCELADUS"),localStorage.setItem("ENCELADUS",i.token),M(!0),m(!1),localStorage.setItem("do_password","true")})})},F=()=>{c()},P=()=>{f(!1),c(),N({to:"/sign-in"})};return s.useEffect(()=>{ee.on("showNewVersionModal",t=>{K(t.remoteVersion),p(!0)}),localStorage.setItem("country","ZA"),localStorage.setItem("iso_code","ZA");const o=async()=>{await o().then(t=>t.data.countries.map(i=>i.iso_code)).then(t=>{k(t)})};o()},[]),s.useEffect(()=>{d&&a.length>5?w(!0):w(!1)},[d,a]),e.jsx(e.Fragment,{children:e.jsxs("div",{className:"package-select-modal",children:[e.jsx("div",{className:"dimmed-background",onClick:()=>F()}),e.jsx("div",{className:"modal-content-container",children:e.jsxs("div",{className:"modal-content",children:[e.jsx("div",{className:"close-btn",onClick:()=>F(),children:e.jsx("img",{src:R})}),e.jsx("img",{src:le}),e.jsxs("div",{className:"form-container",children:[e.jsxs("h1",{children:[r("Join")," Jabaa",e.jsx("div",{style:{color:"#FF3162"},children:"Games"})]}),j.length!==0?e.jsx(se,{className:"mobile-number-input medium input",placeholder:"Enter phone number",defaultCountry:"ZA",international:!0,countries:j,countryCallingCodeEditable:!1,addInternationalOption:!1,type:"input",name:"mobile_number",smartCaret:!0,onChange:o=>{let t=o?o.replace(/\+/g,""):"";E(t)},onCountryChange:o=>{localStorage.setItem("iso_code",o)}}):e.jsx("div",{children:e.jsx(te,{style:{marginLeft:"50%",marginTop:"2%"}})}),e.jsxs("div",{className:"already-have-account-btn",children:[e.jsx("input",{type:"checkbox",id:"checkbox",onClick:()=>{h(!d)}})," ","Â P",r("I accept the")," ",e.jsx("a",{onClick:()=>{b(!0)},children:e.jsx("span",{className:"underlined-text",children:r("T&C's")})})]}),e.jsxs("a",{className:"already-have-account-btn",children:[e.jsx("br",{}),r("T&C's apply")]}),e.jsx(z,{text:r("Subscribe"),block:!0,isLoading:u,disabled:!v,onClick:()=>Z()}),g&&e.jsxs("span",{className:"already-have-account-btn",style:{cursor:"default"},children:[r("Already have an account?")," ",e.jsx("a",{href:"/sign-in",children:r("Sign In")})]})]})]})}),e.jsx(y,{showModal:I,toggleModal:()=>b(!1),showFooter:!0,showHeader:!0,headerTitle:"",closable:!1,size:"medium",translucent:!0,cta1Title:"OK",modalCTA1:()=>b(!1),children:e.jsx(ae,{})}),e.jsx(y,{showModal:S,toggleModal:()=>f(!1),showFooter:!0,showHeader:!0,headerTitle:"Already Subscribed",closable:!1,size:"medium",translucent:!0,cta1Title:"OK",modalCTA1:()=>P(),children:e.jsx("div",{className:"server-response-message",children:e.jsx("p",{children:r("This number already has an active subscription to JabaaGames, please click OK to return to the sign in page.")})})}),e.jsx(y,{showModal:n,toggleModal:()=>{p(!1),U(D)},showFooter:!0,showHeader:!0,headerTitle:"New App Version",closable:!1,size:"medium",translucent:!0,cta1Title:"OK",modalCTA1:()=>{U(D),p(!1)},children:e.jsx("div",{className:"server-response-message",children:e.jsx("p",{children:r("We've just rolled out an update to our platform. Hit the button to update.")})})}),e.jsx(V,{showModal:J,showLinkToSignIn:!1,toggleModal:()=>M(!1),mobile_number:a,signInBoolean:O}),e.jsx(V,{showModal:A,showLinkToSignIn:!1,toggleModal:()=>_(!1),mobile_number:a,signInBoolean:O}),e.jsx(V,{showModal:T,showLinkToSignIn:!1,toggleModal:()=>C(!1),signInBoolean:O,closeAllModals:()=>{P()},mobile_number:a})]})})}export{re as SelectBrandPackageModal};