<?php
/**
 * defaultpro 移动端转发页
 */
$currentPage = 'repost';
$pageType = 'repost';
$bodyClass = 'repost-page';
$hideTabBar = true;
$showBack = true;
$headerTitle = '转发';
$headerRight = '<button type="button" class="pub-publish-btn" id="repostSubmitBtn">转发</button>';
$this->setLayout('app');
?>
<div class="pub-page">
    <div class="pub-content-section">
        <textarea class="pub-textarea" id="repostContent" placeholder="说点什么..." rows="4"></textarea>
    </div>
    
    <div class="post-card" id="originalPost" style="margin:0 12px;border-radius:12px;">
        <div class="loading-indicator">
            <div class="loading-spinner"></div>
        </div>
    </div>
</div>

<script>
(function() {
    var postId = <?= $id ?>;
    
    // 加载原帖
    $.get(App.baseUrl + '/api/post/detail', {id: postId}, function(res) {
        if (res.code === 0) {
            var post = res.data;
            $('#originalPost').html(
                '<div class="post-user">'+
                    '<img class="post-avatar" src="'+post.avatar+'" alt="'+post.username+'">'+
                    '<div class="post-info">'+
                        '<div class="post-name">'+post.username+'</div>'+
                        '<div class="post-meta">'+post.created_at+'</div>'+
                    '</div>'+
                '</div>'+
                '<div class="post-content">'+post.content+'</div>'
            );
        }
    });
    
    // 转发提交
    $('#repostSubmitBtn').on('click', function() {
        var content = $('#repostContent').val().trim();
        
        $(this).prop('disabled', true).text('转发中...');
        
        $.post(App.baseUrl + '/api/post/repost', {
            id: postId,
            content: content
        }, function(res) {
            if (res.code === 0) {
                alert('转发成功');
                window.location.href = App.baseUrl + '/mobile';
            } else {
                alert(res.msg || '转发失败');
                $('#repostSubmitBtn').prop('disabled', false).text('转发');
            }
        });
    });
})();
</script>
