import 'package:auto_route/annotations.dart';
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/presentation/styles/kw_text_styles.dart';
import 'package:krow/features/earning/domain/bloc/earnings_bloc.dart';
import 'package:krow/features/earning/domain/entities/earning_shift_entity.dart';
import 'package:krow/features/earning/presentation/widget/earnings_appbar.dart';
import 'package:krow/features/earning/presentation/widget/list_item/earning_card_compact_widget.dart';

import '../widget/earnings_history_header.dart';

@RoutePage()
class EarningsHistoryScreen extends StatelessWidget {
  const EarningsHistoryScreen({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: SingleChildScrollView(
        physics: const ClampingScrollPhysics(),
        child: SafeArea(
          top: false,
          child: BlocBuilder<EarningsBloc, EarningsState>(
            builder: (context, state) {
              List<EarningShiftEntity> items = state.currentTab.items;

              return Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  const EarningsAppBar(
                    leading: true,
                    child: EarningsHistoryHeader(),
                  ),
                  const Gap(24),
                  Padding(
                    padding: const EdgeInsets.only(left: 16.0),
                    child: Text(
                      'your_shifts'.tr(),
                      style: AppTextStyles.bodySmallMed,
                    ),
                  ),
                  _buildListView(items),
                ],
              );
            },
          ),
        ),
      ),
    );
  }

  ListView _buildListView(List<EarningShiftEntity> items) {
    return ListView.builder(
      padding: const EdgeInsets.only(top: 24),
      shrinkWrap: true,
      physics: const NeverScrollableScrollPhysics(),
      itemCount: items.length,
      itemBuilder: (context, index) {
        return EarningCardCompactWidget(
          earningEntity: items[index],
        );
      },
    );
  }
}
