import 'package:flutter/material.dart';
import 'package:taxglide/consts/app_colors.dart';

class CommanButton extends StatelessWidget {
  final String text;
  final VoidCallback onPressed;
  final String? backgroundImage; // optional bg image
  final Widget? prefixIcon; // optional prefix icon

  const CommanButton({
    super.key,
    required this.text,
    required this.onPressed,
    this.backgroundImage,
    this.prefixIcon,
  });

  @override
  Widget build(BuildContext context) {
    return SizedBox(
      width: double.infinity,
      height: 57,
      child: InkWell(
        onTap: onPressed,
        borderRadius: BorderRadius.circular(8),
        child: Container(
          decoration: BoxDecoration(
            borderRadius: BorderRadius.circular(8),
            color: AppColors.commanbutton,  // base color (visible always)

            image: backgroundImage != null
                ? DecorationImage(
                    image: AssetImage(backgroundImage!),
                    fit: BoxFit.cover,

                    // 🔥 THIS MAKES BOTH IMAGE + COLOR VISIBLE
                    colorFilter: ColorFilter.mode(
                      AppColors.commanbutton.withOpacity(0.5),
                      BlendMode.srcATop, 
                    ),
                  )
                : null,
          ),
          child: Center(
            child: Row(
              mainAxisSize: MainAxisSize.min,
              children: [
                if (prefixIcon != null) ...[
                  prefixIcon!,
                  const SizedBox(width: 8),
                ],
                Text(
                  text,
                  style: const TextStyle(
                    fontFamily: 'Gilroy-Medium',
                    fontWeight: FontWeight.w500,
                    fontSize: 16,
                    height: 1.4,
                    letterSpacing: 0.03 * 16,
                    color: Colors.white,
                  ),
                ),
              ],
            ),
          ),
        ),
      ),
    );
  }
}
