// Version: 1.1.0 | Created: 2026-04-01 | Updated: 2026-07-04
// Root MaterialApp widget. Wires together theme + router + incoming-call
// overlay (v1.1.0 — the overlay existed but was never mounted, so incoming
// calls showed nothing).

import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';

import '../features/calls/presentation/incoming_call_overlay.dart';
import 'router.dart';
import 'theme.dart';

/// Root application widget.
///
/// [ProviderScope] is set up in main.dart. This widget only handles
/// theme and routing — no business logic here.
class M8ChatApp extends ConsumerWidget {
  const M8ChatApp({super.key});

  @override
  Widget build(BuildContext context, WidgetRef ref) {
    final router = ref.watch(routerProvider);

    return MaterialApp.router(
      title: 'M8Chat',
      theme: buildLightTheme(),
      darkTheme: buildDarkTheme(),
      // Default to dark — M8Chat is a dark-first chat app.
      themeMode: ThemeMode.system,
      routerConfig: router,
      debugShowCheckedModeBanner: false,
      builder: (context, child) =>
          IncomingCallOverlayHost(child: child ?? const SizedBox.shrink()),
    );
  }
}
