package cl.homelogic.platform.designsystem.extensions

import androidx.compose.ui.Modifier
import androidx.compose.ui.semantics.Role
import androidx.compose.ui.semantics.contentDescription
import androidx.compose.ui.semantics.role
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.semantics.stateDescription
import androidx.compose.ui.semantics.testTag

data class AccessibilityInfo(
    val testTag: String,
    val contentDescription: String,
    val role: Role,
    val stateDescription: String? = null,
)

fun Modifier.accessibility(
    accessibilityInfo: AccessibilityInfo,
    mergeDescendants: Boolean = true,
) = this.semantics(mergeDescendants) {
    testTag = accessibilityInfo.testTag
    contentDescription = accessibilityInfo.contentDescription
    role = accessibilityInfo.role

    accessibilityInfo.stateDescription?.let {
        stateDescription = it
    }
}
