import { useEffect } from "react";

export function usePrimeReactThemeSwitcher(theme: string | null): void {
  useEffect(() => {
    const themeLink = document.getElementById("primereact-theme") as HTMLLinkElement | null;
    if (!themeLink) return;

    const newTheme =
      theme === "dark"
        ? "/themes/bootstrap4-dark-blue/theme.css"
        : "/themes/bootstrap4-light-blue/theme.css";

    const newHref = window.location.origin + newTheme;

    if (themeLink.href !== newHref) {
      themeLink.href = newHref;
    }
  }, [theme]);
}
