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

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

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

  @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: [
          //工作标题
          MyTextView(
            item.source ?? "-",
            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: 10),

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

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

          // 工作标题
          Row(
            mainAxisSize: MainAxisSize.max,
            crossAxisAlignment: CrossAxisAlignment.center,
            children: [
              MyTextView(
                "${"Job Title".tr}:",
                isFontRegular: true,
                textColor: ColorConstants.textGrayAECAE5,
                fontSize: 14,
              ),

              //文本
              MyTextView(
                item.jobTitle ?? "-",
                marginLeft: 5,
                isFontRegular: true,
                textColor: Colors.white,
                fontSize: 14,
              ).expanded(),
            ],
          ).marginOnly(top: 10),

          // 开始时间
          Row(
            mainAxisSize: MainAxisSize.max,
            crossAxisAlignment: CrossAxisAlignment.center,
            children: [
              MyTextView(
                "${"Start Time".tr}:",
                isFontRegular: true,
                textColor: ColorConstants.textGrayAECAE5,
                fontSize: 14,
              ),

              //文本
              MyTextView(
                item.startTime ?? "-",
                marginLeft: 5,
                isFontRegular: true,
                textColor: Colors.white,
                fontSize: 14,
              ).expanded(),
            ],
          ).marginOnly(top: 10),

          // 结束时间
          Row(
            mainAxisSize: MainAxisSize.max,
            crossAxisAlignment: CrossAxisAlignment.center,
            children: [
              MyTextView(
                "${"End Time".tr}:",
                isFontRegular: true,
                textColor: ColorConstants.textGrayAECAE5,
                fontSize: 14,
              ),

              //文本
              MyTextView(
                item.endTime ?? "-",
                marginLeft: 5,
                isFontRegular: true,
                textColor: Colors.white,
                fontSize: 14,
              ).expanded(),
            ],
          ).marginOnly(top: 10),

          // 人数
          Row(
            mainAxisSize: MainAxisSize.max,
            crossAxisAlignment: CrossAxisAlignment.center,
            children: [
              MyTextView(
                "No. of Staff:".tr,
                isFontRegular: true,
                textColor: ColorConstants.textGrayAECAE5,
                fontSize: 14,
              ),

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

          // 状态
          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: "Approved" == item.statusShow
                    ? ColorConstants.textGreen05DC82
                    : "Rejected" == item.statusShow
                        ? ColorConstants.textRedFF6262
                        : "Recall" == item.statusShow
                            ? ColorConstants.textYellowFFBB1B
                            : ColorConstants.textBlue06D9FF,
                fontSize: 14,
              ).expanded(),
            ],
          ).marginOnly(top: 10),

          // 创建时间
          Row(
            mainAxisSize: MainAxisSize.max,
            crossAxisAlignment: CrossAxisAlignment.center,
            children: [
              MyTextView(
                "Created At:".tr,
                isFontRegular: true,
                textColor: ColorConstants.textGrayAECAE5,
                fontSize: 14,
              ),

              //发布状态
              MyTextView(
                item.createdAt ?? "-",
                marginLeft: 5,
                isFontRegular: true,
                textColor: Colors.white,
                fontSize: 14,
              ).expanded(),
            ],
          ).marginOnly(top: 10),

          //按钮组
          Visibility(
            visible: item.actionList?.isNotEmpty ?? false,
            child: Row(
              mainAxisSize: MainAxisSize.max,
              mainAxisAlignment: MainAxisAlignment.end,
              crossAxisAlignment: CrossAxisAlignment.center,
              children: [
                //详情按钮
                Visibility(
                  visible: item.actionList.contains("detail"),
                  child: MyButton(
                    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: 12),
                ),

                //Delete按钮
                Visibility(
                  visible: item.actionList.contains("delete"),
                  child: MyButton(
                    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: 12),
                ),

                //Recall按钮
                Visibility(
                  visible: item.actionList.contains("recall"),
                  child: MyButton(
                    onPressed: () {
                      FocusScope.of(context).unfocus();
                      onRecallAction?.call();
                    },
                    text: "Recall".tr,
                    textColor: ColorConstants.white,
                    backgroundColor: ColorConstants.textRedFF6262,
                    radius: 17.25,
                    minWidth: 60,
                    minHeight: 35,
                  ).marginOnly(left: 12),
                ),

                //Edit按钮
                Visibility(
                  visible: item.actionList.contains("edit"),
                  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: 12),
                ),

                //工作流
                Visibility(
                  visible: item.actionList.contains("status"),
                  child: MyButton(
                    onPressed: () {
                      FocusScope.of(context).unfocus();
                      onStatusAction?.call();
                    },
                    text: "Status".tr,
                    textColor: ColorConstants.white,
                    backgroundColor: ColorConstants.textBlue56AAFF,
                    radius: 17.25,
                    minWidth: 60,
                    minHeight: 35,
                  ).marginOnly(left: 12),
                ),
              ],
            ).marginOnly(top: 18, bottom: 2),
          ),
        ],
      ),
    );
  }
}
