import 'package:diplomaticquarterapp/core/model/labs/patient_lab_orders.dart';
import 'package:diplomaticquarterapp/core/viewModels/medical/labs_view_model.dart';
import 'package:diplomaticquarterapp/core/viewModels/project_view_model.dart';
import 'package:diplomaticquarterapp/models/header_model.dart';
import 'package:diplomaticquarterapp/pages/base/base_view.dart';
import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart';
import 'package:diplomaticquarterapp/widgets/new_design/doctor_header.dart';
import 'package:diplomaticquarterapp/widgets/others/network_base_view.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_html/flutter_html.dart';
import 'package:provider/provider.dart';

import 'LabResultWidget.dart';

class LaboratoryResultWidget extends StatefulWidget {
  final GestureTapCallback onTap;
  final String billNo;
  final String details;
  final String orderNo;
  final PatientLabOrders patientLabOrder;

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

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

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

  @override
  Widget build(BuildContext context) {
    projectViewModel = Provider.of(context);
    return BaseView<LabsViewModel>(
      onModelReady: (model) => model.getPatientLabResult(patientLabOrder: widget.patientLabOrder),
      builder: (_, model, w) => NetworkBaseView(
        baseViewModel: model,
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: <Widget>[
            DoctorHeader(
              headerModel: HeaderModel(
                  widget.patientLabOrder.doctorName,
                  widget.patientLabOrder.doctorID,
                  widget.patientLabOrder.doctorImageURL,
                  widget.patientLabOrder.speciality,
                  widget.billNo,
                  widget.patientLabOrder.projectName,
                  widget.patientLabOrder.orderDate,
                  null,
                  widget.patientLabOrder.nationalityFlagURL,
                  widget.patientLabOrder.doctorRate,
                  widget.patientLabOrder.actualDoctorRate,
                  widget.patientLabOrder.noOfPatientsRate,
                  projectViewModel.user.emailAddress),
              onTap: widget.onTap,
            ),
            SizedBox(height: 10),
            if (model.labResultLists.isNotEmpty)
              Container(
                child: Column(
                  children: [
                    InkWell(
                      onTap: () {
                        setState(
                          () {
                            _isShowMoreGeneral = !_isShowMoreGeneral;
                          },
                        );
                      },
                      child: Container(
                        padding: EdgeInsets.only(left: 17, top: 12, right: 13, bottom: 12),
                        margin: EdgeInsets.only(left: 21, right: 21, top: 12),
                        decoration: BoxDecoration(
                          shape: BoxShape.rectangle,
                          color: Colors.white,
                          borderRadius: BorderRadius.all(
                            Radius.circular(10.0),
                          ),
                          boxShadow: [
                            BoxShadow(
                              color: Color(0xff000000).withOpacity(.05),
                              //spreadRadius: 5,
                              blurRadius: 27,
                              offset: Offset(0, -3),
                            ),
                          ],
                        ),
                        child: Column(
                          mainAxisSize: MainAxisSize.min,
                          children: [
                            Row(
                              mainAxisSize: MainAxisSize.min,
                              crossAxisAlignment: CrossAxisAlignment.center,
                              children: <Widget>[
                                Expanded(
                                  child: Text(
                                    TranslationBase.of(context).generalResult,
                                    style: TextStyle(fontSize: 16, fontWeight: FontWeight.w600, color: Color(0xff2E303A), letterSpacing: -0.64, height: 25 / 16),
                                  ),
                                ),
                                Icon(
                                  _isShowMoreGeneral ? Icons.keyboard_arrow_up : Icons.keyboard_arrow_down,
                                  color: Color(0xff575757),
                                  size: 22,
                                )
                              ],
                            ),
                            if (_isShowMoreGeneral)
                              ...List.generate(
                                model.labResultLists.length,
                                (index) => LabResultWidget(
                                  patientLabOrder: widget.patientLabOrder,
                                  filterName: model.labResultLists[index].filterName,
                                  patientLabResultList: model.labResultLists[index].patientLabResultList,
                                ),
                              )
                          ],
                        ),
                      ),
                    ),
                  ],
                ),
              ),
            InkWell(
              onTap: () {
                setState(() {
                  _isShowMore = !_isShowMore;
                });
              },
              child: Container(
                padding: EdgeInsets.only(left: 17, top: 14, right: 13, bottom: 10),
                margin: EdgeInsets.only(left: 21, right: 21, top: 12),
                decoration: BoxDecoration(
                  shape: BoxShape.rectangle,
                  color: Colors.white,
                  borderRadius: BorderRadius.all(
                    Radius.circular(10.0),
                  ),
                  boxShadow: [
                    BoxShadow(
                      color: Color(0xff000000).withOpacity(.05),
                      //spreadRadius: 5,
                      blurRadius: 27,
                      offset: Offset(0, -3),
                    ),
                  ],
                ),
                child: Column(
                  children: [
                    Row(
                      children: <Widget>[
                        Expanded(
                          child: Text(
                            TranslationBase.of(context).specialResult,
                            style: TextStyle(fontSize: 16, fontWeight: FontWeight.w600, color: Color(0xff2E303A), letterSpacing: -0.64, height: 25 / 16),
                          ),
                        ),
                        Icon(
                          _isShowMore ? Icons.keyboard_arrow_up : Icons.keyboard_arrow_down,
                          color: Color(0xff575757),
                          size: 22,
                        )
                      ],
                    ),
                    if (_isShowMore)
                      Container(
                        width: double.infinity,
                        child: Html(
                          data: widget.details ?? TranslationBase.of(context).noDataAvailable,
                        ),
                      ),
                  ],
                ),
              ),
            ),
          ],
        ),
      ),
    );
  }
}
