/home/bdqbpbxa/rc-subdomains/waykay-rc.goodface.com.ua/frontend/js/script.js
// Conveyor line functionality
const conveyor = $(".conveyor-belt__belt");

function conveyorReady(conveyor) {
  let thisConveyor = conveyor;
  const part = thisConveyor.find(".conveyor-belt__belt-part");
  if (part.length) {
    const partWidth = part.outerWidth();
    const windowWidth = window.screen.width;

    let partDublicateCount;
    let partHtml = part[0].outerHTML;
    let appendHtml = "";

    if (partWidth >= windowWidth) {
      partDublicateCount = 2;
    } else {
      partDublicateCount = Math.ceil(windowWidth / partWidth);
    }

    for (var i = 1; i < partDublicateCount; i++) {
      appendHtml += partHtml;
    }

    thisConveyor.append(appendHtml);

    lazyload(".conveyor-belt__belt");

    startConveyorAnimation(thisConveyor, partWidth);
  }
}

function startConveyorAnimation(conveyor, partWidth) {
  let index = 0.9;
  if (!isPc) {
    index = 1.3;
  }
  const speed = index * (partWidth / 100);

  const animationVal = `conveyor-part ${speed}s linear infinite`;

  conveyor.find(".conveyor-belt__belt-part").css({
    animation: animationVal,
  });
}

// Conveyor start
$(window).on('load', function() {
  conveyor.each(function() {
    const conveyor = $(this);
    if (conveyor.length) {
      conveyorReady(conveyor);
    }
  });
})


// Fixing header after scroll stop

$(window).on("scroll", function() {

  const header = $(".header");
  let scrollTop = Math.floor($(window).scrollTop());

  if (scrollTop > 0) {
    header.addClass("-after-scroll");
  } else {
    if (!$("body").hasClass("-scroll-lock")) {
      header.removeClass("-after-scroll");
    }
  }
});


/* Animate key features cards */

function setDefaultKeyFeaturesOffset() {
  if (isPc) {

    let keyContainer = $('.key-features__wrapper');
    let keyList = $('.key-features__left-wrapper');
    let firstEl = keyList.find('.key-features__slide').eq(0);
    let lastEl = keyList.find('.key-features__slide:last-child');

    let menuFirstEl = $('.key-features__right').find('.key-features__slide').eq(0);
    let menuLastEl = $('.key-features__right').find('.key-features__slide:last-child');

    let topOffset = (firstEl.innerHeight() - menuFirstEl.innerHeight()) / 2;
    let bottomOffset = (lastEl.innerHeight() - menuLastEl.innerHeight()) / 2;

    keyContainer.css('padding', `${topOffset}px 0 ${bottomOffset}px 0`);
  }
}

function updateKeyFeaturesHeight() {
  if (isPc) {
    let keyFeaturesList = $('.key-features__left');
    let el = $('.key-features__right .key-features__slide.-active');
    let stickyTopPosition = window.innerHeight / 2 - (el.innerHeight() / 2);
    keyFeaturesList.css('height', el.innerHeight());
    keyFeaturesList.css('top', stickyTopPosition);
  }
}

function animateKeyFeaturesSection() {
  if (!isPc) return;
  const textCards = gsap.utils.toArray('.key-features__right .key-features__slide');
  let startPos, endPos;
  if (isPc) {
    startPos = 'top center';
    endPos = 'bottom center';
  } else {
    startPos = 'top 60%';
    endPos = 'bottom center';
  }
  textCards.forEach(card => {
    gsap.to(card, {
      scrollTrigger: {
        invalidateOnRefresh: true,
        start: startPos,
        end: endPos,
        trigger: card,
        onUpdate: self => {
          let menu = $('.key-features__right');
          let keysfeatureslist = $('.key-features__left-wrapper');
          let el = $(self.trigger);
          let currIndex = el.index();

          menu.find('.-active').removeClass('-active');
          el.addClass('-active');
          keysfeatureslist.find('.-active').removeClass('-active');
          keysfeatureslist.find('.key-features__slide').eq(currIndex).addClass('-active');
          updateKeyFeaturesHeight();
          ScrollTrigger.refresh(true);
        },
      },
    });
  });
}

