/* Minification failed. Returning unminified contents.
(1,20): run-time error CSS1031: Expected selector, found '='
(1,20): run-time error CSS1025: Expected comma or open brace, found '='
(5,2): run-time error CSS1019: Unexpected token, found ')'
(6,18): run-time error CSS1031: Expected selector, found '='
(6,18): run-time error CSS1025: Expected comma or open brace, found '='
(20,2): run-time error CSS1019: Unexpected token, found ')'
(22,10): run-time error CSS1030: Expected identifier, found 'addEventListener('
(22,10): run-time error CSS1031: Expected selector, found 'addEventListener('
(22,10): run-time error CSS1025: Expected comma or open brace, found 'addEventListener('
(40,2): run-time error CSS1019: Unexpected token, found ')'
(42,10): run-time error CSS1031: Expected selector, found 'addTextToItems('
(42,10): run-time error CSS1025: Expected comma or open brace, found 'addTextToItems('
(58,10): run-time error CSS1031: Expected selector, found 'checkScreenWidth('
(58,10): run-time error CSS1025: Expected comma or open brace, found 'checkScreenWidth('
(66,10): run-time error CSS1031: Expected selector, found 'removeTextFromItems('
(66,10): run-time error CSS1025: Expected comma or open brace, found 'removeTextFromItems('
(70,8): run-time error CSS1030: Expected identifier, found 'addEventListener('
(70,8): run-time error CSS1031: Expected selector, found 'addEventListener('
(70,8): run-time error CSS1025: Expected comma or open brace, found 'addEventListener('
(71,1): run-time error CSS1019: Unexpected token, found 'checkScreenWidth('
(71,18): run-time error CSS1019: Unexpected token, found ')'
(73,10): run-time error CSS1030: Expected identifier, found 'addEventListener('
(73,10): run-time error CSS1031: Expected selector, found 'addEventListener('
(73,10): run-time error CSS1025: Expected comma or open brace, found 'addEventListener('
(106,2): run-time error CSS1019: Unexpected token, found ')'
(108,15): run-time error CSS1031: Expected selector, found '='
(108,15): run-time error CSS1025: Expected comma or open brace, found '='
(109,9): run-time error CSS1030: Expected identifier, found 'forEach('
(109,9): run-time error CSS1031: Expected selector, found 'forEach('
(109,9): run-time error CSS1025: Expected comma or open brace, found 'forEach('
(137,2): run-time error CSS1019: Unexpected token, found ')'
(139,10): run-time error CSS1031: Expected selector, found 'moveProductBlocks('
(139,10): run-time error CSS1025: Expected comma or open brace, found 'moveProductBlocks('
(153,1): run-time error CSS1019: Unexpected token, found 'moveProductBlocks('
(153,19): run-time error CSS1019: Unexpected token, found ')'
(154,8): run-time error CSS1030: Expected identifier, found 'addEventListener('
(154,8): run-time error CSS1031: Expected selector, found 'addEventListener('
(154,8): run-time error CSS1025: Expected comma or open brace, found 'addEventListener('
(156,10): run-time error CSS1031: Expected selector, found 'addTextToAnalogsItems('
(156,10): run-time error CSS1025: Expected comma or open brace, found 'addTextToAnalogsItems('
(172,10): run-time error CSS1031: Expected selector, found 'removeTextFromAnalogsItems('
(172,10): run-time error CSS1025: Expected comma or open brace, found 'removeTextFromAnalogsItems('
(177,10): run-time error CSS1031: Expected selector, found 'checkAnalogsScreenWidth('
(177,10): run-time error CSS1025: Expected comma or open brace, found 'checkAnalogsScreenWidth('
(184,8): run-time error CSS1030: Expected identifier, found 'addEventListener('
(184,8): run-time error CSS1031: Expected selector, found 'addEventListener('
(184,8): run-time error CSS1025: Expected comma or open brace, found 'addEventListener('
(185,1): run-time error CSS1019: Unexpected token, found 'checkAnalogsScreenWidth('
(185,25): run-time error CSS1019: Unexpected token, found ')'
(187,10): run-time error CSS1031: Expected selector, found 'handleProductInfoClasses('
(187,10): run-time error CSS1025: Expected comma or open brace, found 'handleProductInfoClasses('
(217,1): run-time error CSS1019: Unexpected token, found 'handleProductInfoClasses('
(217,26): run-time error CSS1019: Unexpected token, found ')'
(218,8): run-time error CSS1030: Expected identifier, found 'addEventListener('
(218,8): run-time error CSS1031: Expected selector, found 'addEventListener('
(218,8): run-time error CSS1025: Expected comma or open brace, found 'addEventListener('
 */
const thumbsSwiper = new Swiper('.product__thumbs', {
    spaceBetween: 20,
    slidesPerView: 'auto',
    watchSlidesProgress: true,
});
const mainSwiper = new Swiper('.product__slider', {
    spaceBetween: 20,
    loop: true,
    navigation: {
        nextEl: '.product__slider-next',
        prevEl: '.product__slider-prev',
    },
    thumbs: {
        swiper: thumbsSwiper,
    },
    pagination: {
        el: '.product__pagination',
        clickable: true,
    },
});

document.addEventListener('DOMContentLoaded', function () {
    const tableBlocks = document.querySelectorAll('.product__table-block');
    const tableContent = document.querySelector('.product__table-content');
    const table = document.querySelector('.product__table');
    if (tableBlocks.length > 5) {
        const showMoreBtn = document.createElement('button');
        showMoreBtn.className = 'product__table-more';
        showMoreBtn.textContent = 'Показати більше';
        tableContent.appendChild(showMoreBtn);
        showMoreBtn.addEventListener('click', function () {
            table.classList.toggle('show-more');
            if (table.classList.contains('show-more')) {
                showMoreBtn.textContent = 'Згорнути';
            } else {
                showMoreBtn.textContent = 'Показати більше';
            }
        });
    }
});

