import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:gap/gap.dart';
import 'package:krow/core/data/enums/pagination_status.dart';
import 'package:krow/core/presentation/styles/kw_text_styles.dart';
import 'package:krow/features/earning/domain/bloc/earnings_bloc.dart';

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

  @override
  Widget build(BuildContext context) {
    return SliverSafeArea(
      top: false,
      sliver: BlocBuilder<EarningsBloc, EarningsState>(
        buildWhen: (previous, current) =>
        previous.currentTab != current.currentTab ||
            current.currentTab.status != previous.currentTab.status,
        builder: (context, state) {
          return SliverToBoxAdapter(
            child: Column(
              children: [
                SizedBox(
                  height: 60,
                  child: Center(
                    child: switch (state.currentTab.status) {
                      PaginationStatus.initial ||
                      PaginationStatus.loading =>
                      const CircularProgressIndicator(),
                      PaginationStatus.empty =>  Text(
                        'no_history_section'.tr(),
                        style: AppTextStyles.bodyMediumReg,
                      ),
                      PaginationStatus.end =>  Text(
                        'end_of_payments_history'.tr(),
                        style: AppTextStyles.bodyMediumReg,
                      ),
                      _ => null,
                    },
                  ),
                ),
                const Gap(20),
              ],
            ),
          );
        },
      ),
    );
  }
}
