buildscript {
  ext.PagerView = [
    kotlinVersion: "2.0.21",
    composeVersion: "1.7.8",
    lifecycleVersion: "2.6.1",
    minSdkVersion: 24,
    compileSdkVersion: 36
  ]

  ext.getExtOrDefault = { prop ->
    if (rootProject.ext.has(prop)) {
      return rootProject.ext.get(prop)
    }

    return PagerView[prop]
  }

  repositories {
    google()
    mavenCentral()
  }

  dependencies {
    classpath "com.android.tools.build:gradle:8.7.2"
    // noinspection DifferentKotlinGradleVersion
    classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${getExtOrDefault('kotlinVersion')}"
    classpath "org.jetbrains.kotlin:compose-compiler-gradle-plugin:${getExtOrDefault('kotlinVersion')}"
  }
}

apply plugin: "com.android.library"

if (project.extensions.findByName("kotlin") == null) {
  apply plugin: "kotlin-android"
}

apply plugin: "org.jetbrains.kotlin.plugin.compose"
apply plugin: "com.facebook.react"

android {
  namespace "com.reactnativepagerview"

  compileSdkVersion getExtOrDefault("compileSdkVersion")

  defaultConfig {
    minSdkVersion getExtOrDefault("minSdkVersion")
  }

  compileOptions {
    sourceCompatibility JavaVersion.VERSION_17
    targetCompatibility JavaVersion.VERSION_17
  }

  buildFeatures {
    compose true
  }
}

def composeVersion = getExtOrDefault("composeVersion")
def lifecycleVersion = getExtOrDefault("lifecycleVersion")

dependencies {
  implementation "com.facebook.react:react-android"
  implementation "androidx.compose.foundation:foundation:$composeVersion"
  implementation "androidx.compose.runtime:runtime:$composeVersion"
  implementation "androidx.compose.ui:ui:$composeVersion"
  // Needed for ComposeViewLifecycleOwner (see ComposePagerView.kt), which
  // gives the ComposeView a self-owned Lifecycle instead of the ambient one.
  implementation "androidx.lifecycle:lifecycle-runtime-ktx:$lifecycleVersion"
  testImplementation "androidx.arch.core:core-testing:2.2.0"
  testImplementation "junit:junit:4.13.2"
}
