/** نمایش قیمت به تومان همراه با قیمت قبلی و درصد تخفیف */
import { discountPercent, faNumber } from "@/lib/format";

export function Price({ price, compareAt, size = "md" }: { price: number; compareAt?: number; size?: "sm" | "md" | "lg" }) {
  const off = discountPercent(price, compareAt);
  const main = { sm: "text-sm", md: "text-base", lg: "text-2xl" }[size];
  return (
    <div className="flex flex-wrap items-baseline gap-x-2 gap-y-0.5">
      <span className={`${main} font-bold`}>
        {faNumber(price)} <span className="text-[0.7em] font-normal text-muted">تومان</span>
      </span>
      {off > 0 && (
        <>
          <span className="text-xs text-subtle line-through">{faNumber(compareAt!)}</span>
          <span className="rounded-full bg-ink px-1.5 py-0.5 text-[10px] font-bold text-paper">٪{faNumber(off)}</span>
        </>
      )}
    </div>
  );
}
