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

import '../../../../../../application/user/user_edit_form/user_edit_form_bloc.dart';
import '../../../../../../common/extension/extension.dart';
import '../../../../../components/field/field.dart';

class ProfileEditNameField extends StatelessWidget {
  final TextEditingController controller;
  const ProfileEditNameField({super.key, required this.controller});

  @override
  Widget build(BuildContext context) {
    return AppTextFormField(
      title: context.lang.name,
      prefixIcon: LineIcons.user,
      hintText: context.lang.name_placeholder,
      controller: controller,
      onChanged: (value) {
        context.read<UserEditFormBloc>().add(
          UserEditFormEvent.nameChanged(value),
        );
      },
      validator: (value) {
        if (context.read<UserEditFormBloc>().state.name.isEmpty) {
          return context.lang.name_placeholder;
        }

        return null;
      },
    );
  }
}
