<?php
/**
 * defaultpro 移动端话题页
 */
$currentPage = 'topic';
$pageType = 'topic';
$bodyClass = 'topic-page';
$showBack = true;
$headerTitle = '#' . $keyword . '#';
$this->setLayout('app');
?>
<div class="post-list" id="topicPosts">
    <div class="loading-indicator">
        <div class="loading-spinner"></div>
    </div>
</div>
<button class="load-more-btn" id="loadMoreBtn" style="display:none;">加载更多</button>

<script>
(function() {
    var keyword = '<?= $this->escape($keyword) ?>';
    var page = 1;
    var loading = false;
    var hasMore = true;
    
    function loadPosts() {
        if (loading || !hasMore) return;
        loading = true;
        
        $.get(App.baseUrl + '/api/post/topic', {keyword: keyword, page: page}, function(res) {
            if (res.code === 0) {
                var html = res.data.list.map(function(post) {
                    return App.renderPostCard(post);
                }).join('');
                $('#topicPosts').append(html);
                hasMore = res.data.has_more;
                page++;
                $('#loadMoreBtn').toggle(hasMore);
            }
            loading = false;
        });
    }
    
    loadPosts();
    
    $(window).on('scroll', function() {
        if ($(window).scrollTop() + $(window).height() >= $(document).height() - 100) {
            loadPosts();
        }
    });
    
    $('#loadMoreBtn').on('click', loadPosts);
})();
</script>
