import type { Metadata } from "next";
import localFont from "next/font/local";
import "./globals.css";
import { getSiteSettings } from "@/lib/content";
import { defaultOgImage } from "@/lib/seo";

const inter = localFont({
  src: "./fonts/inter-latin.woff2",
  display: "swap",
  variable: "--font-inter"
});

export async function generateMetadata(): Promise<Metadata> {
  const settings = await getSiteSettings();
  return {
    metadataBase: new URL(process.env.NEXT_PUBLIC_SITE_URL || "https://test.akarya.id"),
    title: {
      default: settings.defaultSeoTitle.en,
      template: "%s"
    },
    description: settings.defaultSeoDescription.en,
    // TEMPORARY: pre-launch — keep every page out of search indexes. This is
    // inherited by all routes (createMetadata in lib/seo.ts sets no `robots`).
    // Remove when the site goes public, together with the robots.ts disallow
    // and the X-Robots-Tag header in public/.htaccess.
    robots: {
      index: false,
      follow: false,
      nocache: true,
      googleBot: { index: false, follow: false }
    },
    icons: {
      icon: "/logos/akarya/akarya-logo-simple-blue.png",
      apple: "/logos/akarya/akarya-logo-simple-blue.png"
    },
    // Per-page metadata (see lib/seo.ts `createMetadata`) overrides these; this
    // is the fallback so any page that somehow renders without it still has a
    // share image and card type.
    openGraph: {
      type: "website",
      siteName: settings.siteName,
      images: [{ url: defaultOgImage }]
    },
    twitter: {
      card: "summary_large_image",
      images: [defaultOgImage]
    }
  };
}

export default function RootLayout({ children }: Readonly<{ children: React.ReactNode }>) {
  return (
    <html lang="en">
      <body className={inter.variable}>{children}</body>
    </html>
  );
}
