"use client";

import { formatPrice, type Locale, type Price } from "@alterra/shared";
import { useCurrency } from "../Currency";

/** Price in the visitor's currency, with the other currency underneath. USD is labeled as reference. */
export default function PriceTag({
  price,
  lang,
  priceOnRequest,
  perMonth,
  usdNote,
  rent = false,
  size = "md",
}: {
  price: Price | null;
  lang: Locale;
  priceOnRequest: string;
  perMonth: string;
  usdNote: string;
  rent?: boolean;
  size?: "md" | "lg";
}) {
  const { currency } = useCurrency();
  if (!price) return <p className={`uppercase tracking-[0.14em] text-gold-ink ${size === "lg" ? "text-sm" : "text-xs"}`}>{priceOnRequest}</p>;

  const numberLocale = lang === "es" ? "es-CO" : "en-US";
  const main = currency === "USD" ? formatPrice(price.usd, "USD", numberLocale) : formatPrice(price.cop, "COP", numberLocale);
  const secondary = currency === "USD" ? formatPrice(price.cop, "COP", numberLocale) : formatPrice(price.usd, "USD", numberLocale);
  const suffix = rent ? ` ${perMonth}` : "";

  return (
    <div>
      <p className={`font-serif text-forest ${size === "lg" ? "text-4xl md:text-5xl" : "text-2xl"}`}>
        {main}
        <span className="text-[0.55em] text-stone">
          {" "}
          {currency}
          {suffix}
        </span>
      </p>
      <p className={`mt-1 text-stone ${size === "lg" ? "text-sm" : "text-xs"}`}>
        ≈ {secondary} {currency === "USD" ? "COP" : `USD · ${usdNote}`}
      </p>
    </div>
  );
}
