document.addEventListener('DOMContentLoaded', function () {
    const menuButton = document.getElementById('menuButton');
    const menu = document.getElementById('menu');

    menuButton.addEventListener('click', function () {
        if (menu.classList.contains('show')) {
            menu.classList.remove('show');
        } else {
            menu.classList.add('show');
        }
    });
});
document.addEventListener('DOMContentLoaded', function () {
    // Фиксация навигационной панели при прокрутке
    window.addEventListener('scroll', function () {
        const navbar = document.querySelector('.navbar');
        if (window.scrollY > 60) {
            navbar.classList.add('navbar-fixed');
        } else {
            navbar.classList.remove('navbar-fixed');
        }
    });

    // Функция транслитерации
    function translit(word) {
        let answer = '';
        const converter = {
            'а': 'a', 'б': 'b', 'в': 'v', 'г': 'g', 'д': 'd',
            'е': 'e', 'ё': 'e', 'ж': 'zh', 'з': 'z', 'и': 'i',
            'й': 'y', 'к': 'k', 'л': 'l', 'м': 'm', 'н': 'n',
            'о': 'o', 'п': 'p', 'р': 'r', 'с': 's', 'т': 't',
            'у': 'u', 'ф': 'f', 'х': 'h', 'ц': 'c', 'ч': 'ch',
            'ш': 'sh', 'щ': 'sch', 'ь': '', 'ы': 'y', 'ъ': '',
            'э': 'e', 'ю': 'yu', 'я': 'ya',

            // Заглавные буквы
            'А': 'A', 'Б': 'B', 'В': 'V', 'Г': 'G', 'Д': 'D',
            'Е': 'E', 'Ё': 'E', 'Ж': 'Zh', 'З': 'Z', 'И': 'I',
            'Й': 'Y', 'К': 'K', 'Л': 'L', 'М': 'M', 'Н': 'N',
            'О': 'O', 'П': 'P', 'Р': 'R', 'С': 'S', 'Т': 'T',
            'У': 'U', 'Ф': 'F', 'Х': 'H', 'Ц': 'C', 'Ч': 'Ch',
            'Ш': 'Sh', 'Щ': 'Sch', 'Ь': '', 'Ы': 'Y', 
            'Ъ': '',  // Убираем
            'Э': 'E',  // Убираем
            'Ю': 'Yu',
            'Я': 'Ya'
        };

        for (let i = 0; i < word.length; ++i) {
            answer += converter[word[i]] !== undefined ? converter[word[i]] : word[i];
        }

        return answer;
    }

    // Генерация id для заголовков и добавление в TOC
    const headings = document.querySelectorAll('.content h2, .content h3');
    headings.forEach(function (heading) {
        const title = translit(heading.textContent);
        const sanitizedTitle = title.replace(/[\W_]/g, "-");
        heading.id = sanitizedTitle;
    });

    // Функция для создания оглавления
    // function tableOfContents(tocList) {
    //     const tocElement = document.querySelector(tocList);
    //     tocElement.innerHTML = ''; // Очищаем список
    //     let prevH2List = null;

    //     document.querySelectorAll('.content h2').forEach(function (h2) {
    //         const title = h2.id;
    //         const li = document.createElement('li');
    //         li.innerHTML = `<a href="#${title}">${h2.textContent}</a>`;
            
    //         if (prevH2List === null) {
    //             prevH2List = document.createElement('ul');
    //             tocElement.appendChild(prevH2List);
    //         }
            
    //         prevH2List.appendChild(li);
    //     });
    // }

    // // Создание оглавления
    // tableOfContents('.toc-list ol');

    // Плавная прокрутка к якорям
    document.body.addEventListener('click', function (e) {
        if (e.target.matches('[href*="#"]')) {
            e.preventDefault();
            const targetId = e.target.getAttribute('href').substring(1);
            const targetElement = document.getElementById(targetId);
            if (targetElement) {
                const fixedOffset = 70;
                const targetPosition = targetElement.getBoundingClientRect().top + window.scrollY - fixedOffset;
                window.scrollTo({
                    top: targetPosition,
                    behavior: "smooth"
                });
            }
        }
    });
});


document.addEventListener("DOMContentLoaded", function() {
    var cookieInfoElements = document.querySelectorAll(".cookieinfo");
    
    cookieInfoElements.forEach(function(element) {
      var wrapper = document.createElement("div");
      while (element.firstChild) {
        wrapper.appendChild(element.firstChild);
      }
      element.appendChild(wrapper);
    });
  });