import 'package:doctor_app_flutter/utils/translations_delegate_base_utils.dart';
import 'package:doctor_app_flutter/widgets/shared/app_texts_widget.dart';
import 'package:flutter/material.dart';
import 'package:flutter_svg/svg.dart';

typedef OnSoapDetailActionClicked = Function(SoapDetailItemActions);

class SoapDetailItem extends StatelessWidget {
  final String title;
  final String condition;
  final String status;
  final String remarks;
  final String? type;
  final bool showActions;
  final OnSoapDetailActionClicked onSoapDetailActionClicked;

  const SoapDetailItem(
      {super.key,
      required this.title,
      required this.condition,
      required this.remarks,
      required this.onSoapDetailActionClicked,
      required this.status,
      this.type,
      this.showActions = true});

  @override
  Widget build(BuildContext context) {
    return Padding(
      padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Row(
            children: [
              Expanded(
                child: Column(
                  mainAxisSize: MainAxisSize.min,
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    AppText(
                      title,
                      color: Color(0XFF2B353E),
                      fontSize: 12,
                      fontWeight: FontWeight.bold,
                    ),
                    Row(
                      children: [
                        AppText(
                          "${TranslationBase.of(context).condition}:",
                          color: Color(0XFF2B353E),
                          fontSize: 10,
                          fontWeight: FontWeight.w500,
                        ),
                        SizedBox(
                          width: 4,
                        ),
                        AppText(
                          condition,
                          color: Color(0xffD02127),
                          fontSize: 10,
                          fontWeight: FontWeight.w500,
                        ),
                      ],
                    ),
                    Visibility(
                      visible: type?.isNotEmpty == true,
                      child: Row(
                        children: [
                          AppText(
                            "${TranslationBase.of(context).diagnoseType}:",
                            color: Color(0XFF2B353E),
                            fontSize: 10,
                            fontWeight: FontWeight.w500,
                          ),
                          SizedBox(
                            width: 4,
                          ),
                          AppText(
                            type ?? '',
                            color: Color(0xff359846),
                            fontSize: 10,
                            fontWeight: FontWeight.w500,
                          ),
                        ],
                      ),
                    ),
                    Visibility(
                        visible: remarks.isNotEmpty,
                        child: Column(
                          children: [
                            SizedBox(
                              height: 8,
                            ),
                            AppText(
                              remarks,
                              color: Color(0XFF2B353E),
                              fontSize: 10,
                              fontWeight: FontWeight.w400,
                            ),
                          ],
                        ))
                  ],
                ),
              ),
              Status(status: status)
            ],
          ),
          SizedBox(
            height: 16,
          ),
          Visibility(
            visible: showActions,
            child: Row(
              mainAxisSize: MainAxisSize.max,
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                GestureDetector(
                  behavior: HitTestBehavior.opaque,
                  onTap: () =>
                      onSoapDetailActionClicked(SoapDetailItemActions.EDIT),
                  child: SoapDetailItemActionsView(
                    icon: 'assets/images/svgs/edit.svg',
                    fontColor: Color(0XFF2B353E),
                    text: TranslationBase.of(context).edit,
                  ),
                ),
                GestureDetector(
                  behavior: HitTestBehavior.opaque,
                  onTap: () =>
                      onSoapDetailActionClicked(SoapDetailItemActions.RESOLVE),
                  child: SoapDetailItemActionsView(
                    icon: 'assets/images/svgs/resolve.svg',
                    fontColor: Color(0XFF359846),
                    text: TranslationBase.of(context).resolve,
                  ),
                ),
                GestureDetector(
                  behavior: HitTestBehavior.opaque,
                  onTap: () =>
                      onSoapDetailActionClicked(SoapDetailItemActions.AUDIT),
                  child: SoapDetailItemActionsView(
                    icon: 'assets/images/svgs/audit.svg',
                    fontColor: Color(0XFF2B353E),
                    text: TranslationBase.of(context).audit,
                  ),
                ),
                GestureDetector(
                  behavior: HitTestBehavior.opaque,
                  onTap: () =>
                      onSoapDetailActionClicked(SoapDetailItemActions.REMOVE),
                  child: SoapDetailItemActionsView(
                    icon: 'assets/images/svgs/delete.svg',
                    fontColor: Color(0XFFD02127),
                    text: TranslationBase.of(context).delete,
                  ),
                ),
              ],
            ),
          )
        ],
      ),
    );
  }
}

class SoapDetailItemActionsView extends StatelessWidget {
  final String icon;
  final String text;
  final Color fontColor;

  const SoapDetailItemActionsView(
      {super.key,
      required this.icon,
      required this.text,
      required this.fontColor});

  @override
  Widget build(BuildContext context) => Row(
        children: [
          SvgPicture.asset(icon),
          SizedBox(
            width: 8,
          ),
          AppText(
            text,
            color: fontColor,
            fontSize: 10,
            fontWeight: FontWeight.w500,
          ),
        ],
      );
}

class Status extends StatelessWidget {
  final String status;

  const Status({super.key, required this.status});

  @override
  Widget build(BuildContext context) {
    return Material(
        shape: RoundedRectangleBorder(
          borderRadius: BorderRadius.circular(3),
        ),
        // color: Color(0xFF359846),
        color: (status.toLowerCase() ==
                    TranslationBase.of(context).active.toLowerCase() ||
                status.toLowerCase() ==
                    TranslationBase.of(context).stable.toLowerCase())
            ? Color(0xFFD8E8DB)
            : (status.toLowerCase() ==
                    TranslationBase.of(context).resolved.toLowerCase())
                ? Colors.lightBlue
                : Color(0x98d02127),
        child: Padding(
          padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 6),
          child: AppText(
            status,
            color: (status.toLowerCase() ==
                        TranslationBase.of(context).active.toLowerCase() ||
                    status.toLowerCase() ==
                        TranslationBase.of(context).stable.toLowerCase())
                ? Color(0xFF359846)
                : Colors.white,
            fontSize: 8,
            fontWeight: FontWeight.w600,
          ),
        ));
  }
}

enum SoapDetailItemActions { EDIT, RESOLVE, AUDIT, REMOVE, CHANGE_STATUS }
