package com.pixelized.headache.utils.extention

import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.calculateEndPadding
import androidx.compose.foundation.layout.calculateStartPadding
import androidx.compose.runtime.Composable
import androidx.compose.runtime.Immutable
import androidx.compose.runtime.ReadOnlyComposable
import androidx.compose.runtime.Stable
import androidx.compose.ui.platform.LocalLayoutDirection
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.LayoutDirection

@ReadOnlyComposable
@Composable
fun PaddingValues.calculate(
    direction: LayoutDirection = LocalLayoutDirection.current,
): ComputedPaddingValue {
    return ComputedPaddingValue(
        start = calculateStartPadding(layoutDirection = direction),
        top = calculateTopPadding(),
        end = calculateEndPadding(layoutDirection = direction),
        bottom = calculateBottomPadding(),
    )
}

@Stable
@Immutable
data class ComputedPaddingValue(
    @Stable
    val start: Dp,
    @Stable
    val top: Dp,
    @Stable
    val end: Dp,
    @Stable
    val bottom: Dp,
) : PaddingValues {
    override fun calculateLeftPadding(layoutDirection: LayoutDirection): Dp = start

    override fun calculateTopPadding(): Dp = top

    override fun calculateRightPadding(layoutDirection: LayoutDirection): Dp = end

    override fun calculateBottomPadding(): Dp = bottom
}