import 'package:diplomaticquarterapp/core/viewModels/project_view_model.dart';
import 'package:diplomaticquarterapp/uitl/date_uitl.dart';
import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart';
import 'package:diplomaticquarterapp/widgets/avatar/large_avatar.dart';
import 'package:diplomaticquarterapp/widgets/data_display/text.dart';
import 'package:diplomaticquarterapp/widgets/others/StarRating.dart';
import 'package:diplomaticquarterapp/widgets/others/rounded_container_widget.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:diplomaticquarterapp/extensions/string_extensions.dart';
import 'package:provider/provider.dart';

class DoctorCard extends StatelessWidget {
  final String name;
  final String subName;
  final double rat;
  final DateTime date;
  final String profileUrl;
  final String billNo;
  final Function onTap;
  final Function onEmailTap;
  final bool isInOutPatient;
  final bool isLiveCareAppointment;
  final bool isSortByClinic;
  final String appoTime;

  DoctorCard(
      {this.name, this.subName, this.rat, this.date, this.profileUrl, this.isSortByClinic = true, this.billNo, this.onTap, this.onEmailTap, this.isInOutPatient, this.isLiveCareAppointment = false, this.appoTime});

  @override
  Widget build(BuildContext context) {
    ProjectViewModel projectViewModel = Provider.of(context);
    return Container(
      height: 120,
      decoration: BoxDecoration(
          borderRadius: BorderRadius.all(
            Radius.circular(10.0),
          ),
          boxShadow: [
            BoxShadow(
              color: Color(0xff000000).withOpacity(.05),
              //spreadRadius: 5,
              blurRadius: 27,
              offset: Offset(0, -3),
            ),
          ],
          color: Colors.white),
      child: InkWell(
        onTap: onTap,
        child: Row(
          mainAxisSize: MainAxisSize.min,
          children: <Widget>[
            Container(
              //    width: 16, // projectViewModel.isArabic ? 27 : 20,
              height: double.infinity,
              alignment: Alignment.center,
              padding: EdgeInsets.only(left: 2, right: 2),
              decoration: BoxDecoration(
                //Colors.red[900]  Color(0xff404545)
                color: isLiveCareAppointment
                    ? Color(0xff404545)
                    : !isInOutPatient
                        ? Colors.red[900]
                        : Theme.of(context).primaryColor,
                borderRadius: BorderRadius.only(
                  topLeft: projectViewModel.isArabic ? Radius.circular(0) : Radius.circular(10),
                  bottomLeft: projectViewModel.isArabic ? Radius.circular(0) : Radius.circular(10),
                  topRight: projectViewModel.isArabic ? Radius.circular(10) : Radius.circular(0),
                  bottomRight: projectViewModel.isArabic ? Radius.circular(10) : Radius.circular(0),
                ),
              ),
              child: RotatedBox(
                quarterTurns: 3,
                child: Text(
                  isLiveCareAppointment
                      ? TranslationBase.of(context).liveCare.toLowerCase().capitalizeFirstofEach
                      : !isInOutPatient
                          ? TranslationBase.of(context).inPatient.toLowerCase().capitalizeFirstofEach
                          : TranslationBase.of(context).outpatient.toLowerCase().capitalizeFirstofEach,
                  style: TextStyle(fontSize: 10, fontWeight: FontWeight.w700, color: Colors.white, letterSpacing: -0.2, height: 16 / 10),
                ),
              ),
            ),
            Expanded(
              child: Padding(
                padding: const EdgeInsets.only(left: 20, right: 12, top: 12, bottom: 12),
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  mainAxisSize: MainAxisSize.min,
                  children: <Widget>[
                    Row(
                      mainAxisSize: MainAxisSize.min,
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        Expanded(
                          child: Text(
                            (name ?? ""),
                            style: TextStyle(fontSize: 16, fontWeight: FontWeight.w600, color: Color(0xff2E303A), letterSpacing: -0.64, height: 25 / 16),
                          ),
                        ),
                        Column(
                          mainAxisSize: MainAxisSize.min,
                          crossAxisAlignment: CrossAxisAlignment.end,
                          children: [
                            Text(
                              DateUtil.formatDateToDate(date),
                              style: TextStyle(fontSize: 14, fontWeight: FontWeight.w600, color: Color(0xff2B353E), letterSpacing: -0.48, height: 18 / 12),
                            ),
                            Text(
                              // DateUtil.formatDateToTime(date),
                              appoTime,
                              style: TextStyle(fontSize: 14, fontWeight: FontWeight.w600, color: Color(0xff575757), letterSpacing: -0.48, height: 18 / 12),
                            ),
                          ],
                        )
                      ],
                    ),
                    Row(
                      mainAxisSize: MainAxisSize.min,
                      children: <Widget>[
                        LargeAvatar(
                          name: name,
                          url: profileUrl,
                          width: 48,
                          height: 48,
                        ),
                        SizedBox(width: 11),
                        Expanded(
                          child: Column(
                            crossAxisAlignment: CrossAxisAlignment.start,
                            mainAxisSize: MainAxisSize.min,
                            mainAxisAlignment: MainAxisAlignment.center,
                            children: <Widget>[
                              myRichText(isSortByClinic ? TranslationBase.of(context).hospital : TranslationBase.of(context).clinic + ":", subName),
                              myRichText(TranslationBase.of(context).invoiceNo, billNo ?? ""),
                              //if (rat != null) StarRating(totalAverage: rat, forceStars: true),
                            ],
                          ),
                        ),
                        if (onEmailTap != null && projectViewModel.havePrivilege(17))
                          InkWell(
                            onTap: onEmailTap,
                            child: Icon(
                              Icons.email,
                              color: Theme.of(context).primaryColor,
                            ),
                          ),
                      ],
                    ),
                  ],
                ),
              ),
            )
          ],
        ),
      ),
    );
  }
}

// todo 'sikander' move this widget to separate file
Widget myRichText(String title, String value) {
  return RichText(
    text: TextSpan(
        text: title,
        style: TextStyle(fontSize: 12, fontWeight: FontWeight.w600, color: Color(0xff575757), letterSpacing: -0.4, height: 18 / 10),
        children: <TextSpan>[
          TextSpan(
            text: " $value",
            style: TextStyle(fontSize: 14, fontWeight: FontWeight.w600, color: Color(0xff2B353E), letterSpacing: -0.48, height: 18 / 12),
          )
        ]),
  );
}