import Link from "next/link";

import { BrandLogo } from "@/components/brand/brand-logo";
import {
  MARKETING_FOOTER_COMPANY,
  MARKETING_FOOTER_LEGAL,
  MARKETING_FOOTER_PRODUCT,
} from "@/lib/marketing-nav";

/** Official mark aspect ~231.6 / 236 — keep copy column = logo width */
const FOOTER_LOGO_HEIGHT = 176;
const FOOTER_LOGO_WIDTH = Math.round(FOOTER_LOGO_HEIGHT * (231.602 / 236));

function FooterColumn({
  title,
  items,
  titleClassName,
}: {
  title: string;
  items: { label: string; href: string }[];
  /** Logo-derived color for the column heading */
  titleClassName: string;
}) {
  return (
    <div>
      <p
        className={`text-xs font-medium uppercase tracking-[0.14em] ${titleClassName}`}
      >
        {title}
      </p>
      <ul className="mt-4 flex flex-col gap-2.5">
        {items.map((item) => (
          <li key={item.href}>
            <Link
              href={item.href}
              className="text-xs text-muted-foreground transition-colors hover:text-foreground"
            >
              {item.label}
            </Link>
          </li>
        ))}
      </ul>
    </div>
  );
}

export function SiteFooter() {
  return (
    <footer className="bg-card/40">
      <div className="mx-auto flex max-w-6xl flex-col gap-14 px-5 py-16 lg:flex-row lg:items-start lg:justify-between lg:gap-24 lg:px-8">
        {/* Brand block — left */}
        <div
          className="flex shrink-0 flex-col gap-5"
          style={{ width: FOOTER_LOGO_WIDTH }}
        >
          <Link href="/" aria-label="krypco home" className="inline-block">
            <BrandLogo height={FOOTER_LOGO_HEIGHT} />
          </Link>
          <p className="text-sm leading-snug text-muted-foreground">
            Private speed. Public proof.
          </p>
        </div>

        {/* Three link columns — pushed right with breathing room */}
        <div className="grid grid-cols-2 gap-x-12 gap-y-10 sm:grid-cols-3 sm:gap-x-16 lg:ml-auto lg:shrink-0 lg:gap-x-20">
          {/* Colors from official mark: magenta · blue · green */}
          <FooterColumn
            title="Product"
            items={MARKETING_FOOTER_PRODUCT}
            titleClassName="text-accent-hover"
          />
          <FooterColumn
            title="Company"
            items={MARKETING_FOOTER_COMPANY}
            titleClassName="text-depth"
          />
          <FooterColumn
            title="Legal"
            items={MARKETING_FOOTER_LEGAL}
            titleClassName="text-proof"
          />
        </div>
      </div>

      <div className="mx-auto flex max-w-6xl flex-col gap-2 px-5 pb-8 pt-4 text-xs text-muted-foreground sm:flex-row sm:items-center sm:justify-between lg:px-8">
        <p>© {new Date().getFullYear()} krypco. All rights reserved.</p>
        <p className="tabular-nums">hybrid network · skeleton preview</p>
      </div>
    </footer>
  );
}
