$(()=>{const n=({passwordInputTrigger:t,passwordInput:n})=>{t&&n&&(t.onclick=()=>{if(n.type==="password"){n.type="text";return}n.type="password"})};n({passwordInputTrigger:document.querySelector("#new_password_input_trigger"),passwordInput:document.querySelector("#new_password_input")});n({passwordInputTrigger:document.querySelector("#confirm_password_input_trigger"),passwordInput:document.querySelector("#confirm_password_input")})});
$(()=>{String.prototype.padStart||(String.prototype.padStart=function(n,t){return n=n>>0,t=String(typeof t!="undefined"?t:" "),this.length>n?String(this):(n=n-this.length,n>t.length&&(t+=t.repeat(n/t.length)),t.slice(0,n)+String(this))}),window.initializeOtp=()=>{const n=document.querySelectorAll(".request_otp_button");Array.prototype.slice.call(n).forEach(n=>{n.onclick||(n.onclick=t=>{t.preventDefault();n.disabled=!0;n.classList.add("disabled");const r=n.dataset.otpAction;let i=n.dataset.otpType;if(!i){const n=document.querySelector(`.otp_type_select[data-otp-action="${r}"]`);i=n.value}var u=`/otp/request/${i}/${r}`;window.$.ajax({type:"POST",url:u,contentType:"application/json; charset=utf-8",dataType:"json",success:t=>{if(isNaN(t.expiryInSeconds)||t.expiryInSeconds<=0){n.innerText=t.message;const i=parseInt(n.dataset.intervalInSeconds)*1e3||3e4;setTimeout(()=>{n.disabled=!1,n.classList.remove("disabled"),n.innerText=n.dataset.title},i);return}let i=t.expiryInSeconds+1;const u=n=>Math.floor(n/60).toString().padStart(2,"0")+":"+Math.floor(n%60).toString().padStart(2,"0"),r=function(){if(i-=1,i<0){n.disabled=!1;n.classList.remove("disabled");n.innerText=n.dataset.title;return}n.innerText=t.message+` [${u(i)}]`;setTimeout(r,1e3)};r()}})})})},window.initializeOtp()});
$(()=>{const n=()=>registerPopup({content:"Please try again in few minutes. Code:007OR"}),t=(t,i,r,u)=>{$.ajax({type:"POST",url:`/OtpV2/OtpPopup`,data:JSON.stringify({channelType:r,actionName:u}),contentType:"application/json; charset=utf-8",dataType:"html",success:n=>{t.innerHTML=n;i.disabled=!1;const r=t.querySelector("#otp_popup");r.classList.add("open");window.initializeOtp();window.initializeOtpPopup();window.initializeChangeOtpChannelButton()},error:n})};window.initializeOtpPopupButton=()=>{const u=document.querySelectorAll(".show_otp_popup_button"),i=document.querySelector("#otp_popup_container");u.length>0&&i&&Array.from(u).forEach(u=>{const f=document.querySelector(`.input_verification_value[data-channel-type="${u.dataset.otpChannelType}"]`);u.onclick||(u.onclick=()=>{const e=document.querySelector("#contact_verification_form");e?$("#contact_verification_form").valid()&&(i.innerHTML="",u.disabled=!0,$.ajax({type:"POST",url:`/OtpV2/UpdateContact`,data:JSON.stringify({channelType:u.dataset.otpChannelType,value:f.value}),contentType:"application/json; charset=utf-8",dataType:"json",success:n=>{n.errorCode===0?t(i,u,u.dataset.otpChannelType,u.dataset.otpActionName):registerPopup({contentTitle:n.status,content:n.message,onClose:function(){location.reload()}})},error:n})):r({onSuccess:()=>t(i,u,u.dataset.otpChannelType,u.dataset.otpActionName)})})})};window.initializeOtpPopupButton();const i=(t,i,r,u,f)=>{const e=document.querySelector("#loader_container");e.classList.remove("hide");e.classList.add("display");t.innerHTML="";$.ajax({type:"POST",url:`/OtpV2/ContactVerificationForm`,data:JSON.stringify({channelType:i,actionName:r,redirectRoute:u}),contentType:"application/json; charset=utf-8",dataType:"html",success:i=>{e.classList.remove("display");e.classList.add("hide");t.innerHTML=i;const r=document.querySelector("#contact_verification_form"),u=document.querySelector(".show_otp_popup_button");r&&u&&($("#contact_verification_form").validate(),r.addEventListener("keydown",n=>{n.key==="Enter"&&n.target.nodeName==="INPUT"&&(n.preventDefault(),u.click())}));const o=document.querySelector("#whatsapp_verification_input");o&&$("#whatsapp_verification_input").rules("add",{required:!0,regex:/^(?=.*[0-9])[0-9\-]+$/,messages:{required:f.translations.whatsappRequiredMessage,regex:f.translations.whatsappDigitErrorMessage}});const s=document.querySelector("#email_verification_input");s&&$("#email_verification_input").rules("add",{required:!0,email:!0,messages:{required:f.translations.emailRequiredMessage,email:f.translations.emailErrorMessage}});r.onsubmit=t=>{t.preventDefault();const e=document.querySelector("#request_verification_token"),i=document.querySelector(".otp_hidden_input"),o=document.querySelector(".input_verification_value"),r=document.querySelector("#otp_popup_container .otp-popup-content .field-validation-error"),f=document.querySelector("#otp_submit_button");r&&r.remove();u.disabled=!0;f.disabled=!0;$.ajax({type:"POST",url:`/OtpV2/SubmitVerification`,headers:{requestVerificationToken:e.value},data:JSON.stringify({otp:i.value,value:o.value,channelType:i.dataset.channelType}),contentType:"application/json; charset=utf-8",dataType:"json",success:n=>{if(n.errorCode===0){const r=document.querySelector("#otp_popup");r.classList.remove("open");const t=document.querySelector("#verification_success_popup"),u=document.querySelector("#verification_success_message"),i=document.querySelector("#close_verification_success_btn");t&&(t.classList.add("open"),u.innerText=n.message,i&&(i.onclick=()=>{window.location.reload()}))}else{const t=document.querySelector("#otp_popup_container .otp-popup-content"),i=document.querySelector(".otp-input-container");if(t){const r=document.createElement("span");r.className="field-validation-error";r.innerText=n.message;t.insertBefore(r,i)}f.disabled=!1}},error:n})};window.initializeChangeVerificationMethod(f);window.initializeOtp();window.initializeOtpPopup();window.initializeOtpPopupButton()},error:n})};window.initializeVerificationForm=n=>{const t=document.querySelector("#contact_verification_container");t&&i(t,t.dataset.channelType,t.dataset.actionName,t.dataset.redirectRoute,n)};window.initializeChangeVerificationMethod=n=>{const t=document.querySelector("#contact_verification_container"),r=document.querySelectorAll(".change_verification_method_button");t&&r.length>0&&Array.from(r).forEach(r=>{r.onclick||(r.onclick=()=>{i(t,r.dataset.channelType,r.dataset.actionName,r.dataset.redirectRoute,n)})})};window.initializeChangeOtpChannelButton=()=>{const t=document.querySelectorAll(".change_otp_channel_button"),n=document.querySelector(".show_otp_popup_button"),i=document.querySelector(`.otp_hidden_input`);t&&Array.from(t).forEach(t=>{t.onclick||(t.onclick=()=>{i.dataset.channelType=t.dataset.channelType,n.dataset.otpChannelType=t.dataset.channelType,n.dataset.otpActionName=t.dataset.actionName,n.click()})})};const r=({onSuccess:t})=>{const i=document.querySelector("#withdrawal_form"),r=document.querySelector("#withdrawal_container"),u=document.querySelector("#error_container"),f=document.querySelector("#otp_popup");if(u&&u.remove(),i){const u=Object.fromEntries(new FormData(i).entries());$.ajax({type:"POST",url:`/Wallet/PreWithdrawalCheck`,data:JSON.stringify(u),contentType:"application/json; charset=utf-8",dataType:"json",success:n=>{if(n.errorCode===0)t();else if(f&&f.classList.remove("open"),r){const t=document.createElement("div");t.className="form-group";t.id="error_container";const u=document.createElement("div");u.className="alert-danger";u.innerText=n.message;t.appendChild(u);r.insertBefore(t,i)}},error:n})}};window.initializeOtpPopup=()=>{const t=document.querySelector("#otp_popup"),i=document.querySelector(".request_otp_button");if(t){i&&i.click();const u=document.querySelector("#otp_input");if(u){const o=t.dataset.channelType,i=document.querySelectorAll("#otp_fake_inputs div"),f=document.querySelector(`.otp_hidden_input[data-channel-type="${o}"]`),e=document.querySelector("#otp_submit_button"),c=document.querySelector(`.show_otp_popup_button[data-otp-channel-type="${o}"]`),l=document.querySelector("#close_otp_popup_button"),s=function(){i.forEach(n=>n.classList.remove("focused"))},h=function(n){s();n<i.length&&i[n].classList.add("focused")};u.addEventListener("input",n=>{const t=n.target.value;for(let n=0;n<i.length;n++)t[n]?(i[n].textContent=t[n],i[n].classList.add("filled")):(i[n].textContent="",i[n].classList.remove("filled"));h(t.length);f.value=t;e.disabled=f.value.length<6?!0:!1});u.addEventListener("focus",()=>{h(u.value.length)});u.addEventListener("blur",()=>{s()});e.onclick=()=>{const t=document.querySelector("#withdrawal_form");f.value.length==6&&(t?r({onSuccess:()=>{const u=Object.fromEntries(new FormData(t).entries()),i=document.querySelector("input[name=__RequestVerificationToken]"),f=document.querySelector("input[type=radio][name=PaymentType]:checked").value,r=document.querySelector(".otp-popup-content .field-validation-error");r&&r.remove();$.ajax({type:"POST",url:`/Wallet/${f}WithdrawalAsync`,headers:{__RequestVerificationToken:i.value},data:u,dataType:"json",success:n=>{if(n.errorCode===0)registerPopup({content:n.message}),window.location.replace("/home");else{const t=document.querySelector(".otp-popup-content"),r=document.querySelector(".otp-input-container");if(i.outerHTML=n.antiForgeryHtmlInput,t){const i=document.createElement("span");i.className="field-validation-error";i.innerText=n.message;t.insertBefore(i,r)}}},error:n})}}):c.closest("form").dispatchEvent(new Event("submit")))};l.onclick=()=>{t.classList.remove("open")}}}};window.initializeOtpPopup()});
$(()=>{window.initializeChangePassword=n=>{const t=document.querySelector("#cancel_reset_password"),u=document.querySelector("#reset_password_warning"),i=document.querySelector("#alert_success"),r=document.querySelector("#alert_danger"),f=document.querySelector("#request_verification_token");t&&(t.onclick=()=>{registerPopup({content:n.translations.CancelChangePasswordConfirmation,onConfirm:()=>{i.hidden=!0,r.hidden=!0,$.ajax({type:"POST",url:"/Profile/CancelResetPassword",contentType:"application/json; charset=utf-8",headers:{requestVerificationToken:f.value},dataType:"json",success:n=>{let t;n.status==!0?(t=i,u.hidden=!0):t=r;t&&(t.innerHTML=n.message,t.hidden=!1);$("#popup_modal").modal("hide")},error:()=>registerPopup({content:"Please try again in few minutes. Code:012CP"})})},cssClass:"cancel-reset-password-confirmation"})})}});