(()=>{function t(t){const e=parseInt(t,10);return Number.isNaN(e)?0:e}function e(e){if(!e||"function"!=typeof e.getAttribute)return{submissionId:0,editToken:""};const o=t(e.getAttribute("data-botsauto-submission-id"));return{submissionId:o>0?o:0,editToken:(e.getAttribute("data-botsauto-edit-token")||"").trim()}}function o(t){return t&&t.document?t.document:"undefined"!=typeof document?document:null}function a(t,e){if(!t||"function"!=typeof t.querySelector)return"";const o=t.querySelector('input[name="'+e+'"]');return o&&void 0!==o.value&&null!==o.value?String(o.value):""}function n(t,e){return t&&"function"==typeof t.querySelector?t.querySelector(e):null}function i(t,e){if(!t||void 0===t.fn)return"";try{const o=t(e).first().val();return null==o?"":String(o)}catch(t){return""}}function r(t,e){if(!t||void 0===t.fn)return null;try{return t(e).get(0)||null}catch(t){return null}}function s(s,u){const d=function(s,u){const d=u||window,c=o(d);let l=a(c,"botsauto_submission_id"),p=a(c,"botsauto_edit_token")||a(c,"botsauto_edit"),b=n(c,".botsauto-checklist-root[data-botsauto-submission-id], .botsauto-checklist-root[data-botsauto-edit-token]"),m=n(c,".botsauto-about-jan-frontend[data-botsauto-submission-id], .botsauto-about-jan-frontend[data-botsauto-edit-token]");l||(l=i(s,'input[name="botsauto_submission_id"]')),p||(p=i(s,'input[name="botsauto_edit_token"]')||i(s,'input[name="botsauto_edit"]')),b||(b=r(s,".botsauto-checklist-root[data-botsauto-submission-id], .botsauto-checklist-root[data-botsauto-edit-token]")),m||(m=r(s,".botsauto-about-jan-frontend[data-botsauto-submission-id], .botsauto-about-jan-frontend[data-botsauto-edit-token]"));const f=e(b),g=e(m);let h=t(l);h<=0&&(h=f.submissionId||g.submissionId||0),h<=0&&d.botsauto&&d.botsauto.botsauto_submission_id&&(h=t(d.botsauto.botsauto_submission_id)),h<=0&&d.botsauto&&d.botsauto.submission_id&&(h=t(d.botsauto.submission_id));let v=String(p||"").trim();return v||(v=f.editToken||g.editToken||""),!v&&d.botsauto&&d.botsauto.botsauto_edit_token&&(v=String(d.botsauto.botsauto_edit_token).trim()),!v&&d.botsauto&&d.botsauto.edit_token&&(v=String(d.botsauto.edit_token).trim()),{submissionId:h>0?h:0,editToken:v}}(s,u),c={};return d.submissionId>0&&(c.botsauto_submission_id=d.submissionId),d.editToken&&(c.botsauto_edit_token=d.editToken),c}function u(t){if(!t)return!1;const e=String(t).toLowerCase();return-1!==e.indexOf("/wp-json/mwai/")||-1!==e.indexOf("/wp-json/mwai-ui/")||-1!==e.indexOf("/mwai/")||-1!==e.indexOf("/mwai-ui/")||-1!==e.indexOf("/wp-json/mwai")||-1!==e.indexOf("rest_route=/mwai")||-1!==e.indexOf("rest_route=/mwai-ui")}function d(t,e,o){const a=s(e,o),n=!!a.botsauto_submission_id,i=!!a.botsauto_edit_token;if(!n&&!i)return t;let r=t;r&&"object"==typeof r||(r={});let u=r.context;return u&&"object"==typeof u||(u={}),n&&!u.botsauto_submission_id&&(u.botsauto_submission_id=a.botsauto_submission_id),i&&!u.botsauto_edit_token&&(u.botsauto_edit_token=a.botsauto_edit_token),r.context=u,n&&!r.botsauto_submission_id&&(r.botsauto_submission_id=a.botsauto_submission_id),i&&!r.botsauto_edit_token&&(r.botsauto_edit_token=a.botsauto_edit_token),r}function c(t){const e=t||{},a=e.$,n=e.globalScope||window,i="function"==typeof e.warn?e.warn:function(){},r="function"==typeof e.log?e.log:function(){};!function(t){const e=t||{},a=e.globalScope||window,n=e.$||a.jQuery,i="function"==typeof e.warn?e.warn:function(){},r=o(a);if(!n||"function"!=typeof n.ajaxSend||!r)return!1;if(a.__botsautoMwaiJqueryInterceptorBound)return!0;a.__botsautoMwaiJqueryInterceptorBound=!0,a.__botsautoMwaiContextInterceptorBound=!0,n(r).ajaxSend(function(t,e,o){if(!o||!u(o.url))return;const r=o.data;if(!r){const t=d({},n,a);return o.data=JSON.stringify(t),void e.setRequestHeader("Content-Type","application/json; charset=UTF-8")}if("string"==typeof r){const t=r.trim();if(!t||"{"!==t.charAt(0))return;try{const i=d(JSON.parse(t),n,a);o.data=JSON.stringify(i),e.setRequestHeader("Content-Type","application/json; charset=UTF-8")}catch(t){i("BOTSAUTO: unable to parse MWAI request payload",t)}return}"object"==typeof r&&(o.data=d(r,n,a))})}({globalScope:n,$:a,warn:i,log:r}),function(t){const e=t||{},o=e.globalScope||window,a=e.$||o.jQuery||null,n="function"==typeof e.warn?e.warn:function(){},i="function"==typeof e.log?e.log:function(){},r=o.Request||("undefined"!=typeof Request?Request:null),c=o.Headers||("undefined"!=typeof Headers?Headers:null),l=o.URL||("undefined"!=typeof URL?URL:null);if("function"!=typeof o.fetch||o.__botsautoMwaiFetchInterceptorBound)return!1;o.__botsautoMwaiFetchInterceptorBound=!0;const p=o.fetch.bind(o);function b(){return o.jQuery||a||null}function m(t){return!!r&&t instanceof r}function f(t){if(!t||"[object Object]"!==Object.prototype.toString.call(t))return!1;const e=Object.getPrototypeOf(t);return e===Object.prototype||null===e}function g(t){if(!c)return t;let e;try{e=new c(t||{})}catch(t){e=new c}return e.has("Content-Type")||e.set("Content-Type","application/json; charset=UTF-8"),e}function h(t){if("string"==typeof t){const e=t.trim();if(!e)return{enriched:!1,body:t};try{const a=JSON.parse(e);if(!a||"object"!=typeof a||Array.isArray(a))return{enriched:!1,body:t};const n=d(a,b(),o);return n.botsauto_fetch_payload_injected=1,{enriched:!0,body:JSON.stringify(n)}}catch(e){return{enriched:!1,body:t}}}if(f(t)){const e=d(t,b(),o);return e.botsauto_fetch_payload_injected=1,{enriched:!0,body:JSON.stringify(e)}}return{enriched:!1,body:t}}async function v(t,e){const o={input:t,init:e,enriched:!1};let a=e&&"object"==typeof e?Object.assign({},e):e;if(a&&Object.prototype.hasOwnProperty.call(a,"body")&&void 0!==a.body&&null!==a.body){const e=h(a.body);return e.enriched?(a&&"object"==typeof a||(a={}),a.body=e.body,a.headers=g(a.headers),{input:t,init:a,enriched:!0}):o}if(!m(t))return o;let n="";try{n=await t.clone().text()}catch(t){return o}if(!n)return o;const i=h(n);if(!i.enriched)return o;const s={body:i.body,headers:g(t.headers)},u=r?new r(t,s):t;return a&&"object"==typeof a&&(a.headers=g(a.headers||t.headers)),{input:u,init:a,enriched:!0}}o.fetch=async function(t,a){let r="";if("string"==typeof t?r=t:l&&t instanceof l?r=t.toString():m(t)&&t.url&&(r=t.url),!u(r))return p(t,a);if(!function(t,e){const o=s(t,e);return!(!o.botsauto_submission_id&&!o.botsauto_edit_token)}(o.jQuery||e.$||null,o))return p(t,a);try{const e=await v(t,a);if(e.enriched)return i("[BOTSAUTO AI CONTEXT] fetch_payload_injected=1"),p(e.input,e.init)}catch(t){n("BOTSAUTO: unable to enrich MWAI fetch request",t)}return p(t,a)}}({globalScope:n,$:a,warn:i,log:r})}function l(t){const e=t||{},o=e.window,a=e.document,n=e.$,i=e.eventHandlerCounts||{click:0},r=e.state||{};if(o&&a&&n){if(d(),o.addEventListener("resize",d),o.addEventListener("orientationchange",d),l(),o.botsautoEnsureTooltipInitialization=p,!o.__botsautoTooltipInitObserverBound){o.__botsautoTooltipInitObserverBound=!0;var s=".botsauto-checklist, .botsauto-wrapper, .botsauto-container",u=a.body||a.documentElement;u&&"function"==typeof MutationObserver&&(r.tooltipInitObserver=new MutationObserver(function(t){for(var e=!1,o=0;o<t.length;o++)if("childList"===t[o].type&&t[o].addedNodes.length){for(var a=0;a<t[o].addedNodes.length;a++){var n=t[o].addedNodes[a];if(n&&1===n.nodeType&&("function"==typeof n.matches&&n.matches(s)||n.querySelector&&n.querySelector(s))){e=!0;break}}if(e)break}e&&setTimeout(p,100)}),r.tooltipInitObserver.observe(u,{childList:!0,subtree:!0}))}n(o).on("load",function(){setTimeout(p,200)})}function d(){const t=.01*o.innerHeight;a.documentElement.style.setProperty("--botsauto-vh",`${t}px`)}function c(){n(".botsauto-itp[data-open]").removeAttr("data-open"),n('.botsauto-item-info[aria-expanded="true"]').attr("aria-expanded","false"),a.documentElement.style.overflow="",n(".botsauto-itp__dialog").removeAttr("role aria-modal aria-labelledby"),n(".botsauto-itp").off("keydown.focustrap")}function l(){function t(){var t=.01*o.innerHeight;a.documentElement.style.setProperty("--itp-vh",t+"px"),a.documentElement.style.setProperty("--botsauto-vh",t+"px")}r.setViewportHeight=t,t(),n(o).off("resize.botsauto",t).on("resize.botsauto",t),n(o).off("orientationchange.botsauto",t).on("orientationchange.botsauto",t),n(a).off("click.botsauto",".botsauto-item-info").on("click.botsauto",".botsauto-item-info",function(t){t.preventDefault(),t.stopPropagation();var e=n(this),o=e.attr("id");if(o){c();var i=n('.botsauto-itp[data-button-id="'+o+'"]');if(0!==i.length){i.parent().is("body")||i.detach().appendTo("body"),i.attr("data-open","true"),e.attr("aria-expanded","true"),a.documentElement.style.overflow="hidden";var r=i.find(".botsauto-itp__dialog");r.attr("role","dialog"),r.attr("aria-modal","true"),r.attr("aria-labelledby","botsauto-itp__title");var s=i.find(".botsauto-itp__close");s.length&&s.focus(),function(t){var e=t.find('button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])'),o=e.first(),n=e.last();t.off("keydown.focustrap"),t.on("keydown.focustrap",function(t){"Tab"===t.key&&(t.shiftKey?o.length&&a.activeElement===o[0]&&(t.preventDefault(),n.focus()):n.length&&a.activeElement===n[0]&&(t.preventDefault(),o.focus()))})}(i)}}}),n(a).off("click.botsauto",".botsauto-itp__close").on("click.botsauto",".botsauto-itp__close",function(t){t.preventDefault(),t.stopPropagation(),c()}),i.click++,n(a).off("click.botsauto",".botsauto-itp__overlay").on("click.botsauto",".botsauto-itp__overlay",function(){c()}),i.click++,n(a).off("keydown.botsauto").on("keydown.botsauto",function(t){"Escape"===t.key&&n(".botsauto-itp[data-open]").length&&c()}),n(a).off("click.botsauto",".botsauto-itp__body a").on("click.botsauto",".botsauto-itp__body a",function(t){t.stopPropagation()}),i.click++}function p(){l(),"function"==typeof r.setViewportHeight&&r.setViewportHeight()}}function p(t){const e=t.$,o=t.debug.log,a=t.debug.warn;var n,i=!!window.BOTSAUTO_PREVIEW_DATA,r=Date.now(),s={click:0,change:0,input:0,ajaxComplete:0},u=!1;function d(t){var o;if(t&&t.jquery)o=t.filter(".botsauto-intro-progress-wrap").add(t.find(".botsauto-intro-progress-wrap"));else if(t&&1===t.nodeType){var a=e(t);o=a.is(".botsauto-intro-progress-wrap")?a:a.find(".botsauto-intro-progress-wrap")}else if(t&&"number"==typeof t.length&&t.length>0&&t[0]&&1===t[0].nodeType){var n=e(t);o=n.filter(".botsauto-intro-progress-wrap").add(n.find(".botsauto-intro-progress-wrap"))}else o=e(".botsauto-intro-progress-wrap");o&&o.length&&o.each(function(){var t=e(this),o=t.children(".botsauto-intro").first(),a=t.children(".botsauto-progress-wrapper.ba-progress").first(),n=a;if(!a.length){var i=t.children("[data-tooltip]").first();i.length&&(a=i.find(".botsauto-progress-wrapper.ba-progress").first()).length&&(n=i)}if(!a.length&&(a=t.find(".botsauto-progress-wrapper.ba-progress").first()).length){var r=a.closest("[data-tooltip]");n=r.length&&r.parent().is(t)?r:a}if(a.length){n&&n.length||(n=a),o.length?n.prev()[0]!==o[0]&&n.insertAfter(o):t.children().first()[0]!==n[0]&&t.prepend(n);var s=t.children(".botsauto-progress-info").first();s.length&&s.prev()[0]!==n[0]&&s.insertAfter(n);var u=t.children(".botsauto-actions").first();u.length&&(s.length?u.prev()[0]!==s[0]&&u.insertAfter(s):u.prev()[0]!==n[0]&&u.insertAfter(n))}})}function c(t){return"string"!=typeof t?"":t.trim()}function p(t,e){if(!t||"function"!=typeof t.attachShadow)return!1;try{var o=function(t){var e=c(t.hostStyles),o=c(t.innerStyles),a=[],n=":host{display:block!important;box-sizing:border-box!important;";e&&";"!==(n+=e).charAt(n.length-1)&&(n+=";"),n+="}",a.push(n),a.push(":host *, :host *::before, :host *::after{box-sizing:border-box!important;}");var i=".intro-root{display:block;box-sizing:border-box;";return o&&";"!==(i+=o).charAt(i.length-1)&&(i+=";"),i+="}",a.push(i),a.push(".intro-root > :first-child{margin-top:0;}"),a.push(".intro-root > :last-child{margin-bottom:0;}"),a.push(".intro-root a{color:inherit;text-decoration:underline;}"),"<style>"+a.join("\n")+'</style><div class="intro-root">'+("string"==typeof t.html?t.html:"")+"</div>"}(e),n=t.shadowRoot;return n||(n=t.attachShadow({mode:"open"})),n.innerHTML=o,t.hasAttribute("style")&&t.removeAttribute("style"),t.__botsautoIntroMode="shadow",t.setAttribute("data-intro-mode","shadow"),!0}catch(t){return a("BOTSAUTO intro shadow render failed",t),!1}}function b(t,e){if(t){!function(t,e){if(t){var o="display:block!important;box-sizing:border-box!important;",a=c(e);a&&";"!==(o+=a).charAt(o.length-1)&&(o+=";"),t.setAttribute("style",o)}}(t,e.hostStyles);var o=t.querySelector("iframe.botsauto-intro-iframe");o||((o=document.createElement("iframe")).className="botsauto-intro-iframe",o.setAttribute("frameborder","0"),o.setAttribute("scrolling","no"),o.setAttribute("aria-hidden","false"),o.setAttribute("tabindex","-1"),o.style.width="100%",o.style.border="0",o.style.display="block",o.style.overflow="hidden",t.innerHTML="",t.appendChild(o));var a=o.contentDocument||o.contentWindow&&o.contentWindow.document;if(a){var n=["html,body{margin:0;padding:0;}","body{box-sizing:border-box!important;"+c(e.innerStyles)+"}","body *, body *::before, body *::after{box-sizing:border-box!important;}","body > :first-child{margin-top:0;}","body > :last-child{margin-bottom:0;}","a{color:inherit;text-decoration:underline;}"].join(""),i="string"==typeof e.html?e.html:"";a.open(),a.write('<!DOCTYPE html><html><head><meta charset="utf-8"/><style>'+n+"</style></head><body>"+i+"</body></html>"),a.close();var r=function(){if(o&&o.parentNode){var t=a.documentElement?a.documentElement.scrollHeight:0;a.body&&(t=Math.max(t,a.body.scrollHeight)),t>0&&(o.style.height=t+"px")}};r(),setTimeout(r,30),setTimeout(r,120),o.__botsautoResizeListener&&o.removeEventListener("load",o.__botsautoResizeListener),o.__botsautoResizeListener=r,o.addEventListener("load",r),t.__botsautoIntroMode="iframe",t.setAttribute("data-intro-mode","iframe")}}}function m(t){var o;if(t&&t.jquery)o=t.filter(".botsauto-intro-shadow-host").add(t.find(".botsauto-intro-shadow-host"));else if(t&&1===t.nodeType){var n=e(t);o=n.is(".botsauto-intro-shadow-host")?n:n.find(".botsauto-intro-shadow-host")}else if(t&&"number"==typeof t.length&&t.length>0&&t[0]&&1===t[0].nodeType){var i=e(t);o=i.filter(".botsauto-intro-shadow-host").add(i.find(".botsauto-intro-shadow-host"))}else o=e(".botsauto-intro-shadow-host");o&&o.length&&o.each(function(){var t=this,e=function(t){if(!t)return null;var e=t.getAttribute("data-intro-config");if(!e)return null;try{return JSON.parse(e)}catch(t){return a("BOTSAUTO intro config parse failed",t),null}}(t);if(e&&e.html){var o=e.signature||t.getAttribute("data-intro-config");if(t.__botsautoIntroSignature===o){var n=t.__botsautoIntroMode;if("shadow"===n&&t.shadowRoot&&t.shadowRoot.childNodes.length)return;if("iframe"===n&&t.querySelector("iframe.botsauto-intro-iframe"))return}var i=!1;"function"==typeof t.attachShadow&&(i=p(t,e)),i||b(t,e),t.__botsautoIntroSignature=o}})}function f(t){d(t),m(t)}window.withObserverPaused=function(t){window.__botsautoObserver__&&(window.__botsautoObserver__.disconnect(),u=!1);try{t()}finally{window.__botsautoObserver__&&window.__botsautoObserverTarget__&&(window.__botsautoObserver__.observe(window.__botsautoObserverTarget__,{childList:!0,subtree:!0}),u=!0)}},window.botsautoEnsureIntroProgressOrder=f,window.botsautoIsolateIntroText=m,f(),["botsauto:checklist:refreshed","botsauto:checklist:rendered","botsauto:import:modeChanged","botsauto:progress:updated"].forEach(function(t){document.addEventListener(t,function(t){f(t&&t.detail&&t.detail.scope?t.detail.scope:void 0)})});var g=function(){var t="botsauto-expanded-state::",e=Boolean(window&&window.BOTSAUTO_DEBUG_PHASES),o=function(){try{var e=t+"probe";return window.localStorage.setItem(e,"1"),window.localStorage.removeItem(e),!0}catch(t){return!1}}(),a=new WeakMap,n=new WeakSet;function i(t,o){e&&window.console&&console.debug}function r(t){var e=parseInt(t,10);return isNaN(e)?0:e}function s(){return window.location&&"string"==typeof window.location.pathname?function(t){if(null==t)return"";var e=String(t).trim().toLowerCase();return e.length>1&&"/"===e.charAt(e.length-1)&&(e=e.slice(0,-1)),e}(window.location.pathname):""}function u(e){var o={postId:0,instanceId:"",path:"",postKey:null,instanceKey:null,pathKey:null,primaryKey:null,fallbacks:[],migrated:!1};return o.postId=function(t){if(!t)return 0;var e=t.querySelector('input[name="post_id"]');if(e){var o=r(e.value);if(o>0)return o}var a=t.closest("[data-checklist-id]");if(a){var n=r(a.getAttribute("data-checklist-id"));if(n>0)return n}return 0}(e),o.instanceId=function(t){if(!t)return"";var e=t.getAttribute("data-botsauto-instance");if(e&&e.trim())return e.trim();var o=t.closest("[data-botsauto-instance]");if(o){var a=o.getAttribute("data-botsauto-instance");if(a&&a.trim())return a.trim()}return window.botsauto&&window.botsauto.instance_id?String(window.botsauto.instance_id):""}(e),o.path=s(),o.postId>0&&(o.postKey=t+"post-"+o.postId),o.instanceId&&(o.instanceKey=t+"instance-"+o.instanceId),o.path&&(o.pathKey=t+"path-"+o.path),o.postKey?(o.primaryKey=o.postKey,o.instanceKey&&o.instanceKey!==o.postKey&&o.fallbacks.push(o.instanceKey),o.pathKey&&o.pathKey!==o.postKey&&o.pathKey!==o.instanceKey&&o.fallbacks.push(o.pathKey)):o.instanceKey?(o.primaryKey=o.instanceKey,o.pathKey&&o.pathKey!==o.instanceKey&&o.fallbacks.push(o.pathKey)):o.pathKey&&(o.primaryKey=o.pathKey),i(0,(o.postId,o.instanceId,o.path,o.primaryKey,o.fallbacks.slice())),o}function d(t){if(!Array.isArray(t))return[];for(var e=Object.create(null),o=[],a=0;a<t.length;a++){var n=t[a];if("string"==typeof n){var i=n.trim();i&&(Object.prototype.hasOwnProperty.call(e,i)||(e[i]=!0,o.push(i)))}}return o}function c(t){if(!o||!t)return{list:[],raw:null,hasValue:!1};try{var e,a=window.localStorage.getItem(t);if(null==a)return{list:[],raw:null,hasValue:!1};try{e=JSON.parse(a)}catch(t){e=[]}return{list:d(Array.isArray(e)?e:[]),raw:a,hasValue:!0}}catch(t){return{list:[],raw:null,hasValue:!1}}}function l(t,e){if(o&&t){var a=d(e);try{window.localStorage.setItem(t,JSON.stringify(a))}catch(t){}}}function p(t){if(o&&t)try{window.localStorage.removeItem(t)}catch(t){}}function b(t,e){if(!e||!e.postKey||e.migrated)return null;e.migrated=!0;var o=c(e.postKey);if(o.hasValue)return i(0,(e.postKey,e.postKey)),o.list;for(var a=0;a<e.fallbacks.length;a++){var n=e.fallbacks[a],r=c(n);if(r.hasValue)return l(e.postKey,r.list),p(n),i(0,(e.postKey,r.list.slice())),r.list}return i(0,e.postKey),null}function m(t,e){if(!t)return"";var o=t.getAttribute("data-phase-key");if(o&&o.trim())return o.trim();var a="",n=t.querySelector(".botsauto-phase-title");n&&n.textContent&&(a=n.textContent.trim().toLowerCase().replace(/\s+/g,"-").replace(/[^a-z0-9\-]/g,"")),a||(a="phase");var i=e;return("number"!=typeof i||i<0)&&(i=0),a=a+"-"+(i+1),t.setAttribute("data-phase-key",a),a}function f(t){if(!t)return[];var e=t.querySelectorAll("details.botsauto-phase");return e?Array.prototype.slice.call(e):[]}function g(t,e){var o,n=a.get(t);if(!n||!n.primaryKey)return{expanded:[],hasValue:!1};for(var r=(o=Array.isArray(e)?{list:d(e),raw:null,hasValue:!0,fromMigration:!0}:c(n.primaryKey)).hasValue,s=new Set(o.list),u=[],p=f(t),b=!1,g=0;g<p.length;g++){var h=p[g],v=m(h,g);if(v){var w=r?s.has(v):h.open;r&&h.open!==w&&(h.open=w,b=!0),w&&u.push(v)}}if(r){var _=d(u);(b||_.length!==o.list.length)&&l(n.primaryKey,_)}return i(0,(n.primaryKey,u.slice())),{expanded:u,hasValue:r}}function h(t,e){var o=a.get(t);if(!o||!o.primaryKey)return[];var n=Array.isArray(e)?d(e):function(t){for(var e=f(t),o=[],a=0;a<e.length;a++){var n=e[a],i=m(n,a);i&&n.open&&o.push(i)}return d(o)}(t);return l(o.primaryKey,n),i(0,(o.primaryKey,n.slice())),n}function v(t){var e=t.target;if(e&&1===e.nodeType&&(!e.tagName||"details"===e.tagName.toLowerCase())&&e.classList&&e.classList.contains("botsauto-phase")){var o=e.closest("form.botsauto-checklist");if(o){m(e,-1);var a=h(o);i(0,(e.getAttribute("data-phase-key"),e.open,a.slice()))}}}function w(t){t&&!n.has(t)&&(t.addEventListener("toggle",v,!0),n.add(t),i(0,(t.getAttribute("id"),a.has(t)&&a.get(t).primaryKey)))}return{init:function(t){for(var e=function(t){if(t&&t.jquery)return t.toArray();if(t===document||t===window)return[document];if(t&&(1===t.nodeType||9===t.nodeType))return[t];if(Array.isArray(t))return t;if(t&&"number"==typeof t.length)try{return Array.prototype.slice.call(t)}catch(t){return[document]}return[document]}(t),o=[],i=new Set,r=0;r<e.length;r++){var s=e[r];if(s&&(s.matches&&s.matches("form.botsauto-checklist")&&(i.has(s)||(i.add(s),o.push(s))),s.querySelectorAll))for(var d=s.querySelectorAll("form.botsauto-checklist"),c=0;c<d.length;c++){var l=d[c];i.has(l)||(i.add(l),o.push(l))}}if(!o.length&&-1===e.indexOf(document))for(var p=document.querySelectorAll?document.querySelectorAll("form.botsauto-checklist"):[],m=0;m<p.length;m++){var f=p[m];i.has(f)||(i.add(f),o.push(f))}for(var v=0;v<o.length;v++){var _=o[v];if(_&&"0"!==_.getAttribute("data-phase-state")){var y=u(_);if(a.set(_,y),n.has(_))h(_);else{var k=g(_,y.postKey?b(0,y):null);k.hasValue||h(_,k.expanded),w(_)}}}},saveState:function(t){return h(t)},restoreState:function(t){return g(t).expanded},migrateKeys:function(t){var e=u(t);return a.set(t,e),b(0,a.get(t))||[]}}}();function h(t){g.init(t||document)}"loading"===document.readyState?document.addEventListener("DOMContentLoaded",function(){h()}):h(),["botsauto:ui:refreshed","botsauto:checklist:rendered","botsauto:checklist:refreshed","botsauto:checklist:updated","botsauto:checklist:hydrated","botsauto:checklist:saved","botsauto:checklist:submitted"].forEach(function(t){document.addEventListener(t,function(t){h(t&&t.detail&&(t.detail.scope||t.detail.root||t.detail.container)||document)})}),e(document).off("ajaxComplete.phaseStateController").on("ajaxComplete.phaseStateController",function(){h(document)}),window.botsautoPhaseState=g;var v=window.botsautoDocked||{},w=!(!1===v.enabled||"0"===v.enabled||0===v.enabled),_=parseInt(v.breakpoint,10);(isNaN(_)||_<320)&&(_=1024);var y=new Map,k=!1,S=null;function x(){return(window.innerWidth||document.documentElement.clientWidth||0)>=_}function A(){w&&(k||(k=!0,setTimeout(function(){k=!1,O()},40)))}function T(t,n,i,r){var s=i.querySelector(".ba-docked-perc"),u=i.querySelector(".ba-docked-save"),d=i.querySelector(".ba-docked-expand"),c=i.querySelector(".ba-docked-collapse"),l=null,p=0;function b(){return"1"===i.getAttribute("data-closed")}function m(){i.classList.remove("is-visible"),i.setAttribute("aria-hidden","true")}function f(){!b()&&x()?(i.classList.add("is-visible"),i.setAttribute("aria-hidden","false")):m()}function g(){return!b()&&x()&&r&&document.body.contains(r)&&i&&document.body.contains(i)}function h(t){g()?t.forEach(function(t){t.target===r&&(t.isIntersecting&&t.intersectionRatio>0?m():f())}):m()}function v(){w(),g()&&((l=new IntersectionObserver(h,{threshold:[0,.05]})).observe(r),function(){if(g()){var t=r.getBoundingClientRect(),e=window.innerHeight||document.documentElement.clientHeight||0;!e&&document.documentElement&&(e=document.documentElement.clientHeight||0),t.bottom>0&&t.top<e?m():f()}else m()}())}function w(){l&&(l.disconnect(),l=null)}function _(){if(!g())return m(),void w();v()}function y(t){p=t,s&&(s.textContent=t+"%")}function k(t){t&&t.dispatchEvent(new Event("click",{bubbles:!0}))}function S(t){t.preventDefault();var i=n&&n.matches&&n.matches(Rt)?n:n?n.querySelector(Rt):null;if(i)if(e(i).data("botsautoSubmitting"))o("[BOTSAUTO SAVE] ignored duplicate submit from docked save");else{var r=function(t){var o=e(t||n).find('.botsauto-submit-row button[type="submit"], .botsauto-submit-row input[type="submit"]').first();return o.length?o[0]:null}(i);if("function"!=typeof i.requestSubmit)if(!r||r.disabled||"function"!=typeof r.click){var s=new Event("submit",{bubbles:!0,cancelable:!0});i.dispatchEvent(s)&&"function"==typeof i.submit&&i.submit()}else r.click();else try{r&&!r.disabled?i.requestSubmit(r):i.requestSubmit()}catch(t){a("[BOTSAUTO SAVE] requestSubmit fallback used for docked save",t),r&&!r.disabled&&"function"==typeof r.click&&r.click()}}}function A(t){t.preventDefault(),k(n.querySelector('[data-botsauto-expand-all="true"]')||n.querySelector("#botsauto-expand-all"))}function T(t){t.preventDefault(),k(n.querySelector('[data-botsauto-collapse-all="true"]')||n.querySelector("#botsauto-collapse-all"))}return u&&u.addEventListener("click",S),d&&d.addEventListener("click",A),c&&c.addEventListener("click",T),i.setAttribute("aria-hidden","true"),i.setAttribute("data-botsauto-docked-ready","1"),_(),y(p),{instanceId:t,bar:i,updateProgress:y,refresh:_,setProgressTarget:function(t){t&&t!==r?(r=t,v()):_()},destroy:function(){w(),m(),u&&u.removeEventListener("click",S),d&&d.removeEventListener("click",A),c&&c.removeEventListener("click",T)}}}function O(){if(!w)return e(".botsauto-docked-bar").removeClass("is-visible").attr("aria-hidden","true"),y.forEach(function(t){t.destroy()}),void y.clear();y.forEach(function(t,e){t.bar&&document.body.contains(t.bar)||(t.destroy(),y.delete(e))});var t=e(".botsauto-docked-bar[data-botsauto-instance]");t.length&&t.each(function(){var t=this,a=t.getAttribute("data-botsauto-instance");if(a){var n=e('.botsauto-checklist[data-botsauto-instance="'+a+'"], .botsauto-wrapper[data-botsauto-instance="'+a+'"], .botsauto-container[data-botsauto-instance="'+a+'"]').first();if(n.length){var i=n.find(".botsauto-progress-wrapper.ba-progress").first();if(i.length){if(y.has(a)){var r=y.get(a);if(r.bar===t)return r.setProgressTarget(i[0]),void r.refresh();r.destroy(),y.delete(a)}var s=T(a,n[0],t,i[0]);y.set(a,s)}else o("BOTSAUTO: Docked bar skipped, progress not found for instance",a)}else o("BOTSAUTO: Docked bar skipped, root not found for instance",a)}})}function C(t){e(".botsauto-version-badge").each(function(){var o=e(this),a=(o.data("label-format")||"v{version}").replace("{version}",t);o.text(a)}),window.botsauto&&void 0!==window.botsauto.current_version&&(window.botsauto.current_version=t)}O(),e(document).on("ajaxComplete.botsautoDocked",function(){A()}),["botsauto:ui:refreshed","botsauto:checklist:rendered","botsauto:checklist:refreshed","botsauto:import:modeChanged"].forEach(function(t){document.addEventListener(t,A)}),window.addEventListener("resize",function(){w&&(S||(S=requestAnimationFrame(function(){S=null,y.forEach(function(t){t.refresh()})})))}),window.addEventListener("orientationchange",function(){A()}),window.botsautoRefreshDockedBars=O,window.botsautoUpdateVersion=C;var j=["is-active","is-checked","nvt","is-nvt","checked","completed","botsauto-item--checked","botsauto-item--active","botsauto-item--nvt"],I=["is-checked","checked","completed","botsauto-item--checked","botsauto-item--active","botsauto-item--nvt","active","highlight-checked","with-checked-icon","has-checked-icon","checked-icon","botsauto-checked-icon"],E=[".botsauto-answer-row",".botsauto-item-text",".botsauto-item-text-inner",".botsauto-item-icon",".botsauto-icon",".botsauto-item-info",".botsauto-note-btn",".botsauto-nvt-toggle",".botsauto-attachment-indicator",".botsauto-attachment-indicator .ba-attach-indicator",".botsauto-state-icon",".botsauto-status-icon"],q=['[data-role="checked-icon"]',"[data-checked-icon]",".botsauto-checked-icon",".ba-checked-icon",".botsauto-state-icon--checked"];function N(t){if(!t||!t.length)return null;function e(t){if(!t||!t.length)return"";var e=t.attr("style");return"string"==typeof e?e:""}var o=(t.attr("class")||"").split(/\s+/).filter(function(t){return t&&-1===j.indexOf(t)}),a=t.find(".botsauto-checkbox").first(),n=t.find(".botsauto-item-text").first(),i=t.find(".botsauto-item-text-inner").first(),r=t.find(".botsauto-note-btn").first(),s=t.find(".botsauto-nvt-toggle").first(),u=t.find(".botsauto-answer-row").first(),d=t.find(".botsauto-item-icon, .botsauto-icon").first(),c=t.find(".botsauto-item-info").first();return{baseClasses:o,itemStyle:e(t),checkboxStyle:e(a),itemTextStyle:e(n),itemTextInnerStyle:e(i),noteButtonStyle:e(r),nvtToggleStyle:e(s),nvtToggleHtml:s.length?s.html():null,answerRowStyle:e(u),iconStyle:e(d),infoStyle:e(c)}}function B(t,e){if(t&&t.length&&e){Array.isArray(e.baseClasses)&&e.baseClasses.forEach(function(e){e&&!t.hasClass(e)&&t.addClass(e)});var o=t.find(".botsauto-checkbox").first(),a=t.find(".botsauto-item-text").first(),n=t.find(".botsauto-item-text-inner").first(),i=t.find(".botsauto-note-btn").first(),r=t.find(".botsauto-nvt-toggle").first(),s=t.find(".botsauto-answer-row").first(),u=t.find(".botsauto-item-icon, .botsauto-icon").first(),d=t.find(".botsauto-item-info").first();c(t,e.itemStyle),c(o,e.checkboxStyle),c(a,e.itemTextStyle),c(n,e.itemTextInnerStyle),c(i,e.noteButtonStyle),c(r,e.nvtToggleStyle),c(s,e.answerRowStyle),c(u,e.iconStyle),c(d,e.infoStyle),null!==e.nvtToggleHtml&&r.length&&r.html(e.nvtToggleHtml)}function c(t,e){t&&t.length&&(e&&""!==e.trim()?t.attr("style",e):t.removeAttr("style"))}}function U(t,a){if(t&&t.length){!function(t){if(t&&t.length&&!t.data("botsautoDefaultPresentation")){var e=function(t){if(!t||!t.length)return"active";var e=t.attr("data-state");if(e&&""!==e.trim())return e.trim();if(t.hasClass("nvt")||t.hasClass("is-nvt"))return"nvt";var o=t.find(".botsauto-checkbox").first();return o.length&&o.prop("checked")?"checked":"active"}(t);if("active"===e){var a=N(t);a&&t.data("botsautoDefaultPresentation",a)}else o("BOTSAUTO: Delaying default presentation capture for item",t.data("item-id"),"state:",e)}}(t);t.data("item-id");switch(function(t){var o=t.data("item-id");t.find(".botsauto-item-text, .botsauto-item-text-inner, label").each(function(){this.style.removeProperty("color")}),t[0].style.removeProperty("--ba-itm-text");var a=t.closest(".botsauto-checklist, .botsauto-wrapper, .botsauto-container");a.length&&(a[0].style.removeProperty("--ba-nvt-text"),a[0].style.removeProperty("--nvt-text-color"));o=t.data("item-id");e("#botsauto-nvt-text-color-"+o).remove(),t.removeClass("is-nvt nvt"),t.removeClass("is-active is-checked botsauto-item--checked botsauto-item--active botsauto-item--nvt checked completed active"),E.forEach(function(o){t.find(o).each(function(){var t=e(this);I.forEach(function(e){e&&t.hasClass(e)&&t.removeClass(e)});var o=this.attributes;if(o)for(var a=o.length-1;a>=0;a--){var n=o[a];if(n&&n.name){var i=n.name;"checked"!==i&&-1!==i.toLowerCase().indexOf("checked")&&t.removeAttr(i)}}})}),q.forEach(function(e){t.find(e).remove()}),t.removeAttr("aria-disabled tabindex"),t.removeAttr("style"),t.find(".botsauto-item-text, .botsauto-item-text-inner, .botsauto-icon, .botsauto-item-icon, .botsauto-item-info").removeAttr("style"),t.find(".botsauto-checkbox").removeAttr("style"),t.find(".botsauto-nvt-label").removeAttr("style"),t.find(".botsauto-attachment-indicator, .botsauto-attachment-indicator .ba-attach-indicator").removeAttr("style"),t.find(".nvt-text, .botsauto-nvt-text").removeClass("nvt-text botsauto-nvt-text"),t.find(".nvt-badge, .botsauto-nvt-label").remove();var n=t.find(".botsauto-checkbox");n.length&&(n.prop("disabled",!1),n.removeAttr("title"),n.removeAttr("aria-disabled"),n.removeAttr("tabindex"));var i=t.find(".botsauto-nvt-toggle");i.length&&(i.removeClass("active"),i.attr("title",window.botsauto&&window.botsauto.nvt_icon_tooltip||"NVT"),i.html(window.botsauto&&window.botsauto.nvt_icon||'<i class="fas fa-ban"></i>'),i.removeAttr("style"));t.find(".botsauto-answer-row, .botsauto-note-btn").removeAttr("style"),t.removeData("was-checked nvt-styling-in-progress prev-state")}(t),a){case"active":default:L(t);break;case"checked":!function(t){t.addClass("is-checked");var e=t.find(".botsauto-checkbox");e.length&&(e.prop("checked",!0),e.prop("disabled",!1));t.data("item-id")}(t);break;case"nvt":!function(t){t.removeAttr("style"),t.find(".botsauto-item-text, .botsauto-item-text-inner, .botsauto-icon").removeAttr("style"),t.addClass("nvt is-nvt").removeClass("checked completed is-checked"),t.attr("aria-disabled","true"),t.attr("tabindex","-1");var e=t.find(".botsauto-checkbox");e.length&&(e.prop("checked",!1),e.prop("disabled",!0),e.attr("aria-disabled","true"),e.attr("tabindex","-1"),e.attr("title",window.botsauto&&window.botsauto.nvt_tooltip_text||"Niet van toepassing"));var o=t.find(".botsauto-nvt-toggle");o.length&&(o.addClass("active"),o.attr("title",window.botsauto&&window.botsauto.undo_icon_tooltip||"Ongedaan maken"),o.html(window.botsauto&&window.botsauto.undo_icon||'<i class="fas fa-undo"></i>'));D(t),V(t);const a=window.botsauto&&window.botsauto.nvt_item_styles||{},n=window.botsauto&&window.botsauto.nvt_label_styles||{};(function(t,e,o){var a=t.find(".botsauto-checkbox"),n=t.find(".botsauto-item-text"),i=t.find(".botsauto-item-text-inner");if(t.data("nvt-styling-in-progress",!0),a.length){var r={};a.prop("checked",!1).prop("disabled",!0).attr("title",window.botsauto&&window.botsauto.nvt_tooltip_text||"Niet van toepassing"),a.css({"accent-color":"","background-color":"","border-color":""}),a.css(r)}if(n.length){var s={},u=o||e,d=[];(u["border-width"]||u.border_width)&&d.push(u["border-width"]||u.border_width),(u["border-style"]||u.border_style)&&d.push(u["border-style"]||u.border_style),(u["border-color"]||u.border_color)&&d.push(u["border-color"]||u.border_color),d.length>0&&(s.border=d.join(" ")+"!important"),(u["border-radius"]||u.border_radius)&&(s["border-radius"]=(u["border-radius"]||u.border_radius)+"!important"),(u["padding-top"]||u.padding_top)&&(s["padding-top"]=(u["padding-top"]||u.padding_top)+"!important"),(u["padding-right"]||u.padding_right)&&(s["padding-right"]=(u["padding-right"]||u.padding_right)+"!important"),(u["padding-bottom"]||u.padding_bottom)&&(s["padding-bottom"]=(u["padding-bottom"]||u.padding_bottom)+"!important"),(u["padding-left"]||u.padding_left)&&(s["padding-left"]=(u["padding-left"]||u.padding_left)+"!important"),(u["margin-top"]||u.margin_top)&&(s["margin-top"]=(u["margin-top"]||u.margin_top)+"!important"),(u["margin-right"]||u.margin_right)&&(s["margin-right"]=(u["margin-right"]||u.margin_right)+"!important"),(u["margin-bottom"]||u.margin_bottom)&&(s["margin-bottom"]=(u["margin-bottom"]||u.margin_bottom)+"!important"),(u["margin-left"]||u.margin_left)&&(s["margin-left"]=(u["margin-left"]||u.margin_left)+"!important"),u["text-align"]&&(s["text-align"]=u["text-align"]+"!important"),s.display="inline-block!important";var c=t.find(".botsauto-nvt-label");c.length&&c.css(s)}if(t.removeAttr("style"),t.find(".botsauto-item-text, .botsauto-item-text-inner, .botsauto-icon").removeAttr("style"),i.length){var l={};if((e.color||e.text_color)&&(l.color=(e.color||e.text_color)+"!important"),(e["font-size"]||e.font_size)&&(l["font-size"]=(e["font-size"]||e.font_size)+"!important"),(e["font-weight"]||e.font_weight)&&(l["font-weight"]=(e["font-weight"]||e.font_weight)+"!important"),(e["font-style"]||e.font_style)&&(l["font-style"]=(e["font-style"]||e.font_style)+"!important"),(e["text-decoration"]||e.text_decoration)&&(l["text-decoration"]=(e["text-decoration"]||e.text_decoration)+"!important"),e["text-decoration-color"]||e.text_decoration_color||e.decoration_color){var p=e["text-decoration-color"]||e.text_decoration_color||e.decoration_color;l["text-decoration-color"]=p+"!important",l["-webkit-text-decoration-color"]=p+"!important"}e["text-align"]&&(l["text-align"]=e["text-align"]+"!important"),e["line-height"]&&(l["line-height"]=e["line-height"]+"!important"),e["letter-spacing"]&&(l["letter-spacing"]=e["letter-spacing"]+"!important"),e["font-family"]&&(l["font-family"]=e["font-family"]+"!important"),(e["padding-top"]||e.padding_top)&&(l["padding-top"]=(e["padding-top"]||e.padding_top)+"!important"),(e["padding-right"]||e.padding_right)&&(l["padding-right"]=(e["padding-right"]||e.padding_right)+"!important"),(e["padding-bottom"]||e.padding_bottom)&&(l["padding-bottom"]=(e["padding-bottom"]||e.padding_bottom)+"!important"),(e["padding-left"]||e.padding_left)&&(l["padding-left"]=(e["padding-left"]||e.padding_left)+"!important"),(e["margin-top"]||e.margin_top)&&(l["margin-top"]=(e["margin-top"]||e.margin_top)+"!important"),(e["margin-right"]||e.margin_right)&&(l["margin-right"]=(e["margin-right"]||e.margin_right)+"!important"),(e["margin-bottom"]||e.margin_bottom)&&(l["margin-bottom"]=(e["margin-bottom"]||e.margin_bottom)+"!important"),(e["margin-left"]||e.margin_left)&&(l["margin-left"]=(e["margin-left"]||e.margin_left)+"!important"),i.length?i.css(l):n.length&&n.css(l)}t.removeData("nvt-styling-in-progress")})(t,a,n),function(t,e){var o=e.color||e.text_color||"#666666";t.data("item-id");t[0].style.setProperty("--ba-itm-text",o)}(t,a),t.length&&t[0].offsetHeight;t.data("item-id")}(t)}t.attr("data-state",a)}}function L(t){!function(t){if(t&&t.length){var e=t.data("botsautoDefaultPresentation");e?B(t,e):(e=N(t))&&(t.data("botsautoDefaultPresentation",e),B(t,e))}}(t),t.addClass("is-active");var e=t.find(".botsauto-checkbox");e.length&&(e.prop("checked",!1),e.prop("disabled",!1)),t.data("item-id")}function P(t,o){const a=t&&""!==t.trim()?t.trim():"Niet van toepassing",n=o&&""!==o.trim()?o.trim():a;return e('<span class="botsauto-nvt-label" />').attr("data-default-label",a).append('<span class="label--desktop">'+a+"</span>").append('<span class="label--mobile">'+n+"</span>")}function D(t){if(t.find(".botsauto-nvt-label").length>0)return void t.data("item-id");const e=(window.botsauto&&window.botsauto.nvt_label_saved||"").trim(),o=(window.botsauto&&window.botsauto.nvt_label_default||"Niet van toepassing").trim(),a=""!==e?e:window.botsauto&&window.botsauto.nvt_label||o||"Niet van toepassing",n=(window.botsauto&&window.botsauto.nvt_label_mobile||"").trim();var i;a&&""!==a?i=a:(console.error("BOTSAUTO: Label text is empty, using fallback"),i="Niet van toepassing"),t.data("item-id");var r=P(i,n);if(r&&r.length){var s=t.find(".botsauto-item-text"),u=!1;if(s.length)s.after(r),u=!0;else{var d=t.find(".botsauto-answer-row");d.length?(d.append(r),u=!0):(t.append(r),u=!0)}u?t.data("item-id"):(console.error("BOTSAUTO: Failed to insert badge anywhere in item",t.data("item-id")),t.append(r)),0===t.find(".botsauto-nvt-label").length?console.error("BOTSAUTO: CRITICAL - Badge not found in DOM after insertion for item",t.data("item-id")):t.data("item-id")}else console.error("BOTSAUTO: Failed to create badge element")}function V(t){var e=t.find(".botsauto-nvt-label");if(e.length){var o=window.botsauto&&window.botsauto.nvt_label_styles||{},a=(t.data("item-id"),{});o.color&&(a.color=o.color+"!important"),(o["background-color"]||o.background_color)&&(a["background-color"]=(o["background-color"]||o.background_color)+"!important");var n=[];(o["border-width"]||o.border_width)&&n.push(o["border-width"]||o.border_width),(o["border-style"]||o.border_style)&&n.push(o["border-style"]||o.border_style),(o["border-color"]||o.border_color)&&n.push(o["border-color"]||o.border_color),n.length>0&&(a.border=n.join(" ")+"!important"),(o["border-radius"]||o.border_radius)&&(a["border-radius"]=(o["border-radius"]||o.border_radius)+"!important"),o.padding?a.padding=o.padding+"!important":((o["padding-top"]||o.padding_top)&&(a["padding-top"]=(o["padding-top"]||o.padding_top)+"!important"),(o["padding-right"]||o.padding_right)&&(a["padding-right"]=(o["padding-right"]||o.padding_right)+"!important"),(o["padding-bottom"]||o.padding_bottom)&&(a["padding-bottom"]=(o["padding-bottom"]||o.padding_bottom)+"!important"),(o["padding-left"]||o.padding_left)&&(a["padding-left"]=(o["padding-left"]||o.padding_left)+"!important")),o.margin?a.margin=o.margin+"!important":((o["margin-top"]||o.margin_top)&&(a["margin-top"]=(o["margin-top"]||o.margin_top)+"!important"),(o["margin-right"]||o.margin_right)&&(a["margin-right"]=(o["margin-right"]||o.margin_right)+"!important"),(o["margin-bottom"]||o.margin_bottom)&&(a["margin-bottom"]=(o["margin-bottom"]||o.margin_bottom)+"!important"),(o["margin-left"]||o.margin_left)&&(a["margin-left"]=(o["margin-left"]||o.margin_left)+"!important")),(o["font-size"]||o.font_size)&&(a["font-size"]=(o["font-size"]||o.font_size)+"!important"),(o["font-weight"]||o.font_weight)&&(a["font-weight"]=(o["font-weight"]||o.font_weight)+"!important"),(o["font-style"]||o.font_style)&&(a["font-style"]=(o["font-style"]||o.font_style)+"!important"),(o["font-family"]||o.font_family)&&(a["font-family"]=(o["font-family"]||o.font_family)+"!important"),(o["text-align"]||o.text_align)&&(a["text-align"]=(o["text-align"]||o.text_align)+"!important"),a.display="inline-flex!important",a["align-items"]="center!important",a["white-space"]="nowrap!important",e.css(a)}}function z(t){var e=t.attr("data-state")||"active";"nvt"!==e?(t.data("prev-state",e),t.data("item-id")):t.data("item-id")}function M(t){var e=t.data("prev-state")||"active";t.removeData("prev-state"),t.data("item-id"),U(t,e)}function F(t){var e=t?window.botsauto&&window.botsauto.attention_all_reasons:window.botsautoAttentionReasons||window.botsauto&&window.botsauto.attention_reasons;return Array.isArray(e)?e:[]}function K(t){var e=String(t||"").toLowerCase().replace(/[^a-z0-9_]+/g,"_").replace(/_+/g,"_").replace(/^_+|_+$/g,"");return"blocked"===e?"wacht_op_input":e}function R(t){for(var e=String(t||""),o=K(e),a=F(!0).concat(F(!1)),n=0;n<a.length;n++)if(K(a[n].code||"")===o)return a[n];return"blocked"===e||"wacht_op_input"===o?{code:"wacht_op_input",label:"Wacht op input",category:"blocked"}:null}function J(){var t=e("#botsauto-attention-state");if(!t.length||!t.val())return{};try{var o=decodeURIComponent(escape(window.atob(String(t.val())))),n=JSON.parse(o);return n&&"object"==typeof n&&!Array.isArray(n)?n:{}}catch(t){return a("BOTSAUTO: Could not parse attention state",t),{}}}function H(t){var o=e("#botsauto-attention-state");o.length&&o.val(function(t){try{return window.btoa(unescape(encodeURIComponent(JSON.stringify(t||{}))))}catch(t){return a("BOTSAUTO: Could not encode attention state",t),""}}(t||J()))}function G(){return"botsauto_attention_presave_"+(window.location.pathname+window.location.search)}function W(){if(!Pt(Lt())&&"undefined"!=typeof Storage)try{localStorage.setItem(G(),e("#botsauto-attention-state").val()||"")}catch(t){a("BOTSAUTO: Could not persist attention localStorage",t)}}window.botsautoSetItemState=U,window.botsautoRememberPrevState=z,window.botsautoRestorePrevState=M,window.botsautoCreateNVTBadge=D,window.botsautoApplyNVTBadgeStyling=V,window.botsautoRenderNvtLabel=P,window.botsautoApplyStylesForState=function(t,e){t&&t.length&&(t.data("item-id"),U(t,e))},window.botsautoForceApplyNVTStyles=function(){e(".botsauto-item.nvt").each(function(){U(e(this),"nvt")})},window.botsautoForceCreateNVTBadges=function(){e(".botsauto-item.nvt").each(function(){var t=e(this);0===t.find(".botsauto-nvt-label").length?(t.data("item-id"),D(t),V(t)):(t.data("item-id"),V(t))})},window.botsautoDebugNVTStyles=function(){void 0!==window.botsauto&&window.botsauto,window.botsauto&&(window.botsauto.nvt_item_styles,window.botsauto.nvt_label_styles,window.botsauto.checked_item_styles),e(".botsauto-item.nvt").each(function(){var t=e(this),o=t.find(".botsauto-item-text"),a=t.find(".botsauto-item-text-inner"),n=t.find(".botsauto-nvt-label");t.data("item-id"),o.css("background-color"),o.css("border"),o.css("border-radius"),a.css("color"),a.css("text-decoration"),n.css("background-color"),n.length&&window.getComputedStyle(n[0]).backgroundColor})},window.botsautoDebugNVTBadges=function(){var t=e(".botsauto-item.nvt");t.length,t.each(function(){var t=e(this),o=(t.data("item-id"),t.find(".botsauto-nvt-label")),a=t.find(".botsauto-item-text"),n=t.find(".botsauto-answer-row");o.length,a.length,n.length,o.text(),o.is(":visible"),o.css("display"),o.css("visibility"),o.css("opacity"),0===o.length&&D(t)})},window.botsautoDetectBackgroundLeaks=function(){var t=[];return e(".botsauto-item.nvt").each(function(){var o=e(this),a=o.data("item-id"),n=o.find(".botsauto-nvt-label"),i=o.find(".botsauto-item-text"),r=o.find(".botsauto-item-text-inner"),s=o,u="";window.botsauto&&window.botsauto.nvt_label_styles&&(u=window.botsauto.nvt_label_styles["background-color"]||window.botsauto.nvt_label_styles.background_color||"");var d=i.length?window.getComputedStyle(i[0]).backgroundColor:"transparent",c=r.length?window.getComputedStyle(r[0]).backgroundColor:"transparent",l=s.length?window.getComputedStyle(s[0]).backgroundColor:"transparent",p=n.length?window.getComputedStyle(n[0]).backgroundColor:"transparent";u&&"transparent"!==u&&(d===p&&"rgba(0, 0, 0, 0)"!==d&&t.push({itemId:a,element:"itemText",background:d,expected:u}),c===p&&"rgba(0, 0, 0, 0)"!==c&&t.push({itemId:a,element:"itemTextInner",background:c,expected:u}),l===p&&"rgba(0, 0, 0, 0)"!==l&&t.push({itemId:a,element:"container",background:l,expected:u}))}),t.length>0&&t.forEach(function(t){t.itemId,t.element,t.background}),t},window.botsautoForceApplyNVTStyles=function(){e(".botsauto-item.nvt").each(function(){var t=e(this),o=window.botsauto&&window.botsauto.nvt_item_styles?window.botsauto.nvt_item_styles:{},a=window.botsauto&&window.botsauto.nvt_label_styles?window.botsauto.nvt_label_styles:{};try{applyNVTInlineStylesImmediate(t,o,a),applyNVTInlineStylesDirect(t,o,a),t.data("item-id")}catch(e){console.error("Error applying NVT styles to item",t.data("item-id"),":",e)}})},window.botsautoTestNVTTextColor=function(){var t=e(".botsauto-item.nvt");t.length,t.each(function(){var t=e(this),o=t.find(".botsauto-item-text-inner");t.data("item-id");o.length,o.css("color"),o.length&&window.getComputedStyle(o[0]).color,o.length&&o[0].style.color;var a=window.botsauto&&window.botsauto.nvt_item_styles?window.botsauto.nvt_item_styles:{};a.color||a.text_color})},e(".botsauto-note-btn").each(function(){var t=e(this).hasClass("botsauto-done")?window.botsauto&&window.botsauto.done_icon_tooltip||"Notitie bekijken":window.botsauto&&window.botsauto.note_icon_tooltip||"Notitie toevoegen";e(this).attr("title",t)}),e(".botsauto-nvt-toggle").each(function(){var t=e(this).closest(".botsauto-item").hasClass("nvt")?window.botsauto&&window.botsauto.undo_icon_tooltip||"Ongedaan maken":window.botsauto&&window.botsauto.nvt_icon_tooltip||"NVT";e(this).attr("title",t)}),e(".botsauto-item.nvt").each(function(){var t=e(this);U(t,"nvt"),t.find(".botsauto-nvt-toggle").attr("title",window.botsauto&&window.botsauto.undo_icon_tooltip||"Ongedaan maken"),function(t){const e=t.find(".botsauto-nvt-label").first();if(!e.length)return;let o=(e.attr("data-default-label")||"").trim();""===o&&(o=(window.botsauto&&window.botsauto.nvt_label||"").trim()),""===o&&(o=(window.botsauto&&window.botsauto.nvt_label_default||"Niet van toepassing").trim());const a=P(o,(window.botsauto&&window.botsauto.nvt_label_mobile||"").trim());e.replaceWith(a)}(t)}),e(".botsauto-item").each(function(){var t=e(this),o=t.find(".botsauto-checkbox"),a=o.length&&o.prop("checked"),n=t.hasClass("nvt");U(t,n?"nvt":a?"checked":"active"),t.data("item-id")}),function(){var t=e("#botsauto-nvt-state");if(t.length){var o=[];e(".botsauto-item.nvt").each(function(){var t=e(this).data("item-id");t&&""!==t&&"undefined"!==t&&"null"!==t&&o.push(String(t))});var a=t.val(),n=a?a.split(",").filter(function(t){return t&&""!==t&&"undefined"!==t&&"null"!==t}):[];o.sort().join(",")!==n.sort().join(",")?(t.val(o.join(",")),o.join(",")):o.join(",")}}(),function(){if("undefined"!=typeof Storage){var t=0;if(window.botsauto&&window.botsauto.checklist_id&&(t=parseInt(window.botsauto.checklist_id,10)||0),t>0)try{var o="botsauto_nvt_presave_"+(window.location.pathname+window.location.search);localStorage.removeItem(o)}catch(t){}else try{o="botsauto_nvt_presave_"+(window.location.pathname+window.location.search);var a=localStorage.getItem(o);if(a){var n=a.split(",").filter(function(t){return t&&""!==t&&"undefined"!==t&&"null"!==t});n.forEach(function(t){var o=e('.botsauto-item[data-item-id="'+t+'"]');if(o.length){var a=o.attr("data-state")||"active";"nvt"!==a&&(o.attr("data-prev-state")||o.attr("data-prev-state",a),U(o,"nvt"))}});var i=e("#botsauto-nvt-state");i.length&&i.val(n.join(",")),Bt()}}catch(t){}}}();var $=0,X=null;function Y(t){var o=(t=e(t)).data("ownerItem");if(o&&o.length&&e.contains(document,o[0]))return o;var a=t.attr("data-owner-item-id");if(a){var n=document.getElementById(a);if(n)return e(n)}return t.closest(".botsauto-item")}function Q(t,o){if(t=e(t),o=e(o),t.length&&o.length&&o[0].getBoundingClientRect){var a=o[0].getBoundingClientRect();t.css({position:"fixed",visibility:"hidden",display:"block",zIndex:1e6});var n=t.outerWidth(),i=t.outerHeight(),r=window.innerWidth||document.documentElement.clientWidth,s=window.innerHeight||document.documentElement.clientHeight,u=a.right-n;u=Math.max(8,Math.min(u,r-n-8));var d=a.bottom+6;d+i>s-8&&(d=a.top-i-6),d=Math.max(8,Math.min(d,s-i-8)),t.css({top:d+"px",left:u+"px",right:"auto",visibility:"visible"})}}function Z(){e(".botsauto-attention-menu").each(function(){var t=e(this),o=t.data("originControl"),a=Y(t);o&&o.length||(o=t.closest(".botsauto-attention-control")),t.prop("hidden",!0).attr("hidden",!0),o.removeClass("is-open"),o.find(".botsauto-attention-toggle").attr("aria-expanded","false"),a.removeClass("is-attention-menu-open"),function(t){if((t=e(t)).length){var o=t.data("originControl"),a=t.data("attentionPlaceholder");o&&o.length&&e.contains(document,o[0])&&(a&&a.length&&e.contains(document,a[0])?a.replaceWith(t):o.append(t)),a&&a.length&&a.remove(),t.removeClass("botsauto-attention-menu--floating").removeAttr("data-owner-item-id").removeData("ownerItem").removeData("originControl").removeData("triggerButton").removeData("attentionPlaceholder").css({position:"",visibility:"",display:"",zIndex:"",top:"",left:"",right:""})}}(t)})}function tt(t){var o=e(t),a=o.closest(".botsauto-attention-control"),n=a.children(".botsauto-attention-menu").first(),i=o.closest(".botsauto-item");if(n.length){Z();var r=e('<span class="botsauto-attention-menu-placeholder" hidden></span>'),s=function(t){var e=t.attr("id");return e||(e="botsauto-attention-owner-"+ ++$,t.attr("id",e)),e}(i);n.data("ownerItem",i).data("originControl",a).data("triggerButton",o).data("attentionPlaceholder",r).attr("data-owner-item-id",s),n.before(r),e(document.body).append(n),n.prop("hidden",!1).removeAttr("hidden"),n.addClass("botsauto-attention-menu--floating"),a.addClass("is-open"),i.addClass("is-attention-menu-open"),o.attr("aria-expanded","true"),Q(n,o)}}function et(t,o,a){if(a=a||{},!t||!t.length||!function(t){var e=t.find(".botsauto-checkbox").first();return!(t.hasClass("nvt")||t.hasClass("is-nvt")||e.length&&e.prop("checked"))}(t))return!1;var n=String(t.data("item-id")||"");if(!n)return!1;if(!(o=K(o)))return!1;var i=function(t){var e=R(t);return e&&e.label?String(e.label):t?"Onbekende/verwijderde reden: "+String(t):""}(o),r=function(t){var e=R(t);return e&&e.category?String(e.category):"general"}(o),s=J();return s[n]=o,H(s),W(),t.addClass("has-attention").removeClass("is-in-progress").toggleClass("is-blocked","blocked"===r),t.attr("data-attention-reason",o),t.attr("data-attention-label",i),t.attr("data-attention-category",r),t.find("> .botsauto-answer-row .botsauto-attention-badge").remove(),function(t){var o=t.children(".botsauto-attention-chip").first();if(!o.length){o=e('<span class="botsauto-attention-chip" />');var a=t.children(".botsauto-answer-row").first();a.length?o.insertBefore(a):t.prepend(o)}return o}(t).text(i).attr("title",i).show(),t.find(".botsauto-attention-toggle").addClass("active").prop("disabled",!1).attr("aria-disabled","false").attr("title","Aandacht vereist: "+i).attr("aria-label","Aandacht vereist: "+i),a.skipSummary||nt(),!0}function ot(t,e){if(e=e||{},t&&t.length){var o=String(t.data("item-id")||""),a=J();o&&Object.prototype.hasOwnProperty.call(a,o)&&(delete a[o],H(a),W()),Z(),t.removeClass("has-attention is-blocked"),t.removeAttr("data-attention-reason data-attention-label data-attention-category"),t.children(".botsauto-attention-chip, .botsauto-attention-badge").remove(),t.find("> .botsauto-answer-row .botsauto-attention-badge").remove(),t.find(".botsauto-attention-toggle").removeClass("active").attr("title","Aandacht vereist").attr("aria-label","Aandacht vereist").attr("aria-expanded","false"),at(t),e.skipSummary||nt()}}function at(t){if(t&&t.length){var o=t.find(".botsauto-checkbox").first(),a=o.length&&o.prop("checked"),n=t.hasClass("nvt")||t.hasClass("is-nvt")||"nvt"===t.attr("data-state"),i=t.hasClass("has-attention"),r=e.trim(t.find('textarea[name^="notes["]').first().val()||""),s=t.hasClass("has-note-attachments")||t.find(".ba-attachment-row").length>0||"true"===t.find(".botsauto-answer-row").attr("data-has-attachments");t.toggleClass("is-in-progress",!a&&!n&&!i&&(""!==r||s)),t.find(".botsauto-attention-toggle").prop("disabled",a||n).attr("aria-disabled",a||n?"true":"false"),(a||n)&&i?ot(t,{skipSummary:!0}):(a||n)&&(t.hasClass("is-attention-menu-open")&&Z(),t.children(".botsauto-attention-chip, .botsauto-attention-badge").remove(),t.find("> .botsauto-answer-row .botsauto-attention-badge").remove(),t.find(".botsauto-attention-toggle").attr("aria-expanded","false"),t.removeClass("is-attention-menu-open"),t.find(".botsauto-attention-control").removeClass("is-open"),t.find(".botsauto-attention-menu").prop("hidden",!0).attr("hidden",!0))}}function nt(){!function(){var t=e("form.botsauto-checklist").first();if(t.length&&!t.find(".botsauto-status-summary").length){var o=e('<div class="botsauto-status-summary" aria-live="polite" />'),a=e('<div class="botsauto-status-counts" />');[["completed","Voltooid"],["nvt","NVT"],["attention","Aandacht vereist"],["blocked","Wacht op input"],["in-progress","In behandeling"],["open","Open"]].forEach(function(t){a.append('<span class="botsauto-status-count" data-status-count="'+t[0]+'">'+t[1]+": <strong>0</strong></span>")});var n=e('<div class="botsauto-status-filters" role="group" aria-label="Checklist filters" />');[["all","Alles"],["attention","Aandacht vereist"],["blocked","Wacht op input"],["in-progress","In behandeling"],["open","Open"],["completed","Voltooid"],["nvt","NVT"]].forEach(function(t){n.append('<button type="button" class="botsauto-status-filter" data-filter="'+t[0]+'">'+t[1]+"</button>")}),o.append(a).append(n);var i=e(".botsauto-intro-progress-wrap").first();i.length?i.after(o):t.prepend(o)}}();var t={completed:0,nvt:0,attention:0,blocked:0,"in-progress":0,open:0};e(".botsauto-item").each(function(){var o=e(this);at(o);var a=o.find(".botsauto-checkbox").first(),n=a.length&&a.prop("checked"),i=o.hasClass("nvt")||o.hasClass("is-nvt")||"nvt"===o.attr("data-state"),r=o.hasClass("has-attention");i?t.nvt++:n?t.completed++:r?(t.attention++,"blocked"===(o.attr("data-attention-category")||"general")&&t.blocked++):o.hasClass("is-in-progress")?t["in-progress"]++:t.open++}),Object.keys(t).forEach(function(o){e('.botsauto-status-count[data-status-count="'+o+'"] strong').text(t[o])}),it(e(".botsauto-status-filter.active").data("filter")||"all");try{jt(("string"==typeof Rt?document.querySelector(Rt):null)||document.querySelector("form.botsauto-checklist"))}catch(t){a("BOTSAUTO phase completion update failed, continuing checklist UI update",t)}try{Ct(("string"==typeof Rt?document.querySelector(Rt):null)||document.querySelector("form.botsauto-checklist"))}catch(t){a("BOTSAUTO phase review state update failed; existing checklist UI continues.",t)}}function it(t){t=t||"all",e(".botsauto-status-filter").removeClass("active").filter('[data-filter="'+t+'"]').addClass("active"),e(".botsauto-item").each(function(){var o=e(this),a=o.find(".botsauto-checkbox").first(),n=a.length&&a.prop("checked"),i=o.hasClass("nvt")||o.hasClass("is-nvt")||"nvt"===o.attr("data-state"),r="all"===t||"attention"===t&&o.hasClass("has-attention")||"blocked"===t&&o.hasClass("is-blocked")||"in-progress"===t&&o.hasClass("is-in-progress")||"open"===t&&!n&&!i&&!o.hasClass("has-attention")&&!o.hasClass("is-in-progress")||"completed"===t&&n&&!i||"nvt"===t&&i;o.toggle(r),o.toggleClass("is-filter-match",r),o.toggleClass("is-filter-hidden",!r)}),function(t){var o=!t||"all"===t;e((a=e(".botsauto-question-group"),n=e(".botsauto-question-row").map(function(){return e(this).closest("li")[0]}).filter(function(){return!e(this).hasClass("botsauto-question-group")}),a.add(n))).each(function(){var t=e(this),a=t.find(".botsauto-item.is-filter-match").length>0,n=o||a;t.toggle(n),t.toggleClass("is-filter-match",n),t.toggleClass("is-filter-hidden",!n)});var a,n}(t),function(t){var o=!t||"all"===t;e(".botsauto-phase").each(function(){var t=e(this),a=t.find(".botsauto-question-group.is-filter-match").length>0;a||(a=t.find(".botsauto-question-row").filter(function(){return e(this).closest("li").hasClass("is-filter-match")}).length>0);var n=o||a;t.toggle(n),t.toggleClass("is-filter-match",n),t.toggleClass("is-filter-hidden",!n)})}(t)}function rt(t){var e=t&&t.querySelectorAll?t:document;return{form:t||null,field:e.querySelector?e.querySelector("#botsauto-phase-completion-state"):null,phases:e.querySelectorAll?e.querySelectorAll("details.botsauto-phase"):[],containers:e.querySelectorAll?e.querySelectorAll(".botsauto-phase-completion"):[]}}function st(t,e){t&&(t.textContent=$t(e))}function ut(t,e,o){var a=$t(e).trim(),n=function(t){var e=$t(t).trim();if(!e)return"";var o=new Date(e);if(!o||isNaN(o.getTime()))return"";try{if("undefined"!=typeof Intl&&Intl&&"function"==typeof Intl.DateTimeFormat)return new Intl.DateTimeFormat("nl-NL",{dateStyle:"medium",timeStyle:"short"}).format(o);if("function"==typeof o.toLocaleString)return o.toLocaleString("nl-NL")}catch(t){return o.toISOString()}return o.toISOString()}(o);return a&&n?t+" "+a+" · "+n:a?t+" "+a:n||""}function dt(t,e,o,a){if(t&&t.querySelector){var n=t.querySelector(".botsauto-phase-completion-note");if(n){var i=function(t){return{showMetadata:"1"===(t&&t.getAttribute&&t.getAttribute("data-show-metadata")||"1"),showReviewNote:"1"===(t&&t.getAttribute&&t.getAttribute("data-show-review-note")||"1")}}(n),r=n.querySelector(".botsauto-phase-completion-note__section--completion"),s=n.querySelector(".botsauto-phase-completion-note__section--review"),u=r?r.querySelector(".botsauto-phase-completion-note__text"):null,d=r?r.querySelector(".botsauto-phase-completion-note__meta"):null,c=s?s.querySelector(".botsauto-phase-completion-note__text"):null,l=s?s.querySelector(".botsauto-phase-completion-note__meta"):null,p=$t(e&&e.completion_note).trim(),b=$t(e&&e.review_note).trim(),m=""!==p,f=""!==b&&i.showReviewNote,g=m,h=g||f,v=ut("Afgerond door",e&&e.completed_by_name,e&&e.completed_at),w=ut("Opnieuw bevestigd door",e&&e.reviewed_by_name,e&&e.reviewed_at);r&&(r.hidden=!g),s&&(s.hidden=!f),u&&st(u,p),c&&st(c,b),d&&(st(d,v),d.hidden=!(i.showMetadata&&v)),l&&(st(l,w),l.hidden=!(i.showMetadata&&w)),n.hidden=!h,n.classList.toggle("botsauto-phase-completion-note--has-completion",m),n.classList.toggle("botsauto-phase-completion-note--has-review",f),n.classList.toggle("botsauto-phase-completion-note--completed",!(!o||"completed"!==o.key)),n.classList.toggle("botsauto-phase-completion-note--attention",!(!o||"completed_with_attention"!==o.key)),n.classList.toggle("botsauto-phase-completion-note--review",f&&!a),n.classList.toggle("botsauto-phase-completion-note--review-needed",!!a)}}}function ct(t,e){if(!t)return"";var o=t.getAttribute("data-phase-key")||"";return o||(o="phase-completion-"+String(e||0),t.setAttribute("data-phase-key",o)),o}function lt(t,o){if(!t)return"Fase "+String(o||0);var a=t.getAttribute("data-phase-name")||"";if(!a){var n=t.querySelector(".botsauto-phase-title");a=n?e.trim(e(n).text()||""):""}return a||"Fase "+String(o||0)}function pt(t){var e=rt(t);if(!e.field)return{};var o=e.field.value||"";if(!o)return{};try{var n=oe(o),i=n?JSON.parse(n):{};return i&&"object"==typeof i&&!Array.isArray(i)?i:{}}catch(t){return a("BOTSAUTO phase completion state parse failed",t),{}}}function bt(t){return!(!t||"completed"!==t.manual_status&&"completed_with_attention"!==t.manual_status)}function mt(t){if(!t||"object"!=typeof t)return"open";var e=$t(t.workflow_status).trim();return{open:!0,completed:!0,review_needed:!0,reopened:!0,reconfirmed:!0}[e]?e:bt(t)?"completed":"open"}function ft(t,e){var o=$t(t).trim();return o||(alert(e),null)}function gt(t,e){var o=rt(t);return!!o.field&&(o.field.value=ee(JSON.stringify(e||{})),!0)}function ht(t){var e=$t(t).trim();if(!e)return"{}";try{var o;try{o=oe(e)}catch(t){o=e}var a=o?JSON.parse(o):{};if(!a||"object"!=typeof a||Array.isArray(a))return"{}";var n={};return Object.keys(a).sort().forEach(function(t){var e=a[t];e&&"object"==typeof e&&!Array.isArray(e)&&(n[t]={phase_name:$t(e.phase_name),workflow_status:$t(e.workflow_status),manual_status:$t(e.manual_status),completed_at:$t(e.completed_at),completed_by:parseInt(e.completed_by,10)||0,completed_by_name:$t(e.completed_by_name),completion_note:$t(e.completion_note),completion_snapshot_hash:$t(e.completion_snapshot_hash),reopened_at:$t(e.reopened_at),reopened_by:parseInt(e.reopened_by,10)||0,reopened_by_name:$t(e.reopened_by_name),reopen_note:$t(e.reopen_note),reviewed_at:$t(e.reviewed_at),reviewed_by:parseInt(e.reviewed_by,10)||0,reviewed_by_name:$t(e.reviewed_by_name),review_note:$t(e.review_note),latest_confirmation_snapshot_hash:$t(e.latest_confirmation_snapshot_hash),completed_count_at_completion:parseInt(e.completed_count_at_completion,10)||0,nvt_count_at_completion:parseInt(e.nvt_count_at_completion,10)||0,open_count_at_completion:parseInt(e.open_count_at_completion,10)||0,attention_count_at_completion:parseInt(e.attention_count_at_completion,10)||0,completed_count_at_review:null===e.completed_count_at_review||""===e.completed_count_at_review?null:parseInt(e.completed_count_at_review,10)||0,nvt_count_at_review:null===e.nvt_count_at_review||""===e.nvt_count_at_review?null:parseInt(e.nvt_count_at_review,10)||0,open_count_at_review:null===e.open_count_at_review||""===e.open_count_at_review?null:parseInt(e.open_count_at_review,10)||0,attention_count_at_review:null===e.attention_count_at_review||""===e.attention_count_at_review?null:parseInt(e.attention_count_at_review,10)||0})}),JSON.stringify(n)}catch(t){return e}}function vt(t){var o={total:0,completed:0,nvt:0,open:0,attention:0,waiting_for_input:0};return t&&t.querySelectorAll?(e(t).find(".botsauto-item").each(function(){var t=e(this);o.total++,at(t);var a=t.find(".botsauto-checkbox").first(),n=a.length&&a.prop("checked"),i=t.hasClass("nvt")||t.hasClass("is-nvt")||"nvt"===t.attr("data-state"),r=t.hasClass("has-attention");i?o.nvt++:n?o.completed++:r?(o.attention++,"blocked"===(t.attr("data-attention-category")||"general")&&o.waiting_for_input++):o.open++}),o):o}function wt(t,e){if(bt(t)){var o=mt(t);return"reopened"===o?{key:"reopened",label:"Heropend"}:"reconfirmed"===o?{key:"reconfirmed",label:"Opnieuw bevestigd"}:"review_needed"===o?{key:"review_needed",label:"Herbeoordeling nodig"}:0===e.open&&0===e.attention?{key:"completed",label:"Afgerond"}:{key:"completed_with_attention",label:"Afgerond met aandachtspunten"}}return e.waiting_for_input>0?{key:"waiting_for_input",label:"Wacht op input"}:e.attention>0?{key:"needs_attention",label:"Aandacht nodig"}:0===e.open?{key:"ready_to_complete",label:"Afrondbaar"}:{key:"in_progress",label:"Nog bezig"}}function _t(t){return $t(t).replace(/\s+/g," ").trim()}function yt(t,e){var o=Jt||"data-botsauto-original-name",a=t.getAttribute("name")||t.getAttribute(o)||"",n=t.getAttribute("id")||"";return _t(a||n||"field-"+String(e||0))}function kt(t,e){if(!t)return"item-"+String(e||0);var o=t.getAttribute("data-item-id")||t.getAttribute("data-item-hash")||"";if(!o){var a=t.querySelector("input[name^='answers[']"),n=a&&a.name?a.name.match(/^answers\[([^\]]+)\]$/):null;o=n?n[1]:""}return _t(o||"item-"+String(e||0))}function St(t){var e=[];return t&&t.querySelectorAll?(t.querySelectorAll("input, select, textarea").forEach(function(t,o){var a=_t(t.getAttribute("type")||t.tagName||"").toLowerCase();if("button"!==a&&"submit"!==a&&"reset"!==a){var n={key:yt(t,o+1),tag:_t(t.tagName||"").toLowerCase(),type:a,value:"",checked:!1};"checkbox"===a||"radio"===a?(n.checked=!!t.checked,n.value=_t(t.value||"")):t.tagName&&"select"===t.tagName.toLowerCase()?n.value=_t(t.value||""):n.value=$t(t.value),e.push(n)}}),e.sort(function(t,e){return t.key<e.key?-1:t.key>e.key?1:0}),e):e}function xt(t){return null===t||"object"!=typeof t?JSON.stringify(t):Array.isArray(t)?"["+t.map(xt).join(",")+"]":"{"+Object.keys(t).sort().map(function(e){return JSON.stringify(e)+":"+xt(t[e])}).join(",")+"}"}function At(t){for(var e=xt(function(t){var e=t||null,o=parseInt(e&&e.getAttribute?e.getAttribute("data-phase-index"):"",10)||0,a={phase_key:_t(e&&e.getAttribute&&e.getAttribute("data-phase-key")||""),phase_name:_t(lt(e,o||1)),items:[]};return e&&e.querySelectorAll?(e.querySelectorAll(".botsauto-item").forEach(function(t,e){var o=t.querySelector(".botsauto-checkbox"),n=Jt||"data-botsauto-original-name",i=t.querySelector("textarea[name^='notes['], textarea["+n+"^='notes[']"),r=t.classList.contains("nvt")||t.classList.contains("is-nvt")||"nvt"===t.getAttribute("data-state"),s=_t(t.getAttribute("data-attention-reason")||""),u=_t(t.getAttribute("data-attention-category")||""),d=_t(t.getAttribute("data-attention-label")||"");a.items.push({item_key:kt(t,e+1),checked:!(!o||!o.checked),nvt:!!r,attention:t.classList.contains("has-attention"),attention_code:s,attention_category:u,attention_reason:s,attention_label:d,note_value:i?$t(i.value):"",fields:St(t)})}),a.items.sort(function(t,e){return t.item_key<e.item_key?-1:t.item_key>e.item_key?1:0}),a):a}(t)),o=2166136261,a=0;a<e.length;a++)o^=e.charCodeAt(a),o=Math.imul(o,16777619);return"ba-fnv1a-"+(o>>>0).toString(16)}function Tt(t,e){if(!bt(e))return!1;if("reopened"===mt(e))return!1;var o=function(t){return _t(t&&(t.latest_confirmation_snapshot_hash||t.completion_snapshot_hash))}(e);return!!o&&At(t)!==o}function Ot(t){try{Ct(t)}catch(t){a("BOTSAUTO phase review state update failed; existing checklist UI continues.",t)}}function Ct(t){var e=rt(t);if(e.field&&e.phases.length){var o=pt(t);Array.prototype.forEach.call(e.phases,function(e,a){var n=ct(e,a+1),i=e.querySelector(".botsauto-phase-completion");if(n&&i){var r=o[n]||null,s=bt(r),u=!1;if(s&&(u=Tt(e,r)),r&&"object"==typeof r){var d=mt(r),c=s?u?"review_needed":d:"open";r.workflow_status!==c&&(r.workflow_status=c,o[n]=r,gt(t,o))}var l=function(t,e){if(!t||!t.querySelector)return{reconfirmBtn:null,message:null};var o=t.querySelector(".botsauto-phase-actions")||t,a=t.querySelector(".botsauto-phase-review-message");a||((a=document.createElement("p")).className="botsauto-phase-review-message",a.hidden=!0,a.textContent="Deze fase is afgerond, maar daarna gewijzigd.",o.parentNode.insertBefore(a,o));var n=t.querySelector(".botsauto-phase-reconfirm-btn");return n||((n=document.createElement("button")).type="button",n.className="botsauto-btn botsauto-phase-reconfirm-btn",n.hidden=!0,n.textContent="Fase opnieuw bevestigen",o.insertBefore(n,o.querySelector(".botsauto-phase-reopen-btn")||null)),n.setAttribute("data-phase-key",e||""),{reconfirmBtn:n,message:a}}(i,n),p=i.querySelector(".botsauto-phase-complete-btn"),b=i.querySelector(".botsauto-phase-reopen-btn"),m=mt(r),f="reopened"===m||"review_needed"===m;if(p&&(p.hidden=s,p.setAttribute("data-phase-key",n)),b&&(b.hidden=!s||"reopened"===m,b.setAttribute("data-phase-key",n)),l.reconfirmBtn&&(l.reconfirmBtn.hidden=!f,l.reconfirmBtn.setAttribute("data-phase-key",n)),l.message&&(l.message.hidden=!(s&&u)),e.classList.toggle("botsauto-phase--review-needed",s&&u),i.classList.toggle("botsauto-phase-status-review-needed",s&&u),i.setAttribute("data-phase-review-status",s&&u?"review_needed":""),s&&u){i.setAttribute("data-phase-status","review_needed"),e.setAttribute("data-phase-completion-status","review_needed");var g=i.querySelector(".botsauto-phase-status-chip");g&&(g.textContent="Herbeoordeling nodig",g.setAttribute("data-phase-status","review_needed"))}dt(i,r,wt(bt(r)?r:null,vt(e)),s&&u)}})}}function jt(t){var e=rt(t);if(e.field&&e.containers.length&&e.phases.length){var o=pt(t);Array.prototype.forEach.call(e.phases,function(t,e){var a=ct(t,e+1);if(a){var n=vt(t),i=o[a]||null,r=bt(i)?i:null,s=wt(r,n),u=n.total?Math.round((n.completed+n.nvt)/n.total*100):0,d=t.querySelector(".botsauto-phase-completion");if(d){d.setAttribute("data-phase-status",s.key),d.setAttribute("data-phase-manual-status",r?r.manual_status:"");var c=d.querySelector(".botsauto-phase-progress");if(c){c.style.setProperty("--botsauto-phase-progress-pct",u+"%"),c.setAttribute("aria-valuenow",String(u));var l=c.querySelector(".botsauto-phase-progress__fill");l&&(l.style.width=u+"%");var p=c.querySelector(".botsauto-phase-progress__label");p&&(p.textContent=u+"%")}var b=d.querySelector(".botsauto-phase-status-chip");b&&(b.textContent=s.label,b.setAttribute("data-phase-status",s.key)),["completed","nvt","open","attention"].forEach(function(t){var e=d.querySelector('.botsauto-phase-count[data-phase-count="'+t+'"] strong');e&&(e.textContent=String(n[t]||0))});var m=d.querySelector(".botsauto-phase-complete-btn"),f=d.querySelector(".botsauto-phase-reopen-btn"),g=bt(r),h=mt(i);m&&(m.hidden=g,m.textContent=function(t){return t.attention>0?"Afronden met aandachtspunten":t.open>0?"Afronden met open punten":"Fase afronden"}(n),m.setAttribute("data-phase-key",a)),f&&(f.hidden=!g||"reopened"===h,f.setAttribute("data-phase-key",a)),dt(d,r,s,"review_needed"===d.getAttribute("data-phase-review-status")),t.classList.toggle("botsauto-phase--manual-completed",g),t.setAttribute("data-phase-completion-status",s.key)}}})}}function It(t){var e=t.closest("details.botsauto-phase"),o=t.closest("form.botsauto-checklist")||document.querySelector(Rt);if(e&&o&&rt(o).field){var n=parseInt(e.getAttribute("data-phase-index"),10)||0,i=ct(e,n||1),r=pt(o),s=r[i]||null;if(bt(s)){var u=vt(e),d=window.prompt("Deze fase is gewijzigd sinds afronding. Leg kort vast waarom de fase opnieuw bevestigd kan worden.","");if(null!==d){var c=ft(d,"Een herbevestigingsnotitie is verplicht.");if(null!==c){var l="";try{l=At(e)}catch(t){return void a("BOTSAUTO phase review hash creation failed during reconfirm; phase state was not changed.",t)}var p=window.botsauto&&window.botsauto.phase_completion_current_user_name||s.completed_by_name||"";r[i]={phase_name:s.phase_name||lt(e,n||1),workflow_status:"reconfirmed",manual_status:u.attention>0||u.open>0?"completed_with_attention":"completed",completed_at:s.completed_at||"",completed_by:parseInt(s.completed_by,10)||0,completed_by_name:s.completed_by_name||"",completion_note:s.completion_note||"",completion_snapshot_hash:s.completion_snapshot_hash||"",reviewed_at:(new Date).toISOString(),reviewed_by:window.botsauto&&window.botsauto.phase_completion_current_user_id||0,reviewed_by_name:p,review_note:c,latest_confirmation_snapshot_hash:l,reopened_at:s.reopened_at||"",reopened_by:parseInt(s.reopened_by,10)||0,reopened_by_name:s.reopened_by_name||"",reopen_note:s.reopen_note||"",completed_count_at_completion:parseInt(s.completed_count_at_completion,10)||0,nvt_count_at_completion:parseInt(s.nvt_count_at_completion,10)||0,open_count_at_completion:parseInt(s.open_count_at_completion,10)||0,attention_count_at_completion:parseInt(s.attention_count_at_completion,10)||0,completed_count_at_review:u.completed,nvt_count_at_review:u.nvt,open_count_at_review:u.open,attention_count_at_review:u.attention},gt(o,r)&&(jt(o),Ot(o))}}}}}function Et(t,e){var o=t||{};return o.networkError?"Aandacht opslaan mislukt. Controleer uw verbinding en probeer opnieuw.":403===o.status?"Je sessie is verlopen of je hebt geen toegang meer. Vernieuw de pagina en probeer opnieuw.":400===o.status&&"invalid_reason"===o.errorCode?"Selecteer een geldige aandachtreden.":409===o.status&&"item_not_open"===o.errorCode?"Aandacht kan alleen op open checklist-items worden gezet.":o.message||e}function qt(t,e){H(e),ot(t,{skipSummary:!0}),e[t.data("item-id")]&&et(t,e[t.data("item-id")],{skipSummary:!0}),nt()}function Nt(t,e,o,a){return Vt(t,"Aandacht opslaan mislukt.",{action:"botsauto_update_item_attention",responseJSON:e,status:o,textStatus:a,errorCode:e&&e.data&&e.data.error_code?e.data.error_code:"",serverMessage:e&&e.data&&e.data.message?e.data.message:""})}function Bt(){d();var t=jQuery,e=t(".botsauto-question-row .botsauto-checkbox, .botsauto-item .botsauto-checkbox, .botsauto-checkbox").filter(":enabled").filter(function(){return"nvt"!==(t(this).closest(".botsauto-item").attr("data-state")||"active")}),o=e.length,a=e.filter(":checked").length,n=o?Math.round(a/o*100):0;!function(t){y.size&&y.forEach(function(e){e.updateProgress(t)})}(n);var i=t(".botsauto-progress");if(i.length){var r;i.show(),function(t,e){t.find(".botsauto-progress__fill").css("width",e+"%"),t.find(".botsauto-progress__label").text(e+"%"),t.css("--ba-pg-percent",e+"%"),t.attr("aria-valuenow",e),t.closest(".botsauto-progress-wrapper").attr("data-progress",e),t.find(".botsauto-progress__thumb-label").text(e+"%")}(i,n),r=n<50?i.css("--ba-pg-low")||window.botsauto&&window.botsauto.progress_low||"#333333":n<100?i.css("--ba-pg-mid")||window.botsauto&&window.botsauto.progress_mid||"#007cba":i.css("--ba-pg-done")||window.botsauto&&window.botsauto.progress_complete||"#006633",i.each(function(){this.style.setProperty("--ba-pg-percent",n+"%"),this.style.setProperty("--ba-pg-fill",r),this.style.setProperty("--ba-pg-thumb-fill",r)});var s=i.attr("data-tooltip")||window.botsauto&&window.botsauto.progress_tooltip||"";s&&i.attr("title",s)}t(".botsauto-progress-count").text(a+" van "+o+" relevante items voltooid"),t(".botsauto-progress-perc").text(n+"%");var u=t(".botsauto-outro");if(u.length){var c=t('input[name="completed"]').is(":checked");100===n||c?u.show():u.hide()}nt();try{var l=new CustomEvent("botsauto:progress:updated",{detail:{percent:n,total:o,completed:a}});document.dispatchEvent(l)}catch(t){var p=document.createEvent("CustomEvent");p.initCustomEvent("botsauto:progress:updated",!0,!0,{percent:n,total:o,completed:a}),document.dispatchEvent(p)}}e(document).off("click.botsautoPhaseCompletion",".botsauto-phase-complete-btn").on("click.botsautoPhaseCompletion",".botsauto-phase-complete-btn",function(t){t.preventDefault(),t.stopPropagation();var e=this,o=e.closest("details.botsauto-phase"),n=e.closest("form.botsauto-checklist")||document.querySelector(Rt);if(o&&n&&rt(n).field){var i=parseInt(o.getAttribute("data-phase-index"),10)||0,r=ct(o,i||1),s=pt(n),u=s[r]||null;if(u&&"open"!==mt(u))It(e);else{var d=vt(o),c=d.open>0||d.attention>0,l="";if(c){var p=d.attention>0?"Deze fase bevat nog aandachtspunten. Leg kort vast waarom afronden verantwoord is.":"Deze fase bevat nog open punten. Leg kort vast waarom afronden verantwoord is.",b=window.prompt(p,"");if(null===b)return;var m=ft(b,"Een afrondingsnotitie is verplicht wanneer de fase open punten of aandachtspunten bevat.");if(null===m)return;l=m}var f="";try{f=At(o)}catch(t){a("BOTSAUTO phase review hash creation failed during completion; phase completion continues.",t)}s[r]={phase_name:lt(o,i||1),workflow_status:"completed",manual_status:c?"completed_with_attention":"completed",completed_at:(new Date).toISOString(),completed_by:window.botsauto&&window.botsauto.phase_completion_current_user_id||0,completed_by_name:window.botsauto&&window.botsauto.phase_completion_current_user_name||"",completion_note:l,completion_snapshot_hash:f,completed_count_at_completion:d.completed,nvt_count_at_completion:d.nvt,open_count_at_completion:d.open,attention_count_at_completion:d.attention},gt(n,s)&&(jt(n),Ot(n))}}}),e(document).off("click.botsautoPhaseCompletionReconfirm",".botsauto-phase-reconfirm-btn").on("click.botsautoPhaseCompletionReconfirm",".botsauto-phase-reconfirm-btn",function(t){t.preventDefault(),t.stopPropagation(),It(this)}),e(document).off("click.botsautoPhaseCompletionReopen",".botsauto-phase-reopen-btn").on("click.botsautoPhaseCompletionReopen",".botsauto-phase-reopen-btn",function(t){t.preventDefault(),t.stopPropagation();var e=this.closest("details.botsauto-phase"),o=this.closest("form.botsauto-checklist")||document.querySelector(Rt);if(e&&o&&rt(o).field){var a=parseInt(e.getAttribute("data-phase-index"),10)||0,n=ct(e,a||1),i=pt(o);if(Object.prototype.hasOwnProperty.call(i,n)&&i[n]&&"object"==typeof i[n]){var r=window.prompt("Leg kort vast waarom deze fase opnieuw wordt geopend.","");if(null===r)return;var s=ft(r,"Een heropeningsnotitie is verplicht.");if(null===s)return;i[n]=Object.assign({},i[n],{workflow_status:"reopened",reopened_at:(new Date).toISOString(),reopened_by:window.botsauto&&window.botsauto.phase_completion_current_user_id||0,reopened_by_name:window.botsauto&&window.botsauto.phase_completion_current_user_name||"",reopen_note:s})}gt(o,i)&&(jt(o),Ot(o))}}),function(){var t=Lt();if("undefined"!=typeof Storage)if(Pt(t))try{localStorage.removeItem(G())}catch(t){}else try{var o=localStorage.getItem(G());if(!o)return;e("#botsauto-attention-state").val(o);var n=J();Object.keys(n).forEach(function(t){et(e('.botsauto-item[data-item-id="'+t+'"]'),n[t],{skipSummary:!0})})}catch(t){a("BOTSAUTO: Could not restore pre-save attention state",t)}}(),e(document).off("click.botsautoAttention",".botsauto-attention-toggle").on("click.botsautoAttention",".botsauto-attention-toggle",function(t){t.preventDefault();var o=e(this);o.prop("disabled")||(o.closest(".botsauto-attention-control").hasClass("is-open")?Z():tt(o))}),e(document).off("click.botsautoAttentionReason",".botsauto-attention-reason-option").on("click.botsautoAttentionReason",".botsauto-attention-reason-option",function(){var t=e(this),o=Y(t.closest(".botsauto-attention-menu")),a=J(),n=String(t.data("reason-code")||"");if(et(o,n)){Z();var i=Lt();if(Pt(i)){var r=Dt({action:"botsauto_update_item_attention",item_key:o.data("item-id"),attention_state:"on",reason:n,nonce:window.botsauto&&window.botsauto.nonce||""},i);e.post(window.botsauto&&window.botsauto.ajax_url||"",r).done(function(t){if(!t||!t.success){var e=Nt(null,t,parseInt(t&&t.data&&(t.data.status||t.data.status_code),10)||400,"error");return Mt(e),qt(o,a),void alert(Et(e,"Aandacht opslaan mislukt."))}t.data&&t.data.version&&C(t.data.version)}).fail(function(t,e){var n=Nt(t,null,0,e);Mt(n),qt(o,a),alert(Et(n,"Aandacht opslaan mislukt."))})}}else Z()}),e(document).off("click.botsautoAttentionClear",".botsauto-attention-clear").on("click.botsautoAttentionClear",".botsauto-attention-clear",function(){var t=Y(e(this).closest(".botsauto-attention-menu")),o=J();ot(t),Z();var a=Lt();if(Pt(a)){var n=Dt({action:"botsauto_update_item_attention",item_key:t.data("item-id"),attention_state:"off",reason:"",nonce:window.botsauto&&window.botsauto.nonce||""},a);e.post(window.botsauto&&window.botsauto.ajax_url||"",n).done(function(e){if(!e||!e.success){var a=Nt(null,e,parseInt(e&&e.data&&(e.data.status||e.data.status_code),10)||400,"error");return Mt(a),qt(t,o),void alert(Et(a,"Aandacht verwijderen mislukt."))}e.data&&e.data.version&&C(e.data.version)}).fail(function(e,a){var n=Nt(e,null,0,a);Mt(n),qt(t,o),alert(Et(n,"Aandacht verwijderen mislukt."))})}}),e(document).off("click.botsautoAttentionOutside").on("click.botsautoAttentionOutside",function(t){e(t.target).closest(".botsauto-attention-control, .botsauto-attention-menu").length||Z()}),e(document).off("keydown.botsautoAttention").on("keydown.botsautoAttention",function(t){"Escape"!==t.key&&"Esc"!==t.key||Z()}),e(window).off("resize.botsautoAttention scroll.botsautoAttention").on("resize.botsautoAttention scroll.botsautoAttention",function(){X&&window.clearTimeout(X),X=window.setTimeout(function(){X=null,e(".botsauto-attention-menu--floating:not([hidden])").each(function(){var t=e(this),o=t.data("triggerButton");o&&o.length&&e.contains(document,o[0])?Q(t,o):Z()})},50)}),e(document).off("click.botsautoStatusFilter",".botsauto-status-filter").on("click.botsautoStatusFilter",".botsauto-status-filter",function(){it(e(this).data("filter")||"all")}),e(document).off("input.botsautoAttentionNotes","textarea[name^='notes[']").on("input.botsautoAttentionNotes","textarea[name^='notes[']",function(){at(e(this).closest(".botsauto-item")),nt()}),e(document).off("input.botsautoPhaseReviewFields change.botsautoPhaseReviewFields","form.botsauto-checklist .botsauto-item input:not(.botsauto-checkbox):not([type='button']):not([type='submit']):not([type='reset']), form.botsauto-checklist .botsauto-item select, form.botsauto-checklist .botsauto-item textarea").on("input.botsautoPhaseReviewFields change.botsautoPhaseReviewFields","form.botsauto-checklist .botsauto-item input:not(.botsauto-checkbox):not([type='button']):not([type='submit']):not([type='reset']), form.botsauto-checklist .botsauto-item select, form.botsauto-checklist .botsauto-item textarea",function(){at(e(this).closest(".botsauto-item")),nt()}),Bt(),nt();const Ut=new Set;function Lt(){var t=window.botsauto||{},e=function(){var t=document.querySelector("form.botsauto-checklist");if(!t||!t.querySelector)return null;var e=!!t.querySelector('input[name="_botsauto_nonce"]'),o=!!t.querySelector('input[name="action"][value="botsauto_save"]');return e&&o?t:null}(),o=parseInt(t.submission_id||t.botsauto_submission_id||0,10)||0;if(o<=0&&e){var a=e.querySelector('input[name="post_id"]');a&&(o=parseInt(a.value||0,10)||0)}var n=String(t.draftToken||t.draft_token||"").trim();if(!n&&e){var i=e.querySelector('input[name="draft_token"], input[name="botsauto_draft_token"]');i&&"string"==typeof i.value&&(n=String(i.value).trim())}var r=String(t.instanceToken||t.instance_token||"").trim();if(!r&&e){var s=e.querySelector('input[name="instance_token"]');s&&"string"==typeof s.value&&(r=String(s.value).trim())}return{submissionId:o,draftToken:n,instanceToken:r,hasRequestAccessToken:!(!n&&!r),canUseCookieBackedAccess:!!t.server_persist_allowed}}function Pt(t){if(i)return!1;var e=t||Lt();return!!(e&&e.submissionId>0&&(e.hasRequestAccessToken||e.canUseCookieBackedAccess))}function Dt(t,o){var a=o||Lt(),n=e.extend({},t||{}),i=a&&a.submissionId?a.submissionId:0;return i>0&&(n.checklist_id=i,n.submission_id=i,n.post_id=i),a&&a.draftToken&&(n.draft_token=a.draftToken),a&&a.instanceToken&&(n.instance_token=a.instanceToken),n}function Vt(t,e,o){var a=o||{},n=void 0!==a.responseJSON?a.responseJSON:t&&t.responseJSON?t.responseJSON:null;if(!n&&t&&t.responseText)try{n=JSON.parse(t.responseText)}catch(t){n=null}var i=n&&"object"==typeof n&&n.data?n.data:null,r=parseInt(void 0!==a.status?a.status:t&&t.status,10)||0,s=n&&"boolean"==typeof n.success?n.success:null,u=String(a.errorCode||i&&(i.error_code||i.code)||n&&n.error_code||"").toLowerCase().trim(),d=String(a.serverMessage||i&&i.message||n&&n.message||"").trim(),c=String(a.textStatus||"").toLowerCase(),l=String(a.action||"unknown").trim(),p=String(e||"Er is een fout opgetreden.").trim(),b="network_error"===u||0===r;"timeout"!==c&&"abort"!==c&&"error"!==c||(b=b||0===r);var m="";return b?m="Netwerkfout. Controleer uw verbinding en probeer opnieuw.":"invalid_nonce"===u||"nonce_invalid"===u||"nonce_missing"===u?m="Je sessiebeveiliging is verlopen. Vernieuw de pagina en probeer opnieuw.":"access_denied"===u||"submission_access_denied"===u||"token_mismatch"===u||"unauthorized_instance"===u||"password_not_authenticated"===u?m="Je hebt geen toegang tot deze actie. Vernieuw de pagina, log opnieuw in of voer je wachtwoord opnieuw in.":"missing_submission_context"===u?m="De checklistcontext ontbreekt. Vernieuw de pagina en probeer opnieuw.":"item_not_found"===u?m="Het gekozen checklist-item is niet gevonden. Vernieuw de pagina of neem contact op met de beheerder.":"invalid_item"===u||"invalid_item_id"===u?m="Dit checklist-item is ongeldig. Vernieuw de pagina of neem contact op met de beheerder.":"session_expired"===u?m="Je sessie is verlopen. Vernieuw de pagina en log opnieuw in.":"verification_required"===u?m="Verificatie is vereist. Log opnieuw in of voer je wachtwoord opnieuw in.":d?m=d:404===r?m="Het gevraagde item is niet gevonden. Vernieuw de pagina of neem contact op met de beheerder.":403===r?m="Je hebt geen toegang tot deze actie. Vernieuw de pagina, log opnieuw in of voer je wachtwoord opnieuw in.":400===r&&(m="Controleer de ingevulde gegevens en probeer opnieuw."),{success:s,status:r,errorCode:u,message:m||p,networkError:b,action:l}}function zt(t,e,o){return Vt(t,e,o).message}function Mt(t){t&&!t.networkError&&window.console&&console.error&&console.error("BOTSAUTO: AJAX serverfout",{status:t.status||0,error_code:t.errorCode||"",action:t.action||"unknown"})}window.botsautoGetSubmissionContext=Lt,window.botsautoHasServerPersistableSubmission=Pt,window.botsautoAppendSubmissionAccessPayload=Dt,e(document).off("change.botsauto",".botsauto-checkbox").on("change.botsauto",".botsauto-checkbox",function(t){var o=e(this),a=o.closest(".botsauto-item"),n=a.data("item-id");if("nvt"!==(a.attr("data-state")||"active")){if(!Ut.has(n)){var i=!o.prop("checked"),r=a.hasClass("has-attention"),s=r&&a.attr("data-attention-reason")||"",u=o.prop("checked")?1:0,d=o.prop("checked")?"checked":"active";U(a,d),o.prop("checked")?ot(a,{skipSummary:!0}):at(a),Bt(),nt();var c=Lt();if(Pt(c)){if(n){Ut.add(n);var l=function(t,o){var a=Dt({action:window.botsauto&&window.botsauto.action||"botsauto_toggle_item",_ajax_nonce:t,item_id:n,new_state:u},c);e.post(window.botsauto&&window.botsauto.ajax_url||"",a).done(function(t){if(t&&t.success&&t.data&&t.data.saved)t.data.version&&C(t.data.version);else{var a=t&&t.data&&t.data.error_code?t.data.error_code:"",n=t&&t.data&&t.data.message?t.data.message:"";if(!o&&("nonce_invalid"===a||"nonce_missing"===a||t&&"Invalid nonce"===t.data)){var i=Dt({action:"botsauto_refresh_toggle_item_nonce"},c);e.post(window.botsauto&&window.botsauto.ajax_url||"",i).done(function(t){var e=t&&t.data?t.data:null,o=e&&e.nonce?e.nonce:"",a=e&&e.action?e.action:"",n=e&&e.code?e.code:"";t&&t.success&&o&&(!a||"botsauto_toggle_item"===a)?(window.botsauto.nonce=o,l(o,!0)):(Mt(Vt({status:403,responseJSON:t},"Aanvinken mislukt. Probeer opnieuw.",{action:"botsauto_refresh_toggle_item_nonce",errorCode:n})),b(),alert(zt({status:403,responseJSON:t},"Aanvinken mislukt. Probeer opnieuw.",{action:"botsauto_refresh_toggle_item_nonce",errorCode:n})))}).fail(function(t){Mt(Vt(t,"Aanvinken mislukt. Probeer opnieuw.",{action:"botsauto_refresh_toggle_item_nonce"})),b(),alert(zt(t,"Aanvinken mislukt. Probeer opnieuw.",{action:"botsauto_refresh_toggle_item_nonce"}))})}else{Mt(Vt({responseJSON:t},"Aanvinken mislukt. Probeer opnieuw.",{action:window.botsauto&&window.botsauto.action||"botsauto_toggle_item",errorCode:a,serverMessage:n})),b(),alert(zt({responseJSON:t},"Aanvinken mislukt. Probeer opnieuw.",{action:window.botsauto&&window.botsauto.action||"botsauto_toggle_item",errorCode:a,serverMessage:n}))}}}).fail(function(t,e,o){Mt(Vt(t,"Aanvinken mislukt. Probeer opnieuw.",{action:window.botsauto&&window.botsauto.action||"botsauto_toggle_item",textStatus:e})),b(),alert(zt(t,"Aanvinken mislukt. Probeer opnieuw.",{action:window.botsauto&&window.botsauto.action||"botsauto_toggle_item",textStatus:e}))}).always(function(){Ut.delete(n)})},p=window.botsauto.nonce||"";if(p)l(p,!1);else Mt(Vt(null,"Aanvinken mislukt. Probeer opnieuw.",{action:"botsauto_toggle_item",errorCode:"invalid_nonce",status:400})),b(),Ut.delete(n),alert(zt(null,"Aanvinken mislukt. Probeer opnieuw.",{action:"botsauto_toggle_item",errorCode:"invalid_nonce",status:400}))}}else Bt(),nt()}}else Bt();function b(){o.prop("checked",i),U(a,i?"checked":"active"),!i&&r&&s?et(a,s,{skipSummary:!0}):at(a),Bt(),nt()}}),s.change++,e(document).off("change.botsauto",'input[name="completed"]').on("change.botsauto",'input[name="completed"]',Bt),s.change++,e(document).off("ajaxComplete.botsauto").on("ajaxComplete.botsauto",function(){o("BOTSAUTO: AJAX complete, updating progress"),Bt()}),s.ajaxComplete++;var Ft=document.querySelector('[data-botsauto-role="checklist-root"]')||document.getElementById("botsauto-checklist-root")||document.querySelector(".botsauto-checklist")||document.querySelector(".botsauto-wrapper")||document.querySelector(".botsauto-container")||document.body;window.__botsautoObserverTarget__=Ft,n=Ft;try{let t=function(){Kt||(Kt=!0,requestAnimationFrame(function(){Kt=!1,o("BOTSAUTO: MutationObserver triggered progress update"),h(Ft),Bt()}))};var Kt=!1;Ft&&(window.__botsautoObserver__&&window.__botsautoObserver__.disconnect(),window.__botsautoObserver__=new MutationObserver(function(e){e.some(function(t){return"childList"===t.type&&t.addedNodes.length>0})&&t()}),window.__botsautoObserver__.observe(Ft,{childList:!0,subtree:!0}),u=!0,o("BOTSAUTO: MutationObserver active on target:",Ft))}catch(t){a("BOTSAUTO: MutationObserver setup failed:",t)}e(document).off("click.botsauto",".botsauto-nvt-toggle").on("click.botsauto",".botsauto-nvt-toggle",function(){var t=e(this).closest(".botsauto-item");if(t.length){var o=t.data("item-id");if(!o||""===o||"undefined"===o||"null"===o)return console.error("BOTSAUTO: Invalid item_key for NVT toggle",{itemKey:o,li:t}),void alert("NVT toggle mislukt: Ongeldig item identificatie (missing item_key)");var a=t.attr("data-state")||"active",n="nvt"===a,r=n?"clear":"nvt",s=Lt(),u=(s.submissionId,Pt(s)),d=!u;n?(M(t),at(t)):(z(t),U(t,"nvt"),ot(t,{skipSummary:!0}));var c=e("#botsauto-nvt-state");if(c.length){var l=c.val()?c.val().split(",").filter(function(t){return t&&""!==t&&"undefined"!==t&&"null"!==t}):[];o=String(o),"nvt"===r?-1===l.indexOf(o)&&l.push(o):l=l.filter(function(t){return t!==o}),c.val(l.join(",")),l.join(",")}if(d&&"undefined"!=typeof Storage)try{var p="botsauto_nvt_presave_"+(window.location.pathname+window.location.search),b=c.length?c.val():"";localStorage.setItem(p,b)}catch(t){}if(u&&!i){let a=function(){"nvt"===r?M(t):U(t,"nvt");var a=e("#botsauto-nvt-state");if(a.length){var n=a.val()?a.val().split(",").filter(function(t){return t&&""!==t&&"undefined"!==t&&"null"!==t}):[];"nvt"===r?n=n.filter(function(t){return t!==String(o)}):-1===n.indexOf(String(o))&&n.push(String(o)),a.val(n.join(","))}},n=function(t,i){var u=Dt({action:"botsauto_toggle_nvt",item_key:o,new_state:r,nonce:t},s);e.post(window.botsauto&&window.botsauto.ajax_url||"",u).done(function(t){if(t&&t.success)t.data&&t.data.version&&C(t.data.version),t.data&&t.data.nvt_count,t.data&&t.data.debug&&window.console&&console.log&&t.data.debug;else{var o=t&&t.data&&t.data.error_code;if(i||"nonce_invalid"!==o&&"nonce_missing"!==o){Mt(Vt({responseJSON:t},"NVT toggle mislukt. Probeer opnieuw.",{action:"botsauto_toggle_nvt",errorCode:o,serverMessage:t&&t.data?t.data.message:""})),a(),alert(zt({responseJSON:t},"NVT toggle mislukt. Probeer opnieuw.",{action:"botsauto_toggle_nvt",errorCode:o,serverMessage:t&&t.data?t.data.message:""}))}else{var r=Dt({action:"botsauto_refresh_toggle_item_nonce"},s);e.post(window.botsauto&&window.botsauto.ajax_url||"",r).done(function(t){var e=t&&t.data?t.data:null,o=e&&e.nonce?e.nonce:"",i=e&&e.action?e.action:"",r=e&&e.code?e.code:"";t&&t.success&&o&&(!i||"botsauto_toggle_item"===i)?(window.botsauto.nonce=o,n(o,!0)):(Mt(Vt({status:403,responseJSON:t},"NVT toggle mislukt. Probeer opnieuw.",{action:"botsauto_refresh_toggle_item_nonce",errorCode:r})),a(),alert(zt({status:403,responseJSON:t},"NVT toggle mislukt. Probeer opnieuw.",{action:"botsauto_refresh_toggle_item_nonce",errorCode:r})))}).fail(function(t,e,o){Mt(Vt(t,"NVT toggle mislukt. Probeer opnieuw.",{action:"botsauto_refresh_toggle_item_nonce",textStatus:e})),a(),alert(zt(t,"NVT toggle mislukt. Probeer opnieuw.",{action:"botsauto_refresh_toggle_item_nonce",textStatus:e}))})}}}).fail(function(t,e,o){Mt(Vt(t,"NVT toggle mislukt. Probeer opnieuw.",{action:"botsauto_toggle_nvt",textStatus:e})),a(),alert(zt(t,"NVT toggle mislukt. Probeer opnieuw.",{action:"botsauto_toggle_nvt",textStatus:e}))})};var m=window.botsauto&&window.botsauto.nonce||"";if(!m||""===m){if(Mt(Vt(null,"NVT toggle mislukt. Probeer opnieuw.",{action:"botsauto_toggle_nvt",errorCode:"invalid_nonce",status:400})),alert(zt(null,"NVT toggle mislukt. Probeer opnieuw.",{action:"botsauto_toggle_nvt",errorCode:"invalid_nonce",status:400})),"nvt"===r?M(t):U(t,"nvt"),c.length){l=c.val()?c.val().split(",").filter(function(t){return t&&""!==t&&"undefined"!==t&&"null"!==t}):[];"nvt"===r?l=l.filter(function(t){return t!==String(o)}):-1===l.indexOf(String(o))&&l.push(String(o)),c.val(l.join(","))}return}n(m,!1)}Bt(),nt()}}),e(document).off("click.botsauto",".botsauto-open").on("click.botsauto",".botsauto-open",function(t){t.preventDefault();var o=e(this).data("target");e(o).show(),e("body").addClass("botsauto-modal-open")}),s.click++,e(document).off("click.botsauto",".botsauto-close").on("click.botsauto",".botsauto-close",function(){e(this).closest(".botsauto-modal").hide(),e("body").removeClass("botsauto-modal-open")}),s.click++,e(document).off("click.botsauto",".botsauto-modal").on("click.botsauto",".botsauto-modal",function(t){t.target===this&&(e(this).hide(),e("body").removeClass("botsauto-modal-open"))}),s.click++,i||e(".botsauto-modal.botsauto-auto-open").each(function(){e(this).show(),e("body").addClass("botsauto-modal-open")});var Rt="form.botsauto-checklist",Jt="data-botsauto-original-name",Ht="notes_payload_b64",Gt="textarea[name^='notes['], textarea["+Jt+"^='notes[']";function Wt(){window.botsautoStyle&&"1"===window.botsautoStyle.rich&&"undefined"!=typeof tinymce&&tinymce.triggerSave()}function $t(t){return null==t?"":String(t)}function Xt(t){var e=$t(t).trim();if(!e)return"";try{return JSON.stringify(JSON.parse(e))}catch(t){return e}}function Yt(t){var e=$t(t);return e?e.split(",").map(function(t){return $t(t).trim()}).filter(function(t){return""!==t}).sort().join(","):""}function Qt(t,e){for(var o=0;o<e.length;o++){var a=t.querySelector('[name="'+e[o]+'"]');if(a&&void 0!==a.value&&null!==a.value)return $t(a.value)}return""}function Zt(t){var e={};return t.querySelectorAll("input[name^='answers']").forEach(function(t){var o=t.name.match(/answers\[(.+)\]/);o&&(e[o[1]]=t.checked?"1":"")}),e}function te(t){var e={};return t.querySelectorAll("textarea[name^='notes']").forEach(function(t){var o=t.name.match(/notes\[(.+)\]/);o&&(e[o[1]]=$t(t.value))}),e}function ee(t){var e=$t(t);if("function"==typeof window.TextEncoder){for(var o=(new window.TextEncoder).encode(e),a="",n=0;n<o.length;n+=8192){var i=o.subarray(n,n+8192);a+=String.fromCharCode.apply(null,i)}return window.btoa(a)}return window.btoa(unescape(encodeURIComponent(e)))}function oe(t){var e=$t(t).trim();if(!e)return"";var o=window.atob(e);if("function"==typeof window.TextDecoder){for(var a=new Uint8Array(o.length),n=0;n<o.length;n++)a[n]=o.charCodeAt(n);return new window.TextDecoder("utf-8").decode(a)}return decodeURIComponent(escape(o))}function ae(t){t&&t.querySelectorAll&&t.querySelectorAll("textarea["+Jt+"]").forEach(function(t){var e=t.getAttribute(Jt);e&&t.setAttribute("name",e),t.removeAttribute(Jt)})}function ne(t){if(t&&t.querySelectorAll)try{var e={};t.querySelectorAll(Gt).forEach(function(t){var o=t.getAttribute("name")||t.getAttribute(Jt)||"",a=o.match(/^notes\[([^\]]+)\]$/);a&&(e[a[1]]=$t(t.value),!t.getAttribute(Jt)&&t.getAttribute("name")&&t.setAttribute(Jt,o),t.removeAttribute("name"))});var o=function(t){var e=t.querySelector('input[type="hidden"][name="'+Ht+'"]');return e||((e=document.createElement("input")).type="hidden",e.name=Ht,t.appendChild(e),e)}(t);o.value=ee(JSON.stringify(e)),window.BOTSAUTO_DEBUG&&window.console&&console.log}catch(e){throw ae(t),e}}function ie(t){var e={};return t&&"object"==typeof t?(Object.keys(t).forEach(function(o){e[o]=$t(t[o])}),e):e}function re(t){var e=t.querySelector("input[name=completed]"),o=Qt(t,["entry_title","title"]),a=Qt(t,["salesprofessional_name","name"]),n=Qt(t,["ba_email","email"]);return{entry_title:o,name:a,ba_email:n,email:n,customer_name:Qt(t,["customer_name"]),salesprofessional_name:Qt(t,["salesprofessional_name","name"]),ai_kansenscan:Qt(t,["ai_kansenscan"]),existing_customer:Qt(t,["existing_customer"]),customer_website:Qt(t,["customer_website"]),customer_country:Qt(t,["customer_country"]),salesorganization_name:Qt(t,["salesorganization_name"]),salesprofessional_role:Qt(t,["salesprofessional_role"]),salesorganization_website:Qt(t,["salesorganization_website"]),custom_submission_fields_json:Xt(Qt(t,["custom_submission_fields_json"])),nvt_state:Yt(Qt(t,["nvt_state"])),phase_completion_state:ht(Qt(t,["botsauto_phase_completion_state_b64"])),answers:Zt(t),notes:te(t),completed:e&&e.checked?"1":""}}function se(t,e){var o;for(o in t)if(Object.prototype.hasOwnProperty.call(t,o)&&$t(t[o])!==$t(e[o]))return!0;for(o in e)if(Object.prototype.hasOwnProperty.call(e,o)&&$t(e[o])!==$t(t[o]))return!0;return!1}function ue(t){Wt();var e=function(){var t=window.botsautoOrig;if(!t||"object"!=typeof t)return null;var e,o,a,n=$t(t.name||t.salesprofessional_name||""),i=$t(t.ba_email||t.email||"");return{entry_title:$t(t.entry_title||t.title||""),name:n,ba_email:i,email:$t(t.email||t.ba_email||""),customer_name:$t(t.customer_name||""),salesprofessional_name:$t(t.salesprofessional_name||t.name||""),ai_kansenscan:$t(t.ai_kansenscan||""),existing_customer:$t(t.existing_customer||""),customer_website:$t(t.customer_website||""),customer_country:$t(t.customer_country||""),salesorganization_name:$t(t.salesorganization_name||""),salesprofessional_role:$t(t.salesprofessional_role||""),salesorganization_website:$t(t.salesorganization_website||""),custom_submission_fields_json:Xt(t.custom_submission_fields_json||""),nvt_state:Yt(t.nvt_state||""),phase_completion_state:ht(t.phase_completion_state||"{}"),answers:(o=t.answers,a={},o&&"object"==typeof o?(Object.keys(o).forEach(function(t){a[t]=o[t]?"1":""}),a):a),notes:ie(t.notes),completed:(e=t.completed,"1"===e||1===e||!0===e?"1":"")}}();if(!e)return!!t.querySelector("input[name=post_id]");for(var o=re(t),a=["entry_title","name","ba_email","email","customer_name","salesprofessional_name","ai_kansenscan","existing_customer","customer_website","customer_country","salesorganization_name","salesprofessional_role","salesorganization_website","custom_submission_fields_json","nvt_state","phase_completion_state","completed"],n=0;n<a.length;n++){var i=a[n];if($t(e[i])!==$t(o[i]))return!0}return!!se(e.answers||{},o.answers||{})||!!se(e.notes||{},o.notes||{})}function de(t,o){(function(t){var o,a,n=t.find('.botsauto-submit-row button[type="submit"], .botsauto-submit-row input[type="submit"], button[type="submit"], input[type="submit"]'),i=(o=t[0],(a=o&&o.closest?o.closest("[data-botsauto-instance]"):null)?a.getAttribute("data-botsauto-instance"):"");if(i){var r=e(".botsauto-docked-bar[data-botsauto-instance]").filter(function(){return this.getAttribute("data-botsauto-instance")===i}).find(".ba-docked-save");n=n.add(r)}return n})(e(t)).each(function(){!function(t,e){if(t&&t.length){if(e)return t.data("botsauto-save-busy-active")||(t.data("botsauto-save-original-text",t.is("input")?t.val():t.text()),t.data("botsauto-save-original-disabled",!!t.prop("disabled")),t.data("botsauto-save-original-aria-busy",t.attr("aria-busy")),t.data("botsauto-save-busy-active",!0)),t.prop("disabled",!0).attr("aria-busy","true"),void(t.is("input")?t.val("Opslaan..."):t.text("Opslaan..."));if(t.data("botsauto-save-busy-active")){var o=t.data("botsauto-save-original-text")||"Opslaan",a=!!t.data("botsauto-save-original-disabled"),n=t.data("botsauto-save-original-aria-busy");t.prop("disabled",a),void 0===n?t.removeAttr("aria-busy"):t.attr("aria-busy",n),t.is("input")?t.val(o):t.text(o),t.removeData("botsauto-save-busy-active").removeData("botsauto-save-original-text").removeData("botsauto-save-original-disabled").removeData("botsauto-save-original-aria-busy")}}}(e(this),o)})}function ce(t){var e=function(t){var e=window.botsautoEmailVerification;if(!e||!1===e.enabled||"0"===e.enabled||0===e.enabled)return null;var o=e.greenfield||e.controller||null;if(!o)return null;if("function"==typeof o.getForm){var a=o.getForm();if(a&&a!==t)return null}else if(o.$form&&o.$form.length&&o.$form[0]!==t)return null;return o}(t);if(!e)return!0;if("function"==typeof e.canSubmit&&!e.canSubmit()){if(o("[BOTSAUTO SAVE] email verification blocked"),"function"==typeof e.showRequiredError)e.showRequiredError();else if("function"==typeof e.showError){var a=window.botsautoEmailVerification||{},n=a.i18n&&a.i18n.emailVerificationRequired?a.i18n.emailVerificationRequired:"E-mail verificatie vereist";e.showError(n)}var i=t.querySelector('[data-botsauto-email="canonical"], input[name="ba_email"]');return i&&"function"==typeof i.focus&&i.focus(),!1}return"function"==typeof e.updateFormHiddenFields&&e.updateFormHiddenFields(),!0}function le(t,a){var n=e(t);ae(t),de(t,!1),n.data("botsautoSubmitting",!1),n.data("botsautoAjaxSaving",!1),o("[BOTSAUTO SAVE] save lock released",a||"")}function pe(t){o("[BOTSAUTO SAVE] native submit started");var e=window.HTMLFormElement&&window.HTMLFormElement.prototype?window.HTMLFormElement.prototype.submit:null;"function"!=typeof e?t.submit():e.call(t)}function be(t,o,a){var n="error"===a?"error":"success",i=e("#botsauto-form-notices");i.length||(i=e(t).find("[data-botsauto-flash-root]").first()),i.length||(i=e("<div>",{id:"botsauto-form-notices",class:"botsauto-flash-slot","data-botsauto-flash-root":"true"}).prependTo(e(t))),i.attr("data-botsauto-flash-root","true").addClass("botsauto-flash-slot").show(),i.find("[data-botsauto-flash-message]").remove();var r=window.botsauto&&parseInt(window.botsauto.notification_timeout,10);(!r||r<1e3)&&(r=5e3),r>12e4&&(r=12e4);var s=window.botsauto&&parseInt(window.botsauto.notification_fade_duration,10);(isNaN(s)||s<0)&&(s=400),s>1e4&&(s=1e4);var u=i.find("[data-botsauto-flash-announcer]");u.length||(u=e("<span>",{class:"screen-reader-text","aria-live":"error"===n?"assertive":"polite","aria-atomic":"true","data-botsauto-flash-announcer":"true"}).appendTo(i));var d="botsauto-flash-"+(Date.now?Date.now():(new Date).getTime()).toString(36)+"-"+Math.random().toString(36).slice(2,10),c=e("<div>",{id:d,class:"botsauto-notice botsauto-notice-"+n,role:"error"===n?"alert":"status","aria-live":"error"===n?"assertive":"polite","aria-atomic":"true",tabindex:0,"data-botsauto-flash-message":"true","data-botsauto-flash-type":n,"data-botsauto-flash-timeout":r,"data-botsauto-flash-fade":s,"data-botsauto-flash-query":"","data-botsauto-flash-source":"runtime"}).text(o);u.length?c.insertBefore(u):i.append(c)}function me(t,e){var a=new FormData(t);a.set("ajax_submit","1"),a.set("action",a.get("action")||"botsauto_save");var n=t.getAttribute("action")||window.location.href,i=t.querySelector('input[name="ba_email"]');return i&&i.value.trim()&&!a.has("ba_email")&&a.append("ba_email",i.value.trim()),o("[BOTSAUTO SAVE] ajax save started"),fetch(n,{method:"POST",body:a,credentials:"same-origin",headers:{Accept:"application/json","X-Requested-With":"XMLHttpRequest"}}).then(function(t){return t.text().then(function(e){var o=null;try{o=e?JSON.parse(e):null}catch(t){throw new Error("Onverwachte serverreactie bij opslaan.")}if(!t.ok||!o||!o.success){var a=Vt({status:t.status,responseJSON:o},"Er is een fout opgetreden bij het opslaan.",{action:"botsauto_save"});Mt(a);var n=new Error(zt({status:t.status,responseJSON:o},"Er is een fout opgetreden bij het opslaan.",{action:"botsauto_save"}));throw n.botsautoErrorDetails=a,n}return o})}).then(function(e){var a=e.data||{};a&&a.post_id&&syncSubmissionContext(a);var n=a.message||"Checklist opgeslagen.";return be(t,n,"success"),function(t){window.botsautoOrig=re(t)}(t),a.version&&"function"==typeof window.botsautoUpdateVersion&&window.botsautoUpdateVersion(a.version),o("[BOTSAUTO SAVE] ajax save completed"),e}).catch(function(e){var o=e&&e.botsautoErrorDetails?e.botsautoErrorDetails:Vt(null,e&&e.message?e.message:"Er is een fout opgetreden bij het opslaan.",{action:"botsauto_save",errorCode:"network_error",status:0});throw e&&e.botsautoErrorDetails||Mt(o),be(t,zt(null,o.message,{action:o.action||"botsauto_save",errorCode:o.errorCode||"",status:o.status||0,responseJSON:o.responseJSON||null}),"error"),e})}function fe(t){var e=null==t?"":String(t);return e?e.length<=10?e.charAt(0)+"…("+e.length+")":e.slice(0,6)+"…"+e.slice(-4)+"("+e.length+")":""}function ge(t,e){if(!t)return"";try{return new URL(t,window.location.origin).searchParams.get(e)||""}catch(t){return""}}function he(t){t&&t.length&&t.each(function(){var t=e(this);if(!t.data("botsautoBaseStyleCached")){var o=t.attr("data-base-style"),a=void 0!==o?o:t.attr("style")||"";t.data("botsautoBaseStyle",a||""),t.data("botsautoBaseStyleCached",!0)}})}function ve(t){return he(t),t.data("botsautoBaseStyle")||""}function we(t){t&&t.length&&t.each(function(){var t=e(this),o=ve(t);o?t.attr("style",o):t.removeAttr("style")})}function _e(t,e){var o=function(t){var e={};return t?(t.split(";").forEach(function(t){var o=t.trim();if(o){var a=o.indexOf(":");if(-1!==a){var n=o.slice(0,a).trim().toLowerCase(),i=o.slice(a+1).trim();n&&(e[n]=i)}}}),e):e}(t);return Object.keys(e).forEach(function(t){var a=t.toLowerCase(),n=e[t];null==n||""===n?delete o[a]:o[a]=n}),function(t){var e=[];return Object.keys(t).forEach(function(o){var a=t[o];null!=a&&""!==a&&e.push(o+":"+a)}),e.length?e.join("; ")+";":""}(o)}function ye(t){he(t),t.find("*").not("input, button, select, textarea").each(function(){he(e(this))})}function ke(t,o){if(t&&t.length){var a=t.data("selected-bg"),n=t.data("selected-border"),i=t.data("selected-text"),r=t.find(".botsauto-csv-import-mode-option");if(r.each(function(){ye(e(this))}),r.each(function(){var t=e(this);we(t),function(t){we(t.find("*").not("input, button, select, textarea"))}(t),t.removeClass("botsauto-import-mode-selected")}),o&&o.length)if(ye(o),o.addClass("botsauto-import-mode-selected"),function(t,e,o){var a={};e&&(a["background-color"]=e+" !important"),o&&(a["border-color"]=o+" !important");var n=_e(ve(t),a);n?t.attr("style",n):t.removeAttr("style")}(o,a,n),i)!function(t,o){o&&t.each(function(){var t=e(this),a=_e(ve(t),{color:o+" !important"});a?t.attr("style",a):t.removeAttr("style")})}(o.find("*").not("input, button, select, textarea"),i);!function(t,o){var a=t.closest(".botsauto-csv-import-row");a.length||(a=t.parent());var n=a.find(".botsauto-csv-file-label").first(),i=a.find(".botsauto-csv-file-name").first();he(n),he(i),we(n),we(i),o&&n.add(i).each(function(){var t=e(this);if(t.length){var a=_e(ve(t),{color:o+" !important"});a?t.attr("style",a):t.removeAttr("style")}})}(t,i)}}function Se(t,o,a,n,i){var r=e('input[name="botsauto-csv-import-mode-'+t+'"]:checked'),s=r.val(),u=e("#botsauto-csv-import-mode-error-"+t);if(!s||!r.length){var d="Selecteer een importmodus.";return u.text(d).show(),u.closest(".botsauto-csv-import-mode-selection").scrollIntoView({behavior:"smooth",block:"nearest"}),!1}u.hide().text("");if(-1===["same_instance","clone","map_merge"].indexOf(s)){d="Ongeldige importmodus geselecteerd. Selecteer een geldige importmodus.";return u.text(d).show(),u.closest(".botsauto-csv-import-mode-selection").scrollIntoView({behavior:"smooth",block:"nearest"}),!1}var c=e("#botsauto-csv-create-missing-"+t).is(":checked"),l=e("#botsauto-csv-replace-all-"+t).is(":checked");if(!i&&l&&!confirm("Alles vervangen: Dit zal Status en Notitie voor ALLE items in deze checklist overschrijven.\n\nWeet je zeker dat je wilt doorgaan?"))return!1;var p=new FormData;return p.append("action","botsauto_user_import_csv"),p.append("post_id",t),p.append("nonce",o),p.append("instance_access_token",a),p.append("import_mode",s),p.append("create_missing",c?"1":"0"),p.append("replace_all",l?"1":"0"),p.append("preview",i?"1":"0"),p.append("csv_file",n),p}function xe(){try{var t={scrollY:window.scrollY||window.pageYOffset||0,importMode:null,createMissing:null,replaceAll:null,timestamp:Date.now()};return e('input[type="radio"][name^="botsauto-csv-import-mode-"]:checked').each(function(){var o=e(this).attr("name").replace("botsauto-csv-import-mode-","");t.importMode=e(this).val(),t.postId=o;var a=e("#botsauto-csv-import-options-"+o);a.length&&(t.createMissing=a.find('input[name="create_missing-'+o+'"]').is(":checked"),t.replaceAll=a.find('input[name="replace_all-'+o+'"]').is(":checked"))}),sessionStorage.setItem("botsautoUiState",JSON.stringify(t)),!0}catch(t){return!1}}function Ae(){try{var t=new URL(window.location);t.searchParams.delete("importSuccess"),t.searchParams.delete("p"),t.searchParams.delete("u"),t.searchParams.delete("c"),t.searchParams.delete("s"),window.history.replaceState({},"",t)}catch(t){if(window.history&&window.history.replaceState){var e=window.location.pathname+window.location.hash;window.history.replaceState({},"",e)}}}e(document).off("submit.botsautoSave",Rt).on("submit.botsautoSave",Rt,async function(t){if(i)t.preventDefault();else{var n=e(this);if(function(t){return!!(t&&t.length&&t.hasClass("botsauto-checklist")&&t.find('input[name="_botsauto_nonce"]').length&&t.find('input[name="action"][value="botsauto_save"]').length&&t.find('input[name="checklist_id"]').length)}(n)){var r=this;if(t.preventDefault(),n.data("botsautoSubmitting"))o("[BOTSAUTO SAVE] ignored duplicate submit");else{n.data("botsautoSubmitting",!0),de(r,!0),o("[BOTSAUTO SAVE] save submit started");try{if(Wt(),!function(t){var e=t.querySelector("input[name=entry_title]"),o=t.querySelector("input[name=customer_name]"),a=t.querySelector("input[name=ba_email]")||t.querySelector("input[name=email]"),n=e?e.value.trim():"",i=o?o.value.trim():"",r=a?a.value.trim():"",s=/^[^@\s]+@[^@\s]+\.[^@\s]+$/.test(r);return n?i?!!s||(alert("Voer een geldig e-mailadres in."),!1):(alert("Vul de klantnaam in."),!1):(alert("Vul een titel in."),!1)}(r)||!function(t){if(i)return!1;if("undefined"!=typeof Storage)try{var n="botsauto_nvt_presave_"+(window.location.pathname+window.location.search);localStorage.removeItem(n),localStorage.removeItem(G()),o("BOTSAUTO: Cleared pre-save NVT localStorage on form submission")}catch(t){a("BOTSAUTO: Could not clear pre-save localStorage on submit:",t)}var r=t.find('input[name="completed"]');if(!r.length||!r.is(":checked"))return!0;var s=t.find(".botsauto-item").filter(function(){var t=e(this);return"nvt"!==(t.attr("data-state")||"active")&&!t.find(".botsauto-checkbox").prop("checked")});if(s.length){if(!window.confirm("Er zijn nog steeds items op de checklist die niet zijn afgevinkt. Weet je zeker dat je de checklist wilt voltooien? Niet-afgevinkte items worden dan automatisch ingesteld op 'Niet van toepassing'."))return r.prop("checked",!1),!1;var u=t.find("#botsauto-nvt-state");if(u.length){var d=u.val()?u.val().split(",").filter(function(t){return t&&""!==t&&"undefined"!==t&&"null"!==t}):[],c=J();s.each(function(){var t=e(this).data("item-id");t&&""!==t&&"undefined"!==t&&"null"!==t?(t=String(t),-1===d.indexOf(t)&&d.push(t),Object.prototype.hasOwnProperty.call(c,t)&&(delete c[t],ot(e(this),{skipSummary:!0}))):console.error("BOTSAUTO: Invalid item ID for auto-NVT",{id:t})}),u.val(d.join(",")),H(c),o("BOTSAUTO: Auto-marked unanswered as NVT:",d.join(","))}}return!0}(n))return void le(r,"validation-blocked");if(!ce(r))return void le(r,"email-verification-blocked");await function(t){var e=t.querySelector('input[name="g-recaptcha-response"]');if(!e)return Promise.resolve(!0);var a=e.getAttribute("data-botsauto-recaptcha-site-key")||window.botsauto&&window.botsauto.recaptcha_site_key||"",n=e.getAttribute("data-botsauto-recaptcha-action")||"botsauto_submit";return a?window.grecaptcha&&"function"==typeof window.grecaptcha.ready&&"function"==typeof window.grecaptcha.execute?(o("[BOTSAUTO SAVE] recaptcha token requested"),new Promise(function(t,i){window.grecaptcha.ready(function(){window.grecaptcha.execute(a,{action:n}).then(function(a){a?(e.value=a,e.setAttribute("data-botsauto-recaptcha-issued-at",String(Date.now?Date.now():(new Date).getTime())),o("[BOTSAUTO SAVE] recaptcha token received"),t(!0)):i(new Error("reCAPTCHA gaf geen geldig token terug."))},function(t){i(t||new Error("reCAPTCHA-token ophalen is mislukt."))})})})):Promise.reject(new Error("reCAPTCHA kon niet worden geladen. Probeer het opnieuw.")):Promise.reject(new Error("reCAPTCHA is niet correct geconfigureerd."))}(r),function(t){var e=t.querySelector("input[name=send_pdf]");if(e){var o=!t.querySelector("input[name=post_id]"),a=t.querySelector("input[name=completed]"),n=a&&a.checked?"1":"";o||"1"===n?e.value="1":ue(t)?e.value=window.confirm("Wilt u de nieuwe PDF per e-mail ontvangen?")?"1":"0":"1"!==e.value&&(e.value="0")}}(r),ne(r),await De(r)}catch(t){return a("[BOTSAUTO SAVE] save failed during preparation",t),be(r,t&&t.message?t.message:"Er is een fout opgetreden bij het voorbereiden van de opslag.","error"),void le(r,"preparation-failed")}var s=function(t){var e=t.querySelector("input[name=post_id]"),o=t.querySelector("input[name=send_pdf]"),a=t.querySelector("input[name=completed]"),n=!!(e&&parseInt(e.value,10)>0),i=!(!o||"1"!==o.value),r=!(!a||!a.checked);return n&&!i&&!r&&"function"==typeof window.fetch&&"function"==typeof window.FormData}(r);if(s){n.data("botsautoAjaxSaving",!0);try{await me(r)}catch(t){a("[BOTSAUTO SAVE] ajax save failed",t)}finally{le(r,"ajax-save-complete")}}else try{pe(r)}catch(t){a("[BOTSAUTO SAVE] native submit failed",t),be(r,"Er is een fout opgetreden bij het verzenden van de checklist.","error"),le(r,"native-submit-failed")}}}}}),e(document).off("click.botsauto",".botsauto-info-btn").on("click.botsauto",".botsauto-info-btn",function(){var t=e(this).data("info");if(t&&t.video){var o='<iframe width="'+(t.videoWidth||560)+'" height="'+(t.videoHeight||315)+'" src="'+t.video+'" frameborder="0" allowfullscreen></iframe>';e(this).closest(".botsauto-info").next(".botsauto-info-content").html(o);var a=document.querySelector(".botsauto-modal-content");a&&(a.style.height=a.scrollHeight+"px")}}),s.click++,e(document).off("click.botsauto touchstart.botsauto",".botsauto-video-thumb-wrap").on("click.botsauto touchstart.botsauto",".botsauto-video-thumb-wrap",function(t){t.preventDefault();var o=e(this);if(!o.data("botsauto-loaded")){o.data("botsauto-loaded",!0);var a=o.data("embed");if(a){var n=atob(a);o.closest(".botsauto-video").find(".botsauto-video-embed").replaceWith(n),o.remove()}}}),s.click++,e(".botsauto-video-thumb-wrap img").each(function(){var t=this,o=function(){!function(t){var o=e(t),a=o.closest(".botsauto-video-inner");if(a.length){var n=a.width(),i=a.height();t.naturalWidth&&t.naturalHeight&&(t.naturalWidth<n||t.naturalHeight<i)?o.addClass("botsauto-thumb-contain"):o.removeClass("botsauto-thumb-contain")}}(t)};t.complete?o():e(t).one("load",o),e(window).on("resize",o)}),e(document).off("click.botsauto",".botsauto-csv-export-btn").on("click.botsauto",".botsauto-csv-export-btn",function(t){if(t.preventDefault(),!i){var o=e(this),a=o.data("post-id"),n=o.data("nonce"),r=o.data("instance-access-token");if(a&&n&&r){var s=o.text();o.prop("disabled",!0).text("Exporteren..."),e.ajax({url:window.botsauto&&window.botsauto.ajax_url||"",type:"POST",data:{action:"botsauto_user_export_csv",post_id:a,nonce:n,instance_access_token:r},success:function(t){if(t.success&&t.data.csv_content){var e=new Blob([t.data.csv_content],{type:"text/csv;charset=utf-8;"}),o=window.URL.createObjectURL(e),a=document.createElement("a");a.href=o,a.download=t.data.filename||"botsauto-checklist.csv",document.body.appendChild(a),a.click(),document.body.removeChild(a),window.URL.revokeObjectURL(o),alert("CSV-export succesvol gedownload!")}else{var n="Onbekende fout";t.data&&("string"==typeof t.data?n=t.data:t.data.message&&(n=t.data.message)),alert("CSV-exportfout: "+n)}},error:function(t,e,o){var a=o||"Verbindingsfout";if(t.responseText)try{var n=JSON.parse(t.responseText);n.data&&n.data.message&&(a=n.data.message)}catch(t){}alert("CSV-exportfout: "+a)},complete:function(){o.prop("disabled",!1).text(s)}})}else alert("Fout: Kan CSV-export niet uitvoeren. Ontbrekende gegevens. Vernieuw de pagina en probeer opnieuw.")}}),s.click++,e(document).off("change.botsauto",'input[type="radio"][name^="botsauto-csv-import-mode-"]').on("change.botsauto",'input[type="radio"][name^="botsauto-csv-import-mode-"]',function(t){var o=e(this).attr("name").replace("botsauto-csv-import-mode-",""),a=e(this).val(),n=e("#botsauto-csv-import-options-"+o),i=e("#botsauto-csv-create-missing-label-"+o),r=e("#botsauto-csv-import-mode-error-"+o);ke(e(this).closest(".botsauto-csv-import-mode-selection"),e(this).closest(".botsauto-csv-import-mode-option")),r.hide().text(""),"clone"===a||"map_merge"===a?(n.show(),"map_merge"===a?i.show():(i.hide(),e("#botsauto-csv-create-missing-"+o).prop("checked",!1))):(n.hide(),i.hide(),e("#botsauto-csv-create-missing-"+o).prop("checked",!1))}),s.change++,e(document).ready(function(){e(".botsauto-csv-import-mode-option").each(function(){var t=e(this),o=t.find('input[type="radio"][name^="botsauto-csv-import-mode-"]');if(o.length){var a=o.attr("name").replace("botsauto-csv-import-mode-","");t.attr("data-post-id",a)}}),e(".botsauto-csv-import-mode-selection").each(function(){var t=e(this),o=t.find('input[type="radio"]:checked').closest(".botsauto-csv-import-mode-option");o.length||(o=t.find(".botsauto-csv-import-mode-option").first()),o.length&&ke(t,o)})}),e(document).off("change.botsauto",'input[type="file"][id^="botsauto-csv-file-input-"]').on("change.botsauto",'input[type="file"][id^="botsauto-csv-file-input-"]',function(t){var o=this,a=e(o).data("post-id")||e(o).attr("id").replace("botsauto-csv-file-input-",""),n=e('.botsauto-csv-import-btn[data-post-id="'+a+'"]'),i=e('.botsauto-csv-preview-btn[data-post-id="'+a+'"]'),r=e("#botsauto-csv-file-name-"+a);if(!o.files||0===o.files.length)return n.prop("disabled",!0),i.prop("disabled",!0),void r.text("Geen bestand gekozen");var s=o.files[0];return s.name.toLowerCase().endsWith(".csv")||["text/csv","application/csv","text/plain","application/vnd.ms-excel"].includes(s.type)?s.size>5242880?(alert("Fout: Bestand is te groot. Maximum grootte is 5MB."),o.value="",n.prop("disabled",!0),i.prop("disabled",!0),void r.text("Geen bestand gekozen")):(r.text(s.name),n.prop("disabled",!1),void i.prop("disabled",!1)):(alert("Fout: Alleen CSV-bestanden zijn toegestaan."),o.value="",n.prop("disabled",!0),i.prop("disabled",!0),void r.text("Geen bestand gekozen"))}),s.change++,e('input[type="file"][id^="botsauto-csv-file-input-"]').each(function(){var t=this,o=e(t).data("post-id")||e(t).attr("id").replace("botsauto-csv-file-input-",""),a=e('.botsauto-csv-import-btn[data-post-id="'+o+'"]'),n=e('.botsauto-csv-preview-btn[data-post-id="'+o+'"]'),i=e("#botsauto-csv-file-name-"+o);if(t.files&&t.files.length>0){var r=t.files[0];i.text(r.name),a.prop("disabled",!1),n.prop("disabled",!1)}else a.prop("disabled",!0),n.prop("disabled",!0),""===i.text().trim()&&i.text("Geen bestand gekozen")}),e(document).off("click.botsauto",".botsauto-csv-preview-btn").on("click.botsauto",".botsauto-csv-preview-btn",function(t){if(t.preventDefault(),t.stopPropagation(),!i){var o=e(this),a=o.data("post-id"),n=o.data("nonce"),r=o.data("instance-access-token")||e("#botsauto-csv-file-input-"+a).data("instance-access-token");if(a&&n&&r){var s=e("#botsauto-csv-file-input-"+a);if(0!==s.length&&s[0].files&&0!==s[0].files.length){var u=s[0].files[0];if(!(u.name.toLowerCase().endsWith(".csv")||["text/csv","application/csv","text/plain","application/vnd.ms-excel"].includes(u.type))||u.size>5242880)alert("Fout: Ongeldig bestandstype of bestand is te groot.");else{var d=o.text();o.prop("disabled",!0).text("Voorbeeld genereren...");var c=Se(a,n,r,u,!0);c?e.ajax({url:window.botsauto&&window.botsauto.ajax_url||"",type:"POST",data:c,processData:!1,contentType:!1,success:function(t){t.success&&t.data?function(t,o){e(".botsauto-csv-preview-summary").remove();var a='<div class="botsauto-csv-preview-summary" style="margin: 1em 0; padding: 1em; background-color: #e8f4f8; border: 1px solid #0073aa; border-radius: 4px; color: #0073aa;">';if(a+='<h4 style="margin-top: 0; color: #0073aa;">Import voorvertoning resultaten</h4>',t.import_mode){var n={same_instance:"Zelfde checklist (Strikt)",clone:"Van andere checklist – Kopiëren",map_merge:"Van andere checklist – Samenvoegen"}[t.import_mode]||t.import_mode;a+='<p style="margin-bottom: 0.75em; font-size: 0.95em; color: #0073aa;">',a+="<strong>Importmodus:</strong> "+n,t.create_missing&&"map_merge"===t.import_mode&&(a+=' <span style="color: #666;">(met Ontbrekende items aanmaken)</span>'),t.replace_all&&(a+=' <span style="color: #dc3545;">(Alles vervangen ingeschakeld)</span>'),a+="</p>"}a+='<p style="font-size: 1.1em; color: #0073aa;">',a+="<strong>CSV rijen:</strong> "+(t.processed||0)+" • ",a+="<strong>Zou bijwerken:</strong> "+(t.would_update||0)+" • ",a+="<strong>Zou aanmaken:</strong> "+(t.would_create||0)+" • ",a+="<strong>Zou overslaan:</strong> "+(t.would_skip||0),t.ambiguous&&t.ambiguous>0&&(a+=' • <strong style="color: #dc3545;">Dubbelzinnig:</strong> '+t.ambiguous);a+="</p>",t.warnings&&t.warnings.length>0&&(a+='<div style="margin-top: 1em; padding: 0.75em; background-color: #fff3cd; border-left: 4px solid #ffc107; color: #856404; border-radius: 3px;">',a+='<strong>Sommige rijen zouden worden overgeslagen:</strong><ul style="margin: 0.5em 0 0 1.5em;">',t.warnings.slice(0,10).forEach(function(t){a+="<li>Rij "+t.row+": "+t.reason+(t.item?" ("+t.item+")":"")+"</li>"}),t.warnings.length>10&&(a+="<li>... en nog "+(t.warnings.length-10)+" waarschuwingen</li>"),a+="</ul></div>");a+='<p style="margin-top: 0.75em; font-size: 0.9em; color: #666;">',a+='Dit is een voorvertoning. Er zijn nog geen wijzigingen doorgevoerd. Klik op "Importeren" om door te gaan.',a+="</p>",a+='<button type="button" class="botsauto-csv-preview-close" ',a+='style="margin-top: 0.75em; padding: 0.5em 1em; background-color: #2271b1; color: white; border: none; border-radius: 3px; cursor: pointer;">',a+="Sluiten",a+="</button>",a+="</div>";var i=e('.botsauto-csv-import-section[data-post-id="'+o+'"]');0===i.length&&(i=e(".botsauto-csv-import-section").first());i.length>0&&i.after(a);var r=e(".botsauto-csv-preview-summary");r.length>0&&r[0].scrollIntoView({behavior:"smooth",block:"nearest"});e(document).off("click.botsauto",".botsauto-csv-preview-close").on("click.botsauto",".botsauto-csv-preview-close",function(t){t.preventDefault(),e(this).closest(".botsauto-csv-preview-summary").fadeOut(300,function(){e(this).remove()})})}(t.data,a):(Mt(Vt({status:400,responseJSON:t},"Onbekende fout bij voorvertoning.",{action:"botsauto_user_import_csv_preview"})),alert("Voorbeeldfout: "+zt({status:400,responseJSON:t},"Onbekende fout bij voorvertoning.",{action:"botsauto_user_import_csv_preview"})))},error:function(t,e,o){Mt(Vt(t,"Voorbeeld ophalen mislukt.",{action:"botsauto_user_import_csv_preview",textStatus:e})),alert("Voorbeeldfout: "+zt(t,"Voorbeeld ophalen mislukt.",{action:"botsauto_user_import_csv_preview",textStatus:e}))},complete:function(){o.prop("disabled",!1).text(d)}}):o.prop("disabled",!1).text(d)}}else alert("Fout: Selecteer eerst een CSV-bestand.")}else alert("Fout: Kan CSV-voorbeeld niet uitvoeren. Ontbrekende gegevens. Vernieuw de pagina en probeer opnieuw.")}}),s.click++,e(document).off("click.botsauto",".botsauto-csv-import-btn").on("click.botsauto",".botsauto-csv-import-btn",function(t){if(t.preventDefault(),t.stopPropagation(),!i){var o=e(this),a=o.data("post-id"),n=o.data("nonce"),r=o.data("instance-access-token")||e("#botsauto-csv-file-input-"+a).data("instance-access-token");if(a&&n&&r){var s=e("#botsauto-csv-file-input-"+a);if(0!==s.length&&s[0].files&&0!==s[0].files.length){var u=s[0].files[0];if(!(u.name.toLowerCase().endsWith(".csv")||["text/csv","application/csv","text/plain","application/vnd.ms-excel"].includes(u.type))||u.size>5242880)alert("Fout: Ongeldig bestand.");else{var d=o.text(),c=o.prop("disabled");o.prop("disabled",!0).text("Importeren...").attr("aria-busy","true"),o.off("keydown.botsauto-import").on("keydown.botsauto-import",function(t){if("Enter"===t.key||" "===t.key)return t.preventDefault(),t.stopPropagation(),!1});var l=Se(a,n,r,u,!1);if(!l)return o.prop("disabled",c).text(d).attr("aria-busy","false"),void o.off("keydown.botsauto-import");e.ajax({url:window.botsauto&&window.botsauto.ajax_url||"",type:"POST",data:l,processData:!1,contentType:!1,success:function(t){if(t.success&&t.data){var n=t.data;void 0===n.ok&&(n.ok=!0),s[0].value="",e("#botsauto-csv-file-name-"+a).text("Geen bestand gekozen"),function(t,o){e(".botsauto-csv-import-summary").remove();t.updated>0&&t.zero_updates;var a=t.zero_updates||t.warnings&&t.warnings.length>0,n=a?"#856404":"#0f5132",i='<div class="botsauto-csv-import-summary" style="margin: 1em 0; padding: 1em; background-color: '+(a?"#fff3cd":"#d1e7dd")+"; border: 1px solid "+(a?"#ffc107":"#badbcc")+"; border-radius: 4px; color: "+n+';">';t.compatibility_mode&&(i+='<div style="padding: 0.75em; margin-bottom: 1em; background-color: #fff3cd; border-left: 4px solid #ffc107; color: #856404; border-radius: 3px;">',i+="<strong>Compatibiliteitsmodus:</strong> ",i+="Your CSV was imported using fallback matching. For best results, export again with the new format (contains Checklist_ID and Item_ID).",i+="</div>");if(i+='<h4 style="margin-top: 0; color: '+n+';">Import voltooid</h4>',t.import_mode){var r={same_instance:"Zelfde checklist (Strikt)",clone:"Van andere checklist – Kopiëren",map_merge:"Van andere checklist – Samenvoegen"}[t.import_mode]||t.import_mode;i+='<p style="margin-bottom: 0.75em; font-size: 0.95em; color: '+n+';">',i+="<strong>Importmodus:</strong> "+r,t.create_missing&&"map_merge"===t.import_mode&&(i+=' <span style="color: '+n+'; opacity: 0.8;">(met Ontbrekende items aanmaken)</span>'),t.replace_all&&(i+=' <span style="color: #dc3545;">(Alles vervangen ingeschakeld)</span>'),i+="</p>"}if(t.zero_updates){i+='<div style="padding: 0.75em; margin: 1em 0; background-color: #fff3cd; border-left: 4px solid #ffc107; color: #856404; border-radius: 3px;">',i+="<strong>"+"Import voltooid, maar er zijn geen wijzigingen toegepast."+"</strong><br>",i+='<button type="button" class="botsauto-refresh-anyway-btn" data-post-id="'+o+'" ',i+='style="margin-top: 0.5em; padding: 0.5em 1em; background-color: #2271b1; color: white; border: none; border-radius: 3px; cursor: pointer;">',i+="Ververs toch",i+="</button>",i+="</div>"}i+='<p style="font-size: 1.1em; color: '+n+';">',i+="<strong>"+t.processed+"</strong> verwerkt • ",i+="<strong>"+t.updated+"</strong> bijgewerkt",t.created&&t.created>0&&(i+=" • <strong>"+t.created+"</strong> aangemaakt");i+=" • <strong>"+t.skipped+"</strong> overgeslagen",t.ambiguous&&t.ambiguous>0&&(i+=' • <strong style="color: #dc3545;">'+t.ambiguous+"</strong> dubbelzinnig");i+="</p>",t.warnings&&t.warnings.length>0?(i+='<div style="margin-top: 1em; padding: 0.75em; background-color: #fff3cd; border-left: 4px solid #ffc107; color: #856404; border-radius: 3px;">',i+='<strong>Sommige rijen konden niet worden geïmporteerd:</strong><ul style="margin: 0.5em 0 0 1.5em;">',t.warnings.slice(0,10).forEach(function(t){i+="<li>Rij "+t.row+": "+t.reason+(t.item?" ("+t.item+")":"")+"</li>"}),t.warnings.length>10&&(i+="<li>... en nog "+(t.warnings.length-10)+" waarschuwingen</li>"),i+="</ul></div>",t.error_report&&(i+='<p style="margin-top: 0.75em;">',i+='<a href="#" class="botsauto-download-error-report" ',i+='data-report="'+t.error_report+'" ',i+='data-filename="foutrapport-'+o+"-"+(new Date).getTime()+'.csv" ',i+='style="text-decoration: underline; color: '+n+'; font-weight: bold;">',i+="Download foutrapport (CSV)",i+="</a>",i+="</p>")):t.zero_updates||(i+='<p style="margin-top: 0.5em; color: '+n+'; font-weight: bold;">✓ Alle rijen succesvol geïmporteerd</p>');i+='<button type="button" class="botsauto-csv-summary-close" ',i+='style="margin-top: 0.75em; padding: 0.5em 1em; background-color: #2271b1; color: white; border: none; border-radius: 3px; cursor: pointer;">',i+="Sluiten",i+="</button>",i+="</div>";var s=e('.botsauto-csv-import-section[data-post-id="'+o+'"]');0===s.length&&(s=e(".botsauto-csv-import-section").first());if(s.length>0)s.after(i);else{var u=e('.botsauto-csv-import-row[data-post-id="'+o+'"]');0===u.length&&(u=e(".botsauto-csv-import-row").first()),u.after(i)}var d=e(".botsauto-csv-import-summary");d.length>0&&d[0].scrollIntoView({behavior:"smooth",block:"nearest"});!t.zero_updates&&!0===t.ok&&(t.updated>0||t.created>0)&&setTimeout(function(){!function(t,e,o){var a=!1,n="";!0===t.ok?t.updated>0||t.created>0?(a=!0,n="success"):0===t.updated&&0===t.created&&(n="no_changes"):n="error";if(a){xe();var i=new URL(window.location);if(i.searchParams.set("importSuccess","1"),i.searchParams.set("p",t.processed||"0"),i.searchParams.set("u",t.updated||"0"),i.searchParams.set("c",t.created||"0"),i.searchParams.set("s",t.skipped||"0"),o||(o=!0),o){var r=i.toString()+"&r="+Date.now();window.location.replace(r)}}}(t,0,!0)},1500)}(n,a),o.prop("disabled",!0)}else{var i="Onbekende fout";t.data&&("string"==typeof t.data?i=t.data:t.data.message&&(i=t.data.message));var r='<div class="botsauto-import-error-banner" role="alert" aria-live="assertive" aria-atomic="true" tabindex="-1" style="position: fixed; top: 0; left: 0; right: 0; background-color: #f8d7da; border-bottom: 2px solid #dc3545; color: #721c24; padding: 1em; z-index: 10000; box-shadow: 0 2px 4px rgba(0,0,0,0.1); outline: none;">';r+='<div style="max-width: 1200px; margin: 0 auto; display: flex; justify-content: space-between; align-items: center;">',r+="<div><strong>Import mislukt:</strong> "+i+". Probeer het opnieuw of ververs de pagina.</div>",r+="<div>",r+='<button type="button" class="botsauto-error-try-again" style="margin-right: 0.5em; padding: 0.5em 1em; background-color: #2271b1; color: white; border: none; border-radius: 3px; cursor: pointer;">Probeer opnieuw</button>',r+='<button type="button" class="botsauto-error-refresh-page" style="padding: 0.5em 1em; background-color: #6c757d; color: white; border: none; border-radius: 3px; cursor: pointer;">Ververs pagina</button>',r+='<button type="button" class="botsauto-banner-close" style="margin-left: 0.5em; background: none; border: none; color: #721c24; font-size: 1.2em; cursor: pointer; padding: 0 0.5em;">&times;</button>',r+="</div>",r+="</div>",r+="</div>",e("body").prepend(r),e(".botsauto-error-try-again").on("click",function(){e(".botsauto-import-error-banner").remove(),o.click()}),e(".botsauto-error-refresh-page").on("click",function(){window.location.reload()}),e(".botsauto-import-error-banner .botsauto-banner-close").on("click",function(){e(".botsauto-import-error-banner").fadeOut(300,function(){e(this).remove()})})}},error:function(t,a,n){var i="Verbindingsfout";if(403===t.status||401===t.status)i="Token verlopen of onvoldoende rechten. Ververs de pagina.";else if(t.responseText)try{var r=JSON.parse(t.responseText);r.data&&r.data.message?i=r.data.message:r.data&&"string"==typeof r.data&&(i=r.data)}catch(t){}var s='<div class="botsauto-import-error-banner" role="alert" aria-live="assertive" aria-atomic="true" tabindex="-1" style="position: fixed; top: 0; left: 0; right: 0; background-color: #f8d7da; border-bottom: 2px solid #dc3545; color: #721c24; padding: 1em; z-index: 10000; box-shadow: 0 2px 4px rgba(0,0,0,0.1); outline: none;">';s+='<div style="max-width: 1200px; margin: 0 auto; display: flex; justify-content: space-between; align-items: center;">',s+="<div><strong>Import mislukt:</strong> "+i+". Probeer het opnieuw of ververs de pagina.</div>",s+="<div>",s+='<button type="button" class="botsauto-error-try-again" style="margin-right: 0.5em; padding: 0.5em 1em; background-color: #2271b1; color: white; border: none; border-radius: 3px; cursor: pointer;">Probeer opnieuw</button>',s+='<button type="button" class="botsauto-error-refresh-page" style="padding: 0.5em 1em; background-color: #6c757d; color: white; border: none; border-radius: 3px; cursor: pointer;">Ververs pagina</button>',s+='<button type="button" class="botsauto-banner-close" style="margin-left: 0.5em; background: none; border: none; color: #721c24; font-size: 1.2em; cursor: pointer; padding: 0 0.5em;">&times;</button>',s+="</div>",s+="</div>",s+="</div>",e("body").prepend(s),setTimeout(function(){e(".botsauto-import-error-banner").focus()},100),e(".botsauto-error-try-again").on("click",function(){e(".botsauto-import-error-banner").remove(),o.click()}),e(".botsauto-error-refresh-page").on("click",function(){window.location.reload()}),e(".botsauto-import-error-banner .botsauto-banner-close").on("click",function(){e(".botsauto-import-error-banner").fadeOut(300,function(){e(this).remove()})}),e(document).on("keydown.botsauto-error-banner",function(t){"Escape"===t.key&&e(".botsauto-import-error-banner").length&&(e(".botsauto-import-error-banner").fadeOut(300,function(){e(this).remove()}),e(document).off("keydown.botsauto-error-banner"))})},complete:function(){o.prop("disabled",!(s[0].files&&s[0].files.length>0)).text(d).attr("aria-busy","false"),o.off("keydown.botsauto-import")}})}}else alert("Fout: Selecteer eerst een CSV-bestand.")}else alert("Fout: Kan CSV-import niet uitvoeren. Ontbrekende gegevens. Vernieuw de pagina en probeer opnieuw.")}}),s.click++,e(document).off("click.botsauto",".botsauto-csv-template-btn").on("click.botsauto",".botsauto-csv-template-btn",function(t){if(t.preventDefault(),t.stopPropagation(),!i){var n=e(this),r=parseInt(n.data("post-id"),10)||0;if(r){var s=function(t){var e=(t.attr("href")||"").toString();return{postId:t.data("post-id")||0,href:e,hrefAction:ge(e,"action"),hrefNonce:fe(ge(e,"nonce")),hrefToken:fe(ge(e,"instance_access_token")),domNonce:fe(t.data("nonce")),domToken:fe(t.data("instance-access-token"))}}(n);o("BOTSAUTO CSV TEMPLATE: first-click context before refresh",s);var u=n.text();n.attr("aria-busy","true").css("pointer-events","none").text("Template voorbereiden..."),function(t){var o=window.botsauto&&window.botsauto.ajax_url||window.botsauto&&window.botsauto.ajaxUrl||"";if(!o)return e.Deferred().reject({reason:"missing_ajax_url"}).promise();var a="";return window.botsauto&&window.botsauto.draft_token?a=window.botsauto.draft_token:window.botsauto&&window.botsauto.draftToken&&(a=window.botsauto.draftToken),e.ajax({url:o,type:"POST",dataType:"json",data:{action:"botsauto_user_csv_context",post_id:t,draft_token:a}}).then(function(t){return t&&t.success&&t.data&&t.data.download_url?t.data:e.Deferred().reject({reason:"invalid_response",response:t||null}).promise()})}(r).done(function(t){var a=function(t,o){var a='[data-post-id="'+t+'"]',n=o.nonce||"",i=o.instance_access_token||"",r=o.download_url||"";return e(".botsauto-csv-preview-btn"+a+", .botsauto-csv-import-btn"+a+", .botsauto-csv-template-btn"+a+", #botsauto-csv-file-input-"+t).attr("data-nonce",n).attr("data-instance-access-token",i).data("nonce",n).data("instance-access-token",i),e(".botsauto-csv-template-btn"+a).attr("href",r),{nonce:n,instance_access_token:i,download_url:r,expires_at:o.expires_at||0,issued_at:o.issued_at||0}}(r,t);o("BOTSAUTO CSV TEMPLATE: refreshed context for download",{postId:r,before:s,after:{downloadUrl:a.download_url,nonce:fe(a.nonce),token:fe(a.instance_access_token),expiresAt:a.expires_at,issuedAt:a.issued_at}}),window.location.assign(a.download_url)}).fail(function(t){a("BOTSAUTO CSV TEMPLATE: context refresh failed",{postId:r,before:s,error:t||null}),alert("Template downloaden mislukt: de downloadcontext kon niet worden ververst. Vernieuw de pagina en probeer opnieuw.")}).always(function(){n.attr("aria-busy","false").css("pointer-events","").text(u)})}else alert("Fout: Ongeldige checklistcontext voor template-download.")}}),s.click++,e(document).ready(function(){!function(){try{var t=new URLSearchParams(window.location.search);if("1"===t.get("importSuccess")){var o=t.get("p")||"0",a=t.get("u")||"0",n=t.get("c")||"0",i=t.get("s")||"0",r='<div class="botsauto-import-success-banner" role="alert" aria-live="polite" style="position: fixed; top: 0; left: 0; right: 0; background-color: #d1e7dd; border-bottom: 2px solid #badbcc; color: #0f5132; padding: 1em; z-index: 10000; box-shadow: 0 2px 4px rgba(0,0,0,0.1);">';r+='<div style="max-width: 1200px; margin: 0 auto; display: flex; justify-content: space-between; align-items: center;">',r+='<div style="font-weight: bold;">',r+="Import voltooid: "+o+" verwerkt • "+a+" bijgewerkt • "+n+" aangemaakt • "+i+" overgeslagen.",r+="</div>",r+='<button type="button" class="botsauto-banner-close" style="background: none; border: none; color: #0f5132; font-size: 1.2em; cursor: pointer; padding: 0 0.5em;">&times;</button>',r+="</div>",r+="</div>",e("body").prepend(r),setTimeout(function(){e(".botsauto-import-success-banner").fadeOut(300,function(){e(this).remove(),Ae()})},5e3),e(document).on("click",".botsauto-banner-close",function(){e(this).closest(".botsauto-import-success-banner").fadeOut(300,function(){e(this).remove(),Ae()})}),setTimeout(function(){var t=e(".botsauto-import-success-banner");t.attr("tabindex","-1"),t.focus();var r=e("<div>",{role:"status","aria-live":"polite","aria-atomic":"true",class:"screen-reader-text",style:"position: absolute; left: -9999px; width: 1px; height: 1px; overflow: hidden;",text:"Import voltooid: "+o+" verwerkt, "+a+" bijgewerkt, "+n+" aangemaakt, "+i+" overgeslagen."});e("body").append(r),setTimeout(function(){r.remove()},1e3)},100)}}catch(t){}}(),function(){try{var t=sessionStorage.getItem("botsautoUiState");if(!t)return!1;var o=JSON.parse(t);if(!o||!o.timestamp)return!1;if(o.scrollY&&o.scrollY>0&&setTimeout(function(){window.scrollTo(0,o.scrollY)},100),o.postId&&o.importMode){var a=e('input[name="botsauto-csv-import-mode-'+o.postId+'"][value="'+o.importMode+'"]');if(a.length){if(a.prop("checked",!0).trigger("change"),null!==o.createMissing){var n=e("#botsauto-csv-import-options-"+o.postId+' input[name="create_missing-'+o.postId+'"]');n.length&&n.prop("checked",o.createMissing)}if(null!==o.replaceAll){var i=e("#botsauto-csv-import-options-"+o.postId+' input[name="replace_all-'+o.postId+'"]');i.length&&i.prop("checked",o.replaceAll)}}}return sessionStorage.removeItem("botsautoUiState"),!0}catch(t){return!1}}()}),e(document).off("click.botsauto",".botsauto-download-error-report").on("click.botsauto",".botsauto-download-error-report",function(t){t.preventDefault();var o=e(this),a=o.data("report"),n=o.data("filename")||"error-report.csv";if(a){for(var i=atob(a),r=new Uint8Array(i.length),s=0;s<i.length;s++)r[s]=i.charCodeAt(s);var u=new Blob([r],{type:"text/csv;charset=utf-8;"}),d=window.URL.createObjectURL(u),c=document.createElement("a");c.href=d,c.download=n,document.body.appendChild(c),c.click(),document.body.removeChild(c),window.URL.revokeObjectURL(d)}}),s.click++,e(document).off("click.botsauto",".botsauto-csv-summary-close").on("click.botsauto",".botsauto-csv-summary-close",function(t){t.preventDefault(),e(this).closest(".botsauto-csv-import-summary").fadeOut(300,function(){e(this).remove()})}),s.click++,e(document).off("click.botsauto",".botsauto-refresh-anyway-btn").on("click.botsauto",".botsauto-refresh-anyway-btn",function(t){t.preventDefault();e(this).data("post-id");xe();var o=new URL(window.location);o.searchParams.set("importSuccess","1"),o.searchParams.set("p","0"),o.searchParams.set("u","0"),o.searchParams.set("c","0"),o.searchParams.set("s","0");var a=o.toString()+"&r="+Date.now();window.location.replace(a)}),s.click++,function(){if(!window.__botsautoFlashInit){window.__botsautoFlashInit=!0,window.__botsautoNotifDismissInit=!0;var t="[data-botsauto-flash-root]",e="[data-botsauto-flash-message]",o="[data-botsauto-flash-announcer]",a=["botsauto_msg","botsauto_err"],n="undefined"!=typeof WeakMap,i="undefined"!=typeof WeakSet,r=n?new WeakMap:new Map,s=n?new WeakMap:new Map,u=i?new WeakSet:new Set,d=window.botsauto||{},c=m(d.notification_timeout,5e3),l=f(d.notification_fade_duration,400);if(C(document),x(document),"function"==typeof MutationObserver){var p=document.body||document.documentElement;if(p)new MutationObserver(function(o){for(var a=0;a<o.length;a++)if("childList"===o[a].type)for(var n=v(o[a].addedNodes),i=0;i<n.length;i++){var r=n[i];if(1===r.nodeType){if(g(r,t))O(r);else if(r.querySelector)for(var s=v(r.querySelectorAll(t)),u=0;u<s.length;u++)O(s[u]);if(g(r,e)||r.querySelector&&r.querySelector(e)){var d=h(r,t);d?T(d):S(r,null)}}}}).observe(p,{childList:!0,subtree:!0})}else setInterval(function(){C(document)},2e3);window.botsautoRemoveDuplicateMessages=function(t){x(t||document)}}function b(t){if("number"==typeof t)return t;if("string"==typeof t&&""!==t.trim()){var e=parseInt(t,10);if(isFinite(e))return e}return NaN}function m(t,e){var o=isFinite(e)?e:5e3,a=b(t);return isFinite(a)?a<1e3?o:a>12e4?12e4:a:o}function f(t,e){var o=isFinite(e)?e:400,a=b(t);return isFinite(a)?a<0?0:a>1e4?1e4:a:o}function g(t,e){if(!t||1!==t.nodeType)return!1;var o=t.matches||t.matchesSelector||t.msMatchesSelector||t.webkitMatchesSelector;return!!o&&o.call(t,e)}function h(t,e){if(!t||1!==t.nodeType)return null;if("function"==typeof t.closest)return t.closest(e);for(var o=t;o&&1===o.nodeType;){if(g(o,e))return o;o=o.parentElement}return null}function v(t){return t?Array.prototype.slice.call(t):[]}function w(t){if(!t)return{defaultTimeout:c,defaultFade:l,announcer:document.querySelector(o)||null,scanScheduled:!1,observer:null,poller:null};var e=s.get(t);if(e)return e;var a=t.dataset||{},n={defaultTimeout:m(a.botsautoFlashDefaultTimeout,c),defaultFade:f(a.botsautoFlashFade,l),announcer:t.querySelector(o)||null,scanScheduled:!1,observer:null,poller:null};return s.set(t,n),n}function _(t){var e=r.get(t);e&&!e.dismissed&&(e.timerId&&(clearTimeout(e.timerId),e.timerId=null),e.remaining<=0?k(t):(e.paused=!1,e.startedAt=Date.now?Date.now():(new Date).getTime(),e.timerId=setTimeout(function(){e.timerId=null,e.remaining=0,k(t)},e.remaining)))}function y(t){t&&("function"==typeof t.remove?t.remove():t.parentNode&&t.parentNode.removeChild(t))}function k(e){var n=r.get(e);if(n&&!n.dismissed){n.dismissed=!0,n.timerId&&(clearTimeout(n.timerId),n.timerId=null),n.remaining=0,!function(t,e){var a=w(t).announcer||document.querySelector(o);if(a){var n,i=e&&"error"===e.getAttribute("data-botsauto-flash-type")?"error":"success",r=d.flash||{};n="error"===i&&r.dismissed_error?r.dismissed_error:"success"===i&&r.dismissed_success?r.dismissed_success:r.dismissed?r.dismissed:"error"===i?"Foutmelding gesloten.":"Melding gesloten.",a.textContent="",setTimeout(function(){a.textContent=n},50)}}(n.root||h(e,t),e),function(t){if("undefined"!=typeof history&&"function"==typeof history.replaceState){var e=a.slice();t&&-1===e.indexOf(t)&&e.push(t);var o=window.location.href;try{for(var n=new URL(o,window.location.origin),i=!1,r=0;r<e.length;r++)n.searchParams.has(e[r])&&(n.searchParams.delete(e[r]),i=!0);if(i){var s=n.pathname+(n.searchParams.toString()?"?"+n.searchParams.toString():"")+n.hash;history.replaceState(null,document.title,s)}}catch(t){var u=window.location.search;if(!u)return;for(var d=u.substring(1).split("&"),c=[],l=!1,p=0;p<d.length;p++)if(d[p]){var b=d[p].split("=")[0];e.indexOf(decodeURIComponent(b))>-1?l=!0:c.push(d[p])}if(l){var m=c.length?"?"+c.join("&"):"",f=window.location.pathname+m+window.location.hash;history.replaceState(null,document.title,f)}}}}(n.queryParam);var i="function"==typeof window.matchMedia&&window.matchMedia("(prefers-reduced-motion: reduce)").matches,s=f(e.getAttribute("data-botsauto-flash-fade"),n.fade);i||0===s?y(e):(e.setAttribute("aria-hidden","true"),e.style.transition="opacity "+s/1e3+"s ease-out",e.style.opacity="0",setTimeout(function(){y(e)},s))}}function S(t,e){if(t&&!r.has(t)){var o=w(e),a=m(t.getAttribute("data-botsauto-flash-timeout"),o.defaultTimeout),n={timeout:a,remaining:a,timerId:null,startedAt:null,paused:!1,dismissed:!1,fade:f(t.getAttribute("data-botsauto-flash-fade"),o.defaultFade),queryParam:t.getAttribute("data-botsauto-flash-query")||"",root:e};r.set(t,n),t.setAttribute("data-botsauto-flash-bound","true"),t.hasAttribute("tabindex")||t.setAttribute("tabindex","0");var i=function(){!function(t){var e=r.get(t);if(e&&!e.dismissed&&!e.paused){if(e.timerId&&(clearTimeout(e.timerId),e.timerId=null),e.startedAt){var o=(Date.now?Date.now():(new Date).getTime())-e.startedAt;e.remaining=Math.max(0,e.remaining-o)}e.paused=!0}}(t)},s=function(){!function(t){var e=r.get(t);e&&!e.dismissed&&(e.timerId||(e.remaining<=0?k(t):_(t)))}(t)};t.addEventListener("mouseenter",i),t.addEventListener("mouseleave",s),t.addEventListener("pointerenter",i),t.addEventListener("pointerleave",s),t.addEventListener("focusin",i),t.addEventListener("focusout",function(e){e&&t.contains(e.relatedTarget)||s()}),t.addEventListener("keydown",function(e){if(e){var o=e.key||e.keyCode;"Escape"!==o&&"Esc"!==o&&27!==o||(e.preventDefault(),k(t))}});var u=t.querySelector("[data-botsauto-flash-dismiss]");u&&u.addEventListener("click",function(e){e.preventDefault(),k(t)}),_(t)}}function x(t){var o=t||document,a=v(o.querySelectorAll(e));a.length||(a=[]);for(var n=Object.create(null),i=0;i<a.length;i++){var r=a[i],s=(r.getAttribute("data-botsauto-flash-type")||"")+"|"+(r.textContent||"").trim();n[s]?y(r):n[s]=!0}var u=v(o.querySelectorAll(".botsauto-protected-container[data-botsauto-msg]"));if(u.length)for(var d=Object.create(null),c=0;c<u.length;c++){var l=u[c],p=(l.getAttribute("data-botsauto-msg")||"")+"|"+(l.getAttribute("data-post-id")||"");d[p]?y(l):d[p]=!0}}function A(t){if(t){x(t);var o=v(t.querySelectorAll(e));if(o.length)for(var a=0;a<o.length;a++)S(o[a],t)}}function T(t){var e,o=w(t);o.scanScheduled||(o.scanScheduled=!0,e=function(){o.scanScheduled=!1,A(t)},"function"==typeof window.requestAnimationFrame?window.requestAnimationFrame(e):setTimeout(e,16))}function O(t){if(t){var o=u.has?u.has(t):!0===t.__botsautoFlashInit;A(t),o||(u.add?u.add(t):t.__botsautoFlashInit=!0,function(t){if(t){var o=w(t);o.observer||o.poller||("function"==typeof MutationObserver?(o.observer=new MutationObserver(function(o){for(var a=!1,n=0;n<o.length;n++)if("childList"===o[n].type){for(var i=v(o[n].addedNodes),r=0;r<i.length;r++){var s=i[r];if(1===s.nodeType){if(g(s,e)){a=!0;break}if(s.querySelector&&s.querySelector(e)){a=!0;break}}}if(a)break}a&&T(t)}),o.observer.observe(t,{childList:!0,subtree:!0})):o.poller=setInterval(function(){A(t)},800))}}(t))}}function C(e){var o=v((e||document).querySelectorAll(t));if(o.length)for(var a=0;a<o.length;a++)O(o[a])}}(),l({window,document,$:e,eventHandlerCounts:s,state:{tooltipInitObserver:null}}),(()=>{const t=window.botsauto=window.botsauto||{},e=".botsauto-note-attachments .ba-note-file";let o=!1,a=null,n=0;function i(){n&&(window.clearTimeout(n),n=0)}function r(t,e,o){const a=function(t){let e=t.querySelector(".ba-upload-status");if(e)return e;e=document.createElement("div"),e.className="ba-upload-status",e.setAttribute("role","status"),e.setAttribute("aria-live","polite"),e.hidden=!0;const o=t.querySelector(".ba-attachments-list");return o&&o.parentNode?o.parentNode.insertBefore(e,o.nextSibling):t.appendChild(e),e}(t);if(i(),a.hidden=!1,a.className="ba-upload-status"+(o?" is-"+o:""),a.textContent="","loading"===o){const t=document.createElement("span");t.className="ba-upload-spinner",t.setAttribute("aria-hidden","true"),a.appendChild(t)}const n=document.createElement("span");n.textContent=e||"",a.appendChild(n)}function s(t,e){const o=t&&t.messages&&"object"==typeof t.messages?t.messages:{};return(o.upload||(1===e?"Upload voltooid":e+" documenten geupload."))+". "+(o.processing||"Verwerking wordt voorbereid")+". "+(o.ai_cache||"AI-cache wordt op de achtergrond opgebouwd")+"."}function u(t,e){const o=[];if(t&&o.push(t),e){const t=function(t){const e=String(t||"");return window.CSS&&"function"==typeof window.CSS.escape?window.CSS.escape(e):e.replace(/\\/g,"\\\\").replace(/"/g,'\\"')}(e);document.querySelectorAll(`.botsauto-note-attachments[data-item-hash="${t}"]`).forEach(t=>{-1===o.indexOf(t)&&o.push(t)})}const a=o.find(t=>function(t){if(!t||!t.isConnected)return!1;if(t.closest("[hidden]"))return!1;if("function"==typeof window.getComputedStyle){const e=window.getComputedStyle(t);if(e&&("none"===e.display||"hidden"===e.visibility))return!1}return t.getClientRects().length>0}(t))||o[0]||t||null,n=a?a.querySelector(".ba-attachments-list"):null;return!n&&window.console&&console.error&&console.error("BOTSAUTO Upload: Missing .ba-attachments-list for render target",{itemHash:e||"",hasPreferredWrap:!!t,hasResolvedWrap:!!a}),{wrap:a,list:n}}document.addEventListener("change",async d=>{var c,l,p;const b=d.target.closest(e);if(!b)return;const m=b.closest(".botsauto-note-attachments");if(!m)return;if(o)return;o=!0;let f=m;try{const e=Array.from(b.files||[]);if(!e.length)return;const o=m.dataset.itemHash;if(!o)throw new Error("Ontbrekende item identificatie.");let d=u(m,o);f=d.wrap||m;let g=d.list;b.disabled=!0,r(f,"Document uploaden...","loading");let h=f.dataset.postId||m.dataset.postId;if(!h||"0"===h){const e=await async function(){if(a)return a;const e=t.ajax_url||t.ajaxUrl||"",o=t.botsauto_nonce||"";if(!e||!o)throw new Error("Checklist kan niet automatisch worden voorbereid.");a=(async()=>{var a,n,i;const r=new FormData;r.append("action","botsauto_init_submission"),r.append("nonce",o);const s=t.draftToken||t.draft_token||"";s&&r.append("draft_token",s);const u=document.querySelector('#post_ID, input[name="post_id"]'),d=u&&parseInt(u.value,10)||0;d>0&&r.append("post_id",String(d));const c=await fetch(e,{method:"POST",body:r,credentials:"same-origin"});let l=null;try{l=await c.json()}catch(t){l=null}if(!c.ok||!(null==l?void 0:l.success)||!(null==(a=null==l?void 0:l.data)?void 0:a.post_id)){const t="Conceptchecklist aanmaken mislukt.",e=(null==(n=null==l?void 0:l.data)?void 0:n.message)||(null==(i=null==l?void 0:l.data)?void 0:i.detail)||t;throw new Error(e||t)}return l.data})();try{return await a}finally{a=null}}();if(function(e){const o=String(e&&e.post_id||"").trim();if(!o||"0"===o)return;const a=parseInt(o,10)||0,n=String(e&&e.draft_token||t.draftToken||t.draft_token||"").trim(),i=String(e&&e.instance_token||t.instanceToken||t.instance_token||"").trim(),r=String(e&&e.context_id||"").trim(),s=String(e&&e.botsauto_verification_session_id||"").trim();a>0&&(t.checklist_id=a,t.submission_id=a,t.botsauto_submission_id=a),n&&(t.draftToken=n,t.draft_token=n),i&&(t.instanceToken=i,t.instance_token=i),Oe&&a>0&&(Oe.submission_id=a),window.botsauto&&window.botsauto.session_data&&a>0&&(window.botsauto.session_data.submission_id=a),Array.from(document.querySelectorAll("form.botsauto-checklist")).forEach(t=>{if(!t||!t.querySelector)return;const e=(e,o)=>{if(""===o)return;let a=t.querySelector(`input[name="${e}"]`);a||(a=document.createElement("input"),a.type="hidden",a.name=e,t.appendChild(a)),a.value=o};e("post_id",o),e("botsauto_submission_id",o),e("draft_token",n),e("instance_token",i),e("context_id",r),e("botsauto_verification_session_id",s)}),document.querySelectorAll('input[name="post_id"], #post_ID').forEach(t=>{t&&"string"==typeof t.value&&(t.value=o)}),document.querySelectorAll(".botsauto-note-attachments").forEach(t=>{t.dataset.postId=o}),document.querySelectorAll("[data-post-id]").forEach(t=>{t.setAttribute("data-post-id",o),t.dataset&&(t.dataset.postId=o)})}(e),d=u(m,o),f=d.wrap||m,g=d.list,h=f.dataset.postId||m.dataset.postId,!h||"0"===h)throw new Error("Conceptchecklist kon niet worden voorbereid. Sla de checklist handmatig op en probeer opnieuw.")}const v=t.instanceToken||t.instance_token||"";if(!v)throw new Error("Beveiligingscontrole mislukt. Vernieuw de pagina en probeer opnieuw.");let w=0;for(const a of e){const e=new FormData;e.append("action","botsauto_upload_note_file"),e.append("nonce",t.upload_nonce||t.nonce||""),e.append("item_hash",o),e.append("file",a),e.append("post_id",h),e.append("instance_token",v),window.BOTSAUTO_DEBUG&&window.console&&console.log&&(a.name,a.size);const n=await fetch(t.ajax_url,{method:"POST",body:e,credentials:"same-origin"}),i=await n.json();if(window.BOTSAUTO_DEBUG&&window.console&&console.log,!(null==i?void 0:i.success)){const t=(null==(c=null==i?void 0:i.data)?void 0:c.message)||"upload_failed",e={nonce_invalid:"Beveiligingscontrole mislukt. Herlaad de pagina en probeer opnieuw.",missing_identifier:"Ontbrekende identificatie. Herlaad de pagina.",invalid_submission:"Ongeldige inzending.",quota_exceeded:"Je kunt maximaal 10 bestanden toevoegen per onderdeel.",file_too_large:"Bestand is te groot (max. 10 MB).",filetype_not_allowed:"Dit bestandstype is niet toegestaan. Toegestane types: PDF, PNG, JPG, JPEG, DOC, DOCX, XLS, XLSX, TXT.",upload_failed:"Upload mislukt. Probeer het opnieuw."},o=(null==(l=null==i?void 0:i.data)?void 0:l.detail)||e[t]||e.upload_failed;throw window.console&&console.error&&console.error("BOTSAUTO Upload: Upload failed",{errorCode:t,error:o,response:i}),new Error(o)}const b=i.data||{},_=b.attachment_id||b.id,y=b.display_name||b.filename||a.name||"",k=void 0!==b.filesize?b.filesize:b.size,S=document.createElement("li");S.className="ba-attachment-row",S.dataset.attachmentId=_,S.dataset.mode=b.mode||"post",S.dataset.itemHash=o,S.dataset.postId=h,S.dataset.filename=y;const x=b.view_url||b.url||"#",A=String(x).replace(/"/g,"&quot;"),T=String(y).replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;"),O=String(y).toLowerCase(),C=O.includes(".")?O.split(".").pop():"",j=!(!window.botsauto||!window.botsauto.m365_enabled),I=j&&["docx","xlsx","pptx"].includes(C)?'<button type="button" class="ba-edit-attachment">Bewerken</button>':"";if(S.innerHTML=`<div class="ba-attachment-main"><a href="${A}" target="_blank" rel="noopener" class="ba-attachment-link">${T}</a></div><div class="ba-attachment-actions">${I}<button type="button" class="ba-remove-attachment">Verwijderen</button></div>`,d=u(m,o),f=d.wrap||f||m,g=d.list||g,!g)throw new Error("Upload gelukt, maar de bijlagenlijst kon niet direct worden bijgewerkt. Vernieuw de pagina en probeer opnieuw.");g.appendChild(S);const E=f.closest(".botsauto-item");E&&(E.classList.add("has-note-attachments"),null==(p=window.BA_attachIndicator)||p.update(E));const q=new CustomEvent("botsauto:attachment:added",{detail:{itemHash:o,attachmentId:_,filename:y,display_name:b.display_name||y,url:b.url,view_url:b.view_url||b.url,download_url:b.download_url||b.url,size:k,filesize:k,mime:b.mime||b.type||"",type:b.type||b.mime||"",status:b.status||"uploaded",processing_status:b.processing_status||"background_queued",use_for_ai:b.use_for_ai,cache_status:b.cache_status||{},uploadTime:b.upload_time||(new Date).toISOString(),mode:b.mode||"post"}});document.dispatchEvent(q),w+=1,r(f,s(b,w),"success")}w>0&&(n=window.setTimeout(()=>{!function(t){const e=t.querySelector(".ba-upload-status");i(),e&&(e.hidden=!0,e.className="ba-upload-status",e.textContent="")}(f)},6e3))}catch(t){const e="Uploaden is niet gelukt.",o=t&&t.message?t.message:e;r(f,o,"error"),alert(o)}finally{b.value="",b.disabled=!1,o=!1}},{passive:!0}),document.addEventListener("click",t=>{const o=t.target.closest(".ba-file-label");if(!o)return;const a=o.nextElementSibling;a&&a.matches(e)&&(t.preventDefault(),a.disabled||a.click())})})(),document.addEventListener("click",t=>{const e=t.target.closest(".ba-edit-attachment");if(!e)return;const o=e.closest("li"),a=e.closest(".botsauto-note-attachments");if(!o||!a)return;const n=o.dataset.attachmentId||"",i=o.dataset.itemHash||a.dataset.itemHash||"",r=o.dataset.postId||a.dataset.postId||"",s=o.dataset.filename||(o.querySelector("a")?o.querySelector("a").textContent:"bestand");window.BOTSAUTOAttachmentEditor&&"function"==typeof window.BOTSAUTOAttachmentEditor.startMicrosoftEdit?window.BOTSAUTOAttachmentEditor.startMicrosoftEdit({fileId:n,itemHash:i,filename:s,postId:r,triggerButton:e}):alert("Bewerkfunctie is niet beschikbaar. Vernieuw de pagina en probeer opnieuw.")},{passive:!0}),document.addEventListener("click",async t=>{var e,o,a;const n=t.target.closest(".ba-remove-attachment");if(!n)return;const i=n.closest("li"),r=n.closest(".botsauto-note-attachments"),s=window.botsauto||{},u=null==r?void 0:r.dataset.itemHash,d=null==i?void 0:i.dataset.attachmentId,c=s.instanceToken||s.instance_token||"";if(!u||!d)return;const l=null==r?void 0:r.dataset.postId;if(!l||"0"===l)return;const p=new FormData;p.append("action","botsauto_delete_note_file"),p.append("nonce",s.upload_nonce||s.nonce||""),p.append("post_id",l),p.append("item_hash",u),p.append("attachment_id",d),p.append("instance_token",c);const b=await fetch(s.ajax_url,{method:"POST",body:p,credentials:"same-origin"}),m=await b.json();if(!(null==m?void 0:m.success))return void alert((null==(e=null==m?void 0:m.data)?void 0:e.message)||"Verwijderen is niet gelukt.");{i.remove();const t=new CustomEvent("botsauto:attachment:removed",{detail:{itemHash:u,attachmentId:d,mode:"post"}});document.dispatchEvent(t)}const f=r.querySelector(".ba-attachments-list"),g=r.closest(".botsauto-item");g&&(f&&0===f.children.length?(g.classList.remove("has-note-attachments"),null==(o=window.BA_attachIndicator)||o.cleanup(g)):null==(a=window.BA_attachIndicator)||a.update(g))},{passive:!0}),window.BA_attachIndicator={countAttachments(t){const e=t.querySelector(".botsauto-note-attachments");if(!e)return 0;const o=e.querySelector(".ba-attachments-list");return o?o.children.length:0},updateDataAttributes(t){const e=t.querySelector(".botsauto-answer-row");if(!e)return;if(!("on"===e.dataset.attachmentIndicator))return e.dataset.hasAttachments="false",void(e.dataset.attachmentCount&&delete e.dataset.attachmentCount);const o=this.countAttachments(t),a=o>0;e.dataset.hasAttachments=a?"true":"false",a?e.dataset.attachmentCount=String(o):e.dataset.attachmentCount&&delete e.dataset.attachmentCount},ensureIndicatorNode(t){var e,o;const a=t.querySelector(".botsauto-answer-row");if(!a)return;const n="on"===a.dataset.attachmentIndicator,i="true"===a.dataset.hasAttachments,r=a.querySelector(".botsauto-item-text");if(!r)return;const s=r.querySelector(".botsauto-item-text-inner");if(!s)return;let u=s.querySelector(".botsauto-attachment-indicator");if(n&&i){if(!u){u=document.createElement("span"),u.className="botsauto-attachment-indicator",u.setAttribute("aria-label","Bijlage(n)"),u.setAttribute("title","Bijlage(n) aanwezig");const t=document.createElement("i");t.className="ba-attach-indicator",t.setAttribute("aria-hidden","true"),u.appendChild(t);const o=(null==(e=window.botsauto)?void 0:e.baAttIndPos)||"after";a.dataset.attindPos=o,"before"===o?s.insertBefore(u,s.firstChild):s.appendChild(u)}const t=u.querySelector(".ba-attach-indicator");if(t){const e=((null==(o=window.botsauto)?void 0:o.baAttIndFaClass)||"fa-solid fa-paperclip").trim();t.className="ba-attach-indicator "+e}}else u&&u.remove()},update(t){this.updateDataAttributes(t),this.ensureIndicatorNode(t)},cleanup(t){const e=t.querySelector(".botsauto-answer-row");e&&(e.dataset.hasAttachments="false",e.dataset.attachmentCount&&delete e.dataset.attachmentCount),this.ensureIndicatorNode(t)}},function(){if("undefined"==typeof MutationObserver)return;const t=()=>{document.querySelectorAll(".botsauto-note-attachments").forEach(t=>{const e=t.closest(".botsauto-item");if(!e)return;if("true"===t.dataset.baObserved)return;t.dataset.baObserved="true";const o=new MutationObserver(t=>{let o=!1;for(const e of t)if("childList"===e.type){o=!0;break}o&&setTimeout(()=>{var t;null==(t=window.BA_attachIndicator)||t.update(e)},0)}),a=t.querySelector(".ba-attachments-list");a&&o.observe(a,{childList:!0,subtree:!1})})};"loading"===document.readyState?document.addEventListener("DOMContentLoaded",t):t();const e=document.querySelector(".botsauto-checklist");if(e){new MutationObserver(e=>{for(const o of e)"childList"===o.type&&o.addedNodes.length>0&&setTimeout(t,0)}).observe(e,{childList:!0,subtree:!0})}document.addEventListener("botsauto:attachment:added",t=>{var e,o;const a=null==(e=t.detail)?void 0:e.itemHash;if(!a)return void d();const n=document.querySelector(`.botsauto-item[data-item-hash="${a}"]`);n?(null==(o=window.BA_attachIndicator)||o.update(n),d(n)):d()}),document.addEventListener("botsauto:attachment:removed",t=>{var e,o;const a=null==(e=t.detail)?void 0:e.itemHash;if(!a)return void d();const n=document.querySelector(`.botsauto-item[data-item-hash="${a}"]`);n?(null==(o=window.BA_attachIndicator)||o.update(n),d(n)):d()})}();var Te=null,Oe=window.botsauto&&window.botsauto.session_data?window.botsauto.session_data:null,Ce=!1,je=null;function Ie(t){return t&&t.querySelector&&t.classList&&t.classList.contains("botsauto-checklist")&&t.querySelector('input[name="_botsauto_nonce"]')&&t.querySelector('input[name="action"][value="botsauto_save"]')?t:null}function Ee(t){var e=Ie(t);if(!e)return 0;var o=e.querySelector('input[name="post_id"]');if(!o||o.hasAttribute("data-botsauto-transcript-post-id"))return 0;var a=String(o.value||"").trim();if(!/^\d+$/.test(a))return 0;var n=parseInt(a,10)||0;return n>0?n:0}function qe(t,e){var o=Ie(t),a=window.botsauto||{},n={submissionId:e||0,draftToken:"",instanceToken:"",editToken:"",canUseCookieBackedAccess:!(!a||!a.server_persist_allowed)};if(o){var i=o.querySelector('input[name="draft_token"], input[name="botsauto_draft_token"]'),r=o.querySelector('input[name="instance_token"]'),s=o.querySelector('input[name="edit_token"], input[name="botsauto_edit_token"], input[name="botsauto_edit"]');i&&(n.draftToken=String(i.value||"").trim()),r&&(n.instanceToken=String(r.value||"").trim()),s&&(n.editToken=String(s.value||"").trim())}if(n.draftToken||(n.draftToken=String(a&&(a.draft_token||a.draftToken||a.botsauto_draft_token)||"").trim()),n.instanceToken||(n.instanceToken=String(a&&(a.instance_token||a.instanceToken)||"").trim()),n.editToken||(n.editToken=String(a&&(a.edit_token||a.botsauto_edit_token)||"").trim()),Oe&&Oe.context){var u=Oe.context;!n.draftToken&&u.draft_token&&(n.draftToken=String(u.draft_token).trim()),!n.instanceToken&&u.instance_token&&(n.instanceToken=String(u.instance_token).trim()),!n.editToken&&u.edit_token&&(n.editToken=String(u.edit_token).trim())}return n.hasDraftOrInstanceToken=!(!n.draftToken&&!n.instanceToken),n.hasAnyAccessContext=!!(n.hasDraftOrInstanceToken||n.editToken||n.canUseCookieBackedAccess),n}function Ne(t){var e=Ee(t);if(e<=0)return!1;var o=qe(t,e);return!(!o||!o.hasAnyAccessContext)}async function Be(t,e){if(!Oe)return o("[BOTSAUTO SAVE] nonce refresh skipped: no session data"),!1;if(!e)return a("[BOTSAUTO SAVE] nonce refresh skipped: missing submission context"),!1;try{o("[BOTSAUTO SAVE] nonce refresh started");var n=qe(t,e);if(!n.hasAnyAccessContext)return a("[BOTSAUTO SAVE] nonce refresh skipped: missing access context"),!1;var i={action:Oe.refresh_action,session_id:Oe.session_id,submission_id:String(e),post_id:String(e),checklist_id:String(e)};n.draftToken&&(i.draft_token=n.draftToken,i.botsauto_draft_token=n.draftToken),n.instanceToken&&(i.instance_token=n.instanceToken),n.editToken&&(i.edit_token=n.editToken);const r=await fetch(Oe.ajax_url,{method:"POST",credentials:"same-origin",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:new URLSearchParams(i)}),s=await r.json(),u=s&&s.data?s.data:null,d=u&&u.nonce?u.nonce:"",c=u&&u.action?u.action:"";if(s&&s.success&&d){if(c&&"botsauto_save_form"!==c)return console.error("BOTSAUTO: Refusing nonce refresh for unexpected action",c,s),!1;const e=t&&t.querySelector?t.querySelector('input[name="_botsauto_nonce"]'):document.querySelector('input[name="_botsauto_nonce"]');return e?(e.value=d,o("[BOTSAUTO SAVE] nonce refresh completed"),Ce=!1,je=null,!0):(a("[BOTSAUTO SAVE] nonce field not found for refresh"),Mt(je=Vt({status:r.status,responseJSON:s},"Sessie kon niet worden vernieuwd. Probeer het opnieuw.",{action:Oe.refresh_action||"botsauto_refresh_nonce",errorCode:"missing_submission_context"})),!1)}return je=Vt({status:r.status,responseJSON:s},"Sessie kon niet worden vernieuwd. Probeer het opnieuw.",{action:Oe.refresh_action||"botsauto_refresh_nonce"}),Ce="session_expired"===je.errorCode,Mt(je),a("[BOTSAUTO SAVE] nonce refresh failed"),!1}catch(t){return je=Vt(null,"Sessie kon niet worden vernieuwd. Controleer uw verbinding en probeer opnieuw.",{action:Oe&&Oe.refresh_action?Oe.refresh_action:"botsauto_refresh_nonce",errorCode:"network_error",status:0}),a("[BOTSAUTO SAVE] nonce refresh error"),!1}}async function Ue(){if(Oe)try{await fetch(Oe.ajax_url,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:new URLSearchParams({action:Oe.touch_action,session_id:Oe.session_id})}),o("BOTSAUTO: Session kept alive")}catch(t){}}function Le(){Te&&clearInterval(Te),Te=setInterval(Ue,3e5),o("BOTSAUTO: Session heartbeat started (5 minute intervals)")}function Pe(){Te&&(clearInterval(Te),Te=null,o("BOTSAUTO: Session heartbeat stopped"))}async function De(t){if(!Oe)return o("[BOTSAUTO SAVE] no session data available, proceeding with current nonce"),!0;var e=Ee(t);if(!e)return o("[BOTSAUTO SAVE] nonce refresh skipped for new submission"),Ce=!1,je=null,!0;if(!Ne(t))return o("[BOTSAUTO SAVE] nonce refresh skipped: persisted submission without access context"),Ce=!1,je=null,!0;if(!await Be(t,e)){if(Ce)throw Ve(je&&je.message?je.message:""),new Error("Sessie verlopen");throw new Error(je&&je.message?je.message:"Sessie kon niet worden vernieuwd. Probeer het opnieuw.")}return!0}function Ve(t){const e=document.createElement("div");e.className="botsauto-timeout-modal",e.style.cssText="\n      position: fixed;\n      top: 0;\n      left: 0;\n      width: 100%;\n      height: 100%;\n      background: rgba(0,0,0,0.8);\n      z-index: 10000;\n      display: flex;\n      align-items: center;\n      justify-content: center;\n    ";const o=document.createElement("div");o.style.cssText="\n      background: white;\n      padding: 30px;\n      border-radius: 8px;\n      max-width: 400px;\n      text-align: center;\n      box-shadow: 0 4px 20px rgba(0,0,0,0.3);\n    ";const a=document.createElement("h3");a.style.marginTop="0",a.style.color="#d63638",a.textContent="Sessie verlopen";const n=document.createElement("p");n.textContent=t&&String(t).trim()?String(t).trim():"Je sessie is verlopen. Klik om te vernieuwen en opnieuw te verzenden.";const i=document.createElement("button");i.type="button",i.style.background="#0073aa",i.style.color="white",i.style.border="none",i.style.padding="10px 20px",i.style.borderRadius="4px",i.style.cursor="pointer",i.style.fontSize="16px",i.textContent="Vernieuwen en opnieuw proberen",i.addEventListener("click",function(){window.location.reload()}),o.appendChild(a),o.appendChild(n),o.appendChild(i),e.appendChild(o),document.body.appendChild(e)}Oe&&(o("BOTSAUTO: Initializing session management with TTL:",Oe.ttl_minutes,"minutes"),Le());try{Bt(),o("BOTSAUTO: Initial progress update completed")}catch(t){a("BOTSAUTO: Initial updateProgress failed",t)}requestAnimationFrame(function(){try{Bt(),o("BOTSAUTO: Second pass progress update completed")}catch(t){a("BOTSAUTO: Second pass updateProgress failed",t)}});var ze=Date.now();function Me(){var t=e("#botsauto-ai-kansenscan"),a=e(".botsauto-ai-conditional"),n=e("#botsauto-customer-website"),i=e("#botsauto-customer-country");function r(){var e=t.val()||"";"Ja, in het Nederlands"===e||"Ja, in het Engels"===e?(a.show(),n.length&&n.attr("required","required"),i.length&&i.attr("required","required"),o("BOTSAUTO: AI Kansenscan enabled, showing conditional fields",{value:e})):(a.hide(),n.length&&n.removeAttr("required"),i.length&&i.removeAttr("required"),o("BOTSAUTO: AI Kansenscan disabled, hiding conditional fields",{value:e}))}t.length&&a.length?(setTimeout(function(){r()},0),r(),t.off("change.aikansenscan").on("change.aikansenscan",r),o("BOTSAUTO: AI Kansenscan conditional fields initialized",{aiSelectFound:t.length>0,conditionalFieldsFound:a.length,initialValue:t.val()})):o("BOTSAUTO: AI Kansenscan fields not found, skipping initialization")}function Fe(){var t=window.botsauto&&window.botsauto.ai_timeout_ms?parseInt(window.botsauto.ai_timeout_ms,10):NaN;return!isNaN(t)&&t>0?t:15e4}function Ke(){e(document).off("click.aikansenscan",".botsauto-ai-generate").on("click.aikansenscan",".botsauto-ai-generate",function(t){t.preventDefault();var a=e(this),n=a.text(),i=1e3,r=2e3,s=[3e3,5e3,8e3],u=0,d=3e5,c=d,l=0,p=Math.ceil(c/i),b="",m=Date.now(),f=e("#post_ID").val()||e('input[name="post_id"]').val()||0;if(f&&"0"!==f){var g=a.siblings(".botsauto-ai-error");0===g.length&&0===(g=a.closest(".botsauto-ai-controls, .botsauto-section, div").find(".botsauto-ai-error")).length&&(g=e('<div class="botsauto-ai-error" style="margin-top: 10px; display: none;"></div>'),a.after(g)),g.hide().empty(),a.prop("disabled",!0).text("AI Kansenscan wordt gegenereerd... dit kan enkele minuten duren");var h=window.botsauto&&window.botsauto.botsauto_nonce?window.botsauto.botsauto_nonce:"";h||(h=e('input[name="botsauto_nonce"]').val()||"");var v=window.botsauto&&window.botsauto.instanceToken?window.botsauto.instanceToken:"";!v&&window.botsauto&&window.botsauto.instance_token&&(v=window.botsauto.instance_token);var w={action:"botsauto_ai_kansenscan_start",post_id:f,nonce:h,instance_token:v},_=function(t,e){var o='<div class="botsauto-error-message" style="padding: 10px; background-color: #f8d7da; border: 1px solid #f5c6cb; border-radius: 4px; color: #721c24;">';o+="<strong>"+(e||"Fout")+":</strong> "+t,o+="</div>",g.siblings(".botsauto-ai-warning, .botsauto-ai-warning-timeout").remove(),g.html(o).show()},y=function(t,e){var o='<div class="'+(e||"botsauto-ai-warning-timeout")+'" style="padding: 10px; background-color: #fff3cd; border: 1px solid #ffeeba; border-radius: 4px; color: #856404; margin-top: 10px;">';o+="<strong>Let op:</strong> "+t,o+="</div>",g.hide().empty(),g.siblings(".botsauto-ai-warning, .botsauto-ai-warning-timeout").remove(),g.after(o)},k=function(t){var e=function(t){if(!t||"object"!=typeof t)return"";var e=parseInt(t.ready_count,10),o=parseInt(t.total_count,10);(isNaN(e)||e<0)&&(e=0),(isNaN(o)||o<0)&&(o=0);var a=t.status?String(t.status):"";return o<=0?"starting_ai_generation"===a?"AI Kansenscan wordt gegenereerd...":"":"repairing_cache"===a?"Cache herstellen... "+e+" van "+o+" gereed":"cache_ready"===a||"starting_ai_generation"===a?"AI Kansenscan wordt gegenereerd...":"Bijlagen voorbereiden... "+e+" van "+o+" gereed"}(t);return!!e&&(a.prop("disabled",!0).text(e),y(e,"botsauto-ai-warning"),!0)},S=function(t){if(!t||"object"!=typeof t)return null;if(t.cache_progress&&"object"==typeof t.cache_progress)return t.cache_progress;if(t.data&&"object"==typeof t.data){if(t.data.cache_progress&&"object"==typeof t.data.cache_progress)return t.data.cache_progress;if(t.data.extra&&"object"==typeof t.data.extra&&t.data.extra.cache_progress&&"object"==typeof t.data.extra.cache_progress)return t.data.extra.cache_progress}return null},x=function(){try{if("function"==typeof window.refreshAttachmentsOverview)return void window.refreshAttachmentsOverview(f);var t;"function"==typeof window.CustomEvent?t=new CustomEvent("botsauto:attachment:added",{detail:{postId:f,source:"ai-timeout"}}):(t=document.createEvent("CustomEvent")).initCustomEvent("botsauto:attachment:added",!0,!0,{postId:f,source:"ai-timeout"}),document.dispatchEvent(t)}catch(t){}},A=function(){a.prop("disabled",!1).text(n)},T=function(t){var e=t&&t.data?t.data:{},a=e.status||"";I(e);var n,i=k(S(t));if("success"===a||"completed"===a)return e.document&&e.document.id&&function(t,e){var a=document.querySelector('[data-botsauto-role="attachments"][data-botsauto-section="attachments"]')||document.getElementById("botsauto-attachments-overview");if(!a)return void o("BOTSAUTO: Attachments overview not yet rendered, attachment will appear after page refresh");a.style.display="block";var n=a.querySelector(".botsauto-overview-content");n||((n=document.createElement("div")).className="botsauto-overview-content",a.appendChild(n));var i,r="ai_kansenscan",s=t.label||"Kansenscan (AI)",u=a.querySelector('.botsauto-overview-item[data-item-hash="'+r+'"]');if(u)(i=u.querySelector(".botsauto-overview-attachments"))||((i=document.createElement("ul")).className="botsauto-overview-attachments",i.setAttribute("role","list"),u.appendChild(i));else{var d=document.createElement("div");d.className="botsauto-overview-item",d.dataset.itemHash=r;var c=document.createElement("div");c.className="botsauto-overview-item-header";var l=document.createElement("div");l.className="botsauto-overview-item-head",l.setAttribute("data-oi-align","center"),l.setAttribute("data-oi-gap","M");var p=document.createElement("h3");p.className="botsauto-overview-item-title";var b=document.createElement("a");b.className="botsauto-attachment-jump",b.href="#botsauto-item-"+r,b.textContent=s,p.appendChild(b),l.appendChild(p),(q=document.createElement("button")).type="button",q.className="botsauto-overview-item-toggle",q.setAttribute("aria-expanded","false");var m="attachments-"+r;q.setAttribute("aria-controls",m),(E=document.createElement("i")).className="fa-solid fa-chevron-right",E.setAttribute("aria-hidden","true"),q.appendChild(E),l.appendChild(q),c.appendChild(l),d.appendChild(c),(i=document.createElement("ul")).className="botsauto-overview-attachments botsauto-overview-attachments-collapsible",i.id=m,i.setAttribute("role","list"),i.style.display="none",d.appendChild(i),n.firstChild?n.insertBefore(d,n.firstChild):n.appendChild(d),window.makeItemsCollapsible&&"function"==typeof window.makeItemsCollapsible&&window.makeItemsCollapsible(a),u=d}if(i.querySelector('li[data-attachment-id="'+t.id+'"]'))return;var f=document.createElement("li");f.setAttribute("data-attachment-id",t.id||"");var g=document.createElement("div");g.className="botsauto-overview-file-info";var h=document.createElement("a");h.href=t.view_url||t.url||"#",h.target="_blank",h.rel="noopener",h.className="botsauto-overview-file-link botsauto-overview-file-card-link";var v=t.filename||"kansenscan.pdf",w="string"==typeof t.card_html?t.card_html.trim():"",_=null;if(w){var y=document.createElement("div");y.innerHTML=w,_=y.querySelector(".botsauto-file-card")}_?h.appendChild(_):h.textContent=v;g.appendChild(h);var k=document.createElement("div");if(k.className="botsauto-overview-meta",window.BOTS_TimeFormatter&&"function"==typeof window.BOTS_TimeFormatter.createTimeElement){var S=window.BOTS_TimeFormatter.createTimeElement(Math.floor(Date.now()/1e3));k.appendChild(S)}else{var x=document.createElement("span");x.className="botsauto-overview-file-time",x.textContent="zojuist",k.appendChild(x)}g.appendChild(k),f.appendChild(g);var A=document.createElement("div");A.className="botsauto-overview-file-actions";var T=document.createElement("button");T.type="button",T.className="botsauto-attachment-download",T.setAttribute("aria-label","Downloaden: "+(t.filename||"bestand")),T.setAttribute("data-url",t.download_url||t.url||""),T.setAttribute("data-filename",t.filename||""),T.innerHTML='<i class="fa-solid fa-download" aria-hidden="true"></i> Downloaden',T.title="Downloaden: "+(t.filename||"bestand"),A.appendChild(T);var O=String(t.filename||"").toLowerCase(),C=O.includes(".")?O.split(".").pop():"";if(-1!==["docx","xlsx","pptx"].indexOf(C)&&t.id&&e){var j=document.createElement("button");j.type="button",j.className="botsauto-attachment-edit",j.setAttribute("aria-label","Bewerken: "+(t.filename||"bestand")),j.setAttribute("data-file-id",t.id||""),j.setAttribute("data-item-hash",r),j.setAttribute("data-post-id",e),j.setAttribute("data-filename",t.filename||""),j.innerHTML='<i class="fa-solid fa-pen-to-square" aria-hidden="true"></i> Bewerken',j.title="Bewerken: "+(t.filename||"bestand"),A.appendChild(j)}if(window.botsauto_attachments_permissions&&!1!==window.botsauto_attachments_permissions.can_delete){var I=document.createElement("button");I.type="button",I.className="botsauto-attachment-delete",I.setAttribute("aria-label","Verwijderen: "+(t.filename||"bestand")),I.setAttribute("data-file-id",t.id||""),I.setAttribute("data-file-url",t.download_url||t.url||""),I.setAttribute("data-item-hash",r),I.innerHTML='<i class="fa-solid fa-trash-can" aria-hidden="true"></i> Verwijderen',I.title="Verwijderen: "+(t.filename||"bestand"),A.appendChild(I)}f.appendChild(A),i.firstChild?i.insertBefore(f,i.firstChild):i.appendChild(f);if(u){var E,q=u.querySelector(".botsauto-overview-item-toggle"),N=u.querySelector(".botsauto-overview-attachments");if(q&&N)if("false"===q.getAttribute("aria-expanded")||"none"===N.style.display||u.classList.contains("botsauto-overview-item-collapsed"))if(window.toggleSection&&"function"==typeof window.toggleSection)window.toggleSection(u);else q.setAttribute("aria-expanded","true"),N.style.display="flex",(E=q.querySelector("i"))&&(E.className="fa-solid fa-chevron-down"),u.classList.remove("botsauto-overview-item-collapsed")}if(a._resultCount){var B=a.querySelectorAll(".botsauto-overview-attachments li").length;a._resultCount&&"function"==typeof window.updateResultCount&&window.updateResultCount(a,B,B)}}(e.document,f),x(),n='<div class="botsauto-success-message" style="padding: 10px; background-color: #d4edda; border: 1px solid #c3e6cb; border-radius: 4px; color: #155724;">',n+="<strong>Succes:</strong> "+"AI Kansenscan succesvol gegenereerd.",n+="</div>",g.siblings(".botsauto-ai-warning, .botsauto-ai-warning-timeout").remove(),g.html(n).show(),A(),!0;if("failed"===a||"stale"===a||"cancelled"===a||"error"===a){if(q(a,j(t)))return!1;var r=e.error||e.message||"AI Kansenscan generatie mislukt.";return(e&&e.context_limit_hint||/context (window|length)|context_length_exceeded|input te groot|prompt te groot/i.test(String(r)))&&(r="AI Kansenscan kon niet worden gemaakt omdat de input te groot is. Verklein context of bijlagen."),_(r,"Mislukt"),A(),!0}return!i&&E(e),!1},O=function(t){var e=t?String(t).toLowerCase():"";return"error"===e||"failed"===e||"stale"===e||"cancelled"===e},C=function(t,e){var o=t&&t.data&&"object"==typeof t.data?t.data:{},a=o.error||o.message||"";return!a&&t&&"string"==typeof t.message&&(a=t.message),a||e},j=function(t){var e=t&&t.data&&"object"==typeof t.data?t.data:{},o=e.reason||e.code||"";return!o&&t&&"string"==typeof t.code&&(o=t.code),o?String(o).toLowerCase():""},I=function(t){var e=function(t){return t&&t.runtime_limits&&"object"==typeof t.runtime_limits?t.runtime_limits:t&&t.data&&"object"==typeof t.data&&t.data.runtime_limits&&"object"==typeof t.data.runtime_limits?t.data.runtime_limits:null}(t),o=e?parseInt(e.running_timeout_seconds,10):NaN,a=d;!isNaN(o)&&o>0&&(a=Math.max(d,1e3*(o+120))),c=a,p=Math.ceil(c/i)},E=function(t){if(!t||"object"!=typeof t)return!1;var e=t.status?String(t.status).toLowerCase():"",o={queued:"AI Kansenscan staat in de wachtrij.",validating_cache:"AI Kansenscan controleert de bijlagen-cache.",preparing_context:"AI Kansenscan bereidt checklistcontext voor.",running_ai:"AI Kansenscan wordt gegenereerd.",generating_output:"AI Kansenscan document wordt gemaakt."};if(!Object.prototype.hasOwnProperty.call(o,e))return!1;var n=t.message&&""!==String(t.message).trim()?String(t.message):o[e];return a.prop("disabled",!0).text(n),y(n,"botsauto-ai-warning"),!0},q=function(t,e){var o=t?String(t).toLowerCase():"",a=e?String(e).toLowerCase():"";return"not_found"===o||"pending_lookup"===o||"unknown_yet"===o||"failed"===o&&Date.now()-m<=1e4&&("job_not_found"===a||"not_found"===a||"pending_lookup"===a||"unknown_yet"===a)},N=function(t){setTimeout(U,t>0?t:i)},B=function(t){if(++u>=5)return y("Statuscontrole voor AI Kansenscan kon tijdelijk niet worden voltooid. De generatie kan op de server nog doorlopen. Vernieuw de pagina of controleer later of de PDF is aangemaakt.","botsauto-ai-warning-timeout"),x(),void A();var e;y(t||"Statuscontrole tijdelijk niet bereikbaar. De AI Kansenscan loopt mogelijk nog door...","botsauto-ai-warning botsauto-ai-warning-status-transient"),N((e=u)<=0?i:1===e?s[0]:2===e?s[1]:s[2])},U=function(){if(++l>p)return y("De AI Kansenscan duurt langer dan verwacht. Je kunt ondertussen verder werken; controleer straks het bijlagenoverzicht.","botsauto-ai-warning-timeout"),x(),void A();e.ajax({url:window.botsauto&&(window.botsauto.ajaxUrl||window.botsauto.ajax_url)?window.botsauto.ajaxUrl||window.botsauto.ajax_url:ajaxurl,type:"POST",dataType:"json",timeout:Fe(),data:{action:"botsauto_ai_kansenscan_status",post_id:f,nonce:h,instance_token:v,run_id:b},success:function(t){if(t&&"object"==typeof t)if(u=0,g.siblings(".botsauto-ai-warning-status-transient").remove(),t&&t.success){T(t)||N(i)}else{var e=t&&t.data&&t.data.status?t.data.status:"",o=j(t);if(O(e)&&!q(e,o))return _(C(t,"Statuscontrole voor AI Kansenscan is definitief mislukt."),"Mislukt"),void A();B("Statuscontrole tijdelijk niet bereikbaar. De AI Kansenscan loopt mogelijk nog door...")}else B("Statuscontrole tijdelijk niet bereikbaar. De AI Kansenscan loopt mogelijk nog door...")},error:function(t,e){var o=t&&t.responseJSON?t.responseJSON:null,a=o&&o.data&&o.data.status?o.data.status:"",n=j(o);if(O(a)&&!q(a,n))return _(C(o,"Statuscontrole voor AI Kansenscan is mislukt. Start opnieuw."),"Mislukt"),void A();B("timeout"===e?"Statuscontrole duurt langer dan verwacht. De AI Kansenscan loopt mogelijk nog door...":"parsererror"===e?"Onverwachte serverrespons tijdens statuscontrole. We proberen zo opnieuw.":"Statuscontrole tijdelijk niet bereikbaar. De AI Kansenscan loopt mogelijk nog door...")}})};e.ajax({url:window.botsauto&&(window.botsauto.ajaxUrl||window.botsauto.ajax_url)?window.botsauto.ajaxUrl||window.botsauto.ajax_url:ajaxurl,type:"POST",data:w,dataType:"json",timeout:Fe(),success:function(t){if(t&&t.success){var e=t.data?t.data:{};return b=e.run_id?String(e.run_id):"",I(e),g.hide().empty(),g.siblings(".botsauto-ai-warning, .botsauto-ai-warning-timeout").remove(),k(e.cache_progress||null)||E(e),void N(r)}var o=t&&t.data&&t.data.status?t.data.status:"",a=t&&t.data&&t.data.message?t.data.message:"",n=S(t);if(n)return k(n),void N(0===l?r:i);O(o)?_(a||"AI Kansenscan generatie mislukt.","Mislukt"):y(a||"AI Kansenscan kon niet direct starten. Probeer het opnieuw.","botsauto-ai-warning"),A()},error:function(t,e){var o=t&&t.responseJSON?t.responseJSON:null,a=S(o);if(a)return k(a),void N(0===l?r:i);var n=t&&t.status>=400&&t.status<500,s=o&&o.data&&o.data.status?o.data.status:"";if(O(s)||n)return _(C(o,"AI Kansenscan kon niet worden gestart."),"Mislukt"),void A();"timeout"===e?y("Startverzoek duurde te lang. Controleer straks het bijlagenoverzicht of probeer opnieuw.","botsauto-ai-warning-timeout"):y("parsererror"===e?"Onverwachte serverrespons bij starten van de AI Kansenscan. Probeer opnieuw.":"Netwerkprobleem bij starten van de AI Kansenscan. Probeer opnieuw.","botsauto-ai-warning"),A()}})}else alert("Ongeldig checklist ID. Sla eerst de checklist op.")})}function Re(){function t(t,e){if(t&&t.length){var o=t.find("[data-botsauto-ai-token-budget]");if(o.length){var a=o.find("[data-botsauto-ai-token-budget-summary]"),n=o.find("[data-botsauto-ai-token-budget-status]"),i=o.find("[data-botsauto-ai-token-budget-bar]"),r=o.find("[data-botsauto-ai-token-budget-bar-fill]"),s=o.find("[data-botsauto-ai-token-budget-list]");if(!e||"object"!=typeof e)return o.attr("hidden","hidden").removeClass("botsauto-ai-token-budget--safe botsauto-ai-token-budget--high botsauto-ai-token-budget--risk"),a.text(""),n.text(""),i.attr("aria-valuenow","0"),r.css("width","0%"),void s.empty();var u="string"==typeof e.status?e.status:"safe",d="botsauto-ai-token-budget--safe";"risk"===u?d="botsauto-ai-token-budget--risk":"high"===u&&(d="botsauto-ai-token-budget--high");var c=Number(e.budget_tokens||0);(!isFinite(c)||c<0)&&(c=0);var l=Number(e.used_tokens||0);(!isFinite(l)||l<0)&&(l=0);var p=Number(e.remaining_tokens||Math.max(0,c-l));(!isFinite(p)||p<0)&&(p=0);var b=Number(e.usage_ratio||0);(!isFinite(b)||b<0)&&(b=c>0?l/c:0);var m=Math.max(0,Math.min(100,Math.round(100*b))),f="string"==typeof e.status_label&&""!==e.status_label.trim()?e.status_label.trim():"",g=function(t){return"number"==typeof t&&isFinite(t)||(t=0),"function"==typeof t.toLocaleString?t.toLocaleString("nl-NL"):String(t)};o.removeAttr("hidden").removeClass("botsauto-ai-token-budget--safe botsauto-ai-token-budget--high botsauto-ai-token-budget--risk").addClass(d),a.text(g(l)+" / "+g(c)+" tokens ("+m+"%)"),n.text(f+" - resterend: "+g(p)+" tokens"),i.attr("aria-valuenow",String(m)),r.css("width",m+"%");var h=e.sections&&"object"==typeof e.sections?e.sections:{},v="";["fixed_prompt","checklist_data","notes","attachments","web_context"].forEach(function(t){if(Object.prototype.hasOwnProperty.call(h,t)){var e=h[t];if(e&&"object"==typeof e){var o="string"==typeof e.label?e.label:t,a=Number(e.tokens||0);(!isFinite(a)||a<0)&&(a=0),v+="<li><span>"+(String(o).replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#39;")+"</span><strong>")+g(a)+" tokens</strong></li>"}}}),s.html(v)}}}e(document).off("click.aikansenscanprompt",".botsauto-kansenscan-prompt").on("click.aikansenscanprompt",".botsauto-kansenscan-prompt",function(a){a.preventDefault();var n=e(this),i=n.data("post-id"),r=n.data("modal-id"),s=e(),u="";"string"==typeof r&&r.trim().length&&(u=r.trim()),r&&(s=e("#"+String(r).replace(/([ #;?%&,.+*~\':"!^$[\]()=>|\/@])/g,"\\$1"))),s.length||(s=e("#botsauto-ai-prompt-modal-"+i));var d=s.find(".botsauto-ai-prompt-modal__textarea");if(i){var c=n.siblings(".botsauto-ai-error");0===c.length&&0===(c=n.closest(".botsauto-ai-controls, .botsauto-section, div").find(".botsauto-ai-error")).length&&(c=e('<div class="botsauto-ai-error" style="margin-top: 10px; display: none;"></div>'),n.after(c));var l=function(){c.hide().empty(),c.siblings(".botsauto-ai-warning, .botsauto-ai-warning-timeout").remove()},p=function(t,e){if(t){var o='<div class="'+(e||"botsauto-ai-warning")+'" style="padding: 10px; background-color: #fff3cd; border: 1px solid #ffeeba; border-radius: 4px; color: #856404; margin-top: 10px;">';o+="<strong>Let op:</strong> "+t,o+="</div>",c.hide().empty(),c.siblings(".botsauto-ai-warning, .botsauto-ai-warning-timeout").remove(),c.after(o)}},b=function(t){return t&&"object"==typeof t?t.data&&"object"==typeof t.data?t.data:t:{}},m=function(t){if(!t||"object"!=typeof t)return null;if(t.cache_progress&&"object"==typeof t.cache_progress)return t.cache_progress;var e=b(t);return e.cache_progress&&"object"==typeof e.cache_progress?e.cache_progress:e.extra&&"object"==typeof e.extra&&e.extra.cache_progress&&"object"==typeof e.extra.cache_progress?e.extra.cache_progress:null},f=function(t){var e=b(t),o=e&&"string"==typeof e.code?e.code:"",a=e&&"string"==typeof e.status?e.status:"",n=m(t),i=n&&"string"==typeof n.status?n.status:"",r=n?parseInt(n.total_count,10):0;return(isNaN(r)||r<0)&&(r=0),"attachment_cache_not_ready"===o||("preparing_attachments"===a||"repairing_cache"===a||("preparing_attachments"===i||"repairing_cache"===i)&&r>0)},g=n.text(),h=null,v=0,w=1500,_=!1,y=function(){h&&(clearTimeout(h),h=null)},k=function(){y(),_||(_=!0,n.prop("disabled",!1).text(g))},S=function(t){if(!_){if(v>=30)return p("Het ophalen van de prompt duurt langer dan verwacht. Probeer het zo opnieuw.","botsauto-ai-warning-timeout"),void k();var e=parseInt(t,10);(isNaN(e)||e<=0)&&(e=w),y(),h=setTimeout(function(){v+=1,C()},e)}},x=function(t){var e=b(t),o=function(t){if(!t||"object"!=typeof t)return"";var e=parseInt(t.ready_count,10),o=parseInt(t.total_count,10);(isNaN(e)||e<0)&&(e=0),(isNaN(o)||o<0)&&(o=0);var a=t.status?String(t.status):"";return o<=0?"":"repairing_cache"===a?"Cache herstellen... "+e+" van "+o+" gereed":"preparing_attachments"===a?"Bijlagen voorbereiden... "+e+" van "+o+" gereed":""}(m(t)),a=o||(e&&e.message?e.message:"Bijlagen voorbereiden is nog bezig. We proberen het opnieuw zodra de cache gereed is.");n.prop("disabled",!0).text(o||"Bijlagen voorbereiden..."),p(a,"botsauto-ai-warning"),S(w)};l(),n.prop("disabled",!0).text("Prompt genereren..."),function(){var t=s.find("[data-botsauto-ai-token-budget]");if(t.length){var e=t.find("[data-botsauto-ai-token-budget-summary]"),o=t.find("[data-botsauto-ai-token-budget-status]"),a=t.find("[data-botsauto-ai-token-budget-bar]"),n=t.find("[data-botsauto-ai-token-budget-bar-fill]"),i=t.find("[data-botsauto-ai-token-budget-list]");t.attr("hidden","hidden").removeClass("botsauto-ai-token-budget--safe botsauto-ai-token-budget--high botsauto-ai-token-budget--risk"),e.text(""),o.text(""),a.attr("aria-valuenow","0"),n.css("width","0%"),i.empty()}}();var A=window.botsauto&&window.botsauto.botsauto_nonce?window.botsauto.botsauto_nonce:"";A||(A=e('input[name="botsauto_nonce"]').val()||"");var T=window.botsauto&&window.botsauto.instanceToken?window.botsauto.instanceToken:"";!T&&window.botsauto&&window.botsauto.instance_token&&(T=window.botsauto.instance_token);var O=window.botsauto&&(window.botsauto.ajaxUrl||window.botsauto.ajax_url)?window.botsauto.ajaxUrl||window.botsauto.ajax_url:"undefined"!=typeof ajaxurl?ajaxurl:"",C=function(){_||e.ajax({url:O,type:"POST",dataType:"json",timeout:Fe(),data:{action:"botsauto_get_ai_kansenscan_prompt",post_id:i,nonce:A,instance_token:T},success:function(a){var n=b(a),i=function(t){var e="";"string"==typeof t.debug_full_prompt&&t.debug_full_prompt.length>0?e=t.debug_full_prompt:"string"==typeof t.debug_system_prompt&&"string"==typeof t.debug_user_prompt&&(t.debug_system_prompt.length>0||t.debug_user_prompt.length>0)?(e="MODEL SUGGESTION: "+("string"==typeof t.model&&t.model.length>0?t.model:"")+"\n\n",e+="===SYSTEM MESSAGE===\n"+t.debug_system_prompt+"\n\n",e+="===USER MESSAGE===\n"+t.debug_user_prompt):"string"==typeof t.prompt&&t.prompt.length>0&&(e=t.prompt);return e}(n),r=!(!n||!n.token_budget||"object"!=typeof n.token_budget);if(a&&a.success&&i&&r)return l(),d.val(i),t(s,n.token_budget),u&&s.attr("data-botsauto-trigger-modal-id",u),function(t){t.css("display","flex"),e("body").addClass("botsauto-ai-prompt-modal-open"),setTimeout(function(){t.find(".botsauto-ai-prompt-modal__close-icon").focus()},100),o("BOTSAUTO: AI Prompt Modal opened")}(s),void k();if(f(a))x(a);else{if(a&&a.success&&i&&!r)return p("Prompt is gereed, maar tokenbudgetgegevens ontbreken nog. Probeer het opnieuw.","botsauto-ai-warning"),void k();var c=n&&n.message?n.message:"Er is een fout opgetreden bij het ophalen van de prompt.";p(c,"botsauto-ai-warning"),k()}},error:function(t,e){var o=t&&t.responseJSON?t.responseJSON:null;if(f(o))x(o);else{if("timeout"===e||"parsererror"===e)return p("Prompt ophalen duurt langer dan verwacht. We proberen opnieuw...","botsauto-ai-warning-timeout"),void S(w);var a="",n=b(o);n&&"string"==typeof n.message&&(a=n.message),p(a||"Er is een fout opgetreden bij het ophalen van de prompt.","botsauto-ai-warning"),k()}}})};C()}else console.error("BOTSAUTO: Missing post ID for prompt generation.")}),e(document).off("click.aimodalcloseicon",".botsauto-ai-prompt-modal__close-icon").on("click.aimodalcloseicon",".botsauto-ai-prompt-modal__close-icon",function(t){t.preventDefault(),Je(e(this).closest(".botsauto-ai-prompt-modal"))}),e(document).off("click.aimodalclosebtn",".botsauto-ai-prompt-modal__close-btn").on("click.aimodalclosebtn",".botsauto-ai-prompt-modal__close-btn",function(t){t.preventDefault(),Je(e(this).closest(".botsauto-ai-prompt-modal"))}),e(document).off("click.aimodaloverlay",".botsauto-ai-prompt-modal__overlay").on("click.aimodaloverlay",".botsauto-ai-prompt-modal__overlay",function(t){t.preventDefault();var o=e(this).closest(".botsauto-ai-prompt-modal");"1"!==o.data("overlay-close")&&1!==o.data("overlay-close")||Je(o)}),e(document).off("click.aimodalcopy",".botsauto-ai-prompt-modal__copy-btn").on("click.aimodalcopy",".botsauto-ai-prompt-modal__copy-btn",function(t){t.preventDefault();var o=e(this).closest(".botsauto-ai-prompt-modal").find(".botsauto-ai-prompt-modal__textarea"),a=e(this),n=a.html(),i=o.val();navigator.clipboard&&window.isSecureContext?navigator.clipboard.writeText(i).then(function(){He(a,n)}).catch(function(t){console.error("BOTSAUTO: Clipboard write failed",t),Ge(o,a,n)}):Ge(o,a,n)}),e(document).off("keydown.aipromptmodal").on("keydown.aipromptmodal",function(t){if("Escape"===t.key||27===t.keyCode){var o=e(".botsauto-ai-prompt-modal:visible");o.length&&Je(o)}})}function Je(t){t.hide(),e("body").removeClass("botsauto-ai-prompt-modal-open");var a=t.attr("id")||"",n=t.attr("data-botsauto-trigger-modal-id")||"",i=e();if(n&&(i=e('.botsauto-kansenscan-prompt[data-modal-id="'+n+'"]').first()),i.length||(i=e('.botsauto-kansenscan-prompt[data-modal-id="'+a+'"]').first()),!i.length){var r=a.replace("botsauto-ai-prompt-modal-","").split("-botsauto-")[0];i=e('.botsauto-kansenscan-prompt[data-post-id="'+r+'"]').first()}i.length&&i.focus(),o("BOTSAUTO: AI Prompt Modal closed")}function He(t,e){t.html('<i class="fas fa-check" aria-hidden="true"></i> Gekopieerd!'),t.addClass("botsauto-ai-prompt-modal__copy-btn--success"),setTimeout(function(){t.html(e),t.removeClass("botsauto-ai-prompt-modal__copy-btn--success")},2e3)}function Ge(t,e,o){try{t[0].select(),t[0].setSelectionRange(0,99999),document.execCommand ("copy")?He(e,o):console.error("BOTSAUTO: Fallback copy command failed")}catch(t){console.error("BOTSAUTO: Fallback copy failed",t)}}function We(){if(window.botsauto&&window.botsauto.logo_editable&&window.botsauto.submission_id){var t=!!window.botsauto.allow_svg_upload,n=["image/jpeg","image/png","image/gif","image/webp"],i=["jpg","jpeg","png","gif","webp"];t&&(n.push("image/svg+xml"),i.push("svg"));var r=e('.botsauto-logo[data-editable="true"]');if(r.length){o("BOTSAUTO LOGO: Initializing logo upload");var s=e("<input>",{type:"file",id:"botsauto-logo-file-input",accept:n.join(","),css:{display:"none"}}).appendTo("body");r.off("click.botsautoLogo").on("click.botsautoLogo",function(t){t.preventDefault(),t.stopPropagation(),r.hasClass("botsauto-logo--uploading")||s.trigger("click")}),r.attr("tabindex","0").attr("role","button").attr("aria-label","Klik of druk Enter om logo te wijzigen").off("keypress.botsautoLogo").on("keypress.botsautoLogo",function(t){"Enter"!==t.key&&" "!==t.key||(t.preventDefault(),s.trigger("click"))}),s.off("change.botsautoLogo").on("change.botsautoLogo",function(r){var u=r.target.files&&r.target.files[0];if(u){o("BOTSAUTO LOGO: File selected",u.name,u.type,u.size);var d=(u.type||"").toLowerCase(),c=(u.name||"").toLowerCase(),l=-1!==c.indexOf(".")?c.split(".").pop():"";if(!t&&("image/svg+xml"===d||"svg"===l))return alert("SVG uploads are disabled for security reasons."),void s.val("");var p=d&&-1!==n.indexOf(d),b=l&&-1!==i.indexOf(l);if(!p&&!b)return alert("Alleen afbeeldingen zijn toegestaan ("+(t?"JPG, PNG, GIF, WebP, SVG":"JPG, PNG, GIF, WebP")+")."),void s.val("");if(u.size>5242880)return alert("Bestand is te groot (max. 5 MB)."),void s.val("");!function(t){var n=e('.botsauto-logo[data-editable="true"]'),i=n.find("img");if(!window.botsauto||!window.botsauto.ajax_url)return void a("BOTSAUTO LOGO: Missing AJAX configuration");n.addClass("botsauto-logo--uploading");var r=new FormData;r.append("action","botsauto_upload_checklist_logo"),r.append("nonce",window.botsauto.logo_nonce),r.append("post_id",window.botsauto.submission_id),r.append("edit_token",window.botsauto.edit_token||""),r.append("logo",t),o("BOTSAUTO LOGO: Starting upload",{post_id:window.botsauto.submission_id,file_name:t.name,file_size:t.size}),e.ajax({url:window.botsauto.ajax_url,type:"POST",data:r,processData:!1,contentType:!1,timeout:6e4,success:function(t){if(n.removeClass("botsauto-logo--uploading"),t&&t.success&&t.data&&t.data.logo_url)o("BOTSAUTO LOGO: Upload successful",t.data.logo_url),i.attr("src",t.data.logo_url),n.attr("data-has-custom","true"),n.addClass("botsauto-logo--success"),setTimeout(function(){n.removeClass("botsauto-logo--success")},2e3);else{var e=t&&t.data&&t.data.detail?t.data.detail:"Upload mislukt. Probeer het opnieuw.";a("BOTSAUTO LOGO: Upload failed",t),alert(e)}},error:function(t,e,o){n.removeClass("botsauto-logo--uploading"),a("BOTSAUTO LOGO: AJAX error",e,o);var i="Upload mislukt. Controleer uw verbinding en probeer het opnieuw.";t.responseJSON&&t.responseJSON.data&&t.responseJSON.data.detail&&(i=t.responseJSON.data.detail),alert(i)}})}(u),s.val("")}}),r.off("contextmenu.botsautoLogo").on("contextmenu.botsautoLogo",function(t){"true"===r.attr("data-has-custom")&&(t.preventDefault(),confirm("Wilt u het logo terugzetten naar de standaardafbeelding?")&&function(){var t=e('.botsauto-logo[data-editable="true"]'),n=t.find("img"),i=t.attr("data-default-logo")||"";if(!window.botsauto||!window.botsauto.ajax_url)return void a("BOTSAUTO LOGO: Missing AJAX configuration");t.addClass("botsauto-logo--uploading"),e.ajax({url:window.botsauto.ajax_url,type:"POST",data:{action:"botsauto_delete_checklist_logo",nonce:window.botsauto.logo_nonce,post_id:window.botsauto.submission_id,edit_token:window.botsauto.edit_token||""},timeout:3e4,success:function(e){if(t.removeClass("botsauto-logo--uploading"),e&&e.success){o("BOTSAUTO LOGO: Delete successful");var r=e.data&&e.data.logo_url?e.data.logo_url:i;r&&n.attr("src",r),t.attr("data-has-custom","false"),t.addClass("botsauto-logo--success"),setTimeout(function(){t.removeClass("botsauto-logo--success")},2e3)}else{var s=e&&e.data&&e.data.detail?e.data.detail:"Verwijderen mislukt. Probeer het opnieuw.";a("BOTSAUTO LOGO: Delete failed",e),alert(s)}},error:function(e,o,n){t.removeClass("botsauto-logo--uploading"),a("BOTSAUTO LOGO: Delete AJAX error",o,n),alert("Verwijderen mislukt. Controleer uw verbinding en probeer het opnieuw.")}})}())})}else o("BOTSAUTO LOGO: No editable logo container found")}else o("BOTSAUTO LOGO: Not editable (unsaved submission or missing data)")}o("BOTSAUTO: Script version initialized in",ze-r+"ms"),o("BOTSAUTO: Event handlers bound - click:",s.click,"change:",s.change,"input:",s.input,"ajaxComplete:",s.ajaxComplete),o("BOTSAUTO: MutationObserver active:",u,"target:",n),Me(),e(document).on("botsauto:formupdated",Me),window.__botsautoObserver__,Ke(),Re(),e(document).on("botsauto:formupdated",function(){Ke(),Re()}),We(),e(document).on("botsauto:formupdated",function(){We()});var $e=new Set,Xe=window.setInterval;window.setInterval=function(t,e){var o=Xe(t,e);return $e.add(o),o},e(window).off("beforeunload.botsauto").on("beforeunload.botsauto",function(){o("BOTSAUTO: Cleaning up on page unload"),$e.forEach(function(t){clearInterval(t)}),$e.clear(),window.__botsautoObserver__&&(window.__botsautoObserver__.disconnect(),window.__botsautoObserver__=null),e(document).off(".botsauto"),e(window).off(".botsauto"),Pe(),window.__BOTSautoMainRan__=!1}),e(document).off("visibilitychange.botsauto").on("visibilitychange.botsauto",function(){document.hidden?Pe():Oe&&Le()})}!function(t){const e=t.document||("undefined"!=typeof document?document:null);if(!e)return;const o=t.jQuery||null,a=function(t){const e=t||window;return void 0===e.BOTSAUTO_DEBUG&&(e.BOTSAUTO_DEBUG=!1),{log:function(){e.BOTSAUTO_DEBUG&&e.console&&"function"==typeof e.console.log&&e.console.log.apply(e.console,arguments)},warn:function(){e.BOTSAUTO_DEBUG&&e.console&&"function"==typeof e.console.warn&&e.console.warn.apply(e.console,arguments)},isEnabled:function(){return!!e.BOTSAUTO_DEBUG}}}(t);c({globalScope:t,$:o,warn:a.warn,log:a.log});let n="loading"!==e.readyState;function i(){const o=t.jQuery;return!(!n||!o||void 0===o.fn)&&(!function(t,e){const o=t||window;return o.__BOTSautoMainRan__=o.__BOTSautoMainRan__||!1,o.__BOTSautoMainRan__?("function"==typeof e&&e("BOTSAUTO: Main script already ran, skipping re-initialization"),!1):(o.__BOTSautoMainRan__=!0,!0)}(t,a.warn)||(function(t,e){const o=t||window,a=e||document;o.__botsautoTranscriptToggleBound||(o.__botsautoTranscriptToggleBound=!0,a.addEventListener("click",function(t){if(!t.target||"function"!=typeof t.target.closest)return;const e=t.target.closest(".botsauto-transcript-toggle");if(!e)return;const o=e.closest(".botsauto-transcript-item");o&&o.classList.toggle("expanded")}))}(t,e),p({globalScope:t,document:e,$:o,debug:a}),!0))}function r(){const e=t.jQuery;return!(!e||void 0===e.fn)&&(c({globalScope:t,$:e,warn:a.warn,log:a.log}),i(),!0)}if(!r()){let e=0;const o=t.setInterval(function(){e+=1,(r()||e>50)&&t.clearInterval(o)},100)}function s(){n=!0,i()}"loading"===e.readyState?e.addEventListener("DOMContentLoaded",s):s()}(window)})();