import 'package:diplomaticquarterapp/uitl/date_uitl.dart';
import 'package:diplomaticquarterapp/widgets/buttons/button.dart';
import 'package:diplomaticquarterapp/widgets/buttons/secondary_button.dart';
import 'package:diplomaticquarterapp/widgets/data_display/text.dart';
import 'package:diplomaticquarterapp/widgets/others/app_scaffold_widget.dart';
import 'package:diplomaticquarterapp/widgets/transitions/fade_page.dart';
import 'package:flutter/material.dart';
import 'package:flutter_datetime_picker/flutter_datetime_picker.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,
      appBarTitle: 'Delivery Due Date',
      body: Padding(
        padding: EdgeInsets.symmetric(horizontal: 35.0, vertical: 20.0),
        child: SingleChildScrollView(
          child: Container(
            child: Column(
              //mainAxisAlignment: MainAxisAlignment.spaceAround,
              children: [
                Texts(
                  'Congratulations, you are pregnant! Now when will the new baby arrive? To estimate the due date, enter the date when the last menstrual perios began (the first day), then click calculate.',
                ),
                Divider(
                  //height: 2,
                  thickness: 2,
                ),
                Column(
                  children: [
                    Texts(
                      'What was the date of the first day of the last period?',
                    ),
                    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),
                        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('Date'),
                              ],
                            ),
                            Texts(getDate()),
                          ],
                        ),
                      ),
                    ),
                  ],
                ),
                SizedBox(
                  height: 280.0,
                ),
                Container(
                  height: 50.0,
                  width: 350.0,
                  child: SecondaryButton(
                    label: 'CALCULATE',
                    onTap: () {
                      setState(() {
                        {
                          Navigator.push(
                            context,
                            FadePage(
                                page: DeliveryDueResult(
                              conceivedDate: conceivedDate,
                              dateFrom: dateFrom,
                              dateTo: dateTo,
                              deliveryDue: deliveryDue,
                              firstTrimester: firstTrimester,
                              secondTrimester: secondTrimester,
                              thirdTrimester: thirdTrimester,
                            )),
                          );
                        }
                      });
                    },
                  ),
                ),
              ],
            ),
          ),
        ),
      ),
    );
  }
}
