import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:go_router/go_router.dart';
import 'package:real_estate_mobile/core/constants/app_colors.dart';
import 'package:real_estate_mobile/features/home/presentation/widgets/features_section.dart';
import 'package:real_estate_mobile/features/home/presentation/widgets/hero_section.dart';
import 'package:real_estate_mobile/features/home/presentation/widgets/testimonials_section.dart';
import 'package:real_estate_mobile/features/home/presentation/widgets/top_professionals_section.dart';
import 'package:real_estate_mobile/features/home/presentation/widgets/trust_stats_section.dart';

class HomeScreen extends ConsumerWidget {
  const HomeScreen({super.key});

  @override
  Widget build(BuildContext context, WidgetRef ref) {
    return SingleChildScrollView(
      child: Column(
        children: [
          // Hero Section with Search
          const HeroSection(),
          const SizedBox(height: 40),

          // Features Section
          const FeaturesSection(),
          const SizedBox(height: 40),

          // Top Professionals Section (Agents/Lenders tabs)
          const TopProfessionalsSection(),
          const SizedBox(height: 40),

          // Trust & Stats Section
          const TrustStatsSection(),
          const SizedBox(height: 24),

          // Testimonials Section
          const TestimonialsSection(),
          const SizedBox(height: 40),

          // Footer
          _buildFooter(context),
        ],
      ),
    );
  }

  static const _footerRoutes = <String, String>{
    'Home': '/home',
    'About': '/about',
    'Contact': '/contact',
    'FAQ': '/faq',
  };

  Widget _buildFooter(BuildContext context) {
    return Container(
      width: double.infinity,
      padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 24),
      color: AppColors.primaryDark,
      child: Column(
        children: [
          Image.asset(
            'assets/icons/logo.png',
            width: 109,
            height: 29,
            color: Colors.white,
          ),
          const SizedBox(height: 16),
          Row(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              _buildFooterLink(context, 'Home'),
              _buildFooterDot(),
              _buildFooterLink(context, 'About'),
              _buildFooterDot(),
              _buildFooterLink(context, 'Contact'),
              _buildFooterDot(),
              _buildFooterLink(context, 'FAQ'),
            ],
          ),
          const SizedBox(height: 16),
          Text(
            '\u00A9 2025 RE-Quest. All rights reserved.',
            style: TextStyle(
              fontFamily: 'SourceSerif4',
              fontSize: 12,
              fontWeight: FontWeight.w400,
              color: Colors.white.withValues(alpha: 0.6),
            ),
          ),
        ],
      ),
    );
  }

  Widget _buildFooterLink(BuildContext context, String text) {
    return GestureDetector(
      onTap: () {
        final route = _footerRoutes[text];
        if (route != null) context.go(route);
      },
      child: Text(
        text,
        style: const TextStyle(
          fontFamily: 'SourceSerif4',
          fontSize: 14,
          fontWeight: FontWeight.w400,
          color: Colors.white,
        ),
      ),
    );
  }

  Widget _buildFooterDot() {
    return Padding(
      padding: const EdgeInsets.symmetric(horizontal: 12),
      child: Text(
        '\u2022',
        style: TextStyle(
          fontSize: 14,
          color: Colors.white.withValues(alpha: 0.5),
        ),
      ),
    );
  }
}
