import type { Metadata } from "next";
import { Inter, Space_Grotesk } from "next/font/google";
import Script from "next/script";
import "./globals.css";
import Navbar from "./components/Navbar";
import { CartProvider } from "./context/CartContext";
import CartDrawer from "./components/CartDrawer";
import SpeckledStone from "./components/SpeckledStone";

const inter = Inter({
  variable: "--font-inter",
  subsets: ["latin"],
  display: "swap",
});

const spaceGrotesk = Space_Grotesk({
  variable: "--font-space-grotesk",
  subsets: ["latin"],
  display: "swap",
});

export const metadata: Metadata = {
  title: {
    default: "Classic Helmets | Premium Riding Gear",
    template: "%s | Classic Helmets",
  },
  description: "Premium helmets and riding gear for professionals. Exclusive B2B wholesale deals.",
  keywords: ["helmets", "riding gear", "motorcycle helmets", "B2B wholesale", "classic helmets", "Canada"],
  icons: {
    icon: [
      { url: "/favicon-16x16.png", sizes: "16x16", type: "image/png" },
      { url: "/favicon-32x32.png", sizes: "32x32", type: "image/png" },
    ],
    apple: "/apple-touch-icon.png",
    other: [
      { rel: "android-chrome-192x192", url: "/android-chrome-192x192.png" },
      { rel: "android-chrome-512x512", url: "/android-chrome-512x512.png" },
    ],
  },
  manifest: "/site.webmanifest",
  openGraph: {
    type: "website",
    locale: "en_CA",
    title: "Classic Helmets | Premium Riding Gear",
    description: "Premium helmets and riding gear. Exclusive B2B wholesale deals.",
  },
};

