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

class DeviceControlBlock extends StatefulWidget {
  final bool mainPowerOn;
  final List<Map<String, dynamic>> deviceControls;
  final List<Map<String, dynamic>> devices;

  const DeviceControlBlock({
    super.key,
    required this.mainPowerOn,
    required this.deviceControls,
    required this.devices,
  });

  @override
  State<DeviceControlBlock> createState() => _DeviceControlBlockState();
}

class _DeviceControlBlockState extends State<DeviceControlBlock> {
  @override
  Widget build(BuildContext context) {
    return Container(
      width: double.infinity,
      padding: EdgeInsets.all(20.w),
      decoration: BoxDecoration(
        borderRadius: BorderRadius.circular(24.r),
        color: Colors.white,
      ),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              Text(
                '设备控制',
                style: TextStyle(
                  fontSize: 28.sp,
                  fontWeight: FontWeight.bold,
                  color: const Color.fromRGBO(31, 41, 55, 1),
                ),
              ),
              FlutterSwitch(
                value: widget.mainPowerOn,
                onToggle: (value) {},
                activeColor: const Color.fromRGBO(59, 130, 246, 1),
                inactiveColor: const Color.fromRGBO(209, 213, 219, 1),
                width: 60.w,
                height: 30.h,
                toggleSize: 26,
              ),
            ],
          ),
          SizedBox(height: 20.h),
          ...widget.devices.map((device) {
            return Container(
              margin: EdgeInsets.only(bottom: 12.h),
              padding: EdgeInsets.all(16.w),
              decoration: BoxDecoration(
                color: const Color.fromRGBO(249, 250, 251, 1),
                borderRadius: BorderRadius.circular(16.r),
              ),
              child: Row(
                children: [
                  Icon(
                    device['icon'] as IconData,
                    color: const Color.fromRGBO(107, 114, 128, 1),
                    size: 28.sp,
                  ),
                  SizedBox(width: 12.w),
                  Expanded(
                    child: Text(
                      device['name'] as String,
                      style: TextStyle(
                        fontSize: 24.sp,
                        color: const Color.fromRGBO(31, 41, 55, 1),
                      ),
                    ),
                  ),
                  Text(
                    device['status'] as String,
                    style: TextStyle(
                      fontSize: 22.sp,
                      color: const Color.fromRGBO(107, 114, 128, 1),
                    ),
                  ),
                ],
              ),
            );
          }).toList(),
        ],
      ),
    );
  }
}