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 ChangePasswordCurrentPassword extends StatelessWidget {
  const ChangePasswordCurrentPassword({super.key});

  @override
  Widget build(BuildContext context) {
    return AppPasswordTextFormField(
      title: context.lang.current_password,
      prefixIcon: LineIcons.lock,
      hintText: context.lang.current_password_placeholder,
      onChanged: (value) => context.read<ChangePasswordFormBloc>().add(
        ChangePasswordFormEvent.currentPasswordChanged(value),
      ),
      validator: (value) {
        if (context
            .read<ChangePasswordFormBloc>()
            .state
            .currentPassword
            .isEmpty) {
          return context.lang.current_password_placeholder;
        }
        return null;
      },
    );
  }
}
