import 'package:cs_resources/constants/color_constants.dart';
import 'package:domain/entity/response/revise_list_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_button.dart';
import 'package:widgets/my_text_view.dart';

/*
 * Revise的Item布局
 */
class ReviseListItem extends StatelessWidget {
  final int index;
  final ReviseListSGRows item;
  final VoidCallback? onDetailAction;
  final VoidCallback? onLogsAction;
  final VoidCallback? onDeleteAction;
  final VoidCallback? onRecallAction;
  final VoidCallback? onEditAction;

  ReviseListItem({
    required this.index,
    required this.item,
    this.onDetailAction,
    this.onLogsAction,
    this.onDeleteAction,
    this.onRecallAction,
    this.onEditAction,
  });

  @override
  Widget build(BuildContext context) {
    return Container(
      padding: const EdgeInsets.symmetric(vertical: 23, horizontal: 21),
      margin: const EdgeInsets.only(left: 15, right: 15, top: 5, bottom: 5),
      decoration: BoxDecoration(
        color: const 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(
                "Name:".tr,
                isFontRegular: true,
                textColor: ColorConstants.textGrayAECAE5,
                fontSize: 14,
              ),
              MyTextView(
                item.name ?? "-",
                marginLeft: 5,
                isFontRegular: true,
                textColor: Colors.white,
                fontSize: 14,
              ).expanded(),
            ],
          ).marginOnly(top: 15),

          // 身份证
          Row(
            mainAxisSize: MainAxisSize.max,
            crossAxisAlignment: CrossAxisAlignment.center,
            children: [
              MyTextView(
                "Nric".tr + ":",
                isFontRegular: true,
                textColor: ColorConstants.textGrayAECAE5,
                fontSize: 14,
              ),

              //日期时间
              MyTextView(
                item.nric ?? "-",
                marginLeft: 5,
                isFontRegular: true,
                textColor: Colors.white,
                fontSize: 14,
              ).expanded(),
            ],
          ).marginOnly(top: 15),

          // 工作时间
          Row(
            mainAxisSize: MainAxisSize.max,
            crossAxisAlignment: CrossAxisAlignment.center,
            children: [
              MyTextView(
                "Job Time".tr + ":",
                isFontRegular: true,
                textColor: ColorConstants.textGrayAECAE5,
                fontSize: 14,
              ),
              MyTextView(
                item.jobTime ?? "",
                marginLeft: 5,
                isFontRegular: true,
                textColor: ColorConstants.white,
                fontSize: 14,
              ).expanded(),
            ],
          ).marginOnly(top: 15),

          // 加减小时
          Row(
            mainAxisSize: MainAxisSize.max,
            crossAxisAlignment: CrossAxisAlignment.center,
            children: [
              MyTextView(
                "+/- Hours".tr + ":",
                isFontRegular: true,
                textColor: ColorConstants.textGrayAECAE5,
                fontSize: 14,
              ),
              MyTextView(
                item.adjustHours ?? "-",
                marginLeft: 5,
                isFontRegular: true,
                textColor: Colors.white,
                fontSize: 14,
              ).expanded(),
            ],
          ).marginOnly(top: 15),

          // 总小时
          Row(
            mainAxisSize: MainAxisSize.max,
            crossAxisAlignment: CrossAxisAlignment.center,
            children: [
              MyTextView(
                "Total Hours:".tr,
                isFontRegular: true,
                textColor: ColorConstants.textGrayAECAE5,
                fontSize: 14,
              ),
              MyTextView(
                item.totalHours ?? "-",
                marginLeft: 5,
                isFontRegular: true,
                textColor: Colors.white,
                fontSize: 14,
              ).expanded(),
            ],
          ).marginOnly(top: 15),

          // 修改小时
          Row(
            mainAxisSize: MainAxisSize.max,
            crossAxisAlignment: CrossAxisAlignment.center,
            children: [
              MyTextView(
                "Revise Hours".tr + ":",
                isFontRegular: true,
                textColor: ColorConstants.textGrayAECAE5,
                fontSize: 14,
              ),
              MyTextView(
                item.reviseHours ?? "-",
                marginLeft: 5,
                isFontRegular: true,
                textColor: Colors.white,
                fontSize: 14,
              ).expanded(),
            ],
          ).marginOnly(top: 15),

          // 状态
          Row(
            mainAxisSize: MainAxisSize.max,
            crossAxisAlignment: CrossAxisAlignment.center,
            children: [
              MyTextView(
                "Status:".tr,
                isFontRegular: true,
                textColor: ColorConstants.textGrayAECAE5,
                fontSize: 14,
              ),

              //状态
              MyTextView(
                item.statusShow == null ? "" : item.statusShow!.tr,
                marginLeft: 5,
                isFontRegular: true,
                textColor: Colors.white,
                fontSize: 14,
              ).expanded(),
            ],
          ).marginOnly(top: 15),

          //按钮组
          Visibility(
            visible: item.actionList?.isNotEmpty ?? false,
            child: Row(
              mainAxisSize: MainAxisSize.max,
              mainAxisAlignment: MainAxisAlignment.end,
              crossAxisAlignment: CrossAxisAlignment.center,
              children: [
                //编辑按钮
                Visibility(
                  visible: item.actionList?.contains("edit") ?? false,
                  child: MyButton(
                    onPressed: () {
                      FocusScope.of(context).unfocus();
                      onEditAction?.call();
                    },
                    text: "Edit".tr,
                    textColor: ColorConstants.white,
                    backgroundColor: hexToColor(
                      "#FFBB1B",
                    ),
                    radius: 17.25,
                    minWidth: 60,
                    minHeight: 35,
                  ).marginOnly(left: 5,right: 5),
                ),

                //状态工作流按钮
                Visibility(
                  visible: item.actionList?.contains("recall") ?? false,
                  child: MyButton(
                    padding: const EdgeInsets.symmetric(horizontal: 10),
                    onPressed: () {
                      FocusScope.of(context).unfocus();
                      onRecallAction?.call();
                    },
                    text: "Recall".tr,
                    textColor: ColorConstants.white,
                    backgroundColor: ColorConstants.textYellowF8AE00,
                    radius: 17.25,
                    minWidth: 60,
                    minHeight: 35,
                  ).marginOnly(left: 5,right: 5),
                ),

                //状态工作流按钮
                Visibility(
                  visible: item.actionList?.contains("delete") ?? false,
                  child: MyButton(
                    padding: const EdgeInsets.symmetric(horizontal: 10),
                    onPressed: () {
                      FocusScope.of(context).unfocus();
                      onDeleteAction?.call();
                    },
                    text: "Delete".tr,
                    textColor: ColorConstants.white,
                    backgroundColor: ColorConstants.textRedFF6262,
                    radius: 17.25,
                    minWidth: 60,
                    minHeight: 35,
                  ).marginOnly(left: 5,right: 5),
                ),

                //详情按钮
                Visibility(
                  visible: item.actionList?.contains("detail") ?? false,
                  child: MyButton(
                    padding: const EdgeInsets.symmetric(horizontal: 10),
                    onPressed: () {
                      FocusScope.of(context).unfocus();
                      onDetailAction?.call();
                    },
                    text: "Detail".tr,
                    textColor: ColorConstants.white,
                    backgroundColor: ColorConstants.textBlue56AAFF,
                    radius: 17.25,
                    minWidth: 60,
                    minHeight: 35,
                  ).marginOnly(left: 5,right: 5),
                ),

                //日志
                Visibility(
                  visible: item.actionList?.contains("logs") ?? false,
                  child: MyButton(
                    padding: const EdgeInsets.symmetric(horizontal: 10),
                    onPressed: () {
                      FocusScope.of(context).unfocus();
                      onLogsAction?.call();
                    },
                    text: "Logs".tr,
                    textColor: ColorConstants.white,
                    backgroundColor: ColorConstants.textGreen0AC074,
                    radius: 17.25,
                    minWidth: 60,
                    minHeight: 35,
                  ).marginOnly(left: 5,right: 5),
                ),
              ],
            ).marginOnly(top: 18, bottom: 2),
          ),
        ],
      ),
    );
  }
}