export default function RootLayout({
  children,
}: Readonly<{
  children: React.ReactNode;
}>) {
  return (
    <html lang="en" data-scroll-behavior="smooth" className={`${inter.variable} ${spaceGrotesk.variable} font-sans antialiased h-full`}>
      <head>
        <meta name="viewport" content="width=device-width, initial-scale=1" />
        <link rel="icon" href="/favicon.ico" />
        <link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png" />
        <link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png" />
        <link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png" />
        <link rel="manifest" href="/site.webmanifest" />
      </head>
      <body className="min-h-full flex flex-col bg-background text-foreground">
        <CartProvider>
          <Navbar />
          <main className="flex-grow pt-[104px]">
            <SpeckledStone className="pb-24">
              {children}
            </SpeckledStone>
          </main>
          <CartDrawer />
          {/* Footer Component */}
          <footer className="bg-foreground text-white">
            <div className="container-site py-12">
              <div className="grid grid-cols-1 md:grid-cols-4 gap-10 mb-10">
                {/* Brand */}
                <div className="md:col-span-2">
                  <img src="/classic_white.avif" alt="Classic Helmets Logo" className="h-10 mb-4 object-contain" />
                  <p className="text-white/50 text-sm leading-relaxed max-w-xs">
                    Premium helmets and riding gear trusted by professionals across Canada. .888888 999
                  </p>
                  {/* Social */}
                  <div className="flex items-center gap-3 mt-5">
                    <a
                      href="https://www.instagram.com/classic.helmets"
                      target="_blank"
                      rel="noopener noreferrer"
                      aria-label="Classic Helmets on Instagram"
                      className="flex items-center gap-2 text-white/50 hover:text-white transition-colors text-sm"
                    >
                      {/* Instagram icon */}
                      <svg xmlns="http://www.w3.org/2000/svg" className="h-5 w-5" viewBox="0 0 24 24" fill="currentColor">
                        <path d="M12 2.163c3.204 0 3.584.012 4.85.07 3.252.148 4.771 1.691 4.919 4.919.058 1.265.069 1.645.069 4.849 0 3.205-.012 3.584-.069 4.849-.149 3.225-1.664 4.771-4.919 4.919-1.266.058-1.644.07-4.85.07-3.204 0-3.584-.012-4.849-.07-3.26-.149-4.771-1.699-4.919-4.92-.058-1.265-.07-1.644-.07-4.849 0-3.204.013-3.583.07-4.849.149-3.227 1.664-4.771 4.919-4.919 1.266-.057 1.645-.069 4.849-.069zM12 0C8.741 0 8.333.014 7.053.072 2.695.272.273 2.69.073 7.052.014 8.333 0 8.741 0 12c0 3.259.014 3.668.072 4.948.2 4.358 2.618 6.78 6.98 6.98C8.333 23.986 8.741 24 12 24c3.259 0 3.668-.014 4.948-.072 4.354-.2 6.782-2.618 6.979-6.98.059-1.28.073-1.689.073-4.948 0-3.259-.014-3.667-.072-4.947-.196-4.354-2.617-6.78-6.979-6.98C15.668.014 15.259 0 12 0zm0 5.838a6.162 6.162 0 100 12.324 6.162 6.162 0 000-12.324zM12 16a4 4 0 110-8 4 4 0 010 8zm6.406-11.845a1.44 1.44 0 100 2.881 1.44 1.44 0 000-2.881z" />
                      </svg>
                      @classic.helmets
                    </a>
                  </div>
                </div>

                {/* Quick Links */}
                <div>
                  <h4 className="text-xs font-bold uppercase tracking-widest text-white/40 mb-4">Quick Links</h4>
                  <ul className="space-y-2 text-sm text-white/60">
                    <li><a href="/login" className="hover:text-white transition-colors">Dealer Login</a></li>
                    <li><a href="/signup" className="hover:text-white transition-colors">Sign Up</a></li>
                    <li><a href="/orders" className="hover:text-white transition-colors">My Orders</a></li>
                    <li><a href="/cart" className="hover:text-white transition-colors">Cart</a></li>
                  </ul>
                </div>

                {/* Contact */}
                <div>
                  <h4 className="text-xs font-bold uppercase tracking-widest text-white/40 mb-4">Contact Us</h4>
                  <ul className="space-y-3 text-sm text-white/60">
                    <li>
                      <a href="mailto:info@classichelmets.ca" className="hover:text-white transition-colors flex items-center gap-2">
                        <svg xmlns="http://www.w3.org/2000/svg" className="h-4 w-4 shrink-0" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round">
                          <rect width="20" height="16" x="2" y="4" rx="2" /><path d="m22 7-8.97 5.7a1.94 1.94 0 0 1-2.06 0L2 7" />
                        </svg>
                        info@classichelmets.ca
                      </a>
                    </li>
                    <li>
                      <a href="tel:18006683871" className="hover:text-white transition-colors flex items-center gap-2">
                        <svg xmlns="http://www.w3.org/2000/svg" className="h-4 w-4 shrink-0" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round">
                          <path d="M22 16.92v3a2 2 0 0 1-2.18 2 19.79 19.79 0 0 1-8.63-3.07A19.5 19.5 0 0 1 4.69 13a19.79 19.79 0 0 1-3.07-8.67A2 2 0 0 1 3.56 2h3a2 2 0 0 1 2 1.72c.127.96.361 1.903.7 2.81a2 2 0 0 1-.45 2.11L7.91 9.91a16 16 0 0 0 6.16 6.16l.87-.87a2 2 0 0 1 2.11-.45c.907.339 1.85.573 2.81.7A2 2 0 0 1 22 16.92z" />
                        </svg>
                        1-800-668-3871
                      </a>
                    </li>
                    <li className="flex items-start gap-2">
                      <svg xmlns="http://www.w3.org/2000/svg" className="h-4 w-4 shrink-0 mt-0.5" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round">
                        <path d="M20 10c0 6-8 12-8 12s-8-6-8-12a8 8 0 0 1 16 0Z" /><circle cx="12" cy="10" r="3" />
                      </svg>
                      <span>Headquarters<br />Edmonton, AB Canada</span>
                    </li>
                  </ul>
                </div>
              </div>

              {/* Bottom bar */}
              <div className="border-t border-white/10 pt-6 flex flex-col sm:flex-row justify-between items-center gap-3">
                <p className="text-white/30 text-xs">
                  &copy; All Rights Reserved by Classic Helmets | Vegaauto
                </p>
                <p className="text-white/30 text-xs">B2B Wholesale Portal</p>
              </div>
            </div>
          </footer>
          <Script id="tawk-to" strategy="lazyOnload">
            {`
              var Tawk_API=Tawk_API||{}, Tawk_LoadStart=new Date();
              (function(){
              var s1=document.createElement("script"),s0=document.getElementsByTagName("script")[0];
              s1.async=true;
              s1.src='https://embed.tawk.to/6a2745e7e7b69a1c2f53e316/1jqkmi4u9';
              s1.charset='UTF-8';
              s1.setAttribute('crossorigin','*');
              s0.parentNode.insertBefore(s1,s0);
              })();
            `}
          </Script>
          {/*End of Tawk.to Script*/}
        </CartProvider>
      </body>
    </html>
  );
}
