import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:gap/gap.dart';
import 'package:tanami_app/core/styles/app_color.dart';
import 'package:tanami_app/core/utils/date_time_formatter/date_time_formatter.dart';
import 'package:tanami_app/features/MainScreens/Invest/domain/model/detail_io_model.dart';

import '../../../../../core/styles/app_text.dart';
import '../../../../../core/utils/language/localizations_delegate.dart';
import '../../../../../shared/components/text_widget.dart';

class InvestDetailDetailsSection extends StatelessWidget {
  final String type;
  final DetailIOModel detailIOModel;
  const InvestDetailDetailsSection(
      {super.key, required this.type, required this.detailIOModel});

  @override
  Widget build(BuildContext context) {
    var localizations = AppLocalizations.of(context);
    return Column(
      children: [
        Container(
          color: AppColor.plainWhite,
          child: Padding(
            padding: const EdgeInsets.all(20.0),
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                TextWidget().text17W700(
                  detailIOModel.data!.investmentNameEnglish!,
                  clr: AppColor.plainBlack,
                ),
                Gap(
                  10.h,
                ),
                type == "closed"
                    ? const SizedBox()
                    : TextWidget().text22W900(
                        "USD ${detailIOModel.data!.goalAmount!}",
                        clr: AppColor.investTextColor),
                type == "closed" ? const SizedBox() : const Gap(8.0),
                type == "closed"
                    ? const SizedBox()
                    : LinearProgressIndicator(
                        value: type == "closed"
                            ? 1
                            : (double.parse(
                                    detailIOModel.data!.amountInvested!) /
                                double.parse(detailIOModel.data!.goalAmount!)),
                        borderRadius: BorderRadius.circular(2),
                        minHeight: 8.0,
                        backgroundColor: AppColor.txtBorderColor,
                        valueColor: const AlwaysStoppedAnimation<Color>(
                            AppColor.investTextColor),
                      ),
                type == "closed" ? const SizedBox() : const Gap(8.0),
                type == "closed"
                    ? const SizedBox()
                    : TextWidget().text11W700(
                        type == "closed"
                            ? "100% ${localizations.translate(AppText.fundedText)}"
                            : "${(double.parse(detailIOModel.data!.amountInvested!) / double.parse(detailIOModel.data!.goalAmount!)) * 100}% ${localizations.translate(AppText.fundedText)}",
                        clr: AppColor.portoflioCardTextColor),
                type == "closed" ? const SizedBox() : const Gap(8.0),
                TextWidget().text14W400(
                  detailIOModel.data!.descriptionEnglish!,
                  clr: Colors.grey,
                  txtAlign: TextAlign.start,
                )
              ],
            ),
          ),
        ),
        Container(
          decoration: const BoxDecoration(
            color: AppColor.portfolioCardBgColor,
            borderRadius: BorderRadius.only(
              bottomLeft: Radius.circular(20.0),
              bottomRight: Radius.circular(20.0),
            ),
          ),
          child: Padding(
            padding:
                const EdgeInsets.symmetric(horizontal: 20.0, vertical: 16.0),
            child: Column(
              children: [
                Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    SizedBox(
                      width: 150.w,
                      child: TextWidget().text14W500(
                        "${localizations.translate(AppText.sponsorNameText)}:",
                        clr: AppColor.portoflioCardTextColor,
                        txtAlign: TextAlign.start,
                      ),
                    ),
                    TextWidget().text14W700(
                      detailIOModel.data!.sponsor!.sponsorName!,
                      clr: AppColor.plainBlack,
                      txtAlign: TextAlign.end,
                    )
                  ],
                ),
                type == "closed" ? const SizedBox() : SizedBox(height: 8.h),
                type == "closed"
                    ? const SizedBox()
                    : Row(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        crossAxisAlignment: CrossAxisAlignment.start,
                        children: [
                          SizedBox(
                            width: 150.w,
                            child: TextWidget().text14W500(
                              "${localizations.translate(AppText.estimatedReturnText)}:",
                              clr: AppColor.portoflioCardTextColor,
                              txtAlign: TextAlign.start,
                            ),
                          ),
                          TextWidget().text14W700(
                            detailIOModel.data!.expectedReturn!,
                            clr: AppColor.plainBlack,
                            txtAlign: TextAlign.end,
                          ),
                        ],
                      ),
                type == "closed"
                    ? Column(
                        children: [
                          SizedBox(
                            height: 8.h,
                          ),
                          Row(
                            mainAxisAlignment: MainAxisAlignment.spaceBetween,
                            crossAxisAlignment: CrossAxisAlignment.start,
                            children: [
                              SizedBox(
                                width: 150.w,
                                child: TextWidget().text14W500(
                                  type == "closed"
                                      ? "${localizations.translate(AppText.actualReturnToDate)}:"
                                      : "${localizations.translate(AppText.actualEstimatedReturnText)}:",
                                  clr: AppColor.portoflioCardTextColor,
                                  txtAlign: TextAlign.start,
                                ),
                              ),
                              TextWidget().text14W700(
                                '22.5%',
                                clr: AppColor.plainBlack,
                                txtAlign: TextAlign.end,
                              ),
                            ],
                          ),
                          SizedBox(
                            height: 8.h,
                          ),
                        ],
                      )
                    : const SizedBox(),
                SizedBox(
                  height: type == "closed" ? 0 : 8.h,
                ),
                Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    SizedBox(
                      width: 150.w,
                      child: TextWidget().text14W500(
                        "${localizations.translate(AppText.holdingPeriodText)}:",
                        clr: AppColor.portoflioCardTextColor,
                        txtAlign: TextAlign.start,
                      ),
                    ),
                    TextWidget().text14W700(
                      detailIOModel.data!.holdingPeriod!,
                      clr: AppColor.plainBlack,
                      txtAlign: TextAlign.end,
                    ),
                  ],
                ),
                SizedBox(
                  height: 8.h,
                ),
                type == "closed"
                    ? Row(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        crossAxisAlignment: CrossAxisAlignment.start,
                        children: [
                          TextWidget().text14W500(
                            type == "closed"
                                ? "${localizations.translate(AppText.expectedExitDate)}:"
                                : "${localizations.translate(AppText.payoutDateText)}:",
                            clr: AppColor.portoflioCardTextColor,
                            txtAlign: TextAlign.start,
                          ),
                          TextWidget().text14W700(
                            DateTimeFormatter()
                                .formatDate(detailIOModel.data!.closingDate!),
                            clr: AppColor.plainBlack,
                            txtAlign: TextAlign.end,
                          ),
                        ],
                      )
                    : Row(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        crossAxisAlignment: CrossAxisAlignment.start,
                        children: [
                          TextWidget().text14W500(
                            "${localizations.translate(AppText.minimumInvestmentText)}:",
                            clr: AppColor.portoflioCardTextColor,
                            txtAlign: TextAlign.start,
                          ),
                          TextWidget().text14W700(
                            'BHR ${detailIOModel.data!.minInvestmentAmt![0].minInvestmentAmt}',
                            clr: AppColor.plainBlack,
                            txtAlign: TextAlign.end,
                          ),
                        ],
                      )
              ],
            ),
          ),
        )
      ],
    );
  }
}
