$(document).ready(function() { // Bulk Email Recipient Management // Select All button $('#select-all-btn').click(function() { $('.recipient-checkbox').prop('checked', true); updateRecipientCount(); }); // Deselect All button $('#deselect-all-btn').click(function() { $('.recipient-checkbox').prop('checked', false); updateRecipientCount(); }); // Remove Selected button $('#remove-selected-btn').click(function() { $('.recipient-checkbox:checked').each(function() { $(this).closest('.recipient-item').slideUp(300, function() { $(this).remove(); updateRecipientCount(); }); }); }); // Update count when individual checkboxes are changed $(document).on('change', '.recipient-checkbox', function() { updateRecipientCount(); }); // Update recipient count display function updateRecipientCount() { var checkedCount = $('.recipient-checkbox:checked').length; var totalCount = $('.recipient-checkbox').length; $('#recipient-count').text(totalCount); // Update the next button state if (checkedCount === 0) { $('#next-compose-btn').prop('disabled', true).text('Select Recipients First'); } else { $('#next-compose-btn').prop('disabled', false).text('Next: Compose Email (' + checkedCount + ' selected)'); } } // Initialize count on page load if ($('.recipient-checkbox').length > 0) { updateRecipientCount(); } // Form validation for recipients step $('#recipients-form').submit(function(e) { var checkedCount = $('.recipient-checkbox:checked').length; if (checkedCount === 0) { e.preventDefault(); alert('Please select at least one recipient before proceeding.'); return false; } }); // Dynamic recipient filtering (if needed for future enhancement) $('#filter-recipients-input').on('keyup', function() { var value = $(this).val().toLowerCase(); $('.recipient-item').filter(function() { $(this).toggle($(this).text().toLowerCase().indexOf(value) > -1); }); }); // Preview email functionality $('#preview-email-btn').click(function() { var subject = $('#subject').val(); var body = $('#body').val(); if (subject.trim() === '' || body.trim() === '') { alert('Please enter both subject and body before previewing.'); return; } // Create preview modal (assuming Bootstrap modal) var modalHtml = '