import 'package:cs_resources/constants/color_constants.dart';
import 'package:domain/entity/response/revise_log_s_g_entity.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:plugin_basic/basic_export.dart';
import 'package:widgets/ext/ex_widget.dart';
import 'package:widgets/my_text_view.dart';

/**
 * 修改记录Item
 */
class ReviseLogItem extends StatelessWidget {
  final int index;
  final ReviseLogSGRecords item;

  ReviseLogItem({
    required this.index,
    required this.item,
  });

  @override
  Widget build(BuildContext context) {
    return Container(
      padding: EdgeInsets.symmetric(vertical: 23, horizontal: 21),
      margin: EdgeInsets.only(left: 15, right: 15, top: 5, bottom: 5),
      decoration: BoxDecoration(
        color: Color(0xFF4DCFF6).withOpacity(0.2), // 设置背景颜色和不透明度
        borderRadius: BorderRadius.circular(5), // 设置圆角
      ),
      child: Column(
        mainAxisSize: MainAxisSize.max,
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          //时间
          Row(
            mainAxisSize: MainAxisSize.max,
            crossAxisAlignment: CrossAxisAlignment.center,
            children: [
              MyTextView(
                "Date Time".tr + ":",
                isFontRegular: true,
                textColor: ColorConstants.textGrayAECAE5,
                fontSize: 14,
              ),
              MyTextView(
                item.createdAt ?? "-",
                marginLeft: 5,
                isFontRegular: true,
                textColor: Colors.white,
                fontSize: 14,
              ).expanded(),
            ],
          ),

          // 操作者
          Row(
            mainAxisSize: MainAxisSize.max,
            crossAxisAlignment: CrossAxisAlignment.center,
            children: [
              MyTextView(
                "Operator:".tr,
                isFontRegular: true,
                textColor: ColorConstants.textGrayAECAE5,
                fontSize: 14,
              ),
              MyTextView(
                item.operationName ?? "-",
                marginLeft: 5,
                isFontRegular: true,
                textColor: Colors.white,
                fontSize: 14,
              ).expanded(),
            ],
          ).marginOnly(top: 15),

          // 操作类型
          Row(
            mainAxisSize: MainAxisSize.max,
            crossAxisAlignment: CrossAxisAlignment.center,
            children: [
              MyTextView(
                "Action".tr + ":",
                isFontRegular: true,
                textColor: ColorConstants.textGrayAECAE5,
                fontSize: 14,
              ),

              //状态
              MyTextView(
                item.actText ?? "-",
                marginLeft: 5,
                isFontRegular: true,
                textColor: item.actText == "Audit" ? ColorConstants.textYellowF8AE00 : ColorConstants.textGreen0AC074,
                fontSize: 14,
              ).expanded(),
            ],
          ).marginOnly(top: 15),

          // 操作内容
          Row(
            mainAxisSize: MainAxisSize.max,
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              MyTextView(
                "Content".tr + ":",
                isFontRegular: true,
                textColor: ColorConstants.textGrayAECAE5,
                fontSize: 14,
              ),

              //时间
              MyTextView(
                _obtainContent(),
                marginLeft: 5,
                isFontRegular: true,
                textColor: Colors.white,
                fontSize: 14,
              ).expanded(),
            ],
          ).marginOnly(top: 15),
        ],
      ),
    );
  }

  String _obtainContent() {
    String displayText = "";

    // 检查 reviseHours
    if (item.content?.reviseHours != null) {
      displayText += "Revise Hours => ${item.content!.reviseHours!.value!}\n";
    }

    // 检查 reviseMsg
    if (item.content?.reviseMsg != null) {
      displayText += "Reason => ${item.content!.reviseMsg!.value!}\n";
    }

    // 检查 status
    if (item.content?.status != null) {
      displayText += "Status => ${item.content!.status!.value!}\n";
    }

    // 如果没有任何信息，则显示 "-"
    if (displayText.isEmpty) {
      displayText = "-";
    } else {
      // 去掉末尾的换行符
      displayText = displayText.trim();
    }

    return displayText;
  }
}
