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

import '../../app.dart';
import 'widgets/forgot_password_dialog.dart';

class LoginPage extends StatelessWidget {
  final ProfileController pc = Get.put(ProfileController());
  final VisibilityController vc = Get.put(VisibilityController());

  @override
  Widget build(BuildContext context) {
    return GetX<LoginController>(
      init: LoginController(),
      builder: (lc) => Scaffold(
        appBar: CustomAppbarWidget(),
        body: SingleChildScrollView(
          child: ConstrainedBox(
            constraints: BoxConstraints(
              minWidth: 1.sw,
              minHeight: 1.sh,
            ),
            child: IntrinsicHeight(
              child: Container(
                padding: EdgeInsets.only(left: 30.w, right: 30.w, top: 30.h),
                child: Form(
                  key: lc.formKey,
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      Text(
                        'login'.tr,
                        style: new TextStyle(
                          color: Color(0xFF3A3A3A),
                          fontSize: 14.sp,
                          fontWeight: FontWeight.w700,
                        ),
                      ),
                      AppTheme.appSizeDivider20H,
                      AppTheme.appColorDivider,
                      AppTheme.appSizeDivider20H,
                      Text(
                        'phone_number'.tr,
                        style: AppTheme.styleColorC4C4,
                      ),
                      SizedBox(height: 15.h),
                      // AppTheme.appSizeDivider20H,
                      MyTextFormField(
                        controller: lc.phoneCtrl,
                        keyboardType: TextInputType.number,
                        inputFormatters: [maskFormatterPhone],
                        label: 'phone_number'.tr,
                        hasPrefixIcon: true,
                      ),
                      AppTheme.appSizeDivider20H,
                      Text('password'.tr, style: AppTheme.styleColorC4C4),
                      SizedBox(height: 15.h),
                      MyTextFormField(
                        controller: lc.passwordCtrl,
                        suffix: PasswordVisibilityWidget(),
                        obscureText: vc.obscureText.value,
                        isPassword: true,
                        label: 'password'.tr,
                      ),
                      AppTheme.appSizeDivider20H,
                      Center(
                        child: TextButton(
                          onPressed: () {
                            debugPrint('forgot password');
                            Get.dialog(
                              ForgotPasswordDialog(),
                            );
                          },
                          child: Text(
                            'forgot_password?'.tr,
                            style: new TextStyle(
                              color: ThemeColor.mainColor,
                              fontSize: 14.sp,
                              fontWeight: FontWeight.w500,
                            ),
                          ),
                        ),
                      ),
                      AppTheme.appSizeDivider20H,
                      AppTheme.appSizeDivider20H,
                      lc.isLoading.value
                          ? CustomLoader()
                          : ColoredButton(
                              title: 'login1'.tr,
                              callback: lc.login,
                              btnColor: ThemeColor.mainColor,
                            ),
                      SizedBox(height: 30.h),
                      SizedBox(height: 16.h),
                      Center(
                        child: Text(
                          'have_account'.tr,
                          style: TextStyle(
                            fontSize: 14.sp,
                            color: ThemeColor.color3A3A3A,
                          ),
                        ),
                      ),
                      AppTheme.appSizeDivider20H,
                      MyOutlinedButton(
                        title: 'register'.tr,
                        btnColor: ThemeColor.mainColor,
                        txtColor: ThemeColor.mainColor,
                        callback: () {
                          debugPrint('on register tapped');
                          pc.onPageChange(1);
                        },
                      ),
                    ],
                  ),
                ),
              ),
            ),
          ),
        ),
      ),
    );
  }
}
