import 'package:cs_resources/constants/color_constants.dart';
import 'package:domain/entity/response/job_list_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 JobListItem extends StatelessWidget {
  final int index;
  final JobListRows item;
  final VoidCallback? onDetailAction;
  final VoidCallback? onAppliedAction;

  JobListItem({
    required this.index,
    required this.item,
    this.onDetailAction,
    this.onAppliedAction,
  });

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

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

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

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

              //人数
              MyTextView(
                item.staffShow ?? "",
                marginLeft: 5,
                isFontRegular: true,
                textColor: ColorConstants.textYellowFFBB1B,
                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: "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: 15),

          // 创建时间
          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: 15),

          //按钮组
          Visibility(
            visible: item.actionList?.isNotEmpty ?? false,
            child: Row(
              mainAxisSize: MainAxisSize.max,
              mainAxisAlignment: MainAxisAlignment.end,
              crossAxisAlignment: CrossAxisAlignment.center,
              children: [
                //详情按钮
                Visibility(
                  visible: item.actionList?.contains("detail") ?? false,
                  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),
                ),
              ],
            ).marginOnly(top: 18, bottom: 2),
          ),
        ],
      ),
    ).onTap(() {
      onAppliedAction?.call();
    });
  }
}
