import 'package:doctor_app_flutter/config/size_config.dart';
import 'package:doctor_app_flutter/core/viewModel/project_view_model.dart';
import 'package:doctor_app_flutter/core/model/discharge_summary/GetDischargeSummaryResModel.dart';
import 'package:doctor_app_flutter/utils/date-utils.dart';
import 'package:doctor_app_flutter/utils/utils.dart';
import 'package:doctor_app_flutter/utils/translations_delegate_base_utils.dart';
import 'package:doctor_app_flutter/widgets/shared/expandable-widget-header-body.dart';
import 'package:doctor_app_flutter/widgets/shared/user-guid/CusomRow.dart';
import 'package:eva_icons_flutter/eva_icons_flutter.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

class DischargeSummaryWidget extends StatefulWidget {
  final GetDischargeSummaryResModel dischargeSummary;
  bool isShowMore = false;

  DischargeSummaryWidget({Key? key, required this.dischargeSummary});

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

class _DischargeSummaryWidgetState extends State<DischargeSummaryWidget> {
  bool isCardExpanded = false;

  @override
  Widget build(BuildContext context) {
    ProjectViewModel projectViewModel = Provider.of(context);
    return Column(
      children: [
        Container(
          width: double.infinity,
          // margin: EdgeInsets.only(top: 8.0, left: 8.0, right: 8.0),
          // padding: EdgeInsets.all(8.0),
          decoration: BoxDecoration(
            color: Colors.white,
            borderRadius: BorderRadius.all(
              Radius.circular(10.0),
            ),
            border: Border.all(color: Colors.grey[200]!, width: 0.5),
          ),
          child: Padding(
            padding: EdgeInsets.all(15.0),
            child: HeaderBodyExpandableNotifier(
              headerWidget: Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  Expanded(
                    child: Column(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        CustomRow(
                          label: TranslationBase.of(context).doctorName + ": ",
                          value: widget.dischargeSummary.createdByName.toString() ?? "".toString(),
                          isCopyable: false,
                        ),
                        CustomRow(
                          label: TranslationBase.of(context).branch + ": ",
                          value: widget.dischargeSummary.projectName.toString() ?? "".toString(),
                          isCopyable: false,
                        ),
                        CustomRow(
                          label: TranslationBase.of(context).clinicName + ": ",
                          value: widget.dischargeSummary.clinicName.toString() ?? "".toString(),
                          isCopyable: false,
                        ),
                        CustomRow(
                          label: TranslationBase.of(context).dischargeDate + ": ",
                          value: AppDateUtils.getDateTimeFromServerFormat(widget.dischargeSummary.createdOn!).day.toString() +
                              " " +
                              AppDateUtils.getMonth(AppDateUtils.getDateTimeFromServerFormat(widget.dischargeSummary.createdOn!).month).toString().substring(0, 3) +
                              ' ' +
                              AppDateUtils.getDateTimeFromServerFormat(widget.dischargeSummary.createdOn!).year.toString(),
                          isCopyable: false,
                        ),
                      ],
                    ),
                  ),
                  Column(
                    crossAxisAlignment: CrossAxisAlignment.end,
                    children: [
                      InkWell(
                          onTap: () {
                            setState(() {
                              isCardExpanded = !isCardExpanded;
                            });
                          },
                          child: Icon(isCardExpanded ? EvaIcons.arrowUp : EvaIcons.arrowDown))
                    ],
                  ),
                ],
              ),

              bodyWidget: Row(
                children: [
                  Column(
                    children: [
                      SizedBox(
                        height: 15.0,
                      ),
                      //AppText(TranslationBase.of(context).moreDetails),
                      SizedBox(
                        height: 15.0,
                      ),
                      Container(
                        width: MediaQuery.of(context).size.width * 0.5,
                        child: RichText(
                          maxLines: 3,
                          overflow: TextOverflow.ellipsis,
                          text: new TextSpan(
                            style: new TextStyle(fontSize: 1.3 * SizeConfig.textMultiplier!, color: Color(0xFF575757)),
                            children: <TextSpan>[
                              new TextSpan(
                                  text: TranslationBase.of(context).pastMedicalHistory + ": ",
                                  style: TextStyle(
                                    fontSize: SizeConfig.getTextMultiplierBasedOnWidth() * 2.8,
                                    color: Color(0xFF575757),
                                    //TranslationBase.of(context).doctorResponse + " : ",
                                  )),
                              new TextSpan(
                                  text: Utils.parseHtmlString(widget.dischargeSummary.pastHistory!),
                                  style: TextStyle(
                                    fontFamily: 'Poppins',
                                    fontSize: SizeConfig.getTextMultiplierBasedOnWidth() * 3,
                                    color: Color(0xFF2E303A),
                                    fontWeight: FontWeight.w700,
                                  )),
                            ],
                          ),
                        ),
                      ),
                      SizedBox(
                        height: 5.0,
                      ),
                      Visibility(
                        visible: Utils.parseHtmlString(widget.dischargeSummary.investigations ?? "").isNotEmpty,
                        child: Container(
                          width: MediaQuery.of(context).size.width * 0.5,
                          child: RichText(
                            maxLines: 3,
                            overflow: TextOverflow.ellipsis,
                            text: new TextSpan(
                              style: new TextStyle(fontSize: 1.3 * SizeConfig.textMultiplier!, color: Color(0xFF575757)),
                              children: <TextSpan>[
                                new TextSpan(
                                    text: TranslationBase.of(context).investigation + ": ",
                                    style: TextStyle(
                                      fontSize: SizeConfig.getTextMultiplierBasedOnWidth() * 2.8,
                                      color: Color(0xFF575757),
                                      //TranslationBase.of(context).doctorResponse + " : ",
                                    )),
                                new TextSpan(
                                    text: Utils.parseHtmlString(widget.dischargeSummary.investigations ?? ""),
                                    style: TextStyle(
                                      fontFamily: 'Poppins',
                                      fontSize: SizeConfig.getTextMultiplierBasedOnWidth() * 3,
                                      color: Color(0xFF2E303A),
                                      fontWeight: FontWeight.w700,
                                    )),
                              ],
                            ),
                          ),
                        ),
                      ),
                      SizedBox(
                        height: 5.0,
                      ),
                      Visibility(
                        visible: Utils.parseHtmlString(widget.dischargeSummary.conditionOnDischarge ?? "").isNotEmpty,
                        child: Container(
                          width: MediaQuery.of(context).size.width * 0.5,
                          child: RichText(
                            maxLines: 3,
                            overflow: TextOverflow.ellipsis,
                            text: new TextSpan(
                              style: new TextStyle(fontSize: 1.3 * SizeConfig.textMultiplier!, color: Color(0xFF575757)),
                              children: <TextSpan>[
                                new TextSpan(
                                    text: TranslationBase.of(context).condition + ": ",
                                    style: TextStyle(
                                      fontSize: SizeConfig.getTextMultiplierBasedOnWidth() * 2.8,
                                      color: Color(0xFF575757),
                                      //TranslationBase.of(context).doctorResponse + " : ",
                                    )),
                                new TextSpan(
                                    text: Utils.parseHtmlString(widget.dischargeSummary.conditionOnDischarge!),
                                    style: TextStyle(
                                      fontFamily: 'Poppins',
                                      fontSize: SizeConfig.getTextMultiplierBasedOnWidth() * 3,
                                      color: Color(0xFF2E303A),
                                      fontWeight: FontWeight.w700,
                                    )),
                              ],
                            ),
                          ),
                        ),
                      ),
                      SizedBox(
                        height: 5.0,
                      ),
              Visibility(
                  visible: Utils.parseHtmlString(widget.dischargeSummary.planedProcedure ?? "").isNotEmpty,
                        child: Container(
                          width: MediaQuery.of(context).size.width * 0.5,
                          child: RichText(
                            maxLines: 3,
                            overflow: TextOverflow.ellipsis,
                            text: new TextSpan(
                              style: new TextStyle(fontSize: 1.3 * SizeConfig.textMultiplier!, color: Color(0xFF575757)),
                              children: <TextSpan>[
                                new TextSpan(
                                    text: TranslationBase.of(context).planedProcedure + ": ",
                                    style: TextStyle(
                                      fontSize: SizeConfig.getTextMultiplierBasedOnWidth() * 2.8,
                                      color: Color(0xFF575757),
                                      //TranslationBase.of(context).doctorResponse + " : ",
                                    )),
                                new TextSpan(
                                    text: Utils.parseHtmlString(widget.dischargeSummary.planedProcedure!),
                                    style: TextStyle(
                                      fontFamily: 'Poppins',
                                      fontSize: SizeConfig.getTextMultiplierBasedOnWidth() * 3,
                                      color: Color(0xFF2E303A),
                                      fontWeight: FontWeight.w700,
                                    )),
                              ],
                            ),
                          ),
                        ),
                      ),
                    ],
                  )
                ],
              ),
              isExpand: isCardExpanded,
            ),
          ),
        ),
      ],
    );
  }
}
