import 'package:hmg_patient_app/core/model/ImagesInfo.dart';
import 'package:hmg_patient_app/core/viewModels/child_vaccines/user_information_view_model.dart';
import 'package:hmg_patient_app/pages/base/base_view.dart';
import 'package:hmg_patient_app/pages/medical/balance/new_text_Field.dart';
import 'package:hmg_patient_app/theme/colors.dart';
import 'package:hmg_patient_app/uitl/app_toast.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/buttons/secondary_button.dart';
import 'package:hmg_patient_app/widgets/input/text_field.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 'child_vaccine_page.dart';

class ChildInitialPage extends StatefulWidget {
  @override
  _ChildVaccinesPageState createState() => _ChildVaccinesPageState();
}

class _ChildVaccinesPageState extends State<ChildInitialPage> with SingleTickerProviderStateMixin {
  TextEditingController titleController = TextEditingController();
  var checkedValue = false;
  String addEmail = "";

  @override
  Widget build(BuildContext context) {
    return BaseView<UserInformationViewModel>(
      onModelReady: (model) => model.getUserInformationRequestOrders(),
      builder: (_, model, w) => AppScaffold(
        isShowAppBar: true,
        isShowDecPage: true,
        showNewAppBarTitle: true,
        showNewAppBar: true,
        description: TranslationBase.of(context).childVaccineInfo,
        imagesInfo: [
          ImagesInfo(
              imageEn: 'https://hmgwebservices.com/Images/MobileApp/images-info-home/child-vaccines/en/0.png',
              imageAr: 'https://hmgwebservices.com/Images/MobileApp/images-info-home/child-vaccines/ar/0.png'),
          ImagesInfo(
              imageEn: 'https://hmgwebservices.com/Images/MobileApp/images-info-home/child-vaccines/en/1.png',
              imageAr: 'https://hmgwebservices.com/Images/MobileApp/images-info-home/child-vaccines/ar/1.png')
        ],
        appBarTitle: TranslationBase.of(context).vaccination,
        body: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          mainAxisAlignment: MainAxisAlignment.spaceAround,
          children: [
            Padding(
              padding: const EdgeInsets.all(12.0),
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Text(
                    TranslationBase.of(context).welcomeBack,
                    style: TextStyle(
                      fontSize: 16,
                      letterSpacing: -0.64,
                      fontWeight: FontWeight.w600,
                    ),
                  ),
                  SizedBox(
                    height: 16,
                  ),
                  Text(
                    TranslationBase.of(context).msg_email_address_up_to_date,
                    style: TextStyle(
                      fontSize: 16,
                      letterSpacing: -0.64,
                      fontWeight: FontWeight.w600,
                    ),
                  ),
                  SizedBox(
                    height: 20,
                  ),
                  NewTextFields(
                  ///  fillColor: Colors.red,
                    //Changed By Aamir
                    hintText: model.user != null ? model.user!.emailAddress : "",
                    controller: titleController,
                    fontSize: 14,
                    hintColor: Colors.black,
                    fontWeight: FontWeight.w600,
                    suffixIcon: checkedValue ? Icons.check_box : Icons.check_box_outline_blank,
                    onSuffixTap: () {
                      setState(() {
                        checkedValue = !checkedValue;
                      });
                    },
                    onChanged: (text) {
                      addEmail = text;
                      model.user!.emailAddress == addEmail ? checkedValue = false : checkedValue = true;
                    },
                    validator: (value) {
                      if (value == null) {
                        return model.user!.emailAddress;
                      } else {
                        return model.user!.emailAddress;
                      }
                    },
                  ),
                ],
              ),
            ),
            mFlex(1),
            Container(
              width: double.infinity,
              color: Colors.white,
              padding: EdgeInsets.all(16),
              child: Column(
                children: [
                  if (checkedValue)
                    SecondaryButton(
                      textColor: Colors.white,
                      color: checkedValue == false ? Colors.white24 : CustomColors.green,
                      label: TranslationBase.of(context).updateEmail,
                      //
                      onTap: () {
                        model.user!.emailAddress = addEmail.toString();
                        AppToast.showSuccessToast(message: TranslationBase.of(context).updateEmailMsg);
                        // bloodDetails.city=_selectedHospital.toString();

                        // bloodDetails.
                      },
                    ),
                  if (checkedValue) mHeight(16),
                  DefaultButton(
                    TranslationBase.of(context).viewListChildren,
                    () => Navigator.push(
                      context,
                      FadePage(
                        page: ChildVaccinePage(),
                      ),
                    ),
                  ),
                ],
              ),
            ),
          ],
        ),
      ),
    );
  }
}
