plugins {
    id 'com.android.application'
    id 'kotlin-android'
}
def android_builder_version = "4.0.1"

ext {
    android_builder_main_version = Integer.parseInt(android_builder_version.split("\\.")[0])
    android_builder_mid_version = Integer.parseInt(android_builder_version.split("\\.")[1])
}

android {
    this.rootProject.buildscript.configurations.classpath
            .resolvedConfiguration
            .firstLevelModuleDependencies.
            each {
                def name = it.name
                if (name.contains('com.android.tools.build:gradle')) {
                    def moduleVersion = it.moduleVersion
                    if (moduleVersion.contains("-")) {
                        def alphaversionArray = moduleVersion.split("-")[0]
                        def versionArray = alphaversionArray.toString().split("\\.")
                        ext.android_builder_main_version = Integer.parseInt(versionArray[0])
                        ext.android_builder_mid_version = Integer.parseInt(versionArray[1])
                    } else {
                        version = moduleVersion
                        android_builder_version = moduleVersion
                        ext.android_builder_main_version = Integer.parseInt(android_builder_version.split("\\.")[0])
                        ext.android_builder_mid_version = Integer.parseInt(android_builder_version.split("\\.")[1])
                    }
                }
            }
    compileSdkVersion 30
    buildToolsVersion "30.0.3"

    defaultConfig {
        applicationId "com.ellison.composemovie"
        minSdkVersion 27
        targetSdkVersion 30
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    kotlinOptions {
        jvmTarget = '1.8'
    }

    buildFeatures {
        viewBinding true
        dataBinding true
        if (android_builder_main_version >= 7 || (android_builder_main_version > 4 && android_builder_mid_version > 1)) {
            compose true
        }
        // Disable unused AGP features
        buildConfig false
        aidl false
        renderScript false
        resValues false
        shaders false
    }

    composeOptions {
        kotlinCompilerExtensionVersion compose_version
        kotlinCompilerVersion kotlin_version
    }

    packagingOptions {
        // Multiple dependency bring these files in. Exclude them to enable
        // our test APK to build (has no effect on our AARs)
        excludes += "/META-INF/AL2.0"
        excludes += "/META-INF/LGPL2.1"
    }
}

dependencies {
    testImplementation 'junit:junit:4.+'
    androidTestImplementation 'androidx.test.ext:junit:1.1.2'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'

    implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
    implementation 'androidx.core:core-ktx:1.3.2'

    implementation 'com.google.android.material:material:1.2.1'
    implementation 'androidx.constraintlayout:constraintlayout:2.0.4'

    implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutines_version"
    implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutines_version"

    implementation 'com.squareup.retrofit2:retrofit:2.9.0'
    implementation 'com.squareup.okhttp3:logging-interceptor:5.0.0-alpha.2'

    implementation 'com.squareup.retrofit2:converter-gson:2.9.0'

    implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.3.0'
    implementation "androidx.lifecycle:lifecycle-livedata:2.1.0"
    implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.1.0'
    implementation "androidx.lifecycle:lifecycle-extensions:2.1.0"

    //Compose
    if (android_builder_main_version < 7) {
        add("kotlinCompilerPluginClasspath", "androidx.compose.compiler:compiler:$compose_version")
    }

    implementation "androidx.appcompat:appcompat:$compose_appcompat_version"
    implementation "androidx.activity:activity-compose:$compose_activity_version"
    implementation "androidx.compose.ui:ui:$compose_version"
    implementation "androidx.compose.material:material:$compose_version"
    implementation "androidx.compose.material:material-icons-extended:$compose_version"
    implementation "androidx.compose.ui:ui-tooling:$compose_version"

    implementation "androidx.navigation:navigation-compose:$compose_navigation_version"

    implementation "androidx.compose.runtime:runtime:$compose_version"
    implementation "androidx.compose.runtime:runtime-livedata:$compose_version"


    // google.accompanist replace chrisbanes.accompanist !!!
//    implementation "dev.chrisbanes.accompanist:accompanist-coil:$compose_utils_chrisbanes_coil"

    implementation "com.google.accompanist:accompanist-coil:$compose_accompanist_version"
//    implementation "com.google.accompanist:accompanist-insets:$compose_accompanist_version"
//    implementation "com.google.accompanist:accompanist-insets-ui:$compose_accompanist_version"
//    implementation "com.google.accompanist:accompanist-pager:$compose_accompanist_version"
}