<?php
$canManage = isset($_SESSION['user_id']) && (
    $post['user_id'] == $_SESSION['user_id'] || 
    (isset($_SESSION['is_admin']) && $_SESSION['is_admin'])
);
$isAdmin = isset($_SESSION['is_admin']) && $_SESSION['is_admin'];
$isSelf = isset($_SESSION['user_id']) && $post['user_id'] == $_SESSION['user_id'];
$isFavorited = false;
if (isset($_SESSION['user_id']) && !$isSelf) {
    $favoriteModel = new FavoriteModel();
    $isFavorited = $favoriteModel->isFavorited($post['id'], $_SESSION['user_id']);
}
?>
<div class="post-actions">
    <button class="action-btn like-btn <?php echo !empty($post['liked']) ? 'liked' : ''; ?>" data-id="<?php echo $post['id']; ?>" aria-label="点赞">
        <span class="action-icon">👍</span>
        <span class="action-count"><?php echo $post['likes'] ?? 0; ?></span>
    </button>
    <button class="action-btn comment-btn" data-id="<?php echo $post['id']; ?>" aria-label="评论">
        <span class="action-icon">💬</span>
        <span class="action-count"><?php echo $post['comments'] ?? 0; ?></span>
    </button>
    <button class="action-btn repost-btn" data-id="<?php echo $post['id']; ?>" aria-label="转发">
        <span class="action-icon">🔁</span>
        <span class="action-count"><?php echo $post['reposts'] ?? 0; ?></span>
    </button>
    <?php if (!$isSelf): ?>
    <button class="action-btn favorite-btn <?php echo $isFavorited ? 'favorited' : ''; ?>" data-id="<?php echo $post['id']; ?>" aria-label="收藏">
        <span class="action-icon">⭐</span>
    </button>
    <?php endif; ?>
    <?php if ($canManage): ?>
    <button class="action-btn more-btn" data-id="<?php echo $post['id']; ?>" aria-label="更多">⋯</button>
    <div class="action-more-menu" data-post-id="<?php echo $post['id']; ?>">
        <?php if ($isSelf): ?>
        <a href="javascript:void(0)" class="more-item edit-post" data-id="<?php echo $post['id']; ?>">✏️ 编辑</a>
        <?php endif; ?>
        <a href="javascript:void(0)" class="more-item delete-post" data-id="<?php echo $post['id']; ?>" style="color:#ff4d4f;">🗑️ 删除</a>
        <?php if ($isAdmin): ?>
        <a href="javascript:void(0)" class="more-item pin-post" data-id="<?php echo $post['id']; ?>" data-pinned="<?php echo !empty($post['is_pinned']) ? 1 : 0; ?>">
            <?php echo !empty($post['is_pinned']) ? '📌 取消置顶' : '📌 置顶'; ?>
        </a>
        <a href="javascript:void(0)" class="more-item feature-post" data-id="<?php echo $post['id']; ?>" data-featured="<?php echo !empty($post['is_featured']) ? 1 : 0; ?>">
            <?php echo !empty($post['is_featured']) ? '⭐ 取消加精' : '⭐ 加精'; ?>
        </a>
        <?php endif; ?>
    </div>
    <?php endif; ?>
</div>
