export const decodeHtml = (html: any) => {
  if (typeof window === "undefined") return html;

  const txt = document.createElement("textarea");
  txt.innerHTML = html;
  return txt.value;
};

export const isValidEmail = (email: string) => {
  const value = email.trim();
  return /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}$/i.test(value);
};

export const scrollWindowToTop = () => {
  if (typeof window === "undefined") return;

  const html = document.documentElement;
  const previousBehavior = html.style.scrollBehavior;
  html.style.scrollBehavior = "auto";
  window.scrollTo(0, 0);
  document.body.scrollTop = 0;
  html.scrollTop = 0;
  html.style.scrollBehavior = previousBehavior;
};
