package cl.homelogic.platform.navigation

import androidx.compose.animation.EnterTransition
import androidx.compose.animation.ExitTransition
import androidx.compose.animation.core.tween
import androidx.compose.animation.fadeIn
import androidx.compose.animation.fadeOut
import androidx.compose.animation.scaleIn
import androidx.compose.animation.scaleOut
import androidx.compose.animation.slideInHorizontally
import androidx.compose.animation.slideInVertically
import androidx.compose.animation.slideOutHorizontally
import androidx.compose.animation.slideOutVertically

enum class NavigationTransition {
    FLOW,
    SINGLE,
}

object NavigationAnimations {
    private const val ANIMATION_DURATION = 200
    private const val OVERLAY_SCALE_REDUCED = 0.95f
    private const val OVERLAY_OPACITY = 0.3f

    val horizontalEnter: EnterTransition = slideInHorizontally(
        initialOffsetX = { fullWidth -> fullWidth },
        animationSpec = tween(ANIMATION_DURATION),
    ) + fadeIn(
        animationSpec = tween(ANIMATION_DURATION),
    )

    val horizontalExit: ExitTransition = fadeOut(
        animationSpec = tween(ANIMATION_DURATION),
    ) + scaleOut(
        targetScale = OVERLAY_SCALE_REDUCED,
        animationSpec = tween(ANIMATION_DURATION),
    )

    val horizontalPopEnter: EnterTransition = fadeIn(
        animationSpec = tween(ANIMATION_DURATION),
    ) + scaleIn(
        initialScale = OVERLAY_SCALE_REDUCED,
        animationSpec = tween(ANIMATION_DURATION),
    )

    val horizontalPopExit: ExitTransition = slideOutHorizontally(
        targetOffsetX = { fullWidth -> fullWidth },
        animationSpec = tween(ANIMATION_DURATION),
    ) + fadeOut(
        animationSpec = tween(ANIMATION_DURATION),
    )

    // For vertical modal transitions
    val verticalEnter: EnterTransition = slideInVertically(
        initialOffsetY = { fullHeight -> fullHeight },
        animationSpec = tween(ANIMATION_DURATION),
    )

    val verticalExit: ExitTransition = fadeOut(
        targetAlpha = OVERLAY_OPACITY,
        animationSpec = tween(ANIMATION_DURATION),
    ) + scaleOut(
        targetScale = OVERLAY_SCALE_REDUCED,
        animationSpec = tween(ANIMATION_DURATION),
    )

    val verticalPopEnter: EnterTransition = fadeIn(
        initialAlpha = OVERLAY_OPACITY,
        animationSpec = tween(ANIMATION_DURATION),
    ) + scaleIn(
        initialScale = OVERLAY_SCALE_REDUCED,
        animationSpec = tween(ANIMATION_DURATION),
    )

    val verticalPopExit: ExitTransition = slideOutVertically(
        targetOffsetY = { fullHeight -> fullHeight },
        animationSpec = tween(ANIMATION_DURATION),
    )
}
