import 'package:hmg_patient_app/theme/colors.dart';
import 'package:hmg_patient_app/uitl/date_uitl.dart';
import 'package:hmg_patient_app/uitl/translations_delegate_base.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/data_display/text.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/material.dart';
import 'package:flutter_datetime_picker_plus/flutter_datetime_picker_plus.dart';
import 'package:intl/intl.dart';

import 'delivery_due_result_page.dart';

class DeliveryDue extends StatefulWidget {
  @override
  _DeliveryDueState createState() => _DeliveryDueState();
}

class _DeliveryDueState extends State<DeliveryDue> {
  DateTime bloodSugarDate = DateTime.now();
  DateTime timeSugarDate = DateTime.now();
  var dateFrom = DateTime.now();
  var dateTo = DateTime.now();
  var conceivedDate = DateTime.now();
  var deliveryDue = DateTime.now();
  var firstTrimester = DateTime.now();
  var secondTrimester = DateTime.now();
  var thirdTrimester = DateTime.now();
  var dt = DateTime.now();
  var newFormat = DateFormat("yy-MM-dd");

  String getDate() {
    return "${DateUtil.getMonth(bloodSugarDate.month)} ${bloodSugarDate.day}, ${bloodSugarDate.year}";
  }

  String getTime() {
    return " ${timeSugarDate.hour}:${timeSugarDate.minute}";
  }

  @override
  Widget build(BuildContext context) {
    return AppScaffold(
      isShowAppBar: true,
      showNewAppBar: true,
      showNewAppBarTitle: true,
      isShowDecPage: false,
      appBarTitle: TranslationBase.of(context).pregnancyTitle,
      body: Column(
        children: [
          Expanded(
            child: SingleChildScrollView(
              child: Container(
                padding: EdgeInsets.symmetric(horizontal: 21.0, vertical: 21.0),
                child: Column(
                  children: [
                    Text(
                      TranslationBase.of(context).pregnancyDesc,
                      style: TextStyle(
                        fontSize: 14,
                        fontWeight: FontWeight.w600,
                      ),
                    ),
                    Divider(
                      //height: 2,
                      thickness: 1,
                    ),
                    Column(
                      children: [
                        Text(
                          TranslationBase.of(context).pregnancyDateLabel,
                          style: TextStyle(
                            fontSize: 14,
                            fontWeight: FontWeight.w600,
                          ),
                        ),
                        InkWell(
                          onTap: () {
                            DatePicker.showDatePicker(
                              context,
                              showTitleActions: true,
                              minTime: DateTime(DateTime.now().year - 1, 1, 1),
                              maxTime: DateTime.now(),
                              onConfirm: (date) {
                                print('confirm $date');
                                setState(() {
                                  bloodSugarDate = date;
                                  dateFrom = date.add(Duration(days: 10));

                                  dateTo = date.add(Duration(days: 20));
                                  conceivedDate = date.add(Duration(days: 14));
                                  deliveryDue = date.add(Duration(days: 280));
                                  firstTrimester = date.add(Duration(days: 85));
                                  secondTrimester = date.add(Duration(days: 190));
                                  thirdTrimester = date.add(Duration(days: 280));
                                });
                              },
                              currentTime: DateTime.now(),
                            );
                          },
                          child: Container(
                            padding: EdgeInsets.all(12),
                            margin: EdgeInsets.only(top: 15.0),
                            width: double.infinity,
                            height: 65,
                            decoration: BoxDecoration(borderRadius: BorderRadius.circular(12), color: Colors.white),
                            child: Row(
                              mainAxisAlignment: MainAxisAlignment.spaceBetween,
                              children: [
                                Row(
                                  children: [
                                    Icon(Icons.date_range),
                                    Texts(TranslationBase.of(context).date),
                                  ],
                                ),
                                Texts(getDate()),
                              ],
                            ),
                          ),
                        ),
                      ],
                    ),

                  ],
                ),
              ),
            ),
          ),
          Container(
            margin: EdgeInsets.symmetric(horizontal: 16.0, vertical: 16.0),
            color: Colors.white,
            child: SecondaryButton(
              label: TranslationBase.of(context).calculate,
              color: CustomColors.accentColor,
              onTap: () {
                setState(() {
                  {
                    Navigator.push(
                      context,
                      FadePage(
                          page: DeliveryDueResult(
                            conceivedDate: conceivedDate,
                            dateFrom: dateFrom,
                            dateTo: dateTo,
                            deliveryDue: deliveryDue,
                            firstTrimester: firstTrimester,
                            secondTrimester: secondTrimester,
                            thirdTrimester: thirdTrimester,
                          )),
                    );
                  }
                });
              },
            ),
          ),
        ],
      ),
    );
  }
}
