import 'package:cpt_sg/modules/agency/agency_add/agency_add_page.dart';
import 'package:cs_resources/constants/color_constants.dart';
import 'package:cs_resources/generated/assets.dart';
import 'package:domain/entity/response/s_g_dashboard_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_load_image.dart';
import 'package:widgets/my_text_view.dart';

/*
 * 中介的各种统计数据
 */
class DashboardItem extends StatelessWidget {
  final int index;
  final SGDashboardAgencyList item;
  void Function(String? agencyId, String? outletId, String? day)? OnItemClickAction;

  DashboardItem({
    required this.index,
    required this.item,
    this.OnItemClickAction,
  });

  @override
  Widget build(BuildContext context) {
    return Container(
      margin: const EdgeInsets.only(left: 15, right: 15, top: 5, bottom: 5),
      child: Column(
        mainAxisSize: MainAxisSize.max,
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          MyTextView(
            "${item.agencyName} (${item.outletName})",
            isFontMedium: true,
            marginBottom: 9,
            textColor: Colors.white,
            fontSize: 14,
          ),

          // 星期中每一天的数据
          GridView.builder(
            padding: EdgeInsets.zero,
            physics: const NeverScrollableScrollPhysics(),
            // 禁用 GridView 的滚动
            shrinkWrap: true,
            // 适应内容高度
            gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
              crossAxisCount: 2, // 每行2个元素
              crossAxisSpacing: 9,
              mainAxisSpacing: 9,
              childAspectRatio: 168 / 50, // 控制子项的宽高比
            ),
            itemCount: item.days.length,
            // 每个 SliverList 项中的网格项数量
            itemBuilder: (BuildContext context, int gridIndex) {
              return Container(
                decoration: BoxDecoration(
                  color: const Color(0xFF4DCFF6).withOpacity(0.2), // 设置背景颜色和不透明度
                  borderRadius: BorderRadius.circular(5), // 设置圆角
                ),
                child: Row(
                  mainAxisSize: MainAxisSize.max,
                  crossAxisAlignment: CrossAxisAlignment.center,
                  mainAxisAlignment: MainAxisAlignment.start,
                  children: [
                    MyAssetImage(
                            item.days[gridIndex].week == "Mon"
                                ? Assets.cptReportWeekNum1
                                : item.days[gridIndex].week == "Tue"
                                    ? Assets.cptReportWeekNum2
                                    : item.days[gridIndex].week == "Wed"
                                        ? Assets.cptReportWeekNum3
                                        : item.days[gridIndex].week == "Thu"
                                            ? Assets.cptReportWeekNum4
                                            : item.days[gridIndex].week == "Fir"
                                                ? Assets.cptReportWeekNum5
                                                : item.days[gridIndex].week == "Sat"
                                                    ? Assets.cptReportWeekNum6
                                                    : Assets.cptReportWeekNum7,
                            width: 25,
                            height: 25)
                        .marginOnly(left: 10),
                    MyTextView(
                      item.days[gridIndex].day ?? "-",
                      fontSize: 12.5,
                      marginLeft: 10,
                      textColor: ColorConstants.textGrayAECAE5,
                      isFontRegular: true,
                    ).expanded(),
                    MyTextView(
                      item.days[gridIndex].num ?? "-",
                      fontSize: 13.5,
                      marginRight: 15,
                      textColor: ColorConstants.textYellowF8AE00,
                      isFontBold: true,
                    ),
                  ],
                ).onTap(() {
                  OnItemClickAction?.call(item.agencyId, item.outletId, item.days[gridIndex].day);
                }),
              );
            },
          ),
        ],
      ),
    );
  }
}
