package com.pixelized.desktop.lwa.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

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

@Composable
@ReadOnlyComposable
fun PaddingValues.calculateVerticalPaddings(): PaddingValues {
    return PaddingValues(
        top = calculateTopPadding(),
        bottom = calculateBottomPadding(),
    )
}


@Composable
@ReadOnlyComposable
fun PaddingValues.calculateHorizontalPaddings(
    layoutDirection: LayoutDirection = LocalLayoutDirection.current,
): PaddingValues {
    return PaddingValues(
        start = calculateStartPadding(layoutDirection = layoutDirection),
        end = calculateEndPadding(layoutDirection = layoutDirection),
    )
}

@Immutable
@Stable
data class ComputedPaddingValues(
    @Stable val start: Dp,
    @Stable val top: Dp,
    @Stable val end: Dp,
    @Stable val bottom: Dp,
)