import 'package:connectycube_sdk/connectycube_calls.dart';
import 'package:flutter/material.dart';
import 'package:vmeeting/src/extension/context_extensions.dart';
import 'package:vmeeting/src/widgets/big_text_widget.dart';

import '../../src/constants/colors_const.dart';
import '../../src/controllers/enter_number_cont.dart';
import '../../src/utils/app_utils.dart';
import '../../src/widgets/textfiled_widgets/auth_text_fild.dart';

class ResetPasswordPage extends StatefulWidget {
  final NumberController controller;
  const ResetPasswordPage({super.key, required this.controller});

  @override
  State<ResetPasswordPage> createState() => _ResetPasswordPageState();
}

class _ResetPasswordPageState extends State<ResetPasswordPage> {

  final _emailControlle = TextEditingController(text: AppUtils.userModel.email);
  final _emailFocusNode = FocusNode();

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const BigText(text: "Chage Password"),
      ),
      body: buildUI(),
    );
  }

  Widget buildUI(){
    return Container(
      margin: EdgeInsets.symmetric(horizontal: context.w * 0.06),
      child: Column(
        children: [
          SizedBox(height: context.h*0.2),
          AuthTextFild(
            lableName: "Email",
            borderRadius: 10,
            elevation: 1,
            color: Colors.grey.withOpacity(0.2),
            type: TextInputType.emailAddress,
            focusNode: _emailFocusNode,
            textEditingController: _emailControlle,
          ),
          SizedBox(height: context.h*0.1),
          buildButtons(),
        ],
      ),
    );
  }


  Future<dynamic>resetPasswordUser(String emile) async {
  return await resetPassword(emile)
        .then((voidResult) {
          print("Shu yerga keldi");
    })
        .catchError((error) {
      print("Shu yerga keldi");
    });

  }



  Widget buildButtons() {
    return StreamBuilder(stream: widget.controller.outputElevatedButton,
        builder: (BuildContext context, snapshot){
          return Column(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              ElevatedButton(
                style: ElevatedButton.styleFrom(
                  foregroundColor: Colors.white,
                  backgroundColor: ColorConst.appGreenColor,
                  disabledForegroundColor: Colors.grey.withOpacity(0.38),
                  disabledBackgroundColor: Colors.grey.withOpacity(0.12),
                ),
                onPressed: () async {
                  if( _emailControlle.text.isNotEmpty){
                    widget.controller.inputElevatedButton.add(true);
                  final resetPasswordUse = await  resetPasswordUser(_emailControlle.text);
                    widget.controller.inputElevatedButton.add(false);
                  print(resetPasswordUse);
                  }else{
                    AppUtils.showSnackBar(context, "PLEASE ENTER THE SAME VALUE AGAIN");
                  }

                },
                child: SizedBox(
                  height: context.h * 0.06,
                  child:  Center(
                    child: snapshot.data ?? false
                        ? AppUtils.buttonLoader
                        :  BigText(
                      text: "Chage".toUpperCase(),
                      fontWidget: FontWeight.bold,
                      size: 16,
                    ),
                  ),
                ),
              ),
            ],
          );
        });
  }
}
