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 '../../../../../components/field/field.dart';

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

  @override
  Widget build(BuildContext context) {
    return AppPasswordTextFormField(
      title: 'New Password',
      prefixIcon: LineIcons.lock,
      hintText: 'Please enter your new password',
      onChanged: (value) => context.read<ChangePasswordFormBloc>().add(
        ChangePasswordFormEvent.newPasswordChanged(value),
      ),
      validator: (value) {
        if (context.read<ChangePasswordFormBloc>().state.newPassword.isEmpty) {
          return 'Please enter your new password';
        }

        if (context.read<ChangePasswordFormBloc>().state.newPassword ==
            context.read<ChangePasswordFormBloc>().state.currentPassword) {
          return 'New password cannot be same as current password';
        }
        return null;
      },
    );
  }
}
