import { cn } from "@/lib/utils";
import { fmtMoney } from "@/lib/format";

export function Money({ value, currency = "MAD", className, compact, signed, tone }: { value: number | null | undefined; currency?: string; className?: string; compact?: boolean; signed?: boolean; tone?: "auto" | "positive" | "negative" | "muted" }) {
  const v = value ?? 0;
  const t = tone === "auto" ? (v > 0 ? "positive" : v < 0 ? "negative" : "muted") : tone;
  return (
    <span className={cn("tabular whitespace-nowrap", t === "positive" && "text-positive-600", t === "negative" && "text-negative-600", t === "muted" && "text-fg-muted", className)}>
      {fmtMoney(v, currency, { compact, signed })}
    </span>
  );
}
