import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

class EnergyStatsCardBlock extends StatelessWidget {
  final double todayEnergy;
  final double todayEnergyChange;
  final double monthEnergy;
  final double monthEnergyChange;
  final double monthBill;

  const EnergyStatsCardBlock({
    super.key,
    required this.todayEnergy,
    required this.todayEnergyChange,
    required this.monthEnergy,
    required this.monthEnergyChange,
    required this.monthBill,
  });

  @override
  Widget build(BuildContext context) {
    return Padding(
      padding: EdgeInsets.symmetric(horizontal: 16.w),
      child: Row(
        children: [
          Expanded(
            child: _buildCard(
              '${todayEnergy.toInt()}',
              '今日(kwh)',
              '${todayEnergyChange.toInt()}%',
              true,
              const Color.fromRGBO(59, 130, 246, 1),
            ),
          ),
          SizedBox(width: 12.w),
          Expanded(
            child: _buildCard(
              '${monthEnergy.toInt()}',
              '本月(kWh)',
              '${monthEnergyChange.toInt()}%',
              true,
              const Color.fromRGBO(59, 130, 246, 1),
            ),
          ),
          SizedBox(width: 12.w),
          Expanded(
            child: _buildCard(
              '¥${monthBill.toInt()}',
              '本月电费预估',
              null,
              null,
              const Color.fromRGBO(16, 185, 129, 1),
            ),
          ),
        ],
      ),
    );
  }

  Widget _buildCard(String value, String label, String? change, bool? isDown, Color valueColor) {
    return Container(
      padding: EdgeInsets.symmetric(vertical: 24.h, horizontal: 16.w),
      decoration: BoxDecoration(
        color: Colors.white,
        borderRadius: BorderRadius.circular(20.r),
      ),
      child: Column(
        children: [
          Text(
            value,
            style: TextStyle(
              color: valueColor,
              fontSize: 40.sp,
              fontWeight: FontWeight.w500,
            ),
          ),
          SizedBox(height: 4.h),
          Text(
            label,
            style: TextStyle(
              color: Colors.black54,
              fontSize: 24.sp,
            ),
          ),
          SizedBox(height: 4.h),
          if (change != null)
            Row(
              mainAxisAlignment: MainAxisAlignment.center,
              children: [
                Icon(
                  isDown! ? Icons.arrow_downward : Icons.arrow_upward,
                  color: isDown
                      ? const Color.fromRGBO(16, 185, 129, 1)
                      : const Color.fromRGBO(239, 68, 68, 1),
                  size: 24.sp,
                ),
                Text(
                  change,
                  style: TextStyle(
                    color: isDown
                        ? const Color.fromRGBO(16, 185, 129, 1)
                        : const Color.fromRGBO(239, 68, 68, 1),
                    fontSize: 24.sp,
                  ),
                ),
              ],
            )
          else
            SizedBox(height: 24.h),
        ],
      ),
    );
  }
}