import 'package:doctor_app_flutter/core/model/SOAP/assessment/audit_diagnosis.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:flutter/material.dart';
import 'package:intl/intl.dart';

class AuditItem extends StatelessWidget {
  final AuditDiagnosis auditDiagnosis;

  const AuditItem({super.key, required this.auditDiagnosis});

  @override
  Widget build(BuildContext context) {
    return Padding(
      padding: const EdgeInsets.symmetric(vertical: 12, horizontal: 16),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              AppText(
                auditDiagnosis.doctorName ?? '',
                fontWeight: FontWeight.w600,
                fontSize: 12,
                color: Color(0xFF2B353E),
              ),
              AppText(
                getDate(auditDiagnosis.createdOn?.isNotEmpty== true ? auditDiagnosis.createdOn ?? '' : auditDiagnosis.modifiedOn??''),
                fontWeight: FontWeight.w600,
                fontSize: 10,
                color: Color(0xFF2B353E),
              ),
            ],
          ),
          SizedBox(height: 4,),
          Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              AppText(
                "${TranslationBase.of(context).diagnosis}: ${auditDiagnosis.diagnosisType}",
                fontWeight: FontWeight.w600,
                fontSize: 12,
                color: Color(0xFF2B353E),
              ),
              AppText(
                getTime(auditDiagnosis.createdOn?.isNotEmpty== true ? auditDiagnosis.createdOn ?? '' : auditDiagnosis.modifiedOn??''),
                fontWeight: FontWeight.w600,
                fontSize: 10,
                color: Color(0xFF2B353E),
              ),
            ],
          ),
          SizedBox(
            height: 4,
          ),

          Visibility(
            visible: auditDiagnosis.deletedRemarks?.isEmpty == true,
            child: AppText(
              //todo handle the item after the discussion from the vidapro team this is temporary
              "${TranslationBase.of(context).remarks}: ${auditDiagnosis.remarks?.isNotEmpty == true? auditDiagnosis.remarks : TranslationBase.of(context).noRemarks}",
              fontWeight: FontWeight.w600,
              fontSize: 12,
              color: Color(0xFF2B353E),
            ),
          ),
          Visibility(
            visible: auditDiagnosis.deletedRemarks?.isNotEmpty == true,
            child: AppText(
              //todo handle the item after the discussion from the vidapro team this is temporary
              "${TranslationBase.of(context).deletedRemarks}${auditDiagnosis.deletedRemarks}",
              fontWeight: FontWeight.w600,
              fontSize: 12,
              color: Color(0xFF2B353E),
            ),
          ),
        ],
      ),
    );
  }

  String getDate(String dateTime) {
    if (dateTime.isEmpty) return '';
    DateTime now = DateTime.now();
    return DateFormat('dd MMM yyyy').format(now);
  }

  String getTime(String dateTime) {
    if (dateTime.isEmpty) return '';
    DateTime now = DateTime.now();
    return DateFormat('hh:mm a').format(now);
  }
}
