!function(){"use strict";function e(e,t){for(var r=0;r=this.maximum)return null;(t="TBODY"===this.containerWithRows.nodeName||"TABLE"===this.containerWithRows.nodeName?document.createElement("tbody"):document.createElement("div")).innerHTML=this.template;var n=t.children[0];return e?e.parentNode.insertBefore(n,e.nextSibling):this.containerWithRows.append(n),this.buttonMove&&(n.setAttribute("draggable","false"),n.setAttribute("aria-grabbed","false"),n.setAttribute("tabindex","0")),n.setAttribute("data-new","1"),this.fixUniqueAttributes(n,r),this.dispatchEvent(new CustomEvent("subform-row-add",{detail:{row:n},bubbles:!0})),n.dispatchEvent(new CustomEvent("joomla:updated",{bubbles:!0,cancelable:!0})),n},d.removeRow=function(e){this.getRows().length<=this.minimum||(this.dispatchEvent(new CustomEvent("subform-row-remove",{detail:{row:e},bubbles:!0})),e.dispatchEvent(new CustomEvent("joomla:removed",{bubbles:!0,cancelable:!0})),e.parentNode.removeChild(e))},d.fixUniqueAttributes=function(e,t){var r=this,n=t||0,a=e.getAttribute("data-group"),o=e.getAttribute("data-base-name"),i=Math.max(this.lastRowIndex,n),u=o+i;this.lastRowIndex=i+1,e.setAttribute("data-group",u);var s=e.querySelectorAll("[name]"),l={};(s=[].slice.call(s).filter((function(e){return"JOOMLA-FIELD-SUBFORM"===e.nodeName?e.parentElement.closest("joomla-field-subform")===r:e.closest("joomla-field-subform")===r}))).forEach((function(t){var r=t,n=r.getAttribute("name"),o=r.getAttribute("aria-describedby"),i=n.replace(/(\[\]$)/g,"").replace(/(\]\[)/g,"__").replace(/\[/g,"_").replace(/\]/g,""),s=n.replace("["+a+"][","["+u+"]["),b=i.replace(a,u).replace(/\W/g,"_"),f=0,c=i;if("checkbox"===r.type&&n.match(/\[\]$/)){if(!(f=l[i]?l[i].length:0)){var d=r.closest("fieldset.checkboxes"),m=e.querySelector('label[for="'+i+'"]');d&&d.setAttribute("id",b),m&&(m.setAttribute("for",b),m.setAttribute("id",b+"-lbl"))}c+=f,b+=f}else if("radio"===r.type){if(!(f=l[i]?l[i].length:0)){var p=r.closest("fieldset.radio"),g=e.querySelector('label[for="'+i+'"]');p&&p.setAttribute("id",b),g&&(g.setAttribute("for",b),g.setAttribute("id",b+"-lbl"))}c+=f,b+=f}l[i]?l[i].push(!0):l[i]=[!0],r.name=s,r.id&&(r.id=b),o&&r.setAttribute("aria-describedby",s+"-desc");var h=e.querySelector('label[for="'+c+'"]');h&&(h.setAttribute("for",b),h.setAttribute("id",b+"-lbl"))}))},d.setUpDragSort=function(){var e=this,t=null,r=!1;function o(t){return!t.form&&t.matches(e.buttonMove)?t:t.closest(e.buttonMove)}function i(e,t){var r=!1;if(e.parentNode===t.parentNode)for(var n=e;n;n=n.previousSibling)if(n===t){r=!0;break}r?t.parentNode.insertBefore(e,t):t.parentNode.insertBefore(e,t.nextSibling)}Array.from(this.getRows()).forEach((function(e){e.setAttribute("draggable","false"),e.setAttribute("aria-grabbed","false"),e.setAttribute("tabindex","0")})),this.addEventListener("touchstart",(function(n){r=!0;var a=o(n.target),u=a?a.closest(e.repeatableElement):null;u&&u.closest("joomla-field-subform")===e&&(t?(u!==t&&i(t,u),t.setAttribute("draggable","false"),t.setAttribute("aria-grabbed","false"),t=null):(u.setAttribute("draggable","true"),u.setAttribute("aria-grabbed","true"),t=u),n.preventDefault())})),this.addEventListener("mousedown",(function(n){var a=n.target;if(!r){var i=o(a),u=i?i.closest(e.repeatableElement):null;u&&u.closest("joomla-field-subform")===e&&(u.setAttribute("draggable","true"),u.setAttribute("aria-grabbed","true"),t=u)}})),this.addEventListener("mouseup",(function(){t&&!r&&(t.setAttribute("draggable","false"),t.setAttribute("aria-grabbed","false"),t=null)})),this.addEventListener("keydown",(function(r){if(!(r.keyCode!==a&&r.keyCode!==n&&r.keyCode!==u||r.target.form)&&r.target.matches(e.repeatableElement)){var o=r.target;if(o&&o.closest("joomla-field-subform")===e&&(r.keyCode===n&&function(e){return e.ctrlKey||e.metaKey||e.shiftKey}(r)&&("true"===o.getAttribute("aria-grabbed")?(o.setAttribute("draggable","false"),o.setAttribute("aria-grabbed","false"),t=null):(t&&(t.setAttribute("draggable","false"),t.setAttribute("aria-grabbed","false"),t=null),o.setAttribute("draggable","true"),o.setAttribute("aria-grabbed","true"),t=o),r.preventDefault()),r.keyCode===a&&t&&(t.setAttribute("draggable","false"),t.setAttribute("aria-grabbed","false"),t=null),r.keyCode===u&&t)){if(t.setAttribute("draggable","false"),t.setAttribute("aria-grabbed","false"),o===t)return void(t=null);i(t,o),r.preventDefault(),t=null}}})),this.addEventListener("dragstart",(function(e){var r=e.dataTransfer;t&&(r.effectAllowed="move",r.setData("text",""))})),this.addEventListener("dragover",(function(e){t&&e.preventDefault()})),this.addEventListener("dragenter",(function(r){var n=r.target;if(t&&n.parentElement.closest("joomla-field-subform")===e){var a=n.closest(e.repeatableElement);a&&a.closest("joomla-field-subform")===e&&i(t,a)}})),this.addEventListener("dragend",(function(){t&&(t.setAttribute("draggable","false"),t.setAttribute("aria-grabbed","false"),t=null)}))},b=l,(f=[{key:"buttonAdd",get:function(){return this.getAttribute("button-add")}},{key:"buttonRemove",get:function(){return this.getAttribute("button-remove")}},{key:"buttonMove",get:function(){return this.getAttribute("button-move")}},{key:"rowsContainer",get:function(){return this.getAttribute("rows-container")}},{key:"repeatableElement",get:function(){return this.getAttribute("repeatable-element")}},{key:"minimum",get:function(){return this.getAttribute("minimum")}},{key:"maximum",get:function(){return this.getAttribute("maximum")}},{key:"name",get:function(){return this.getAttribute("name")},set:function(e){this.template=this.template.replace(new RegExp(' name="'+this.name.replace(/[[\]]/g,"\\$&"),"g"),' name="'+e),this.setAttribute("name",e)}}])&&e(b.prototype,f),c&&e(b,c),Object.defineProperty(b,"prototype",{writable:!1}),l}(o(HTMLElement));t.define("joomla-field-subform",s)}(customElements)}();