import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart';
import 'package:hmg_nurses/classes/colors.dart';
import 'package:hmg_nurses/config/routes.dart';
import 'package:hmg_nurses/extensions/string_extensions.dart';
import 'package:hmg_nurses/extensions/widget_extensions.dart';
import 'package:hmg_nurses/generated/locale_keys.g.dart';
import 'package:hmg_nurses/widgets/button/default_button.dart';
import 'package:hmg_nurses/widgets/cupertino_picker.dart';
import 'package:hmg_nurses/widgets/input_widget.dart';
import 'package:sizer/sizer.dart';

class LoginPage extends StatefulWidget {
  const LoginPage({Key? key}) : super(key: key);

  @override
  State<LoginPage> createState() => _LoginPageState();
}

class _LoginPageState extends State<LoginPage> {
  final loginFormKey = GlobalKey<FormState>();
  var projectIdController = TextEditingController();
  var userIdController = TextEditingController();
  var passwordController = TextEditingController();
  FocusNode projectIdFocusNode = FocusNode();
  FocusNode userIdFocusNode = FocusNode();
  FocusNode passwordIdFocusNode = FocusNode();

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: SafeArea(
        child: SingleChildScrollView(
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  LocaleKeys.welcomeTo.tr().toText14(color: MyColors.blackColor),
                  LocaleKeys.drSulaiman.tr().toText20(isBold: true, color: MyColors.blackColor),
                  "Nurses App".toText16(color: MyColors.redColor),
                ],
              ),
              heightSpacer4per(),
              Form(
                key: loginFormKey,
                child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
                  heightSpacer3per(),
                  CustomTextField(
                    LocaleKeys.userID.tr(),
                    userIdController,
                    isEnableBorder: true,
                    focusNode: userIdFocusNode,
                    isInputTypeNum: true,
                  ),
                  heightSpacer3per(),
                  CustomTextField(
                    LocaleKeys.password.tr(),
                    passwordController,
                    isTextIsPassword: true,
                    focusNode: passwordIdFocusNode,
                  ),
                  heightSpacer3per(),
                  CustomTextField(
                    LocaleKeys.branch.tr(),
                    projectIdController,
                    hasSelection: true,
                    isEnable: false,
                    focusNode: projectIdFocusNode,
                    onClick: () => CustomCupertinoPicker.showCupertinoPicker(context, [], () {}),
                  ),
                  heightSpacer15per(),
                ]),
              )
            ],
          ).paddingSymmetrical(8.w, 4.h),
        ),
      ),
      bottomSheet: Container(
        height: 12.h,
        color: MyColors.backgroundColor,
        width: double.infinity,
        child: Center(
          child: FractionallySizedBox(
            widthFactor: 0.89,
            child: Column(
              mainAxisAlignment: MainAxisAlignment.end,
              children: <Widget>[
                Padding(
                  padding: EdgeInsets.symmetric(horizontal: 4.w),
                  child: DefaultButton(LocaleKeys.login.tr(), () {
                    Navigator.pushNamed(context, AppRoutes.loginMethodsPage);
                  }, colors: const [MyColors.redColor, MyColors.redColor]),
                ),
                heightSpacer3per(),
              ],
            ),
          ),
        ),
      ),
    );
  }
}
