import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'src/services/api_service.dart';
import 'src/services/dashboard_provider.dart';
import 'src/screens/dashboard_screen.dart';
import 'src/theme/app_theme.dart';

void main() {
  runApp(const XPDashboardApp());
}

class XPDashboardApp extends StatelessWidget {
  const XPDashboardApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MultiProvider(
      providers: [
        Provider<ApiService>(
          create: (_) => ApiService(),
          dispose: (_, apiService) => apiService.dispose(),
        ),
        ChangeNotifierProxyProvider<ApiService, DashboardProvider>(
          create: (context) => DashboardProvider(context.read<ApiService>()),
          update: (context, apiService, previous) =>
              previous ?? DashboardProvider(apiService),
        ),
      ],
      child: MaterialApp(
        title: 'XP Nix Dashboard',
        theme: AppTheme.lightTheme,
        darkTheme: AppTheme.darkTheme,
        themeMode: ThemeMode.system,
        home: const DashboardScreen(),
        debugShowCheckedModeBanner: false,
      ),
    );
  }
}
