import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

class CustomTextField {
  static Widget normalTextField({
    bool readOnly = false,
    bool obscureText = false,
    TextEditingController? controller,
    String? labelText,
    String? hintText,
    FocusNode? focusNode,
    TextInputType? keyboardType,
    Widget? animation,
    List<TextInputFormatter>? inputFormatters,
    void Function()? onTap,
  }) {
    return Padding(
      padding: EdgeInsets.symmetric(horizontal: 12),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.stretch,
        children: [
          if (labelText != null)
            Row(
              mainAxisAlignment:
                  animation != null
                      ? MainAxisAlignment.spaceBetween
                      : MainAxisAlignment.start,
              crossAxisAlignment: CrossAxisAlignment.end,
              children: [
                Padding(
                  padding: const EdgeInsets.only(bottom: 5),
                  child: Text(
                    labelText,
                    style: TextStyle(
                      fontWeight: FontWeight.w500,
                      fontFamily: 'FiraCode',
                    ),
                  ),
                ),
                animation ?? SizedBox(),
              ],
            ),
          Stack(
            children: [
              TextFormField(
                decoration: InputDecoration(
                  contentPadding: EdgeInsets.symmetric(horizontal: 12),
                  enabledBorder: OutlineInputBorder(
                    borderSide: BorderSide(
                      width: 1,
                      color: Colors.black,
                      style: BorderStyle.solid,
                    ),
                    borderRadius: BorderRadius.circular(8),
                  ),
                ),
              ),
              TextFormField(
                cursorWidth: 1,
                cursorHeight: 16,
                controller: controller,
                readOnly: readOnly,
                focusNode: focusNode,
                obscureText: obscureText,
                cursorColor: Colors.black,
                keyboardType: keyboardType,
                onTap: onTap,
                style: TextStyle(
                  fontWeight: FontWeight.w400,
                  fontSize: 14,
                  color: Colors.black,
                  fontFamily: 'FiraCode',
                ),
                decoration: InputDecoration(
                  contentPadding: EdgeInsets.symmetric(horizontal: 12),
                  hintText: hintText,
                  hintStyle: TextStyle(
                    fontWeight: FontWeight.w500,
                    fontSize: 12,
                    color: Colors.grey.shade500,
                    fontFamily: 'FiraCode',
                  ),
                  focusedBorder: UnderlineInputBorder(
                    borderSide: BorderSide(
                      width: 5,
                      color: Colors.black,
                      style: BorderStyle.solid,
                    ),
                    borderRadius: BorderRadius.circular(8),
                  ),
                  // Garis bawah lebih tebal saat fokus
                  border: OutlineInputBorder(
                    borderRadius: BorderRadius.circular(8),
                    borderSide: BorderSide(
                      width: 1, // Border normal
                      color: Colors.grey,
                    ),
                  ),
                ),
                inputFormatters: inputFormatters,
              ),
            ],
          ),
        ],
      ),
    );
  }
}
