import 'package:flutter/material.dart';

class CustomElevatedButton extends StatelessWidget {
  final bool icon;
  final String text;
  final double width;
  final double height;
  final Color? borderColor;
  final double borderRadius;
  final Color backgroundColor;
  final Color foregroundColor;
  final GestureTapCallback? onTap;

  const CustomElevatedButton({
    super.key,
    this.onTap,
    this.borderColor,
    this.icon = false,
    required this.text,
    required this.height,
    this.borderRadius = 0,
    required this.backgroundColor,
    required this.foregroundColor,
    this.width = double.maxFinite,
  });

  @override
  Widget build(BuildContext context) => _buildButtonWrapper();

  Widget _buildButtonWrapper() =>
      SizedBox(height: 50, width: width, child: _buildButton());

  Widget _buildButton() => OutlinedButton(
        onPressed: onTap,
        style: OutlinedButton.styleFrom(
          backgroundColor: backgroundColor,
          side: borderColor == null
              ? BorderSide.none
              : BorderSide(color: borderColor!),
          shape: RoundedRectangleBorder(
              borderRadius: BorderRadius.circular(borderRadius)),
        ),
        child: _buildRow(),
      );

  Widget _buildRow() => Row(
        mainAxisAlignment: MainAxisAlignment.center,
        children: _buildRowChildren(),
      );

  List<Widget> _buildRowChildren() =>
      [_buildText(), const SizedBox(width: 5), if (icon) _buildIcon()];

  Widget _buildIcon() => Icon(
        Icons.arrow_forward,
        color: foregroundColor,
      );

  Widget _buildText() => Text(
        text,
        style: TextStyle(color: foregroundColor, fontWeight: FontWeight.bold),
      );
}
