import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:uco_mobile_poc/app/custom_widgets/Fields/input_field.dart';
import 'package:uco_mobile_poc/app/custom_widgets/custom_button.dart';
import 'package:uco_mobile_poc/app/modules/password_change/controllers/password_change_controller.dart';

import '../../../core/constants/form_field_constants.dart';
import '../../../core/constants/translation_keys.dart';
import '../../../custom_widgets/custom_app_bar.dart';
import '../../../res/app_colors.dart';

class ChangePasswordScreen extends GetView<ChangePasswordController> {
  const ChangePasswordScreen({super.key});

  @override
  Widget build(BuildContext context) {
    String className = runtimeType.toString().split('.').last;
    return Scaffold(
      appBar: DashBoardAppBar(
        title: TranslationKeys.makeTranslation(TranslationKeys.changepassword),
        onBackButtonPressed: () {
          Get.back();
          controller.clearFields();
        },
      ),
      body: GetBuilder<ChangePasswordController>(builder: (controller) {
        return Padding(
          padding: const EdgeInsets.only(right: 12.0, left: 12.0),
          child: Column(
            children: [
              const SizedBox(height: 20),
              controller.oldPasswordField = InputField(
                refKey: FormFieldConstants.instance().getFormKey("${className}oldPassword"),
                controller: FormFieldConstants.instance().getController("${className}oldPassword"),
                hintText: "Enter old password",
                labelText: "Old Password",
                keyboardType: TextInputType.visiblePassword,
                requiredPasswordIcon: true,
                isPassword: true,
              ),
              controller.newPasswordField = InputField(
                refKey: FormFieldConstants.instance().getFormKey("${className}newPassword"),
                controller: FormFieldConstants.instance().getController("${className}newPassword"),
                hintText: "Enter new password",
                labelText: "New Password",
                keyboardType: TextInputType.visiblePassword,
                requiredPasswordIcon: true,
                isPassword: true,
              ),
              controller.confirmNewPasswordField = InputField(
                refKey: FormFieldConstants.instance().getFormKey("${className}confirmNewPasswordField"),
                controller: FormFieldConstants.instance().getController("${className}confirmNewPasswordField"),
                hintText: "Enter new password again",
                labelText: "Confirm New Password",
                keyboardType: TextInputType.visiblePassword,
                requiredPasswordIcon: true,
                isPassword: true,
              )
            ],
          ),
        );
      }),
      persistentFooterButtons: [
        Padding(
          padding: const EdgeInsets.symmetric(horizontal: 20),
          child: CustomButton(
            onPressed: () {
              Get.find<ChangePasswordController>().changePassword();
            },
            buttonText: TranslationKeys.makeTranslation(TranslationKeys.textChangePassword),
            buttonColor: AppColors.colorButton,
            buttonPadding: const EdgeInsets.symmetric(vertical: 8, horizontal: 0),
          ),
        ),
      ],
      persistentFooterAlignment: AlignmentDirectional.bottomCenter,
      resizeToAvoidBottomInset: false,
      backgroundColor: AppColors.colorSecondary,
    );
  }
}
