package com.aiosman.ravenow.ui.group

import androidx.compose.foundation.layout.*
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.material3.Text
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.platform.LocalContext
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.aiosman.ravenow.LocalAppTheme
import com.aiosman.ravenow.R
import com.aiosman.ravenow.ui.composables.CustomAsyncImage
import com.aiosman.ravenow.ui.composables.Checkbox
import com.aiosman.ravenow.ui.modifiers.noRippleClickable

@Composable
fun MemberItem(
    member: GroupMember,
    isSelected: Boolean = false,
    onSelect: () -> Unit
) {
    val AppColors = LocalAppTheme.current
    val context = LocalContext.current
    
    Row(
        modifier = Modifier
            .fillMaxWidth()
            .height(56.dp) // 固定高度防止跳动
            .noRippleClickable { onSelect() }
            .padding(horizontal = 0.dp, vertical = 8.dp),
        verticalAlignment = Alignment.CenterVertically
    ) {
        CustomAsyncImage(
            context = context,
            imageUrl = member.avatar,
            contentDescription = member.name,
            defaultRes = R.drawable.default_avatar,
            placeholderRes = R.drawable.default_avatar,
            errorRes = R.drawable.default_avatar,
            modifier = Modifier
                .size(40.dp)
                .clip(CircleShape)
        )
        
        Spacer(modifier = Modifier.width(12.dp))
        
        Text(
            text = member.name,
            fontSize = 16.sp,
            color = AppColors.text,
            modifier = Modifier.weight(1f)
        )
        
        Spacer(modifier = Modifier.width(8.dp))
        
        Checkbox(
            size = 20,
            checked = isSelected,
            onCheckedChange = { onSelect() }
        )
    }
}
