var TF_Phone_Control=function(){function t(t){this.elem=t=void 0===t?"":t,this.initialSelectHTML=this.elem.innerHTML,this.choices=null,this.countriesData=this.getJoomlaOption("tf_phonecontrol_data")||{},this.init(),this.initEvents()}var e=t.prototype;return e.init=function(){var s=this;this.choices=new Choices(this.elem,{allowHTML:!0,classNames:{containerOuter:"choices tf-phone-control--flag"},fuseOptions:{threshold:.3},shouldSort:!1,searchPlaceholderValue:"Search",itemSelectText:"",searchFields:["label","value"],callbackOnCreateTemplates:function(i){var a=this.config.itemSelectText,t=s.elem.closest(".tf-phone-control"),r=t.dataset.flagsBaseUrl,t=t.querySelector(".tf-phone-control--skeleton");return t&&t.remove(),{item:function(t,e){t.classNames&&(t=t.classNames);var o=e.value?s.countriesData[e.value].name:"",n=e.value?s.countriesData[e.value].calling_code:"";return i('\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t'+o+' +'+n+"\t\t\t\t\t\t\t\t\t\t\t\t\t\t")},choice:function(t,e){t.classNames&&(t=t.classNames);var o=e.value?s.countriesData[e.value].name:"",n=e.value?s.countriesData[e.value].calling_code:"";return i('\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t'+o+' '+o+'+'+n+"\t\t\t\t\t\t\t\t\t\t\t\t\t\t")}}}}),this.elem.phonecontrol=this},e.getJoomlaOption=function(t,e){if(!this.JoomlaOptions){var o=document.querySelector(".joomla-script-options");if(!o)return;this.JoomlaOptions=JSON.parse(o.text||o.textContent)}return void 0!==this.JoomlaOptions[t]?this.JoomlaOptions[t]:e},e.maybeRemoveRequiredValidator=function(t){var e,o,n;"false"!==t.dataset.required&&(e=t.querySelector(".tf-phone-control--validator"),o=t.querySelector(".tf-phone-control--flag--selector").value,n=t.querySelector(".tf-phone-control--number").value,e||""!==o&&""!==n||((e=document.createElement("input")).type="hidden",e.classList.add("tf-phone-control--validator"),e.id=t.dataset.id,t.insertBefore(e,t.firstChild)),e)&&(""===o||""===n?(e.classList.add("required"),e.setAttribute("required","required")):(e.classList.remove("required"),e.removeAttribute("required")))},e.initEvents=function(){var e,o=this,t=this.elem.closest(".tf-phone-control").querySelector(".tf-phone-control--number");t&&(e=t.closest(".tf-phone-control"),t.addEventListener("blur",function(t){o.maybeRemoveRequiredValidator(e)})),this.choices.passedElement.element.addEventListener("choice",function(e){setTimeout(function(){var t=e.target.closest(".tf-phone-control"),t=(o.maybeRemoveRequiredValidator(t),t.querySelector(".tf-phone-control--number"));t.focus(),t.dispatchEvent(new CustomEvent("change",{bubbles:!0}))},1)}.bind(this)),this.choices.passedElement.element.addEventListener("showDropdown",function(){var t=this.value,t=this.parentElement.parentElement.querySelector('.choices__list--dropdown [data-value="'+t+'"]');t&&(t.classList.add("tf-selectjs-selected-item"),t.parentElement.scrollTop=t.offsetTop-t.parentElement.offsetTop)})},e.reset=function(){this.choices.destroy(),this.elem.innerHTML=this.initialSelectHTML,new t(this.elem)},t}(),TF_Phone_Controls=function(){function t(){this.init()}var e=t.prototype;return e.init=function(){var t,e;window.IntersectionObserver&&0!==(t=document.querySelectorAll(".tf-phone-control--flag--selector:not(.done)")).length&&(this.prepareJ3(t),e=new IntersectionObserver(function(t,e){t.forEach(function(t){t.isIntersecting&&(t.target.classList.add("done"),new TF_Phone_Control(t.target),e.unobserve(t.target))})},{rootMargin:"0px 0px 0px 0px"}),t.forEach(function(t){e.observe(t)}))},e.prepareJ3=function(t){Joomla.Modal||t.forEach(function(t){window.jQuery&&jQuery(t).chosen&&jQuery(t).chosen("destroy")})},t}();"loading"!=document.readyState?new TF_Phone_Controls:document.addEventListener("DOMContentLoaded",function(){new TF_Phone_Controls});