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 GameRepeats extends StatefulWidget {
  const GameRepeats(
      {super.key, required this.repeatsSelected, this.currentSelection, this.onTap});

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

  @override
  State<GameRepeats> createState() => _GameRepeatsState();
}

class _GameRepeatsState extends State<GameRepeats> {
  @override
  Widget build(BuildContext context) {
    final List<Widget> seconds = [
      for (int i = 2; i <= 10; i++) repeatButton('${i}x'),
      repeatButton("No")
    ];
    int _currentSelection = widget.currentSelection ?? 0;
    CarouselController _carouselController = CarouselController();
    return EditMenu(
      playItemParameter: PlaySetUp.playSetUpItem.gameRepeats,
      title: 'Game Repeats',
      description:
          'The number of times you will play with the current settings.',
      icon: Icons.compare_arrows,
      currentSelection: _currentSelection,
      carouselController: _carouselController,
      items: seconds,
      itemSelected: widget.repeatsSelected,
      unit: 'Repeats',
      onTapPlaySettingButton: widget.onTap,
    );
  }

  Widget repeatButton(String value) {
    return SizedBox(
      width: 100,
      height: 50,
      child: Card(
        elevation: 1.5,
        child: Center(
          child: Text(
            value,
            textAlign: TextAlign.center,
            style: const TextStyle(fontWeight: FontWeight.bold, fontSize: 40),
          ),
        ),
      ),
    );
  }
}
