import 'package:boilerplate/core/utils/navigator_util.dart';
import 'package:boilerplate/domain/entities/product/product_data.dart';
import 'package:boilerplate/presentation/widgets/ipm_image.dart';
import 'package:boilerplate/presentation/widgets/ipm_photo_view.dart';
import 'package:flutter/material.dart';

import '../../../../../core/styles/my_dimensions.dart';

class ProductImages extends StatefulWidget {
  final List<ProductImageData> images;

  ProductImages({Key? key, required this.images}) : super(key: key);

  @override
  State<ProductImages> createState() => _ProductImagesState();
}

class _ProductImagesState extends State<ProductImages> {
  int currentPage = 0;

  @override
  void initState() {
    super.initState();
  }

  @override
  void dispose() {
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    // print("widget.images  ${widget.images[0].link.toString()}");
    // print("widget.images  ${widget.images[1].link.toString()}");
    // print("widget.images  ${widget.images[2].link.toString()}");
    // print("widget.images  ${widget.images.length}");
    if (widget.images.isEmpty) {
      return SizedBox(height: MediaQuery.of(context).padding.top);
    }

    return SizedBox(
      width: MyDimens.dimen375,
      height: MyDimens.dimen360,
      child: Stack(
        alignment: Alignment.bottomCenter,
        children: [
          PageView.builder(
            onPageChanged: ((value) {
              setState(() {
                currentPage = value;
              });
            }),
            itemCount: widget.images.length,
            itemBuilder: (context, index) {
              return GestureDetector(
                onTap: () => NavigatorUtil.pushToPage(IPMPhotoViewScreen(
                  url: widget.images[index].link,
                )),
                child: IPMImage(
                  url: widget.images[index].link,
                  fit: BoxFit.cover,
                ),
              );
            },
          ),
          Positioned(
            bottom: MyDimens.dimen22,
            child: Row(
              mainAxisSize: MainAxisSize.min,
              children: [
                ...List.generate(
                  widget.images.length,
                  (index) => Container(
                    margin: EdgeInsets.symmetric(horizontal: MyDimens.dimen6),
                    width: MyDimens.dimen6,
                    height: MyDimens.dimen6,
                    decoration: BoxDecoration(
                      borderRadius: BorderRadius.circular(100),
                      color: index == currentPage
                          ? const Color(0xFFD9D9D9)
                          : const Color(0xFFD9D9D9).withOpacity(0.5),
                    ),
                  ),
                ).toList(),
              ],
            ),
          )
        ],
      ),
    );
  }
}
