import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:go_router/go_router.dart';
import 'package:recomendagro/assets/theme/colors.dart';
import 'package:recomendagro/src/shared/utils/responsive/responsive_metrics.dart';
import 'package:recomendagro/src/shared/widgets/back_button.dart';
import 'package:recomendagro/src/shared/widgets/buttons/simple_button.dart';
import 'package:recomendagro/src/shared/widgets/inputs/code_input.dart';

class CodigoVerificacaoScreen extends ConsumerStatefulWidget {
  static String path = '/verificacodigo';
  const CodigoVerificacaoScreen({ Key? key }) : super(key: key);

  @override
  ConsumerState<CodigoVerificacaoScreen> createState() => _CodigoVerificacaoScreenState();
}

class _CodigoVerificacaoScreenState extends ConsumerState<CodigoVerificacaoScreen> {
  

  final GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>();
  bool showpass = false;
  TextEditingController emailController = TextEditingController();
  TextEditingController senhaController = TextEditingController();
  TextEditingController codeController = TextEditingController();
  TextEditingController nomeCompletoController = TextEditingController();
  // final GlobalKey<FormState> _formKey = GlobalKey<FormState>();
  final GlobalKey<FormState> _form2Key = GlobalKey<FormState>();
  bool firstStep = true;

  bool isloading = false;
  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    Radius radius = const Radius.circular(20);
    return WillPopScope(
      onWillPop: () async {
        return Future.value(false);
      },
      child: Scaffold(
      key: _scaffoldKey,
      extendBodyBehindAppBar: true,
      appBar: const PreferredSize(child: SizedBox(), preferredSize: Size.fromHeight(0)),
      body: SingleChildScrollView(
        child: Container(
          decoration: BoxDecoration(
            color: Theme.of(context).primaryColor,
            image: DecorationImage(
              image: AssetImage('lib/assets/images/bg_header.png'),
              fit: BoxFit.cover,
            )
          ),
          child: Column(
            children: [
              const SizedBox(height: 30),
              SizedBox(
                height: Metrics.height(context)/6,
                child: Center(
                  child: SizedBox(
                    child: Image.asset(
                      'lib/assets/logos/logo_branca.png',
                      fit: BoxFit.fill,
                      width: 100
                    )
                  )
                ),
              ),
              ClipRRect(
                borderRadius: BorderRadius.only(
                  topLeft: radius,
                  topRight: radius
                ),
                child: Container(
                  padding: const EdgeInsets.symmetric(horizontal: 35),
                  decoration: BoxDecoration(
                    color: Theme.of(context).scaffoldBackgroundColor
                  ),
                  child:Center(
                    child: Form(
                      key: _form2Key,
                      child: Column(
                        mainAxisAlignment: MainAxisAlignment.center,
                        crossAxisAlignment: CrossAxisAlignment.center,
                        children: [
                          const SizedBox(height: 30),
                          Row(
                            children: [
                              const BackButtonWidget(),
                              const SizedBox(width: 10),
                              SizedBox(
                                child: Text(
                                  "Confirmação de conta",
                                  textAlign: TextAlign.start,
                                  style: Theme.of(context).textTheme.bodyMedium?.copyWith(
                                    fontWeight: FontWeight.w600,
                                    color: AppColorLight.text01Color,
                                    fontSize: 26
                                  )
                                )
                              ),
                            ],
                          ),
                          const SizedBox(height: 30),
                          SizedBox(
                            width: double.infinity,
                            child: RichText(
                              textAlign: TextAlign.start,
                              maxLines: 3,
                              text: TextSpan(
                                text: 'Verifique sua conta usando o código de ativação enviado ao seu e-mail ',
                                style: Theme.of(context).textTheme.bodyMedium?.copyWith(
                                  fontWeight: FontWeight.w600,
                                  height: 1.7,
                                  color: AppColorLight.text03Color,
                                  fontSize: 16
                                ),
                                children: <TextSpan>[
                                  TextSpan(
                                    text: emailController.text,
                                    style: Theme.of(context).textTheme.bodyMedium?.copyWith(
                                      fontWeight: FontWeight.w600,
                                      color: AppColorLight.text01Color,
                                      fontSize: 16
                                    ),
                                  ),
                                ]
                              )
                            )
                          ),
                          const SizedBox(height: 30),
                          // SimpleInput(
                          //   title: 'Código',
                          //   hintText: 'Informe código',
                          //   controller: codeController,
                          //   validator: true,
                          // ),
                          CodeInputController(
                            controller: codeController,
                          ),
                          const SizedBox(height: 30),
                          ButtonWidget(
                            label: 'Verificar conta',
                            isloading: isloading,
                            onTap: (){

                            }
                          )
                        ]
                      )
                    ),
                  )
                ),
              )
            ],
          ),
        ),
      )
    ));
  }

  void doLogin() async {
    // if(_formKey.currentState!.validate()){
    //   setState(() {
    //     isloading = true;
    //   });
    //   await ref.read(authController.notifier).fazerLogin({
    //     'email': emailController.text,
    //     'senha': senhaController.text
    //   });
    //   setState(() {
    //     isloading = false;
    //   });
    //   if(!mounted)return;
      
    //   if((ref.read(authController).hasError == false)){
    //     context.go(ListDocumentosScreen.path);
    //   }else{
    //     dialogToastMessage(
    //       context,
    //       message: 'Usuário ou senha inválidos.',
    //       dialogColorType: DialogColorType.WARNING
    //     );
    //   }
    // }
  }
}