import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:taafee_mobile/common/const/const.dart';
import 'package:taafee_mobile/common/extensions/widget_extension.dart';
import 'package:taafee_mobile/common/widgets/text.dart';

class ButtonWidget extends StatelessWidget {
  final VoidCallback onTap;
  final String title;
  final Color? color;
  final bool? haveIcon;
  final Widget? child;
  final double? width;
  final Color? textColor;
  final Color? loaderColor;
  final bool? isLoading;
  final double? buttonHeight;
  final bool hideTextOnLoading;
  final double? fontSize;
  final bool columnShapeOnLoading;
  const ButtonWidget({
    super.key,
    required this.onTap,
    required this.title,
    this.color,
    this.hideTextOnLoading = false,
    this.haveIcon = false,
    this.child,
    this.loaderColor,
    this.width,
    this.buttonHeight,
    this.fontSize,
    this.textColor,
    this.isLoading = false,
    this.columnShapeOnLoading = false,
  });

  @override
  Widget build(BuildContext context) {
    return Container(
      alignment: Alignment.center,
      width: width ?? Get.width * 0.9,
      height: buttonHeight ?? 55,
      decoration: BoxDecoration(
          borderRadius: BorderRadius.circular(30),
          color: color ?? AppColors.primeColor),
      child: haveIcon!
          ? Row(mainAxisAlignment: MainAxisAlignment.center, children: [
              child ?? Container(),
              BoldTextWidget(
                title,
                fontSize: fontSize,
                color: textColor ?? Colors.white,
              ).paddingSymmetric(horizontal: 10),
            ])
          : isLoading!
              //wrap (Loader with visibility instead of repeating it)
              ? (columnShapeOnLoading)
                  ? Column(
                      mainAxisAlignment: MainAxisAlignment.center,
                      children: [
                        Visibility(
                          visible: !((isLoading != null) &&
                              hideTextOnLoading &&
                              isLoading!),
                          child: BoldTextWidget(
                            title,
                            fontSize: fontSize,
                            textAlign: TextAlign.center,
                            color: textColor ?? Colors.white,
                          ).paddingSymmetric(horizontal: 20),
                        ),
                        SizedBox(
                          width: 20,
                          height: 20,
                          child: CircularProgressIndicator(
                            color: loaderColor ?? Colors.white,
                          ),
                        ),
                      ],
                    )
                  : Row(
                      mainAxisAlignment: MainAxisAlignment.center,
                      children: [
                        Visibility(
                          visible: !((isLoading != null) &&
                              hideTextOnLoading &&
                              isLoading!),
                          child: BoldTextWidget(
                            title,
                            fontSize: fontSize,
                            textAlign: TextAlign.center,
                            color: textColor ?? Colors.white,
                          ).paddingSymmetric(horizontal: 20),
                        ),
                        SizedBox(
                          width: 20,
                          height: 20,
                          child: CircularProgressIndicator(
                            color: loaderColor ?? Colors.white,
                          ),
                        ),
                      ],
                    )
              : BoldTextWidget(
                  title,
                  fontSize: fontSize,
                  textAlign: TextAlign.center,
                  color: textColor ?? Colors.white,
                ),
    ).onTap(() {
      if (isLoading == null || !isLoading!) onTap();
    });
    // return InkWell(
    //   onTap: onTap,
    //   child: BoldTextWidget(title),
    // );
  }
}
