(function(){"use strict";function M(i,o){for(var d=0;d<o.length;d++){var l=o[d];l.enumerable=l.enumerable||!1,l.configurable=!0,"value"in l&&(l.writable=!0),Object.defineProperty(i,I(l.key),l)}}function q(i,o,d){return o&&M(i.prototype,o),d&&M(i,d),Object.defineProperty(i,"prototype",{writable:!1}),i}function B(i,o){i.prototype=Object.create(o.prototype),i.prototype.constructor=i,w(i,o)}function S(i){return S=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(d){return d.__proto__||Object.getPrototypeOf(d)},S(i)}function w(i,o){return w=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(l,m){return l.__proto__=m,l},w(i,o)}function W(){if(typeof Reflect>"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function _(i,o,d){return W()?_=Reflect.construct.bind():_=function(m,E,A){var a=[null];a.push.apply(a,E);var t=Function.bind.apply(m,a),e=new t;return A&&w(e,A.prototype),e},_.apply(null,arguments)}function F(i){return Function.toString.call(i).indexOf("[native code]")!==-1}function j(i){var o=typeof Map=="function"?new Map:void 0;return j=function(l){if(l===null||!F(l))return l;if(typeof l!="function")throw new TypeError("Super expression must either be null or a function");if(typeof o<"u"){if(o.has(l))return o.get(l);o.set(l,m)}function m(){return _(l,arguments,S(this).constructor)}return m.prototype=Object.create(l.prototype,{constructor:{value:m,enumerable:!1,writable:!0,configurable:!0}}),w(m,l)},j(i)}function O(i){if(i===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return i}function U(i,o){if(typeof i!="object"||i===null)return i;var d=i[Symbol.toPrimitive];if(d!==void 0){var l=d.call(i,o||"default");if(typeof l!="object")return l;throw new TypeError("@@toPrimitive must return a primitive value.")}return(o==="string"?String:Number)(i)}function I(i){var o=U(i,"string");return typeof o=="symbol"?o:String(o)}/** * @copyright (C) 2019 Open Source Matters, Inc. <https://www.joomla.org> * @license GNU General Public License version 2 or later; see LICENSE.txt */(function(i){var o={SPACE:32,ESC:27,ENTER:13};function d(m){return m.ctrlKey||m.metaKey||m.shiftKey}var l=function(m){B(E,m);function E(){var a;a=m.call(this)||this;var t=O(a);if(a.containerWithRows=O(a),a.rowsContainer){var e=a.querySelectorAll(a.rowsContainer);Array.from(e).forEach(function(n){n.closest("joomla-field-subform")===O(a)&&(a.containerWithRows=n)})}return a.lastRowIndex=a.getRows().length-1,a.template="",a.prepareTemplate(),(a.buttonAdd||a.buttonRemove)&&(a.addEventListener("click",function(n){var s=null,g=null;if(t.buttonAdd&&(s=n.target.matches(t.buttonAdd)?n.target:n.target.closest(t.buttonAdd)),t.buttonRemove&&(g=n.target.matches(t.buttonRemove)?n.target:n.target.closest(t.buttonRemove)),s&&s.closest("joomla-field-subform")===t){var b=s.closest(t.repeatableElement);b=b&&b.closest("joomla-field-subform")===t?b:null,t.addRow(b),n.preventDefault()}else if(g&&g.closest("joomla-field-subform")===t){var r=g.closest(t.repeatableElement);t.removeRow(r),n.preventDefault()}}),a.addEventListener("keydown",function(n){if(n.keyCode===o.SPACE){var s=t.buttonAdd&&n.target.matches(t.buttonAdd),g=t.buttonRemove&&n.target.matches(t.buttonRemove);if((s||g)&&n.target.closest("joomla-field-subform")===t){var b=n.target.closest(t.repeatableElement);b=b&&b.closest("joomla-field-subform")===t?b:null,g&&b?t.removeRow(b):s&&t.addRow(b),n.preventDefault()}}})),a.buttonMove&&a.setUpDragSort(),a}var A=E.prototype;return A.getRows=function(){var t=this,e=Array.from(this.containerWithRows.children),n=[];return e.forEach(function(s){s.matches(t.repeatableElement)&&n.push(s)}),n},A.prepareTemplate=function(){var t=[].slice.call(this.children).filter(function(e){return e.classList.contains("subform-repeatable-template-section")});if(t[0]&&(this.template=t[0].innerHTML),!this.template)throw new Error("The row template is required for the subform element to work")},A.addRow=function(t){var e=this.getRows().length;if(e>=this.maximum)return null;var n;this.containerWithRows.nodeName==="TBODY"||this.containerWithRows.nodeName==="TABLE"?n=document.createElement("tbody"):n=document.createElement("div"),n.innerHTML=this.template;var s=n.children[0];return t?t.parentNode.insertBefore(s,t.nextSibling):this.containerWithRows.append(s),this.buttonMove&&(s.setAttribute("draggable","false"),s.setAttribute("aria-grabbed","false"),s.setAttribute("tabindex","0")),s.setAttribute("data-new","1"),this.fixUniqueAttributes(s,e),this.dispatchEvent(new CustomEvent("subform-row-add",{detail:{row:s},bubbles:!0})),s.dispatchEvent(new CustomEvent("joomla:updated",{bubbles:!0,cancelable:!0})),s},A.removeRow=function(t){var e=this.getRows().length;e<=this.minimum||(this.dispatchEvent(new CustomEvent("subform-row-remove",{detail:{row:t},bubbles:!0})),t.dispatchEvent(new CustomEvent("joomla:removed",{bubbles:!0,cancelable:!0})),t.parentNode.removeChild(t))},A.fixUniqueAttributes=function(t,e){var n=this,s=e||0,g=t.getAttribute("data-group"),b=t.getAttribute("data-base-name"),r=Math.max(this.lastRowIndex,s),u=b+r;this.lastRowIndex=r+1,t.setAttribute("data-group",u);var f=t.querySelectorAll("[name]"),c={};f=[].slice.call(f).filter(function(R){return R.nodeName==="JOOMLA-FIELD-SUBFORM"?R.parentElement.closest("joomla-field-subform")===n:R.closest("joomla-field-subform")===n}),f.forEach(function(R){var v=R,k=v.getAttribute("name"),K=v.getAttribute("aria-describedby"),p=k.replace(/(\[\]$)/g,"").replace(/(\]\[)/g,"__").replace(/\[/g,"_").replace(/\]/g,""),D=k.replace("["+g+"][","["+u+"]["),h=p.replace(g,u).replace(/\W/g,"_"),y=0,x=p;if(v.type==="checkbox"&&k.match(/\[\]$/)){if(y=c[p]?c[p].length:0,!y){var L=v.closest("fieldset.checkboxes"),P=t.querySelector('label[for="'+p+'"]');L&&L.setAttribute("id",h),P&&(P.setAttribute("for",h),P.setAttribute("id",h+"-lbl"))}x+=y,h+=y}else if(v.type==="radio"){if(y=c[p]?c[p].length:0,!y){var C=v.closest("fieldset.radio"),N=t.querySelector('label[for="'+p+'"]');C&&C.setAttribute("id",h),N&&(N.setAttribute("for",h),N.setAttribute("id",h+"-lbl"))}x+=y,h+=y}c[p]?c[p].push(!0):c[p]=[!0],v.name=D,v.id&&(v.id=h),K&&v.setAttribute("aria-describedby",D+"-desc");var T=t.querySelector('label[for="'+x+'"]');T&&(T.setAttribute("for",h),T.setAttribute("id",h+"-lbl"))})},A.setUpDragSort=function(){var t=this,e=null,n=!1,s=Array.from(this.getRows());s.forEach(function(r){r.setAttribute("draggable","false"),r.setAttribute("aria-grabbed","false"),r.setAttribute("tabindex","0")});function g(r){return!r.form&&r.matches(t.buttonMove)?r:r.closest(t.buttonMove)}function b(r,u){var f=!1;if(r.parentNode===u.parentNode){for(var c=r;c;c=c.previousSibling)if(c===u){f=!0;break}}f?u.parentNode.insertBefore(r,u):u.parentNode.insertBefore(r,u.nextSibling)}this.addEventListener("touchstart",function(r){n=!0;var u=g(r.target),f=u?u.closest(t.repeatableElement):null;!f||f.closest("joomla-field-subform")!==t||(e?(f!==e&&b(e,f),e.setAttribute("draggable","false"),e.setAttribute("aria-grabbed","false"),e=null):(f.setAttribute("draggable","true"),f.setAttribute("aria-grabbed","true"),e=f),r.preventDefault())}),this.addEventListener("mousedown",function(r){var u=r.target;if(!n){var f=g(u),c=f?f.closest(t.repeatableElement):null;!c||c.closest("joomla-field-subform")!==t||(c.setAttribute("draggable","true"),c.setAttribute("aria-grabbed","true"),e=c)}}),this.addEventListener("mouseup",function(){e&&!n&&(e.setAttribute("draggable","false"),e.setAttribute("aria-grabbed","false"),e=null)}),this.addEventListener("keydown",function(r){if(!(r.keyCode!==o.ESC&&r.keyCode!==o.SPACE&&r.keyCode!==o.ENTER||r.target.form||!r.target.matches(t.repeatableElement))){var u=r.target;if(!(!u||u.closest("joomla-field-subform")!==t)&&(r.keyCode===o.SPACE&&d(r)&&(u.getAttribute("aria-grabbed")==="true"?(u.setAttribute("draggable","false"),u.setAttribute("aria-grabbed","false"),e=null):(e&&(e.setAttribute("draggable","false"),e.setAttribute("aria-grabbed","false"),e=null),u.setAttribute("draggable","true"),u.setAttribute("aria-grabbed","true"),e=u),r.preventDefault()),r.keyCode===o.ESC&&e&&(e.setAttribute("draggable","false"),e.setAttribute("aria-grabbed","false"),e=null),r.keyCode===o.ENTER&&e)){if(e.setAttribute("draggable","false"),e.setAttribute("aria-grabbed","false"),u===e){e=null;return}b(e,u),r.preventDefault(),e=null}}}),this.addEventListener("dragstart",function(r){var u=r.dataTransfer;e&&(u.effectAllowed="move",u.setData("text",""))}),this.addEventListener("dragover",function(r){e&&r.preventDefault()}),this.addEventListener("dragenter",function(r){var u=r.target;if(!(!e||u.parentElement.closest("joomla-field-subform")!==t)){var f=u.closest(t.repeatableElement);!f||f.closest("joomla-field-subform")!==t||b(e,f)}}),this.addEventListener("dragend",function(){e&&(e.setAttribute("draggable","false"),e.setAttribute("aria-grabbed","false"),e=null)})},q(E,[{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(t){this.template=this.template.replace(new RegExp(' name="'+this.name.replace(/[[\]]/g,"\\$&"),"g"),' name="'+t),this.setAttribute("name",t)}}]),E}(j(HTMLElement));i.define("joomla-field-subform",l)})(customElements)})();