document.addEventListener("DOMContentLoaded",async()=>{let r=e=>"string"==typeof e&&/^[a-zA-Z0-9_-]+$/.test(e)?e:"",i=(e,t=[])=>{if(!e||"string"!=typeof e)return t;try{var n=JSON.parse(e);return Array.isArray(n)?n:t}catch(e){return t}},d=async()=>{try{var e=window.vkBlocksTocApi?.apiUrl||"/wp-json/vk-blocks/v1/toc_settings",t=await(await fetch(e,{credentials:"include"})).json();return t.success?t.data:null}catch(e){return null}},c=async()=>{let c=await d();c&&document.querySelectorAll(".wp-block-vk-blocks-table-of-contents-new").forEach(e=>{var t=e.querySelector(".vk_tableOfContents_list");if(t){let s;s="true"===e.dataset.useCustomLevels?i(e.dataset.customLevels||"[]",[]).map(e=>parseInt(e.replace("h","")))||[2,3,4,5,6]:c.allowedHeadingLevels||[2,3,4,5,6];let a=i(e.dataset.excludedHeadings||"[]",[]),o=!1!==c.includeBorderBox,n=e.dataset.numberingStyle||"";n=n||c.numberingStyle||"auto";t.querySelectorAll(".vk_tableOfContents_list_item").forEach(e=>{var t,n,l=e.className?e.className.match(/vk_tableOfContents_list_item-h-(\d+)/):null;l&&(l=parseInt(l[1]),n=e.querySelector("a"))&&(n=(n=n.getAttribute("href"))?n.replace("#",""):"",n=r(n),l=s.includes(l),t=a.includes(n),n=n.startsWith("vk-border-box-"),n=!o&&n,l&&!t&&!n||e.remove())});e=t.querySelectorAll(".vk_tableOfContents_list_item");let l=0;e.forEach(e=>{var t=e.className?e.className.match(/vk_tableOfContents_list_item-h-(\d+)/):null;t&&(t=parseInt(t[1]),e=e.querySelector(".vk_tableOfContents_list_item_link_preNumber"),"none"===n?e&&(e.style.display="none"):"h2-only"===n?2===t?(l++,e&&(e.style.display="",e.textContent=l+". ")):e&&(e.style.display="none"):e&&(e.style.display=""))})}})},u=(document.querySelectorAll(".wp-block-vk-blocks-table-of-contents-new").forEach(e=>{let l=e.querySelector(".vk_tableOfContents_openCloseBtn");if(l){let t=l.previousElementSibling,n=l.closest(".tab").querySelector(".tab_content-open, .tab_content-close");n&&n.classList.contains("tab_content-open")?(l.textContent="CLOSE",t&&(n&&(n.style.transition="none"),l.style.transition="none",t.checked=!0,n&&(n.getBoundingClientRect(),n.style.transition=""),l.getBoundingClientRect(),l.style.transition="")):(l.textContent="OPEN",t&&(t.checked=!1)),l.addEventListener("click",function(e){t&&"checkbox"===t.type&&(e.preventDefault(),e=!t.checked,t.checked=e,l.textContent=e?"CLOSE":"OPEN",l.classList.toggle("button_status-open",e),l.classList.toggle("button_status-close",!e),n)&&(n.classList.toggle("tab_content-open",e),n.classList.toggle("tab_content-close",!e))})}}),document.querySelectorAll(".vk_tableOfContents_list li").forEach(e=>{e.innerHTML=e.innerHTML.replace(/\uFFFC/g,"")}),await c(),null),t=0,e=()=>{var e=Date.now();5e3<e-t&&(t=e,(async()=>{var e,t,n,l,s,a,o=await d();o&&u&&(e=JSON.stringify(o.allowedHeadingLevels),t=JSON.stringify(u.allowedHeadingLevels),n=o.includeBorderBox,l=u.includeBorderBox,s=o.numberingStyle,a=u.numberingStyle,e===t&&n===l&&s===a||c()),u=o})())};document.addEventListener("visibilitychange",()=>{document.hidden||e()}),window.addEventListener("focus",e)});