package com.zaojiao.app.feat.design

import androidx.annotation.DrawableRes
import androidx.compose.foundation.Image
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.painter.ColorPainter
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.res.painterResource
import coil.compose.AsyncImage

object Images {
    @Composable
    fun Network(
        modifier: Modifier = Modifier,
        url: String?,
        description: String? = null,
        contentScale: ContentScale = ContentScale.Crop,
    ) {
        if (url != null) {
            AsyncImage(
                model = url,
                contentDescription = description,
                modifier = modifier,
                contentScale = contentScale,
                error = ColorPainter(Colors.FF999999),
            )
        } else {
            Image(
                painter = ColorPainter(Color(0xFFAAAAAA)),
                contentDescription = description,
                modifier = modifier,
                contentScale = contentScale,
            )
        }
    }

    @Composable
    fun Resource(
        modifier: Modifier = Modifier,
        @DrawableRes id: Int,
        description: String? = null,
        contentScale: ContentScale = ContentScale.Crop,
    ) {
        Image(
            painter = painterResource(id = id),
            contentDescription = description,
            modifier = modifier,
            contentScale = contentScale,
        )
    }
}