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

class LoginInput extends StatelessWidget {
  final String hintText;
  final int maxLength;
  final TextEditingController controller;
  final Widget? suffix;

  const LoginInput({
    super.key,
    required this.hintText,
    this.maxLength = 11,
    required this.controller,
    this.suffix,
  });

  @override
  Widget build(BuildContext context) {
    return TextField(
      controller: controller,
      maxLength: maxLength,
      keyboardType: TextInputType.number,
      inputFormatters: [
        FilteringTextInputFormatter.digitsOnly, // 只允许 0-9
      ],
      decoration: InputDecoration(
        hintText: hintText,
        hintStyle: Theme.of(context).textTheme.labelLarge?.copyWith(fontSize: 16),
        counterText: '',
        filled: true,
        fillColor: Theme.of(context).colorScheme.surfaceContainer,
        border: OutlineInputBorder(
          borderRadius: BorderRadius.circular(60),
          borderSide: BorderSide.none, // 去掉边框
        ),
        isCollapsed: true,
        contentPadding: EdgeInsets.symmetric(vertical: 14, horizontal: 20),
        suffixIconConstraints: BoxConstraints(minWidth: 0, minHeight: 0),
        suffixIcon: suffix != null
            ? Container(
                padding: EdgeInsets.only(right: 20),
                child: suffix,
              )
            : null,
      ),
    );
  }
}
