import 'package:flutter/material.dart';

import '../utils/nir_utils.dart';
import 'custom_app_text_field.dart';

/// Champ de saisie dédié au NIR (Numéro d'Inscription au Répertoire – 15 caractères).
/// Format affiché : 1 12 34 56 789 012-34 ou 1 12 34 2A 789 012-34 pour la Corse.
/// La valeur envoyée au [controller] est formatée ; utiliser [normalizeNir](controller.text) à la soumission.
class NirTextField extends StatelessWidget {
  final TextEditingController controller;
  final String labelText;
  final String hintText;
  final String? Function(String?)? validator;
  final double fieldWidth;
  final double fieldHeight;
  final double labelFontSize;
  final double inputFontSize;
  final bool enabled;
  final bool readOnly;
  final CustomAppTextFieldStyle style;

  const NirTextField({
    super.key,
    required this.controller,
    this.labelText = 'N° Sécurité Sociale (NIR)',
    this.hintText = '15 car. (ex. 1 12 34 56 789 012-34 ou 2A Corse)',
    this.validator,
    this.fieldWidth = double.infinity,
    this.fieldHeight = 53.0,
    this.labelFontSize = 18.0,
    this.inputFontSize = 18.0,
    this.enabled = true,
    this.readOnly = false,
    this.style = CustomAppTextFieldStyle.beige,
  });

  @override
  Widget build(BuildContext context) {
    return CustomAppTextField(
      controller: controller,
      labelText: labelText,
      hintText: hintText,
      fieldWidth: fieldWidth,
      fieldHeight: fieldHeight,
      labelFontSize: labelFontSize,
      inputFontSize: inputFontSize,
      keyboardType: TextInputType.text,
      validator: validator ?? validateNir,
      inputFormatters: [NirInputFormatter()],
      enabled: enabled,
      readOnly: readOnly,
      style: style,
    );
  }
}
