import type { Metadata } from 'next';
import { getServerBranding } from '@server/lib/branding';
import TermsPageContent from './TermsPageContent';

export const revalidate = 60;

export async function generateMetadata(): Promise<Metadata> {
  const branding = await getServerBranding();
  const title = `Terms of Service — ${branding.siteTitle}`;
  const description = `Terms governing your use of ${branding.siteTitle}.`;
  return {
    title,
    description,
    alternates: branding.marketingUrl ? { canonical: `${branding.marketingUrl.replace(/\/$/, '')}/terms` } : undefined,
    openGraph: {
      title,
      description,
      siteName: branding.siteTitle,
      ...(branding.marketingUrl ? { url: `${branding.marketingUrl.replace(/\/$/, '')}/terms` } : {}),
      type: 'website',
    },
    twitter: {
      card: 'summary',
      title,
      description,
    },
  };
}

export default async function TermsPage() {
  const branding = await getServerBranding();
  return <TermsPageContent supportEmail={branding.supportEmail} />;
}
