import 'package:diplomaticquarterapp/core/enum/viewstate.dart';
import 'package:diplomaticquarterapp/core/viewModels/medical/reports_monthly_view_model.dart';
import 'package:diplomaticquarterapp/pages/base/base_view.dart';
import 'package:diplomaticquarterapp/pages/medical/reports/user_agreement_page.dart';
import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart';
import 'package:diplomaticquarterapp/widgets/buttons/secondary_button.dart';
import 'package:diplomaticquarterapp/widgets/data_display/text.dart';
import 'package:diplomaticquarterapp/widgets/input/custom_switch.dart';
import 'package:diplomaticquarterapp/widgets/others/app_scaffold_widget.dart';
import 'package:diplomaticquarterapp/widgets/transitions/fade_page.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

class MonthlyReportsPage extends StatefulWidget {
  @override
  _MonthlyReportsPageState createState() => _MonthlyReportsPageState();
}

class _MonthlyReportsPageState extends State<MonthlyReportsPage> {
  bool isAgree = false;
  bool isSummary = false;

  @override
  Widget build(BuildContext context) {
    return BaseView<ReportsMonthlyViewModel>(
      builder: (_, model, w) => AppScaffold(
        isShowAppBar: true,
        appBarTitle: TranslationBase.of(context).monthlyReports,
        body: SingleChildScrollView(
          child: Container(
            padding: EdgeInsets.all(12),
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Container(
                  padding: EdgeInsets.all(9),
                  height: 55,
                  decoration: BoxDecoration(
                      color: Colors.white,
                      borderRadius: BorderRadius.all(Radius.circular(8)),
                      shape: BoxShape.rectangle,
                      border: Border.all(color: Colors.grey)),
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      Texts(
                        TranslationBase.of(context).patientHealthSummaryReport,
                        bold: true,
                      ),
                      CustomSwitch(
                        value: isSummary,
                        activeColor: Colors.red,
                        inactiveColor: Colors.grey,
                        onChanged: () async {
                          setState(() {
                            isSummary = !isSummary;
                          });
                        },
                      )
                    ],
                  ),
                ),
                SizedBox(
                  height: 15,
                ),
                Container(
                  margin: EdgeInsets.all(8),
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      Texts(
                        model.user.emailAddress,
                        bold: true,
                      ),
                    ],
                  ),
                ),
                Divider(
                  height: 10.4,
                  thickness: 1.0,
                ),
                SizedBox(
                  height: 15,
                ),
                Container(
                  margin: EdgeInsets.all(8),
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    crossAxisAlignment: CrossAxisAlignment.center,
                    children: [
                      Expanded(
                        child: Texts(TranslationBase.of(context)
                            .toViewTheTermsAndConditions),
                      ),
                      InkWell(
                        onTap: () {
                          Navigator.push(
                            context,
                            FadePage(
                              page: UserAgreementContent(),
                            ),
                          );
                        },
                        child: Texts(
                          TranslationBase.of(context).clickHere,
                          color: Colors.blue,
                        ),
                      )
                    ],
                  ),
                ),
                SizedBox(
                  height: 5,
                ),
                Row(
                  crossAxisAlignment: CrossAxisAlignment.center,
                  mainAxisAlignment: MainAxisAlignment.start,
                  children: [
                    Checkbox(
                      value: isAgree,
                      onChanged: (value) {
                        setState(() {
                          isAgree = !isAgree;
                        });
                      },
                      activeColor: Colors.red,
                    ),
                    Texts(TranslationBase.of(context)
                        .iAgreeToTheTermsAndConditions),
                  ],
                ),
                Container(
                  margin: EdgeInsets.all(8),
                  width: double.infinity,
                  child: SecondaryButton(
                    textColor: Colors.white,
                    label: TranslationBase.of(context).save,
                    disabled: !isAgree,
                    loading: model.state == ViewState.BusyLocal,
                    onTap: () {
                      model.updatePatientHealthSummaryReport(
                          message: TranslationBase.of(context)
                              .updateSuccessfully,
                          isSummary: isSummary);
                    },
                  ),
                ),
                Padding(
                  padding: const EdgeInsets.all(5.0),
                  child: Texts(
                    TranslationBase.of(context)
                        .iAgreeToTheTermsAndConditionsSubtitle,
                    fontWeight: FontWeight.normal,
                  ),
                ),
                SizedBox(
                  height: 12,
                ),
                Center(child: Image.asset('assets/images/report.jpg'))
              ],
            ),
          ),
        ),
      ),
    );
  }
}
