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

class WindSpeedBlock extends StatefulWidget {
  final String currentSpeed;
  final List<String> speedOptions;
  final Function(String) onSetWindSpeed;

  const WindSpeedBlock({
    super.key,
    required this.currentSpeed,
    required this.speedOptions,
    required this.onSetWindSpeed,
  });

  @override
  State<WindSpeedBlock> createState() => _WindSpeedBlockState();
}

class _WindSpeedBlockState extends State<WindSpeedBlock> {
  @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: [
          Text(
            '风速控制',
            style: TextStyle(
              fontSize: 28.sp,
              fontWeight: FontWeight.bold,
              color: const Color.fromRGBO(31, 41, 55, 1),
            ),
          ),
          SizedBox(height: 20.h),
          Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: widget.speedOptions.map((speed) {
              final isSelected = speed == widget.currentSpeed;
              return GestureDetector(
                onTap: () => widget.onSetWindSpeed(speed),
                child: Container(
                  width: 120.w,
                  padding: EdgeInsets.symmetric(vertical: 16.h),
                  decoration: BoxDecoration(
                    color: isSelected
                        ? const Color.fromRGBO(59, 130, 246, 1)
                        : const Color.fromRGBO(229, 231, 235, 1),
                    borderRadius: BorderRadius.circular(16.r),
                  ),
                  child: Center(
                    child: Text(
                      speed,
                      style: TextStyle(
                        fontSize: 24.sp,
                        color: isSelected
                            ? Colors.white
                            : const Color.fromRGBO(107, 114, 128, 1),
                      ),
                    ),
                  ),
                ),
              );
            }).toList(),
          ),
        ],
      ),
    );
  }
}