import 'package:cs_resources/constants/color_constants.dart';
import 'package:cs_resources/generated/assets.dart';
import 'package:domain/entity/response/t_h_applied_index_entity.dart';
import 'package:domain/entity/response/t_h_applied_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:plugin_basic/service/app_config_service.dart';
import 'package:plugin_platform/engine/image/image_preview.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 AppliedErItem extends StatelessWidget {
  final int index;
  final THAppliedIndexEntity? jobInfo;
  final THAppliedTableRows item;
  final VoidCallback? onStatusAction;
  final VoidCallback? onEditAction;
  final VoidCallback? onRemarkAction;
  final VoidCallback? onItemAction;
  final VoidCallback? onMemberAction;

  AppliedErItem({
    required this.index,
    required this.item,
    required this.jobInfo,
    this.onStatusAction,
    this.onRemarkAction,
    this.onEditAction,
    this.onItemAction,
    this.onMemberAction,
  });

  @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: [
          //员工姓名
          Row(
            mainAxisSize: MainAxisSize.max,
            crossAxisAlignment: CrossAxisAlignment.center,
            children: [
              MyTextView(
                "Name:".tr,
                isFontRegular: true,
                textColor: ColorConstants.textGrayAECAE5,
                fontSize: 14,
              ),

              Row(
                children: [
                  //姓名
                  MyTextView(
                    item.labourerName ?? "-",
                    isFontMedium: true,
                    textColor: ColorConstants.textYellowFFBB1B,
                    fontSize: 14,
                    marginLeft: 5,
                    marginRight: 10,
                    textDecoration: TextDecoration.underline,
                    decorationColor: ColorConstants.textYellowFFBB1B,
                    // 可选，设置下划线的颜色
                    decorationThickness: 2.0,
                    // 可选，设置下划线的粗细
                    decorationStyle: TextDecorationStyle.solid,
                    onClick: onMemberAction,
                  ),

                  //头像
                  Hero(
                    tag: '112cc8a34e13',
                    child: MyLoadImage(
                      item.avatar,
                      width: 22,
                      height: 22,
                    ),
                  ).onTap(() {
                    if (Utils.isNotEmpty(item.avatar)) {
                      ImagePreviewEngine.singleImagePreview(context, item.avatar ?? "", heroTag: '112cc8a34e13');
                    }
                  }),
                ],
              ).expanded(),

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

          Row(
            children: [
              Row(
                mainAxisSize: MainAxisSize.min,
                children: [
                  MyTextView(
                    "Status:".tr,
                    isFontRegular: true,
                    textColor: ColorConstants.textGrayAECAE5,
                    fontSize: 14,
                  ),
                  MyTextView(
                    item.statusShow ?? "-",
                    isFontRegular: true,
                    textColor: "Completed" == item.statusShow
                        ? ColorConstants.textGreen05DC82
                        : "Cancelled" == item.statusShow || "Rejected" == item.statusShow
                            ? ColorConstants.textRedFF6262
                            : "Revised" == item.statusShow || "Pending" == item.statusShow || "Approve" == item.statusShow
                                ? ColorConstants.textYellowFFBB1B
                                : ColorConstants.textBlue06D9FF, //默认蓝色
                    fontSize: 14,
                  )
                ],
              ).expanded(),
              const SizedBox(width: 10),
              MyTextView(
                item.clothingSize ?? "-",
                isFontMedium: true,
                textColor: ColorConstants.textYellowFFBB1B,
                fontSize: 14,
                textDecoration: TextDecoration.underline,
                decorationColor: ColorConstants.textYellowFFBB1B,
                // 可选，设置下划线的颜色
                decorationThickness: 2.0,
                // 可选，设置下划线的粗细
                decorationStyle: TextDecorationStyle.solid,
              ).expanded(),
            ],
          ).marginOnly(top: 6),

          // 工作开始时间,结束时间
          Row(
            children: [
              //开始时间
              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(),
                ],
              ).expanded(),

              const SizedBox(width: 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(),
                ],
              ).expanded(),
            ],
          ).marginOnly(top: 6),

          //门卫签到
          Row(
            children: [
              // 门卫签到时间
              Row(
                mainAxisSize: MainAxisSize.max,
                crossAxisAlignment: CrossAxisAlignment.center,
                children: [
                  MyTextView(
                    "Security In:".tr,
                    isFontRegular: true,
                    textColor: ColorConstants.textGrayAECAE5,
                    fontSize: 14,
                  ),

                  //时间
                  MyTextView(
                    item.securityIn?.time ?? "-",
                    marginLeft: 5,
                    isFontRegular: true,
                    textColor: item.securityIn?.changed == 1 ? ColorConstants.textRedFF6262 : ColorConstants.textGreen0AC074,
                    fontSize: 14,
                    onClick: () {
                      if (Utils.isNotEmpty(item.securityIn?.image)) {
                        ImagePreviewEngine.singleImagePreview(context, item.securityIn!.image!);
                      }
                    },
                    textDecoration: Utils.isNotEmpty(item.securityIn?.image) ? TextDecoration.underline : TextDecoration.none,
                    decorationColor: ColorConstants.textGreen0AC074,
                    decorationThickness: 2.0,
                    decorationStyle: TextDecorationStyle.solid,
                  ).expanded(),
                ],
              ).expanded(),

              const SizedBox(width: 10),

              // 门卫签出时间
              Row(
                mainAxisSize: MainAxisSize.max,
                crossAxisAlignment: CrossAxisAlignment.center,
                children: [
                  MyTextView(
                    "Security Out:".tr,
                    isFontRegular: true,
                    textColor: ColorConstants.textGrayAECAE5,
                    fontSize: 14,
                  ),

                  //时间
                  MyTextView(
                    item.securityOut?.time ?? "-",
                    marginLeft: 5,
                    isFontRegular: true,
                    textColor: item.securityOut?.changed == 1 ? ColorConstants.textRedFF6262 : ColorConstants.textYellowF8AE00,
                    fontSize: 14,
                    onClick: () {
                      if (Utils.isNotEmpty(item.securityOut?.image)) {
                        ImagePreviewEngine.singleImagePreview(context, item.securityOut!.image!);
                      }
                    },
                    textDecoration: Utils.isNotEmpty(item.securityOut?.image) ? TextDecoration.underline : TextDecoration.none,
                    decorationColor: ColorConstants.textYellowF8AE00,
                    decorationThickness: 2.0,
                    decorationStyle: TextDecorationStyle.solid,
                  ).expanded(),
                ],
              ).expanded(),
            ],
          ).marginOnly(top: 6),

          //工作地签到
          Row(
            children: [
              // 工作地签到时间
              Row(
                mainAxisSize: MainAxisSize.max,
                crossAxisAlignment: CrossAxisAlignment.center,
                children: [
                  MyTextView(
                    "Work In:".tr,
                    isFontRegular: true,
                    textColor: ColorConstants.textGrayAECAE5,
                    fontSize: 14,
                  ),

                  //时间
                  MyTextView(
                    item.workIn?.time ?? "-",
                    marginLeft: 5,
                    isFontRegular: true,
                    textColor: item.workIn?.changed == 1 ? ColorConstants.textRedFF6262 : ColorConstants.textGreen0AC074,
                    fontSize: 14,
                    onClick: () {
                      if (Utils.isNotEmpty(item.workIn?.image)) {
                        ImagePreviewEngine.singleImagePreview(context, item.workIn!.image!);
                      }
                    },
                    textDecoration: Utils.isNotEmpty(item.workIn?.image) ? TextDecoration.underline : TextDecoration.none,
                    decorationColor: ColorConstants.textGreen0AC074,
                    decorationThickness: 2.0,
                    decorationStyle: TextDecorationStyle.solid,
                  ).expanded(),
                ],
              ).expanded(),

              const SizedBox(width: 10),

              // 工作地签出时间
              Row(
                mainAxisSize: MainAxisSize.max,
                crossAxisAlignment: CrossAxisAlignment.center,
                children: [
                  MyTextView(
                    "Work Out:".tr,
                    isFontRegular: true,
                    textColor: ColorConstants.textGrayAECAE5,
                    fontSize: 14,
                  ),

                  //时间
                  MyTextView(
                    item.workOut?.time ?? "-",
                    marginLeft: 5,
                    isFontRegular: true,
                    textColor: item.workOut?.changed == 1 ? ColorConstants.textRedFF6262 : ColorConstants.textYellowF8AE00,
                    fontSize: 14,
                    onClick: () {
                      if (Utils.isNotEmpty(item.workOut?.image)) {
                        ImagePreviewEngine.singleImagePreview(context, item.workOut!.image!);
                      }
                    },
                    textDecoration: Utils.isNotEmpty(item.workOut?.image) ? TextDecoration.underline : TextDecoration.none,
                    decorationColor: ColorConstants.textYellowF8AE00,
                    decorationThickness: 2.0,
                    decorationStyle: TextDecorationStyle.solid,
                  ).expanded(),
                ],
              ).expanded(),
            ],
          ).marginOnly(top: 6),

          //工作时长
          Row(
            children: [
              // + - Hours
              Row(
                mainAxisSize: MainAxisSize.max,
                crossAxisAlignment: CrossAxisAlignment.center,
                children: [
                  MyTextView(
                    "+/- Hours:".tr,
                    isFontRegular: true,
                    textColor: ColorConstants.textGrayAECAE5,
                    fontSize: 14,
                  ),

                  //小时
                  MyTextView(
                    item.adjustHours ?? "0",
                    marginLeft: 5,
                    isFontRegular: true,
                    textColor: Colors.white,
                    fontSize: 14,
                  ).expanded(),
                ],
              ).expanded(),

              const SizedBox(width: 10),

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

                  //小时
                  MyTextView(
                    item.totalHours ?? "0",
                    marginLeft: 5,
                    isFontRegular: true,
                    textColor: Colors.white,
                    fontSize: 14,
                  ).expanded(),
                ],
              ).expanded(),
            ],
          ).marginOnly(top: 6),

          //按钮组
          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();
                      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),
                ),

                //Remark按钮
                Visibility(
                  visible: true,
                  child: MyButton(
                    onPressed: () {
                      FocusScope.of(context).unfocus();
                      onRemarkAction?.call();
                    },
                    text: "Remarks".tr,
                    textColor: ColorConstants.white,
                    backgroundColor: hexToColor("#56AAFF"),
                    radius: 17.25,
                    minWidth: 60,
                    minHeight: 35,
                  ).marginOnly(left: 12),
                ),
              ],
            ).marginOnly(top: 4),
          ),
        ],
      ).onTap(() {
        onItemAction?.call();
      }),
    );
  }
}
