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