import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:hub/features/menu/index.dart';
import 'package:hub/flutter_flow/flutter_flow_theme.dart';

class ButtonMenuItem extends MenuItem {
  const ButtonMenuItem({
    super.key,
    required this.action,
    required this.title,
    required this.icon,
  }) : super(action: action, title: title, icon: icon);

  @override
  final Function() action;
  @override
  final String title;
  @override
  final IconData icon;

  @override
  _MenuButtonWidgetState createState() => _MenuButtonWidgetState();
}

class _MenuButtonWidgetState extends State<ButtonMenuItem> {
  bool _isProcessing = false;

  @override
  Widget build(BuildContext context) {
    final textScaler = MediaQuery.textScalerOf(context);
    final double baseFontSize = 14;
    final double scaledFontSize = baseFontSize * textScaler.scale(1);
    final double limitedFontSize = scaledFontSize > 24 ? 12 : baseFontSize;

    return InkWell(
      splashColor: Colors.transparent,
      focusColor: Colors.transparent,
      hoverColor: Colors.transparent,
      highlightColor: Colors.transparent,
      onTap: _isProcessing
          ? null
          : () async {
              setState(() {
                _isProcessing = true;
              });
              await widget.action.call();
              setState(() {
                _isProcessing = false;
              });
            },
      child: Padding(
        padding: const EdgeInsets.symmetric(horizontal: 0, vertical: 0),
        child: Container(
          width: 300,
          height: 280,
          decoration: BoxDecoration(
            color: FlutterFlowTheme.of(context).primaryBackground,
            boxShadow: [
              BoxShadow(
                blurRadius: 4.0,
                color: FlutterFlowTheme.of(context).customColor5,
                offset: const Offset(0.0, 2.0),
              )
            ],
            borderRadius: BorderRadius.circular(24.0),
            shape: BoxShape.rectangle,
            border: Border.all(
              color: FlutterFlowTheme.of(context).alternate,
              width: 0.5,
            ),
          ),
          child: Padding(
            padding: const EdgeInsets.all(0.0),
            child: Column(
              mainAxisSize: MainAxisSize.min,
              mainAxisAlignment: MainAxisAlignment.spaceEvenly,
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                if (widget.icon != null)
                  Container(
                    alignment: Alignment.topLeft,
                    padding: const EdgeInsets.only(left: 8.0),
                    child: Icon(
                      widget.icon,
                      size: 24.0,
                      color: FlutterFlowTheme.of(context).primaryText,
                    ),
                  ),
                Flexible(
                  child: Padding(
                    padding: const EdgeInsets.only(left: 10.0),
                    child: Text(
                      widget.title,
                      overflow: TextOverflow.ellipsis,
                      maxLines: 2,
                      textAlign: TextAlign.start,
                      style: FlutterFlowTheme.of(context).titleLarge.override(
                            fontFamily: 'Nunito',
                            color: FlutterFlowTheme.of(context).primaryText,
                            fontSize: limitedFontSize,
                            fontWeight: FontWeight.w500,
                            useGoogleFonts:
                                GoogleFonts.asMap().containsKey('Nunito'),
                          ),
                    ),
                  ),
                ),
              ],
            ),
          ),
        ),
      ),
    );
  }
}
