import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'app_state.dart';


class FavoritePage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    TindBookState state = Provider.of<TindBookState>(context);

    return Scaffold(
      appBar: AppBar(
        title: Text('Favorite Books'),
      ),
      body: GridView.builder(
        gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
          crossAxisCount: 2,
          childAspectRatio: 0.7,
        ),
        itemCount: state.favorites.length,
        itemBuilder: (context, index) {
          return GestureDetector(
            onTap: () {
              Navigator.push(
                context,
                MaterialPageRoute(
                  builder: (context) => ImageScreen(imagePath: state.getFav(index)['image']),
                ),
              );
            },
            child: Padding(
              padding: const EdgeInsets.all(8.0),
              child: Image.asset(
                state.getFav(index)['image'],
                fit: BoxFit.cover,
              ),
            ),
          );
        },
      ),
    );
  }
}

class ImageScreen extends StatelessWidget {
  final String imagePath;

  const ImageScreen({Key? key, required this.imagePath}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(),
      body: Center(
        child: Image.asset(imagePath),
      ),
    );
  }
}
