plugins {
    id 'com.android.library'
    id 'kotlin-android'
    id "com.google.devtools.ksp" version "1.8.10-1.0.9"
    id 'kotlinx-serialization'
}
apply from:rootProject.file('base.gradle')

android {
    buildFeatures {
        compose true
        buildConfig true
    }
    namespace 'com.funny.translation.core'
}

dependencies {
    // androidx.core
//    api 'androidx.core:core-ktx:1.7.0'
    api "org.jetbrains.kotlin:kotlin-stdlib-jdk8:${Versions.kotlinVersion}"
    api "org.jetbrains.kotlinx:kotlinx-datetime:0.4.0"
    api "org.jetbrains.kotlinx:kotlinx-serialization-json:1.4.1"
    api "org.jetbrains.kotlinx:kotlinx-collections-immutable:0.3.5"
    api "org.jetbrains.kotlin:kotlin-reflect:${Versions.kotlinVersion}"

    def coroutines_version = '1.5.1'
    api "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutines_version"
    api "org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutines_version"

    // OkHttp
    api "com.squareup.okhttp3:okhttp:4.9.1"

    // 网络请求
    def retrofit_version = "2.9.0"
    api "com.squareup.retrofit2:retrofit:$retrofit_version"
    implementation "com.jakewharton.retrofit:retrofit2-kotlinx-serialization-converter:0.8.0"
    implementation ('com.github.ihsanbal:LoggingInterceptor:3.1.0') {
        exclude group: 'org.json', module: 'json'
    }

    //JS rhino
    api 'com.github.gedoor:rhino-android:1.6'

    // Coil
    api "io.coil-kt:coil-compose:2.4.0"

    // 刘海屏适配
    api 'com.github.smarxpan:NotchScreenTool:0.0.1'

    // Material Design Color
    api "com.github.FunnySaltyFish:CMaterialColors:1.0.21"
    api 'com.github.FunnySaltyFish:ComposeLoading:v1.0.4'

    api "androidx.biometric:biometric:1.2.0-alpha05"

    api 'com.github.getActivity:ToastUtils:11.2'

    // api 'com.github.Kyant0.Monet:Monet:0.1.0-alpha03-multiplatform-fixed'
    implementation "androidx.palette:palette-ktx:1.0.0"

    // Markwon
    final def markwon_version = '4.6.2'
    implementation "io.noties.markwon:core:$markwon_version"
    implementation "io.noties.markwon:ext-strikethrough:$markwon_version"
    implementation "io.noties.markwon:ext-tables:$markwon_version"
    implementation "io.noties.markwon:html:$markwon_version"
    implementation "io.noties.markwon:image-coil:$markwon_version"
    implementation "io.noties.markwon:linkify:$markwon_version"
    implementation 'me.saket:better-link-movement-method:2.2.0'

    def room_version = Versions.roomVersion
    api "androidx.room:room-runtime:$room_version"
    api "androidx.room:room-ktx:$room_version"
    api "androidx.room:room-paging:$room_version"
    ksp "androidx.room:room-compiler:$room_version"

    api 'androidx.annotation:annotation:1.5.0'

    // Import the Compose BOM
    api platform("androidx.compose:compose-bom:${Versions.composeBomVersion}")
    api "androidx.compose.ui:ui"
    api "androidx.compose.material:material"
    api "androidx.compose.ui:ui-tooling"
    api "androidx.compose.animation:animation"

    api "androidx.appcompat:appcompat:${Versions.appCompatVersion}"
    api "androidx.navigation:navigation-compose:2.7.0"
    api "androidx.activity:activity-compose:${Versions.activityComposeVersion}"
    api "androidx.activity:activity-ktx:${Versions.activityComposeVersion}"
    api "androidx.lifecycle:lifecycle-viewmodel-compose:${Versions.lifeCycleViewModelComposeVersion}"
    // https://mvnrepository.com/artifact/androidx.lifecycle/lifecycle-runtime-ktx
    runtimeOnly 'androidx.lifecycle:lifecycle-runtime-ktx:2.6.1'


    api "androidx.compose.material3:material3"
    api "androidx.compose.material3:material3-window-size-class"

    def accompanist_version = "0.31.6-rc"
    api "com.google.accompanist:accompanist-systemuicontroller:$accompanist_version"
    api "com.google.accompanist:accompanist-navigation-animation:$accompanist_version"
    api "com.google.accompanist:accompanist-pager-indicators:$accompanist_version"
    api "com.google.accompanist:accompanist-permissions:$accompanist_version"
    api project(path: ':jet-setting-core')

    implementation(name: "monet", ext: "aar");

    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test.ext:junit:1.1.3'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}

// 定义函数，用于输出 Hello, FunnyTranslation Open Source
static def printHello(Exec exec) {
    // just print FunnyTranslation OpenSource
    // windows: cmd /c echo FunnyTranslation OpenSource
    // linux: sh -c echo FunnyTranslation OpenSource
    if (System.getProperty("os.name").toLowerCase().contains("windows")) {
        exec.commandLine "cmd", "/c", "echo", "Hello FunnyTranslation-OpenSource"
    } else {
        exec.commandLine "sh", "-c", "echo", "Hello FunnyTranslation-OpenSource"
    }
}

tasks.register('encryptFunnyJs', Exec) {
    // 如果 funny_sign_v1_release 存在，则用它
    def release = new File(rootDir, "funny_sign_v1_release_template.js")
    println("release.exists() = " + release.exists())
    if (release.exists()) {
        def filePath = release.absolutePath
        def assetsDir = android.sourceSets.main.assets.srcDirs[0]
        def targetFilePath = new File(assetsDir, "funny_sign_v1_release.js").absolutePath
        def versionCode = Versions.versionCode
        commandLine "node", rootProject.file("encrypt_funny_js.js"), filePath, targetFilePath, versionCode
    } else {
        printHello(it)
    }
    standardOutput = new ByteArrayOutputStream()
    doLast {
        println standardOutput.toString()
    }
}

tasks.register("signApk", Exec) { exec ->
    // 执行根目录下的 sign_new_key.py
    def signNewKey = rootProject.file("sign_new_key.py")
    if (signNewKey.exists()) {
        exec.commandLine "python", signNewKey.path, rootDir.path
    } else {
        printHello(exec)
    }
}