import 'package:flutter/foundation.dart' show kIsWeb;
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'l10n/l10n.dart';
import 'services/stripe_service.dart';
import 'ui/home_screen.dart';
import 'ui/theme.dart';
import 'ui/web_shell.dart';

void main() {
  WidgetsFlutterBinding.ensureInitialized();
  // Author unlock: open with ?unlock=master#/  (or --dart-define=UNLOCK=master)
  AuthorAccess.applyFromLaunch(uri: kIsWeb ? Uri.base : null);
  runApp(const KeyResonanceApp());
}

class KeyResonanceApp extends StatefulWidget {
  const KeyResonanceApp({super.key});

  @override
  State<KeyResonanceApp> createState() => _KeyResonanceAppState();
}

class _KeyResonanceAppState extends State<KeyResonanceApp> {
  AppLang _lang = AppLang.zh;

  @override
  Widget build(BuildContext context) {
    return LangScope(
      l10n: L10n(_lang),
      onChanged: (lang) => setState(() => _lang = lang),
      child: MaterialApp(
        title: 'Key Resonance Destiny · 键共振命理',
        debugShowCheckedModeBanner: false,
        theme: AppTheme.light,
        scrollBehavior: kIsWeb
            ? const MaterialScrollBehavior().copyWith(
                dragDevices: {
                  PointerDeviceKind.touch,
                  PointerDeviceKind.mouse,
                  PointerDeviceKind.trackpad,
                },
              )
            : null,
        builder: (context, child) {
          final page = child ?? const SizedBox.shrink();
          if (!kIsWeb) return page;
          return WebShell(child: page);
        },
        home: const HomeScreen(),
      ),
    );
  }
}
