import 'package:flutter/material.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:provider/provider.dart';
import 'package:resume/l10n/app_localizations.dart';
import 'package:resume/pages/landing_page.dart';
import 'package:resume/providers/locale_provider.dart';
import 'package:resume/providers/content_provider.dart';
import './services/tools.dart';
import 'theme.dart' show darkTheme;

void main() {
  final String initialPath = Uri.base.path;
  final String defaultLocale = Tools.getLocaleFromPath(initialPath);
  runApp(
    MultiProvider(
      providers: [
        ChangeNotifierProvider(
          create: (context) =>
              LocaleProvider(defaultLocale: Locale(defaultLocale)),
        ),
        ChangeNotifierProvider(create: (context) => ContentProvider()),
      ],
      child: const Resume(),
    ),
  );
}

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

  @override
  State<Resume> createState() => _ResumeState();
}

class _ResumeState extends State<Resume> {
  @override
  Widget build(BuildContext context) {
    return Consumer<LocaleProvider>(
      builder: (context, localeProvider, child) => MaterialApp(
        title: 'Resume',
        theme: darkTheme,
        localizationsDelegates: const [
          AppLocalizations.delegate,
          GlobalMaterialLocalizations.delegate,
          GlobalWidgetsLocalizations.delegate,
          GlobalCupertinoLocalizations.delegate,
        ],
        supportedLocales: const [
          Locale('en'),
          Locale('de'),
        ],
        locale: localeProvider.locale,
        routes: {
          '/': (context) => const LandingPage(),
        },
        initialRoute: '/',
      ),
    );
  }
}
