/*
 * Copyright 2024 Mifos Initiative
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at https://mozilla.org/MPL/2.0/.
 *
 * See https://github.com/openMF/mobile-wallet/blob/master/LICENSE.md
 */
package org.mifospay.core.ui

import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.ImageBitmap
import androidx.compose.ui.layout.ContentScale
import org.mifospay.core.designsystem.component.MifosTextUserImage
import template.core.base.designsystem.theme.KptTheme

@Composable
fun MifosUserImage(
    modifier: Modifier = Modifier,
    bitmap: ImageBitmap? = null,
    username: String? = null,
) {
    if (bitmap == null) {
        MifosTextUserImage(
            text = username?.firstOrNull()?.toString() ?: "J",
            modifier = modifier,
        )
    } else {
        Image(
            modifier = modifier
                .clip(CircleShape)
                .background(KptTheme.colorScheme.primary),
            bitmap = bitmap,
            contentDescription = "Profile Image",
            contentScale = ContentScale.Crop,
        )
    }
}
