package io.nexilis.alpha.ui.components

import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Person
import androidx.compose.material.icons.filled.Verified
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.vector.rememberVectorPainter
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.unit.dp
import coil.compose.AsyncImage
import coil.request.ImageRequest
import io.nexilis.service.data.entities.Buddy

@Composable
fun Person(buddy: Buddy) {
    Column {
        Box(
            Modifier.align(Alignment.CenterHorizontally),
            contentAlignment = Alignment.BottomEnd
        ) {
            AsyncImage(
                model = ImageRequest.Builder(LocalContext.current)
                    .data("https://digixplatform.com/filepalio/image/${buddy.image_id}")
                    .addHeader("Cookie", "PHPSESSID=123;MOBILE=123")
                    .crossfade(true)
                    .build(),
                placeholder = rememberVectorPainter(image = Icons.Default.Person),
                contentDescription = "",
                contentScale = ContentScale.Crop,
                modifier = Modifier
                    .size(48.dp)
                    .clip(CircleShape)
                    .background(Color.LightGray),
                error = rememberVectorPainter(image = Icons.Default.Person),
            )
            if (buddy.official_account != "0") {
                val color: Color = when (buddy.official_account) {
                    "1", "3" -> {
                        Color(0xFF4c87ef)
                    }

                    "2" -> {
                        Color(0xFF0cff00)
                    }

                    "5" -> {
                        Color(0xFFE000FF)
                    }

                    else -> {
                        Color(0xFF4c87ef)
                    }
                }
                Icon(
                    imageVector = Icons.Default.Verified,
                    contentDescription = "",
                    modifier = Modifier
                        .size(16.dp)
                        .clip(CircleShape)
                        .background(color = MaterialTheme.colorScheme.surface),
                    tint = color
                )
            }
        }
    }
}