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

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

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

    return Form(
      key: registerUserBloc.formKey,
      child: Padding(
        padding: const EdgeInsets.symmetric(
          horizontal: 14,
        ),
        child: Align(
          alignment: Alignment.topLeft,
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              const Gap(50),
              FormLabelTextField(
                hintText: localizations.translate(AppText.enterFirstName),
                title: localizations.translate(AppText.firstNameText),
                type: "first name",
                textEditingController: registerUserBloc.firstNameTextField,
              ),
              const Gap(12),
              FormLabelTextField(
                hintText: localizations.translate(AppText.enterLastName),
                title: localizations.translate(AppText.lastNameText),
                type: "first name",
                textEditingController: registerUserBloc.lastNameTextField,
              ),
              const Gap(12),
              FormLabelTextField(
                hintText: localizations.translate(AppText.enterEmail),
                title: localizations.translate(AppText.emailText),
                type: "email",
                textEditingController: registerUserBloc.emailTextField,
              ),
              const Gap(12),
              BlocProvider(
                create: (_) => PasswordVisibilityBloc(),
                child: FormLabelTextField(
                  hintText: localizations.translate(AppText.enterPassword),
                  title: localizations.translate(AppText.password),
                  type: AppText.password.toLowerCase(),
                  textEditingController: registerUserBloc.passwordTextField,
                ),
              ),
              const Gap(12),
              BlocProvider(
                create: (_) => PasswordVisibilityBloc(),
                child: FormLabelTextField(
                  hintText: localizations.translate(AppText.repeatPasswordText),
                  title: localizations.translate(AppText.repeatPasswordText),
                  type: "repeat-password",
                  textEditingController:
                      registerUserBloc.repeatPasswordTextField,
                  originalPasswordController:
                      registerUserBloc.passwordTextField,
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }
}
