import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:gap/gap.dart';
import 'package:tanami_app/core/styles/app_text.dart';

import '../../../../core/utils/language/localizations_delegate.dart';
import '../../../../shared/components/bloc/password_field/password_visibility_bloc.dart';
import '../../../../shared/components/form_label_textfield.dart';
import '../bloc/restore_password_bloc.dart';

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

  @override
  Widget build(BuildContext context) {
    var localizations = AppLocalizations.of(context);
    final restorePasswordBloc = context.read<RestorePasswordBloc>();

    // Reset fields when the screen is built
    restorePasswordBloc.resetFields();

    return Form(
      key: restorePasswordBloc.formKey,
      child: Padding(
        padding: const EdgeInsets.symmetric(
          horizontal: 14,
        ),
        child: Align(
          alignment: Alignment.topLeft,
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              const Gap(50),
              BlocProvider(
                create: (_) => PasswordVisibilityBloc(),
                child: FormLabelTextField(
                  hintText: localizations.translate(AppText.enterPassword),
                  title: localizations.translate(AppText.newPasswordText),
                  type: AppText.password.toLowerCase(),
                  textEditingController: restorePasswordBloc.passwordTextField,
                ),
              ),
              const Gap(12),
              BlocProvider(
                create: (_) => PasswordVisibilityBloc(),
                child: FormLabelTextField(
                  hintText: localizations.translate(AppText.repeatPasswordText),
                  title: localizations.translate(AppText.repeatPasswordText),
                  type: AppText.password.toLowerCase(),
                  textEditingController:
                      restorePasswordBloc.repeatPasswordTextField,
                  originalPasswordController:
                      restorePasswordBloc.passwordTextField,
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }
}
