import 'package:flutter/material.dart';

class VInput extends StatelessWidget {
  final String? placeholder;
  final String? initialValue;
  final TextEditingController? controller;
  final FocusNode? focusNode;
  final ValueChanged<String>? onChanged;
  final VoidCallback? onTap;
  final bool? readOnly;
  final double? radius;
  final Widget? suffixIcon;
  final int? maxLines;

  const VInput({
    super.key,
    this.initialValue,
    this.controller,
    this.focusNode,
    this.placeholder,
    this.onChanged,
    this.onTap,
    this.readOnly = false,
    this.radius,
    this.suffixIcon,
    this.maxLines = 1,
  });

  @override
  Widget build(BuildContext context) {
    final c = controller ?? TextEditingController(text: initialValue);
    final borderRadius = BorderRadius.all(Radius.circular(radius ?? 0));
    return TextField(
      controller: c,
      textAlign: TextAlign.start,
      textAlignVertical: TextAlignVertical.center,
      maxLines: maxLines,
      decoration: InputDecoration(
        enabledBorder: OutlineInputBorder(
          borderRadius: borderRadius,
          borderSide: const BorderSide(color: Colors.grey),
        ),
        focusedBorder: OutlineInputBorder(
          borderRadius: borderRadius,
          borderSide: BorderSide(color: Theme.of(context).primaryColor),
        ),
        errorBorder: OutlineInputBorder(
          borderRadius: borderRadius,
          borderSide: BorderSide(color: Theme.of(context).colorScheme.error),
        ),
        suffixIcon: suffixIcon,
        // errorText: "112323",
        errorMaxLines: 1,
        fillColor: Colors.white,
        filled: true,
        hintText: placeholder,
        hintStyle: const TextStyle(
          fontSize: 16,
          color: Colors.black54,
        ),
        contentPadding: const EdgeInsets.symmetric(horizontal: 8, vertical: 8),
        // isDense: true,
        isCollapsed: false,
      ),
      onChanged: (value) {
        onChanged?.call(value);
      },
      onTap: () {
        onTap?.call();
      },
      readOnly: readOnly!,
    );
  }
}