// main.dart — 入口示例
// 演示:登录 → 引导 → 主框架(4 Tab)的完整串接,套用穿山甲明/暗主题。
// 把 lib/ 下的 pangolin_theme.dart 与 widgets/ 一并拷进工程,按实际目录改 import 路径。
import 'package:flutter/material.dart';
import 'pangolin_theme.dart';
import 'widgets/pangolin_widgets.dart';

void main() => runApp(const PangolinApp());

class PangolinApp extends StatefulWidget {
  const PangolinApp({super.key});
  @override
  State<PangolinApp> createState() => _PangolinAppState();
}

class _PangolinAppState extends State<PangolinApp> {
  // 全局开关:语言 + 主题(真实工程可换成 Provider / Riverpod / Bloc 等)
  bool zh = true;
  ThemeMode mode = ThemeMode.system;

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

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

class RootFlow extends StatefulWidget {
  const RootFlow({super.key, this.zh = true});
  final bool zh;
  @override
  State<RootFlow> createState() => _RootFlowState();
}

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

  @override
  Widget build(BuildContext context) {
    switch (stage) {
      case AppStage.auth:
        return AuthScreen(zh: widget.zh, onDone: () => setState(() => stage = AppStage.onboarding));
      case AppStage.onboarding:
        return OnboardingScreen(onDone: () => setState(() => stage = AppStage.app));
      case AppStage.app:
        return HomeShell(zh: widget.zh);
    }
  }
}
