mirrored_repositories/Widgets-App/lib/presentation/screen
import 'package:animate_do/animate_do.dart';
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';


class SlideInfo {
  final String title;
  final String caption;
  final String imageUrl;

  SlideInfo(this.title, this.caption, this.imageUrl);
}

final slides = <SlideInfo>[
  SlideInfo("Busca la comida", 'Est in aliqua cupidatat cillum id laborum mollit nostrud Lorem ', 'assets/images/1.png'),
  SlideInfo("Entrega rápida", 'Cillum aliqua ipsum consequat eiusmod ut elit est ipsum. Duis .', 'assets/images/2.png'),
  SlideInfo("Disfruta la comida", "Ea labore cupidatat .", 'assets/images/3.png'),
];


class AppTutorialScreen extends StatefulWidget {
  
  static const name = "tutorial_screen";
  
  const AppTutorialScreen({super.key});

  @override
  State<AppTutorialScreen> createState() => _AppTutorialScreenState();
}

class _AppTutorialScreenState extends State<AppTutorialScreen> {

  late final PageController pageviewController;
  bool endReached = false;

  @override
  void initState() {
    super.initState();
    pageviewController = PageController()..addListener(() {
      // print('${ pageviewController.page }'); 
      final page = pageviewController.page ?? 0;
      if ( !endReached && page >= (slides.length - 1.5)){
        setState(() {
          endReached = true;
        });
      }
     });
  }

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

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.white,
      body: Stack(
        children: [
          PageView(
            controller: pageviewController,
            physics: const BouncingScrollPhysics(),
            children: slides.map(
              (slideInfo) => _Slide(
                title: slideInfo.title, 
                caption: slideInfo.caption, 
                imageUrl: slideInfo.imageUrl
              )
            ).toList(),
          ),

          Positioned(
            right: 20,
            top: 50,
            child: TextButton(
              onPressed: () => {
                Navigator.of(context).pop()
              }, 
              child: const Text("Saltar"),
            )
          ),

          Positioned(
            bottom: 40,
            right: 40,
            child: ( endReached ) ? 
            FadeInRight(
              from: 15,
              delay: const Duration(seconds: 1),
              child: FilledButton(
                child: const Text("Comenzar"),
                onPressed: () => context.pop(),
              ),
            ) : const SizedBox(),
          ),

        ],
      ),
    );
  }
}


class _Slide extends StatelessWidget {
  
  final String title;
  final String caption;
  final String imageUrl;

  const _Slide({
    required this.title, 
    required this.caption, 
    required this.imageUrl
  });

  @override
  Widget build(BuildContext context) {

    final titleStyle = Theme.of(context).textTheme.titleLarge;
    final captionStyle = Theme.of(context).textTheme.bodySmall;

    return Padding(
      padding: const EdgeInsets.symmetric(horizontal: 30),
      child: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Image(
              image: AssetImage( imageUrl ), 
            ),
            const SizedBox( height: 20 ),
            Text( title, style: titleStyle,),
            const SizedBox( height: 10 ,),
            Text( caption, style: captionStyle, ),
          ],
        ),
      ),
    );
  }
}