1var m=Object.defineProperty,u=Object.getOwnPropertySymbols,w=Object.prototype.hasOwnProperty,g=Object.prototype.propertyIsEnumerable,h=(a,t,e)=>t in a?m(a,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):a[t]=e,f=(a,t)=>{for(var e in t||(t={}))w.call(t,e)&&h(a,e,t[e]);if(u)for(var e of u(t))g.call(t,e)&&h(a,e,t[e]);return a},l=(a,t,e)=>new Promise((s,i)=>{var r=c=>{try{n(e.next(c))}catch(d){i(d)}},o=c=>{try{n(e.throw(c))}catch(d){i(d)}},n=c=>c.done?s(c.value):Promise.resolve(c.value).then(r,o);n((e=e.apply(a,t)).next())});import{c as p,a as v}from"./datalayer.45a66048.js";import"./debounce.04880337.js";import"./isSymbol.f1626f95.js";import"./_commonjsHelpers.a6551a8d.js";import"./toNumber.04785dd6.js";import"./utils.ba978b64.js";class E extends HTMLElement{constructor(){switch(super(),this.form=this.querySelector("form"),this.result=this.querySelector("[data-result]"),this.subtext=document.querySelector(".js-subtext"),this.form&&this.form.addEventListener("submit",this.onFormSubmit.bind(this)),this.getAttribute("action")){case"resetPassword":this.getAccessToken();break;case"confirmEmail":this.confirmEmail();break}}toggleSubmitting(t=!0){const e=this.querySelector('button[type="submit"]');t?e.setAttribute("disabled",!0):e.removeAttribute("disabled")}get values(){return Object.fromEntries(new FormData(this.form))}get authCode(){let e=new URLSearchParams(window.location.search).get("code");return e&&e.indexOf("__")>0&&(e=e.slice(0,e.indexOf("__"))),e}get verificationCode(){let e=new URLSearchParams(window.location.search).get("verification_code");return e&&e.indexOf("__")>0?e.substring(0,e.indexOf("__")):e}getAccessToken(){const t=this.authCode;if(!t)return this.showError(!0);let e;fetch(`${window.BARREL.sbdApiUrl}/aic/getAccessToken`,{method:"POST",headers:{"Content-Type":"application/json",token:window.BARREL.sbdApiAccessToken},body:JSON.stringify({code:t})}).then(s=>(e=s.status,s.json())).then(s=>{e===200?this._accessToken=s.access_token:this.showError(!0)})}confirmEmail(){fetch(`${window.BARREL.sbdApiUrl}/aic/confirmEmail`,{method:"POST",headers:{"Content-Type":"application/json",token:window.BARREL.sbdApiAccessToken},body:JSON.stringify({verificationCode:this.verificationCode})}).then(t=>{t.status===200?(p(),this.showSuccess(!0)):this.showError(!0)})}onFormSubmit(t){t.preventDefault();const e=this.getAttribute("action"),s=navigator.languages&&navigator.languages.length?navigator.languages[0]:navigator.language,i=f({locale:s},this.values);this._accessToken&&(i.accessToken=this._accessToken),(e==="login"||e==="register")&&(i.leadSource="website_registration"),e==="register"&&(i.details={address1:"",address2:"",city:"",province:"",country:"",zip:"",province_code:"",country_code:"",country_name:"",phone:"",birth_date:"",gender:"",accepts_marketing:!!i.acceptsMarketing,preferences:""},delete i.acceptsMarketing),this.toggleSubmitting(!0);try{return fetch(`${window.BARREL.sbdApiUrl}/aic/${e}`,{method:"POST",headers:{"Content-Type":"application/json",token:window.BARREL.sbdApiAccessToken},body:JSON.stringify(i)}).then(r=>{switch(e){case"register":return this.handleRegisterResponse(r);case"login":return this.handleLoginResponse(r);case"requestResetPassword":return this.handleRequestResetPasswordResponse(r);case"resetPassword":return this.handleResetPasswordResponse(r);case"sendVerificationEmail":return this.handleSendVerificationEmailResponse(r)}}).then(({success:r,error:o,invalidCredentials:n,invalidFields:c,emailVerified:d})=>{this.toggleSubmitting(!1),n?this.showInvalidCredentialsErrors():c?this.showInvalidFieldErrors(c):typeof r<"u"?this.showSuccess(r):typeof o<"u"&&this.showError(o),e==="login"&&(d!==void 0&&!d?(this.showError(""),this.showResendVerificationEmail(!0)):this.showResendVerificationEmail(!1)),e==="sendVerificationEmail"&&this.subtext.classList.add("hidden")})}catch{this.showError(!0)}}handleRegisterResponse(t){return l(this,null,function*(){var e;if(t.status===200)return v(),{success:!0};if(t.status===400){const s=yield t.json();if((e=s.data)!=null&&e.invalid_fields)return{invalidFields:s.data.invalid_fields};if(s.message)return{error:s.message}}return{error:!0}})}handleLoginResponse(t){return l(this,null,function*(){var e,s;if(t.status==200){const i=yield t.text();if(i){localStorage.setItem("isRedirect","true"),window.location.href=i;return}}else if(t.status==400){const i=yield t.json();let r,o,n;return((e=i.data)==null?void 0:e.error)==="invalid_credentials"?n=!0:(s=i.data)!=null&&s.invalid_fields&&(i.data.invalid_fields.signInForm&&(r=i.data.invalid_fields.signInForm[0],delete i.data.invalid_fields.signInForm),Object.keys(i.data.invalid_fields).length&&(o=i.data.invalid_fields)),r||(r=i.message),n?{invalidCredentials:n}:o?{invalidFields:o}:{error:r,emailVerified:i.emailVerified}}return{error:!0}})}handleRequestResetPasswordResponse(t){return l(this,null,function*(){if(t.status==200)return{success:!0};if(t.status==400){yield t.json();const e="If an account with that email is found, a reset password link
1will be emailed to you.";return{error:e!=null&&e.length?e:!0}}})}handleResetPasswordResponse(t){return l(this,null,function*(){var e,s;if(t.status==200)return{success:!0};if(t.status===400){const i=yield t.json();let r,o,n;return((e=i.data)==null?void 0:e.error)==="invalid_credentials"?n=!0:(s=i.data)!=null&&s.invalid_fields&&Object.keys(i.data.invalid_fields).length&&(o=i.data.invalid_fields),r||(r=i.message),n?{invalidCredentials:n}:o?{invalidFields:o}:{error:r,emailVerified:i.emailVerified}}return{error:!0}})}handleSendVerificationEmailResponse(t){return l(this,null,function*(){var e;if(t.status==200)return{success:!0};if(t.status===400){const s=yield t.json();return{error:s.message,code:(e=s.data)==null?void 0:e.code}}return{error:!0}})}showSuccess(t){var e,s;this.result.innerHTML=typeof t=="string"?t:this.dataset.successMessage,(e=this.subtext)==null||e.classList.add("hidden"),(s=this.form)==null||s.classList.add("hidden"),this.result.classList.remove("hidden")}showError(t){var s;this.result.innerHTML=typeof t=="string"?t:this.dataset.errorMessage,this.getAttribute("action")!="login"&&((s=this.form)==null||s.classList.add("hidden")),this.result.classList.remove("hidden"),this.querySelector("[invalid-credentials]").classList.add("hidden")}showInvalidCredentialsErrors(){const t=this.querySelector("[invalid-credentials]");this.result.classList.add("hidden"),t.classList.remove("hidden")}showInvalidFieldErrors(t){t.email=t.emailAddress,delete t.emailAddress,t.password=t.newPassword,delete t.newPassword,t.passwordConfirm=t.newPasswordConfirm,delete t.newPasswordConfirm,this.querySelectorAll("text-input").forEach(e=>{const s=e.querySelector("input");t[s.name]?e.showError(t[s.name][0]):e.classList.contains("has-error")&&(e.classList.remove("has-error"),e.querySelector("[data-error]").innerText="")})}showResendVerificationEmail(t){const e=this.querySelector("[resend-verification-email]");t?(this.result.classList.add("hidden"),e.classList.remove("hidden")):e.classList.add("hidden")}}customElements.define("account-form",E);class b extends HTMLElement{constructor(){super();const t=this.closest("[data-form-container]"),e=this.querySelector("a"),s=e.href.slice(e.href.indexOf("#"));e.addEventListener("click",i=>{i.preventDefault(),window.history.replaceState(null,null,`${window.location.pathname}${s}`),t.classList.add("hidden"),t.nextElementSibling.classList.remove("hidden")}),window.location.hash==s&&e.click()}}customElements.define("account-recover-link",b);class y extends HTMLElement{constructor(){super();const t=this.closest("[data-form-container]");this.querySelector("a").addEventListener("click",e=>{e.preventDefault(),window.history.replaceState(null,null,window.location.pathname),t.classList.add("hidden"),t.previousElementSibling.classList.remove("hidden")})}}customElements.define("account-recover-cancel-link",y); 2//# sourceMappingURL=/cdn/shop/t/182/assets/account-form.3307625d.js.map
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.