import 'package:auth/src/features/recover_password/presentation/new_password/new_password_screen.dart';
import 'package:design_system/design_system.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:navigation/navigation.dart';
import 'package:sf_localizations/sf_localizations.dart';
import 'package:utils/utils.dart';

import '../state/recover_password_view_model.dart';

class SentScreen extends ConsumerWidget {
  final NavigationContract navigationContract;

  const SentScreen({super.key, required this.navigationContract});

  @override
  Widget build(BuildContext context, WidgetRef ref) {
    final theme = ref.watch(themePortProvider);

    final viewModel = ref.read(recoverPasswordViewModelProvider.notifier);
    final viewState = ref.watch(recoverPasswordViewModelProvider);

    return Scaffold(
      backgroundColor: theme.getColorFor(ThemeCode.backgroundPrimary),
      body: Container(
        margin: EdgeInsets.all(24),
        child: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              Text(
                context.translate(I18n.recoverPasswordTitle),
                textAlign: TextAlign.center,
                style: TextStyle(
                  fontWeight: FontWeight.w500,
                  fontSize: SizeUtils.getByScreen(small: 30, big: 30, xl: 26),
                  letterSpacing: 0,
                ),
              ),
              SizedBox(height: SizeUtils.getByScreen(small: 48, big: 48, xl: 40)),
              Row(
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  Icon(
                    Icons.check,
                    color: theme.getColorFor(ThemeCode.buttonPrimary),
                  ),
                  SizedBox(width: SizeUtils.getByScreen(small: 10, big: 10, xl: 6)),
                  Text(
                    viewState.recoveryFormat == "email"
                        ? context.translate(I18n.emailSent)
                        : context.translate(I18n.smsSent),
                    style: TextStyle(fontSize: SizeUtils.getByScreen(small: 18, big: 18, xl: 15), fontWeight: FontWeight.bold),
                  ),
                ],
              ),
              SizedBox(height: SizeUtils.getByScreen(small: 48, big: 48, xl: 40)),
              Text(
                viewState.recoveryFormat == "email"
                    ? context.translate(I18n.checkEmail1)
                    : context.translate(I18n.checkSms1),
                textAlign: TextAlign.center,
                style: TextStyle(fontSize: SizeUtils.getByScreen(small: 17, big: 17, xl: 15), letterSpacing: 0),
              ),
              SizedBox(height: 16),
              Text(
                viewState.recoveryFormat == "email"
                    ? context.translate(I18n.checkEmail2)
                    : context.translate(I18n.checkSms2),
                textAlign: TextAlign.center,
                style: TextStyle(fontSize: SizeUtils.getByScreen(small: 14, big: 14, xl: 12), letterSpacing: 0),
              ),
              SizedBox(height: SizeUtils.getByScreen(small: 48, big: 48, xl: 40)),
              Row(
                children: [
                  Expanded(
                    child: SecondaryButton(
                      onPressed: () {
                        if ( viewState.recoveryFormat == "email") {
                          viewModel.requestEmail();
                        } else {
                          viewModel.requestSms();
                        }
                      },
                      text: viewState.recoveryFormat == "email"
                          ? context.translate(I18n.resendEmail)
                          : context.translate(I18n.resendSms),
                      size: SizeUtils.getByScreen(small: 16, big: 16, xl: 14),
                    ),
                  ),
                  SizedBox(width: 10),
                  Expanded(
                    child: PrimaryButton(
                      onPressed: () => Navigator.push(
                        context,
                        MaterialPageRoute(builder: (_) => NewPasswordScreen(navigationContract: navigationContract)),
                      ),
                      text: context.translate(I18n.continueKey),
                      color: theme.getColorFor(ThemeCode.buttonSecondary),
                      size: SizeUtils.getByScreen(small: 16, big: 16, xl: 14),
                    ),
                  ),
                ],
              ),
            ],
          ),
        ),
      ),
    );
  }
}
