import 'package:doctor_app_flutter/core/viewModel/doctor_replay_view_model.dart';
import 'package:doctor_app_flutter/models/SOAP/GetGetProgressNoteResModel.dart';
import 'package:doctor_app_flutter/models/SOAP/my_selected_allergy.dart';
import 'package:doctor_app_flutter/models/SOAP/my_selected_assement.dart';
import 'package:doctor_app_flutter/models/SOAP/my_selected_examination.dart';
import 'package:doctor_app_flutter/models/SOAP/my_selected_history.dart';
import 'package:doctor_app_flutter/models/patient/patiant_info_model.dart';
import 'package:doctor_app_flutter/screens/base/base_view.dart';
import 'package:doctor_app_flutter/util/translations_delegate_base.dart';
import 'package:doctor_app_flutter/widgets/patients/profile/patient-page-header-widget.dart';
import 'package:doctor_app_flutter/widgets/patients/profile/soap_update/steps_widget.dart';
import 'package:doctor_app_flutter/widgets/patients/profile/soap_update/subjective/update_subjective_page.dart';
import 'package:doctor_app_flutter/widgets/patients/profile/soap_update/update_assessment_page.dart';
import 'package:doctor_app_flutter/widgets/patients/profile/soap_update/update_objective_page.dart';
import 'package:doctor_app_flutter/widgets/patients/profile/soap_update/update_plan_page.dart';
import 'package:doctor_app_flutter/widgets/shared/app_scaffold_widget.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';


class UpdateSoapIndex extends StatefulWidget {
  final bool isUpdate;

  const UpdateSoapIndex({Key key, this.isUpdate}) : super(key: key);
  @override
  _UpdateSoapIndexState createState() => _UpdateSoapIndexState();
}

class _UpdateSoapIndexState extends State<UpdateSoapIndex>
    with TickerProviderStateMixin {
  PageController _controller;
  int _currentIndex = 0;
  List<MySelectedAllergy> myAllergiesList = List();
  List<MySelectedHistory> myHistoryList = List();
  List<MySelectedExamination> mySelectedExamination = List();
  List<MySelectedAssessment> mySelectedAssessment = List();

  GetPatientProgressNoteResModel patientProgressNote = GetPatientProgressNoteResModel();
  changePageViewIndex(pageIndex) {
    if (pageIndex != _currentIndex) changeLoadingState(true);
    _controller.jumpToPage(pageIndex);
  }

  bool _isLoading = true;

  @override
  void initState() {
    // TODO: implement initState
    _controller = new PageController();

    super.initState();
  }

  void changeLoadingState(isLoading) {
    setState(() {
      _isLoading = isLoading;
    });
  }

  @override
  Widget build(BuildContext context) {
    final routeArgs = ModalRoute.of(context).settings.arguments as Map;
    PatiantInformtion patient = routeArgs['patient'];
    return BaseView<DoctorReplayViewModel>(
      builder: (_, model, w) => AppScaffold(
        // baseViewModel: model,
        isLoading: _isLoading,
        appBarTitle: TranslationBase.of(context).healthRecordInformation,
        body: SingleChildScrollView(
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Container(
                decoration:
                    BoxDecoration(boxShadow: <BoxShadow>[], color: Colors.white),
                child: Column(
                  mainAxisAlignment: MainAxisAlignment.start,
                  children: <Widget>[
                    PatientPageHeaderWidget(patient),
                    FractionallySizedBox(
                      child: SingleChildScrollView(
                        child: Container(
                          height: MediaQuery.of(context).size.height * 0.75,
                          child: Column(
                            children: [
                              Container(
                                margin: EdgeInsets.only(
                                    left:
                                        MediaQuery.of(context).size.width * 0.05,
                                    right:
                                        MediaQuery.of(context).size.width * 0.05),
                                child: StepsWidget(
                                  index: _currentIndex,
                                  changeCurrentTab: changePageViewIndex,
                                ),
                              ),
                              Expanded(
                                child: PageView(
                                  physics: NeverScrollableScrollPhysics(),
                                  controller: _controller,
                                  onPageChanged: (index) {
                                    setState(() {
                                      _currentIndex = index;
                                    });
                                  },
                                  scrollDirection: Axis.horizontal,
                                  children: <Widget>[
                                    UpdateSubjectivePage(
                                      changePageViewIndex: changePageViewIndex,
                                      myAllergiesList: myAllergiesList,
                                      myHistoryList: myHistoryList,
                                      patientInfo: patient,
                                        changeLoadingState:changeLoadingState
                                    ),
                                    UpdateObjectivePage(
                                      changePageViewIndex: changePageViewIndex,
                                      mySelectedExamination:
                                          mySelectedExamination,
                                      patientInfo: patient,
                                        changeLoadingState:changeLoadingState
                                    ),
                                    UpdateAssessmentPage(
                                      changePageViewIndex: changePageViewIndex,
                                      mySelectedAssessmentList:
                                          mySelectedAssessment,
                                      patientInfo: patient,
                                        changeLoadingState:changeLoadingState

                                    ),
                                    UpdatePlanPage(
                                      changePageViewIndex: changePageViewIndex,
                                      patientInfo: patient,
                                        patientProgressNote: patientProgressNote,
                                        changeLoadingState:changeLoadingState

                                    )
                                  ],
                                ),
                              ),
                            ],
                          ),
                        ),
                      ),
                    )
                  ],
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }
}
