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

/*
 * 用工审核的列表Item
 */
class LabourReviewItem extends StatelessWidget {
  final int index;
  final SGLabourReviewTableRows item;
  final VoidCallback? onStatusAction;
  final VoidCallback? onEditAction;
  final VoidCallback? onDetailAction;
  final VoidCallback? onItemAction;

  LabourReviewItem({
    required this.index,
    required this.item,
    this.onStatusAction,
    this.onEditAction,
    this.onDetailAction,
    this.onItemAction,
  });

  @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(
                item.source ?? "-",
                isFontMedium: true,
                textColor: ColorConstants.textYellowFFBB1B,
                fontSize: 14,
                marginLeft: 5,
                marginRight: 5,
                textDecoration: TextDecoration.underline,
                decorationColor: ColorConstants.textYellowFFBB1B,
                // 可选，设置下划线的颜色
                decorationThickness: 2.0,
                // 可选，设置下划线的粗细
                decorationStyle: TextDecorationStyle.solid,
              ).expanded(),

              //是否选中
              MyAssetImage(
                item.isSelected ? Assets.baseServiceItemSelectedIcon : Assets.baseServiceItemUnselectedIcon,
                width: 20.5,
                height: 20.5,
              ),
            ],
          ),

          // 工作日期
          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: 11),

          //工作标题
          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: 11),

          // 部门
          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: 11),

          //工作时间
          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: Colors.white,
                fontSize: 14,
              ).expanded(),
            ],
          ).marginOnly(top: 11),

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

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

          // 状态
          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: 11),

          //按钮组
          Visibility(
            visible: true,
            child: Row(
              mainAxisSize: MainAxisSize.max,
              mainAxisAlignment: MainAxisAlignment.end,
              crossAxisAlignment: CrossAxisAlignment.center,
              children: [
                //详情按钮
                Visibility(
                  visible: true,
                  child: MyButton(
                    onPressed: () {
                      FocusScope.of(context).unfocus();
                      onDetailAction?.call();
                    },
                    text: "Detail".tr,
                    textColor: ColorConstants.white,
                    backgroundColor: hexToColor(
                      "#56AAFF",
                    ),
                    radius: 17.25,
                    minWidth: 60,
                    minHeight: 35,
                  ).marginOnly(left: 12),
                ),

                //Edit按钮
                Visibility(
                  visible: true,
                  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: true,
                  child: MyButton(
                    onPressed: () {
                      FocusScope.of(context).unfocus();
                      onStatusAction?.call();
                    },
                    text: "Status".tr,
                    textColor: ColorConstants.white,
                    backgroundColor: hexToColor("#0AC074"),
                    radius: 17.25,
                    minWidth: 60,
                    minHeight: 35,
                  ).marginOnly(left: 12),
                ),
              ],
            ).marginOnly(top: 18, bottom: 2),
          ),
        ],
      ),
    ).onTap(() {
      onItemAction?.call();
    });
  }
}
