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

import '../../../../../application/auth/register_form/register_form_bloc.dart';
import '../../../../components/field/field.dart';

class RegisterNameField extends StatelessWidget {
  const RegisterNameField({super.key});

  @override
  Widget build(BuildContext context) {
    return AppTextFormField(
      title: 'Masukkan nama',
      hintText: 'John Doe',
      onChanged: (value) {
        context.read<RegisterFormBloc>().add(
          RegisterFormEvent.nameChanged(value),
        );
      },
      validator: (value) {
        if (context.read<RegisterFormBloc>().state.name.isEmpty) {
          return 'Masukkan nama';
        }

        return null;
      },
    );
  }
}
