jQuery(document).ready(function(e){if(backendBulkSendingHandlerData=fiksef_bulkSendingHandlerData,"undefined"==typeof backendBulkSendingHandlerData||"undefined"==typeof KSEF_Common)return void console.error("backendBulkSendingHandlerData or KSEF_Common is not defined. Bulk sending script will not run.");const n=backendBulkSendingHandlerData.ajaxUrl,a=backendBulkSendingHandlerData.ajaxNonce;function t(e){e.empty()}function s(e,n){e.append(n)}function o(e,n){e.css("background-color",n)}async function i(e,i){const c=i.find(".column-ksef_id");t(c),s(c,"Wysyłanie...");const d=await KSEF_Common.sendInitialKsefRequest(n,"fiksef_send_document_to_ksef",e,a);if(t(c),"already_archived"===d.status)return s(c,d.message),void o(i,"transparent");"error"!==d.status?("success"===d.status||"awaiting"===d.status)&&d.documentReferenceNumber&&d.sessionReferenceNumber?(s(c,d.message),i.addClass("row-pending"),"max_attempts"===(await KSEF_Common.pollKsefDocumentStatus(n,"fiksef_check_document_status",{document:d.documentReferenceNumber,session:d.sessionReferenceNumber},e,backendBulkSendingHandlerData.pollNonce,{onAttempt:function(e){t(c),s(c,e.message),"awaiting"!==e.status&&i.removeClass("row-pending")}})).status&&s(c,"<br/>Nie udało się potwierdzić statusu w KSeF.")):(s(c,d.message||"Nieoczekiwana odpowiedź serwera."),o(i,"#ffe0e0")):s(c,d.message)}e("#doaction, #doaction2").on("click",function(n){if(("doaction"===e(this).attr("id")?e('select[name="action"]').val():e('select[name="action2"]').val())!==backendBulkSendingHandlerData.bulkAction)return;n.preventDefault();const a=e('input[name="post[]"]:checked').map(function(){return e(this).val()}).get();a.length?async function(n){for(const a of n){const n=e("#post-"+a);n.length&&await i(a,n)}}(a):alert("Proszę zaznaczyć przynajmniej jedną fakturę.")})});