package ch.dissem.yaep.ui.common.layout

import androidx.compose.ui.unit.Constraints

enum class AspectRatio {
    PORTRAIT, LANDSCAPE, SQUARISH;

    companion object {
        private const val ASPECT_RATIO_LANDSCAPE = 1.4f
        private const val ASPECT_RATIO_PORTRAIT = 1 / ASPECT_RATIO_LANDSCAPE

        fun from(constraints: Constraints): AspectRatio {
            val ratio = constraints.maxWidth.toFloat() / constraints.maxHeight.toFloat()
            return when {
                ratio < ASPECT_RATIO_PORTRAIT -> PORTRAIT
                ratio > ASPECT_RATIO_LANDSCAPE -> LANDSCAPE
                else -> SQUARISH
            }
        }
    }
}