import 'package:diplomaticquarterapp/core/enum/viewstate.dart';
import 'package:diplomaticquarterapp/core/model/AlHabibMedicalService/HomeHealthCare/PatientERHHCInsertServicesList.dart';
import 'package:diplomaticquarterapp/core/model/AlHabibMedicalService/HomeHealthCare/patient_er_insert_pres_order_request_model.dart';
import 'package:diplomaticquarterapp/core/viewModels/AlHabibMedicalService/home_health_care_view_model.dart';
import 'package:diplomaticquarterapp/pages/base/base_view.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:flutter/cupertino.dart';
import 'package:flutter/material.dart';

class NewHomeHealthCareStepOnePage extends StatefulWidget {
  final PatientERInsertPresOrderRequestModel
      patientERInsertPresOrderRequestModel;
  final Function changePageViewIndex;
  final HomeHealthCareViewModel model;
  const NewHomeHealthCareStepOnePage(
      {Key key,
      this.patientERInsertPresOrderRequestModel,
        this.model,
      this.changePageViewIndex})
      : super(key: key);

  @override
  _NewHomeHealthCareStepOnePageState createState() =>
      _NewHomeHealthCareStepOnePageState();
}

class _NewHomeHealthCareStepOnePageState
    extends State<NewHomeHealthCareStepOnePage> {
  @override
  void initState() {

    widget
        .patientERInsertPresOrderRequestModel
        .patientERHHCInsertServicesList =[];
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return AppScaffold(
        isShowAppBar: false,
        baseViewModel: widget.model,
        body: SingleChildScrollView(
          physics: ScrollPhysics(),
          child: Container(
            margin: EdgeInsets.all(12),
            child: Center(
              child: FractionallySizedBox(
                widthFactor: 0.94,
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    SizedBox(
                      height: 20,
                    ),
                    Texts(
//                        TranslationBase.of(context).advancePaymentLabel,
                      "Select Home Health Care Services",
                      textAlign: TextAlign.center,
                    ),
                    Column(
                      children: widget.model.hhcAllServicesList.map((service) {
                        return Container(
                          margin: EdgeInsets.only(top: 15),
                          decoration: BoxDecoration(
                              border:
                              Border.all(color: Colors.grey, width: 1),
                              borderRadius: BorderRadius.circular(12),
                              color: Colors.white),
                          child: Column(
                            children: [
                              Row(
                                children: [
                                  Checkbox(
                                      value: isServiceSelected(
                                          service.serviceID),
                                      activeColor: Colors.black38,
                                      onChanged: (bool newValue) {
                                        setState(() {
                                          this
                                              .widget
                                              .patientERInsertPresOrderRequestModel
                                              .patientERHHCInsertServicesList
                                              .add(new PatientERHHCInsertServicesList(
                                              recordID:  this
                                                  .widget
                                                  .patientERInsertPresOrderRequestModel
                                                  .patientERHHCInsertServicesList
                                                  .length,
                                              serviceID:
                                              service.serviceID,
                                              serviceName:
                                              service.description));
                                          // widget.patientERInsertPresOrderRequestModel
                                          // isPatientInsured = newValue;
                                        });
                                      }),
                                  Expanded(
                                    child: Padding(
                                      padding: const EdgeInsets.all(20.0),
                                      child: Texts(
                                        service.description,
                                        fontSize: 15,
                                      ),
                                    ),
                                  ),
                                ],
                              ),
                            ],
                          ),
                        );
                      }).toList(),
                    )
                  ],
                ),
              ),
            ),
          ),
        ),
        bottomSheet:Container(
          height: MediaQuery.of(context).size.height * 0.10,
          width: double.infinity,
          child: Column(
            children: <Widget>[
              Container(
                width: MediaQuery
                    .of(context)
                    .size
                    .width * 0.9,
                child: SecondaryButton(
                    label: "Next",
                    disabled: this.widget.patientERInsertPresOrderRequestModel.patientERHHCInsertServicesList.length ==0,
                    textColor: Theme
                        .of(context)
                        .backgroundColor),
              ),
            ],
          ),
        ));
  }

  isServiceSelected(int serviceId) {
    Iterable <PatientERHHCInsertServicesList> patientERHHCInsertServicesList = widget
        .patientERInsertPresOrderRequestModel.patientERHHCInsertServicesList
        .where((element) => serviceId == element.serviceID);
     if(patientERHHCInsertServicesList.length > 0) {
       return true;
     }
     return false;
  }
}
