import 'package:didvan/config/design_config.dart';
import 'package:didvan/config/theme_data.dart';
import 'package:didvan/views/widgets/didvan/text.dart';
import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';

class AiSectionBNB extends StatelessWidget {
  final int currentTabIndex;
  final void Function(int index) onTabChanged;

  const AiSectionBNB(
      {Key? key, required this.currentTabIndex, required this.onTabChanged})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    const String cameraSolid = 'lib/assets/icons/houshanNav/imagegeneratorS.svg';
    const String cameraRegular =
        'lib/assets/icons/houshanNav/imagegeneratorU.svg';
    // const String micSolid = 'lib/assets/icons/houshanNav/aichatS.svg';
    // const String micRegular = 'lib/assets/icons/houshanNav/aichatU.svg';
    const String aiSolid =
        'lib/assets/icons/houshanNav/streamline-flex_ai-scanner-robot-remix.svg';
    const String aiRegular =
        'lib/assets/icons/houshanNav/streamline-flex_ai-scanner-robot.svg';
    const String searchSolid = 'lib/assets/icons/houshanNav/searchS.svg';
    const String searchRegular = 'lib/assets/icons/houshanNav/searchU.svg';
    const String translateSolid =
        'lib/assets/icons/houshanNav/translateS.svg';
    const String translateRegular =
        'lib/assets/icons/houshanNav/translateU.svg';

    return Container(
      height: 72,
      decoration: BoxDecoration(
        color: Theme.of(context).colorScheme.surface,
        borderRadius: const BorderRadius.vertical(top: Radius.circular(16)),
        boxShadow: [
          BoxShadow(
            color: const Color(0XFF1B3C59).withValues(alpha: 0.15),
            blurRadius: 8,
            spreadRadius: 0,
            offset: const Offset(0, -8),
          )
        ],
      ),
      padding: const EdgeInsets.symmetric(horizontal: 12),
      child: Row(
        children: [
          _AiNavBarItem(
            isSelected: currentTabIndex == 0,
            title: 'تصویرساز',
            selectedIcon: cameraSolid,
            unselectedIcon: cameraRegular,
            onTap: () => onTabChanged(0),
          ),
          // _AiNavBarItem(
          //   isSelected: currentTabIndex == 1,
          //   title: 'چت صوتی',
          //   selectedIcon: micSolid,
          //   unselectedIcon: micRegular,
          //   onTap: () => onTabChanged(1),
          // ),
          _AiNavBarItem(
            isSelected: currentTabIndex == 2,
            title: 'گفت‌وگو',
            selectedIcon: aiSolid,
            unselectedIcon: aiRegular,
            onTap: () => onTabChanged(2),
          ),
          _AiNavBarItem(
            isSelected: currentTabIndex == 3,
            title: 'جست‌وجو',
            selectedIcon: searchSolid,
            unselectedIcon: searchRegular,
            onTap: () => onTabChanged(3),
          ),
          _AiNavBarItem(
            isSelected: currentTabIndex == 4,
            title: 'ترجمه',
            selectedIcon: translateSolid,
            unselectedIcon: translateRegular,
            onTap: () => onTabChanged(4),
          ),
        ],
      ),
    );
  }
}

class _AiNavBarItem extends StatelessWidget {
  final VoidCallback onTap;
  final bool isSelected;
  final String title;
  final String selectedIcon;
  final String unselectedIcon;

  const _AiNavBarItem({
    Key? key,
    required this.isSelected,
    required this.title,
    required this.selectedIcon,
    required this.unselectedIcon,
    required this.onTap,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    final double iconSize = title.isEmpty ? 50.0 : 32.0;

    return Expanded(
      child: Tooltip(
        message: title,
        decoration: BoxDecoration(
          color: Theme.of(context).colorScheme.title,
          borderRadius: DesignConfig.highBorderRadius,
          boxShadow: DesignConfig.defaultShadow,
        ),
        child: GestureDetector(
          onTap: onTap,
          child: Container(
            color: Colors.transparent,
            child: Column(
              mainAxisAlignment: MainAxisAlignment.center,
              children: [
                AnimatedContainer(
                  padding: const EdgeInsets.all(4),
                  duration: DesignConfig.lowAnimationDuration,
                  decoration: const BoxDecoration(
                    shape: BoxShape.circle,
                  ),
                  child: SvgPicture.asset(
                    isSelected ? selectedIcon : unselectedIcon,
                    width: iconSize,
                    height: iconSize,
                  ),
                ),
                if (title.isNotEmpty)
                  Padding(
                    padding: const EdgeInsets.only(top: 2.0),
                    child: DidvanText(
                      title,
                      style: Theme.of(context).textTheme.bodySmall,
                      color: Theme.of(context).colorScheme.title,
                    ),
                  ),
              ],
            ),
          ),
        ),
      ),
    );
  }
}