// K2_ONLY

/*
 * Copyright 2010-2024 JetBrains s.r.o. and Kotlin Programming Language contributors.
 * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
 */

package androidx.compose.compiler.test

import androidx.compose.runtime.Composable
import androidx.compose.runtime.mock.Text
import androidx.compose.runtime.mock.compositionTest
import androidx.compose.runtime.mock.validate
import kotlin.test.Test

class DefaultParamOpenTests {
    @Test
    fun defaultParamInterfaceImpl() = compositionTest {
        val instance = DefaultParamInterfaceImpl()
        compose {
            instance.Content()
            instance.ComposedContent()
            instance.Content { Text("provided") }
            instance.ComposedContent { Text("provided") }
        }

        validate {
            Text("default")
            Text("default")
            Text("provided")
            Text("provided")
        }
    }

    @Test
    fun defaultParamClsImpl() = compositionTest {
        val instance = DefaultParamOpenImpl()
        compose {
            instance.Content()
            instance.ComposedContent()
            instance.Content { Text("provided") }
            instance.ComposedContent { Text("provided") }
        }

        validate {
            Text("default")
            Text("default")
            Text("provided")
            Text("provided")
        }
    }
}

private interface DefaultParamOpenInterface {
    @Composable
    fun Content(
        content: @Composable () -> Unit = @Composable { ComposedContent() },
    )

    @Composable
    fun ComposedContent(
        content: @Composable () -> Unit = @Composable { Text("default") },
    ) {
        content()
    }
}

private class DefaultParamInterfaceImpl : DefaultParamOpenInterface {
    @Composable
    override fun Content(content: @Composable () -> Unit) {
        content()
    }

    @Composable
    override fun ComposedContent(content: @Composable () -> Unit) {
        super.ComposedContent(content)
    }
}

private abstract class DefaultParamOpen {
    @Composable
    open fun Content(
        content: @Composable () -> Unit = @Composable { ComposedContent() },
    ) {
        content()
    }

    @Composable
    open fun ComposedContent(
        content: @Composable () -> Unit = @Composable { Text("default") },
    ) {
        content()
    }
}

private class DefaultParamOpenImpl : DefaultParamOpen() {
    @Composable
    override fun Content(content: @Composable () -> Unit) {
        content()
    }

    @Composable
    override fun ComposedContent(content: @Composable () -> Unit) {
        super.ComposedContent(content)
    }
}
