import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:gap/gap.dart';
import 'package:krow/features/earning/domain/bloc/earnings_bloc.dart';
import 'package:krow/features/earning/presentation/widget/list_item/earning_card_widget.dart';

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

  @override
  Widget build(BuildContext context) {
    return SliverPadding(
      padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 24),
      sliver: BlocBuilder<EarningsBloc, EarningsState>(
        buildWhen: (previous, current) =>
            previous.tabIndex != current.tabIndex ||
            previous.currentTab.items != current.currentTab.items,
        builder: (context, state) {
          return SliverList.separated(
            itemCount: state.currentTab.items.length,
            separatorBuilder: (context, index) => const Gap(12),
            itemBuilder: (context, index) {
              return EarningCardWidget(
                earningEntity: state.currentTab.items[index],
              );
            },
          );
        },
      ),
    );
  }
}
