import 'package:carousel_slider/carousel_slider.dart';
import 'package:flutter/material.dart';
import 'package:skillcourt/pages/play_setup/play_setup.dart';
import 'package:skillcourt/pages/play_setup/play_setup_item.dart';

class PadLightUp extends StatefulWidget {
  const PadLightUp(
      {super.key,
      required this.secondSelected,
      required this.currentSelection,
      this.onTap});

  final int? currentSelection;
  final Function(int) secondSelected;
  final Function()? onTap;

  @override
  State<PadLightUp> createState() => _PadLightUpState();
}

class _PadLightUpState extends State<PadLightUp> {
  @override
  Widget build(BuildContext context) {
    final List<Widget> seconds = [for (int i = 0; i <= 30; i++) timeButton(i)];
    int _currentSelection = widget.currentSelection ?? 0;
    CarouselController _carouselController = CarouselController();
    return EditMenu(
      playItemParameter: PlaySetUp.playSetUpItem.padLightUp,
      title: 'Pad light up',
      description: 'The length of time the pad lights are on.',
      icon: Icons.wb_sunny_outlined,
      carouselController: _carouselController,
      items: seconds,
      itemSelected: widget.secondSelected,
      onTapPlaySettingButton: widget.onTap,
      currentSelection: _currentSelection,
      unit: 'Seconds',
    );
  }

  Widget timeButton(int value) {
    return SizedBox(
      width: 100,
      height: 50,
      child: Card(
        elevation: 1.5,
        child: Center(
          child: Text(
            value < 10 ? '0$value' : '$value',
            textAlign: TextAlign.center,
            style: const TextStyle(fontWeight: FontWeight.bold, fontSize: 40),
          ),
        ),
      ),
    );
  }
}
