<?php
/**
 * defaultpro 移动端粉丝列表
 */
$currentPage = 'fans';
$pageType = 'fans';
$bodyClass = 'fans-page';
$showBack = true;
$headerTitle = '我的粉丝';
$this->setLayout('app');
?>
<div class="user-list" id="fansList">
    <div class="loading-indicator">
        <div class="loading-spinner"></div>
    </div>
</div>

<script>
(function() {
    var page = 1;
    var loading = false;
    var hasMore = true;
    var userId = <?= $_SESSION['user_id'] ?>;
    
    function loadFans() {
        if (loading || !hasMore) return;
        loading = true;
        
        $.get(App.baseUrl + '/mobileApi/userFans', {user_id: userId, page: page}, function(res) {
            if (res.code === 0) {
                var items = res.data.items || [];
                var html = items.map(function(u) {
                    var isFollowing = u.is_following ? 'followed' : '';
                    var btnText = u.is_following ? '已关注' : '关注';
                    return '<div class="user-item">'+
                        '<a href="'+App.baseUrl+'/mobile/user?username='+encodeURIComponent(u.username)+'">'+
                        '<img class="user-item-avatar" src="'+u.avatar+'" alt="'+u.username+'">'+
                        '</a>'+
                        '<a href="'+App.baseUrl+'/mobile/user?username='+encodeURIComponent(u.username)+'" class="user-item-info">'+
                            '<div class="user-item-name">'+escapeHtml(u.username)+'</div>'+
                            '<div class="user-item-bio">'+(u.bio || '这个人很懒')+'</div>'+
                        '</a>'+
                        '<button class="user-item-btn '+isFollowing+'" data-id="'+u.id+'">'+btnText+'</button>'+
                    '</div>';
                }).join('');
                if (page === 1 && items.length === 0) {
                    $('#fansList').html('<div class="empty-state"><i class="fa-solid fa-users"></i>暂无粉丝</div>');
                } else {
                    $('#fansList').append(html);
                }
                hasMore = res.data.pagination ? res.data.pagination.has_more : false;
                page++;
            }
            loading = false;
        });
    }
    
    loadFans();
})();
</script>
