import 'package:flutter/material.dart';
import 'package:niogu_app/core/constants/app_color.dart';
import 'package:niogu_app/core/constants/app_font_size.dart';
import 'package:sizer/sizer.dart';

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

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

  @override
  Widget build(BuildContext context) {
    final bool isTablet = 100.w >= 600;
    final double height = isTablet ? 14.h : 12.h;
    return Container(
      height: height,
      decoration: BoxDecoration(
        color: Colors.white,
        border: BoxBorder.fromLTRB(
          top: BorderSide(color: Colors.grey.shade300),
        ),
      ),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceAround,
        children: [
          _buildNavItem(Icons.grid_view_rounded, "Menu", 0),
          _buildNavItem(Icons.inventory_2_rounded, "Barang", 1),

          _buildCenterPosButton(2),

          _buildNavItem(Icons.description_rounded, "Laporan", 3),
          _buildNavItem(Icons.person_rounded, "Profil", 4),
        ],
      ),
    );
  }

  Widget _buildNavItem(IconData icon, String label, int index) {
    final bool isActive = currentIndex == index;

    return InkWell(
      onTap: () => onTap(index),
      borderRadius: BorderRadius.circular(2.5.w),
      child: AnimatedContainer(
        duration: const Duration(milliseconds: 200),
        padding: EdgeInsets.symmetric(horizontal: 3.w, vertical: 1.h),
        decoration: BoxDecoration(
          color: isActive
              ? AppColor.primaryColor.withOpacity(0.08)
              : Colors.transparent,
          borderRadius: BorderRadius.circular(2.5.w),
        ),
        child: Column(
          mainAxisSize: MainAxisSize.min,
          children: [
            Icon(
              icon,
              color: isActive ? AppColor.primaryColor : Colors.grey,
              size: 6.w,
            ),
            SizedBox(height: 0.5.h),
            Text(
              label,
              style: TextStyle(
                fontSize: AppFontSize.small.sp,
                fontWeight: isActive ? FontWeight.bold : FontWeight.w500,
                color: isActive ? AppColor.primaryColor : Colors.grey,
              ),
            ),
          ],
        ),
      ),
    );
  }

  Widget _buildCenterPosButton(int index) {
    return InkWell(
      onTap: () => onTap(index),
      borderRadius: BorderRadius.circular(4.w),
      child: Container(
        width: 15.w,
        height: 15.w,
        decoration: BoxDecoration(
          color: AppColor.primaryColor,
          borderRadius: BorderRadius.circular(4.w),
          boxShadow: [
            BoxShadow(
              color: AppColor.primaryColor.withOpacity(0.3),
              blurRadius: 10,
              offset: const Offset(0, 4),
            ),
          ],
        ),
        child: Icon(
          Icons.point_of_sale_rounded,
          color: Colors.white,
          size: 12.w,
        ),
      ),
    );
  }
}
