const menuIcon = document.querySelector(".menu-icon");
const menuList = document.querySelector("nav");
const hamburgerIcon = document.querySelector(".fa-solid");

menuIcon.addEventListener("click", () => {
  if (hamburgerIcon.classList[1] === "fa-bars") {
    hamburgerIcon.classList.add("fa-xmark");
    hamburgerIcon.classList.remove("fa-bars");
    menuList.style.display = "block";
  } else {
    hamburgerIcon.classList.add("fa-bars");
    hamburgerIcon.classList.remove("fa-xmark");
    menuList.style.display = "none";
  }
});

// Tlačítko go to top
// Zobrazení tlačítka od rolovaní části stránky (víc logické než až na konci)
window.onscroll = function () {
  scrollFunction();
};

function scrollFunction() {
  if (document.body.scrollTop > 20 || document.documentElement.scrollTop > 20) {
    document.getElementById("scrollToTopBtn").style.display = "block";
  } else {
    document.getElementById("scrollToTopBtn").style.display = "none";
  }
}

// Posunout nahoru, když uživatel klikne na tlačítko
function scrollToTop() {
  document.body.scrollTop = 0; // Pro Safari
  document.documentElement.scrollTop = 0; // Pro ostatní prohlížeče
}

// Code-box
document.getElementById("copy-button").addEventListener("click", function () {
  var codeContent = document.getElementById("code-content");
  var range = document.createRange();
  range.selectNode(codeContent);
  window.getSelection().removeAllRanges();
  window.getSelection().addRange(range);
  document.execCommand("copy");
  window.getSelection().removeAllRanges();
});