(()=>{"use strict";const t=function(t){return t.nextElementSibling.querySelector("input.text-field")},e=function(t,e,o){var n;if(t.checked=e?.includes(t.value),!t.checked)return;if(o.calcValue+=parseFloat(null!==(n=t.dataset?.calculate)&&void 0!==n?n:t.value),!o.isArray())return;const i=e.indexOf(t.value);e.splice(i,1)},{isEmpty:o}=JetFormBuilderFunctions,{InputData:n,ReactiveHook:i}=JetFormBuilderAbstract,{getParsedName:s}=JetFormBuilderFunctions;function r(t){return Array.isArray(t)?(1===t.length&&t[0]&&1!=t[0]&&t[0].includes(",")&&(t=(t=t[0].split(",")).map((t=>"true"===t?"":"false"===t?null:t))),t):[t].filter(Boolean)}function u(){n.call(this),this.wrapper=null,this.isResetCalcValue=!1}u.prototype=Object.create(n.prototype),u.prototype.wrapper=null,u.prototype.isSupported=function(t){return t.classList.contains("checkradio-wrap")&&t.querySelector(".checkboxes-wrap")},u.prototype.addListeners=function(){this.enterKey=new i,this.wrapper.addEventListener("change",this.onChangeValue.bind(this)),this.wrapper.addEventListener("keydown",this.handleEnterKey.bind(this)),this.wrapper.addEventListener("focusout",(t=>{[...this.nodes].includes(t?.relatedTarget)||t?.relatedTarget?.closest?.(".jet-form-builder__field-wrap.custom-option")||this.reportOnBlur()})),this.addNewButton&&this.wrapper.addEventListener("click",(t=>{t?.target&&!this.addNewButton.isEqualNode(t.target)||(this.silenceSet([...this.value.current,!0]),this.getCustomNodes().at(-1).closest(".jet-form-builder__field-wrap").querySelector("span input.jet-form-builder__field").focus())})),this.isArray()&&this.sanitize(r),this.callable=null,this.sanitize((n=>function(n,i){i.calcValue=0;const s=i.isArray()?[...n]:n;for(const t of i.nodes)!t.dataset.custom&&e(t,s,i);if(!i.addNewButton)return n;const r=i.getCustomNodes();if(!r.length||s.length){for(let e=Math.max(r.length,s.length)-1;e>=0;e--){let n=r[e];const u=s[e];if(null==u){n&&n.closest(".custom-option").remove();continue}if(void 0===n){if(!1===u)continue;i.addCustomOption(),n=i.nodes[i.nodes.length-1]}const a=t(n);a.disabled=!1===u,a.disabled||o(u)||!0===u||(i.calcValue+=1),a.value!==u&&"boolean"!=typeof u&&(a.value=u)}return n.filter((t=>null!==t))}for(let t=Math.max(r.length,s.length)-1;t>=0;t--)if(r[t]){let e=r[t];void 0===s[t]&&e.closest(".custom-option").remove()}}(n,this)))},u.prototype.onChangeValue=function(t){this.value.current=this.getActiveValue()},u.prototype.setValue=function(){this.value.current=this.getActiveValue(),this.value.applySanitizers(this.value.current)},u.prototype.setNode=function(t){t.jfbSync=this,this.nodes=t.getElementsByClassName("jet-form-builder__field checkboxes-field"),this.rawName=this.nodes[0].name,this.name=s(this.rawName),this.inputType="checkbox",this.wrapper=t,this.addNewButton=t.querySelector(".jet-form-builder__field-wrap.custom-option .add-custom-option")},u.prototype.getActiveValue=function(){var t;const e=[];for(const t of this.nodes)this.processValueFormSingleChoice(t,e);return this.isArray()?e:null!==(t=e?.[0])&&void 0!==t?t:""},u.prototype.processValueFormSingleChoice=function(e,o){if(!e.dataset.custom&&!e.checked)return;if(!e.dataset.custom)return void o.push(e.value);const n=t(e);e.checked||n.value?n.value||!e.checked?n.value&&o.push(!!e.checked&&n.value):o.push(!0):o.push(null)},u.prototype.isArray=function(){return Boolean(this.addNewButton)||this.nodes.item&&this.nodes.item(0)?.name?.includes?.("[]")},u.prototype.addCustomOption=function(){const t=this.addNewButton.closest(".custom-option");return this.wrapper.insertBefore(this.getCustomOptionNode(),t)},u.prototype.getCustomOptionNode=function(){if(!this.addNewButton)return!1;const t=this.addNewButton.querySelector("template"),e=document.createElement("template");return e.innerHTML=t.innerHTML.trim(),e.content.firstChild},u.prototype.getCustomNodes=function(){return[...this.nodes].filter((t=>t.dataset.custom&&t.nextElementSibling))};const a=u,{addFilter:l}=JetPlugins.hooks;window.JetFormBuilderAbstract={...window.JetFormBuilderAbstract,CheckboxData:a},l("jet.fb.inputs","jet-form-builder/checkbox-field",(function(t){return[a,...t]}))})();