/*
 * Copyright 2024 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/**
 * This file was created using the `create_project.py` script located in the
 * `<AndroidX root>/development/project-creator` directory.
 *
 * Please use that script when creating a new project, rather than copying an existing project and
 * modifying its settings.
 */
import androidx.build.SoftwareType
import androidx.build.PlatformIdentifier

plugins {
    id("AndroidXPlugin")
    id("AndroidXComposePlugin")
    alias(libs.plugins.kotlinSerialization)
}

androidXMultiplatform {
    androidLibrary {
        compileSdk = 36
        namespace = "androidx.navigation3.ui"
        androidResources.enable = true
    }
    jvmStubs()
    linuxX64Stubs()

    defaultPlatform(PlatformIdentifier.ANDROID)

    sourceSets {
        commonMain {
            dependencies {
                api(project(":navigation3:navigation3-runtime"))
                api(project(":navigationevent:navigationevent-compose"))
                api("androidx.compose.animation:animation:1.9.0-rc01")
                api("androidx.compose.runtime:runtime:1.9.0-rc01")
                api("androidx.compose.runtime:runtime-saveable:1.9.0-rc01")
                api("androidx.compose.ui:ui:1.9.0-rc01")
                api("androidx.savedstate:savedstate:1.3.0")
                api("androidx.savedstate:savedstate-compose:1.3.0")
                implementation("androidx.annotation:annotation:1.8.0")
                implementation(libs.kotlinStdlib)
                implementation("androidx.collection:collection:1.4.5")
                // TODO pin lifecycle:lifecycle-runtime to the version that contains the `LifecycleOwner` composable api when it is released
                implementation(project(":lifecycle:lifecycle-runtime"))
                implementation(project(":lifecycle:lifecycle-runtime-compose"))
            }
        }

        commonTest {
            dependencies {
                implementation(libs.kotlinTest)
                implementation(project(":kruth:kruth"))
                implementation(project(":compose:runtime:runtime-test-utils"))
                implementation(project(":navigationevent:navigationevent-testing"))
            }
        }

        jvmMain {
            dependsOn(commonMain)
            dependencies {
            }
        }

        androidMain {
            dependsOn(jvmMain)
            dependencies {
                api(project(":activity:activity-compose"))
            }
        }

        jvmTest {
            dependsOn(commonTest)
            dependencies {
            }
        }

        androidInstrumentedTest {
            dependsOn(jvmTest)
            dependencies {
                implementation(project(":activity:activity-compose"))
                implementation(libs.testRules)
                implementation(libs.testRunner)
                implementation(libs.junit)
                implementation(libs.testExtJunitKtx)
                implementation(libs.truth)
                implementation("androidx.compose.material3:material3:1.3.1")
                implementation(project(":compose:test-utils"))
                implementation("androidx.compose.ui:ui-test:1.7.5")
                implementation("androidx.compose.ui:ui-test-junit4:1.7.5")
                implementation(libs.kotlinSerializationCore)
            }
        }

        commonStubsMain {
            dependsOn(commonMain)
        }

        jvmStubsMain {
            dependsOn(commonStubsMain)
        }
    }
}

androidx {
    name = "Androidx Navigation 3 UI"
    type = SoftwareType.PUBLISHED_LIBRARY_ONLY_USED_BY_KOTLIN_CONSUMERS
    inceptionYear = "2024"
    description = "Provides a Navigation3 display that uses the building blocks from runtime to " +
            "create a higher level solution."
    samples(project(":navigation3:navigation3-ui:navigation3-ui-samples"))
    addGoldenImageAssets()
}
