import { getLocale, getTranslations } from "next-intl/server";
import { Link } from "@/i18n/navigation";
import { getOffers } from "@/lib/offersStore";
import { localize } from "@/lib/localize";

export async function OfferBanner() {
  const t = await getTranslations("offerBanner");
  const locale = await getLocale();
  const offers = await getOffers();
  const featured = offers.find((o) => o.status === "live");
  if (!featured) return null;

  const spotsLeft = featured.maxVouchers - featured.vouchersSold;

  return (
    <div className="border-b border-brass/20 bg-espresso-light">
      <Link
        href="/offers"
        className="group mx-auto flex max-w-6xl flex-wrap items-center justify-between gap-3 px-6 py-3.5 text-sm text-ivory"
      >
        <span className="flex items-center gap-3">
          <span className="eyebrow rounded-full bg-tomato/20 px-2.5 py-1 text-tomato">{t("label")}</span>
          <span className="text-ivory-dim">
            {localize(featured.title, locale)} <span className="text-brass">·</span> {spotsLeft}/{featured.maxVouchers}
          </span>
        </span>
        <span className="eyebrow text-ivory underline decoration-brass/50 underline-offset-4 transition group-hover:decoration-ivory">
          {t("cta")} →
        </span>
      </Link>
    </div>
  );
}
