jQuery(document).ready(function(){jQuery(".wpse-duplicate-trigger").on("click",function(e){e.preventDefault();var o=jQuery(this).parents(".remodal");if(!o.find(".duplicate-modal-post-selector").val())return o.find(".duplicate-modal-post-selector")[0].reportValidity(),!0;window.wpseAddRowExtraData=o.find("input,select,textarea").serialize();var n=parseInt(o.find('[name="number_of_copies"]').val()),r=vgse_editor_settings.duplicate_batch_size,e=Math.ceil(n/r),t=jQuery(".remodal-bg").data("nonce"),s=vgse_editor_settings.post_type,a=window.wpseAddRowExtraData,d=(loading_ajax({estado:!1}),o.find(".response")),i=(d.before('<div id="be-duplicate-nanobar-container" />'),{classname:"be-progress-bar",target:document.getElementById("be-duplicate-nanobar-container")}),l=new Nanobar(i),p=(l.go(2),n),c=r;beAjaxLoop({totalCalls:e,url:vgse_global_data.ajax_url,method:"POST",data:{action:"vgse_insert_individual_post",nonce:t,post_type:s,rows:0,extra_data:a,dont_return_new_rows:5<p?"yes":null},prepareData:function(e,t){var t=(t.current-1)*r,a=Math.min(t+r,n);return e.rows=a-t,e},onSuccess:function(e,t,a){if(loading_ajax({estado:!1}),!(e=!0===e.success||e.data?e:{data:{message:vgse_editor_settings.texts.http_error_try_now},success:!1}).success)return jQuery(d).append("<p>"+e.data.message+"</p>"),confirm(e.data.message)?(t.current=0,d.scrollTop(d[0].scrollHeight),!0):(jQuery(d).append(vgse_editor_settings.texts.saving_stop_error),d.scrollTop(d[0].scrollHeight),!1);vgseAddFoundRowsCount(window.beFoundRows+parseInt(a.rows)),vgAddRowsToSheet(e.data.message,"prepend"),jQuery("body").trigger("vgSheetEditor:afterNewRowsInsert",[e,s,a.rows]);a=t.current/t.totalCalls*100,l.go(a=a<1?1:a),a=parseInt(c)*t.current>p?p:parseInt(c)*t.current,a=(a=vgse_editor_settings.texts.paged_batch_saved.replace("{updated}",a)).replace("{total}",p);return jQuery(d).empty().append("<p>"+a+"</p>"),e.data.force_complete&&(t.current=t.totalCalls),t.current===t.totalCalls&&(jQuery(d).append("<p>"+vgse_editor_settings.texts.everything_saved+"</p>"),loading_ajax({estado:!1}),l.go(100),notification({mensaje:vgse_editor_settings.texts.process_finished}),d.find(".remodal-cancel").removeClass("hidden"),o.find("#be-duplicate-nanobar-container").remove(),o.find('[name="number_of_copies"]').val("").trigger("change"),5<p)&&vgseReloadSpreadsheet(!0),setTimeout(function(){d.scrollTop(d[0].scrollHeight)},600),!0}})}),jQuery("body").on("vgSheetEditor:afterNewRowsInsert",function(){"undefined"!=typeof wpseAddRowExtraData&&"string"==typeof wpseAddRowExtraData&&-1<wpseAddRowExtraData.indexOf("duplicate_this")&&(wpseAddRowExtraData=null)}),jQuery(document).on("closed",".remodal-duplicate",function(){jQuery(".remodal-duplicate").find(".response").empty()}),jQuery(document).on("opened",".remodal-duplicate",function(){var a,o,e=vgseGetSelectedIds(),t=jQuery(".remodal-duplicate");t.find('[name="number_of_copies"]').val("1").trigger("change"),e.length&&(a=t.find(".duplicate-modal-post-selector"),o=[],e.forEach(function(e){var t=vgse_editor_settings.post_type+"--"+e;a.find('option[value="'+t+'"]').length||a.append('<option value="'+t+'">'+vgse_editor_settings.post_type+" ID "+e+"</option>"),o.push(t)}),a.val(o).trigger("change"))})}),jQuery(document).ready(function(){if("undefined"==typeof hot||!jQuery(".remodal-duplicate").length)return!0;var e=hot.getSettings().contextMenu;void 0===e.items&&(e.items={}),e.items.wpse_duplicate_row={name:vgse_editor_settings.texts.duplicate_row,callback:function(e,t,a){var o,n,r,s;beGetModifiedItems().length?alert(vgse_editor_settings.texts.save_changes_before_we_reload):(o=[],n=[],t.forEach(function(e){e.start.row<e.end.row?vgseRange(e.start.row,e.end.row).forEach(function(e){n.push(e)}):n.push(e.start.row)}),n.forEach(function(e){o[hot.getDataAtRowProp(e,"ID")]=vgseGetRowTitle(e)}),r=jQuery(".remodal-duplicate").find(".duplicate-modal-post-selector"),s=[],o.forEach(function(e,t){var a=vgse_editor_settings.post_type+"--"+t;r.find('option[value="'+a+'"]').length||r.append('<option value="'+a+'">'+e+" ("+t+")</option>"),s.push(a)}),r.val(s).trigger("change"),jQuery(".duplicate-container  button").click())}},hot.updateSettings({contextMenu:e})});