import 'package:flutter/material.dart';

import 'package:intl/intl.dart';

import 'package:money2/money2.dart';

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

import 'package:pweb/utils/money_display.dart';


String formatMoney(BuildContext context, Money? money) {
  return formatMoneyUi(context, money);
}

String formatAmount(BuildContext context, double amount, String currency) {
  return formatAmountUi(context, amount: amount, currency: currency);
}

String formatDateLabel(
  BuildContext context,
  DateTime? date, {
  String fallback = '-',
}) {
  if (date == null || date.millisecondsSinceEpoch == 0) return fallback;
  return dateTimeToLocalFormat(context, date.toLocal());
}

String formatLongDate(
  BuildContext context,
  DateTime? date, {
  String fallback = '-',
}) {
  if (date == null || date.millisecondsSinceEpoch == 0) return fallback;
  final locale = Localizations.localeOf(context).toString();
  final formatter = DateFormat('d MMMM y', locale);
  return formatter.format(date.toLocal());
}

String collapseWhitespace(String value) {
  return value.replaceAll(RegExp(r'\s+'), ' ').trim();
}
