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

class CommanTextFormField extends StatelessWidget {
  final String? hintText;
  final TextEditingController? controller;
  final TextInputType? keyboardType;
  final bool obscureText;
  final bool readOnly;
  final String? Function(String?)? validator;
  final IconData? prefixIcon;
  final bool hasError;
  final Function(String)? onChanged;
  final FocusNode? focusNode;
  final VoidCallback? onTap;

  /// ✅ NEW
  final List<TextInputFormatter>? inputFormatters;
  final TextCapitalization textCapitalization;

  const CommanTextFormField({
    Key? key,
    this.hintText,
    this.controller,
    this.keyboardType,
    this.obscureText = false,
    this.readOnly = false,
    this.validator,
    this.prefixIcon,
    this.hasError = false,
    this.onChanged,
    this.focusNode,
    this.onTap,

    /// ✅ DEFAULTS
    this.inputFormatters,
    this.textCapitalization = TextCapitalization.none,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return SizedBox(
      width: double.infinity,
      height: 56,
      child: TextFormField(
        focusNode: focusNode,
        controller: controller,
        keyboardType: keyboardType,
        obscureText: obscureText,
        validator: validator,
        onChanged: onChanged,
        onTap: onTap,
        readOnly: readOnly,

        /// ✅ APPLIED HERE
        inputFormatters: inputFormatters,
        textCapitalization: textCapitalization,

        cursorColor: readOnly ? Colors.transparent : AppColors.authleading,
        decoration: InputDecoration(
          hintText: hintText,
          filled: true,
          fillColor: readOnly ? const Color(0xFFF6F6F6) : Colors.white,
          contentPadding: const EdgeInsets.symmetric(
            horizontal: 16,
            vertical: 16,
          ),
          prefixIcon: prefixIcon != null
              ? Icon(prefixIcon, color: AppColors.authleading)
              : null,
          hintStyle: AppTextStyles.medium.copyWith(
            fontSize: 11.31,
            height: 1.4,
            letterSpacing: 0.03,
            color: hasError
                ? Colors.red.withOpacity(0.6)
                : AppColors.authleading
          ),
          border: OutlineInputBorder(
            borderRadius: BorderRadius.circular(6),
            borderSide: BorderSide(
              color: hasError
                  ? Colors.red
                  : readOnly
                  ? AppColors.authleading
                  : const Color(0xFFDFDFDF),
              width: 1,
            ),
          ),
          enabledBorder: OutlineInputBorder(
            borderRadius: BorderRadius.circular(6),
            borderSide: BorderSide(
              color: hasError
                  ? Colors.red
                  : readOnly
                  ? Colors.grey.shade300
                  : const Color(0xFFDFDFDF),
              width: 1,
            ),
          ),
          focusedBorder: OutlineInputBorder(
            borderRadius: BorderRadius.circular(6),
            borderSide: BorderSide(
              color: hasError
                  ? Colors.red
                  : readOnly
                  ? Colors.grey.shade400
                  : Colors.blue,
              width: 1,
            ),
          ),
        ),
        style: AppTextStyles.medium.copyWith(
          fontSize: 11.31,
          height: 1.4,
          letterSpacing: 0.03,
          color: readOnly ? AppColors.authleading : AppColors.authleading,
        ),
      ),
    );
  }
}
