import 'package:flutter/material.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:supabase_flutter/supabase_flutter.dart';

import 'dart:async';

import 'gates/debug_launch_gate.dart';

const String supabaseUrl = 'https://mannjismlhlwaqqqnvog.supabase.co';
const String supabaseAnonKey =
    'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6Im1hbm5qaXNtbGhsd2FxcXFudm9nIiwicm9sZSI6ImFub24iLCJpYXQiOjE3Nzk3MjU3MjEsImV4cCI6MjA5NTMwMTcyMX0.hF5tD1n7t_WSDLIesu1xcBHhzHouAVUCP8tUDDwUmDw';

SupabaseClient get supabase => Supabase.instance.client;

Future<void> main() async {
  WidgetsFlutterBinding.ensureInitialized();

  FlutterError.onError = (details) {
    FlutterError.presentError(details);
    Zone.current.handleUncaughtError(
      details.exception,
      details.stack ?? StackTrace.current,
    );
  };

  runZonedGuarded(
    () async {
      await Supabase.initialize(
        url: supabaseUrl,
        publishableKey: supabaseAnonKey,
      );
      runApp(const MyApp());
    },
    (error, stack) {
      debugPrint('UNCAUGHT: $error');
      debugPrintStack(stackTrace: stack);
    },
  );
}

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

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Check-Teeth Kids',
      debugShowCheckedModeBanner: false,
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: const Color(0xFF2F9E94)),
        scaffoldBackgroundColor: const Color(0xFFFAFAF7),
        useMaterial3: true,
        // Sem isto, o Material 3 aplica por padrão uma sobreposição de cor
        // (surfaceTintColor) e uma elevação extra ao rolar (scrolledUnderElevation)
        // por cima de qualquer app bar — o que "lavava" o gradiente customizado
        // das app bars, fazendo-o parecer uma cor sólida em vez de gradiente.
        appBarTheme: const AppBarTheme(
          surfaceTintColor: Colors.transparent,
          scrolledUnderElevation: 0,
        ),
      ),
      localizationsDelegates: const [
        GlobalMaterialLocalizations.delegate,
        GlobalWidgetsLocalizations.delegate,
        GlobalCupertinoLocalizations.delegate,
      ],
      supportedLocales: const [Locale('pt', 'PT'), Locale('pt', 'BR')],
      locale: const Locale('pt', 'PT'),
      home: const DebugLaunchGate(),
    );
  }
}
