import 'package:carousel_slider/carousel_slider.dart';
import 'package:flutter/material.dart';
import 'package:gap/gap.dart';
import 'package:krow/core/presentation/gen/assets.gen.dart';
import 'package:krow/core/presentation/styles/theme.dart';

class ShowcaseCarouselWidget extends StatefulWidget {
  const ShowcaseCarouselWidget({super.key});

  @override
  State<ShowcaseCarouselWidget> createState() => _ShowcaseCarouselWidgetState();
}

class _ShowcaseCarouselWidgetState extends State<ShowcaseCarouselWidget> {
  int _currentIndex = 0;

  @override
  Widget build(BuildContext context) {
    return Column(
      children: [
        Expanded(
          child: CarouselSlider(
            options: CarouselOptions(
              aspectRatio: 10 / 9,
              viewportFraction: 1,
              autoPlay: true,
              autoPlayAnimationDuration: Durations.medium4,
              autoPlayInterval: const Duration(seconds: 2),
              onPageChanged: (index, _) {
                setState(() => _currentIndex = index);
              },
            ),
            items: [
              for (final image in Assets.images.slider.values)
                image.image(
                  fit: BoxFit.fitWidth,
                  width: double.maxFinite,
                ),
            ],
          ),
        ),
        const Gap(20),
        Row(
          mainAxisAlignment: MainAxisAlignment.center,
          children: List.generate(
            3,
            (index) {
              return AnimatedContainer(
                duration: Durations.short4,
                width: _currentIndex == index ? 30 : 6.0,
                height: 6.0,
                margin: const EdgeInsets.symmetric(
                  horizontal: 5.0,
                ),
                decoration: const BoxDecoration(
                  borderRadius: BorderRadius.all(
                    Radius.circular(20),
                  ),
                  color: AppColors.grayWhite,
                ),
              );
            },
          ),
        ),
      ],
    );
  }
}
