document.addEventListener('DOMContentLoaded', function(){
const modal=document.getElementById('phone-modal');
const modalContent=modal ? modal.querySelector('.modal-content'):null;
const overlay=modal ? modal.querySelector('.modal-overlay'):null;
const closeBtn=document.getElementById('close-modal');
const msgWrapper=document.querySelector('.floating-contact-wrap');
const msgBtn=msgWrapper ? msgWrapper.querySelector('.main-msg-btn'):null;
const msgDropdown=msgWrapper ? msgWrapper.querySelector('.contact-dropdown'):null;
const openPhoneModal=(e)=> {
if(e) e.preventDefault();
if(!modal||!modalContent) return;
modal.classList.remove('opacity-0', 'pointer-events-none');
modalContent.classList.replace('scale-95', 'scale-100');
document.body.style.overflow='hidden';
};
const closePhoneModal=()=> {
if(!modal||!modalContent) return;
modal.classList.add('opacity-0', 'pointer-events-none');
modalContent.classList.replace('scale-100', 'scale-95');
document.body.style.overflow='';
};
const initCallButtons=()=> {
const buttons=document.querySelectorAll('button, a.bg-green-700, a.bg-green-600');
buttons.forEach(btn=> {
const text=btn.innerText.toLowerCase();
const hasPhoneIcon=btn.querySelector('.lucide-phone');
if(text.includes('зателефонувати')||text.includes('викликати')||text.includes('позвони')||text.includes('записатись')||text.includes('связаться с нами')||text.includes('записаться')||text.includes('вызвать')||text.includes('затися з нами')||hasPhoneIcon){
btn.addEventListener('click', openPhoneModal);
}});
};
const toggleMessengers=(e)=> {
if(e){
e.preventDefault();
e.stopPropagation();
}
if(!msgDropdown||!msgBtn) return;
const isHidden=msgDropdown.classList.contains('opacity-0');
if(isHidden){
msgDropdown.classList.remove('opacity-0', 'translate-y-4', 'pointer-events-none');
msgDropdown.classList.add('opacity-100', 'translate-y-0');
msgBtn.style.transform='rotate(90deg)';
}else{
closeMessengers();
}};
const closeMessengers=()=> {
if(!msgDropdown||!msgBtn) return;
msgDropdown.classList.add('opacity-0', 'translate-y-4', 'pointer-events-none');
msgDropdown.classList.remove('opacity-100', 'translate-y-0');
msgBtn.style.transform='rotate(0deg)';
};
if(msgBtn){
msgBtn.addEventListener('click', toggleMessengers);
}
if(overlay) overlay.addEventListener('click', closePhoneModal);
if(closeBtn) closeBtn.addEventListener('click', closePhoneModal);
document.addEventListener('click', function(e){
if(msgWrapper&&!msgWrapper.contains(e.target)){
closeMessengers();
}});
document.addEventListener('keydown', (e)=> {
if(e.key==='Escape'){
closePhoneModal();
closeMessengers();
}});
initCallButtons();
});
jQuery(document).ready(function(t){if(t(".wp-block-wpm-language-switcher").length>0&&t(".wp-block-wpm-language-switcher .wpm-language-switcher").length>0){let e=t(".wp-block-wpm-language-switcher"),a=t(e).find("ul"),c=e.find(".wpm-switcher-select");(a.length>0||c.length>0)&&(wpm_localize_data.wpm_block_switch_nonce,t.ajax({type:"POST",url:wpm_localize_data.ajax_url,dataType:"json",data:{action:"wpm_block_lang_switcher",current_url:wpm_localize_data.current_url,security:wpm_localize_data.wpm_block_switch_nonce},success:function(e){a.length>0&&t(".wp-block-wpm-language-switcher .wpm-language-switcher a").each(function(a,c){var n=t(this).data("lang");let l="";t.each(e,function(t,e){n==t&&(l=e)}),t(this).attr("href",l)}),c.length>0&&t(".wp-block-wpm-language-switcher .wpm-language-switcher option").each(function(a,c){var n=t(this).data("lang");let l="";t.each(e,function(t,e){n==t&&(l=e)}),t(this).attr("value",l)})}}))}t(document).on("change",".wp-block-wpm-language-switcher .wpm-switcher-select",function(e){let a=t(this).val();window.location.href=a})});
(function(){
const siteNavigation=document.getElementById('site-navigation');
if(! siteNavigation){
return;
}
const button=siteNavigation.getElementsByTagName('button')[ 0 ];
if('undefined'===typeof button){
return;
}
const menu=siteNavigation.getElementsByTagName('ul')[ 0 ];
if('undefined'===typeof menu){
button.style.display='none';
return;
}
if(! menu.classList.contains('nav-menu') ){
menu.classList.add('nav-menu');
}
button.addEventListener('click', function(){
siteNavigation.classList.toggle('toggled');
if(button.getAttribute('aria-expanded')==='true'){
button.setAttribute('aria-expanded', 'false');
}else{
button.setAttribute('aria-expanded', 'true');
}});
document.addEventListener('click', function(event){
const isClickInside=siteNavigation.contains(event.target);
if(! isClickInside){
siteNavigation.classList.remove('toggled');
button.setAttribute('aria-expanded', 'false');
}});
const links=menu.getElementsByTagName('a');
const linksWithChildren=menu.querySelectorAll('.menu-item-has-children > a, .page_item_has_children > a');
for(const link of links){
link.addEventListener('focus', toggleFocus, true);
link.addEventListener('blur', toggleFocus, true);
}
for(const link of linksWithChildren){
link.addEventListener('touchstart', toggleFocus, false);
}
function toggleFocus(){
if(event.type==='focus'||event.type==='blur'){
let self=this;
while(! self.classList.contains('nav-menu') ){
if('li'===self.tagName.toLowerCase()){
self.classList.toggle('focus');
}
self=self.parentNode;
}}
if(event.type==='touchstart'){
const menuItem=this.parentNode;
event.preventDefault();
for(const link of menuItem.parentNode.children){
if(menuItem!==link){
link.classList.remove('focus');
}}
menuItem.classList.toggle('focus');
}}
}());