1import{D as e,E as t,Ht as n,On as r,Qn as i,_ as a,b as o,bt as ee,ct as s,ft as c,g as l,k as u,mt as d,nr as f,o as p,qt as m,tt as h,un as te,v as ne,vn as g,y as _}from"./C2bBK_b8.js";import{J as re}from"./BU-870ZA.js";import{t as ie}from"./BRm8pp6E.js";import{M as v}from"./IAApUOHY.js";import{gr as ae}from"./D5JM-Z-I.js";import{t as oe}from"./2OXtHLdg.js";import{t as se}from"./lB_5R51E.js";import{t as ce}from"./Tn0SS0Wm.js";import{n as le,r as ue}from"./CKxbbObN.js";import{t as de}from"./DG-NwLXi.js";import{t as fe}from"./BDNMzG2s.js";import{t as pe}from"./C2ybOyJ82.js";import{t as me}from"./PQsX16pA.js";import{t as he}from"./BadZOK44.js";import{f as ge,h as y,l as _e,m as ve,p as ye,t as be}from"./DiwPRerL.js";import{t as xe}from"./BAPMHDQE.js";function Se(){return v(`otp-verify-stats`,()=>null)}var Ce={key:0,class:`form__input`},we={class:`notification notification--error`},Te={key:1,class:`form__input phone`},Ee={class:`input input--field`},De={key:0,class:`form__input`},Oe={class:`notification notification--warning`},ke={class:`form__input`},Ae={key:3,class:`form__input`},je={class:`modal__title modal__title--bold`},Me={key:0,class:`notification notification--error mb12`},Ne={class:`modal__paragraph modal__paragraph--medium modal__paragraph--center`},Pe=[`textContent`],Fe={class:`modal__form`},Ie={class:`form`},Le={class:`form__input form__input--flex form__input--spacer-large dir-ltr`,dir:`ltr`},Re={class:`form__input form__input--spacer-large`},ze={class:`counter`},Be={class:`counter__link counter__link--disable`},Ve={key:1,class:`cl-red mt8 text-center`},He={key:2,class:`mt8 text-center`},Ue={class:`input input--field`},We={class:`notification notification--info`},Ge={class:`input input--field`},Ke={class:`input input--field`},b=Object.assign(fe(u({__name:`MobileOtp`,props:{isSalesman:{type:Boolean,default:!1},isGuestCheckout:{type:Boolean,default:!1},isGenerateOtp:{type:Boolean,default:!1},disabled:{type:Boolean,default:!1},actionFlag:{default:`registration`},onlyCountries:{default:()=>[]},selectedCountry:{default:``},allowDropdown:{type:Boolean,default:!1},defaultInputMobile:{default:null},unverifiedMobileNumber:{type:Boolean,default:!1},modalId:{default:``},verificationMethod:{default:`mobile_otp`}},emits:[`verified`,`loginWithExistingMobile`,`anyDirty`],setup(u,{expose:v,emit:fe}){let b=u,x=fe,{t:S}=ie(),{apiFetch:C}=ae(),{storeCountry:qe}=de(),w=Se(),T=g(``),E=g(``),D=g(``),O=g(``),Je=g(!1),k=g(!0),A=g(!1),j=g(!1),M=g(!1),N=g(``),P=g(!1),F=l(()=>b.verificationMethod===`email_otp`),I=g(``),L=g(F.value),R=g(1);n(F,e=>{L.value=e});let z=g(!1),B=g([``,``,``,``]),V=g(``),H=g(0),U=g(!1),W=g(``),G=g(0),K=g(null),Ye=g([]),Xe=l(()=>B.value.join(``)),q=l(()=>B.value.every(e=>e!==``)),J=l(()=>b.actionFlag===`registration`),Ze=l(()=>b.defaultInputMobile?.country_code?ue(b.defaultInputMobile.country_code):b.selectedCountry?ue(b.selectedCountry):qe.value),Qe=l(()=>{let e=b.defaultInputMobile?.country_code?Ze.value:``;return e&&le(e)?e.toLowerCase():qe.value.toLowerCase()}),$e=l(()=>b.isSalesman?S(`Add customer mobile number`):S(`Phone number`));function et(e){return String(e||``).trim().toLowerCase()}let Y=l(()=>et(I.value));n(R,e=>{e>2&&!L.value&&(k.value=!0,L.value=!0,z.value=!1)});let tt=!1;function nt(e){if(!tt&&e.number&&(tt=!0,x(`anyDirty`)),T.value=e.number,D.value=e.countryCode,Je.value=e.isValid,e.isValid){k.value=!1;let t=K.value?.getSelectedCountryData();t?.dialCode&&(E.value=ye(t.dialCode));let n=K.value?.getNumber()||e.number;O.value=ve(y(ge(n,E.value)),E.value)}else k.value=!0}async function X(){if(L.value&&!be.test(Y.value)){N.value=S(`Please provide valid e-mail address.`);return}N.value=``,W.value=``,k.value=!0,A.value=!0,B.value=[``,``,``,``];try{if(J.value&&!b.isGenerateOtp&&!L.value){console.debug(`[MobileOtp][validateMobile][start]`,{mobile:O.value});let e=await C(`/v2/{storeCode}/user/validate-mobile`,{method:`POST`,body:{isd_code:E.value,mobile_number:O.value,action_flag:b.actionFlag}});if(k.value=!1,e?.code===200&&e?.status){let t=e.data?.otp_id??e.result?.otp_id;t&&(V.value=String(t),z.value=!0,Q(),console.debug(`[MobileOtp][validateMobile][success]`,{otpId:V.value}),h(()=>$(0)))}else e?.type===`COMMERCE_CUSTOMER_MOBILE_NUMBER_ALREADY_EXIST`?P.value=!0:(N.value=e?.message||S(`Failed to send verification code`),console.debug(`[MobileOtp][validateMobile][failed]`,{message:N.value}))}else{console.debug(`[MobileOtp][generateOTP][start]`,{mobile:O.value,emailVisible:L.value});let e=await C(`/v2/{storeCode}/sms/generateOTP`,{method:`POST`,body:{mobile_code:L.value?``:E.value,mobile_number:L.value?``:O.value,email:L.value?Y.value:``}});k.value=!1;
1let t=e?.data?.otp_id??e?.result?.otp_id;(e?.success||e?.status||e?.code===200)&&t&&t?(V.value=String(t),z.value=!0,Q(),console.debug(`[MobileOtp][generateOTP][success]`,{otpId:V.value}),h(()=>$(0))):e?.type===`COMMERCE_CUSTOMER_MOBILE_NUMBER_ALREADY_EXIST`?P.value=!0:(N.value=e?.message||S(`Failed to send verification code`),console.debug(`[MobileOtp][generateOTP][failed]`,{message:N.value}))}}catch(e){k.value=!1,N.value=S(`Failed to send verification code`),console.error(`[MobileOtp][sendVerificationCode][error]`,e)}finally{A.value=!1}}async function rt(){P.value=!1,N.value=``,k.value=!0,A.value=!0,B.value=[``,``,``,``];try{console.debug(`[MobileOtp][sendOtp][start]`,{mobile:O.value});let e=await C(`/v2/{storeCode}/sms/generateOTP`,{method:`POST`,body:{mobile_code:E.value,mobile_number:O.value}});k.value=!1;let t=e?.data?.otp_id??e?.result?.otp_id;(e?.success||e?.status||e?.code===200)&&t&&t?(V.value=String(t),z.value=!0,Q(),console.debug(`[MobileOtp][sendOtp][success]`,{otpId:V.value}),h(()=>$(0))):(N.value=e?.message||S(`Failed to send verification code`),console.debug(`[MobileOtp][sendOtp][failed]`,{message:N.value}))}catch(e){k.value=!1,N.value=S(`Failed to send verification code`),console.error(`[MobileOtp][sendOtp][error]`,e)}finally{A.value=!1}}let Z=null;function Q(){H.value=60,Z&&clearInterval(Z),Z=pe(()=>{H.value--,H.value<=0&&(clearInterval(Z),Z=null,b.isGuestCheckout&&!b.isGenerateOtp&&!J.value&&R.value++)},1e3)}function $(e){let t=Ye.value[e];t&&(t.$el?.querySelector(`input`)??t)?.focus()}function it(e,t){let n=y(t).slice(0,1);B.value[e]=n,n&&e<3&&$(e+1)}function at(e,t){t.key===`Backspace`&&!B.value[e]&&e>0&&$(e-1)}function ot(e){let t=y(e.clipboardData?.getData(`text`)||``);/^\d{4}$/.test(t)&&(B.value=t.split(``),$(3),e.preventDefault())}async function st(){if(q.value){W.value=``,k.value=!0,U.value=!0,console.debug(`[MobileOtp][verifyOtp][start]`,{otpId:V.value});try{let e=await C(`/v2/{storeCode}/sms/verifyOTP`,{method:`POST`,body:{otp_text:Xe.value,otp_id:V.value,mobile_code:L.value?``:E.value,mobile_number:L.value?``:O.value,...Y.value?{email:Y.value}:{}}});k.value=!1,e?.status?(j.value=!0,M.value=!0,z.value=!1,G.value=0,console.debug(`[MobileOtp][verifyOtp][success]`,{mobile:O.value}),b.actionFlag===`login`&&(w.value={otpId:V.value,mobileNo:O.value,countryCallingCode:E.value,countryCode:D.value,...Y.value?{email:Y.value}:{}}),h(()=>{x(`verified`,{mobile:O.value,isd:E.value,countryCode:D.value,state:!0,otp_id:V.value,otp_text:Xe.value,method:L.value?`email`:`mobile`,...Y.value?{email:Y.value}:{}})})):(W.value=e?.message||S(`Invalid verification code`),console.debug(`[MobileOtp][verifyOtp][failed]`,{message:W.value}))}catch(e){k.value=!1,W.value=S(`Failed to verify code`),console.error(`[MobileOtp][verifyOtp][error]`,e)}finally{U.value=!1}}}function ct(){H.value>0||(J.value&&G.value++,B.value=[``,``,``,``],W.value=``,X())}function lt(){z.value=!1,B.value=[``,``,``,``],W.value=``,Z&&=(clearInterval(Z),null)}function ut(){x(`loginWithExistingMobile`,O.value)}function dt(){z.value=!1,T.value=``,E.value=``,O.value=``,k.value=!1,j.value=!1,P.value=!1,M.value=!1}function ft(){T.value=``,E.value=``,O.value=``,k.value=!0,j.value=!1,P.value=!1,M.value=!1,I.value=``,L.value=!1,R.value=1,G.value=0,B.value=[``,``,``,``],W.value=``,N.value=``,w.value=null}function pt(e){e.key===`Enter`&&(z.value&&q.value&&!U.value?st():!z.value&&!k.value&&!j.value&&X())}return s(async()=>{if(window.addEventListener(`keydown`,pt),w.value){let e=w.value;T.value=e.mobileNo,E.value=e.countryCallingCode,D.value=e.countryCode,O.value=e.mobileNo,V.value=e.otpId,I.value=e.email??``,j.value=!0,M.value=!0,k.value=!0,await h(),K.value?.setNumber(e.mobileNo);return}b.defaultInputMobile&&Object.keys(b.defaultInputMobile).length&&(T.value=b.defaultInputMobile.mobile_number,E.value=b.defaultInputMobile.isd_code,O.value=b.defaultInputMobile.mobile_number,j.value=!0,P.value=!0,M.value=!0,k.value=!0,await h(),K.value?.setNumber(b.defaultInputMobile.mobile_number),X())}),c(()=>{window.removeEventListener(`keydown`,pt),Z&&clearInterval(Z)}),v({otpVerified:j,mobileNumber:O,dialCode:E,countryCode:D,resetInputs:ft}),(n,s)=>{let c=se,l=he,h=xe,g=ce,ie=me,v=oe;return d(),o(`div`,null,[r(N)?(d(),o(`div`,Ce,[a(`div`,we,[e(c,{"icon-id":`error-circle`,class:`notification__icon`}),a(`span`,null,f(r(N)),1)])])):_(``,!0),r(F)?_(``,!0):(d(),o(`div`,Te,[a(`div`,Ee,[e(l,{ref_key:`phoneInputRef`,ref:K,modelValue:r(T),"onUpdate:modelValue":s[0]||=e=>te(T)?T.value=e:null,label:r($e),disabled:r(M)||u.disabled,"only-countries":u.onlyCountries.length?u.onlyCountries:[r(Qe)],"initial-country":r(Ze).toLowerCase(),"allow-dropdown":u.allowDropdown,onChange:nt},null,8,[`modelValue`,`label`,`disabled`,`only-countries`,`initial-country`,`allow-dropdown`]),r(j)?(d(),ne(c,{key:0,"icon-id":`completed-circle`,class:`input__icon`})):_(``,!0)])])),r(L)?(d(),o(p,{key:2},[r(F)?_(``,!0):(d(),o(`div`,De,[a(`div`,Oe,[e(c,{"icon-id":`warning`,class:`notification__icon`}),t(` `+f(r(S)(`Still having problems with code?`))+` `,1),a(`b`,null,f(r(S)(`Verify by email instead`)),1)])])),a(`div`,ke,[e(h,{"model-value":r(I),type:`email`,name:`email`,autocomplete:`email`,maxlength:255,label:r(F)?r(S)(`Email Address`):r(S)(`Email`),"onUpdate:modelValue":s[1]||=e=>I.value=et(e)},null,8,[`model-value`,`label`])])],64)):_(``,!0),!r(j)&&!r(P)?(d(),o(`div`,Ae,[e(g,{class:i([`button--secondary button--fluid`,{async:r(A)}]),type:`button`,disabled:r(k)&&!r(L)||r(A),onClick:s[2]||=e=>X()},{default:m(()=>[t(f(r(S)(`Send Verification Code`)),1)]),_:1},8,[`class`,`disabled`])])):_(``,!0),e(v,{modelValue:r(z),"onUpdate:modelValue":s[3]||=e=>te(z)?z.value=e:null,size:`small`,"header-variant":[`shadow`,`center`],"content-variant":`space-medium`,"close-position":`right`,"click-to-close":!1,"esc-to-close":!1,onClose:lt},{header:m(()=>[e(c,{class:`modal__icon`,"icon-id":`completed-fill`}),a(`h4`,je,f(r(L)?r(S)(`Verify Email`):r(S)(`Verify Mobile Number`)),1)]),default:m(()=>[r(W)?(d(),o(`div`,Me,[e(c,{"icon-id":`error-circle`,class:`notification__icon`}
1),t(` `+f(r(W)),1)])):_(``,!0),a(`p`,Ne,[a(`b`,null,[t(f(r(S)(r(L)?`Please enter the code sent to email: `:`Please enter the code sent by WhatsApp or SMS to: `))+` `,1),a(`span`,{class:`ar-number`,textContent:f(r(L)?r(_e)(r(I)):r(T).replace(/(\d{3})(.*)(\d{3})/,`$1******$3`))},null,8,Pe)])]),e(ie,{loading:r(A)},null,8,[`loading`]),a(`div`,Fe,[a(`div`,Ie,[a(`div`,Le,[(d(),o(p,null,ee(4,(t,n)=>e(h,{key:n,ref_for:!0,ref:e=>{r(Ye)[n]=e},type:`tel`,class:`input--small`,name:`verificationCode`,"input-class":`input__field--center`,"model-value":r(B)[n],maxlength:1,disabled:r(U),autocomplete:`one-time-code`,"is-number":``,onInput:e=>it(n,e),onKeyup:e=>at(n,e),onPaste:ot},null,8,[`model-value`,`disabled`,`onInput`,`onKeyup`])),64))]),a(`div`,Re,[e(g,{class:i([`button--secondary button--fluid`,{async:r(U)}]),type:`button`,disabled:!r(q)||r(U),onClick:st},{default:m(()=>[t(f(r(S)(`Verify`)),1)]),_:1},8,[`class`,`disabled`])])])]),a(`p`,ze,[r(H)>0?(d(),o(p,{key:0},[t(f(r(H))+` `+f(r(S)(`seconds left to`))+` `,1),a(`span`,Be,f(r(S)(`Send again`)),1)],64)):(d(),o(p,{key:1},[t(f(r(S)(`Didn't get the code?`))+` `,1),a(`a`,{href:`#`,class:`counter__link`,onClick:re(ct,[`prevent`])},f(r(S)(`Send again`)),1)],64))]),r(J)&&r(G)>=2?(d(),o(`p`,Ve,f(r(S)(`You can place an order as a guest, no need to register`)),1)):_(``,!0),u.actionFlag===`login`&&u.unverifiedMobileNumber?(d(),o(`div`,He,[a(`p`,null,f(r(S)(`No longer using this mobile number?`)),1),a(`p`,{class:`counter__link link`,onClick:re(dt,[`prevent`])},f(r(S)(`Change your mobile number`)),1)])):_(``,!0)]),_:1},8,[`modelValue`]),!r(j)&&u.actionFlag===`registration`&&r(P)?(d(),o(p,{key:4},[a(`div`,Ue,[a(`div`,We,[e(c,{"icon-id":`info`,class:`notification__icon`}),t(` `+f(r(S)(`The entered mobile number is already exist, would you like to Login or Continue to create a new account ?`)),1)])]),a(`div`,Ge,[e(g,{class:`button--secondary button--fluid`,type:`button`,onClick:ut},{default:m(()=>[t(f(r(S)(`Login`)),1)]),_:1})]),a(`div`,Ke,[e(g,{class:i([`button--secondary button--fluid`,{async:r(A)}]),type:`button`,onClick:rt},{default:m(()=>[t(f(r(S)(`Continue to create a new account`)),1)]),_:1},8,[`class`])])],64)):_(``,!0)])}}}),[[`__scopeId`,`data-v-deaa0dfa`]]),{__name:`AuthMobileOtp`});export{Se as n,b 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.