// Flutter imports:
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

// Project imports:
import 'package:remever/common/resources.dart';
import 'package:remever/common/widgets/typography.dart';
import 'package:remever/common/widgets/wspace.dart';
import 'package:remever/components/extensions/context.dart';
import 'package:remever/gen/assets.gen.dart';
import 'package:remever/screens/auth/cubit/auth_cubit.dart';
import 'package:remever/widgets/primary_button.dart';

///
/// Отрисовка инициализации авторизации
///
class InitialAuth extends StatelessWidget {
  const InitialAuth({super.key});

  // Константы для стилей и отступов
  static final EdgeInsetsGeometry _padding = EdgeInsets.all(16).r;
  static final _regular14 = Regular14px();

  void _onEnterTap(BuildContext context) {
    context.read<AuthCubit>().toEmailState();
  }

  void _onPolicyTap() {}

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: AppColors.bg,
      body: Padding(
        padding: _padding,
        child: SingleChildScrollView(
          physics: BouncingScrollPhysics(),
          child: Column(
            children: <Widget>[
              HSpace(148),
              _buildLogo(),
              _buildQuote(),
              HSpace(245),
              _buildLoginButton(context),
              HSpace(28),
              _buildPolicyLink(),
              _buildBottomSpacing(),
            ],
          ),
        ),
      ),
    );
  }

  Widget _buildLogo() {
    return Assets.images.logo.image(width: 308.w, height: 100.h);
  }

  Widget _buildQuote() {
    return Column(
      children: <Widget>[
        HSpace(16),
        Assets.images.quote.image(width: 324.w, height: 64.h),
      ],
    );
  }

  Widget _buildLoginButton(BuildContext context) {
    return PrimaryButton(
      onTap: () => _onEnterTap(context),
      child: AppTypography(
        'Войти по e-mail',
        type: _regular14,
        color: AppColors.white,
      ),
    );
  }

  Widget _buildPolicyLink() {
    return InkWell(
      onTap: () => _onPolicyTap(),
      child: AppTypography.rich(
        'Отправляя данные, Вы подтверждаете согласие с ',
        type: _regular14,
        color: AppColors.disabled,
        children: <TextSpan>[
          TextSpan(
            text: 'Политикой обработки персональных данных',
            style: _regular14.style.copyWith(color: AppColors.primary),
          ),
        ],
      ),
    );
  }

  Widget _buildBottomSpacing() {
    return HSpace(40);
  }
}
