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';
import 'package:hub/flutter_flow/flutter_flow_util.dart';

class CardMenuItem extends MenuItem {
  const CardMenuItem({
    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
  _MenuCardItemState createState() => _MenuCardItemState();
}

class _MenuCardItemState extends State<CardMenuItem> {
  bool _isProcessing = false;

  @override
  Widget build(BuildContext context) {
    return InkWell(
      splashColor: Colors.transparent,
      focusColor: Colors.transparent,
      hoverColor: Colors.transparent,
      highlightColor: Colors.transparent,
      onTap: _isProcessing
          ? null
          : () async {
              safeSetState(() {
                _isProcessing = true;
              });
              await widget.action.call();
              safeSetState(() {
                _isProcessing = false;
              });
            },
      child: Card(
        elevation: 0,
        color: FlutterFlowTheme.of(context).primaryBackground,
        child: Row(
          mainAxisSize: MainAxisSize.max,
          mainAxisAlignment: MainAxisAlignment.start,
          children: [
            Align(
              alignment: const AlignmentDirectional(-1.0, 0.0),
              child: Padding(
                padding:
                    const EdgeInsetsDirectional.fromSTEB(8.0, 0.0, 10.0, 0.0),
                child: Container(
                  width: 30.0,
                  height: 30.0,
                  decoration: BoxDecoration(
                    color: FlutterFlowTheme.of(context).primaryBackground,
                    shape: BoxShape.circle,
                  ),
                  alignment: const AlignmentDirectional(0.0, 0.0),
                  child: Icon(
                    widget.icon,
                    color: FlutterFlowTheme.of(context).accent1,
                    size: 24.0,
                  ),
                ),
              ),
            ),
            Flexible(
              child: Text(
                widget.title,
                style: FlutterFlowTheme.of(context).titleLarge.override(
                      fontFamily: 'Nunito',
                      color: FlutterFlowTheme.of(context).primaryText,
                      fontSize: 14.0,
                      fontWeight: FontWeight.w500,
                      useGoogleFonts: GoogleFonts.asMap().containsKey('Nunito'),
                    ),
              ),
            ),
          ],
        ),
      ),
    );
  }
}
