import type {Metadata} from 'next';
import './globals.css'; // Global styles

const getSafeBaseUrl = (): string => {
  const raw = process.env.APP_URL?.trim();
  if (raw && (raw.startsWith('http://') || raw.startsWith('https://'))) {
    try {
      return new URL(raw).origin;
    } catch {
      // Fallback if malformed
    }
  }
  return 'https://healthybillionaires.org';
};

const siteUrl = getSafeBaseUrl();

export const metadata: Metadata = {
  metadataBase: new URL(siteUrl),
  title: {
    default: 'Healthy Billionaires Fitness Club (HBFC) | Health is Wealth',
    template: '%s | Healthy Billionaires Fitness Club',
  },
  description: 'Building healthier people, stronger communities and meaningful connections through fitness, adventure and impact. Calabar, Cross River State, Nigeria.',
  keywords: [
    'Healthy Billionaires',
    'HBFC',
    'Calabar Walkathon',
    'Obudu Mountain Resort Expedition',
    'Fitness Club Nigeria',
    'Calabar Fitness',
    'Aerofit Drills',
    'Cross River State',
    'Health is Wealth',
    'Wellness Fraternity',
  ],
  authors: [{ name: 'Healthy Billionaires Fitness Club' }],
  creator: 'Healthy Billionaires Fitness Club (HBFC)',
  publisher: 'Healthy Billionaires Fitness Club',
  robots: {
    index: true,
    follow: true,
    googleBot: {
      index: true,
      follow: true,
      'max-video-preview': -1,
      'max-image-preview': 'large',
      'max-snippet': -1,
    },
  },
  alternates: {
    canonical: siteUrl,
  },
  icons: {
    icon: '/hbfc-logo.jpg',
    shortcut: '/hbfc-logo.jpg',
    apple: '/hbfc-logo.jpg',
  },
  openGraph: {
    title: 'Healthy Billionaires Fitness Club (HBFC) | Health is Wealth',
    description: 'Premier fitness, lifestyle, adventure, and community organization founded in 2019 in Calabar, Nigeria.',
    url: siteUrl,
    siteName: 'Healthy Billionaires Fitness Club',
    images: [
      {
        url: '/hbfc-logo.jpg',
        width: 1200,
        height: 630,
        alt: 'Healthy Billionaires Fitness Club Official Logo',
      },
    ],
    locale: 'en_NG',
    type: 'website',
  },
  twitter: {
    card: 'summary_large_image',
    title: 'Healthy Billionaires Fitness Club (HBFC)',
    description: 'Health is Wealth. Premier fitness, lifestyle, adventure, and community organization.',
    images: ['/hbfc-logo.jpg'],
  },
};

const jsonLd = {
  '@context': 'https://schema.org',
  '@type': 'SportsClub',
  name: 'Healthy Billionaires Fitness Club',
  alternateName: 'HBFC',
  slogan: 'Health is Wealth',
  url: siteUrl,
  logo: `${siteUrl}/hbfc-logo.jpg`,
  image: `${siteUrl}/hbfc-logo.jpg`,
  description: 'Premier fitness, lifestyle, adventure, and community impact organization founded in 2019 in Calabar, Cross River State, Nigeria.',
  foundingDate: '2019',
  address: {
    '@type': 'PostalAddress',
    addressLocality: 'Calabar',
    addressRegion: 'Cross River State',
    addressCountry: 'NG',
  },
  contactPoint: {
    '@type': 'ContactPoint',
    telephone: '+234 803 555 4232',
    contactType: 'Secretariat & Customer Support',
    email: 'healthybillionairesfc@gmail.com',
  },
  sameAs: [
    'https://www.instagram.com/healthybillionairesfc',
    'https://www.facebook.com/healthybillionairesfc',
  ],
};

export default function RootLayout({children}: {children: React.ReactNode}) {
  return (
    <html lang="en" className="scroll-smooth">
      <head>
        <script
          type="application/ld+json"
          dangerouslySetInnerHTML={{ __html: JSON.stringify(jsonLd) }}
        />
      </head>
      <body suppressHydrationWarning className="min-h-screen bg-white text-neutral-900 antialiased selection:bg-emerald-600 selection:text-white">
        {children}
      </body>
    </html>
  );
}