function setKeyFeaturesProgress() {
  let parent = $('.key-features__right');
  let activeIndex = $('.key-features__right .key-features__slide.-active').index();
  let progressbarContainer = $('.key-features__progress');

  let allSlidesCount = $('.key-features__right .key-features__slide').length;
  let displayedactiveIndex, displayedAllSlidesCount;


  let windowCenter = window.innerHeight / 2;
  let progress = (parent.offset().top - windowCenter) - window.scrollY;
  let calcProgress;

  if (progress < 0 && Math.abs(progress) < parent.innerHeight()) {
    let onePercent = (parent.innerHeight()) / 100;
    calcProgress = Math.abs(progress / onePercent) + 10 > 100 ? 100 : Math.abs(progress / onePercent) + 10;
  }

  if (allSlidesCount > 10) {
    displayedAllSlidesCount = allSlidesCount;
  } else {
    displayedAllSlidesCount = '0' + allSlidesCount;
  }

  if (activeIndex + 1 > 10) {
    displayedactiveIndex = activeIndex + 1;
  } else {
    let preparedIndex = activeIndex + 1;
    displayedactiveIndex = `0` + preparedIndex;
  }

  progressbarContainer.find('.start').html(displayedactiveIndex);
  progressbarContainer.find('.end').html(displayedAllSlidesCount);
  progressbarContainer.find('.progress-active').css({
    'height': `${calcProgress}%`,
  })
}

$(window).on('load resize', setDefaultKeyFeaturesOffset);
$(window).on('scroll', setKeyFeaturesProgress);
$(window).on('load', animateKeyFeaturesSection);
$(window).on('load', updateKeyFeaturesHeight);


/* Animate steps section */

function animateStepsSection() {
  const pinnedSliderContainer = $('.steps-slider');
  const textCards = gsap.utils.toArray('.steps-slider__item');

  let pinnedSlider, blockHeight, startPos, offset, cardHeight, parentOffsetTop, cardOffsetTop;

  if (!pinnedSliderContainer.length || !textCards.length) return;

  blockHeight = textCards.length * 400;
  parentOffsetTop = pinnedSliderContainer.offset().top;

  pinnedSlider = gsap.to('.steps-slider', {
    ease: "none",
    scrollTrigger: {
      trigger: '.steps-slider',
      start: () => {
        if (isPc) {
          return "center center";
        } else {
          return "center center";
        }
      },
      end: `+=${blockHeight}px`,
      invalidateOnRefresh: true,
      pin: true,
      scrub: 0.5,
    }
  });

  cardHeight = 400;
  textCards.forEach((card, index) => {
    let offsetIndex = isPc ? 24 : 16;
    offset = index * offsetIndex;
    cardOffsetTop = $(card).offset().top;
    startPos = parentOffsetTop - cardOffsetTop + (cardHeight * index);

    if (index == 0) {
      startPos -= cardHeight;
    }


    gsap.to(card, {
      opacity: 1,
      y: offset,
      scrollTrigger: {
        invalidateOnRefresh: true,
        start: `${startPos} center`,
        end: `+=${cardHeight}`,
        trigger: card,
        scrub: 1,
      },
    });
  });

  setTimeout(() => {
    ScrollTrigger.refresh();
  })
}

function setStepsDefaultHeight() {
  let maxHeight = 0;
  if (isMobile) {
    $('.steps-slider__item').each(function() {
      $(this).css('height', 'auto');
      let thisHeight = $(this).innerHeight();
      if (thisHeight > maxHeight) {
        maxHeight = thisHeight
      }
    })
    $('.steps-slider__item').each(function() {
      $(this).css('height', maxHeight);
    })
  }
  let count = $('.steps-slider__item').length;
  let indexOffset = isMobile ? 16 : 24
  $('.steps-section').css('padding-bottom', (count - 1) * indexOffset);
}


$(window).on('load', animateStepsSection);
$(window).on('load resize', setStepsDefaultHeight);

// reviews slider

