jQuery(document).ready(function($) { // View suggestion details modal window.pcPreviewSuggestion = function(suggestionId) { $.ajax({ url: pcCommunitySuggestionsAdmin.ajax_url, type: 'POST', data: { action: 'pc_get_suggestion', suggestion_id: suggestionId, nonce: pcCommunitySuggestionsAdmin.nonce }, success: function(response) { if (response.success) { pcShowSuggestionModal(response.data); } else { alert(pcCommunitySuggestionsAdmin.i18n.action_failed + ': ' + response.data.message); } }, error: function() { alert(pcCommunitySuggestionsAdmin.i18n.action_failed); } }); }; function pcShowSuggestionModal(suggestion) { const modalHtml = ` `; $('body').append(modalHtml); $('.pc-modal').fadeIn(200); // Prevent background scrolling $('body').css('overflow', 'hidden'); } window.pcCloseModal = function() { $('.pc-modal').fadeOut(200, function() { $(this).remove(); }); $('body').css('overflow', ''); }; // Add comment functionality window.pcAddComment = function(suggestionId) { var $commentsRow = $('#pc-comments-' + suggestionId); $commentsRow.slideToggle(); }; window.pcSubmitComment = function(suggestionId) { var $textarea = $('#pc-comment-' + suggestionId); var comment = $textarea.val().trim(); if (!comment) { alert('Please enter a comment.'); return; } var $button = $textarea.siblings('button'); var originalText = $button.text(); $button.prop('disabled', true).text('Adding...'); $.ajax({ url: pcCommunitySuggestionsAdmin.ajax_url, type: 'POST', data: { action: 'pc_add_comment', suggestion_id: suggestionId, comment: comment, nonce: pcCommunitySuggestionsAdmin.nonce }, success: function(response) { if (response.success) { var commentHtml = '
' + '
' + '' + response.data.comment.author + ' ' + '' + response.data.comment.date + '' + '
' + '
' + response.data.comment.content + '
' + '
' + '' + '
' + '
'; var $commentsList = $('#pc-comments-list-' + suggestionId); $commentsList.find('.pc-no-comments').remove(); $commentsList.append(commentHtml); $textarea.val(''); alert(response.data.message); } else { alert(response.data.message || pcCommunitySuggestionsAdmin.i18n.action_failed); } }, error: function() { alert(pcCommunitySuggestionsAdmin.i18n.action_failed); }, complete: function() { $button.prop('disabled', false).text(originalText); } }); }; window.pcDeleteComment = function(commentId) { if (!confirm('Are you sure you want to delete this comment?')) { return; } $.ajax({ url: pcCommunitySuggestionsAdmin.ajax_url, type: 'POST', data: { action: 'pc_delete_comment', comment_id: commentId, nonce: pcCommunitySuggestionsAdmin.nonce }, success: function(response) { if (response.success) { $('.pc-comment-item[data-comment-id="' + commentId + '"]').fadeOut(300, function() { $(this).remove(); }); alert(response.data.message); } else { alert(response.data.message || pcCommunitySuggestionsAdmin.i18n.action_failed); } }, error: function() { alert(pcCommunitySuggestionsAdmin.i18n.action_failed); } }); }; // Close modal on overlay click $(document).on('click', '.pc-modal-overlay', function(e) { if (e.target === this) { pcCloseModal(); } }); // Close modal on ESC key $(document).on('keydown', function(e) { if (e.key === 'Escape' && $('.pc-modal').is(':visible')) { pcCloseModal(); } }); // Add modal styles $('