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

class InputField extends StatefulWidget {
  final String hintText;
  final String labelText;
  final TextEditingController controller;
  final bool obscureText;
  final TextInputType? keyboardType;
  final String? Function(String?)? validator;// Add this line for validation

   InputField({
    super.key,
    required this.hintText,
    required this.labelText,
    required this.controller,
    this.obscureText = false,
    this.keyboardType = TextInputType.text,
    this.validator, // Add this
  });

  @override
  State<InputField> createState() => _InputFieldState();
}

class _InputFieldState extends State<InputField> {
  bool _isObscured = true;

  @override
  Widget build(BuildContext context) {
    return Container(
      height: 65,
      width: Get.width * 0.9,
      padding: const EdgeInsets.fromLTRB(6, 10, 10, 0),
      child: TextFormField(
        controller: widget.controller,
        obscureText: widget.obscureText && _isObscured,
        keyboardType: widget.keyboardType,
        decoration: InputDecoration(
          labelText: widget.labelText,
          hintText: widget.hintText,
          labelStyle: const TextStyle(
            color: Color(0xFF000000),
          ),

          enabledBorder: const OutlineInputBorder(
            borderSide: BorderSide(color: Colors.grey),
            borderRadius: BorderRadius.all(Radius.circular(8)),
          ),
          focusedBorder: const OutlineInputBorder(
            borderSide: BorderSide(color: Colors.blue),
            borderRadius: BorderRadius.all(Radius.circular(8)),
          ),
          contentPadding:
          const EdgeInsets.symmetric(vertical: 10, horizontal: 16),
          fillColor: Colors.white,
          filled: true,
          // suffixIcon: widget.obscureText
          //     ? IconButton(
          //   icon: Icon(
          //     _isObscured ? Icons.visibility : Icons.visibility_off,
          //     color: Colors.grey,
          //   ),
          //   onPressed: () {
          //     setState(() {
          //       _isObscured = !_isObscured;
          //     });
          //   },
          // )
          //     : null,
        ),
        validator: widget.validator, // Add this for validation
      ),
    );
  }
}
