import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi
import org.jetbrains.kotlin.gradle.dsl.JvmTarget

plugins {
    alias(libs.plugins.kotlinMultiplatform)
    alias(libs.plugins.androidLibrary)
    alias(libs.plugins.composeMultiplatform)
    alias(libs.plugins.composeCompiler)
}

kotlin {
    androidTarget {
        @OptIn(ExperimentalKotlinGradlePluginApi::class)
        compilerOptions {
            jvmTarget.set(JvmTarget.JVM_11)
        }
    }

    // 仅产出静态库（klib），由主工程静态链接进 libkn.so，打包时在包里
    ohosArm64 {
        binaries.staticLib()
    }
    ohosX64 {
        binaries.staticLib()
    }


    sourceSets {
        commonMain.dependencies {
            implementation(compose.runtime)
            implementation(compose.foundation)
            implementation(compose.material)
            implementation(compose.material3)
            implementation(compose.ui)
        }
        androidMain.dependencies {
            implementation(libs.androidx.activity.compose)
        }
        val ohosArm64Main by getting {
            dependencies {
                implementation("org.jetbrains.skiko:skiko-ohosarm64")
            }
        }
        val ohosX64Main by getting {
            dependencies {
                implementation("org.jetbrains.skiko:skiko-ohosx64")
            }
        }
    }
}

android {
    namespace = "com.example.lib06"
    compileSdk = libs.versions.android.compileSdk.get().toInt()
    defaultConfig {
        minSdk = libs.versions.android.minSdk.get().toInt()
    }
    compileOptions {
        sourceCompatibility = JavaVersion.VERSION_11
        targetCompatibility = JavaVersion.VERSION_11
    }
}

compose {
    ohos {
        skia("0.9.22.2-OH.0.1.2-06")
    }
}

val versionCatalog = extensions.getByType<VersionCatalogsExtension>().named("libs")
val cmpVersion = versionCatalog.findVersion("composeMultiplatform")
    .orElseThrow { IllegalStateException("Missing version composeMultiplatform in version catalog") }
    .requiredVersion

configurations.all {
    resolutionStrategy {
        force("org.jetbrains.compose.export:export-ohosarm64:${cmpVersion}")
        force("org.jetbrains.compose.ui:ui-ohosarm64:${cmpVersion}")
        force("org.jetbrains.compose.ui:ui-arkui-ohosarm64:${cmpVersion}")
        force("org.jetbrains.compose.foundation:foundation-ohosarm64:${cmpVersion}")
        force("org.jetbrains.compose.export:export-ohosx64:${cmpVersion}")
        force("org.jetbrains.compose.ui:ui-ohosx64:${cmpVersion}")
        force("org.jetbrains.compose.ui:ui-arkui-ohosx64:${cmpVersion}")
        force("org.jetbrains.compose.foundation:foundation-ohosx64:${cmpVersion}")
    }
}
