import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:smart_hotel_app/views/home/device/cubit/device_state.dart';

class DeviceParmsBlock extends StatelessWidget {
  final DeviceInfo deviceInfo;

  const DeviceParmsBlock({super.key, required this.deviceInfo});

  @override
  Widget build(BuildContext context) {
    return Container(
      width: double.infinity,
      margin: EdgeInsets.only(top: 10.h),
      padding: EdgeInsets.all(25.w),
      decoration: BoxDecoration(
        borderRadius: BorderRadius.circular(25.r),
        color: Colors.white,
      ),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Text(
            '实时参数',
            style: TextStyle(
              fontSize: 28.sp,
              color: Colors.black,
              fontWeight: FontWeight.bold,
            ),
          ),
          SizedBox(height: 20.h),
          Row(
            children: [
              Expanded(
                child: _buildParamCard(deviceInfo.voltage, '电压'),
              ),
              SizedBox(width: 15.w),
              Expanded(
                child: _buildParamCard(deviceInfo.current, '电流'),
              ),
            ],
          ),
          SizedBox(height: 15.h),
          Row(
            children: [
              Expanded(
                child: _buildParamCard(deviceInfo.power, '有功功率', isGreen: true),
              ),
              SizedBox(width: 15.w),
              Expanded(
                child: _buildParamCard(deviceInfo.temperature, '设备温度'),
              ),
            ],
          ),
        ],
      ),
    );
  }

  Widget _buildParamCard(String value, String label, {bool isGreen = false}) {
    return Container(
      padding: EdgeInsets.all(25.w),
      decoration: BoxDecoration(
        borderRadius: BorderRadius.circular(25.r),
        color: Color.fromRGBO(229, 241, 255, 1),
      ),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Text(
            value,
            style: TextStyle(
              fontSize: 40.sp,
              color: isGreen ? Color.fromRGBO(20, 184, 166, 1) : Color.fromRGBO(73, 149, 234, 1),
              fontWeight: FontWeight.bold,
            ),
          ),
          SizedBox(height: 8.h),
          Text(
            label,
            style: TextStyle(
              fontSize: 24.sp,
              color: Color.fromRGBO(100, 116, 139, 1),
            ),
          ),
        ],
      ),
    );
  }
}