(function ($) {
	'use strict';

	if (typeof wppsCustomPostOrder === 'undefined' || !wppsCustomPostOrder.listTable || typeof window.wppsOrderingUi === 'undefined') {
		return;
	}

	window.wppsOrderingUi.initListTable({
		config: wppsCustomPostOrder,
		tbodySelector: '#the-list',
		actions: {
			save: 'wpps_cpo_save_order'
		},
		buildPayload: function () {
			return {
				post_type: wppsCustomPostOrder.objectType || window.typenow || 'post',
				parent_id: 0,
				scope: 'list_table'
			};
		},
		extractId: function ($row) {
			var id = $row.attr('id');
			if (!id || id.indexOf('post-') !== 0) {
				return 0;
			}
			return parseInt(id.replace('post-', ''), 10) || 0;
		}
	});
})(jQuery);
