import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:smart_hotel_app/views/report/device/cubit/device_list_state.dart';

class DeviceCard extends StatelessWidget {
  final DeviceInfo device;

  const DeviceCard({
    super.key,
    required this.device,
  });

  IconData _getIconForType(DeviceTypeEnum type) {
    switch (type) {
      case DeviceTypeEnum.smartBreaker:
        return Icons.power;
      case DeviceTypeEnum.guestControl:
        return Icons.settings_remote;
      case DeviceTypeEnum.network:
        return Icons.wifi;
      default:
        return Icons.devices;
    }
  }

  Color _getIconColor(DeviceTypeEnum type) {
    switch (type) {
      case DeviceTypeEnum.smartBreaker:
        return const Color.fromRGBO(245, 158, 11, 1);
      case DeviceTypeEnum.guestControl:
        return const Color.fromRGBO(59, 130, 246, 1);
      case DeviceTypeEnum.network:
        return const Color.fromRGBO(16, 185, 129, 1);
      default:
        return const Color.fromRGBO(107, 114, 128, 1);
    }
  }

  String _getTypeLabel(DeviceTypeEnum type) {
    switch (type) {
      case DeviceTypeEnum.smartBreaker:
        return '智能空开';
      case DeviceTypeEnum.guestControl:
        return '客控设备';
      case DeviceTypeEnum.network:
        return '网络设备';
      default:
        return '其他';
    }
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      width: double.infinity,
      padding: EdgeInsets.all(28.w),
      decoration: BoxDecoration(
        borderRadius: BorderRadius.circular(24.r),
        color: Colors.white,
      ),
      child: Row(
        children: [
          Container(
            width: 80.w,
            height: 80.h,
            decoration: BoxDecoration(
              borderRadius: BorderRadius.circular(16.r),
              color: _getIconColor(device.type).withOpacity(0.1),
            ),
            child: Icon(
              _getIconForType(device.type),
              color: _getIconColor(device.type),
              size: 36.sp,
            ),
          ),
          SizedBox(width: 20.w),
          Expanded(
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Text(
                  device.name,
                  style: TextStyle(
                    fontSize: 26.sp,
                    fontWeight: FontWeight.bold,
                    color: const Color.fromRGBO(31, 41, 55, 1),
                  ),
                ),
                SizedBox(height: 8.h),
                Row(
                  children: [
                    Text(
                      _getTypeLabel(device.type),
                      style: TextStyle(
                        fontSize: 20.sp,
                        color: const Color.fromRGBO(107, 114, 128, 1),
                      ),
                    ),
                    SizedBox(width: 16.w),
                    Text(
                      '房间 ${device.room}',
                      style: TextStyle(
                        fontSize: 20.sp,
                        color: const Color.fromRGBO(107, 114, 128, 1),
                      ),
                    ),
                  ],
                ),
              ],
            ),
          ),
          Column(
            crossAxisAlignment: CrossAxisAlignment.end,
            children: [
              Container(
                padding: EdgeInsets.symmetric(horizontal: 16.w, vertical: 8.h),
                decoration: BoxDecoration(
                  borderRadius: BorderRadius.circular(12.r),
                  color: device.online
                      ? const Color.fromRGBO(220, 252, 231, 1)
                      : const Color.fromRGBO(254, 226, 226, 1),
                ),
                child: Text(
                  device.status,
                  style: TextStyle(
                    fontSize: 20.sp,
                    color: device.online
                        ? const Color.fromRGBO(21, 128, 61, 1)
                        : const Color.fromRGBO(220, 38, 38, 1),
                    fontWeight: FontWeight.bold,
                  ),
                ),
              ),
              SizedBox(height: 8.h),
              Text(
                device.lastUpdate,
                style: TextStyle(
                  fontSize: 18.sp,
                  color: const Color.fromRGBO(156, 163, 175, 1),
                ),
              ),
            ],
          ),
        ],
      ),
    );
  }
}
