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 '../../../../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) {
    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: AppText.enterFirstName,
                title: AppText.firstNameText,
                type: AppText.firstNameText,
                textEditingController: registerUserBloc.firstNameTextField,
              ),
              const Gap(12),
              FormLabelTextField(
                hintText: AppText.enterLastName,
                title: AppText.lastNameText,
                type: AppText.lastNameText,
                textEditingController: registerUserBloc.lastNameTextField,
              ),
              const Gap(12),
              FormLabelTextField(
                hintText: AppText.enterEmail,
                title: AppText.emailText,
                type: AppText.emailText,
                textEditingController: registerUserBloc.emailTextField,
              ),
              const Gap(12),
              BlocProvider(
                create: (_) => PasswordVisibilityBloc(),
                child: FormLabelTextField(
                  hintText: AppText.enterPassword,
                  title: AppText.password,
                  type: AppText.password.toLowerCase(),
                  textEditingController: registerUserBloc.passwordTextField,
                ),
              ),
              const Gap(12),
              BlocProvider(
                create: (_) => PasswordVisibilityBloc(),
                child: FormLabelTextField(
                  hintText: AppText.repeatPasswordText,
                  title: AppText.repeatPasswordText,
                  type: AppText.password.toLowerCase(),
                  textEditingController:
                      registerUserBloc.repeatPasswordTextField,
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }
}
