(function () {
    const messageInput = document.getElementById('messageInputTag');
    const submitButton = document.getElementById('submitButton');
    if (messageInput){
        messageInput.addEventListener('input', function () {
            if (messageInput.value.trim() !== "") {
                submitButton.classList.remove('hidden');
            } else {
                submitButton.classList.add('hidden');
            }
        });
    }


    document.querySelectorAll('.reaction-button').forEach(button => {
        button.addEventListener('click', function() {
            const reaction = this.getAttribute('data-reaction');
            const eventMessage = {
                event_type: 'submit_review',
                reaction: reaction
            };
            osichatSocket.send(JSON.stringify(eventMessage));
        });
    });



    if (document.getElementById('sendReview')){
        document.getElementById('sendReview').addEventListener('submit', function(event) {
            event.preventDefault();
        
            const details = document.getElementById('messageInputTag').value.trim();
            if (details) {
                const eventMessage = {
                    event_type: 'submit_review',
                    details: details
                };
        
                osichatSocket.send(JSON.stringify(eventMessage));
            } else {
                console.error('Details cannot be empty');
            }
        });
    }   
    


    document.getElementById("startNewConversation").addEventListener("click", function() {
        const eventMessage = {
            event_type: "start_conversation"
        };
        osichatSocket.send(JSON.stringify(eventMessage));
    });



})();