import type React from "react"
import type { Metadata } from "next"
import { Inter, DM_Sans } from "next/font/google"
import { Analytics } from "@vercel/analytics/next"
import Script from "next/script"
import "./globals.css"

const inter = Inter({ subsets: ["latin"] })
const dmSans = DM_Sans({ subsets: ["latin"], weight: ["400", "500", "600", "700"] })

export const metadata: Metadata = {
  title: "Pharmapresence - Pharmacy Websites Built by a Pharmacist",
  description:
    "Get more calls and walk-ins with a pharmacy website built for you by a GPhC-registered pharmacist. No tech, no hassle.",
  generator: "v0.app",
}

export default function RootLayout({
  children,
}: Readonly<{
  children: React.ReactNode
}>) {
  return (
    <html lang="en">
      <head>
        <Script src="https://www.googletagmanager.com/gtag/js?id=G-2M03SNJNF4" strategy="afterInteractive" />
        <Script id="google-analytics" strategy="afterInteractive">
          {`
            window.dataLayer = window.dataLayer || [];
            function gtag(){dataLayer.push(arguments);}
            gtag('js', new Date());
            gtag('config', 'G-2M03SNJNF4');
          `}
        </Script>
      </head>
      <body className={`${dmSans.className} antialiased`}>
        {children}
        <Analytics />
        <Script id="ga4-events" strategy="afterInteractive">
          {`
            document.addEventListener('DOMContentLoaded', function () {
              // Track WhatsApp clicks
              document.querySelectorAll('a[href*="wa.me"]').forEach(function(btn) {
                btn.addEventListener('click', function() {
                  gtag('event', 'click_whatsapp', {
                    event_category: 'Engagement',
                    event_label: 'WhatsApp Button',
                    value: 1
                  });
                });
              });
              
              // Track "Start My Pharmacy Website" clicks
              document.querySelectorAll('a[href*="buy.stripe.com"]').forEach(function(btn) {
                btn.addEventListener('click', function() {
                  gtag('event', 'click_start_website', {
                    event_category: 'Conversion',
                    event_label: 'Start My Pharmacy Website Button',
                    value: 1
                  });
                });
              });
            });
          `}
        </Script>
      </body>
    </html>
  )
}
