export function toIntlLocale(locale: string) {
  return locale === "id" ? "id-ID" : "en-US";
}

export function formatDecimal(value: number, locale: string, maximumFractionDigits = 3) {
  return new Intl.NumberFormat(toIntlLocale(locale), {
    minimumFractionDigits: 0,
    maximumFractionDigits
  }).format(value);
}

export function formatQuantity(
  value: number,
  locale: string,
  unitCode?: string | null,
  maximumFractionDigits = 3
) {
  const formatted = formatDecimal(value, locale, maximumFractionDigits);
  return unitCode ? `${formatted} ${unitCode}` : formatted;
}

export function formatKilogram(value: number, locale: string, maximumFractionDigits = 3) {
  return formatQuantity(value, locale, "kg", maximumFractionDigits);
}

export function formatCurrencyAmount(
  value: number,
  locale: string,
  currencyCode: string,
  maximumFractionDigits = 0
) {
  return new Intl.NumberFormat(toIntlLocale(locale), {
    style: "currency",
    currency: currencyCode,
    maximumFractionDigits
  }).format(value);
}
