@file:Suppress("UNUSED_EXPRESSION")

package com.example.wabi.view.components.images

import android.net.Uri
import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.layout.ContentScale
import coil.compose.AsyncImagePainter.State
import coil.compose.rememberAsyncImagePainter
import coil.request.ImageRequest
import coil.size.Size.Companion.ORIGINAL
import com.example.wabi.domain.repository.UserShareDate

@Composable
fun CoilImageInput(
    image: Uri, modifier: Modifier = Modifier, standartImage: Unit
) {
    val painter = rememberAsyncImagePainter(
        model = ImageRequest.Builder(UserShareDate.context!!).data(image).size(ORIGINAL).build(),
        contentScale = ContentScale.Crop
    ).state

    if (painter is State.Error) {
        standartImage
    } else {
        if (painter is State.Success) {
            Image(
                painter = painter.painter,
                contentDescription = "Image from URI",
                contentScale = ContentScale.Crop,
                modifier = modifier.background(color = Color.White)
            )
        }
    }
}