import 'package:flutter/material.dart';
import 'custom_info_card.dart';

class FavoritesPage extends StatelessWidget {
  final List<Map<String, dynamic>> favoriteCards;
  final VoidCallback? onRefresh;

  const FavoritesPage({super.key, required this.favoriteCards, this.onRefresh});

  @override
  Widget build(BuildContext context) => Scaffold(
    appBar: AppBar(
      flexibleSpace: Padding(
        padding: EdgeInsets.only(top: MediaQuery.of(context).padding.top - 20),
        child: Image.asset('assets/header_image.png', fit: BoxFit.cover),
      ),
      toolbarHeight: MediaQuery.of(context).size.height * 0.19,
      title: const Text('Mis Favoritos', style: TextStyle(color: Colors.white)),
    ),
    body: Container(
      decoration: const BoxDecoration(
        gradient: LinearGradient(
          colors: [Color.fromARGB(255, 254, 100, 91), Colors.orange],
          begin: Alignment.topCenter,
          end: Alignment.bottomCenter,
        ),
      ),
      child: favoriteCards.isEmpty
          ? _buildEmptyState()
          : RefreshIndicator(
              onRefresh: () async => onRefresh?.call(),
              child: ListView.builder(
                padding: const EdgeInsets.only(top: 16),
                itemCount: favoriteCards.length,
                itemBuilder: (_, i) => CustomInfoCard(
                  imagePath: "assets/icons/${favoriteCards[i]['image']}",
                  title: favoriteCards[i]['title'],
                  subtitle: favoriteCards[i]['subtitle'],
                  texto: favoriteCards[i]['texto'],
                  categoria: favoriteCards[i]['categoria'],
                  isFavorite: true,
                ),
              ),
            ),
    ),
  );

  Widget _buildEmptyState() => Center(
    child: Column(
      mainAxisAlignment: MainAxisAlignment.center,
      children: [
        const Icon(Icons.favorite_border, size: 64, color: Colors.white54),
        const SizedBox(height: 16),
        const Text(
          'No tienes favoritos aún',
          style: TextStyle(color: Colors.white, fontSize: 18),
        ),
        const SizedBox(height: 8),
        Text(
          'Agrega favoritos desde las otras secciones',
          style: TextStyle(color: Colors.white.withOpacity(0.8)),
        ),
      ],
    ),
  );
}