/* Created by Nitesh Kumar Verma on 15/12/23 */

import 'dart:developer';

import 'package:exide_crr/res/app_color_text_size.dart';
import 'package:exide_crr/utils/helper_class.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:exide_crr/constants/font_constants.dart';

class CustomButton extends StatelessWidget {
  /// Button name title
  final String buttonName;

  /// The callback called when the onTap button clicked
  final VoidCallback onTap;

  double height;
  double width;

  /// top margin
  double topMargin = 24;

  /// bottom margin
  double bottomMargin = 30;

  double borderRadius = 16;

  Color? backgroundColor;
  Color? activeBackgroundColor;
  Color? foregroundColor;
  Color borderColor = AppColor.transparent;

  bool isLoading = false;
  bool isActive = false;
  bool showSuffixIcon = false;

  CustomButton({
    Key? key,
    required this.buttonName,
    required this.onTap,
    this.topMargin = 24,
    this.height = 55,
    this.width = 350,
    this.bottomMargin = 30,
    this.borderRadius = 8,
    this.isLoading = false,
    this.isActive = false,
    this.showSuffixIcon = false,
    this.backgroundColor = AppColor.blackColor,
    this.activeBackgroundColor = AppColor.blackColor,
    this.foregroundColor = AppColor.whiteColor,
    this.borderColor = AppColor.transparent,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    log("${isLoading || !isActive}");
    return Align(
      alignment: Alignment.center,
      child: IgnorePointer(
        ignoring: isLoading || !isActive,
        child: InkWell(
          /// button click event
          onTap: onTap,
          child: Container(
            width: width,
            height: height,
            padding: EdgeInsets.symmetric(vertical: 0.h, horizontal: 24.w),
            alignment: Alignment.center,
            decoration: BoxDecoration(
                color: isActive
                    ? activeBackgroundColor
                    : AppColor.inActiveButtonColor,
                borderRadius: BorderRadius.circular(borderRadius),
                border: Border.all(color: borderColor, width: 1)),
            child: isLoading
                ? HelperClass.spinkit
                : Row(
                    crossAxisAlignment: CrossAxisAlignment.center,
                    mainAxisSize: MainAxisSize.min,
                    children: [
                      Expanded(
                        child: Text(
                          /// button name
                          buttonName,
                          style: GoogleFonts.getFont(
                            FontConstants.fontFamilyName,
                            fontSize: TextSize.textButtonSize,
                            fontWeight: FontWeight.w700,
                            color: foregroundColor,
                            fontStyle: FontStyle.normal,
                          ),
                          textAlign: TextAlign.center,
                          maxLines: 1,
                          overflow: TextOverflow.ellipsis,
                        ),
                      ),
                      Visibility(
                        visible: showSuffixIcon,
                        child: Container(
                          margin: EdgeInsets.only(left: 4.w),
                          child: Icon(
                            Icons.arrow_forward,
                            color: AppColor.white,
                            size: 12.w,
                          ),
                        ),
                      ),
                    ],
                  ),
          ),
        ),
      ),
    );
  }
}