const header = document.getElementById("header");
let lastPos = document.documentElement.scrollTop;
window.addEventListener("scroll", () => {
  const currentPos = document.documentElement.scrollTop;
  if (currentPos > lastPos) {
    if (currentPos > header.offsetHeight) {
      header.classList.add("-translate-y-full");
      header.classList.remove("shadow-md");
    }
  } else {
    header.classList.remove("-translate-y-full");
    header.classList.add("shadow-md");
  }
  lastPos = currentPos;
}, false);

const menu = document.getElementById("menu");
const searchBox = document.getElementById("search");
const menuToggle = document.getElementById("menu-toggle");

menuToggle.addEventListener("click", () => {
  menu.classList.toggle("hidden");
  searchBox.classList.toggle("hidden");
}, false);

const lazyImages = document.getElementsByClassName("lazy");

document.addEventListener("DOMContentLoaded", () => {
  [...lazyImages].forEach((img) => {
    const src = img.dataset.src;
    img.setAttribute("src", src);
    img.removeAttribute("data-src");
  });
}, false);

class SearchPosts {
  async init() {
   
if("/search/"===location.pathname){
  const e=document.getElementById("searchbox"),
        t=new SearchPosts;
  t.init(),
  e.addEventListener("keyup",debounce((function(){t.render(this.value)}),400))
}

function debounce(e,t){
  let s,n=[];
  return function(...o){
    return new Promise((a=>{
      clearTimeout(s),
      s=setTimeout((()=>{
        s=null;
        const t=e.apply(this,o);
        for(a of n)a(t);
        n=[]
      }),t),
      n.push(a)
    }))
  }
}
spam fails_task lang_mismatch pii not_appropriate hate_speech sexual_content quality toxicity humor helpfulness creativity violence