<?php
/**
 * 用户卡片组件
 * 
 * @param array $user 用户数据
 * @param string $size 尺寸: small|medium|large
 * @param bool $showFollow 是否显示关注按钮
 */

$userId = $user['id'] ?? '';
$username = $user['username'] ?? '未知用户';
$avatar = $user['avatar'] ?? '';
$bio = $user['bio'] ?? '';
$followers = $user['followers_count'] ?? 0;
$following = $user['following_count'] ?? 0;
$verified = $user['verified'] ?? false;
$isFollowing = $user['is_following'] ?? false;
$size = $size ?? 'medium';

$avatarUrl = $avatar ? Helper::uploadUrl($avatar) : $this->themeUrl() . '/images/avatar_default.png';
$sizeClass = "user-card-{$size}";
?>
<div class="user-card <?php echo $sizeClass; ?>" onclick="window.location.href='<?php echo Helper::getBaseUrl(); ?>/?r=mobile/user&id=<?php echo $userId; ?>'">
    <img class="user-card-avatar" src="<?php echo $avatarUrl; ?>" alt="<?php echo htmlspecialchars($username); ?>">
    <div class="user-card-name">
        <?php echo htmlspecialchars($username); ?>
        <?php if ($verified): ?>
        <span class="verified-badge" title="已认证">✓</span>
        <?php endif; ?>
    </div>
    <?php if ($size !== 'small'): ?>
    <div class="user-card-stats">
        <span><?php echo number_format($followers); ?> 粉丝</span>
        <span><?php echo number_format($following); ?> 关注</span>
    </div>
    <?php endif; ?>
    <?php if ($bio && $size === 'large'): ?>
    <div class="user-card-bio"><?php echo htmlspecialchars($bio); ?></div>
    <?php endif; ?>
    <?php if ($showFollow && isset($_SESSION['user_id']) && $_SESSION['user_id'] != $userId): ?>
    <button class="user-card-follow-btn <?php echo $isFollowing ? 'following' : ''; ?>" 
            data-user-id="<?php echo $userId; ?>"
            onclick="event.stopPropagation(); handleFollow(this);">
        <?php echo $isFollowing ? '已关注' : '关注'; ?>
    </button>
    <?php endif; ?>
</div>
