import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:rkm/widgets/title_input.dart';
import '../config/color_palette.dart';
import '../controllers/format_txt.dart';
import 'error_default.dart';
import 'input_text.dart';

class InputWithSubtitle extends StatelessWidget {
  String subtitle;
  String hintInput;
  String errorInput;
  String labelInput;
  double widthSubtitle;
  double widthInput;
  double widthError;
  TextEditingController controller;
  var onChanged;
  bool enabled;
  bool mandatory;
  TextInputType textInputType;
  int maxLines;
  Color colorBorder;
  String typeInput;
  int maxLength;
  List<TextInputFormatter> inputFormatters;

  InputWithSubtitle({
    required this.subtitle,
    required this.hintInput,
    required this.errorInput,
    required this.labelInput,
    required this.widthSubtitle,
    required this.widthInput,
    required this.controller,
    this.typeInput = 'normal',
    this.enabled = true,
    this.mandatory = true,
    this.textInputType = TextInputType.text,
    this.maxLines = 1,
    this.colorBorder = ColorPalette.white,
    required this.onChanged,
    this.widthError = 0.7,
    this.maxLength = 200,
    List<TextInputFormatter>? inputFormatters, // Alteração aqui
  }) : inputFormatters = inputFormatters ?? [FormatText()];

  @override
  Widget build(BuildContext context) {

    List splited = controller.text.trim().split(' ');

    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        TitleInput(title:labelInput),
        InputText(
          controller: controller,
          width: widthInput,
          title: hintInput,
          enabled: enabled,
          textInputType: textInputType,
          maxLines:maxLines,
          colorBorder: colorBorder,
          onChanged: onChanged,
          maxLength: maxLength,
          inputFormatters: inputFormatters,
        ),
        typeInput=='normal'&&(enabled&&mandatory) && (labelInput=='Nome' && splited.length<=1) ?ErrorDefault(widthDefault: widthError,error: errorInput,):Container(),
        typeInput!='normal'&&(enabled&&mandatory)&& errorInput!=''?ErrorDefault(widthDefault: widthError,error: errorInput,):Container(),
        Divider(color: ColorPalette.black54,height: 5,endIndent: 10,)
      ],
    );
  }
}
