import 'package:doctor_app_flutter/config/config.dart';
import 'package:doctor_app_flutter/models/patient/patiant_info_model.dart';
import 'package:doctor_app_flutter/routes.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:hexcolor/hexcolor.dart';
import '../../../config/size_config.dart';
import '../../shared/app_texts_widget.dart';
import 'package:doctor_app_flutter/util/translations_delegate_base.dart';

import 'PatientProfileButton.dart';

/*
 *@author: Elham Rababah
 *@Date:22/4/2020
 *@param:
 *@return:ProfileMedicalInfoWidget
 *@desc:   Profile Medical Info Widget
 */
class ProfileMedicalInfoWidget extends StatelessWidget {
  ProfileMedicalInfoWidget({Key key, this.patient}) : super(key: key);
  PatiantInformtion patient;
  @override
  Widget build(BuildContext context) {
    return SliverGrid.count(
        crossAxisSpacing: 10,
        mainAxisSpacing: 20,
        crossAxisCount: 2,
        childAspectRatio: 1.5,
        children: [
          PatientProfileButton(
              key: key,
              patient: patient,
              nameLine1: "Create New",
              nameLine2: "Episode",
              route: CREATE_EPISODE,
              icon: 'heartbeat.png'),
          PatientProfileButton(
              key: key,
              patient: patient,
              nameLine1: TranslationBase.of(context).vital,
              nameLine2: TranslationBase.of(context).signs,
              route: VITAL_SIGN_DETAILS,
              icon: 'heartbeat.png'),
          PatientProfileButton(
              key: key,
              patient: patient,
              route: LAB_ORDERS,
              nameLine1: TranslationBase.of(context).lab,
              nameLine2: TranslationBase.of(context).result,
              icon: 'lab.png'),
          PatientProfileButton(
              key: key,
              patient: patient,
              route: PRESCRIPTIONS,
              nameLine1: TranslationBase.of(context).medicines,
              nameLine2: TranslationBase.of(context).prescription,
              icon: 'note.png'),
          PatientProfileButton(
              key: key,
              patient: patient,
              route: RADIOLOGY,
              nameLine1: TranslationBase.of(context).previewHealth,
              nameLine2: TranslationBase.of(context).summaryReport,
              icon: 'radiology-1.png'),
          Visibility(
              visible: selectedPatientType != 0 && selectedPatientType != 5,
              child: PatientProfileButton(
                  key: key,
                  patient: patient,
                  route: PROGRESS_NOTE,
                  nameLine1: TranslationBase.of(context).progress,
                  nameLine2: TranslationBase.of(context).note,
                  icon: 'heartbeat.png')),
          PatientProfileButton(
              key: key,
              patient: patient,
              route: PATIENT_INSURANCE_APPROVALS,
              nameLine1: TranslationBase.of(context).insurance,
              nameLine2: TranslationBase.of(context).approvals,
              icon: 'lab.png'),
          PatientProfileButton(
              key: key,
              patient: patient,
              route: ORDER_PRESCRIPTION,
              nameLine1: 'Order',
              nameLine2: 'Prescription',
              icon: 'lab.png'),
          PatientProfileButton(
              key: key,
              patient: patient,
              route: ORDER_PROCEDURE,
              nameLine1: 'Order Test',
              nameLine2: 'Or Procedures',
              icon: 'lab.png'),
          Visibility(
              visible: selectedPatientType != 0 &&
                  selectedPatientType != 5 &&
                  selectedPatientType != 2,
              child: PatientProfileButton(
                  key: key,
                  patient: patient,
                  route: REFER_PATIENT_TO_DOCTOR,
                  nameLine1: TranslationBase.of(context).myReferral,
                  nameLine2: TranslationBase.of(context).patient,
                  icon: 'note.png')),
          Visibility(
              visible: selectedPatientType != 0 && selectedPatientType != 5,
              child: PatientProfileButton(
                  key: key,
                  patient: patient,
                  route: PATIENT_ORDERS,
                  nameLine1: TranslationBase.of(context).orders,
                  nameLine2: TranslationBase.of(context).list,
                  icon: 'radiology-1.png')),
          Visibility(
              visible: selectedPatientType != 0 && selectedPatientType != 5,
              child: PatientProfileButton(
                  key: key,
                  patient: patient,
                  route: ADD_SICKLEAVE,
                  nameLine1: TranslationBase.of(context).patientSick,
                  nameLine2: TranslationBase.of(context).leave,
                  icon: 'sick_leaves_icons.png')),
        ]);
  }
}

