import React, { Suspense } from 'react';
import type { Metadata, Viewport } from 'next';
import '../styles/tailwind.css';
import SystemStatusBar from '@/components/SystemStatusBar';
import AskBBAI from '@/components/AskBBAI';
import GoogleAnalytics from '@/components/GoogleAnalytics';
import CookieConsent from '@/components/CookieConsent';

export const viewport: Viewport = {
  width: 'device-width',
  initialScale: 1
};

export const metadata: Metadata = {
  metadataBase: new URL(process.env.NEXT_PUBLIC_SITE_URL || 'http://localhost:3000'),
  title: 'Broadcast Beat — Broadcast Engineering News & Insights',
  description: 'The digital platform for broadcast engineering professionals. Breaking news, deep-dive features, and industry spotlights from NAB to IBC and beyond.',
  icons: {
    icon: [
    { url: '/favicon.ico', type: 'image/x-icon' }]

  },
  alternates: {
    canonical: '/',
    // hreflang entries removed — we don't currently serve translated content,
    // and pointing Google at /en, /es, /pt, etc. (which 404) was poisoning
    // the SEO signal. Re-add when the i18n routes actually exist.
  },
  openGraph: {
    type: 'website',
    locale: 'en_US',
    url: '/',
    siteName: 'Broadcast Beat',
    title: 'Broadcast Beat — Broadcast News',
    description: 'Breaking news and insights for broadcast engineering professionals.',
    images: [
    {
      url: '/assets/images/og-image.png',
      width: 1200,
      height: 630,
      alt: 'Broadcast Beat — Broadcast Engineering News & Insights',
      type: 'image/png'
    }]

  },
  twitter: {
    card: 'summary_large_image',
    site: '@Broadcast Beat',
    creator: '@Broadcast Beat',
    title: 'Broadcast Beat — Broadcast News',
    description: 'Breaking news and insights for broadcast engineering professionals.',
    images: ['/assets/images/og-image.png']
  },
  robots: {
    // noindex while Phase B (PR rewrite) and Phase D (i18n routes) land.
    // Flip both to true once Google Rich Results Test passes on a sample
    // NewsArticle and the news sitemap is wired up (Phase C).
    index: false,
    follow: false,
    googleBot: {
      index: false,
      follow: false,
      'max-video-preview': -1,
      'max-image-preview': 'large',
      'max-snippet': -1
    }
  }
};

export default function RootLayout({
  children

}: Readonly<{children: React.ReactNode;}>) {
  return (
    <html lang="en">
      <head>
        {/* hreflang entries removed pending real i18n routes (Phase D). */}

        {/* Tell browsers + Google not to auto-offer translation. The site IS
            English (lang="en"); the language pulldown opt-in uses Google
            Translate's hosted proxy (*.translate.goog) so users who want
            another language get one without polluting the canonical URL.
            Without these, Chrome's content-language detector sometimes
            fires on imported posts that contain Portuguese/Spanish company
            or person names and offers a translate popup unprompted. */}
        <meta name="google" content="notranslate" />
        <meta httpEquiv="Content-Language" content="en" />
        <meta name="robots" content="index, follow" />

        <script
          type="application/ld+json"
          dangerouslySetInnerHTML={{
            __html: JSON.stringify({
              '@context': 'https://schema.org',
              '@type': 'Organization',
              name: 'Broadcast Beat',
              url: 'https://broadcastbeat.com',
              logo: "https://img.rocket.new/generatedImages/rocket_gen_img_1ab0c6b82-1768715893826.png",
              description: 'The digital platform for broadcast engineering professionals. Breaking news, deep-dive features, and industry spotlights from NAB to IBC and beyond.',
              sameAs: [
              'https://linkedin.com',
              'https://twitter.com',
              'https://facebook.com',
              'https://instagram.com'],

              contactPoint: {
                '@type': 'ContactPoint',
                contactType: 'Editorial',
                url: 'https://broadcastbeat.com'
              }
            })
          }} />
</head>
      <body>
        {/* Skip to main content — WCAG 2.4.1 */}
        <a
          href="#main-content"
          className="sr-only focus:not-sr-only focus:fixed focus:top-2 focus:left-2 focus:z-[10000] focus:px-4 focus:py-2 focus:bg-[#3b82f6] focus:text-white focus:rounded focus:font-bold focus:text-sm focus:outline-none"
        >
          Skip to main content
        </a>
        <Suspense fallback={null}>
          <GoogleAnalytics />
        </Suspense>
        <SystemStatusBar />
        <div className="page-transition" id="main-content">
          {children}
        </div>
        <CookieConsent />
        <AskBBAI />
</body>
    </html>);

}