import 'package:cs_resources/constants/color_constants.dart';
import 'package:domain/entity/response/labour_request_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_text_view.dart';

/*
 * 用工请求的主页面列表Item
 */
class LabourRequestItem extends StatelessWidget {
  final int index;
  final String? selectedDate;
  final List<LabourRequestERCountList>? countList;
  final LabourRequestERSourceList item;
  final void Function(String? date)? gotoJobAction;

  LabourRequestItem({
    required this.index,
    required this.selectedDate,
    required this.countList,
    required this.item,
    this.gotoJobAction,
  });

  @override
  Widget build(BuildContext context) {
    final countMap = countList?.fold<Map<String, LabourRequestERCountList>>({}, (map, item) {
        map[item.date??""] = item;
        return map;
      },
    ) ?? {};

    return Container(
      padding: const EdgeInsets.symmetric(vertical: 0, 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(
            children: [
              //日期
              MyTextView(
                'Date'.tr,
                fontSize: 15,
                textColor: Colors.white,
                paddingTop: 15,
                textAlign: TextAlign.center,
                paddingBottom: 15,
                isFontBold: true,
              ).expanded(flex: 55),

              //类型
              MyTextView(
                item.agencyName ?? "-",
                fontSize: 15,
                textColor: Colors.white,
                isFontBold: true,
                textAlign: TextAlign.center,
                paddingTop: 15,
                paddingBottom: 15,
              ).expanded(flex: 45),
            ],
          ),

          const Divider(height: 0.5, color: ColorConstants.dividerItem).marginOnly(bottom: 6),

          //在这里根据Item内部的数组转换为对应的Widget
          if (item.requestList != null && item.requestList!.isNotEmpty)
            ...item.requestList!.map((e) {
              final countItem = countMap[e.date]; // 使用 Map 进行查找
              return Padding(
                padding: const EdgeInsets.symmetric(vertical: 5), // 每项的间距
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    MyTextView(
                      "[${countItem?.week ?? '-'}]${e.date}(${countItem?.num ?? '-'})",
                      fontSize: 15,
                      textColor: selectedDate == e.date ? ColorConstants.textGreen00FB92 : Colors.white,
                      paddingTop: 6,
                      textAlign: TextAlign.center,
                      paddingBottom: 6,
                      isFontRegular: true,
                    ).expanded(flex: 55),

                    //类型
                    MyTextView(
                      e.num ?? "-",
                      fontSize: 15,
                      textColor: ColorConstants.textYellowFFBB1B,
                      isFontRegular: true,
                      textAlign: TextAlign.center,
                      paddingTop: 6,
                      paddingBottom: 6,
                      onClick: (){
                        gotoJobAction?.call(e.date);
                      },
                      //下划线的设置
                      textDecoration: TextDecoration.underline,
                      decorationColor: ColorConstants.textYellowFFBB1B,
                      decorationThickness: 2.0,
                      decorationStyle: TextDecorationStyle.solid, // 可选，设置下划线的样式
                    ).expanded(flex: 45),
                  ],
                ),
              );
            }).toList(),

          const SizedBox(height: 10),
        ],
      ),
    );
  }
}
