import 'package:doctor_app_flutter/config/config.dart';
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/icons_app/doctor_app_icons.dart';
import 'package:doctor_app_flutter/core/model/doctor/list_gt_my_patients_question_model.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/app_texts_widget.dart';
import 'package:doctor_app_flutter/widgets/shared/card_with_bg_widget.dart';
import 'package:doctor_app_flutter/widgets/shared/user-guid/CusomRow.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:url_launcher/url_launcher.dart';
import 'package:url_launcher/url_launcher_string.dart';

class DoctorReplyWidget extends StatefulWidget {
  final ListGtMyPatientsQuestions reply;
  bool isShowMore = false;

  DoctorReplyWidget({Key? key, required this.reply});

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

class _DoctorReplyWidgetState extends State<DoctorReplyWidget> {
  @override
  Widget build(BuildContext context) {
    ProjectViewModel projectViewModel = Provider.of(context);

    return Container(
      child: CardWithBgWidget(
        bgColor: widget.reply.infoStatus == 99
            ? Color(0xFF2B353E)
            : widget.reply.infoStatus == 4
                ? AppGlobal.inProgressColor
                : widget.reply.infoStatus == 3
                    ? Color(0xFFD02127)
                    : AppGlobal.appGreenColor,
        hasBorder: false,
        widget: Container(
            child: InkWell(
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              if (widget.reply.infoStatus != 0)
                Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    RichText(
                      text: new TextSpan(
                        style: new TextStyle(
                            fontSize: 2.0 * SizeConfig.textMultiplier!,
                            color: Colors.black),
                        children: <TextSpan>[
                          new TextSpan(
                              text: widget.reply.infoStatus == 99
                                  ? TranslationBase.of(context).notReplied
                                  : widget.reply.infoStatus == 1
                                      ? TranslationBase.of(context)
                                          .replayCallStatus
                                      : widget.reply.infoStatus == 2
                                          ? TranslationBase.of(context)
                                              .patientArrived
                                          : widget.reply.infoStatus == 3
                                              ? TranslationBase.of(context)
                                                  .calledAndNoResponse
                                              : widget.reply.infoStatus == 4
                                                  ? TranslationBase.of(context)
                                                      .underProcess
                                                  : widget.reply.infoStatus == 6
                                                      ? TranslationBase.of(
                                                              context)
                                                          .textResponse
                                                      : '',
                              style: TextStyle(
                                  color: widget.reply.infoStatus == 99
                                      ? Color(0xFF2B353E)
                                      : widget.reply.infoStatus == 4
                                          ? AppGlobal.inProgressColor
                                          : widget.reply.infoStatus == 3
                                              ? Color(0xFFD02127)
                                              : AppGlobal.appGreenColor,
                                  fontWeight: FontWeight.w700,
                                  fontFamily: 'Poppins',
                                  fontSize: 1.8 * SizeConfig.textMultiplier!)),
                        ],
                      ),
                    ),
                    Column(
                      crossAxisAlignment: CrossAxisAlignment.end,
                      children: [
                        AppText(
                          AppDateUtils.getDateTimeFromServerFormat(
                                      widget.reply.createdOn!)
                                  .day
                                  .toString() +
                              " " +
                              AppDateUtils.getMonth(
                                      AppDateUtils.getDateTimeFromServerFormat(
                                              widget.reply.createdOn!)
                                          .month)
                                  .toString()
                                  .substring(0, 3) +
                              ' ' +
                              AppDateUtils.getDateTimeFromServerFormat(
                                      widget.reply.createdOn!)
                                  .year
                                  .toString(),
                          fontFamily: 'Poppins',
                          fontWeight: FontWeight.w600,
                        ),
                        AppText(
                          AppDateUtils.getDateTimeFromServerFormat(
                                      widget.reply.createdOn!)
                                  .hour
                                  .toString() +
                              ":" +
                              AppDateUtils.getDateTimeFromServerFormat(
                                      widget.reply.createdOn!)
                                  .minute
                                  .toString(),
                          fontFamily: 'Poppins',
                          fontWeight: FontWeight.w600,
                        )
                      ],
                    ),
                  ],
                ),
              Row(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Expanded(
                    child: AppText(
                      Utils.capitalize(widget.reply.patientName),
                      fontSize: SizeConfig.textMultiplier! * 2.5,
                      fontWeight: FontWeight.bold,
                      fontFamily: 'Poppins',
                    ),
                  ),
                  Container(
                    margin: EdgeInsets.symmetric(horizontal: 4),
                    child: InkWell(
                      onTap: () {
                        launchUrlString("tel://" + widget.reply.mobileNumber!);
                      },
                      child: Icon(
                        Icons.phone,
                        color: Colors.black87,
                      ),
                    ),
                  ),
                  SizedBox(
                    width: 4,
                  ),
                  widget.reply.gender == 1
                      ? Icon(
                          DoctorApp.male_2,
                          color: Colors.blue,
                        )
                      : Icon(
                          DoctorApp.female_1,
                          color: Colors.pink,
                        ),
                ],
              ),
              SizedBox(
                height: 20,
              ),

              Row(
                crossAxisAlignment: CrossAxisAlignment.start,
                mainAxisAlignment: MainAxisAlignment.start,
                children: [
                  Column(
                    mainAxisAlignment: MainAxisAlignment.start,
                    children: <Widget>[
                      Container(
                        margin: EdgeInsets.only(top: 5),
                        width: 60,
                        height: 60,
                        child: Image.asset(
                          widget.reply.gender == 1
                              ? 'assets/images/male_avatar.png'
                              : 'assets/images/female_avatar.png',
                          fit: BoxFit.cover,
                        ),
                      ),
                    ],
                  ),
                  SizedBox(
                    width: 20,
                  ),
                  Expanded(
                    child: Column(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        // SizedBox(height: 10,),
                        // Row(
                        //   mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        //   crossAxisAlignment: CrossAxisAlignment.start,
                        //   children: [
                        //     Column(
                        //       crossAxisAlignment: CrossAxisAlignment.start,
                        //       children: [
                                CustomRow(
                                  label: TranslationBase.of(context).fileNumber,
                                  value: widget.reply.patientID.toString(),
                                  isCopyable: false,
                                  isExpanded: false,
                                ),
                                CustomRow(
                                  label: TranslationBase.of(context).age + " : ",                                isCopyable: false,
                                  isExpanded: false,
                                  value:
                                      "${AppDateUtils.getAgeByBirthday(widget.reply.dateofBirth!, context)}",
                                ),
                                SizedBox(
                                  height: 8,
                                ),
                        //       ],
                        //     ),
                        //   ],
                        // ),

                        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).requestType +
                                            ": ",
                                    style: TextStyle(
                                      fontSize: SizeConfig
                                              .getTextMultiplierBasedOnWidth() *
                                          2.8,
                                      color: Color(0xFF575757),
                                      //TranslationBase.of(context).doctorResponse + " : ",
                                    )),
                                new TextSpan(
                                    text:
                                        "${widget.reply.requestTypeDescription}",
                                    style: TextStyle(
                                      fontFamily: 'Poppins',
                                      fontSize: SizeConfig
                                              .getTextMultiplierBasedOnWidth() *
                                          3,
                                      color: Color(0xFF2E303A),
                                      fontWeight: FontWeight.w700,
                                    )),
                              ],
                            ),
                          ),
                        ),
                      ],
                    ),
                  )
                ],
              ),
              // Container(
              //   alignment: projectViewModel.isArabic?Alignment.centerLeft:Alignment.centerRight,
              //   child: Icon(FontAwesomeIcons.arrowRight,
              //       size: 20, color: Colors.black),)
            ],
          ),
          // onTap: onTap,
        )),
      ),
    );
  }
}
