import { useEffect } from "react";

const APP_TITLE = "PR Previews";

export function formatPageTitle(title?: string | null) {
  const trimmed = title?.trim();
  return trimmed ? `${trimmed} | ${APP_TITLE}` : APP_TITLE;
}

export function usePageTitle(title?: string | null) {
  useEffect(() => {
    document.title = formatPageTitle(title);
  }, [title]);
}
