(()=>{function e(e,t){const a=e,o=t;function i(){const e=o.querySelector('[data-botsauto-role="attachments"][data-botsauto-section="attachments"]')||o.getElementById("botsauto-attachments-overview");if(!e)return;const t=new URLSearchParams(a.location.search);if("1"===t.get("botsauto_ms_connected")?h('Microsoft 365 is gekoppeld. Klik op "Bewerken" om te starten.'):t.get("botsauto_ms_error")&&g("Microsoft koppelen is mislukt. Gebruik voorlopig Downloaden + handmatige upload."),a.botsauto_debug&&(e.dataset.postId,e.dataset.sessionId),"none"===e.style.display){const t=e.querySelectorAll(".botsauto-overview-item").length>0,o=(e.dataset.sessionId,a.location.search.includes("botsauto_edit"));(o||t)&&(e.style.removeProperty("display"),a.botsauto_debug)}!function(){const e=o.createElement("i");e.className="fa-solid fa-check",e.style.display="none",e.style.visibility="hidden",o.body.appendChild(e);a.getComputedStyle(e,"::before").content;o.body.removeChild(e)}(),void 0===a.botsauto_debug&&(a.botsauto_debug=a.botsauto_debug||!1);const i=e.dataset.postId,n=e.dataset.sessionId;var s;(s=e).addEventListener("click",function(e){a.botsauto_debug&&(e.target,e.target.className,e.target.tagName);const t=e.target.closest(".botsauto-overview-item-toggle");if(t){a.botsauto_debug,e.preventDefault(),e.stopPropagation();const o=t.closest(".botsauto-overview-item");return void(o&&C(o))}const i=e.target.closest(".botsauto-overview-item-header");if(i){const t=i.querySelector(".botsauto-overview-item-toggle");if(e.target!==t&&!t.contains(e.target)){e.preventDefault(),e.stopPropagation();const t=i.closest(".botsauto-overview-item");t&&C(t)}return}const n=e.target.closest(".botsauto-ai-toggle-icon");if(n){if(e.preventDefault(),e.stopPropagation(),n.classList.contains("botsauto-ai-toggle-loading")||n.disabled)return;return void function(e){var t;const o=e.getAttribute("data-attachment-id"),i=e.getAttribute("data-post-id"),n="1"===e.getAttribute("data-included"),s=n?0:1;if(!o||!i)return void g("Ontbrekende vereiste parameters.");const r=n;e.setAttribute("data-included",s.toString()),e.disabled=!0,e.classList.add("botsauto-ai-toggle-loading"),1===s?(e.classList.remove("botsauto-ai-toggle-inactive"),e.setAttribute("aria-label","Exclude from AI Kansenscan"),e.setAttribute("title","Exclude from AI Kansenscan")):(e.classList.add("botsauto-ai-toggle-inactive"),e.setAttribute("aria-label","Include in AI Kansenscan"),e.setAttribute("title","Include in AI Kansenscan"));const l=a.botsautoAttachmentsAjax||{},d=l.ajax_url||(null==(t=a.botsauto)?void 0:t.ajax_url)||"/wp-admin/admin-ajax.php",c=l.ai_nonce||"";if(!c)return e.setAttribute("data-included",r?"1":"0"),e.disabled=!1,e.classList.remove("botsauto-ai-toggle-loading"),r?e.classList.remove("botsauto-ai-toggle-inactive"):e.classList.add("botsauto-ai-toggle-inactive"),void g("Beveiligingscontrole niet beschikbaar. Vernieuw de pagina.");a.botsauto_debug&&c.substring(0,10);const u=new FormData;u.append("action","botsauto_toggle_ai_attachment"),u.append("post_id",i),u.append("attachment_id",o),u.append("new_state",s),u.append("nonce",c),fetch(d,{method:"POST",body:u,credentials:"same-origin"}).then(e=>e.json()).then(t=>{var i,n,s;if(e.classList.remove("botsauto-ai-toggle-loading"),e.disabled=!1,t.success)e.setAttribute("data-included",t.data.new_state.toString()),a.botsauto_debug&&t.data.new_state;else{e.setAttribute("data-included",r?"1":"0"),r?(e.classList.remove("botsauto-ai-toggle-inactive"),e.setAttribute("aria-label","Exclude from AI Kansenscan"),e.setAttribute("title","Exclude from AI Kansenscan")):(e.classList.add("botsauto-ai-toggle-inactive"),e.setAttribute("aria-label","Include in AI Kansenscan"),e.setAttribute("title","Include in AI Kansenscan")),e.classList.add("botsauto-ai-toggle-error");const l=(null==(i=t.data)?void 0:i.message)||"Unable to save, please retry";e.setAttribute("title",l),e.setAttribute("aria-label",l),g(l),setTimeout(()=>{e.classList.remove("botsauto-ai-toggle-error")},3e3),a.botsauto_debug&&console.error("BOTSAUTO Debug: AI attachment toggle failed",{attachmentId:o,error:t.data,errorCode:null==(n=t.data)?void 0:n.error,errorMessage:null==(s=t.data)?void 0:s.message,fullResponse:t})}}).catch(t=>{e.classList.remove("botsauto-ai-toggle-loading"),e.disabled=!1,e.setAttribute("data-included",r?"1":"0"),r?(e.classList.remove("botsauto-ai-toggle-inactive"),e.setAttribute("aria-label","Exclude from AI Kansenscan"),e.setAttribute("title","Exclude from AI Kansenscan")):(e.classList.add("botsauto-ai-toggle-inactive"),e.setAttribute("aria-label","Include in AI Kansenscan"),e.setAttribute("title","Include in AI Kansenscan")),e.classList.add("botsauto-ai-toggle-error");const a="Network error. Unable to save, please retry.";e.setAttribute("title",a),e.setAttribute("aria-label",a),g(a),setTimeout(()=>{e.classList.remove("botsauto-ai-toggle-error")},3e3),console.error("BOTSAUTO: Error toggling AI attachment state:",t)})}(n)}const r=e.target.closest(".botsauto-attachment-download, .botsauto-attachment-delete, .botsauto-attachment-edit, .botsauto-attachment-mark-done");if(r)if(e.preventDefault(),e.stopPropagation(),r.classList.contains("botsauto-attachment-download")){const e=r.getAttribute("data-url"),t=r.getAttribute("data-filename");a.botsauto_debug,function(e,t){if(e)try{const a=o.createElement("a");a.href=e;const i=String(t||"").trim(),n=/\.[A-Za-z0-9]{1,10}$/.test(i);i&&n&&(a.download=i),a.rel="noopener",o.body.appendChild(a),a.click(),o.body.removeChild(a),h(`"${t||"bestand"}" wordt gedownload`)}catch(e){console.error("Error downloading file:",e),g("Kon bestand niet downloaden")}else g("Download URL niet beschikbaar")}(e,t)}else if(r.classList.contains("botsauto-attachment-edit"))b({fileId:r.getAttribute("data-file-id"),itemHash:r.getAttribute("data-item-hash"),filename:r.getAttribute("data-filename")||"bestand",postId:r.getAttribute("data-post-id")||s.dataset.postId,triggerButton:r});else if(r.classList.contains("botsauto-attachment-mark-done"))!async function({fileId:e,itemHash:t,postId:o,triggerButton:i,container:n}){var s,r,l;if(!e||!o||"0"===o)return void g("Actie niet beschikbaar voor deze bijlage.");const d=(a.botsauto||{}).ajax_url||(null==(s=a.botsautoAttachmentsAjax)?void 0:s.ajax_url)||"/wp-admin/admin-ajax.php",c=(null==(r=a.botsauto_attachments_permissions)?void 0:r.mark_done_nonce)||"";if(c){i&&(i.disabled=!0);try{const a=new FormData;a.append("action","botsauto_mark_editing_done"),a.append("post_id",String(o)),a.append("attachment_id",String(e)),a.append("item_hash",String(t||"")),a.append("nonce",c);const i=await fetch(d,{method:"POST",body:a,credentials:"same-origin"}),s=await i.json();if(!(null==s?void 0:s.success))return void g((null==(l=null==s?void 0:s.data)?void 0:l.message)||"Status bijwerken mislukt.");h("Status bijgewerkt naar Gereed."),n&&S(n,n.dataset.sessionId)}catch(e){console.error("BOTSAUTO: Manual editing done failed",e),g("Status bijwerken mislukt.")}finally{i&&(i.disabled=!1)}}else g("Beveiligingscontrole niet beschikbaar. Vernieuw de pagina.")}({fileId:r.getAttribute("data-file-id"),itemHash:r.getAttribute("data-item-hash"),postId:r.getAttribute("data-post-id")||s.dataset.postId,triggerButton:r,container:s});else if(r.classList.contains("botsauto-attachment-delete")){const e=r.getAttribute("data-file-id"),t=r.getAttribute("data-file-url"),o=r.getAttribute("data-item-hash"),i=r.getAttribute("data-filename")||"bestand";a.botsauto_debug;const n={id:e,url:t,filename:i},l=s.dataset.postId,d=s.dataset.sessionId;v(s,n,o,l&&"0"!==l?l:d)}}),function(e){const t=e.querySelector(".botsauto-overview-title");if(!t)return;if(e.querySelector(".botsauto-overview-search"))return;const a=o.createElement("div");a.className="botsauto-overview-search";const i=o.createElement("input");i.type="text",i.className="botsauto-overview-search-input",i.placeholder="Zoek bijlagen...",i.setAttribute("aria-label","Zoek bijlagen op bestandsnaam, type of bijbehorend item");const n=o.createElement("select");n.className="botsauto-overview-filter-type",n.setAttribute("aria-label","Filter op bestandstype");[{value:"",text:"Alle bestandstypen"},{value:"pdf",text:"PDF"},{value:"image",text:"Afbeeldingen"},{value:"doc",text:"Documenten"},{value:"other",text:"Andere"}].forEach(e=>{const t=o.createElement("option");t.value=e.value,t.textContent=e.text,n.appendChild(t)});const s=o.createElement("select");s.className="botsauto-overview-filter-item",s.setAttribute("aria-label","Filter op checklist item");const d=o.createElement("option");d.value="",d.textContent="Alle items",s.appendChild(d);o.querySelectorAll(".botsauto-item[data-item-hash]").forEach(e=>{const t=e.dataset.itemHash,a=e.querySelector(".botsauto-item-text, .botsauto-item-label");if(t&&a){const e=o.createElement("option");e.value=t,e.textContent=a.textContent.trim(),s.appendChild(e)}});const c=o.createElement("button");c.type="button",c.className="botsauto-btn botsauto-overview-clear-filters",c.textContent="Filters wissen",c.setAttribute("aria-label","Alle filters wissen");const u=o.createElement("div");let m;u.className="botsauto-overview-result-count",u.setAttribute("aria-live","polite"),u.setAttribute("aria-atomic","true"),a.appendChild(i),a.appendChild(n),a.appendChild(s),a.appendChild(c),a.appendChild(u),t.parentNode.insertBefore(a,t.nextSibling),i.addEventListener("input",()=>{clearTimeout(m),m=setTimeout(()=>{r(e)},250)}),n.addEventListener("change",()=>r(e)),s.addEventListener("change",()=>r(e)),c.addEventListener("click",()=>function(e){e._searchInput.value="",e._fileTypeSelect.value="",e._itemSelect.value="";const t=e.querySelectorAll(".botsauto-overview-item");t.forEach(e=>{e.style.display="block";e.querySelectorAll(".botsauto-overview-attachments li").forEach(e=>{e.style.display="flex"})});const a=e.querySelectorAll(".botsauto-overview-attachments li").length;l(e,a,a)}(e)),e._searchInput=i,e._fileTypeSelect=n,e._itemSelect=s,e._resultCount=u}(e),function(e){const t=e.querySelector(".botsauto-overview-content");if(!t)return;(function(e){const t=e.querySelector(".botsauto-overview-title");if(!t)return;if(e.querySelector(".botsauto-overview-controls"))return;const i=a.BAttachmentsLabels||{expand_all:"Alles uitklappen",collapse_all:"Alles inklappen"},n=o.createElement("div");n.className="botsauto-overview-controls";const s=o.createElement("button");s.type="button",s.className="botsauto-overview-expand-all",s.textContent=i.expand_all,s.setAttribute("aria-label",i.expand_all);const r=o.createElement("button");r.type="button",r.className="botsauto-overview-collapse-all",r.textContent=i.collapse_all,r.setAttribute("aria-label",i.collapse_all),n.appendChild(s),n.appendChild(r),e.insertBefore(n,e.firstChild),s.addEventListener("click",()=>function(e){const t=e.querySelectorAll(".botsauto-overview-item");t.forEach(e=>{E(e,!0)})}(e)),r.addEventListener("click",()=>function(e){const t=e.querySelectorAll(".botsauto-overview-item");t.forEach(e=>{E(e,!1)})}(e))})(e),k(e),L(e)}(e),i&&"0"!==i&&(k(e),L(e),x(e,n),a.BOTS_TimeFormatter&&a.BOTS_TimeFormatter.initAutoRefresh(e))}"loading"===o.readyState?o.addEventListener("DOMContentLoaded",i):i();function n(e){const t=String((null==e?void 0:e.filename)||"").toLowerCase();if(!t.includes("."))return!1;const a=t.split(".").pop();return["docx","xlsx","pptx"].includes(a)}function s(e,t){if(!e||"global"===e||"ai_kansenscan"===e)return!1;const a=String((null==t?void 0:t.attachment_type)||(null==t?void 0:t.type)||(null==t?void 0:t.source)||(null==t?void 0:t.origin)||"").toLowerCase();return"ai"!==a&&"ai_generated"!==a&&!!o.getElementById("botsauto-item-"+e)}function r(e){const t=e._searchInput.value.toLowerCase().trim(),a=e._fileTypeSelect.value,o=e._itemSelect.value,i=e.querySelectorAll(".botsauto-overview-item");let n=0;i.forEach(e=>{const i=e.dataset.itemHash,s=e.querySelectorAll(".botsauto-overview-attachments li");let r=!1;s.forEach(e=>{const n=e.querySelector(".botsauto-overview-file-link"),s=n?n.querySelector(".botsauto-file-name, .botsauto-overview-filename"):null,l=s?(s.textContent||"").toLowerCase():"",c=n?n.href:"";let u=!0;if(t&&!l.includes(t)&&(u=!1),a&&u){const e=l.split(".").pop()||"",t=d(c);("pdf"!==a||e.includes("pdf"))&&("image"!==a||m(e,t))&&("doc"!==a||p(e,t))?"other"===a&&(e.includes("pdf")||m(e,t)||p(e,t))&&(u=!1):u=!1}o&&i!==o&&(u=!1),u?(e.style.display="flex",r=!0):e.style.display="none"}),r?e.style.display="block":e.style.display="none",n+=s.length});const s=e.querySelectorAll('.botsauto-overview-attachments li[style*="display: flex"], .botsauto-overview-attachments li:not([style*="display: none"])').length;l(e,s,n)}function l(e,t,a){e._resultCount.textContent=t===a?`${a} bijlage${1!==a?"n":""}`:`${t} van ${a} bijlage${1!==a?"n":""}`}function d(e){var t;if(!e)return"";return{jpg:"image/jpeg",jpeg:"image/jpeg",png:"image/png",gif:"image/gif",webp:"image/webp",bmp:"image/bmp",svg:"image/svg+xml",tif:"image/tiff",tiff:"image/tiff",heic:"image/heic",ico:"image/x-icon",pdf:"application/pdf",doc:"application/msword",docx:"application/vnd.openxmlformats-officedocument.wordprocessingml.document",rtf:"application/rtf",odt:"application/vnd.oasis.opendocument.text",pages:"application/vnd.apple.pages",xls:"application/vnd.ms-excel",xlsx:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",csv:"text/csv",ods:"application/vnd.oasis.opendocument.spreadsheet",numbers:"application/vnd.apple.numbers",ppt:"application/vnd.ms-powerpoint",pptx:"application/vnd.openxmlformats-officedocument.presentationml.presentation",odp:"application/vnd.oasis.opendocument.presentation",key:"application/vnd.apple.keynote",txt:"text/plain",log:"text/plain",md:"text/markdown",js:"application/javascript",ts:"application/typescript",json:"application/json",css:"text/css",scss:"text/scss",html:"text/html",xml:"application/xml",yml:"text/yaml",yaml:"text/yaml",php:"application/x-httpd-php",py:"text/x-python",rb:"text/x-ruby",java:"text/x-java-source",c:"text/x-c",cpp:"text/x-c++",cs:"text/x-csharp",go:"text/x-go",rs:"text/x-rust",swift:"text/x-swift",zip:"application/zip",rar:"application/x-rar-compressed","7z":"application/x-7z-compressed",gz:"application/gzip",tar:"application/x-tar",xz:"application/x-xz",mp3:"audio/mpeg",wav:"audio/wav",ogg:"audio/ogg",m4a:"audio/mp4",flac:"audio/flac",aac:"audio/aac",mp4:"video/mp4",mov:"video/quicktime",avi:"video/x-msvideo",mkv:"video/x-matroska",webm:"video/webm"}[(null==(t=e.split(".").pop())?void 0:t.toLowerCase())||""]||""}function c(e){const t=e&&"string"==typeof e.card_html&&e.card_html.trim()?e.card_html.trim():e&&"string"==typeof e.preview_html&&e.preview_html.trim().includes("botsauto-file-card")?e.preview_html.trim():"";if(t){const e=o.createElement("div");e.innerHTML=t;const a=e.querySelector(".botsauto-file-card");if(a)return a}const a=o.createElement("span");return a.className="botsauto-overview-filename",a.textContent=(null==e?void 0:e.filename)||"Naamloos bestand",a}function u(e){const t=String((null==e?void 0:e.m365_status)||"").toLowerCase();if(!t)return null;const a=o.createElement("span");if(a.className="botsauto-m365-status","editing"===t){a.classList.add("botsauto-m365-status-editing");const t=Number((null==e?void 0:e.botsauto_editing_started_at)||0),o=Number((null==e?void 0:e.botsauto_last_modified_ago_seconds)||0);if(t>0){const e=new Date(1e3*t),i=String(e.getHours()).padStart(2,"0"),n=String(e.getMinutes()).padStart(2,"0");if(a.textContent="In bewerking - Gestart om "+i+":"+n,o>0){const e=Math.max(1,Math.floor(o/60));a.textContent+=" - Laatst gewijzigd "+e+" min geleden"}}else a.textContent="In bewerking";return a}if("idle"===t)return a.classList.add("botsauto-m365-status-idle"),a.textContent="Gereed",a;if("synced"===t&&Number((null==e?void 0:e.m365_last_synced_at)||0)>0){a.classList.add("botsauto-m365-status-synced");const t=new Date(1e3*Number(e.m365_last_synced_at));return a.textContent="Laatst gesynchroniseerd: "+t.toLocaleString(),a}if("failed"===t){a.classList.add("botsauto-m365-status-failed");const t=String((null==e?void 0:e.m365_last_sync_error)||"").trim();return a.textContent=t?"Synchronisatie mislukt: "+t:"Synchronisatie mislukt",a}return null}function m(e,t){return["jpg","jpeg","png","gif","webp","svg","bmp"].includes(e)||["image/jpeg","image/png","image/gif","image/webp","image/svg+xml","image/bmp"].includes(t)}function p(e,t){return["doc","docx","xls","xlsx","ppt","pptx","txt","rtf"].includes(e)||["application/msword","application/vnd.openxmlformats-officedocument.wordprocessingml.document","application/vnd.ms-excel","application/vnd.openxmlformats-officedocument.spreadsheetml.sheet","application/vnd.ms-powerpoint","application/vnd.openxmlformats-officedocument.presentationml.presentation","text/plain","application/rtf"].includes(t)}async function b({fileId:e,itemHash:t,filename:o,postId:i,triggerButton:n}){var s,r,l,d,c,u;if(!e||!i||"0"===i)return void g("Bewerken is alleen beschikbaar voor opgeslagen bijlagen.");const m=(a.botsauto||{}).ajax_url||(null==(s=a.botsautoAttachmentsAjax)?void 0:s.ajax_url)||"/wp-admin/admin-ajax.php",p=(null==(r=a.botsauto_attachments_permissions)?void 0:r.edit_nonce)||"";if(p){n&&(n.disabled=!0);try{const o=new FormData;o.append("action","botsauto_attachment_edit_link"),o.append("post_id",String(i)),o.append("attachment_id",String(e)),o.append("item_hash",String(t||"")),o.append("return_url",a.location.href),o.append("edit_token",String(a.botsauto&&a.botsauto.edit_token||"")),o.append("nonce",p);const n=await fetch(m,{method:"POST",body:o,credentials:"same-origin"}),s=await n.json();if(!(null==s?void 0:s.success)){const e=(null==(l=null==s?void 0:s.data)?void 0:l.code)||"";return"m365_not_configured"===e||"m365_disabled"===e?void g("Microsoft 365 documentbewerking is niet geconfigureerd."):"m365_refresh_missing"===e||"m365_refresh_failed"===e||"m365_refresh_invalid"===e?void g("De verbinding met Microsoft 365 is verlopen. Neem contact op met de beheerder."):"unsupported_file_type"===e?void g("Dit bestandstype kan niet online worden bewerkt."):"m365_locked"===e?void g("Dit document is momenteel in bewerking door een andere gebruiker."):void g((null==(d=null==s?void 0:s.data)?void 0:d.message)||"Microsoft bewerken mislukt.")}const r=(null==(c=s.data)?void 0:c.open_url)||"";if(!r)return void g("Bewerklink ontbreekt. Gebruik Downloaden + handmatige upload.");let b=r;if(r.includes("/wp-json/botsauto/v1/m365/open"))try{const e=await fetch(r,{method:"GET",credentials:"same-origin",headers:{"X-BOTSAUTO-FETCH":"1"}}),t=await e.json(),a=String((null==t?void 0:t.redirect)||"");if(!e.ok||!(null==t?void 0:t.success)||!a)return void g("Bewerklink ontbreekt. Gebruik Downloaden + handmatige upload.");b=a}catch(e){return void g("Kon Microsoft 365 niet starten.")}a.open(b,"_blank","noopener"),h((null==(u=s.data)?void 0:u.message)||"Het document is geopend in Microsoft 365. SharePoint is de enige bron van waarheid.")}catch(e){console.error("BOTSAUTO: Microsoft edit start failed",e),g("Kon Microsoft 365 niet starten.")}finally{n&&(n.disabled=!1)}}else g("Beveiligingscontrole niet beschikbaar. Vernieuw de pagina.")}function v(e,t,o,i){const n=t.filename||"bestand";if(!confirm(`Weet je zeker dat je "${n}" wilt verwijderen? Deze actie kan niet ongedaan worden gemaakt.`))return;const s=e.dataset.postId;!s||"0"===s?function(e,t,o,i){try{const n=a.BA_sessionAttachments&&a.BA_sessionAttachments[i];if(!n||!n[o])return void g("Bestand niet gevonden in sessie");const s=n[o],r=s.findIndex(e=>e.url===t.url&&e.filename===t.filename);if(-1===r)return void g("Bestand niet gevonden");s.splice(r,1),0===s.length&&delete n[o],_(e,i),h(`"${t.filename}" succesvol verwijderd`)}catch(e){console.error("Error deleting session file:",e),g(f("unknown_error","Kon bestand niet verwijderen"))}}(e,t,o,i):function(e,t,o,i){var n;const s=a.botsauto||{},r=(null==(n=a.botsauto_attachments_permissions)?void 0:n.delete_nonce)||"",l=new FormData;l.append("action","botsauto_delete_attachment"),l.append("post_id",i),l.append("item_hash",o),l.append("file_id",t.id||""),l.append("file_url",t.url||""),l.append("nonce",r),fetch(s.ajax_url,{method:"POST",body:l,credentials:"same-origin"}).then(e=>e.json()).then(a=>{var o,i;if(a.success)S(e,e.dataset.sessionId),h(`"${t.filename}" succesvol verwijderd`);else{g(f((null==(o=a.data)?void 0:o.code)||"unknown_error",null==(i=a.data)?void 0:i.message))}}).catch(e=>{console.error("Error deleting file:",e),g(f("unknown_error","Kon bestand niet verwijderen"))})}(e,t,o,i)}function f(e,t){return{not_authorized:"Je hebt geen toestemming om deze bijlage te verwijderen.",nonce_invalid:"Beveiligingscontrole mislukt. Vernieuw de pagina en probeer opnieuw.",file_missing:"Bijlage niet gevonden.",context_mismatch:"Deze bijlage hoort niet bij deze checklist.",missing_parameters:"Ontbrekende vereiste parameters.",no_attachments:"Geen bijlagen gevonden.",unknown_error:"Er is iets misgegaan. Probeer het later opnieuw."}[e]||t||"Er is iets misgegaan. Probeer het later opnieuw."}function h(e){w(e,"success")}function g(e){w(e,"error")}function w(e,t){const a=o.createElement("div");a.className=`botsauto-overview-message botsauto-overview-message-${t}`,a.textContent=e,a.setAttribute("aria-live","polite");const i=o.querySelector('[data-botsauto-role="attachments"][data-botsauto-section="attachments"]')||o.getElementById("botsauto-attachments-overview");i&&(i.insertBefore(a,i.firstChild),setTimeout(()=>{a.parentNode&&a.parentNode.removeChild(a)},5e3))}function _(e,t){const i=e.querySelector(".botsauto-overview-content");if(!i)return;const r=a.BA_sessionAttachments&&a.BA_sessionAttachments[t];if(!r||0===Object.keys(r).length)return e.style.display="block",void(i.innerHTML='<div class="botsauto-overview-empty"><p>Geen bijlagen gevonden.</p></div>');e.style.display="block",i.innerHTML="";const d=A(),m=y();let p=!1;m.forEach(t=>{const l=r[t];if(!l||0===l.length)return;p=!0;const m=d[t]||"Onbekend item",b=o.createElement("div");b.className="botsauto-overview-item",b.dataset.itemHash=t;const v=o.createElement("div");v.className="botsauto-overview-item-header";const f=e.querySelector(`.botsauto-overview-item[data-item-hash="${t}"]`),h=null==f?void 0:f.querySelector(".botsauto-overview-item-head"),g=(null==h?void 0:h.getAttribute("data-oi-align"))||"center",w=(null==h?void 0:h.getAttribute("data-oi-gap"))||"M",_=o.createElement("div");_.className="botsauto-overview-item-head",_.setAttribute("data-oi-align",g),_.setAttribute("data-oi-gap",w);const A=o.createElement("h3");A.className="botsauto-overview-item-title";const y=o.createElement("a");y.className="botsauto-attachment-jump",y.href="#botsauto-item-"+t,y.textContent=m,A.appendChild(y);const x=o.createElement("button");x.type="button",x.className="botsauto-overview-item-toggle",x.setAttribute("aria-expanded","false"),x.setAttribute("aria-controls","attachments-"+Math.random().toString(36).substr(2,9));const S=o.createElement("i");S.className="fa-solid fa-chevron-right",S.setAttribute("aria-hidden","true"),x.appendChild(S),_.appendChild(A),_.appendChild(x),v.appendChild(_),b.appendChild(v);const k=o.createElement("ul");k.className="botsauto-overview-attachments",k.setAttribute("role","list"),k.style.display="none",l.forEach(i=>{var r;const l=o.createElement("li"),d=o.createElement("div");d.className="botsauto-overview-file-info";const m=o.createElement("a"),p=i.view_url||i.url||"#",b=i.download_url||i.url||"";if(m.href=p,m.target="_blank",m.rel="noopener",m.className="botsauto-overview-file-link botsauto-overview-file-card-link",m.appendChild(c(i)),d.appendChild(m),a.BOTS_TimeFormatter&&i.upload_time){const e=o.createElement("div");e.className="botsauto-overview-meta";const t=a.BOTS_TimeFormatter.createTimeElement(i.upload_time);e.appendChild(t),d.appendChild(e)}const v=u(i);if(v){const e=o.createElement("div");e.className="botsauto-overview-meta",e.appendChild(v),d.appendChild(e)}l.appendChild(d);const f=o.createElement("div");f.className="botsauto-overview-file-actions";const h=o.createElement("button");h.type="button",h.className="botsauto-attachment-download",h.setAttribute("aria-label","Downloaden: "+(i.filename||"bestand")),h.setAttribute("data-url",b),h.setAttribute("data-filename",i.filename||""),h.innerHTML='<i class="fa-solid fa-download" aria-hidden="true"></i> Downloaden',h.title="Downloaden: "+(i.filename||"bestand"),f.appendChild(h);const g=e.dataset.postId,w=(!0===i.can_edit||n(i))&&g&&"0"!==g&&i.id,_="editing"===String((null==i?void 0:i.botsauto_editing_status)||(null==i?void 0:i.m365_status)||"").toLowerCase();if(w){const e=o.createElement("button");e.type="button",e.className="botsauto-attachment-edit",e.setAttribute("aria-label","Bewerken: "+(i.filename||"bestand")),e.setAttribute("data-file-id",i.id||""),e.setAttribute("data-item-hash",t),e.setAttribute("data-post-id",g),e.setAttribute("data-filename",i.filename||""),e.innerHTML='<i class="fa-solid fa-pen-to-square" aria-hidden="true"></i> Bewerken',e.title="Bewerken: "+(i.filename||"bestand"),f.appendChild(e)}if(_&&g&&"0"!==g&&i.id){const e=o.createElement("button");e.type="button",e.className="botsauto-attachment-mark-done",e.setAttribute("aria-label","Markeer als gereed: "+(i.filename||"bestand")),e.setAttribute("data-file-id",i.id||""),e.setAttribute("data-item-hash",t),e.setAttribute("data-post-id",g),e.innerHTML='<i class="fa-solid fa-check" aria-hidden="true"></i> Markeer als gereed',e.title="Markeer als gereed: "+(i.filename||"bestand"),f.appendChild(e)}if(!1!==i.can_delete&&!1!==(null==(r=a.botsauto_attachments_permissions)?void 0:r.can_delete)){const e=o.createElement("button");e.type="button",e.className="botsauto-attachment-delete",e.setAttribute("aria-label","Verwijderen: "+(i.filename||"bestand")),e.setAttribute("data-file-id",i.id||""),e.setAttribute("data-file-url",b),e.setAttribute("data-item-hash",t),e.innerHTML='<i class="fa-solid fa-trash-can" aria-hidden="true"></i> Verwijderen',e.title="Verwijderen: "+(i.filename||"bestand"),f.appendChild(e)}if(s(t,i)){const e=o.createElement("a");e.className="botsauto-jump-to-item",e.href="#botsauto-item-"+t,e.title="Ga naar checklist item",e.setAttribute("aria-label","Ga naar checklist item"),e.innerHTML='<i class="fas fa-arrow-up-right-from-square" aria-hidden="true"></i>',f.appendChild(e)}l.appendChild(f),k.appendChild(l)}),b.appendChild(k),i.appendChild(b)}),p||(i.innerHTML='<div class="botsauto-overview-empty"><p>Geen bijlagen gevonden.</p></div>'),k(e);const b=j();N(e,b);const v=e.querySelectorAll(".botsauto-overview-attachments li").length;l(e,v,v)}function A(){const e={};return o.querySelectorAll(".botsauto-item[data-item-hash]").forEach(t=>{const a=t.dataset.itemHash,o=t.querySelector(".botsauto-item-text, .botsauto-item-label");a&&o&&(e[a]=o.textContent.trim())}),e}function y(){const e=[];return o.querySelectorAll(".botsauto-item[data-item-hash]").forEach(t=>{const a=t.dataset.itemHash;a&&e.push(a)}),e}function x(e,t){const a=new MutationObserver(function(o){clearTimeout(a.updateTimer),a.updateTimer=setTimeout(function(){S(e,t)},300)});o.querySelectorAll(".ba-attachments-list").forEach(e=>{a.observe(e,{childList:!0,subtree:!0})}),o.addEventListener("botsauto:attachment:added",function(){setTimeout(function(){S(e,t)},100)},{passive:!0}),o.addEventListener("botsauto:attachment:removed",function(){setTimeout(function(){S(e,t)},100)},{passive:!0})}function S(e,t){const i=e.dataset.postId,r=!i||"0"===i,d=a.pageYOffset,m=function(e){const t={},a=e.querySelectorAll(".botsauto-overview-item");return a.forEach(e=>{const a=e.dataset.itemHash;a&&(t[a]=e.classList.contains("botsauto-overview-item-collapsed"))}),t}(e);r&&t?_(e,t):i&&"0"!==i?function(e,t,i,r){const d=a.botsauto||{},m=wp_create_nonce?wp_create_nonce("botsauto_frontend_overview"):"",p=new FormData;p.append("action","botsauto_frontend_overview_data"),p.append("post_id",t),p.append("nonce",m),fetch(d.ajax_url,{method:"POST",body:p,credentials:"same-origin"}).then(e=>e.json()).then(t=>{var d;t.success?(!function(e,t){const i=e.querySelector(".botsauto-overview-content");if(!i)return;if(i.innerHTML="",!t||0===Object.keys(t).length)return void(i.innerHTML='<div class="botsauto-overview-empty"><p>Geen bijlagen gevonden.</p></div>');const r=A(),d=y();let m=!1;d.forEach(l=>{const d=t[l];if(!d||0===d.length)return;m=!0;const p=r[l]||"Onbekend item",b=o.createElement("div");b.className="botsauto-overview-item",b.dataset.itemHash=l;const v=o.createElement("div");v.className="botsauto-overview-item-header";const f=e.querySelector(`.botsauto-overview-item[data-item-hash="${l}"]`),h=null==f?void 0:f.querySelector(".botsauto-overview-item-head"),g=(null==h?void 0:h.getAttribute("data-oi-align"))||"center",w=(null==h?void 0:h.getAttribute("data-oi-gap"))||"M",_=o.createElement("div");_.className="botsauto-overview-item-head",_.setAttribute("data-oi-align",g),_.setAttribute("data-oi-gap",w);const A=o.createElement("h3");A.className="botsauto-overview-item-title";const y=o.createElement("a");y.className="botsauto-attachment-jump",y.href="#botsauto-item-"+l,y.textContent=p,A.appendChild(y);const x=o.createElement("button");x.type="button",x.className="botsauto-overview-item-toggle",x.setAttribute("aria-expanded","false"),x.setAttribute("aria-controls","attachments-"+Math.random().toString(36).substr(2,9));const S=o.createElement("i");S.className="fa-solid fa-chevron-right",S.setAttribute("aria-hidden","true"),x.appendChild(S),_.appendChild(A),_.appendChild(x),v.appendChild(_),b.appendChild(v);const k=o.createElement("ul");k.className="botsauto-overview-attachments",k.setAttribute("role","list"),k.style.display="none",d.forEach(t=>{var i;const r=o.createElement("li"),d=o.createElement("div");d.className="botsauto-overview-file-info";const m=e.dataset.postId,p=!1!==t.ai_kansenscan_enabled,b=!1!==t.ai_included,v=o.createElement("a"),f=t.view_url||t.url||"#",h=t.download_url||t.url||"";if(v.href=f,v.target="_blank",v.rel="noopener",v.className="botsauto-overview-file-link botsauto-overview-file-card-link",v.appendChild(c(t)),d.appendChild(v),p&&m&&"0"!==m){const e=o.createElement("button");e.type="button",e.className="botsauto-ai-toggle-icon",b||e.classList.add("botsauto-ai-toggle-inactive");const a=o.createElement("i");a.className="fa-solid fa-brain",a.setAttribute("aria-hidden","true"),e.appendChild(a),e.setAttribute("data-attachment-id",t.id||""),e.setAttribute("data-post-id",m),e.setAttribute("data-included",b?"1":"0"),e.setAttribute("tabindex","0"),e.setAttribute("role","button");const i=b?"Exclude from AI Kansenscan":"Include in AI Kansenscan";e.setAttribute("aria-label",i),e.setAttribute("title",i),d.appendChild(e)}if(a.BOTS_TimeFormatter&&t.upload_time){const e=o.createElement("div");e.className="botsauto-overview-meta";const i=a.BOTS_TimeFormatter.createTimeElement(t.upload_time);e.appendChild(i),d.appendChild(e)}const g=u(t);if(g){const e=o.createElement("div");e.className="botsauto-overview-meta",e.appendChild(g),d.appendChild(e)}r.appendChild(d);const w=o.createElement("div");w.className="botsauto-overview-file-actions";const _=o.createElement("button");_.type="button",_.className="botsauto-attachment-download",_.setAttribute("aria-label","Downloaden: "+(t.filename||"bestand")),_.setAttribute("data-url",h),_.setAttribute("data-filename",t.filename||""),_.innerHTML='<i class="fa-solid fa-download" aria-hidden="true"></i> Downloaden',_.title="Downloaden: "+(t.filename||"bestand"),w.appendChild(_);const A=(!0===t.can_edit||n(t))&&m&&"0"!==m&&t.id,y="editing"===String((null==t?void 0:t.botsauto_editing_status)||(null==t?void 0:t.m365_status)||"").toLowerCase();if(A){const e=o.createElement("button");e.type="button",e.className="botsauto-attachment-edit",e.setAttribute("aria-label","Bewerken: "+(t.filename||"bestand")),e.setAttribute("data-file-id",t.id||""),e.setAttribute("data-item-hash",l),e.setAttribute("data-post-id",m),e.setAttribute("data-filename",t.filename||""),e.innerHTML='<i class="fa-solid fa-pen-to-square" aria-hidden="true"></i> Bewerken',e.title="Bewerken: "+(t.filename||"bestand"),w.appendChild(e)}if(y&&m&&"0"!==m&&t.id){const e=o.createElement("button");e.type="button",e.className="botsauto-attachment-mark-done",e.setAttribute("aria-label","Markeer als gereed: "+(t.filename||"bestand")),e.setAttribute("data-file-id",t.id||""),e.setAttribute("data-item-hash",l),e.setAttribute("data-post-id",m),e.innerHTML='<i class="fa-solid fa-check" aria-hidden="true"></i> Markeer als gereed',e.title="Markeer als gereed: "+(t.filename||"bestand"),w.appendChild(e)}if(!1!==t.can_delete&&!1!==(null==(i=a.botsauto_attachments_permissions)?void 0:i.can_delete)){const e=o.createElement("button");e.type="button",e.className="botsauto-attachment-delete",e.setAttribute("aria-label","Verwijderen: "+(t.filename||"bestand")),e.setAttribute("data-file-id",t.id||""),e.setAttribute("data-file-url",h),e.setAttribute("data-item-hash",l),e.innerHTML='<i class="fa-solid fa-trash-can" aria-hidden="true"></i> Verwijderen',e.title="Verwijderen: "+(t.filename||"bestand"),w.appendChild(e)}if(s(l,t)){const e=o.createElement("a");e.className="botsauto-jump-to-item",e.href="#botsauto-item-"+l,e.title="Ga naar checklist item",e.setAttribute("aria-label","Ga naar checklist item"),e.innerHTML='<i class="fas fa-arrow-up-right-from-square" aria-hidden="true"></i>',w.appendChild(e)}r.appendChild(w),k.appendChild(r)}),b.appendChild(k),i.appendChild(b)}),m||(i.innerHTML='<div class="botsauto-overview-empty"><p>Geen bijlagen gevonden.</p></div>');k(e);const p=e.querySelectorAll(".botsauto-overview-attachments li").length;l(e,p,p)}(e,t.data),N(e,i),a.scrollTo(0,r)):null==(d=t.data)||d.message}).catch(e=>{})}(e,i,m,d):(k(e),L(e))}function k(e){e.querySelectorAll(".botsauto-overview-item").forEach(e=>{let t=e.querySelector(".botsauto-overview-item-toggle");const a=e.querySelector(".botsauto-overview-attachments");if(!t&&a){const i=e.querySelector(".botsauto-overview-item-header");if(i){let e=i.querySelector(".botsauto-overview-item-head");if(!e){e=o.createElement("div"),e.className="botsauto-overview-item-head",e.setAttribute("data-oi-align","center"),e.setAttribute("data-oi-gap","M");const t=i.querySelector(".botsauto-overview-item-title");t&&(i.removeChild(t),e.appendChild(t)),i.appendChild(e)}t=o.createElement("button"),t.type="button",t.className="botsauto-overview-item-toggle",t.setAttribute("aria-expanded","false");const n="attachments-"+Math.random().toString(36).slice(2,11);t.setAttribute("aria-controls",n);const s=o.createElement("i");s.className="fa-solid fa-chevron-right",s.setAttribute("aria-hidden","true"),t.appendChild(s),e.appendChild(t),a.id=n}}if(!t||!a)return;if("true"===e.dataset.collapsibleInitialized)return;const i=t.getAttribute("aria-controls");i&&(a.id=i),a.classList.contains("botsauto-overview-attachments-collapsible")||(a.className+=" botsauto-overview-attachments-collapsible");const n=e.querySelector(".botsauto-overview-item-header");n&&(n.style.cursor="pointer"),e.dataset.collapsibleInitialized="true"})}function E(e,t){const o=e.querySelector(".botsauto-overview-item-toggle"),i=e.querySelector(".botsauto-overview-attachments");if(!o||!i)return;const n=o.querySelector("i");n&&(a.botsauto_debug&&e.dataset.itemHash,o.setAttribute("aria-expanded",t.toString()),t?(i.style.display="flex",n.className="fa-solid fa-chevron-down",e.classList.remove("botsauto-overview-item-collapsed")):(i.style.display="none",n.className="fa-solid fa-chevron-right",e.classList.add("botsauto-overview-item-collapsed")),function(e){const t=e.dataset.itemHash;if(!t)return;const a=e.classList.contains("botsauto-overview-item-collapsed"),o=j();o[t]=a;try{sessionStorage.setItem("botsauto_overview_collapsible_state",JSON.stringify(o))}catch(e){}}(e))}function C(e){const t=e.querySelector(".botsauto-overview-item-toggle"),a=e.querySelector(".botsauto-overview-attachments");if(!t||!a)return;E(e,!("true"===t.getAttribute("aria-expanded")))}function L(e){e.querySelectorAll(".botsauto-overview-item").forEach(e=>{const t=e.querySelector(".botsauto-overview-item-toggle"),a=e.querySelector(".botsauto-overview-attachments"),o=null==t?void 0:t.querySelector("i");t&&a&&(t.setAttribute("aria-expanded","false"),a.style.display="none",o&&(o.className="fa-solid fa-chevron-right"),e.classList.add("botsauto-overview-item-collapsed"))})}function j(){try{const e=sessionStorage.getItem("botsauto_overview_collapsible_state");return e?JSON.parse(e):{}}catch(e){return{}}}function N(e,t){e.querySelectorAll(".botsauto-overview-item").forEach(e=>{const a=e.dataset.itemHash;if(!a||void 0===t[a])return;const o=t[a],i=e.querySelector(".botsauto-overview-item-toggle"),n=e.querySelector(".botsauto-overview-attachments"),s=null==i?void 0:i.querySelector("i");i&&n&&(i.setAttribute("aria-expanded",(!o).toString()),o?(n.style.display="none",s&&(s.className="fa-solid fa-chevron-right"),e.classList.add("botsauto-overview-item-collapsed")):(n.style.display="flex",s&&(s.className="fa-solid fa-chevron-down"),e.classList.remove("botsauto-overview-item-collapsed")))})}a.toggleSection=C,a.makeItemsCollapsible=k,a.BOTSAUTOAttachmentEditor={startMicrosoftEdit:b}}var t,a;t=window,a=document,function(t,a){e(t,a)}(t,a)})();