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/screens/patients/profile/soap_update/subjective/update_subjective_page.dart';
import 'package:doctor_app_flutter/widgets/patients/profile/patient-profile-header-new-design.dart';
import 'package:doctor_app_flutter/widgets/shared/app_scaffold_widget.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

import 'assessment/update_assessment_page.dart';
import 'objective/update_objective_page.dart';
import 'plan/update_plan_page.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,{isChangeState = true}) {
    if (pageIndex != _currentIndex && isChangeState)
      changeLoadingState(true);
    _controller.jumpToPage(pageIndex);
    setState(() {
      _currentIndex = pageIndex;
    });
  }

  bool _isLoading = true;

  @override
  void 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(
        isLoading: _isLoading,
        isShowAppBar: false,
        body: SingleChildScrollView(
          child: SingleChildScrollView(
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Container(
                decoration: BoxDecoration(
                    boxShadow: <BoxShadow>[],
                    color: Theme.of(context).scaffoldBackgroundColor),
                child: Column(
                  mainAxisAlignment: MainAxisAlignment.start,
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: <Widget>[
                    PatientProfileHeaderNewDesign(patient, '7', '7',),
                    Container(
                      width: double.infinity,
                      height: 1,
                      color: Color(0xffCCCCCC),
                    ),

                    Container(
                      color: Theme.of(context).scaffoldBackgroundColor,
                      height: MediaQuery.of(context).size.height * 0.73,
                      child: PageView(
                        physics: NeverScrollableScrollPhysics(),
                        controller: _controller,
                        onPageChanged: (index) {
                          setState(() {
                            _currentIndex = index;
                          });
                        },
                        scrollDirection: Axis.horizontal,
                        children: <Widget>[
                          UpdateSubjectivePage(
                              changePageViewIndex: changePageViewIndex,
                              currentIndex: _currentIndex,
                              myAllergiesList: myAllergiesList,
                              myHistoryList: myHistoryList,
                              patientInfo: patient,
                              changeLoadingState: changeLoadingState),
                          UpdateObjectivePage(
                              changePageViewIndex: changePageViewIndex,
                              currentIndex: _currentIndex,
                              mySelectedExamination: mySelectedExamination,
                              patientInfo: patient,
                              changeLoadingState: changeLoadingState),
                          UpdateAssessmentPage(
                              changePageViewIndex: changePageViewIndex,
                              currentIndex: _currentIndex,
                              mySelectedAssessmentList: mySelectedAssessment,
                              patientInfo: patient,
                              changeLoadingState: changeLoadingState),
                          UpdatePlanPage(
                              changePageViewIndex: changePageViewIndex,
                              currentIndex: _currentIndex,
                              patientInfo: patient,
                              patientProgressNote: patientProgressNote,
                              changeLoadingState: changeLoadingState)
                        ],
                      ),
                    )
                  ],
                ),
              ),
            ],
          ),
        ),
      ),
    ));
  }
}
