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,
    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,
    this.child,
    this.enabled = true,
    this.progress = 0.0, // اضافه شد
  }) : assert(text != null || child != null, 'Either text or child must be provided');

  final String? text;
  final Widget? child;
  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;
  final bool enabled;
  final double progress; // 0.0 تا 1.0
  @override
  Widget build(BuildContext context) {
    final bool isEnabled = enabled && !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),
                value: progress > 0.0 && progress <= 1.0 ? progress : null,
              ),
            )
          : child ?? Text(text!),
    );
  }
}
