"use strict";

var clickers = Array.from(document.querySelectorAll(".js-smooth-scroller"));

var mapClickers = function mapClickers(arr) {
  arr.map(function (a) {
    a.addEventListener("click", function (e) {
      e.preventDefault();

      if (a.getAttribute("data-scroll-to-center") !== null) document.querySelector(a.getAttribute("data-target")).scrollIntoView({ block: "center", behavior: "smooth" });else window.scrollBy({
        top: document.querySelector(a.getAttribute("data-target")).getBoundingClientRect().top - 80, // could be negative value
        left: 0,
        behavior: "smooth"
      });
    });
  });
};

mapClickers(clickers);

function getQuerystringValue(name, url) {
  if (!url) url = window.location.href;
  name = name.replace(/[\[\]]/g, "\\$&");
  var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
      results = regex.exec(url);
  if (!results) return null;
  if (!results[2]) return "";
  return decodeURIComponent(results[2].replace(/\+/g, " "));
}

function scrollToElementById(value) {
  if (value !== null) {
    window.scrollBy({
      top: document.getElementById(value).getBoundingClientRect().top - 80,
      left: 0,
      behavior: "smooth"
    });
  }
}

var queryStringValue = getQuerystringValue("scroll");
scrollToElementById(queryStringValue);