import { listPublicNavigation } from "@cms/db"

import { Link } from "@/i18n/navigation"

import { LanguageSwitcher } from "./language-switcher"

export async function PublicSiteHeader() {
  const navItems = await listPublicNavigation("header")

  return (
    <header className="border-b border-neutral-200 bg-white/80 backdrop-blur">
      <div className="mx-auto flex w-full max-w-6xl flex-wrap items-center justify-between gap-4 px-6 py-4">
        <Link
          href="/"
          className="text-sm font-semibold uppercase tracking-[0.2em] text-neutral-700"
        >
          CMS Web
        </Link>

        <nav className="flex flex-wrap items-center gap-2">
          {navItems.length === 0 ? (
            <Link
              href="/"
              className="rounded-md border border-neutral-300 px-3 py-1.5 text-sm font-medium text-neutral-700 hover:bg-neutral-100"
            >
              Home
            </Link>
          ) : (
            navItems.map((item) => (
              <Link
                key={item.id}
                href={item.href}
                className="rounded-md border border-neutral-300 px-3 py-1.5 text-sm font-medium text-neutral-700 hover:bg-neutral-100"
              >
                {item.label}
              </Link>
            ))
          )}
        </nav>

        <LanguageSwitcher />
      </div>
    </header>
  )
}
