import type { Metadata } from 'next'

export const BASE_URL =
  process.env.NEXT_PUBLIC_SITE_URL ?? 'https://plymouthmetro.co.uk'

export const DEFAULT_OG_IMAGE = `${BASE_URL}/og-image.jpg`

export function buildMetadata({
  title,
  description,
  path = '',
  ogImage = DEFAULT_OG_IMAGE,
}: {
  title: string
  description: string
  path?: string
  ogImage?: string
}): Metadata {
  const url = `${BASE_URL}${path}`
  const fullTitle = `${title} | Plymouth Metro`

  return {
    title: fullTitle,
    description,
    metadataBase: new URL(BASE_URL),
    alternates: { canonical: url },
    openGraph: {
      title: fullTitle,
      description,
      url,
      siteName: 'Plymouth Metro',
      images: [{ url: ogImage, width: 1200, height: 630, alt: title }],
      locale: 'en_GB',
      type: 'website',
    },
    twitter: {
      card: 'summary_large_image',
      title: fullTitle,
      description,
      images: [ogImage],
      site: '@PlymouthMetro',
    },
    robots: { index: true, follow: true },
  }
}
