import 'package:mc_common_app/extensions/int_extensions.dart';
import 'package:mc_common_app/extensions/string_extensions.dart';
import 'package:mc_common_app/generated/locale_keys.g.dart';
import 'package:mc_common_app/view_models/user_view_model.dart';
import 'package:mc_common_app/widgets/common_widgets/app_bar.dart';
import 'package:mc_common_app/widgets/button/show_fill_button.dart';
import 'package:mc_common_app/widgets/txt_field.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

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

  @override
  State<ChangeEmailPage> createState() => _ChangeEmailPageState();
}

class _ChangeEmailPageState extends State<ChangeEmailPage> {
  String password = "";
  String email = '';

  late UserVM userVM;

  @override
  void initState() {
    userVM = Provider.of<UserVM>(context, listen: false);
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: CustomAppBar(
        title: LocaleKeys.changeEmail.tr(),
      ),
      body: SingleChildScrollView(
        child: Container(
          // width: double.infinity,
          // height: double.infinity,
          padding: const EdgeInsets.all(20),
          child: Column(
            children: [
              LocaleKeys.enterEmail.tr().toText(
                    height: 23 / 24,
                    fontSize: 24,
                    letterSpacing: -1.44,
                  ),
              12.height,
              TxtField(
                hint: LocaleKeys.enterNewEmail.tr(),
                onChanged: (v) => email = v,
              ),
              12.height,
              TxtField(
                hint: LocaleKeys.enterCurrentPassword.tr(),
                onChanged: (v) => password = v,
              ),
              40.height,
              ShowFillButton(
                title: LocaleKeys.confirm.tr(),
                maxWidth: double.infinity,
                onPressed: () async {
                  await userVM.changeUserEmail(context, email, password);
                },
              ),
            ],
          ),
        ),
      ),
    );
  }
}