function addTextToItems() {
    const blocks = document.querySelectorAll('.product__table-block');
    blocks.forEach(block => {
        const items = block.querySelectorAll('.product__table-item');
        const labels = ['СКЛАД:', 'КІЛЬКІСТЬ:', 'ЧАС ПОСТАВКИ:', 'ЦІНА:'];
        items.forEach((item, index) => {
            let label = document.createElement('p');
            label.classList.add('product__table-name');
            label.textContent = labels[index];
            if (!item.querySelector('.product__table-name')) {
                item.insertBefore(label, item.firstChild);
            }
        });
    });
}

function checkScreenWidth() {
    if (window.innerWidth < 1000) {
        addTextToItems();
    } else {
        removeTextFromItems();
    }
}

function removeTextFromItems() {
    const labels = document.querySelectorAll('.product__table-name');
    labels.forEach(label => label.remove());
}
window.addEventListener('resize', checkScreenWidth);
checkScreenWidth()

document.addEventListener('DOMContentLoaded', () => {
    const productInfoButtons = document.querySelectorAll('.product__info-select--btn');
    const productInfoItems = document.querySelectorAll('.product__info-item');
    const productInfoTitles = document.querySelectorAll('.product__info-title');

    productInfoButtons.forEach(button => {
        button.addEventListener('click', () => {
            productInfoButtons.forEach(btn => btn.classList.remove('active'));
            button.classList.add('active');
            const selectValue = button.getAttribute('data-select');
            productInfoItems.forEach(item => {
                item.classList.remove('active');
                if (item.getAttribute('data-result') === selectValue) {
                    item.classList.add('active');
                }
            });
        });
    });

    productInfoTitles.forEach(title => {
        title.addEventListener('click', () => {
            const selectValue = title.getAttribute('data-select');
            const correspondingButton = document.querySelector(`.product__info-select--btn[data-select="${selectValue}"]`);
            const correspondingItem = document.querySelector(`.product__info-item[data-result="${selectValue}"]`);
            const isActive = correspondingItem.classList.contains('active');
            productInfoButtons.forEach(btn => btn.classList.remove('active'));
            productInfoItems.forEach(item => item.classList.remove('active'));
            if (!isActive) {
                correspondingButton.classList.add('active');
                correspondingItem.classList.add('active');
            }
        });
    });
});

const sliders = document.querySelectorAll('.popular__content');
sliders.forEach(content => {
    const swiperContainer = content.querySelector('.popular__slider');
    const prevButton = content.querySelector('.popular__slide-prev');
    const nextButton = content.querySelector('.popular__slide-next');
    new Swiper(swiperContainer, {
        loop: true,
        spaceBetween: 20,
        slidesPerView: 1,
        allowTouchMove: true,
        navigation: {
            nextEl: nextButton,
            prevEl: prevButton,
        },
        autoplay: {
            delay: 3000,
        },
        breakpoints: {
            480: {
                slidesPerView: 1,
            },
            768: {
                slidesPerView: 3,
            },
            1000: {
                slidesPerView: 4,
            },
        },
    });
});

function moveProductBlocks() {
    const title = document.querySelector('.product__title');
    const about = document.querySelector('.product__about');
    const top = document.querySelector('.product__top');
    const content = document.querySelector('.product__content');

    if (window.innerWidth < 768) {
        top.insertBefore(title, top.firstChild);
        top.insertBefore(about, top.firstChild);
    } else {
        content.appendChild(title);
        content.appendChild(about);
    }
}
moveProductBlocks();
window.addEventListener('resize', moveProductBlocks);

function addTextToAnalogsItems() {
    const blocks = document.querySelectorAll('.analogs__table-block');
    blocks.forEach(block => {
        const items = block.querySelectorAll('.analogs__table-item:not(.analogs__table-start)');
        const labels = ['КІЛЬКІСТЬ:', 'ВІДПРАВКА:', 'ЦІНА:'];
        items.forEach((item, index) => {
            let label = document.createElement('p');
            label.classList.add('analogs__table-title');
            label.textContent = labels[index];
            if (!item.querySelector('.analogs__table-title')) {
                item.insertBefore(label, item.firstChild);
            }
        });
    });
}

function removeTextFromAnalogsItems() {
    const labels = document.querySelectorAll('.analogs__table-title');
    labels.forEach(label => label.remove());
}

function checkAnalogsScreenWidth() {
    if (window.innerWidth < 768) {
        addTextToAnalogsItems();
    } else {
        removeTextFromAnalogsItems();
    }
}
window.addEventListener('resize', checkAnalogsScreenWidth);
checkAnalogsScreenWidth();

function handleProductInfoClasses() {
    const productInfoItems = document.querySelectorAll('.product__info-item');
    const productSelectBtns = document.querySelectorAll('.product__info-select--btn');

    if (window.innerWidth < 768) {
        const hasActiveItem = Array.from(productInfoItems).some(item =>
            item.classList.contains('active')
        );
        if (!hasActiveItem) {
            productInfoItems.forEach(item => {
                item.classList.remove('active');
            });
        }
    } else {
        const hasActiveItem = Array.from(productInfoItems).some(item =>
            item.classList.contains('active')
        );
        if (!hasActiveItem) {
            productSelectBtns.forEach(btn => {
                btn.classList.remove('active');
            });
            if (productInfoItems.length > 0) {
                productInfoItems[0].classList.add('active');
            }
            if (productSelectBtns.length > 0) {
                productSelectBtns[0].classList.add('active');
            }
        }
    }
}
handleProductInfoClasses();
window.addEventListener('resize', handleProductInfoClasses);
