def DEFAULT_COMPILE_SDK_VERSION = 35
def DEFAULT_MIN_SDK_VERSION = 21
def DEFAULT_TARGET_SDK_VERSION = 35
def DEFAULT_KOTLIN_VERSION = '2.0.21'

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

buildscript {
  // Buildscript is evaluated before everything else so we can't use safeExtGet
  def kotlin_version = rootProject.ext.has('kotlinVersion') ? rootProject.ext.get('kotlinVersion') : '2.0.21'
 if (project == rootProject) {
  repositories {
    google()
    mavenCentral()
  }

  dependencies {
    classpath "com.android.tools.build:gradle:7.2.1"
    // noinspection DifferentKotlinGradleVersion
    classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
  }
 }
}

apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'

def supportsNamespace() {
    def parsed = com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION.tokenize('.')
    def major = parsed[0].toInteger()
    def minor = parsed[1].toInteger()

    // Namespace support was added in 7.3.0
    return (major == 7 && minor >= 3) || major >= 8
}

android {
  compileSdkVersion safeExtGet('compileSdkVersion', DEFAULT_COMPILE_SDK_VERSION)
 if(supportsNamespace()) {
        namespace "com.mappls.sdk.direction.ui.react"

        sourceSets {
            main {
                manifest.srcFile "src/main/AndroidManifestNew.xml"
            }
        }
    }
  defaultConfig {
    minSdkVersion safeExtGet('minSdkVersion', DEFAULT_MIN_SDK_VERSION)
    targetSdkVersion safeExtGet('targetSdkVersion', DEFAULT_TARGET_SDK_VERSION)
    versionCode 1
    versionName "1.0"

  }

   buildFeatures {
    dataBinding true
  }


  buildTypes {
    release {
      minifyEnabled false
    }
  }
  lintOptions {
    abortOnError false
  }
}

repositories {
    // ref: https://www.baeldung.com/maven-local-repository
    mavenLocal()
    maven {
        // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
        url "$rootDir/../node_modules/react-native/android"
    }
    maven {
        // Android JSC is installed from npm
        url "$rootDir/../node_modules/jsc-android/dist"
    }
    maven {
        url 'https://maven.mappls.com/repository/mappls/'
    }
    google()
    mavenCentral()
}

def kotlin_version = safeExtGet('kotlinVersion', DEFAULT_KOTLIN_VERSION)

dependencies {
  implementation fileTree(dir: 'libs', include: ['*.aar'])

  // noinspection GradleDynamicVersion
  implementation 'com.facebook.react:react-native:+'
  implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
  //Direction Widget
  implementation 'com.mappls.sdk:direction-ui:3.0.1'

}
