import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart';
import 'package:hmg_patient_app_new/core/app_assets.dart';
import 'package:hmg_patient_app_new/core/app_state.dart';
import 'package:hmg_patient_app_new/core/dependencies.dart';
import 'package:hmg_patient_app_new/core/utils/size_utils.dart';
import 'package:hmg_patient_app_new/core/utils/utils.dart';
import 'package:hmg_patient_app_new/extensions/string_extensions.dart';
import 'package:hmg_patient_app_new/extensions/widget_extensions.dart';
import 'package:hmg_patient_app_new/generated/locale_keys.g.dart';
import 'package:hmg_patient_app_new/theme/colors.dart';

class BottomNavigation extends StatelessWidget {
  final int currentIndex;
  final ValueChanged<int> onTap;

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

  @override
  Widget build(BuildContext context) {
    AppState appState = getIt.get<AppState>();
    final items = [
      BottomNavItem(icon: AppAssets.homeBottom, fillIcon: AppAssets.homeBottomFill, label: LocaleKeys.home.tr(context: context)),
      appState.isAuthenticated
          ? BottomNavItem(icon: AppAssets.myFilesBottom, fillIcon: AppAssets.myFilesBottomFill, label: LocaleKeys.medicalFile.tr(context: context))
          : BottomNavItem(icon: AppAssets.weatherBottom, fillIcon: AppAssets.weatherBottomFill, label: LocaleKeys.weatherIndicators.tr(context: context)),
      BottomNavItem(
        icon: AppAssets.bookAppoBottom,
        fillIcon: AppAssets.bookAppoBottom,
        label: LocaleKeys.appointments.tr(context: context),
        iconSize: 32, isSpecial: true),
      appState.isAuthenticated
          // ? BottomNavItem(icon: AppAssets.toDoBottom, label: LocaleKeys.todoList.tr(context: context))
          ? BottomNavItem(icon: AppAssets.symptomCheckerBottomIcon, fillIcon: AppAssets.symptomCheckerBottomFillIcon, label: LocaleKeys.symptoms.tr(context: context))
          : BottomNavItem(icon: AppAssets.news, fillIcon: AppAssets.newsFill, label: LocaleKeys.news.tr()),
      BottomNavItem(icon: AppAssets.servicesBottom, fillIcon: AppAssets.servicesBottomFill, label: LocaleKeys.services2.tr(context: context)),
    ];

    return Container(
      decoration: BoxDecoration(
        color: AppColors.whiteColor,
        border: Border(
          top: BorderSide(
            color: AppColors.bottomNAVBorder,
            width: 0.5,
          ),
        ),
      ),
      padding: const EdgeInsets.all(15),
      // height: 84.h,
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceEvenly,
        children: List.generate(
          items.length,
          (index) => _buildNavItem(items[index], index),
        ),
      ),
    );
  }

  Widget _buildNavItem(BottomNavItem item, int index) {
    final bool isSelected = currentIndex == index;

    return GestureDetector(
      onTap: () => onTap(index),
      behavior: HitTestBehavior.opaque,
      child: SizedBox(
        height: 56.h,
        child: Column(
          mainAxisSize: MainAxisSize.min,
          mainAxisAlignment: MainAxisAlignment.center,
          crossAxisAlignment: CrossAxisAlignment.center,
          children: [
            Utils.buildSvgWithAssets(
              icon: isSelected ? item.fillIcon : item.icon,
              height: item.iconSize.h,
              width: item.iconSize.w,
              applyThemeColor: !item.isSpecial
              // iconColor:  isSelected ? Colors.black87 : Colors.black87,
            ),
            // const SizedBox(height: 10),
            SizedBox(height: item.isSpecial ? 0 : 8.h),
            item.label.toText10(isBold: true),
            // SizedBox(height: item.isSpecial ? 5 : 0)
          ],
        ),
      ),
    ).expanded;
  }
}

class BottomNavItem {
  final String icon;
  final String fillIcon;
  final String label;
  final double iconSize;
  final bool isSpecial;
  final Color? color;

  const BottomNavItem({
    required this.icon,
    required this.fillIcon,
    required this.label,
    this.iconSize = 24,
    this.isSpecial = false,
    this.color,
  });
}

