import 'package:flutter/widgets.dart';

import 'package:money2/money2.dart';

import 'package:pshared/utils/currency.dart';

import 'package:pweb/generated/i18n/app_localizations.dart';


String formatMoneyUi(BuildContext context, Money? money) {
  final l10n = AppLocalizations.of(context)!;
  if (money == null) return l10n.valueUnavailable;
  return money.toString();
}

String formatAmountUi(
  BuildContext context, {
  required double amount,
  required String currency,
}) {
  final l10n = AppLocalizations.of(context)!;
  final moneyCurrency = money2CurrencyFromCode(currency);
  if (moneyCurrency == null) return l10n.valueUnavailable;

  final money = Money.fromNumWithCurrency(amount, moneyCurrency);
  return money.toString();
}
