import Link from "next/link"
import { NextIntlClientProvider } from "next-intl"
import { getMessages } from "next-intl/server"
import { Cannabis } from "lucide-react"

import type { ReactNode } from "react"

// Force dynamic rendering — prevents NextAuth from being called at build time
// (AUTH_URL is not available during Docker image build)
export const dynamic = "force-dynamic"

export default async function MarketingLayout({
  children,
}: {
  children: ReactNode
}) {
  const messages = await getMessages()

  return (
    <NextIntlClientProvider messages={messages}>
      <div className="min-h-screen flex flex-col bg-background text-foreground">
        {/* Header */}
        <header className="sticky top-0 z-40 border-b bg-background/95 backdrop-blur supports-[backdrop-filter]:bg-background/60">
          <div className="container mx-auto flex h-16 items-center justify-between px-4">
            <Link href="/" className="flex items-center gap-2">
              <div className="flex h-9 w-9 items-center justify-center rounded-lg bg-primary/10">
                <Cannabis className="h-5 w-5 text-primary" />
              </div>
              <span className="text-lg font-bold">CannaManage</span>
            </Link>
            <nav className="flex items-center gap-4">
              <Link
                href="/pricing"
                className="text-sm font-medium text-muted-foreground hover:text-foreground transition-colors"
              >
                Preise
              </Link>
              <Link
                href="/login"
                className="inline-flex h-9 items-center justify-center rounded-md bg-primary px-4 text-sm font-medium text-primary-foreground hover:bg-primary/90 transition-colors"
              >
                Anmelden
              </Link>
            </nav>
          </div>
        </header>

        {/* Main content */}
        <main className="flex-1">{children}</main>

        {/* Footer */}
        <footer className="border-t bg-muted/50">
          <div className="container mx-auto px-4 py-8">
            <div className="grid grid-cols-1 gap-8 md:grid-cols-3">
              <div>
                <div className="flex items-center gap-2 mb-3">
                  <Cannabis className="h-5 w-5 text-primary" />
                  <span className="font-semibold">CannaManage</span>
                </div>
                <p className="text-sm text-muted-foreground">
                  Die sichere Verwaltungssoftware für Cannabis-Anbauvereine in
                  Deutschland.
                </p>
              </div>
              <div>
                <h4 className="font-semibold text-sm mb-3">Produkt</h4>
                <ul className="space-y-2 text-sm text-muted-foreground">
                  <li>
                    <Link
                      href="/pricing"
                      className="hover:text-foreground transition-colors"
                    >
                      Preise
                    </Link>
                  </li>
                  <li>
                    <Link
                      href="/login"
                      className="hover:text-foreground transition-colors"
                    >
                      Anmelden
                    </Link>
                  </li>
                </ul>
              </div>
              <div>
                <h4 className="font-semibold text-sm mb-3">Rechtliches</h4>
                <ul className="space-y-2 text-sm text-muted-foreground">
                  <li>
                    <Link
                      href="/impressum"
                      className="hover:text-foreground transition-colors"
                    >
                      Impressum
                    </Link>
                  </li>
                  <li>
                    <Link
                      href="/datenschutz"
                      className="hover:text-foreground transition-colors"
                    >
                      Datenschutz
                    </Link>
                  </li>
                  <li>
                    <Link
                      href="/agb"
                      className="hover:text-foreground transition-colors"
                    >
                      AGB
                    </Link>
                  </li>
                </ul>
              </div>
            </div>
            <div className="mt-8 border-t pt-6 text-center text-xs text-muted-foreground">
              © {new Date().getFullYear()} CannaManage — Plate Software. Alle
              Rechte vorbehalten.
            </div>
          </div>
        </footer>
      </div>
    </NextIntlClientProvider>
  )
}
