import 'package:doctor_app_flutter/core/model/labs/patient_lab_orders.dart';
import 'package:doctor_app_flutter/core/viewModel/labs_view_model.dart';
import 'package:doctor_app_flutter/core/viewModel/project_view_model.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/lab_result/LabResultWidget.dart';
import 'package:doctor_app_flutter/util/translations_delegate_base.dart';
import 'package:doctor_app_flutter/widgets/shared/app_texts_widget.dart';
import 'package:doctor_app_flutter/widgets/shared/network_base_view.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

class LaboratoryResultWidget extends StatefulWidget {
  final GestureTapCallback onTap;
  final String billNo;
  final String details;
  final String orderNo;
  final PatientLabOrders patientLabOrder;
  final PatiantInformtion patient;
  final bool isInpatient;

  const LaboratoryResultWidget(
      {Key key,
      this.onTap,
      this.billNo,
      this.details,
      this.orderNo,
      this.patientLabOrder,
      this.patient,
      this.isInpatient})
      : super(key: key);

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

class _LaboratoryResultWidgetState extends State<LaboratoryResultWidget> {
  bool _isShowMoreGeneral = true;
  ProjectViewModel projectViewModel;

  @override
  Widget build(BuildContext context) {
    projectViewModel = Provider.of(context);
    return BaseView<LabsViewModel>(
      onModelReady: (model) => model.getPatientLabResult(
          patientLabOrder: widget.patientLabOrder,
          patient: widget.patient,
          isInpatient: widget.isInpatient),
      builder: (_, model, w) => NetworkBaseView(
        baseViewModel: model,
        child: Container(
          margin: EdgeInsets.all(15),
          child: Column(
            children: <Widget>[
              Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: <Widget>[
                  SizedBox(
                    height: 12,
                  ),
                  if (model.labResultLists.isNotEmpty)
                    Container(
                      child: Column(
                        children: [
                          InkWell(
                            onTap: () {
                              setState(
                                () {
                                  _isShowMoreGeneral = !_isShowMoreGeneral;
                                },
                              );
                            },
                            child: Container(
                              padding: EdgeInsets.all(10.0),
                              margin: EdgeInsets.only(left: 5, right: 5),
                              decoration: BoxDecoration(
                                  shape: BoxShape.rectangle,
                                  color: Colors.white,
                                  borderRadius: BorderRadius.all(
                                    Radius.circular(5.0),
                                  )),
                              child: Row(
                                children: <Widget>[
                                  Expanded(
                                      child: Container(
                                          margin: EdgeInsets.only(
                                              left: 10, right: 10),
                                          child: AppText(
                                            TranslationBase.of(context)
                                                .generalResult,
                                            bold: true,
                                          ))),
                                  Container(
                                    width: 25,
                                    height: 25,
                                    child: Icon(
                                      _isShowMoreGeneral
                                          ? Icons.keyboard_arrow_up
                                          : Icons.keyboard_arrow_down,
                                      color: Colors.grey[800],
                                      size: 22,
                                    ),
                                  )
                                ],
                              ),
                            ),
                          ),
                          if (_isShowMoreGeneral)
                            AnimatedContainer(
                              padding: EdgeInsets.all(10.0),
                              margin: EdgeInsets.only(left: 5, right: 5),
                              decoration: BoxDecoration(
                                shape: BoxShape.rectangle,
                                color: Colors.white,
                                borderRadius: BorderRadius.only(
                                  bottomLeft: Radius.circular(5.0),
                                  bottomRight: Radius.circular(5.0),
                                ),
                              ),
                              duration: Duration(milliseconds: 7000),
                              child: Container(
                                width: double.infinity,
                                child: Column(
                                  crossAxisAlignment: CrossAxisAlignment.start,
                                  children: <Widget>[
                                    ...List.generate(
                                      model.labResultLists.length,
                                      (index) => LabResultWidget(
                                        patientLabOrder: widget.patientLabOrder,
                                        filterName: model
                                            .labResultLists[index].filterName,
                                        patientLabResultList: model
                                            .labResultLists[index]
                                            .patientLabResultList,
                                        patient: widget.patient,
                                        isInpatient: widget.isInpatient,
                                      ),
                                    )
                                  ],
                                ),
                              ),
                            ),
                        ],
                      ),
                    ),
                  SizedBox(
                    height: 10,
                  ),
                ],
              ),
            ],
          ),
        ),
      ),
    );
  }
}
