import 'package:ef/ef.dart';
import 'package:fl_chart/fl_chart.dart';
import 'package:flutter/material.dart';
import 'package:vbvs_app/common/color/appConstants.dart';
import 'package:vbvs_app/common/util/FitTool.dart';
import 'package:vbvs_app/common/util/MyUtils.dart';

class SleepRadarChart extends StatelessWidget {
  final List<Map<String, dynamic>> data;

  const SleepRadarChart({Key? key, required this.data}) : super(key: key);

  // const SleepRadarChart({
  //   Key? key,
  //   required this.today,
  //   required this.yesterday,
  // }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
      padding: const EdgeInsets.all(16),
      child: Column(
        children: [
          // 雷达图
          _buildRadarChart(),
        ],
      ),
    );
  }

  Widget _buildRadarChart() {
    return AspectRatio(
      aspectRatio: 1.3,
      child: RadarChart(
        RadarChartData(
          dataSets: [
            // 今日数据
            RadarDataSet(
              dataEntries: data
                  .map((e) => RadarEntry(value: (e['t'] as num).toDouble()))
                  .toList(),
              borderColor: stringToColor("#00C1AA"),
              borderWidth: 2,
              fillColor: Colors.transparent,
              entryRadius: 0,
            ),
            // 昨日数据
            RadarDataSet(
              dataEntries: data
                  .map((e) => RadarEntry(value: (e['y'] as num).toDouble()))
                  .toList(),
              borderColor: stringToColor("#FFD251"),
              borderWidth: 2,
              fillColor: Colors.transparent,
              entryRadius: 0,
            ),
          ],
          radarBackgroundColor: stringToColor("#343844").withOpacity(0.6),
          radarBorderData: BorderSide(
              color: themeController.currentColor.sc4, width: 0.5.rpx),
          radarShape: RadarShape.polygon,
          titlePositionPercentageOffset: 0.2,
          titleTextStyle: TextStyle(
              fontSize: AppConstants().normal_text_fontSize,
              color: themeController.currentColor.sc3),
          getTitle: (index, angle) {
            return RadarChartTitle(text: data[index]['name'] ?? '未知'.tr);
          },
          tickCount: 5,
          ticksTextStyle:
              const TextStyle(color: Colors.transparent, fontSize: 10),
          gridBorderData: BorderSide(color: Colors.transparent, width: 1),
          tickBorderData: BorderSide(
              color: themeController.currentColor.sc4, width: 0.5.rpx),
        ),
        swapAnimationDuration: const Duration(milliseconds: 400),
      ),
    );
  }
}
