import 'package:cims_apps/application/assets/path_assets.dart';
import 'package:cims_apps/application/component/image/image_view.dart';
import 'package:cims_apps/application/component/text_caption/text_caption.dart';
import 'package:cims_apps/application/component/text_form/text_form_view.dart';
import 'package:cims_apps/features/auth/registration/viewmodel/submission_data_viewmodel.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

class SubmitEmail extends StatelessWidget {
  const SubmitEmail({Key? key}) : super(key: key);

  Widget _emailVerify() {
    return Column(
      children: [
        const ImageView(image: PathAssets.imgEmail),
        Align(
          alignment: Alignment.center,
          child: RichText(
            textAlign: TextAlign.center,
            text: TextSpan(children: [
              const TextSpan(
                text:
                    'We have sent a verification link to your e-mail. \nPlease check your email for ',
                style: TextStyle(
                  color: Colors.black,
                  decoration: TextDecoration.none,
                ),
              ),
              TextSpan(
                recognizer: TapGestureRecognizer()
                  ..onTap = () {
                    print('object');
                  },
                text: 'verification',
                style: const TextStyle(
                  color: Colors.blue,
                ),
              ),
              const TextSpan(
                text: ' to \ncontinue registration.',
                style: TextStyle(
                  color: Colors.black,
                  decoration: TextDecoration.none,
                ),
              ),
            ]),
          ),
        ),
      ],
    );
  }

  @override
  Widget build(BuildContext context) {
    return ChangeNotifierProvider(
        create: (context) => SubmissionDataViewModel(),
        builder: (context, child) {
          return Consumer<SubmissionDataViewModel>(
              builder: (context, provider, child) {
            return Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                !provider.isEmailVerify
                    ? const TextCaption(title: 'Enter your e-mail')
                    : const TextCaption(title: 'Check your e-mail '),
                !provider.isEmailVerify
                    ? TextFormView(
                        name: 'E-mail Address',
                        hintText: 'Input e-mail address',
                        onTap: () {
                          provider.submitEmail();
                        },
                      )
                    : _emailVerify(),
              ],
            );
          });
        });
  }
}
