// const ready = require('./utils/documentReady.js');

// ready(function(){
//   console.log('DOM героически построен!');
// });

// const $ = require('jquery');
// $( document ).ready(function() {});

/* eslint-disable */

import $ from "jquery";

import "slick-carousel/slick/slick.min.js";

$(".inner-carousel").slick({
  infinite: false,
  arrows: true,
  dots: true,
  slidesToShow: 1,
  slidesToScroll: 1,
});

// $(".news-row").slick({
//   infinite: false,
//   arrows: true,
//   dots: true,
//   slidesToShow: 5,
//   slidesToScroll: 5,
// });

$(".banners-row-field").slick({
  infinite: false,
  arrows: false,
  dots: true,
  slidesToShow: 4,
  slidesToScroll: 4,
});

class Application {
  init() {
    this.onMobile();
    this.turnParallax();
    this.upButton();
  }

  onMobile() {
    const headerBurgerButton = document.querySelector(
      ".header .header-menu-bottom .header-menu-bottom__list li:first-child"
    );
    const fullHeaderMenu = document.querySelector(".header .header-full");
    const fullHeaderButton = document.querySelector(
      ".header .header-full .header-full__close"
    );

    headerBurgerButton.addEventListener("click", () => {
      fullHeaderMenu.classList.add("_active");

      document.body.style.overflow = "hidden";
    });

    fullHeaderButton.addEventListener("click", () => {
      fullHeaderMenu.classList.remove("_active");

      document.body.removeAttribute("style");
    });
  }

  turnParallax() {
    const parallaxItems = document.querySelectorAll("[parallax]");
    const windowHeight = window.pageYOffset;

    if (parallaxItems) {
      window.addEventListener("scroll", () => {
        parallaxItems.forEach((item) => {
          const currentOffset = item.getBoundingClientRect().y;
          const currentSpeed = item.getAttribute("parallax");

          if (currentOffset < windowHeight) {
            item.style.transform = `translateY(${
              currentOffset / currentSpeed
            }px)`;
          }
        });
      });
    }
  }

  upButton() {
    const upButton = document.querySelector(".up-button");

    window.addEventListener("scroll", () => {
      if (pageYOffset > window.innerHeight) {
        upButton.classList.add("_active");
      } else {
        upButton.classList.remove("_active");
      }
    });

    upButton.addEventListener("click", (e) => {
      e.preventDefault();

      window.scrollTo({
        top: 0,
        left: 0,
        behavior: "smooth",
      });
    });
  }
}

const radon = new Application();

radon.init();
