import 'dart:math';

import 'package:diplomaticquarterapp/core/service/medical/vital_sign_service.dart';
import 'package:diplomaticquarterapp/core/viewModels/medical/medical_view_model.dart';
import 'package:diplomaticquarterapp/pages/MyAppointments/MyAppointments.dart';
import 'package:diplomaticquarterapp/pages/base/base_view.dart';
import 'package:diplomaticquarterapp/pages/medical/prescriptions/prescriptions_home_page.dart';
import 'package:diplomaticquarterapp/pages/medical/radiology/radiology_home_page.dart';
import 'package:diplomaticquarterapp/pages/medical/vital_sign/vital_sign_details_screen.dart';
import 'package:diplomaticquarterapp/pages/medical/reports/report_home_page.dart';
import 'package:diplomaticquarterapp/widgets/data_display/medical/medical_profile_item.dart';
import 'package:diplomaticquarterapp/widgets/data_display/medical/time_line_widget.dart';
import 'package:diplomaticquarterapp/widgets/data_display/text.dart';
import 'package:diplomaticquarterapp/widgets/others/app_scaffold_widget.dart';
import 'package:diplomaticquarterapp/widgets/others/sliver_app_bar_delegate.dart';
import 'package:diplomaticquarterapp/widgets/transitions/fade_page.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:diplomaticquarterapp/pages/insurance/insurance_card_screen.dart';
import '../../locator.dart';
import 'doctor/doctor_home_page.dart';
import 'package:diplomaticquarterapp/pages/insurance/insurance_update_screen.dart';
import 'package:diplomaticquarterapp/pages/insurance/insurance_approval_screen.dart';
import 'labs/labs_home_page.dart';

class MedicalProfilePage extends StatefulWidget {
  @override
  _MedicalProfilePageState createState() => _MedicalProfilePageState();
}

