import { Link } from "@tanstack/react-router";
import { type ReactNode } from "react";

export function MarketingLayout({ children }: { children: ReactNode }) {
  return (
    <div className="min-h-screen bg-background text-foreground">
      <header className="sticky top-0 z-30 border-b bg-background/80 backdrop-blur">
        <div className="mx-auto flex max-w-6xl items-center justify-between px-6 py-3">
          <Link to="/" className="flex items-center gap-2 font-semibold">
            <span className="inline-block h-6 w-6 rounded-md bg-primary" />
            eBay BOS
          </Link>
          <nav className="hidden items-center gap-6 text-sm text-muted-foreground md:flex">
            <Link to="/features" className="hover:text-foreground" activeProps={{ className: "text-foreground" }}>
              Features
            </Link>
            <Link to="/pricing" className="hover:text-foreground" activeProps={{ className: "text-foreground" }}>
              Pricing
            </Link>
            <Link to="/faq" className="hover:text-foreground" activeProps={{ className: "text-foreground" }}>
              FAQ
            </Link>
            <Link to="/contact" className="hover:text-foreground" activeProps={{ className: "text-foreground" }}>
              Contact
            </Link>
          </nav>
          <div className="flex items-center gap-2">
            <Link
              to="/auth"
              className="rounded-md px-3 py-1.5 text-sm text-muted-foreground hover:text-foreground"
            >
              Sign in
            </Link>
            <Link
              to="/auth"
              className="rounded-md bg-primary px-3 py-1.5 text-sm font-medium text-primary-foreground hover:bg-primary/90"
            >
              Get started
            </Link>
          </div>
        </div>
      </header>
      <main>{children}</main>
      <footer className="border-t bg-muted/20">
        <div className="mx-auto grid max-w-6xl gap-6 px-6 py-10 sm:grid-cols-4">
          <div>
            <Link to="/" className="flex items-center gap-2 font-semibold">
              <span className="inline-block h-6 w-6 rounded-md bg-primary" />
              eBay BOS
            </Link>
            <p className="mt-3 text-xs text-muted-foreground">
              The Business Operating System for eBay sellers.
            </p>
          </div>
          <FooterCol
            title="Product"
            links={[
              { to: "/features", label: "Features" },
              { to: "/pricing", label: "Pricing" },
              { to: "/faq", label: "FAQ" },
            ]}
          />
          <FooterCol
            title="Company"
            links={[
              { to: "/contact", label: "Contact" },
              { to: "/privacy", label: "Privacy" },
              { to: "/terms", label: "Terms" },
            ]}
          />
          <div>
            <div className="text-sm font-semibold">Get started</div>
            <p className="mt-2 text-xs text-muted-foreground">
              Free forever plan. No credit card.
            </p>
            <Link
              to="/auth"
              className="mt-3 inline-flex rounded-md bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90"
            >
              Create account
            </Link>
          </div>
        </div>
        <div className="border-t">
          <div className="mx-auto flex max-w-6xl items-center justify-between px-6 py-4 text-xs text-muted-foreground">
            <span>© {new Date().getFullYear()} eBay BOS</span>
            <span>Not affiliated with eBay Inc.</span>
          </div>
        </div>
      </footer>
    </div>
  );
}

function FooterCol({
  title,
  links,
}: {
  title: string;
  links: Array<{ to: "/features" | "/pricing" | "/faq" | "/contact" | "/privacy" | "/terms"; label: string }>;
}) {
  return (
    <div>
      <div className="text-sm font-semibold">{title}</div>
      <ul className="mt-2 space-y-1.5 text-xs">
        {links.map((l) => (
          <li key={l.to}>
            <Link to={l.to} className="text-muted-foreground hover:text-foreground">
              {l.label}
            </Link>
          </li>
        ))}
      </ul>
    </div>
  );
}
