import 'package:fis_ui/index.dart';
import 'package:flutter/material.dart';
import 'package:flyinsono/architecture/define.dart';

class FCustomExitButton extends FStatefulWidget {
  final String text;
  final IconData icon;
  final VoidCallback onPressed;
  final Color? normalColor;

  FCustomExitButton(
    this.text,
    this.icon,
    this.onPressed, {
    this.normalColor,
  });

  @override
  FState<FStatefulWidget> createState() {
    return _CustomButtonState();
  }
}

class _CustomButtonState extends FState<FCustomExitButton> {
  bool hover = false;
  @override
  FWidget build(BuildContext context) {
    return FMouseRegion(
      onEnter: (event) {
        setState(() {
          hover = true;
        });
      },
      onExit: (event) {
        setState(() {
          hover = false;
        });
      },
      child: FElevatedButton(
        onPressed: widget.onPressed,
        name: 'FCustomButton',
        businessParent: FVirtualPageWidget('FCustomButton'),
        style: ElevatedButton.styleFrom(
          padding: EdgeInsets.symmetric(horizontal: 8, vertical: 16),
          backgroundColor: hover
              ? Colors.redAccent
              : widget.normalColor ?? Colors.transparent,
          side: BorderSide(color: Colors.redAccent, width: 2),
          shape: RoundedRectangleBorder(
            borderRadius: BorderRadius.circular(8),
          ),
        ),
        child: FRow(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            FText(
              widget.text,
              style: TextStyle(
                fontWeight: FontWeight.w600,
                color: hover ? Colors.grey[300] : Colors.redAccent,
              ),
            ),
            FSizedBox(width: 3),
            FIcon(
              Icons.exit_to_app,
              color: hover ? Colors.grey[300] : Colors.redAccent,
            ),
          ],
        ),
      ),
    );
  }
}
