<?php if (!defined('__TYPECHO_ROOT_DIR__')) exit;
$db = \Typecho\Db::get();
?>
<div class="uc-page">
    <div class="uc-page-header">
        <h2 class="uc-page-title">我的评论</h2>
    </div>

    <div class="uc-list">
        <?php
        $comments = $db->fetchAll($db->select()->from('table.comments')
            ->where('authorId = ?', $this->user->uid)
            ->order('created', \Typecho\Db::SORT_DESC)
            ->limit(20));
        ?>

        <?php if (empty($comments)): ?>
            <div class="uc-empty"><img src="<?php $this->options->themeUrl('assets/images/no.svg'); ?>" alt="你还没有发表过评论">你还没有发表过评论</div>
        <?php else: ?>
            <?php foreach ($comments as $comment): ?>
                <?php
                $parentPost = $db->fetchRow($db->select('cid', 'title', 'slug')->from('table.contents')->where('cid = ?', $comment['cid']));
                if (!$parentPost) continue;
                ?>
                <div class="uc-list-item">
                    <div class="uc-item-body">
                        <div class="uc-item-text"><?php echo $comment['text']; ?></div>
                        <div class="uc-item-meta">
                            <span><i class="ri-time-line"></i> <?php echo (new \Typecho\Date($comment['created']))->format('Y-m-d H:i'); ?></span>
                            <span>评论于 <a href="<?php echo \Typecho\Router::url('post', $parentPost, $this->options->index); ?>"><?php echo $parentPost['title']; ?></a></span>
                        </div>
                    </div>
                    <span class="uc-tag uc-tag-<?php echo $comment['status'] == 'approved' ? 'success' : 'warning'; ?>">
                        <?php echo $comment['status'] == 'approved' ? '已通过' : '待审核'; ?>
                    </span>
                </div>
            <?php endforeach; ?>
        <?php endif; ?>
    </div>
</div>
