import { formatNaira } from "@/lib/format";
import { usePrivacyStore } from "@/stores/privacy";
import { cn } from "@/lib/utils";

/**
 * Renders a monetary value that respects the global privacy switch.
 * Use this instead of formatNaira() anywhere an amount is shown on screen.
 */
export function Money({
  value,
  className,
  mask = "₦ ••••",
  prefix,
}: {
  value: number | string | null | undefined;
  className?: string;
  mask?: string;
  prefix?: string;
}) {
  const visible = usePrivacyStore((s) => s.visible);
  return (
    <span className={cn("tabular-nums transition-all duration-200", className)}>
      {visible ? `${prefix ?? ""}${formatNaira(value)}` : mask}
    </span>
  );
}

/** Imperative variant for places that need a plain string. */
export function useMoney() {
  const visible = usePrivacyStore((s) => s.visible);
  return (value: number | string | null | undefined, mask = "₦ ••••") =>
    visible ? formatNaira(value) : mask;
}
