const VND_FORMATTER = new Intl.NumberFormat('vi-VN', {
  style: 'currency',
  currency: 'VND',
  maximumFractionDigits: 0,
});

const VND_COMPACT_FORMATTER = new Intl.NumberFormat('vi-VN', {
  style: 'currency',
  currency: 'VND',
  notation: 'compact',
  maximumFractionDigits: 1,
});

export function formatVND(amount: number): string {
  return VND_FORMATTER.format(amount);
}

export function formatVNDCompact(amount: number): string {
  return VND_COMPACT_FORMATTER.format(amount);
}

export function parseVND(formatted: string): number | null {
  const cleaned = formatted.replace(/[^\d]/g, '');
  if (cleaned === '') return null;
  return Number(cleaned);
}
