import 'package:cashumit/screens/config_screen.dart';
import 'package:cashumit/screens/transaction_screen.dart';
import 'package:flutter/material.dart';
import 'package:cashumit/screens/receipt_screen.dart';
import 'package:cashumit/screens/local_receipts_screen.dart';
import 'package:provider/provider.dart';
import 'package:cashumit/providers/receipt_provider.dart';

void main() async {
  // Ensure WidgetsFlutterBinding is initialized for async operations
  WidgetsFlutterBinding.ensureInitialized();

  runApp(
    MultiProvider(
      providers: [
        ChangeNotifierProvider(create: (_) => ReceiptProvider()),
      ],
      child: const MyApp(),
    ),
  );
}

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Cashumit',
      theme: ThemeData(
        primarySwatch: Colors.blue,
        visualDensity: VisualDensity.adaptivePlatformDensity,
      ),
      initialRoute: '/',
      routes: {
        '/': (context) => const ReceiptScreen(),
        '/receipt': (context) => const ReceiptScreen(),
        '/transaction': (context) => const TransactionScreen(),
        '/config': (context) => const ConfigScreen(),
        '/local-receipts': (context) => const LocalReceiptsScreen(),
      },
    );
  }
}
