package com.isidroid.render_preview

import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.layout.onGloballyPositioned
import androidx.compose.ui.unit.IntSize
import androidx.compose.ui.unit.dp
import timber.log.Timber

@Composable
fun RenderPlaceholderComponent(
    onSize: (IntSize) -> Unit,
    modifier: Modifier = Modifier
) {
    var containerSize by remember { mutableStateOf<IntSize?>(null) }

    LaunchedEffect(containerSize) { containerSize?.also { onSize(it) } }

    Box(
        modifier = modifier
            .fillMaxWidth()
            .padding(vertical = 16.dp)
            .onGloballyPositioned { containerSize = it.size }
    )
}