import 'package:cs_resources/constants/color_constants.dart';
import 'package:domain/entity/response/labour_list_e_r_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 JobListErItem extends StatelessWidget {
  final int index;
  final LabourListERRows item;
  final VoidCallback? onEditAction;
  final VoidCallback? onDeleteAction;
  final VoidCallback? onAppliedAction;
  final VoidCallback? onPreSelectedAction;

  JobListErItem({
    required this.index,
    required this.item,
    this.onEditAction,
    this.onDeleteAction,
    this.onAppliedAction,
    this.onPreSelectedAction,
  });

  @override
  Widget build(BuildContext context) {
    return Container(
      padding: const EdgeInsets.symmetric(vertical: 18, 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,
          ),

          // 部门
          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(
                "Datetime:".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: [
              MyTextView(
                "No. of Staff:".tr,
                isFontRegular: true,
                textColor: ColorConstants.textGrayAECAE5,
                fontSize: 14,
              ),

              //人数
              MyTextView(
                item.hiringNum ?? "",
                marginLeft: 5,
                isFontRegular: true,
                textColor: ColorConstants.textGreen0AC074,
                onClick: onAppliedAction,
                textDecoration: TextDecoration.underline,
                //下拉选
                decorationColor: ColorConstants.textGreen0AC074,
                decorationThickness: 2.0,
                decorationStyle: TextDecorationStyle.solid,
                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 ?? "-",
                marginLeft: 5,
                isFontRegular: true,
                fontSize: 14,
                textColor: ColorConstants.textYellowFFBB1B,
                textDecoration: TextDecoration.underline,
                decorationColor: ColorConstants.textYellowFFBB1B,
                decorationThickness: 2.0,
                decorationStyle: TextDecorationStyle.solid,
                onClick: onPreSelectedAction,
              ).expanded(),
            ],
          ).marginOnly(top: 6),

          // 时薪
          // Row(
          //   mainAxisSize: MainAxisSize.max,
          //   crossAxisAlignment: CrossAxisAlignment.center,
          //   children: [
          //     MyTextView(
          //       "${"Hourly Rate".tr}:",
          //       isFontRegular: true,
          //       textColor: ColorConstants.textGrayAECAE5,
          //       fontSize: 14,
          //     ),
          //
          //     //文本
          //     MyTextView(
          //       item.hiringNum ?? "-",
          //       marginLeft: 5,
          //       isFontRegular: true,
          //       textColor: Colors.white,
          //       fontSize: 14,
          //     ).expanded(),
          //   ],
          // ).marginOnly(top: 6),

          // 状态
          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: "Completed" == item.statusShow
                    ? ColorConstants.textGreen05DC82
                    : "Cancelled" == item.statusShow
                        ? ColorConstants.textRedFF6262
                        : "Revised" == item.statusShow || "Pending" == item.statusShow
                            ? ColorConstants.textYellowFFBB1B
                            : ColorConstants.textBlue06D9FF,
                fontSize: 14,
              ).expanded(),
            ],
          ).marginOnly(top: 6),

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

                //删除按钮
                Visibility(
                  visible: item.actionList.contains("delete"),
                  child: MyButton(
                    onPressed: () {
                      FocusScope.of(context).unfocus();
                      onDeleteAction?.call();
                    },
                    text: "Delete".tr,
                    textColor: ColorConstants.white,
                    backgroundColor: hexToColor(
                      "#DC4462",
                    ),
                    radius: 17.25,
                    minWidth: 60,
                    minHeight: 35,
                  ).marginOnly(left: 12),
                ),
              ],
            ).marginOnly(top: 5),
          ),
        ],
      ),
    ).onTap(() {
      onAppliedAction?.call();
    });
  }
}
