package com.example.cuida;

import android.app.Application;
import com.google.firebase.firestore.FirebaseFirestore;
import com.google.firebase.firestore.FirebaseFirestoreSettings;

public class CuidaApplication extends Application {
    @Override
    public void onCreate() {
        super.onCreate();
        
        // Ativar persistência offline globalmente para toda a aplicação
        FirebaseFirestore db = FirebaseFirestore.getInstance();
        FirebaseFirestoreSettings settings = new FirebaseFirestoreSettings.Builder()
                .setPersistenceEnabled(true)
                .build();
        db.setFirestoreSettings(settings);

        // Forçar Locale Português
        java.util.Locale ptLocale = new java.util.Locale("pt", "PT");
        java.util.Locale.setDefault(ptLocale);
        android.content.res.Configuration config = new android.content.res.Configuration();
        config.setLocale(ptLocale);
        getResources().updateConfiguration(config, getResources().getDisplayMetrics());

        // --- Global Theme Initialization ---
        android.content.SharedPreferences themePrefs = getSharedPreferences("theme_prefs", android.content.Context.MODE_PRIVATE);
        boolean isDarkMode = themePrefs.getBoolean("dark_mode", false);
        if (isDarkMode) {
            androidx.appcompat.app.AppCompatDelegate.setDefaultNightMode(androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_YES);
        } else {
            androidx.appcompat.app.AppCompatDelegate.setDefaultNightMode(androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_NO);
        }
    }
}
