apply plugin: 'com.android.library'

group = 'expo.modules.gaodemap.navigation'
version = '2.0.0'

def expoModulesCorePlugin = new File(project(":expo-modules-core").projectDir.absolutePath, "ExpoModulesCorePlugin.gradle")
apply from: expoModulesCorePlugin
applyKotlinExpoModulesCorePlugin()
useCoreDependencies()
useExpoPublishing()

def useManagedAndroidSdkVersions = false
if (useManagedAndroidSdkVersions) {
  useDefaultAndroidSdkVersions()
} else {
  buildscript {
    ext.safeExtGet = { prop, fallback ->
      rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
    }
  }
  project.android {
    compileSdkVersion safeExtGet("compileSdkVersion", 36)
    defaultConfig {
      minSdkVersion safeExtGet("minSdkVersion", 24)
      targetSdkVersion safeExtGet("targetSdkVersion", 36)
    }
  }
}

logger.warn("[expo-gaode-map-navigation] Thank you for using expo-gaode-map-navigation ❤️")
logger.warn("[expo-gaode-map-navigation] If you enjoy using expo-gaode-map-navigation, please consider sponsoring this project: https://github.com/TomWq")

android {
  namespace "expo.modules.gaodemap.navigation"
  defaultConfig {
    versionCode 1
    versionName "2.0.0"
  }
  lintOptions {
    abortOnError false
  }
}

dependencies {
    def customSdkPath = null
    println "ExpoGaodeMapNavigation: Checking for custom SDK property in rootProject: ${rootProject.name}"
    if (rootProject.hasProperty("EXPO_GAODE_MAP_CUSTOM_SDK_PATH")) {
        customSdkPath = rootProject.property("EXPO_GAODE_MAP_CUSTOM_SDK_PATH")
        println "ExpoGaodeMapNavigation: Found custom SDK path property: ${customSdkPath}"
    }

    if (customSdkPath) {
        def sdkFile = rootProject.file(customSdkPath)
        if (!sdkFile.exists()) {
             sdkFile = new File(rootProject.projectDir.parentFile, customSdkPath)
        }
        
        if (sdkFile.exists()) {
            println "ExpoGaodeMapNavigation: Using custom Map SDK from ${sdkFile.absolutePath}"
            implementation files(sdkFile)
        } else {
            println "ExpoGaodeMapNavigation: Custom SDK path configured but file not found, falling back to Maven dependency."
            implementation 'com.amap.api:navi-3dmap:latest.integration'
        }
    } else {
        implementation 'com.amap.api:navi-3dmap:latest.integration'
    }
}
