package mg.dot.feufaro

import com.russhwolf.settings.Settings
import com.russhwolf.settings.set
import androidx.compose.ui.window.WindowPosition
import androidx.compose.ui.unit.DpSize
import androidx.compose.ui.unit.dp
import mg.dot.feufaro.WindowState

actual class SaveSettings actual constructor() {
    actual val settings: Settings = Settings()

    actual fun loadLastUsedDir(): String = settings.getString("last_dir", "/")
    actual fun saveLastUsedDir(lastDir: String) { settings["last_dir"] = lastDir }

    fun saveWindowBounds(width: Int, height: Int, x: Int, y: Int) {
        settings["window_width"] = width
        settings["window_height"] = height
        settings["window_x"] = x
        settings["window_y"] = y
    }

    fun loadWindowBounds(): List<Int> = listOf(
        settings.getInt("window_width", 800),
        settings.getInt("window_height", 600),
        settings.getInt("window_x", 100),
        settings.getInt("window_y", 100)
    )

    actual fun loadWindowState(): WindowState {
        val bounds = loadWindowBounds()
        return WindowState(bounds[0], bounds[1],
            bounds[2], bounds[3]
        )
    }

    actual fun saveWindowState(state: WindowState) {
        saveWindowBounds(
            state.width,
            state.height,
            state.x,
            state.y
        )
    }
}