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

class MenuOption extends StatelessWidget {
  final String? title;
  final Widget? titleWidget;
  final IconData? icon;
  final Widget? iconWidget;
  final double iconSize;
  final String? suffix;
  final VoidCallback onTap;
  final Widget? trailing;
  final Color? color;

  MenuOption({
    Key? key,
    required this.onTap,
    this.title,
    this.icon,
    this.iconWidget,
    this.suffix,
    this.color,
    this.trailing,
    this.titleWidget,
    this.iconSize = 18,
  }) : super(key: key) {
    if (title == null && titleWidget == null) {
      throw Exception("MenuOption must have a title or titleWidget");
    }
  }

  @override
  Widget build(BuildContext context) {
    final ThemeData theme = Theme.of(context);
    final Color effectiveTitleColor = color ?? theme.colorScheme.title;

    Widget? displayIcon;
    if (iconWidget != null) {
      displayIcon = iconWidget;
    } else if (icon != null) {
      displayIcon = Icon(icon, size: iconSize, color: effectiveTitleColor);
    }

    return GestureDetector(
      onTap: onTap,
      child: Container(
        color: Colors.transparent,
        padding: const EdgeInsets.symmetric(vertical: 0.0), 
        child: Row(
          children: [
            if (displayIcon != null) displayIcon,
            if (displayIcon != null) const SizedBox(width: 4),
            
            if (titleWidget != null) titleWidget!
            else DidvanText(
                    title!,
                    color: effectiveTitleColor,
                  ),
            const Spacer(), 
            
            if (suffix != null)
              Padding(
                padding: const EdgeInsets.only(left: 8.0),
                child: DidvanText(
                  suffix!,
                  style: theme.textTheme.titleSmall!
                      .copyWith(fontWeight: FontWeight.w400),
                  color: theme.colorScheme.primary,
                ),
              ),
            
            trailing ??
                Icon(
                  DidvanIcons.angle_left_regular,
                  size: 18,
                  color: effectiveTitleColor,
                ),
          ],
        ),
      ),
    );
  }
}