import 'package:didvan/config/theme_data.dart';
import 'package:flutter/material.dart';

class MessageBarBtn extends StatelessWidget {
  final bool enable;
  final IconData? icon;
  final Widget? iconWidget;
  final Function()? click;

  const MessageBarBtn({
    Key? key,
    this.icon,
    this.iconWidget,
    this.click,
    required this.enable,
  })  : assert(icon != null || iconWidget != null,
            'Either icon or iconWidget must be provided'),
        super(key: key);

  @override
  Widget build(BuildContext context) {
    Widget finalIconWidget;

    if (iconWidget != null) {
      finalIconWidget = Opacity(
        opacity: enable ? 1.0 : 0.5,
        child: iconWidget,
      );
    } else {
      final color = enable
          ? Theme.of(context).colorScheme.primary
          : Theme.of(context).colorScheme.disabledText;

      finalIconWidget = Icon(
        icon,
        size: 24,
        color: color,
      );
    }

    return InkWell(
      onTap: click,
      child: Padding(
        padding: const EdgeInsets.all(4.0),
        child: finalIconWidget,
      ),
    );
  }
}