import com.codingfeline.buildkonfig.compiler.FieldSpec.Type.STRING
import org.jetbrains.compose.desktop.application.dsl.TargetFormat

plugins {
    alias(libs.plugins.composeCompiler)
    alias(libs.plugins.composeMultiplatform)
    alias(libs.plugins.kotlinMultiplatform)
    alias(libs.plugins.kotlinSerialization)
    alias(libs.plugins.buildkonfig)
}

fun getLwaVersion() = "1.5.1"

kotlin {
    jvm("desktop")

    sourceSets {
        val desktopMain by getting

        commonMain.dependencies {
            // common
            implementation(projects.shared)
            // compose
            implementation(compose.runtime)
            implementation(compose.foundation)
            implementation(compose.material)
            implementation(compose.ui)
            implementation(compose.components.resources)
            implementation(compose.components.uiToolingPreview)
            implementation(libs.compose.desktop.preview)
            implementation(libs.androidx.lifecycle.viewmodel)
            implementation(libs.androidx.lifecycle.runtime.compose)
            implementation(libs.androidx.navigation.compose)
            // injection
            implementation(libs.koin.compose)
            implementation(libs.koin.compose.viewmodel)
            implementation(libs.engawapg.zoomable)
            // composable component.
            implementation(libs.coil.compose)
            implementation(libs.coil.network.ktor)
            // Shader
            implementation(libs.hypnoticcanvas)
            implementation(libs.hypnoticcanvas.shaders)
            // network
            implementation(libs.kotlinx.serialization.json)
            implementation(libs.ktor.serialization.json)
            implementation(libs.ktor.client.core)
            implementation(libs.ktor.client.okhttp)
            implementation(libs.ktor.client.websockets)
            implementation(libs.ktor.client.negotiation)
            // shell
            implementation(libs.turtle)
            // log
            // implementation(libs.logback)
        }

        commonTest.dependencies {
            implementation(libs.kotlin.test)
        }

        desktopMain.dependencies {
            implementation(compose.desktop.currentOs)
            implementation(libs.kotlinx.coroutines.swing)
        }
    }
}

buildkonfig {
    packageName = "com.pixelized.desktop.lwa"

    defaultConfigs {
        buildConfigField(STRING, "version", getLwaVersion())
    }
}

// https://github.com/JetBrains/compose-multiplatform/blob/master/tutorials/Native_distributions_and_local_execution/README.md#basic-usage
compose.desktop {
    application {
        mainClass = "com.pixelized.desktop.lwa.MainKt"

        nativeDistributions {
            targetFormats(TargetFormat.Dmg, TargetFormat.Msi, TargetFormat.Deb)

            packageName = "Table de Lwa"
            packageVersion = getLwaVersion()
            description = "Application de support au jeux de rôle dans l'univers de Lwa."
            copyright = "© 2020 Pixelized. All rights reserved."
            vendor = "Pixelized"

            includeAllModules = true

            // Use system theming for the app toolbars.
            jvmArgs("-Dapple.awt.application.appearance=system")
        }

        buildTypes.release.proguard {
            configurationFiles.from(project.file("compose-desktop.pro"))
        }
    }
}

compose.resources {
    generateResClass = auto
}