/**
 * EasySite Pro – Header/Footer builder (drag-and-drop stub)
 */
(function ($) {
	'use strict';

	var $sortable = $('.easysite-builder-sortable');

	if (!$sortable.length || typeof $sortable.sortable !== 'function') {
		// jQuery UI sortable may not be loaded; use native drag fallback message
		return;
	}

	$sortable.sortable({
		update: function () {
			var layout = [];
			$(this).children('li').each(function () {
				layout.push($(this).data('element'));
			});
			$.post(easysiteAdmin.ajaxUrl, {
				action: 'easysite_save_header_layout',
				nonce: easysiteAdmin.nonce,
				layout: layout
			});
		}
	});
})(jQuery);