class CircleAvatarWidget extends StatelessWidget {
  const CircleAvatarWidget(
      {Key key,
      @required this.url,
      @required this.des,
      this.height,
      this.width})
      : super(key: key);

  final String url;
  final String des;

  final double height;
  final double width;

  @override
  Widget build(BuildContext context) {
    return Container(
      child: Column(
        children: <Widget>[
          Container(
            height: height,
            width: width,
            // width: 50,
            // height: 50,
            decoration: new BoxDecoration(
                // color: Colors.green, // border color
                shape: BoxShape.circle,
                border: Border.all(color: HexColor('#B7831A'), width: 1.5)),
            child: CircleAvatar(
              radius: SizeConfig.imageSizeMultiplier * 12,
              child: Image.asset(url),
              backgroundColor: Colors.transparent,
            ),
          ),
          SizedBox(
            height: 10,
          ),
          AppText(
            des,
            fontSize: 1.5 * SizeConfig.textMultiplier,
            textAlign: TextAlign.center,
          )
        ],
      ),
    );
  }
}

class PatientProfileButton extends StatelessWidget {
  final String nameLine1;
  final String nameLine2;
  final String icon;
  final dynamic route;
  final PatiantInformtion patient;
  final String url = "assets/images/";
  PatientProfileButton(
      {Key key,
      this.patient,
      this.nameLine1,
      this.nameLine2,
      this.icon,
      this.route})
      : super(key: key);
  @override
  Widget build(BuildContext context) {
    return new Container(
      margin: new EdgeInsets.symmetric(horizontal: 4.0),
      child: InkWell(
        onTap: () {
          navigator(context, this.route);
        },
        child: Column(children: <Widget>[
          Container(
            alignment: Alignment.topLeft,
            padding: EdgeInsets.all(5),
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                AppText(
                  this.nameLine1,
                  color: Color(0xFFB9382C),
                  fontWeight: FontWeight.w600,
                  textAlign: TextAlign.left,
                  fontSize: SizeConfig.textMultiplier * 2,
                ),
                AppText(
                  this.nameLine2,
                  color: Colors.black,
                  fontWeight: FontWeight.w600,
                  textAlign: TextAlign.left,
                  fontSize: SizeConfig.textMultiplier * 2,
                ),
              ],
            ),
          ),
          Expanded(
            child: Container(
                child: Row(
              mainAxisAlignment: MainAxisAlignment.end,
              children: <Widget>[
                Container(
                    padding: EdgeInsets.all(10),
                    child: new Image.asset(url + icon))
              ],
            )),
          )
        ]),
      ),
      decoration: BoxDecoration(
        // border: Border.all(),
        color: Colors.white,
        borderRadius: BorderRadius.all(Radius.circular(10)),
        border: Border.fromBorderSide(BorderSide(
          color: Color(0xffBBBBBB),
          width: 1,
        )),
        boxShadow: [
          BoxShadow(
            color: Colors.grey.withOpacity(0.2),
            spreadRadius: 5,
            blurRadius: 7,
            offset: Offset(0, 3), // changes position of shadow
          ),
        ],
      ),
      padding: EdgeInsets.fromLTRB(5, 10, 5, 5),
    );
  }

  void navigator(BuildContext context, route) {
    Navigator.of(context).pushNamed(route, arguments: {'patient': patient});
  }
}
