import 'package:cargocalculaterapp/core/extension/build_context_extension.dart';
import 'package:cargocalculaterapp/core/functions/base_finctions.dart';
import 'package:cargocalculaterapp/core/utils/app_utils.dart';
import 'package:cargocalculaterapp/core/widgets/loading/progress_hud.dart';
import 'package:cargocalculaterapp/features/calculator/presentation/pages/calculator_info/widget/calculator_info_widget.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_svg/flutter_svg.dart';

import '../../../../../constants/constants.dart';
import '../../../../../generated/l10n.dart';
import '../../arguments/calculator_info_argument.dart';
import '../../bloc/calculator_info/calculator_info_bloc.dart';

class CalculatorInfoPage extends StatelessWidget {
  const CalculatorInfoPage({super.key, required this.argument});

  final CalculatorInfoArgument? argument;

  @override
  Widget build(BuildContext context) {
    return BlocBuilder<CalculatorInfoBloc, CalculatorInfoState>(
      builder: (context, state) {
        return Scaffold(
          backgroundColor: context.color.grayBackground,
          appBar: AppBar(title: Text(AppLocalization.current.calculator)),
          body: ModalProgressHUD(
            inAsyncCall: state.isLoading,
            child: ListView(
              padding: AppUtils.kPaddingAll16,
              children: [
                Container(
                  margin: const EdgeInsets.only(bottom: 32),
                  padding: AppUtils.kPaddingAll16,
                  width: double.infinity,
                  decoration: BoxDecoration(
                    borderRadius: AppUtils.kBorderRadius16,
                    color: context.color.statusBackground,
                    border: Border.all(color: context.color.lightBorder),
                  ),
                  child: Column(
                    mainAxisSize: MainAxisSize.min,
                    children: [
                      CalculatorInfoWidget(
                        title: AppLocalization.current.product_name,
                        name: argument?.productName ?? "-",
                      ),
                      CalculatorInfoWidget(
                        title: AppLocalization.current.warehouse,
                        name: Functions.getTranslatedItem(
                          AppConst.warehouseOptions[argument?.weraHouse],
                          context,
                        ),
                      ),
                      CalculatorInfoWidget(
                        title: AppLocalization.current.weight,
                        name: "${argument?.weight} kg",
                      ),
                      CalculatorInfoWidget(
                        title: AppLocalization.current.size,
                        name: "${argument?.size} m³",
                      ),
                      CalculatorInfoWidget(
                        title: AppLocalization.current.average_weight,
                        name: "${argument?.averageWeight}",
                      ),
                      CalculatorInfoWidget(
                        title: AppLocalization.current.delivery_price,
                        name: "${argument?.deliveryPrice}",
                      ),
                    ],
                  ),
                ),
                Row(
                  children: [
                    Expanded(
                      child: InkWell(
                        onTap: () {
                          if (argument != null) {
                            context.read<CalculatorInfoBloc>().add(
                              CreateLeadEvent(
                                isCall: true,
                                argument: argument!,
                              ),
                            );
                          }
                        },
                        borderRadius: AppUtils.kBorderRadius24,
                        child: Ink(
                          decoration: BoxDecoration(
                            color: context.color.scaffoldBackgroundColor,
                            borderRadius: AppUtils.kBorderRadius24,
                            border: Border.all(
                              color: context.color.primaryColor,
                            ),
                          ),
                          height: 56,
                          padding: AppUtils.kPaddingHor16,
                          child: Row(
                            mainAxisAlignment: MainAxisAlignment.center,
                            children: [
                              SvgPicture.asset(
                                "assets/svg/ic_phone.svg",
                                colorFilter: ColorFilter.mode(
                                  context.color.textColor,
                                  BlendMode.srcIn,
                                ),
                              ),
                              AppUtils.kBoxWidth4,
                              Text(
                                AppLocalization.current.phone_call,
                                style: TextStyle(
                                  fontSize: 16,
                                  fontWeight: FontWeight.w700,
                                  color: context.color.textColor,
                                ),
                              ),
                            ],
                          ),
                        ),
                      ),
                    ),
                    AppUtils.kBoxWidth16,
                    Expanded(
                      child: ElevatedButton(
                        onPressed: () {
                          if (argument != null) {
                            context.read<CalculatorInfoBloc>().add(
                              CreateLeadEvent(
                                isCall: false,
                                argument: argument!,
                              ),
                            );
                          }
                        },
                        child: Row(
                          mainAxisAlignment: MainAxisAlignment.center,
                          children: [
                            SvgPicture.asset("assets/svg/ic_list_1.svg"),
                            AppUtils.kBoxWidth4,
                            Text(AppLocalization.current.send),
                          ],
                        ),
                      ),
                    ),
                  ],
                ),
              ],
            ),
          ),
        );
      },
    );
  }
}
