// 聊天页面功能
function testToggleEmoji(event) {
    event.stopPropagation();
    
    var picker = document.getElementById('chatEmojiPicker');
    if (!picker) return;
    
    if (picker.classList.contains('show')) {
        picker.classList.remove('show');
        document.body.classList.remove('emoji-open');
        return;
    }
    
    var emojiList = [
        '😀','😃','😄','😁','😆','😅','🤣','😂','🙂','😊','😇','🥰','😍','🤩','😘','😗',
        '😚','😋','😛','😜','🤪','😝','🤑','🤗','🤭','🤫','🤔','🤐','🤨','😐','😑','😶',
        '😏','😒','🙄','😬','🤥','😌','😔','😪','🤤','😴','😷','🤒','🤕','🤢','🤮','🤧',
        '🥵','🥶','🥴','😵','🤯','🤠','🥳','😎','🤓','🧐','😕','😟','🙁','☹️','😮','😯',
        '😲','😳','🥺','😦','😧','😨','😰','😥','😢','😭','😱','😖','😣','😞','😓','😩',
        '😫','🥱','😤','😡','😠','🤬','😈','👿','💀','☠️','💩','🤡','👹','👺','👻','👽',
        '👍','👎','🤝','🙏','💪','👏','🙌','👐','🤞','✌️','🤟','🤘','👌','🤏','👈','👉',
        '❤️','🧡','💛','💚','💙','💜','🖤','🤍','💔','❣️','💕','💞','💓','💗','💖','💘',
        '🌹','🌸','💐','🌺','🌻','🌼','🌷','🌱','🌿','☘️','🍀','🎄','🌲','🌳','🍃','🍂',
        '🎉','🎊','🎈','🎁','🏆','🥇','🥈','🥉','⚽','🏀','🏈','⚾','🎾','🏐','🏉','🎱'
    ];
    
    var html = '<div style="display:flex;justify-content:space-between;align-items:center;padding:12px 16px;border-bottom:1px solid #eee;"><span style="font-size:14px;font-weight:500;">选择表情</span><span onclick="testCloseEmoji()" style="width:28px;height:28px;display:flex;align-items:center;justify-content:center;font-size:20px;cursor:pointer;color:#999;">×</span></div>';
    html += '<div style="display:grid;grid-template-columns:repeat(8,1fr);padding:8px;gap:2px;max-height:240px;overflow-y:auto;">';
    for (var i = 0; i < emojiList.length; i++) {
        html += '<span onclick="testInsertEmoji(\'' + emojiList[i] + '\')" style="font-size:24px;padding:4px;text-align:center;cursor:pointer;border-radius:6px;">' + emojiList[i] + '</span>';
    }
    html += '</div>';
    picker.innerHTML = html;
    picker.classList.add('show');
    document.body.classList.add('emoji-open');
}

function testCloseEmoji() {
    var picker = document.getElementById('chatEmojiPicker');
    if (picker) {
        picker.classList.remove('show');
    }
    document.body.classList.remove('emoji-open');
}

function testInsertEmoji(emoji) {
    var input = document.getElementById('messageInput');
    if (input) {
        input.value += emoji;
        document.getElementById('sendBtn').disabled = !input.value.trim();
    }
}