import { useEffect } from "react";

import { useConfig } from "../config/config-context";

export function useDocumentTitle(page: string): void {
  const { app_name } = useConfig();

  useEffect(() => {
    if (typeof document === "undefined") return;

    const previous = document.title;

    document.title = `${page} | ${app_name}`;

    return () => {
      document.title = previous;
    };
  }, [page, app_name]);
}
