import 'package:flutter/material.dart';

import 'package:pshared/models/ledger/account.dart';
import 'package:pshared/models/payment/wallet.dart';

import 'package:pweb/widgets/payment/source_wallet_selector/balance_formatter.dart';
import 'package:pweb/widgets/payment/source_wallet_selector/display_name.dart';
import 'package:pweb/widgets/payment/source_wallet_selector/options.dart';

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


List<DropdownMenuItem<SourceOptionKey>> buildSourceSelectorItems({
  required BuildContext context,
  required List<Wallet> wallets,
  required List<LedgerAccount> ledgerAccounts,
  required AppLocalizations l10n,
}) {
  return <DropdownMenuItem<SourceOptionKey>>[
    ...wallets.map((wallet) {
      return DropdownMenuItem<SourceOptionKey>(
        value: walletOptionKey(wallet.id),
        child: Text(
          '${walletDisplayName(wallet, l10n)} - ${walletBalance(context, wallet)}',
          overflow: TextOverflow.ellipsis,
        ),
      );
    }),
    ...ledgerAccounts.map((ledger) {
      return DropdownMenuItem<SourceOptionKey>(
        value: ledgerOptionKey(ledger.ledgerAccountRef),
        child: Text(
          '${ledgerDisplayName(ledger, l10n)} - ${ledgerBalance(context, ledger)}',
          overflow: TextOverflow.ellipsis,
        ),
      );
    }),
  ];
}
