/**
 * GiraForms - Admin JavaScript
 */

(function ($) {
	'use strict';

	$(document).ready(function () {
		/**
		 * Confirm delete actions
		 */
		$('.delete a').on('click', function (e) {
			if (!confirm(giraFormsAdmin.strings.confirmDelete)) {
				e.preventDefault();
				return false;
			}
		});

		/**
		 * Auto-refresh submissions list
		 */
		if ($('.wp-list-table.submissions').length) {
			// Optional: Add auto-refresh every 30 seconds
			// setInterval(function() {
			//     location.reload();
			// }, 30000);
		}

		/**
		 * Export functionality
		 */
		$('.giraforms-export-button').on('click', function (e) {
			const formId = $('#form_id_filter').val();
			if (formId) {
				$(this).attr('href', $(this).data('export-url') + '&form_id=' + formId);
			}
		});

		/**
		 * Bulk actions handler
		 */
		$('#doaction, #doaction2').on('click', function (e) {
			const action = $(this).siblings('select').val();
			const selected = $('input[name="submission[]"]:checked').length;

			if (action === 'delete' && selected > 0) {
				if (
					!confirm(
						'Are you sure you want to delete ' + selected + ' submission(s)?'
					)
				) {
					e.preventDefault();
					return false;
				}
			}
		});

		
	});
})(jQuery);
