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 MenuItem extends StatelessWidget {
  final String? title;
  final Widget? titleWidget;
  final IconData? icon;
  final double iconSize;
  final String? suffix;
  final VoidCallback onTap;
  final Widget? trailing;
  final Color? color;
  MenuItem({
    Key? key,
    required this.onTap,
    this.title,
    this.icon,
    this.suffix,
    this.color,
    this.trailing,
    this.titleWidget,
    this.iconSize = 18,
  }) : super(key: key) {
    if (title == null && titleWidget == null) {
      throw Exception;
    }
  }

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: onTap,
      child: Container(
        color: Colors.transparent,
        child: Row(
          children: [
            if (icon != null)
              Icon(
                icon,
                size: iconSize,
                color: color ?? Theme.of(context).colorScheme.title,
              ),
            if (icon != null) const SizedBox(width: 4),
            if (titleWidget != null) titleWidget!,
            if (titleWidget == null)
              DidvanText(
                title!,
                color: color ?? Theme.of(context).colorScheme.title,
              ),
            const Spacer(),
            if (suffix != null)
              DidvanText(
                suffix!,
                style: Theme.of(context)
                    .textTheme
                    .subtitle2!
                    .copyWith(fontWeight: FontWeight.w400),
                color: Theme.of(context).colorScheme.primary,
              ),
            trailing ??
                Icon(
                  DidvanIcons.angle_left_regular,
                  size: 18,
                  color: color ?? Theme.of(context).colorScheme.title,
                ),
          ],
        ),
      ),
    );
  }
}
