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

class ReportLabourItem extends StatelessWidget {
  LabourReportEntity? entity; //主体数据
  int type; //0 Completed  1 Incomplete  2 Completed + Incomplete

  ReportLabourItem({
    required this.entity,
    required this.type,
  });

  @override
  Widget build(BuildContext context) {
    return Container(
      width: double.infinity,
      padding: const EdgeInsets.only(top: 16, bottom: 20),
      margin: const EdgeInsets.symmetric(vertical: 5, horizontal: 15),
      decoration: BoxDecoration(
        color: const Color(0xFF4DCFF6).withOpacity(0.2), // 设置背景颜色和不透明度
        borderRadius: BorderRadius.circular(5), // 设置圆角
      ),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          MyTextView(
            type == 0
                ? "Completed".tr
                : type == 1
                    ? "Incomplete".tr
                    : "Completed + Incomplete".tr,
            fontSize: 14,
            isFontBold: true,
            marginBottom: 15,
            marginLeft: 20,
            marginRight: 20,
            textColor: type == 0
                ? ColorConstants.textGreen0AC074
                : type == 1
                    ? ColorConstants.textBlue06D9FF
                    : ColorConstants.textRedFF6262,
          ),
          const Divider(height: 0.5, color: ColorConstants.dividerBar),

          Row(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              MyTextView(
                "Outlet".tr,
                fontSize: 14,
                textColor: Colors.white,
                isFontRegular: true,
              ).expanded(),
              Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  MyTextView("Hours".tr, textColor: Colors.white, fontSize: 14, isFontRegular: true),
                  MyTextView(
                    "(${entity?.total?.hrs})",
                    textColor: type == 0
                        ? ColorConstants.textGreen0AC074
                        : type == 1
                            ? ColorConstants.textBlue06D9FF
                            : ColorConstants.textRedFF6262,
                    fontSize: 14,
                    isFontRegular: true,
                  ),
                ],
              ).expanded(),
              Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  MyTextView("TotalAmt".tr, textColor: Colors.white, fontSize: 14, isFontRegular: true),
                  MyTextView(
                    "(${entity?.total?.agAmt})",
                    textColor: type == 0
                        ? ColorConstants.textGreen0AC074
                        : type == 1
                            ? ColorConstants.textBlue06D9FF
                            : ColorConstants.textRedFF6262,
                    fontSize: 14,
                    isFontRegular: true,
                  ),
                ],
              ).expanded(),
            ],
          ).marginOnly(left: 20, right: 20, top: 18, bottom: 2),

          //底部的实际数据
          ...(entity?.rows.map((item) {
                return _childItem(
                  item.outletName,
                  type == 0
                      ? item.hrs
                      : type == 1
                          ? item.inHrs
                          : item.totHrs,
                  type == 0
                      ? item.agAmt
                      : type == 1
                          ? item.inAgAmt
                          : item.totAgAmt,
                );
              }).toList() ??
              []),
        ],
      ),
    );
  }

  Widget _childItem(String? outletName, String? hours, String? agAmt) {
    return Row(
      children: [
        MyTextView(
          outletName ?? "",
          fontSize: 14,
          textColor: Colors.white,
          isFontRegular: true,
        ).expanded(),
        MyTextView(
          "$hours H",
          fontSize: 14,
          textColor: Colors.white,
          isFontRegular: true,
        ).expanded(),
        MyTextView(
          "\$ $agAmt",
          fontSize: 14,
          textColor: Colors.white,
          isFontRegular: true,
        ).expanded(),
      ],
    ).marginOnly(top: 16, left: 20, right: 20);
  }
}
