import 'package:flutter/material.dart';
import 'package:mc_common_app/extensions/string_extensions.dart';
import 'package:mc_common_app/theme/colors.dart';
import 'package:mc_common_app/widgets/extensions/extensions_widget.dart';
import 'package:mc_common_app/classes/consts.dart';

class ShowFillButton extends StatelessWidget {
  final String title;
  final Color? backgroundColor;
  final VoidCallback onPressed;
  final Color txtColor;
  final double elevation, radius, maxWidth, maxHeight, fontSize, horizontalPadding, horizontalMargin, verticalMargin;
  final bool isFlatButton, isBold;
  final EdgeInsets? margin;
  final bool isFilled;
  final bool isDisabled;
  final Color borderColor;
  final Widget? iconWidget;

  const ShowFillButton({
    super.key,
    required this.title,
    required this.onPressed,
    this.txtColor = Colors.white,
    this.backgroundColor = MyColors.darkPrimaryColor,
    this.elevation = 0,
    this.isFilled = true,
    this.isDisabled = false,
    this.radius = 0,
    this.maxWidth = 88,
    this.maxHeight = 55,
    this.fontSize = 18,
    this.horizontalPadding = 16,
    this.isFlatButton = false,
    this.isBold = false,
    this.horizontalMargin = 0,
    this.verticalMargin = 0,
    this.margin,
    this.iconWidget,
    this.borderColor = MyColors.primaryColor,
  });

  @override
  Widget build(BuildContext context) {
    return isFlatButton
        ? Container(
            height: maxHeight,
            padding: const EdgeInsets.only(
              left: 20,
              right: 20,
            ),
            child: showButton(),
          )
        : Padding(
            padding: margin ?? const EdgeInsets.all(0.0),
            child: ConstrainedBox(
              constraints: BoxConstraints(
                minHeight: maxHeight,
                minWidth: maxWidth,
                maxHeight: maxHeight,
                maxWidth: maxWidth,
              ),
              child: showButton(),
            ),
          );
  }

  Widget showButton() {
    return Container(
      // decoration: isFlatButton ? null : MyColors.gradientButton,
      color: isDisabled
          ? MyColors.grey98Color.withOpacity(0.3)
          : (isFlatButton
              ? null
              : isFilled
                  ? backgroundColor
                  : null),
      margin: EdgeInsets.symmetric(horizontal: horizontalMargin, vertical: verticalMargin),
      child: MaterialButton(
        onPressed: onPressed,
        shape: RoundedRectangleBorder(
          borderRadius: BorderRadius.circular(radius),
          side: isFilled ? BorderSide.none : BorderSide(width: 2, color: borderColor),
        ),
        child: iconWidget != null
            ? Row(
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  iconWidget!,
                  title.toText(
                    fontSize: fontSize,
                    isBold: isBold,
                    fontWeight: MyFonts.Medium,
                    color: isDisabled ? MyColors.lightTextColor : txtColor,
                    maxLines: 1,
                  ),
                ],
              )
            : title.toText(
                fontSize: fontSize,
                isBold: isBold,
                fontWeight: MyFonts.Medium,
                color: isDisabled ? MyColors.lightTextColor : txtColor,
                maxLines: 1,
              ),
      ),
    );
  }
}
