package com.isidroid.render_preview

import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.Card
import androidx.compose.material3.CardDefaults
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import coil.compose.rememberAsyncImagePainter

@Composable
fun RenderPreviewComponent(
    widthPx: Float,
    heightPx: Float,
    filePath: String,
    modifier: Modifier = Modifier
) {
    if (widthPx == 0f || heightPx == 0f) return
    val (width, height) = with(LocalDensity.current) { listOf(widthPx.toDp(), heightPx.toDp()) }
    val shape = RoundedCornerShape(4.dp)

    Image(
        painter = rememberAsyncImagePainter(model = filePath),
        contentDescription = null,
        modifier = modifier
            .size(width, height)
            .background(Color.White, shape = shape)
    )

}

@Preview
@Composable
private fun RenderPreviewComponentPreview() {
    Surface {
        Box(modifier = Modifier.padding(12.dp)) {
            RenderPreviewComponent(
                widthPx = 800f,
                heightPx = 480f,
                filePath = ""
            )
        }
    }
}