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 'package:tanami_app/features/forgotPassword/presentation/bloc/restore_password_bloc.dart';

import '../../../../shared/components/bloc/password_field/password_visibility_bloc.dart';
import '../../../../shared/components/form_label_textfield.dart';

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

  @override
  Widget build(BuildContext 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: AppText.enterPassword,
                  title: "New Password",
                  type: AppText.password.toLowerCase(),
                  textEditingController: restorePasswordBloc.passwordTextField,
                ),
              ),
              const Gap(12),
              BlocProvider(
                create: (_) => PasswordVisibilityBloc(),
                child: FormLabelTextField(
                  hintText: AppText.repeatPasswordText,
                  title: AppText.repeatPasswordText,
                  type: AppText.password.toLowerCase(),
                  textEditingController:
                      restorePasswordBloc.repeatPasswordTextField,
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }
}
