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_box_decorations.dart';
import 'package:krow/core/presentation/styles/kw_text_styles.dart';
import 'package:krow/core/presentation/styles/theme.dart';
import 'package:krow/features/earning/domain/bloc/earnings_bloc.dart';
import 'package:krow/features/earning/presentation/widget/animated_slider.dart';

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

  @override
  Widget build(BuildContext context) {
    return Row(
      children: [
        Expanded(
          child: Container(
            padding: const EdgeInsets.all(12),
            margin: const EdgeInsets.only(
              bottom: 24,
              left: 12,
              right: 12,
            ),
            decoration: KwBoxDecorations.primaryDark,
            child: BlocBuilder<EarningsBloc, EarningsState>(
              builder: (context, state) {
                return Column(
                  crossAxisAlignment: CrossAxisAlignment.center,
                  children: [
                    Text(
                      'your_earnings'.tr(),
                      textAlign: TextAlign.center,
                      style: AppTextStyles.bodyMediumMed
                          .copyWith(color: AppColors.grayWhite),
                    ),
                    const Gap(12),
                    const AnimatedSlider(),
                    const Gap(24),
                    Text(
                      '\$${state.totalEarnings.toStringAsFixed(2)}',
                      style: AppTextStyles.headingH0
                          .copyWith(color: AppColors.grayWhite),
                    ),
                    const Gap(24),
                    Container(
                      padding: const EdgeInsets.all(12),
                      decoration: KwBoxDecorations.primaryDark.copyWith(
                        color: AppColors.darkBgStroke,
                      ),
                      child: Column(
                        children: [
                          _buildInfoRow(
                            'total_worked_hours'.tr(),
                            '${state.totalHours.toInt()}',
                          ),
                          // const Gap(12),
                          // _buildInfoRow(
                          //   'Payout:',
                          //   '\$${state.totalPayout.toStringAsFixed(2)}',
                          // ),
                        ],
                      ),
                    ),
                    // const Gap(24),
                    // KwButton.accent(
                    //   label: 'Earnings History',
                    //   onPressed: () {
                    //     context.router.push(const EarningsHistoryRoute());
                    //   },
                    // )
                  ],
                );
              },
            ),
          ),
        ),
      ],
    );
  }

  Row _buildInfoRow(String title, String? value) {
    return Row(
      mainAxisAlignment: MainAxisAlignment.spaceBetween,
      children: [
        Text(
          title,
          style:
              AppTextStyles.bodyMediumMed.copyWith(color: AppColors.grayWhite),
        ),
        Text(
          value ?? '',
          style:
              AppTextStyles.bodyMediumMed.copyWith(color: AppColors.grayWhite),
        ),
      ],
    );
  }
}
