import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';
import '../../../../../constants/constants.dart';
import '../../mixin/image_page_mixin.dart';
import '../arguments/image_page_argument.dart';

class ImagePage extends StatefulWidget {
  const ImagePage({super.key, required this.argument});

  final ImagePageArgument? argument;

  @override
  State<ImagePage> createState() => _ImagePageState();
}

class _ImagePageState extends State<ImagePage> with ImagePageMixin {
  @override
  void initState() {
    initController(widget.argument?.currentPage ?? 0);
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(),
      body: PageView.builder(
        controller: pageController,

        itemCount: widget.argument?.images?.length ?? 0,
        itemBuilder: (_, index) => InteractiveViewer(
          scaleEnabled: true,
          panEnabled: true,
          constrained: true,
          maxScale: 14,
          clipBehavior: Clip.antiAlias,
          child: CachedNetworkImage(
            imageUrl: "${Constants.baseUrl}${widget.argument?.images?[index]}",
            height: double.infinity,
            width: double.infinity,
          ),
        ),
      ),
    );
  }
}