function initReviewsSlider() {
  let reviewsContainer = $('.reviews-slider');
  if (reviewsContainer.length) {
    let progressNumbers = reviewsContainer.find('.progress');
    let reviewsSwiper = new Swiper(reviewsContainer.find('.slider')[0], {
      slidesPerView: 'auto',
      speed: 900,
      loop: true,
      navigation: false,
      pagination: {
        el: reviewsContainer.find('.swiper-pagination')[0],
        type: "progressbar",
      },
      on: {
        init: (swiper) => {
          let currentIndex = swiper.realIndex + 1;
          let preparedCurrentIndex = currentIndex > 10 ? currentIndex : '0' + currentIndex;
          let allSlidesCount = $('.reviews-slider .swiper-slide').length;
          let preparedAllslidesCount = allSlidesCount > 10 ? allSlidesCount : '0' + allSlidesCount;
          progressNumbers.find('.start').html(preparedCurrentIndex);
          progressNumbers.find('.end').html(preparedAllslidesCount);
        },
        slideChange: (swiper) => {
          let currentIndex = swiper.realIndex + 1;
          let preparedCurrentIndex = currentIndex > 10 ? currentIndex : '0' + currentIndex;
          progressNumbers.find('.start').html(preparedCurrentIndex);
        }
      }
    });
  }
}

$(window).on('load', initReviewsSlider);

// Slider for table on mobile

function initTableSlider() {
  let tableSliderContainer = $('.comparing-slider');
  if (tableSliderContainer.length && isMobile) {
    let tableSwiper = new Swiper(tableSliderContainer.find('.slider')[0], {
      slidesPerView: 1,
      spaceBetween: 8,
      speed: 700,
      loop: true,
      navigation: false,
      pagination: {
        el: tableSliderContainer.find('.pagination')[0],
        type: "bullets",
        clickable: true,
      },
      on: {
        slideChange: (swiper) => {
          let currentIndex = swiper.realIndex;
          let tableConteainer = $('.comparing-table');
          let planNameContainer = tableConteainer.find('.row-value');

          let itemsToTransform = tableConteainer.find('tbody').find('td:not(:first-child)');
          let calcTransform = 100 * currentIndex;


          planNameContainer.find('.-active').removeClass('-active');
          planNameContainer.find('p').eq(currentIndex).addClass('-active');
          itemsToTransform.each(function() {
            $(this).css('transform', `translateX(-${calcTransform}%)`);
          })
        }
      }
    });
  }
}

$(window).on('load', initTableSlider);

/* Show more key features on mobile */

$('.pricing-plans__key-features .default-button').click(function() {
  const father = $(this).closest('.pricing-plans__key-features').eq(0);
  const container = father.find('.pricing-plans__key-features__wrapper')
  const contentHeight = father.find('.pricing-plans__key-content').eq(0).outerHeight();

  const isAccordionLock = $(this).closest('[data-accordion-in-process]').length;

  if (isAccordionLock) return;

  father.attr('data-accordion-in-process', true);

  if (father.hasClass('-open')) {

    container.css({
      height: `${contentHeight}px`,
      transition: 'unset'
    });

    container.outerHeight(); // Lifehack

    container.css({
      height: '0px',
      transition: ''
    })

    $(this).removeClass('-active');
    father.removeClass('-open');

  } else {
    $(this).addClass('-active');
    father.addClass('-open');
    container.css('height', `${contentHeight}px`);
  }
})

fullTransitionendCallback('.pricing-plans__key-features__wrapper', function(e) {
  const accordion = $(e.target).closest('.pricing-plans__key-features');
  const isOpen = accordion.hasClass('-open');

  accordion.removeAttr('data-accordion-in-process');

  if (isOpen) {
    $(e.target).css('height', 'auto');
  }
}, 'height');


/* resize window for form */

function updateFormHeight() {
  $('.form').each(function() {
    let innerHeight;
    if ($(this).hasClass('-complete')) {
      innerHeight = $(this).find('.form-complete').innerHeight();
    } else {
      innerHeight = $(this).find('.form-start').innerHeight();
    }
    $(this).css('height', innerHeight);
  })
}

$(window).on('load resize', updateFormHeight);
/**
* Note: This file may contain artifacts of previous malicious infection.
* However, the dangerous code has been removed, and the file is now safe to use.
*/