(()=>{"use strict";function t(t){const e=new DataTransfer;for(const n of t)e.items.add(n);return e.files}function e(t){return!!t.classList.contains("jet-form-builder-file-upload__input")&&"file"===t.type}const{InputData:n}=window.JetFormBuilderAbstract;function i(){n.call(this),this.isMultiple=!1,this.prevFiles=null,this.template=null,this.previewsContainer=null,this.wrapper=null,this.isSupported=function(t){return e(t)},this.addListeners=function(){const[e]=this.nodes;e.addEventListener("change",e=>{var n;this.value.current=t(this.isMultiple?[...null!==(n=this.prevFiles)&&void 0!==n?n:[],...e.target.files]:[...e.target.files])})},this.setNode=function(t){n.prototype.setNode.call(this,t),this.isMultiple=t.multiple,this.wrapper=t.closest(".jet-form-builder-file-upload"),this.previewsContainer=this.wrapper.querySelector(".jet-form-builder-file-upload__files"),this.template=this.wrapper.closest(".field-type-media-field").querySelector(".jet-form-builder__preview-template")},this.setValue=function(){this.callable.loadFiles()},this.initNotifyValue=()=>{},this.reQueryValue=()=>{}}i.prototype=Object.create(n.prototype),i.prototype.wrapper=null,i.prototype.previewsContainer=null,i.prototype.template=null;const r=i,{BaseSignal:l}=window.JetFormBuilderAbstract;function o(t){return String(null!=t?t:"").replaceAll("&","&").replaceAll("<","<").replaceAll(">",">").replaceAll('"',""")}function s(){l.call(this),this.lock.current=!0,this.isSupported=function(t){return e(t)},this.runSignal=function(){const[e]=this.input.nodes,n=[],{current:i}=this.input.value,r=u(null!=i?i:[]);for(const t of r)n.push(this.getPreview(t));!function(t,e){const n=t.querySelectorAll(".jet-form-builder-file-upload__file");for(const t of n)e.some(e=>e.isEqualNode(t))||t.remove();for(const n in e){if(!e.hasOwnProperty(n))continue;const i=e[n];i.isConnected||t.appendChild(i)}}(this.input.previewsContainer,n),e.files=t(r),this.input.prevFiles=r,this.sortable()}}s.prototype=Object.create(l.prototype),s.prototype.loadFiles=function(){const e=this.input.previewsContainer.querySelectorAll(".jet-form-builder-file-upload__file"),n=[];for(const t of e){this.addRemoveHandler(t);const e=t.dataset.file,i=t.querySelector(".jet-form-builder-file-upload__file-remove"),{fileName:r}=i.dataset;n.push([e,r])}n.length?Promise.allSettled(n.map(([t,e])=>new Promise((n,i)=>{fetch(t).then(t=>t.blob()).then(t=>n(function(t,e){return new File([t],e,t)}(t,e))).catch(i)}))).then(e=>{const n=u(e.map(({value:t})=>t));this.lock.current=!1,this.input.silenceSet(t(n))}).catch(()=>{this.lock.current=!1}):this.lock.current=!1},s.prototype.sortable=function(){jQuery(this.input.previewsContainer).unbind(),jQuery(this.input.previewsContainer).sortable({items:".jet-form-builder-file-upload__file",forcePlaceholderSize:!0}).bind("sortupdate",()=>this.onSortCallback())},s.prototype.onSortCallback=function(){const t=new DataTransfer,[e]=this.input.nodes,n=this.input.previewsContainer.querySelectorAll(".jet-form-builder-file-upload__file-remove");for(const i of n){const{fileName:n}=i.dataset;for(const i of e.files)i.name===n&&t.items.add(i)}this.input.value.current=t.files},s.prototype.addRemoveHandler=function(t){t.querySelector(".jet-form-builder-file-upload__file-remove").addEventListener("click",this.removeFile.bind(this))},s.prototype.getPreview=function(t){const e=this.input.previewsContainer.querySelector(`[data-file-name="${t.name}"]`);if(!e){const e=this.createPreview(t);return this.addRemoveHandler(e),e}return e.closest(".jet-form-builder-file-upload__file")},s.prototype.createPreview=function(t){const e=URL.createObjectURL(t);let{innerHTML:n}=this.input.template;n=n.replace("%file_url%",o(e)),n=n.replace("%file_name%",o(t.name));const i=document.createElement("template");i.innerHTML=n;const r=i.content.firstChild;if(/^image\//.test(t.type)){const n=document.createElement("img");n.src=e,n.alt=t.name,r.prepend(n)}return r},s.prototype.removeFile=function({target:t}){const e=".jet-form-builder-file-upload__file-remove",{value:n}=this.input;t.matches(e)||(t=t.closest(e));const{fileName:i}=t.dataset,r=new DataTransfer;for(const t of n.current)i!==t.name&&r.items.add(t);n.current=r.files},s.prototype.getFileNode=function(t){const e=`data-file-name="${t}"`;return this.input.previewsContainer.querySelector(`.jet-form-builder-file-upload__file-remove[${e}]`).closest(".jet-form-builder-file-upload__file")};const a=s;function u(t){const e=new Set,n=[];for(const i of function(t){return t?Array.isArray(t)?t:"function"==typeof t[Symbol.iterator]?Array.from(t):"object"==typeof t?Object.values(t):[]:[]}(t))i?.name&&(e.has(i.name)||(e.add(i.name),n.push(i)));return n}function c(t){return String(null!=t?t:"").replaceAll("&","&").replaceAll("<","<").replaceAll(">",">").replaceAll('"',""").replaceAll("'","'")}function f(t){const e=t.closest(".field-type-media-field");if(!e)return"";const n=e.querySelectorAll(".jet-form-builder-file-upload__file");if(!n.length)return"";const i=[];return n.forEach(t=>{var e,n;const r=String(null!==(e=t.dataset?.file)&&void 0!==e?e:"").trim(),l=t.querySelector(".jet-form-builder-file-upload__file-remove"),o=String(null!==(n=l?.dataset?.fileName)&&void 0!==n?n:"").trim();t.querySelector("img")&&r?i.push(function(t,e=""){const n=e||"Image";return`\n\t\t