import 'package:flutter/material.dart';

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

import 'package:pweb/models/dashboard/balance_item.dart';
import 'package:pweb/pages/dashboard/buttons/balance/add/card.dart';
import 'package:pweb/pages/dashboard/buttons/balance/config.dart';
import 'package:pweb/pages/dashboard/buttons/balance/source/card.dart';
import 'package:pweb/pages/dashboard/buttons/balance/source/cards/ledger.dart';


class BalanceCarouselCardItem extends StatelessWidget {
  final BalanceItem item;
  final ValueChanged<Wallet> onTopUp;
  final ValueChanged<LedgerAccount> onLedgerAddFunds;
  final ValueChanged<Wallet> onWalletTap;
  final ValueChanged<LedgerAccount> onLedgerTap;

  const BalanceCarouselCardItem({
    super.key,
    required this.item,
    required this.onTopUp,
    required this.onLedgerAddFunds,
    required this.onWalletTap,
    required this.onLedgerTap,
  });

  @override
  Widget build(BuildContext context) {
    final card = switch (item) {
      WalletBalanceItem(:final wallet) => BalanceSourceCard.wallet(
        wallet: wallet,
        onAddFunds: () => onTopUp(wallet),
        onTap: () => onWalletTap(wallet),
      ),
      LedgerBalanceItem(:final account) => LedgerAccountCard(
        account: account,
        onTap: () => onLedgerTap(account),
        onAddFunds: () => onLedgerAddFunds(account),
      ),
      AddBalanceActionItem() => const AddBalanceCard(),
    };

    return Padding(padding: WalletCardConfig.cardPadding, child: card);
  }
}
