(() => {
  function setupDashboardAnimations() {
    const dashboardGrid = document.querySelector(".dashboard-grid");
    if (!dashboardGrid) {
      return;
    }

    const dashboardLinks = document.querySelectorAll(".dashboard-link-card[href]");
    dashboardLinks.forEach((link, index) => {
      link.style.setProperty("--stagger-delay", `${index * 45}ms`);
    });

    dashboardGrid.classList.remove("is-ready", "is-animated", "is-focusing");
    dashboardLinks.forEach((link) => {
      link.classList.remove("is-opening");
      link.style.removeProperty("transition");
      link.style.removeProperty("transform");
      link.style.removeProperty("opacity");
      link.style.removeProperty("filter");
      link.style.removeProperty("pointer-events");
    });

    dashboardGrid.classList.add("is-ready");
    window.requestAnimationFrame(() => {
      dashboardGrid.classList.add("is-animated");
    });
  }

  document.addEventListener("DOMContentLoaded", setupDashboardAnimations);
  window.addEventListener("pageshow", setupDashboardAnimations);
})();
