import 'package:flutter/material.dart';
import 'package:rasadyar_core/presentation/common/app_color.dart';
import 'package:rasadyar_core/presentation/common/app_fonts.dart';

class RElevated extends StatelessWidget {
  const RElevated({
    super.key,
    required this.text,
    required this.onPressed,
    this.foregroundColor = Colors.white,
    this.backgroundColor = AppColor.blueNormal,
    this.disabledBackgroundColor,
    this.disabledForegroundColor = Colors.white,
    this.radius = 8.0,
    this.textStyle,
    this.width = 150.0,
    this.height = 56.0,
    this.isFullWidth = false,
    this.isLoading = false,
  });

  final String text;
  final VoidCallback? onPressed;
  final double width;
  final double height;
  final bool isFullWidth;
  final Color foregroundColor;
  final Color backgroundColor;
  final Color? disabledForegroundColor;
  final Color? disabledBackgroundColor;
  final double radius;
  final TextStyle? textStyle;
  final bool isLoading;

  @override
  Widget build(BuildContext context) {
    final bool isEnabled = onPressed != null && !isLoading;

    return ElevatedButton(
      onPressed: isEnabled ? onPressed : null,
      style: ElevatedButton.styleFrom(
        backgroundColor: backgroundColor,
        foregroundColor: foregroundColor,
        disabledBackgroundColor:
            disabledBackgroundColor ?? backgroundColor.withAlpha(38),
        disabledForegroundColor: disabledForegroundColor,
        shape: RoundedRectangleBorder(
          borderRadius: BorderRadius.circular(radius),
        ),
        minimumSize: Size(isFullWidth ? double.infinity : width, height),
        padding: EdgeInsets.zero,
        textStyle: textStyle ?? AppFonts.yekan18,
      ),
      child:
          isLoading
              ? SizedBox(
                width: 24,
                height: 24,
                child: CircularProgressIndicator(
                  strokeWidth: 2.5,
                  valueColor: AlwaysStoppedAnimation<Color>(foregroundColor),
                ),
              )
              : Text(text),
    );
  }
}
