{"version":3,"sources":["webpack:///./assets/javascripts/modules/components/MyAccountLayerComponent.js"],"names":["MyAccountLayerComponent","Component","emailInput","this","$component","querySelector","SELECTORS","pwdRecoveryBtn","loginBtn","recoveryForm","recoverySubmitBtn","formEmailInput","formPswInput","myAccountLayerWrapper","document","self","url","dom","getAttribute","params","URLSearchParams","FormData","toString","fetch","method","body","headers","Content-Type","then","res","text","rbody","recovery","DOMParser","parseFromString","error","parentElement","innerText","trim","Error","value","addEventListener","classList","add","CSS","remove","success","evt","preventDefault","disabled","sendRecovery","email","setTimeout","visible","catch","err","component","setError","message","e","activeElement","contains","readDOM","bindEvents"],"mappings":"wWAEqBA,grBAAgCC,6CAuBjD,OACEC,WAAYC,KAAKC,WAAWC,cAAcF,KAAKG,UAAUJ,YACzDK,eAAgBJ,KAAKC,WAAWC,cAAcF,KAAKG,UAAUC,gBAC7DC,SAAUL,KAAKC,WAAWC,cAAcF,KAAKG,UAAUE,UACvDC,aAAcN,KAAKC,WAAWC,cAAcF,KAAKG,UAAUG,cAC3DC,kBAAmBP,KAAKC,WAAWC,cAAcF,KAAKG,UAAUI,mBAChEC,eAAgBR,KAAKC,WAAWC,cAAcF,KAAKG,UAAUK,gBAC7DC,aAAcT,KAAKC,WAAWC,cAAcF,KAAKG,UAAUM,cAC3DC,sBAAuBC,SAAST,cAAcF,KAAKG,UAAUO,+DAK/D,IAAME,EAAOZ,KACPa,EAAMb,KAAKc,IAAIR,aAAaS,aAAa,UACzCC,EAAU,IAAIC,gBAAgB,IAAIC,SAASlB,KAAKc,IAAIR,eAAgBa,WAE1E,OAAOC,MAAMP,GACXQ,OAAQ,OACRC,KAAMN,EACNO,SACEC,eAAgB,uCAGjBC,KAAK,SAAAC,GAAA,OAAOA,EAAIC,SAChBF,KAAK,SAAAG,GACJ,IACMC,GADQ,IAAIC,WAAaC,gBAAgBH,EAAO,aAChC1B,cAAc,yBACpC,GAAG2B,EAAU,CACX,IAAMG,EAAQH,EAASI,cAAcA,cAAc/B,cAA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S8C,eAAiB9C,SAAST,cAAcU,EAAKT,UAAUJ,cAAgBY,SAAS8C,cAAe,OAAO,EAE/L7C,EAAKE,IAAIJ,sBAAsB6B,UAAUmB,SAAS9C,EAAK6B,IAAIS,UAAUtC,EAAKE,IAAIJ,sBAAsB6B,UAAUG,OAAO9B,EAAK6B,IAAIS,4CAKnIlD,KAAKc,IAAMd,KAAK2D,UAChB3D,KAAK4D,+CA1GL,OACExD,eAAgB,0BAChBC,SAAU,mBACVN,WAAY,8BACZO,aAAc,4BACdC,kBAAmB,oBACnBC,eAAgB,+BAChBC,aAAc,kCACdC,sBAAuB,8DAKzB,OACEmB,SAAU,aACVc,QAAS,YACTO,QAAS,iBAlBMrD","file":"component-MyAccountLayerComponent.chunks.js","sourcesContent":["import Component from '../abstracts/Component';\n\nexport default class MyAccountLayerComponent extends Component {\n  get SELECTORS() {\n    return {\n      pwdRecoveryBtn: '[data-pwd-recovery-btn]',\n      loginBtn: '[data-login-btn]',\n      emailInput: '[data-modal-recovery-email]',\n      recoveryForm: '[data-recovery-form] form',\n      recoverySubmitBtn: '[data-submit-btn]',\n      formEmailInput: 'fieldset input[type=\"email\"]',\n      formPswInput: 'fieldset input[type=\"password\"]',\n      myAccountLayerWrapper: '[data-myaccount-layer-wrapper]',\n    };\n  }\n\n  get CSS() {\n    return {\n      recovery: '--recovery',\n      success: '--success',\n      visible: 'show',\n    };\n  }\n\n  readDOM() {\n    return {\n      emailInput: this.$component.querySelector(this.SELECTORS.emailInput),\n      pwdRecoveryBtn: this.$component.querySelector(this.SELECTORS.pwdRecoveryBtn),\n      loginBtn: this.$component.querySelector(this.SELECTORS.loginBtn),\n      recoveryForm: this.$component.querySelector(this.SELECTORS.recoveryForm),\n      recoverySubmitBtn: this.$component.querySelector(this.SELECTORS.recoverySubmitBtn),\n      formEmailInput: this.$component.querySelector(this.SELECTORS.formEmailInput),\n      formPswInput: this.$component.querySelector(this.SELECTORS.formPswInput),\n      myAccountLayerWrapper: document.querySelector(this.SELECTORS.myAccountLayerWrapper),\n    }\n  }\n\n  sendRecovery() {\n    const self = this;\n    const url = this.dom.recoveryForm.getAttribute('action');\n    const params = (new URLSearchParams(new FormData(this.dom.recoveryForm))).toString();\n\n    return fetch(url, {\n      method: 'POST',\n      body: params,\n      headers: {\n        'Content-Type': 'application/x-www-form-urlencoded',\n      },\n    })\n      .then(res => res.text())\n      .then(rbody => {\n        const rdoc = (new DOMParser()).parseFromString(rbody, 'text/html');\n        const recovery = rdoc.querySelector('[data-recovery-email]');\n        if(recovery) {\n          const error = recovery.parentElement.parentElement.querySelector('[data-error]');\n          if(error.innerText.trim()) throw new Error(error.innerText.trim());\n        }\n\n        return self.$component.querySelector('input[name=email]').value;\n      });\n  }\n\n  bindEvents() {\n    let self = this;\n    // GO TO RECOVERY\n    this.dom.pwdRecoveryBtn.addEventListener('click', () => {\n      self.$component.classList.add(self.CSS.recovery);\n      self.$component.classList.remove(self.CSS.success);\n    });\n\n    // FROM RECOVERY GO TO LOGIN\n    this.dom.loginBtn.addEventListener('click', () => {\n      self.$component.classList.remove(self.CSS.recovery);\n      self.$component.classList.remove(self.CSS.success);\n    });\n\n    this.dom.recoveryForm.addEventListener('submit', evt => {\n      evt.preventDefault();\n      self.dom.recoverySubmitBtn.disabled = true;\n      self.sendRecovery()\n        .then((email) => {\n          self.$component.querySelector('[data-recovery-message]').innerText = email;\n          self.$component.classList.remove(self.CSS.recovery);\n          self.$component.classList.add(self.CSS.success);\n          setTimeout(function() {\n            self.dom.myAccountLayerWrapper.classList.remove(self.CSS.visible);\n          }, 3000);\n        })\n        .catch(err => {\n          self.dom.emailInput.parentElement.parentElement.component.setError(err.message);\n          self.dom.recoverySubmitBtn.disabled = false;\n        });\n    });\n\n    // click on layer adding open class\n    this.$component.addEventListener('click',(e) => {\n      // adding class\n      self.dom.myAccountLayerWrapper.classList.add(self.CSS.visible);\n    });\n    // mouseleave from div\n    this.dom.myAccountLayerWrapper.addEventListener('mouseleave', e => {\n      // for google autocompilation\n      if(self.dom.formEmailInput === document.activeElement || self.dom.formPswInput === document.activeElement || document.querySelector(self.SELECTORS.emailInput) === document.activeElement) return false;\n      // if is open and i click outside the div, close it\n      if(self.dom.myAccountLayerWrapper.classList.contains(self.CSS.visible)) self.dom.myAccountLayerWrapper.classList.remove(self.CSS.visible);\n    });\n  }\n\n  render() {\n    this.dom = this.readDOM();\n    this.bindEvents();\n  }\n}"],"sourceRoot":""}