import 'package:cs_resources/constants/color_constants.dart';
import 'package:domain/entity/response/t_h_o_a_labour_table_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:shared/utils/util.dart';
import 'package:widgets/ext/ex_widget.dart';
import 'package:widgets/my_button.dart';
import 'package:widgets/my_text_view.dart';
import 'package:widgets/widget_export.dart';

/*
 * 用工请求的主页面列表Item
 */
class LabourRequestItem extends StatelessWidget {
  final int index;
  final THOALabourTableRows item;
  final int totalNum;
  final VoidCallback? onStatusAction;
  final VoidCallback? onRecallAction;
  final VoidCallback? onDetailAction;
  final VoidCallback? onEditAction;
  final VoidCallback? onDeleteAction;
  final VoidCallback? onAttAction;
  final VoidCallback? onPreSelectedAction;

  LabourRequestItem({
    required this.index,
    required this.item,
    required this.totalNum,
    this.onStatusAction,
    this.onRecallAction,
    this.onDetailAction,
    this.onEditAction,
    this.onDeleteAction,
    this.onAttAction,
    this.onPreSelectedAction,
  });

  @override
  Widget build(BuildContext context) {
    return Container(
      padding: const EdgeInsets.symmetric(vertical: 15, 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: [
          //工作标题
          MyTextView(
            item.jobTitle ?? "-",
            isFontMedium: true,
            textColor: ColorConstants.textYellowFFBB1B,
            fontSize: 14,
            textDecoration: TextDecoration.underline,
            decorationColor: ColorConstants.textYellowFFBB1B,
            // 可选，设置下划线的颜色
            decorationThickness: 2.0,
            // 可选，设置下划线的粗细
            decorationStyle: TextDecorationStyle.solid, // 可选，设置下划线的样式
          ),

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

              //部门
              MyTextView(
                item.outletName ?? "-",
                marginLeft: 5,
                isFontRegular: true,
                textColor: Colors.white,
                fontSize: 14,
              ).expanded(),
            ],
          ).marginOnly(top: 6),

          // 工作日期时间
          Row(
            mainAxisSize: MainAxisSize.max,
            crossAxisAlignment: CrossAxisAlignment.center,
            children: [
              MyTextView(
                "${"Job Time".tr}:",
                isFontRegular: true,
                textColor: ColorConstants.textGrayAECAE5,
                fontSize: 14,
              ),

              //日期时间
              MyTextView(
                "${item.jobDate} ${item.startTime}~${item.endTime}",
                marginLeft: 5,
                isFontRegular: true,
                textColor: Colors.white,
                fontSize: 14,
              ).expanded(),
            ],
          ).marginOnly(top: 6),

          // 人数
          Row(
            mainAxisSize: MainAxisSize.max,
            crossAxisAlignment: CrossAxisAlignment.center,
            children: [
              RichText(
                text: TextSpan(
                  style: const TextStyle(fontSize: 14, fontWeight: FontWeight.w400, color: ColorConstants.textGrayAECAE5),
                  children: <TextSpan>[
                    TextSpan(
                      text: "Manpower Needed".tr,
                    ),
                    TextSpan(
                      text: "($totalNum)",
                      style: const TextStyle(fontSize: 14, fontWeight: FontWeight.w400, color: ColorConstants.textYellowFFBB1B),
                    ),
                    const TextSpan(
                      text: ":",
                    ),
                  ],
                ),
              ),

              //人数
              MyTextView(
                item.hiringNum.toString(),
                marginLeft: 5,
                isFontRegular: true,
                textColor: Colors.white,
                fontSize: 14,
              ).expanded(),
            ],
          ).marginOnly(top: 6),

          // 预选人数
          Row(
            mainAxisSize: MainAxisSize.max,
            crossAxisAlignment: CrossAxisAlignment.center,
            children: [
              MyTextView(
                "${"Pre Selected".tr}:",
                isFontRegular: true,
                textColor: ColorConstants.textGrayAECAE5,
                fontSize: 14,
              ),

              //文本
              MyTextView(
                item.preNum.toString(),
                marginLeft: 5,
                isFontRegular: true,
                textColor: ColorConstants.textYellowFFBB1B,
                textDecoration: TextDecoration.underline,
                decorationColor: ColorConstants.textYellowFFBB1B,
                decorationThickness: 2.0,
                decorationStyle: TextDecorationStyle.solid,
                onClick: onPreSelectedAction,
                fontSize: 14,
              ).expanded(),
            ],
          ).marginOnly(top: 6),

          // 最后操作人员
          Row(
            mainAxisSize: MainAxisSize.max,
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              MyTextView(
                "${"Latest Operated".tr}:",
                isFontRegular: true,
                textColor: ColorConstants.textGrayAECAE5,
                fontSize: 14,
                marginTop: 8,
              ),

              //文本
              Html(
                data: item.lastOperator ?? "",
                style: {
                  "*": Style(
                    color: Colors.white,
                    fontSize: FontSize(14),
                  ),
                  "small": Style(
                    color: ColorConstants.textGrayAECAE5,
                    fontSize: FontSize(12),
                  ),
                  // 你可以为其他HTML标签设置样式
                },
              ).expanded(),
            ],
          ),

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

              //文本
              Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  MyTextView(
                    item.statusShow == null ? "" : item.statusShow!.tr,
                    marginLeft: 5,
                    isFontRegular: true,
                    textColor: "Approved" == item.statusShow
                        ? ColorConstants.textGreen05DC82
                        : "Rejected" == item.statusShow
                            ? ColorConstants.textRedFF6262
                            : "Recall" == item.statusShow
                                ? ColorConstants.textYellowFFBB1B
                                : ColorConstants.textBlue06D9FF,
                    fontSize: 14,
                  ),
                  Visibility(
                      visible: Utils.isNotEmpty(item.approveBy),
                      child: MyTextView(
                        item.approveBy ?? "-",
                        marginLeft: 5,
                        isFontRegular: true,
                        textColor: ColorConstants.textGrayAECAE5,
                        fontSize: 12,
                      ))
                ],
              ).expanded(),
            ],
          ),

          //按钮组
          Visibility(
            visible: true,
            child: Row(
              mainAxisSize: MainAxisSize.max,
              mainAxisAlignment: MainAxisAlignment.end,
              crossAxisAlignment: CrossAxisAlignment.center,
              children: [
                //详情按钮
                Visibility(
                  visible: item.status != 4,
                  child: MyButton(
                    onPressed: () {
                      FocusScope.of(context).unfocus();
                      onDetailAction?.call();
                    },
                    text: "Detail".tr,
                    textColor: ColorConstants.white,
                    backgroundColor: hexToColor("#56AAFF"),
                    radius: 17.25,
                    padding: const EdgeInsets.symmetric(horizontal: 8),
                    minWidth: 50,
                    minHeight: 35,
                  ).marginOnly(left: 10),
                ),

                Visibility(
                  visible: item.status == 4,
                  child: MyButton(
                    onPressed: () {
                      FocusScope.of(context).unfocus();
                      onDeleteAction?.call();
                    },
                    text: "Delete".tr,
                    textColor: ColorConstants.white,
                    backgroundColor: hexToColor("#56AAFF"),
                    radius: 17.25,
                    padding: const EdgeInsets.symmetric(horizontal: 8),
                    minWidth: 50,
                    minHeight: 35,
                  ).marginOnly(left: 10),
                ),

                //Att 附件
                Visibility(
                  visible: true,
                  child: MyButton(
                    onPressed: () {
                      FocusScope.of(context).unfocus();
                      onAttAction?.call();
                    },
                    text: "Att(${item.attNum})",
                    textColor: ColorConstants.white,
                    backgroundColor: hexToColor("#CA28E4"),
                    radius: 17.25,
                    padding: const EdgeInsets.symmetric(horizontal: 8),
                    minWidth: 50,
                    minHeight: 35,
                  ).marginOnly(left: 10),
                ),

                //Recall按钮 (Pending)
                Visibility(
                  visible: item.status == 1,
                  child: MyButton(
                    onPressed: () {
                      FocusScope.of(context).unfocus();
                      onRecallAction?.call();
                    },
                    text: "Recall".tr,
                    textColor: ColorConstants.white,
                    backgroundColor: hexToColor("#FFBB1B"),
                    radius: 17.25,
                    padding: const EdgeInsets.symmetric(horizontal: 8),
                    minWidth: 50,
                    minHeight: 35,
                  ).marginOnly(left: 10),
                ),

                //Edit按钮 (Recall)
                Visibility(
                  visible: item.status == 4 || item.status == 3,
                  child: MyButton(
                    onPressed: () {
                      FocusScope.of(context).unfocus();
                      onEditAction?.call();
                    },
                    text: "Edit".tr,
                    textColor: ColorConstants.white,
                    backgroundColor: hexToColor("#FFBB1B"),
                    radius: 17.25,
                    padding: const EdgeInsets.symmetric(horizontal: 8),
                    minWidth: 50,
                    minHeight: 35,
                  ).marginOnly(left: 10),
                ),

                //状态工作流按钮
                Visibility(
                  visible: true,
                  child: MyButton(
                    onPressed: () {
                      FocusScope.of(context).unfocus();
                      onStatusAction?.call();
                    },
                    text: "Status".tr,
                    textColor: ColorConstants.white,
                    backgroundColor: hexToColor("#0AC074"),
                    radius: 17.25,
                    padding: const EdgeInsets.symmetric(horizontal: 8),
                    minWidth: 50,
                    minHeight: 35,
                  ).marginOnly(left: 10),
                ),
              ],
            ).marginOnly(top: 6, bottom: 2),
          ),
        ],
      ),
    );
  }
}
