/*! For license information please see ae1a59.js.LICENSE.txt */
(window.webpackJsonp=window.webpackJsonp||[]).push([[3],{226:function(e,s,t){"use strict";t(494)},494:function(e,s,t){"use strict";var i=t(0),a=t(6),r=t(4);class n{constructor(e){this._element=e,this._container=e.parentNode,this._element.addEventListener("input",this.clearMessage.bind(this))}createNotice(){this._notice||(this._notice=document.createElement("p"),this._notice.setAttribute("class","form__notice form__notice--red"),this._container.append(this._notice))}clearMessage(){this._notice&&(this._notice.innerHTML="",this._notice.classList.add("hidden")),this._element.classList.remove("field--red")}showError(e){this.createNotice(),this._notice.innerHTML=e,this._notice.classList.remove("hidden"),this._element.classList.add("field--red")}setValue(e){this._element.value=e}}class o{constructor(e){this._form=e,this.initialize()}initialize(){if(this._uri=this._form.getAttribute("action")||window.location,this._method="get"===this._form.dataset.ajax?"GET":"POST",this._wrapper=this._form.parentNode,this._fields={},(0,a.addEventListener)(this._form,"submit",this.onSubmit.bind(this)),this._message=document.createElement("p"),(0,r.addClass)(this._message,"alert"),(0,r.addClass)(this._message,"hidden"),(0,r.hasClass)(this._wrapper,"modal__wrapper")&&((0,r.addClass)(this._message,"alert--full-width"),this._form.dataset.hasOwnProperty("once")||(0,a.addEventListener)(this._wrapper,"closeModal",this.clearFormMessages.bind(this))),this._form.dataset.alert){this._form.dataset.alert.split(",").forEach((e=>{(0,r.addClass)(this._message,"alert--"+e)}))}this._wrapper.insertBefore(this._message,this._form)}clearFormMessages(){(0,r.removeClass)(this._form,"hidden"),(0,r.addClass)(this._message,"hidden");for(let e in this._fields)this._fields.hasOwnProperty(e)&&this._fields[e].clearMessage()}onSubmit(e){if(e.preventDefault(),this._sending)return;this._sending=!0;let s=(0,i.querySelector)(this._form,"[type=submit], button:not([type])");s&&(s.disabled=!0,h(s));const t=new FormData(this._form);fetch(this._uri,{method:this._method,body:t,headers:{"X-Requested-With":"XMLHttpRequest"},credentials:"include"}).then((e=>e.json())).then((e=>{this._sending=!1,this.onResponse(e)}))}onResponse(e){this._form.dispatchEvent(new Event("response"));let s=(0,i.querySelector)(this._form,"[type=submit], button:not([type])");if(s&&(s.disabled=!1,h(s)),this.showFormMessage(e.status,e.message||""),e.errors)for(let s in e.errors)e.errors.hasOwnProperty(s)&&this.showFieldError(s,e.errors[s]);if(e.values)for(let s in e.values)e.values.hasOwnProperty(s)&&this.setFieldValue(s,e.values[s])}showFieldError(e,s){if(!this._fields[e]){const s=(0,i.querySelector)(this._form,'[name="'.concat(e,'"]'));if(!s)return;this._fields[e]=new n(s)}this._fields[e].showError(s)}setFieldValue(e,s){if(!this._fields[e]){const s=(0,i.querySelector)(this._form,'[name="'.concat(e,'"]'));if(!s)return;this._fields[e]=new n(s)}this._fields[e].setValue(s)}showFormMessage(e,s){if(s){switch((0,r.removeClass)(this._message,"hidden"),e.toUpperCase()){case"SUCCESS":(0,r.removeClass)(this._message,"alert--red"),(0,r.addClass)(this._message,"alert--green"),(0,r.addClass)(this._form,"hidden");break;case"ERROR":(0,r.removeClass)(this._message,"alert--green"),(0,r.addClass)(this._message,"alert--red")}this._message.innerHTML=s}else(0,r.addClass)(this._message,"hidden")}}const h=function(e){e.dataset.submitText&&("INPUT"===e.tagName.toUpperCase()?d(e):l(e))},d=function(e){let s=e.value||"";e.value=e.dataset.submitText,e.dataset.submitText=s},l=function(e){let s=e.textContent||"";e.textContent=e.dataset.submitText,e.dataset.submitText=s};(0,i.querySelectorAll)(document,"form[data-ajax]").forEach((e=>new o(e)))}}]);