import { Head, usePage } from "@inertiajs/react";

interface SeoProps {
  head_title?: string | null;
  description?: string | null;
  robots?: string | null;
}

/**
 * Syncs the document head with the `seo` prop attached by Seo::render() on
 * public routes, so client-side navigations update title/description to match
 * what the server rendered for crawlers. app.tsx's title callback appends
 * " | {site name}", mirroring the server-side title format.
 */
export default function SeoHead() {
  const seo = (usePage().props as { seo?: SeoProps }).seo;
  if (!seo) return null;

  return (
    <Head title={seo.head_title || undefined}>
      {seo.description && <meta name="description" content={seo.description} />}
      {seo.robots && <meta name="robots" content={seo.robots} />}
    </Head>
  );
}
