import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';

import '../../../../app.dart';
import '../personal_info_controller.dart';

class PersonalInfoForm extends StatelessWidget {
  final VisibilityController vc = Get.put(VisibilityController());

  @override
  Widget build(BuildContext context) {
    return GetX<PersonalInfoController>(
      init: PersonalInfoController(),
      builder: (pic) => Form(
        key: pic.personalInfoForm,
        child: pic.isLoading.value
            ? Container(
                height: 0.20.sh,
                child: Center(child: CustomLoader()),
              )
            : pic.isErrorOccurred.value
                ? Container(
                    height: 0.20.sh,
                    child: Center(
                      child: retryBuilder(pic.getCurrentUser),
                    ),
                  )
                : Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      AppTheme.appSizeDivider20H,
                      Text('profile_detail'.tr, style: AppTheme.headerStyle),
                      AppTheme.appSizeDivider20H,
                      AppTheme.appColorDivider,
                      AppTheme.appSizeDivider20H,
                      Text('name'.tr, style: AppTheme.styleColorC4C4),
                      AppTheme.appSizeDivider20H,
                      MyTextFormField(
                        controller: pic.nameCtrl,
                        // label: 'Имя',
                      ),
                      AppTheme.appSizeDivider20H,
                      Text('surname'.tr, style: AppTheme.styleColorC4C4),
                      AppTheme.appSizeDivider20H,
                      MyTextFormField(
                        controller: pic.surnameCtrl,
                        // label: 'Фамилия',
                      ),
                      AppTheme.appSizeDivider20H,
                      Text('phone_number'.tr, style: AppTheme.styleColorC4C4),
                      AppTheme.appSizeDivider20H,

                      MyTextFormField(
                        inputFormatters: [maskFormatterPhone],
                        controller: pic.phoneCtrl,
                        prefixTxt: '+993',
                        // label: 'Номер телефона',
                      ),

                      AppTheme.appSizeDivider20H,
                      Text('password'.tr, style: AppTheme.styleColorC4C4),
                      AppTheme.appSizeDivider20H,

                      // password region
                      MyTextFormField(
                        controller: pic.pwdCtrl,
                        // label: 'Пароль',
                        suffix: PasswordVisibilityWidget(),
                        obscureText: vc.obscureText.value,
                        isPassword: true,
                      ),
                      AppTheme.appSizeDivider20H,
                      ColoredButton(
                        title: 'save_changes'.tr,
                        btnColor: ThemeColor.mainColor,
                        callback: pic.updateProfile,
                      ),
                    ],
                  ),
      ),
    );
  }
}
