import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:go_router/go_router.dart';
import '../../../core/auth/auth_notifier.dart';
import '../../../core/auth/auth_providers_provider.dart';
import '../../../core/theme/halo_tokens.dart';
import '../../../core/theme/widgets/widgets.dart';

class WelcomeScreen extends ConsumerWidget {
  const WelcomeScreen({super.key});

  @override
  Widget build(BuildContext context, WidgetRef ref) {
    final providersAsync = ref.watch(authProvidersProvider);
    final providers =
        providersAsync.valueOrNull ?? AuthProvidersConfig.fallback;

    return Scaffold(
      body: SafeArea(
        child: Padding(
          padding: const EdgeInsets.all(HaloSpacing.s24),
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            crossAxisAlignment: CrossAxisAlignment.stretch,
            children: [
              const Center(child: HaloOrb(seed: 0, size: 96, label: 'H')),
              const SizedBox(height: HaloSpacing.s24),
              const Text(
                'Halo Bestie',
                style: TextStyle(
                  fontFamily: HaloTokens.fontDisplay,
                  fontSize: 32,
                  fontWeight: FontWeight.w700,
                  color: HaloTokens.ink,
                ),
                textAlign: TextAlign.center,
              ),
              const SizedBox(height: HaloSpacing.s8),
              const Text(
                'Tempat curhat kamu',
                style: TextStyle(
                  fontFamily: HaloTokens.fontBody,
                  fontSize: 15,
                  color: HaloTokens.inkSoft,
                ),
                textAlign: TextAlign.center,
              ),
              const SizedBox(height: HaloSpacing.s48),
              HaloButton(
                label: 'Lanjut sebagai Tamu',
                fullWidth: true,
                onPressed: () => context.push('/auth/display-name'),
              ),
              const SizedBox(height: HaloSpacing.s12),
              if (providers.google) ...[
                HaloButton(
                  label: 'lanjut dengan Google',
                  icon: const Icon(Icons.g_mobiledata),
                  variant: HaloButtonVariant.secondary,
                  fullWidth: true,
                  onPressed: () =>
                      ref.read(authProvider.notifier).loginGoogle(),
                ),
                const SizedBox(height: HaloSpacing.s12),
              ],
              if (providers.apple) ...[
                HaloButton(
                  label: 'lanjut dengan Apple',
                  icon: const Icon(Icons.apple),
                  variant: HaloButtonVariant.secondary,
                  fullWidth: true,
                  onPressed: () =>
                      ref.read(authProvider.notifier).loginApple(),
                ),
                const SizedBox(height: HaloSpacing.s12),
              ],
              HaloButton(
                label: 'Daftar / Masuk',
                variant: HaloButtonVariant.ghost,
                fullWidth: true,
                onPressed: () => context.push('/auth/register'),
              ),
            ],
          ),
        ),
      ),
    );
  }
}
