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/invoice/data/models/invoice_model.dart';
import 'package:krow/features/invoice/domain/blocs/invoice_details_bloc/invoice_details_bloc.dart';
import 'package:krow/features/invoice/domain/invoice_entity.dart';

class InvoiceTotalWidget extends StatelessWidget {

  const InvoiceTotalWidget({super.key});

  @override
  Widget build(BuildContext context) {
    return BlocBuilder<InvoiceDetailsBloc, InvoiceDetailsState>(
      builder: (context, state) {
        return Container(
          decoration: KwBoxDecorations.white12,
          padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 24),
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Text('Total', style: AppTextStyles.headingH3),
              Gap(24),
              Container(
                decoration: KwBoxDecorations.primaryLight8,
                padding: const EdgeInsets.symmetric(
                    horizontal: 12, vertical: 8),
                child: Column(
                  children: [
                    totalInfoRow('Sub Total', '\$${state.invoiceModel?.workAmount?.toStringAsFixed(2)??'0'}'),
                    Gap(8),
                    totalInfoRow('Other Charges', '\$${state.invoiceModel?.addonsAmount?.toStringAsFixed(2)??'0'}'),
                    Gap(8),
                    totalInfoRow('Grand Total', '\$${state.invoiceModel?.total?.toStringAsFixed(2)??'0'}'),
                  ],
                ),
              )
            ],
          ),
        );
      },
    );
  }

  Widget totalInfoRow(String title, String value) {
    return Row(
      mainAxisAlignment: MainAxisAlignment.spaceBetween,
      children: [
        Text(title,
            style: AppTextStyles.bodyMediumReg
                .copyWith(color: AppColors.blackGray)),
        Gap(20),
        Text(value, style: AppTextStyles.bodyMediumMed)
      ],
    );
  }
}
