import 'package:hmg_patient_app/core/model/pharmacies/LacumAccountInformation.dart';
import 'package:hmg_patient_app/core/viewModels/pharmacyModule/lacum-trasnfer-viewModel.dart';
import 'package:hmg_patient_app/pages/base/base_view.dart';
import 'package:hmg_patient_app/uitl/translations_delegate_base.dart';
import 'package:hmg_patient_app/widgets/buttons/borderedButton.dart';
import 'package:hmg_patient_app/widgets/data_display/text.dart';
import 'package:hmg_patient_app/widgets/others/app_scaffold_widget.dart';
import 'package:flutter/material.dart';

class LacumTransferPage extends StatefulWidget {
  final LacumAccountInformation lacumInformation;
  final LacumAccountInformation lacumGroupInformation;

  LacumTransferPage(this.lacumInformation, this.lacumGroupInformation);

  @override
  _LacumTransferPageState createState() => _LacumTransferPageState();
}

class _LacumTransferPageState extends State<LacumTransferPage> {
  TextEditingController _beneficieryAccountController = new TextEditingController();
  TextEditingController _transferPointsController = new TextEditingController();

  @override
  void initState() {
    super.initState();
    _beneficieryAccountController.text = "";
    _transferPointsController.text = "0";
  }

  @override
  Widget build(BuildContext context) {
    final mediaQuery = MediaQuery.of(context);

    return BaseView<LacumTranferViewModel>(
        onModelReady: (model) => model.setLakumData(widget.lacumInformation, widget.lacumGroupInformation),
        builder: (_, model, wi) => AppScaffold(
              appBarTitle: "${TranslationBase.of(context).lakumTransfer}",
              isShowAppBar: true,
              isPharmacy: true,
              isShowDecPage: false,
              showHomeAppBarIcon: false,
              isBottomBar: true,
              showPharmacyCart: false,
              backgroundColor: Colors.white,
              baseViewModel: model,
              body: Container(
                width: double.infinity,
                child: SingleChildScrollView(
                  child: SizedBox(
                    height: mediaQuery.size.height - 58 - mediaQuery.padding.top,
                    child: Padding(
                      padding: const EdgeInsets.all(16.0),
                      child: Column(
                        crossAxisAlignment: CrossAxisAlignment.stretch,
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        children: [
                          Column(
                            children: [
                              Row(
                                children: [
                                  Container(
                                    height: 100,
                                    width: mediaQuery.size.width / 2 - 26,
                                    padding: EdgeInsets.only(top: 12, left: 8, right: 8, bottom: 4),
                                    decoration: BoxDecoration(
                                        shape: BoxShape.rectangle,
                                        borderRadius: BorderRadius.circular(8),
                                        border: Border.fromBorderSide(BorderSide(
                                          color: Color(0xffe1e1e1),
                                          width: 0.4,
                                        )),
                                        color: Colors.green
                                        //(0xff6294ed),
                                        ),
                                    child: Row(
                                      crossAxisAlignment: CrossAxisAlignment.start,
                                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                                      children: [
                                        Expanded(
                                          child: Column(
                                            children: [
                                              Container(
                                                child: Texts(
                                                  "${TranslationBase.of(context).point} ${TranslationBase.of(context).balance}",
                                                  fontSize: 14,
                                                  fontWeight: FontWeight.bold,
                                                  color: Colors.white,
                                                ),
                                              ),
                                            ],
                                          ),
                                        ),
                                        Expanded(
                                          child: Container(
                                            padding: EdgeInsets.symmetric(vertical: 8),
                                            child: Column(
                                              mainAxisAlignment: MainAxisAlignment.end,
                                              crossAxisAlignment: CrossAxisAlignment.end,
                                              children: [
                                                Texts(
                                                  "${model.lacumGroupInformation!.lakumInquiryInformationObjVersion!.pointsBalance}",
                                                  fontSize: 14,
                                                  fontWeight: FontWeight.bold,
                                                  color: Colors.white,
                                                ),
                                              ],
                                            ),
                                          ),
                                        )
                                      ],
                                    ),
                                  ),
                                  SizedBox(
                                    width: 20,
                                  ),
                                  Container(
                                    height: 100,
                                    width: mediaQuery.size.width / 2 - 26,
                                    padding: EdgeInsets.only(top: 12, left: 8, right: 8, bottom: 4),
                                    decoration: BoxDecoration(
                                      shape: BoxShape.rectangle,
                                      borderRadius: BorderRadius.circular(8),
                                      border: Border.fromBorderSide(BorderSide(
                                        color: Color(0xffe1e1e1),
                                        width: 0.4,
                                      )),
                                      color: Color(0xff339933),
                                    ),
                                    child: Row(
                                      crossAxisAlignment: CrossAxisAlignment.start,
                                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                                      children: [
                                        Expanded(
                                          child: Column(
                                            children: [
                                              Container(
                                                child: Texts(
                                                  "${TranslationBase.of(context).riyal} ${TranslationBase.of(context).balance}",
                                                  fontSize: 14,
                                                  fontWeight: FontWeight.bold,
                                                  color: Colors.white,
                                                ),
                                              ),
                                            ],
                                          ),
                                        ),
                                        Expanded(
                                          child: Container(
                                            padding: EdgeInsets.symmetric(vertical: 8),
                                            child: Column(
                                              mainAxisAlignment: MainAxisAlignment.end,
                                              crossAxisAlignment: CrossAxisAlignment.end,
                                              children: [
                                                Texts(
                                                  "${model.lacumGroupInformation!.lakumInquiryInformationObjVersion!.pointsBalanceAmount}",
                                                  fontSize: 14,
                                                  fontWeight: FontWeight.bold,
                                                  color: Colors.white,
                                                ),
                                              ],
                                            ),
                                          ),
                                        )
                                      ],
                                    ),
                                  ),
                                ],
                              ),
                              Container(
                                margin: EdgeInsets.only(top: 16),
                                child: TextField(
                                  controller: _beneficieryAccountController,
                                  decoration: new InputDecoration(
                                    hintText: TranslationBase.of(context).enterBeneficiaryAccountNo,
                                  ),
                                  style: TextStyle(
                                    fontSize: 16,
                                    color: Colors.grey.shade700,
                                  ),
                                ),
                              ),
                              Container(
                                margin: EdgeInsets.only(top: 4),
                                child: BorderedButton(
                                  TranslationBase.of(context).checkBeneficiary,
                                  backgroundColor: _beneficieryAccountController.text.isNotEmpty ? Color(0xff60686b) : Color(0xffb0b4b5),
                                  textColor: Colors.white,
                                  fontSize: 16,
                                  hPadding: 8,
                                  vPadding: 12,
                                  handler: _beneficieryAccountController.text.isNotEmpty
                                      ? () {
                                          model.getLacumGroupDataBuAccountId(_beneficieryAccountController.text);
                                        }
                                      : () {},
                                ),
                              ),
                              (model.lacumReceiverInformation != null && model.lacumReceiverInformation!.lakumInquiryInformationObjVersion != null)
                                  ? Container(
                                      margin: EdgeInsets.only(top: 8),
                                      child: Column(
                                        crossAxisAlignment: CrossAxisAlignment.start,
                                        children: [
                                          Texts(
                                            TranslationBase.of(context).beneficiaryName,
                                            color: Colors.black,
                                          ),
                                          Padding(
                                            padding: const EdgeInsets.symmetric(horizontal: 8),
                                            child: TextField(
                                              enabled: false,
                                              decoration: new InputDecoration(
                                                  hintText: "${model.lacumReceiverInformation!.lakumInquiryInformationObjVersion!.memberName}",
                                                  hintStyle: TextStyle(
                                                    fontSize: 16,
                                                    color: Colors.grey.shade600,
                                                  )),
                                              style: TextStyle(
                                                fontSize: 16,
                                                color: Colors.grey.shade700,
                                              ),
                                            ),
                                          ),
                                          SizedBox(
                                            height: 10,
                                            width: double.infinity,
                                          ),
                                          Texts(
                                            TranslationBase.of(context).pointsToTransfer,
                                            color: Colors.black,
                                          ),
                                          Padding(
                                            padding: const EdgeInsets.symmetric(horizontal: 8),
                                            child: TextField(
                                              controller: _transferPointsController,
                                              decoration: new InputDecoration(
                                                  focusColor: Colors.green,
                                                  hintStyle: TextStyle(
                                                    fontSize: 16,
                                                    color: Colors.grey.shade600,
                                                  )),
                                              style: TextStyle(
                                                fontSize: 16,
                                                color: Colors.grey.shade700,
                                              ),
                                            ),
                                          ),
                                        ],
                                      ),
                                    )
                                  : Container()
                            ],
                          ),
                          if (model.lacumReceiverInformation != null && model.lacumReceiverInformation!.lakumInquiryInformationObjVersion != null)
                            Container(
                              margin: EdgeInsets.all(8),
                              child: BorderedButton(
                                TranslationBase.of(context).lakumTransfer,
                                backgroundColor: Color(0xff339933),
                                textColor: Colors.white,
                                fontSize: 18,
                                hPadding: 8,
                                radius: 12,
                                vPadding: 16,
                                fontWeight: FontWeight.w600,
                                handler: () {
                                  model.transferYaHalaLoyaltyPoints(_transferPointsController.text).then((status) => {
                                        {Navigator.pop(context)}
                                      });
                                },
                              ),
                            )
                        ],
                      ),
                    ),
                  ),
                ),
              ),
            ));
  }
}