class _MedicalProfilePageState extends State<MedicalProfilePage> {
  @override
  Widget build(BuildContext context) {
    return BaseView<MedicalViewModel>(
      onModelReady: (model) => model.getAppointmentHistory(),
      builder: (_, model, widget) => AppScaffold(
        baseViewModel: model,
        body: SafeArea(
          child: SingleChildScrollView(
            child: Column(
              children: <Widget>[
                Stack(
                  children: <Widget>[
                    Column(
                      children: <Widget>[
                        Container(
                          width: double.infinity,
                          color: Colors.grey,
                          height: 210,
                          child: ListView.builder(
                            itemBuilder: (context, index) => TimeLineWidget(
                              isUp: index % 2 == 1,
                              appoitmentAllHistoryResul:
                                  model.appoitmentAllHistoryResultList[index],
                            ),
                            itemCount:
                                model.appoitmentAllHistoryResultList.length,
                            scrollDirection: Axis.horizontal,
                            reverse: true,
                          ),
                        ),
                        Padding(
                          padding: EdgeInsets.symmetric(vertical: 12.0),
                          child: Column(
                            children: <Widget>[
                              Container(
                                width: double.infinity,
                                height: 30,
                              ),
                              Row(
                                children: <Widget>[
                                  Expanded(
                                    flex: 1,
                                    child: InkWell(
                                      onTap: () {
                                        Navigator.push(context,
                                            FadePage(page: MyAppointments()));
                                      },
                                      child: MedicalProfileItem(
                                        title: 'My Appointments',
                                        imagePath: 'my_appointment_icon.png',
                                        subTitle: 'List',
                                      ),
                                    ),
                                  ),
                                  Expanded(
                                    flex: 1,
                                    child: InkWell(
                                      onTap: () => Navigator.push(context,
                                          FadePage(page: RadiologyHomePage())),
                                      child: MedicalProfileItem(
                                        title: 'Radiology',
                                        imagePath: 'radiology_icon.png',
                                        subTitle: 'Service',
                                      ),
                                    ),
                                  ),
                                  Expanded(
                                    flex: 1,
                                    child: InkWell(
                                      onTap: () => Navigator.push(context,
                                          FadePage(page: LabsHomePage())),
                                      child: MedicalProfileItem(
                                        title: 'Lab',
                                        imagePath: 'lab_result_icon.png',
                                        subTitle: 'Result',
                                      ),
                                    ),
                                  ),
                                ],
                              ),
                              Row(
                                children: <Widget>[
                                  Expanded(
                                    flex: 1,
                                    child: InkWell(
                                      onTap: () {
                                        Navigator.push(
                                            context,
                                            FadePage(
                                                page: HomePrescriptionsPage()));
                                      },
                                      child: MedicalProfileItem(
                                        title: 'Medicines',
                                        imagePath: 'prescription_icon.png',
                                        subTitle: 'Prescriptions',
                                      ),
                                    ),
                                  ),
                                  Expanded(
                                    flex: 1,
                                    child: InkWell(
                                      onTap: () => Navigator.push(
                                          context,
                                          FadePage(
                                              page: VitalSignDetailsScreen())),
                                      child: MedicalProfileItem(
                                        title: 'Vital Signs',
                                        imagePath: 'medical_history_icon.png',
                                        subTitle: 'Reports',
                                      ),
                                    ),
                                  ),
                                  Expanded(
                                    flex: 1,
                                    child: InkWell(
//                              onTap: () => Navigator.push(
//                                  context, FadePage(page: RadiologyHomePage())),
                                      child: MedicalProfileItem(
                                        title: 'My Medicines ',
                                        imagePath: 'radiology_icon.png',
                                        subTitle: 'Service',
                                      ),
                                    ),
                                  ),
                                ],
                              ),
                              Row(
                                children: <Widget>[
                                  Expanded(
                                    flex: 1,
                                    child: InkWell(
                                      onTap: () {
                                        Navigator.push(context,
                                            FadePage(page: DoctorHomePage()));
                                      },
                                      child: MedicalProfileItem(
                                        title: 'My Doctor',
                                        imagePath: 'doctor_icon.png',
                                        subTitle: 'List',
                                      ),
                                    ),
                                  ),
                                  Expanded(
                                    flex: 1,
                                    child: InkWell(
                                      //TODO
//                              onTap: () {
//                                Navigator.push(context,
//                                    FadePage(page: InsuranceApproval()));
//                              },
                                      child: MedicalProfileItem(
                                        title: 'Eye',
                                        imagePath:
                                            'insurance_approvals_icon.png',
                                        subTitle: 'Measurement',
                                      ),
                                    ),
                                  ),
                                  Expanded(
                                    flex: 1,
                                    child: InkWell(
                                      onTap: () {
                                        Navigator.push(context,
                                            FadePage(page: InsuranceCard()));
                                      },
                                      child: MedicalProfileItem(
                                        title: 'Insurance',
                                        imagePath: 'insurance_card_icon.png',
                                        subTitle: 'Card',
                                      ),
                                    ),
                                  ),
                                ],
                              ),
                              Row(children: <Widget>[
                                Expanded(
                                  flex: 1,
                                  child: InkWell(
                                    //TODO
//                            onTap: () {
//                              Navigator.push(
//                                  context, FadePage(page: DoctorHomePage()));
//                            },
                                    child: MedicalProfileItem(
                                      title: 'Update Insurance',
                                      imagePath: 'insurance_card_icon.png',
                                      subTitle: 'card',
                                    ),
                                  ),
                                ),
                                Expanded(
                                  flex: 1,
                                  child: InkWell(
//                            onTap: () {
//                              Navigator.push(
//                                  context, FadePage(page: InsuranceApproval()));
//                            },
                                    child: MedicalProfileItem(
                                      title: 'Insurance Approval',
                                      imagePath: 'insurance_approvals_icon.png',
                                      subTitle: '',
                                    ),
                                  ),
                                ),
                                Expanded(
                                  flex: 1,
                                  child: MedicalProfileItem(
                                    title: 'Allergies',
                                    imagePath: 'medical_history_icon.png',
                                    subTitle: 'Diagnosed',
                                  ),
                                ),
                              ]),
                              Row(children: <Widget>[
                                Expanded(
                                  flex: 1,
                                  child: InkWell(
                                    //TODO
//                            onTap: () {
//                              Navigator.push(
//                                  context, FadePage(page: DoctorHomePage()));
//                            },
                                    child: MedicalProfileItem(
                                      title: 'My Vaccines',
                                      imagePath: 'insurance_card_icon.png',
                                      subTitle: 'card',
                                    ),
                                  ),
                                ),
                                Expanded(
                                  flex: 1,
                                  child: InkWell(
                                    onTap: () {
                                      Navigator.push(context,
                                          FadePage(page: HomeReportPage()));
                                    },
                                    child: MedicalProfileItem(
                                      title: 'Medical',
                                      imagePath: 'insurance_approvals_icon.png',
                                      subTitle: 'Reports',
                                    ),
                                  ),
                                ),
                                Expanded(
                                  flex: 1,
                                  child: MedicalProfileItem(
                                    title: 'Monthly',
                                    imagePath: 'medical_history_icon.png',
                                    subTitle: 'Report',
                                  ),
                                ),
                              ]),
                              Row(children: <Widget>[
                                Expanded(
                                  flex: 1,
                                  child: InkWell(
                                    //TODO
//                            onTap: () {
//                              Navigator.push(
//                                  context, FadePage(page: DoctorHomePage()));
//                            },
                                    child: MedicalProfileItem(
                                      title: 'Sick',
                                      imagePath: 'insurance_card_icon.png',
                                      subTitle: 'Leaves',
                                    ),
                                  ),
                                ),
                                Expanded(
                                  flex: 1,
                                  child: InkWell(
//                            onTap: () {
//                              Navigator.push(
//                                  context, FadePage(page: InsuranceApproval()));
//                            },
                                    child: MedicalProfileItem(
                                      title: 'My Balance',
                                      imagePath: 'insurance_approvals_icon.png',
                                      subTitle: 'Credit',
                                    ),
                                  ),
                                ),
                                Expanded(
                                  flex: 1,
                                  child: MedicalProfileItem(
                                    title: 'Patient Call',
                                    imagePath: 'medical_history_icon.png',
                                    subTitle: 'Service',
                                  ),
                                ),
                              ]),
                              Row(children: <Widget>[
                                Expanded(
                                  flex: 1,
                                  child: InkWell(
                                    //TODO
//                            onTap: () {
//                              Navigator.push(
//                                  context, FadePage(page: DoctorHomePage()));
//                            },
                                    child: MedicalProfileItem(
                                      title: 'Smart Watches',
                                      imagePath: 'insurance_card_icon.png',
                                      subTitle: 'Pairing',
                                    ),
                                  ),
                                ),
                                Expanded(
                                  flex: 1,
                                  child: InkWell(
//                            onTap: () {
//                              Navigator.push(
//                                  context, FadePage(page: InsuranceApproval()));
//                            },
                                    child: MedicalProfileItem(
                                      title: 'My Trackers',
                                      imagePath: 'insurance_approvals_icon.png',
                                      subTitle: 'Service',
                                    ),
                                  ),
                                ),
                                Expanded(
                                  flex: 1,
                                  child: MedicalProfileItem(
                                    title: 'Ask Your',
                                    imagePath: 'medical_history_icon.png',
                                    subTitle: 'Doctor',
                                  ),
                                ),
                              ]),
                              Row(children: <Widget>[
                                Expanded(
                                  flex: 1,
                                  child: InkWell(
                                    //TODO
//                            onTap: () {
//                              Navigator.push(
//                                  context, FadePage(page: DoctorHomePage()));
//                            },
                                    child: MedicalProfileItem(
                                      title: 'Internet',
                                      imagePath: 'insurance_card_icon.png',
                                      subTitle: 'Pairing',
                                    ),
                                  ),
                                ),
                                Expanded(
                                  flex: 1,
                                  child: InkWell(
//                            onTap: () {
//                              Navigator.push(
//                                  context, FadePage(page: InsuranceApproval()));
//                            },
                                    child: MedicalProfileItem(
                                      title: 'My Trackers',
                                      imagePath: 'insurance_approvals_icon.png',
                                      subTitle: 'Service',
                                    ),
                                  ),
                                ),
                                Expanded(
                                  flex: 1,
                                  child: MedicalProfileItem(
                                    title: 'Ask Your',
                                    imagePath: 'medical_history_icon.png',
                                    subTitle: 'Doctor',
                                  ),
                                ),
                              ]),
                            ],
                          ),
                        )
                      ],
                    ),
                    if (model.user != null)
                      Positioned(
                        top: 175,
                        left: 20,
                        right: 20,
                        child: Container(
                          width: double.infinity,
                          height: 70,
                          decoration: BoxDecoration(
                            color: Colors.grey[600],
                            shape: BoxShape.rectangle,
                            border: Border.all(
                                color: Colors.transparent, width: 0.5),
                            borderRadius: BorderRadius.all(Radius.circular(9)),
                          ),
                          child: Column(
                            crossAxisAlignment: CrossAxisAlignment.center,
                            children: <Widget>[
                              SizedBox(
                                height: 8,
                              ),
                              Texts(
                                model.user.firstName +
                                    " " +
                                    model.user.lastName,
                                color: Colors.white,
                              ),
                              SizedBox(
                                height: 8,
                              ),
                              Texts(
                                '${model.user.patientID}',
                                color: Colors.white,
                              ),
                            ],
                          ),
                        ),
                      ),

                    Positioned(top: 10,left: 10,
                    child: Texts('Time Line ',color: Colors.white,fontSize: 14,fontWeight: FontWeight.normal,),
                    )
                  ],
                ),
              ],
            ),
          ),
        ),
      ),
    );
  }
}
