(function(){"use strict";(()=>{const e=async()=>{const c="formychat_ip_data",r=a=>{delete a.success,window.formychat_ip=a,window.dispatchEvent(new CustomEvent("formychat_ip_loaded",{detail:a}))};try{const a=localStorage.getItem(c);if(a){const{timestamp:l,data:d}=JSON.parse(a);if(Date.now()-l<864e5)return r(d),d}const u=await fetch("https://ipwhois.app/json/");if(!u.ok)throw new Error("Failed to fetch IP data");const s=await u.json();if(!s||typeof s!="object")throw new Error("Invalid IP data");return localStorage.setItem(c,JSON.stringify({timestamp:Date.now(),data:s})),r(s),s}catch{return window.formychat_ip=null,null}};document.addEventListener("DOMContentLoaded",e),window.addEventListener("formychat_ip_loaded",c=>{var n,r;window.formychat_country_code=((r=(n=c.detail)==null?void 0:n.country_phone)==null?void 0:r.replace("+",""))||"44"})})(),window.initFormyChatDropDown=()=>{const e=document.querySelector(".formychat-dropdown");if(!e)return;const c=e.querySelector(".formychat-dropdown-placeholder"),n=e.querySelector(".formychat-dropdown-content-search"),r=e.querySelector(".formychat-dropdown-input"),a=()=>{document.addEventListener("click",o=>{if(o.target.closest(".formychat-dropdown-placeholder"))return u(o);if(!o.target.closest(".formychat-dropdown")&&!o.target.closest(".formychat-dropdown-placeholder"))return l();if(o.target.closest(".formychat-dropdown-content-item")||o.target.classList.contains("formychat-dropdown-content-item"))return d(o)}),document.addEventListener("keyup",o=>{if(o.target.closest(".formychat-dropdown")){if(o.target.closest(".formychat-dropdown-content-search")){f(o.target.value.toLowerCase().trim());return}if(o.key==="Escape"){l();return}}});const t=e.querySelector(".formychat-dropdown-content-item.selected");t&&d({target:t})};window.addEventListener("DOMContentLoaded",a);const u=t=>{if(t.preventDefault(),t.stopPropagation(),e.classList.contains("open")){l();return}s()},s=()=>{e.classList.add("active"),n.focus();const t=e.querySelector(".formychat-dropdown-content-item.selected");t&&t.scrollIntoView({behavior:"smooth",block:"center"})},l=()=>{e.classList.remove("active")},d=t=>{e.querySelectorAll(".formychat-dropdown-content-item").forEach(i=>{i.classList.remove("selected")}),t.target.classList.add("selected"),c&&(c.querySelector("span").textContent=t.target.dataset.placeholder),r.value=t.target.dataset.value,n.value="",f(),l()},f=(t="")=>{e.querySelectorAll(".formychat-dropdown-content-item").forEach(i=>{let m=!t||t.length===0;t&&t.length&&(m=t.length===0||i.dataset.tags.toLowerCase().includes(t)),i.style.display=m?"block":"none"})};if(!r.value||r.value.length===0)if(window.formychat_country_code){const t=e.querySelectorAll(".formychat-dropdown-content-item"),o=Array.from(t).find(i=>i.dataset.value===window.formychat_country_code);o&&d({target:o})}else window.addEventListener("formychat_ip_loaded",t=>{var h,y;const o=((y=(h=t.detail)==null?void 0:h.country_phone)==null?void 0:y.replace("+",""))||"44",i=e.querySelectorAll(".formychat-dropdown-content-item"),m=Array.from(i).find(v=>v.dataset.value===o);m&&d({target:m})});else{let t=e.querySelector('.formychat-dropdown-content-item[data-value="'+r.value+'"]');t&&d({target:t})}window.dispatchEvent(new Event("formychat_dropdown_initialized"))},document.addEventListener("DOMContentLoaded",initFormyChatDropDown);const w=()=>{if(window.location.href.includes("page=wpcf7")&&window.location.hash==="#formychat"){const e=document.querySelector("#formychat-tab");e&&e.click()}};document.addEventListener("DOMContentLoaded",w);const p=()=>{if(!window.location.href.includes("page=ninja-forms"))return;const e=new MutationObserver(c=>{c.forEach(()=>{const n=document.querySelector('input[type="text"]#formychat_number');n&&(n.value===""&&(n.value=window.formychat_country_code),n.value,n.placeholder=window.formychat_country_code,n.value=n.value.replace("+",""))})});e.observe(document.body,{childList:!0,subtree:!0}),setInterval(()=>{e.takeRecords()},1e3)};document.addEventListener("DOMContentLoaded",p)})();
//# sourceMappingURL=admin.common.js.map
