package org.zaine.management

import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import dagger.hilt.android.AndroidEntryPoint
import org.zaine.management.ui.ZManagementRoot
import org.zaine.management.ui.theme.ZManagementTheme

@AndroidEntryPoint
class MainActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContent {
            val settings = getSharedPreferences("settings", MODE_PRIVATE)
            var darkMode by rememberSaveable { mutableStateOf(settings.getBoolean("dark_mode", false)) }
            ZManagementTheme(darkTheme = darkMode) {
                ZManagementRoot(
                    darkMode = darkMode,
                    onDarkModeChange = {
                        darkMode = it
                        settings.edit().putBoolean("dark_mode", it).apply()
                    }
                )
            }
        }
    }
}
