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

class DeviceOverviewCard extends StatelessWidget {
  final String deviceName;
  final String deviceType;
  final String deviceStatus;
  final String deviceModel;
  final String installLocation;
  final String area;
  final String responsiblePerson;
  final String lastInspectionTime;
  final IconData icon;

  const DeviceOverviewCard({
    super.key,
    required this.deviceName,
    required this.deviceType,
    required this.deviceStatus,
    required this.deviceModel,
    required this.installLocation,
    required this.area,
    required this.responsiblePerson,
    required this.lastInspectionTime,
    required this.icon,
  });

  @override
  Widget build(BuildContext context) {
    return Container(
      decoration: BoxDecoration(
        color: Colors.white,
        borderRadius: BorderRadius.circular(20.r),
      ),
      padding: EdgeInsets.symmetric(horizontal: 20.w, vertical: 24.h),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Row(
            spacing: 20.w,
            children: [
              Container(
                width: 90.w,
                height: 90.h,
                decoration: const BoxDecoration(
                  color: Color.fromRGBO(235, 244, 255, 1.0),
                  shape: BoxShape.circle,
                ),
                child: Icon(
                  icon,
                  color: const Color.fromRGBO(66, 165, 245, 1.0),
                  size: 40.sp,
                ),
              ),
              Expanded(
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  spacing: 5.h,
                  children: [
                    Text(
                      deviceName,
                      style: TextStyle(
                        fontSize: 36.sp,
                        fontWeight: FontWeight.bold,
                        color: const Color.fromRGBO(10, 13, 20, 1.0),
                      ),
                    ),
                    Text(
                      deviceType,
                      style: TextStyle(
                        fontSize: 28.sp,
                        color: const Color.fromRGBO(100, 116, 139, 1.0),
                      ),
                    ),
                  ],
                ),
              ),
            ],
          ),
          Container(
            margin: EdgeInsets.only(left: 110.w, top: 5.h),
            padding: EdgeInsets.symmetric(horizontal: 12.w, vertical: 4.h),
            decoration: BoxDecoration(
              color: deviceStatus == '1'
                  ? const Color.fromRGBO(209, 250, 229, 1.0)
                  : const Color.fromRGBO(255, 235, 238, 1.0),
              borderRadius: BorderRadius.circular(40.r),
            ),
            child: Text(
              deviceStatus == '1' ? '在线' : '离线',
              style: TextStyle(
                fontSize: 24.sp,
                color: deviceStatus == '1'
                    ? const Color.fromRGBO(20, 184, 166, 1.0)
                    : const Color.fromRGBO(231, 76, 60, 1.0),
              ),
            ),
          ),
          SizedBox(height: 32.h),
          Text(
            '基本信息',
            style: TextStyle(
              fontSize: 32.sp,
              fontWeight: FontWeight.bold,
              color: const Color.fromRGBO(10, 13, 20, 1.0),
            ),
          ),
          SizedBox(height: 24.h),
          _buildInfoItem('设备型号', deviceModel),
          SizedBox(height: 24.h),
          _buildInfoItem('安装位置', installLocation),
          SizedBox(height: 24.h),
          _buildInfoItem('所属区域', area),
          SizedBox(height: 24.h),
          _buildInfoItem('责任人', responsiblePerson),
          SizedBox(height: 24.h),
          _buildInfoItem('最后巡检', lastInspectionTime),
        ],
      ),
    );
  }

  Widget _buildInfoItem(String label, String value) {
    return Row(
      mainAxisAlignment: MainAxisAlignment.spaceBetween,
      children: [
        Text(
          label,
          style: TextStyle(
            fontSize: 28.sp,
            color: const Color.fromRGBO(100, 116, 139, 1.0),
          ),
        ),
        Text(
          value.isNotEmpty ? value : '--',
          style: TextStyle(
            fontSize: 28.sp,
            color: const Color.fromRGBO(100, 116, 139, 1.0),
          ),
        ),
      ],
    );
  }
}
