import 'package:hmg_patient_app/core/model/ImagesInfo.dart';
import 'package:hmg_patient_app/core/model/my_balance/patient_advance_balance_amount.dart';
import 'package:hmg_patient_app/core/viewModels/medical/my_balance_view_model.dart';
import 'package:hmg_patient_app/core/viewModels/project_view_model.dart';
import 'package:hmg_patient_app/pages/base/base_view.dart';
import 'package:hmg_patient_app/theme/colors.dart';
import 'package:hmg_patient_app/uitl/translations_delegate_base.dart';
import 'package:hmg_patient_app/uitl/utils_new.dart';
import 'package:hmg_patient_app/widgets/buttons/defaultButton.dart';
import 'package:hmg_patient_app/widgets/others/app_scaffold_widget.dart';
import 'package:hmg_patient_app/widgets/transitions/fade_page.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_svg/svg.dart';
import 'package:provider/provider.dart';

import 'advance_payment_page.dart';

class MyBalancePage extends StatelessWidget {
  List<ImagesInfo> imagesInfo = [];

  late ProjectViewModel projectViewModel;

  @override
  Widget build(BuildContext context) {
    projectViewModel = Provider.of(context);

    imagesInfo.add(ImagesInfo(
        imageEn: 'https://hmgwebservices.com/Images/MobileApp/images-info-home/my-balance/en/0.png', imageAr: 'https://hmgwebservices.com/Images/MobileApp/images-info-home/my-balance/ar/0.png'));
    return BaseView<MyBalanceViewModel>(
      onModelReady: (model) => model.getPatientAdvanceBalanceAmount(),
      builder: (_, model, w) => AppScaffold(
        baseViewModel: model,
        isShowAppBar: true,
        appBarTitle: TranslationBase.of(context).myWallet,
        imagesInfo: imagesInfo,
        description: TranslationBase.of(context).infoMyBalance,
        showNewAppBar: true,
        showNewAppBarTitle: true,
        backgroundColor: CustomColors.appBackgroudGreyColor,
        body: Column(
          children: [
            Expanded(
              child: SingleChildScrollView(
                physics: BouncingScrollPhysics(),
                padding: EdgeInsets.all(21),
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    Container(
                      padding: EdgeInsets.fromLTRB(14, 12, 10, 12),
                      decoration: BoxDecoration(
                        color: Color(0xff2B353E),
                        borderRadius: BorderRadius.all(
                          Radius.circular(10.0),
                        ),
                      ),
                      child: Row(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        children: [
                          Expanded(
                            child: Column(
                              crossAxisAlignment: CrossAxisAlignment.start,
                              mainAxisAlignment: MainAxisAlignment.spaceBetween,
                              children: [
                                SvgPicture.asset(
                                  "assets/images/new/services/balance_credit.svg",
                                  height: 40,
                                  width: 40,
                                  color: Colors.white,
                                ),
                                SizedBox(height: 6),
                                Text(
                                  TranslationBase.of(context).totalBalance,
                                  style: TextStyle(
                                    fontSize: 16,
                                    letterSpacing: -0.96,
                                    fontWeight: FontWeight.bold,
                                    color: Colors.white,
                                    //height: 16/22
                                  ),
                                ),
                              ],
                            ),
                          ),
                          Container(
                            padding: EdgeInsets.fromLTRB(14, 10, 12, 10),
                            decoration: BoxDecoration(
                              color: Color(0xff3f4850),
                              borderRadius: BorderRadius.all(
                                Radius.circular(10.0),
                              ),
                            ),
                            child: Column(
                              crossAxisAlignment: CrossAxisAlignment.end,
                              mainAxisSize: MainAxisSize.min,
                              children: [
                                Row(
                                  children: [
                                    projectViewModel.user!.outSA == 1
                                        ? Container()
                                        : projectViewModel.isArabic
                                            ? Container()
                                            : SvgPicture.asset(
                                                "assets/images/new/Saudi_Riyal_Symbol.svg",
                                                width: 22,
                                                height: 22,
                                                color: Colors.white,
                                              ),
                                    mWidth(6),
                                    Text(
                                      double.parse(model.totalAdvanceBalanceAmount?.toString() ?? "0").toStringAsFixed(2),
                                      style: TextStyle(
                                        fontSize: 24,
                                        fontWeight: FontWeight.bold,
                                        letterSpacing: -1.44,
                                        height: 24 / 21,
                                        color: Colors.white,
                                      ),
                                    ),
                                    mWidth(6),
                                    projectViewModel.user!.outSA == 1
                                        ? Container()
                                        : projectViewModel.isArabic
                                            ? SvgPicture.asset(
                                                "assets/images/new/Saudi_Riyal_Symbol.svg",
                                                width: 22,
                                                height: 22,
                                                color: Colors.white,
                                              )
                                            : Container(),
                                  ],
                                ),
                                Text(
                                  projectViewModel.user!.outSA == 1 ? TranslationBase.of(context).aed : "",
                                  style: TextStyle(
                                    fontSize: 16,
                                    fontWeight: FontWeight.bold,
                                    letterSpacing: -0.96,
                                    color: Colors.white,
                                  ),
                                ),
                              ],
                            ),
                          ),
                        ],
                      ),
                    ),
                    SizedBox(height: 12),
                    ListView.separated(
                        physics: NeverScrollableScrollPhysics(),
                        shrinkWrap: true,
                        itemBuilder: (cxt, index) {
                          PatientAdvanceBalanceAmount balanceAmount = model.patientAdvanceBalanceAmountList[index];
                          double amount = double.parse(balanceAmount.patientAdvanceBalanceAmount?.toString() ?? "0");
                          return Container(
                            padding: EdgeInsets.fromLTRB(14, 18, 14, 18),
                            decoration: BoxDecoration(
                                borderRadius: BorderRadius.all(
                                  Radius.circular(10.0),
                                ),
                                boxShadow: [
                                  BoxShadow(
                                    color: Color(0xff000000).withOpacity(.05),
                                    //spreadRadius: 5,
                                    blurRadius: 27,
                                    offset: Offset(0, -3),
                                  ),
                                ],
                                color: Colors.white),
                            child: Row(
                              mainAxisAlignment: MainAxisAlignment.spaceBetween,
                              children: [
                                Expanded(
                                  child: Text(
                                    balanceAmount!.projectDescription!,
                                    style: TextStyle(
                                      fontSize: 16,
                                      letterSpacing: -0.64,
                                      fontWeight: amount > 0 ? FontWeight.bold : FontWeight.w500,
                                      color: Color(0xff2E303A),
                                    ),
                                  ),
                                ),
                                Row(
                                  children: [
                                    projectViewModel.user!.outSA == 1
                                        ? Container()
                                        : projectViewModel.isArabic
                                            ? Container()
                                            : SvgPicture.asset("assets/images/new/Saudi_Riyal_Symbol.svg", width: 16, height: 16),
                                    mWidth(6),
                                    Text(
                                      amount.toStringAsFixed(2) + " " + (projectViewModel.user!.outSA == 1 ? TranslationBase.of(context).aed : ""),
                                      style: TextStyle(
                                        fontSize: 16,
                                        letterSpacing: -0.64,
                                        fontWeight: amount > 0 ? FontWeight.bold : FontWeight.w500,
                                        color: Color(0xff2E303A),
                                      ),
                                    ),
                                    mWidth(6),
                                    projectViewModel.user!.outSA == 1
                                        ? Container()
                                        : projectViewModel.isArabic
                                            ? SvgPicture.asset("assets/images/new/Saudi_Riyal_Symbol.svg", width: 16, height: 16)
                                            : Container(),
                                  ],
                                ),
                              ],
                            ),
                          );
                        },
                        separatorBuilder: (cxt, index) => SizedBox(height: 12),
                        itemCount: model.patientAdvanceBalanceAmountList.length),
                  ],
                ),
              ),
            ),
            DefaultButton(
              TranslationBase.of(context).createAdvancedPayment,
              () {
                Navigator.push(context, FadePage(page: AdvancePaymentPage()));
                projectViewModel.analytics.advancePayments.wallet_recharge(service_type: 'alhabib wallet');
              },
            ).insideContainer,
          ],
        ),
      ),
    );
  }
}
