// main.dart — 入口(演示态)
// 串接:登录 → 引导 → 主框架(4 Tab);状态层统一走 Riverpod。
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';

import 'pangolin_theme.dart';
import 'state/app_providers.dart';
import 'widgets/auth_screen.dart';
import 'widgets/home_shell.dart';
import 'widgets/onboarding_screen.dart';

void main() => runApp(const ProviderScope(child: PangolinApp()));

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

  @override
  Widget build(BuildContext context, WidgetRef ref) {
    final mode = ref.watch(themeModeProvider);
    return MaterialApp(
      title: '穿山甲',
      debugShowCheckedModeBanner: false,
      theme: PangolinTheme.light,
      darkTheme: PangolinTheme.dark,
      themeMode: mode,
      home: const RootFlow(),
    );
  }
}

/// 应用阶段:登录 → 引导 → 主应用
enum AppStage { auth, onboarding, app }

class RootFlow extends ConsumerStatefulWidget {
  const RootFlow({super.key});
  @override
  ConsumerState<RootFlow> createState() => _RootFlowState();
}

class _RootFlowState extends ConsumerState<RootFlow> {
  AppStage stage = AppStage.auth;

  @override
  Widget build(BuildContext context) {
    final t = ref.watch(appTextProvider);
    switch (stage) {
      case AppStage.auth:
        return AuthScreen(t: t, onDone: () => setState(() => stage = AppStage.onboarding));
      case AppStage.onboarding:
        return OnboardingScreen(t: t, onDone: () => setState(() => stage = AppStage.app));
      case AppStage.app:
        return const HomeShell();
    }
  }
}
