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/core/presentation/widgets/ui_kit/kw_tabs.dart';
import 'package:krow/features/earning/domain/bloc/earnings_bloc.dart';
import 'package:krow/features/earning/presentation/widget/earnings_appbar.dart';
import 'package:krow/features/earning/presentation/widget/earnings_header.dart';

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

  @override
  Widget build(BuildContext context) {
    return SliverList.list(
      children: [
        const EarningsAppBar(child: EarningsHeader()),
        const Gap(24),
        Padding(
          padding: const EdgeInsets.only(left: 16.0),
          child: Text(
            'your_shifts'.tr(),
            style: AppTextStyles.bodySmallMed,
          ),
        ),
        const Gap(24),
        BlocBuilder<EarningsBloc, EarningsState>(
          buildWhen: (previous, current) =>
          previous.tabs != current.tabs,
          builder: (context, state) {
            return KwTabBar(
              key: const Key('earnings_tab_bar'),
              forceScroll: true,
              tabs: [for (final tab in state.tabs) tab.label.tr()],
              onTap: (int index) {
                context
                    .read<EarningsBloc>()
                    .add(EarningsTabChangedEvent(tabIndex: index));
              },
            );
          },
        ),
      ],
    );
  }
}
