import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:krezus/domains/transaction/transaction_bloc.dart';
import 'package:krezus/pages/transactions/widgets/transaction_line.dart';

class TransactionsList extends StatelessWidget {
  const TransactionsList({super.key});

  @override
  Widget build(BuildContext context) {
    return BlocBuilder<TransactionBloc, TransactionState>(
      buildWhen: (previous, current) => previous.transactionsLinesFiltered != current.transactionsLinesFiltered,
      builder: (context, state) => Expanded(
        child: ListView.builder(
          itemCount: state.transactionsLinesFiltered.length,
          itemBuilder: (context, index) => TransactionLine(
            transaction: state.transactionsLinesFiltered[index].transaction,
            subTotal: state.transactionsLinesFiltered[index].subTotal
          )
        )
      )
    );
  }
}