import 'package:control_style/control_style.dart';
import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:tanami_app/core/styles/app_color.dart';

Widget textFormField({
  final dynamic validator,
  final TextEditingController? textEditingController,
  final String? hintText,
  final Widget? leadingIcon,
  final Color? prefixIconColor,
  final String? validatorText,
  final String? value,
  final bool? readonly,
  final bool? enabled,
  final int? maxlines,
  final TextInputType? texttype,
  final dynamic inputFormatters,
  final Function(String)? onInput,
  final VoidCallback? onTap,
  final TextCapitalization? textCapV,
  final Widget? suffixIcon,
  final TextAlign? txtAlign,
}) {
  return TextFormField(
    textAlign: txtAlign ?? TextAlign.start,
    validator: validator,
    textAlignVertical: TextAlignVertical.center,
    cursorColor: AppColor.primaryColor2,
    initialValue: value,
    readOnly: readonly!,
    onTap: onTap,
    enabled: enabled,
    maxLines: maxlines,
    autovalidateMode: AutovalidateMode.onUserInteraction,
    controller: textEditingController,
    textCapitalization: textCapV ?? TextCapitalization.none,
    decoration: InputDecoration(
      fillColor: AppColor.plainWhite,
      filled: true,
      hintStyle: GoogleFonts.dmSans(
        color: AppColor.hintTextColor,
        fontSize: 15,
        fontWeight: FontWeight.w400,
      ),
      hintText: hintText,
      prefixIconColor: prefixIconColor,
      prefixIcon: leadingIcon,
      errorStyle: GoogleFonts.dmSans(
        color: AppColor.txtErrorColor,
        fontSize: 14,
        fontWeight: FontWeight.w400,
      ),
      suffixIcon: suffixIcon,
      border: DecoratedInputBorder(
        child: OutlineInputBorder(
          borderRadius: BorderRadius.circular(12.0),
          borderSide: const BorderSide(color: AppColor.txtBorderColor),
        ),
        shadow: const [
          BoxShadow(
            color: AppColor.txtBorderShadowColor,
            blurRadius: 2,
            offset: Offset(0, 1),
            spreadRadius: 0.50,
          )
        ],
      ),
      contentPadding:
          const EdgeInsets.symmetric(vertical: 16.0, horizontal: 16.0),
      errorBorder: DecoratedInputBorder(
        child: OutlineInputBorder(
          borderRadius: BorderRadius.circular(12.0),
          borderSide: const BorderSide(color: AppColor.txtErrorBorderColor),
        ),
        shadow: const [
          BoxShadow(
            color: AppColor.txtBorderShadowColor,
            blurRadius: 2,
            offset: Offset(0, 1),
            spreadRadius: 0.50,
          )
        ],
      ),
      disabledBorder: DecoratedInputBorder(
        child: OutlineInputBorder(
          borderRadius: BorderRadius.circular(12.0),
          borderSide: const BorderSide(color: AppColor.txtBorderColor),
        ),
        shadow: const [
          BoxShadow(
            color: AppColor.txtBorderShadowColor,
            blurRadius: 2,
            offset: Offset(0, 1),
            spreadRadius: 0.50,
          )
        ],
      ),
      enabledBorder: DecoratedInputBorder(
        child: OutlineInputBorder(
          borderRadius: BorderRadius.circular(12.0),
          borderSide: const BorderSide(color: AppColor.txtBorderColor),
        ),
        shadow: const [
          BoxShadow(
            color: AppColor.txtBorderShadowColor,
            blurRadius: 2,
            offset: Offset(0, 1),
            spreadRadius: 0.50,
          )
        ],
      ),
      focusedBorder: DecoratedInputBorder(
        child: OutlineInputBorder(
          borderRadius: BorderRadius.circular(12.0),
          borderSide: const BorderSide(color: AppColor.txtBorderColor),
        ),
        shadow: const [
          BoxShadow(
            color: AppColor.txtBorderShadowColor,
            blurRadius: 2,
            offset: Offset(0, 1),
            spreadRadius: 0.50,
          )
        ],
      ),
    ),
    style: GoogleFonts.dmSans(
      color: AppColor.charcoalColor,
      fontSize: 14,
      fontWeight: FontWeight.w500,
    ),
    keyboardType: texttype,
    inputFormatters: inputFormatters,
    onChanged: (value) {
      onInput?.call(value);
    },
  );
}
