import groovy.json.JsonSlurper
import org.gradle.api.tasks.testing.logging.TestExceptionFormat

apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: "com.facebook.react"


react {
    jsRootDir = file("../../src/")
    libraryName = "rnnavigation"
    codegenJavaPackageName = "com.reactnativenavigation.react"
}


def safeExtGet(prop, fallback) {
    rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
}

def safeExtGetFallbackLowerBound(prop, fallback) {
    Math.max(safeExtGet(prop, fallback), fallback)
}

def DEFAULT_COMPILE_SDK_VERSION = 35
def DEFAULT_MIN_SDK_VERSION = 24
def DEFAULT_TARGET_SDK_VERSION = 35
def DEFAULT_KOTLIN_VERSION = "1.5.31"
def DEFAULT_KOTLIN_STDLIB = 'kotlin-stdlib-jdk8'
def DEFAULT_BUILD_TOOLS_VERSION = "35.0.0"
def kotlinVersion = safeExtGet("RNNKotlinVersion", DEFAULT_KOTLIN_VERSION)
def kotlinStdlib = safeExtGet('RNNKotlinStdlib', DEFAULT_KOTLIN_STDLIB)
def kotlinCoroutinesCore = safeExtGet('RNNKotlinCoroutinesCore', '1.5.2')
def _buildToolsVersion = safeExtGet('buildToolsVersion', DEFAULT_BUILD_TOOLS_VERSION)

android {
    namespace 'com.reactnativenavigation'
    compileSdkVersion safeExtGetFallbackLowerBound('compileSdkVersion', DEFAULT_COMPILE_SDK_VERSION)
    buildToolsVersion = _buildToolsVersion
    defaultConfig {
        minSdkVersion safeExtGetFallbackLowerBound('minSdkVersion', DEFAULT_MIN_SDK_VERSION)
        targetSdkVersion safeExtGetFallbackLowerBound('targetSdkVersion', DEFAULT_TARGET_SDK_VERSION)

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
        }
        debug {
            minifyEnabled false
        }
    }
    lintOptions {
        abortOnError false
    }

    testOptions {
        managedDevices {
            localDevices {
                pixel3aapi34 {
                    device = "Pixel 3a"
                    apiLevel = 34
                    systemImageSource = "aosp-atd"
                }
            }
        }
        unitTests.includeAndroidResources = true
        unitTests.all { t ->
            maxHeapSize = "4g"
            testLogging {
                events "PASSED", "SKIPPED", "FAILED"
                exceptionFormat TestExceptionFormat.FULL
                showExceptions true
                showCauses true
                showStackTraces true
            }
            afterSuite { desc, result ->
                if (!desc.parent) { // will match the outermost suite
                    def output = "      ${result.resultType} (${result.successfulTestCount} successes, ${result.failedTestCount} failures, ${result.skippedTestCount} skipped)     "
                    def repeatLength = output.length()
                    println '\n\n' + ('-' * repeatLength) + '\n' + output + '\n' + ('-' * repeatLength) + '\n'

                    println "see report at file://${t.reports.html.outputLocation}/index.html"
                }
            }
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_17
        targetCompatibility JavaVersion.VERSION_17
    }
    kotlinOptions {
        jvmTarget = JavaVersion.VERSION_17
    }
}

dependencies {

    implementation "androidx.core:core-ktx:1.6.0"
    implementation "org.jetbrains.kotlin:$kotlinStdlib:$kotlinVersion"
    implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$kotlinCoroutinesCore"
    implementation "androidx.constraintlayout:constraintlayout:2.0.4"

    implementation 'androidx.appcompat:appcompat:1.7.0'
    implementation 'androidx.annotation:annotation:1.2.0'
    implementation 'com.google.android.material:material:1.2.0-alpha03'

    implementation 'com.github.wix-playground:ahbottomnavigation:4.0.0'
    implementation 'com.github.Dimezis:BlurView:version-3.0.0'
//    implementation project(':AHBottomNavigation')
    implementation 'com.github.wix-playground:reflow-animator:1.0.6'
    implementation 'com.github.clans:fab:1.6.4'

    //noinspection GradleDynamicVersion
    implementation 'com.facebook.react:react-native:+'


    if ("Playground".toLowerCase() == rootProject.name.toLowerCase()) {
        // tests only for our playground
        testImplementation 'junit:junit:4.13.2'
        testImplementation "org.robolectric:robolectric:4.14.1"
        testImplementation 'org.assertj:assertj-core:3.11.1'
        testImplementation 'org.mockito:mockito-core:4.0.0'
        testImplementation 'com.squareup.assertj:assertj-android:1.2.0'
        testImplementation 'org.mockito:mockito-inline:4.6.1'
        testImplementation "org.mockito.kotlin:mockito-kotlin:4.0.0"
        testImplementation "org.jetbrains.kotlin:kotlin-test:$kotlinVersion"

        // Core testing libraries
        androidTestImplementation "androidx.test.ext:junit:1.2.1"
        androidTestImplementation 'org.assertj:assertj-core:3.11.1'

        androidTestImplementation "androidx.test.espresso:espresso-core:3.6.1"

        androidTestImplementation "com.linkedin.dexmaker:dexmaker-mockito-inline:2.28.4"
        androidTestImplementation 'org.opentest4j:opentest4j:1.2.0'
        androidTestImplementation ("org.mockito.kotlin:mockito-kotlin:5.4.0") {
            exclude group: 'org.mockito', module: 'mockito-core'
        }

        androidTestImplementation "androidx.test.uiautomator:uiautomator:2.3.0"

        androidTestImplementation("com.facebook.react:hermes-android")

    }
}
