import 'package:cpt_sg/modules/agency/agency_add/agency_add_page.dart';
import 'package:cs_resources/constants/color_constants.dart';
import 'package:domain/entity/response/staff_request_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:shared/utils/util.dart';
import 'package:widgets/ext/ex_widget.dart';

import 'package:widgets/my_text_view.dart';
import 'package:widgets/shatter/custom_progress_bar.dart';

class ReportStaffRequestItem extends StatelessWidget {
  final StaffRequestReportEntity item;

  ReportStaffRequestItem({
    required this.item,
  });

  @override
  Widget build(BuildContext context) {
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        Row(
          mainAxisSize: MainAxisSize.max,
          children: [
            MyTextView(
              item.name ?? "",
              fontSize: 14,
              textColor: Colors.white,
              isFontRegular: true,
            ).expanded(),
            MyTextView(
              "(${item.num})",
              marginLeft: 3,
              textColor: ColorConstants.textYellowF8AE00,
              fontSize: 14,
              isFontRegular: true,
            ),
          ],
        ),
        CustomProgressBar(
          progress: _convertProgress(item.ratio),
          color: item.bg == "rec-primary"
              ? hexToColor("#228FFE")
              : item.bg == "rec-success"
                  ? hexToColor("#01A5A7")
                  : item.bg == "rec-warning"
                      ? hexToColor("#E0A721")
                      : item.bg == "rec-orange"
                          ? hexToColor("#DD592C")
                          : item.bg == "rec-danger"
                              ? hexToColor("#FE3737")
                              : hexToColor("#943EFF"),
        ).marginOnly(top: 6),
      ],
    ).paddingOnly(left: 22.5, right: 22.5, top: 8, bottom: 8);
  }

  // 进度的转换
  double _convertProgress(String? percentageString) {
    try {
      if (Utils.isEmpty(percentageString)) {
        return 0.0;
      }

      // 去掉百分号
      String cleanedString = percentageString!.replaceAll('%', '');

      // 将字符串转换为 double
      return double.parse(cleanedString) / 100;
    } catch (e) {
      print('转换失败: $e');
      return 0.0;
    }
  }
}
