document.addEventListener('DOMContentLoaded', function () {
    function initProgressBars() {
        const CVPBArea = document.querySelectorAll(".bwdcv-pb-area");		
        function setValueWithoutAnimation(counter, progressBar, value) {
            counter.textContent = value + "%";
        }		
        function CVProgressBar(progressWrapper) {
            const bwdProgressBox = progressWrapper.querySelectorAll(".bwdcv-pb-name");
            bwdProgressBox.forEach(pbBox => {
                const allPB = pbBox.querySelector(".bwdcv-per-val");
                const progressBar = pbBox.querySelector(".bwdcv-progress-bar");
                const counter = pbBox.querySelector(".bwdcv-percentage-counter");
                const allPBVal = parseInt(allPB.getAttribute("data-pb-val"));
                allPB.style.width = allPBVal + "%";
                setValueWithoutAnimation(counter, progressBar, allPBVal);
            });
        }
        CVPBArea.forEach(area => {
            CVProgressBar(area);
        });
    }
    initProgressBars();

    

    const container = document.querySelector('.bwdcvs-cv-builder-common').parentElement;
    if (container ) {
        container.style.display = 'flex';
        container.style.alignItems = 'center';
        container.style.flexDirection = 'column';
    }
    const adjustScale = () => {
        const viewportWidth = window.innerWidth;
        const minWidth = 320;
        const maxWidth = 1366;
        const minScale = 0.3;
        const refWidth1 = 992;
        const refScale1 = 0.468514;
        const refWidth2 = 1366;
        const refScale2 = 0.598237;
        const maxScale = 1;
        let scaleValue;
        if (viewportWidth <= refWidth1) {
            scaleValue =
                minScale +
                (refScale1 - minScale) * ((viewportWidth - minWidth) / (refWidth1 - minWidth));
        } else if (viewportWidth <= refWidth2) {
            scaleValue =
                refScale1 +
                (refScale2 - refScale1) * ((viewportWidth - refWidth1) / (refWidth2 - refWidth1));
        } else {
            scaleValue = Math.min(
                maxScale,
                refScale2 + (maxScale - refScale2) * ((viewportWidth - refWidth2) / (maxWidth - refWidth2))
            );
        }
        if (container) {
            const originalHeight = container.scrollHeight;
            const scaledHeight = originalHeight * scaleValue;
            container.style.transform = `scale(${scaleValue})`;
            container.style.transformOrigin = '50% 0px';
            container.style.transition = '0.5s ease-in-out';
            container.style.maxHeight = `${scaledHeight}px`;
        }
    };
    adjustScale();
    window.addEventListener('resize', adjustScale);

    
   
});