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

class CustomNavBar extends StatelessWidget {
  final int currentIndex;
  final Function(int) onTap;

  const CustomNavBar({
    super.key,
    required this.currentIndex,
    required this.onTap,
  });

  @override
  Widget build(BuildContext context) {
    return Container(
      height: 90,
      color: colorAzul,
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceEvenly,
        children: [
          _buildNavButton(
            index: 0,
            currentIndex: currentIndex,
            iconNormal: Icons.home_outlined,
            iconActive: Icons.home,
            label: 'Domicilios',
            onTap: onTap,
          ),
          _buildNavButton(
            index: 1,
            currentIndex: currentIndex,
            iconNormal: Icons.alt_route_rounded,
            iconActive: Icons.alt_route_rounded,
            label: 'Rutas',
            onTap: onTap,
          ),
          _buildNavButton(
            index: 2,
            currentIndex: currentIndex,
            iconNormal: Icons.settings_outlined,
            iconActive: Icons.settings,
            label: 'Configuración',
            onTap: onTap,
          ),
        ],
      ),
    );
  }

  Widget _buildNavButton({
    required int index,
    required int currentIndex,
    required IconData iconNormal,
    required IconData iconActive,
    required String label,
    required Function(int) onTap,
  }) {
    final bool isActive = currentIndex == index;

    return Expanded(
      child: GestureDetector(
        onTap: () => onTap(index),
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            Icon(
              isActive ? iconActive : iconNormal,
              color: Colors.white,
              size: isActive ? 55 : 35,
            ),
            const SizedBox(height: 5),
            Text(
              label,
              style: TextStyle(
                color: Colors.white,
                fontSize: isActive ? 14 : 12,
                fontWeight: isActive ? FontWeight.bold : FontWeight.normal,
              ),
            ),
          ],
        ),
      ),
    );
  }
}