import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart';
import '../screens/daily_flux_screen.dart';
import '../screens/journal_screen.dart';
import '../screens/message_list_screen.dart';
import '../screens/profile_screen.dart';

class CozyHomeFrame extends StatefulWidget {
  const CozyHomeFrame({super.key});

  @override
  State<CozyHomeFrame> createState() => _CozyHomeFrameState();
}

class _CozyHomeFrameState extends State<CozyHomeFrame> {
  int _currentIndex = 0;
  final List<Widget> _pages = [
    const DailyFluxScreen(),
    const JournalScreen(),
    const MessageListScreen(),
    const ProfileScreen(),
  ];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: _pages[_currentIndex],
      bottomNavigationBar: SafeArea(
        child: Container(
          height: 70,
          margin: const EdgeInsets.fromLTRB(20, 0, 20, 20),
          decoration: BoxDecoration(
            color: Colors.white,
            borderRadius: BorderRadius.circular(35),
            boxShadow: [
              BoxShadow(
                color: const Color(0xFF8D6E63).withOpacity(0.05),
                blurRadius: 20,
                offset: const Offset(0, 10),
              ),
            ],
          ),
          child: Row(
            mainAxisAlignment: MainAxisAlignment.spaceEvenly,
            children: [
              _buildNavItem(0, Icons.spa_rounded, "Flux"),
              _buildNavItem(1, Icons.bar_chart_rounded, "Journal"),
              _buildNavItem(2, Icons.notifications_rounded, "Msg"),
              _buildNavItem(3, Icons.person_rounded, "Me"),
            ],
          ),
        ),
      ),
    );
  }

  Widget _buildNavItem(int index, IconData icon, String label) {
    final isSelected = _currentIndex == index;
    return GestureDetector(
      onTap: () => setState(() => _currentIndex = index),
      child: AnimatedContainer(
        duration: const Duration(milliseconds: 300),
        padding: EdgeInsets.symmetric(
          horizontal: isSelected ? 16 : 12,
          vertical: 10,
        ),
        decoration: BoxDecoration(
          color: isSelected ? const Color(0xFFFFF3E0) : Colors.transparent,
          borderRadius: BorderRadius.circular(25),
        ),
        child: Row(
          children: [
            Icon(
              icon,
              color: isSelected
                  ? const Color(0xFFFB8C00)
                  : const Color(0xFFBCAAA4),
              size: 24,
            ),
            if (isSelected) ...[
              const SizedBox(width: 6),
              Text(
                label,
                style: GoogleFonts.nunito(
                  fontWeight: FontWeight.bold,
                  color: const Color(0xFFFB8C00),
                  fontSize: 13,
                ),
              ),
            ],
          ],
        ),
      ),
    );
  }
}
