(function ($) {
	'use strict';

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

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