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

import '../../../../../../application/user/change_password_form/change_password_form_bloc.dart';
import '../../../../../../common/extension/extension.dart';
import '../../../../../components/field/field.dart';

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

  @override
  Widget build(BuildContext context) {
    return AppPasswordTextFormField(
      title: context.lang.new_password,
      prefixIcon: LineIcons.lock,
      hintText: context.lang.new_password_placeholder,
      onChanged: (value) => context.read<ChangePasswordFormBloc>().add(
        ChangePasswordFormEvent.newPasswordChanged(value),
      ),
      validator: (value) {
        if (context.read<ChangePasswordFormBloc>().state.newPassword.isEmpty) {
          return context.lang.new_password_placeholder;
        }

        if (context.read<ChangePasswordFormBloc>().state.newPassword ==
            context.read<ChangePasswordFormBloc>().state.currentPassword) {
          return context.lang.new_password_not_same;
        }
        return null;
      },
    );
  }
}
