!function(){"use strict";const t=function(t){let i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;return i||(i=Math.random().toString(36).substr(2,5)),`${t}.${i}`},i=function(t){let i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return window.FormieTranslations&&(t=window.FormieTranslations[t]||t),t.replace(/{([a-zA-Z0-9]+)}/g,((t,e)=>i[e]?i[e]:t))};window.FormieTextLimit=class{constructor(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};this.$form=t.$form,this.form=this.$form.form,this.$field=t.$field,this.$text=this.$field.querySelector("[data-limit]"),this.$input=this.$field.querySelector("input, textarea"),this.initTextLimits()}initTextLimits(){this.minChars=this.$input.getAttribute("data-min-chars"),this.maxChars=this.$input.getAttribute("data-max-chars"),this.minWords=this.$input.getAttribute("data-min-words"),this.maxWords=this.$input.getAttribute("data-max-words"),this.maxChars&&(this.form.addEventListener(this.$input,t("paste"),this.characterCheck.bind(this),!1),this.form.addEventListener(this.$input,t("keydown"),this.characterCheck.bind(this),!1),this.form.addEventListener(this.$input,t("populate"),this.characterCheck.bind(this),!1),this.$input.dispatchEvent(new Event("keydown",{bubbles:!0}))),this.maxWords&&(this.form.addEventListener(this.$input,t("paste"),this.wordCheck.bind(this),!1),this.form.addEventListener(this.$input,t("keydown"),this.wordCheck.bind(this),!1),this.form.addEventListener(this.$input,t("populate"),this.wordCheck.bind(this),!1),this.$input.dispatchEvent(new Event("keydown",{bubbles:!0}))),this.form.registerEvent("registerFormieValidation",this.registerValidation.bind(this))}registerValidation(t){t.validator.addValidator("textMinCharacterLimit",(t=>{let{input:i}=t;const e=i.getAttribute("data-min-chars");if(!e)return!0;const r=this.stripTags(i.value);return!(e-this.count(r)>0)}),(t=>{let{label:e,input:r}=t;return i("{attribute} must be no less than {min} characters.",{attribute:e,min:r.getAttribute("data-min-chars")})})),t.validator.addValidator("textMaxCharacterLimit",(t=>{let{input:i}=t;const e=i.getAttribute("data-max-chars");if(!e)return!0;const r=this.stripTags(i.value);return!(e-this.count(r)<0)}),(t=>{let{label:e,input:r}=t;return i("{attribute} must be no greater than {max} characters.",{attribute:e,max:r.getAttribute("data-max-chars")})})),t.validator.addValidator("textMinWordLimit",(t=>{let{input:i}=t;const e=i.getAttribute("data-min-words");if(!e)return!0;return!(e-(this.stripTags(i.value).split(/\S+/).length-1)>0)}),(t=>{let{label:e,input:r}=t;return i("{attribute} must be no less than {min} words.",{attribute:e,min:r.getAttribute("data-min-words")})})),t.validator.addValidator("textMaxWordLimit",(t=>{let{input:i}=t;const e=i.getAttribute("data-max-words");if(!e)return!0;return!(e-(this.stripTags(i.value).split(/\S+/).length-1)<0)}),(t=>{let{label:e,input:r}=t;return i("{attribute} must be no greater than {max} words.",{attribute:e,max:r.getAttribute("data-max-words")})}))}characterCheck(t){setTimeout((()=>{const e=this.stripTags(t.target.value),r=this.maxChars-this.count(e),a=["fui-limit-number"],s=1==r||-1==r?"character":"characters";r<0&&a.push("fui-limit-number-error"),this.$text&&(this.$text.innerHTML=i(`{startTag}{num}{endTag} ${s} left`,{num:String(r),startTag:`<span class="${a.join(" ")}">`,endTag:"</span>"}))}),1)}wordCheck(t){setTimeout((()=>{const e=this.stripTags(t.target.value).split(/\S+/).length-1,r=this.maxWords-e,a=["fui-limit-number"],s=1==r||-1==r?"word":"words";r<0&&a.push("fui-limit-number-error"),this.$text&&(this.$text.innerHTML=i(`{startTag}{num}{endTag} ${s} left`,{num:String(r),startTag:`<span class="${a.join(" ")}">`,endTag:"</span>"}))}),1)}count(t){return(t.match(/(?:\p{Extended_Pictographic}[\p{Emoji_Modifier}\p{M}]*(?:\p{Join_Control}\p{Extended_Pictographic}[\p{Emoji_Modifier}\p{M}]*)*|\s|.)\p{M}*/guy)||[]).length}stripTags(t){return(new DOMParser).parseFromString(t,"text/html").body.textContent||""}}}();