// FluxWater:Monitor - Cozy Edition v2.1
// Updates: Added Message Screen with Dialogs

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:hive_flutter/hive_flutter.dart';
import 'package:provider/provider.dart';

import 'services/flux_service.dart';
import 'widgets/cozy_home_frame.dart';

void main() async {
  WidgetsFlutterBinding.ensureInitialized();

  await Hive.initFlutter();
  await Hive.openBox('fluxData');
  await Hive.openBox('fluxSettings');

  SystemChrome.setSystemUIOverlayStyle(
    const SystemUiOverlayStyle(
      statusBarColor: Colors.transparent,
      statusBarIconBrightness: Brightness.dark,
      systemNavigationBarColor: Color(0xFFFFFBF0),
      systemNavigationBarIconBrightness: Brightness.dark,
    ),
  );

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

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'FluxWater:Monitor',
      debugShowCheckedModeBanner: false,
      theme: ThemeData(
        useMaterial3: true,
        brightness: Brightness.light,
        scaffoldBackgroundColor: const Color(0xFFFFFBF0),
        colorScheme: ColorScheme.fromSeed(
          seedColor: const Color(0xFFAED581),
          primary: const Color(0xFF81C784),
          secondary: const Color(0xFFFFCC80),
          surface: const Color(0xFFFFFFFF),
          background: const Color(0xFFFFFBF0),
        ),
        textTheme: GoogleFonts.nunitoTextTheme(Theme.of(context).textTheme)
            .copyWith(
              displayLarge: GoogleFonts.nunito(
                fontWeight: FontWeight.w800,
                color: const Color(0xFF5D4037),
              ),
              titleLarge: GoogleFonts.nunito(
                fontWeight: FontWeight.w700,
                color: const Color(0xFF5D4037),
              ),
              bodyLarge: GoogleFonts.quicksand(color: const Color(0xFF795548)),
              bodyMedium: GoogleFonts.quicksand(color: const Color(0xFF795548)),
            ),
        appBarTheme: const AppBarTheme(
          backgroundColor: Colors.transparent,
          elevation: 0,
          centerTitle: true,
          iconTheme: IconThemeData(color: Color(0xFF5D4037)),
          titleTextStyle: TextStyle(
            color: Color(0xFF5D4037),
            fontSize: 20,
            fontWeight: FontWeight.bold,
          ),
        ),
        cardTheme: CardThemeData(
          elevation: 0,
          shape: RoundedRectangleBorder(
            borderRadius: BorderRadius.circular(24),
          ),
          color: Colors.white,
        ),
        dialogTheme: DialogThemeData(
          backgroundColor: const Color(0xFFFFFBF0),
          shape: RoundedRectangleBorder(
            borderRadius: BorderRadius.circular(24),
          ),
          titleTextStyle: GoogleFonts.nunito(
            fontSize: 20,
            fontWeight: FontWeight.bold,
            color: const Color(0xFF5D4037),
          ),
        ),
      ),
      home: const CozyHomeFrame(),
    );
  }
}
