import 'package:cs_resources/constants/color_constants.dart';
import 'package:cs_resources/generated/assets.dart';
import 'package:domain/entity/response/contract_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: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 ContractItem extends StatelessWidget {
  final int index;
  final ContractTableRows item;
  final VoidCallback? onRenewAction;
  final VoidCallback? onDetailAction;
  final VoidCallback? onEditAction;

  ContractItem({
    required this.index,
    required this.item,
    this.onRenewAction,
    this.onDetailAction,
    this.onEditAction,
  });

  @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(
                "${"Agency Name".tr}:",
                isFontRegular: true,
                textColor: ColorConstants.textGrayAECAE5,
                fontSize: 14,
              ),

              //文本
              MyTextView(
                item.agencyName ?? "-",
                marginLeft: 5,
                isFontMedium: true,
                textColor: ColorConstants.textYellowFFBB1B,
                fontSize: 14,
                textDecoration: TextDecoration.underline,
                decorationColor: ColorConstants.textYellowFFBB1B,
                // 可选，设置下划线的颜色
                decorationThickness: 2.0,
                // 可选，设置下划线的粗细
                decorationStyle: TextDecorationStyle.solid, // 可选，设置下划线的样式
              ).expanded(),
            ],
          ),

          // 编码
          Row(
            mainAxisSize: MainAxisSize.max,
            crossAxisAlignment: CrossAxisAlignment.center,
            children: [
              MyTextView(
                "${"ACRA NO".tr}:",
                isFontRegular: true,
                textColor: ColorConstants.textGrayAECAE5,
                fontSize: 14,
              ),

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

          // 负责人
          Row(
            mainAxisSize: MainAxisSize.max,
            crossAxisAlignment: CrossAxisAlignment.center,
            children: [
              MyTextView(
                "${"Person in Charge".tr}:",
                isFontRegular: true,
                textColor: ColorConstants.textGrayAECAE5,
                fontSize: 14,
              ),

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

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

              //文本
              MyTextView(
                item.positionNum.toString(),
                backgroundColor: ColorConstants.textGreen0AC074,
                cornerRadius: 20,
                marginLeft: 5,
                paddingTop: 0,
                paddingLeft: 14,
                paddingRight: 14,
                paddingBottom: 0,
                isFontRegular: true,
                textColor: Colors.white,
                fontSize: 14,
              ),
            ],
          ).marginOnly(top: 12),

          // 合同开始时间
          Row(
            mainAxisSize: MainAxisSize.max,
            crossAxisAlignment: CrossAxisAlignment.center,
            children: [
              MyTextView(
                "${"Contract Start Date".tr}:",
                isFontRegular: true,
                textColor: ColorConstants.textGrayAECAE5,
                fontSize: 14,
              ),

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

          // 合同结束时间
          Row(
            mainAxisSize: MainAxisSize.max,
            crossAxisAlignment: CrossAxisAlignment.center,
            children: [
              MyTextView(
                "${"Contract End Date".tr}:",
                isFontRegular: true,
                textColor: ColorConstants.textGrayAECAE5,
                fontSize: 14,
              ),

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

          // 附件
          Row(
            mainAxisSize: MainAxisSize.max,
            crossAxisAlignment: CrossAxisAlignment.center,
            children: [
              MyTextView(
                "${"Contract".tr}:",
                isFontRegular: true,
                marginRight: 5,
                textColor: ColorConstants.textGrayAECAE5,
                fontSize: 14,
              ),

              //文本
              const MyAssetImage(
                Assets.agencyContractFileIcon,
                width: 15,
                height: 13.5,
              ),
            ],
          ).marginOnly(top: 12),

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

              //状态
              MyTextView(
                1 == item.status
                    ? "Active".tr
                    : 2 == item.status
                        ? "Expired".tr
                        : "-",
                marginLeft: 5,
                isFontRegular: true,
                textColor: 1 == item.status
                    ? ColorConstants.textBlue5CEEFF
                    : 2 == item.status
                        ? ColorConstants.textRedFF6262
                        : ColorConstants.white,
                fontSize: 14,
              ).expanded(),
            ],
          ).marginOnly(top: 12),

          // 创建时间
          Row(
            mainAxisSize: MainAxisSize.max,
            crossAxisAlignment: CrossAxisAlignment.center,
            children: [
              MyTextView(
                "Created At:".tr,
                isFontRegular: true,
                textColor: ColorConstants.textGrayAECAE5,
                fontSize: 14,
              ),

              //文本
              MyTextView(
                "2024-01-01 17:46:19",
                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: [

                //Edit按钮
                Visibility(
                  visible: true,
                  child: MyButton(
                    onPressed: () {
                      FocusScope.of(context).unfocus();
                      onEditAction?.call();
                    },
                    text: "Edit".tr,
                    textColor: ColorConstants.white,
                    backgroundColor: ColorConstants.textGreen0AC074,
                    radius: 17.25,
                    minWidth: 60,
                    minHeight: 35,
                  ).marginOnly(left: 12),
                ),

                // Renew按钮
                Visibility(
                  visible: true,
                  child: MyButton(
                    onPressed: () {
                      FocusScope.of(context).unfocus();
                      onRenewAction?.call();
                    },
                    text: "Renew".tr,
                    textColor: ColorConstants.white,
                    backgroundColor: ColorConstants.textYellowFFBB1B,
                    radius: 17.25,
                    minWidth: 60,
                    minHeight: 35,
                  ).marginOnly(left: 12),
                ),


              ],
            ).marginOnly(top: 15, bottom: 2),
          ),
        ],
      ),
    ).onTap(() {
      FocusScope.of(context).unfocus();
      onDetailAction?.call();
    });
  }
}
