<?php

declare(strict_types=1);

/**
 * 技師評論按讚／收藏按鈕。
 * 需變數：$rv, $rvId, $mid, $masseurStoreId, $masseurCsrf, $loginNext, $masseurVerified, $masseurLoggedIn
 */

$rvLikeCount = (int) ($rv['like_count'] ?? 0);
$rvFavCount = (int) ($rv['favorite_count'] ?? 0);
$rvViewerLiked = !empty($rv['viewer_liked']);
$rvViewerFavorited = !empty($rv['viewer_favorited']);

?>
<footer class="masseur-review__foot">
    <?php if ($masseurVerified): ?>
        <form method="post" action="api/masseur_action.php" class="masseur-review-like-form">
            <input type="hidden" name="csrf" value="<?= htmlspecialchars($masseurCsrf, ENT_QUOTES, 'UTF-8') ?>">
            <input type="hidden" name="action" value="review_like">
            <input type="hidden" name="store_id" value="<?= (int) $masseurStoreId ?>">
            <input type="hidden" name="masseur_id" value="<?= (int) $mid ?>">
            <input type="hidden" name="review_id" value="<?= (int) $rvId ?>">
            <button type="submit" class="masseur-review-like-btn<?= $rvViewerLiked ? ' is-active' : '' ?>" title="<?= $rvViewerLiked ? '取消讚' : '按讚' ?>">👍 <?= $rvLikeCount ?></button>
        </form>
        <form method="post" action="api/masseur_action.php" class="masseur-review-fav-form">
            <input type="hidden" name="csrf" value="<?= htmlspecialchars($masseurCsrf, ENT_QUOTES, 'UTF-8') ?>">
            <input type="hidden" name="action" value="review_favorite">
            <input type="hidden" name="store_id" value="<?= (int) $masseurStoreId ?>">
            <input type="hidden" name="masseur_id" value="<?= (int) $mid ?>">
            <input type="hidden" name="review_id" value="<?= (int) $rvId ?>">
            <button type="submit" class="masseur-review-fav-btn<?= $rvViewerFavorited ? ' is-active' : '' ?>" title="<?= $rvViewerFavorited ? '取消收藏' : '收藏此評論' ?>"><?= $rvViewerFavorited ? '★' : '☆' ?> <?= $rvFavCount ?></button>
        </form>
    <?php else: ?>
        <span class="masseur-review-like-btn is-static" title="讚">👍 <?= $rvLikeCount ?></span>
        <?php if ($masseurLoggedIn): ?>
            <span class="masseur-review-fav-btn is-static" title="收藏">☆ <?= $rvFavCount ?></span>
        <?php else: ?>
            <a class="masseur-review-fav-btn masseur-review-fav-btn--guest" href="login.php?next=<?= $loginNext ?>" title="登入後可收藏">☆ <?= $rvFavCount ?></a>
        <?php endif; ?>
    <?php endif; ?>
</footer>
