/*
 * Copyright (C) 2022 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.LibraryType

plugins {
    id("AndroidXPlugin")
    id("com.android.library")
    id("AndroidXComposePlugin")
}

androidXMultiplatform {
    android()

    sourceSets {
        commonMain {
            dependencies {
                implementation("androidx.compose.ui:ui:1.7.0")
                implementation("androidx.compose.ui:ui-unit:1.7.0")
                implementation("androidx.compose.ui:ui-util:1.7.0")
                implementation("androidx.compose.foundation:foundation:1.7.0")
                implementation("androidx.compose.foundation:foundation-layout:1.7.0")
                implementation(project(":constraintlayout:constraintlayout-core"))
                implementation("androidx.collection:collection:1.4.2")
            }
        }

        commonTest {
            dependencies {
            }
        }

        jvmCommonMain {
            dependsOn(commonMain)
            dependencies {
            }
        }


        androidMain {
            dependsOn(jvmCommonMain)
            dependencies {
                api("androidx.annotation:annotation:1.8.1")
                implementation("androidx.core:core-ktx:1.5.0")
            }
        }

        jvmCommonTest {
            dependsOn(commonTest)
            dependencies {
            }
        }

        androidInstrumentedTest {
            dependsOn(jvmCommonTest)
            dependencies {
                implementation(libs.kotlinTest)
                implementation(libs.testRules)
                implementation(libs.testRunner)
                implementation(libs.junit)
                implementation(libs.truth)
                implementation(project(":compose:foundation:foundation"))
                implementation(project(":compose:material:material"))
                implementation("androidx.compose.material:material-icons-core:1.6.7")
                implementation(project(":compose:ui:ui-test-junit4"))
                implementation(project(":compose:ui:ui-test-manifest"))
                implementation(project(":compose:test-utils"))
            }
        }

        androidUnitTest {
            dependsOn(jvmCommonTest)
            dependencies {
                implementation(libs.kotlinTest)
                implementation(libs.testRules)
                implementation(libs.testRunner)
                implementation(libs.junit)
            }
        }
    }
}

dependencies {
    lintPublish(project(":constraintlayout:constraintlayout-compose-lint"))
}

androidx {
    name = "ConstraintLayout Compose"
    type = LibraryType.PUBLISHED_LIBRARY_ONLY_USED_BY_KOTLIN_CONSUMERS
    mavenVersion = LibraryVersions.CONSTRAINTLAYOUT_COMPOSE
    inceptionYear = "2022"
    description = "This library offers a flexible and adaptable way to position and animate widgets in Compose"
    legacyDisableKotlinStrictApiMode = true
    metalavaK2UastEnabled = false
    samples(project(":constraintlayout:constraintlayout-compose:constraintlayout-compose-samples"))
}

android {
    compileSdk = 35
    namespace = "androidx.constraintlayout.compose"
}
