import androidx.compose.foundation.layout.padding
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.font.FontFamily
import androidx.compose.ui.text.font.FontStyle
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.platform.Font
import androidx.compose.ui.window.Window
import androidx.compose.ui.window.WindowPlacement
import androidx.compose.ui.window.application
import androidx.compose.ui.window.rememberWindowState
import ch.dissem.yaep.ui.common.App
import ch.dissem.yaep.ui.common.theme.emojiFontFamily
import org.jetbrains.compose.resources.painterResource
import yaep.commonui.generated.resources.Res
import yaep.commonui.generated.resources.moon

fun main() = application {
    emojiFontFamily = FontFamily(
        Font(
            resource = "NotoColorEmoji-Regular.ttf",
            weight = FontWeight.W400,
            style = FontStyle.Normal
        )
    )

    Window(
        onCloseRequest = ::exitApplication,
        undecorated = true,
        title = "YAEP",
        icon = painterResource(Res.drawable.moon)
    ) {
        var useDarkMode by remember { mutableStateOf(true) }
        DesktopWindow(
            useDarkMode = useDarkMode,
            topBar = {
                AppBar(
                    useDarkMode = useDarkMode,
                    setDarkMode = { useDarkMode = it },
                    onCloseRequest = ::exitApplication,
                    windowState = rememberWindowState(
                        placement = WindowPlacement.Floating
                    )
                )
            }
        ) {
            App(modifier = Modifier.padding(it))
        }
    }
}