import 'package:cs_resources/constants/color_constants.dart';
import 'package:cs_resources/generated/assets.dart';
import 'package:domain/entity/response/s_g_attendance_review_table_entity.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 AttendanceReviewItem extends StatelessWidget {
  final int index;
  final SGAttendanceReviewTableRows item;
  final VoidCallback? onStatusAction;
  final VoidCallback? onItemAction;
  final void Function(String? img)? onImagePreviewAction;

  AttendanceReviewItem({
    required this.index,
    required this.item,
    this.onStatusAction,
    this.onItemAction,
    this.onImagePreviewAction,
  });

  @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: [
          // Source
          Row(
            mainAxisSize: MainAxisSize.max,
            crossAxisAlignment: CrossAxisAlignment.center,
            children: [
              MyTextView(
                "${"Source".tr}:",
                isFontRegular: true,
                textColor: ColorConstants.textGrayAECAE5,
                fontSize: 14,
              ),
              MyTextView(
                item.source ?? "-",
                marginLeft: 5,
                isFontRegular: true,
                textColor: Colors.white,
                fontSize: 14,
              ).expanded(),

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

            ],
          ).marginOnly(top: 12),

          //员工姓名
          Row(
            mainAxisSize: MainAxisSize.max,
            crossAxisAlignment: CrossAxisAlignment.center,
            children: [
              MyTextView(
                "Staff Name:".tr,
                isFontRegular: true,
                textColor: ColorConstants.textGrayAECAE5,
                fontSize: 14,
              ),

              //姓名
              MyTextView(
                item.staffName ?? "-",
                isFontMedium: true,
                textColor: ColorConstants.white,
                fontSize: 14,
                marginLeft: 5,
                marginRight: 5,
              ).expanded(),
            ],
          ).marginOnly(top: 12),

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


          // 工作时间
          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: 12),


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


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

              //时间
              MyTextView(
                item.workIn?.time ?? "-",
                marginLeft: 5,
                isFontRegular: true,
                textColor: item.workIn?.color == null ? Colors.white : hexToColor(item.workIn!.color!),
                fontSize: 14,
                decorationStyle: item.workIn?.image == null ? null : TextDecorationStyle.solid,
                decorationColor: item.workIn?.color == null ? Colors.white : hexToColor(item.workIn!.color!),
                onClick: (){
                  onImagePreviewAction?.call(item.workIn?.image);
                },
              ).expanded(),
            ],
          ).marginOnly(top: 12),

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

              //时间
              MyTextView(
                item.workOut?.time ?? "-",
                marginLeft: 5,
                isFontRegular: true,
                textColor: item.workOut?.color == null ? Colors.white : hexToColor(item.workOut!.color!),
                fontSize: 14,
                decorationStyle: item.workOut?.image == null ? null : TextDecorationStyle.solid,
                decorationColor: item.workOut?.color == null ? Colors.white : hexToColor(item.workOut!.color!),
                decorationThickness: 2.0,
                onClick: (){
                  onImagePreviewAction?.call(item.workOut?.image);
                },
              ).expanded(),
            ],
          ).marginOnly(top: 12),

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

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

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

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

          // 状态
          Row(
            children: [
              MyTextView(
                "Status:".tr,
                isFontRegular: true,
                textColor: ColorConstants.textGrayAECAE5,
                fontSize: 14,
              ),

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

          //按钮组
          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();
                      onStatusAction?.call();
                    },
                    text: "Status".tr,
                    textColor: ColorConstants.white,
                    backgroundColor: ColorConstants.textGreen0AC074,
                    radius: 17.25,
                    minWidth: 60,
                    minHeight: 35,
                  ).marginOnly(left: 12),
                ),

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