function _createForOfIteratorHelperLoose(e,t){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(r)return(r=r.call(e)).next.bind(r);if(Array.isArray(e)||(r=_unsupportedIterableToArray(e))||t&&e&&"number"==typeof e.length){r&&(e=r);var a=0;return function(){return a>=e.length?{done:!0}:{done:!1,value:e[a++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function _unsupportedIterableToArray(e,t){if(e){if("string"==typeof e)return _arrayLikeToArray(e,t);var r={}.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?_arrayLikeToArray(e,t):void 0}}function _arrayLikeToArray(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,a=Array(t);r<t;r++)a[r]=e[r];return a}var FPF_Repeater=function(){function e(){this.repeaterWrapper=".fpf-repeater-field",this.init()}var t=e.prototype;return t.init=function(){e.initDragManager(),this.initEvents()},t.initEvents=function(){document.addEventListener("click",function(e){this.handleAdd(e),this.handleRemove(e)}.bind(this))},t.handleAdd=function(e){if(e.target.closest(".fpf-repeater-field-add-item-btn")){e.preventDefault();var t=e.target.closest(this.repeaterWrapper),r=t.querySelector(".template");if(r=r.cloneNode(!0),(r=this.replaceTemplateIDs(t,r)).classList.remove("template"),r.querySelectorAll(".fpf-colorpicker-item.no-render").forEach(function(e){e.classList.remove("no-render")}),r.querySelectorAll(".fpf-datepicker-item.no-render").forEach(function(e){e.classList.remove("no-render")}),r.innerHTML=r.innerHTML.replace(/data-showon-initialised/g,""),t.querySelectorAll(".items .fpf-repeater-item").length&&e.target.closest(".fpf-repeater-item")?e.target.closest(".fpf-repeater-item").parentNode.insertBefore(r,e.target.closest(".fpf-repeater-item").nextSibling):t.querySelector(".items").append(r),"function"==typeof FPF_Conditionize&&new FPF_Conditionize(r),"function"==typeof FPF_Colorpicker&&new FPF_Colorpicker,"function"==typeof FPF_Datepicker&&new FPF_Datepicker,"function"==typeof FPF_Textarea)new FPF_Textarea(r).init();var a={repeater_name:t.getAttribute("data-name"),initial_open:!0,repeater_item:r};r.repeater_data=a;var n=new CustomEvent("fpf_repeater_add",{detail:a,cancelable:!0});document.dispatchEvent(n),e.preventDefault()}},e.initDragManager=function(){var e=document.querySelectorAll(".fpf-repeater-field:not(.initialized)");if(e)for(var t,r=_createForOfIteratorHelperLoose(e);!(t=r()).done;){var a=t.value;new Sortable(a.querySelector(".items"),{animation:150,handle:".fpf-repeater-field-move-item-btn"}),a.classList.add("initialized")}},t.handleRemove=function(e){var t=e.target.closest(".fpf-repeater-field-remove-item-btn");t&&(t.classList.contains("no-confirm")||confirm(fpf_js_object.FPF_ARE_YOU_SURE_YOU_WANT_TO_DELETE_THIS_ITEM))&&(e.target.closest(".fpf-repeater-item").remove(),e.preventDefault())},t.replaceTemplateIDs=function(e,t){var r=this.getNewRepeaterItemID(e);t.querySelectorAll("[name]").forEach(function(e){var t=e.getAttribute("name");t=t.replace("[ITEM_ID]","["+r+"]"),e.setAttribute("name",t)}),t.querySelectorAll("[data-name]").forEach(function(e){var t=e.getAttribute("data-name");t=t.replace("[ITEM_ID]","["+r+"]"),e.setAttribute("data-name",t)}),t.querySelectorAll("[data-showon]").forEach(function(e){var t=e.getAttribute("data-showon");t=t.replace(/\[ITEM_ID\]/g,"["+r+"]"),e.setAttribute("data-showon",t),e.classList.remove("fpf-run-condition")}),t.querySelectorAll("[for]").forEach(function(e){var t=e.getAttribute("for");t=t.replace(/\[ITEM_ID\]/g,"["+r+"]"),e.setAttribute("for",t)}),t.querySelectorAll("[id]").forEach(function(e){var t=e.getAttribute("id");t=t.replace(/\[ITEM_ID\]/g,"["+r+"]"),e.setAttribute("id",t)});var a=t.getAttribute("data-item-id");return a=a.replace(/\[ITEM_ID\]/g,r),t.setAttribute("data-item-id",a),t},t.getNewRepeaterItemID=function(e){var t=e.querySelectorAll(".items .fpf-repeater-item"),r=0;return t.forEach(function(e){var t=parseInt(e.getAttribute("data-item-id"));r<t&&(r=t)}),0===r?1:r+1},e}();FPF_Helper.onReady(function(){new FPF_Repeater});

